瀏覽代碼

Add option to choose a different account derived from the same mnemonic (#1116)

This is useful for running 2 pushers in parallel
Amin Moghaddam 2 年之前
父節點
當前提交
99eaab878d
共有 4 個文件被更改,包括 20 次插入16 次删除
  1. 1 3
      package-lock.json
  2. 1 1
      price_pusher/package.json
  3. 13 4
      price_pusher/src/sui/command.ts
  4. 5 8
      price_pusher/src/sui/sui.ts

+ 1 - 3
package-lock.json

@@ -29861,7 +29861,6 @@
       "version": "4.0.5",
       "resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.5.tgz",
       "integrity": "sha512-HTm14iMQKK2FjFLRTM5lAVcyaUzOnqbPtesFIvREgXpJHdQm8bWS+GkQgIkfaBYRHuCnea7w8UVNfwiAQhlr9A==",
-      "hasInstallScript": true,
       "optional": true,
       "dependencies": {
         "node-gyp-build": "^4.3.0"
@@ -30191,7 +30190,6 @@
       "version": "5.0.7",
       "resolved": "https://registry.npmjs.org/utf-8-validate/-/utf-8-validate-5.0.7.tgz",
       "integrity": "sha512-vLt1O5Pp+flcArHGIyKEQq883nBt8nN8tVBcoL0qUXj2XT1n7p70yGIq2VK98I5FdZ1YHc0wk/koOnHjnXWk1Q==",
-      "hasInstallScript": true,
       "optional": true,
       "dependencies": {
         "node-gyp-build": "^4.3.0"
@@ -54809,7 +54807,7 @@
     },
     "price_pusher": {
       "name": "@pythnetwork/price-pusher",
-      "version": "5.6.3",
+      "version": "5.7.0",
       "license": "Apache-2.0",
       "dependencies": {
         "@injectivelabs/sdk-ts": "1.10.72",

+ 1 - 1
price_pusher/package.json

@@ -1,6 +1,6 @@
 {
   "name": "@pythnetwork/price-pusher",
-  "version": "5.6.3",
+  "version": "5.7.0",
   "description": "Pyth Price Pusher",
   "homepage": "https://pyth.network",
   "main": "lib/index.js",

+ 13 - 4
price_pusher/src/sui/command.ts

@@ -50,6 +50,12 @@ export default {
       required: true,
       default: 500_000_000,
     } as Options,
+    "account-index": {
+      description: "Index of the account to use derived by the mnemonic",
+      type: "number",
+      required: true,
+      default: 0,
+    } as Options,
     ...options.priceConfigFile,
     ...options.priceServiceEndpoint,
     ...options.mnemonicFile,
@@ -68,6 +74,7 @@ export default {
       wormholeStateId,
       numGasObjects,
       gasBudget,
+      accountIndex,
     } = argv;
 
     const priceConfigs = readPriceConfigFile(priceConfigFile);
@@ -88,10 +95,12 @@ export default {
       }
     );
     const mnemonic = fs.readFileSync(mnemonicFile, "utf-8").trim();
+    const keypair = Ed25519Keypair.deriveKeypair(
+      mnemonic,
+      `m/44'/784'/${accountIndex}'/0'/0'`
+    );
     console.log(
-      `Pushing updates from wallet address: ${Ed25519Keypair.deriveKeypair(
-        mnemonic
-      )
+      `Pushing updates from wallet address: ${keypair
         .getPublicKey()
         .toSuiAddress()}`
     );
@@ -115,7 +124,7 @@ export default {
       pythStateId,
       wormholeStateId,
       endpoint,
-      mnemonic,
+      keypair,
       gasBudget,
       numGasObjects
     );

+ 5 - 8
price_pusher/src/sui/sui.ts

@@ -121,7 +121,7 @@ export class SuiPricePusher implements IPricePusher {
     private wormholePackageId: string,
     private wormholeStateId: string,
     endpoint: string,
-    mnemonic: string,
+    keypair: Ed25519Keypair,
     private gasBudget: number,
     private gasPool: SuiObjectRef[],
     private pythClient: SuiPythClient
@@ -162,14 +162,14 @@ export class SuiPricePusher implements IPricePusher {
 
   /**
    * Create a price pusher with a pool of `numGasObjects` gas coins that will be used to send transactions.
-   * The gas coins of the wallet for the provided mnemonic will be merged and then evenly split into `numGasObjects`.
+   * The gas coins of the wallet for the provided keypair will be merged and then evenly split into `numGasObjects`.
    */
   static async createWithAutomaticGasPool(
     priceServiceConnection: PriceServiceConnection,
     pythStateId: string,
     wormholeStateId: string,
     endpoint: string,
-    mnemonic: string,
+    keypair: Ed25519Keypair,
     gasBudget: number,
     numGasObjects: number
   ): Promise<SuiPricePusher> {
@@ -182,10 +182,7 @@ export class SuiPricePusher implements IPricePusher {
     const provider = new JsonRpcProvider(
       new Connection({ fullnode: endpoint })
     );
-    const signer = new RawSigner(
-      Ed25519Keypair.deriveKeypair(mnemonic),
-      provider
-    );
+    const signer = new RawSigner(keypair, provider);
     const pythPackageId = await SuiPricePusher.getPackageId(
       provider,
       pythStateId
@@ -214,7 +211,7 @@ export class SuiPricePusher implements IPricePusher {
       wormholePackageId,
       wormholeStateId,
       endpoint,
-      mnemonic,
+      keypair,
       gasBudget,
       gasPool,
       pythClient