Created
June 5, 2020 22:19
-
-
Save anubhavgirdhar/d65fc16b96ef6587d49c5c7ce6660fac 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.6.6+commit.6c089d02.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.5.0; | |
import "./ParcelStorage.sol"; | |
contract Aave is ParcelStorage{ | |
function deposit(uint msgValue) external payable { | |
lendingPool.deposit.value(msgValue)(ethAddress,msgValue,referral); | |
} | |
function depositAndRedirect(uint msgValue,address receiver)external payable{ | |
lendingPool.deposit.value(msgValue)(ethAddress,msgValue,referral); | |
/// Instantiation of the aToken address | |
aToken aTokenInstance = aToken(0xD483B49F2d55D2c53D32bE6efF735cB001880F79); | |
/// transfer method call | |
aTokenInstance.redirectInterestStream(receiver); | |
} | |
} | |
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 LendingPool{ | |
function deposit(address _reserve, uint256 _amount, uint16 _referralCode) | |
external | |
payable; | |
} | |
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 aToken{ | |
function redirectInterestStream(address reciever) external; | |
} |
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 CtokenInterface { | |
function mint() external payable; | |
function transfer(address, uint256) external returns (bool); | |
function balanceOf(address owner) external view returns (uint256); | |
} | |
contract Zap { | |
address cEthAddress = 0xf92FbE0D3C0dcDAE407923b2Ac17eC223b1084E4; | |
CtokenInterface cEth = CtokenInterface(cEthAddress); | |
function deposit() external payable { | |
cEth.mint.value(msg.value)(); | |
} | |
struct EIP712Domain { | |
string name; | |
string version; | |
uint256 chainId; | |
address verifyingContract; | |
} | |
struct MetaTransaction { | |
address holder; | |
uint256 nonce; | |
} | |
mapping(address => uint256) public nonces; | |
bytes32 internal constant EIP712_DOMAIN_TYPEHASH = keccak256(bytes("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")); | |
bytes32 internal constant META_TRANSACTION_TYPEHASH = keccak256(bytes("MetaTransaction(address holder,uint256 nonce)")); | |
bytes32 internal DOMAIN_SEPARATOR = keccak256(abi.encode( | |
EIP712_DOMAIN_TYPEHASH, | |
keccak256(bytes("Compound-DApp")), | |
keccak256(bytes("1")), | |
42, // Kovan | |
address(this) | |
)); | |
// Withdraw with MetaTransaction | |
function withdraw(address userAddress, uint256 nonce,bytes32 r, bytes32 s, uint8 v) external payable{ | |
bytes32 digest = keccak256( | |
abi.encodePacked( | |
"\x19\x01", | |
DOMAIN_SEPARATOR, | |
keccak256(abi.encode(META_TRANSACTION_TYPEHASH,userAddress,nonce)))); | |
require(userAddress != address(0), "invalid-address-0"); | |
require(userAddress == ecrecover(digest, v, r, s), "invalid-signatures"); | |
cEth.mint.value(msg.value)(); | |
uint amount = cEth.balanceOf(address(this)); | |
cEth.transfer(userAddress, amount); | |
nonces[userAddress]++; | |
} | |
} |
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 "./ParcelStorage.sol"; | |
contract Compound is ParcelStorage{ | |
function deposit(uint msgValue)external payable { | |
cEth.mint.value(msgValue)(); | |
} | |
function depositAndBorrow(uint msgValue, uint daiValue) external payable { | |
cEth.mint.value(msgValue)(); | |
address[] memory toEnter = new address[](1); | |
toEnter[0] = cEthAddress; | |
comptroller.enterMarkets(toEnter); | |
cDai.borrow(daiValue); | |
} | |
function getHashDeposit(uint value)public pure returns(bytes memory){ | |
return abi.encodeWithSignature("deposit(uint256)",value); | |
} | |
function getHashBorrow(uint value)public pure returns(bytes memory){ | |
return abi.encodeWithSignature("depositAndBorrow(uint256)",value); | |
} | |
} | |
// 0.1 ether to depositAndBorrow | |
// ["0x0080e27881Cab07547F644C746ef8CA62750c95D"],["0x71c83ea5000000000000000000000000000000000000000000000000016345785d8a0000"] | |
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 comptrollerInterface{ | |
function enterMarkets(address[] calldata cTokens) external returns (uint[] memory); | |
} |
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 cTokenInterface{ | |
function mint() external payable; | |
function balanceOf(address _owner) external view returns (uint balance); | |
function transfer(address _to, uint _value) external returns (bool success); | |
function borrow(uint borrowAmount) external returns (uint); | |
} | |
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
/* | |
Implements EIP20 token standard: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md | |
.*/ | |
pragma solidity ^0.4.21; | |
import "./EIP20Interface.sol"; | |
contract EIP20 is EIP20Interface { | |
uint256 constant private MAX_UINT256 = 2**256 - 1; | |
mapping (address => uint256) public balances; | |
mapping (address => mapping (address => uint256)) public allowed; | |
/* | |
NOTE: | |
The following variables are OPTIONAL vanities. One does not have to include them. | |
They allow one to customise the token contract & in no way influences the core functionality. | |
Some wallets/interfaces might not even bother to look at this information. | |
*/ | |
string public name; //fancy name: eg Simon Bucks | |
uint8 public decimals; //How many decimals to show. | |
string public symbol; //An identifier: eg SBX | |
function EIP20( | |
uint256 _initialAmount, | |
string _tokenName, | |
uint8 _decimalUnits, | |
string _tokenSymbol | |
) public { | |
balances[msg.sender] = _initialAmount; // Give the creator all initial tokens | |
totalSupply = _initialAmount; // Update total supply | |
name = _tokenName; // Set the name for display purposes | |
decimals = _decimalUnits; // Amount of decimals for display purposes | |
symbol = _tokenSymbol; // Set the symbol for display purposes | |
} | |
function transfer(address _to, uint256 _value) public returns (bool success) { | |
require(balances[msg.sender] >= _value); | |
balances[msg.sender] -= _value; | |
balances[_to] += _value; | |
emit Transfer(msg.sender, _to, _value); //solhint-disable-line indent, no-unused-vars | |
return true; | |
} | |
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { | |
uint256 allowance = allowed[_from][msg.sender]; | |
require(balances[_from] >= _value && allowance >= _value); | |
balances[_to] += _value; | |
balances[_from] -= _value; | |
if (allowance < MAX_UINT256) { | |
allowed[_from][msg.sender] -= _value; | |
} | |
emit Transfer(_from, _to, _value); //solhint-disable-line indent, no-unused-vars | |
return true; | |
} | |
function balanceOf(address _owner) public view returns (uint256 balance) { | |
return balances[_owner]; | |
} | |
function approve(address _spender, uint256 _value) public returns (bool success) { | |
allowed[msg.sender][_spender] = _value; | |
emit Approval(msg.sender, _spender, _value); //solhint-disable-line indent, no-unused-vars | |
return true; | |
} | |
function allowance(address _owner, address _spender) public view returns (uint256 remaining) { | |
return allowed[_owner][_spender]; | |
} | |
} |
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
// Abstract contract for the full ERC 20 Token standard | |
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md | |
pragma solidity ^0.4.21; | |
contract EIP20Interface { | |
/* This is a slight change to the ERC20 base standard. | |
function totalSupply() constant returns (uint256 supply); | |
is replaced with: | |
uint256 public totalSupply; | |
This automatically creates a getter function for the totalSupply. | |
This is moved to the base contract since public getter functions are not | |
currently recognised as an implementation of the matching abstract | |
function by the compiler. | |
*/ | |
/// total amount of tokens | |
uint256 public totalSupply; | |
/// @param _owner The address from which the balance will be retrieved | |
/// @return The balance | |
function balanceOf(address _owner) public view returns (uint256 balance); | |
/// @notice send `_value` token to `_to` from `msg.sender` | |
/// @param _to The address of the recipient | |
/// @param _value The amount of token to be transferred | |
/// @return Whether the transfer was successful or not | |
function transfer(address _to, uint256 _value) public returns (bool success); | |
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from` | |
/// @param _from The address of the sender | |
/// @param _to The address of the recipient | |
/// @param _value The amount of token to be transferred | |
/// @return Whether the transfer was successful or not | |
function transferFrom(address _from, address _to, uint256 _value) public returns (bool success); | |
/// @notice `msg.sender` approves `_spender` to spend `_value` tokens | |
/// @param _spender The address of the account able to transfer the tokens | |
/// @param _value The amount of tokens to be approved for transfer | |
/// @return Whether the approval was successful or not | |
function approve(address _spender, uint256 _value) public returns (bool success); | |
/// @param _owner The address of the account owning tokens | |
/// @param _spender The address of the account able to transfer the tokens | |
/// @return Amount of remaining tokens allowed to spent | |
function allowance(address _owner, address _spender) public view returns (uint256 remaining); | |
// solhint-disable-next-line no-simple-event-func-name | |
event Transfer(address indexed _from, address indexed _to, uint256 _value); | |
event Approval(address indexed _owner, address indexed _spender, uint256 _value); | |
} |
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; | |
contract EIP712 { | |
mapping(address => uint256) public nonces; | |
struct EIP712Domain { | |
string name; | |
string version; | |
uint256 chainId; | |
address verifyingContract; | |
} | |
struct MetaTransaction { | |
address holder; | |
uint256 nonce; | |
} | |
bytes32 internal constant EIP712_DOMAIN_TYPEHASH = keccak256(bytes("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")); | |
bytes32 internal constant META_TRANSACTION_TYPEHASH = keccak256(bytes("MetaTransaction(address holder,uint256 nonce)")); | |
bytes32 internal DOMAIN_SEPARATOR = keccak256(abi.encode( | |
EIP712_DOMAIN_TYPEHASH, | |
keccak256(bytes("kyber")), | |
keccak256(bytes("1")), | |
3, // Ropsten | |
address(this) | |
)); | |
} |
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; | |
contract EIP712Parcel { | |
mapping(address => uint256) public nonces; | |
struct EIP712Domain { | |
string name; | |
string version; | |
uint256 chainId; | |
address verifyingContract; | |
} | |
struct MetaTransaction { | |
address from; | |
address to; | |
uint256 nonce; | |
} | |
bytes32 internal constant EIP712_DOMAIN_TYPEHASH = keccak256(bytes("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")); | |
bytes32 internal constant META_TRANSACTION_TYPEHASH = keccak256(bytes("MetaTransaction(address from,address to,uint256 nonce)")); | |
bytes32 internal DOMAIN_SEPARATOR = keccak256(abi.encode( | |
EIP712_DOMAIN_TYPEHASH, | |
keccak256(bytes("parcel")), | |
keccak256(bytes("1")), | |
42, // Kovan | |
address(this) | |
)); | |
} |
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 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); | |
} |
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.6.0; | |
import "./storage.sol"; | |
interface Forwarder { | |
enum SignatureType { DIRECT, EIP1654, EIP1271 } | |
struct Message { | |
address from; | |
address to; | |
uint256 chainId; | |
address replayProtection; | |
bytes nonce; | |
bytes data; | |
bytes32 innerMessageHash; | |
} | |
function forward( | |
Message calldata message, | |
SignatureType signatureType, | |
bytes calldata signature | |
) external payable; | |
} | |
contract Implementation is EternalStorage,Forwarder{ | |
function isOwner(address signer) internal view returns (bool){ | |
for(uint i = 0; i < owners.length; i++){ | |
if(signer == owners[i]) { | |
return true; | |
} | |
} | |
return false; | |
} | |
function updateImplementation(address signer,address _newImplementation) external { | |
require( | |
isOwner(signer) == true,"not the owner" | |
); | |
require(_newImplementation != address(0), "Address can't be 0"); | |
implementation = _newImplementation; | |
} | |
function forward(Message memory message, | |
SignatureType signatureType, | |
bytes memory signature) external { | |
} | |
function _call( | |
address from, | |
address to, | |
uint256 value, | |
bytes memory data | |
) internal { | |
(bool success,) = to.call{value:value}(abi.encodePacked(data, from)); | |
if (!success) { | |
assembly { | |
let returnDataSize := returndatasize() | |
returndatacopy(0, 0, returnDataSize) | |
revert(0, returnDataSize) | |
} | |
} | |
} | |
} |
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 "./ERC20.sol"; | |
interface KyberNetworkProxyInterface { | |
function tradeWithHint(ERC20 src, uint srcAmount, ERC20 dest, address destAddress, uint maxDestAmount, | |
uint minConversionRate, address walletId, bytes calldata hint) external payable returns(uint); | |
} | |
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 "kyberWallet.sol"; | |
contract KyberRegistry is EIP712{ | |
mapping(address => address payable) public registered; | |
modifier oneAccount{ | |
require(registered[msg.sender] == address(0),"account exists"); | |
_; | |
} | |
function register() oneAccount external payable{ | |
KyberWallet newAccount = new KyberWallet(); | |
registered[msg.sender] = address(newAccount); | |
} | |
function registerWithMeta(address userAddress,bytes32 r, bytes32 s, uint8 v) oneAccount external { | |
bytes32 digest = keccak256( | |
abi.encodePacked( | |
"\x19\x01", | |
DOMAIN_SEPARATOR, | |
keccak256(abi.encode(META_TRANSACTION_TYPEHASH,userAddress,nonces[userAddress])))); | |
require(userAddress != address(0), "invalid-address-0"); | |
require(userAddress == ecrecover(digest, v, r, s), "invalid-signatures"); | |
KyberWallet newAccount = new KyberWallet(); | |
registered[userAddress] = address(newAccount); | |
} | |
} | |
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 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); | |
} | |
interface KyberNetworkProxyInterface { | |
function tradeWithHint(ERC20 src, uint srcAmount, ERC20 dest, address destAddress, uint maxDestAmount, | |
uint minConversionRate, address walletId, bytes calldata hint) external payable returns(uint); | |
} | |
contract Trial { | |
KyberNetworkProxyInterface kyber = KyberNetworkProxyInterface(0x818E6FECD516Ecc3849DAf6845e3EC868087B755); | |
function callHint(ERC20 src, uint srcAmount, ERC20 dest, address destAddress, uint maxDestAmount, | |
uint minConversionRate, address walletId, bytes calldata hint) external payable { | |
kyber.tradeWithHint.value(msg.value)(src,srcAmount,dest,destAddress,maxDestAmount,minConversionRate,walletId,hint); | |
} | |
} |
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 "./kyberNetworkProxyInterface.sol"; | |
import "./EIP712.sol"; | |
contract KyberWallet is EIP712 { | |
address kyberNetworkProxyAddress = 0x818E6FECD516Ecc3849DAf6845e3EC868087B755; | |
KyberNetworkProxyInterface kyber = KyberNetworkProxyInterface(kyberNetworkProxyAddress); | |
ERC20 dai = ERC20(0xaD6D458402F60fD3Bd25163575031ACDce07538D); | |
// Internal Function call to forward data to kyber | |
function _call( | |
address to, | |
uint256 value, | |
bytes memory data | |
) internal { | |
(bool success,) = to.call.value(value)(data); | |
if (!success) { | |
assembly { | |
let returnDataSize := returndatasize() | |
returndatacopy(0, 0, returnDataSize) | |
revert(0, returnDataSize) | |
} | |
} | |
} | |
// address userAddress [0] | |
// address destAddress [1] | |
// address walletId [2] | |
function forwardWithMeta(bytes32 r, bytes32 s, uint8 v,ERC20 src, uint srcAmount, ERC20 dest, uint maxDestAmount, | |
uint minConversionRate, bytes calldata hint,address[] calldata _addresses) external payable{ | |
bytes32 digest = keccak256( | |
abi.encodePacked( | |
"\x19\x01", | |
DOMAIN_SEPARATOR, | |
keccak256(abi.encode(META_TRANSACTION_TYPEHASH,_addresses[0],nonces[_addresses[0]])))); | |
require(_addresses[0] != address(0), "invalid-address-0"); | |
require(_addresses[0] == ecrecover(digest, v, r, s), "invalid-signatures"); | |
tradeWithHint(_addresses[0],src,srcAmount,dest,maxDestAmount,minConversionRate,_addresses[2],hint); | |
nonces[_addresses[0]]++; | |
} | |
function tradeWithHint(address userAddress,ERC20 src, uint srcAmount, ERC20 dest, uint maxDestAmount, | |
uint minConversionRate, address walletId, bytes memory hint) public payable { | |
dai.transferFrom(userAddress,address(this),srcAmount); | |
dai.approve(kyberNetworkProxyAddress,srcAmount); | |
kyber.tradeWithHint(src,srcAmount,dest,userAddress,maxDestAmount,minConversionRate,walletId,hint); | |
} | |
function() external payable{ | |
} | |
} | |
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 "./ParcelStorage.sol"; | |
contract MultiSender is ParcelStorage{ | |
function multiToken(address[] memory targets,address payable[] memory addresses,uint[] memory values) public payable { | |
for (uint i = 0; i < addresses.length; i++) { | |
if(targets[i] == ethAddress){ | |
address(addresses[i]).transfer(values[i]); | |
}else{ | |
ERC20 erc20 = ERC20(targets[i]); | |
erc20.transfer(addresses[i],values[i]); | |
} | |
} | |
} | |
function() external payable { | |
} | |
} | |
// address : 0x2F0a3327C0C306773c10130fD8F1827cDf15f1ca | |
// args : ["0x4F96Fe3b7A6Cf9725f59d353F723c1bDb64CA6Aa","0x4F96Fe3b7A6Cf9725f59d353F723c1bDb64CA6Aa","0x4F96Fe3b7A6Cf9725f59d353F723c1bDb64CA6Aa","0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE","0x4F96Fe3b7A6Cf9725f59d353F723c1bDb64CA6Aa"],["0x36eC99A4CA6F1a3E3299aEB94587F34A9E6adA1f","0x55f6F8D7d1C39735503896827bF79669f34d569b","0xadb67bA1a22a6eb5f60357222AB6C3a547a791d4","0xDa099Ccb40c9eC8De9A69084d40BB453148EF52D","0x1D562B8E2fB0eaed249970BeE1B65dCA1610027e"],["1000000000000000","50000000000000000","40000000000000000","30000000000000000","50000000000000000"] |
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 "./ParcelStorage.sol"; | |
contract Parcel is ParcelStorage{ | |
mapping(address => uint256) public nonces; | |
struct EIP712Domain { | |
string name; | |
string version; | |
uint256 chainId; | |
address verifyingContract; | |
} | |
struct MetaTransaction { | |
address from; | |
address to; | |
uint256 nonce; | |
} | |
bytes32 internal constant EIP712_DOMAIN_TYPEHASH = keccak256(bytes("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")); | |
bytes32 internal constant META_TRANSACTION_TYPEHASH = keccak256(bytes("MetaTransaction(address from,address to,uint256 nonce)")); | |
bytes32 internal DOMAIN_SEPARATOR = keccak256(abi.encode( | |
EIP712_DOMAIN_TYPEHASH, | |
keccak256(bytes("parcel")), | |
keccak256(bytes("1")), | |
42, // Kovan | |
address(this) | |
)); | |
constructor(address _owner) public { | |
owner = _owner; | |
} | |
modifier onlyOwner{ | |
require(msg.sender == owner,"Not the Owner"); | |
_; | |
} | |
/** | |
* @dev Delegate the calls to Connector And this function is ran by execute(). | |
* @param _target Target to of Connector. | |
* @param _data CallData of function in Connector. | |
*/ | |
function _call(address _target, bytes memory _data) internal { | |
require(_target != address(0), "target-invalid"); | |
assembly { | |
let succeeded := delegatecall(gas(), _target, add(_data, 0x20), mload(_data), 0, 0) | |
switch iszero(succeeded) | |
case 1 { | |
// throw if delegatecall failed | |
let size := returndatasize() | |
returndatacopy(0x00, 0x00, size) | |
revert(0x00, size) | |
} | |
} | |
} | |
/** | |
* @dev This is the main function | |
* @param targets Array of Target(s) of Implementation. | |
* @param data Array of Calldata(s) of function. | |
*/ | |
function execute( | |
address[] calldata targets, | |
bytes[] calldata data, | |
address[] calldata addresses, | |
bytes32 r, bytes32 s, uint8 v | |
) | |
onlyOwner | |
external | |
payable | |
{ | |
bytes32 digest = keccak256( | |
abi.encodePacked( | |
"\x19\x01", | |
DOMAIN_SEPARATOR, | |
keccak256(abi.encode(META_TRANSACTION_TYPEHASH,addresses[0],addresses[1],nonces[addresses[0]])))); | |
require(addresses[0] != address(0), "invalid-address-0"); | |
require(addresses[0] == ecrecover(digest, v, r, s), "invalid-signatures"); | |
for (uint i = 0; i < targets.length; i++) { | |
_call(targets[i], data[i]); | |
} | |
nonces[addresses[0]]++; | |
} | |
function withdraw(address[] calldata targets) onlyOwner external { | |
msg.sender.transfer(address(this).balance); | |
for (uint i = 0; i < targets.length; i++) { | |
ERC20 erc20 = ERC20(targets[i]); | |
uint balance = erc20.balanceOf(address(this)); | |
erc20.transfer(msg.sender,balance); | |
} | |
} | |
function() external payable{ | |
} | |
} | |
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 "parcel.sol"; | |
contract ParcelRegistry { | |
mapping(address => address) public registered; | |
modifier oneAccount{ | |
require(registered[msg.sender] == address(0),"account exists"); | |
_; | |
} | |
function register() oneAccount external payable returns(address){ | |
Parcel newAccount = new Parcel(msg.sender); | |
registered[msg.sender] = address(newAccount); | |
} | |
} | |
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 "./uniswapInterface.sol"; | |
import "./cTokenInterface.sol"; | |
import "./ERC20.sol"; | |
import "./comptrollerInterface.sol"; | |
import "./aaveInterface.sol"; | |
import "./aTokenInterface.sol"; | |
interface ILendingPoolAddressesProvider { | |
function getLendingPool() external view returns (address); | |
} | |
contract ParcelStorage{ | |
address public uniswapRouterAddress = 0xf164fC0Ec4E93095b804a4795bBe1e041497b92a; | |
UniswapInterface uniswap = UniswapInterface(uniswapRouterAddress); | |
address WETH_KOVAN = 0xd0A1E359811322d97991E03f863a0C30C2cF029C; | |
address DAI_KOVAN = 0x4F96Fe3b7A6Cf9725f59d353F723c1bDb64CA6Aa; | |
address cEthAddress = 0xf92FbE0D3C0dcDAE407923b2Ac17eC223b1084E4; | |
cTokenInterface cEth = cTokenInterface(cEthAddress); | |
address cDaiAddress = 0xe7bc397DBd069fC7d0109C0636d06888bb50668c; | |
cTokenInterface cDai = cTokenInterface(cDaiAddress); | |
address comptrollerAddress = 0x1f5D7F3CaAC149fE41b8bd62A3673FE6eC0AB73b; | |
comptrollerInterface comptroller = comptrollerInterface(comptrollerAddress); | |
cTokenInterface dai = cTokenInterface(DAI_KOVAN); | |
address public owner; | |
// // Retrieve LendingPool address | |
ILendingPoolAddressesProvider provider = ILendingPoolAddressesProvider(address(0x506B0B2CF20FAA8f38a4E2B524EE43e1f4458Cc5)); // mainnet address, for other addresses: https://docs.aave.com/developers/developing-on-aave/deployed-contract-instances | |
LendingPool lendingPool = LendingPool(provider.getLendingPool()); | |
// Input variables | |
address ethAddress = address(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE); // mainnet DAI | |
uint16 referral = 0; | |
} | |
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.6.0; | |
contract EternalStorage { | |
address public implementation; | |
address[] public owners; | |
mapping(uint128 => uint128) internal batchNonce; | |
/* Upgradable Storage */ | |
mapping(bytes32 => uint256) internal uIntStorage; | |
mapping(bytes32 => string) internal stringStorage; | |
mapping(bytes32 => address) internal addressStorage; | |
mapping(bytes32 => bytes) internal bytesStorage; | |
mapping(bytes32 => bool) internal boolStorage; | |
mapping(bytes32 => int256) internal intStorage; | |
} | |
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; | |
contract Test{ | |
uint public count = 1; | |
uint internal counter = 10; | |
function getCounter() external{ | |
// require(msg.sender == 0x7991ed26d05b311e7ff7f6e5d89D47A498BDBFf2,""); | |
count = 0; | |
counter = counter*10; | |
// return counter; | |
} | |
function y() external{ | |
// require(msg.sender == 0x7991ed26d05b311e7ff7f6e5d89D47A498BDBFf2,""); | |
counter = counter*10; | |
} | |
} |
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 "kyberWallet.sol"; | |
contract Test { | |
uint public count; | |
address public sender; | |
function increase()external payable{ | |
count+=msg.value; | |
sender = msg.sender; | |
} | |
function encodeData() external pure returns (bytes memory){ | |
return abi.encodeWithSignature("increase()"); | |
} | |
} | |
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 "./ParcelStorage.sol"; | |
contract Uniswap is ParcelStorage{ | |
function swap(address[] calldata path, uint amountInEth)external payable { | |
uint[] memory returnedAmount = getAmount(path,amountInEth); | |
uniswap.swapExactETHForTokens.value(amountInEth)(returnedAmount[1],path,address(this), now + 12000); | |
} | |
function getAmount(address[] memory path, uint amountInEth) public view returns(uint[] memory){ | |
uint[] memory returnedAmount = uniswap.getAmountsOut(amountInEth,path); | |
return returnedAmount; | |
} | |
function getHash(address[] memory path, uint amountInEth)public pure returns(bytes memory){ | |
return abi.encodeWithSignature("swap(address[],uint256)",path,amountInEth); | |
} | |
} | |
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 UniswapInterface{ | |
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline) | |
external | |
payable | |
returns (uint[] memory amounts); | |
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts); | |
} | |
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.6.0; | |
import "./storage.sol"; | |
contract Account is EternalStorage { | |
constructor(address payable _owner, address _implementation) public { | |
owners.push(_owner); | |
implementation = _implementation; | |
} | |
receive() external payable {} | |
fallback() external payable { | |
address addr = implementation; | |
assembly { | |
calldatacopy(0, 0, calldatasize()) | |
let result := delegatecall(gas(), addr, 0, calldatasize(), 0, 0) | |
returndatacopy(0, 0, returndatasize()) | |
switch result | |
case 0 { | |
revert(0, returndatasize()) | |
} | |
default { | |
return(0, returndatasize()) | |
} | |
} | |
} | |
} | |
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.99 <0.6.0; | |
interface Forwarder { | |
enum SignatureType { DIRECT, EIP1654, EIP1271 } | |
struct Message { | |
address from; | |
address to; | |
uint256 chainId; | |
address replayProtection; | |
bytes nonce; | |
bytes data; | |
bytes32 innerMessageHash; | |
} | |
function forward( | |
Message calldata message, | |
SignatureType signatureType, | |
bytes calldata signature | |
) external payable; | |
} | |
contract Factory { | |
event Deployed(address addr, uint256 salt); | |
function deploy(uint256 salt) public { | |
bytes memory code = hex"608060405234801561001057600080fd5b506040516102eb3803806102eb8339818101604052604081101561003357600080fd5b8101908080519060200190929190805190602001909291905050506001829080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050506101e9806101026000396000f3fe60806040526004361061002d5760003560e01c8063025e7c27146100805780635c60da1b146100fb57610034565b3661003457005b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690503660008037600080366000845af43d6000803e806000811461007b573d6000f35b3d6000fd5b34801561008c57600080fd5b506100b9600480360360208110156100a357600080fd5b8101908080359060200190929190505050610152565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561010757600080fd5b5061011061018e565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6001818154811061015f57fe5b906000526020600020016000915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff168156fea26469706673582212203d15836e1dc4274908a8317014e221efabdaed29d584eee069f3c821c8b07fae64736f6c63430006090033000000000000000000000000930f2ca6c496975fe247c3e4d02579bab4782f44000000000000000000000000930f2ca6c496975fe247c3e4d02579bab4782f44"; | |
// bytes memory code = abi.encodePacked(hex"608060405234801561001057600080fd5b5060de8061001f6000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c8063025e7c271460375780635c60da1b14606d575b600080fd5b605160048036036020811015604b57600080fd5b50356073565b604080516001600160a01b039092168252519081900360200190f35b60516099565b60018181548110607f57fe5b6000918252602090912001546001600160a01b0316905081565b6000546001600160a01b03168156fea2646970667358221220bf6d7e81f5bffab7769e8cee9b493e6762902a47bbc4e2658a4470da48e41d7a64736f6c63430006080033",abi.encode(0x930F2ca6C496975fe247c3e4d02579bAB4782f44,0x930F2ca6C496975fe247c3e4d02579bAB4782f44)); | |
address addr; | |
assembly { | |
addr := create2(0, add(code, 0x20), mload(code), salt) | |
if iszero(extcodesize(addr)) { | |
revert(0, 0) | |
} | |
} | |
emit Deployed(addr, salt); | |
} | |
function deployAndExecute(uint256 salt) public { | |
bytes memory code = hex"608060405234801561001057600080fd5b506040516102eb3803806102eb8339818101604052604081101561003357600080fd5b8101908080519060200190929190805190602001909291905050506001829080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550806000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050506101e9806101026000396000f3fe60806040526004361061002d5760003560e01c8063025e7c27146100805780635c60da1b146100fb57610034565b3661003457005b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690503660008037600080366000845af43d6000803e806000811461007b573d6000f35b3d6000fd5b34801561008c57600080fd5b506100b9600480360360208110156100a357600080fd5b8101908080359060200190929190505050610152565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b34801561010757600080fd5b5061011061018e565b604051808273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b6001818154811061015f57fe5b906000526020600020016000915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff168156fea26469706673582212203d15836e1dc4274908a8317014e221efabdaed29d584eee069f3c821c8b07fae64736f6c63430006090033000000000000000000000000930f2ca6c496975fe247c3e4d02579bab4782f44000000000000000000000000930f2ca6c496975fe247c3e4d02579bab4782f44"; | |
// bytes memory code = abi.encodePacked(hex"608060405234801561001057600080fd5b5060de8061001f6000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c8063025e7c271460375780635c60da1b14606d575b600080fd5b605160048036036020811015604b57600080fd5b50356073565b604080516001600160a01b039092168252519081900360200190f35b60516099565b60018181548110607f57fe5b6000918252602090912001546001600160a01b0316905081565b6000546001600160a01b03168156fea2646970667358221220bf6d7e81f5bffab7769e8cee9b493e6762902a47bbc4e2658a4470da48e41d7a64736f6c63430006080033",abi.encode(0x930F2ca6C496975fe247c3e4d02579bAB4782f44,0x930F2ca6C496975fe247c3e4d02579bAB4782f44)); | |
address addr; | |
assembly { | |
addr := create2(0, add(code, 0x20), mload(code), salt) | |
if iszero(extcodesize(addr)) { | |
revert(0, 0) | |
} | |
} | |
if (_targets.length > 0) AccountInterface(_account).cast.value(msg.value)(_targets, _datas, _origin); | |
emit Deployed(addr, salt); | |
} | |
} | |
// web3 call to encode bytecode data --- working | |
// web3.eth.contract(yourAbi).getData(ctorArg1, ctorArg1,... etc, {data: compliedBytecode}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment