Skip to content

Commit

Permalink
Tether Support and Gas Optimizations
Browse files Browse the repository at this point in the history
This patch adds Tether support and creates a number of small gas optimizations. The goal is to reduce about 10-20K of gas on operations by simplying certain operations in the protocol, without significantly changing behavior. Specfically we:

1. Remove `checkTransferIn` as the now look at the effect of `transfer` to handle fees, which obviates the need for check transfer in.
2. Change our delegator contract to use `msg.data` directly, instead of re-encoding. This removes some unnecessary repacking.
3. Reduce potentially redunant SLOADs by memoizing values.
4. Do not re-accrue interest multiple-times per block (as the interest accrued is, by definition, zero, beyond the first transaction in a block for a given cToken).
5. Remove `localVars` structs as Solidity handles more variables correctly and it cleans up code.
6. In some cases, switch from `CarefulMath` to `SafeMath` (that is, revert instead of returning error codes). This is done in select places as it's technically a change of behavior and needs to be handled carefully.
7. Add Tether to Price Oracle Proxy.
8. Bump up to 0.5.16, but:
9. Update Solidity 0.6.x-style contract inheritence (that is, interfaces cannot declare constants, etc)
10. Add a scenario command to check the BorrowRate from an IR model
11. Deploy Tether to Ropsten and Mainnet
12. Bump up total gas limit
  • Loading branch information
maxwolff authored and hayesgm committed Apr 25, 2020
1 parent 18aa599 commit cce8c88
Show file tree
Hide file tree
Showing 111 changed files with 14,015 additions and 7,790 deletions.
46 changes: 18 additions & 28 deletions contracts/CDaiDelegate.sol
Original file line number Diff line number Diff line change
Expand Up @@ -181,38 +181,28 @@ contract CDaiDelegate is CErc20Delegate {

/*** Maker Interfaces ***/

contract PotLike {
function chi() public view returns (uint);
function dsr() public view returns (uint);
function rho() public view returns (uint);
function pie(address) public view returns (uint);
function drip() public returns (uint);
function join(uint) public;
function exit(uint) public;
interface PotLike {
function chi() external view returns (uint);
function pie(address) external view returns (uint);
function drip() external returns (uint);
function join(uint) external;
function exit(uint) external;
}

contract GemLike {
function approve(address, uint) public;
function balanceOf(address) public view returns (uint);
function transfer(address, uint) public;
function transferFrom(address, address, uint) public;
function deposit() public payable;
function withdraw(uint) public;
interface GemLike {
function approve(address, uint) external;
function balanceOf(address) external view returns (uint);
function transferFrom(address, address, uint) external returns (bool);
}

contract VatLike {
function can(address, address) public view returns (uint);
function ilks(bytes32) public view returns (uint, uint, uint, uint, uint);
function dai(address) public view returns (uint);
function urns(bytes32, address) public view returns (uint, uint);
function frob(bytes32, address, address, address, int, int) public;
function hope(address) public;
function move(address, address, uint) public;
interface VatLike {
function dai(address) external view returns (uint);
function hope(address) external;
}

contract DaiJoinLike {
function vat() public returns (VatLike);
function dai() public returns (GemLike);
function join(address, uint) public payable;
function exit(address, uint) public;
interface DaiJoinLike {
function vat() external returns (VatLike);
function dai() external returns (GemLike);
function join(address, uint) external payable;
function exit(address, uint) external;
}
23 changes: 2 additions & 21 deletions contracts/CErc20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -130,29 +130,10 @@ contract CErc20 is CToken, CErc20Interface {
return token.balanceOf(address(this));
}

/**
* @dev Checks whether or not there is sufficient allowance for this contract to move amount from `from` and
* whether or not `from` has a balance of at least `amount`. Does NOT do a transfer.
*/
function checkTransferIn(address from, uint amount) internal view returns (Error) {
EIP20Interface token = EIP20Interface(underlying);

if (token.allowance(from, address(this)) < amount) {
return Error.TOKEN_INSUFFICIENT_ALLOWANCE;
}

if (token.balanceOf(from) < amount) {
return Error.TOKEN_INSUFFICIENT_BALANCE;
}

return Error.NO_ERROR;
}

/**
* @dev Similar to EIP20 transfer, except it handles a False result from `transferFrom` and reverts in that case.
* If caller has not called `checkTransferIn`, this may revert due to insufficient balance or insufficient
* allowance. If caller has called `checkTransferIn` prior to this call, and it returned Error.NO_ERROR,
* this should not revert in normal conditions. This function returns the actual amount received,
* This will revert due to insufficient balance or insufficient allowance.
* This function returns the actual amount received,
* which may be less than `amount` if there is a fee attached to the transfer.
*
* Note: This wrapper safely handles non-standard ERC-20 tokens that do not return a value.
Expand Down
Loading

0 comments on commit cce8c88

Please sign in to comment.