Skip to content

Commit ff6b110

Browse files
authored
[price_pusher] Option to ignore gas objects (#1545)
* gr * bump version
1 parent 4966b95 commit ff6b110

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

apps/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": "6.7.1",
3+
"version": "6.7.2",
44
"description": "Pyth Price Pusher",
55
"homepage": "https://pyth.network",
66
"main": "lib/index.js",

apps/price_pusher/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import near from "./near/command";
99
import solana from "./solana/command";
1010

1111
yargs(hideBin(process.argv))
12+
.parserConfiguration({
13+
"parse-numbers": false,
14+
})
1215
.config("config")
1316
.global("config")
1417
.command(evm)

apps/price_pusher/src/sui/command.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ export default {
4444
required: true,
4545
default: 30,
4646
} as Options,
47+
"ignore-gas-objects": {
48+
description:
49+
"Gas objects to ignore when merging gas objects on startup -- use this for locked objects.",
50+
type: "array",
51+
required: false,
52+
default: [],
53+
} as Options,
4754
"gas-budget": {
4855
description: "Gas budget for each price update",
4956
type: "number",
@@ -73,6 +80,7 @@ export default {
7380
pythStateId,
7481
wormholeStateId,
7582
numGasObjects,
83+
ignoreGasObjects,
7684
gasBudget,
7785
accountIndex,
7886
} = argv;
@@ -126,7 +134,8 @@ export default {
126134
endpoint,
127135
keypair,
128136
gasBudget,
129-
numGasObjects
137+
numGasObjects,
138+
ignoreGasObjects
130139
);
131140

132141
const controller = new Controller(

apps/price_pusher/src/sui/sui.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ export class SuiPricePusher implements IPricePusher {
162162
endpoint: string,
163163
keypair: Ed25519Keypair,
164164
gasBudget: number,
165-
numGasObjects: number
165+
numGasObjects: number,
166+
ignoreGasObjects: string[]
166167
): Promise<SuiPricePusher> {
167168
if (numGasObjects > MAX_NUM_OBJECTS_IN_ARGUMENT) {
168169
throw new Error(
@@ -183,7 +184,8 @@ export class SuiPricePusher implements IPricePusher {
183184
const gasPool = await SuiPricePusher.initializeGasPool(
184185
keypair,
185186
provider,
186-
numGasObjects
187+
numGasObjects,
188+
ignoreGasObjects
187189
);
188190

189191
const pythClient = new SuiPythClient(
@@ -318,17 +320,26 @@ export class SuiPricePusher implements IPricePusher {
318320

319321
// This function will smash all coins owned by the signer into one, and then
320322
// split them equally into numGasObjects.
323+
// ignoreGasObjects is a list of gas objects that will be ignored during the
324+
// merging -- use this to store any locked objects on initialization.
321325
private static async initializeGasPool(
322326
signer: Ed25519Keypair,
323327
provider: SuiClient,
324-
numGasObjects: number
328+
numGasObjects: number,
329+
ignoreGasObjects: string[]
325330
): Promise<SuiObjectRef[]> {
326331
const signerAddress = await signer.toSuiAddress();
327332

333+
if (ignoreGasObjects.length > 0) {
334+
console.log("Ignoring some gas objects for coin merging:");
335+
console.log(ignoreGasObjects);
336+
}
337+
328338
const consolidatedCoin = await SuiPricePusher.mergeGasCoinsIntoOne(
329339
signer,
330340
provider,
331-
signerAddress
341+
signerAddress,
342+
ignoreGasObjects
332343
);
333344
const coinResult = await provider.getObject({
334345
id: consolidatedCoin.objectId,
@@ -458,7 +469,8 @@ export class SuiPricePusher implements IPricePusher {
458469
private static async mergeGasCoinsIntoOne(
459470
signer: Ed25519Keypair,
460471
provider: SuiClient,
461-
owner: SuiAddress
472+
owner: SuiAddress,
473+
initialLockedAddresses: string[]
462474
): Promise<SuiObjectRef> {
463475
const gasCoins = await SuiPricePusher.getAllGasCoins(provider, owner);
464476
// skip merging if there is only one coin
@@ -472,6 +484,7 @@ export class SuiPricePusher implements IPricePusher {
472484
);
473485
let finalCoin;
474486
const lockedAddresses: Set<string> = new Set();
487+
initialLockedAddresses.forEach((value) => lockedAddresses.add(value));
475488
for (let i = 0; i < gasCoinsChunks.length; i++) {
476489
const mergeTx = new TransactionBlock();
477490
let coins = gasCoinsChunks[i];
@@ -497,15 +510,13 @@ export class SuiPricePusher implements IPricePusher {
497510
"quorum of validators because of locked objects. Retried a conflicting transaction"
498511
)
499512
) {
500-
/*
501513
Object.values((e as any).data).forEach((lockedObjects: any) => {
502514
lockedObjects.forEach((lockedObject: [string, number, string]) => {
503515
lockedAddresses.add(lockedObject[0]);
504516
});
505517
});
506518
// retry merging without the locked coins
507519
i--;
508-
*/
509520
continue;
510521
}
511522
throw e;

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)