@subwallet/extension-base 1.0.7-1 → 1.0.8-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.
Files changed (55) hide show
  1. package/background/KoniTypes.d.ts +6 -4
  2. package/background/KoniTypes.js +1 -0
  3. package/background/errors/TransactionError.js +5 -1
  4. package/cjs/background/KoniTypes.js +1 -0
  5. package/cjs/background/errors/TransactionError.js +4 -0
  6. package/cjs/constants/index.js +6 -3
  7. package/cjs/koni/api/dotsama/balance.js +2 -1
  8. package/cjs/koni/api/dotsama/crowdloan.js +1 -1
  9. package/cjs/koni/api/dotsama/transfer.js +2 -2
  10. package/cjs/koni/api/staking/bonding/astar.js +5 -4
  11. package/cjs/koni/api/staking/bonding/relayChain.js +12 -3
  12. package/cjs/koni/api/staking/bonding/utils.js +7 -0
  13. package/cjs/koni/api/xcm/polkadotXcm.js +18 -37
  14. package/cjs/koni/api/xcm/utils.js +78 -11
  15. package/cjs/koni/api/xcm/xTokens.js +4 -33
  16. package/cjs/koni/api/xcm/xcmPallet.js +4 -36
  17. package/cjs/koni/background/handlers/Extension.js +179 -97
  18. package/cjs/koni/background/handlers/State.js +1 -1
  19. package/cjs/packageInfo.js +1 -1
  20. package/cjs/services/chain-service/constants.js +8 -6
  21. package/cjs/services/chain-service/index.js +19 -15
  22. package/cjs/services/chain-service/utils.js +1 -5
  23. package/cjs/services/transaction-service/helpers/index.js +45 -2
  24. package/cjs/services/transaction-service/index.js +58 -24
  25. package/cjs/utils/number.js +112 -0
  26. package/constants/index.d.ts +1 -0
  27. package/constants/index.js +1 -0
  28. package/koni/api/dotsama/balance.js +2 -1
  29. package/koni/api/dotsama/crowdloan.js +2 -2
  30. package/koni/api/dotsama/transfer.js +2 -2
  31. package/koni/api/staking/bonding/astar.js +5 -4
  32. package/koni/api/staking/bonding/relayChain.js +13 -4
  33. package/koni/api/staking/bonding/utils.d.ts +5 -0
  34. package/koni/api/staking/bonding/utils.js +6 -0
  35. package/koni/api/xcm/polkadotXcm.js +20 -39
  36. package/koni/api/xcm/utils.d.ts +36 -3
  37. package/koni/api/xcm/utils.js +72 -11
  38. package/koni/api/xcm/xTokens.js +6 -35
  39. package/koni/api/xcm/xcmPallet.js +5 -35
  40. package/koni/background/handlers/Extension.js +109 -29
  41. package/koni/background/handlers/State.js +2 -2
  42. package/package.json +13 -8
  43. package/packageInfo.js +1 -1
  44. package/services/chain-service/constants.d.ts +1 -0
  45. package/services/chain-service/constants.js +8 -7
  46. package/services/chain-service/index.js +13 -8
  47. package/services/chain-service/types.d.ts +8 -0
  48. package/services/chain-service/utils.d.ts +0 -1
  49. package/services/chain-service/utils.js +1 -4
  50. package/services/transaction-service/helpers/index.d.ts +2 -0
  51. package/services/transaction-service/helpers/index.js +42 -0
  52. package/services/transaction-service/index.js +54 -20
  53. package/services/transaction-service/types.d.ts +2 -2
  54. package/utils/number.d.ts +9 -0
  55. package/utils/number.js +100 -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';
@@ -386,6 +386,7 @@ export interface AmountData extends BasicTokenInfo {
386
386
  }
387
387
  export interface XCMTransactionAdditionalInfo {
388
388
  destinationChain: string;
389
+ originalChain: string;
389
390
  fee?: AmountData;
390
391
  }
391
392
  export interface NFTTransactionAdditionalInfo {
@@ -458,7 +459,8 @@ export declare enum TransferTxErrorType {
458
459
  NOT_ENOUGH_VALUE = "NOT_ENOUGH_VALUE",
459
460
  NOT_ENOUGH_FEE = "NOT_ENOUGH_FEE",
460
461
  INVALID_TOKEN = "INVALID_TOKEN",
461
- TRANSFER_ERROR = "TRANSFER_ERROR"
462
+ TRANSFER_ERROR = "TRANSFER_ERROR",
463
+ RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT = "RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT"
462
464
  }
463
465
  export declare type TransactionErrorType = BasicTxErrorType | TransferTxErrorType | StakingTxErrorType;
464
466
  export declare enum BasicTxWarningCode {
@@ -1415,9 +1417,9 @@ export interface KoniRequestSignatures {
1415
1417
  'pri(chainService.subscribeMultiChainAssetMap)': [null, Record<string, _MultiChainAsset>, Record<string, _MultiChainAsset>];
1416
1418
  'pri(chainService.subscribeXcmRefMap)': [null, Record<string, _AssetRef>, Record<string, _AssetRef>];
1417
1419
  'pri(chainService.upsertChain)': [_NetworkUpsertParams, boolean];
1418
- 'pri(chainService.enableChains)': [string[], boolean];
1420
+ 'pri(chainService.enableChains)': [EnableMultiChainParams, boolean];
1421
+ 'pri(chainService.enableChain)': [EnableChainParams, boolean];
1419
1422
  'pri(chainService.disableChains)': [string[], boolean];
1420
- 'pri(chainService.enableChain)': [string, boolean];
1421
1423
  'pri(chainService.disableChain)': [string, boolean];
1422
1424
  'pri(chainService.removeChain)': [string, boolean];
1423
1425
  'pri(chainService.deleteCustomAsset)': [string, boolean];
@@ -120,6 +120,7 @@ export let TransferTxErrorType;
120
120
  TransferTxErrorType["NOT_ENOUGH_FEE"] = "NOT_ENOUGH_FEE";
121
121
  TransferTxErrorType["INVALID_TOKEN"] = "INVALID_TOKEN";
122
122
  TransferTxErrorType["TRANSFER_ERROR"] = "TRANSFER_ERROR";
123
+ TransferTxErrorType["RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT"] = "RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT";
123
124
  })(TransferTxErrorType || (TransferTxErrorType = {}));
124
125
  export let BasicTxWarningCode;
125
126
  (function (BasicTxWarningCode) {
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { SWError } from '@subwallet/extension-base/background/errors/SWError';
5
- import { BasicTxErrorType, StakingTxErrorType } from '@subwallet/extension-base/background/KoniTypes';
5
+ import { BasicTxErrorType, StakingTxErrorType, TransferTxErrorType } from '@subwallet/extension-base/background/KoniTypes';
6
6
 
7
7
  // Todo: finish this map in the future
8
8
  const defaultErrorMap = {
@@ -77,6 +77,10 @@ const defaultErrorMap = {
77
77
  [StakingTxErrorType.INACTIVE_NOMINATION_POOL]: {
78
78
  message: 'This nomination pool is not active',
79
79
  code: undefined
80
+ },
81
+ [TransferTxErrorType.RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT]: {
82
+ message: 'Receiver is not enough existential deposit',
83
+ code: undefined
80
84
  }
81
85
  };
82
86
  export class TransactionError extends SWError {
@@ -127,6 +127,7 @@ exports.TransferTxErrorType = TransferTxErrorType;
127
127
  TransferTxErrorType["NOT_ENOUGH_FEE"] = "NOT_ENOUGH_FEE";
128
128
  TransferTxErrorType["INVALID_TOKEN"] = "INVALID_TOKEN";
129
129
  TransferTxErrorType["TRANSFER_ERROR"] = "TRANSFER_ERROR";
130
+ TransferTxErrorType["RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT"] = "RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT";
130
131
  })(TransferTxErrorType || (exports.TransferTxErrorType = TransferTxErrorType = {}));
131
132
  let BasicTxWarningCode;
132
133
  exports.BasicTxWarningCode = BasicTxWarningCode;
@@ -82,6 +82,10 @@ const defaultErrorMap = {
82
82
  [_KoniTypes.StakingTxErrorType.INACTIVE_NOMINATION_POOL]: {
83
83
  message: 'This nomination pool is not active',
84
84
  code: undefined
85
+ },
86
+ [_KoniTypes.TransferTxErrorType.RECEIVER_NOT_ENOUGH_EXISTENTIAL_DEPOSIT]: {
87
+ message: 'Receiver is not enough existential deposit',
88
+ code: undefined
85
89
  }
86
90
  };
87
91
  class TransactionError extends _SWError.SWError {
@@ -22,9 +22,10 @@ var _exportNames = {
22
22
  ALL_NETWORK_KEY: true,
23
23
  ALL_GENESIS_HASH: true,
24
24
  IGNORE_GET_SUBSTRATE_FEATURES_LIST: true,
25
- IGNORE_QR_SIGNER: true
25
+ IGNORE_QR_SIGNER: true,
26
+ XCM_MIN_AMOUNT_RATIO: true
26
27
  };
27
- exports.SUB_TOKEN_REFRESH_BALANCE_INTERVAL = exports.IGNORE_QR_SIGNER = exports.IGNORE_GET_SUBSTRATE_FEATURES_LIST = exports.CRON_REFRESH_STAKING_REWARD_INTERVAL = exports.CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = exports.CRON_REFRESH_PRICE_INTERVAL = exports.CRON_REFRESH_NFT_INTERVAL = exports.CRON_REFRESH_HISTORY_INTERVAL = exports.CRON_REFRESH_CHAIN_STAKING_METADATA = exports.CRON_REFRESH_CHAIN_NOMINATOR_METADATA = exports.CRON_RECOVER_HISTORY_INTERVAL = exports.CRON_GET_API_MAP_STATUS = exports.CRON_AUTO_RECOVER_WEB3_INTERVAL = exports.CRON_AUTO_RECOVER_DOTSAMA_INTERVAL = exports.ASTAR_REFRESH_BALANCE_INTERVAL = exports.ALL_NETWORK_KEY = exports.ALL_GENESIS_HASH = exports.ALL_ACCOUNT_KEY = exports.ACALA_REFRESH_CROWDLOAN_INTERVAL = void 0;
28
+ exports.XCM_MIN_AMOUNT_RATIO = exports.SUB_TOKEN_REFRESH_BALANCE_INTERVAL = exports.IGNORE_QR_SIGNER = exports.IGNORE_GET_SUBSTRATE_FEATURES_LIST = exports.CRON_REFRESH_STAKING_REWARD_INTERVAL = exports.CRON_REFRESH_STAKING_REWARD_FAST_INTERVAL = exports.CRON_REFRESH_PRICE_INTERVAL = exports.CRON_REFRESH_NFT_INTERVAL = exports.CRON_REFRESH_HISTORY_INTERVAL = exports.CRON_REFRESH_CHAIN_STAKING_METADATA = exports.CRON_REFRESH_CHAIN_NOMINATOR_METADATA = exports.CRON_RECOVER_HISTORY_INTERVAL = exports.CRON_GET_API_MAP_STATUS = exports.CRON_AUTO_RECOVER_WEB3_INTERVAL = exports.CRON_AUTO_RECOVER_DOTSAMA_INTERVAL = exports.ASTAR_REFRESH_BALANCE_INTERVAL = exports.ALL_NETWORK_KEY = exports.ALL_GENESIS_HASH = exports.ALL_ACCOUNT_KEY = exports.ACALA_REFRESH_CROWDLOAN_INTERVAL = void 0;
28
29
  var _staking = require("./staking");
29
30
  Object.keys(_staking).forEach(function (key) {
30
31
  if (key === "default" || key === "__esModule") return;
@@ -77,4 +78,6 @@ exports.ALL_GENESIS_HASH = ALL_GENESIS_HASH;
77
78
  const IGNORE_GET_SUBSTRATE_FEATURES_LIST = ['astarEvm', 'ethereum', 'ethereum_goerli', 'binance', 'binance_test', 'boba_rinkeby', 'boba', 'bobabase', 'bobabeam'];
78
79
  exports.IGNORE_GET_SUBSTRATE_FEATURES_LIST = IGNORE_GET_SUBSTRATE_FEATURES_LIST;
79
80
  const IGNORE_QR_SIGNER = [];
80
- exports.IGNORE_QR_SIGNER = IGNORE_QR_SIGNER;
81
+ exports.IGNORE_QR_SIGNER = IGNORE_QR_SIGNER;
82
+ const XCM_MIN_AMOUNT_RATIO = 1.2;
83
+ exports.XCM_MIN_AMOUNT_RATIO = XCM_MIN_AMOUNT_RATIO;
@@ -296,10 +296,11 @@ async function subscribeTokensAccountsPallet(addresses, chain, api, callBack, in
296
296
  const unsubList = await Promise.all(Object.values(tokenMap).map(async tokenInfo => {
297
297
  try {
298
298
  const onChainInfo = (0, _utils2._getTokenOnChainInfo)(tokenInfo);
299
+ const assetId = (0, _utils2._getTokenOnChainAssetId)(tokenInfo);
299
300
 
300
301
  // Get Token Balance
301
302
  // @ts-ignore
302
- return await api.query.tokens.accounts.multi(addresses.map(address => [address, onChainInfo]), balances => {
303
+ return await api.query.tokens.accounts.multi(addresses.map(address => [address, onChainInfo || assetId]), balances => {
303
304
  const tokenBalance = {
304
305
  reserved: (0, _utils3.sumBN)(balances.map(b => b.reserved || new _util.BN(0))),
305
306
  frozen: (0, _utils3.sumBN)(balances.map(b => b.frozen || new _util.BN(0))),
@@ -112,7 +112,7 @@ async function subscribeCrowdloan(addresses, substrateApiMap, callback, chainInf
112
112
  });
113
113
  Object.entries(chainInfoMap).forEach(_ref3 => {
114
114
  let [networkKey, chainInfo] = _ref3;
115
- if ((0, _utils._isSubstrateParachain)(chainInfo)) {
115
+ if ((0, _utils._isSubstrateParaChain)(chainInfo)) {
116
116
  const parentChain = (0, _utils._getSubstrateRelayParent)(chainInfo);
117
117
  const crowdloanCb = rs => {
118
118
  callback(networkKey, rs);
@@ -127,9 +127,9 @@ const createTransferExtrinsic = async _ref => {
127
127
  transfer = api.tx.currencies.transfer(to, (0, _utils2._getTokenOnChainInfo)(tokenInfo), value);
128
128
  } else if (_constants._TRANSFER_CHAIN_GROUP.kintsugi.includes(networkKey) && !(0, _utils2._isNativeToken)(tokenInfo) && isTxTokensSupported) {
129
129
  if (transferAll) {
130
- transfer = api.tx.tokens.transferAll(to, (0, _utils2._getTokenOnChainInfo)(tokenInfo), false);
130
+ transfer = api.tx.tokens.transferAll(to, (0, _utils2._getTokenOnChainInfo)(tokenInfo) || (0, _utils2._getTokenOnChainAssetId)(tokenInfo), false);
131
131
  } else if (value) {
132
- transfer = api.tx.tokens.transfer(to, (0, _utils2._getTokenOnChainInfo)(tokenInfo), new _util.BN(value));
132
+ transfer = api.tx.tokens.transfer(to, (0, _utils2._getTokenOnChainInfo)(tokenInfo) || (0, _utils2._getTokenOnChainAssetId)(tokenInfo), new _util.BN(value));
133
133
  }
134
134
  } else if (_constants._TRANSFER_CHAIN_GROUP.genshiro.includes(networkKey) && !(0, _utils2._isNativeToken)(tokenInfo) && isTxEqBalancesSupported) {
135
135
  transfer = api.tx.eqBalances.transfer([(0, _utils2._getTokenOnChainAssetId)(tokenInfo)], to, value);
@@ -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
- dAppInfoMap[dappInfo.address.toLowerCase()] = dappInfo;
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.toLowerCase(),
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
- validator.expectedReturn = _constants._STAKING_CHAIN_GROUP.aleph.includes(chain) ? (0, _utils.calculateAlephZeroValidatorReturn)(chainStakingMetadata.expectedReturn, (0, _utils.getCommission)(commission)) : (0, _utils.calculateValidatorStakedReturn)(chainStakingMetadata.expectedReturn, bnValidatorStake, bnAvgStake, (0, _utils.getCommission)(commission));
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;
@@ -9,47 +9,28 @@ var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
9
9
  // Copyright 2019-2022 @subwallet/extension-base
10
10
  // SPDX-License-Identifier: Apache-2.0
11
11
 
12
- function getDestinationChainLocation(destinationChainInfo) {
13
- if ((0, _utils2._isSubstrateParaChain)(destinationChainInfo)) {
14
- return {
15
- V1: {
16
- parents: 1,
17
- interior: {
18
- X1: {
19
- Parachain: (0, _utils2._getSubstrateParaId)(destinationChainInfo)
20
- }
21
- }
22
- }
23
- };
24
- }
25
- return {
26
- // to relaychain by default
27
- V1: {
28
- parents: 1,
29
- interior: 'Here'
30
- }
31
- };
32
- }
33
- function getAssetLocation(tokenInfo, sendingValue) {
34
- const multilocation = (0, _utils2._getXcmAssetMultilocation)(tokenInfo);
35
- return {
36
- V1: [{
37
- id: multilocation,
38
- fun: {
39
- Fungible: sendingValue
40
- }
41
- }]
42
- };
43
- }
44
12
  function getExtrinsicByPolkadotXcmPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
45
13
  const weightParam = (0, _utils.getDestWeight)();
46
- const beneficiary = (0, _utils.getBeneficiary)(originChainInfo, destinationChainInfo, recipientAddress);
47
- const destination = getDestinationChainLocation(destinationChainInfo);
48
- const assetLocation = getAssetLocation(tokenInfo, value);
14
+ const beneficiary = (0, _utils.getBeneficiary)(destinationChainInfo, recipientAddress);
15
+ const destination = (0, _utils.getDestinationChainLocation)(originChainInfo, destinationChainInfo);
16
+ let assetLocation = (0, _utils.getTokenLocation)(tokenInfo, value);
49
17
  let method = 'limitedReserveTransferAssets';
50
- if (['astar', 'shiden'].includes(originChainInfo.slug)) {
18
+ if (['astar', 'shiden'].includes(originChainInfo.slug) && !(0, _utils2._isNativeToken)(tokenInfo)) {
51
19
  method = 'limitedReserveWithdrawAssets';
52
- } else if ((0, _utils2._isSubstrateRelayChain)(destinationChainInfo)) {
20
+ } else if (['statemint', 'statemine'].includes(originChainInfo.slug) && (0, _utils2._isSubstrateRelayChain)(destinationChainInfo)) {
21
+ assetLocation = {
22
+ V1: [{
23
+ id: {
24
+ Concrete: {
25
+ parents: 1,
26
+ interior: 'Here'
27
+ }
28
+ },
29
+ fun: {
30
+ Fungible: value
31
+ }
32
+ }]
33
+ };
53
34
  method = 'limitedTeleportAssets';
54
35
  }
55
36
  return api.tx.polkadotXcm[method](destination, beneficiary, assetLocation, 0,
@@ -5,8 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.FOUR_INSTRUCTIONS_WEIGHT = exports.FOUR_INSTRUCTIONS_LIMITED_WEIGHT = void 0;
7
7
  exports.getBeneficiary = getBeneficiary;
8
+ exports.getDestMultilocation = getDestMultilocation;
8
9
  exports.getDestWeight = getDestWeight;
10
+ exports.getDestinationChainLocation = getDestinationChainLocation;
9
11
  exports.getReceiverLocation = getReceiverLocation;
12
+ exports.getTokenLocation = getTokenLocation;
10
13
  var _chainList = require("@subwallet/chain-list");
11
14
  var _utils = require("@subwallet/extension-base/services/chain-service/utils");
12
15
  var _utilCrypto = require("@polkadot/util-crypto");
@@ -21,13 +24,14 @@ const FOUR_INSTRUCTIONS_LIMITED_WEIGHT = {
21
24
 
22
25
  // get multilocation for destination chain from a parachain
23
26
  exports.FOUR_INSTRUCTIONS_LIMITED_WEIGHT = FOUR_INSTRUCTIONS_LIMITED_WEIGHT;
24
- function getReceiverLocation(originChainInfo, destinationChainInfo, toAddress) {
27
+ function getReceiverLocation(destinationChainInfo, toAddress, version) {
28
+ const network = version && version === 'V3' ? undefined : 'Any';
25
29
  if (destinationChainInfo.slug === _chainList.COMMON_CHAIN_SLUGS.ASTAR_EVM) {
26
30
  const ss58Address = (0, _utilCrypto.evmToAddress)(toAddress, 2006); // TODO: shouldn't pass addressPrefix directly
27
31
 
28
32
  return {
29
33
  AccountId32: {
30
- network: 'Any',
34
+ network,
31
35
  id: (0, _utilCrypto.decodeAddress)(ss58Address)
32
36
  }
33
37
  };
@@ -35,21 +39,21 @@ function getReceiverLocation(originChainInfo, destinationChainInfo, toAddress) {
35
39
  if ((0, _utils._isChainEvmCompatible)(destinationChainInfo)) {
36
40
  return {
37
41
  AccountKey20: {
38
- network: 'Any',
42
+ network,
39
43
  key: toAddress
40
44
  }
41
45
  };
42
46
  }
43
47
  return {
44
48
  AccountId32: {
45
- network: 'Any',
49
+ network,
46
50
  id: (0, _utilCrypto.decodeAddress)(toAddress)
47
51
  }
48
52
  };
49
53
  }
50
- function getBeneficiary(originChainInfo, destinationChainInfo, recipientAddress) {
51
- let version = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'V1';
52
- const receiverLocation = getReceiverLocation(originChainInfo, destinationChainInfo, recipientAddress);
54
+ function getBeneficiary(destinationChainInfo, recipientAddress) {
55
+ let version = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'V1';
56
+ const receiverLocation = getReceiverLocation(destinationChainInfo, recipientAddress, version);
53
57
  return {
54
58
  [version]: {
55
59
  parents: 0,
@@ -61,8 +65,71 @@ function getBeneficiary(originChainInfo, destinationChainInfo, recipientAddress)
61
65
  }
62
66
  function getDestWeight() {
63
67
  return 'Unlimited';
64
- // return api.tx.xTokens.transfer.meta.args[3].type.toString() ===
65
- // 'XcmV2WeightLimit'
66
- // ? 'Unlimited'
67
- // : FOUR_INSTRUCTIONS_WEIGHT;
68
+ }
69
+ function getTokenLocation(tokenInfo, sendingValue) {
70
+ let version = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'V1';
71
+ if (!(0, _utils._isNativeToken)(tokenInfo)) {
72
+ const multilocation = (0, _utils._getXcmAssetMultilocation)(tokenInfo);
73
+ return {
74
+ [version]: [{
75
+ id: multilocation,
76
+ fun: {
77
+ Fungible: sendingValue
78
+ }
79
+ }]
80
+ };
81
+ }
82
+ return {
83
+ [version]: [{
84
+ id: {
85
+ Concrete: {
86
+ parents: 0,
87
+ interior: 'Here'
88
+ }
89
+ },
90
+ fun: {
91
+ Fungible: sendingValue
92
+ }
93
+ }]
94
+ };
95
+ }
96
+ function getDestMultilocation(destinationChainInfo, recipient) {
97
+ let version = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'V1';
98
+ const receiverLocation = getReceiverLocation(destinationChainInfo, recipient, version);
99
+ if ((0, _utils._isSubstrateParaChain)(destinationChainInfo)) {
100
+ const interior = {
101
+ X2: [{
102
+ Parachain: (0, _utils._getSubstrateParaId)(destinationChainInfo)
103
+ }, receiverLocation]
104
+ };
105
+ return {
106
+ [version]: {
107
+ parents: 1,
108
+ interior
109
+ }
110
+ };
111
+ }
112
+ return {
113
+ [version]: {
114
+ parents: 1,
115
+ interior: {
116
+ X1: receiverLocation
117
+ }
118
+ }
119
+ };
120
+ }
121
+ function getDestinationChainLocation(originChainInfo, destinationChainInfo) {
122
+ let version = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'V1';
123
+ const parents = (0, _utils._isSubstrateRelayChain)(originChainInfo) ? 0 : 1;
124
+ const interior = (0, _utils._isSubstrateParaChain)(destinationChainInfo) ? {
125
+ X1: {
126
+ Parachain: (0, _utils._getSubstrateParaId)(destinationChainInfo)
127
+ }
128
+ } : 'Here';
129
+ return {
130
+ [version]: {
131
+ parents,
132
+ interior
133
+ }
134
+ };
68
135
  }
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getExtrinsicByXtokensPallet = getExtrinsicByXtokensPallet;
7
7
  var _utils = require("@subwallet/extension-base/koni/api/xcm/utils");
8
- var _constants = require("@subwallet/extension-base/services/chain-service/constants");
9
8
  var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
10
9
  // Copyright 2019-2022 @subwallet/extension-base
11
10
  // SPDX-License-Identifier: Apache-2.0
@@ -22,38 +21,10 @@ function getCurrencyId(tokenInfo) {
22
21
  } else if (['pioneer'].includes(tokenInfo.originChain)) {
23
22
  return (0, _utils2._getXcmAssetMultilocation)(tokenInfo);
24
23
  }
25
- return (0, _utils2._getTokenOnChainInfo)(tokenInfo);
26
- }
27
- function getMultiLocationForXtokensPallet(originChainInfo, destinationChainInfo, toAddress) {
28
- const xcmType = (0, _utils2._getXcmTransferType)(originChainInfo, destinationChainInfo);
29
- const paraId = (0, _utils2._getSubstrateParaId)(destinationChainInfo);
30
- const receiverLocation = (0, _utils.getReceiverLocation)(originChainInfo, destinationChainInfo, toAddress);
31
- if (xcmType === _constants._XCM_TYPE.PP) {
32
- // parachain -> parachain
33
- const interior = {
34
- X2: [{
35
- Parachain: paraId
36
- }, receiverLocation]
37
- };
38
- return {
39
- V1: {
40
- parents: 1,
41
- interior
42
- }
43
- };
44
- }
45
-
46
- // parachain -> relaychain by default
47
- return {
48
- V1: {
49
- parents: 1,
50
- interior: {
51
- X1: receiverLocation
52
- }
53
- }
54
- };
24
+ return (0, _utils2._getTokenOnChainInfo)(tokenInfo) || (0, _utils2._getTokenOnChainAssetId)(tokenInfo);
55
25
  }
56
26
  function getExtrinsicByXtokensPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
57
- const weightParam = ['pioneer'].includes(originChainInfo.slug) ? _utils.FOUR_INSTRUCTIONS_WEIGHT : (0, _utils.getDestWeight)();
58
- return api.tx.xTokens.transfer(getCurrencyId(tokenInfo), value, getMultiLocationForXtokensPallet(originChainInfo, destinationChainInfo, recipientAddress), weightParam);
27
+ const weightParam = ['pioneer', 'hydradx_main'].includes(originChainInfo.slug) ? _utils.FOUR_INSTRUCTIONS_WEIGHT : (0, _utils.getDestWeight)();
28
+ const destVersion = ['moonbeam', 'moonriver'].includes(originChainInfo.slug) ? 'V3' : undefined;
29
+ return api.tx.xTokens.transfer(getCurrencyId(tokenInfo), value, (0, _utils.getDestMultilocation)(destinationChainInfo, recipientAddress, destVersion), weightParam);
59
30
  }
@@ -5,48 +5,16 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.getExtrinsicByXcmPalletPallet = getExtrinsicByXcmPalletPallet;
7
7
  var _utils = require("@subwallet/extension-base/koni/api/xcm/utils");
8
- var _utils2 = require("@subwallet/extension-base/services/chain-service/utils");
9
8
  // Copyright 2019-2022 @subwallet/extension-base
10
9
  // SPDX-License-Identifier: Apache-2.0
11
10
 
12
- function getDestinationChainLocation(destinationChainInfo) {
13
- let version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'V1';
14
- return {
15
- [version]: {
16
- parents: 0,
17
- interior: {
18
- X1: {
19
- Parachain: (0, _utils2._getSubstrateParaId)(destinationChainInfo)
20
- }
21
- }
22
- }
23
- };
24
- }
25
- function getTokenLocation(sendingValue) {
26
- let version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'V2';
27
- return {
28
- // always native token of relaychain
29
- [version]: [{
30
- id: {
31
- Concrete: {
32
- parents: 0,
33
- interior: 'Here'
34
- }
35
- },
36
- fun: {
37
- Fungible: sendingValue
38
- }
39
- }]
40
- };
41
- }
42
-
43
11
  // this pallet is only used by Relaychains
44
12
  function getExtrinsicByXcmPalletPallet(tokenInfo, originChainInfo, destinationChainInfo, recipientAddress, value, api) {
45
13
  const weightParam = (0, _utils.getDestWeight)();
46
- const xcmVer = ['kusama'].includes(originChainInfo.slug) ? 'V2' : 'V1';
47
- const destination = getDestinationChainLocation(destinationChainInfo, xcmVer);
48
- const beneficiary = (0, _utils.getBeneficiary)(originChainInfo, destinationChainInfo, recipientAddress, xcmVer);
49
- const tokenLocation = getTokenLocation(value, xcmVer);
14
+ const xcmVer = ['kusama'].includes(originChainInfo.slug) ? 'V3' : 'V1';
15
+ const destination = (0, _utils.getDestinationChainLocation)(originChainInfo, destinationChainInfo, xcmVer);
16
+ const beneficiary = (0, _utils.getBeneficiary)(destinationChainInfo, recipientAddress, xcmVer);
17
+ const tokenLocation = (0, _utils.getTokenLocation)(tokenInfo, value, xcmVer);
50
18
  let method = 'limitedReserveTransferAssets';
51
19
  if (['statemint', 'statemine'].includes(destinationChainInfo.slug)) {
52
20
  method = 'limitedTeleportAssets';