Skip to content
Closed
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
7f52115
Format codes
yrong Mar 17, 2025
49ce6e7
Support PNA
yrong Mar 18, 2025
47522a2
Transfer relay token to ethereum
yrong Mar 18, 2025
e94274b
Send relay token back
yrong Mar 19, 2025
ddf47c3
Index PNA with foreign id
yrong Mar 19, 2025
6aa2cee
Polish
yrong Mar 19, 2025
73a4293
Update packages with dry_run support
yrong Mar 19, 2025
a3410f1
Merge branch 'main' into ron/support-pna
yrong Mar 19, 2025
ffde26b
Merge branch 'main' into ron/format
yrong Mar 19, 2025
9c0ae0b
Merge branch 'ron/format' into ron/support-pna
yrong Mar 19, 2025
1ae6c37
Merge branch 'main' into ron/support-pna
yrong Mar 20, 2025
4e1543b
Build XCM for PNA
yrong Mar 21, 2025
6b6f2e1
Build xcm for dry run
yrong Mar 22, 2025
bdab98a
Test with local e2e
yrong Mar 24, 2025
8685125
Find contract address
yrong Mar 24, 2025
adf7c66
Update script
yrong Mar 24, 2025
b6c3fe7
Cleanup
yrong Mar 24, 2025
e8991a5
Transfer PAL to Ethereum
yrong Mar 24, 2025
744b8d4
Fix transfer from Penpal
yrong Mar 24, 2025
fbd3359
Update demo script to use V2 api
yrong Mar 25, 2025
013a826
Update script
yrong Mar 25, 2025
bcaf3cf
Do not check for ED if dry run was successful (#1415)
alistair-singh Mar 31, 2025
1bc34a3
Add PNA relay token to daily transfer
yrong Apr 1, 2025
db968e4
Merge branch 'main' into ron/support-pna
yrong Apr 1, 2025
610795f
Update packages for testing
yrong Apr 1, 2025
b2ca787
Clean contracts cache
yrong Apr 1, 2025
c4be0bf
Transfer native Ether
yrong Apr 1, 2025
1cc5417
Ignore registry.json
yrong Apr 1, 2025
a977872
Rename the script
yrong Apr 2, 2025
1d5ad4c
Remove unused
yrong Apr 2, 2025
645caf9
Transfer Ether
yrong Apr 2, 2025
176cd84
Refactor test scripts
yrong Apr 2, 2025
2f2256f
Use string for asset_id
yrong Apr 3, 2025
6056d6f
Merge branch 'ron/support-pna' of https://github.com/Snowfork/snowbri…
yrong Apr 3, 2025
e25ef34
Use assetId directly for query account balance on Moonbeam
yrong Apr 3, 2025
e4c108e
Update web/packages/api/src/assets_v2.ts
yrong Apr 3, 2025
e88c941
Use WSS endpoint from dwellir
yrong Apr 3, 2025
f5c84fd
Update web/packages/operations/src/registry.ts
yrong Apr 3, 2025
9e8a169
Decouple Asset type from XcmBuilder
yrong Apr 3, 2025
d46b66e
Remove logging
yrong Apr 3, 2025
8b70d62
Build ExportMessage to estimate delivery fee with it
yrong Apr 3, 2025
6734c44
Merge branch 'snowbridge-v1' into ron/support-pna
yrong Apr 3, 2025
3849e91
Update packges for integration with UI
yrong Apr 3, 2025
87fb685
Overrides DOT on AH
yrong Apr 4, 2025
5ccef13
Update pre-release packages
yrong Apr 4, 2025
e30174c
For compatiblity with dryRun
yrong Apr 4, 2025
092f842
Update packages
yrong Apr 4, 2025
04e50cd
Add other PNAs
yrong Apr 4, 2025
be5fccd
Update packages
yrong Apr 4, 2025
750e370
Update token addresses in V1 local setup
yrong Apr 4, 2025
7f7dd8e
Fix potential bug multi-hop ENA to destination chain
yrong Apr 4, 2025
b90393d
Cleanup
yrong Apr 4, 2025
145d042
Fix local setup
yrong Apr 4, 2025
684de99
Merge branch 'ron/support-pna' of https://github.com/Snowfork/snowbri…
yrong Apr 4, 2025
3b48261
More comments
yrong Apr 5, 2025
fff0319
Regression tests
yrong Apr 5, 2025
643ce46
Remove initial scripts
yrong Apr 5, 2025
a3a3d34
Initialize scripts
yrong Apr 5, 2025
37d4e9d
Fix KSM location
yrong Apr 6, 2025
cfad3d1
Update packages
yrong Apr 6, 2025
a33d58a
Fix transfer KSM from AHP
yrong Apr 6, 2025
77fb1c7
Update packages for test
yrong Apr 6, 2025
b8d379a
Fix tranfer local asset on AH
yrong Apr 6, 2025
9ee3780
Update packages
yrong Apr 6, 2025
aee725d
Fix getTokenBalance for PNA transfer
yrong Apr 7, 2025
09c57d4
Update packages
yrong Apr 7, 2025
d902b69
Update script path
yrong Apr 8, 2025
ec779df
Release packages
yrong Apr 9, 2025
cf0e3a5
For tests
yrong Apr 11, 2025
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
12 changes: 6 additions & 6 deletions 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.46",
"version": "0.1.47",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This clashes with my PR #1450. May need to sync here.

"description": "Snowbridge API client",
"license": "Apache-2.0",
"repository": {
Expand All @@ -27,11 +27,11 @@
"typescript": "^5.4.5"
},
"dependencies": {
"@polkadot/api": "^14.3.1",
"@polkadot/keyring": "^13.2.3",
"@polkadot/types": "^14.3.1",
"@polkadot/util": "^13.2.3",
"@polkadot/util-crypto": "^13.2.3",
"@polkadot/api": "^15.7.2",
"@polkadot/keyring": "^13.4.3",
"@polkadot/types": "^15.7.2",
"@polkadot/util": "^13.4.3",
"@polkadot/util-crypto": "^13.4.3",
"@snowbridge/contract-types": "workspace:*",
"@typechain/ethers-v6": "^0.5.1",
"ethers": "^6.13.5",
Expand Down
255 changes: 238 additions & 17 deletions web/packages/api/src/assets_v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export type ERC20Metadata = {
name: string
symbol: string
decimals: number
foreignId?: string
}

export type EthereumChain = {
Expand Down Expand Up @@ -77,6 +78,16 @@ export type Asset = {
decimals: number
isSufficient: boolean
xc20?: string
// Location on source Parachain
location?: any
// Location reanchored on AH
locationOnAH?: any
// Location reanchored on Ethereum
locationOnEthereum?: any
Comment thread
yrong marked this conversation as resolved.
// For chains that use `Assets` pallet to manage local assets
// the asset_id is normally represented as u32, but on Moonbeam,
// it is u128, so use string here to avoid overflow
assetId?: string
}

export type RegistryOptions = {
Expand Down Expand Up @@ -526,7 +537,8 @@ export async function getLocationBalance(
provider: ApiPromise,
specName: string,
location: any,
account: string
account: string,
assetId?: any
): Promise<bigint> {
switch (specName) {
case "basilisk":
Expand All @@ -546,10 +558,16 @@ export async function getLocationBalance(
case "asset-hub-paseo":
case "westmint":
case "statemint": {
const assetId = location
const accountData = (
await provider.query.foreignAssets.account(assetId, account)
).toPrimitive() as any
let accountData: any
if (assetId) {
accountData = (
await provider.query.assets.account(assetId, account)
).toPrimitive() as any
} else {
accountData = (
await provider.query.foreignAssets.account(location, account)
).toPrimitive() as any
}
return BigInt(accountData?.balance ?? 0n)
}
case "bifrost":
Expand All @@ -573,11 +591,14 @@ export async function getLocationBalance(
}
case "moonriver":
case "moonbeam": {
const assetId = (
await provider.query.assetManager.assetTypeId({ xcm: location })
).toPrimitive()
// For PNA, use assetId directly; for ENA, query assetId by Multilocation
if (!assetId) {
throw Error(`DOT not registered for spec ${specName}.`)
assetId = (
await provider.query.assetManager.assetTypeId({ xcm: location })
).toPrimitive()
if (!assetId) {
throw Error(`Asset not registered for spec ${specName}.`)
}
}
const accountData = (
await provider.query.assets.account(assetId, account)
Expand Down Expand Up @@ -610,9 +631,16 @@ export function getTokenBalance(
specName: string,
account: string,
ethChainId: number,
tokenAddress: string
tokenAddress: string,
asset?: Asset
) {
return getLocationBalance(provider, specName, erc20Location(ethChainId, tokenAddress), account)
return getLocationBalance(
provider,
specName,
asset?.location ?? erc20Location(ethChainId, tokenAddress),
account,
asset?.assetId
)
}

export async function getParachainId(parachain: ApiPromise): Promise<number> {
Expand All @@ -628,13 +656,20 @@ export async function calculateDestinationFee(provider: ApiPromise, destinationX
throw Error(`Can not query XCM Weight.`)
}

const feeInDot = (
let feeInDot: any
feeInDot = (
await provider.call.xcmPaymentApi.queryWeightToAssetFee(weight.ok, {
v4: { parents: 1, interior: "Here" },
})
).toPrimitive() as any
// For compatibility with Westend, which has XCMV5 enabled.
if (!feeInDot.ok) {
throw Error(`Can not convert weight to fee in DOT.`)
feeInDot = (
await provider.call.xcmPaymentApi.queryWeightToAssetFee(weight.ok, {
v5: { parents: 1, interior: "Here" },
})
).toPrimitive() as any
if (!feeInDot.ok) throw Error(`Can not convert weight to fee in DOT.`)
}
const executionFee = BigInt(feeInDot.ok.toString())

Expand Down Expand Up @@ -865,7 +900,7 @@ async function indexParachain(
}

if (Object.keys(assets).length === 0) {
throw Error(
console.warn(
`Cannot discover assets for ${info.specName} (parachain ${parachainId}). Please add a handler for that runtime or add overrides.`
)
}
Expand Down Expand Up @@ -969,7 +1004,7 @@ async function indexEthChain(
decimals: assetHub.assets[token].decimals,
}
} else {
assets[token] = await assetErc20Metadata(provider, token)
assets[token] = await assetErc20Metadata(provider, token, gatewayAddress)
}
}
if ((await provider.getCode(gatewayAddress)) === undefined) {
Expand Down Expand Up @@ -1082,15 +1117,29 @@ const ERC20_METADATA_ABI = [

async function assetErc20Metadata(
provider: AbstractProvider,
token: string
token: string,
gateway?: string
): Promise<ERC20Metadata> {
const erc20Metadata = new Contract(token, ERC20_METADATA_ABI, provider)
const [name, symbol, decimals] = await Promise.all([
erc20Metadata.name(),
erc20Metadata.symbol(),
erc20Metadata.decimals(),
])
return { token, name: String(name), symbol: String(symbol), decimals: Number(decimals) }
let metadata: any = {
token,
name: String(name),
symbol: String(symbol),
decimals: Number(decimals),
}
if (gateway) {
let gatewayCon = IGateway__factory.connect(gateway, provider)
let tokenId = await gatewayCon.queryForeignTokenID(token)
if (tokenId != "0x0000000000000000000000000000000000000000000000000000000000000000") {
metadata.foreignId = tokenId
}
}
return metadata
}

function getTokenFromLocation(location: any, chainId: number) {
Expand Down Expand Up @@ -1154,6 +1203,178 @@ function addOverrides(envName: string, result: RegistryOptions) {
isSufficient: true,
},
],
"1000": [
{
token: "0x196C20DA81Fbc324EcdF55501e95Ce9f0bD84d14".toLowerCase(),
name: "DOT",
minimumBalance: 100_000_000n,
symbol: "DOT",
decimals: 10,
isSufficient: true,
location: DOT_LOCATION,
},
{
token: "0x12bbfDc9e813614eEf8Dc8A2560b0EfBeaf7C2AB".toLowerCase(),
name: "KUSAMA",
minimumBalance: 3_333_333n,
symbol: "KSM",
decimals: 12,
isSufficient: true,
location: {
parents: 2,
interior: {
x1: [
{
globalConsensus: "Kusama",
},
],
},
},
},
{
token: "0x21FaB0eA070F162180447881D5873Cf3d57200d6".toLowerCase(),
name: "Kolkadot",
minimumBalance: 1n,
symbol: "KOL",
decimals: 12,
isSufficient: false,
location: {
parents: 0,
interior: { X2: [{ palletInstance: 50 }, { generalIndex: 86 }] },
},
assetId: "86",
},
{
token: "0x92262680A8d6636bbA9bFFDf484c274cA2de6400".toLowerCase(),
name: "DED",
minimumBalance: 1n,
symbol: "DED",
decimals: 10,
isSufficient: false,
location: {
parents: 0,
interior: { X2: [{ palletInstance: 50 }, { generalIndex: 30 }] },
},
assetId: "30",
},
{
token: "0xa37B046782518A80e2E69056009FBD0431d36E50".toLowerCase(),
name: "PINK",
minimumBalance: 1n,
symbol: "PINK",
decimals: 10,
isSufficient: false,
location: {
parents: 0,
interior: { X2: [{ palletInstance: 50 }, { generalIndex: 23 }] },
},
assetId: "23",
},
{
token: "0x5FDcD48F09FB67de3D202cd854B372AEC1100ED5".toLowerCase(),
name: "GAVUN WUD",
minimumBalance: 1n,
symbol: "WUD",
decimals: 10,
isSufficient: false,
location: {
parents: 0,
interior: { X2: [{ palletInstance: 50 }, { generalIndex: 31337 }] },
},
assetId: "31337",
},
],
}
Comment thread
yrong marked this conversation as resolved.
break
}
case "westend_sepolia": {
result.assetOverrides = {
"1000": [
{
token: "0xF50fb50d65C8C1f6c72E4D8397c984933AfC8F7e".toLowerCase(),
name: "WND",
minimumBalance: 1n,
symbol: "WND",
decimals: 18,
isSufficient: true,
location: DOT_LOCATION,
},
],
}
break
}
case "local_e2e": {
result.assetOverrides = {
"1000": [
{
token: "0xB8C39CbCe8106c8415472e3AAe88Eb694Cc70B57".toLowerCase(),
name: "wnd",
minimumBalance: 1n,
symbol: "wnd",
decimals: 18,
isSufficient: true,
location: DOT_LOCATION,
},
{
token: "0x44Cf1D0Db863BBC053098E33e92d02802dDb926a".toLowerCase(),
name: "pal-2",
minimumBalance: 1n,
symbol: "pal-2",
decimals: 18,
isSufficient: true,
location: {
parents: 1,
interior: {
x3: [
{ parachain: 2000 },
{ palletInstance: 50 },
{ generalIndex: 2 },
],
},
},
},
],
"2000": [
{
token: "0x44Cf1D0Db863BBC053098E33e92d02802dDb926a".toLowerCase(),
name: "pal-2",
minimumBalance: 1n,
symbol: "pal-2",
decimals: 18,
isSufficient: true,
assetId: "2",
location: {
parents: 0,
interior: { x2: [{ palletInstance: 50 }, { generalIndex: 2 }] },
},
locationOnAH: {
parents: 1,
interior: {
x3: [
{ parachain: 2000 },
{ palletInstance: 50 },
{ generalIndex: 2 },
],
},
},
locationOnEthereum: {
parents: 1,
interior: {
x4: [
{
globalConsensus: {
byGenesis:
"0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e",
},
},
{ parachain: 2000 },
{ palletInstance: 50 },
{ generalIndex: 2 },
],
},
},
},
],
}
break
}
Expand Down
8 changes: 4 additions & 4 deletions web/packages/api/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export const SNOWBRIDGE_ENV: { [id: string]: SnowbridgeEnvironment } = {
"1002": "ws://127.0.0.1:11144",
"2000": "ws://127.0.0.1:13144",
},
GATEWAY_CONTRACT: "0x87d1f7fdfEe7f651FaBc8bFCB6E086C278b77A7d",
GATEWAY_CONTRACT: "0x87d1f7fdfee7f651fabc8bfcb6e086c278b77a7d",
BEEFY_CONTRACT: "0x2ffa5ecdbe006d30397c7636d3e015eee251369f",
ASSET_HUB_PARAID: 1000,
BRIDGE_HUB_PARAID: 1002,
Expand Down Expand Up @@ -586,10 +586,10 @@ export const SNOWBRIDGE_ENV: { [id: string]: SnowbridgeEnvironment } = {
ETHEREUM_CHAINS: {
"11155111": (key) => `https://eth-sepolia.g.alchemy.com/v2/${key}`,
},
RELAY_CHAIN_URL: "https://westend-rpc.polkadot.io",
RELAY_CHAIN_URL: "wss://westend-rpc.dwellir.com",
PARACHAINS: {
"1000": "wss://westend-asset-hub-rpc.polkadot.io",
"1002": "https://westend-bridge-hub-rpc.polkadot.io",
"1000": "wss://asset-hub-westend-rpc.dwellir.com",
"1002": "wss://bridge-hub-westend-rpc.dwellir.com",
},
GATEWAY_CONTRACT: "0x9ed8b47bc3417e3bd0507adc06e56e2fa360a4e9",
BEEFY_CONTRACT: "0x6DFaD3D73A28c48E4F4c616ECda80885b415283a",
Expand Down
Loading