-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
308 additions
and
18 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
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
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,9 @@ | ||
import { createClient } from "polkadot-api" | ||
import { getSmProvider } from "polkadot-api/sm-provider" | ||
import { smoldot } from "./smoldot" | ||
|
||
export const rocRelayChain = import("polkadot-api/chains/rococo_v2_2").then( | ||
({ chainSpec }) => smoldot.addChain({ chainSpec }), | ||
) | ||
|
||
export const rocClient = createClient(getSmProvider(rocRelayChain)) |
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,32 @@ | ||
import { createClient } from "polkadot-api" | ||
import { getSmProvider } from "polkadot-api/sm-provider" | ||
import { smoldot } from "./smoldot" | ||
import { rocRelayChain } from "./roc" | ||
|
||
const chainSpec = `{ | ||
"name": "Rococo Asset Hub", | ||
"id": "asset-hub-rococo", | ||
"chainType": "Live", | ||
"bootNodes": [ | ||
"/dns/rococo-asset-hub-bootnode-0.polkadot.io/tcp/30333/p2p/12D3KooWRrZMndHAopzao34uGsN7srjS3gh9nAjTGKLSyJeU31Lg", | ||
"/dns/rococo-asset-hub-bootnode-1.polkadot.io/tcp/30333/p2p/12D3KooWAewimoNJqMaiiV5pYiowA5hLuh5JS5QiRJCCyWVrrSTS" | ||
], | ||
"telemetryEndpoints": null, | ||
"protocolId": null, | ||
"properties": { | ||
"tokenDecimals": 12, | ||
"tokenSymbol": "ROC" | ||
}, | ||
"relay_chain": "rococo_v2_2", | ||
"para_id": 1000, | ||
"codeSubstitutes": {}, | ||
"genesis": { | ||
"stateRootHash": "0xad0224198565f04f9f7a6120231d310f9280669ec3395b898dd2bb69e1deb87d" | ||
} | ||
}` | ||
|
||
const smoldotParaChain = rocRelayChain.then((relayChain) => | ||
smoldot.addChain({ chainSpec, potentialRelayChains: [relayChain] }), | ||
) | ||
|
||
export const rocAhClient = createClient(getSmProvider(smoldotParaChain)) |
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 |
---|---|---|
@@ -1,4 +1,78 @@ | ||
import SmWorker from "polkadot-api/smoldot/worker?worker" | ||
import { startFromWorker } from "polkadot-api/smoldot/from-worker" | ||
|
||
export const smoldot = startFromWorker(new SmWorker()) | ||
/* | ||
interface QueueNode<T> { | ||
value: T | ||
next?: QueueNode<T> | ||
} | ||
export default class Queue<T> { | ||
private first?: QueueNode<T> | ||
private last?: QueueNode<T> | ||
constructor(...vals: T[]) { | ||
if (vals.length === 0) return | ||
vals.forEach((val) => this.push(val)) | ||
} | ||
push(value: T) { | ||
const nextLast: QueueNode<T> = { value } | ||
if (this.last === undefined) { | ||
this.last = nextLast | ||
this.first = this.last | ||
} else { | ||
this.last.next = nextLast | ||
this.last = nextLast | ||
} | ||
} | ||
pop() { | ||
const result = this.first?.value | ||
if (this.first) { | ||
this.first = this.first.next | ||
if (!this.first) { | ||
this.last = undefined | ||
} | ||
} | ||
return result | ||
} | ||
peek() { | ||
return this.first?.value | ||
} | ||
} | ||
const messages = new Queue<string>() | ||
let tickDate = "" | ||
const setTickDate = () => { | ||
tickDate = new Date().toISOString() | ||
setTimeout(setTickDate, 0) | ||
} | ||
setTickDate() | ||
const getTickDate = () => tickDate | ||
*/ | ||
|
||
export const smoldot = startFromWorker( | ||
new SmWorker() /*, { | ||
maxLogLevel: 9, | ||
logCallback: (level: number, target: string, message: string) => { | ||
messages.push(`${getTickDate()} (${level})${target}\n${message}\n\n`) | ||
}, | ||
}*/, | ||
) | ||
/*;(window as any).getLogs = () => { | ||
console.log("touch the window now!") | ||
setTimeout(() => { | ||
console.log("putting the logs in place") | ||
let data = `` | ||
while (messages.peek() !== undefined) { | ||
data += messages.pop()! | ||
} | ||
navigator.clipboard.writeText(data) | ||
console.log("copied!") | ||
}, 3_000) | ||
}*/ |
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,73 @@ | ||
import { | ||
DotXcmV3Junctions, | ||
DotXcmV3MultiassetAssetId, | ||
XcmV3Junction, | ||
XcmV3JunctionNetworkId, | ||
XcmV3MultiassetFungibility, | ||
XcmVersionedMultiAssets, | ||
rocAh as descriptors, | ||
} from "@polkadot-api/descriptors" | ||
import { rocAhClient } from "@/api/clients" | ||
import { AssetInChain } from "../types" | ||
import { | ||
fromAssetHubToForeign, | ||
fromAssetHubToRelay, | ||
getNativeAsset, | ||
watchAccoutFreeBalance, | ||
watchForeingAssetAccoutFreeBalance, | ||
} from "../common" | ||
|
||
const api = rocAhClient.getTypedApi(descriptors) | ||
|
||
const chain = "rocAh" | ||
const roc: AssetInChain = { | ||
chain, | ||
symbol: "ROC", | ||
watchFreeBalance: watchAccoutFreeBalance(api), | ||
teleport: { | ||
roc: (...args) => | ||
api.tx.PolkadotXcm.limited_teleport_assets(fromAssetHubToRelay(...args)), | ||
wndAh: (from, amount, to) => | ||
api.tx.PolkadotXcm.limited_reserve_transfer_assets( | ||
fromAssetHubToForeign( | ||
XcmV3JunctionNetworkId.Westend(), | ||
1000, | ||
getNativeAsset(1, amount), | ||
from, | ||
to, | ||
), | ||
), | ||
}, | ||
} | ||
|
||
const wndInRocAh: Parameters<typeof DotXcmV3MultiassetAssetId.Concrete>[0] = { | ||
parents: 2, | ||
interior: DotXcmV3Junctions.X1( | ||
XcmV3Junction.GlobalConsensus(XcmV3JunctionNetworkId.Westend()), | ||
), | ||
} | ||
|
||
const wnd: AssetInChain = { | ||
chain, | ||
symbol: "WND", | ||
watchFreeBalance: watchForeingAssetAccoutFreeBalance(api, wndInRocAh), | ||
teleport: { | ||
wndAh: (from, amount, to) => | ||
api.tx.PolkadotXcm.limited_reserve_transfer_assets( | ||
fromAssetHubToForeign( | ||
XcmV3JunctionNetworkId.Westend(), | ||
1000, | ||
XcmVersionedMultiAssets.V3([ | ||
{ | ||
id: DotXcmV3MultiassetAssetId.Concrete(wndInRocAh), | ||
fun: XcmV3MultiassetFungibility.Fungible(amount), | ||
}, | ||
]), | ||
from, | ||
to, | ||
), | ||
), | ||
}, | ||
} | ||
|
||
export default [wnd, roc] |
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,4 @@ | ||
import relay from "./relay" | ||
import ah from "./ah" | ||
|
||
export default [...relay, ...ah] |
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,18 @@ | ||
import { roc as descriptors } from "@polkadot-api/descriptors" | ||
import { rocClient } from "@/api/clients" | ||
import { AssetInChain } from "../types" | ||
import { fromRelayToAssetHub, watchAccoutFreeBalance } from "../common" | ||
|
||
const api = rocClient.getTypedApi(descriptors) | ||
|
||
const roc: AssetInChain = { | ||
chain: "roc", | ||
symbol: "ROC", | ||
watchFreeBalance: watchAccoutFreeBalance(api), | ||
teleport: { | ||
rocAh: (...args) => | ||
api.tx.XcmPallet.limited_teleport_assets(fromRelayToAssetHub(...args)), | ||
}, | ||
} | ||
|
||
export default [roc] |
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
Oops, something went wrong.