@autonomys/auto-consensus 1.5.8 → 1.5.9
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/dist/position/index.d.ts +3 -41
- package/dist/position/index.d.ts.map +1 -1
- package/dist/position/index.js +16 -169
- package/dist/position/position.d.ts +43 -0
- package/dist/position/position.d.ts.map +1 -0
- package/dist/position/position.js +70 -0
- package/dist/position/runtime.d.ts +67 -0
- package/dist/position/runtime.d.ts.map +1 -0
- package/dist/position/runtime.js +53 -0
- package/dist/types/position.d.ts +9 -5
- package/dist/types/position.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/position.d.ts +0 -4
- package/dist/position.d.ts.map +0 -1
- package/dist/position.js +0 -20
package/dist/position/index.d.ts
CHANGED
|
@@ -1,42 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Retrieves the complete staking position of a nominator for a specific operator.
|
|
5
|
-
*
|
|
6
|
-
* This function calculates the comprehensive staking position of a nominator including
|
|
7
|
-
* current value, pending deposits, pending withdrawals, and storage fee deposits.
|
|
8
|
-
* It handles complex calculations involving share prices across different epochs
|
|
9
|
-
* and provides a complete view of the nominator's stake position.
|
|
10
|
-
*
|
|
11
|
-
* @param api - The connected API instance
|
|
12
|
-
* @param operatorId - The ID of the operator to query position for
|
|
13
|
-
* @param nominatorAccountId - The account ID of the nominator
|
|
14
|
-
* @returns Promise that resolves to NominatorPosition with complete position details
|
|
15
|
-
* @throws Error if operator not found, domain staking summary unavailable, or calculation fails
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```typescript
|
|
19
|
-
* import { nominatorPosition } from '@autonomys/auto-consensus'
|
|
20
|
-
* import { activate } from '@autonomys/auto-utils'
|
|
21
|
-
*
|
|
22
|
-
* const api = await activate({ networkId: 'gemini-3h' })
|
|
23
|
-
* const position = await nominatorPosition(api, '1', 'nominator_account_address')
|
|
24
|
-
*
|
|
25
|
-
* console.log(`Current Value: ${position.knownValue}`)
|
|
26
|
-
* console.log(`Storage Fee Deposit: ${position.storageFeeDeposit}`)
|
|
27
|
-
* console.log(`Pending Deposits: ${position.pendingDeposits.length}`)
|
|
28
|
-
* console.log(`Pending Withdrawals: ${position.pendingWithdrawals.length}`)
|
|
29
|
-
*
|
|
30
|
-
* // Check pending deposits
|
|
31
|
-
* position.pendingDeposits.forEach(deposit => {
|
|
32
|
-
* console.log(`Pending: ${deposit.amount} at epoch ${deposit.effectiveEpoch}`)
|
|
33
|
-
* })
|
|
34
|
-
*
|
|
35
|
-
* // Check pending withdrawals
|
|
36
|
-
* position.pendingWithdrawals.forEach(withdrawal => {
|
|
37
|
-
* console.log(`Withdrawal: ${withdrawal.amount} unlocks at block ${withdrawal.unlockAtBlock}`)
|
|
38
|
-
* })
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export declare const nominatorPosition: (api: Api, operatorId: string | number | bigint, nominatorAccountId: string) => Promise<NominatorPosition>;
|
|
1
|
+
export * from './position';
|
|
2
|
+
export * from './price';
|
|
3
|
+
export * from './utils';
|
|
42
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/position/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/position/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA"}
|
package/dist/position/index.js
CHANGED
|
@@ -1,172 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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);
|
|
10
15
|
};
|
|
11
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const price_1 = require("./price");
|
|
16
|
-
const utils_1 = require("./utils");
|
|
17
|
-
/**
|
|
18
|
-
* Processes pending deposits to calculate additional shares and storage fees
|
|
19
|
-
*/
|
|
20
|
-
const processPendingDeposits = (api, operatorId, depositData, currentEpochIndex) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
-
const zeroAmounts = {
|
|
22
|
-
additionalShares: BigInt(0),
|
|
23
|
-
pendingStorageFee: BigInt(0),
|
|
24
|
-
pendingDeposits: [],
|
|
25
|
-
};
|
|
26
|
-
if (!depositData.pending)
|
|
27
|
-
return zeroAmounts;
|
|
28
|
-
const { effectiveDomainEpoch, amount, storageFeeDeposit: pendingStorageFee } = depositData.pending;
|
|
29
|
-
// If epoch hasn't passed yet, keep as pending
|
|
30
|
-
if (effectiveDomainEpoch >= currentEpochIndex) {
|
|
31
|
-
return Object.assign(Object.assign({}, zeroAmounts), { pendingStorageFee, pendingDeposits: [{ amount, effectiveEpoch: effectiveDomainEpoch }] });
|
|
32
|
-
}
|
|
33
|
-
// Epoch has passed - convert pending amount to shares
|
|
34
|
-
try {
|
|
35
|
-
const epochSharePrice = yield (0, price_1.operatorEpochSharePrice)(api, operatorId, effectiveDomainEpoch, 0);
|
|
36
|
-
const additionalShares = epochSharePrice !== undefined ? (0, utils_1.stakeToShare)(amount, epochSharePrice) : amount; // Fallback: assume 1:1 conversion
|
|
37
|
-
if (epochSharePrice === undefined) {
|
|
38
|
-
console.warn(`No epoch share price found for epoch ${effectiveDomainEpoch}, using pending amount as is`);
|
|
39
|
-
}
|
|
40
|
-
return {
|
|
41
|
-
additionalShares,
|
|
42
|
-
pendingStorageFee, // Storage fee from processed pending deposit
|
|
43
|
-
pendingDeposits: [], // Empty array indicates pending deposit was processed
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
console.warn(`Error getting epoch share price for epoch ${effectiveDomainEpoch}, treating as still pending:`, error);
|
|
48
|
-
return Object.assign(Object.assign({}, zeroAmounts), { pendingStorageFee, pendingDeposits: [{ amount, effectiveEpoch: effectiveDomainEpoch }] });
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
/**
|
|
52
|
-
* Processes pending withdrawals to calculate withdrawal amounts and unlock blocks
|
|
53
|
-
*/
|
|
54
|
-
const processPendingWithdrawals = (api, operatorId, withdrawalsData, currentEpochIndex) => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
-
const pendingWithdrawals = [];
|
|
56
|
-
if (withdrawalsData.length === 0)
|
|
57
|
-
return pendingWithdrawals;
|
|
58
|
-
for (const withdrawal of withdrawalsData) {
|
|
59
|
-
const { withdrawalInShares } = withdrawal;
|
|
60
|
-
// Skip if no withdrawalInShares
|
|
61
|
-
if (!withdrawalInShares)
|
|
62
|
-
continue;
|
|
63
|
-
const { domainEpoch, shares, unlockAtConfirmedDomainBlockNumber } = withdrawalInShares;
|
|
64
|
-
// Process regular withdrawals
|
|
65
|
-
for (const w of withdrawal.withdrawals) {
|
|
66
|
-
pendingWithdrawals.push({
|
|
67
|
-
stakeWithdrawalAmount: w.amountToUnlock,
|
|
68
|
-
unlockAtDomainBlock: w.unlockAtConfirmedDomainBlockNumber,
|
|
69
|
-
storageFeeRefund: w.storageFeeRefund,
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
const sharePrice =
|
|
73
|
-
// If withdrawal epoch has passed, use its share price, otherwise use instant share price
|
|
74
|
-
domainEpoch[1] < currentEpochIndex
|
|
75
|
-
? yield (0, price_1.operatorEpochSharePrice)(api, operatorId, domainEpoch[1], // epoch index
|
|
76
|
-
domainEpoch[0])
|
|
77
|
-
: yield (0, price_1.instantSharePrice)(api, operatorId);
|
|
78
|
-
const withdrawalAmount = sharePrice ? (0, utils_1.shareToStake)(shares, sharePrice) : BigInt(0); // fallback to 0 if no price available
|
|
79
|
-
pendingWithdrawals.push({
|
|
80
|
-
stakeWithdrawalAmount: withdrawalAmount,
|
|
81
|
-
unlockAtDomainBlock: unlockAtConfirmedDomainBlockNumber,
|
|
82
|
-
storageFeeRefund: withdrawalInShares.storageFeeRefund,
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
return pendingWithdrawals;
|
|
86
|
-
});
|
|
87
|
-
/**
|
|
88
|
-
* Retrieves the complete staking position of a nominator for a specific operator.
|
|
89
|
-
*
|
|
90
|
-
* This function calculates the comprehensive staking position of a nominator including
|
|
91
|
-
* current value, pending deposits, pending withdrawals, and storage fee deposits.
|
|
92
|
-
* It handles complex calculations involving share prices across different epochs
|
|
93
|
-
* and provides a complete view of the nominator's stake position.
|
|
94
|
-
*
|
|
95
|
-
* @param api - The connected API instance
|
|
96
|
-
* @param operatorId - The ID of the operator to query position for
|
|
97
|
-
* @param nominatorAccountId - The account ID of the nominator
|
|
98
|
-
* @returns Promise that resolves to NominatorPosition with complete position details
|
|
99
|
-
* @throws Error if operator not found, domain staking summary unavailable, or calculation fails
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* ```typescript
|
|
103
|
-
* import { nominatorPosition } from '@autonomys/auto-consensus'
|
|
104
|
-
* import { activate } from '@autonomys/auto-utils'
|
|
105
|
-
*
|
|
106
|
-
* const api = await activate({ networkId: 'gemini-3h' })
|
|
107
|
-
* const position = await nominatorPosition(api, '1', 'nominator_account_address')
|
|
108
|
-
*
|
|
109
|
-
* console.log(`Current Value: ${position.knownValue}`)
|
|
110
|
-
* console.log(`Storage Fee Deposit: ${position.storageFeeDeposit}`)
|
|
111
|
-
* console.log(`Pending Deposits: ${position.pendingDeposits.length}`)
|
|
112
|
-
* console.log(`Pending Withdrawals: ${position.pendingWithdrawals.length}`)
|
|
113
|
-
*
|
|
114
|
-
* // Check pending deposits
|
|
115
|
-
* position.pendingDeposits.forEach(deposit => {
|
|
116
|
-
* console.log(`Pending: ${deposit.amount} at epoch ${deposit.effectiveEpoch}`)
|
|
117
|
-
* })
|
|
118
|
-
*
|
|
119
|
-
* // Check pending withdrawals
|
|
120
|
-
* position.pendingWithdrawals.forEach(withdrawal => {
|
|
121
|
-
* console.log(`Withdrawal: ${withdrawal.amount} unlocks at block ${withdrawal.unlockAtBlock}`)
|
|
122
|
-
* })
|
|
123
|
-
* ```
|
|
124
|
-
*/
|
|
125
|
-
const nominatorPosition = (api, operatorId, nominatorAccountId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
126
|
-
try {
|
|
127
|
-
// TODO: handle when operator is not found
|
|
128
|
-
const operatorData = yield (0, staking_1.operator)(api, operatorId);
|
|
129
|
-
// Step 1: Get deposits, withdrawals, and domain staking summary
|
|
130
|
-
const [depositsData, withdrawalsData, stakingSummary] = yield Promise.all([
|
|
131
|
-
(0, staking_1.deposits)(api, operatorId, nominatorAccountId),
|
|
132
|
-
(0, staking_1.withdrawals)(api, operatorId, nominatorAccountId),
|
|
133
|
-
(0, domain_1.domainStakingSummary)(api, operatorData.currentDomainId),
|
|
134
|
-
]);
|
|
135
|
-
if (!stakingSummary) {
|
|
136
|
-
throw new Error('Domain staking summary not found');
|
|
137
|
-
}
|
|
138
|
-
// Find the deposit data for the operator
|
|
139
|
-
const depositData = depositsData.find((d) => String(d.operatorId) === String(operatorId));
|
|
140
|
-
if (!depositData) {
|
|
141
|
-
return {
|
|
142
|
-
knownValue: BigInt(0),
|
|
143
|
-
pendingDeposits: [],
|
|
144
|
-
pendingWithdrawals: [],
|
|
145
|
-
storageFeeDeposit: BigInt(0),
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
const { currentEpochIndex } = stakingSummary;
|
|
149
|
-
// Process pending deposits
|
|
150
|
-
const { additionalShares, pendingStorageFee, pendingDeposits } = yield processPendingDeposits(api, operatorId, depositData, currentEpochIndex);
|
|
151
|
-
// Calculate final totals
|
|
152
|
-
const totalShares = depositData.known.shares + additionalShares;
|
|
153
|
-
// Calculate total storage fee deposit: known + pending (handled by processPendingDeposits)
|
|
154
|
-
const totalStorageFeeDeposit = depositData.known.storageFeeDeposit + pendingStorageFee;
|
|
155
|
-
// Calculate current position value
|
|
156
|
-
const currentSharePrice = yield (0, price_1.instantSharePrice)(api, operatorId);
|
|
157
|
-
const knownValue = (0, utils_1.shareToStake)(totalShares, currentSharePrice);
|
|
158
|
-
// Process pending withdrawals
|
|
159
|
-
const pendingWithdrawals = yield processPendingWithdrawals(api, operatorId, withdrawalsData, currentEpochIndex);
|
|
160
|
-
return {
|
|
161
|
-
knownValue,
|
|
162
|
-
pendingDeposits,
|
|
163
|
-
pendingWithdrawals,
|
|
164
|
-
storageFeeDeposit: totalStorageFeeDeposit,
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
catch (error) {
|
|
168
|
-
console.error('Error calculating nominator position:', error);
|
|
169
|
-
throw new Error(`Error calculating position for nominator ${nominatorAccountId} in operator ${operatorId}: ${error}`);
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
exports.nominatorPosition = nominatorPosition;
|
|
17
|
+
__exportStar(require("./position"), exports);
|
|
18
|
+
__exportStar(require("./price"), exports);
|
|
19
|
+
__exportStar(require("./utils"), exports);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Api } from '@autonomys/auto-utils';
|
|
2
|
+
import type { NominatorPosition } from '../types/position';
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves the complete staking position of a nominator for a specific operator.
|
|
5
|
+
*
|
|
6
|
+
* This function uses the runtime API to get the comprehensive staking position of a nominator
|
|
7
|
+
* including current value, pending deposits, pending withdrawals, and storage fee deposits.
|
|
8
|
+
* The runtime API handles all complex calculations involving share prices across different
|
|
9
|
+
* epochs and provides a complete view of the nominator's stake position.
|
|
10
|
+
*
|
|
11
|
+
* @param api - The connected API instance
|
|
12
|
+
* @param operatorId - The ID of the operator to query position for
|
|
13
|
+
* @param nominatorAccountId - The account ID of the nominator
|
|
14
|
+
* @returns Promise that resolves to NominatorPosition with complete position details
|
|
15
|
+
* @throws Error if the runtime API call fails or position cannot be determined
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* import { nominatorPosition } from '@autonomys/auto-consensus'
|
|
20
|
+
* import { activate } from '@autonomys/auto-utils'
|
|
21
|
+
*
|
|
22
|
+
* const api = await activate({ networkId: 'taurus' })
|
|
23
|
+
* const position = await nominatorPosition(api, '1', 'nominator_account_address')
|
|
24
|
+
*
|
|
25
|
+
* console.log(`Current Staked Value: ${position.currentStakedValue}`)
|
|
26
|
+
* console.log(`Total Shares: ${position.totalShares}`)
|
|
27
|
+
* console.log(`Storage Fee Deposit: ${position.storageFeeDeposit.currentValue}`)
|
|
28
|
+
* console.log(`Pending Deposit: ${position.pendingDeposit ? 'Yes' : 'No'}`)
|
|
29
|
+
* console.log(`Pending Withdrawals: ${position.pendingWithdrawals.length}`)
|
|
30
|
+
*
|
|
31
|
+
* // Check pending deposit
|
|
32
|
+
* if (position.pendingDeposit) {
|
|
33
|
+
* console.log(`Pending: ${position.pendingDeposit.amount} at epoch ${position.pendingDeposit.effectiveEpoch}`)
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* // Check pending withdrawals
|
|
37
|
+
* position.pendingWithdrawals.forEach(withdrawal => {
|
|
38
|
+
* console.log(`Withdrawal: ${withdrawal.stakeWithdrawalAmount} unlocks at block ${withdrawal.unlockAtBlock}`)
|
|
39
|
+
* })
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare const nominatorPosition: (api: Api, operatorId: string | number | bigint, nominatorAccountId: string) => Promise<NominatorPosition>;
|
|
43
|
+
//# sourceMappingURL=position.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"position.d.ts","sourceRoot":"","sources":["../../src/position/position.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAA;AAChD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAQ1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,eAAO,MAAM,iBAAiB,GAC5B,KAAK,GAAG,EACR,YAAY,MAAM,GAAG,MAAM,GAAG,MAAM,EACpC,oBAAoB,MAAM,KACzB,OAAO,CAAC,iBAAiB,CAqB3B,CAAA"}
|
|
@@ -0,0 +1,70 @@
|
|
|
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.nominatorPosition = void 0;
|
|
13
|
+
const parse_1 = require("../utils/parse");
|
|
14
|
+
const runtime_1 = require("./runtime");
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves the complete staking position of a nominator for a specific operator.
|
|
17
|
+
*
|
|
18
|
+
* This function uses the runtime API to get the comprehensive staking position of a nominator
|
|
19
|
+
* including current value, pending deposits, pending withdrawals, and storage fee deposits.
|
|
20
|
+
* The runtime API handles all complex calculations involving share prices across different
|
|
21
|
+
* epochs and provides a complete view of the nominator's stake position.
|
|
22
|
+
*
|
|
23
|
+
* @param api - The connected API instance
|
|
24
|
+
* @param operatorId - The ID of the operator to query position for
|
|
25
|
+
* @param nominatorAccountId - The account ID of the nominator
|
|
26
|
+
* @returns Promise that resolves to NominatorPosition with complete position details
|
|
27
|
+
* @throws Error if the runtime API call fails or position cannot be determined
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { nominatorPosition } from '@autonomys/auto-consensus'
|
|
32
|
+
* import { activate } from '@autonomys/auto-utils'
|
|
33
|
+
*
|
|
34
|
+
* const api = await activate({ networkId: 'taurus' })
|
|
35
|
+
* const position = await nominatorPosition(api, '1', 'nominator_account_address')
|
|
36
|
+
*
|
|
37
|
+
* console.log(`Current Staked Value: ${position.currentStakedValue}`)
|
|
38
|
+
* console.log(`Total Shares: ${position.totalShares}`)
|
|
39
|
+
* console.log(`Storage Fee Deposit: ${position.storageFeeDeposit.currentValue}`)
|
|
40
|
+
* console.log(`Pending Deposit: ${position.pendingDeposit ? 'Yes' : 'No'}`)
|
|
41
|
+
* console.log(`Pending Withdrawals: ${position.pendingWithdrawals.length}`)
|
|
42
|
+
*
|
|
43
|
+
* // Check pending deposit
|
|
44
|
+
* if (position.pendingDeposit) {
|
|
45
|
+
* console.log(`Pending: ${position.pendingDeposit.amount} at epoch ${position.pendingDeposit.effectiveEpoch}`)
|
|
46
|
+
* }
|
|
47
|
+
*
|
|
48
|
+
* // Check pending withdrawals
|
|
49
|
+
* position.pendingWithdrawals.forEach(withdrawal => {
|
|
50
|
+
* console.log(`Withdrawal: ${withdrawal.stakeWithdrawalAmount} unlocks at block ${withdrawal.unlockAtBlock}`)
|
|
51
|
+
* })
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
const nominatorPosition = (api, operatorId, nominatorAccountId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
+
try {
|
|
56
|
+
// Call the runtime API to get the nominator position
|
|
57
|
+
const position = (yield api.call.domainsApi.nominatorPosition((0, parse_1.parseString)(operatorId), nominatorAccountId));
|
|
58
|
+
if (position.isNone) {
|
|
59
|
+
// No position exists for this nominator with this operator
|
|
60
|
+
return (0, runtime_1.createEmptyPosition)();
|
|
61
|
+
}
|
|
62
|
+
const runtimePosition = position.unwrap();
|
|
63
|
+
return (0, runtime_1.convertRuntimePosition)(runtimePosition);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
console.error('Error fetching nominator position:', error);
|
|
67
|
+
throw new Error(`Error fetching position for nominator ${nominatorAccountId} in operator ${operatorId}: ${error}`);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
exports.nominatorPosition = nominatorPosition;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { NominatorPosition } from '../types/position';
|
|
2
|
+
interface RuntimeStorageFeeDeposit {
|
|
3
|
+
totalDeposited: {
|
|
4
|
+
toString(): string;
|
|
5
|
+
};
|
|
6
|
+
currentValue: {
|
|
7
|
+
toString(): string;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
interface RuntimePendingDeposit {
|
|
11
|
+
amount: {
|
|
12
|
+
toString(): string;
|
|
13
|
+
};
|
|
14
|
+
effectiveEpoch: {
|
|
15
|
+
toNumber(): number;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
interface RuntimePendingWithdrawal {
|
|
19
|
+
stakeWithdrawalAmount: {
|
|
20
|
+
toString(): string;
|
|
21
|
+
};
|
|
22
|
+
storageFeeRefund: {
|
|
23
|
+
toString(): string;
|
|
24
|
+
};
|
|
25
|
+
unlockAtBlock: {
|
|
26
|
+
toNumber(): number;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
interface RuntimeNominatorPosition {
|
|
30
|
+
currentStakedValue: {
|
|
31
|
+
toString(): string;
|
|
32
|
+
};
|
|
33
|
+
totalShares: {
|
|
34
|
+
toString(): string;
|
|
35
|
+
};
|
|
36
|
+
storageFeeDeposit: RuntimeStorageFeeDeposit;
|
|
37
|
+
pendingDeposit: {
|
|
38
|
+
isSome: boolean;
|
|
39
|
+
isNone: boolean;
|
|
40
|
+
unwrap(): RuntimePendingDeposit;
|
|
41
|
+
};
|
|
42
|
+
pendingWithdrawals: RuntimePendingWithdrawal[];
|
|
43
|
+
}
|
|
44
|
+
export interface RuntimeNominatorPositionResponse {
|
|
45
|
+
isNone: boolean;
|
|
46
|
+
isSome: boolean;
|
|
47
|
+
unwrap(): RuntimeNominatorPosition;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Converts runtime nominator position data to TypeScript NominatorPosition type.
|
|
51
|
+
*
|
|
52
|
+
* This function handles the conversion from the runtime API response format
|
|
53
|
+
* to the clean TypeScript types used by the SDK, including BigInt conversions
|
|
54
|
+
* and Option unwrapping.
|
|
55
|
+
*
|
|
56
|
+
* @param runtimePosition - The runtime nominator position data
|
|
57
|
+
* @returns Converted NominatorPosition object
|
|
58
|
+
*/
|
|
59
|
+
export declare const convertRuntimePosition: (runtimePosition: RuntimeNominatorPosition) => NominatorPosition;
|
|
60
|
+
/**
|
|
61
|
+
* Creates an empty NominatorPosition for when no position exists.
|
|
62
|
+
*
|
|
63
|
+
* @returns Empty NominatorPosition with zero values
|
|
64
|
+
*/
|
|
65
|
+
export declare const createEmptyPosition: () => NominatorPosition;
|
|
66
|
+
export {};
|
|
67
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/position/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAG1D,UAAU,wBAAwB;IAChC,cAAc,EAAE;QAAE,QAAQ,IAAI,MAAM,CAAA;KAAE,CAAA;IACtC,YAAY,EAAE;QAAE,QAAQ,IAAI,MAAM,CAAA;KAAE,CAAA;CACrC;AAED,UAAU,qBAAqB;IAC7B,MAAM,EAAE;QAAE,QAAQ,IAAI,MAAM,CAAA;KAAE,CAAA;IAC9B,cAAc,EAAE;QAAE,QAAQ,IAAI,MAAM,CAAA;KAAE,CAAA;CACvC;AAED,UAAU,wBAAwB;IAChC,qBAAqB,EAAE;QAAE,QAAQ,IAAI,MAAM,CAAA;KAAE,CAAA;IAC7C,gBAAgB,EAAE;QAAE,QAAQ,IAAI,MAAM,CAAA;KAAE,CAAA;IACxC,aAAa,EAAE;QAAE,QAAQ,IAAI,MAAM,CAAA;KAAE,CAAA;CACtC;AAED,UAAU,wBAAwB;IAChC,kBAAkB,EAAE;QAAE,QAAQ,IAAI,MAAM,CAAA;KAAE,CAAA;IAC1C,WAAW,EAAE;QAAE,QAAQ,IAAI,MAAM,CAAA;KAAE,CAAA;IACnC,iBAAiB,EAAE,wBAAwB,CAAA;IAC3C,cAAc,EAAE;QACd,MAAM,EAAE,OAAO,CAAA;QACf,MAAM,EAAE,OAAO,CAAA;QACf,MAAM,IAAI,qBAAqB,CAAA;KAChC,CAAA;IACD,kBAAkB,EAAE,wBAAwB,EAAE,CAAA;CAC/C;AAGD,MAAM,WAAW,gCAAgC;IAC/C,MAAM,EAAE,OAAO,CAAA;IACf,MAAM,EAAE,OAAO,CAAA;IACf,MAAM,IAAI,wBAAwB,CAAA;CACnC;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,GACjC,iBAAiB,wBAAwB,KACxC,iBAoBF,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,QAAO,iBAWtC,CAAA"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createEmptyPosition = exports.convertRuntimePosition = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Converts runtime nominator position data to TypeScript NominatorPosition type.
|
|
6
|
+
*
|
|
7
|
+
* This function handles the conversion from the runtime API response format
|
|
8
|
+
* to the clean TypeScript types used by the SDK, including BigInt conversions
|
|
9
|
+
* and Option unwrapping.
|
|
10
|
+
*
|
|
11
|
+
* @param runtimePosition - The runtime nominator position data
|
|
12
|
+
* @returns Converted NominatorPosition object
|
|
13
|
+
*/
|
|
14
|
+
const convertRuntimePosition = (runtimePosition) => {
|
|
15
|
+
return {
|
|
16
|
+
currentStakedValue: BigInt(runtimePosition.currentStakedValue.toString()),
|
|
17
|
+
totalShares: BigInt(runtimePosition.totalShares.toString()),
|
|
18
|
+
storageFeeDeposit: {
|
|
19
|
+
totalDeposited: BigInt(runtimePosition.storageFeeDeposit.totalDeposited.toString()),
|
|
20
|
+
currentValue: BigInt(runtimePosition.storageFeeDeposit.currentValue.toString()),
|
|
21
|
+
},
|
|
22
|
+
pendingDeposit: runtimePosition.pendingDeposit.isSome
|
|
23
|
+
? {
|
|
24
|
+
amount: BigInt(runtimePosition.pendingDeposit.unwrap().amount.toString()),
|
|
25
|
+
effectiveEpoch: runtimePosition.pendingDeposit.unwrap().effectiveEpoch.toNumber(),
|
|
26
|
+
}
|
|
27
|
+
: null,
|
|
28
|
+
pendingWithdrawals: runtimePosition.pendingWithdrawals.map((withdrawal) => ({
|
|
29
|
+
stakeWithdrawalAmount: BigInt(withdrawal.stakeWithdrawalAmount.toString()),
|
|
30
|
+
storageFeeRefund: BigInt(withdrawal.storageFeeRefund.toString()),
|
|
31
|
+
unlockAtBlock: withdrawal.unlockAtBlock.toNumber(),
|
|
32
|
+
})),
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
exports.convertRuntimePosition = convertRuntimePosition;
|
|
36
|
+
/**
|
|
37
|
+
* Creates an empty NominatorPosition for when no position exists.
|
|
38
|
+
*
|
|
39
|
+
* @returns Empty NominatorPosition with zero values
|
|
40
|
+
*/
|
|
41
|
+
const createEmptyPosition = () => {
|
|
42
|
+
return {
|
|
43
|
+
currentStakedValue: BigInt(0),
|
|
44
|
+
totalShares: BigInt(0),
|
|
45
|
+
storageFeeDeposit: {
|
|
46
|
+
totalDeposited: BigInt(0),
|
|
47
|
+
currentValue: BigInt(0),
|
|
48
|
+
},
|
|
49
|
+
pendingDeposit: null,
|
|
50
|
+
pendingWithdrawals: [],
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
exports.createEmptyPosition = createEmptyPosition;
|
package/dist/types/position.d.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
export type NominatorPosition = {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
currentStakedValue: bigint;
|
|
3
|
+
totalShares: bigint;
|
|
4
|
+
storageFeeDeposit: {
|
|
5
|
+
totalDeposited: bigint;
|
|
6
|
+
currentValue: bigint;
|
|
7
|
+
};
|
|
8
|
+
pendingDeposit: {
|
|
4
9
|
amount: bigint;
|
|
5
10
|
effectiveEpoch: number;
|
|
6
|
-
}
|
|
11
|
+
} | null;
|
|
7
12
|
pendingWithdrawals: {
|
|
8
13
|
stakeWithdrawalAmount: bigint;
|
|
9
|
-
unlockAtDomainBlock: number;
|
|
10
14
|
storageFeeRefund: bigint;
|
|
15
|
+
unlockAtBlock: number;
|
|
11
16
|
}[];
|
|
12
|
-
storageFeeDeposit: bigint;
|
|
13
17
|
};
|
|
14
18
|
//# sourceMappingURL=position.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"position.d.ts","sourceRoot":"","sources":["../../src/types/position.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG;IAC9B,
|
|
1
|
+
{"version":3,"file":"position.d.ts","sourceRoot":"","sources":["../../src/types/position.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG;IAC9B,kBAAkB,EAAE,MAAM,CAAA;IAC1B,WAAW,EAAE,MAAM,CAAA;IACnB,iBAAiB,EAAE;QACjB,cAAc,EAAE,MAAM,CAAA;QACtB,YAAY,EAAE,MAAM,CAAA;KACrB,CAAA;IACD,cAAc,EAAE;QACd,MAAM,EAAE,MAAM,CAAA;QACd,cAAc,EAAE,MAAM,CAAA;KACvB,GAAG,IAAI,CAAA;IACR,kBAAkB,EAAE;QAClB,qBAAqB,EAAE,MAAM,CAAA;QAC7B,gBAAgB,EAAE,MAAM,CAAA;QACxB,aAAa,EAAE,MAAM,CAAA;KACtB,EAAE,CAAA;CACJ,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@autonomys/auto-consensus",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.9",
|
|
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.9"
|
|
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": "915c6210b4a05b74570d76f497e839867c6c821b"
|
|
39
39
|
}
|
package/dist/position.d.ts
DELETED
package/dist/position.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"position.d.ts","sourceRoot":"","sources":["../src/position.ts"],"names":[],"mappings":"AAEA,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA"}
|
package/dist/position.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// file: src/position.ts
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
-
};
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
__exportStar(require("./position/index"), exports);
|
|
19
|
-
__exportStar(require("./position/price"), exports);
|
|
20
|
-
__exportStar(require("./position/utils"), exports);
|