From 0e5d7d0470bfbe6f8c248636e4312420983878c6 Mon Sep 17 00:00:00 2001 From: Jayant Krishnamurthy Date: Wed, 19 Jul 2023 12:18:44 -0700 Subject: [PATCH] [price_pusher] Refresh sui object versions (#966) --- price_pusher/package.json | 2 +- price_pusher/src/sui/sui.ts | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/price_pusher/package.json b/price_pusher/package.json index 9471092e..dc786e7a 100644 --- a/price_pusher/package.json +++ b/price_pusher/package.json @@ -1,6 +1,6 @@ { "name": "@pythnetwork/price-pusher", - "version": "5.4.5", + "version": "5.4.6", "description": "Pyth Price Pusher", "homepage": "https://pyth.network", "main": "lib/index.js", diff --git a/price_pusher/src/sui/sui.ts b/price_pusher/src/sui/sui.ts index d1a71d38..99d913cc 100644 --- a/price_pusher/src/sui/sui.ts +++ b/price_pusher/src/sui/sui.ts @@ -329,7 +329,11 @@ export class SuiPricePusher implements IPricePusher { `The balance of gas object ${gasObject.objectId} is too low. Removing from pool.` ); } else { - nextGasObject = gasObject; + // Refresh the coin object here in case the error is caused by an object version mismatch. + nextGasObject = await SuiPricePusher.tryRefreshObjectReference( + this.signer.provider, + gasObject + ); } console.error(e); @@ -373,6 +377,29 @@ export class SuiPricePusher implements IPricePusher { return gasPool; } + // Attempt to refresh the version of the provided object reference to point to the current version + // of the object. Return the provided object reference if an error occurs or the object could not + // be retrieved. + private static async tryRefreshObjectReference( + provider: JsonRpcProvider, + ref: SuiObjectRef + ): Promise { + try { + const objectResponse = await provider.getObject({ id: ref.objectId }); + if (objectResponse.data !== undefined) { + return { + digest: objectResponse.data.digest, + objectId: objectResponse.data.objectId, + version: objectResponse.data.version, + }; + } else { + return ref; + } + } catch (error) { + return ref; + } + } + private static async getAllGasCoins( provider: JsonRpcProvider, owner: SuiAddress