├── .DS_Store ├── README.md └── contracts ├── .DS_Store ├── BasketedForexPortfolio.sol ├── DAIInterestUltaShortBTCPortfolio.sol ├── DAIInterestUltraLongETHPortfolio.sol └── gift-lib ├── .solhint.json └── giftcontract.sol /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProofSuite/StructuredSmartContracts/f873cb053ad5f3d4dabceced5f12864e16b9a834/.DS_Store -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Structured Smart Contracts 2 | 3 | ![Structured Logo](https://www.structuredeth.com/images/structured.png) 4 | 5 | Contracts For Creating Baskets of DeFi financial products on the Ethereum blockchain 6 | 7 | Website: [strcuturedeth.com](https://www.structuredeth.com) 8 | 9 | More Docs coming... 10 | 11 | -------------------------------------------------------------------------------- /contracts/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProofSuite/StructuredSmartContracts/f873cb053ad5f3d4dabceced5f12864e16b9a834/contracts/.DS_Store -------------------------------------------------------------------------------- /contracts/BasketedForexPortfolio.sol: -------------------------------------------------------------------------------- 1 | //diversified currency basket generation 2 | 3 | contract synthMainInterface{ 4 | function minimumDepositAmount ( ) external view returns ( uint256 ); 5 | function exchangeEtherForSynthsAtRate ( uint256 guaranteedRate ) external payable returns ( uint256 ); 6 | function synthsReceivedForEther ( uint256 amount ) external view returns ( uint256 ); 7 | function synth ( ) external view returns ( address ); 8 | function exchangeSynthsForSynthetix ( uint256 synthAmount ) external returns ( uint256 ); 9 | function nominateNewOwner ( address _owner ) external; 10 | function setPaused ( bool _paused ) external; 11 | function initiationTime ( ) external view returns ( uint256 ); 12 | function exchangeEtherForSynths ( ) external payable returns ( uint256 ); 13 | function setSelfDestructBeneficiary ( address _beneficiary ) external; 14 | function fundsWallet ( ) external view returns ( address ); 15 | function priceStalePeriod ( ) external view returns ( uint256 ); 16 | function setPriceStalePeriod ( uint256 _time ) external; 17 | function terminateSelfDestruct ( ) external; 18 | function setSynth ( address _synth ) external; 19 | function pricesAreStale ( ) external view returns ( bool ); 20 | function updatePrices ( uint256 newEthPrice, uint256 newSynthetixPrice, uint256 timeSent ) external; 21 | function lastPriceUpdateTime ( ) external view returns ( uint256 ); 22 | function totalSellableDeposits ( ) external view returns ( uint256 ); 23 | function nominatedOwner ( ) external view returns ( address ); 24 | function exchangeSynthsForSynthetixAtRate ( uint256 synthAmount, uint256 guaranteedRate ) external returns ( uint256 ); 25 | function paused ( ) external view returns ( bool ); 26 | function setFundsWallet ( address _fundsWallet ) external; 27 | function depositStartIndex ( ) external view returns ( uint256 ); 28 | function synthetix ( ) external view returns ( address ); 29 | function acceptOwnership ( ) external; 30 | function exchangeEtherForSynthetix ( ) external payable returns ( uint256 ); 31 | function setOracle ( address _oracle ) external; 32 | function exchangeEtherForSynthetixAtRate ( uint256 guaranteedEtherRate, uint256 guaranteedSynthetixRate ) external payable returns ( uint256 ); 33 | function oracle ( ) external view returns ( address ); 34 | function withdrawMyDepositedSynths ( ) external; 35 | function owner ( ) external view returns ( address ); 36 | function lastPauseTime ( ) external view returns ( uint256 ); 37 | function selfDestruct ( ) external; 38 | function synthetixReceivedForSynths ( uint256 amount ) external view returns ( uint256 ); 39 | function SELFDESTRUCT_DELAY ( ) external view returns ( uint256 ); 40 | function setMinimumDepositAmount ( uint256 _amount ) external; 41 | function feePool ( ) external view returns ( address ); 42 | function deposits ( uint256 ) external view returns ( address user, uint256 amount ); 43 | function selfDestructInitiated ( ) external view returns ( bool ); 44 | function usdToEthPrice ( ) external view returns ( uint256 ); 45 | function initiateSelfDestruct ( ) external; 46 | function tokenFallback ( address from, uint256 amount, bytes data ) external returns ( bool ); 47 | function selfDestructBeneficiary ( ) external view returns ( address ); 48 | function smallDeposits ( address ) external view returns ( uint256 ); 49 | function synthetixReceivedForEther ( uint256 amount ) external view returns ( uint256 ); 50 | function depositSynths ( uint256 amount ) external; 51 | function withdrawSynthetix ( uint256 amount ) external; 52 | function usdToSnxPrice ( ) external view returns ( uint256 ); 53 | function ORACLE_FUTURE_LIMIT ( ) external view returns ( uint256 ); 54 | function depositEndIndex ( ) external view returns ( uint256 ); 55 | function setSynthetix ( address _synthetix ) external; 56 | } 57 | 58 | contract synthConvertInterface{ 59 | function name ( ) external view returns ( string ); 60 | function setGasPriceLimit ( uint256 _gasPriceLimit ) external; 61 | function approve ( address spender, uint256 value ) external returns ( bool ); 62 | function removeSynth ( bytes32 currencyKey ) external; 63 | function issueSynths ( bytes32 currencyKey, uint256 amount ) external; 64 | function mint ( ) external returns ( bool ); 65 | function setIntegrationProxy ( address _integrationProxy ) external; 66 | function nominateNewOwner ( address _owner ) external; 67 | function initiationTime ( ) external view returns ( uint256 ); 68 | function totalSupply ( ) external view returns ( uint256 ); 69 | function setFeePool ( address _feePool ) external; 70 | function exchange ( bytes32 sourceCurrencyKey, uint256 sourceAmount, bytes32 destinationCurrencyKey, address destinationAddress ) external returns ( bool ); 71 | function setSelfDestructBeneficiary ( address _beneficiary ) external; 72 | function transferFrom ( address from, address to, uint256 value ) external returns ( bool ); 73 | function decimals ( ) external view returns ( uint8 ); 74 | function synths ( bytes32 ) external view returns ( address ); 75 | function terminateSelfDestruct ( ) external; 76 | function rewardsDistribution ( ) external view returns ( address ); 77 | function exchangeRates ( ) external view returns ( address ); 78 | function nominatedOwner ( ) external view returns ( address ); 79 | function setExchangeRates ( address _exchangeRates ) external; 80 | function effectiveValue ( bytes32 sourceCurrencyKey, uint256 sourceAmount, bytes32 destinationCurrencyKey ) external view returns ( uint256 ); 81 | function transferableSynthetix ( address account ) external view returns ( uint256 ); 82 | function validateGasPrice ( uint256 _givenGasPrice ) external view; 83 | function balanceOf ( address account ) external view returns ( uint256 ); 84 | function availableCurrencyKeys ( ) external view returns ( bytes32[] ); 85 | function acceptOwnership ( ) external; 86 | function remainingIssuableSynths ( address issuer, bytes32 currencyKey ) external view returns ( uint256 ); 87 | function availableSynths ( uint256 ) external view returns ( address ); 88 | function totalIssuedSynths ( bytes32 currencyKey ) external view returns ( uint256 ); 89 | function addSynth ( address synth ) external; 90 | function owner ( ) external view returns ( address ); 91 | function setExchangeEnabled ( bool _exchangeEnabled ) external; 92 | function symbol ( ) external view returns ( string ); 93 | function gasPriceLimit ( ) external view returns ( uint256 ); 94 | function setProxy ( address _proxy ) external; 95 | function selfDestruct ( ) external; 96 | function integrationProxy ( ) external view returns ( address ); 97 | function setTokenState ( address _tokenState ) external; 98 | function collateralisationRatio ( address issuer ) external view returns ( uint256 ); 99 | function rewardEscrow ( ) external view returns ( address ); 100 | function SELFDESTRUCT_DELAY ( ) external view returns ( uint256 ); 101 | function collateral ( address account ) external view returns ( uint256 ); 102 | function maxIssuableSynths ( address issuer, bytes32 currencyKey ) external view returns ( uint256 ); 103 | function transfer ( address to, uint256 value ) external returns ( bool ); 104 | function synthInitiatedExchange ( address from, bytes32 sourceCurrencyKey, uint256 sourceAmount, bytes32 destinationCurrencyKey, address destinationAddress ) external returns ( bool ); 105 | function transferFrom ( address from, address to, uint256 value, bytes data ) external returns ( bool ); 106 | function feePool ( ) external view returns ( address ); 107 | function selfDestructInitiated ( ) external view returns ( bool ); 108 | function setMessageSender ( address sender ) external; 109 | function initiateSelfDestruct ( ) external; 110 | function transfer ( address to, uint256 value, bytes data ) external returns ( bool ); 111 | function supplySchedule ( ) external view returns ( address ); 112 | function selfDestructBeneficiary ( ) external view returns ( address ); 113 | function setProtectionCircuit ( bool _protectionCircuitIsActivated ) external; 114 | function debtBalanceOf ( address issuer, bytes32 currencyKey ) external view returns ( uint256 ); 115 | function synthetixState ( ) external view returns ( address ); 116 | function availableSynthCount ( ) external view returns ( uint256 ); 117 | function allowance ( address owner, address spender ) external view returns ( uint256 ); 118 | function escrow ( ) external view returns ( address ); 119 | function tokenState ( ) external view returns ( address ); 120 | function burnSynths ( bytes32 currencyKey, uint256 amount ) external; 121 | function proxy ( ) external view returns ( address ); 122 | function issueMaxSynths ( bytes32 currencyKey ) external; 123 | function exchangeEnabled ( ) external view returns ( bool ); 124 | } 125 | 126 | 127 | 128 | 129 | 130 | library SafeMath { 131 | function mul(uint256 a, uint256 b) internal constant returns (uint256) { 132 | uint256 c = a * b; 133 | assert(a == 0 || c / a == b); 134 | return c; 135 | } 136 | 137 | function div(uint256 a, uint256 b) internal constant returns (uint256) { 138 | assert(b > 0); // Solidity automatically throws when dividing by 0 139 | uint256 c = a / b; 140 | assert(a == b * c + a % b); // There is no case in which this doesn't hold 141 | return c; 142 | } 143 | 144 | function sub(uint256 a, uint256 b) internal constant returns (uint256) { 145 | assert(b <= a); 146 | return a - b; 147 | } 148 | 149 | function add(uint256 a, uint256 b) internal constant returns (uint256) { 150 | uint256 c = a + b; 151 | assert(c >= a); 152 | return c; 153 | } 154 | } 155 | 156 | 157 | contract Portfolio1 { 158 | 159 | 160 | synthMainInterface sInt = synthMainInterface(0x172e09691dfbbc035e37c73b62095caa16ee2388); 161 | synthConvertInterface sInt2 = synthConvertInterface(0x42d03f506c2308ecd06ae81d8fa22352bc7a8f2b); 162 | 163 | 164 | //sUSD code 165 | bytes32 sourceKey= 0x7355534400000000000000000000000000000000000000000000000000000000; 166 | 167 | //sJPY code 168 | bytes32 destKey = 0x734a505900000000000000000000000000000000000000000000000000000000; 169 | 170 | uint256 sUSDBack = 0; 171 | 172 | using SafeMath for uint256; 173 | 174 | 175 | 176 | 177 | 178 | function () payable{ 179 | 180 | // buyPackage(); 181 | } 182 | 183 | 184 | function getLastUSDBack() constant returns (uint256){ 185 | return sUSDBack; 186 | } 187 | 188 | 189 | 190 | 191 | function buyPackage() payable returns(bool){ 192 | 193 | 194 | 195 | 196 | //100 percent for now 197 | uint256 amountEthUsing = msg.value; 198 | sUSDBack = sInt.synthsReceivedForEther(amountEthUsing).mul(100).div(95); 199 | sInt.exchangeEtherForSynths.value(amountEthUsing)(); 200 | //sInt2.exchange(sourceKey, sUSDBack, destKey ,msg.sender); 201 | 202 | //sInt.transferFrom ( this, msg.sender, sUSDBack); 203 | 204 | 205 | 206 | 207 | return true; 208 | 209 | } 210 | } -------------------------------------------------------------------------------- /contracts/DAIInterestUltaShortBTCPortfolio.sol: -------------------------------------------------------------------------------- 1 | 2 | //10% 3x wBTC Short / 90% Fulcrum Dai Loan Interest 3 | 4 | contract fulcrumInterface { 5 | function mintWithEther(address receiver, uint256 maxPriceAllowed) external payable returns (uint256 mintAmount); 6 | function mint(address receiver, uint256 amount) external payable returns (uint256 mintAmount); 7 | 8 | function burnToEther(address receiver, uint256 burnAmount, uint256 minPriceAllowed) returns (uint256 loanAmountPaid); 9 | 10 | } 11 | 12 | 13 | interface ERC20 { 14 | function totalSupply() public view returns (uint supply); 15 | function balanceOf(address _owner) public view returns (uint balance); 16 | function transfer(address _to, uint _value) public returns (bool success); 17 | function transferFrom(address _from, address _to, uint _value) public returns (bool success); 18 | function approve(address _spender, uint _value) public returns (bool success); 19 | function allowance(address _owner, address _spender) public view returns (uint remaining); 20 | function decimals() public view returns(uint digits); 21 | event Approval(address indexed _owner, address indexed _spender, uint _value); 22 | } 23 | 24 | 25 | contract IERC20Token { 26 | // these functions aren't abstract since the compiler emits automatically generated getter functions as external 27 | function name() public view returns (string) {} 28 | function symbol() public view returns (string) {} 29 | function decimals() public view returns (uint8) {} 30 | function totalSupply() public view returns (uint256) {} 31 | function balanceOf(address _owner) public view returns (uint256) { _owner; } 32 | function allowance(address _owner, address _spender) public view returns (uint256) { _owner; _spender; } 33 | 34 | function transfer(address _to, uint256 _value) public returns (bool success); 35 | function transferFrom(address _from, address _to, uint256 _value) public returns (bool success); 36 | function approve(address _spender, uint256 _value) public returns (bool success); 37 | } 38 | 39 | 40 | 41 | contract UniswapExchangeInterface { 42 | // Address of ERC20 token sold on this exchange 43 | function tokenAddress() external view returns (address token); 44 | // Address of Uniswap Factory 45 | function factoryAddress() external view returns (address factory); 46 | // Provide Liquidity 47 | function addLiquidity(uint256 min_liquidity, uint256 max_tokens, uint256 deadline) external payable returns (uint256); 48 | function removeLiquidity(uint256 amount, uint256 min_eth, uint256 min_tokens, uint256 deadline) external returns (uint256, uint256); 49 | // Get Prices 50 | function getEthToTokenInputPrice(uint256 eth_sold) external view returns (uint256 tokens_bought); 51 | function getEthToTokenOutputPrice(uint256 tokens_bought) external view returns (uint256 eth_sold); 52 | function getTokenToEthInputPrice(uint256 tokens_sold) external view returns (uint256 eth_bought); 53 | function getTokenToEthOutputPrice(uint256 eth_bought) external view returns (uint256 tokens_sold); 54 | // Trade ETH to ERC20 55 | function ethToTokenSwapInput(uint256 min_tokens, uint256 deadline) external payable returns (uint256 tokens_bought); 56 | function ethToTokenTransferInput(uint256 min_tokens, uint256 deadline, address recipient) external payable returns (uint256 tokens_bought); 57 | function ethToTokenSwapOutput(uint256 tokens_bought, uint256 deadline) external payable returns (uint256 eth_sold); 58 | function ethToTokenTransferOutput(uint256 tokens_bought, uint256 deadline, address recipient) external payable returns (uint256 eth_sold); 59 | // Trade ERC20 to ETH 60 | function tokenToEthSwapInput(uint256 tokens_sold, uint256 min_eth, uint256 deadline) external returns (uint256 eth_bought); 61 | function tokenToEthTransferInput(uint256 tokens_sold, uint256 min_eth, uint256 deadline, address recipient) external returns (uint256 eth_bought); 62 | function tokenToEthSwapOutput(uint256 eth_bought, uint256 max_tokens, uint256 deadline) external returns (uint256 tokens_sold); 63 | function tokenToEthTransferOutput(uint256 eth_bought, uint256 max_tokens, uint256 deadline, address recipient) external returns (uint256 tokens_sold); 64 | // Trade ERC20 to ERC20 65 | function tokenToTokenSwapInput(uint256 tokens_sold, uint256 min_tokens_bought, uint256 min_eth_bought, uint256 deadline, address token_addr) external returns (uint256 tokens_bought); 66 | 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); 67 | function tokenToTokenSwapOutput(uint256 tokens_bought, uint256 max_tokens_sold, uint256 max_eth_sold, uint256 deadline, address token_addr) external returns (uint256 tokens_sold); 68 | 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); 69 | // Trade ERC20 to Custom Pool 70 | function tokenToExchangeSwapInput(uint256 tokens_sold, uint256 min_tokens_bought, uint256 min_eth_bought, uint256 deadline, address exchange_addr) external returns (uint256 tokens_bought); 71 | 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); 72 | function tokenToExchangeSwapOutput(uint256 tokens_bought, uint256 max_tokens_sold, uint256 max_eth_sold, uint256 deadline, address exchange_addr) external returns (uint256 tokens_sold); 73 | 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); 74 | // ERC20 comaptibility for liquidity tokens 75 | bytes32 public name; 76 | bytes32 public symbol; 77 | uint256 public decimals; 78 | function transfer(address _to, uint256 _value) external returns (bool); 79 | function transferFrom(address _from, address _to, uint256 value) external returns (bool); 80 | function approve(address _spender, uint256 _value) external returns (bool); 81 | function allowance(address _owner, address _spender) external view returns (uint256); 82 | function balanceOf(address _owner) external view returns (uint256); 83 | function totalSupply() external view returns (uint256); 84 | // Never use 85 | function setup(address token_addr) external; 86 | } 87 | 88 | 89 | 90 | 91 | library SafeMath { 92 | function mul(uint256 a, uint256 b) internal constant returns (uint256) { 93 | uint256 c = a * b; 94 | assert(a == 0 || c / a == b); 95 | return c; 96 | } 97 | 98 | function div(uint256 a, uint256 b) internal constant returns (uint256) { 99 | assert(b > 0); // Solidity automatically throws when dividing by 0 100 | uint256 c = a / b; 101 | assert(a == b * c + a % b); // There is no case in which this doesn't hold 102 | return c; 103 | } 104 | 105 | function sub(uint256 a, uint256 b) internal constant returns (uint256) { 106 | assert(b <= a); 107 | return a - b; 108 | } 109 | 110 | function add(uint256 a, uint256 b) internal constant returns (uint256) { 111 | uint256 c = a + b; 112 | assert(c >= a); 113 | return c; 114 | } 115 | } 116 | 117 | 118 | contract Portfolio1 { 119 | 120 | 121 | 122 | //3x Short BTC 123 | address leverageContractAddress= 0x849548f5d966017b6b49f6a3a740bbdb78176edb; 124 | fulcrumInterface fInt = fulcrumInterface(leverageContractAddress); 125 | 126 | //Dai Loan 127 | address loanContractAddress= 0x14094949152eddbfcd073717200da82fed8dc960; 128 | fulcrumInterface fInt2 = fulcrumInterface(loanContractAddress); 129 | 130 | address daiAddress = 0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359; 131 | 132 | address uniswapAddress = 0x09cabEC1eAd1c0Ba254B09efb3EE13841712bE14; 133 | UniswapExchangeInterface usi = UniswapExchangeInterface(uniswapAddress); 134 | 135 | using SafeMath for uint256; 136 | 137 | 138 | 139 | 140 | 141 | function () payable{ 142 | 143 | buyPackage(); 144 | } 145 | 146 | 147 | 148 | 149 | function buyPackage() payable returns(bool){ 150 | 151 | uint256 maxMint = 1000000000000000000000000000000000000; 152 | uint256 createdAmount = 0; 153 | uint256 createdAmount2 = 0; 154 | 155 | ERC20 daiToken = ERC20(daiAddress); 156 | 157 | 158 | 159 | uint256 leverageAmountEth = msg.value.mul(10).div(100); 160 | uint256 loanAmountEth = msg.value.mul(90).div(100); 161 | 162 | 163 | uint256 daiBack = usi.ethToTokenSwapInput.value(loanAmountEth)(1, block.timestamp); 164 | 165 | daiToken.approve(loanContractAddress, 10000000000000000000000000000000); 166 | 167 | 168 | createdAmount = fInt.mintWithEther.value(leverageAmountEth)(msg.sender, maxMint); 169 | createdAmount2 = fInt2.mint(msg.sender, daiBack); 170 | 171 | 172 | 173 | 174 | return true; 175 | 176 | } 177 | } -------------------------------------------------------------------------------- /contracts/DAIInterestUltraLongETHPortfolio.sol: -------------------------------------------------------------------------------- 1 | 2 | //10% 3x ETH long / 90% Fulcrum Dai Loan Interest 3 | 4 | contract fulcrumInterface { 5 | function mintWithEther(address receiver, uint256 maxPriceAllowed) external payable returns (uint256 mintAmount); 6 | function mint(address receiver, uint256 amount) external payable returns (uint256 mintAmount); 7 | 8 | function burnToEther(address receiver, uint256 burnAmount, uint256 minPriceAllowed) returns (uint256 loanAmountPaid); 9 | 10 | } 11 | 12 | 13 | interface ERC20 { 14 | function totalSupply() public view returns (uint supply); 15 | function balanceOf(address _owner) public view returns (uint balance); 16 | function transfer(address _to, uint _value) public returns (bool success); 17 | function transferFrom(address _from, address _to, uint _value) public returns (bool success); 18 | function approve(address _spender, uint _value) public returns (bool success); 19 | function allowance(address _owner, address _spender) public view returns (uint remaining); 20 | function decimals() public view returns(uint digits); 21 | event Approval(address indexed _owner, address indexed _spender, uint _value); 22 | } 23 | 24 | 25 | contract IERC20Token { 26 | // these functions aren't abstract since the compiler emits automatically generated getter functions as external 27 | function name() public view returns (string) {} 28 | function symbol() public view returns (string) {} 29 | function decimals() public view returns (uint8) {} 30 | function totalSupply() public view returns (uint256) {} 31 | function balanceOf(address _owner) public view returns (uint256) { _owner; } 32 | function allowance(address _owner, address _spender) public view returns (uint256) { _owner; _spender; } 33 | 34 | function transfer(address _to, uint256 _value) public returns (bool success); 35 | function transferFrom(address _from, address _to, uint256 _value) public returns (bool success); 36 | function approve(address _spender, uint256 _value) public returns (bool success); 37 | } 38 | 39 | 40 | 41 | contract UniswapExchangeInterface { 42 | // Address of ERC20 token sold on this exchange 43 | function tokenAddress() external view returns (address token); 44 | // Address of Uniswap Factory 45 | function factoryAddress() external view returns (address factory); 46 | // Provide Liquidity 47 | function addLiquidity(uint256 min_liquidity, uint256 max_tokens, uint256 deadline) external payable returns (uint256); 48 | function removeLiquidity(uint256 amount, uint256 min_eth, uint256 min_tokens, uint256 deadline) external returns (uint256, uint256); 49 | // Get Prices 50 | function getEthToTokenInputPrice(uint256 eth_sold) external view returns (uint256 tokens_bought); 51 | function getEthToTokenOutputPrice(uint256 tokens_bought) external view returns (uint256 eth_sold); 52 | function getTokenToEthInputPrice(uint256 tokens_sold) external view returns (uint256 eth_bought); 53 | function getTokenToEthOutputPrice(uint256 eth_bought) external view returns (uint256 tokens_sold); 54 | // Trade ETH to ERC20 55 | function ethToTokenSwapInput(uint256 min_tokens, uint256 deadline) external payable returns (uint256 tokens_bought); 56 | function ethToTokenTransferInput(uint256 min_tokens, uint256 deadline, address recipient) external payable returns (uint256 tokens_bought); 57 | function ethToTokenSwapOutput(uint256 tokens_bought, uint256 deadline) external payable returns (uint256 eth_sold); 58 | function ethToTokenTransferOutput(uint256 tokens_bought, uint256 deadline, address recipient) external payable returns (uint256 eth_sold); 59 | // Trade ERC20 to ETH 60 | function tokenToEthSwapInput(uint256 tokens_sold, uint256 min_eth, uint256 deadline) external returns (uint256 eth_bought); 61 | function tokenToEthTransferInput(uint256 tokens_sold, uint256 min_eth, uint256 deadline, address recipient) external returns (uint256 eth_bought); 62 | function tokenToEthSwapOutput(uint256 eth_bought, uint256 max_tokens, uint256 deadline) external returns (uint256 tokens_sold); 63 | function tokenToEthTransferOutput(uint256 eth_bought, uint256 max_tokens, uint256 deadline, address recipient) external returns (uint256 tokens_sold); 64 | // Trade ERC20 to ERC20 65 | function tokenToTokenSwapInput(uint256 tokens_sold, uint256 min_tokens_bought, uint256 min_eth_bought, uint256 deadline, address token_addr) external returns (uint256 tokens_bought); 66 | 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); 67 | function tokenToTokenSwapOutput(uint256 tokens_bought, uint256 max_tokens_sold, uint256 max_eth_sold, uint256 deadline, address token_addr) external returns (uint256 tokens_sold); 68 | 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); 69 | // Trade ERC20 to Custom Pool 70 | function tokenToExchangeSwapInput(uint256 tokens_sold, uint256 min_tokens_bought, uint256 min_eth_bought, uint256 deadline, address exchange_addr) external returns (uint256 tokens_bought); 71 | 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); 72 | function tokenToExchangeSwapOutput(uint256 tokens_bought, uint256 max_tokens_sold, uint256 max_eth_sold, uint256 deadline, address exchange_addr) external returns (uint256 tokens_sold); 73 | 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); 74 | // ERC20 comaptibility for liquidity tokens 75 | bytes32 public name; 76 | bytes32 public symbol; 77 | uint256 public decimals; 78 | function transfer(address _to, uint256 _value) external returns (bool); 79 | function transferFrom(address _from, address _to, uint256 value) external returns (bool); 80 | function approve(address _spender, uint256 _value) external returns (bool); 81 | function allowance(address _owner, address _spender) external view returns (uint256); 82 | function balanceOf(address _owner) external view returns (uint256); 83 | function totalSupply() external view returns (uint256); 84 | // Never use 85 | function setup(address token_addr) external; 86 | } 87 | 88 | 89 | 90 | 91 | library SafeMath { 92 | function mul(uint256 a, uint256 b) internal constant returns (uint256) { 93 | uint256 c = a * b; 94 | assert(a == 0 || c / a == b); 95 | return c; 96 | } 97 | 98 | function div(uint256 a, uint256 b) internal constant returns (uint256) { 99 | assert(b > 0); // Solidity automatically throws when dividing by 0 100 | uint256 c = a / b; 101 | assert(a == b * c + a % b); // There is no case in which this doesn't hold 102 | return c; 103 | } 104 | 105 | function sub(uint256 a, uint256 b) internal constant returns (uint256) { 106 | assert(b <= a); 107 | return a - b; 108 | } 109 | 110 | function add(uint256 a, uint256 b) internal constant returns (uint256) { 111 | uint256 c = a + b; 112 | assert(c >= a); 113 | return c; 114 | } 115 | } 116 | 117 | 118 | contract Portfolio1 { 119 | 120 | 121 | 122 | //3x Long ETH 123 | address leverageContractAddress= 0x00a8097a78893fb4623854d78f154b1034245191; 124 | fulcrumInterface fInt = fulcrumInterface(leverageContractAddress); 125 | 126 | //Dai Loan 127 | address loanContractAddress= 0x14094949152eddbfcd073717200da82fed8dc960; 128 | fulcrumInterface fInt2 = fulcrumInterface(loanContractAddress); 129 | 130 | address daiAddress = 0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359; 131 | 132 | address uniswapAddress = 0x09cabEC1eAd1c0Ba254B09efb3EE13841712bE14; 133 | UniswapExchangeInterface usi = UniswapExchangeInterface(uniswapAddress); 134 | 135 | using SafeMath for uint256; 136 | 137 | 138 | 139 | 140 | 141 | function () payable{ 142 | 143 | buyPackage(); 144 | } 145 | 146 | 147 | 148 | 149 | function buyPackage() payable returns(bool){ 150 | 151 | uint256 maxMint = 100000000000000000000000000000000000; 152 | uint256 createdAmount = 0; 153 | uint256 createdAmount2 = 0; 154 | 155 | ERC20 daiToken = ERC20(daiAddress); 156 | 157 | 158 | 159 | uint256 leverageAmountEth = msg.value.mul(10).div(100); 160 | uint256 loanAmountEth = msg.value.mul(90).div(100); 161 | 162 | 163 | uint256 daiBack = usi.ethToTokenSwapInput.value(loanAmountEth)(1, block.timestamp); 164 | 165 | daiToken.approve(loanContractAddress, 1000000000000000000000000000000); 166 | 167 | 168 | createdAmount = fInt.mintWithEther.value(leverageAmountEth)(msg.sender, maxMint); 169 | createdAmount2 = fInt2.mint(msg.sender, daiBack); 170 | 171 | 172 | 173 | 174 | return true; 175 | 176 | } 177 | } -------------------------------------------------------------------------------- /contracts/gift-lib/.solhint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "solhint:default" 3 | } 4 | -------------------------------------------------------------------------------- /contracts/gift-lib/giftcontract.sol: -------------------------------------------------------------------------------- 1 | //generated by www.structuredeth.com/gift 2 | 3 | // to-do: Update to 0.5.x; 4 | pragma solidity ^0.4.26; 5 | 6 | interface CompoundERC20 { 7 | function approve(address spender, uint256 amount) external returns(bool); 8 | 9 | function mint(uint256 mintAmount) external returns(uint256); 10 | 11 | function redeem(uint redeemTokens) external returns(uint); 12 | 13 | function totalSupply() public view returns(uint supply); 14 | 15 | function balanceOf(address _owner) public view returns(uint256 balance); 16 | 17 | function transfer(address _to, uint _value) public returns(bool success); 18 | 19 | function transferFrom(address _from, address _to, uint _value) public returns(bool success); 20 | 21 | function exchangeRateStored() public view returns(uint256 exchangeRate); 22 | } 23 | 24 | interface GiftRegistry { 25 | function addGift(address contractAddress, uint256 initialAmount); 26 | } 27 | 28 | interface IKyberNetworkProxy { 29 | function maxGasPrice() external view returns(uint); 30 | 31 | function getUserCapInWei(address user) external view returns(uint); 32 | 33 | function getUserCapInTokenWei(address user, ERC20 token) external view returns(uint); 34 | 35 | function enabled() external view returns(bool); 36 | 37 | function info(bytes32 id) external view returns(uint); 38 | 39 | function getExpectedRate( 40 | ERC20 src, 41 | ERC20 dest, 42 | uint srcQty 43 | ) external view returns(uint expectedRate, uint slippageRate); 44 | 45 | function tradeWithHint( 46 | ERC20 src, 47 | uint srcAmount, 48 | ERC20 dest, 49 | address destAddress, 50 | uint maxDestAmount, 51 | uint minConversionRate, 52 | address walletId, 53 | bytes hint 54 | ) external payable returns(uint); 55 | 56 | function swapEtherToToken(ERC20 token, uint minRate) external payable returns(uint); 57 | 58 | function swapTokenToEther(ERC20 token, uint tokenQty, uint minRate) external returns(uint); 59 | } 60 | 61 | 62 | library SafeMath { 63 | function mul(uint256 a, uint256 b) internal constant returns(uint256) { 64 | uint256 c = a * b; 65 | assert(a == 0 || c / a == b); 66 | return c; 67 | } 68 | 69 | function div(uint256 a, uint256 b) internal constant returns(uint256) { 70 | assert(b > 0); // Solidity automatically throws when dividing by 0 71 | uint256 c = a / b; 72 | assert(a == b * c + a % b); // There is no case in which this doesn't hold 73 | return c; 74 | } 75 | 76 | function sub(uint256 a, uint256 b) internal constant returns(uint256) { 77 | assert(b <= a); 78 | return a - b; 79 | } 80 | 81 | function add(uint256 a, uint256 b) internal constant returns(uint256) { 82 | uint256 c = a + b; 83 | assert(c >= a); 84 | return c; 85 | } 86 | } 87 | 88 | 89 | interface ERC20 { 90 | function totalSupply() public view returns(uint supply); 91 | 92 | function balanceOf(address _owner) public view returns(uint balance); 93 | 94 | function transfer(address _to, uint _value) public returns(bool success); 95 | 96 | function transferFrom(address _from, address _to, uint _value) public returns(bool success); 97 | 98 | function approve(address _spender, uint _value) public returns(bool success); 99 | 100 | function allowance(address _owner, address _spender) public view returns(uint remaining); 101 | 102 | function decimals() public view returns(uint digits); 103 | event Approval(address indexed _owner, address indexed _spender, uint _value); 104 | } 105 | 106 | 107 | contract GiftOfCompound { 108 | 109 | 110 | // to-do: Fix scoping of variables; 111 | // to-do: Clean up flow on entry functions 112 | // to-do: re-compose functions for better compartmentalization 113 | // to-do: write abstract interface for GiftOf contracts 114 | 115 | using SafeMath 116 | for uint256; 117 | address theRecipient; 118 | address theSender; 119 | bytes PERM_HINT; 120 | uint256 initialCDaiAmount; 121 | uint256 theInterestRecipient; 122 | uint256 theInterestSender; 123 | uint256 initialDaiAmount; 124 | uint256 initialcDaiDaiRate; 125 | uint256 startedWithGiftAmount; 126 | uint256 internal PRECISION; 127 | uint256 valueChange2Result; 128 | address cOffRamp; 129 | CompoundERC20 cdai; 130 | GiftRegistry giftRegistration; 131 | 132 | modifier onlyGiftGroup() { 133 | if (msg.sender != theSender && msg.sender != theRecipient) { 134 | throw; 135 | } 136 | _; 137 | } 138 | 139 | modifier onlyCOffRamp() { 140 | if (msg.sender != cOffRamp) { 141 | throw; 142 | } 143 | _; 144 | } 145 | 146 | 147 | //if smeone sends eth to this contract, throw it because it will just end up getting locked forever 148 | function() payable { 149 | throw; 150 | } 151 | 152 | constructor(address recipient, uint256 interestRecipient, uint256 interestSender) public payable { 153 | 154 | if (msg.value <= 0) { 155 | throw; 156 | } 157 | 158 | theSender = msg.sender; 159 | theRecipient = recipient; 160 | PRECISION = 10 ** 27; 161 | theInterestSender = interestSender; 162 | theInterestRecipient = interestRecipient; 163 | 164 | //sum of the interest percentage must be 100 so everyone can get their funds 165 | if (theInterestRecipient.add(theInterestSender) != 100) { 166 | throw; 167 | } 168 | 169 | startedWithGiftAmount = 0; 170 | initialCDaiAmount = giftWrap(); 171 | cOffRamp = 0x4C8A4aEbB3F28F9e50BDF16eD8491A1FF2CFB6fe; 172 | address regContractAddr = 0xb83353ddea4995c3c330cf1803fc1b9f07c0de88; 173 | giftRegistration = GiftRegistry(regContractAddr); 174 | giftRegistration.addGift(this, initialCDaiAmount); 175 | 176 | } 177 | 178 | function redeemAll(address _to) returns(bool) { 179 | uint256 canSendAmount = amountEntitledTo(msg.sender); 180 | transfer(_to, canSendAmount); 181 | return true; 182 | 183 | } 184 | 185 | function redeemAllToCentral(address _to) returns(bool) { 186 | uint256 canSendAmount = amountEntitledTo(msg.sender); 187 | transferKeepCDai(cOffRamp, canSendAmount); 188 | return true; 189 | } 190 | 191 | function transferKeepCDai(address _to, uint256 _value) onlyGiftGroup returns(bool) { 192 | 193 | uint256 userHasAccessTo = amountEntitledTo(msg.sender); 194 | ERC20 dai = ERC20(0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359); 195 | 196 | // you do not enough entitlement to the interest 197 | 198 | if (_value > userHasAccessTo) { 199 | throw; 200 | } else { 201 | uint256 currentCDai = cdai.balanceOf(this); 202 | require(dai.transfer(_to, currentCDai)); 203 | } 204 | 205 | /** 206 | * set initial amount to current amount so that people can keep 207 | * withdrawing and we can know if they are entiteld to the interest amount 208 | */ 209 | initialCDaiAmount = cdai.balanceOf(this); 210 | return true; 211 | } 212 | 213 | function transfer(address _to, uint256 _value) onlyGiftGroup returns(bool) { 214 | 215 | uint256 userHasAccessTo = amountEntitledTo(msg.sender); 216 | ERC20 dai = ERC20(0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359); 217 | 218 | //you do not enough entitlement to the interest 219 | if (_value > userHasAccessTo) { 220 | revert(); 221 | } else { 222 | cdai.redeem(_value); 223 | uint256 currentDai = dai.balanceOf(this); 224 | require(dai.transfer(_to, currentDai)); 225 | } 226 | 227 | /** 228 | * set initial amount to current amount so that people can keep 229 | * withdrawing and we can know if they are entiteld to the interest amount 230 | */ 231 | initialCDaiAmount = cdai.balanceOf(this); 232 | 233 | return true; 234 | } 235 | 236 | function giftWrap() internal returns(uint256) { 237 | ERC20 dai = ERC20(0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359); 238 | address kyberProxyAddress = 0x818E6FECD516Ecc3849DAf6845e3EC868087B755; 239 | IKyberNetworkProxy kyberProxy = IKyberNetworkProxy(kyberProxyAddress); 240 | cdai = CompoundERC20(0xf5dce57282a584d2746faf1593d3121fcac444dc); 241 | theRecipient.send(1500000000000000); 242 | uint256 ethAmount1 = msg.value.sub(1500000000000000); 243 | PERM_HINT = "PERM"; 244 | ERC20 eth = ERC20(0x00eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee); 245 | uint daiAmount = kyberProxy.tradeWithHint.value(ethAmount1)( 246 | eth, 247 | ethAmount1, 248 | dai, 249 | this, 250 | 8000000000000000000000000000000000000000000000000000000000000000, 251 | 0, 252 | 0x0000000000000000000000000000000000000004, 253 | PERM_HINT 254 | ); 255 | dai.approve(address(cdai), 8000000000000000000000000000000000000000000000000000000); 256 | cdai.mint(daiAmount); 257 | uint256 cdaiAmount = cdai.balanceOf(this); 258 | startedWithGiftAmount = cdaiAmount; 259 | initialDaiAmount = daiAmount; 260 | initialcDaiDaiRate = cdai.exchangeRateStored(); 261 | 262 | return cdaiAmount; 263 | } 264 | 265 | function changeCOffRamp(address newCOffRamp) onlyCOffRamp returns(bool) { 266 | cOffRamp = newCOffRamp; 267 | } 268 | 269 | function amountEntitledTo(address qAddress) constant returns(uint256) { 270 | uint256 initialExchangeRate = initialcDaiDaiRate; 271 | uint multiplier = 10000000; 272 | uint256 currentExchangeRate = cdai.exchangeRateStored().mul(multiplier); 273 | uint256 valueChange = currentExchangeRate.div(initialExchangeRate); 274 | uint256 valueChange2 = initialCDaiAmount.mul(valueChange).div(multiplier); 275 | uint256 totalInterestEarned = valueChange2.sub(initialCDaiAmount); 276 | uint256 usersPercentage; 277 | 278 | valueChange2Result = valueChange2; 279 | 280 | if (qAddress == theRecipient) { 281 | usersPercentage = theInterestSender; 282 | } else if (qAddress == theSender) { 283 | usersPercentage = theInterestSender; 284 | } else { 285 | return 0; 286 | } 287 | 288 | uint256 tInterestEntitledTo = totalInterestEarned.mul(usersPercentage).div(100); 289 | uint256 amountITo; 290 | 291 | 292 | // to-do: compartmentalize this if-web into internal function 293 | 294 | if (qAddress == theRecipient) { 295 | amountITo = initialCDaiAmount.sub(tInterestEntitledTo); 296 | } 297 | 298 | if (qAddress == theSender) { 299 | if (initialCDaiAmount == startedWithGiftAmount) { 300 | //nothing has been redeemed, so sender can refund 301 | amountITo = initialCDaiAmount; 302 | } else { 303 | amountITo = tInterestEntitledTo; 304 | } 305 | } 306 | 307 | return amountITo; 308 | 309 | } 310 | 311 | function getStartedWithGiftAmount() constant external returns(uint256) { 312 | return startedWithGiftAmount; 313 | } 314 | 315 | function getStartedWithDaiValueAmount() constant external returns(uint256) { 316 | return initialDaiAmount; 317 | } 318 | 319 | function getStartedWithCDaiDaiRate() constant external returns(uint256) { 320 | return initialcDaiDaiRate; 321 | } 322 | 323 | function getRecipient() constant external returns(address) { 324 | return theRecipient; 325 | } 326 | 327 | function getSender() constant external returns(address) { 328 | return theSender; 329 | } 330 | 331 | function percentageInterestEntitledTo(address qAddress) constant external returns(uint256) { 332 | uint256 usersPercentage; 333 | 334 | if (qAddress == theRecipient) { 335 | usersPercentage = theInterestRecipient; 336 | } else if (qAddress == theSender) { 337 | usersPercentage = theInterestSender; 338 | } else { 339 | usersPercentage = 0; 340 | } 341 | 342 | return usersPercentage; 343 | } 344 | 345 | function valueChangeVal() constant external returns(uint256) { 346 | 347 | uint256 initialExchangeRate = initialcDaiDaiRate; 348 | uint multiplier = 10000000; 349 | uint256 currentExchangeRate = cdai.exchangeRateStored().mul(multiplier); 350 | uint256 valueChange = currentExchangeRate.div(initialExchangeRate); 351 | uint256 valueChange2 = initialCDaiAmount.mul(valueChange).div(multiplier); 352 | uint256 totalInterestEarned = valueChange2.sub(initialCDaiAmount); 353 | 354 | return totalInterestEarned; 355 | } 356 | 357 | function currentGiftAmount() constant external returns(uint256) { 358 | uint256 cDaiMinted = cdai.balanceOf(this); 359 | return cDaiMinted; 360 | } 361 | } 362 | --------------------------------------------------------------------------------