diff --git a/contracts/NewBancorPool.sol b/contracts/NewBancorPool.sol index db07701..7a40ab7 100644 --- a/contracts/NewBancorPool.sol +++ b/contracts/NewBancorPool.sol @@ -115,10 +115,12 @@ contract NewBancorPool is BnStorage, BnConstants, Managed { * @notice - Mint cToken (Compound Token) * @dev - Reference from this link => https://compound.finance/developers/ctokens ***/ - function mintCToken(uint256 mintAmount) public returns (bool) { + function mintCToken(uint256 mintAmount, address recipient) public returns (bool) { iErc20.approve(address(cDAItokenAddr), mintAmount); // approve the transfer iCErc20.mint(mintAmount); + iCErc20.transfer(recipient, mintAmount); + // [Ref]: // Erc20 underlying = Erc20(_ERC20tokenAddr); // get a handle for the underlying asset contract // CErc20 cToken = CErc20(cDAItokenAddr); // get a handle for the corresponding cToken contract diff --git a/contracts_compound-protocol/CErc20.sol b/contracts_old/contracts_ref_compound-protocol/CErc20.sol similarity index 100% rename from contracts_compound-protocol/CErc20.sol rename to contracts_old/contracts_ref_compound-protocol/CErc20.sol diff --git a/contracts_compound-protocol/CToken.sol b/contracts_old/contracts_ref_compound-protocol/CToken.sol similarity index 100% rename from contracts_compound-protocol/CToken.sol rename to contracts_old/contracts_ref_compound-protocol/CToken.sol diff --git a/contracts_old/contracts_ref_compound-protocol/interfaces/EIP20Interface.sol b/contracts_old/contracts_ref_compound-protocol/interfaces/EIP20Interface.sol new file mode 100644 index 0000000..238ebd8 --- /dev/null +++ b/contracts_old/contracts_ref_compound-protocol/interfaces/EIP20Interface.sol @@ -0,0 +1,59 @@ +pragma solidity 0.4.26; + +/** + * @title ERC 20 Token Standard Interface + * https://eips.ethereum.org/EIPS/eip-20 + */ +interface EIP20Interface { + + /** + * @notice Get the total number of tokens in circulation + * @return The supply of tokens + */ + function totalSupply() external view returns (uint256); + + /** + * @notice Gets the balance of the specified address + * @param owner The address from which the balance will be retrieved + * @return The balance + */ + function balanceOf(address owner) external view returns (uint256 balance); + + /** + * @notice Transfer `amount` tokens from `msg.sender` to `dst` + * @param dst The address of the destination account + * @param amount The number of tokens to transfer + * @return Whether or not the transfer succeeded + */ + function transfer(address dst, uint256 amount) external returns (bool success); + + /** + * @notice Transfer `amount` tokens from `src` to `dst` + * @param src The address of the source account + * @param dst The address of the destination account + * @param amount The number of tokens to transfer + * @return Whether or not the transfer succeeded + */ + function transferFrom(address src, address dst, uint256 amount) external returns (bool success); + + /** + * @notice Approve `spender` to transfer up to `amount` from `src` + * @dev This will overwrite the approval amount for `spender` + * and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve) + * @param spender The address of the account which may transfer tokens + * @param amount The number of tokens that are approved (-1 means infinite) + * @return Whether or not the approval succeeded + */ + function approve(address spender, uint256 amount) external returns (bool success); + + /** + * @notice Get the current allowance from `owner` for `spender` + * @param owner The address of the account which owns the tokens to be spent + * @param spender The address of the account which may transfer tokens + * @return The number of tokens allowed to be spent (-1 means infinite) + */ + function allowance(address owner, address spender) external view returns (uint256 remaining); + + event Transfer(address indexed from, address indexed to, uint256 amount); + event Approval(address indexed owner, address indexed spender, uint256 amount); +} diff --git a/contracts_old/contracts_ref_compound-protocol/mockToken/CERC20Mock.sol b/contracts_old/contracts_ref_compound-protocol/mockToken/CERC20Mock.sol new file mode 100755 index 0000000..d619641 --- /dev/null +++ b/contracts_old/contracts_ref_compound-protocol/mockToken/CERC20Mock.sol @@ -0,0 +1,115 @@ +pragma solidity 0.4.26; + +import '../../bancor-protocol/utility/SafeMath.sol'; +import "../../bancor-protocol/token/interfaces/IERC20Token.sol"; + +import "../interfaces/EIP20Interface.sol"; + +/** + * @title CERC20 Mock + * @dev See https://compound.finance/developers + */ +contract CERC20Mock { + using SafeMath for uint256; + + /** + * @notice Indicator that this is a CToken contract (for inspection) + */ + bool public constant isCToken = true; + + /** + * @notice Block number that interest started to increase from + */ + uint256 public initialBlockNumber; + + /** + * @notice Initial exchange rate used when minting the first CTokens (used when totalSupply = 0) + */ + uint256 public initialExchangeRate; + + /** + * @notice Underlying asset for this CToken + */ + address public underlying; + + /** + * @notice EIP-20 token decimals for this token + */ + uint256 public decimals; + + /** + * @notice Construct a new money market + * @param underlying_ The address of the underlying asset + * @param initialExchangeRate_ The initial exchange rate, scaled by 1e18 + * @param decimals_ ERC-20 decimal precision of this token + */ + constructor(address underlying_, uint256 initialExchangeRate_, uint256 decimals_) public { + initialBlockNumber = block.number; + underlying = underlying_; + initialExchangeRate = initialExchangeRate_; + decimals = decimals_; + EIP20Interface(underlying).totalSupply(); // Sanity check the underlying + } + + /*** User Interface ***/ + + /** + * @notice Get the underlying balance of the `owner` + * @dev This also accrues interest in a transaction + * @param owner The address of the account to query + * @return The amount of underlying owned by `owner` + */ + function balanceOfUnderlying(address owner) public view returns (uint256) { + uint256 underlyingBalance = EIP20Interface(underlying).balanceOf(address(this)); + if (balanceOf(owner) == 0) return 0; + return (totalSupply().mul(1e18).div(balanceOf(owner))).mul(underlyingBalance).div(1e18); + } + + /** + * @notice Accrue interest then return the up-to-date exchange rate + * @return Calculated exchange rate scaled by 1e18 + */ + function exchangeRateCurrent() public view returns (uint256) { + uint256 totalUnderlying = EIP20Interface(underlying).balanceOf(address(this)); + uint256 tokenValueExp = initialExchangeRate; + if (totalSupply() > 0 && totalUnderlying > 0) { + totalUnderlying = totalUnderlying.mul(1e18); + tokenValueExp = totalUnderlying.div(totalSupply()); + } + return tokenValueExp; + } + + /** + * @notice Sender supplies assets into the market and receives cTokens in exchange + * @dev Accrues interest whether or not the operation succeeds, unless reverted + * @param mintAmount The amount of the underlying asset to supply + * @return true=success, otherwise a failure + */ + function mint(uint256 mintAmount) external returns (bool) { + uint256 mintedTokens = (mintAmount.mul(1e18)).div(exchangeRateCurrent()); + _mint(msg.sender, mintedTokens); + return EIP20Interface(underlying).transferFrom(msg.sender, address(this), mintAmount); + } + + /** + * @notice Sender supplies underlying to the money market + * @dev This is just a mock + * @param supplyAmount The amount of underlying to supply + * @return true=success, otherwise a failure + */ + function supplyUnderlying(uint256 supplyAmount) external returns (bool) { + return EIP20Interface(underlying).transferFrom(msg.sender, address(this), supplyAmount); + } + + /** + * @notice Sender redeems cTokens in exchange for a specified amount of underlying asset + * @dev This is just a mock + * @param redeemAmount The amount of underlying to redeem + * @return true=success, otherwise a failure + */ + function redeemUnderlying(uint256 redeemAmount) external returns (bool) { + uint256 redeemTokens = redeemAmount.mul(1e18).div(exchangeRateCurrent()); + _burn(msg.sender, redeemTokens); + return EIP20Interface(underlying).transfer(msg.sender, redeemAmount); + } +} diff --git a/contracts_old/contracts_ref_compound-protocol/mockToken/ERC20Mock.sol b/contracts_old/contracts_ref_compound-protocol/mockToken/ERC20Mock.sol new file mode 100755 index 0000000..2424490 --- /dev/null +++ b/contracts_old/contracts_ref_compound-protocol/mockToken/ERC20Mock.sol @@ -0,0 +1,19 @@ +pragma solidity 0.4.26; + +import "../../bancor-protocol/token/interfaces/IERC20Token.sol"; + +/** + * @title ERC20 Mock + * @dev Mock class using ERC20 + */ +contract ERC20Mock { + /** + * @dev Allows anyone to mint tokens to any address + * @param to The address that will receive the minted tokens. + * @param amount The amount of tokens to mint. + * @return A boolean that indicates if the operation was successful. + */ + function mint(address to, uint256 amount) public { + _mint(to, amount); + } +}