@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
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
<!-- auto-changelog-above -->
|
|
9
|
+
|
|
10
|
+
## [Unreleased]
|
|
11
|
+
|
|
12
|
+
### BREAKING CHANGES
|
|
13
|
+
|
|
14
|
+
- **Product Rename**: Earn SDK renamed to Amplify SDK
|
|
15
|
+
- Package name: `@paxoslabs/earn-sdk` → `@paxoslabs/amplify-sdk`
|
|
16
|
+
- Function: `initEarnSDK()` → `initAmplifySDK()`
|
|
17
|
+
- Type: `AmplifyVault` → `AmplifyVault`
|
|
18
|
+
- Repository: `Ion-Protocol/earn-sdk` → `Ion-Protocol/amplify-sdk`
|
|
19
|
+
- 7 source files renamed (earn-* → amplify-*)
|
|
20
|
+
|
|
21
|
+
### Migration Guide
|
|
22
|
+
|
|
23
|
+
**For Existing Users**:
|
|
24
|
+
|
|
25
|
+
1. Update package in `package.json`:
|
|
26
|
+
```bash
|
|
27
|
+
npm uninstall @paxoslabs/earn-sdk
|
|
28
|
+
npm install @paxoslabs/amplify-sdk
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
2. Update import statements:
|
|
32
|
+
```typescript
|
|
33
|
+
// Old
|
|
34
|
+
import { initEarnSDK, type EarnVault } from "@paxoslabs/earn-sdk";
|
|
35
|
+
|
|
36
|
+
// New
|
|
37
|
+
import { initAmplifySDK, type AmplifyVault } from "@paxoslabs/amplify-sdk";
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
3. Update function calls:
|
|
41
|
+
```typescript
|
|
42
|
+
// Old
|
|
43
|
+
await initEarnSDK("pxl_internal_your_api_key");
|
|
44
|
+
|
|
45
|
+
// New
|
|
46
|
+
await initAmplifySDK("pxl_internal_your_api_key");
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
4. Update type references:
|
|
50
|
+
```typescript
|
|
51
|
+
// Old
|
|
52
|
+
const vault: EarnVault = ...;
|
|
53
|
+
|
|
54
|
+
// New
|
|
55
|
+
const vault: AmplifyVault = ...;
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Notes
|
|
59
|
+
- API endpoints continue to use `/v1/earn-sdk/*` for backwards compatibility
|
|
60
|
+
- No changes required to backend integration
|
|
61
|
+
- Old package `@paxoslabs/earn-sdk` will be deprecated but remain functional
|
|
62
|
+
- Endpoint migration to `/v1/amplify-sdk/*` planned for future release
|
|
63
|
+
|
|
64
|
+
### Documentation
|
|
65
|
+
- **Comprehensive SDK Documentation (Phase 008)**:
|
|
66
|
+
- Complete README.md overhaul with 5-minute quick start guide
|
|
67
|
+
- New documentation structure under `docs/`:
|
|
68
|
+
- `getting-started.md` - Detailed installation and first API call guide
|
|
69
|
+
- `api-reference/` - Complete API documentation for all SDK functions
|
|
70
|
+
- `vault-discovery.md` - Vault and asset discovery via Amplify API
|
|
71
|
+
- `deposits.md` - Standard deposit flows (viem + wagmi patterns)
|
|
72
|
+
- `deposits-permit.md` - Gas-optimized permit deposits (EIP-2612)
|
|
73
|
+
- `withdrawals.md` - Complete withdrawal flows with deadline protection
|
|
74
|
+
- `caching.md` - Performance optimization with vault caching
|
|
75
|
+
- `types.md` - TypeScript type definitions reference
|
|
76
|
+
- `guides/` - Tutorial-style integration guides
|
|
77
|
+
- `react-integration.md` - Three React patterns (direct, custom hooks, TanStack Query)
|
|
78
|
+
- `error-handling.md` - Error handling patterns for API and transactions
|
|
79
|
+
- `multi-chain.md` - Multi-chain deployment and chain selection
|
|
80
|
+
- `examples/` - Fully executable example projects
|
|
81
|
+
- `viem-deposit/` - Complete viem deposit example with tests
|
|
82
|
+
- `wagmi-deposit/` - Complete wagmi deposit example with React hooks
|
|
83
|
+
- `wagmi-withdraw/` - Complete wagmi withdrawal example
|
|
84
|
+
- 56 viem code examples and 33 wagmi code examples across all documentation
|
|
85
|
+
- 100% coverage of all 48 functional requirements
|
|
86
|
+
- All code examples are TypeScript with full type safety
|
|
87
|
+
- MSW (Mock Service Worker) integration for runnable examples
|
|
88
|
+
- Validation script for documentation quality assurance
|
|
89
|
+
|
|
90
|
+
## [0.0.1-alpha.1] - 2025-11-01
|
|
91
|
+
|
|
92
|
+
### Features
|
|
93
|
+
- Initial SDK implementation with comprehensive AmplifyVault support
|
|
94
|
+
- Multi-chain support (PRIME) Earn vaults
|
|
95
|
+
- Complete deposit functionality with approval management and slippage protection
|
|
96
|
+
- Cross-chain bridging support for deposit and withdrawal flows
|
|
97
|
+
- **New Withdraw Flow (Phase 5)**:
|
|
98
|
+
- Prepare withdrawal transactions with `prepareWithdrawTransactionData()`
|
|
99
|
+
- Automatic vault data fetching and caching via `fetchSupportedAssets()`
|
|
100
|
+
- Three-field vault resolution (yieldType + wantToken + chainId)
|
|
101
|
+
- Configurable slippage protection (default 1%, in basis points)
|
|
102
|
+
- Full TypeScript type safety for all withdraw operations
|
|
103
|
+
- Comprehensive error handling with specific error codes
|
|
104
|
+
- Exchange rate calculations and approval management
|
|
105
|
+
- Complete TypeScript support with full type safety
|
|
106
|
+
|
|
107
|
+
### Build System
|
|
108
|
+
- Added automated release workflow with conventional commits
|
|
109
|
+
- Configured semantic versioning with alpha/beta/rc support
|
|
110
|
+
- Implemented comprehensive CI/CD pipeline with quality gates
|
|
111
|
+
- Added security auditing and dependency scanning
|
|
112
|
+
- Configured automated NPM publishing with provenance
|
package/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025, PaxosLabs
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,533 @@
|
|
|
1
|
+
```
|
|
2
|
+
_____ .__ .__ _____ _________________ ____ __.
|
|
3
|
+
/ _ \ _____ ______ | | |__|/ ____\__.__. / _____/\______ \ | |/ _|
|
|
4
|
+
/ /_\ \ / \\____ \| | | \ __< | | \_____ \ | | \| <
|
|
5
|
+
/ | \ Y Y \ |_> > |_| || | \___ | / \ | ` \ | \
|
|
6
|
+
\____|__ /__|_| / __/|____/__||__| / ____| /_______ //_______ /____|__ \
|
|
7
|
+
\/ \/|__| \/ \/ \/ \/
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
# Paxos Labs Amplify SDK
|
|
11
|
+
|
|
12
|
+
A TypeScript SDK for interacting with Paxos Labs Amplify Vaults, providing type-safe functions for discovering vaults, depositing assets, and withdrawing across multiple blockchain networks.
|
|
13
|
+
|
|
14
|
+
[](https://www.npmjs.com/package/@paxoslabs/amplify-sdk)
|
|
15
|
+
[](https://opensource.org/licenses/MIT)
|
|
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
|
+
## Features
|
|
40
|
+
|
|
41
|
+
- **Vault Discovery** - Query available vaults and supported assets via API
|
|
42
|
+
- **Deposits** - Deposit assets into vaults with slippage protection
|
|
43
|
+
- **Withdrawals** - Withdraw assets from vaults with deadline protection
|
|
44
|
+
- **Permit Deposits** - Gas-optimized deposits using EIP-2612 permit signatures
|
|
45
|
+
- **Cache Management** - Optimize API calls with built-in caching
|
|
46
|
+
- **Multi-Chain Support** - Seamless operations across 7+ blockchain networks
|
|
47
|
+
- **Full TypeScript Support** - Complete type definitions and autocomplete
|
|
48
|
+
- **React Ready** - Works with viem (vanilla) and wagmi (React hooks)
|
|
49
|
+
|
|
50
|
+
## Quick Start (5 Minutes)
|
|
51
|
+
|
|
52
|
+
### 1. Installation
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# npm
|
|
56
|
+
npm install @paxoslabs/amplify-sdk viem
|
|
57
|
+
|
|
58
|
+
# yarn
|
|
59
|
+
yarn add @paxoslabs/amplify-sdk viem
|
|
60
|
+
|
|
61
|
+
# pnpm
|
|
62
|
+
pnpm add @paxoslabs/amplify-sdk viem
|
|
63
|
+
|
|
64
|
+
# For React apps, also install wagmi
|
|
65
|
+
pnpm add wagmi @tanstack/react-query
|
|
66
|
+
```
|
|
67
|
+
|
|
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
|
+
## Documentation
|
|
264
|
+
|
|
265
|
+
### 📚 Complete Guides
|
|
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.
|
|
522
|
+
|
|
523
|
+
## License
|
|
524
|
+
|
|
525
|
+
MIT © Paxos Labs
|
|
526
|
+
|
|
527
|
+
---
|
|
528
|
+
|
|
529
|
+
**Need Help?**
|
|
530
|
+
|
|
531
|
+
- 📖 [Full Documentation](./docs/getting-started.md)
|
|
532
|
+
- 🐛 [Report Issues](https://github.com/Ion-Protocol/amplify-sdk/issues)
|
|
533
|
+
- 💬 [GitHub Discussions](https://github.com/Ion-Protocol/amplify-sdk/discussions)
|