tradeBySourceAmount()

The function parameters must include the list of orders (tradeActions) to interact with.

Using the SDK is highly recommended. See Performing Trades for details.

Function tradeBySourceAmount()

This function will trade the exact amount of indicated source tokens for as many target tokens as possible.

CarbonController.sol
    function tradeBySourceAmount(
        Token sourceToken,
        Token targetToken,
        TradeAction[] calldata tradeActions,
        uint256 deadline,
        uint128 minReturn
    ) external payable nonReentrant whenNotPaused returns (uint128) 

Function Arguments

tradeActionamountneeds to follow the relevant token decimal. tradeBySourceAmount, follows the sourceToken decimals

Example

tradeBySourceAmount(
0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, //source token
0x1F573D6Fb3F13d689FF844B4cE37794d79a7FF1C, //target token
[{59, 1600000000000000000}, {72, 3140000000000000000}], //array of tradeActions [{strategyId, amount},{strategyId, amount}...]
1675680190, //deadline
5320000000000000000 //minReturn
)

While all required data is available on-chain, it is recommended to use the Carbon DeFi SDK.

To trade directly with the ETH token, use the contract address: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE

Last updated