@subwallet/extension-base 1.2.28-0 → 1.2.30-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/cjs/core/substrate/xcm-parser.js +15 -6
- package/cjs/koni/background/handlers/Extension.js +6 -6
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/index.js +19 -13
- package/cjs/services/balance-service/helpers/subscribe/substrate/gear.js +6 -4
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +14 -2
- package/cjs/services/balance-service/transfer/xcm/index.js +8 -13
- package/cjs/services/chain-service/constants.js +2 -1
- package/cjs/services/earning-service/handlers/lending/interlay.js +0 -2
- package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +1 -12
- package/cjs/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +2 -2
- package/cjs/services/migration-service/scripts/databases/MigrateAssetSetting.js +2 -2
- package/cjs/services/migration-service/scripts/index.js +2 -2
- package/cjs/services/swap-service/handler/chainflip-handler.js +12 -6
- package/cjs/services/swap-service/handler/hydradx-handler.js +1 -1
- package/cjs/services/swap-service/utils.js +29 -0
- package/core/substrate/xcm-parser.d.ts +3 -2
- package/core/substrate/xcm-parser.js +14 -6
- package/koni/background/handlers/Extension.js +6 -6
- package/package.json +8 -8
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/index.js +19 -13
- package/services/balance-service/helpers/subscribe/substrate/gear.js +6 -4
- package/services/balance-service/helpers/subscribe/substrate/index.js +14 -2
- package/services/balance-service/transfer/xcm/index.js +8 -13
- package/services/chain-service/constants.d.ts +1 -0
- package/services/chain-service/constants.js +2 -1
- package/services/earning-service/handlers/lending/interlay.js +0 -2
- package/services/earning-service/handlers/liquid-staking/parallel.js +1 -12
- package/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +2 -2
- package/services/migration-service/scripts/databases/MigrateAssetSetting.js +2 -2
- package/services/migration-service/scripts/index.js +2 -2
- package/services/swap-service/handler/chainflip-handler.d.ts +3 -2
- package/services/swap-service/handler/chainflip-handler.js +11 -6
- package/services/swap-service/handler/hydradx-handler.js +1 -1
- package/services/swap-service/utils.d.ts +12 -0
- package/services/swap-service/utils.js +27 -0
|
@@ -9,6 +9,7 @@ exports._getXcmDestWeight = _getXcmDestWeight;
|
|
|
9
9
|
exports._getXcmMultiAssets = _getXcmMultiAssets;
|
|
10
10
|
exports._getXcmMultiLocation = _getXcmMultiLocation;
|
|
11
11
|
exports._getXcmUnstableWarning = _getXcmUnstableWarning;
|
|
12
|
+
exports._isMythosFromHydrationToMythos = _isMythosFromHydrationToMythos;
|
|
12
13
|
exports._isSnowBridgeXcm = _isSnowBridgeXcm;
|
|
13
14
|
exports._isXcmTransferUnstable = _isXcmTransferUnstable;
|
|
14
15
|
exports._isXcmWithinSameConsensus = _isXcmWithinSameConsensus;
|
|
@@ -60,8 +61,8 @@ function _getXcmMultiLocation(originChainInfo, destChainInfo, version, recipient
|
|
|
60
61
|
}
|
|
61
62
|
};
|
|
62
63
|
}
|
|
63
|
-
function _isXcmTransferUnstable(originChainInfo, destChainInfo) {
|
|
64
|
-
return !_isXcmWithinSameConsensus(originChainInfo, destChainInfo);
|
|
64
|
+
function _isXcmTransferUnstable(originChainInfo, destChainInfo, assetSlug) {
|
|
65
|
+
return !_isXcmWithinSameConsensus(originChainInfo, destChainInfo) || _isMythosFromHydrationToMythos(originChainInfo, destChainInfo, assetSlug);
|
|
65
66
|
}
|
|
66
67
|
function getAssetHubBridgeUnstableWarning(originChainInfo) {
|
|
67
68
|
switch (originChainInfo.slug) {
|
|
@@ -76,16 +77,21 @@ function getAssetHubBridgeUnstableWarning(originChainInfo) {
|
|
|
76
77
|
function getSnowBridgeUnstableWarning(originChainInfo) {
|
|
77
78
|
switch (originChainInfo.slug) {
|
|
78
79
|
case _chainList.COMMON_CHAIN_SLUGS.POLKADOT_ASSET_HUB:
|
|
79
|
-
return 'Cross-chain transfer of this token is not recommended as it is in beta, incurs a fee of 70
|
|
80
|
+
return 'Cross-chain transfer of this token is not recommended as it is in beta, incurs a fee of $70 and takes up to 1 hour to complete. Continue at your own risk';
|
|
80
81
|
case _chainList.COMMON_CHAIN_SLUGS.ETHEREUM:
|
|
81
|
-
return 'Cross-chain transfer of this token is not recommended as it is in beta, incurs a fee of 5
|
|
82
|
+
return 'Cross-chain transfer of this token is not recommended as it is in beta, incurs a fee of $5 and takes up to 1 hour to complete. Continue at your own risk';
|
|
82
83
|
default:
|
|
83
84
|
return 'Cross-chain transfer of this token is not recommended as it is in beta, incurs a high fee and takes up to 1 hour to complete. Continue at your own risk';
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
|
-
function
|
|
87
|
+
function getMythosFromHydrationToMythosWarning() {
|
|
88
|
+
return 'Cross-chain transfer of this token requires a high transaction fee. Do you want to continue?';
|
|
89
|
+
}
|
|
90
|
+
function _getXcmUnstableWarning(originChainInfo, destChainInfo, assetSlug) {
|
|
87
91
|
if (_isSnowBridgeXcm(originChainInfo, destChainInfo)) {
|
|
88
92
|
return getSnowBridgeUnstableWarning(originChainInfo);
|
|
93
|
+
} else if (_isMythosFromHydrationToMythos(originChainInfo, destChainInfo, assetSlug)) {
|
|
94
|
+
return getMythosFromHydrationToMythosWarning();
|
|
89
95
|
} else {
|
|
90
96
|
return getAssetHubBridgeUnstableWarning(originChainInfo);
|
|
91
97
|
}
|
|
@@ -96,6 +102,9 @@ function _isXcmWithinSameConsensus(originChainInfo, destChainInfo) {
|
|
|
96
102
|
function _isSnowBridgeXcm(originChainInfo, destChainInfo) {
|
|
97
103
|
return !_isXcmWithinSameConsensus(originChainInfo, destChainInfo) && ((0, _utils._isPureEvmChain)(originChainInfo) || (0, _utils._isPureEvmChain)(destChainInfo));
|
|
98
104
|
}
|
|
105
|
+
function _isMythosFromHydrationToMythos(originChainInfo, destChainInfo, assetSlug) {
|
|
106
|
+
return originChainInfo.slug === 'hydradx_main' && destChainInfo.slug === 'mythos' && assetSlug === 'hydradx_main-LOCAL-MYTH';
|
|
107
|
+
}
|
|
99
108
|
|
|
100
109
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
101
110
|
|
|
@@ -209,7 +218,7 @@ function _getAssetIdentifier(tokenInfo, version) {
|
|
|
209
218
|
if (!_assetIdentifier) {
|
|
210
219
|
throw new Error('Asset must have multilocation');
|
|
211
220
|
}
|
|
212
|
-
const assetIdentifier = ['statemint-LOCAL-KSM'].includes(tokenInfo.slug) // todo: hotfix for ksm statemint recheck all chain
|
|
221
|
+
const assetIdentifier = ['statemint-LOCAL-KSM', 'statemine-LOCAL-DOT'].includes(tokenInfo.slug) // todo: hotfix for ksm statemint recheck all chain
|
|
213
222
|
? _assetIdentifier : _adaptX1Interior(structuredClone(_assetIdentifier), version);
|
|
214
223
|
return version >= 4 // from V4, Concrete is removed
|
|
215
224
|
? assetIdentifier : {
|
|
@@ -1770,11 +1770,11 @@ class KoniExtension {
|
|
|
1770
1770
|
return this.#koniState.transactionService.generateBeforeHandleResponseErrors(errors);
|
|
1771
1771
|
}
|
|
1772
1772
|
const chainInfoMap = this.#koniState.getChainInfoMap();
|
|
1773
|
-
const
|
|
1773
|
+
const isSnowBridgeEvmTransfer = (0, _utils3._isPureEvmChain)(chainInfoMap[originNetworkKey]) && (0, _xcmParser._isSnowBridgeXcm)(chainInfoMap[originNetworkKey], chainInfoMap[destinationNetworkKey]);
|
|
1774
1774
|
let additionalValidator;
|
|
1775
1775
|
let eventsHandler;
|
|
1776
1776
|
if (fromKeyPair && destinationTokenInfo) {
|
|
1777
|
-
if (
|
|
1777
|
+
if (isSnowBridgeEvmTransfer) {
|
|
1778
1778
|
const evmApi = this.#koniState.getEvmApi(originNetworkKey);
|
|
1779
1779
|
extrinsic = await (0, _xcm.createSnowBridgeExtrinsic)({
|
|
1780
1780
|
destinationTokenInfo,
|
|
@@ -1844,7 +1844,7 @@ class KoniExtension {
|
|
|
1844
1844
|
transaction: extrinsic,
|
|
1845
1845
|
data: inputData,
|
|
1846
1846
|
extrinsicType: _KoniTypes.ExtrinsicType.TRANSFER_XCM,
|
|
1847
|
-
chainType: !
|
|
1847
|
+
chainType: !isSnowBridgeEvmTransfer ? _KoniTypes.ChainType.SUBSTRATE : _KoniTypes.ChainType.EVM,
|
|
1848
1848
|
transferNativeAmount: (0, _utils3._isNativeToken)(originTokenInfo) ? value : '0',
|
|
1849
1849
|
ignoreWarnings: inputData.transferAll,
|
|
1850
1850
|
isTransferAll: inputData.transferAll,
|
|
@@ -2003,8 +2003,9 @@ class KoniExtension {
|
|
|
2003
2003
|
const substrateApi = this.#koniState.chainService.getSubstrateApi(originTokenInfo.originChain);
|
|
2004
2004
|
const chainInfoMap = this.#koniState.chainService.getChainInfoMap();
|
|
2005
2005
|
const destinationTokenInfo = this.#koniState.getXcmEqualAssetByChain(destChain, originTokenInfo.slug);
|
|
2006
|
+
const existentialDeposit = originTokenInfo.minAmount || '0';
|
|
2006
2007
|
if (destinationTokenInfo) {
|
|
2007
|
-
const [
|
|
2008
|
+
const [bnMockExecutionFee, {
|
|
2008
2009
|
value
|
|
2009
2010
|
}] = await Promise.all([(0, _xcm.getXcmMockTxFee)(substrateApi, chainInfoMap, originTokenInfo, destinationTokenInfo), this.getAddressTransferableBalance({
|
|
2010
2011
|
extrinsicType: _KoniTypes.ExtrinsicType.TRANSFER_XCM,
|
|
@@ -2013,8 +2014,7 @@ class KoniExtension {
|
|
|
2013
2014
|
token: originTokenInfo.slug
|
|
2014
2015
|
})]);
|
|
2015
2016
|
const bnMaxTransferable = new _bignumber.default(value);
|
|
2016
|
-
const estimatedFee =
|
|
2017
|
-
|
|
2017
|
+
const estimatedFee = bnMockExecutionFee.multipliedBy(_constants.XCM_FEE_RATIO).plus(new _bignumber.default(existentialDeposit));
|
|
2018
2018
|
return bnMaxTransferable.minus(estimatedFee);
|
|
2019
2019
|
}
|
|
2020
2020
|
return new _bignumber.default(0);
|
package/cjs/packageInfo.js
CHANGED
|
@@ -78,6 +78,21 @@ const filterAddress = (addresses, chainInfo) => {
|
|
|
78
78
|
return [fetchList, [...unfetchList, ...evmAddresses]];
|
|
79
79
|
}
|
|
80
80
|
};
|
|
81
|
+
const handleUnsupportedOrPendingAddresses = (addresses, chainSlug, chainAssetMap, state, callback) => {
|
|
82
|
+
const tokens = (0, _utils2.filterAssetsByChainAndType)(chainAssetMap, chainSlug, [_types._AssetType.NATIVE, _types._AssetType.ERC20, _types._AssetType.PSP22, _types._AssetType.LOCAL, _types._AssetType.GRC20, _types._AssetType.VFT]);
|
|
83
|
+
const now = new Date().getTime();
|
|
84
|
+
Object.values(tokens).forEach(token => {
|
|
85
|
+
const items = addresses.map(address => ({
|
|
86
|
+
address,
|
|
87
|
+
tokenSlug: token.slug,
|
|
88
|
+
free: '0',
|
|
89
|
+
locked: '0',
|
|
90
|
+
state,
|
|
91
|
+
timestamp: now
|
|
92
|
+
}));
|
|
93
|
+
callback(items);
|
|
94
|
+
});
|
|
95
|
+
};
|
|
81
96
|
|
|
82
97
|
// main subscription, use for multiple chains, multiple addresses and multiple tokens
|
|
83
98
|
function subscribeBalance(addresses, chains, tokens, _chainAssetMap, _chainInfoMap, substrateApiMap, evmApiMap, callback, extrinsicType) {
|
|
@@ -96,19 +111,7 @@ function subscribeBalance(addresses, chains, tokens, _chainAssetMap, _chainInfoM
|
|
|
96
111
|
const chainSlug = chainInfo.slug;
|
|
97
112
|
const [useAddresses, notSupportAddresses] = filterAddress(addresses, chainInfo);
|
|
98
113
|
if (notSupportAddresses.length) {
|
|
99
|
-
|
|
100
|
-
const now = new Date().getTime();
|
|
101
|
-
Object.values(tokens).forEach(token => {
|
|
102
|
-
const items = notSupportAddresses.map(address => ({
|
|
103
|
-
address,
|
|
104
|
-
tokenSlug: token.slug,
|
|
105
|
-
free: '0',
|
|
106
|
-
locked: '0',
|
|
107
|
-
state: _KoniTypes.APIItemState.NOT_SUPPORT,
|
|
108
|
-
timestamp: now
|
|
109
|
-
}));
|
|
110
|
-
callback(items);
|
|
111
|
-
});
|
|
114
|
+
handleUnsupportedOrPendingAddresses(notSupportAddresses, chainSlug, chainAssetMap, _KoniTypes.APIItemState.NOT_SUPPORT, callback);
|
|
112
115
|
}
|
|
113
116
|
const evmApi = evmApiMap[chainSlug];
|
|
114
117
|
if ((0, _utils._isPureEvmChain)(chainInfo)) {
|
|
@@ -121,6 +124,9 @@ function subscribeBalance(addresses, chains, tokens, _chainAssetMap, _chainInfoM
|
|
|
121
124
|
});
|
|
122
125
|
}
|
|
123
126
|
const substrateApi = await substrateApiMap[chainSlug].isReady;
|
|
127
|
+
if (!substrateApi.isApiReady) {
|
|
128
|
+
handleUnsupportedOrPendingAddresses(useAddresses, chainSlug, chainAssetMap, _KoniTypes.APIItemState.PENDING, callback);
|
|
129
|
+
}
|
|
124
130
|
return (0, _substrate.subscribeSubstrateBalance)(useAddresses, chainInfo, chainAssetMap, substrateApi, evmApi, callback, extrinsicType);
|
|
125
131
|
});
|
|
126
132
|
return () => {
|
|
@@ -23,7 +23,8 @@ const subscribeGRC20Balance = _ref => {
|
|
|
23
23
|
chainInfo,
|
|
24
24
|
substrateApi
|
|
25
25
|
} = _ref;
|
|
26
|
-
|
|
26
|
+
const apiPromise = substrateApi.api;
|
|
27
|
+
if (!(apiPromise instanceof _api.GearApi)) {
|
|
27
28
|
console.warn('Cannot subscribe GRC20 balance without GearApi instance');
|
|
28
29
|
return _util.noop;
|
|
29
30
|
}
|
|
@@ -32,7 +33,7 @@ const subscribeGRC20Balance = _ref => {
|
|
|
32
33
|
const tokenList = (0, _utils2.filterAssetsByChainAndType)(assetMap, chain, [_types._AssetType.GRC20]);
|
|
33
34
|
Object.entries(tokenList).forEach(_ref2 => {
|
|
34
35
|
let [slug, tokenInfo] = _ref2;
|
|
35
|
-
grc20ContractMap[slug] = (0, _utils2.getGRC20ContractPromise)(
|
|
36
|
+
grc20ContractMap[slug] = (0, _utils2.getGRC20ContractPromise)(apiPromise, (0, _utils._getContractAddressOfToken)(tokenInfo));
|
|
36
37
|
});
|
|
37
38
|
const getTokenBalances = () => {
|
|
38
39
|
Object.values(tokenList).map(async tokenInfo => {
|
|
@@ -82,7 +83,8 @@ const subscribeVftBalance = _ref3 => {
|
|
|
82
83
|
chainInfo,
|
|
83
84
|
substrateApi
|
|
84
85
|
} = _ref3;
|
|
85
|
-
|
|
86
|
+
const apiPromise = substrateApi.api;
|
|
87
|
+
if (!(apiPromise instanceof _api.GearApi)) {
|
|
86
88
|
console.warn('Cannot subscribe VFT balance without GearApi instance');
|
|
87
89
|
return _util.noop;
|
|
88
90
|
}
|
|
@@ -91,7 +93,7 @@ const subscribeVftBalance = _ref3 => {
|
|
|
91
93
|
const tokenList = (0, _utils2.filterAssetsByChainAndType)(assetMap, chain, [_types._AssetType.VFT]);
|
|
92
94
|
Object.entries(tokenList).forEach(_ref4 => {
|
|
93
95
|
let [slug, tokenInfo] = _ref4;
|
|
94
|
-
vftContractMap[slug] = (0, _utils2.getVFTContractPromise)(
|
|
96
|
+
vftContractMap[slug] = (0, _utils2.getVFTContractPromise)(apiPromise, (0, _utils._getContractAddressOfToken)(tokenInfo));
|
|
95
97
|
});
|
|
96
98
|
const getTokenBalances = () => {
|
|
97
99
|
Object.values(tokenList).map(async tokenInfo => {
|
|
@@ -114,7 +114,6 @@ const subscribeSubstrateBalance = async (addresses, chainInfo, assetMap, substra
|
|
|
114
114
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
115
115
|
exports.subscribeSubstrateBalance = subscribeSubstrateBalance;
|
|
116
116
|
const subscribeWithSystemAccountPallet = async _ref => {
|
|
117
|
-
var _substrateApi$api$tx, _substrateApi$api$tx$;
|
|
118
117
|
let {
|
|
119
118
|
addresses,
|
|
120
119
|
callback,
|
|
@@ -124,7 +123,7 @@ const subscribeWithSystemAccountPallet = async _ref => {
|
|
|
124
123
|
} = _ref;
|
|
125
124
|
const systemAccountKey = 'query_system_account';
|
|
126
125
|
const poolMembersKey = 'query_nominationPools_poolMembers';
|
|
127
|
-
const isNominationPoolMigrated =
|
|
126
|
+
const isNominationPoolMigrated = await checkNominationPoolCompleteMigrated(substrateApi);
|
|
128
127
|
const params = [{
|
|
129
128
|
section: 'query',
|
|
130
129
|
module: systemAccountKey.split('_')[1],
|
|
@@ -167,6 +166,19 @@ const subscribeWithSystemAccountPallet = async _ref => {
|
|
|
167
166
|
subscription.unsubscribe();
|
|
168
167
|
};
|
|
169
168
|
};
|
|
169
|
+
const checkNominationPoolCompleteMigrated = async substrateApi => {
|
|
170
|
+
if (!substrateApi.api.tx.nominationPools || !substrateApi.api.query.staking) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
const isNominationPoolMigrated = !!substrateApi.api.tx.nominationPools.migrateDelegation && !!substrateApi.api.query.staking.counterForVirtualStakers && !!substrateApi.api.query.staking.virtualStakers;
|
|
174
|
+
if (!isNominationPoolMigrated) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
const [nominationPoolCounterRaw, nominationPoolInfoRaw] = await Promise.all([substrateApi.api.query.staking.counterForVirtualStakers(), substrateApi.api.query.staking.virtualStakers.entries()]);
|
|
178
|
+
const nominationPoolCounter = nominationPoolCounterRaw.toPrimitive();
|
|
179
|
+
const nominationPoolInfoLength = nominationPoolInfoRaw.length;
|
|
180
|
+
return nominationPoolCounter !== 0 && nominationPoolInfoLength !== 0;
|
|
181
|
+
};
|
|
170
182
|
const subscribeForeignAssetBalance = async _ref2 => {
|
|
171
183
|
let {
|
|
172
184
|
addresses,
|
|
@@ -49,19 +49,14 @@ const createXcmExtrinsic = async _ref2 => {
|
|
|
49
49
|
const destinationChainInfo = chainInfoMap[destinationTokenInfo.originChain];
|
|
50
50
|
const chainApi = await substrateApi.isReady;
|
|
51
51
|
const api = chainApi.api;
|
|
52
|
-
|
|
53
|
-
if (_constants._XCM_CHAIN_GROUP.polkadotXcm.includes(originTokenInfo.originChain)) {
|
|
54
|
-
|
|
55
|
-
extrinsic = (0, _xTokens.getExtrinsicByXtokensPallet)(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
|
|
56
|
-
} else {
|
|
57
|
-
extrinsic = (0, _polkadotXcm.getExtrinsicByPolkadotXcmPallet)(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
|
|
58
|
-
}
|
|
59
|
-
} else if (_constants._XCM_CHAIN_GROUP.xcmPallet.includes(originTokenInfo.originChain)) {
|
|
60
|
-
extrinsic = (0, _xcmPallet.getExtrinsicByXcmPalletPallet)(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
|
|
61
|
-
} else {
|
|
62
|
-
extrinsic = (0, _xTokens.getExtrinsicByXtokensPallet)(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
|
|
52
|
+
const polkadotXcmSpecialCases = _constants._XCM_CHAIN_GROUP.polkadotXcmSpecialCases.includes(originChainInfo.slug) && (0, _utils._isNativeToken)(originTokenInfo);
|
|
53
|
+
if (_constants._XCM_CHAIN_GROUP.polkadotXcm.includes(originTokenInfo.originChain) || polkadotXcmSpecialCases) {
|
|
54
|
+
return (0, _polkadotXcm.getExtrinsicByPolkadotXcmPallet)(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
|
|
63
55
|
}
|
|
64
|
-
|
|
56
|
+
if (_constants._XCM_CHAIN_GROUP.xcmPallet.includes(originTokenInfo.originChain)) {
|
|
57
|
+
return (0, _xcmPallet.getExtrinsicByXcmPalletPallet)(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
|
|
58
|
+
}
|
|
59
|
+
return (0, _xTokens.getExtrinsicByXtokensPallet)(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
|
|
65
60
|
};
|
|
66
61
|
exports.createXcmExtrinsic = createXcmExtrinsic;
|
|
67
62
|
const getXcmMockTxFee = async (substrateApi, chainInfoMap, originTokenInfo, destinationTokenInfo) => {
|
|
@@ -69,7 +64,7 @@ const getXcmMockTxFee = async (substrateApi, chainInfoMap, originTokenInfo, dest
|
|
|
69
64
|
var _paymentInfo$partialF;
|
|
70
65
|
const destChainInfo = chainInfoMap[destinationTokenInfo.originChain];
|
|
71
66
|
const originChainInfo = chainInfoMap[originTokenInfo.originChain];
|
|
72
|
-
const address = '5DRewsYzhJqZXU3SRaWy1FSt5iDr875ao91aw5fjrJmDG4Ap';
|
|
67
|
+
const address = '5DRewsYzhJqZXU3SRaWy1FSt5iDr875ao91aw5fjrJmDG4Ap'; // todo: move this
|
|
73
68
|
|
|
74
69
|
// mock receiving account from sender
|
|
75
70
|
const recipient = !(0, _utilCrypto.isEthereumAddress)(address) && (0, _utils._isChainEvmCompatible)(destChainInfo) && !(0, _utils._isChainEvmCompatible)(originChainInfo) ? (0, _util.u8aToHex)((0, _utilCrypto.addressToEvm)(address)) : address;
|
|
@@ -283,7 +283,8 @@ const _DEFAULT_MANTA_ZK_CHAIN = 'calamari';
|
|
|
283
283
|
// XCM------------------------------------------------------------------------------------------------------------------
|
|
284
284
|
exports._DEFAULT_MANTA_ZK_CHAIN = _DEFAULT_MANTA_ZK_CHAIN;
|
|
285
285
|
const _XCM_CHAIN_GROUP = {
|
|
286
|
-
polkadotXcm: ['
|
|
286
|
+
polkadotXcm: ['statemine', 'statemint', 'equilibrium_parachain', 'rococo_assethub', 'mythos'],
|
|
287
|
+
polkadotXcmSpecialCases: ['astar', 'shiden'],
|
|
287
288
|
xcmPallet: ['polkadot', 'kusama', 'rococo']
|
|
288
289
|
// default is xTokens pallet
|
|
289
290
|
};
|
|
@@ -61,7 +61,6 @@ class InterlayLendingPoolHandler extends _base.default {
|
|
|
61
61
|
statistic: {
|
|
62
62
|
assetEarning: [{
|
|
63
63
|
slug: this.rewardAssets[0],
|
|
64
|
-
apr: 1.29,
|
|
65
64
|
exchangeRate: exchangeRate / decimals
|
|
66
65
|
}],
|
|
67
66
|
maxCandidatePerFarmer: 1,
|
|
@@ -71,7 +70,6 @@ class InterlayLendingPoolHandler extends _base.default {
|
|
|
71
70
|
defaultUnstake: '0',
|
|
72
71
|
fastUnstake: '0'
|
|
73
72
|
},
|
|
74
|
-
totalApr: 1.29,
|
|
75
73
|
tvl: '291890000000000'
|
|
76
74
|
}
|
|
77
75
|
};
|
|
@@ -46,7 +46,7 @@ class ParallelLiquidStakingPoolHandler extends _base.default {
|
|
|
46
46
|
|
|
47
47
|
async getPoolStat() {
|
|
48
48
|
const substrateApi = await this.substrateApi.isReady;
|
|
49
|
-
const [_exchangeRate,
|
|
49
|
+
const [_exchangeRate, _stakingLedgers] = await Promise.all([substrateApi.api.query.liquidStaking.exchangeRate(), substrateApi.api.query.liquidStaking.stakingLedgers.entries()]);
|
|
50
50
|
let tvl = _util.BN_ZERO;
|
|
51
51
|
for (const _stakingLedger of _stakingLedgers) {
|
|
52
52
|
const _ledger = _stakingLedger[1];
|
|
@@ -54,16 +54,7 @@ class ParallelLiquidStakingPoolHandler extends _base.default {
|
|
|
54
54
|
tvl = tvl.add(new _util.BN(ledger.total.toString()));
|
|
55
55
|
}
|
|
56
56
|
const exchangeRate = _exchangeRate.toPrimitive();
|
|
57
|
-
const currentBlockHeader = _currentBlockHeader.toPrimitive();
|
|
58
|
-
const currentTimestamp = _currentTimestamp.toPrimitive();
|
|
59
|
-
const beginBlock = currentBlockHeader.number - 24 * 60 * 60 / 6 * 14;
|
|
60
|
-
const _beginBlockHash = await substrateApi.api.rpc.chain.getBlockHash(beginBlock);
|
|
61
|
-
const beginBlockHash = _beginBlockHash.toString();
|
|
62
|
-
const [_beginTimestamp, _beginExchangeRate] = await Promise.all([substrateApi.api.query.timestamp.now.at(beginBlockHash), substrateApi.api.query.liquidStaking.exchangeRate.at(beginBlockHash)]);
|
|
63
|
-
const beginTimestamp = _beginTimestamp.toPrimitive();
|
|
64
|
-
const beginExchangeRate = _beginExchangeRate.toPrimitive();
|
|
65
57
|
const decimals = 10 ** this.rateDecimals;
|
|
66
|
-
const apy = (exchangeRate / beginExchangeRate) ** (365 * 24 * 60 * 60000 / (currentTimestamp - beginTimestamp)) - 1;
|
|
67
58
|
const minStake = substrateApi.api.consts.liquidStaking.minStake.toString();
|
|
68
59
|
const minUnstake = substrateApi.api.consts.liquidStaking.minUnstake.toString();
|
|
69
60
|
this.updateExchangeRate(exchangeRate);
|
|
@@ -77,7 +68,6 @@ class ParallelLiquidStakingPoolHandler extends _base.default {
|
|
|
77
68
|
statistic: {
|
|
78
69
|
assetEarning: [{
|
|
79
70
|
slug: this.rewardAssets[0],
|
|
80
|
-
apy: apy * 100,
|
|
81
71
|
exchangeRate: exchangeRate / decimals
|
|
82
72
|
}],
|
|
83
73
|
unstakingPeriod: 24 * 28,
|
|
@@ -88,7 +78,6 @@ class ParallelLiquidStakingPoolHandler extends _base.default {
|
|
|
88
78
|
defaultUnstake: minUnstake,
|
|
89
79
|
fastUnstake: '0'
|
|
90
80
|
},
|
|
91
|
-
totalApy: apy * 100,
|
|
92
81
|
tvl: tvl.toString()
|
|
93
82
|
}
|
|
94
83
|
};
|
|
@@ -14,8 +14,8 @@ class MigrateTransactionHistoryBySymbol extends _Base.default {
|
|
|
14
14
|
const state = this.state;
|
|
15
15
|
try {
|
|
16
16
|
const changeSlugsMap = {
|
|
17
|
-
'
|
|
18
|
-
'
|
|
17
|
+
'polygon-NATIVE-MATIC': 'polygon-NATIVE-POL',
|
|
18
|
+
'5irechain_mainnet-NATIVE-5IRE': '5irechain_mainnet-NATIVE-5ire'
|
|
19
19
|
};
|
|
20
20
|
const allTxs = [];
|
|
21
21
|
await Promise.all(Object.entries(changeSlugsMap).map(async (_ref, i) => {
|
|
@@ -13,8 +13,8 @@ class MigrateAssetSetting extends _Base.default {
|
|
|
13
13
|
async run() {
|
|
14
14
|
try {
|
|
15
15
|
const changeSlugsMap = {
|
|
16
|
-
'
|
|
17
|
-
'
|
|
16
|
+
'polygon-NATIVE-MATIC': 'polygon-NATIVE-POL',
|
|
17
|
+
'5irechain_mainnet-NATIVE-5IRE': '5irechain_mainnet-NATIVE-5ire'
|
|
18
18
|
};
|
|
19
19
|
const assetSetting = await this.state.chainService.getAssetSettings();
|
|
20
20
|
const migratedAssetSetting = {};
|
|
@@ -61,8 +61,8 @@ var _default = {
|
|
|
61
61
|
'1.1.33-01': _MigrateLedgerAccountV.default,
|
|
62
62
|
'1.1.41-01': _DeleteChainStaking.default,
|
|
63
63
|
'1.1.46-01': _AutoEnableSomeTokens.default,
|
|
64
|
-
'1.
|
|
65
|
-
'1.
|
|
64
|
+
'1.2.28-01': _MigrateAssetSetting.default,
|
|
65
|
+
'1.2.28-02': _MigrateTransactionHistoryBySymbol.default,
|
|
66
66
|
'1.2.69-01': _MigrateRemoveGenesisHash.default,
|
|
67
67
|
'1.2.13-01': _ReloadMetadata.default,
|
|
68
68
|
'1.2.14-01': _ClearMetadataDatabase.default
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.ChainflipSwapHandler = void 0;
|
|
7
|
+
exports.ChainflipSwapHandler = exports.CHAINFLIP_BROKER_API = void 0;
|
|
8
8
|
var _swap = require("@chainflip/sdk/swap");
|
|
9
9
|
var _chainList = require("@subwallet/chain-list");
|
|
10
10
|
var _SwapError = require("@subwallet/extension-base/background/errors/SwapError");
|
|
@@ -26,10 +26,13 @@ var ChainflipFeeType;
|
|
|
26
26
|
ChainflipFeeType["INGRESS"] = "INGRESS";
|
|
27
27
|
ChainflipFeeType["NETWORK"] = "NETWORK";
|
|
28
28
|
ChainflipFeeType["EGRESS"] = "EGRESS";
|
|
29
|
-
ChainflipFeeType["
|
|
29
|
+
ChainflipFeeType["BOOST"] = "BOOST";
|
|
30
|
+
ChainflipFeeType["BROKER"] = "BROKER";
|
|
30
31
|
})(ChainflipFeeType || (ChainflipFeeType = {}));
|
|
31
32
|
const INTERMEDIARY_MAINNET_ASSET_SLUG = _chainList.COMMON_ASSETS.USDC_ETHEREUM;
|
|
32
33
|
const INTERMEDIARY_TESTNET_ASSET_SLUG = _chainList.COMMON_ASSETS.USDC_SEPOLIA;
|
|
34
|
+
const CHAINFLIP_BROKER_API = process.env.CHAINFLIP_BROKER_API || '';
|
|
35
|
+
exports.CHAINFLIP_BROKER_API = CHAINFLIP_BROKER_API;
|
|
33
36
|
var CHAINFLIP_QUOTE_ERROR;
|
|
34
37
|
(function (CHAINFLIP_QUOTE_ERROR) {
|
|
35
38
|
CHAINFLIP_QUOTE_ERROR["InsufficientLiquidity"] = "InsufficientLiquidity";
|
|
@@ -47,9 +50,9 @@ class ChainflipSwapHandler {
|
|
|
47
50
|
});
|
|
48
51
|
this.isTestnet = isTestnet;
|
|
49
52
|
this.providerSlug = isTestnet ? _swap3.SwapProviderId.CHAIN_FLIP_TESTNET : _swap3.SwapProviderId.CHAIN_FLIP_MAINNET;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
this.swapSdk = new _swap.SwapSDK((0, _utils2.getChainflipOptions)(isTestnet));
|
|
53
56
|
}
|
|
54
57
|
get chainService() {
|
|
55
58
|
return this.swapBaseHandler.chainService;
|
|
@@ -235,7 +238,10 @@ class ChainflipSwapHandler {
|
|
|
235
238
|
case ChainflipFeeType.NETWORK:
|
|
236
239
|
|
|
237
240
|
// eslint-disable-next-line no-fallthrough
|
|
238
|
-
case ChainflipFeeType.
|
|
241
|
+
case ChainflipFeeType.BOOST:
|
|
242
|
+
|
|
243
|
+
// eslint-disable-next-line no-fallthrough
|
|
244
|
+
case ChainflipFeeType.BROKER:
|
|
239
245
|
{
|
|
240
246
|
const tokenSlug = Object.keys(this.assetMapping).find(assetSlug => this.assetMapping[assetSlug] === fee.asset);
|
|
241
247
|
feeComponent.push({
|
|
@@ -256,7 +256,7 @@ class HydradxHandler {
|
|
|
256
256
|
|
|
257
257
|
switch (defaultError) {
|
|
258
258
|
case _sdk.PoolError.InsufficientTradingAmount:
|
|
259
|
-
return new _SwapError.SwapError(_swap2.SwapErrorType.
|
|
259
|
+
return new _SwapError.SwapError(_swap2.SwapErrorType.NOT_MEET_MIN_SWAP);
|
|
260
260
|
case _sdk.PoolError.TradeNotAllowed:
|
|
261
261
|
return new _SwapError.SwapError(_swap2.SwapErrorType.ERROR_FETCHING_QUOTE);
|
|
262
262
|
case _sdk.PoolError.MaxInRatioExceeded:
|
|
@@ -7,11 +7,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports._PROVIDER_TO_SUPPORTED_PAIR_MAP = exports.SWAP_QUOTE_TIMEOUT_MAP = exports.CHAIN_FLIP_TESTNET_EXPLORER = exports.CHAIN_FLIP_SUPPORTED_TESTNET_MAPPING = exports.CHAIN_FLIP_SUPPORTED_TESTNET_ASSET_MAPPING = exports.CHAIN_FLIP_SUPPORTED_MAINNET_MAPPING = exports.CHAIN_FLIP_SUPPORTED_MAINNET_ASSET_MAPPING = exports.CHAIN_FLIP_MAINNET_EXPLORER = void 0;
|
|
8
8
|
exports.calculateSwapRate = calculateSwapRate;
|
|
9
9
|
exports.convertSwapRate = convertSwapRate;
|
|
10
|
+
exports.getChainflipBroker = getChainflipBroker;
|
|
11
|
+
exports.getChainflipOptions = getChainflipOptions;
|
|
10
12
|
exports.getSwapAltToken = getSwapAltToken;
|
|
11
13
|
exports.getSwapAlternativeAsset = getSwapAlternativeAsset;
|
|
12
14
|
var _swap = require("@chainflip/sdk/swap");
|
|
13
15
|
var _chainList = require("@subwallet/chain-list");
|
|
14
16
|
var _utils = require("@subwallet/extension-base/services/chain-service/utils");
|
|
17
|
+
var _chainflipHandler = require("@subwallet/extension-base/services/swap-service/handler/chainflip-handler");
|
|
15
18
|
var _swap2 = require("@subwallet/extension-base/types/swap");
|
|
16
19
|
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
17
20
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
@@ -79,4 +82,30 @@ function convertSwapRate(rate, fromAsset, toAsset) {
|
|
|
79
82
|
const decimalDiff = (0, _utils._getAssetDecimals)(toAsset) - (0, _utils._getAssetDecimals)(fromAsset);
|
|
80
83
|
const bnRate = new _bignumber.default(rate);
|
|
81
84
|
return bnRate.times(10 ** decimalDiff).pow(-1).toNumber();
|
|
85
|
+
}
|
|
86
|
+
function getChainflipOptions(isTestnet) {
|
|
87
|
+
if (isTestnet) {
|
|
88
|
+
return {
|
|
89
|
+
network: getChainflipNetwork(isTestnet)
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
network: getChainflipNetwork(isTestnet),
|
|
94
|
+
broker: getChainflipBroker(isTestnet)
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function getChainflipNetwork(isTestnet) {
|
|
98
|
+
return isTestnet ? 'perseverance' : 'mainnet';
|
|
99
|
+
}
|
|
100
|
+
function getChainflipBroker(isTestnet) {
|
|
101
|
+
// noted: currently not use testnet broker
|
|
102
|
+
if (isTestnet) {
|
|
103
|
+
return {
|
|
104
|
+
url: `https://perseverance.chainflip-broker.io/rpc/${_chainflipHandler.CHAINFLIP_BROKER_API}`
|
|
105
|
+
};
|
|
106
|
+
} else {
|
|
107
|
+
return {
|
|
108
|
+
url: `https://chainflip-broker.io/rpc/${_chainflipHandler.CHAINFLIP_BROKER_API}`
|
|
109
|
+
};
|
|
110
|
+
}
|
|
82
111
|
}
|
|
@@ -47,8 +47,9 @@ export declare function _getXcmMultiLocation(originChainInfo: _ChainInfo, destCh
|
|
|
47
47
|
interior: unknown;
|
|
48
48
|
};
|
|
49
49
|
};
|
|
50
|
-
export declare function _isXcmTransferUnstable(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): boolean;
|
|
51
|
-
export declare function _getXcmUnstableWarning(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): string;
|
|
50
|
+
export declare function _isXcmTransferUnstable(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo, assetSlug: string): boolean;
|
|
51
|
+
export declare function _getXcmUnstableWarning(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo, assetSlug: string): string;
|
|
52
52
|
export declare function _isXcmWithinSameConsensus(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): boolean;
|
|
53
53
|
export declare function _isSnowBridgeXcm(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo): boolean;
|
|
54
|
+
export declare function _isMythosFromHydrationToMythos(originChainInfo: _ChainInfo, destChainInfo: _ChainInfo, assetSlug: string): boolean;
|
|
54
55
|
export declare function _adaptX1Interior(assetIdentifier: Record<string, any>, version: number): Record<string, any>;
|
|
@@ -46,8 +46,8 @@ export function _getXcmMultiLocation(originChainInfo, destChainInfo, version, re
|
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
|
-
export function _isXcmTransferUnstable(originChainInfo, destChainInfo) {
|
|
50
|
-
return !_isXcmWithinSameConsensus(originChainInfo, destChainInfo);
|
|
49
|
+
export function _isXcmTransferUnstable(originChainInfo, destChainInfo, assetSlug) {
|
|
50
|
+
return !_isXcmWithinSameConsensus(originChainInfo, destChainInfo) || _isMythosFromHydrationToMythos(originChainInfo, destChainInfo, assetSlug);
|
|
51
51
|
}
|
|
52
52
|
function getAssetHubBridgeUnstableWarning(originChainInfo) {
|
|
53
53
|
switch (originChainInfo.slug) {
|
|
@@ -62,16 +62,21 @@ function getAssetHubBridgeUnstableWarning(originChainInfo) {
|
|
|
62
62
|
function getSnowBridgeUnstableWarning(originChainInfo) {
|
|
63
63
|
switch (originChainInfo.slug) {
|
|
64
64
|
case COMMON_CHAIN_SLUGS.POLKADOT_ASSET_HUB:
|
|
65
|
-
return 'Cross-chain transfer of this token is not recommended as it is in beta, incurs a fee of 70
|
|
65
|
+
return 'Cross-chain transfer of this token is not recommended as it is in beta, incurs a fee of $70 and takes up to 1 hour to complete. Continue at your own risk';
|
|
66
66
|
case COMMON_CHAIN_SLUGS.ETHEREUM:
|
|
67
|
-
return 'Cross-chain transfer of this token is not recommended as it is in beta, incurs a fee of 5
|
|
67
|
+
return 'Cross-chain transfer of this token is not recommended as it is in beta, incurs a fee of $5 and takes up to 1 hour to complete. Continue at your own risk';
|
|
68
68
|
default:
|
|
69
69
|
return 'Cross-chain transfer of this token is not recommended as it is in beta, incurs a high fee and takes up to 1 hour to complete. Continue at your own risk';
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
|
|
72
|
+
function getMythosFromHydrationToMythosWarning() {
|
|
73
|
+
return 'Cross-chain transfer of this token requires a high transaction fee. Do you want to continue?';
|
|
74
|
+
}
|
|
75
|
+
export function _getXcmUnstableWarning(originChainInfo, destChainInfo, assetSlug) {
|
|
73
76
|
if (_isSnowBridgeXcm(originChainInfo, destChainInfo)) {
|
|
74
77
|
return getSnowBridgeUnstableWarning(originChainInfo);
|
|
78
|
+
} else if (_isMythosFromHydrationToMythos(originChainInfo, destChainInfo, assetSlug)) {
|
|
79
|
+
return getMythosFromHydrationToMythosWarning();
|
|
75
80
|
} else {
|
|
76
81
|
return getAssetHubBridgeUnstableWarning(originChainInfo);
|
|
77
82
|
}
|
|
@@ -82,6 +87,9 @@ export function _isXcmWithinSameConsensus(originChainInfo, destChainInfo) {
|
|
|
82
87
|
export function _isSnowBridgeXcm(originChainInfo, destChainInfo) {
|
|
83
88
|
return !_isXcmWithinSameConsensus(originChainInfo, destChainInfo) && (_isPureEvmChain(originChainInfo) || _isPureEvmChain(destChainInfo));
|
|
84
89
|
}
|
|
90
|
+
export function _isMythosFromHydrationToMythos(originChainInfo, destChainInfo, assetSlug) {
|
|
91
|
+
return originChainInfo.slug === 'hydradx_main' && destChainInfo.slug === 'mythos' && assetSlug === 'hydradx_main-LOCAL-MYTH';
|
|
92
|
+
}
|
|
85
93
|
|
|
86
94
|
// ---------------------------------------------------------------------------------------------------------------------
|
|
87
95
|
|
|
@@ -195,7 +203,7 @@ function _getAssetIdentifier(tokenInfo, version) {
|
|
|
195
203
|
if (!_assetIdentifier) {
|
|
196
204
|
throw new Error('Asset must have multilocation');
|
|
197
205
|
}
|
|
198
|
-
const assetIdentifier = ['statemint-LOCAL-KSM'].includes(tokenInfo.slug) // todo: hotfix for ksm statemint recheck all chain
|
|
206
|
+
const assetIdentifier = ['statemint-LOCAL-KSM', 'statemine-LOCAL-DOT'].includes(tokenInfo.slug) // todo: hotfix for ksm statemint recheck all chain
|
|
199
207
|
? _assetIdentifier : _adaptX1Interior(structuredClone(_assetIdentifier), version);
|
|
200
208
|
return version >= 4 // from V4, Concrete is removed
|
|
201
209
|
? assetIdentifier : {
|
|
@@ -1711,11 +1711,11 @@ export default class KoniExtension {
|
|
|
1711
1711
|
return this.#koniState.transactionService.generateBeforeHandleResponseErrors(errors);
|
|
1712
1712
|
}
|
|
1713
1713
|
const chainInfoMap = this.#koniState.getChainInfoMap();
|
|
1714
|
-
const
|
|
1714
|
+
const isSnowBridgeEvmTransfer = _isPureEvmChain(chainInfoMap[originNetworkKey]) && _isSnowBridgeXcm(chainInfoMap[originNetworkKey], chainInfoMap[destinationNetworkKey]);
|
|
1715
1715
|
let additionalValidator;
|
|
1716
1716
|
let eventsHandler;
|
|
1717
1717
|
if (fromKeyPair && destinationTokenInfo) {
|
|
1718
|
-
if (
|
|
1718
|
+
if (isSnowBridgeEvmTransfer) {
|
|
1719
1719
|
const evmApi = this.#koniState.getEvmApi(originNetworkKey);
|
|
1720
1720
|
extrinsic = await createSnowBridgeExtrinsic({
|
|
1721
1721
|
destinationTokenInfo,
|
|
@@ -1785,7 +1785,7 @@ export default class KoniExtension {
|
|
|
1785
1785
|
transaction: extrinsic,
|
|
1786
1786
|
data: inputData,
|
|
1787
1787
|
extrinsicType: ExtrinsicType.TRANSFER_XCM,
|
|
1788
|
-
chainType: !
|
|
1788
|
+
chainType: !isSnowBridgeEvmTransfer ? ChainType.SUBSTRATE : ChainType.EVM,
|
|
1789
1789
|
transferNativeAmount: _isNativeToken(originTokenInfo) ? value : '0',
|
|
1790
1790
|
ignoreWarnings: inputData.transferAll,
|
|
1791
1791
|
isTransferAll: inputData.transferAll,
|
|
@@ -1940,8 +1940,9 @@ export default class KoniExtension {
|
|
|
1940
1940
|
const substrateApi = this.#koniState.chainService.getSubstrateApi(originTokenInfo.originChain);
|
|
1941
1941
|
const chainInfoMap = this.#koniState.chainService.getChainInfoMap();
|
|
1942
1942
|
const destinationTokenInfo = this.#koniState.getXcmEqualAssetByChain(destChain, originTokenInfo.slug);
|
|
1943
|
+
const existentialDeposit = originTokenInfo.minAmount || '0';
|
|
1943
1944
|
if (destinationTokenInfo) {
|
|
1944
|
-
const [
|
|
1945
|
+
const [bnMockExecutionFee, {
|
|
1945
1946
|
value
|
|
1946
1947
|
}] = await Promise.all([getXcmMockTxFee(substrateApi, chainInfoMap, originTokenInfo, destinationTokenInfo), this.getAddressTransferableBalance({
|
|
1947
1948
|
extrinsicType: ExtrinsicType.TRANSFER_XCM,
|
|
@@ -1950,8 +1951,7 @@ export default class KoniExtension {
|
|
|
1950
1951
|
token: originTokenInfo.slug
|
|
1951
1952
|
})]);
|
|
1952
1953
|
const bnMaxTransferable = new BigN(value);
|
|
1953
|
-
const estimatedFee =
|
|
1954
|
-
|
|
1954
|
+
const estimatedFee = bnMockExecutionFee.multipliedBy(XCM_FEE_RATIO).plus(new BigN(existentialDeposit));
|
|
1955
1955
|
return bnMaxTransferable.minus(estimatedFee);
|
|
1956
1956
|
}
|
|
1957
1957
|
return new BigN(0);
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.2.
|
|
20
|
+
"version": "1.2.30-0",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -2038,12 +2038,12 @@
|
|
|
2038
2038
|
"@acala-network/api": "^5.0.2",
|
|
2039
2039
|
"@apollo/client": "^3.7.14",
|
|
2040
2040
|
"@azns/resolver-core": "^1.4.0",
|
|
2041
|
-
"@chainflip/sdk": "^1.
|
|
2041
|
+
"@chainflip/sdk": "^1.5.2",
|
|
2042
2042
|
"@equilab/api": "~1.14.25",
|
|
2043
2043
|
"@ethereumjs/common": "^4.1.0",
|
|
2044
2044
|
"@ethereumjs/tx": "^5.1.0",
|
|
2045
2045
|
"@ethersproject/abi": "^5.7.0",
|
|
2046
|
-
"@galacticcouncil/sdk": "^2.
|
|
2046
|
+
"@galacticcouncil/sdk": "^4.2.0",
|
|
2047
2047
|
"@gear-js/api": "^0.38.1",
|
|
2048
2048
|
"@json-rpc-tools/utils": "^1.7.6",
|
|
2049
2049
|
"@metamask/eth-sig-util": "^7.0.3",
|
|
@@ -2070,11 +2070,11 @@
|
|
|
2070
2070
|
"@reduxjs/toolkit": "^1.9.1",
|
|
2071
2071
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
2072
2072
|
"@substrate/connect": "^0.8.9",
|
|
2073
|
-
"@subwallet/chain-list": "0.2.
|
|
2074
|
-
"@subwallet/extension-base": "^1.2.
|
|
2075
|
-
"@subwallet/extension-chains": "^1.2.
|
|
2076
|
-
"@subwallet/extension-dapp": "^1.2.
|
|
2077
|
-
"@subwallet/extension-inject": "^1.2.
|
|
2073
|
+
"@subwallet/chain-list": "0.2.87",
|
|
2074
|
+
"@subwallet/extension-base": "^1.2.30-0",
|
|
2075
|
+
"@subwallet/extension-chains": "^1.2.30-0",
|
|
2076
|
+
"@subwallet/extension-dapp": "^1.2.30-0",
|
|
2077
|
+
"@subwallet/extension-inject": "^1.2.30-0",
|
|
2078
2078
|
"@subwallet/keyring": "^0.1.6",
|
|
2079
2079
|
"@subwallet/ui-keyring": "^0.1.6",
|
|
2080
2080
|
"@walletconnect/keyvaluestorage": "^1.1.1",
|
package/packageInfo.js
CHANGED
|
@@ -7,5 +7,5 @@ export const packageInfo = {
|
|
|
7
7
|
name: '@subwallet/extension-base',
|
|
8
8
|
path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
|
|
9
9
|
type: 'esm',
|
|
10
|
-
version: '1.2.
|
|
10
|
+
version: '1.2.30-0'
|
|
11
11
|
};
|
|
@@ -70,6 +70,21 @@ const filterAddress = (addresses, chainInfo) => {
|
|
|
70
70
|
return [fetchList, [...unfetchList, ...evmAddresses]];
|
|
71
71
|
}
|
|
72
72
|
};
|
|
73
|
+
const handleUnsupportedOrPendingAddresses = (addresses, chainSlug, chainAssetMap, state, callback) => {
|
|
74
|
+
const tokens = filterAssetsByChainAndType(chainAssetMap, chainSlug, [_AssetType.NATIVE, _AssetType.ERC20, _AssetType.PSP22, _AssetType.LOCAL, _AssetType.GRC20, _AssetType.VFT]);
|
|
75
|
+
const now = new Date().getTime();
|
|
76
|
+
Object.values(tokens).forEach(token => {
|
|
77
|
+
const items = addresses.map(address => ({
|
|
78
|
+
address,
|
|
79
|
+
tokenSlug: token.slug,
|
|
80
|
+
free: '0',
|
|
81
|
+
locked: '0',
|
|
82
|
+
state,
|
|
83
|
+
timestamp: now
|
|
84
|
+
}));
|
|
85
|
+
callback(items);
|
|
86
|
+
});
|
|
87
|
+
};
|
|
73
88
|
|
|
74
89
|
// main subscription, use for multiple chains, multiple addresses and multiple tokens
|
|
75
90
|
export function subscribeBalance(addresses, chains, tokens, _chainAssetMap, _chainInfoMap, substrateApiMap, evmApiMap, callback, extrinsicType) {
|
|
@@ -82,19 +97,7 @@ export function subscribeBalance(addresses, chains, tokens, _chainAssetMap, _cha
|
|
|
82
97
|
const chainSlug = chainInfo.slug;
|
|
83
98
|
const [useAddresses, notSupportAddresses] = filterAddress(addresses, chainInfo);
|
|
84
99
|
if (notSupportAddresses.length) {
|
|
85
|
-
|
|
86
|
-
const now = new Date().getTime();
|
|
87
|
-
Object.values(tokens).forEach(token => {
|
|
88
|
-
const items = notSupportAddresses.map(address => ({
|
|
89
|
-
address,
|
|
90
|
-
tokenSlug: token.slug,
|
|
91
|
-
free: '0',
|
|
92
|
-
locked: '0',
|
|
93
|
-
state: APIItemState.NOT_SUPPORT,
|
|
94
|
-
timestamp: now
|
|
95
|
-
}));
|
|
96
|
-
callback(items);
|
|
97
|
-
});
|
|
100
|
+
handleUnsupportedOrPendingAddresses(notSupportAddresses, chainSlug, chainAssetMap, APIItemState.NOT_SUPPORT, callback);
|
|
98
101
|
}
|
|
99
102
|
const evmApi = evmApiMap[chainSlug];
|
|
100
103
|
if (_isPureEvmChain(chainInfo)) {
|
|
@@ -107,6 +110,9 @@ export function subscribeBalance(addresses, chains, tokens, _chainAssetMap, _cha
|
|
|
107
110
|
});
|
|
108
111
|
}
|
|
109
112
|
const substrateApi = await substrateApiMap[chainSlug].isReady;
|
|
113
|
+
if (!substrateApi.isApiReady) {
|
|
114
|
+
handleUnsupportedOrPendingAddresses(useAddresses, chainSlug, chainAssetMap, APIItemState.PENDING, callback);
|
|
115
|
+
}
|
|
110
116
|
return subscribeSubstrateBalance(useAddresses, chainInfo, chainAssetMap, substrateApi, evmApi, callback, extrinsicType);
|
|
111
117
|
});
|
|
112
118
|
return () => {
|
|
@@ -16,7 +16,8 @@ export const subscribeGRC20Balance = ({
|
|
|
16
16
|
chainInfo,
|
|
17
17
|
substrateApi
|
|
18
18
|
}) => {
|
|
19
|
-
|
|
19
|
+
const apiPromise = substrateApi.api;
|
|
20
|
+
if (!(apiPromise instanceof GearApi)) {
|
|
20
21
|
console.warn('Cannot subscribe GRC20 balance without GearApi instance');
|
|
21
22
|
return noop;
|
|
22
23
|
}
|
|
@@ -24,7 +25,7 @@ export const subscribeGRC20Balance = ({
|
|
|
24
25
|
const grc20ContractMap = {};
|
|
25
26
|
const tokenList = filterAssetsByChainAndType(assetMap, chain, [_AssetType.GRC20]);
|
|
26
27
|
Object.entries(tokenList).forEach(([slug, tokenInfo]) => {
|
|
27
|
-
grc20ContractMap[slug] = getGRC20ContractPromise(
|
|
28
|
+
grc20ContractMap[slug] = getGRC20ContractPromise(apiPromise, _getContractAddressOfToken(tokenInfo));
|
|
28
29
|
});
|
|
29
30
|
const getTokenBalances = () => {
|
|
30
31
|
Object.values(tokenList).map(async tokenInfo => {
|
|
@@ -72,7 +73,8 @@ export const subscribeVftBalance = ({
|
|
|
72
73
|
chainInfo,
|
|
73
74
|
substrateApi
|
|
74
75
|
}) => {
|
|
75
|
-
|
|
76
|
+
const apiPromise = substrateApi.api;
|
|
77
|
+
if (!(apiPromise instanceof GearApi)) {
|
|
76
78
|
console.warn('Cannot subscribe VFT balance without GearApi instance');
|
|
77
79
|
return noop;
|
|
78
80
|
}
|
|
@@ -80,7 +82,7 @@ export const subscribeVftBalance = ({
|
|
|
80
82
|
const vftContractMap = {};
|
|
81
83
|
const tokenList = filterAssetsByChainAndType(assetMap, chain, [_AssetType.VFT]);
|
|
82
84
|
Object.entries(tokenList).forEach(([slug, tokenInfo]) => {
|
|
83
|
-
vftContractMap[slug] = getVFTContractPromise(
|
|
85
|
+
vftContractMap[slug] = getVFTContractPromise(apiPromise, _getContractAddressOfToken(tokenInfo));
|
|
84
86
|
});
|
|
85
87
|
const getTokenBalances = () => {
|
|
86
88
|
Object.values(tokenList).map(async tokenInfo => {
|
|
@@ -112,10 +112,9 @@ const subscribeWithSystemAccountPallet = async ({
|
|
|
112
112
|
extrinsicType,
|
|
113
113
|
substrateApi
|
|
114
114
|
}) => {
|
|
115
|
-
var _substrateApi$api$tx, _substrateApi$api$tx$;
|
|
116
115
|
const systemAccountKey = 'query_system_account';
|
|
117
116
|
const poolMembersKey = 'query_nominationPools_poolMembers';
|
|
118
|
-
const isNominationPoolMigrated =
|
|
117
|
+
const isNominationPoolMigrated = await checkNominationPoolCompleteMigrated(substrateApi);
|
|
119
118
|
const params = [{
|
|
120
119
|
section: 'query',
|
|
121
120
|
module: systemAccountKey.split('_')[1],
|
|
@@ -158,6 +157,19 @@ const subscribeWithSystemAccountPallet = async ({
|
|
|
158
157
|
subscription.unsubscribe();
|
|
159
158
|
};
|
|
160
159
|
};
|
|
160
|
+
const checkNominationPoolCompleteMigrated = async substrateApi => {
|
|
161
|
+
if (!substrateApi.api.tx.nominationPools || !substrateApi.api.query.staking) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
const isNominationPoolMigrated = !!substrateApi.api.tx.nominationPools.migrateDelegation && !!substrateApi.api.query.staking.counterForVirtualStakers && !!substrateApi.api.query.staking.virtualStakers;
|
|
165
|
+
if (!isNominationPoolMigrated) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
const [nominationPoolCounterRaw, nominationPoolInfoRaw] = await Promise.all([substrateApi.api.query.staking.counterForVirtualStakers(), substrateApi.api.query.staking.virtualStakers.entries()]);
|
|
169
|
+
const nominationPoolCounter = nominationPoolCounterRaw.toPrimitive();
|
|
170
|
+
const nominationPoolInfoLength = nominationPoolInfoRaw.length;
|
|
171
|
+
return nominationPoolCounter !== 0 && nominationPoolInfoLength !== 0;
|
|
172
|
+
};
|
|
161
173
|
const subscribeForeignAssetBalance = async ({
|
|
162
174
|
addresses,
|
|
163
175
|
assetMap,
|
|
@@ -39,26 +39,21 @@ export const createXcmExtrinsic = async ({
|
|
|
39
39
|
const destinationChainInfo = chainInfoMap[destinationTokenInfo.originChain];
|
|
40
40
|
const chainApi = await substrateApi.isReady;
|
|
41
41
|
const api = chainApi.api;
|
|
42
|
-
|
|
43
|
-
if (_XCM_CHAIN_GROUP.polkadotXcm.includes(originTokenInfo.originChain)) {
|
|
44
|
-
|
|
45
|
-
extrinsic = getExtrinsicByXtokensPallet(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
|
|
46
|
-
} else {
|
|
47
|
-
extrinsic = getExtrinsicByPolkadotXcmPallet(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
|
|
48
|
-
}
|
|
49
|
-
} else if (_XCM_CHAIN_GROUP.xcmPallet.includes(originTokenInfo.originChain)) {
|
|
50
|
-
extrinsic = getExtrinsicByXcmPalletPallet(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
|
|
51
|
-
} else {
|
|
52
|
-
extrinsic = getExtrinsicByXtokensPallet(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
|
|
42
|
+
const polkadotXcmSpecialCases = _XCM_CHAIN_GROUP.polkadotXcmSpecialCases.includes(originChainInfo.slug) && _isNativeToken(originTokenInfo);
|
|
43
|
+
if (_XCM_CHAIN_GROUP.polkadotXcm.includes(originTokenInfo.originChain) || polkadotXcmSpecialCases) {
|
|
44
|
+
return getExtrinsicByPolkadotXcmPallet(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
|
|
53
45
|
}
|
|
54
|
-
|
|
46
|
+
if (_XCM_CHAIN_GROUP.xcmPallet.includes(originTokenInfo.originChain)) {
|
|
47
|
+
return getExtrinsicByXcmPalletPallet(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
|
|
48
|
+
}
|
|
49
|
+
return getExtrinsicByXtokensPallet(originTokenInfo, originChainInfo, destinationChainInfo, recipient, sendingValue, api);
|
|
55
50
|
};
|
|
56
51
|
export const getXcmMockTxFee = async (substrateApi, chainInfoMap, originTokenInfo, destinationTokenInfo) => {
|
|
57
52
|
try {
|
|
58
53
|
var _paymentInfo$partialF;
|
|
59
54
|
const destChainInfo = chainInfoMap[destinationTokenInfo.originChain];
|
|
60
55
|
const originChainInfo = chainInfoMap[originTokenInfo.originChain];
|
|
61
|
-
const address = '5DRewsYzhJqZXU3SRaWy1FSt5iDr875ao91aw5fjrJmDG4Ap';
|
|
56
|
+
const address = '5DRewsYzhJqZXU3SRaWy1FSt5iDr875ao91aw5fjrJmDG4Ap'; // todo: move this
|
|
62
57
|
|
|
63
58
|
// mock receiving account from sender
|
|
64
59
|
const recipient = !isEthereumAddress(address) && _isChainEvmCompatible(destChainInfo) && !_isChainEvmCompatible(originChainInfo) ? u8aToHex(addressToEvm(address)) : address;
|
|
@@ -76,6 +76,7 @@ export declare const _ZK_ASSET_PREFIX = "zk";
|
|
|
76
76
|
export declare const _DEFAULT_MANTA_ZK_CHAIN = "calamari";
|
|
77
77
|
export declare const _XCM_CHAIN_GROUP: {
|
|
78
78
|
polkadotXcm: string[];
|
|
79
|
+
polkadotXcmSpecialCases: string[];
|
|
79
80
|
xcmPallet: string[];
|
|
80
81
|
};
|
|
81
82
|
export declare const _XCM_TYPE: {
|
|
@@ -261,7 +261,8 @@ export const _DEFAULT_MANTA_ZK_CHAIN = 'calamari';
|
|
|
261
261
|
// XCM------------------------------------------------------------------------------------------------------------------
|
|
262
262
|
|
|
263
263
|
export const _XCM_CHAIN_GROUP = {
|
|
264
|
-
polkadotXcm: ['
|
|
264
|
+
polkadotXcm: ['statemine', 'statemint', 'equilibrium_parachain', 'rococo_assethub', 'mythos'],
|
|
265
|
+
polkadotXcmSpecialCases: ['astar', 'shiden'],
|
|
265
266
|
xcmPallet: ['polkadot', 'kusama', 'rococo']
|
|
266
267
|
// default is xTokens pallet
|
|
267
268
|
};
|
|
@@ -54,7 +54,6 @@ export default class InterlayLendingPoolHandler extends BaseLendingPoolHandler {
|
|
|
54
54
|
statistic: {
|
|
55
55
|
assetEarning: [{
|
|
56
56
|
slug: this.rewardAssets[0],
|
|
57
|
-
apr: 1.29,
|
|
58
57
|
exchangeRate: exchangeRate / decimals
|
|
59
58
|
}],
|
|
60
59
|
maxCandidatePerFarmer: 1,
|
|
@@ -64,7 +63,6 @@ export default class InterlayLendingPoolHandler extends BaseLendingPoolHandler {
|
|
|
64
63
|
defaultUnstake: '0',
|
|
65
64
|
fastUnstake: '0'
|
|
66
65
|
},
|
|
67
|
-
totalApr: 1.29,
|
|
68
66
|
tvl: '291890000000000'
|
|
69
67
|
}
|
|
70
68
|
};
|
|
@@ -39,7 +39,7 @@ export default class ParallelLiquidStakingPoolHandler extends BaseLiquidStakingP
|
|
|
39
39
|
|
|
40
40
|
async getPoolStat() {
|
|
41
41
|
const substrateApi = await this.substrateApi.isReady;
|
|
42
|
-
const [_exchangeRate,
|
|
42
|
+
const [_exchangeRate, _stakingLedgers] = await Promise.all([substrateApi.api.query.liquidStaking.exchangeRate(), substrateApi.api.query.liquidStaking.stakingLedgers.entries()]);
|
|
43
43
|
let tvl = BN_ZERO;
|
|
44
44
|
for (const _stakingLedger of _stakingLedgers) {
|
|
45
45
|
const _ledger = _stakingLedger[1];
|
|
@@ -47,16 +47,7 @@ export default class ParallelLiquidStakingPoolHandler extends BaseLiquidStakingP
|
|
|
47
47
|
tvl = tvl.add(new BN(ledger.total.toString()));
|
|
48
48
|
}
|
|
49
49
|
const exchangeRate = _exchangeRate.toPrimitive();
|
|
50
|
-
const currentBlockHeader = _currentBlockHeader.toPrimitive();
|
|
51
|
-
const currentTimestamp = _currentTimestamp.toPrimitive();
|
|
52
|
-
const beginBlock = currentBlockHeader.number - 24 * 60 * 60 / 6 * 14;
|
|
53
|
-
const _beginBlockHash = await substrateApi.api.rpc.chain.getBlockHash(beginBlock);
|
|
54
|
-
const beginBlockHash = _beginBlockHash.toString();
|
|
55
|
-
const [_beginTimestamp, _beginExchangeRate] = await Promise.all([substrateApi.api.query.timestamp.now.at(beginBlockHash), substrateApi.api.query.liquidStaking.exchangeRate.at(beginBlockHash)]);
|
|
56
|
-
const beginTimestamp = _beginTimestamp.toPrimitive();
|
|
57
|
-
const beginExchangeRate = _beginExchangeRate.toPrimitive();
|
|
58
50
|
const decimals = 10 ** this.rateDecimals;
|
|
59
|
-
const apy = (exchangeRate / beginExchangeRate) ** (365 * 24 * 60 * 60000 / (currentTimestamp - beginTimestamp)) - 1;
|
|
60
51
|
const minStake = substrateApi.api.consts.liquidStaking.minStake.toString();
|
|
61
52
|
const minUnstake = substrateApi.api.consts.liquidStaking.minUnstake.toString();
|
|
62
53
|
this.updateExchangeRate(exchangeRate);
|
|
@@ -70,7 +61,6 @@ export default class ParallelLiquidStakingPoolHandler extends BaseLiquidStakingP
|
|
|
70
61
|
statistic: {
|
|
71
62
|
assetEarning: [{
|
|
72
63
|
slug: this.rewardAssets[0],
|
|
73
|
-
apy: apy * 100,
|
|
74
64
|
exchangeRate: exchangeRate / decimals
|
|
75
65
|
}],
|
|
76
66
|
unstakingPeriod: 24 * 28,
|
|
@@ -81,7 +71,6 @@ export default class ParallelLiquidStakingPoolHandler extends BaseLiquidStakingP
|
|
|
81
71
|
defaultUnstake: minUnstake,
|
|
82
72
|
fastUnstake: '0'
|
|
83
73
|
},
|
|
84
|
-
totalApy: apy * 100,
|
|
85
74
|
tvl: tvl.toString()
|
|
86
75
|
}
|
|
87
76
|
};
|
|
@@ -7,8 +7,8 @@ export default class MigrateTransactionHistoryBySymbol extends BaseMigrationJob
|
|
|
7
7
|
const state = this.state;
|
|
8
8
|
try {
|
|
9
9
|
const changeSlugsMap = {
|
|
10
|
-
'
|
|
11
|
-
'
|
|
10
|
+
'polygon-NATIVE-MATIC': 'polygon-NATIVE-POL',
|
|
11
|
+
'5irechain_mainnet-NATIVE-5IRE': '5irechain_mainnet-NATIVE-5ire'
|
|
12
12
|
};
|
|
13
13
|
const allTxs = [];
|
|
14
14
|
await Promise.all(Object.entries(changeSlugsMap).map(async ([oldSlug, newSlug], i) => {
|
|
@@ -6,8 +6,8 @@ export default class MigrateAssetSetting extends BaseMigrationJob {
|
|
|
6
6
|
async run() {
|
|
7
7
|
try {
|
|
8
8
|
const changeSlugsMap = {
|
|
9
|
-
'
|
|
10
|
-
'
|
|
9
|
+
'polygon-NATIVE-MATIC': 'polygon-NATIVE-POL',
|
|
10
|
+
'5irechain_mainnet-NATIVE-5IRE': '5irechain_mainnet-NATIVE-5ire'
|
|
11
11
|
};
|
|
12
12
|
const assetSetting = await this.state.chainService.getAssetSettings();
|
|
13
13
|
const migratedAssetSetting = {};
|
|
@@ -53,8 +53,8 @@ export default {
|
|
|
53
53
|
'1.1.33-01': MigrateLedgerAccountV2,
|
|
54
54
|
'1.1.41-01': DeleteChainStaking,
|
|
55
55
|
'1.1.46-01': AutoEnableSomeTokens,
|
|
56
|
-
'1.
|
|
57
|
-
'1.
|
|
56
|
+
'1.2.28-01': MigrateAssetSetting,
|
|
57
|
+
'1.2.28-02': MigrateTransactionHistoryBySymbol,
|
|
58
58
|
'1.2.69-01': MigrateRemoveGenesisHash,
|
|
59
59
|
'1.2.13-01': ReloadMetadata,
|
|
60
60
|
'1.2.14-01': ClearMetadataDatabase
|
|
@@ -6,6 +6,7 @@ import { ChainService } from '@subwallet/extension-base/services/chain-service';
|
|
|
6
6
|
import { SwapBaseInterface } from '@subwallet/extension-base/services/swap-service/handler/base-handler';
|
|
7
7
|
import { BaseStepDetail, CommonOptimalPath, CommonStepFeeInfo } from '@subwallet/extension-base/types/service-base';
|
|
8
8
|
import { OptimalSwapPathParams, SwapEarlyValidation, SwapProviderId, SwapQuote, SwapRequest, SwapSubmitParams, SwapSubmitStepData, ValidateSwapProcessParams } from '@subwallet/extension-base/types/swap';
|
|
9
|
+
export declare const CHAINFLIP_BROKER_API: string;
|
|
9
10
|
export declare class ChainflipSwapHandler implements SwapBaseInterface {
|
|
10
11
|
private swapSdk;
|
|
11
12
|
private readonly isTestnet;
|
|
@@ -17,8 +18,8 @@ export declare class ChainflipSwapHandler implements SwapBaseInterface {
|
|
|
17
18
|
get providerInfo(): import("@subwallet/extension-base/types/swap").SwapProvider;
|
|
18
19
|
get name(): string;
|
|
19
20
|
get slug(): string;
|
|
20
|
-
get assetMapping(): Record<string, import("@chainflip/sdk/dist/contracts-
|
|
21
|
-
get chainMapping(): Record<string, import("@chainflip/sdk/dist/contracts-
|
|
21
|
+
get assetMapping(): Record<string, import("@chainflip/sdk/dist/contracts-Cb-5VdIi").a>;
|
|
22
|
+
get chainMapping(): Record<string, import("@chainflip/sdk/dist/contracts-Cb-5VdIi").C>;
|
|
22
23
|
get intermediaryAssetSlug(): COMMON_ASSETS.USDC_ETHEREUM | COMMON_ASSETS.USDC_SEPOLIA;
|
|
23
24
|
validateSwapRequest(request: SwapRequest): Promise<SwapEarlyValidation>;
|
|
24
25
|
private parseSwapPath;
|
|
@@ -11,7 +11,7 @@ import { getERC20TransactionObject, getEVMTransactionObject } from '@subwallet/e
|
|
|
11
11
|
import { createTransferExtrinsic } from '@subwallet/extension-base/services/balance-service/transfer/token';
|
|
12
12
|
import { _getAssetDecimals, _getChainNativeTokenSlug, _getContractAddressOfToken, _isNativeToken, _isSubstrateChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
13
13
|
import { SwapBaseHandler } from '@subwallet/extension-base/services/swap-service/handler/base-handler';
|
|
14
|
-
import { calculateSwapRate, CHAIN_FLIP_SUPPORTED_MAINNET_ASSET_MAPPING, CHAIN_FLIP_SUPPORTED_MAINNET_MAPPING, CHAIN_FLIP_SUPPORTED_TESTNET_ASSET_MAPPING, CHAIN_FLIP_SUPPORTED_TESTNET_MAPPING, SWAP_QUOTE_TIMEOUT_MAP } from '@subwallet/extension-base/services/swap-service/utils';
|
|
14
|
+
import { calculateSwapRate, CHAIN_FLIP_SUPPORTED_MAINNET_ASSET_MAPPING, CHAIN_FLIP_SUPPORTED_MAINNET_MAPPING, CHAIN_FLIP_SUPPORTED_TESTNET_ASSET_MAPPING, CHAIN_FLIP_SUPPORTED_TESTNET_MAPPING, getChainflipOptions, SWAP_QUOTE_TIMEOUT_MAP } from '@subwallet/extension-base/services/swap-service/utils';
|
|
15
15
|
import { CommonStepType } from '@subwallet/extension-base/types/service-base';
|
|
16
16
|
import { SwapErrorType, SwapFeeType, SwapProviderId, SwapStepType } from '@subwallet/extension-base/types/swap';
|
|
17
17
|
import BigNumber from 'bignumber.js';
|
|
@@ -20,10 +20,12 @@ var ChainflipFeeType;
|
|
|
20
20
|
ChainflipFeeType["INGRESS"] = "INGRESS";
|
|
21
21
|
ChainflipFeeType["NETWORK"] = "NETWORK";
|
|
22
22
|
ChainflipFeeType["EGRESS"] = "EGRESS";
|
|
23
|
-
ChainflipFeeType["
|
|
23
|
+
ChainflipFeeType["BOOST"] = "BOOST";
|
|
24
|
+
ChainflipFeeType["BROKER"] = "BROKER";
|
|
24
25
|
})(ChainflipFeeType || (ChainflipFeeType = {}));
|
|
25
26
|
const INTERMEDIARY_MAINNET_ASSET_SLUG = COMMON_ASSETS.USDC_ETHEREUM;
|
|
26
27
|
const INTERMEDIARY_TESTNET_ASSET_SLUG = COMMON_ASSETS.USDC_SEPOLIA;
|
|
28
|
+
export const CHAINFLIP_BROKER_API = process.env.CHAINFLIP_BROKER_API || '';
|
|
27
29
|
var CHAINFLIP_QUOTE_ERROR;
|
|
28
30
|
(function (CHAINFLIP_QUOTE_ERROR) {
|
|
29
31
|
CHAINFLIP_QUOTE_ERROR["InsufficientLiquidity"] = "InsufficientLiquidity";
|
|
@@ -40,9 +42,9 @@ export class ChainflipSwapHandler {
|
|
|
40
42
|
});
|
|
41
43
|
this.isTestnet = isTestnet;
|
|
42
44
|
this.providerSlug = isTestnet ? SwapProviderId.CHAIN_FLIP_TESTNET : SwapProviderId.CHAIN_FLIP_MAINNET;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
|
|
46
|
+
// @ts-ignore
|
|
47
|
+
this.swapSdk = new SwapSDK(getChainflipOptions(isTestnet));
|
|
46
48
|
}
|
|
47
49
|
get chainService() {
|
|
48
50
|
return this.swapBaseHandler.chainService;
|
|
@@ -228,7 +230,10 @@ export class ChainflipSwapHandler {
|
|
|
228
230
|
case ChainflipFeeType.NETWORK:
|
|
229
231
|
|
|
230
232
|
// eslint-disable-next-line no-fallthrough
|
|
231
|
-
case ChainflipFeeType.
|
|
233
|
+
case ChainflipFeeType.BOOST:
|
|
234
|
+
|
|
235
|
+
// eslint-disable-next-line no-fallthrough
|
|
236
|
+
case ChainflipFeeType.BROKER:
|
|
232
237
|
{
|
|
233
238
|
const tokenSlug = Object.keys(this.assetMapping).find(assetSlug => this.assetMapping[assetSlug] === fee.asset);
|
|
234
239
|
feeComponent.push({
|
|
@@ -248,7 +248,7 @@ export class HydradxHandler {
|
|
|
248
248
|
|
|
249
249
|
switch (defaultError) {
|
|
250
250
|
case PoolError.InsufficientTradingAmount:
|
|
251
|
-
return new SwapError(SwapErrorType.
|
|
251
|
+
return new SwapError(SwapErrorType.NOT_MEET_MIN_SWAP);
|
|
252
252
|
case PoolError.TradeNotAllowed:
|
|
253
253
|
return new SwapError(SwapErrorType.ERROR_FETCHING_QUOTE);
|
|
254
254
|
case PoolError.MaxInRatioExceeded:
|
|
@@ -13,3 +13,15 @@ export declare function getSwapAlternativeAsset(swapPair: SwapPair): string | un
|
|
|
13
13
|
export declare function getSwapAltToken(chainAsset: _ChainAsset): string | undefined;
|
|
14
14
|
export declare function calculateSwapRate(fromAmount: string, toAmount: string, fromAsset: _ChainAsset, toAsset: _ChainAsset): number;
|
|
15
15
|
export declare function convertSwapRate(rate: string, fromAsset: _ChainAsset, toAsset: _ChainAsset): number;
|
|
16
|
+
export declare function getChainflipOptions(isTestnet: boolean): {
|
|
17
|
+
network: string;
|
|
18
|
+
broker?: undefined;
|
|
19
|
+
} | {
|
|
20
|
+
network: string;
|
|
21
|
+
broker: {
|
|
22
|
+
url: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export declare function getChainflipBroker(isTestnet: boolean): {
|
|
26
|
+
url: string;
|
|
27
|
+
};
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { Assets, Chains } from '@chainflip/sdk/swap';
|
|
5
5
|
import { COMMON_ASSETS, COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
|
|
6
6
|
import { _getAssetDecimals } from '@subwallet/extension-base/services/chain-service/utils';
|
|
7
|
+
import { CHAINFLIP_BROKER_API } from '@subwallet/extension-base/services/swap-service/handler/chainflip-handler';
|
|
7
8
|
import { SwapProviderId } from '@subwallet/extension-base/types/swap';
|
|
8
9
|
import BigN from 'bignumber.js';
|
|
9
10
|
export const CHAIN_FLIP_TESTNET_EXPLORER = 'https://blocks-perseverance.chainflip.io';
|
|
@@ -60,4 +61,30 @@ export function convertSwapRate(rate, fromAsset, toAsset) {
|
|
|
60
61
|
const decimalDiff = _getAssetDecimals(toAsset) - _getAssetDecimals(fromAsset);
|
|
61
62
|
const bnRate = new BigN(rate);
|
|
62
63
|
return bnRate.times(10 ** decimalDiff).pow(-1).toNumber();
|
|
64
|
+
}
|
|
65
|
+
export function getChainflipOptions(isTestnet) {
|
|
66
|
+
if (isTestnet) {
|
|
67
|
+
return {
|
|
68
|
+
network: getChainflipNetwork(isTestnet)
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
network: getChainflipNetwork(isTestnet),
|
|
73
|
+
broker: getChainflipBroker(isTestnet)
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function getChainflipNetwork(isTestnet) {
|
|
77
|
+
return isTestnet ? 'perseverance' : 'mainnet';
|
|
78
|
+
}
|
|
79
|
+
export function getChainflipBroker(isTestnet) {
|
|
80
|
+
// noted: currently not use testnet broker
|
|
81
|
+
if (isTestnet) {
|
|
82
|
+
return {
|
|
83
|
+
url: `https://perseverance.chainflip-broker.io/rpc/${CHAINFLIP_BROKER_API}`
|
|
84
|
+
};
|
|
85
|
+
} else {
|
|
86
|
+
return {
|
|
87
|
+
url: `https://chainflip-broker.io/rpc/${CHAINFLIP_BROKER_API}`
|
|
88
|
+
};
|
|
89
|
+
}
|
|
63
90
|
}
|