Skip to content

Commit

Permalink
chore(subbridge): enable evm sygma bridge (#334)
Browse files Browse the repository at this point in the history
* chore(subbridge): astar pallet update

* fix testnet

* chore(subbridge): enable evm sygma bridge
  • Loading branch information
kingsleydon authored Sep 13, 2023
1 parent 2e03c79 commit 9a8cf22
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 78 deletions.
15 changes: 14 additions & 1 deletion apps/subbridge/config/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export type AssetId =
| 'glmr'
| 'sdn'
| 'astr'
| 'gpha'

export type OrmlToken =
| 'PHA'
Expand Down Expand Up @@ -82,7 +83,6 @@ export const ASSETS: Readonly<Record<AssetId, Asset>> = {
ethereum: '0x6c5bA91642F10282b576d91922Ae6448C9d52f4E',
moonbeam: '0xFFFfFfFf63d24eCc8eB8a7b5D0803e900F7b6cED',
moonriver: '0xffFfFFff8E6b63d9e447B6d4C45BDA8AF9dc9603',
goerli: '0xB376b0Ee6d8202721838e76376e81eEc0e2FE864',
},
chainBridgeResourceId: {
phala:
Expand Down Expand Up @@ -133,6 +133,19 @@ export const ASSETS: Readonly<Record<AssetId, Asset>> = {
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',
Expand Down
14 changes: 4 additions & 10 deletions apps/subbridge/config/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,7 @@ export const BRIDGES: Readonly<Bridge[]> = [
toChains: [
{
id: 'phala',
assets: [
{
assetId: 'pha',
estimatedTime: '~ 5 mins',
kind: 'evmChainBridge',
},
],
assets: [{assetId: 'pha', estimatedTime: '~ 5 mins', kind: 'evmSygma'}],
},
{
id: 'khala',
Expand Down Expand Up @@ -341,8 +335,8 @@ export const BRIDGES: Readonly<Bridge[]> = [
{
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'},
],
},
],
Expand Down Expand Up @@ -384,7 +378,7 @@ export const BRIDGES: Readonly<Bridge[]> = [
toChains: [
{
id: 'rhala',
assets: [{assetId: 'pha', estimatedTime: '', kind: 'evmSygma'}],
assets: [{assetId: 'gpha', estimatedTime: '', kind: 'evmSygma'}],
},
],
},
Expand Down
10 changes: 7 additions & 3 deletions apps/subbridge/config/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion apps/subbridge/lib/evmSygma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
112 changes: 49 additions & 63 deletions apps/subbridge/lib/transferByPolkadotXTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ChainId>([
'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',
)
Expand Down

0 comments on commit 9a8cf22

Please sign in to comment.