@airgap/polkadot 0.13.45-beta.2 → 0.13.45-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/v0/index.js +6 -6
- package/v0/index.js.map +1 -1
- package/v0/protocol/kusama/KusamaProtocol.js +22 -41
- package/v0/protocol/kusama/KusamaProtocol.js.map +1 -1
- package/v0/protocol/kusama/KusamaProtocolOptions.js +33 -70
- package/v0/protocol/kusama/KusamaProtocolOptions.js.map +1 -1
- package/v0/protocol/polkadot/PolkadotProtocol.js +23 -42
- package/v0/protocol/polkadot/PolkadotProtocol.js.map +1 -1
- package/v0/protocol/polkadot/PolkadotProtocolOptions.js +33 -70
- package/v0/protocol/polkadot/PolkadotProtocolOptions.js.map +1 -1
- package/v1/controller/PolkadotAccountController.js +373 -648
- package/v1/controller/PolkadotAccountController.js.map +1 -1
- package/v1/controller/PolkadotTransactionController.js +3 -23
- package/v1/controller/PolkadotTransactionController.js.map +1 -1
- package/v1/data/staking/PolkadotActiveEraInfo.js +10 -11
- package/v1/data/staking/PolkadotActiveEraInfo.js.map +1 -1
- package/v1/data/staking/PolkadotEraRewardPoints.js +10 -13
- package/v1/data/staking/PolkadotEraRewardPoints.js.map +1 -1
- package/v1/data/staking/PolkadotExposure.js +11 -14
- 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 +11 -12
- 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 +12 -13
- 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 +13 -16
- package/v1/data/staking/PolkadotStakingLedger.js.map +1 -1
- package/v1/data/staking/PolkadotValidatorDetails.d.ts +1 -1
- package/v1/data/staking/PolkadotValidatorPrefs.js +9 -10
- package/v1/data/staking/PolkadotValidatorPrefs.js.map +1 -1
- package/v1/data/transaction/method/args.js +146 -271
- package/v1/data/transaction/method/args.js.map +1 -1
- package/v1/data/transaction/transaction.js +11 -22
- 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 +40 -98
- package/v1/module/PolkadotModule.js.map +1 -1
- package/v1/module.js +2 -3
- package/v1/module.js.map +1 -1
- package/v1/node/PolkadotNodeClient.js +101 -284
- package/v1/node/PolkadotNodeClient.js.map +1 -1
- package/v1/protocol/KusamaProtocol.js +28 -54
- package/v1/protocol/KusamaProtocol.js.map +1 -1
- package/v1/protocol/PolkadotBaseProtocol.js +409 -701
- package/v1/protocol/PolkadotBaseProtocol.js.map +1 -1
- package/v1/protocol/PolkadotProtocol.js +20 -51
- package/v1/protocol/PolkadotProtocol.js.map +1 -1
- package/v1/serializer/v3/schemas/converter/transaction-converter.js +5 -6
- package/v1/serializer/v3/schemas/converter/transaction-converter.js.map +1 -1
- package/v1/serializer/v3/serializer-companion.js +75 -154
- package/v1/serializer/v3/serializer-companion.js.map +1 -1
- package/v1/serializer/v3/validators/transaction-validator.js +3 -23
- package/v1/serializer/v3/validators/transaction-validator.js.map +1 -1
- package/v1/serializer/v3/validators/validators.js +1 -1
- package/v1/serializer/v3/validators/validators.js.map +1 -1
- package/v1/types/configuration.d.ts +1 -1
- package/v1/types/crypto.d.ts +1 -1
- package/v1/types/protocol.d.ts +2 -2
|
@@ -1,737 +1,445 @@
|
|
|
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
|
-
};
|
|
62
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
63
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
64
4
|
};
|
|
65
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
66
6
|
exports.PolkadotBaseProtocolImpl = void 0;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
7
|
+
const bignumber_1 = __importDefault(require("@airgap/coinlib-core/dependencies/src/bignumber.js-9.0.0/bignumber"));
|
|
8
|
+
const assert_1 = require("@airgap/coinlib-core/utils/assert");
|
|
9
|
+
const module_kit_1 = require("@airgap/module-kit");
|
|
10
|
+
const v1_1 = require("@airgap/substrate/v1");
|
|
11
|
+
const PolkadotAccountController_1 = require("../controller/PolkadotAccountController");
|
|
12
|
+
const PolkadotTransactionController_1 = require("../controller/PolkadotTransactionController");
|
|
13
|
+
const PolkadotPayee_1 = require("../data/staking/PolkadotPayee");
|
|
14
|
+
const PolkadotStakingActionType_1 = require("../data/staking/PolkadotStakingActionType");
|
|
15
|
+
const PolkadotNodeClient_1 = require("../node/PolkadotNodeClient");
|
|
76
16
|
// Implementation
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
_this = _super.call(this, options, nodeClient, accountController, transactionController, blockExplorer) || this;
|
|
86
|
-
_this.defaultValidator = options.network.defaultValidator;
|
|
87
|
-
return _this;
|
|
17
|
+
class PolkadotBaseProtocolImpl extends v1_1.SubstrateStakingProtocolImpl {
|
|
18
|
+
constructor(options) {
|
|
19
|
+
const nodeClient = new PolkadotNodeClient_1.PolkadotNodeClient(options.configuration, options.network.rpcUrl);
|
|
20
|
+
const accountController = new PolkadotAccountController_1.PolkadotAccountController(options.configuration, nodeClient);
|
|
21
|
+
const transactionController = new PolkadotTransactionController_1.PolkadotTransactionController(options.configuration, nodeClient);
|
|
22
|
+
const blockExplorer = new v1_1.SubscanBlockExplorerClient(options.network.blockExplorerApi);
|
|
23
|
+
super(options, nodeClient, accountController, transactionController, blockExplorer);
|
|
24
|
+
this.defaultValidator = options.network.defaultValidator;
|
|
88
25
|
}
|
|
89
26
|
// Staking
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
27
|
+
async getDefaultDelegatee() {
|
|
28
|
+
if (this.defaultValidator) {
|
|
29
|
+
return this.defaultValidator;
|
|
30
|
+
}
|
|
31
|
+
const validators = await this.nodeClient.getValidators();
|
|
32
|
+
return validators ? validators[0].asString() : '';
|
|
33
|
+
}
|
|
34
|
+
async getCurrentDelegateesForPublicKey(publicKey) {
|
|
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
|
|
98
140
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
141
|
+
}
|
|
142
|
+
]
|
|
143
|
+
: []),
|
|
144
|
+
{
|
|
145
|
+
type: 'nominate',
|
|
146
|
+
tip,
|
|
147
|
+
args: {
|
|
148
|
+
targets: typeof targets === 'string' ? [targets] : targets
|
|
103
149
|
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
-
}];
|
|
150
|
+
}
|
|
151
|
+
]);
|
|
152
|
+
return [(0, module_kit_1.newUnsignedTransaction)({ encoded })];
|
|
153
|
+
}
|
|
154
|
+
async prepareRebondNominate(publicKey, tip, targets, value) {
|
|
155
|
+
const [balance, lockedBalance] = await Promise.all([
|
|
156
|
+
this.accountController.getBalance(publicKey),
|
|
157
|
+
this.accountController.getUnlockingBalance(publicKey)
|
|
158
|
+
]);
|
|
159
|
+
const toDelegate = bignumber_1.default.isBigNumber(value) ? value : new bignumber_1.default(value);
|
|
160
|
+
const params = [];
|
|
161
|
+
if (toDelegate.gt(lockedBalance)) {
|
|
162
|
+
params.push({
|
|
163
|
+
type: 'rebond',
|
|
164
|
+
tip,
|
|
165
|
+
args: {
|
|
166
|
+
value: lockedBalance
|
|
134
167
|
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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)];
|
|
168
|
+
}, {
|
|
169
|
+
type: 'bond_extra',
|
|
170
|
+
tip,
|
|
171
|
+
args: {
|
|
172
|
+
value: toDelegate.minus(lockedBalance)
|
|
161
173
|
}
|
|
162
174
|
});
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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)];
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
params.push({
|
|
178
|
+
type: 'rebond',
|
|
179
|
+
tip,
|
|
180
|
+
args: {
|
|
181
|
+
value: toDelegate
|
|
181
182
|
}
|
|
182
183
|
});
|
|
184
|
+
}
|
|
185
|
+
params.push({
|
|
186
|
+
type: 'nominate',
|
|
187
|
+
tip,
|
|
188
|
+
args: {
|
|
189
|
+
targets: typeof targets === 'string' ? [targets] : targets
|
|
190
|
+
}
|
|
183
191
|
});
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
192
|
+
const encoded = await this.transactionController.prepareSubmittableTransactions(publicKey, balance.transferable, params);
|
|
193
|
+
return [(0, module_kit_1.newUnsignedTransaction)({ encoded })];
|
|
194
|
+
}
|
|
195
|
+
async prepareScheduleUndelegate(publicKey, tip, value) {
|
|
196
|
+
const balance = await this.accountController.getBalance(publicKey);
|
|
197
|
+
const keepController = value === undefined;
|
|
198
|
+
const encoded = await this.transactionController.prepareSubmittableTransactions(publicKey, balance.transferable, [
|
|
199
|
+
{
|
|
200
|
+
type: 'cancel_nomination',
|
|
201
|
+
tip,
|
|
202
|
+
args: {}
|
|
203
|
+
},
|
|
204
|
+
...(keepController
|
|
205
|
+
? []
|
|
206
|
+
: [
|
|
207
|
+
{
|
|
208
|
+
type: 'unbond',
|
|
209
|
+
tip,
|
|
210
|
+
args: {
|
|
211
|
+
value: bignumber_1.default.isBigNumber(value) ? value : new bignumber_1.default(value)
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
])
|
|
215
|
+
]);
|
|
216
|
+
return [(0, module_kit_1.newUnsignedTransaction)({ encoded })];
|
|
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
|
|
209
226
|
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
227
|
+
}
|
|
228
|
+
]);
|
|
229
|
+
return [(0, module_kit_1.newUnsignedTransaction)({ encoded })];
|
|
230
|
+
}
|
|
231
|
+
async prepareUnbond(publicKey, tip, value) {
|
|
232
|
+
const balance = await this.accountController.getBalance(publicKey);
|
|
233
|
+
const encoded = await this.transactionController.prepareSubmittableTransactions(publicKey, balance.transferable, [
|
|
234
|
+
{
|
|
235
|
+
type: 'unbond',
|
|
236
|
+
tip,
|
|
237
|
+
args: {
|
|
238
|
+
value: bignumber_1.default.isBigNumber(value) ? value : new bignumber_1.default(value)
|
|
219
239
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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.')];
|
|
240
|
+
}
|
|
241
|
+
]);
|
|
242
|
+
return [(0, module_kit_1.newUnsignedTransaction)({ encoded })];
|
|
243
|
+
}
|
|
244
|
+
async prepareRebond(publicKey, tip, value) {
|
|
245
|
+
const balance = await this.accountController.getBalance(publicKey);
|
|
246
|
+
const encoded = await this.transactionController.prepareSubmittableTransactions(publicKey, balance.transferable, [
|
|
247
|
+
{
|
|
248
|
+
type: 'rebond',
|
|
249
|
+
tip,
|
|
250
|
+
args: {
|
|
251
|
+
value: bignumber_1.default.isBigNumber(value) ? value : new bignumber_1.default(value)
|
|
255
252
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
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 })]];
|
|
253
|
+
}
|
|
254
|
+
]);
|
|
255
|
+
return [(0, module_kit_1.newUnsignedTransaction)({ encoded })];
|
|
256
|
+
}
|
|
257
|
+
async prepareBondExtra(publicKey, tip, value) {
|
|
258
|
+
const balance = await this.accountController.getBalance(publicKey);
|
|
259
|
+
const encoded = await this.transactionController.prepareSubmittableTransactions(publicKey, balance.transferable, [
|
|
260
|
+
{
|
|
261
|
+
type: 'bond_extra',
|
|
262
|
+
tip,
|
|
263
|
+
args: {
|
|
264
|
+
value: bignumber_1.default.isBigNumber(value) ? value : new bignumber_1.default(value)
|
|
295
265
|
}
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
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 })]];
|
|
266
|
+
}
|
|
267
|
+
]);
|
|
268
|
+
return [(0, module_kit_1.newUnsignedTransaction)({ encoded })];
|
|
269
|
+
}
|
|
270
|
+
async prepareRebondExtra(publicKey, tip, value) {
|
|
271
|
+
const [balance, lockedBalance] = await Promise.all([
|
|
272
|
+
this.accountController.getBalance(publicKey),
|
|
273
|
+
this.accountController.getUnlockingBalance(publicKey)
|
|
274
|
+
]);
|
|
275
|
+
const toDelegate = bignumber_1.default.isBigNumber(value) ? value : new bignumber_1.default(value);
|
|
276
|
+
const configs = toDelegate.gt(lockedBalance)
|
|
277
|
+
? [
|
|
278
|
+
{
|
|
279
|
+
type: 'rebond',
|
|
280
|
+
tip,
|
|
281
|
+
args: {
|
|
282
|
+
value: lockedBalance
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
type: 'bond_extra',
|
|
287
|
+
tip,
|
|
288
|
+
args: {
|
|
289
|
+
value: toDelegate.minus(lockedBalance)
|
|
290
|
+
}
|
|
347
291
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
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 })]];
|
|
292
|
+
]
|
|
293
|
+
: [
|
|
294
|
+
{
|
|
295
|
+
type: 'rebond',
|
|
296
|
+
tip,
|
|
297
|
+
args: {
|
|
298
|
+
value: toDelegate
|
|
299
|
+
}
|
|
380
300
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
301
|
+
];
|
|
302
|
+
const encoded = await this.transactionController.prepareSubmittableTransactions(publicKey, balance.transferable, configs);
|
|
303
|
+
return [(0, module_kit_1.newUnsignedTransaction)({ encoded })];
|
|
304
|
+
}
|
|
305
|
+
async prepareWithdrawUnbonded(publicKey, tip) {
|
|
306
|
+
const [balance, slashingSpansNumber] = await Promise.all([
|
|
307
|
+
this.accountController.getBalance(publicKey),
|
|
308
|
+
this.accountController.getSlashingSpansNumber(publicKey)
|
|
309
|
+
]);
|
|
310
|
+
const encoded = await this.transactionController.prepareSubmittableTransactions(publicKey, balance.transferable, [
|
|
311
|
+
{
|
|
312
|
+
type: 'withdraw_unbonded',
|
|
313
|
+
tip,
|
|
314
|
+
args: { slashingSpansNumber }
|
|
315
|
+
}
|
|
316
|
+
]);
|
|
317
|
+
return [(0, module_kit_1.newUnsignedTransaction)({ encoded })];
|
|
318
|
+
}
|
|
319
|
+
// Custom
|
|
320
|
+
async getNominatorDetails(address, validators) {
|
|
321
|
+
return this.accountController.getNominatorDetails(address, validators);
|
|
322
|
+
}
|
|
323
|
+
async getValidatorDetails(address) {
|
|
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
|
|
404
373
|
}
|
|
405
|
-
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
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 })]];
|
|
374
|
+
]);
|
|
375
|
+
}
|
|
376
|
+
if (!isBonded && !isUnbonding && intention === 'delegate') {
|
|
377
|
+
// not delegated & unbond
|
|
378
|
+
requiredTransactions.push([
|
|
379
|
+
'bond',
|
|
380
|
+
{
|
|
381
|
+
// controller: SubstrateSS58Address.createPlaceholder(),
|
|
382
|
+
value: stakingBalance,
|
|
383
|
+
payee: 0
|
|
428
384
|
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
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 })]];
|
|
385
|
+
], [
|
|
386
|
+
'nominate',
|
|
387
|
+
{
|
|
388
|
+
targets: [v1_1.SubstrateSS58Address.createPlaceholder()]
|
|
452
389
|
}
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
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 })]];
|
|
390
|
+
], ['cancel_nomination', {}], [
|
|
391
|
+
'unbond',
|
|
392
|
+
{
|
|
393
|
+
value: stakingBalance
|
|
476
394
|
}
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
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 })]];
|
|
395
|
+
], [
|
|
396
|
+
'withdraw_unbonded',
|
|
397
|
+
{
|
|
398
|
+
slashingSpansNumber: 0
|
|
522
399
|
}
|
|
523
|
-
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
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 })]];
|
|
400
|
+
]);
|
|
401
|
+
}
|
|
402
|
+
else if (isUnbonding && intention === 'delegate') {
|
|
403
|
+
requiredTransactions.push([
|
|
404
|
+
'rebond',
|
|
405
|
+
{
|
|
406
|
+
value: unlockingBalance
|
|
547
407
|
}
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
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
|
-
}];
|
|
408
|
+
], [
|
|
409
|
+
'nominate',
|
|
410
|
+
{
|
|
411
|
+
targets: [v1_1.SubstrateSS58Address.createPlaceholder()]
|
|
588
412
|
}
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
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')];
|
|
413
|
+
], ['cancel_nomination', {}], [
|
|
414
|
+
'unbond',
|
|
415
|
+
{
|
|
416
|
+
value: stakingBalance.plus(unlockingBalance)
|
|
601
417
|
}
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
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')];
|
|
418
|
+
], [
|
|
419
|
+
'withdraw_unbonded',
|
|
420
|
+
{
|
|
421
|
+
slashingSpansNumber: 0
|
|
614
422
|
}
|
|
615
|
-
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
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')];
|
|
423
|
+
]);
|
|
424
|
+
}
|
|
425
|
+
else if (isBonded) {
|
|
426
|
+
requiredTransactions.push([
|
|
427
|
+
'unbond',
|
|
428
|
+
{
|
|
429
|
+
value: stakingBalance
|
|
630
430
|
}
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
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];
|
|
431
|
+
], [
|
|
432
|
+
'withdraw_unbonded',
|
|
433
|
+
{
|
|
434
|
+
slashingSpansNumber: 0
|
|
730
435
|
}
|
|
731
|
-
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
}
|
|
436
|
+
]);
|
|
437
|
+
}
|
|
438
|
+
if (isNominating) {
|
|
439
|
+
requiredTransactions.push(['cancel_nomination', {}]);
|
|
440
|
+
}
|
|
441
|
+
return requiredTransactions;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
736
444
|
exports.PolkadotBaseProtocolImpl = PolkadotBaseProtocolImpl;
|
|
737
445
|
//# sourceMappingURL=PolkadotBaseProtocol.js.map
|