Skip to content

Commit

Permalink
Fix mythos api (#1377)
Browse files Browse the repository at this point in the history
* fixes

* update package numbers

* adding hydration and moonbeam
  • Loading branch information
alistair-singh authored Feb 7, 2025
1 parent 0275f13 commit 3cf5530
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 7 deletions.
2 changes: 1 addition & 1 deletion web/packages/api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@snowbridge/api",
"version": "0.1.31",
"version": "0.1.32",
"description": "Snowbridge API client",
"license": "Apache-2.0",
"repository": {
Expand Down
5 changes: 5 additions & 0 deletions web/packages/api/src/assets_v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ export async function getLocationBalance(provider: ApiPromise, specName: string,
const accountData = (await provider.query.tokens.accounts(account, assetId)).toPrimitive() as any
return BigInt(accountData?.free ?? 0n)
}
case "mythos":
case "muse": {
console.log(`${specName} does not support DOT, returning 0.`)
return 0n
}
case "moonriver":
case "moonbeam": {
const assetId = (await provider.query.assetManager.assetIdType(location)).toPrimitive()
Expand Down
2 changes: 2 additions & 0 deletions web/packages/api/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,8 @@ export const SNOWBRIDGE_ENV: { [id: string]: SnowbridgeEnvironment } = {
"1000": "wss://asset-hub-polkadot-rpc.dwellir.com",
"1002": "https://bridge-hub-polkadot-rpc.dwellir.com",
"3369": "https://polkadot-mythos-rpc.polkadot.io",
"2034": "wss://hydration-rpc.n.dwellir.com",
"2030": "wss://bifrost-polkadot-rpc.dwellir.com",
},
GATEWAY_CONTRACT: "0x27ca963c279c93801941e1eb8799c23f407d68e7",
BEEFY_CONTRACT: "0x6eD05bAa904df3DE117EcFa638d4CB84e1B8A00C",
Expand Down
4 changes: 3 additions & 1 deletion web/packages/api/src/toPolkadot_v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,12 @@ async function dryRunAssetHub(assetHub: ApiPromise, transfer: Transfer) {
const resultPrimitive = result.toPrimitive() as any
const resultHuman = result.toHuman() as any

const destinationXcmsLength = resultPrimitive.ok.forwardedXcms.length
const destinationXcm = destinationXcmsLength > 0 ? resultPrimitive.ok.forwardedXcms[destinationXcmsLength-1] : undefined
return {
success: resultPrimitive.ok?.executionResult?.complete !== undefined,
errorMessage: resultHuman.Ok.executionResult.Incomplete?.error,
destinationXcm: resultPrimitive.ok.forwardedXcms.length > 0 ? resultPrimitive.ok.forwardedXcms[0] : undefined
destinationXcm,
}
}

Expand Down
2 changes: 1 addition & 1 deletion web/packages/contract-types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@snowbridge/contract-types",
"version": "0.1.31",
"version": "0.1.32",
"description": "Snowbridge contract type bindings",
"license": "Apache-2.0",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion web/packages/contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@snowbridge/contracts",
"version": "0.1.31",
"version": "0.1.32",
"description": "Snowbridge contract source and abi.",
"license": "Apache-2.0",
"repository": {
Expand Down
32 changes: 29 additions & 3 deletions web/packages/operations/src/transfer_token_v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,47 @@ const monitor = async () => {
},
})

let overrides = {}
if(env === "polkadot_mainnet") {
// Add override for mythos token and add precompile for moonbeam
overrides = {
precompiles: { "2004": "0x000000000000000000000000000000000000081A" },
destinationFeeOverrides: {
"3369": 500_000_000n
},
assetOverrides: {
"3369": [
{
token: "0xba41ddf06b7ffd89d1267b5a93bfef2424eb2003".toLowerCase(),
name: "Mythos",
minimumBalance: 10_000_000_000_000_000n,
symbol: "MYTH",
decimals: 18,
isSufficient: true,
}
]
}
}
}

// Step 0. Build the Asset Registry. The registry contains the list of all token and parachain metadata in order to send tokens.
// It may take some build but does not change often so it is safe to cache for 12 hours and shipped with your dapp as static data.
//
// The registry can be build from a snowbridge environment or snowbridge coutntext.
// const registry = await assetsV2.buildRegistry(assetsV2.fromEnvironment(snwobridgeEnv))
// If your dapp does not use the snowbridge environment or context you can always build it manually by
// specifying RegistryOptions for only the parachains you care about.
const registry = await assetsV2.buildRegistry(await assetsV2.fromContext(context))
const registry = await assetsV2.buildRegistry({
...await assetsV2.fromContext(context),
...overrides
})

console.log("Asset Registry:", JSON.stringify(registry, (_, value) => typeof value === "bigint" ? String(value) : value, 2))

const polkadot_keyring = new Keyring({ type: "sr25519" })

const ETHEREUM_ACCOUNT = new Wallet(
"0x5e002a1af63fd31f1c25258f3082dc889762664cb8f218d86da85dff8b07b342",
process.env.ETH_PRIVATE_KEY ?? "your key goes here",
context.ethereum()
)
const ETHEREUM_ACCOUNT_PUBLIC = await ETHEREUM_ACCOUNT.getAddress()
Expand Down Expand Up @@ -144,7 +170,7 @@ const monitor = async () => {

console.log("Asset Hub to Ethereum")
{
const sourceParaId = 2000
const sourceParaId = 1000
// Step 1. Get the delivery fee for the transaction
const fee = await toEthereumV2.getDeliveryFee(await context.assetHub(), registry)

Expand Down

0 comments on commit 3cf5530

Please sign in to comment.