Skip to content

Commit

Permalink
Add SAI collateral
Browse files Browse the repository at this point in the history
  • Loading branch information
gbalabasquer committed Aug 15, 2019
1 parent 6100d63 commit 85a3ce7
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 3 deletions.
8 changes: 8 additions & 0 deletions bin/deploy-all
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,11 @@ message DEPLOYING GNT
source "$ADDRESS_DIR/load-ilk-gnt-a-$(seth chain)"

# -----------------------------------------------------------------------------------------

message DEPLOYING SAI

"$BIN_DIR/deploy-ilk-sai"
# shellcheck source=/dev/null
source "$ADDRESS_DIR/load-ilk-sai-$(seth chain)"

# -----------------------------------------------------------------------------------------
11 changes: 8 additions & 3 deletions bin/deploy-ilk
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ export ETH_FROM=${ETH_FROM:-$(seth rpc eth_coinbase)}

dappBuild

{ test -z "$1" || test -z "$2" || test -z "$3"; } && exit 1
{ test -z "$1" || test -z "$3"; } && exit 1

tok=$1
ilk="${1}-${2}"
ilkVar="${1}_${2}"
if [[ -n "$2" ]]; then
ilk="${1}-${2}"
ilkVar="${1}_${2}"
else
ilk="${1}"
ilkVar="${1}"
fi
ilkJoin=$3 # adapter contract name
decimals=$4

Expand Down
16 changes: 16 additions & 0 deletions bin/deploy-ilk-sai
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

# shellcheck source=bin/lib/common.sh
. "${LIB_DIR:-$(cd "${0%/*}/lib"&&pwd)}/common.sh"

export ETH_FROM=${ETH_FROM:-$(seth rpc eth_coinbase)}

dappBuild

test -z "$SAI" && SAI=$(dapp create DSToken "$(seth --to-bytes32 "$(seth --from-ascii "SAI")")")
test -z "$PIP_SAI" && PIP_SAI=$(dapp create DSValue)
export SAI
export PIP_SAI

# shellcheck source=/dev/null
source "$BIN_DIR/deploy-ilk" "SAI" "" "AuthGemJoin"
39 changes: 39 additions & 0 deletions src/DssDeploy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ contract DssDeployTest is DssDeployTestBase {
function testTokens() public {
deployKeepAuth();
DSValue pip = new DSValue();

REP rep = new REP(100 ether);
GemJoin1 repJoin = new GemJoin1(address(vat), "REP", address(rep));
assertEq(repJoin.dec(), 18);
Expand Down Expand Up @@ -684,6 +685,44 @@ contract DssDeployTest is DssDeployTestBase {
assertEq(vat.gem("GNT", address(this)), 6);
}

function testTokenSai() public {
deployKeepAuth();
DSValue pip = new DSValue();

DSToken sai = new DSToken("SAI");
sai.mint(10);
AuthGemJoin saiJoin = new AuthGemJoin(address(vat), "SAI", address(sai));
assertEq(saiJoin.dec(), 18);

dssDeploy.deployCollateral("SAI", address(saiJoin), address(pip));

sai.approve(address(saiJoin), uint(-1));
assertEq(sai.balanceOf(address(saiJoin)), 0);
assertEq(vat.gem("SAI", address(this)), 0);
saiJoin.join(address(this), 10);
assertEq(sai.balanceOf(address(saiJoin)), 10);
assertEq(vat.gem("SAI", address(this)), 10);
saiJoin.exit(address(this), 4);
assertEq(sai.balanceOf(address(saiJoin)), 6);
assertEq(vat.gem("SAI", address(this)), 6);
}

function testFailTokenSai() public {
deployKeepAuth();
DSValue pip = new DSValue();

DSToken sai = new DSToken("SAI");
sai.mint(10);
AuthGemJoin saiJoin = new AuthGemJoin(address(vat), "SAI", address(sai));
assertEq(saiJoin.dec(), 18);

dssDeploy.deployCollateral("SAI", address(saiJoin), address(pip));

sai.approve(address(saiJoin), uint(-1));
saiJoin.deny(address(this));
saiJoin.join(address(this), 10);
}

function testAuth() public {
deployKeepAuth();

Expand Down
35 changes: 35 additions & 0 deletions src/join.sol
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,38 @@ contract GemJoin4 is DSNote {
require(gem.transfer(usr, wad), "GemJoin4/failed-transfer");
}
}

// AuthGemJoin

contract AuthGemJoin is DSNote {
VatLike public vat;
bytes32 public ilk;
GemLike public gem;
uint public dec;

// --- Auth ---
mapping (address => uint) public wards;
function rely(address usr) public note auth { wards[usr] = 1; }
function deny(address usr) public note auth { wards[usr] = 0; }
modifier auth { require(wards[msg.sender] == 1, "AuthGemJoin/non-authed"); _; }

constructor(address vat_, bytes32 ilk_, address gem_) public {
vat = VatLike(vat_);
ilk = ilk_;
gem = GemLike(gem_);
dec = gem.decimals();
wards[msg.sender] = 1;
}

function join(address usr, uint wad) public auth note {
require(int(wad) >= 0, "AuthGemJoin/overflow");
vat.slip(ilk, usr, int(wad));
require(gem.transferFrom(msg.sender, address(this), wad), "AuthGemJoin/failed-transfer");
}

function exit(address usr, uint wad) public auth note {
require(wad <= 2 ** 255, "AuthGemJoin/overflow");
vat.slip(ilk, msg.sender, -int(wad));
require(gem.transfer(usr, wad), "AuthGemJoin/failed-transfer");
}
}

0 comments on commit 85a3ce7

Please sign in to comment.