@pioneer-platform/pioneer-balance 8.3.27 → 8.3.29
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/lib/index.d.ts +13 -0
- package/lib/index.js +112 -9
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
export declare const UTXO_SUPPORT: string[];
|
2
|
+
export declare const TENDERMINT_SUPPORT: string[];
|
3
|
+
export declare const CAIP_TO_COIN_MAP: {
|
4
|
+
[key: string]: string;
|
5
|
+
};
|
6
|
+
export declare const OTHER_SUPPORT: string[];
|
7
|
+
export declare const SUPPORTED_CAIPS: {
|
8
|
+
UTXO: string[];
|
9
|
+
TENDERMINT: string[];
|
10
|
+
EIP155: string[];
|
11
|
+
OTHER: string[];
|
12
|
+
};
|
1
13
|
export declare class Balance {
|
2
14
|
private blockchains;
|
3
15
|
private nodes;
|
@@ -6,5 +18,6 @@ export declare class Balance {
|
|
6
18
|
constructor(config: any);
|
7
19
|
init(): Promise<boolean>;
|
8
20
|
getNodes(networkId: string): Promise<any>;
|
21
|
+
classifyCaip(caip: string): Promise<string>;
|
9
22
|
getBalance(asset: any, pubkey: any): Promise<any>;
|
10
23
|
}
|
package/lib/index.js
CHANGED
@@ -56,10 +56,39 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
56
56
|
}
|
57
57
|
};
|
58
58
|
Object.defineProperty(exports, "__esModule", { value: true });
|
59
|
-
exports.Balance = void 0;
|
59
|
+
exports.Balance = exports.SUPPORTED_CAIPS = exports.OTHER_SUPPORT = exports.CAIP_TO_COIN_MAP = exports.TENDERMINT_SUPPORT = exports.UTXO_SUPPORT = void 0;
|
60
60
|
var TAG = " | pioneer balance | ";
|
61
61
|
var caipToNetworkId = require('@pioneer-platform/pioneer-caip').caipToNetworkId;
|
62
62
|
var Network = require("@pioneer-platform/pioneer-network");
|
63
|
+
exports.UTXO_SUPPORT = [
|
64
|
+
'bip122:000000000019d6689c085ae165831e93/slip44:0', // BTC
|
65
|
+
'bip122:000000000000000000651ef99cb9fcbe/slip44:145', // BCH
|
66
|
+
'bip122:000007d91d1254d60e2dd1ae58038307/slip44:5', // DASH
|
67
|
+
'bip122:00000000001a91e3dace36e2be3bf030/slip44:3', // DOGE
|
68
|
+
'bip122:12a765e31ffd4059bada1e25190f6e98/slip44:2', // LTC
|
69
|
+
];
|
70
|
+
exports.TENDERMINT_SUPPORT = [
|
71
|
+
'cosmos:mayachain-mainnet-v1/slip44:931',
|
72
|
+
'cosmos:osmosis-1/slip44:118',
|
73
|
+
'cosmos:cosmoshub-4/slip44:118',
|
74
|
+
'cosmos:kaiyo-1/slip44:118',
|
75
|
+
'cosmos:thorchain-mainnet-v1/slip44:931', // supportedCaips.ts
|
76
|
+
];
|
77
|
+
// Mapping of CAIP identifiers to KeepKey coin names for UTXO chains
|
78
|
+
exports.CAIP_TO_COIN_MAP = {
|
79
|
+
'bip122:000000000019d6689c085ae165831e93/slip44:0': 'Bitcoin',
|
80
|
+
'bip122:000000000000000000651ef99cb9fcbe/slip44:145': 'BitcoinCash',
|
81
|
+
'bip122:000007d91d1254d60e2dd1ae58038307/slip44:5': 'Dash',
|
82
|
+
'bip122:00000000001a91e3dace36e2be3bf030/slip44:3': 'Dogecoin',
|
83
|
+
'bip122:12a765e31ffd4059bada1e25190f6e98/slip44:2': 'Litecoin',
|
84
|
+
};
|
85
|
+
exports.OTHER_SUPPORT = ['ripple:4109c6f2045fc7eff4cde8f9905d19c2/slip44:144'];
|
86
|
+
exports.SUPPORTED_CAIPS = {
|
87
|
+
UTXO: exports.UTXO_SUPPORT,
|
88
|
+
TENDERMINT: exports.TENDERMINT_SUPPORT,
|
89
|
+
EIP155: ['eip155:*'],
|
90
|
+
OTHER: exports.OTHER_SUPPORT,
|
91
|
+
};
|
63
92
|
var Balance = /** @class */ (function () {
|
64
93
|
function Balance(config) {
|
65
94
|
this.blockchains = config.wss || [];
|
@@ -139,11 +168,26 @@ var Balance = /** @class */ (function () {
|
|
139
168
|
});
|
140
169
|
});
|
141
170
|
};
|
142
|
-
Balance.prototype.
|
171
|
+
Balance.prototype.classifyCaip = function (caip) {
|
143
172
|
return __awaiter(this, void 0, void 0, function () {
|
144
|
-
var tag, networkId, balance;
|
145
173
|
return __generator(this, function (_a) {
|
146
|
-
|
174
|
+
if (exports.SUPPORTED_CAIPS.UTXO.includes(caip))
|
175
|
+
return [2 /*return*/, 'UTXO'];
|
176
|
+
if (exports.SUPPORTED_CAIPS.TENDERMINT.includes(caip))
|
177
|
+
return [2 /*return*/, 'TENDERMINT'];
|
178
|
+
if (caip.startsWith('eip155'))
|
179
|
+
return [2 /*return*/, 'EIP155'];
|
180
|
+
if (exports.SUPPORTED_CAIPS.OTHER.includes(caip))
|
181
|
+
return [2 /*return*/, 'OTHER'];
|
182
|
+
throw new Error("Unsupported CAIP: ".concat(caip));
|
183
|
+
});
|
184
|
+
});
|
185
|
+
};
|
186
|
+
Balance.prototype.getBalance = function (asset, pubkey) {
|
187
|
+
return __awaiter(this, void 0, void 0, function () {
|
188
|
+
var tag, networkId, type, _a, networkIdToSymbol, coin, balance, balance;
|
189
|
+
return __generator(this, function (_b) {
|
190
|
+
switch (_b.label) {
|
147
191
|
case 0:
|
148
192
|
tag = TAG + " | getBalance | ";
|
149
193
|
if (!asset.caip)
|
@@ -152,14 +196,73 @@ var Balance = /** @class */ (function () {
|
|
152
196
|
throw new Error("pubkey required!");
|
153
197
|
networkId = caipToNetworkId(asset.caip);
|
154
198
|
console.info(tag, "networkId: ", networkId);
|
155
|
-
|
156
|
-
return [4 /*yield*/, this.networks.networks.ethereum.getBalanceAddressByNetwork(networkId, pubkey.pubkey)];
|
199
|
+
return [4 /*yield*/, this.classifyCaip(asset.caip)];
|
157
200
|
case 1:
|
158
|
-
|
201
|
+
type = _b.sent();
|
202
|
+
_a = type;
|
203
|
+
switch (_a) {
|
204
|
+
case 'UTXO': return [3 /*break*/, 2];
|
205
|
+
case 'TENDERMINT': return [3 /*break*/, 4];
|
206
|
+
case 'EIP155': return [3 /*break*/, 5];
|
207
|
+
case 'OTHER': return [3 /*break*/, 7];
|
208
|
+
}
|
209
|
+
return [3 /*break*/, 8];
|
210
|
+
case 2:
|
211
|
+
networkIdToSymbol = {
|
212
|
+
'bip122:000000000019d6689c085ae165831e93': 'BTC', // Bitcoin
|
213
|
+
'bip122:000000000000000000651ef99cb9fcbe': 'BCH', // Bitcoin Cash
|
214
|
+
'bip122:000007d91d1254d60e2dd1ae58038307': 'DASH', // Dash
|
215
|
+
'bip122:00000000001a91e3dace36e2be3bf030': 'DOGE', // Dogecoin
|
216
|
+
'bip122:12a765e31ffd4059bada1e25190f6e98': 'LTC' // Litecoin
|
217
|
+
};
|
218
|
+
coin = networkIdToSymbol[networkId];
|
219
|
+
console.log(tag, 'coin: ', coin);
|
220
|
+
return [4 /*yield*/, this.networks.networks.utxo.getBalanceByXpub(coin, pubkey.pubkey)];
|
221
|
+
case 3:
|
222
|
+
balance = _b.sent();
|
223
|
+
console.log(tag, "balance: ", balance);
|
224
|
+
asset.balance = balance;
|
225
|
+
return [3 /*break*/, 9];
|
226
|
+
case 4:
|
227
|
+
{
|
228
|
+
console.log(tag, 'Tendermint transaction');
|
229
|
+
if (asset.caip === 'cosmos:mayachain-mainnet-v1/slip44:931') {
|
230
|
+
asset.balance = this.networks.networks.mayachain.getBalance(networkId);
|
231
|
+
}
|
232
|
+
if (asset.caip === 'cosmos:osmosis-1/slip44:118') {
|
233
|
+
asset.balance = this.networks.networks.cosmos.getBalance(networkId);
|
234
|
+
}
|
235
|
+
if (asset.caip === 'cosmos:cosmoshub-4/slip44:118') {
|
236
|
+
asset.balance = this.networks.networks.thorchain.getBalance(networkId);
|
237
|
+
}
|
238
|
+
if (asset.caip === 'cosmos:thorchain-mainnet-v1/slip44:931') {
|
239
|
+
asset.balance = this.networks.networks.thorchain.getBalance(networkId);
|
240
|
+
}
|
241
|
+
//TODO tokens/ibc and non-gas assets
|
242
|
+
return [3 /*break*/, 9];
|
243
|
+
}
|
244
|
+
_b.label = 5;
|
245
|
+
case 5: return [4 /*yield*/, this.networks.networks.ethereum.getBalanceAddressByNetwork(networkId, pubkey.pubkey)];
|
246
|
+
case 6:
|
247
|
+
balance = _b.sent();
|
159
248
|
console.log(tag, "balance: ", balance);
|
160
249
|
asset.balance = balance;
|
161
|
-
|
162
|
-
case
|
250
|
+
return [3 /*break*/, 9];
|
251
|
+
case 7:
|
252
|
+
{
|
253
|
+
if (asset.caip === 'ripple:4109c6f2045fc7eff4cde8f9905d19c2/slip44:144') {
|
254
|
+
asset.balance = this.networks.networks.ripple.getBalance(pubkey.pubkey);
|
255
|
+
}
|
256
|
+
console.log(tag, 'Other transaction');
|
257
|
+
return [3 /*break*/, 9];
|
258
|
+
}
|
259
|
+
_b.label = 8;
|
260
|
+
case 8:
|
261
|
+
{
|
262
|
+
throw new Error("Unsupported CAIP: ".concat(asset.caip));
|
263
|
+
}
|
264
|
+
_b.label = 9;
|
265
|
+
case 9: return [2 /*return*/, asset];
|
163
266
|
}
|
164
267
|
});
|
165
268
|
});
|