@pioneer-platform/osmosis-network 8.3.12 → 8.3.13
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.js +114 -2
- package/package.json +7 -7
package/lib/index.js
CHANGED
|
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g =
|
|
12
|
+
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);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
14
|
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
15
|
function step(op) {
|
|
16
16
|
if (f) throw new TypeError("Generator is already executing.");
|
|
@@ -181,6 +181,9 @@ module.exports = {
|
|
|
181
181
|
getAPR: function () {
|
|
182
182
|
return get_APR();
|
|
183
183
|
},
|
|
184
|
+
getStakingPositions: function (address) {
|
|
185
|
+
return get_staking_positions(address);
|
|
186
|
+
},
|
|
184
187
|
getEpochs: function () {
|
|
185
188
|
return get_epochs();
|
|
186
189
|
},
|
|
@@ -1175,3 +1178,112 @@ var get_node_info_verbose = function () {
|
|
|
1175
1178
|
});
|
|
1176
1179
|
});
|
|
1177
1180
|
};
|
|
1181
|
+
var get_staking_positions = function (address) {
|
|
1182
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1183
|
+
var tag, positions, delegations, i, delegation, position, e_29, rewards, i, reward, rewardAmount, j, position, e_30, e_31;
|
|
1184
|
+
return __generator(this, function (_a) {
|
|
1185
|
+
switch (_a.label) {
|
|
1186
|
+
case 0:
|
|
1187
|
+
tag = TAG + " | get_staking_positions | ";
|
|
1188
|
+
_a.label = 1;
|
|
1189
|
+
case 1:
|
|
1190
|
+
_a.trys.push([1, 9, , 10]);
|
|
1191
|
+
positions = [];
|
|
1192
|
+
_a.label = 2;
|
|
1193
|
+
case 2:
|
|
1194
|
+
_a.trys.push([2, 4, , 5]);
|
|
1195
|
+
return [4 /*yield*/, get_delegations_by_address(address)];
|
|
1196
|
+
case 3:
|
|
1197
|
+
delegations = _a.sent();
|
|
1198
|
+
log.debug(tag, "delegations: ", delegations);
|
|
1199
|
+
if (delegations && delegations.length > 0) {
|
|
1200
|
+
for (i = 0; i < delegations.length; i++) {
|
|
1201
|
+
delegation = delegations[i];
|
|
1202
|
+
position = {
|
|
1203
|
+
type: 'delegation',
|
|
1204
|
+
chart: 'staking',
|
|
1205
|
+
context: 'osmosis:staking',
|
|
1206
|
+
contextType: 'staking',
|
|
1207
|
+
caip: 'cosmos:osmosis-1/slip44:118',
|
|
1208
|
+
networkId: 'cosmos:osmosis-1',
|
|
1209
|
+
pubkey: address,
|
|
1210
|
+
validatorAddress: delegation.delegation.validator_address,
|
|
1211
|
+
shares: delegation.delegation.shares,
|
|
1212
|
+
balance: parseFloat(delegation.balance.amount) / BASE_OSMO,
|
|
1213
|
+
denom: delegation.balance.denom,
|
|
1214
|
+
ticker: 'OSMO',
|
|
1215
|
+
symbol: 'OSMO',
|
|
1216
|
+
name: 'Osmosis Delegation',
|
|
1217
|
+
icon: 'https://pioneers.dev/coins/osmosis.png',
|
|
1218
|
+
status: 'active',
|
|
1219
|
+
updated: new Date().getTime(),
|
|
1220
|
+
valueUsd: 0 // Will be calculated by chart processor
|
|
1221
|
+
};
|
|
1222
|
+
positions.push(position);
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
return [3 /*break*/, 5];
|
|
1226
|
+
case 4:
|
|
1227
|
+
e_29 = _a.sent();
|
|
1228
|
+
log.error(tag, "Error getting delegations:", e_29);
|
|
1229
|
+
return [3 /*break*/, 5];
|
|
1230
|
+
case 5:
|
|
1231
|
+
_a.trys.push([5, 7, , 8]);
|
|
1232
|
+
return [4 /*yield*/, get_rewards(address)];
|
|
1233
|
+
case 6:
|
|
1234
|
+
rewards = _a.sent();
|
|
1235
|
+
log.debug(tag, "rewards: ", rewards);
|
|
1236
|
+
if (rewards && rewards.result && rewards.result.rewards) {
|
|
1237
|
+
for (i = 0; i < rewards.result.rewards.length; i++) {
|
|
1238
|
+
reward = rewards.result.rewards[i];
|
|
1239
|
+
if (reward.reward && reward.reward.length > 0) {
|
|
1240
|
+
rewardAmount = 0;
|
|
1241
|
+
for (j = 0; j < reward.reward.length; j++) {
|
|
1242
|
+
if (reward.reward[j].denom === 'uosmo') {
|
|
1243
|
+
rewardAmount += parseFloat(reward.reward[j].amount) / BASE_OSMO;
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
if (rewardAmount > 0) {
|
|
1247
|
+
position = {
|
|
1248
|
+
type: 'reward',
|
|
1249
|
+
chart: 'staking',
|
|
1250
|
+
context: 'osmosis:rewards',
|
|
1251
|
+
contextType: 'rewards',
|
|
1252
|
+
caip: 'cosmos:osmosis-1/slip44:118',
|
|
1253
|
+
networkId: 'cosmos:osmosis-1',
|
|
1254
|
+
pubkey: address,
|
|
1255
|
+
validatorAddress: reward.validator_address,
|
|
1256
|
+
balance: rewardAmount,
|
|
1257
|
+
denom: 'uosmo',
|
|
1258
|
+
ticker: 'OSMO',
|
|
1259
|
+
symbol: 'OSMO',
|
|
1260
|
+
name: 'Osmosis Rewards',
|
|
1261
|
+
icon: 'https://pioneers.dev/coins/osmosis.png',
|
|
1262
|
+
status: 'claimable',
|
|
1263
|
+
updated: new Date().getTime(),
|
|
1264
|
+
valueUsd: 0 // Will be calculated by chart processor
|
|
1265
|
+
};
|
|
1266
|
+
positions.push(position);
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
return [3 /*break*/, 8];
|
|
1272
|
+
case 7:
|
|
1273
|
+
e_30 = _a.sent();
|
|
1274
|
+
log.error(tag, "Error getting rewards:", e_30);
|
|
1275
|
+
return [3 /*break*/, 8];
|
|
1276
|
+
case 8:
|
|
1277
|
+
// TODO: Add unbonding delegations support
|
|
1278
|
+
// This would require implementing get_unbonding_delegations function
|
|
1279
|
+
log.info(tag, "Found ".concat(positions.length, " staking positions for ").concat(address));
|
|
1280
|
+
return [2 /*return*/, positions];
|
|
1281
|
+
case 9:
|
|
1282
|
+
e_31 = _a.sent();
|
|
1283
|
+
log.error(tag, "Error getting staking positions: ", e_31);
|
|
1284
|
+
return [2 /*return*/, []];
|
|
1285
|
+
case 10: return [2 /*return*/];
|
|
1286
|
+
}
|
|
1287
|
+
});
|
|
1288
|
+
});
|
|
1289
|
+
};
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pioneer-platform/osmosis-network",
|
|
3
|
-
"version": "8.3.
|
|
3
|
+
"version": "8.3.13",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"create": "
|
|
7
|
+
"create": "pnpm run build && pnpm run test",
|
|
8
8
|
"build": "tsc -p .",
|
|
9
|
-
"test": "
|
|
10
|
-
"prepublish": "rm -rf lib &&
|
|
11
|
-
"refresh": "rm -rf ./node_modules ./package-lock.json &&
|
|
9
|
+
"test": "pnpm run build && node __tests__/test-module.js",
|
|
10
|
+
"prepublish": "rm -rf lib && pnpm run build",
|
|
11
|
+
"refresh": "rm -rf ./node_modules ./package-lock.json && pnpm install"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@pioneer-platform/loggerdog": "^8.3.1",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"dotenv": "^8.2.0",
|
|
17
17
|
"prettyjson": "^1.2.1",
|
|
18
18
|
"ts-node": "^8.10.2",
|
|
19
|
-
"typescript": "^5.0.
|
|
19
|
+
"typescript": "^5.0.4"
|
|
20
20
|
},
|
|
21
21
|
"gitHead": "a76012f6693a12181c4744e53e977a9eaeef0ed3"
|
|
22
|
-
}
|
|
22
|
+
}
|