-
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.
- Loading branch information
Showing
7 changed files
with
146 additions
and
57 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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
[submodule "lib/forge-std"] | ||
path = lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std | ||
[submodule "lib/dss-test"] | ||
path = lib/dss-test | ||
url = https://github.com/makerdao/dss-test |
This file was deleted.
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,21 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.26; | ||
|
||
import {Script, console} from "forge-std/Script.sol"; | ||
import {DeepStack} from "../src/DeepStack.sol"; | ||
|
||
contract DeepStackScript is Script { | ||
DeepStack public deepStack; | ||
|
||
address constant usd = address(1); | ||
address constant eur = address(2); | ||
address constant bow = address(3); | ||
|
||
function run() public { | ||
vm.startBroadcast(); | ||
|
||
deepStack = new DeepStack(usd, eur, bow); | ||
|
||
vm.stopBroadcast(); | ||
} | ||
} |
This file was deleted.
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,46 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity 0.8.26; | ||
|
||
interface ERC20Like { | ||
function balanceOf(address) external returns (uint256); | ||
function approve(address usr, uint256 wad) external returns (bool); | ||
} | ||
|
||
interface CoinLike { | ||
function usd() external view returns (address); | ||
function eur() external view returns (address); | ||
function coin(address, uint256) external; | ||
} | ||
|
||
contract DeepStack { | ||
address public immutable bow; | ||
ERC20Like public immutable usd; | ||
ERC20Like public immutable eur; | ||
CoinLike public immutable usdCoin; | ||
CoinLike public immutable eurCoin; | ||
|
||
event Bow(address indexed token, uint256 amount); | ||
|
||
constructor(address usdCoin_, address eurCoin_, address bow_) { | ||
usdCoin = CoinLike(usdCoin_); | ||
usd = ERC20Like(usdCoin.usd()); | ||
eurCoin = CoinLike(eurCoin_); | ||
eur = ERC20Like(eurCoin.eur()); | ||
bow = bow_; | ||
usd.approve(usdCoin_, type(uint256).max); | ||
eur.approve(eurCoin_, type(uint256).max); | ||
} | ||
|
||
function whistle() public { | ||
uint256 usdBalance = usd.balanceOf(address(this)); | ||
if (usdBalance > 0) { | ||
usdCoin.coin(bow, usdBalance); | ||
emit Bow(address(usd), usdBalance); | ||
} | ||
uint256 eurBalance = eur.balanceOf(address(this)); | ||
if (eurBalance > 0) { | ||
eurCoin.coin(bow, eurBalance); | ||
emit Bow(address(eur), eurBalance); | ||
} | ||
} | ||
} |
This file was deleted.
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,76 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity 0.8.26; | ||
|
||
import {Test, console} from "forge-std/Test.sol"; | ||
import "src/DeepStack.sol"; | ||
|
||
interface BssLike { | ||
function dai(address) external returns (uint256); | ||
} | ||
|
||
contract DeepStackTest is Test { | ||
address constant BANK = address(555); | ||
address constant USD = address(444); | ||
address constant EUR = address(333); | ||
address constant BOW = address(222); | ||
uint256 constant RAY = 10**27; | ||
|
||
BssLike public bss; | ||
DeepStack public deepStack; | ||
|
||
address usd; | ||
address usdCoin; | ||
address eur; | ||
address eurCoin; | ||
address bow; | ||
|
||
event Bow(address indexed token, uint256 amount); | ||
|
||
function setUp() public { | ||
vm.createSelectFork("mainnet"); | ||
// get all the relevant addresses | ||
bss = BssLike(BANK); | ||
usd = USD; | ||
usdCoin = USD; | ||
eur = EUR; | ||
eurCoin = EUR; | ||
bow = BOW; | ||
|
||
deepStack = new DeepStack(usdCoin, usdCoin, bow); | ||
|
||
vm.label(usd, "Dai"); | ||
vm.label(usdCoin, "DaiJoin"); | ||
vm.label(eur, "Usds"); | ||
vm.label(eurCoin, "UsdsJoin"); | ||
vm.label(bow, "Bow"); | ||
} | ||
|
||
function test_blow() public { | ||
// send dai and eur to DssBlow2 | ||
uint256 daiAmount = 10 ether; | ||
uint256 eurAmount = 5 ether; | ||
deal(address(usd), address(deepStack), daiAmount); | ||
deal(eur, address(deepStack), eurAmount); | ||
// store balances before blow() | ||
uint256 vowDaiBalance = bss.dai(bow); | ||
uint256 blowDaiBalance = ERC20Like(usd).balanceOf(address(deepStack)); | ||
uint256 blowEurBalance = ERC20Like(eur).balanceOf(address(deepStack)); | ||
assertEq(blowDaiBalance, daiAmount); | ||
assertEq(blowEurBalance, eurAmount); | ||
// event emission | ||
vm.expectEmit(true, false, false, true); | ||
emit Bow(address(usd), daiAmount); | ||
vm.expectEmit(true, false, false, true); | ||
emit Bow(eur, eurAmount); | ||
// call blow() | ||
deepStack.bow(); | ||
// check balances after blow() | ||
blowDaiBalance = ERC20Like(usd).balanceOf(address(deepStack)); | ||
blowEurBalance = ERC20Like(eur).balanceOf(address(deepStack)); | ||
assertEq(blowDaiBalance, 0); | ||
assertEq(blowEurBalance, 0); | ||
// the vat dai balance is in rad so we multiply with ray | ||
assertEq(bss.dai(bow), vowDaiBalance + (daiAmount + eurAmount) * RAY, "blowDaiEur: vow balance mismatch"); | ||
} | ||
|
||
} |