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

feat(smart-wallet): Initial commit #319

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
20 changes: 20 additions & 0 deletions sdks/smart-wallet-sdk/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
},
extends: [
'plugin:@typescript-eslint/recommended',
'plugin:eslint-comments/recommended',
'plugin:import/typescript',
'prettier',
],
plugins: ['@typescript-eslint', 'import'],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
'import/order': ['error', { 'newlines-between': 'always', alphabetize: { order: 'asc' } }],
},
}
29 changes: 29 additions & 0 deletions sdks/smart-wallet-sdk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Dependencies
node_modules/

# Build output
dist/
build/

# Generated files
src/contracts/

# Coverage
coverage/

# Cache
.cache/
.turbo/

# IDE
.idea/
.vscode/

# Logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# OS
.DS_Store
21 changes: 21 additions & 0 deletions sdks/smart-wallet-sdk/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Uniswap Labs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
25 changes: 25 additions & 0 deletions sdks/smart-wallet-sdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Smart Wallet SDK

⚒️ An SDK for building applications with smart wallets on Uniswap

This SDK provides utilities for interacting with Uniswap protocols using smart wallets.

## Installation

```bash
npm install @uniswap/smart-wallet-sdk
```

or

```bash
yarn add @uniswap/smart-wallet-sdk
```

## Documentation

Coming soon...

## License

MIT
1 change: 1 addition & 0 deletions sdks/smart-wallet-sdk/abis/MinimalDelegation.json

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions sdks/smart-wallet-sdk/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
rootDir: 'src',
globals: {
'ts-jest': {
tsconfig: 'tsconfig.base.json',
},
},
}
100 changes: 100 additions & 0 deletions sdks/smart-wallet-sdk/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"name": "@uniswap/smart-wallet-sdk",
"description": "⚒️ An SDK for building applications with smart wallets on Uniswap",
"repository": "https://github.com/Uniswap/sdks.git",
"keywords": [
"uniswap",
"ethereum",
"smart-wallet"
],
"license": "MIT",
"main": "./dist/cjs/src/index.js",
"module": "./dist/esm/src/index.js",
"types": "./dist/types/src/index.d.ts",
"files": [
"dist"
],
"engines": {
"node": ">=14"
},
"scripts": {
"clean": "rm -rf dist src/contracts",
"build": "yarn clean && yarn typechain && yarn build:cjs && yarn build:esm && yarn build:types",
"build:cjs": "tsc -p tsconfig.cjs.json",
"build:esm": "tsc -p tsconfig.esm.json",
"build:types": "tsc -p tsconfig.types.json",
"lint": "eslint src --ext .ts",
"test": "jest",
"typechain": "typechain --target=ethers-v5 --out-dir src/contracts --glob ./abis/**/*.json"
},
"exports": {
".": {
"types": "./dist/types/src/index.d.ts",
"import": "./dist/esm/src/index.js",
"require": "./dist/cjs/src/index.js"
}
},
"sideEffects": false,
"dependencies": {
"@ethersproject/abi": "^5.7.0",
"@ethersproject/bignumber": "^5.7.0",
"@ethersproject/providers": "^5.7.0",
"@uniswap/sdk-core": "^7.6.0",
"ethers": "^5.7.2"
},
"devDependencies": {
"@typechain/ethers-v5": "^10.2.0",
"@types/jest": "^25.2.3",
"@types/node": "^18.7.16",
"eslint": "^7.8.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-eslint-comments": "^3.2.0",
"eslint-plugin-functional": "^3.0.2",
"eslint-plugin-import": "^2.22.0",
"jest": "25.5.0",
"prettier": "^2.4.1",
"ts-jest": "^25.5.1",
"ts-node": "^10.9.1",
"tslib": "^2.3.0",
"typechain": "^8.1.1",
"typescript": "^4.3.3"
},
"prettier": {
"printWidth": 120,
"semi": false,
"singleQuote": true
},
"publishConfig": {
"access": "public",
"provenance": true
},
"release": {
"extends": "semantic-release-monorepo",
"branches": [
{
"name": "main",
"prerelease": false
}
],
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"preset": "angular",
"releaseRules": "../../publishing/release-rules.cjs"
}
],
"@semantic-release/release-notes-generator",
"@semantic-release/npm",
"@semantic-release/github",
[
"@semantic-release/exec",
{
"successCmd": "git restore yarn.lock && yarn",
"failCmd": "git restore yarn.lock && yarn",
"execCwd": "../.."
}
]
]
}
}
71 changes: 71 additions & 0 deletions sdks/smart-wallet-sdk/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { ChainId } from '@uniswap/sdk-core'

/**
* The target address for self-calls is address(0)
*/
export const SELF_CALL_TARGET = "0x0000000000000000000000000000000000000000"

/**
* Call types for smart wallet calls
* Follows ERC-7579
*/
export enum ModeType {
BATCHED_CALL = '0x0100000000000000000000000000000000000000000000000000000000000000',
BATCHED_CAN_REVERT_CALL = '0x0101000000000000000000000000000000000000000000000000000000000000',
BATCHED_CALL_SUPPORTS_OPDATA = '0x0100000000007821000100000000000000000000000000000000000000000000',
BATCHED_CALL_SUPPORTS_OPDATA_AND_CAN_REVERT = '0x0101000000007821000100000000000000000000000000000000000000000000'
}

/**
* ABI encoding for each mode type
*/
export const MODE_TYPE_ABI_ENCODING = {
[ModeType.BATCHED_CALL]: ['(address,uint256,bytes)[]'],
[ModeType.BATCHED_CAN_REVERT_CALL]: ['(address,uint256,bytes)[]'],
[ModeType.BATCHED_CALL_SUPPORTS_OPDATA]: ['(address,uint256,bytes)[]', 'bytes'],
[ModeType.BATCHED_CALL_SUPPORTS_OPDATA_AND_CAN_REVERT]: ['(address,uint256,bytes)[]', 'bytes']
}

/**
* Call types for smart wallet calls
* Follows ERC-7579
*/
export enum ERC7579CallType {
BATCHED_CALL = 1
}

/**
* Execution types for smart wallet calls
* Follows ERC-7579
*/
export enum ERC7579ExecutionType {
/** A batch call where if any of the calls fail, the whole transaction reverts */
REVERT_ON_FAILURE = 0,
/** A batch call where if one of the calls fails but specifies to continue, the transaction continues */
CAN_REVERT = 1
}

/**
* Mode selectors for smart wallet calls
* Follows ERC-7579 and ERC-7821
*/
export enum ERC7579ModeSelector {
BATCHED_CALL = 0,
BATCHED_CALL_SUPPORTS_OPDATA = 0x78210001
}

/**
* Mapping of chainId to Smart Wallet contract addresses
*/
export const SMART_WALLET_ADDRESSES: { [chainId in ChainId]?: string } = {
// Mainnet
[ChainId.MAINNET]: '0x0000000000000000000000000000000000000000', // Placeholder - to be replaced
// Optimism
[ChainId.OPTIMISM]: '0x0000000000000000000000000000000000000000', // Placeholder - to be replaced
// Polygon
[ChainId.POLYGON]: '0x0000000000000000000000000000000000000000', // Placeholder - to be replaced
// Arbitrum
[ChainId.ARBITRUM_ONE]: '0x0000000000000000000000000000000000000000', // Placeholder - to be replaced
// Base
[ChainId.BASE]: '0x0000000000000000000000000000000000000000', // Placeholder - to be replaced
}
17 changes: 17 additions & 0 deletions sdks/smart-wallet-sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Smart Wallet SDK entry point
export const VERSION = '0.1.0'

// Export all types
export * from './types'

// Export constants
export * from './constants'

// Export utilities
export * from './utils'

// Export main class
export * from './smartWallet'

// Export generated contracts (will be available after running typechain)
// export * from './contracts'
74 changes: 74 additions & 0 deletions sdks/smart-wallet-sdk/src/smartWallet.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { ChainId } from '@uniswap/sdk-core'

import { SmartWallet } from './smartWallet'
import { Call } from './types'

describe('SmartWallet', () => {
describe('encodeExecute', () => {
it('encodes batch calls correctly', () => {
const calls: Call[] = [
{
to: '0x1111111111111111111111111111111111111111',
data: '0x1234',
value: '0'
},
{
to: '0x2222222222222222222222222222222222222222',
data: '0x5678',
value: '1'
}
]

const result = SmartWallet.encodeExecute(calls)
expect(result).toBeDefined()
expect(result.calldata).toBeDefined()
expect(result.value).toBeDefined()
})

it('encodes batch calls with revertOnFailure option', () => {
const calls: Call[] = [
{
to: '0x1111111111111111111111111111111111111111',
data: '0x1234',
value: '0'
}
]

const result = SmartWallet.encodeExecute(calls, { revertOnFailure: true })
expect(result).toBeDefined()
expect(result.calldata).toBeDefined()
expect(result.value).toBeDefined()
})
})

describe('createExecute', () => {
it('creates an execute call for specific chain', () => {
// Simple test - just mock createExecute for simplicity
const originalMethod = SmartWallet.createExecute

// Temporarily override the method for testing
SmartWallet.createExecute = jest.fn().mockReturnValue({
to: '0x1234567890123456789012345678901234567890',
data: '0xmocked_data',
value: '0'
})

// Call the method
const methodParams = {
calldata: '0xtest',
value: '0'
}

const call = SmartWallet.createExecute(methodParams, ChainId.MAINNET)

// Verify the result
expect(call).toBeDefined()
expect(call.to).toBe('0x1234567890123456789012345678901234567890')
expect(call.data).toBe('0xmocked_data')
expect(call.value).toBe('0')

// Restore the original method
SmartWallet.createExecute = originalMethod
})
})
})
Loading
Loading