Aggregator Smart Contract Interface
The Aggregator contract provides a swap function which allows users to perform token swaps across multiple routes and adapters.
Functions
swap
swapPerforms a token swap from one token to another, potentially using multiple routes and adapters.
Signature
function swap(
address tokenFromAddress,
uint256 tokenFromAmount,
address tokenToAddress,
uint256 tokenToAmount,
uint256 tokenToMinAmount,
IAggregator.Route[] routes
) external payable;Parameters
tokenFromAddress
address
The address of the token to swap from.
tokenFromAmount
uint256
The amount of the input token to swap.
tokenToAddress
address
The address of the token to receive.
tokenToAmount
uint256
The expected amount of the output token.
tokenToMinAmount
uint256
The minimum amount of the output token after slippage.
routes
IAggregator.Route[]
An array of routes describing the swap path and adapters to use.
Route Structure
Each Route in the routes array is a struct with the following fields:
tokenFrom
address
The address of the token to swap from in this route.
tokenTo
address
The address of the token to swap to in this route.
adapter
address
The address of the adapter contract to use for this route.
additionalParams
bytes
Additional parameters for the adapter (if needed).
profitReceiver
profitReceiverReturns the address that receives profit from positive slippage and fees.
Signature
function profitReceiver() external view returns (address receiver);Returns
receiver
address
The address of the profit receiver.
singleHopFee
singleHopFeeReturns the fee charged for single-hop swaps (routes with only one adapter).
Signature
function singleHopFee() external view returns (uint128 fee);Returns
fee
uint128
The single hop fee as a percentage (scaled by PERCENTAGE_BASE).
multiHopFee
multiHopFeeReturns the fee charged for multi-hop swaps (routes with more than one adapter).
Signature
function multiHopFee() external view returns (uint128 fee);Returns
fee
uint128
The multi hop fee as a percentage (scaled by PERCENTAGE_BASE).
activeAdapters
activeAdaptersReturns whether a specific adapter is active and can be used for swaps.
Signature
function activeAdapters(address adapter) external view returns (bool isActive);Parameters
adapter
address
The address of the adapter to check.
Returns
isActive
bool
True if the adapter is active, false otherwise.
freeOfChargeFeeAdapters
freeOfChargeFeeAdaptersReturns whether a specific adapter is designated as free of charge for single-hop swaps.
Signature
function freeOfChargeFeeAdapters(address adapter) external view returns (bool isFreeOfCharge);Parameters
adapter
address
The address of the adapter to check.
Returns
isFreeOfCharge
bool
True if the adapter is free of charge for single-hop swaps, false otherwise.
Note
Free of charge adapters do not charge any fees for swaps if routes contain only them (routes.length == 1).
PERCENTAGE_BASE
PERCENTAGE_BASEReturns the percentage base used for fee calculations.
Signature
function PERCENTAGE_BASE() external view returns (uint256 percentageBase);Returns
percentageBase
uint256
The percentage base constant (1e18), representing 100% in fee calculations.
Events
SwapExecuted
SwapExecutedEmitted when a swap is successfully executed.
Signature
event SwapExecuted(address tokenFrom, uint256 tokenFromAmount, address tokenTo, uint256 tokenToAmount);Parameters
tokenFrom
address
The address of the token swapped from.
tokenFromAmount
uint256
The amount of tokenFrom swapped.
tokenTo
address
The address of the token swapped to.
tokenToAmount
uint256
The amount of tokenTo received.
SingleHopFeeUpdated
SingleHopFeeUpdatedEmitted when the single hop fee is updated.
Signature
event SingleHopFeeUpdated(uint256 singleHopFee);Parameters
singleHopFee
uint256
The new single hop fee.
MultiHopFeeUpdated
MultiHopFeeUpdatedEmitted when the multi-hop fee is updated.
Signature
event MultiHopFeeUpdated(uint256 multiHopFee);Parameters
multiHopFee
uint256
The new multi hop fee.
FreeOfChargeFeeAdapterUpdated
FreeOfChargeFeeAdapterUpdatedEmitted when an adapter's free-of-charge status is updated.
Signature
event FreeOfChargeFeeAdapterUpdated(address indexed adapter, bool isFreeOfCharge);Parameters
adapter
address
The address of the adapter.
isFreeOfCharge
bool
True if the adapter is free of charge.
Errors
SingleHopFeeTooHigh
SingleHopFeeTooHighThrown when attempting to set a single hop fee greater than 100% (PERCENTAGE_BASE).
Signature
error SingleHopFeeTooHigh();SingleHopFeeAlreadySet
SingleHopFeeAlreadySetThrown when attempting to set the single hop fee to its current value.
Signature
error SingleHopFeeAlreadySet();MultiHopFeeTooHigh
MultiHopFeeTooHighThrown when attempting to set a multi-hop fee greater than 100% (PERCENTAGE_BASE).
Signature
error MultiHopFeeTooHigh();MultiHopFeeAlreadySet
MultiHopFeeAlreadySetThrown when attempting to set the multi-hop fee to its current value.
Signature
error MultiHopFeeAlreadySet();ProfitReceiverAddressZero
ProfitReceiverAddressZeroThrown when attempting to set the profit receiver address to the zero address.
Signature
error ProfitReceiverAddressZero();RoutesLengthZero
RoutesLengthZeroThrown when the routes array is empty during a swap operation.
Signature
error RoutesLengthZero();TokenFromCannotBeEqualToTokenTo
TokenFromCannotBeEqualToTokenToThrown when a route specifies the same token for both tokenFrom and tokenTo.
Signature
error TokenFromCannotBeEqualToTokenTo();TokenFromAddressMismatch
TokenFromAddressMismatchThrown when the first route's tokenFrom address doesn't match the swap's tokenFromAddress parameter.
Signature
error TokenFromAddressMismatch();TokenToAddressMismatch
TokenToAddressMismatchThrown when the last route's tokenTo address doesn't match the swap's tokenToAddress parameter.
Signature
error TokenToAddressMismatch();TokenFromAmountZero
TokenFromAmountZeroThrown when the tokenFromAmount is zero.
Signature
error TokenFromAmountZero();TokenToAmountLessThanMinAmount
TokenToAmountLessThanMinAmountThrown when the expected tokenToAmount is less than the minimum amount (tokenToMinAmount).
Signature
error TokenToAmountLessThanMinAmount();TokenFromAmountExceedsBalance
TokenFromAmountExceedsBalanceThrown when the user's token balance is insufficient for the swap amount.
Signature
error TokenFromAmountExceedsBalance();ReceivedAmountLessThanMinAmount
ReceivedAmountLessThanMinAmountThrown when the actual received amount is less than the minimum acceptable amount.
Signature
error ReceivedAmountLessThanMinAmount();AdapterNotActive
AdapterNotActiveThrown when attempting to use an inactive adapter in a swap route.
Signature
error AdapterNotActive(address adapter);Parameters
adapter
address
The address of the inactive adapter.
NativeTokenAmountMismatch
NativeTokenAmountMismatchThrown when the native token amount sent doesn't match the expected amount for native token swaps.
Signature
error NativeTokenAmountMismatch(uint256 expected, uint256 received);Parameters
expected
uint256
The expected native token amount.
received
uint256
The actual native token amount.
UnexpectedNativeTokenSent
UnexpectedNativeTokenSentThrown when native tokens are sent for non-native token swaps.
Signature
error UnexpectedNativeTokenSent();Example Usage
Below is an example of swapping 1 WMON for USDC on Monad Testnet.
// Example call to swap 1 WMON for USDC on Monad Testnet
aggregator.swap(
0x760AfE86e5de5fa0Ee542fc7B7B713e1c5425701, // tokenFromAddress (WMON)
1000000000000000000, // tokenFromAmount (1 WMON, 18 decimals)
0xf817257fed379853cDe0fa4F97AB987181B1E5Ea, // tokenToAddress (USDC)
1617900, // tokenToAmount (expected USDC amount out)
1600000, // tokenToMinAmount (min USDC amount out after slippage)
[
{
tokenFrom: 0x760AfE86e5de5fa0Ee542fc7B7B713e1c5425701, // WMON
tokenTo: 0xf817257fed379853cDe0fa4F97AB987181B1E5Ea, // USDC
adapter: 0xe5a44bc972134f6baa8168adce623f7a33bac4ab, // Example adapter address
additionalParams: "0x" // Adapter-specific params (empty in this example)
}
]
);Last updated

