@subwallet/extension-base 1.0.13-0 → 1.1.1-dev.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 +37 -0
- package/background/KoniTypes.js +8 -1
- package/background/handlers/Extension.js +17 -2
- package/background/types.d.ts +6 -1
- package/bundle-polkadot-extension-base.js +20 -0
- package/cjs/background/KoniTypes.js +10 -2
- package/cjs/background/handlers/Extension.js +22 -6
- package/cjs/constants/index.js +7 -1
- package/cjs/defaults.js +1 -1
- package/cjs/koni/api/dotsama/balance.js +5 -0
- package/cjs/koni/api/dotsama/transfer.js +6 -0
- package/cjs/koni/api/staking/bonding/astar.js +2 -2
- package/cjs/koni/api/staking/bonding/relayChain.js +12 -2
- package/cjs/koni/api/staking/bonding/utils.js +2 -2
- package/cjs/koni/background/cron.js +13 -37
- package/cjs/koni/background/handlers/Extension.js +324 -147
- package/cjs/koni/background/handlers/State.js +224 -51
- package/cjs/koni/background/subscription.js +9 -86
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/chain-service/constants.js +10 -4
- package/cjs/services/chain-service/handler/SubstrateApi.js +2 -1
- package/cjs/services/chain-service/handler/SubstrateChainHandler.js +3 -1
- package/cjs/services/chain-service/handler/manta/MantaPrivateHandler.js +147 -0
- package/cjs/services/chain-service/helper/erc20_abi.json +224 -0
- package/cjs/services/chain-service/helper/erc721_abi.json +384 -0
- package/cjs/services/chain-service/helper/psp22_abi.json +1127 -0
- package/cjs/services/chain-service/helper/psp34_abi.json +3144 -0
- package/cjs/services/chain-service/helper/test_erc721_abi.json +393 -0
- package/cjs/services/chain-service/index.js +54 -5
- package/cjs/services/chain-service/utils.js +6 -1
- package/cjs/services/event-service/types.js +3 -1
- package/cjs/services/storage-service/DatabaseService.js +31 -1
- package/cjs/services/storage-service/databases/index.js +3 -0
- package/cjs/services/storage-service/db-stores/MantaPay.js +40 -0
- package/cjs/utils/index.js +12 -0
- package/cjs/utils/lazy.js +52 -0
- package/constants/index.d.ts +2 -0
- package/constants/index.js +2 -0
- package/defaults.d.ts +1 -1
- package/defaults.js +1 -1
- package/koni/api/dotsama/balance.js +6 -1
- package/koni/api/dotsama/transfer.js +7 -1
- package/koni/api/staking/bonding/astar.d.ts +1 -1
- package/koni/api/staking/bonding/astar.js +1 -1
- package/koni/api/staking/bonding/relayChain.js +12 -2
- package/koni/api/staking/bonding/utils.js +3 -3
- package/koni/background/cron.d.ts +1 -5
- package/koni/background/cron.js +15 -39
- package/koni/background/handlers/Extension.d.ts +5 -0
- package/koni/background/handlers/Extension.js +186 -11
- package/koni/background/handlers/State.d.ts +15 -3
- package/koni/background/handlers/State.js +226 -50
- package/koni/background/subscription.d.ts +1 -4
- package/koni/background/subscription.js +11 -87
- package/package.json +23 -6
- package/packageInfo.js +1 -1
- package/services/chain-service/constants.d.ts +3 -0
- package/services/chain-service/constants.js +5 -2
- package/services/chain-service/handler/SubstrateApi.d.ts +1 -1
- package/services/chain-service/handler/SubstrateApi.js +2 -1
- package/services/chain-service/handler/SubstrateChainHandler.d.ts +1 -1
- package/services/chain-service/handler/SubstrateChainHandler.js +3 -1
- package/services/chain-service/handler/manta/MantaPrivateHandler.d.ts +30 -0
- package/services/chain-service/handler/manta/MantaPrivateHandler.js +140 -0
- package/services/chain-service/handler/types.d.ts +2 -0
- package/services/chain-service/index.d.ts +7 -3
- package/services/chain-service/index.js +56 -7
- package/services/chain-service/utils.d.ts +1 -0
- package/services/chain-service/utils.js +5 -1
- package/services/event-service/types.d.ts +3 -0
- package/services/event-service/types.js +3 -1
- package/services/storage-service/DatabaseService.d.ts +10 -1
- package/services/storage-service/DatabaseService.js +31 -1
- package/services/storage-service/databases/index.d.ts +2 -0
- package/services/storage-service/databases/index.js +3 -0
- package/services/storage-service/db-stores/MantaPay.d.ts +9 -0
- package/services/storage-service/db-stores/MantaPay.js +32 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +2 -1
- package/utils/lazy.d.ts +2 -0
- package/utils/lazy.js +43 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.MantaPrivateHandler = void 0;
|
|
7
|
+
var _mantaExtensionSdk = require("manta-extension-sdk");
|
|
8
|
+
var _rxjs = require("rxjs");
|
|
9
|
+
// Copyright 2019-2022 @subwallet/extension-base authors & contributors
|
|
10
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
11
|
+
|
|
12
|
+
class MantaPrivateHandler {
|
|
13
|
+
_privateWallet = undefined;
|
|
14
|
+
syncStateSubject = new _rxjs.Subject();
|
|
15
|
+
constructor(dbService) {
|
|
16
|
+
this.dbService = dbService;
|
|
17
|
+
this.syncState = {
|
|
18
|
+
isSyncing: false,
|
|
19
|
+
progress: 0
|
|
20
|
+
};
|
|
21
|
+
this.syncStateSubject.next(this.syncState);
|
|
22
|
+
}
|
|
23
|
+
setCurrentAddress(address) {
|
|
24
|
+
this.currentAddress = address;
|
|
25
|
+
}
|
|
26
|
+
getSyncState() {
|
|
27
|
+
return this.syncState;
|
|
28
|
+
}
|
|
29
|
+
get privateWallet() {
|
|
30
|
+
return this._privateWallet;
|
|
31
|
+
}
|
|
32
|
+
subscribeSyncState() {
|
|
33
|
+
return this.syncStateSubject;
|
|
34
|
+
}
|
|
35
|
+
async updateMantaPayConfig(address, chain, changes) {
|
|
36
|
+
await this.dbService.updateMantaPayData(`config_${chain}_${address}`, changes);
|
|
37
|
+
}
|
|
38
|
+
async saveMantaPayConfig(config) {
|
|
39
|
+
await this.dbService.setMantaPayData({
|
|
40
|
+
key: `config_${config.chain}_${config.address}`,
|
|
41
|
+
...config
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
async getMantaPayConfig(address, chain) {
|
|
45
|
+
return this.dbService.getMantaPayData(`config_${chain}_${address}`);
|
|
46
|
+
}
|
|
47
|
+
async getMantaPayFirstConfig(chain) {
|
|
48
|
+
return this.dbService.getMantaPayFirstConfig(chain);
|
|
49
|
+
}
|
|
50
|
+
async deleteMantaPayConfig(address, chain) {
|
|
51
|
+
return this.dbService.deleteMantaPayConfig(`config_${chain}_${address}`);
|
|
52
|
+
}
|
|
53
|
+
async saveMantaAuthContext(context) {
|
|
54
|
+
await this.dbService.setMantaPayData({
|
|
55
|
+
key: `authContext_${context.chain}_${context.address}`,
|
|
56
|
+
...context
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async getMantaAuthContext(address, chain) {
|
|
60
|
+
return this.dbService.getMantaPayData(`authContext_${chain}_${address}`);
|
|
61
|
+
}
|
|
62
|
+
async deleteMantaAuthContext(address, chain) {
|
|
63
|
+
return this.dbService.deleteMantaPayConfig(`authContext_${chain}_${address}`);
|
|
64
|
+
}
|
|
65
|
+
async saveLedgerState(palletName, network, data) {
|
|
66
|
+
try {
|
|
67
|
+
const suffix = this.currentAddress ? `_${this.currentAddress}` : '';
|
|
68
|
+
await this.dbService.setMantaPayData({
|
|
69
|
+
key: `storage_state_${palletName}_${network}${suffix}`,
|
|
70
|
+
...data
|
|
71
|
+
});
|
|
72
|
+
} catch (e) {
|
|
73
|
+
console.error('manta-pay', e);
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
async getLedgerState(palletName, network) {
|
|
79
|
+
let result;
|
|
80
|
+
try {
|
|
81
|
+
const suffix = this.currentAddress ? `_${this.currentAddress}` : '';
|
|
82
|
+
|
|
83
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
84
|
+
result = await this.dbService.getMantaPayData(`storage_state_${palletName}_${network}${suffix}`);
|
|
85
|
+
} catch (e) {
|
|
86
|
+
console.error(e);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
90
|
+
return result || null;
|
|
91
|
+
}
|
|
92
|
+
async initMantaPay(providerUrl, network) {
|
|
93
|
+
const networkParam = network.charAt(0).toUpperCase() + network.slice(1); // Manta || Calamari || Dolphin
|
|
94
|
+
|
|
95
|
+
const baseWallet = await _mantaExtensionSdk.BaseWallet.init({
|
|
96
|
+
apiEndpoint: providerUrl,
|
|
97
|
+
loggingEnabled: false,
|
|
98
|
+
provingFilePath: './manta-pay/proving',
|
|
99
|
+
parametersFilePath: './manta-pay/parameters',
|
|
100
|
+
saveStorageStateToLocal: this.saveLedgerState.bind(this),
|
|
101
|
+
getStorageStateFromLocal: this.getLedgerState.bind(this)
|
|
102
|
+
});
|
|
103
|
+
this._privateWallet = _mantaExtensionSdk.MantaPayWallet.init(networkParam, baseWallet);
|
|
104
|
+
return this._privateWallet.api;
|
|
105
|
+
}
|
|
106
|
+
async getCurrentLedgerState() {
|
|
107
|
+
var _this$_privateWallet;
|
|
108
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
109
|
+
const ledgerState = await this.getLedgerState('mantaPay', 'Calamari');
|
|
110
|
+
if (!ledgerState) {
|
|
111
|
+
return 0;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
|
115
|
+
return await ((_this$_privateWallet = this._privateWallet) === null || _this$_privateWallet === void 0 ? void 0 : _this$_privateWallet.getLedgerCurrentCount(ledgerState.checkpoint));
|
|
116
|
+
}
|
|
117
|
+
setSyncState(data) {
|
|
118
|
+
this.syncState = data;
|
|
119
|
+
this.syncStateSubject.next(this.syncState);
|
|
120
|
+
}
|
|
121
|
+
async subscribeSyncProgress() {
|
|
122
|
+
var _this$_privateWallet2;
|
|
123
|
+
const ledgerTotalCount = await ((_this$_privateWallet2 = this._privateWallet) === null || _this$_privateWallet2 === void 0 ? void 0 : _this$_privateWallet2.getLedgerTotalCount());
|
|
124
|
+
const interval = setInterval(() => {
|
|
125
|
+
this.getCurrentLedgerState().then(currentCount => {
|
|
126
|
+
const progress = Math.floor(currentCount / ledgerTotalCount * 100);
|
|
127
|
+
if (progress === 100) {
|
|
128
|
+
this.syncState = {
|
|
129
|
+
isSyncing: false,
|
|
130
|
+
progress
|
|
131
|
+
};
|
|
132
|
+
clearInterval(interval);
|
|
133
|
+
} else {
|
|
134
|
+
this.syncState = {
|
|
135
|
+
isSyncing: true,
|
|
136
|
+
progress
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
this.syncStateSubject.next(this.syncState);
|
|
140
|
+
}).catch(console.error);
|
|
141
|
+
}, 1000);
|
|
142
|
+
return () => {
|
|
143
|
+
interval && clearInterval(interval);
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.MantaPrivateHandler = MantaPrivateHandler;
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"anonymous": false,
|
|
4
|
+
"inputs": [
|
|
5
|
+
{
|
|
6
|
+
"indexed": true,
|
|
7
|
+
"internalType": "address",
|
|
8
|
+
"name": "owner",
|
|
9
|
+
"type": "address"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"indexed": true,
|
|
13
|
+
"internalType": "address",
|
|
14
|
+
"name": "spender",
|
|
15
|
+
"type": "address"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"indexed": false,
|
|
19
|
+
"internalType": "uint256",
|
|
20
|
+
"name": "value",
|
|
21
|
+
"type": "uint256"
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"name": "Approval",
|
|
25
|
+
"type": "event"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"anonymous": false,
|
|
29
|
+
"inputs": [
|
|
30
|
+
{
|
|
31
|
+
"indexed": true,
|
|
32
|
+
"internalType": "address",
|
|
33
|
+
"name": "from",
|
|
34
|
+
"type": "address"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"indexed": true,
|
|
38
|
+
"internalType": "address",
|
|
39
|
+
"name": "to",
|
|
40
|
+
"type": "address"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"indexed": false,
|
|
44
|
+
"internalType": "uint256",
|
|
45
|
+
"name": "value",
|
|
46
|
+
"type": "uint256"
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
"name": "Transfer",
|
|
50
|
+
"type": "event"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"inputs": [
|
|
54
|
+
{
|
|
55
|
+
"internalType": "address",
|
|
56
|
+
"name": "owner",
|
|
57
|
+
"type": "address"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"internalType": "address",
|
|
61
|
+
"name": "spender",
|
|
62
|
+
"type": "address"
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
"name": "allowance",
|
|
66
|
+
"outputs": [
|
|
67
|
+
{
|
|
68
|
+
"internalType": "uint256",
|
|
69
|
+
"name": "",
|
|
70
|
+
"type": "uint256"
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
"stateMutability": "view",
|
|
74
|
+
"type": "function"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"inputs": [
|
|
78
|
+
{
|
|
79
|
+
"internalType": "address",
|
|
80
|
+
"name": "spender",
|
|
81
|
+
"type": "address"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
"internalType": "uint256",
|
|
85
|
+
"name": "value",
|
|
86
|
+
"type": "uint256"
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
"name": "approve",
|
|
90
|
+
"outputs": [
|
|
91
|
+
{
|
|
92
|
+
"internalType": "bool",
|
|
93
|
+
"name": "",
|
|
94
|
+
"type": "bool"
|
|
95
|
+
}
|
|
96
|
+
],
|
|
97
|
+
"stateMutability": "nonpayable",
|
|
98
|
+
"type": "function"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"inputs": [
|
|
102
|
+
{
|
|
103
|
+
"internalType": "address",
|
|
104
|
+
"name": "who",
|
|
105
|
+
"type": "address"
|
|
106
|
+
}
|
|
107
|
+
],
|
|
108
|
+
"name": "balanceOf",
|
|
109
|
+
"outputs": [
|
|
110
|
+
{
|
|
111
|
+
"internalType": "uint256",
|
|
112
|
+
"name": "",
|
|
113
|
+
"type": "uint256"
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
"stateMutability": "view",
|
|
117
|
+
"type": "function"
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
"inputs": [],
|
|
121
|
+
"name": "decimals",
|
|
122
|
+
"outputs": [
|
|
123
|
+
{
|
|
124
|
+
"internalType": "uint8",
|
|
125
|
+
"name": "",
|
|
126
|
+
"type": "uint8"
|
|
127
|
+
}
|
|
128
|
+
],
|
|
129
|
+
"stateMutability": "view",
|
|
130
|
+
"type": "function"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"inputs": [],
|
|
134
|
+
"name": "name",
|
|
135
|
+
"outputs": [
|
|
136
|
+
{
|
|
137
|
+
"internalType": "string",
|
|
138
|
+
"name": "",
|
|
139
|
+
"type": "string"
|
|
140
|
+
}
|
|
141
|
+
],
|
|
142
|
+
"stateMutability": "view",
|
|
143
|
+
"type": "function"
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
"inputs": [],
|
|
147
|
+
"name": "symbol",
|
|
148
|
+
"outputs": [
|
|
149
|
+
{
|
|
150
|
+
"internalType": "string",
|
|
151
|
+
"name": "",
|
|
152
|
+
"type": "string"
|
|
153
|
+
}
|
|
154
|
+
],
|
|
155
|
+
"stateMutability": "view",
|
|
156
|
+
"type": "function"
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
"inputs": [],
|
|
160
|
+
"name": "totalSupply",
|
|
161
|
+
"outputs": [
|
|
162
|
+
{
|
|
163
|
+
"internalType": "uint256",
|
|
164
|
+
"name": "",
|
|
165
|
+
"type": "uint256"
|
|
166
|
+
}
|
|
167
|
+
],
|
|
168
|
+
"stateMutability": "view",
|
|
169
|
+
"type": "function"
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
"inputs": [
|
|
173
|
+
{
|
|
174
|
+
"internalType": "address",
|
|
175
|
+
"name": "to",
|
|
176
|
+
"type": "address"
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
"internalType": "uint256",
|
|
180
|
+
"name": "value",
|
|
181
|
+
"type": "uint256"
|
|
182
|
+
}
|
|
183
|
+
],
|
|
184
|
+
"name": "transfer",
|
|
185
|
+
"outputs": [
|
|
186
|
+
{
|
|
187
|
+
"internalType": "bool",
|
|
188
|
+
"name": "",
|
|
189
|
+
"type": "bool"
|
|
190
|
+
}
|
|
191
|
+
],
|
|
192
|
+
"stateMutability": "nonpayable",
|
|
193
|
+
"type": "function"
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
"inputs": [
|
|
197
|
+
{
|
|
198
|
+
"internalType": "address",
|
|
199
|
+
"name": "from",
|
|
200
|
+
"type": "address"
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
"internalType": "address",
|
|
204
|
+
"name": "to",
|
|
205
|
+
"type": "address"
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
"internalType": "uint256",
|
|
209
|
+
"name": "value",
|
|
210
|
+
"type": "uint256"
|
|
211
|
+
}
|
|
212
|
+
],
|
|
213
|
+
"name": "transferFrom",
|
|
214
|
+
"outputs": [
|
|
215
|
+
{
|
|
216
|
+
"internalType": "bool",
|
|
217
|
+
"name": "",
|
|
218
|
+
"type": "bool"
|
|
219
|
+
}
|
|
220
|
+
],
|
|
221
|
+
"stateMutability": "nonpayable",
|
|
222
|
+
"type": "function"
|
|
223
|
+
}
|
|
224
|
+
]
|