@paxoslabs/amplify-sdk 0.0.1-alpha.3 → 0.0.2
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 +4 -479
- package/dist/{chunk-GBWBO6ZF.mjs → chunk-774KTF7A.mjs} +7 -7
- package/dist/chunk-774KTF7A.mjs.map +1 -0
- package/dist/{chunk-BXUG3WDV.js → chunk-ANL3PE7L.js} +8 -8
- package/dist/chunk-ANL3PE7L.js.map +1 -0
- package/dist/{chunk-ZCVMGIMV.js → chunk-BMN6KTOC.js} +11 -11
- package/dist/chunk-BMN6KTOC.js.map +1 -0
- package/dist/{chunk-YP2TR5RP.mjs → chunk-LVJ44U7Z.mjs} +8 -8
- package/dist/chunk-LVJ44U7Z.mjs.map +1 -0
- package/dist/{chunk-AIBI7ZQM.js → chunk-NLLEYTJ6.js} +8 -8
- package/dist/{chunk-AIBI7ZQM.js.map → chunk-NLLEYTJ6.js.map} +1 -1
- package/dist/{chunk-ZLS2AAMI.mjs → chunk-SYVANMRO.mjs} +3 -3
- package/dist/{chunk-ZLS2AAMI.mjs.map → chunk-SYVANMRO.mjs.map} +1 -1
- package/dist/core.d.mts +6 -6
- package/dist/core.d.ts +6 -6
- package/dist/core.js +13 -13
- package/dist/core.js.map +1 -1
- package/dist/core.mjs +5 -5
- package/dist/core.mjs.map +1 -1
- package/dist/display.d.mts +3 -3
- package/dist/display.d.ts +3 -3
- package/dist/display.js +13 -13
- package/dist/display.js.map +1 -1
- package/dist/display.mjs +7 -7
- package/dist/display.mjs.map +1 -1
- package/dist/{exchange-rate-CRA_CMaX.d.mts → exchange-rate-BfPH_fQt.d.mts} +4 -4
- package/dist/{exchange-rate-D3_FVgqa.d.ts → exchange-rate-Cp1ddpw4.d.ts} +4 -4
- package/dist/index.d.mts +11 -11
- package/dist/index.d.ts +11 -11
- package/dist/index.js +54 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +41 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
- package/dist/chunk-BXUG3WDV.js.map +0 -1
- package/dist/chunk-GBWBO6ZF.mjs.map +0 -1
- package/dist/chunk-YP2TR5RP.mjs.map +0 -1
- package/dist/chunk-ZCVMGIMV.js.map +0 -1
package/README.md
CHANGED
|
@@ -14,28 +14,6 @@ A TypeScript SDK for interacting with Paxos Labs Amplify Vaults, providing type-
|
|
|
14
14
|
[](https://www.npmjs.com/package/@paxoslabs/amplify-sdk)
|
|
15
15
|
[](https://opensource.org/licenses/MIT)
|
|
16
16
|
|
|
17
|
-
## Table of Contents
|
|
18
|
-
|
|
19
|
-
- [Features](#features)
|
|
20
|
-
- [Quick Start (5 Minutes)](#quick-start-5-minutes)
|
|
21
|
-
- [Documentation](#documentation)
|
|
22
|
-
- [Complete Guides](#-complete-guides)
|
|
23
|
-
- [Example Projects](#-example-projects)
|
|
24
|
-
- [Core API Overview](#core-api-overview)
|
|
25
|
-
- [Vault Discovery](#vault-discovery)
|
|
26
|
-
- [Cache Management](#cache-management)
|
|
27
|
-
- [Deposits](#deposits)
|
|
28
|
-
- [Permit Deposits (Gas-Optimized)](#permit-deposits-gas-optimized)
|
|
29
|
-
- [Withdrawals](#withdrawals)
|
|
30
|
-
- [TypeScript Support](#typescript-support)
|
|
31
|
-
- [Error Handling](#error-handling)
|
|
32
|
-
- [Supported Networks](#supported-networks)
|
|
33
|
-
- [Requirements](#requirements)
|
|
34
|
-
- [API Configuration](#api-configuration)
|
|
35
|
-
- [Available Vault Keys](#available-vault-keys)
|
|
36
|
-
- [Contributing](#contributing)
|
|
37
|
-
- [License](#license)
|
|
38
|
-
|
|
39
17
|
## Features
|
|
40
18
|
|
|
41
19
|
- **Vault Discovery** - Query available vaults and supported assets via API
|
|
@@ -47,9 +25,7 @@ A TypeScript SDK for interacting with Paxos Labs Amplify Vaults, providing type-
|
|
|
47
25
|
- **Full TypeScript Support** - Complete type definitions and autocomplete
|
|
48
26
|
- **React Ready** - Works with viem (vanilla) and wagmi (React hooks)
|
|
49
27
|
|
|
50
|
-
##
|
|
51
|
-
|
|
52
|
-
### 1. Installation
|
|
28
|
+
## Installation
|
|
53
29
|
|
|
54
30
|
```bash
|
|
55
31
|
# npm
|
|
@@ -65,469 +41,18 @@ pnpm add @paxoslabs/amplify-sdk viem
|
|
|
65
41
|
pnpm add wagmi @tanstack/react-query
|
|
66
42
|
```
|
|
67
43
|
|
|
68
|
-
### 2. Initialize the SDK
|
|
69
|
-
|
|
70
|
-
**⚠️ Required**: Initialize the SDK with your API key before using any functions.
|
|
71
|
-
|
|
72
|
-
```typescript
|
|
73
|
-
import { initAmplifySDK } from "@paxoslabs/amplify-sdk";
|
|
74
|
-
|
|
75
|
-
// Initialize SDK with your API key
|
|
76
|
-
await initAmplifySDK("pxl_your_api_key_here");
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
**Get Your API Key**: Contact Paxos Labs to request an API key for access.
|
|
80
|
-
|
|
81
|
-
**Environment Variables** (Recommended):
|
|
82
|
-
|
|
83
|
-
```bash
|
|
84
|
-
# .env file
|
|
85
|
-
PAXOS_API_KEY=pxl_your_api_key_here
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
```typescript
|
|
89
|
-
// In your app
|
|
90
|
-
await initAmplifySDK(process.env.PAXOS_API_KEY!);
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
**Features**:
|
|
94
|
-
|
|
95
|
-
- ✅ **Automatic Authentication**: All API calls include authentication headers
|
|
96
|
-
- ✅ **Cache Pre-population**: Vaults and assets cached during initialization
|
|
97
|
-
- ✅ **Idempotent**: Multiple calls with same key are safe (no-op)
|
|
98
|
-
- ✅ **Re-initialization**: Switch API keys at runtime for environment changes
|
|
99
|
-
|
|
100
|
-
### 3. Discover Available Vaults
|
|
101
|
-
|
|
102
|
-
```typescript
|
|
103
|
-
import { fetchVaults } from "@paxoslabs/amplify-sdk";
|
|
104
|
-
|
|
105
|
-
// Fetch all available vaults
|
|
106
|
-
const allVaults = await fetchVaults();
|
|
107
|
-
|
|
108
|
-
// Or filter by chain and yield type
|
|
109
|
-
const primeVaults = await fetchVaults({
|
|
110
|
-
chainId: 1, // Ethereum mainnet
|
|
111
|
-
yieldType: "PRIME",
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
console.log(`Found ${primeVaults.length} PRIME vaults on Ethereum`);
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
### 4. Find Supported Deposit Assets
|
|
118
|
-
|
|
119
|
-
```typescript
|
|
120
|
-
import { fetchSupportedAssets } from "@paxoslabs/amplify-sdk";
|
|
121
|
-
|
|
122
|
-
// Fetch assets supported for deposits
|
|
123
|
-
const assets = await fetchSupportedAssets({
|
|
124
|
-
chainId: 1, // Ethereum mainnet
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
// Find USDC
|
|
128
|
-
const usdc = assets.find((asset) => asset.symbol === "USDC");
|
|
129
|
-
console.log(`USDC address: ${usdc?.address}`);
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
### 5. Deposit into a Vault (Viem)
|
|
133
|
-
|
|
134
|
-
```typescript
|
|
135
|
-
import { createWalletClient, http } from "viem";
|
|
136
|
-
import { mainnet } from "viem/chains";
|
|
137
|
-
import { privateKeyToAccount } from "viem/accounts";
|
|
138
|
-
import {
|
|
139
|
-
prepareApproveDepositToken,
|
|
140
|
-
prepareDepositTransactionData,
|
|
141
|
-
isDepositSpendApproved,
|
|
142
|
-
} from "@paxoslabs/amplify-sdk";
|
|
143
|
-
|
|
144
|
-
// Setup viem client
|
|
145
|
-
const account = privateKeyToAccount("0x...");
|
|
146
|
-
const client = createWalletClient({
|
|
147
|
-
account,
|
|
148
|
-
chain: mainnet,
|
|
149
|
-
transport: http(),
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
async function deposit() {
|
|
153
|
-
const vaultKey = "op-nTBILL"; // T-Bill vault
|
|
154
|
-
const tokenSymbol = "USDC";
|
|
155
|
-
const amount = "1000.0"; // $1000 USDC
|
|
156
|
-
const chainId = 1;
|
|
157
|
-
|
|
158
|
-
// 1. Check if approval needed
|
|
159
|
-
const isApproved = await isDepositSpendApproved({
|
|
160
|
-
vaultKey,
|
|
161
|
-
userAddress: account.address,
|
|
162
|
-
depositTokenSymbol: tokenSymbol,
|
|
163
|
-
depositAmount: amount,
|
|
164
|
-
chainId,
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
// 2. Approve if needed
|
|
168
|
-
if (!isApproved) {
|
|
169
|
-
const approvalTx = await prepareApproveDepositToken({
|
|
170
|
-
vaultKey,
|
|
171
|
-
depositTokenSymbol: tokenSymbol,
|
|
172
|
-
depositAmount: amount,
|
|
173
|
-
chainId,
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
const approvalHash = await client.writeContract(approvalTx);
|
|
177
|
-
console.log(`Approval tx: ${approvalHash}`);
|
|
178
|
-
// Wait for approval confirmation...
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// 3. Prepare and execute deposit
|
|
182
|
-
const depositTx = await prepareDepositTransactionData({
|
|
183
|
-
vaultKey,
|
|
184
|
-
userAddress: account.address,
|
|
185
|
-
depositTokenSymbol: tokenSymbol,
|
|
186
|
-
depositAmount: amount,
|
|
187
|
-
chainId,
|
|
188
|
-
slippage: 100, // 1% slippage (100 basis points)
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
const depositHash = await client.writeContract(depositTx);
|
|
192
|
-
console.log(`Deposit tx: ${depositHash}`);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
deposit();
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
### 5. Deposit into a Vault (Wagmi + React)
|
|
199
|
-
|
|
200
|
-
```tsx
|
|
201
|
-
import { useAccount, useWriteContract } from "wagmi";
|
|
202
|
-
import {
|
|
203
|
-
prepareApproveDepositToken,
|
|
204
|
-
prepareDepositTransactionData,
|
|
205
|
-
isDepositSpendApproved,
|
|
206
|
-
} from "@paxoslabs/amplify-sdk";
|
|
207
|
-
|
|
208
|
-
function DepositComponent() {
|
|
209
|
-
const { address } = useAccount();
|
|
210
|
-
const { writeContract } = useWriteContract();
|
|
211
|
-
|
|
212
|
-
const handleDeposit = async () => {
|
|
213
|
-
if (!address) return;
|
|
214
|
-
|
|
215
|
-
const vaultKey = "op-nTBILL";
|
|
216
|
-
const tokenSymbol = "USDC";
|
|
217
|
-
const amount = "1000.0";
|
|
218
|
-
const chainId = 1;
|
|
219
|
-
|
|
220
|
-
try {
|
|
221
|
-
// Check approval
|
|
222
|
-
const isApproved = await isDepositSpendApproved({
|
|
223
|
-
vaultKey,
|
|
224
|
-
userAddress: address,
|
|
225
|
-
depositTokenSymbol: tokenSymbol,
|
|
226
|
-
depositAmount: amount,
|
|
227
|
-
chainId,
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
// Approve if needed
|
|
231
|
-
if (!isApproved) {
|
|
232
|
-
const approvalTx = await prepareApproveDepositToken({
|
|
233
|
-
vaultKey,
|
|
234
|
-
depositTokenSymbol: tokenSymbol,
|
|
235
|
-
depositAmount: amount,
|
|
236
|
-
chainId,
|
|
237
|
-
});
|
|
238
|
-
await writeContract(approvalTx);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// Execute deposit
|
|
242
|
-
const depositTx = await prepareDepositTransactionData({
|
|
243
|
-
vaultKey,
|
|
244
|
-
userAddress: address,
|
|
245
|
-
depositTokenSymbol: tokenSymbol,
|
|
246
|
-
depositAmount: amount,
|
|
247
|
-
chainId,
|
|
248
|
-
slippage: 100, // 1%
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
await writeContract(depositTx);
|
|
252
|
-
} catch (error) {
|
|
253
|
-
console.error("Deposit failed:", error);
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
|
|
257
|
-
return <button onClick={handleDeposit}>Deposit $1000 USDC</button>;
|
|
258
|
-
}
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
**That's it!** You've discovered vaults and executed your first deposit. ✨
|
|
262
|
-
|
|
263
44
|
## Documentation
|
|
264
45
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
- **[Getting Started Guide](./docs/getting-started.md)** - Detailed setup and first API call
|
|
268
|
-
- **[API Reference: Vault Discovery](./docs/api-reference/vault-discovery.md)** - Fetch vaults and assets
|
|
269
|
-
- **[API Reference: Deposits](./docs/api-reference/deposits.md)** - Standard deposit flows
|
|
270
|
-
- **[API Reference: Permit Deposits](./docs/api-reference/deposits-permit.md)** - Gas-optimized deposits
|
|
271
|
-
- **[API Reference: Withdrawals](./docs/api-reference/withdrawals.md)** - Withdrawal flows
|
|
272
|
-
- **[API Reference: Caching](./docs/api-reference/caching.md)** - Performance optimization
|
|
273
|
-
- **[API Reference: Types](./docs/api-reference/types.md)** - TypeScript type definitions
|
|
274
|
-
- **[Guide: Error Handling](./docs/guides/error-handling.md)** - Error patterns and recovery
|
|
275
|
-
- **[Guide: React Integration](./docs/guides/react-integration.md)** - React patterns and hooks
|
|
276
|
-
- **[Guide: Multi-Chain Operations](./docs/guides/multi-chain.md)** - Cross-chain deposits/withdrawals
|
|
277
|
-
|
|
278
|
-
### 💻 Example Projects
|
|
279
|
-
|
|
280
|
-
- **[Viem Deposit Example](./docs/examples/viem-deposit/)** - Executable viem deposit example
|
|
281
|
-
- **[Wagmi Deposit Example](./docs/examples/wagmi-deposit/)** - React wagmi deposit component
|
|
282
|
-
- **[Wagmi Withdrawal Example](./docs/examples/wagmi-withdraw/)** - React wagmi withdrawal component
|
|
283
|
-
|
|
284
|
-
## Core API Overview
|
|
285
|
-
|
|
286
|
-
### Vault Discovery
|
|
287
|
-
|
|
288
|
-
```typescript
|
|
289
|
-
import {
|
|
290
|
-
fetchVaults,
|
|
291
|
-
fetchSupportedAssets,
|
|
292
|
-
getWithdrawSupportedAssets,
|
|
293
|
-
} from "@paxoslabs/amplify-sdk";
|
|
294
|
-
|
|
295
|
-
// Discover vaults
|
|
296
|
-
const vaults = await fetchVaults({
|
|
297
|
-
chainId: 1,
|
|
298
|
-
yieldType: "PRIME", // or "TBILL", "LENDING"
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
// Discover deposit assets
|
|
302
|
-
const depositAssets = await fetchSupportedAssets({
|
|
303
|
-
chainId: 1,
|
|
304
|
-
symbol: "USDC",
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
// Discover withdrawal assets
|
|
308
|
-
const withdrawAssets = await getWithdrawSupportedAssets();
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
### Cache Management
|
|
312
|
-
|
|
313
|
-
```typescript
|
|
314
|
-
import {
|
|
315
|
-
initializeCache,
|
|
316
|
-
getVaultsFromCache,
|
|
317
|
-
getAssetsFromCache,
|
|
318
|
-
refreshVaultCache,
|
|
319
|
-
} from "@paxoslabs/amplify-sdk";
|
|
320
|
-
|
|
321
|
-
// Initialize cache (recommended at app startup)
|
|
322
|
-
await initializeCache();
|
|
323
|
-
|
|
324
|
-
// Use cached data (80% faster than API calls)
|
|
325
|
-
const cachedVaults = await getVaultsFromCache({ chainId: 1 });
|
|
326
|
-
const cachedAssets = await getAssetsFromCache({ symbol: "USDC" });
|
|
327
|
-
|
|
328
|
-
// Refresh cache periodically
|
|
329
|
-
await refreshVaultCache();
|
|
330
|
-
```
|
|
331
|
-
|
|
332
|
-
### Deposits
|
|
333
|
-
|
|
334
|
-
```typescript
|
|
335
|
-
import {
|
|
336
|
-
prepareDepositTransactionData,
|
|
337
|
-
prepareApproveDepositToken,
|
|
338
|
-
isDepositSpendApproved,
|
|
339
|
-
} from "@paxoslabs/amplify-sdk";
|
|
340
|
-
|
|
341
|
-
// Check approval status
|
|
342
|
-
const isApproved = await isDepositSpendApproved({
|
|
343
|
-
vaultKey: "op-nTBILL",
|
|
344
|
-
userAddress: "0x...",
|
|
345
|
-
depositTokenSymbol: "USDC",
|
|
346
|
-
depositAmount: "1000.0",
|
|
347
|
-
chainId: 1,
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
// Prepare approval transaction
|
|
351
|
-
const approvalTx = await prepareApproveDepositToken({
|
|
352
|
-
vaultKey: "op-nTBILL",
|
|
353
|
-
depositTokenSymbol: "USDC",
|
|
354
|
-
depositAmount: "1000.0",
|
|
355
|
-
chainId: 1,
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
// Prepare deposit transaction
|
|
359
|
-
const depositTx = await prepareDepositTransactionData({
|
|
360
|
-
vaultKey: "op-nTBILL",
|
|
361
|
-
userAddress: "0x...",
|
|
362
|
-
depositTokenSymbol: "USDC",
|
|
363
|
-
depositAmount: "1000.0",
|
|
364
|
-
chainId: 1,
|
|
365
|
-
slippage: 100, // 1% (100 basis points)
|
|
366
|
-
});
|
|
367
|
-
```
|
|
368
|
-
|
|
369
|
-
### Permit Deposits (Gas-Optimized)
|
|
370
|
-
|
|
371
|
-
```typescript
|
|
372
|
-
import {
|
|
373
|
-
prepareDepositWithPermitTransactionData,
|
|
374
|
-
type PrepareDepositWithPermitTransactionDataParams,
|
|
375
|
-
} from "@paxoslabs/amplify-sdk";
|
|
376
|
-
|
|
377
|
-
// Sign permit message off-chain (using viem or wagmi)
|
|
378
|
-
const signature = await signTypedData({
|
|
379
|
-
/* permit EIP-2612 typed data */
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
// Execute deposit with permit in single transaction
|
|
383
|
-
const permitDepositTx = await prepareDepositWithPermitTransactionData({
|
|
384
|
-
vaultKey: "op-nTBILL",
|
|
385
|
-
userAddress: "0x...",
|
|
386
|
-
depositTokenSymbol: "USDC",
|
|
387
|
-
depositAmount: "1000.0",
|
|
388
|
-
chainId: 1,
|
|
389
|
-
permitSignature: signature,
|
|
390
|
-
deadline: Math.floor(Date.now() / 1000) + 3600, // 1 hour
|
|
391
|
-
});
|
|
392
|
-
```
|
|
393
|
-
|
|
394
|
-
### Withdrawals
|
|
395
|
-
|
|
396
|
-
```typescript
|
|
397
|
-
import {
|
|
398
|
-
prepareWithdrawTransactionData,
|
|
399
|
-
prepareApproveWithdrawToken,
|
|
400
|
-
isWithdrawalSpendApproved,
|
|
401
|
-
} from "@paxoslabs/amplify-sdk";
|
|
402
|
-
|
|
403
|
-
// Check if vault shares are approved
|
|
404
|
-
const isApproved = await isWithdrawalSpendApproved({
|
|
405
|
-
vaultKey: "op-nTBILL",
|
|
406
|
-
userAddress: "0x...",
|
|
407
|
-
withdrawAmount: "100.0", // vault shares
|
|
408
|
-
chainId: 1,
|
|
409
|
-
});
|
|
410
|
-
|
|
411
|
-
// Approve vault shares
|
|
412
|
-
const approvalTx = await prepareApproveWithdrawToken({
|
|
413
|
-
vaultKey: "op-nTBILL",
|
|
414
|
-
withdrawAmount: "100.0",
|
|
415
|
-
chainId: 1,
|
|
416
|
-
});
|
|
417
|
-
|
|
418
|
-
// Withdraw assets
|
|
419
|
-
const withdrawTx = await prepareWithdrawTransactionData({
|
|
420
|
-
vaultKey: "op-nTBILL",
|
|
421
|
-
chainId: 1,
|
|
422
|
-
userAddress: "0x...",
|
|
423
|
-
wantTokenSymbol: "USDC",
|
|
424
|
-
offerAmount: "100.0", // vault shares to redeem
|
|
425
|
-
deadline: Math.floor(Date.now() / 1000) + 3600, // 1 hour
|
|
426
|
-
slippage: 100, // 1%
|
|
427
|
-
});
|
|
428
|
-
```
|
|
429
|
-
|
|
430
|
-
## TypeScript Support
|
|
431
|
-
|
|
432
|
-
Full type definitions with autocomplete:
|
|
433
|
-
|
|
434
|
-
```typescript
|
|
435
|
-
import type {
|
|
436
|
-
AmplifyVault,
|
|
437
|
-
SupportedAsset,
|
|
438
|
-
VaultFilterOptions,
|
|
439
|
-
VaultKey,
|
|
440
|
-
ChainId,
|
|
441
|
-
DepositTransactionData,
|
|
442
|
-
WithdrawTransactionData,
|
|
443
|
-
PrepareDepositTransactionDataParams,
|
|
444
|
-
} from "@paxoslabs/amplify-sdk";
|
|
445
|
-
|
|
446
|
-
// All functions have full TypeScript support
|
|
447
|
-
const depositData: DepositTransactionData = await prepareDepositTransactionData(
|
|
448
|
-
{
|
|
449
|
-
// TypeScript provides autocomplete and validation
|
|
450
|
-
}
|
|
451
|
-
);
|
|
452
|
-
```
|
|
453
|
-
|
|
454
|
-
## Error Handling
|
|
455
|
-
|
|
456
|
-
```typescript
|
|
457
|
-
import { APIError } from "@paxoslabs/amplify-sdk";
|
|
458
|
-
|
|
459
|
-
try {
|
|
460
|
-
const vaults = await fetchVaults({ chainId: 1 });
|
|
461
|
-
} catch (error) {
|
|
462
|
-
if (error instanceof APIError) {
|
|
463
|
-
console.error(`API Error: ${error.message}`);
|
|
464
|
-
console.error(`Endpoint: ${error.context?.endpoint}`);
|
|
465
|
-
console.error(`Status: ${error.context?.status}`);
|
|
466
|
-
} else {
|
|
467
|
-
console.error("Unexpected error:", error);
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
```
|
|
471
|
-
|
|
472
|
-
## Supported Networks
|
|
473
|
-
|
|
474
|
-
| Network | Chain ID | Status |
|
|
475
|
-
| ---------------- | ---------- | ------ |
|
|
476
|
-
| Ethereum Mainnet | 1 | ✅ |
|
|
477
|
-
| HyperEVM | 999 | ✅ |
|
|
478
|
-
| Boba Network | 288 | ✅ |
|
|
479
|
-
| Sei Network | 713715 | ✅ |
|
|
480
|
-
| Plume Mainnet | 98866 | ✅ |
|
|
481
|
-
| Form Network | 478 | ✅ |
|
|
482
|
-
| Swell Mainnet | 1923 | ✅ |
|
|
483
|
-
| Rari Chain | 1380012617 | ✅ |
|
|
484
|
-
|
|
485
|
-
## Requirements
|
|
486
|
-
|
|
487
|
-
- **Node.js** >= 20
|
|
488
|
-
- **TypeScript** >= 4.9.0 (optional but recommended)
|
|
489
|
-
- **viem** >= 2.0.0 (required)
|
|
490
|
-
- **wagmi** >= 2.0.0 (for React applications)
|
|
491
|
-
- **@tanstack/react-query** >= 5.0.0 (for React applications)
|
|
492
|
-
|
|
493
|
-
## API Configuration
|
|
494
|
-
|
|
495
|
-
The SDK connects to the Amplify API at `http://localhost:8500` by default. This is suitable for development environments. For production deployments, you'll need to configure the API endpoint according to your backend setup.
|
|
496
|
-
|
|
497
|
-
**Note**: All API calls have a 10-second timeout. Network requests that exceed this timeout will throw an `APIError`.
|
|
498
|
-
|
|
499
|
-
## Available Vault Keys
|
|
500
|
-
|
|
501
|
-
```typescript
|
|
502
|
-
import { VaultKeys } from "@paxoslabs/amplify-sdk";
|
|
503
|
-
|
|
504
|
-
console.log(VaultKeys);
|
|
505
|
-
// {
|
|
506
|
-
// OPNALPHA: "op-nALPHA",
|
|
507
|
-
// OPNBASIS: "op-nBASIS",
|
|
508
|
-
// OPNETF: "op-nETF",
|
|
509
|
-
// OPNPAYFI: "op-nPAYFI",
|
|
510
|
-
// OPNPLUME: "op-PLUME",
|
|
511
|
-
// OPNRWA: "op-nRWA",
|
|
512
|
-
// OPNTBILL: "op-nTBILL",
|
|
513
|
-
// OPPUSD: "op-pUSD",
|
|
514
|
-
// XLHYPE: "XLHYPE",
|
|
515
|
-
// CAMPUSD: "campUSD"
|
|
516
|
-
// }
|
|
517
|
-
```
|
|
518
|
-
|
|
519
|
-
## Contributing
|
|
520
|
-
|
|
521
|
-
Contributions are welcome! Please read our [Contributing Guide](./CONTRIBUTING.md) for details on our code of conduct and the process for submitting pull requests.
|
|
46
|
+
Full documentation at https://developers.paxoslabs.com/
|
|
522
47
|
|
|
523
48
|
## License
|
|
524
49
|
|
|
525
|
-
|
|
50
|
+
BSD © Paxos Labs
|
|
526
51
|
|
|
527
52
|
---
|
|
528
53
|
|
|
529
54
|
**Need Help?**
|
|
530
55
|
|
|
531
|
-
- 📖 [Full Documentation](./docs/getting-started.
|
|
56
|
+
- 📖 [Full Documentation](./docs/getting-started.mdx)
|
|
532
57
|
- 🐛 [Report Issues](https://github.com/Ion-Protocol/amplify-sdk/issues)
|
|
533
58
|
- 💬 [GitHub Discussions](https://github.com/Ion-Protocol/amplify-sdk/discussions)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getErc20AllowanceWithDecimals, getRateInQuoteWithAssetDecimals } from './chunk-
|
|
1
|
+
import { getErc20AllowanceWithDecimals, getRateInQuoteWithAssetDecimals } from './chunk-LVJ44U7Z.mjs';
|
|
2
2
|
import { getVaultByKey } from './chunk-R663BFAZ.mjs';
|
|
3
3
|
import { toChainId } from './chunk-J3662HYT.mjs';
|
|
4
4
|
import { bigIntToNumberAsString } from './chunk-7RWWVUHP.mjs';
|
|
@@ -9,7 +9,7 @@ var isDepositSpendApproved = async ({
|
|
|
9
9
|
yieldType,
|
|
10
10
|
chainId,
|
|
11
11
|
depositAssetAddress,
|
|
12
|
-
|
|
12
|
+
recipientAddress
|
|
13
13
|
}) => {
|
|
14
14
|
try {
|
|
15
15
|
const normalizedChainId = toChainId(chainId);
|
|
@@ -38,7 +38,7 @@ var isDepositSpendApproved = async ({
|
|
|
38
38
|
const [allowance, decimals] = await getErc20AllowanceWithDecimals({
|
|
39
39
|
chainId: normalizedChainId,
|
|
40
40
|
tokenAddress: depositAssetAddress,
|
|
41
|
-
|
|
41
|
+
recipientAddress,
|
|
42
42
|
spenderAddress: boringVaultAddress
|
|
43
43
|
});
|
|
44
44
|
if (allowance.status === "failure" || decimals.status === "failure") {
|
|
@@ -73,7 +73,7 @@ var isWithdrawalSpendApproved = async ({
|
|
|
73
73
|
yieldType,
|
|
74
74
|
chainId,
|
|
75
75
|
wantAssetAddress,
|
|
76
|
-
|
|
76
|
+
recipientAddress
|
|
77
77
|
}) => {
|
|
78
78
|
try {
|
|
79
79
|
const normalizedChainId = toChainId(chainId);
|
|
@@ -102,7 +102,7 @@ var isWithdrawalSpendApproved = async ({
|
|
|
102
102
|
const [allowance, decimals] = await getErc20AllowanceWithDecimals({
|
|
103
103
|
chainId: normalizedChainId,
|
|
104
104
|
tokenAddress: boringVaultAddress,
|
|
105
|
-
|
|
105
|
+
recipientAddress,
|
|
106
106
|
spenderAddress: ATOMIC_QUEUE_CONTRACT_ADDRESS
|
|
107
107
|
});
|
|
108
108
|
if (allowance.status === "failure" || decimals.status === "failure") {
|
|
@@ -224,5 +224,5 @@ var getWithdrawExchangeRate = async ({
|
|
|
224
224
|
};
|
|
225
225
|
|
|
226
226
|
export { getDepositExchangeRate, getWithdrawExchangeRate, isDepositSpendApproved, isWithdrawalSpendApproved };
|
|
227
|
-
//# sourceMappingURL=chunk-
|
|
228
|
-
//# sourceMappingURL=chunk-
|
|
227
|
+
//# sourceMappingURL=chunk-774KTF7A.mjs.map
|
|
228
|
+
//# sourceMappingURL=chunk-774KTF7A.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/display/approvals.ts","../src/display/exchange-rate.ts"],"names":[],"mappings":";;;;;;;AAOO,IAAM,yBAAyB,OAAO;AAAA,EAC3C,SAAA;AAAA,EACA,OAAA;AAAA,EACA,mBAAA;AAAA,EACA;AACF,CAAA,KAKM;AACJ,EAAA,IAAI;AACF,IAAA,MAAM,iBAAA,GAAoB,UAAU,OAAO,CAAA;AAC3C,IAAA,MAAM,MAAA,GAAS,MAAM,iBAAA,CAAkB;AAAA,MACrC,SAAA;AAAA,MACA,OAAA,EAAS,iBAAA;AAAA,MACT,YAAA,EAAc;AAAA,KACf,CAAA;AAED,IAAA,IAAI,CAAC,MAAA,EAAQ;AACX,MAAA,MAAM,IAAI,QAAA;AAAA,QACR,CAAA,oBAAA,EAAuB,SAAS,CAAA,UAAA,EAAa,iBAAiB,CAAA,CAAA;AAAA,QAC9D;AAAA,UACE,QAAA,EAAU;AAAA;AACZ,OACF;AAAA,IACF;AAEA,IAAA,MAAM,kBAAA,GAAqB,OAAO,KAAA,CAAM,kBAAA;AACxC,IAAA,IAAI,CAAC,kBAAA,EAAoB;AACvB,MAAA,MAAM,IAAI,QAAA;AAAA,QACR,CAAA,sDAAA,EAAyD,OAAO,EAAE,CAAA,CAAA;AAAA,QAClE;AAAA,UACE,QAAA,EAAU;AAAA;AACZ,OACF;AAAA,IACF;AAEA,IAAA,MAAM,CAAC,SAAA,EAAW,QAAQ,CAAA,GAAI,MAAM,6BAAA,CAA8B;AAAA,MA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":["import { type Address, formatUnits } from \"viem\";\nimport { findVaultByConfig } from \"../api/amplify-sdk-client\";\nimport { getErc20AllowanceWithDecimals } from \"../api/erc20\";\nimport { type ChainId, toChainId } from \"../api/vault-config\";\nimport { ATOMIC_QUEUE_CONTRACT_ADDRESS } from \"../constants\";\nimport { APIError, type YieldType } from \"../types/amplify-sdk-api\";\n\nexport const isDepositSpendApproved = async ({\n yieldType,\n chainId,\n depositAssetAddress,\n recipientAddress,\n}: {\n yieldType: YieldType;\n chainId: ChainId;\n depositAssetAddress: Address;\n recipientAddress: Address;\n}) => {\n try {\n const normalizedChainId = toChainId(chainId);\n const config = await findVaultByConfig({\n yieldType,\n chainId: normalizedChainId,\n assetAddress: depositAssetAddress,\n });\n\n if (!config) {\n throw new APIError(\n `Vault not found for ${yieldType} on chain ${normalizedChainId}`,\n {\n endpoint: \"isDepositSpendApproved\",\n }\n );\n }\n\n const boringVaultAddress = config.vault.boringVaultAddress;\n if (!boringVaultAddress) {\n throw new APIError(\n `BoringVault contract address not configured for vault ${config.id}`,\n {\n endpoint: \"isDepositSpendApproved\",\n }\n );\n }\n\n const [allowance, decimals] = await getErc20AllowanceWithDecimals({\n chainId: normalizedChainId,\n tokenAddress: depositAssetAddress,\n recipientAddress: recipientAddress,\n spenderAddress: boringVaultAddress,\n });\n\n if (allowance.status === \"failure\" || decimals.status === \"failure\") {\n throw new APIError(\n `Failed to get allowance: ${allowance.error || decimals.error}`,\n {\n endpoint: \"isDepositSpendApproved\",\n }\n );\n }\n\n return {\n isApproved: allowance.result > 0n,\n allowance: formatUnits(allowance.result, decimals.result),\n allowanceAsBigInt: allowance.result.toString(),\n decimals: decimals.result,\n error: null,\n };\n } catch (error) {\n if (error instanceof APIError) {\n throw error;\n }\n\n // Wrap other errors\n throw new APIError(\n `Failed to check deposit approval: ${\n error instanceof Error ? error.message : String(error)\n }`,\n {\n endpoint: \"isDepositSpendApproved\",\n cause: error,\n }\n );\n }\n};\n\nexport const isWithdrawalSpendApproved = async ({\n yieldType,\n chainId,\n wantAssetAddress,\n recipientAddress,\n}: {\n yieldType: YieldType;\n chainId: ChainId;\n wantAssetAddress: Address;\n recipientAddress: Address;\n}) => {\n try {\n const normalizedChainId = toChainId(chainId);\n\n const config = await findVaultByConfig({\n yieldType,\n chainId: normalizedChainId,\n assetAddress: wantAssetAddress,\n });\n\n if (!config) {\n throw new APIError(\n `Vault not found for ${yieldType} on chain ${normalizedChainId}`,\n {\n endpoint: \"isWithdrawalSpendApproved\",\n }\n );\n }\n\n const boringVaultAddress = config.vault.boringVaultAddress;\n\n if (!boringVaultAddress) {\n throw new APIError(\n `BoringVault contract address not configured for vault ${config.id}`,\n {\n endpoint: \"isWithdrawalSpendApproved\",\n }\n );\n }\n\n const [allowance, decimals] = await getErc20AllowanceWithDecimals({\n chainId: normalizedChainId,\n tokenAddress: boringVaultAddress,\n recipientAddress: recipientAddress,\n spenderAddress: ATOMIC_QUEUE_CONTRACT_ADDRESS,\n });\n\n if (allowance.status === \"failure\" || decimals.status === \"failure\") {\n return {\n isApproved: false,\n allowance: \"0\",\n allowanceAsBigInt: \"0\",\n decimals: \"0\",\n error: allowance.error || decimals.error,\n };\n }\n\n return {\n isApproved: allowance.result > 0n,\n allowance: formatUnits(allowance.result, decimals.result),\n allowanceAsBigInt: allowance.result.toString(),\n decimals: decimals.result,\n error: null,\n };\n } catch (error) {\n if (error instanceof APIError) {\n throw error;\n }\n\n throw new APIError(\n `Failed to check withdrawal approval: ${\n error instanceof Error ? error.message : String(error)\n }`,\n { endpoint: \"isWithdrawalSpendApproved\", cause: error }\n );\n }\n};\n","import { getRateInQuoteWithAssetDecimals } from \"../api/accountant\";\nimport type { ChainId } from \"../api/vault-config\";\nimport { bigIntToNumberAsString } from \"../utils/bigint\";\nimport { getVaultByKey } from \"../vaults\";\nimport type { VaultKey } from \"../vaults/config\";\n\ninterface GetDepositExchangeRateParams {\n vaultKey: VaultKey;\n sourceChainId: ChainId;\n depositTokenSymbol: string;\n minimumFractionDigits?: number;\n maximumFractionDigits?: number;\n}\n\n/**\n * Gets the deposit exchange rate for a vault (tokens per share)\n * @throws {Error} If the token address is not found or if there's an error fetching the rate\n * @returns Promise<string> The exchange rate as a formatted string representing how many deposit tokens are worth 1 share\n */\nconst getDepositExchangeRate = async ({\n vaultKey,\n sourceChainId,\n depositTokenSymbol,\n minimumFractionDigits,\n maximumFractionDigits = 3,\n}: GetDepositExchangeRateParams) => {\n const vault = await getVaultByKey(vaultKey);\n\n const sourceChain = vault.deposit.sourceChains[sourceChainId];\n if (!sourceChain) {\n throw new Error(\n `Source chain ${sourceChainId} not found for vault ${vaultKey}`\n );\n }\n\n const depositToken = sourceChain.depositTokens?.[depositTokenSymbol];\n if (!depositToken) {\n throw new Error(\n `Deposit token ${depositTokenSymbol} not found for chain ${sourceChainId}`\n );\n }\n\n const tokenAddress = depositToken.address;\n if (!tokenAddress) {\n throw new Error(`Token address not found for ${depositTokenSymbol}`);\n }\n\n const [decimals, rate] = await getRateInQuoteWithAssetDecimals({\n assetAddress: tokenAddress,\n accountantAddress: vault.contracts.accountant,\n chainId: sourceChainId,\n });\n\n if (rate.status === \"failure\") {\n throw new Error(`Failed to get rate: ${rate.error.message}`);\n }\n if (decimals.status === \"failure\") {\n throw new Error(`Failed to get decimals: ${decimals.error.message}`);\n }\n\n return bigIntToNumberAsString(rate.result, {\n decimals: decimals.result,\n minimumFractionDigits,\n maximumFractionDigits,\n });\n};\n\ninterface GetWithdrawExchangeRateParams {\n vaultKey: VaultKey;\n sourceChainId: ChainId;\n destinationChainId: ChainId;\n wantTokenSymbol: string;\n minimumFractionDigits?: number;\n maximumFractionDigits?: number;\n}\n\n/**\n * Gets the withdraw exchange rate for a vault (tokens per share)\n * @throws {Error} If the token address is not found or if there's an error fetching the rate\n * @returns Promise<string> The exchange rate as a formatted string representing how many want tokens are worth 1 share\n */\nconst getWithdrawExchangeRate = async ({\n vaultKey,\n sourceChainId,\n destinationChainId,\n wantTokenSymbol,\n minimumFractionDigits,\n maximumFractionDigits = 3,\n}: GetWithdrawExchangeRateParams) => {\n const vault = await getVaultByKey(vaultKey);\n\n const sourceChain = vault.withdraw.sourceChains[sourceChainId];\n if (!sourceChain) {\n throw new Error(\n `Source chain ${sourceChainId} not found for vault ${vaultKey}`\n );\n }\n\n const destinationChain = sourceChain.destinationChains[destinationChainId];\n if (!destinationChain) {\n throw new Error(\n `Destination chain ${destinationChainId} not found for source chain ${sourceChainId}`\n );\n }\n\n const wantToken = destinationChain.wantTokens?.[wantTokenSymbol];\n if (!wantToken) {\n throw new Error(\n `Want token ${wantTokenSymbol} not found for chain ${destinationChainId}`\n );\n }\n\n const tokenAddress = wantToken.address;\n if (!tokenAddress) {\n throw new Error(`Token address not found for ${wantTokenSymbol}`);\n }\n\n const [decimals, rate] = await getRateInQuoteWithAssetDecimals({\n assetAddress: tokenAddress,\n accountantAddress: vault.contracts.accountant,\n chainId: sourceChainId,\n });\n\n if (rate.status === \"failure\") {\n throw new Error(`Failed to get rate: ${rate.error.message}`);\n }\n if (decimals.status === \"failure\") {\n throw new Error(`Failed to get decimals: ${decimals.error.message}`);\n }\n\n return bigIntToNumberAsString(rate.result, {\n decimals: decimals.result,\n minimumFractionDigits,\n maximumFractionDigits,\n });\n};\n\nexport { getDepositExchangeRate, getWithdrawExchangeRate };\n"]}
|
|
@@ -43,14 +43,14 @@ var getClient = async (chainId) => {
|
|
|
43
43
|
var getErc20Balance = async ({
|
|
44
44
|
chainId,
|
|
45
45
|
tokenAddress,
|
|
46
|
-
|
|
46
|
+
recipientAddress
|
|
47
47
|
}) => {
|
|
48
48
|
const client = await getClient(chainId);
|
|
49
49
|
const balance = await client.readContract({
|
|
50
50
|
abi: viem.erc20Abi,
|
|
51
51
|
address: tokenAddress,
|
|
52
52
|
functionName: "balanceOf",
|
|
53
|
-
args: [
|
|
53
|
+
args: [recipientAddress]
|
|
54
54
|
});
|
|
55
55
|
return balance;
|
|
56
56
|
};
|
|
@@ -69,7 +69,7 @@ var getErc20Decimals = async ({
|
|
|
69
69
|
var getErc20Allowance = async ({
|
|
70
70
|
chainId,
|
|
71
71
|
tokenAddress,
|
|
72
|
-
|
|
72
|
+
recipientAddress,
|
|
73
73
|
spenderAddress
|
|
74
74
|
}) => {
|
|
75
75
|
const client = await getClient(chainId);
|
|
@@ -77,14 +77,14 @@ var getErc20Allowance = async ({
|
|
|
77
77
|
abi: viem.erc20Abi,
|
|
78
78
|
address: tokenAddress,
|
|
79
79
|
functionName: "allowance",
|
|
80
|
-
args: [
|
|
80
|
+
args: [recipientAddress, spenderAddress]
|
|
81
81
|
});
|
|
82
82
|
return allowance;
|
|
83
83
|
};
|
|
84
84
|
var getErc20AllowanceWithDecimals = async ({
|
|
85
85
|
chainId,
|
|
86
86
|
tokenAddress,
|
|
87
|
-
|
|
87
|
+
recipientAddress,
|
|
88
88
|
spenderAddress
|
|
89
89
|
}) => {
|
|
90
90
|
const client = await getClient(chainId);
|
|
@@ -94,7 +94,7 @@ var getErc20AllowanceWithDecimals = async ({
|
|
|
94
94
|
abi: viem.erc20Abi,
|
|
95
95
|
address: tokenAddress,
|
|
96
96
|
functionName: "allowance",
|
|
97
|
-
args: [
|
|
97
|
+
args: [recipientAddress, spenderAddress]
|
|
98
98
|
},
|
|
99
99
|
{
|
|
100
100
|
abi: viem.erc20Abi,
|
|
@@ -2082,5 +2082,5 @@ exports.getErc20Balance = getErc20Balance;
|
|
|
2082
2082
|
exports.getErc20Decimals = getErc20Decimals;
|
|
2083
2083
|
exports.getRateInQuoteAndSharesAndWantAssetDecimals = getRateInQuoteAndSharesAndWantAssetDecimals;
|
|
2084
2084
|
exports.getRateInQuoteWithAssetDecimals = getRateInQuoteWithAssetDecimals;
|
|
2085
|
-
//# sourceMappingURL=chunk-
|
|
2086
|
-
//# sourceMappingURL=chunk-
|
|
2085
|
+
//# sourceMappingURL=chunk-ANL3PE7L.js.map
|
|
2086
|
+
//# sourceMappingURL=chunk-ANL3PE7L.js.map
|