Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enzo Tool #66

Merged
merged 10 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"clean": "node tools/clean.js",
"lint": "npx nx run-many -t lint",
"test": "npx nx run-many -t test -- --passWithNoTests",
"deploy:tools": "npx nx deploy aw-tool-uniswap-swap && npx nx deploy aw-tool-sign-ecdsa && npx nx deploy aw-tool-erc20-transfer",
"deploy:tools": "npx nx deploy aw-tool-uniswap-swap && npx nx deploy aw-tool-sign-ecdsa && npx nx deploy aw-tool-erc20-transfer && npx nx deploy aw-tool-enso",
"start:cli": "pnpm build && pnpm deploy:tools && NO_DEPRECATION=* node packages/law-cli/dist/src/index.js",
"start:cli:no-build": "NO_DEPRECATION=* node packages/law-cli/dist/src/index.js",
"docs": "npx typedoc --options typedoc.json",
Expand Down
7 changes: 5 additions & 2 deletions packages/agent-wallet/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
"include": [],
"references": [
{
"path": "../aw-tool-sign-ecdsa"
"path": "../aw-tool-uniswap-swap"
},
{
"path": "../aw-tool-uniswap-swap"
"path": "../aw-tool-sign-ecdsa"
},
{
"path": "../aw-tool-erc20-transfer"
},
{
"path": "../aw-tool-enso"
},
{
"path": "../aw-tool-registry"
},
Expand Down
7 changes: 5 additions & 2 deletions packages/agent-wallet/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
"include": ["src/**/*.ts"],
"references": [
{
"path": "../aw-tool-sign-ecdsa/tsconfig.lib.json"
"path": "../aw-tool-uniswap-swap/tsconfig.lib.json"
},
{
"path": "../aw-tool-uniswap-swap/tsconfig.lib.json"
"path": "../aw-tool-sign-ecdsa/tsconfig.lib.json"
},
{
"path": "../aw-tool-erc20-transfer/tsconfig.lib.json"
},
{
"path": "../aw-tool-enso/tsconfig.lib.json"
},
{
"path": "../aw-tool-registry/tsconfig.lib.json"
},
Expand Down
7 changes: 5 additions & 2 deletions packages/aw-signer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
"include": [],
"references": [
{
"path": "../aw-tool-sign-ecdsa"
"path": "../aw-tool-uniswap-swap"
},
{
"path": "../aw-tool-uniswap-swap"
"path": "../aw-tool-sign-ecdsa"
},
{
"path": "../aw-tool-erc20-transfer"
},
{
"path": "../aw-tool-enso"
},
{
"path": "../aw-tool-registry"
},
Expand Down
7 changes: 5 additions & 2 deletions packages/aw-signer/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
"include": ["src/**/*.ts"],
"references": [
{
"path": "../aw-tool-sign-ecdsa/tsconfig.lib.json"
"path": "../aw-tool-uniswap-swap/tsconfig.lib.json"
},
{
"path": "../aw-tool-uniswap-swap/tsconfig.lib.json"
"path": "../aw-tool-sign-ecdsa/tsconfig.lib.json"
},
{
"path": "../aw-tool-erc20-transfer/tsconfig.lib.json"
},
{
"path": "../aw-tool-enso/tsconfig.lib.json"
},
{
"path": "../aw-tool-registry/tsconfig.lib.json"
},
Expand Down
7 changes: 5 additions & 2 deletions packages/aw-subagent-gaia/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
"include": [],
"references": [
{
"path": "../aw-tool-sign-ecdsa"
"path": "../aw-tool-uniswap-swap"
},
{
"path": "../aw-tool-uniswap-swap"
"path": "../aw-tool-sign-ecdsa"
},
{
"path": "../aw-tool-erc20-transfer"
},
{
"path": "../aw-tool-enso"
},
{
"path": "../aw-tool-registry"
},
Expand Down
7 changes: 5 additions & 2 deletions packages/aw-subagent-gaia/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
"include": ["src/**/*.ts"],
"references": [
{
"path": "../aw-tool-sign-ecdsa/tsconfig.lib.json"
"path": "../aw-tool-uniswap-swap/tsconfig.lib.json"
},
{
"path": "../aw-tool-uniswap-swap/tsconfig.lib.json"
"path": "../aw-tool-sign-ecdsa/tsconfig.lib.json"
},
{
"path": "../aw-tool-erc20-transfer/tsconfig.lib.json"
},
{
"path": "../aw-tool-enso/tsconfig.lib.json"
},
{
"path": "../aw-tool-registry/tsconfig.lib.json"
},
Expand Down
7 changes: 5 additions & 2 deletions packages/aw-subagent-openai/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
"include": [],
"references": [
{
"path": "../aw-tool-sign-ecdsa"
"path": "../aw-tool-uniswap-swap"
},
{
"path": "../aw-tool-uniswap-swap"
"path": "../aw-tool-sign-ecdsa"
},
{
"path": "../aw-tool-erc20-transfer"
},
{
"path": "../aw-tool-enso"
},
{
"path": "../aw-tool-registry"
},
Expand Down
7 changes: 5 additions & 2 deletions packages/aw-subagent-openai/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
"include": ["src/**/*.ts"],
"references": [
{
"path": "../aw-tool-sign-ecdsa/tsconfig.lib.json"
"path": "../aw-tool-uniswap-swap/tsconfig.lib.json"
},
{
"path": "../aw-tool-uniswap-swap/tsconfig.lib.json"
"path": "../aw-tool-sign-ecdsa/tsconfig.lib.json"
},
{
"path": "../aw-tool-erc20-transfer/tsconfig.lib.json"
},
{
"path": "../aw-tool-enso/tsconfig.lib.json"
},
{
"path": "../aw-tool-registry/tsconfig.lib.json"
},
Expand Down
2 changes: 2 additions & 0 deletions packages/aw-tool-enso/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
artifacts
63 changes: 63 additions & 0 deletions packages/aw-tool-enso/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# AW-Tool Enso Documentation

The `aw-tool-enso` package provides utilities for performing onchain actions, such as swap, deposit, lend, borrow, etc. across 180+ protocols.

---

## Files Overview (in src/lib)

### 1. **`ipfs.ts`**

Handles IPFS CIDs for different environments (development, testing, production). Falls back to default CIDs if the build output is not found.

#### Key Features

- **Default CIDs**: Predefined CIDs for `datil-dev`, `datil-test`, and `datil` environments
- **Dynamic CID Loading**: Attempts to load CIDs from `dist/ipfs.json` at runtime
- **Fallback Mechanism**: Uses default CIDs if the file is missing or unreadable

---

### 2. **`lit-action.ts`**

Contains the main logic for executing a Lit Action to perform an Enso route.

#### Key Features

- **PKP Info Retrieval**: Fetches PKP details (token ID, Ethereum address, public key) from the PubkeyRouter contract.
- **Input Validation**: Validates inputs against the policy defined in the PKP Tool Registry.
- **Find the best route between 2 tokens**: Returns the best possible route between two tokens on specified chain.
- **Gas Estimation**: Estimates gas limits and fees for the transaction.
- **Transaction Creation**: Creates and signs the transaction using the PKP public key.
- **Broadcasting**: Sends the signed transaction to the network.

---

### 3. **`policy.ts`**

Defines and validates the Enso policy schema using Zod.

#### Key Features

- **Policy Schema**: Validates policy fields:
- `type`: Must be 'SignEcdsa'
- `version`: Policy version string
- `allowedPrefixes`: Array of allowed message prefixes
- **Encoding/Decoding**: Converts policies to and from ABI-encoded strings using ethers
- **Type Safety**: Uses Zod for schema validation and TypeScript type inference

---

### 4. **`tool.ts`**

Configures the Enso route for different Lit networks.

#### Key Features

- **Parameter Schema**: Validates required parameters:
- `tokenIn`
- `tokenOut`
- `amountIn`
- `chainId`
- **Network Configuration**: Creates network-specific tools for each supported Lit network
- **Policy Integartion**: Integrates with the `EnsoRoutePolicy`
22 changes: 22 additions & 0 deletions packages/aw-tool-enso/eslint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const baseConfig = require('../../eslint.config.cjs');

module.exports = [
...baseConfig,
{
files: ['**/*.json'],
rules: {
'@nx/dependency-checks': [
'error',
{
ignoredFiles: [
'{projectRoot}/eslint.config.{js,cjs,mjs}',
'{projectRoot}/tools/scripts/*',
],
},
],
},
languageOptions: {
parser: require('jsonc-eslint-parser'),
},
},
];
10 changes: 10 additions & 0 deletions packages/aw-tool-enso/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
displayName: 'aw-tool-enso',
preset: '../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: 'test-output/jest/coverage',
};
85 changes: 85 additions & 0 deletions packages/aw-tool-enso/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"name": "@lit-protocol/aw-tool-enso",
"version": "0.1.0-18",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@ensofinance/sdk": "^1.0.10",
"@lit-protocol/aw-tool": "workspace:*",
"ethers": "^5.7.2",
"tslib": "^2.8.1",
"zod": "^3.24.1"
},
"devDependencies": {
"@dotenvx/dotenvx": "^1.31.3",
"esbuild": "^0.19.11",
"node-fetch": "^2.7.0"
},
"type": "commonjs",
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"typings": "./dist/src/index.d.ts",
"files": [
"dist",
"!**/*.tsbuildinfo"
],
"nx": {
"sourceRoot": "packages/aw-tool-enso/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": [
"{options.outputPath}"
],
"options": {
"outputPath": "packages/aw-tool-enso/dist",
"main": "packages/aw-tool-enso/src/index.ts",
"tsConfig": "packages/aw-tool-enso/tsconfig.lib.json",
"assets": [
"packages/aw-tool-enso/*.md"
]
}
},
"build:action": {
"executor": "nx:run-commands",
"dependsOn": [
"build"
],
"options": {
"commands": [
"node tools/scripts/build-lit-action.js"
],
"cwd": "packages/aw-tool-enso",
"parallel": false
},
"outputs": [
"{workspaceRoot}/packages/aw-tool-enso/dist/deployed-lit-action.js"
]
},
"deploy": {
"executor": "nx:run-commands",
"dependsOn": [
"build:action"
],
"options": {
"commands": [
"node tools/scripts/deploy-lit-action.js"
],
"cwd": "packages/aw-tool-enso"
}
},
"publish": {
"executor": "@nx/js:npm-publish",
"dependsOn": [
"deploy"
],
"options": {
"packageRoot": "dist"
}
}
},
"name": "aw-tool-enso"
}
}
16 changes: 16 additions & 0 deletions packages/aw-tool-enso/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const ENSO_SUPPORTED_CHAINS = new Map<number, string>([
[1, 'ethereum'],
[10, 'optimism'],
[56, 'bnb chain'],
[100, 'gnosis'],
[137, 'polygon'],
[324, 'zksync'],
[8453, 'base'],
[42161, 'arbitrum'],
[43114, 'avalanche'],
[59144, 'linea'],
[11155111, 'sepolia'],
]);

export const ENSO_API_KEY = '1e02632d-6feb-4a75-a157-documentation' as const;
export const ENSO_ETH = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' as const;
1 change: 1 addition & 0 deletions packages/aw-tool-enso/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Enso } from './lib/tool';
Loading
Loading