2

In similar fashion to this question specific to PancakeSwap

For many UniswapV2 clones, I want to find the part of the code which is replicating IUniswapV2Callee interface, so that I can use it in a flashloan/swap using contract. For example: ExampleFlashSwap.sol

For SushiswapV2, I am currently unable to find this function name. I saw ITridentCallee.sol but it is different.

Long story short, how can I get these function names and definitions? Currently I am stuck on Sushiswap and Shibaswap.

2
  • You just linked to the interface with the function names and definitions? Commented Aug 13, 2023 at 23:16
  • @PatrickCollins That is only for Sushiswap and I am still unsure if it is the correct one and how to use it exactly, in comparison to the usual Uniswap or Pancakeswap syntax.
    – miskin
    Commented Aug 14, 2023 at 14:13

1 Answer 1

1

Trident is not v2. Trident pools use the Bentobox contract to store liquidity. You can flashloan from Bentobox easily.

Here is an old example:
You call flashloan, Bento transfers you the token(s), and then calls-back the onFlashloan function in your contract.

# @notice bento's flashloan ability.
interface Bento:
  def flashLoan(
    borrower: address, # @param borrower: address of the contract to be called back.
    receiver: address, # @param receiver: address of the token receiver.
    token: address,    # @param token: address of the token to receive.
    amount: uint256,   # @param amount: number of the tokens to receive.
    data: Bytes[B]     # @param calldata: encoded data to pass to the `borrower` contract.
  ): nonpayable

...

# @notice the function that will be called back by bento.
# `amount` + `fee` needs to be repayed to msg.sender (bento) before call returns.
@external
def onFlashLoan(
    sender: address,  # @param sender: address of the invoker.
    token: address,   # @param token: address of the token token loaned.
    amount: uint256,  # @param amount: quantity of `token` loaned.
    fee: uint256,     # @param fee: amount that needs to be paid for loan. Same as `token`.
    data: Bytes[B]    # @param data: the calldata we passed to flashloan function.
):

https://github.com/0xMaka/vybes/blob/main/flashBento.vy


For v2 (and clones) the logic is in the pool contract, and you will want to implement IUniswapV2Callee. That is, your calling contract that will be called back by the pool.

enter image description here

interface IUniswapV2Callee {
    function uniswapV2Call(address sender, uint amount0, uint amount1, bytes calldata data) external;
}

Pool calls the function in your contract and so your contract needs to have a function that conforms to the interface.

The pool will optimistically transfer the tokens to you expecting them to already be at the pool or for it to be a flash loan. You just pass some greater than zero length of data with the call to the low level swap, and it will make the callback so that you can repay.

Bot logic is usually in the called-back function in your contract.

Your Answer

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

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