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