-
Notifications
You must be signed in to change notification settings - 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 11 commits
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 |
|---|---|---|
|
|
@@ -50,6 +50,12 @@ contract LoopringIOExchangeOwner is SelectorBasedAccessManager, ERC1271, Drainab | |
| address[] receivers; | ||
| } | ||
|
|
||
| struct PostBlocksCallback | ||
| { | ||
| address to; | ||
| bytes data; | ||
| } | ||
|
|
||
| constructor( | ||
| address _exchange | ||
| ) | ||
|
|
@@ -91,9 +97,11 @@ contract LoopringIOExchangeOwner is SelectorBasedAccessManager, ERC1271, Drainab | |
| } | ||
|
|
||
| function submitBlocksWithCallbacks( | ||
| bool isDataCompressed, | ||
| bytes calldata data, | ||
| CallbackConfig calldata config | ||
| bool isDataCompressed, | ||
| bytes calldata data, | ||
| CallbackConfig calldata config, | ||
| ExchangeData.FlashMint[] calldata flashMints, | ||
| PostBlocksCallback[] calldata postBlocksCallbacks | ||
| ) | ||
| external | ||
| { | ||
|
|
@@ -123,13 +131,27 @@ contract LoopringIOExchangeOwner is SelectorBasedAccessManager, ERC1271, Drainab | |
| // Decode the blocks | ||
| ExchangeData.Block[] memory blocks = _decodeBlocks(decompressed); | ||
|
|
||
| // 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 mints | ||
| if (flashMints.length > 0) { | ||
| IExchangeV3(target).flashMint(flashMints); | ||
| } | ||
|
|
||
| // Submit blocks | ||
| target.fastCallAndVerify(gasleft(), 0, decompressed); | ||
|
|
||
| // Do transaction verifying blocks callbacks | ||
| _verifyTransactions(blocks, config); | ||
|
|
||
| // Do post blocks callbacks | ||
| _afterBlockSubmission(blocks, postBlocksCallbacks); | ||
|
|
||
| // Make sure flash mints were repaid | ||
| if (flashMints.length > 0) { | ||
| IExchangeV3(target).verifyFlashMintsPaidBack(flashMints); | ||
| } | ||
| } | ||
|
|
||
| function _beforeBlockSubmission( | ||
| function _verifyTransactions( | ||
| ExchangeData.Block[] memory blocks, | ||
| CallbackConfig calldata config | ||
| ) | ||
|
|
@@ -187,6 +209,23 @@ contract LoopringIOExchangeOwner is SelectorBasedAccessManager, ERC1271, Drainab | |
| } | ||
| } | ||
|
|
||
| function _afterBlockSubmission( | ||
| ExchangeData.Block[] memory /*blocks*/, | ||
| PostBlocksCallback[] calldata postBlocksCallbacks | ||
| ) | ||
| private | ||
| { | ||
| for (uint i = 0; i < postBlocksCallbacks.length; i++) { | ||
| // Disallow calls to the exchange and pre block callback contracts | ||
dong77 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| require(postBlocksCallbacks[i].to != target, "EXCHANGE_CANNOT_BE_POST_CALLBACK_TARGET"); | ||
Brechtpd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| require(postBlocksCallbacks[i].data.toBytes4(0) != IBlockReceiver.beforeBlockSubmission.selector, "INVALID_POST_CALLBACK_FUNCTION"); | ||
Brechtpd marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| (bool success, bytes memory returnData) = postBlocksCallbacks[i].to.call(postBlocksCallbacks[i].data); | ||
| if (!success) { | ||
| assembly { revert(add(returnData, 32), mload(returnData)) } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function _processTxCallbacks( | ||
| ExchangeData.Block memory _block, | ||
| TxCallback[] calldata txCallbacks, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.