vdAMM Contracts
vdAMM-II.sol
Note
Split reference
This reference file was too long so it is split into multiple chunks. This is chunk number II.
This file represents a part of a Solidity contract for an Automated Market Maker (AMM) in a decentralized exchange. It includes functions for performing swaps between different LSD (presumably a token in the ecosystem) and calculating associated fees. The code also contains a dynamic fee calculation method which calculates fees based on the distance of the LSD's price from a target price.
_swapLsdToLsd
_swapLsdToLsd(uint256 amountIn, address lsdIn, address lsdOut, uint256 minAmountOut) public returns (uint256, uint256, uint256, uint256)
This internal function performs a swap between two different LSDs, calculates the fees, and returns the output amount and fees.
Parameters
- amountIn uint256: The amount of lsdIn to be swapped.
- lsdIn address: The address of the LSD token to be swapped from.
- lsdOut address: The address of the LSD token to be swapped to.
- minAmountOut uint256: The minimum amount of lsdOut to be received from the swap.
Return Values
- uint256, uint256, uint256, uint256: The output LSD amount, the base fee, the dynamic fee and the protocol fee.
getAmmFee
getAmmFee(uint256 ethAmountIn, address lsdIn, address lsdOut) public view returns (uint256, uint256, uint256)
This function calculates and returns the AMM fee for a swap operation.
Parameters
- ethAmountIn uint256: The amount of ETH to be swapped.
- lsdIn address: The address of the LSD token to be swapped from.
- lsdOut address: The address of the LSD token to be swapped to.
Return Values
- uint256, uint256, uint256: The base fee, the dynamic fee and the dynamic fee in BPS.
getLsdDynamicFeeBps
getLsdDynamicFeeBps(uint256 ethDelta, address lsd, bool increment) public view returns (uint256)
This function calculates the dynamic fee in basis points for a swap operation based on the distance of the LSD's price from a target price.
Parameters
- ethDelta uint256: The change in the amount of ETH in the swap.
- lsd address: The address of the LSD token.
- increment bool: A boolean flag indicating whether the amount of LSD is increasing or decreasing.
Return Values
- uint256: The dynamic fee in basis points.