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)