Address Contract Partially Verified
Address
0x00d0f137b51692D0AC708bdE7b367a373865cFfe
Balance
0.772696 ETH ($1536.88)
Nonce
1
Code Size
9682 bytes
Creator
0xa0863436...dE29 at tx 0xa6a2d1d5...a32be7
Indexed Transactions
0
Contract Bytecode
9682 bytes
0x6080604052600436106100915760003560e01c8063715018a611610059578063715018a61461016a5780638da5cb5b1461017f5780638f32d59b146101b0578063b10e1dbc146101d9578063f2fde38b1461020757610091565b80631385d24c1461009357806325e07c3e146100a85780633ccfd60b146100f6578063551196d51461010b5780635de0398e1461013e575b005b34801561009f57600080fd5b5061009161023a565b6100e4600480360360808110156100be57600080fd5b506001600160a01b038135811691602081013590911690604081013590606001356102a2565b60408051918252519081900360200190f35b34801561010257600080fd5b506100916105a2565b34801561011757600080fd5b506100916004803603602081101561012e57600080fd5b50356001600160a01b0316610643565b34801561014a57600080fd5b50610153610799565b6040805161ffff9092168252519081900360200190f35b34801561017657600080fd5b506100916107aa565b34801561018b57600080fd5b50610194610840565b604080516001600160a01b039092168252519081900360200190f35b3480156101bc57600080fd5b506101c5610854565b604080519115158252519081900360200190f35b3480156101e557600080fd5b50610091600480360360208110156101fc57600080fd5b503561ffff1661087d565b34801561021357600080fd5b506100916004803603602081101561022a57600080fd5b50356001600160a01b0316610940565b610242610854565b610281576040805162461bcd60e51b8152602060048201819052602482015260008051602061257e833981519152604482015290519081900360640190fd5b6000805460ff60a81b198116600160a81b9182900460ff1615909102179055565b6000805460ff166102fa576040805162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015290519081900360640190fd5b6000805460ff191690819055600160a81b900460ff1615610357576040805162461bcd60e51b815260206004820152601260248201527115195b5c1bdc985c9a5b1e4814185d5cd95960721b604482015290519081900360640190fd5b6040805163615db6e160e11b81526001600160a01b03861660048201529051739424b1412450d0f8fc2255faf6046b98213b76bd9163c2bb6dc2916024808301926020929190829003018186803b1580156103b157600080fd5b505afa1580156103c5573d6000803e3d6000fd5b505050506040513d60208110156103db57600080fd5b5051610426576040805162461bcd60e51b8152602060048201526015602482015274125b9d985b1a590810985b185b98d95c88141bdbdb605a1b604482015290519081900360640190fd5b6000846001600160a01b0316632f37b624876040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b15801561047e57600080fd5b505afa158015610492573d6000803e3d6000fd5b505050506040513d60208110156104a857600080fd5b5051156104b657508461057c565b6001600160a01b03861615801561054f575060408051630bcded8960e21b815273c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2600482015290516001600160a01b03871691632f37b624916024808301926020929190829003018186803b15801561052257600080fd5b505afa158015610536573d6000803e3d6000fd5b505050506040513d602081101561054c57600080fd5b50515b1561056f575073c02aaa39b223fe8d0a0e5c4f27ead9083c756cc261057c565b6105798585610993565b90505b61058a338787878588610e59565b9150506000805460ff19166001179055949350505050565b6105aa610854565b6105e9576040805162461bcd60e51b8152602060048201819052602482015260008051602061257e833981519152604482015290519081900360640190fd5b4760006106056105f7610840565b6001600160a01b03166110b3565b6040519091506001600160a01b0382169083156108fc029084906000818181858888f1935050505015801561063e573d6000803e3d6000fd5b505050565b61064b610854565b61068a576040805162461bcd60e51b8152602060048201819052602482015260008051602061257e833981519152604482015290519081900360640190fd5b604080516370a0823160e01b815230600482015290516000916001600160a01b038416916370a0823191602480820192602092909190829003018186803b1580156106d457600080fd5b505afa1580156106e8573d6000803e3d6000fd5b505050506040513d60208110156106fe57600080fd5b505190506001600160a01b03821663a9059cbb610719610840565b836040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050602060405180830381600087803b15801561076957600080fd5b505af115801561077d573d6000803e3d6000fd5b505050506040513d602081101561079357600080fd5b50505050565b600054600160b01b900461ffff1681565b6107b2610854565b6107f1576040805162461bcd60e51b8152602060048201819052602482015260008051602061257e833981519152604482015290519081900360640190fd5b600080546040516101009091046001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a360008054610100600160a81b0319169055565b60005461010090046001600160a01b031690565b6000805461010090046001600160a01b031661086e6110b6565b6001600160a01b031614905090565b610885610854565b6108c4576040805162461bcd60e51b8152602060048201819052602482015260008051602061257e833981519152604482015290519081900360640190fd5b6127108161ffff161061091e576040805162461bcd60e51b815260206004820152601a60248201527f476f6f6457696c6c2056616c7565206e6f7420616c6c6f776564000000000000604482015290519081900360640190fd5b6000805461ffff909216600160b01b0261ffff60b01b19909216919091179055565b610948610854565b610987576040805162461bcd60e51b8152602060048201819052602482015260008051602061257e833981519152604482015290519081900360640190fd5b610990816110ba565b50565b60006060836001600160a01b031663be3bbd2e6040518163ffffffff1660e01b815260040160006040518083038186803b1580156109d057600080fd5b505afa1580156109e4573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526020811015610a0d57600080fd5b8101908080516040519392919084600160201b821115610a2c57600080fd5b908301906020820185811115610a4157600080fd5b82518660208202830111600160201b82111715610a5d57600080fd5b82525081516020918201928201910280838360005b83811015610a8a578181015183820152602001610a72565b505050509050016040525050509050600080600090505b8251811015610e50576000610aca8787868581518110610abd57fe5b6020026020010151611165565b905073c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316848381518110610af657fe5b60200260200101516001600160a01b031614610e245760006001600160a01b0316735c69bee701ef814a2b6a3edd4b1652cb9cc5aa6f6001600160a01b031663e6a43905868581518110610b4657fe5b602090810291909101810151604080516001600160e01b031960e086901b1681526001600160a01b03909216600483015273c02aaa39b223fe8d0a0e5c4f27ead9083c756cc260248301525160448083019392829003018186803b158015610bad57600080fd5b505afa158015610bc1573d6000803e3d6000fd5b505050506040513d6020811015610bd757600080fd5b50516001600160a01b03161415610bee5750610e48565b6040805160028082526060808301845292602083019080388339019050509050848381518110610c1a57fe5b602002602001015181600081518110610c2f57fe5b60200260200101906001600160a01b031690816001600160a01b03168152505073c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281600181518110610c7157fe5b6001600160a01b039092166020928302919091018201526040805163d06ca61f60e01b81526004810185815260248201928352845160448301528451600094737a250d5630b4cf539739df2c5dacb4c659f2488d9463d06ca61f9489948994909360649092019185810191028083838c5b83811015610cfa578181015183820152602001610ce2565b50505050905001935050505060006040518083038186803b158015610d1e57600080fd5b505afa158015610d32573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526020811015610d5b57600080fd5b8101908080516040519392919084600160201b821115610d7a57600080fd5b908301906020820185811115610d8f57600080fd5b82518660208202830111600160201b82111715610dab57600080fd5b82525081516020918201928201910280838360005b83811015610dd8578181015183820152602001610dc0565b50505050905001604052505050600181518110610df157fe5b6020026020010151905080851015610e1d57809450858481518110610e1257fe5b602002602001015196505b5050610e46565b80831015610e4657809250838281518110610e3b57fe5b602002602001015194505b505b600101610aa1565b50505092915050565b600080610e668686611450565b9050856001600160a01b03166323b872dd3330610e838986611580565b6040518463ffffffff1660e01b815260040180846001600160a01b03166001600160a01b03168152602001836001600160a01b03166001600160a01b031681526020018281526020019350505050602060405180830381600087803b158015610eeb57600080fd5b505af1158015610eff573d6000803e3d6000fd5b505050506040513d6020811015610f1557600080fd5b5051610f2057600080fd5b856001600160a01b0316632f37b624886040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b158015610f7657600080fd5b505afa158015610f8a573d6000803e3d6000fd5b505050506040513d6020811015610fa057600080fd5b505115610fc557610fbd86888a610fb78986611580565b876115c9565b9150506110a9565b6000610fdb8786610fd68986611580565b611705565b90506001600160a01b03881661109b576000610ff886838c6118e2565b90508481101561103f576040805162461bcd60e51b815260206004820152600d60248201526c4869676820736c69707061676560981b604482015290519081900360640190fd5b604080516001600160a01b03808d168252808b1660208301528b16818301526060810183905290517fccd66be260e4d251757c46211a144a9df723fe5d98726e537a900b7115b0e74d9181900360800190a192506110a9915050565b6000610ff8868b8b85611cdd565b9695505050505050565b90565b3390565b6001600160a01b0381166110ff5760405162461bcd60e51b81526004018080602001828103825260268152602001806125376026913960400191505060405180910390fd5b600080546040516001600160a01b038085169361010090930416917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0390921661010002610100600160a81b0319909216919091179055565b600080846001600160a01b03166318160ddd6040518163ffffffff1660e01b815260040160206040518083038186803b1580156111a157600080fd5b505afa1580156111b5573d6000803e3d6000fd5b505050506040513d60208110156111cb57600080fd5b505160408051631a995bed60e31b815290519192506000916001600160a01b0388169163d4cadf68916004808301926020929190829003018186803b15801561121357600080fd5b505afa158015611227573d6000803e3d6000fd5b505050506040513d602081101561123d57600080fd5b50516040805163936c347760e01b815290519192506000916001600160a01b0389169163936c3477916004808301926020929190829003018186803b15801561128557600080fd5b505afa158015611299573d6000803e3d6000fd5b505050506040513d60208110156112af57600080fd5b50516040805163f8b2cb4f60e01b81526001600160a01b0388811660048301529151929350600092918a169163f8b2cb4f91602480820192602092909190829003018186803b15801561130157600080fd5b505afa158015611315573d6000803e3d6000fd5b505050506040513d602081101561132b57600080fd5b505160408051634a46c67360e11b81526001600160a01b0389811660048301529151929350600092918b169163948d8ce691602480820192602092909190829003018186803b15801561137d57600080fd5b505afa158015611391573d6000803e3d6000fd5b505050506040513d60208110156113a757600080fd5b505160408051634494c00960e11b815260048101859052602481018390526044810188905260648101869052608481018b905260a4810187905290519192506001600160a01b038b169163892980129160c480820192602092909190829003018186803b15801561141757600080fd5b505afa15801561142b573d6000803e3d6000fd5b505050506040513d602081101561144157600080fd5b50519998505050505050505050565b60008054600160b01b900461ffff1661146b5750600061157a565b60005461149090611488908490600160b01b900461ffff16612235565b61271061228e565b604080516323b872dd60e01b815233600482015273e737b6afec2320f616297e59445b60a11e3ef75f60248201526044810183905290519192506001600160a01b038516916323b872dd916064808201926020929091908290030181600087803b1580156114fd57600080fd5b505af1158015611511573d6000803e3d6000fd5b505050506040513d602081101561152757600080fd5b505161157a576040805162461bcd60e51b815260206004820152601b60248201527f4572726f7220696e207472616e7366657272696e67204250543a310000000000604482015290519081900360640190fd5b92915050565b60006115c283836040518060400160405280601e81526020017f536166654d6174683a207375627472616374696f6e206f766572666c6f7700008152506122d0565b9392505050565b60006115d6868685611705565b90508181101561161d576040805162461bcd60e51b815260206004820152600d60248201526c4869676820736c69707061676560981b604482015290519081900360640190fd5b604080516001600160a01b03808716825280891660208301528716818301526060810183905290517fccd66be260e4d251757c46211a144a9df723fe5d98726e537a900b7115b0e74d9181900360800190a1846001600160a01b031663a9059cbb85836040518363ffffffff1660e01b815260040180836001600160a01b03166001600160a01b0316815260200182815260200192505050602060405180830381600087803b1580156116cf57600080fd5b505af11580156116e3573d6000803e3d6000fd5b505050506040513d60208110156116f957600080fd5b50909695505050505050565b6000836001600160a01b0316632f37b624846040518263ffffffff1660e01b815260040180826001600160a01b03166001600160a01b0316815260200191505060206040518083038186803b15801561175d57600080fd5b505afa158015611771573d6000803e3d6000fd5b505050506040513d602081101561178757600080fd5b50516117cc576040805162461bcd60e51b815260206004820152600f60248201526e151bdad95b881b9bdd08189bdd5b99608a1b604482015290519081900360640190fd5b60006117d9858486611165565b90506117f06117e9826062612235565b606461228e565b9050846001600160a01b03166346ab38f18585846040518463ffffffff1660e01b815260040180846001600160a01b03166001600160a01b031681526020018381526020018281526020019350505050602060405180830381600087803b15801561185a57600080fd5b505af115801561186e573d6000803e3d6000fd5b505050506040513d602081101561188457600080fd5b50519150816118da576040805162461bcd60e51b815260206004820152601e60248201527f4572726f7220696e2065786974696e672062616c616e63657220706f6f6c0000604482015290519081900360640190fd5b509392505050565b60006001600160a01b03841673c02aaa39b223fe8d0a0e5c4f27ead9083c756cc214156119ba5773c02aaa39b223fe8d0a0e5c4f27ead9083c756cc26001600160a01b0316632e1a7d4d846040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b15801561196357600080fd5b505af1158015611977573d6000803e3d6000fd5b50506040516001600160a01b038516925085156108fc02915085906000818181858888f193505050501580156119b1573d6000803e3d6000fd5b508290506115c2565b6040805163095ea7b360e01b8152737a250d5630b4cf539739df2c5dacb4c659f2488d60048201526024810185905290516001600160a01b0386169163095ea7b39160448083019260209291908290030181600087803b158015611a1d57600080fd5b505af1158015611a31573d6000803e3d6000fd5b505050506040513d6020811015611a4757600080fd5b505060408051600280825260608083018452926020830190803883390190505090508481600081518110611a7757fe5b60200260200101906001600160a01b031690816001600160a01b03168152505073c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281600181518110611ab957fe5b60200260200101906001600160a01b031690816001600160a01b031681525050737a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b03166318cbafe58560018487600f60fc1b6040518663ffffffff1660e01b81526004018086815260200185815260200180602001846001600160a01b03166001600160a01b03168152602001838152602001828103825285818151815260200191508051906020019060200280838360005b83811015611b7f578181015183820152602001611b67565b505050509050019650505050505050600060405180830381600087803b158015611ba857600080fd5b505af1158015611bbc573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526020811015611be557600080fd5b8101908080516040519392919084600160201b821115611c0457600080fd5b908301906020820185811115611c1957600080fd5b82518660208202830111600160201b82111715611c3557600080fd5b82525081516020918201928201910280838360005b83811015611c62578181015183820152602001611c4a565b50505050905001604052505050600182510381518110611c7e57fe5b60200260200101519150600082116118da576040805162461bcd60e51b815260206004820152601860248201527f4572726f7220696e207377617070696e67204574683a20310000000000000000604482015290519081900360640190fd5b6000611cfe85737a250d5630b4cf539739df2c5dacb4c659f2488d84612367565b6001600160a01b03851673c02aaa39b223fe8d0a0e5c4f27ead9083c756cc214611f9757604080516003808252608082019092526060916020820183803883390190505090508581600081518110611d5257fe5b60200260200101906001600160a01b031690816001600160a01b03168152505073c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281600181518110611d9457fe5b60200260200101906001600160a01b031690816001600160a01b0316815250508381600281518110611dc257fe5b60200260200101906001600160a01b031690816001600160a01b031681525050737a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b03166338ed17398460018489600f60fc1b6040518663ffffffff1660e01b81526004018086815260200185815260200180602001846001600160a01b03166001600160a01b03168152602001838152602001828103825285818151815260200191508051906020019060200280838360005b83811015611e88578181015183820152602001611e70565b505050509050019650505050505050600060405180830381600087803b158015611eb157600080fd5b505af1158015611ec5573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526020811015611eee57600080fd5b8101908080516040519392919084600160201b821115611f0d57600080fd5b908301906020820185811115611f2257600080fd5b82518660208202830111600160201b82111715611f3e57600080fd5b82525081516020918201928201910280838360005b83811015611f6b578181015183820152602001611f53565b50505050905001604052505050600182510381518110611f8757fe5b60200260200101519150506121d8565b604080516002808252606080830184529260208301908038833901905050905073c02aaa39b223fe8d0a0e5c4f27ead9083c756cc281600081518110611fd957fe5b60200260200101906001600160a01b031690816001600160a01b031681525050838160018151811061200757fe5b60200260200101906001600160a01b031690816001600160a01b031681525050737a250d5630b4cf539739df2c5dacb4c659f2488d6001600160a01b03166338ed17398460018489600f60fc1b6040518663ffffffff1660e01b81526004018086815260200185815260200180602001846001600160a01b03166001600160a01b03168152602001838152602001828103825285818151815260200191508051906020019060200280838360005b838110156120cd5781810151838201526020016120b5565b505050509050019650505050505050600060405180830381600087803b1580156120f657600080fd5b505af115801561210a573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052602081101561213357600080fd5b8101908080516040519392919084600160201b82111561215257600080fd5b90830190602082018581111561216757600080fd5b82518660208202830111600160201b8211171561218357600080fd5b82525081516020918201928201910280838360005b838110156121b0578181015183820152602001612198565b505050509050016040525050506001825103815181106121cc57fe5b60200260200101519150505b6000811161222d576040805162461bcd60e51b815260206004820152601860248201527f4572726f7220696e207377617070696e67204552433a20310000000000000000604482015290519081900360640190fd5b949350505050565b6000826122445750600061157a565b8282028284828161225157fe5b04146115c25760405162461bcd60e51b815260040180806020018281038252602181526020018061255d6021913960400191505060405180910390fd5b60006115c283836040518060400160405280601a81526020017f536166654d6174683a206469766973696f6e206279207a65726f0000000000008152506124d1565b6000818484111561235f5760405162461bcd60e51b81526004018080602001828103825283818151815260200191508051906020019080838360005b8381101561232457818101518382015260200161230c565b50505050905090810190601f1680156123515780820380516001836020036101000a031916815260200191505b509250505060405180910390fd5b505050900390565b604080516001600160a01b038481166024830152604480830185905283518084039091018152606490920183526020820180516001600160e01b031663095ea7b360e01b178152925182516000946060949389169392918291908083835b602083106123e45780518252601f1990920191602091820191016123c5565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d8060008114612446576040519150601f19603f3d011682016040523d82523d6000602084013e61244b565b606091505b5091509150818015612479575080511580612479575080806020019051602081101561247657600080fd5b50515b6124ca576040805162461bcd60e51b815260206004820152601e60248201527f5472616e7366657248656c7065723a20415050524f56455f4641494c45440000604482015290519081900360640190fd5b5050505050565b600081836125205760405162461bcd60e51b815260206004820181815283516024840152835190928392604490910191908501908083836000831561232457818101518382015260200161230c565b50600083858161252c57fe5b049594505050505056fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f2061646472657373536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f774f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572a265627a7a72315820fd2c145f1dee4bc3b8627757d4358c84d64ae73e3135eb561180b874790168b164736f6c63430005110032
Verified Source Code Partial Match
Compiler: v0.5.17+commit.d19bba13
EVM: istanbul
Optimization: Yes (200 runs)
Balancer_ZapOut_General_V2_2.sol 1255 lines
// ███████╗░█████╗░██████╗░██████╗░███████╗██████╗░░░░███████╗██╗
// ╚════██║██╔══██╗██╔══██╗██╔══██╗██╔════╝██╔══██╗░░░██╔════╝██║
// ░░███╔═╝███████║██████╔╝██████╔╝█████╗░░██████╔╝░░░█████╗░░██║
// ██╔══╝░░██╔══██║██╔═══╝░██╔═══╝░██╔══╝░░██╔══██╗░░░██╔══╝░░██║
// ███████╗██║░░██║██║░░░░░██║░░░░░███████╗██║░░██║██╗██║░░░░░██║
// ╚══════╝╚═╝░░╚═╝╚═╝░░░░░╚═╝░░░░░╚══════╝╚═╝░░╚═╝╚═╝╚═╝░░░░░╚═╝
// Copyright (C) 2020 zapper, nodar, suhail, seb, sumit, apoorv
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
///@author Zapper
///@notice This contract adds removes liquidity from Balancer Pools into ETH/ERC/Underlying Tokens.
// SPDX-License-Identifier: GPLv2
// File: @openzeppelin/contracts/utils/Address.sol
pragma solidity ^0.5.5;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash
= 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly {
codehash := extcodehash(account)
}
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Converts an `address` into `address payable`. Note that this is
* simply a type cast: the actual underlying value is not changed.
*
* _Available since v2.4.0._
*/
function toPayable(address account)
internal
pure
returns (address payable)
{
return address(uint160(account));
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*
* _Available since v2.4.0._
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(
address(this).balance >= amount,
"Address: insufficient balance"
);
// solhint-disable-next-line avoid-call-value
(bool success, ) = recipient.call.value(amount)("");
require(
success,
"Address: unable to send value, recipient may have reverted"
);
}
}
// File: @openzeppelin/contracts/token/ERC20/IERC20.sol
pragma solidity ^0.5.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP. Does not include
* the optional functions; to access them see {ERC20Detailed}.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount)
external
returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender)
external
view
returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(
address indexed owner,
address indexed spender,
uint256 value
);
}
// File: @openzeppelin/contracts/GSN/Context.sol
pragma solidity ^0.5.0;
/*
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
contract Context {
// Empty internal constructor, to prevent people from mistakenly deploying
// an instance of this contract, which should be used via inheritance.
constructor() internal {}
// solhint-disable-previous-line no-empty-blocks
function _msgSender() internal view returns (address payable) {
return msg.sender;
}
function _msgData() internal view returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
}
// File: @openzeppelin/contracts/ownership/Ownable.sol
pragma solidity ^0.5.0;
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
contract Ownable is Context {
address private _owner;
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(isOwner(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Returns true if the caller is the current owner.
*/
function isOwner() public view returns (bool) {
return _msgSender() == _owner;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public onlyOwner {
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
*/
function _transferOwnership(address newOwner) internal {
require(
newOwner != address(0),
"Ownable: new owner is the zero address"
);
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
}
// File: @openzeppelin/contracts/utils/ReentrancyGuard.sol
pragma solidity ^0.5.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*
* _Since v2.5.0:_ this module is now much more gas efficient, given net gas
* metering changes introduced in the Istanbul hardfork.
*/
contract ReentrancyGuard {
bool private _notEntered;
constructor() internal {
// Storing an initial non-zero value makes deployment a bit more
// expensive, but in exchange the refund on every call to nonReentrant
// will be lower in amount. Since refunds are capped to a percetange of
// the total transaction's gas, it is best to keep them low in cases
// like this one, to increase the likelihood of the full refund coming
// into effect.
_notEntered = true;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and make it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
// On the first call to nonReentrant, _notEntered will be true
require(_notEntered, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_notEntered = false;
_;
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_notEntered = true;
}
}
// File: @openzeppelin/contracts/math/SafeMath.sol
pragma solidity ^0.5.0;
/**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot overflow.
*
* _Available since v2.4.0._
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*
* _Available since v2.4.0._
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*
* _Available since v2.4.0._
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
}
// File: contracts/Balancer/Balancer_ZapOut_General_V2_2.sol
pragma solidity ^0.5.12;
interface IBFactory_Balancer_Unzap_V1_1 {
function isBPool(address b) external view returns (bool);
}
interface IBPool_Balancer_Unzap_V1_1 {
function exitswapPoolAmountIn(
address tokenOut,
uint256 poolAmountIn,
uint256 minAmountOut
) external payable returns (uint256 tokenAmountOut);
function totalSupply() external view returns (uint256);
function getFinalTokens() external view returns (address[] memory tokens);
function getDenormalizedWeight(address token)
external
view
returns (uint256);
function getTotalDenormalizedWeight() external view returns (uint256);
function getSwapFee() external view returns (uint256);
function isBound(address t) external view returns (bool);
function calcSingleOutGivenPoolIn(
uint256 tokenBalanceOut,
uint256 tokenWeightOut,
uint256 poolSupply,
uint256 totalWeight,
uint256 poolAmountIn,
uint256 swapFee
) external pure returns (uint256 tokenAmountOut);
function getBalance(address token) external view returns (uint256);
}
interface IuniswapFactory_Balancer_Unzap_V1_1 {
function getExchange(address token)
external
view
returns (address exchange);
}
interface Iuniswap_Balancer_Unzap_V1_1 {
// converting ERC20 to ERC20 and transfer
function tokenToTokenTransferInput(
uint256 tokens_sold,
uint256 min_tokens_bought,
uint256 min_eth_bought,
uint256 deadline,
address recipient,
address token_addr
) external returns (uint256 tokens_bought);
function getTokenToEthInputPrice(uint256 tokens_sold)
external
view
returns (uint256 eth_bought);
function getEthToTokenInputPrice(uint256 eth_sold)
external
view
returns (uint256 tokens_bought);
function tokenToEthTransferInput(
uint256 tokens_sold,
uint256 min_eth,
uint256 deadline,
address recipient
) external returns (uint256 eth_bought);
function balanceOf(address _owner) external view returns (uint256);
function transfer(address _to, uint256 _value) external returns (bool);
function transferFrom(
address from,
address to,
uint256 tokens
) external returns (bool success);
}
interface IWETH {
function deposit() external payable;
function transfer(address to, uint256 value) external returns (bool);
function withdraw(uint256) external;
}
library TransferHelper {
function safeApprove(
address token,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('approve(address,uint256)')));
(bool success, bytes memory data) = token.call(
abi.encodeWithSelector(0x095ea7b3, to, value)
);
require(
success && (data.length == 0 || abi.decode(data, (bool))),
"TransferHelper: APPROVE_FAILED"
);
}
function safeTransfer(
address token,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('transfer(address,uint256)')));
(bool success, bytes memory data) = token.call(
abi.encodeWithSelector(0xa9059cbb, to, value)
);
require(
success && (data.length == 0 || abi.decode(data, (bool))),
"TransferHelper: TRANSFER_FAILED"
);
}
function safeTransferFrom(
address token,
address from,
address to,
uint256 value
) internal {
// bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
(bool success, bytes memory data) = token.call(
abi.encodeWithSelector(0x23b872dd, from, to, value)
);
require(
success && (data.length == 0 || abi.decode(data, (bool))),
"TransferHelper: TRANSFER_FROM_FAILED"
);
}
}
interface IUniswapV2Factory {
function getPair(address tokenA, address tokenB)
external
view
returns (address);
}
interface IUniswapRouter02 {
//get estimated amountOut
function getAmountsOut(uint256 amountIn, address[] calldata path)
external
view
returns (uint256[] memory amounts);
function getAmountsIn(uint256 amountOut, address[] calldata path)
external
view
returns (uint256[] memory amounts);
//token 2 token
function swapExactTokensForTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapTokensForExactTokens(
uint256 amountOut,
uint256 amountInMax,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
//eth 2 token
function swapExactETHForTokens(
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external payable returns (uint256[] memory amounts);
function swapETHForExactTokens(
uint256 amountOut,
address[] calldata path,
address to,
uint256 deadline
) external payable returns (uint256[] memory amounts);
//token 2 eth
function swapTokensForExactETH(
uint256 amountOut,
uint256 amountInMax,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapExactTokensForETH(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
}
contract Balancer_ZapOut_General_V2_2 is ReentrancyGuard, Ownable {
using SafeMath for uint256;
using Address for address;
bool private stopped = false;
uint16 public goodwill;
address
private constant zgoodwillAddress = 0xE737b6AfEC2320f616297e59445b60a11e3eF75F;
IUniswapV2Factory
private constant UniSwapV2FactoryAddress = IUniswapV2Factory(
0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f
);
IUniswapRouter02 private constant uniswapRouter = IUniswapRouter02(
0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
);
IBFactory_Balancer_Unzap_V1_1
private constant BalancerFactory = IBFactory_Balancer_Unzap_V1_1(
0x9424B1412450D0f8Fc2255FAf6046b98213B76Bd
);
address
private constant wethTokenAddress = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2;
uint256
private constant deadline = 0xf000000000000000000000000000000000000000000000000000000000000000;
event Zapout(
address _toWhomToIssue,
address _fromBalancerPoolAddress,
address _toTokenContractAddress,
uint256 _OutgoingAmount
);
constructor(uint16 _goodwill) public {
goodwill = _goodwill;
}
// circuit breaker modifiers
modifier stopInEmergency {
if (stopped) {
revert("Temporarily Paused");
} else {
_;
}
}
/**
@notice This function is used for zapping out of balancer pools
@param _ToTokenContractAddress The token in which we want zapout (for ethers, its zero address)
@param _FromBalancerPoolAddress The address of balancer pool to zap out
@param _IncomingBPT The quantity of balancer pool tokens
@param _minTokensRec slippage user wants
@return success or failure
*/
function EasyZapOut(
address _ToTokenContractAddress,
address _FromBalancerPoolAddress,
uint256 _IncomingBPT,
uint256 _minTokensRec
) public payable nonReentrant stopInEmergency returns (uint256) {
require(
BalancerFactory.isBPool(_FromBalancerPoolAddress),
"Invalid Balancer Pool"
);
address _FromTokenAddress;
if (
IBPool_Balancer_Unzap_V1_1(_FromBalancerPoolAddress).isBound(
_ToTokenContractAddress
)
) {
_FromTokenAddress = _ToTokenContractAddress;
} else if (
_ToTokenContractAddress == address(0) &&
IBPool_Balancer_Unzap_V1_1(_FromBalancerPoolAddress).isBound(
wethTokenAddress
)
) {
_FromTokenAddress = wethTokenAddress;
} else {
_FromTokenAddress = _getBestDeal(
_FromBalancerPoolAddress,
_IncomingBPT
);
}
return (
_performZapOut(
msg.sender,
_ToTokenContractAddress,
_FromBalancerPoolAddress,
_IncomingBPT,
_FromTokenAddress,
_minTokensRec
)
);
}
/**
@notice This method is called by ZapOut and EasyZapOut()
@param _toWhomToIssue is the address of user
@param _ToTokenContractAddress is the address of the token to which you want to convert to
@param _FromBalancerPoolAddress the address of the Balancer Pool from which you want to ZapOut
@param _IncomingBPT is the quantity of Balancer Pool tokens that the user wants to ZapOut
@param _IntermediateToken is the token to which the Balancer Pool should be Zapped Out
@notice this is only used if the outgoing token is not amongst the Balancer Pool tokens
@return success or failure
*/
function _performZapOut(
address payable _toWhomToIssue,
address _ToTokenContractAddress,
address _FromBalancerPoolAddress,
uint256 _IncomingBPT,
address _IntermediateToken,
uint256 _minTokensRec
) internal returns (uint256) {
//transfer goodwill
uint256 goodwillPortion = _transferGoodwill(
_FromBalancerPoolAddress,
_IncomingBPT
);
require(
IERC20(_FromBalancerPoolAddress).transferFrom(
msg.sender,
address(this),
SafeMath.sub(_IncomingBPT, goodwillPortion)
)
);
if (
IBPool_Balancer_Unzap_V1_1(_FromBalancerPoolAddress).isBound(
_ToTokenContractAddress
)
) {
return (
_directZapout(
_FromBalancerPoolAddress,
_ToTokenContractAddress,
_toWhomToIssue,
SafeMath.sub(_IncomingBPT, goodwillPortion),
_minTokensRec
)
);
}
//exit balancer
uint256 _returnedTokens = _exitBalancer(
_FromBalancerPoolAddress,
_IntermediateToken,
SafeMath.sub(_IncomingBPT, goodwillPortion)
);
if (_ToTokenContractAddress == address(0)) {
uint256 ethBought = _token2Eth(
_IntermediateToken,
_returnedTokens,
_toWhomToIssue
);
require(ethBought >= _minTokensRec, "High slippage");
emit Zapout(
_toWhomToIssue,
_FromBalancerPoolAddress,
_ToTokenContractAddress,
ethBought
);
return ethBought;
} else {
uint256 tokenBought = _token2Token(
_IntermediateToken,
_toWhomToIssue,
_ToTokenContractAddress,
_returnedTokens
);
require(tokenBought >= _minTokensRec, "High slippage");
emit Zapout(
_toWhomToIssue,
_FromBalancerPoolAddress,
_ToTokenContractAddress,
tokenBought
);
return tokenBought;
}
}
/**
@notice This function is used for zapping out of balancer pool
@param _FromBalancerPoolAddress The address of balancer pool to zap out
@param _ToTokenContractAddress The token in which we want to zapout (for ethers, its zero address)
@param _toWhomToIssue The address of user
@param tokens2Trade The quantity of balancer pool tokens
@return success or failure
*/
function _directZapout(
address _FromBalancerPoolAddress,
address _ToTokenContractAddress,
address _toWhomToIssue,
uint256 tokens2Trade,
uint256 _minTokensRec
) internal returns (uint256 returnedTokens) {
returnedTokens = _exitBalancer(
_FromBalancerPoolAddress,
_ToTokenContractAddress,
tokens2Trade
);
require(returnedTokens >= _minTokensRec, "High slippage");
emit Zapout(
_toWhomToIssue,
_FromBalancerPoolAddress,
_ToTokenContractAddress,
returnedTokens
);
IERC20(_ToTokenContractAddress).transfer(
_toWhomToIssue,
returnedTokens
);
}
/**
@notice This function is used to calculate and transfer goodwill
@param _tokenContractAddress Token address in which goodwill is deducted
@param tokens2Trade The total amount of tokens to be zapped out
@return The amount of goodwill deducted
*/
function _transferGoodwill(
address _tokenContractAddress,
uint256 tokens2Trade
) internal returns (uint256 goodwillPortion) {
if (goodwill == 0) {
return 0;
}
goodwillPortion = SafeMath.div(
SafeMath.mul(tokens2Trade, goodwill),
10000
);
require(
IERC20(_tokenContractAddress).transferFrom(
msg.sender,
zgoodwillAddress,
goodwillPortion
),
"Error in transferring BPT:1"
);
return goodwillPortion;
}
/**
@notice This function finds best token from the final tokens of balancer pool
@param _FromBalancerPoolAddress The address of balancer pool to zap out
@param _IncomingBPT The amount of balancer pool token to covert
@return The token address having max liquidity
*/
function _getBestDeal(
address _FromBalancerPoolAddress,
uint256 _IncomingBPT
) internal view returns (address _token) {
//get token list
address[] memory tokens = IBPool_Balancer_Unzap_V1_1(
_FromBalancerPoolAddress
)
.getFinalTokens();
uint256 maxEth;
for (uint256 index = 0; index < tokens.length; index++) {
//get token for given bpt amount
uint256 tokensForBPT = _getBPT2Token(
_FromBalancerPoolAddress,
_IncomingBPT,
tokens[index]
);
//get eth value for each token
if (tokens[index] != wethTokenAddress) {
if (
UniSwapV2FactoryAddress.getPair(
tokens[index],
wethTokenAddress
) == address(0)
) {
continue;
}
address[] memory path = new address[](2);
path[0] = tokens[index];
path[1] = wethTokenAddress;
uint256 ethReturned = uniswapRouter.getAmountsOut(
tokensForBPT,
path
)[1];
//get max eth value
if (maxEth < ethReturned) {
maxEth = ethReturned;
_token = tokens[index];
}
} else {
//get max eth value
if (maxEth < tokensForBPT) {
maxEth = tokensForBPT;
_token = tokens[index];
}
}
}
}
/**
@notice This function gives the amount of tokens on zapping out from given BPool
@param _FromBalancerPoolAddress Address of balancer pool to zapout from
@param _IncomingBPT The amount of BPT to zapout
@param _toToken Address of token to zap out with
@return Amount of ERC token
*/
function _getBPT2Token(
address _FromBalancerPoolAddress,
uint256 _IncomingBPT,
address _toToken
) internal view returns (uint256 tokensReturned) {
uint256 totalSupply = IBPool_Balancer_Unzap_V1_1(
_FromBalancerPoolAddress
)
.totalSupply();
uint256 swapFee = IBPool_Balancer_Unzap_V1_1(_FromBalancerPoolAddress)
.getSwapFee();
uint256 totalWeight = IBPool_Balancer_Unzap_V1_1(
_FromBalancerPoolAddress
)
.getTotalDenormalizedWeight();
uint256 balance = IBPool_Balancer_Unzap_V1_1(_FromBalancerPoolAddress)
.getBalance(_toToken);
uint256 denorm = IBPool_Balancer_Unzap_V1_1(_FromBalancerPoolAddress)
.getDenormalizedWeight(_toToken);
tokensReturned = IBPool_Balancer_Unzap_V1_1(_FromBalancerPoolAddress)
.calcSingleOutGivenPoolIn(
balance,
denorm,
totalSupply,
totalWeight,
_IncomingBPT,
swapFee
);
}
/**
@notice This function is used to zap out of the given balancer pool
@param _FromBalancerPoolAddress The address of balancer pool to zap out
@param _ToTokenContractAddress The Token address which will be zapped out
@param _amount The amount of token for zapout
@return The amount of tokens received after zap out
*/
function _exitBalancer(
address _FromBalancerPoolAddress,
address _ToTokenContractAddress,
uint256 _amount
) internal returns (uint256 returnedTokens) {
require(
IBPool_Balancer_Unzap_V1_1(_FromBalancerPoolAddress).isBound(
_ToTokenContractAddress
),
"Token not bound"
);
uint256 minTokens = _getBPT2Token(
_FromBalancerPoolAddress,
_amount,
_ToTokenContractAddress
);
minTokens = SafeMath.div(SafeMath.mul(minTokens, 98), 100);
returnedTokens = IBPool_Balancer_Unzap_V1_1(_FromBalancerPoolAddress)
.exitswapPoolAmountIn(_ToTokenContractAddress, _amount, minTokens);
require(returnedTokens > 0, "Error in exiting balancer pool");
}
/**
@notice This function is used to swap tokens
@param _FromTokenContractAddress The token address to swap from
@param _ToWhomToIssue The address to transfer after swap
@param _ToTokenContractAddress The token address to swap to
@param tokens2Trade The quantity of tokens to swap
@return The amount of tokens returned after swap
*/
function _token2Token(
address _FromTokenContractAddress,
address _ToWhomToIssue,
address _ToTokenContractAddress,
uint256 tokens2Trade
) internal returns (uint256 tokenBought) {
TransferHelper.safeApprove(
_FromTokenContractAddress,
address(uniswapRouter),
tokens2Trade
);
if (_FromTokenContractAddress != wethTokenAddress) {
address[] memory path = new address[](3);
path[0] = _FromTokenContractAddress;
path[1] = wethTokenAddress;
path[2] = _ToTokenContractAddress;
tokenBought = uniswapRouter.swapExactTokensForTokens(
tokens2Trade,
1,
path,
_ToWhomToIssue,
deadline
)[path.length - 1];
} else {
address[] memory path = new address[](2);
path[0] = wethTokenAddress;
path[1] = _ToTokenContractAddress;
tokenBought = uniswapRouter.swapExactTokensForTokens(
tokens2Trade,
1,
path,
_ToWhomToIssue,
deadline
)[path.length - 1];
}
require(tokenBought > 0, "Error in swapping ERC: 1");
}
/**
@notice This function is used to swap tokens to eth
@param _FromTokenContractAddress The token address to swap from
@param tokens2Trade The quantity of tokens to swap
@param _toWhomToIssue The address to transfer after swap
@return The amount of ether returned after swap
*/
function _token2Eth(
address _FromTokenContractAddress,
uint256 tokens2Trade,
address payable _toWhomToIssue
) internal returns (uint256 ethBought) {
if (_FromTokenContractAddress == wethTokenAddress) {
IWETH(wethTokenAddress).withdraw(tokens2Trade);
_toWhomToIssue.transfer(tokens2Trade);
return tokens2Trade;
}
IERC20(_FromTokenContractAddress).approve(
address(uniswapRouter),
tokens2Trade
);
address[] memory path = new address[](2);
path[0] = _FromTokenContractAddress;
path[1] = wethTokenAddress;
ethBought = uniswapRouter.swapExactTokensForETH(
tokens2Trade,
1,
path,
_toWhomToIssue,
deadline
)[path.length - 1];
require(ethBought > 0, "Error in swapping Eth: 1");
}
function set_new_goodwill(uint16 _new_goodwill) public onlyOwner {
require(
_new_goodwill >= 0 && _new_goodwill < 10000,
"GoodWill Value not allowed"
);
goodwill = _new_goodwill;
}
function inCaseTokengetsStuck(IERC20 _TokenAddress) public onlyOwner {
uint256 qty = _TokenAddress.balanceOf(address(this));
_TokenAddress.transfer(owner(), qty);
}
// - to Pause the contract
function toggleContractActive() public onlyOwner {
stopped = !stopped;
}
// - to withdraw any ETH balance sitting in the contract
function withdraw() public onlyOwner {
uint256 contractBalance = address(this).balance;
address payable _to = owner().toPayable();
_to.transfer(contractBalance);
}
function() external payable {}
}
Read Contract
goodwill 0x5de0398e → uint16
isOwner 0x8f32d59b → bool
owner 0x8da5cb5b → address
Write Contract 7 functions
These functions modify contract state and require a wallet transaction to execute.
EasyZapOut 0x25e07c3e
address _ToTokenContractAddress
address _FromBalancerPoolAddress
uint256 _IncomingBPT
uint256 _minTokensRec
returns: uint256
inCaseTokengetsStuck 0x551196d5
address _TokenAddress
renounceOwnership 0x715018a6
No parameters
set_new_goodwill 0xb10e1dbc
uint16 _new_goodwill
toggleContractActive 0x1385d24c
No parameters
transferOwnership 0xf2fde38b
address newOwner
withdraw 0x3ccfd60b
No parameters
Recent Transactions
No transactions found for this address