radix-utils 1.1.0
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/LICENSE +21 -0
- package/README.md +283 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.d.ts +99 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/date.d.ts +8 -0
- package/dist/utils/date.d.ts.map +1 -0
- package/dist/utils/date.js +25 -0
- package/dist/utils/date.js.map +1 -0
- package/dist/utils/decimal.d.ts +16 -0
- package/dist/utils/decimal.d.ts.map +1 -0
- package/dist/utils/decimal.js +38 -0
- package/dist/utils/decimal.js.map +1 -0
- package/dist/utils/wallet.d.ts +11 -0
- package/dist/utils/wallet.d.ts.map +1 -0
- package/dist/utils/wallet.js +114 -0
- package/dist/utils/wallet.js.map +1 -0
- package/dist/validators/index.d.ts +27 -0
- package/dist/validators/index.d.ts.map +1 -0
- package/dist/validators/index.js +228 -0
- package/dist/validators/index.js.map +1 -0
- package/package.json +56 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Radix Utils Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
# Radix Utils
|
|
2
|
+
|
|
3
|
+
A comprehensive utility library for Radix DLT blockchain development, providing helper functions for working with validators, staking, and various Radix-specific operations.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install radix-utils
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- **Validator Information**: Fetch comprehensive validator data including staking amounts, fees, and vault information
|
|
14
|
+
- **Resource Checking**: Check fungible resource balances across multiple accounts
|
|
15
|
+
- **Fee Calculations**: Compute validator fee factors with pending changes
|
|
16
|
+
- **Date Utilities**: Calculate unlock dates based on epoch information
|
|
17
|
+
- **Decimal Operations**: Radix-specific decimal operations with proper precision
|
|
18
|
+
- **TypeScript Support**: Full TypeScript definitions included
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { fetchValidatorInfo, BN, GatewayApiClient } from 'radix-utils';
|
|
24
|
+
|
|
25
|
+
// Initialize the Gateway API client
|
|
26
|
+
const gatewayApi = GatewayApiClient.initialize({
|
|
27
|
+
networkId: 1, // Mainnet
|
|
28
|
+
applicationName: 'Your App Name',
|
|
29
|
+
applicationVersion: '1.0.0',
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Fetch validator information
|
|
33
|
+
const validatorAddress = 'validator_rdx1sd...';
|
|
34
|
+
const validatorInfo = await fetchValidatorInfo(gatewayApi, validatorAddress);
|
|
35
|
+
|
|
36
|
+
if (validatorInfo) {
|
|
37
|
+
console.log('Total Staked XRD:', validatorInfo.totalStakedXrds);
|
|
38
|
+
console.log('Current Fee:', validatorInfo.fees.current);
|
|
39
|
+
console.log('Validator Metadata:', validatorInfo.metadata);
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## API Reference
|
|
44
|
+
|
|
45
|
+
### Validator Functions
|
|
46
|
+
|
|
47
|
+
#### `fetchValidatorInfo(gatewayApi, validatorAddress)`
|
|
48
|
+
|
|
49
|
+
Fetches comprehensive information about a validator.
|
|
50
|
+
|
|
51
|
+
**Parameters:**
|
|
52
|
+
|
|
53
|
+
- `gatewayApi`: GatewayApiClient instance
|
|
54
|
+
- `validatorAddress`: String - The validator address (must start with 'validator\_')
|
|
55
|
+
|
|
56
|
+
**Returns:** `Promise<ValidatorInfo | undefined>`
|
|
57
|
+
|
|
58
|
+
**Example:**
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
const info = await fetchValidatorInfo(gatewayApi, 'validator_rdx1sd...');
|
|
62
|
+
console.log(info?.totalStakedXrds);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
#### `checkResourceInUsersFungibleAssets(usersAddresses, fungibleResourceToCheck, gatewayApi, ledgerState?)`
|
|
66
|
+
|
|
67
|
+
Checks if a specific fungible resource exists in users' accounts.
|
|
68
|
+
|
|
69
|
+
**Parameters:**
|
|
70
|
+
|
|
71
|
+
- `usersAddresses`: String[] - Array of account addresses to check
|
|
72
|
+
- `fungibleResourceToCheck`: String - Resource address to look for
|
|
73
|
+
- `gatewayApi`: GatewayApiClient instance
|
|
74
|
+
- `ledgerState?`: LedgerStateSelector (optional)
|
|
75
|
+
|
|
76
|
+
**Returns:** `Promise<ResourceCheckResult>`
|
|
77
|
+
|
|
78
|
+
**Example:**
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
const result = await checkResourceInUsersFungibleAssets(
|
|
82
|
+
['account_rdx1...', 'account_rdx2...'],
|
|
83
|
+
'resource_rdx1...',
|
|
84
|
+
gatewayApi
|
|
85
|
+
);
|
|
86
|
+
console.log('Total Amount:', result.totalAmount);
|
|
87
|
+
console.log('Users with Resource:', result.usersWithResourceAmount);
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
#### `computeValidatorFeeFactor(currentFeeFactor, newFeeFactor, currentEpoch)`
|
|
91
|
+
|
|
92
|
+
Computes validator fee factor information including pending changes.
|
|
93
|
+
|
|
94
|
+
**Parameters:**
|
|
95
|
+
|
|
96
|
+
- `currentFeeFactor`: String - Current fee factor as decimal string
|
|
97
|
+
- `newFeeFactor`: NewFeeFactor | null - New fee factor configuration
|
|
98
|
+
- `currentEpoch`: Number - Current epoch number
|
|
99
|
+
|
|
100
|
+
**Returns:** `FeeFactor`
|
|
101
|
+
|
|
102
|
+
#### `fetchWalletBalances(gatewayApi, walletAddress, ledgerState?)`
|
|
103
|
+
|
|
104
|
+
Fetches complete wallet balances including both fungible and non-fungible tokens with automatic pagination.
|
|
105
|
+
|
|
106
|
+
**Parameters:**
|
|
107
|
+
|
|
108
|
+
- `gatewayApi`: GatewayApiClient instance
|
|
109
|
+
- `walletAddress`: String - The wallet address to fetch balances for
|
|
110
|
+
- `ledgerState?`: LedgerStateSelector (optional) - For historical data
|
|
111
|
+
|
|
112
|
+
**Returns:** `Promise<WalletBalances>`
|
|
113
|
+
|
|
114
|
+
**Example:**
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
const balances = await fetchWalletBalances(gatewayApi, 'account_rdx1...');
|
|
118
|
+
|
|
119
|
+
// Access fungible token balances
|
|
120
|
+
Object.entries(balances.fungible).forEach(([address, balance]) => {
|
|
121
|
+
console.log(`Token ${address}: ${balance.amount}`);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// Access NFT collections
|
|
125
|
+
Object.entries(balances.nonFungible).forEach(([address, collection]) => {
|
|
126
|
+
console.log(`NFT Collection ${address}: ${collection.ids.length} items`);
|
|
127
|
+
});
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Utility Functions
|
|
131
|
+
|
|
132
|
+
#### `BN(value)`
|
|
133
|
+
|
|
134
|
+
Creates a new Decimal instance with Radix-specific precision configuration.
|
|
135
|
+
|
|
136
|
+
**Parameters:**
|
|
137
|
+
|
|
138
|
+
- `value`: String | Number - Value to convert to Decimal
|
|
139
|
+
|
|
140
|
+
**Returns:** `Decimal`
|
|
141
|
+
|
|
142
|
+
**Example:**
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
const amount = BN('1000.123456789');
|
|
146
|
+
const result = amount.plus('500.987654321');
|
|
147
|
+
console.log(result.toString());
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
#### `calculateEstimatedUnlockDate(epochUnlocked, currentEpoch)`
|
|
151
|
+
|
|
152
|
+
Calculates the estimated unlock date based on epoch information.
|
|
153
|
+
|
|
154
|
+
**Parameters:**
|
|
155
|
+
|
|
156
|
+
- `epochUnlocked`: Number - Epoch when stake will be unlocked
|
|
157
|
+
- `currentEpoch`: Number - Current epoch number
|
|
158
|
+
|
|
159
|
+
**Returns:** `String` - Formatted date string
|
|
160
|
+
|
|
161
|
+
**Example:**
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
const unlockDate = calculateEstimatedUnlockDate(1500, 1400);
|
|
165
|
+
console.log('Estimated unlock:', unlockDate);
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
#### `retryPromiseAll(promises, retries?, delay?)`
|
|
169
|
+
|
|
170
|
+
Executes Promise.all with retry logic and exponential backoff.
|
|
171
|
+
|
|
172
|
+
**Parameters:**
|
|
173
|
+
|
|
174
|
+
- `promises`: Promise<T>[] - Array of promises to execute
|
|
175
|
+
- `retries?`: Number (default: 3) - Number of retry attempts
|
|
176
|
+
- `delay?`: Number (default: 1000) - Initial delay in milliseconds
|
|
177
|
+
|
|
178
|
+
**Returns:** `Promise<T[]>`
|
|
179
|
+
|
|
180
|
+
## TypeScript Types
|
|
181
|
+
|
|
182
|
+
The library exports comprehensive TypeScript types:
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import type {
|
|
186
|
+
ValidatorInfo,
|
|
187
|
+
ValidatorVaults,
|
|
188
|
+
UnlockingRewards,
|
|
189
|
+
FeeFactor,
|
|
190
|
+
ResourceCheckResult,
|
|
191
|
+
WalletBalances,
|
|
192
|
+
FungibleBalances,
|
|
193
|
+
NonFungibleBalances,
|
|
194
|
+
} from 'radix-utils';
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Key Types
|
|
198
|
+
|
|
199
|
+
- **ValidatorInfo**: Complete validator information including staking data, fees, and metadata
|
|
200
|
+
- **ValidatorVaults**: Validator vault addresses
|
|
201
|
+
- **UnlockingRewards**: Array of unlocking reward entries
|
|
202
|
+
- **FeeFactor**: Fee factor information with current and pending changes
|
|
203
|
+
- **ResourceCheckResult**: Result of resource balance checks
|
|
204
|
+
- **WalletBalances**: Complete wallet balance information with fungible and non-fungible tokens
|
|
205
|
+
- **FungibleBalances**: Map of fungible token balances by address
|
|
206
|
+
- **NonFungibleBalances**: Map of NFT collections by address
|
|
207
|
+
|
|
208
|
+
## Contributing
|
|
209
|
+
|
|
210
|
+
Contributions are welcome! This library is designed to be easily extensible. To add new utility functions:
|
|
211
|
+
|
|
212
|
+
1. Create new files in the appropriate directory (`src/validators/`, `src/utils/`, etc.)
|
|
213
|
+
2. Export your functions from the relevant index files
|
|
214
|
+
3. Add comprehensive TypeScript types in `src/types/`
|
|
215
|
+
4. Update the main `src/index.ts` to export your new functions
|
|
216
|
+
5. Add tests for your new functionality
|
|
217
|
+
6. Update this README with documentation
|
|
218
|
+
|
|
219
|
+
### Development Setup
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
# Clone the repository
|
|
223
|
+
git clone <repository-url>
|
|
224
|
+
cd radix-utils
|
|
225
|
+
|
|
226
|
+
# Install dependencies
|
|
227
|
+
npm install
|
|
228
|
+
|
|
229
|
+
# Build the project
|
|
230
|
+
npm run build
|
|
231
|
+
|
|
232
|
+
# Run tests
|
|
233
|
+
npm test
|
|
234
|
+
|
|
235
|
+
# Run linting
|
|
236
|
+
npm run lint
|
|
237
|
+
|
|
238
|
+
# Format code
|
|
239
|
+
npm run format
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Project Structure
|
|
243
|
+
|
|
244
|
+
```
|
|
245
|
+
src/
|
|
246
|
+
├── types/ # TypeScript type definitions
|
|
247
|
+
├── validators/ # Validator-related utilities
|
|
248
|
+
├── utils/ # General utility functions
|
|
249
|
+
└── index.ts # Main export file
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
## Dependencies
|
|
253
|
+
|
|
254
|
+
- `@radixdlt/babylon-gateway-api-sdk`: Radix Gateway API SDK
|
|
255
|
+
- `decimal.js`: Arbitrary precision decimal calculations
|
|
256
|
+
|
|
257
|
+
## License
|
|
258
|
+
|
|
259
|
+
MIT License - see LICENSE file for details.
|
|
260
|
+
|
|
261
|
+
## Support
|
|
262
|
+
|
|
263
|
+
For issues and feature requests, please use the GitHub issue tracker.
|
|
264
|
+
|
|
265
|
+
## Changelog
|
|
266
|
+
|
|
267
|
+
### 1.1.0
|
|
268
|
+
|
|
269
|
+
- Added `fetchWalletBalances` function for comprehensive wallet balance fetching
|
|
270
|
+
- Added support for both fungible and non-fungible token balance retrieval
|
|
271
|
+
- Added automatic pagination support for large wallets
|
|
272
|
+
- Added new TypeScript types: `WalletBalances`, `FungibleBalances`, `NonFungibleBalances`
|
|
273
|
+
- Added comprehensive test coverage for wallet functionality
|
|
274
|
+
- Updated documentation with wallet balance examples
|
|
275
|
+
|
|
276
|
+
### 1.0.0
|
|
277
|
+
|
|
278
|
+
- Initial release
|
|
279
|
+
- Added `fetchValidatorInfo` function
|
|
280
|
+
- Added `checkResourceInUsersFungibleAssets` function
|
|
281
|
+
- Added `computeValidatorFeeFactor` function
|
|
282
|
+
- Added decimal and date utilities
|
|
283
|
+
- Full TypeScript support
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './types';
|
|
2
|
+
export { BN, retryPromiseAll } from './utils/decimal';
|
|
3
|
+
export { calculateEstimatedUnlockDate } from './utils/date';
|
|
4
|
+
export { fetchWalletBalances } from './utils/wallet';
|
|
5
|
+
export { fetchValidatorInfo, checkResourceInUsersFungibleAssets, computeValidatorFeeFactor, } from './validators';
|
|
6
|
+
export type { ValidatorInfo, ValidatorVaults, UnlockingRewards, UnlockingReward, NewFeeFactor, FeeFactor, ResourceCheckResult, LedgerStateVersion, WalletBalances, FungibleBalances, NonFungibleBalances, FungibleBalance, NonFungibleBalance, } from './types';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,EAAE,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAGrD,OAAO,EACL,kBAAkB,EAClB,kCAAkC,EAClC,yBAAyB,GAC1B,MAAM,cAAc,CAAC;AAGtB,YAAY,EACV,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,SAAS,EACT,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,kBAAkB,GACnB,MAAM,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.computeValidatorFeeFactor = exports.checkResourceInUsersFungibleAssets = exports.fetchValidatorInfo = exports.fetchWalletBalances = exports.calculateEstimatedUnlockDate = exports.retryPromiseAll = exports.BN = void 0;
|
|
18
|
+
// Export types
|
|
19
|
+
__exportStar(require("./types"), exports);
|
|
20
|
+
// Export utility functions
|
|
21
|
+
var decimal_1 = require("./utils/decimal");
|
|
22
|
+
Object.defineProperty(exports, "BN", { enumerable: true, get: function () { return decimal_1.BN; } });
|
|
23
|
+
Object.defineProperty(exports, "retryPromiseAll", { enumerable: true, get: function () { return decimal_1.retryPromiseAll; } });
|
|
24
|
+
var date_1 = require("./utils/date");
|
|
25
|
+
Object.defineProperty(exports, "calculateEstimatedUnlockDate", { enumerable: true, get: function () { return date_1.calculateEstimatedUnlockDate; } });
|
|
26
|
+
var wallet_1 = require("./utils/wallet");
|
|
27
|
+
Object.defineProperty(exports, "fetchWalletBalances", { enumerable: true, get: function () { return wallet_1.fetchWalletBalances; } });
|
|
28
|
+
// Export validator functions
|
|
29
|
+
var validators_1 = require("./validators");
|
|
30
|
+
Object.defineProperty(exports, "fetchValidatorInfo", { enumerable: true, get: function () { return validators_1.fetchValidatorInfo; } });
|
|
31
|
+
Object.defineProperty(exports, "checkResourceInUsersFungibleAssets", { enumerable: true, get: function () { return validators_1.checkResourceInUsersFungibleAssets; } });
|
|
32
|
+
Object.defineProperty(exports, "computeValidatorFeeFactor", { enumerable: true, get: function () { return validators_1.computeValidatorFeeFactor; } });
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,eAAe;AACf,0CAAwB;AAExB,2BAA2B;AAC3B,2CAAsD;AAA7C,6FAAA,EAAE,OAAA;AAAE,0GAAA,eAAe,OAAA;AAC5B,qCAA4D;AAAnD,oHAAA,4BAA4B,OAAA;AACrC,yCAAqD;AAA5C,6GAAA,mBAAmB,OAAA;AAE5B,6BAA6B;AAC7B,2CAIsB;AAHpB,gHAAA,kBAAkB,OAAA;AAClB,gIAAA,kCAAkC,OAAA;AAClC,uHAAA,yBAAyB,OAAA"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a single unlocking reward entry
|
|
3
|
+
*/
|
|
4
|
+
export interface UnlockingReward {
|
|
5
|
+
epoch_unlocked: number;
|
|
6
|
+
stake_unit_amount: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Array of unlocking rewards
|
|
10
|
+
*/
|
|
11
|
+
export type UnlockingRewards = UnlockingReward[];
|
|
12
|
+
/**
|
|
13
|
+
* New fee factor configuration
|
|
14
|
+
*/
|
|
15
|
+
export interface NewFeeFactor {
|
|
16
|
+
new_fee_factor: string;
|
|
17
|
+
epoch_effective: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Fee factor information with current and pending changes
|
|
21
|
+
*/
|
|
22
|
+
export interface FeeFactor {
|
|
23
|
+
aboutToChange: NewFeeFactor | null;
|
|
24
|
+
current: string;
|
|
25
|
+
alert: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Validator vault addresses
|
|
29
|
+
*/
|
|
30
|
+
export interface ValidatorVaults {
|
|
31
|
+
NODE_CURRENTLY_EARNED_LSU_VAULT_ADDRESS: string;
|
|
32
|
+
NODE_OWNER_UNLOCKING_LSU_VAULT_ADDRESS: string;
|
|
33
|
+
NODE_TOTAL_STAKED_XRD_VAULT_ADDRESS: string;
|
|
34
|
+
NODE_UNSTAKING_XRD_VAULT_ADDRESS: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Complete validator information
|
|
38
|
+
*/
|
|
39
|
+
export interface ValidatorInfo {
|
|
40
|
+
currentlyEarnedLockedLSUs: string;
|
|
41
|
+
ownerLSUsInUnlockingProcess: string;
|
|
42
|
+
totalStakedXrds: string;
|
|
43
|
+
totalXrdsLeavingOurNode: string;
|
|
44
|
+
unlockingLSUsBreakdown: UnlockingRewards;
|
|
45
|
+
epoch: number;
|
|
46
|
+
unlockedLSUs: string;
|
|
47
|
+
metadata: Record<string, string>;
|
|
48
|
+
stakeUnitAddress: string;
|
|
49
|
+
vaults: ValidatorVaults;
|
|
50
|
+
validatorAddress: string;
|
|
51
|
+
fees: FeeFactor;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Resource check result
|
|
55
|
+
*/
|
|
56
|
+
export interface ResourceCheckResult {
|
|
57
|
+
usersWithResourceAmount: Record<string, string>;
|
|
58
|
+
totalAmount: string;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Ledger state version information
|
|
62
|
+
*/
|
|
63
|
+
export interface LedgerStateVersion {
|
|
64
|
+
epoch: number;
|
|
65
|
+
network: string;
|
|
66
|
+
proposer_round_timestamp: string;
|
|
67
|
+
round: number;
|
|
68
|
+
state_version: number;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Fungible token balance information
|
|
72
|
+
*/
|
|
73
|
+
export interface FungibleBalance {
|
|
74
|
+
tokenAddress: string;
|
|
75
|
+
amount: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Non-fungible token collection information
|
|
79
|
+
*/
|
|
80
|
+
export interface NonFungibleBalance {
|
|
81
|
+
collectionAddress: string;
|
|
82
|
+
ids: string[];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Map of fungible balances by token address
|
|
86
|
+
*/
|
|
87
|
+
export type FungibleBalances = Record<string, FungibleBalance>;
|
|
88
|
+
/**
|
|
89
|
+
* Map of non-fungible balances by collection address
|
|
90
|
+
*/
|
|
91
|
+
export type NonFungibleBalances = Record<string, NonFungibleBalance>;
|
|
92
|
+
/**
|
|
93
|
+
* Complete wallet balance information
|
|
94
|
+
*/
|
|
95
|
+
export interface WalletBalances {
|
|
96
|
+
fungible: FungibleBalances;
|
|
97
|
+
nonFungible: NonFungibleBalances;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,eAAe,EAAE,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,aAAa,EAAE,YAAY,GAAG,IAAI,CAAC;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,eA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GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC;AAErE;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,WAAW,EAAE,mBAAmB,CAAC;CAClC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calculate estimated unlock date based on epoch information
|
|
3
|
+
* @param epochUnlocked - The epoch when the stake will be unlocked
|
|
4
|
+
* @param currentEpoch - The current epoch
|
|
5
|
+
* @returns Formatted date string
|
|
6
|
+
*/
|
|
7
|
+
export declare const calculateEstimatedUnlockDate: (epochUnlocked: number, currentEpoch: number) => string;
|
|
8
|
+
//# sourceMappingURL=date.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/utils/date.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,GACvC,eAAe,MAAM,EACrB,cAAc,MAAM,KACnB,MAeF,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateEstimatedUnlockDate = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Calculate estimated unlock date based on epoch information
|
|
6
|
+
* @param epochUnlocked - The epoch when the stake will be unlocked
|
|
7
|
+
* @param currentEpoch - The current epoch
|
|
8
|
+
* @returns Formatted date string
|
|
9
|
+
*/
|
|
10
|
+
const calculateEstimatedUnlockDate = (epochUnlocked, currentEpoch) => {
|
|
11
|
+
const minutesPerEpoch = 5;
|
|
12
|
+
const currentDate = new Date();
|
|
13
|
+
const unlockDate = new Date(currentDate.getTime() +
|
|
14
|
+
(epochUnlocked - currentEpoch) * minutesPerEpoch * 60000);
|
|
15
|
+
return unlockDate.toLocaleString('en-GB', {
|
|
16
|
+
day: '2-digit',
|
|
17
|
+
month: '2-digit',
|
|
18
|
+
year: 'numeric',
|
|
19
|
+
hour: 'numeric',
|
|
20
|
+
minute: '2-digit',
|
|
21
|
+
hour12: true,
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
exports.calculateEstimatedUnlockDate = calculateEstimatedUnlockDate;
|
|
25
|
+
//# sourceMappingURL=date.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../src/utils/date.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACI,MAAM,4BAA4B,GAAG,CAC1C,aAAqB,EACrB,YAAoB,EACZ,EAAE;IACV,MAAM,eAAe,GAAG,CAAC,CAAC;IAC1B,MAAM,WAAW,GAAG,IAAI,IAAI,EAAE,CAAC;IAC/B,MAAM,UAAU,GAAG,IAAI,IAAI,CACzB,WAAW,CAAC,OAAO,EAAE;QACnB,CAAC,aAAa,GAAG,YAAY,CAAC,GAAG,eAAe,GAAG,KAAK,CAC3D,CAAC;IACF,OAAO,UAAU,CAAC,cAAc,CAAC,OAAO,EAAE;QACxC,GAAG,EAAE,SAAS;QACd,KAAK,EAAE,SAAS;QAChB,IAAI,EAAE,SAAS;QACf,IAAI,EAAE,SAAS;QACf,MAAM,EAAE,SAAS;QACjB,MAAM,EAAE,IAAI;KACb,CAAC,CAAC;AACL,CAAC,CAAC;AAlBW,QAAA,4BAA4B,gCAkBvC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Decimal } from 'decimal.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new Decimal instance with Radix-specific configuration
|
|
4
|
+
* @param value - The value to convert to Decimal
|
|
5
|
+
* @returns A new Decimal instance
|
|
6
|
+
*/
|
|
7
|
+
export declare const BN: (value: string | number) => Decimal;
|
|
8
|
+
/**
|
|
9
|
+
* Retry a promise with exponential backoff
|
|
10
|
+
* @param promises - Array of promises to execute
|
|
11
|
+
* @param retries - Number of retries (default: 3)
|
|
12
|
+
* @param delay - Initial delay in milliseconds (default: 1000)
|
|
13
|
+
* @returns Promise that resolves to the result of Promise.all
|
|
14
|
+
*/
|
|
15
|
+
export declare const retryPromiseAll: <T>(promises: Promise<T>[], retries?: number, delay?: number) => Promise<T[]>;
|
|
16
|
+
//# sourceMappingURL=decimal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decimal.d.ts","sourceRoot":"","sources":["../../src/utils/decimal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAQrC;;;;GAIG;AACH,eAAO,MAAM,EAAE,GAAI,OAAO,MAAM,GAAG,MAAM,KAAG,OAA6B,CAAC;AAE1E;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAAU,CAAC,EACrC,UAAU,OAAO,CAAC,CAAC,CAAC,EAAE,EACtB,gBAAW,EACX,cAAY,KACX,OAAO,CAAC,CAAC,EAAE,CAYb,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.retryPromiseAll = exports.BN = void 0;
|
|
4
|
+
const decimal_js_1 = require("decimal.js");
|
|
5
|
+
// Configure Decimal for Radix use case
|
|
6
|
+
decimal_js_1.Decimal.config({
|
|
7
|
+
precision: 28,
|
|
8
|
+
rounding: decimal_js_1.Decimal.ROUND_HALF_UP,
|
|
9
|
+
});
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new Decimal instance with Radix-specific configuration
|
|
12
|
+
* @param value - The value to convert to Decimal
|
|
13
|
+
* @returns A new Decimal instance
|
|
14
|
+
*/
|
|
15
|
+
const BN = (value) => new decimal_js_1.Decimal(value);
|
|
16
|
+
exports.BN = BN;
|
|
17
|
+
/**
|
|
18
|
+
* Retry a promise with exponential backoff
|
|
19
|
+
* @param promises - Array of promises to execute
|
|
20
|
+
* @param retries - Number of retries (default: 3)
|
|
21
|
+
* @param delay - Initial delay in milliseconds (default: 1000)
|
|
22
|
+
* @returns Promise that resolves to the result of Promise.all
|
|
23
|
+
*/
|
|
24
|
+
const retryPromiseAll = async (promises, retries = 3, delay = 1000) => {
|
|
25
|
+
for (let i = 0; i < retries; i++) {
|
|
26
|
+
try {
|
|
27
|
+
return await Promise.all(promises);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (i === retries - 1)
|
|
31
|
+
throw error;
|
|
32
|
+
await new Promise((resolve) => setTimeout(resolve, delay * Math.pow(2, i)));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
throw new Error('All retries exhausted');
|
|
36
|
+
};
|
|
37
|
+
exports.retryPromiseAll = retryPromiseAll;
|
|
38
|
+
//# sourceMappingURL=decimal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decimal.js","sourceRoot":"","sources":["../../src/utils/decimal.ts"],"names":[],"mappings":";;;AAAA,2CAAqC;AAErC,uCAAuC;AACvC,oBAAO,CAAC,MAAM,CAAC;IACb,SAAS,EAAE,EAAE;IACb,QAAQ,EAAE,oBAAO,CAAC,aAAa;CAChC,CAAC,CAAC;AAEH;;;;GAIG;AACI,MAAM,EAAE,GAAG,CAAC,KAAsB,EAAW,EAAE,CAAC,IAAI,oBAAO,CAAC,KAAK,CAAC,CAAC;AAA7D,QAAA,EAAE,MAA2D;AAE1E;;;;;;GAMG;AACI,MAAM,eAAe,GAAG,KAAK,EAClC,QAAsB,EACtB,OAAO,GAAG,CAAC,EACX,KAAK,GAAG,IAAI,EACE,EAAE;IAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,EAAE,CAAC,EAAE,EAAE,CAAC;QACjC,IAAI,CAAC;YACH,OAAO,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACrC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,KAAK,OAAO,GAAG,CAAC;gBAAE,MAAM,KAAK,CAAC;YACnC,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAC5B,UAAU,CAAC,OAAO,EAAE,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAC5C,CAAC;QACJ,CAAC;IACH,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;AAC3C,CAAC,CAAC;AAhBW,QAAA,eAAe,mBAgB1B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { GatewayApiClient, LedgerStateSelector } from '@radixdlt/babylon-gateway-api-sdk';
|
|
2
|
+
import { WalletBalances } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Fetch complete wallet balances including fungible and non-fungible tokens
|
|
5
|
+
* @param gatewayApi - Gateway API client instance
|
|
6
|
+
* @param walletAddress - The wallet address to fetch balances for
|
|
7
|
+
* @param ledgerState - Optional ledger state selector for historical data
|
|
8
|
+
* @returns Complete wallet balance information
|
|
9
|
+
*/
|
|
10
|
+
export declare const fetchWalletBalances: (gatewayApi: GatewayApiClient, walletAddress: string, ledgerState?: LedgerStateSelector) => Promise<WalletBalances>;
|
|
11
|
+
//# sourceMappingURL=wallet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/utils/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAKhB,mBAAmB,EACpB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EACL,cAAc,EAGf,MAAM,UAAU,CAAC;AA6ElB;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAC9B,YAAY,gBAAgB,EAC5B,eAAe,MAAM,EACrB,cAAc,mBAAmB,KAChC,OAAO,CAAC,cAAc,CA8CxB,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchWalletBalances = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Fetch all fungible resources for a wallet address with pagination
|
|
6
|
+
* @param gatewayApi - Gateway API client instance
|
|
7
|
+
* @param walletAddress - The wallet address to fetch fungibles for
|
|
8
|
+
* @param ledgerState - Optional ledger state selector
|
|
9
|
+
* @returns Array of all fungible resource collection items
|
|
10
|
+
*/
|
|
11
|
+
const fetchAllFungibles = async (gatewayApi, walletAddress, ledgerState) => {
|
|
12
|
+
let allFungibleItems = [];
|
|
13
|
+
let nextCursor = undefined;
|
|
14
|
+
let response;
|
|
15
|
+
let stateVersion = undefined;
|
|
16
|
+
do {
|
|
17
|
+
response = await gatewayApi.state.innerClient.entityFungiblesPage({
|
|
18
|
+
stateEntityFungiblesPageRequest: {
|
|
19
|
+
address: walletAddress,
|
|
20
|
+
cursor: nextCursor || undefined,
|
|
21
|
+
aggregation_level: 'Global',
|
|
22
|
+
at_ledger_state: ledgerState ||
|
|
23
|
+
(stateVersion ? { state_version: stateVersion } : undefined),
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
allFungibleItems = allFungibleItems.concat(response.items);
|
|
27
|
+
nextCursor = response.next_cursor;
|
|
28
|
+
stateVersion = response.ledger_state.state_version;
|
|
29
|
+
} while (nextCursor);
|
|
30
|
+
return allFungibleItems;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Fetch all non-fungible resources for a wallet address with pagination
|
|
34
|
+
* @param gatewayApi - Gateway API client instance
|
|
35
|
+
* @param walletAddress - The wallet address to fetch non-fungibles for
|
|
36
|
+
* @param ledgerState - Optional ledger state selector
|
|
37
|
+
* @returns Array of all non-fungible resource collection items
|
|
38
|
+
*/
|
|
39
|
+
const fetchAllNonFungibles = async (gatewayApi, walletAddress, ledgerState) => {
|
|
40
|
+
let allNonFungibleItems = [];
|
|
41
|
+
let nextCursor = undefined;
|
|
42
|
+
let response;
|
|
43
|
+
let stateVersion = undefined;
|
|
44
|
+
do {
|
|
45
|
+
response = await gatewayApi.state.innerClient.entityNonFungiblesPage({
|
|
46
|
+
stateEntityNonFungiblesPageRequest: {
|
|
47
|
+
address: walletAddress,
|
|
48
|
+
cursor: nextCursor || undefined,
|
|
49
|
+
aggregation_level: 'Vault',
|
|
50
|
+
opt_ins: { non_fungible_include_nfids: true },
|
|
51
|
+
at_ledger_state: ledgerState ||
|
|
52
|
+
(stateVersion ? { state_version: stateVersion } : undefined),
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
allNonFungibleItems = allNonFungibleItems.concat(response.items);
|
|
56
|
+
nextCursor = response.next_cursor;
|
|
57
|
+
stateVersion = response.ledger_state.state_version;
|
|
58
|
+
} while (nextCursor);
|
|
59
|
+
return allNonFungibleItems;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Fetch complete wallet balances including fungible and non-fungible tokens
|
|
63
|
+
* @param gatewayApi - Gateway API client instance
|
|
64
|
+
* @param walletAddress - The wallet address to fetch balances for
|
|
65
|
+
* @param ledgerState - Optional ledger state selector for historical data
|
|
66
|
+
* @returns Complete wallet balance information
|
|
67
|
+
*/
|
|
68
|
+
const fetchWalletBalances = async (gatewayApi, walletAddress, ledgerState) => {
|
|
69
|
+
try {
|
|
70
|
+
// Fetch both fungible and non-fungible resources in parallel
|
|
71
|
+
const [fungibleBalances, nonFungibleBalances] = await Promise.all([
|
|
72
|
+
fetchAllFungibles(gatewayApi, walletAddress, ledgerState),
|
|
73
|
+
fetchAllNonFungibles(gatewayApi, walletAddress, ledgerState),
|
|
74
|
+
]);
|
|
75
|
+
// Format fungible balances
|
|
76
|
+
const formattedFungibleBalances = {};
|
|
77
|
+
fungibleBalances.forEach((balance) => {
|
|
78
|
+
if (balance.aggregation_level === 'Global') {
|
|
79
|
+
const amount = balance.amount;
|
|
80
|
+
const tokenAddress = balance.resource_address;
|
|
81
|
+
if (+amount > 0) {
|
|
82
|
+
formattedFungibleBalances[tokenAddress] = { tokenAddress, amount };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
// Format non-fungible balances
|
|
87
|
+
const formattedNonFungibleBalances = {};
|
|
88
|
+
nonFungibleBalances.forEach((item) => {
|
|
89
|
+
if (item.aggregation_level === 'Vault' && 'vaults' in item) {
|
|
90
|
+
const collectionAddress = item.resource_address;
|
|
91
|
+
const vault = item.vaults.items[0];
|
|
92
|
+
if (vault && 'items' in vault) {
|
|
93
|
+
const ids = vault.items;
|
|
94
|
+
if (ids && ids.length > 0) {
|
|
95
|
+
formattedNonFungibleBalances[collectionAddress] = {
|
|
96
|
+
collectionAddress,
|
|
97
|
+
ids,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
return {
|
|
104
|
+
fungible: formattedFungibleBalances,
|
|
105
|
+
nonFungible: formattedNonFungibleBalances,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
console.error('Error in fetchWalletBalances:', error);
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
exports.fetchWalletBalances = fetchWalletBalances;
|
|
114
|
+
//# sourceMappingURL=wallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../src/utils/wallet.ts"],"names":[],"mappings":";;;AAcA;;;;;;GAMG;AACH,MAAM,iBAAiB,GAAG,KAAK,EAC7B,UAA4B,EAC5B,aAAqB,EACrB,WAAiC,EACW,EAAE;IAC9C,IAAI,gBAAgB,GAAsC,EAAE,CAAC;IAC7D,IAAI,UAAU,GAA8B,SAAS,CAAC;IACtD,IAAI,QAA0C,CAAC;IAC/C,IAAI,YAAY,GAAuB,SAAS,CAAC;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AI,QAAQ,IAAI,IAAI,EAAE,CAAC;gBAC3D,MAAM,iBAAiB,GAAG,IAAI,CAAC,gBAAgB,CAAC;gBAChD,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBACnC,IAAI,KAAK,IAAI,OAAO,IAAI,KAAK,EAAE,CAAC;oBAC9B,MAAM,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC;oBACxB,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;wBAC1B,4BAA4B,CAAC,iBAAiB,CAAC,GAAG;4BAChD,iBAAiB;4BACjB,GAAG;yBACJ,CAAC;oBACJ,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,OAAO;YACL,QAAQ,EAAE,yBAAyB;YACnC,WAAW,EAAE,4BAA4B;SAC1C,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,KAAK,CAAC,CAAC;QACtD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC,CAAC;AAlDW,QAAA,mBAAmB,uBAkD9B"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { GatewayApiClient, LedgerStateSelector } from '@radixdlt/babylon-gateway-api-sdk';
|
|
2
|
+
import { ValidatorInfo, NewFeeFactor, FeeFactor, ResourceCheckResult } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Compute validator fee factor information
|
|
5
|
+
* @param currentFeeFactor - Current fee factor as string
|
|
6
|
+
* @param newFeeFactor - New fee factor configuration (if any)
|
|
7
|
+
* @param currentEpoch - Current epoch number
|
|
8
|
+
* @returns Fee factor information
|
|
9
|
+
*/
|
|
10
|
+
export declare const computeValidatorFeeFactor: (currentFeeFactor: string, newFeeFactor: NewFeeFactor | null, currentEpoch: number) => FeeFactor;
|
|
11
|
+
/**
|
|
12
|
+
* Check if a resource exists in users' fungible assets
|
|
13
|
+
* @param usersAddresses - Array of user addresses to check
|
|
14
|
+
* @param fungibleResourceToCheck - Resource address to check for
|
|
15
|
+
* @param gatewayApi - Gateway API client instance
|
|
16
|
+
* @param ledgerState - Optional ledger state selector
|
|
17
|
+
* @returns Resource check result with users and total amount
|
|
18
|
+
*/
|
|
19
|
+
export declare const checkResourceInUsersFungibleAssets: (usersAddresses: string[], fungibleResourceToCheck: string, gatewayApi: GatewayApiClient, ledgerState?: LedgerStateSelector) => Promise<ResourceCheckResult>;
|
|
20
|
+
/**
|
|
21
|
+
* Fetch comprehensive validator information
|
|
22
|
+
* @param gatewayApi - Gateway API client instance
|
|
23
|
+
* @param validatorAddress - Validator address to fetch info for
|
|
24
|
+
* @returns Validator information or undefined if not found/invalid
|
|
25
|
+
*/
|
|
26
|
+
export declare const fetchValidatorInfo: (gatewayApi: GatewayApiClient, validatorAddress: string) => Promise<ValidatorInfo | undefined>;
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validators/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAEhB,mBAAmB,EACpB,MAAM,mCAAmC,CAAC;AAG3C,OAAO,EACL,aAAa,EAGb,YAAY,EACZ,SAAS,EACT,mBAAmB,EACpB,MAAM,UAAU,CAAC;AAiGlB;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,GACpC,kBAAkB,MAAM,EACxB,cAAc,YAAY,GAAG,IAAI,EACjC,cAAc,MAAM,KACnB,SA2BF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,kCAAkC,GAC7C,gBAAgB,MAAM,EAAE,EACxB,yBAAyB,MAAM,EAC/B,YAAY,gBAAgB,EAC5B,cAAc,mBAAmB,KAChC,OAAO,CAAC,mBAAmB,CAiC7B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAC7B,YAAY,gBAAgB,EAC5B,kBAAkB,MAAM,KACvB,OAAO,CAAC,aAAa,GAAG,SAAS,CAyGnC,CAAC"}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchValidatorInfo = exports.checkResourceInUsersFungibleAssets = exports.computeValidatorFeeFactor = void 0;
|
|
4
|
+
const decimal_1 = require("../utils/decimal");
|
|
5
|
+
const date_1 = require("../utils/date");
|
|
6
|
+
/**
|
|
7
|
+
* Extract metadata from EntityMetadataCollection
|
|
8
|
+
* @param metadata - The metadata collection to extract from
|
|
9
|
+
* @returns Extracted metadata as key-value pairs
|
|
10
|
+
*/
|
|
11
|
+
const extractMetadata = (metadata) => {
|
|
12
|
+
const extractedMetadata = {};
|
|
13
|
+
metadata.items.forEach((item) => {
|
|
14
|
+
const valueType = item.value.typed.type;
|
|
15
|
+
if (valueType === 'String' ||
|
|
16
|
+
valueType === 'Url' ||
|
|
17
|
+
valueType === 'GlobalAddress' ||
|
|
18
|
+
valueType === 'NonFungibleLocalId') {
|
|
19
|
+
extractedMetadata[item.key] = item.value.typed.value;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
return extractedMetadata;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Extract vault addresses from validator state
|
|
26
|
+
* @param state - The validator state object
|
|
27
|
+
* @returns Validator vault addresses
|
|
28
|
+
*/
|
|
29
|
+
const extractVaultsAddresses = (state) => {
|
|
30
|
+
let NODE_CURRENTLY_EARNED_LSU_VAULT_ADDRESS = '';
|
|
31
|
+
let NODE_OWNER_UNLOCKING_LSU_VAULT_ADDRESS = '';
|
|
32
|
+
let NODE_TOTAL_STAKED_XRD_VAULT_ADDRESS = '';
|
|
33
|
+
let NODE_UNSTAKING_XRD_VAULT_ADDRESS = '';
|
|
34
|
+
if ('stake_xrd_vault' in state) {
|
|
35
|
+
NODE_TOTAL_STAKED_XRD_VAULT_ADDRESS = state.stake_xrd_vault.entity_address;
|
|
36
|
+
}
|
|
37
|
+
if ('pending_xrd_withdraw_vault' in state) {
|
|
38
|
+
NODE_UNSTAKING_XRD_VAULT_ADDRESS = state.pending_xrd_withdraw_vault.entity_address;
|
|
39
|
+
}
|
|
40
|
+
if ('locked_owner_stake_unit_vault' in state) {
|
|
41
|
+
NODE_CURRENTLY_EARNED_LSU_VAULT_ADDRESS = state.locked_owner_stake_unit_vault.entity_address;
|
|
42
|
+
}
|
|
43
|
+
if ('pending_owner_stake_unit_unlock_vault' in state) {
|
|
44
|
+
NODE_OWNER_UNLOCKING_LSU_VAULT_ADDRESS = state.pending_owner_stake_unit_unlock_vault.entity_address;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
NODE_CURRENTLY_EARNED_LSU_VAULT_ADDRESS,
|
|
48
|
+
NODE_OWNER_UNLOCKING_LSU_VAULT_ADDRESS,
|
|
49
|
+
NODE_TOTAL_STAKED_XRD_VAULT_ADDRESS,
|
|
50
|
+
NODE_UNSTAKING_XRD_VAULT_ADDRESS,
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Filter pending withdrawals and separate unlocked LSUs
|
|
55
|
+
* @param pendingWithdrawals - Array of pending withdrawals
|
|
56
|
+
* @param currentEpoch - Current epoch number
|
|
57
|
+
* @returns Filtered withdrawals and unlocked amounts
|
|
58
|
+
*/
|
|
59
|
+
const filterPendingWithdrawalsFromUnlockedLSUs = (pendingWithdrawals, currentEpoch) => {
|
|
60
|
+
let unlockedLSUsAmount = (0, decimal_1.BN)(0);
|
|
61
|
+
let lsuInUnlockingProcess = (0, decimal_1.BN)(0);
|
|
62
|
+
const filteredWithdrawals = pendingWithdrawals.filter((withdrawal) => {
|
|
63
|
+
const isUnlocked = withdrawal.epoch_unlocked <= currentEpoch;
|
|
64
|
+
if (isUnlocked) {
|
|
65
|
+
unlockedLSUsAmount = unlockedLSUsAmount.add(withdrawal.stake_unit_amount);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
lsuInUnlockingProcess = lsuInUnlockingProcess.add(withdrawal.stake_unit_amount);
|
|
69
|
+
}
|
|
70
|
+
return !isUnlocked;
|
|
71
|
+
});
|
|
72
|
+
return {
|
|
73
|
+
filteredWithdrawals,
|
|
74
|
+
unlockedLSUsAmount,
|
|
75
|
+
lsuInUnlockingProcess,
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Compute validator fee factor information
|
|
80
|
+
* @param currentFeeFactor - Current fee factor as string
|
|
81
|
+
* @param newFeeFactor - New fee factor configuration (if any)
|
|
82
|
+
* @param currentEpoch - Current epoch number
|
|
83
|
+
* @returns Fee factor information
|
|
84
|
+
*/
|
|
85
|
+
const computeValidatorFeeFactor = (currentFeeFactor, newFeeFactor, currentEpoch) => {
|
|
86
|
+
const feeFactor = {
|
|
87
|
+
aboutToChange: null,
|
|
88
|
+
current: (+currentFeeFactor * 100).toFixed(2) + '%',
|
|
89
|
+
alert: '',
|
|
90
|
+
};
|
|
91
|
+
if (newFeeFactor) {
|
|
92
|
+
const newFactorPercentage = (+newFeeFactor.new_fee_factor * 100).toFixed(2) + '%';
|
|
93
|
+
if (newFeeFactor.epoch_effective <= currentEpoch) {
|
|
94
|
+
feeFactor.current = newFactorPercentage;
|
|
95
|
+
feeFactor.aboutToChange = null;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
feeFactor.aboutToChange = {
|
|
99
|
+
new_fee_factor: newFactorPercentage,
|
|
100
|
+
epoch_effective: newFeeFactor.epoch_effective,
|
|
101
|
+
};
|
|
102
|
+
feeFactor.alert = `Fee will be changed to ${newFactorPercentage} on ${(0, date_1.calculateEstimatedUnlockDate)(newFeeFactor.epoch_effective, currentEpoch)}`;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return feeFactor;
|
|
106
|
+
};
|
|
107
|
+
exports.computeValidatorFeeFactor = computeValidatorFeeFactor;
|
|
108
|
+
/**
|
|
109
|
+
* Check if a resource exists in users' fungible assets
|
|
110
|
+
* @param usersAddresses - Array of user addresses to check
|
|
111
|
+
* @param fungibleResourceToCheck - Resource address to check for
|
|
112
|
+
* @param gatewayApi - Gateway API client instance
|
|
113
|
+
* @param ledgerState - Optional ledger state selector
|
|
114
|
+
* @returns Resource check result with users and total amount
|
|
115
|
+
*/
|
|
116
|
+
const checkResourceInUsersFungibleAssets = async (usersAddresses, fungibleResourceToCheck, gatewayApi, ledgerState) => {
|
|
117
|
+
try {
|
|
118
|
+
const allPromises = usersAddresses.map((address) => gatewayApi.state.innerClient.entityFungibleResourceVaultPage({
|
|
119
|
+
stateEntityFungibleResourceVaultsPageRequest: {
|
|
120
|
+
address,
|
|
121
|
+
resource_address: fungibleResourceToCheck,
|
|
122
|
+
at_ledger_state: ledgerState,
|
|
123
|
+
},
|
|
124
|
+
}));
|
|
125
|
+
const allResponses = (await (0, decimal_1.retryPromiseAll)(allPromises)).flat();
|
|
126
|
+
let totalAmount = (0, decimal_1.BN)(0);
|
|
127
|
+
const usersWithResourceAmount = {};
|
|
128
|
+
allResponses.forEach((res) => {
|
|
129
|
+
res.items.forEach((vault) => {
|
|
130
|
+
if ((0, decimal_1.BN)(vault.amount).greaterThan(0)) {
|
|
131
|
+
usersWithResourceAmount[res.address] = vault.amount;
|
|
132
|
+
totalAmount = totalAmount.plus(vault.amount);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
return {
|
|
137
|
+
usersWithResourceAmount,
|
|
138
|
+
totalAmount: totalAmount.toString(),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
console.error('Error in checkResourceInUsersFungibleAssets', error);
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
exports.checkResourceInUsersFungibleAssets = checkResourceInUsersFungibleAssets;
|
|
147
|
+
/**
|
|
148
|
+
* Fetch comprehensive validator information
|
|
149
|
+
* @param gatewayApi - Gateway API client instance
|
|
150
|
+
* @param validatorAddress - Validator address to fetch info for
|
|
151
|
+
* @returns Validator information or undefined if not found/invalid
|
|
152
|
+
*/
|
|
153
|
+
const fetchValidatorInfo = async (gatewayApi, validatorAddress) => {
|
|
154
|
+
if (validatorAddress === '' || !validatorAddress.startsWith('validator_')) {
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
const res = await gatewayApi.state.innerClient.stateEntityDetails({
|
|
159
|
+
stateEntityDetailsRequest: {
|
|
160
|
+
addresses: [validatorAddress],
|
|
161
|
+
aggregation_level: 'Vault',
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
const validatorInfo = res.items[0];
|
|
165
|
+
const vaultsBalance = {};
|
|
166
|
+
let rewardsInUnlockingProcess = [];
|
|
167
|
+
const epoch = res.ledger_state.epoch;
|
|
168
|
+
let unlockedLSUs = (0, decimal_1.BN)(0);
|
|
169
|
+
let ownerLSUsInUnlockingProcess = (0, decimal_1.BN)(0);
|
|
170
|
+
let stakeUnitAddress = '';
|
|
171
|
+
let fees = { alert: '', current: '', aboutToChange: null };
|
|
172
|
+
if (validatorInfo?.details?.type === 'Component' &&
|
|
173
|
+
validatorInfo?.details?.state) {
|
|
174
|
+
const metadata = extractMetadata(res.items[0].metadata);
|
|
175
|
+
const validatorState = validatorInfo.details.state;
|
|
176
|
+
const vaults = extractVaultsAddresses(validatorState);
|
|
177
|
+
// Extract vault balances
|
|
178
|
+
validatorInfo?.fungible_resources?.items.forEach((resource) => {
|
|
179
|
+
if (resource.aggregation_level === 'Vault') {
|
|
180
|
+
resource.vaults.items.forEach((vault) => {
|
|
181
|
+
vaultsBalance[vault.vault_address] = vault.amount;
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
// Process pending withdrawals
|
|
186
|
+
if ('pending_owner_stake_unit_withdrawals' in validatorState) {
|
|
187
|
+
const { filteredWithdrawals, unlockedLSUsAmount, lsuInUnlockingProcess, } = filterPendingWithdrawalsFromUnlockedLSUs(validatorState.pending_owner_stake_unit_withdrawals, epoch);
|
|
188
|
+
rewardsInUnlockingProcess = filteredWithdrawals;
|
|
189
|
+
unlockedLSUs = unlockedLSUs.add(unlockedLSUsAmount);
|
|
190
|
+
ownerLSUsInUnlockingProcess = ownerLSUsInUnlockingProcess.add(lsuInUnlockingProcess);
|
|
191
|
+
}
|
|
192
|
+
// Add already unlocked amounts
|
|
193
|
+
if ('already_unlocked_owner_stake_unit_amount' in validatorState) {
|
|
194
|
+
unlockedLSUs = unlockedLSUs.add(validatorState.already_unlocked_owner_stake_unit_amount);
|
|
195
|
+
}
|
|
196
|
+
// Get stake unit address
|
|
197
|
+
if ('stake_unit_resource_address' in validatorState) {
|
|
198
|
+
stakeUnitAddress = validatorState.stake_unit_resource_address;
|
|
199
|
+
}
|
|
200
|
+
// Compute fees
|
|
201
|
+
if ('validator_fee_factor' in validatorState &&
|
|
202
|
+
'validator_fee_change_request' in validatorState) {
|
|
203
|
+
fees = (0, exports.computeValidatorFeeFactor)(validatorState.validator_fee_factor, validatorState.validator_fee_change_request, epoch);
|
|
204
|
+
}
|
|
205
|
+
const info = {
|
|
206
|
+
currentlyEarnedLockedLSUs: vaultsBalance[vaults.NODE_CURRENTLY_EARNED_LSU_VAULT_ADDRESS] || '0',
|
|
207
|
+
ownerLSUsInUnlockingProcess: ownerLSUsInUnlockingProcess.toString(),
|
|
208
|
+
totalStakedXrds: vaultsBalance[vaults.NODE_TOTAL_STAKED_XRD_VAULT_ADDRESS] || '0',
|
|
209
|
+
totalXrdsLeavingOurNode: vaultsBalance[vaults.NODE_UNSTAKING_XRD_VAULT_ADDRESS] || '0',
|
|
210
|
+
unlockingLSUsBreakdown: rewardsInUnlockingProcess,
|
|
211
|
+
epoch,
|
|
212
|
+
unlockedLSUs: unlockedLSUs.toString(),
|
|
213
|
+
metadata,
|
|
214
|
+
stakeUnitAddress,
|
|
215
|
+
vaults,
|
|
216
|
+
validatorAddress,
|
|
217
|
+
fees,
|
|
218
|
+
};
|
|
219
|
+
return info;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
console.error('Error in fetchValidatorInfo', error);
|
|
224
|
+
}
|
|
225
|
+
return undefined;
|
|
226
|
+
};
|
|
227
|
+
exports.fetchValidatorInfo = fetchValidatorInfo;
|
|
228
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/validators/index.ts"],"names":[],"mappings":";;;AAKA,8CAAuD;AACvD,wCAA6D;AAU7D;;;;GAIG;AACH,MAAM,eAAe,GAAG,CACtB,QAAkC,EACV,EAAE;IAC1B,MAAM,iBAAiB,GAA2B,EAAE,CAAC;IACrD,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC9B,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC;QACxC,IACE,SAAS,KAAK,QAAQ;YACtB,SAAS,KAAK,KAAK;YACnB,SAAS,KAAK,eAAe;YAC7B,SAAS,KAAK,oBAAoB,EAClC,CAAC;YACD,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC;QACvD,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,sBAAsB,GAAG,CAAC,KAAa,EAAmB,EAAE;IAChE,IAAI,uCAAuC,GAAG,EAAE,CAAC;IACjD,IAAI,sCAAsC,GAAG,EAAE,CAAC;IAChD,IAAI,mCAAmC,GAAG,EAAE,CAAC;IAC7C,IAAI,gCAAgC,GAAG,EAAE,CAAC;IAE1C,IAAI,iBAAiB,IAAI,KAAK,EAAE,CAAC;QAC/B,mC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,KAAK;gBACL,YAAY,EAAE,YAAY,CAAC,QAAQ,EAAE;gBACrC,QAAQ;gBACR,gBAAgB;gBAChB,MAAM;gBACN,gBAAgB;gBAChB,IAAI;aACL,CAAC;YAEF,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,KAAK,CAAC,CAAC;IACtD,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AA5GW,QAAA,kBAAkB,sBA4G7B"}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "radix-utils",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Utility functions for Radix DLT blockchain development",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist/**/*"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"dev": "tsc --watch",
|
|
13
|
+
"test": "jest",
|
|
14
|
+
"lint": "eslint src/**/*.ts",
|
|
15
|
+
"format": "prettier --write src/**/*.ts",
|
|
16
|
+
"prepublishOnly": "npm run build",
|
|
17
|
+
"prepare": "npm run build"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"radix",
|
|
21
|
+
"radixdlt",
|
|
22
|
+
"blockchain",
|
|
23
|
+
"crypto",
|
|
24
|
+
"utilities",
|
|
25
|
+
"validators",
|
|
26
|
+
"staking"
|
|
27
|
+
],
|
|
28
|
+
"author": "",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": ""
|
|
33
|
+
},
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": ""
|
|
36
|
+
},
|
|
37
|
+
"homepage": "",
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@radixdlt/babylon-gateway-api-sdk": "^1.6.0",
|
|
40
|
+
"decimal.js": "^10.4.3"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/jest": "^29.5.5",
|
|
44
|
+
"@types/node": "^20.6.0",
|
|
45
|
+
"@typescript-eslint/eslint-plugin": "^6.7.0",
|
|
46
|
+
"@typescript-eslint/parser": "^6.7.0",
|
|
47
|
+
"eslint": "^8.49.0",
|
|
48
|
+
"jest": "^29.7.0",
|
|
49
|
+
"prettier": "^3.0.3",
|
|
50
|
+
"ts-jest": "^29.1.1",
|
|
51
|
+
"typescript": "^5.2.2"
|
|
52
|
+
},
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=16.0.0"
|
|
55
|
+
}
|
|
56
|
+
}
|