@subwallet/extension-base 1.3.64-0 → 1.3.65-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/koni/background/handlers/State.js +1 -0
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/index.js +158 -16
- package/cjs/services/balance-service/transfer/xcm/acrossBridge/index.js +50 -4
- package/cjs/services/balance-service/transfer/xcm/index.js +7 -2
- package/cjs/services/chain-online-service/index.js +0 -3
- package/cjs/services/chain-service/index.js +6 -1
- package/cjs/services/earning-service/constants/chains.js +0 -2
- package/cjs/services/earning-service/handlers/lending/interlay.js +1 -0
- package/cjs/services/earning-service/handlers/liquid-staking/acala.js +1 -1
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +1 -1
- package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +1 -0
- package/cjs/services/earning-service/handlers/native-staking/tanssi.js +65 -9
- package/cjs/services/migration-service/scripts/DeleteEarningData20251105.js +21 -0
- package/cjs/services/migration-service/scripts/OptimizeEnableToken.js +19 -0
- package/cjs/services/migration-service/scripts/index.js +5 -1
- package/cjs/utils/fee/transfer.js +1 -5
- package/koni/background/handlers/State.js +1 -0
- package/package.json +16 -6
- package/packageInfo.js +1 -1
- package/services/balance-service/index.d.ts +8 -0
- package/services/balance-service/index.js +158 -17
- package/services/balance-service/transfer/xcm/acrossBridge/index.d.ts +2 -0
- package/services/balance-service/transfer/xcm/acrossBridge/index.js +47 -2
- package/services/balance-service/transfer/xcm/index.js +7 -2
- package/services/chain-online-service/index.js +0 -3
- package/services/chain-service/index.d.ts +1 -0
- package/services/chain-service/index.js +6 -1
- package/services/earning-service/constants/chains.js +0 -2
- package/services/earning-service/handlers/lending/interlay.js +2 -0
- package/services/earning-service/handlers/liquid-staking/acala.js +1 -1
- package/services/earning-service/handlers/liquid-staking/bifrost.js +1 -1
- package/services/earning-service/handlers/liquid-staking/parallel.js +2 -0
- package/services/earning-service/handlers/native-staking/tanssi.js +62 -6
- package/services/migration-service/scripts/DeleteEarningData20251105.d.ts +4 -0
- package/services/migration-service/scripts/DeleteEarningData20251105.js +13 -0
- package/services/migration-service/scripts/OptimizeEnableToken.d.ts +4 -0
- package/services/migration-service/scripts/OptimizeEnableToken.js +11 -0
- package/services/migration-service/scripts/index.js +5 -1
- package/utils/fee/transfer.js +2 -6
- package/utils/staticData/buyTokenConfigs.json +0 -46
|
@@ -3,10 +3,33 @@
|
|
|
3
3
|
|
|
4
4
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
5
5
|
import { APIItemState, ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
|
+
import { _getAssetDecimals } from '@subwallet/extension-base/services/chain-service/utils';
|
|
6
7
|
import { BasicTxErrorType, EarningStatus } from '@subwallet/extension-base/types';
|
|
8
|
+
import { formatNumber } from '@subwallet/extension-base/utils';
|
|
7
9
|
import BigN from 'bignumber.js';
|
|
8
10
|
import { parseIdentity } from "../../utils/index.js";
|
|
9
11
|
import BaseParaNativeStakingPoolHandler from "./base-para.js";
|
|
12
|
+
// Constants
|
|
13
|
+
const sequencersPerAppchain = new BigN(5);
|
|
14
|
+
const rewardsForStakers = new BigN(0.8);
|
|
15
|
+
const blocksPerYear = new BigN(5256000); // 6 seconds block time hence 365 * 24 * 60 * 60 / 6 (5.256.000) blocks per year
|
|
16
|
+
|
|
17
|
+
function calculateCollatorApy(rewardsPerBlock, totalStake, nativeTokenDecimals) {
|
|
18
|
+
const rewardsPerChainPerYear = new BigN(rewardsPerBlock).times(blocksPerYear);
|
|
19
|
+
const rewardsPerSequencerPerYear = rewardsPerChainPerYear.div(sequencersPerAppchain);
|
|
20
|
+
const rewardsForStakersPerSequencerPerYear = rewardsPerSequencerPerYear.times(rewardsForStakers);
|
|
21
|
+
const formattedTotalStake = formatNumber(totalStake.toString(), nativeTokenDecimals);
|
|
22
|
+
if (formattedTotalStake === '0') {
|
|
23
|
+
return new BigN(0);
|
|
24
|
+
}
|
|
25
|
+
return rewardsForStakersPerSequencerPerYear.times(100).div(formattedTotalStake);
|
|
26
|
+
}
|
|
27
|
+
async function getActiveCollators(api) {
|
|
28
|
+
const collatorAssignment = await api.query.tanssiCollatorAssignment.collatorContainerChain();
|
|
29
|
+
const activeCollatorContainerChain = collatorAssignment.toPrimitive();
|
|
30
|
+
const activeCollators = Object.values(activeCollatorContainerChain.containerChains || {}).flat().map(c => c.toString());
|
|
31
|
+
return activeCollators;
|
|
32
|
+
}
|
|
10
33
|
function perbillToPercentBn(perbill) {
|
|
11
34
|
const raw = new BigN((perbill === null || perbill === void 0 ? void 0 : perbill.toString()) || '0');
|
|
12
35
|
const bnPercent = raw.multipliedBy(new BigN(100)).div(new BigN(1000000000));
|
|
@@ -124,9 +147,18 @@ export default class TanssiNativeStakingPoolHandler extends BaseParaNativeStakin
|
|
|
124
147
|
async subscribePoolInfo(callback) {
|
|
125
148
|
let cancel = false;
|
|
126
149
|
const defaultCallback = async () => {
|
|
127
|
-
const
|
|
128
|
-
const activeConfig = (await
|
|
150
|
+
const chainApi = await this.substrateApi.isReady;
|
|
151
|
+
const activeConfig = (await chainApi.api.query.collatorConfiguration.activeConfig()).toPrimitive();
|
|
129
152
|
const maxCollators = activeConfig.maxCollators;
|
|
153
|
+
const chainsToRewardOpt = await chainApi.api.query.inflationRewards.chainsToReward();
|
|
154
|
+
const chainsToReward = chainsToRewardOpt.toPrimitive();
|
|
155
|
+
const rewardsPerBlock = chainsToReward.rewardsPerChain;
|
|
156
|
+
const formatRewardsPerBlock = formatNumber(rewardsPerBlock, _getAssetDecimals(this.nativeToken));
|
|
157
|
+
const candidates = await chainApi.api.query.pooledStaking.sortedEligibleCandidates();
|
|
158
|
+
const activeCollators = await getActiveCollators(chainApi.api);
|
|
159
|
+
const decimals = _getAssetDecimals(this.nativeToken);
|
|
160
|
+
const apyList = candidates.filter(c => activeCollators.includes(c.candidate.toString())).map(c => calculateCollatorApy(formatRewardsPerBlock, new BigN(c.stake.toString()), decimals));
|
|
161
|
+
const totalApy = apyList.length ? BigN.max(...apyList).toNumber() : 0;
|
|
130
162
|
const data = {
|
|
131
163
|
...this.baseInfo,
|
|
132
164
|
type: this.type,
|
|
@@ -147,7 +179,8 @@ export default class TanssiNativeStakingPoolHandler extends BaseParaNativeStakin
|
|
|
147
179
|
},
|
|
148
180
|
era: 0,
|
|
149
181
|
eraTime: 6 / 3600,
|
|
150
|
-
unstakingPeriod: 12
|
|
182
|
+
unstakingPeriod: 12,
|
|
183
|
+
totalApy
|
|
151
184
|
}
|
|
152
185
|
};
|
|
153
186
|
if (!cancel) {
|
|
@@ -165,10 +198,10 @@ export default class TanssiNativeStakingPoolHandler extends BaseParaNativeStakin
|
|
|
165
198
|
/* Subscribe pool position */
|
|
166
199
|
|
|
167
200
|
async subscribePoolPosition(useAddresses, onUpdate) {
|
|
168
|
-
const substrateApi = this.substrateApi;
|
|
169
|
-
await substrateApi.isReady;
|
|
201
|
+
const substrateApi = await this.substrateApi.isReady;
|
|
170
202
|
let cancel = false;
|
|
171
203
|
const intervalIds = [];
|
|
204
|
+
const activeCollators = await getActiveCollators(substrateApi.api);
|
|
172
205
|
for (const delegator of useAddresses) {
|
|
173
206
|
const fetchAndUpdate = async () => {
|
|
174
207
|
if (cancel) {
|
|
@@ -230,6 +263,19 @@ export default class TanssiNativeStakingPoolHandler extends BaseParaNativeStakin
|
|
|
230
263
|
validatorMinStake: '0'
|
|
231
264
|
});
|
|
232
265
|
}
|
|
266
|
+
let status;
|
|
267
|
+
if (nominations.length === 0) {
|
|
268
|
+
status = EarningStatus.NOT_STAKING;
|
|
269
|
+
} else {
|
|
270
|
+
const activeCount = nominations.filter(n => activeCollators.includes(n.validatorAddress)).length;
|
|
271
|
+
if (activeCount === 0) {
|
|
272
|
+
status = EarningStatus.WAITING;
|
|
273
|
+
} else if (activeCount < nominations.length) {
|
|
274
|
+
status = EarningStatus.PARTIALLY_EARNING;
|
|
275
|
+
} else {
|
|
276
|
+
status = EarningStatus.EARNING_REWARD;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
233
279
|
onUpdate({
|
|
234
280
|
...this.baseInfo,
|
|
235
281
|
type: this.type,
|
|
@@ -238,7 +284,7 @@ export default class TanssiNativeStakingPoolHandler extends BaseParaNativeStakin
|
|
|
238
284
|
totalStake: bnTotalStake.toString(),
|
|
239
285
|
activeStake: bnActiveStake.toString(),
|
|
240
286
|
unstakeBalance: bnUnstakeBalance.toString(),
|
|
241
|
-
status
|
|
287
|
+
status,
|
|
242
288
|
isBondedBefore: nominations.length > 0,
|
|
243
289
|
nominations,
|
|
244
290
|
unstakings: [],
|
|
@@ -289,6 +335,11 @@ export default class TanssiNativeStakingPoolHandler extends BaseParaNativeStakin
|
|
|
289
335
|
candidateSummariesMap[address] = summary.toJSON();
|
|
290
336
|
});
|
|
291
337
|
const candidateAddresses = candidates.map(c => c.candidate.toString());
|
|
338
|
+
const activeCollators = await getActiveCollators(chainApi.api);
|
|
339
|
+
const chainsToRewardOpt = await chainApi.api.query.inflationRewards.chainsToReward();
|
|
340
|
+
const chainsToReward = chainsToRewardOpt.toPrimitive();
|
|
341
|
+
const rewardsPerBlock = chainsToReward.rewardsPerChain;
|
|
342
|
+
const formatRewardsPerBlock = formatNumber(rewardsPerBlock, _getAssetDecimals(this.nativeToken));
|
|
292
343
|
const targets = await Promise.all(candidates.map(async c => {
|
|
293
344
|
const address = c.candidate.toString();
|
|
294
345
|
const totalStake = new BigN(c.stake.toString());
|
|
@@ -299,6 +350,10 @@ export default class TanssiNativeStakingPoolHandler extends BaseParaNativeStakin
|
|
|
299
350
|
const ownStake = ownStakeInfo ? new BigN(ownStakeInfo.totalStake) : new BigN(0);
|
|
300
351
|
const otherStake = BigN.max(totalStake.minus(ownStake), 0);
|
|
301
352
|
const [identity, isReasonable] = await parseIdentity(this.substrateApi, address);
|
|
353
|
+
let apy = new BigN(0);
|
|
354
|
+
if (activeCollators.includes(address)) {
|
|
355
|
+
apy = calculateCollatorApy(formatRewardsPerBlock, totalStake, _getAssetDecimals(this.nativeToken));
|
|
356
|
+
}
|
|
302
357
|
const validator = {
|
|
303
358
|
address,
|
|
304
359
|
chain: this.chain,
|
|
@@ -311,6 +366,7 @@ export default class TanssiNativeStakingPoolHandler extends BaseParaNativeStakin
|
|
|
311
366
|
blocked: false,
|
|
312
367
|
isVerified: isReasonable,
|
|
313
368
|
isCrowded: false,
|
|
369
|
+
expectedReturn: apy.toNumber(),
|
|
314
370
|
identity
|
|
315
371
|
};
|
|
316
372
|
return validator;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
|
|
5
|
+
export default class DeleteEarningData20251105 extends BaseMigrationJob {
|
|
6
|
+
async run() {
|
|
7
|
+
try {
|
|
8
|
+
await this.state.dbService.deleteYieldPoolInfo(['DOT___native_staking___polkadot', 'DOT___nomination_pool___polkadot']);
|
|
9
|
+
} catch (e) {
|
|
10
|
+
console.error(e);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import BaseMigrationJob from '@subwallet/extension-base/services/migration-service/Base';
|
|
5
|
+
export default class OptimizeEnableToken extends BaseMigrationJob {
|
|
6
|
+
async run() {
|
|
7
|
+
// Reset the hasOptimizedTokens flag to allow re-optimize tokens
|
|
8
|
+
this.state.balanceService.enableOptimizeTokenPromise();
|
|
9
|
+
return Promise.resolve();
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -20,6 +20,7 @@ import DeleteChain from "./DeleteChain.js";
|
|
|
20
20
|
import DeleteChainStaking from "./DeleteChainStaking.js";
|
|
21
21
|
import DeleteEarningData from "./DeleteEarningData.js";
|
|
22
22
|
import DeleteEarningData20251010 from "./DeleteEarningData20251010.js";
|
|
23
|
+
import DeleteEarningData20251105 from "./DeleteEarningData20251105.js";
|
|
23
24
|
import DisableZeroBalanceTokens from "./DisableZeroBalanceTokens.js";
|
|
24
25
|
import EnableVaraChain from "./EnableVaraChain.js";
|
|
25
26
|
import MigrateAuthUrls from "./MigrateAuthUrls.js";
|
|
@@ -32,6 +33,7 @@ import MigrateTransactionHistoryBridge from "./MigrateTransactionHistoryBridge.j
|
|
|
32
33
|
import MigrateTransactionHistoryBySymbol from "./MigrateTransactionHistoryBySymbol.js";
|
|
33
34
|
import MigrateTransactionHistoryBySymbol20251027 from "./MigrateTransactionHistoryBySymbol20251027.js";
|
|
34
35
|
import MigrateWalletReference from "./MigrateWalletReference.js";
|
|
36
|
+
import OptimizeEnableToken from "./OptimizeEnableToken.js";
|
|
35
37
|
export const EVERYTIME = '__everytime__';
|
|
36
38
|
export const MYTHOS_MIGRATION_KEY = '1.3.21-01';
|
|
37
39
|
export default {
|
|
@@ -72,6 +74,8 @@ export default {
|
|
|
72
74
|
'1.3.42-01': MigrateNewUnifiedAccount,
|
|
73
75
|
'1.3.54-01': MigrateChainPatrol,
|
|
74
76
|
'1.3.62-01': DeleteEarningData20251010,
|
|
77
|
+
'1.3.58-01': OptimizeEnableToken,
|
|
75
78
|
'1.3.64-01': MigrateAssetSetting20251027,
|
|
76
|
-
'1.3.64-02': MigrateTransactionHistoryBySymbol20251027
|
|
79
|
+
'1.3.64-02': MigrateTransactionHistoryBySymbol20251027,
|
|
80
|
+
'1.3.65-01': DeleteEarningData20251105
|
|
77
81
|
};
|
package/utils/fee/transfer.js
CHANGED
|
@@ -10,7 +10,7 @@ import { getERC20TransactionObject, getEVMTransactionObject } from '@subwallet/e
|
|
|
10
10
|
import { createSubstrateExtrinsic } from '@subwallet/extension-base/services/balance-service/transfer/token';
|
|
11
11
|
import { createTonTransaction } from '@subwallet/extension-base/services/balance-service/transfer/ton-transfer';
|
|
12
12
|
import { createAcrossBridgeExtrinsic, createAvailBridgeExtrinsicFromAvail, createAvailBridgeTxFromEth, createPolygonBridgeExtrinsic, createSnowBridgeExtrinsic, createXcmExtrinsicV2 } from '@subwallet/extension-base/services/balance-service/transfer/xcm';
|
|
13
|
-
import { _isAcrossChainBridge, _isAcrossTestnetBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/acrossBridge';
|
|
13
|
+
import { _isAcrossChainBridge, _isAcrossTestnetBridge, getAcrossSendingValue } from '@subwallet/extension-base/services/balance-service/transfer/xcm/acrossBridge';
|
|
14
14
|
import { isAvailChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/availBridge';
|
|
15
15
|
import { _isPolygonChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/polygonBridge';
|
|
16
16
|
import { _isPosChainBridge } from '@subwallet/extension-base/services/balance-service/transfer/xcm/posBridge';
|
|
@@ -375,11 +375,7 @@ export const calculateXcmMaxTransferable = async (id, request, freeBalance, fee)
|
|
|
375
375
|
funcCreateExtrinsic = createPolygonBridgeExtrinsic;
|
|
376
376
|
} else if (isAcrossBridgeTransfer) {
|
|
377
377
|
funcCreateExtrinsic = createAcrossBridgeExtrinsic;
|
|
378
|
-
|
|
379
|
-
params.sendingValue = BigN(0.0037).shiftedBy(_getAssetDecimals(srcToken)).toFixed(0, 1);
|
|
380
|
-
} else {
|
|
381
|
-
params.sendingValue = BigN(1).shiftedBy(_getAssetDecimals(srcToken)).toFixed(0, 1);
|
|
382
|
-
}
|
|
378
|
+
params.sendingValue = await getAcrossSendingValue(srcChain, srcToken, destChain, _isAcrossTestnetBridge(srcChain.slug));
|
|
383
379
|
} else if (isSnowBridgeEvmTransfer) {
|
|
384
380
|
funcCreateExtrinsic = createSnowBridgeExtrinsic;
|
|
385
381
|
} else if (isAvailBridgeFromEvm) {
|
|
@@ -1,50 +1,4 @@
|
|
|
1
1
|
[
|
|
2
|
-
{
|
|
3
|
-
"serviceInfo": {
|
|
4
|
-
"transak": {
|
|
5
|
-
"network": "mainnet",
|
|
6
|
-
"symbol": "DOT",
|
|
7
|
-
"isSuspended": false
|
|
8
|
-
},
|
|
9
|
-
"banxa": {
|
|
10
|
-
"network": "DOT",
|
|
11
|
-
"symbol": "DOT",
|
|
12
|
-
"isSuspended": false
|
|
13
|
-
},
|
|
14
|
-
"coinbase": {
|
|
15
|
-
"network": "polkadot",
|
|
16
|
-
"symbol": "DOT",
|
|
17
|
-
"isSuspended": false
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
"network": "polkadot",
|
|
21
|
-
"slug": "polkadot-NATIVE-DOT",
|
|
22
|
-
"symbol": "DOT",
|
|
23
|
-
"support": "SUBSTRATE"
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
"serviceInfo": {
|
|
27
|
-
"transak": {
|
|
28
|
-
"network": "mainnet",
|
|
29
|
-
"symbol": "KSM",
|
|
30
|
-
"isSuspended": false
|
|
31
|
-
},
|
|
32
|
-
"banxa": {
|
|
33
|
-
"network": "KSM",
|
|
34
|
-
"symbol": "KSM",
|
|
35
|
-
"isSuspended": false
|
|
36
|
-
},
|
|
37
|
-
"coinbase": {
|
|
38
|
-
"network": "kusama",
|
|
39
|
-
"symbol": "KSM",
|
|
40
|
-
"isSuspended": false
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
"network": "kusama",
|
|
44
|
-
"slug": "kusama-NATIVE-KSM",
|
|
45
|
-
"symbol": "KSM",
|
|
46
|
-
"support": "SUBSTRATE"
|
|
47
|
-
},
|
|
48
2
|
{
|
|
49
3
|
"serviceInfo": {
|
|
50
4
|
"transak": {
|