Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .images/local-network/asset-changed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .images/local-network/asset-para1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .images/local-network/asset-para2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .images/local-network/map-xUSD.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .images/local-network/mapped-xUSD.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions README-es.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ manual:
ver token transferido:
![](.images/mangata-roc.png)

## Otros ejemplos

<a href="./src/examples/local-network/readme-es.md">ejemplos en un red local</a>

## Probar

Ejecución de las pruebas unitarias.
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,9 @@ manually:
see token transfered:
![](.images/mangata-roc.png)

## Other examples

<a href="./src/examples/local-network/readme.md">local network examples</a>

## Testing

Expand Down
93 changes: 93 additions & 0 deletions src/examples/local-network/config-assets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { ApiPromise, Keyring, WsProvider } from '@polkadot/api'
import { cryptoWaitReady } from '@polkadot/util-crypto'
import { localNetworkUtils } from './local-network-utils'

const main = async () => {
await cryptoWaitReady()

const keyring = new Keyring({ type: 'sr25519' })
const sender = keyring.addFromUri('//Alice')

const relayProvider = await ApiPromise.create({
provider: new WsProvider(localNetworkUtils.relayRpc),
})

const paraAProvider = await ApiPromise.create({
provider: new WsProvider(localNetworkUtils.parachain1Rpc),
})

const paraBProvider = await ApiPromise.create({
provider: new WsProvider(localNetworkUtils.parachain2Rpc),
})

console.log('creating assets...')
const extrinsicCreateAssetParaA = paraAProvider.tx.utility.batchAll([
paraAProvider.tx.assets.create(1, sender.address, 100000000000),
paraAProvider.tx.assets.setMetadata(1, 'xUSD', 'xUSD', 12),
])

await extrinsicCreateAssetParaA.signAndSend(sender)
console.log('xUSD created on statemine')

const extrinsicCreateAssetParaB = paraBProvider.tx.utility.batchAll([
paraBProvider.tx.assets.create(1, sender.address, 100000000000),
paraBProvider.tx.assets.setMetadata(1, 'txUSD', 'txUSD', 12),
])

await extrinsicCreateAssetParaB.signAndSend(sender)
console.log('txUSD created on trappist')

console.log('waiting for assets...')
await new Promise((resolve) => setTimeout(resolve, 30000))

console.log('setting xUSD as sufficient...')
const extrinsicRelay = await relayProvider.tx.sudo.sudo(
(relayProvider.tx as any).parasSudoWrapper.sudoQueueDownwardXcm(localNetworkUtils.parachain1ChainId, {
V2: [
{
Transact: {
originType: 'Superuser',
requireWeightAtMost: 100000000000,
call: {
encoded:
'0x32150400d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d00d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d00d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d00d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d040100',
},
},
},
],
}),
)

await extrinsicRelay.signAndSend(sender)

console.log('setting txUSD as multilocation...')

const extrinsicParab = await paraBProvider.tx.sudo.sudo(
paraBProvider.tx.assetRegistry.registerReserveAsset(1, {
parents: 1,
interior: {
X3: [
{
Parachain: 1000,
},
{
PalletInstance: 50,
},
{
GeneralIndex: 1,
},
],
},
}),
)

await extrinsicParab.signAndSend(sender)

console.log('done!')
}

main().then(() => process.exit(1))

/**
npx ts-node src/examples/local-network/config-assets.ts
*/
75 changes: 75 additions & 0 deletions src/examples/local-network/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@

[settings]
timeout = 1000

[relaychain]
chain = "rococo-local"
default_command = "./bin/polkadot"

[[relaychain.nodes]]
name = "alice"
validator = true
ws_port = 9900
extra_args = [ "-lparachain=debug" ]

[[relaychain.nodes]]
name = "bob"
validator = true
extra_args = [ "-lparachain=debug" ]

[[relaychain.nodes]]
name = "charlie"
validator = true
extra_args = [ "-lparachain=debug" ]

[[parachains]]
id = 1000
add_to_genesis = true
cumulus_based = true
chain = "statemine-local"

[[parachains.collators]]
name = "statemine-collator01"
command = "./bin/polkadot-parachain"
ws_port = 9910
args = ["--log=xcm=trace,pallet-assets=trace"]

[[parachains.collators]]
name = "statemine-collator02"
command = "./bin/polkadot-parachain"
ws_port = 9911
args = ["--log=xcm=trace,pallet-assets=trace"]

[[parachains]]
id = 2000
add_to_genesis = true
cumulus_based = true

[[parachains.collators]]
name = "trappist-collator01"
command = "./bin/trappist-collator"
ws_port = 9920
args = ["--log=xcm=trace,pallet-assets=trace"]

[[parachains.collators]]
name = "trappist-collator02"
command = "./bin/trappist-collator"
ws_port = 9921
args = ["--log=xcm=trace,pallet-assets=trace"]

[types.Header]
number = "u64"
parent_hash = "Hash"
post_state = "Hash"

[[hrmp_channels]]
sender = 1000
recipient = 2000
max_capacity = 8
max_message_size = 512

[[hrmp_channels]]
sender = 2000
recipient = 1000
max_capacity = 8
max_message_size = 512
Empty file.
10 changes: 7 additions & 3 deletions src/examples/local-network/local-network-utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
export const localNetworkUtils = {
relayRpc: 'ws://127.0.0.1:30101',
parachain1Rpc: 'ws://127.0.0.1:40001',
relayRpc: 'ws://127.0.0.1:9900',
parachain1Rpc: 'ws://127.0.0.1:9911',
parachain2Rpc: 'ws://127.0.0.1:9921',
parachain1ChainId: 1000,
parachain1DestinationAccount: '',
parachain1DestinationAccount: 'FoQJpPyadYccjavVdTWxpxU7rUEaYhfLCPwXgkfD6Zat9QP',
parachain2ChainId: 2000,
parachain2DestinationAccount: '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty', //bob account
relayChainDestintionAccount: '5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty',
}
51 changes: 51 additions & 0 deletions src/examples/local-network/manually-config-assets-es.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Configurar activos manualmente
===

Si quieres crear tus propios activos y hacerlos transferibles, preparamos una pequeña guia. Vamos a basarnos es <a href="./config.toml">esta configuración local</a> y crearemos xUSD en statemine y txUSD en trappist.

Primero, ve a crear los activos en ambas parachains

<ul>
<li>asset name: xUSD / txUSD</li>
<li>asset symbol: xUSD / txUSD</li>
<li>asset decimals: 12</li>
<li>minimum balance: 1</li>
<li>asset id: 1</li>
</ul>

Statemine:

![](../../../.images/local-network/asset-para1.png)

Trappist:

![](../../../.images/local-network/asset-para2.png)


Si quieres transferir xUSD a txUSD en trappist, primero necesitamos marcar xUSD como sufficient para poder para tarifas con ese activo:

Ve a Developrt > Extrinsic, y prepara el extrinsc, <strong> NO </strong> hagas el submit, solo copia el encoded call data.

![](../../../.images/local-network/is_sufficient-extrinsic.png)

Luego en la relaychain, ve a Developer > sudo:

![](../../../.images/local-network/extrinsic-from-relay.png)

Has submit, y en statamine deberias ver:

![](../../../.images/local-network/asset-status-change-explorer.png)

Tambien, puedes chequear en Developer > Chain state, recarga la página y deberias ver:

![](../../../.images/local-network/asset-changed.png)

Ahora, vamos a mapear el xUSD en trappist, en trappist, ve a Developer > Extrinsic:

![](../../../.images/local-network/map-xUSD.png)

Has el submit, y puedes chequear que el activo fue mapeado en Developer > Chain state, deberias ver:

![](../../../.images/local-network/mapped-xUSD.png)

Esos es todo, ahora estas listo para transferir xUSD a trappist.
54 changes: 54 additions & 0 deletions src/examples/local-network/manually-config-assets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Manually Config Assets
===

If you want to create your own asset and set them as transferables, we prepared a little guide.
We're going to base in <a href="./config.toml">this local config</a> and we will create xUSD on statemine and txUSD on trappist.

First, go to create the assets in both parachains:

<ul>
<li>asset name: xUSD / txUSD</li>
<li>asset symbol: xUSD / txUSD</li>
<li>asset decimals: 12</li>
<li>minimum balance: 1</li>
<li>asset id: 1</li>
</ul>

Statemine:

![](../../../.images/local-network/asset-para1.png)

Trappist:

![](../../../.images/local-network/asset-para2.png)


We want to transfer xUSD to txUSD on trappist, first we need to set xUSD as sufficient to be able to pay fees with that asset:

Go to Developer > Extrinsic, and prepare the extrinsic, <strong> DON'T </strong> submit, just copy the encoded call data.

![](../../../.images/local-network/is_sufficient-extrinsic.png)


Then on the relay chain, go to Developer > sudo:

![](../../../.images/local-network/extrinsic-from-relay.png)

Submit, and in Statemine you should see this:

![](../../../.images/local-network/asset-status-change-explorer.png)

Also, you can check in Developer > Chain state, reload the page and you should see:

![](../../../.images/local-network/asset-changed.png)


Now, we have to map xUSD in trappist, in trappist, go to Developer > Extrinsic:

![](../../../.images/local-network/map-xUSD.png)

submit, you can check if the asset was mapped in Developer > chain state, you should see this:

![](../../../.images/local-network/mapped-xUSD.png)

That's all, now you're ready to transfer xUSD to trappist.
Loading