@subwallet/extension-base 1.1.54-0 → 1.1.56-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 +30 -2
- package/background/KoniTypes.js +6 -0
- package/background/errors/SwapError.d.ts +6 -0
- package/background/errors/SwapError.js +57 -0
- package/background/errors/TransactionError.js +9 -0
- package/background/types.d.ts +2 -0
- package/cjs/background/KoniTypes.js +8 -1
- package/cjs/background/errors/SwapError.js +64 -0
- package/cjs/background/errors/TransactionError.js +9 -0
- package/cjs/koni/api/nft/{statemint_nft → assethub_nft}/index.js +5 -3
- package/cjs/koni/api/nft/{statemine_nft → assethub_unique}/index.js +5 -3
- package/cjs/koni/api/nft/index.js +13 -13
- package/cjs/koni/api/nft/nft.js +1 -1
- package/cjs/koni/api/nft/transfer.js +11 -15
- package/cjs/koni/api/staking/bonding/utils.js +35 -6
- package/cjs/koni/background/handlers/Extension.js +214 -102
- package/cjs/koni/background/handlers/State.js +5 -2
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/index.js +6 -3
- package/cjs/services/chain-service/constants.js +18 -4
- package/cjs/services/chain-service/index.js +39 -18
- package/cjs/services/chain-service/utils/index.js +15 -4
- package/cjs/services/chain-service/utils/patch.js +1 -1
- package/cjs/services/earning-service/constants/chains.js +4 -2
- package/cjs/services/earning-service/handlers/native-staking/amplitude.js +7 -9
- package/cjs/services/earning-service/handlers/native-staking/astar.js +4 -3
- package/cjs/services/earning-service/handlers/native-staking/para-chain.js +11 -8
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +22 -3
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +19 -5
- package/cjs/services/earning-service/service.js +0 -1
- package/cjs/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +4 -17
- package/cjs/services/migration-service/scripts/databases/MigrateAssetSetting.js +4 -17
- package/cjs/services/migration-service/scripts/index.js +3 -3
- package/cjs/services/swap-service/handler/base-handler.js +189 -0
- package/cjs/services/swap-service/handler/chainflip-handler.js +407 -0
- package/cjs/services/swap-service/handler/hydradx-handler.js +531 -0
- package/cjs/services/swap-service/index.js +250 -0
- package/cjs/services/swap-service/utils.js +126 -0
- package/cjs/services/transaction-service/index.js +20 -0
- package/cjs/services/transaction-service/utils.js +6 -0
- package/cjs/types/fee/evm.js +1 -0
- package/cjs/types/fee/fee.js +70 -0
- package/cjs/types/fee/index.js +27 -1
- package/cjs/types/service-base.js +1 -0
- package/cjs/types/swap/index.js +50 -0
- package/cjs/utils/index.js +12 -0
- package/cjs/utils/swap.js +78 -0
- package/koni/api/nft/{statemint_nft → assethub_nft}/index.d.ts +1 -1
- package/koni/api/nft/{statemint_nft → assethub_nft}/index.js +4 -2
- package/koni/api/nft/{statemine_nft → assethub_unique}/index.d.ts +1 -1
- package/koni/api/nft/{statemine_nft → assethub_unique}/index.js +4 -2
- package/koni/api/nft/index.js +13 -13
- package/koni/api/nft/nft.js +1 -1
- package/koni/api/nft/transfer.d.ts +1 -2
- package/koni/api/nft/transfer.js +10 -13
- package/koni/api/staking/bonding/utils.d.ts +3 -1
- package/koni/api/staking/bonding/utils.js +32 -6
- package/koni/background/handlers/Extension.d.ts +6 -0
- package/koni/background/handlers/Extension.js +111 -0
- package/koni/background/handlers/State.d.ts +2 -0
- package/koni/background/handlers/State.js +5 -2
- package/package.json +85 -28
- package/packageInfo.js +1 -1
- package/services/balance-service/index.js +6 -3
- package/services/base/types.d.ts +4 -0
- package/services/chain-service/constants.js +18 -4
- package/services/chain-service/index.d.ts +4 -0
- package/services/chain-service/index.js +21 -1
- package/services/chain-service/utils/index.d.ts +7 -5
- package/services/chain-service/utils/index.js +9 -2
- package/services/chain-service/utils/patch.js +1 -1
- package/services/earning-service/constants/chains.d.ts +1 -0
- package/services/earning-service/constants/chains.js +1 -0
- package/services/earning-service/handlers/native-staking/amplitude.js +7 -9
- package/services/earning-service/handlers/native-staking/astar.js +4 -3
- package/services/earning-service/handlers/native-staking/para-chain.js +12 -9
- package/services/earning-service/handlers/native-staking/relay-chain.js +24 -5
- package/services/earning-service/handlers/nomination-pool/index.js +19 -5
- package/services/earning-service/service.js +0 -1
- package/services/event-service/types.d.ts +1 -0
- package/services/migration-service/scripts/MigrateTransactionHistoryBySymbol.js +4 -17
- package/services/migration-service/scripts/databases/MigrateAssetSetting.js +4 -17
- package/services/migration-service/scripts/index.js +3 -3
- package/services/swap-service/handler/base-handler.d.ts +38 -0
- package/services/swap-service/handler/base-handler.js +180 -0
- package/services/swap-service/handler/chainflip-handler.d.ts +30 -0
- package/services/swap-service/handler/chainflip-handler.js +399 -0
- package/services/swap-service/handler/hydradx-handler.d.ts +36 -0
- package/services/swap-service/handler/hydradx-handler.js +522 -0
- package/services/swap-service/index.d.ts +32 -0
- package/services/swap-service/index.js +241 -0
- package/services/swap-service/utils.d.ts +18 -0
- package/services/swap-service/utils.js +105 -0
- package/services/transaction-service/index.js +20 -0
- package/services/transaction-service/utils.d.ts +2 -0
- package/services/transaction-service/utils.js +6 -2
- package/types/fee/evm.d.ts +49 -0
- package/types/fee/evm.js +1 -0
- package/types/fee/fee.d.ts +32 -0
- package/types/fee/fee.js +63 -0
- package/types/fee/index.d.ts +2 -49
- package/types/fee/index.js +5 -1
- package/types/service-base.d.ts +10 -0
- package/types/service-base.js +1 -0
- package/types/swap/index.d.ts +168 -0
- package/types/swap/index.js +41 -0
- package/types/yield/info/chain/target.d.ts +2 -0
- package/types/yield/info/pallet.d.ts +8 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +2 -1
- package/utils/swap.d.ts +3 -0
- package/utils/swap.js +70 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.swapCustomFormatter = exports.formatNumberString = void 0;
|
|
8
|
+
var _number = require("@subwallet/extension-base/utils/number");
|
|
9
|
+
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
10
|
+
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
11
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
12
|
+
|
|
13
|
+
// Clear zero from end, use with decimal only
|
|
14
|
+
const clearZero = result => {
|
|
15
|
+
let index = result.length - 1;
|
|
16
|
+
while (result[index] === '0') {
|
|
17
|
+
result = result.slice(0, index);
|
|
18
|
+
index--;
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
};
|
|
22
|
+
const NUM_1T = new _bignumber.default(1e12);
|
|
23
|
+
const TLIM = new _bignumber.default(1e17);
|
|
24
|
+
const NUM_1B = new _bignumber.default(1e9);
|
|
25
|
+
const BLIM = new _bignumber.default(1e14);
|
|
26
|
+
const NUM_1M = new _bignumber.default(1e6);
|
|
27
|
+
const NUM_100M = new _bignumber.default(1e8);
|
|
28
|
+
const swapCustomFormatter = (input, metadata) => {
|
|
29
|
+
const minNumberFormat = 2;
|
|
30
|
+
const maxNumberFormat = (metadata === null || metadata === void 0 ? void 0 : metadata.maxNumberFormat) || 6;
|
|
31
|
+
const [int, decimal = '0'] = input.split('.');
|
|
32
|
+
let _decimal = '';
|
|
33
|
+
const intNumber = new _bignumber.default(int);
|
|
34
|
+
const max = _number.BN_TEN.pow(maxNumberFormat);
|
|
35
|
+
|
|
36
|
+
// If count of number in integer part greater or equal maxNumberFormat, do not show decimal
|
|
37
|
+
if (intNumber.gte(max)) {
|
|
38
|
+
if (intNumber.gte(NUM_100M)) {
|
|
39
|
+
if (intNumber.gte(BLIM)) {
|
|
40
|
+
if (intNumber.gte(TLIM)) {
|
|
41
|
+
return `${intNumber.dividedBy(NUM_1T).toFixed()} T`;
|
|
42
|
+
}
|
|
43
|
+
return `${intNumber.dividedBy(NUM_1B).toFixed()} B`;
|
|
44
|
+
}
|
|
45
|
+
return `${intNumber.dividedBy(NUM_1M).toFixed()} M`;
|
|
46
|
+
}
|
|
47
|
+
_decimal = decimal.slice(0, metadata === null || metadata === void 0 ? void 0 : metadata.maxNumberFormat);
|
|
48
|
+
return `${int}.${_decimal}`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Get only minNumberFormat number at decimal
|
|
52
|
+
if (decimal.length <= minNumberFormat || !(metadata !== null && metadata !== void 0 && metadata.maxNumberFormat)) {
|
|
53
|
+
_decimal = decimal;
|
|
54
|
+
} else {
|
|
55
|
+
_decimal = decimal.slice(0, maxNumberFormat);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Clear zero number for decimal
|
|
59
|
+
_decimal = clearZero(_decimal);
|
|
60
|
+
if (_decimal) {
|
|
61
|
+
return `${int}.${_decimal}`;
|
|
62
|
+
}
|
|
63
|
+
return int;
|
|
64
|
+
};
|
|
65
|
+
exports.swapCustomFormatter = swapCustomFormatter;
|
|
66
|
+
const formatNumberString = numberString => {
|
|
67
|
+
const number = parseFloat(numberString);
|
|
68
|
+
const exponentNotation = number.toExponential();
|
|
69
|
+
let [coefficient, exponent] = exponentNotation.split('e');
|
|
70
|
+
if (parseInt(exponent) < 0) {
|
|
71
|
+
coefficient = coefficient.replace(/^0+|\./g, '');
|
|
72
|
+
coefficient = '0.' + '0'.repeat(Math.abs(parseInt(exponent)) - 1) + coefficient;
|
|
73
|
+
} else {
|
|
74
|
+
coefficient += '0'.repeat(parseInt(exponent) - coefficient.length + 1);
|
|
75
|
+
}
|
|
76
|
+
return coefficient;
|
|
77
|
+
};
|
|
78
|
+
exports.formatNumberString = formatNumberString;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseNftApi, HandleNftParams } from '@subwallet/extension-base/koni/api/nft/nft';
|
|
2
2
|
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
3
|
-
export default class
|
|
3
|
+
export default class AssetHubNftsPalletApi extends BaseNftApi {
|
|
4
4
|
constructor(api: _SubstrateApi | null, addresses: string[], chain: string);
|
|
5
5
|
private getMetadata;
|
|
6
6
|
/**
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import { AssetHubNftType } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
5
|
import { BaseNftApi } from '@subwallet/extension-base/koni/api/nft/nft';
|
|
5
6
|
import { isUrl } from '@subwallet/extension-base/utils';
|
|
6
7
|
import fetch from 'cross-fetch';
|
|
7
|
-
export default class
|
|
8
|
+
export default class AssetHubNftsPalletApi extends BaseNftApi {
|
|
8
9
|
// eslint-disable-next-line no-useless-constructor
|
|
9
10
|
constructor(api, addresses, chain) {
|
|
10
11
|
super(chain, api, addresses);
|
|
@@ -105,7 +106,8 @@ export default class StatemintNftApi extends BaseNftApi {
|
|
|
105
106
|
image: tokenInfo && tokenInfo.image ? this.parseUrl(tokenInfo === null || tokenInfo === void 0 ? void 0 : tokenInfo.image) : undefined,
|
|
106
107
|
collectionId: this.parseTokenId(parsedClassId),
|
|
107
108
|
chain: this.chain,
|
|
108
|
-
owner: address
|
|
109
|
+
owner: address,
|
|
110
|
+
assetHubType: AssetHubNftType.NFTS
|
|
109
111
|
};
|
|
110
112
|
params.updateItem(this.chain, parsedNft, address);
|
|
111
113
|
const parsedCollection = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseNftApi, HandleNftParams } from '@subwallet/extension-base/koni/api/nft/nft';
|
|
2
2
|
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
3
|
-
export default class
|
|
3
|
+
export default class AssetHubUniquesPalletApi extends BaseNftApi {
|
|
4
4
|
constructor(api: _SubstrateApi | null, addresses: string[], chain: string);
|
|
5
5
|
private getMetadata;
|
|
6
6
|
/**
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import { AssetHubNftType } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
5
|
import { BaseNftApi } from '@subwallet/extension-base/koni/api/nft/nft';
|
|
5
6
|
import { isUrl } from '@subwallet/extension-base/utils';
|
|
6
7
|
import fetch from 'cross-fetch';
|
|
7
|
-
export default class
|
|
8
|
+
export default class AssetHubUniquesPalletApi extends BaseNftApi {
|
|
8
9
|
// eslint-disable-next-line no-useless-constructor
|
|
9
10
|
constructor(api, addresses, chain) {
|
|
10
11
|
super(chain, api, addresses);
|
|
@@ -105,7 +106,8 @@ export default class StatemineNftApi extends BaseNftApi {
|
|
|
105
106
|
image: tokenInfo && tokenInfo.image ? this.parseUrl(tokenInfo === null || tokenInfo === void 0 ? void 0 : tokenInfo.image) : undefined,
|
|
106
107
|
collectionId: this.parseTokenId(parsedClassId),
|
|
107
108
|
chain: this.chain,
|
|
108
|
-
owner: address
|
|
109
|
+
owner: address,
|
|
110
|
+
assetHubType: AssetHubNftType.UNIQUES
|
|
109
111
|
};
|
|
110
112
|
params.updateItem(this.chain, parsedNft, address);
|
|
111
113
|
const parsedCollection = {
|
package/koni/api/nft/index.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { AcalaNftApi } from '@subwallet/extension-base/koni/api/nft/acala_nft';
|
|
5
|
+
import AssetHubUniquesPalletApi from '@subwallet/extension-base/koni/api/nft/assethub_unique';
|
|
5
6
|
import { BitCountryNftApi } from '@subwallet/extension-base/koni/api/nft/bit.country';
|
|
6
7
|
import { EvmNftApi } from '@subwallet/extension-base/koni/api/nft/evm_nft';
|
|
7
8
|
import { KaruraNftApi } from '@subwallet/extension-base/koni/api/nft/karura_nft';
|
|
8
9
|
import OrdinalNftApi from '@subwallet/extension-base/koni/api/nft/ordinal_nft';
|
|
9
10
|
import { RmrkNftApi } from '@subwallet/extension-base/koni/api/nft/rmrk_nft';
|
|
10
|
-
import StatemineNftApi from '@subwallet/extension-base/koni/api/nft/statemine_nft';
|
|
11
11
|
import { UniqueNftApi } from '@subwallet/extension-base/koni/api/nft/unique_network_nft';
|
|
12
12
|
// import UniqueNftApi from '@subwallet/extension-base/koni/api/nft/unique_nft';
|
|
13
13
|
import { VaraNftApi } from '@subwallet/extension-base/koni/api/nft/vara_nft';
|
|
@@ -15,25 +15,25 @@ import { WasmNftApi } from '@subwallet/extension-base/koni/api/nft/wasm_nft';
|
|
|
15
15
|
import { _NFT_CHAIN_GROUP } from '@subwallet/extension-base/services/chain-service/constants';
|
|
16
16
|
import { _isChainSupportEvmNft, _isChainSupportNativeNft, _isChainSupportWasmNft, _isSupportOrdinal } from '@subwallet/extension-base/services/chain-service/utils';
|
|
17
17
|
import { categoryAddresses, targetIsWeb } from '@subwallet/extension-base/utils';
|
|
18
|
-
import
|
|
18
|
+
import AssetHubNftsPalletApi from "./assethub_nft/index.js";
|
|
19
19
|
function createSubstrateNftApi(chain, substrateApi, addresses) {
|
|
20
20
|
const [substrateAddresses] = categoryAddresses(addresses);
|
|
21
21
|
if (_NFT_CHAIN_GROUP.acala.includes(chain)) {
|
|
22
|
-
return new AcalaNftApi(substrateApi, substrateAddresses, chain);
|
|
22
|
+
return [new AcalaNftApi(substrateApi, substrateAddresses, chain)];
|
|
23
23
|
} else if (_NFT_CHAIN_GROUP.karura.includes(chain)) {
|
|
24
|
-
return new KaruraNftApi(substrateApi, substrateAddresses, chain);
|
|
24
|
+
return [new KaruraNftApi(substrateApi, substrateAddresses, chain)];
|
|
25
25
|
} else if (_NFT_CHAIN_GROUP.rmrk.includes(chain)) {
|
|
26
|
-
return new RmrkNftApi(substrateAddresses, chain);
|
|
26
|
+
return [new RmrkNftApi(substrateAddresses, chain)];
|
|
27
27
|
} else if (_NFT_CHAIN_GROUP.statemine.includes(chain)) {
|
|
28
|
-
return new
|
|
28
|
+
return [new AssetHubUniquesPalletApi(substrateApi, substrateAddresses, chain), new AssetHubNftsPalletApi(substrateApi, substrateAddresses, chain)];
|
|
29
29
|
} else if (_NFT_CHAIN_GROUP.statemint.includes(chain)) {
|
|
30
|
-
return new
|
|
30
|
+
return [new AssetHubUniquesPalletApi(substrateApi, substrateAddresses, chain), new AssetHubNftsPalletApi(substrateApi, substrateAddresses, chain)];
|
|
31
31
|
} else if (_NFT_CHAIN_GROUP.unique_network.includes(chain)) {
|
|
32
|
-
return new UniqueNftApi(chain, substrateAddresses);
|
|
32
|
+
return [new UniqueNftApi(chain, substrateAddresses)];
|
|
33
33
|
} else if (_NFT_CHAIN_GROUP.bitcountry.includes(chain)) {
|
|
34
|
-
return new BitCountryNftApi(substrateApi, substrateAddresses, chain);
|
|
34
|
+
return [new BitCountryNftApi(substrateApi, substrateAddresses, chain)];
|
|
35
35
|
} else if (_NFT_CHAIN_GROUP.vara.includes(chain)) {
|
|
36
|
-
return new VaraNftApi(chain, substrateAddresses);
|
|
36
|
+
return [new VaraNftApi(chain, substrateAddresses)];
|
|
37
37
|
}
|
|
38
38
|
return null;
|
|
39
39
|
}
|
|
@@ -105,9 +105,9 @@ export class NftHandler {
|
|
|
105
105
|
Object.entries(this.chainInfoMap).forEach(([chain, chainInfo]) => {
|
|
106
106
|
if (_isChainSupportNativeNft(chainInfo)) {
|
|
107
107
|
if (this.substrateApiMap[chain]) {
|
|
108
|
-
const
|
|
109
|
-
if (
|
|
110
|
-
this.handlers.push(
|
|
108
|
+
const handlers = createSubstrateNftApi(chain, this.substrateApiMap[chain], substrateAddresses);
|
|
109
|
+
if (handlers && !!handlers.length) {
|
|
110
|
+
this.handlers.push(...handlers);
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
}
|
package/koni/api/nft/nft.js
CHANGED
|
@@ -3,6 +3,5 @@ export declare function isRecipientSelf(currentAddress: string, recipientAddress
|
|
|
3
3
|
export declare function acalaGetExtrinsic(substrateApi: _SubstrateApi, senderAddress: string, recipientAddress: string, params: Record<string, any>): import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult> | null;
|
|
4
4
|
export declare function rmrkGetExtrinsic(substrateApi: _SubstrateApi, senderAddress: string, recipientAddress: string, params: Record<string, any>): import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult> | null;
|
|
5
5
|
export declare function uniqueGetExtrinsic(substrateApi: _SubstrateApi, senderAddress: string, recipientAddress: string, params: Record<string, any>): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult> | null>;
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function statemintGetExtrinsic(substrateApi: _SubstrateApi, senderAddress: string, recipientAddress: string, params: Record<string, any>): import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult> | null;
|
|
6
|
+
export declare function assetHubGetExtrinsic(substrateApi: _SubstrateApi, senderAddress: string, recipientAddress: string, params: Record<string, any>): import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult> | null;
|
|
8
7
|
export declare function getNftTransferExtrinsic(networkKey: string, substrateApi: _SubstrateApi, senderAddress: string, recipientAddress: string, params: Record<string, any>): Promise<import("@polkadot/api-base/types").SubmittableExtrinsic<"promise", import("@polkadot/types/types").ISubmittableResult> | null>;
|
package/koni/api/nft/transfer.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright 2019-2022 @subwallet/extension-koni authors & contributors
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import { AssetHubNftType } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
5
|
import { SUPPORTED_TRANSFER_SUBSTRATE_CHAIN_NAME } from '@subwallet/extension-base/koni/api/nft/config';
|
|
5
6
|
import { reformatAddress } from '@subwallet/extension-base/utils';
|
|
6
7
|
export function isRecipientSelf(currentAddress, recipientAddress) {
|
|
@@ -52,21 +53,17 @@ export async function uniqueGetExtrinsic(substrateApi, senderAddress, recipientA
|
|
|
52
53
|
return null;
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
|
-
export function
|
|
56
|
+
export function assetHubGetExtrinsic(substrateApi, senderAddress, recipientAddress, params) {
|
|
56
57
|
try {
|
|
57
58
|
const itemId = params.itemId;
|
|
58
59
|
const collectionId = params.collectionId;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
const nftType = params.assetHubType;
|
|
61
|
+
if (nftType === AssetHubNftType.NFTS) {
|
|
62
|
+
return substrateApi.api.tx.nfts.transfer(collectionId, itemId, recipientAddress);
|
|
63
|
+
} else if (nftType === AssetHubNftType.UNIQUES) {
|
|
64
|
+
return substrateApi.api.tx.uniques.transfer(collectionId, itemId, recipientAddress);
|
|
65
|
+
}
|
|
62
66
|
return null;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
export function statemintGetExtrinsic(substrateApi, senderAddress, recipientAddress, params) {
|
|
66
|
-
try {
|
|
67
|
-
const itemId = params.itemId;
|
|
68
|
-
const collectionId = params.collectionId;
|
|
69
|
-
return substrateApi.api.tx.nfts.transfer(collectionId, itemId, recipientAddress);
|
|
70
67
|
} catch (e) {
|
|
71
68
|
console.error(e);
|
|
72
69
|
return null;
|
|
@@ -87,9 +84,9 @@ export async function getNftTransferExtrinsic(networkKey, substrateApi, senderAd
|
|
|
87
84
|
case SUPPORTED_TRANSFER_SUBSTRATE_CHAIN_NAME.opal:
|
|
88
85
|
return await uniqueGetExtrinsic(substrateApi, senderAddress, recipientAddress, params);
|
|
89
86
|
case SUPPORTED_TRANSFER_SUBSTRATE_CHAIN_NAME.statemine:
|
|
90
|
-
return
|
|
87
|
+
return assetHubGetExtrinsic(substrateApi, senderAddress, recipientAddress, params);
|
|
91
88
|
case SUPPORTED_TRANSFER_SUBSTRATE_CHAIN_NAME.statemint:
|
|
92
|
-
return
|
|
89
|
+
return assetHubGetExtrinsic(substrateApi, senderAddress, recipientAddress, params);
|
|
93
90
|
case SUPPORTED_TRANSFER_SUBSTRATE_CHAIN_NAME.bitcountry:
|
|
94
91
|
return acalaGetExtrinsic(substrateApi, senderAddress, recipientAddress, params);
|
|
95
92
|
case SUPPORTED_TRANSFER_SUBSTRATE_CHAIN_NAME.pioneer:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
2
2
|
import { NominationInfo, NominatorMetadata, StakingType, UnstakingInfo } from '@subwallet/extension-base/background/KoniTypes';
|
|
3
3
|
import { _SubstrateInflationParams } from '@subwallet/extension-base/services/chain-service/constants';
|
|
4
|
-
import { EarningStatus, YieldPoolInfo, YieldPositionInfo } from '@subwallet/extension-base/types';
|
|
4
|
+
import { EarningStatus, PalletStakingEraRewardPoints, YieldPoolInfo, YieldPositionInfo } from '@subwallet/extension-base/types';
|
|
5
5
|
import BigNumber from 'bignumber.js';
|
|
6
6
|
import { ApiPromise } from '@polkadot/api';
|
|
7
7
|
import { Codec } from '@polkadot/types/types';
|
|
@@ -158,6 +158,8 @@ export declare function getEarningStatusByNominations(bnTotalActiveStake: BN, no
|
|
|
158
158
|
export declare function getValidatorLabel(chain: string): "dApp" | "Validator" | "Collator";
|
|
159
159
|
export declare function getAvgValidatorEraReward(supportedDays: number, eraRewardHistory: Codec[]): BigNumber;
|
|
160
160
|
export declare function getSupportedDaysByHistoryDepth(erasPerDay: number, maxSupportedEras: number): 15 | 30;
|
|
161
|
+
export declare function getValidatorPointsMap(eraRewardMap: Record<string, PalletStakingEraRewardPoints>): Record<string, BigNumber>;
|
|
162
|
+
export declare function getTopValidatorByPoints(validatorPointsList: Record<string, BigNumber>): string[];
|
|
161
163
|
export declare const getMinStakeErrorMessage: (chainInfo: _ChainInfo, bnMinStake: BN) => string;
|
|
162
164
|
export declare const getMaxValidatorErrorMessage: (chainInfo: _ChainInfo, max: number) => string;
|
|
163
165
|
export declare const getExistUnstakeErrorMessage: (chain: string, type?: StakingType, isStakeMore?: boolean) => string;
|
|
@@ -197,13 +197,13 @@ export function getYieldAvailableActionsByPosition(yieldPosition, yieldPoolInfo,
|
|
|
197
197
|
const result = [];
|
|
198
198
|
if ([YieldPoolType.NATIVE_STAKING, YieldPoolType.NOMINATION_POOL].includes(yieldPoolInfo.type)) {
|
|
199
199
|
result.push(YieldAction.STAKE);
|
|
200
|
-
const bnActiveStake = new
|
|
201
|
-
if (yieldPosition.activeStake && bnActiveStake.gt(
|
|
200
|
+
const bnActiveStake = new BigNumber(yieldPosition.activeStake);
|
|
201
|
+
if (yieldPosition.activeStake && bnActiveStake.gt('0')) {
|
|
202
202
|
result.push(YieldAction.UNSTAKE);
|
|
203
203
|
const isAstarNetwork = _STAKING_CHAIN_GROUP.astar.includes(yieldPosition.chain);
|
|
204
204
|
const isAmplitudeNetwork = _STAKING_CHAIN_GROUP.amplitude.includes(yieldPosition.chain);
|
|
205
|
-
const bnUnclaimedReward = new
|
|
206
|
-
if ((yieldPosition.type === YieldPoolType.NOMINATION_POOL || isAmplitudeNetwork) && bnUnclaimedReward.gt(
|
|
205
|
+
const bnUnclaimedReward = new BigNumber(unclaimedReward || '0');
|
|
206
|
+
if ((yieldPosition.type === YieldPoolType.NOMINATION_POOL || isAmplitudeNetwork) && bnUnclaimedReward.gt('0') || isAstarNetwork) {
|
|
207
207
|
result.push(YieldAction.CLAIM_REWARD);
|
|
208
208
|
}
|
|
209
209
|
}
|
|
@@ -216,8 +216,8 @@ export function getYieldAvailableActionsByPosition(yieldPosition, yieldPoolInfo,
|
|
|
216
216
|
}
|
|
217
217
|
} else if (yieldPoolInfo.type === YieldPoolType.LIQUID_STAKING) {
|
|
218
218
|
result.push(YieldAction.START_EARNING);
|
|
219
|
-
const activeBalance = new
|
|
220
|
-
if (activeBalance.gt(
|
|
219
|
+
const activeBalance = new BigNumber(yieldPosition.activeStake);
|
|
220
|
+
if (activeBalance.gt('0')) {
|
|
221
221
|
result.push(YieldAction.UNSTAKE);
|
|
222
222
|
}
|
|
223
223
|
const hasWithdrawal = yieldPosition.unstakings.some(unstakingInfo => unstakingInfo.status === UnstakingStatus.CLAIMABLE);
|
|
@@ -350,6 +350,32 @@ export function getSupportedDaysByHistoryDepth(erasPerDay, maxSupportedEras) {
|
|
|
350
350
|
return 15;
|
|
351
351
|
}
|
|
352
352
|
}
|
|
353
|
+
export function getValidatorPointsMap(eraRewardMap) {
|
|
354
|
+
// mapping store validator and totalPoints
|
|
355
|
+
const validatorTotalPointsMap = {};
|
|
356
|
+
Object.values(eraRewardMap).forEach(info => {
|
|
357
|
+
const individual = info.individual;
|
|
358
|
+
Object.entries(individual).forEach(([validator, rawPoints]) => {
|
|
359
|
+
const points = rawPoints.replaceAll(',', '');
|
|
360
|
+
if (!validatorTotalPointsMap[validator]) {
|
|
361
|
+
validatorTotalPointsMap[validator] = new BigNumber(points);
|
|
362
|
+
} else {
|
|
363
|
+
validatorTotalPointsMap[validator] = validatorTotalPointsMap[validator].plus(points);
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
return validatorTotalPointsMap;
|
|
368
|
+
}
|
|
369
|
+
export function getTopValidatorByPoints(validatorPointsList) {
|
|
370
|
+
const sortValidatorPointsList = Object.fromEntries(Object.entries(validatorPointsList).sort((a, b) => a[1].minus(b[1]).toNumber()).reverse());
|
|
371
|
+
|
|
372
|
+
// keep 50% first validator
|
|
373
|
+
const entries = Object.entries(sortValidatorPointsList);
|
|
374
|
+
const endIndex = Math.ceil(entries.length / 2);
|
|
375
|
+
const top50PercentEntries = entries.slice(0, endIndex);
|
|
376
|
+
const top50PercentRecord = Object.fromEntries(top50PercentEntries);
|
|
377
|
+
return Object.keys(top50PercentRecord);
|
|
378
|
+
}
|
|
353
379
|
export const getMinStakeErrorMessage = (chainInfo, bnMinStake) => {
|
|
354
380
|
const tokenInfo = _getChainNativeTokenBasicInfo(chainInfo);
|
|
355
381
|
const number = formatNumber(bnMinStake.toString(), tokenInfo.decimals || 0, balanceFormatter);
|
|
@@ -108,6 +108,7 @@ export default class KoniExtension {
|
|
|
108
108
|
private derivationCreateV2;
|
|
109
109
|
private jsonRestoreV2;
|
|
110
110
|
private batchRestoreV2;
|
|
111
|
+
private batchExportV2;
|
|
111
112
|
private getNftCollection;
|
|
112
113
|
private subscribeNftCollection;
|
|
113
114
|
private getNft;
|
|
@@ -237,5 +238,10 @@ export default class KoniExtension {
|
|
|
237
238
|
private completeCampaignBanner;
|
|
238
239
|
private subscribeBuyTokens;
|
|
239
240
|
private subscribeBuyServices;
|
|
241
|
+
private subscribeSwapPairs;
|
|
242
|
+
private handleSwapRequest;
|
|
243
|
+
private getLatestSwapQuote;
|
|
244
|
+
private validateSwapProcess;
|
|
245
|
+
private handleSwapStep;
|
|
240
246
|
handle<TMessageType extends MessageTypes>(id: string, type: TMessageType, request: RequestTypes[TMessageType], port: chrome.runtime.Port): Promise<ResponseType<TMessageType>>;
|
|
241
247
|
}
|
|
@@ -1393,6 +1393,26 @@ export default class KoniExtension {
|
|
|
1393
1393
|
throw new Error(t('Wrong password'));
|
|
1394
1394
|
}
|
|
1395
1395
|
}
|
|
1396
|
+
async batchExportV2({
|
|
1397
|
+
addresses,
|
|
1398
|
+
password
|
|
1399
|
+
}) {
|
|
1400
|
+
try {
|
|
1401
|
+
if (addresses && !addresses.length) {
|
|
1402
|
+
throw new Error(t('No accounts found to export'));
|
|
1403
|
+
}
|
|
1404
|
+
return {
|
|
1405
|
+
exportedJson: await keyring.backupAccounts(password, addresses)
|
|
1406
|
+
};
|
|
1407
|
+
} catch (e) {
|
|
1408
|
+
const error = e;
|
|
1409
|
+
if (error.message === 'Invalid master password') {
|
|
1410
|
+
throw new Error(t('Wrong password'));
|
|
1411
|
+
} else {
|
|
1412
|
+
throw error;
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1396
1416
|
getNftCollection() {
|
|
1397
1417
|
return this.#koniState.getNftCollection();
|
|
1398
1418
|
}
|
|
@@ -3943,6 +3963,82 @@ export default class KoniExtension {
|
|
|
3943
3963
|
|
|
3944
3964
|
/* Buy service */
|
|
3945
3965
|
|
|
3966
|
+
/* Swap service */
|
|
3967
|
+
async subscribeSwapPairs(id, port) {
|
|
3968
|
+
const cb = createSubscription(id, port);
|
|
3969
|
+
let ready = false;
|
|
3970
|
+
await this.#koniState.swapService.waitForStarted();
|
|
3971
|
+
const callback = rs => {
|
|
3972
|
+
if (ready) {
|
|
3973
|
+
cb(rs);
|
|
3974
|
+
}
|
|
3975
|
+
};
|
|
3976
|
+
const subscription = this.#koniState.swapService.subscribeSwapPairs(callback);
|
|
3977
|
+
this.createUnsubscriptionHandle(id, subscription.unsubscribe);
|
|
3978
|
+
port.onDisconnect.addListener(() => {
|
|
3979
|
+
this.cancelSubscription(id);
|
|
3980
|
+
});
|
|
3981
|
+
ready = true;
|
|
3982
|
+
return this.#koniState.swapService.getSwapPairs();
|
|
3983
|
+
}
|
|
3984
|
+
async handleSwapRequest(request) {
|
|
3985
|
+
return this.#koniState.swapService.handleSwapRequest(request);
|
|
3986
|
+
}
|
|
3987
|
+
async getLatestSwapQuote(swapRequest) {
|
|
3988
|
+
return this.#koniState.swapService.getLatestQuotes(swapRequest);
|
|
3989
|
+
}
|
|
3990
|
+
async validateSwapProcess(params) {
|
|
3991
|
+
return this.#koniState.swapService.validateSwapProcess(params);
|
|
3992
|
+
}
|
|
3993
|
+
async handleSwapStep(inputData) {
|
|
3994
|
+
const {
|
|
3995
|
+
address,
|
|
3996
|
+
process,
|
|
3997
|
+
quote,
|
|
3998
|
+
recipient
|
|
3999
|
+
} = inputData;
|
|
4000
|
+
if (!quote || !address || !process) {
|
|
4001
|
+
return this.#koniState.transactionService.generateBeforeHandleResponseErrors([new TransactionError(BasicTxErrorType.INTERNAL_ERROR)]);
|
|
4002
|
+
}
|
|
4003
|
+
const isLastStep = inputData.currentStep + 1 === process.steps.length;
|
|
4004
|
+
const swapValidations = await this.#koniState.swapService.validateSwapProcess({
|
|
4005
|
+
address,
|
|
4006
|
+
process,
|
|
4007
|
+
selectedQuote: quote,
|
|
4008
|
+
recipient
|
|
4009
|
+
});
|
|
4010
|
+
if (swapValidations.length > 0) {
|
|
4011
|
+
return this.#koniState.transactionService.generateBeforeHandleResponseErrors(swapValidations);
|
|
4012
|
+
}
|
|
4013
|
+
|
|
4014
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
4015
|
+
const {
|
|
4016
|
+
chainType,
|
|
4017
|
+
extrinsic,
|
|
4018
|
+
extrinsicType,
|
|
4019
|
+
transferNativeAmount,
|
|
4020
|
+
txChain,
|
|
4021
|
+
txData
|
|
4022
|
+
} = await this.#koniState.swapService.handleSwapProcess(inputData);
|
|
4023
|
+
// const chosenFeeToken = process.steps.findIndex((step) => step.type === SwapStepType.SET_FEE_TOKEN) > -1;
|
|
4024
|
+
// const allowSkipValidation = [ExtrinsicType.SET_FEE_TOKEN, ExtrinsicType.SWAP].includes(extrinsicType);
|
|
4025
|
+
|
|
4026
|
+
return await this.#koniState.transactionService.handleTransaction({
|
|
4027
|
+
address,
|
|
4028
|
+
chain: txChain,
|
|
4029
|
+
transaction: extrinsic,
|
|
4030
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
4031
|
+
data: txData,
|
|
4032
|
+
extrinsicType,
|
|
4033
|
+
// change this depends on step
|
|
4034
|
+
chainType,
|
|
4035
|
+
resolveOnDone: !isLastStep,
|
|
4036
|
+
transferNativeAmount
|
|
4037
|
+
// skipFeeValidation: chosenFeeToken && allowSkipValidation
|
|
4038
|
+
});
|
|
4039
|
+
}
|
|
4040
|
+
/* Swap service */
|
|
4041
|
+
|
|
3946
4042
|
// --------------------------------------------------------------
|
|
3947
4043
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
3948
4044
|
async handle(id, type, request, port) {
|
|
@@ -4074,6 +4170,8 @@ export default class KoniExtension {
|
|
|
4074
4170
|
return this.subscribeCrowdloan(id, port);
|
|
4075
4171
|
case 'pri(derivation.createV2)':
|
|
4076
4172
|
return this.derivationCreateV2(request);
|
|
4173
|
+
case 'pri(accounts.batchExportV2)':
|
|
4174
|
+
return this.batchExportV2(request);
|
|
4077
4175
|
case 'pri(json.restoreV2)':
|
|
4078
4176
|
return this.jsonRestoreV2(request);
|
|
4079
4177
|
case 'pri(json.batchRestoreV2)':
|
|
@@ -4472,6 +4570,19 @@ export default class KoniExtension {
|
|
|
4472
4570
|
case 'pri(database.exportJson)':
|
|
4473
4571
|
return this.#koniState.dbService.getExportJson();
|
|
4474
4572
|
/* Database */
|
|
4573
|
+
|
|
4574
|
+
/* Swap service */
|
|
4575
|
+
case 'pri(swapService.subscribePairs)':
|
|
4576
|
+
return this.subscribeSwapPairs(id, port);
|
|
4577
|
+
case 'pri(swapService.handleSwapRequest)':
|
|
4578
|
+
return this.handleSwapRequest(request);
|
|
4579
|
+
case 'pri(swapService.getLatestQuote)':
|
|
4580
|
+
return this.getLatestSwapQuote(request);
|
|
4581
|
+
case 'pri(swapService.validateSwapProcess)':
|
|
4582
|
+
return this.validateSwapProcess(request);
|
|
4583
|
+
case 'pri(swapService.handleSwapStep)':
|
|
4584
|
+
return this.handleSwapStep(request);
|
|
4585
|
+
/* Swap service */
|
|
4475
4586
|
// Default
|
|
4476
4587
|
default:
|
|
4477
4588
|
throw new Error(`Unable to handle message of type ${type}`);
|
|
@@ -21,6 +21,7 @@ import { AuthUrls, MetaRequest, SignRequest } from '@subwallet/extension-base/se
|
|
|
21
21
|
import SettingService from '@subwallet/extension-base/services/setting-service/SettingService';
|
|
22
22
|
import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
|
|
23
23
|
import { SubscanService } from '@subwallet/extension-base/services/subscan-service';
|
|
24
|
+
import { SwapService } from '@subwallet/extension-base/services/swap-service';
|
|
24
25
|
import TransactionService from '@subwallet/extension-base/services/transaction-service';
|
|
25
26
|
import WalletConnectService from '@subwallet/extension-base/services/wallet-connect-service';
|
|
26
27
|
import { BalanceMap, EvmFeeInfo } from '@subwallet/extension-base/types';
|
|
@@ -71,6 +72,7 @@ export default class KoniState {
|
|
|
71
72
|
readonly buyService: BuyService;
|
|
72
73
|
readonly earningService: EarningService;
|
|
73
74
|
readonly feeService: FeeService;
|
|
75
|
+
readonly swapService: SwapService;
|
|
74
76
|
private generalStatus;
|
|
75
77
|
private waitSleeping;
|
|
76
78
|
private waitStarting;
|
|
@@ -28,6 +28,7 @@ import SettingService from '@subwallet/extension-base/services/setting-service/S
|
|
|
28
28
|
import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
|
|
29
29
|
import { SubscanService } from '@subwallet/extension-base/services/subscan-service';
|
|
30
30
|
import { SUBSCAN_API_CHAIN_MAP } from '@subwallet/extension-base/services/subscan-service/subscan-chain-map';
|
|
31
|
+
import { SwapService } from '@subwallet/extension-base/services/swap-service';
|
|
31
32
|
import TransactionService from '@subwallet/extension-base/services/transaction-service';
|
|
32
33
|
import WalletConnectService from '@subwallet/extension-base/services/wallet-connect-service';
|
|
33
34
|
import AccountRefStore from '@subwallet/extension-base/stores/AccountRef';
|
|
@@ -104,6 +105,7 @@ export default class KoniState {
|
|
|
104
105
|
this.transactionService = new TransactionService(this);
|
|
105
106
|
this.earningService = new EarningService(this);
|
|
106
107
|
this.feeService = new FeeService(this);
|
|
108
|
+
this.swapService = new SwapService(this);
|
|
107
109
|
this.subscription = new KoniSubscription(this, this.dbService);
|
|
108
110
|
this.cron = new KoniCron(this, this.subscription, this.dbService);
|
|
109
111
|
this.logger = createLogger('State');
|
|
@@ -226,6 +228,7 @@ export default class KoniState {
|
|
|
226
228
|
this.eventService.emit('chain.ready', true);
|
|
227
229
|
await this.balanceService.init();
|
|
228
230
|
await this.earningService.init();
|
|
231
|
+
await this.swapService.init();
|
|
229
232
|
this.onReady();
|
|
230
233
|
this.onAccountAdd();
|
|
231
234
|
this.onAccountRemove();
|
|
@@ -1396,7 +1399,7 @@ export default class KoniState {
|
|
|
1396
1399
|
// Stopping services
|
|
1397
1400
|
await Promise.all([this.cron.stop(), this.subscription.stop()]);
|
|
1398
1401
|
await this.pauseAllNetworks(undefined, 'IDLE mode');
|
|
1399
|
-
await Promise.all([this.historyService.stop(), this.priceService.stop(), this.balanceService.stop(), this.earningService.stop()]);
|
|
1402
|
+
await Promise.all([this.historyService.stop(), this.priceService.stop(), this.balanceService.stop(), this.earningService.stop(), this.swapService.stop()]);
|
|
1400
1403
|
|
|
1401
1404
|
// Complete sleeping
|
|
1402
1405
|
sleeping.resolve();
|
|
@@ -1428,7 +1431,7 @@ export default class KoniState {
|
|
|
1428
1431
|
}
|
|
1429
1432
|
|
|
1430
1433
|
// Start services
|
|
1431
|
-
await Promise.all([this.cron.start(), this.subscription.start(), this.historyService.start(), this.priceService.start(), this.balanceService.start(), this.earningService.start()]);
|
|
1434
|
+
await Promise.all([this.cron.start(), this.subscription.start(), this.historyService.start(), this.priceService.start(), this.balanceService.start(), this.earningService.start(), this.swapService.start()]);
|
|
1432
1435
|
|
|
1433
1436
|
// Complete starting
|
|
1434
1437
|
starting.resolve();
|