Created
July 27, 2020 17:36
-
-
Save rori4/ce1858e7f9dde337ce113b36a07185b0 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.17+commit.d19bba13.js&optimize=false&gist=
This file contains hidden or 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.4.22 <0.7.0; | |
| /** | |
| * @title Storage | |
| * @dev Store & retreive value in a variable | |
| */ | |
| contract Storage { | |
| uint256 number; | |
| /** | |
| * @dev Store value in variable | |
| * @param num value to store | |
| */ | |
| function store(uint256 num) public { | |
| number = num; | |
| } | |
| /** | |
| * @dev Return value | |
| * @return value of 'number' | |
| */ | |
| function retreive() public view returns (uint256){ | |
| return number; | |
| } | |
| } |
This file contains hidden or 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.4.22 <0.7.0; | |
| /** | |
| * @title Owner | |
| * @dev Set & change owner | |
| */ | |
| contract Owner { | |
| address private owner; | |
| // event for EVM logging | |
| event OwnerSet(address indexed oldOwner, address indexed newOwner); | |
| // modifier to check if caller is owner | |
| modifier isOwner() { | |
| // If the first argument of 'require' evaluates to 'false', execution terminates and all | |
| // changes to the state and to Ether balances are reverted. | |
| // This used to consume all gas in old EVM versions, but not anymore. | |
| // It is often a good idea to use 'require' to check if functions are called correctly. | |
| // As a second argument, you can also provide an explanation about what went wrong. | |
| require(msg.sender == owner, "Caller is not owner"); | |
| _; | |
| } | |
| /** | |
| * @dev Set contract deployer as owner | |
| */ | |
| constructor() public { | |
| owner = msg.sender; // 'msg.sender' is sender of current call, contract deployer for a constructor | |
| emit OwnerSet(address(0), owner); | |
| } | |
| /** | |
| * @dev Change owner | |
| * @param newOwner address of new owner | |
| */ | |
| function changeOwner(address newOwner) public isOwner { | |
| emit OwnerSet(owner, newOwner); | |
| owner = newOwner; | |
| } | |
| /** | |
| * @dev Return owner address | |
| * @return address of owner | |
| */ | |
| function getOwner() external view returns (address) { | |
| return owner; | |
| } | |
| } |
This file contains hidden or 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.4.22 <0.7.0; | |
| /** | |
| * @title Ballot | |
| * @dev Implements voting process along with vote delegation | |
| */ | |
| contract Ballot { | |
| struct Voter { | |
| uint weight; // weight is accumulated by delegation | |
| bool voted; // if true, that person already voted | |
| address delegate; // person delegated to | |
| uint vote; // index of the voted proposal | |
| } | |
| struct Proposal { | |
| // If you can limit the length to a certain number of bytes, | |
| // always use one of bytes1 to bytes32 because they are much cheaper | |
| bytes32 name; // short name (up to 32 bytes) | |
| uint voteCount; // number of accumulated votes | |
| } | |
| address public chairperson; | |
| mapping(address => Voter) public voters; | |
| Proposal[] public proposals; | |
| /** | |
| * @dev Create a new ballot to choose one of 'proposalNames'. | |
| * @param proposalNames names of proposals | |
| */ | |
| constructor(bytes32[] memory proposalNames) public { | |
| chairperson = msg.sender; | |
| voters[chairperson].weight = 1; | |
| for (uint i = 0; i < proposalNames.length; i++) { | |
| // 'Proposal({...})' creates a temporary | |
| // Proposal object and 'proposals.push(...)' | |
| // appends it to the end of 'proposals'. | |
| proposals.push(Proposal({ | |
| name: proposalNames[i], | |
| voteCount: 0 | |
| })); | |
| } | |
| } | |
| /** | |
| * @dev Give 'voter' the right to vote on this ballot. May only be called by 'chairperson'. | |
| * @param voter address of voter | |
| */ | |
| function giveRightToVote(address voter) public { | |
| require( | |
| msg.sender == chairperson, | |
| "Only chairperson can give right to vote." | |
| ); | |
| require( | |
| !voters[voter].voted, | |
| "The voter already voted." | |
| ); | |
| require(voters[voter].weight == 0); | |
| voters[voter].weight = 1; | |
| } | |
| /** | |
| * @dev Delegate your vote to the voter 'to'. | |
| * @param to address to which vote is delegated | |
| */ | |
| function delegate(address to) public { | |
| Voter storage sender = voters[msg.sender]; | |
| require(!sender.voted, "You already voted."); | |
| require(to != msg.sender, "Self-delegation is disallowed."); | |
| while (voters[to].delegate != address(0)) { | |
| to = voters[to].delegate; | |
| // We found a loop in the delegation, not allowed. | |
| require(to != msg.sender, "Found loop in delegation."); | |
| } | |
| sender.voted = true; | |
| sender.delegate = to; | |
| Voter storage delegate_ = voters[to]; | |
| if (delegate_.voted) { | |
| // If the delegate already voted, | |
| // directly add to the number of votes | |
| proposals[delegate_.vote].voteCount += sender.weight; | |
| } else { | |
| // If the delegate did not vote yet, | |
| // add to her weight. | |
| delegate_.weight += sender.weight; | |
| } | |
| } | |
| /** | |
| * @dev Give your vote (including votes delegated to you) to proposal 'proposals[proposal].name'. | |
| * @param proposal index of proposal in the proposals array | |
| */ | |
| function vote(uint proposal) public { | |
| Voter storage sender = voters[msg.sender]; | |
| require(sender.weight != 0, "Has no right to vote"); | |
| require(!sender.voted, "Already voted."); | |
| sender.voted = true; | |
| sender.vote = proposal; | |
| // If 'proposal' is out of the range of the array, | |
| // this will throw automatically and revert all | |
| // changes. | |
| proposals[proposal].voteCount += sender.weight; | |
| } | |
| /** | |
| * @dev Computes the winning proposal taking all previous votes into account. | |
| * @return winningProposal_ index of winning proposal in the proposals array | |
| */ | |
| function winningProposal() public view | |
| returns (uint winningProposal_) | |
| { | |
| uint winningVoteCount = 0; | |
| for (uint p = 0; p < proposals.length; p++) { | |
| if (proposals[p].voteCount > winningVoteCount) { | |
| winningVoteCount = proposals[p].voteCount; | |
| winningProposal_ = p; | |
| } | |
| } | |
| } | |
| /** | |
| * @dev Calls winningProposal() function to get the index of the winner contained in the proposals array and then | |
| * @return winnerName_ the name of the winner | |
| */ | |
| function winnerName() public view | |
| returns (bytes32 winnerName_) | |
| { | |
| winnerName_ = proposals[winningProposal()].name; | |
| } | |
| } |
This file contains hidden or 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
| //Mainent: 0x99f1b2247381bd89ed695c4b422d13557d9430d4 | |
| pragma solidity >=0.4.26; | |
| pragma experimental ABIEncoderV2; | |
| interface OrFeedInterface { | |
| function getExchangeRate ( string fromSymbol, string toSymbol, string venue, uint256 amount ) external view returns ( uint256 ); | |
| function getTokenDecimalCount ( address tokenAddress ) external view returns ( uint256 ); | |
| function getTokenAddress ( string symbol ) external view returns ( address ); | |
| function getSynthBytes32 ( string symbol ) external view returns ( bytes32 ); | |
| function getForexAddress ( string symbol ) external view returns ( address ); | |
| } | |
| library SafeMath { | |
| function mul(uint256 a, uint256 b) internal view returns(uint256) { | |
| uint256 c = a * b; | |
| assert(a == 0 || c / a == b); | |
| return c; | |
| } | |
| function div(uint256 a, uint256 b) internal view returns(uint256) { | |
| assert(b > 0); // Solidity automatically throws when dividing by 0 | |
| uint256 c = a / b; | |
| assert(a == b * c + a % b); // There is no case in which this doesn't hold | |
| return c; | |
| } | |
| function sub(uint256 a, uint256 b) internal view returns(uint256) { | |
| assert(b <= a); | |
| return a - b; | |
| } | |
| function add(uint256 a, uint256 b) internal view returns(uint256) { | |
| uint256 c = a + b; | |
| assert(c >= a); | |
| return c; | |
| } | |
| } | |
| contract ArbCalc{ | |
| OrFeedInterface orfeed = OrFeedInterface(0x8316b082621cfedab95bf4a44a1d4b64a6ffc336); | |
| address owner; | |
| modifier onlyOwner() { | |
| if (msg.sender != owner) { | |
| throw; | |
| } | |
| _; | |
| } | |
| constructor() public payable { | |
| owner = msg.sender; | |
| } | |
| function kill() onlyOwner{ | |
| selfdestruct(owner); | |
| } | |
| function() payable{ | |
| } | |
| function arbCalc(uint8[] eOrder, string[] tOrder, uint256 amount, bool back ) public constant returns (uint256){ | |
| uint256 final1 = eOrder.length -1; | |
| uint lastSell = amount; | |
| for(uint i =0; i<eOrder.length; i++){ | |
| uint256 next = i+1; | |
| if(i < final1){ | |
| if(eOrder[i] ==1){ | |
| //kyber buy | |
| lastSell = orfeed.getExchangeRate(tOrder[i], tOrder[0], "KYBERBYSYMBOLV1", lastSell); | |
| } | |
| else if(eOrder[i] ==2){ | |
| lastSell = orfeed.getExchangeRate(tOrder[i], tOrder[next], "UNISWAPBYSYMBOLV1", lastSell); | |
| //lastSell = orfeed.getExchangeRate(tOrder[i], tOrder[next], "BUY-UNISWAP-EXCHANGE", lastSell); | |
| } | |
| else if(eOrder[i] ==4){ | |
| lastSell = orfeed.getExchangeRate(tOrder[i], tOrder[next], "UNISWAPBYSYMBOLV2", lastSell); | |
| // lastSell = swapTokenOnUniswapCalc(tOrder[i], lastSell, tOrder[0]); | |
| } | |
| else{ | |
| lastSell = orfeed.getExchangeRate(tOrder[i], tOrder[next], "BANCOR", lastSell); | |
| } | |
| } | |
| else{ | |
| //sell | |
| if(back ==true){ | |
| if(eOrder[i] ==1){ | |
| //kyber buy | |
| lastSell = orfeed.getExchangeRate(tOrder[i], tOrder[0], "KYBERBYSYMBOLV1", lastSell); | |
| //lastSell = swapTokenOnKyberCalc(tOrder[i], lastSell, tOrder[0]); | |
| } | |
| else if(eOrder[i] ==2){ | |
| lastSell = orfeed.getExchangeRate(tOrder[i], tOrder[0], "UNISWAPBYSYMBOLV1", lastSell); | |
| // lastSell = swapTokenOnUniswapCalc(tOrder[i], lastSell, tOrder[0]); | |
| } | |
| else if(eOrder[i] ==4){ | |
| lastSell = orfeed.getExchangeRate(tOrder[i], tOrder[0], "UNISWAPBYSYMBOLV2", lastSell); | |
| // lastSell = swapTokenOnUniswapCalc(tOrder[i], lastSell, tOrder[0]); | |
| } | |
| else{ | |
| lastSell = orfeed.getExchangeRate(tOrder[i], tOrder[0], "BANCOR", lastSell); | |
| //lastSell = bancorConvert2Calc(tOrder[0], tOrder[i], lastSell); | |
| } | |
| } | |
| } | |
| } | |
| return lastSell; | |
| } | |
| } |
This file contains hidden or 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.0; | |
| 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"; | |
| //DAI ADDRESS: 0xFf795577d9AC8bD7D90Ee22b6C1703490b6512FD | |
| // PROVIDER ADDRESS: 0x506B0B2CF20FAA8f38a4E2B524EE43e1f4458Cc5 | |
| // 1000 dai = 1000000000000000000000 (Due to 18 decimal number) | |
| contract MyfirstFlashLoan is FlashLoanReceiverBase(address(0x506B0B2CF20FAA8f38a4E2B524EE43e1f4458Cc5)) { | |
| function flashLoan(uint256 newamount, address _token) external { | |
| bytes memory _params = "0x0"; | |
| address exchangeAddress = addressesProvider.getLendingPool(); | |
| ILendingPool exchange = ILendingPool(exchangeAddress); | |
| exchange.flashLoan(address(this), _token, newamount, _params); | |
| } | |
| function executeOperation( | |
| address _reserve, | |
| uint256 _amount, | |
| uint256 _fee, | |
| bytes calldata _params | |
| ) external { | |
| // INSERT YOUR USE CASE HERE | |
| uint256 totalDebt = _amount.add(_fee); | |
| transferFundsBackToPoolInternal(_reserve, totalDebt); | |
| } | |
| } |
This file contains hidden or 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.0; | |
| pragma experimental ABIEncoderV2; | |
| 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"; | |
| import "https://github.com/mrdavey/ez-flashloan/blob/remix/contracts/utils/Withdrawable.sol"; | |
| interface OrFeedInterface { | |
| function getExchangeRate ( string calldata fromSymbol, string calldata toSymbol, string calldata venue, uint256 amount ) external view returns ( uint256 ); | |
| function getTokenDecimalCount ( address tokenAddress ) external view returns ( uint256 ); | |
| function getTokenAddress ( string calldata symbol ) external view returns ( address ); | |
| function getSynthBytes32 ( string calldata symbol ) external view returns ( bytes32 ); | |
| function getForexAddress ( string calldata symbol ) external view returns ( address ); | |
| function arb(address fundsReturnToAddress, address liquidityProviderContractAddress, string[] calldata tokens, uint256 amount, string[] calldata exchanges) external payable returns (bool); | |
| } | |
| // LendingPoolAddressesProvider Kovan = 0x506B0B2CF20FAA8f38a4E2B524EE43e1f4458Cc5 | |
| // LendingPoolAddressesProvider Ropsten = 0x1c8756FD2B28e9426CDBDcC7E3c4d64fa9A54728 | |
| // LendingPoolAddressesProvider Mainnet = 0x24a42fD28C976A61Df5D00D0599C34c4f90748c8 | |
| // https://docs.aave.com/developers/deployed-contracts/deployed-contract-instances | |
| contract Flashloan is FlashLoanReceiverBase(address(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8)) { | |
| /** | |
| This function is called after your contract has received the flash loaned amount | |
| */ | |
| address orFeedAddress = 0x8316B082621CFedAB95bf4a44a1d4B64a6ffc336; | |
| function executeOperation( | |
| address _reserve, | |
| uint256 _amount, | |
| uint256 _fee, | |
| bytes calldata _params | |
| ) external { | |
| require(_amount <= getBalanceInternal(address(this), _reserve), "Invalid balance, was the flashLoan successful?"); | |
| // | |
| // Your logic goes here. | |
| // !! Ensure that *this contract* has enough of `_reserve` funds to payback the `_fee` !! | |
| // | |
| ERC20 asset = ERC20(_reserve); | |
| uint256 assetBalanceBeforeArb = asset.balanceOf(address(this)); | |
| ( | |
| string[] memory tokens, | |
| string[] memory exchanges | |
| ) = abi.decode(_params, (string[], string[])); | |
| // Orfeed arb is available only on mainnet | |
| OrFeedInterface orfeed= OrFeedInterface(orFeedAddress); | |
| orfeed.arb(address(this), address(this), tokens, _amount, exchanges); | |
| uint totalDebt = _amount.add(_fee); | |
| require(assetBalanceBeforeArb - totalDebt > 0, "No profit! Reverting"); | |
| transferFundsBackToPoolInternal(_reserve, totalDebt); | |
| } | |
| function flashloan(address _asset, uint256 _amount, bytes memory params) public onlyOwner { | |
| /** | |
| * Flash Loan of 1000 DAI | |
| */ | |
| address receiver = address(this); | |
| uint256 amount = _amount * 1e18; | |
| // If no params are needed, use an empty params: | |
| // Else encode the params like below (bytes encoded param of type `address` and `uint`) | |
| // bytes memory params = abi.encode(address(this), 1234); | |
| ILendingPool lendingPool = ILendingPool(addressesProvider.getLendingPool()); | |
| lendingPool.flashLoan(receiver, _asset, amount, params); | |
| } | |
| } |
This file contains hidden or 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.0; | |
| interface ILendingPool { | |
| function addressesProvider () external view returns ( address ); | |
| function deposit ( address _reserve, uint256 _amount, uint16 _referralCode ) external payable; | |
| function redeemUnderlying ( address _reserve, address _user, uint256 _amount ) external; | |
| function borrow ( address _reserve, uint256 _amount, uint256 _interestRateMode, uint16 _referralCode ) external; | |
| function repay ( address _reserve, uint256 _amount, address _onBehalfOf ) external payable; | |
| function swapBorrowRateMode ( address _reserve ) external; | |
| function rebalanceFixedBorrowRate ( address _reserve, address _user ) external; | |
| function setUserUseReserveAsCollateral ( address _reserve, bool _useAsCollateral ) external; | |
| function liquidationCall ( address _collateral, address _reserve, address _user, uint256 _purchaseAmount, bool _receiveAToken ) external payable; | |
| function flashLoan ( address _receiver, address _reserve, uint256 _amount, bytes calldata _params ) external; | |
| function getReserveConfigurationData ( address _reserve ) external view returns ( uint256 ltv, uint256 liquidationThreshold, uint256 liquidationDiscount, address interestRateStrategyAddress, bool usageAsCollateralEnabled, bool borrowingEnabled, bool fixedBorrowRateEnabled, bool isActive ); | |
| function getReserveData ( address _reserve ) external view returns ( uint256 totalLiquidity, uint256 availableLiquidity, uint256 totalBorrowsFixed, uint256 totalBorrowsVariable, uint256 liquidityRate, uint256 variableBorrowRate, uint256 fixedBorrowRate, uint256 averageFixedBorrowRate, uint256 utilizationRate, uint256 liquidityIndex, uint256 variableBorrowIndex, address aTokenAddress, uint40 lastUpdateTimestamp ); | |
| function getUserAccountData ( address _user ) external view returns ( uint256 totalLiquidityETH, uint256 totalCollateralETH, uint256 totalBorrowsETH, uint256 availableBorrowsETH, uint256 currentLiquidationThreshold, uint256 ltv, uint256 healthFactor ); | |
| function getUserReserveData ( address _reserve, address _user ) external view returns ( uint256 currentATokenBalance, uint256 currentUnderlyingBalance, uint256 currentBorrowBalance, uint256 principalBorrowBalance, uint256 borrowRateMode, uint256 borrowRate, uint256 liquidityRate, uint256 originationFee, uint256 variableBorrowIndex, uint256 lastUpdateTimestamp, bool usageAsCollateralEnabled ); | |
| function getReserves () external view; | |
| } |
This file contains hidden or 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
| // this line is added to create a gist. Empty file is not allowed. |
This file contains hidden or 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.4.26; | |
| interface ERC20 { | |
| function totalSupply() external view returns (uint supply); | |
| function balanceOf(address _owner) external view returns (uint balance); | |
| function transfer(address _to, uint _value) external returns (bool success); | |
| function transferFrom(address _from, address _to, uint _value) external returns (bool success); | |
| function approve(address _spender, uint _value) external returns (bool success); | |
| function allowance(address _owner, address _spender) external view returns (uint remaining); | |
| function decimals() external view returns(uint digits); | |
| event Approval(address indexed _owner, address indexed _spender, uint _value); | |
| } | |
| contract flashIt { | |
| function test() public returns(uint) { | |
| address test_addr = 0xFf795577d9AC8bD7D90Ee22b6C1703490b6512FD; | |
| ERC20 theToken = ERC20(test_addr); | |
| return theToken.balanceOf(this); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment