Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
cash(wad)
Browse files Browse the repository at this point in the history
allows working around rounding issues in cash
  • Loading branch information
rainbreak committed Nov 21, 2017
1 parent e05fd82 commit 2c177a7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
7 changes: 4 additions & 3 deletions libexec/sai/sai-cash
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash
### sai-cash -- cash in sai balance for gems after cage
set -e
sai=$(token balance "$(sai sai)" "${ETH_FROM?}")
echo >&2 "Cashing in $sai SAI..."
(set -x; seth send "${SAI_TAP?}" "cash()")
jam=$(token balance "$(sai sai)" "${ETH_FROM?}")
echo >&2 "Cashing in $jam SAI..."
wad=$(sai wad $jam)
(set -x; seth send "${SAI_TAP?}" "cash(uint256)" $wad )
36 changes: 18 additions & 18 deletions src/sai.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ contract FakePerson {
}

function cash() public {
tap.cash();
tap.cash(sai.balanceOf(this));
}
}

Expand Down Expand Up @@ -570,7 +570,7 @@ contract CageTest is SaiTestBase {
assertEq(gem.balanceOf(tub), 5 ether);
assertEq(gem.balanceOf(tap), 5 ether);

tap.cash();
tap.cash(sai.balanceOf(this));
assertEq(sai.balanceOf(this), 0 ether);
assertEq(skr.balanceOf(this), 0 ether);
assertEq(gem.balanceOf(this), 95 ether);
Expand Down Expand Up @@ -606,7 +606,7 @@ contract CageTest is SaiTestBase {
tap.vent();
top.flow();
assertEq(skr.balanceOf(this), 25 ether);
tap.cash();
tap.cash(sai.balanceOf(this));
tub.exit(uint256(skr.balanceOf(this)));
assertEq(gem.balanceOf(this), 100 ether);
assertEq(sai.balanceOf(this), 0 ether);
Expand All @@ -625,7 +625,7 @@ contract CageTest is SaiTestBase {
mark(1 ether);
top.cage();

tap.cash();
tap.cash(sai.balanceOf(this));
tub.exit(uint256(skr.balanceOf(this)));
assertEq(skr.balanceOf(this), 0 ether);
uint256 gemBySAI = 5 ether; // Adding 5 gem from 5 sai
Expand Down Expand Up @@ -662,7 +662,7 @@ contract CageTest is SaiTestBase {
assertEq(skr.balanceOf(this), 20 ether);
assertEq(gem.balanceOf(this), 70 ether);

tap.cash();
tap.cash(sai.balanceOf(this));
assertEq(sai.balanceOf(this), 0 ether);
assertEq(skr.balanceOf(this), 20 ether);

Expand Down Expand Up @@ -706,7 +706,7 @@ contract CageTest is SaiTestBase {
assertEq(sai.balanceOf(this), 5 ether);
assertEq(skr.balanceOf(this), 0 ether);
assertEq(gem.balanceOf(this), 90 ether);
tap.cash();
tap.cash(sai.balanceOf(this));
assertEq(sai.balanceOf(this), 0 ether);
assertEq(skr.balanceOf(this), 0 ether);

Expand Down Expand Up @@ -740,7 +740,7 @@ contract CageTest is SaiTestBase {
assertEq(skr.balanceOf(this), 20 ether);
assertEq(gem.balanceOf(this), 70 ether);

tap.cash();
tap.cash(sai.balanceOf(this));
assertEq(sai.balanceOf(this), 0 ether);

tub.bite(cup);
Expand All @@ -764,7 +764,7 @@ contract CageTest is SaiTestBase {
assertEq(skr.balanceOf(this), 20 ether);
assertEq(gem.balanceOf(this), 70 ether);

tap.cash();
tap.cash(sai.balanceOf(this));
assertEq(sai.balanceOf(this), 0 ether);
tub.exit(uint256(skr.balanceOf(this)));
assertEq(skr.balanceOf(this), 0 ether);
Expand Down Expand Up @@ -799,7 +799,7 @@ contract CageTest is SaiTestBase {
assertEq(sai.balanceOf(this), 5 ether);
assertEq(skr.balanceOf(this), 0 ether);
assertEq(gem.balanceOf(this), 90 ether);
tap.cash();
tap.cash(sai.balanceOf(this));
assertEq(sai.balanceOf(this), 0 ether);
assertEq(skr.balanceOf(this), 0 ether);

Expand Down Expand Up @@ -831,7 +831,7 @@ contract CageTest is SaiTestBase {

assertEq(sai.balanceOf(this), 5 ether);
assertEq(gem.balanceOf(this), 70 ether);
tap.cash();
tap.cash(sai.balanceOf(this));
assertEq(sai.balanceOf(this), 0 ether);
// returns 20 gems, taken from the free skr,
// sai is made whole
Expand Down Expand Up @@ -894,7 +894,7 @@ contract CageTest is SaiTestBase {
assertEq(skr.balanceOf(this), 95 ether); // free skr
assertEq(skr.balanceOf(tub), 0); // locked skr

tap.cash();
tap.cash(sai.balanceOf(this));

assertEq(sai.balanceOf(this), 0);
assertEq(gem.balanceOf(this), 5 ether);
Expand Down Expand Up @@ -947,7 +947,7 @@ contract CageTest is SaiTestBase {
assertEq(skr.balanceOf(this), 90 ether); // free skr
assertEq(skr.balanceOf(tub), 0); // locked skr

tap.cash();
tap.cash(sai.balanceOf(this));

assertEq(sai.balanceOf(this), 0);
assertEq(gem.balanceOf(this), 10 ether);
Expand Down Expand Up @@ -1000,7 +1000,7 @@ contract CageTest is SaiTestBase {
assertEq(skr.balanceOf(this), 90 ether); // free skr
assertEq(skr.balanceOf(tub), 0); // locked skr

tap.cash();
tap.cash(sai.balanceOf(this));

assertEq(sai.balanceOf(this), 0);
assertEq(gem.balanceOf(this), 20 ether);
Expand Down Expand Up @@ -1053,7 +1053,7 @@ contract CageTest is SaiTestBase {
assertEq(skr.balanceOf(this), 90 ether); // free skr
assertEq(skr.balanceOf(tub), 0); // locked skr

tap.cash();
tap.cash(sai.balanceOf(this));

assertEq(sai.balanceOf(this), 0);
assertEq(gem.balanceOf(this), 100 ether);
Expand Down Expand Up @@ -1087,7 +1087,7 @@ contract CageTest is SaiTestBase {
assertEq(gem.balanceOf(tap), rmul(5 ether, top.fix())); // Needed to payout 5 sai
assertEq(gem.balanceOf(tub), sub(10 ether, rmul(5 ether, top.fix())));

tap.cash();
tap.cash(sai.balanceOf(this));

assertEq(sai.balanceOf(this), 0 ether);
assertEq(sai.balanceOf(person), 2.5 ether);
Expand Down Expand Up @@ -1123,7 +1123,7 @@ contract CageTest is SaiTestBase {

// now we can cash in our sai
assertEq(sai.balanceOf(this), 5 ether);
tap.cash();
tap.cash(sai.balanceOf(this));
assertEq(sai.balanceOf(this), 0 ether);
assertEq(gem.balanceOf(this), 97 ether);

Expand Down Expand Up @@ -1721,7 +1721,7 @@ contract TaxTest is SaiTestBase {

assertEq(sai.balanceOf(this), 100 ether);
assertEq(gem.balanceOf(this), 1000 ether);
tap.cash();
tap.cash(sai.balanceOf(this));
assertEq(sai.balanceOf(this), 0 ether);
assertEq(gem.balanceOf(this), 1010 ether);
}
Expand Down Expand Up @@ -1826,7 +1826,7 @@ contract WayTest is SaiTestBase {
assertEq(gem.balanceOf(this), 1000 ether);
assertEq(sai.balanceOf(this), 100 ether);
assertEq(sai.balanceOf(tap), 0 ether);
tap.cash();
tap.cash(sai.balanceOf(this));
assertEq(gem.balanceOf(this), 1020 ether);
assertEq(sai.balanceOf(this), 0 ether);
assertEq(sai.balanceOf(tap), 100 ether);
Expand Down
3 changes: 1 addition & 2 deletions src/tap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ contract SaiTap is DSThing {
off = true;
fix = fix_;
}
function cash() public note {
function cash(uint wad) public note {
require(off);
var wad = sai.balanceOf(msg.sender);
sai.pull(msg.sender, wad);
tub.gem().transfer(msg.sender, rmul(wad, fix));
}
Expand Down

0 comments on commit 2c177a7

Please sign in to comment.