Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue-3893] Support bridge ETH <-> POS #3894

Merged
merged 12 commits into from
Jan 2, 2025
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
"@polkadot/types-support": "^15.0.1",
"@polkadot/util": "^13.2.3",
"@polkadot/util-crypto": "^13.2.3",
"@subwallet/chain-list": "0.2.96",
"@subwallet/chain-list": "0.2.96-beta.8",
"@subwallet/keyring": "^0.1.8-beta.0",
"@subwallet/react-ui": "5.1.2-b79",
"@subwallet/ui-keyring": "0.1.8-beta.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/extension-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"@reduxjs/toolkit": "^1.9.1",
"@sora-substrate/type-definitions": "^1.17.7",
"@substrate/connect": "^0.8.9",
"@subwallet/chain-list": "0.2.96",
"@subwallet/chain-list": "0.2.96-beta.8",
"@subwallet/extension-base": "^1.3.11-0",
"@subwallet/extension-chains": "^1.3.11-0",
"@subwallet/extension-dapp": "^1.3.11-0",
Expand Down
19 changes: 17 additions & 2 deletions packages/extension-base/src/core/substrate/xcm-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
import { _Address } from '@subwallet/extension-base/background/KoniTypes';
import { isAvailChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/availBridge';
import { _isPolygonChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/polygonBridge';
import { _isPosChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/posBridge';
import { _getChainSubstrateAddressPrefix, _getEvmChainId, _getSubstrateParaId, _getSubstrateRelayParent, _getXcmAssetMultilocation, _isChainEvmCompatible, _isPureEvmChain, _isSubstrateParaChain } from '@subwallet/extension-base/services/chain-service/utils';

import { decodeAddress, evmToAddress } from '@polkadot/util-crypto';
Expand Down Expand Up @@ -63,7 +64,7 @@ export function _getXcmMultiLocation (originChainInfo: _ChainInfo, destChainInfo
}

export function _isXcmTransferUnstable (originChainInfo: _ChainInfo, destChainInfo: _ChainInfo, assetSlug: string): boolean {
return !_isXcmWithinSameConsensus(originChainInfo, destChainInfo) || _isMythosFromHydrationToMythos(originChainInfo, destChainInfo, assetSlug) || _isPolygonBridgeXcm(originChainInfo, destChainInfo);
return !_isXcmWithinSameConsensus(originChainInfo, destChainInfo) || _isMythosFromHydrationToMythos(originChainInfo, destChainInfo, assetSlug) || _isPolygonBridgeXcm(originChainInfo, destChainInfo) || _isPosBridgeXcm(originChainInfo, destChainInfo);
}

function getAssetHubBridgeUnstableWarning (originChainInfo: _ChainInfo): string {
Expand Down Expand Up @@ -104,8 +105,18 @@ function getPolygonBridgeWarning (originChainInfo: _ChainInfo): string {
}
}

function getPosBridgeWarning (originChainInfo: _ChainInfo): string {
if (originChainInfo.slug === COMMON_CHAIN_SLUGS.ETHEREUM || originChainInfo.slug === COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA) {
return 'Cross-chain transfer of this token may take up to 22 minutes. Do you still want to continue?';
} else {
return 'Cross-chain transfer of this token may take up to 90 minutes, and you’ll need to manually claim the funds on the destination network to complete the transfer. Do you still want to continue?';
}
}

export function _getXcmUnstableWarning (originChainInfo: _ChainInfo, destChainInfo: _ChainInfo, assetSlug: string): string {
if (_isPolygonBridgeXcm(originChainInfo, destChainInfo)) {
if (_isPosBridgeXcm(originChainInfo, destChainInfo)) {
return getPosBridgeWarning(originChainInfo);
} else if (_isPolygonBridgeXcm(originChainInfo, destChainInfo)) {
return getPolygonBridgeWarning(originChainInfo);
} else if (_isAvailBridgeXcm(originChainInfo, destChainInfo)) {
return getAvailBridgeWarning();
Expand Down Expand Up @@ -141,6 +152,10 @@ export function _isPolygonBridgeXcm (originChainInfo: _ChainInfo, destChainInfo:
return _isPolygonChainBridge(originChainInfo.slug, destChainInfo.slug);
}

export function _isPosBridgeXcm (originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): boolean {
return _isPosChainBridge(originChainInfo.slug, destChainInfo.slug);
}

// ---------------------------------------------------------------------------------------------------------------------

function _getMultiLocationParent (originChainInfo: _ChainInfo, isWithinSameConsensus: boolean): number {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export const _AVAIL_BRIDGE_GATEWAY_ABI: Record<string, any> = require('./avail_b
export const _AVAIL_TEST_BRIDGE_GATEWAY_ABI: Record<string, any> = require('./avail_test_bridge_abi.json');
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
export const _POLYGON_BRIDGE_ABI: Record<string, any> = require('./polygon_bridge_abi.json');
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
export const _POS_BRIDGE_ABI: Record<string, any> = require('./pos_bridge_abi.json');
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
export const _POS_BRIDGE_L2_ABI: Record<string, any> = require('./pos_bridge_l2_abi.json');

const SNOWBRIDGE_GATEWAY_ETHEREUM_CONTRACT_ADDRESS = '0x27ca963C279c93801941e1eB8799c23f407d68e7';
const SNOWBRIDGE_GATEWAY_SEPOLIA_CONTRACT_ADDRESS = '0x5B4909cE6Ca82d2CE23BD46738953c7959E710Cd';
Expand Down Expand Up @@ -72,3 +76,29 @@ export function getPolygonBridgeContract (chain: string): string {

throw new Error('Invalid chain');
}

const POSBRIDGE_GATEWAY_AMOY_CONTRACT_ADDRESS = '0x52eF3d68BaB452a294342DC3e5f464d7f610f72E';
const POSBRIDGE_GATEWAY_SEPOLIA_CONTRACT_ADDRESS = '0x34F5A25B627f50Bb3f5cAb72807c4D4F405a9232';

const POSBRIDGE_GATEWAY_CONTRACT_ADDRESS = '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619';
const POSBRIDGE_GATEWAY_ETHEREUM_CONTRACT_ADDRESS = '0xA0c68C638235ee32657e8f720a23ceC1bFc77C77';

export function getPosL2BridgeContract (chain: string): string {
if (chain === 'polygon_amoy' || chain === COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA) {
return POSBRIDGE_GATEWAY_AMOY_CONTRACT_ADDRESS;
} else if (chain === 'polygon' || chain === COMMON_CHAIN_SLUGS.ETHEREUM) {
return POSBRIDGE_GATEWAY_CONTRACT_ADDRESS;
}

throw new Error('Invalid chain');
}

export function getPosL1BridgeContract (chain: string): string {
if (chain === COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA) {
return POSBRIDGE_GATEWAY_SEPOLIA_CONTRACT_ADDRESS;
} else if (chain === COMMON_CHAIN_SLUGS.ETHEREUM) {
return POSBRIDGE_GATEWAY_ETHEREUM_CONTRACT_ADDRESS;
}

throw new Error('Invalid chain');
}
Loading
Loading