@lit-protocol/vincent-ability-erc20-transfer 0.0.10-mma
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/CONTRIBUTING.md +84 -0
- package/README.md +271 -0
- package/dist/CONTRIBUTING.md +84 -0
- package/dist/README.md +271 -0
- package/dist/package.json +31 -0
- package/dist/src/generated/lit-action.js +9 -0
- package/dist/src/generated/vincent-ability-metadata.json +3 -0
- package/dist/src/generated/vincent-bundled-ability.d.ts +1122 -0
- package/dist/src/generated/vincent-bundled-ability.d.ts.map +1 -0
- package/dist/src/generated/vincent-bundled-ability.js +15 -0
- package/dist/src/generated/vincent-bundled-ability.js.map +1 -0
- package/dist/src/generated/vincent-bundled-ability.ts +13 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +6 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/lib/helpers/commit-allowed-policies.d.ts +15 -0
- package/dist/src/lib/helpers/commit-allowed-policies.d.ts.map +1 -0
- package/dist/src/lib/helpers/commit-allowed-policies.js +37 -0
- package/dist/src/lib/helpers/commit-allowed-policies.js.map +1 -0
- package/dist/src/lib/helpers/execute-operation.d.ts +17 -0
- package/dist/src/lib/helpers/execute-operation.d.ts.map +1 -0
- package/dist/src/lib/helpers/execute-operation.js +54 -0
- package/dist/src/lib/helpers/execute-operation.js.map +1 -0
- package/dist/src/lib/helpers/index.d.ts +50 -0
- package/dist/src/lib/helpers/index.d.ts.map +1 -0
- package/dist/src/lib/helpers/index.js +116 -0
- package/dist/src/lib/helpers/index.js.map +1 -0
- package/dist/src/lib/lit-action.d.ts +2 -0
- package/dist/src/lib/lit-action.d.ts.map +1 -0
- package/dist/src/lib/lit-action.js +16 -0
- package/dist/src/lib/lit-action.js.map +1 -0
- package/dist/src/lib/schemas.d.ts +97 -0
- package/dist/src/lib/schemas.d.ts.map +1 -0
- package/dist/src/lib/schemas.js +73 -0
- package/dist/src/lib/schemas.js.map +1 -0
- package/dist/src/lib/vincent-ability.d.ts +1119 -0
- package/dist/src/lib/vincent-ability.d.ts.map +1 -0
- package/dist/src/lib/vincent-ability.js +190 -0
- package/dist/src/lib/vincent-ability.js.map +1 -0
- package/package.json +30 -0
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Contributing to Vincent Ability ERC20 Transfer
|
|
2
|
+
|
|
3
|
+
This document provides guidelines for contributing to the Vincent Ability ERC20 Transfer project.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The Vincent Ability ERC20 Transfer is an ability to send ERC20 transfer transactions from a Vincent app on behalf of the delegator. It's part of the Vincent Abilities ecosystem and is built using the Vincent Ability SDK.
|
|
8
|
+
|
|
9
|
+
## Setup
|
|
10
|
+
|
|
11
|
+
1. Follow the global setup instructions in the repository root [CONTRIBUTING.md](../../../CONTRIBUTING.md).
|
|
12
|
+
2. Install dependencies:
|
|
13
|
+
```bash
|
|
14
|
+
pnpm install
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Development Workflow
|
|
18
|
+
|
|
19
|
+
### Testing
|
|
20
|
+
|
|
21
|
+
Run tests:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
nx test ability-erc20-transfer
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Building the Lit Action
|
|
28
|
+
|
|
29
|
+
Build the ability:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
nx action:build ability-erc20-transfer
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Deploying the Lit Action to IPFS
|
|
36
|
+
|
|
37
|
+
Building will be done automatically. Deploy the ability:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
nx action:deploy ability-erc20-transfer
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Ability Development Guidelines
|
|
44
|
+
|
|
45
|
+
1. Use the Vincent Ability SDK to create abilities
|
|
46
|
+
2. Define clear schemas for ability parameters
|
|
47
|
+
3. Implement the ability lifecycle methods (precheck, execute)
|
|
48
|
+
4. Handle errors gracefully
|
|
49
|
+
5. Write comprehensive tests for all functionality
|
|
50
|
+
6. Document the ability's purpose and usage
|
|
51
|
+
|
|
52
|
+
## Integration with Policies
|
|
53
|
+
|
|
54
|
+
This ability can be integrated with various Vincent Policies to enforce constraints. When developing or modifying the ability, consider how it will be used with policies such as:
|
|
55
|
+
|
|
56
|
+
- Vincent Policy Send Counter
|
|
57
|
+
|
|
58
|
+
## Testing
|
|
59
|
+
|
|
60
|
+
Write unit tests for all functionality:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pnpm test
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Documentation
|
|
67
|
+
|
|
68
|
+
- Document the ability's purpose and usage
|
|
69
|
+
- Update README.md when adding new features
|
|
70
|
+
- Document the ability's parameters and behavior
|
|
71
|
+
|
|
72
|
+
## Pull Request Process
|
|
73
|
+
|
|
74
|
+
1. Ensure your code follows the coding standards
|
|
75
|
+
2. Update documentation if necessary
|
|
76
|
+
3. Include tests for new functionality
|
|
77
|
+
4. Link any related issues in your pull request description
|
|
78
|
+
5. Request a review from a maintainer
|
|
79
|
+
|
|
80
|
+
## Additional Resources
|
|
81
|
+
|
|
82
|
+
- [Vincent Documentation](https://docs.heyvincent.ai/)
|
|
83
|
+
- [Vincent Ability SDK Documentation](../../libs/ability-sdk/README.md)
|
|
84
|
+
- [ERC20 Standard](https://eips.ethereum.org/EIPS/eip-20)
|
package/README.md
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
# Vincent Ability ERC20 Transfer
|
|
2
|
+
|
|
3
|
+
A Vincent Ability for secure ERC-20 token transfers with integrated policy-based governance, balance
|
|
4
|
+
validation, and multi-network support.
|
|
5
|
+
|
|
6
|
+
## Overview
|
|
7
|
+
|
|
8
|
+
The `erc20-transfer` ability enables secure ERC-20 token transfers through the Vincent Framework,
|
|
9
|
+
providing:
|
|
10
|
+
|
|
11
|
+
- Secure transfers using PKP (Programmable Key Pair) wallets
|
|
12
|
+
- Automatic token decimals detection
|
|
13
|
+
- Policy-based governance with integrated rate limiting
|
|
14
|
+
- Balance validation for both native gas fees and token amounts
|
|
15
|
+
- Multi-network support (precheck uses rpcUrl; execute resolves RPC via the `chain` parameter)
|
|
16
|
+
- Real-time transaction execution with detailed logging and error handling
|
|
17
|
+
|
|
18
|
+
## Key Features
|
|
19
|
+
|
|
20
|
+
### 🪙 ERC-20 Token Support
|
|
21
|
+
|
|
22
|
+
- Works with any ERC-20 token
|
|
23
|
+
- Automatically fetches token decimals from the contract
|
|
24
|
+
- Token balance validation before transfer execution
|
|
25
|
+
- Standard ERC-20 transfer function integration
|
|
26
|
+
|
|
27
|
+
### 🔐 PKP-Based Security
|
|
28
|
+
|
|
29
|
+
- Uses Lit Protocol's PKP wallets for secure transaction signing
|
|
30
|
+
- Delegated execution with proper permission validation
|
|
31
|
+
- No private key exposure during transaction execution
|
|
32
|
+
|
|
33
|
+
### 🚦 Policy Integration
|
|
34
|
+
|
|
35
|
+
- Integrated with `send-counter-limit` policy for rate limiting
|
|
36
|
+
- Configurable transaction limits per time window
|
|
37
|
+
- Automatic policy enforcement during execution
|
|
38
|
+
|
|
39
|
+
### 🌐 Multi-Network Support
|
|
40
|
+
|
|
41
|
+
- Precheck uses the provided RPC URL (rpcUrl)
|
|
42
|
+
- Execute resolves RPC via the `chain` parameter using Lit Actions
|
|
43
|
+
- Works with any EVM-compatible network
|
|
44
|
+
|
|
45
|
+
### ✅ Comprehensive Validation
|
|
46
|
+
|
|
47
|
+
- Ethereum address format validation for recipient and token contract
|
|
48
|
+
- Amount validation (must be a positive decimal string)
|
|
49
|
+
- RPC URL required for precheck
|
|
50
|
+
- Native balance check for gas fees
|
|
51
|
+
- Token balance check before transfer
|
|
52
|
+
|
|
53
|
+
## Parameters
|
|
54
|
+
|
|
55
|
+
All functions accept the following parameters:
|
|
56
|
+
|
|
57
|
+
| Parameter | Type | Description |
|
|
58
|
+
| --------------------------- | --------- | ----------------------------------------------------------------------------- |
|
|
59
|
+
| `rpcUrl` | `string` | RPC URL used during precheck validations |
|
|
60
|
+
| `chain` | `string` | Chain name used during execute (e.g., 'base', 'ethereum') |
|
|
61
|
+
| `to` | `string` | Recipient address (0x...) |
|
|
62
|
+
| `tokenAddress` | `string` | ERC-20 token contract address (0x...) |
|
|
63
|
+
| `amount` | `string` | Amount in human-readable string (e.g., "1.23") |
|
|
64
|
+
| `alchemyGasSponsor` | `boolean` | Whether to use Alchemy's gas sponsorship (EIP-7702) |
|
|
65
|
+
| `alchemyGasSponsorApiKey` | `string` | Alchemy API key for gas sponsorship (required if alchemyGasSponsor is true) |
|
|
66
|
+
| `alchemyGasSponsorPolicyId` | `string` | Alchemy gas policy ID for sponsorship (required if alchemyGasSponsor is true) |
|
|
67
|
+
|
|
68
|
+
## Usage Examples
|
|
69
|
+
|
|
70
|
+
### USDC Transfer on Base Network
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
const transferParams = {
|
|
74
|
+
rpcUrl: 'https://base.llamarpc.com',
|
|
75
|
+
chain: 'base',
|
|
76
|
+
to: '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6',
|
|
77
|
+
tokenAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // Base USDC
|
|
78
|
+
amount: '10.50',
|
|
79
|
+
};
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Custom Token Transfer
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
const transferParams = {
|
|
86
|
+
rpcUrl: 'https://mainnet.infura.io/v3/YOUR_PROJECT_ID',
|
|
87
|
+
chain: 'ethereum',
|
|
88
|
+
to: '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6',
|
|
89
|
+
tokenAddress: '0xYourTokenContractAddress',
|
|
90
|
+
amount: '100.0',
|
|
91
|
+
};
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Small Amount Transfer (for testing)
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
const transferParams = {
|
|
98
|
+
rpcUrl: 'https://base.llamarpc.com',
|
|
99
|
+
chain: 'base',
|
|
100
|
+
to: '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6',
|
|
101
|
+
tokenAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
|
|
102
|
+
amount: '0.000001',
|
|
103
|
+
};
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Execution Flow
|
|
107
|
+
|
|
108
|
+
### 1. Precheck Phase
|
|
109
|
+
|
|
110
|
+
- Validates recipient address format
|
|
111
|
+
- Validates token contract address format
|
|
112
|
+
- Validates transfer amount (positive, reasonable limits)
|
|
113
|
+
- Validates token decimals (0-18 range)
|
|
114
|
+
- Validates RPC URL format (if provided)
|
|
115
|
+
- Validates chain ID (if provided)
|
|
116
|
+
- Returns validation status
|
|
117
|
+
|
|
118
|
+
### 2. Execute Phase
|
|
119
|
+
|
|
120
|
+
- Connects to specified RPC endpoint
|
|
121
|
+
- Retrieves PKP public key from delegation context
|
|
122
|
+
- Converts PKP public key to Ethereum address
|
|
123
|
+
- Parses token amount using specified decimals
|
|
124
|
+
- Validates native balance for gas fees
|
|
125
|
+
- Validates token balance for transfer amount
|
|
126
|
+
- Executes ERC-20 transfer using `laUtils.transaction.handler.contractCall`
|
|
127
|
+
- Triggers policy commit phase for rate limiting
|
|
128
|
+
- Returns transaction hash and metadata
|
|
129
|
+
|
|
130
|
+
## Policy Integration
|
|
131
|
+
|
|
132
|
+
The ability automatically integrates with the `send-counter-limit` policy:
|
|
133
|
+
|
|
134
|
+
- **Precheck**: Validates ability parameters
|
|
135
|
+
- **Execute**: Performs the actual ERC-20 transfer
|
|
136
|
+
- **Policy Commit**: Records the transaction for rate limiting
|
|
137
|
+
|
|
138
|
+
### Policy Configuration
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
// Example: Allow 2 ERC-20 transfers per 10 seconds
|
|
142
|
+
const policyConfig = {
|
|
143
|
+
maxSends: 2n,
|
|
144
|
+
timeWindowSeconds: 10n,
|
|
145
|
+
};
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Error Handling
|
|
149
|
+
|
|
150
|
+
The ability provides detailed error messages for various failure scenarios:
|
|
151
|
+
|
|
152
|
+
### Address Validation Errors
|
|
153
|
+
|
|
154
|
+
```
|
|
155
|
+
"Invalid recipient address format"
|
|
156
|
+
"Invalid token contract address format"
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Amount Validation Errors
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
"Invalid amount format or amount must be greater than 0"
|
|
163
|
+
"Amount too large (maximum 1,000,000 tokens per transaction)"
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Balance Validation Errors
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
"Insufficient native balance for gas. Need 0.0001 ETH, but only have 0.00005 ETH"
|
|
170
|
+
"Insufficient token balance. Need 100.0 tokens, but only have 50.0 tokens"
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Network Errors
|
|
174
|
+
|
|
175
|
+
```
|
|
176
|
+
"Invalid RPC URL format"
|
|
177
|
+
"Unable to obtain blockchain provider for transfer operations"
|
|
178
|
+
"PKP public key not available from delegation context"
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Transaction Errors
|
|
182
|
+
|
|
183
|
+
```
|
|
184
|
+
"Unknown error occurred"
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Response Format
|
|
188
|
+
|
|
189
|
+
### Success Response
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
{
|
|
193
|
+
txHash: "0x...",
|
|
194
|
+
to
|
|
195
|
+
:
|
|
196
|
+
"0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6",
|
|
197
|
+
amount
|
|
198
|
+
:
|
|
199
|
+
"10.50",
|
|
200
|
+
tokenAddress
|
|
201
|
+
:
|
|
202
|
+
"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
203
|
+
timestamp
|
|
204
|
+
:
|
|
205
|
+
1703123456789
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Error Response
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
{
|
|
213
|
+
error: 'Detailed error message';
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Development
|
|
218
|
+
|
|
219
|
+
### Building
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
npm install
|
|
223
|
+
npm run build
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Testing
|
|
227
|
+
|
|
228
|
+
This ability is tested through the Vincent E2E testing framework:
|
|
229
|
+
|
|
230
|
+
- `npm run vincent:e2e:erc20` - Tests ERC-20 transfers with rate limiting
|
|
231
|
+
|
|
232
|
+
### Architecture
|
|
233
|
+
|
|
234
|
+
The ability follows the Vincent two-phase execution model:
|
|
235
|
+
|
|
236
|
+
1. **Precheck** - Parameter validation outside Lit Actions
|
|
237
|
+
2. **Execute** - Transaction execution within Lit Actions
|
|
238
|
+
|
|
239
|
+
## Security Considerations
|
|
240
|
+
|
|
241
|
+
- **Balance validation**: Comprehensive checks for both native gas fees and token balances
|
|
242
|
+
- **PKP security**: Uses Lit Protocol's secure PKP system
|
|
243
|
+
- **Policy enforcement**: Integrated rate limiting prevents abuse
|
|
244
|
+
- **Network validation**: RPC URL and chain validation prevents malicious endpoints
|
|
245
|
+
|
|
246
|
+
## Supported Networks
|
|
247
|
+
|
|
248
|
+
- **Base Mainnet** (Chain ID: 8453)
|
|
249
|
+
- **Ethereum Mainnet** (Chain ID: 1)
|
|
250
|
+
- **Polygon** (Chain ID: 137)
|
|
251
|
+
- **Arbitrum** (Chain ID: 42161)
|
|
252
|
+
- **Any EVM-compatible network supported by Lit**
|
|
253
|
+
|
|
254
|
+
### Popular Token Addresses
|
|
255
|
+
|
|
256
|
+
#### Base Network
|
|
257
|
+
|
|
258
|
+
- **USDC**: `0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913`
|
|
259
|
+
- **WETH**: `0x4200000000000000000000000000000000000006`
|
|
260
|
+
|
|
261
|
+
#### Ethereum Mainnet
|
|
262
|
+
|
|
263
|
+
- **USDC**: `0xA0b86a33E6441b8C4C8C8C8C8C8C8C8C8C8C8C8`
|
|
264
|
+
- **USDT**: `0xdAC17F958D2ee523a2206206994597C13D831ec7`
|
|
265
|
+
|
|
266
|
+
## Dependencies
|
|
267
|
+
|
|
268
|
+
- `@lit-protocol/vincent-scaffold-sdk` - Core Vincent framework
|
|
269
|
+
- `@lit-protocol/vincent-ability-sdk` - Ability development framework
|
|
270
|
+
- `ethers.js` - Blockchain interaction
|
|
271
|
+
- `zod` - Schema validation and type safety
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Contributing to Vincent Ability ERC20 Transfer
|
|
2
|
+
|
|
3
|
+
This document provides guidelines for contributing to the Vincent Ability ERC20 Transfer project.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The Vincent Ability ERC20 Transfer is an ability to send ERC20 transfer transactions from a Vincent app on behalf of the delegator. It's part of the Vincent Abilities ecosystem and is built using the Vincent Ability SDK.
|
|
8
|
+
|
|
9
|
+
## Setup
|
|
10
|
+
|
|
11
|
+
1. Follow the global setup instructions in the repository root [CONTRIBUTING.md](../../../CONTRIBUTING.md).
|
|
12
|
+
2. Install dependencies:
|
|
13
|
+
```bash
|
|
14
|
+
pnpm install
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Development Workflow
|
|
18
|
+
|
|
19
|
+
### Testing
|
|
20
|
+
|
|
21
|
+
Run tests:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
nx test ability-erc20-transfer
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Building the Lit Action
|
|
28
|
+
|
|
29
|
+
Build the ability:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
nx action:build ability-erc20-transfer
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Deploying the Lit Action to IPFS
|
|
36
|
+
|
|
37
|
+
Building will be done automatically. Deploy the ability:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
nx action:deploy ability-erc20-transfer
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Ability Development Guidelines
|
|
44
|
+
|
|
45
|
+
1. Use the Vincent Ability SDK to create abilities
|
|
46
|
+
2. Define clear schemas for ability parameters
|
|
47
|
+
3. Implement the ability lifecycle methods (precheck, execute)
|
|
48
|
+
4. Handle errors gracefully
|
|
49
|
+
5. Write comprehensive tests for all functionality
|
|
50
|
+
6. Document the ability's purpose and usage
|
|
51
|
+
|
|
52
|
+
## Integration with Policies
|
|
53
|
+
|
|
54
|
+
This ability can be integrated with various Vincent Policies to enforce constraints. When developing or modifying the ability, consider how it will be used with policies such as:
|
|
55
|
+
|
|
56
|
+
- Vincent Policy Send Counter
|
|
57
|
+
|
|
58
|
+
## Testing
|
|
59
|
+
|
|
60
|
+
Write unit tests for all functionality:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pnpm test
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Documentation
|
|
67
|
+
|
|
68
|
+
- Document the ability's purpose and usage
|
|
69
|
+
- Update README.md when adding new features
|
|
70
|
+
- Document the ability's parameters and behavior
|
|
71
|
+
|
|
72
|
+
## Pull Request Process
|
|
73
|
+
|
|
74
|
+
1. Ensure your code follows the coding standards
|
|
75
|
+
2. Update documentation if necessary
|
|
76
|
+
3. Include tests for new functionality
|
|
77
|
+
4. Link any related issues in your pull request description
|
|
78
|
+
5. Request a review from a maintainer
|
|
79
|
+
|
|
80
|
+
## Additional Resources
|
|
81
|
+
|
|
82
|
+
- [Vincent Documentation](https://docs.heyvincent.ai/)
|
|
83
|
+
- [Vincent Ability SDK Documentation](../../libs/ability-sdk/README.md)
|
|
84
|
+
- [ERC20 Standard](https://eips.ethereum.org/EIPS/eip-20)
|
package/dist/README.md
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
# Vincent Ability ERC20 Transfer
|
|
2
|
+
|
|
3
|
+
A Vincent Ability for secure ERC-20 token transfers with integrated policy-based governance, balance
|
|
4
|
+
validation, and multi-network support.
|
|
5
|
+
|
|
6
|
+
## Overview
|
|
7
|
+
|
|
8
|
+
The `erc20-transfer` ability enables secure ERC-20 token transfers through the Vincent Framework,
|
|
9
|
+
providing:
|
|
10
|
+
|
|
11
|
+
- Secure transfers using PKP (Programmable Key Pair) wallets
|
|
12
|
+
- Automatic token decimals detection
|
|
13
|
+
- Policy-based governance with integrated rate limiting
|
|
14
|
+
- Balance validation for both native gas fees and token amounts
|
|
15
|
+
- Multi-network support (precheck uses rpcUrl; execute resolves RPC via the `chain` parameter)
|
|
16
|
+
- Real-time transaction execution with detailed logging and error handling
|
|
17
|
+
|
|
18
|
+
## Key Features
|
|
19
|
+
|
|
20
|
+
### 🪙 ERC-20 Token Support
|
|
21
|
+
|
|
22
|
+
- Works with any ERC-20 token
|
|
23
|
+
- Automatically fetches token decimals from the contract
|
|
24
|
+
- Token balance validation before transfer execution
|
|
25
|
+
- Standard ERC-20 transfer function integration
|
|
26
|
+
|
|
27
|
+
### 🔐 PKP-Based Security
|
|
28
|
+
|
|
29
|
+
- Uses Lit Protocol's PKP wallets for secure transaction signing
|
|
30
|
+
- Delegated execution with proper permission validation
|
|
31
|
+
- No private key exposure during transaction execution
|
|
32
|
+
|
|
33
|
+
### 🚦 Policy Integration
|
|
34
|
+
|
|
35
|
+
- Integrated with `send-counter-limit` policy for rate limiting
|
|
36
|
+
- Configurable transaction limits per time window
|
|
37
|
+
- Automatic policy enforcement during execution
|
|
38
|
+
|
|
39
|
+
### 🌐 Multi-Network Support
|
|
40
|
+
|
|
41
|
+
- Precheck uses the provided RPC URL (rpcUrl)
|
|
42
|
+
- Execute resolves RPC via the `chain` parameter using Lit Actions
|
|
43
|
+
- Works with any EVM-compatible network
|
|
44
|
+
|
|
45
|
+
### ✅ Comprehensive Validation
|
|
46
|
+
|
|
47
|
+
- Ethereum address format validation for recipient and token contract
|
|
48
|
+
- Amount validation (must be a positive decimal string)
|
|
49
|
+
- RPC URL required for precheck
|
|
50
|
+
- Native balance check for gas fees
|
|
51
|
+
- Token balance check before transfer
|
|
52
|
+
|
|
53
|
+
## Parameters
|
|
54
|
+
|
|
55
|
+
All functions accept the following parameters:
|
|
56
|
+
|
|
57
|
+
| Parameter | Type | Description |
|
|
58
|
+
| --------------------------- | --------- | ----------------------------------------------------------------------------- |
|
|
59
|
+
| `rpcUrl` | `string` | RPC URL used during precheck validations |
|
|
60
|
+
| `chain` | `string` | Chain name used during execute (e.g., 'base', 'ethereum') |
|
|
61
|
+
| `to` | `string` | Recipient address (0x...) |
|
|
62
|
+
| `tokenAddress` | `string` | ERC-20 token contract address (0x...) |
|
|
63
|
+
| `amount` | `string` | Amount in human-readable string (e.g., "1.23") |
|
|
64
|
+
| `alchemyGasSponsor` | `boolean` | Whether to use Alchemy's gas sponsorship (EIP-7702) |
|
|
65
|
+
| `alchemyGasSponsorApiKey` | `string` | Alchemy API key for gas sponsorship (required if alchemyGasSponsor is true) |
|
|
66
|
+
| `alchemyGasSponsorPolicyId` | `string` | Alchemy gas policy ID for sponsorship (required if alchemyGasSponsor is true) |
|
|
67
|
+
|
|
68
|
+
## Usage Examples
|
|
69
|
+
|
|
70
|
+
### USDC Transfer on Base Network
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
const transferParams = {
|
|
74
|
+
rpcUrl: 'https://base.llamarpc.com',
|
|
75
|
+
chain: 'base',
|
|
76
|
+
to: '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6',
|
|
77
|
+
tokenAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // Base USDC
|
|
78
|
+
amount: '10.50',
|
|
79
|
+
};
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Custom Token Transfer
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
const transferParams = {
|
|
86
|
+
rpcUrl: 'https://mainnet.infura.io/v3/YOUR_PROJECT_ID',
|
|
87
|
+
chain: 'ethereum',
|
|
88
|
+
to: '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6',
|
|
89
|
+
tokenAddress: '0xYourTokenContractAddress',
|
|
90
|
+
amount: '100.0',
|
|
91
|
+
};
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Small Amount Transfer (for testing)
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
const transferParams = {
|
|
98
|
+
rpcUrl: 'https://base.llamarpc.com',
|
|
99
|
+
chain: 'base',
|
|
100
|
+
to: '0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6',
|
|
101
|
+
tokenAddress: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
|
|
102
|
+
amount: '0.000001',
|
|
103
|
+
};
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Execution Flow
|
|
107
|
+
|
|
108
|
+
### 1. Precheck Phase
|
|
109
|
+
|
|
110
|
+
- Validates recipient address format
|
|
111
|
+
- Validates token contract address format
|
|
112
|
+
- Validates transfer amount (positive, reasonable limits)
|
|
113
|
+
- Validates token decimals (0-18 range)
|
|
114
|
+
- Validates RPC URL format (if provided)
|
|
115
|
+
- Validates chain ID (if provided)
|
|
116
|
+
- Returns validation status
|
|
117
|
+
|
|
118
|
+
### 2. Execute Phase
|
|
119
|
+
|
|
120
|
+
- Connects to specified RPC endpoint
|
|
121
|
+
- Retrieves PKP public key from delegation context
|
|
122
|
+
- Converts PKP public key to Ethereum address
|
|
123
|
+
- Parses token amount using specified decimals
|
|
124
|
+
- Validates native balance for gas fees
|
|
125
|
+
- Validates token balance for transfer amount
|
|
126
|
+
- Executes ERC-20 transfer using `laUtils.transaction.handler.contractCall`
|
|
127
|
+
- Triggers policy commit phase for rate limiting
|
|
128
|
+
- Returns transaction hash and metadata
|
|
129
|
+
|
|
130
|
+
## Policy Integration
|
|
131
|
+
|
|
132
|
+
The ability automatically integrates with the `send-counter-limit` policy:
|
|
133
|
+
|
|
134
|
+
- **Precheck**: Validates ability parameters
|
|
135
|
+
- **Execute**: Performs the actual ERC-20 transfer
|
|
136
|
+
- **Policy Commit**: Records the transaction for rate limiting
|
|
137
|
+
|
|
138
|
+
### Policy Configuration
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
// Example: Allow 2 ERC-20 transfers per 10 seconds
|
|
142
|
+
const policyConfig = {
|
|
143
|
+
maxSends: 2n,
|
|
144
|
+
timeWindowSeconds: 10n,
|
|
145
|
+
};
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Error Handling
|
|
149
|
+
|
|
150
|
+
The ability provides detailed error messages for various failure scenarios:
|
|
151
|
+
|
|
152
|
+
### Address Validation Errors
|
|
153
|
+
|
|
154
|
+
```
|
|
155
|
+
"Invalid recipient address format"
|
|
156
|
+
"Invalid token contract address format"
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Amount Validation Errors
|
|
160
|
+
|
|
161
|
+
```
|
|
162
|
+
"Invalid amount format or amount must be greater than 0"
|
|
163
|
+
"Amount too large (maximum 1,000,000 tokens per transaction)"
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Balance Validation Errors
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
"Insufficient native balance for gas. Need 0.0001 ETH, but only have 0.00005 ETH"
|
|
170
|
+
"Insufficient token balance. Need 100.0 tokens, but only have 50.0 tokens"
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Network Errors
|
|
174
|
+
|
|
175
|
+
```
|
|
176
|
+
"Invalid RPC URL format"
|
|
177
|
+
"Unable to obtain blockchain provider for transfer operations"
|
|
178
|
+
"PKP public key not available from delegation context"
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Transaction Errors
|
|
182
|
+
|
|
183
|
+
```
|
|
184
|
+
"Unknown error occurred"
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Response Format
|
|
188
|
+
|
|
189
|
+
### Success Response
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
{
|
|
193
|
+
txHash: "0x...",
|
|
194
|
+
to
|
|
195
|
+
:
|
|
196
|
+
"0x742d35Cc6634C0532925a3b8D4C9db96C4b4d8b6",
|
|
197
|
+
amount
|
|
198
|
+
:
|
|
199
|
+
"10.50",
|
|
200
|
+
tokenAddress
|
|
201
|
+
:
|
|
202
|
+
"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
203
|
+
timestamp
|
|
204
|
+
:
|
|
205
|
+
1703123456789
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Error Response
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
{
|
|
213
|
+
error: 'Detailed error message';
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Development
|
|
218
|
+
|
|
219
|
+
### Building
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
npm install
|
|
223
|
+
npm run build
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Testing
|
|
227
|
+
|
|
228
|
+
This ability is tested through the Vincent E2E testing framework:
|
|
229
|
+
|
|
230
|
+
- `npm run vincent:e2e:erc20` - Tests ERC-20 transfers with rate limiting
|
|
231
|
+
|
|
232
|
+
### Architecture
|
|
233
|
+
|
|
234
|
+
The ability follows the Vincent two-phase execution model:
|
|
235
|
+
|
|
236
|
+
1. **Precheck** - Parameter validation outside Lit Actions
|
|
237
|
+
2. **Execute** - Transaction execution within Lit Actions
|
|
238
|
+
|
|
239
|
+
## Security Considerations
|
|
240
|
+
|
|
241
|
+
- **Balance validation**: Comprehensive checks for both native gas fees and token balances
|
|
242
|
+
- **PKP security**: Uses Lit Protocol's secure PKP system
|
|
243
|
+
- **Policy enforcement**: Integrated rate limiting prevents abuse
|
|
244
|
+
- **Network validation**: RPC URL and chain validation prevents malicious endpoints
|
|
245
|
+
|
|
246
|
+
## Supported Networks
|
|
247
|
+
|
|
248
|
+
- **Base Mainnet** (Chain ID: 8453)
|
|
249
|
+
- **Ethereum Mainnet** (Chain ID: 1)
|
|
250
|
+
- **Polygon** (Chain ID: 137)
|
|
251
|
+
- **Arbitrum** (Chain ID: 42161)
|
|
252
|
+
- **Any EVM-compatible network supported by Lit**
|
|
253
|
+
|
|
254
|
+
### Popular Token Addresses
|
|
255
|
+
|
|
256
|
+
#### Base Network
|
|
257
|
+
|
|
258
|
+
- **USDC**: `0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913`
|
|
259
|
+
- **WETH**: `0x4200000000000000000000000000000000000006`
|
|
260
|
+
|
|
261
|
+
#### Ethereum Mainnet
|
|
262
|
+
|
|
263
|
+
- **USDC**: `0xA0b86a33E6441b8C4C8C8C8C8C8C8C8C8C8C8C8`
|
|
264
|
+
- **USDT**: `0xdAC17F958D2ee523a2206206994597C13D831ec7`
|
|
265
|
+
|
|
266
|
+
## Dependencies
|
|
267
|
+
|
|
268
|
+
- `@lit-protocol/vincent-scaffold-sdk` - Core Vincent framework
|
|
269
|
+
- `@lit-protocol/vincent-ability-sdk` - Ability development framework
|
|
270
|
+
- `ethers.js` - Blockchain interaction
|
|
271
|
+
- `zod` - Schema validation and type safety
|