@pioneer-platform/cosmos-network 8.3.9 → 8.3.11
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 +1 -2
- package/lib/index.js +167 -14
- package/package.json +8 -8
- package/yarn-error.log +0 -22803
package/lib/index.d.ts
CHANGED
|
@@ -7,8 +7,6 @@ declare let wait: any;
|
|
|
7
7
|
declare let sleep: any;
|
|
8
8
|
declare const txEncoder: any;
|
|
9
9
|
declare const ASSET = "ATOM";
|
|
10
|
-
declare let nodes: any;
|
|
11
|
-
declare let publicNode: any;
|
|
12
10
|
declare let ATOM_BASE: number;
|
|
13
11
|
declare let URL_GAIAD: string;
|
|
14
12
|
declare let RUNTIME: any;
|
|
@@ -54,3 +52,4 @@ declare let normalize_tx: (tx: any, type: any) => any;
|
|
|
54
52
|
declare let get_txs_by_address: (address: string) => Promise<any>;
|
|
55
53
|
declare let getTransaction: (txid: string) => Promise<any>;
|
|
56
54
|
declare let getStakingInfo: (address: string, valAddress: string) => Promise<any>;
|
|
55
|
+
declare let get_staking_positions: (address: string) => Promise<any>;
|
package/lib/index.js
CHANGED
|
@@ -54,8 +54,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
54
54
|
});
|
|
55
55
|
};
|
|
56
56
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
57
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
58
|
-
return g =
|
|
57
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
58
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
59
59
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
60
60
|
function step(op) {
|
|
61
61
|
if (f) throw new TypeError("Generator is already executing.");
|
|
@@ -117,8 +117,8 @@ var sleep = wait.sleep;
|
|
|
117
117
|
//encoder
|
|
118
118
|
var txEncoder = require('@pioneer-platform/cosmos-tx-encoder');
|
|
119
119
|
var ASSET = "ATOM";
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
// let nodes = require('@pioneer-platform/nodes')
|
|
121
|
+
// let publicNode = nodes.getNode('cosmos','gaiad')
|
|
122
122
|
var ATOM_BASE = 1000000;
|
|
123
123
|
var URL_GAIAD = 'https://atom.nownodes.io';
|
|
124
124
|
// let URL_GAIAD = process.env['URL_GAIAD'] || 'https://atom.nownodes.io/cosmos'
|
|
@@ -216,6 +216,9 @@ module.exports = {
|
|
|
216
216
|
getValidatorsByHeight: function (height) {
|
|
217
217
|
return get_validators_at_height(height);
|
|
218
218
|
},
|
|
219
|
+
getStakingPositions: function (address) {
|
|
220
|
+
return get_staking_positions(address);
|
|
221
|
+
},
|
|
219
222
|
// txs: function(addr) {
|
|
220
223
|
// return Promise.all([
|
|
221
224
|
// req(`GET`, `/txs?sender=${addr}`)(),
|
|
@@ -345,9 +348,9 @@ var get_voucher_info = function (voucher) {
|
|
|
345
348
|
});
|
|
346
349
|
};
|
|
347
350
|
var get_balances = function (address) {
|
|
348
|
-
var _a;
|
|
349
351
|
return __awaiter(this, void 0, void 0, function () {
|
|
350
352
|
var tag, output, url, accountInfo, i, entry, balance, voucher, voucherInfo, balance, e_6, e_7;
|
|
353
|
+
var _a;
|
|
351
354
|
return __generator(this, function (_b) {
|
|
352
355
|
switch (_b.label) {
|
|
353
356
|
case 0:
|
|
@@ -510,7 +513,7 @@ var get_rewards = function (address) {
|
|
|
510
513
|
_a.label = 1;
|
|
511
514
|
case 1:
|
|
512
515
|
_a.trys.push([1, 3, , 4]);
|
|
513
|
-
return [4 /*yield*/, axios({ method: 'GET', url: URL_GAIAD + '/distribution/delegators/' + address + '/rewards' })];
|
|
516
|
+
return [4 /*yield*/, axios({ method: 'GET', url: URL_GAIAD + '/cosmos/distribution/v1beta1/delegators/' + address + '/rewards' })];
|
|
514
517
|
case 2:
|
|
515
518
|
resp = _a.sent();
|
|
516
519
|
log.debug(tag, "resp: ", resp.data);
|
|
@@ -535,11 +538,11 @@ var get_delegations_by_address = function (address) {
|
|
|
535
538
|
_a.label = 1;
|
|
536
539
|
case 1:
|
|
537
540
|
_a.trys.push([1, 3, , 4]);
|
|
538
|
-
return [4 /*yield*/, axios({ method: 'GET', url: URL_GAIAD + '/staking/
|
|
541
|
+
return [4 /*yield*/, axios({ method: 'GET', url: URL_GAIAD + '/cosmos/staking/v1beta1/delegations/' + address })];
|
|
539
542
|
case 2:
|
|
540
543
|
resp = _a.sent();
|
|
541
544
|
log.debug(tag, "resp: ", resp.data);
|
|
542
|
-
output_6 = resp.data.
|
|
545
|
+
output_6 = resp.data.delegation_responses;
|
|
543
546
|
return [2 /*return*/, output_6];
|
|
544
547
|
case 3:
|
|
545
548
|
e_10 = _a.sent();
|
|
@@ -1506,20 +1509,21 @@ var getTransaction = function (txid) {
|
|
|
1506
1509
|
};
|
|
1507
1510
|
var getStakingInfo = function (address, valAddress) {
|
|
1508
1511
|
return __awaiter(this, void 0, void 0, function () {
|
|
1509
|
-
var tag, output,
|
|
1512
|
+
var tag, output, resp, output_13, e_34;
|
|
1510
1513
|
return __generator(this, function (_a) {
|
|
1511
1514
|
switch (_a.label) {
|
|
1512
1515
|
case 0:
|
|
1513
|
-
tag = TAG + " |
|
|
1516
|
+
tag = TAG + " | getStakingInfo | ";
|
|
1514
1517
|
output = {};
|
|
1515
1518
|
_a.label = 1;
|
|
1516
1519
|
case 1:
|
|
1517
1520
|
_a.trys.push([1, 3, , 4]);
|
|
1518
|
-
return [4 /*yield*/, axios({ method: 'GET', url: URL_GAIAD + '/
|
|
1521
|
+
return [4 /*yield*/, axios({ method: 'GET', url: URL_GAIAD + '/staking/delegators/' + address + '/delegations/' + valAddress })];
|
|
1519
1522
|
case 2:
|
|
1520
|
-
|
|
1521
|
-
log.debug(tag, "
|
|
1522
|
-
|
|
1523
|
+
resp = _a.sent();
|
|
1524
|
+
log.debug(tag, "resp: ", resp.data);
|
|
1525
|
+
output_13 = resp.data;
|
|
1526
|
+
return [2 /*return*/, output_13];
|
|
1523
1527
|
case 3:
|
|
1524
1528
|
e_34 = _a.sent();
|
|
1525
1529
|
throw e_34;
|
|
@@ -1528,3 +1532,152 @@ var getStakingInfo = function (address, valAddress) {
|
|
|
1528
1532
|
});
|
|
1529
1533
|
});
|
|
1530
1534
|
};
|
|
1535
|
+
var get_staking_positions = function (address) {
|
|
1536
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1537
|
+
var tag, positions, delegations, i, delegation, position, e_35, rewards, i, reward, rewardAmount, j, position, e_36, unbondings, i, unbonding, j, entry, position, e_37, e_38;
|
|
1538
|
+
return __generator(this, function (_a) {
|
|
1539
|
+
switch (_a.label) {
|
|
1540
|
+
case 0:
|
|
1541
|
+
tag = TAG + " | get_staking_positions | ";
|
|
1542
|
+
_a.label = 1;
|
|
1543
|
+
case 1:
|
|
1544
|
+
_a.trys.push([1, 12, , 13]);
|
|
1545
|
+
positions = [];
|
|
1546
|
+
_a.label = 2;
|
|
1547
|
+
case 2:
|
|
1548
|
+
_a.trys.push([2, 4, , 5]);
|
|
1549
|
+
return [4 /*yield*/, get_delegations_by_address(address)];
|
|
1550
|
+
case 3:
|
|
1551
|
+
delegations = _a.sent();
|
|
1552
|
+
log.debug(tag, "delegations: ", delegations);
|
|
1553
|
+
if (delegations && delegations.length > 0) {
|
|
1554
|
+
for (i = 0; i < delegations.length; i++) {
|
|
1555
|
+
delegation = delegations[i];
|
|
1556
|
+
position = {
|
|
1557
|
+
type: 'delegation',
|
|
1558
|
+
chart: 'staking',
|
|
1559
|
+
context: 'cosmos:staking',
|
|
1560
|
+
contextType: 'staking',
|
|
1561
|
+
caip: 'cosmos:cosmoshub-4/slip44:118',
|
|
1562
|
+
networkId: 'cosmos:cosmoshub-4',
|
|
1563
|
+
pubkey: address,
|
|
1564
|
+
validatorAddress: delegation.delegation.validator_address,
|
|
1565
|
+
shares: delegation.delegation.shares,
|
|
1566
|
+
balance: parseFloat(delegation.balance.amount) / ATOM_BASE,
|
|
1567
|
+
denom: delegation.balance.denom,
|
|
1568
|
+
ticker: 'ATOM',
|
|
1569
|
+
symbol: 'ATOM',
|
|
1570
|
+
name: 'Cosmos Delegation',
|
|
1571
|
+
icon: 'https://pioneers.dev/coins/cosmos.png',
|
|
1572
|
+
status: 'active',
|
|
1573
|
+
updated: new Date().getTime(),
|
|
1574
|
+
valueUsd: 0 // Will be calculated by chart processor
|
|
1575
|
+
};
|
|
1576
|
+
positions.push(position);
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
return [3 /*break*/, 5];
|
|
1580
|
+
case 4:
|
|
1581
|
+
e_35 = _a.sent();
|
|
1582
|
+
log.error(tag, "Error getting delegations:", e_35);
|
|
1583
|
+
return [3 /*break*/, 5];
|
|
1584
|
+
case 5:
|
|
1585
|
+
_a.trys.push([5, 7, , 8]);
|
|
1586
|
+
return [4 /*yield*/, get_rewards(address)];
|
|
1587
|
+
case 6:
|
|
1588
|
+
rewards = _a.sent();
|
|
1589
|
+
log.debug(tag, "rewards: ", rewards);
|
|
1590
|
+
if (rewards && rewards.rewards) {
|
|
1591
|
+
for (i = 0; i < rewards.rewards.length; i++) {
|
|
1592
|
+
reward = rewards.rewards[i];
|
|
1593
|
+
if (reward.reward && reward.reward.length > 0) {
|
|
1594
|
+
rewardAmount = 0;
|
|
1595
|
+
for (j = 0; j < reward.reward.length; j++) {
|
|
1596
|
+
if (reward.reward[j].denom === 'uatom') {
|
|
1597
|
+
rewardAmount += parseFloat(reward.reward[j].amount) / ATOM_BASE;
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
if (rewardAmount > 0) {
|
|
1601
|
+
position = {
|
|
1602
|
+
type: 'reward',
|
|
1603
|
+
chart: 'staking',
|
|
1604
|
+
context: 'cosmos:rewards',
|
|
1605
|
+
contextType: 'rewards',
|
|
1606
|
+
caip: 'cosmos:cosmoshub-4/slip44:118',
|
|
1607
|
+
networkId: 'cosmos:cosmoshub-4',
|
|
1608
|
+
pubkey: address,
|
|
1609
|
+
validatorAddress: reward.validator_address,
|
|
1610
|
+
balance: rewardAmount,
|
|
1611
|
+
denom: 'uatom',
|
|
1612
|
+
ticker: 'ATOM',
|
|
1613
|
+
symbol: 'ATOM',
|
|
1614
|
+
name: 'Cosmos Rewards',
|
|
1615
|
+
icon: 'https://pioneers.dev/coins/cosmos.png',
|
|
1616
|
+
status: 'claimable',
|
|
1617
|
+
updated: new Date().getTime(),
|
|
1618
|
+
valueUsd: 0 // Will be calculated by chart processor
|
|
1619
|
+
};
|
|
1620
|
+
positions.push(position);
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
return [3 /*break*/, 8];
|
|
1626
|
+
case 7:
|
|
1627
|
+
e_36 = _a.sent();
|
|
1628
|
+
log.error(tag, "Error getting rewards:", e_36);
|
|
1629
|
+
return [3 /*break*/, 8];
|
|
1630
|
+
case 8:
|
|
1631
|
+
_a.trys.push([8, 10, , 11]);
|
|
1632
|
+
return [4 /*yield*/, axios({ method: 'GET', url: URL_GAIAD + '/cosmos/staking/v1beta1/delegators/' + address + '/unbonding_delegations' })];
|
|
1633
|
+
case 9:
|
|
1634
|
+
unbondings = _a.sent();
|
|
1635
|
+
log.debug(tag, "unbondings: ", unbondings.data);
|
|
1636
|
+
if (unbondings.data && unbondings.data.unbonding_responses) {
|
|
1637
|
+
for (i = 0; i < unbondings.data.unbonding_responses.length; i++) {
|
|
1638
|
+
unbonding = unbondings.data.unbonding_responses[i];
|
|
1639
|
+
if (unbonding.entries && unbonding.entries.length > 0) {
|
|
1640
|
+
for (j = 0; j < unbonding.entries.length; j++) {
|
|
1641
|
+
entry = unbonding.entries[j];
|
|
1642
|
+
position = {
|
|
1643
|
+
type: 'unbonding',
|
|
1644
|
+
chart: 'staking',
|
|
1645
|
+
context: 'cosmos:unbonding',
|
|
1646
|
+
contextType: 'unbonding',
|
|
1647
|
+
caip: 'cosmos:cosmoshub-4/slip44:118',
|
|
1648
|
+
networkId: 'cosmos:cosmoshub-4',
|
|
1649
|
+
pubkey: address,
|
|
1650
|
+
validatorAddress: unbonding.validator_address,
|
|
1651
|
+
balance: parseFloat(entry.balance) / ATOM_BASE,
|
|
1652
|
+
denom: 'uatom',
|
|
1653
|
+
ticker: 'ATOM',
|
|
1654
|
+
symbol: 'ATOM',
|
|
1655
|
+
name: 'Cosmos Unbonding',
|
|
1656
|
+
icon: 'https://pioneers.dev/coins/cosmos.png',
|
|
1657
|
+
status: 'unbonding',
|
|
1658
|
+
completionTime: entry.completion_time,
|
|
1659
|
+
updated: new Date().getTime(),
|
|
1660
|
+
valueUsd: 0 // Will be calculated by chart processor
|
|
1661
|
+
};
|
|
1662
|
+
positions.push(position);
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
return [3 /*break*/, 11];
|
|
1668
|
+
case 10:
|
|
1669
|
+
e_37 = _a.sent();
|
|
1670
|
+
log.error(tag, "Error getting unbondings:", e_37);
|
|
1671
|
+
return [3 /*break*/, 11];
|
|
1672
|
+
case 11:
|
|
1673
|
+
log.debug(tag, "Total staking positions found:", positions.length);
|
|
1674
|
+
return [2 /*return*/, positions];
|
|
1675
|
+
case 12:
|
|
1676
|
+
e_38 = _a.sent();
|
|
1677
|
+
log.error(tag, "Error in get_staking_positions:", e_38);
|
|
1678
|
+
throw e_38;
|
|
1679
|
+
case 13: return [2 /*return*/];
|
|
1680
|
+
}
|
|
1681
|
+
});
|
|
1682
|
+
});
|
|
1683
|
+
};
|
package/package.json
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pioneer-platform/cosmos-network",
|
|
3
|
-
"version": "8.3.
|
|
3
|
+
"version": "8.3.11",
|
|
4
4
|
"scripts": {
|
|
5
|
-
"create": "
|
|
5
|
+
"create": "pnpm run build && pnpm run test",
|
|
6
6
|
"build": "tsc -p .",
|
|
7
|
-
"test": "
|
|
8
|
-
"prepublish": "rm -R lib &&
|
|
9
|
-
"refresh": "rm -rf ./node_modules ./package-lock.json &&
|
|
7
|
+
"test": "pnpm run build && node __tests__/test-module.js",
|
|
8
|
+
"prepublish": "rm -R lib && pnpm run build",
|
|
9
|
+
"refresh": "rm -rf ./node_modules ./package-lock.json && pnpm install"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@pioneer-platform/cosmos-tx-encoder": "^0.2.1",
|
|
13
13
|
"@pioneer-platform/loggerdog": "^8.3.1",
|
|
14
14
|
"@pioneer-platform/nodes": "^8.3.10",
|
|
15
|
-
"axios": "^1.
|
|
15
|
+
"axios": "^1.6.0",
|
|
16
16
|
"dotenv": "^8.2.0",
|
|
17
17
|
"https": "^1.0.0",
|
|
18
|
-
"typescript": "^5.0.
|
|
18
|
+
"typescript": "^5.0.4",
|
|
19
19
|
"wait-promise": "^0.4.1"
|
|
20
20
|
},
|
|
21
21
|
"description": "Cosmos events to redis pub/sub",
|
|
@@ -31,4 +31,4 @@
|
|
|
31
31
|
"author": "Bithighlander <pioneer@gmail.com>",
|
|
32
32
|
"license": "ISC",
|
|
33
33
|
"gitHead": "aeae28273014ab69b42f22abec159c6693a56c40"
|
|
34
|
-
}
|
|
34
|
+
}
|