-
Notifications
You must be signed in to change notification settings - Fork 3
[WIP] Leveraged Basis trade vault #64
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7892458
add initial implementation of LevBasisTSA
0xdomrom 462f940
add withdraw check
0xdomrom c93924c
some reformatting and tests
6d7b347
Merge branch 'feat/lev-basis-vault' of github.com:derivexyz/v2-matchi…
a36d327
more tests
1b01f1e
fixes
285d3ad
further polish
0e96d2b
last polish pre-deploy
fc1535b
updated vault logic
cf80d28
updates as per audit
0xdomrom 0e303a9
update tests
0xdomrom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ docs/ | |
|
||
# IDE files | ||
.idea/ | ||
.vscode/ | ||
|
||
lcov.info | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
pragma solidity ^0.8.20; | ||
|
||
import "./Matching.sol"; | ||
import "./interfaces/IActionVerifier.sol"; | ||
import "./interfaces/IAtomicSigner.sol"; | ||
|
||
// Wrapper contract for the "Executor" role within the Matching contract. Allows for calling out to the singer of an | ||
// action if their signature is "0" before forwarding the request onto Matching itself. | ||
|
||
contract AtomicSigningExecutor { | ||
struct AtomicAction { | ||
bool isAtomic; | ||
bytes extraData; | ||
} | ||
|
||
Matching public immutable matching; | ||
|
||
constructor(Matching _matching) { | ||
matching = _matching; | ||
} | ||
|
||
function atomicVerifyAndMatch( | ||
IActionVerifier.Action[] memory actions, | ||
bytes[] memory signatures, | ||
bytes memory actionData, | ||
AtomicAction[] memory atomicActionData | ||
) external onlyTradeExecutor { | ||
for (uint i = 0; i < actions.length; i++) { | ||
AtomicAction memory atomicAction = atomicActionData[i]; | ||
if (atomicAction.isAtomic) { | ||
// Call the signer of the action | ||
IAtomicSigner signer = IAtomicSigner(actions[i].signer); | ||
signer.signActionViaPermit(actions[i], atomicAction.extraData, signatures[i]); | ||
} | ||
} | ||
matching.verifyAndMatch(actions, signatures, actionData); | ||
} | ||
|
||
modifier onlyTradeExecutor() { | ||
require(matching.tradeExecutors(msg.sender), "AtomicSigningExecutor: Only trade executors can call this function"); | ||
_; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// SPDX-License-Identifier: GPL-3.0-only | ||
pragma solidity ^0.8.13; | ||
|
||
import "./IMatching.sol"; | ||
|
||
interface IAtomicSigner { | ||
function signActionViaPermit(IMatching.Action memory action, bytes memory extraData, bytes memory signerSig) external; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,15 +47,35 @@ abstract contract BaseOnChainSigningTSA is BaseTSA { | |
///////////// | ||
|
||
function signActionData(IMatching.Action memory action, bytes memory extraData) external virtual onlySigner { | ||
_signActionData(action, extraData); | ||
} | ||
|
||
// TODO: check if we can call this from the backend | ||
0xdomrom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
function signActionViaPermit(IMatching.Action memory action, bytes memory extraData, bytes memory signerSig) | ||
external | ||
virtual | ||
{ | ||
bytes32 hash = getActionTypedDataHash(action); | ||
|
||
(address recovered, ECDSA.RecoverError error) = ECDSA.tryRecover(hash, signerSig); | ||
require(error == ECDSA.RecoverError.NoError && _getBaseSigningTSAStorage().signers[recovered], "Invalid signature"); | ||
|
||
// require signerSig is a valid signature of signer on hash | ||
_signActionData(action, extraData); | ||
} | ||
|
||
function _signActionData(IMatching.Action memory action, bytes memory extraData) internal { | ||
bytes32 hash = getActionTypedDataHash(action); | ||
// TODO: check we want caching. **If params are updated, old ones would not be revoked.** | ||
0xdomrom marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// if (_getBaseSigningTSAStorage().signedData[hash]) return; | ||
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. can remove now? |
||
|
||
if (action.signer != address(this)) { | ||
revert BOCST_InvalidAction(); | ||
} | ||
_verifyAction(action, hash, extraData); | ||
_getBaseSigningTSAStorage().signedData[hash] = true; | ||
|
||
emit ActionSigned(msg.sender, hash, action); | ||
emit ActionSigned(action.signer, hash, action); | ||
} | ||
|
||
function revokeActionSignature(IMatching.Action memory action) external virtual onlySigner { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.