mirror of
https://github.com/Instadapp/InstaContract.git
synced 2024-07-29 22:47:45 +00:00
Fixed all the indentation
This commit is contained in:
parent
3616863f44
commit
ed0dea5424
|
@ -1,5 +1,6 @@
|
||||||
pragma solidity ^0.5.0;
|
pragma solidity ^0.5.0;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @title Ownable
|
* @title Ownable
|
||||||
* @dev The Ownable contract has an owner address, and provides basic authorization control
|
* @dev The Ownable contract has an owner address, and provides basic authorization control
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
pragma solidity ^0.5.0;
|
pragma solidity ^0.5.0;
|
||||||
|
|
||||||
|
|
||||||
contract AddressRegistry {
|
contract AddressRegistry {
|
||||||
event AddressSet(string name, address addr);
|
event AddressSet(string name, address addr);
|
||||||
mapping(bytes32 => address) registry;
|
mapping(bytes32 => address) registry;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
pragma solidity ^0.5.0;
|
pragma solidity ^0.5.0;
|
||||||
|
|
||||||
|
|
||||||
library SafeMath {
|
library SafeMath {
|
||||||
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
|
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
|
||||||
if (a == 0) {
|
if (a == 0) {
|
||||||
|
@ -43,6 +44,7 @@ interface Kyber {
|
||||||
function getExpectedRate(address src, address dest, uint srcQty) external view returns (uint, uint);
|
function getExpectedRate(address src, address dest, uint srcQty) external view returns (uint, uint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract Registry {
|
contract Registry {
|
||||||
address public addressRegistry;
|
address public addressRegistry;
|
||||||
modifier onlyAdmin() {
|
modifier onlyAdmin() {
|
||||||
|
@ -56,6 +58,7 @@ contract Registry {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract Trade is Registry {
|
contract Trade is Registry {
|
||||||
using SafeMath for uint;
|
using SafeMath for uint;
|
||||||
using SafeMath for uint256;
|
using SafeMath for uint256;
|
||||||
|
@ -81,13 +84,30 @@ contract Trade is Registry {
|
||||||
uint srcAmt, // amount of token for sell
|
uint srcAmt, // amount of token for sell
|
||||||
uint minConversionRate, // minimum slippage rate
|
uint minConversionRate, // minimum slippage rate
|
||||||
uint maxDestAmt // max amount of dest token
|
uint maxDestAmt // max amount of dest token
|
||||||
) public payable returns (uint destAmt) {
|
)
|
||||||
|
public
|
||||||
|
payable
|
||||||
|
returns (uint destAmt)
|
||||||
|
{
|
||||||
address eth = getAddress("eth");
|
address eth = getAddress("eth");
|
||||||
uint ethQty = getToken(msg.sender, src, srcAmt, eth);
|
uint ethQty = getToken(
|
||||||
|
msg.sender,
|
||||||
|
src,
|
||||||
|
srcAmt,
|
||||||
|
eth
|
||||||
|
);
|
||||||
|
|
||||||
// Interacting with Kyber Proxy Contract
|
// Interacting with Kyber Proxy Contract
|
||||||
Kyber kyberFunctions = Kyber(getAddress("kyber"));
|
Kyber kyberFunctions = Kyber(getAddress("kyber"));
|
||||||
destAmt = kyberFunctions.trade.value(ethQty)(src, srcAmt, dest, msg.sender, maxDestAmt, minConversionRate, getAddress("admin"));
|
destAmt = kyberFunctions.trade.value(ethQty)(
|
||||||
|
src,
|
||||||
|
srcAmt,
|
||||||
|
dest,
|
||||||
|
msg.sender,
|
||||||
|
maxDestAmt,
|
||||||
|
minConversionRate,
|
||||||
|
getAddress("admin")
|
||||||
|
);
|
||||||
|
|
||||||
// maxDestAmt usecase implementated
|
// maxDestAmt usecase implementated
|
||||||
if (src == eth && address(this).balance > 0) {
|
if (src == eth && address(this).balance > 0) {
|
||||||
|
@ -101,11 +121,27 @@ contract Trade is Registry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emit KyberTrade(src, srcAmt, dest, destAmt, msg.sender, minConversionRate, getAddress("admin"));
|
emit KyberTrade(
|
||||||
|
src,
|
||||||
|
srcAmt,
|
||||||
|
dest,
|
||||||
|
destAmt,
|
||||||
|
msg.sender,
|
||||||
|
minConversionRate,
|
||||||
|
getAddress("admin")
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getToken(address trader, address src, uint srcAmt, address eth) internal returns (uint ethQty) {
|
function getToken(
|
||||||
|
address trader,
|
||||||
|
address src,
|
||||||
|
uint srcAmt,
|
||||||
|
address eth
|
||||||
|
)
|
||||||
|
internal
|
||||||
|
returns (uint ethQty)
|
||||||
|
{
|
||||||
if (src == eth) {
|
if (src == eth) {
|
||||||
require(msg.value == srcAmt, "Invalid Operation");
|
require(msg.value == srcAmt, "Invalid Operation");
|
||||||
ethQty = srcAmt;
|
ethQty = srcAmt;
|
||||||
|
@ -115,9 +151,9 @@ contract Trade is Registry {
|
||||||
ethQty = 0;
|
ethQty = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract InstaKyber is Trade {
|
contract InstaKyber is Trade {
|
||||||
constructor(address rAddr) public {
|
constructor(address rAddr) public {
|
||||||
addressRegistry = rAddr;
|
addressRegistry = rAddr;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
pragma solidity ^0.5.0;
|
pragma solidity ^0.5.0;
|
||||||
|
|
||||||
|
|
||||||
library SafeMath {
|
library SafeMath {
|
||||||
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
|
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
|
||||||
if (a == 0) {
|
if (a == 0) {
|
||||||
|
@ -52,14 +53,21 @@ interface WETHFace {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface InstaKyber {
|
interface InstaKyber {
|
||||||
function executeTrade(address src, address dest, uint srcAmt, uint minConversionRate, uint maxDestAmt)
|
function executeTrade(
|
||||||
external
|
address src,
|
||||||
payable
|
address dest,
|
||||||
returns (uint destAmt);
|
uint srcAmt,
|
||||||
|
uint minConversionRate,
|
||||||
|
uint maxDestAmt
|
||||||
|
)
|
||||||
|
external
|
||||||
|
payable
|
||||||
|
returns (uint destAmt);
|
||||||
|
|
||||||
function getExpectedPrice(address src, address dest, uint srcAmt) external view returns (uint, uint);
|
function getExpectedPrice(address src, address dest, uint srcAmt) external view returns (uint, uint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract Registry {
|
contract Registry {
|
||||||
address public addressRegistry;
|
address public addressRegistry;
|
||||||
modifier onlyAdmin() {
|
modifier onlyAdmin() {
|
||||||
|
@ -74,6 +82,7 @@ contract Registry {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract GlobalVar is Registry {
|
contract GlobalVar is Registry {
|
||||||
using SafeMath for uint;
|
using SafeMath for uint;
|
||||||
using SafeMath for uint256;
|
using SafeMath for uint256;
|
||||||
|
@ -85,6 +94,7 @@ contract GlobalVar is Registry {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract IssueLoan is GlobalVar {
|
contract IssueLoan is GlobalVar {
|
||||||
event LockedETH(address borrower, uint lockETH, uint lockPETH, address lockedBy);
|
event LockedETH(address borrower, uint lockETH, uint lockPETH, address lockedBy);
|
||||||
event LoanedDAI(address borrower, uint loanDAI, address payTo);
|
event LoanedDAI(address borrower, uint loanDAI, address payTo);
|
||||||
|
@ -116,7 +126,13 @@ contract IssueLoan is GlobalVar {
|
||||||
uint pethToLock = pethPEReth(msg.value);
|
uint pethToLock = pethPEReth(msg.value);
|
||||||
loanMaster.join(pethToLock); // WETH to PETH
|
loanMaster.join(pethToLock); // WETH to PETH
|
||||||
loanMaster.lock(cdps[borrower], pethToLock); // PETH to CDP
|
loanMaster.lock(cdps[borrower], pethToLock); // PETH to CDP
|
||||||
emit LockedETH(borrower, msg.value, pethToLock, msg.sender);
|
|
||||||
|
emit LockedETH(
|
||||||
|
borrower,
|
||||||
|
msg.value,
|
||||||
|
pethToLock,
|
||||||
|
msg.sender
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function drawDAI(uint daiDraw, address beneficiary) public {
|
function drawDAI(uint daiDraw, address beneficiary) public {
|
||||||
|
@ -131,9 +147,9 @@ contract IssueLoan is GlobalVar {
|
||||||
daiTkn.transfer(payTo, daiDraw);
|
daiTkn.transfer(payTo, daiDraw);
|
||||||
emit LoanedDAI(msg.sender, daiDraw, payTo);
|
emit LoanedDAI(msg.sender, daiDraw, payTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract RepayLoan is IssueLoan {
|
contract RepayLoan is IssueLoan {
|
||||||
event WipedDAI(address borrower, uint daiWipe, uint mkrCharged, address wipedBy);
|
event WipedDAI(address borrower, uint daiWipe, uint mkrCharged, address wipedBy);
|
||||||
event UnlockedETH(address borrower, uint ethFree);
|
event UnlockedETH(address borrower, uint ethFree);
|
||||||
|
@ -164,13 +180,23 @@ contract RepayLoan is IssueLoan {
|
||||||
// claiming paid MKR back
|
// claiming paid MKR back
|
||||||
if (msg.value > 0) {
|
if (msg.value > 0) {
|
||||||
// Interacting with Kyber to swap ETH with MKR
|
// Interacting with Kyber to swap ETH with MKR
|
||||||
swapETHMKR(eth, mkr, mkrCharged, msg.value);
|
swapETHMKR(
|
||||||
|
eth,
|
||||||
|
mkr,
|
||||||
|
mkrCharged,
|
||||||
|
msg.value
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
// take MKR directly from address
|
// take MKR directly from address
|
||||||
mkrTkn.transferFrom(msg.sender, address(this), mkrCharged); // user paying MKR fees
|
mkrTkn.transferFrom(msg.sender, address(this), mkrCharged); // user paying MKR fees
|
||||||
}
|
}
|
||||||
|
|
||||||
emit WipedDAI(borrower, daiWipe, mkrCharged, msg.sender);
|
emit WipedDAI(
|
||||||
|
borrower,
|
||||||
|
daiWipe,
|
||||||
|
mkrCharged,
|
||||||
|
msg.sender
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function unlockETH(uint ethFree) public {
|
function unlockETH(uint ethFree) public {
|
||||||
|
@ -185,25 +211,38 @@ contract RepayLoan is IssueLoan {
|
||||||
emit UnlockedETH(msg.sender, ethFree);
|
emit UnlockedETH(msg.sender, ethFree);
|
||||||
}
|
}
|
||||||
|
|
||||||
function swapETHMKR(address eth, address mkr, uint mkrCharged, uint ethQty) internal {
|
function swapETHMKR(
|
||||||
|
address eth,
|
||||||
|
address mkr,
|
||||||
|
uint mkrCharged,
|
||||||
|
uint ethQty
|
||||||
|
)
|
||||||
|
internal
|
||||||
|
{
|
||||||
InstaKyber instak = InstaKyber(getAddress("InstaKyber"));
|
InstaKyber instak = InstaKyber(getAddress("InstaKyber"));
|
||||||
uint minRate;
|
uint minRate;
|
||||||
(, minRate) = instak.getExpectedPrice(eth, mkr, ethQty);
|
(, minRate) = instak.getExpectedPrice(eth, mkr, ethQty);
|
||||||
uint mkrBought = instak.executeTrade.value(ethQty)(eth, mkr, ethQty, minRate, mkrCharged);
|
uint mkrBought = instak.executeTrade.value(ethQty)(
|
||||||
|
eth,
|
||||||
|
mkr,
|
||||||
|
ethQty,
|
||||||
|
minRate,
|
||||||
|
mkrCharged
|
||||||
|
);
|
||||||
require(mkrCharged == mkrBought, "ETH not sufficient to cover the MKR fees.");
|
require(mkrCharged == mkrBought, "ETH not sufficient to cover the MKR fees.");
|
||||||
if (address(this).balance > 0) {
|
if (address(this).balance > 0) {
|
||||||
msg.sender.transfer(address(this).balance);
|
msg.sender.transfer(address(this).balance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract BorrowTasks is RepayLoan {
|
contract BorrowTasks is RepayLoan {
|
||||||
event TranferCDP(bytes32 cdp, address owner, address nextOwner);
|
event TranferCDP(bytes32 cdp, address owner, address nextOwner);
|
||||||
event CDPClaimed(bytes32 cdp, address owner);
|
event CDPClaimed(bytes32 cdp, address owner);
|
||||||
|
|
||||||
function transferCDP(address nextOwner) public {
|
function transferCDP(address nextOwner) public {
|
||||||
require(nextOwner != 0, "Invalid Address.");
|
require(nextOwner != address(0), "Invalid Address.");
|
||||||
MakerCDP loanMaster = MakerCDP(cdpAddr);
|
MakerCDP loanMaster = MakerCDP(cdpAddr);
|
||||||
loanMaster.give(cdps[msg.sender], nextOwner);
|
loanMaster.give(cdps[msg.sender], nextOwner);
|
||||||
cdps[msg.sender] = blankCDP;
|
cdps[msg.sender] = blankCDP;
|
||||||
|
@ -243,6 +282,7 @@ contract BorrowTasks is RepayLoan {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract InstaMaker is BorrowTasks {
|
contract InstaMaker is BorrowTasks {
|
||||||
event MKRCollected(uint amount);
|
event MKRCollected(uint amount);
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// Resolver to Wipe & Coll any CDP
|
// Resolver to Wipe & Coll any CDP
|
||||||
pragma solidity ^0.5.0;
|
pragma solidity ^0.5.0;
|
||||||
|
|
||||||
|
|
||||||
library SafeMath {
|
library SafeMath {
|
||||||
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
|
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
|
||||||
if (a == 0) {
|
if (a == 0) {
|
||||||
|
@ -47,14 +48,21 @@ interface WETHFace {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface InstaKyber {
|
interface InstaKyber {
|
||||||
function executeTrade(address src, address dest, uint srcAmt, uint minConversionRate, uint maxDestAmt)
|
function executeTrade(
|
||||||
external
|
address src,
|
||||||
payable
|
address dest,
|
||||||
returns (uint destAmt);
|
uint srcAmt,
|
||||||
|
uint minConversionRate,
|
||||||
|
uint maxDestAmt
|
||||||
|
)
|
||||||
|
external
|
||||||
|
payable
|
||||||
|
returns (uint destAmt);
|
||||||
|
|
||||||
function getExpectedPrice(address src, address dest, uint srcAmt) external view returns (uint, uint);
|
function getExpectedPrice(address src, address dest, uint srcAmt) external view returns (uint, uint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract Registry {
|
contract Registry {
|
||||||
address public addressRegistry;
|
address public addressRegistry;
|
||||||
modifier onlyAdmin() {
|
modifier onlyAdmin() {
|
||||||
|
@ -69,6 +77,7 @@ contract Registry {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract Helper is Registry {
|
contract Helper is Registry {
|
||||||
using SafeMath for uint;
|
using SafeMath for uint;
|
||||||
using SafeMath for uint256;
|
using SafeMath for uint256;
|
||||||
|
@ -88,8 +97,15 @@ contract Helper is Registry {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract Lock is Helper {
|
contract Lock is Helper {
|
||||||
event LockedETH(uint cdpNum, address lockedBy, uint lockETH, uint lockPETH);
|
|
||||||
|
event LockedETH(
|
||||||
|
uint cdpNum,
|
||||||
|
address lockedBy,
|
||||||
|
uint lockETH,
|
||||||
|
uint lockPETH
|
||||||
|
);
|
||||||
|
|
||||||
function lockETH(uint cdpNum) public payable {
|
function lockETH(uint cdpNum) public payable {
|
||||||
MakerCDP loanMaster = MakerCDP(cdpAddr);
|
MakerCDP loanMaster = MakerCDP(cdpAddr);
|
||||||
|
@ -98,11 +114,17 @@ contract Lock is Helper {
|
||||||
uint pethToLock = pethPEReth(msg.value);
|
uint pethToLock = pethPEReth(msg.value);
|
||||||
loanMaster.join(pethToLock); // WETH to PETH
|
loanMaster.join(pethToLock); // WETH to PETH
|
||||||
loanMaster.lock(bytes32(cdpNum), pethToLock); // PETH to CDP
|
loanMaster.lock(bytes32(cdpNum), pethToLock); // PETH to CDP
|
||||||
emit LockedETH(cdpNum, msg.sender, msg.value, pethToLock);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
emit LockedETH(
|
||||||
|
cdpNum,
|
||||||
|
msg.sender,
|
||||||
|
msg.value,
|
||||||
|
pethToLock
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract Wipe is Lock {
|
contract Wipe is Lock {
|
||||||
event WipedDAI(uint cdpNum, address wipedBy, uint daiWipe, uint mkrCharged);
|
event WipedDAI(uint cdpNum, address wipedBy, uint daiWipe, uint mkrCharged);
|
||||||
|
|
||||||
|
@ -125,22 +147,35 @@ contract Wipe is Lock {
|
||||||
mkrTkn.transferFrom(msg.sender, address(this), mkrCharged); // user paying MKR fees
|
mkrTkn.transferFrom(msg.sender, address(this), mkrCharged); // user paying MKR fees
|
||||||
}
|
}
|
||||||
|
|
||||||
emit WipedDAI(cdpNum, msg.sender, daiWipe, mkrCharged);
|
emit WipedDAI(
|
||||||
|
cdpNum,
|
||||||
|
msg.sender,
|
||||||
|
daiWipe,
|
||||||
|
mkrCharged
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function swapETHMKR(uint mkrCharged, uint ethQty) internal {
|
function swapETHMKR(uint mkrCharged, uint ethQty) internal {
|
||||||
InstaKyber instak = InstaKyber(kyber);
|
InstaKyber instak = InstaKyber(kyber);
|
||||||
uint minRate;
|
uint minRate;
|
||||||
(, minRate) = instak.getExpectedPrice(eth, mkr, ethQty);
|
(, minRate) = instak.getExpectedPrice(eth, mkr, ethQty);
|
||||||
uint mkrBought = instak.executeTrade.value(ethQty)(eth, mkr, ethQty, minRate, mkrCharged);
|
|
||||||
|
uint mkrBought = instak.executeTrade.value(ethQty)(
|
||||||
|
eth,
|
||||||
|
mkr,
|
||||||
|
ethQty,
|
||||||
|
minRate,
|
||||||
|
mkrCharged
|
||||||
|
);
|
||||||
|
|
||||||
require(mkrCharged == mkrBought, "ETH not sufficient to cover the MKR fees.");
|
require(mkrCharged == mkrBought, "ETH not sufficient to cover the MKR fees.");
|
||||||
if (address(this).balance > 0) {
|
if (address(this).balance > 0) {
|
||||||
msg.sender.transfer(address(this).balance);
|
msg.sender.transfer(address(this).balance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract ApproveTkn is Wipe {
|
contract ApproveTkn is Wipe {
|
||||||
function approveERC20() public {
|
function approveERC20() public {
|
||||||
IERC20 wethTkn = IERC20(weth);
|
IERC20 wethTkn = IERC20(weth);
|
||||||
|
@ -152,9 +187,9 @@ contract ApproveTkn is Wipe {
|
||||||
IERC20 daiTkn = IERC20(dai);
|
IERC20 daiTkn = IERC20(dai);
|
||||||
daiTkn.approve(cdpAddr, 2 ** 256 - 1);
|
daiTkn.approve(cdpAddr, 2 ** 256 - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract PublicCDP is ApproveTkn {
|
contract PublicCDP is ApproveTkn {
|
||||||
event MKRCollected(uint amount);
|
event MKRCollected(uint amount);
|
||||||
|
|
||||||
|
@ -178,5 +213,4 @@ contract PublicCDP is ApproveTkn {
|
||||||
mkrTkn.transfer(msg.sender, amount);
|
mkrTkn.transfer(msg.sender, amount);
|
||||||
emit MKRCollected(amount);
|
emit MKRCollected(amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
pragma solidity ^0.5.0;
|
pragma solidity ^0.5.0;
|
||||||
|
|
||||||
|
|
||||||
library SafeMath {
|
library SafeMath {
|
||||||
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
|
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
|
||||||
if (a == 0) {
|
if (a == 0) {
|
||||||
|
@ -27,6 +28,7 @@ interface MakerCDP {
|
||||||
function give(bytes32 cup, address guy) external;
|
function give(bytes32 cup, address guy) external;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract UniqueCDP {
|
contract UniqueCDP {
|
||||||
address public deployer;
|
address public deployer;
|
||||||
address public cdpAddr;
|
address public cdpAddr;
|
||||||
|
|
|
@ -23,6 +23,7 @@ interface Kyber {
|
||||||
function getExpectedRate(address src, address dest, uint srcQty) external view returns (uint, uint);
|
function getExpectedRate(address src, address dest, uint srcQty) external view returns (uint, uint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract Registry {
|
contract Registry {
|
||||||
address public addressRegistry;
|
address public addressRegistry;
|
||||||
modifier onlyAdmin() {
|
modifier onlyAdmin() {
|
||||||
|
@ -35,6 +36,7 @@ contract Registry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract Trade is Registry {
|
contract Trade is Registry {
|
||||||
event KyberTrade(address src, uint srcAmt, address dest, uint destAmt, address beneficiary, uint minConversionRate);
|
event KyberTrade(address src, uint srcAmt, address dest, uint destAmt, address beneficiary, uint minConversionRate);
|
||||||
|
|
||||||
|
@ -56,14 +58,29 @@ contract Trade is Registry {
|
||||||
|
|
||||||
// Interacting with Kyber Proxy Contract
|
// Interacting with Kyber Proxy Contract
|
||||||
Kyber kyberFunctions = Kyber(getAddress("kyber"));
|
Kyber kyberFunctions = Kyber(getAddress("kyber"));
|
||||||
destAmt = kyberFunctions.trade.value(0)(src, srcDAI, dest, msg.sender, 2 ** 255, minConversionRate, getAddress("admin"));
|
|
||||||
|
|
||||||
emit KyberTrade(src, srcDAI, dest, destAmt, msg.sender, minConversionRate);
|
destAmt = kyberFunctions.trade.value(0)(
|
||||||
|
src,
|
||||||
|
srcDAI,
|
||||||
|
dest,
|
||||||
|
msg.sender,
|
||||||
|
2 ** 255,
|
||||||
|
minConversionRate,
|
||||||
|
getAddress("admin")
|
||||||
|
);
|
||||||
|
|
||||||
|
emit KyberTrade(
|
||||||
|
src,
|
||||||
|
srcDAI,
|
||||||
|
dest,
|
||||||
|
destAmt,
|
||||||
|
msg.sender,
|
||||||
|
minConversionRate
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract DAI2ETH is Trade {
|
contract DAI2ETH is Trade {
|
||||||
constructor(address rAddr) public {
|
constructor(address rAddr) public {
|
||||||
addressRegistry = rAddr;
|
addressRegistry = rAddr;
|
||||||
|
@ -71,5 +88,4 @@ contract DAI2ETH is Trade {
|
||||||
}
|
}
|
||||||
|
|
||||||
function() external payable {}
|
function() external payable {}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
pragma solidity ^0.5.0;
|
pragma solidity ^0.5.0;
|
||||||
|
|
||||||
|
|
||||||
library SafeMath {
|
library SafeMath {
|
||||||
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
|
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
|
||||||
if (a == 0) {
|
if (a == 0) {
|
||||||
|
@ -72,14 +73,21 @@ interface WETHFace {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface InstaKyber {
|
interface InstaKyber {
|
||||||
function executeTrade(address src, address dest, uint srcAmt, uint minConversionRate, uint maxDestAmt)
|
function executeTrade(
|
||||||
external
|
address src,
|
||||||
payable
|
address dest,
|
||||||
returns (uint destAmt);
|
uint srcAmt,
|
||||||
|
uint minConversionRate,
|
||||||
|
uint maxDestAmt
|
||||||
|
)
|
||||||
|
external
|
||||||
|
payable
|
||||||
|
returns (uint destAmt);
|
||||||
|
|
||||||
function getExpectedPrice(address src, address dest, uint srcAmt) external view returns (uint, uint);
|
function getExpectedPrice(address src, address dest, uint srcAmt) external view returns (uint, uint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract Registry {
|
contract Registry {
|
||||||
address public addressRegistry;
|
address public addressRegistry;
|
||||||
modifier onlyAdmin() {
|
modifier onlyAdmin() {
|
||||||
|
@ -91,9 +99,9 @@ contract Registry {
|
||||||
AddressRegistry addrReg = AddressRegistry(addressRegistry);
|
AddressRegistry addrReg = AddressRegistry(addressRegistry);
|
||||||
return addrReg.getAddr(name);
|
return addrReg.getAddr(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract GlobalVar is Registry {
|
contract GlobalVar is Registry {
|
||||||
using SafeMath for uint;
|
using SafeMath for uint;
|
||||||
using SafeMath for uint256;
|
using SafeMath for uint256;
|
||||||
|
@ -117,9 +125,9 @@ contract GlobalVar is Registry {
|
||||||
MakerCDP loanMaster = MakerCDP(cdpAddr);
|
MakerCDP loanMaster = MakerCDP(cdpAddr);
|
||||||
rPETH = (ethNum.mul(10 ** 27)).div(loanMaster.per());
|
rPETH = (ethNum.mul(10 ** 27)).div(loanMaster.per());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract BorrowLoan is GlobalVar {
|
contract BorrowLoan is GlobalVar {
|
||||||
// uint cdpNum
|
// uint cdpNum
|
||||||
event LockedETH(uint cdpNum, address borrower, uint lockETH, uint lockPETH);
|
event LockedETH(uint cdpNum, address borrower, uint lockETH, uint lockPETH);
|
||||||
|
@ -145,7 +153,12 @@ contract BorrowLoan is GlobalVar {
|
||||||
uint pethToLock = pethPEReth(msg.value);
|
uint pethToLock = pethPEReth(msg.value);
|
||||||
loanMaster.join(pethToLock); // WETH to PETH
|
loanMaster.join(pethToLock); // WETH to PETH
|
||||||
loanMaster.lock(cup, pethToLock); // PETH to CDP
|
loanMaster.lock(cup, pethToLock); // PETH to CDP
|
||||||
emit LockedETH(uint(cup), msg.sender, msg.value, pethToLock);
|
emit LockedETH(
|
||||||
|
uint(cup),
|
||||||
|
msg.sender,
|
||||||
|
msg.value,
|
||||||
|
pethToLock
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// minting DAI
|
// minting DAI
|
||||||
|
@ -157,12 +170,18 @@ contract BorrowLoan is GlobalVar {
|
||||||
payTo = msg.sender;
|
payTo = msg.sender;
|
||||||
}
|
}
|
||||||
daiTkn.transfer(payTo, daiDraw);
|
daiTkn.transfer(payTo, daiDraw);
|
||||||
emit LoanedDAI(uint(cup), msg.sender, daiDraw, payTo);
|
|
||||||
|
emit LoanedDAI(
|
||||||
|
uint(cup),
|
||||||
|
msg.sender,
|
||||||
|
daiDraw,
|
||||||
|
payTo
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract RepayLoan is BorrowLoan {
|
contract RepayLoan is BorrowLoan {
|
||||||
event WipedDAI(uint cdpNum, address borrower, uint daiWipe, uint mkrCharged);
|
event WipedDAI(uint cdpNum, address borrower, uint daiWipe, uint mkrCharged);
|
||||||
event FreedETH(uint cdpNum, address borrower, uint ethFree);
|
event FreedETH(uint cdpNum, address borrower, uint ethFree);
|
||||||
|
@ -189,7 +208,13 @@ contract RepayLoan is BorrowLoan {
|
||||||
// take MKR directly from address
|
// take MKR directly from address
|
||||||
mkrTkn.transferFrom(msg.sender, address(this), mkrCharged); // user paying MKR fees
|
mkrTkn.transferFrom(msg.sender, address(this), mkrCharged); // user paying MKR fees
|
||||||
}
|
}
|
||||||
emit WipedDAI(cdpNum, msg.sender, daiWipe, mkrCharged);
|
|
||||||
|
emit WipedDAI(
|
||||||
|
cdpNum,
|
||||||
|
msg.sender,
|
||||||
|
daiWipe,
|
||||||
|
mkrCharged
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO => send pethFree from frontend instead of ethFree
|
// TODO => send pethFree from frontend instead of ethFree
|
||||||
|
@ -224,11 +249,17 @@ contract RepayLoan is BorrowLoan {
|
||||||
|
|
||||||
cdps[cdpNum] = address(0x0);
|
cdps[cdpNum] = address(0x0);
|
||||||
|
|
||||||
emit ShutCDP(cdpNum, msg.sender, daiDebt, wethBal);
|
emit ShutCDP(
|
||||||
|
cdpNum,
|
||||||
|
msg.sender,
|
||||||
|
daiDebt,
|
||||||
|
wethBal
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract MiscTask is RepayLoan {
|
contract MiscTask is RepayLoan {
|
||||||
event TranferInternal(uint cdpNum, address owner, address nextOwner);
|
event TranferInternal(uint cdpNum, address owner, address nextOwner);
|
||||||
event TranferExternal(uint cdpNum, address owner, address nextOwner);
|
event TranferExternal(uint cdpNum, address owner, address nextOwner);
|
||||||
|
@ -304,6 +335,7 @@ contract MiscTask is RepayLoan {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract InstaBank is MiscTask {
|
contract InstaBank is MiscTask {
|
||||||
event MKRCollected(uint amount);
|
event MKRCollected(uint amount);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
pragma solidity ^0.5.0;
|
pragma solidity ^0.5.0;
|
||||||
|
|
||||||
|
|
||||||
library SafeMath {
|
library SafeMath {
|
||||||
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
|
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
|
||||||
if (a == 0) {
|
if (a == 0) {
|
||||||
|
@ -53,6 +54,7 @@ interface InstaBank {
|
||||||
function transferCDPInternal(uint cdpNum, address nextOwner) external;
|
function transferCDPInternal(uint cdpNum, address nextOwner) external;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract Registry {
|
contract Registry {
|
||||||
address public addressRegistry;
|
address public addressRegistry;
|
||||||
modifier onlyAdmin() {
|
modifier onlyAdmin() {
|
||||||
|
@ -65,6 +67,7 @@ contract Registry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract GlobalVar is Registry {
|
contract GlobalVar is Registry {
|
||||||
using SafeMath for uint;
|
using SafeMath for uint;
|
||||||
using SafeMath for uint256;
|
using SafeMath for uint256;
|
||||||
|
@ -92,6 +95,7 @@ contract GlobalVar is Registry {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract LoopNewCDP is GlobalVar {
|
contract LoopNewCDP is GlobalVar {
|
||||||
event LevNewCDP(uint cdpNum, uint ethLocked, uint daiMinted);
|
event LevNewCDP(uint cdpNum, uint ethLocked, uint daiMinted);
|
||||||
|
|
||||||
|
@ -143,6 +147,7 @@ contract LoopNewCDP is GlobalVar {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
contract LeverageCDP is LoopNewCDP {
|
contract LeverageCDP is LoopNewCDP {
|
||||||
constructor(address rAddr) public {
|
constructor(address rAddr) public {
|
||||||
addressRegistry = rAddr;
|
addressRegistry = rAddr;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user