@autonomys/auto-consensus 1.5.2 → 1.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/dist/account.d.ts +26 -0
  2. package/dist/account.d.ts.map +1 -1
  3. package/dist/account.js +26 -0
  4. package/dist/balances.d.ts +50 -0
  5. package/dist/balances.d.ts.map +1 -1
  6. package/dist/balances.js +50 -0
  7. package/dist/batch.d.ts +29 -0
  8. package/dist/batch.d.ts.map +1 -1
  9. package/dist/batch.js +29 -0
  10. package/dist/domain.d.ts +56 -0
  11. package/dist/domain.d.ts.map +1 -1
  12. package/dist/domain.js +91 -0
  13. package/dist/info.d.ts +406 -0
  14. package/dist/info.d.ts.map +1 -1
  15. package/dist/info.js +406 -0
  16. package/dist/position/index.d.ts +36 -1
  17. package/dist/position/index.d.ts.map +1 -1
  18. package/dist/position/index.js +117 -70
  19. package/dist/position/price.d.ts +60 -3
  20. package/dist/position/price.d.ts.map +1 -1
  21. package/dist/position/price.js +60 -3
  22. package/dist/position/utils.d.ts +53 -2
  23. package/dist/position/utils.d.ts.map +1 -1
  24. package/dist/position/utils.js +53 -2
  25. package/dist/remark.d.ts +29 -0
  26. package/dist/remark.d.ts.map +1 -1
  27. package/dist/remark.js +29 -0
  28. package/dist/staking.d.ts +305 -0
  29. package/dist/staking.d.ts.map +1 -1
  30. package/dist/staking.js +305 -0
  31. package/dist/transfer.d.ts +59 -0
  32. package/dist/transfer.d.ts.map +1 -1
  33. package/dist/transfer.js +59 -0
  34. package/dist/types/position.d.ts +1 -1
  35. package/dist/types/position.d.ts.map +1 -1
  36. package/dist/utils/format.d.ts +86 -0
  37. package/dist/utils/format.d.ts.map +1 -1
  38. package/dist/utils/format.js +86 -0
  39. package/dist/utils/query.d.ts +31 -0
  40. package/dist/utils/query.d.ts.map +1 -1
  41. package/dist/utils/query.js +31 -0
  42. package/dist/utils/sudo.d.ts +36 -0
  43. package/dist/utils/sudo.d.ts.map +1 -1
  44. package/dist/utils/sudo.js +36 -0
  45. package/package.json +3 -3
@@ -15,11 +15,114 @@ const staking_1 = require("../staking");
15
15
  const price_1 = require("./price");
16
16
  const utils_1 = require("./utils");
17
17
  /**
18
- * High-level helper that returns the staking/storage position of a nominator inside an operator pool
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
+ amount: w.amountToUnlock,
68
+ unlockAtDomainBlock: w.unlockAtConfirmedDomainBlockNumber,
69
+ });
70
+ }
71
+ const sharePrice =
72
+ // If withdrawal epoch has passed, use its share price, otherwise use instant share price
73
+ domainEpoch[1] < currentEpochIndex
74
+ ? yield (0, price_1.operatorEpochSharePrice)(api, operatorId, domainEpoch[1], // epoch index
75
+ domainEpoch[0])
76
+ : yield (0, price_1.instantSharePrice)(api, operatorId);
77
+ const withdrawalAmount = sharePrice ? (0, utils_1.shareToStake)(shares, sharePrice) : BigInt(0); // fallback to 0 if no price available
78
+ pendingWithdrawals.push({
79
+ amount: withdrawalAmount,
80
+ unlockAtDomainBlock: unlockAtConfirmedDomainBlockNumber,
81
+ });
82
+ }
83
+ return pendingWithdrawals;
84
+ });
85
+ /**
86
+ * Retrieves the complete staking position of a nominator for a specific operator.
87
+ *
88
+ * This function calculates the comprehensive staking position of a nominator including
89
+ * current value, pending deposits, pending withdrawals, and storage fee deposits.
90
+ * It handles complex calculations involving share prices across different epochs
91
+ * and provides a complete view of the nominator's stake position.
92
+ *
93
+ * @param api - The connected API instance
94
+ * @param operatorId - The ID of the operator to query position for
95
+ * @param nominatorAccountId - The account ID of the nominator
96
+ * @returns Promise that resolves to NominatorPosition with complete position details
97
+ * @throws Error if operator not found, domain staking summary unavailable, or calculation fails
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * import { nominatorPosition } from '@autonomys/auto-consensus'
102
+ * import { activate } from '@autonomys/auto-utils'
103
+ *
104
+ * const api = await activate({ networkId: 'gemini-3h' })
105
+ * const position = await nominatorPosition(api, '1', 'nominator_account_address')
106
+ *
107
+ * console.log(`Current Value: ${position.knownValue}`)
108
+ * console.log(`Storage Fee Deposit: ${position.storageFeeDeposit}`)
109
+ * console.log(`Pending Deposits: ${position.pendingDeposits.length}`)
110
+ * console.log(`Pending Withdrawals: ${position.pendingWithdrawals.length}`)
111
+ *
112
+ * // Check pending deposits
113
+ * position.pendingDeposits.forEach(deposit => {
114
+ * console.log(`Pending: ${deposit.amount} at epoch ${deposit.effectiveEpoch}`)
115
+ * })
116
+ *
117
+ * // Check pending withdrawals
118
+ * position.pendingWithdrawals.forEach(withdrawal => {
119
+ * console.log(`Withdrawal: ${withdrawal.amount} unlocks at block ${withdrawal.unlockAtBlock}`)
120
+ * })
121
+ * ```
19
122
  */
20
123
  const nominatorPosition = (api, operatorId, nominatorAccountId) => __awaiter(void 0, void 0, void 0, function* () {
21
- var _a, _b;
22
124
  try {
125
+ // TODO: handle when operator is not found
23
126
  const operatorData = yield (0, staking_1.operator)(api, operatorId);
24
127
  // Step 1: Get deposits, withdrawals, and domain staking summary
25
128
  const [depositsData, withdrawalsData, stakingSummary] = yield Promise.all([
@@ -30,7 +133,8 @@ const nominatorPosition = (api, operatorId, nominatorAccountId) => __awaiter(voi
30
133
  if (!stakingSummary) {
31
134
  throw new Error('Domain staking summary not found');
32
135
  }
33
- const depositData = depositsData.length > 0 ? depositsData[0] : null;
136
+ // Find the deposit data for the operator
137
+ const depositData = depositsData.find((d) => String(d.operatorId) === String(operatorId));
34
138
  if (!depositData) {
35
139
  return {
36
140
  knownValue: BigInt(0),
@@ -39,75 +143,18 @@ const nominatorPosition = (api, operatorId, nominatorAccountId) => __awaiter(voi
39
143
  storageFeeDeposit: BigInt(0),
40
144
  };
41
145
  }
42
- const currentEpochIndex = stakingSummary.currentEpochIndex;
43
- let totalShares = depositData.known.shares;
44
- let totalStorageFeeDeposit = depositData.known.storageFeeDeposit + ((_b = (_a = depositData.pending) === null || _a === void 0 ? void 0 : _a.storageFeeDeposit) !== null && _b !== void 0 ? _b : BigInt(0));
45
- const pendingDeposits = [];
46
- if (depositData.pending) {
47
- const { effectiveDomainEpoch, amount, storageFeeDeposit: pendingStorageFee, } = depositData.pending;
48
- if (effectiveDomainEpoch <= currentEpochIndex) {
49
- // Epoch has passed - convert pending amount to shares using epoch share price
50
- try {
51
- const epochSharePrice = yield (0, price_1.operatorEpochSharePrice)(api, operatorId, effectiveDomainEpoch, 0);
52
- if (epochSharePrice !== undefined) {
53
- // Convert pending amount to shares and add to total
54
- const pendingShares = (0, utils_1.stakeToShare)(amount, epochSharePrice);
55
- totalShares += pendingShares;
56
- console.log(`Converted pending deposit: ${amount} tokens at epoch ${effectiveDomainEpoch} (price: ${epochSharePrice}) = ${pendingShares} shares`);
57
- }
58
- else {
59
- // Fallback: if no epoch price available, assume 1:1 conversion
60
- console.warn(`No epoch share price found for epoch ${effectiveDomainEpoch}, using pending amount as shares`);
61
- totalShares += amount;
62
- }
63
- // Add pending storage fee to total
64
- totalStorageFeeDeposit += pendingStorageFee;
65
- }
66
- catch (error) {
67
- console.warn(`Error getting epoch share price for epoch ${effectiveDomainEpoch}, treating as still pending:`, error);
68
- // Keep as pending if we can't get the epoch price
69
- pendingDeposits.push({
70
- amount: amount,
71
- effectiveEpoch: effectiveDomainEpoch,
72
- });
73
- }
74
- }
75
- else {
76
- // Epoch hasn't passed yet - keep as pending
77
- pendingDeposits.push({
78
- amount: amount,
79
- effectiveEpoch: effectiveDomainEpoch,
80
- });
81
- }
82
- }
83
- // Step 3: Calculate current position value using instant share price
146
+ const { currentEpochIndex } = stakingSummary;
147
+ // Process pending deposits
148
+ const { additionalShares, pendingStorageFee, pendingDeposits } = yield processPendingDeposits(api, operatorId, depositData, currentEpochIndex);
149
+ // Calculate final totals
150
+ const totalShares = depositData.known.shares + additionalShares;
151
+ // Calculate total storage fee deposit: known + pending (handled by processPendingDeposits)
152
+ const totalStorageFeeDeposit = depositData.known.storageFeeDeposit + pendingStorageFee;
153
+ // Calculate current position value
84
154
  const currentSharePrice = yield (0, price_1.instantSharePrice)(api, operatorId);
85
155
  const knownValue = (0, utils_1.shareToStake)(totalShares, currentSharePrice);
86
- // Step 4: Process pending withdrawals
87
- const pendingWithdrawals = [];
88
- if (withdrawalsData.length > 0) {
89
- for (const withdrawal of withdrawalsData) {
90
- // Process regular withdrawals
91
- for (const w of withdrawal.withdrawals) {
92
- pendingWithdrawals.push({
93
- amount: w.amountToUnlock,
94
- unlockAtBlock: w.unlockAtConfirmedDomainBlockNumber,
95
- });
96
- }
97
- // Process withdrawal in shares
98
- if (withdrawal.withdrawalInShares) {
99
- const sharePrice = yield (0, price_1.operatorEpochSharePrice)(api, operatorId, withdrawal.withdrawalInShares.domainEpoch[1], // epoch index
100
- withdrawal.withdrawalInShares.domainEpoch[0]);
101
- const withdrawalAmount = sharePrice
102
- ? (0, utils_1.shareToStake)(withdrawal.withdrawalInShares.shares, sharePrice)
103
- : BigInt(0); // fallback to 0 if no price available
104
- pendingWithdrawals.push({
105
- amount: withdrawalAmount,
106
- unlockAtBlock: withdrawal.withdrawalInShares.unlockAtConfirmedDomainBlockNumber,
107
- });
108
- }
109
- }
110
- }
156
+ // Process pending withdrawals
157
+ const pendingWithdrawals = yield processPendingWithdrawals(api, operatorId, withdrawalsData, currentEpochIndex);
111
158
  return {
112
159
  knownValue,
113
160
  pendingDeposits,
@@ -1,12 +1,69 @@
1
1
  import type { Api } from '@autonomys/auto-utils';
2
2
  /**
3
- * Fetch the stored share price (18-dec Perbill) for a given (operatorId, domainEpoch) tuple
4
- * Returns undefined if no price is stored for that epoch (i.e. no staking activity)
3
+ * Retrieves the stored share price for a specific operator at a given domain epoch.
4
+ *
5
+ * This function fetches the historical share price that was recorded for an operator
6
+ * at a specific domain epoch. Share prices are stored when staking activity occurs
7
+ * and are used to convert between stake amounts and shares at different points in time.
8
+ * The price is returned in 18-decimal Perbill format.
9
+ *
10
+ * @param api - The connected API instance
11
+ * @param operatorId - The ID of the operator to query price for
12
+ * @param domainEpoch - The domain epoch index to query price for
13
+ * @param domainId - The domain ID (default: 0)
14
+ * @returns Promise that resolves to share price in 18-decimal Perbill format, or undefined if no price stored
15
+ * @throws Error if the query fails or operator/epoch not found
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { operatorEpochSharePrice } from '@autonomys/auto-consensus'
20
+ * import { activate } from '@autonomys/auto-utils'
21
+ *
22
+ * const api = await activate({ networkId: 'gemini-3h' })
23
+ *
24
+ * // Get share price for operator 1 at epoch 100
25
+ * const sharePrice = await operatorEpochSharePrice(api, '1', 100, 0)
26
+ *
27
+ * if (sharePrice) {
28
+ * console.log(`Share price at epoch 100: ${sharePrice}`)
29
+ * // Use for stake/share conversions at that epoch
30
+ * } else {
31
+ * console.log('No share price recorded for that epoch')
32
+ * }
33
+ * ```
5
34
  */
6
35
  export declare const operatorEpochSharePrice: (api: Api, operatorId: string | number | bigint, domainEpoch: string | number | bigint, domainId?: string | number | bigint) => Promise<bigint | undefined>;
7
36
  /**
8
- * Compute the on-the-fly share price for the operator in the current domain epoch
37
+ * Calculates the current real-time share price for an operator.
38
+ *
39
+ * This function computes the current share price by considering the operator's
40
+ * total stake, current epoch rewards (after nomination tax), and total shares.
41
+ * The calculation provides an up-to-date price that reflects recent staking
42
+ * activity and rewards distribution.
43
+ *
9
44
  * Formula: (currentTotalStake + currentEpochReward * (1 - nominationTax)) / currentTotalShares
45
+ *
46
+ * @param api - The connected API instance
47
+ * @param operatorId - The ID of the operator to calculate price for
48
+ * @returns Promise that resolves to current share price in 18-decimal Perbill format
49
+ * @throws Error if operator not found, domain staking summary unavailable, or calculation fails
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * import { instantSharePrice } from '@autonomys/auto-consensus'
54
+ * import { activate } from '@autonomys/auto-utils'
55
+ *
56
+ * const api = await activate({ networkId: 'gemini-3h' })
57
+ *
58
+ * // Get current share price for operator 1
59
+ * const currentPrice = await instantSharePrice(api, '1')
60
+ * console.log(`Current share price: ${currentPrice}`)
61
+ *
62
+ * // Use for real-time stake/share conversions
63
+ * const stakeAmount = BigInt('1000000000000000000') // 1 AI3
64
+ * const sharesEquivalent = (stakeAmount * BigInt(10 ** 18)) / currentPrice
65
+ * console.log(`${stakeAmount} stake = ${sharesEquivalent} shares`)
66
+ * ```
10
67
  */
11
68
  export declare const instantSharePrice: (api: Api, operatorId: string | number | bigint) => Promise<bigint>;
12
69
  //# sourceMappingURL=price.d.ts.map
@@ -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;AAKhD;;;GAGG;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,CAmC5B,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAC5B,KAAK,GAAG,EACR,YAAY,MAAM,GAAG,MAAM,GAAG,MAAM,KACnC,OAAO,CAAC,MAAM,CAiChB,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;AAKhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,CAmC5B,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,eAAO,MAAM,iBAAiB,GAC5B,KAAK,GAAG,EACR,YAAY,MAAM,GAAG,MAAM,GAAG,MAAM,KACnC,OAAO,CAAC,MAAM,CAiChB,CAAA"}
@@ -14,8 +14,37 @@ const domain_1 = require("../domain");
14
14
  const staking_1 = require("../staking");
15
15
  const parse_1 = require("../utils/parse");
16
16
  /**
17
- * Fetch the stored share price (18-dec Perbill) for a given (operatorId, domainEpoch) tuple
18
- * Returns undefined if no price is stored for that epoch (i.e. no staking activity)
17
+ * Retrieves the stored share price for a specific operator at a given domain epoch.
18
+ *
19
+ * This function fetches the historical share price that was recorded for an operator
20
+ * at a specific domain epoch. Share prices are stored when staking activity occurs
21
+ * and are used to convert between stake amounts and shares at different points in time.
22
+ * The price is returned in 18-decimal Perbill format.
23
+ *
24
+ * @param api - The connected API instance
25
+ * @param operatorId - The ID of the operator to query price for
26
+ * @param domainEpoch - The domain epoch index to query price for
27
+ * @param domainId - The domain ID (default: 0)
28
+ * @returns Promise that resolves to share price in 18-decimal Perbill format, or undefined if no price stored
29
+ * @throws Error if the query fails or operator/epoch not found
30
+ *
31
+ * @example
32
+ * ```typescript
33
+ * import { operatorEpochSharePrice } from '@autonomys/auto-consensus'
34
+ * import { activate } from '@autonomys/auto-utils'
35
+ *
36
+ * const api = await activate({ networkId: 'gemini-3h' })
37
+ *
38
+ * // Get share price for operator 1 at epoch 100
39
+ * const sharePrice = await operatorEpochSharePrice(api, '1', 100, 0)
40
+ *
41
+ * if (sharePrice) {
42
+ * console.log(`Share price at epoch 100: ${sharePrice}`)
43
+ * // Use for stake/share conversions at that epoch
44
+ * } else {
45
+ * console.log('No share price recorded for that epoch')
46
+ * }
47
+ * ```
19
48
  */
20
49
  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) {
21
50
  try {
@@ -46,8 +75,36 @@ const operatorEpochSharePrice = (api_1, operatorId_1, domainEpoch_1, ...args_1)
46
75
  });
47
76
  exports.operatorEpochSharePrice = operatorEpochSharePrice;
48
77
  /**
49
- * Compute the on-the-fly share price for the operator in the current domain epoch
78
+ * Calculates the current real-time share price for an operator.
79
+ *
80
+ * This function computes the current share price by considering the operator's
81
+ * total stake, current epoch rewards (after nomination tax), and total shares.
82
+ * The calculation provides an up-to-date price that reflects recent staking
83
+ * activity and rewards distribution.
84
+ *
50
85
  * Formula: (currentTotalStake + currentEpochReward * (1 - nominationTax)) / currentTotalShares
86
+ *
87
+ * @param api - The connected API instance
88
+ * @param operatorId - The ID of the operator to calculate price for
89
+ * @returns Promise that resolves to current share price in 18-decimal Perbill format
90
+ * @throws Error if operator not found, domain staking summary unavailable, or calculation fails
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * import { instantSharePrice } from '@autonomys/auto-consensus'
95
+ * import { activate } from '@autonomys/auto-utils'
96
+ *
97
+ * const api = await activate({ networkId: 'gemini-3h' })
98
+ *
99
+ * // Get current share price for operator 1
100
+ * const currentPrice = await instantSharePrice(api, '1')
101
+ * console.log(`Current share price: ${currentPrice}`)
102
+ *
103
+ * // Use for real-time stake/share conversions
104
+ * const stakeAmount = BigInt('1000000000000000000') // 1 AI3
105
+ * const sharesEquivalent = (stakeAmount * BigInt(10 ** 18)) / currentPrice
106
+ * console.log(`${stakeAmount} stake = ${sharesEquivalent} shares`)
107
+ * ```
51
108
  */
52
109
  const instantSharePrice = (api, operatorId) => __awaiter(void 0, void 0, void 0, function* () {
53
110
  try {
@@ -1,11 +1,62 @@
1
1
  /**
2
- * Convert shares to stake using an 18-decimal Perbill price
2
+ * Converts operator shares to stake amount using a given share price.
3
+ *
4
+ * This utility function converts a number of operator shares to the equivalent
5
+ * stake amount using the provided share price. The share price should be in
6
+ * 18-decimal Perbill format as returned by the price functions.
7
+ *
3
8
  * Formula: shares * price / 10^18
9
+ *
10
+ * @param shares - Number of shares to convert
11
+ * @param price - Share price in 18-decimal Perbill format
12
+ * @returns Equivalent stake amount in smallest token units
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import { shareToStake, instantSharePrice } from '@autonomys/auto-consensus'
17
+ * import { activate } from '@autonomys/auto-utils'
18
+ *
19
+ * const api = await activate({ networkId: 'gemini-3h' })
20
+ *
21
+ * // Get current share price
22
+ * const sharePrice = await instantSharePrice(api, '1')
23
+ *
24
+ * // Convert 1000 shares to stake amount
25
+ * const shares = BigInt(1000)
26
+ * const stakeAmount = shareToStake(shares, sharePrice)
27
+ * console.log(`${shares} shares = ${stakeAmount} tokens`)
28
+ * ```
4
29
  */
5
30
  export declare const shareToStake: (shares: bigint, price: bigint) => bigint;
6
31
  /**
7
- * Convert stake to shares using an 18-decimal Perbill price
32
+ * Converts stake amount to operator shares using a given share price.
33
+ *
34
+ * This utility function converts a stake amount to the equivalent number
35
+ * of operator shares using the provided share price. The share price should
36
+ * be in 18-decimal Perbill format as returned by the price functions.
37
+ *
8
38
  * Formula: stake * 10^18 / price
39
+ *
40
+ * @param stake - Stake amount in smallest token units to convert
41
+ * @param price - Share price in 18-decimal Perbill format
42
+ * @returns Equivalent number of shares
43
+ * @throws Error if price is zero (division by zero)
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * import { stakeToShare, instantSharePrice } from '@autonomys/auto-consensus'
48
+ * import { activate } from '@autonomys/auto-utils'
49
+ *
50
+ * const api = await activate({ networkId: 'gemini-3h' })
51
+ *
52
+ * // Get current share price
53
+ * const sharePrice = await instantSharePrice(api, '1')
54
+ *
55
+ * // Convert 1 AI3 to shares
56
+ * const stakeAmount = BigInt('1000000000000000000') // 1 AI3
57
+ * const shares = stakeToShare(stakeAmount, sharePrice)
58
+ * console.log(`${stakeAmount} tokens = ${shares} shares`)
59
+ * ```
9
60
  */
10
61
  export declare const stakeToShare: (stake: bigint, price: bigint) => bigint;
11
62
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/position/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,EAAE,OAAO,MAAM,KAAG,MAE5D,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,EAAE,OAAO,MAAM,KAAG,MAK3D,CAAA"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/position/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,EAAE,OAAO,MAAM,KAAG,MAE5D,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,MAAM,EAAE,OAAO,MAAM,KAAG,MAK3D,CAAA"}
@@ -2,16 +2,67 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.stakeToShare = exports.shareToStake = void 0;
4
4
  /**
5
- * Convert shares to stake using an 18-decimal Perbill price
5
+ * Converts operator shares to stake amount using a given share price.
6
+ *
7
+ * This utility function converts a number of operator shares to the equivalent
8
+ * stake amount using the provided share price. The share price should be in
9
+ * 18-decimal Perbill format as returned by the price functions.
10
+ *
6
11
  * Formula: shares * price / 10^18
12
+ *
13
+ * @param shares - Number of shares to convert
14
+ * @param price - Share price in 18-decimal Perbill format
15
+ * @returns Equivalent stake amount in smallest token units
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * import { shareToStake, instantSharePrice } from '@autonomys/auto-consensus'
20
+ * import { activate } from '@autonomys/auto-utils'
21
+ *
22
+ * const api = await activate({ networkId: 'gemini-3h' })
23
+ *
24
+ * // Get current share price
25
+ * const sharePrice = await instantSharePrice(api, '1')
26
+ *
27
+ * // Convert 1000 shares to stake amount
28
+ * const shares = BigInt(1000)
29
+ * const stakeAmount = shareToStake(shares, sharePrice)
30
+ * console.log(`${shares} shares = ${stakeAmount} tokens`)
31
+ * ```
7
32
  */
8
33
  const shareToStake = (shares, price) => {
9
34
  return (shares * price) / BigInt(Math.pow(10, 18));
10
35
  };
11
36
  exports.shareToStake = shareToStake;
12
37
  /**
13
- * Convert stake to shares using an 18-decimal Perbill price
38
+ * Converts stake amount to operator shares using a given share price.
39
+ *
40
+ * This utility function converts a stake amount to the equivalent number
41
+ * of operator shares using the provided share price. The share price should
42
+ * be in 18-decimal Perbill format as returned by the price functions.
43
+ *
14
44
  * Formula: stake * 10^18 / price
45
+ *
46
+ * @param stake - Stake amount in smallest token units to convert
47
+ * @param price - Share price in 18-decimal Perbill format
48
+ * @returns Equivalent number of shares
49
+ * @throws Error if price is zero (division by zero)
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * import { stakeToShare, instantSharePrice } from '@autonomys/auto-consensus'
54
+ * import { activate } from '@autonomys/auto-utils'
55
+ *
56
+ * const api = await activate({ networkId: 'gemini-3h' })
57
+ *
58
+ * // Get current share price
59
+ * const sharePrice = await instantSharePrice(api, '1')
60
+ *
61
+ * // Convert 1 AI3 to shares
62
+ * const stakeAmount = BigInt('1000000000000000000') // 1 AI3
63
+ * const shares = stakeToShare(stakeAmount, sharePrice)
64
+ * console.log(`${stakeAmount} tokens = ${shares} shares`)
65
+ * ```
15
66
  */
16
67
  const stakeToShare = (stake, price) => {
17
68
  if (price === BigInt(0)) {
package/dist/remark.d.ts CHANGED
@@ -1,3 +1,32 @@
1
1
  import type { ApiPromise } from '@autonomys/auto-utils';
2
+ /**
3
+ * Creates a remark transaction for adding arbitrary data to the blockchain.
4
+ *
5
+ * Remark transactions allow you to include arbitrary data in the blockchain without
6
+ * affecting the state. This is useful for timestamping data, adding metadata,
7
+ * or including custom information that needs to be permanently recorded.
8
+ *
9
+ * @param api - The connected API promise instance
10
+ * @param remark - The remark data to include in the transaction (as string or bytes)
11
+ * @param withEvent - Whether to emit an event for this remark (default: false)
12
+ * @returns A submittable remark transaction
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import { remark } from '@autonomys/auto-consensus'
17
+ * import { activate, signAndSendTx } from '@autonomys/auto-utils'
18
+ *
19
+ * const api = await activate({ networkId: 'gemini-3h' })
20
+ *
21
+ * // Create a simple remark
22
+ * const remarkTx = remark(api, 'Hello, blockchain!')
23
+ *
24
+ * // Create a remark with event
25
+ * const remarkWithEventTx = remark(api, JSON.stringify({ timestamp: Date.now() }), true)
26
+ *
27
+ * // Sign and send the transaction
28
+ * await signAndSendTx(sender, remarkTx)
29
+ * ```
30
+ */
2
31
  export declare const remark: (api: ApiPromise, remark: string, withEvent?: boolean) => import("@autonomys/auto-utils").SubmittableExtrinsic<"promise", import("@autonomys/auto-utils").ISubmittableResult>;
3
32
  //# sourceMappingURL=remark.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"remark.d.ts","sourceRoot":"","sources":["../src/remark.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAEvD,eAAO,MAAM,MAAM,GAAI,KAAK,UAAU,EAAE,QAAQ,MAAM,EAAE,YAAY,OAAO,wHACQ,CAAA"}
1
+ {"version":3,"file":"remark.d.ts","sourceRoot":"","sources":["../src/remark.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,MAAM,GAAI,KAAK,UAAU,EAAE,QAAQ,MAAM,EAAE,YAAY,OAAO,wHACQ,CAAA"}
package/dist/remark.js CHANGED
@@ -1,5 +1,34 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.remark = void 0;
4
+ /**
5
+ * Creates a remark transaction for adding arbitrary data to the blockchain.
6
+ *
7
+ * Remark transactions allow you to include arbitrary data in the blockchain without
8
+ * affecting the state. This is useful for timestamping data, adding metadata,
9
+ * or including custom information that needs to be permanently recorded.
10
+ *
11
+ * @param api - The connected API promise instance
12
+ * @param remark - The remark data to include in the transaction (as string or bytes)
13
+ * @param withEvent - Whether to emit an event for this remark (default: false)
14
+ * @returns A submittable remark transaction
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { remark } from '@autonomys/auto-consensus'
19
+ * import { activate, signAndSendTx } from '@autonomys/auto-utils'
20
+ *
21
+ * const api = await activate({ networkId: 'gemini-3h' })
22
+ *
23
+ * // Create a simple remark
24
+ * const remarkTx = remark(api, 'Hello, blockchain!')
25
+ *
26
+ * // Create a remark with event
27
+ * const remarkWithEventTx = remark(api, JSON.stringify({ timestamp: Date.now() }), true)
28
+ *
29
+ * // Sign and send the transaction
30
+ * await signAndSendTx(sender, remarkTx)
31
+ * ```
32
+ */
4
33
  const remark = (api, remark, withEvent) => !withEvent ? api.tx.system.remark(remark) : api.tx.system.remarkWithEvent(remark);
5
34
  exports.remark = remark;