@autonomys/auto-consensus 1.5.7 → 1.5.8
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/price.d.ts +5 -5
- package/dist/position/price.d.ts.map +1 -1
- package/dist/position/price.js +14 -22
- 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/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) {
|
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.8",
|
|
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.8"
|
|
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": "d0127cf5c278bcfc4d5ebec32e86a60b5c3d7851"
|
|
39
39
|
}
|