Gearbox V2


Liquidity operations

Add liquidity

EL(tn)=EL(tn1)+amountU+B(tn1)r(tn1)(tntn1)EL(t_n) = EL(t_{n-1})+amount_U+B(t_{n-1})*r(t_{n-1})*(t_{n}-t_{n-1})
mint  diesel  tokens=amountUdiesel  supply(tn)EL(tn1)mint\;diesel\;tokens =amount_{U}*\frac{diesel\;supply(t_n)}{EL(t_{n-1})}

where amount_U - is amount of added underlying liquidity. Then called Pool Update().

Remove liquidity

EL(tn)=EL(tn1)+EL(t_n) = EL(t_{n-1})+
+B(tn1)r(tn1)(tntn1)amountLPEL(tn)diesel  supply(tn),+B(t_{n-1})*r(t_{n-1})*(t_{n}-t_{n-1})-amount_{LP}*\frac{EL(t_n)}{diesel\;supply(t_n)},
burn  diesel  tokens=amountLPburn\;diesel\;tokens =amount_{LP}

where amount_LP - amount of removed LP tokens.Then call Pool Update().

Adding / removing liquidity programatically


Adds liquidity to pool and send diesel (LP) tokens back to LP:

  • Transfers underlying asset to pool
  • Mints diesel (LP) token with current diesel rate
  • Updates expected liquidity
  • Updates borrow rate
function addLiquidity(
        uint256 amount,
        address onBehalfOf,
        uint256 referralCode
    ) external 
amountAmount of tokens to be transfer
onBehalfOfThe address that will receive the diesel tokens, same as msg.sender if the user wants to receive them on his own wallet, or a different address if the beneficiary of diesel tokens is a different wallet
referralCodeCode used to register the integrator originating the operation, for potential rewards. 0 if the action is executed directly by the user, without any middle-man


function removeLiquidity(uint256 amount, address to)
amountAmount of tokens to be transfer
toAddress to transfer liquidity

It burns user diesel (LP) tokens and returns underlying tokens:

  • Transfers to LP underlying account = amount * diesel rate
  • Burns diesel tokens
  • Decreases underlying amount from total_liquidity
  • Updates borrow rate