@lit-protocol/vincent-ability-uniswap-swap 0.0.7-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/CHANGELOG.md +15 -0
- package/CONTRIBUTING.md +100 -0
- package/README.md +127 -0
- package/dist/CHANGELOG.md +15 -0
- package/dist/CONTRIBUTING.md +100 -0
- package/dist/README.md +127 -0
- package/dist/package.json +37 -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 +976 -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/generated/vincent-tool-metadata.json +3 -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/ability-checks/check-erc20-allowance.d.ts +9 -0
- package/dist/src/lib/ability-checks/check-erc20-allowance.d.ts.map +1 -0
- package/dist/src/lib/ability-checks/check-erc20-allowance.js +17 -0
- package/dist/src/lib/ability-checks/check-erc20-allowance.js.map +1 -0
- package/dist/src/lib/ability-checks/check-native-token-balance.d.ts +6 -0
- package/dist/src/lib/ability-checks/check-native-token-balance.d.ts.map +1 -0
- package/dist/src/lib/ability-checks/check-native-token-balance.js +12 -0
- package/dist/src/lib/ability-checks/check-native-token-balance.js.map +1 -0
- package/dist/src/lib/ability-checks/check-token-in-balance.d.ts +8 -0
- package/dist/src/lib/ability-checks/check-token-in-balance.d.ts.map +1 -0
- package/dist/src/lib/ability-checks/check-token-in-balance.js +17 -0
- package/dist/src/lib/ability-checks/check-token-in-balance.js.map +1 -0
- package/dist/src/lib/ability-checks/check-uniswap-pool-exists.d.ts +10 -0
- package/dist/src/lib/ability-checks/check-uniswap-pool-exists.d.ts.map +1 -0
- package/dist/src/lib/ability-checks/check-uniswap-pool-exists.js +24 -0
- package/dist/src/lib/ability-checks/check-uniswap-pool-exists.js.map +1 -0
- package/dist/src/lib/ability-checks/getErc20Contract.d.ts +4 -0
- package/dist/src/lib/ability-checks/getErc20Contract.d.ts.map +1 -0
- package/dist/src/lib/ability-checks/getErc20Contract.js +20 -0
- package/dist/src/lib/ability-checks/getErc20Contract.js.map +1 -0
- package/dist/src/lib/ability-checks/index.d.ts +5 -0
- package/dist/src/lib/ability-checks/index.d.ts.map +1 -0
- package/dist/src/lib/ability-checks/index.js +8 -0
- package/dist/src/lib/ability-checks/index.js.map +1 -0
- package/dist/src/lib/ability-helpers/calculate-usd-value.d.ts +7 -0
- package/dist/src/lib/ability-helpers/calculate-usd-value.d.ts.map +1 -0
- package/dist/src/lib/ability-helpers/calculate-usd-value.js +22 -0
- package/dist/src/lib/ability-helpers/calculate-usd-value.js.map +1 -0
- package/dist/src/lib/ability-helpers/estimate-gas-for-swap.d.ts +7 -0
- package/dist/src/lib/ability-helpers/estimate-gas-for-swap.d.ts.map +1 -0
- package/dist/src/lib/ability-helpers/estimate-gas-for-swap.js +24 -0
- package/dist/src/lib/ability-helpers/estimate-gas-for-swap.js.map +1 -0
- package/dist/src/lib/ability-helpers/get-eth-usd-price.d.ts +6 -0
- package/dist/src/lib/ability-helpers/get-eth-usd-price.d.ts.map +1 -0
- package/dist/src/lib/ability-helpers/get-eth-usd-price.js +22 -0
- package/dist/src/lib/ability-helpers/get-eth-usd-price.js.map +1 -0
- package/dist/src/lib/ability-helpers/get-gas-params.d.ts +8 -0
- package/dist/src/lib/ability-helpers/get-gas-params.d.ts.map +1 -0
- package/dist/src/lib/ability-helpers/get-gas-params.js +31 -0
- package/dist/src/lib/ability-helpers/get-gas-params.js.map +1 -0
- package/dist/src/lib/ability-helpers/get-pkp-info.d.ts +6 -0
- package/dist/src/lib/ability-helpers/get-pkp-info.d.ts.map +1 -0
- package/dist/src/lib/ability-helpers/get-pkp-info.js +22 -0
- package/dist/src/lib/ability-helpers/get-pkp-info.js.map +1 -0
- package/dist/src/lib/ability-helpers/get-token-amount-in-usd.d.ts +10 -0
- package/dist/src/lib/ability-helpers/get-token-amount-in-usd.d.ts.map +1 -0
- package/dist/src/lib/ability-helpers/get-token-amount-in-usd.js +68 -0
- package/dist/src/lib/ability-helpers/get-token-amount-in-usd.js.map +1 -0
- package/dist/src/lib/ability-helpers/get-uniswap-quote.d.ts +15 -0
- package/dist/src/lib/ability-helpers/get-uniswap-quote.d.ts.map +1 -0
- package/dist/src/lib/ability-helpers/get-uniswap-quote.js +114 -0
- package/dist/src/lib/ability-helpers/get-uniswap-quote.js.map +1 -0
- package/dist/src/lib/ability-helpers/index.d.ts +10 -0
- package/dist/src/lib/ability-helpers/index.d.ts.map +1 -0
- package/dist/src/lib/ability-helpers/index.js +13 -0
- package/dist/src/lib/ability-helpers/index.js.map +1 -0
- package/dist/src/lib/ability-helpers/send-uniswap-tx.d.ts +12 -0
- package/dist/src/lib/ability-helpers/send-uniswap-tx.d.ts.map +1 -0
- package/dist/src/lib/ability-helpers/send-uniswap-tx.js +119 -0
- package/dist/src/lib/ability-helpers/send-uniswap-tx.js.map +1 -0
- package/dist/src/lib/ability-helpers/sign-tx.d.ts +3 -0
- package/dist/src/lib/ability-helpers/sign-tx.d.ts.map +1 -0
- package/dist/src/lib/ability-helpers/sign-tx.js +28 -0
- package/dist/src/lib/ability-helpers/sign-tx.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 +15 -0
- package/dist/src/lib/lit-action.js.map +1 -0
- package/dist/src/lib/schemas.d.ts +92 -0
- package/dist/src/lib/schemas.d.ts.map +1 -0
- package/dist/src/lib/schemas.js +66 -0
- package/dist/src/lib/schemas.js.map +1 -0
- package/dist/src/lib/vincent-ability.d.ts +974 -0
- package/dist/src/lib/vincent-ability.d.ts.map +1 -0
- package/dist/src/lib/vincent-ability.js +187 -0
- package/dist/src/lib/vincent-ability.js.map +1 -0
- package/package.json +36 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
## 1.0.2 (2025-07-08)
|
|
2
|
+
|
|
3
|
+
### 🩹 Fixes
|
|
4
|
+
|
|
5
|
+
- - Fixed `fail` results being returned as `success` in some cases ([867a2f85](https://github.com/LIT-Protocol/Vincent/commit/867a2f85))
|
|
6
|
+
|
|
7
|
+
### 🧱 Updated Dependencies
|
|
8
|
+
|
|
9
|
+
- Updated ability-sdk to 1.0.2
|
|
10
|
+
- Updated app-sdk to 1.0.2
|
|
11
|
+
- Updated policy-spending-limit to 1.0.2
|
|
12
|
+
|
|
13
|
+
### ❤️ Thank You
|
|
14
|
+
|
|
15
|
+
- Daryl Collins
|
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Contributing to Vincent Ability Uniswap Swap
|
|
2
|
+
|
|
3
|
+
This document provides guidelines for contributing to the Vincent Ability Uniswap Swap project.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The Vincent Ability Uniswap Swap is an ability to trigger swaps on Uniswap 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-uniswap-swap
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Building the Lit Action
|
|
28
|
+
|
|
29
|
+
Build the policy:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
nx action:build ability-uniswap-swap
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Deploying the Lit Action to IPFS
|
|
36
|
+
|
|
37
|
+
Building will be done automatically. Deploy the policy:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
nx action:deploy ability-uniswap-swap
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Project Structure
|
|
44
|
+
|
|
45
|
+
- `src/`: Source code
|
|
46
|
+
- `index.ts`: Main entry point
|
|
47
|
+
|
|
48
|
+
## Ability Development Guidelines
|
|
49
|
+
|
|
50
|
+
1. Use the Vincent Ability SDK to create abilities
|
|
51
|
+
2. Define clear schemas for ability parameters
|
|
52
|
+
3. Implement the ability lifecycle methods (precheck, execute)
|
|
53
|
+
4. Handle errors gracefully
|
|
54
|
+
5. Write comprehensive tests for all functionality
|
|
55
|
+
6. Document the ability's purpose and usage
|
|
56
|
+
|
|
57
|
+
## Integration with Policies
|
|
58
|
+
|
|
59
|
+
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:
|
|
60
|
+
|
|
61
|
+
- Vincent Policy Spending Limit
|
|
62
|
+
|
|
63
|
+
## Uniswap Integration
|
|
64
|
+
|
|
65
|
+
This ability integrates with Uniswap V3 for token swaps. When working with this ability, consider:
|
|
66
|
+
|
|
67
|
+
1. Understanding the Uniswap V3 SDK and how it works
|
|
68
|
+
2. Handling token approvals before swaps
|
|
69
|
+
3. Managing slippage and price impact
|
|
70
|
+
4. Handling different token decimals
|
|
71
|
+
5. Supporting multiple chains and Uniswap deployments
|
|
72
|
+
|
|
73
|
+
## Testing
|
|
74
|
+
|
|
75
|
+
Write unit tests for all functionality:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pnpm test
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Documentation
|
|
82
|
+
|
|
83
|
+
- Document the ability's purpose and usage
|
|
84
|
+
- Update README.md when adding new features
|
|
85
|
+
- Document the ability's parameters and behavior
|
|
86
|
+
|
|
87
|
+
## Pull Request Process
|
|
88
|
+
|
|
89
|
+
1. Ensure your code follows the coding standards
|
|
90
|
+
2. Update documentation if necessary
|
|
91
|
+
3. Include tests for new functionality
|
|
92
|
+
4. Link any related issues in your pull request description
|
|
93
|
+
5. Request a review from a maintainer
|
|
94
|
+
|
|
95
|
+
## Additional Resources
|
|
96
|
+
|
|
97
|
+
- [Vincent Documentation](https://docs.heyvincent.ai/)
|
|
98
|
+
- [Vincent Ability SDK Documentation](../../libs/ability-sdk/README.md)
|
|
99
|
+
- [Uniswap V3 Documentation](https://docs.uniswap.org/protocol/V3/introduction)
|
|
100
|
+
- [Uniswap V3 SDK](https://docs.uniswap.org/sdk/v3/overview)
|
package/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# Vincent Ability Uniswap Swap
|
|
2
|
+
|
|
3
|
+
An ability to trigger swaps on Uniswap from a Vincent app on behalf of the delegator.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The Vincent Ability Uniswap Swap is part of the Vincent Abilities ecosystem and is built using the Vincent Ability SDK. It allows Vincent apps to execute token swaps on Uniswap V3 on behalf of users, enabling seamless integration with decentralized exchange functionality.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- Execute token swaps on Uniswap V3
|
|
12
|
+
- Support for exact input and exact output swaps
|
|
13
|
+
- Support for multiple token pairs
|
|
14
|
+
- Integration with spending limit policies for enhanced security
|
|
15
|
+
- Support for multiple chains and Uniswap deployments
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @lit-protocol/vincent-ability-uniswap-swap
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
This ability can be used in Vincent apps to execute Uniswap swaps:
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { getVincentAbilityClient } from '@lit-protocol/vincent-app-sdk/abilityClient';
|
|
29
|
+
import { bundledVincentAbility } from '@lit-protocol/vincent-ability-uniswap-swap';
|
|
30
|
+
|
|
31
|
+
// One of delegatee signers from your app's Vincent Dashboard
|
|
32
|
+
const delegateeSigner = new ethers.Wallet('YOUR_DELEGATEE_PRIVATE_KEY');
|
|
33
|
+
|
|
34
|
+
// Initialize the Vincent Ability Client
|
|
35
|
+
const abilityClient = getVincentAbilityClient({
|
|
36
|
+
ethersSigner: delegateeSigner,
|
|
37
|
+
bundledVincentAbility,
|
|
38
|
+
});
|
|
39
|
+
const delegatorPkpEthAddress = '0x09182301238'; // The delegator PKP Eth Address
|
|
40
|
+
|
|
41
|
+
const abilityParams = {
|
|
42
|
+
chainId: '8453', // The chain where the tx will be executed
|
|
43
|
+
tokenIn: '0x1234...', // The input token address
|
|
44
|
+
amountIn: '1000000000000000000', // The input amount (in wei)
|
|
45
|
+
tokenOut: '0xabcd...', // The output token address
|
|
46
|
+
rpcUrl: 'https://mainnet.base.org', // The RPC to send the transaction through
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// Run precheck to see if ability should be executed
|
|
50
|
+
const precheckResult = await client.precheck(abilityParams, {
|
|
51
|
+
delegatorPkpEthAddress,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
if (precheckResult.success === true) {
|
|
55
|
+
// Execute the Vincent Ability
|
|
56
|
+
const executeResult = await client.execute(abilityParams, {
|
|
57
|
+
delegatorPkpEthAddress,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// ...ability has executed, you can check `executeResult` for details
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Integration with Policies
|
|
65
|
+
|
|
66
|
+
This ability is integrated with the Vincent Policy Spending Limit to enforce spending constraints:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import {
|
|
70
|
+
createVincentAbilityPolicy,
|
|
71
|
+
createVincentAbility,
|
|
72
|
+
createPolicyMapFromAbilityPolicies,
|
|
73
|
+
} from '@lit-protocol/vincent-ability-sdk';
|
|
74
|
+
import { bundledVincentPolicy } from '@lit-protocol/vincent-policy-spending-limit';
|
|
75
|
+
import { abilityParamsSchema } from '@lit-protocol/vincent-ability-uniswap-swap';
|
|
76
|
+
|
|
77
|
+
const spendingLimitPolicy = createVincentAbilityPolicy({
|
|
78
|
+
abilityParamsSchema,
|
|
79
|
+
bundledVincentPolicy,
|
|
80
|
+
abilityParameterMappings: {
|
|
81
|
+
pkpEthAddress: 'pkpEthAddress',
|
|
82
|
+
ethRpcUrl: 'ethRpcUrl',
|
|
83
|
+
tokenInAddress: 'tokenAddress',
|
|
84
|
+
tokenInDecimals: 'tokenDecimals',
|
|
85
|
+
tokenInAmount: 'buyAmount',
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
export const uniswapSwapWithSpendingLimit = createVincentAbility({
|
|
90
|
+
abilityParamsSchema,
|
|
91
|
+
policyMap: createPolicyMapFromAbilityPolicies([spendingLimitPolicy]),
|
|
92
|
+
// ... rest of ability implementation
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Prerequisites
|
|
97
|
+
|
|
98
|
+
Before executing a swap, ensure that:
|
|
99
|
+
|
|
100
|
+
1. The user has approved the input token for the Uniswap router
|
|
101
|
+
2. The user has sufficient balance of the input token
|
|
102
|
+
3. The user has delegated permission to the Vincent app to execute swaps
|
|
103
|
+
|
|
104
|
+
You can use the Vincent Ability ERC20 Approval to handle token approvals:
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { getVincentAbilityClient } from '@lit-protocol/vincent-app-sdk/abilityClient';
|
|
108
|
+
import { ERC20_APPROVAL_TOOL_IPFS_ID } from '@lit-protocol/vincent-ability-erc20-approval';
|
|
109
|
+
|
|
110
|
+
// ... approve tokens before swap
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Building
|
|
114
|
+
|
|
115
|
+
Run `nx build ability-uniswap-swap` to build the library.
|
|
116
|
+
|
|
117
|
+
## Running unit tests
|
|
118
|
+
|
|
119
|
+
Run `nx test ability-uniswap-swap` to execute the unit tests via [Jest](https://jestjs.io).
|
|
120
|
+
|
|
121
|
+
## Contributing
|
|
122
|
+
|
|
123
|
+
Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines on how to contribute to this project.
|
|
124
|
+
|
|
125
|
+
## License
|
|
126
|
+
|
|
127
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
## 1.0.2 (2025-07-08)
|
|
2
|
+
|
|
3
|
+
### 🩹 Fixes
|
|
4
|
+
|
|
5
|
+
- - Fixed `fail` results being returned as `success` in some cases ([867a2f85](https://github.com/LIT-Protocol/Vincent/commit/867a2f85))
|
|
6
|
+
|
|
7
|
+
### 🧱 Updated Dependencies
|
|
8
|
+
|
|
9
|
+
- Updated ability-sdk to 1.0.2
|
|
10
|
+
- Updated app-sdk to 1.0.2
|
|
11
|
+
- Updated policy-spending-limit to 1.0.2
|
|
12
|
+
|
|
13
|
+
### ❤️ Thank You
|
|
14
|
+
|
|
15
|
+
- Daryl Collins
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# Contributing to Vincent Ability Uniswap Swap
|
|
2
|
+
|
|
3
|
+
This document provides guidelines for contributing to the Vincent Ability Uniswap Swap project.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The Vincent Ability Uniswap Swap is an ability to trigger swaps on Uniswap 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-uniswap-swap
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Building the Lit Action
|
|
28
|
+
|
|
29
|
+
Build the policy:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
nx action:build ability-uniswap-swap
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Deploying the Lit Action to IPFS
|
|
36
|
+
|
|
37
|
+
Building will be done automatically. Deploy the policy:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
nx action:deploy ability-uniswap-swap
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Project Structure
|
|
44
|
+
|
|
45
|
+
- `src/`: Source code
|
|
46
|
+
- `index.ts`: Main entry point
|
|
47
|
+
|
|
48
|
+
## Ability Development Guidelines
|
|
49
|
+
|
|
50
|
+
1. Use the Vincent Ability SDK to create abilities
|
|
51
|
+
2. Define clear schemas for ability parameters
|
|
52
|
+
3. Implement the ability lifecycle methods (precheck, execute)
|
|
53
|
+
4. Handle errors gracefully
|
|
54
|
+
5. Write comprehensive tests for all functionality
|
|
55
|
+
6. Document the ability's purpose and usage
|
|
56
|
+
|
|
57
|
+
## Integration with Policies
|
|
58
|
+
|
|
59
|
+
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:
|
|
60
|
+
|
|
61
|
+
- Vincent Policy Spending Limit
|
|
62
|
+
|
|
63
|
+
## Uniswap Integration
|
|
64
|
+
|
|
65
|
+
This ability integrates with Uniswap V3 for token swaps. When working with this ability, consider:
|
|
66
|
+
|
|
67
|
+
1. Understanding the Uniswap V3 SDK and how it works
|
|
68
|
+
2. Handling token approvals before swaps
|
|
69
|
+
3. Managing slippage and price impact
|
|
70
|
+
4. Handling different token decimals
|
|
71
|
+
5. Supporting multiple chains and Uniswap deployments
|
|
72
|
+
|
|
73
|
+
## Testing
|
|
74
|
+
|
|
75
|
+
Write unit tests for all functionality:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pnpm test
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Documentation
|
|
82
|
+
|
|
83
|
+
- Document the ability's purpose and usage
|
|
84
|
+
- Update README.md when adding new features
|
|
85
|
+
- Document the ability's parameters and behavior
|
|
86
|
+
|
|
87
|
+
## Pull Request Process
|
|
88
|
+
|
|
89
|
+
1. Ensure your code follows the coding standards
|
|
90
|
+
2. Update documentation if necessary
|
|
91
|
+
3. Include tests for new functionality
|
|
92
|
+
4. Link any related issues in your pull request description
|
|
93
|
+
5. Request a review from a maintainer
|
|
94
|
+
|
|
95
|
+
## Additional Resources
|
|
96
|
+
|
|
97
|
+
- [Vincent Documentation](https://docs.heyvincent.ai/)
|
|
98
|
+
- [Vincent Ability SDK Documentation](../../libs/ability-sdk/README.md)
|
|
99
|
+
- [Uniswap V3 Documentation](https://docs.uniswap.org/protocol/V3/introduction)
|
|
100
|
+
- [Uniswap V3 SDK](https://docs.uniswap.org/sdk/v3/overview)
|
package/dist/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# Vincent Ability Uniswap Swap
|
|
2
|
+
|
|
3
|
+
An ability to trigger swaps on Uniswap from a Vincent app on behalf of the delegator.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The Vincent Ability Uniswap Swap is part of the Vincent Abilities ecosystem and is built using the Vincent Ability SDK. It allows Vincent apps to execute token swaps on Uniswap V3 on behalf of users, enabling seamless integration with decentralized exchange functionality.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- Execute token swaps on Uniswap V3
|
|
12
|
+
- Support for exact input and exact output swaps
|
|
13
|
+
- Support for multiple token pairs
|
|
14
|
+
- Integration with spending limit policies for enhanced security
|
|
15
|
+
- Support for multiple chains and Uniswap deployments
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @lit-protocol/vincent-ability-uniswap-swap
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
This ability can be used in Vincent apps to execute Uniswap swaps:
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { getVincentAbilityClient } from '@lit-protocol/vincent-app-sdk/abilityClient';
|
|
29
|
+
import { bundledVincentAbility } from '@lit-protocol/vincent-ability-uniswap-swap';
|
|
30
|
+
|
|
31
|
+
// One of delegatee signers from your app's Vincent Dashboard
|
|
32
|
+
const delegateeSigner = new ethers.Wallet('YOUR_DELEGATEE_PRIVATE_KEY');
|
|
33
|
+
|
|
34
|
+
// Initialize the Vincent Ability Client
|
|
35
|
+
const abilityClient = getVincentAbilityClient({
|
|
36
|
+
ethersSigner: delegateeSigner,
|
|
37
|
+
bundledVincentAbility,
|
|
38
|
+
});
|
|
39
|
+
const delegatorPkpEthAddress = '0x09182301238'; // The delegator PKP Eth Address
|
|
40
|
+
|
|
41
|
+
const abilityParams = {
|
|
42
|
+
chainId: '8453', // The chain where the tx will be executed
|
|
43
|
+
tokenIn: '0x1234...', // The input token address
|
|
44
|
+
amountIn: '1000000000000000000', // The input amount (in wei)
|
|
45
|
+
tokenOut: '0xabcd...', // The output token address
|
|
46
|
+
rpcUrl: 'https://mainnet.base.org', // The RPC to send the transaction through
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// Run precheck to see if ability should be executed
|
|
50
|
+
const precheckResult = await client.precheck(abilityParams, {
|
|
51
|
+
delegatorPkpEthAddress,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
if (precheckResult.success === true) {
|
|
55
|
+
// Execute the Vincent Ability
|
|
56
|
+
const executeResult = await client.execute(abilityParams, {
|
|
57
|
+
delegatorPkpEthAddress,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// ...ability has executed, you can check `executeResult` for details
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Integration with Policies
|
|
65
|
+
|
|
66
|
+
This ability is integrated with the Vincent Policy Spending Limit to enforce spending constraints:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
import {
|
|
70
|
+
createVincentAbilityPolicy,
|
|
71
|
+
createVincentAbility,
|
|
72
|
+
createPolicyMapFromAbilityPolicies,
|
|
73
|
+
} from '@lit-protocol/vincent-ability-sdk';
|
|
74
|
+
import { bundledVincentPolicy } from '@lit-protocol/vincent-policy-spending-limit';
|
|
75
|
+
import { abilityParamsSchema } from '@lit-protocol/vincent-ability-uniswap-swap';
|
|
76
|
+
|
|
77
|
+
const spendingLimitPolicy = createVincentAbilityPolicy({
|
|
78
|
+
abilityParamsSchema,
|
|
79
|
+
bundledVincentPolicy,
|
|
80
|
+
abilityParameterMappings: {
|
|
81
|
+
pkpEthAddress: 'pkpEthAddress',
|
|
82
|
+
ethRpcUrl: 'ethRpcUrl',
|
|
83
|
+
tokenInAddress: 'tokenAddress',
|
|
84
|
+
tokenInDecimals: 'tokenDecimals',
|
|
85
|
+
tokenInAmount: 'buyAmount',
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
export const uniswapSwapWithSpendingLimit = createVincentAbility({
|
|
90
|
+
abilityParamsSchema,
|
|
91
|
+
policyMap: createPolicyMapFromAbilityPolicies([spendingLimitPolicy]),
|
|
92
|
+
// ... rest of ability implementation
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Prerequisites
|
|
97
|
+
|
|
98
|
+
Before executing a swap, ensure that:
|
|
99
|
+
|
|
100
|
+
1. The user has approved the input token for the Uniswap router
|
|
101
|
+
2. The user has sufficient balance of the input token
|
|
102
|
+
3. The user has delegated permission to the Vincent app to execute swaps
|
|
103
|
+
|
|
104
|
+
You can use the Vincent Ability ERC20 Approval to handle token approvals:
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
import { getVincentAbilityClient } from '@lit-protocol/vincent-app-sdk/abilityClient';
|
|
108
|
+
import { ERC20_APPROVAL_TOOL_IPFS_ID } from '@lit-protocol/vincent-ability-erc20-approval';
|
|
109
|
+
|
|
110
|
+
// ... approve tokens before swap
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Building
|
|
114
|
+
|
|
115
|
+
Run `nx build ability-uniswap-swap` to build the library.
|
|
116
|
+
|
|
117
|
+
## Running unit tests
|
|
118
|
+
|
|
119
|
+
Run `nx test ability-uniswap-swap` to execute the unit tests via [Jest](https://jestjs.io).
|
|
120
|
+
|
|
121
|
+
## Contributing
|
|
122
|
+
|
|
123
|
+
Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for guidelines on how to contribute to this project.
|
|
124
|
+
|
|
125
|
+
## License
|
|
126
|
+
|
|
127
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lit-protocol/vincent-ability-uniswap-swap",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"publishConfig": {
|
|
5
|
+
"access": "public"
|
|
6
|
+
},
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@lit-protocol/vincent-policy-spending-limit": "workspace:*",
|
|
9
|
+
"@lit-protocol/vincent-ability-sdk": "workspace:*",
|
|
10
|
+
"@uniswap/sdk-core": "^7.7.2",
|
|
11
|
+
"ethers": "^5.8.0",
|
|
12
|
+
"tslib": "2.8.1",
|
|
13
|
+
"zod": "^3.25.64"
|
|
14
|
+
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"@lit-protocol/vincent-app-sdk": "workspace:^"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@dotenvx/dotenvx": "^1.44.2",
|
|
20
|
+
"@lit-protocol/auth-helpers": "^7.2.0",
|
|
21
|
+
"@lit-protocol/constants": "^7.2.0",
|
|
22
|
+
"@lit-protocol/contracts-sdk": "^7.2.0",
|
|
23
|
+
"@lit-protocol/lit-node-client": "^7.0.8",
|
|
24
|
+
"esbuild": "^0.19.12",
|
|
25
|
+
"esbuild-plugin-polyfill-node": "^0.3.0",
|
|
26
|
+
"ipfs-only-hash": "^4.0.0",
|
|
27
|
+
"viem": "^2.28.0"
|
|
28
|
+
},
|
|
29
|
+
"main": "./dist/src/index.js",
|
|
30
|
+
"module": "./dist/src/index.js",
|
|
31
|
+
"types": "./dist/src/index.d.ts",
|
|
32
|
+
"files": [
|
|
33
|
+
"dist/**",
|
|
34
|
+
"*.md"
|
|
35
|
+
],
|
|
36
|
+
"type": "commonjs"
|
|
37
|
+
}
|