@subwallet/extension-base 1.1.40-1 → 1.1.41-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 +3 -1
- package/cjs/constants/index.js +1 -1
- package/cjs/koni/api/dotsama/transfer.js +1 -1
- package/cjs/koni/api/nft/bit.country/index.js +2 -0
- package/cjs/koni/api/nft/config.js +3 -1
- package/cjs/koni/api/tokens/evm/transfer.js +4 -4
- package/cjs/koni/background/handlers/Extension.js +32 -17
- package/cjs/koni/background/handlers/State.js +41 -9
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/helpers/subscribe/substrate/index.js +58 -0
- package/cjs/services/chain-service/constants.js +11 -7
- package/cjs/services/chain-service/handler/chain-spec/goldberg.js +75 -8
- package/cjs/services/chain-service/index.js +71 -59
- package/cjs/services/chain-service/utils.js +11 -6
- package/cjs/services/earning-service/constants/chains.js +2 -2
- package/cjs/services/earning-service/handlers/liquid-staking/acala.js +9 -3
- package/cjs/services/earning-service/handlers/liquid-staking/bifrost.js +8 -1
- package/cjs/services/earning-service/handlers/liquid-staking/parallel.js +6 -1
- package/cjs/services/earning-service/handlers/liquid-staking/stella-swap.js +25 -17
- package/cjs/services/earning-service/handlers/native-staking/amplitude.js +4 -0
- package/cjs/services/earning-service/handlers/native-staking/astar.js +6 -2
- package/cjs/services/earning-service/handlers/native-staking/para-chain.js +5 -0
- package/cjs/services/earning-service/handlers/native-staking/relay-chain.js +14 -16
- package/cjs/services/earning-service/handlers/nomination-pool/index.js +9 -11
- package/cjs/services/earning-service/handlers/special.js +2 -0
- package/cjs/services/earning-service/service.js +51 -18
- package/cjs/services/fee-service/service.js +70 -0
- package/cjs/services/fee-service/utils/index.js +209 -0
- package/cjs/services/migration-service/scripts/DeleteChainStaking.js +23 -0
- package/cjs/services/migration-service/scripts/index.js +3 -1
- package/cjs/services/transaction-service/index.js +37 -37
- package/cjs/types/fee/index.js +1 -0
- package/cjs/types/index.js +11 -0
- package/cjs/utils/eth.js +2 -105
- package/cjs/utils/index.js +12 -0
- package/cjs/utils/reportError.js +31 -0
- package/constants/index.d.ts +1 -1
- package/constants/index.js +1 -1
- package/koni/api/dotsama/transfer.js +1 -1
- package/koni/api/nft/bit.country/index.js +3 -1
- package/koni/api/nft/config.d.ts +1 -0
- package/koni/api/nft/config.js +1 -0
- package/koni/api/tokens/evm/transfer.js +1 -1
- package/koni/background/handlers/Extension.d.ts +1 -0
- package/koni/background/handlers/Extension.js +18 -3
- package/koni/background/handlers/State.d.ts +4 -1
- package/koni/background/handlers/State.js +32 -1
- package/package.json +31 -6
- package/packageInfo.js +1 -1
- package/services/balance-service/helpers/subscribe/substrate/index.js +59 -1
- package/services/chain-service/constants.d.ts +2 -0
- package/services/chain-service/constants.js +11 -7
- package/services/chain-service/handler/chain-spec/goldberg.d.ts +70 -1
- package/services/chain-service/handler/chain-spec/goldberg.js +75 -8
- package/services/chain-service/index.d.ts +7 -3
- package/services/chain-service/index.js +62 -51
- package/services/chain-service/types.d.ts +4 -0
- package/services/chain-service/utils.d.ts +1 -0
- package/services/chain-service/utils.js +10 -6
- package/services/earning-service/constants/chains.js +2 -2
- package/services/earning-service/handlers/liquid-staking/acala.js +9 -3
- package/services/earning-service/handlers/liquid-staking/bifrost.js +8 -1
- package/services/earning-service/handlers/liquid-staking/parallel.d.ts +1 -1
- package/services/earning-service/handlers/liquid-staking/parallel.js +6 -1
- package/services/earning-service/handlers/liquid-staking/stella-swap.js +25 -17
- package/services/earning-service/handlers/native-staking/amplitude.js +4 -0
- package/services/earning-service/handlers/native-staking/astar.js +6 -2
- package/services/earning-service/handlers/native-staking/para-chain.js +5 -0
- package/services/earning-service/handlers/native-staking/relay-chain.js +15 -17
- package/services/earning-service/handlers/nomination-pool/index.js +10 -12
- package/services/earning-service/handlers/special.d.ts +1 -0
- package/services/earning-service/handlers/special.js +2 -0
- package/services/earning-service/service.d.ts +4 -1
- package/services/earning-service/service.js +52 -19
- package/services/fee-service/service.d.ts +12 -0
- package/services/fee-service/service.js +63 -0
- package/services/fee-service/utils/index.d.ts +8 -0
- package/services/fee-service/utils/index.js +193 -0
- package/services/migration-service/scripts/DeleteChainStaking.d.ts +4 -0
- package/services/migration-service/scripts/DeleteChainStaking.js +15 -0
- package/services/migration-service/scripts/index.js +3 -1
- package/services/transaction-service/index.js +2 -2
- package/types/fee/index.d.ts +49 -0
- package/types/fee/index.js +1 -0
- package/types/index.d.ts +1 -0
- package/types/index.js +1 -0
- package/types/yield/info/account/unstake.d.ts +2 -0
- package/types/yield/info/pallet.d.ts +4 -0
- package/utils/eth.d.ts +0 -15
- package/utils/eth.js +0 -101
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/reportError.d.ts +1 -0
- package/utils/reportError.js +23 -0
|
@@ -22,9 +22,25 @@ const chainSpec = {
|
|
|
22
22
|
appLookup: 'DataLookup',
|
|
23
23
|
commitment: 'KateCommitment'
|
|
24
24
|
},
|
|
25
|
+
V2HeaderExtension: {
|
|
26
|
+
appLookup: 'DataLookup',
|
|
27
|
+
commitment: 'KateCommitment'
|
|
28
|
+
},
|
|
29
|
+
V3HeaderExtension: {
|
|
30
|
+
appLookup: 'DataLookup',
|
|
31
|
+
commitment: 'KateCommitment'
|
|
32
|
+
},
|
|
33
|
+
VTHeaderExtension: {
|
|
34
|
+
newField: 'Vec<u8>',
|
|
35
|
+
commitment: 'KateCommitment',
|
|
36
|
+
appLookup: 'DataLookup'
|
|
37
|
+
},
|
|
25
38
|
HeaderExtension: {
|
|
26
39
|
_enum: {
|
|
27
|
-
V1: 'V1HeaderExtension'
|
|
40
|
+
V1: 'V1HeaderExtension',
|
|
41
|
+
V2: 'V2HeaderExtension',
|
|
42
|
+
V3: 'V3HeaderExtension',
|
|
43
|
+
VTest: 'VTHeaderExtension'
|
|
28
44
|
}
|
|
29
45
|
},
|
|
30
46
|
DaHeader: {
|
|
@@ -44,10 +60,12 @@ const chainSpec = {
|
|
|
44
60
|
extra: 'CheckAppIdExtra',
|
|
45
61
|
types: 'CheckAppIdTypes'
|
|
46
62
|
},
|
|
63
|
+
BlockLengthColumns: 'Compact<u32>',
|
|
64
|
+
BlockLengthRows: 'Compact<u32>',
|
|
47
65
|
BlockLength: {
|
|
48
66
|
max: 'PerDispatchClass',
|
|
49
|
-
cols: '
|
|
50
|
-
rows: '
|
|
67
|
+
cols: 'BlockLengthColumns',
|
|
68
|
+
rows: 'BlockLengthRows',
|
|
51
69
|
chunkSize: 'Compact<u32>'
|
|
52
70
|
},
|
|
53
71
|
PerDispatchClass: {
|
|
@@ -59,12 +77,37 @@ const chainSpec = {
|
|
|
59
77
|
root: 'H256',
|
|
60
78
|
proof: 'Vec<H256>',
|
|
61
79
|
numberOfLeaves: 'Compact<u32>',
|
|
62
|
-
|
|
80
|
+
leafIndex: 'Compact<u32>',
|
|
63
81
|
leaf: 'H256'
|
|
64
82
|
},
|
|
83
|
+
DataProofV2: {
|
|
84
|
+
dataRoot: 'H256',
|
|
85
|
+
blobRoot: 'H256',
|
|
86
|
+
bridgeRoot: 'H256',
|
|
87
|
+
proof: 'Vec<H256>',
|
|
88
|
+
numberOfLeaves: 'Compact<u32>',
|
|
89
|
+
leafIndex: 'Compact<u32>',
|
|
90
|
+
leaf: 'H256'
|
|
91
|
+
},
|
|
92
|
+
ProofResponse: {
|
|
93
|
+
dataProof: 'DataProofV2',
|
|
94
|
+
message: 'Option<Message>'
|
|
95
|
+
},
|
|
96
|
+
Message: {
|
|
97
|
+
messageType: 'MessageType',
|
|
98
|
+
from: 'H256',
|
|
99
|
+
to: 'H256',
|
|
100
|
+
originDomain: 'u32',
|
|
101
|
+
destinationDomain: 'u32',
|
|
102
|
+
data: 'Vec<u8>',
|
|
103
|
+
id: 'u64'
|
|
104
|
+
},
|
|
105
|
+
MessageType: {
|
|
106
|
+
_enum: ['ArbitraryMessage', 'FungibleToken']
|
|
107
|
+
},
|
|
65
108
|
Cell: {
|
|
66
|
-
row: '
|
|
67
|
-
col: '
|
|
109
|
+
row: 'BlockLengthRows',
|
|
110
|
+
col: 'BlockLengthColumns'
|
|
68
111
|
}
|
|
69
112
|
},
|
|
70
113
|
rpc: {
|
|
@@ -90,10 +133,22 @@ const chainSpec = {
|
|
|
90
133
|
}],
|
|
91
134
|
type: 'Vec<u8>'
|
|
92
135
|
},
|
|
136
|
+
queryAppData: {
|
|
137
|
+
description: 'Fetches app data rows for the given app',
|
|
138
|
+
params: [{
|
|
139
|
+
name: 'app_id',
|
|
140
|
+
type: 'AppId'
|
|
141
|
+
}, {
|
|
142
|
+
name: 'at',
|
|
143
|
+
type: 'Hash',
|
|
144
|
+
isOptional: true
|
|
145
|
+
}],
|
|
146
|
+
type: 'Vec<Option<Vec<u8>>>'
|
|
147
|
+
},
|
|
93
148
|
queryDataProof: {
|
|
94
|
-
description: 'Generate the data proof for the given `
|
|
149
|
+
description: 'Generate the data proof for the given `transaction_index`',
|
|
95
150
|
params: [{
|
|
96
|
-
name: '
|
|
151
|
+
name: 'transaction_index',
|
|
97
152
|
type: 'u32'
|
|
98
153
|
}, {
|
|
99
154
|
name: 'at',
|
|
@@ -101,6 +156,18 @@ const chainSpec = {
|
|
|
101
156
|
isOptional: true
|
|
102
157
|
}],
|
|
103
158
|
type: 'DataProof'
|
|
159
|
+
},
|
|
160
|
+
queryDataProofV2: {
|
|
161
|
+
description: 'Generate the data proof for the given `transaction_index`',
|
|
162
|
+
params: [{
|
|
163
|
+
name: 'transaction_index',
|
|
164
|
+
type: 'u32'
|
|
165
|
+
}, {
|
|
166
|
+
name: 'at',
|
|
167
|
+
type: 'Hash',
|
|
168
|
+
isOptional: true
|
|
169
|
+
}],
|
|
170
|
+
type: 'ProofResponse'
|
|
104
171
|
}
|
|
105
172
|
}
|
|
106
173
|
},
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { _AssetRef, _AssetType, _ChainAsset, _ChainInfo, _MultiChainAsset } from '@subwallet/chain-list/types';
|
|
3
3
|
import { AssetSetting, ValidateNetworkResponse } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
4
|
import { MantaPrivateHandler } from '@subwallet/extension-base/services/chain-service/handler/manta/MantaPrivateHandler';
|
|
5
|
-
import { _ChainConnectionStatus, _ChainState, _NetworkUpsertParams, _ValidateCustomAssetRequest, _ValidateCustomAssetResponse } from '@subwallet/extension-base/services/chain-service/types';
|
|
5
|
+
import { _ChainApiStatus, _ChainConnectionStatus, _ChainState, _NetworkUpsertParams, _ValidateCustomAssetRequest, _ValidateCustomAssetResponse } from '@subwallet/extension-base/services/chain-service/types';
|
|
6
6
|
import { EventService } from '@subwallet/extension-base/services/event-service';
|
|
7
7
|
import { IMetadataItem } from '@subwallet/extension-base/services/storage-service/databases';
|
|
8
8
|
import DatabaseService from '@subwallet/extension-base/services/storage-service/DatabaseService';
|
|
@@ -19,6 +19,7 @@ export declare class ChainService {
|
|
|
19
19
|
get mantaPay(): MantaPrivateHandler | undefined;
|
|
20
20
|
private chainInfoMapSubject;
|
|
21
21
|
private chainStateMapSubject;
|
|
22
|
+
private chainStatusMapSubject;
|
|
22
23
|
private assetRegistrySubject;
|
|
23
24
|
private multiChainAssetMapSubject;
|
|
24
25
|
private xcmRefMapSubject;
|
|
@@ -40,6 +41,7 @@ export declare class ChainService {
|
|
|
40
41
|
subscribeMultiChainAssetMap(): Subject<Record<string, _MultiChainAsset>>;
|
|
41
42
|
subscribeXcmRefMap(): Subject<Record<string, _AssetRef>>;
|
|
42
43
|
subscribeChainStateMap(): Subject<Record<string, _ChainState>>;
|
|
44
|
+
subscribeChainStatusMap(): BehaviorSubject<Record<string, _ChainApiStatus>>;
|
|
43
45
|
getAssetRegistry(): Record<string, _ChainAsset>;
|
|
44
46
|
getMultiChainAssetMap(): Record<string, _MultiChainAsset>;
|
|
45
47
|
getSmartContractTokens(): Record<string, _ChainAsset>;
|
|
@@ -51,6 +53,8 @@ export declare class ChainService {
|
|
|
51
53
|
getAssetRefMap(): Record<string, _AssetRef>;
|
|
52
54
|
getChainStateMap(): Record<string, _ChainState>;
|
|
53
55
|
getChainStateByKey(key: string): _ChainState;
|
|
56
|
+
getChainStatusMap(): Record<string, _ChainApiStatus>;
|
|
57
|
+
getChainStatusByKey(key: string): _ChainApiStatus;
|
|
54
58
|
getActiveChains(): string[];
|
|
55
59
|
getSupportedSmartContractTypes(): _AssetType[];
|
|
56
60
|
getActiveChainInfoMap(): Record<string, _ChainInfo>;
|
|
@@ -66,7 +70,8 @@ export declare class ChainService {
|
|
|
66
70
|
forceRemoveChain(slug: string): boolean;
|
|
67
71
|
removeCustomChain(slug: string): boolean;
|
|
68
72
|
resetChainInfoMap(excludedChains?: string[]): boolean;
|
|
69
|
-
|
|
73
|
+
private connectionStatusQueueMap;
|
|
74
|
+
updateChainConnectionStatus(slug: string, connectionStatus: _ChainConnectionStatus): void;
|
|
70
75
|
upsertCustomToken(token: _ChainAsset): string;
|
|
71
76
|
deleteAssetsByChain(chainSlug: string): void;
|
|
72
77
|
deleteCustomAssets(targetAssets: string[]): void;
|
|
@@ -109,7 +114,6 @@ export declare class ChainService {
|
|
|
109
114
|
refreshEvmApi(slug: string): void;
|
|
110
115
|
stopAllChainApis(): Promise<void>;
|
|
111
116
|
resumeAllChainApis(): Promise<void>;
|
|
112
|
-
checkAndUpdateStatusMapForChain(chainSlug: string): void;
|
|
113
117
|
initAssetSettings(): Promise<void>;
|
|
114
118
|
setAssetSettings(assetSettings: Record<string, AssetSetting>, emitEvent?: boolean): void;
|
|
115
119
|
setMantaZkAssetSettings(visible: boolean): void;
|
|
@@ -31,6 +31,7 @@ export class ChainService {
|
|
|
31
31
|
// TODO: consider BehaviorSubject
|
|
32
32
|
chainInfoMapSubject = new Subject();
|
|
33
33
|
chainStateMapSubject = new Subject();
|
|
34
|
+
chainStatusMapSubject = new BehaviorSubject({});
|
|
34
35
|
assetRegistrySubject = new Subject();
|
|
35
36
|
multiChainAssetMapSubject = new Subject();
|
|
36
37
|
xcmRefMapSubject = new Subject();
|
|
@@ -104,6 +105,9 @@ export class ChainService {
|
|
|
104
105
|
subscribeChainStateMap() {
|
|
105
106
|
return this.chainStateMapSubject;
|
|
106
107
|
}
|
|
108
|
+
subscribeChainStatusMap() {
|
|
109
|
+
return this.chainStatusMapSubject;
|
|
110
|
+
}
|
|
107
111
|
getAssetRegistry() {
|
|
108
112
|
return this.dataMap.assetRegistry;
|
|
109
113
|
}
|
|
@@ -181,6 +185,12 @@ export class ChainService {
|
|
|
181
185
|
getChainStateByKey(key) {
|
|
182
186
|
return this.dataMap.chainStateMap[key];
|
|
183
187
|
}
|
|
188
|
+
getChainStatusMap() {
|
|
189
|
+
return this.chainStatusMapSubject.getValue();
|
|
190
|
+
}
|
|
191
|
+
getChainStatusByKey(key) {
|
|
192
|
+
return this.getChainStatusMap()[key];
|
|
193
|
+
}
|
|
184
194
|
getActiveChains() {
|
|
185
195
|
return Object.entries(this.dataMap.chainStateMap).filter(([, chainState]) => _isChainEnabled(chainState)).map(([key]) => key);
|
|
186
196
|
}
|
|
@@ -339,9 +349,31 @@ export class ChainService {
|
|
|
339
349
|
this.lockChainInfoMap = false;
|
|
340
350
|
return true;
|
|
341
351
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
352
|
+
connectionStatusQueueMap = {};
|
|
353
|
+
updateChainConnectionStatus(slug, connectionStatus) {
|
|
354
|
+
this.connectionStatusQueueMap[slug] = connectionStatus;
|
|
355
|
+
addLazy('updateChainConnectionStatus', () => {
|
|
356
|
+
const chainStatusMap = this.getChainStatusMap();
|
|
357
|
+
let update = false;
|
|
358
|
+
Object.entries(this.connectionStatusQueueMap).forEach(([slug, status]) => {
|
|
359
|
+
if (chainStatusMap[slug]) {
|
|
360
|
+
if (chainStatusMap[slug].connectionStatus !== status) {
|
|
361
|
+
chainStatusMap[slug].connectionStatus = status;
|
|
362
|
+
chainStatusMap[slug].lastUpdated = Date.now();
|
|
363
|
+
update = true;
|
|
364
|
+
}
|
|
365
|
+
} else {
|
|
366
|
+
chainStatusMap[slug] = {
|
|
367
|
+
slug,
|
|
368
|
+
connectionStatus: status,
|
|
369
|
+
lastUpdated: Date.now()
|
|
370
|
+
};
|
|
371
|
+
update = true;
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
this.connectionStatusQueueMap = {};
|
|
375
|
+
update && this.chainStatusMapSubject.next(chainStatusMap);
|
|
376
|
+
});
|
|
345
377
|
}
|
|
346
378
|
upsertCustomToken(token) {
|
|
347
379
|
if (token.slug.length === 0) {
|
|
@@ -470,13 +502,17 @@ export class ChainService {
|
|
|
470
502
|
this.logger.log('Finished updating latest asset ref');
|
|
471
503
|
}
|
|
472
504
|
handleLatestPriceId(latestPriceIds) {
|
|
505
|
+
let isUpdated = false;
|
|
473
506
|
Object.entries(latestPriceIds).forEach(([slug, priceId]) => {
|
|
474
|
-
if (this.dataMap.assetRegistry[slug]) {
|
|
507
|
+
if (this.dataMap.assetRegistry[slug] && this.dataMap.assetRegistry[slug].priceId !== priceId) {
|
|
508
|
+
isUpdated = true;
|
|
475
509
|
this.dataMap.assetRegistry[slug].priceId = priceId;
|
|
476
510
|
}
|
|
477
511
|
});
|
|
478
|
-
|
|
479
|
-
|
|
512
|
+
if (isUpdated) {
|
|
513
|
+
this.assetRegistrySubject.next(this.dataMap.assetRegistry);
|
|
514
|
+
this.eventService.emit('asset.updateState', '');
|
|
515
|
+
}
|
|
480
516
|
this.logger.log('Finished updating latest price IDs');
|
|
481
517
|
}
|
|
482
518
|
handleLatestData() {
|
|
@@ -486,12 +522,10 @@ export class ChainService {
|
|
|
486
522
|
this.fetchLatestBlockedAssetRef().then(latestAssetRef => {
|
|
487
523
|
this.handleLatestBlockedAssetRef(latestAssetRef);
|
|
488
524
|
}).catch(console.error);
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
// }).catch(console.error);
|
|
525
|
+
this.fetchLatestPriceIdsData().then(latestPriceIds => {
|
|
526
|
+
this.handleLatestPriceId(latestPriceIds);
|
|
527
|
+
}).catch(console.error);
|
|
493
528
|
}
|
|
494
|
-
|
|
495
529
|
async initApis() {
|
|
496
530
|
const chainInfoMap = this.getChainInfoMap();
|
|
497
531
|
const chainStateMap = this.getChainStateMap();
|
|
@@ -513,13 +547,8 @@ export class ChainService {
|
|
|
513
547
|
providerName
|
|
514
548
|
} = this.getChainCurrentProviderByKey(chainInfo.slug);
|
|
515
549
|
const onUpdateStatus = status => {
|
|
516
|
-
const
|
|
517
|
-
|
|
518
|
-
// Avoid unnecessary update in case disable chain
|
|
519
|
-
if (currentStatus !== status) {
|
|
520
|
-
this.setChainConnectionStatus(chainInfo.slug, status);
|
|
521
|
-
this.updateChainStateMapSubscription();
|
|
522
|
-
}
|
|
550
|
+
const slug = chainInfo.slug;
|
|
551
|
+
this.updateChainConnectionStatus(slug, status);
|
|
523
552
|
};
|
|
524
553
|
if (chainInfo.substrateInfo !== null && chainInfo.substrateInfo !== undefined) {
|
|
525
554
|
if (_MANTA_ZK_CHAIN_GROUP.includes(chainInfo.slug) && MODULE_SUPPORT.MANTA_ZK && this.mantaChainHandler) {
|
|
@@ -618,7 +647,7 @@ export class ChainService {
|
|
|
618
647
|
this.lockChainInfoMap = true;
|
|
619
648
|
chainStateMap[chainSlug].active = false;
|
|
620
649
|
// Set disconnect state for inactive chain
|
|
621
|
-
|
|
650
|
+
this.updateChainConnectionStatus(chainSlug, _ChainConnectionStatus.DISCONNECTED);
|
|
622
651
|
this.destroyApiForChain(chainInfo);
|
|
623
652
|
this.dbService.updateChainStore({
|
|
624
653
|
...chainInfo,
|
|
@@ -711,9 +740,9 @@ export class ChainService {
|
|
|
711
740
|
this.dataMap.chainStateMap[chainInfo.slug] = {
|
|
712
741
|
currentProvider: providerKey,
|
|
713
742
|
slug: chainInfo.slug,
|
|
714
|
-
connectionStatus: _ChainConnectionStatus.DISCONNECTED,
|
|
715
743
|
active: _DEFAULT_ACTIVE_CHAINS.includes(chainInfo.slug)
|
|
716
744
|
};
|
|
745
|
+
this.updateChainConnectionStatus(chainInfo.slug, _ChainConnectionStatus.DISCONNECTED);
|
|
717
746
|
|
|
718
747
|
// create data for storage
|
|
719
748
|
newStorageData.push({
|
|
@@ -764,9 +793,9 @@ export class ChainService {
|
|
|
764
793
|
this.dataMap.chainStateMap[storedSlug] = {
|
|
765
794
|
currentProvider: selectedProvider,
|
|
766
795
|
slug: storedSlug,
|
|
767
|
-
connectionStatus: _ChainConnectionStatus.DISCONNECTED,
|
|
768
796
|
active: canActive && storedChainInfo.active
|
|
769
797
|
};
|
|
798
|
+
this.updateChainConnectionStatus(storedSlug, _ChainConnectionStatus.DISCONNECTED);
|
|
770
799
|
newStorageData.push({
|
|
771
800
|
...mergedChainInfoMap[storedSlug],
|
|
772
801
|
active: canActive && storedChainInfo.active,
|
|
@@ -786,9 +815,9 @@ export class ChainService {
|
|
|
786
815
|
this.dataMap.chainStateMap[duplicatedDefaultSlug] = {
|
|
787
816
|
currentProvider: storedChainInfo.currentProvider,
|
|
788
817
|
slug: duplicatedDefaultSlug,
|
|
789
|
-
connectionStatus: _ChainConnectionStatus.DISCONNECTED,
|
|
790
818
|
active: storedChainInfo.active
|
|
791
819
|
};
|
|
820
|
+
this.updateChainConnectionStatus(duplicatedDefaultSlug, _ChainConnectionStatus.DISCONNECTED);
|
|
792
821
|
newStorageData.push({
|
|
793
822
|
...mergedChainInfoMap[duplicatedDefaultSlug],
|
|
794
823
|
active: storedChainInfo.active,
|
|
@@ -813,9 +842,9 @@ export class ChainService {
|
|
|
813
842
|
currentProvider: storedChainInfo.currentProvider,
|
|
814
843
|
// TODO: review
|
|
815
844
|
slug: storedSlug,
|
|
816
|
-
connectionStatus: _ChainConnectionStatus.DISCONNECTED,
|
|
817
845
|
active: storedChainInfo.active
|
|
818
846
|
};
|
|
847
|
+
this.updateChainConnectionStatus(storedSlug, _ChainConnectionStatus.DISCONNECTED);
|
|
819
848
|
newStorageData.push({
|
|
820
849
|
...mergedChainInfoMap[storedSlug],
|
|
821
850
|
active: storedChainInfo.active,
|
|
@@ -833,9 +862,9 @@ export class ChainService {
|
|
|
833
862
|
this.dataMap.chainStateMap[slug] = {
|
|
834
863
|
currentProvider: Object.keys(chainInfo.providers)[0],
|
|
835
864
|
slug,
|
|
836
|
-
connectionStatus: _ChainConnectionStatus.DISCONNECTED,
|
|
837
865
|
active: _DEFAULT_ACTIVE_CHAINS.includes(slug)
|
|
838
866
|
};
|
|
867
|
+
this.updateChainConnectionStatus(slug, _ChainConnectionStatus.DISCONNECTED);
|
|
839
868
|
newStorageData.push({
|
|
840
869
|
...mergedChainInfoMap[slug],
|
|
841
870
|
active: _DEFAULT_ACTIVE_CHAINS.includes(slug),
|
|
@@ -910,9 +939,7 @@ export class ChainService {
|
|
|
910
939
|
}
|
|
911
940
|
}
|
|
912
941
|
updateChainStateMapSubscription() {
|
|
913
|
-
|
|
914
|
-
this.chainStateMapSubject.next(this.getChainStateMap());
|
|
915
|
-
}, 300, 900);
|
|
942
|
+
this.chainStateMapSubject.next(this.getChainStateMap());
|
|
916
943
|
}
|
|
917
944
|
updateChainInfoMapSubscription() {
|
|
918
945
|
this.chainInfoMapSubject.next(this.getChainInfoMap());
|
|
@@ -1021,10 +1048,17 @@ export class ChainService {
|
|
|
1021
1048
|
const chainStateMap = this.getChainStateMap();
|
|
1022
1049
|
chainStateMap[newChainSlug] = {
|
|
1023
1050
|
active: true,
|
|
1024
|
-
connectionStatus: _ChainConnectionStatus.DISCONNECTED,
|
|
1025
1051
|
currentProvider: params.chainEditInfo.currentProvider,
|
|
1026
1052
|
slug: newChainSlug
|
|
1027
1053
|
};
|
|
1054
|
+
|
|
1055
|
+
// const chainStatusMap = this.getChainStatusMap();
|
|
1056
|
+
// const chainStatusMap[newChainSlug] = {
|
|
1057
|
+
// slug: newChainSlug,
|
|
1058
|
+
// connectionStatus: _ChainConnectionStatus.DISCONNECTED,
|
|
1059
|
+
// lastUpdated: Date.now()
|
|
1060
|
+
// };
|
|
1061
|
+
|
|
1028
1062
|
await this.initApiForChain(chainInfo);
|
|
1029
1063
|
|
|
1030
1064
|
// create a record in assetRegistry for native token and update store/subscription
|
|
@@ -1309,29 +1343,6 @@ export class ChainService {
|
|
|
1309
1343
|
await Promise.all([this.substrateChainHandler.wakeUp(), this.evmChainHandler.wakeUp()]);
|
|
1310
1344
|
this.checkLatestData();
|
|
1311
1345
|
}
|
|
1312
|
-
checkAndUpdateStatusMapForChain(chainSlug) {
|
|
1313
|
-
const substrateApiMap = this.getSubstrateApiMap();
|
|
1314
|
-
const evmApiMap = this.getEvmApiMap();
|
|
1315
|
-
const chainState = this.getChainStateByKey(chainSlug);
|
|
1316
|
-
let update = false;
|
|
1317
|
-
function updateState(current, status) {
|
|
1318
|
-
if (current.connectionStatus !== status) {
|
|
1319
|
-
current.connectionStatus = status;
|
|
1320
|
-
update = true;
|
|
1321
|
-
}
|
|
1322
|
-
}
|
|
1323
|
-
if (chainState.active) {
|
|
1324
|
-
const api = substrateApiMap[chainSlug] || evmApiMap[chainSlug];
|
|
1325
|
-
if (api) {
|
|
1326
|
-
updateState(chainState, api.isApiConnected ? _ChainConnectionStatus.CONNECTED : _ChainConnectionStatus.DISCONNECTED);
|
|
1327
|
-
}
|
|
1328
|
-
} else {
|
|
1329
|
-
updateState(chainState, _ChainConnectionStatus.DISCONNECTED);
|
|
1330
|
-
}
|
|
1331
|
-
if (update) {
|
|
1332
|
-
this.dataMap.chainStateMap[chainSlug] = chainState;
|
|
1333
|
-
}
|
|
1334
|
-
}
|
|
1335
1346
|
async initAssetSettings() {
|
|
1336
1347
|
const assetSettings = await this.getAssetSettings();
|
|
1337
1348
|
const activeChainSlugs = this.getActiveChainSlugs();
|
|
@@ -22,7 +22,11 @@ export interface _ChainState {
|
|
|
22
22
|
slug: string;
|
|
23
23
|
active: boolean;
|
|
24
24
|
currentProvider: string;
|
|
25
|
+
}
|
|
26
|
+
export interface _ChainApiStatus {
|
|
27
|
+
slug: string;
|
|
25
28
|
connectionStatus: _ChainConnectionStatus;
|
|
29
|
+
lastUpdated: number;
|
|
26
30
|
}
|
|
27
31
|
export interface _SubstrateDefaultFormatBalance {
|
|
28
32
|
decimals?: number[] | number;
|
|
@@ -15,6 +15,7 @@ export declare function _isTokenTransferredByEvm(tokenInfo: _ChainAsset): boolea
|
|
|
15
15
|
export declare function _checkSmartContractSupportByChain(chainInfo: _ChainInfo, contractType: _AssetType): boolean;
|
|
16
16
|
export declare function _getTokenOnChainAssetId(tokenInfo: _ChainAsset): string;
|
|
17
17
|
export declare function _getTokenOnChainInfo(tokenInfo: _ChainAsset): Record<string, any>;
|
|
18
|
+
export declare function _isBridgedToken(tokenInfo: _ChainAsset): boolean;
|
|
18
19
|
export declare function _getTokenMinAmount(tokenInfo: _ChainAsset): string;
|
|
19
20
|
export declare function _isChainEvmCompatible(chainInfo: _ChainInfo): boolean;
|
|
20
21
|
export declare function _isNativeToken(tokenInfo: _ChainAsset): boolean;
|
|
@@ -88,6 +88,10 @@ export function _getTokenOnChainInfo(tokenInfo) {
|
|
|
88
88
|
var _tokenInfo$metadata4;
|
|
89
89
|
return (_tokenInfo$metadata4 = tokenInfo.metadata) === null || _tokenInfo$metadata4 === void 0 ? void 0 : _tokenInfo$metadata4.onChainInfo;
|
|
90
90
|
}
|
|
91
|
+
export function _isBridgedToken(tokenInfo) {
|
|
92
|
+
var _tokenInfo$metadata5;
|
|
93
|
+
return (_tokenInfo$metadata5 = tokenInfo.metadata) === null || _tokenInfo$metadata5 === void 0 ? void 0 : _tokenInfo$metadata5.isBridged;
|
|
94
|
+
}
|
|
91
95
|
export function _getTokenMinAmount(tokenInfo) {
|
|
92
96
|
return tokenInfo.minAmount || '0';
|
|
93
97
|
}
|
|
@@ -240,16 +244,16 @@ export function _isXcmPathSupported(originTokenSlug, destinationTokenSlug, asset
|
|
|
240
244
|
return assetRef.path === _AssetRefPath.XCM;
|
|
241
245
|
}
|
|
242
246
|
export function _getXcmAssetType(tokenInfo) {
|
|
243
|
-
var _tokenInfo$
|
|
244
|
-
return ((_tokenInfo$
|
|
247
|
+
var _tokenInfo$metadata6;
|
|
248
|
+
return ((_tokenInfo$metadata6 = tokenInfo.metadata) === null || _tokenInfo$metadata6 === void 0 ? void 0 : _tokenInfo$metadata6.assetType) || '';
|
|
245
249
|
}
|
|
246
250
|
export function _getXcmAssetId(tokenInfo) {
|
|
247
|
-
var _tokenInfo$
|
|
248
|
-
return ((_tokenInfo$
|
|
251
|
+
var _tokenInfo$metadata7;
|
|
252
|
+
return ((_tokenInfo$metadata7 = tokenInfo.metadata) === null || _tokenInfo$metadata7 === void 0 ? void 0 : _tokenInfo$metadata7.assetId) || '-1';
|
|
249
253
|
}
|
|
250
254
|
export function _getXcmAssetMultilocation(tokenInfo) {
|
|
251
|
-
var _tokenInfo$
|
|
252
|
-
return (_tokenInfo$
|
|
255
|
+
var _tokenInfo$metadata8;
|
|
256
|
+
return (_tokenInfo$metadata8 = tokenInfo.metadata) === null || _tokenInfo$metadata8 === void 0 ? void 0 : _tokenInfo$metadata8.multilocation;
|
|
253
257
|
}
|
|
254
258
|
export function _getXcmTransferType(originChainInfo, destinationChainInfo) {
|
|
255
259
|
var _originChainInfo$subs, _destinationChainInfo;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
export const _STAKING_CHAIN_GROUP = {
|
|
5
|
-
relay: ['polkadot', 'kusama', 'aleph', 'polkadex', 'ternoa', '
|
|
5
|
+
relay: ['polkadot', 'kusama', 'aleph', 'polkadex', 'ternoa', 'alephTest', 'polkadexTest', 'westend', 'kate', 'edgeware', 'creditcoin', 'vara_network', 'goldberg_testnet'],
|
|
6
6
|
para: ['moonbeam', 'moonriver', 'moonbase', 'turing', 'turingStaging', 'bifrost', 'bifrost_testnet', 'calamari_test', 'calamari', 'manta_network'],
|
|
7
7
|
astar: ['astar', 'shiden', 'shibuya'],
|
|
8
8
|
amplitude: ['amplitude', 'amplitude_test', 'kilt', 'kilt_peregrine', 'pendulum', 'krest_network'],
|
|
@@ -12,7 +12,7 @@ export const _STAKING_CHAIN_GROUP = {
|
|
|
12
12
|
bifrost: ['bifrost', 'bifrost_testnet'],
|
|
13
13
|
aleph: ['aleph', 'alephTest'],
|
|
14
14
|
// A0 has distinct tokenomics
|
|
15
|
-
ternoa: ['ternoa'
|
|
15
|
+
ternoa: ['ternoa'],
|
|
16
16
|
liquidStaking: ['bifrost_dot', 'acala', 'parallel', 'moonbeam'],
|
|
17
17
|
lending: ['interlay'],
|
|
18
18
|
krest_network: ['krest_network']
|
|
@@ -23,7 +23,8 @@ export default class AcalaLiquidStakingPoolHandler extends BaseLiquidStakingPool
|
|
|
23
23
|
defaultUnstake: true,
|
|
24
24
|
fastUnstake: true,
|
|
25
25
|
cancelUnstake: false,
|
|
26
|
-
withdraw:
|
|
26
|
+
withdraw: false,
|
|
27
|
+
// TODO: Change after verify unstake info
|
|
27
28
|
claimReward: false
|
|
28
29
|
};
|
|
29
30
|
constructor(state, chain) {
|
|
@@ -112,6 +113,7 @@ export default class AcalaLiquidStakingPoolHandler extends BaseLiquidStakingPool
|
|
|
112
113
|
}
|
|
113
114
|
const balances = _balances;
|
|
114
115
|
const redeemRequests = await substrateApi.api.query.homa.redeemRequests.multi(useAddresses);
|
|
116
|
+
// This rate is multiple with decimals
|
|
115
117
|
const exchangeRate = await this.getExchangeRate();
|
|
116
118
|
const decimals = BN_TEN.pow(new BN(this.rateDecimals));
|
|
117
119
|
for (let i = 0; i < balances.length; i++) {
|
|
@@ -123,14 +125,17 @@ export default class AcalaLiquidStakingPoolHandler extends BaseLiquidStakingPool
|
|
|
123
125
|
const unstakings = [];
|
|
124
126
|
const redeemRequest = redeemRequests[i].toPrimitive();
|
|
125
127
|
if (redeemRequest) {
|
|
128
|
+
// If withdrawable = false, redeem request is claimed
|
|
126
129
|
const [redeemAmount, withdrawable] = redeemRequest;
|
|
127
|
-
|
|
130
|
+
|
|
131
|
+
// Redeem amount in derivative token
|
|
132
|
+
const amount = new BN(redeemAmount).mul(new BN(exchangeRate)).div(decimals);
|
|
128
133
|
totalBalance = totalBalance.add(amount);
|
|
129
134
|
unlockingBalance = unlockingBalance.add(amount);
|
|
130
135
|
unstakings.push({
|
|
131
136
|
chain: this.chain,
|
|
132
137
|
status: withdrawable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
|
|
133
|
-
claimable:
|
|
138
|
+
claimable: amount.toString()
|
|
134
139
|
});
|
|
135
140
|
}
|
|
136
141
|
const result = {
|
|
@@ -203,6 +208,7 @@ export default class AcalaLiquidStakingPoolHandler extends BaseLiquidStakingPool
|
|
|
203
208
|
async handleYieldRedeem(amount, address, selectedTarget) {
|
|
204
209
|
const substrateApi = await this.substrateApi.isReady;
|
|
205
210
|
const weightedMinAmount = await this.createParamToRedeem(amount, address);
|
|
211
|
+
// const extrinsic = substrateApi.api.tx.stableAsset.swap(0, 1, 0, amount, weightedMinAmount);
|
|
206
212
|
const extrinsic = substrateApi.api.tx.aggregatedDex.swapWithExactSupply(
|
|
207
213
|
// Swap path
|
|
208
214
|
[{
|
|
@@ -76,6 +76,8 @@ export default class BifrostLiquidStakingPoolHandler extends BaseLiquidStakingPo
|
|
|
76
76
|
const assetInfo = this.state.getAssetBySlug(this.inputAsset);
|
|
77
77
|
const assetDecimals = 10 ** _getAssetDecimals(assetInfo);
|
|
78
78
|
const rate = parseFloat(exchangeRate.data.slp_polkadot_ratio[0].ratio);
|
|
79
|
+
|
|
80
|
+
/** Special for bifrost, the rate is divined and unknown decimals to convert (asset decimal is 10 but the rate length is 18) */
|
|
79
81
|
this.updateExchangeRate(rate);
|
|
80
82
|
return {
|
|
81
83
|
...this.baseInfo,
|
|
@@ -128,7 +130,7 @@ export default class BifrostLiquidStakingPoolHandler extends BaseLiquidStakingPo
|
|
|
128
130
|
const [_unlockLedgerList, _currentRelayEra, rate] = await Promise.all([substrateApi.api.query.vtokenMinting.userUnlockLedger.multi(useAddresses.map(address => [address, _getTokenOnChainInfo(inputTokenInfo)])), substrateApi.api.query.vtokenMinting.ongoingTimeUnit(_getTokenOnChainInfo(inputTokenInfo)), this.getExchangeRate()]);
|
|
129
131
|
const exchangeRate = new BigNumber(rate);
|
|
130
132
|
const currentRelayEraObj = _currentRelayEra.toPrimitive();
|
|
131
|
-
const currentRelayEra = currentRelayEraObj.
|
|
133
|
+
const currentRelayEra = currentRelayEraObj.era;
|
|
132
134
|
const unlockLedgerList = [];
|
|
133
135
|
const activeBalanceMap = {};
|
|
134
136
|
for (let i = 0; i < balances.length; i++) {
|
|
@@ -188,15 +190,20 @@ export default class BifrostLiquidStakingPoolHandler extends BaseLiquidStakingPo
|
|
|
188
190
|
const isClaimable = unlocking.era - currentRelayEra < 0;
|
|
189
191
|
const remainingEra = unlocking.era - currentRelayEra;
|
|
190
192
|
const waitingTime = remainingEra * _STAKING_ERA_LENGTH_MAP[this.chain];
|
|
193
|
+
// const currentTimestampMs = Date.now();
|
|
194
|
+
// const targetTimestampMs = currentTimestampMs + waitingTime * 60 * 60 * 1000;
|
|
195
|
+
|
|
191
196
|
unlockBalance = unlockBalance.add(new BN(unlocking.balance));
|
|
192
197
|
unstakingList.push({
|
|
193
198
|
chain: this.chain,
|
|
194
199
|
status: isClaimable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
|
|
195
200
|
claimable: unlocking.balance,
|
|
196
201
|
waitingTime: waitingTime
|
|
202
|
+
// targetTimestampMs: targetTimestampMs
|
|
197
203
|
});
|
|
198
204
|
});
|
|
199
205
|
}
|
|
206
|
+
|
|
200
207
|
const activeToTotalBalance = exchangeRate.multipliedBy(bnActiveBalance.toString());
|
|
201
208
|
const totalBalance = activeToTotalBalance.plus(unlockBalance.toString());
|
|
202
209
|
const result = {
|
|
@@ -11,7 +11,7 @@ export default class ParallelLiquidStakingPoolHandler extends BaseLiquidStakingP
|
|
|
11
11
|
protected readonly inputAsset: string;
|
|
12
12
|
protected readonly rewardAssets: string[];
|
|
13
13
|
protected readonly feeAssets: string[];
|
|
14
|
-
readonly minAmountPercent = 0.
|
|
14
|
+
readonly minAmountPercent = 0.96;
|
|
15
15
|
protected readonly rateDecimals = 18;
|
|
16
16
|
protected readonly availableMethod: YieldPoolMethodInfo;
|
|
17
17
|
constructor(state: KoniState, chain: string);
|
|
@@ -14,7 +14,7 @@ export default class ParallelLiquidStakingPoolHandler extends BaseLiquidStakingP
|
|
|
14
14
|
inputAsset = 'parallel-LOCAL-DOT';
|
|
15
15
|
rewardAssets = ['parallel-LOCAL-DOT'];
|
|
16
16
|
feeAssets = ['parallel-NATIVE-PARA'];
|
|
17
|
-
minAmountPercent = 0.
|
|
17
|
+
minAmountPercent = 0.96;
|
|
18
18
|
rateDecimals = 18;
|
|
19
19
|
availableMethod = {
|
|
20
20
|
join: true,
|
|
@@ -126,6 +126,9 @@ export default class ParallelLiquidStakingPoolHandler extends BaseLiquidStakingP
|
|
|
126
126
|
const remainingEra = chunk.era - currentEra;
|
|
127
127
|
const eraTime = _STAKING_ERA_LENGTH_MAP[this.chain] || _STAKING_ERA_LENGTH_MAP.default;
|
|
128
128
|
const waitingTime = remainingEra * eraTime;
|
|
129
|
+
// const currentTimestampMs = Date.now();
|
|
130
|
+
// const targetTimestampMs = currentTimestampMs + waitingTime * 60 * 60 * 1000;
|
|
131
|
+
|
|
129
132
|
totalBalance = totalBalance.add(amount);
|
|
130
133
|
unlockingBalance = unlockingBalance.add(amount);
|
|
131
134
|
unstakings.push({
|
|
@@ -133,9 +136,11 @@ export default class ParallelLiquidStakingPoolHandler extends BaseLiquidStakingP
|
|
|
133
136
|
status: isClaimable ? UnstakingStatus.CLAIMABLE : UnstakingStatus.UNLOCKING,
|
|
134
137
|
claimable: amount.toString(),
|
|
135
138
|
waitingTime: waitingTime
|
|
139
|
+
// targetTimestampMs: targetTimestampMs
|
|
136
140
|
});
|
|
137
141
|
}
|
|
138
142
|
}
|
|
143
|
+
|
|
139
144
|
const result = {
|
|
140
145
|
...this.baseInfo,
|
|
141
146
|
type: this.type,
|