@autonomys/auto-consensus 1.5.13 → 1.5.14
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/README.md +41 -1
- package/dist/position/price.js +1 -1
- package/dist/staking/index.d.ts +3 -0
- package/dist/staking/index.d.ts.map +1 -0
- package/dist/staking/index.js +18 -0
- package/dist/staking/staking.d.ts +43 -0
- package/dist/staking/staking.d.ts.map +1 -0
- package/dist/staking/staking.js +182 -0
- package/dist/staking/withdrawal-helpers.d.ts +94 -0
- package/dist/staking/withdrawal-helpers.d.ts.map +1 -0
- package/dist/staking/withdrawal-helpers.js +114 -0
- package/package.json +3 -3
- package/dist/staking.d.ts +0 -315
- package/dist/staking.d.ts.map +0 -1
- package/dist/staking.js +0 -458
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ The **Autonomys Auto Consensus SDK** (`@autonomys/auto-consensus`) offers a suit
|
|
|
22
22
|
- **Account Management**: Access detailed account information, including nonce and balance data.
|
|
23
23
|
- **Balance Operations**: Retrieve account balances and the total issuance of tokens in the network.
|
|
24
24
|
- **Token Transfers**: Transfer tokens securely between addresses.
|
|
25
|
-
- **Staking Functionality**: Register operators, nominate operators,
|
|
25
|
+
- **Staking Functionality**: Register operators, nominate operators, manage staking operations, and withdraw by all/percent/value via helpers.
|
|
26
26
|
- **Blockchain Information Access**: Fetch current block numbers, block hashes, and network timestamps.
|
|
27
27
|
- **Domain Interactions**: Access domain registry information and staking summaries.
|
|
28
28
|
- **TypeScript Support**: Fully typed for enhanced developer experience.
|
|
@@ -188,6 +188,46 @@ import { activate, activateWallet, signAndSendTx, disconnect } from '@autonomys/
|
|
|
188
188
|
|
|
189
189
|
### 4. Staking Operations
|
|
190
190
|
|
|
191
|
+
#### Withdraw Stake Helpers (all / percent / value)
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
import {
|
|
195
|
+
withdrawStakeAll,
|
|
196
|
+
withdrawStakeByPercent,
|
|
197
|
+
withdrawStakeByValue,
|
|
198
|
+
events,
|
|
199
|
+
} from '@autonomys/auto-consensus'
|
|
200
|
+
import { activate, activateWallet, signAndSendTx } from '@autonomys/auto-utils'
|
|
201
|
+
;(async () => {
|
|
202
|
+
const api = await activate({ networkId: 'your_network_id' })
|
|
203
|
+
const { accounts } = await activateWallet({ networkId: 'your_network_id', mnemonic: '...' })
|
|
204
|
+
const sender = accounts[0]
|
|
205
|
+
const operatorId = '1'
|
|
206
|
+
const account = sender.address
|
|
207
|
+
|
|
208
|
+
// Withdraw all
|
|
209
|
+
const txAll = await withdrawStakeAll({ api, operatorId, account })
|
|
210
|
+
await signAndSendTx(sender, txAll, [events.withdrawStake])
|
|
211
|
+
|
|
212
|
+
// Withdraw by percent (e.g., 25%)
|
|
213
|
+
const txPct = await withdrawStakeByPercent({ api, operatorId, account, percent: 25 })
|
|
214
|
+
await signAndSendTx(sender, txPct, [events.withdrawStake])
|
|
215
|
+
|
|
216
|
+
// Withdraw by target value (amount in smallest units)
|
|
217
|
+
// Note: Value is storage-inclusive. Estimated receive uses
|
|
218
|
+
// totalPayoutValue = currentStakedValue + storageFeeDeposit.currentValue.
|
|
219
|
+
// Shares are computed at snapshot; if price rises before inclusion,
|
|
220
|
+
// actual received may exceed the requested amount.
|
|
221
|
+
const txVal = await withdrawStakeByValue({
|
|
222
|
+
api,
|
|
223
|
+
operatorId,
|
|
224
|
+
account,
|
|
225
|
+
amountToWithdraw: '500000000000000000',
|
|
226
|
+
})
|
|
227
|
+
await signAndSendTx(sender, txVal, [events.withdrawStake])
|
|
228
|
+
})()
|
|
229
|
+
```
|
|
230
|
+
|
|
191
231
|
#### **Register an Operator**
|
|
192
232
|
|
|
193
233
|
Register a new operator for staking.
|
package/dist/position/price.js
CHANGED
|
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.instantSharePrice = exports.operatorEpochSharePrice = void 0;
|
|
13
13
|
const domain_1 = require("../domain");
|
|
14
|
-
const staking_1 = require("../staking");
|
|
14
|
+
const staking_1 = require("../staking/staking");
|
|
15
15
|
const parse_1 = require("../utils/parse");
|
|
16
16
|
const storage_1 = require("../utils/storage");
|
|
17
17
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/staking/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,sBAAsB,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./staking"), exports);
|
|
18
|
+
__exportStar(require("./withdrawal-helpers"), exports);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Api } from '@autonomys/auto-utils';
|
|
2
|
+
import type { NominateOperatorParams, RegisterOperatorParams, StakingParams, StringNumberOrBigInt, WithdrawStakeParams } from '../types/staking';
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves all registered operators on the network.
|
|
5
|
+
*/
|
|
6
|
+
export declare const operators: (api: Api) => Promise<import("../types/staking").Operator[]>;
|
|
7
|
+
/**
|
|
8
|
+
* Retrieves detailed information about a specific operator.
|
|
9
|
+
*/
|
|
10
|
+
export declare const operator: (api: Api, operatorId: StringNumberOrBigInt) => Promise<import("../types/staking").OperatorDetails>;
|
|
11
|
+
/**
|
|
12
|
+
* Retrieves deposit information for an operator.
|
|
13
|
+
*/
|
|
14
|
+
export declare const deposits: (api: Api, operatorId: StringNumberOrBigInt, account?: string | undefined) => Promise<import("../types/staking").Deposit[]>;
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves withdrawal information for an operator.
|
|
17
|
+
*/
|
|
18
|
+
export declare const withdrawals: (api: Api, operatorId: StringNumberOrBigInt, account?: string | undefined) => Promise<import("../types/staking").Withdrawal[]>;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a transaction to register a new operator.
|
|
21
|
+
*/
|
|
22
|
+
export declare const registerOperator: (params: RegisterOperatorParams) => import("@autonomys/auto-utils").SubmittableExtrinsic<"promise", import("@autonomys/auto-utils").ISubmittableResult>;
|
|
23
|
+
/**
|
|
24
|
+
* Creates a transaction to nominate (stake to) an existing operator.
|
|
25
|
+
*/
|
|
26
|
+
export declare const nominateOperator: (params: NominateOperatorParams) => import("@autonomys/auto-utils").SubmittableExtrinsic<"promise", import("@autonomys/auto-utils").ISubmittableResult>;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a transaction to withdraw stake from an operator (shares-only).
|
|
29
|
+
*/
|
|
30
|
+
export declare const withdrawStake: (params: WithdrawStakeParams) => import("@autonomys/auto-utils").SubmittableExtrinsic<"promise", import("@autonomys/auto-utils").ISubmittableResult>;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a transaction to deregister an operator.
|
|
33
|
+
*/
|
|
34
|
+
export declare const deregisterOperator: (params: StakingParams) => import("@autonomys/auto-utils").SubmittableExtrinsic<"promise", import("@autonomys/auto-utils").ISubmittableResult>;
|
|
35
|
+
/**
|
|
36
|
+
* Creates a transaction to unlock funds from an operator.
|
|
37
|
+
*/
|
|
38
|
+
export declare const unlockFunds: (params: StakingParams) => import("@autonomys/auto-utils").SubmittableExtrinsic<"promise", import("@autonomys/auto-utils").ISubmittableResult>;
|
|
39
|
+
/**
|
|
40
|
+
* Creates a transaction to unlock a nominator from an operator.
|
|
41
|
+
*/
|
|
42
|
+
export declare const unlockNominator: (params: StakingParams) => import("@autonomys/auto-utils").SubmittableExtrinsic<"promise", import("@autonomys/auto-utils").ISubmittableResult>;
|
|
43
|
+
//# sourceMappingURL=staking.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"staking.d.ts","sourceRoot":"","sources":["../../src/staking/staking.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAA8B,MAAM,uBAAuB,CAAA;AACvE,OAAO,KAAK,EACV,sBAAsB,EACtB,sBAAsB,EACtB,aAAa,EACb,oBAAoB,EACpB,mBAAmB,EACpB,MAAM,kBAAkB,CAAA;AASzB;;GAEG;AACH,eAAO,MAAM,SAAS,GAAU,KAAK,GAAG,mDAQvC,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ,GAAU,KAAK,GAAG,EAAE,YAAY,oBAAoB,wDAQxE,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ,GACnB,KAAK,GAAG,EACR,YAAY,oBAAoB,EAChC,UAAS,MAAM,GAAG,SAAqB,kDAcxC,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,WAAW,GACtB,KAAK,GAAG,EACR,YAAY,oBAAoB,EAChC,UAAS,MAAM,GAAG,SAAqB,qDAgBxC,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,sBAAsB,wHAmB9D,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,sBAAsB,wHAS9D,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,QAAQ,mBAAmB,wHAWxD,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAAI,QAAQ,aAAa,wHASvD,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,WAAW,GAAI,QAAQ,aAAa,wHAShD,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,aAAa,wHASpD,CAAA"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// file: src/staking/staking.ts
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.unlockNominator = exports.unlockFunds = exports.deregisterOperator = exports.withdrawStake = exports.nominateOperator = exports.registerOperator = exports.withdrawals = exports.deposits = exports.operator = exports.operators = void 0;
|
|
14
|
+
const auto_utils_1 = require("@autonomys/auto-utils");
|
|
15
|
+
const parse_1 = require("../utils/parse");
|
|
16
|
+
/**
|
|
17
|
+
* Retrieves all registered operators on the network.
|
|
18
|
+
*/
|
|
19
|
+
const operators = (api) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
try {
|
|
21
|
+
const _operators = yield api.query.domains.operators.entries();
|
|
22
|
+
return _operators.map((o) => (0, parse_1.parseOperator)(o));
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
console.error('error', error);
|
|
26
|
+
throw new Error('Error querying operators list.' + error);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
exports.operators = operators;
|
|
30
|
+
/**
|
|
31
|
+
* Retrieves detailed information about a specific operator.
|
|
32
|
+
*/
|
|
33
|
+
const operator = (api, operatorId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
try {
|
|
35
|
+
const _operator = yield api.query.domains.operators((0, parse_1.parseString)(operatorId));
|
|
36
|
+
return (0, parse_1.parseOperatorDetails)(_operator);
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
console.error('error', error);
|
|
40
|
+
throw new Error(`Error querying operatorId: ${operatorId} with error: ${error}`);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
exports.operator = operator;
|
|
44
|
+
/**
|
|
45
|
+
* Retrieves deposit information for an operator.
|
|
46
|
+
*/
|
|
47
|
+
const deposits = (api_1, operatorId_1, ...args_1) => __awaiter(void 0, [api_1, operatorId_1, ...args_1], void 0, function* (api, operatorId, account = undefined) {
|
|
48
|
+
try {
|
|
49
|
+
if (account) {
|
|
50
|
+
const _deposits = yield api.query.domains.deposits.entries((0, parse_1.parseString)(operatorId));
|
|
51
|
+
return _deposits.map((o) => (0, parse_1.parseDeposit)(o)).filter((deposit) => deposit.account === account);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
const _deposits = yield api.query.domains.deposits.entries((0, parse_1.parseString)(operatorId));
|
|
55
|
+
return _deposits.map((o) => (0, parse_1.parseDeposit)(o));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
console.error('error', error);
|
|
60
|
+
throw new Error('Error querying deposits list.' + error);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
exports.deposits = deposits;
|
|
64
|
+
/**
|
|
65
|
+
* Retrieves withdrawal information for an operator.
|
|
66
|
+
*/
|
|
67
|
+
const withdrawals = (api_1, operatorId_1, ...args_1) => __awaiter(void 0, [api_1, operatorId_1, ...args_1], void 0, function* (api, operatorId, account = undefined) {
|
|
68
|
+
try {
|
|
69
|
+
if (account) {
|
|
70
|
+
const _withdrawals = yield api.query.domains.withdrawals.entries((0, parse_1.parseString)(operatorId));
|
|
71
|
+
return _withdrawals
|
|
72
|
+
.map((o) => (0, parse_1.parseWithdrawal)(o))
|
|
73
|
+
.filter((withdrawal) => withdrawal.account === account);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
const _withdrawals = yield api.query.domains.withdrawals.entries((0, parse_1.parseString)(operatorId));
|
|
77
|
+
return _withdrawals.map((o) => (0, parse_1.parseWithdrawal)(o));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
console.error('error', error);
|
|
82
|
+
throw new Error('Error querying withdrawals list.' + error);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
exports.withdrawals = withdrawals;
|
|
86
|
+
/**
|
|
87
|
+
* Creates a transaction to register a new operator.
|
|
88
|
+
*/
|
|
89
|
+
const registerOperator = (params) => {
|
|
90
|
+
try {
|
|
91
|
+
const { api, domainId, amountToStake, minimumNominatorStake, nominationTax, publicKey } = params;
|
|
92
|
+
let signingKey = params.signingKey;
|
|
93
|
+
if (!signingKey && !publicKey)
|
|
94
|
+
throw new Error('Signing key or public key not provided');
|
|
95
|
+
else if (!signingKey && publicKey)
|
|
96
|
+
signingKey = (0, auto_utils_1.signingKey)(publicKey);
|
|
97
|
+
if (!signingKey)
|
|
98
|
+
throw new Error('Signing key not provided');
|
|
99
|
+
return api.tx.domains.registerOperator((0, parse_1.parseString)(domainId), (0, parse_1.parseString)(amountToStake), {
|
|
100
|
+
signingKey,
|
|
101
|
+
minimumNominatorStake: (0, parse_1.parseString)(minimumNominatorStake),
|
|
102
|
+
nominationTax: (0, parse_1.parseString)(nominationTax),
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
console.error('error', error);
|
|
107
|
+
throw new Error('Error creating register operator tx.' + error);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
exports.registerOperator = registerOperator;
|
|
111
|
+
/**
|
|
112
|
+
* Creates a transaction to nominate (stake to) an existing operator.
|
|
113
|
+
*/
|
|
114
|
+
const nominateOperator = (params) => {
|
|
115
|
+
try {
|
|
116
|
+
const { api, operatorId, amountToStake } = params;
|
|
117
|
+
return api.tx.domains.nominateOperator((0, parse_1.parseString)(operatorId), (0, parse_1.parseString)(amountToStake));
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
console.error('error', error);
|
|
121
|
+
throw new Error('Error creating nominate operator tx.' + error);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
exports.nominateOperator = nominateOperator;
|
|
125
|
+
/**
|
|
126
|
+
* Creates a transaction to withdraw stake from an operator (shares-only).
|
|
127
|
+
*/
|
|
128
|
+
const withdrawStake = (params) => {
|
|
129
|
+
try {
|
|
130
|
+
const { api, operatorId, shares } = params;
|
|
131
|
+
if (shares === undefined || shares === null)
|
|
132
|
+
throw new Error('Provide shares(string/number/bigint) to withdraw stake');
|
|
133
|
+
return api.tx.domains.withdrawStake((0, parse_1.parseString)(operatorId), (0, parse_1.parseString)(shares));
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
console.error('error', error);
|
|
137
|
+
throw new Error('Error creating withdraw stake tx.' + error);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
exports.withdrawStake = withdrawStake;
|
|
141
|
+
/**
|
|
142
|
+
* Creates a transaction to deregister an operator.
|
|
143
|
+
*/
|
|
144
|
+
const deregisterOperator = (params) => {
|
|
145
|
+
try {
|
|
146
|
+
const { api, operatorId } = params;
|
|
147
|
+
return api.tx.domains.deregisterOperator((0, parse_1.parseString)(operatorId));
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
console.error('error', error);
|
|
151
|
+
throw new Error('Error creating de-register operator tx.' + error);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
exports.deregisterOperator = deregisterOperator;
|
|
155
|
+
/**
|
|
156
|
+
* Creates a transaction to unlock funds from an operator.
|
|
157
|
+
*/
|
|
158
|
+
const unlockFunds = (params) => {
|
|
159
|
+
try {
|
|
160
|
+
const { api, operatorId } = params;
|
|
161
|
+
return api.tx.domains.unlockFunds((0, parse_1.parseString)(operatorId));
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
console.error('error', error);
|
|
165
|
+
throw new Error('Error creating unlock funds tx.' + error);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
exports.unlockFunds = unlockFunds;
|
|
169
|
+
/**
|
|
170
|
+
* Creates a transaction to unlock a nominator from an operator.
|
|
171
|
+
*/
|
|
172
|
+
const unlockNominator = (params) => {
|
|
173
|
+
try {
|
|
174
|
+
const { api, operatorId } = params;
|
|
175
|
+
return api.tx.domains.unlockNominator((0, parse_1.parseString)(operatorId));
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
console.error('error', error);
|
|
179
|
+
throw new Error('Error creating unlock nominator tx.' + error);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
exports.unlockNominator = unlockNominator;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { ApiPromise } from '@autonomys/auto-utils';
|
|
2
|
+
import type { StringNumberOrBigInt } from '../types/staking';
|
|
3
|
+
/**
|
|
4
|
+
* Parameters to withdraw all stake for an account on an operator.
|
|
5
|
+
*/
|
|
6
|
+
export type WithdrawStakeAllParams = {
|
|
7
|
+
/** Connected API instance */
|
|
8
|
+
api: ApiPromise;
|
|
9
|
+
/** Operator ID to withdraw from */
|
|
10
|
+
operatorId: StringNumberOrBigInt;
|
|
11
|
+
/** Nominator account ID whose stake is being withdrawn */
|
|
12
|
+
account: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Parameters to withdraw a percentage of the current stake (rounded down in shares).
|
|
16
|
+
*/
|
|
17
|
+
export type WithdrawStakeByPercentParams = {
|
|
18
|
+
/** Connected API instance */
|
|
19
|
+
api: ApiPromise;
|
|
20
|
+
/** Operator ID to withdraw from */
|
|
21
|
+
operatorId: StringNumberOrBigInt;
|
|
22
|
+
/** Nominator account ID whose stake is being withdrawn */
|
|
23
|
+
account: string;
|
|
24
|
+
/** Percent in range 0..100 (values are clamped, shares are rounded down) */
|
|
25
|
+
percent: StringNumberOrBigInt;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Parameters to withdraw a target value amount (in balance units, not shares).
|
|
29
|
+
* The helper computes the equivalent shares using the current position.
|
|
30
|
+
*/
|
|
31
|
+
export type WithdrawStakeByValueParams = {
|
|
32
|
+
/** Connected API instance */
|
|
33
|
+
api: ApiPromise;
|
|
34
|
+
/** Operator ID to withdraw from */
|
|
35
|
+
operatorId: StringNumberOrBigInt;
|
|
36
|
+
/** Nominator account ID whose stake is being withdrawn */
|
|
37
|
+
account: string;
|
|
38
|
+
/** Target amount to withdraw in balance units (will be capped at current value) */
|
|
39
|
+
amountToWithdraw: StringNumberOrBigInt;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Creates a submittable extrinsic to withdraw ALL stake for a nominator on a given operator.
|
|
43
|
+
*
|
|
44
|
+
* This is a convenience wrapper that:
|
|
45
|
+
* 1) Fetches the nominator position to obtain totalShares
|
|
46
|
+
* 2) Calls protocol-native withdrawStake({ shares: totalShares })
|
|
47
|
+
*
|
|
48
|
+
* Edge cases:
|
|
49
|
+
* - Throws if the nominator has no shares
|
|
50
|
+
*
|
|
51
|
+
* @param params - {@link WithdrawStakeAllParams}
|
|
52
|
+
* @returns A submittable extrinsic prepared for submission
|
|
53
|
+
*/
|
|
54
|
+
export declare const withdrawStakeAll: (params: WithdrawStakeAllParams) => Promise<import("@autonomys/auto-utils").SubmittableExtrinsic<"promise", import("@autonomys/auto-utils").ISubmittableResult>>;
|
|
55
|
+
/**
|
|
56
|
+
* Creates a submittable extrinsic to withdraw a percentage of the current stake.
|
|
57
|
+
*
|
|
58
|
+
* Share calculation:
|
|
59
|
+
* shares = floor(totalShares * clamp(percent, 0..100) / 100)
|
|
60
|
+
*
|
|
61
|
+
* Edge cases:
|
|
62
|
+
* - Percent is clamped to [0, 100]
|
|
63
|
+
* - Throws if computed shares is zero
|
|
64
|
+
* - Throws if the nominator has no shares
|
|
65
|
+
*
|
|
66
|
+
* @param params - {@link WithdrawStakeByPercentParams}
|
|
67
|
+
* @returns A submittable extrinsic prepared for submission
|
|
68
|
+
*/
|
|
69
|
+
export declare const withdrawStakeByPercent: (params: WithdrawStakeByPercentParams) => Promise<import("@autonomys/auto-utils").SubmittableExtrinsic<"promise", import("@autonomys/auto-utils").ISubmittableResult>>;
|
|
70
|
+
/**
|
|
71
|
+
* Creates a submittable extrinsic to withdraw a target value (in balance units) from the current position.
|
|
72
|
+
*
|
|
73
|
+
* Storage-inclusive value: This helper uses total payout value = current staked value + current storage fee refund value.
|
|
74
|
+
* The storage fee refund component is valued at the current bundle storage fund redeem price and varies with time.
|
|
75
|
+
*
|
|
76
|
+
* Share calculation (using floor, "at most at snapshot"):
|
|
77
|
+
* totalPayoutValue = currentStakedValue + storageFeeDeposit.currentValue
|
|
78
|
+
* shares = floor(min(requestedAmount, totalPayoutValue) * totalShares / totalPayoutValue)
|
|
79
|
+
*
|
|
80
|
+
* Notes:
|
|
81
|
+
* - The number of shares is fixed in the extrinsic; actual received tokens may exceed the requested amount if prices rise between calculation and inclusion.
|
|
82
|
+
*
|
|
83
|
+
* Edge cases:
|
|
84
|
+
* - Throws if amountToWithdraw <= 0
|
|
85
|
+
* - Caps requested amount to totalPayoutValue
|
|
86
|
+
* - Throws if totalPayoutValue is zero
|
|
87
|
+
* - Throws if computed shares is zero
|
|
88
|
+
* - Throws if the nominator has no shares
|
|
89
|
+
*
|
|
90
|
+
* @param params - {@link WithdrawStakeByValueParams}
|
|
91
|
+
* @returns A submittable extrinsic prepared for submission
|
|
92
|
+
*/
|
|
93
|
+
export declare const withdrawStakeByValue: (params: WithdrawStakeByValueParams) => Promise<import("@autonomys/auto-utils").SubmittableExtrinsic<"promise", import("@autonomys/auto-utils").ISubmittableResult>>;
|
|
94
|
+
//# sourceMappingURL=withdrawal-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withdrawal-helpers.d.ts","sourceRoot":"","sources":["../../src/staking/withdrawal-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAEvD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AAI5D;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,6BAA6B;IAC7B,GAAG,EAAE,UAAU,CAAA;IACf,mCAAmC;IACnC,UAAU,EAAE,oBAAoB,CAAA;IAChC,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG;IACzC,6BAA6B;IAC7B,GAAG,EAAE,UAAU,CAAA;IACf,mCAAmC;IACnC,UAAU,EAAE,oBAAoB,CAAA;IAChC,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAA;IACf,4EAA4E;IAC5E,OAAO,EAAE,oBAAoB,CAAA;CAC9B,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,0BAA0B,GAAG;IACvC,6BAA6B;IAC7B,GAAG,EAAE,UAAU,CAAA;IACf,mCAAmC;IACnC,UAAU,EAAE,oBAAoB,CAAA;IAChC,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAA;IACf,mFAAmF;IACnF,gBAAgB,EAAE,oBAAoB,CAAA;CACvC,CAAA;AAQD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,gBAAgB,GAAU,QAAQ,sBAAsB,iIAQpE,CAAA;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,sBAAsB,GAAU,QAAQ,4BAA4B,iIAehF,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,oBAAoB,GAAU,QAAQ,0BAA0B,iIAyB5E,CAAA"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.withdrawStakeByValue = exports.withdrawStakeByPercent = exports.withdrawStakeAll = void 0;
|
|
13
|
+
const position_1 = require("../position");
|
|
14
|
+
const parse_1 = require("../utils/parse");
|
|
15
|
+
const staking_1 = require("./staking");
|
|
16
|
+
const clampPercent = (percent) => {
|
|
17
|
+
if (percent < BigInt(0))
|
|
18
|
+
return BigInt(0);
|
|
19
|
+
if (percent > BigInt(100))
|
|
20
|
+
return BigInt(100);
|
|
21
|
+
return percent;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Creates a submittable extrinsic to withdraw ALL stake for a nominator on a given operator.
|
|
25
|
+
*
|
|
26
|
+
* This is a convenience wrapper that:
|
|
27
|
+
* 1) Fetches the nominator position to obtain totalShares
|
|
28
|
+
* 2) Calls protocol-native withdrawStake({ shares: totalShares })
|
|
29
|
+
*
|
|
30
|
+
* Edge cases:
|
|
31
|
+
* - Throws if the nominator has no shares
|
|
32
|
+
*
|
|
33
|
+
* @param params - {@link WithdrawStakeAllParams}
|
|
34
|
+
* @returns A submittable extrinsic prepared for submission
|
|
35
|
+
*/
|
|
36
|
+
const withdrawStakeAll = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
const { api, operatorId, account } = params;
|
|
38
|
+
const position = yield (0, position_1.nominatorPosition)(api, operatorId, account);
|
|
39
|
+
const totalShares = position.totalShares;
|
|
40
|
+
if (totalShares === BigInt(0))
|
|
41
|
+
throw new Error('No shares to withdraw for the given account');
|
|
42
|
+
return (0, staking_1.withdrawStake)({ api, operatorId, shares: totalShares });
|
|
43
|
+
});
|
|
44
|
+
exports.withdrawStakeAll = withdrawStakeAll;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a submittable extrinsic to withdraw a percentage of the current stake.
|
|
47
|
+
*
|
|
48
|
+
* Share calculation:
|
|
49
|
+
* shares = floor(totalShares * clamp(percent, 0..100) / 100)
|
|
50
|
+
*
|
|
51
|
+
* Edge cases:
|
|
52
|
+
* - Percent is clamped to [0, 100]
|
|
53
|
+
* - Throws if computed shares is zero
|
|
54
|
+
* - Throws if the nominator has no shares
|
|
55
|
+
*
|
|
56
|
+
* @param params - {@link WithdrawStakeByPercentParams}
|
|
57
|
+
* @returns A submittable extrinsic prepared for submission
|
|
58
|
+
*/
|
|
59
|
+
const withdrawStakeByPercent = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
|
+
const { api, operatorId, account } = params;
|
|
61
|
+
const rawPercent = BigInt((0, parse_1.parseString)(params.percent));
|
|
62
|
+
const percent = clampPercent(rawPercent);
|
|
63
|
+
const position = yield (0, position_1.nominatorPosition)(api, operatorId, account);
|
|
64
|
+
const totalShares = position.totalShares;
|
|
65
|
+
if (totalShares === BigInt(0))
|
|
66
|
+
throw new Error('No shares to withdraw for the given account');
|
|
67
|
+
const shares = (totalShares * percent) / BigInt(100);
|
|
68
|
+
if (shares === BigInt(0))
|
|
69
|
+
throw new Error('Computed zero shares to withdraw; increase percent');
|
|
70
|
+
return (0, staking_1.withdrawStake)({ api, operatorId, shares });
|
|
71
|
+
});
|
|
72
|
+
exports.withdrawStakeByPercent = withdrawStakeByPercent;
|
|
73
|
+
/**
|
|
74
|
+
* Creates a submittable extrinsic to withdraw a target value (in balance units) from the current position.
|
|
75
|
+
*
|
|
76
|
+
* Storage-inclusive value: This helper uses total payout value = current staked value + current storage fee refund value.
|
|
77
|
+
* The storage fee refund component is valued at the current bundle storage fund redeem price and varies with time.
|
|
78
|
+
*
|
|
79
|
+
* Share calculation (using floor, "at most at snapshot"):
|
|
80
|
+
* totalPayoutValue = currentStakedValue + storageFeeDeposit.currentValue
|
|
81
|
+
* shares = floor(min(requestedAmount, totalPayoutValue) * totalShares / totalPayoutValue)
|
|
82
|
+
*
|
|
83
|
+
* Notes:
|
|
84
|
+
* - The number of shares is fixed in the extrinsic; actual received tokens may exceed the requested amount if prices rise between calculation and inclusion.
|
|
85
|
+
*
|
|
86
|
+
* Edge cases:
|
|
87
|
+
* - Throws if amountToWithdraw <= 0
|
|
88
|
+
* - Caps requested amount to totalPayoutValue
|
|
89
|
+
* - Throws if totalPayoutValue is zero
|
|
90
|
+
* - Throws if computed shares is zero
|
|
91
|
+
* - Throws if the nominator has no shares
|
|
92
|
+
*
|
|
93
|
+
* @param params - {@link WithdrawStakeByValueParams}
|
|
94
|
+
* @returns A submittable extrinsic prepared for submission
|
|
95
|
+
*/
|
|
96
|
+
const withdrawStakeByValue = (params) => __awaiter(void 0, void 0, void 0, function* () {
|
|
97
|
+
const { api, operatorId, account } = params;
|
|
98
|
+
const requestedAmount = BigInt((0, parse_1.parseString)(params.amountToWithdraw));
|
|
99
|
+
if (requestedAmount <= BigInt(0))
|
|
100
|
+
throw new Error('amountToWithdraw must be greater than zero');
|
|
101
|
+
const position = yield (0, position_1.nominatorPosition)(api, operatorId, account);
|
|
102
|
+
const { totalShares, currentStakedValue, storageFeeDeposit } = position;
|
|
103
|
+
if (totalShares === BigInt(0))
|
|
104
|
+
throw new Error('No shares to withdraw for the given account');
|
|
105
|
+
const totalPayoutValue = currentStakedValue + storageFeeDeposit.currentValue;
|
|
106
|
+
if (totalPayoutValue === BigInt(0))
|
|
107
|
+
throw new Error('No redeemable value to withdraw; cannot compute shares');
|
|
108
|
+
const effectiveAmount = requestedAmount > totalPayoutValue ? totalPayoutValue : requestedAmount;
|
|
109
|
+
const shares = (effectiveAmount * totalShares) / totalPayoutValue;
|
|
110
|
+
if (shares === BigInt(0))
|
|
111
|
+
throw new Error('Computed zero shares to withdraw; requested amount too small for current price');
|
|
112
|
+
return (0, staking_1.withdrawStake)({ api, operatorId, shares });
|
|
113
|
+
});
|
|
114
|
+
exports.withdrawStakeByValue = withdrawStakeByValue;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autonomys/auto-consensus",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.14",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"README.md"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@autonomys/auto-utils": "^1.5.
|
|
28
|
+
"@autonomys/auto-utils": "^1.5.14"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/jest": "^29.5.14",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"ts-jest": "^29.3.1",
|
|
36
36
|
"typescript": "^5.8.3"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "6f87eed19ee289fad2ee16bd4900f7455ce56680"
|
|
39
39
|
}
|
package/dist/staking.d.ts
DELETED
|
@@ -1,315 +0,0 @@
|
|
|
1
|
-
import { Api } from '@autonomys/auto-utils';
|
|
2
|
-
import type { NominateOperatorParams, RegisterOperatorParams, StakingParams, StringNumberOrBigInt, WithdrawStakeParams } from './types/staking';
|
|
3
|
-
/**
|
|
4
|
-
* Retrieves all registered operators on the network.
|
|
5
|
-
*
|
|
6
|
-
* This function queries the blockchain to get information about all operators
|
|
7
|
-
* that have been registered across all domains. Operators are entities that
|
|
8
|
-
* process transactions and maintain domain chains.
|
|
9
|
-
*
|
|
10
|
-
* @param api - The connected API instance
|
|
11
|
-
* @returns Promise that resolves to an array of Operator objects
|
|
12
|
-
* @throws Error if the operators query fails
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* import { operators } from '@autonomys/auto-consensus'
|
|
17
|
-
* import { activate } from '@autonomys/auto-utils'
|
|
18
|
-
*
|
|
19
|
-
* const api = await activate({ networkId: 'mainnet' })
|
|
20
|
-
* const allOperators = await operators(api)
|
|
21
|
-
*
|
|
22
|
-
* allOperators.forEach(op => {
|
|
23
|
-
* console.log(`Operator ${op.operatorId}: Domain ${op.operatorDetails.currentDomainId}`)
|
|
24
|
-
* console.log(`Total Stake: ${op.operatorDetails.currentTotalStake}`)
|
|
25
|
-
* })
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export declare const operators: (api: Api) => Promise<import("./types/staking").Operator[]>;
|
|
29
|
-
/**
|
|
30
|
-
* Retrieves detailed information about a specific operator.
|
|
31
|
-
*
|
|
32
|
-
* This function queries information about a single operator including their
|
|
33
|
-
* signing key, domain assignment, stake amounts, and operational status.
|
|
34
|
-
*
|
|
35
|
-
* @param api - The connected API instance
|
|
36
|
-
* @param operatorId - The ID of the operator to query
|
|
37
|
-
* @returns Promise that resolves to OperatorDetails object
|
|
38
|
-
* @throws Error if the operator query fails or operator doesn't exist
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```typescript
|
|
42
|
-
* import { operator } from '@autonomys/auto-consensus'
|
|
43
|
-
* import { activate } from '@autonomys/auto-utils'
|
|
44
|
-
*
|
|
45
|
-
* const api = await activate({ networkId: 'mainnet' })
|
|
46
|
-
* const operatorInfo = await operator(api, '1')
|
|
47
|
-
*
|
|
48
|
-
* console.log(`Domain: ${operatorInfo.currentDomainId}`)
|
|
49
|
-
* console.log(`Total Stake: ${operatorInfo.currentTotalStake}`)
|
|
50
|
-
* console.log(`Minimum Nominator Stake: ${operatorInfo.minimumNominatorStake}`)
|
|
51
|
-
* console.log(`Nomination Tax: ${operatorInfo.nominationTax}%`)
|
|
52
|
-
* ```
|
|
53
|
-
*/
|
|
54
|
-
export declare const operator: (api: Api, operatorId: StringNumberOrBigInt) => Promise<import("./types/staking").OperatorDetails>;
|
|
55
|
-
/**
|
|
56
|
-
* Retrieves deposit information for an operator.
|
|
57
|
-
*
|
|
58
|
-
* This function queries all deposits (stakes) made to a specific operator.
|
|
59
|
-
* It can optionally filter deposits by a specific account address.
|
|
60
|
-
*
|
|
61
|
-
* @param api - The connected API instance
|
|
62
|
-
* @param operatorId - The ID of the operator to query deposits for
|
|
63
|
-
* @param account - Optional account address to filter deposits by
|
|
64
|
-
* @returns Promise that resolves to an array of Deposit objects
|
|
65
|
-
* @throws Error if the deposits query fails
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```typescript
|
|
69
|
-
* import { deposits } from '@autonomys/auto-consensus'
|
|
70
|
-
* import { activate } from '@autonomys/auto-utils'
|
|
71
|
-
*
|
|
72
|
-
* const api = await activate({ networkId: 'mainnet' })
|
|
73
|
-
*
|
|
74
|
-
* // Get all deposits for operator
|
|
75
|
-
* const allDeposits = await deposits(api, '1')
|
|
76
|
-
*
|
|
77
|
-
* // Get deposits for specific account
|
|
78
|
-
* const accountDeposits = await deposits(api, '1', 'account_address')
|
|
79
|
-
*
|
|
80
|
-
* allDeposits.forEach(deposit => {
|
|
81
|
-
* console.log(`Account: ${deposit.account}, Shares: ${deposit.shares}`)
|
|
82
|
-
* })
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
export declare const deposits: (api: Api, operatorId: StringNumberOrBigInt, account?: string | undefined) => Promise<import("./types/staking").Deposit[]>;
|
|
86
|
-
/**
|
|
87
|
-
* Retrieves withdrawal information for an operator.
|
|
88
|
-
*
|
|
89
|
-
* This function queries all pending withdrawals for a specific operator.
|
|
90
|
-
* Withdrawals are stakes that have been requested to be unstaked but are
|
|
91
|
-
* still in the withdrawal period. Can optionally filter by account.
|
|
92
|
-
*
|
|
93
|
-
* @param api - The connected API instance
|
|
94
|
-
* @param operatorId - The ID of the operator to query withdrawals for
|
|
95
|
-
* @param account - Optional account address to filter withdrawals by
|
|
96
|
-
* @returns Promise that resolves to an array of Withdrawal objects
|
|
97
|
-
* @throws Error if the withdrawals query fails
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* ```typescript
|
|
101
|
-
* import { withdrawals } from '@autonomys/auto-consensus'
|
|
102
|
-
* import { activate } from '@autonomys/auto-utils'
|
|
103
|
-
*
|
|
104
|
-
* const api = await activate({ networkId: 'mainnet' })
|
|
105
|
-
*
|
|
106
|
-
* // Get all withdrawals for operator
|
|
107
|
-
* const allWithdrawals = await withdrawals(api, '1')
|
|
108
|
-
*
|
|
109
|
-
* // Get withdrawals for specific account
|
|
110
|
-
* const accountWithdrawals = await withdrawals(api, '1', 'account_address')
|
|
111
|
-
*
|
|
112
|
-
* allWithdrawals.forEach(withdrawal => {
|
|
113
|
-
* console.log(`Account: ${withdrawal.account}`)
|
|
114
|
-
* console.log(`Total Withdrawal: ${withdrawal.totalWithdrawalAmount}`)
|
|
115
|
-
* })
|
|
116
|
-
* ```
|
|
117
|
-
*/
|
|
118
|
-
export declare const withdrawals: (api: Api, operatorId: StringNumberOrBigInt, account?: string | undefined) => Promise<import("./types/staking").Withdrawal[]>;
|
|
119
|
-
/**
|
|
120
|
-
* Creates a transaction to register a new operator.
|
|
121
|
-
*
|
|
122
|
-
* This function creates a transaction to register a new operator on a specific domain.
|
|
123
|
-
* The operator will be able to process transactions and earn rewards. Requires
|
|
124
|
-
* initial stake, minimum nominator stake, and nomination tax settings.
|
|
125
|
-
*
|
|
126
|
-
* @param params - RegisterOperatorParams containing all registration parameters
|
|
127
|
-
* @param params.api - The connected API promise instance
|
|
128
|
-
* @param params.domainId - The domain ID where the operator will be registered
|
|
129
|
-
* @param params.amountToStake - Initial amount to stake (in smallest token units)
|
|
130
|
-
* @param params.minimumNominatorStake - Minimum stake required from nominators
|
|
131
|
-
* @param params.nominationTax - Percentage fee charged to nominators
|
|
132
|
-
* @param params.signingKey - Optional signing key (derived from publicKey if not provided)
|
|
133
|
-
* @param params.publicKey - Optional public key (used to derive signingKey if needed)
|
|
134
|
-
* @returns A submittable operator registration transaction
|
|
135
|
-
* @throws Error if signing key/public key not provided or transaction creation fails
|
|
136
|
-
*
|
|
137
|
-
* @example
|
|
138
|
-
* ```typescript
|
|
139
|
-
* import { registerOperator } from '@autonomys/auto-consensus'
|
|
140
|
-
* import { activate, activateWallet, signAndSendTx } from '@autonomys/auto-utils'
|
|
141
|
-
*
|
|
142
|
-
* const api = await activate({ networkId: 'mainnet' })
|
|
143
|
-
* const { accounts } = await activateWallet({ networkId: 'mainnet', mnemonic })
|
|
144
|
-
*
|
|
145
|
-
* const registerTx = registerOperator({
|
|
146
|
-
* api,
|
|
147
|
-
* domainId: '0',
|
|
148
|
-
* amountToStake: '100000000000000000000', // 100 AI3
|
|
149
|
-
* minimumNominatorStake: '1000000000000000000', // 1 AI3
|
|
150
|
-
* nominationTax: '10', // 10%
|
|
151
|
-
* publicKey: accounts[0].publicKey
|
|
152
|
-
* })
|
|
153
|
-
*
|
|
154
|
-
* await signAndSendTx(accounts[0], registerTx)
|
|
155
|
-
* ```
|
|
156
|
-
*/
|
|
157
|
-
export declare const registerOperator: (params: RegisterOperatorParams) => import("@autonomys/auto-utils").SubmittableExtrinsic<"promise", import("@autonomys/auto-utils").ISubmittableResult>;
|
|
158
|
-
/**
|
|
159
|
-
* Creates a transaction to nominate (stake to) an existing operator.
|
|
160
|
-
*
|
|
161
|
-
* This function creates a transaction to stake tokens to an existing operator.
|
|
162
|
-
* Nominators earn rewards proportional to their stake, minus the operator's
|
|
163
|
-
* nomination tax. The stake helps secure the network and the specific domain.
|
|
164
|
-
*
|
|
165
|
-
* @param params - NominateOperatorParams containing nomination parameters
|
|
166
|
-
* @param params.api - The connected API promise instance
|
|
167
|
-
* @param params.operatorId - The ID of the operator to nominate
|
|
168
|
-
* @param params.amountToStake - Amount to stake (in smallest token units)
|
|
169
|
-
* @returns A submittable operator nomination transaction
|
|
170
|
-
* @throws Error if transaction creation fails
|
|
171
|
-
*
|
|
172
|
-
* @example
|
|
173
|
-
* ```typescript
|
|
174
|
-
* import { nominateOperator } from '@autonomys/auto-consensus'
|
|
175
|
-
* import { activate, signAndSendTx } from '@autonomys/auto-utils'
|
|
176
|
-
*
|
|
177
|
-
* const api = await activate({ networkId: 'mainnet' })
|
|
178
|
-
*
|
|
179
|
-
* const nominateTx = nominateOperator({
|
|
180
|
-
* api,
|
|
181
|
-
* operatorId: '1',
|
|
182
|
-
* amountToStake: '50000000000000000000' // 50 AI3
|
|
183
|
-
* })
|
|
184
|
-
*
|
|
185
|
-
* await signAndSendTx(nominator, nominateTx)
|
|
186
|
-
* ```
|
|
187
|
-
*/
|
|
188
|
-
export declare const nominateOperator: (params: NominateOperatorParams) => import("@autonomys/auto-utils").SubmittableExtrinsic<"promise", import("@autonomys/auto-utils").ISubmittableResult>;
|
|
189
|
-
/**
|
|
190
|
-
* Creates a transaction to withdraw stake from an operator.
|
|
191
|
-
*
|
|
192
|
-
* This function creates a transaction to withdraw staked tokens from an operator.
|
|
193
|
-
* As per the latest protocol, withdrawals are specified strictly in shares.
|
|
194
|
-
* Withdrawn stake enters a withdrawal period before being available.
|
|
195
|
-
*
|
|
196
|
-
* @param params - WithdrawStakeParams containing withdrawal parameters
|
|
197
|
-
* @param params.api - The connected API promise instance
|
|
198
|
-
* @param params.operatorId - The ID of the operator to withdraw stake from
|
|
199
|
-
* @param params.shares - Number of shares to withdraw (string/number/bigint)
|
|
200
|
-
* @returns A submittable stake withdrawal transaction
|
|
201
|
-
* @throws Error if no withdrawal method specified or transaction creation fails
|
|
202
|
-
*
|
|
203
|
-
* @example
|
|
204
|
-
* ```typescript
|
|
205
|
-
* import { withdrawStake } from '@autonomys/auto-consensus'
|
|
206
|
-
* import { activate, signAndSendTx } from '@autonomys/auto-utils'
|
|
207
|
-
*
|
|
208
|
-
* const api = await activate({ networkId: 'mainnet' })
|
|
209
|
-
*
|
|
210
|
-
* // Withdraw all stake
|
|
211
|
-
* const withdrawAllTx = withdrawStake({ api, operatorId: '1', all: true })
|
|
212
|
-
*
|
|
213
|
-
* // Withdraw 50% of stake
|
|
214
|
-
* const withdrawPercentTx = withdrawStake({ api, operatorId: '1', percent: '50' })
|
|
215
|
-
*
|
|
216
|
-
* // Withdraw specific amount
|
|
217
|
-
* const withdrawAmountTx = withdrawStake({
|
|
218
|
-
* api,
|
|
219
|
-
* operatorId: '1',
|
|
220
|
-
* stake: '25000000000000000000'
|
|
221
|
-
* })
|
|
222
|
-
*
|
|
223
|
-
* await signAndSendTx(staker, withdrawAllTx)
|
|
224
|
-
* ```
|
|
225
|
-
*/
|
|
226
|
-
export declare const withdrawStake: (params: WithdrawStakeParams) => import("@autonomys/auto-utils").SubmittableExtrinsic<"promise", import("@autonomys/auto-utils").ISubmittableResult>;
|
|
227
|
-
/**
|
|
228
|
-
* Creates a transaction to deregister an operator.
|
|
229
|
-
*
|
|
230
|
-
* This function creates a transaction to deregister an operator, removing them
|
|
231
|
-
* from active service. The operator will no longer process transactions or earn
|
|
232
|
-
* rewards. All stakes will enter the withdrawal period.
|
|
233
|
-
*
|
|
234
|
-
* @param params - StakingParams containing the operator information
|
|
235
|
-
* @param params.api - The connected API promise instance
|
|
236
|
-
* @param params.operatorId - The ID of the operator to deregister
|
|
237
|
-
* @returns A submittable operator deregistration transaction
|
|
238
|
-
* @throws Error if transaction creation fails
|
|
239
|
-
*
|
|
240
|
-
* @example
|
|
241
|
-
* ```typescript
|
|
242
|
-
* import { deregisterOperator } from '@autonomys/auto-consensus'
|
|
243
|
-
* import { activate, signAndSendTx } from '@autonomys/auto-utils'
|
|
244
|
-
*
|
|
245
|
-
* const api = await activate({ networkId: 'mainnet' })
|
|
246
|
-
*
|
|
247
|
-
* const deregisterTx = deregisterOperator({
|
|
248
|
-
* api,
|
|
249
|
-
* operatorId: '1'
|
|
250
|
-
* })
|
|
251
|
-
*
|
|
252
|
-
* await signAndSendTx(operatorOwner, deregisterTx)
|
|
253
|
-
* ```
|
|
254
|
-
*/
|
|
255
|
-
export declare const deregisterOperator: (params: StakingParams) => import("@autonomys/auto-utils").SubmittableExtrinsic<"promise", import("@autonomys/auto-utils").ISubmittableResult>;
|
|
256
|
-
/**
|
|
257
|
-
* Creates a transaction to unlock funds from an operator.
|
|
258
|
-
*
|
|
259
|
-
* This function creates a transaction to unlock funds that have completed
|
|
260
|
-
* their withdrawal period. These are funds that were previously withdrawn
|
|
261
|
-
* and have now passed the required waiting period.
|
|
262
|
-
*
|
|
263
|
-
* @param params - StakingParams containing the operator information
|
|
264
|
-
* @param params.api - The connected API promise instance
|
|
265
|
-
* @param params.operatorId - The ID of the operator to unlock funds from
|
|
266
|
-
* @returns A submittable unlock funds transaction
|
|
267
|
-
* @throws Error if transaction creation fails
|
|
268
|
-
*
|
|
269
|
-
* @example
|
|
270
|
-
* ```typescript
|
|
271
|
-
* import { unlockFunds } from '@autonomys/auto-consensus'
|
|
272
|
-
* import { activate, signAndSendTx } from '@autonomys/auto-utils'
|
|
273
|
-
*
|
|
274
|
-
* const api = await activate({ networkId: 'mainnet' })
|
|
275
|
-
*
|
|
276
|
-
* const unlockTx = unlockFunds({
|
|
277
|
-
* api,
|
|
278
|
-
* operatorId: '1'
|
|
279
|
-
* })
|
|
280
|
-
*
|
|
281
|
-
* await signAndSendTx(account, unlockTx)
|
|
282
|
-
* ```
|
|
283
|
-
*/
|
|
284
|
-
export declare const unlockFunds: (params: StakingParams) => import("@autonomys/auto-utils").SubmittableExtrinsic<"promise", import("@autonomys/auto-utils").ISubmittableResult>;
|
|
285
|
-
/**
|
|
286
|
-
* Creates a transaction to unlock a nominator from an operator.
|
|
287
|
-
*
|
|
288
|
-
* This function creates a transaction to unlock a nominator's position,
|
|
289
|
-
* allowing them to withdraw their stake after the withdrawal period.
|
|
290
|
-
* This is typically used when a nominator wants to completely exit their
|
|
291
|
-
* position with an operator.
|
|
292
|
-
*
|
|
293
|
-
* @param params - StakingParams containing the operator information
|
|
294
|
-
* @param params.api - The connected API promise instance
|
|
295
|
-
* @param params.operatorId - The ID of the operator to unlock nominator from
|
|
296
|
-
* @returns A submittable unlock nominator transaction
|
|
297
|
-
* @throws Error if transaction creation fails
|
|
298
|
-
*
|
|
299
|
-
* @example
|
|
300
|
-
* ```typescript
|
|
301
|
-
* import { unlockNominator } from '@autonomys/auto-consensus'
|
|
302
|
-
* import { activate, signAndSendTx } from '@autonomys/auto-utils'
|
|
303
|
-
*
|
|
304
|
-
* const api = await activate({ networkId: 'mainnet' })
|
|
305
|
-
*
|
|
306
|
-
* const unlockNominatorTx = unlockNominator({
|
|
307
|
-
* api,
|
|
308
|
-
* operatorId: '1'
|
|
309
|
-
* })
|
|
310
|
-
*
|
|
311
|
-
* await signAndSendTx(nominator, unlockNominatorTx)
|
|
312
|
-
* ```
|
|
313
|
-
*/
|
|
314
|
-
export declare const unlockNominator: (params: StakingParams) => import("@autonomys/auto-utils").SubmittableExtrinsic<"promise", import("@autonomys/auto-utils").ISubmittableResult>;
|
|
315
|
-
//# sourceMappingURL=staking.d.ts.map
|
package/dist/staking.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"staking.d.ts","sourceRoot":"","sources":["../src/staking.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAA8B,MAAM,uBAAuB,CAAA;AACvE,OAAO,KAAK,EACV,sBAAsB,EACtB,sBAAsB,EACtB,aAAa,EACb,oBAAoB,EACpB,mBAAmB,EACpB,MAAM,iBAAiB,CAAA;AASxB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,SAAS,GAAU,KAAK,GAAG,kDAQvC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,QAAQ,GAAU,KAAK,GAAG,EAAE,YAAY,oBAAoB,uDAQxE,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,QAAQ,GACnB,KAAK,GAAG,EACR,YAAY,oBAAoB,EAChC,UAAS,MAAM,GAAG,SAAqB,iDAgBxC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,WAAW,GACtB,KAAK,GAAG,EACR,YAAY,oBAAoB,EAChC,UAAS,MAAM,GAAG,SAAqB,oDAkBxC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,sBAAsB,wHAmB9D,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,sBAAsB,wHAS9D,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,aAAa,GAAI,QAAQ,mBAAmB,wHAWxD,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,kBAAkB,GAAI,QAAQ,aAAa,wHASvD,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,WAAW,GAAI,QAAQ,aAAa,wHAShD,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,aAAa,wHASpD,CAAA"}
|
package/dist/staking.js
DELETED
|
@@ -1,458 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// file: src/staking.ts
|
|
3
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.unlockNominator = exports.unlockFunds = exports.deregisterOperator = exports.withdrawStake = exports.nominateOperator = exports.registerOperator = exports.withdrawals = exports.deposits = exports.operator = exports.operators = void 0;
|
|
14
|
-
const auto_utils_1 = require("@autonomys/auto-utils");
|
|
15
|
-
const parse_1 = require("./utils/parse");
|
|
16
|
-
/**
|
|
17
|
-
* Retrieves all registered operators on the network.
|
|
18
|
-
*
|
|
19
|
-
* This function queries the blockchain to get information about all operators
|
|
20
|
-
* that have been registered across all domains. Operators are entities that
|
|
21
|
-
* process transactions and maintain domain chains.
|
|
22
|
-
*
|
|
23
|
-
* @param api - The connected API instance
|
|
24
|
-
* @returns Promise that resolves to an array of Operator objects
|
|
25
|
-
* @throws Error if the operators query fails
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```typescript
|
|
29
|
-
* import { operators } from '@autonomys/auto-consensus'
|
|
30
|
-
* import { activate } from '@autonomys/auto-utils'
|
|
31
|
-
*
|
|
32
|
-
* const api = await activate({ networkId: 'mainnet' })
|
|
33
|
-
* const allOperators = await operators(api)
|
|
34
|
-
*
|
|
35
|
-
* allOperators.forEach(op => {
|
|
36
|
-
* console.log(`Operator ${op.operatorId}: Domain ${op.operatorDetails.currentDomainId}`)
|
|
37
|
-
* console.log(`Total Stake: ${op.operatorDetails.currentTotalStake}`)
|
|
38
|
-
* })
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
const operators = (api) => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
-
try {
|
|
43
|
-
const _operators = yield api.query.domains.operators.entries();
|
|
44
|
-
return _operators.map((o) => (0, parse_1.parseOperator)(o));
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
console.error('error', error);
|
|
48
|
-
throw new Error('Error querying operators list.' + error);
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
exports.operators = operators;
|
|
52
|
-
/**
|
|
53
|
-
* Retrieves detailed information about a specific operator.
|
|
54
|
-
*
|
|
55
|
-
* This function queries information about a single operator including their
|
|
56
|
-
* signing key, domain assignment, stake amounts, and operational status.
|
|
57
|
-
*
|
|
58
|
-
* @param api - The connected API instance
|
|
59
|
-
* @param operatorId - The ID of the operator to query
|
|
60
|
-
* @returns Promise that resolves to OperatorDetails object
|
|
61
|
-
* @throws Error if the operator query fails or operator doesn't exist
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* ```typescript
|
|
65
|
-
* import { operator } from '@autonomys/auto-consensus'
|
|
66
|
-
* import { activate } from '@autonomys/auto-utils'
|
|
67
|
-
*
|
|
68
|
-
* const api = await activate({ networkId: 'mainnet' })
|
|
69
|
-
* const operatorInfo = await operator(api, '1')
|
|
70
|
-
*
|
|
71
|
-
* console.log(`Domain: ${operatorInfo.currentDomainId}`)
|
|
72
|
-
* console.log(`Total Stake: ${operatorInfo.currentTotalStake}`)
|
|
73
|
-
* console.log(`Minimum Nominator Stake: ${operatorInfo.minimumNominatorStake}`)
|
|
74
|
-
* console.log(`Nomination Tax: ${operatorInfo.nominationTax}%`)
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
const operator = (api, operatorId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
78
|
-
try {
|
|
79
|
-
const _operator = yield api.query.domains.operators((0, parse_1.parseString)(operatorId));
|
|
80
|
-
return (0, parse_1.parseOperatorDetails)(_operator);
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
console.error('error', error);
|
|
84
|
-
throw new Error(`Error querying operatorId: ${operatorId} with error: ${error}`);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
exports.operator = operator;
|
|
88
|
-
/**
|
|
89
|
-
* Retrieves deposit information for an operator.
|
|
90
|
-
*
|
|
91
|
-
* This function queries all deposits (stakes) made to a specific operator.
|
|
92
|
-
* It can optionally filter deposits by a specific account address.
|
|
93
|
-
*
|
|
94
|
-
* @param api - The connected API instance
|
|
95
|
-
* @param operatorId - The ID of the operator to query deposits for
|
|
96
|
-
* @param account - Optional account address to filter deposits by
|
|
97
|
-
* @returns Promise that resolves to an array of Deposit objects
|
|
98
|
-
* @throws Error if the deposits query fails
|
|
99
|
-
*
|
|
100
|
-
* @example
|
|
101
|
-
* ```typescript
|
|
102
|
-
* import { deposits } from '@autonomys/auto-consensus'
|
|
103
|
-
* import { activate } from '@autonomys/auto-utils'
|
|
104
|
-
*
|
|
105
|
-
* const api = await activate({ networkId: 'mainnet' })
|
|
106
|
-
*
|
|
107
|
-
* // Get all deposits for operator
|
|
108
|
-
* const allDeposits = await deposits(api, '1')
|
|
109
|
-
*
|
|
110
|
-
* // Get deposits for specific account
|
|
111
|
-
* const accountDeposits = await deposits(api, '1', 'account_address')
|
|
112
|
-
*
|
|
113
|
-
* allDeposits.forEach(deposit => {
|
|
114
|
-
* console.log(`Account: ${deposit.account}, Shares: ${deposit.shares}`)
|
|
115
|
-
* })
|
|
116
|
-
* ```
|
|
117
|
-
*/
|
|
118
|
-
const deposits = (api_1, operatorId_1, ...args_1) => __awaiter(void 0, [api_1, operatorId_1, ...args_1], void 0, function* (api, operatorId, account = undefined) {
|
|
119
|
-
try {
|
|
120
|
-
if (account) {
|
|
121
|
-
// For specific account, query all deposits for operator and filter
|
|
122
|
-
const _deposits = yield api.query.domains.deposits.entries((0, parse_1.parseString)(operatorId));
|
|
123
|
-
return _deposits.map((o) => (0, parse_1.parseDeposit)(o)).filter((deposit) => deposit.account === account);
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
// Query all deposits for operator
|
|
127
|
-
const _deposits = yield api.query.domains.deposits.entries((0, parse_1.parseString)(operatorId));
|
|
128
|
-
return _deposits.map((o) => (0, parse_1.parseDeposit)(o));
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
catch (error) {
|
|
132
|
-
console.error('error', error);
|
|
133
|
-
throw new Error('Error querying deposits list.' + error);
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
exports.deposits = deposits;
|
|
137
|
-
/**
|
|
138
|
-
* Retrieves withdrawal information for an operator.
|
|
139
|
-
*
|
|
140
|
-
* This function queries all pending withdrawals for a specific operator.
|
|
141
|
-
* Withdrawals are stakes that have been requested to be unstaked but are
|
|
142
|
-
* still in the withdrawal period. Can optionally filter by account.
|
|
143
|
-
*
|
|
144
|
-
* @param api - The connected API instance
|
|
145
|
-
* @param operatorId - The ID of the operator to query withdrawals for
|
|
146
|
-
* @param account - Optional account address to filter withdrawals by
|
|
147
|
-
* @returns Promise that resolves to an array of Withdrawal objects
|
|
148
|
-
* @throws Error if the withdrawals query fails
|
|
149
|
-
*
|
|
150
|
-
* @example
|
|
151
|
-
* ```typescript
|
|
152
|
-
* import { withdrawals } from '@autonomys/auto-consensus'
|
|
153
|
-
* import { activate } from '@autonomys/auto-utils'
|
|
154
|
-
*
|
|
155
|
-
* const api = await activate({ networkId: 'mainnet' })
|
|
156
|
-
*
|
|
157
|
-
* // Get all withdrawals for operator
|
|
158
|
-
* const allWithdrawals = await withdrawals(api, '1')
|
|
159
|
-
*
|
|
160
|
-
* // Get withdrawals for specific account
|
|
161
|
-
* const accountWithdrawals = await withdrawals(api, '1', 'account_address')
|
|
162
|
-
*
|
|
163
|
-
* allWithdrawals.forEach(withdrawal => {
|
|
164
|
-
* console.log(`Account: ${withdrawal.account}`)
|
|
165
|
-
* console.log(`Total Withdrawal: ${withdrawal.totalWithdrawalAmount}`)
|
|
166
|
-
* })
|
|
167
|
-
* ```
|
|
168
|
-
*/
|
|
169
|
-
const withdrawals = (api_1, operatorId_1, ...args_1) => __awaiter(void 0, [api_1, operatorId_1, ...args_1], void 0, function* (api, operatorId, account = undefined) {
|
|
170
|
-
try {
|
|
171
|
-
if (account) {
|
|
172
|
-
// For specific account, query all withdrawals for operator and filter
|
|
173
|
-
const _withdrawals = yield api.query.domains.withdrawals.entries((0, parse_1.parseString)(operatorId));
|
|
174
|
-
return _withdrawals
|
|
175
|
-
.map((o) => (0, parse_1.parseWithdrawal)(o))
|
|
176
|
-
.filter((withdrawal) => withdrawal.account === account);
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
// Query all withdrawals for operator
|
|
180
|
-
const _withdrawals = yield api.query.domains.withdrawals.entries((0, parse_1.parseString)(operatorId));
|
|
181
|
-
return _withdrawals.map((o) => (0, parse_1.parseWithdrawal)(o));
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
catch (error) {
|
|
185
|
-
console.error('error', error);
|
|
186
|
-
throw new Error('Error querying withdrawals list.' + error);
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
exports.withdrawals = withdrawals;
|
|
190
|
-
/**
|
|
191
|
-
* Creates a transaction to register a new operator.
|
|
192
|
-
*
|
|
193
|
-
* This function creates a transaction to register a new operator on a specific domain.
|
|
194
|
-
* The operator will be able to process transactions and earn rewards. Requires
|
|
195
|
-
* initial stake, minimum nominator stake, and nomination tax settings.
|
|
196
|
-
*
|
|
197
|
-
* @param params - RegisterOperatorParams containing all registration parameters
|
|
198
|
-
* @param params.api - The connected API promise instance
|
|
199
|
-
* @param params.domainId - The domain ID where the operator will be registered
|
|
200
|
-
* @param params.amountToStake - Initial amount to stake (in smallest token units)
|
|
201
|
-
* @param params.minimumNominatorStake - Minimum stake required from nominators
|
|
202
|
-
* @param params.nominationTax - Percentage fee charged to nominators
|
|
203
|
-
* @param params.signingKey - Optional signing key (derived from publicKey if not provided)
|
|
204
|
-
* @param params.publicKey - Optional public key (used to derive signingKey if needed)
|
|
205
|
-
* @returns A submittable operator registration transaction
|
|
206
|
-
* @throws Error if signing key/public key not provided or transaction creation fails
|
|
207
|
-
*
|
|
208
|
-
* @example
|
|
209
|
-
* ```typescript
|
|
210
|
-
* import { registerOperator } from '@autonomys/auto-consensus'
|
|
211
|
-
* import { activate, activateWallet, signAndSendTx } from '@autonomys/auto-utils'
|
|
212
|
-
*
|
|
213
|
-
* const api = await activate({ networkId: 'mainnet' })
|
|
214
|
-
* const { accounts } = await activateWallet({ networkId: 'mainnet', mnemonic })
|
|
215
|
-
*
|
|
216
|
-
* const registerTx = registerOperator({
|
|
217
|
-
* api,
|
|
218
|
-
* domainId: '0',
|
|
219
|
-
* amountToStake: '100000000000000000000', // 100 AI3
|
|
220
|
-
* minimumNominatorStake: '1000000000000000000', // 1 AI3
|
|
221
|
-
* nominationTax: '10', // 10%
|
|
222
|
-
* publicKey: accounts[0].publicKey
|
|
223
|
-
* })
|
|
224
|
-
*
|
|
225
|
-
* await signAndSendTx(accounts[0], registerTx)
|
|
226
|
-
* ```
|
|
227
|
-
*/
|
|
228
|
-
const registerOperator = (params) => {
|
|
229
|
-
try {
|
|
230
|
-
const { api, domainId, amountToStake, minimumNominatorStake, nominationTax, publicKey } = params;
|
|
231
|
-
let signingKey = params.signingKey;
|
|
232
|
-
if (!signingKey && !publicKey)
|
|
233
|
-
throw new Error('Signing key or public key not provided');
|
|
234
|
-
else if (!signingKey && publicKey)
|
|
235
|
-
signingKey = (0, auto_utils_1.signingKey)(publicKey);
|
|
236
|
-
if (!signingKey)
|
|
237
|
-
throw new Error('Signing key not provided');
|
|
238
|
-
return api.tx.domains.registerOperator((0, parse_1.parseString)(domainId), (0, parse_1.parseString)(amountToStake), {
|
|
239
|
-
signingKey,
|
|
240
|
-
minimumNominatorStake: (0, parse_1.parseString)(minimumNominatorStake),
|
|
241
|
-
nominationTax: (0, parse_1.parseString)(nominationTax),
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
catch (error) {
|
|
245
|
-
console.error('error', error);
|
|
246
|
-
throw new Error('Error creating register operator tx.' + error);
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
exports.registerOperator = registerOperator;
|
|
250
|
-
/**
|
|
251
|
-
* Creates a transaction to nominate (stake to) an existing operator.
|
|
252
|
-
*
|
|
253
|
-
* This function creates a transaction to stake tokens to an existing operator.
|
|
254
|
-
* Nominators earn rewards proportional to their stake, minus the operator's
|
|
255
|
-
* nomination tax. The stake helps secure the network and the specific domain.
|
|
256
|
-
*
|
|
257
|
-
* @param params - NominateOperatorParams containing nomination parameters
|
|
258
|
-
* @param params.api - The connected API promise instance
|
|
259
|
-
* @param params.operatorId - The ID of the operator to nominate
|
|
260
|
-
* @param params.amountToStake - Amount to stake (in smallest token units)
|
|
261
|
-
* @returns A submittable operator nomination transaction
|
|
262
|
-
* @throws Error if transaction creation fails
|
|
263
|
-
*
|
|
264
|
-
* @example
|
|
265
|
-
* ```typescript
|
|
266
|
-
* import { nominateOperator } from '@autonomys/auto-consensus'
|
|
267
|
-
* import { activate, signAndSendTx } from '@autonomys/auto-utils'
|
|
268
|
-
*
|
|
269
|
-
* const api = await activate({ networkId: 'mainnet' })
|
|
270
|
-
*
|
|
271
|
-
* const nominateTx = nominateOperator({
|
|
272
|
-
* api,
|
|
273
|
-
* operatorId: '1',
|
|
274
|
-
* amountToStake: '50000000000000000000' // 50 AI3
|
|
275
|
-
* })
|
|
276
|
-
*
|
|
277
|
-
* await signAndSendTx(nominator, nominateTx)
|
|
278
|
-
* ```
|
|
279
|
-
*/
|
|
280
|
-
const nominateOperator = (params) => {
|
|
281
|
-
try {
|
|
282
|
-
const { api, operatorId, amountToStake } = params;
|
|
283
|
-
return api.tx.domains.nominateOperator((0, parse_1.parseString)(operatorId), (0, parse_1.parseString)(amountToStake));
|
|
284
|
-
}
|
|
285
|
-
catch (error) {
|
|
286
|
-
console.error('error', error);
|
|
287
|
-
throw new Error('Error creating nominate operator tx.' + error);
|
|
288
|
-
}
|
|
289
|
-
};
|
|
290
|
-
exports.nominateOperator = nominateOperator;
|
|
291
|
-
/**
|
|
292
|
-
* Creates a transaction to withdraw stake from an operator.
|
|
293
|
-
*
|
|
294
|
-
* This function creates a transaction to withdraw staked tokens from an operator.
|
|
295
|
-
* As per the latest protocol, withdrawals are specified strictly in shares.
|
|
296
|
-
* Withdrawn stake enters a withdrawal period before being available.
|
|
297
|
-
*
|
|
298
|
-
* @param params - WithdrawStakeParams containing withdrawal parameters
|
|
299
|
-
* @param params.api - The connected API promise instance
|
|
300
|
-
* @param params.operatorId - The ID of the operator to withdraw stake from
|
|
301
|
-
* @param params.shares - Number of shares to withdraw (string/number/bigint)
|
|
302
|
-
* @returns A submittable stake withdrawal transaction
|
|
303
|
-
* @throws Error if no withdrawal method specified or transaction creation fails
|
|
304
|
-
*
|
|
305
|
-
* @example
|
|
306
|
-
* ```typescript
|
|
307
|
-
* import { withdrawStake } from '@autonomys/auto-consensus'
|
|
308
|
-
* import { activate, signAndSendTx } from '@autonomys/auto-utils'
|
|
309
|
-
*
|
|
310
|
-
* const api = await activate({ networkId: 'mainnet' })
|
|
311
|
-
*
|
|
312
|
-
* // Withdraw all stake
|
|
313
|
-
* const withdrawAllTx = withdrawStake({ api, operatorId: '1', all: true })
|
|
314
|
-
*
|
|
315
|
-
* // Withdraw 50% of stake
|
|
316
|
-
* const withdrawPercentTx = withdrawStake({ api, operatorId: '1', percent: '50' })
|
|
317
|
-
*
|
|
318
|
-
* // Withdraw specific amount
|
|
319
|
-
* const withdrawAmountTx = withdrawStake({
|
|
320
|
-
* api,
|
|
321
|
-
* operatorId: '1',
|
|
322
|
-
* stake: '25000000000000000000'
|
|
323
|
-
* })
|
|
324
|
-
*
|
|
325
|
-
* await signAndSendTx(staker, withdrawAllTx)
|
|
326
|
-
* ```
|
|
327
|
-
*/
|
|
328
|
-
const withdrawStake = (params) => {
|
|
329
|
-
try {
|
|
330
|
-
const { api, operatorId, shares } = params;
|
|
331
|
-
if (shares === undefined || shares === null)
|
|
332
|
-
throw new Error('Provide shares(string/number/bigint) to withdraw stake');
|
|
333
|
-
return api.tx.domains.withdrawStake((0, parse_1.parseString)(operatorId), (0, parse_1.parseString)(shares));
|
|
334
|
-
}
|
|
335
|
-
catch (error) {
|
|
336
|
-
console.error('error', error);
|
|
337
|
-
throw new Error('Error creating withdraw stake tx.' + error);
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
exports.withdrawStake = withdrawStake;
|
|
341
|
-
/**
|
|
342
|
-
* Creates a transaction to deregister an operator.
|
|
343
|
-
*
|
|
344
|
-
* This function creates a transaction to deregister an operator, removing them
|
|
345
|
-
* from active service. The operator will no longer process transactions or earn
|
|
346
|
-
* rewards. All stakes will enter the withdrawal period.
|
|
347
|
-
*
|
|
348
|
-
* @param params - StakingParams containing the operator information
|
|
349
|
-
* @param params.api - The connected API promise instance
|
|
350
|
-
* @param params.operatorId - The ID of the operator to deregister
|
|
351
|
-
* @returns A submittable operator deregistration transaction
|
|
352
|
-
* @throws Error if transaction creation fails
|
|
353
|
-
*
|
|
354
|
-
* @example
|
|
355
|
-
* ```typescript
|
|
356
|
-
* import { deregisterOperator } from '@autonomys/auto-consensus'
|
|
357
|
-
* import { activate, signAndSendTx } from '@autonomys/auto-utils'
|
|
358
|
-
*
|
|
359
|
-
* const api = await activate({ networkId: 'mainnet' })
|
|
360
|
-
*
|
|
361
|
-
* const deregisterTx = deregisterOperator({
|
|
362
|
-
* api,
|
|
363
|
-
* operatorId: '1'
|
|
364
|
-
* })
|
|
365
|
-
*
|
|
366
|
-
* await signAndSendTx(operatorOwner, deregisterTx)
|
|
367
|
-
* ```
|
|
368
|
-
*/
|
|
369
|
-
const deregisterOperator = (params) => {
|
|
370
|
-
try {
|
|
371
|
-
const { api, operatorId } = params;
|
|
372
|
-
return api.tx.domains.deregisterOperator((0, parse_1.parseString)(operatorId));
|
|
373
|
-
}
|
|
374
|
-
catch (error) {
|
|
375
|
-
console.error('error', error);
|
|
376
|
-
throw new Error('Error creating de-register operator tx.' + error);
|
|
377
|
-
}
|
|
378
|
-
};
|
|
379
|
-
exports.deregisterOperator = deregisterOperator;
|
|
380
|
-
/**
|
|
381
|
-
* Creates a transaction to unlock funds from an operator.
|
|
382
|
-
*
|
|
383
|
-
* This function creates a transaction to unlock funds that have completed
|
|
384
|
-
* their withdrawal period. These are funds that were previously withdrawn
|
|
385
|
-
* and have now passed the required waiting period.
|
|
386
|
-
*
|
|
387
|
-
* @param params - StakingParams containing the operator information
|
|
388
|
-
* @param params.api - The connected API promise instance
|
|
389
|
-
* @param params.operatorId - The ID of the operator to unlock funds from
|
|
390
|
-
* @returns A submittable unlock funds transaction
|
|
391
|
-
* @throws Error if transaction creation fails
|
|
392
|
-
*
|
|
393
|
-
* @example
|
|
394
|
-
* ```typescript
|
|
395
|
-
* import { unlockFunds } from '@autonomys/auto-consensus'
|
|
396
|
-
* import { activate, signAndSendTx } from '@autonomys/auto-utils'
|
|
397
|
-
*
|
|
398
|
-
* const api = await activate({ networkId: 'mainnet' })
|
|
399
|
-
*
|
|
400
|
-
* const unlockTx = unlockFunds({
|
|
401
|
-
* api,
|
|
402
|
-
* operatorId: '1'
|
|
403
|
-
* })
|
|
404
|
-
*
|
|
405
|
-
* await signAndSendTx(account, unlockTx)
|
|
406
|
-
* ```
|
|
407
|
-
*/
|
|
408
|
-
const unlockFunds = (params) => {
|
|
409
|
-
try {
|
|
410
|
-
const { api, operatorId } = params;
|
|
411
|
-
return api.tx.domains.unlockFunds((0, parse_1.parseString)(operatorId));
|
|
412
|
-
}
|
|
413
|
-
catch (error) {
|
|
414
|
-
console.error('error', error);
|
|
415
|
-
throw new Error('Error creating unlock funds tx.' + error);
|
|
416
|
-
}
|
|
417
|
-
};
|
|
418
|
-
exports.unlockFunds = unlockFunds;
|
|
419
|
-
/**
|
|
420
|
-
* Creates a transaction to unlock a nominator from an operator.
|
|
421
|
-
*
|
|
422
|
-
* This function creates a transaction to unlock a nominator's position,
|
|
423
|
-
* allowing them to withdraw their stake after the withdrawal period.
|
|
424
|
-
* This is typically used when a nominator wants to completely exit their
|
|
425
|
-
* position with an operator.
|
|
426
|
-
*
|
|
427
|
-
* @param params - StakingParams containing the operator information
|
|
428
|
-
* @param params.api - The connected API promise instance
|
|
429
|
-
* @param params.operatorId - The ID of the operator to unlock nominator from
|
|
430
|
-
* @returns A submittable unlock nominator transaction
|
|
431
|
-
* @throws Error if transaction creation fails
|
|
432
|
-
*
|
|
433
|
-
* @example
|
|
434
|
-
* ```typescript
|
|
435
|
-
* import { unlockNominator } from '@autonomys/auto-consensus'
|
|
436
|
-
* import { activate, signAndSendTx } from '@autonomys/auto-utils'
|
|
437
|
-
*
|
|
438
|
-
* const api = await activate({ networkId: 'mainnet' })
|
|
439
|
-
*
|
|
440
|
-
* const unlockNominatorTx = unlockNominator({
|
|
441
|
-
* api,
|
|
442
|
-
* operatorId: '1'
|
|
443
|
-
* })
|
|
444
|
-
*
|
|
445
|
-
* await signAndSendTx(nominator, unlockNominatorTx)
|
|
446
|
-
* ```
|
|
447
|
-
*/
|
|
448
|
-
const unlockNominator = (params) => {
|
|
449
|
-
try {
|
|
450
|
-
const { api, operatorId } = params;
|
|
451
|
-
return api.tx.domains.unlockNominator((0, parse_1.parseString)(operatorId));
|
|
452
|
-
}
|
|
453
|
-
catch (error) {
|
|
454
|
-
console.error('error', error);
|
|
455
|
-
throw new Error('Error creating unlock nominator tx.' + error);
|
|
456
|
-
}
|
|
457
|
-
};
|
|
458
|
-
exports.unlockNominator = unlockNominator;
|