@wallfree-dev/polkadot 0.13.42
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/LICENSE.md +7 -0
- package/index.d.ts +1 -0
- package/index.js +18 -0
- package/index.js.map +1 -0
- package/package.json +65 -0
- package/readme.md +121 -0
- package/v0/index.d.ts +5 -0
- package/v0/index.js +31 -0
- package/v0/index.js.map +1 -0
- package/v0/protocol/kusama/KusamaProtocol.d.ts +22 -0
- package/v0/protocol/kusama/KusamaProtocol.js +71 -0
- package/v0/protocol/kusama/KusamaProtocol.js.map +1 -0
- package/v0/protocol/kusama/KusamaProtocolOptions.d.ts +23 -0
- package/v0/protocol/kusama/KusamaProtocolOptions.js +85 -0
- package/v0/protocol/kusama/KusamaProtocolOptions.js.map +1 -0
- package/v0/protocol/polkadot/PolkadotProtocol.d.ts +23 -0
- package/v0/protocol/polkadot/PolkadotProtocol.js +72 -0
- package/v0/protocol/polkadot/PolkadotProtocol.js.map +1 -0
- package/v0/protocol/polkadot/PolkadotProtocolOptions.d.ts +23 -0
- package/v0/protocol/polkadot/PolkadotProtocolOptions.js +85 -0
- package/v0/protocol/polkadot/PolkadotProtocolOptions.js.map +1 -0
- package/v1/controller/PolkadotAccountController.d.ts +30 -0
- package/v1/controller/PolkadotAccountController.js +675 -0
- package/v1/controller/PolkadotAccountController.js.map +1 -0
- package/v1/controller/PolkadotTransactionController.d.ts +5 -0
- package/v1/controller/PolkadotTransactionController.js +28 -0
- package/v1/controller/PolkadotTransactionController.js.map +1 -0
- package/v1/data/staking/PolkadotActiveEraInfo.d.ts +8 -0
- package/v1/data/staking/PolkadotActiveEraInfo.js +19 -0
- package/v1/data/staking/PolkadotActiveEraInfo.js.map +1 -0
- package/v1/data/staking/PolkadotEraRewardPoints.d.ts +8 -0
- package/v1/data/staking/PolkadotEraRewardPoints.js +21 -0
- package/v1/data/staking/PolkadotEraRewardPoints.js.map +1 -0
- package/v1/data/staking/PolkadotExposure.d.ts +9 -0
- package/v1/data/staking/PolkadotExposure.js +23 -0
- package/v1/data/staking/PolkadotExposure.js.map +1 -0
- package/v1/data/staking/PolkadotNominationStatus.d.ts +5 -0
- package/v1/data/staking/PolkadotNominationStatus.js +10 -0
- package/v1/data/staking/PolkadotNominationStatus.js.map +1 -0
- package/v1/data/staking/PolkadotNominations.d.ts +9 -0
- package/v1/data/staking/PolkadotNominations.js +21 -0
- package/v1/data/staking/PolkadotNominations.js.map +1 -0
- package/v1/data/staking/PolkadotNominatorDetails.d.ts +24 -0
- package/v1/data/staking/PolkadotNominatorDetails.js +3 -0
- package/v1/data/staking/PolkadotNominatorDetails.js.map +1 -0
- package/v1/data/staking/PolkadotPayee.d.ts +5 -0
- package/v1/data/staking/PolkadotPayee.js +10 -0
- package/v1/data/staking/PolkadotPayee.js.map +1 -0
- package/v1/data/staking/PolkadotSlashingSpans.d.ts +10 -0
- package/v1/data/staking/PolkadotSlashingSpans.js +23 -0
- package/v1/data/staking/PolkadotSlashingSpans.js.map +1 -0
- package/v1/data/staking/PolkadotStakingActionType.d.ts +14 -0
- package/v1/data/staking/PolkadotStakingActionType.js +19 -0
- package/v1/data/staking/PolkadotStakingActionType.js.map +1 -0
- package/v1/data/staking/PolkadotStakingBalance.d.ts +5 -0
- package/v1/data/staking/PolkadotStakingBalance.js +3 -0
- package/v1/data/staking/PolkadotStakingBalance.js.map +1 -0
- package/v1/data/staking/PolkadotStakingLedger.d.ts +11 -0
- package/v1/data/staking/PolkadotStakingLedger.js +27 -0
- package/v1/data/staking/PolkadotStakingLedger.js.map +1 -0
- package/v1/data/staking/PolkadotValidatorDetails.d.ts +16 -0
- package/v1/data/staking/PolkadotValidatorDetails.js +3 -0
- package/v1/data/staking/PolkadotValidatorDetails.js.map +1 -0
- package/v1/data/staking/PolkadotValidatorPrefs.d.ts +7 -0
- package/v1/data/staking/PolkadotValidatorPrefs.js +17 -0
- package/v1/data/staking/PolkadotValidatorPrefs.js.map +1 -0
- package/v1/data/transaction/method/args.d.ts +2 -0
- package/v1/data/transaction/method/args.js +441 -0
- package/v1/data/transaction/method/args.js.map +1 -0
- package/v1/data/transaction/transaction.d.ts +2 -0
- package/v1/data/transaction/transaction.js +28 -0
- package/v1/data/transaction/transaction.js.map +1 -0
- package/v1/index.d.ts +15 -0
- package/v1/index.js +16 -0
- package/v1/index.js.map +1 -0
- package/v1/module/PolkadotModule.d.ts +19 -0
- package/v1/module/PolkadotModule.js +113 -0
- package/v1/module/PolkadotModule.js.map +1 -0
- package/v1/module.d.ts +3 -0
- package/v1/module.js +24 -0
- package/v1/module.js.map +1 -0
- package/v1/node/PolkadotNodeClient.d.ts +45 -0
- package/v1/node/PolkadotNodeClient.js +319 -0
- package/v1/node/PolkadotNodeClient.js.map +1 -0
- package/v1/protocol/KusamaProtocol.d.ts +14 -0
- package/v1/protocol/KusamaProtocol.js +106 -0
- package/v1/protocol/KusamaProtocol.js.map +1 -0
- package/v1/protocol/PolkadotBaseProtocol.d.ts +57 -0
- package/v1/protocol/PolkadotBaseProtocol.js +737 -0
- package/v1/protocol/PolkadotBaseProtocol.js.map +1 -0
- package/v1/protocol/PolkadotProtocol.d.ts +14 -0
- package/v1/protocol/PolkadotProtocol.js +119 -0
- package/v1/protocol/PolkadotProtocol.js.map +1 -0
- package/v1/serializer/v3/schemas/converter/transaction-converter.d.ts +7 -0
- package/v1/serializer/v3/schemas/converter/transaction-converter.js +21 -0
- package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-polkadot.d.ts +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-polkadot.js +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-request-polkadot.js.map +1 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-polkadot.d.ts +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-polkadot.js +3 -0
- package/v1/serializer/v3/schemas/definitions/transaction-sign-response-polkadot.js.map +1 -0
- package/v1/serializer/v3/schemas/generated/transaction-sign-request-polkadot.json +36 -0
- package/v1/serializer/v3/schemas/generated/transaction-sign-response-polkadot.json +19 -0
- package/v1/serializer/v3/serializer-companion.d.ts +14 -0
- package/v1/serializer/v3/serializer-companion.js +189 -0
- package/v1/serializer/v3/serializer-companion.js.map +1 -0
- package/v1/serializer/v3/validators/transaction-validator.d.ts +4 -0
- package/v1/serializer/v3/validators/transaction-validator.js +28 -0
- package/v1/serializer/v3/validators/transaction-validator.js.map +1 -0
- package/v1/serializer/v3/validators/validators.d.ts +4 -0
- package/v1/serializer/v3/validators/validators.js +6 -0
- package/v1/serializer/v3/validators/validators.js.map +1 -0
- package/v1/types/configuration.d.ts +11 -0
- package/v1/types/configuration.js +3 -0
- package/v1/types/configuration.js.map +1 -0
- package/v1/types/crypto.d.ts +2 -0
- package/v1/types/crypto.js +3 -0
- package/v1/types/crypto.js.map +1 -0
- package/v1/types/protocol.d.ts +13 -0
- package/v1/types/protocol.js +3 -0
- package/v1/types/protocol.js.map +1 -0
|
@@ -0,0 +1,737 @@
|
|
|
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
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
54
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
55
|
+
if (ar || !(i in from)) {
|
|
56
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
57
|
+
ar[i] = from[i];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
61
|
+
};
|
|
62
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
63
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
64
|
+
};
|
|
65
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
66
|
+
exports.PolkadotBaseProtocolImpl = void 0;
|
|
67
|
+
var bignumber_1 = __importDefault(require("@wallfree-dev/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
|
|
68
|
+
var assert_1 = require("@wallfree-dev/coinlib-core/utils/assert");
|
|
69
|
+
var module_kit_1 = require("@wallfree-dev/module-kit");
|
|
70
|
+
var v1_1 = require("@wallfree-dev/substrate/v1");
|
|
71
|
+
var PolkadotAccountController_1 = require("../controller/PolkadotAccountController");
|
|
72
|
+
var PolkadotTransactionController_1 = require("../controller/PolkadotTransactionController");
|
|
73
|
+
var PolkadotPayee_1 = require("../data/staking/PolkadotPayee");
|
|
74
|
+
var PolkadotStakingActionType_1 = require("../data/staking/PolkadotStakingActionType");
|
|
75
|
+
var PolkadotNodeClient_1 = require("../node/PolkadotNodeClient");
|
|
76
|
+
// Implementation
|
|
77
|
+
var PolkadotBaseProtocolImpl = /** @class */ (function (_super) {
|
|
78
|
+
__extends(PolkadotBaseProtocolImpl, _super);
|
|
79
|
+
function PolkadotBaseProtocolImpl(options) {
|
|
80
|
+
var _this = this;
|
|
81
|
+
var nodeClient = new PolkadotNodeClient_1.PolkadotNodeClient(options.configuration, options.network.rpcUrl);
|
|
82
|
+
var accountController = new PolkadotAccountController_1.PolkadotAccountController(options.configuration, nodeClient);
|
|
83
|
+
var transactionController = new PolkadotTransactionController_1.PolkadotTransactionController(options.configuration, nodeClient);
|
|
84
|
+
var blockExplorer = new v1_1.SubscanBlockExplorerClient(options.network.blockExplorerApi);
|
|
85
|
+
_this = _super.call(this, options, nodeClient, accountController, transactionController, blockExplorer) || this;
|
|
86
|
+
_this.defaultValidator = options.network.defaultValidator;
|
|
87
|
+
return _this;
|
|
88
|
+
}
|
|
89
|
+
// Staking
|
|
90
|
+
PolkadotBaseProtocolImpl.prototype.getDefaultDelegatee = function () {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
92
|
+
var validators;
|
|
93
|
+
return __generator(this, function (_a) {
|
|
94
|
+
switch (_a.label) {
|
|
95
|
+
case 0:
|
|
96
|
+
if (this.defaultValidator) {
|
|
97
|
+
return [2 /*return*/, this.defaultValidator];
|
|
98
|
+
}
|
|
99
|
+
return [4 /*yield*/, this.nodeClient.getValidators()];
|
|
100
|
+
case 1:
|
|
101
|
+
validators = _a.sent();
|
|
102
|
+
return [2 /*return*/, validators ? validators[0].asString() : ''];
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
PolkadotBaseProtocolImpl.prototype.getCurrentDelegateesForPublicKey = function (publicKey) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
109
|
+
return __generator(this, function (_a) {
|
|
110
|
+
return [2 /*return*/, this.accountController.getCurrentValidators(publicKey)];
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
PolkadotBaseProtocolImpl.prototype.getCurrentDelegateesForAddress = function (address) {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
116
|
+
return __generator(this, function (_a) {
|
|
117
|
+
return [2 /*return*/, this.accountController.getCurrentValidators(address)];
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
PolkadotBaseProtocolImpl.prototype.getDelegateeDetails = function (address) {
|
|
122
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
123
|
+
var validatorDetails;
|
|
124
|
+
return __generator(this, function (_a) {
|
|
125
|
+
switch (_a.label) {
|
|
126
|
+
case 0: return [4 /*yield*/, this.accountController.getValidatorDetails(address)];
|
|
127
|
+
case 1:
|
|
128
|
+
validatorDetails = _a.sent();
|
|
129
|
+
return [2 /*return*/, {
|
|
130
|
+
name: validatorDetails.name || '',
|
|
131
|
+
status: validatorDetails.status || '',
|
|
132
|
+
address: address
|
|
133
|
+
}];
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
PolkadotBaseProtocolImpl.prototype.isPublicKeyDelegating = function (publicKey) {
|
|
139
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
140
|
+
return __generator(this, function (_a) {
|
|
141
|
+
return [2 /*return*/, this.accountController.isDelegating(publicKey)];
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
};
|
|
145
|
+
PolkadotBaseProtocolImpl.prototype.isAddressDelegating = function (address) {
|
|
146
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
147
|
+
return __generator(this, function (_a) {
|
|
148
|
+
return [2 /*return*/, this.accountController.isDelegating(address)];
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
PolkadotBaseProtocolImpl.prototype.getDelegatorDetailsFromPublicKey = function (publicKey) {
|
|
153
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
154
|
+
var address;
|
|
155
|
+
return __generator(this, function (_a) {
|
|
156
|
+
switch (_a.label) {
|
|
157
|
+
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
|
|
158
|
+
case 1:
|
|
159
|
+
address = _a.sent();
|
|
160
|
+
return [2 /*return*/, this.getDelegatorDetailsFromAddress(address)];
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
PolkadotBaseProtocolImpl.prototype.getDelegatorDetailsFromAddress = function (address) {
|
|
166
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
167
|
+
return __generator(this, function (_a) {
|
|
168
|
+
return [2 /*return*/, this.accountController.getNominatorDetails(address)];
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
PolkadotBaseProtocolImpl.prototype.getDelegationDetailsFromPublicKey = function (publicKey, delegatees) {
|
|
173
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
174
|
+
var address;
|
|
175
|
+
return __generator(this, function (_a) {
|
|
176
|
+
switch (_a.label) {
|
|
177
|
+
case 0: return [4 /*yield*/, this.getAddressFromPublicKey(publicKey)];
|
|
178
|
+
case 1:
|
|
179
|
+
address = _a.sent();
|
|
180
|
+
return [2 /*return*/, this.getDelegationDetailsFromAddress(address, delegatees)];
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
PolkadotBaseProtocolImpl.prototype.getDelegationDetailsFromAddress = function (address, delegatees) {
|
|
186
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
187
|
+
var _a, nominatorDetails, validatorsDetails;
|
|
188
|
+
var _this = this;
|
|
189
|
+
return __generator(this, function (_b) {
|
|
190
|
+
switch (_b.label) {
|
|
191
|
+
case 0: return [4 /*yield*/, Promise.all([
|
|
192
|
+
this.accountController.getNominatorDetails(address, delegatees),
|
|
193
|
+
Promise.all(delegatees.map(function (validator) { return _this.accountController.getValidatorDetails(validator); }))
|
|
194
|
+
])];
|
|
195
|
+
case 1:
|
|
196
|
+
_a = _b.sent(), nominatorDetails = _a[0], validatorsDetails = _a[1];
|
|
197
|
+
nominatorDetails.rewards =
|
|
198
|
+
nominatorDetails.delegatees.length > 0 && nominatorDetails.stakingDetails
|
|
199
|
+
? nominatorDetails.stakingDetails.rewards.map(function (reward) { return ({
|
|
200
|
+
index: reward.eraIndex,
|
|
201
|
+
amount: reward.amount,
|
|
202
|
+
timestamp: reward.timestamp
|
|
203
|
+
}); })
|
|
204
|
+
: [];
|
|
205
|
+
return [2 /*return*/, {
|
|
206
|
+
delegator: nominatorDetails,
|
|
207
|
+
delegatees: validatorsDetails
|
|
208
|
+
}];
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
};
|
|
213
|
+
// tslint:disable-next-line: cyclomatic-complexity
|
|
214
|
+
PolkadotBaseProtocolImpl.prototype.prepareDelegatorActionFromPublicKey = function (publicKey, type, data) {
|
|
215
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
216
|
+
return __generator(this, function (_a) {
|
|
217
|
+
if (!data) {
|
|
218
|
+
data = {};
|
|
219
|
+
}
|
|
220
|
+
switch (type) {
|
|
221
|
+
case PolkadotStakingActionType_1.PolkadotStakingActionType.BOND_NOMINATE:
|
|
222
|
+
(0, assert_1.assertFields)("".concat(type, " action"), data, 'targets', 'value', 'payee');
|
|
223
|
+
return [2 /*return*/, this.prepareNomination(publicKey, data.tip || 0, data.targets, data.controller || publicKey, data.value, data.payee)];
|
|
224
|
+
case PolkadotStakingActionType_1.PolkadotStakingActionType.REBOND_NOMINATE:
|
|
225
|
+
(0, assert_1.assertFields)("".concat(type, " action"), data, 'targets', 'value');
|
|
226
|
+
return [2 /*return*/, this.prepareRebondNominate(publicKey, data.tip || 0, data.targets, data.value)];
|
|
227
|
+
case PolkadotStakingActionType_1.PolkadotStakingActionType.NOMINATE:
|
|
228
|
+
(0, assert_1.assertFields)("".concat(type, " action"), data, 'targets');
|
|
229
|
+
return [2 /*return*/, this.prepareNomination(publicKey, data.tip || 0, data.targets)];
|
|
230
|
+
case PolkadotStakingActionType_1.PolkadotStakingActionType.CANCEL_NOMINATION:
|
|
231
|
+
return [2 /*return*/, this.prepareScheduleUndelegate(publicKey, data.tip || 0, data.value)];
|
|
232
|
+
case PolkadotStakingActionType_1.PolkadotStakingActionType.CHANGE_NOMINATION:
|
|
233
|
+
(0, assert_1.assertFields)("".concat(type, " action"), data, 'targets');
|
|
234
|
+
return [2 /*return*/, this.prepareChangeValidator(publicKey, data.tip || 0, data.targets)];
|
|
235
|
+
case PolkadotStakingActionType_1.PolkadotStakingActionType.UNBOND:
|
|
236
|
+
(0, assert_1.assertFields)("".concat(type, " action"), data, 'value');
|
|
237
|
+
return [2 /*return*/, this.prepareUnbond(publicKey, data.tip || 0, data.value)];
|
|
238
|
+
case PolkadotStakingActionType_1.PolkadotStakingActionType.REBOND:
|
|
239
|
+
(0, assert_1.assertFields)("".concat(type, " action"), data, 'value');
|
|
240
|
+
return [2 /*return*/, this.prepareRebond(publicKey, data.tip || 0, data.value)];
|
|
241
|
+
case PolkadotStakingActionType_1.PolkadotStakingActionType.BOND_EXTRA:
|
|
242
|
+
(0, assert_1.assertFields)("".concat(type, " action"), data, 'value');
|
|
243
|
+
return [2 /*return*/, this.prepareBondExtra(publicKey, data.tip || 0, data.value)];
|
|
244
|
+
case PolkadotStakingActionType_1.PolkadotStakingActionType.REBOND_EXTRA:
|
|
245
|
+
(0, assert_1.assertFields)("".concat(type, " action"), data, 'value');
|
|
246
|
+
return [2 /*return*/, this.prepareRebondExtra(publicKey, data.tip || 0, data.value)];
|
|
247
|
+
case PolkadotStakingActionType_1.PolkadotStakingActionType.WITHDRAW_UNBONDED:
|
|
248
|
+
return [2 /*return*/, this.prepareWithdrawUnbonded(publicKey, data.tip || 0)];
|
|
249
|
+
case PolkadotStakingActionType_1.PolkadotStakingActionType.CHANGE_REWARD_DESTINATION:
|
|
250
|
+
return [2 /*return*/, Promise.reject('Unsupported delegator action.')];
|
|
251
|
+
case PolkadotStakingActionType_1.PolkadotStakingActionType.CHANGE_CONTROLLER:
|
|
252
|
+
return [2 /*return*/, Promise.reject('Unsupported delegator action.')];
|
|
253
|
+
default:
|
|
254
|
+
return [2 /*return*/, Promise.reject('Unsupported delegator action.')];
|
|
255
|
+
}
|
|
256
|
+
return [2 /*return*/];
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
};
|
|
260
|
+
PolkadotBaseProtocolImpl.prototype.prepareNomination = function (publicKey, tip, targets, controller, value, payee) {
|
|
261
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
262
|
+
var balance, available, bondFirst, encoded;
|
|
263
|
+
return __generator(this, function (_a) {
|
|
264
|
+
switch (_a.label) {
|
|
265
|
+
case 0: return [4 /*yield*/, this.accountController.getBalance(publicKey)];
|
|
266
|
+
case 1:
|
|
267
|
+
balance = _a.sent();
|
|
268
|
+
available = new bignumber_1.default(balance.transferable).minus(value || 0);
|
|
269
|
+
bondFirst = controller !== undefined && value !== undefined && payee !== undefined;
|
|
270
|
+
return [4 /*yield*/, this.transactionController.prepareSubmittableTransactions(publicKey, available, __spreadArray(__spreadArray([], (bondFirst
|
|
271
|
+
? [
|
|
272
|
+
// tslint:disable-next-line: no-object-literal-type-assertion
|
|
273
|
+
{
|
|
274
|
+
type: 'bond',
|
|
275
|
+
tip: tip,
|
|
276
|
+
args: {
|
|
277
|
+
controller: controller,
|
|
278
|
+
value: bignumber_1.default.isBigNumber(value) ? value : new bignumber_1.default(value),
|
|
279
|
+
payee: typeof payee === 'string' ? PolkadotPayee_1.PolkadotPayee[payee] : payee
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
]
|
|
283
|
+
: []), true), [
|
|
284
|
+
{
|
|
285
|
+
type: 'nominate',
|
|
286
|
+
tip: tip,
|
|
287
|
+
args: {
|
|
288
|
+
targets: typeof targets === 'string' ? [targets] : targets
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
], false))];
|
|
292
|
+
case 2:
|
|
293
|
+
encoded = _a.sent();
|
|
294
|
+
return [2 /*return*/, [(0, module_kit_1.newUnsignedTransaction)({ encoded: encoded })]];
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
};
|
|
299
|
+
PolkadotBaseProtocolImpl.prototype.prepareRebondNominate = function (publicKey, tip, targets, value) {
|
|
300
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
301
|
+
var _a, balance, lockedBalance, toDelegate, params, encoded;
|
|
302
|
+
return __generator(this, function (_b) {
|
|
303
|
+
switch (_b.label) {
|
|
304
|
+
case 0: return [4 /*yield*/, Promise.all([
|
|
305
|
+
this.accountController.getBalance(publicKey),
|
|
306
|
+
this.accountController.getUnlockingBalance(publicKey)
|
|
307
|
+
])];
|
|
308
|
+
case 1:
|
|
309
|
+
_a = _b.sent(), balance = _a[0], lockedBalance = _a[1];
|
|
310
|
+
toDelegate = bignumber_1.default.isBigNumber(value) ? value : new bignumber_1.default(value);
|
|
311
|
+
params = [];
|
|
312
|
+
if (toDelegate.gt(lockedBalance)) {
|
|
313
|
+
params.push({
|
|
314
|
+
type: 'rebond',
|
|
315
|
+
tip: tip,
|
|
316
|
+
args: {
|
|
317
|
+
value: lockedBalance
|
|
318
|
+
}
|
|
319
|
+
}, {
|
|
320
|
+
type: 'bond_extra',
|
|
321
|
+
tip: tip,
|
|
322
|
+
args: {
|
|
323
|
+
value: toDelegate.minus(lockedBalance)
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
else {
|
|
328
|
+
params.push({
|
|
329
|
+
type: 'rebond',
|
|
330
|
+
tip: tip,
|
|
331
|
+
args: {
|
|
332
|
+
value: toDelegate
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
params.push({
|
|
337
|
+
type: 'nominate',
|
|
338
|
+
tip: tip,
|
|
339
|
+
args: {
|
|
340
|
+
targets: typeof targets === 'string' ? [targets] : targets
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
return [4 /*yield*/, this.transactionController.prepareSubmittableTransactions(publicKey, balance.transferable, params)];
|
|
344
|
+
case 2:
|
|
345
|
+
encoded = _b.sent();
|
|
346
|
+
return [2 /*return*/, [(0, module_kit_1.newUnsignedTransaction)({ encoded: encoded })]];
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
};
|
|
351
|
+
PolkadotBaseProtocolImpl.prototype.prepareScheduleUndelegate = function (publicKey, tip, value) {
|
|
352
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
353
|
+
var balance, keepController, encoded;
|
|
354
|
+
return __generator(this, function (_a) {
|
|
355
|
+
switch (_a.label) {
|
|
356
|
+
case 0: return [4 /*yield*/, this.accountController.getBalance(publicKey)];
|
|
357
|
+
case 1:
|
|
358
|
+
balance = _a.sent();
|
|
359
|
+
keepController = value === undefined;
|
|
360
|
+
return [4 /*yield*/, this.transactionController.prepareSubmittableTransactions(publicKey, balance.transferable, __spreadArray([
|
|
361
|
+
{
|
|
362
|
+
type: 'cancel_nomination',
|
|
363
|
+
tip: tip,
|
|
364
|
+
args: {}
|
|
365
|
+
}
|
|
366
|
+
], (keepController
|
|
367
|
+
? []
|
|
368
|
+
: [
|
|
369
|
+
{
|
|
370
|
+
type: 'unbond',
|
|
371
|
+
tip: tip,
|
|
372
|
+
args: {
|
|
373
|
+
value: bignumber_1.default.isBigNumber(value) ? value : new bignumber_1.default(value)
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
]), true))];
|
|
377
|
+
case 2:
|
|
378
|
+
encoded = _a.sent();
|
|
379
|
+
return [2 /*return*/, [(0, module_kit_1.newUnsignedTransaction)({ encoded: encoded })]];
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
});
|
|
383
|
+
};
|
|
384
|
+
PolkadotBaseProtocolImpl.prototype.prepareChangeValidator = function (publicKey, tip, targets) {
|
|
385
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
386
|
+
var balance, encoded;
|
|
387
|
+
return __generator(this, function (_a) {
|
|
388
|
+
switch (_a.label) {
|
|
389
|
+
case 0: return [4 /*yield*/, this.accountController.getBalance(publicKey)];
|
|
390
|
+
case 1:
|
|
391
|
+
balance = _a.sent();
|
|
392
|
+
return [4 /*yield*/, this.transactionController.prepareSubmittableTransactions(publicKey, balance.transferable, [
|
|
393
|
+
{
|
|
394
|
+
type: 'nominate',
|
|
395
|
+
tip: tip,
|
|
396
|
+
args: {
|
|
397
|
+
targets: typeof targets === 'string' ? [targets] : targets
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
])];
|
|
401
|
+
case 2:
|
|
402
|
+
encoded = _a.sent();
|
|
403
|
+
return [2 /*return*/, [(0, module_kit_1.newUnsignedTransaction)({ encoded: encoded })]];
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
});
|
|
407
|
+
};
|
|
408
|
+
PolkadotBaseProtocolImpl.prototype.prepareUnbond = function (publicKey, tip, value) {
|
|
409
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
410
|
+
var balance, encoded;
|
|
411
|
+
return __generator(this, function (_a) {
|
|
412
|
+
switch (_a.label) {
|
|
413
|
+
case 0: return [4 /*yield*/, this.accountController.getBalance(publicKey)];
|
|
414
|
+
case 1:
|
|
415
|
+
balance = _a.sent();
|
|
416
|
+
return [4 /*yield*/, this.transactionController.prepareSubmittableTransactions(publicKey, balance.transferable, [
|
|
417
|
+
{
|
|
418
|
+
type: 'unbond',
|
|
419
|
+
tip: tip,
|
|
420
|
+
args: {
|
|
421
|
+
value: bignumber_1.default.isBigNumber(value) ? value : new bignumber_1.default(value)
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
])];
|
|
425
|
+
case 2:
|
|
426
|
+
encoded = _a.sent();
|
|
427
|
+
return [2 /*return*/, [(0, module_kit_1.newUnsignedTransaction)({ encoded: encoded })]];
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
});
|
|
431
|
+
};
|
|
432
|
+
PolkadotBaseProtocolImpl.prototype.prepareRebond = function (publicKey, tip, value) {
|
|
433
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
434
|
+
var balance, encoded;
|
|
435
|
+
return __generator(this, function (_a) {
|
|
436
|
+
switch (_a.label) {
|
|
437
|
+
case 0: return [4 /*yield*/, this.accountController.getBalance(publicKey)];
|
|
438
|
+
case 1:
|
|
439
|
+
balance = _a.sent();
|
|
440
|
+
return [4 /*yield*/, this.transactionController.prepareSubmittableTransactions(publicKey, balance.transferable, [
|
|
441
|
+
{
|
|
442
|
+
type: 'rebond',
|
|
443
|
+
tip: tip,
|
|
444
|
+
args: {
|
|
445
|
+
value: bignumber_1.default.isBigNumber(value) ? value : new bignumber_1.default(value)
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
])];
|
|
449
|
+
case 2:
|
|
450
|
+
encoded = _a.sent();
|
|
451
|
+
return [2 /*return*/, [(0, module_kit_1.newUnsignedTransaction)({ encoded: encoded })]];
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
});
|
|
455
|
+
};
|
|
456
|
+
PolkadotBaseProtocolImpl.prototype.prepareBondExtra = function (publicKey, tip, value) {
|
|
457
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
458
|
+
var balance, encoded;
|
|
459
|
+
return __generator(this, function (_a) {
|
|
460
|
+
switch (_a.label) {
|
|
461
|
+
case 0: return [4 /*yield*/, this.accountController.getBalance(publicKey)];
|
|
462
|
+
case 1:
|
|
463
|
+
balance = _a.sent();
|
|
464
|
+
return [4 /*yield*/, this.transactionController.prepareSubmittableTransactions(publicKey, balance.transferable, [
|
|
465
|
+
{
|
|
466
|
+
type: 'bond_extra',
|
|
467
|
+
tip: tip,
|
|
468
|
+
args: {
|
|
469
|
+
value: bignumber_1.default.isBigNumber(value) ? value : new bignumber_1.default(value)
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
])];
|
|
473
|
+
case 2:
|
|
474
|
+
encoded = _a.sent();
|
|
475
|
+
return [2 /*return*/, [(0, module_kit_1.newUnsignedTransaction)({ encoded: encoded })]];
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
});
|
|
479
|
+
};
|
|
480
|
+
PolkadotBaseProtocolImpl.prototype.prepareRebondExtra = function (publicKey, tip, value) {
|
|
481
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
482
|
+
var _a, balance, lockedBalance, toDelegate, configs, encoded;
|
|
483
|
+
return __generator(this, function (_b) {
|
|
484
|
+
switch (_b.label) {
|
|
485
|
+
case 0: return [4 /*yield*/, Promise.all([
|
|
486
|
+
this.accountController.getBalance(publicKey),
|
|
487
|
+
this.accountController.getUnlockingBalance(publicKey)
|
|
488
|
+
])];
|
|
489
|
+
case 1:
|
|
490
|
+
_a = _b.sent(), balance = _a[0], lockedBalance = _a[1];
|
|
491
|
+
toDelegate = bignumber_1.default.isBigNumber(value) ? value : new bignumber_1.default(value);
|
|
492
|
+
configs = toDelegate.gt(lockedBalance)
|
|
493
|
+
? [
|
|
494
|
+
{
|
|
495
|
+
type: 'rebond',
|
|
496
|
+
tip: tip,
|
|
497
|
+
args: {
|
|
498
|
+
value: lockedBalance
|
|
499
|
+
}
|
|
500
|
+
},
|
|
501
|
+
{
|
|
502
|
+
type: 'bond_extra',
|
|
503
|
+
tip: tip,
|
|
504
|
+
args: {
|
|
505
|
+
value: toDelegate.minus(lockedBalance)
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
]
|
|
509
|
+
: [
|
|
510
|
+
{
|
|
511
|
+
type: 'rebond',
|
|
512
|
+
tip: tip,
|
|
513
|
+
args: {
|
|
514
|
+
value: toDelegate
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
];
|
|
518
|
+
return [4 /*yield*/, this.transactionController.prepareSubmittableTransactions(publicKey, balance.transferable, configs)];
|
|
519
|
+
case 2:
|
|
520
|
+
encoded = _b.sent();
|
|
521
|
+
return [2 /*return*/, [(0, module_kit_1.newUnsignedTransaction)({ encoded: encoded })]];
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
});
|
|
525
|
+
};
|
|
526
|
+
PolkadotBaseProtocolImpl.prototype.prepareWithdrawUnbonded = function (publicKey, tip) {
|
|
527
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
528
|
+
var _a, balance, slashingSpansNumber, encoded;
|
|
529
|
+
return __generator(this, function (_b) {
|
|
530
|
+
switch (_b.label) {
|
|
531
|
+
case 0: return [4 /*yield*/, Promise.all([
|
|
532
|
+
this.accountController.getBalance(publicKey),
|
|
533
|
+
this.accountController.getSlashingSpansNumber(publicKey)
|
|
534
|
+
])];
|
|
535
|
+
case 1:
|
|
536
|
+
_a = _b.sent(), balance = _a[0], slashingSpansNumber = _a[1];
|
|
537
|
+
return [4 /*yield*/, this.transactionController.prepareSubmittableTransactions(publicKey, balance.transferable, [
|
|
538
|
+
{
|
|
539
|
+
type: 'withdraw_unbonded',
|
|
540
|
+
tip: tip,
|
|
541
|
+
args: { slashingSpansNumber: slashingSpansNumber }
|
|
542
|
+
}
|
|
543
|
+
])];
|
|
544
|
+
case 2:
|
|
545
|
+
encoded = _b.sent();
|
|
546
|
+
return [2 /*return*/, [(0, module_kit_1.newUnsignedTransaction)({ encoded: encoded })]];
|
|
547
|
+
}
|
|
548
|
+
});
|
|
549
|
+
});
|
|
550
|
+
};
|
|
551
|
+
// Custom
|
|
552
|
+
PolkadotBaseProtocolImpl.prototype.getNominatorDetails = function (address, validators) {
|
|
553
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
554
|
+
return __generator(this, function (_a) {
|
|
555
|
+
return [2 /*return*/, this.accountController.getNominatorDetails(address, validators)];
|
|
556
|
+
});
|
|
557
|
+
});
|
|
558
|
+
};
|
|
559
|
+
PolkadotBaseProtocolImpl.prototype.getValidatorDetails = function (address) {
|
|
560
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
561
|
+
return __generator(this, function (_a) {
|
|
562
|
+
return [2 /*return*/, this.accountController.getValidatorDetails(address)];
|
|
563
|
+
});
|
|
564
|
+
});
|
|
565
|
+
};
|
|
566
|
+
PolkadotBaseProtocolImpl.prototype.getNominationStatus = function (address, validator, era) {
|
|
567
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
568
|
+
return __generator(this, function (_a) {
|
|
569
|
+
return [2 /*return*/, this.accountController.getNominationStatus(address, validator, era)];
|
|
570
|
+
});
|
|
571
|
+
});
|
|
572
|
+
};
|
|
573
|
+
PolkadotBaseProtocolImpl.prototype.getStakingBalance = function (address) {
|
|
574
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
575
|
+
var stakingBalance;
|
|
576
|
+
return __generator(this, function (_a) {
|
|
577
|
+
switch (_a.label) {
|
|
578
|
+
case 0: return [4 /*yield*/, this.accountController.getStakingBalance(address)];
|
|
579
|
+
case 1:
|
|
580
|
+
stakingBalance = _a.sent();
|
|
581
|
+
if (stakingBalance === undefined) {
|
|
582
|
+
return [2 /*return*/, undefined];
|
|
583
|
+
}
|
|
584
|
+
return [2 /*return*/, {
|
|
585
|
+
bonded: (0, module_kit_1.newAmount)(stakingBalance.bonded, 'blockchain'),
|
|
586
|
+
unlocking: (0, module_kit_1.newAmount)(stakingBalance.unlocking, 'blockchain')
|
|
587
|
+
}];
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
});
|
|
591
|
+
};
|
|
592
|
+
PolkadotBaseProtocolImpl.prototype.getMinNominatorBond = function () {
|
|
593
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
594
|
+
var minNominatorBond;
|
|
595
|
+
return __generator(this, function (_a) {
|
|
596
|
+
switch (_a.label) {
|
|
597
|
+
case 0: return [4 /*yield*/, this.nodeClient.getMinNominatorBond()];
|
|
598
|
+
case 1:
|
|
599
|
+
minNominatorBond = _a.sent();
|
|
600
|
+
return [2 /*return*/, (0, module_kit_1.newAmount)(minNominatorBond !== null && minNominatorBond !== void 0 ? minNominatorBond : 0, 'blockchain')];
|
|
601
|
+
}
|
|
602
|
+
});
|
|
603
|
+
});
|
|
604
|
+
};
|
|
605
|
+
PolkadotBaseProtocolImpl.prototype.getExistentialDeposit = function () {
|
|
606
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
607
|
+
var existentialDeposit;
|
|
608
|
+
return __generator(this, function (_a) {
|
|
609
|
+
switch (_a.label) {
|
|
610
|
+
case 0: return [4 /*yield*/, this.nodeClient.getExistentialDeposit()];
|
|
611
|
+
case 1:
|
|
612
|
+
existentialDeposit = _a.sent();
|
|
613
|
+
return [2 /*return*/, (0, module_kit_1.newAmount)(existentialDeposit !== null && existentialDeposit !== void 0 ? existentialDeposit : 0, 'blockchain')];
|
|
614
|
+
}
|
|
615
|
+
});
|
|
616
|
+
});
|
|
617
|
+
};
|
|
618
|
+
PolkadotBaseProtocolImpl.prototype.getFutureStakingTransactionsFee = function (address) {
|
|
619
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
620
|
+
var futureTransactions, feeEstimation;
|
|
621
|
+
return __generator(this, function (_a) {
|
|
622
|
+
switch (_a.label) {
|
|
623
|
+
case 0: return [4 /*yield*/, this.getFutureRequiredTransactions(address, 'delegate')];
|
|
624
|
+
case 1:
|
|
625
|
+
futureTransactions = _a.sent();
|
|
626
|
+
return [4 /*yield*/, this.transactionController.estimateTransactionFees(address, futureTransactions)];
|
|
627
|
+
case 2:
|
|
628
|
+
feeEstimation = _a.sent();
|
|
629
|
+
return [2 /*return*/, (0, module_kit_1.newAmount)(feeEstimation, 'blockchain')];
|
|
630
|
+
}
|
|
631
|
+
});
|
|
632
|
+
});
|
|
633
|
+
};
|
|
634
|
+
PolkadotBaseProtocolImpl.prototype.getFutureRequiredTransactions = function (accountId, intention) {
|
|
635
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
636
|
+
var results, isBonded, isNominating, balance, unlockingBalance, transferableBalance, stakingBalance, isUnbonding, requiredTransactions;
|
|
637
|
+
return __generator(this, function (_a) {
|
|
638
|
+
switch (_a.label) {
|
|
639
|
+
case 0: return [4 /*yield*/, Promise.all([
|
|
640
|
+
this.accountController.isBonded(accountId),
|
|
641
|
+
this.accountController.isDelegating(accountId),
|
|
642
|
+
this.accountController.getBalance(accountId),
|
|
643
|
+
this.accountController.getUnlockingBalance(accountId)
|
|
644
|
+
])];
|
|
645
|
+
case 1:
|
|
646
|
+
results = _a.sent();
|
|
647
|
+
isBonded = results[0];
|
|
648
|
+
isNominating = results[1];
|
|
649
|
+
balance = results[2];
|
|
650
|
+
unlockingBalance = results[3];
|
|
651
|
+
transferableBalance = balance.transferable.minus(balance.existentialDeposit);
|
|
652
|
+
stakingBalance = balance.transferable;
|
|
653
|
+
isUnbonding = unlockingBalance.gt(0);
|
|
654
|
+
requiredTransactions = [];
|
|
655
|
+
if (intention === 'transfer') {
|
|
656
|
+
requiredTransactions.push([
|
|
657
|
+
'transfer',
|
|
658
|
+
{
|
|
659
|
+
to: v1_1.SubstrateSS58Address.createPlaceholder(),
|
|
660
|
+
value: transferableBalance
|
|
661
|
+
}
|
|
662
|
+
]);
|
|
663
|
+
}
|
|
664
|
+
if (!isBonded && !isUnbonding && intention === 'delegate') {
|
|
665
|
+
// not delegated & unbond
|
|
666
|
+
requiredTransactions.push([
|
|
667
|
+
'bond',
|
|
668
|
+
{
|
|
669
|
+
// controller: SubstrateSS58Address.createPlaceholder(),
|
|
670
|
+
value: stakingBalance,
|
|
671
|
+
payee: 0
|
|
672
|
+
}
|
|
673
|
+
], [
|
|
674
|
+
'nominate',
|
|
675
|
+
{
|
|
676
|
+
targets: [v1_1.SubstrateSS58Address.createPlaceholder()]
|
|
677
|
+
}
|
|
678
|
+
], ['cancel_nomination', {}], [
|
|
679
|
+
'unbond',
|
|
680
|
+
{
|
|
681
|
+
value: stakingBalance
|
|
682
|
+
}
|
|
683
|
+
], [
|
|
684
|
+
'withdraw_unbonded',
|
|
685
|
+
{
|
|
686
|
+
slashingSpansNumber: 0
|
|
687
|
+
}
|
|
688
|
+
]);
|
|
689
|
+
}
|
|
690
|
+
else if (isUnbonding && intention === 'delegate') {
|
|
691
|
+
requiredTransactions.push([
|
|
692
|
+
'rebond',
|
|
693
|
+
{
|
|
694
|
+
value: unlockingBalance
|
|
695
|
+
}
|
|
696
|
+
], [
|
|
697
|
+
'nominate',
|
|
698
|
+
{
|
|
699
|
+
targets: [v1_1.SubstrateSS58Address.createPlaceholder()]
|
|
700
|
+
}
|
|
701
|
+
], ['cancel_nomination', {}], [
|
|
702
|
+
'unbond',
|
|
703
|
+
{
|
|
704
|
+
value: stakingBalance.plus(unlockingBalance)
|
|
705
|
+
}
|
|
706
|
+
], [
|
|
707
|
+
'withdraw_unbonded',
|
|
708
|
+
{
|
|
709
|
+
slashingSpansNumber: 0
|
|
710
|
+
}
|
|
711
|
+
]);
|
|
712
|
+
}
|
|
713
|
+
else if (isBonded) {
|
|
714
|
+
requiredTransactions.push([
|
|
715
|
+
'unbond',
|
|
716
|
+
{
|
|
717
|
+
value: stakingBalance
|
|
718
|
+
}
|
|
719
|
+
], [
|
|
720
|
+
'withdraw_unbonded',
|
|
721
|
+
{
|
|
722
|
+
slashingSpansNumber: 0
|
|
723
|
+
}
|
|
724
|
+
]);
|
|
725
|
+
}
|
|
726
|
+
if (isNominating) {
|
|
727
|
+
requiredTransactions.push(['cancel_nomination', {}]);
|
|
728
|
+
}
|
|
729
|
+
return [2 /*return*/, requiredTransactions];
|
|
730
|
+
}
|
|
731
|
+
});
|
|
732
|
+
});
|
|
733
|
+
};
|
|
734
|
+
return PolkadotBaseProtocolImpl;
|
|
735
|
+
}(v1_1.SubstrateStakingProtocolImpl));
|
|
736
|
+
exports.PolkadotBaseProtocolImpl = PolkadotBaseProtocolImpl;
|
|
737
|
+
//# sourceMappingURL=PolkadotBaseProtocol.js.map
|