-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Content migration] - Asset Transfer API #57
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
...evelop/application-devs/tooling/asset-transfer-api/overview/localParachainTx.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
37 changes: 37 additions & 0 deletions
37
...ets/code/develop/application-devs/tooling/asset-transfer-api/overview/localParachainTx.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |
87 changes: 87 additions & 0 deletions
87
...code/develop/application-devs/tooling/asset-transfer-api/overview/paraToPara.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
36 changes: 36 additions & 0 deletions
36
.snippets/code/develop/application-devs/tooling/asset-transfer-api/overview/paraToPara.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |
62 changes: 62 additions & 0 deletions
62
...e/develop/application-devs/tooling/asset-transfer-api/overview/relayToSystem.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
36 changes: 36 additions & 0 deletions
36
.snippets/code/develop/application-devs/tooling/asset-transfer-api/overview/relayToSystem.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |
16 changes: 16 additions & 0 deletions
16
.snippets/code/develop/application-devs/tooling/asset-transfer-api/overview/setup.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
10 changes: 10 additions & 0 deletions
10
...op/application-devs/tooling/asset-transfer-api/reference/asset-transfer-type.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'`. |
35 changes: 35 additions & 0 deletions
35
.../code/develop/application-devs/tooling/asset-transfer-api/reference/ca-example-request.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |
12 changes: 12 additions & 0 deletions
12
...op/application-devs/tooling/asset-transfer-api/reference/ca-example-response.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
6 changes: 6 additions & 0 deletions
6
...ets/code/develop/application-devs/tooling/asset-transfer-api/reference/ca-fn-signature.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>>; |
15 changes: 15 additions & 0 deletions
15
...lop/application-devs/tooling/asset-transfer-api/reference/constructed-format.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some snippets use
assetsApi
and otherassetApi
, stick to one wayAlso, I find kind of weird this comment:
// Your code using assetsApi goes here
But is nitpicking at the end of the day, if you find a better way to express it cool, if not no worries :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It meant the variable called
assetsApi
that has already been initialized in line 11. Do you think it looks better if we putassetTransferApi
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I get that. My point here was that in some snippets, you initialized the variable in a plural form, and in others, you used assetApi in a singular