@paxoslabs/amplify-sdk 0.0.1-alpha.1
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/CHANGELOG.md +112 -0
- package/LICENSE +28 -0
- package/README.md +533 -0
- package/dist/amplify-sdk-api-B5hBTGrB.d.ts +258 -0
- package/dist/amplify-sdk-api-DPrRhynk.d.mts +258 -0
- package/dist/chunk-3I3PYX2F.js +45 -0
- package/dist/chunk-3I3PYX2F.js.map +1 -0
- package/dist/chunk-7RWWVUHP.mjs +39 -0
- package/dist/chunk-7RWWVUHP.mjs.map +1 -0
- package/dist/chunk-AFWUOS3M.js +15 -0
- package/dist/chunk-AFWUOS3M.js.map +1 -0
- package/dist/chunk-BDXS57YH.js +828 -0
- package/dist/chunk-BDXS57YH.js.map +1 -0
- package/dist/chunk-FYNPQXCR.mjs +46 -0
- package/dist/chunk-FYNPQXCR.mjs.map +1 -0
- package/dist/chunk-GE2VQUPP.mjs +228 -0
- package/dist/chunk-GE2VQUPP.mjs.map +1 -0
- package/dist/chunk-ICKDAKVS.js +16 -0
- package/dist/chunk-ICKDAKVS.js.map +1 -0
- package/dist/chunk-ISO6Z7LD.mjs +809 -0
- package/dist/chunk-ISO6Z7LD.mjs.map +1 -0
- package/dist/chunk-ITB7FXG4.js +14 -0
- package/dist/chunk-ITB7FXG4.js.map +1 -0
- package/dist/chunk-J3662HYT.mjs +29 -0
- package/dist/chunk-J3662HYT.mjs.map +1 -0
- package/dist/chunk-JLXNOGZB.js +2061 -0
- package/dist/chunk-JLXNOGZB.js.map +1 -0
- package/dist/chunk-O5P6SP2O.js +233 -0
- package/dist/chunk-O5P6SP2O.js.map +1 -0
- package/dist/chunk-R663BFAZ.mjs +14 -0
- package/dist/chunk-R663BFAZ.mjs.map +1 -0
- package/dist/chunk-RUIAH5HY.js +32 -0
- package/dist/chunk-RUIAH5HY.js.map +1 -0
- package/dist/chunk-SIR2TCAR.mjs +13 -0
- package/dist/chunk-SIR2TCAR.mjs.map +1 -0
- package/dist/chunk-XXHRCCZS.mjs +11 -0
- package/dist/chunk-XXHRCCZS.mjs.map +1 -0
- package/dist/chunk-ZSFIOWWT.js +49 -0
- package/dist/chunk-ZSFIOWWT.js.map +1 -0
- package/dist/chunk-ZZBZIDZP.mjs +2050 -0
- package/dist/chunk-ZZBZIDZP.mjs.map +1 -0
- package/dist/config-B-u3VqEX.d.mts +21 -0
- package/dist/config-B-u3VqEX.d.ts +21 -0
- package/dist/config-BQynVNDC.d.mts +101 -0
- package/dist/config-BQynVNDC.d.ts +101 -0
- package/dist/core.d.mts +152 -0
- package/dist/core.d.ts +152 -0
- package/dist/core.js +187 -0
- package/dist/core.js.map +1 -0
- package/dist/core.mjs +150 -0
- package/dist/core.mjs.map +1 -0
- package/dist/display.d.mts +25 -0
- package/dist/display.d.ts +25 -0
- package/dist/display.js +124 -0
- package/dist/display.js.map +1 -0
- package/dist/display.mjs +105 -0
- package/dist/display.mjs.map +1 -0
- package/dist/exchange-rate-CRA_CMaX.d.mts +65 -0
- package/dist/exchange-rate-D3_FVgqa.d.ts +65 -0
- package/dist/index.d.mts +3236 -0
- package/dist/index.d.ts +3236 -0
- package/dist/index.js +1115 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1047 -0
- package/dist/index.mjs.map +1 -0
- package/dist/utils.d.mts +111 -0
- package/dist/utils.d.ts +111 -0
- package/dist/utils.js +51 -0
- package/dist/utils.js.map +1 -0
- package/dist/utils.mjs +17 -0
- package/dist/utils.mjs.map +1 -0
- package/dist/vault-config-BNzhv3QV.d.ts +15 -0
- package/dist/vault-config-BjSE7oL8.d.mts +15 -0
- package/dist/vaults.d.mts +6 -0
- package/dist/vaults.d.ts +6 -0
- package/dist/vaults.js +13 -0
- package/dist/vaults.js.map +1 -0
- package/dist/vaults.mjs +4 -0
- package/dist/vaults.mjs.map +1 -0
- package/package.json +142 -0
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { Address } from 'viem';
|
|
2
|
+
import { Y as YieldType } from './config-B-u3VqEX.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Type definitions for Amplify SDK API integration
|
|
6
|
+
*
|
|
7
|
+
* These types define the data structures returned by the Earn SDK backend API
|
|
8
|
+
* and internal cache structures used by the SDK.
|
|
9
|
+
*
|
|
10
|
+
* @module types/amplify-sdk-api
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Vault smart contract configuration
|
|
15
|
+
*
|
|
16
|
+
* Contains all contract addresses required for vault operations:
|
|
17
|
+
* - boringVaultAddress: Main vault contract
|
|
18
|
+
* - tellerAddress: Handles deposits and withdrawals
|
|
19
|
+
* - accountantAddress: Manages accounting logic
|
|
20
|
+
* - managerAddress: Controls strategy execution
|
|
21
|
+
* - rolesAuthorityAddress: Enforces role-based access
|
|
22
|
+
* - baseTokenAddress: Deposit token address (correlation key with SupportedAsset)
|
|
23
|
+
* - baseTokenStandIn: Optional stand-in token
|
|
24
|
+
* - communityCodeDepositorAddress: Optional community depositor contract
|
|
25
|
+
*/
|
|
26
|
+
interface VaultContracts {
|
|
27
|
+
boringVaultAddress: Address;
|
|
28
|
+
tellerAddress: Address;
|
|
29
|
+
accountantAddress: Address;
|
|
30
|
+
managerAddress: Address;
|
|
31
|
+
rolesAuthorityAddress: Address;
|
|
32
|
+
baseTokenAddress: Address;
|
|
33
|
+
baseTokenStandIn?: Address;
|
|
34
|
+
communityCodeDepositorAddress?: Address;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Amplify vault configuration
|
|
38
|
+
*
|
|
39
|
+
* Represents a single vault with contract addresses, yield type, and supported deposit asset.
|
|
40
|
+
* Multiple vaults can share the same baseTokenAddress (different chains/yield types).
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const vault: AmplifyVault = {
|
|
45
|
+
* id: "config-eth-prime-001",
|
|
46
|
+
* chainId: 1,
|
|
47
|
+
* yieldType: "PRIME",
|
|
48
|
+
* vault: {
|
|
49
|
+
* boringVaultAddress: "0x8a5Fb0Eb3E1a90AF81C5DFF9f2e5D0e7b8D4E5F6",
|
|
50
|
+
* tellerAddress: "0x7B8C9D0E1F2A3B4C5D6E7F8A9B0C1D2E3F4A5B6C",
|
|
51
|
+
* accountantAddress: "0x6A7B8C9D0E1F2A3B4C5D6E7F8A9B0C1D2E3F4A5B",
|
|
52
|
+
* managerAddress: "0x5A6B7C8D9E0F1A2B3C4D5E6F7A8B9C0D1E2F3A4B",
|
|
53
|
+
* rolesAuthorityAddress: "0x4A5B6C7D8E9F0A1B2C3D4E5F6A7B8C9D0E1F2A3B",
|
|
54
|
+
* baseTokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
|
|
55
|
+
* },
|
|
56
|
+
* supportedAssets: {
|
|
57
|
+
* address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
58
|
+
* symbol: "USDC",
|
|
59
|
+
* name: "USD Coin",
|
|
60
|
+
* decimals: 6,
|
|
61
|
+
* coinGeckoTokenId: "usd-coin"
|
|
62
|
+
* }
|
|
63
|
+
* };
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
interface AmplifyVault {
|
|
67
|
+
/** Unique identifier for the vault configuration */
|
|
68
|
+
id: string;
|
|
69
|
+
/** Chain ID where the vault is deployed (e.g., 1 for Ethereum) */
|
|
70
|
+
chainId: number;
|
|
71
|
+
/** Yield strategy type */
|
|
72
|
+
yieldType: YieldType;
|
|
73
|
+
/** Vault smart contract addresses */
|
|
74
|
+
vault: VaultContracts;
|
|
75
|
+
/** Supported deposit asset for this vault */
|
|
76
|
+
supportedAssets: {
|
|
77
|
+
/** Token contract address */
|
|
78
|
+
address: Address;
|
|
79
|
+
/** Token symbol (e.g., USDC, USDT) */
|
|
80
|
+
symbol: string;
|
|
81
|
+
/** Full token name (e.g., USD Coin) */
|
|
82
|
+
name: string;
|
|
83
|
+
/** Number of decimal places (e.g., 6 for USDC, 18 for DAI) */
|
|
84
|
+
decimals: number;
|
|
85
|
+
/** CoinGecko token identifier for price lookups */
|
|
86
|
+
coinGeckoTokenId?: string;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Supported asset (token) metadata
|
|
91
|
+
*
|
|
92
|
+
* Represents a cryptocurrency token with metadata and chain support.
|
|
93
|
+
* Joins with AmplifyVault via address == AmplifyVault.vault.baseTokenAddress
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const asset: SupportedAsset = {
|
|
98
|
+
* address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
99
|
+
* symbol: "USDC",
|
|
100
|
+
* name: "USD Coin",
|
|
101
|
+
* decimals: 6,
|
|
102
|
+
* coinGeckoTokenId: "usd-coin",
|
|
103
|
+
* chains: [1, 137, 8453, 42161]
|
|
104
|
+
* };
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
interface SupportedAsset {
|
|
108
|
+
/** Token contract address (correlation key with AmplifyVault.vault.baseTokenAddress) */
|
|
109
|
+
address: Address;
|
|
110
|
+
/** Token symbol (e.g., USDC, USDT) */
|
|
111
|
+
symbol: string;
|
|
112
|
+
/** Full token name (e.g., USD Coin) */
|
|
113
|
+
name: string;
|
|
114
|
+
/** Number of decimal places (e.g., 6 for USDC, 18 for DAI) */
|
|
115
|
+
decimals: number;
|
|
116
|
+
/** CoinGecko token identifier for price lookups */
|
|
117
|
+
coinGeckoTokenId?: string;
|
|
118
|
+
/** Array of chain IDs where this token is supported */
|
|
119
|
+
chains: number[];
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Filter options for vault queries
|
|
123
|
+
*
|
|
124
|
+
* Used to filter vaults by chain, yield type, or deposit token.
|
|
125
|
+
* All filters are optional and can be combined.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* // Get all PRIME vaults on Ethereum
|
|
130
|
+
* const options: VaultFilterOptions = {
|
|
131
|
+
* chainId: 1,
|
|
132
|
+
* yieldType: "PRIME"
|
|
133
|
+
* };
|
|
134
|
+
*
|
|
135
|
+
* // Get all vaults accepting USDC
|
|
136
|
+
* const usdcOptions: VaultFilterOptions = {
|
|
137
|
+
* depositTokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
|
|
138
|
+
* };
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
interface VaultFilterOptions {
|
|
142
|
+
/** Filter by chain ID */
|
|
143
|
+
chainId?: number;
|
|
144
|
+
/** Filter by yield type */
|
|
145
|
+
yieldType?: YieldType;
|
|
146
|
+
/** Filter by deposit token address */
|
|
147
|
+
depositTokenAddress?: string;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Filter options for asset queries
|
|
151
|
+
*
|
|
152
|
+
* Used to filter supported assets by chain IDs, yield type, address, or symbol.
|
|
153
|
+
* All filters are optional and can be combined.
|
|
154
|
+
*
|
|
155
|
+
* Note: API endpoints only support `chains` and `yieldType` parameters.
|
|
156
|
+
* The `address` and `symbol` filters are only applied in cache-layer filtering.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* // Get all assets supported on Ethereum and Base (API call)
|
|
161
|
+
* const options: AssetFilterOptions = {
|
|
162
|
+
* chains: [1, 8453]
|
|
163
|
+
* };
|
|
164
|
+
*
|
|
165
|
+
* // Get PRIME yield type assets (API call)
|
|
166
|
+
* const primeOptions: AssetFilterOptions = {
|
|
167
|
+
* yieldType: "PRIME"
|
|
168
|
+
* };
|
|
169
|
+
*
|
|
170
|
+
* // Filter by address (cache-only)
|
|
171
|
+
* const usdcOptions: AssetFilterOptions = {
|
|
172
|
+
* address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
|
|
173
|
+
* };
|
|
174
|
+
*
|
|
175
|
+
* // Filter by symbol (cache-only)
|
|
176
|
+
* const symbolOptions: AssetFilterOptions = {
|
|
177
|
+
* symbol: "USDC"
|
|
178
|
+
* };
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
interface AssetFilterOptions {
|
|
182
|
+
/** Filter by chain IDs (API + cache: assets with these chains in chains array) */
|
|
183
|
+
chains?: number[];
|
|
184
|
+
/** Filter by yield type (API + cache: PRIME, TBILL, or LENDING) */
|
|
185
|
+
yieldType?: YieldType;
|
|
186
|
+
/** Filter by token address (cache-only: exact address match) */
|
|
187
|
+
address?: string;
|
|
188
|
+
/** Filter by token symbol (cache-only: exact symbol match) */
|
|
189
|
+
symbol?: string;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* API error with descriptive messages
|
|
193
|
+
*
|
|
194
|
+
* Thrown when API requests fail due to network errors, server errors,
|
|
195
|
+
* or malformed responses.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* throw new APIError("Failed to fetch vaults: Network timeout", {
|
|
200
|
+
* statusCode: 408,
|
|
201
|
+
* endpoint: "/v1/earn-sdk/vaults"
|
|
202
|
+
* });
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
declare class APIError extends Error {
|
|
206
|
+
/**
|
|
207
|
+
* HTTP status code (if available)
|
|
208
|
+
*/
|
|
209
|
+
statusCode?: number;
|
|
210
|
+
/**
|
|
211
|
+
* API endpoint that failed
|
|
212
|
+
*/
|
|
213
|
+
endpoint?: string;
|
|
214
|
+
/**
|
|
215
|
+
* Original error cause
|
|
216
|
+
*/
|
|
217
|
+
cause?: unknown;
|
|
218
|
+
constructor(message: string, options?: {
|
|
219
|
+
statusCode?: number;
|
|
220
|
+
endpoint?: string;
|
|
221
|
+
cause?: unknown;
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Supported asset information for withdrawal
|
|
226
|
+
*
|
|
227
|
+
* Asset grouped with available vaults that support withdrawal of that asset.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```typescript
|
|
231
|
+
* const asset: WithdrawSupportedAsset = {
|
|
232
|
+
* address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
233
|
+
* symbol: "USDC",
|
|
234
|
+
* decimals: 6,
|
|
235
|
+
* vaults: [
|
|
236
|
+
* { id: "prime-usdc-eth", yieldType: "PRIME", chainId: 1, vaultId: "..." },
|
|
237
|
+
* { id: "prime-usdc-boba", yieldType: "PRIME", chainId: 288, vaultId: "..." },
|
|
238
|
+
* ],
|
|
239
|
+
* };
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
interface WithdrawSupportedAsset {
|
|
243
|
+
/** Token contract address */
|
|
244
|
+
address: Address;
|
|
245
|
+
/** Token symbol (e.g., "USDC", "ETH") */
|
|
246
|
+
symbol: string;
|
|
247
|
+
/** Number of decimal places for this token */
|
|
248
|
+
decimals: number;
|
|
249
|
+
/** Array of vaults that support withdrawals of this asset */
|
|
250
|
+
vaults: Array<{
|
|
251
|
+
id: string;
|
|
252
|
+
yieldType: YieldType;
|
|
253
|
+
chainId: number;
|
|
254
|
+
vaultId: string;
|
|
255
|
+
}>;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export { type AmplifyVault as A, type SupportedAsset as S, type VaultFilterOptions as V, type WithdrawSupportedAsset as W, type AssetFilterOptions as a, APIError as b };
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { Address } from 'viem';
|
|
2
|
+
import { Y as YieldType } from './config-B-u3VqEX.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Type definitions for Amplify SDK API integration
|
|
6
|
+
*
|
|
7
|
+
* These types define the data structures returned by the Earn SDK backend API
|
|
8
|
+
* and internal cache structures used by the SDK.
|
|
9
|
+
*
|
|
10
|
+
* @module types/amplify-sdk-api
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Vault smart contract configuration
|
|
15
|
+
*
|
|
16
|
+
* Contains all contract addresses required for vault operations:
|
|
17
|
+
* - boringVaultAddress: Main vault contract
|
|
18
|
+
* - tellerAddress: Handles deposits and withdrawals
|
|
19
|
+
* - accountantAddress: Manages accounting logic
|
|
20
|
+
* - managerAddress: Controls strategy execution
|
|
21
|
+
* - rolesAuthorityAddress: Enforces role-based access
|
|
22
|
+
* - baseTokenAddress: Deposit token address (correlation key with SupportedAsset)
|
|
23
|
+
* - baseTokenStandIn: Optional stand-in token
|
|
24
|
+
* - communityCodeDepositorAddress: Optional community depositor contract
|
|
25
|
+
*/
|
|
26
|
+
interface VaultContracts {
|
|
27
|
+
boringVaultAddress: Address;
|
|
28
|
+
tellerAddress: Address;
|
|
29
|
+
accountantAddress: Address;
|
|
30
|
+
managerAddress: Address;
|
|
31
|
+
rolesAuthorityAddress: Address;
|
|
32
|
+
baseTokenAddress: Address;
|
|
33
|
+
baseTokenStandIn?: Address;
|
|
34
|
+
communityCodeDepositorAddress?: Address;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Amplify vault configuration
|
|
38
|
+
*
|
|
39
|
+
* Represents a single vault with contract addresses, yield type, and supported deposit asset.
|
|
40
|
+
* Multiple vaults can share the same baseTokenAddress (different chains/yield types).
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const vault: AmplifyVault = {
|
|
45
|
+
* id: "config-eth-prime-001",
|
|
46
|
+
* chainId: 1,
|
|
47
|
+
* yieldType: "PRIME",
|
|
48
|
+
* vault: {
|
|
49
|
+
* boringVaultAddress: "0x8a5Fb0Eb3E1a90AF81C5DFF9f2e5D0e7b8D4E5F6",
|
|
50
|
+
* tellerAddress: "0x7B8C9D0E1F2A3B4C5D6E7F8A9B0C1D2E3F4A5B6C",
|
|
51
|
+
* accountantAddress: "0x6A7B8C9D0E1F2A3B4C5D6E7F8A9B0C1D2E3F4A5B",
|
|
52
|
+
* managerAddress: "0x5A6B7C8D9E0F1A2B3C4D5E6F7A8B9C0D1E2F3A4B",
|
|
53
|
+
* rolesAuthorityAddress: "0x4A5B6C7D8E9F0A1B2C3D4E5F6A7B8C9D0E1F2A3B",
|
|
54
|
+
* baseTokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
|
|
55
|
+
* },
|
|
56
|
+
* supportedAssets: {
|
|
57
|
+
* address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
58
|
+
* symbol: "USDC",
|
|
59
|
+
* name: "USD Coin",
|
|
60
|
+
* decimals: 6,
|
|
61
|
+
* coinGeckoTokenId: "usd-coin"
|
|
62
|
+
* }
|
|
63
|
+
* };
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
interface AmplifyVault {
|
|
67
|
+
/** Unique identifier for the vault configuration */
|
|
68
|
+
id: string;
|
|
69
|
+
/** Chain ID where the vault is deployed (e.g., 1 for Ethereum) */
|
|
70
|
+
chainId: number;
|
|
71
|
+
/** Yield strategy type */
|
|
72
|
+
yieldType: YieldType;
|
|
73
|
+
/** Vault smart contract addresses */
|
|
74
|
+
vault: VaultContracts;
|
|
75
|
+
/** Supported deposit asset for this vault */
|
|
76
|
+
supportedAssets: {
|
|
77
|
+
/** Token contract address */
|
|
78
|
+
address: Address;
|
|
79
|
+
/** Token symbol (e.g., USDC, USDT) */
|
|
80
|
+
symbol: string;
|
|
81
|
+
/** Full token name (e.g., USD Coin) */
|
|
82
|
+
name: string;
|
|
83
|
+
/** Number of decimal places (e.g., 6 for USDC, 18 for DAI) */
|
|
84
|
+
decimals: number;
|
|
85
|
+
/** CoinGecko token identifier for price lookups */
|
|
86
|
+
coinGeckoTokenId?: string;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Supported asset (token) metadata
|
|
91
|
+
*
|
|
92
|
+
* Represents a cryptocurrency token with metadata and chain support.
|
|
93
|
+
* Joins with AmplifyVault via address == AmplifyVault.vault.baseTokenAddress
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const asset: SupportedAsset = {
|
|
98
|
+
* address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
99
|
+
* symbol: "USDC",
|
|
100
|
+
* name: "USD Coin",
|
|
101
|
+
* decimals: 6,
|
|
102
|
+
* coinGeckoTokenId: "usd-coin",
|
|
103
|
+
* chains: [1, 137, 8453, 42161]
|
|
104
|
+
* };
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
interface SupportedAsset {
|
|
108
|
+
/** Token contract address (correlation key with AmplifyVault.vault.baseTokenAddress) */
|
|
109
|
+
address: Address;
|
|
110
|
+
/** Token symbol (e.g., USDC, USDT) */
|
|
111
|
+
symbol: string;
|
|
112
|
+
/** Full token name (e.g., USD Coin) */
|
|
113
|
+
name: string;
|
|
114
|
+
/** Number of decimal places (e.g., 6 for USDC, 18 for DAI) */
|
|
115
|
+
decimals: number;
|
|
116
|
+
/** CoinGecko token identifier for price lookups */
|
|
117
|
+
coinGeckoTokenId?: string;
|
|
118
|
+
/** Array of chain IDs where this token is supported */
|
|
119
|
+
chains: number[];
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Filter options for vault queries
|
|
123
|
+
*
|
|
124
|
+
* Used to filter vaults by chain, yield type, or deposit token.
|
|
125
|
+
* All filters are optional and can be combined.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* // Get all PRIME vaults on Ethereum
|
|
130
|
+
* const options: VaultFilterOptions = {
|
|
131
|
+
* chainId: 1,
|
|
132
|
+
* yieldType: "PRIME"
|
|
133
|
+
* };
|
|
134
|
+
*
|
|
135
|
+
* // Get all vaults accepting USDC
|
|
136
|
+
* const usdcOptions: VaultFilterOptions = {
|
|
137
|
+
* depositTokenAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
|
|
138
|
+
* };
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
interface VaultFilterOptions {
|
|
142
|
+
/** Filter by chain ID */
|
|
143
|
+
chainId?: number;
|
|
144
|
+
/** Filter by yield type */
|
|
145
|
+
yieldType?: YieldType;
|
|
146
|
+
/** Filter by deposit token address */
|
|
147
|
+
depositTokenAddress?: string;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Filter options for asset queries
|
|
151
|
+
*
|
|
152
|
+
* Used to filter supported assets by chain IDs, yield type, address, or symbol.
|
|
153
|
+
* All filters are optional and can be combined.
|
|
154
|
+
*
|
|
155
|
+
* Note: API endpoints only support `chains` and `yieldType` parameters.
|
|
156
|
+
* The `address` and `symbol` filters are only applied in cache-layer filtering.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```typescript
|
|
160
|
+
* // Get all assets supported on Ethereum and Base (API call)
|
|
161
|
+
* const options: AssetFilterOptions = {
|
|
162
|
+
* chains: [1, 8453]
|
|
163
|
+
* };
|
|
164
|
+
*
|
|
165
|
+
* // Get PRIME yield type assets (API call)
|
|
166
|
+
* const primeOptions: AssetFilterOptions = {
|
|
167
|
+
* yieldType: "PRIME"
|
|
168
|
+
* };
|
|
169
|
+
*
|
|
170
|
+
* // Filter by address (cache-only)
|
|
171
|
+
* const usdcOptions: AssetFilterOptions = {
|
|
172
|
+
* address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
|
|
173
|
+
* };
|
|
174
|
+
*
|
|
175
|
+
* // Filter by symbol (cache-only)
|
|
176
|
+
* const symbolOptions: AssetFilterOptions = {
|
|
177
|
+
* symbol: "USDC"
|
|
178
|
+
* };
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
interface AssetFilterOptions {
|
|
182
|
+
/** Filter by chain IDs (API + cache: assets with these chains in chains array) */
|
|
183
|
+
chains?: number[];
|
|
184
|
+
/** Filter by yield type (API + cache: PRIME, TBILL, or LENDING) */
|
|
185
|
+
yieldType?: YieldType;
|
|
186
|
+
/** Filter by token address (cache-only: exact address match) */
|
|
187
|
+
address?: string;
|
|
188
|
+
/** Filter by token symbol (cache-only: exact symbol match) */
|
|
189
|
+
symbol?: string;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* API error with descriptive messages
|
|
193
|
+
*
|
|
194
|
+
* Thrown when API requests fail due to network errors, server errors,
|
|
195
|
+
* or malformed responses.
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* ```typescript
|
|
199
|
+
* throw new APIError("Failed to fetch vaults: Network timeout", {
|
|
200
|
+
* statusCode: 408,
|
|
201
|
+
* endpoint: "/v1/earn-sdk/vaults"
|
|
202
|
+
* });
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
declare class APIError extends Error {
|
|
206
|
+
/**
|
|
207
|
+
* HTTP status code (if available)
|
|
208
|
+
*/
|
|
209
|
+
statusCode?: number;
|
|
210
|
+
/**
|
|
211
|
+
* API endpoint that failed
|
|
212
|
+
*/
|
|
213
|
+
endpoint?: string;
|
|
214
|
+
/**
|
|
215
|
+
* Original error cause
|
|
216
|
+
*/
|
|
217
|
+
cause?: unknown;
|
|
218
|
+
constructor(message: string, options?: {
|
|
219
|
+
statusCode?: number;
|
|
220
|
+
endpoint?: string;
|
|
221
|
+
cause?: unknown;
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Supported asset information for withdrawal
|
|
226
|
+
*
|
|
227
|
+
* Asset grouped with available vaults that support withdrawal of that asset.
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```typescript
|
|
231
|
+
* const asset: WithdrawSupportedAsset = {
|
|
232
|
+
* address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
|
|
233
|
+
* symbol: "USDC",
|
|
234
|
+
* decimals: 6,
|
|
235
|
+
* vaults: [
|
|
236
|
+
* { id: "prime-usdc-eth", yieldType: "PRIME", chainId: 1, vaultId: "..." },
|
|
237
|
+
* { id: "prime-usdc-boba", yieldType: "PRIME", chainId: 288, vaultId: "..." },
|
|
238
|
+
* ],
|
|
239
|
+
* };
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
interface WithdrawSupportedAsset {
|
|
243
|
+
/** Token contract address */
|
|
244
|
+
address: Address;
|
|
245
|
+
/** Token symbol (e.g., "USDC", "ETH") */
|
|
246
|
+
symbol: string;
|
|
247
|
+
/** Number of decimal places for this token */
|
|
248
|
+
decimals: number;
|
|
249
|
+
/** Array of vaults that support withdrawals of this asset */
|
|
250
|
+
vaults: Array<{
|
|
251
|
+
id: string;
|
|
252
|
+
yieldType: YieldType;
|
|
253
|
+
chainId: number;
|
|
254
|
+
vaultId: string;
|
|
255
|
+
}>;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export { type AmplifyVault as A, type SupportedAsset as S, type VaultFilterOptions as V, type WithdrawSupportedAsset as W, type AssetFilterOptions as a, APIError as b };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var viem = require('viem');
|
|
4
|
+
|
|
5
|
+
// src/utils/bigint.ts
|
|
6
|
+
var RAY = {
|
|
7
|
+
bigint: BigInt(1e27),
|
|
8
|
+
number: 1e27
|
|
9
|
+
};
|
|
10
|
+
var WAD = {
|
|
11
|
+
bigint: BigInt(1e18),
|
|
12
|
+
number: 1e18
|
|
13
|
+
};
|
|
14
|
+
function bigIntToNumberAsString(value, opts = {}) {
|
|
15
|
+
const {
|
|
16
|
+
decimals = 18,
|
|
17
|
+
minimumFractionDigits = 0,
|
|
18
|
+
maximumFractionDigits = 3
|
|
19
|
+
} = opts;
|
|
20
|
+
const numberValue = Number.parseFloat(viem.formatUnits(value, decimals));
|
|
21
|
+
return new Intl.NumberFormat("en-US", {
|
|
22
|
+
minimumFractionDigits,
|
|
23
|
+
maximumFractionDigits
|
|
24
|
+
}).format(numberValue);
|
|
25
|
+
}
|
|
26
|
+
function calculateExpectedSharesMinted(depositAmount, rateInQuote, shareDecimals) {
|
|
27
|
+
const ONE_SHARE = BigInt(10) ** BigInt(shareDecimals);
|
|
28
|
+
const sharesMinted = depositAmount * ONE_SHARE / rateInQuote;
|
|
29
|
+
return sharesMinted;
|
|
30
|
+
}
|
|
31
|
+
function calculateAtomicPrice(rateInQuote, slippage) {
|
|
32
|
+
const basisPoints = 1e4;
|
|
33
|
+
const slippageInBasisPoints = Math.floor(slippage * basisPoints);
|
|
34
|
+
const percentageToKeep = basisPoints - slippageInBasisPoints;
|
|
35
|
+
const atomicPrice = rateInQuote * BigInt(percentageToKeep) / BigInt(basisPoints);
|
|
36
|
+
return atomicPrice;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
exports.RAY = RAY;
|
|
40
|
+
exports.WAD = WAD;
|
|
41
|
+
exports.bigIntToNumberAsString = bigIntToNumberAsString;
|
|
42
|
+
exports.calculateAtomicPrice = calculateAtomicPrice;
|
|
43
|
+
exports.calculateExpectedSharesMinted = calculateExpectedSharesMinted;
|
|
44
|
+
//# sourceMappingURL=chunk-3I3PYX2F.js.map
|
|
45
|
+
//# sourceMappingURL=chunk-3I3PYX2F.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/bigint.ts"],"names":["formatUnits"],"mappings":";;;;;AAUO,IAAM,GAAA,GAAM;AAAA,EACjB,MAAA,EAAQ,OAAO,IAAI,CAAA;AAAA,EACnB,MAAA,EAAQ;AACV;AAOO,IAAM,GAAA,GAAM;AAAA,EACjB,MAAA,EAAQ,OAAO,IAAI,CAAA;AAAA,EACnB,MAAA,EAAQ;AACV;AAgBO,SAAS,sBAAA,CACd,KAAA,EACA,IAAA,GAII,EAAC,EACG;AACR,EAAA,MAAM;AAAA,IACJ,QAAA,GAAW,EAAA;AAAA,IACX,qBAAA,GAAwB,CAAA;AAAA,IACxB,qBAAA,GAAwB;AAAA,GAC1B,GAAI,IAAA;AACJ,EAAA,MAAM,cAAc,MAAA,CAAO,UAAA,CAAWA,gBAAA,CAAY,KAAA,EAAO,QAAQ,CAAC,CAAA;AAClE,EAAA,OAAO,IAAI,IAAA,CAAK,YAAA,CAAa,OAAA,EAAS;AAAA,IACpC,qBAAA;AAAA,IACA;AAAA,GACD,CAAA,CAAE,MAAA,CAAO,WAAW,CAAA;AACvB;AAaO,SAAS,6BAAA,CACd,aAAA,EACA,WAAA,EACA,aAAA,EACQ;AAER,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,EAAE,CAAA,IAAK,OAAO,aAAa,CAAA;AAIpD,EAAA,MAAM,YAAA,GAAgB,gBAAgB,SAAA,GAAa,WAAA;AAEnD,EAAA,OAAO,YAAA;AACT;AAYO,SAAS,oBAAA,CACd,aACA,QAAA,EACQ;AAGR,EAAA,MAAM,WAAA,GAAc,GAAA;AACpB,EAAA,MAAM,qBAAA,GAAwB,IAAA,CAAK,KAAA,CAAM,QAAA,GAAW,WAAW,CAAA;AAC/D,EAAA,MAAM,mBAAmB,WAAA,GAAc,qBAAA;AAIvC,EAAA,MAAM,cACH,WAAA,GAAc,MAAA,CAAO,gBAAgB,CAAA,GAAK,OAAO,WAAW,CAAA;AAE/D,EAAA,OAAO,WAAA;AACT","file":"chunk-3I3PYX2F.js","sourcesContent":["/**\n * @fileoverview Utilities for working with bigint values and fixed-point math\n */\nimport { formatUnits } from \"viem\";\n\n/**\n * RAY precision unit (10^27)\n * Used for high precision fixed-point calculations\n * @type {{bigint: bigint, number: number}}\n */\nexport const RAY = {\n bigint: BigInt(1e27),\n number: 1e27,\n};\n\n/**\n * WAD precision unit (10^18)\n * Common precision unit for Ethereum tokens (matches ETH's 18 decimals)\n * @type {{bigint: bigint, number: number}}\n */\nexport const WAD = {\n bigint: BigInt(1e18),\n number: 1e18,\n};\n\n/**\n * Converts a bigint value to a formatted number string with specified decimal precision\n *\n * @param {bigint} value - The bigint value to convert\n * @param {Object} opts - Formatting options\n * @param {number} [opts.decimals=18] - Number of decimals to use when converting from bigint\n * @param {number} [opts.minimumFractionDigits=0] - Minimum number of fraction digits to display\n * @param {number} [opts.maximumFractionDigits=3] - Maximum number of fraction digits to display\n * @returns {string} The formatted number as a string\n *\n * @example\n * // Returns \"123.456\"\n * bigIntToNumberAsString(BigInt(\"123456000000000000000\"), { decimals: 18 })\n */\nexport function bigIntToNumberAsString(\n value: bigint,\n opts: {\n decimals?: number;\n minimumFractionDigits?: number;\n maximumFractionDigits?: number;\n } = {}\n): string {\n const {\n decimals = 18,\n minimumFractionDigits = 0,\n maximumFractionDigits = 3,\n } = opts;\n const numberValue = Number.parseFloat(formatUnits(value, decimals));\n return new Intl.NumberFormat(\"en-US\", {\n minimumFractionDigits: minimumFractionDigits,\n maximumFractionDigits: maximumFractionDigits,\n }).format(numberValue);\n}\n\n/**\n * Calculates the expected amount of shares to be minted based on deposit amount and rate\n *\n * The calculation follows the formula:\n * sharesMinted = depositAmount * ONE_SHARE / rateInQuote\n *\n * @param {bigint} depositAmount - The amount to deposit in quote asset decimals\n * @param {bigint} rateInQuote - The rate in quote representing \"quote asset per share\"\n * @param {number} shareDecimals - The decimal precision of the BoringVault shares (ONE_SHARE)\n * @returns {bigint} The expected amount of shares to be minted\n */\nexport function calculateExpectedSharesMinted(\n depositAmount: bigint,\n rateInQuote: bigint,\n shareDecimals: number\n): bigint {\n // Calculate ONE_SHARE based on the vault's share decimals\n const ONE_SHARE = BigInt(10) ** BigInt(shareDecimals);\n\n // Calculate shares minted using the formula:\n // sharesMinted = depositAmount * ONE_SHARE / rateInQuote\n const sharesMinted = (depositAmount * ONE_SHARE) / rateInQuote;\n\n return sharesMinted;\n}\n\n/**\n * Calculates the atomic price with slippage applied\n * The calculation follows the formula:\n * atomicPrice = rateInQuote * (1 - slippage)\n *\n * @param {bigint} rateInQuote - The rate in quote representing \"quote asset per share\"\n * @param {number} slippage - The maximum acceptable slippage as a decimal (e.g., 0.01 for 1%)\n * @param {number} quoteDecimals - The decimal precision of the quote asset\n * @returns {bigint} The atomic price with slippage applied\n */\nexport function calculateAtomicPrice(\n rateInQuote: bigint,\n slippage: number\n): bigint {\n // Convert slippage to basis points (1% = 100 basis points = 0.01)\n // Multiply by 10000 to get precision and subtract from 10000 to get the percentage to keep\n const basisPoints = 10000;\n const slippageInBasisPoints = Math.floor(slippage * basisPoints);\n const percentageToKeep = basisPoints - slippageInBasisPoints;\n\n // Calculate atomic price using fixed point arithmetic:\n // atomicPrice = rateInQuote * percentageToKeep / basisPoints\n const atomicPrice =\n (rateInQuote * BigInt(percentageToKeep)) / BigInt(basisPoints);\n\n return atomicPrice;\n}\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { formatUnits } from 'viem';
|
|
2
|
+
|
|
3
|
+
// src/utils/bigint.ts
|
|
4
|
+
var RAY = {
|
|
5
|
+
bigint: BigInt(1e27),
|
|
6
|
+
number: 1e27
|
|
7
|
+
};
|
|
8
|
+
var WAD = {
|
|
9
|
+
bigint: BigInt(1e18),
|
|
10
|
+
number: 1e18
|
|
11
|
+
};
|
|
12
|
+
function bigIntToNumberAsString(value, opts = {}) {
|
|
13
|
+
const {
|
|
14
|
+
decimals = 18,
|
|
15
|
+
minimumFractionDigits = 0,
|
|
16
|
+
maximumFractionDigits = 3
|
|
17
|
+
} = opts;
|
|
18
|
+
const numberValue = Number.parseFloat(formatUnits(value, decimals));
|
|
19
|
+
return new Intl.NumberFormat("en-US", {
|
|
20
|
+
minimumFractionDigits,
|
|
21
|
+
maximumFractionDigits
|
|
22
|
+
}).format(numberValue);
|
|
23
|
+
}
|
|
24
|
+
function calculateExpectedSharesMinted(depositAmount, rateInQuote, shareDecimals) {
|
|
25
|
+
const ONE_SHARE = BigInt(10) ** BigInt(shareDecimals);
|
|
26
|
+
const sharesMinted = depositAmount * ONE_SHARE / rateInQuote;
|
|
27
|
+
return sharesMinted;
|
|
28
|
+
}
|
|
29
|
+
function calculateAtomicPrice(rateInQuote, slippage) {
|
|
30
|
+
const basisPoints = 1e4;
|
|
31
|
+
const slippageInBasisPoints = Math.floor(slippage * basisPoints);
|
|
32
|
+
const percentageToKeep = basisPoints - slippageInBasisPoints;
|
|
33
|
+
const atomicPrice = rateInQuote * BigInt(percentageToKeep) / BigInt(basisPoints);
|
|
34
|
+
return atomicPrice;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { RAY, WAD, bigIntToNumberAsString, calculateAtomicPrice, calculateExpectedSharesMinted };
|
|
38
|
+
//# sourceMappingURL=chunk-7RWWVUHP.mjs.map
|
|
39
|
+
//# sourceMappingURL=chunk-7RWWVUHP.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/bigint.ts"],"names":[],"mappings":";;;AAUO,IAAM,GAAA,GAAM;AAAA,EACjB,MAAA,EAAQ,OAAO,IAAI,CAAA;AAAA,EACnB,MAAA,EAAQ;AACV;AAOO,IAAM,GAAA,GAAM;AAAA,EACjB,MAAA,EAAQ,OAAO,IAAI,CAAA;AAAA,EACnB,MAAA,EAAQ;AACV;AAgBO,SAAS,sBAAA,CACd,KAAA,EACA,IAAA,GAII,EAAC,EACG;AACR,EAAA,MAAM;AAAA,IACJ,QAAA,GAAW,EAAA;AAAA,IACX,qBAAA,GAAwB,CAAA;AAAA,IACxB,qBAAA,GAAwB;AAAA,GAC1B,GAAI,IAAA;AACJ,EAAA,MAAM,cAAc,MAAA,CAAO,UAAA,CAAW,WAAA,CAAY,KAAA,EAAO,QAAQ,CAAC,CAAA;AAClE,EAAA,OAAO,IAAI,IAAA,CAAK,YAAA,CAAa,OAAA,EAAS;AAAA,IACpC,qBAAA;AAAA,IACA;AAAA,GACD,CAAA,CAAE,MAAA,CAAO,WAAW,CAAA;AACvB;AAaO,SAAS,6BAAA,CACd,aAAA,EACA,WAAA,EACA,aAAA,EACQ;AAER,EAAA,MAAM,SAAA,GAAY,MAAA,CAAO,EAAE,CAAA,IAAK,OAAO,aAAa,CAAA;AAIpD,EAAA,MAAM,YAAA,GAAgB,gBAAgB,SAAA,GAAa,WAAA;AAEnD,EAAA,OAAO,YAAA;AACT;AAYO,SAAS,oBAAA,CACd,aACA,QAAA,EACQ;AAGR,EAAA,MAAM,WAAA,GAAc,GAAA;AACpB,EAAA,MAAM,qBAAA,GAAwB,IAAA,CAAK,KAAA,CAAM,QAAA,GAAW,WAAW,CAAA;AAC/D,EAAA,MAAM,mBAAmB,WAAA,GAAc,qBAAA;AAIvC,EAAA,MAAM,cACH,WAAA,GAAc,MAAA,CAAO,gBAAgB,CAAA,GAAK,OAAO,WAAW,CAAA;AAE/D,EAAA,OAAO,WAAA;AACT","file":"chunk-7RWWVUHP.mjs","sourcesContent":["/**\n * @fileoverview Utilities for working with bigint values and fixed-point math\n */\nimport { formatUnits } from \"viem\";\n\n/**\n * RAY precision unit (10^27)\n * Used for high precision fixed-point calculations\n * @type {{bigint: bigint, number: number}}\n */\nexport const RAY = {\n bigint: BigInt(1e27),\n number: 1e27,\n};\n\n/**\n * WAD precision unit (10^18)\n * Common precision unit for Ethereum tokens (matches ETH's 18 decimals)\n * @type {{bigint: bigint, number: number}}\n */\nexport const WAD = {\n bigint: BigInt(1e18),\n number: 1e18,\n};\n\n/**\n * Converts a bigint value to a formatted number string with specified decimal precision\n *\n * @param {bigint} value - The bigint value to convert\n * @param {Object} opts - Formatting options\n * @param {number} [opts.decimals=18] - Number of decimals to use when converting from bigint\n * @param {number} [opts.minimumFractionDigits=0] - Minimum number of fraction digits to display\n * @param {number} [opts.maximumFractionDigits=3] - Maximum number of fraction digits to display\n * @returns {string} The formatted number as a string\n *\n * @example\n * // Returns \"123.456\"\n * bigIntToNumberAsString(BigInt(\"123456000000000000000\"), { decimals: 18 })\n */\nexport function bigIntToNumberAsString(\n value: bigint,\n opts: {\n decimals?: number;\n minimumFractionDigits?: number;\n maximumFractionDigits?: number;\n } = {}\n): string {\n const {\n decimals = 18,\n minimumFractionDigits = 0,\n maximumFractionDigits = 3,\n } = opts;\n const numberValue = Number.parseFloat(formatUnits(value, decimals));\n return new Intl.NumberFormat(\"en-US\", {\n minimumFractionDigits: minimumFractionDigits,\n maximumFractionDigits: maximumFractionDigits,\n }).format(numberValue);\n}\n\n/**\n * Calculates the expected amount of shares to be minted based on deposit amount and rate\n *\n * The calculation follows the formula:\n * sharesMinted = depositAmount * ONE_SHARE / rateInQuote\n *\n * @param {bigint} depositAmount - The amount to deposit in quote asset decimals\n * @param {bigint} rateInQuote - The rate in quote representing \"quote asset per share\"\n * @param {number} shareDecimals - The decimal precision of the BoringVault shares (ONE_SHARE)\n * @returns {bigint} The expected amount of shares to be minted\n */\nexport function calculateExpectedSharesMinted(\n depositAmount: bigint,\n rateInQuote: bigint,\n shareDecimals: number\n): bigint {\n // Calculate ONE_SHARE based on the vault's share decimals\n const ONE_SHARE = BigInt(10) ** BigInt(shareDecimals);\n\n // Calculate shares minted using the formula:\n // sharesMinted = depositAmount * ONE_SHARE / rateInQuote\n const sharesMinted = (depositAmount * ONE_SHARE) / rateInQuote;\n\n return sharesMinted;\n}\n\n/**\n * Calculates the atomic price with slippage applied\n * The calculation follows the formula:\n * atomicPrice = rateInQuote * (1 - slippage)\n *\n * @param {bigint} rateInQuote - The rate in quote representing \"quote asset per share\"\n * @param {number} slippage - The maximum acceptable slippage as a decimal (e.g., 0.01 for 1%)\n * @param {number} quoteDecimals - The decimal precision of the quote asset\n * @returns {bigint} The atomic price with slippage applied\n */\nexport function calculateAtomicPrice(\n rateInQuote: bigint,\n slippage: number\n): bigint {\n // Convert slippage to basis points (1% = 100 basis points = 0.01)\n // Multiply by 10000 to get precision and subtract from 10000 to get the percentage to keep\n const basisPoints = 10000;\n const slippageInBasisPoints = Math.floor(slippage * basisPoints);\n const percentageToKeep = basisPoints - slippageInBasisPoints;\n\n // Calculate atomic price using fixed point arithmetic:\n // atomicPrice = rateInQuote * percentageToKeep / basisPoints\n const atomicPrice =\n (rateInQuote * BigInt(percentageToKeep)) / BigInt(basisPoints);\n\n return atomicPrice;\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkBDXS57YH_js = require('./chunk-BDXS57YH.js');
|
|
4
|
+
|
|
5
|
+
// src/utils/time.ts
|
|
6
|
+
var calculateDeadline = (daysFromNow = chunkBDXS57YH_js.DEFAULT_DEADLINE) => {
|
|
7
|
+
const daysInSeconds = daysFromNow * 24 * 60 * 60;
|
|
8
|
+
const currentTimeStamp = Math.floor(Date.now() / 1e3);
|
|
9
|
+
const deadline = currentTimeStamp + daysInSeconds;
|
|
10
|
+
return BigInt(deadline);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
exports.calculateDeadline = calculateDeadline;
|
|
14
|
+
//# sourceMappingURL=chunk-AFWUOS3M.js.map
|
|
15
|
+
//# sourceMappingURL=chunk-AFWUOS3M.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/time.ts"],"names":["DEFAULT_DEADLINE"],"mappings":";;;;;AAoBO,IAAM,iBAAA,GAAoB,CAAC,WAAA,GAAcA,iCAAA,KAAqB;AAEnE,EAAA,MAAM,aAAA,GAAgB,WAAA,GAAc,EAAA,GAAK,EAAA,GAAK,EAAA;AAG9C,EAAA,MAAM,mBAAmB,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,GAAA,KAAQ,GAAI,CAAA;AAGrD,EAAA,MAAM,WAAW,gBAAA,GAAmB,aAAA;AAEpC,EAAA,OAAO,OAAO,QAAQ,CAAA;AACxB","file":"chunk-AFWUOS3M.js","sourcesContent":["/**\n * @fileoverview Utility functions for time-related operations\n */\n\nimport { DEFAULT_DEADLINE } from \"../constants\";\n\n/**\n * Calculates a deadline timestamp in seconds from the current time\n *\n * @param {number} [daysFromNow=DEFAULT_DEADLINE] - Number of days from now to set the deadline\n * @returns {number} Unix timestamp in seconds representing the deadline\n *\n * @example\n * // Returns a timestamp 3 days from now (in seconds)\n * const threeDay = calculateDeadline();\n *\n * @example\n * // Returns a timestamp 7 days from now (in seconds)\n * const weekDeadline = calculateDeadline(7);\n */\nexport const calculateDeadline = (daysFromNow = DEFAULT_DEADLINE) => {\n // Get days in seconds\n const daysInSeconds = daysFromNow * 24 * 60 * 60;\n\n // Get current timestamp in seconds\n const currentTimeStamp = Math.floor(Date.now() / 1000);\n\n // Calculate deadline (current time + 3 days in seconds)\n const deadline = currentTimeStamp + daysInSeconds;\n\n return BigInt(deadline);\n};\n"]}
|