@subwallet/extension-base 1.3.62-0 → 1.3.64-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/api/staking/bonding/utils.js +6 -0
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/transfer/smart-contract.js +14 -10
- package/cjs/services/balance-service/transfer/xcm/acrossBridge/index.js +0 -6
- package/cjs/services/balance-service/transfer/xcm/utils.js +2 -0
- package/cjs/services/chain-service/constants.js +16 -0
- package/cjs/services/chain-service/utils/index.js +24 -4
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/earning-service/constants/chains.js +2 -1
- package/cjs/services/earning-service/handlers/native-staking/base-para.js +6 -3
- package/cjs/services/earning-service/handlers/native-staking/energy.js +60 -6
- package/cjs/services/earning-service/handlers/native-staking/tanssi.js +496 -0
- package/cjs/services/earning-service/service.js +4 -0
- package/cjs/services/earning-service/utils/index.js +2 -0
- package/cjs/services/migration-service/scripts/MigrateTransactionHistoryBySymbol20251027.js +51 -0
- package/cjs/services/migration-service/scripts/databases/MigrateAssetSetting20251027.js +37 -0
- package/cjs/services/migration-service/scripts/index.js +5 -1
- package/cjs/services/swap-service/handler/base-handler.js +4 -1
- package/cjs/services/swap-service/handler/chainflip-handler.js +1 -17
- package/cjs/services/swap-service/handler/optimex-handler.js +421 -0
- package/cjs/services/swap-service/handler/simpleswap-handler.js +4 -2
- package/cjs/services/swap-service/index.js +38 -140
- package/cjs/services/swap-service/utils.js +16 -157
- package/cjs/services/transaction-service/helpers/index.js +2 -1
- package/cjs/types/service-base.js +0 -1
- package/cjs/types/swap/index.js +5 -8
- package/cjs/utils/account/common.js +1 -2
- package/koni/api/staking/bonding/utils.d.ts +1 -0
- package/koni/api/staking/bonding/utils.js +5 -0
- package/package.json +26 -6
- package/packageInfo.js +1 -1
- package/services/balance-service/transfer/smart-contract.d.ts +3 -2
- package/services/balance-service/transfer/smart-contract.js +35 -29
- package/services/balance-service/transfer/xcm/acrossBridge/index.d.ts +0 -4
- package/services/balance-service/transfer/xcm/acrossBridge/index.js +0 -4
- package/services/balance-service/transfer/xcm/utils.js +2 -0
- package/services/chain-service/constants.js +16 -0
- package/services/chain-service/utils/index.d.ts +3 -2
- package/services/chain-service/utils/index.js +20 -1
- package/services/chain-service/utils/patch.d.ts +1 -1
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/constants/chains.d.ts +1 -0
- package/services/earning-service/constants/chains.js +2 -1
- package/services/earning-service/handlers/native-staking/base-para.js +6 -3
- package/services/earning-service/handlers/native-staking/energy.d.ts +6 -0
- package/services/earning-service/handlers/native-staking/energy.js +60 -8
- package/services/earning-service/handlers/native-staking/tanssi.d.ts +16 -0
- package/services/earning-service/handlers/native-staking/tanssi.js +478 -0
- package/services/earning-service/service.js +4 -0
- package/services/earning-service/utils/index.js +2 -0
- package/services/migration-service/scripts/MigrateTransactionHistoryBySymbol20251027.d.ts +4 -0
- package/services/migration-service/scripts/MigrateTransactionHistoryBySymbol20251027.js +42 -0
- package/services/migration-service/scripts/databases/MigrateAssetSetting20251027.d.ts +4 -0
- package/services/migration-service/scripts/databases/MigrateAssetSetting20251027.js +29 -0
- package/services/migration-service/scripts/index.js +5 -1
- package/services/swap-service/handler/base-handler.js +6 -3
- package/services/swap-service/handler/chainflip-handler.d.ts +0 -2
- package/services/swap-service/handler/chainflip-handler.js +2 -18
- package/services/swap-service/handler/optimex-handler.d.ts +43 -0
- package/services/swap-service/handler/optimex-handler.js +410 -0
- package/services/swap-service/handler/simpleswap-handler.js +5 -3
- package/services/swap-service/index.d.ts +0 -1
- package/services/swap-service/index.js +21 -123
- package/services/swap-service/utils.d.ts +6 -12
- package/services/swap-service/utils.js +8 -138
- package/services/transaction-service/helpers/index.js +2 -1
- package/types/service-base.d.ts +3 -4
- package/types/service-base.js +0 -2
- package/types/swap/index.d.ts +3 -1
- package/types/swap/index.js +7 -6
- package/types/yield/info/account/info.d.ts +5 -0
- package/utils/account/common.js +2 -3
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _TransactionError = require("@subwallet/extension-base/background/errors/TransactionError");
|
|
9
|
+
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
10
|
+
var _types = require("@subwallet/extension-base/types");
|
|
11
|
+
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
12
|
+
var _utils = require("../../utils");
|
|
13
|
+
var _basePara = _interopRequireDefault(require("./base-para"));
|
|
14
|
+
// Copyright 2019-2022 @subwallet/extension-base
|
|
15
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
16
|
+
|
|
17
|
+
function perbillToPercentBn(perbill) {
|
|
18
|
+
const raw = new _bignumber.default((perbill === null || perbill === void 0 ? void 0 : perbill.toString()) || '0');
|
|
19
|
+
const bnPercent = raw.multipliedBy(new _bignumber.default(100)).div(new _bignumber.default(1000000000));
|
|
20
|
+
return bnPercent.toNumber();
|
|
21
|
+
}
|
|
22
|
+
async function getOwnStakes(chainApi, candidates, delegator) {
|
|
23
|
+
const queries = [];
|
|
24
|
+
for (const candidate of candidates) {
|
|
25
|
+
// Auto-compounding
|
|
26
|
+
queries.push([candidate, {
|
|
27
|
+
AutoCompoundingShares: {
|
|
28
|
+
delegator
|
|
29
|
+
}
|
|
30
|
+
}]);
|
|
31
|
+
queries.push([candidate, 'AutoCompoundingSharesSupply']);
|
|
32
|
+
queries.push([candidate, 'AutoCompoundingSharesTotalStaked']);
|
|
33
|
+
|
|
34
|
+
// Manual rewards
|
|
35
|
+
queries.push([candidate, {
|
|
36
|
+
ManualRewardsShares: {
|
|
37
|
+
delegator
|
|
38
|
+
}
|
|
39
|
+
}]);
|
|
40
|
+
queries.push([candidate, 'ManualRewardsSharesSupply']);
|
|
41
|
+
queries.push([candidate, 'ManualRewardsSharesTotalStaked']);
|
|
42
|
+
|
|
43
|
+
// Joining
|
|
44
|
+
queries.push([candidate, {
|
|
45
|
+
JoiningShares: {
|
|
46
|
+
delegator
|
|
47
|
+
}
|
|
48
|
+
}]);
|
|
49
|
+
queries.push([candidate, 'JoiningSharesSupply']);
|
|
50
|
+
queries.push([candidate, 'JoiningSharesTotalStaked']);
|
|
51
|
+
|
|
52
|
+
// Leaving
|
|
53
|
+
queries.push([candidate, {
|
|
54
|
+
LeavingShares: {
|
|
55
|
+
delegator
|
|
56
|
+
}
|
|
57
|
+
}]);
|
|
58
|
+
queries.push([candidate, 'LeavingSharesSupply']);
|
|
59
|
+
queries.push([candidate, 'LeavingSharesTotalStaked']);
|
|
60
|
+
|
|
61
|
+
// Claimable reward
|
|
62
|
+
queries.push([candidate, 'ManualRewardsCounter']);
|
|
63
|
+
queries.push([candidate, {
|
|
64
|
+
ManualRewardsCheckpoint: {
|
|
65
|
+
delegator
|
|
66
|
+
}
|
|
67
|
+
}]);
|
|
68
|
+
}
|
|
69
|
+
const results = await chainApi.api.query.pooledStaking.pools.multi(queries);
|
|
70
|
+
const stakes = {};
|
|
71
|
+
const stride = 14;
|
|
72
|
+
for (let i = 0; i < candidates.length; i++) {
|
|
73
|
+
const base = i * stride;
|
|
74
|
+
|
|
75
|
+
// Auto-compounding
|
|
76
|
+
const acShares = new _bignumber.default(results[base + 0].toString());
|
|
77
|
+
const acSupply = new _bignumber.default(results[base + 1].toString());
|
|
78
|
+
const acTotal = new _bignumber.default(results[base + 2].toString());
|
|
79
|
+
const autoCompounding = acSupply.isZero() ? new _bignumber.default(0) : acShares.multipliedBy(acTotal).div(acSupply);
|
|
80
|
+
|
|
81
|
+
// Manual rewards
|
|
82
|
+
const mrShares = new _bignumber.default(results[base + 3].toString());
|
|
83
|
+
const mrSupply = new _bignumber.default(results[base + 4].toString());
|
|
84
|
+
const mrTotal = new _bignumber.default(results[base + 5].toString());
|
|
85
|
+
const manualRewards = mrSupply.isZero() ? new _bignumber.default(0) : mrShares.multipliedBy(mrTotal).div(mrSupply);
|
|
86
|
+
|
|
87
|
+
// Joining
|
|
88
|
+
const jShares = new _bignumber.default(results[base + 6].toString());
|
|
89
|
+
const jSupply = new _bignumber.default(results[base + 7].toString());
|
|
90
|
+
const jTotal = new _bignumber.default(results[base + 8].toString());
|
|
91
|
+
const joining = jSupply.isZero() ? new _bignumber.default(0) : jShares.multipliedBy(jTotal).div(jSupply);
|
|
92
|
+
|
|
93
|
+
// Leaving
|
|
94
|
+
const lShares = new _bignumber.default(results[base + 9].toString());
|
|
95
|
+
const lSupply = new _bignumber.default(results[base + 10].toString());
|
|
96
|
+
const lTotal = new _bignumber.default(results[base + 11].toString());
|
|
97
|
+
const leaving = lSupply.isZero() ? new _bignumber.default(0) : lShares.multipliedBy(lTotal).div(lSupply);
|
|
98
|
+
|
|
99
|
+
// Claimable rewards
|
|
100
|
+
const counter = new _bignumber.default(results[base + 12].toString());
|
|
101
|
+
const checkpoint = new _bignumber.default(results[base + 13].toString());
|
|
102
|
+
const claimable = counter.minus(checkpoint).multipliedBy(mrShares);
|
|
103
|
+
|
|
104
|
+
// Total stake
|
|
105
|
+
const totalStake = autoCompounding.plus(manualRewards).plus(joining).plus(leaving);
|
|
106
|
+
stakes[candidates[i]] = {
|
|
107
|
+
autoCompounding: autoCompounding.toFixed(0),
|
|
108
|
+
autoCompoundingShares: acShares.toFixed(0),
|
|
109
|
+
manualRewards: manualRewards.toFixed(0),
|
|
110
|
+
joining: joining.toFixed(0),
|
|
111
|
+
leaving: leaving.toFixed(0),
|
|
112
|
+
totalStake: totalStake.toFixed(0),
|
|
113
|
+
claimable: claimable.toFixed(0)
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
return stakes;
|
|
117
|
+
}
|
|
118
|
+
class TanssiNativeStakingPoolHandler extends _basePara.default {
|
|
119
|
+
availableMethod = {
|
|
120
|
+
join: true,
|
|
121
|
+
defaultUnstake: true,
|
|
122
|
+
fastUnstake: false,
|
|
123
|
+
cancelUnstake: false,
|
|
124
|
+
withdraw: false,
|
|
125
|
+
claimReward: true,
|
|
126
|
+
changeValidator: false
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/* Subscribe pool info */
|
|
130
|
+
|
|
131
|
+
async subscribePoolInfo(callback) {
|
|
132
|
+
let cancel = false;
|
|
133
|
+
const defaultCallback = async () => {
|
|
134
|
+
const api = await this.substrateApi.isReady;
|
|
135
|
+
const activeConfig = (await api.api.query.collatorConfiguration.activeConfig()).toPrimitive();
|
|
136
|
+
const maxCollators = activeConfig.maxCollators;
|
|
137
|
+
const data = {
|
|
138
|
+
...this.baseInfo,
|
|
139
|
+
type: this.type,
|
|
140
|
+
metadata: {
|
|
141
|
+
...this.metadataInfo,
|
|
142
|
+
description: this.getDescription()
|
|
143
|
+
},
|
|
144
|
+
statistic: {
|
|
145
|
+
assetEarning: [{
|
|
146
|
+
slug: this.nativeToken.slug
|
|
147
|
+
}],
|
|
148
|
+
maxCandidatePerFarmer: maxCollators,
|
|
149
|
+
maxWithdrawalRequestPerFarmer: 1,
|
|
150
|
+
earningThreshold: {
|
|
151
|
+
join: '0',
|
|
152
|
+
defaultUnstake: '0',
|
|
153
|
+
fastUnstake: '0'
|
|
154
|
+
},
|
|
155
|
+
era: 0,
|
|
156
|
+
eraTime: 6 / 3600,
|
|
157
|
+
unstakingPeriod: 12
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
if (!cancel) {
|
|
161
|
+
callback(data);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
await defaultCallback();
|
|
165
|
+
return () => {
|
|
166
|
+
cancel = true;
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/* Subscribe pool info */
|
|
171
|
+
|
|
172
|
+
/* Subscribe pool position */
|
|
173
|
+
|
|
174
|
+
async subscribePoolPosition(useAddresses, onUpdate) {
|
|
175
|
+
const substrateApi = this.substrateApi;
|
|
176
|
+
await substrateApi.isReady;
|
|
177
|
+
let cancel = false;
|
|
178
|
+
const intervalIds = [];
|
|
179
|
+
for (const delegator of useAddresses) {
|
|
180
|
+
const fetchAndUpdate = async () => {
|
|
181
|
+
if (cancel) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
const entries = await substrateApi.api.query.pooledStaking.delegatorCandidateSummaries.entries(delegator);
|
|
185
|
+
if (!entries || entries.length === 0) {
|
|
186
|
+
onUpdate({
|
|
187
|
+
...this.baseInfo,
|
|
188
|
+
type: this.type,
|
|
189
|
+
address: delegator,
|
|
190
|
+
balanceToken: this.nativeToken.slug,
|
|
191
|
+
totalStake: '0',
|
|
192
|
+
activeStake: '0',
|
|
193
|
+
unstakeBalance: '0',
|
|
194
|
+
status: _types.EarningStatus.NOT_STAKING,
|
|
195
|
+
isBondedBefore: false,
|
|
196
|
+
nominations: [],
|
|
197
|
+
unstakings: []
|
|
198
|
+
});
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
const candidates = entries.map(_ref => {
|
|
202
|
+
let [storageKey] = _ref;
|
|
203
|
+
return storageKey.args[1].toString();
|
|
204
|
+
});
|
|
205
|
+
const ownStakesMap = await getOwnStakes(substrateApi, candidates, delegator);
|
|
206
|
+
const nominations = [];
|
|
207
|
+
let bnTotalStake = new _bignumber.default(0);
|
|
208
|
+
let bnActiveStake = new _bignumber.default(0);
|
|
209
|
+
let bnUnstakeBalance = new _bignumber.default(0);
|
|
210
|
+
let bnJoiningStake = new _bignumber.default(0);
|
|
211
|
+
let bnCompoundingStake = new _bignumber.default(0);
|
|
212
|
+
let bnManualStake = new _bignumber.default(0);
|
|
213
|
+
for (const candidate of candidates) {
|
|
214
|
+
const ownStake = ownStakesMap[candidate];
|
|
215
|
+
if (!ownStake) {
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
const autoCompounding = new _bignumber.default(ownStake.autoCompounding);
|
|
219
|
+
const manualRewards = new _bignumber.default(ownStake.manualRewards);
|
|
220
|
+
const joining = new _bignumber.default(ownStake.joining);
|
|
221
|
+
const leaving = new _bignumber.default(ownStake.leaving);
|
|
222
|
+
const totalStake = new _bignumber.default(ownStake.totalStake);
|
|
223
|
+
if (totalStake.isZero()) {
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
bnTotalStake = bnTotalStake.plus(totalStake);
|
|
227
|
+
bnActiveStake = bnActiveStake.plus(autoCompounding).plus(manualRewards).plus(joining);
|
|
228
|
+
bnUnstakeBalance = bnUnstakeBalance.plus(leaving);
|
|
229
|
+
bnJoiningStake = bnJoiningStake.plus(joining);
|
|
230
|
+
bnCompoundingStake = bnCompoundingStake.plus(autoCompounding);
|
|
231
|
+
bnManualStake = bnManualStake.plus(manualRewards);
|
|
232
|
+
const [identity] = await (0, _utils.parseIdentity)(this.substrateIdentityApi, candidate);
|
|
233
|
+
nominations.push({
|
|
234
|
+
chain: this.chain,
|
|
235
|
+
status: _types.EarningStatus.EARNING_REWARD,
|
|
236
|
+
validatorAddress: candidate,
|
|
237
|
+
validatorIdentity: identity,
|
|
238
|
+
activeStake: new _bignumber.default(autoCompounding).plus(manualRewards).toFixed(),
|
|
239
|
+
hasUnstaking: !leaving.isZero(),
|
|
240
|
+
validatorMinStake: '0'
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
onUpdate({
|
|
244
|
+
...this.baseInfo,
|
|
245
|
+
type: this.type,
|
|
246
|
+
address: delegator,
|
|
247
|
+
balanceToken: this.nativeToken.slug,
|
|
248
|
+
totalStake: bnTotalStake.toString(),
|
|
249
|
+
activeStake: bnActiveStake.toString(),
|
|
250
|
+
unstakeBalance: bnUnstakeBalance.toString(),
|
|
251
|
+
status: nominations.length > 0 ? _types.EarningStatus.EARNING_REWARD : _types.EarningStatus.NOT_STAKING,
|
|
252
|
+
isBondedBefore: nominations.length > 0,
|
|
253
|
+
nominations,
|
|
254
|
+
unstakings: [],
|
|
255
|
+
metadata: {
|
|
256
|
+
pendingStake: bnJoiningStake.toString(),
|
|
257
|
+
compoundingStake: bnCompoundingStake.toString(),
|
|
258
|
+
manualStake: bnManualStake.toString()
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
};
|
|
262
|
+
fetchAndUpdate().catch(console.error);
|
|
263
|
+
const intervalId = setInterval(() => {
|
|
264
|
+
fetchAndUpdate().catch(console.error);
|
|
265
|
+
}, 30000);
|
|
266
|
+
intervalIds.push(intervalId);
|
|
267
|
+
}
|
|
268
|
+
return () => {
|
|
269
|
+
cancel = true;
|
|
270
|
+
intervalIds.forEach(id => clearInterval(id));
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
async checkAccountHaveStake(addresses) {
|
|
274
|
+
const stakedAddresses = [];
|
|
275
|
+
const api = await this.substrateApi.isReady;
|
|
276
|
+
const candidateSummariesByAddress = await Promise.all(addresses.map(address => api.api.query.pooledStaking.delegatorCandidateSummaries.entries(address)));
|
|
277
|
+
for (let i = 0; i < addresses.length; i++) {
|
|
278
|
+
const candidateSummaries = candidateSummariesByAddress[i];
|
|
279
|
+
if (candidateSummaries && candidateSummaries.length > 0) {
|
|
280
|
+
stakedAddresses.push(addresses[i]);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return stakedAddresses;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/* Subscribe pool position */
|
|
287
|
+
|
|
288
|
+
/* Get pool targets */
|
|
289
|
+
|
|
290
|
+
async getPoolTargets() {
|
|
291
|
+
const chainApi = await this.substrateApi.isReady;
|
|
292
|
+
const commissionRaw = chainApi.api.consts.pooledStaking.rewardsCollatorCommission.toJSON();
|
|
293
|
+
const commission = perbillToPercentBn(commissionRaw);
|
|
294
|
+
const candidates = await chainApi.api.query.pooledStaking.sortedEligibleCandidates();
|
|
295
|
+
const candidateSummaries = await chainApi.api.query.pooledStaking.candidateSummaries.entries();
|
|
296
|
+
const candidateSummariesMap = {};
|
|
297
|
+
candidateSummaries.forEach(_ref2 => {
|
|
298
|
+
let [key, summary] = _ref2;
|
|
299
|
+
const address = key.args[0].toString();
|
|
300
|
+
candidateSummariesMap[address] = summary.toJSON();
|
|
301
|
+
});
|
|
302
|
+
const candidateAddresses = candidates.map(c => c.candidate.toString());
|
|
303
|
+
const targets = await Promise.all(candidates.map(async c => {
|
|
304
|
+
const address = c.candidate.toString();
|
|
305
|
+
const totalStake = new _bignumber.default(c.stake.toString());
|
|
306
|
+
const candidateInfo = candidateSummariesMap[address];
|
|
307
|
+
const nominatorCount = (candidateInfo === null || candidateInfo === void 0 ? void 0 : candidateInfo.delegators) || 0;
|
|
308
|
+
const ownStakesMap = await getOwnStakes(chainApi, candidateAddresses, address);
|
|
309
|
+
const ownStakeInfo = ownStakesMap[address];
|
|
310
|
+
const ownStake = ownStakeInfo ? new _bignumber.default(ownStakeInfo.totalStake) : new _bignumber.default(0);
|
|
311
|
+
const otherStake = _bignumber.default.max(totalStake.minus(ownStake), 0);
|
|
312
|
+
const [identity, isReasonable] = await (0, _utils.parseIdentity)(this.substrateApi, address);
|
|
313
|
+
const validator = {
|
|
314
|
+
address,
|
|
315
|
+
chain: this.chain,
|
|
316
|
+
totalStake: totalStake.toFixed(),
|
|
317
|
+
ownStake: ownStake.toFixed(),
|
|
318
|
+
otherStake: otherStake.toFixed(),
|
|
319
|
+
minBond: '0',
|
|
320
|
+
nominatorCount,
|
|
321
|
+
commission,
|
|
322
|
+
blocked: false,
|
|
323
|
+
isVerified: isReasonable,
|
|
324
|
+
isCrowded: false,
|
|
325
|
+
identity
|
|
326
|
+
};
|
|
327
|
+
return validator;
|
|
328
|
+
}));
|
|
329
|
+
return targets;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/* Get pool targets */
|
|
333
|
+
|
|
334
|
+
/* Join pool action */
|
|
335
|
+
|
|
336
|
+
async createJoinExtrinsic(data, positionInfo, bondDest, netuid) {
|
|
337
|
+
const {
|
|
338
|
+
amount,
|
|
339
|
+
selectedValidators
|
|
340
|
+
} = data;
|
|
341
|
+
const substrateApi = this.substrateApi;
|
|
342
|
+
const api = await substrateApi.isReady;
|
|
343
|
+
const binaryAmount = new _bignumber.default(amount);
|
|
344
|
+
const selectedCollatorInfo = selectedValidators[0];
|
|
345
|
+
const {
|
|
346
|
+
address: selectedCollatorAddress
|
|
347
|
+
} = selectedCollatorInfo;
|
|
348
|
+
const extrinsic = api.api.tx.pooledStaking.requestDelegate(selectedCollatorAddress, 'AutoCompounding',
|
|
349
|
+
// 'ManualRewards'
|
|
350
|
+
binaryAmount.toFixed());
|
|
351
|
+
return [extrinsic, {
|
|
352
|
+
slug: this.nativeToken.slug,
|
|
353
|
+
amount
|
|
354
|
+
}];
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/* Join pool action */
|
|
358
|
+
|
|
359
|
+
/* Leave pool action */
|
|
360
|
+
|
|
361
|
+
async handleYieldUnstake(amount, address, selectedTarget) {
|
|
362
|
+
if (!selectedTarget) {
|
|
363
|
+
return Promise.reject(new _TransactionError.TransactionError(_types.BasicTxErrorType.INVALID_PARAMS));
|
|
364
|
+
}
|
|
365
|
+
const substrateApi = await this.substrateApi.isReady;
|
|
366
|
+
const txs = [];
|
|
367
|
+
const stakesMap = await getOwnStakes(substrateApi, [selectedTarget], address);
|
|
368
|
+
const stakeInfo = stakesMap[selectedTarget];
|
|
369
|
+
const manualRewards = new _bignumber.default(stakeInfo.manualRewards);
|
|
370
|
+
const autoCompounding = new _bignumber.default(stakeInfo.autoCompounding);
|
|
371
|
+
const unstakeAmount = new _bignumber.default(amount);
|
|
372
|
+
if (manualRewards.gt(0)) {
|
|
373
|
+
if (unstakeAmount.lte(manualRewards)) {
|
|
374
|
+
txs.push(substrateApi.api.tx.pooledStaking.requestUndelegate(selectedTarget, 'ManualRewards', {
|
|
375
|
+
Stake: unstakeAmount.toFixed()
|
|
376
|
+
}));
|
|
377
|
+
} else {
|
|
378
|
+
txs.push(substrateApi.api.tx.pooledStaking.requestUndelegate(selectedTarget, 'ManualRewards', {
|
|
379
|
+
Stake: manualRewards.toFixed()
|
|
380
|
+
}));
|
|
381
|
+
const remaining = unstakeAmount.minus(manualRewards);
|
|
382
|
+
if (remaining.gt(0)) {
|
|
383
|
+
const acShares = new _bignumber.default(stakeInfo.autoCompoundingShares || '0');
|
|
384
|
+
// Unstake all: use Shares to avoid small leftovers as rewards are automatically compounded every 6 seconds
|
|
385
|
+
const isUnstakeAll = remaining.gte(autoCompounding.multipliedBy(0.9999));
|
|
386
|
+
txs.push(substrateApi.api.tx.pooledStaking.requestUndelegate(selectedTarget, 'AutoCompounding', isUnstakeAll ? {
|
|
387
|
+
Shares: acShares.toFixed(0)
|
|
388
|
+
} : {
|
|
389
|
+
Stake: remaining.toFixed(0)
|
|
390
|
+
}));
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
} else {
|
|
394
|
+
const acShares = new _bignumber.default(stakeInfo.autoCompoundingShares || '0');
|
|
395
|
+
const isUnstakeAll = unstakeAmount.gte(autoCompounding.multipliedBy(0.9999));
|
|
396
|
+
txs.push(substrateApi.api.tx.pooledStaking.requestUndelegate(selectedTarget, 'AutoCompounding', isUnstakeAll ? {
|
|
397
|
+
Shares: acShares.toFixed(0)
|
|
398
|
+
} : {
|
|
399
|
+
Stake: unstakeAmount.toFixed(0)
|
|
400
|
+
}));
|
|
401
|
+
}
|
|
402
|
+
const extrinsic = txs.length === 1 ? txs[0] : substrateApi.api.tx.utility.batchAll(txs);
|
|
403
|
+
return [_KoniTypes.ExtrinsicType.STAKING_UNBOND, extrinsic];
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/* Leave pool action */
|
|
407
|
+
|
|
408
|
+
/* Get pool reward */
|
|
409
|
+
async getPoolReward(useAddresses, callback) {
|
|
410
|
+
let cancel = false;
|
|
411
|
+
const substrateApi = this.substrateApi;
|
|
412
|
+
await substrateApi.isReady;
|
|
413
|
+
await Promise.all(useAddresses.map(async address => {
|
|
414
|
+
if (cancel) {
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
const delegatorSummaries = await substrateApi.api.query.pooledStaking.delegatorCandidateSummaries.entries(address);
|
|
418
|
+
if (!delegatorSummaries || delegatorSummaries.length === 0) {
|
|
419
|
+
const earningRewardItem = {
|
|
420
|
+
...this.baseInfo,
|
|
421
|
+
address,
|
|
422
|
+
type: this.type,
|
|
423
|
+
unclaimedReward: '0',
|
|
424
|
+
state: _KoniTypes.APIItemState.READY
|
|
425
|
+
};
|
|
426
|
+
callback(earningRewardItem);
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
const candidates = delegatorSummaries.map(_ref3 => {
|
|
430
|
+
let [key] = _ref3;
|
|
431
|
+
return key.args[1].toString();
|
|
432
|
+
});
|
|
433
|
+
const ownStakesMap = await getOwnStakes(substrateApi, candidates, address);
|
|
434
|
+
let totalClaimable = new _bignumber.default(0);
|
|
435
|
+
for (const candidate of candidates) {
|
|
436
|
+
const ownStake = ownStakesMap[candidate];
|
|
437
|
+
if (ownStake) {
|
|
438
|
+
totalClaimable = totalClaimable.plus(ownStake.claimable || 0);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
const _unclaimedReward = totalClaimable.toFixed();
|
|
442
|
+
const earningRewardItem = {
|
|
443
|
+
...this.baseInfo,
|
|
444
|
+
address,
|
|
445
|
+
type: this.type,
|
|
446
|
+
unclaimedReward: _unclaimedReward,
|
|
447
|
+
state: _KoniTypes.APIItemState.READY
|
|
448
|
+
};
|
|
449
|
+
if (_unclaimedReward !== '0') {
|
|
450
|
+
await this.createClaimNotification(earningRewardItem, this.nativeToken);
|
|
451
|
+
}
|
|
452
|
+
callback(earningRewardItem);
|
|
453
|
+
}));
|
|
454
|
+
return () => {
|
|
455
|
+
cancel = true;
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/* Get pool reward */
|
|
460
|
+
|
|
461
|
+
/* Other actions */
|
|
462
|
+
|
|
463
|
+
async handleYieldClaimReward(address, bondReward) {
|
|
464
|
+
const api = await this.substrateApi.isReady;
|
|
465
|
+
const delegatorSummaries = await api.api.query.pooledStaking.delegatorCandidateSummaries.entries(address);
|
|
466
|
+
if (!delegatorSummaries || delegatorSummaries.length === 0) {
|
|
467
|
+
return Promise.reject(new _TransactionError.TransactionError(_types.BasicTxErrorType.INTERNAL_ERROR));
|
|
468
|
+
}
|
|
469
|
+
const candidates = delegatorSummaries.map(_ref4 => {
|
|
470
|
+
let [key] = _ref4;
|
|
471
|
+
return key.args[1].toString();
|
|
472
|
+
});
|
|
473
|
+
const ownStakesMap = await getOwnStakes(api, candidates, address);
|
|
474
|
+
const claimablePairs = [];
|
|
475
|
+
for (const candidate of candidates) {
|
|
476
|
+
const ownStake = ownStakesMap[candidate];
|
|
477
|
+
if (ownStake && new _bignumber.default(ownStake.claimable).gt(0)) {
|
|
478
|
+
claimablePairs.push([candidate, address]);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
if (claimablePairs.length === 0) {
|
|
482
|
+
return Promise.reject(new _TransactionError.TransactionError(_types.BasicTxErrorType.INTERNAL_ERROR));
|
|
483
|
+
}
|
|
484
|
+
const extrinsic = api.api.tx.pooledStaking.claimManualRewards(claimablePairs);
|
|
485
|
+
return extrinsic;
|
|
486
|
+
}
|
|
487
|
+
handleYieldWithdraw(address, unstakingInfo) {
|
|
488
|
+
throw new Error('Method not implemented.');
|
|
489
|
+
}
|
|
490
|
+
handleYieldCancelUnstake(params) {
|
|
491
|
+
throw new Error('Method not implemented.');
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/* Other actions */
|
|
495
|
+
}
|
|
496
|
+
exports.default = TanssiNativeStakingPoolHandler;
|
|
@@ -17,6 +17,7 @@ var _types2 = require("@subwallet/extension-base/types");
|
|
|
17
17
|
var _utils2 = require("@subwallet/extension-base/utils");
|
|
18
18
|
var _fetchStaticCache = require("@subwallet/extension-base/utils/fetchStaticCache");
|
|
19
19
|
var _rxjs = require("rxjs");
|
|
20
|
+
var _tanssi = _interopRequireDefault(require("./handlers/native-staking/tanssi"));
|
|
20
21
|
var _handlers = require("./handlers");
|
|
21
22
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
22
23
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -108,6 +109,9 @@ class EarningService {
|
|
|
108
109
|
if (_constants2._STAKING_CHAIN_GROUP.energy.includes(chain)) {
|
|
109
110
|
handlers.push(new _handlers.EnergyNativeStakingPoolHandler(this.state, chain));
|
|
110
111
|
}
|
|
112
|
+
if (_constants2._STAKING_CHAIN_GROUP.tanssi.includes(chain)) {
|
|
113
|
+
handlers.push(new _tanssi.default(this.state, chain));
|
|
114
|
+
}
|
|
111
115
|
if (_constants2._STAKING_CHAIN_GROUP.nominationPool.includes(chain)) {
|
|
112
116
|
const ahMigratedChain = ahMigratedChainMap[chain];
|
|
113
117
|
if (ahMigratedChain) {
|
|
@@ -122,6 +122,8 @@ function isActionFromValidator(stakingType, chain) {
|
|
|
122
122
|
return true;
|
|
123
123
|
} else if (_constants._STAKING_CHAIN_GROUP.energy.includes(chain)) {
|
|
124
124
|
return true;
|
|
125
|
+
} else if (_constants._STAKING_CHAIN_GROUP.tanssi.includes(chain)) {
|
|
126
|
+
return true;
|
|
125
127
|
}
|
|
126
128
|
return false;
|
|
127
129
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _Base = _interopRequireDefault(require("@subwallet/extension-base/services/migration-service/Base"));
|
|
9
|
+
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
10
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
11
|
+
|
|
12
|
+
class MigrateTransactionHistoryBySymbol20251027 extends _Base.default {
|
|
13
|
+
async run() {
|
|
14
|
+
const state = this.state;
|
|
15
|
+
try {
|
|
16
|
+
const changeSlugsMap = {
|
|
17
|
+
'moonriver-ERC20-GLMR.wb-0xFfFffFff1a49463978f19dfD6983f2fa1885C254': 'moonriver-ERC20-GLMR.mb-0xFfFffFff1a49463978f19dfD6983f2fa1885C254'
|
|
18
|
+
};
|
|
19
|
+
const allTxs = [];
|
|
20
|
+
await Promise.all(Object.entries(changeSlugsMap).map(async (_ref, i) => {
|
|
21
|
+
let [oldSlug, newSlug] = _ref;
|
|
22
|
+
const oldSlugSplit = oldSlug.split('-');
|
|
23
|
+
const oldChainSlug = oldSlugSplit[0];
|
|
24
|
+
const oldSymbolSlug = oldSlugSplit[2];
|
|
25
|
+
const newSlugSplit = newSlug.split('-');
|
|
26
|
+
const newSymbolSlug = newSlugSplit[2];
|
|
27
|
+
const filterTransactions = await state.dbService.stores.transaction.table.where({
|
|
28
|
+
chain: oldChainSlug
|
|
29
|
+
}).and(tx => {
|
|
30
|
+
var _tx$amount;
|
|
31
|
+
return ((_tx$amount = tx.amount) === null || _tx$amount === void 0 ? void 0 : _tx$amount.symbol) === oldSymbolSlug;
|
|
32
|
+
}).toArray();
|
|
33
|
+
if (filterTransactions.length > 0) {
|
|
34
|
+
for (const transaction of filterTransactions) {
|
|
35
|
+
if (transaction.amount && transaction.amount.symbol === oldSymbolSlug) {
|
|
36
|
+
transaction.amount.symbol = newSymbolSlug;
|
|
37
|
+
}
|
|
38
|
+
if (transaction.fee && transaction.fee.symbol === oldSymbolSlug) {
|
|
39
|
+
transaction.fee.symbol = newSymbolSlug;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
allTxs.push(...filterTransactions);
|
|
44
|
+
}));
|
|
45
|
+
await state.dbService.stores.transaction.table.bulkPut(allTxs);
|
|
46
|
+
} catch (e) {
|
|
47
|
+
this.logger.error(e);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.default = MigrateTransactionHistoryBySymbol20251027;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _Base = _interopRequireDefault(require("@subwallet/extension-base/services/migration-service/Base"));
|
|
9
|
+
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
10
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
11
|
+
|
|
12
|
+
class MigrateAssetSetting20251027 extends _Base.default {
|
|
13
|
+
async run() {
|
|
14
|
+
try {
|
|
15
|
+
const changeSlugsMap = {
|
|
16
|
+
'moonriver-ERC20-GLMR.wb-0xFfFffFff1a49463978f19dfD6983f2fa1885C254': 'moonriver-ERC20-GLMR.mb-0xFfFffFff1a49463978f19dfD6983f2fa1885C254'
|
|
17
|
+
};
|
|
18
|
+
const assetSetting = await this.state.chainService.getAssetSettings();
|
|
19
|
+
const migratedAssetSetting = {};
|
|
20
|
+
for (const [oldSlug, newSlug] of Object.entries(changeSlugsMap)) {
|
|
21
|
+
if (Object.keys(assetSetting).includes(oldSlug)) {
|
|
22
|
+
const isVisible = assetSetting[oldSlug].visible;
|
|
23
|
+
migratedAssetSetting[newSlug] = {
|
|
24
|
+
visible: isVisible
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
this.state.chainService.setAssetSettings({
|
|
29
|
+
...assetSetting,
|
|
30
|
+
...migratedAssetSetting
|
|
31
|
+
});
|
|
32
|
+
} catch (e) {
|
|
33
|
+
console.error(e);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.default = MigrateAssetSetting20251027;
|
|
@@ -9,6 +9,7 @@ var _MigrateChainPatrol = _interopRequireDefault(require("@subwallet/extension-b
|
|
|
9
9
|
var _ClearMetadataDatabase = _interopRequireDefault(require("./databases/ClearMetadataDatabase"));
|
|
10
10
|
var _ClearMetadataForMythos = _interopRequireDefault(require("./databases/ClearMetadataForMythos"));
|
|
11
11
|
var _MigrateAssetSetting = _interopRequireDefault(require("./databases/MigrateAssetSetting"));
|
|
12
|
+
var _MigrateAssetSetting2 = _interopRequireDefault(require("./databases/MigrateAssetSetting20251027"));
|
|
12
13
|
var _MigrateEarningVersion = _interopRequireDefault(require("./databases/MigrateEarningVersion"));
|
|
13
14
|
var _ReloadMetadata = _interopRequireDefault(require("./databases/ReloadMetadata"));
|
|
14
15
|
var _MigrateLedgerAccount = _interopRequireDefault(require("./keyring/MigrateLedgerAccount"));
|
|
@@ -33,6 +34,7 @@ var _MigrateTokenDecimals = _interopRequireDefault(require("./MigrateTokenDecima
|
|
|
33
34
|
var _MigrateTransactionHistory = _interopRequireDefault(require("./MigrateTransactionHistory"));
|
|
34
35
|
var _MigrateTransactionHistoryBridge = _interopRequireDefault(require("./MigrateTransactionHistoryBridge"));
|
|
35
36
|
var _MigrateTransactionHistoryBySymbol = _interopRequireDefault(require("./MigrateTransactionHistoryBySymbol"));
|
|
37
|
+
var _MigrateTransactionHistoryBySymbol2 = _interopRequireDefault(require("./MigrateTransactionHistoryBySymbol20251027"));
|
|
36
38
|
var _MigrateWalletReference = _interopRequireDefault(require("./MigrateWalletReference"));
|
|
37
39
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
38
40
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -78,6 +80,8 @@ var _default = {
|
|
|
78
80
|
// [`${EVERYTIME}-1`]: AutoEnableChainsTokens
|
|
79
81
|
'1.3.42-01': _MigrateNewUnifiedAccount.default,
|
|
80
82
|
'1.3.54-01': _MigrateChainPatrol.default,
|
|
81
|
-
'1.3.62-01': _DeleteEarningData2.default
|
|
83
|
+
'1.3.62-01': _DeleteEarningData2.default,
|
|
84
|
+
'1.3.64-01': _MigrateAssetSetting2.default,
|
|
85
|
+
'1.3.64-02': _MigrateTransactionHistoryBySymbol2.default
|
|
82
86
|
};
|
|
83
87
|
exports.default = _default;
|
|
@@ -64,7 +64,10 @@ class SwapBaseHandler {
|
|
|
64
64
|
return result;
|
|
65
65
|
} catch (e) {
|
|
66
66
|
const errorMessage = e.message;
|
|
67
|
-
if (errorMessage.toLowerCase().startsWith(
|
|
67
|
+
if (errorMessage.toLowerCase().startsWith(_utils4.DetectedGenOptimalProcessErrMsg.AMOUNT_TOO_LOW) || errorMessage.toLowerCase().startsWith(_utils4.DetectedGenOptimalProcessErrMsg.AMOUNT_TOO_HIGH)) {
|
|
68
|
+
throw new Error(errorMessage);
|
|
69
|
+
}
|
|
70
|
+
if (errorMessage.toLowerCase().includes(_utils4.DetectedGenOptimalProcessErrMsg.NOT_ENOUGHT_BITCOIN)) {
|
|
68
71
|
throw new Error(errorMessage);
|
|
69
72
|
}
|
|
70
73
|
return result;
|