Skip to content

Commit

Permalink
Add option to choose a different account derived from the same mnemon…
Browse files Browse the repository at this point in the history
…ic (#1116)

This is useful for running 2 pushers in parallel
  • Loading branch information
m30m authored Oct 20, 2023
1 parent 8b721c3 commit 99eaab8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
4 changes: 1 addition & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion price_pusher/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
17 changes: 13 additions & 4 deletions price_pusher/src/sui/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -68,6 +74,7 @@ export default {
wormholeStateId,
numGasObjects,
gasBudget,
accountIndex,
} = argv;

const priceConfigs = readPriceConfigFile(priceConfigFile);
Expand All @@ -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()}`
);
Expand All @@ -115,7 +124,7 @@ export default {
pythStateId,
wormholeStateId,
endpoint,
mnemonic,
keypair,
gasBudget,
numGasObjects
);
Expand Down
13 changes: 5 additions & 8 deletions price_pusher/src/sui/sui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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> {
Expand All @@ -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
Expand Down Expand Up @@ -214,7 +211,7 @@ export class SuiPricePusher implements IPricePusher {
wormholePackageId,
wormholeStateId,
endpoint,
mnemonic,
keypair,
gasBudget,
gasPool,
pythClient
Expand Down

0 comments on commit 99eaab8

Please sign in to comment.