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