[go: up one dir, main page]

Skip to content

A template for writing Uniswap Custom Swap Curves in Stylus.

License

Notifications You must be signed in to change notification settings

OpenZeppelin/uniswap-stylus-curve-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Uniswap Custom Swap Curve

Warning

This project is still in a very early and experimental phase. It has never been audited nor thoroughly reviewed for security vulnerabilities. Do not use in production.

A template for writing Uniswap Custom Swap Curves in Stylus

Use this Template

  1. The example curve lib.rs demonstrates a constant-sum swap curve, in which tokens are traded exactly 1:1.

Tip

You can modify ICurve trait based on your needs, or provide your custom algorithm for a swap curve calculation.

Caution

If anything changes in the contract's interface, make sure to update your Solidity contract with Uniswap hooks to use the new Solidity ABI Interface of this contract.

Getting started

Follow the instructions in the Stylus quickstart to configure your development environment.

You'll also need Foundry to interact with the contract.

Check and deploy

You can use cargo stylus to check that your contract is compatible with Stylus by running

cargo stylus check

With the following command you can deploy it to an Arbitrum chain

cargo stylus deploy --endpoint $RPC_URL --private-key $PRIVATE_KEY

Tests

For unit testing, this example integrates the motsu library from OpenZeppelin. To run unit tests, you can simply use

cargo test --locked --features std --lib

Alternatively, you can use the bash script available test-unit.sh.

Exporting Solidity ABI Interface

To export the Solidity ABI interface run the following command

cargo stylus export-abi

How to run a local dev node

Instructions to setup a local dev node can be found here.

Solidity Interface

This is the current Solidity ABI Interface for the contract

interface IUniswapCurve {
    function getAmountInForExactOutput(uint256 amount_out, address input, address output, bool zero_for_one) external returns (uint256);

    function getAmountOutFromExactInput(uint256 amount_in, address input, address output, bool zero_for_one) external returns (uint256);

    error CurveCustomError();
}

About

A template for writing Uniswap Custom Swap Curves in Stylus.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published