-
Notifications
You must be signed in to change notification settings - Fork 83
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
Simulated Token Balances for Verified Quotes #3147
Merged
MartinquaXD
merged 2 commits into
cowprotocol:main
from
nlordell:feat/token-state-override-part-2
Dec 5, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 @@ | ||
{"abi":[{"inputs":[{"internalType":"address","name":"trader","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ensureBalance","outputs":[],"stateMutability":"nonpayable","type":"function"}],"bytecode":"0x608060405234801561001057600080fd5b506103ee806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063c56cca8314610030575b600080fd5b61004361003e3660046102fa565b610045565b005b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8481166004830152600091908416906370a0823190602401602060405180830381865afa1580156100b5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100d99190610336565b90508181106100e85750505050565b60006100f4828461034f565b905061011773ffffffffffffffffffffffffffffffffffffffff851686836101ae565b6101a7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f74726164657220646f6573206e6f74206861766520656e6f7567682073656c6c60448201527f5f746f6b656e0000000000000000000000000000000000000000000000000000606482015260840160405180910390fd5b5050505050565b6040805173ffffffffffffffffffffffffffffffffffffffff8481166024830152604480830185905283518084039091018152606490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb00000000000000000000000000000000000000000000000000000000179052915160009260609190871690610247908490610389565b6000604051808303816000865af19150503d8060008114610284576040519150601f19603f3d011682016040523d82523d6000602084013e610289565b606091505b5090935090508280156102a057506102a0816102aa565b9695505050505050565b60008151600014806102cb5750818060200190518101906102cb91906103b8565b92915050565b803573ffffffffffffffffffffffffffffffffffffffff811681146102f557600080fd5b919050565b60008060006060848603121561030f57600080fd5b610318846102d1565b9250610326602085016102d1565b9150604084013590509250925092565b60006020828403121561034857600080fd5b5051919050565b818103818111156102cb577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000825160005b818110156103aa5760208186018101518583015201610390565b506000920191825250919050565b6000602082840312156103ca57600080fd5b815180151581146103da57600080fd5b939250505056fea164736f6c6343000811000a","deployedBytecode":"0x608060405234801561001057600080fd5b506004361061002b5760003560e01c8063c56cca8314610030575b600080fd5b61004361003e3660046102fa565b610045565b005b6040517f70a0823100000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8481166004830152600091908416906370a0823190602401602060405180830381865afa1580156100b5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906100d99190610336565b90508181106100e85750505050565b60006100f4828461034f565b905061011773ffffffffffffffffffffffffffffffffffffffff851686836101ae565b6101a7576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f74726164657220646f6573206e6f74206861766520656e6f7567682073656c6c60448201527f5f746f6b656e0000000000000000000000000000000000000000000000000000606482015260840160405180910390fd5b5050505050565b6040805173ffffffffffffffffffffffffffffffffffffffff8481166024830152604480830185905283518084039091018152606490920183526020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb00000000000000000000000000000000000000000000000000000000179052915160009260609190871690610247908490610389565b6000604051808303816000865af19150503d8060008114610284576040519150601f19603f3d011682016040523d82523d6000602084013e610289565b606091505b5090935090508280156102a057506102a0816102aa565b9695505050505050565b60008151600014806102cb5750818060200190518101906102cb91906103b8565b92915050565b803573ffffffffffffffffffffffffffffffffffffffff811681146102f557600080fd5b919050565b60008060006060848603121561030f57600080fd5b610318846102d1565b9250610326602085016102d1565b9150604084013590509250925092565b60006020828403121561034857600080fd5b5051919050565b818103818111156102cb577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000825160005b818110156103aa5760208186018101518583015201610390565b506000920191825250919050565b6000602082840312156103ca57600080fd5b815180151581146103da57600080fd5b939250505056fea164736f6c6343000811000a","devdoc":{"methods":{}},"userdoc":{"methods":{}}} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 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,34 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.17; | ||
|
||
import { IERC20 } from "./interfaces/IERC20.sol"; | ||
import { SafeERC20 } from "./libraries/SafeERC20.sol"; | ||
|
||
/// @title A piggy bank contract (Spardose is piggy bank in German) | ||
/// @notice This contract account is used for pre-funding traders with tokens | ||
/// for quote simulations. A separate contract is used (instead of overriding | ||
/// the balance of the solver or trader directly) in order to interfere as | ||
/// little as possible with the settlement. | ||
contract Spardose { | ||
using SafeERC20 for *; | ||
|
||
/// @dev Ensures that the trader has at least `amount` tokens. If not, it | ||
/// will transfer the difference to the trader. | ||
/// | ||
/// @param trader - the address of the trader | ||
/// @param token - the token to ensure a balance for | ||
/// @param amount - the amount of `token` that the `trader` must hold. | ||
function ensureBalance(address trader, address token, uint256 amount) external { | ||
uint256 traderBalance = IERC20(token).balanceOf(trader); | ||
if (traderBalance >= amount) { | ||
// Nothing to do. | ||
return; | ||
} | ||
|
||
uint256 difference = amount - traderBalance; | ||
require( | ||
IERC20(token).trySafeTransfer(trader, difference), | ||
"trader does not have enough sell_token" | ||
); | ||
} | ||
} |
This file contains 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 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 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 |
---|---|---|
|
@@ -114,6 +114,7 @@ pub mod support { | |
Signatures; | ||
SimulateCode; | ||
Solver; | ||
Spardose; | ||
Swapper; | ||
Trader; | ||
} | ||
|
This file contains 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 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 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 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just to silence a Solidity compiler warning.