@airgap/moonbeam 0.13.45-beta.2 → 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,649 +1,364 @@
|
|
|
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.MoonbeamBaseProtocolImpl = void 0;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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 assert_1 = require("@airgap/coinlib-core/utils/assert");
|
|
11
|
+
const module_kit_1 = require("@airgap/module-kit");
|
|
12
|
+
const v1_1 = require("@airgap/substrate/v1");
|
|
13
|
+
const MoonbeamAccountController_1 = require("../controller/MoonbeamAccountController");
|
|
14
|
+
const MoonbeamTransactionController_1 = require("../controller/MoonbeamTransactionController");
|
|
15
|
+
const MoonbeamStakingActionType_1 = require("../data/staking/MoonbeamStakingActionType");
|
|
16
|
+
const MoonbeamNodeClient_1 = require("../node/MoonbeamNodeClient");
|
|
68
17
|
// Implementation
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
_this = _super.call(this, options, nodeClient, accountController, transactionController, blockExplorer) || this;
|
|
78
|
-
_this.defaultValidator = options.network.defaultValidator;
|
|
79
|
-
return _this;
|
|
18
|
+
class MoonbeamBaseProtocolImpl extends v1_1.SubstrateStakingProtocolImpl {
|
|
19
|
+
constructor(options) {
|
|
20
|
+
const nodeClient = new MoonbeamNodeClient_1.MoonbeamNodeClient(options.configuration, options.network.rpcUrl);
|
|
21
|
+
const accountController = new MoonbeamAccountController_1.MoonbeamAccountController(options.configuration, nodeClient);
|
|
22
|
+
const transactionController = new MoonbeamTransactionController_1.MoonbeamTransactionController(options.configuration, nodeClient);
|
|
23
|
+
const blockExplorer = new v1_1.SubscanBlockExplorerClient(options.network.blockExplorerApi);
|
|
24
|
+
super(options, nodeClient, accountController, transactionController, blockExplorer);
|
|
25
|
+
this.defaultValidator = options.network.defaultValidator;
|
|
80
26
|
}
|
|
81
27
|
// Staking
|
|
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
|
-
return
|
|
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
|
-
return
|
|
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
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
data = {};
|
|
199
|
-
}
|
|
200
|
-
switch (type) {
|
|
201
|
-
case MoonbeamStakingActionType_1.MoonbeamStakingActionType.DELEGATE:
|
|
202
|
-
(0, assert_1.assertFields)("".concat(type, " action"), data, 'candidate', 'amount');
|
|
203
|
-
return [2 /*return*/, this.prepareDelegation(publicKey, (_a = data.tip) !== null && _a !== void 0 ? _a : 0, data.candidate, data.amount)];
|
|
204
|
-
case MoonbeamStakingActionType_1.MoonbeamStakingActionType.BOND_MORE:
|
|
205
|
-
(0, assert_1.assertFields)("".concat(type, " action"), data, 'candidate', 'more');
|
|
206
|
-
return [2 /*return*/, this.prepareDelegatorBondMore(publicKey, (_b = data.tip) !== null && _b !== void 0 ? _b : 0, data.candidate, data.more)];
|
|
207
|
-
case MoonbeamStakingActionType_1.MoonbeamStakingActionType.SCHEDULE_BOND_LESS:
|
|
208
|
-
(0, assert_1.assertFields)("".concat(type, " action"), data, 'candidate', 'less');
|
|
209
|
-
return [2 /*return*/, this.prepareScheduleDelegatorBondLess(publicKey, (_c = data.tip) !== null && _c !== void 0 ? _c : 0, data.candidate, data.less)];
|
|
210
|
-
case MoonbeamStakingActionType_1.MoonbeamStakingActionType.EXECUTE_BOND_LESS:
|
|
211
|
-
(0, assert_1.assertFields)("".concat(type, " action"), data, 'candidate');
|
|
212
|
-
return [2 /*return*/, this.prepareExecuteDelegatorBondLess(publicKey, (_d = data.tip) !== null && _d !== void 0 ? _d : 0, data.candidate)];
|
|
213
|
-
case MoonbeamStakingActionType_1.MoonbeamStakingActionType.CANCEL_BOND_LESS:
|
|
214
|
-
(0, assert_1.assertFields)("".concat(type, " action"), data, 'candidate');
|
|
215
|
-
return [2 /*return*/, this.prepareCancelDelegatorBondLess(publicKey, (_e = data.tip) !== null && _e !== void 0 ? _e : 0, data.candidate)];
|
|
216
|
-
case MoonbeamStakingActionType_1.MoonbeamStakingActionType.SCHEDULE_UNDELEGATE:
|
|
217
|
-
(0, assert_1.assertFields)("".concat(type, " action"), data, 'collator');
|
|
218
|
-
return [2 /*return*/, this.prepareScheduleUndelegate(publicKey, (_f = data.tip) !== null && _f !== void 0 ? _f : 0, data.collator)];
|
|
219
|
-
case MoonbeamStakingActionType_1.MoonbeamStakingActionType.EXECUTE_UNDELEGATE:
|
|
220
|
-
(0, assert_1.assertFields)("".concat(type, " action"), data, 'candidate');
|
|
221
|
-
return [2 /*return*/, this.prepareExecuteUndelegate(publicKey, (_g = data.tip) !== null && _g !== void 0 ? _g : 0, data.candidate)];
|
|
222
|
-
case MoonbeamStakingActionType_1.MoonbeamStakingActionType.CANCEL_UNDELEGATE:
|
|
223
|
-
(0, assert_1.assertFields)("".concat(type, " action"), data, 'candidate');
|
|
224
|
-
return [2 /*return*/, this.prepareCancelUndelegate(publicKey, (_h = data.tip) !== null && _h !== void 0 ? _h : 0, data.candidate)];
|
|
225
|
-
case MoonbeamStakingActionType_1.MoonbeamStakingActionType.SCHEDULE_UNDELEGATE_ALL:
|
|
226
|
-
return [2 /*return*/, this.prepareScheduleUndelegateAll(publicKey, (_j = data.tip) !== null && _j !== void 0 ? _j : 0)];
|
|
227
|
-
case MoonbeamStakingActionType_1.MoonbeamStakingActionType.EXECUTE_UNDELEGATE_ALL:
|
|
228
|
-
return [2 /*return*/, this.prepareExecuteUndelegateAll(publicKey, (_k = data.tip) !== null && _k !== void 0 ? _k : 0)];
|
|
229
|
-
case MoonbeamStakingActionType_1.MoonbeamStakingActionType.CANCEL_UNDELEGATE_ALL:
|
|
230
|
-
return [2 /*return*/, this.prepareCancelUndelegateAll(publicKey, (_l = data.tip) !== null && _l !== void 0 ? _l : 0)];
|
|
231
|
-
default:
|
|
232
|
-
throw new errors_1.UnsupportedError(coinlib_core_1.Domain.SUBSTRATE, 'Unsupported delegator action.');
|
|
28
|
+
async getDefaultDelegatee() {
|
|
29
|
+
if (this.defaultValidator) {
|
|
30
|
+
return this.defaultValidator;
|
|
31
|
+
}
|
|
32
|
+
const collators = await this.nodeClient.getCollators();
|
|
33
|
+
return collators ? collators[0].asString() : '';
|
|
34
|
+
}
|
|
35
|
+
async getCurrentDelegateesForPublicKey(publicKey) {
|
|
36
|
+
return this.accountController.getCurrentCollators(publicKey);
|
|
37
|
+
}
|
|
38
|
+
async getCurrentDelegateesForAddress(address) {
|
|
39
|
+
return this.accountController.getCurrentCollators(address);
|
|
40
|
+
}
|
|
41
|
+
async getDelegateeDetails(address) {
|
|
42
|
+
const collatorDetails = await this.accountController.getCollatorDetails(address);
|
|
43
|
+
return {
|
|
44
|
+
name: collatorDetails.name ?? '',
|
|
45
|
+
status: collatorDetails.status ?? '',
|
|
46
|
+
address: collatorDetails.address
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
async isPublicKeyDelegating(publicKey) {
|
|
50
|
+
return this.accountController.isDelegating(publicKey);
|
|
51
|
+
}
|
|
52
|
+
async isAddressDelegating(address) {
|
|
53
|
+
return this.accountController.isDelegating(address);
|
|
54
|
+
}
|
|
55
|
+
async getDelegatorDetailsFromPublicKey(publicKey) {
|
|
56
|
+
return this.accountController.getDelegatorDetails(publicKey);
|
|
57
|
+
}
|
|
58
|
+
async getDelegatorDetailsFromAddress(address) {
|
|
59
|
+
return this.accountController.getDelegatorDetails(address);
|
|
60
|
+
}
|
|
61
|
+
async getDelegationDetailsFromPublicKey(publicKey, delegatees) {
|
|
62
|
+
const address = await this.getAddressFromPublicKey(publicKey);
|
|
63
|
+
return this.getDelegationDetailsFromAddress(address, delegatees);
|
|
64
|
+
}
|
|
65
|
+
async getDelegationDetailsFromAddress(address, delegatees) {
|
|
66
|
+
if (delegatees.length > 1) {
|
|
67
|
+
throw new errors_1.UnsupportedError(coinlib_core_1.Domain.SUBSTRATE, 'Multiple validators for a single delegation are not supported');
|
|
68
|
+
}
|
|
69
|
+
const collator = delegatees[0];
|
|
70
|
+
const delegationDetails = await this.accountController.getDelegationDetails(address, collator);
|
|
71
|
+
return {
|
|
72
|
+
delegator: delegationDetails.delegatorDetails,
|
|
73
|
+
delegatees: [delegationDetails.collatorDetails]
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
async prepareDelegatorActionFromPublicKey(publicKey, type, data) {
|
|
77
|
+
if (!data) {
|
|
78
|
+
data = {};
|
|
79
|
+
}
|
|
80
|
+
switch (type) {
|
|
81
|
+
case MoonbeamStakingActionType_1.MoonbeamStakingActionType.DELEGATE:
|
|
82
|
+
(0, assert_1.assertFields)(`${type} action`, data, 'candidate', 'amount');
|
|
83
|
+
return this.prepareDelegation(publicKey, data.tip ?? 0, data.candidate, data.amount);
|
|
84
|
+
case MoonbeamStakingActionType_1.MoonbeamStakingActionType.BOND_MORE:
|
|
85
|
+
(0, assert_1.assertFields)(`${type} action`, data, 'candidate', 'more');
|
|
86
|
+
return this.prepareDelegatorBondMore(publicKey, data.tip ?? 0, data.candidate, data.more);
|
|
87
|
+
case MoonbeamStakingActionType_1.MoonbeamStakingActionType.SCHEDULE_BOND_LESS:
|
|
88
|
+
(0, assert_1.assertFields)(`${type} action`, data, 'candidate', 'less');
|
|
89
|
+
return this.prepareScheduleDelegatorBondLess(publicKey, data.tip ?? 0, data.candidate, data.less);
|
|
90
|
+
case MoonbeamStakingActionType_1.MoonbeamStakingActionType.EXECUTE_BOND_LESS:
|
|
91
|
+
(0, assert_1.assertFields)(`${type} action`, data, 'candidate');
|
|
92
|
+
return this.prepareExecuteDelegatorBondLess(publicKey, data.tip ?? 0, data.candidate);
|
|
93
|
+
case MoonbeamStakingActionType_1.MoonbeamStakingActionType.CANCEL_BOND_LESS:
|
|
94
|
+
(0, assert_1.assertFields)(`${type} action`, data, 'candidate');
|
|
95
|
+
return this.prepareCancelDelegatorBondLess(publicKey, data.tip ?? 0, data.candidate);
|
|
96
|
+
case MoonbeamStakingActionType_1.MoonbeamStakingActionType.SCHEDULE_UNDELEGATE:
|
|
97
|
+
(0, assert_1.assertFields)(`${type} action`, data, 'collator');
|
|
98
|
+
return this.prepareScheduleUndelegate(publicKey, data.tip ?? 0, data.collator);
|
|
99
|
+
case MoonbeamStakingActionType_1.MoonbeamStakingActionType.EXECUTE_UNDELEGATE:
|
|
100
|
+
(0, assert_1.assertFields)(`${type} action`, data, 'candidate');
|
|
101
|
+
return this.prepareExecuteUndelegate(publicKey, data.tip ?? 0, data.candidate);
|
|
102
|
+
case MoonbeamStakingActionType_1.MoonbeamStakingActionType.CANCEL_UNDELEGATE:
|
|
103
|
+
(0, assert_1.assertFields)(`${type} action`, data, 'candidate');
|
|
104
|
+
return this.prepareCancelUndelegate(publicKey, data.tip ?? 0, data.candidate);
|
|
105
|
+
case MoonbeamStakingActionType_1.MoonbeamStakingActionType.SCHEDULE_UNDELEGATE_ALL:
|
|
106
|
+
return this.prepareScheduleUndelegateAll(publicKey, data.tip ?? 0);
|
|
107
|
+
case MoonbeamStakingActionType_1.MoonbeamStakingActionType.EXECUTE_UNDELEGATE_ALL:
|
|
108
|
+
return this.prepareExecuteUndelegateAll(publicKey, data.tip ?? 0);
|
|
109
|
+
case MoonbeamStakingActionType_1.MoonbeamStakingActionType.CANCEL_UNDELEGATE_ALL:
|
|
110
|
+
return this.prepareCancelUndelegateAll(publicKey, data.tip ?? 0);
|
|
111
|
+
default:
|
|
112
|
+
throw new errors_1.UnsupportedError(coinlib_core_1.Domain.SUBSTRATE, 'Unsupported delegator action.');
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
async prepareDelegation(publicKey, tip, candidate, amount) {
|
|
116
|
+
const requestedAmount = new bignumber_1.default(amount);
|
|
117
|
+
const minAmount = await this.accountController.getMinDelegationAmount(publicKey);
|
|
118
|
+
if (requestedAmount.lt(minAmount)) {
|
|
119
|
+
throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.SUBSTRATE, `The amount is too low, it has to be at least ${minAmount.toString()}`);
|
|
120
|
+
}
|
|
121
|
+
const results = await Promise.all([
|
|
122
|
+
this.accountController.getDelegatorDetails(publicKey),
|
|
123
|
+
this.accountController.getCollatorDetails(candidate),
|
|
124
|
+
this.nodeClient.getMaxDelegationsPerDelegator(),
|
|
125
|
+
this.getBalanceOfPublicKey(publicKey)
|
|
126
|
+
]);
|
|
127
|
+
const delegatorDetails = results[0];
|
|
128
|
+
const collatorDetails = results[1];
|
|
129
|
+
const maxDelegations = results[2];
|
|
130
|
+
const balance = results[3];
|
|
131
|
+
if (maxDelegations?.lte(delegatorDetails.delegatees.length)) {
|
|
132
|
+
throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.SUBSTRATE, 'This delegator cannot nominate more collators.');
|
|
133
|
+
}
|
|
134
|
+
const available = new bignumber_1.default((0, module_kit_1.newAmount)(balance.total).blockchain(this.metadata.units).value).minus(amount);
|
|
135
|
+
const encoded = await this.transactionController.prepareSubmittableTransactions(publicKey, available, [
|
|
136
|
+
{
|
|
137
|
+
type: 'delegate',
|
|
138
|
+
tip,
|
|
139
|
+
args: {
|
|
140
|
+
candidate,
|
|
141
|
+
amount: new bignumber_1.default(amount),
|
|
142
|
+
candidateDelegationCount: collatorDetails.delegators,
|
|
143
|
+
delegationCount: delegatorDetails.delegatees.length
|
|
233
144
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
case 1:
|
|
247
|
-
minAmount = _a.sent();
|
|
248
|
-
if (requestedAmount.lt(minAmount)) {
|
|
249
|
-
throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.SUBSTRATE, "The amount is too low, it has to be at least ".concat(minAmount.toString()));
|
|
250
|
-
}
|
|
251
|
-
return [4 /*yield*/, Promise.all([
|
|
252
|
-
this.accountController.getDelegatorDetails(publicKey),
|
|
253
|
-
this.accountController.getCollatorDetails(candidate),
|
|
254
|
-
this.nodeClient.getMaxDelegationsPerDelegator(),
|
|
255
|
-
this.getBalanceOfPublicKey(publicKey)
|
|
256
|
-
])];
|
|
257
|
-
case 2:
|
|
258
|
-
results = _a.sent();
|
|
259
|
-
delegatorDetails = results[0];
|
|
260
|
-
collatorDetails = results[1];
|
|
261
|
-
maxDelegations = results[2];
|
|
262
|
-
balance = results[3];
|
|
263
|
-
if (maxDelegations === null || maxDelegations === void 0 ? void 0 : maxDelegations.lte(delegatorDetails.delegatees.length)) {
|
|
264
|
-
throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.SUBSTRATE, 'This delegator cannot nominate more collators.');
|
|
265
|
-
}
|
|
266
|
-
available = new bignumber_1.default((0, module_kit_1.newAmount)(balance.total).blockchain(this.metadata.units).value).minus(amount);
|
|
267
|
-
return [4 /*yield*/, this.transactionController.prepareSubmittableTransactions(publicKey, available, [
|
|
268
|
-
{
|
|
269
|
-
type: 'delegate',
|
|
270
|
-
tip: tip,
|
|
271
|
-
args: {
|
|
272
|
-
candidate: candidate,
|
|
273
|
-
amount: new bignumber_1.default(amount),
|
|
274
|
-
candidateDelegationCount: collatorDetails.delegators,
|
|
275
|
-
delegationCount: delegatorDetails.delegatees.length
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
])];
|
|
279
|
-
case 3:
|
|
280
|
-
encoded = _a.sent();
|
|
281
|
-
return [2 /*return*/, [(0, module_kit_1.newUnsignedTransaction)({ encoded: encoded })]];
|
|
145
|
+
}
|
|
146
|
+
]);
|
|
147
|
+
return [(0, module_kit_1.newUnsignedTransaction)({ encoded })];
|
|
148
|
+
}
|
|
149
|
+
async prepareScheduleUndelegate(publicKey, tip, collator) {
|
|
150
|
+
const balance = await this.getBalanceOfPublicKey(publicKey);
|
|
151
|
+
const encoded = await this.transactionController.prepareSubmittableTransactions(publicKey, (0, module_kit_1.newAmount)(balance.total).blockchain(this.metadata.units).value, [
|
|
152
|
+
{
|
|
153
|
+
type: 'schedule_revoke_delegation',
|
|
154
|
+
tip,
|
|
155
|
+
args: {
|
|
156
|
+
collator
|
|
282
157
|
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
158
|
+
}
|
|
159
|
+
]);
|
|
160
|
+
return [(0, module_kit_1.newUnsignedTransaction)({ encoded })];
|
|
161
|
+
}
|
|
162
|
+
async prepareExecuteUndelegate(publicKey, tip, candidate) {
|
|
163
|
+
return this.prepareExecuteDelegationRequest(publicKey, tip, candidate);
|
|
164
|
+
}
|
|
165
|
+
async prepareCancelUndelegate(publicKey, tip, candidate) {
|
|
166
|
+
return this.prepareCancelDelegationRequest(publicKey, tip, candidate);
|
|
167
|
+
}
|
|
168
|
+
async prepareScheduleUndelegateAll(publicKey, tip) {
|
|
169
|
+
const balance = await this.getBalanceOfPublicKey(publicKey);
|
|
170
|
+
const encoded = await this.transactionController.prepareSubmittableTransactions(publicKey, (0, module_kit_1.newAmount)(balance.total).blockchain(this.metadata.units).value, [
|
|
171
|
+
{
|
|
172
|
+
type: 'schedule_leave_delegators',
|
|
173
|
+
tip,
|
|
174
|
+
args: {}
|
|
175
|
+
}
|
|
176
|
+
]);
|
|
177
|
+
return [(0, module_kit_1.newUnsignedTransaction)({ encoded })];
|
|
178
|
+
}
|
|
179
|
+
async prepareExecuteUndelegateAll(publicKey, tip) {
|
|
180
|
+
const results = await Promise.all([
|
|
181
|
+
this.accountController.getDelegatorDetails(publicKey),
|
|
182
|
+
this.getBalanceOfPublicKey(publicKey),
|
|
183
|
+
this.getAddressFromPublicKey(publicKey)
|
|
184
|
+
]);
|
|
185
|
+
const delegatorDetails = results[0];
|
|
186
|
+
const balance = results[1];
|
|
187
|
+
const delegator = results[2];
|
|
188
|
+
const encoded = await this.transactionController.prepareSubmittableTransactions(publicKey, (0, module_kit_1.newAmount)(balance.total).blockchain(this.metadata.units).value, [
|
|
189
|
+
{
|
|
190
|
+
type: 'execute_leave_delegators',
|
|
191
|
+
tip,
|
|
192
|
+
args: {
|
|
193
|
+
delegator,
|
|
194
|
+
delegationCount: delegatorDetails.delegatees.length
|
|
306
195
|
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
return [4 /*yield*/, this.transactionController.prepareSubmittableTransactions(publicKey, (0, module_kit_1.newAmount)(balance.total).blockchain(this.metadata.units).value, [
|
|
333
|
-
{
|
|
334
|
-
type: 'schedule_leave_delegators',
|
|
335
|
-
tip: tip,
|
|
336
|
-
args: {}
|
|
337
|
-
}
|
|
338
|
-
])];
|
|
339
|
-
case 2:
|
|
340
|
-
encoded = _a.sent();
|
|
341
|
-
return [2 /*return*/, [(0, module_kit_1.newUnsignedTransaction)({ encoded: encoded })]];
|
|
196
|
+
}
|
|
197
|
+
]);
|
|
198
|
+
return [(0, module_kit_1.newUnsignedTransaction)({ encoded })];
|
|
199
|
+
}
|
|
200
|
+
async prepareCancelUndelegateAll(publicKey, tip) {
|
|
201
|
+
const balance = await this.getBalanceOfPublicKey(publicKey);
|
|
202
|
+
const encoded = await this.transactionController.prepareSubmittableTransactions(publicKey, (0, module_kit_1.newAmount)(balance.total).blockchain(this.metadata.units).value, [
|
|
203
|
+
{
|
|
204
|
+
type: 'cancel_leave_delegators',
|
|
205
|
+
tip,
|
|
206
|
+
args: {}
|
|
207
|
+
}
|
|
208
|
+
]);
|
|
209
|
+
return [(0, module_kit_1.newUnsignedTransaction)({ encoded })];
|
|
210
|
+
}
|
|
211
|
+
async prepareDelegatorBondMore(publicKey, tip, candidate, more) {
|
|
212
|
+
const balance = await this.getBalanceOfPublicKey(publicKey);
|
|
213
|
+
const available = new bignumber_1.default((0, module_kit_1.newAmount)(balance.total).blockchain(this.metadata.units).value).minus(more);
|
|
214
|
+
const encoded = await this.transactionController.prepareSubmittableTransactions(publicKey, available, [
|
|
215
|
+
{
|
|
216
|
+
type: 'delegator_bond_more',
|
|
217
|
+
tip,
|
|
218
|
+
args: {
|
|
219
|
+
candidate,
|
|
220
|
+
more: new bignumber_1.default(more)
|
|
342
221
|
}
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
delegationCount: delegatorDetails.delegatees.length
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
])];
|
|
371
|
-
case 2:
|
|
372
|
-
encoded = _a.sent();
|
|
373
|
-
return [2 /*return*/, [(0, module_kit_1.newUnsignedTransaction)({ encoded: encoded })]];
|
|
222
|
+
}
|
|
223
|
+
]);
|
|
224
|
+
return [(0, module_kit_1.newUnsignedTransaction)({ encoded })];
|
|
225
|
+
}
|
|
226
|
+
async prepareScheduleDelegatorBondLess(publicKey, tip, candidate, less) {
|
|
227
|
+
const [balance, delegationDetails] = await Promise.all([
|
|
228
|
+
this.getBalanceOfPublicKey(publicKey),
|
|
229
|
+
this.accountController.getDelegationDetails(publicKey, candidate)
|
|
230
|
+
]);
|
|
231
|
+
const bondAmount = new bignumber_1.default(delegationDetails.bond);
|
|
232
|
+
const requestedAmount = new bignumber_1.default(less);
|
|
233
|
+
if (requestedAmount.gt(bondAmount)) {
|
|
234
|
+
throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.SUBSTRATE, 'Bond less amount too high');
|
|
235
|
+
}
|
|
236
|
+
else if (requestedAmount.eq(bondAmount)) {
|
|
237
|
+
return this.prepareScheduleUndelegate(publicKey, tip, candidate);
|
|
238
|
+
}
|
|
239
|
+
const encoded = await this.transactionController.prepareSubmittableTransactions(publicKey, (0, module_kit_1.newAmount)(balance.total).blockchain(this.metadata.units).value, [
|
|
240
|
+
{
|
|
241
|
+
type: 'schedule_delegator_bond_less',
|
|
242
|
+
tip,
|
|
243
|
+
args: {
|
|
244
|
+
candidate,
|
|
245
|
+
less: requestedAmount
|
|
374
246
|
}
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
247
|
+
}
|
|
248
|
+
]);
|
|
249
|
+
return [(0, module_kit_1.newUnsignedTransaction)({ encoded })];
|
|
250
|
+
}
|
|
251
|
+
async prepareExecuteDelegatorBondLess(publicKey, tip, candidate) {
|
|
252
|
+
return this.prepareExecuteDelegationRequest(publicKey, tip, candidate);
|
|
253
|
+
}
|
|
254
|
+
async prepareCancelDelegatorBondLess(publicKey, tip, candidate) {
|
|
255
|
+
return this.prepareCancelDelegationRequest(publicKey, tip, candidate);
|
|
256
|
+
}
|
|
257
|
+
async prepareExecuteDelegationRequest(publicKey, tip, candidate) {
|
|
258
|
+
const results = await Promise.all([this.getBalanceOfPublicKey(publicKey), this.getAddressFromPublicKey(publicKey)]);
|
|
259
|
+
const balance = results[0];
|
|
260
|
+
const delegator = results[1];
|
|
261
|
+
const encoded = await this.transactionController.prepareSubmittableTransactions(publicKey, (0, module_kit_1.newAmount)(balance.total).blockchain(this.metadata.units).value, [
|
|
262
|
+
{
|
|
263
|
+
type: 'execute_delegation_request',
|
|
264
|
+
tip,
|
|
265
|
+
args: {
|
|
266
|
+
delegator,
|
|
267
|
+
candidate
|
|
396
268
|
}
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
return [4 /*yield*/, this.transactionController.prepareSubmittableTransactions(publicKey, available, [
|
|
410
|
-
{
|
|
411
|
-
type: 'delegator_bond_more',
|
|
412
|
-
tip: tip,
|
|
413
|
-
args: {
|
|
414
|
-
candidate: candidate,
|
|
415
|
-
more: new bignumber_1.default(more)
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
])];
|
|
419
|
-
case 2:
|
|
420
|
-
encoded = _a.sent();
|
|
421
|
-
return [2 /*return*/, [(0, module_kit_1.newUnsignedTransaction)({ encoded: encoded })]];
|
|
269
|
+
}
|
|
270
|
+
]);
|
|
271
|
+
return [(0, module_kit_1.newUnsignedTransaction)({ encoded })];
|
|
272
|
+
}
|
|
273
|
+
async prepareCancelDelegationRequest(publicKey, tip, candidate) {
|
|
274
|
+
const balance = await this.getBalanceOfPublicKey(publicKey);
|
|
275
|
+
const encoded = await this.transactionController.prepareSubmittableTransactions(publicKey, (0, module_kit_1.newAmount)(balance.total).blockchain(this.metadata.units).value, [
|
|
276
|
+
{
|
|
277
|
+
type: 'cancel_delegation_request',
|
|
278
|
+
tip,
|
|
279
|
+
args: {
|
|
280
|
+
candidate
|
|
422
281
|
}
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
282
|
+
}
|
|
283
|
+
]);
|
|
284
|
+
return [(0, module_kit_1.newUnsignedTransaction)({ encoded })];
|
|
285
|
+
}
|
|
286
|
+
async getMinDelegationAmountWithPublicKey(publicKey) {
|
|
287
|
+
return this.accountController.getMinDelegationAmount(publicKey);
|
|
288
|
+
}
|
|
289
|
+
async getMinDelegationAmountWithAddress(address) {
|
|
290
|
+
return this.accountController.getMinDelegationAmount(address);
|
|
291
|
+
}
|
|
292
|
+
// Custom
|
|
293
|
+
async getStakingDetails(address, collator) {
|
|
294
|
+
return this.accountController.getDelegationDetails(address, collator);
|
|
295
|
+
}
|
|
296
|
+
async getCollatorDetails(address) {
|
|
297
|
+
return this.accountController.getCollatorDetails(address);
|
|
298
|
+
}
|
|
299
|
+
async getMaxDelegationsPerDelegator() {
|
|
300
|
+
const maxDelegations = await this.nodeClient.getMaxDelegationsPerDelegator();
|
|
301
|
+
return maxDelegations?.toString();
|
|
302
|
+
}
|
|
303
|
+
async getMaxTopDelegationsPerCandidate() {
|
|
304
|
+
const maxTopDelegations = await this.nodeClient.getMaxTopDelegationsPerCandidate();
|
|
305
|
+
return maxTopDelegations?.toString();
|
|
306
|
+
}
|
|
307
|
+
async getFutureRequiredTransactions(accountId, intention) {
|
|
308
|
+
const results = await Promise.all([this.accountController.isDelegating(accountId), this.accountController.getBalance(accountId)]);
|
|
309
|
+
const isDelegating = results[0];
|
|
310
|
+
const balance = results[1];
|
|
311
|
+
const transferableBalance = balance.transferable.minus(balance.existentialDeposit);
|
|
312
|
+
const stakingBalance = balance.transferable;
|
|
313
|
+
const requiredTransactions = [];
|
|
314
|
+
if (intention === 'transfer') {
|
|
315
|
+
requiredTransactions.push([
|
|
316
|
+
'transfer',
|
|
317
|
+
{
|
|
318
|
+
to: v1_1.SubstrateEthAddress.createPlaceholder(),
|
|
319
|
+
value: transferableBalance
|
|
458
320
|
}
|
|
459
|
-
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
471
|
-
return __generator(this, function (_a) {
|
|
472
|
-
return [2 /*return*/, this.prepareCancelDelegationRequest(publicKey, tip, candidate)];
|
|
473
|
-
});
|
|
474
|
-
});
|
|
475
|
-
};
|
|
476
|
-
MoonbeamBaseProtocolImpl.prototype.prepareExecuteDelegationRequest = function (publicKey, tip, candidate) {
|
|
477
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
478
|
-
var results, balance, delegator, encoded;
|
|
479
|
-
return __generator(this, function (_a) {
|
|
480
|
-
switch (_a.label) {
|
|
481
|
-
case 0: return [4 /*yield*/, Promise.all([this.getBalanceOfPublicKey(publicKey), this.getAddressFromPublicKey(publicKey)])];
|
|
482
|
-
case 1:
|
|
483
|
-
results = _a.sent();
|
|
484
|
-
balance = results[0];
|
|
485
|
-
delegator = results[1];
|
|
486
|
-
return [4 /*yield*/, this.transactionController.prepareSubmittableTransactions(publicKey, (0, module_kit_1.newAmount)(balance.total).blockchain(this.metadata.units).value, [
|
|
487
|
-
{
|
|
488
|
-
type: 'execute_delegation_request',
|
|
489
|
-
tip: tip,
|
|
490
|
-
args: {
|
|
491
|
-
delegator: delegator,
|
|
492
|
-
candidate: candidate
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
])];
|
|
496
|
-
case 2:
|
|
497
|
-
encoded = _a.sent();
|
|
498
|
-
return [2 /*return*/, [(0, module_kit_1.newUnsignedTransaction)({ encoded: encoded })]];
|
|
321
|
+
]);
|
|
322
|
+
}
|
|
323
|
+
if (!isDelegating && intention === 'delegate') {
|
|
324
|
+
// not delegated
|
|
325
|
+
requiredTransactions.push([
|
|
326
|
+
'delegate',
|
|
327
|
+
{
|
|
328
|
+
candidate: v1_1.SubstrateEthAddress.createPlaceholder(),
|
|
329
|
+
amount: stakingBalance,
|
|
330
|
+
candidateDelegationCount: 0,
|
|
331
|
+
delegationCount: 0
|
|
499
332
|
}
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
505
|
-
var balance, encoded;
|
|
506
|
-
return __generator(this, function (_a) {
|
|
507
|
-
switch (_a.label) {
|
|
508
|
-
case 0: return [4 /*yield*/, this.getBalanceOfPublicKey(publicKey)];
|
|
509
|
-
case 1:
|
|
510
|
-
balance = _a.sent();
|
|
511
|
-
return [4 /*yield*/, this.transactionController.prepareSubmittableTransactions(publicKey, (0, module_kit_1.newAmount)(balance.total).blockchain(this.metadata.units).value, [
|
|
512
|
-
{
|
|
513
|
-
type: 'cancel_delegation_request',
|
|
514
|
-
tip: tip,
|
|
515
|
-
args: {
|
|
516
|
-
candidate: candidate
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
])];
|
|
520
|
-
case 2:
|
|
521
|
-
encoded = _a.sent();
|
|
522
|
-
return [2 /*return*/, [(0, module_kit_1.newUnsignedTransaction)({ encoded: encoded })]];
|
|
333
|
+
], [
|
|
334
|
+
'schedule_revoke_delegation',
|
|
335
|
+
{
|
|
336
|
+
collator: v1_1.SubstrateEthAddress.createPlaceholder()
|
|
523
337
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
return __generator(this, function (_a) {
|
|
530
|
-
return [2 /*return*/, this.accountController.getMinDelegationAmount(publicKey)];
|
|
531
|
-
});
|
|
532
|
-
});
|
|
533
|
-
};
|
|
534
|
-
MoonbeamBaseProtocolImpl.prototype.getMinDelegationAmountWithAddress = function (address) {
|
|
535
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
536
|
-
return __generator(this, function (_a) {
|
|
537
|
-
return [2 /*return*/, this.accountController.getMinDelegationAmount(address)];
|
|
538
|
-
});
|
|
539
|
-
});
|
|
540
|
-
};
|
|
541
|
-
// Custom
|
|
542
|
-
MoonbeamBaseProtocolImpl.prototype.getStakingDetails = function (address, collator) {
|
|
543
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
544
|
-
return __generator(this, function (_a) {
|
|
545
|
-
return [2 /*return*/, this.accountController.getDelegationDetails(address, collator)];
|
|
546
|
-
});
|
|
547
|
-
});
|
|
548
|
-
};
|
|
549
|
-
MoonbeamBaseProtocolImpl.prototype.getCollatorDetails = function (address) {
|
|
550
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
551
|
-
return __generator(this, function (_a) {
|
|
552
|
-
return [2 /*return*/, this.accountController.getCollatorDetails(address)];
|
|
553
|
-
});
|
|
554
|
-
});
|
|
555
|
-
};
|
|
556
|
-
MoonbeamBaseProtocolImpl.prototype.getMaxDelegationsPerDelegator = function () {
|
|
557
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
558
|
-
var maxDelegations;
|
|
559
|
-
return __generator(this, function (_a) {
|
|
560
|
-
switch (_a.label) {
|
|
561
|
-
case 0: return [4 /*yield*/, this.nodeClient.getMaxDelegationsPerDelegator()];
|
|
562
|
-
case 1:
|
|
563
|
-
maxDelegations = _a.sent();
|
|
564
|
-
return [2 /*return*/, maxDelegations === null || maxDelegations === void 0 ? void 0 : maxDelegations.toString()];
|
|
338
|
+
], [
|
|
339
|
+
'execute_delegation_request',
|
|
340
|
+
{
|
|
341
|
+
delegator: v1_1.SubstrateEthAddress.createPlaceholder(),
|
|
342
|
+
candidate: v1_1.SubstrateEthAddress.createPlaceholder()
|
|
565
343
|
}
|
|
566
|
-
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
switch (_a.label) {
|
|
574
|
-
case 0: return [4 /*yield*/, this.nodeClient.getMaxTopDelegationsPerCandidate()];
|
|
575
|
-
case 1:
|
|
576
|
-
maxTopDelegations = _a.sent();
|
|
577
|
-
return [2 /*return*/, maxTopDelegations === null || maxTopDelegations === void 0 ? void 0 : maxTopDelegations.toString()];
|
|
344
|
+
]);
|
|
345
|
+
}
|
|
346
|
+
if (isDelegating && intention === 'delegate') {
|
|
347
|
+
requiredTransactions.push([
|
|
348
|
+
'schedule_revoke_delegation',
|
|
349
|
+
{
|
|
350
|
+
collator: v1_1.SubstrateEthAddress.createPlaceholder()
|
|
578
351
|
}
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
var results, isDelegating, balance, transferableBalance, stakingBalance, requiredTransactions;
|
|
585
|
-
return __generator(this, function (_a) {
|
|
586
|
-
switch (_a.label) {
|
|
587
|
-
case 0: return [4 /*yield*/, Promise.all([this.accountController.isDelegating(accountId), this.accountController.getBalance(accountId)])];
|
|
588
|
-
case 1:
|
|
589
|
-
results = _a.sent();
|
|
590
|
-
isDelegating = results[0];
|
|
591
|
-
balance = results[1];
|
|
592
|
-
transferableBalance = balance.transferable.minus(balance.existentialDeposit);
|
|
593
|
-
stakingBalance = balance.transferable;
|
|
594
|
-
requiredTransactions = [];
|
|
595
|
-
if (intention === 'transfer') {
|
|
596
|
-
requiredTransactions.push([
|
|
597
|
-
'transfer',
|
|
598
|
-
{
|
|
599
|
-
to: v1_1.SubstrateEthAddress.createPlaceholder(),
|
|
600
|
-
value: transferableBalance
|
|
601
|
-
}
|
|
602
|
-
]);
|
|
603
|
-
}
|
|
604
|
-
if (!isDelegating && intention === 'delegate') {
|
|
605
|
-
// not delegated
|
|
606
|
-
requiredTransactions.push([
|
|
607
|
-
'delegate',
|
|
608
|
-
{
|
|
609
|
-
candidate: v1_1.SubstrateEthAddress.createPlaceholder(),
|
|
610
|
-
amount: stakingBalance,
|
|
611
|
-
candidateDelegationCount: 0,
|
|
612
|
-
delegationCount: 0
|
|
613
|
-
}
|
|
614
|
-
], [
|
|
615
|
-
'schedule_revoke_delegation',
|
|
616
|
-
{
|
|
617
|
-
collator: v1_1.SubstrateEthAddress.createPlaceholder()
|
|
618
|
-
}
|
|
619
|
-
], [
|
|
620
|
-
'execute_delegation_request',
|
|
621
|
-
{
|
|
622
|
-
delegator: v1_1.SubstrateEthAddress.createPlaceholder(),
|
|
623
|
-
candidate: v1_1.SubstrateEthAddress.createPlaceholder()
|
|
624
|
-
}
|
|
625
|
-
]);
|
|
626
|
-
}
|
|
627
|
-
if (isDelegating && intention === 'delegate') {
|
|
628
|
-
requiredTransactions.push([
|
|
629
|
-
'schedule_revoke_delegation',
|
|
630
|
-
{
|
|
631
|
-
collator: v1_1.SubstrateEthAddress.createPlaceholder()
|
|
632
|
-
}
|
|
633
|
-
], [
|
|
634
|
-
'execute_delegation_request',
|
|
635
|
-
{
|
|
636
|
-
delegator: v1_1.SubstrateEthAddress.createPlaceholder(),
|
|
637
|
-
candidate: v1_1.SubstrateEthAddress.createPlaceholder()
|
|
638
|
-
}
|
|
639
|
-
]);
|
|
640
|
-
}
|
|
641
|
-
return [2 /*return*/, requiredTransactions];
|
|
352
|
+
], [
|
|
353
|
+
'execute_delegation_request',
|
|
354
|
+
{
|
|
355
|
+
delegator: v1_1.SubstrateEthAddress.createPlaceholder(),
|
|
356
|
+
candidate: v1_1.SubstrateEthAddress.createPlaceholder()
|
|
642
357
|
}
|
|
643
|
-
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
}
|
|
358
|
+
]);
|
|
359
|
+
}
|
|
360
|
+
return requiredTransactions;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
648
363
|
exports.MoonbeamBaseProtocolImpl = MoonbeamBaseProtocolImpl;
|
|
649
364
|
//# sourceMappingURL=MoonbeamBaseProtocol.js.map
|