Преглед на файлове

[price_pusher] Refresh sui object versions (#966)

Jayant Krishnamurthy преди 2 години
родител
ревизия
0e5d7d0470
променени са 2 файла, в които са добавени 29 реда и са изтрити 2 реда
  1. 1 1
      price_pusher/package.json
  2. 28 1
      price_pusher/src/sui/sui.ts

+ 1 - 1
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",

+ 28 - 1
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<SuiObjectRef> {
+    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