MagpieRouterV2
The MagpieRouterV2 contract serves as the implementation of the IMagpieRouterV2 interface. It provides functions for executing token swaps, managing operational states, and dynamically updating function selectors for handling commands. The functions enforce necessary checks and interact with underlying libraries like LibSwap, LibCommand, and LibUniswapV3 to execute operations. Key functionalities include pausing and unpausing the contract, handling swaps and silent swaps, and estimating gas usage for swaps. Access control is strictly enforced using OpenZeppelin's Ownable2Step, ensuring that only the contract owner can perform critical updates and operations.
pause():
this function is used to pause the contract incase of any emergency.
unpause():
this function is used to unpause the contract after the crisis has been resolved the the contract is redy to be used again.
getSelector():
this function is used to retrieve the selector for the given command type from the Magpie Storage.
Input:
The different commands like approval, transfer, transferFrom etc.
Output:
The function selector for each of the commands.
updateSelector():
the updateSelector function is an administrative tool within a smart contract that allows the owner to update the mapping of command types to function selectors.
Input
commandType
uint16
The different commands like approval, transfer, transferFrom etc.
selector
bytes4
The function selector for each of these commands.
getSelector():
Gets the selector at the specific commandType.
Input:
Identifier for each command. We have one selector / command.
Output:
The function selector for the specified command.
enforceDeadline():
the enforceDeadline function is used to enforce time constraints on certain operations within a smart contract. By checking if the current time has exceeded a specified deadline and reverting if it has, the function ensures that operations are only executed within their valid time windows.
Input
deadline
uint256
The timestamp in epochs beyond which the transaction will get expired.
fallback():
Handle uniswapV3SwapCallback requests from any protocol that is based on UniswapV3.
Input
amount0Delta
int256
the changes in the amount of the first token involved in the swap
amount1Delta
int256
the changes in the amount of the second token involved in the swap
data
bytes calldata
a byte array containing additional information needed for the callback.
isTokenMovement():
This function is useful for determining whether a specific command action within a swap sequence involves moving tokens.
Input
commandAction
CommandAction
Output
bool
It will return true if there is a movement in tokens like approval, transfer, transferFrom, wrap and unwrap.
estimateSwapGas():
the estimateSwapGas function provides an external interface for estimating the gas cost of a token swap operation without actually executing the swap.
Input
bytes calldata
A bytes array containing input parameters for swapping.
Output
amountOut
uint256
The amount received after swapping.
gasUsed
uint256
The cost of gas while performing the swap.
swap():
the swap function provides an external interface for performing token swaps, with the additional feature of triggering events. It simplifies the swap process for external callers by handling the complexities internally through the execute function. The inclusion of event triggering makes this function suitable for scenarios where tracking swap operations is necessary
Input
bytes calldata
A bytes array containing input parameters for swapping.
Output
amountOut
uint256
The amount received after swapping.
silentSwap():
the silentSwap function provides an external interface for performing token swaps. It simplifies the swap process for external callers by handling the complexities internally through the execute function. The function's design allows for straightforward token swaps without additional overhead like event logging or gas estimation, making it suitable for users or contracts seeking to perform swaps with minimal extra features.
Input
bytes calldata
A bytes array containing input parameters for swapping.
Output
amountOut
uint256
The amount received after swapping.
execute():
the execute function is a comprehensive and versatile function that handles the execution of a sequence of commands, typically for the swap operation. It includes advanced features like gas estimation and event triggering.
Input
triggerEvent
bool
An indicator if the function needs to trigger the swap event.
Output
amountOut
uint256
The amount received after swapping.
gasUsed
uint256
The gas utilised during swapping.
Last updated