@airgap/moonbeam 0.13.45-beta.3 → 0.13.45-beta.5
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,364 +1,649 @@
|
|
|
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
|
+
};
|
|
2
53
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
54
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
55
|
};
|
|
5
56
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
57
|
exports.MoonbeamBaseProtocolImpl = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
58
|
+
var coinlib_core_1 = require("@airgap/coinlib-core");
|
|
59
|
+
var bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
|
|
60
|
+
var errors_1 = require("@airgap/coinlib-core/errors");
|
|
61
|
+
var assert_1 = require("@airgap/coinlib-core/utils/assert");
|
|
62
|
+
var module_kit_1 = require("@airgap/module-kit");
|
|
63
|
+
var v1_1 = require("@airgap/substrate/v1");
|
|
64
|
+
var MoonbeamAccountController_1 = require("../controller/MoonbeamAccountController");
|
|
65
|
+
var MoonbeamTransactionController_1 = require("../controller/MoonbeamTransactionController");
|
|
66
|
+
var MoonbeamStakingActionType_1 = require("../data/staking/MoonbeamStakingActionType");
|
|
67
|
+
var MoonbeamNodeClient_1 = require("../node/MoonbeamNodeClient");
|
|
17
68
|
// Implementation
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
69
|
+
var MoonbeamBaseProtocolImpl = /** @class */ (function (_super) {
|
|
70
|
+
__extends(MoonbeamBaseProtocolImpl, _super);
|
|
71
|
+
function MoonbeamBaseProtocolImpl(options) {
|
|
72
|
+
var _this = this;
|
|
73
|
+
var nodeClient = new MoonbeamNodeClient_1.MoonbeamNodeClient(options.configuration, options.network.rpcUrl);
|
|
74
|
+
var accountController = new MoonbeamAccountController_1.MoonbeamAccountController(options.configuration, nodeClient);
|
|
75
|
+
var transactionController = new MoonbeamTransactionController_1.MoonbeamTransactionController(options.configuration, nodeClient);
|
|
76
|
+
var blockExplorer = new v1_1.SubscanBlockExplorerClient(options.network.blockExplorerApi);
|
|
77
|
+
_this = _super.call(this, options, nodeClient, accountController, transactionController, blockExplorer) || this;
|
|
78
|
+
_this.defaultValidator = options.network.defaultValidator;
|
|
79
|
+
return _this;
|
|
26
80
|
}
|
|
27
81
|
// Staking
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
|
82
|
+
MoonbeamBaseProtocolImpl.prototype.getDefaultDelegatee = function () {
|
|
83
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
84
|
+
var collators;
|
|
85
|
+
return __generator(this, function (_a) {
|
|
86
|
+
switch (_a.label) {
|
|
87
|
+
case 0:
|
|
88
|
+
if (this.defaultValidator) {
|
|
89
|
+
return [2 /*return*/, this.defaultValidator];
|
|
90
|
+
}
|
|
91
|
+
return [4 /*yield*/, this.nodeClient.getCollators()];
|
|
92
|
+
case 1:
|
|
93
|
+
collators = _a.sent();
|
|
94
|
+
return [2 /*return*/, collators ? collators[0].asString() : ''];
|
|
144
95
|
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
MoonbeamBaseProtocolImpl.prototype.getCurrentDelegateesForPublicKey = function (publicKey) {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
101
|
+
return __generator(this, function (_a) {
|
|
102
|
+
return [2 /*return*/, this.accountController.getCurrentCollators(publicKey)];
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
MoonbeamBaseProtocolImpl.prototype.getCurrentDelegateesForAddress = function (address) {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
108
|
+
return __generator(this, function (_a) {
|
|
109
|
+
return [2 /*return*/, this.accountController.getCurrentCollators(address)];
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
MoonbeamBaseProtocolImpl.prototype.getDelegateeDetails = function (address) {
|
|
114
|
+
var _a, _b;
|
|
115
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
116
|
+
var collatorDetails;
|
|
117
|
+
return __generator(this, function (_c) {
|
|
118
|
+
switch (_c.label) {
|
|
119
|
+
case 0: return [4 /*yield*/, this.accountController.getCollatorDetails(address)];
|
|
120
|
+
case 1:
|
|
121
|
+
collatorDetails = _c.sent();
|
|
122
|
+
return [2 /*return*/, {
|
|
123
|
+
name: (_a = collatorDetails.name) !== null && _a !== void 0 ? _a : '',
|
|
124
|
+
status: (_b = collatorDetails.status) !== null && _b !== void 0 ? _b : '',
|
|
125
|
+
address: collatorDetails.address
|
|
126
|
+
}];
|
|
157
127
|
}
|
|
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
|
-
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
MoonbeamBaseProtocolImpl.prototype.isPublicKeyDelegating = function (publicKey) {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
133
|
+
return __generator(this, function (_a) {
|
|
134
|
+
return [2 /*return*/, this.accountController.isDelegating(publicKey)];
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
MoonbeamBaseProtocolImpl.prototype.isAddressDelegating = function (address) {
|
|
139
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
140
|
+
return __generator(this, function (_a) {
|
|
141
|
+
return [2 /*return*/, this.accountController.isDelegating(address)];
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
MoonbeamBaseProtocolImpl.prototype.getDelegatorDetailsFromPublicKey = function (publicKey) {
|
|
146
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
147
|
+
return __generator(this, function (_a) {
|
|
148
|
+
return [2 /*return*/, this.accountController.getDelegatorDetails(publicKey)];
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
MoonbeamBaseProtocolImpl.prototype.getDelegatorDetailsFromAddress = function (address) {
|
|
153
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
154
|
+
return __generator(this, function (_a) {
|
|
155
|
+
return [2 /*return*/, this.accountController.getDelegatorDetails(address)];
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
MoonbeamBaseProtocolImpl.prototype.getDelegationDetailsFromPublicKey = function (publicKey, delegatees) {
|
|
160
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
161
|
+
var address;
|
|
162
|
+
return __generator(this, function (_a) {
|
|
163
|
+
switch (_a.label) {
|
|
164
|
+
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
|
|
165
|
+
case 1:
|
|
166
|
+
address = _a.sent();
|
|
167
|
+
return [2 /*return*/, this.getDelegationDetailsFromAddress(address, delegatees)];
|
|
195
168
|
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
type: 'delegator_bond_more',
|
|
217
|
-
tip,
|
|
218
|
-
args: {
|
|
219
|
-
candidate,
|
|
220
|
-
more: new bignumber_1.default(more)
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
MoonbeamBaseProtocolImpl.prototype.getDelegationDetailsFromAddress = function (address, delegatees) {
|
|
173
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
174
|
+
var collator, delegationDetails;
|
|
175
|
+
return __generator(this, function (_a) {
|
|
176
|
+
switch (_a.label) {
|
|
177
|
+
case 0:
|
|
178
|
+
if (delegatees.length > 1) {
|
|
179
|
+
throw new errors_1.UnsupportedError(coinlib_core_1.Domain.SUBSTRATE, 'Multiple validators for a single delegation are not supported');
|
|
180
|
+
}
|
|
181
|
+
collator = delegatees[0];
|
|
182
|
+
return [4 /*yield*/, this.accountController.getDelegationDetails(address, collator)];
|
|
183
|
+
case 1:
|
|
184
|
+
delegationDetails = _a.sent();
|
|
185
|
+
return [2 /*return*/, {
|
|
186
|
+
delegator: delegationDetails.delegatorDetails,
|
|
187
|
+
delegatees: [delegationDetails.collatorDetails]
|
|
188
|
+
}];
|
|
221
189
|
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
this
|
|
229
|
-
|
|
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
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
MoonbeamBaseProtocolImpl.prototype.prepareDelegatorActionFromPublicKey = function (publicKey, type, data) {
|
|
194
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
195
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
196
|
+
return __generator(this, function (_m) {
|
|
197
|
+
if (!data) {
|
|
198
|
+
data = {};
|
|
246
199
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
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.');
|
|
268
233
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
{
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
234
|
+
return [2 /*return*/];
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
MoonbeamBaseProtocolImpl.prototype.prepareDelegation = function (publicKey, tip, candidate, amount) {
|
|
239
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
240
|
+
var requestedAmount, minAmount, results, delegatorDetails, collatorDetails, maxDelegations, balance, available, encoded;
|
|
241
|
+
return __generator(this, function (_a) {
|
|
242
|
+
switch (_a.label) {
|
|
243
|
+
case 0:
|
|
244
|
+
requestedAmount = new bignumber_1.default(amount);
|
|
245
|
+
return [4 /*yield*/, this.accountController.getMinDelegationAmount(publicKey)];
|
|
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 })]];
|
|
281
282
|
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
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
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
};
|
|
286
|
+
MoonbeamBaseProtocolImpl.prototype.prepareScheduleUndelegate = function (publicKey, tip, collator) {
|
|
287
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
288
|
+
var balance, encoded;
|
|
289
|
+
return __generator(this, function (_a) {
|
|
290
|
+
switch (_a.label) {
|
|
291
|
+
case 0: return [4 /*yield*/, this.getBalanceOfPublicKey(publicKey)];
|
|
292
|
+
case 1:
|
|
293
|
+
balance = _a.sent();
|
|
294
|
+
return [4 /*yield*/, this.transactionController.prepareSubmittableTransactions(publicKey, (0, module_kit_1.newAmount)(balance.total).blockchain(this.metadata.units).value, [
|
|
295
|
+
{
|
|
296
|
+
type: 'schedule_revoke_delegation',
|
|
297
|
+
tip: tip,
|
|
298
|
+
args: {
|
|
299
|
+
collator: collator
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
])];
|
|
303
|
+
case 2:
|
|
304
|
+
encoded = _a.sent();
|
|
305
|
+
return [2 /*return*/, [(0, module_kit_1.newUnsignedTransaction)({ encoded: encoded })]];
|
|
320
306
|
}
|
|
321
|
-
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
};
|
|
310
|
+
MoonbeamBaseProtocolImpl.prototype.prepareExecuteUndelegate = function (publicKey, tip, candidate) {
|
|
311
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
312
|
+
return __generator(this, function (_a) {
|
|
313
|
+
return [2 /*return*/, this.prepareExecuteDelegationRequest(publicKey, tip, candidate)];
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
};
|
|
317
|
+
MoonbeamBaseProtocolImpl.prototype.prepareCancelUndelegate = function (publicKey, tip, candidate) {
|
|
318
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
319
|
+
return __generator(this, function (_a) {
|
|
320
|
+
return [2 /*return*/, this.prepareCancelDelegationRequest(publicKey, tip, candidate)];
|
|
321
|
+
});
|
|
322
|
+
});
|
|
323
|
+
};
|
|
324
|
+
MoonbeamBaseProtocolImpl.prototype.prepareScheduleUndelegateAll = function (publicKey, tip) {
|
|
325
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
326
|
+
var balance, encoded;
|
|
327
|
+
return __generator(this, function (_a) {
|
|
328
|
+
switch (_a.label) {
|
|
329
|
+
case 0: return [4 /*yield*/, this.getBalanceOfPublicKey(publicKey)];
|
|
330
|
+
case 1:
|
|
331
|
+
balance = _a.sent();
|
|
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 })]];
|
|
332
342
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
};
|
|
346
|
+
MoonbeamBaseProtocolImpl.prototype.prepareExecuteUndelegateAll = function (publicKey, tip) {
|
|
347
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
348
|
+
var results, delegatorDetails, balance, delegator, encoded;
|
|
349
|
+
return __generator(this, function (_a) {
|
|
350
|
+
switch (_a.label) {
|
|
351
|
+
case 0: return [4 /*yield*/, Promise.all([
|
|
352
|
+
this.accountController.getDelegatorDetails(publicKey),
|
|
353
|
+
this.getBalanceOfPublicKey(publicKey),
|
|
354
|
+
this.getAddressFromPublicKey(publicKey)
|
|
355
|
+
])];
|
|
356
|
+
case 1:
|
|
357
|
+
results = _a.sent();
|
|
358
|
+
delegatorDetails = results[0];
|
|
359
|
+
balance = results[1];
|
|
360
|
+
delegator = results[2];
|
|
361
|
+
return [4 /*yield*/, this.transactionController.prepareSubmittableTransactions(publicKey, (0, module_kit_1.newAmount)(balance.total).blockchain(this.metadata.units).value, [
|
|
362
|
+
{
|
|
363
|
+
type: 'execute_leave_delegators',
|
|
364
|
+
tip: tip,
|
|
365
|
+
args: {
|
|
366
|
+
delegator: delegator,
|
|
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 })]];
|
|
337
374
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
};
|
|
378
|
+
MoonbeamBaseProtocolImpl.prototype.prepareCancelUndelegateAll = function (publicKey, tip) {
|
|
379
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
380
|
+
var balance, encoded;
|
|
381
|
+
return __generator(this, function (_a) {
|
|
382
|
+
switch (_a.label) {
|
|
383
|
+
case 0: return [4 /*yield*/, this.getBalanceOfPublicKey(publicKey)];
|
|
384
|
+
case 1:
|
|
385
|
+
balance = _a.sent();
|
|
386
|
+
return [4 /*yield*/, this.transactionController.prepareSubmittableTransactions(publicKey, (0, module_kit_1.newAmount)(balance.total).blockchain(this.metadata.units).value, [
|
|
387
|
+
{
|
|
388
|
+
type: 'cancel_leave_delegators',
|
|
389
|
+
tip: tip,
|
|
390
|
+
args: {}
|
|
391
|
+
}
|
|
392
|
+
])];
|
|
393
|
+
case 2:
|
|
394
|
+
encoded = _a.sent();
|
|
395
|
+
return [2 /*return*/, [(0, module_kit_1.newUnsignedTransaction)({ encoded: encoded })]];
|
|
343
396
|
}
|
|
344
|
-
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
397
|
+
});
|
|
398
|
+
});
|
|
399
|
+
};
|
|
400
|
+
MoonbeamBaseProtocolImpl.prototype.prepareDelegatorBondMore = function (publicKey, tip, candidate, more) {
|
|
401
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
402
|
+
var balance, available, encoded;
|
|
403
|
+
return __generator(this, function (_a) {
|
|
404
|
+
switch (_a.label) {
|
|
405
|
+
case 0: return [4 /*yield*/, this.getBalanceOfPublicKey(publicKey)];
|
|
406
|
+
case 1:
|
|
407
|
+
balance = _a.sent();
|
|
408
|
+
available = new bignumber_1.default((0, module_kit_1.newAmount)(balance.total).blockchain(this.metadata.units).value).minus(more);
|
|
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 })]];
|
|
351
422
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
};
|
|
426
|
+
MoonbeamBaseProtocolImpl.prototype.prepareScheduleDelegatorBondLess = function (publicKey, tip, candidate, less) {
|
|
427
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
428
|
+
var _a, balance, delegationDetails, bondAmount, requestedAmount, encoded;
|
|
429
|
+
return __generator(this, function (_b) {
|
|
430
|
+
switch (_b.label) {
|
|
431
|
+
case 0: return [4 /*yield*/, Promise.all([
|
|
432
|
+
this.getBalanceOfPublicKey(publicKey),
|
|
433
|
+
this.accountController.getDelegationDetails(publicKey, candidate)
|
|
434
|
+
])];
|
|
435
|
+
case 1:
|
|
436
|
+
_a = _b.sent(), balance = _a[0], delegationDetails = _a[1];
|
|
437
|
+
bondAmount = new bignumber_1.default(delegationDetails.bond);
|
|
438
|
+
requestedAmount = new bignumber_1.default(less);
|
|
439
|
+
if (requestedAmount.gt(bondAmount)) {
|
|
440
|
+
throw new errors_1.ConditionViolationError(coinlib_core_1.Domain.SUBSTRATE, 'Bond less amount too high');
|
|
441
|
+
}
|
|
442
|
+
else if (requestedAmount.eq(bondAmount)) {
|
|
443
|
+
return [2 /*return*/, this.prepareScheduleUndelegate(publicKey, tip, candidate)];
|
|
444
|
+
}
|
|
445
|
+
return [4 /*yield*/, this.transactionController.prepareSubmittableTransactions(publicKey, (0, module_kit_1.newAmount)(balance.total).blockchain(this.metadata.units).value, [
|
|
446
|
+
{
|
|
447
|
+
type: 'schedule_delegator_bond_less',
|
|
448
|
+
tip: tip,
|
|
449
|
+
args: {
|
|
450
|
+
candidate: candidate,
|
|
451
|
+
less: requestedAmount
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
])];
|
|
455
|
+
case 2:
|
|
456
|
+
encoded = _b.sent();
|
|
457
|
+
return [2 /*return*/, [(0, module_kit_1.newUnsignedTransaction)({ encoded: encoded })]];
|
|
357
458
|
}
|
|
358
|
-
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
459
|
+
});
|
|
460
|
+
});
|
|
461
|
+
};
|
|
462
|
+
MoonbeamBaseProtocolImpl.prototype.prepareExecuteDelegatorBondLess = function (publicKey, tip, candidate) {
|
|
463
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
464
|
+
return __generator(this, function (_a) {
|
|
465
|
+
return [2 /*return*/, this.prepareExecuteDelegationRequest(publicKey, tip, candidate)];
|
|
466
|
+
});
|
|
467
|
+
});
|
|
468
|
+
};
|
|
469
|
+
MoonbeamBaseProtocolImpl.prototype.prepareCancelDelegatorBondLess = function (publicKey, tip, candidate) {
|
|
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 })]];
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
});
|
|
502
|
+
};
|
|
503
|
+
MoonbeamBaseProtocolImpl.prototype.prepareCancelDelegationRequest = function (publicKey, tip, candidate) {
|
|
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 })]];
|
|
523
|
+
}
|
|
524
|
+
});
|
|
525
|
+
});
|
|
526
|
+
};
|
|
527
|
+
MoonbeamBaseProtocolImpl.prototype.getMinDelegationAmountWithPublicKey = function (publicKey) {
|
|
528
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
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()];
|
|
565
|
+
}
|
|
566
|
+
});
|
|
567
|
+
});
|
|
568
|
+
};
|
|
569
|
+
MoonbeamBaseProtocolImpl.prototype.getMaxTopDelegationsPerCandidate = function () {
|
|
570
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
571
|
+
var maxTopDelegations;
|
|
572
|
+
return __generator(this, function (_a) {
|
|
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()];
|
|
578
|
+
}
|
|
579
|
+
});
|
|
580
|
+
});
|
|
581
|
+
};
|
|
582
|
+
MoonbeamBaseProtocolImpl.prototype.getFutureRequiredTransactions = function (accountId, intention) {
|
|
583
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
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];
|
|
642
|
+
}
|
|
643
|
+
});
|
|
644
|
+
});
|
|
645
|
+
};
|
|
646
|
+
return MoonbeamBaseProtocolImpl;
|
|
647
|
+
}(v1_1.SubstrateStakingProtocolImpl));
|
|
363
648
|
exports.MoonbeamBaseProtocolImpl = MoonbeamBaseProtocolImpl;
|
|
364
649
|
//# sourceMappingURL=MoonbeamBaseProtocol.js.map
|