@subwallet/extension-base 1.3.71-0 → 1.3.72-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 +13 -2
- package/background/KoniTypes.js +3 -1
- package/cjs/background/KoniTypes.js +3 -1
- package/cjs/core/logic-validation/recipientAddress.js +1 -1
- package/cjs/core/logic-validation/transfer.js +33 -10
- package/cjs/core/types.js +1 -0
- package/cjs/koni/background/handlers/Extension.js +81 -8
- package/cjs/koni/background/handlers/State.js +2 -0
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +46 -2
- package/cjs/services/balance-service/transfer/token.js +13 -35
- package/cjs/services/balance-service/transfer/xcm/index.js +3 -8
- package/cjs/services/balance-service/transfer/xcm/utils.js +1 -1
- package/cjs/services/chain-service/constants.js +6 -5
- package/cjs/services/chain-service/index.js +1 -0
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/migration-service/scripts/MigrateTransactionHistoryBySymbol20251223.js +55 -0
- package/cjs/services/migration-service/scripts/databases/MigrateAssetSetting20251223.js +41 -0
- package/cjs/services/migration-service/scripts/index.js +17 -13
- package/cjs/services/substrate-proxy-service/constant.js +26 -0
- package/cjs/services/substrate-proxy-service/index.js +170 -0
- package/cjs/services/transaction-service/index.js +78 -10
- package/cjs/services/transaction-service/utils.js +8 -5
- package/cjs/types/index.js +11 -0
- package/cjs/types/substrateProxyAccount/actions/index.js +1 -0
- package/cjs/types/substrateProxyAccount/index.js +16 -0
- package/cjs/utils/account/transform.js +5 -4
- package/cjs/utils/fee/transfer.js +4 -2
- package/core/logic-validation/recipientAddress.js +1 -1
- package/core/logic-validation/transfer.d.ts +3 -3
- package/core/logic-validation/transfer.js +34 -11
- package/core/types.d.ts +2 -1
- package/core/types.js +1 -0
- package/koni/background/handlers/Extension.d.ts +3 -0
- package/koni/background/handlers/Extension.js +81 -8
- package/koni/background/handlers/State.d.ts +2 -0
- package/koni/background/handlers/State.js +2 -0
- package/package.json +36 -6
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/substrate/index.js +47 -3
- package/services/balance-service/transfer/token.d.ts +0 -4
- package/services/balance-service/transfer/token.js +12 -33
- package/services/balance-service/transfer/xcm/index.js +3 -8
- package/services/balance-service/transfer/xcm/utils.d.ts +0 -2
- package/services/balance-service/transfer/xcm/utils.js +1 -1
- package/services/chain-service/constants.d.ts +1 -1
- package/services/chain-service/constants.js +4 -4
- package/services/chain-service/index.js +1 -0
- package/services/chain-service/utils/patch.d.ts +1 -1
- package/services/chain-service/utils/patch.js +1 -1
- package/services/migration-service/scripts/MigrateTransactionHistoryBySymbol20251223.d.ts +4 -0
- package/services/migration-service/scripts/MigrateTransactionHistoryBySymbol20251223.js +46 -0
- package/services/migration-service/scripts/databases/MigrateAssetSetting20251223.d.ts +4 -0
- package/services/migration-service/scripts/databases/MigrateAssetSetting20251223.js +33 -0
- package/services/migration-service/scripts/index.js +8 -4
- package/services/open-gov/interface.d.ts +4 -3
- package/services/substrate-proxy-service/constant.d.ts +3 -0
- package/services/substrate-proxy-service/constant.js +19 -0
- package/services/substrate-proxy-service/index.d.ts +13 -0
- package/services/substrate-proxy-service/index.js +159 -0
- package/services/transaction-service/index.js +79 -11
- package/services/transaction-service/types.d.ts +2 -2
- package/services/transaction-service/utils.js +8 -5
- package/types/balance/transfer.d.ts +1 -0
- package/types/index.d.ts +1 -0
- package/types/index.js +1 -0
- package/types/substrateProxyAccount/actions/index.d.ts +17 -0
- package/types/substrateProxyAccount/actions/index.js +1 -0
- package/types/substrateProxyAccount/index.d.ts +23 -0
- package/types/substrateProxyAccount/index.js +8 -0
- package/types/transaction/request.d.ts +1 -0
- package/types/yield/actions/join/submit.d.ts +1 -1
- package/utils/account/transform.js +5 -4
- package/utils/fee/transfer.js +4 -2
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
5
|
+
import { BasicTxErrorType } from '@subwallet/extension-base/types';
|
|
6
|
+
import { reformatAddress } from '@subwallet/extension-base/utils';
|
|
7
|
+
import BigN from 'bignumber.js';
|
|
8
|
+
import { txTypeToSubstrateProxyMap } from "./constant.js";
|
|
9
|
+
export default class SubstrateProxyAccountService {
|
|
10
|
+
constructor(state) {
|
|
11
|
+
this.state = state;
|
|
12
|
+
}
|
|
13
|
+
getSubstrateApi(chain) {
|
|
14
|
+
return this.state.getSubstrateApi(chain);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Get proxied accounts for a main account
|
|
18
|
+
// Get when view details or perform transaction
|
|
19
|
+
async getSubstrateProxyAccountGroup(request) {
|
|
20
|
+
var _substrateApi$api$con, _substrateApi$api$con2;
|
|
21
|
+
const {
|
|
22
|
+
address,
|
|
23
|
+
chain,
|
|
24
|
+
excludedSubstrateProxyAccounts,
|
|
25
|
+
type
|
|
26
|
+
} = request;
|
|
27
|
+
const substrateApi = this.getSubstrateApi(chain);
|
|
28
|
+
await substrateApi.isReady;
|
|
29
|
+
|
|
30
|
+
// Get proxied accounts from on-chain data
|
|
31
|
+
const result = await substrateApi.api.query.proxy.proxies(address);
|
|
32
|
+
const baseDeposit = ((_substrateApi$api$con = substrateApi.api.consts.proxy.proxyDepositBase) === null || _substrateApi$api$con === void 0 ? void 0 : _substrateApi$api$con.toString()) || '0';
|
|
33
|
+
const factorDeposit = ((_substrateApi$api$con2 = substrateApi.api.consts.proxy.proxyDepositFactor) === null || _substrateApi$api$con2 === void 0 ? void 0 : _substrateApi$api$con2.toString()) || '0';
|
|
34
|
+
const deposit = new BigN(baseDeposit).plus(factorDeposit);
|
|
35
|
+
const [_substrateProxyAccounts, currentSubstrateProxyDeposit] = result.toPrimitive();
|
|
36
|
+
|
|
37
|
+
// Mapping on-chain data to our defined type
|
|
38
|
+
let substrateProxyAccounts = (_substrateProxyAccounts || []).map(account => {
|
|
39
|
+
const proxyId = this.state.keyringService.context.belongUnifiedAccount(account.delegate) || reformatAddress(account.delegate);
|
|
40
|
+
return {
|
|
41
|
+
substrateProxyAddress: account.delegate,
|
|
42
|
+
substrateProxyType: account.proxyType,
|
|
43
|
+
delay: account.delay,
|
|
44
|
+
proxyId
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
if (type) {
|
|
48
|
+
const allowedSet = new Set([...(txTypeToSubstrateProxyMap[type] || []), 'Any']);
|
|
49
|
+
substrateProxyAccounts = substrateProxyAccounts.filter(p => allowedSet.has(p.substrateProxyType));
|
|
50
|
+
}
|
|
51
|
+
if (excludedSubstrateProxyAccounts && excludedSubstrateProxyAccounts.length > 0) {
|
|
52
|
+
substrateProxyAccounts = substrateProxyAccounts.filter(p => {
|
|
53
|
+
return !excludedSubstrateProxyAccounts.some(excluded => excluded.address === p.substrateProxyAddress && excluded.substrateProxyType === p.substrateProxyType);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
const estimateSubstrateProxyDeposit = new BigN(currentSubstrateProxyDeposit).plus(factorDeposit);
|
|
57
|
+
return {
|
|
58
|
+
substrateProxyAccounts,
|
|
59
|
+
substrateProxyDeposit: new BigN(currentSubstrateProxyDeposit).gt(0) ? estimateSubstrateProxyDeposit.toFixed() : deposit.toFixed()
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Linking proxy account with main account
|
|
64
|
+
async addSubstrateProxyAccounts(data) {
|
|
65
|
+
const {
|
|
66
|
+
address,
|
|
67
|
+
chain,
|
|
68
|
+
substrateProxyAddress,
|
|
69
|
+
substrateProxyType
|
|
70
|
+
} = data;
|
|
71
|
+
if (address === substrateProxyAddress) {
|
|
72
|
+
return Promise.reject(new TransactionError(BasicTxErrorType.INVALID_PARAMS));
|
|
73
|
+
}
|
|
74
|
+
const substrateApi = this.getSubstrateApi(chain);
|
|
75
|
+
await substrateApi.isReady;
|
|
76
|
+
|
|
77
|
+
// Currently we not support delay time
|
|
78
|
+
return substrateApi.api.tx.proxy.addProxy(substrateProxyAddress, substrateProxyType, 0);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Validate adding proxy account
|
|
82
|
+
async validateAddSubstrateProxyAccount(params, signerSubstrateProxyAddress) {
|
|
83
|
+
var _substrateApi$api$con3, _substrateApi$api$con4, _substrateApi$api$con5, _substrateApi$api$con6;
|
|
84
|
+
const {
|
|
85
|
+
address,
|
|
86
|
+
chain,
|
|
87
|
+
substrateProxyType
|
|
88
|
+
} = params;
|
|
89
|
+
const substrateApi = this.getSubstrateApi(chain);
|
|
90
|
+
await substrateApi.isReady;
|
|
91
|
+
const addProxyTx = substrateApi.api.tx.proxy.addProxy;
|
|
92
|
+
const proxyTypeArg = addProxyTx.meta.args.find(arg => arg.name.toString() === 'proxyType');
|
|
93
|
+
if (proxyTypeArg) {
|
|
94
|
+
const typeName = proxyTypeArg.type.toString();
|
|
95
|
+
const proxyTypeEnum = substrateApi.api.registry.createType(typeName);
|
|
96
|
+
const variants = proxyTypeEnum.defKeys;
|
|
97
|
+
if (!variants.includes(substrateProxyType)) {
|
|
98
|
+
return [new TransactionError(BasicTxErrorType.UNSUPPORTED, 'This proxy type is not supported on the chosen network. Select another one and try again')];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (!substrateApi.api.tx.proxy || !substrateApi.api.tx.proxy.addProxy) {
|
|
102
|
+
return [new TransactionError(BasicTxErrorType.UNSUPPORTED)];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Validate max proxies accounts limit
|
|
106
|
+
const maxSubstrateProxies = ((_substrateApi$api$con3 = substrateApi.api.consts.proxy.maxProxies) === null || _substrateApi$api$con3 === void 0 ? void 0 : (_substrateApi$api$con4 = _substrateApi$api$con3.toNumber) === null || _substrateApi$api$con4 === void 0 ? void 0 : _substrateApi$api$con4.call(_substrateApi$api$con3)) || 0;
|
|
107
|
+
const currentProxiesRaw = await substrateApi.api.query.proxy.proxies(address);
|
|
108
|
+
const [proxyList] = currentProxiesRaw.toPrimitive();
|
|
109
|
+
if (proxyList.length >= maxSubstrateProxies) {
|
|
110
|
+
return [new TransactionError(BasicTxErrorType.INVALID_PARAMS, `Maximum number of proxies reached: ${maxSubstrateProxies}`)];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Ensure enough balance for deposit + fee
|
|
114
|
+
const transferableBalance = await this.state.balanceService.getTransferableBalance(address, chain);
|
|
115
|
+
const bnTransferableBalance = new BigN(transferableBalance.value);
|
|
116
|
+
const feeInfo = await substrateApi.api.tx.proxy.addProxy(params.substrateProxyAddress, params.substrateProxyType, 0).paymentInfo(address);
|
|
117
|
+
const estimatedFee = new BigN(feeInfo.partialFee.toString());
|
|
118
|
+
const baseDeposit = ((_substrateApi$api$con5 = substrateApi.api.consts.proxy.proxyDepositBase) === null || _substrateApi$api$con5 === void 0 ? void 0 : _substrateApi$api$con5.toString()) || '0';
|
|
119
|
+
const factorDeposit = ((_substrateApi$api$con6 = substrateApi.api.consts.proxy.proxyDepositFactor) === null || _substrateApi$api$con6 === void 0 ? void 0 : _substrateApi$api$con6.toString()) || '0';
|
|
120
|
+
const requiredDeposit = proxyList.length === 0 ? new BigN(baseDeposit).plus(factorDeposit) : new BigN(factorDeposit);
|
|
121
|
+
const totalRequired = new BigN(requiredDeposit).plus(!signerSubstrateProxyAddress ? estimatedFee : 0);
|
|
122
|
+
if (bnTransferableBalance.lt(totalRequired)) {
|
|
123
|
+
return [new TransactionError(BasicTxErrorType.NOT_ENOUGH_BALANCE)];
|
|
124
|
+
}
|
|
125
|
+
return [];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Removing linked proxy accounts from main account
|
|
129
|
+
async removeSubstrateProxyAccounts(data) {
|
|
130
|
+
const {
|
|
131
|
+
chain,
|
|
132
|
+
isRemoveAll,
|
|
133
|
+
selectedSubstrateProxyAccounts
|
|
134
|
+
} = data;
|
|
135
|
+
const substrateApi = this.getSubstrateApi(chain);
|
|
136
|
+
await substrateApi.isReady;
|
|
137
|
+
const api = substrateApi.api;
|
|
138
|
+
if (isRemoveAll) {
|
|
139
|
+
return api.tx.proxy.removeProxies();
|
|
140
|
+
}
|
|
141
|
+
if (!selectedSubstrateProxyAccounts.length) {
|
|
142
|
+
return Promise.reject(new TransactionError(BasicTxErrorType.INVALID_PARAMS));
|
|
143
|
+
}
|
|
144
|
+
if (selectedSubstrateProxyAccounts.length === 1) {
|
|
145
|
+
const {
|
|
146
|
+
delay,
|
|
147
|
+
substrateProxyAddress,
|
|
148
|
+
substrateProxyType
|
|
149
|
+
} = selectedSubstrateProxyAccounts[0];
|
|
150
|
+
return api.tx.proxy.removeProxy(substrateProxyAddress, substrateProxyType, delay);
|
|
151
|
+
}
|
|
152
|
+
const removeProxies = selectedSubstrateProxyAccounts.map(({
|
|
153
|
+
delay,
|
|
154
|
+
substrateProxyAddress,
|
|
155
|
+
substrateProxyType
|
|
156
|
+
}) => api.tx.proxy.removeProxy(substrateProxyAddress, substrateProxyType, delay));
|
|
157
|
+
return api.tx.utility.batchAll(removeProxies);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -15,7 +15,7 @@ import { getBaseTransactionInfo, getTransactionId, isBitcoinTransaction, isCarda
|
|
|
15
15
|
import { getExplorerLink, parseTransactionData } from '@subwallet/extension-base/services/transaction-service/utils';
|
|
16
16
|
import { isWalletConnectRequest } from '@subwallet/extension-base/services/wallet-connect-service/helpers';
|
|
17
17
|
import { BasicTxErrorType, StepStatus, YieldPoolType } from '@subwallet/extension-base/types';
|
|
18
|
-
import { anyNumberToBN, pairToAccount, reformatAddress } from '@subwallet/extension-base/utils';
|
|
18
|
+
import { anyNumberToBN, isSameAddress, pairToAccount, reformatAddress } from '@subwallet/extension-base/utils';
|
|
19
19
|
import { mergeTransactionAndSignature } from '@subwallet/extension-base/utils/eth/mergeTransactionAndSignature';
|
|
20
20
|
import { isContractAddress, parseContractInput } from '@subwallet/extension-base/utils/eth/parseTransaction';
|
|
21
21
|
import { getId } from '@subwallet/extension-base/utils/getId';
|
|
@@ -120,18 +120,26 @@ export default class TransactionService {
|
|
|
120
120
|
const isNonNativeTokenPayFee = tokenPayFeeSlug && !_isNativeTokenBySlug(tokenPayFeeSlug);
|
|
121
121
|
const nonNativeTokenPayFeeInfo = isNonNativeTokenPayFee ? this.state.chainService.getAssetBySlug(tokenPayFeeSlug) : undefined;
|
|
122
122
|
const priceMap = (await this.state.priceService.getPrice()).priceMap;
|
|
123
|
+
|
|
124
|
+
// Get signer account
|
|
125
|
+
let signer = address;
|
|
126
|
+
const signerSubstrateProxyAddress = transactionInput.signerSubstrateProxyAddress;
|
|
123
127
|
if (!transactionInput.skipFeeRecalculation) {
|
|
124
|
-
validationResponse.estimateFee = await estimateFeeForTransaction(validationResponse, transaction, chainInfo, evmApi, substrateApi, priceMap, feeInfo, nativeTokenInfo, nonNativeTokenPayFeeInfo, transactionInput.isTransferLocalTokenAndPayThatTokenAsFee);
|
|
128
|
+
validationResponse.estimateFee = await estimateFeeForTransaction(validationResponse, transaction, chainInfo, evmApi, substrateApi, priceMap, feeInfo, nativeTokenInfo, nonNativeTokenPayFeeInfo, transactionInput.isTransferLocalTokenAndPayThatTokenAsFee, signerSubstrateProxyAddress);
|
|
125
129
|
}
|
|
126
130
|
const chainInfoMap = this.state.chainService.getChainInfoMap();
|
|
131
|
+
let substrateProxyAccountNativeTokenAvailable;
|
|
132
|
+
if (signerSubstrateProxyAddress && !isSameAddress(signerSubstrateProxyAddress, address)) {
|
|
133
|
+
signer = signerSubstrateProxyAddress;
|
|
134
|
+
substrateProxyAccountNativeTokenAvailable = await this.state.balanceService.getTransferableBalance(signerSubstrateProxyAddress, chain, nativeTokenInfo.slug, extrinsicType);
|
|
135
|
+
}
|
|
127
136
|
|
|
128
137
|
// Check account signing transaction
|
|
129
|
-
|
|
130
|
-
checkSigningAccountForTransaction(validationResponse, chainInfoMap);
|
|
138
|
+
checkSigningAccountForTransaction(validationResponse, chainInfoMap, signer);
|
|
131
139
|
const nativeTokenAvailable = await this.state.balanceService.getBalanceByType(address, chain, nativeTokenInfo.slug, transactionInput.balanceType, extrinsicType);
|
|
132
140
|
|
|
133
141
|
// Check available balance against transaction fee
|
|
134
|
-
checkBalanceWithTransactionFee(validationResponse, transactionInput, nativeTokenInfo, nativeTokenAvailable);
|
|
142
|
+
checkBalanceWithTransactionFee(validationResponse, transactionInput, nativeTokenInfo, nativeTokenAvailable, substrateProxyAccountNativeTokenAvailable);
|
|
135
143
|
|
|
136
144
|
// Warnings Ton address if bounceable and not active
|
|
137
145
|
// if (transaction && isTonTransaction(transaction) && tonApi) {
|
|
@@ -746,8 +754,10 @@ export default class TransactionService {
|
|
|
746
754
|
// Will be added in next step
|
|
747
755
|
nonce: nonce !== null && nonce !== void 0 ? nonce : 0,
|
|
748
756
|
startBlock: startBlock || 0,
|
|
749
|
-
processId: (_transaction$step3 = transaction.step) === null || _transaction$step3 === void 0 ? void 0 : _transaction$step3.processId
|
|
757
|
+
processId: (_transaction$step3 = transaction.step) === null || _transaction$step3 === void 0 ? void 0 : _transaction$step3.processId,
|
|
758
|
+
substrateProxyAddresses: []
|
|
750
759
|
};
|
|
760
|
+
const substrateProxyHistories = [];
|
|
751
761
|
const nativeAsset = _getChainNativeTokenBasicInfo(chainInfo);
|
|
752
762
|
const baseNativeAmount = {
|
|
753
763
|
value: '0',
|
|
@@ -1114,6 +1124,55 @@ export default class TransactionService {
|
|
|
1114
1124
|
};
|
|
1115
1125
|
break;
|
|
1116
1126
|
}
|
|
1127
|
+
case ExtrinsicType.ADD_SUBSTRATE_PROXY_ACCOUNT:
|
|
1128
|
+
{
|
|
1129
|
+
const data = parseTransactionData(transaction.data);
|
|
1130
|
+
const substrateProxyAddress = data.substrateProxyAddress;
|
|
1131
|
+
historyItem.substrateProxyAddresses = [substrateProxyAddress];
|
|
1132
|
+
substrateProxyHistories.push({
|
|
1133
|
+
...historyItem,
|
|
1134
|
+
substrateProxyAddresses: [substrateProxyAddress]
|
|
1135
|
+
});
|
|
1136
|
+
try {
|
|
1137
|
+
const substrateProxyAccount = keyring.getPair(substrateProxyAddress);
|
|
1138
|
+
if (substrateProxyAccount) {
|
|
1139
|
+
substrateProxyHistories.push({
|
|
1140
|
+
...historyItem,
|
|
1141
|
+
address: substrateProxyAccount.address,
|
|
1142
|
+
direction: TransactionDirection.RECEIVED,
|
|
1143
|
+
substrateProxyAddresses: [substrateProxyAddress]
|
|
1144
|
+
});
|
|
1145
|
+
}
|
|
1146
|
+
} catch (e) {
|
|
1147
|
+
// skip
|
|
1148
|
+
}
|
|
1149
|
+
break;
|
|
1150
|
+
}
|
|
1151
|
+
case ExtrinsicType.REMOVE_SUBSTRATE_PROXY_ACCOUNT:
|
|
1152
|
+
{
|
|
1153
|
+
const data = parseTransactionData(transaction.data);
|
|
1154
|
+
for (const substrateProxyItem of data.selectedSubstrateProxyAccounts || []) {
|
|
1155
|
+
const substrateProxyAddress = substrateProxyItem.substrateProxyAddress;
|
|
1156
|
+
substrateProxyHistories.push({
|
|
1157
|
+
...historyItem,
|
|
1158
|
+
substrateProxyAddresses: [substrateProxyAddress]
|
|
1159
|
+
});
|
|
1160
|
+
try {
|
|
1161
|
+
const substrateProxyAccount = keyring.getPair(substrateProxyAddress);
|
|
1162
|
+
if (substrateProxyAccount) {
|
|
1163
|
+
substrateProxyHistories.push({
|
|
1164
|
+
...historyItem,
|
|
1165
|
+
address: substrateProxyAccount.address,
|
|
1166
|
+
direction: TransactionDirection.RECEIVED,
|
|
1167
|
+
substrateProxyAddresses: [substrateProxyAddress]
|
|
1168
|
+
});
|
|
1169
|
+
}
|
|
1170
|
+
} catch (e) {
|
|
1171
|
+
// skip
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
break;
|
|
1175
|
+
}
|
|
1117
1176
|
case ExtrinsicType.UNKNOWN:
|
|
1118
1177
|
break;
|
|
1119
1178
|
}
|
|
@@ -1141,7 +1200,7 @@ export default class TransactionService {
|
|
|
1141
1200
|
} catch (e) {
|
|
1142
1201
|
console.warn(e);
|
|
1143
1202
|
}
|
|
1144
|
-
return [historyItem];
|
|
1203
|
+
return [historyItem, ...substrateProxyHistories];
|
|
1145
1204
|
}
|
|
1146
1205
|
onSigned({
|
|
1147
1206
|
id
|
|
@@ -1721,12 +1780,13 @@ export default class TransactionService {
|
|
|
1721
1780
|
});
|
|
1722
1781
|
return emitter;
|
|
1723
1782
|
}
|
|
1724
|
-
signAndSendSubstrateTransaction({
|
|
1783
|
+
async signAndSendSubstrateTransaction({
|
|
1725
1784
|
address,
|
|
1726
1785
|
chain,
|
|
1727
1786
|
feeCustom,
|
|
1728
1787
|
id,
|
|
1729
1788
|
signAfterCreate,
|
|
1789
|
+
signerSubstrateProxyAddress,
|
|
1730
1790
|
step,
|
|
1731
1791
|
tokenPayFeeSlug,
|
|
1732
1792
|
transaction,
|
|
@@ -1743,7 +1803,15 @@ export default class TransactionService {
|
|
|
1743
1803
|
extrinsicHash: id,
|
|
1744
1804
|
processId: step === null || step === void 0 ? void 0 : step.processId
|
|
1745
1805
|
};
|
|
1746
|
-
|
|
1806
|
+
let extrinsic = transaction;
|
|
1807
|
+
let signer = address;
|
|
1808
|
+
if (signerSubstrateProxyAddress && signerSubstrateProxyAddress !== address) {
|
|
1809
|
+
const substrateApi = this.state.chainService.getSubstrateApi(chain);
|
|
1810
|
+
await substrateApi.isReady;
|
|
1811
|
+
signer = signerSubstrateProxyAddress;
|
|
1812
|
+
extrinsic = substrateApi.api.tx.proxy.proxy(address, null, transaction);
|
|
1813
|
+
}
|
|
1814
|
+
|
|
1747
1815
|
// const registry = extrinsic.registry;
|
|
1748
1816
|
// const signedExtensions = registry.signedExtensions;
|
|
1749
1817
|
|
|
@@ -1753,7 +1821,7 @@ export default class TransactionService {
|
|
|
1753
1821
|
const {
|
|
1754
1822
|
signature,
|
|
1755
1823
|
signedTransaction
|
|
1756
|
-
} = await this.state.requestService.signInternalTransaction(id,
|
|
1824
|
+
} = await this.state.requestService.signInternalTransaction(id, signer, url || EXTENSION_REQUEST_URL, payload, signAfterCreate);
|
|
1757
1825
|
return {
|
|
1758
1826
|
id: new Date().getTime(),
|
|
1759
1827
|
signature,
|
|
@@ -1775,7 +1843,7 @@ export default class TransactionService {
|
|
|
1775
1843
|
// }
|
|
1776
1844
|
// }
|
|
1777
1845
|
|
|
1778
|
-
extrinsic.signAsync(
|
|
1846
|
+
extrinsic.signAsync(signer, signerOption).then(async rs => {
|
|
1779
1847
|
// Emit signed event
|
|
1780
1848
|
emitter.emit('signed', eventData);
|
|
1781
1849
|
|
|
@@ -8,7 +8,7 @@ import EventEmitter from 'eventemitter3';
|
|
|
8
8
|
import { TransactionConfig } from 'web3-core';
|
|
9
9
|
import { SubmittableExtrinsic } from '@polkadot/api/promise/types';
|
|
10
10
|
import { EventRecord } from '@polkadot/types/interfaces';
|
|
11
|
-
export interface SWTransactionBase extends ValidateTransactionResponse, Partial<Pick<BaseRequestSign, 'ignoreWarnings'>>, TransactionFee, SWTransactionEmitter {
|
|
11
|
+
export interface SWTransactionBase extends ValidateTransactionResponse, Partial<Pick<BaseRequestSign, 'ignoreWarnings' | 'signerSubstrateProxyAddress'>>, TransactionFee, SWTransactionEmitter {
|
|
12
12
|
id: string;
|
|
13
13
|
url?: string;
|
|
14
14
|
isInternal: boolean;
|
|
@@ -50,7 +50,7 @@ export interface SWTransactionEmitter {
|
|
|
50
50
|
emitterTransaction?: TransactionEmitter;
|
|
51
51
|
}
|
|
52
52
|
declare type SwInputBase = Pick<SWTransactionBase, 'address' | 'url' | 'data' | 'extrinsicType' | 'chain' | 'chainType' | 'ignoreWarnings' | 'transferNativeAmount'> & Partial<Pick<SWTransactionBase, 'additionalValidator' | 'eventsHandler'>>;
|
|
53
|
-
export interface SWTransactionInput extends SwInputBase, Partial<Pick<SWTransactionBase, 'estimateFee' | 'signAfterCreate' | 'isPassConfirmation' | 'step' | 'errorOnTimeOut' | 'xcmFeeDryRun'>>, TransactionFee {
|
|
53
|
+
export interface SWTransactionInput extends SwInputBase, Partial<Pick<SWTransactionBase, 'estimateFee' | 'signAfterCreate' | 'isPassConfirmation' | 'step' | 'errorOnTimeOut' | 'xcmFeeDryRun' | 'signerSubstrateProxyAddress'>>, TransactionFee {
|
|
54
54
|
id?: string;
|
|
55
55
|
transaction?: SWTransactionBase['transaction'] | null;
|
|
56
56
|
warnings?: SWTransactionBase['warnings'];
|
|
@@ -25,6 +25,9 @@ function getBlockExplorerAccountRoute(explorerLink) {
|
|
|
25
25
|
if (explorerLink.includes('devnet-explorer.mosaicchain.io')) {
|
|
26
26
|
return 'accounts';
|
|
27
27
|
}
|
|
28
|
+
if (explorerLink.includes('mainnet-gw2.mosaicchain.io')) {
|
|
29
|
+
return 'accounts';
|
|
30
|
+
}
|
|
28
31
|
if (explorerLink.includes('statescan.io')) {
|
|
29
32
|
return '#/accounts';
|
|
30
33
|
}
|
|
@@ -53,7 +56,7 @@ function getBlockExplorerAccountRoute(explorerLink) {
|
|
|
53
56
|
return 'account';
|
|
54
57
|
}
|
|
55
58
|
if (explorerLink.includes('node.xode.net')) {
|
|
56
|
-
return 'account';
|
|
59
|
+
return 'polkadot/account';
|
|
57
60
|
}
|
|
58
61
|
if (explorerLink.includes('tonviewer.com')) {
|
|
59
62
|
return '';
|
|
@@ -82,7 +85,10 @@ function getBlockExplorerTxRoute(chainInfo) {
|
|
|
82
85
|
if (['edgeware', 'commune'].includes(chainInfo.slug)) {
|
|
83
86
|
return 'extrinsics';
|
|
84
87
|
}
|
|
85
|
-
if (['
|
|
88
|
+
if (['xode'].includes(chainInfo.slug)) {
|
|
89
|
+
return 'polkadot/extrinsics';
|
|
90
|
+
}
|
|
91
|
+
if (['mosaicTest', 'polkadex', 'mosaic'].includes(chainInfo.slug)) {
|
|
86
92
|
return 'transactions';
|
|
87
93
|
}
|
|
88
94
|
const explorerLink = _getBlockExplorerFromChain(chainInfo);
|
|
@@ -126,9 +132,6 @@ export function getExplorerLink(chainInfo, value, type) {
|
|
|
126
132
|
if (chainInfo.slug === 'tangle') {
|
|
127
133
|
return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}extrinsic/${value}${route}/${value}`;
|
|
128
134
|
}
|
|
129
|
-
if (chainInfo.slug === 'xode') {
|
|
130
|
-
return `${explorerLink}${explorerLink.endsWith('/') ? '' : '/'}polkadot-chain-transaction?search=${value}`;
|
|
131
|
-
}
|
|
132
135
|
if (['truth_network', 'aventus'].includes(chainInfo.slug)) {
|
|
133
136
|
// getTransactionId(value)
|
|
134
137
|
// .then((transactionId) => {
|
|
@@ -18,6 +18,7 @@ export interface ResponseSubscribeTransfer {
|
|
|
18
18
|
feePercentageSpecialCase?: number;
|
|
19
19
|
error?: string;
|
|
20
20
|
isEvmRpcError?: boolean;
|
|
21
|
+
maxTransferableWithoutFee: string;
|
|
21
22
|
}
|
|
22
23
|
export interface RequestSubmitTransferWithId extends RequestSubmitTransfer {
|
|
23
24
|
id?: string;
|
package/types/index.d.ts
CHANGED
package/types/index.js
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BaseRequestSign, InternalRequestSign } from '../../transaction';
|
|
2
|
+
import { SubstrateProxyAccountItem, SubstrateProxyType } from '..';
|
|
3
|
+
export interface AddSubstrateProxyAccountParams extends BaseRequestSign {
|
|
4
|
+
address: string;
|
|
5
|
+
chain: string;
|
|
6
|
+
substrateProxyAddress: string;
|
|
7
|
+
substrateProxyType: SubstrateProxyType;
|
|
8
|
+
substrateProxyDeposit: string;
|
|
9
|
+
}
|
|
10
|
+
export declare type RequestAddSubstrateProxyAccount = InternalRequestSign<AddSubstrateProxyAccountParams>;
|
|
11
|
+
export interface RemoveSubstrateProxyAccountParams extends BaseRequestSign {
|
|
12
|
+
address: string;
|
|
13
|
+
chain: string;
|
|
14
|
+
selectedSubstrateProxyAccounts: SubstrateProxyAccountItem[];
|
|
15
|
+
isRemoveAll?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare type RequestRemoveSubstrateProxyAccount = InternalRequestSign<RemoveSubstrateProxyAccountParams>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
2
|
+
export interface ExcludedSubstrateProxyAccounts {
|
|
3
|
+
address: string;
|
|
4
|
+
substrateProxyType: SubstrateProxyType;
|
|
5
|
+
}
|
|
6
|
+
export interface RequestGetSubstrateProxyAccountGroup {
|
|
7
|
+
chain: string;
|
|
8
|
+
address: string;
|
|
9
|
+
type?: ExtrinsicType;
|
|
10
|
+
excludedSubstrateProxyAccounts?: ExcludedSubstrateProxyAccounts[];
|
|
11
|
+
}
|
|
12
|
+
export declare type SubstrateProxyType = 'Any' | 'NonTransfer' | 'Governance' | 'Staking';
|
|
13
|
+
export interface SubstrateProxyAccountItem {
|
|
14
|
+
substrateProxyAddress: string;
|
|
15
|
+
substrateProxyType: SubstrateProxyType;
|
|
16
|
+
delay: number;
|
|
17
|
+
proxyId?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface SubstrateProxyAccountGroup {
|
|
20
|
+
substrateProxyAccounts: SubstrateProxyAccountItem[];
|
|
21
|
+
substrateProxyDeposit: string;
|
|
22
|
+
}
|
|
23
|
+
export * from './actions';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
// All possible proxy types in Substrate in this article: https://wiki.polkadot.com/learn/learn-proxies/#proxy-types
|
|
5
|
+
// Only support these 4 types for now
|
|
6
|
+
|
|
7
|
+
export * from "./actions/index.js";
|
|
8
|
+
export {};
|
|
@@ -2,6 +2,7 @@ import { TransactionFee } from '../fee';
|
|
|
2
2
|
import { TransactionWarningType } from './warning';
|
|
3
3
|
export declare type BaseRequestSign = {
|
|
4
4
|
ignoreWarnings?: TransactionWarningType[];
|
|
5
|
+
signerSubstrateProxyAddress?: string;
|
|
5
6
|
};
|
|
6
7
|
export declare type InternalRequestSign<T> = T & BaseRequestSign;
|
|
7
8
|
export interface RequestBaseTransfer {
|
|
@@ -86,7 +86,7 @@ export interface BondingSubmitParams extends BaseRequestSign {
|
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
88
|
export declare type RequestBondingSubmit = InternalRequestSign<BondingSubmitParams>;
|
|
89
|
-
export declare type SubmitChangeValidatorStaking = SubmitBittensorChangeValidatorStaking | SubmitJoinNativeStaking
|
|
89
|
+
export declare type SubmitChangeValidatorStaking = InternalRequestSign<SubmitBittensorChangeValidatorStaking | SubmitJoinNativeStaking>;
|
|
90
90
|
export interface SubmitBittensorChangeValidatorStaking extends SubmitJoinNativeStaking {
|
|
91
91
|
originValidator: string;
|
|
92
92
|
maxAmount: string;
|
|
@@ -157,14 +157,15 @@ const EARN_VMANTA_ACTIONS = [ExtrinsicType.MINT_VMANTA, ExtrinsicType.REDEEM_VMA
|
|
|
157
157
|
const EVM_ACTIONS = [ExtrinsicType.TOKEN_SPENDING_APPROVAL, ExtrinsicType.EVM_EXECUTE];
|
|
158
158
|
const CLAIM_AVAIL_BRIDGE = [ExtrinsicType.CLAIM_BRIDGE];
|
|
159
159
|
const OPEN_GOV_ACTIONS = [ExtrinsicType.GOV_VOTE, ExtrinsicType.GOV_UNVOTE, ExtrinsicType.GOV_UNLOCK_VOTE];
|
|
160
|
+
const SUBSTRATE_PROXY_ACTION = [ExtrinsicType.ADD_SUBSTRATE_PROXY_ACCOUNT, ExtrinsicType.REMOVE_SUBSTRATE_PROXY_ACCOUNT];
|
|
160
161
|
const OTHER_ACTIONS = [ExtrinsicType.TRANSFER_XCM, ExtrinsicType.SEND_NFT, ExtrinsicType.SWAP, ExtrinsicType.CROWDLOAN];
|
|
161
162
|
export const getAccountTransactionActions = (signMode, networkType, type, _meta, _specialNetwork) => {
|
|
162
163
|
if ([AccountSignMode.PASSWORD, AccountSignMode.INJECTED].includes(signMode)) {
|
|
163
164
|
switch (networkType) {
|
|
164
165
|
case AccountChainType.SUBSTRATE:
|
|
165
|
-
return [...BASE_TRANSFER_ACTIONS, ...NATIVE_STAKE_ACTIONS, ...POOL_STAKE_ACTIONS, ...EARN_VDOT_ACTIONS, ...EARN_LDOT_ACTIONS, ...EARN_SDOT_ACTIONS, ...EARN_QDOT_ACTIONS, ...EARN_VMANTA_ACTIONS, ...CLAIM_AVAIL_BRIDGE, ...OPEN_GOV_ACTIONS, ...OTHER_ACTIONS];
|
|
166
|
+
return [...BASE_TRANSFER_ACTIONS, ...NATIVE_STAKE_ACTIONS, ...POOL_STAKE_ACTIONS, ...EARN_VDOT_ACTIONS, ...EARN_LDOT_ACTIONS, ...EARN_SDOT_ACTIONS, ...EARN_QDOT_ACTIONS, ...EARN_VMANTA_ACTIONS, ...CLAIM_AVAIL_BRIDGE, ...OPEN_GOV_ACTIONS, ...SUBSTRATE_PROXY_ACTION, ...OTHER_ACTIONS];
|
|
166
167
|
case AccountChainType.ETHEREUM:
|
|
167
|
-
return [...BASE_TRANSFER_ACTIONS, ...NATIVE_STAKE_ACTIONS, ...POOL_STAKE_ACTIONS, ...EARN_STDOT_ACTIONS, ...OTHER_ACTIONS, ...CLAIM_AVAIL_BRIDGE, ...EVM_ACTIONS];
|
|
168
|
+
return [...BASE_TRANSFER_ACTIONS, ...NATIVE_STAKE_ACTIONS, ...POOL_STAKE_ACTIONS, ...EARN_STDOT_ACTIONS, ...OTHER_ACTIONS, ...CLAIM_AVAIL_BRIDGE, ...SUBSTRATE_PROXY_ACTION, ...EVM_ACTIONS];
|
|
168
169
|
case AccountChainType.TON:
|
|
169
170
|
return [...BASE_TRANSFER_ACTIONS];
|
|
170
171
|
case AccountChainType.CARDANO:
|
|
@@ -175,7 +176,7 @@ export const getAccountTransactionActions = (signMode, networkType, type, _meta,
|
|
|
175
176
|
} else if (signMode === AccountSignMode.QR) {
|
|
176
177
|
switch (networkType) {
|
|
177
178
|
case AccountChainType.SUBSTRATE:
|
|
178
|
-
return [...BASE_TRANSFER_ACTIONS, ...NATIVE_STAKE_ACTIONS, ...POOL_STAKE_ACTIONS, ...EARN_VDOT_ACTIONS, ...EARN_LDOT_ACTIONS, ...EARN_SDOT_ACTIONS, ...EARN_QDOT_ACTIONS, ...EARN_VMANTA_ACTIONS, ...CLAIM_AVAIL_BRIDGE, ...OPEN_GOV_ACTIONS, ...OTHER_ACTIONS];
|
|
179
|
+
return [...BASE_TRANSFER_ACTIONS, ...NATIVE_STAKE_ACTIONS, ...POOL_STAKE_ACTIONS, ...EARN_VDOT_ACTIONS, ...EARN_LDOT_ACTIONS, ...EARN_SDOT_ACTIONS, ...EARN_QDOT_ACTIONS, ...EARN_VMANTA_ACTIONS, ...CLAIM_AVAIL_BRIDGE, ...OPEN_GOV_ACTIONS, ...SUBSTRATE_PROXY_ACTION, ...OTHER_ACTIONS];
|
|
179
180
|
case AccountChainType.ETHEREUM:
|
|
180
181
|
return [...(isProductionMode ? [] : [...BASE_TRANSFER_ACTIONS, ...NATIVE_STAKE_ACTIONS, ...POOL_STAKE_ACTIONS, ...EARN_STDOT_ACTIONS, ...CLAIM_AVAIL_BRIDGE, ...OTHER_ACTIONS, ...EVM_ACTIONS])];
|
|
181
182
|
case AccountChainType.TON:
|
|
@@ -190,7 +191,7 @@ export const getAccountTransactionActions = (signMode, networkType, type, _meta,
|
|
|
190
191
|
case AccountChainType.SUBSTRATE:
|
|
191
192
|
return [...BASE_TRANSFER_ACTIONS, ...NATIVE_STAKE_ACTIONS, ...POOL_STAKE_ACTIONS, ...EARN_VDOT_ACTIONS, ...EARN_VMANTA_ACTIONS, ...EARN_LDOT_ACTIONS, ...EARN_SDOT_ACTIONS,
|
|
192
193
|
// ...EARN_QDOT_ACTIONS,
|
|
193
|
-
...OPEN_GOV_ACTIONS, ...OTHER_ACTIONS];
|
|
194
|
+
...OPEN_GOV_ACTIONS, ...SUBSTRATE_PROXY_ACTION, ...OTHER_ACTIONS];
|
|
194
195
|
case AccountChainType.ETHEREUM:
|
|
195
196
|
return [...BASE_TRANSFER_ACTIONS, ...EARN_STDOT_ACTIONS, ...EVM_ACTIONS, ...CLAIM_AVAIL_BRIDGE, ExtrinsicType.STAKING_WITHDRAW,
|
|
196
197
|
// For liquid staking
|
package/utils/fee/transfer.js
CHANGED
|
@@ -319,7 +319,8 @@ export const calculateTransferMaxTransferable = async (id, request, freeBalance,
|
|
|
319
319
|
feeType: feeChainType,
|
|
320
320
|
id: id,
|
|
321
321
|
error,
|
|
322
|
-
isEvmRpcError: isEvmRpcError
|
|
322
|
+
isEvmRpcError: isEvmRpcError,
|
|
323
|
+
maxTransferableWithoutFee: freeBalance.value
|
|
323
324
|
};
|
|
324
325
|
};
|
|
325
326
|
export const calculateXcmMaxTransferable = async (id, request, freeBalance, fee) => {
|
|
@@ -510,7 +511,8 @@ export const calculateXcmMaxTransferable = async (id, request, freeBalance, fee)
|
|
|
510
511
|
feeOptions: feeOptions,
|
|
511
512
|
feeType: feeChainType,
|
|
512
513
|
id: id,
|
|
513
|
-
error
|
|
514
|
+
error,
|
|
515
|
+
maxTransferableWithoutFee: freeBalance.value
|
|
514
516
|
};
|
|
515
517
|
};
|
|
516
518
|
export const isEvmEIP1559FeeDetail = fee => {
|