@subwallet/extension-base 1.0.7-1 → 1.0.7-2
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 +3 -3
- package/cjs/koni/api/staking/bonding/astar.js +5 -4
- package/cjs/koni/api/staking/bonding/relayChain.js +12 -3
- package/cjs/koni/api/staking/bonding/utils.js +7 -0
- package/cjs/koni/background/handlers/Extension.js +98 -74
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/constants.js +3 -1
- package/koni/api/staking/bonding/astar.js +5 -4
- package/koni/api/staking/bonding/relayChain.js +13 -4
- package/koni/api/staking/bonding/utils.d.ts +5 -0
- package/koni/api/staking/bonding/utils.js +6 -0
- package/koni/background/handlers/Extension.js +29 -7
- package/package.json +5 -5
- package/packageInfo.js +1 -1
- package/services/chain-service/constants.d.ts +1 -0
- package/services/chain-service/constants.js +3 -2
- package/services/chain-service/types.d.ts +8 -0
|
@@ -4,7 +4,7 @@ import { TransactionError } from '@subwallet/extension-base/background/errors/Tr
|
|
|
4
4
|
import { AuthUrls, Resolver } from '@subwallet/extension-base/background/handlers/State';
|
|
5
5
|
import { AccountAuthType, AccountJson, AddressJson, AuthorizeRequest, ConfirmationRequestBase, RequestAccountList, RequestAccountSubscribe, RequestAuthorizeCancel, RequestAuthorizeReject, RequestAuthorizeSubscribe, RequestAuthorizeTab, RequestCurrentAccountAddress, ResponseAuthorizeList, ResponseJsonGetAccountInfo, SeedLengths } from '@subwallet/extension-base/background/types';
|
|
6
6
|
import { _CHAIN_VALIDATION_ERROR } from '@subwallet/extension-base/services/chain-service/handler/types';
|
|
7
|
-
import { _ChainState, _EvmApi, _NetworkUpsertParams, _SubstrateApi, _ValidateCustomAssetRequest, _ValidateCustomAssetResponse } from '@subwallet/extension-base/services/chain-service/types';
|
|
7
|
+
import { _ChainState, _EvmApi, _NetworkUpsertParams, _SubstrateApi, _ValidateCustomAssetRequest, _ValidateCustomAssetResponse, EnableChainParams, EnableMultiChainParams } from '@subwallet/extension-base/services/chain-service/types';
|
|
8
8
|
import { SWTransactionResponse, SWTransactionResult } from '@subwallet/extension-base/services/transaction-service/types';
|
|
9
9
|
import { InjectedAccount, MetadataDefBase } from '@subwallet/extension-inject/types';
|
|
10
10
|
import { KeyringPair$Json, KeyringPair$Meta } from '@subwallet/keyring/types';
|
|
@@ -1415,9 +1415,9 @@ export interface KoniRequestSignatures {
|
|
|
1415
1415
|
'pri(chainService.subscribeMultiChainAssetMap)': [null, Record<string, _MultiChainAsset>, Record<string, _MultiChainAsset>];
|
|
1416
1416
|
'pri(chainService.subscribeXcmRefMap)': [null, Record<string, _AssetRef>, Record<string, _AssetRef>];
|
|
1417
1417
|
'pri(chainService.upsertChain)': [_NetworkUpsertParams, boolean];
|
|
1418
|
-
'pri(chainService.enableChains)': [
|
|
1418
|
+
'pri(chainService.enableChains)': [EnableMultiChainParams, boolean];
|
|
1419
|
+
'pri(chainService.enableChain)': [EnableChainParams, boolean];
|
|
1419
1420
|
'pri(chainService.disableChains)': [string[], boolean];
|
|
1420
|
-
'pri(chainService.enableChain)': [string, boolean];
|
|
1421
1421
|
'pri(chainService.disableChain)': [string, boolean];
|
|
1422
1422
|
'pri(chainService.removeChain)': [string, boolean];
|
|
1423
1423
|
'pri(chainService.deleteCustomAsset)': [string, boolean];
|
|
@@ -184,14 +184,15 @@ async function getAstarNominatorMetadata(chainInfo, address, substrateApi) {
|
|
|
184
184
|
const dAppInfoMap = {};
|
|
185
185
|
const allDapps = await allDappsReq;
|
|
186
186
|
allDapps.forEach(dappInfo => {
|
|
187
|
-
|
|
187
|
+
const address = (0, _utilCrypto.isEthereumAddress)(dappInfo.address) ? dappInfo.address.toLowerCase() : dappInfo.address;
|
|
188
|
+
dAppInfoMap[address] = dappInfo;
|
|
188
189
|
});
|
|
189
190
|
for (const item of _stakerInfo) {
|
|
190
191
|
const data = item[0].toHuman();
|
|
191
192
|
const stakedDapp = data[1];
|
|
192
193
|
const stakeData = item[1].toPrimitive();
|
|
193
194
|
const stakeList = stakeData.stakes;
|
|
194
|
-
const dappAddress = stakedDapp.Evm.toLowerCase();
|
|
195
|
+
const dappAddress = (0, _utilCrypto.isEthereumAddress)(stakedDapp.Evm) ? stakedDapp.Evm.toLowerCase() : stakedDapp.Evm;
|
|
195
196
|
const currentStake = stakeList.slice(-1)[0].staked.toString() || '0';
|
|
196
197
|
const bnCurrentStake = new _util.BN(currentStake);
|
|
197
198
|
if (bnCurrentStake.gt(_util.BN_ZERO)) {
|
|
@@ -201,7 +202,7 @@ async function getAstarNominatorMetadata(chainInfo, address, substrateApi) {
|
|
|
201
202
|
nominationList.push({
|
|
202
203
|
status: dappStakingStatus,
|
|
203
204
|
chain,
|
|
204
|
-
validatorAddress: dappAddress
|
|
205
|
+
validatorAddress: dappAddress,
|
|
205
206
|
activeStake: currentStake,
|
|
206
207
|
validatorMinStake: '0',
|
|
207
208
|
validatorIdentity: dappInfo === null || dappInfo === void 0 ? void 0 : dappInfo.name,
|
|
@@ -334,7 +335,7 @@ async function getAstarClaimRewardExtrinsic(substrateApi, address) {
|
|
|
334
335
|
const stakedDapp = data[1];
|
|
335
336
|
const stakeData = item[1].toHuman();
|
|
336
337
|
const stakes = stakeData.stakes;
|
|
337
|
-
const dappAddress = stakedDapp.Evm.toLowerCase();
|
|
338
|
+
const dappAddress = (0, _utilCrypto.isEthereumAddress)(stakedDapp.Evm) ? stakedDapp.Evm.toLowerCase() : stakedDapp.Evm;
|
|
338
339
|
let numberOfUnclaimedEra = 0;
|
|
339
340
|
const maxTx = 50;
|
|
340
341
|
for (let i = 0; i < stakes.length; i++) {
|
|
@@ -162,7 +162,7 @@ async function getRelayChainStakingMetadata(chainInfo, substrateApi) {
|
|
|
162
162
|
chain,
|
|
163
163
|
type: _KoniTypes.StakingType.NOMINATED,
|
|
164
164
|
era: parseInt(currentEra),
|
|
165
|
-
expectedReturn,
|
|
165
|
+
expectedReturn: !_constants._STAKING_CHAIN_GROUP.ternoa.includes(chain) ? expectedReturn : undefined,
|
|
166
166
|
// in %, annually
|
|
167
167
|
inflation,
|
|
168
168
|
minStake: minStake.toString(),
|
|
@@ -503,7 +503,8 @@ async function getRelayValidatorsInfo(chain, substrateApi, decimals, chainStakin
|
|
|
503
503
|
const currentEra = _era.toString();
|
|
504
504
|
const allValidators = [];
|
|
505
505
|
const validatorInfoList = [];
|
|
506
|
-
const [_totalEraStake, _eraStakers, _minBond] = await Promise.all([chainApi.api.query.staking.erasTotalStake(parseInt(currentEra)), chainApi.api.query.staking.erasStakers.entries(parseInt(currentEra)), chainApi.api.query.staking.minNominatorBond()]);
|
|
506
|
+
const [_totalEraStake, _eraStakers, _minBond, _stakingRewards] = await Promise.all([chainApi.api.query.staking.erasTotalStake(parseInt(currentEra)), chainApi.api.query.staking.erasStakers.entries(parseInt(currentEra)), chainApi.api.query.staking.minNominatorBond(), chainApi.api.query.stakingRewards && chainApi.api.query.stakingRewards.data()]);
|
|
507
|
+
const stakingRewards = _stakingRewards === null || _stakingRewards === void 0 ? void 0 : _stakingRewards.toPrimitive();
|
|
507
508
|
const maxNominatorRewarded = chainApi.api.consts.staking.maxNominatorRewardedPerValidator.toString();
|
|
508
509
|
const bnTotalEraStake = new _util.BN(_totalEraStake.toString());
|
|
509
510
|
const eraStakers = _eraStakers;
|
|
@@ -566,7 +567,15 @@ async function getRelayValidatorsInfo(chain, substrateApi, decimals, chainStakin
|
|
|
566
567
|
for (const validator of validatorInfoList) {
|
|
567
568
|
const commission = extraInfoMap[validator.address].commission;
|
|
568
569
|
const bnValidatorStake = totalStakeMap[validator.address].div(bnDecimals);
|
|
569
|
-
|
|
570
|
+
if (_constants._STAKING_CHAIN_GROUP.aleph.includes(chain)) {
|
|
571
|
+
validator.expectedReturn = (0, _utils.calculateAlephZeroValidatorReturn)(chainStakingMetadata.expectedReturn, (0, _utils.getCommission)(commission));
|
|
572
|
+
} else if (_constants._STAKING_CHAIN_GROUP.ternoa.includes(chain)) {
|
|
573
|
+
const rewardPerValidator = new _util.BN(stakingRewards.sessionExtraRewardPayout).divn(allValidators.length).div(bnDecimals);
|
|
574
|
+
const validatorStake = totalStakeMap[validator.address].div(bnDecimals).toNumber();
|
|
575
|
+
validator.expectedReturn = (0, _utils.calculateTernoaValidatorReturn)(rewardPerValidator.toNumber(), validatorStake, (0, _utils.getCommission)(commission));
|
|
576
|
+
} else {
|
|
577
|
+
validator.expectedReturn = (0, _utils.calculateValidatorStakedReturn)(chainStakingMetadata.expectedReturn, bnValidatorStake, bnAvgStake, (0, _utils.getCommission)(commission));
|
|
578
|
+
}
|
|
570
579
|
validator.commission = parseFloat(commission.split('%')[0]);
|
|
571
580
|
validator.blocked = extraInfoMap[validator.address].blocked;
|
|
572
581
|
validator.identity = extraInfoMap[validator.address].identity;
|
|
@@ -9,6 +9,7 @@ exports.calcInflationUniformEraPayout = calcInflationUniformEraPayout;
|
|
|
9
9
|
exports.calculateAlephZeroValidatorReturn = calculateAlephZeroValidatorReturn;
|
|
10
10
|
exports.calculateChainStakedReturn = calculateChainStakedReturn;
|
|
11
11
|
exports.calculateInflation = calculateInflation;
|
|
12
|
+
exports.calculateTernoaValidatorReturn = calculateTernoaValidatorReturn;
|
|
12
13
|
exports.calculateValidatorStakedReturn = calculateValidatorStakedReturn;
|
|
13
14
|
exports.getBondedValidators = getBondedValidators;
|
|
14
15
|
exports.getCommission = getCommission;
|
|
@@ -113,6 +114,12 @@ function calculateChainStakedReturn(inflation, totalEraStake, totalIssuance, net
|
|
|
113
114
|
function calculateAlephZeroValidatorReturn(chainStakedReturn, commission) {
|
|
114
115
|
return chainStakedReturn * (100 - commission) / 100;
|
|
115
116
|
}
|
|
117
|
+
function calculateTernoaValidatorReturn(rewardPerValidator, validatorStake, commission) {
|
|
118
|
+
const percentRewardForNominators = (100 - commission) / 100;
|
|
119
|
+
const rewardForNominators = rewardPerValidator * percentRewardForNominators;
|
|
120
|
+
const stakeRatio = rewardForNominators / validatorStake;
|
|
121
|
+
return stakeRatio * 365 * 100;
|
|
122
|
+
}
|
|
116
123
|
function calculateValidatorStakedReturn(chainStakedReturn, totalValidatorStake, avgStake, commission) {
|
|
117
124
|
const bnAdjusted = avgStake.mul(_util.BN_HUNDRED).div(totalValidatorStake);
|
|
118
125
|
const adjusted = bnAdjusted.toNumber() * chainStakedReturn;
|
|
@@ -11,6 +11,7 @@ var _Extension = require("@subwallet/extension-base/background/handlers/Extensio
|
|
|
11
11
|
var _helpers = require("@subwallet/extension-base/background/handlers/helpers");
|
|
12
12
|
var _subscriptions = require("@subwallet/extension-base/background/handlers/subscriptions");
|
|
13
13
|
var _KoniTypes = require("@subwallet/extension-base/background/KoniTypes");
|
|
14
|
+
var _TransactionWarning = require("@subwallet/extension-base/background/warnings/TransactionWarning");
|
|
14
15
|
var _constants = require("@subwallet/extension-base/constants");
|
|
15
16
|
var _defaults = require("@subwallet/extension-base/defaults");
|
|
16
17
|
var _parseTransaction = require("@subwallet/extension-base/koni/api/dotsama/parseTransaction");
|
|
@@ -1471,6 +1472,17 @@ class KoniExtension {
|
|
|
1471
1472
|
}
|
|
1472
1473
|
const transferNativeAmount = isTransferNativeToken ? transferAmount.value : '0';
|
|
1473
1474
|
this.addContact(to);
|
|
1475
|
+
const additionalValidator = async inputTransaction => {
|
|
1476
|
+
if (!isTransferNativeToken) {
|
|
1477
|
+
const {
|
|
1478
|
+
value: balance
|
|
1479
|
+
} = await this.#koniState.balanceService.getTokenFreeBalance(from, networkKey, tokenSlug);
|
|
1480
|
+
const minAmount = tokenInfo.minAmount || '0';
|
|
1481
|
+
if (new _bignumber.default(balance).minus(transferAmount.value).lt(minAmount)) {
|
|
1482
|
+
inputTransaction.warnings.push(new _TransactionWarning.TransactionWarning(_KoniTypes.BasicTxWarningCode.NOT_ENOUGH_EXISTENTIAL_DEPOSIT, ''));
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
};
|
|
1474
1486
|
return this.#koniState.transactionService.handleTransaction({
|
|
1475
1487
|
errors,
|
|
1476
1488
|
warnings,
|
|
@@ -1482,8 +1494,9 @@ class KoniExtension {
|
|
|
1482
1494
|
data: inputData,
|
|
1483
1495
|
extrinsicType: isTransferNativeToken ? _KoniTypes.ExtrinsicType.TRANSFER_BALANCE : _KoniTypes.ExtrinsicType.TRANSFER_TOKEN,
|
|
1484
1496
|
ignoreWarnings: transferAll,
|
|
1485
|
-
isTransferAll: transferAll,
|
|
1486
|
-
edAsWarning:
|
|
1497
|
+
isTransferAll: isTransferNativeToken ? transferAll : false,
|
|
1498
|
+
edAsWarning: true,
|
|
1499
|
+
additionalValidator: additionalValidator
|
|
1487
1500
|
});
|
|
1488
1501
|
}
|
|
1489
1502
|
validateCrossChainTransfer(destinationNetworkKey, sendingTokenSlug, sender, sendingValue) {
|
|
@@ -1572,14 +1585,18 @@ class KoniExtension {
|
|
|
1572
1585
|
disableChain(networkKey) {
|
|
1573
1586
|
return this.#koniState.disableChain(networkKey);
|
|
1574
1587
|
}
|
|
1575
|
-
async enableChain(
|
|
1576
|
-
|
|
1588
|
+
async enableChain(_ref39) {
|
|
1589
|
+
let {
|
|
1590
|
+
chainSlug,
|
|
1591
|
+
enableTokens
|
|
1592
|
+
} = _ref39;
|
|
1593
|
+
return await this.#koniState.enableChain(chainSlug, enableTokens);
|
|
1577
1594
|
}
|
|
1578
|
-
async validateNetwork(
|
|
1595
|
+
async validateNetwork(_ref40) {
|
|
1579
1596
|
let {
|
|
1580
1597
|
existedChainSlug,
|
|
1581
1598
|
provider
|
|
1582
|
-
} =
|
|
1599
|
+
} = _ref40;
|
|
1583
1600
|
return await this.#koniState.validateCustomChain(provider, existedChainSlug);
|
|
1584
1601
|
}
|
|
1585
1602
|
resetDefaultNetwork() {
|
|
@@ -1617,22 +1634,22 @@ class KoniExtension {
|
|
|
1617
1634
|
async validateCustomAsset(data) {
|
|
1618
1635
|
return await this.#koniState.validateCustomAsset(data);
|
|
1619
1636
|
}
|
|
1620
|
-
async getAddressFreeBalance(
|
|
1637
|
+
async getAddressFreeBalance(_ref41) {
|
|
1621
1638
|
let {
|
|
1622
1639
|
address,
|
|
1623
1640
|
networkKey,
|
|
1624
1641
|
token
|
|
1625
|
-
} =
|
|
1642
|
+
} = _ref41;
|
|
1626
1643
|
return await this.#koniState.balanceService.getTokenFreeBalance(address, networkKey, token);
|
|
1627
1644
|
}
|
|
1628
|
-
async transferGetMaxTransferable(
|
|
1645
|
+
async transferGetMaxTransferable(_ref42) {
|
|
1629
1646
|
let {
|
|
1630
1647
|
address,
|
|
1631
1648
|
destChain,
|
|
1632
1649
|
isXcmTransfer,
|
|
1633
1650
|
networkKey,
|
|
1634
1651
|
token
|
|
1635
|
-
} =
|
|
1652
|
+
} = _ref42;
|
|
1636
1653
|
const freeBalance = await this.#koniState.balanceService.getTokenFreeBalance(address, networkKey, token);
|
|
1637
1654
|
const tokenInfo = token ? this.#koniState.chainService.getAssetBySlug(token) : this.#koniState.chainService.getNativeTokenInfo(networkKey);
|
|
1638
1655
|
if (!(0, _utils._isNativeToken)(tokenInfo)) {
|
|
@@ -1703,12 +1720,12 @@ class KoniExtension {
|
|
|
1703
1720
|
};
|
|
1704
1721
|
}
|
|
1705
1722
|
}
|
|
1706
|
-
async subscribeAddressFreeBalance(
|
|
1723
|
+
async subscribeAddressFreeBalance(_ref43, id, port) {
|
|
1707
1724
|
let {
|
|
1708
1725
|
address,
|
|
1709
1726
|
networkKey,
|
|
1710
1727
|
token
|
|
1711
|
-
} =
|
|
1728
|
+
} = _ref43;
|
|
1712
1729
|
const cb = (0, _subscriptions.createSubscription)(id, port);
|
|
1713
1730
|
const [unsub, currentFreeBalance] = await this.#koniState.balanceService.subscribeTokenFreeBalance(address, networkKey, token, cb);
|
|
1714
1731
|
this.createUnsubscriptionHandle(id, unsub);
|
|
@@ -1717,26 +1734,26 @@ class KoniExtension {
|
|
|
1717
1734
|
});
|
|
1718
1735
|
return currentFreeBalance;
|
|
1719
1736
|
}
|
|
1720
|
-
async transferCheckReferenceCount(
|
|
1737
|
+
async transferCheckReferenceCount(_ref44) {
|
|
1721
1738
|
let {
|
|
1722
1739
|
address,
|
|
1723
1740
|
networkKey
|
|
1724
|
-
} =
|
|
1741
|
+
} = _ref44;
|
|
1725
1742
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-return
|
|
1726
1743
|
return await (0, _transfer.checkReferenceCount)(networkKey, address, this.#koniState.getSubstrateApiMap(), this.#koniState.getChainInfo(networkKey));
|
|
1727
1744
|
}
|
|
1728
|
-
async transferCheckSupporting(
|
|
1745
|
+
async transferCheckSupporting(_ref45) {
|
|
1729
1746
|
let {
|
|
1730
1747
|
networkKey,
|
|
1731
1748
|
tokenSlug
|
|
1732
|
-
} =
|
|
1749
|
+
} = _ref45;
|
|
1733
1750
|
const tokenInfo = this.#koniState.getAssetBySlug(tokenSlug);
|
|
1734
1751
|
return await (0, _transfer.checkSupportTransfer)(networkKey, tokenInfo, this.#koniState.getSubstrateApiMap(), this.#koniState.getChainInfo(networkKey));
|
|
1735
1752
|
}
|
|
1736
|
-
transferGetExistentialDeposit(
|
|
1753
|
+
transferGetExistentialDeposit(_ref46) {
|
|
1737
1754
|
let {
|
|
1738
1755
|
tokenSlug
|
|
1739
|
-
} =
|
|
1756
|
+
} = _ref46;
|
|
1740
1757
|
const tokenInfo = this.#koniState.getAssetBySlug(tokenSlug);
|
|
1741
1758
|
return (0, _utils._getTokenMinAmount)(tokenInfo);
|
|
1742
1759
|
}
|
|
@@ -1770,32 +1787,39 @@ class KoniExtension {
|
|
|
1770
1787
|
isSendingSelf
|
|
1771
1788
|
};
|
|
1772
1789
|
}
|
|
1773
|
-
async enableChains(
|
|
1790
|
+
async enableChains(_ref47) {
|
|
1791
|
+
let {
|
|
1792
|
+
chainSlugs,
|
|
1793
|
+
enableTokens
|
|
1794
|
+
} = _ref47;
|
|
1774
1795
|
try {
|
|
1775
|
-
await Promise.all(
|
|
1796
|
+
await Promise.all(chainSlugs.map(chainSlug => this.enableChain({
|
|
1797
|
+
chainSlug,
|
|
1798
|
+
enableTokens
|
|
1799
|
+
})));
|
|
1776
1800
|
} catch (e) {
|
|
1777
1801
|
return false;
|
|
1778
1802
|
}
|
|
1779
1803
|
return true;
|
|
1780
1804
|
}
|
|
1781
|
-
getAccountMeta(
|
|
1805
|
+
getAccountMeta(_ref48) {
|
|
1782
1806
|
let {
|
|
1783
1807
|
address
|
|
1784
|
-
} =
|
|
1808
|
+
} = _ref48;
|
|
1785
1809
|
const pair = _uiKeyring.keyring.getPair(address);
|
|
1786
1810
|
(0, _util.assert)(pair, 'Unable to find pair');
|
|
1787
1811
|
return {
|
|
1788
1812
|
meta: pair.meta
|
|
1789
1813
|
};
|
|
1790
1814
|
}
|
|
1791
|
-
accountsTie2(
|
|
1815
|
+
accountsTie2(_ref49) {
|
|
1792
1816
|
let {
|
|
1793
1817
|
address,
|
|
1794
1818
|
genesisHash
|
|
1795
|
-
} =
|
|
1819
|
+
} = _ref49;
|
|
1796
1820
|
return this.#koniState.setAccountTie(address, genesisHash);
|
|
1797
1821
|
}
|
|
1798
|
-
async accountsCreateExternalV2(
|
|
1822
|
+
async accountsCreateExternalV2(_ref50) {
|
|
1799
1823
|
let {
|
|
1800
1824
|
address,
|
|
1801
1825
|
genesisHash,
|
|
@@ -1803,7 +1827,7 @@ class KoniExtension {
|
|
|
1803
1827
|
isEthereum,
|
|
1804
1828
|
isReadOnly,
|
|
1805
1829
|
name
|
|
1806
|
-
} =
|
|
1830
|
+
} = _ref50;
|
|
1807
1831
|
try {
|
|
1808
1832
|
let result;
|
|
1809
1833
|
try {
|
|
@@ -1862,7 +1886,7 @@ class KoniExtension {
|
|
|
1862
1886
|
}];
|
|
1863
1887
|
}
|
|
1864
1888
|
}
|
|
1865
|
-
async accountsCreateHardwareV2(
|
|
1889
|
+
async accountsCreateHardwareV2(_ref51) {
|
|
1866
1890
|
let {
|
|
1867
1891
|
accountIndex,
|
|
1868
1892
|
address,
|
|
@@ -1871,7 +1895,7 @@ class KoniExtension {
|
|
|
1871
1895
|
hardwareType,
|
|
1872
1896
|
isAllowed,
|
|
1873
1897
|
name
|
|
1874
|
-
} =
|
|
1898
|
+
} = _ref51;
|
|
1875
1899
|
const key = _uiKeyring.keyring.addHardware(address, hardwareType, {
|
|
1876
1900
|
accountIndex,
|
|
1877
1901
|
addressOffset,
|
|
@@ -1894,10 +1918,10 @@ class KoniExtension {
|
|
|
1894
1918
|
});
|
|
1895
1919
|
return true;
|
|
1896
1920
|
}
|
|
1897
|
-
async accountsCreateHardwareMultiple(
|
|
1921
|
+
async accountsCreateHardwareMultiple(_ref52) {
|
|
1898
1922
|
let {
|
|
1899
1923
|
accounts
|
|
1900
|
-
} =
|
|
1924
|
+
} = _ref52;
|
|
1901
1925
|
const addresses = [];
|
|
1902
1926
|
if (!accounts.length) {
|
|
1903
1927
|
throw new Error('No accounts to import');
|
|
@@ -1948,14 +1972,14 @@ class KoniExtension {
|
|
|
1948
1972
|
});
|
|
1949
1973
|
return true;
|
|
1950
1974
|
}
|
|
1951
|
-
async accountsCreateWithSecret(
|
|
1975
|
+
async accountsCreateWithSecret(_ref53) {
|
|
1952
1976
|
let {
|
|
1953
1977
|
isAllow,
|
|
1954
1978
|
isEthereum,
|
|
1955
1979
|
name,
|
|
1956
1980
|
publicKey,
|
|
1957
1981
|
secretKey
|
|
1958
|
-
} =
|
|
1982
|
+
} = _ref53;
|
|
1959
1983
|
try {
|
|
1960
1984
|
let keyringPair = null;
|
|
1961
1985
|
if (isEthereum) {
|
|
@@ -2098,30 +2122,30 @@ class KoniExtension {
|
|
|
2098
2122
|
|
|
2099
2123
|
// Parse transaction
|
|
2100
2124
|
|
|
2101
|
-
parseSubstrateTransaction(
|
|
2125
|
+
parseSubstrateTransaction(_ref54) {
|
|
2102
2126
|
let {
|
|
2103
2127
|
data,
|
|
2104
2128
|
networkKey
|
|
2105
|
-
} =
|
|
2129
|
+
} = _ref54;
|
|
2106
2130
|
const apiProps = this.#koniState.getSubstrateApi(networkKey);
|
|
2107
2131
|
const apiPromise = apiProps.api;
|
|
2108
2132
|
return (0, _parseTransaction.parseSubstrateTransaction)(data, apiPromise);
|
|
2109
2133
|
}
|
|
2110
|
-
async parseEVMRLP(
|
|
2134
|
+
async parseEVMRLP(_ref55) {
|
|
2111
2135
|
let {
|
|
2112
2136
|
data
|
|
2113
|
-
} =
|
|
2137
|
+
} = _ref55;
|
|
2114
2138
|
return await (0, _parseTransaction2.parseEvmRlp)(data, this.#koniState.getChainInfoMap(), this.#koniState.getEvmApiMap());
|
|
2115
2139
|
}
|
|
2116
2140
|
|
|
2117
2141
|
// Sign
|
|
2118
2142
|
|
|
2119
|
-
qrSignSubstrate(
|
|
2143
|
+
qrSignSubstrate(_ref56) {
|
|
2120
2144
|
let {
|
|
2121
2145
|
address,
|
|
2122
2146
|
data,
|
|
2123
2147
|
networkKey
|
|
2124
|
-
} =
|
|
2148
|
+
} = _ref56;
|
|
2125
2149
|
const pair = _uiKeyring.keyring.getPair(address);
|
|
2126
2150
|
(0, _util.assert)(pair, 'Unable to find pair');
|
|
2127
2151
|
if (pair.isLocked) {
|
|
@@ -2138,13 +2162,13 @@ class KoniExtension {
|
|
|
2138
2162
|
signature: signed
|
|
2139
2163
|
};
|
|
2140
2164
|
}
|
|
2141
|
-
async qrSignEVM(
|
|
2165
|
+
async qrSignEVM(_ref57) {
|
|
2142
2166
|
let {
|
|
2143
2167
|
address,
|
|
2144
2168
|
chainId,
|
|
2145
2169
|
message,
|
|
2146
2170
|
type
|
|
2147
|
-
} =
|
|
2171
|
+
} = _ref57;
|
|
2148
2172
|
let signed;
|
|
2149
2173
|
const network = this.getNetworkJsonByChainId(chainId);
|
|
2150
2174
|
if (!network) {
|
|
@@ -2225,11 +2249,11 @@ class KoniExtension {
|
|
|
2225
2249
|
});
|
|
2226
2250
|
return this.#koniState.getNominatorMetadata();
|
|
2227
2251
|
}
|
|
2228
|
-
async getBondingOptions(
|
|
2252
|
+
async getBondingOptions(_ref58) {
|
|
2229
2253
|
let {
|
|
2230
2254
|
chain,
|
|
2231
2255
|
type
|
|
2232
|
-
} =
|
|
2256
|
+
} = _ref58;
|
|
2233
2257
|
const apiProps = this.#koniState.getSubstrateApi(chain);
|
|
2234
2258
|
const chainInfo = this.#koniState.getChainInfo(chain);
|
|
2235
2259
|
const chainStakingMetadata = await this.#koniState.getStakingMetadataByChain(chain, type);
|
|
@@ -2418,12 +2442,12 @@ class KoniExtension {
|
|
|
2418
2442
|
}
|
|
2419
2443
|
|
|
2420
2444
|
// EVM Transaction
|
|
2421
|
-
async parseContractInput(
|
|
2445
|
+
async parseContractInput(_ref59) {
|
|
2422
2446
|
let {
|
|
2423
2447
|
chainId,
|
|
2424
2448
|
contract,
|
|
2425
2449
|
data
|
|
2426
|
-
} =
|
|
2450
|
+
} = _ref59;
|
|
2427
2451
|
const network = this.getNetworkJsonByChainId(chainId);
|
|
2428
2452
|
return await (0, _parseTransaction2.parseContractInput)(data, contract, network);
|
|
2429
2453
|
}
|
|
@@ -2494,12 +2518,12 @@ class KoniExtension {
|
|
|
2494
2518
|
|
|
2495
2519
|
// Change master password
|
|
2496
2520
|
|
|
2497
|
-
keyringChangeMasterPassword(
|
|
2521
|
+
keyringChangeMasterPassword(_ref60) {
|
|
2498
2522
|
let {
|
|
2499
2523
|
createNew,
|
|
2500
2524
|
newPassword,
|
|
2501
2525
|
oldPassword
|
|
2502
|
-
} =
|
|
2526
|
+
} = _ref60;
|
|
2503
2527
|
try {
|
|
2504
2528
|
// Remove isMasterPassword meta if createNew
|
|
2505
2529
|
if (createNew) {
|
|
@@ -2533,11 +2557,11 @@ class KoniExtension {
|
|
|
2533
2557
|
|
|
2534
2558
|
// Migrate password
|
|
2535
2559
|
|
|
2536
|
-
keyringMigrateMasterPassword(
|
|
2560
|
+
keyringMigrateMasterPassword(_ref61) {
|
|
2537
2561
|
let {
|
|
2538
2562
|
address,
|
|
2539
2563
|
password
|
|
2540
|
-
} =
|
|
2564
|
+
} = _ref61;
|
|
2541
2565
|
try {
|
|
2542
2566
|
_uiKeyring.keyring.migrateWithMasterPassword(address, password);
|
|
2543
2567
|
} catch (e) {
|
|
@@ -2555,10 +2579,10 @@ class KoniExtension {
|
|
|
2555
2579
|
|
|
2556
2580
|
// Unlock wallet
|
|
2557
2581
|
|
|
2558
|
-
keyringUnlock(
|
|
2582
|
+
keyringUnlock(_ref62) {
|
|
2559
2583
|
let {
|
|
2560
2584
|
password
|
|
2561
|
-
} =
|
|
2585
|
+
} = _ref62;
|
|
2562
2586
|
try {
|
|
2563
2587
|
_uiKeyring.keyring.unlockKeyring(password);
|
|
2564
2588
|
} catch (e) {
|
|
@@ -2584,11 +2608,11 @@ class KoniExtension {
|
|
|
2584
2608
|
|
|
2585
2609
|
// Export mnemonic
|
|
2586
2610
|
|
|
2587
|
-
keyringExportMnemonic(
|
|
2611
|
+
keyringExportMnemonic(_ref63) {
|
|
2588
2612
|
let {
|
|
2589
2613
|
address,
|
|
2590
2614
|
password
|
|
2591
|
-
} =
|
|
2615
|
+
} = _ref63;
|
|
2592
2616
|
const pair = _uiKeyring.keyring.getPair(address);
|
|
2593
2617
|
const result = pair.exportMnemonic(password);
|
|
2594
2618
|
return {
|
|
@@ -2598,10 +2622,10 @@ class KoniExtension {
|
|
|
2598
2622
|
|
|
2599
2623
|
// Reset wallet
|
|
2600
2624
|
|
|
2601
|
-
async resetWallet(
|
|
2625
|
+
async resetWallet(_ref64) {
|
|
2602
2626
|
let {
|
|
2603
2627
|
resetAll
|
|
2604
|
-
} =
|
|
2628
|
+
} = _ref64;
|
|
2605
2629
|
try {
|
|
2606
2630
|
await this.#koniState.resetWallet(resetAll);
|
|
2607
2631
|
return {
|
|
@@ -2617,10 +2641,10 @@ class KoniExtension {
|
|
|
2617
2641
|
}
|
|
2618
2642
|
|
|
2619
2643
|
/// Signing external request
|
|
2620
|
-
signingApprovePasswordV2(
|
|
2644
|
+
signingApprovePasswordV2(_ref65) {
|
|
2621
2645
|
let {
|
|
2622
2646
|
id
|
|
2623
|
-
} =
|
|
2647
|
+
} = _ref65;
|
|
2624
2648
|
const queued = this.#koniState.getSignRequest(id);
|
|
2625
2649
|
(0, _util.assert)(queued, 'Unable to find request');
|
|
2626
2650
|
const {
|
|
@@ -2673,22 +2697,22 @@ class KoniExtension {
|
|
|
2673
2697
|
|
|
2674
2698
|
/// Derive account
|
|
2675
2699
|
|
|
2676
|
-
derivationCreateMultiple(
|
|
2700
|
+
derivationCreateMultiple(_ref66) {
|
|
2677
2701
|
let {
|
|
2678
2702
|
isAllowed,
|
|
2679
2703
|
items,
|
|
2680
2704
|
parentAddress
|
|
2681
|
-
} =
|
|
2705
|
+
} = _ref66;
|
|
2682
2706
|
const parentPair = _uiKeyring.keyring.getPair(parentAddress);
|
|
2683
2707
|
const isEvm = parentPair.type === 'ethereum';
|
|
2684
2708
|
if (parentPair.isLocked) {
|
|
2685
2709
|
_uiKeyring.keyring.unlockPair(parentPair.address);
|
|
2686
2710
|
}
|
|
2687
|
-
const createChild =
|
|
2711
|
+
const createChild = _ref67 => {
|
|
2688
2712
|
let {
|
|
2689
2713
|
name,
|
|
2690
2714
|
suri
|
|
2691
|
-
} =
|
|
2715
|
+
} = _ref67;
|
|
2692
2716
|
const meta = {
|
|
2693
2717
|
name: name,
|
|
2694
2718
|
parentAddress
|
|
@@ -2734,10 +2758,10 @@ class KoniExtension {
|
|
|
2734
2758
|
}
|
|
2735
2759
|
return true;
|
|
2736
2760
|
}
|
|
2737
|
-
derivationCreateV3(
|
|
2761
|
+
derivationCreateV3(_ref68) {
|
|
2738
2762
|
let {
|
|
2739
2763
|
address: parentAddress
|
|
2740
|
-
} =
|
|
2764
|
+
} = _ref68;
|
|
2741
2765
|
const parentPair = _uiKeyring.keyring.getPair(parentAddress);
|
|
2742
2766
|
const isEvm = parentPair.type === 'ethereum';
|
|
2743
2767
|
if (parentPair.isLocked) {
|
|
@@ -2769,11 +2793,11 @@ class KoniExtension {
|
|
|
2769
2793
|
});
|
|
2770
2794
|
return true;
|
|
2771
2795
|
}
|
|
2772
|
-
validateDerivePath(
|
|
2796
|
+
validateDerivePath(_ref69) {
|
|
2773
2797
|
let {
|
|
2774
2798
|
parentAddress,
|
|
2775
2799
|
suri
|
|
2776
|
-
} =
|
|
2800
|
+
} = _ref69;
|
|
2777
2801
|
const parentPair = _uiKeyring.keyring.getPair(parentAddress);
|
|
2778
2802
|
const isEvm = parentPair.type === 'ethereum';
|
|
2779
2803
|
if (parentPair.isLocked) {
|
|
@@ -2806,12 +2830,12 @@ class KoniExtension {
|
|
|
2806
2830
|
suri: meta.suri
|
|
2807
2831
|
};
|
|
2808
2832
|
}
|
|
2809
|
-
getListDeriveAccounts(
|
|
2833
|
+
getListDeriveAccounts(_ref70) {
|
|
2810
2834
|
let {
|
|
2811
2835
|
limit,
|
|
2812
2836
|
page,
|
|
2813
2837
|
parentAddress
|
|
2814
|
-
} =
|
|
2838
|
+
} = _ref70;
|
|
2815
2839
|
const parentPair = _uiKeyring.keyring.getPair(parentAddress);
|
|
2816
2840
|
const isEvm = parentPair.type === 'ethereum';
|
|
2817
2841
|
if (parentPair.isLocked) {
|
|
@@ -2902,10 +2926,10 @@ class KoniExtension {
|
|
|
2902
2926
|
getSupportedSmartContractTypes() {
|
|
2903
2927
|
return this.#koniState.getSupportedSmartContractTypes();
|
|
2904
2928
|
}
|
|
2905
|
-
getTransaction(
|
|
2929
|
+
getTransaction(_ref71) {
|
|
2906
2930
|
let {
|
|
2907
2931
|
id
|
|
2908
|
-
} =
|
|
2932
|
+
} = _ref71;
|
|
2909
2933
|
const {
|
|
2910
2934
|
transaction,
|
|
2911
2935
|
...transactionResult
|
|
@@ -2915,8 +2939,8 @@ class KoniExtension {
|
|
|
2915
2939
|
subscribeTransactions(id, port) {
|
|
2916
2940
|
const cb = (0, _subscriptions.createSubscription)(id, port);
|
|
2917
2941
|
function convertRs(rs) {
|
|
2918
|
-
return Object.fromEntries(Object.entries(rs).map(
|
|
2919
|
-
let [key, value] =
|
|
2942
|
+
return Object.fromEntries(Object.entries(rs).map(_ref72 => {
|
|
2943
|
+
let [key, value] = _ref72;
|
|
2920
2944
|
const {
|
|
2921
2945
|
additionalValidator,
|
|
2922
2946
|
transaction,
|
|
@@ -2947,10 +2971,10 @@ class KoniExtension {
|
|
|
2947
2971
|
});
|
|
2948
2972
|
return notificationSubject.value;
|
|
2949
2973
|
}
|
|
2950
|
-
async reloadCron(
|
|
2974
|
+
async reloadCron(_ref73) {
|
|
2951
2975
|
let {
|
|
2952
2976
|
data
|
|
2953
|
-
} =
|
|
2977
|
+
} = _ref73;
|
|
2954
2978
|
if (data === 'nft') {
|
|
2955
2979
|
return await this.#koniState.reloadNft();
|
|
2956
2980
|
} else if (data === 'staking') {
|
|
@@ -2968,10 +2992,10 @@ class KoniExtension {
|
|
|
2968
2992
|
|
|
2969
2993
|
// Phishing detect
|
|
2970
2994
|
|
|
2971
|
-
async passPhishingPage(
|
|
2995
|
+
async passPhishingPage(_ref74) {
|
|
2972
2996
|
let {
|
|
2973
2997
|
url
|
|
2974
|
-
} =
|
|
2998
|
+
} = _ref74;
|
|
2975
2999
|
return await this.#koniState.approvePassPhishingPage(url);
|
|
2976
3000
|
}
|
|
2977
3001
|
|
package/cjs/packageInfo.js
CHANGED
|
@@ -66,7 +66,9 @@ const _STAKING_CHAIN_GROUP = {
|
|
|
66
66
|
kilt: ['kilt', 'kilt_peregrine'],
|
|
67
67
|
nominationPool: ['polkadot', 'kusama', 'westend', 'alephTest', 'aleph'],
|
|
68
68
|
bifrost: ['bifrost', 'bifrost_testnet'],
|
|
69
|
-
aleph: ['aleph', 'alephTest']
|
|
69
|
+
aleph: ['aleph', 'alephTest'],
|
|
70
|
+
// A0 has distinct tokenomics
|
|
71
|
+
ternoa: ['ternoa', 'ternoa_alphanet']
|
|
70
72
|
};
|
|
71
73
|
exports._STAKING_CHAIN_GROUP = _STAKING_CHAIN_GROUP;
|
|
72
74
|
const _STAKING_ERA_LENGTH_MAP = {
|
|
@@ -168,14 +168,15 @@ export async function getAstarNominatorMetadata(chainInfo, address, substrateApi
|
|
|
168
168
|
const dAppInfoMap = {};
|
|
169
169
|
const allDapps = await allDappsReq;
|
|
170
170
|
allDapps.forEach(dappInfo => {
|
|
171
|
-
|
|
171
|
+
const address = isEthereumAddress(dappInfo.address) ? dappInfo.address.toLowerCase() : dappInfo.address;
|
|
172
|
+
dAppInfoMap[address] = dappInfo;
|
|
172
173
|
});
|
|
173
174
|
for (const item of _stakerInfo) {
|
|
174
175
|
const data = item[0].toHuman();
|
|
175
176
|
const stakedDapp = data[1];
|
|
176
177
|
const stakeData = item[1].toPrimitive();
|
|
177
178
|
const stakeList = stakeData.stakes;
|
|
178
|
-
const dappAddress = stakedDapp.Evm.toLowerCase();
|
|
179
|
+
const dappAddress = isEthereumAddress(stakedDapp.Evm) ? stakedDapp.Evm.toLowerCase() : stakedDapp.Evm;
|
|
179
180
|
const currentStake = stakeList.slice(-1)[0].staked.toString() || '0';
|
|
180
181
|
const bnCurrentStake = new BN(currentStake);
|
|
181
182
|
if (bnCurrentStake.gt(BN_ZERO)) {
|
|
@@ -185,7 +186,7 @@ export async function getAstarNominatorMetadata(chainInfo, address, substrateApi
|
|
|
185
186
|
nominationList.push({
|
|
186
187
|
status: dappStakingStatus,
|
|
187
188
|
chain,
|
|
188
|
-
validatorAddress: dappAddress
|
|
189
|
+
validatorAddress: dappAddress,
|
|
189
190
|
activeStake: currentStake,
|
|
190
191
|
validatorMinStake: '0',
|
|
191
192
|
validatorIdentity: dappInfo === null || dappInfo === void 0 ? void 0 : dappInfo.name,
|
|
@@ -318,7 +319,7 @@ export async function getAstarClaimRewardExtrinsic(substrateApi, address) {
|
|
|
318
319
|
const stakedDapp = data[1];
|
|
319
320
|
const stakeData = item[1].toHuman();
|
|
320
321
|
const stakes = stakeData.stakes;
|
|
321
|
-
const dappAddress = stakedDapp.Evm.toLowerCase();
|
|
322
|
+
const dappAddress = isEthereumAddress(stakedDapp.Evm) ? stakedDapp.Evm.toLowerCase() : stakedDapp.Evm;
|
|
322
323
|
let numberOfUnclaimedEra = 0;
|
|
323
324
|
const maxTx = 50;
|
|
324
325
|
for (let i = 0; i < stakes.length; i++) {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
5
5
|
import { StakingStatus, StakingTxErrorType, StakingType, UnstakingStatus } from '@subwallet/extension-base/background/KoniTypes';
|
|
6
|
-
import { calculateAlephZeroValidatorReturn, calculateChainStakedReturn, calculateInflation, calculateValidatorStakedReturn, getCommission, parseIdentity, parsePoolStashAddress, transformPoolName } from '@subwallet/extension-base/koni/api/staking/bonding/utils';
|
|
6
|
+
import { calculateAlephZeroValidatorReturn, calculateChainStakedReturn, calculateInflation, calculateTernoaValidatorReturn, calculateValidatorStakedReturn, getCommission, parseIdentity, parsePoolStashAddress, transformPoolName } from '@subwallet/extension-base/koni/api/staking/bonding/utils';
|
|
7
7
|
import { _STAKING_CHAIN_GROUP, _STAKING_ERA_LENGTH_MAP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
8
8
|
import { _getChainSubstrateAddressPrefix } from '@subwallet/extension-base/services/chain-service/utils';
|
|
9
9
|
import { reformatAddress } from '@subwallet/extension-base/utils';
|
|
@@ -138,7 +138,7 @@ export async function getRelayChainStakingMetadata(chainInfo, substrateApi) {
|
|
|
138
138
|
chain,
|
|
139
139
|
type: StakingType.NOMINATED,
|
|
140
140
|
era: parseInt(currentEra),
|
|
141
|
-
expectedReturn,
|
|
141
|
+
expectedReturn: !_STAKING_CHAIN_GROUP.ternoa.includes(chain) ? expectedReturn : undefined,
|
|
142
142
|
// in %, annually
|
|
143
143
|
inflation,
|
|
144
144
|
minStake: minStake.toString(),
|
|
@@ -477,7 +477,8 @@ export async function getRelayValidatorsInfo(chain, substrateApi, decimals, chai
|
|
|
477
477
|
const currentEra = _era.toString();
|
|
478
478
|
const allValidators = [];
|
|
479
479
|
const validatorInfoList = [];
|
|
480
|
-
const [_totalEraStake, _eraStakers, _minBond] = await Promise.all([chainApi.api.query.staking.erasTotalStake(parseInt(currentEra)), chainApi.api.query.staking.erasStakers.entries(parseInt(currentEra)), chainApi.api.query.staking.minNominatorBond()]);
|
|
480
|
+
const [_totalEraStake, _eraStakers, _minBond, _stakingRewards] = await Promise.all([chainApi.api.query.staking.erasTotalStake(parseInt(currentEra)), chainApi.api.query.staking.erasStakers.entries(parseInt(currentEra)), chainApi.api.query.staking.minNominatorBond(), chainApi.api.query.stakingRewards && chainApi.api.query.stakingRewards.data()]);
|
|
481
|
+
const stakingRewards = _stakingRewards === null || _stakingRewards === void 0 ? void 0 : _stakingRewards.toPrimitive();
|
|
481
482
|
const maxNominatorRewarded = chainApi.api.consts.staking.maxNominatorRewardedPerValidator.toString();
|
|
482
483
|
const bnTotalEraStake = new BN(_totalEraStake.toString());
|
|
483
484
|
const eraStakers = _eraStakers;
|
|
@@ -540,7 +541,15 @@ export async function getRelayValidatorsInfo(chain, substrateApi, decimals, chai
|
|
|
540
541
|
for (const validator of validatorInfoList) {
|
|
541
542
|
const commission = extraInfoMap[validator.address].commission;
|
|
542
543
|
const bnValidatorStake = totalStakeMap[validator.address].div(bnDecimals);
|
|
543
|
-
|
|
544
|
+
if (_STAKING_CHAIN_GROUP.aleph.includes(chain)) {
|
|
545
|
+
validator.expectedReturn = calculateAlephZeroValidatorReturn(chainStakingMetadata.expectedReturn, getCommission(commission));
|
|
546
|
+
} else if (_STAKING_CHAIN_GROUP.ternoa.includes(chain)) {
|
|
547
|
+
const rewardPerValidator = new BN(stakingRewards.sessionExtraRewardPayout).divn(allValidators.length).div(bnDecimals);
|
|
548
|
+
const validatorStake = totalStakeMap[validator.address].div(bnDecimals).toNumber();
|
|
549
|
+
validator.expectedReturn = calculateTernoaValidatorReturn(rewardPerValidator.toNumber(), validatorStake, getCommission(commission));
|
|
550
|
+
} else {
|
|
551
|
+
validator.expectedReturn = calculateValidatorStakedReturn(chainStakingMetadata.expectedReturn, bnValidatorStake, bnAvgStake, getCommission(commission));
|
|
552
|
+
}
|
|
544
553
|
validator.commission = parseFloat(commission.split('%')[0]);
|
|
545
554
|
validator.blocked = extraInfoMap[validator.address].blocked;
|
|
546
555
|
validator.identity = extraInfoMap[validator.address].identity;
|
|
@@ -102,6 +102,10 @@ export interface Unlocking {
|
|
|
102
102
|
remainingEras: BN;
|
|
103
103
|
value: BN;
|
|
104
104
|
}
|
|
105
|
+
export interface TernoaStakingRewardsStakingRewardsData {
|
|
106
|
+
sessionEraPayout: string;
|
|
107
|
+
sessionExtraRewardPayout: string;
|
|
108
|
+
}
|
|
105
109
|
export declare function parsePoolStashAddress(api: ApiPromise, index: number, poolId: number, poolsPalletId: string): string;
|
|
106
110
|
export declare function transformPoolName(input: string): string;
|
|
107
111
|
export declare function parseIdentity(identityInfo: PalletIdentityRegistration | null): string | undefined;
|
|
@@ -111,6 +115,7 @@ export declare function calcInflationRewardCurve(minInflation: number, stakedFra
|
|
|
111
115
|
export declare function calculateInflation(totalEraStake: BN, totalIssuance: BN, numAuctions: number, networkKey: string): number;
|
|
112
116
|
export declare function calculateChainStakedReturn(inflation: number, totalEraStake: BN, totalIssuance: BN, networkKey: string): number;
|
|
113
117
|
export declare function calculateAlephZeroValidatorReturn(chainStakedReturn: number, commission: number): number;
|
|
118
|
+
export declare function calculateTernoaValidatorReturn(rewardPerValidator: number, validatorStake: number, commission: number): number;
|
|
114
119
|
export declare function calculateValidatorStakedReturn(chainStakedReturn: number, totalValidatorStake: BN, avgStake: BN, commission: number): number;
|
|
115
120
|
export declare function getCommission(commissionString: string): number;
|
|
116
121
|
export interface InflationConfig {
|
|
@@ -86,6 +86,12 @@ export function calculateChainStakedReturn(inflation, totalEraStake, totalIssuan
|
|
|
86
86
|
export function calculateAlephZeroValidatorReturn(chainStakedReturn, commission) {
|
|
87
87
|
return chainStakedReturn * (100 - commission) / 100;
|
|
88
88
|
}
|
|
89
|
+
export function calculateTernoaValidatorReturn(rewardPerValidator, validatorStake, commission) {
|
|
90
|
+
const percentRewardForNominators = (100 - commission) / 100;
|
|
91
|
+
const rewardForNominators = rewardPerValidator * percentRewardForNominators;
|
|
92
|
+
const stakeRatio = rewardForNominators / validatorStake;
|
|
93
|
+
return stakeRatio * 365 * 100;
|
|
94
|
+
}
|
|
89
95
|
export function calculateValidatorStakedReturn(chainStakedReturn, totalValidatorStake, avgStake, commission) {
|
|
90
96
|
const bnAdjusted = avgStake.mul(BN_HUNDRED).div(totalValidatorStake);
|
|
91
97
|
const adjusted = bnAdjusted.toNumber() * chainStakedReturn;
|
|
@@ -6,7 +6,8 @@ import { TransactionError } from '@subwallet/extension-base/background/errors/Tr
|
|
|
6
6
|
import { isJsonPayload, SEED_DEFAULT_LENGTH, SEED_LENGTHS } from '@subwallet/extension-base/background/handlers/Extension';
|
|
7
7
|
import { withErrorLog } from '@subwallet/extension-base/background/handlers/helpers';
|
|
8
8
|
import { createSubscription } from '@subwallet/extension-base/background/handlers/subscriptions';
|
|
9
|
-
import { AccountExternalErrorCode, BasicTxErrorType, ChainType, ExternalRequestPromiseStatus, ExtrinsicType, StakingType, TransferTxErrorType } from '@subwallet/extension-base/background/KoniTypes';
|
|
9
|
+
import { AccountExternalErrorCode, BasicTxErrorType, BasicTxWarningCode, ChainType, ExternalRequestPromiseStatus, ExtrinsicType, StakingType, TransferTxErrorType } from '@subwallet/extension-base/background/KoniTypes';
|
|
10
|
+
import { TransactionWarning } from '@subwallet/extension-base/background/warnings/TransactionWarning';
|
|
10
11
|
import { ALL_ACCOUNT_KEY, ALL_GENESIS_HASH } from '@subwallet/extension-base/constants';
|
|
11
12
|
import { ALLOWED_PATH } from '@subwallet/extension-base/defaults';
|
|
12
13
|
import { parseSubstrateTransaction } from '@subwallet/extension-base/koni/api/dotsama/parseTransaction';
|
|
@@ -1423,6 +1424,17 @@ export default class KoniExtension {
|
|
|
1423
1424
|
}
|
|
1424
1425
|
const transferNativeAmount = isTransferNativeToken ? transferAmount.value : '0';
|
|
1425
1426
|
this.addContact(to);
|
|
1427
|
+
const additionalValidator = async inputTransaction => {
|
|
1428
|
+
if (!isTransferNativeToken) {
|
|
1429
|
+
const {
|
|
1430
|
+
value: balance
|
|
1431
|
+
} = await this.#koniState.balanceService.getTokenFreeBalance(from, networkKey, tokenSlug);
|
|
1432
|
+
const minAmount = tokenInfo.minAmount || '0';
|
|
1433
|
+
if (new BigN(balance).minus(transferAmount.value).lt(minAmount)) {
|
|
1434
|
+
inputTransaction.warnings.push(new TransactionWarning(BasicTxWarningCode.NOT_ENOUGH_EXISTENTIAL_DEPOSIT, ''));
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
};
|
|
1426
1438
|
return this.#koniState.transactionService.handleTransaction({
|
|
1427
1439
|
errors,
|
|
1428
1440
|
warnings,
|
|
@@ -1434,8 +1446,9 @@ export default class KoniExtension {
|
|
|
1434
1446
|
data: inputData,
|
|
1435
1447
|
extrinsicType: isTransferNativeToken ? ExtrinsicType.TRANSFER_BALANCE : ExtrinsicType.TRANSFER_TOKEN,
|
|
1436
1448
|
ignoreWarnings: transferAll,
|
|
1437
|
-
isTransferAll: transferAll,
|
|
1438
|
-
edAsWarning:
|
|
1449
|
+
isTransferAll: isTransferNativeToken ? transferAll : false,
|
|
1450
|
+
edAsWarning: true,
|
|
1451
|
+
additionalValidator: additionalValidator
|
|
1439
1452
|
});
|
|
1440
1453
|
}
|
|
1441
1454
|
validateCrossChainTransfer(destinationNetworkKey, sendingTokenSlug, sender, sendingValue) {
|
|
@@ -1524,8 +1537,11 @@ export default class KoniExtension {
|
|
|
1524
1537
|
disableChain(networkKey) {
|
|
1525
1538
|
return this.#koniState.disableChain(networkKey);
|
|
1526
1539
|
}
|
|
1527
|
-
async enableChain(
|
|
1528
|
-
|
|
1540
|
+
async enableChain({
|
|
1541
|
+
chainSlug,
|
|
1542
|
+
enableTokens
|
|
1543
|
+
}) {
|
|
1544
|
+
return await this.#koniState.enableChain(chainSlug, enableTokens);
|
|
1529
1545
|
}
|
|
1530
1546
|
async validateNetwork({
|
|
1531
1547
|
existedChainSlug,
|
|
@@ -1715,9 +1731,15 @@ export default class KoniExtension {
|
|
|
1715
1731
|
isSendingSelf
|
|
1716
1732
|
};
|
|
1717
1733
|
}
|
|
1718
|
-
async enableChains(
|
|
1734
|
+
async enableChains({
|
|
1735
|
+
chainSlugs,
|
|
1736
|
+
enableTokens
|
|
1737
|
+
}) {
|
|
1719
1738
|
try {
|
|
1720
|
-
await Promise.all(
|
|
1739
|
+
await Promise.all(chainSlugs.map(chainSlug => this.enableChain({
|
|
1740
|
+
chainSlug,
|
|
1741
|
+
enableTokens
|
|
1742
|
+
})));
|
|
1721
1743
|
} catch (e) {
|
|
1722
1744
|
return false;
|
|
1723
1745
|
}
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.0.7-
|
|
20
|
+
"version": "1.0.7-2",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -1698,10 +1698,10 @@
|
|
|
1698
1698
|
"@subsocial/types": "^0.6.8",
|
|
1699
1699
|
"@substrate/connect": "^0.7.26",
|
|
1700
1700
|
"@subwallet/chain-list": "^0.1.9",
|
|
1701
|
-
"@subwallet/extension-base": "^1.0.7-
|
|
1702
|
-
"@subwallet/extension-chains": "^1.0.7-
|
|
1703
|
-
"@subwallet/extension-dapp": "^1.0.7-
|
|
1704
|
-
"@subwallet/extension-inject": "^1.0.7-
|
|
1701
|
+
"@subwallet/extension-base": "^1.0.7-2",
|
|
1702
|
+
"@subwallet/extension-chains": "^1.0.7-2",
|
|
1703
|
+
"@subwallet/extension-dapp": "^1.0.7-2",
|
|
1704
|
+
"@subwallet/extension-inject": "^1.0.7-2",
|
|
1705
1705
|
"@subwallet/keyring": "^0.0.9",
|
|
1706
1706
|
"@subwallet/ui-keyring": "^0.0.9",
|
|
1707
1707
|
"@unique-nft/types": "^0.6.0-4",
|
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.0.7-
|
|
10
|
+
version: '1.0.7-2'
|
|
11
11
|
};
|
|
@@ -36,6 +36,7 @@ export declare const _STAKING_CHAIN_GROUP: {
|
|
|
36
36
|
nominationPool: string[];
|
|
37
37
|
bifrost: string[];
|
|
38
38
|
aleph: string[];
|
|
39
|
+
ternoa: string[];
|
|
39
40
|
};
|
|
40
41
|
export declare const _STAKING_ERA_LENGTH_MAP: Record<string, number>;
|
|
41
42
|
export declare const _PARACHAIN_INFLATION_DISTRIBUTION: Record<string, Record<string, number>>;
|
|
@@ -55,9 +55,10 @@ export const _STAKING_CHAIN_GROUP = {
|
|
|
55
55
|
kilt: ['kilt', 'kilt_peregrine'],
|
|
56
56
|
nominationPool: ['polkadot', 'kusama', 'westend', 'alephTest', 'aleph'],
|
|
57
57
|
bifrost: ['bifrost', 'bifrost_testnet'],
|
|
58
|
-
aleph: ['aleph', 'alephTest']
|
|
58
|
+
aleph: ['aleph', 'alephTest'],
|
|
59
|
+
// A0 has distinct tokenomics
|
|
60
|
+
ternoa: ['ternoa', 'ternoa_alphanet']
|
|
59
61
|
};
|
|
60
|
-
|
|
61
62
|
export const _STAKING_ERA_LENGTH_MAP = {
|
|
62
63
|
// in hours
|
|
63
64
|
alephTest: 24,
|
|
@@ -93,6 +93,14 @@ export declare type _NetworkUpsertParams = {
|
|
|
93
93
|
providerError?: _CHAIN_VALIDATION_ERROR;
|
|
94
94
|
};
|
|
95
95
|
export declare const _CUSTOM_PREFIX = "custom-";
|
|
96
|
+
export interface EnableChainParams {
|
|
97
|
+
chainSlug: string;
|
|
98
|
+
enableTokens?: boolean;
|
|
99
|
+
}
|
|
100
|
+
export interface EnableMultiChainParams {
|
|
101
|
+
chainSlugs: string[];
|
|
102
|
+
enableTokens?: boolean;
|
|
103
|
+
}
|
|
96
104
|
export interface _ValidateCustomAssetRequest {
|
|
97
105
|
contractAddress: string;
|
|
98
106
|
originChain: string;
|