@subwallet/extension-base 1.3.10-0 → 1.3.12-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/background/KoniTypes.d.ts +3 -0
- package/background/errors/SwapError.js +5 -0
- package/cjs/background/errors/SwapError.js +5 -0
- package/cjs/core/logic-validation/swap.js +27 -0
- package/cjs/core/substrate/xcm-parser.js +16 -2
- package/cjs/koni/api/contract-handler/utils/index.js +29 -1
- package/cjs/koni/background/handlers/Extension.js +16 -4
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/transfer/smart-contract.js +2 -0
- package/cjs/services/balance-service/transfer/xcm/index.js +6 -6
- package/cjs/services/balance-service/transfer/xcm/polygonBridge.js +2 -2
- package/cjs/services/balance-service/transfer/xcm/posBridge.js +144 -0
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/earning-service/constants/chains.js +4 -2
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost-manta.js +2 -1
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +2 -2
- package/cjs/services/inapp-notification-service/index.js +2 -0
- package/cjs/services/inapp-notification-service/utils/polygon.js +1 -1
- package/cjs/services/keyring-service/context/handlers/Ledger.js +3 -1
- package/cjs/services/swap-service/handler/chainflip-handler.js +0 -1
- package/cjs/services/swap-service/handler/simpleswap-handler.js +444 -0
- package/cjs/services/swap-service/index.js +15 -3
- package/cjs/services/swap-service/utils.js +13 -2
- package/cjs/services/transaction-service/index.js +14 -10
- package/cjs/services/transaction-service/utils.js +12 -1
- package/cjs/types/swap/index.js +7 -3
- package/cjs/utils/number.js +10 -0
- package/constants/staking.d.ts +4 -0
- package/core/logic-validation/swap.d.ts +2 -1
- package/core/logic-validation/swap.js +26 -0
- package/core/substrate/xcm-parser.d.ts +1 -0
- package/core/substrate/xcm-parser.js +15 -2
- package/koni/api/contract-handler/utils/index.d.ts +4 -0
- package/koni/api/contract-handler/utils/index.js +24 -0
- package/koni/api/contract-handler/utils/pos_bridge_abi.json +783 -0
- package/koni/api/contract-handler/utils/pos_bridge_l2_abi.json +793 -0
- package/koni/background/handlers/Extension.js +18 -6
- package/package.json +18 -6
- package/packageInfo.js +1 -1
- package/services/balance-service/transfer/smart-contract.js +2 -0
- package/services/balance-service/transfer/xcm/index.js +7 -7
- package/services/balance-service/transfer/xcm/polygonBridge.js +2 -2
- package/services/balance-service/transfer/xcm/posBridge.d.ts +14 -0
- package/services/balance-service/transfer/xcm/posBridge.js +131 -0
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/constants/chains.d.ts +1 -0
- package/services/earning-service/constants/chains.js +2 -1
- package/services/earning-service/handlers/liquid-staking/bifrost-manta.js +2 -1
- package/services/earning-service/handlers/liquid-staking/bifrost.js +3 -3
- package/services/inapp-notification-service/index.js +2 -0
- package/services/inapp-notification-service/interfaces.d.ts +7 -6
- package/services/inapp-notification-service/utils/polygon.d.ts +6 -6
- package/services/inapp-notification-service/utils/polygon.js +1 -1
- package/services/keyring-service/context/handlers/Ledger.js +3 -1
- package/services/swap-service/handler/chainflip-handler.js +0 -1
- package/services/swap-service/handler/simpleswap-handler.d.ts +24 -0
- package/services/swap-service/handler/simpleswap-handler.js +434 -0
- package/services/swap-service/index.d.ts +2 -1
- package/services/swap-service/index.js +13 -2
- package/services/swap-service/utils.d.ts +2 -0
- package/services/swap-service/utils.js +10 -1
- package/services/transaction-service/index.js +15 -11
- package/services/transaction-service/utils.d.ts +2 -1
- package/services/transaction-service/utils.js +12 -2
- package/types/account/info/keyring.d.ts +2 -0
- package/types/swap/index.d.ts +15 -3
- package/types/swap/index.js +5 -2
- package/utils/number.d.ts +9 -0
- package/utils/number.js +10 -0
package/cjs/utils/number.js
CHANGED
|
@@ -200,6 +200,16 @@ const toBNString = (input, decimal) => {
|
|
|
200
200
|
const raw = new _bignumber.default(input);
|
|
201
201
|
return raw.multipliedBy(BN_TEN.pow(decimal)).toFixed();
|
|
202
202
|
};
|
|
203
|
+
|
|
204
|
+
/** @function formatNumber
|
|
205
|
+
* Convert number to a formatted string by dividing by 10^decimal
|
|
206
|
+
* @param {string | number | BigNumber} input - Input number
|
|
207
|
+
* @param {number} decimal - Decimal number
|
|
208
|
+
* @param {NumberFormatter} [formatter] - Formatter function
|
|
209
|
+
* - Default: balanceFormatter: With number > 1, show decimal with 2 numbers,
|
|
210
|
+
* with number < 1, show decimal with 6 (default) number
|
|
211
|
+
* @param {Record<string, number>} [metadata] - Metadata for formatter
|
|
212
|
+
*/
|
|
203
213
|
exports.toBNString = toBNString;
|
|
204
214
|
const formatNumber = function (input, decimal) {
|
|
205
215
|
let formatter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : balanceFormatter;
|
package/constants/staking.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
export declare const PREDEFINED_STAKING_POOL: Record<string, number>;
|
|
2
2
|
export declare const MAX_NOMINATIONS = "16";
|
|
3
3
|
export declare const PREDEFINED_EARNING_POOL_PROMISE: Promise<Record<string, number[]>>;
|
|
4
|
+
export declare type ChainRecommendValidator = {
|
|
5
|
+
maxCount: number;
|
|
6
|
+
preSelectValidators: string;
|
|
7
|
+
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
2
|
import { SwapError } from '@subwallet/extension-base/background/errors/SwapError';
|
|
3
3
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
4
|
-
import { AssetHubPreValidationMetadata, ChainflipPreValidationMetadata, HydradxPreValidationMetadata, SwapErrorType } from '@subwallet/extension-base/types/swap';
|
|
4
|
+
import { AssetHubPreValidationMetadata, ChainflipPreValidationMetadata, HydradxPreValidationMetadata, SimpleSwapValidationMetadata, SwapErrorType } from '@subwallet/extension-base/types/swap';
|
|
5
5
|
export declare function _validateBalanceToSwapOnAssetHub(fromToken: _ChainAsset, feeToken: _ChainAsset, feeTokenChainInfo: _ChainInfo, feeAmount: string, fromTokenBalance: string, feeTokenBalance: string, swapAmount: string, isXcmOk: boolean, minSwap?: string): TransactionError | undefined;
|
|
6
6
|
export declare function _validateBalanceToSwap(fromToken: _ChainAsset, feeToken: _ChainAsset, feeTokenChainInfo: _ChainInfo, feeAmount: string, fromTokenBalance: string, feeTokenBalance: string, swapAmount: string, isXcmOk: boolean, minSwap?: string): TransactionError | undefined;
|
|
7
7
|
export declare function _validateSwapRecipient(destChainInfo: _ChainInfo, recipient: string): TransactionError | undefined;
|
|
8
8
|
export declare function _getChainflipEarlyValidationError(error: SwapErrorType, metadata: ChainflipPreValidationMetadata): SwapError;
|
|
9
9
|
export declare function _getEarlyHydradxValidationError(error: SwapErrorType, metadata: HydradxPreValidationMetadata): SwapError;
|
|
10
10
|
export declare function _getEarlyAssetHubValidationError(error: SwapErrorType, metadata: AssetHubPreValidationMetadata): SwapError;
|
|
11
|
+
export declare function _getSimpleSwapEarlyValidationError(error: SwapErrorType, metadata: SimpleSwapValidationMetadata): SwapError;
|
|
@@ -137,4 +137,30 @@ export function _getEarlyAssetHubValidationError(error, metadata) {
|
|
|
137
137
|
default:
|
|
138
138
|
return new SwapError(error);
|
|
139
139
|
}
|
|
140
|
+
}
|
|
141
|
+
export function _getSimpleSwapEarlyValidationError(error, metadata) {
|
|
142
|
+
// todo: support more providers
|
|
143
|
+
switch (error) {
|
|
144
|
+
case SwapErrorType.NOT_MEET_MIN_SWAP:
|
|
145
|
+
{
|
|
146
|
+
const message = `Amount too low. Increase your amount above ${metadata.minSwap.value} ${metadata.minSwap.symbol} and try again`;
|
|
147
|
+
return new SwapError(error, message);
|
|
148
|
+
}
|
|
149
|
+
case SwapErrorType.SWAP_EXCEED_ALLOWANCE:
|
|
150
|
+
{
|
|
151
|
+
if (metadata.maxSwap) {
|
|
152
|
+
return new SwapError(error, `Amount too high. Lower your amount below ${metadata.maxSwap.value} ${metadata.maxSwap.symbol} and try again`);
|
|
153
|
+
} else {
|
|
154
|
+
return new SwapError(error, 'Amount too high. Lower your amount and try again');
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
case SwapErrorType.ASSET_NOT_SUPPORTED:
|
|
158
|
+
return new SwapError(error, 'This swap pair is not supported');
|
|
159
|
+
case SwapErrorType.UNKNOWN:
|
|
160
|
+
return new SwapError(error, `Undefined error. Check your Internet and ${metadata.chain.slug} connection or contact support`);
|
|
161
|
+
case SwapErrorType.ERROR_FETCHING_QUOTE:
|
|
162
|
+
return new SwapError(error, 'No swap quote found. Adjust your amount or try again later.');
|
|
163
|
+
default:
|
|
164
|
+
return new SwapError(error);
|
|
165
|
+
}
|
|
140
166
|
}
|
|
@@ -54,4 +54,5 @@ export declare function _isSnowBridgeXcm(originChainInfo: _ChainInfo, destChainI
|
|
|
54
54
|
export declare function _isAvailBridgeXcm(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): boolean;
|
|
55
55
|
export declare function _isMythosFromHydrationToMythos(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo, assetSlug: string): boolean;
|
|
56
56
|
export declare function _isPolygonBridgeXcm(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): boolean;
|
|
57
|
+
export declare function _isPosBridgeXcm(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): boolean;
|
|
57
58
|
export declare function _adaptX1Interior(_assetIdentifier: Record<string, any>, version: number): Record<string, any>;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
|
|
5
5
|
import { isAvailChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/availBridge';
|
|
6
6
|
import { _isPolygonChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/polygonBridge';
|
|
7
|
+
import { _isPosChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/posBridge';
|
|
7
8
|
import { _getChainSubstrateAddressPrefix, _getEvmChainId, _getSubstrateParaId, _getSubstrateRelayParent, _getXcmAssetMultilocation, _isChainEvmCompatible, _isPureEvmChain, _isSubstrateParaChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
8
9
|
import { decodeAddress, evmToAddress } from '@polkadot/util-crypto';
|
|
9
10
|
const FOUR_INSTRUCTIONS_WEIGHT = 5000000000;
|
|
@@ -49,7 +50,7 @@ export function _getXcmMultiLocation(originChainInfo, destChainInfo, version, re
|
|
|
49
50
|
};
|
|
50
51
|
}
|
|
51
52
|
export function _isXcmTransferUnstable(originChainInfo, destChainInfo, assetSlug) {
|
|
52
|
-
return !_isXcmWithinSameConsensus(originChainInfo, destChainInfo) || _isMythosFromHydrationToMythos(originChainInfo, destChainInfo, assetSlug) || _isPolygonBridgeXcm(originChainInfo, destChainInfo);
|
|
53
|
+
return !_isXcmWithinSameConsensus(originChainInfo, destChainInfo) || _isMythosFromHydrationToMythos(originChainInfo, destChainInfo, assetSlug) || _isPolygonBridgeXcm(originChainInfo, destChainInfo) || _isPosBridgeXcm(originChainInfo, destChainInfo);
|
|
53
54
|
}
|
|
54
55
|
function getAssetHubBridgeUnstableWarning(originChainInfo) {
|
|
55
56
|
switch (originChainInfo.slug) {
|
|
@@ -84,8 +85,17 @@ function getPolygonBridgeWarning(originChainInfo) {
|
|
|
84
85
|
return 'Cross-chain transfer of this token may take up to 3 hours, and you’ll need to manually claim the funds on the destination network to complete the transfer. Do you still want to continue?';
|
|
85
86
|
}
|
|
86
87
|
}
|
|
88
|
+
function getPosBridgeWarning(originChainInfo) {
|
|
89
|
+
if (originChainInfo.slug === COMMON_CHAIN_SLUGS.ETHEREUM || originChainInfo.slug === COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA) {
|
|
90
|
+
return 'Cross-chain transfer of this token may take up to 22 minutes. Do you still want to continue?';
|
|
91
|
+
} else {
|
|
92
|
+
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?';
|
|
93
|
+
}
|
|
94
|
+
}
|
|
87
95
|
export function _getXcmUnstableWarning(originChainInfo, destChainInfo, assetSlug) {
|
|
88
|
-
if (
|
|
96
|
+
if (_isPosBridgeXcm(originChainInfo, destChainInfo)) {
|
|
97
|
+
return getPosBridgeWarning(originChainInfo);
|
|
98
|
+
} else if (_isPolygonBridgeXcm(originChainInfo, destChainInfo)) {
|
|
89
99
|
return getPolygonBridgeWarning(originChainInfo);
|
|
90
100
|
} else if (_isAvailBridgeXcm(originChainInfo, destChainInfo)) {
|
|
91
101
|
return getAvailBridgeWarning();
|
|
@@ -114,6 +124,9 @@ export function _isMythosFromHydrationToMythos(originChainInfo, destChainInfo, a
|
|
|
114
124
|
export function _isPolygonBridgeXcm(originChainInfo, destChainInfo) {
|
|
115
125
|
return _isPolygonChainBridge(originChainInfo.slug, destChainInfo.slug);
|
|
116
126
|
}
|
|
127
|
+
export function _isPosBridgeXcm(originChainInfo, destChainInfo) {
|
|
128
|
+
return _isPosChainBridge(originChainInfo.slug, destChainInfo.slug);
|
|
129
|
+
}
|
|
117
130
|
|
|
118
131
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
119
132
|
|
|
@@ -12,8 +12,12 @@ export declare const _SNOWBRIDGE_GATEWAY_ABI: Record<string, any>;
|
|
|
12
12
|
export declare const _AVAIL_BRIDGE_GATEWAY_ABI: Record<string, any>;
|
|
13
13
|
export declare const _AVAIL_TEST_BRIDGE_GATEWAY_ABI: Record<string, any>;
|
|
14
14
|
export declare const _POLYGON_BRIDGE_ABI: Record<string, any>;
|
|
15
|
+
export declare const _POS_BRIDGE_ABI: Record<string, any>;
|
|
16
|
+
export declare const _POS_BRIDGE_L2_ABI: Record<string, any>;
|
|
15
17
|
export declare function getSnowBridgeGatewayContract(chain: string): "0x27ca963C279c93801941e1eB8799c23f407d68e7" | "0x5B4909cE6Ca82d2CE23BD46738953c7959E710Cd";
|
|
16
18
|
export declare function isSnowBridgeGatewayContract(contractAddress: _Address): boolean;
|
|
17
19
|
export declare function getAvailBridgeGatewayContract(chain: string): "0x054fd961708D8E2B9c10a63F6157c74458889F0a" | "0x967F7DdC4ec508462231849AE81eeaa68Ad01389";
|
|
18
20
|
export declare function isAvailBridgeGatewayContract(contractAddress: _Address): boolean;
|
|
19
21
|
export declare function getPolygonBridgeContract(chain: string): string;
|
|
22
|
+
export declare function getPosL2BridgeContract(chain: string): string;
|
|
23
|
+
export declare function getPosL1BridgeContract(chain: string): string;
|
|
@@ -26,6 +26,10 @@ export const _AVAIL_BRIDGE_GATEWAY_ABI = require("./avail_bridge_abi.json");
|
|
|
26
26
|
export const _AVAIL_TEST_BRIDGE_GATEWAY_ABI = require("./avail_test_bridge_abi.json");
|
|
27
27
|
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
|
|
28
28
|
export const _POLYGON_BRIDGE_ABI = require("./polygon_bridge_abi.json");
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
|
|
30
|
+
export const _POS_BRIDGE_ABI = require("./pos_bridge_abi.json");
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires,@typescript-eslint/no-unsafe-assignment
|
|
32
|
+
export const _POS_BRIDGE_L2_ABI = require("./pos_bridge_l2_abi.json");
|
|
29
33
|
const SNOWBRIDGE_GATEWAY_ETHEREUM_CONTRACT_ADDRESS = '0x27ca963C279c93801941e1eB8799c23f407d68e7';
|
|
30
34
|
const SNOWBRIDGE_GATEWAY_SEPOLIA_CONTRACT_ADDRESS = '0x5B4909cE6Ca82d2CE23BD46738953c7959E710Cd';
|
|
31
35
|
export function getSnowBridgeGatewayContract(chain) {
|
|
@@ -57,4 +61,24 @@ export function getPolygonBridgeContract(chain) {
|
|
|
57
61
|
return POLYGONBRIDGE_GATEWAY_ETHEREUM_CONTRACT_ADDRESS;
|
|
58
62
|
}
|
|
59
63
|
throw new Error('Invalid chain');
|
|
64
|
+
}
|
|
65
|
+
const POSBRIDGE_GATEWAY_AMOY_CONTRACT_ADDRESS = '0x52eF3d68BaB452a294342DC3e5f464d7f610f72E';
|
|
66
|
+
const POSBRIDGE_GATEWAY_SEPOLIA_CONTRACT_ADDRESS = '0x34F5A25B627f50Bb3f5cAb72807c4D4F405a9232';
|
|
67
|
+
const POSBRIDGE_GATEWAY_CONTRACT_ADDRESS = '0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619';
|
|
68
|
+
const POSBRIDGE_GATEWAY_ETHEREUM_CONTRACT_ADDRESS = '0xA0c68C638235ee32657e8f720a23ceC1bFc77C77';
|
|
69
|
+
export function getPosL2BridgeContract(chain) {
|
|
70
|
+
if (chain === 'polygon_amoy' || chain === COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA) {
|
|
71
|
+
return POSBRIDGE_GATEWAY_AMOY_CONTRACT_ADDRESS;
|
|
72
|
+
} else if (chain === 'polygon' || chain === COMMON_CHAIN_SLUGS.ETHEREUM) {
|
|
73
|
+
return POSBRIDGE_GATEWAY_CONTRACT_ADDRESS;
|
|
74
|
+
}
|
|
75
|
+
throw new Error('Invalid chain');
|
|
76
|
+
}
|
|
77
|
+
export function getPosL1BridgeContract(chain) {
|
|
78
|
+
if (chain === COMMON_CHAIN_SLUGS.ETHEREUM_SEPOLIA) {
|
|
79
|
+
return POSBRIDGE_GATEWAY_SEPOLIA_CONTRACT_ADDRESS;
|
|
80
|
+
} else if (chain === COMMON_CHAIN_SLUGS.ETHEREUM) {
|
|
81
|
+
return POSBRIDGE_GATEWAY_ETHEREUM_CONTRACT_ADDRESS;
|
|
82
|
+
}
|
|
83
|
+
throw new Error('Invalid chain');
|
|
60
84
|
}
|