@gauntlet-xyz/sdk 2.0.0 → 2.3.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.
Files changed (70) hide show
  1. package/README.md +82 -1
  2. package/dist/api/activity.d.ts +70 -0
  3. package/dist/api/activity.d.ts.map +1 -0
  4. package/dist/api/activity.js +154 -0
  5. package/dist/api/activity.js.map +1 -0
  6. package/dist/api/caip.d.ts +29 -0
  7. package/dist/api/caip.d.ts.map +1 -0
  8. package/dist/api/caip.js +38 -0
  9. package/dist/api/caip.js.map +1 -0
  10. package/dist/api/client.d.ts +114 -0
  11. package/dist/api/client.d.ts.map +1 -0
  12. package/dist/api/client.js +109 -0
  13. package/dist/api/client.js.map +1 -0
  14. package/dist/api/decimal.d.ts +21 -0
  15. package/dist/api/decimal.d.ts.map +1 -0
  16. package/dist/api/decimal.js +44 -0
  17. package/dist/api/decimal.js.map +1 -0
  18. package/dist/api/errors.d.ts +32 -0
  19. package/dist/api/errors.d.ts.map +1 -0
  20. package/dist/api/errors.js +41 -0
  21. package/dist/api/errors.js.map +1 -0
  22. package/dist/api/generated.d.ts +1461 -0
  23. package/dist/api/generated.d.ts.map +1 -0
  24. package/dist/api/generated.js +6 -0
  25. package/dist/api/generated.js.map +1 -0
  26. package/dist/api/http.d.ts +16 -0
  27. package/dist/api/http.d.ts.map +1 -0
  28. package/dist/api/http.js +39 -0
  29. package/dist/api/http.js.map +1 -0
  30. package/dist/api/index.d.ts +14 -0
  31. package/dist/api/index.d.ts.map +1 -0
  32. package/dist/api/index.js +8 -0
  33. package/dist/api/index.js.map +1 -0
  34. package/dist/api/positionHistory.d.ts +44 -0
  35. package/dist/api/positionHistory.d.ts.map +1 -0
  36. package/dist/api/positionHistory.js +126 -0
  37. package/dist/api/positionHistory.js.map +1 -0
  38. package/dist/client.d.ts +6 -0
  39. package/dist/client.d.ts.map +1 -1
  40. package/dist/client.js +2 -0
  41. package/dist/client.js.map +1 -1
  42. package/dist/evm/abis/provisionerV2.d.ts +224 -0
  43. package/dist/evm/abis/provisionerV2.d.ts.map +1 -1
  44. package/dist/evm/abis/provisionerV2.js +59 -0
  45. package/dist/evm/abis/provisionerV2.js.map +1 -1
  46. package/dist/evm/aeraContracts/v2.d.ts +1369 -25
  47. package/dist/evm/aeraContracts/v2.d.ts.map +1 -1
  48. package/dist/index.d.ts +1 -0
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +1 -0
  51. package/dist/index.js.map +1 -1
  52. package/dist/privy/index.d.ts +52 -0
  53. package/dist/privy/index.d.ts.map +1 -0
  54. package/dist/privy/index.js +51 -0
  55. package/dist/privy/index.js.map +1 -0
  56. package/manifest/vaults.json +299 -5
  57. package/package.json +2 -2
  58. package/src/api/activity.ts +219 -0
  59. package/src/api/caip.ts +61 -0
  60. package/src/api/client.ts +201 -0
  61. package/src/api/decimal.ts +49 -0
  62. package/src/api/errors.ts +64 -0
  63. package/src/api/generated.ts +1461 -0
  64. package/src/api/http.ts +62 -0
  65. package/src/api/index.ts +65 -0
  66. package/src/api/positionHistory.ts +167 -0
  67. package/src/client.ts +7 -1
  68. package/src/evm/abis/provisionerV2.ts +59 -0
  69. package/src/index.ts +2 -0
  70. package/src/privy/index.ts +95 -0
@@ -0,0 +1,62 @@
1
+ import { GauntletApiError } from './errors';
2
+
3
+ export const DEFAULT_API_URL = 'https://api.gauntlet.xyz';
4
+
5
+ export interface GauntletApiConfig {
6
+ /** Kong consumer key sent as `x-api-key`. Anonymous access is rate-limited. */
7
+ apiKey?: string;
8
+ /**
9
+ * Override the API origin. Defaults to `https://api.gauntlet.xyz`. In a
10
+ * browser this may be a relative path (e.g. a Next.js rewrite like
11
+ * `/gauntlet-api`), which resolves against the page origin.
12
+ */
13
+ apiUrl?: string;
14
+ /** Custom fetch implementation (testing, instrumentation). Defaults to global fetch. */
15
+ fetch?: typeof fetch;
16
+ }
17
+
18
+ export type QueryParams = Record<string, string | number | boolean | undefined>;
19
+
20
+ export async function apiGet<T>(
21
+ config: GauntletApiConfig,
22
+ path: string,
23
+ query?: QueryParams
24
+ ): Promise<T> {
25
+ // Concatenate instead of `new URL(path, base)`: the paths are absolute, so
26
+ // URL resolution would silently drop any path prefix on a proxy apiUrl.
27
+ const base = (config.apiUrl ?? DEFAULT_API_URL).replace(/\/+$/, '');
28
+ // Relative bases resolve against the browser origin.
29
+ const origin = (globalThis as { location?: { origin: string } }).location?.origin;
30
+ if (origin === undefined && !/^[a-z][a-z0-9+.-]*:\/\//i.test(base)) {
31
+ throw new Error(
32
+ `relative apiUrl "${base}" requires a browser origin; pass an absolute apiUrl outside the browser`
33
+ );
34
+ }
35
+ const url = new URL(base + path, origin);
36
+ for (const [key, value] of Object.entries(query ?? {})) {
37
+ if (value !== undefined) url.searchParams.set(key, String(value));
38
+ }
39
+
40
+ const fetchImpl = config.fetch ?? fetch;
41
+ const response = await fetchImpl(url, {
42
+ headers: {
43
+ accept: 'application/json',
44
+ ...(config.apiKey ? { 'x-api-key': config.apiKey } : {}),
45
+ },
46
+ });
47
+
48
+ if (!response.ok) {
49
+ let message = response.statusText || 'request failed';
50
+ let code: string | undefined;
51
+ try {
52
+ const body = (await response.json()) as { error?: { code?: string; message?: string } };
53
+ message = body.error?.message ?? message;
54
+ code = body.error?.code;
55
+ } catch {
56
+ // non-JSON error body — keep the status text
57
+ }
58
+ throw new GauntletApiError({ status: response.status, path, message, code });
59
+ }
60
+
61
+ return (await response.json()) as T;
62
+ }
@@ -0,0 +1,65 @@
1
+ export { GauntletApi } from './client';
2
+ export type {
3
+ ActivityOptions,
4
+ AmountPair,
5
+ ChainSyncStatus,
6
+ HealthResponse,
7
+ LatestPriceOptions,
8
+ LatestPriceResponse,
9
+ PageOptions,
10
+ PartialResponseError,
11
+ PositionTimeseriesPoint,
12
+ PriceTimeseriesOptions,
13
+ PriceTimeseriesResponse,
14
+ TimeseriesMeta,
15
+ TimeWindowOptions,
16
+ TokenRef,
17
+ TvlResponse,
18
+ UserActivity,
19
+ UserActivityResponse,
20
+ UserAllPositionsResponse,
21
+ UserPosition,
22
+ UserPositionLatestResponse,
23
+ UserPositionsTimeseriesResponse,
24
+ VaultDetail,
25
+ VaultDetailResponse,
26
+ VaultMetrics,
27
+ VaultTimeseriesPoint,
28
+ VaultTimeseriesResponse,
29
+ } from './client';
30
+
31
+ export { DEFAULT_API_URL } from './http';
32
+ export type { GauntletApiConfig } from './http';
33
+
34
+ export { bigIntToDecimal, decimalToBigInt, SHARE_DECIMALS, sharesToBigInt } from './decimal';
35
+
36
+ export {
37
+ apiVaultIdFromVaultId,
38
+ formatApiVaultId,
39
+ parseApiVaultId,
40
+ vaultIdFromApiVaultId,
41
+ } from './caip';
42
+ export type { ApiVaultId } from './caip';
43
+
44
+ export { getActivityFlows, stitchActivityFlows, waitForRequestSettlement } from './activity';
45
+ export type {
46
+ ActivityFlow,
47
+ ActivityFlowKind,
48
+ ActivityFlowsOptions,
49
+ ActivityFlowStatus,
50
+ AssetAmount,
51
+ WaitForSettlementOptions,
52
+ } from './activity';
53
+
54
+ export { buildPositionHistory, getPositionHistory } from './positionHistory';
55
+ export type { PositionHistory, PositionHistoryPoint } from './positionHistory';
56
+
57
+ export {
58
+ DecimalPrecisionError,
59
+ GauntletApiError,
60
+ InvalidCaipIdError,
61
+ InvalidDecimalError,
62
+ SettlementTimeoutError,
63
+ } from './errors';
64
+
65
+ export type { components as GaiaApiComponents, paths as GaiaApiPaths } from './generated';
@@ -0,0 +1,167 @@
1
+ import { GauntletSDKError } from '../errors';
2
+ import type { GauntletApi, TokenRef, UserActivity } from './client';
3
+ import { bigIntToDecimal, decimalToBigInt, sharesToBigInt } from './decimal';
4
+
5
+ /**
6
+ * Internal accounting scale for asset amounts. The API emits human-unit
7
+ * decimal strings with at most `token.decimals` fractional digits, so 18
8
+ * digits is exact for every supported asset; a token with more than 18
9
+ * decimals would throw `DecimalPrecisionError` rather than lose precision.
10
+ */
11
+ const ASSET_SCALE = 18;
12
+
13
+ /** The wallet's reconstructed position state immediately after one activity row. */
14
+ export interface PositionHistoryPoint {
15
+ timestamp: Date;
16
+ txHash: string;
17
+ type: UserActivity['type'];
18
+ /** Signed share movement of this row, 18-decimal base units. */
19
+ sharesDelta: bigint;
20
+ /** Signed asset movement of this row (deposit-ledger convention), human decimal string. */
21
+ assetsDelta: string;
22
+ /** Shares held by the wallet after this row (escrowed redeem shares excluded). */
23
+ sharesBalance: bigint;
24
+ /** Assets escrowed at the Provisioner awaiting share mint, human decimal string. */
25
+ pendingDepositAssets: string;
26
+ /** Shares escrowed at the Provisioner awaiting asset return, 18-decimal base units. */
27
+ pendingRedeemShares: bigint;
28
+ /** Cumulative settled deposits minus settled withdrawals, human decimal string. */
29
+ netAssetsIn: string;
30
+ }
31
+
32
+ export interface PositionHistory {
33
+ /** CAIP-10 vault id the history belongs to. */
34
+ vaultId: string;
35
+ /** The vault's asset token, when the indexer reports it on any row. */
36
+ token: TokenRef | null;
37
+ /** Chronological (oldest-first) position states, one per activity row. */
38
+ points: PositionHistoryPoint[];
39
+ }
40
+
41
+ /**
42
+ * Pure builder: replays a single vault's activity rows (any order) into a
43
+ * chronological position timeline — running share balance, escrowed pending
44
+ * amounts, and cumulative net asset flows.
45
+ *
46
+ * Async lifecycles are paired via `request_hash` so settled deposits count
47
+ * the requested asset amount and terminal rows release the matching escrow.
48
+ */
49
+ export function buildPositionHistory(rows: UserActivity[]): PositionHistory {
50
+ if (rows.length === 0) {
51
+ throw new GauntletSDKError('Cannot build position history from zero activity rows');
52
+ }
53
+ const vaultIds = new Set(rows.map((r) => r.vault_id));
54
+ if (vaultIds.size > 1) {
55
+ throw new GauntletSDKError(
56
+ `Position history requires rows from a single vault; got ${[...vaultIds].join(', ')}`
57
+ );
58
+ }
59
+
60
+ const ordered = [...rows].sort((a, b) => a.block_timestamp - b.block_timestamp);
61
+ const token = ordered.find((r) => r.assets_delta.token)?.assets_delta.token ?? null;
62
+
63
+ let sharesBalance = 0n;
64
+ let pendingDepositAssets = 0n;
65
+ let pendingRedeemShares = 0n;
66
+ let netAssetsIn = 0n;
67
+ const pendingDepositByHash = new Map<string, bigint>();
68
+ const pendingRedeemByHash = new Map<string, bigint>();
69
+
70
+ const points: PositionHistoryPoint[] = [];
71
+ for (const row of ordered) {
72
+ const sharesDelta = sharesToBigInt(row.shares_delta);
73
+ const assetsDelta = decimalToBigInt(row.assets_delta.native, ASSET_SCALE);
74
+ sharesBalance += sharesDelta;
75
+
76
+ switch (row.type) {
77
+ case 'deposit':
78
+ if (row.request_hash != null) {
79
+ // Async terminal solve: assets moved at request time; release escrow.
80
+ const requested = pendingDepositByHash.get(row.request_hash);
81
+ if (requested === undefined) {
82
+ throw new GauntletSDKError(
83
+ `Deposit settlement ${row.tx_hash} references request_hash "${row.request_hash}" with no matching deposit_pending row`
84
+ );
85
+ }
86
+ pendingDepositByHash.delete(row.request_hash);
87
+ pendingDepositAssets -= requested;
88
+ netAssetsIn += requested;
89
+ } else {
90
+ netAssetsIn += assetsDelta;
91
+ }
92
+ break;
93
+ case 'deposit_pending':
94
+ pendingDepositAssets += assetsDelta;
95
+ if (row.request_hash != null) pendingDepositByHash.set(row.request_hash, assetsDelta);
96
+ break;
97
+ case 'deposit_refunded':
98
+ // Row carries the unwound request as a negative delta.
99
+ pendingDepositAssets += assetsDelta;
100
+ if (row.request_hash != null) pendingDepositByHash.delete(row.request_hash);
101
+ break;
102
+ case 'withdraw':
103
+ // Sync withdraws and async terminal solves both carry the asset
104
+ // payout as a negative delta on this row.
105
+ netAssetsIn += assetsDelta;
106
+ if (row.request_hash != null) {
107
+ const escrowed = pendingRedeemByHash.get(row.request_hash);
108
+ if (escrowed === undefined) {
109
+ throw new GauntletSDKError(
110
+ `Withdraw settlement ${row.tx_hash} references request_hash "${row.request_hash}" with no matching withdraw_pending row`
111
+ );
112
+ }
113
+ pendingRedeemByHash.delete(row.request_hash);
114
+ pendingRedeemShares -= escrowed;
115
+ }
116
+ break;
117
+ case 'withdraw_pending': {
118
+ const escrowed = -sharesDelta;
119
+ pendingRedeemShares += escrowed;
120
+ if (row.request_hash != null) pendingRedeemByHash.set(row.request_hash, escrowed);
121
+ break;
122
+ }
123
+ case 'withdraw_refunded':
124
+ pendingRedeemShares -= sharesDelta;
125
+ if (row.request_hash != null) pendingRedeemByHash.delete(row.request_hash);
126
+ break;
127
+ case 'transfer_in':
128
+ case 'transfer_out':
129
+ break;
130
+ default:
131
+ throw new GauntletSDKError(`Unknown activity row type "${row.type}"`);
132
+ }
133
+
134
+ points.push({
135
+ timestamp: new Date(row.block_timestamp * 1000),
136
+ txHash: row.tx_hash,
137
+ type: row.type,
138
+ sharesDelta,
139
+ assetsDelta: row.assets_delta.native,
140
+ sharesBalance,
141
+ pendingDepositAssets: bigIntToDecimal(pendingDepositAssets, ASSET_SCALE),
142
+ pendingRedeemShares,
143
+ netAssetsIn: bigIntToDecimal(netAssetsIn, ASSET_SCALE),
144
+ });
145
+ }
146
+
147
+ return { vaultId: ordered[0].vault_id, token, points };
148
+ }
149
+
150
+ /**
151
+ * Fetches a wallet's complete activity for one vault and replays it into a
152
+ * position timeline. `vaultId` is the CAIP-10 id; use `apiVaultIdFromVaultId`
153
+ * to convert a manifest vault id. A wallet that has never touched the vault
154
+ * gets an empty timeline, not an error.
155
+ */
156
+ export async function getPositionHistory(
157
+ api: GauntletApi,
158
+ walletAddress: string,
159
+ vaultId: string
160
+ ): Promise<PositionHistory> {
161
+ const rows: UserActivity[] = [];
162
+ for await (const row of api.activityRows(walletAddress, { vaultId, order: 'asc', limit: 1000 })) {
163
+ rows.push(row);
164
+ }
165
+ if (rows.length === 0) return { vaultId, token: null, points: [] };
166
+ return buildPositionHistory(rows);
167
+ }
package/src/client.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { type PublicClient, type WalletClient } from 'viem';
2
2
  import bundledManifest from '../manifest/vaults.json';
3
+ import { GauntletApi } from './api/client';
3
4
  import { RpcNotConfiguredError, UnimplementedFeatureError } from './errors';
4
5
  import type { VaultManifest } from './evm/types';
5
6
  import { base } from 'viem/chains';
@@ -20,7 +21,10 @@ export enum AttributionMode {
20
21
  export type ChainId = string | number;
21
22
 
22
23
  export interface GauntletClientConfig {
24
+ /** Gaia API key, sent as `x-api-key` on `client.api` requests. Anonymous access is rate-limited. */
23
25
  apiKey?: string;
26
+ /** Override the Gaia API origin (e.g. a same-origin proxy route). Defaults to `https://api.gauntlet.xyz`. */
27
+ apiUrl?: string;
24
28
  /** Map of chainId → PublicClient, e.g. { [base.id]: createPublicClient(...) } */
25
29
  evmClients?: Record<ChainId, PublicClient>;
26
30
  attributionMode?: AttributionMode;
@@ -56,12 +60,13 @@ export interface GauntletClientConfig {
56
60
  * ```
57
61
  */
58
62
  export class GauntletClient {
59
- // used for future core api and encoding attribution
60
63
  readonly apiKey?: string;
61
64
  readonly builderCode?: string;
62
65
  readonly attributionMode: AttributionMode;
63
66
  readonly evmClients: Record<ChainId, PublicClient>;
64
67
  readonly wallet?: WalletClient;
68
+ /** Typed client for the Gaia REST API (vaults, positions, activity, tvl, prices). */
69
+ readonly api: GauntletApi;
65
70
 
66
71
  private _manifest: VaultManifest = bundledManifest as VaultManifest;
67
72
 
@@ -71,6 +76,7 @@ export class GauntletClient {
71
76
  this.attributionMode = config.attributionMode ?? AttributionMode.PUBLIC;
72
77
  this.builderCode = config.builderCode;
73
78
  this.wallet = config.wallet;
79
+ this.api = new GauntletApi({ apiKey: config.apiKey, apiUrl: config.apiUrl });
74
80
  }
75
81
 
76
82
  get manifest(): Promise<VaultManifest> {
@@ -199,4 +199,63 @@ export const provisionerV2Abi = [
199
199
  name: 'Redeemed',
200
200
  anonymous: false,
201
201
  },
202
+ { type: 'error', inputs: [], name: 'Aera__AsyncDepositDisabled' },
203
+ { type: 'error', inputs: [], name: 'Aera__AsyncRedeemDisabled' },
204
+ { type: 'error', inputs: [], name: 'Aera__AutoPriceSolveNotAllowed' },
205
+ { type: 'error', inputs: [], name: 'Aera__CallerIsNotRequestUser' },
206
+ { type: 'error', inputs: [], name: 'Aera__CallerIsVault' },
207
+ { type: 'error', inputs: [], name: 'Aera__CancellationFeeExceedsRequestAmount' },
208
+ { type: 'error', inputs: [], name: 'Aera__DeadlineInFutureAndUnauthorized' },
209
+ { type: 'error', inputs: [], name: 'Aera__DeadlineInPast' },
210
+ { type: 'error', inputs: [], name: 'Aera__DeadlineTooFarInFuture' },
211
+ { type: 'error', inputs: [], name: 'Aera__DepositCancellationDetailsNotZero' },
212
+ { type: 'error', inputs: [], name: 'Aera__DepositCapExceeded' },
213
+ { type: 'error', inputs: [], name: 'Aera__DepositCapZero' },
214
+ { type: 'error', inputs: [], name: 'Aera__DepositHashNotFound' },
215
+ { type: 'error', inputs: [], name: 'Aera__DepositRequestCancellationDisabled' },
216
+ { type: 'error', inputs: [], name: 'Aera__FixedPriceSolverTipNotAllowed' },
217
+ { type: 'error', inputs: [], name: 'Aera__HashCollision' },
218
+ { type: 'error', inputs: [], name: 'Aera__HashNotFound' },
219
+ { type: 'error', inputs: [], name: 'Aera__InvalidToken' },
220
+ { type: 'error', inputs: [], name: 'Aera__MaxDepositRefundTimeoutExceeded' },
221
+ { type: 'error', inputs: [], name: 'Aera__MaxTokensInExceeded' },
222
+ { type: 'error', inputs: [], name: 'Aera__MaxUnitsInExceeded' },
223
+ { type: 'error', inputs: [], name: 'Aera__MinTokensOutNotMet' },
224
+ { type: 'error', inputs: [], name: 'Aera__MinUnitsOutNotMet' },
225
+ { type: 'error', inputs: [], name: 'Aera__MultiplierOutOfRange' },
226
+ { type: 'error', inputs: [], name: 'Aera__PriceAndFeeCalculatorVaultPaused' },
227
+ { type: 'error', inputs: [], name: 'Aera__PullFundsSubmitDataNotSet' },
228
+ { type: 'error', inputs: [], name: 'Aera__ReceiverNotApproved' },
229
+ { type: 'error', inputs: [], name: 'Aera__RedeemCancellationCapNumeraireZero' },
230
+ { type: 'error', inputs: [], name: 'Aera__RedeemCancellationDetailsNotZero' },
231
+ { type: 'error', inputs: [], name: 'Aera__RedeemRequestCancellationDisabled' },
232
+ { type: 'error', inputs: [], name: 'Aera__RefundPeriodExpired' },
233
+ { type: 'error', inputs: [], name: 'Aera__RequestAmountExceedsRefundCap' },
234
+ { type: 'error', inputs: [], name: 'Aera__SolvingGateDisabled' },
235
+ { type: 'error', inputs: [], name: 'Aera__SolvingPaused' },
236
+ { type: 'error', inputs: [], name: 'Aera__SyncDepositDisabled' },
237
+ { type: 'error', inputs: [], name: 'Aera__SyncRedeemAbsoluteCapNumeraireZero' },
238
+ { type: 'error', inputs: [], name: 'Aera__SyncRedeemDisabled' },
239
+ { type: 'error', inputs: [], name: 'Aera__SyncRedeemEpochCapExceeded' },
240
+ { type: 'error', inputs: [], name: 'Aera__SyncRedeemMaxDynamicPremiumBpsTooHigh' },
241
+ { type: 'error', inputs: [], name: 'Aera__SyncRedeemMaxPriceAgeExceeded' },
242
+ { type: 'error', inputs: [], name: 'Aera__SyncRedeemMaxPriceAgeZero' },
243
+ { type: 'error', inputs: [], name: 'Aera__SyncRedeemNotConfigured' },
244
+ { type: 'error', inputs: [], name: 'Aera__SyncRedeemRelativeCapBpsTooHigh' },
245
+ { type: 'error', inputs: [], name: 'Aera__SyncRedeemRelativeCapBpsZero' },
246
+ { type: 'error', inputs: [], name: 'Aera__TokenCantBePriced' },
247
+ { type: 'error', inputs: [], name: 'Aera__TokensZero' },
248
+ { type: 'error', inputs: [], name: 'Aera__Unauthorized' },
249
+ { type: 'error', inputs: [], name: 'Aera__UnitsLocked' },
250
+ { type: 'error', inputs: [], name: 'Aera__UnitsZero' },
251
+ { type: 'error', inputs: [], name: 'Aera__ZeroAddressAuthority' },
252
+ { type: 'error', inputs: [], name: 'Aera__ZeroAddressMultiDepositorVault' },
253
+ { type: 'error', inputs: [], name: 'Aera__ZeroAddressPriceAndFeeCalculator' },
254
+ { type: 'error', inputs: [], name: 'Aera__ZeroAddressReceiver' },
255
+ { type: 'error', inputs: [], name: 'ReentrancyGuardReentrantCall' },
256
+ {
257
+ type: 'error',
258
+ inputs: [{ name: 'token', internalType: 'address', type: 'address' }],
259
+ name: 'SafeERC20FailedOperation',
260
+ },
202
261
  ] as const;
package/src/index.ts CHANGED
@@ -2,6 +2,8 @@ export { GauntletClient, AttributionMode } from './client';
2
2
  export type { GauntletClientConfig } from './client';
3
3
  export { ContractVersion } from './evm/types';
4
4
 
5
+ export * from './api';
6
+
5
7
  export type {
6
8
  VaultInfo,
7
9
  VaultDeployment,
@@ -0,0 +1,95 @@
1
+ import {
2
+ createPublicClient,
3
+ createWalletClient,
4
+ custom,
5
+ http,
6
+ type Address,
7
+ type Chain,
8
+ type EIP1193Provider,
9
+ type PublicClient,
10
+ type Transport,
11
+ type WalletClient,
12
+ } from 'viem';
13
+ import { AttributionMode, GauntletClient, type ChainId } from '../client';
14
+
15
+ /**
16
+ * Structural view of a Privy embedded or connected wallet — matches
17
+ * `ConnectedWallet` from `@privy-io/react-auth` (via `useWallets()`) and
18
+ * `PrivyClient`-side wallets without importing Privy types, so the SDK has no
19
+ * dependency on any `@privy-io` package.
20
+ */
21
+ export interface PrivyEthereumWallet {
22
+ /** The wallet's EVM address. */
23
+ address: string;
24
+ /** Privy's EIP-1193 provider factory for this wallet. */
25
+ getEthereumProvider(): Promise<EIP1193Provider>;
26
+ }
27
+
28
+ /**
29
+ * Wraps a Privy wallet in a viem `WalletClient` bound to `chain`, ready to
30
+ * sign SDK transaction steps.
31
+ *
32
+ * ```ts
33
+ * const { wallets } = useWallets();
34
+ * const wallet = await walletClientFromPrivy(wallets[0], base);
35
+ * ```
36
+ */
37
+ export async function walletClientFromPrivy(
38
+ wallet: PrivyEthereumWallet,
39
+ chain: Chain
40
+ ): Promise<WalletClient> {
41
+ const provider = await wallet.getEthereumProvider();
42
+ return createWalletClient({
43
+ account: wallet.address as Address,
44
+ chain,
45
+ transport: custom(provider),
46
+ });
47
+ }
48
+
49
+ export interface PrivyGauntletClientConfig {
50
+ /** The Privy wallet to sign with (e.g. `useWallets().wallets[0]`). */
51
+ wallet: PrivyEthereumWallet;
52
+ /** Chains the client should be able to read from; the first is the wallet's signing chain. */
53
+ chains: [Chain, ...Chain[]];
54
+ /** Per-chain transport override; defaults to each chain's public RPC via `http()`. */
55
+ transports?: Record<ChainId, Transport>;
56
+ apiKey?: string;
57
+ apiUrl?: string;
58
+ attributionMode?: AttributionMode;
59
+ builderCode?: string;
60
+ }
61
+
62
+ /**
63
+ * Opinionated one-call setup for Privy apps: builds public clients for each
64
+ * chain and a signing wallet from the Privy provider, returning a fully
65
+ * configured `GauntletClient`.
66
+ *
67
+ * ```ts
68
+ * const client = await createGauntletClientFromPrivy({
69
+ * wallet: wallets[0],
70
+ * chains: [base],
71
+ * builderCode: 'my-app',
72
+ * });
73
+ * const steps = await getDepositTx(client, { vaultId, amount });
74
+ * ```
75
+ */
76
+ export async function createGauntletClientFromPrivy(
77
+ config: PrivyGauntletClientConfig
78
+ ): Promise<GauntletClient> {
79
+ const evmClients: Record<ChainId, PublicClient> = {};
80
+ for (const chain of config.chains) {
81
+ evmClients[chain.id] = createPublicClient({
82
+ chain,
83
+ transport: config.transports?.[chain.id] ?? http(),
84
+ });
85
+ }
86
+
87
+ return new GauntletClient({
88
+ evmClients,
89
+ wallet: await walletClientFromPrivy(config.wallet, config.chains[0]),
90
+ apiKey: config.apiKey,
91
+ apiUrl: config.apiUrl,
92
+ attributionMode: config.attributionMode,
93
+ builderCode: config.builderCode,
94
+ });
95
+ }