Snowsight has launched!
Many of you have tested out the service over the past few weeks, so check their tweet below and see if you have a tester’s credit for their premium tier. I do, and will be hitting the service hard over the next week to see how it performs.
The Snowsight Arbitrage Bot code that I published a few days ago was set up for their beta service, and the new one has some small changes that you should implement so it works.
I am making updates to my bot as I test the new service, and I will edit this post several times with new information.
New Contract
The previous Snowsight contract, which is responsible for receiving payments and extending credits for the service, was deployed to 0xD9B1ee4AE46d4fe51Eeaf644107f53A37F93352f. The new contract is deployed to 0x727Dc3C412cCb942c6b5f220190ebAB3eFE0Eb93. The old contract has been disabled, and can no longer receive payments.
So please update the contract address in your bot to read:
SNOWSIGHT_CONTRACT_ADDRESS = "0x727Dc3C412cCb942c6b5f220190ebAB3eFE0Eb93"
New Connection Status
On first connection to the Snowsight websocket, the beta service would display a message with the JSON key-value pair 'status':'authenticated'
, which has been replaced with 'status':'[payment tier]'
.
I have a credit currently, so my connection message reads 'status':'premium'
. The other responses are 'trial''premium''standard', so
change the code that handles connection status in the function watch_pending_transactions()
to read:
elif resp["status"] in ["trial", "standard", "premium"]:
If the other statuses are 'trial'
and 'standard'
, simply add those with commas to the comparison list.
New Payment Calculation
There is no longer a payment cap. The beta service was limited to purchasing 24 hours at a time, so my renew_subscription()
function checked for the current credit compared to the maximum to optimize gas use.
I have reworked the subscription function to support the differing payment tiers. In my case I have set the following values in my constants section:
SNOWSIGHT_TIER = "standard"
SNOWSIGHT_TIME = 60 * 60 * 24 * 3 # subscription block in seconds
And here is the updated renewal:
async def renew_subscription():
"""
An async function that blocks only when a renewal
is necessary. Retrieves data from the Snowsight contract,
calculates the maximum payment, and submits a transaction
through the Chainsight relay.
This function is async but the snowsight payment blocks
the event loop until the transaction is confirmed
"""
print("Starting subscription renewal loop")
global newest_block_timestamp
global status_new_blocks
global nonce
_snowsight_tiers = {
"trial": 0,
"standard": 1,
"premium": 2,
}
try:
snowsight_contract = brownie.Contract(
SNOWSIGHT_CONTRACT_ADDRESS,
)
except:
snowsight_contract = brownie.Contract.from_explorer(
SNOWSIGHT_CONTRACT_ADDRESS,
)
renewal_timestamp = snowsight_contract.payments(
degenbot.address,
_snowsight_tiers[SNOWSIGHT_TIER],
)[-1]
while True:
# delay until we're receiving new blocks (newest_block_timestamp needs to be accurate)
if not status_new_blocks:
await asyncio.sleep(1)
continue
if SNOWSIGHT_TIER in ["trial"]:
# trial payment has a min and max payment of
# 86400, so we can't renew early and must wait
# for expiration
if renewal_timestamp <= newest_block_timestamp:
payment = snowsight_contract.calculateMaxPayment(
_snowsight_tiers[SNOWSIGHT_TIER]
)
else:
print(
f"Renewal in {renewal_timestamp - newest_block_timestamp} seconds"
)
await asyncio.sleep(renewal_timestamp - newest_block_timestamp)
continue
if SNOWSIGHT_TIER in ["standard", "premium"]:
# renew credit if we're within 600 seconds
# of expiration for standard and premium
if renewal_timestamp - newest_block_timestamp <= 600:
payment = max(
snowsight_contract.calculatePaymentByTierAndTime(
_snowsight_tiers[SNOWSIGHT_TIER],
SNOWSIGHT_TIME,
),
snowsight_contract.calculateMinPayment(
_snowsight_tiers[SNOWSIGHT_TIER],
),
)
else:
# sleep half of the remaining time
print(
f"Renewal in {renewal_timestamp - newest_block_timestamp} seconds"
)
await asyncio.sleep((renewal_timestamp - newest_block_timestamp) / 2)
try:
snowsight_contract.pay(
_snowsight_tiers[SNOWSIGHT_TIER],
{
"from": degenbot.address,
"value": payment,
"priority_fee": 0,
},
)
renewal_timestamp = snowsight_contract.payments(
degenbot.address,
_snowsight_tiers[SNOWSIGHT_TIER],
)[-1]
nonce = degenbot.nonce
except Exception as e:
print(e)
continue
Hi, i run code and received this error
best_profit = -int(opt.fun)
ValueError: cannot convert float NaN to integer
NameError: name 'newest_block_timestamp' is not defined
Hi, I updated the code, but met this bug.