// hevm: flattened sources of /nix/store/k8y52yly1kzii65m0yw5pbidrq3jlajh-dss-deploy-001fb27/src/join.sol
pragma solidity =0.5.12;
////// /nix/store/4vip6nyqfd0yhs15md21rzxsk5jgx6sv-dss/dapp/dss/src/lib.sol
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
/* pragma solidity 0.5.12; */
contract LibNote {
event LogNote(
bytes4 indexed sig,
address indexed usr,
bytes32 indexed arg1,
bytes32 indexed arg2,
bytes data
) anonymous;
modifier note {
_;
assembly {
// log an 'anonymous' event with a constant 6 words of calldata
// and four indexed topics: selector, caller, arg1 and arg2
let mark := msize // end of memory ensures zero
mstore(0x40, add(mark, 288)) // update free memory pointer
mstore(mark, 0x20) // bytes type data offset
mstore(add(mark, 0x20), 224) // bytes size (padded)
calldatacopy(add(mark, 0x40), 0, 224) // bytes payload
log4(mark, 288, // calldata
shl(224, shr(224, calldataload(0))), // msg.sig
caller, // msg.sender
calldataload(4), // arg1
calldataload(36) // arg2
)
}
}
}
////// /nix/store/k8y52yly1kzii65m0yw5pbidrq3jlajh-dss-deploy-001fb27/src/join.sol
/// join.sol -- Non-standard token adapters
// Copyright (C) 2018 Rain <rainbreak@riseup.net>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
/* pragma solidity 0.5.12; */
/* import "dss/lib.sol"; */
contract VatLike {
function slip(bytes32,address,int) public;
}
// GemJoin2
// For a token that does not return a bool on transfer or transferFrom (like OMG)
// This is one way of doing it. Check the balances before and after calling a transfer
contract GemLike2 {
function decimals() public view returns (uint);
function transfer(address,uint) public;
function transferFrom(address,address,uint) public;
function balanceOf(address) public view returns (uint);
function allowance(address,address) public view returns (uint);
}
contract GemJoin2 is LibNote {
// --- Auth ---
mapping (address => uint) public wards;
function rely(address usr) external note auth { wards[usr] = 1; }
function deny(address usr) external note auth { wards[usr] = 0; }
modifier auth { require(wards[msg.sender] == 1); _; }
VatLike public vat;
bytes32 public ilk;
GemLike2 public gem;
uint public dec;
uint public live; // Access Flag
constructor(address vat_, bytes32 ilk_, address gem_) public {
wards[msg.sender] = 1;
live = 1;
vat = VatLike(vat_);
ilk = ilk_;
gem = GemLike2(gem_);
dec = gem.decimals();
}
function cage() external note auth {
live = 0;
}
function mul(uint x, uint y) internal pure returns (uint z) {
require(y == 0 || (z = x * y) / y == x, "GemJoin2/overflow");
}
function join(address urn, uint wad) public note {
require(live == 1, "GemJoin2/not-live");
require(wad <= 2 ** 255, "GemJoin2/overflow");
vat.slip(ilk, urn, int(wad));
uint256 prevBalance = gem.balanceOf(msg.sender);
require(prevBalance >= wad, "GemJoin2/no-funds");
require(gem.allowance(msg.sender, address(this)) >= wad, "GemJoin2/no-allowance");
(bool ok,) = address(gem).call(
abi.encodeWithSignature("transferFrom(address,address,uint256)", msg.sender, address(this), wad)
);
require(ok, "GemJoin2/failed-transfer");
require(prevBalance - wad == gem.balanceOf(msg.sender), "GemJoin2/failed-transfer");
}
function exit(address guy, uint wad) public note {
require(wad <= 2 ** 255, "GemJoin2/overflow");
vat.slip(ilk, msg.sender, -int(wad));
uint256 prevBalance = gem.balanceOf(address(this));
require(prevBalance >= wad, "GemJoin2/no-funds");
(bool ok,) = address(gem).call(
abi.encodeWithSignature("transfer(address,uint256)", guy, wad)
);
require(ok, "GemJoin2/failed-transfer");
require(prevBalance - wad == gem.balanceOf(address(this)), "GemJoin2/failed-transfer");
}
}
// GemJoin3
// For a token that has a lower precision than 18 and doesn't have decimals field in place (like DGD)
contract GemLike3 {
function transfer(address,uint) public returns (bool);
function transferFrom(address,address,uint) public returns (bool);
}
contract GemJoin3 is LibNote {
// --- Auth ---
mapping (address => uint) public wards;
function rely(address usr) external note auth { wards[usr] = 1; }
function deny(address usr) external note auth { wards[usr] = 0; }
modifier auth { require(wards[msg.sender] == 1); _; }
VatLike public vat;
bytes32 public ilk;
GemLike3 public gem;
uint public dec;
uint public live; // Access Flag
constructor(address vat_, bytes32 ilk_, address gem_, uint decimals) public {
require(decimals < 18, "GemJoin3/decimals-18-or-higher");
wards[msg.sender] = 1;
live = 1;
vat = VatLike(vat_);
ilk = ilk_;
gem = GemLike3(gem_);
dec = decimals;
}
function cage() external note auth {
live = 0;
}
function mul(uint x, uint y) internal pure returns (uint z) {
require(y == 0 || (z = x * y) / y == x, "GemJoin3/overflow");
}
function join(address urn, uint wad) public note {
require(live == 1, "GemJoin3/not-live");
uint wad18 = mul(wad, 10 ** (18 - dec));
require(wad18 <= 2 ** 255, "GemJoin3/overflow");
vat.slip(ilk, urn, int(wad18));
require(gem.transferFrom(msg.sender, address(this), wad), "GemJoin3/failed-transfer");
}
function exit(address guy, uint wad) public note {
uint wad18 = mul(wad, 10 ** (18 - dec));
require(wad18 <= 2 ** 255, "GemJoin3/overflow");
vat.slip(ilk, msg.sender, -int(wad18));
require(gem.transfer(guy, wad), "GemJoin3/failed-transfer");
}
}
/// GemJoin4
// Copyright (C) 2019 Lorenzo Manacorda <lorenzo@mailbox.org>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// For tokens that do not implement transferFrom (like GNT), meaning the usual adapter
// approach won't work: the adapter cannot call transferFrom and therefore
// has no way of knowing when users deposit gems into it.
// To work around this, we introduce the concept of a bag, which is a trusted
// (it's created by the adapter), personalized component (one for each user).
// Users first have to create their bag with `GemJoin4.make`, then transfer
// gem to it, and then call `GemJoin4.join`, which transfer the gems from the
// bag to the adapter.
contract GemLike4 {
function decimals() public view returns (uint);
function balanceOf(address) public returns (uint256);
function transfer(address, uint256) public returns (bool);
}
contract GemBag {
address public ada;
address public lad;
GemLike4 public gem;
constructor(address lad_, address gem_) public {
ada = msg.sender;
lad = lad_;
gem = GemLike4(gem_);
}
function exit(address usr, uint256 wad) external {
require(msg.sender == ada || msg.sender == lad, "GemBag/invalid-caller");
require(gem.transfer(usr, wad), "GemBag/failed-transfer");
}
}
contract GemJoin4 is LibNote {
// --- Auth ---
mapping (address => uint) public wards;
function rely(address usr) external note auth { wards[usr] = 1; }
function deny(address usr) external note auth { wards[usr] = 0; }
modifier auth { require(wards[msg.sender] == 1); _; }
VatLike public vat;
bytes32 public ilk;
GemLike4 public gem;
uint public dec;
uint public live; // Access Flag
mapping(address => address) public bags;
constructor(address vat_, bytes32 ilk_, address gem_) public {
wards[msg.sender] = 1;
live = 1;
vat = VatLike(vat_);
ilk = ilk_;
gem = GemLike4(gem_);
dec = gem.decimals();
}
function cage() external note auth {
live = 0;
}
// -- admin --
function make() external returns (address bag) {
bag = make(msg.sender);
}
function make(address usr) public note returns (address bag) {
require(bags[usr] == address(0), "GemJoin4/bag-already-exists");
bag = address(new GemBag(address(usr), address(gem)));
bags[usr] = bag;
}
// -- gems --
function join(address urn, uint256 wad) external note {
require(live == 1, "GemJoin4/not-live");
require(int256(wad) >= 0, "GemJoin4/negative-amount");
GemBag(bags[msg.sender]).exit(address(this), wad);
vat.slip(ilk, urn, int256(wad));
}
function exit(address usr, uint256 wad) external note {
require(int256(wad) >= 0, "GemJoin4/negative-amount");
vat.slip(ilk, msg.sender, -int256(wad));
require(gem.transfer(usr, wad), "GemJoin4/failed-transfer");
}
}
// AuthGemJoin
// For a token that needs restriction on the sources which are able to execute the join function (like SAI through Migration contract)
contract GemLike {
function decimals() public view returns (uint);
function transfer(address,uint) public returns (bool);
function transferFrom(address,address,uint) public returns (bool);
}
contract AuthGemJoin is LibNote {
VatLike public vat;
bytes32 public ilk;
GemLike public gem;
uint public dec;
uint public live; // Access Flag
// --- 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 {
wards[msg.sender] = 1;
live = 1;
vat = VatLike(vat_);
ilk = ilk_;
gem = GemLike(gem_);
dec = gem.decimals();
}
function cage() external note auth {
live = 0;
}
function join(address usr, uint wad) public auth note {
require(live == 1, "AuthGemJoin/not-live");
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 note {
require(wad <= 2 ** 255, "AuthGemJoin/overflow");
vat.slip(ilk, msg.sender, -int(wad));
require(gem.transfer(usr, wad), "AuthGemJoin/failed-transfer");
}
}
{
"compilationTarget": {
"AuthGemJoin.sol": "AuthGemJoin"
},
"evmVersion": "petersburg",
"libraries": {},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"vat_","type":"address"},{"internalType":"bytes32","name":"ilk_","type":"bytes32"},{"internalType":"address","name":"gem_","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":true,"inputs":[{"indexed":true,"internalType":"bytes4","name":"sig","type":"bytes4"},{"indexed":true,"internalType":"address","name":"usr","type":"address"},{"indexed":true,"internalType":"bytes32","name":"arg1","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"arg2","type":"bytes32"},{"indexed":false,"internalType":"bytes","name":"data","type":"bytes"}],"name":"LogNote","type":"event"},{"constant":false,"inputs":[],"name":"cage","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"dec","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"usr","type":"address"}],"name":"deny","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"usr","type":"address"},{"internalType":"uint256","name":"wad","type":"uint256"}],"name":"exit","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"gem","outputs":[{"internalType":"contract GemLike","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"ilk","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"usr","type":"address"},{"internalType":"uint256","name":"wad","type":"uint256"}],"name":"join","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"live","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"usr","type":"address"}],"name":"rely","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"vat","outputs":[{"internalType":"contract VatLike","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"wards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}]