Skip to content

Commit 0e5d7d0

Browse files
authored
[price_pusher] Refresh sui object versions (#966)
1 parent 03185cb commit 0e5d7d0

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

price_pusher/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/price-pusher",
3-
"version": "5.4.5",
3+
"version": "5.4.6",
44
"description": "Pyth Price Pusher",
55
"homepage": "https://pyth.network",
66
"main": "lib/index.js",

price_pusher/src/sui/sui.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,11 @@ export class SuiPricePusher implements IPricePusher {
329329
`The balance of gas object ${gasObject.objectId} is too low. Removing from pool.`
330330
);
331331
} else {
332-
nextGasObject = gasObject;
332+
// Refresh the coin object here in case the error is caused by an object version mismatch.
333+
nextGasObject = await SuiPricePusher.tryRefreshObjectReference(
334+
this.signer.provider,
335+
gasObject
336+
);
333337
}
334338
console.error(e);
335339

@@ -373,6 +377,29 @@ export class SuiPricePusher implements IPricePusher {
373377
return gasPool;
374378
}
375379

380+
// Attempt to refresh the version of the provided object reference to point to the current version
381+
// of the object. Return the provided object reference if an error occurs or the object could not
382+
// be retrieved.
383+
private static async tryRefreshObjectReference(
384+
provider: JsonRpcProvider,
385+
ref: SuiObjectRef
386+
): Promise<SuiObjectRef> {
387+
try {
388+
const objectResponse = await provider.getObject({ id: ref.objectId });
389+
if (objectResponse.data !== undefined) {
390+
return {
391+
digest: objectResponse.data.digest,
392+
objectId: objectResponse.data.objectId,
393+
version: objectResponse.data.version,
394+
};
395+
} else {
396+
return ref;
397+
}
398+
} catch (error) {
399+
return ref;
400+
}
401+
}
402+
376403
private static async getAllGasCoins(
377404
provider: JsonRpcProvider,
378405
owner: SuiAddress

0 commit comments

Comments
 (0)