forked from nlordell/dexag-trader
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split up solidity files and added README
- Loading branch information
Nicholas Rodrigues Lordello
committed
Sep 4, 2022
1 parent
99cb3c0
commit 4b4f88b
Showing
5 changed files
with
54 additions
and
27 deletions.
There are no files selected for viewing
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,14 @@ | ||
# DEXag Trader | ||
|
||
This repo contains a daemon that monitors the CoW Protocol orderbook and, for each new order, simulates trading the order amounts on various DEX aggregators. | ||
The simulation records both the expected traded amounts as well as the actual executed amounts. | ||
|
||
## Simulation Details | ||
|
||
Simulation is done with an `eth_call` with state overrides. | ||
This allows simulations to work even for traders that haven't approved the required contracts. | ||
|
||
## Output | ||
|
||
The daemon writes to an SQLite database `orders.db`. | ||
It includes details of the original CoW Protocol order and trade simulation results for each DEX aggregator. |
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,7 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8; | ||
|
||
interface IERC20 { | ||
function balanceOf(address holder) external view returns (uint256); | ||
function approve(address target, uint256 amount) external returns (bool); | ||
} |
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,12 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8; | ||
|
||
library Caller { | ||
function doCall(address self, bytes memory cdata) internal returns (bytes memory rdata) { | ||
bool success; | ||
(success, rdata) = self.call(cdata); | ||
if (!success) { | ||
assembly { revert(add(rdata, 32), mload(rdata)) } | ||
} | ||
} | ||
} |
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,18 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8; | ||
|
||
import { IERC20 } from "../interfaces/IERC20.sol"; | ||
import { Caller } from "./Caller.sol"; | ||
|
||
library SafeERC20 { | ||
using Caller for address; | ||
|
||
function safeApprove(IERC20 self, address target, uint256 amount) internal { | ||
bytes memory cdata = abi.encodeCall(self.approve, (target, amount)); | ||
bytes memory rdata = address(self).doCall(cdata); | ||
require( | ||
rdata.length == 0 || abi.decode(rdata, (bool)), | ||
"SafeERC20: approval failed" | ||
); | ||
} | ||
} |