@subwallet/extension-base 1.2.8-1 → 1.2.10-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 +7 -3
- package/background/KoniTypes.js +1 -1
- package/cjs/background/KoniTypes.js +1 -1
- package/cjs/core/logic-validation/transfer.js +22 -2
- package/cjs/core/substrate/foreign-asset-pallet.js +16 -0
- package/cjs/core/substrate/xcm-parser.js +26 -4
- package/cjs/koni/api/contract-handler/evm/web3.js +58 -0
- package/cjs/{services/chain-service/helper → koni/api/contract-handler/utils}/index.js +19 -2
- package/cjs/koni/api/contract-handler/wasm/index.js +49 -0
- package/cjs/koni/api/nft/evm_nft/index.js +6 -6
- package/cjs/koni/api/nft/wasm_nft/index.js +16 -16
- package/cjs/koni/api/yield/helper/utils.js +1 -22
- package/cjs/koni/background/handlers/Extension.js +128 -64
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/index.js +11 -0
- package/cjs/services/balance-service/helpers/process.js +50 -0
- package/cjs/services/balance-service/helpers/subscribe/evm.js +11 -3
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +10 -24
- package/cjs/services/balance-service/index.js +20 -0
- package/cjs/{koni/api/tokens/evm/transfer.js → services/balance-service/transfer/smart-contract.js} +33 -38
- package/cjs/{koni/api/dotsama/transfer.js → services/balance-service/transfer/token.js} +3 -3
- package/cjs/{koni/api → services/balance-service/transfer}/xcm/index.js +26 -6
- package/cjs/{koni/api → services/balance-service/transfer}/xcm/polkadotXcm.js +2 -2
- package/cjs/services/balance-service/transfer/xcm/snowBridge.js +60 -0
- package/cjs/{koni/api → services/balance-service/transfer}/xcm/xTokens.js +1 -1
- package/cjs/{koni/api → services/balance-service/transfer}/xcm/xcmPallet.js +1 -1
- package/cjs/services/chain-service/handler/EvmChainHandler.js +3 -3
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +4 -4
- package/cjs/services/chain-service/health-check/utils/asset-info.js +18 -18
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +16 -35
- package/cjs/services/earning-service/handlers/special.js +1 -1
- package/cjs/services/history-service/subscan-history.js +1 -1
- package/cjs/services/swap-service/handler/base-handler.js +3 -2
- package/cjs/services/swap-service/handler/chainflip-handler.js +10 -9
- package/cjs/services/swap-service/handler/hydradx-handler.js +12 -11
- package/cjs/services/swap-service/index.js +3 -2
- package/cjs/services/swap-service/utils.js +1 -13
- package/cjs/services/transaction-service/index.js +2 -2
- package/cjs/types/service-base.js +30 -1
- package/cjs/types/swap/index.js +0 -4
- package/cjs/utils/eth/parseTransaction/index.js +10 -10
- package/core/logic-validation/transfer.d.ts +1 -1
- package/core/logic-validation/transfer.js +22 -3
- package/core/substrate/foreign-asset-pallet.d.ts +8 -0
- package/core/substrate/foreign-asset-pallet.js +9 -0
- package/core/substrate/xcm-parser.d.ts +3 -1
- package/core/substrate/xcm-parser.js +25 -5
- package/koni/api/contract-handler/evm/web3.d.ts +8 -0
- package/koni/api/contract-handler/evm/web3.js +45 -0
- package/{services/chain-service/helper → koni/api/contract-handler/utils}/index.d.ts +4 -0
- package/{services/chain-service/helper → koni/api/contract-handler/utils}/index.js +15 -1
- package/koni/api/contract-handler/utils/snowbridge_gateway_abi.json +1122 -0
- package/koni/api/{tokens → contract-handler}/wasm/index.d.ts +0 -2
- package/koni/api/{tokens → contract-handler}/wasm/index.js +1 -25
- package/koni/api/nft/evm_nft/index.js +1 -1
- package/koni/api/nft/wasm_nft/index.js +2 -2
- package/koni/api/yield/helper/utils.d.ts +1 -5
- package/koni/api/yield/helper/utils.js +0 -16
- package/koni/background/handlers/Extension.d.ts +2 -0
- package/koni/background/handlers/Extension.js +82 -18
- package/package.json +85 -79
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/index.d.ts +1 -0
- package/services/balance-service/helpers/index.js +2 -1
- package/services/balance-service/helpers/process.d.ts +13 -0
- package/services/balance-service/helpers/process.js +43 -0
- package/services/balance-service/helpers/subscribe/evm.js +11 -3
- package/services/balance-service/helpers/subscribe/substrate/index.js +11 -25
- package/services/balance-service/index.d.ts +3 -0
- package/services/balance-service/index.js +21 -1
- package/services/balance-service/transfer/smart-contract.d.ts +7 -0
- package/{koni/api/tokens/evm/transfer.js → services/balance-service/transfer/smart-contract.js} +28 -31
- package/{koni/api/dotsama/transfer.js → services/balance-service/transfer/token.js} +4 -4
- package/{koni/api → services/balance-service/transfer}/xcm/index.d.ts +9 -3
- package/{koni/api → services/balance-service/transfer}/xcm/index.js +21 -3
- package/{koni/api → services/balance-service/transfer}/xcm/polkadotXcm.js +3 -3
- package/services/balance-service/transfer/xcm/snowBridge.d.ts +4 -0
- package/services/balance-service/transfer/xcm/snowBridge.js +54 -0
- package/{koni/api → services/balance-service/transfer}/xcm/xTokens.js +1 -1
- package/{koni/api → services/balance-service/transfer}/xcm/xcmPallet.js +1 -1
- package/services/chain-service/handler/EvmChainHandler.js +1 -1
- package/services/chain-service/handler/SubstrateChainHandler.js +2 -2
- package/services/chain-service/health-check/utils/asset-info.js +3 -3
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +16 -35
- package/services/earning-service/handlers/special.js +1 -1
- package/services/history-service/subscan-history.js +1 -1
- package/services/swap-service/handler/base-handler.d.ts +5 -5
- package/services/swap-service/handler/base-handler.js +4 -3
- package/services/swap-service/handler/chainflip-handler.d.ts +4 -4
- package/services/swap-service/handler/chainflip-handler.js +7 -6
- package/services/swap-service/handler/hydradx-handler.d.ts +6 -6
- package/services/swap-service/handler/hydradx-handler.js +12 -11
- package/services/swap-service/index.d.ts +3 -2
- package/services/swap-service/index.js +4 -3
- package/services/swap-service/utils.d.ts +1 -3
- package/services/swap-service/utils.js +1 -11
- package/services/transaction-service/index.js +2 -2
- package/types/service-base.d.ts +31 -3
- package/types/service-base.js +23 -1
- package/types/swap/index.d.ts +8 -30
- package/types/swap/index.js +0 -4
- package/types/yield/actions/join/submit.d.ts +7 -4
- package/utils/eth/parseTransaction/index.js +1 -1
- package/cjs/koni/api/tokens/evm/balance.js +0 -18
- package/cjs/koni/api/tokens/evm/web3.js +0 -17
- package/cjs/koni/api/tokens/index.js +0 -17
- package/cjs/koni/api/tokens/wasm/index.js +0 -74
- package/koni/api/tokens/evm/balance.d.ts +0 -2
- package/koni/api/tokens/evm/balance.js +0 -12
- package/koni/api/tokens/evm/transfer.d.ts +0 -17
- package/koni/api/tokens/evm/web3.d.ts +0 -3
- package/koni/api/tokens/evm/web3.js +0 -9
- package/koni/api/tokens/index.d.ts +0 -1
- package/koni/api/tokens/index.js +0 -11
- /package/cjs/koni/api/{tokens → contract-handler}/wasm/utils.js +0 -0
- /package/cjs/{koni/api → services/balance-service/transfer}/xcm/utils.js +0 -0
- /package/{services/chain-service/helper → koni/api/contract-handler/utils}/azero_domain_registry_abi.json +0 -0
- /package/{services/chain-service/helper → koni/api/contract-handler/utils}/erc20_abi.json +0 -0
- /package/{services/chain-service/helper → koni/api/contract-handler/utils}/erc721_abi.json +0 -0
- /package/{services/chain-service/helper → koni/api/contract-handler/utils}/neuroguns_psp34_abi.json +0 -0
- /package/{services/chain-service/helper → koni/api/contract-handler/utils}/pink_psp34_abi.json +0 -0
- /package/{services/chain-service/helper → koni/api/contract-handler/utils}/psp22_abi.json +0 -0
- /package/{services/chain-service/helper → koni/api/contract-handler/utils}/psp34_abi.json +0 -0
- /package/{services/chain-service/helper → koni/api/contract-handler/utils}/test_erc721_abi.json +0 -0
- /package/koni/api/{tokens → contract-handler}/wasm/utils.d.ts +0 -0
- /package/koni/api/{tokens → contract-handler}/wasm/utils.js +0 -0
- /package/{koni/api/dotsama/transfer.d.ts → services/balance-service/transfer/token.d.ts} +0 -0
- /package/{koni/api → services/balance-service/transfer}/xcm/polkadotXcm.d.ts +0 -0
- /package/{koni/api → services/balance-service/transfer}/xcm/utils.d.ts +0 -0
- /package/{koni/api → services/balance-service/transfer}/xcm/utils.js +0 -0
- /package/{koni/api → services/balance-service/transfer}/xcm/xTokens.d.ts +0 -0
- /package/{koni/api → services/balance-service/transfer}/xcm/xcmPallet.d.ts +0 -0
|
@@ -4,8 +4,7 @@
|
|
|
4
4
|
import { _AssetType } from '@subwallet/chain-list/types';
|
|
5
5
|
import { APIItemState } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
6
|
import { ASTAR_REFRESH_BALANCE_INTERVAL, SUB_TOKEN_REFRESH_BALANCE_INTERVAL } from '@subwallet/extension-base/constants';
|
|
7
|
-
import {
|
|
8
|
-
import { getERC20Contract } from '@subwallet/extension-base/koni/api/tokens/evm/web3';
|
|
7
|
+
import { getERC20Contract } from '@subwallet/extension-base/koni/api/contract-handler/evm/web3';
|
|
9
8
|
import { _getContractAddressOfToken } from '@subwallet/extension-base/services/chain-service/utils';
|
|
10
9
|
import { filterAssetsByChainAndType } from '@subwallet/extension-base/utils';
|
|
11
10
|
import { BN } from '@polkadot/util';
|
|
@@ -56,6 +55,15 @@ export function subscribeERC20Interval({
|
|
|
56
55
|
clearInterval(interval);
|
|
57
56
|
};
|
|
58
57
|
}
|
|
58
|
+
async function getEVMBalance(addresses, web3Api) {
|
|
59
|
+
return await Promise.all(addresses.map(async address => {
|
|
60
|
+
try {
|
|
61
|
+
return await web3Api.api.eth.getBalance(address);
|
|
62
|
+
} catch (e) {
|
|
63
|
+
return '0';
|
|
64
|
+
}
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
59
67
|
export function subscribeEVMBalance(params) {
|
|
60
68
|
var _Object$values$;
|
|
61
69
|
const {
|
|
@@ -69,7 +77,7 @@ export function subscribeEVMBalance(params) {
|
|
|
69
77
|
const nativeTokenInfo = filterAssetsByChainAndType(assetMap, chain, [_AssetType.NATIVE]);
|
|
70
78
|
const nativeTokenSlug = ((_Object$values$ = Object.values(nativeTokenInfo)[0]) === null || _Object$values$ === void 0 ? void 0 : _Object$values$.slug) || '';
|
|
71
79
|
function getBalance() {
|
|
72
|
-
getEVMBalance(
|
|
80
|
+
getEVMBalance(addresses, evmApi).then(balances => {
|
|
73
81
|
return balances.map((balance, index) => {
|
|
74
82
|
return {
|
|
75
83
|
address: addresses[index],
|
|
@@ -5,12 +5,13 @@ import { GearApi } from '@gear-js/api';
|
|
|
5
5
|
import { _AssetType } from '@subwallet/chain-list/types';
|
|
6
6
|
import { APIItemState } from '@subwallet/extension-base/background/KoniTypes';
|
|
7
7
|
import { SUB_TOKEN_REFRESH_BALANCE_INTERVAL } from '@subwallet/extension-base/constants';
|
|
8
|
+
import { _getForeignAssetPalletLockedBalance, _getForeignAssetPalletTransferable } from '@subwallet/extension-base/core/substrate/foreign-asset-pallet';
|
|
8
9
|
import { _getTotalStakeInNominationPool } from '@subwallet/extension-base/core/substrate/nominationpools-pallet';
|
|
9
10
|
import { _getSystemPalletTotalBalance, _getSystemPalletTransferable } from '@subwallet/extension-base/core/substrate/system-pallet';
|
|
10
|
-
import { getPSP22ContractPromise } from '@subwallet/extension-base/koni/api/
|
|
11
|
-
import { getDefaultWeightV2 } from '@subwallet/extension-base/koni/api/
|
|
11
|
+
import { getPSP22ContractPromise } from '@subwallet/extension-base/koni/api/contract-handler/wasm';
|
|
12
|
+
import { getDefaultWeightV2 } from '@subwallet/extension-base/koni/api/contract-handler/wasm/utils';
|
|
12
13
|
import { _BALANCE_CHAIN_GROUP, _MANTA_ZK_CHAIN_GROUP, _ZK_ASSET_PREFIX } from '@subwallet/extension-base/services/chain-service/constants';
|
|
13
|
-
import { _checkSmartContractSupportByChain, _getChainExistentialDeposit, _getChainNativeTokenSlug, _getContractAddressOfToken, _getTokenOnChainAssetId, _getTokenOnChainInfo, _getTokenTypesSupportedByChain, _isBridgedToken, _isChainEvmCompatible, _isSubstrateRelayChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
14
|
+
import { _checkSmartContractSupportByChain, _getChainExistentialDeposit, _getChainNativeTokenSlug, _getContractAddressOfToken, _getTokenOnChainAssetId, _getTokenOnChainInfo, _getTokenTypesSupportedByChain, _getXcmAssetMultilocation, _isBridgedToken, _isChainEvmCompatible, _isSubstrateRelayChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
14
15
|
import { filterAssetsByChainAndType, getGRC20ContractPromise } from '@subwallet/extension-base/utils';
|
|
15
16
|
import BigN from 'bignumber.js';
|
|
16
17
|
import { combineLatest, Observable } from 'rxjs';
|
|
@@ -59,7 +60,7 @@ export const subscribeSubstrateBalance = async (addresses, chainInfo, assetMap,
|
|
|
59
60
|
unsubLocalToken = await subscribeOrmlTokensPallet(substrateParams);
|
|
60
61
|
}
|
|
61
62
|
if (_BALANCE_CHAIN_GROUP.supportBridged.includes(chain)) {
|
|
62
|
-
unsubBridgedToken = await
|
|
63
|
+
unsubBridgedToken = await subscribeForeignAssetBalance(substrateParams);
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
/**
|
|
@@ -150,7 +151,7 @@ const subscribeWithSystemAccountPallet = async ({
|
|
|
150
151
|
subscription.unsubscribe();
|
|
151
152
|
};
|
|
152
153
|
};
|
|
153
|
-
const
|
|
154
|
+
const subscribeForeignAssetBalance = async ({
|
|
154
155
|
addresses,
|
|
155
156
|
assetMap,
|
|
156
157
|
callback,
|
|
@@ -165,30 +166,15 @@ const subscribeBridgedBalance = async ({
|
|
|
165
166
|
try {
|
|
166
167
|
const isBridgedToken = _isBridgedToken(tokenInfo);
|
|
167
168
|
if (isBridgedToken) {
|
|
168
|
-
const
|
|
169
|
-
return await substrateApi.query.foreignAssets.account.multi(addresses.map(address => [
|
|
169
|
+
const assetLocation = _getTokenOnChainInfo(tokenInfo) || _getXcmAssetMultilocation(tokenInfo);
|
|
170
|
+
return await substrateApi.query.foreignAssets.account.multi(addresses.map(address => [assetLocation, address]), balances => {
|
|
170
171
|
const items = balances.map((balance, index) => {
|
|
171
|
-
const
|
|
172
|
-
let frozen = BN_ZERO;
|
|
173
|
-
let total = BN_ZERO;
|
|
174
|
-
if (bdata) {
|
|
175
|
-
// @ts-ignore
|
|
176
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-argument
|
|
177
|
-
const addressBalance = new BN(String(bdata === null || bdata === void 0 ? void 0 : bdata.balance).replaceAll(',', '') || '0');
|
|
178
|
-
|
|
179
|
-
// @ts-ignore
|
|
180
|
-
if (bdata !== null && bdata !== void 0 && bdata.isFrozen) {
|
|
181
|
-
frozen = addressBalance;
|
|
182
|
-
} else {
|
|
183
|
-
total = addressBalance;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
const free = total.sub(frozen);
|
|
172
|
+
const accountInfo = balance === null || balance === void 0 ? void 0 : balance.toPrimitive();
|
|
187
173
|
return {
|
|
188
174
|
address: addresses[index],
|
|
189
175
|
tokenSlug: tokenInfo.slug,
|
|
190
|
-
free:
|
|
191
|
-
locked:
|
|
176
|
+
free: accountInfo ? _getForeignAssetPalletTransferable(accountInfo).toString() : '0',
|
|
177
|
+
locked: accountInfo ? _getForeignAssetPalletLockedBalance(accountInfo).toString() : '0',
|
|
192
178
|
state: APIItemState.READY
|
|
193
179
|
};
|
|
194
180
|
});
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { AmountData, DetectBalanceCache, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
2
|
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
|
|
3
|
+
import { RequestOptimalTransferProcess } from '@subwallet/extension-base/services/balance-service/helpers/process';
|
|
3
4
|
import { ServiceStatus, StoppableServiceInterface } from '@subwallet/extension-base/services/base/types';
|
|
4
5
|
import { EventItem, EventType } from '@subwallet/extension-base/services/event-service/types';
|
|
5
6
|
import { BalanceItem, BalanceJson } from '@subwallet/extension-base/types';
|
|
7
|
+
import { CommonOptimalPath } from '@subwallet/extension-base/types/service-base';
|
|
6
8
|
import { PromiseHandler } from '@subwallet/extension-base/utils';
|
|
7
9
|
import { BehaviorSubject } from 'rxjs';
|
|
8
10
|
/**
|
|
@@ -93,4 +95,5 @@ export declare class BalanceService implements StoppableServiceInterface {
|
|
|
93
95
|
private startBalanceDetectCache;
|
|
94
96
|
private startScanBalance;
|
|
95
97
|
private stopScanBalance;
|
|
98
|
+
getOptimalTransferProcess(params: RequestOptimalTransferProcess): Promise<CommonOptimalPath>;
|
|
96
99
|
}
|
|
@@ -4,8 +4,10 @@
|
|
|
4
4
|
import { BalanceError } from '@subwallet/extension-base/background/errors/BalanceError';
|
|
5
5
|
import { BalanceErrorType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
6
|
import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
|
|
7
|
+
import { _isXcmWithinSameConsensus } from '@subwallet/extension-base/core/substrate/xcm-parser';
|
|
8
|
+
import { getDefaultTransferProcess, getSnowbridgeTransferProcessFromEvm } from '@subwallet/extension-base/services/balance-service/helpers/process';
|
|
7
9
|
import { ServiceStatus } from '@subwallet/extension-base/services/base/types';
|
|
8
|
-
import { _getChainNativeTokenSlug } from '@subwallet/extension-base/services/chain-service/utils';
|
|
10
|
+
import { _getChainNativeTokenSlug, _isPureEvmChain } from '@subwallet/extension-base/services/chain-service/utils';
|
|
9
11
|
import DetectAccountBalanceStore from '@subwallet/extension-base/stores/DetectAccountBalance';
|
|
10
12
|
import { addLazy, createPromiseHandler, isAccountAll, waitTimeout } from '@subwallet/extension-base/utils';
|
|
11
13
|
import keyring from '@subwallet/ui-keyring';
|
|
@@ -464,4 +466,22 @@ export class BalanceService {
|
|
|
464
466
|
this._unsubscribeBalanceDetectCache = undefined;
|
|
465
467
|
this.startBalanceDetectCache = undefined;
|
|
466
468
|
}
|
|
469
|
+
|
|
470
|
+
// process
|
|
471
|
+
async getOptimalTransferProcess(params) {
|
|
472
|
+
const originChainInfo = this.state.chainService.getChainInfoByKey(params.originChain);
|
|
473
|
+
if (!params.destChain) {
|
|
474
|
+
// normal transfers
|
|
475
|
+
return getDefaultTransferProcess();
|
|
476
|
+
}
|
|
477
|
+
const destChainInfo = this.state.chainService.getChainInfoByKey(params.destChain);
|
|
478
|
+
|
|
479
|
+
// xcm
|
|
480
|
+
if (!_isXcmWithinSameConsensus(originChainInfo, destChainInfo) && _isPureEvmChain(originChainInfo)) {
|
|
481
|
+
const evmApi = this.state.chainService.getEvmApi(originChainInfo.slug);
|
|
482
|
+
const tokenInfo = this.state.chainService.getAssetBySlug(params.tokenSlug);
|
|
483
|
+
return getSnowbridgeTransferProcessFromEvm(params.address, evmApi, tokenInfo, params.amount);
|
|
484
|
+
}
|
|
485
|
+
return getDefaultTransferProcess();
|
|
486
|
+
}
|
|
467
487
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
+
import { _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
3
|
+
import { TransactionConfig } from 'web3-core';
|
|
4
|
+
export declare function getEVMTransactionObject(chainInfo: _ChainInfo, from: string, to: string, value: string, transferAll: boolean, web3Api: _EvmApi): Promise<[TransactionConfig, string]>;
|
|
5
|
+
export declare function getERC20TransactionObject(assetAddress: string, chainInfo: _ChainInfo, from: string, to: string, value: string, transferAll: boolean, evmApi: _EvmApi): Promise<[TransactionConfig, string]>;
|
|
6
|
+
export declare function getERC721Transaction(web3Api: _EvmApi, chain: string, contractAddress: string, senderAddress: string, recipientAddress: string, tokenId: string): Promise<TransactionConfig>;
|
|
7
|
+
export declare function getPSP34TransferExtrinsic(substrateApi: _SubstrateApi, senderAddress: string, recipientAddress: string, params: Record<string, any>): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult> | null>;
|
package/{koni/api/tokens/evm/transfer.js → services/balance-service/transfer/smart-contract.js}
RENAMED
|
@@ -1,39 +1,13 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import { getERC20Contract } from '@subwallet/extension-base/koni/api/contract-handler/evm/web3';
|
|
5
|
+
import { _ERC721_ABI } from '@subwallet/extension-base/koni/api/contract-handler/utils';
|
|
6
|
+
import { getPSP34ContractPromise } from '@subwallet/extension-base/koni/api/contract-handler/wasm';
|
|
7
|
+
import { getWasmContractGasLimit } from '@subwallet/extension-base/koni/api/contract-handler/wasm/utils';
|
|
8
|
+
import { EVM_REFORMAT_DECIMALS } from '@subwallet/extension-base/services/chain-service/constants';
|
|
8
9
|
import { calculateGasFeeParams } from '@subwallet/extension-base/services/fee-service/utils';
|
|
9
10
|
import BigN from 'bignumber.js';
|
|
10
|
-
import { hexToBn } from '@polkadot/util';
|
|
11
|
-
export const handleTransferBalanceResult = ({
|
|
12
|
-
callback,
|
|
13
|
-
changeValue,
|
|
14
|
-
networkKey,
|
|
15
|
-
receipt,
|
|
16
|
-
response,
|
|
17
|
-
updateState
|
|
18
|
-
}) => {
|
|
19
|
-
response.status = true;
|
|
20
|
-
let fee;
|
|
21
|
-
if (_BALANCE_PARSING_CHAIN_GROUP.bobabeam.indexOf(networkKey) > -1) {
|
|
22
|
-
// @ts-ignore
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
24
|
-
fee = hexToBn(receipt.l1Fee || '0x0').add(hexToBn(receipt.l2BobaFee || '0x0')).toString();
|
|
25
|
-
} else {
|
|
26
|
-
fee = (receipt.gasUsed * receipt.effectiveGasPrice).toString();
|
|
27
|
-
}
|
|
28
|
-
response.txResult = {
|
|
29
|
-
change: changeValue || '0',
|
|
30
|
-
fee
|
|
31
|
-
};
|
|
32
|
-
updateState && updateState({
|
|
33
|
-
status: receipt.status ? ExternalRequestPromiseStatus.COMPLETED : ExternalRequestPromiseStatus.FAILED
|
|
34
|
-
});
|
|
35
|
-
callback(response);
|
|
36
|
-
};
|
|
37
11
|
export async function getEVMTransactionObject(chainInfo, from, to, value, transferAll, web3Api) {
|
|
38
12
|
var _priority$maxFeePerGa, _priority$maxPriority;
|
|
39
13
|
const networkKey = chainInfo.slug;
|
|
@@ -120,4 +94,27 @@ export async function getERC721Transaction(web3Api, chain, contractAddress, send
|
|
|
120
94
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
121
95
|
data: contract.methods.safeTransferFrom(senderAddress, recipientAddress, tokenId).encodeABI()
|
|
122
96
|
};
|
|
97
|
+
}
|
|
98
|
+
const mustFormatNumberReg = /^-?[0-9][0-9,.]+$/;
|
|
99
|
+
export async function getPSP34TransferExtrinsic(substrateApi, senderAddress, recipientAddress, params) {
|
|
100
|
+
const contractAddress = params.contractAddress;
|
|
101
|
+
const onChainOption = params.onChainOption;
|
|
102
|
+
for (const [key, value] of Object.entries(onChainOption)) {
|
|
103
|
+
if (mustFormatNumberReg.test(value)) {
|
|
104
|
+
onChainOption[key] = value.replaceAll(',', '');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
const contractPromise = getPSP34ContractPromise(substrateApi.api, contractAddress);
|
|
109
|
+
// @ts-ignore
|
|
110
|
+
const gasLimit = await getWasmContractGasLimit(substrateApi.api, senderAddress, 'psp34::transfer', contractPromise, {}, [recipientAddress, onChainOption, {}]);
|
|
111
|
+
|
|
112
|
+
// @ts-ignore
|
|
113
|
+
return contractPromise.tx['psp34::transfer']({
|
|
114
|
+
gasLimit
|
|
115
|
+
}, recipientAddress, onChainOption, {});
|
|
116
|
+
} catch (e) {
|
|
117
|
+
console.debug(e);
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
123
120
|
}
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { GearApi } from '@gear-js/api';
|
|
5
|
-
import { getPSP22ContractPromise } from '@subwallet/extension-base/koni/api/
|
|
6
|
-
import { getWasmContractGasLimit } from '@subwallet/extension-base/koni/api/
|
|
5
|
+
import { getPSP22ContractPromise } from '@subwallet/extension-base/koni/api/contract-handler/wasm';
|
|
6
|
+
import { getWasmContractGasLimit } from '@subwallet/extension-base/koni/api/contract-handler/wasm/utils';
|
|
7
7
|
import { _TRANSFER_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
8
|
-
import { _getContractAddressOfToken, _getTokenOnChainAssetId, _getTokenOnChainInfo, _isBridgedToken, _isChainEvmCompatible, _isNativeToken, _isTokenGearSmartContract, _isTokenTransferredByEvm, _isTokenWasmSmartContract } from '@subwallet/extension-base/services/chain-service/utils';
|
|
8
|
+
import { _getContractAddressOfToken, _getTokenOnChainAssetId, _getTokenOnChainInfo, _getXcmAssetMultilocation, _isBridgedToken, _isChainEvmCompatible, _isNativeToken, _isTokenGearSmartContract, _isTokenTransferredByEvm, _isTokenWasmSmartContract } from '@subwallet/extension-base/services/chain-service/utils';
|
|
9
9
|
import { calculateGasFeeParams } from '@subwallet/extension-base/services/fee-service/utils';
|
|
10
10
|
import { getGRC20ContractPromise } from '@subwallet/extension-base/utils';
|
|
11
11
|
import BigN from 'bignumber.js';
|
|
@@ -36,7 +36,7 @@ export const createTransferExtrinsic = async ({
|
|
|
36
36
|
let transferAmount; // for PSP-22 tokens, might be deprecated in the future
|
|
37
37
|
|
|
38
38
|
if (_isBridgedToken(tokenInfo) && api.tx.foreignAssets) {
|
|
39
|
-
const onChainInfo = _getTokenOnChainInfo(tokenInfo);
|
|
39
|
+
const onChainInfo = _getTokenOnChainInfo(tokenInfo) || _getXcmAssetMultilocation(tokenInfo);
|
|
40
40
|
if (transferAll) {
|
|
41
41
|
transfer = api.tx.foreignAssets.transfer(onChainInfo, to, value);
|
|
42
42
|
} else {
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
-
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
2
|
+
import { _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
3
3
|
import BigN from 'bignumber.js';
|
|
4
|
+
import { TransactionConfig } from 'web3-core';
|
|
4
5
|
import { SubmittableExtrinsic } from '@polkadot/api/types';
|
|
5
|
-
|
|
6
|
+
declare type CreateXcmExtrinsicProps = {
|
|
6
7
|
originTokenInfo: _ChainAsset;
|
|
7
8
|
destinationTokenInfo: _ChainAsset;
|
|
8
9
|
recipient: string;
|
|
9
10
|
sendingValue: string;
|
|
10
11
|
substrateApi: _SubstrateApi;
|
|
11
12
|
chainInfoMap: Record<string, _ChainInfo>;
|
|
12
|
-
}
|
|
13
|
+
};
|
|
14
|
+
declare type CreateSnowBridgeExtrinsicProps = Omit<CreateXcmExtrinsicProps, 'substrateApi'> & {
|
|
15
|
+
evmApi: _EvmApi;
|
|
16
|
+
sender: string;
|
|
17
|
+
};
|
|
18
|
+
export declare const createSnowBridgeExtrinsic: ({ chainInfoMap, destinationTokenInfo, evmApi, originTokenInfo, recipient, sender, sendingValue }: CreateSnowBridgeExtrinsicProps) => Promise<TransactionConfig>;
|
|
13
19
|
export declare const createXcmExtrinsic: ({ chainInfoMap, destinationTokenInfo, originTokenInfo, recipient, sendingValue, substrateApi }: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'>>;
|
|
14
20
|
export declare const getXcmMockTxFee: (substrateApi: _SubstrateApi, chainInfoMap: Record<string, _ChainInfo>, address: string, originTokenInfo: _ChainAsset, destinationTokenInfo: _ChainAsset) => Promise<BigN>;
|
|
15
21
|
export {};
|
|
@@ -1,14 +1,32 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { _isSnowBridgeXcm } from '@subwallet/extension-base/core/substrate/xcm-parser';
|
|
5
|
+
import { getExtrinsicByPolkadotXcmPallet } from '@subwallet/extension-base/services/balance-service/transfer/xcm/polkadotXcm';
|
|
6
|
+
import { getSnowBridgeEvmTransfer } from '@subwallet/extension-base/services/balance-service/transfer/xcm/snowBridge';
|
|
7
|
+
import { getExtrinsicByXcmPalletPallet } from '@subwallet/extension-base/services/balance-service/transfer/xcm/xcmPallet';
|
|
8
|
+
import { getExtrinsicByXtokensPallet } from '@subwallet/extension-base/services/balance-service/transfer/xcm/xTokens';
|
|
7
9
|
import { _XCM_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
8
10
|
import { _isChainEvmCompatible, _isNativeToken } from '@subwallet/extension-base/services/chain-service/utils';
|
|
9
11
|
import BigN from 'bignumber.js';
|
|
10
12
|
import { u8aToHex } from '@polkadot/util';
|
|
11
13
|
import { addressToEvm, isEthereumAddress } from '@polkadot/util-crypto';
|
|
14
|
+
export const createSnowBridgeExtrinsic = async ({
|
|
15
|
+
chainInfoMap,
|
|
16
|
+
destinationTokenInfo,
|
|
17
|
+
evmApi,
|
|
18
|
+
originTokenInfo,
|
|
19
|
+
recipient,
|
|
20
|
+
sender,
|
|
21
|
+
sendingValue
|
|
22
|
+
}) => {
|
|
23
|
+
const originChainInfo = chainInfoMap[originTokenInfo.originChain];
|
|
24
|
+
const destinationChainInfo = chainInfoMap[destinationTokenInfo.originChain];
|
|
25
|
+
if (!_isSnowBridgeXcm(originChainInfo, destinationChainInfo)) {
|
|
26
|
+
throw new Error('This is not a valid SnowBridge transfer');
|
|
27
|
+
}
|
|
28
|
+
return getSnowBridgeEvmTransfer(originTokenInfo, originChainInfo, destinationChainInfo, sender, recipient, sendingValue, evmApi);
|
|
29
|
+
};
|
|
12
30
|
export const createXcmExtrinsic = async ({
|
|
13
31
|
chainInfoMap,
|
|
14
32
|
destinationTokenInfo,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { _getXcmBeneficiary, _getXcmDestWeight, _getXcmMultiAssets, _getXcmMultiLocation } from '@subwallet/extension-base/core/substrate/xcm-parser';
|
|
5
|
-
import { isUseTeleportProtocol, STABLE_XCM_VERSION } from '@subwallet/extension-base/
|
|
4
|
+
import { _getXcmBeneficiary, _getXcmDestWeight, _getXcmMultiAssets, _getXcmMultiLocation, _isXcmWithinSameConsensus } from '@subwallet/extension-base/core/substrate/xcm-parser';
|
|
5
|
+
import { isUseTeleportProtocol, STABLE_XCM_VERSION } from '@subwallet/extension-base/services/balance-service/transfer/xcm/utils';
|
|
6
6
|
import { _isBridgedToken } from '@subwallet/extension-base/services/chain-service/utils';
|
|
7
7
|
export function getExtrinsicByPolkadotXcmPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
8
8
|
let version = STABLE_XCM_VERSION;
|
|
9
9
|
let method = 'limitedReserveTransferAssets';
|
|
10
|
-
if (_isBridgedToken(tokenInfo)) {
|
|
10
|
+
if (_isBridgedToken(tokenInfo) && !_isXcmWithinSameConsensus(originChainInfo, destinationChainInfo)) {
|
|
11
11
|
version = 4;
|
|
12
12
|
method = 'transferAssets';
|
|
13
13
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
|
+
import { _EvmApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
3
|
+
import { TransactionConfig } from 'web3-core';
|
|
4
|
+
export declare function getSnowBridgeEvmTransfer(tokenInfo: _ChainAsset, originChainInfo: _ChainInfo, destinationChainInfo: _ChainInfo, sender: string, recipientAddress: string, value: string, evmApi: _EvmApi): Promise<TransactionConfig>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { getWeb3Contract } from '@subwallet/extension-base/koni/api/contract-handler/evm/web3';
|
|
5
|
+
import { _SNOWBRIDGE_GATEWAY_ABI, getSnowBridgeGatewayContract } from '@subwallet/extension-base/koni/api/contract-handler/utils';
|
|
6
|
+
import { _getContractAddressOfToken, _getSubstrateParaId, _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
|
|
7
|
+
import { calculateGasFeeParams } from '@subwallet/extension-base/services/fee-service/utils';
|
|
8
|
+
import { u8aToHex } from '@polkadot/util';
|
|
9
|
+
import { decodeAddress } from '@polkadot/util-crypto';
|
|
10
|
+
async function getSendFeeToken(contract, tokenContract, destChainParaId, destinationFee) {
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
12
|
+
const quoteSendTokenFee = contract.methods.quoteSendTokenFee(tokenContract, destChainParaId, destinationFee);
|
|
13
|
+
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
15
|
+
return await quoteSendTokenFee.call();
|
|
16
|
+
}
|
|
17
|
+
export async function getSnowBridgeEvmTransfer(tokenInfo, originChainInfo, destinationChainInfo, sender, recipientAddress, value, evmApi) {
|
|
18
|
+
var _priority$maxFeePerGa, _priority$maxPriority;
|
|
19
|
+
const snowBridgeContractAddress = getSnowBridgeGatewayContract(originChainInfo.slug);
|
|
20
|
+
const snowBridgeContract = getWeb3Contract(snowBridgeContractAddress, evmApi, _SNOWBRIDGE_GATEWAY_ABI);
|
|
21
|
+
const tokenContract = _getContractAddressOfToken(tokenInfo);
|
|
22
|
+
const destinationChainParaId = _getSubstrateParaId(destinationChainInfo);
|
|
23
|
+
const recipient = {
|
|
24
|
+
kind: 1,
|
|
25
|
+
data: _isChainEvmCompatible(destinationChainInfo) ? recipientAddress : u8aToHex(decodeAddress(recipientAddress))
|
|
26
|
+
};
|
|
27
|
+
const destinationFee = '0';
|
|
28
|
+
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
30
|
+
const transferCall = snowBridgeContract.methods.sendToken(tokenContract, destinationChainParaId, recipient, destinationFee, value);
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
32
|
+
const transferEncodedCall = transferCall.encodeABI();
|
|
33
|
+
const [priority, sendTokenFee] = await Promise.all([calculateGasFeeParams(evmApi, evmApi.chainSlug), getSendFeeToken(snowBridgeContract, tokenContract, destinationChainParaId, destinationFee)]);
|
|
34
|
+
let gasLimit;
|
|
35
|
+
try {
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
37
|
+
gasLimit = await transferCall.estimateGas({
|
|
38
|
+
from: sender
|
|
39
|
+
});
|
|
40
|
+
} catch (e) {
|
|
41
|
+
gasLimit = 200000; // todo: handle this better
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
from: sender,
|
|
46
|
+
to: snowBridgeContractAddress,
|
|
47
|
+
value: sendTokenFee,
|
|
48
|
+
data: transferEncodedCall,
|
|
49
|
+
gas: gasLimit,
|
|
50
|
+
gasPrice: priority.gasPrice,
|
|
51
|
+
maxFeePerGas: (_priority$maxFeePerGa = priority.maxFeePerGas) === null || _priority$maxFeePerGa === void 0 ? void 0 : _priority$maxFeePerGa.toString(),
|
|
52
|
+
maxPriorityFeePerGas: (_priority$maxPriority = priority.maxPriorityFeePerGas) === null || _priority$maxPriority === void 0 ? void 0 : _priority$maxPriority.toString()
|
|
53
|
+
};
|
|
54
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { _getXcmDestWeight, _getXcmMultiAssets, _getXcmMultiLocation } from '@subwallet/extension-base/core/substrate/xcm-parser';
|
|
5
|
-
import { STABLE_XCM_VERSION } from '@subwallet/extension-base/
|
|
5
|
+
import { STABLE_XCM_VERSION } from '@subwallet/extension-base/services/balance-service/transfer/xcm/utils';
|
|
6
6
|
import { _getTokenOnChainAssetId, _getTokenOnChainInfo, _getXcmAssetId, _getXcmAssetMultilocation, _getXcmAssetType } from '@subwallet/extension-base/services/chain-service/utils';
|
|
7
7
|
function getCurrencyId(tokenInfo) {
|
|
8
8
|
if (['moonbeam', 'moonbase', 'moonriver'].includes(tokenInfo.originChain)) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { _getXcmBeneficiary, _getXcmDestWeight, _getXcmMultiAssets, _getXcmMultiLocation } from '@subwallet/extension-base/core/substrate/xcm-parser';
|
|
5
|
-
import { isUseTeleportProtocol, STABLE_XCM_VERSION } from '@subwallet/extension-base/
|
|
5
|
+
import { isUseTeleportProtocol, STABLE_XCM_VERSION } from '@subwallet/extension-base/services/balance-service/transfer/xcm/utils';
|
|
6
6
|
// this pallet is only used by Relaychains
|
|
7
7
|
export function getExtrinsicByXcmPalletPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
|
|
8
8
|
const weightParam = _getXcmDestWeight(originChainInfo);
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { _AssetType } from '@subwallet/chain-list/types';
|
|
5
|
+
import { _ERC20_ABI, _ERC721_ABI } from '@subwallet/extension-base/koni/api/contract-handler/utils';
|
|
5
6
|
import { AbstractChainHandler } from '@subwallet/extension-base/services/chain-service/handler/AbstractChainHandler';
|
|
6
7
|
import { EvmApi } from '@subwallet/extension-base/services/chain-service/handler/EvmApi';
|
|
7
|
-
import { _ERC20_ABI, _ERC721_ABI } from '@subwallet/extension-base/services/chain-service/helper';
|
|
8
8
|
import BigN from 'bignumber.js';
|
|
9
9
|
import { logger as createLogger } from '@polkadot/util/logger';
|
|
10
10
|
export class EvmChainHandler extends AbstractChainHandler {
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
|
|
4
4
|
import { GearApi } from '@gear-js/api';
|
|
5
5
|
import { _AssetType } from '@subwallet/chain-list/types';
|
|
6
|
-
import { getDefaultWeightV2 } from '@subwallet/extension-base/koni/api/
|
|
6
|
+
import { getDefaultWeightV2 } from '@subwallet/extension-base/koni/api/contract-handler/wasm/utils';
|
|
7
7
|
import { AbstractChainHandler } from '@subwallet/extension-base/services/chain-service/handler/AbstractChainHandler';
|
|
8
8
|
import { SubstrateApi } from '@subwallet/extension-base/services/chain-service/handler/SubstrateApi';
|
|
9
9
|
import { DEFAULT_GEAR_ADDRESS, getGRC20ContractPromise } from '@subwallet/extension-base/utils';
|
|
10
10
|
import { ContractPromise } from '@polkadot/api-contract';
|
|
11
11
|
import { BN } from '@polkadot/util';
|
|
12
12
|
import { logger as createLogger } from '@polkadot/util/logger';
|
|
13
|
-
import { _PSP22_ABI, _PSP34_ABI } from "
|
|
13
|
+
import { _PSP22_ABI, _PSP34_ABI } from "../../../koni/api/contract-handler/utils/index.js";
|
|
14
14
|
export const DEFAULT_AUX = ['Aux1', 'Aux2', 'Aux3', 'Aux4', 'Aux5', 'Aux6', 'Aux7', 'Aux8', 'Aux9'];
|
|
15
15
|
export class SubstrateChainHandler extends AbstractChainHandler {
|
|
16
16
|
substrateApiMap = {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { getERC20Contract } from '@subwallet/extension-base/koni/api/
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { getERC20Contract } from '@subwallet/extension-base/koni/api/contract-handler/evm/web3';
|
|
5
|
+
import { _PSP22_ABI } from '@subwallet/extension-base/koni/api/contract-handler/utils';
|
|
6
|
+
import { getDefaultWeightV2 } from '@subwallet/extension-base/koni/api/contract-handler/wasm/utils';
|
|
7
7
|
import { _getContractAddressOfToken, _getTokenOnChainAssetId, _getTokenOnChainInfo } from '@subwallet/extension-base/services/chain-service/utils';
|
|
8
8
|
import BigN from 'bignumber.js';
|
|
9
9
|
import { ContractPromise } from '@polkadot/api-contract';
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
5
5
|
import { BasicTxErrorType, ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
|
-
import { getERC20Contract } from '@subwallet/extension-base/koni/api/
|
|
6
|
+
import { getERC20Contract, getERC20SpendingApprovalTx } from '@subwallet/extension-base/koni/api/contract-handler/evm/web3';
|
|
7
7
|
import { _getAssetDecimals, _getContractAddressOfToken } from '@subwallet/extension-base/services/chain-service/utils';
|
|
8
8
|
import { calculateGasFeeParams } from '@subwallet/extension-base/services/fee-service/utils';
|
|
9
9
|
import { EarningStatus, UnstakingStatus, YieldStepType } from '@subwallet/extension-base/types';
|
|
@@ -17,7 +17,6 @@ export const getStellaswapLiquidStakingContract = (networkKey, assetAddress, evm
|
|
|
17
17
|
};
|
|
18
18
|
const APR_STATS_URL = 'https://apr-api.stellaswap.com/api/v1/stdot';
|
|
19
19
|
const SUBWALLET_REFERRAL = '0x7e6815f45E624768548d085231f2d453f16FD7DD';
|
|
20
|
-
const MAX_INT = '115792089237316195423570985008687907853269984665640564039457584007913129639935';
|
|
21
20
|
export default class StellaSwapLiquidStakingPoolHandler extends BaseLiquidStakingPoolHandler {
|
|
22
21
|
inputAsset = 'moonbeam-LOCAL-xcDOT';
|
|
23
22
|
altInputAsset = '';
|
|
@@ -247,7 +246,6 @@ export default class StellaSwapLiquidStakingPoolHandler extends BaseLiquidStakin
|
|
|
247
246
|
return Promise.resolve([]);
|
|
248
247
|
}
|
|
249
248
|
async handleTokenApproveStep(data, path) {
|
|
250
|
-
var _priority$maxFeePerGa, _priority$maxPriority;
|
|
251
249
|
const {
|
|
252
250
|
address
|
|
253
251
|
} = data;
|
|
@@ -256,33 +254,16 @@ export default class StellaSwapLiquidStakingPoolHandler extends BaseLiquidStakin
|
|
|
256
254
|
const derivativeTokenInfo = this.state.getAssetBySlug(this.derivativeAssets[0]);
|
|
257
255
|
const derivativeTokenContractAddress = _getContractAddressOfToken(derivativeTokenInfo);
|
|
258
256
|
const evmApi = this.evmApi;
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
262
|
-
const approveCall = inputTokenContract.methods.approve(derivativeTokenContractAddress, MAX_INT); // TODO: need test
|
|
263
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
264
|
-
const approveEncodedCall = approveCall.encodeABI();
|
|
265
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
266
|
-
const gasLimit = await approveCall.estimateGas({
|
|
267
|
-
from: address
|
|
268
|
-
});
|
|
269
|
-
const priority = await calculateGasFeeParams(evmApi, this.chain);
|
|
270
|
-
const transactionObject = {
|
|
271
|
-
from: address,
|
|
272
|
-
to: _getContractAddressOfToken(inputTokenInfo),
|
|
273
|
-
data: approveEncodedCall,
|
|
274
|
-
gas: gasLimit,
|
|
275
|
-
gasPrice: priority.gasPrice,
|
|
276
|
-
maxFeePerGas: (_priority$maxFeePerGa = priority.maxFeePerGas) === null || _priority$maxFeePerGa === void 0 ? void 0 : _priority$maxFeePerGa.toString(),
|
|
277
|
-
maxPriorityFeePerGas: (_priority$maxPriority = priority.maxPriorityFeePerGas) === null || _priority$maxPriority === void 0 ? void 0 : _priority$maxPriority.toString()
|
|
278
|
-
};
|
|
257
|
+
const transactionObject = await getERC20SpendingApprovalTx(derivativeTokenContractAddress, address, _getContractAddressOfToken(inputTokenInfo), evmApi);
|
|
279
258
|
const _data = {
|
|
280
|
-
|
|
281
|
-
|
|
259
|
+
contractAddress: inputTokenSlug,
|
|
260
|
+
spenderAddress: this.derivativeAssets[0],
|
|
261
|
+
owner: address,
|
|
262
|
+
chain: this.chain
|
|
282
263
|
};
|
|
283
264
|
return Promise.resolve({
|
|
284
265
|
txChain: this.chain,
|
|
285
|
-
extrinsicType: ExtrinsicType.
|
|
266
|
+
extrinsicType: ExtrinsicType.TOKEN_SPENDING_APPROVAL,
|
|
286
267
|
extrinsic: transactionObject,
|
|
287
268
|
txData: _data,
|
|
288
269
|
transferNativeAmount: '0',
|
|
@@ -290,7 +271,7 @@ export default class StellaSwapLiquidStakingPoolHandler extends BaseLiquidStakin
|
|
|
290
271
|
});
|
|
291
272
|
}
|
|
292
273
|
async handleSubmitStep(data, path) {
|
|
293
|
-
var _priority$
|
|
274
|
+
var _priority$maxFeePerGa, _priority$maxPriority;
|
|
294
275
|
const {
|
|
295
276
|
address,
|
|
296
277
|
amount
|
|
@@ -316,8 +297,8 @@ export default class StellaSwapLiquidStakingPoolHandler extends BaseLiquidStakin
|
|
|
316
297
|
data: depositEncodedCall,
|
|
317
298
|
gas: gasLimit,
|
|
318
299
|
gasPrice: priority.gasPrice,
|
|
319
|
-
maxFeePerGas: (_priority$
|
|
320
|
-
maxPriorityFeePerGas: (_priority$
|
|
300
|
+
maxFeePerGas: (_priority$maxFeePerGa = priority.maxFeePerGas) === null || _priority$maxFeePerGa === void 0 ? void 0 : _priority$maxFeePerGa.toString(),
|
|
301
|
+
maxPriorityFeePerGas: (_priority$maxPriority = priority.maxPriorityFeePerGas) === null || _priority$maxPriority === void 0 ? void 0 : _priority$maxPriority.toString()
|
|
321
302
|
};
|
|
322
303
|
return {
|
|
323
304
|
txChain: this.chain,
|
|
@@ -337,7 +318,7 @@ export default class StellaSwapLiquidStakingPoolHandler extends BaseLiquidStakin
|
|
|
337
318
|
return Promise.reject(new TransactionError(BasicTxErrorType.UNSUPPORTED));
|
|
338
319
|
}
|
|
339
320
|
async handleYieldUnstake(amount, address, selectedTarget) {
|
|
340
|
-
var _priority$
|
|
321
|
+
var _priority$maxFeePerGa2, _priority$maxPriority2;
|
|
341
322
|
const evmApi = this.evmApi;
|
|
342
323
|
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
343
324
|
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
@@ -359,8 +340,8 @@ export default class StellaSwapLiquidStakingPoolHandler extends BaseLiquidStakin
|
|
|
359
340
|
data: redeemEncodedCall,
|
|
360
341
|
gas: gasLimit,
|
|
361
342
|
gasPrice: priority.gasPrice,
|
|
362
|
-
maxFeePerGas: (_priority$
|
|
363
|
-
maxPriorityFeePerGas: (_priority$
|
|
343
|
+
maxFeePerGas: (_priority$maxFeePerGa2 = priority.maxFeePerGas) === null || _priority$maxFeePerGa2 === void 0 ? void 0 : _priority$maxFeePerGa2.toString(),
|
|
344
|
+
maxPriorityFeePerGas: (_priority$maxPriority2 = priority.maxPriorityFeePerGas) === null || _priority$maxPriority2 === void 0 ? void 0 : _priority$maxPriority2.toString()
|
|
364
345
|
};
|
|
365
346
|
return [ExtrinsicType.UNSTAKE_STDOT, transaction];
|
|
366
347
|
}
|
|
@@ -370,7 +351,7 @@ export default class StellaSwapLiquidStakingPoolHandler extends BaseLiquidStakin
|
|
|
370
351
|
/* Other actions */
|
|
371
352
|
|
|
372
353
|
async handleYieldWithdraw(address, unstakingInfo) {
|
|
373
|
-
var _priority$
|
|
354
|
+
var _priority$maxFeePerGa3, _priority$maxPriority3;
|
|
374
355
|
const evmApi = this.evmApi;
|
|
375
356
|
const derivativeTokenSlug = this.derivativeAssets[0];
|
|
376
357
|
const derivativeTokenInfo = this.state.getAssetBySlug(derivativeTokenSlug);
|
|
@@ -392,8 +373,8 @@ export default class StellaSwapLiquidStakingPoolHandler extends BaseLiquidStakin
|
|
|
392
373
|
data: withdrawEncodedCall,
|
|
393
374
|
gas: gasLimit,
|
|
394
375
|
gasPrice: priority.gasPrice,
|
|
395
|
-
maxFeePerGas: (_priority$
|
|
396
|
-
maxPriorityFeePerGas: (_priority$
|
|
376
|
+
maxFeePerGas: (_priority$maxFeePerGa3 = priority.maxFeePerGas) === null || _priority$maxFeePerGa3 === void 0 ? void 0 : _priority$maxFeePerGa3.toString(),
|
|
377
|
+
maxPriorityFeePerGas: (_priority$maxPriority3 = priority.maxPriorityFeePerGas) === null || _priority$maxPriority3 === void 0 ? void 0 : _priority$maxPriority3.toString()
|
|
397
378
|
}; // TODO: check tx history parsing
|
|
398
379
|
}
|
|
399
380
|
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
5
5
|
import { BasicTxErrorType, ChainType, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
6
|
import { ALL_ACCOUNT_KEY } from '@subwallet/extension-base/constants';
|
|
7
|
-
import { createXcmExtrinsic } from '@subwallet/extension-base/koni/api/xcm';
|
|
8
7
|
import { YIELD_POOL_STAT_REFRESH_INTERVAL } from '@subwallet/extension-base/koni/api/yield/helper/utils';
|
|
8
|
+
import { createXcmExtrinsic } from '@subwallet/extension-base/services/balance-service/transfer/xcm';
|
|
9
9
|
import { _getChainNativeTokenSlug } from '@subwallet/extension-base/services/chain-service/utils';
|
|
10
10
|
import { YieldStepType, YieldValidationStatus } from '@subwallet/extension-base/types';
|
|
11
11
|
import { createPromiseHandler, formatNumber } from '@subwallet/extension-base/utils';
|
|
@@ -91,7 +91,7 @@ export function parseSubscanTransferData(address, transferItem, chainInfo) {
|
|
|
91
91
|
amount: {
|
|
92
92
|
value: transferItem.amount,
|
|
93
93
|
decimals: 0,
|
|
94
|
-
symbol: transferItem.asset_symbol
|
|
94
|
+
symbol: transferItem.asset_type === 'nfts' ? 'NFT' : transferItem.asset_symbol
|
|
95
95
|
},
|
|
96
96
|
fee: {
|
|
97
97
|
value: transferItem.fee,
|