calculateTradeSourceAmount()

CarbonController.sol
    function calculateTradeSourceAmount(
        Token sourceToken,
        Token targetToken,
        TradeAction[] calldata tradeActions
    ) external view returns (uint128);
   

This function is used to get the number of target tokens that would be received by trading the indicated number of source tokens.

Function Arguments

NameTypeDescription

sourceToken

Token

The address of the token being swapped into the trade

targetToken

Token

The address of the token received from the trade

tradeActions

array

The list of TradeAction objects that specify the route of the trade. The TradeAction object contains the strategy ID of the strategy that is being swapped into, and the number of tokens being swapped in For example: {712, 1500000000000000000}

Returns

This returns the number of target tokens expected to be returned by the specified trade.

Example

tradeSourceAmount(
0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE, //token0
0x514910771AF9Ca656af840dff83E8264EcF986CA, //token1
[(712,1500000000000000000), (615, 2300000000000000000)] // TradeAction (id, amount)
)

// Return
// 7300000000000000000

For the ETH token, use the contract address: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE

Last updated