Skip to content

Commit

Permalink
Add asset-transfer-api docs (#16)
Browse files Browse the repository at this point in the history
* Init asset-transfer-api docs

* Add overview

* wip: add params & result types

* Add types

* Add examples

* Add support info and add notes

* Improve example

* Update docs/build-on-polkadot/xcm/asset-transfer-api.md

Co-authored-by: Nicolás Hussein <[email protected]>

* Update docs/build-on-polkadot/xcm/asset-transfer-api.md

Co-authored-by: Nicolás Hussein <[email protected]>

* Improve setup docs

* Fix note

* Replace assetId with asset ID

* Add sentence before terminal output

* demo api docs

* Remove spaces

* Add API Reference and improve overview

* Update docs/build-on-polkadot/xcm/asset-transfer-api/reference.md

Co-authored-by: Nicolás Hussein <[email protected]>

* Update docs/.snippets/code/build-on-polkadot/xcm/asset-transfer-api/reference/tx-result.md

Co-authored-by: Nicolás Hussein <[email protected]>

* Replace js with ts in code snippet

* Add decodeExtrinsic and fetchFeeInfo

* Update docs/build-on-polkadot/xcm/asset-transfer-api/overview.md

Co-authored-by: Dawn Kelly <[email protected]>

* Add ts project setup

* Fix termynal output

* Update docs/build-on-polkadot/xcm/asset-transfer-api.md

Co-authored-by: Dawn Kelly <[email protected]>

* Update docs/build-on-polkadot/xcm/asset-transfer-api/reference.md

Co-authored-by: Dawn Kelly <[email protected]>

* Update docs/build-on-polkadot/xcm/asset-transfer-api/reference.md

Co-authored-by: Dawn Kelly <[email protected]>

* Update docs/build-on-polkadot/xcm/asset-transfer-api/reference.md

Co-authored-by: Erin Shaben <[email protected]>

* Update docs/build-on-polkadot/xcm/asset-transfer-api/overview.md

Co-authored-by: Erin Shaben <[email protected]>

* Update docs/build-on-polkadot/xcm/asset-transfer-api/overview.md

Co-authored-by: Erin Shaben <[email protected]>

* Update docs/build-on-polkadot/xcm/asset-transfer-api/reference.md

Co-authored-by: Erin Shaben <[email protected]>

* Update docs/build-on-polkadot/xcm/asset-transfer-api/overview.md

Co-authored-by: Erin Shaben <[email protected]>

* Update docs/build-on-polkadot/xcm/asset-transfer-api/overview.md

Co-authored-by: Erin Shaben <[email protected]>

* Remove comment

* Update description

* Fix whitespaces and periods

* Update headers

* Update createTransferTransaction description

* Fix descriptions

* Update docs/build-on-polkadot/xcm/asset-transfer-api/reference.md

Co-authored-by: Erin Shaben <[email protected]>

* Add transfer to headers

* Move setup script to snippets

* Fix code format

* Add missing {target=_blank}

* Delete unused file

* Fix variables for asset_transfer_api

* Update docs/build-on-polkadot/xcm/asset-transfer-api/overview.md

Co-authored-by: Dawn Kelly <[email protected]>

* update styling of interface and child admonitions on light mode

* Update docs/.snippets/code/build-on-polkadot/xcm/asset-transfer-api/overview/setup.ts

Co-authored-by: Erin Shaben <[email protected]>

* Update docs/build-on-polkadot/xcm/asset-transfer-api/overview.md

Co-authored-by: Erin Shaben <[email protected]>

* Update docs/build-on-polkadot/xcm/asset-transfer-api/reference.md

Co-authored-by: Erin Shaben <[email protected]>

* Update docs/.snippets/code/build-on-polkadot/xcm/asset-transfer-api/reference/transfer-arg-opts.md

Co-authored-by: Erin Shaben <[email protected]>

* Update docs/.snippets/code/build-on-polkadot/xcm/asset-transfer-api/reference/tx-result.md

Co-authored-by: Erin Shaben <[email protected]>

* Update docs/.snippets/code/build-on-polkadot/xcm/asset-transfer-api/reference/tx-result.md

Co-authored-by: Erin Shaben <[email protected]>

* Update docs/.snippets/code/build-on-polkadot/xcm/asset-transfer-api/reference/transfer-arg-opts.md

Co-authored-by: Erin Shaben <[email protected]>

* Update docs/.snippets/code/build-on-polkadot/xcm/asset-transfer-api/reference/transfer-arg-opts.md

Co-authored-by: Erin Shaben <[email protected]>

* Update docs/.snippets/code/build-on-polkadot/xcm/asset-transfer-api/reference/transfer-arg-opts.md

Co-authored-by: Erin Shaben <[email protected]>

* Add links

* Update docs/.snippets/code/build-on-polkadot/xcm/asset-transfer-api/reference/transfer-arg-opts.md

Co-authored-by: Erin Shaben <[email protected]>

* Update docs/.snippets/code/build-on-polkadot/xcm/asset-transfer-api/reference/tx-result.md

Co-authored-by: Erin Shaben <[email protected]>

* Update docs/.snippets/code/build-on-polkadot/xcm/asset-transfer-api/reference/tx-result.md

Co-authored-by: Erin Shaben <[email protected]>

* Update docs/.snippets/code/build-on-polkadot/xcm/asset-transfer-api/reference/tx-result.md

Co-authored-by: Erin Shaben <[email protected]>

* Update docs/build-on-polkadot/xcm/asset-transfer-api/reference.md

Co-authored-by: Erin Shaben <[email protected]>

* Replace duplicated code with snippets

* Update docs/.snippets/code/build-on-polkadot/xcm/asset-transfer-api/reference/constructed-format.md

Co-authored-by: Erin Shaben <[email protected]>

---------

Co-authored-by: Nicolás Hussein <[email protected]>
Co-authored-by: Erin Shaben <[email protected]>
Co-authored-by: Dawn Kelly <[email protected]>
  • Loading branch information
4 people authored Aug 23, 2024
1 parent 75336b4 commit 3cdbd28
Show file tree
Hide file tree
Showing 33 changed files with 1,331 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<div id="termynal" data-termynal>
<span data-ty="input"><span class="file-path"></span>ts-node localParachainTx.ts</span>
<br>
<span data-ty>Call data:</span>
<span data-ty>{</span>
<span data-ty> "origin": "moonbeam",</span>
<span data-ty> "dest": "moonbeam",</span>
<span data-ty> "direction": "local",</span>
<span data-ty> "xcmVersion": null,</span>
<span data-ty> "method": "balances::transferKeepAlive",</span>
<span data-ty> "format": "call",</span>
<span data-ty> "tx": "0x0a03f977814e90da44bfa03b6295a0616a897441acec821a0600"</span>
<span data-ty>}</span>
<span data-ty></span>
<span data-ty>Decoded tx:</span>
<span data-ty>{</span>
<span data-ty> "args": {</span>
<span data-ty> "dest": "0xF977814e90dA44bFA03b6295A0616a897441aceC",</span>
<span data-ty> "value": "1,000,000,000,000,000,000"</span>
<span data-ty> },</span>
<span data-ty> "method": "transferKeepAlive",</span>
<span data-ty> "section": "balances"</span>
<span data-ty>}</span>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {
AssetTransferApi,
constructApiPromise,
} from "@substrate/asset-transfer-api";

async function main() {
const { api, specName, safeXcmVersion } = await constructApiPromise(
"wss://wss.api.moonbeam.network"
);
const assetApi = new AssetTransferApi(api, specName, safeXcmVersion);

let callInfo;
try {
callInfo = await assetApi.createTransferTransaction(
"2004",
"0xF977814e90dA44bFA03b6295A0616a897441aceC",
[],
["1000000000000000000"],
{
format: "call",
keepAlive: true,
}
);

console.log(`Call data:\n${JSON.stringify(callInfo, null, 4)}`);
} catch (e) {
console.error(e);
throw Error(e as string);
}

const decoded = assetApi.decodeExtrinsic(callInfo.tx, "call");
console.log(`\nDecoded tx:\n${JSON.stringify(JSON.parse(decoded), null, 4)}`);
}

main()
.catch((err) => console.error(err))
.finally(() => process.exit());
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<div id='termynal' data-termynal>
<span data-ty='input'><span class='file-path'></span>ts-node paraToPara.ts</span>

<br>
<span data-ty>Call data:</span>
<span data-ty>{</span>
<span data-ty> "origin": "moonriver",</span>
<span data-ty> "dest": "bifrost",</span>
<span data-ty> "direction": "ParaToPara",</span>
<span data-ty> "xcmVersion": 2,</span>
<span data-ty> "method": "transferMultiassets",</span>
<span data-ty> "format": "call",</span>
<span data-ty> "tx": "0x6a05010800010200451f06080101000700e40b540200010200451f0608010a0002093d000000000001010200451f0100c4db7bcb733e117c0b34ac96354b10d47e84a006b9e7e66a229d174e8ff2a06300"</span>
<span data-ty>}</span>
<span data-ty></span>
<span data-ty>Decoded tx:</span>
<span data-ty>{</span>
<span data-ty> "args": {</span>
<span data-ty> "assets": {</span>
<span data-ty> "V2": [</span>
<span data-ty> {</span>
<span data-ty> "id": {</span>
<span data-ty> "Concrete": {</span>
<span data-ty> "parents": "1",</span>
<span data-ty> "interior": {</span>
<span data-ty> "X2": [</span>
<span data-ty> {</span>
<span data-ty> "Parachain": "2,001"</span>
<span data-ty> },</span>
<span data-ty> {</span>
<span data-ty> "GeneralKey": "0x0101"</span>
<span data-ty> }</span>
<span data-ty> ]</span>
<span data-ty> }</span>
<span data-ty> }</span>
<span data-ty> },</span>
<span data-ty> "fun": {</span>
<span data-ty> "Fungible": "10,000,000,000"</span>
<span data-ty> }</span>
<span data-ty> },</span>
<span data-ty> {</span>
<span data-ty> "id": {</span>
<span data-ty> "Concrete": {</span>
<span data-ty> "parents": "1",</span>
<span data-ty> "interior": {</span>
<span data-ty> "X2": [</span>
<span data-ty> {</span>
<span data-ty> "Parachain": "2,001"</span>
<span data-ty> },</span>
<span data-ty> {</span>
<span data-ty> "GeneralKey": "0x010a"</span>
<span data-ty> }</span>
<span data-ty> ]</span>
<span data-ty> }</span>
<span data-ty> }</span>
<span data-ty> },</span>
<span data-ty> "fun": {</span>
<span data-ty> "Fungible": "1,000,000"</span>
<span data-ty> }</span>
<span data-ty> }</span>
<span data-ty> ]</span>
<span data-ty> },</span>
<span data-ty> "fee_item": "0",</span>
<span data-ty> "dest": {</span>
<span data-ty> "V2": {</span>
<span data-ty> "parents": "1",</span>
<span data-ty> "interior": {</span>
<span data-ty> "X2": [</span>
<span data-ty> {</span>
<span data-ty> "Parachain": "2,001"</span>
<span data-ty> },</span>
<span data-ty> {</span>
<span data-ty> "AccountId32": {</span>
<span data-ty> "network": "Any",</span>
<span data-ty> "id": "0xc4db7bcb733e117c0b34ac96354b10d47e84a006b9e7e66a229d174e8ff2a063"</span>
<span data-ty> }</span>
<span data-ty> }</span>
<span data-ty> ]</span>
<span data-ty> }</span>
<span data-ty> }</span>
<span data-ty> },</span>
<span data-ty> "dest_weight_limit": "Unlimited"</span>
<span data-ty> },</span>
<span data-ty> "method": "transferMultiassets",</span>
<span data-ty> "section": "xTokens"</span>
<span data-ty>}</span>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {
AssetTransferApi,
constructApiPromise,
} from "@substrate/asset-transfer-api";

async function main() {
const { api, specName, safeXcmVersion } = await constructApiPromise(
"wss://moonriver.public.blastapi.io"
);
const assetApi = new AssetTransferApi(api, specName, safeXcmVersion);
let callInfo;
try {
callInfo = await assetApi.createTransferTransaction(
"2001",
"0xc4db7bcb733e117c0b34ac96354b10d47e84a006b9e7e66a229d174e8ff2a063",
["vMOVR", "72145018963825376852137222787619937732"],
["1000000", "10000000000"],
{
format: "call",
xcmVersion: safeXcmVersion,
}
);

console.log(`Call data:\n${JSON.stringify(callInfo, null, 4)}`);
} catch (e) {
console.error(e);
throw Error(e as string);
}

const decoded = assetApi.decodeExtrinsic(callInfo.tx, "call");
console.log(`\nDecoded tx:\n${JSON.stringify(JSON.parse(decoded), null, 4)}`);
}

main()
.catch((err) => console.error(err))
.finally(() => process.exit());
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<div id="termynal" data-termynal>
<span data-ty="input"><span class="file-path"></span>ts-node relayToSystem.ts</span>
<br>
<span data-ty>Call data:</span>
<span data-ty>{</span>
<span data-ty> "origin": "westend",</span>
<span data-ty> "dest": "westmint",</span>
<span data-ty> "direction": "RelayToSystem",</span>
<span data-ty> "xcmVersion": 3,</span>
<span data-ty> "method": "transferAssets",</span>
<span data-ty> "format": "call",</span>
<span data-ty> "tx": "0x630b03000100a10f03000101006c0c32faf970eacb2d4d8e538ac0dab3642492561a1be6f241c645876c056c1d030400000000070010a5d4e80000000000"</span>
<span data-ty>}</span>
<span data-ty></span>
<span data-ty>Decoded tx:</span>
<span data-ty>{</span>
<span data-ty> "args": {</span>
<span data-ty> "dest": {</span>
<span data-ty> "V3": {</span>
<span data-ty> "parents": "0",</span>
<span data-ty> "interior": {</span>
<span data-ty> "X1": {</span>
<span data-ty> "Parachain": "1,000"</span>
<span data-ty> }</span>
<span data-ty> }</span>
<span data-ty> }</span>
<span data-ty> },</span>
<span data-ty> "beneficiary": {</span>
<span data-ty> "V3": {</span>
<span data-ty> "parents": "0",</span>
<span data-ty> "interior": {</span>
<span data-ty> "X1": {</span>
<span data-ty> "AccountId32": {</span>
<span data-ty> "network": null,</span>
<span data-ty> "id": "0x6c0c32faf970eacb2d4d8e538ac0dab3642492561a1be6f241c645876c056c1d"</span>
<span data-ty> }</span>
<span data-ty> }</span>
<span data-ty> }</span>
<span data-ty> }</span>
<span data-ty> },</span>
<span data-ty> "assets": {</span>
<span data-ty> "V3": [</span>
<span data-ty> {</span>
<span data-ty> "id": {</span>
<span data-ty> "Concrete": {</span>
<span data-ty> "parents": "0",</span>
<span data-ty> "interior": "Here"</span>
<span data-ty> }</span>
<span data-ty> },</span>
<span data-ty> "fun": {</span>
<span data-ty> "Fungible": "1,000,000,000,000"</span>
<span data-ty> }</span>
<span data-ty> }</span>
<span data-ty> ]</span>
<span data-ty> },</span>
<span data-ty> "fee_asset_item": "0",</span>
<span data-ty> "weight_limit": "Unlimited"</span>
<span data-ty> },</span>
<span data-ty> "method": "transferAssets",</span>
<span data-ty> "section": "xcmPallet"</span>
<span data-ty>}</span>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {
AssetTransferApi,
constructApiPromise,
} from "@substrate/asset-transfer-api";

async function main() {
const { api, specName, safeXcmVersion } = await constructApiPromise(
"wss://westend-rpc.polkadot.io"
);
const assetApi = new AssetTransferApi(api, specName, safeXcmVersion);
let callInfo;
try {
callInfo = await assetApi.createTransferTransaction(
"1000",
"5EWNeodpcQ6iYibJ3jmWVe85nsok1EDG8Kk3aFg8ZzpfY1qX",
["WND"],
["1000000000000"],
{
format: "call",
xcmVersion: safeXcmVersion,
}
);

console.log(`Call data:\n${JSON.stringify(callInfo, null, 4)}`);
} catch (e) {
console.error(e);
throw Error(e as string);
}

const decoded = assetApi.decodeExtrinsic(callInfo.tx, "call");
console.log(`\nDecoded tx:\n${JSON.stringify(JSON.parse(decoded), null, 4)}`);
}

main()
.catch((err) => console.error(err))
.finally(() => process.exit());
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {
AssetTransferApi,
constructApiPromise,
} from "@substrate/asset-transfer-api";

async function main() {
const { api, specName, safeXcmVersion } = await constructApiPromise(
"INSERT_WEBSOCKET_URL"
);

const assetsApi = new AssetTransferApi(api, specName, safeXcmVersion);

// Your code using assetsApi goes here
}

main();
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
```ts
export type AssetTransferType =
| LocalReserve
| DestinationReserve
| Teleport
| RemoteReserve;
```

!!! note
To use the `assetTransferType` parameter, which is a string, you should use the `AssetTransferType` type as if each of its variants are strings. For example: `assetTransferType = 'LocalReserve'`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import {
AssetTransferApi,
constructApiPromise,
} from "@substrate/asset-transfer-api";

async function main() {
const { api, specName, safeXcmVersion } = await constructApiPromise(
"wss://westend-rpc.polkadot.io"
);
const assetsApi = new AssetTransferApi(api, specName, safeXcmVersion);

let callInfo;
try {
callInfo = await assetsApi.claimAssets(
[
`{"parents":"0","interior":{"X2":[{"PalletInstance":"50"},{"GeneralIndex":"1984"}]}}`,
],
["1000000000000"],
"0xf5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b",
{
format: "call",
xcmVersion: 2,
}
);

console.log(`Call data:\n${JSON.stringify(callInfo, null, 4)}`);
} catch (e) {
console.error(e);
throw Error(e as string);
}
}

main()
.catch((err) => console.error(err))
.finally(() => process.exit());
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div id="termynal" data-termynal>
<span data-ty>Call data:</span>
<span data-ty>{</span>
<span data-ty> "origin": "0",</span>
<span data-ty> "dest": "westend",</span>
<span data-ty> "direction": "local",</span>
<span data-ty> "xcmVersion": 2,</span>
<span data-ty> "method": "claimAssets",</span>
<span data-ty> "format": "call",</span>
<span data-ty> "tx": "0x630c0104000002043205011f00070010a5d4e80100010100f5d5714c084c112843aca74f8c498da06cc5a2d63153b825189baa51043b1f0b"</span>
<span data-ty>}</span>
<div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public async claimAssets<T extends Format>(
assetIds: string[],
amounts: string[],
beneficiary: string,
opts: TransferArgsOpts<T>
): Promise<TxResult<T>>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```ts
export type ConstructedFormat<T> = T extends 'payload'
? GenericExtrinsicPayload
: T extends 'call'
? `0x${string}`
: T extends 'submittable'
? SubmittableExtrinsic<'promise', ISubmittableResult>
: never;
```

The `ConstructedFormat` type is a conditional type that returns a specific type based on the value of the TxResult `format` field.

- Payload format - if the format field is set to `'payload'`, the `ConstructedFormat` type will return a [`GenericExtrinsicPayload`](https://github.com/polkadot-js/api/blob/3b7b44f048ff515579dd233ea6964acec39c0589/packages/types/src/extrinsic/ExtrinsicPayload.ts#L48){target=_blank}
- Call format - if the format field is set to `'call'`, the `ConstructedFormat` type will return a hexadecimal string (`0x${string}`). This is the encoded representation of the extrinsic call
- Submittable format - if the format field is set to `'submittable'`, the `ConstructedFormat` type will return a [`SubmittableExtrinsic`](https://github.com/polkadot-js/api/blob/3b7b44f048ff515579dd233ea6964acec39c0589/packages/api-base/src/types/submittable.ts#L56){target=_blank}. This is a Polkadot.js type that represents a transaction that can be submitted to the blockchain
Loading

0 comments on commit 3cdbd28

Please sign in to comment.