-
Couldn't load subscription status.
- Fork 124
[protocol 3.6] Bridge and Converter #2218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
296ea1c
fdb2b6b
932272c
b868997
579fcd9
45593d0
5560975
ec261be
4accf94
f113f6d
b33f52a
90a5576
f03a0d1
1148cb9
7af1e4a
9d96ffd
0955f34
2f1e14b
84499a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,25 @@ contract LoopringIOExchangeOwner is SelectorBasedAccessManager, ChiDiscount, ERC | |
| address[] receivers; | ||
| } | ||
|
|
||
| struct FlashDepositInfo | ||
| { | ||
| address to; | ||
| address token; | ||
| uint96 amount; | ||
| } | ||
|
|
||
| struct FlashVaultInfo | ||
dong77 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| address to; | ||
| bytes data; | ||
| } | ||
|
|
||
| struct FlashConfig | ||
| { | ||
| FlashDepositInfo[] deposits; | ||
| FlashVaultInfo[] vaults; | ||
| } | ||
|
|
||
| constructor( | ||
| address _exchange, | ||
| address _chiToken | ||
|
|
@@ -101,7 +120,8 @@ contract LoopringIOExchangeOwner is SelectorBasedAccessManager, ChiDiscount, ERC | |
| bool isDataCompressed, | ||
| bytes calldata data, | ||
| CallbackConfig calldata config, | ||
| ChiConfig calldata chiConfig | ||
| ChiConfig calldata chiConfig, | ||
Brechtpd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| FlashConfig calldata flashConfig | ||
| ) | ||
| external | ||
| discountCHI(chiToken, chiConfig) | ||
|
|
@@ -135,7 +155,31 @@ contract LoopringIOExchangeOwner is SelectorBasedAccessManager, ChiDiscount, ERC | |
| // Process the callback logic. | ||
| _beforeBlockSubmission(blocks, config); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For AMM, maybe it's OK to move code inside I'm not sure if the current There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may be useful, but I don't know if we should add support for things that we currently don't plan to use (and if we use it maybe it needs additional changes again). But a boolean before/after may indeed be useful with perhaps very little work, so perhaps still worth it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The normal callbacks can now be run before or after the blocks submission using a flag. I kept the |
||
|
|
||
| // Do flash deposits | ||
| for (uint i = 0; i < flashConfig.deposits.length; i++) { | ||
| IExchangeV3(target).flashDeposit( | ||
Brechtpd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| flashConfig.deposits[i].to, | ||
| flashConfig.deposits[i].token, | ||
| flashConfig.deposits[i].amount | ||
| ); | ||
| } | ||
|
|
||
| target.fastCallAndVerify(gasleft(), 0, decompressed); | ||
|
|
||
| // Do vault logic | ||
| for (uint i = 0; i < flashConfig.vaults.length; i++) { | ||
| require(flashConfig.vaults[i].to != target, "EXCHANGE_CANNOT_BE_VAULT"); | ||
| (bool success, ) = flashConfig.vaults[i].to.call(flashConfig.vaults[i].data); | ||
dong77 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| require(success, "VAULT_CALL_FAILED"); | ||
| } | ||
|
|
||
| // Make sure flash deposits were repaid | ||
| for (uint i = 0; i < flashConfig.deposits.length; i++) { | ||
| require( | ||
| IExchangeV3(target).getAmountFlashDeposited(flashConfig.deposits[i].token) == 0, | ||
dong77 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "FLASH_DEPOSIT_NOT REPAID" | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| function _beforeBlockSubmission( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // Copyright 2017 Loopring Technology Limited. | ||
| pragma solidity ^0.7.0; | ||
|
|
||
| import "../core/iface/IExchangeV3.sol"; | ||
| import "../lib/Claimable.sol"; | ||
| import "../lib/Drainable.sol"; | ||
| import "../lib/ERC20.sol"; | ||
|
|
||
|
|
||
| /// @author Brecht Devos - <[email protected]> | ||
| contract TestVault is Claimable, Drainable { | ||
|
|
||
| function swapAndRepay( | ||
| address exchange, | ||
| address swapContract, | ||
| bytes calldata swapData, | ||
| address swapToken, | ||
| uint swapAmount, | ||
| address repayToken, | ||
| uint96 repayAmount | ||
| ) | ||
| public | ||
| { | ||
| // Swap | ||
| if (swapToken != address(0)) { | ||
| ERC20(swapToken).approve(swapContract, swapAmount); | ||
| } | ||
| (bool success, ) = swapContract.call(swapData); | ||
| require(success, "SWAP_FAILED"); | ||
|
|
||
| // Repay | ||
| if (repayToken != address(0)) { | ||
| IDepositContract depositContract = IExchangeV3(exchange).getDepositContract(); | ||
| ERC20(repayToken).approve(address(depositContract), repayAmount); | ||
| } | ||
| uint repayValue = (repayToken == address(0)) ? repayAmount : 0; | ||
| IExchangeV3(exchange).repayFlashDeposit{value: repayValue}( | ||
| address(this), | ||
| repayToken, | ||
| repayAmount, | ||
| new bytes(0) | ||
| ); | ||
| } | ||
|
|
||
| function canDrain(address drainer, address /* token */) | ||
| public | ||
| override | ||
| view | ||
| returns (bool) | ||
| { | ||
| return drainer == owner; | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.