From dc4de6aa6cac11d6e93e73e48301114d5e033b2e Mon Sep 17 00:00:00 2001 From: Ken Vu Date: Thu, 5 Oct 2023 17:20:53 +1300 Subject: [PATCH] Add comment headers to make the code a bit clearer --- examples/substrate/use-feeProxy/src/callBatchAll.ts | 9 +++++++++ examples/substrate/use-feeProxy/src/callEVMCall.ts | 9 +++++++++ .../substrate/use-feeProxy/src/callProxyExtrinsic.ts | 11 ++++++++++- .../use-feeProxy/src/callProxyExtrinsicEVMCall.ts | 12 ++++++++++-- .../substrate/use-feeProxy/src/callSystemRemark.ts | 10 ++++++++++ 5 files changed, 48 insertions(+), 3 deletions(-) diff --git a/examples/substrate/use-feeProxy/src/callBatchAll.ts b/examples/substrate/use-feeProxy/src/callBatchAll.ts index 052cc9e..1a66027 100644 --- a/examples/substrate/use-feeProxy/src/callBatchAll.ts +++ b/examples/substrate/use-feeProxy/src/callBatchAll.ts @@ -16,6 +16,9 @@ interface AmountsIn { * Assumes the caller has some ASTO balance. */ withChainApi("porcini", async (api, caller, logger) => { + /** + * 1. Create `utility.batchAll` call that batches 3 transfer calls to ALICE, BOB & CHARLIE + */ const oneASTO = 1 * Math.pow(10, 18); // 1 ASTO in `wei` unit const transferToAliceCall = api.tx.assets.transfer(ASTO_ASSET_ID, ALICE, oneASTO.toString()); const transferToBobCall = api.tx.assets.transfer(ASTO_ASSET_ID, BOB, oneASTO.toString()); @@ -37,6 +40,9 @@ withChainApi("porcini", async (api, caller, logger) => { transferToCharlieCall, ]); + /** + * 2. Determine the `maxPayment` in ASTO by estimate the gas cost and use `dex` to get a quote + */ // we need a dummy feeProxy call (with maxPayment=0) to do a proper fee estimation const feeProxyCallForEstimation = api.tx.feeProxy.callWithFeePreferences( ASTO_ASSET_ID, @@ -58,6 +64,9 @@ withChainApi("porcini", async (api, caller, logger) => { // allow a buffer to avoid slippage, 5% const maxPayment = Number(amountIn * 1.05).toFixed(); + /** + * 3. Create and dispatch `feeProxy.callWithFeePreferences` extrinsic + */ logger.info( { parameters: { diff --git a/examples/substrate/use-feeProxy/src/callEVMCall.ts b/examples/substrate/use-feeProxy/src/callEVMCall.ts index e56333b..6642305 100644 --- a/examples/substrate/use-feeProxy/src/callEVMCall.ts +++ b/examples/substrate/use-feeProxy/src/callEVMCall.ts @@ -23,8 +23,14 @@ interface AmountsIn { * the transfer */ withChainApi("porcini", async (api, caller, logger) => { + /** + * 1. Create `emv.call` call + */ const { call: evmCall, estimateGasCost } = await createEVMCall(caller.address, api, logger); + /** + * 2. Determine the `maxPayment` in ASTO by estimate the gas cost and use `dex` to get a quote + */ // we need a dummy feeProxy call (with maxPayment=0) to do a proper fee estimation const feeProxyCallForEstimation = api.tx.feeProxy.callWithFeePreferences( ASTO_ASSET_ID, @@ -49,6 +55,9 @@ withChainApi("porcini", async (api, caller, logger) => { // allow a buffer to avoid slippage, 5% const maxPayment = Number(amountIn * 1.05).toFixed(); + /** + * 3. Create and dispatch `feeProxy.callWithFeePreferences` extrinsic + */ logger.info( { parameters: { diff --git a/examples/substrate/use-feeProxy/src/callProxyExtrinsic.ts b/examples/substrate/use-feeProxy/src/callProxyExtrinsic.ts index 73e4f7a..36b0d62 100644 --- a/examples/substrate/use-feeProxy/src/callProxyExtrinsic.ts +++ b/examples/substrate/use-feeProxy/src/callProxyExtrinsic.ts @@ -16,6 +16,9 @@ interface AmountsIn { * Assumes the caller has a valid Futurepass account and some ASTO balance to pay for gas. */ withChainApi("porcini", async (api, caller, logger) => { + /** + * 1. Create `futurepass.proxyExtrinsic` call that wraps around `system.remarkWithEvent` call + */ const fpAccount = (await api.query.futurepass.holders(caller.address)).unwrap(); logger.info( { @@ -31,7 +34,6 @@ withChainApi("porcini", async (api, caller, logger) => { // can be any extrinsic, using `system.remarkWithEvent` for simplicity const remarkCall = api.tx.system.remarkWithEvent("Hello World"); - // wrap `remarkCall` with `proxyCall`, effetively request Futurepass account to pay for gas logger.info( { parameters: { @@ -42,6 +44,10 @@ withChainApi("porcini", async (api, caller, logger) => { `create a "futurepass.proxyExtrinsic"` ); const futurepassCall = api.tx.futurepass.proxyExtrinsic(fpAccount, remarkCall); + + /** + * 2. Determine the `maxPayment` in ASTO by estimate the gas cost and use `dex` to get a quote + */ // we need a dummy feeProxy call (with maxPayment=0) to do a proper fee estimation const feeProxyCallForEstimation = api.tx.feeProxy.callWithFeePreferences( ASTO_ASSET_ID, @@ -62,6 +68,9 @@ withChainApi("porcini", async (api, caller, logger) => { // allow a buffer to avoid slippage, 5% const maxPayment = Number(amountIn * 1.05).toFixed(); + /** + * 3. Create and dispatch `feeProxy.callWithFeePreferences` extrinsic + */ logger.info( { parameters: { diff --git a/examples/substrate/use-feeProxy/src/callProxyExtrinsicEVMCall.ts b/examples/substrate/use-feeProxy/src/callProxyExtrinsicEVMCall.ts index 8e355eb..29aee31 100644 --- a/examples/substrate/use-feeProxy/src/callProxyExtrinsicEVMCall.ts +++ b/examples/substrate/use-feeProxy/src/callProxyExtrinsicEVMCall.ts @@ -25,6 +25,9 @@ interface AmountsIn { * some SYLO balance to demonstrate the transfer */ withChainApi("porcini", async (api, caller, logger) => { + /** + * 1. Create `futurepass.proxyExtrinsic` call that wraps around `evm.call` + */ const fpAccount = (await api.query.futurepass.holders(caller.address)).unwrap(); logger.info( { @@ -37,9 +40,7 @@ withChainApi("porcini", async (api, caller, logger) => { ); assert(fpAccount); - // can be any extrinsic, using `system.remarkWithEvent` for simplicity const { call: evmCall, estimateGasCost } = await createEVMCall(fpAccount.toString(), api, logger); - // wrap `remarkCall` with `proxyCall`, effetively request Futurepass account to pay for gas logger.info( { parameters: { @@ -50,6 +51,10 @@ withChainApi("porcini", async (api, caller, logger) => { `create a "futurepass.proxyExtrinsic"` ); const futurepassCall = api.tx.futurepass.proxyExtrinsic(fpAccount, evmCall); + + /** + * 2. Determine the `maxPayment` in ASTO by estimate the gas cost and use `dex` to get a quote + */ // we need a dummy feeProxy call (with maxPayment=0) to do a proper fee estimation const feeProxyCallForEstimation = api.tx.feeProxy.callWithFeePreferences( ASTO_ASSET_ID, @@ -73,6 +78,9 @@ withChainApi("porcini", async (api, caller, logger) => { // allow a buffer to avoid slippage, 5% const maxPayment = Number(amountIn * 1.05).toFixed(); + /** + * 3. Create and dispatch `feeProxy.callWithFeePreferences` extrinsic + */ logger.info( { parameters: { diff --git a/examples/substrate/use-feeProxy/src/callSystemRemark.ts b/examples/substrate/use-feeProxy/src/callSystemRemark.ts index 912d605..8e1b825 100644 --- a/examples/substrate/use-feeProxy/src/callSystemRemark.ts +++ b/examples/substrate/use-feeProxy/src/callSystemRemark.ts @@ -15,6 +15,9 @@ interface AmountsIn { * Assumes the caller has some ASTO balance. */ withChainApi("porcini", async (api, caller, logger) => { + /** + * 1. Create `system.remarkWithEvent` call + */ // can be any extrinsic, using `system.remarkWithEvent` for simplicity logger.info( { @@ -25,6 +28,10 @@ withChainApi("porcini", async (api, caller, logger) => { `create a "system.remarkWithEvent"` ); const remarkCall = api.tx.system.remarkWithEvent("Hello World"); + + /** + * 2. Determine the `maxPayment` in ASTO by estimate the gas cost and use `dex` to get a quote + */ // we need a dummy feeProxy call (with maxPayment=0) to do a proper fee estimation const feeProxyCallForEstimation = api.tx.feeProxy.callWithFeePreferences( ASTO_ASSET_ID, @@ -45,6 +52,9 @@ withChainApi("porcini", async (api, caller, logger) => { // allow a buffer to avoid slippage, 5% const maxPayment = Number(amountIn * 1.05).toFixed(); + /** + * 3. Create and dispatch `feeProxy.callWithFeePreferences` extrinsic + */ logger.info( { parameters: {