Transaction Hash:
Block:
14175365 at Feb-10-2022 01:20:58 AM +UTC
Transaction Fee:
0.031755812574776977 ETH
$76.57
Gas Used:
383,503 Gas / 82.804600159 Gwei
Account State Difference:
Address | Before | After | State Difference | ||
---|---|---|---|---|---|
0x6F352D71...A96307d8F |
16.537434714753495121 Eth
Nonce: 36
|
16.505678902178718144 Eth
Nonce: 37
| 0.031755812574776977 | ||
0x7F101fE4...353f2B90c
Miner
| (Flexpool.io) | 4,891.134773891829220796 Eth | 4,891.135349146329220796 Eth | 0.0005752545 |
Execution Trace
USRProxy.1e9a6950( )

0xd4eef282f58ecaf12118e96ed4c06f60f88009c6.1e9a6950( )
USRProxy.CALL( )
0x47992aaada10c4b55659ff5e4d95527b8d50e434.DELEGATECALL( )
-
DFStore.STATICCALL( )
DFProxy.b8964b06( )
0x93ae5ebbe4dae9aefd33425ef084d0fd457b8dc6.b8964b06( )
-
0x26472cc7f4cb43ae9b3f18c705de8c34578933f9.STATICCALL( )
-
DFStore.getWrappedToken( _srcToken=0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359 ) => ( 0x26472Cc7F4cB43ae9b3F18c705De8c34578933F9 )
-
DSToken.balanceOf( src=0x7FdcDAd3b4a67e00D9fD5F22f4FD89a5fa4f57bA ) => ( 0 )
-
0x26472cc7f4cb43ae9b3f18c705de8c34578933f9.70a08231( )
-
0x26472cc7f4cb43ae9b3f18c705de8c34578933f9.3831ac93( )
-
0x26472cc7f4cb43ae9b3f18c705de8c34578933f9.52e24eb1( )
-
0x26472cc7f4cb43ae9b3f18c705de8c34578933f9.70a08231( )
-
DFProxy.b8964b06( )
0x93ae5ebbe4dae9aefd33425ef084d0fd457b8dc6.b8964b06( )
-
0x666ed86f5ed0e80d8f441002b1ae08dcbaeff1e6.STATICCALL( )
-
DFStore.getWrappedToken( _srcToken=0x8E870D67F660D95d5be530380D0eC0bd388289E1 ) => ( 0x666ed86F5eD0E80d8F441002B1AE08dcbaeff1E6 )
-
AdminUpgradeabilityProxy.70a08231( )
-
0x666ed86f5ed0e80d8f441002b1ae08dcbaeff1e6.70a08231( )
-
0x666ed86f5ed0e80d8f441002b1ae08dcbaeff1e6.3831ac93( )
-
0x666ed86f5ed0e80d8f441002b1ae08dcbaeff1e6.52e24eb1( )
-
0x666ed86f5ed0e80d8f441002b1ae08dcbaeff1e6.70a08231( )
-
DFProxy.b8964b06( )
0x93ae5ebbe4dae9aefd33425ef084d0fd457b8dc6.b8964b06( )
-
0x284bfce387b079eb3461d7da9399266662e697c5.STATICCALL( )
-
DFStore.getWrappedToken( _srcToken=0x0000000000085d4780B73119b644AE5ecd22b376 ) => ( 0x284BFCE387B079Eb3461d7DA9399266662E697C5 )
-
OwnedUpgradeabilityProxy.70a08231( )
-
0x284bfce387b079eb3461d7da9399266662e697c5.70a08231( )
-
0x284bfce387b079eb3461d7da9399266662e697c5.3831ac93( )
-
0x284bfce387b079eb3461d7da9399266662e697c5.52e24eb1( )
-
0x284bfce387b079eb3461d7da9399266662e697c5.70a08231( )
-
DFProxy.b8964b06( )
0x93ae5ebbe4dae9aefd33425ef084d0fd457b8dc6.b8964b06( )
-
0x369dffbb1d8f49ecf63501e2d175742ae1bfdfc8.STATICCALL( )
-
DFStore.getWrappedToken( _srcToken=0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 ) => ( 0x369dFFbB1D8F49ecF63501E2d175742aE1bfDFC8 )
-
FiatTokenProxy.70a08231( )
-
0x369dffbb1d8f49ecf63501e2d175742ae1bfdfc8.70a08231( )
-
0x369dffbb1d8f49ecf63501e2d175742ae1bfdfc8.3831ac93( )
-
0x369dffbb1d8f49ecf63501e2d175742ae1bfdfc8.52e24eb1( )
-
0x369dffbb1d8f49ecf63501e2d175742ae1bfdfc8.70a08231( )
-
-
-
DSToken.balanceOf( src=0xeF004C5CdFaaB19299B3ED66f14Ec010Fe5F20d0 ) => ( 56022184212312372828468 )
-
DSToken.balanceOf( src=0xeF004C5CdFaaB19299B3ED66f14Ec010Fe5F20d0 ) => ( 56022184212312372828468 )
USRProxy.08669aab( )
0x47992aaada10c4b55659ff5e4d95527b8d50e434.08669aab( )
-
DSGuard.canCall( src_=0xeF004C5CdFaaB19299B3ED66f14Ec010Fe5F20d0, dst_=0x2Cd4E8D82f62a91b2299B083Ba08532A6A96a13a, sig=System.Byte[] ) => ( True )
-
DFStore.STATICCALL( )
DFProxy.b8964b06( )
0x93ae5ebbe4dae9aefd33425ef084d0fd457b8dc6.b8964b06( )
-
0x26472cc7f4cb43ae9b3f18c705de8c34578933f9.STATICCALL( )
-
DFStore.getWrappedToken( _srcToken=0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359 ) => ( 0x26472Cc7F4cB43ae9b3F18c705De8c34578933F9 )
-
DSToken.balanceOf( src=0x7FdcDAd3b4a67e00D9fD5F22f4FD89a5fa4f57bA ) => ( 0 )
-
0x26472cc7f4cb43ae9b3f18c705de8c34578933f9.70a08231( )
-
0x26472cc7f4cb43ae9b3f18c705de8c34578933f9.3831ac93( )
-
0x26472cc7f4cb43ae9b3f18c705de8c34578933f9.52e24eb1( )
-
0x26472cc7f4cb43ae9b3f18c705de8c34578933f9.70a08231( )
-
DFProxy.b8964b06( )
0x93ae5ebbe4dae9aefd33425ef084d0fd457b8dc6.b8964b06( )
-
0x666ed86f5ed0e80d8f441002b1ae08dcbaeff1e6.STATICCALL( )
-
DFStore.getWrappedToken( _srcToken=0x8E870D67F660D95d5be530380D0eC0bd388289E1 ) => ( 0x666ed86F5eD0E80d8F441002B1AE08dcbaeff1E6 )
-
AdminUpgradeabilityProxy.70a08231( )
-
0x666ed86f5ed0e80d8f441002b1ae08dcbaeff1e6.70a08231( )
-
0x666ed86f5ed0e80d8f441002b1ae08dcbaeff1e6.3831ac93( )
-
0x666ed86f5ed0e80d8f441002b1ae08dcbaeff1e6.52e24eb1( )
-
0x666ed86f5ed0e80d8f441002b1ae08dcbaeff1e6.70a08231( )
-
DFProxy.b8964b06( )
0x93ae5ebbe4dae9aefd33425ef084d0fd457b8dc6.b8964b06( )
-
0x284bfce387b079eb3461d7da9399266662e697c5.STATICCALL( )
-
DFStore.getWrappedToken( _srcToken=0x0000000000085d4780B73119b644AE5ecd22b376 ) => ( 0x284BFCE387B079Eb3461d7DA9399266662E697C5 )
-
OwnedUpgradeabilityProxy.70a08231( )
-
0x284bfce387b079eb3461d7da9399266662e697c5.70a08231( )
-
0x284bfce387b079eb3461d7da9399266662e697c5.3831ac93( )
-
0x284bfce387b079eb3461d7da9399266662e697c5.52e24eb1( )
-
0x284bfce387b079eb3461d7da9399266662e697c5.70a08231( )
-
DFProxy.b8964b06( )
0x93ae5ebbe4dae9aefd33425ef084d0fd457b8dc6.b8964b06( )
-
0x369dffbb1d8f49ecf63501e2d175742ae1bfdfc8.STATICCALL( )
-
DFStore.getWrappedToken( _srcToken=0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 ) => ( 0x369dFFbB1D8F49ecF63501E2d175742aE1bfDFC8 )
-
FiatTokenProxy.70a08231( )
-
0x369dffbb1d8f49ecf63501e2d175742ae1bfdfc8.70a08231( )
-
0x369dffbb1d8f49ecf63501e2d175742ae1bfdfc8.3831ac93( )
-
0x369dffbb1d8f49ecf63501e2d175742ae1bfdfc8.52e24eb1( )
-
0x369dffbb1d8f49ecf63501e2d175742ae1bfdfc8.70a08231( )
-
-
0x369dffbb1d8f49ecf63501e2d175742ae1bfdfc8.3831ac93( )
DFProxy.48fdf3a2( )
0x93ae5ebbe4dae9aefd33425ef084d0fd457b8dc6.48fdf3a2( )
-
DSGuard.canCall( src_=0x2Cd4E8D82f62a91b2299B083Ba08532A6A96a13a, dst_=0x7FdcDAd3b4a67e00D9fD5F22f4FD89a5fa4f57bA, sig=System.Byte[] ) => ( True )
-
FiatTokenProxy.70a08231( )
-
FiatTokenProxy.a9059cbb( )
-
FiatTokenProxy.70a08231( )
-
Funds.transferOut( _token=0xeb269732ab75A6fD61Ea60b06fE994cD32a83549, _to=0xeF004C5CdFaaB19299B3ED66f14Ec010Fe5F20d0, _amount=159961669036652214760789 )
-
File 1 of 11: USRProxy
File 2 of 11: USRProxy
File 3 of 11: DFStore
File 4 of 11: DFProxy
File 5 of 11: DSToken
File 6 of 11: AdminUpgradeabilityProxy
File 7 of 11: OwnedUpgradeabilityProxy
File 8 of 11: FiatTokenProxy
File 9 of 11: DSToken
File 10 of 11: DSGuard
File 11 of 11: Funds
pragma solidity 0.5.12; contract Proxy { function() external payable { _fallback(); } function _implementation() internal view returns (address); function _delegate(address implementation) internal { assembly { calldatacopy(0, 0, calldatasize) let result := delegatecall( gas, implementation, 0, calldatasize, 0, 0 ) returndatacopy(0, 0, returndatasize) switch result case 0 { revert(0, returndatasize) } default { return(0, returndatasize) } } } function _willFallback() internal {} function _fallback() internal { _willFallback(); _delegate(_implementation()); } } library AddressUtils { function isContract(address addr) internal view returns (bool) { uint256 size; assembly { size := extcodesize(addr) } return size > 0; } } contract UpgradeabilityProxy is Proxy { event Upgraded(address implementation); bytes32 private constant IMPLEMENTATION_SLOT = 0x7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8c3; constructor(address _implementation) public { assert( IMPLEMENTATION_SLOT == keccak256("org.zeppelinos.proxy.implementation") ); _setImplementation(_implementation); } function _implementation() internal view returns (address impl) { bytes32 slot = IMPLEMENTATION_SLOT; assembly { impl := sload(slot) } } function _upgradeTo(address newImplementation) internal { _setImplementation(newImplementation); emit Upgraded(newImplementation); } function _setImplementation(address newImplementation) private { require( AddressUtils.isContract(newImplementation), "Cannot set a proxy implementation to a non-contract address" ); bytes32 slot = IMPLEMENTATION_SLOT; assembly { sstore(slot, newImplementation) } } } contract AdminUpgradeabilityProxy is UpgradeabilityProxy { event AdminChanged(address previousAdmin, address newAdmin); event AdminUpdated(address newAdmin); bytes32 private constant ADMIN_SLOT = 0x10d6a54a4754c8869d6886b5f5d7fbfa5b4522237ea5c60d11bc4e7a1ff9390b; bytes32 private constant PENDING_ADMIN_SLOT = 0x54ac2bd5363dfe95a011c5b5a153968d77d153d212e900afce8624fdad74525c; modifier ifAdmin() { if (msg.sender == _admin()) { _; } else { _fallback(); } } constructor(address _implementation) public UpgradeabilityProxy(_implementation) { assert(ADMIN_SLOT == keccak256("org.zeppelinos.proxy.admin")); _setAdmin(msg.sender); } function admin() external ifAdmin returns (address) { return _admin(); } function pendingAdmin() external ifAdmin returns (address) { return _pendingAdmin(); } function implementation() external ifAdmin returns (address) { return _implementation(); } function changeAdmin(address _newAdmin) external ifAdmin { require( _newAdmin != address(0), "Cannot change the admin of a proxy to the zero address" ); require( _newAdmin != _admin(), "The current and new admin cannot be the same ." ); require( _newAdmin != _pendingAdmin(), "Cannot set the newAdmin of a proxy to the same address ." ); _setPendingAdmin(_newAdmin); emit AdminChanged(_admin(), _newAdmin); } function updateAdmin() external { address _newAdmin = _pendingAdmin(); require( _newAdmin != address(0), "Cannot change the admin of a proxy to the zero address" ); require( msg.sender == _newAdmin, "msg.sender and newAdmin must be the same ." ); _setAdmin(_newAdmin); _setPendingAdmin(address(0)); emit AdminUpdated(_newAdmin); } function upgradeTo(address newImplementation) external ifAdmin { _upgradeTo(newImplementation); } function upgradeToAndCall(address newImplementation, bytes calldata data) external payable ifAdmin { _upgradeTo(newImplementation); (bool success, ) = address(this).call.value(msg.value)(data); require(success, "upgradeToAndCall-error"); } function _admin() internal view returns (address adm) { bytes32 slot = ADMIN_SLOT; assembly { adm := sload(slot) } } function _pendingAdmin() internal view returns (address pendingAdm) { bytes32 slot = PENDING_ADMIN_SLOT; assembly { pendingAdm := sload(slot) } } function _setAdmin(address newAdmin) internal { bytes32 slot = ADMIN_SLOT; assembly { sstore(slot, newAdmin) } } function _setPendingAdmin(address pendingAdm) internal { bytes32 slot = PENDING_ADMIN_SLOT; assembly { sstore(slot, pendingAdm) } } function _willFallback() internal { require( msg.sender != _admin(), "Cannot call fallback function from the proxy admin" ); super._willFallback(); } } contract USRProxy is AdminUpgradeabilityProxy { constructor(address _implementation) public AdminUpgradeabilityProxy(_implementation) {} // Allow anyone to view the implementation address function USRImplementation() external view returns (address) { return _implementation(); } }
File 2 of 11: USRProxy
pragma solidity 0.5.12; contract Proxy { function() external payable { _fallback(); } function _implementation() internal view returns (address); function _delegate(address implementation) internal { assembly { calldatacopy(0, 0, calldatasize) let result := delegatecall( gas, implementation, 0, calldatasize, 0, 0 ) returndatacopy(0, 0, returndatasize) switch result case 0 { revert(0, returndatasize) } default { return(0, returndatasize) } } } function _willFallback() internal {} function _fallback() internal { _willFallback(); _delegate(_implementation()); } } library AddressUtils { function isContract(address addr) internal view returns (bool) { uint256 size; assembly { size := extcodesize(addr) } return size > 0; } } contract UpgradeabilityProxy is Proxy { event Upgraded(address implementation); bytes32 private constant IMPLEMENTATION_SLOT = 0x7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8c3; constructor(address _implementation) public { assert( IMPLEMENTATION_SLOT == keccak256("org.zeppelinos.proxy.implementation") ); _setImplementation(_implementation); } function _implementation() internal view returns (address impl) { bytes32 slot = IMPLEMENTATION_SLOT; assembly { impl := sload(slot) } } function _upgradeTo(address newImplementation) internal { _setImplementation(newImplementation); emit Upgraded(newImplementation); } function _setImplementation(address newImplementation) private { require( AddressUtils.isContract(newImplementation), "Cannot set a proxy implementation to a non-contract address" ); bytes32 slot = IMPLEMENTATION_SLOT; assembly { sstore(slot, newImplementation) } } } contract AdminUpgradeabilityProxy is UpgradeabilityProxy { event AdminChanged(address previousAdmin, address newAdmin); event AdminUpdated(address newAdmin); bytes32 private constant ADMIN_SLOT = 0x10d6a54a4754c8869d6886b5f5d7fbfa5b4522237ea5c60d11bc4e7a1ff9390b; bytes32 private constant PENDING_ADMIN_SLOT = 0x54ac2bd5363dfe95a011c5b5a153968d77d153d212e900afce8624fdad74525c; modifier ifAdmin() { if (msg.sender == _admin()) { _; } else { _fallback(); } } constructor(address _implementation) public UpgradeabilityProxy(_implementation) { assert(ADMIN_SLOT == keccak256("org.zeppelinos.proxy.admin")); _setAdmin(msg.sender); } function admin() external ifAdmin returns (address) { return _admin(); } function pendingAdmin() external ifAdmin returns (address) { return _pendingAdmin(); } function implementation() external ifAdmin returns (address) { return _implementation(); } function changeAdmin(address _newAdmin) external ifAdmin { require( _newAdmin != address(0), "Cannot change the admin of a proxy to the zero address" ); require( _newAdmin != _admin(), "The current and new admin cannot be the same ." ); require( _newAdmin != _pendingAdmin(), "Cannot set the newAdmin of a proxy to the same address ." ); _setPendingAdmin(_newAdmin); emit AdminChanged(_admin(), _newAdmin); } function updateAdmin() external { address _newAdmin = _pendingAdmin(); require( _newAdmin != address(0), "Cannot change the admin of a proxy to the zero address" ); require( msg.sender == _newAdmin, "msg.sender and newAdmin must be the same ." ); _setAdmin(_newAdmin); _setPendingAdmin(address(0)); emit AdminUpdated(_newAdmin); } function upgradeTo(address newImplementation) external ifAdmin { _upgradeTo(newImplementation); } function upgradeToAndCall(address newImplementation, bytes calldata data) external payable ifAdmin { _upgradeTo(newImplementation); (bool success, ) = address(this).call.value(msg.value)(data); require(success, "upgradeToAndCall-error"); } function _admin() internal view returns (address adm) { bytes32 slot = ADMIN_SLOT; assembly { adm := sload(slot) } } function _pendingAdmin() internal view returns (address pendingAdm) { bytes32 slot = PENDING_ADMIN_SLOT; assembly { pendingAdm := sload(slot) } } function _setAdmin(address newAdmin) internal { bytes32 slot = ADMIN_SLOT; assembly { sstore(slot, newAdmin) } } function _setPendingAdmin(address pendingAdm) internal { bytes32 slot = PENDING_ADMIN_SLOT; assembly { sstore(slot, pendingAdm) } } function _willFallback() internal { require( msg.sender != _admin(), "Cannot call fallback function from the proxy admin" ); super._willFallback(); } } contract USRProxy is AdminUpgradeabilityProxy { constructor(address _implementation) public AdminUpgradeabilityProxy(_implementation) {} // Allow anyone to view the implementation address function USRImplementation() external view returns (address) { return _implementation(); } }
File 3 of 11: DFStore
pragma solidity ^0.5.2; contract IERC20Token { function balanceOf(address _owner) public view returns (uint); function allowance(address _owner, address _spender) public view returns (uint); function transfer(address _to, uint _value) public returns (bool success); function transferFrom(address _from, address _to, uint _value) public returns (bool success); function approve(address _spender, uint _value) public returns (bool success); function totalSupply() public view returns (uint); } contract IDSWrappedToken is IERC20Token { function mint(address _account, uint _value) public; function burn(address _account, uint _value) public; function wrap(address _dst, uint _amount) public returns (uint); function unwrap(address _dst, uint _amount) public returns (uint); function changeByMultiple(uint _amount) public view returns (uint); function reverseByMultiple(uint _xAmount) public view returns (uint); function getSrcERC20() public view returns (address); } contract DSMath { function add(uint x, uint y) internal pure returns (uint z) { require((z = x + y) >= x, "ds-math-add-overflow"); } function sub(uint x, uint y) internal pure returns (uint z) { require((z = x - y) <= x, "ds-math-sub-underflow"); } function mul(uint x, uint y) internal pure returns (uint z) { require(y == 0 || (z = x * y) / y == x, "ds-math-mul-overflow"); } function div(uint x, uint y) internal pure returns (uint z) { require(y > 0, "ds-math-div-overflow"); z = x / y; } function min(uint x, uint y) internal pure returns (uint z) { return x <= y ? x : y; } function max(uint x, uint y) internal pure returns (uint z) { return x >= y ? x : y; } uint constant WAD = 10 ** 18; function wdiv(uint x, uint y) internal pure returns (uint z) { z = add(mul(x, WAD), y / 2) / y; } /** * @dev x to the power of y power(base, exponent) */ function pow(uint256 base, uint256 exponent) public pure returns (uint256) { if (exponent == 0) { return 1; } else if (exponent == 1) { return base; } else if (base == 0 && exponent != 0) { return 0; } else { uint256 z = base; for (uint256 i = 1; i < exponent; i++) z = mul(z, base); return z; } } } contract DSAuthority { function canCall( address src, address dst, bytes4 sig ) public view returns (bool); } contract DSAuthEvents { event LogSetAuthority (address indexed authority); event LogSetOwner (address indexed owner); event OwnerUpdate (address indexed owner, address indexed newOwner); } contract DSAuth is DSAuthEvents { DSAuthority public authority; address public owner; address public newOwner; constructor() public { owner = msg.sender; emit LogSetOwner(msg.sender); } // Warning: you should absolutely sure you want to give up authority!!! function disableOwnership() public onlyOwner { owner = address(0); emit OwnerUpdate(msg.sender, owner); } function transferOwnership(address newOwner_) public onlyOwner { require(newOwner_ != owner, "TransferOwnership: the same owner."); newOwner = newOwner_; } function acceptOwnership() public { require(msg.sender == newOwner, "AcceptOwnership: only new owner do this."); emit OwnerUpdate(owner, newOwner); owner = newOwner; newOwner = address(0x0); } ///[snow] guard is Authority who inherit DSAuth. function setAuthority(DSAuthority authority_) public onlyOwner { authority = authority_; emit LogSetAuthority(address(authority)); } modifier onlyOwner { require(isOwner(msg.sender), "ds-auth-non-owner"); _; } function isOwner(address src) internal view returns (bool) { return bool(src == owner); } modifier auth { require(isAuthorized(msg.sender, msg.sig), "ds-auth-unauthorized"); _; } function isAuthorized(address src, bytes4 sig) internal view returns (bool) { if (src == address(this)) { return true; } else if (src == owner) { return true; } else if (authority == DSAuthority(0)) { return false; } else { return authority.canCall(src, address(this), sig); } } } contract DFStore is DSMath, DSAuth { // MEMBERS /// @dev cw - The Weight of collateral struct Section { uint minted; uint burned; uint backupIdx; address[] colIDs; uint[] cw; } Section[] public secList; mapping(address => address) public wrappedTokens; uint backupSeed = 1; mapping(uint => Section) public secListBackup; mapping(address => bool) public mintingTokens; mapping(address => bool) public mintedTokens; mapping(address => address) public tokenBackup; address[] public mintedTokenList; /// @dev The position of current secList uint private mintPosition; /// @dev The position of old secList uint private burnPosition; /// @dev The total amount of minted. uint private totalMinted; /// @dev The total amount of burned. uint private totalBurned; /// @dev The minimal amount of burned. uint private minimalBurnAmount = 10 ** 14; /// @dev The total amount of collateral. uint private totalCol; mapping(uint => uint) public FeeRate; mapping(uint => address) public FeeToken; mapping(address => address) public TokenMedian; mapping(address => uint) public poolBalance; mapping(address => uint) public resUSDXBalance; mapping(address => mapping (address => uint)) public depositorsBalance; event UpdateSection(address[] _wrappedTokens, uint[] _number); constructor(address[] memory _wrappedTokens, uint[] memory _weights) public { _setSection(_wrappedTokens, _weights); } function getSectionMinted(uint _position) public view returns (uint) { return secList[_position].minted; } function addSectionMinted(uint _amount) public auth { require(_amount > 0, "AddSectionMinted: amount not correct."); secList[mintPosition].minted = add(secList[mintPosition].minted, _amount); } function addSectionMinted(uint _position, uint _amount) public auth { require(_amount > 0, "AddSectionMinted: amount not correct."); secList[_position].minted = add(secList[_position].minted, _amount); } function setSectionMinted(uint _amount) public auth { secList[mintPosition].minted = _amount; } function setSectionMinted(uint _position, uint _amount) public auth { secList[_position].minted = _amount; } function getSectionBurned(uint _position) public view returns (uint) { return secList[_position].burned; } function addSectionBurned(uint _amount) public auth { require(_amount > 0, "AddSectionBurned: amount not correct."); secList[burnPosition].burned = add(secList[burnPosition].burned, _amount); } function addSectionBurned(uint _position, uint _amount) public auth { require(_amount > 0, "AddSectionBurned: amount not correct."); secList[_position].burned = add(secList[_position].burned, _amount); } function setSectionBurned(uint _amount) public auth { secList[burnPosition].burned = _amount; } function setSectionBurned(uint _position, uint _amount) public auth { secList[_position].burned = _amount; } function getSectionToken(uint _position) public view returns (address[] memory) { return secList[_position].colIDs; } function getSectionWeight(uint _position) public view returns (uint[] memory) { return secList[_position].cw; } function getSectionData(uint _position) public view returns (uint, uint, uint, address[] memory, uint[] memory) { return ( secList[_position].minted, secList[_position].burned, secList[_position].backupIdx, secList[_position].colIDs, secList[_position].cw ); } function getBackupSectionData(uint _position) public view returns (uint, address[] memory, uint[] memory) { uint _backupIdx = getBackupSectionIndex(_position); return (secListBackup[_backupIdx].backupIdx, secListBackup[_backupIdx].colIDs, secListBackup[_backupIdx].cw); } function getBackupSectionIndex(uint _position) public view returns (uint) { return secList[_position].backupIdx; } function setBackupSectionIndex(uint _position, uint _backupIdx) public auth { secList[_position].backupIdx = _backupIdx; } function _setSection(address[] memory _wrappedTokens, uint[] memory _weight) internal { require(_wrappedTokens.length == _weight.length, "_SetSection: data not allow."); uint sum; uint factor = 10 ** 10; address[] memory _srcTokens = new address[](_weight.length); for (uint i = 0; i < _wrappedTokens.length; i++) { require(_weight[i] != 0, "_SetSection: invalid weight"); require(_wrappedTokens[i] != address(0), "_SetSection: 0 address not allow."); _srcTokens[i] = IDSWrappedToken(_wrappedTokens[i]).getSrcERC20(); require(_srcTokens[i] != address(0), "_SetSection: invalid address"); sum = add(sum, _weight[i]); } secList.push(Section(0, 0, 0, new address[](_wrappedTokens.length), new uint[](_weight.length))); uint _mintPosition = secList.length - 1; if (_mintPosition > 0) { address[] memory _cruColIDs = getSectionToken(mintPosition); for (uint i = 0; i < _cruColIDs.length; i++) delete mintingTokens[_cruColIDs[i]]; } for (uint i = 0; i < _wrappedTokens.length; i++) { require(mul(div(mul(_weight[i], factor), sum), sum) == mul(_weight[i], factor), "_SetSection: invalid weight"); secList[_mintPosition].cw[i] = _weight[i]; secList[_mintPosition].colIDs[i] = _wrappedTokens[i]; mintingTokens[_wrappedTokens[i]] = true; wrappedTokens[_srcTokens[i]] = _wrappedTokens[i]; if (mintedTokens[_wrappedTokens[i]]) continue; mintedTokenList.push(_wrappedTokens[i]); mintedTokens[_wrappedTokens[i]] = true; } mintPosition = _mintPosition; emit UpdateSection(secList[mintPosition].colIDs, secList[mintPosition].cw); } function setSection(address[] memory _wrappedTokens, uint[] memory _weight) public auth { _setSection(_wrappedTokens, _weight); } function setBackupSection(uint _position, address[] memory _wrappedTokens, uint[] memory _weight) public auth { require(_wrappedTokens.length == _weight.length, "SetBackupSection: data not allow."); require(_position < mintPosition, "SetBackupSection: update mint section first."); uint _backupIdx = secList[_position].backupIdx; if (_backupIdx == 0){ _backupIdx = backupSeed; secList[_position].backupIdx = _backupIdx; backupSeed = add(_backupIdx, 1); } secListBackup[_backupIdx] = Section(0, 0, _position, new address[](_wrappedTokens.length), new uint[](_weight.length)); for (uint i = 0; i < _wrappedTokens.length; i++) { require(_wrappedTokens[i] != address(0), "SetBackupSection: token contract address invalid"); require(_weight[i] > 0, "SetBackupSection: weight must greater than 0"); secListBackup[_backupIdx].cw[i] = _weight[i]; secListBackup[_backupIdx].colIDs[i] = _wrappedTokens[i]; mintedTokens[_wrappedTokens[i]] = true; } } function burnSectionMoveon() public auth { require( secList[burnPosition].minted == secList[burnPosition].burned, "BurnSectionMoveon: burned not meet minted." ); burnPosition = add(burnPosition, 1); assert(burnPosition <= mintPosition); } function getMintingToken(address _token) public view returns (bool) { return mintingTokens[_token]; } function setMintingToken(address _token, bool _flag) public auth { mintingTokens[_token] = _flag; } function getMintedToken(address _token) public view returns (bool) { return mintedTokens[_token]; } function setMintedToken(address _token, bool _flag) public auth { mintedTokens[_token] = _flag; } function getBackupToken(address _token) public view returns (address) { return tokenBackup[_token]; } function setBackupToken(address _token, address _backupToken) public auth { tokenBackup[_token] = _backupToken; } function getMintedTokenList() public view returns (address[] memory) { return mintedTokenList; } function getMintPosition() public view returns (uint) { return mintPosition; } function getBurnPosition() public view returns (uint) { return burnPosition; } function getTotalMinted() public view returns (uint) { return totalMinted; } function addTotalMinted(uint _amount) public auth { require(_amount > 0, "AddTotalMinted: minted amount is zero."); totalMinted = add(totalMinted, _amount); } function setTotalMinted(uint _amount) public auth { totalMinted = _amount; } function getTotalBurned() public view returns (uint) { return totalBurned; } function addTotalBurned(uint _amount) public auth { require(_amount > 0, "AddTotalBurned: minted amount is zero."); totalBurned = add(totalBurned, _amount); } function setTotalBurned(uint _amount) public auth { totalBurned = _amount; } function getMinBurnAmount() public view returns (uint) { return minimalBurnAmount; } function setMinBurnAmount(uint _amount) public auth { _setMinBurnAmount(_amount); } function _setMinBurnAmount(uint _amount) internal { minimalBurnAmount = _amount; } function getTokenBalance(address _tokenID) public view returns (uint) { return poolBalance[_tokenID]; } function setTokenBalance(address _tokenID, uint _amount) public auth { poolBalance[_tokenID] = _amount; } function getResUSDXBalance(address _tokenID) public view returns (uint) { return resUSDXBalance[_tokenID]; } function setResUSDXBalance(address _tokenID, uint _amount) public auth { resUSDXBalance[_tokenID] = _amount; } function getDepositorBalance(address _depositor, address _tokenID) public view returns (uint) { return depositorsBalance[_depositor][_tokenID]; } function setDepositorBalance(address _depositor, address _tokenID, uint _amount) public auth { depositorsBalance[_depositor][_tokenID] = _amount; } function setFeeRate(uint ct, uint rate) public auth { FeeRate[ct] = rate; } function getFeeRate(uint ct) public view returns (uint) { return FeeRate[ct]; } function setTypeToken(uint tt, address _tokenID) public auth { FeeToken[tt] = _tokenID; } function getTypeToken(uint tt) public view returns (address) { return FeeToken[tt]; } function setTokenMedian(address _tokenID, address _median) public auth { TokenMedian[_tokenID] = _median; } function getTokenMedian(address _tokenID) public view returns (address) { return TokenMedian[_tokenID]; } function setTotalCol(uint _amount) public auth { totalCol = _amount; } function getTotalCol() public view returns (uint) { return totalCol; } function setWrappedToken(address _srcToken, address _wrappedToken) public auth { wrappedTokens[_srcToken] = _wrappedToken; } function getWrappedToken(address _srcToken) public view returns (address) { return wrappedTokens[_srcToken]; } }
File 4 of 11: DFProxy
pragma solidity 0.5.12; contract Proxy { function() external payable { _fallback(); } function _implementation() internal view returns (address); function _delegate(address implementation) internal { assembly { calldatacopy(0, 0, calldatasize) let result := delegatecall( gas, implementation, 0, calldatasize, 0, 0 ) returndatacopy(0, 0, returndatasize) switch result case 0 { revert(0, returndatasize) } default { return(0, returndatasize) } } } function _willFallback() internal {} function _fallback() internal { _willFallback(); _delegate(_implementation()); } } library AddressUtils { function isContract(address addr) internal view returns (bool) { uint256 size; assembly { size := extcodesize(addr) } return size > 0; } } contract UpgradeabilityProxy is Proxy { event Upgraded(address implementation); bytes32 private constant IMPLEMENTATION_SLOT = 0x7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8c3; constructor(address _implementation) public { assert( IMPLEMENTATION_SLOT == keccak256("org.zeppelinos.proxy.implementation") ); _setImplementation(_implementation); } function _implementation() internal view returns (address impl) { bytes32 slot = IMPLEMENTATION_SLOT; assembly { impl := sload(slot) } } function _upgradeTo(address newImplementation) internal { _setImplementation(newImplementation); emit Upgraded(newImplementation); } function _setImplementation(address newImplementation) private { require( AddressUtils.isContract(newImplementation), "Cannot set a proxy implementation to a non-contract address" ); bytes32 slot = IMPLEMENTATION_SLOT; assembly { sstore(slot, newImplementation) } } } contract AdminUpgradeabilityProxy is UpgradeabilityProxy { event AdminChanged(address previousAdmin, address newAdmin); event AdminUpdated(address newAdmin); bytes32 private constant ADMIN_SLOT = 0x10d6a54a4754c8869d6886b5f5d7fbfa5b4522237ea5c60d11bc4e7a1ff9390b; bytes32 private constant PENDING_ADMIN_SLOT = 0x54ac2bd5363dfe95a011c5b5a153968d77d153d212e900afce8624fdad74525c; modifier ifAdmin() { if (msg.sender == _admin()) { _; } else { _fallback(); } } constructor(address _implementation) public UpgradeabilityProxy(_implementation) { assert(ADMIN_SLOT == keccak256("org.zeppelinos.proxy.admin")); _setAdmin(msg.sender); } function admin() external ifAdmin returns (address) { return _admin(); } function pendingAdmin() external ifAdmin returns (address) { return _pendingAdmin(); } function implementation() external ifAdmin returns (address) { return _implementation(); } function changeAdmin(address _newAdmin) external ifAdmin { require( _newAdmin != address(0), "Cannot change the admin of a proxy to the zero address" ); require( _newAdmin != _admin(), "The current and new admin cannot be the same ." ); require( _newAdmin != _pendingAdmin(), "Cannot set the newAdmin of a proxy to the same address ." ); _setPendingAdmin(_newAdmin); emit AdminChanged(_admin(), _newAdmin); } function updateAdmin() external { address _newAdmin = _pendingAdmin(); require( _newAdmin != address(0), "Cannot change the admin of a proxy to the zero address" ); require( msg.sender == _newAdmin, "msg.sender and newAdmin must be the same ." ); _setAdmin(_newAdmin); _setPendingAdmin(address(0)); emit AdminUpdated(_newAdmin); } function upgradeTo(address newImplementation) external ifAdmin { _upgradeTo(newImplementation); } function upgradeToAndCall(address newImplementation, bytes calldata data) external payable ifAdmin { _upgradeTo(newImplementation); (bool success, ) = address(this).call.value(msg.value)(data); require(success, "upgradeToAndCall-error"); } function _admin() internal view returns (address adm) { bytes32 slot = ADMIN_SLOT; assembly { adm := sload(slot) } } function _pendingAdmin() internal view returns (address pendingAdm) { bytes32 slot = PENDING_ADMIN_SLOT; assembly { pendingAdm := sload(slot) } } function _setAdmin(address newAdmin) internal { bytes32 slot = ADMIN_SLOT; assembly { sstore(slot, newAdmin) } } function _setPendingAdmin(address pendingAdm) internal { bytes32 slot = PENDING_ADMIN_SLOT; assembly { sstore(slot, pendingAdm) } } function _willFallback() internal { require( msg.sender != _admin(), "Cannot call fallback function from the proxy admin" ); super._willFallback(); } } contract DFProxy is AdminUpgradeabilityProxy { constructor(address _implementation) public AdminUpgradeabilityProxy(_implementation) {} // Allow anyone to view the implementation address function DFImplementation() external view returns (address) { return _implementation(); } }
File 5 of 11: DSToken
pragma solidity ^0.4.13; ////// lib/ds-math/src/math.sol /// math.sol -- mixin for inline numerical wizardry // 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.4.13; */ contract DSMath { function add(uint x, uint y) internal pure returns (uint z) { require((z = x + y) >= x); } function sub(uint x, uint y) internal pure returns (uint z) { require((z = x - y) <= x); } function mul(uint x, uint y) internal pure returns (uint z) { require(y == 0 || (z = x * y) / y == x); } function min(uint x, uint y) internal pure returns (uint z) { return x <= y ? x : y; } function max(uint x, uint y) internal pure returns (uint z) { return x >= y ? x : y; } function imin(int x, int y) internal pure returns (int z) { return x <= y ? x : y; } function imax(int x, int y) internal pure returns (int z) { return x >= y ? x : y; } uint constant WAD = 10 ** 18; uint constant RAY = 10 ** 27; function wmul(uint x, uint y) internal pure returns (uint z) { z = add(mul(x, y), WAD / 2) / WAD; } function rmul(uint x, uint y) internal pure returns (uint z) { z = add(mul(x, y), RAY / 2) / RAY; } function wdiv(uint x, uint y) internal pure returns (uint z) { z = add(mul(x, WAD), y / 2) / y; } function rdiv(uint x, uint y) internal pure returns (uint z) { z = add(mul(x, RAY), y / 2) / y; } // This famous algorithm is called "exponentiation by squaring" // and calculates x^n with x as fixed-point and n as regular unsigned. // // It's O(log n), instead of O(n) for naive repeated multiplication. // // These facts are why it works: // // If n is even, then x^n = (x^2)^(n/2). // If n is odd, then x^n = x * x^(n-1), // and applying the equation for even x gives // x^n = x * (x^2)^((n-1) / 2). // // Also, EVM division is flooring and // floor[(n-1) / 2] = floor[n / 2]. // function rpow(uint x, uint n) internal pure returns (uint z) { z = n % 2 != 0 ? x : RAY; for (n /= 2; n != 0; n /= 2) { x = rmul(x, x); if (n % 2 != 0) { z = rmul(z, x); } } } } ////// lib/ds-stop/lib/ds-auth/src/auth.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.4.13; */ contract DSAuthority { function canCall( address src, address dst, bytes4 sig ) public view returns (bool); } contract DSAuthEvents { event LogSetAuthority (address indexed authority); event LogSetOwner (address indexed owner); } contract DSAuth is DSAuthEvents { DSAuthority public authority; address public owner; function DSAuth() public { owner = msg.sender; LogSetOwner(msg.sender); } function setOwner(address owner_) public auth { owner = owner_; LogSetOwner(owner); } function setAuthority(DSAuthority authority_) public auth { authority = authority_; LogSetAuthority(authority); } modifier auth { require(isAuthorized(msg.sender, msg.sig)); _; } function isAuthorized(address src, bytes4 sig) internal view returns (bool) { if (src == address(this)) { return true; } else if (src == owner) { return true; } else if (authority == DSAuthority(0)) { return false; } else { return authority.canCall(src, this, sig); } } } ////// lib/ds-stop/lib/ds-note/src/note.sol /// note.sol -- the `note' modifier, for logging calls as events // 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.4.13; */ contract DSNote { event LogNote( bytes4 indexed sig, address indexed guy, bytes32 indexed foo, bytes32 indexed bar, uint wad, bytes fax ) anonymous; modifier note { bytes32 foo; bytes32 bar; assembly { foo := calldataload(4) bar := calldataload(36) } LogNote(msg.sig, msg.sender, foo, bar, msg.value, msg.data); _; } } ////// lib/ds-stop/src/stop.sol /// stop.sol -- mixin for enable/disable functionality // Copyright (C) 2017 DappHub, LLC // 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.4.13; */ /* import "ds-auth/auth.sol"; */ /* import "ds-note/note.sol"; */ contract DSStop is DSNote, DSAuth { bool public stopped; modifier stoppable { require(!stopped); _; } function stop() public auth note { stopped = true; } function start() public auth note { stopped = false; } } ////// lib/erc20/src/erc20.sol /// erc20.sol -- API for the ERC20 token standard // See <https://github.com/ethereum/EIPs/issues/20>. // This file likely does not meet the threshold of originality // required for copyright to apply. As a result, this is free and // unencumbered software belonging to the public domain. /* pragma solidity ^0.4.8; */ contract ERC20Events { event Approval(address indexed src, address indexed guy, uint wad); event Transfer(address indexed src, address indexed dst, uint wad); } contract ERC20 is ERC20Events { function totalSupply() public view returns (uint); function balanceOf(address guy) public view returns (uint); function allowance(address src, address guy) public view returns (uint); function approve(address guy, uint wad) public returns (bool); function transfer(address dst, uint wad) public returns (bool); function transferFrom( address src, address dst, uint wad ) public returns (bool); } ////// src/base.sol /// base.sol -- basic ERC20 implementation // Copyright (C) 2015, 2016, 2017 DappHub, LLC // 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.4.13; */ /* import "erc20/erc20.sol"; */ /* import "ds-math/math.sol"; */ contract DSTokenBase is ERC20, DSMath { uint256 _supply; mapping (address => uint256) _balances; mapping (address => mapping (address => uint256)) _approvals; function DSTokenBase(uint supply) public { _balances[msg.sender] = supply; _supply = supply; } function totalSupply() public view returns (uint) { return _supply; } function balanceOf(address src) public view returns (uint) { return _balances[src]; } function allowance(address src, address guy) public view returns (uint) { return _approvals[src][guy]; } function transfer(address dst, uint wad) public returns (bool) { return transferFrom(msg.sender, dst, wad); } function transferFrom(address src, address dst, uint wad) public returns (bool) { if (src != msg.sender) { _approvals[src][msg.sender] = sub(_approvals[src][msg.sender], wad); } _balances[src] = sub(_balances[src], wad); _balances[dst] = add(_balances[dst], wad); Transfer(src, dst, wad); return true; } function approve(address guy, uint wad) public returns (bool) { _approvals[msg.sender][guy] = wad; Approval(msg.sender, guy, wad); return true; } } ////// src/token.sol /// token.sol -- ERC20 implementation with minting and burning // Copyright (C) 2015, 2016, 2017 DappHub, LLC // 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.4.13; */ /* import "ds-stop/stop.sol"; */ /* import "./base.sol"; */ contract DSToken is DSTokenBase(0), DSStop { bytes32 public symbol; uint256 public decimals = 18; // standard token precision. override to customize function DSToken(bytes32 symbol_) public { symbol = symbol_; } event Mint(address indexed guy, uint wad); event Burn(address indexed guy, uint wad); function approve(address guy) public stoppable returns (bool) { return super.approve(guy, uint(-1)); } function approve(address guy, uint wad) public stoppable returns (bool) { return super.approve(guy, wad); } function transferFrom(address src, address dst, uint wad) public stoppable returns (bool) { if (src != msg.sender && _approvals[src][msg.sender] != uint(-1)) { _approvals[src][msg.sender] = sub(_approvals[src][msg.sender], wad); } _balances[src] = sub(_balances[src], wad); _balances[dst] = add(_balances[dst], wad); Transfer(src, dst, wad); return true; } function push(address dst, uint wad) public { transferFrom(msg.sender, dst, wad); } function pull(address src, uint wad) public { transferFrom(src, msg.sender, wad); } function move(address src, address dst, uint wad) public { transferFrom(src, dst, wad); } function mint(uint wad) public { mint(msg.sender, wad); } function burn(uint wad) public { burn(msg.sender, wad); } function mint(address guy, uint wad) public auth stoppable { _balances[guy] = add(_balances[guy], wad); _supply = add(_supply, wad); Mint(guy, wad); } function burn(address guy, uint wad) public auth stoppable { if (guy != msg.sender && _approvals[guy][msg.sender] != uint(-1)) { _approvals[guy][msg.sender] = sub(_approvals[guy][msg.sender], wad); } _balances[guy] = sub(_balances[guy], wad); _supply = sub(_supply, wad); Burn(guy, wad); } // Optional token name bytes32 public name = ""; function setName(bytes32 name_) public auth { name = name_; } }
File 6 of 11: AdminUpgradeabilityProxy
pragma solidity ^0.4.24; // File: contracts/zeppelin/Proxy.sol /** * @title Proxy * @dev Implements delegation of calls to other contracts, with proper * forwarding of return values and bubbling of failures. * It defines a fallback function that delegates all calls to the address * returned by the abstract _implementation() internal function. */ contract Proxy { /** * @dev Fallback function. * Implemented entirely in `_fallback`. */ function () payable external { _fallback(); } /** * @return The Address of the implementation. */ function _implementation() internal view returns (address); /** * @dev Delegates execution to an implementation contract. * This is a low level function that doesn't return to its internal call site. * It will return to the external caller whatever the implementation returns. * @param implementation Address to delegate. */ function _delegate(address implementation) internal { assembly { // Copy msg.data. We take full control of memory in this inline assembly // block because it will not return to Solidity code. We overwrite the // Solidity scratch pad at memory position 0. calldatacopy(0, 0, calldatasize) // Call the implementation. // out and outsize are 0 because we don't know the size yet. let result := delegatecall(gas, implementation, 0, calldatasize, 0, 0) // Copy the returned data. returndatacopy(0, 0, returndatasize) switch result // delegatecall returns 0 on error. case 0 { revert(0, returndatasize) } default { return(0, returndatasize) } } } /** * @dev Function that is run as the first thing in the fallback function. * Can be redefined in derived contracts to add functionality. * Redefinitions must call super._willFallback(). */ function _willFallback() internal { } /** * @dev fallback implementation. * Extracted to enable manual triggering. */ function _fallback() internal { _willFallback(); _delegate(_implementation()); } } // File: contracts/zeppelin/AddressUtils.sol /** * Utility library of inline functions on addresses */ library AddressUtils { /** * Returns whether the target address is a contract * @dev This function will return false if invoked during the constructor of a contract, * as the code is not actually created until after the constructor finishes. * @param addr address to check * @return whether the target address is a contract */ function isContract(address addr) internal view returns (bool) { uint256 size; // XXX Currently there is no better way to check if there is a contract in an address // than to check the size of the code at that address. // See https://ethereum.stackexchange.com/a/14016/36603 // for more details about how this works. // TODO Check this again before the Serenity release, because all addresses will be // contracts then. // solium-disable-next-line security/no-inline-assembly assembly { size := extcodesize(addr) } return size > 0; } } // File: contracts/zeppelin/UpgradeabilityProxy.sol /** * @title UpgradeabilityProxy * @dev This contract implements a proxy that allows to change the * implementation address to which it will delegate. * Such a change is called an implementation upgrade. */ contract UpgradeabilityProxy is Proxy { /** * @dev Emitted when the implementation is upgraded. * @param implementation Address of the new implementation. */ event Upgraded(address implementation); /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "org.zeppelinos.proxy.implementation", and is * validated in the constructor. */ bytes32 private constant IMPLEMENTATION_SLOT = 0x7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8c3; /** * @dev Contract constructor. * @param _implementation Address of the initial implementation. */ constructor(address _implementation) public { assert(IMPLEMENTATION_SLOT == keccak256("org.zeppelinos.proxy.implementation")); _setImplementation(_implementation); } /** * @dev Returns the current implementation. * @return Address of the current implementation */ function _implementation() internal view returns (address impl) { bytes32 slot = IMPLEMENTATION_SLOT; assembly { impl := sload(slot) } } /** * @dev Upgrades the proxy to a new implementation. * @param newImplementation Address of the new implementation. */ function _upgradeTo(address newImplementation) internal { _setImplementation(newImplementation); emit Upgraded(newImplementation); } /** * @dev Sets the implementation address of the proxy. * @param newImplementation Address of the new implementation. */ function _setImplementation(address newImplementation) private { require(AddressUtils.isContract(newImplementation), "Cannot set a proxy implementation to a non-contract address"); bytes32 slot = IMPLEMENTATION_SLOT; assembly { sstore(slot, newImplementation) } } } // File: contracts/zeppelin/AdminUpgradeabilityProxy.sol /** * @title AdminUpgradeabilityProxy * @dev This contract combines an upgradeability proxy with an authorization * mechanism for administrative tasks. * All external functions in this contract must be guarded by the * `ifAdmin` modifier. See ethereum/solidity#3864 for a Solidity * feature proposal that would enable this to be done automatically. */ contract AdminUpgradeabilityProxy is UpgradeabilityProxy { /** * @dev Emitted when the administration has been transferred. * @param previousAdmin Address of the previous admin. * @param newAdmin Address of the new admin. */ event AdminChanged(address previousAdmin, address newAdmin); /** * @dev Storage slot with the admin of the contract. * This is the keccak-256 hash of "org.zeppelinos.proxy.admin", and is * validated in the constructor. */ bytes32 private constant ADMIN_SLOT = 0x10d6a54a4754c8869d6886b5f5d7fbfa5b4522237ea5c60d11bc4e7a1ff9390b; /** * @dev Modifier to check whether the `msg.sender` is the admin. * If it is, it will run the function. Otherwise, it will delegate the call * to the implementation. */ modifier ifAdmin() { if (msg.sender == _admin()) { _; } else { _fallback(); } } /** * Contract constructor. * It sets the `msg.sender` as the proxy administrator. * @param _implementation address of the initial implementation. */ constructor(address _implementation) UpgradeabilityProxy(_implementation) public { assert(ADMIN_SLOT == keccak256("org.zeppelinos.proxy.admin")); _setAdmin(msg.sender); } /** * @return The address of the proxy admin. */ function admin() external view ifAdmin returns (address) { return _admin(); } /** * @return The address of the implementation. */ function implementation() external view ifAdmin returns (address) { return _implementation(); } /** * @dev Changes the admin of the proxy. * Only the current admin can call this function. * @param newAdmin Address to transfer proxy administration to. */ function changeAdmin(address newAdmin) external ifAdmin { require(newAdmin != address(0), "Cannot change the admin of a proxy to the zero address"); emit AdminChanged(_admin(), newAdmin); _setAdmin(newAdmin); } /** * @dev Upgrade the backing implementation of the proxy. * Only the admin can call this function. * @param newImplementation Address of the new implementation. */ function upgradeTo(address newImplementation) external ifAdmin { _upgradeTo(newImplementation); } /** * @dev Upgrade the backing implementation of the proxy and call a function * on the new implementation. * This is useful to initialize the proxied contract. * @param newImplementation Address of the new implementation. * @param data Data to send as msg.data in the low level call. * It should include the signature and the parameters of the function to be * called, as described in * https://solidity.readthedocs.io/en/develop/abi-spec.html#function-selector-and-argument-encoding. */ function upgradeToAndCall(address newImplementation, bytes data) payable external ifAdmin { _upgradeTo(newImplementation); require(address(this).call.value(msg.value)(data)); } /** * @return The admin slot. */ function _admin() internal view returns (address adm) { bytes32 slot = ADMIN_SLOT; assembly { adm := sload(slot) } } /** * @dev Sets the address of the proxy admin. * @param newAdmin Address of the new proxy admin. */ function _setAdmin(address newAdmin) internal { bytes32 slot = ADMIN_SLOT; assembly { sstore(slot, newAdmin) } } /** * @dev Only fall back when the sender is not the admin. */ function _willFallback() internal { require(msg.sender != _admin(), "Cannot call fallback function from the proxy admin"); super._willFallback(); } }
File 7 of 11: OwnedUpgradeabilityProxy
pragma solidity ^0.4.23; // This is the proxy contract for the TrustToken Registry // File: contracts/Proxy/Proxy.sol /** * @title Proxy * @dev Gives the possibility to delegate any call to a foreign implementation. */ contract Proxy { /** * @dev Tells the address of the implementation where every call will be delegated. * @return address of the implementation to which it will be delegated */ function implementation() public view returns (address); /** * @dev Fallback function allowing to perform a delegatecall to the given implementation. * This function will return whatever the implementation call returns */ function() external payable { address _impl = implementation(); require(_impl != address(0), "implementation contract not set"); assembly { let ptr := mload(0x40) calldatacopy(ptr, 0, calldatasize) let result := delegatecall(gas, _impl, ptr, calldatasize, 0, 0) let size := returndatasize returndatacopy(ptr, 0, size) switch result case 0 { revert(ptr, size) } default { return(ptr, size) } } } } // File: contracts/Proxy/UpgradeabilityProxy.sol /** * @title UpgradeabilityProxy * @dev This contract represents a proxy where the implementation address to which it will delegate can be upgraded */ contract UpgradeabilityProxy is Proxy { /** * @dev This event will be emitted every time the implementation gets upgraded * @param implementation representing the address of the upgraded implementation */ event Upgraded(address indexed implementation); // Storage position of the address of the current implementation bytes32 private constant implementationPosition = keccak256("trueUSD.proxy.implementation"); /** * @dev Tells the address of the current implementation * @return address of the current implementation */ function implementation() public view returns (address impl) { bytes32 position = implementationPosition; assembly { impl := sload(position) } } /** * @dev Sets the address of the current implementation * @param newImplementation address representing the new implementation to be set */ function _setImplementation(address newImplementation) internal { bytes32 position = implementationPosition; assembly { sstore(position, newImplementation) } } /** * @dev Upgrades the implementation address * @param newImplementation representing the address of the new implementation to be set */ function _upgradeTo(address newImplementation) internal { address currentImplementation = implementation(); require(currentImplementation != newImplementation); _setImplementation(newImplementation); emit Upgraded(newImplementation); } } // File: contracts/Proxy/OwnedUpgradeabilityProxy.sol /** * @title OwnedUpgradeabilityProxy * @dev This contract combines an upgradeability proxy with basic authorization control functionalities */ contract OwnedUpgradeabilityProxy is UpgradeabilityProxy { /** * @dev Event to show ownership has been transferred * @param previousOwner representing the address of the previous owner * @param newOwner representing the address of the new owner */ event ProxyOwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Event to show ownership transfer is pending * @param currentOwner representing the address of the current owner * @param pendingOwner representing the address of the pending owner */ event NewPendingOwner(address currentOwner, address pendingOwner); // Storage position of the owner and pendingOwner of the contract bytes32 private constant proxyOwnerPosition = keccak256("trueUSD.proxy.owner"); bytes32 private constant pendingProxyOwnerPosition = keccak256("trueUSD.pending.proxy.owner"); /** * @dev the constructor sets the original owner of the contract to the sender account. */ constructor() public { _setUpgradeabilityOwner(msg.sender); } /** * @dev Throws if called by any account other than the owner. */ modifier onlyProxyOwner() { require(msg.sender == proxyOwner(), "only Proxy Owner"); _; } /** * @dev Throws if called by any account other than the pending owner. */ modifier onlyPendingProxyOwner() { require(msg.sender == pendingProxyOwner(), "only pending Proxy Owner"); _; } /** * @dev Tells the address of the owner * @return the address of the owner */ function proxyOwner() public view returns (address owner) { bytes32 position = proxyOwnerPosition; assembly { owner := sload(position) } } /** * @dev Tells the address of the owner * @return the address of the owner */ function pendingProxyOwner() public view returns (address pendingOwner) { bytes32 position = pendingProxyOwnerPosition; assembly { pendingOwner := sload(position) } } /** * @dev Sets the address of the owner */ function _setUpgradeabilityOwner(address newProxyOwner) internal { bytes32 position = proxyOwnerPosition; assembly { sstore(position, newProxyOwner) } } /** * @dev Sets the address of the owner */ function _setPendingUpgradeabilityOwner(address newPendingProxyOwner) internal { bytes32 position = pendingProxyOwnerPosition; assembly { sstore(position, newPendingProxyOwner) } } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. *changes the pending owner to newOwner. But doesn't actually transfer * @param newOwner The address to transfer ownership to. */ function transferProxyOwnership(address newOwner) external onlyProxyOwner { require(newOwner != address(0)); _setPendingUpgradeabilityOwner(newOwner); emit NewPendingOwner(proxyOwner(), newOwner); } /** * @dev Allows the pendingOwner to claim ownership of the proxy */ function claimProxyOwnership() external onlyPendingProxyOwner { emit ProxyOwnershipTransferred(proxyOwner(), pendingProxyOwner()); _setUpgradeabilityOwner(pendingProxyOwner()); _setPendingUpgradeabilityOwner(address(0)); } /** * @dev Allows the proxy owner to upgrade the current version of the proxy. * @param implementation representing the address of the new implementation to be set. */ function upgradeTo(address implementation) external onlyProxyOwner { _upgradeTo(implementation); } }
File 8 of 11: FiatTokenProxy
pragma solidity ^0.4.24; // File: zos-lib/contracts/upgradeability/Proxy.sol /** * @title Proxy * @dev Implements delegation of calls to other contracts, with proper * forwarding of return values and bubbling of failures. * It defines a fallback function that delegates all calls to the address * returned by the abstract _implementation() internal function. */ contract Proxy { /** * @dev Fallback function. * Implemented entirely in `_fallback`. */ function () payable external { _fallback(); } /** * @return The Address of the implementation. */ function _implementation() internal view returns (address); /** * @dev Delegates execution to an implementation contract. * This is a low level function that doesn't return to its internal call site. * It will return to the external caller whatever the implementation returns. * @param implementation Address to delegate. */ function _delegate(address implementation) internal { assembly { // Copy msg.data. We take full control of memory in this inline assembly // block because it will not return to Solidity code. We overwrite the // Solidity scratch pad at memory position 0. calldatacopy(0, 0, calldatasize) // Call the implementation. // out and outsize are 0 because we don't know the size yet. let result := delegatecall(gas, implementation, 0, calldatasize, 0, 0) // Copy the returned data. returndatacopy(0, 0, returndatasize) switch result // delegatecall returns 0 on error. case 0 { revert(0, returndatasize) } default { return(0, returndatasize) } } } /** * @dev Function that is run as the first thing in the fallback function. * Can be redefined in derived contracts to add functionality. * Redefinitions must call super._willFallback(). */ function _willFallback() internal { } /** * @dev fallback implementation. * Extracted to enable manual triggering. */ function _fallback() internal { _willFallback(); _delegate(_implementation()); } } // File: openzeppelin-solidity/contracts/AddressUtils.sol /** * Utility library of inline functions on addresses */ library AddressUtils { /** * Returns whether the target address is a contract * @dev This function will return false if invoked during the constructor of a contract, * as the code is not actually created until after the constructor finishes. * @param addr address to check * @return whether the target address is a contract */ function isContract(address addr) internal view returns (bool) { uint256 size; // XXX Currently there is no better way to check if there is a contract in an address // than to check the size of the code at that address. // See https://ethereum.stackexchange.com/a/14016/36603 // for more details about how this works. // TODO Check this again before the Serenity release, because all addresses will be // contracts then. // solium-disable-next-line security/no-inline-assembly assembly { size := extcodesize(addr) } return size > 0; } } // File: zos-lib/contracts/upgradeability/UpgradeabilityProxy.sol /** * @title UpgradeabilityProxy * @dev This contract implements a proxy that allows to change the * implementation address to which it will delegate. * Such a change is called an implementation upgrade. */ contract UpgradeabilityProxy is Proxy { /** * @dev Emitted when the implementation is upgraded. * @param implementation Address of the new implementation. */ event Upgraded(address implementation); /** * @dev Storage slot with the address of the current implementation. * This is the keccak-256 hash of "org.zeppelinos.proxy.implementation", and is * validated in the constructor. */ bytes32 private constant IMPLEMENTATION_SLOT = 0x7050c9e0f4ca769c69bd3a8ef740bc37934f8e2c036e5a723fd8ee048ed3f8c3; /** * @dev Contract constructor. * @param _implementation Address of the initial implementation. */ constructor(address _implementation) public { assert(IMPLEMENTATION_SLOT == keccak256("org.zeppelinos.proxy.implementation")); _setImplementation(_implementation); } /** * @dev Returns the current implementation. * @return Address of the current implementation */ function _implementation() internal view returns (address impl) { bytes32 slot = IMPLEMENTATION_SLOT; assembly { impl := sload(slot) } } /** * @dev Upgrades the proxy to a new implementation. * @param newImplementation Address of the new implementation. */ function _upgradeTo(address newImplementation) internal { _setImplementation(newImplementation); emit Upgraded(newImplementation); } /** * @dev Sets the implementation address of the proxy. * @param newImplementation Address of the new implementation. */ function _setImplementation(address newImplementation) private { require(AddressUtils.isContract(newImplementation), "Cannot set a proxy implementation to a non-contract address"); bytes32 slot = IMPLEMENTATION_SLOT; assembly { sstore(slot, newImplementation) } } } // File: zos-lib/contracts/upgradeability/AdminUpgradeabilityProxy.sol /** * @title AdminUpgradeabilityProxy * @dev This contract combines an upgradeability proxy with an authorization * mechanism for administrative tasks. * All external functions in this contract must be guarded by the * `ifAdmin` modifier. See ethereum/solidity#3864 for a Solidity * feature proposal that would enable this to be done automatically. */ contract AdminUpgradeabilityProxy is UpgradeabilityProxy { /** * @dev Emitted when the administration has been transferred. * @param previousAdmin Address of the previous admin. * @param newAdmin Address of the new admin. */ event AdminChanged(address previousAdmin, address newAdmin); /** * @dev Storage slot with the admin of the contract. * This is the keccak-256 hash of "org.zeppelinos.proxy.admin", and is * validated in the constructor. */ bytes32 private constant ADMIN_SLOT = 0x10d6a54a4754c8869d6886b5f5d7fbfa5b4522237ea5c60d11bc4e7a1ff9390b; /** * @dev Modifier to check whether the `msg.sender` is the admin. * If it is, it will run the function. Otherwise, it will delegate the call * to the implementation. */ modifier ifAdmin() { if (msg.sender == _admin()) { _; } else { _fallback(); } } /** * Contract constructor. * It sets the `msg.sender` as the proxy administrator. * @param _implementation address of the initial implementation. */ constructor(address _implementation) UpgradeabilityProxy(_implementation) public { assert(ADMIN_SLOT == keccak256("org.zeppelinos.proxy.admin")); _setAdmin(msg.sender); } /** * @return The address of the proxy admin. */ function admin() external view ifAdmin returns (address) { return _admin(); } /** * @return The address of the implementation. */ function implementation() external view ifAdmin returns (address) { return _implementation(); } /** * @dev Changes the admin of the proxy. * Only the current admin can call this function. * @param newAdmin Address to transfer proxy administration to. */ function changeAdmin(address newAdmin) external ifAdmin { require(newAdmin != address(0), "Cannot change the admin of a proxy to the zero address"); emit AdminChanged(_admin(), newAdmin); _setAdmin(newAdmin); } /** * @dev Upgrade the backing implementation of the proxy. * Only the admin can call this function. * @param newImplementation Address of the new implementation. */ function upgradeTo(address newImplementation) external ifAdmin { _upgradeTo(newImplementation); } /** * @dev Upgrade the backing implementation of the proxy and call a function * on the new implementation. * This is useful to initialize the proxied contract. * @param newImplementation Address of the new implementation. * @param data Data to send as msg.data in the low level call. * It should include the signature and the parameters of the function to be * called, as described in * https://solidity.readthedocs.io/en/develop/abi-spec.html#function-selector-and-argument-encoding. */ function upgradeToAndCall(address newImplementation, bytes data) payable external ifAdmin { _upgradeTo(newImplementation); require(address(this).call.value(msg.value)(data)); } /** * @return The admin slot. */ function _admin() internal view returns (address adm) { bytes32 slot = ADMIN_SLOT; assembly { adm := sload(slot) } } /** * @dev Sets the address of the proxy admin. * @param newAdmin Address of the new proxy admin. */ function _setAdmin(address newAdmin) internal { bytes32 slot = ADMIN_SLOT; assembly { sstore(slot, newAdmin) } } /** * @dev Only fall back when the sender is not the admin. */ function _willFallback() internal { require(msg.sender != _admin(), "Cannot call fallback function from the proxy admin"); super._willFallback(); } } // File: contracts/FiatTokenProxy.sol /** * Copyright CENTRE SECZ 2018 * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is furnished to * do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ pragma solidity ^0.4.24; /** * @title FiatTokenProxy * @dev This contract proxies FiatToken calls and enables FiatToken upgrades */ contract FiatTokenProxy is AdminUpgradeabilityProxy { constructor(address _implementation) public AdminUpgradeabilityProxy(_implementation) { } }
File 9 of 11: DSToken
pragma solidity ^0.5.2; contract DSMath { function add(uint x, uint y) internal pure returns (uint z) { require((z = x + y) >= x, "ds-math-add-overflow"); } function sub(uint x, uint y) internal pure returns (uint z) { require((z = x - y) <= x, "ds-math-sub-underflow"); } function mul(uint x, uint y) internal pure returns (uint z) { require(y == 0 || (z = x * y) / y == x, "ds-math-mul-overflow"); } function div(uint x, uint y) internal pure returns (uint z) { require(y > 0, "ds-math-div-overflow"); z = x / y; } function min(uint x, uint y) internal pure returns (uint z) { return x <= y ? x : y; } function max(uint x, uint y) internal pure returns (uint z) { return x >= y ? x : y; } // function imin(int x, int y) internal pure returns (int z) { // return x <= y ? x : y; // } // function imax(int x, int y) internal pure returns (int z) { // return x >= y ? x : y; // } uint constant WAD = 10 ** 18; // uint constant RAY = 10 ** 27; // function wmul(uint x, uint y) internal pure returns (uint z) { // z = add(mul(x, y), WAD / 2) / WAD; // } // function rmul(uint x, uint y) internal pure returns (uint z) { // z = add(mul(x, y), RAY / 2) / RAY; // } function wdiv(uint x, uint y) internal pure returns (uint z) { z = add(mul(x, WAD), y / 2) / y; } // function rdiv(uint x, uint y) internal pure returns (uint z) { // z = add(mul(x, RAY), y / 2) / y; // } // This famous algorithm is called "exponentiation by squaring" // and calculates x^n with x as fixed-point and n as regular unsigned. // // It's O(log n), instead of O(n) for naive repeated multiplication. // // These facts are why it works: // // If n is even, then x^n = (x^2)^(n/2). // If n is odd, then x^n = x * x^(n-1), // and applying the equation for even x gives // x^n = x * (x^2)^((n-1) / 2). // // Also, EVM division is flooring and // floor[(n-1) / 2] = floor[n / 2]. // // function rpow(uint _x, uint n) internal pure returns (uint z) { // uint x = _x; // z = n % 2 != 0 ? x : RAY; // for (n /= 2; n != 0; n /= 2) { // x = rmul(x, x); // if (n % 2 != 0) { // z = rmul(z, x); // } // } // } /** * @dev x to the power of y power(base, exponent) */ function pow(uint256 base, uint256 exponent) public pure returns (uint256) { if (exponent == 0) { return 1; } else if (exponent == 1) { return base; } else if (base == 0 && exponent != 0) { return 0; } else { uint256 z = base; for (uint256 i = 1; i < exponent; i++) z = mul(z, base); return z; } } } contract DSAuthEvents { event LogSetAuthority (address indexed authority); event LogSetOwner (address indexed owner); } contract DSAuth is DSAuthEvents { address public authority; address public owner; constructor() public { owner = msg.sender; emit LogSetOwner(msg.sender); } function setOwner(address owner_) public onlyOwner { require(owner_ != address(0), "invalid owner address"); owner = owner_; emit LogSetOwner(owner); } function setAuthority(address authority_) public onlyOwner { authority = authority_; emit LogSetAuthority(address(authority)); } modifier auth { require(isAuthorized(msg.sender), "ds-auth-unauthorized"); _; } modifier onlyOwner { require(isOwner(msg.sender), "ds-auth-non-owner"); _; } function isOwner(address src) public view returns (bool) { return bool(src == owner); } function isAuthorized(address src) internal view returns (bool) { if (src == address(this)) { return true; } else if (src == owner) { return true; } else if (authority == address(0)) { return false; } else if (src == authority) { return true; } else { return false; } } } contract DSNote { event LogNote( bytes4 indexed sig, address indexed guy, bytes32 indexed foo, bytes32 indexed bar, uint256 wad, bytes fax ) anonymous; modifier note { bytes32 foo; bytes32 bar; uint256 wad; assembly { foo := calldataload(4) bar := calldataload(36) wad := callvalue } emit LogNote(msg.sig, msg.sender, foo, bar, wad, msg.data); _; } } contract DSStop is DSNote, DSAuth, DSMath { bool public stopped; modifier stoppable { require(!stopped, "ds-stop-is-stopped"); _; } function stop() public onlyOwner note { stopped = true; } function start() public onlyOwner note { stopped = false; } } contract ERC20Events { event Approval(address indexed src, address indexed guy, uint wad); event Transfer(address indexed src, address indexed dst, uint wad); } contract ERC20 is ERC20Events { function totalSupply() public view returns (uint); function balanceOf(address guy) public view returns (uint); function allowance(address src, address guy) public view returns (uint); function approve(address guy, uint wad) public returns (bool); function transfer(address dst, uint wad) public returns (bool); function transferFrom(address src, address dst, uint wad) public returns (bool); } contract DSTokenBase is ERC20, DSMath { uint256 _supply; mapping (address => uint256) _balances; mapping (address => mapping (address => uint256)) _approvals; constructor(uint supply) public { _supply = supply; } function totalSupply() public view returns (uint) { return _supply; } function balanceOf(address src) public view returns (uint) { return _balances[src]; } function allowance(address src, address guy) public view returns (uint) { return _approvals[src][guy]; } function transfer(address dst, uint wad) public returns (bool) { return transferFrom(msg.sender, dst, wad); } function transferFrom(address src, address dst, uint wad) public returns (bool) { if (src != msg.sender) { require(_approvals[src][msg.sender] >= wad, "ds-token-insufficient-approval"); _approvals[src][msg.sender] = sub(_approvals[src][msg.sender], wad); } require(_balances[src] >= wad, "ds-token-insufficient-balance"); _balances[src] = sub(_balances[src], wad); _balances[dst] = add(_balances[dst], wad); emit Transfer(src, dst, wad); return true; } function approve(address guy, uint wad) public returns (bool) { _approvals[msg.sender][guy] = wad; emit Approval(msg.sender, guy, wad); return true; } } contract DSToken is DSTokenBase(0), DSStop { bytes32 public name = ""; bytes32 public symbol; uint256 public decimals = 18; constructor(bytes32 symbol_) public { symbol = symbol_; } function setName(bytes32 name_) public onlyOwner { name = name_; } function approvex(address guy) public stoppable returns (bool) { return super.approve(guy, uint(-1)); } function approve(address guy, uint wad) public stoppable returns (bool) { require(_approvals[msg.sender][guy] == 0 || wad == 0); //take care of re-approve. return super.approve(guy, wad); } function transferFrom(address src, address dst, uint wad) public stoppable returns (bool) { if (src != msg.sender && _approvals[src][msg.sender] != uint(-1)) { require(_approvals[src][msg.sender] >= wad, "ds-token-insufficient-approval"); _approvals[src][msg.sender] = sub(_approvals[src][msg.sender], wad); } require(_balances[src] >= wad, "ds-token-insufficient-balance"); _balances[src] = sub(_balances[src], wad); _balances[dst] = add(_balances[dst], wad); emit Transfer(src, dst, wad); return true; } function mint(address guy, uint wad) public auth stoppable { _mint(guy, wad); } function burn(address guy, uint wad) public auth stoppable { _burn(guy, wad); } function _mint(address guy, uint wad) internal { require(guy != address(0), "ds-token-mint: mint to the zero address"); _balances[guy] = add(_balances[guy], wad); _supply = add(_supply, wad); emit Transfer(address(0), guy, wad); } function _burn(address guy, uint wad) internal { require(guy != address(0), "ds-token-burn: burn from the zero address"); require(_balances[guy] >= wad, "ds-token-insufficient-balance"); if (guy != msg.sender && _approvals[guy][msg.sender] != uint(-1)) { require(_approvals[guy][msg.sender] >= wad, "ds-token-insufficient-approval"); _approvals[guy][msg.sender] = sub(_approvals[guy][msg.sender], wad); } _balances[guy] = sub(_balances[guy], wad); _supply = sub(_supply, wad); emit Transfer(guy, address(0), wad); } }
File 10 of 11: DSGuard
pragma solidity ^0.5.2; contract DSAuthority { function canCall( address src, address dst, bytes4 sig ) public view returns (bool); } contract DSAuthEvents { event LogSetAuthority (address indexed authority); event LogSetOwner (address indexed owner); event OwnerUpdate (address indexed owner, address indexed newOwner); } contract DSAuth is DSAuthEvents { DSAuthority public authority; address public owner; address public newOwner; constructor() public { owner = msg.sender; emit LogSetOwner(msg.sender); } // Warning: you should absolutely sure you want to give up authority!!! function disableOwnership() public onlyOwner { owner = address(0); emit OwnerUpdate(msg.sender, owner); } function transferOwnership(address newOwner_) public onlyOwner { require(newOwner_ != owner, "TransferOwnership: the same owner."); newOwner = newOwner_; } function acceptOwnership() public { require(msg.sender == newOwner, "AcceptOwnership: only new owner do this."); emit OwnerUpdate(owner, newOwner); owner = newOwner; newOwner = address(0x0); } ///[snow] guard is Authority who inherit DSAuth. function setAuthority(DSAuthority authority_) public onlyOwner { authority = authority_; emit LogSetAuthority(address(authority)); } modifier onlyOwner { require(isOwner(msg.sender), "ds-auth-non-owner"); _; } function isOwner(address src) internal view returns (bool) { return bool(src == owner); } modifier auth { require(isAuthorized(msg.sender, msg.sig), "ds-auth-unauthorized"); _; } function isAuthorized(address src, bytes4 sig) internal view returns (bool) { if (src == address(this)) { return true; } else if (src == owner) { return true; } else if (authority == DSAuthority(0)) { return false; } else { return authority.canCall(src, address(this), sig); } } } contract DSGuardEvents { event LogPermit( bytes32 indexed src, bytes32 indexed dst, bytes32 indexed sig ); event LogForbid( bytes32 indexed src, bytes32 indexed dst, bytes32 indexed sig ); } contract DSGuard is DSAuth, DSAuthority, DSGuardEvents { bytes32 constant public ANY = bytes32(uint(-1)); mapping (bytes32 => mapping (bytes32 => mapping (bytes32 => bool))) acl; function canCall( address src_, address dst_, bytes4 sig ) public view returns (bool) { bytes32 src = bytes32(bytes20(src_)); bytes32 dst = bytes32(bytes20(dst_)); return acl[src][dst][sig] || acl[src][dst][ANY] || acl[src][ANY][sig] || acl[src][ANY][ANY] || acl[ANY][dst][sig] || acl[ANY][dst][ANY] || acl[ANY][ANY][sig] || acl[ANY][ANY][ANY]; } function _permit(bytes32 src, bytes32 dst, bytes32 sig) internal { acl[src][dst][sig] = true; emit LogPermit(src, dst, sig); } function _forbid(bytes32 src, bytes32 dst, bytes32 sig) internal { acl[src][dst][sig] = false; emit LogForbid(src, dst, sig); } function permit(address src, address dst, bytes32 sig) public auth { _permit(bytes32(bytes20(src)), bytes32(bytes20(dst)), sig); } function permitx(address src, address dst) public auth { _permit(bytes32(bytes20(src)), bytes32(bytes20(dst)), ANY); } function forbid(address src, address dst, bytes32 sig) public auth { _forbid(bytes32(bytes20(src)), bytes32(bytes20(dst)), sig); } function forbidx(address src, address dst) public auth { _forbid(bytes32(bytes20(src)), bytes32(bytes20(dst)), ANY); } }
File 11 of 11: Funds
// File: @openzeppelin/contracts-ethereum-package/contracts/token/ERC20/IERC20.sol pragma solidity ^0.5.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. Does not include * the optional functions; to access them see {ERC20Detailed}. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); } // File: @openzeppelin/contracts-ethereum-package/contracts/math/SafeMath.sol pragma solidity ^0.5.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return sub(a, b, "SafeMath: subtraction overflow"); } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. * * _Available since v2.4.0._ */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return div(a, b, "SafeMath: division by zero"); } /** * @dev Returns the integer division of two unsigned integers. Reverts with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. * * _Available since v2.4.0._ */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0, errorMessage); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return mod(a, b, "SafeMath: modulo by zero"); } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts with custom message when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. * * _Available since v2.4.0._ */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b != 0, errorMessage); return a % b; } } // File: @openzeppelin/contracts-ethereum-package/contracts/utils/Address.sol pragma solidity ^0.5.5; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * ==== */ function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. `keccak256('')` bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } /** * @dev Converts an `address` into `address payable`. Note that this is * simply a type cast: the actual underlying value is not changed. * * _Available since v2.4.0._ */ function toPayable(address account) internal pure returns (address payable) { return address(uint160(account)); } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. * * _Available since v2.4.0._ */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); // solhint-disable-next-line avoid-call-value (bool success, ) = recipient.call.value(amount)(""); require(success, "Address: unable to send value, recipient may have reverted"); } } // File: @openzeppelin/contracts-ethereum-package/contracts/token/ERC20/SafeERC20.sol pragma solidity ^0.5.0; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for ERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using SafeMath for uint256; using Address for address; function safeTransfer(IERC20 token, address to, uint256 value) internal { callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' // solhint-disable-next-line max-line-length require((value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).add(value); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender).sub(value, "SafeERC20: decreased allowance below zero"); callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. // A Solidity high level call has three parts: // 1. The target address is checked to verify it contains contract code // 2. The call itself is made, and success asserted // 3. The return value is decoded, which in turn checks the size of the returned data. // solhint-disable-next-line max-line-length require(address(token).isContract(), "SafeERC20: call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = address(token).call(data); require(success, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional // solhint-disable-next-line max-line-length require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } } // File: contracts/library/DSAuth.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 DSAuthority { function canCall( address src, address dst, bytes4 sig ) public view returns (bool); } contract DSAuthEvents { event LogSetAuthority(address indexed authority); event LogSetOwner(address indexed owner); event OwnerUpdate(address indexed owner, address indexed newOwner); } contract DSAuth is DSAuthEvents { DSAuthority public authority; address public owner; address public newOwner; constructor() public { owner = msg.sender; emit LogSetOwner(msg.sender); } // Warning: you should absolutely sure you want to give up authority!!! function disableOwnership() public onlyOwner { owner = address(0); emit OwnerUpdate(msg.sender, owner); } function transferOwnership(address newOwner_) public onlyOwner { require(newOwner_ != owner, "TransferOwnership: the same owner."); newOwner = newOwner_; } function acceptOwnership() public { require( msg.sender == newOwner, "AcceptOwnership: only new owner do this." ); emit OwnerUpdate(owner, newOwner); owner = newOwner; newOwner = address(0x0); } ///[snow] guard is Authority who inherit DSAuth. function setAuthority(DSAuthority authority_) public onlyOwner { authority = authority_; emit LogSetAuthority(address(authority)); } modifier onlyOwner { require(isOwner(msg.sender), "ds-auth-non-owner"); _; } function isOwner(address src) internal view returns (bool) { return bool(src == owner); } modifier auth { require(isAuthorized(msg.sender, msg.sig), "ds-auth-unauthorized"); _; } function isAuthorized(address src, bytes4 sig) internal view returns (bool) { if (src == address(this)) { return true; } else if (src == owner) { return true; } else if (authority == DSAuthority(0)) { return false; } else { return authority.canCall(src, address(this), sig); } } } // File: contracts/Funds.sol pragma solidity 0.5.12; contract Funds is DSAuth { using SafeMath for uint256; using SafeERC20 for IERC20; function transferOut( address _token, address _to, uint256 _amount ) external auth { require(_to != address(0), "transferOut: address invalid."); IERC20(_token).safeTransfer(_to, _amount); } }