diff --git a/.changeset/fifty-phones-float.md b/.changeset/fifty-phones-float.md new file mode 100644 index 0000000000..1d8f4a92b8 --- /dev/null +++ b/.changeset/fifty-phones-float.md @@ -0,0 +1,5 @@ +--- +'@kadena/graph': patch +--- + +Enabled option for different gas payers in simulation diff --git a/packages/apps/graph/README.md b/packages/apps/graph/README.md index aa67908b26..9b7b383373 100644 --- a/packages/apps/graph/README.md +++ b/packages/apps/graph/README.md @@ -36,7 +36,9 @@ pnpm build --filter @kadena/graph... 2. Start devnet: - > **NOTE:** This project has a built-in command to create and start devnet. For the full guide visit the quickstart page on the documentation website [here](https://docs.kadena.io/build/quickstart). + > **NOTE:** This project has a built-in command to create and start devnet. + > For the full guide visit the quickstart page on the documentation website + > [here](https://docs.kadena.io/build/quickstart). ```sh pnpm run devnet @@ -51,8 +53,7 @@ pnpm build --filter @kadena/graph... the image by adding `--pull=always` after `docker run` in the `devnet` script. - If something goes wrong, you can delete the volume, and try to - start again: + If something goes wrong, you can delete the volume, and try to start again: ```sh docker volume rm kadena_devnet @@ -120,10 +121,10 @@ transactions are different, with different amounts and to and from different chains. The new number is generated using the previous one as seed. ```sh -npm run simulate -- -a -i -t -tp -s +npm run simulate -a -i -t -tp -s ``` -- accounts - number of accounts to be created in the devnet (default: 5) +- numberOfAccounts - number of accounts to be created in the devnet (default: 6) - timeInterval - frequency of transactions in miliseconds (default: 100) - maxAmount - maximum amount for a single transaction (default: 25) - tokenPool - amount of circulating tokens (default: 1000000) diff --git a/packages/apps/graph/src/devnet/crosschain-transfer.ts b/packages/apps/graph/src/devnet/crosschain-transfer.ts index 6a9aae28b9..f624187980 100644 --- a/packages/apps/graph/src/devnet/crosschain-transfer.ts +++ b/packages/apps/graph/src/devnet/crosschain-transfer.ts @@ -74,13 +74,30 @@ export async function crossChainTransfer({ from, to, amount, + gasPayer = sender00, }: { from: IAccount; to: IAccount; amount: number; + gasPayer?: IAccount; }): Promise { + // Gas Payer validations + if (gasPayer.chainId !== to.chainId) { + logger.info( + `Gas payer ${gasPayer.account} does not for sure have an account on the receiver chain; using sender00 as gas payer`, + ); + gasPayer = sender00; + } + + if (!gasPayer.secretKey) { + logger.info( + `Gas payer ${gasPayer.account} does not have a secret key; using sender00 as gas payer`, + ); + gasPayer = sender00; + } + logger.info( - `Crosschain Transfer from ${from.account}, chain ${from.chainId}\nTo ${to.account}, chain ${to.chainId}\nAmount: ${amount}`, + `Crosschain Transfer from ${from.account}, chain ${from.chainId}\nTo ${to.account}, chain ${to.chainId}\nAmount: ${amount}\nGas Payer: ${gasPayer.account}`, ); const pactAmount = new PactNumber(amount).toPactDecimal(); @@ -113,9 +130,10 @@ export async function crossChainTransfer({ const unsignedTx2 = finishInTheTargetChain( continuation, to.chainId || devnetConfig.CHAIN_ID, + gasPayer, ); - const signedTx2 = signAndAssertTransaction([sender00])(unsignedTx2); + const signedTx2 = signAndAssertTransaction([gasPayer])(unsignedTx2); const submittedTx2 = await submit(signedTx2); inspect('Transfer Submited')(submittedTx2); const status2 = await listen(submittedTx2); diff --git a/packages/apps/graph/src/devnet/simulation/simulate.ts b/packages/apps/graph/src/devnet/simulation/simulate.ts index 2574fdb21f..69de802e08 100644 --- a/packages/apps/graph/src/devnet/simulation/simulate.ts +++ b/packages/apps/graph/src/devnet/simulation/simulate.ts @@ -10,6 +10,7 @@ import { isEqualChainAccounts, logger, seedRandom, + sender00, } from '../helper'; import { safeTransfer } from '../safe-transfer'; import { transfer } from '../transfer'; @@ -23,8 +24,8 @@ const simualtionTransferOptions: TransferType[] = [ ]; export async function simulate({ - numberOfAccounts = 2, - transferInterval = 1000, + numberOfAccounts = 6, + transferInterval = 100, maxAmount = 25, tokenPool = 1000000, seed = Date.now().toString(), @@ -134,11 +135,17 @@ export async function simulate({ continue; } - logger.info('Cross chain transfer', account, nextAccount); + // Get a random account to potentially pay for the gas + const possibleGasPayer = getRandomOption(seededRandomNo, accounts); + result = await crossChainTransfer({ from: account, to: nextAccount, amount, + gasPayer: + possibleGasPayer.chainId === nextAccount.chainId + ? possibleGasPayer + : sender00, }); } else { // Make sure the chain id is the same if the transfer type is transfer or safe-transfer