@autonomys/auto-consensus 1.5.7 → 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/price.d.ts +5 -5
- package/dist/position/price.d.ts.map +1 -1
- package/dist/position/price.js +14 -22
- 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/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/parse.d.ts.map +1 -1
- package/dist/utils/parse.js +0 -1
- package/dist/utils/storage.d.ts +17 -0
- package/dist/utils/storage.d.ts.map +1 -0
- package/dist/utils/storage.js +69 -0
- 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;
|
package/dist/position/price.d.ts
CHANGED
|
@@ -5,13 +5,13 @@ import type { Api } from '@autonomys/auto-utils';
|
|
|
5
5
|
* This function fetches the historical share price that was recorded for an operator
|
|
6
6
|
* at a specific domain epoch. Share prices are stored when staking activity occurs
|
|
7
7
|
* and are used to convert between stake amounts and shares at different points in time.
|
|
8
|
-
* The price is returned in 18-decimal
|
|
8
|
+
* The price is returned in 18-decimal Perquintill format.
|
|
9
9
|
*
|
|
10
10
|
* @param api - The connected API instance
|
|
11
11
|
* @param operatorId - The ID of the operator to query price for
|
|
12
12
|
* @param domainEpoch - The domain epoch index to query price for
|
|
13
13
|
* @param domainId - The domain ID (default: 0)
|
|
14
|
-
* @returns Promise that resolves to share price in 18-decimal
|
|
14
|
+
* @returns Promise that resolves to share price in 18-decimal Perquintill format, or undefined if no price stored
|
|
15
15
|
* @throws Error if the query fails or operator/epoch not found
|
|
16
16
|
*
|
|
17
17
|
* @example
|
|
@@ -19,7 +19,7 @@ import type { Api } from '@autonomys/auto-utils';
|
|
|
19
19
|
* import { operatorEpochSharePrice } from '@autonomys/auto-consensus'
|
|
20
20
|
* import { activate } from '@autonomys/auto-utils'
|
|
21
21
|
*
|
|
22
|
-
* const api = await activate({ networkId: '
|
|
22
|
+
* const api = await activate({ networkId: 'taurus' })
|
|
23
23
|
*
|
|
24
24
|
* // Get share price for operator 1 at epoch 100
|
|
25
25
|
* const sharePrice = await operatorEpochSharePrice(api, '1', 100, 0)
|
|
@@ -45,7 +45,7 @@ export declare const operatorEpochSharePrice: (api: Api, operatorId: string | nu
|
|
|
45
45
|
*
|
|
46
46
|
* @param api - The connected API instance
|
|
47
47
|
* @param operatorId - The ID of the operator to calculate price for
|
|
48
|
-
* @returns Promise that resolves to current share price in 18-decimal
|
|
48
|
+
* @returns Promise that resolves to current share price in 18-decimal Perquintill format
|
|
49
49
|
* @throws Error if operator not found, domain staking summary unavailable, or calculation fails
|
|
50
50
|
*
|
|
51
51
|
* @example
|
|
@@ -53,7 +53,7 @@ export declare const operatorEpochSharePrice: (api: Api, operatorId: string | nu
|
|
|
53
53
|
* import { instantSharePrice } from '@autonomys/auto-consensus'
|
|
54
54
|
* import { activate } from '@autonomys/auto-utils'
|
|
55
55
|
*
|
|
56
|
-
* const api = await activate({ networkId: '
|
|
56
|
+
* const api = await activate({ networkId: 'taurus' })
|
|
57
57
|
*
|
|
58
58
|
* // Get current share price for operator 1
|
|
59
59
|
* const currentPrice = await instantSharePrice(api, '1')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"price.d.ts","sourceRoot":"","sources":["../../src/position/price.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"price.d.ts","sourceRoot":"","sources":["../../src/position/price.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAA;AAMhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,eAAO,MAAM,uBAAuB,GAClC,KAAK,GAAG,EACR,YAAY,MAAM,GAAG,MAAM,GAAG,MAAM,EACpC,aAAa,MAAM,GAAG,MAAM,GAAG,MAAM,EACrC,WAAU,MAAM,GAAG,MAAM,GAAG,MAAU,KACrC,OAAO,CAAC,MAAM,GAAG,SAAS,CA2B5B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,iBAAiB,GAC5B,KAAK,GAAG,EACR,YAAY,MAAM,GAAG,MAAM,GAAG,MAAM,KACnC,OAAO,CAAC,MAAM,CAiChB,CAAA"}
|
package/dist/position/price.js
CHANGED
|
@@ -13,19 +13,20 @@ exports.instantSharePrice = exports.operatorEpochSharePrice = void 0;
|
|
|
13
13
|
const domain_1 = require("../domain");
|
|
14
14
|
const staking_1 = require("../staking");
|
|
15
15
|
const parse_1 = require("../utils/parse");
|
|
16
|
+
const storage_1 = require("../utils/storage");
|
|
16
17
|
/**
|
|
17
18
|
* Retrieves the stored share price for a specific operator at a given domain epoch.
|
|
18
19
|
*
|
|
19
20
|
* This function fetches the historical share price that was recorded for an operator
|
|
20
21
|
* at a specific domain epoch. Share prices are stored when staking activity occurs
|
|
21
22
|
* and are used to convert between stake amounts and shares at different points in time.
|
|
22
|
-
* The price is returned in 18-decimal
|
|
23
|
+
* The price is returned in 18-decimal Perquintill format.
|
|
23
24
|
*
|
|
24
25
|
* @param api - The connected API instance
|
|
25
26
|
* @param operatorId - The ID of the operator to query price for
|
|
26
27
|
* @param domainEpoch - The domain epoch index to query price for
|
|
27
28
|
* @param domainId - The domain ID (default: 0)
|
|
28
|
-
* @returns Promise that resolves to share price in 18-decimal
|
|
29
|
+
* @returns Promise that resolves to share price in 18-decimal Perquintill format, or undefined if no price stored
|
|
29
30
|
* @throws Error if the query fails or operator/epoch not found
|
|
30
31
|
*
|
|
31
32
|
* @example
|
|
@@ -33,7 +34,7 @@ const parse_1 = require("../utils/parse");
|
|
|
33
34
|
* import { operatorEpochSharePrice } from '@autonomys/auto-consensus'
|
|
34
35
|
* import { activate } from '@autonomys/auto-utils'
|
|
35
36
|
*
|
|
36
|
-
* const api = await activate({ networkId: '
|
|
37
|
+
* const api = await activate({ networkId: 'taurus' })
|
|
37
38
|
*
|
|
38
39
|
* // Get share price for operator 1 at epoch 100
|
|
39
40
|
* const sharePrice = await operatorEpochSharePrice(api, '1', 100, 0)
|
|
@@ -48,25 +49,16 @@ const parse_1 = require("../utils/parse");
|
|
|
48
49
|
*/
|
|
49
50
|
const operatorEpochSharePrice = (api_1, operatorId_1, domainEpoch_1, ...args_1) => __awaiter(void 0, [api_1, operatorId_1, domainEpoch_1, ...args_1], void 0, function* (api, operatorId, domainEpoch, domainId = 0) {
|
|
50
51
|
try {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const sharePrice = yield api.query.domains.operatorEpochSharePrice((0, parse_1.parseString)(operatorId), domainEpochTuple);
|
|
54
|
-
if (sharePrice.isEmpty) {
|
|
52
|
+
const sharePrice = yield (0, storage_1.getOperatorEpochSharePrice)(api, (0, parse_1.parseString)(operatorId), domainId, domainEpoch);
|
|
53
|
+
if (sharePrice === undefined) {
|
|
55
54
|
return undefined;
|
|
56
55
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (priceValue === null || priceValue === undefined) {
|
|
56
|
+
const perquintillValue = sharePrice;
|
|
57
|
+
if (perquintillValue === BigInt(0)) {
|
|
60
58
|
return undefined;
|
|
61
59
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const perbillValue = BigInt(priceValue.toString());
|
|
65
|
-
const scaledPrice = perbillValue * BigInt(Math.pow(10, 9)); // Scale from 9 to 18 decimals
|
|
66
|
-
// Invert the share price: if API returns 0.5601 (shares worth 56% of original),
|
|
67
|
-
// we need 1/0.5601 ≈ 1.785 for stakeToShare conversion
|
|
68
|
-
const oneInPerbill = BigInt(Math.pow(10, 18));
|
|
69
|
-
return (oneInPerbill * oneInPerbill) / scaledPrice;
|
|
60
|
+
const one = BigInt('1000000000000000000');
|
|
61
|
+
return (one * one) / perquintillValue;
|
|
70
62
|
}
|
|
71
63
|
catch (error) {
|
|
72
64
|
console.error('Error fetching operator epoch share price:', error);
|
|
@@ -86,7 +78,7 @@ exports.operatorEpochSharePrice = operatorEpochSharePrice;
|
|
|
86
78
|
*
|
|
87
79
|
* @param api - The connected API instance
|
|
88
80
|
* @param operatorId - The ID of the operator to calculate price for
|
|
89
|
-
* @returns Promise that resolves to current share price in 18-decimal
|
|
81
|
+
* @returns Promise that resolves to current share price in 18-decimal Perquintill format
|
|
90
82
|
* @throws Error if operator not found, domain staking summary unavailable, or calculation fails
|
|
91
83
|
*
|
|
92
84
|
* @example
|
|
@@ -94,7 +86,7 @@ exports.operatorEpochSharePrice = operatorEpochSharePrice;
|
|
|
94
86
|
* import { instantSharePrice } from '@autonomys/auto-consensus'
|
|
95
87
|
* import { activate } from '@autonomys/auto-utils'
|
|
96
88
|
*
|
|
97
|
-
* const api = await activate({ networkId: '
|
|
89
|
+
* const api = await activate({ networkId: 'taurus' })
|
|
98
90
|
*
|
|
99
91
|
* // Get current share price for operator 1
|
|
100
92
|
* const currentPrice = await instantSharePrice(api, '1')
|
|
@@ -124,9 +116,9 @@ const instantSharePrice = (api, operatorId) => __awaiter(void 0, void 0, void 0,
|
|
|
124
116
|
const effectiveStake = currentTotalStake + rewardAfterTax;
|
|
125
117
|
// Avoid division by zero
|
|
126
118
|
if (currentTotalShares === BigInt(0)) {
|
|
127
|
-
return BigInt(Math.pow(10, 18)); // Return 1.0 in
|
|
119
|
+
return BigInt(Math.pow(10, 18)); // Return 1.0 in Perquintill format
|
|
128
120
|
}
|
|
129
|
-
// Return price in 18-decimal
|
|
121
|
+
// Return price in 18-decimal Perquintill format
|
|
130
122
|
return (effectiveStake * BigInt(Math.pow(10, 18))) / currentTotalShares;
|
|
131
123
|
}
|
|
132
124
|
catch (error) {
|
|
@@ -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/dist/utils/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAEA,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA;AACvB,cAAc,QAAQ,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAEA,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA;AACvB,cAAc,WAAW,CAAA;AACzB,cAAc,QAAQ,CAAA"}
|
package/dist/utils/index.js
CHANGED
|
@@ -19,4 +19,5 @@ __exportStar(require("./events"), exports);
|
|
|
19
19
|
__exportStar(require("./format"), exports);
|
|
20
20
|
__exportStar(require("./parse"), exports);
|
|
21
21
|
__exportStar(require("./query"), exports);
|
|
22
|
+
__exportStar(require("./storage"), exports);
|
|
22
23
|
__exportStar(require("./sudo"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/utils/parse.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AACzF,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EACL,OAAO,EACP,QAAQ,EACR,eAAe,EAKf,aAAa,EAEb,oBAAoB,EACpB,UAAU,EACV,kBAAkB,EACnB,MAAM,kBAAkB,CAAA;AAEzB,eAAO,MAAM,OAAO,GAAI,OAAO,EAAE,KAAG,MAAkC,CAAA;AAEtE,eAAO,MAAM,YAAY,GAAI,MAAM,cAAc,KAAG,WAYnD,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,WAAW,KAAK,KAAG,SAuBjD,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAI,OAAO,WAAW,KAAG,SAAS,EAGlE,CAAA;AAED,eAAO,MAAM,mBAAmB,GAAI,OAAO,WAAW,KAAG,SAAS,EAWjE,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,KAAG,cAMnE,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAI,iBAAiB,KAAK,KAAG,eAe7D,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,KAAG,QAKvE,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,SAAS,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,KAAG,OAuBrE,CAAA;AAED,eAAO,MAAM,uBAAuB,GAClC,oBAAoB,WAAW,CAAC,aAAa,CAAC,oBAAoB,CAAC,CAAC,KACnE,kBAKD,CAAA;AAEF,eAAO,MAAM,eAAe,GAAI,YAAY,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,KAAG,
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/utils/parse.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AACzF,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EACL,OAAO,EACP,QAAQ,EACR,eAAe,EAKf,aAAa,EAEb,oBAAoB,EACpB,UAAU,EACV,kBAAkB,EACnB,MAAM,kBAAkB,CAAA;AAEzB,eAAO,MAAM,OAAO,GAAI,OAAO,EAAE,KAAG,MAAkC,CAAA;AAEtE,eAAO,MAAM,YAAY,GAAI,MAAM,cAAc,KAAG,WAYnD,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,WAAW,KAAK,KAAG,SAuBjD,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAI,OAAO,WAAW,KAAG,SAAS,EAGlE,CAAA;AAED,eAAO,MAAM,mBAAmB,GAAI,OAAO,WAAW,KAAG,SAAS,EAWjE,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,KAAG,cAMnE,CAAA;AAED,eAAO,MAAM,oBAAoB,GAAI,iBAAiB,KAAK,KAAG,eAe7D,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,KAAG,QAKvE,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,SAAS,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,KAAG,OAuBrE,CAAA;AAED,eAAO,MAAM,uBAAuB,GAClC,oBAAoB,WAAW,CAAC,aAAa,CAAC,oBAAoB,CAAC,CAAC,KACnE,kBAKD,CAAA;AAEF,eAAO,MAAM,eAAe,GAAI,YAAY,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,KAAG,UAsB3E,CAAA;AAED,eAAO,MAAM,WAAW,GAAI,YAAY,oBAAoB,KAAG,MACM,CAAA"}
|
package/dist/utils/parse.js
CHANGED
|
@@ -122,7 +122,6 @@ const parseWithdrawal = (withdrawal) => {
|
|
|
122
122
|
Array.isArray(parsedWithdrawal.withdrawals) &&
|
|
123
123
|
parsedWithdrawal.withdrawals.length > 0
|
|
124
124
|
? parsedWithdrawal.withdrawals.map((w) => ({
|
|
125
|
-
domainId: w.domainId,
|
|
126
125
|
unlockAtConfirmedDomainBlockNumber: w.unlockAtConfirmedDomainBlockNumber,
|
|
127
126
|
amountToUnlock: BigInt(w.amountToUnlock),
|
|
128
127
|
storageFeeRefund: BigInt(w.storageFeeRefund),
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Api } from '@autonomys/auto-utils';
|
|
2
|
+
/**
|
|
3
|
+
* Reads operator epoch share price from storage, handling both Perbill and Perquintill formats.
|
|
4
|
+
*
|
|
5
|
+
* This function uses raw storage queries to bypass type decoding issues when the runtime
|
|
6
|
+
* has been upgraded but historical data remains in the old format.
|
|
7
|
+
*
|
|
8
|
+
* NOTE: Supporting Perbill is only necessary to support Taurus. Once Taurus is deprecated, this wrapper around raw storage can be removed and the standard query can be used.
|
|
9
|
+
*
|
|
10
|
+
* @param api - The API instance
|
|
11
|
+
* @param operatorId - The operator ID
|
|
12
|
+
* @param domainId - The domain ID
|
|
13
|
+
* @param domainEpoch - The domain epoch
|
|
14
|
+
* @returns The share price in Perquintill format (18 decimals) or undefined
|
|
15
|
+
*/
|
|
16
|
+
export declare const getOperatorEpochSharePrice: (api: Api, operatorId: string | number | bigint, domainId: string | number | bigint, domainEpoch: string | number | bigint) => Promise<bigint | undefined>;
|
|
17
|
+
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/utils/storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAA;AAKhD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,0BAA0B,GACrC,KAAK,GAAG,EACR,YAAY,MAAM,GAAG,MAAM,GAAG,MAAM,EACpC,UAAU,MAAM,GAAG,MAAM,GAAG,MAAM,EAClC,aAAa,MAAM,GAAG,MAAM,GAAG,MAAM,KACpC,OAAO,CAAC,MAAM,GAAG,SAAS,CAiD5B,CAAA"}
|
|
@@ -0,0 +1,69 @@
|
|
|
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.getOperatorEpochSharePrice = void 0;
|
|
13
|
+
const util_1 = require("@polkadot/util");
|
|
14
|
+
/**
|
|
15
|
+
* Reads operator epoch share price from storage, handling both Perbill and Perquintill formats.
|
|
16
|
+
*
|
|
17
|
+
* This function uses raw storage queries to bypass type decoding issues when the runtime
|
|
18
|
+
* has been upgraded but historical data remains in the old format.
|
|
19
|
+
*
|
|
20
|
+
* NOTE: Supporting Perbill is only necessary to support Taurus. Once Taurus is deprecated, this wrapper around raw storage can be removed and the standard query can be used.
|
|
21
|
+
*
|
|
22
|
+
* @param api - The API instance
|
|
23
|
+
* @param operatorId - The operator ID
|
|
24
|
+
* @param domainId - The domain ID
|
|
25
|
+
* @param domainEpoch - The domain epoch
|
|
26
|
+
* @returns The share price in Perquintill format (18 decimals) or undefined
|
|
27
|
+
*/
|
|
28
|
+
const getOperatorEpochSharePrice = (api, operatorId, domainId, domainEpoch) => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
+
try {
|
|
30
|
+
// Get storage key
|
|
31
|
+
const storageKey = api.query.domains.operatorEpochSharePrice.key(operatorId, [
|
|
32
|
+
domainId,
|
|
33
|
+
domainEpoch,
|
|
34
|
+
]);
|
|
35
|
+
// Get raw storage value
|
|
36
|
+
const rawResult = yield api.rpc.state.getStorage(storageKey);
|
|
37
|
+
// Type assertion for Option<Raw>
|
|
38
|
+
const rawOption = rawResult;
|
|
39
|
+
if (!rawOption || rawOption.isNone) {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
// Convert to bytes
|
|
43
|
+
const rawBytes = rawOption.unwrap().toU8a();
|
|
44
|
+
if (rawBytes.length === 0) {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
// Parse as little-endian bigint
|
|
48
|
+
const value = (0, util_1.u8aToBigInt)(rawBytes, { isLe: true });
|
|
49
|
+
// Handle both formats based on byte length
|
|
50
|
+
if (rawBytes.length === 4) {
|
|
51
|
+
// Old Perbill format (4 bytes, parts per billion)
|
|
52
|
+
// Scale from 9 to 18 decimals: multiply by 10^9
|
|
53
|
+
return value * BigInt(1000000000);
|
|
54
|
+
}
|
|
55
|
+
else if (rawBytes.length === 8) {
|
|
56
|
+
// New Perquintill format (8 bytes, parts per quintillion)
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
console.warn(`Unexpected share price storage length: ${rawBytes.length} bytes for operator ${operatorId}, domain ${domainId}, epoch ${domainEpoch}`);
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.error(`Error reading operator epoch share price from storage for operator ${operatorId}, domain ${domainId}, epoch ${domainEpoch}:`, error);
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
exports.getOperatorEpochSharePrice = getOperatorEpochSharePrice;
|
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);
|