@subwallet/extension-base 1.3.69-0 → 1.3.71-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/background/KoniTypes.d.ts +11 -0
- package/background/KoniTypes.js +68 -8
- package/cjs/background/KoniTypes.js +68 -8
- package/cjs/constants/blocked-actions.js +3 -0
- package/cjs/core/logic-validation/swap.js +0 -3
- package/cjs/core/substrate/system-pallet.js +0 -2
- package/cjs/koni/api/nft/wasm_nft/index.js +0 -1
- package/cjs/koni/api/staking/bonding/astar.js +0 -2
- package/cjs/koni/api/staking/bonding/paraChain.js +0 -3
- package/cjs/koni/api/staking/bonding/relayChain.js +2 -4
- package/cjs/koni/api/staking/bonding/utils.js +0 -4
- package/cjs/koni/background/cron.js +0 -1
- package/cjs/koni/background/handlers/Extension.js +216 -158
- package/cjs/koni/background/handlers/State.js +59 -54
- package/cjs/koni/background/handlers/Tabs.js +39 -34
- package/cjs/packageInfo.js +1 -1
- package/cjs/page/index.js +7 -0
- package/cjs/page/substrate/PostMessageProvider.js +3 -0
- package/cjs/services/balance-service/helpers/subscribe/cardano/utils.js +0 -1
- package/cjs/services/balance-service/helpers/subscribe/substrate/gear.js +0 -2
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +2 -3
- package/cjs/services/balance-service/helpers/subscribe/ton/utils.js +0 -3
- package/cjs/services/balance-service/index.js +103 -7
- package/cjs/services/balance-service/transfer/bitcoin-transfer.js +0 -1
- package/cjs/services/balance-service/transfer/cardano-transfer.js +1 -2
- package/cjs/services/balance-service/transfer/smart-contract.js +0 -1
- package/cjs/services/balance-service/transfer/token.js +0 -2
- package/cjs/services/balance-service/transfer/ton-transfer.js +0 -1
- package/cjs/services/balance-service/transfer/xcm/snowBridge.js +0 -1
- package/cjs/services/chain-service/constants.js +15 -4
- package/cjs/services/chain-service/handler/CardanoApi.js +3 -1
- package/cjs/services/chain-service/handler/SubstrateApi.js +0 -2
- package/cjs/services/chain-service/handler/light-client/index.js +1 -2
- package/cjs/services/chain-service/health-check/index.js +0 -1
- package/cjs/services/chain-service/health-check/utils/new-utils/chain-asset-validate.js +0 -1
- package/cjs/services/chain-service/index.js +18 -26
- package/cjs/services/chain-service/utils/index.js +34 -30
- package/cjs/services/earning-service/handlers/base.js +32 -0
- package/cjs/services/earning-service/handlers/lending/base.js +0 -2
- package/cjs/services/earning-service/handlers/liquid-staking/acala.js +0 -1
- package/cjs/services/earning-service/handlers/liquid-staking/base.js +0 -2
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +0 -2
- package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +0 -1
- package/cjs/services/earning-service/handlers/native-staking/astar.js +0 -2
- package/cjs/services/earning-service/handlers/native-staking/dtao.js +43 -2
- package/cjs/services/earning-service/handlers/native-staking/energy.js +0 -1
- package/cjs/services/earning-service/handlers/native-staking/mythos.js +0 -2
- package/cjs/services/earning-service/handlers/native-staking/para-chain.js +0 -2
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +8 -9
- package/cjs/services/earning-service/handlers/special.js +7 -0
- package/cjs/services/event-service/index.js +1 -0
- package/cjs/services/history-service/subsquid-multi-chain-history.js +0 -1
- package/cjs/services/keyring-service/context/handlers/Derive.js +1 -1
- package/cjs/services/keyring-service/context/handlers/Migration.js +11 -9
- package/cjs/services/keyring-service/context/handlers/Mnemonic.js +18 -13
- package/cjs/services/keyring-service/context/state.js +21 -3
- package/cjs/services/keyring-service/utils.js +12 -2
- package/cjs/services/migration-service/index.js +1 -2
- package/cjs/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +0 -1
- package/cjs/services/nft-service/index.js +5 -0
- package/cjs/services/open-gov/handler.js +561 -0
- package/cjs/services/open-gov/index.js +273 -0
- package/cjs/services/open-gov/interface.js +31 -0
- package/cjs/services/open-gov/utils.js +66 -0
- package/cjs/services/request-service/handler/BitcoinRequestHandler.js +1 -2
- package/cjs/services/request-service/handler/CardanoRequestHandler.js +0 -1
- package/cjs/services/request-service/handler/EvmRequestHandler.js +0 -1
- package/cjs/services/request-service/handler/TonRequestHandler.js +0 -1
- package/cjs/services/request-service/helper/index.js +1 -2
- package/cjs/services/storage-service/DatabaseService.js +19 -3
- package/cjs/services/storage-service/databases/index.js +5 -0
- package/cjs/services/storage-service/db-stores/GovLockedInfoStore.js +35 -0
- package/cjs/services/swap-service/handler/asset-hub/handler.js +0 -1
- package/cjs/services/swap-service/handler/asset-hub/router.js +0 -1
- package/cjs/services/swap-service/handler/chainflip-handler.js +1 -4
- package/cjs/services/swap-service/handler/hydradx-handler.js +0 -1
- package/cjs/services/swap-service/handler/kyber-handler.js +0 -1
- package/cjs/services/swap-service/handler/optimex-handler.js +1 -2
- package/cjs/services/swap-service/handler/simpleswap-handler.js +1 -3
- package/cjs/services/swap-service/handler/uniswap-handler.js +0 -3
- package/cjs/services/transaction-service/event-parser/index.js +6 -6
- package/cjs/services/transaction-service/helpers/index.js +6 -0
- package/cjs/services/transaction-service/index.js +71 -28
- package/cjs/services/wallet-connect-service/index.js +21 -18
- package/cjs/services/wallet-connect-service/types.js +1 -1
- package/cjs/types/account/info/keyring.js +9 -1
- package/cjs/types/balance/index.js +5 -1
- package/cjs/types/swap/index.js +2 -1
- package/cjs/types/transaction/process.js +2 -0
- package/cjs/types/yield/actions/join/step.js +17 -1
- package/cjs/utils/account/common.js +0 -26
- package/cjs/utils/account/derive/info/solo.js +7 -4
- package/cjs/utils/account/derive/validate.js +1 -1
- package/cjs/utils/account/transform.js +10 -5
- package/cjs/utils/auth.js +1 -1
- package/cjs/utils/bitcoin/utxo-management.js +0 -1
- package/cjs/utils/environment.js +2 -1
- package/cjs/utils/fee/transfer.js +1 -2
- package/cjs/utils/index.js +1 -2
- package/constants/blocked-actions.js +3 -0
- package/core/logic-validation/swap.js +0 -3
- package/core/substrate/system-pallet.js +0 -2
- package/koni/api/nft/wasm_nft/index.js +0 -1
- package/koni/api/staking/bonding/astar.js +0 -2
- package/koni/api/staking/bonding/paraChain.js +0 -3
- package/koni/api/staking/bonding/relayChain.js +2 -4
- package/koni/api/staking/bonding/utils.js +0 -4
- package/koni/background/cron.js +0 -1
- package/koni/background/handlers/Extension.d.ts +4 -0
- package/koni/background/handlers/Extension.js +70 -11
- package/koni/background/handlers/State.d.ts +2 -0
- package/koni/background/handlers/State.js +46 -40
- package/koni/background/handlers/Tabs.js +9 -3
- package/package.json +44 -20
- package/packageInfo.js +1 -1
- package/page/substrate/PostMessageProvider.js +3 -0
- package/services/balance-service/helpers/subscribe/cardano/utils.js +0 -1
- package/services/balance-service/helpers/subscribe/substrate/gear.js +0 -2
- package/services/balance-service/helpers/subscribe/substrate/index.js +0 -1
- package/services/balance-service/helpers/subscribe/ton/utils.js +0 -3
- package/services/balance-service/index.d.ts +8 -0
- package/services/balance-service/index.js +105 -9
- package/services/balance-service/transfer/bitcoin-transfer.js +0 -1
- package/services/balance-service/transfer/smart-contract.js +0 -1
- package/services/balance-service/transfer/token.js +0 -2
- package/services/balance-service/transfer/ton-transfer.js +0 -1
- package/services/balance-service/transfer/xcm/snowBridge.js +0 -1
- package/services/chain-service/constants.d.ts +8 -0
- package/services/chain-service/constants.js +12 -2
- package/services/chain-service/handler/CardanoApi.js +3 -1
- package/services/chain-service/handler/SubstrateApi.js +0 -2
- package/services/chain-service/health-check/index.js +0 -1
- package/services/chain-service/health-check/utils/new-utils/chain-asset-validate.js +0 -1
- package/services/chain-service/index.d.ts +0 -1
- package/services/chain-service/index.js +15 -23
- package/services/chain-service/utils/index.js +35 -31
- package/services/earning-service/handlers/base.js +32 -0
- package/services/earning-service/handlers/lending/base.js +0 -2
- package/services/earning-service/handlers/liquid-staking/acala.js +0 -1
- package/services/earning-service/handlers/liquid-staking/base.js +0 -2
- package/services/earning-service/handlers/liquid-staking/bifrost.js +0 -2
- package/services/earning-service/handlers/liquid-staking/parallel.js +0 -1
- package/services/earning-service/handlers/native-staking/astar.js +0 -2
- package/services/earning-service/handlers/native-staking/dtao.js +43 -0
- package/services/earning-service/handlers/native-staking/energy.js +0 -1
- package/services/earning-service/handlers/native-staking/mythos.js +0 -2
- package/services/earning-service/handlers/native-staking/para-chain.js +0 -2
- package/services/earning-service/handlers/native-staking/relay-chain.js +8 -9
- package/services/earning-service/handlers/special.js +7 -0
- package/services/event-service/index.d.ts +1 -0
- package/services/event-service/index.js +1 -0
- package/services/event-service/types.d.ts +1 -0
- package/services/history-service/subsquid-multi-chain-history.js +0 -1
- package/services/keyring-service/context/handlers/Derive.js +2 -2
- package/services/keyring-service/context/handlers/Migration.js +3 -1
- package/services/keyring-service/context/handlers/Mnemonic.d.ts +1 -1
- package/services/keyring-service/context/handlers/Mnemonic.js +16 -10
- package/services/keyring-service/context/state.d.ts +3 -0
- package/services/keyring-service/context/state.js +21 -3
- package/services/keyring-service/utils.d.ts +1 -0
- package/services/keyring-service/utils.js +9 -0
- package/services/mint-campaign-service/campaigns/UnlockDotCampaign.js +0 -1
- package/services/nft-service/index.js +6 -0
- package/services/open-gov/handler.d.ts +27 -0
- package/services/open-gov/handler.js +545 -0
- package/services/open-gov/index.d.ts +45 -0
- package/services/open-gov/index.js +265 -0
- package/services/open-gov/interface.d.ts +141 -0
- package/services/open-gov/interface.js +24 -0
- package/services/open-gov/utils.d.ts +14 -0
- package/services/open-gov/utils.js +52 -0
- package/services/request-service/handler/CardanoRequestHandler.js +0 -1
- package/services/request-service/handler/EvmRequestHandler.js +0 -1
- package/services/request-service/handler/TonRequestHandler.js +0 -1
- package/services/setting-service/constants.js +0 -1
- package/services/storage-service/DatabaseService.d.ts +7 -0
- package/services/storage-service/DatabaseService.js +19 -3
- package/services/storage-service/databases/index.d.ts +2 -0
- package/services/storage-service/databases/index.js +6 -0
- package/services/storage-service/db-stores/GovLockedInfoStore.d.ts +10 -0
- package/services/storage-service/db-stores/GovLockedInfoStore.js +27 -0
- package/services/swap-service/handler/asset-hub/handler.js +0 -1
- package/services/swap-service/handler/asset-hub/router.js +0 -1
- package/services/swap-service/handler/chainflip-handler.js +0 -2
- package/services/swap-service/handler/hydradx-handler.js +0 -1
- package/services/swap-service/handler/kyber-handler.js +0 -1
- package/services/swap-service/handler/simpleswap-handler.js +0 -1
- package/services/swap-service/handler/uniswap-handler.js +0 -3
- package/services/transaction-service/event-parser/index.js +6 -6
- package/services/transaction-service/helpers/index.js +6 -0
- package/services/transaction-service/index.js +43 -0
- package/services/wallet-connect-service/index.js +21 -18
- package/services/wallet-connect-service/types.js +1 -1
- package/types/account/action/add/mnemonic.d.ts +3 -2
- package/types/account/info/keyring.js +9 -1
- package/types/balance/index.js +5 -1
- package/types/swap/index.js +2 -1
- package/types/transaction/process.js +3 -1
- package/types/yield/actions/join/step.js +17 -1
- package/utils/account/common.d.ts +0 -3
- package/utils/account/common.js +0 -24
- package/utils/account/derive/info/solo.js +8 -5
- package/utils/account/derive/validate.d.ts +2 -2
- package/utils/account/derive/validate.js +1 -1
- package/utils/account/transform.js +10 -5
- package/utils/auth.js +2 -2
- package/utils/bitcoin/utxo-management.js +0 -1
- package/utils/index.js +2 -5
package/cjs/utils/environment.js
CHANGED
|
@@ -11,7 +11,8 @@ var _mv = require("@subwallet/extension-base/utils/mv3");
|
|
|
11
11
|
var _bowser = _interopRequireDefault(require("bowser"));
|
|
12
12
|
var _KoniTypes = require("../background/KoniTypes");
|
|
13
13
|
var _constants = require("../constants");
|
|
14
|
-
var _navigator3;
|
|
14
|
+
var _navigator3; // Copyright 2019-2022 @polkadot/extension authors & contributors
|
|
15
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
15
16
|
function detectRuntimeEnvironment() {
|
|
16
17
|
if (_mv.isSupportWindow && typeof document !== 'undefined') {
|
|
17
18
|
var _navigator, _window$location, _window$location2;
|
|
@@ -31,8 +31,7 @@ var bitcoin = _interopRequireWildcard(require("bitcoinjs-lib"));
|
|
|
31
31
|
var _util = require("@polkadot/util");
|
|
32
32
|
var _utilCrypto = require("@polkadot/util-crypto");
|
|
33
33
|
var _combine = require("./combine");
|
|
34
|
-
function
|
|
35
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
34
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
36
35
|
// Copyright 2019-2022 @subwallet/extension-base
|
|
37
36
|
// SPDX-License-Identifier: Apache-2.0
|
|
38
37
|
|
package/cjs/utils/index.js
CHANGED
|
@@ -602,7 +602,6 @@ function isSameAddress(address1, address2) {
|
|
|
602
602
|
}
|
|
603
603
|
return (0, _account.reformatAddress)(address1, 0) === (0, _account.reformatAddress)(address2, 0); // TODO: maybe there's a better way
|
|
604
604
|
}
|
|
605
|
-
|
|
606
605
|
function isSameAddressType(address1, address2) {
|
|
607
606
|
const isSameEvmAddress = (0, _utilCrypto.isEthereumAddress)(address1) && (0, _utilCrypto.isEthereumAddress)(address2);
|
|
608
607
|
const isSameTonAddress = (0, _keyring.isTonAddress)(address1) && (0, _keyring.isTonAddress)(address2);
|
|
@@ -614,7 +613,7 @@ function isAddressAndChainCompatible(address, chain) {
|
|
|
614
613
|
const keypairType = (0, _keyring.getKeypairTypeByAddress)(address);
|
|
615
614
|
const isEvmCompatible = (0, _utils._isChainEvmCompatible)(chain) && _types.EthereumKeypairTypes.includes(keypairType); // some chains compatible to substrate and evm, and use evm-address
|
|
616
615
|
const isTonCompatible = (0, _utils._isPureTonChain)(chain) && _types.TonKeypairTypes.includes(keypairType);
|
|
617
|
-
const isSubstrateCompatible = (0, _utils._isPureSubstrateChain)(chain) && _types.
|
|
616
|
+
const isSubstrateCompatible = (0, _utils._isPureSubstrateChain)(chain) && _types.AllSubstrateKeypairTypes.includes(keypairType);
|
|
618
617
|
const isCardanoCompatible = (0, _utils._isPureCardanoChain)(chain) && _types.CardanoKeypairTypes.includes(keypairType);
|
|
619
618
|
const isBitcoinCompatible = (0, _utils._isPureBitcoinChain)(chain) && _types.BitcoinKeypairTypes.includes(keypairType);
|
|
620
619
|
return isEvmCompatible || isSubstrateCompatible || isTonCompatible || isCardanoCompatible || isBitcoinCompatible;
|
|
@@ -9,6 +9,9 @@ export const APP_VER = packageInfo.version;
|
|
|
9
9
|
const PRODUCTION_BRANCHES = ['master', 'webapp', 'webapp-dev'];
|
|
10
10
|
const branchName = process.env.BRANCH_NAME || 'koni-dev';
|
|
11
11
|
const targetFolder = PRODUCTION_BRANCHES.indexOf(branchName) > -1 ? 'list' : 'preview';
|
|
12
|
+
|
|
13
|
+
// todo: check if can check exactly App Environment, Browser Type, OS Type
|
|
14
|
+
|
|
12
15
|
export async function fetchBlockedConfigObjects() {
|
|
13
16
|
const targetFile = `${targetFolder}/envConfig.json`;
|
|
14
17
|
return await fetchStaticData('blocked-actions', targetFile);
|
|
@@ -34,7 +34,6 @@ export function _validateBalanceToSwapOnAssetHub(fromToken, feeToken, feeTokenCh
|
|
|
34
34
|
return new TransactionError(SwapErrorType.SWAP_NOT_ENOUGH_BALANCE, `Insufficient balance. You need more than ${parsedMinSwapValue} ${fromToken.symbol} to start swapping. Deposit ${fromToken.symbol} and try again.`); // todo: min swap or amount?
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
|
|
38
37
|
if (new BigN(swapAmount).gte(fromTokenBalance)) {
|
|
39
38
|
const parsedMaxBalanceSwap = formatNumber(fromTokenBalance, _getAssetDecimals(fromToken));
|
|
40
39
|
return new TransactionError(SwapErrorType.SWAP_EXCEED_ALLOWANCE, `Amount too high. Lower your amount ${bnFromTokenBalance.gt(0) ? `below ${parsedMaxBalanceSwap} ${fromToken.symbol}` : ''} and try again`);
|
|
@@ -62,7 +61,6 @@ export function _validateBalanceToSwap(fromToken, feeToken, feeTokenChainInfo, f
|
|
|
62
61
|
return new TransactionError(SwapErrorType.SWAP_NOT_ENOUGH_BALANCE, `Insufficient balance. You need more than ${parsedMinSwapValue} ${fromToken.symbol} to start swapping. Deposit ${fromToken.symbol} and try again.`); // todo: min swap or amount?
|
|
63
62
|
}
|
|
64
63
|
}
|
|
65
|
-
|
|
66
64
|
if (new BigN(swapAmount).gte(fromTokenBalance)) {
|
|
67
65
|
const parsedMaxBalanceSwap = formatNumber(fromTokenBalance, _getAssetDecimals(fromToken));
|
|
68
66
|
return new TransactionError(SwapErrorType.SWAP_EXCEED_ALLOWANCE, `Amount too high. Lower your amount ${bnFromTokenBalance.gt(0) ? `below ${parsedMaxBalanceSwap} ${fromToken.symbol}` : ''} and try again`);
|
|
@@ -206,7 +204,6 @@ export function _validateBalanceToSwapV2(request) {
|
|
|
206
204
|
return new TransactionError(SwapErrorType.SWAP_NOT_ENOUGH_BALANCE, `Insufficient balance. You need more than ${parsedMinSwapValue} ${fromToken.symbol} to start swapping. Deposit ${fromToken.symbol} and try again.`); // todo: min swap or amount?
|
|
207
205
|
}
|
|
208
206
|
}
|
|
209
|
-
|
|
210
207
|
return undefined;
|
|
211
208
|
}
|
|
212
209
|
export function _validateSwapRecipientV2(destChainInfo, recipient) {
|
|
@@ -18,7 +18,6 @@ export function _getSystemPalletTransferable(accountInfo, existentialDeposit, ex
|
|
|
18
18
|
export function _canAccountBeReaped(accountInfo) {
|
|
19
19
|
return accountInfo.consumers === 0; // might need to check refCount
|
|
20
20
|
}
|
|
21
|
-
|
|
22
21
|
export function _isAccountActive(accountInfo) {
|
|
23
22
|
return !(accountInfo.consumers === 0 && accountInfo.providers === 0 && accountInfo.sufficients === 0);
|
|
24
23
|
}
|
|
@@ -46,7 +45,6 @@ function _getAppliedExistentialDeposit(accountInfo, existentialDeposit, strictMo
|
|
|
46
45
|
}
|
|
47
46
|
return _canAccountBeReaped(accountInfo) ? BigInt(0) : bnExistentialDeposit; // account for ED here will go better with max transfer logic
|
|
48
47
|
}
|
|
49
|
-
|
|
50
48
|
function _getSystemPalletTransferableV2(accountInfo, existentialDeposit, strictMode) {
|
|
51
49
|
const bnLocked = BigInt(accountInfo.data.frozen) - BigInt(accountInfo.data.reserved); // locked can go below 0 but this shouldn't matter
|
|
52
50
|
const bnAppliedExistentialDeposit = _getAppliedExistentialDeposit(accountInfo, existentialDeposit, strictMode);
|
|
@@ -114,7 +114,6 @@ export async function subscribeAstarNominatorMetadata(chainInfo, address, substr
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
|
-
|
|
118
117
|
const unlockingChunks = ledger.unbondingInfo.unlockingChunks;
|
|
119
118
|
if (unlockingChunks.length > 0) {
|
|
120
119
|
for (const unlockingChunk of unlockingChunks) {
|
|
@@ -200,7 +199,6 @@ export async function getAstarNominatorMetadata(chainInfo, address, substrateApi
|
|
|
200
199
|
}
|
|
201
200
|
}
|
|
202
201
|
}
|
|
203
|
-
|
|
204
202
|
const unlockingChunks = ledger.unbondingInfo.unlockingChunks;
|
|
205
203
|
if (unlockingChunks.length > 0) {
|
|
206
204
|
for (const unlockingChunk of unlockingChunks) {
|
|
@@ -132,7 +132,6 @@ export async function getParaChainStakingMetadata(chain, substrateApi) {
|
|
|
132
132
|
if (unvestedAllocation) {
|
|
133
133
|
totalIssuance.add(unvestedAllocation); // for Turing network, read more at https://hackmd.io/@sbAqOuXkRvyiZPOB3Ryn6Q/Sypr3ZJh5
|
|
134
134
|
}
|
|
135
|
-
|
|
136
135
|
const inflationConfig = _inflation.toHuman();
|
|
137
136
|
const inflation = getParaCurrentInflation(parseRawNumber(totalStake.toString()), inflationConfig);
|
|
138
137
|
const unstakingPeriod = parseInt(unstakingDelay) * _STAKING_ERA_LENGTH_MAP[chain];
|
|
@@ -185,7 +184,6 @@ export async function subscribeParaChainNominatorMetadata(chainInfo, address, su
|
|
|
185
184
|
}
|
|
186
185
|
}
|
|
187
186
|
}
|
|
188
|
-
|
|
189
187
|
const bnStake = new BN(delegation.amount);
|
|
190
188
|
const bnUnstakeBalance = unstakingMap[delegation.owner] ? new BN(unstakingMap[delegation.owner].claimable) : BN_ZERO;
|
|
191
189
|
const bnActiveStake = bnStake.sub(bnUnstakeBalance);
|
|
@@ -279,7 +277,6 @@ export async function getParaChainNominatorMetadata(chainInfo, address, substrat
|
|
|
279
277
|
}
|
|
280
278
|
}
|
|
281
279
|
}
|
|
282
|
-
|
|
283
280
|
const bnStake = new BN(delegation.amount);
|
|
284
281
|
const bnUnstakeBalance = unstakingMap[delegation.owner] ? new BN(unstakingMap[delegation.owner].claimable) : BN_ZERO;
|
|
285
282
|
const bnActiveStake = bnStake.sub(bnUnstakeBalance);
|
|
@@ -221,7 +221,6 @@ export async function subscribeRelayChainNominatorMetadata(chainInfo, address, s
|
|
|
221
221
|
});
|
|
222
222
|
}));
|
|
223
223
|
}
|
|
224
|
-
|
|
225
224
|
let stakingStatus = EarningStatus.NOT_EARNING;
|
|
226
225
|
const bnActiveStake = new BN(activeStake);
|
|
227
226
|
let waitingNominationCount = 0;
|
|
@@ -273,13 +272,13 @@ export async function subscribeRelayChainNominatorMetadata(chainInfo, address, s
|
|
|
273
272
|
* Deprecated
|
|
274
273
|
* */
|
|
275
274
|
export async function getRelayChainNominatorMetadata(chainInfo, address, substrateApi) {
|
|
276
|
-
var _chainApi$api$
|
|
275
|
+
var _chainApi$api$query0, _chainApi$api$query0$, _chainApi$api$query1, _chainApi$api$query1$, _chainApi$api$query10, _chainApi$api$query11, _chainApi$api$query12, _chainApi$api$query13, _chainApi$api$query14, _chainApi$api$query15, _chainApi$api$query16, _chainApi$api$query17, _chainApi$api$query18, _chainApi$api$query19;
|
|
277
276
|
if (isEthereumAddress(address)) {
|
|
278
277
|
return;
|
|
279
278
|
}
|
|
280
279
|
const chain = chainInfo.slug;
|
|
281
280
|
const chainApi = await substrateApi.isReady;
|
|
282
|
-
const [_ledger, _nominations, _currentEra, _bonded, _minimumActiveStake, _minNominatorBond] = await Promise.all([(_chainApi$api$
|
|
281
|
+
const [_ledger, _nominations, _currentEra, _bonded, _minimumActiveStake, _minNominatorBond] = await Promise.all([(_chainApi$api$query0 = chainApi.api.query) === null || _chainApi$api$query0 === void 0 ? void 0 : (_chainApi$api$query0$ = _chainApi$api$query0.staking) === null || _chainApi$api$query0$ === void 0 ? void 0 : _chainApi$api$query0$.ledger(address), (_chainApi$api$query1 = chainApi.api.query) === null || _chainApi$api$query1 === void 0 ? void 0 : (_chainApi$api$query1$ = _chainApi$api$query1.staking) === null || _chainApi$api$query1$ === void 0 ? void 0 : _chainApi$api$query1$.nominators(address), (_chainApi$api$query10 = chainApi.api.query) === null || _chainApi$api$query10 === void 0 ? void 0 : (_chainApi$api$query11 = _chainApi$api$query10.staking) === null || _chainApi$api$query11 === void 0 ? void 0 : _chainApi$api$query11.currentEra(), (_chainApi$api$query12 = chainApi.api.query) === null || _chainApi$api$query12 === void 0 ? void 0 : (_chainApi$api$query13 = _chainApi$api$query12.staking) === null || _chainApi$api$query13 === void 0 ? void 0 : _chainApi$api$query13.bonded(address), ((_chainApi$api$query14 = chainApi.api.query) === null || _chainApi$api$query14 === void 0 ? void 0 : (_chainApi$api$query15 = _chainApi$api$query14.staking) === null || _chainApi$api$query15 === void 0 ? void 0 : _chainApi$api$query15.minimumActiveStake) && ((_chainApi$api$query16 = chainApi.api.query) === null || _chainApi$api$query16 === void 0 ? void 0 : (_chainApi$api$query17 = _chainApi$api$query16.staking) === null || _chainApi$api$query17 === void 0 ? void 0 : _chainApi$api$query17.minimumActiveStake()), (_chainApi$api$query18 = chainApi.api.query) === null || _chainApi$api$query18 === void 0 ? void 0 : (_chainApi$api$query19 = _chainApi$api$query18.staking) === null || _chainApi$api$query19 === void 0 ? void 0 : _chainApi$api$query19.minNominatorBond()]);
|
|
283
282
|
const minActiveStake = (_minimumActiveStake === null || _minimumActiveStake === void 0 ? void 0 : _minimumActiveStake.toString()) || '0';
|
|
284
283
|
const minNominatorBond = _minNominatorBond.toString();
|
|
285
284
|
const bnMinActiveStake = new BN(minActiveStake);
|
|
@@ -334,7 +333,6 @@ export async function getRelayChainNominatorMetadata(chainInfo, address, substra
|
|
|
334
333
|
});
|
|
335
334
|
}));
|
|
336
335
|
}
|
|
337
|
-
|
|
338
336
|
let stakingStatus = EarningStatus.NOT_EARNING;
|
|
339
337
|
const bnActiveStake = new BN(activeStake);
|
|
340
338
|
let waitingNominationCount = 0;
|
|
@@ -69,7 +69,6 @@ export function calculateChainStakedReturn(inflation, totalEraStake, totalIssuan
|
|
|
69
69
|
if (_STAKING_CHAIN_GROUP.aleph.includes(networkKey)) {
|
|
70
70
|
stakedReturn *= 0.9; // 10% goes to treasury
|
|
71
71
|
}
|
|
72
|
-
|
|
73
72
|
return stakedReturn;
|
|
74
73
|
}
|
|
75
74
|
export async function calculateChainStakedReturnV2(chainInfo, totalIssuance, erasPerDay, lastTotalStaked, validatorEraReward, inflation, isCompound) {
|
|
@@ -136,11 +135,9 @@ export function calculateValidatorStakedReturn(chainStakedReturn, totalValidator
|
|
|
136
135
|
const stakedReturn = (adjusted > Number.MAX_SAFE_INTEGER ? Number.MAX_SAFE_INTEGER : adjusted) / 100;
|
|
137
136
|
return stakedReturn * (100 - commission) / 100; // Deduct commission
|
|
138
137
|
}
|
|
139
|
-
|
|
140
138
|
export function getCommission(commissionString) {
|
|
141
139
|
return parseFloat(commissionString.split('%')[0]); // Example: 12%
|
|
142
140
|
}
|
|
143
|
-
|
|
144
141
|
export function getParaCurrentInflation(totalStaked, inflationConfig) {
|
|
145
142
|
// read more at https://hackmd.io/@sbAqOuXkRvyiZPOB3Ryn6Q/Sypr3ZJh5
|
|
146
143
|
const expectMin = parseRawNumber(inflationConfig.expect.min);
|
|
@@ -263,7 +260,6 @@ export function getYieldAvailableActionsByPosition(yieldPosition, yieldPoolInfo,
|
|
|
263
260
|
result.push(YieldAction.START_EARNING);
|
|
264
261
|
result.push(YieldAction.WITHDRAW_EARNING); // TODO
|
|
265
262
|
}
|
|
266
|
-
|
|
267
263
|
return result;
|
|
268
264
|
}
|
|
269
265
|
export let StakingAction;
|
package/koni/background/cron.js
CHANGED
|
@@ -291,5 +291,9 @@ export default class KoniExtension {
|
|
|
291
291
|
private migrateUnifiedAndFetchEligibleSoloAccounts;
|
|
292
292
|
private migrateSoloAccount;
|
|
293
293
|
private pingSession;
|
|
294
|
+
private handleVote;
|
|
295
|
+
private handleRemoveVote;
|
|
296
|
+
private handleUnlockVote;
|
|
297
|
+
private subscribeGovLockedInfo;
|
|
294
298
|
handle<TMessageType extends MessageTypes>(id: string, type: TMessageType, request: RequestTypes[TMessageType], port: chrome.runtime.Port): Promise<ResponseType<TMessageType>>;
|
|
295
299
|
}
|
|
@@ -52,7 +52,7 @@ import { _analyzeAddress, calculateMaxTransferable, combineAllAccountProxy, comb
|
|
|
52
52
|
import { parseContractInput, parseEvmRlp } from '@subwallet/extension-base/utils/eth/parseTransaction';
|
|
53
53
|
import { getId } from '@subwallet/extension-base/utils/getId';
|
|
54
54
|
import { getKeypairTypeByAddress, isAddress, isCardanoAddress, isSubstrateAddress, isTonAddress } from '@subwallet/keyring';
|
|
55
|
-
import { BitcoinKeypairTypes, CardanoKeypairTypes, EthereumKeypairTypes,
|
|
55
|
+
import { AllSubstrateKeypairTypes, BitcoinKeypairTypes, CardanoKeypairTypes, EthereumKeypairTypes, TonKeypairTypes } from '@subwallet/keyring/types';
|
|
56
56
|
import { getBitcoinAddressInfo } from '@subwallet/keyring/utils';
|
|
57
57
|
import { isBitcoinAddress } from '@subwallet/keyring/utils/address/validate';
|
|
58
58
|
import { keyring } from '@subwallet/ui-keyring';
|
|
@@ -591,7 +591,7 @@ export default class KoniExtension {
|
|
|
591
591
|
const type = getKeypairTypeByAddress(address);
|
|
592
592
|
const validTypes = {
|
|
593
593
|
evm: EthereumKeypairTypes,
|
|
594
|
-
substrate:
|
|
594
|
+
substrate: AllSubstrateKeypairTypes,
|
|
595
595
|
ton: TonKeypairTypes,
|
|
596
596
|
cardano: CardanoKeypairTypes,
|
|
597
597
|
bitcoin: BitcoinKeypairTypes
|
|
@@ -2227,7 +2227,6 @@ export default class KoniExtension {
|
|
|
2227
2227
|
const fee = await this.#koniState.feeService.subscribeChainFee(id, chain, feeChainType, data => {
|
|
2228
2228
|
feeSubject.next(data); // Must be called after subscription
|
|
2229
2229
|
});
|
|
2230
|
-
|
|
2231
2230
|
const unsub = () => {
|
|
2232
2231
|
subscription.unsubscribe();
|
|
2233
2232
|
unsubBalance();
|
|
@@ -2352,11 +2351,9 @@ export default class KoniExtension {
|
|
|
2352
2351
|
const [unsubBalance, freeBalance] = await this.#koniState.balanceService.subscribeBalance(address, chain, token, BalanceType.TRANSFERABLE, ExtrinsicType.TRANSFER_BALANCE, data => {
|
|
2353
2352
|
freeBalanceSubject.next(data); // Must be called after subscription
|
|
2354
2353
|
});
|
|
2355
|
-
|
|
2356
2354
|
const fee = await this.#koniState.feeService.subscribeChainFee(id, chain, feeType, data => {
|
|
2357
2355
|
feeSubject.next(data); // Must be called after subscription
|
|
2358
2356
|
});
|
|
2359
|
-
|
|
2360
2357
|
const unsub = () => {
|
|
2361
2358
|
subscription.unsubscribe();
|
|
2362
2359
|
unsubBalance();
|
|
@@ -3592,21 +3589,21 @@ export default class KoniExtension {
|
|
|
3592
3589
|
const unsubSyncProgress = await ((_this$koniState$chain7 = this.#koniState.chainService) === null || _this$koniState$chain7 === void 0 ? void 0 : (_this$koniState$chain8 = _this$koniState$chain7.mantaPay) === null || _this$koniState$chain8 === void 0 ? void 0 : _this$koniState$chain8.subscribeSyncProgress());
|
|
3593
3590
|
console.debug('Start initial sync for MantaPay');
|
|
3594
3591
|
this.#koniState.initialSyncMantaPay(address).then(() => {
|
|
3595
|
-
var _this$koniState$chain9, _this$koniState$
|
|
3592
|
+
var _this$koniState$chain9, _this$koniState$chain0;
|
|
3596
3593
|
console.debug('Finished initial sync for MantaPay');
|
|
3597
3594
|
this.#skipAutoLock = false;
|
|
3598
3595
|
unsubSyncProgress && unsubSyncProgress();
|
|
3599
3596
|
// make sure the sync state is set, just in case it gets unsubscribed
|
|
3600
|
-
(_this$koniState$chain9 = this.#koniState.chainService) === null || _this$koniState$chain9 === void 0 ? void 0 : (_this$koniState$
|
|
3597
|
+
(_this$koniState$chain9 = this.#koniState.chainService) === null || _this$koniState$chain9 === void 0 ? void 0 : (_this$koniState$chain0 = _this$koniState$chain9.mantaPay) === null || _this$koniState$chain0 === void 0 ? void 0 : _this$koniState$chain0.setSyncState({
|
|
3601
3598
|
progress: 100,
|
|
3602
3599
|
isSyncing: false
|
|
3603
3600
|
});
|
|
3604
3601
|
}).catch(e => {
|
|
3605
|
-
var _this$koniState$
|
|
3602
|
+
var _this$koniState$chain1, _this$koniState$chain10;
|
|
3606
3603
|
console.error('Error syncing MantaPay', e);
|
|
3607
3604
|
this.#skipAutoLock = false;
|
|
3608
3605
|
unsubSyncProgress && unsubSyncProgress();
|
|
3609
|
-
(_this$koniState$
|
|
3606
|
+
(_this$koniState$chain1 = this.#koniState.chainService) === null || _this$koniState$chain1 === void 0 ? void 0 : (_this$koniState$chain10 = _this$koniState$chain1.mantaPay) === null || _this$koniState$chain10 === void 0 ? void 0 : _this$koniState$chain10.setSyncState({
|
|
3610
3607
|
progress: 0,
|
|
3611
3608
|
isSyncing: false
|
|
3612
3609
|
});
|
|
@@ -3644,7 +3641,7 @@ export default class KoniExtension {
|
|
|
3644
3641
|
return this.#koniState.getMantaPayConfig('calamari');
|
|
3645
3642
|
}
|
|
3646
3643
|
subscribeMantaPaySyncState(id, port) {
|
|
3647
|
-
var _this$koniState$subsc, _this$koniState$
|
|
3644
|
+
var _this$koniState$subsc, _this$koniState$chain11, _this$koniState$chain12;
|
|
3648
3645
|
const cb = createSubscription(id, port);
|
|
3649
3646
|
const syncingStateSubscription = (_this$koniState$subsc = this.#koniState.subscribeMantaPaySyncState()) === null || _this$koniState$subsc === void 0 ? void 0 : _this$koniState$subsc.subscribe({
|
|
3650
3647
|
next: rs => {
|
|
@@ -3655,7 +3652,7 @@ export default class KoniExtension {
|
|
|
3655
3652
|
port.onDisconnect.addListener(() => {
|
|
3656
3653
|
this.cancelSubscription(id);
|
|
3657
3654
|
});
|
|
3658
|
-
return ((_this$koniState$
|
|
3655
|
+
return ((_this$koniState$chain11 = this.#koniState.chainService) === null || _this$koniState$chain11 === void 0 ? void 0 : (_this$koniState$chain12 = _this$koniState$chain11.mantaPay) === null || _this$koniState$chain12 === void 0 ? void 0 : _this$koniState$chain12.getSyncState()) || {
|
|
3659
3656
|
isSyncing: false,
|
|
3660
3657
|
progress: 0,
|
|
3661
3658
|
needManualSync: false
|
|
@@ -4744,6 +4741,58 @@ export default class KoniExtension {
|
|
|
4744
4741
|
}
|
|
4745
4742
|
/* Migrate Unified Account */
|
|
4746
4743
|
|
|
4744
|
+
/* Open Gov */
|
|
4745
|
+
|
|
4746
|
+
async handleVote(request) {
|
|
4747
|
+
const extrinsic = await this.#koniState.openGovService.handleVote(request);
|
|
4748
|
+
return await this.#koniState.transactionService.handleTransaction({
|
|
4749
|
+
address: request.address,
|
|
4750
|
+
chain: request.chain,
|
|
4751
|
+
transaction: extrinsic,
|
|
4752
|
+
data: request,
|
|
4753
|
+
extrinsicType: ExtrinsicType.GOV_VOTE,
|
|
4754
|
+
chainType: ChainType.SUBSTRATE
|
|
4755
|
+
});
|
|
4756
|
+
}
|
|
4757
|
+
async handleRemoveVote(request) {
|
|
4758
|
+
const extrinsic = await this.#koniState.openGovService.handleRemoveVote(request);
|
|
4759
|
+
return await this.#koniState.transactionService.handleTransaction({
|
|
4760
|
+
address: request.address,
|
|
4761
|
+
chain: request.chain,
|
|
4762
|
+
transaction: extrinsic,
|
|
4763
|
+
data: request,
|
|
4764
|
+
extrinsicType: ExtrinsicType.GOV_UNVOTE,
|
|
4765
|
+
chainType: ChainType.SUBSTRATE
|
|
4766
|
+
});
|
|
4767
|
+
}
|
|
4768
|
+
async handleUnlockVote(request) {
|
|
4769
|
+
const extrinsic = await this.#koniState.openGovService.handleUnlockVote(request);
|
|
4770
|
+
return await this.#koniState.transactionService.handleTransaction({
|
|
4771
|
+
address: request.address,
|
|
4772
|
+
chain: request.chain,
|
|
4773
|
+
transaction: extrinsic,
|
|
4774
|
+
data: request,
|
|
4775
|
+
extrinsicType: ExtrinsicType.GOV_UNLOCK_VOTE,
|
|
4776
|
+
chainType: ChainType.SUBSTRATE
|
|
4777
|
+
});
|
|
4778
|
+
}
|
|
4779
|
+
async subscribeGovLockedInfo(id, port) {
|
|
4780
|
+
const cb = createSubscription(id, port);
|
|
4781
|
+
await this.#koniState.openGovService.waitForStarted();
|
|
4782
|
+
const govLockedInfoSubscription = this.#koniState.openGovService.subscribeGovLockedInfoSubject().subscribe({
|
|
4783
|
+
next: rs => {
|
|
4784
|
+
cb(rs);
|
|
4785
|
+
}
|
|
4786
|
+
});
|
|
4787
|
+
this.createUnsubscriptionHandle(id, govLockedInfoSubscription.unsubscribe);
|
|
4788
|
+
port.onDisconnect.addListener(() => {
|
|
4789
|
+
this.cancelSubscription(id);
|
|
4790
|
+
});
|
|
4791
|
+
return await this.#koniState.openGovService.getGovLockedInfoInfo();
|
|
4792
|
+
}
|
|
4793
|
+
|
|
4794
|
+
/* Open Gov */
|
|
4795
|
+
|
|
4747
4796
|
// --------------------------------------------------------------
|
|
4748
4797
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
4749
4798
|
async handle(id, type, request, port) {
|
|
@@ -5402,6 +5451,16 @@ export default class KoniExtension {
|
|
|
5402
5451
|
return this.migrateSoloAccount(request);
|
|
5403
5452
|
case 'pri(migrate.pingSession)':
|
|
5404
5453
|
return this.pingSession(request);
|
|
5454
|
+
|
|
5455
|
+
/* Gov */
|
|
5456
|
+
case 'pri(openGov.vote)':
|
|
5457
|
+
return this.handleVote(request);
|
|
5458
|
+
case 'pri(openGov.unvote)':
|
|
5459
|
+
return this.handleRemoveVote(request);
|
|
5460
|
+
case 'pri(openGov.unlockVote)':
|
|
5461
|
+
return this.handleUnlockVote(request);
|
|
5462
|
+
case 'pri(openGov.subscribeGovLockedInfo)':
|
|
5463
|
+
return this.subscribeGovLockedInfo(id, port);
|
|
5405
5464
|
// Default
|
|
5406
5465
|
default:
|
|
5407
5466
|
throw new Error(`Unable to handle message of type ${type}`);
|
|
@@ -21,6 +21,7 @@ import MintCampaignService from '@subwallet/extension-base/services/mint-campaig
|
|
|
21
21
|
import MktCampaignService from '@subwallet/extension-base/services/mkt-campaign-service';
|
|
22
22
|
import NftService from '@subwallet/extension-base/services/nft-service';
|
|
23
23
|
import NotificationService from '@subwallet/extension-base/services/notification-service/NotificationService';
|
|
24
|
+
import OpenGovService from '@subwallet/extension-base/services/open-gov';
|
|
24
25
|
import { PriceService } from '@subwallet/extension-base/services/price-service';
|
|
25
26
|
import RequestService from '@subwallet/extension-base/services/request-service';
|
|
26
27
|
import { AuthUrls, MetaRequest, SignRequest } from '@subwallet/extension-base/services/request-service/types';
|
|
@@ -81,6 +82,7 @@ export default class KoniState {
|
|
|
81
82
|
readonly swapService: SwapService;
|
|
82
83
|
readonly inappNotificationService: InappNotificationService;
|
|
83
84
|
readonly chainOnlineService: ChainOnlineService;
|
|
85
|
+
readonly openGovService: OpenGovService;
|
|
84
86
|
private generalStatus;
|
|
85
87
|
private waitSleeping;
|
|
86
88
|
private waitStarting;
|