Swapping assets is easy with the GenericTraderRouter. You can find the address for the router on the Smart Contract Addresses page.
structSwapExactInputForOutputParams {uint256 accountNumber;uint256[] marketIdsPath;uint256 inputAmountWei;uint256 minOutputAmountWei; TraderParam[] tradersPath; IDolomiteMargin.AccountInfo[] makerAccounts; UserConfig userConfig;}/** * @param _isolationModeMarketId Market ID of isolation mode token (0 if not using isolation mode) * @param _params Trading parameters including: * - accountNumber: Account to trade from * - marketIdsPath: Array of market IDs for trading path * - inputAmountWei: Amount to swap (uint(-1) for entire balance) * - minOutputAmountWei: Minimum output amount * - tradersPath: Array of traders to use * - makerAccounts: Accounts for internal liquidity trades * - userConfig: Deadline, balance checks, and event config */functionswapExactInputForOutput(uint256_isolationModeMarketId,SwapExactInputForOutputParamsmemory_params) external;/** * @param _isolationModeMarketId Market ID of isolation mode token (0 if not using isolation mode) * @param _params Trading parameters including: * - All parameters from SwapExactInputForOutputParams * - transferCollateralParams: Collateral transfer config * - expiryParams: Position expiry settings */functionswapExactInputForOutputAndModifyPosition(uint256_isolationModeMarketId,SwapExactInputForOutputAndModifyPositionParamsmemory_params) external;
Examples
For these examples, we are creating the structs and arrays directly inline to make it more readable. This would result in a compile error in normal solidity.
Also, the tradeData is dependent on which trader you are using.
Depositing 1,000 USDC into the default account number and then swapping for WETH.
Depositing 1,000 USDC into the user's default account and swapping into GLP, an isolation mode asset. Swapping into an isolation mode asset requires using a whitelisted wrapper trader and swapping out of an isolation mode asset requires using a whitelisted unwrapper trader.
tradeData is in the format of (uint256 minAmountOut, bytes memory extraOrderData) = abi.decode(tradeData, (uint256, bytes)). The GLP wrapper requires no extra order data, but many traders require extra information.