Request form
Cookbook may introduce a token in the future. Share and contribute to be eligible for future airdrops.
close icon
relevant tag icon
Euler Swap Hub
copy icon
euler-xyz
• version 1.0.0
Finance
Swap
ERC20
AMM

Euler Swap Hub

SwapHub is a generic swapping interface where users can select their desired swapping handler without any changes needed to Euler contracts. When a user invokes a swap, the input amount (or maximum input) is transferred to the handler contract. The handler contract should then perform the swap by whatever means it chooses, then transfer back any remaining input and all the output. SwapHub will ensure that the amounts returned satisfy the user's slippage settings and process the corresponding withdrawal and deposit on behalf of the user.

*Visit desktop site to download or deploy

Version

1.0.0

Creator

euler-xyz

Last Publish

1/16/2023
Any contract you deploy is yours.
Fully owned and controlled by your wallet.
Documentation
Source Code
swap(address) :
This function is used to swap two different sub-accounts. It takes in two sub-account IDs, a swap handler address, and a set of parameters for the swap. It initializes the swap by setting up a SwapCache memory object, and then emits a RequestSwapHub event. It then performs the swap internally, and updates the balances of the two sub-accounts accordingly. Finally, it checks the liquidity of the two sub-accounts and logs the asset status. (autogenerated documentation)
swapAndRepay(address) :
This function is used to swap and repay a debt between two sub-accounts. It takes in two sub-account IDs, a swap handler, swap parameters, and a target debt amount. It initializes the swap and emits a RequestSwapHubRepay event. It then checks that the mode is set to 1 and calculates the amount owed by the sub-account. It then calls the swapInternal function to perform the swap and updates the pool size and decreases the borrow amount. Finally, it checks the liquidity of the sub-account. (autogenerated documentation)
swapInternal(address) :
This function is used to facilitate a swap between two different assets. It takes in a SwapCache memory cache, an address of a swap handler, and a set of SwapParams memory parameters. It first withdraws the amount of the asset to be swapped in, and then transfers it to the swap handler. It then calls the executeSwap function on the swap handler, which performs the actual swap. After the swap is complete, it checks to make sure that the output amount is sufficient, and then updates the pool size and balance of the asset that was swapped in. Finally, it returns the amount of the asset that was swapped out. (autogenerated documentation)
initSwap() :
This function is used to initialize a swap between two sub-accounts. It takes in two sub-account IDs and a SwapParams memory object as parameters. It first checks that the two underlying assets are different, then it retrieves the two sub-accounts and updates their average liquidity. It then retrieves the eToken addresses for the two underlying assets and loads the asset caches for each. Finally, it calculates the pre-balance for each asset. (autogenerated documentation)

Get Cookin'
share iconShare

copy iconDownload Source
copy iconnpx cookbookdev i euler-swap-hub
copy icon

Last Publish

1/16/2023

Version

1.0.0

Creator

euler-xyz

Cookbook is free.
Any contract you deploy is yours.
Your contract is owned and controlled by you.