Skip to content

Commit

Permalink
Add comment headers to make the code a bit clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
ken-futureverse committed Oct 5, 2023
1 parent b683eb2 commit dc4de6a
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
9 changes: 9 additions & 0 deletions examples/substrate/use-feeProxy/src/callBatchAll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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,
Expand All @@ -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: {
Expand Down
9 changes: 9 additions & 0 deletions examples/substrate/use-feeProxy/src/callEVMCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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: {
Expand Down
11 changes: 10 additions & 1 deletion examples/substrate/use-feeProxy/src/callProxyExtrinsic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand All @@ -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: {
Expand All @@ -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,
Expand All @@ -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: {
Expand Down
12 changes: 10 additions & 2 deletions examples/substrate/use-feeProxy/src/callProxyExtrinsicEVMCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand All @@ -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: {
Expand All @@ -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,
Expand All @@ -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: {
Expand Down
10 changes: 10 additions & 0 deletions examples/substrate/use-feeProxy/src/callSystemRemark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{
Expand All @@ -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,
Expand All @@ -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: {
Expand Down

0 comments on commit dc4de6a

Please sign in to comment.