2

The newly introduced ERC4626 standard provides functions for depositing and withdrawing funds to a vault, but it is unclear to me how the designers envisioned adding custom slippage rates from the function method:

function deposit(uint256 assets, address receiver) public virtual returns (uint256 shares);

There's mention that slippage rates should be included in the preview functions (e.g., previewDeposit), but what would the best-practice solution look like to add per-interaction slippage with this? My only thoughts here are:

  • somehow set-it in a mapping prior to calling the deposit function but that seems unnecessarily cumbersome.
  • implement standard slippage of e.g., 3% and add a custom deposit function that does support slippage

In any case, neither of these would be 'standard'.

1 Answer 1

1

You can customise the inner workings of the deposit function as you wish. Like adding a standard slippage

uint slippage = 100; // = 1% slippage

function deposit(uint256 assets, address receiver) public virtual returns (uint256 shares){
    //... code
    uint amountWithSlippage = amount + (amount / slippage); using amounts under 100 wei would make transaction revert, add an if statement to make this possible
    //... code

}

Or add a fucntion where users can edit their slippage themselves

mapping(address => uint) slippages;

function setSlippage(uint _slippage) public {
    slippages[msg.sender] = _slippage;

function deposit(uint256 assets, address receiver) public virtual returns (uint256 shares){

     //... code
    uint slippage = slippages[msg.sender];
    uint amountWithSlippage = amount + (amount / slippage);
    //... code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.