Created
May 6, 2020 05:03
-
-
Save NAKsir-melody/d197597c2cd65622b2b0dec1e10ce65a to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.5.16+commit.9c3226ce.js&optimize=false&gist=
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity 0.5.16; | |
//https://docs.aave.com/developers/tutorials/performing-a-flash-loan/...-with-remix | |
import "https://github.com/mrdavey/ez-flashloan/blob/remix/contracts/aave/FlashLoanReceiverBase.sol"; | |
import "https://github.com/mrdavey/ez-flashloan/blob/remix/contracts/aave/ILendingPool.sol"; | |
import "https://github.com/mrdavey/ez-flashloan/blob/remix/contracts/aave/ILendingPoolAddressesProvider.sol"; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity 0.5.16; | |
pragma experimental ABIEncoderV2; | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v2.5.0/contracts/token/ERC20/ERC20.sol"; | |
contract IToken is ERC20 { | |
function mint(address receiver, uint depositAmount) external returns (uint); | |
function burn(address receiver, uint withdrawAmount) external returns (uint); | |
function mintWithEther(address receiver) external payable returns (uint); | |
function burnToEther(address receiver, uint256 withdrawAmount) external returns (uint); | |
function loanTokenAddress() external returns (address); | |
} | |
contract fulcrumInterface { | |
function mintWithEther(address receiver, uint256 maxPriceAllowed) external payable returns (uint256 mintAmount); | |
function mint(address receiver, uint256 amount) external payable returns (uint256 mintAmount); | |
function burnToEther(address receiver, uint256 burnAmount, uint256 minPriceAllowed) external returns (uint256 loanAmountPaid); | |
} | |
interface IBZxLoanToken { | |
function transfer(address dst, uint256 amount) external returns (bool); | |
function transferFrom(address src, address dst, uint256 amount) external returns (bool); | |
function approve(address spender, uint256 amount) external returns (bool); | |
function allowance(address owner, address spender) external view returns (uint256); | |
function balanceOf(address owner) external view returns (uint256); | |
function loanTokenAddress() external view returns (address); | |
function tokenPrice() external view returns (uint256 price); | |
// function mintWithEther(address receiver) external payable returns (uint256 mintAmount); | |
function mint(address receiver, uint256 depositAmount) external returns (uint256 mintAmount); | |
// function burnToEther(address payable receiver, uint256 burnAmount) external returns (uint256 loanAmountPaid); | |
function burn(address receiver, uint256 burnAmount) external returns (uint256 loanAmountPaid); | |
} | |
contract IBZxLoanEther is IBZxLoanToken { | |
function mintWithEther(address receiver) external payable returns (uint256 mintAmount); | |
function burnToEther(address payable receiver, uint256 burnAmount) external returns (uint256 loanAmountPaid); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity 0.5.16; | |
pragma experimental ABIEncoderV2; | |
interface CEth { | |
function mint() external payable; | |
function borrow(uint256) external returns (uint256); | |
function repayBorrow() external payable; | |
function borrowBalanceCurrent(address) external returns (uint256); | |
} | |
interface CErc20 { | |
function mint(uint256) external returns (uint256); | |
function borrow(uint256) external returns (uint256); | |
function borrowRatePerBlock() external view returns (uint256); | |
function borrowBalanceCurrent(address) external returns (uint256); | |
function repayBorrow(uint256) external returns (uint256); | |
} | |
interface Comptroller { | |
function markets(address) external returns (bool, uint256); | |
function enterMarkets(address[] calldata) | |
external | |
returns (uint256[] memory); | |
function getAccountLiquidity(address) | |
external | |
view | |
returns (uint256, uint256, uint256); | |
function exitMarket(address cToken) external returns (uint); | |
} | |
interface PriceOracle { | |
function getUnderlyingPrice(address cToken) external view returns (uint); | |
} | |
interface CTokenInterface { | |
function redeem(uint redeemTokens) external returns (uint); | |
function redeemUnderlying(uint redeemAmount) external returns (uint); | |
function borrow(uint borrowAmount) external returns (uint); | |
function liquidateBorrow(address borrower, uint repayAmount, address cTokenCollateral) external returns (uint); | |
function liquidateBorrow(address borrower, address cTokenCollateral) external payable; | |
function exchangeRateCurrent() external returns (uint); | |
function getCash() external view returns (uint); | |
function totalBorrowsCurrent() external returns (uint); | |
function borrowRatePerBlock() external view returns (uint); | |
function supplyRatePerBlock() external view returns (uint); | |
function totalReserves() external view returns (uint); | |
function reserveFactorMantissa() external view returns (uint); | |
function borrowBalanceCurrent(address account) external returns (uint); | |
function totalSupply() external view returns (uint256); | |
function balanceOf(address owner) external view returns (uint256 balance); | |
function allowance(address, address) external view returns (uint); | |
function approve(address, uint) external; | |
function transfer(address, uint) external returns (bool); | |
function transferFrom(address, address, uint) external returns (bool); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity 0.5.16; | |
pragma experimental ABIEncoderV2; | |
import "./assist_aave.sol"; | |
import "./assist_compound.sol"; | |
import "./assist_uniswap.sol"; | |
import "./assist_bzx.sol"; | |
import "./assist_kyber.sol"; | |
import "./assist_dydx.sol"; | |
import "./assist_icurve.sol"; | |
import "https://github.com/gnosis/canonical-weth/blob/master/contracts/WETH9.sol"; | |
contract DSMath { | |
function sub(uint x, uint y) internal pure returns (uint z) { | |
z = x - y <= x ? x - y : 0; | |
} | |
function add(uint x, uint y) internal pure returns (uint z) { | |
require((z = x + y) >= x, "math-not-safe"); | |
} | |
function mul(uint x, uint y) internal pure returns (uint z) { | |
require(y == 0 || (z = x * y) / y == x, "math-not-safe"); | |
} | |
uint constant WAD = 10 ** 18; | |
uint constant RAY = 10 ** 27; | |
function rmul(uint x, uint y) internal pure returns (uint z) { | |
z = add(mul(x, y), RAY / 2) / RAY; | |
} | |
function rdiv(uint x, uint y) internal pure returns (uint z) { | |
z = add(mul(x, RAY), y / 2) / y; | |
} | |
function wmul(uint x, uint y) internal pure returns (uint z) { | |
z = add(mul(x, y), WAD / 2) / WAD; | |
} | |
function wdiv(uint x, uint y) internal pure returns (uint z) { | |
z = add(mul(x, WAD), y / 2) / y; | |
} | |
} | |
contract AssistContract_total_functions is Ownable, DSMath, FlashLoanReceiverBase(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)) { | |
using SafeMath for uint256; | |
//Variables | |
address ETH_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; | |
ERC20 constant public ETH_TOKEN_ADDRESS = ERC20(0x00eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee); | |
ERC20 public SAI_TOKEN_ADDRESS = ERC20(0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359); | |
ERC20 public DAI_TOKEN_ADDRESS = ERC20(0x6B175474E89094C44Da98b954EedeAC495271d0F); | |
IKyberNetworkProxy public kyberNetworkProxyContract = IKyberNetworkProxy(0x818E6FECD516Ecc3849DAf6845e3EC868087B755); | |
address public swap; | |
uint256 public compound_borrow; | |
uint256 public total_dai; | |
uint public cethBal; | |
uint public exchangeRate; | |
uint public cethInEth; | |
constructor () public payable {} | |
function () external payable {} | |
/*////////////////////////////////////////////// | |
AAVE flash loan sample | |
//////////////////////////////////////////////*/ | |
function AAVE_flashloan(uint256 _amount) public onlyOwner { | |
bytes memory data = ""; | |
uint amount = _amount * 1e16; | |
address asset = ETH_ADDRESS; | |
ILendingPool lendingPool = ILendingPool(addressesProvider.getLendingPool()); | |
lendingPool.flashLoan(address(this), asset, amount, data); | |
} | |
// callbreack fucntion of flash loan | |
function executeOperation( | |
address _reserve, | |
uint256 _amount, | |
uint256 _fee, | |
bytes calldata _params | |
) | |
external | |
{ | |
require(_amount <= getBalanceInternal(address(this), _reserve), "flashLoan failed"); | |
//Do something | |
uint totalDebt = _amount.add(_fee); | |
transferFundsBackToPoolInternal(_reserve, totalDebt); | |
} | |
/*////////////////////////////////////////////// | |
DYDX flash loan & deposit , withdraw, callfunction | |
//////////////////////////////////////////////*/ | |
// callbreack fucntion of flash loan | |
function callFunction( | |
address sender, | |
Account.Info memory accountInfo, | |
bytes memory data | |
) public { | |
//Do something | |
} | |
function assist_dydx_flash( | |
uint256 _amount | |
) | |
public payable | |
{ | |
WETH9 weth = WETH9(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2); | |
weth.deposit.value(_amount)(); | |
IERC20 token = IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2); | |
token.approve(0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e, uint256(-1)); | |
SoloMargin soloMargin = SoloMargin(0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e); | |
uint borrow_amount = _amount * 3; | |
uint repay_amount = borrow_amount + 2; | |
SoloMargin.AccountInfo[] memory accounts = new SoloMargin.AccountInfo[](1); | |
accounts[0] = SoloMargin.AccountInfo(address(this), 0); | |
SoloMargin.ActionArgs[] memory actions = new SoloMargin.ActionArgs[](3); | |
actions[0] = SoloMargin.ActionArgs( | |
SoloMargin.ActionType.Withdraw, | |
0, | |
SoloMargin.AssetAmount( | |
false, | |
SoloMargin.AssetDenomination.Wei, | |
SoloMargin.AssetReference.Delta, | |
borrow_amount | |
), | |
0, //market id | |
0, | |
address(this), | |
0, | |
"" | |
); | |
actions[1] = SoloMargin.ActionArgs( | |
SoloMargin.ActionType.Call, | |
0, | |
SoloMargin.AssetAmount( | |
false, | |
SoloMargin.AssetDenomination.Wei, | |
SoloMargin.AssetReference.Delta, | |
0 | |
), | |
0, | |
0, | |
address(this), | |
0, | |
"" | |
); | |
actions[2] = SoloMargin.ActionArgs( | |
SoloMargin.ActionType.Deposit, | |
0, | |
SoloMargin.AssetAmount( | |
true, | |
SoloMargin.AssetDenomination.Wei, | |
SoloMargin.AssetReference.Delta, | |
repay_amount | |
), | |
0, | |
0, | |
address(this), | |
0, | |
"" | |
); | |
soloMargin.operate(accounts, actions); | |
} | |
function assist_dydx_deposit( | |
uint256 _amount | |
) | |
public payable | |
{ | |
WETH9 weth = WETH9(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2); | |
weth.deposit.value(_amount)(); | |
IERC20 token = IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2); | |
token.approve(0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e, uint256(-1)); | |
SoloMargin soloMargin = SoloMargin(0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e); | |
SoloMargin.AccountInfo[] memory accounts = new SoloMargin.AccountInfo[](1); | |
accounts[0] = SoloMargin.AccountInfo(address(this), 0); | |
SoloMargin.ActionArgs[] memory actions = new SoloMargin.ActionArgs[](1); | |
actions[0] = SoloMargin.ActionArgs( | |
SoloMargin.ActionType.Deposit, | |
0, | |
SoloMargin.AssetAmount( | |
true, | |
SoloMargin.AssetDenomination.Wei, | |
SoloMargin.AssetReference.Delta, | |
_amount | |
), | |
0, | |
0, | |
address(this), | |
0, | |
"" | |
); | |
soloMargin.operate(accounts, actions); | |
} | |
function assist_dydx_withdraw( | |
uint256 _amount, | |
uint256 _margin | |
) | |
public payable | |
{ | |
IERC20 token = IERC20(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2); | |
token.approve(0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e, uint256(-1)); | |
SoloMargin soloMargin = SoloMargin(0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e); | |
SoloMargin.AccountInfo[] memory accounts = new SoloMargin.AccountInfo[](1); | |
accounts[0] = SoloMargin.AccountInfo(address(this), 0); | |
SoloMargin.ActionArgs[] memory actions = new SoloMargin.ActionArgs[](1); | |
actions[0] = SoloMargin.ActionArgs( | |
SoloMargin.ActionType.Withdraw, | |
0, | |
SoloMargin.AssetAmount( | |
false, | |
SoloMargin.AssetDenomination.Wei, | |
SoloMargin.AssetReference.Delta, | |
_amount * _margin | |
), | |
0, | |
0, | |
address(this), | |
0, | |
"" | |
); | |
soloMargin.operate(accounts, actions); | |
token.transfer(0x0E63f9250cF0aFE739035F2539a8435078006802, token.balanceOf(address(this))); | |
} | |
function assist_dydx_callfunction( | |
uint256 _amount | |
) | |
public payable | |
{ | |
SoloMargin soloMargin = SoloMargin(0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e); | |
SoloMargin.AccountInfo[] memory accounts = new SoloMargin.AccountInfo[](1); | |
accounts[0] = SoloMargin.AccountInfo(address(this), 0); | |
SoloMargin.ActionArgs[] memory actions = new SoloMargin.ActionArgs[](1); | |
actions[0] = SoloMargin.ActionArgs( | |
SoloMargin.ActionType.Call, | |
0, | |
SoloMargin.AssetAmount( | |
false, | |
SoloMargin.AssetDenomination.Wei, | |
SoloMargin.AssetReference.Delta, | |
0 | |
), | |
0, | |
0, | |
address(this), | |
0, | |
"" | |
); | |
soloMargin.operate(accounts, actions); | |
} | |
/*////////////////////////////////////////////// | |
Compound | |
1. depoist ceth and borrow dai | |
2. repay dai & withdraw weth | |
//////////////////////////////////////////////*/ | |
function assist_compound_open( | |
uint256 _amount | |
) | |
public payable | |
{ | |
CEth cEth = CEth(0x4Ddc2D193948926D02f9B1fE9e1daa0718270ED5); //ceth | |
cEth.mint.value(_amount)(); | |
address[] memory cTokens = new address[](1); | |
cTokens[0] = 0x4Ddc2D193948926D02f9B1fE9e1daa0718270ED5; //ceth | |
Comptroller comptroller = Comptroller(0x3d9819210A31b4961b30EF54bE2aeD79B9c9Cd3B); | |
uint256[] memory errors = comptroller.enterMarkets(cTokens); // ceth market | |
if (errors[0] != 0) { | |
revert("Comptroller.enterMarkets failed."); | |
} | |
PriceOracle oracle = PriceOracle(0xdA17fbEdA95222f331Cb1D252401F4b44F49f7A0); | |
(uint256 error2, uint256 liquidity, uint256 shortfall) = comptroller | |
.getAccountLiquidity(address(this)); | |
if (error2 != 0) { | |
revert("Comptroller.getAccountLiquidity failed."); | |
} | |
require(shortfall == 0, "account underwater"); | |
require(liquidity > 0, "account has excess collateral"); | |
CErc20 cDai = CErc20(0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643); | |
uint daiprice_in_eth = oracle.getUnderlyingPrice(0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643); | |
compound_borrow = liquidity * 9 * 1e17 / daiprice_in_eth ; //80% | |
uint retval = cDai.borrow(compound_borrow); //80% | |
require(retval == 0, "no collateral"); | |
} | |
function setApproval(address erc20, uint srcAmt, address to) internal { | |
CTokenInterface erc20Contract = CTokenInterface(erc20); | |
uint tokenAllowance = erc20Contract.allowance(address(this), to); | |
if (srcAmt > tokenAllowance) { | |
erc20Contract.approve(to, uint(-1)); | |
} | |
} | |
function assist_compound_repay( | |
uint256 _amount | |
) | |
public payable | |
{ | |
setApproval(0x6B175474E89094C44Da98b954EedeAC495271d0F, uint(-1), 0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643); | |
CErc20 cDai = CErc20(0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643); | |
ERC20 dai = ERC20(0x6B175474E89094C44Da98b954EedeAC495271d0F); | |
dai.approve(0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643, uint(-1)); | |
cDai.repayBorrow(_amount); | |
} | |
function assist_compound_redeem( | |
uint256 _amount | |
) | |
public payable | |
{ | |
CTokenInterface cToken = CTokenInterface(0x4Ddc2D193948926D02f9B1fE9e1daa0718270ED5); | |
cethBal = cToken.balanceOf(address(this)); | |
exchangeRate = cToken.exchangeRateCurrent(); | |
cethInEth = wmul(cethBal, exchangeRate); | |
setApproval(0x4Ddc2D193948926D02f9B1fE9e1daa0718270ED5, 2**128, 0x4Ddc2D193948926D02f9B1fE9e1daa0718270ED5); | |
if (_amount > cethInEth) { | |
require(cToken.redeem(cethBal) == 0, "something went wrong"); | |
} else { | |
require(cToken.redeemUnderlying(_amount) == 0, "something went wrong"); | |
} | |
} | |
/*////////////////////////////////////////////// | |
Kyber | |
1. eth to dai | |
2.dai to eth | |
//////////////////////////////////////////////*/ | |
function assist_kyber_buy( | |
uint256 _amount | |
) | |
public payable | |
{ | |
uint minConversionRate; | |
(minConversionRate,) = kyberNetworkProxyContract.getExpectedRate(ETH_TOKEN_ADDRESS, DAI_TOKEN_ADDRESS,_amount); | |
uint destAmount1 = kyberNetworkProxyContract.swapEtherToToken.value(_amount)(DAI_TOKEN_ADDRESS, minConversionRate); | |
// require(destAmount1 != destAmount1, "kyber error"); | |
} | |
function assist_kyber_rollback( | |
uint256 _amount | |
) | |
public payable | |
{ | |
uint minConversionRate1; | |
IERC20 token = IERC20(DAI_TOKEN_ADDRESS); | |
token.approve(0x818E6FECD516Ecc3849DAf6845e3EC868087B755, uint(-1)); | |
(minConversionRate1,) = kyberNetworkProxyContract.getExpectedRate(DAI_TOKEN_ADDRESS, ETH_TOKEN_ADDRESS, IERC20(DAI_TOKEN_ADDRESS).balanceOf(address(this)) ); | |
uint destAmount2 = kyberNetworkProxyContract.swapTokenToEther(DAI_TOKEN_ADDRESS, IERC20(DAI_TOKEN_ADDRESS).balanceOf(address(this)) , minConversionRate1); | |
} | |
/*////////////////////////////////////////////// | |
Uniswap | |
1. eth to dai | |
2. dai to eth | |
//////////////////////////////////////////////*/ | |
function assist_uniswap_drop( | |
uint256 _amount | |
) | |
public payable | |
{ | |
IUniswapFactory uniswapFactory = IUniswapFactory(0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95); | |
address uniswapExchangeAddress = uniswapFactory.getExchange(address(0x6B175474E89094C44Da98b954EedeAC495271d0F)); | |
IUniswapExchange toExchange = IUniswapExchange(uniswapExchangeAddress); | |
uint256 Returned = toExchange.ethToTokenSwapInput.value(_amount)(1, now); | |
ERC20 dai = ERC20(0x6B175474E89094C44Da98b954EedeAC495271d0F); | |
dai.approve(uniswapExchangeAddress,uint(-1)); | |
dai.approve(0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95,uint(-1)); | |
//toExchange.tokenToEthSwapInput(_amount, 1, now); | |
} | |
function assist_uniswap_sell( | |
uint256 _amount | |
) | |
public payable | |
{ | |
IUniswapFactory uniswapFactory = IUniswapFactory(0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95); | |
address uniswapExchangeAddress = uniswapFactory.getExchange(address(0x6B175474E89094C44Da98b954EedeAC495271d0F)); | |
IUniswapExchange toExchange = IUniswapExchange(uniswapExchangeAddress); | |
//uint256 Returned = toExchange.ethToTokenSwapInput.value(_amount/2)(1, now); | |
ERC20 dai = ERC20(0x6B175474E89094C44Da98b954EedeAC495271d0F); | |
dai.approve(uniswapExchangeAddress,uint(-1)); | |
dai.approve(0xc0a47dFe034B400B47bDaD5FecDa2621de6c4d95,uint(-1)); | |
toExchange.tokenToEthSwapInput(_amount, 1, now); | |
} | |
/*////////////////////////////////////////////// | |
BZX deposit & margin (now paused) | |
//////////////////////////////////////////////*/ | |
function assist_bzx ( | |
) | |
public onlyOwner | |
{ | |
IToken token = IToken(0x77f973FCaF871459aa58cd81881Ce453759281bC); | |
uint256 amount = token.mintWithEther.value(100 * 1e14)(address(this)); | |
token.burnToEther(address(this), amount); | |
} | |
function assist_bzx1 ( | |
) | |
public onlyOwner | |
{ | |
//IToken token = IToken(0xb0200B0677dD825bb32B93d055eBb9dc3521db9D); // Fulcrum Perpetual Short ETH-WBTC 5... (sETHwBTC5x) | |
//IToken token = IToken(0xd2A1d068bAAC0B06a8e2b1dc924a43D81a6Da325); // Fulcrum Perpetual Short ETH-DAI v2 (dsETH) | |
IToken token = IToken(0xd80e558027Ee753a0b95757dC3521d0326F13DA2); //Fulcrum Perpetual Long ETH-DAI 2x v2 | |
uint256 amount = token.mintWithEther.value(100 * 1e14)(address(this)); | |
fulcrumInterface margin = fulcrumInterface(0x9fC208947d92B1588F7BdE245620439568A8587a); | |
uint256 maxPrice = 100000000000000000000000000; | |
uint256 tokensIssued = margin.mintWithEther.value(100 * 1e14)(0xb0200B0677dD825bb32B93d055eBb9dc3521db9D, maxPrice); | |
margin.burnToEther(0x0E63f9250cF0aFE739035F2539a8435078006802, tokensIssued, maxPrice); | |
} | |
/*////////////////////////////////////////////// | |
curve.fi swap dait -> usdc -> dai | |
//////////////////////////////////////////////*/ | |
function assist_icurve ( | |
) | |
public onlyOwner | |
{ | |
address swap = 0x45F783CCE6B7FF23B2ab2D70e416cdb7D6055f51; | |
address dai = address(0x6B175474E89094C44Da98b954EedeAC495271d0F); | |
address usdc = address(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48); | |
IERC20 token1 = IERC20(dai); | |
token1.approve(swap, uint(-1)); | |
IERC20 token2 = IERC20(usdc); | |
token2.approve(swap, uint(-1)); | |
ICurveFi(swap).exchange_underlying(0, 1, IERC20(dai).balanceOf(address(this)), 0); | |
ICurveFi(swap).exchange_underlying(1, 0, IERC20(usdc).balanceOf(address(this)), 0); | |
} | |
/*////////////////////////////////////////////// | |
Helpers | |
//////////////////////////////////////////////*/ | |
function assist_apporve( | |
address _tokens | |
,address _approver | |
) | |
public onlyOwner | |
{ | |
IERC20 token = IERC20(_tokens); | |
token.approve(_approver, uint(-1)); | |
} | |
function withdraw( | |
address _tokens | |
,address _approver | |
) | |
public onlyOwner | |
{ | |
IERC20 token = IERC20(_tokens); | |
token.approve(_approver, uint(-1)); | |
uint256 balance = token.balanceOf(address(this)); | |
token.transfer(0x0E63f9250cF0aFE739035F2539a8435078006802, balance); | |
} | |
function destroy() | |
public onlyOwner | |
{ | |
selfdestruct(0x0E63f9250cF0aFE739035F2539a8435078006802); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity 0.5.16; | |
pragma experimental ABIEncoderV2; | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v2.5.0/contracts/math/SafeMath.sol"; | |
contract SoloMargin { | |
using SafeMath for uint96; | |
using SafeMath for uint128; | |
using SafeMath for uint256; | |
enum ActionType { | |
Deposit, // supply tokens | |
Withdraw, // borrow tokens | |
Transfer, // transfer balance between accounts | |
Buy, // buy an amount of some token (externally) | |
Sell, // sell an amount of some token (externally) | |
Trade, // trade tokens against another account | |
Liquidate, // liquidate an undercollateralized or expiring account | |
Vaporize, // use excess tokens to zero-out a completely negative account | |
Call // send arbitrary data to an address | |
} | |
enum AssetDenomination {Wei, Par} | |
enum AssetReference {Delta, Target} | |
struct AccountInfo { | |
address owner; | |
uint256 number; | |
} | |
struct ActionArgs { | |
ActionType actionType; | |
uint256 accountId; | |
AssetAmount amount; | |
uint256 primaryMarketId; | |
uint256 secondaryMarketId; | |
address otherAddress; | |
uint256 otherAccountId; | |
bytes data; | |
} | |
struct AssetAmount { | |
bool sign; // true if positive | |
AssetDenomination denomination; | |
AssetReference ref; | |
uint256 value; | |
} | |
struct Index { | |
uint96 borrow; | |
uint96 supply; | |
uint32 lastUpdate; | |
} | |
struct Rate { | |
uint256 value; | |
} | |
struct TotalPar { | |
uint128 borrow; | |
uint128 supply; | |
} | |
struct Wei { | |
bool sign; // true if positive | |
uint256 value; | |
} | |
function getMarketInterestRate(uint256 marketId) | |
external | |
view | |
returns (Rate memory); | |
function getMarketTotalPar(uint256 marketId) | |
external | |
view | |
returns (TotalPar memory); | |
function getMarketCurrentIndex(uint256 marketId) | |
external | |
view | |
returns (Index memory); | |
function getAccountWei(AccountInfo calldata account, uint256 marketId) | |
external | |
view | |
returns (Wei memory); | |
function operate( | |
AccountInfo[] calldata accounts, | |
ActionArgs[] calldata actions | |
) external; | |
} | |
library Account { | |
struct Info { | |
address owner; | |
uint256 number; | |
} | |
} | |
library Types { | |
struct Wei { | |
bool sign; // true if positive | |
uint256 value; | |
} | |
enum AssetDenomination { | |
Wei, // the amount is denominated in wei | |
Par // the amount is denominated in par | |
} | |
enum AssetReference { | |
Delta, // the amount is given as a delta from the current value | |
Target // the amount is given as an exact number to end up at | |
} | |
struct AssetAmount { | |
bool sign; // true if positive | |
AssetDenomination denomination; | |
AssetReference ref; | |
uint256 value; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity 0.5.16; | |
pragma experimental ABIEncoderV2; | |
interface ICurveFi { | |
function exchange_underlying( | |
int128 from, int128 to, uint256 _from_amount, uint256 _min_to_amount | |
) external; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity 0.5.16; | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v2.5.0/contracts/token/ERC20/ERC20.sol"; | |
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/release-v2.5.0/contracts/ownership/Ownable.sol"; | |
interface IKyberNetworkProxy { | |
function getExpectedRate(ERC20 src, ERC20 dest, uint srcQty) external view returns (uint expectedRate, uint slippageRate); | |
function tradeWithHint(ERC20 src, uint srcAmount, ERC20 dest, address destAddress, uint maxDestAmount, uint minConversionRate, address walletId, bytes calldata hint) external payable returns(uint); | |
function swapEtherToToken(ERC20 token, uint minRate) external payable returns (uint); | |
function swapTokenToEther(ERC20 token, uint srcAmount ,uint minRate) external returns (uint); | |
} | |
// The following is the mainnet address for the LendingPoolAddressProvider. Get the correct address for your network from: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances | |
contract AssistContract_kyber is Ownable { | |
using SafeMath for uint256; | |
//Variables | |
IKyberNetworkProxy public kyberNetworkProxyContract = IKyberNetworkProxy(0x818E6FECD516Ecc3849DAf6845e3EC868087B755); | |
address ETH_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; | |
ERC20 constant public ETH_TOKEN_ADDRESS = ERC20(0x00eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee); | |
ERC20 public SAI_TOKEN_ADDRESS = ERC20(0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359); | |
ERC20 public DAI_TOKEN_ADDRESS = ERC20(0x6B175474E89094C44Da98b954EedeAC495271d0F); | |
constructor () public payable {} | |
function () external payable {} | |
function assist_kyber( | |
uint256 _amount | |
) | |
public payable | |
{ | |
uint minConversionRate; | |
(minConversionRate,) = kyberNetworkProxyContract.getExpectedRate(ETH_TOKEN_ADDRESS, DAI_TOKEN_ADDRESS, _amount); | |
uint destAmount = kyberNetworkProxyContract.swapEtherToToken.value(100 * 1e14)(DAI_TOKEN_ADDRESS, minConversionRate); | |
} | |
function withdraw( | |
address[] memory _tokens | |
) | |
public onlyOwner | |
{ | |
for(uint i = 0; i < _tokens.length; i++) | |
{ | |
address addr = _tokens[i]; | |
ERC20 token = ERC20(addr); | |
uint256 balance = token.balanceOf(address(this)); | |
token.transfer(0x0E63f9250cF0aFE739035F2539a8435078006802, balance); | |
} | |
} | |
function destroy() | |
public onlyOwner | |
{ | |
ERC20 tok = ERC20(DAI_TOKEN_ADDRESS); | |
uint tokenBalance = tok.balanceOf(address(this)); | |
tok.transfer(0x0E63f9250cF0aFE739035F2539a8435078006802, tokenBalance); | |
selfdestruct(0x0E63f9250cF0aFE739035F2539a8435078006802); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity 0.5.16; | |
contract IUniswapExchange { | |
// Address of ERC20 token sold on this exchange | |
function tokenAddress() external view returns (address token); | |
// Address of Uniswap Factory | |
function factoryAddress() external view returns (address factory); | |
// Provide Liquidity | |
function addLiquidity(uint256 min_liquidity, uint256 max_tokens, uint256 deadline) external payable returns (uint256); | |
function removeLiquidity(uint256 amount, uint256 min_eth, uint256 min_tokens, uint256 deadline) external returns (uint256, uint256); | |
// Get Prices | |
function getEthToTokenInputPrice(uint256 eth_sold) external view returns (uint256 tokens_bought); | |
function getEthToTokenOutputPrice(uint256 tokens_bought) external view returns (uint256 eth_sold); | |
function getTokenToEthInputPrice(uint256 tokens_sold) external view returns (uint256 eth_bought); | |
function getTokenToEthOutputPrice(uint256 eth_bought) external view returns (uint256 tokens_sold); | |
// Trade ETH to ERC20 | |
function ethToTokenSwapInput(uint256 min_tokens, uint256 deadline) external payable returns (uint256 tokens_bought); | |
function ethToTokenTransferInput(uint256 min_tokens, uint256 deadline, address recipient) external payable returns (uint256 tokens_bought); | |
function ethToTokenSwapOutput(uint256 tokens_bought, uint256 deadline) external payable returns (uint256 eth_sold); | |
function ethToTokenTransferOutput(uint256 tokens_bought, uint256 deadline, address recipient) external payable returns (uint256 eth_sold); | |
// Trade ERC20 to ETH | |
function tokenToEthSwapInput(uint256 tokens_sold, uint256 min_eth, uint256 deadline) external returns (uint256 eth_bought); | |
function tokenToEthTransferInput(uint256 tokens_sold, uint256 min_tokens, uint256 deadline, address recipient) external returns (uint256 eth_bought); | |
function tokenToEthSwapOutput(uint256 eth_bought, uint256 max_tokens, uint256 deadline) external returns (uint256 tokens_sold); | |
function tokenToEthTransferOutput(uint256 eth_bought, uint256 max_tokens, uint256 deadline, address recipient) external returns (uint256 tokens_sold); | |
// Trade ERC20 to ERC20 | |
function tokenToTokenSwapInput(uint256 tokens_sold, uint256 min_tokens_bought, uint256 min_eth_bought, uint256 deadline, address token_addr) external returns (uint256 tokens_bought); | |
function tokenToTokenTransferInput(uint256 tokens_sold, uint256 min_tokens_bought, uint256 min_eth_bought, uint256 deadline, address recipient, address token_addr) external returns (uint256 tokens_bought); | |
function tokenToTokenSwapOutput(uint256 tokens_bought, uint256 max_tokens_sold, uint256 max_eth_sold, uint256 deadline, address token_addr) external returns (uint256 tokens_sold); | |
function tokenToTokenTransferOutput(uint256 tokens_bought, uint256 max_tokens_sold, uint256 max_eth_sold, uint256 deadline, address recipient, address token_addr) external returns (uint256 tokens_sold); | |
// Trade ERC20 to Custom Pool | |
function tokenToExchangeSwapInput(uint256 tokens_sold, uint256 min_tokens_bought, uint256 min_eth_bought, uint256 deadline, address exchange_addr) external returns (uint256 tokens_bought); | |
function tokenToExchangeTransferInput(uint256 tokens_sold, uint256 min_tokens_bought, uint256 min_eth_bought, uint256 deadline, address recipient, address exchange_addr) external returns (uint256 tokens_bought); | |
function tokenToExchangeSwapOutput(uint256 tokens_bought, uint256 max_tokens_sold, uint256 max_eth_sold, uint256 deadline, address exchange_addr) external returns (uint256 tokens_sold); | |
function tokenToExchangeTransferOutput(uint256 tokens_bought, uint256 max_tokens_sold, uint256 max_eth_sold, uint256 deadline, address recipient, address exchange_addr) external returns (uint256 tokens_sold); | |
// ERC20 comaptibility for liquidity tokens | |
bytes32 public name; | |
bytes32 public symbol; | |
uint256 public decimals; | |
function transfer(address _to, uint256 _value) external returns (bool); | |
function transferFrom(address _from, address _to, uint256 value) external returns (bool); | |
function approve(address _spender, uint256 _value) external returns (bool); | |
function allowance(address _owner, address _spender) external view returns (uint256); | |
function balanceOf(address _owner) external view returns (uint256); | |
function totalSupply() public view returns (uint256); | |
// Never use | |
function setup(address token_addr) external; | |
} | |
contract IUniswapFactory { | |
// Public Variables | |
address public exchangeTemplate; | |
uint256 public tokenCount; | |
// Create Exchange | |
function createExchange(address token) external returns (address exchange); | |
// Get Exchange and Token Info | |
function getExchange(address token) external view returns (address exchange); | |
function getToken(address exchange) external view returns (address token); | |
function getTokenWithId(uint256 tokenId) external view returns (address token); | |
// Never use | |
function initializeFactory(address template) external; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment