@airgap/polkadot 0.13.10 → 0.13.11-beta.1

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.
Files changed (118) hide show
  1. package/package.json +14 -8
  2. package/airgap-coinlib-polkadot.min.js +0 -85359
  3. package/index.d.ts +0 -1
  4. package/index.js +0 -18
  5. package/index.js.map +0 -1
  6. package/v0/index.d.ts +0 -5
  7. package/v0/index.js +0 -31
  8. package/v0/index.js.map +0 -1
  9. package/v0/protocol/kusama/KusamaProtocol.d.ts +0 -22
  10. package/v0/protocol/kusama/KusamaProtocol.js +0 -71
  11. package/v0/protocol/kusama/KusamaProtocol.js.map +0 -1
  12. package/v0/protocol/kusama/KusamaProtocolOptions.d.ts +0 -23
  13. package/v0/protocol/kusama/KusamaProtocolOptions.js +0 -85
  14. package/v0/protocol/kusama/KusamaProtocolOptions.js.map +0 -1
  15. package/v0/protocol/polkadot/PolkadotProtocol.d.ts +0 -23
  16. package/v0/protocol/polkadot/PolkadotProtocol.js +0 -72
  17. package/v0/protocol/polkadot/PolkadotProtocol.js.map +0 -1
  18. package/v0/protocol/polkadot/PolkadotProtocolOptions.d.ts +0 -23
  19. package/v0/protocol/polkadot/PolkadotProtocolOptions.js +0 -85
  20. package/v0/protocol/polkadot/PolkadotProtocolOptions.js.map +0 -1
  21. package/v1/block-explorer/SubscanBlockExplorer.d.ts +0 -3
  22. package/v1/block-explorer/SubscanBlockExplorer.js +0 -16
  23. package/v1/block-explorer/SubscanBlockExplorer.js.map +0 -1
  24. package/v1/controller/PolkadotAccountController.d.ts +0 -28
  25. package/v1/controller/PolkadotAccountController.js +0 -656
  26. package/v1/controller/PolkadotAccountController.js.map +0 -1
  27. package/v1/controller/PolkadotTransactionController.d.ts +0 -5
  28. package/v1/controller/PolkadotTransactionController.js +0 -28
  29. package/v1/controller/PolkadotTransactionController.js.map +0 -1
  30. package/v1/data/staking/PolkadotActiveEraInfo.d.ts +0 -8
  31. package/v1/data/staking/PolkadotActiveEraInfo.js +0 -19
  32. package/v1/data/staking/PolkadotActiveEraInfo.js.map +0 -1
  33. package/v1/data/staking/PolkadotEraElectionStatus.d.ts +0 -12
  34. package/v1/data/staking/PolkadotEraElectionStatus.js +0 -27
  35. package/v1/data/staking/PolkadotEraElectionStatus.js.map +0 -1
  36. package/v1/data/staking/PolkadotEraRewardPoints.d.ts +0 -8
  37. package/v1/data/staking/PolkadotEraRewardPoints.js +0 -21
  38. package/v1/data/staking/PolkadotEraRewardPoints.js.map +0 -1
  39. package/v1/data/staking/PolkadotExposure.d.ts +0 -9
  40. package/v1/data/staking/PolkadotExposure.js +0 -23
  41. package/v1/data/staking/PolkadotExposure.js.map +0 -1
  42. package/v1/data/staking/PolkadotNominationStatus.d.ts +0 -5
  43. package/v1/data/staking/PolkadotNominationStatus.js +0 -10
  44. package/v1/data/staking/PolkadotNominationStatus.js.map +0 -1
  45. package/v1/data/staking/PolkadotNominations.d.ts +0 -9
  46. package/v1/data/staking/PolkadotNominations.js +0 -21
  47. package/v1/data/staking/PolkadotNominations.js.map +0 -1
  48. package/v1/data/staking/PolkadotNominatorDetails.d.ts +0 -24
  49. package/v1/data/staking/PolkadotNominatorDetails.js +0 -3
  50. package/v1/data/staking/PolkadotNominatorDetails.js.map +0 -1
  51. package/v1/data/staking/PolkadotPayee.d.ts +0 -5
  52. package/v1/data/staking/PolkadotPayee.js +0 -10
  53. package/v1/data/staking/PolkadotPayee.js.map +0 -1
  54. package/v1/data/staking/PolkadotSlashingSpans.d.ts +0 -10
  55. package/v1/data/staking/PolkadotSlashingSpans.js +0 -23
  56. package/v1/data/staking/PolkadotSlashingSpans.js.map +0 -1
  57. package/v1/data/staking/PolkadotStakingActionType.d.ts +0 -14
  58. package/v1/data/staking/PolkadotStakingActionType.js +0 -19
  59. package/v1/data/staking/PolkadotStakingActionType.js.map +0 -1
  60. package/v1/data/staking/PolkadotStakingLedger.d.ts +0 -11
  61. package/v1/data/staking/PolkadotStakingLedger.js +0 -27
  62. package/v1/data/staking/PolkadotStakingLedger.js.map +0 -1
  63. package/v1/data/staking/PolkadotValidatorDetails.d.ts +0 -16
  64. package/v1/data/staking/PolkadotValidatorDetails.js +0 -3
  65. package/v1/data/staking/PolkadotValidatorDetails.js.map +0 -1
  66. package/v1/data/staking/PolkadotValidatorPrefs.d.ts +0 -7
  67. package/v1/data/staking/PolkadotValidatorPrefs.js +0 -17
  68. package/v1/data/staking/PolkadotValidatorPrefs.js.map +0 -1
  69. package/v1/data/transaction/method/args.d.ts +0 -2
  70. package/v1/data/transaction/method/args.js +0 -439
  71. package/v1/data/transaction/method/args.js.map +0 -1
  72. package/v1/data/transaction/transaction.d.ts +0 -2
  73. package/v1/data/transaction/transaction.js +0 -28
  74. package/v1/data/transaction/transaction.js.map +0 -1
  75. package/v1/index.d.ts +0 -10
  76. package/v1/index.js +0 -13
  77. package/v1/index.js.map +0 -1
  78. package/v1/module/PolkadotModule.d.ts +0 -17
  79. package/v1/module/PolkadotModule.js +0 -121
  80. package/v1/module/PolkadotModule.js.map +0 -1
  81. package/v1/node/PolkadotNodeClient.d.ts +0 -46
  82. package/v1/node/PolkadotNodeClient.js +0 -323
  83. package/v1/node/PolkadotNodeClient.js.map +0 -1
  84. package/v1/protocol/KusamaProtocol.d.ts +0 -14
  85. package/v1/protocol/KusamaProtocol.js +0 -105
  86. package/v1/protocol/KusamaProtocol.js.map +0 -1
  87. package/v1/protocol/PolkadotBaseProtocol.d.ts +0 -24
  88. package/v1/protocol/PolkadotBaseProtocol.js +0 -478
  89. package/v1/protocol/PolkadotBaseProtocol.js.map +0 -1
  90. package/v1/protocol/PolkadotProtocol.d.ts +0 -14
  91. package/v1/protocol/PolkadotProtocol.js +0 -116
  92. package/v1/protocol/PolkadotProtocol.js.map +0 -1
  93. package/v1/serializer/v3/schemas/converter/transaction-converter.d.ts +0 -7
  94. package/v1/serializer/v3/schemas/converter/transaction-converter.js +0 -21
  95. package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +0 -1
  96. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-polkadot.d.ts +0 -3
  97. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-polkadot.js +0 -3
  98. package/v1/serializer/v3/schemas/definitions/transaction-sign-request-polkadot.js.map +0 -1
  99. package/v1/serializer/v3/schemas/definitions/transaction-sign-response-polkadot.d.ts +0 -3
  100. package/v1/serializer/v3/schemas/definitions/transaction-sign-response-polkadot.js +0 -3
  101. package/v1/serializer/v3/schemas/definitions/transaction-sign-response-polkadot.js.map +0 -1
  102. package/v1/serializer/v3/schemas/generated/transaction-sign-request-polkadot.json +0 -36
  103. package/v1/serializer/v3/schemas/generated/transaction-sign-response-polkadot.json +0 -19
  104. package/v1/serializer/v3/serializer-companion.d.ts +0 -14
  105. package/v1/serializer/v3/serializer-companion.js +0 -189
  106. package/v1/serializer/v3/serializer-companion.js.map +0 -1
  107. package/v1/serializer/v3/validators/transaction-validator.d.ts +0 -4
  108. package/v1/serializer/v3/validators/transaction-validator.js +0 -28
  109. package/v1/serializer/v3/validators/transaction-validator.js.map +0 -1
  110. package/v1/serializer/v3/validators/validators.d.ts +0 -4
  111. package/v1/serializer/v3/validators/validators.js +0 -6
  112. package/v1/serializer/v3/validators/validators.js.map +0 -1
  113. package/v1/types/configuration.d.ts +0 -11
  114. package/v1/types/configuration.js +0 -3
  115. package/v1/types/configuration.js.map +0 -1
  116. package/v1/types/protocol.d.ts +0 -12
  117. package/v1/types/protocol.js +0 -3
  118. package/v1/types/protocol.js.map +0 -1
@@ -1,656 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
- return new (P || (P = Promise))(function (resolve, reject) {
20
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
- step((generator = generator.apply(thisArg, _arguments || [])).next());
24
- });
25
- };
26
- var __generator = (this && this.__generator) || function (thisArg, body) {
27
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
28
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
- function verb(n) { return function (v) { return step([n, v]); }; }
30
- function step(op) {
31
- if (f) throw new TypeError("Generator is already executing.");
32
- while (_) try {
33
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
- if (y = 0, t) op = [op[0] & 2, t.value];
35
- switch (op[0]) {
36
- case 0: case 1: t = op; break;
37
- case 4: _.label++; return { value: op[1], done: false };
38
- case 5: _.label++; y = op[1]; op = [0]; continue;
39
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
- default:
41
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
- if (t[2]) _.ops.pop();
46
- _.trys.pop(); continue;
47
- }
48
- op = body.call(thisArg, _);
49
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
- }
52
- };
53
- var __importDefault = (this && this.__importDefault) || function (mod) {
54
- return (mod && mod.__esModule) ? mod : { "default": mod };
55
- };
56
- Object.defineProperty(exports, "__esModule", { value: true });
57
- exports.PolkadotAccountController = void 0;
58
- var bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
59
- var v1_1 = require("@airgap/substrate/v1");
60
- var PolkadotEraElectionStatus_1 = require("../data/staking/PolkadotEraElectionStatus");
61
- var PolkadotNominationStatus_1 = require("../data/staking/PolkadotNominationStatus");
62
- var PolkadotStakingActionType_1 = require("../data/staking/PolkadotStakingActionType");
63
- var PolkadotAccountController = /** @class */ (function (_super) {
64
- __extends(PolkadotAccountController, _super);
65
- function PolkadotAccountController() {
66
- return _super !== null && _super.apply(this, arguments) || this;
67
- }
68
- PolkadotAccountController.prototype.getUnlockingBalance = function (accountId) {
69
- var _a;
70
- return __awaiter(this, void 0, void 0, function () {
71
- var stakingDetails;
72
- return __generator(this, function (_b) {
73
- switch (_b.label) {
74
- case 0: return [4 /*yield*/, this.nodeClient.getStakingLedger(this.substrateAddressFrom(accountId))];
75
- case 1:
76
- stakingDetails = _b.sent();
77
- return [2 /*return*/, ((_a = stakingDetails === null || stakingDetails === void 0 ? void 0 : stakingDetails.unlocking.elements.map(function (entry) { return entry.first.value; }).reduce(function (sum, next) { return sum.plus(next); }, new bignumber_1.default(0))) !== null && _a !== void 0 ? _a : new bignumber_1.default(0))];
78
- }
79
- });
80
- });
81
- };
82
- PolkadotAccountController.prototype.isBonded = function (accountId) {
83
- return __awaiter(this, void 0, void 0, function () {
84
- var bonded;
85
- return __generator(this, function (_a) {
86
- switch (_a.label) {
87
- case 0: return [4 /*yield*/, this.nodeClient.getBonded(this.substrateAddressFrom(accountId))];
88
- case 1:
89
- bonded = _a.sent();
90
- return [2 /*return*/, bonded != undefined];
91
- }
92
- });
93
- });
94
- };
95
- PolkadotAccountController.prototype.isDelegating = function (accountId) {
96
- return __awaiter(this, void 0, void 0, function () {
97
- var nominations;
98
- return __generator(this, function (_a) {
99
- switch (_a.label) {
100
- case 0: return [4 /*yield*/, this.nodeClient.getNominations(this.substrateAddressFrom(accountId))];
101
- case 1:
102
- nominations = _a.sent();
103
- return [2 /*return*/, nominations != undefined];
104
- }
105
- });
106
- });
107
- };
108
- PolkadotAccountController.prototype.getCurrentValidators = function (accountId) {
109
- return __awaiter(this, void 0, void 0, function () {
110
- var nominations;
111
- return __generator(this, function (_a) {
112
- switch (_a.label) {
113
- case 0: return [4 /*yield*/, this.nodeClient.getNominations(this.substrateAddressFrom(accountId))];
114
- case 1:
115
- nominations = _a.sent();
116
- if (nominations) {
117
- return [2 /*return*/, nominations.targets.elements.map(function (target) { return target.asAddress(); })];
118
- }
119
- return [2 /*return*/, []];
120
- }
121
- });
122
- });
123
- };
124
- PolkadotAccountController.prototype.getValidatorDetails = function (accountId) {
125
- var _a;
126
- return __awaiter(this, void 0, void 0, function () {
127
- var address, activeEra, identity, status, exposure, validatorPrefs, lastEraReward, activeEraIndex, results, currentValidators;
128
- return __generator(this, function (_b) {
129
- switch (_b.label) {
130
- case 0:
131
- address = this.substrateAddressFrom(accountId);
132
- return [4 /*yield*/, this.nodeClient.getActiveEraInfo()];
133
- case 1:
134
- activeEra = _b.sent();
135
- if (!activeEra) return [3 /*break*/, 4];
136
- activeEraIndex = activeEra.index.toNumber();
137
- return [4 /*yield*/, Promise.all([
138
- this.getAccountIdentityInfo(address),
139
- this.nodeClient.getValidators(),
140
- this.nodeClient.getValidatorPrefs(activeEraIndex, address),
141
- this.nodeClient.getValidatorExposure(activeEraIndex, address)
142
- ])];
143
- case 2:
144
- results = _b.sent();
145
- identity = results[0];
146
- currentValidators = results[1];
147
- validatorPrefs = results[2];
148
- exposure = results[3];
149
- return [4 /*yield*/, this.getEraValidatorReward(address, activeEraIndex - 1)];
150
- case 3:
151
- lastEraReward = _b.sent();
152
- if (currentValidators && currentValidators.find(function (current) { return current.compare(address) == 0; })) {
153
- status = 'Active';
154
- }
155
- else if (currentValidators) {
156
- status = 'Inactive';
157
- }
158
- _b.label = 4;
159
- case 4: return [2 /*return*/, {
160
- address: address.asString(),
161
- name: identity ? identity.display.toString() : undefined,
162
- status: status,
163
- ownStash: exposure ? exposure.own.toString() : undefined,
164
- totalStakingBalance: exposure ? exposure.total.toString() : undefined,
165
- commission: validatorPrefs
166
- ? validatorPrefs.commission.value.dividedBy(1000000000).toString() // commission is Perbill (parts per billion)
167
- : undefined,
168
- lastEraReward: lastEraReward,
169
- nominators: (_a = exposure === null || exposure === void 0 ? void 0 : exposure.others.elements.length) !== null && _a !== void 0 ? _a : 0
170
- }];
171
- }
172
- });
173
- });
174
- };
175
- PolkadotAccountController.prototype.getNominatorDetails = function (accountId, validatorIds) {
176
- var _a, _b;
177
- return __awaiter(this, void 0, void 0, function () {
178
- var address, results, balance, stakingLedger, nominations, activeEra, expectedEraDuration, validators, stakingDetails, availableActions;
179
- return __generator(this, function (_c) {
180
- switch (_c.label) {
181
- case 0:
182
- address = this.substrateAddressFrom(accountId);
183
- return [4 /*yield*/, Promise.all([
184
- this.getBalance(address),
185
- this.nodeClient.getStakingLedger(address),
186
- this.nodeClient.getNominations(address),
187
- this.nodeClient.getActiveEraInfo(),
188
- this.nodeClient.getExpectedEraDuration(),
189
- this.nodeClient.getExistentialDeposit()
190
- ])];
191
- case 1:
192
- results = _c.sent();
193
- balance = results[0];
194
- stakingLedger = results[1];
195
- nominations = results[2];
196
- activeEra = results[3];
197
- expectedEraDuration = results[4];
198
- if (!balance || !activeEra || !expectedEraDuration) {
199
- return [2 /*return*/, Promise.reject('Could not fetch nominator details.')];
200
- }
201
- validators = ((_b = (_a = nominations === null || nominations === void 0 ? void 0 : nominations.targets) === null || _a === void 0 ? void 0 : _a.elements) === null || _b === void 0 ? void 0 : _b.map(function (target) { return target.asAddress(); })) || [];
202
- return [4 /*yield*/, this.getStakingDetails(accountId, stakingLedger, nominations, activeEra, expectedEraDuration)];
203
- case 2:
204
- stakingDetails = _c.sent();
205
- return [4 /*yield*/, this.getAvailableStakingActions(stakingDetails, nominations, validatorIds !== null && validatorIds !== void 0 ? validatorIds : validators, balance.transferableCoveringFees)];
206
- case 3:
207
- availableActions = _c.sent();
208
- return [2 /*return*/, {
209
- address: address.asString(),
210
- balance: balance.toString(),
211
- delegatees: validators,
212
- availableActions: availableActions,
213
- stakingDetails: stakingDetails
214
- }];
215
- }
216
- });
217
- });
218
- };
219
- PolkadotAccountController.prototype.getNominationStatus = function (nominator, validator, era) {
220
- var _a;
221
- return __awaiter(this, void 0, void 0, function () {
222
- var eraIndex, _b, nominations, exposure, isActive, isOversubscribed, position;
223
- return __generator(this, function (_c) {
224
- switch (_c.label) {
225
- case 0:
226
- if (!(era !== undefined)) return [3 /*break*/, 1];
227
- _b = era;
228
- return [3 /*break*/, 3];
229
- case 1: return [4 /*yield*/, this.nodeClient.getActiveEraInfo()];
230
- case 2:
231
- _b = (_a = (_c.sent())) === null || _a === void 0 ? void 0 : _a.index.toNumber();
232
- _c.label = 3;
233
- case 3:
234
- eraIndex = _b;
235
- if (eraIndex === undefined) {
236
- return [2 /*return*/, Promise.reject('Could not fetch active era')];
237
- }
238
- return [4 /*yield*/, this.nodeClient.getNominations(this.substrateAddressFrom(nominator))];
239
- case 4:
240
- nominations = _c.sent();
241
- if (nominations === undefined ||
242
- !nominations.targets.elements.some(function (target) { return target.asAddress() === validator; })) {
243
- return [2 /*return*/, undefined];
244
- }
245
- return [4 /*yield*/, this.nodeClient.getValidatorExposure(eraIndex, this.substrateAddressFrom(validator))];
246
- case 5:
247
- exposure = _c.sent();
248
- if (!exposure) {
249
- return [2 /*return*/, PolkadotNominationStatus_1.PolkadotNominationStatus.INACTIVE];
250
- }
251
- isActive = exposure.others.elements.some(function (element) { return element.first.asAddress() === nominator.toString(); });
252
- if (!isActive) {
253
- return [2 /*return*/, PolkadotNominationStatus_1.PolkadotNominationStatus.INACTIVE];
254
- }
255
- isOversubscribed = exposure.others.elements.length > 256;
256
- if (isOversubscribed) {
257
- position = exposure.others.elements
258
- .sort(function (a, b) { return b.second.value.minus(a.second.value).toNumber(); })
259
- .map(function (exposure) { return exposure.first.asAddress(); })
260
- .indexOf(nominator.toString());
261
- if (position > 256) {
262
- return [2 /*return*/, PolkadotNominationStatus_1.PolkadotNominationStatus.OVERSUBSCRIBED];
263
- }
264
- }
265
- return [2 /*return*/, PolkadotNominationStatus_1.PolkadotNominationStatus.ACTIVE];
266
- }
267
- });
268
- });
269
- };
270
- PolkadotAccountController.prototype.getSlashingSpansNumber = function (accountId) {
271
- return __awaiter(this, void 0, void 0, function () {
272
- var slashingSpans;
273
- return __generator(this, function (_a) {
274
- switch (_a.label) {
275
- case 0: return [4 /*yield*/, this.nodeClient.getSlashingSpan(this.substrateAddressFrom(accountId))];
276
- case 1:
277
- slashingSpans = _a.sent();
278
- return [2 /*return*/, slashingSpans ? slashingSpans.prior.elements.length + 1 : 0];
279
- }
280
- });
281
- });
282
- };
283
- PolkadotAccountController.prototype.getStakingDetails = function (accountId, stakingLedger, nominations, activeEra, expectedEraDuration) {
284
- var _a, _b;
285
- return __awaiter(this, void 0, void 0, function () {
286
- var unlockingDetails, results, stakingStatus, rewards;
287
- return __generator(this, function (_c) {
288
- switch (_c.label) {
289
- case 0:
290
- if (!stakingLedger) {
291
- return [2 /*return*/, undefined];
292
- }
293
- unlockingDetails = this.getUnlockingDetails(stakingLedger.unlocking.elements.map(function (tuple) { return [tuple.first.value, tuple.second.value]; }), activeEra, expectedEraDuration);
294
- return [4 /*yield*/, Promise.all([
295
- this.getStakingStatus(accountId, nominations, activeEra.index.toNumber()),
296
- nominations
297
- ? this.getNominatorRewards(accountId, nominations.targets.elements.map(function (id) { return id.address; }), activeEra, 5)
298
- : []
299
- ])];
300
- case 1:
301
- results = _c.sent();
302
- stakingStatus = results[0];
303
- rewards = results[1];
304
- return [2 /*return*/, {
305
- total: stakingLedger.total.toString(),
306
- active: stakingLedger.active.toString(),
307
- locked: unlockingDetails.locked,
308
- unlocked: unlockingDetails.unlocked,
309
- status: stakingStatus,
310
- nextEra: ((_b = (_a = activeEra.start.value) === null || _a === void 0 ? void 0 : _a.plus(expectedEraDuration)) === null || _b === void 0 ? void 0 : _b.toNumber()) || 0,
311
- rewards: rewards
312
- }];
313
- }
314
- });
315
- });
316
- };
317
- PolkadotAccountController.prototype.getUnlockingDetails = function (unlocking, activeEra, expectedEraDuration) {
318
- var _a = this.partitionArray(unlocking, function (_a) {
319
- var _ = _a[0], era = _a[1];
320
- return activeEra.index.lt(era);
321
- }), locked = _a[0], unlocked = _a[1];
322
- var lockedDetails = locked.map(function (_a) {
323
- var _b;
324
- var value = _a[0], era = _a[1];
325
- var eraStart = ((_b = activeEra.start.value) === null || _b === void 0 ? void 0 : _b.value) || new bignumber_1.default(0);
326
- var estimatedDuration = era.minus(activeEra.index.value).multipliedBy(expectedEraDuration);
327
- var expectedUnlock = eraStart.plus(estimatedDuration);
328
- return {
329
- value: value.toString(10),
330
- expectedUnlock: expectedUnlock.toNumber()
331
- };
332
- });
333
- var totalUnlocked = unlocked.reduce(function (total, _a) {
334
- var value = _a[0], _ = _a[1];
335
- return total.plus(value);
336
- }, new bignumber_1.default(0));
337
- return {
338
- locked: lockedDetails,
339
- unlocked: totalUnlocked.toString()
340
- };
341
- };
342
- PolkadotAccountController.prototype.getStakingStatus = function (nominator, nominations, eraIndex) {
343
- var _a;
344
- return __awaiter(this, void 0, void 0, function () {
345
- var isWaitingForNomination, hasActiveNominations;
346
- var _this = this;
347
- return __generator(this, function (_b) {
348
- switch (_b.label) {
349
- case 0:
350
- isWaitingForNomination = (_a = nominations === null || nominations === void 0 ? void 0 : nominations.submittedIn.gte(eraIndex)) !== null && _a !== void 0 ? _a : false;
351
- hasActiveNominations = false;
352
- if (!(!isWaitingForNomination && nominations)) return [3 /*break*/, 2];
353
- return [4 /*yield*/, Promise.all(nominations.targets.elements.map(function (target) {
354
- return _this.getNominationStatus(nominator, target.asAddress(), eraIndex);
355
- }))];
356
- case 1:
357
- hasActiveNominations = (_b.sent()).some(function (status) { return status === PolkadotNominationStatus_1.PolkadotNominationStatus.ACTIVE; });
358
- _b.label = 2;
359
- case 2:
360
- if (nominations === undefined) {
361
- return [2 /*return*/, 'bonded'];
362
- }
363
- else if (hasActiveNominations) {
364
- return [2 /*return*/, 'nominating'];
365
- }
366
- else if (!isWaitingForNomination && !hasActiveNominations) {
367
- return [2 /*return*/, 'nominating_inactive'];
368
- }
369
- else {
370
- return [2 /*return*/, 'nominating_waiting'];
371
- }
372
- return [2 /*return*/];
373
- }
374
- });
375
- });
376
- };
377
- PolkadotAccountController.prototype.getEraValidatorReward = function (accountId, eraIndex) {
378
- var _a, _b, _c, _d;
379
- return __awaiter(this, void 0, void 0, function () {
380
- var address, results, eraReward, eraPoints, exposureClipped, validatorPrefs, validatorPoints, validatorReward;
381
- var _this = this;
382
- return __generator(this, function (_e) {
383
- switch (_e.label) {
384
- case 0:
385
- address = this.substrateAddressFrom(accountId);
386
- return [4 /*yield*/, Promise.all([
387
- this.nodeClient.getValidatorReward(eraIndex).then(function (result) { return __awaiter(_this, void 0, void 0, function () {
388
- return __generator(this, function (_a) {
389
- return [2 /*return*/, result ? result : this.nodeClient.getValidatorReward(eraIndex - 1)];
390
- });
391
- }); }),
392
- this.nodeClient.getRewardPoints(eraIndex),
393
- this.nodeClient.getStakersClipped(eraIndex, address),
394
- this.nodeClient.getValidatorPrefs(eraIndex, address)
395
- ])];
396
- case 1:
397
- results = _e.sent();
398
- if (results.some(function (result) { return !result; })) {
399
- return [2 /*return*/, undefined];
400
- }
401
- eraReward = results[0];
402
- eraPoints = results[1];
403
- exposureClipped = results[2];
404
- validatorPrefs = results[3];
405
- validatorPoints = (_d = (_c = (_b = (_a = eraPoints === null || eraPoints === void 0 ? void 0 : eraPoints.individual) === null || _a === void 0 ? void 0 : _a.elements) === null || _b === void 0 ? void 0 : _b.find(function (element) { return element.first.address.compare(address); })) === null || _c === void 0 ? void 0 : _c.second) === null || _d === void 0 ? void 0 : _d.value;
406
- if (!eraReward || !eraPoints || !exposureClipped || !validatorPrefs || !validatorPoints) {
407
- return [2 /*return*/, undefined];
408
- }
409
- validatorReward = this.calculateValidatorReward(eraReward, eraPoints.total.value, validatorPoints);
410
- return [2 /*return*/, {
411
- amount: validatorReward.toFixed(),
412
- totalStake: exposureClipped.total.toString(),
413
- ownStake: exposureClipped.own.toString(),
414
- commission: validatorPrefs.commission.toString()
415
- }];
416
- }
417
- });
418
- });
419
- };
420
- PolkadotAccountController.prototype.getNominatorRewards = function (accountId, validators, activeEra, eras) {
421
- return __awaiter(this, void 0, void 0, function () {
422
- var address, expectedEraDuration, eraIndices, rewards;
423
- var _this = this;
424
- return __generator(this, function (_a) {
425
- switch (_a.label) {
426
- case 0:
427
- address = this.substrateAddressFrom(accountId);
428
- return [4 /*yield*/, this.nodeClient.getExpectedEraDuration()];
429
- case 1:
430
- expectedEraDuration = _a.sent();
431
- if (!expectedEraDuration) {
432
- return [2 /*return*/, Promise.reject('Could not fetch all necessary data.')];
433
- }
434
- eraIndices = Array.isArray(eras) ? eras : Array.from(Array(eras).keys()).map(function (index) { return activeEra.index.toNumber() - 1 - index; });
435
- return [4 /*yield*/, Promise.all(eraIndices.map(function (era) {
436
- return _this.calculateEraNominatorReward(address, validators.map(function (validator) { return _this.substrateAddressFrom(validator); }), era).then(function (partial) {
437
- if (partial) {
438
- var rewardEra = partial.eraIndex || activeEra.index.toNumber();
439
- var erasPassed = activeEra.index.minus(rewardEra).toNumber();
440
- partial.timestamp = activeEra.start.value
441
- ? activeEra.start.value.minus(expectedEraDuration.multipliedBy(erasPassed - 1)).toNumber()
442
- : 0;
443
- }
444
- return partial;
445
- });
446
- }))];
447
- case 2:
448
- rewards = _a.sent();
449
- return [2 /*return*/, rewards.filter(function (reward) { return reward; })];
450
- }
451
- });
452
- });
453
- };
454
- PolkadotAccountController.prototype.calculateEraNominatorReward = function (accountId, validators, eraIndex) {
455
- return __awaiter(this, void 0, void 0, function () {
456
- var results, reward, rewardPoints, exposuresWithValidators, partialRewards;
457
- var _this = this;
458
- return __generator(this, function (_a) {
459
- switch (_a.label) {
460
- case 0: return [4 /*yield*/, Promise.all([
461
- this.nodeClient.getValidatorReward(eraIndex),
462
- this.nodeClient.getRewardPoints(eraIndex),
463
- Promise.all(validators.map(function (validator) { return __awaiter(_this, void 0, void 0, function () {
464
- var _a;
465
- return __generator(this, function (_b) {
466
- switch (_b.label) {
467
- case 0:
468
- _a = [this.substrateAddressFrom(validator)];
469
- return [4 /*yield*/, this.nodeClient
470
- .getValidatorPrefs(eraIndex, this.substrateAddressFrom(validator))
471
- .then(function (prefs) { var _a; return (_a = prefs === null || prefs === void 0 ? void 0 : prefs.commission) === null || _a === void 0 ? void 0 : _a.value; })];
472
- case 1:
473
- _a = _a.concat([
474
- _b.sent()
475
- ]);
476
- return [4 /*yield*/, this.nodeClient.getStakersClipped(eraIndex, this.substrateAddressFrom(validator))];
477
- case 2: return [2 /*return*/, _a.concat([
478
- _b.sent()
479
- ])];
480
- }
481
- });
482
- }); }))
483
- ])];
484
- case 1:
485
- results = _a.sent();
486
- reward = results[0];
487
- rewardPoints = results[1];
488
- exposuresWithValidators = results[2];
489
- if (!reward || !rewardPoints || !exposuresWithValidators) {
490
- return [2 /*return*/, undefined];
491
- }
492
- partialRewards = exposuresWithValidators
493
- .map(function (_a) {
494
- var _b, _c, _d, _e;
495
- var validator = _a[0], commission = _a[1], exposure = _a[2];
496
- var validatorPoints = (_c = (_b = rewardPoints.individual.elements.find(function (element) { return element.first.compare(validator) === 0; })) === null || _b === void 0 ? void 0 : _b.second) === null || _c === void 0 ? void 0 : _c.value;
497
- var nominatorStake = (_e = (_d = exposure === null || exposure === void 0 ? void 0 : exposure.others.elements.find(function (element) { return element.first.compare(accountId) === 0; })) === null || _d === void 0 ? void 0 : _d.second) === null || _e === void 0 ? void 0 : _e.value;
498
- if (commission && exposure && validatorPoints && nominatorStake) {
499
- var validatorReward = _this.calculateValidatorReward(reward, rewardPoints.total.value, validatorPoints);
500
- return _this.calculateNominatorReward(validatorReward, commission, exposure.total.value, nominatorStake);
501
- }
502
- else {
503
- return undefined;
504
- }
505
- })
506
- .filter(function (reward) { return reward !== undefined; });
507
- if (partialRewards.every(function (reward) { return !reward; })) {
508
- return [2 /*return*/, undefined];
509
- }
510
- return [2 /*return*/, {
511
- eraIndex: eraIndex,
512
- amount: partialRewards.reduce(function (sum, next) { return sum.plus(next); }, new bignumber_1.default(0)).toFixed(0),
513
- exposures: exposuresWithValidators === null || exposuresWithValidators === void 0 ? void 0 : exposuresWithValidators.map(function (_a) {
514
- var validator = _a[0], _ = _a[1], exposure = _a[2];
515
- return [
516
- validator.asString(),
517
- exposure === null || exposure === void 0 ? void 0 : exposure.others.elements.findIndex(function (element) { return element.first.compare(accountId) === 0; })
518
- ];
519
- }).filter(function (_a) {
520
- var _ = _a[0], index = _a[1];
521
- return index !== undefined;
522
- })
523
- }];
524
- }
525
- });
526
- });
527
- };
528
- PolkadotAccountController.prototype.calculateValidatorReward = function (totalReward, totalPoints, validatorPoints) {
529
- return validatorPoints.dividedBy(totalPoints).multipliedBy(totalReward);
530
- };
531
- PolkadotAccountController.prototype.calculateNominatorReward = function (validatorReward, validatorCommission, totalStake, nominatorStake) {
532
- var nominatorShare = nominatorStake.dividedBy(totalStake);
533
- return new bignumber_1.default(1).minus(validatorCommission.dividedBy(1000000000)).multipliedBy(validatorReward).multipliedBy(nominatorShare);
534
- };
535
- // tslint:disable-next-line: cyclomatic-complexity
536
- PolkadotAccountController.prototype.getAvailableStakingActions = function (stakingDetails, nominations, validatorIds, maxDelegationValue) {
537
- var _a, _b, _c, _d;
538
- return __awaiter(this, void 0, void 0, function () {
539
- var availableActions, currentValidators, validatorAddresses, isBonded, isDelegating, isUnbonding, minBondingValue, minDelegationValue, electionStatus, isElectionClosed, hasFundsToWithdraw;
540
- var _this = this;
541
- return __generator(this, function (_e) {
542
- switch (_e.label) {
543
- case 0:
544
- availableActions = [];
545
- currentValidators = ((_b = (_a = nominations === null || nominations === void 0 ? void 0 : nominations.targets) === null || _a === void 0 ? void 0 : _a.elements) === null || _b === void 0 ? void 0 : _b.map(function (target) { return target.asAddress(); })) || [];
546
- validatorAddresses = validatorIds.map(function (id) { return _this.substrateAddressFrom(id).asString(); });
547
- isBonded = new bignumber_1.default((_c = stakingDetails === null || stakingDetails === void 0 ? void 0 : stakingDetails.active) !== null && _c !== void 0 ? _c : 0).gt(0);
548
- isDelegating = nominations !== undefined;
549
- isUnbonding = stakingDetails && stakingDetails.locked.length > 0;
550
- return [4 /*yield*/, this.nodeClient.getExistentialDeposit()];
551
- case 1:
552
- minBondingValue = _e.sent();
553
- minDelegationValue = new bignumber_1.default(1);
554
- return [4 /*yield*/, this.nodeClient.getElectionStatus().then(function (eraElectionStatus) { return eraElectionStatus === null || eraElectionStatus === void 0 ? void 0 : eraElectionStatus.status.value; })];
555
- case 2:
556
- electionStatus = _e.sent();
557
- isElectionClosed = electionStatus !== PolkadotEraElectionStatus_1.PolkadotElectionStatus.OPEN;
558
- hasFundsToWithdraw = new bignumber_1.default((_d = stakingDetails === null || stakingDetails === void 0 ? void 0 : stakingDetails.unlocked) !== null && _d !== void 0 ? _d : 0).gt(0);
559
- if (maxDelegationValue.gt(minBondingValue !== null && minBondingValue !== void 0 ? minBondingValue : 0) && !isBonded && !isUnbonding && isElectionClosed) {
560
- availableActions.push({
561
- type: PolkadotStakingActionType_1.PolkadotStakingActionType.BOND_NOMINATE,
562
- args: ['targets', 'controller', 'value', 'payee']
563
- });
564
- }
565
- if (maxDelegationValue.gt(minDelegationValue) && isBonded && !isUnbonding && isElectionClosed) {
566
- availableActions.push({
567
- type: PolkadotStakingActionType_1.PolkadotStakingActionType.BOND_EXTRA,
568
- args: ['value']
569
- });
570
- }
571
- if (isBonded && !isDelegating && !isUnbonding && isElectionClosed) {
572
- availableActions.push({
573
- type: PolkadotStakingActionType_1.PolkadotStakingActionType.NOMINATE,
574
- args: ['targets']
575
- }, {
576
- type: PolkadotStakingActionType_1.PolkadotStakingActionType.UNBOND,
577
- args: ['value']
578
- });
579
- }
580
- if (isUnbonding && !isDelegating && isElectionClosed) {
581
- availableActions.push({
582
- type: PolkadotStakingActionType_1.PolkadotStakingActionType.REBOND_NOMINATE,
583
- args: ['targets', 'value']
584
- });
585
- }
586
- if (isUnbonding && isDelegating && isElectionClosed) {
587
- availableActions.push({
588
- type: PolkadotStakingActionType_1.PolkadotStakingActionType.REBOND_EXTRA,
589
- args: ['value']
590
- });
591
- }
592
- if (isDelegating && isElectionClosed) {
593
- if (validatorAddresses.every(function (validator) { return currentValidators.includes(validator); }) &&
594
- validatorAddresses.length === currentValidators.length) {
595
- availableActions.push({
596
- type: PolkadotStakingActionType_1.PolkadotStakingActionType.CANCEL_NOMINATION,
597
- args: ['value']
598
- });
599
- }
600
- else if (validatorAddresses.length > 0) {
601
- availableActions.push({
602
- type: PolkadotStakingActionType_1.PolkadotStakingActionType.CHANGE_NOMINATION,
603
- args: ['targets']
604
- });
605
- }
606
- }
607
- if (hasFundsToWithdraw && isElectionClosed) {
608
- availableActions.push({
609
- type: PolkadotStakingActionType_1.PolkadotStakingActionType.WITHDRAW_UNBONDED,
610
- args: []
611
- });
612
- }
613
- availableActions.sort(function (a, b) { return a.type - b.type; });
614
- return [2 /*return*/, availableActions];
615
- }
616
- });
617
- });
618
- };
619
- PolkadotAccountController.prototype.getAccountIdentityInfo = function (address) {
620
- return __awaiter(this, void 0, void 0, function () {
621
- var registration, superOf, _a;
622
- return __generator(this, function (_b) {
623
- switch (_b.label) {
624
- case 0:
625
- _b.trys.push([0, 3, , 4]);
626
- return [4 /*yield*/, this.nodeClient.getIdentityOf(address)];
627
- case 1:
628
- registration = _b.sent();
629
- if (registration) {
630
- return [2 /*return*/, registration.identityInfo];
631
- }
632
- return [4 /*yield*/, this.nodeClient.getSuperOf(address)];
633
- case 2:
634
- superOf = _b.sent();
635
- return [2 /*return*/, superOf ? this.getAccountIdentityInfo(superOf.first.address) : undefined];
636
- case 3:
637
- _a = _b.sent();
638
- return [2 /*return*/, undefined];
639
- case 4: return [2 /*return*/];
640
- }
641
- });
642
- });
643
- };
644
- PolkadotAccountController.prototype.partitionArray = function (array, predicate) {
645
- var partitioned = [[], []];
646
- for (var _i = 0, array_1 = array; _i < array_1.length; _i++) {
647
- var item = array_1[_i];
648
- var index = predicate(item) ? 0 : 1;
649
- partitioned[index].push(item);
650
- }
651
- return partitioned;
652
- };
653
- return PolkadotAccountController;
654
- }(v1_1.SubstrateCommonAccountController));
655
- exports.PolkadotAccountController = PolkadotAccountController;
656
- //# sourceMappingURL=PolkadotAccountController.js.map