Created
December 17, 2023 12:44
-
-
Save PrasoonPratham/32dd94e46ec5ab811a6b5067cc98bb2c to your computer and use it in GitHub Desktop.
JavaScript version of config creation script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { Keypair, PublicKey } = require("@solana/web3.js"); | |
| const { | |
| WhirlpoolContext, | |
| ORCA_WHIRLPOOL_PROGRAM_ID, | |
| WhirlpoolIx, | |
| } = require("@orca-so/whirlpools-sdk"); | |
| const { TransactionBuilder } = require("@orca-so/common-sdk"); | |
| const { AnchorProvider } = require("@coral-xyz/anchor"); | |
| const prompt = require("prompt"); | |
| // Environment variables | |
| const provider = AnchorProvider.env(); | |
| console.log("connection endpoint", provider.connection.rpcEndpoint); | |
| console.log("wallet", provider.wallet.publicKey.toBase58()); | |
| async function main() { | |
| const ctx = WhirlpoolContext.from( | |
| provider.connection, | |
| provider.wallet, | |
| "HTWRBni325rpsAev5NihDjYPGXtf49BFdRbeTHQJeyTv" | |
| ); | |
| console.log("create WhirlpoolsConfig..."); | |
| // Define a prompt schema | |
| const schema = { | |
| properties: { | |
| feeAuthorityPubkey: { | |
| description: "Enter feeAuthorityPubkey", | |
| type: "string", | |
| required: true, | |
| }, | |
| collectProtocolFeesAuthorityPubkey: { | |
| description: "Enter collectProtocolFeesAuthorityPubkey", | |
| type: "string", | |
| required: true, | |
| }, | |
| rewardEmissionsSuperAuthorityPubkey: { | |
| description: "Enter rewardEmissionsSuperAuthorityPubkey", | |
| type: "string", | |
| required: true, | |
| }, | |
| defaultProtocolFeeRatePer10000: { | |
| description: "Enter defaultProtocolFeeRatePer10000", | |
| type: "string", | |
| required: true, | |
| }, | |
| }, | |
| }; | |
| prompt.start(); // Initialize the prompt | |
| // Use the schema in prompt.get | |
| const result = await new Promise((resolve, reject) => { | |
| prompt.get(schema, (err, result) => { | |
| if (err) { | |
| reject(err); | |
| } else { | |
| resolve(result); | |
| } | |
| }); | |
| }); | |
| const configKeypair = Keypair.generate(); | |
| const builder = new TransactionBuilder(ctx.connection, ctx.wallet); | |
| builder.addInstruction( | |
| WhirlpoolIx.initializeConfigIx(ctx.program, { | |
| whirlpoolsConfigKeypair: configKeypair, | |
| funder: ctx.wallet.publicKey, | |
| feeAuthority: new PublicKey(result.feeAuthorityPubkey), | |
| collectProtocolFeesAuthority: new PublicKey( | |
| result.collectProtocolFeesAuthorityPubkey | |
| ), | |
| rewardEmissionsSuperAuthority: new PublicKey( | |
| result.rewardEmissionsSuperAuthorityPubkey | |
| ), | |
| defaultProtocolFeeRate: Number.parseInt( | |
| result.defaultProtocolFeeRatePer10000 | |
| ), | |
| }) | |
| ); | |
| const sig = await builder.buildAndExecute(); | |
| console.log("tx:", sig); | |
| console.log("whirlpoolsConfig address:", configKeypair.publicKey.toBase58()); | |
| } | |
| main(); | |
| /* | |
| Output | |
| node orca/whirlpool/whirlpools_sdk/create_own_whirlpools/tools/01_create_config.js | |
| connection endpoint https://staging-rpc.dev.eclipsenetwork.xyz | |
| wallet EBAoQ8GFS4QtVBsdbTGPYwrZhHDiUiJDWgvsaeqXFFR8 | |
| create WhirlpoolsConfig... | |
| prompt: Enter feeAuthorityPubkey: EBAoQ8GFS4QtVBsdbTGPYwrZhHDiUiJDWgvsaeqXFFR8 | |
| prompt: Enter collectProtocolFeesAuthorityPubkey: EBAoQ8GFS4QtVBsdbTGPYwrZhHDiUiJDWgvsaeqXFFR8 | |
| prompt: Enter rewardEmissionsSuperAuthorityPubkey: EBAoQ8GFS4QtVBsdbTGPYwrZhHDiUiJDWgvsaeqXFFR8 | |
| prompt: Enter defaultProtocolFeeRatePer10000: 300 | |
| /Users/pratham/Documents/GitHub/solsandbox/node_modules/@solana/web3.js/lib/index.cjs.js:9560 | |
| throw new SendTransactionError('failed to send transaction: ' + res.error.message, logs); | |
| ^ | |
| SendTransactionError: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: Program failed to complete | |
| at Connection.sendEncodedTransaction (/Users/pratham/Documents/GitHub/solsandbox/node_modules/@solana/web3.js/lib/index.cjs.js:9560:13) | |
| at processTicksAndRejections (node:internal/process/task_queues:96:5) | |
| at async Connection.sendRawTransaction (/Users/pratham/Documents/GitHub/solsandbox/node_modules/@solana/web3.js/lib/index.cjs.js:9526:20) | |
| at async Connection.sendTransaction (/Users/pratham/Documents/GitHub/solsandbox/node_modules/@solana/web3.js/lib/index.cjs.js:9482:14) | |
| at async TransactionBuilder.buildAndExecute (/Users/pratham/Documents/GitHub/solsandbox/node_modules/@orca-so/common-sdk/dist/web3/transactions/transactions-builder.js:191:20) | |
| at async main (/Users/pratham/Documents/GitHub/solsandbox/orca/whirlpool/whirlpools_sdk/create_own_whirlpools/tools/01_create_config.js:84:15) { | |
| logs: [ | |
| 'Program HTWRBni325rpsAev5NihDjYPGXtf49BFdRbeTHQJeyTv invoke [1]', | |
| 'Program log: Instruction: InitializeConfig', | |
| 'Program HTWRBni325rpsAev5NihDjYPGXtf49BFdRbeTHQJeyTv consumed 4208 of 200000 compute units', | |
| 'Program failed to complete: Invoked an instruction with data that is too large (12884934228 > 10240)', | |
| 'Program HTWRBni325rpsAev5NihDjYPGXtf49BFdRbeTHQJeyTv failed: Program failed to complete' | |
| ] | |
| } | |
| Node.js v17.3.0 | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment