@gauntlet-xyz/sdk 2.0.0 → 2.5.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/README.md +134 -1
- package/dist/api/activity.d.ts +70 -0
- package/dist/api/activity.d.ts.map +1 -0
- package/dist/api/activity.js +154 -0
- package/dist/api/activity.js.map +1 -0
- package/dist/api/caip.d.ts +29 -0
- package/dist/api/caip.d.ts.map +1 -0
- package/dist/api/caip.js +38 -0
- package/dist/api/caip.js.map +1 -0
- package/dist/api/client.d.ts +135 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +119 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/decimal.d.ts +21 -0
- package/dist/api/decimal.d.ts.map +1 -0
- package/dist/api/decimal.js +44 -0
- package/dist/api/decimal.js.map +1 -0
- package/dist/api/errors.d.ts +32 -0
- package/dist/api/errors.d.ts.map +1 -0
- package/dist/api/errors.js +41 -0
- package/dist/api/errors.js.map +1 -0
- package/dist/api/generated.d.ts +1505 -0
- package/dist/api/generated.d.ts.map +1 -0
- package/dist/api/generated.js +6 -0
- package/dist/api/generated.js.map +1 -0
- package/dist/api/http.d.ts +16 -0
- package/dist/api/http.d.ts.map +1 -0
- package/dist/api/http.js +39 -0
- package/dist/api/http.js.map +1 -0
- package/dist/api/index.d.ts +14 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +8 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/positionHistory.d.ts +44 -0
- package/dist/api/positionHistory.d.ts.map +1 -0
- package/dist/api/positionHistory.js +126 -0
- package/dist/api/positionHistory.js.map +1 -0
- package/dist/client.d.ts +6 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -0
- package/dist/client.js.map +1 -1
- package/dist/errors.d.ts +11 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +21 -2
- package/dist/errors.js.map +1 -1
- package/dist/evm/abis/priceAndFeeCalculatorV2.d.ts +44 -0
- package/dist/evm/abis/priceAndFeeCalculatorV2.d.ts.map +1 -1
- package/dist/evm/abis/priceAndFeeCalculatorV2.js +22 -0
- package/dist/evm/abis/priceAndFeeCalculatorV2.js.map +1 -1
- package/dist/evm/abis/provisionerV2.d.ts +280 -0
- package/dist/evm/abis/provisionerV2.d.ts.map +1 -1
- package/dist/evm/abis/provisionerV2.js +92 -0
- package/dist/evm/abis/provisionerV2.js.map +1 -1
- package/dist/evm/adapters/aera.d.ts.map +1 -1
- package/dist/evm/adapters/aera.js +41 -10
- package/dist/evm/adapters/aera.js.map +1 -1
- package/dist/evm/adapters/types.d.ts +2 -0
- package/dist/evm/adapters/types.d.ts.map +1 -1
- package/dist/evm/aeraContracts/priceAndFeeCalculator.d.ts +10 -5
- package/dist/evm/aeraContracts/priceAndFeeCalculator.d.ts.map +1 -1
- package/dist/evm/aeraContracts/priceAndFeeCalculator.js +39 -5
- package/dist/evm/aeraContracts/priceAndFeeCalculator.js.map +1 -1
- package/dist/evm/aeraContracts/readOptions.d.ts +8 -0
- package/dist/evm/aeraContracts/readOptions.d.ts.map +1 -0
- package/dist/evm/aeraContracts/readOptions.js +4 -0
- package/dist/evm/aeraContracts/readOptions.js.map +1 -0
- package/dist/evm/aeraContracts/v2.d.ts +1932 -217
- package/dist/evm/aeraContracts/v2.d.ts.map +1 -1
- package/dist/evm/aeraContracts/v2.js +84 -28
- package/dist/evm/aeraContracts/v2.js.map +1 -1
- package/dist/evm/aeraContracts.d.ts +9 -3
- package/dist/evm/aeraContracts.d.ts.map +1 -1
- package/dist/evm/aeraContracts.js +69 -8
- package/dist/evm/aeraContracts.js.map +1 -1
- package/dist/evm/deposit.d.ts.map +1 -1
- package/dist/evm/deposit.js +1 -1
- package/dist/evm/deposit.js.map +1 -1
- package/dist/evm/index.d.ts +8 -0
- package/dist/evm/index.d.ts.map +1 -1
- package/dist/evm/index.js +3 -0
- package/dist/evm/index.js.map +1 -1
- package/dist/evm/tokenModes.d.ts +22 -0
- package/dist/evm/tokenModes.d.ts.map +1 -0
- package/dist/evm/tokenModes.js +34 -0
- package/dist/evm/tokenModes.js.map +1 -0
- package/dist/evm/withdraw.d.ts +8 -0
- package/dist/evm/withdraw.d.ts.map +1 -1
- package/dist/evm/withdraw.js +85 -5
- package/dist/evm/withdraw.js.map +1 -1
- package/dist/evm/withdrawQuote.d.ts +127 -0
- package/dist/evm/withdrawQuote.d.ts.map +1 -0
- package/dist/evm/withdrawQuote.js +164 -0
- package/dist/evm/withdrawQuote.js.map +1 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/privy/index.d.ts +52 -0
- package/dist/privy/index.d.ts.map +1 -0
- package/dist/privy/index.js +51 -0
- package/dist/privy/index.js.map +1 -0
- package/manifest/vaults.json +255 -3
- package/package.json +2 -2
- package/src/api/activity.ts +219 -0
- package/src/api/caip.ts +61 -0
- package/src/api/client.ts +234 -0
- package/src/api/decimal.ts +49 -0
- package/src/api/errors.ts +64 -0
- package/src/api/generated.ts +1505 -0
- package/src/api/http.ts +62 -0
- package/src/api/index.ts +70 -0
- package/src/api/positionHistory.ts +167 -0
- package/src/client.ts +7 -1
- package/src/errors.ts +32 -2
- package/src/evm/abis/priceAndFeeCalculatorV2.ts +22 -0
- package/src/evm/abis/provisionerV2.ts +92 -0
- package/src/evm/adapters/aera.ts +50 -23
- package/src/evm/adapters/types.ts +2 -0
- package/src/evm/aeraContracts/priceAndFeeCalculator.ts +72 -5
- package/src/evm/aeraContracts/readOptions.ts +3 -0
- package/src/evm/aeraContracts/v2.ts +158 -34
- package/src/evm/aeraContracts.ts +81 -8
- package/src/evm/deposit.ts +2 -1
- package/src/evm/index.ts +32 -0
- package/src/evm/tokenModes.ts +54 -0
- package/src/evm/withdraw.ts +131 -7
- package/src/evm/withdrawQuote.ts +360 -0
- package/src/index.ts +18 -0
- package/src/privy/index.ts +95 -0
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import type { components } from './generated';
|
|
2
|
+
import { apiGet, type GauntletApiConfig, type QueryParams } from './http';
|
|
3
|
+
|
|
4
|
+
type Schemas = components['schemas'];
|
|
5
|
+
|
|
6
|
+
export type UserActivity = Schemas['UserActivity'];
|
|
7
|
+
export type UserActivityResponse = Schemas['UserActivityResponse'];
|
|
8
|
+
export type UserPosition = Schemas['UserPosition'];
|
|
9
|
+
export type UserAllPositionsResponse = Schemas['UserAllPositionsResponse'];
|
|
10
|
+
export type UserPositionLatestResponse = Schemas['UserPositionLatestResponse'];
|
|
11
|
+
export type UserPositionsTimeseriesResponse = Schemas['UserPositionsTimeseriesResponse'];
|
|
12
|
+
export type PositionTimeseriesPoint = Schemas['PositionTimeseriesPoint'];
|
|
13
|
+
export type VaultDetail = Schemas['VaultDetail'];
|
|
14
|
+
export type VaultDetailResponse = Schemas['VaultDetailResponse'];
|
|
15
|
+
export type VaultTimeseriesResponse = Schemas['VaultTimeseriesResponse'];
|
|
16
|
+
export type VaultTimeseriesPoint = Schemas['VaultTimeseriesPoint'];
|
|
17
|
+
export type VaultMetrics = Schemas['VaultMetrics'];
|
|
18
|
+
export type FeaturedVault = Schemas['FeaturedVault'];
|
|
19
|
+
export type FeaturedVaultsResponse = Schemas['FeaturedVaultsResponse'];
|
|
20
|
+
export type StrategyCard = Schemas['StrategyCard'];
|
|
21
|
+
export type StrategyListResponse = Schemas['StrategyListResponse'];
|
|
22
|
+
export type TvlResponse = Schemas['TvlResponse'];
|
|
23
|
+
export type LatestPriceResponse = Schemas['LatestPriceResponse'];
|
|
24
|
+
export type PriceTimeseriesResponse = Schemas['TimeseriesResponse'];
|
|
25
|
+
export type TokenRef = Schemas['TokenRef'];
|
|
26
|
+
export type PartialResponseError = Schemas['PartialResponseError'];
|
|
27
|
+
export type AmountPair = Schemas['AmountPair'];
|
|
28
|
+
export type TimeseriesMeta = Schemas['TimeseriesMeta'];
|
|
29
|
+
export type HealthResponse = Schemas['HealthResponse'];
|
|
30
|
+
export type ChainSyncStatus = Schemas['ChainSyncStatus'];
|
|
31
|
+
|
|
32
|
+
export interface PageOptions {
|
|
33
|
+
/** Opaque cursor from a previous response's `meta.next_cursor`. */
|
|
34
|
+
next?: string;
|
|
35
|
+
limit?: number;
|
|
36
|
+
order?: 'asc' | 'desc';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface TimeWindowOptions extends PageOptions {
|
|
40
|
+
/** ISO 8601 date (`2026-01-01`) or RFC 3339 timestamp. */
|
|
41
|
+
start?: string;
|
|
42
|
+
end?: string;
|
|
43
|
+
granularity?: 'hour' | 'day' | 'week' | 'month';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface ActivityOptions extends PageOptions {
|
|
47
|
+
/** CAIP-10 vault id (`"{chainId}:{address}"`). Omit for wallet-wide activity. */
|
|
48
|
+
vaultId?: string;
|
|
49
|
+
/**
|
|
50
|
+
* Wallet-wide feeds only: include activity in hidden (enabled but unlisted)
|
|
51
|
+
* vaults alongside visible ones. Activity in disabled vaults is never
|
|
52
|
+
* returned. Ignored when `vaultId` is set.
|
|
53
|
+
*/
|
|
54
|
+
includeHidden?: boolean;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface PositionsOptions extends PageOptions {
|
|
58
|
+
/**
|
|
59
|
+
* Include positions in hidden (enabled but unlisted) vaults alongside
|
|
60
|
+
* visible ones. Positions in disabled vaults are never returned.
|
|
61
|
+
*/
|
|
62
|
+
includeHidden?: boolean;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface LatestPriceOptions {
|
|
66
|
+
address: string;
|
|
67
|
+
chainId: number;
|
|
68
|
+
/** Optional ISO 8601 timestamp for a point-in-time price. */
|
|
69
|
+
at?: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface PriceTimeseriesOptions {
|
|
73
|
+
address: string;
|
|
74
|
+
chainId: number;
|
|
75
|
+
start: string;
|
|
76
|
+
end: string;
|
|
77
|
+
granularity?: 'raw' | 'hour' | 'day' | 'week' | 'month';
|
|
78
|
+
limit?: number;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Typed client for the Gaia REST API (api.gauntlet.xyz).
|
|
83
|
+
*
|
|
84
|
+
* All response types are generated from the service's OpenAPI spec
|
|
85
|
+
* (`src/api/generated.ts`, regenerated via `yarn generate:api-types`) so they
|
|
86
|
+
* cannot drift from the server models. Values are returned exactly as the API
|
|
87
|
+
* emits them — human-unit decimal strings and CAIP-10 vault ids; use
|
|
88
|
+
* `decimalToBigInt` / `sharesToBigInt` and `apiVaultIdFromVaultId` /
|
|
89
|
+
* `vaultIdFromApiVaultId` to convert, or the higher-level `activityFlows` /
|
|
90
|
+
* `positionHistory` helpers for pre-normalized values.
|
|
91
|
+
*
|
|
92
|
+
* Available on a configured client as `client.api`, or standalone:
|
|
93
|
+
* ```ts
|
|
94
|
+
* const api = new GauntletApi({ apiKey: process.env.GAUNTLET_API_KEY });
|
|
95
|
+
* const { data } = await api.vaults();
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
export class GauntletApi {
|
|
99
|
+
private readonly config: GauntletApiConfig;
|
|
100
|
+
|
|
101
|
+
constructor(config: GauntletApiConfig = {}) {
|
|
102
|
+
this.config = config;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private get<T>(path: string, query?: QueryParams): Promise<T> {
|
|
106
|
+
return apiGet<T>(this.config, path, query);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** GET /health — service liveness (version + uptime). */
|
|
110
|
+
health(): Promise<HealthResponse> {
|
|
111
|
+
return this.get('/health');
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** GET /health/chains — per-chain indexer sync freshness. */
|
|
115
|
+
chainSyncStatus(): Promise<ChainSyncStatus[]> {
|
|
116
|
+
return this.get('/health/chains');
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** GET /v1/vaults — all indexed vaults with live metrics (TVL, APY, unit price). */
|
|
120
|
+
vaults(options: PageOptions = {}): Promise<{ data: VaultDetail[]; meta: TimeseriesMeta }> {
|
|
121
|
+
return this.get('/v1/vaults', { next: options.next, limit: options.limit });
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** GET /v1/vaults/featured — admin-curated featured vault cards. */
|
|
125
|
+
featuredVaults(): Promise<FeaturedVaultsResponse> {
|
|
126
|
+
return this.get('/v1/vaults/featured');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** GET /v1/strategies — admin-curated strategy cards. */
|
|
130
|
+
strategies(): Promise<StrategyListResponse> {
|
|
131
|
+
return this.get('/v1/strategies');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** GET /v1/vaults/{vault_id} — one vault with live metrics. `vaultId` is CAIP-10. */
|
|
135
|
+
vault(vaultId: string): Promise<VaultDetailResponse> {
|
|
136
|
+
return this.get(`/v1/vaults/${encodeURIComponent(vaultId)}`);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** GET /v1/vaults/{vault_id}/definition — raw indexed vault definition. */
|
|
140
|
+
vaultDefinition(vaultId: string): Promise<unknown> {
|
|
141
|
+
return this.get(`/v1/vaults/${encodeURIComponent(vaultId)}/definition`);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** GET /v1/vaults/{vault_id}/timeseries — TVL / unit-price / APY history. */
|
|
145
|
+
vaultTimeseries(
|
|
146
|
+
vaultId: string,
|
|
147
|
+
options: TimeWindowOptions = {}
|
|
148
|
+
): Promise<VaultTimeseriesResponse> {
|
|
149
|
+
return this.get(`/v1/vaults/${encodeURIComponent(vaultId)}/timeseries`, { ...options });
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** GET /v1/users/{wallet}/positions — all of a wallet's indexed positions with PnL. */
|
|
153
|
+
positions(
|
|
154
|
+
walletAddress: string,
|
|
155
|
+
options: PositionsOptions = {}
|
|
156
|
+
): Promise<UserAllPositionsResponse> {
|
|
157
|
+
return this.get(`/v1/users/${encodeURIComponent(walletAddress)}/positions`, {
|
|
158
|
+
next: options.next,
|
|
159
|
+
limit: options.limit,
|
|
160
|
+
include_hidden: options.includeHidden,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** GET /v1/users/{wallet}/positions/{vault_id} — one position with PnL breakdown. */
|
|
165
|
+
position(walletAddress: string, vaultId: string): Promise<UserPositionLatestResponse> {
|
|
166
|
+
return this.get(
|
|
167
|
+
`/v1/users/${encodeURIComponent(walletAddress)}/positions/${encodeURIComponent(vaultId)}`
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** GET /v1/users/{wallet}/positions/{vault_id}/timeseries — value / cost-basis / PnL / ROI history. */
|
|
172
|
+
positionTimeseries(
|
|
173
|
+
walletAddress: string,
|
|
174
|
+
vaultId: string,
|
|
175
|
+
options: TimeWindowOptions = {}
|
|
176
|
+
): Promise<UserPositionsTimeseriesResponse> {
|
|
177
|
+
return this.get(
|
|
178
|
+
`/v1/users/${encodeURIComponent(walletAddress)}/positions/${encodeURIComponent(vaultId)}/timeseries`,
|
|
179
|
+
{ ...options }
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** GET /v1/users/{wallet}/activity — one page of the wallet's immutable event log. */
|
|
184
|
+
activity(walletAddress: string, options: ActivityOptions = {}): Promise<UserActivityResponse> {
|
|
185
|
+
const { vaultId, includeHidden, ...page } = options;
|
|
186
|
+
return this.get(`/v1/users/${encodeURIComponent(walletAddress)}/activity`, {
|
|
187
|
+
vault_id: vaultId,
|
|
188
|
+
include_hidden: includeHidden,
|
|
189
|
+
...page,
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Iterates the wallet's full activity log, following `meta.next_cursor`
|
|
195
|
+
* across pages so callers never handle cursors.
|
|
196
|
+
*/
|
|
197
|
+
async *activityRows(
|
|
198
|
+
walletAddress: string,
|
|
199
|
+
options: Omit<ActivityOptions, 'next'> = {}
|
|
200
|
+
): AsyncGenerator<UserActivity> {
|
|
201
|
+
let next: string | undefined;
|
|
202
|
+
do {
|
|
203
|
+
const page = await this.activity(walletAddress, { ...options, next });
|
|
204
|
+
yield* page.data;
|
|
205
|
+
next = page.meta.next_cursor ?? undefined;
|
|
206
|
+
} while (next);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/** GET /v1/tvl — aggregate Gauntlet TVL, optionally with per-source breakdown. */
|
|
210
|
+
tvl(options: { includeBreakdown?: boolean } = {}): Promise<TvlResponse> {
|
|
211
|
+
return this.get('/v1/tvl', { include_breakdown: options.includeBreakdown });
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** GET /v1/prices — latest USD price for a token. */
|
|
215
|
+
latestPrice(options: LatestPriceOptions): Promise<LatestPriceResponse> {
|
|
216
|
+
return this.get('/v1/prices', {
|
|
217
|
+
address: options.address,
|
|
218
|
+
chain_id: options.chainId,
|
|
219
|
+
at: options.at,
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** GET /v1/prices/timeseries — USD price history for a token. */
|
|
224
|
+
priceTimeseries(options: PriceTimeseriesOptions): Promise<PriceTimeseriesResponse> {
|
|
225
|
+
return this.get('/v1/prices/timeseries', {
|
|
226
|
+
address: options.address,
|
|
227
|
+
chain_id: options.chainId,
|
|
228
|
+
start: options.start,
|
|
229
|
+
end: options.end,
|
|
230
|
+
granularity: options.granularity,
|
|
231
|
+
limit: options.limit,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { formatUnits } from 'viem';
|
|
2
|
+
import { DecimalPrecisionError, InvalidDecimalError } from './errors';
|
|
3
|
+
|
|
4
|
+
const DECIMAL_RE = /^(-?)(\d+)(?:\.(\d+))?$/;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Converts an API decimal string (human units, e.g. `"1250.5"`) into base-unit
|
|
8
|
+
* bigint at the given token decimals (e.g. `1250500000n` for 6 decimals).
|
|
9
|
+
*
|
|
10
|
+
* The conversion is exact: a value with more significant fractional digits
|
|
11
|
+
* than `decimals` throws `DecimalPrecisionError` rather than rounding.
|
|
12
|
+
* Hand-rolled instead of viem's `parseUnits`, which silently rounds excess
|
|
13
|
+
* precision (`parseUnits('1.0000005', 6)` → `1000001n`) — unacceptable for
|
|
14
|
+
* financial amounts.
|
|
15
|
+
*/
|
|
16
|
+
export function decimalToBigInt(value: string, decimals: number): bigint {
|
|
17
|
+
if (!Number.isInteger(decimals) || decimals < 0) {
|
|
18
|
+
throw new InvalidDecimalError(`decimals=${decimals}`);
|
|
19
|
+
}
|
|
20
|
+
const match = DECIMAL_RE.exec(value);
|
|
21
|
+
if (!match) throw new InvalidDecimalError(value);
|
|
22
|
+
|
|
23
|
+
const [, sign, whole, frac = ''] = match;
|
|
24
|
+
if (frac.length > decimals && !/^0*$/.test(frac.slice(decimals))) {
|
|
25
|
+
throw new DecimalPrecisionError(value, decimals);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const scaled = BigInt(whole + frac.slice(0, decimals).padEnd(decimals, '0'));
|
|
29
|
+
return sign === '-' ? -scaled : scaled;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Formats a base-unit bigint back into the API's human decimal-string
|
|
34
|
+
* representation (no trailing fractional zeros, no exponent notation).
|
|
35
|
+
*/
|
|
36
|
+
export function bigIntToDecimal(value: bigint, decimals: number): string {
|
|
37
|
+
if (!Number.isInteger(decimals) || decimals < 0) {
|
|
38
|
+
throw new InvalidDecimalError(`decimals=${decimals}`);
|
|
39
|
+
}
|
|
40
|
+
return formatUnits(value, decimals);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Vault shares are always reported in 18-decimal units by the Gaia API. */
|
|
44
|
+
export const SHARE_DECIMALS = 18;
|
|
45
|
+
|
|
46
|
+
/** Parses an API share amount (decimal string) into base-unit bigint (1e18). */
|
|
47
|
+
export function sharesToBigInt(value: string): bigint {
|
|
48
|
+
return decimalToBigInt(value, SHARE_DECIMALS);
|
|
49
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { GauntletSDKError } from '../errors';
|
|
2
|
+
|
|
3
|
+
export class GauntletApiError extends GauntletSDKError {
|
|
4
|
+
readonly status: number;
|
|
5
|
+
readonly path: string;
|
|
6
|
+
/** Machine-readable code from the API error envelope (e.g. `NOT_FOUND`), when present. */
|
|
7
|
+
readonly code?: string;
|
|
8
|
+
|
|
9
|
+
constructor(params: { status: number; path: string; message: string; code?: string }) {
|
|
10
|
+
super(
|
|
11
|
+
`Gauntlet API request to "${params.path}" failed with ${params.status}: ${params.message}`
|
|
12
|
+
);
|
|
13
|
+
this.name = 'GauntletApiError';
|
|
14
|
+
this.status = params.status;
|
|
15
|
+
this.path = params.path;
|
|
16
|
+
this.code = params.code;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class InvalidDecimalError extends GauntletSDKError {
|
|
21
|
+
readonly value: string;
|
|
22
|
+
|
|
23
|
+
constructor(value: string) {
|
|
24
|
+
super(`Value "${value}" is not a valid decimal string`);
|
|
25
|
+
this.name = 'InvalidDecimalError';
|
|
26
|
+
this.value = value;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class DecimalPrecisionError extends GauntletSDKError {
|
|
31
|
+
readonly value: string;
|
|
32
|
+
readonly decimals: number;
|
|
33
|
+
|
|
34
|
+
constructor(value: string, decimals: number) {
|
|
35
|
+
super(
|
|
36
|
+
`Decimal "${value}" has more fractional digits than the token's ${decimals} decimals; converting would lose precision`
|
|
37
|
+
);
|
|
38
|
+
this.name = 'DecimalPrecisionError';
|
|
39
|
+
this.value = value;
|
|
40
|
+
this.decimals = decimals;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class InvalidCaipIdError extends GauntletSDKError {
|
|
45
|
+
readonly id: string;
|
|
46
|
+
|
|
47
|
+
constructor(id: string) {
|
|
48
|
+
super(`"${id}" is not a valid CAIP-10 vault id (expected "{chainId}:{address}")`);
|
|
49
|
+
this.name = 'InvalidCaipIdError';
|
|
50
|
+
this.id = id;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export class SettlementTimeoutError extends GauntletSDKError {
|
|
55
|
+
readonly requestHash: string;
|
|
56
|
+
readonly timeoutMs: number;
|
|
57
|
+
|
|
58
|
+
constructor(requestHash: string, timeoutMs: number) {
|
|
59
|
+
super(`Request "${requestHash}" did not settle within ${timeoutMs}ms`);
|
|
60
|
+
this.name = 'SettlementTimeoutError';
|
|
61
|
+
this.requestHash = requestHash;
|
|
62
|
+
this.timeoutMs = timeoutMs;
|
|
63
|
+
}
|
|
64
|
+
}
|