From 9a8cf229a4ea7498be0a71d27a6a20630346f35f Mon Sep 17 00:00:00 2001 From: Kingsley <10992364+kingsleydon@users.noreply.github.com> Date: Wed, 13 Sep 2023 12:35:14 +0800 Subject: [PATCH] chore(subbridge): enable evm sygma bridge (#334) * chore(subbridge): astar pallet update * fix testnet * chore(subbridge): enable evm sygma bridge --- apps/subbridge/config/asset.ts | 15 ++- apps/subbridge/config/bridge.ts | 14 +-- apps/subbridge/config/chain.ts | 10 +- apps/subbridge/lib/evmSygma.ts | 6 +- .../lib/transferByPolkadotXTokens.ts | 112 ++++++++---------- 5 files changed, 79 insertions(+), 78 deletions(-) diff --git a/apps/subbridge/config/asset.ts b/apps/subbridge/config/asset.ts index 8a1cdc86..c0777e8b 100644 --- a/apps/subbridge/config/asset.ts +++ b/apps/subbridge/config/asset.ts @@ -34,6 +34,7 @@ export type AssetId = | 'glmr' | 'sdn' | 'astr' + | 'gpha' export type OrmlToken = | 'PHA' @@ -82,7 +83,6 @@ export const ASSETS: Readonly> = { ethereum: '0x6c5bA91642F10282b576d91922Ae6448C9d52f4E', moonbeam: '0xFFFfFfFf63d24eCc8eB8a7b5D0803e900F7b6cED', moonriver: '0xffFfFFff8E6b63d9e447B6d4C45BDA8AF9dc9603', - goerli: '0xB376b0Ee6d8202721838e76376e81eEc0e2FE864', }, chainBridgeResourceId: { phala: @@ -133,6 +133,19 @@ export const ASSETS: Readonly> = { sygmaResourceId: '0x0000000000000000000000000000000000000000000000000000000000000001', }, + gpha: { + id: 'gpha', + symbol: 'GPHA', + icon: phaIcon, + erc20TokenContractAddress: { + goerli: '0xB376b0Ee6d8202721838e76376e81eEc0e2FE864', + }, + decimals: {goerli: 18, default: 12}, + sygmaResourceId: + '0x0000000000000000000000000000000000000000000000000000000000001000', + destChainTransactionFee: {}, + existentialDeposit: {}, + }, movr: { id: 'movr', symbol: 'MOVR', diff --git a/apps/subbridge/config/bridge.ts b/apps/subbridge/config/bridge.ts index 3189a4d6..c5e9984e 100644 --- a/apps/subbridge/config/bridge.ts +++ b/apps/subbridge/config/bridge.ts @@ -87,13 +87,7 @@ export const BRIDGES: Readonly = [ toChains: [ { id: 'phala', - assets: [ - { - assetId: 'pha', - estimatedTime: '~ 5 mins', - kind: 'evmChainBridge', - }, - ], + assets: [{assetId: 'pha', estimatedTime: '~ 5 mins', kind: 'evmSygma'}], }, { id: 'khala', @@ -341,8 +335,8 @@ export const BRIDGES: Readonly = [ { id: 'khala', assets: [ - {assetId: 'sdn', estimatedTime: '< 1 min', kind: 'polkadotXcm'}, - {assetId: 'pha', estimatedTime: '< 1 min', kind: 'polkadotXcm'}, + {assetId: 'sdn', estimatedTime: '< 1 min', kind: 'polkadotXTokens'}, + {assetId: 'pha', estimatedTime: '< 1 min', kind: 'polkadotXTokens'}, ], }, ], @@ -384,7 +378,7 @@ export const BRIDGES: Readonly = [ toChains: [ { id: 'rhala', - assets: [{assetId: 'pha', estimatedTime: '', kind: 'evmSygma'}], + assets: [{assetId: 'gpha', estimatedTime: '', kind: 'evmSygma'}], }, ], }, diff --git a/apps/subbridge/config/chain.ts b/apps/subbridge/config/chain.ts index 39fd7ed6..1bf52892 100644 --- a/apps/subbridge/config/chain.ts +++ b/apps/subbridge/config/chain.ts @@ -89,7 +89,11 @@ export const CHAINS: Readonly< name: 'Phala', icon: phalaIcon, kind: 'polkadot', - endpoint: ['wss://api.phala.network/ws'], + endpoint: [ + 'wss://phala-rpc.dwellir.com', + 'wss://api.phala.network/ws', + 'wss://phala.api.onfinality.io/public-ws', + ], ss58Format: 30, paraId: 2035, nativeAsset: 'pha', @@ -102,9 +106,9 @@ export const CHAINS: Readonly< icon: khalaIcon, kind: 'polkadot', endpoint: [ - 'wss://khala-api.phala.network/ws', - 'wss://khala.api.onfinality.io/public-ws', 'wss://khala-rpc.dwellir.com', + 'wss://khala.api.onfinality.io/public-ws', + 'wss://khala-api.phala.network/ws', ], ss58Format: 30, paraId: 2004, diff --git a/apps/subbridge/lib/evmSygma.ts b/apps/subbridge/lib/evmSygma.ts index 6f099583..c5ba5700 100644 --- a/apps/subbridge/lib/evmSygma.ts +++ b/apps/subbridge/lib/evmSygma.ts @@ -34,7 +34,11 @@ export const getEvmSygmaTransfer = async ( let destinationChainId let parachainId - if (toChain.id === 'phala' || toChain.id === 'khala') { + if ( + toChain.id === 'phala' || + toChain.id === 'khala' || + toChain.id === 'rhala' + ) { destinationChainId = toChain.sygmaChainId } else { parachainId = toChain.paraId diff --git a/apps/subbridge/lib/transferByPolkadotXTokens.ts b/apps/subbridge/lib/transferByPolkadotXTokens.ts index 405a0481..bc0caa3e 100644 --- a/apps/subbridge/lib/transferByPolkadotXTokens.ts +++ b/apps/subbridge/lib/transferByPolkadotXTokens.ts @@ -57,84 +57,70 @@ export const transferByPolkadotXTokens = ({ } else if ( fromChainId === 'parallel' || fromChainId === 'parallel-heiko' || - fromChainId === 'basilisk' + fromChainId === 'basilisk' || + fromChainId === 'astar' || + fromChainId === 'shiden' || + fromChainId === 'turing' ) { currencyId = palletAssetId - } else if (fromChainId === 'turing') { - currencyId = asset.palletAssetId?.turing } else { currencyId = { [isTransferringBNCFromBifrost ? 'Native' : 'Token']: asset.ormlToken, } } - return polkadotApi.tx.xTokens.transfer( + const isXcmV3 = new Set([ + 'bifrost-kusama', + 'bifrost-test', + 'karura', + 'karura-test', + 'parallel-heiko', + 'astar', + 'shiden', + 'turing', + ]).has(fromChainId) + + const palletName = + fromChainId === 'astar' || fromChainId === 'shiden' ? 'xtokens' : 'xTokens' + + return polkadotApi.tx[palletName].transfer( currencyId, amount, - fromChainId === 'bifrost-kusama' || - fromChainId === 'bifrost-test' || - fromChainId === 'karura' || - fromChainId === 'karura-test' - ? { - V3: { - parents: 1, - interior: - proxy != null - ? { - X4: [ - {Parachain: CHAINS[proxy].paraId}, - ...createPhalaMultilocation( - 'cb', - generalIndex as number, - destinationAccount as Hex, - ), - ], - } - : { - X2: [ - {Parachain: toChain.paraId}, - { - AccountId32: { - id: u8aToHex(decodeAddress(destinationAccount)), - }, - }, - ], - }, - }, - } - : { - V1: { - parents: 1, - interior: - proxy != null - ? { - X4: [ - {Parachain: CHAINS[proxy].paraId}, - ...createPhalaMultilocation( - 'cb', - generalIndex as number, - destinationAccount as Hex, - ), - ], - } - : { - X2: [ - {Parachain: toChain.paraId}, - { - AccountId32: { - network: 'Any', - id: u8aToHex(decodeAddress(destinationAccount)), - }, - }, - ], + { + [isXcmV3 ? 'V3' : 'V1']: { + parents: 1, + interior: + proxy != null + ? { + X4: [ + {Parachain: CHAINS[proxy].paraId}, + ...createPhalaMultilocation( + 'cb', + generalIndex as number, + destinationAccount as Hex, + ), + ], + } + : { + X2: [ + {Parachain: toChain.paraId}, + { + AccountId32: { + id: u8aToHex(decodeAddress(destinationAccount)), + network: isXcmV3 ? undefined : 'Any', + }, }, - }, - }, + ], + }, + }, + }, fromChainId === 'bifrost-kusama' || fromChainId === 'bifrost-test' ? {Limited: {refTime: '6000000000', proofSize: '1000000'}} : fromChainId === 'parallel' || fromChainId === 'parallel-heiko' || - fromChainId === 'karura' + fromChainId === 'karura' || + fromChainId === 'shiden' || + fromChainId === 'astar' ? {Unlimited: null} : '6000000000', )