Code Monkey home page Code Monkey logo

dnalob / account-abstraction-contract Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mohitchandel/account-abstraction-contract

0.0 0.0 0.0 87 KB

The AccountDelegation smart contract enables delegation of token swap permissions on the EVM network. Users can set delegation preferences to allow a Vault Manager to perform token swaps on their behalf within specified limits, without needing to transfer funds to the contract.

TypeScript 41.86% Solidity 58.14%

account-abstraction-contract's Introduction

AccountDelegation Smart Contract Documentation

Problem Statement

The AccountDelegation contract aims to solve the problem of allowing a Vault Manager to perform token swaps on behalf of a user without the need for the user to sign each transaction. The contract introduces the concept of account abstraction to enable delegation of token swap permissions to the Vault Manager. Additionally, the contract allows users to set a maximum limit for the Vault Manager to trade on their behalf, providing more control over their funds.

Description

The AccountDelegation contract is an Ethereum smart contract written in Solidity that facilitates delegation of token swap permissions between a user and a Vault Manager. Users can set delegation preferences, allowing the Vault Manager to perform token swaps on their behalf within specified limits.

The contract is designed to work with the EVM blockchain, making use of the Uniswap v3-periphery library for token swapping functionality.

Functionalities

The AccountDelegation contract provides the following functionalities:

1. Set Delegation

Function Signature: setDelegation(bool isAllowed, uint256 maxLimit)

  • Allows users to set delegation preferences for the Vault Manager.
  • Users can enable or disable delegation by setting the isAllowed flag to true or false, respectively.
  • Users can set the maximum limit (maxLimit) for the Vault Manager to trade on their behalf.
  • Once delegation is set, the Vault Manager can perform token swaps on behalf of the user within the specified maxLimit.

2. Perform Token Swap

Function Signature: performTokenSwap(address user, address tokenIn, address tokenOut, uint256 amountIn)

  • Allows the Vault Manager to perform token swaps on behalf of the user.
  • The user must have enabled delegation for the Vault Manager (isAllowed = true) to perform the swap.
  • The amount to be swapped (amountIn) must not exceed the user's set maxLimit.
  • The token swap uses Uniswap v3-periphery's ISwapRouter contract to execute the swap.

3. Withdraw Delegation

Function Signature: withdrawDelegation()

  • Allows the user to withdraw delegation preferences.
  • Once withdrawn, the Vault Manager will no longer be able to perform token swaps on behalf of the user.

4. Increase Delegation Limit

Function Signature: increaseDelegationLimit(uint256 amount)

  • Allows the user to increase the maximum limit for the Vault Manager to trade on their behalf.
  • The user must have enabled delegation for the Vault Manager (isAllowed = true) to increase the limit.

5. Decrease Delegation Limit

Function Signature: decreaseDelegationLimit(uint256 amount)

  • Allows the user to decrease the maximum limit for the Vault Manager to trade on their behalf.
  • The user must have enabled delegation for the Vault Manager (isAllowed = true) to decrease the limit.
  • The decrease in limit must not exceed the difference between the user's set maxLimit and the limitLeft.

Implementation Details

The AccountDelegation contract uses the Uniswap v3-periphery library (@uniswap/v3-periphery) for token swapping functionality. The contract deploys with the address of the Vault Manager as the contract creator (msg.sender).

The contract stores user delegation settings in a mapping (userDelegation) where each user's Ethereum address is associated with a DelegationSettings struct that holds their delegation preferences. The struct contains the user's address, delegation status (isAllowed), maximum limit for the Vault Manager to trade (maxLimit), and the remaining limit available for trading (limitLeft).

The contract emits events for important actions, such as setting delegation preferences, increasing/decreasing the trading limit, and withdrawing delegation.

Example Usage

Deployment

  1. Deploy the AccountDelegation contract on the any network with the Uniswap v3-periphery ISwapRouter address.

User Actions

  1. A user can call the setDelegation function to enable delegation and set their maximum trading limit for the Vault Manager.
  2. The user can call performTokenSwap to allow the Vault Manager to perform token swaps on their behalf within the set limit.
  3. If needed, the user can increase or decrease the delegation limit using increaseDelegationLimit and decreaseDelegationLimit functions, respectively.
  4. The user can withdraw delegation by calling the withdrawDelegation function.

Considerations

  • Before deploying and using the contract, ensure that the contract deployer is the designated Vault Manager, as the deployer's address becomes the manager's address (msg.sender).
  • Carefully consider the token swapping logic and the potential risks associated with allowing the Vault Manager to trade on behalf of users.

account-abstraction-contract's People

Contributors

mohitchandel avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.