AvaProtocol / xcm-demo

Javascript usage of OAK’s XCM automation with parachains including Moonbeam, Astar and Mangata.
https://docs.oak.tech/docs/xcm/integration-overview/
4 stars 5 forks source link

Add XCM demo for both Moonbase and Moonbase Alpha #40

Closed imstar15 closed 1 year ago

imstar15 commented 1 year ago

Moonbase alpha environment

  1. Place seed.json(for Turing) and seed-eth.json(for Moonbase) in 'private' folder.

  2. Make sure you have 25 TUR in Turing for the reserved fee required to add the proxy and the execution fee for automationTime.

  3. Make sure you have 5 DEV in Moonbase, we will transfer some to Turing's proxy account and pay the execution fee.

  4. Run the program to schedule automation and wait for cross-chain execution

    PASS_PHRASE=<PASS_PHRASE> PASS_PHRASE_ETH=<PASS_PHRASE_ETH> npm run moonbase-alpha
> moonbase-alpha
> dotenv -e .env babel-node src/moonbeam/moonbase-alpha.js

2023-03-10 14:16:41        API/INIT: RPC methods not decorated: moon_isBlockFinalized, moon_isTxFinalized, transaction_unstable_submitAndWatch, transaction_unstable_unwatch
2023-03-10 14:16:41        API/INIT: moonbase/2201: Not decorating unknown runtime apis: 0xa33d43f58731ad84/2, 0xba8173bf23b2e6f8/1

1. Setup accounts on turing-moonbase-alpha and moonbase-alpha
Parachain address:  0x1e6aEeA3f2ea34F149aE00c174Fe85CEc2f55109
Parachain balance: 2999940019110102511
[
  {
    tokens: [],
    chain: 'turing-moonbase-alpha',
    address: '68gXMRJzd8ccrhoRDuDew9V6X2N9yFe9MTLpicxion8DqZzf'
  }
]
paraTokenIdOnTuring:  1
proxyOnTuring:  6BgBcpDpXwPtQzu5LZ4iv7WTDoBqDu5Pjw8u1D9mFrHeyBik

2. One-time proxy setup on Turing

a) Add a proxy for Alice If there is none setup on Turing (paraId:1000)

Proxy address 6BgBcpDpXwPtQzu5LZ4iv7WTDoBqDu5Pjw8u1D9mFrHeyBik for paraId: 1000 and proxyType: Any already exists; skipping creation ...

b) Reserve transfer DEV to the proxy account on Turing: 
minBalanceOnTuring:  <BN: de0b6b3a7640000>
paraTokenbalanceOnTuring.free:  986201600000000000
Transfer DEV from Moonbase to Turing
Resevered transfer call data:  0x1e0101000001040300130000c84e676dc11b0101020009210100f478592a94fd870066f573bb76e2a88c3b0eb680ba460eec5c6023403151d63800
status.type Ready
status.type Broadcast
status.type InBlock
status.type Finalized

User XcmTest3 turing-moonbase-alpha address: 68gXMRJzd8ccrhoRDuDew9V6X2N9yFe9MTLpicxion8DqZzf, moonbase-alpha address: 0x1e6aEeA3f2ea34F149aE00c174Fe85CEc2f55109

3. Execute an XCM from moonbase-alpha to turing-moonbase-alpha ...

a). Create a payload to store in Turing’s task ...
Task extrinsic encoded call data: 0x3c046c78636d705f6175746f6d6174696f6e5f746573745f61673373386b000470d50a640000000000082048656c6c6f212121
Encoded call data: 0x20000070061496e1811eef1f930e0e17cea6ffb8a261e3ad7fe5de832e6901b373a41e01003c046c78636d705f6175746f6d6174696f6e5f746573745f61673373386b000470d50a640000000000082048656c6c6f212121
requireWeightAtMost: 868992000

b) Execute the above an XCM from Moonbase Alpha to schedule a task on Turing Moonbase Alpha ...
transactRequiredWeightAtMost:  1868992000
overallWeight:  8170208000
fungible:  486899200000000000
transactExtrinsic Encoded call data: 0x210601010100092100000100006c213ed0c1060000000000000000610120000070061496e1811eef1f930e0e17cea6ffb8a261e3ad7fe5de832e6901b373a41e01003c046c78636d705f6175746f6d6174696f6e5f746573745f61673373386b000470d50a640000000000082048656c6c6f212121008e666f0000000001007bfbe601000000
status.type Ready
status.type Broadcast
status.type InBlock
status.type Finalized
Reached the end of main() ...

Send XCM from Moonbase https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fwss.api.moonbase.moonbeam.network#/explorer/query/0x6a20ff9b873cea0a0b2b978accce976caab083f42da9382f8c6428fd2480f5e1

image

Receive XCM on Turing http://167.99.226.24:3000/?rpc=ws%3A%2F%2F167.99.226.24%3A8846#/explorer/query/0xc192a0637d7d578eaede1dc02d43bcd9e17cdf337c2dd6b108a3c7c7de0db982

image