@pythnetwork/price-pusher 5.4.8 → 5.4.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,6 +10,16 @@ export declare class AptosPriceListener extends ChainPriceListener {
10
10
  getOnChainPriceInfo(priceId: string): Promise<PriceInfo | undefined>;
11
11
  }
12
12
  export declare const APTOS_ACCOUNT_HD_PATH = "m/44'/637'/0'/0'/0'";
13
+ /**
14
+ * The `AptosPricePusher` is designed for high-throughput of price updates.
15
+ * Achieving this property requires sacrificing some nice-to-have features of other
16
+ * pusher implementations that can reduce cost when running multiple pushers. Specifically,
17
+ * this implementation does not use `update_price_feeds_if_necssary` and simulate the transaction
18
+ * before submission.
19
+ *
20
+ * If multiple instances of this pusher are running in parallel, both of them will
21
+ * land all of their pushed updates on-chain.
22
+ */
13
23
  export declare class AptosPricePusher implements IPricePusher {
14
24
  private priceServiceConnection;
15
25
  private pythContractAddress;
@@ -1 +1 @@
1
- {"version":3,"file":"aptos.d.ts","sourceRoot":"","sources":["../../src/aptos/aptos.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,SAAS,EACT,SAAS,EACV,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAE3E,qBAAa,kBAAmB,SAAQ,kBAAkB;IAEtD,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,QAAQ;gBADR,UAAU,EAAE,MAAM,EAClB,QAAQ,EAAE,MAAM,EACxB,UAAU,EAAE,SAAS,EAAE,EACvB,MAAM,EAAE;QACN,gBAAgB,EAAE,iBAAiB,CAAC;KACrC;IAKG,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;CA6C3E;AAGD,eAAO,MAAM,qBAAqB,wBAAwB,CAAC;A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wBAAwB,CAAC;AAE3D;;;;;;;;;GASG;AACH,qBAAa,gBAAiB,YAAW,YAAY;IAOjD,OAAO,CAAC,sBAAsB;IAC9B,OAAO,CAAC,mBAAmB;IAC3B,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,0BAA0B;IATpC,OAAO,CAAC,kBAAkB,CAAqB;IAE/C,OAAO,CAAC,oBAAoB,CAAU;gBAG5B,sBAAsB,EAAE,sBAAsB,EAC9C,mBAAmB,EAAE,MAAM,EAC3B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,0BAA0B,EAAE,MAAM;IAK5C;;;;;;OAMG;IACG,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;IAQhE,eAAe,CACnB,QAAQ,EAAE,MAAM,EAAE,EAClB,cAAc,EAAE,MAAM,EAAE,GACvB,OAAO,CAAC,IAAI,CAAC;YAiEF,8BAA8B;YAsB9B,wBAAwB;CA+BvC"}
@@ -44,6 +44,16 @@ class AptosPriceListener extends interface_1.ChainPriceListener {
44
44
  exports.AptosPriceListener = AptosPriceListener;
45
45
  // Derivation path for aptos accounts
46
46
  exports.APTOS_ACCOUNT_HD_PATH = "m/44'/637'/0'/0'/0'";
47
+ /**
48
+ * The `AptosPricePusher` is designed for high-throughput of price updates.
49
+ * Achieving this property requires sacrificing some nice-to-have features of other
50
+ * pusher implementations that can reduce cost when running multiple pushers. Specifically,
51
+ * this implementation does not use `update_price_feeds_if_necssary` and simulate the transaction
52
+ * before submission.
53
+ *
54
+ * If multiple instances of this pusher are running in parallel, both of them will
55
+ * land all of their pushed updates on-chain.
56
+ */
47
57
  class AptosPricePusher {
48
58
  priceServiceConnection;
49
59
  pythContractAddress;
@@ -69,31 +69,31 @@ class InjectivePricePusher {
69
69
  });
70
70
  const txService = new sdk_ts_1.TxGrpcClient(this.grpcEndpoint);
71
71
  // simulation
72
- const { gasInfo: { gasUsed }, } = await txService.simulate(simulateTxRaw);
73
- // simulation returns us the approximate gas used
74
- // gas passed with the transaction should be more than that
75
- // in order for it to be successfully executed
76
- // this multiplier takes care of that
77
- const gas = (gasUsed * this.chainConfig.gasMultiplier).toFixed();
78
- const fee = {
79
- amount: [
80
- {
81
- denom: "inj",
82
- amount: (Number(gas) * this.chainConfig.gasPrice).toFixed(),
83
- },
84
- ],
85
- gas,
86
- };
87
- const { signBytes, txRaw } = (0, sdk_ts_1.createTransactionFromMsg)({
88
- sequence: this.account.baseAccount.sequence,
89
- accountNumber: this.account.baseAccount.accountNumber,
90
- message: msg,
91
- chainId: this.chainConfig.chainId,
92
- fee,
93
- pubKey: this.wallet.toPublicKey().toBase64(),
94
- });
95
- const sig = await this.wallet.sign(Buffer.from(signBytes));
96
72
  try {
73
+ const { gasInfo: { gasUsed }, } = await txService.simulate(simulateTxRaw);
74
+ // simulation returns us the approximate gas used
75
+ // gas passed with the transaction should be more than that
76
+ // in order for it to be successfully executed
77
+ // this multiplier takes care of that
78
+ const gas = (gasUsed * this.chainConfig.gasMultiplier).toFixed();
79
+ const fee = {
80
+ amount: [
81
+ {
82
+ denom: "inj",
83
+ amount: (Number(gas) * this.chainConfig.gasPrice).toFixed(),
84
+ },
85
+ ],
86
+ gas,
87
+ };
88
+ const { signBytes, txRaw } = (0, sdk_ts_1.createTransactionFromMsg)({
89
+ sequence: this.account.baseAccount.sequence,
90
+ accountNumber: this.account.baseAccount.accountNumber,
91
+ message: msg,
92
+ chainId: this.chainConfig.chainId,
93
+ fee,
94
+ pubKey: this.wallet.toPublicKey().toBase64(),
95
+ });
96
+ const sig = await this.wallet.sign(Buffer.from(signBytes));
97
97
  this.account.baseAccount.sequence++;
98
98
  /** Append Signatures */
99
99
  txRaw.signatures = [sig];
package/lib/sui/sui.d.ts CHANGED
@@ -11,6 +11,20 @@ export declare class SuiPriceListener extends ChainPriceListener {
11
11
  });
12
12
  getOnChainPriceInfo(priceId: string): Promise<PriceInfo | undefined>;
13
13
  }
14
+ /**
15
+ * The `SuiPricePusher` is designed for high-throughput of price updates.
16
+ * Achieving this property requires sacrificing some nice-to-have features of other
17
+ * pusher implementations that can reduce cost when running multiple pushers. It also requires
18
+ * jumping through some Sui-specific hoops in order to maximize parallelism.
19
+ *
20
+ * The two main design features are:
21
+ * 1. This implementation does not use `update_price_feeds_if_necssary` and simulate the transaction
22
+ * before submission. If multiple instances of this pusher are running in parallel, all of them will
23
+ * land all of their pushed updates on-chain.
24
+ * 2. The pusher will split the Coin balance in the provided account into a pool of different Coin objects.
25
+ * Each transaction will be allocated a Coin object from this pool as needed. This process enables the
26
+ * transactions to avoid referencing the same owned objects, which allows them to be processed in parallel.
27
+ */
14
28
  export declare class SuiPricePusher implements IPricePusher {
15
29
  private readonly signer;
16
30
  private priceServiceConnection;
@@ -1 +1 @@
1
- {"version":3,"file":"sui.d.ts","sourceRoot":"","sources":["../../src/sui/sui.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,SAAS,EACT,SAAS,EACV,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAC;AAC3E,OAAO,EAIL,SAAS,EAIT,YAAY,EAKb,MAAM,gBAAgB,CAAC;AAMxB,qBAAa,gBAAiB,SAAQ,kBAAkB;IAEpD,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,iCAAiC;IACzC,OAAO,CAAC,QAAQ;gBAFR,aAAa,EAAE,MAAM,EACrB,iCAAiC,EAAE,MAAM,EACzC,QAAQ,EAAE,MAAM,EACxB,UAAU,EAAE,SAAS,EAAE,EACvB,MAAM,EAAE;QACN,gBAAgB,EAAE,iBAAiB,CAAC;KACrC;IAKG,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;CAmD3E;AAED,qBAAa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AQ,EAAE,MAAM,EACR,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,YAAY,EAAE;IAGjC;;;OAGG;WACU,0BAA0B,CACrC,sBAAsB,EAAE,sBAAsB,EAC9C,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EACnB,iBAAiB,EAAE,MAAM,EACzB,eAAe,EAAE,MAAM,EACvB,iCAAiC,EAAE,MAAM,EACzC,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,GACpB,OAAO,CAAC,cAAc,CAAC;IAiCpB,eAAe,CACnB,QAAQ,EAAE,MAAM,EAAE,EAClB,cAAc,EAAE,MAAM,EAAE,GACvB,OAAO,CAAC,IAAI,CAAC;YAsDF,4BAA4B;IA2E1C,iGAAiG;YACnF,qBAAqB;IAMnC,sEAAsE;YACxD,oBAAoB;mBAsDb,iBAAiB;mBAuCjB,yBAAyB;mBAoBzB,cAAc;mBAiCd,mBAAmB;mBAsCnB,oBAAoB;CA+D1C"}
package/lib/sui/sui.js CHANGED
@@ -51,6 +51,20 @@ class SuiPriceListener extends interface_1.ChainPriceListener {
51
51
  }
52
52
  }
53
53
  exports.SuiPriceListener = SuiPriceListener;
54
+ /**
55
+ * The `SuiPricePusher` is designed for high-throughput of price updates.
56
+ * Achieving this property requires sacrificing some nice-to-have features of other
57
+ * pusher implementations that can reduce cost when running multiple pushers. It also requires
58
+ * jumping through some Sui-specific hoops in order to maximize parallelism.
59
+ *
60
+ * The two main design features are:
61
+ * 1. This implementation does not use `update_price_feeds_if_necssary` and simulate the transaction
62
+ * before submission. If multiple instances of this pusher are running in parallel, all of them will
63
+ * land all of their pushed updates on-chain.
64
+ * 2. The pusher will split the Coin balance in the provided account into a pool of different Coin objects.
65
+ * Each transaction will be allocated a Coin object from this pool as needed. This process enables the
66
+ * transactions to avoid referencing the same owned objects, which allows them to be processed in parallel.
67
+ */
54
68
  class SuiPricePusher {
55
69
  signer;
56
70
  priceServiceConnection;
@@ -239,11 +253,20 @@ class SuiPricePusher {
239
253
  // split them equally into numGasObjects.
240
254
  static async initializeGasPool(signer, numGasObjects) {
241
255
  const signerAddress = await signer.getAddress();
242
- const { totalBalance: balance } = await signer.provider.getBalance({
243
- owner: signerAddress,
256
+ const consolidatedCoin = await SuiPricePusher.mergeGasCoinsIntoOne(signer, signerAddress);
257
+ const coinResult = await signer.provider.getObject({
258
+ id: consolidatedCoin.objectId,
259
+ options: { showContent: true },
244
260
  });
261
+ let balance;
262
+ if (coinResult.data &&
263
+ coinResult.data.content &&
264
+ coinResult.data.content.dataType == "moveObject") {
265
+ balance = coinResult.data.content.fields.balance;
266
+ }
267
+ else
268
+ throw new Error("Bad coin object");
245
269
  const splitAmount = (BigInt(balance) - BigInt(GAS_FEE_FOR_SPLIT)) / BigInt(numGasObjects);
246
- const consolidatedCoin = await SuiPricePusher.mergeGasCoinsIntoOne(signer, signerAddress);
247
270
  const gasPool = await SuiPricePusher.splitGasCoinEqually(signer, signerAddress, Number(splitAmount), numGasObjects, consolidatedCoin);
248
271
  console.log("Gas pool is filled with coins: ", gasPool);
249
272
  return gasPool;
@@ -321,17 +344,35 @@ class SuiPricePusher {
321
344
  }
322
345
  const gasCoinsChunks = chunkArray(gasCoins, MAX_NUM_GAS_OBJECTS_IN_PTB - 2);
323
346
  let finalCoin;
347
+ const lockedAddresses = new Set();
324
348
  for (let i = 0; i < gasCoinsChunks.length; i++) {
325
349
  const mergeTx = new sui_js_1.TransactionBlock();
326
350
  let coins = gasCoinsChunks[i];
351
+ coins = coins.filter((coin) => !lockedAddresses.has(coin.objectId));
327
352
  if (finalCoin) {
328
353
  coins = [finalCoin, ...coins];
329
354
  }
330
355
  mergeTx.setGasPayment(coins);
331
- const mergeResult = await signer.signAndExecuteTransactionBlock({
332
- transactionBlock: mergeTx,
333
- options: { showEffects: true },
334
- });
356
+ let mergeResult;
357
+ try {
358
+ mergeResult = await signer.signAndExecuteTransactionBlock({
359
+ transactionBlock: mergeTx,
360
+ options: { showEffects: true },
361
+ });
362
+ }
363
+ catch (e) {
364
+ if (String(e).includes("quorum of validators because of locked objects. Retried a conflicting transaction")) {
365
+ Object.values(e.data).forEach((lockedObjects) => {
366
+ lockedObjects.forEach((lockedObject) => {
367
+ lockedAddresses.add(lockedObject[0]);
368
+ });
369
+ });
370
+ // retry merging without the locked coins
371
+ i--;
372
+ continue;
373
+ }
374
+ throw e;
375
+ }
335
376
  const error = (0, sui_js_1.getExecutionStatusError)(mergeResult);
336
377
  if (error) {
337
378
  throw new Error(`Failed to merge coins when initializing gas pool: ${error}. Try re-running the script`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pythnetwork/price-pusher",
3
- "version": "5.4.8",
3
+ "version": "5.4.10",
4
4
  "description": "Pyth Price Pusher",
5
5
  "homepage": "https://pyth.network",
6
6
  "main": "lib/index.js",
@@ -63,5 +63,5 @@
63
63
  "yaml": "^2.1.1",
64
64
  "yargs": "^17.5.1"
65
65
  },
66
- "gitHead": "55129e5b891b0ce0271dbee69a8b4b7512a222d1"
66
+ "gitHead": "f41cf822ff404de523c9d4e34bed816e140cfa83"
67
67
  }