@subwallet/extension-base 1.3.17-0 → 1.3.18-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 -2
- package/cjs/constants/index.js +6 -3
- package/cjs/core/logic-validation/request.js +26 -19
- package/cjs/core/logic-validation/transfer.js +18 -17
- package/cjs/koni/api/contract-handler/evm/web3.js +3 -3
- package/cjs/koni/background/handlers/Extension.js +269 -123
- package/cjs/koni/background/handlers/State.js +1 -8
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +1 -1
- package/cjs/services/balance-service/index.js +13 -0
- package/cjs/services/balance-service/transfer/smart-contract.js +47 -33
- package/cjs/services/balance-service/transfer/token.js +5 -4
- package/cjs/services/balance-service/transfer/xcm/availBridge.js +14 -18
- package/cjs/services/balance-service/transfer/xcm/index.js +30 -61
- package/cjs/services/balance-service/transfer/xcm/polygonBridge.js +13 -17
- package/cjs/services/balance-service/transfer/xcm/posBridge.js +20 -21
- package/cjs/services/balance-service/transfer/xcm/snowBridge.js +7 -7
- package/cjs/services/balance-service/transfer/xcm/utils.js +2 -2
- package/cjs/services/chain-service/constants.js +3 -3
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +7 -12
- package/cjs/services/earning-service/handlers/special.js +15 -4
- package/cjs/services/fee-service/interfaces.js +1 -0
- package/cjs/services/fee-service/service.js +111 -0
- package/cjs/services/fee-service/utils/index.js +99 -113
- package/cjs/services/storage-service/db-stores/Balance.js +3 -0
- package/cjs/services/swap-service/handler/asset-hub/handler.js +21 -6
- package/cjs/services/swap-service/handler/asset-hub/router.js +1 -1
- package/cjs/services/swap-service/handler/asset-hub/utils.js +4 -4
- package/cjs/services/swap-service/handler/base-handler.js +2 -0
- package/cjs/services/swap-service/handler/chainflip-handler.js +25 -4
- package/cjs/services/swap-service/handler/hydradx-handler.js +20 -6
- package/cjs/services/swap-service/handler/simpleswap-handler.js +23 -3
- package/cjs/services/swap-service/index.js +8 -8
- package/cjs/services/transaction-service/index.js +23 -3
- package/cjs/types/balance/transfer.js +1 -0
- package/cjs/types/fee/base.js +1 -0
- package/cjs/types/fee/evm.js +16 -1
- package/cjs/types/fee/index.js +37 -4
- package/cjs/types/fee/option.js +1 -0
- package/cjs/types/fee/subscription.js +1 -0
- package/cjs/types/fee/substrate.js +1 -0
- package/cjs/types/fee/ton.js +1 -0
- package/cjs/utils/fee/combine.js +50 -0
- package/cjs/utils/fee/index.js +27 -0
- package/cjs/utils/fee/transfer.js +374 -0
- package/cjs/utils/index.js +12 -0
- package/constants/index.d.ts +1 -0
- package/constants/index.js +1 -0
- package/core/logic-validation/request.js +17 -10
- package/core/logic-validation/transfer.d.ts +5 -5
- package/core/logic-validation/transfer.js +20 -19
- package/core/substrate/xcm-parser.d.ts +1 -1
- package/koni/api/contract-handler/evm/web3.js +3 -3
- package/koni/background/handlers/Extension.d.ts +3 -3
- package/koni/background/handlers/Extension.js +253 -107
- package/koni/background/handlers/State.js +1 -8
- package/package.json +55 -5
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/substrate/index.js +1 -1
- package/services/balance-service/index.d.ts +1 -0
- package/services/balance-service/index.js +13 -0
- package/services/balance-service/transfer/smart-contract.d.ts +24 -4
- package/services/balance-service/transfer/smart-contract.js +45 -33
- package/services/balance-service/transfer/token.js +6 -5
- package/services/balance-service/transfer/xcm/availBridge.d.ts +3 -2
- package/services/balance-service/transfer/xcm/availBridge.js +11 -15
- package/services/balance-service/transfer/xcm/index.d.ts +12 -11
- package/services/balance-service/transfer/xcm/index.js +29 -58
- package/services/balance-service/transfer/xcm/polygonBridge.d.ts +4 -3
- package/services/balance-service/transfer/xcm/polygonBridge.js +13 -17
- package/services/balance-service/transfer/xcm/posBridge.d.ts +4 -3
- package/services/balance-service/transfer/xcm/posBridge.js +18 -19
- package/services/balance-service/transfer/xcm/snowBridge.d.ts +2 -1
- package/services/balance-service/transfer/xcm/snowBridge.js +7 -7
- package/services/balance-service/transfer/xcm/utils.js +2 -2
- package/services/chain-service/constants.js +3 -3
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +7 -12
- package/services/earning-service/handlers/special.js +15 -4
- package/services/fee-service/interfaces.d.ts +5 -0
- package/services/fee-service/interfaces.js +1 -0
- package/services/fee-service/service.d.ts +4 -1
- package/services/fee-service/service.js +111 -0
- package/services/fee-service/utils/index.d.ts +8 -2
- package/services/fee-service/utils/index.js +92 -108
- package/services/storage-service/db-stores/Balance.d.ts +1 -0
- package/services/storage-service/db-stores/Balance.js +3 -0
- package/services/swap-service/handler/asset-hub/handler.d.ts +2 -1
- package/services/swap-service/handler/asset-hub/handler.js +21 -6
- package/services/swap-service/handler/asset-hub/router.js +2 -2
- package/services/swap-service/handler/asset-hub/utils.d.ts +1 -1
- package/services/swap-service/handler/asset-hub/utils.js +2 -2
- package/services/swap-service/handler/base-handler.d.ts +4 -1
- package/services/swap-service/handler/base-handler.js +2 -0
- package/services/swap-service/handler/chainflip-handler.d.ts +2 -1
- package/services/swap-service/handler/chainflip-handler.js +24 -3
- package/services/swap-service/handler/hydradx-handler.d.ts +2 -1
- package/services/swap-service/handler/hydradx-handler.js +19 -5
- package/services/swap-service/handler/simpleswap-handler.d.ts +2 -1
- package/services/swap-service/handler/simpleswap-handler.js +23 -3
- package/services/swap-service/index.js +8 -8
- package/services/transaction-service/index.js +23 -3
- package/services/transaction-service/types.d.ts +5 -4
- package/types/balance/transfer.d.ts +25 -0
- package/types/balance/transfer.js +1 -0
- package/types/fee/base.d.ts +8 -0
- package/types/fee/base.js +1 -0
- package/types/fee/evm.d.ts +46 -16
- package/types/fee/evm.js +10 -1
- package/types/fee/index.d.ts +4 -1
- package/types/fee/index.js +4 -1
- package/types/fee/option.d.ts +8 -0
- package/types/fee/option.js +1 -0
- package/types/fee/subscription.d.ts +12 -0
- package/types/fee/subscription.js +1 -0
- package/types/fee/substrate.d.ts +15 -0
- package/types/fee/substrate.js +1 -0
- package/types/fee/ton.d.ts +18 -0
- package/types/fee/ton.js +1 -0
- package/types/transaction/request.d.ts +13 -3
- package/utils/fee/combine.d.ts +12 -0
- package/utils/fee/combine.js +42 -0
- package/utils/fee/index.d.ts +2 -0
- package/utils/fee/index.js +5 -0
- package/utils/fee/transfer.d.ts +22 -0
- package/utils/fee/transfer.js +363 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.3.
|
|
20
|
+
"version": "1.3.18-0",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -1091,6 +1091,11 @@
|
|
|
1091
1091
|
"require": "./cjs/services/event-service/types.js",
|
|
1092
1092
|
"default": "./services/event-service/types.js"
|
|
1093
1093
|
},
|
|
1094
|
+
"./services/fee-service/interfaces": {
|
|
1095
|
+
"types": "./services/fee-service/interfaces.d.ts",
|
|
1096
|
+
"require": "./cjs/services/fee-service/interfaces.js",
|
|
1097
|
+
"default": "./services/fee-service/interfaces.js"
|
|
1098
|
+
},
|
|
1094
1099
|
"./services/fee-service/service": {
|
|
1095
1100
|
"types": "./services/fee-service/service.d.ts",
|
|
1096
1101
|
"require": "./cjs/services/fee-service/service.js",
|
|
@@ -2076,6 +2081,11 @@
|
|
|
2076
2081
|
"require": "./cjs/types/balance/index.js",
|
|
2077
2082
|
"default": "./types/balance/index.js"
|
|
2078
2083
|
},
|
|
2084
|
+
"./types/balance/transfer": {
|
|
2085
|
+
"types": "./types/balance/transfer.d.ts",
|
|
2086
|
+
"require": "./cjs/types/balance/transfer.js",
|
|
2087
|
+
"default": "./types/balance/transfer.js"
|
|
2088
|
+
},
|
|
2079
2089
|
"./types/bridge": {
|
|
2080
2090
|
"types": "./types/bridge/index.d.ts",
|
|
2081
2091
|
"require": "./cjs/types/bridge/index.js",
|
|
@@ -2116,6 +2126,11 @@
|
|
|
2116
2126
|
"require": "./cjs/types/fee/index.js",
|
|
2117
2127
|
"default": "./types/fee/index.js"
|
|
2118
2128
|
},
|
|
2129
|
+
"./types/fee/base": {
|
|
2130
|
+
"types": "./types/fee/base.d.ts",
|
|
2131
|
+
"require": "./cjs/types/fee/base.js",
|
|
2132
|
+
"default": "./types/fee/base.js"
|
|
2133
|
+
},
|
|
2119
2134
|
"./types/fee/evm": {
|
|
2120
2135
|
"types": "./types/fee/evm.d.ts",
|
|
2121
2136
|
"require": "./cjs/types/fee/evm.js",
|
|
@@ -2126,6 +2141,26 @@
|
|
|
2126
2141
|
"require": "./cjs/types/fee/fee.js",
|
|
2127
2142
|
"default": "./types/fee/fee.js"
|
|
2128
2143
|
},
|
|
2144
|
+
"./types/fee/option": {
|
|
2145
|
+
"types": "./types/fee/option.d.ts",
|
|
2146
|
+
"require": "./cjs/types/fee/option.js",
|
|
2147
|
+
"default": "./types/fee/option.js"
|
|
2148
|
+
},
|
|
2149
|
+
"./types/fee/subscription": {
|
|
2150
|
+
"types": "./types/fee/subscription.d.ts",
|
|
2151
|
+
"require": "./cjs/types/fee/subscription.js",
|
|
2152
|
+
"default": "./types/fee/subscription.js"
|
|
2153
|
+
},
|
|
2154
|
+
"./types/fee/substrate": {
|
|
2155
|
+
"types": "./types/fee/substrate.d.ts",
|
|
2156
|
+
"require": "./cjs/types/fee/substrate.js",
|
|
2157
|
+
"default": "./types/fee/substrate.js"
|
|
2158
|
+
},
|
|
2159
|
+
"./types/fee/ton": {
|
|
2160
|
+
"types": "./types/fee/ton.d.ts",
|
|
2161
|
+
"require": "./cjs/types/fee/ton.js",
|
|
2162
|
+
"default": "./types/fee/ton.js"
|
|
2163
|
+
},
|
|
2129
2164
|
"./types/metadata": {
|
|
2130
2165
|
"types": "./types/metadata.d.ts",
|
|
2131
2166
|
"require": "./cjs/types/metadata.js",
|
|
@@ -2361,6 +2396,21 @@
|
|
|
2361
2396
|
"require": "./cjs/utils/eth/parseTransaction/base.js",
|
|
2362
2397
|
"default": "./utils/eth/parseTransaction/base.js"
|
|
2363
2398
|
},
|
|
2399
|
+
"./utils/fee": {
|
|
2400
|
+
"types": "./utils/fee/index.d.ts",
|
|
2401
|
+
"require": "./cjs/utils/fee/index.js",
|
|
2402
|
+
"default": "./utils/fee/index.js"
|
|
2403
|
+
},
|
|
2404
|
+
"./utils/fee/combine": {
|
|
2405
|
+
"types": "./utils/fee/combine.d.ts",
|
|
2406
|
+
"require": "./cjs/utils/fee/combine.js",
|
|
2407
|
+
"default": "./utils/fee/combine.js"
|
|
2408
|
+
},
|
|
2409
|
+
"./utils/fee/transfer": {
|
|
2410
|
+
"types": "./utils/fee/transfer.d.ts",
|
|
2411
|
+
"require": "./cjs/utils/fee/transfer.js",
|
|
2412
|
+
"default": "./utils/fee/transfer.js"
|
|
2413
|
+
},
|
|
2364
2414
|
"./utils/fetch": {
|
|
2365
2415
|
"types": "./utils/fetch.d.ts",
|
|
2366
2416
|
"require": "./cjs/utils/fetch.js",
|
|
@@ -2514,10 +2564,10 @@
|
|
|
2514
2564
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
2515
2565
|
"@substrate/connect": "^0.8.9",
|
|
2516
2566
|
"@subwallet/chain-list": "0.2.99-beta.14",
|
|
2517
|
-
"@subwallet/extension-base": "^1.3.
|
|
2518
|
-
"@subwallet/extension-chains": "^1.3.
|
|
2519
|
-
"@subwallet/extension-dapp": "^1.3.
|
|
2520
|
-
"@subwallet/extension-inject": "^1.3.
|
|
2567
|
+
"@subwallet/extension-base": "^1.3.18-0",
|
|
2568
|
+
"@subwallet/extension-chains": "^1.3.18-0",
|
|
2569
|
+
"@subwallet/extension-dapp": "^1.3.18-0",
|
|
2570
|
+
"@subwallet/extension-inject": "^1.3.18-0",
|
|
2521
2571
|
"@subwallet/keyring": "^0.1.8-beta.0",
|
|
2522
2572
|
"@subwallet/ui-keyring": "^0.1.8-beta.0",
|
|
2523
2573
|
"@ton/core": "^0.56.3",
|
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.3.
|
|
10
|
+
version: '1.3.18-0'
|
|
11
11
|
};
|
|
@@ -204,7 +204,7 @@ const subscribeForeignAssetBalance = async ({
|
|
|
204
204
|
const unsubList = await Promise.all(Object.values(tokenMap).map(tokenInfo => {
|
|
205
205
|
try {
|
|
206
206
|
if (_isBridgedToken(tokenInfo)) {
|
|
207
|
-
const version = ['statemint', 'statemine'].includes(chainInfo.slug) ? 4 : 3;
|
|
207
|
+
const version = ['statemint', 'statemine', 'westend_assethub'].includes(chainInfo.slug) ? 4 : 3;
|
|
208
208
|
const params = [{
|
|
209
209
|
section: 'query',
|
|
210
210
|
module: foreignAssetsAccountKey.split('_')[1],
|
|
@@ -70,6 +70,7 @@ export declare class BalanceService implements StoppableServiceInterface {
|
|
|
70
70
|
getBalance(reset?: boolean): Promise<BalanceJson>;
|
|
71
71
|
/** Get stored balance from db */
|
|
72
72
|
getStoredBalance(address: string): Promise<BalanceItem[]>;
|
|
73
|
+
getTokensHasBalance(address: string, chain: string, tokenSlug?: string): Promise<Record<string, BalanceItem>>;
|
|
73
74
|
handleResetBalance(forceRefresh?: boolean): Promise<void>;
|
|
74
75
|
/**
|
|
75
76
|
* Update value for balance map
|
|
@@ -280,6 +280,19 @@ export class BalanceService {
|
|
|
280
280
|
async getStoredBalance(address) {
|
|
281
281
|
return await this.state.dbService.stores.balance.getBalanceMapByAddresses(address);
|
|
282
282
|
}
|
|
283
|
+
async getTokensHasBalance(address, chain, tokenSlug) {
|
|
284
|
+
const balanceItems = await this.state.dbService.stores.balance.getBalanceHasAmount(address, chain);
|
|
285
|
+
const tokenHasBalanceInfoMap = {};
|
|
286
|
+
balanceItems.forEach(balanceItem => {
|
|
287
|
+
tokenHasBalanceInfoMap[balanceItem.tokenSlug] = balanceItem;
|
|
288
|
+
});
|
|
289
|
+
if (tokenSlug) {
|
|
290
|
+
return {
|
|
291
|
+
[tokenSlug]: tokenHasBalanceInfoMap[tokenSlug]
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
return tokenHasBalanceInfoMap;
|
|
295
|
+
}
|
|
283
296
|
async handleResetBalance(forceRefresh) {
|
|
284
297
|
if (forceRefresh) {
|
|
285
298
|
this.balanceMap.setData({});
|
|
@@ -1,7 +1,27 @@
|
|
|
1
|
-
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
1
|
import { _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
2
|
+
import { FeeInfo, TransactionFee } from '@subwallet/extension-base/types';
|
|
3
3
|
import { TransactionConfig } from 'web3-core';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
interface TransferEvmProps extends TransactionFee {
|
|
5
|
+
chain: string;
|
|
6
|
+
from: string;
|
|
7
|
+
feeInfo: FeeInfo;
|
|
8
|
+
to: string;
|
|
9
|
+
transferAll: boolean;
|
|
10
|
+
value: string;
|
|
11
|
+
evmApi: _EvmApi;
|
|
12
|
+
}
|
|
13
|
+
export declare function getEVMTransactionObject({ chain, evmApi, feeCustom: _feeCustom, feeInfo: _feeInfo, feeOption, from, to, transferAll, value }: TransferEvmProps): Promise<[TransactionConfig, string]>;
|
|
14
|
+
export declare function getERC20TransactionObject({ assetAddress, evmApi, feeCustom: _feeCustom, feeInfo: _feeInfo, feeOption, from, to, transferAll, value }: TransferERC20Props): Promise<[TransactionConfig, string]>;
|
|
15
|
+
interface TransferERC20Props extends TransactionFee {
|
|
16
|
+
assetAddress: string;
|
|
17
|
+
chain: string;
|
|
18
|
+
evmApi: _EvmApi;
|
|
19
|
+
from: string;
|
|
20
|
+
feeInfo: FeeInfo;
|
|
21
|
+
to: string;
|
|
22
|
+
transferAll: boolean;
|
|
23
|
+
value: string;
|
|
24
|
+
}
|
|
25
|
+
export declare function getERC721Transaction(web3Api: _EvmApi, chain: string, contractAddress: string, senderAddress: string, recipientAddress: string, tokenId: string, _feeInfo: FeeInfo): Promise<TransactionConfig>;
|
|
7
26
|
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>;
|
|
27
|
+
export {};
|
|
@@ -6,41 +6,58 @@ import { _ERC721_ABI } from '@subwallet/extension-base/koni/api/contract-handler
|
|
|
6
6
|
import { getPSP34ContractPromise } from '@subwallet/extension-base/koni/api/contract-handler/wasm';
|
|
7
7
|
import { getWasmContractGasLimit } from '@subwallet/extension-base/koni/api/contract-handler/wasm/utils';
|
|
8
8
|
import { EVM_REFORMAT_DECIMALS } from '@subwallet/extension-base/services/chain-service/constants';
|
|
9
|
-
import {
|
|
9
|
+
import { combineEthFee } from '@subwallet/extension-base/utils';
|
|
10
10
|
import BigN from 'bignumber.js';
|
|
11
11
|
import { t } from 'i18next';
|
|
12
|
-
export async function getEVMTransactionObject(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
export async function getEVMTransactionObject({
|
|
13
|
+
chain,
|
|
14
|
+
evmApi,
|
|
15
|
+
feeCustom: _feeCustom,
|
|
16
|
+
feeInfo: _feeInfo,
|
|
17
|
+
feeOption,
|
|
18
|
+
from,
|
|
19
|
+
to,
|
|
20
|
+
transferAll,
|
|
21
|
+
value
|
|
22
|
+
}) {
|
|
23
|
+
const feeCustom = _feeCustom;
|
|
24
|
+
const feeInfo = _feeInfo;
|
|
25
|
+
const feeCombine = combineEthFee(feeInfo, feeOption, feeCustom);
|
|
16
26
|
const transactionObject = {
|
|
17
27
|
to: to,
|
|
18
28
|
value: value,
|
|
19
29
|
from: from,
|
|
20
|
-
|
|
21
|
-
maxFeePerGas: (_priority$maxFeePerGa = priority.maxFeePerGas) === null || _priority$maxFeePerGa === void 0 ? void 0 : _priority$maxFeePerGa.toString(),
|
|
22
|
-
maxPriorityFeePerGas: (_priority$maxPriority = priority.maxPriorityFeePerGas) === null || _priority$maxPriority === void 0 ? void 0 : _priority$maxPriority.toString()
|
|
30
|
+
...feeCombine
|
|
23
31
|
};
|
|
24
|
-
const gasLimit = await
|
|
32
|
+
const gasLimit = await evmApi.api.eth.estimateGas(transactionObject);
|
|
25
33
|
transactionObject.gas = gasLimit;
|
|
26
34
|
let estimateFee;
|
|
27
|
-
if (
|
|
28
|
-
const maxFee =
|
|
35
|
+
if (feeCombine.maxFeePerGas) {
|
|
36
|
+
const maxFee = new BigN(feeCombine.maxFeePerGas);
|
|
29
37
|
estimateFee = maxFee.multipliedBy(gasLimit);
|
|
30
38
|
} else {
|
|
31
|
-
estimateFee = new BigN(
|
|
39
|
+
estimateFee = new BigN(feeCombine.gasPrice || '0').multipliedBy(gasLimit);
|
|
32
40
|
}
|
|
33
41
|
transactionObject.value = transferAll ? new BigN(value).minus(estimateFee).toString() : value;
|
|
34
|
-
if (EVM_REFORMAT_DECIMALS.acala.includes(
|
|
42
|
+
if (EVM_REFORMAT_DECIMALS.acala.includes(chain)) {
|
|
35
43
|
const numberReplace = 18 - 12;
|
|
36
44
|
transactionObject.value = transactionObject.value.substring(0, transactionObject.value.length - 6) + new Array(numberReplace).fill('0').join('');
|
|
37
45
|
}
|
|
38
46
|
return [transactionObject, transactionObject.value.toString()];
|
|
39
47
|
}
|
|
40
|
-
export async function getERC20TransactionObject(
|
|
41
|
-
|
|
42
|
-
|
|
48
|
+
export async function getERC20TransactionObject({
|
|
49
|
+
assetAddress,
|
|
50
|
+
evmApi,
|
|
51
|
+
feeCustom: _feeCustom,
|
|
52
|
+
feeInfo: _feeInfo,
|
|
53
|
+
feeOption,
|
|
54
|
+
from,
|
|
55
|
+
to,
|
|
56
|
+
transferAll,
|
|
57
|
+
value
|
|
58
|
+
}) {
|
|
43
59
|
const erc20Contract = getERC20Contract(assetAddress, evmApi);
|
|
60
|
+
const feeCustom = _feeCustom;
|
|
44
61
|
let freeAmount = new BigN(0);
|
|
45
62
|
let transferValue = value;
|
|
46
63
|
if (transferAll) {
|
|
@@ -54,22 +71,19 @@ export async function getERC20TransactionObject(assetAddress, chainInfo, from, t
|
|
|
54
71
|
return erc20Contract.methods.transfer(to, transferValue).encodeABI();
|
|
55
72
|
}
|
|
56
73
|
const transferData = generateTransferData(to, transferValue);
|
|
57
|
-
const [gasLimit, priority] = await Promise.all([
|
|
58
74
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
59
|
-
erc20Contract.methods.transfer(to, transferValue).estimateGas({
|
|
75
|
+
const gasLimit = await erc20Contract.methods.transfer(to, transferValue).estimateGas({
|
|
60
76
|
from
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
|
|
77
|
+
});
|
|
78
|
+
const feeInfo = _feeInfo;
|
|
79
|
+
const feeCombine = combineEthFee(feeInfo, feeOption, feeCustom);
|
|
64
80
|
const transactionObject = {
|
|
65
81
|
gas: gasLimit,
|
|
66
82
|
from,
|
|
67
83
|
value: '0',
|
|
68
84
|
to: assetAddress,
|
|
69
85
|
data: transferData,
|
|
70
|
-
|
|
71
|
-
maxFeePerGas: (_priority$maxFeePerGa2 = priority.maxFeePerGas) === null || _priority$maxFeePerGa2 === void 0 ? void 0 : _priority$maxFeePerGa2.toString(),
|
|
72
|
-
maxPriorityFeePerGas: (_priority$maxPriority2 = priority.maxPriorityFeePerGas) === null || _priority$maxPriority2 === void 0 ? void 0 : _priority$maxPriority2.toString()
|
|
86
|
+
...feeCombine
|
|
73
87
|
};
|
|
74
88
|
if (transferAll) {
|
|
75
89
|
transferValue = freeAmount.toFixed(0);
|
|
@@ -77,18 +91,16 @@ export async function getERC20TransactionObject(assetAddress, chainInfo, from, t
|
|
|
77
91
|
}
|
|
78
92
|
return [transactionObject, transferValue];
|
|
79
93
|
}
|
|
80
|
-
export async function getERC721Transaction(web3Api, chain, contractAddress, senderAddress, recipientAddress, tokenId) {
|
|
81
|
-
var _priority$maxFeePerGa3, _priority$maxPriority3;
|
|
94
|
+
export async function getERC721Transaction(web3Api, chain, contractAddress, senderAddress, recipientAddress, tokenId, _feeInfo) {
|
|
82
95
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
83
96
|
const contract = new web3Api.api.eth.Contract(_ERC721_ABI, contractAddress);
|
|
84
97
|
let gasLimit;
|
|
85
|
-
let priority;
|
|
86
98
|
try {
|
|
87
|
-
[gasLimit
|
|
99
|
+
[gasLimit] = await Promise.all([
|
|
88
100
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
89
101
|
contract.methods.safeTransferFrom(senderAddress, recipientAddress, tokenId).estimateGas({
|
|
90
102
|
from: senderAddress
|
|
91
|
-
})
|
|
103
|
+
})]);
|
|
92
104
|
} catch (e) {
|
|
93
105
|
const error = e;
|
|
94
106
|
if (error.message.includes('transfer to non ERC721Receiver implementer')) {
|
|
@@ -96,16 +108,16 @@ export async function getERC721Transaction(web3Api, chain, contractAddress, send
|
|
|
96
108
|
}
|
|
97
109
|
throw error;
|
|
98
110
|
}
|
|
111
|
+
const feeInfo = _feeInfo;
|
|
112
|
+
const feeCombine = combineEthFee(feeInfo);
|
|
99
113
|
return {
|
|
100
114
|
from: senderAddress,
|
|
101
|
-
gasPrice: priority.gasPrice,
|
|
102
|
-
maxFeePerGas: (_priority$maxFeePerGa3 = priority.maxFeePerGas) === null || _priority$maxFeePerGa3 === void 0 ? void 0 : _priority$maxFeePerGa3.toString(),
|
|
103
|
-
maxPriorityFeePerGas: (_priority$maxPriority3 = priority.maxPriorityFeePerGas) === null || _priority$maxPriority3 === void 0 ? void 0 : _priority$maxPriority3.toString(),
|
|
104
115
|
gas: gasLimit,
|
|
105
116
|
to: contractAddress,
|
|
106
117
|
value: '0x00',
|
|
107
118
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
108
|
-
data: contract.methods.safeTransferFrom(senderAddress, recipientAddress, tokenId).encodeABI()
|
|
119
|
+
data: contract.methods.safeTransferFrom(senderAddress, recipientAddress, tokenId).encodeABI(),
|
|
120
|
+
...feeCombine
|
|
109
121
|
};
|
|
110
122
|
}
|
|
111
123
|
const mustFormatNumberReg = /^-?[0-9][0-9,.]+$/;
|
|
@@ -9,7 +9,7 @@ import { estimateTonTxFee } from '@subwallet/extension-base/services/balance-ser
|
|
|
9
9
|
import { _TRANSFER_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
10
10
|
import { _getContractAddressOfToken, _getTokenOnChainAssetId, _getTokenOnChainInfo, _getXcmAssetMultilocation, _isBridgedToken, _isChainEvmCompatible, _isChainTonCompatible, _isNativeToken, _isTokenGearSmartContract, _isTokenTransferredByEvm, _isTokenTransferredByTon, _isTokenWasmSmartContract } from '@subwallet/extension-base/services/chain-service/utils';
|
|
11
11
|
import { calculateGasFeeParams } from '@subwallet/extension-base/services/fee-service/utils';
|
|
12
|
-
import { getGRC20ContractPromise, getVFTContractPromise } from '@subwallet/extension-base/utils';
|
|
12
|
+
import { combineEthFee, getGRC20ContractPromise, getVFTContractPromise } from '@subwallet/extension-base/utils';
|
|
13
13
|
import { keyring } from '@subwallet/ui-keyring';
|
|
14
14
|
import { internal } from '@ton/core';
|
|
15
15
|
import { Address } from '@ton/ton';
|
|
@@ -124,11 +124,12 @@ export const getTransferMockTxFee = async (address, chainInfo, tokenInfo, api) =
|
|
|
124
124
|
};
|
|
125
125
|
const gasLimit = await web3.api.eth.estimateGas(transaction);
|
|
126
126
|
const priority = await calculateGasFeeParams(web3, chainInfo.slug);
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
const combinedFee = combineEthFee(priority);
|
|
128
|
+
if (combinedFee.maxFeePerGas) {
|
|
129
|
+
const maxFee = combinedFee.maxFeePerGas;
|
|
130
|
+
estimatedFee = BigN(maxFee).multipliedBy(gasLimit);
|
|
130
131
|
} else {
|
|
131
|
-
estimatedFee = new BigN(
|
|
132
|
+
estimatedFee = new BigN(combinedFee.gasPrice).multipliedBy(gasLimit);
|
|
132
133
|
}
|
|
133
134
|
} else if (_isChainTonCompatible(chainInfo) && _isTokenTransferredByTon(tokenInfo)) {
|
|
134
135
|
const mockWalletContract = keyring.getPair(address).ton.currentContract;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
2
|
import { _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
3
3
|
import { _NotificationInfo } from '@subwallet/extension-base/services/inapp-notification-service/interfaces';
|
|
4
|
+
import { EvmFeeInfo, FeeCustom, FeeInfo, FeeOption } from '@subwallet/extension-base/types';
|
|
4
5
|
import { TransactionConfig } from 'web3-core';
|
|
5
6
|
export declare const AvailBridgeConfig: {
|
|
6
7
|
ASSET_ID: string;
|
|
@@ -37,9 +38,9 @@ declare type Message = {
|
|
|
37
38
|
to: string;
|
|
38
39
|
messageType: string;
|
|
39
40
|
};
|
|
40
|
-
export declare function getAvailBridgeTxFromEth(originChainInfo: _ChainInfo, sender: string, recipient: string, value: string, evmApi: _EvmApi): Promise<TransactionConfig>;
|
|
41
|
+
export declare function getAvailBridgeTxFromEth(originChainInfo: _ChainInfo, sender: string, recipient: string, value: string, evmApi: _EvmApi, fee: FeeInfo, feeCustom?: FeeCustom, feeOption?: FeeOption): Promise<TransactionConfig>;
|
|
41
42
|
export declare function getAvailBridgeExtrinsicFromAvail(recipient: string, sendingValue: string, substrateApi: _SubstrateApi): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
42
43
|
export declare function getClaimTxOnAvail(notification: _NotificationInfo, substrateApi: _SubstrateApi): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult>>;
|
|
43
|
-
export declare function getClaimTxOnEthereum(chainSlug: string, notification: _NotificationInfo, evmApi: _EvmApi): Promise<TransactionConfig>;
|
|
44
|
+
export declare function getClaimTxOnEthereum(chainSlug: string, notification: _NotificationInfo, evmApi: _EvmApi, feeInfo: EvmFeeInfo): Promise<TransactionConfig>;
|
|
44
45
|
export declare function isAvailChainBridge(chainSlug: string): boolean;
|
|
45
46
|
export {};
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
import { COMMON_CHAIN_SLUGS } from '@subwallet/chain-list';
|
|
5
5
|
import { getWeb3Contract } from '@subwallet/extension-base/koni/api/contract-handler/evm/web3';
|
|
6
6
|
import { _AVAIL_BRIDGE_GATEWAY_ABI, _AVAIL_TEST_BRIDGE_GATEWAY_ABI, getAvailBridgeGatewayContract } from '@subwallet/extension-base/koni/api/contract-handler/utils';
|
|
7
|
-
import { calculateGasFeeParams } from '@subwallet/extension-base/services/fee-service/utils';
|
|
8
7
|
import { AVAIL_BRIDGE_API } from '@subwallet/extension-base/services/inapp-notification-service/utils';
|
|
8
|
+
import { combineEthFee } from '@subwallet/extension-base/utils';
|
|
9
9
|
import { decodeAddress } from '@subwallet/keyring';
|
|
10
10
|
import { u8aToHex } from '@polkadot/util';
|
|
11
11
|
export const AvailBridgeConfig = {
|
|
@@ -14,8 +14,7 @@ export const AvailBridgeConfig = {
|
|
|
14
14
|
// todo: check if these config can change later
|
|
15
15
|
AVAIL_DOMAIN: 1
|
|
16
16
|
};
|
|
17
|
-
export async function getAvailBridgeTxFromEth(originChainInfo, sender, recipient, value, evmApi) {
|
|
18
|
-
var _priority$maxFeePerGa, _priority$maxPriority;
|
|
17
|
+
export async function getAvailBridgeTxFromEth(originChainInfo, sender, recipient, value, evmApi, fee, feeCustom, feeOption) {
|
|
19
18
|
const availBridgeContractAddress = getAvailBridgeGatewayContract(originChainInfo.slug);
|
|
20
19
|
const ABI = getAvailBridgeAbi(originChainInfo.slug);
|
|
21
20
|
const availBridgeContract = getWeb3Contract(availBridgeContractAddress, evmApi, ABI);
|
|
@@ -23,19 +22,19 @@ export async function getAvailBridgeTxFromEth(originChainInfo, sender, recipient
|
|
|
23
22
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
|
24
23
|
const sendAvail = availBridgeContract.methods.sendAVAIL(_address, value);
|
|
25
24
|
const transferData = sendAvail.encodeABI();
|
|
26
|
-
const priority = await calculateGasFeeParams(evmApi, evmApi.chainSlug);
|
|
27
25
|
const gasLimit = await sendAvail.estimateGas({
|
|
28
26
|
from: sender
|
|
29
27
|
});
|
|
28
|
+
const _feeCustom = feeCustom;
|
|
29
|
+
const feeInfo = fee;
|
|
30
|
+
const feeCombine = combineEthFee(feeInfo, feeOption, _feeCustom);
|
|
30
31
|
return {
|
|
31
32
|
from: sender,
|
|
32
33
|
to: availBridgeContractAddress,
|
|
33
34
|
value: '0',
|
|
34
35
|
data: transferData,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
maxPriorityFeePerGas: (_priority$maxPriority = priority.maxPriorityFeePerGas) === null || _priority$maxPriority === void 0 ? void 0 : _priority$maxPriority.toString(),
|
|
38
|
-
gas: gasLimit
|
|
36
|
+
gas: gasLimit,
|
|
37
|
+
...feeCombine
|
|
39
38
|
};
|
|
40
39
|
}
|
|
41
40
|
export async function getAvailBridgeExtrinsicFromAvail(recipient, sendingValue, substrateApi) {
|
|
@@ -110,8 +109,7 @@ function getAvailBridgeApi(chainSlug) {
|
|
|
110
109
|
}
|
|
111
110
|
return AVAIL_BRIDGE_API.AVAIL_TESTNET;
|
|
112
111
|
}
|
|
113
|
-
export async function getClaimTxOnEthereum(chainSlug, notification, evmApi) {
|
|
114
|
-
var _priority$maxFeePerGa2, _priority$maxPriority2;
|
|
112
|
+
export async function getClaimTxOnEthereum(chainSlug, notification, evmApi, feeInfo) {
|
|
115
113
|
const availBridgeContractAddress = getAvailBridgeGatewayContract(chainSlug);
|
|
116
114
|
const ABI = getAvailBridgeAbi(chainSlug);
|
|
117
115
|
const availBridgeContract = getWeb3Contract(availBridgeContractAddress, evmApi, ABI);
|
|
@@ -147,16 +145,14 @@ export async function getClaimTxOnEthereum(chainSlug, notification, evmApi) {
|
|
|
147
145
|
const gasLimit = await transfer.estimateGas({
|
|
148
146
|
from: metadata.receiverAddress
|
|
149
147
|
});
|
|
150
|
-
const
|
|
148
|
+
const feeCombine = combineEthFee(feeInfo);
|
|
151
149
|
return {
|
|
152
150
|
from: metadata.receiverAddress,
|
|
153
151
|
to: availBridgeContractAddress,
|
|
154
152
|
value: '0',
|
|
155
153
|
data: transferData,
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
maxPriorityFeePerGas: (_priority$maxPriority2 = priority.maxPriorityFeePerGas) === null || _priority$maxPriority2 === void 0 ? void 0 : _priority$maxPriority2.toString(),
|
|
159
|
-
gas: gasLimit
|
|
154
|
+
gas: gasLimit,
|
|
155
|
+
...feeCombine
|
|
160
156
|
};
|
|
161
157
|
}
|
|
162
158
|
function getAddressMessage(notification) {
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import { _ChainAsset, _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
2
|
import { _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
3
|
-
import
|
|
3
|
+
import { FeeInfo, TransactionFee } from '@subwallet/extension-base/types';
|
|
4
4
|
import { TransactionConfig } from 'web3-core';
|
|
5
5
|
import { SubmittableExtrinsic } from '@polkadot/api/types';
|
|
6
6
|
export declare type CreateXcmExtrinsicProps = {
|
|
7
|
-
|
|
7
|
+
destinationChain: _ChainInfo;
|
|
8
8
|
destinationTokenInfo: _ChainAsset;
|
|
9
|
+
evmApi?: _EvmApi;
|
|
10
|
+
originChain: _ChainInfo;
|
|
11
|
+
originTokenInfo: _ChainAsset;
|
|
9
12
|
recipient: string;
|
|
13
|
+
sender: string;
|
|
10
14
|
sendingValue: string;
|
|
11
|
-
evmApi?: _EvmApi;
|
|
12
15
|
substrateApi?: _SubstrateApi;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
16
|
+
feeInfo: FeeInfo;
|
|
17
|
+
} & TransactionFee;
|
|
16
18
|
export declare type FunctionCreateXcmExtrinsic = (props: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'> | TransactionConfig>;
|
|
17
|
-
export declare const createSnowBridgeExtrinsic: ({
|
|
18
|
-
export declare const createXcmExtrinsic: ({
|
|
19
|
-
export declare const createAvailBridgeTxFromEth: ({
|
|
19
|
+
export declare const createSnowBridgeExtrinsic: ({ destinationChain, evmApi, feeCustom, feeInfo, feeOption, originChain, originTokenInfo, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<TransactionConfig>;
|
|
20
|
+
export declare const createXcmExtrinsic: ({ destinationChain, originChain, originTokenInfo, recipient, sendingValue, substrateApi }: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'>>;
|
|
21
|
+
export declare const createAvailBridgeTxFromEth: ({ evmApi, feeCustom, feeInfo, feeOption, originChain, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<TransactionConfig>;
|
|
20
22
|
export declare const createAvailBridgeExtrinsicFromAvail: ({ recipient, sendingValue, substrateApi }: CreateXcmExtrinsicProps) => Promise<SubmittableExtrinsic<'promise'>>;
|
|
21
|
-
export declare const createPolygonBridgeExtrinsic: ({
|
|
22
|
-
export declare const getXcmMockTxFee: (substrateApi: _SubstrateApi, chainInfoMap: Record<string, _ChainInfo>, originTokenInfo: _ChainAsset, destinationTokenInfo: _ChainAsset) => Promise<BigN>;
|
|
23
|
+
export declare const createPolygonBridgeExtrinsic: ({ destinationChain, evmApi, feeCustom, feeInfo, feeOption, originChain, originTokenInfo, recipient, sender, sendingValue }: CreateXcmExtrinsicProps) => Promise<TransactionConfig>;
|