-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support system to bridge txs (#383)
- Loading branch information
Showing
77 changed files
with
3,384 additions
and
218 deletions.
There are no files selected for viewing
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
47 changes: 47 additions & 0 deletions
47
examples/kusama/assetHub/bridgeTransfers/assetHubDOTToPolkadot.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,47 @@ | ||
/** | ||
* When importing from @substrate/asset-transfer-api it would look like the following | ||
* | ||
* import { AssetTransferApi, constructApiPromise } from '@substrate/asset-transfer-api' | ||
*/ | ||
import { AssetTransferApi, constructApiPromise } from '../../../../src'; | ||
import { TxResult } from '../../../../src/types'; | ||
import { GREEN, PURPLE, RESET } from '../../../colors'; | ||
|
||
/** | ||
* In this example we are creating a `polkadotXcm` pallet `transferAssets` call to send 1 DOT (foreign asset with location `{"parents":"2","interior":{"X1":{"GlobalConsensus":"Polkadot"}}}`) | ||
* from a Kusama Asset Hub (System Parachain) account | ||
* to a Polkadot Asset Hub account, where the `xcmVersion` is set to 4 and no `weightLimit` option is provided declaring that | ||
* the tx will allow unlimited weight to be used for fees. | ||
* | ||
* NOTE: To specify the amount of weight for the tx to use provide a `weightLimit` option containing desired values for `refTime` and `proofSize`. | ||
*/ | ||
const main = async () => { | ||
const { api, specName, safeXcmVersion } = await constructApiPromise('wss://kusama-asset-hub-rpc.polkadot.io'); | ||
const assetApi = new AssetTransferApi(api, specName, safeXcmVersion); | ||
|
||
let callInfo: TxResult<'call'>; | ||
try { | ||
callInfo = await assetApi.createTransferTransaction( | ||
`{"parents":"2","interior":{"X1":{"GlobalConsensus":"Polkadot"}}}`, | ||
'13EoPU88424tufnjevEYbbvZ7sGV3q1uhuN4ZbUaoTsnLHYt', | ||
[`{"parents":"2","interior":{"X1":{"GlobalConsensus":"Polkadot"}}}`], | ||
['10000000000'], | ||
{ | ||
format: 'call', | ||
xcmVersion: 4, | ||
}, | ||
); | ||
|
||
console.log(callInfo); | ||
} catch (e) { | ||
console.error(e); | ||
throw Error(e as string); | ||
} | ||
|
||
const decoded = assetApi.decodeExtrinsic(callInfo.tx, 'call'); | ||
console.log(`\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify(JSON.parse(decoded), null, 4)}${RESET}`); | ||
}; | ||
|
||
main() | ||
.catch((err) => console.error(err)) | ||
.finally(() => process.exit()); |
47 changes: 47 additions & 0 deletions
47
examples/kusama/assetHub/bridgeTransfers/assetHubKSMToPolkadot.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,47 @@ | ||
/** | ||
* When importing from @substrate/asset-transfer-api it would look like the following | ||
* | ||
* import { AssetTransferApi, constructApiPromise } from '@substrate/asset-transfer-api' | ||
*/ | ||
import { AssetTransferApi, constructApiPromise } from '../../../../src'; | ||
import { TxResult } from '../../../../src/types'; | ||
import { GREEN, PURPLE, RESET } from '../../../colors'; | ||
|
||
/** | ||
* In this example we are creating a `polkadotXcm` pallet `transferAssets` call to send 1 KSM (asset with location `{"parents":"1","interior":{"Here":""}}`) | ||
* from a Kusama Asset Hub (System Parachain) account | ||
* to a Polkadot Asset Hub account, where the `xcmVersion` is set to 4 and no `weightLimit` option is provided declaring that | ||
* the tx will allow unlimited weight to be used for fees. | ||
* | ||
* NOTE: To specify the amount of weight for the tx to use provide a `weightLimit` option containing desired values for `refTime` and `proofSize`. | ||
*/ | ||
const main = async () => { | ||
const { api, specName, safeXcmVersion } = await constructApiPromise('wss://kusama-asset-hub-rpc.polkadot.io'); | ||
const assetApi = new AssetTransferApi(api, specName, safeXcmVersion); | ||
|
||
let callInfo: TxResult<'call'>; | ||
try { | ||
callInfo = await assetApi.createTransferTransaction( | ||
`{"parents":"2","interior":{"X1":{"GlobalConsensus":"Polkadot"}}}`, | ||
'13EoPU88424tufnjevEYbbvZ7sGV3q1uhuN4ZbUaoTsnLHYt', | ||
[`{"parents":"1","interior":{"Here":""}}`], | ||
['1000000000000'], | ||
{ | ||
format: 'call', | ||
xcmVersion: 4, | ||
}, | ||
); | ||
|
||
console.log(callInfo); | ||
} catch (e) { | ||
console.error(e); | ||
throw Error(e as string); | ||
} | ||
|
||
const decoded = assetApi.decodeExtrinsic(callInfo.tx, 'call'); | ||
console.log(`\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify(JSON.parse(decoded), null, 4)}${RESET}`); | ||
}; | ||
|
||
main() | ||
.catch((err) => console.error(err)) | ||
.finally(() => process.exit()); |
File renamed without changes.
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
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
47 changes: 47 additions & 0 deletions
47
examples/polkadot/assetHub/bridgeTransfers/assetHubDOTToKusama.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,47 @@ | ||
/** | ||
* When importing from @substrate/asset-transfer-api it would look like the following | ||
* | ||
* import { AssetTransferApi, constructApiPromise } from '@substrate/asset-transfer-api' | ||
*/ | ||
import { AssetTransferApi, constructApiPromise } from '../../../../src'; | ||
import { TxResult } from '../../../../src/types'; | ||
import { GREEN, PURPLE, RESET } from '../../../colors'; | ||
|
||
/** | ||
* In this example we are creating a `polkadotXcm` pallet `transferAssets` call to send 1 DOT (asset with location `{"parents":"1","interior":{"Here":""}}`) | ||
* from a Polkadot Asset Hub (System Parachain) account | ||
* to a Kusama Asset Hub account, where the `xcmVersion` is set to 4 and no `weightLimit` option is provided declaring that | ||
* the tx will allow unlimited weight to be used for fees. | ||
* | ||
* NOTE: To specify the amount of weight for the tx to use provide a `weightLimit` option containing desired values for `refTime` and `proofSize`. | ||
*/ | ||
const main = async () => { | ||
const { api, specName, safeXcmVersion } = await constructApiPromise('wss://polkadot-asset-hub-rpc.polkadot.io'); | ||
const assetApi = new AssetTransferApi(api, specName, safeXcmVersion); | ||
|
||
let callInfo: TxResult<'call'>; | ||
try { | ||
callInfo = await assetApi.createTransferTransaction( | ||
`{"parents":"2","interior":{"X1":{"GlobalConsensus":"Kusama"}}}`, | ||
'Ep7uTCvpbpMDnbfTyzbMQTQQqZ5ACGx5nUKnxmBjB4ktmSa', | ||
[`DOT`], | ||
['10000000000'], | ||
{ | ||
format: 'call', | ||
xcmVersion: 4, | ||
}, | ||
); | ||
|
||
console.log(callInfo); | ||
} catch (e) { | ||
console.error(e); | ||
throw Error(e as string); | ||
} | ||
|
||
const decoded = assetApi.decodeExtrinsic(callInfo.tx, 'call'); | ||
console.log(`\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify(JSON.parse(decoded), null, 4)}${RESET}`); | ||
}; | ||
|
||
main() | ||
.catch((err) => console.error(err)) | ||
.finally(() => process.exit()); |
47 changes: 47 additions & 0 deletions
47
examples/polkadot/assetHub/bridgeTransfers/assetHubKSMToKusama.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,47 @@ | ||
/** | ||
* When importing from @substrate/asset-transfer-api it would look like the following | ||
* | ||
* import { AssetTransferApi, constructApiPromise } from '@substrate/asset-transfer-api' | ||
*/ | ||
import { AssetTransferApi, constructApiPromise } from '../../../../src'; | ||
import { TxResult } from '../../../../src/types'; | ||
import { GREEN, PURPLE, RESET } from '../../../colors'; | ||
|
||
/** | ||
* In this example we are creating a `polkadotXcm` pallet `transferAssets` call to send 1 KSM (foreign asset with location `{"parents":"2","interior":{"X1":{"GlobalConsensus":"Kusama"}}}`) | ||
* from a Polkadot Asset Hub (System Parachain) account | ||
* to a Kusama Asset Hub account, where the `xcmVersion` is set to 4 and no `weightLimit` option is provided declaring that | ||
* the tx will allow unlimited weight to be used for fees. | ||
* | ||
* NOTE: To specify the amount of weight for the tx to use provide a `weightLimit` option containing desired values for `refTime` and `proofSize`. | ||
*/ | ||
const main = async () => { | ||
const { api, specName, safeXcmVersion } = await constructApiPromise('wss://polkadot-asset-hub-rpc.polkadot.io'); | ||
const assetApi = new AssetTransferApi(api, specName, safeXcmVersion); | ||
|
||
let callInfo: TxResult<'call'>; | ||
try { | ||
callInfo = await assetApi.createTransferTransaction( | ||
`{"parents":"2","interior":{"X1":{"GlobalConsensus":"Kusama"}}}`, | ||
'13EoPU88424tufnjevEYbbvZ7sGV3q1uhuN4ZbUaoTsnLHYt', | ||
[`{"parents":"2","interior":{"X1":{"GlobalConsensus":"Kusama"}}}`], | ||
['1000000000000'], | ||
{ | ||
format: 'call', | ||
xcmVersion: 4, | ||
}, | ||
); | ||
|
||
console.log(callInfo); | ||
} catch (e) { | ||
console.error(e); | ||
throw Error(e as string); | ||
} | ||
|
||
const decoded = assetApi.decodeExtrinsic(callInfo.tx, 'call'); | ||
console.log(`\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify(JSON.parse(decoded), null, 4)}${RESET}`); | ||
}; | ||
|
||
main() | ||
.catch((err) => console.error(err)) | ||
.finally(() => process.exit()); |
File renamed without changes.
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
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
File renamed without changes.
47 changes: 47 additions & 0 deletions
47
examples/rococo/assetHub/bridgeTransfers/assetHubROCToWestend.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,47 @@ | ||
/** | ||
* When importing from @substrate/asset-transfer-api it would look like the following | ||
* | ||
* import { AssetTransferApi, constructApiPromise } from '@substrate/asset-transfer-api' | ||
*/ | ||
import { AssetTransferApi, constructApiPromise } from '../../../../src'; | ||
import { TxResult } from '../../../../src/types'; | ||
import { GREEN, PURPLE, RESET } from '../../../colors'; | ||
|
||
/** | ||
* In this example we are creating a `polkadotXcm` pallet `transferAssets` call to send 1 ROC (asset with location `{"parents":"1","interior":{"Here":""}}`) | ||
* from a Rococo Asset Hub (System Parachain) account | ||
* to a Westend Asset Hub account, where the `xcmVersion` is set to 4 and no `weightLimit` option is provided declaring that | ||
* the tx will allow unlimited weight to be used for fees. | ||
* | ||
* NOTE: To specify the amount of weight for the tx to use provide a `weightLimit` option containing desired values for `refTime` and `proofSize`. | ||
*/ | ||
const main = async () => { | ||
const { api, specName, safeXcmVersion } = await constructApiPromise('wss://rococo-asset-hub-rpc.polkadot.io'); | ||
const assetApi = new AssetTransferApi(api, specName, safeXcmVersion); | ||
|
||
let callInfo: TxResult<'call'>; | ||
try { | ||
callInfo = await assetApi.createTransferTransaction( | ||
`{"parents":"2","interior":{"X1":{"GlobalConsensus":"Westend"}}}`, | ||
'5EWNeodpcQ6iYibJ3jmWVe85nsok1EDG8Kk3aFg8ZzpfY1qX', | ||
[`{"parents":"1","interior":{"Here":""}}`], | ||
['1000000000000'], | ||
{ | ||
format: 'call', | ||
xcmVersion: 4, | ||
}, | ||
); | ||
|
||
console.log(callInfo); | ||
} catch (e) { | ||
console.error(e); | ||
throw Error(e as string); | ||
} | ||
|
||
const decoded = assetApi.decodeExtrinsic(callInfo.tx, 'call'); | ||
console.log(`\n${PURPLE}The following decoded tx:\n${GREEN} ${JSON.stringify(JSON.parse(decoded), null, 4)}${RESET}`); | ||
}; | ||
|
||
main() | ||
.catch((err) => console.error(err)) | ||
.finally(() => process.exit()); |
Oops, something went wrong.