@airgap/moonbeam 0.13.45-beta.1 → 0.13.45-beta.3
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/package.json +5 -5
- package/v0/index.js +7 -7
- package/v0/index.js.map +1 -1
- package/v0/protocol/moonbase/MoonbaseProtocol.js +17 -36
- package/v0/protocol/moonbase/MoonbaseProtocol.js.map +1 -1
- package/v0/protocol/moonbase/MoonbaseProtocolOptions.js +28 -67
- package/v0/protocol/moonbase/MoonbaseProtocolOptions.js.map +1 -1
- package/v0/protocol/moonbeam/MoonbeamProtocol.js +334 -589
- package/v0/protocol/moonbeam/MoonbeamProtocol.js.map +1 -1
- package/v0/protocol/moonbeam/MoonbeamProtocolOptions.js +41 -87
- package/v0/protocol/moonbeam/MoonbeamProtocolOptions.js.map +1 -1
- package/v0/protocol/moonbeam/controllers/MoonbeamAccountController.js +287 -495
- package/v0/protocol/moonbeam/controllers/MoonbeamAccountController.js.map +1 -1
- package/v0/protocol/moonbeam/controllers/MoonbeamTransactionController.d.ts +0 -1
- package/v0/protocol/moonbeam/controllers/MoonbeamTransactionController.js +9 -69
- package/v0/protocol/moonbeam/controllers/MoonbeamTransactionController.js.map +1 -1
- package/v0/protocol/moonbeam/data/staking/MoonbeamBond.js +16 -34
- package/v0/protocol/moonbeam/data/staking/MoonbeamBond.js.map +1 -1
- package/v0/protocol/moonbeam/data/staking/MoonbeamCandidateBondLessRequest.js +16 -34
- package/v0/protocol/moonbeam/data/staking/MoonbeamCandidateBondLessRequest.js.map +1 -1
- package/v0/protocol/moonbeam/data/staking/MoonbeamCandidateMetadata.js +22 -23
- package/v0/protocol/moonbeam/data/staking/MoonbeamCandidateMetadata.js.map +1 -1
- package/v0/protocol/moonbeam/data/staking/MoonbeamDelegationScheduledRequests.js +64 -107
- package/v0/protocol/moonbeam/data/staking/MoonbeamDelegationScheduledRequests.js.map +1 -1
- package/v0/protocol/moonbeam/data/staking/MoonbeamDelegator.js +50 -90
- package/v0/protocol/moonbeam/data/staking/MoonbeamDelegator.js.map +1 -1
- package/v0/protocol/moonbeam/data/staking/MoonbeamRoundInfo.js +12 -13
- package/v0/protocol/moonbeam/data/staking/MoonbeamRoundInfo.js.map +1 -1
- package/v0/protocol/moonbeam/data/staking/MoonbeamStakingActionType.js +1 -1
- package/v0/protocol/moonbeam/data/staking/MoonbeamStakingActionType.js.map +1 -1
- package/v0/protocol/moonbeam/node/MoonbeamNodeClient.js +60 -215
- package/v0/protocol/moonbeam/node/MoonbeamNodeClient.js.map +1 -1
- package/v0/protocol/moonriver/MoonriverProtocol.js +17 -36
- package/v0/protocol/moonriver/MoonriverProtocol.js.map +1 -1
- package/v0/protocol/moonriver/MoonriverProtocolOptions.js +28 -67
- package/v0/protocol/moonriver/MoonriverProtocolOptions.js.map +1 -1
- package/v1/controller/MoonbeamAccountController.js +252 -456
- package/v1/controller/MoonbeamAccountController.js.map +1 -1
- package/v1/controller/MoonbeamTransactionController.js +3 -23
- package/v1/controller/MoonbeamTransactionController.js.map +1 -1
- package/v1/data/staking/MoonbeamBond.js +14 -32
- package/v1/data/staking/MoonbeamBond.js.map +1 -1
- package/v1/data/staking/MoonbeamCandidateBondLessRequest.js +14 -32
- package/v1/data/staking/MoonbeamCandidateBondLessRequest.js.map +1 -1
- package/v1/data/staking/MoonbeamCandidateMetadata.js +21 -24
- package/v1/data/staking/MoonbeamCandidateMetadata.js.map +1 -1
- package/v1/data/staking/MoonbeamDelegationScheduledRequests.js +62 -107
- package/v1/data/staking/MoonbeamDelegationScheduledRequests.js.map +1 -1
- package/v1/data/staking/MoonbeamDelegator.js +48 -90
- package/v1/data/staking/MoonbeamDelegator.js.map +1 -1
- package/v1/data/staking/MoonbeamRoundInfo.js +11 -12
- package/v1/data/staking/MoonbeamRoundInfo.js.map +1 -1
- package/v1/data/staking/MoonbeamStakingActionType.js +1 -1
- package/v1/data/staking/MoonbeamStakingActionType.js.map +1 -1
- package/v1/data/transaction/method/args.js +160 -293
- package/v1/data/transaction/method/args.js.map +1 -1
- package/v1/data/transaction/transaction.js +12 -23
- package/v1/data/transaction/transaction.js.map +1 -1
- package/v1/index.js +5 -5
- package/v1/index.js.map +1 -1
- package/v1/module/MoonbeamModule.d.ts +1 -1
- package/v1/module/MoonbeamModule.js +40 -98
- package/v1/module/MoonbeamModule.js.map +1 -1
- package/v1/module.js +2 -3
- package/v1/module.js.map +1 -1
- package/v1/node/MoonbeamNodeClient.js +71 -222
- package/v1/node/MoonbeamNodeClient.js.map +1 -1
- package/v1/protocol/MoonbaseProtocol.js +18 -49
- package/v1/protocol/MoonbaseProtocol.js.map +1 -1
- package/v1/protocol/MoonbeamBaseProtocol.js +340 -625
- package/v1/protocol/MoonbeamBaseProtocol.js.map +1 -1
- package/v1/protocol/MoonbeamProtocol.js +20 -51
- package/v1/protocol/MoonbeamProtocol.js.map +1 -1
- package/v1/protocol/MoonriverProtocol.js +18 -49
- package/v1/protocol/MoonriverProtocol.js.map +1 -1
- package/v1/serializer/v3/schemas/converter/transaction-converter.js +5 -6
- package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -1
- package/v1/serializer/v3/serializer-companion.js +75 -154
- package/v1/serializer/v3/serializer-companion.js.map +1 -1
- package/v1/serializer/v3/validators/transaction-validator.js +3 -23
- package/v1/serializer/v3/validators/transaction-validator.js.map +1 -1
- package/v1/serializer/v3/validators/validators.js +1 -1
- package/v1/serializer/v3/validators/validators.js.map +1 -1
- package/v1/types/configuration.d.ts +1 -1
- package/v1/types/crypto.d.ts +1 -1
- package/v1/types/protocol.d.ts +3 -3
|
@@ -1,388 +1,210 @@
|
|
|
1
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
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
4
|
};
|
|
56
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
6
|
exports.MoonbeamAccountController = void 0;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return
|
|
7
|
+
const coinlib_core_1 = require("@airgap/coinlib-core");
|
|
8
|
+
const bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
|
|
9
|
+
const errors_1 = require("@airgap/coinlib-core/errors");
|
|
10
|
+
const array_1 = require("@airgap/coinlib-core/utils/array");
|
|
11
|
+
const v1_1 = require("@airgap/substrate/v1");
|
|
12
|
+
const MoonbeamCandidateMetadata_1 = require("../data/staking/MoonbeamCandidateMetadata");
|
|
13
|
+
const MoonbeamDelegationScheduledRequests_1 = require("../data/staking/MoonbeamDelegationScheduledRequests");
|
|
14
|
+
const MoonbeamDelegator_1 = require("../data/staking/MoonbeamDelegator");
|
|
15
|
+
const MoonbeamStakingActionType_1 = require("../data/staking/MoonbeamStakingActionType");
|
|
16
|
+
class MoonbeamAccountController extends v1_1.SubstrateCommonAccountController {
|
|
17
|
+
async isDelegating(accountId) {
|
|
18
|
+
const delegatorState = await this.nodeClient.getDelegatorState(v1_1.SubstrateEthAddress.from(accountId));
|
|
19
|
+
return delegatorState ? delegatorState.delegations.elements.length > 0 : false;
|
|
71
20
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
return [2 /*return*/, {
|
|
194
|
-
address: address.asString(),
|
|
195
|
-
status: status,
|
|
196
|
-
minEligibleBalance: candidateInfo.lowestTopDelegationAmount.toString(),
|
|
197
|
-
ownStakingBalance: candidateInfo.bond.toString(),
|
|
198
|
-
totalStakingBalance: candidateInfo.totalCounted.toString(),
|
|
199
|
-
commission: commission.dividedBy(1000000000).toString(),
|
|
200
|
-
delegators: candidateInfo.delegationCount.toNumber()
|
|
201
|
-
}];
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
};
|
|
206
|
-
MoonbeamAccountController.prototype.getDelegationDetails = function (accountId, collator) {
|
|
207
|
-
var _a, _b, _c, _d, _e;
|
|
208
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
209
|
-
var delegatorAddress, collatorAddress, results, balance, delegatorState, collatorDetails, delegationScheduledRequests, currentRound, bond, totalBond, status, delegatorDetails, changeRequest;
|
|
210
|
-
var _f;
|
|
211
|
-
return __generator(this, function (_g) {
|
|
212
|
-
switch (_g.label) {
|
|
213
|
-
case 0:
|
|
214
|
-
delegatorAddress = v1_1.SubstrateEthAddress.from(accountId);
|
|
215
|
-
collatorAddress = v1_1.SubstrateEthAddress.from(collator);
|
|
216
|
-
return [4 /*yield*/, Promise.all([
|
|
217
|
-
this.getBalance(delegatorAddress),
|
|
218
|
-
this.nodeClient.getDelegatorState(delegatorAddress),
|
|
219
|
-
this.getCollatorDetails(collator),
|
|
220
|
-
this.nodeClient.getDelegationScheduledRequests(collatorAddress),
|
|
221
|
-
this.nodeClient.getRound()
|
|
222
|
-
])];
|
|
223
|
-
case 1:
|
|
224
|
-
results = _g.sent();
|
|
225
|
-
balance = results[0];
|
|
226
|
-
delegatorState = results[1];
|
|
227
|
-
collatorDetails = results[2];
|
|
228
|
-
delegationScheduledRequests = results[3];
|
|
229
|
-
currentRound = (_a = results[4]) === null || _a === void 0 ? void 0 : _a.current;
|
|
230
|
-
if (!balance || !collatorDetails) {
|
|
231
|
-
return [2 /*return*/, Promise.reject('Could not fetch delegation details.')];
|
|
232
|
-
}
|
|
233
|
-
bond = (_c = (_b = delegatorState === null || delegatorState === void 0 ? void 0 : delegatorState.delegations.elements.find(function (bond) { return bond.owner.compare(collator) === 0; })) === null || _b === void 0 ? void 0 : _b.amount.value) !== null && _c !== void 0 ? _c : new bignumber_1.default(0);
|
|
234
|
-
totalBond = (_d = delegatorState === null || delegatorState === void 0 ? void 0 : delegatorState.total.value) !== null && _d !== void 0 ? _d : new bignumber_1.default(0);
|
|
235
|
-
switch (delegatorState === null || delegatorState === void 0 ? void 0 : delegatorState.status.type.value) {
|
|
236
|
-
case MoonbeamDelegator_1.MoonbeamDelegatorStatusRaw.ACTIVE:
|
|
237
|
-
status = 'Active';
|
|
238
|
-
break;
|
|
239
|
-
case MoonbeamDelegator_1.MoonbeamDelegatorStatusRaw.LEAVING:
|
|
240
|
-
status = (currentRound === null || currentRound === void 0 ? void 0 : currentRound.gte(delegatorState.status.roundIndex)) ? 'ReadyToLeave' : 'Leaving';
|
|
241
|
-
break;
|
|
242
|
-
}
|
|
243
|
-
_f = {
|
|
244
|
-
address: delegatorAddress.asString(),
|
|
245
|
-
balance: balance.total.toString(),
|
|
246
|
-
totalBond: totalBond.toString(),
|
|
247
|
-
delegatees: (_e = delegatorState === null || delegatorState === void 0 ? void 0 : delegatorState.delegations.elements.map(function (bond) { return bond.owner.asAddress(); })) !== null && _e !== void 0 ? _e : []
|
|
248
|
-
};
|
|
249
|
-
return [4 /*yield*/, this.getStakingActions(delegatorState, collatorDetails, delegationScheduledRequests)];
|
|
250
|
-
case 2:
|
|
251
|
-
delegatorDetails = (_f.availableActions = _g.sent(),
|
|
252
|
-
_f.status = status,
|
|
253
|
-
_f);
|
|
254
|
-
changeRequest = delegationScheduledRequests === null || delegationScheduledRequests === void 0 ? void 0 : delegationScheduledRequests.requests.elements.find(function (request) { return request.delegator.asAddress() === delegatorDetails.address; });
|
|
255
|
-
return [2 /*return*/, {
|
|
256
|
-
delegatorDetails: delegatorDetails,
|
|
257
|
-
collatorDetails: collatorDetails,
|
|
258
|
-
bond: bond.toString(),
|
|
259
|
-
pendingRequest: changeRequest
|
|
260
|
-
? {
|
|
261
|
-
type: changeRequest.action.type.value === MoonbeamDelegationScheduledRequests_1.MoonbeamDelegationActionRaw.REVOKE ? 'revoke' : 'decrease',
|
|
262
|
-
amount: changeRequest.action.amount.toString(),
|
|
263
|
-
executableIn: currentRound
|
|
264
|
-
? bignumber_1.default.max(changeRequest.whenExecutable.value.minus(currentRound.value), 0).toNumber()
|
|
265
|
-
: undefined
|
|
266
|
-
}
|
|
267
|
-
: undefined
|
|
268
|
-
}];
|
|
269
|
-
}
|
|
270
|
-
});
|
|
271
|
-
});
|
|
272
|
-
};
|
|
273
|
-
MoonbeamAccountController.prototype.getStakingActions = function (delegator, collator, delegationScheduledRequests) {
|
|
274
|
-
var _a, _b;
|
|
275
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
276
|
-
var actions, scheduledLeaving, _c, scheduledRequests, delegations, maxDelegations, canDelegateToCollator, isDelegatingCollator, currentRound, _d, _e, _f, _g, _h, _j, _k;
|
|
277
|
-
return __generator(this, function (_l) {
|
|
278
|
-
switch (_l.label) {
|
|
279
|
-
case 0:
|
|
280
|
-
actions = [];
|
|
281
|
-
if (!delegator) return [3 /*break*/, 2];
|
|
282
|
-
return [4 /*yield*/, this.getScheduledLeaving(delegator)];
|
|
283
|
-
case 1:
|
|
284
|
-
_c = _l.sent();
|
|
285
|
-
return [3 /*break*/, 3];
|
|
286
|
-
case 2:
|
|
287
|
-
_c = undefined;
|
|
288
|
-
_l.label = 3;
|
|
289
|
-
case 3:
|
|
290
|
-
scheduledLeaving = _c;
|
|
291
|
-
scheduledRequests = delegationScheduledRequests
|
|
292
|
-
? delegator && collator
|
|
293
|
-
? delegationScheduledRequests.requests.elements.filter(function (value) { return value.delegator.asAddress() === delegator.id.asAddress(); })
|
|
294
|
-
: []
|
|
295
|
-
: undefined;
|
|
296
|
-
delegations = (_a = delegator === null || delegator === void 0 ? void 0 : delegator.delegations.elements) !== null && _a !== void 0 ? _a : [];
|
|
297
|
-
return [4 /*yield*/, this.nodeClient.getMaxDelegationsPerDelegator()];
|
|
298
|
-
case 4:
|
|
299
|
-
maxDelegations = _l.sent();
|
|
300
|
-
canDelegateToCollator = (maxDelegations === null || maxDelegations === void 0 ? void 0 : maxDelegations.gt(delegations.length)) && collator && !delegations.some(function (bond) { return bond.owner.compare(collator.address) === 0; });
|
|
301
|
-
isDelegatingCollator = !!collator && delegations.some(function (bond) { return bond.owner.compare(collator.address) === 0; });
|
|
302
|
-
if (!(scheduledLeaving || scheduledRequests)) return [3 /*break*/, 6];
|
|
303
|
-
return [4 /*yield*/, this.nodeClient.getRound()];
|
|
304
|
-
case 5:
|
|
305
|
-
_d = (_b = (_l.sent())) === null || _b === void 0 ? void 0 : _b.current.value;
|
|
306
|
-
return [3 /*break*/, 7];
|
|
307
|
-
case 6:
|
|
308
|
-
_d = undefined;
|
|
309
|
-
_l.label = 7;
|
|
310
|
-
case 7:
|
|
311
|
-
currentRound = _d;
|
|
312
|
-
if (canDelegateToCollator && !scheduledLeaving && (scheduledRequests === null || scheduledRequests === void 0 ? void 0 : scheduledRequests.length) === 0) {
|
|
313
|
-
actions.push.apply(actions, this.getUndelegatedActions());
|
|
314
|
-
}
|
|
315
|
-
if (delegations.length > 0 && !scheduledLeaving && (scheduledRequests === null || scheduledRequests === void 0 ? void 0 : scheduledRequests.length) === 0) {
|
|
316
|
-
actions.push.apply(actions, this.getDelegatedActions(isDelegatingCollator));
|
|
317
|
-
}
|
|
318
|
-
if (!(scheduledLeaving && currentRound)) return [3 /*break*/, 9];
|
|
319
|
-
_f = (_e = actions.push).apply;
|
|
320
|
-
_g = [actions];
|
|
321
|
-
return [4 /*yield*/, this.getLeavingActions(currentRound, scheduledLeaving)];
|
|
322
|
-
case 8:
|
|
323
|
-
_f.apply(_e, _g.concat([(_l.sent())]));
|
|
324
|
-
_l.label = 9;
|
|
325
|
-
case 9:
|
|
326
|
-
if (!(scheduledRequests && scheduledRequests.length > 0 && currentRound)) return [3 /*break*/, 11];
|
|
327
|
-
_j = (_h = actions.push).apply;
|
|
328
|
-
_k = [actions];
|
|
329
|
-
return [4 /*yield*/, this.getRequestActions(currentRound, scheduledRequests)];
|
|
330
|
-
case 10:
|
|
331
|
-
_j.apply(_h, _k.concat([(_l.sent())]));
|
|
332
|
-
_l.label = 11;
|
|
333
|
-
case 11: return [2 /*return*/, actions];
|
|
334
|
-
}
|
|
335
|
-
});
|
|
336
|
-
});
|
|
337
|
-
};
|
|
338
|
-
MoonbeamAccountController.prototype.getScheduledLeaving = function (delegator) {
|
|
339
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
340
|
-
var allDelegationScheduledRequests;
|
|
341
|
-
var _this = this;
|
|
342
|
-
return __generator(this, function (_a) {
|
|
343
|
-
switch (_a.label) {
|
|
344
|
-
case 0:
|
|
345
|
-
if (delegator.status instanceof MoonbeamDelegator_1.MoonbeamDelegatorStatusLeaving) {
|
|
346
|
-
return [2 /*return*/, delegator.status.roundIndex.value];
|
|
347
|
-
}
|
|
348
|
-
return [4 /*yield*/, Promise.all(delegator.delegations.elements.map(function (bond) {
|
|
349
|
-
var collator = v1_1.SubstrateEthAddress.from(bond.owner.address);
|
|
350
|
-
return _this.nodeClient.getDelegationScheduledRequests(collator);
|
|
351
|
-
}))];
|
|
352
|
-
case 1:
|
|
353
|
-
allDelegationScheduledRequests = _a.sent();
|
|
354
|
-
return [2 /*return*/, allDelegationScheduledRequests.reduce(function (acc, requests) {
|
|
355
|
-
var _a;
|
|
356
|
-
if (acc === undefined) {
|
|
357
|
-
return undefined;
|
|
358
|
-
}
|
|
359
|
-
var whenExecutable = (_a = requests === null || requests === void 0 ? void 0 : requests.requests.elements.find(function (request) {
|
|
360
|
-
request.delegator.asAddress() === delegator.id.asAddress() && request.action.type.value === MoonbeamDelegationScheduledRequests_1.MoonbeamDelegationActionRaw.REVOKE;
|
|
361
|
-
})) === null || _a === void 0 ? void 0 : _a.whenExecutable.value;
|
|
362
|
-
if (whenExecutable === undefined) {
|
|
363
|
-
return undefined;
|
|
364
|
-
}
|
|
365
|
-
if (acc.eq(whenExecutable) || acc.eq(-1)) {
|
|
366
|
-
return whenExecutable;
|
|
367
|
-
}
|
|
368
|
-
else {
|
|
369
|
-
return undefined;
|
|
370
|
-
}
|
|
371
|
-
}, new bignumber_1.default(-1))];
|
|
21
|
+
async getMinDelegationAmount(accountId) {
|
|
22
|
+
const isDelegating = await this.isDelegating(accountId);
|
|
23
|
+
const minAmount = isDelegating ? await this.nodeClient.getMinDelegation() : await this.nodeClient.getMinDelegatorStake();
|
|
24
|
+
if (!minAmount) {
|
|
25
|
+
throw new errors_1.OperationFailedError(coinlib_core_1.Domain.SUBSTRATE, 'Could not fetch network constants');
|
|
26
|
+
}
|
|
27
|
+
return minAmount.toFixed();
|
|
28
|
+
}
|
|
29
|
+
async getCurrentCollators(accountId) {
|
|
30
|
+
const delegatorState = await this.nodeClient.getDelegatorState(v1_1.SubstrateEthAddress.from(accountId));
|
|
31
|
+
if (delegatorState) {
|
|
32
|
+
return delegatorState.delegations.elements.map((collatorDetails) => collatorDetails.owner.asAddress());
|
|
33
|
+
}
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
async getDelegatorDetails(accountId) {
|
|
37
|
+
const address = v1_1.SubstrateEthAddress.from(accountId);
|
|
38
|
+
const results = await Promise.all([this.getBalance(address), this.nodeClient.getDelegatorState(address)]);
|
|
39
|
+
const balance = results[0];
|
|
40
|
+
const delegatorState = results[1];
|
|
41
|
+
if (!balance) {
|
|
42
|
+
return Promise.reject('Could not fetch delegator details.');
|
|
43
|
+
}
|
|
44
|
+
const totalBond = delegatorState?.total.value ?? new bignumber_1.default(0);
|
|
45
|
+
let status;
|
|
46
|
+
switch (delegatorState?.status.type.value) {
|
|
47
|
+
case MoonbeamDelegator_1.MoonbeamDelegatorStatusRaw.ACTIVE:
|
|
48
|
+
status = 'Active';
|
|
49
|
+
break;
|
|
50
|
+
case MoonbeamDelegator_1.MoonbeamDelegatorStatusRaw.LEAVING:
|
|
51
|
+
status = 'Leaving';
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
address: address.asString(),
|
|
56
|
+
balance: balance.total.toString(),
|
|
57
|
+
totalBond: totalBond.toString(),
|
|
58
|
+
delegatees: delegatorState?.delegations.elements.map((bond) => bond.owner.asAddress()) ?? [],
|
|
59
|
+
availableActions: await this.getStakingActions(delegatorState),
|
|
60
|
+
status
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
async getCollatorDetails(accountId) {
|
|
64
|
+
const address = v1_1.SubstrateEthAddress.from(accountId);
|
|
65
|
+
const results = await Promise.all([this.nodeClient.getCandidateInfo(address), this.nodeClient.getCollatorCommission()]);
|
|
66
|
+
const candidateInfo = results[0];
|
|
67
|
+
const commission = results[1];
|
|
68
|
+
if (!candidateInfo || !commission) {
|
|
69
|
+
return Promise.reject('Could not fetch collator details.');
|
|
70
|
+
}
|
|
71
|
+
let status;
|
|
72
|
+
switch (candidateInfo.status.value) {
|
|
73
|
+
case MoonbeamCandidateMetadata_1.MoonbeamCollatorStatus.ACTIVE:
|
|
74
|
+
status = 'Active';
|
|
75
|
+
break;
|
|
76
|
+
case MoonbeamCandidateMetadata_1.MoonbeamCollatorStatus.IDLE:
|
|
77
|
+
status = 'Idle';
|
|
78
|
+
break;
|
|
79
|
+
case MoonbeamCandidateMetadata_1.MoonbeamCollatorStatus.LEAVING:
|
|
80
|
+
status = 'Leaving';
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
address: address.asString(),
|
|
84
|
+
status,
|
|
85
|
+
minEligibleBalance: candidateInfo.lowestTopDelegationAmount.toString(),
|
|
86
|
+
ownStakingBalance: candidateInfo.bond.toString(),
|
|
87
|
+
totalStakingBalance: candidateInfo.totalCounted.toString(),
|
|
88
|
+
commission: commission.dividedBy(1_000_000_000).toString(), // commission is Perbill (parts per billion)
|
|
89
|
+
delegators: candidateInfo.delegationCount.toNumber()
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
async getDelegationDetails(accountId, collator) {
|
|
93
|
+
const delegatorAddress = v1_1.SubstrateEthAddress.from(accountId);
|
|
94
|
+
const collatorAddress = v1_1.SubstrateEthAddress.from(collator);
|
|
95
|
+
const results = await Promise.all([
|
|
96
|
+
this.getBalance(delegatorAddress),
|
|
97
|
+
this.nodeClient.getDelegatorState(delegatorAddress),
|
|
98
|
+
this.getCollatorDetails(collator),
|
|
99
|
+
this.nodeClient.getDelegationScheduledRequests(collatorAddress),
|
|
100
|
+
this.nodeClient.getRound()
|
|
101
|
+
]);
|
|
102
|
+
const balance = results[0];
|
|
103
|
+
const delegatorState = results[1];
|
|
104
|
+
const collatorDetails = results[2];
|
|
105
|
+
const delegationScheduledRequests = results[3];
|
|
106
|
+
const currentRound = results[4]?.current;
|
|
107
|
+
if (!balance || !collatorDetails) {
|
|
108
|
+
return Promise.reject('Could not fetch delegation details.');
|
|
109
|
+
}
|
|
110
|
+
const bond = delegatorState?.delegations.elements.find((bond) => bond.owner.compare(collator) === 0)?.amount.value ?? new bignumber_1.default(0);
|
|
111
|
+
const totalBond = delegatorState?.total.value ?? new bignumber_1.default(0);
|
|
112
|
+
let status;
|
|
113
|
+
switch (delegatorState?.status.type.value) {
|
|
114
|
+
case MoonbeamDelegator_1.MoonbeamDelegatorStatusRaw.ACTIVE:
|
|
115
|
+
status = 'Active';
|
|
116
|
+
break;
|
|
117
|
+
case MoonbeamDelegator_1.MoonbeamDelegatorStatusRaw.LEAVING:
|
|
118
|
+
status = currentRound?.gte(delegatorState.status.roundIndex) ? 'ReadyToLeave' : 'Leaving';
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
const delegatorDetails = {
|
|
122
|
+
address: delegatorAddress.asString(),
|
|
123
|
+
balance: balance.total.toString(),
|
|
124
|
+
totalBond: totalBond.toString(),
|
|
125
|
+
delegatees: delegatorState?.delegations.elements.map((bond) => bond.owner.asAddress()) ?? [],
|
|
126
|
+
availableActions: await this.getStakingActions(delegatorState, collatorDetails, delegationScheduledRequests),
|
|
127
|
+
status
|
|
128
|
+
};
|
|
129
|
+
const changeRequest = delegationScheduledRequests?.requests.elements.find((request) => request.delegator.asAddress() === delegatorDetails.address);
|
|
130
|
+
return {
|
|
131
|
+
delegatorDetails,
|
|
132
|
+
collatorDetails,
|
|
133
|
+
bond: bond.toString(),
|
|
134
|
+
pendingRequest: changeRequest
|
|
135
|
+
? {
|
|
136
|
+
type: changeRequest.action.type.value === MoonbeamDelegationScheduledRequests_1.MoonbeamDelegationActionRaw.REVOKE ? 'revoke' : 'decrease',
|
|
137
|
+
amount: changeRequest.action.amount.toString(),
|
|
138
|
+
executableIn: currentRound
|
|
139
|
+
? bignumber_1.default.max(changeRequest.whenExecutable.value.minus(currentRound.value), 0).toNumber()
|
|
140
|
+
: undefined
|
|
372
141
|
}
|
|
373
|
-
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
|
|
142
|
+
: undefined
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
async getStakingActions(delegator, collator, delegationScheduledRequests) {
|
|
146
|
+
const actions = [];
|
|
147
|
+
const scheduledLeaving = delegator ? await this.getScheduledLeaving(delegator) : undefined;
|
|
148
|
+
const scheduledRequests = delegationScheduledRequests
|
|
149
|
+
? delegator && collator
|
|
150
|
+
? delegationScheduledRequests.requests.elements.filter((value) => value.delegator.asAddress() === delegator.id.asAddress())
|
|
151
|
+
: []
|
|
152
|
+
: undefined;
|
|
153
|
+
const delegations = delegator?.delegations.elements ?? [];
|
|
154
|
+
const maxDelegations = await this.nodeClient.getMaxDelegationsPerDelegator();
|
|
155
|
+
const canDelegateToCollator = maxDelegations?.gt(delegations.length) && collator && !delegations.some((bond) => bond.owner.compare(collator.address) === 0);
|
|
156
|
+
const isDelegatingCollator = !!collator && delegations.some((bond) => bond.owner.compare(collator.address) === 0);
|
|
157
|
+
const currentRound = scheduledLeaving || scheduledRequests ? (await this.nodeClient.getRound())?.current.value : undefined;
|
|
158
|
+
if (canDelegateToCollator && !scheduledLeaving && scheduledRequests?.length === 0) {
|
|
159
|
+
actions.push(...this.getUndelegatedActions());
|
|
160
|
+
}
|
|
161
|
+
if (delegations.length > 0 && !scheduledLeaving && scheduledRequests?.length === 0) {
|
|
162
|
+
actions.push(...this.getDelegatedActions(isDelegatingCollator));
|
|
163
|
+
}
|
|
164
|
+
if (scheduledLeaving && currentRound) {
|
|
165
|
+
actions.push(...(await this.getLeavingActions(currentRound, scheduledLeaving)));
|
|
166
|
+
}
|
|
167
|
+
if (scheduledRequests && scheduledRequests.length > 0 && currentRound) {
|
|
168
|
+
actions.push(...(await this.getRequestActions(currentRound, scheduledRequests)));
|
|
169
|
+
}
|
|
170
|
+
return actions;
|
|
171
|
+
}
|
|
172
|
+
async getScheduledLeaving(delegator) {
|
|
173
|
+
if (delegator.status instanceof MoonbeamDelegator_1.MoonbeamDelegatorStatusLeaving) {
|
|
174
|
+
return delegator.status.roundIndex.value;
|
|
175
|
+
}
|
|
176
|
+
const allDelegationScheduledRequests = await Promise.all(delegator.delegations.elements.map((bond) => {
|
|
177
|
+
const collator = v1_1.SubstrateEthAddress.from(bond.owner.address);
|
|
178
|
+
return this.nodeClient.getDelegationScheduledRequests(collator);
|
|
179
|
+
}));
|
|
180
|
+
return allDelegationScheduledRequests.reduce((acc, requests) => {
|
|
181
|
+
if (acc === undefined) {
|
|
182
|
+
return undefined;
|
|
183
|
+
}
|
|
184
|
+
const whenExecutable = requests?.requests.elements.find((request) => {
|
|
185
|
+
request.delegator.asAddress() === delegator.id.asAddress() && request.action.type.value === MoonbeamDelegationScheduledRequests_1.MoonbeamDelegationActionRaw.REVOKE;
|
|
186
|
+
})?.whenExecutable.value;
|
|
187
|
+
if (whenExecutable === undefined) {
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
190
|
+
if (acc.eq(whenExecutable) || acc.eq(-1)) {
|
|
191
|
+
return whenExecutable;
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
}, new bignumber_1.default(-1));
|
|
197
|
+
}
|
|
198
|
+
getUndelegatedActions() {
|
|
377
199
|
return [
|
|
378
200
|
{
|
|
379
201
|
type: MoonbeamStakingActionType_1.MoonbeamStakingActionType.DELEGATE,
|
|
380
202
|
args: ['candidate', 'amount']
|
|
381
203
|
}
|
|
382
204
|
];
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
|
|
205
|
+
}
|
|
206
|
+
getDelegatedActions(isDelegatingCollator) {
|
|
207
|
+
const actions = [];
|
|
386
208
|
actions.push({
|
|
387
209
|
type: MoonbeamStakingActionType_1.MoonbeamStakingActionType.SCHEDULE_UNDELEGATE_ALL
|
|
388
210
|
});
|
|
@@ -399,96 +221,70 @@ var MoonbeamAccountController = /** @class */ (function (_super) {
|
|
|
399
221
|
});
|
|
400
222
|
}
|
|
401
223
|
return actions;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
return
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
{
|
|
409
|
-
type: MoonbeamStakingActionType_1.MoonbeamStakingActionType.EXECUTE_UNDELEGATE_ALL
|
|
410
|
-
}
|
|
411
|
-
]];
|
|
412
|
-
}
|
|
413
|
-
else {
|
|
414
|
-
return [2 /*return*/, [
|
|
415
|
-
{
|
|
416
|
-
type: MoonbeamStakingActionType_1.MoonbeamStakingActionType.CANCEL_UNDELEGATE_ALL
|
|
417
|
-
}
|
|
418
|
-
]];
|
|
224
|
+
}
|
|
225
|
+
async getLeavingActions(currentRound, scheduledLeaving) {
|
|
226
|
+
if (currentRound.gte(scheduledLeaving)) {
|
|
227
|
+
return [
|
|
228
|
+
{
|
|
229
|
+
type: MoonbeamStakingActionType_1.MoonbeamStakingActionType.EXECUTE_UNDELEGATE_ALL
|
|
419
230
|
}
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
var actions;
|
|
427
|
-
var _this = this;
|
|
428
|
-
return __generator(this, function (_a) {
|
|
429
|
-
switch (_a.label) {
|
|
430
|
-
case 0: return [4 /*yield*/, Promise.all(scheduledRequests.map(function (request) {
|
|
431
|
-
if (request.action.type.value === MoonbeamDelegationScheduledRequests_1.MoonbeamDelegationActionRaw.REVOKE) {
|
|
432
|
-
return _this.getRevokeRequestActions(currentRound, request);
|
|
433
|
-
}
|
|
434
|
-
if (request.action.type.value === MoonbeamDelegationScheduledRequests_1.MoonbeamDelegationActionRaw.DECREASE) {
|
|
435
|
-
return _this.getDecreaseRequestActions(currentRound, request);
|
|
436
|
-
}
|
|
437
|
-
return [];
|
|
438
|
-
}))];
|
|
439
|
-
case 1:
|
|
440
|
-
actions = _a.sent();
|
|
441
|
-
return [2 /*return*/, (0, array_1.flattenArray)(actions)];
|
|
231
|
+
];
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
return [
|
|
235
|
+
{
|
|
236
|
+
type: MoonbeamStakingActionType_1.MoonbeamStakingActionType.CANCEL_UNDELEGATE_ALL
|
|
442
237
|
}
|
|
443
|
-
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
238
|
+
];
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
async getRequestActions(currentRound, scheduledRequests) {
|
|
242
|
+
const actions = await Promise.all(scheduledRequests.map((request) => {
|
|
243
|
+
if (request.action.type.value === MoonbeamDelegationScheduledRequests_1.MoonbeamDelegationActionRaw.REVOKE) {
|
|
244
|
+
return this.getRevokeRequestActions(currentRound, request);
|
|
245
|
+
}
|
|
246
|
+
if (request.action.type.value === MoonbeamDelegationScheduledRequests_1.MoonbeamDelegationActionRaw.DECREASE) {
|
|
247
|
+
return this.getDecreaseRequestActions(currentRound, request);
|
|
248
|
+
}
|
|
249
|
+
return [];
|
|
250
|
+
}));
|
|
251
|
+
return (0, array_1.flattenArray)(actions);
|
|
252
|
+
}
|
|
253
|
+
async getRevokeRequestActions(currentRound, scheduledRequest) {
|
|
254
|
+
if (currentRound.gte(scheduledRequest.whenExecutable.value)) {
|
|
255
|
+
return [
|
|
256
|
+
{
|
|
257
|
+
type: MoonbeamStakingActionType_1.MoonbeamStakingActionType.EXECUTE_UNDELEGATE,
|
|
258
|
+
args: ['candidate']
|
|
456
259
|
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
260
|
+
];
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
return [
|
|
264
|
+
{
|
|
265
|
+
type: MoonbeamStakingActionType_1.MoonbeamStakingActionType.CANCEL_UNDELEGATE,
|
|
266
|
+
args: ['candidate']
|
|
464
267
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
{
|
|
475
|
-
type: MoonbeamStakingActionType_1.MoonbeamStakingActionType.EXECUTE_BOND_LESS,
|
|
476
|
-
args: ['candidate']
|
|
477
|
-
}
|
|
478
|
-
]];
|
|
268
|
+
];
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
async getDecreaseRequestActions(currentRound, scheduledRequest) {
|
|
272
|
+
if (currentRound.gte(scheduledRequest.whenExecutable.value)) {
|
|
273
|
+
return [
|
|
274
|
+
{
|
|
275
|
+
type: MoonbeamStakingActionType_1.MoonbeamStakingActionType.EXECUTE_BOND_LESS,
|
|
276
|
+
args: ['candidate']
|
|
479
277
|
}
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
278
|
+
];
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
return [
|
|
282
|
+
{
|
|
283
|
+
type: MoonbeamStakingActionType_1.MoonbeamStakingActionType.CANCEL_BOND_LESS
|
|
486
284
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
return MoonbeamAccountController;
|
|
492
|
-
}(v1_1.SubstrateCommonAccountController));
|
|
285
|
+
];
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
493
289
|
exports.MoonbeamAccountController = MoonbeamAccountController;
|
|
494
290
|
//# sourceMappingURL=MoonbeamAccountController.js.map
|