@airgap/polkadot 0.13.45-beta.3 → 0.13.45-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/v0/index.js +6 -6
- package/v0/index.js.map +1 -1
- package/v0/protocol/kusama/KusamaProtocol.js +41 -22
- package/v0/protocol/kusama/KusamaProtocol.js.map +1 -1
- package/v0/protocol/kusama/KusamaProtocolOptions.js +70 -33
- package/v0/protocol/kusama/KusamaProtocolOptions.js.map +1 -1
- package/v0/protocol/polkadot/PolkadotProtocol.js +42 -23
- package/v0/protocol/polkadot/PolkadotProtocol.js.map +1 -1
- package/v0/protocol/polkadot/PolkadotProtocolOptions.js +70 -33
- package/v0/protocol/polkadot/PolkadotProtocolOptions.js.map +1 -1
- package/v1/controller/PolkadotAccountController.js +648 -373
- package/v1/controller/PolkadotAccountController.js.map +1 -1
- package/v1/controller/PolkadotTransactionController.js +23 -3
- package/v1/controller/PolkadotTransactionController.js.map +1 -1
- package/v1/data/staking/PolkadotActiveEraInfo.js +11 -10
- package/v1/data/staking/PolkadotActiveEraInfo.js.map +1 -1
- package/v1/data/staking/PolkadotEraRewardPoints.js +13 -10
- package/v1/data/staking/PolkadotEraRewardPoints.js.map +1 -1
- package/v1/data/staking/PolkadotExposure.js +14 -11
- package/v1/data/staking/PolkadotExposure.js.map +1 -1
- package/v1/data/staking/PolkadotNominationStatus.js +1 -1
- package/v1/data/staking/PolkadotNominationStatus.js.map +1 -1
- package/v1/data/staking/PolkadotNominations.js +12 -11
- package/v1/data/staking/PolkadotNominations.js.map +1 -1
- package/v1/data/staking/PolkadotNominatorDetails.d.ts +1 -1
- package/v1/data/staking/PolkadotPayee.js +1 -1
- package/v1/data/staking/PolkadotPayee.js.map +1 -1
- package/v1/data/staking/PolkadotSlashingSpans.js +13 -12
- package/v1/data/staking/PolkadotSlashingSpans.js.map +1 -1
- package/v1/data/staking/PolkadotStakingActionType.js +1 -1
- package/v1/data/staking/PolkadotStakingActionType.js.map +1 -1
- package/v1/data/staking/PolkadotStakingLedger.js +16 -13
- package/v1/data/staking/PolkadotStakingLedger.js.map +1 -1
- package/v1/data/staking/PolkadotValidatorDetails.d.ts +1 -1
- package/v1/data/staking/PolkadotValidatorPrefs.js +10 -9
- package/v1/data/staking/PolkadotValidatorPrefs.js.map +1 -1
- package/v1/data/transaction/method/args.js +271 -146
- package/v1/data/transaction/method/args.js.map +1 -1
- package/v1/data/transaction/transaction.js +22 -11
- package/v1/data/transaction/transaction.js.map +1 -1
- package/v1/index.js +6 -6
- package/v1/index.js.map +1 -1
- package/v1/module/PolkadotModule.d.ts +1 -1
- package/v1/module/PolkadotModule.js +98 -40
- package/v1/module/PolkadotModule.js.map +1 -1
- package/v1/module.js +3 -2
- package/v1/module.js.map +1 -1
- package/v1/node/PolkadotNodeClient.js +284 -101
- package/v1/node/PolkadotNodeClient.js.map +1 -1
- package/v1/protocol/KusamaProtocol.js +54 -28
- package/v1/protocol/KusamaProtocol.js.map +1 -1
- package/v1/protocol/PolkadotBaseProtocol.js +701 -409
- package/v1/protocol/PolkadotBaseProtocol.js.map +1 -1
- package/v1/protocol/PolkadotProtocol.js +51 -20
- package/v1/protocol/PolkadotProtocol.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 +2 -2
|
@@ -1,445 +1,737 @@
|
|
|
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
|
+
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
|
+
};
|
|
2
62
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
63
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
64
|
};
|
|
5
65
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
66
|
exports.PolkadotBaseProtocolImpl = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
67
|
+
var bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
|
|
68
|
+
var assert_1 = require("@airgap/coinlib-core/utils/assert");
|
|
69
|
+
var module_kit_1 = require("@airgap/module-kit");
|
|
70
|
+
var v1_1 = require("@airgap/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");
|
|
16
76
|
// Implementation
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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;
|
|
25
88
|
}
|
|
26
89
|
// Staking
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return this.accountController.getCurrentValidators(publicKey);
|
|
36
|
-
}
|
|
37
|
-
async getCurrentDelegateesForAddress(address) {
|
|
38
|
-
return this.accountController.getCurrentValidators(address);
|
|
39
|
-
}
|
|
40
|
-
async getDelegateeDetails(address) {
|
|
41
|
-
const validatorDetails = await this.accountController.getValidatorDetails(address);
|
|
42
|
-
return {
|
|
43
|
-
name: validatorDetails.name || '',
|
|
44
|
-
status: validatorDetails.status || '',
|
|
45
|
-
address
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
async isPublicKeyDelegating(publicKey) {
|
|
49
|
-
return this.accountController.isDelegating(publicKey);
|
|
50
|
-
}
|
|
51
|
-
async isAddressDelegating(address) {
|
|
52
|
-
return this.accountController.isDelegating(address);
|
|
53
|
-
}
|
|
54
|
-
async getDelegatorDetailsFromPublicKey(publicKey) {
|
|
55
|
-
const address = await this.getAddressFromPublicKey(publicKey);
|
|
56
|
-
return this.getDelegatorDetailsFromAddress(address);
|
|
57
|
-
}
|
|
58
|
-
async getDelegatorDetailsFromAddress(address) {
|
|
59
|
-
return this.accountController.getNominatorDetails(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
|
-
const [nominatorDetails, validatorsDetails] = await Promise.all([
|
|
67
|
-
this.accountController.getNominatorDetails(address, delegatees),
|
|
68
|
-
Promise.all(delegatees.map((validator) => this.accountController.getValidatorDetails(validator)))
|
|
69
|
-
]);
|
|
70
|
-
nominatorDetails.rewards =
|
|
71
|
-
nominatorDetails.delegatees.length > 0 && nominatorDetails.stakingDetails
|
|
72
|
-
? nominatorDetails.stakingDetails.rewards.map((reward) => ({
|
|
73
|
-
index: reward.eraIndex,
|
|
74
|
-
amount: reward.amount,
|
|
75
|
-
timestamp: reward.timestamp
|
|
76
|
-
}))
|
|
77
|
-
: [];
|
|
78
|
-
return {
|
|
79
|
-
delegator: nominatorDetails,
|
|
80
|
-
delegatees: validatorsDetails
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
// tslint:disable-next-line: cyclomatic-complexity
|
|
84
|
-
async prepareDelegatorActionFromPublicKey(publicKey, type, data) {
|
|
85
|
-
if (!data) {
|
|
86
|
-
data = {};
|
|
87
|
-
}
|
|
88
|
-
switch (type) {
|
|
89
|
-
case PolkadotStakingActionType_1.PolkadotStakingActionType.BOND_NOMINATE:
|
|
90
|
-
(0, assert_1.assertFields)(`${type} action`, data, 'targets', 'value', 'payee');
|
|
91
|
-
return this.prepareNomination(publicKey, data.tip || 0, data.targets, data.controller || publicKey, data.value, data.payee);
|
|
92
|
-
case PolkadotStakingActionType_1.PolkadotStakingActionType.REBOND_NOMINATE:
|
|
93
|
-
(0, assert_1.assertFields)(`${type} action`, data, 'targets', 'value');
|
|
94
|
-
return this.prepareRebondNominate(publicKey, data.tip || 0, data.targets, data.value);
|
|
95
|
-
case PolkadotStakingActionType_1.PolkadotStakingActionType.NOMINATE:
|
|
96
|
-
(0, assert_1.assertFields)(`${type} action`, data, 'targets');
|
|
97
|
-
return this.prepareNomination(publicKey, data.tip || 0, data.targets);
|
|
98
|
-
case PolkadotStakingActionType_1.PolkadotStakingActionType.CANCEL_NOMINATION:
|
|
99
|
-
return this.prepareScheduleUndelegate(publicKey, data.tip || 0, data.value);
|
|
100
|
-
case PolkadotStakingActionType_1.PolkadotStakingActionType.CHANGE_NOMINATION:
|
|
101
|
-
(0, assert_1.assertFields)(`${type} action`, data, 'targets');
|
|
102
|
-
return this.prepareChangeValidator(publicKey, data.tip || 0, data.targets);
|
|
103
|
-
case PolkadotStakingActionType_1.PolkadotStakingActionType.UNBOND:
|
|
104
|
-
(0, assert_1.assertFields)(`${type} action`, data, 'value');
|
|
105
|
-
return this.prepareUnbond(publicKey, data.tip || 0, data.value);
|
|
106
|
-
case PolkadotStakingActionType_1.PolkadotStakingActionType.REBOND:
|
|
107
|
-
(0, assert_1.assertFields)(`${type} action`, data, 'value');
|
|
108
|
-
return this.prepareRebond(publicKey, data.tip || 0, data.value);
|
|
109
|
-
case PolkadotStakingActionType_1.PolkadotStakingActionType.BOND_EXTRA:
|
|
110
|
-
(0, assert_1.assertFields)(`${type} action`, data, 'value');
|
|
111
|
-
return this.prepareBondExtra(publicKey, data.tip || 0, data.value);
|
|
112
|
-
case PolkadotStakingActionType_1.PolkadotStakingActionType.REBOND_EXTRA:
|
|
113
|
-
(0, assert_1.assertFields)(`${type} action`, data, 'value');
|
|
114
|
-
return this.prepareRebondExtra(publicKey, data.tip || 0, data.value);
|
|
115
|
-
case PolkadotStakingActionType_1.PolkadotStakingActionType.WITHDRAW_UNBONDED:
|
|
116
|
-
return this.prepareWithdrawUnbonded(publicKey, data.tip || 0);
|
|
117
|
-
case PolkadotStakingActionType_1.PolkadotStakingActionType.CHANGE_REWARD_DESTINATION:
|
|
118
|
-
return Promise.reject('Unsupported delegator action.');
|
|
119
|
-
case PolkadotStakingActionType_1.PolkadotStakingActionType.CHANGE_CONTROLLER:
|
|
120
|
-
return Promise.reject('Unsupported delegator action.');
|
|
121
|
-
default:
|
|
122
|
-
return Promise.reject('Unsupported delegator action.');
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
async prepareNomination(publicKey, tip, targets, controller, value, payee) {
|
|
126
|
-
const balance = await this.accountController.getBalance(publicKey);
|
|
127
|
-
const available = new bignumber_1.default(balance.transferable).minus(value || 0);
|
|
128
|
-
const bondFirst = controller !== undefined && value !== undefined && payee !== undefined;
|
|
129
|
-
const encoded = await this.transactionController.prepareSubmittableTransactions(publicKey, available, [
|
|
130
|
-
...(bondFirst
|
|
131
|
-
? [
|
|
132
|
-
// tslint:disable-next-line: no-object-literal-type-assertion
|
|
133
|
-
{
|
|
134
|
-
type: 'bond',
|
|
135
|
-
tip,
|
|
136
|
-
args: {
|
|
137
|
-
controller,
|
|
138
|
-
value: bignumber_1.default.isBigNumber(value) ? value : new bignumber_1.default(value),
|
|
139
|
-
payee: typeof payee === 'string' ? PolkadotPayee_1.PolkadotPayee[payee] : payee
|
|
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];
|
|
140
98
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
type: 'nominate',
|
|
146
|
-
tip,
|
|
147
|
-
args: {
|
|
148
|
-
targets: typeof targets === 'string' ? [targets] : targets
|
|
99
|
+
return [4 /*yield*/, this.nodeClient.getValidators()];
|
|
100
|
+
case 1:
|
|
101
|
+
validators = _a.sent();
|
|
102
|
+
return [2 /*return*/, validators ? validators[0].asString() : ''];
|
|
149
103
|
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
+
}];
|
|
167
134
|
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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)];
|
|
173
161
|
}
|
|
174
162
|
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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)];
|
|
182
181
|
}
|
|
183
182
|
});
|
|
184
|
-
}
|
|
185
|
-
params.push({
|
|
186
|
-
type: 'nominate',
|
|
187
|
-
tip,
|
|
188
|
-
args: {
|
|
189
|
-
targets: typeof targets === 'string' ? [targets] : targets
|
|
190
|
-
}
|
|
191
183
|
});
|
|
192
|
-
|
|
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
|
-
async prepareChangeValidator(publicKey, tip, targets) {
|
|
219
|
-
const balance = await this.accountController.getBalance(publicKey);
|
|
220
|
-
const encoded = await this.transactionController.prepareSubmittableTransactions(publicKey, balance.transferable, [
|
|
221
|
-
{
|
|
222
|
-
type: 'nominate',
|
|
223
|
-
tip,
|
|
224
|
-
args: {
|
|
225
|
-
targets: typeof targets === 'string' ? [targets] : targets
|
|
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
|
+
}];
|
|
226
209
|
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
tip,
|
|
237
|
-
args: {
|
|
238
|
-
value: bignumber_1.default.isBigNumber(value) ? value : new bignumber_1.default(value)
|
|
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 = {};
|
|
239
219
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
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.')];
|
|
252
255
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
{
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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 })]];
|
|
265
295
|
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
this
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
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 })]];
|
|
291
347
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
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 })]];
|
|
300
380
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
this
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
return this.accountController.getValidatorDetails(address);
|
|
325
|
-
}
|
|
326
|
-
async getNominationStatus(address, validator, era) {
|
|
327
|
-
return this.accountController.getNominationStatus(address, validator, era);
|
|
328
|
-
}
|
|
329
|
-
async getStakingBalance(address) {
|
|
330
|
-
const stakingBalance = await this.accountController.getStakingBalance(address);
|
|
331
|
-
if (stakingBalance === undefined) {
|
|
332
|
-
return undefined;
|
|
333
|
-
}
|
|
334
|
-
return {
|
|
335
|
-
bonded: (0, module_kit_1.newAmount)(stakingBalance.bonded, 'blockchain'),
|
|
336
|
-
unlocking: (0, module_kit_1.newAmount)(stakingBalance.unlocking, 'blockchain')
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
|
-
async getMinNominatorBond() {
|
|
340
|
-
const minNominatorBond = await this.nodeClient.getMinNominatorBond();
|
|
341
|
-
return (0, module_kit_1.newAmount)(minNominatorBond ?? 0, 'blockchain');
|
|
342
|
-
}
|
|
343
|
-
async getExistentialDeposit() {
|
|
344
|
-
const existentialDeposit = await this.nodeClient.getExistentialDeposit();
|
|
345
|
-
return (0, module_kit_1.newAmount)(existentialDeposit ?? 0, 'blockchain');
|
|
346
|
-
}
|
|
347
|
-
async getFutureStakingTransactionsFee(address) {
|
|
348
|
-
const futureTransactions = await this.getFutureRequiredTransactions(address, 'delegate');
|
|
349
|
-
const feeEstimation = await this.transactionController.estimateTransactionFees(address, futureTransactions);
|
|
350
|
-
return (0, module_kit_1.newAmount)(feeEstimation, 'blockchain');
|
|
351
|
-
}
|
|
352
|
-
async getFutureRequiredTransactions(accountId, intention) {
|
|
353
|
-
const results = await Promise.all([
|
|
354
|
-
this.accountController.isBonded(accountId),
|
|
355
|
-
this.accountController.isDelegating(accountId),
|
|
356
|
-
this.accountController.getBalance(accountId),
|
|
357
|
-
this.accountController.getUnlockingBalance(accountId)
|
|
358
|
-
]);
|
|
359
|
-
const isBonded = results[0];
|
|
360
|
-
const isNominating = results[1];
|
|
361
|
-
const balance = results[2];
|
|
362
|
-
const unlockingBalance = results[3];
|
|
363
|
-
const transferableBalance = balance.transferable.minus(balance.existentialDeposit);
|
|
364
|
-
const stakingBalance = balance.transferable;
|
|
365
|
-
const isUnbonding = unlockingBalance.gt(0);
|
|
366
|
-
const requiredTransactions = [];
|
|
367
|
-
if (intention === 'transfer') {
|
|
368
|
-
requiredTransactions.push([
|
|
369
|
-
'transfer',
|
|
370
|
-
{
|
|
371
|
-
to: v1_1.SubstrateSS58Address.createPlaceholder(),
|
|
372
|
-
value: transferableBalance
|
|
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 })]];
|
|
373
404
|
}
|
|
374
|
-
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
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 })]];
|
|
384
428
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
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 })]];
|
|
389
452
|
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
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 })]];
|
|
394
476
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
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 })]];
|
|
399
522
|
}
|
|
400
|
-
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
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 })]];
|
|
407
547
|
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
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
|
+
}];
|
|
412
588
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
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')];
|
|
417
601
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
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')];
|
|
422
614
|
}
|
|
423
|
-
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
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')];
|
|
430
630
|
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
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];
|
|
435
730
|
}
|
|
436
|
-
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
return requiredTransactions;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
731
|
+
});
|
|
732
|
+
});
|
|
733
|
+
};
|
|
734
|
+
return PolkadotBaseProtocolImpl;
|
|
735
|
+
}(v1_1.SubstrateStakingProtocolImpl));
|
|
444
736
|
exports.PolkadotBaseProtocolImpl = PolkadotBaseProtocolImpl;
|
|
445
737
|
//# sourceMappingURL=PolkadotBaseProtocol.js.map
|