├── .gitattributes ├── .gitignore ├── .nvmrc ├── README.md ├── buidler.config.js ├── contracts ├── Migrations.sol ├── common │ ├── interfaces.sol │ ├── math.sol │ └── stores.sol ├── connectors │ ├── 0x.sol │ ├── 1inch.sol │ ├── COMP.sol │ ├── aave.sol │ ├── aave_v2.sol │ ├── authority.sol │ ├── basic.sol │ ├── chi.sol │ ├── compound.sol │ ├── cream.sol │ ├── curve.sol │ ├── curve_3pool.sol │ ├── curve_gauge.sol │ ├── curve_vesting.sol │ ├── curvesbtc.sol │ ├── curvey.sol │ ├── dydx.sol │ ├── dydxFlash.sol │ ├── fee.sol │ ├── gelato.sol │ ├── instapool.sol │ ├── kyber.sol │ ├── makerdao.sol │ ├── mock.sol │ ├── oasis.sol │ ├── refinance.sol │ ├── staking.sol │ ├── swerve.sol │ └── uniswap.sol ├── flashloan │ └── dydx.sol ├── mapping │ ├── 1inch.sol │ ├── curve_gauge_mapping.sol │ ├── instapoolFee.sol │ └── staking.sol ├── static │ ├── basic.sol │ └── maker.sol └── tests │ ├── MockCurveGauge.sol │ ├── MockCurveGaugeMapping.sol │ ├── MockCurveVesting.sol │ ├── MockInstaMapping.sol │ ├── MockStaking.sol │ ├── Mocks.sol │ └── mockOneProto.sol ├── migrations ├── 1_initial_migration.js └── 2_deploy_connector.js ├── package-lock.json ├── package.json ├── tenderly.yaml ├── test ├── CurveGauge.js ├── CurveProtocol.js ├── CurveSBTCProtocol.js ├── CurveVestingProtocol.js ├── SynthetixProtocol.js ├── abi │ ├── 1proto.json │ ├── account.json │ ├── connectors.json │ ├── crvRenWSBTC.json │ ├── curveGauge.json │ ├── curveSwap.json │ ├── curveVesting.json │ ├── dai.js │ ├── erc20.js │ ├── sbtc.json │ ├── swap.js │ └── synthetixStaking.json ├── dai.js ├── oneProto.js └── utils.js └── truffle-config.js /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sol linguist-language=Solidity -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | lib-cov 2 | *.seed 3 | *.log 4 | *.csv 5 | *.dat 6 | *.out 7 | *.pid 8 | *.gz 9 | *.swp 10 | 11 | pids 12 | logs 13 | results 14 | tmp 15 | 16 | # Optional npm cache directory 17 | .npm 18 | 19 | #Build 20 | coverage 21 | public/css/main.css 22 | .nyc_output/* 23 | 24 | #Libraries from npm packages 25 | public/js/lib/bootstrap.min* 26 | public/js/lib/jquery.min* 27 | public/js/lib/popper.min* 28 | 29 | # API keys and secrets 30 | .env 31 | 32 | # Dependency directory 33 | node_modules 34 | bower_components 35 | 36 | # Editors 37 | .idea 38 | .vscode 39 | *.iml 40 | modules.xml 41 | *.ipr 42 | 43 | # Folder config file 44 | Desktop.ini 45 | 46 | # Recycle Bin used on file shares 47 | $RECYCLE.BIN/ 48 | 49 | # OS metadata 50 | .DS_Store 51 | Thumbs.db 52 | .DocumentRevisions-V100 53 | .fseventsd 54 | .Spotlight-V100 55 | .TemporaryItems 56 | .Trashes 57 | .VolumeIcon.icns 58 | .com.apple.timemachine.donotpresent 59 | 60 | # truffle 61 | build/contracts 62 | 63 | # buidler 64 | artifacts 65 | cache 66 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | v12.18.1 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DSA Connectors 2 | 3 | Connectors are standard modules that let DeFi Smart Account interact with various smart contracts, and make the important actions accessible like cross protocol interoperability. 4 | 5 | ## Add Custom Connectors 6 | 7 | 1. Fork and clone it 8 | 2. Create a feature branch: `git checkout -b new-connector` 9 | 3. Add the connector solidity file to `contracts/connectors` 10 | 4. Commit changes: `git commit -am 'Added a connector'` 11 | 5. Push to the remote branch: `git push origin new-connector` 12 | 6. Create a new Pull Request. 13 | 14 | ## Requirements 15 | 16 | Be sure to comply with the requirements while building connectors for better compatibility. 17 | 18 | - Import common files from `contracts/common` directory. 19 | - The contracts should not have `selfdestruct()`. 20 | - The contracts should not have `delegatecall()`. 21 | - Use `uint(-1)` for maximum amount everywhere. 22 | - Use `getEthAddr()` to denote Ethereum (non-ERC20). 23 | - Use `address(this)` instead of `msg.sender` for fetching balance on-chain, etc. 24 | - Only `approve()` limited amount while giving ERC20 allowance, which strictly needs to be 0 by the end of the spell. 25 | - Use `getId()` for getting value that saved from previous spell. 26 | - Use `setId()` for setting value to save for the future spell. 27 | 28 | 31 | 32 | 33 | 34 | ## Support 35 | 36 | If you can't find something you're looking for or have any questions, ask them at our developers community on [Telegram](https://t.me/instadevelopers), [Discord](https://discord.gg/83vvrnY) or simply send an [Email](mailto:info@instadapp.io). 37 | -------------------------------------------------------------------------------- /buidler.config.js: -------------------------------------------------------------------------------- 1 | usePlugin("@nomiclabs/buidler-truffle5"); 2 | // You have to export an object to set up your config 3 | // This object can have the following optional entries: 4 | // defaultNetwork, networks, solc, and paths. 5 | // Go to https://buidler.dev/config/ to learn more 6 | module.exports = { 7 | // This is a sample solc configuration that specifies which version of solc to use 8 | solc: { 9 | version: "0.6.2", 10 | }, 11 | }; 12 | -------------------------------------------------------------------------------- /contracts/Migrations.sol: -------------------------------------------------------------------------------- 1 | pragma solidity >=0.4.21 <0.7.0; 2 | 3 | contract Migrations { 4 | address public owner; 5 | uint public last_completed_migration; 6 | 7 | constructor() public { 8 | owner = msg.sender; 9 | } 10 | 11 | modifier restricted() { 12 | if (msg.sender == owner) _; 13 | } 14 | 15 | function setCompleted(uint completed) public restricted { 16 | last_completed_migration = completed; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /contracts/common/interfaces.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | 3 | interface TokenInterface { 4 | function approve(address, uint256) external; 5 | function transfer(address, uint) external; 6 | function transferFrom(address, address, uint) external; 7 | function deposit() external payable; 8 | function withdraw(uint) external; 9 | function balanceOf(address) external view returns (uint); 10 | function decimals() external view returns (uint); 11 | } 12 | 13 | interface MemoryInterface { 14 | function getUint(uint id) external returns (uint num); 15 | function setUint(uint id, uint val) external; 16 | } 17 | 18 | interface EventInterface { 19 | function emitEvent(uint connectorType, uint connectorID, bytes32 eventCode, bytes calldata eventData) external; 20 | } -------------------------------------------------------------------------------- /contracts/common/math.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | 3 | import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol"; 4 | 5 | contract DSMath { 6 | uint constant WAD = 10 ** 18; 7 | uint constant RAY = 10 ** 27; 8 | 9 | function add(uint x, uint y) internal pure returns (uint z) { 10 | z = SafeMath.add(x, y); 11 | } 12 | 13 | function sub(uint x, uint y) internal virtual pure returns (uint z) { 14 | z = SafeMath.sub(x, y); 15 | } 16 | 17 | function mul(uint x, uint y) internal pure returns (uint z) { 18 | z = SafeMath.mul(x, y); 19 | } 20 | 21 | function div(uint x, uint y) internal pure returns (uint z) { 22 | z = SafeMath.div(x, y); 23 | } 24 | 25 | function wmul(uint x, uint y) internal pure returns (uint z) { 26 | z = SafeMath.add(SafeMath.mul(x, y), WAD / 2) / WAD; 27 | } 28 | 29 | function wdiv(uint x, uint y) internal pure returns (uint z) { 30 | z = SafeMath.add(SafeMath.mul(x, WAD), y / 2) / y; 31 | } 32 | 33 | function rdiv(uint x, uint y) internal pure returns (uint z) { 34 | z = SafeMath.add(SafeMath.mul(x, RAY), y / 2) / y; 35 | } 36 | 37 | function rmul(uint x, uint y) internal pure returns (uint z) { 38 | z = SafeMath.add(SafeMath.mul(x, y), RAY / 2) / RAY; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /contracts/common/stores.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | 3 | import { MemoryInterface, EventInterface} from "./interfaces.sol"; 4 | 5 | 6 | contract Stores { 7 | 8 | /** 9 | * @dev Return ethereum address 10 | */ 11 | function getEthAddr() internal pure returns (address) { 12 | return 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; // ETH Address 13 | } 14 | 15 | /** 16 | * @dev Return memory variable address 17 | */ 18 | function getMemoryAddr() internal pure returns (address) { 19 | return 0x8a5419CfC711B2343c17a6ABf4B2bAFaBb06957F; // InstaMemory Address 20 | } 21 | 22 | /** 23 | * @dev Return InstaEvent Address. 24 | */ 25 | function getEventAddr() internal pure returns (address) { 26 | return 0x2af7ea6Cb911035f3eb1ED895Cb6692C39ecbA97; // InstaEvent Address 27 | } 28 | 29 | /** 30 | * @dev Get Uint value from InstaMemory Contract. 31 | */ 32 | function getUint(uint getId, uint val) internal returns (uint returnVal) { 33 | returnVal = getId == 0 ? val : MemoryInterface(getMemoryAddr()).getUint(getId); 34 | } 35 | 36 | /** 37 | * @dev Set Uint value in InstaMemory Contract. 38 | */ 39 | function setUint(uint setId, uint val) virtual internal { 40 | if (setId != 0) MemoryInterface(getMemoryAddr()).setUint(setId, val); 41 | } 42 | 43 | /** 44 | * @dev emit event on event contract 45 | */ 46 | function emitEvent(bytes32 eventCode, bytes memory eventData) virtual internal { 47 | (uint model, uint id) = connectorID(); 48 | EventInterface(getEventAddr()).emitEvent(model, id, eventCode, eventData); 49 | } 50 | 51 | /** 52 | * @dev Connector Details - needs to be changed before deployment 53 | */ 54 | function connectorID() public view returns(uint model, uint id) { 55 | (model, id) = (0, 0); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /contracts/connectors/0x.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | pragma experimental ABIEncoderV2; 3 | 4 | // import files from common directory 5 | import {TokenInterface, MemoryInterface, EventInterface} from "../common/interfaces.sol"; 6 | import {Stores} from "../common/stores.sol"; 7 | import {DSMath} from "../common/math.sol"; 8 | 9 | contract Helpers is Stores, DSMath { 10 | /** 11 | * @dev Return 0x Address 12 | */ 13 | function get0xAddress() internal pure returns (address) { 14 | return 0xDef1C0ded9bec7F1a1670819833240f027b25EfF; 15 | } 16 | 17 | function convert18ToDec(uint256 _dec, uint256 _amt) internal pure returns (uint256 amt) { 18 | amt = (_amt / 10**(18 - _dec)); 19 | } 20 | 21 | function convertTo18(uint256 _dec, uint256 _amt) internal pure returns (uint256 amt) { 22 | amt = mul(_amt, 10**(18 - _dec)); 23 | } 24 | 25 | function getTokenBal(TokenInterface token) internal view returns (uint256 _amt) { 26 | _amt = address(token) == getEthAddr() ? address(this).balance : token.balanceOf(address(this)); 27 | } 28 | 29 | function getTokensDec(TokenInterface buyAddr, TokenInterface sellAddr) internal view returns (uint256 buyDec, uint256 sellDec) { 30 | buyDec = address(buyAddr) == getEthAddr() ? 18 : buyAddr.decimals(); 31 | sellDec = address(sellAddr) == getEthAddr() ? 18 : sellAddr.decimals(); 32 | } 33 | 34 | struct SwapData { 35 | TokenInterface sellToken; 36 | TokenInterface buyToken; 37 | uint256 _sellAmt; 38 | uint256 _buyAmt; 39 | uint256 unitAmt; 40 | bytes callData; 41 | } 42 | 43 | } 44 | 45 | contract EventResolver is Helpers { 46 | event LogSwap(address indexed buyToken, address indexed sellToken, uint256 buyAmt, uint256 sellAmt, uint256 getId, uint256 setId); 47 | 48 | function emitLogSwap(SwapData memory swapData, uint256 setId) internal { 49 | bytes32 _eventCode; 50 | bytes memory _eventParam; 51 | emit LogSwap(address(swapData.buyToken), address(swapData.sellToken), swapData._buyAmt, swapData._sellAmt, 0, setId); 52 | _eventCode = keccak256("LogSwap(address,address,uint256,uint256,uint256,uint256)"); 53 | _eventParam = abi.encode(address(swapData.buyToken), address(swapData.sellToken), swapData._buyAmt, swapData._sellAmt, 0, setId); 54 | emitEvent(_eventCode, _eventParam); 55 | } 56 | } 57 | 58 | contract Resolver is EventResolver { 59 | function _swapHelper(SwapData memory swapData, uint256 wethAmt) internal returns (uint256 buyAmt) { 60 | TokenInterface buyToken = swapData.buyToken; 61 | (uint256 _buyDec, uint256 _sellDec) = getTokensDec(buyToken, swapData.sellToken); 62 | uint256 _sellAmt18 = convertTo18(_sellDec, swapData._sellAmt); 63 | uint256 _slippageAmt = convert18ToDec(_buyDec, wmul(swapData.unitAmt, _sellAmt18)); 64 | 65 | uint256 initalBal = getTokenBal(buyToken); 66 | 67 | (bool success, ) = address(get0xAddress()).call.value(wethAmt)(swapData.callData); 68 | if (!success) revert("0x-swap-failed"); 69 | 70 | uint256 finalBal = getTokenBal(buyToken); 71 | 72 | buyAmt = sub(finalBal, initalBal); 73 | 74 | require(_slippageAmt <= buyAmt, "Too much slippage"); 75 | } 76 | 77 | function _swap(SwapData memory swapData, uint256 setId) internal { 78 | TokenInterface _sellAddr = swapData.sellToken; 79 | 80 | uint256 ethAmt; 81 | 82 | if (address(_sellAddr) == getEthAddr()) { 83 | ethAmt = swapData._sellAmt; 84 | } else { 85 | TokenInterface(_sellAddr).approve(get0xAddress(), swapData._sellAmt); 86 | } 87 | 88 | swapData._buyAmt = _swapHelper(swapData, ethAmt); 89 | 90 | setUint(setId, swapData._buyAmt); 91 | 92 | emitLogSwap(swapData, setId); 93 | } 94 | } 95 | 96 | contract Connector is Resolver { 97 | /** 98 | * @dev Swap ETH/ERC20_Token using 0x. 99 | * @param buyAddr buying token address.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) 100 | * @param sellAddr selling token amount.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) 101 | * @param sellAmt selling token amount. 102 | * @param unitAmt unit amount of buyAmt/sellAmt with slippage. 103 | * @param callData Data from 0x API. 104 | * @param setId Set token amount at this ID in `InstaMemory` Contract. 105 | */ 106 | function swap( 107 | address buyAddr, 108 | address sellAddr, 109 | uint256 sellAmt, 110 | uint256 unitAmt, 111 | bytes calldata callData, 112 | uint256 setId 113 | ) external payable { 114 | SwapData memory swapData = 115 | SwapData({ 116 | buyToken: TokenInterface(buyAddr), 117 | sellToken: TokenInterface(sellAddr), 118 | unitAmt: unitAmt, 119 | callData: callData, 120 | _sellAmt: sellAmt, 121 | _buyAmt: 0 122 | }); 123 | 124 | _swap(swapData, setId); 125 | } 126 | } 127 | 128 | contract Connect0x is Connector { 129 | string public name = "0x-v1"; 130 | } -------------------------------------------------------------------------------- /contracts/connectors/aave.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | 3 | // import files from common directory 4 | import { TokenInterface , MemoryInterface, EventInterface} from "../common/interfaces.sol"; 5 | import { Stores } from "../common/stores.sol"; 6 | import { DSMath } from "../common/math.sol"; 7 | 8 | interface AaveInterface { 9 | function deposit(address _reserve, uint256 _amount, uint16 _referralCode) external payable; 10 | function redeemUnderlying( 11 | address _reserve, 12 | address payable _user, 13 | uint256 _amount, 14 | uint256 _aTokenBalanceAfterRedeem 15 | ) external; 16 | function setUserUseReserveAsCollateral(address _reserve, bool _useAsCollateral) external; 17 | function getUserReserveData(address _reserve, address _user) external view returns ( 18 | uint256 currentATokenBalance, 19 | uint256 currentBorrowBalance, 20 | uint256 principalBorrowBalance, 21 | uint256 borrowRateMode, 22 | uint256 borrowRate, 23 | uint256 liquidityRate, 24 | uint256 originationFee, 25 | uint256 variableBorrowIndex, 26 | uint256 lastUpdateTimestamp, 27 | bool usageAsCollateralEnabled 28 | ); 29 | function borrow(address _reserve, uint256 _amount, uint256 _interestRateMode, uint16 _referralCode) external; 30 | function repay(address _reserve, uint256 _amount, address payable _onBehalfOf) external payable; 31 | } 32 | 33 | interface AaveProviderInterface { 34 | function getLendingPool() external view returns (address); 35 | function getLendingPoolCore() external view returns (address); 36 | } 37 | 38 | interface AaveCoreInterface { 39 | function getReserveATokenAddress(address _reserve) external view returns (address); 40 | } 41 | 42 | interface ATokenInterface { 43 | function redeem(uint256 _amount) external; 44 | function balanceOf(address _user) external view returns(uint256); 45 | function principalBalanceOf(address _user) external view returns(uint256); 46 | } 47 | 48 | contract AaveHelpers is DSMath, Stores { 49 | 50 | /** 51 | * @dev get Aave Provider 52 | */ 53 | function getAaveProvider() internal pure returns (AaveProviderInterface) { 54 | return AaveProviderInterface(0x24a42fD28C976A61Df5D00D0599C34c4f90748c8); //mainnet 55 | // return AaveProviderInterface(0x506B0B2CF20FAA8f38a4E2B524EE43e1f4458Cc5); //kovan 56 | } 57 | 58 | /** 59 | * @dev get Referral Code 60 | */ 61 | function getReferralCode() internal pure returns (uint16) { 62 | return 3228; 63 | } 64 | 65 | function getIsColl(AaveInterface aave, address token) internal view returns (bool isCol) { 66 | (, , , , , , , , , isCol) = aave.getUserReserveData(token, address(this)); 67 | } 68 | 69 | function getWithdrawBalance(address token) internal view returns (uint bal) { 70 | AaveInterface aave = AaveInterface(getAaveProvider().getLendingPool()); 71 | (bal, , , , , , , , , ) = aave.getUserReserveData(token, address(this)); 72 | } 73 | 74 | function getPaybackBalance(AaveInterface aave, address token) internal view returns (uint bal, uint fee) { 75 | (, bal, , , , , fee, , , ) = aave.getUserReserveData(token, address(this)); 76 | } 77 | } 78 | 79 | 80 | contract BasicResolver is AaveHelpers { 81 | event LogDeposit(address indexed token, uint256 tokenAmt, uint256 getId, uint256 setId); 82 | event LogWithdraw(address indexed token, uint256 tokenAmt, uint256 getId, uint256 setId); 83 | event LogBorrow(address indexed token, uint256 tokenAmt, uint256 getId, uint256 setId); 84 | event LogPayback(address indexed token, uint256 tokenAmt, uint256 getId, uint256 setId); 85 | event LogEnableCollateral(address[] tokens); 86 | 87 | /** 88 | * @dev Deposit ETH/ERC20_Token. 89 | * @param token token address to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) 90 | * @param amt token amount to deposit. 91 | * @param getId Get token amount at this ID from `InstaMemory` Contract. 92 | * @param setId Set token amount at this ID in `InstaMemory` Contract. 93 | */ 94 | function deposit(address token, uint amt, uint getId, uint setId) external payable { 95 | uint _amt = getUint(getId, amt); 96 | AaveInterface aave = AaveInterface(getAaveProvider().getLendingPool()); 97 | 98 | uint ethAmt; 99 | if (token == getEthAddr()) { 100 | _amt = _amt == uint(-1) ? address(this).balance : _amt; 101 | ethAmt = _amt; 102 | } else { 103 | TokenInterface tokenContract = TokenInterface(token); 104 | _amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt; 105 | tokenContract.approve(getAaveProvider().getLendingPoolCore(), _amt); 106 | } 107 | 108 | aave.deposit.value(ethAmt)(token, _amt, getReferralCode()); 109 | 110 | if (!getIsColl(aave, token)) aave.setUserUseReserveAsCollateral(token, true); 111 | 112 | setUint(setId, _amt); 113 | 114 | emit LogDeposit(token, _amt, getId, setId); 115 | } 116 | 117 | /** 118 | * @dev Withdraw ETH/ERC20_Token. 119 | * @param token token address to withdraw.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) 120 | * @param amt token amount to withdraw. 121 | * @param getId Get token amount at this ID from `InstaMemory` Contract. 122 | * @param setId Set token amount at this ID in `InstaMemory` Contract. 123 | */ 124 | function withdraw(address token, uint amt, uint getId, uint setId) external payable { 125 | uint _amt = getUint(getId, amt); 126 | AaveCoreInterface aaveCore = AaveCoreInterface(getAaveProvider().getLendingPoolCore()); 127 | ATokenInterface atoken = ATokenInterface(aaveCore.getReserveATokenAddress(token)); 128 | TokenInterface tokenContract = TokenInterface(token); 129 | 130 | uint initialBal = token == getEthAddr() ? address(this).balance : tokenContract.balanceOf(address(this)); 131 | atoken.redeem(_amt); 132 | uint finalBal = token == getEthAddr() ? address(this).balance : tokenContract.balanceOf(address(this)); 133 | 134 | _amt = sub(finalBal, initialBal); 135 | setUint(setId, _amt); 136 | 137 | emit LogWithdraw(token, _amt, getId, setId); 138 | } 139 | 140 | /** 141 | * @dev Borrow ETH/ERC20_Token. 142 | * @param token token address to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) 143 | * @param amt token amount to borrow. 144 | * @param getId Get token amount at this ID from `InstaMemory` Contract. 145 | * @param setId Set token amount at this ID in `InstaMemory` Contract. 146 | */ 147 | function borrow(address token, uint amt, uint getId, uint setId) external payable { 148 | uint _amt = getUint(getId, amt); 149 | AaveInterface aave = AaveInterface(getAaveProvider().getLendingPool()); 150 | aave.borrow(token, _amt, 2, getReferralCode()); 151 | setUint(setId, _amt); 152 | 153 | emit LogBorrow(token, _amt, getId, setId); 154 | } 155 | 156 | /** 157 | * @dev Payback borrowed ETH/ERC20_Token. 158 | * @param token token address to payback.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) 159 | * @param amt token amount to payback. 160 | * @param getId Get token amount at this ID from `InstaMemory` Contract. 161 | * @param setId Set token amount at this ID in `InstaMemory` Contract. 162 | */ 163 | function payback(address token, uint amt, uint getId, uint setId) external payable { 164 | uint _amt = getUint(getId, amt); 165 | AaveInterface aave = AaveInterface(getAaveProvider().getLendingPool()); 166 | 167 | if (_amt == uint(-1)) { 168 | uint fee; 169 | (_amt, fee) = getPaybackBalance(aave, token); 170 | _amt = add(_amt, fee); 171 | } 172 | uint ethAmt; 173 | if (token == getEthAddr()) { 174 | ethAmt = _amt; 175 | } else { 176 | TokenInterface(token).approve(getAaveProvider().getLendingPoolCore(), _amt); 177 | } 178 | 179 | aave.repay.value(ethAmt)(token, _amt, payable(address(this))); 180 | 181 | setUint(setId, _amt); 182 | 183 | emit LogPayback(token, _amt, getId, setId); 184 | } 185 | 186 | /** 187 | * @dev Enable collateral 188 | * @param tokens Array of tokens to enable collateral 189 | */ 190 | function enableCollateral(address[] calldata tokens) external payable { 191 | uint _length = tokens.length; 192 | require(_length > 0, "0-tokens-not-allowed"); 193 | 194 | AaveInterface aave = AaveInterface(getAaveProvider().getLendingPool()); 195 | 196 | for (uint i = 0; i < _length; i++) { 197 | address token = tokens[i]; 198 | if (getWithdrawBalance(token) > 0 && !getIsColl(aave, token)) { 199 | aave.setUserUseReserveAsCollateral(token, true); 200 | } 201 | } 202 | 203 | emit LogEnableCollateral(tokens); 204 | } 205 | } 206 | 207 | contract ConnectAave is BasicResolver { 208 | string public name = "Aave-v1.1"; 209 | } 210 | -------------------------------------------------------------------------------- /contracts/connectors/authority.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | pragma experimental ABIEncoderV2; 3 | 4 | /** 5 | * @title ConnectAuth. 6 | * @dev Connector For Adding Authorities. 7 | */ 8 | 9 | interface AccountInterface { 10 | function enable(address) external; 11 | function disable(address) external; 12 | } 13 | 14 | interface EventInterface { 15 | function emitEvent(uint _connectorType, uint _connectorID, bytes32 _eventCode, bytes calldata _eventData) external; 16 | } 17 | 18 | interface ListInterface { 19 | struct UserLink { 20 | uint64 first; 21 | uint64 last; 22 | uint64 count; 23 | } 24 | 25 | struct UserList { 26 | uint64 prev; 27 | uint64 next; 28 | } 29 | 30 | struct AccountLink { 31 | address first; 32 | address last; 33 | uint64 count; 34 | } 35 | 36 | struct AccountList { 37 | address prev; 38 | address next; 39 | } 40 | 41 | function accounts() external view returns (uint); 42 | function accountID(address) external view returns (uint64); 43 | function accountAddr(uint64) external view returns (address); 44 | function userLink(address) external view returns (UserLink memory); 45 | function userList(address, uint64) external view returns (UserList memory); 46 | function accountLink(uint64) external view returns (AccountLink memory); 47 | function accountList(uint64, address) external view returns (AccountList memory); 48 | 49 | } 50 | 51 | 52 | contract Basics { 53 | 54 | /** 55 | * @dev Return InstaEvent Address. 56 | */ 57 | function getEventAddr() internal pure returns (address) { 58 | return 0x2af7ea6Cb911035f3eb1ED895Cb6692C39ecbA97; 59 | } 60 | 61 | /** 62 | * @dev Return InstaList Address. 63 | */ 64 | function getListAddr() internal pure returns (address) { 65 | return 0x4c8a1BEb8a87765788946D6B19C6C6355194AbEb; 66 | } 67 | 68 | /** 69 | * @dev Connector ID and Type. 70 | */ 71 | function connectorID() public pure returns(uint _type, uint _id) { 72 | (_type, _id) = (1, 37); 73 | } 74 | 75 | } 76 | 77 | contract Helpers is Basics { 78 | function checkAuthCount() internal view returns (uint count) { 79 | ListInterface listContract = ListInterface(getListAddr()); 80 | uint64 accountId = listContract.accountID(address(this)); 81 | count = listContract.accountLink(accountId).count; 82 | } 83 | } 84 | 85 | contract Auth is Helpers { 86 | 87 | event LogAddAuth(address indexed _msgSender, address indexed _authority); 88 | event LogRemoveAuth(address indexed _msgSender, address indexed _authority); 89 | 90 | /** 91 | * @dev Add New authority 92 | * @param authority authority Address. 93 | */ 94 | function add(address authority) external payable { 95 | AccountInterface(address(this)).enable(authority); 96 | 97 | emit LogAddAuth(msg.sender, authority); 98 | 99 | bytes32 _eventCode = keccak256("LogAddAuth(address,address)"); 100 | bytes memory _eventParam = abi.encode(msg.sender, authority); 101 | (uint _type, uint _id) = connectorID(); 102 | EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam); 103 | } 104 | 105 | /** 106 | * @dev Remove authority 107 | * @param authority authority Address. 108 | */ 109 | function remove(address authority) external payable { 110 | require(checkAuthCount() > 1, "Removing-all-authorities"); 111 | AccountInterface(address(this)).disable(authority); 112 | 113 | emit LogRemoveAuth(msg.sender, authority); 114 | 115 | bytes32 _eventCode = keccak256("LogRemoveAuth(address,address)"); 116 | bytes memory _eventParam = abi.encode(msg.sender, authority); 117 | (uint _type, uint _id) = connectorID(); 118 | EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam); 119 | } 120 | 121 | } 122 | 123 | 124 | contract ConnectAuth is Auth { 125 | string public constant name = "Auth-v1"; 126 | } -------------------------------------------------------------------------------- /contracts/connectors/basic.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | 3 | import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; 4 | import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 5 | 6 | // import files from common directory 7 | import { TokenInterface , MemoryInterface, EventInterface} from "../common/interfaces.sol"; 8 | import { Stores } from "../common/stores.sol"; 9 | import { DSMath } from "../common/math.sol"; 10 | 11 | interface AccountInterface { 12 | function isAuth(address _user) external view returns (bool); 13 | } 14 | /** 15 | * @title ConnectBasic. 16 | * @dev Connector to deposit/withdraw assets. 17 | */ 18 | 19 | contract BasicResolver is Stores { 20 | event LogDeposit(address indexed erc20, uint256 tokenAmt, uint256 getId, uint256 setId); 21 | event LogWithdraw(address indexed erc20, uint256 tokenAmt, address indexed to, uint256 getId, uint256 setId); 22 | 23 | using SafeERC20 for IERC20; 24 | 25 | /** 26 | * @dev Deposit Assets To Smart Account. 27 | * @param erc20 Token Address. 28 | * @param tokenAmt Token Amount. 29 | * @param getId Get Storage ID. 30 | * @param setId Set Storage ID. 31 | */ 32 | function deposit(address erc20, uint tokenAmt, uint getId, uint setId) public payable { 33 | uint amt = getUint(getId, tokenAmt); 34 | if (erc20 != getEthAddr()) { 35 | IERC20 token = IERC20(erc20); 36 | amt = amt == uint(-1) ? token.balanceOf(msg.sender) : amt; 37 | token.safeTransferFrom(msg.sender, address(this), amt); 38 | } else { 39 | require(msg.value == amt || amt == uint(-1), "invalid-ether-amount"); 40 | amt = msg.value; 41 | } 42 | setUint(setId, amt); 43 | 44 | emit LogDeposit(erc20, amt, getId, setId); 45 | 46 | bytes32 _eventCode = keccak256("LogDeposit(address,uint256,uint256,uint256)"); 47 | bytes memory _eventParam = abi.encode(erc20, amt, getId, setId); 48 | emitEvent(_eventCode, _eventParam); 49 | } 50 | 51 | /** 52 | * @dev Withdraw Assets To Smart Account. 53 | * @param erc20 Token Address. 54 | * @param tokenAmt Token Amount. 55 | * @param to Withdraw token address. 56 | * @param getId Get Storage ID. 57 | * @param setId Set Storage ID. 58 | */ 59 | function withdraw( 60 | address erc20, 61 | uint tokenAmt, 62 | address payable to, 63 | uint getId, 64 | uint setId 65 | ) public payable { 66 | // require(AccountInterface(address(this)).isAuth(to), "invalid-to-address"); 67 | uint amt = getUint(getId, tokenAmt); 68 | if (erc20 == getEthAddr()) { 69 | amt = amt == uint(-1) ? address(this).balance : amt; 70 | to.transfer(amt); 71 | } else { 72 | IERC20 token = IERC20(erc20); 73 | amt = amt == uint(-1) ? token.balanceOf(address(this)) : amt; 74 | token.safeTransfer(to, amt); 75 | } 76 | setUint(setId, amt); 77 | 78 | emit LogWithdraw(erc20, amt, to, getId, setId); 79 | 80 | bytes32 _eventCode = keccak256("LogWithdraw(address,uint256,address,uint256,uint256)"); 81 | bytes memory _eventParam = abi.encode(erc20, amt, to, getId, setId); 82 | emitEvent(_eventCode, _eventParam); 83 | } 84 | } 85 | 86 | 87 | contract ConnectBasic is BasicResolver { 88 | string public constant name = "Basic-v1.1"; 89 | } 90 | -------------------------------------------------------------------------------- /contracts/connectors/chi.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | 3 | interface CHIInterface { 4 | function mint(uint256 value) external; 5 | function free(uint256 value) external returns (uint256); 6 | function balanceOf(address) external view returns (uint); 7 | function approve(address, uint256) external; 8 | } 9 | 10 | contract ChiHelpers { 11 | /** 12 | * @dev CHI token Address 13 | */ 14 | function getCHIAddress() internal pure returns (address) { 15 | return 0x0000000000004946c0e9F43F4Dee607b0eF1fA1c; 16 | } 17 | 18 | /** 19 | * @dev Connector Details. 20 | */ 21 | function connectorID() public view returns(uint model, uint id) { 22 | (model, id) = (1, 36); 23 | } 24 | } 25 | 26 | contract ChiResolver is ChiHelpers { 27 | /** 28 | * @dev Mint CHI token. 29 | * @param amt token amount to mint. 30 | */ 31 | function mint(uint amt) public payable { 32 | uint _amt = amt == uint(-1) ? 140 : amt; 33 | require(_amt <= 140, "Max minting is 140 chi"); 34 | CHIInterface(getCHIAddress()).mint(_amt); 35 | } 36 | 37 | /** 38 | * @dev burn CHI token. 39 | * @param amt token amount to burn. 40 | */ 41 | function burn(uint amt) public payable { 42 | CHIInterface chiToken = CHIInterface(getCHIAddress()); 43 | uint _amt = amt == uint(-1) ? chiToken.balanceOf(address(this)) : amt; 44 | chiToken.approve(address(chiToken), _amt); 45 | chiToken.free(_amt); 46 | } 47 | } 48 | 49 | contract ConnectCHI is ChiResolver { 50 | string public name = "CHI-v1"; 51 | } -------------------------------------------------------------------------------- /contracts/connectors/curve.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | 3 | // import files from common directory 4 | import { TokenInterface , MemoryInterface, EventInterface} from "../common/interfaces.sol"; 5 | import { Stores } from "../common/stores.sol"; 6 | import { DSMath } from "../common/math.sol"; 7 | 8 | interface ICurve { 9 | function underlying_coins(int128 tokenId) external view returns (address token); 10 | function calc_token_amount(uint256[4] calldata amounts, bool deposit) external returns (uint256 amount); 11 | function add_liquidity(uint256[4] calldata amounts, uint256 min_mint_amount) external; 12 | function get_dy(int128 sellTokenId, int128 buyTokenId, uint256 sellTokenAmt) external returns (uint256 buyTokenAmt); 13 | function exchange(int128 sellTokenId, int128 buyTokenId, uint256 sellTokenAmt, uint256 minBuyToken) external; 14 | function remove_liquidity_imbalance(uint256[4] calldata amounts, uint256 max_burn_amount) external; 15 | } 16 | 17 | interface ICurveZap { 18 | function calc_withdraw_one_coin(uint256 _token_amount, int128 i) external returns (uint256 amount); 19 | } 20 | 21 | 22 | contract CurveHelpers is Stores, DSMath { 23 | /** 24 | * @dev Return Curve Swap Address 25 | */ 26 | function getCurveSwapAddr() internal pure returns (address) { 27 | return 0xA5407eAE9Ba41422680e2e00537571bcC53efBfD; 28 | } 29 | 30 | /** 31 | * @dev Return Curve Token Address 32 | */ 33 | function getCurveTokenAddr() internal pure returns (address) { 34 | return 0xC25a3A3b969415c80451098fa907EC722572917F; 35 | } 36 | 37 | /** 38 | * @dev Return Curve Zap Address 39 | */ 40 | function getCurveZapAddr() internal pure returns (address) { 41 | return 0xFCBa3E75865d2d561BE8D220616520c171F12851; 42 | } 43 | 44 | function convert18ToDec(uint _dec, uint256 _amt) internal pure returns (uint256 amt) { 45 | amt = (_amt / 10 ** (18 - _dec)); 46 | } 47 | 48 | function convertTo18(uint _dec, uint256 _amt) internal pure returns (uint256 amt) { 49 | amt = mul(_amt, 10 ** (18 - _dec)); 50 | } 51 | 52 | function getTokenI(address token) internal pure returns (int128 i) { 53 | if (token == address(0x6B175474E89094C44Da98b954EedeAC495271d0F)) { 54 | // DAI Token 55 | i = 0; 56 | } else if (token == address(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48)) { 57 | // USDC Token 58 | i = 1; 59 | } else if (token == address(0xdAC17F958D2ee523a2206206994597C13D831ec7)) { 60 | // USDT Token 61 | i = 2; 62 | } else if (token == address(0x57Ab1ec28D129707052df4dF418D58a2D46d5f51)) { 63 | // sUSD Token 64 | i = 3; 65 | } else { 66 | revert("token-not-found."); 67 | } 68 | } 69 | 70 | function getTokenAddr(ICurve curve, uint256 i) internal view returns (address token) { 71 | token = curve.underlying_coins(int128(i)); 72 | require(token != address(0), "token-not-found."); 73 | } 74 | } 75 | 76 | contract CurveProtocol is CurveHelpers { 77 | 78 | event LogSell( 79 | address indexed buyToken, 80 | address indexed sellToken, 81 | uint256 buyAmt, 82 | uint256 sellAmt, 83 | uint256 getId, 84 | uint256 setId 85 | ); 86 | event LogDeposit(address token, uint256 amt, uint256 mintAmt, uint256 getId, uint256 setId); 87 | event LogWithdraw(address token, uint256 amt, uint256 burnAmt, uint256 getId, uint256 setId); 88 | 89 | /** 90 | * @dev Sell Stable ERC20_Token. 91 | * @param buyAddr buying token address. 92 | * @param sellAddr selling token amount. 93 | * @param sellAmt selling token amount. 94 | * @param unitAmt unit amount of buyAmt/sellAmt with slippage. 95 | * @param getId Get token amount at this ID from `InstaMemory` Contract. 96 | * @param setId Set token amount at this ID in `InstaMemory` Contract. 97 | */ 98 | function sell( 99 | address buyAddr, 100 | address sellAddr, 101 | uint sellAmt, 102 | uint unitAmt, 103 | uint getId, 104 | uint setId 105 | ) external payable { 106 | uint _sellAmt = getUint(getId, sellAmt); 107 | ICurve curve = ICurve(getCurveSwapAddr()); 108 | TokenInterface _buyToken = TokenInterface(buyAddr); 109 | TokenInterface _sellToken = TokenInterface(sellAddr); 110 | _sellAmt = _sellAmt == uint(-1) ? _sellToken.balanceOf(address(this)) : _sellAmt; 111 | _sellToken.approve(address(curve), _sellAmt); 112 | 113 | uint _slippageAmt = convert18ToDec(_buyToken.decimals(), wmul(unitAmt, convertTo18(_sellToken.decimals(), _sellAmt))); 114 | 115 | uint intialBal = _buyToken.balanceOf(address(this)); 116 | curve.exchange(getTokenI(sellAddr), getTokenI(buyAddr), _sellAmt, _slippageAmt); 117 | uint finalBal = _buyToken.balanceOf(address(this)); 118 | 119 | uint _buyAmt = sub(finalBal, intialBal); 120 | 121 | setUint(setId, _buyAmt); 122 | 123 | emit LogSell(buyAddr, sellAddr, _buyAmt, _sellAmt, getId, setId); 124 | bytes32 _eventCode = keccak256("LogSell(address,address,uint256,uint256,uint256,uint256)"); 125 | bytes memory _eventParam = abi.encode(buyAddr, sellAddr, _buyAmt, _sellAmt, getId, setId); 126 | emitEvent(_eventCode, _eventParam); 127 | 128 | } 129 | 130 | /** 131 | * @dev Deposit Token. 132 | * @param token token address. 133 | * @param amt token amount. 134 | * @param unitAmt unit amount of curve_amt/token_amt with slippage. 135 | * @param getId Get token amount at this ID from `InstaMemory` Contract. 136 | * @param setId Set token amount at this ID in `InstaMemory` Contract. 137 | */ 138 | function deposit( 139 | address token, 140 | uint amt, 141 | uint unitAmt, 142 | uint getId, 143 | uint setId 144 | ) external payable { 145 | uint256 _amt = getUint(getId, amt); 146 | TokenInterface tokenContract = TokenInterface(token); 147 | 148 | _amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt; 149 | uint[4] memory _amts; 150 | _amts[uint(getTokenI(token))] = _amt; 151 | 152 | tokenContract.approve(getCurveSwapAddr(), _amt); 153 | 154 | uint _amt18 = convertTo18(tokenContract.decimals(), _amt); 155 | uint _slippageAmt = wmul(unitAmt, _amt18); 156 | 157 | TokenInterface curveTokenContract = TokenInterface(getCurveTokenAddr()); 158 | uint initialCurveBal = curveTokenContract.balanceOf(address(this)); 159 | 160 | ICurve(getCurveSwapAddr()).add_liquidity(_amts, _slippageAmt); 161 | 162 | uint finalCurveBal = curveTokenContract.balanceOf(address(this)); 163 | 164 | uint mintAmt = sub(finalCurveBal, initialCurveBal); 165 | 166 | setUint(setId, mintAmt); 167 | 168 | emit LogDeposit(token, _amt, mintAmt, getId, setId); 169 | bytes32 _eventCode = keccak256("LogDeposit(address,uint256,uint256,uint256,uint256)"); 170 | bytes memory _eventParam = abi.encode(token, _amt, mintAmt, getId, setId); 171 | emitEvent(_eventCode, _eventParam); 172 | } 173 | 174 | /** 175 | * @dev Withdraw Token. 176 | * @param token token address. 177 | * @param amt token amount. 178 | * @param unitAmt unit amount of curve_amt/token_amt with slippage. 179 | * @param getId Get token amount at this ID from `InstaMemory` Contract. 180 | * @param setId Set token amount at this ID in `InstaMemory` Contract. 181 | */ 182 | function withdraw( 183 | address token, 184 | uint256 amt, 185 | uint256 unitAmt, 186 | uint getId, 187 | uint setId 188 | ) external payable { 189 | uint _amt = getUint(getId, amt); 190 | int128 tokenId = getTokenI(token); 191 | 192 | TokenInterface curveTokenContract = TokenInterface(getCurveTokenAddr()); 193 | ICurveZap curveZap = ICurveZap(getCurveZapAddr()); 194 | ICurve curveSwap = ICurve(getCurveSwapAddr()); 195 | 196 | uint _curveAmt; 197 | uint[4] memory _amts; 198 | if (_amt == uint(-1)) { 199 | _curveAmt = curveTokenContract.balanceOf(address(this)); 200 | _amt = curveZap.calc_withdraw_one_coin(_curveAmt, tokenId); 201 | _amts[uint(tokenId)] = _amt; 202 | } else { 203 | _amts[uint(tokenId)] = _amt; 204 | _curveAmt = curveSwap.calc_token_amount(_amts, false); 205 | } 206 | 207 | 208 | uint _amt18 = convertTo18(TokenInterface(token).decimals(), _amt); 209 | uint _slippageAmt = wmul(unitAmt, _amt18); 210 | 211 | curveTokenContract.approve(address(curveSwap), 0); 212 | curveTokenContract.approve(address(curveSwap), _slippageAmt); 213 | 214 | curveSwap.remove_liquidity_imbalance(_amts, _slippageAmt); 215 | 216 | setUint(setId, _amt); 217 | 218 | emit LogWithdraw(token, _amt, _curveAmt, getId, setId); 219 | bytes32 _eventCode = keccak256("LogWithdraw(address,uint256,uint256,uint256,uint256)"); 220 | bytes memory _eventParam = abi.encode(token, _amt, _curveAmt, getId, setId); 221 | emitEvent(_eventCode, _eventParam); 222 | } 223 | 224 | } 225 | 226 | contract ConnectCurve is CurveProtocol { 227 | string public name = "Curve-susd-v1.2"; 228 | } 229 | -------------------------------------------------------------------------------- /contracts/connectors/curve_3pool.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | 3 | // import files from common directory 4 | import { TokenInterface , MemoryInterface, EventInterface} from "../common/interfaces.sol"; 5 | import { Stores } from "../common/stores.sol"; 6 | import { DSMath } from "../common/math.sol"; 7 | 8 | interface ICurve { 9 | function underlying_coins(int128 tokenId) external view returns (address token); 10 | function get_dy(int128 sellTokenId, int128 buyTokenId, uint256 sellTokenAmt) external returns (uint256 buyTokenAmt); 11 | function exchange(int128 sellTokenId, int128 buyTokenId, uint256 sellTokenAmt, uint256 minBuyToken) external; 12 | } 13 | 14 | contract CurveHelpers is Stores, DSMath { 15 | /** 16 | * @dev Return Curve 3pool Swap Address 17 | */ 18 | function getCurveSwapAddr() internal pure returns (address) { 19 | return 0xbEbc44782C7dB0a1A60Cb6fe97d0b483032FF1C7; 20 | } 21 | 22 | /** 23 | * @dev Return Curve 3pool Token Address 24 | */ 25 | function getCurveTokenAddr() internal pure returns (address) { 26 | return 0x6c3F90f043a72FA612cbac8115EE7e52BDe6E490; 27 | } 28 | 29 | function convert18ToDec(uint _dec, uint256 _amt) internal pure returns (uint256 amt) { 30 | amt = (_amt / 10 ** (18 - _dec)); 31 | } 32 | 33 | function convertTo18(uint _dec, uint256 _amt) internal pure returns (uint256 amt) { 34 | amt = mul(_amt, 10 ** (18 - _dec)); 35 | } 36 | 37 | function getTokenI(address token) internal pure returns (int128 i) { 38 | if (token == address(0x6B175474E89094C44Da98b954EedeAC495271d0F)) { 39 | // DAI Token 40 | i = 0; 41 | } else if (token == address(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48)) { 42 | // USDC Token 43 | i = 1; 44 | } else if (token == address(0xdAC17F958D2ee523a2206206994597C13D831ec7)) { 45 | // USDT Token 46 | i = 2; 47 | } else { 48 | revert("token-not-found."); 49 | } 50 | } 51 | } 52 | 53 | contract CurveProtocol is CurveHelpers { 54 | 55 | event LogSell( 56 | address indexed buyToken, 57 | address indexed sellToken, 58 | uint256 buyAmt, 59 | uint256 sellAmt, 60 | uint256 getId, 61 | uint256 setId 62 | ); 63 | 64 | /** 65 | * @dev Sell Stable ERC20_Token. 66 | * @param buyAddr buying token address. 67 | * @param sellAddr selling token amount. 68 | * @param sellAmt selling token amount. 69 | * @param unitAmt unit amount of buyAmt/sellAmt with slippage. 70 | * @param getId Get token amount at this ID from `InstaMemory` Contract. 71 | * @param setId Set token amount at this ID in `InstaMemory` Contract. 72 | */ 73 | function sell( 74 | address buyAddr, 75 | address sellAddr, 76 | uint sellAmt, 77 | uint unitAmt, 78 | uint getId, 79 | uint setId 80 | ) external payable { 81 | uint _sellAmt = getUint(getId, sellAmt); 82 | ICurve curve = ICurve(getCurveSwapAddr()); 83 | TokenInterface _buyToken = TokenInterface(buyAddr); 84 | TokenInterface _sellToken = TokenInterface(sellAddr); 85 | _sellAmt = _sellAmt == uint(-1) ? _sellToken.balanceOf(address(this)) : _sellAmt; 86 | _sellToken.approve(address(curve), _sellAmt); 87 | 88 | uint _slippageAmt = convert18ToDec(_buyToken.decimals(), wmul(unitAmt, convertTo18(_sellToken.decimals(), _sellAmt))); 89 | 90 | uint intialBal = _buyToken.balanceOf(address(this)); 91 | curve.exchange(getTokenI(sellAddr), getTokenI(buyAddr), _sellAmt, _slippageAmt); 92 | uint finalBal = _buyToken.balanceOf(address(this)); 93 | 94 | uint _buyAmt = sub(finalBal, intialBal); 95 | 96 | setUint(setId, _buyAmt); 97 | 98 | emit LogSell(buyAddr, sellAddr, _buyAmt, _sellAmt, getId, setId); 99 | bytes32 _eventCode = keccak256("LogSell(address,address,uint256,uint256,uint256,uint256)"); 100 | bytes memory _eventParam = abi.encode(buyAddr, sellAddr, _buyAmt, _sellAmt, getId, setId); 101 | emitEvent(_eventCode, _eventParam); 102 | 103 | } 104 | } 105 | 106 | contract ConnectCurveThreePool is CurveProtocol { 107 | string public name = "Curve-3pool-v1.0"; 108 | } 109 | -------------------------------------------------------------------------------- /contracts/connectors/curve_gauge.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | pragma experimental ABIEncoderV2; 3 | 4 | // import files from common directory 5 | import { Stores } from "../common/stores.sol"; 6 | import { DSMath } from "../common/math.sol"; 7 | import { TokenInterface } from "../common/interfaces.sol"; 8 | 9 | interface IGauge { 10 | function claim_rewards() external; 11 | function deposit(uint256 value) external; 12 | function withdraw(uint256 value) external; 13 | function lp_token() external view returns(address token); 14 | function rewarded_token() external view returns(address token); 15 | function crv_token() external view returns(address token); 16 | function balanceOf(address user) external view returns(uint256 amt); 17 | } 18 | 19 | interface IMintor{ 20 | function mint(address gauge) external; 21 | } 22 | 23 | interface ICurveGaugeMapping { 24 | 25 | struct GaugeData { 26 | address gaugeAddress; 27 | bool rewardToken; 28 | } 29 | 30 | function gaugeMapping(bytes32) external view returns(GaugeData memory); 31 | } 32 | 33 | contract GaugeHelper is DSMath, Stores{ 34 | function getCurveGaugeMappingAddr() internal virtual view returns (address){ 35 | return 0x1C800eF1bBfE3b458969226A96c56B92a069Cc92; 36 | } 37 | 38 | function getCurveMintorAddr() internal virtual view returns (address){ 39 | return 0xd061D61a4d941c39E5453435B6345Dc261C2fcE0; 40 | } 41 | 42 | /** 43 | * @dev Convert String to bytes32. 44 | */ 45 | function stringToBytes32(string memory str) internal pure returns (bytes32 result) { 46 | require(bytes(str).length != 0, "string-empty"); 47 | // solium-disable-next-line security/no-inline-assembly 48 | assembly { 49 | result := mload(add(str, 32)) 50 | } 51 | } 52 | } 53 | 54 | contract CurveGaugeEvent is GaugeHelper { 55 | event LogDeposit( 56 | string indexed gaugePoolName, 57 | uint amount, 58 | uint getId, 59 | uint setId 60 | ); 61 | 62 | event LogWithdraw( 63 | string indexed gaugePoolName, 64 | uint amount, 65 | uint getId, 66 | uint setId 67 | ); 68 | 69 | event LogClaimedReward( 70 | string indexed gaugePoolName, 71 | uint amount, 72 | uint rewardAmt, 73 | uint setId, 74 | uint setIdReward 75 | ); 76 | 77 | function emitLogWithdraw(string memory gaugePoolName, uint _amt, uint getId, uint setId) internal { 78 | emit LogWithdraw(gaugePoolName, _amt, getId, setId); 79 | bytes32 _eventCodeWithdraw = keccak256("LogWithdraw(string,uint256,uint256,uint256)"); 80 | bytes memory _eventParamWithdraw = abi.encode(gaugePoolName, _amt, getId, setId); 81 | emitEvent(_eventCodeWithdraw, _eventParamWithdraw); 82 | } 83 | 84 | function emitLogClaimedReward(string memory gaugePoolName, uint crvAmt, uint rewardAmt, uint setIdCrv, uint setIdReward) internal { 85 | emit LogClaimedReward(gaugePoolName, crvAmt, rewardAmt, setIdCrv, setIdReward); 86 | bytes32 _eventCode = keccak256("LogClaimedReward(string,uint256,uint256,uint256,uint256)"); 87 | bytes memory _eventParam = abi.encode(gaugePoolName, crvAmt, rewardAmt, setIdCrv, setIdReward); 88 | emitEvent(_eventCode, _eventParam); 89 | } 90 | } 91 | 92 | contract CurveGauge is CurveGaugeEvent { 93 | struct Balances{ 94 | uint intialCRVBal; 95 | uint intialRewardBal; 96 | uint finalCRVBal; 97 | uint finalRewardBal; 98 | uint crvRewardAmt; 99 | uint rewardAmt; 100 | } 101 | 102 | /** 103 | * @dev Deposit Cruve LP Token. 104 | * @param gaugePoolName Curve gauge pool name. 105 | * @param amt deposit amount. 106 | * @param getId Get token amount at this ID from `InstaMemory` Contract. 107 | * @param setId Set token amount at this ID in `InstaMemory` Contract. 108 | */ 109 | function deposit( 110 | string calldata gaugePoolName, 111 | uint amt, 112 | uint getId, 113 | uint setId 114 | ) external payable { 115 | uint _amt = getUint(getId, amt); 116 | ICurveGaugeMapping curveGaugeMapping = ICurveGaugeMapping(getCurveGaugeMappingAddr()); 117 | ICurveGaugeMapping.GaugeData memory curveGaugeData = curveGaugeMapping.gaugeMapping( 118 | bytes32(stringToBytes32(gaugePoolName) 119 | )); 120 | require(curveGaugeData.gaugeAddress != address(0), "wrong-gauge-pool-name"); 121 | IGauge gauge = IGauge(curveGaugeData.gaugeAddress); 122 | TokenInterface lp_token = TokenInterface(address(gauge.lp_token())); 123 | 124 | _amt = _amt == uint(-1) ? lp_token.balanceOf(address(this)) : _amt; 125 | lp_token.approve(address(curveGaugeData.gaugeAddress), _amt); 126 | 127 | gauge.deposit(_amt); 128 | 129 | setUint(setId, _amt); 130 | 131 | emit LogDeposit(gaugePoolName, _amt, getId, setId); 132 | bytes32 _eventCode = keccak256("LogDeposit(string,uint256,uint256,uint256)"); 133 | bytes memory _eventParam = abi.encode(gaugePoolName, _amt, getId, setId); 134 | emitEvent(_eventCode, _eventParam); 135 | } 136 | 137 | /** 138 | * @dev Withdraw LP Token and claim both CRV and Reward token. 139 | * @param gaugePoolName gauge pool name. 140 | * @param amt LP token amount. 141 | * @param getId Get LP token amount at this ID from `InstaMemory` Contract. 142 | * @param setId Set LP token amount at this ID in `InstaMemory` Contract. 143 | * @param setIdCrv Set CRV token reward amount at this ID in `InstaMemory` Contract. 144 | * @param setIdReward Set reward amount at this ID in `InstaMemory` Contract. 145 | */ 146 | function withdraw( 147 | string calldata gaugePoolName, 148 | uint amt, 149 | uint getId, 150 | uint setId, 151 | uint setIdCrv, 152 | uint setIdReward 153 | ) external payable { 154 | uint _amt = getUint(getId, amt); 155 | ICurveGaugeMapping curveGaugeMapping = ICurveGaugeMapping(getCurveGaugeMappingAddr()); 156 | ICurveGaugeMapping.GaugeData memory curveGaugeData = curveGaugeMapping.gaugeMapping( 157 | bytes32(stringToBytes32(gaugePoolName)) 158 | ); 159 | require(curveGaugeData.gaugeAddress != address(0), "wrong-gauge-pool-name"); 160 | IGauge gauge = IGauge(curveGaugeData.gaugeAddress); 161 | TokenInterface crv_token = TokenInterface(address(gauge.crv_token())); 162 | TokenInterface rewarded_token; 163 | Balances memory balances; 164 | 165 | _amt = _amt == uint(-1) ? gauge.balanceOf(address(this)) : _amt; 166 | balances.intialCRVBal = crv_token.balanceOf(address(this)); 167 | 168 | if (curveGaugeData.rewardToken) { 169 | rewarded_token = TokenInterface(address(gauge.rewarded_token())); 170 | balances.intialRewardBal = rewarded_token.balanceOf(address(this)); 171 | } 172 | 173 | IMintor(getCurveMintorAddr()).mint(curveGaugeData.gaugeAddress); 174 | gauge.withdraw(_amt); 175 | 176 | balances.finalCRVBal = crv_token.balanceOf(address(this)); 177 | balances.crvRewardAmt = sub(balances.finalCRVBal, balances.intialCRVBal); 178 | 179 | setUint(setId, _amt); 180 | setUint(setIdCrv, balances.crvRewardAmt); 181 | 182 | if (curveGaugeData.rewardToken) { 183 | balances.finalRewardBal = rewarded_token.balanceOf(address(this)); 184 | balances.rewardAmt = sub(balances.finalRewardBal, balances.intialRewardBal); 185 | setUint(setIdReward, balances.rewardAmt); 186 | } 187 | 188 | emitLogWithdraw(gaugePoolName, _amt, getId, setId); 189 | emitLogClaimedReward(gaugePoolName, balances.crvRewardAmt, balances.rewardAmt, setIdCrv, setIdReward); 190 | } 191 | 192 | /** 193 | * @dev Claim CRV Reward with Staked Reward token 194 | * @param gaugePoolName gauge pool name. 195 | * @param setId Set CRV reward amount at this ID in `InstaMemory` Contract. 196 | * @param setIdReward Set token reward amount at this ID in `InstaMemory` Contract. 197 | */ 198 | function claimReward( 199 | string calldata gaugePoolName, 200 | uint setId, 201 | uint setIdReward 202 | ) external payable { 203 | ICurveGaugeMapping curveGaugeMapping = ICurveGaugeMapping(getCurveGaugeMappingAddr()); 204 | ICurveGaugeMapping.GaugeData memory curveGaugeData = curveGaugeMapping.gaugeMapping( 205 | bytes32(stringToBytes32(gaugePoolName)) 206 | ); 207 | require(curveGaugeData.gaugeAddress != address(0), "wrong-gauge-pool-name"); 208 | IMintor mintor = IMintor(getCurveMintorAddr()); 209 | IGauge gauge = IGauge(curveGaugeData.gaugeAddress); 210 | TokenInterface crv_token = TokenInterface(address(gauge.crv_token())); 211 | TokenInterface rewarded_token; 212 | Balances memory balances; 213 | 214 | if (curveGaugeData.rewardToken) { 215 | rewarded_token = TokenInterface(address(gauge.rewarded_token())); 216 | balances.intialRewardBal = rewarded_token.balanceOf(address(this)); 217 | } 218 | 219 | balances.intialCRVBal = crv_token.balanceOf(address(this)); 220 | 221 | mintor.mint(curveGaugeData.gaugeAddress); 222 | 223 | balances.finalCRVBal = crv_token.balanceOf(address(this)); 224 | balances.crvRewardAmt = sub(balances.finalCRVBal, balances.intialCRVBal); 225 | 226 | setUint(setId, balances.crvRewardAmt); 227 | 228 | if(curveGaugeData.rewardToken){ 229 | balances.finalRewardBal = rewarded_token.balanceOf(address(this)); 230 | balances.rewardAmt = sub(balances.finalRewardBal, balances.intialRewardBal); 231 | setUint(setIdReward, balances.rewardAmt); 232 | } 233 | 234 | emitLogClaimedReward(gaugePoolName, balances.crvRewardAmt, balances.rewardAmt, setId, setIdReward); 235 | } 236 | } 237 | 238 | contract ConnectCurveGauge is CurveGauge { 239 | string public name = "Curve-Gauge-v1.0"; 240 | } 241 | 242 | -------------------------------------------------------------------------------- /contracts/connectors/curve_vesting.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | 3 | // import files from common directory 4 | import { Stores } from "../common/stores.sol"; 5 | import { DSMath } from "../common/math.sol"; 6 | import { TokenInterface } from "../common/interfaces.sol"; 7 | 8 | interface ICurve { 9 | function claim(address addr) external; 10 | } 11 | 12 | contract CurveVestingHelpers is Stores, DSMath { 13 | /** 14 | * @dev Return Curve Token Address 15 | */ 16 | function getCurveTokenAddr() virtual internal view returns (address) { 17 | return 0xD533a949740bb3306d119CC777fa900bA034cd52; 18 | } 19 | 20 | /** 21 | * @dev Return Curve Vesting Address 22 | */ 23 | function getCurveVestingAddr() virtual internal view returns (address) { 24 | return 0x575CCD8e2D300e2377B43478339E364000318E2c; 25 | } 26 | } 27 | 28 | contract CurveVestingProtocol is CurveVestingHelpers { 29 | event LogClaim(address account, uint256 claimAmount, uint256 getId, uint256 setId); 30 | 31 | /** 32 | * @dev Claim Curve DAO Token. 33 | * @param getId Get token amount at this ID from `InstaMemory` Contract. 34 | * @param setId Set token amount at this ID in `InstaMemory` Contract. 35 | */ 36 | function claim(uint getId, uint setId) external{ 37 | TokenInterface curveTokenContract = TokenInterface(getCurveTokenAddr()); 38 | 39 | uint initialCurveBal = curveTokenContract.balanceOf(address(this)); 40 | ICurve(getCurveVestingAddr()).claim(address(this)); 41 | uint finalCurveBal = curveTokenContract.balanceOf(address(this)); 42 | 43 | uint claimedAmt = sub(finalCurveBal, initialCurveBal); 44 | 45 | setUint(setId, claimedAmt); 46 | 47 | emit LogClaim(address(this), claimedAmt, getId, setId); 48 | bytes32 _eventCode = keccak256("LogClaim(address,uint256,uint256,uint256)"); 49 | bytes memory _eventParam = abi.encode(address(this), claimedAmt, getId, setId); 50 | emitEvent(_eventCode, _eventParam); 51 | } 52 | } 53 | 54 | contract ConnectCurveVesting is CurveVestingProtocol { 55 | string public name = "Curve-vesting-v1"; 56 | } 57 | 58 | -------------------------------------------------------------------------------- /contracts/connectors/curvesbtc.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | 3 | // import files from common directory 4 | import { Stores } from "../common/stores.sol"; 5 | import { DSMath } from "../common/math.sol"; 6 | import { TokenInterface } from "../common/interfaces.sol"; 7 | 8 | interface ICurve { 9 | function coins(int128 tokenId) external view returns (address token); 10 | function calc_token_amount(uint256[3] calldata amounts, bool deposit) external returns (uint256 amount); 11 | function add_liquidity(uint256[3] calldata amounts, uint256 min_mint_amount) external; 12 | function get_dy(int128 sellTokenId, int128 buyTokenId, uint256 sellTokenAmt) external returns (uint256 buyTokenAmt); 13 | function exchange(int128 sellTokenId, int128 buyTokenId, uint256 sellTokenAmt, uint256 minBuyToken) external; 14 | function remove_liquidity_imbalance(uint256[3] calldata amounts, uint256 max_burn_amount) external; 15 | function calc_withdraw_one_coin(uint256 _token_amount, int128 i) external returns (uint256 amount); 16 | } 17 | 18 | contract CurveSBTCHelpers is Stores, DSMath{ 19 | /** 20 | * @dev Return Curve Swap Address 21 | */ 22 | function getCurveSwapAddr() internal pure returns (address) { 23 | return 0x7fC77b5c7614E1533320Ea6DDc2Eb61fa00A9714; 24 | } 25 | 26 | /** 27 | * @dev Return Curve Token Address 28 | */ 29 | function getCurveTokenAddr() internal pure returns (address) { 30 | return 0x075b1bb99792c9E1041bA13afEf80C91a1e70fB3; 31 | } 32 | 33 | function convert18ToDec(uint _dec, uint256 _amt) internal pure returns (uint256 amt) { 34 | amt = div(_amt, 10 ** (18 - _dec)); 35 | } 36 | 37 | function convertTo18(uint _dec, uint256 _amt) internal pure returns (uint256 amt) { 38 | amt = mul(_amt, 10 ** (18 - _dec)); 39 | } 40 | 41 | function getTokenI(address token) internal pure returns (int128 i) { 42 | if (token == address(0xEB4C2781e4ebA804CE9a9803C67d0893436bB27D)) { 43 | // RenBTC Token 44 | i = 0; 45 | } else if (token == address(0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599)) { 46 | // WBTC Token 47 | i = 1; 48 | } else if (token == address(0xfE18be6b3Bd88A2D2A7f928d00292E7a9963CfC6)) { 49 | // SBTC Token 50 | i = 2; 51 | } else { 52 | revert("token-not-found."); 53 | } 54 | } 55 | } 56 | 57 | contract CurveSBTCProtocol is CurveSBTCHelpers { 58 | 59 | // Events 60 | event LogSell( 61 | address indexed buyToken, 62 | address indexed sellToken, 63 | uint256 buyAmt, 64 | uint256 sellAmt, 65 | uint256 getId, 66 | uint256 setId 67 | ); 68 | event LogDeposit(address token, uint256 amt, uint256 mintAmt, uint256 getId, uint256 setId); 69 | event LogWithdraw(address token, uint256 amt, uint256 burnAmt, uint256 getId, uint256 setId); 70 | 71 | /** 72 | * @dev Sell ERC20_Token. 73 | * @param buyAddr buying token address. 74 | * @param sellAddr selling token amount. 75 | * @param sellAmt selling token amount. 76 | * @param unitAmt unit amount of buyAmt/sellAmt with slippage. 77 | * @param getId Get token amount at this ID from `InstaMemory` Contract. 78 | * @param setId Set token amount at this ID in `InstaMemory` Contract. 79 | */ 80 | function sell( 81 | address buyAddr, 82 | address sellAddr, 83 | uint sellAmt, 84 | uint unitAmt, 85 | uint getId, 86 | uint setId 87 | ) external payable { 88 | uint _sellAmt = getUint(getId, sellAmt); 89 | ICurve curve = ICurve(getCurveSwapAddr()); 90 | TokenInterface _buyToken = TokenInterface(buyAddr); 91 | TokenInterface _sellToken = TokenInterface(sellAddr); 92 | _sellAmt = _sellAmt == uint(-1) ? _sellToken.balanceOf(address(this)) : _sellAmt; 93 | _sellToken.approve(address(curve), _sellAmt); 94 | 95 | uint _slippageAmt = convert18ToDec(_buyToken.decimals(), wmul(unitAmt, convertTo18(_sellToken.decimals(), _sellAmt))); 96 | 97 | uint intialBal = _buyToken.balanceOf(address(this)); 98 | curve.exchange(getTokenI(sellAddr), getTokenI(buyAddr), _sellAmt, _slippageAmt); 99 | uint finalBal = _buyToken.balanceOf(address(this)); 100 | 101 | uint _buyAmt = sub(finalBal, intialBal); 102 | 103 | setUint(setId, _buyAmt); 104 | 105 | emit LogSell(buyAddr, sellAddr, _buyAmt, _sellAmt, getId, setId); 106 | bytes32 _eventCode = keccak256("LogSell(address,address,uint256,uint256,uint256,uint256)"); 107 | bytes memory _eventParam = abi.encode(buyAddr, sellAddr, _buyAmt, _sellAmt, getId, setId); 108 | emitEvent(_eventCode, _eventParam); 109 | } 110 | 111 | /** 112 | * @dev Deposit Token. 113 | * @param token token address. 114 | * @param amt token amount. 115 | * @param unitAmt unit amount of curve_amt/token_amt with slippage. 116 | * @param getId Get token amount at this ID from `InstaMemory` Contract. 117 | * @param setId Set token amount at this ID in `InstaMemory` Contract. 118 | */ 119 | function deposit( 120 | address token, 121 | uint amt, 122 | uint unitAmt, 123 | uint getId, 124 | uint setId 125 | ) external payable { 126 | uint256 _amt = getUint(getId, amt); 127 | TokenInterface tokenContract = TokenInterface(token); 128 | 129 | _amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt; 130 | uint[3] memory _amts; 131 | _amts[uint(getTokenI(token))] = _amt; 132 | 133 | tokenContract.approve(getCurveSwapAddr(), _amt); 134 | 135 | uint _amt18 = convertTo18(tokenContract.decimals(), _amt); 136 | uint _slippageAmt = wmul(unitAmt, _amt18); 137 | 138 | TokenInterface curveTokenContract = TokenInterface(getCurveTokenAddr()); 139 | uint initialCurveBal = curveTokenContract.balanceOf(address(this)); 140 | 141 | ICurve(getCurveSwapAddr()).add_liquidity(_amts, _slippageAmt); 142 | 143 | uint finalCurveBal = curveTokenContract.balanceOf(address(this)); 144 | 145 | uint mintAmt = sub(finalCurveBal, initialCurveBal); 146 | 147 | setUint(setId, mintAmt); 148 | 149 | emit LogDeposit(token, _amt, mintAmt, getId, setId); 150 | bytes32 _eventCode = keccak256("LogDeposit(address,uint256,uint256,uint256,uint256)"); 151 | bytes memory _eventParam = abi.encode(token, _amt, mintAmt, getId, setId); 152 | emitEvent(_eventCode, _eventParam); 153 | } 154 | 155 | /** 156 | * @dev Withdraw Token. 157 | * @param token token address. 158 | * @param amt token amount. 159 | * @param unitAmt unit amount of curve_amt/token_amt with slippage. 160 | * @param getId Get token amount at this ID from `InstaMemory` Contract. 161 | * @param setId Set token amount at this ID in `InstaMemory` Contract. 162 | */ 163 | function withdraw( 164 | address token, 165 | uint256 amt, 166 | uint256 unitAmt, 167 | uint getId, 168 | uint setId 169 | ) external payable { 170 | uint _amt = getUint(getId, amt); 171 | int128 tokenId = getTokenI(token); 172 | 173 | TokenInterface curveTokenContract = TokenInterface(getCurveTokenAddr()); 174 | ICurve curveSwap = ICurve(getCurveSwapAddr()); 175 | 176 | uint _curveAmt; 177 | uint[3] memory _amts; 178 | if (_amt == uint(-1)) { 179 | _curveAmt = curveTokenContract.balanceOf(address(this)); 180 | _amt = curveSwap.calc_withdraw_one_coin(_curveAmt, tokenId); 181 | _amts[uint(tokenId)] = _amt; 182 | } else { 183 | _amts[uint(tokenId)] = _amt; 184 | _curveAmt = curveSwap.calc_token_amount(_amts, false); 185 | } 186 | 187 | uint _amt18 = convertTo18(TokenInterface(token).decimals(), _amt); 188 | uint _slippageAmt = wmul(unitAmt, _amt18); 189 | 190 | curveTokenContract.approve(address(curveSwap), 0); 191 | curveTokenContract.approve(address(curveSwap), _slippageAmt); 192 | 193 | curveSwap.remove_liquidity_imbalance(_amts, _slippageAmt); 194 | 195 | setUint(setId, _amt); 196 | 197 | emit LogWithdraw(token, _amt, _curveAmt, getId, setId); 198 | bytes32 _eventCode = keccak256("LogWithdraw(address,uint256,uint256,uint256,uint256)"); 199 | bytes memory _eventParam = abi.encode(token, _amt, _curveAmt, getId, setId); 200 | emitEvent(_eventCode, _eventParam); 201 | } 202 | } 203 | 204 | contract ConnectSBTCCurve is CurveSBTCProtocol { 205 | string public name = "Curve-sbtc-v1"; 206 | } 207 | 208 | -------------------------------------------------------------------------------- /contracts/connectors/dydxFlash.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | 3 | // import files from common directory 4 | import { TokenInterface , MemoryInterface, EventInterface} from "../common/interfaces.sol"; 5 | import { Stores } from "../common/stores.sol"; 6 | 7 | interface AccountInterface { 8 | function enable(address) external; 9 | function disable(address) external; 10 | } 11 | 12 | interface DydxFlashInterface { 13 | function initiateFlashLoan(address _token, uint256 _amount, bytes calldata data) external; 14 | } 15 | 16 | contract FlashLoanResolver is Stores { 17 | event LogDydxFlashLoan(address indexed token, uint256 tokenAmt); 18 | 19 | /** 20 | * @dev Return ethereum address 21 | */ 22 | function getDydxLoanAddr() internal pure returns (address) { 23 | return address(0); // check9898 - change to dydx flash contract address 24 | } 25 | 26 | function getWethAddr() internal pure returns (address) { 27 | return 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; 28 | } 29 | 30 | /** 31 | * @dev Borrow Flashloan and Cast spells. 32 | * @param token Token Address. 33 | * @param tokenAmt Token Amount. 34 | * @param data targets & data for cast. 35 | */ 36 | function borrowAndCast(address token, uint tokenAmt, bytes memory data) public payable { 37 | AccountInterface(address(this)).enable(getDydxLoanAddr()); 38 | 39 | address _token = token == getEthAddr() ? getWethAddr() : token; 40 | 41 | DydxFlashInterface(getDydxLoanAddr()).initiateFlashLoan(_token, tokenAmt, data); 42 | 43 | AccountInterface(address(this)).disable(getDydxLoanAddr()); 44 | 45 | emit LogDydxFlashLoan(token, tokenAmt); 46 | bytes32 _eventCode = keccak256("LogDydxFlashLoan(address,uint256)"); 47 | bytes memory _eventParam = abi.encode(token, tokenAmt); 48 | (uint _type, uint _id) = connectorID(); 49 | EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam); 50 | } 51 | 52 | } 53 | 54 | 55 | contract ConnectDydxFlashLoan is FlashLoanResolver { 56 | string public constant name = "dydx-flashloan-v1"; 57 | } 58 | -------------------------------------------------------------------------------- /contracts/connectors/fee.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | pragma experimental ABIEncoderV2; 3 | 4 | interface MemoryInterface { 5 | function getUint(uint _id) external returns (uint _num); 6 | function setUint(uint _id, uint _val) external; 7 | } 8 | 9 | contract DSMath { 10 | uint256 constant WAD = 10 ** 18; 11 | 12 | function add(uint x, uint y) internal pure returns (uint z) { 13 | require((z = x + y) >= x, "math-not-safe"); 14 | } 15 | 16 | function sub(uint x, uint y) internal pure returns (uint z) { 17 | require((z = x - y) <= x, "sub-overflow"); 18 | } 19 | 20 | 21 | function mul(uint x, uint y) internal pure returns (uint z) { 22 | require(y == 0 || (z = x * y) / y == x, "math-not-safe"); 23 | } 24 | 25 | function wmul(uint x, uint y) internal pure returns (uint z) { 26 | z = add(mul(x, y), WAD / 2) / WAD; 27 | } 28 | } 29 | 30 | contract Setup is DSMath { 31 | 32 | /** 33 | * @dev Return InstAaMemory Address. 34 | */ 35 | function getMemoryAddr() internal pure returns (address) { 36 | return 0x8a5419CfC711B2343c17a6ABf4B2bAFaBb06957F; 37 | } 38 | 39 | /** 40 | * @dev Get Uint value from InstaMemory Contract. 41 | */ 42 | function getUint(uint getId, uint val) internal returns (uint returnVal) { 43 | returnVal = getId == 0 ? val : MemoryInterface(getMemoryAddr()).getUint(getId); 44 | } 45 | 46 | /** 47 | * @dev Set Uint value in InstaMemory Contract. 48 | */ 49 | function setUint(uint setId, uint val) internal { 50 | if (setId != 0) MemoryInterface(getMemoryAddr()).setUint(setId, val); 51 | } 52 | 53 | /** 54 | * @dev Connector ID and Type 55 | */ 56 | function connectorID() public pure returns(uint _type, uint _id) { 57 | (_type, _id) = (1, 70); 58 | } 59 | 60 | } 61 | 62 | 63 | contract FeeResolver is Setup { 64 | 65 | /** 66 | * @dev Calculate fee 67 | * @param amount token amount to caculate fee. 68 | * @param fee fee percentage. Eg: 1% => 1e17, 100% => 1e18. 69 | * @param getId Get token amount at this ID from `InstaMemory` Contract. 70 | * @param setId Set total amount at this ID in `InstaMemory` Contract. 71 | * @param setIdFee Set only fee amount at this ID in `InstaMemory` Contract. 72 | */ 73 | function calculateFee( 74 | uint amount, 75 | uint fee, 76 | uint getId, 77 | uint setId, 78 | uint setIdFee 79 | ) external payable { 80 | uint _amt = getUint(getId, amount); 81 | 82 | uint feeAmt = wmul(_amt, fee); 83 | 84 | uint totalAmt = add(_amt, feeAmt); 85 | 86 | setUint(setId, totalAmt); 87 | setUint(setIdFee, feeAmt); 88 | } 89 | 90 | /** 91 | * @dev Calculate amount minus fee 92 | * @param amount token amount to caculate fee. 93 | * @param fee fee percentage. Eg: 1% => 1e17, 100% => 1e18. 94 | * @param getId Get token amount at this ID from `InstaMemory` Contract. 95 | * @param setIdAmtMinusFee Set amount minus fee amount at this ID in `InstaMemory` Contract. 96 | * @param setIdFee Set only fee amount at this ID in `InstaMemory` Contract. 97 | */ 98 | function calculateAmtMinusFee( 99 | uint amount, 100 | uint fee, 101 | uint getId, 102 | uint setIdAmtMinusFee, 103 | uint setIdFee 104 | ) external payable { 105 | uint _amt = getUint(getId, amount); 106 | 107 | uint feeAmt = wmul(_amt, fee); 108 | uint amountMinusFee = sub(_amt, feeAmt); 109 | 110 | setUint(setIdAmtMinusFee, amountMinusFee); 111 | setUint(setIdFee, feeAmt); 112 | } 113 | } 114 | 115 | 116 | contract ConnectFee is FeeResolver { 117 | string public constant name = "Fee-v1.1"; 118 | } -------------------------------------------------------------------------------- /contracts/connectors/kyber.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | 3 | // import files from common directory 4 | import { TokenInterface , MemoryInterface, EventInterface} from "../common/interfaces.sol"; 5 | import { Stores } from "../common/stores.sol"; 6 | import { DSMath } from "../common/math.sol"; 7 | 8 | interface KyberInterface { 9 | function trade( 10 | address src, 11 | uint srcAmount, 12 | address dest, 13 | address destAddress, 14 | uint maxDestAmount, 15 | uint minConversionRate, 16 | address walletId 17 | ) external payable returns (uint); 18 | 19 | function getExpectedRate( 20 | address src, 21 | address dest, 22 | uint srcQty 23 | ) external view returns (uint, uint); 24 | } 25 | 26 | 27 | contract KyberHelpers is DSMath, Stores { 28 | /** 29 | * @dev Kyber Proxy Address 30 | */ 31 | function getKyberAddr() internal pure returns (address) { 32 | return 0x818E6FECD516Ecc3849DAf6845e3EC868087B755; 33 | } 34 | 35 | /** 36 | * @dev Referral Address 37 | */ 38 | function getReferralAddr() internal pure returns (address) { 39 | return 0x7284a8451d9a0e7Dc62B3a71C0593eA2eC5c5638; 40 | } 41 | } 42 | 43 | 44 | contract KyberResolver is KyberHelpers { 45 | event LogSell( 46 | address indexed buyToken, 47 | address indexed sellToken, 48 | uint256 buyAmt, 49 | uint256 sellAmt, 50 | uint256 getId, 51 | uint256 setId 52 | ); 53 | 54 | /** 55 | * @dev Sell ETH/ERC20_Token. 56 | * @param buyAddr buying token address.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) 57 | * @param sellAddr selling token amount.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) 58 | * @param sellAmt selling token amount. 59 | * @param unitAmt unit amount of buyAmt/sellAmt with slippage. 60 | * @param getId Get token amount at this ID from `InstaMemory` Contract. 61 | * @param setId Set token amount at this ID in `InstaMemory` Contract. 62 | */ 63 | function sell( 64 | address buyAddr, 65 | address sellAddr, 66 | uint sellAmt, 67 | uint unitAmt, 68 | uint getId, 69 | uint setId 70 | ) external payable 71 | { 72 | uint _sellAmt = getUint(getId, sellAmt); 73 | 74 | uint ethAmt; 75 | if (sellAddr == getEthAddr()) { 76 | _sellAmt = _sellAmt == uint(-1) ? address(this).balance : _sellAmt; 77 | ethAmt = _sellAmt; 78 | } else { 79 | TokenInterface sellContract = TokenInterface(sellAddr); 80 | _sellAmt = _sellAmt == uint(-1) ? sellContract.balanceOf(address(this)) : _sellAmt; 81 | sellContract.approve(getKyberAddr(), _sellAmt); 82 | } 83 | 84 | uint _buyAmt = KyberInterface(getKyberAddr()).trade.value(ethAmt)( 85 | sellAddr, 86 | _sellAmt, 87 | buyAddr, 88 | address(this), 89 | uint(-1), 90 | unitAmt, 91 | getReferralAddr() 92 | ); 93 | 94 | setUint(setId, _buyAmt); 95 | 96 | emit LogSell(buyAddr, sellAddr, _buyAmt, _sellAmt, getId, setId); 97 | bytes32 eventCode = keccak256("LogSell(address,address,uint256,uint256,uint256,uint256)"); 98 | bytes memory eventData = abi.encode(buyAddr, sellAddr, _buyAmt, _sellAmt, getId, setId); 99 | emitEvent(eventCode, eventData); 100 | } 101 | } 102 | 103 | 104 | contract ConnectKyber is KyberResolver { 105 | string public name = "Kyber-v1"; 106 | } -------------------------------------------------------------------------------- /contracts/connectors/mock.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | 3 | // import files from common directory 4 | import { TokenInterface , MemoryInterface, EventInterface} from "../common/interfaces.sol"; 5 | import { Stores } from "../common/stores.sol"; 6 | import { DSMath } from "../common/math.sol"; 7 | 8 | contract MockProtocol is Stores, DSMath { 9 | 10 | event LogMock(uint mockOne, uint mockTwo, uint getId, uint setId); 11 | 12 | // added two additional parameter (getId & setId) for external public facing functions 13 | function mockFunction(uint mockNumber, uint getId, uint setId) external payable { 14 | 15 | // protocol specific logics goes here 16 | 17 | // fetch value of specific id 18 | uint mockBalance = getUint(getId, mockNumber); 19 | 20 | // uses uint(-1) 21 | mockBalance = mockBalance == uint(-1) ? address(this).balance : mockNumber; 22 | 23 | // store new value for specific id 24 | setUint(setId, mockNumber); 25 | 26 | // common event standard 27 | emit LogMock(mockNumber, mockBalance, getId, setId); 28 | bytes32 eventCode = keccak256("LogMock(uint256,uint256,uint256,uint256)"); 29 | bytes memory eventData = abi.encode(mockNumber, mockBalance, getId, setId); 30 | emitEvent(eventCode, eventData); 31 | } 32 | 33 | } 34 | 35 | contract ConnectMock is MockProtocol { 36 | string public name = "Mock-v1"; 37 | } -------------------------------------------------------------------------------- /contracts/connectors/staking.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | pragma experimental ABIEncoderV2; 3 | 4 | // import files from common directory 5 | import { TokenInterface } from "../common/interfaces.sol"; 6 | import { Stores } from "../common/stores.sol"; 7 | import { DSMath } from "../common/math.sol"; 8 | 9 | interface IStakingRewards { 10 | function stake(uint256 amount) external; 11 | function withdraw(uint256 amount) external; 12 | function getReward() external; 13 | function balanceOf(address) external view returns(uint); 14 | } 15 | 16 | interface SynthetixMapping { 17 | 18 | struct StakingData { 19 | address stakingPool; 20 | address stakingToken; 21 | address rewardToken; 22 | } 23 | 24 | function stakingMapping(bytes32) external view returns(StakingData memory); 25 | 26 | } 27 | 28 | contract StakingHelper is DSMath, Stores { 29 | /** 30 | * @dev Return InstaDApp Staking Mapping Addresses 31 | */ 32 | function getMappingAddr() internal virtual view returns (address) { 33 | return 0x772590F33eD05b0E83553650BF9e75A04b337526; // InstaMapping Address 34 | } 35 | 36 | /** 37 | * @dev Convert String to bytes32. 38 | */ 39 | function stringToBytes32(string memory str) internal pure returns (bytes32 result) { 40 | require(bytes(str).length != 0, "string-empty"); 41 | // solium-disable-next-line security/no-inline-assembly 42 | assembly { 43 | result := mload(add(str, 32)) 44 | } 45 | } 46 | 47 | /** 48 | * @dev Get staking data 49 | */ 50 | function getStakingData(string memory stakingName) 51 | internal 52 | view 53 | returns ( 54 | IStakingRewards stakingContract, 55 | TokenInterface stakingToken, 56 | TokenInterface rewardToken, 57 | bytes32 stakingType 58 | ) 59 | { 60 | stakingType = stringToBytes32(stakingName); 61 | SynthetixMapping.StakingData memory stakingData = SynthetixMapping(getMappingAddr()).stakingMapping(stakingType); 62 | require(stakingData.stakingPool != address(0) && stakingData.stakingToken != address(0), "Wrong Staking Name"); 63 | stakingContract = IStakingRewards(stakingData.stakingPool); 64 | stakingToken = TokenInterface(stakingData.stakingToken); 65 | rewardToken = TokenInterface(stakingData.rewardToken); 66 | } 67 | } 68 | 69 | contract Staking is StakingHelper { 70 | event LogDeposit( 71 | address indexed stakingToken, 72 | bytes32 indexed stakingType, 73 | uint256 amount, 74 | uint getId, 75 | uint setId 76 | ); 77 | 78 | event LogWithdraw( 79 | address indexed stakingToken, 80 | bytes32 indexed stakingType, 81 | uint256 amount, 82 | uint getId, 83 | uint setId 84 | ); 85 | 86 | event LogClaimedReward( 87 | address indexed rewardToken, 88 | bytes32 indexed stakingType, 89 | uint256 rewardAmt, 90 | uint setId 91 | ); 92 | 93 | /** 94 | * @dev Deposit Token. 95 | * @param stakingPoolName staking token address. 96 | * @param amt staking token amount. 97 | * @param getId Get token amount at this ID from `InstaMemory` Contract. 98 | * @param setId Set token amount at this ID in `InstaMemory` Contract. 99 | */ 100 | function deposit( 101 | string calldata stakingPoolName, 102 | uint amt, 103 | uint getId, 104 | uint setId 105 | ) external payable { 106 | uint _amt = getUint(getId, amt); 107 | ( 108 | IStakingRewards stakingContract, 109 | TokenInterface stakingToken, 110 | , 111 | bytes32 stakingType 112 | ) = getStakingData(stakingPoolName); 113 | 114 | _amt = _amt == uint(-1) ? stakingToken.balanceOf(address(this)) : _amt; 115 | 116 | stakingToken.approve(address(stakingContract), _amt); 117 | stakingContract.stake(_amt); 118 | 119 | setUint(setId, _amt); 120 | emit LogDeposit(address(stakingToken), stakingType, _amt, getId, setId); 121 | bytes32 _eventCode = keccak256("LogDeposit(address,bytes32,uint256,uint256,uint256)"); 122 | bytes memory _eventParam = abi.encode(address(stakingToken), stakingType, _amt, getId, setId); 123 | emitEvent(_eventCode, _eventParam); 124 | } 125 | 126 | /** 127 | * @dev Withdraw Token. 128 | * @param stakingPoolName staking token address. 129 | * @param amt staking token amount. 130 | * @param getId Get token amount at this ID from `InstaMemory` Contract. 131 | * @param setIdAmount Set token amount at this ID in `InstaMemory` Contract. 132 | * @param setIdReward Set reward amount at this ID in `InstaMemory` Contract. 133 | */ 134 | function withdraw( 135 | string calldata stakingPoolName, 136 | uint amt, 137 | uint getId, 138 | uint setIdAmount, 139 | uint setIdReward 140 | ) external payable { 141 | uint _amt = getUint(getId, amt); 142 | ( 143 | IStakingRewards stakingContract, 144 | TokenInterface stakingToken, 145 | TokenInterface rewardToken, 146 | bytes32 stakingType 147 | ) = getStakingData(stakingPoolName); 148 | 149 | _amt = _amt == uint(-1) ? stakingContract.balanceOf(address(this)) : _amt; 150 | uint intialBal = rewardToken.balanceOf(address(this)); 151 | stakingContract.withdraw(_amt); 152 | stakingContract.getReward(); 153 | uint finalBal = rewardToken.balanceOf(address(this)); 154 | 155 | uint rewardAmt = sub(finalBal, intialBal); 156 | 157 | setUint(setIdAmount, _amt); 158 | setUint(setIdReward, rewardAmt); 159 | 160 | emit LogWithdraw(address(stakingToken), stakingType, _amt, getId, setIdAmount); 161 | bytes32 _eventCodeWithdraw = keccak256("LogWithdraw(address,bytes32,uint256,uint256,uint256)"); 162 | bytes memory _eventParamWithdraw = abi.encode(address(stakingToken), stakingType, _amt, getId, setIdAmount); 163 | emitEvent(_eventCodeWithdraw, _eventParamWithdraw); 164 | 165 | emit LogClaimedReward(address(rewardToken), stakingType, rewardAmt, setIdReward); 166 | bytes32 _eventCodeReward = keccak256("LogClaimedReward(address,bytes32,uint256,uint256)"); 167 | bytes memory _eventParamReward = abi.encode(address(rewardToken), stakingType, rewardAmt, setIdReward); 168 | emitEvent(_eventCodeReward, _eventParamReward); 169 | } 170 | 171 | /** 172 | * @dev Claim Reward. 173 | * @param stakingPoolName staking token address. 174 | * @param setId Set reward amount at this ID in `InstaMemory` Contract. 175 | */ 176 | function claimReward( 177 | string calldata stakingPoolName, 178 | uint setId 179 | ) external payable { 180 | ( 181 | IStakingRewards stakingContract, 182 | , 183 | TokenInterface rewardToken, 184 | bytes32 stakingType 185 | ) = getStakingData(stakingPoolName); 186 | 187 | uint intialBal = rewardToken.balanceOf(address(this)); 188 | stakingContract.getReward(); 189 | uint finalBal = rewardToken.balanceOf(address(this)); 190 | 191 | uint rewardAmt = sub(finalBal, intialBal); 192 | 193 | setUint(setId, rewardAmt); 194 | emit LogClaimedReward(address(rewardToken), stakingType, rewardAmt, setId); 195 | bytes32 _eventCode = keccak256("LogClaimedReward(address,bytes32,uint256,uint256)"); 196 | bytes memory _eventParam = abi.encode(address(rewardToken), stakingType, rewardAmt, setId); 197 | emitEvent(_eventCode, _eventParam); 198 | } 199 | } 200 | 201 | contract ConnectStaking is Staking { 202 | string public name = "Staking-v1.1"; 203 | } 204 | -------------------------------------------------------------------------------- /contracts/connectors/swerve.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | 3 | // import files from common directory 4 | import { TokenInterface , MemoryInterface, EventInterface} from "../common/interfaces.sol"; 5 | import { Stores } from "../common/stores.sol"; 6 | import { DSMath } from "../common/math.sol"; 7 | 8 | interface ISwerve { 9 | function underlying_coins(int128 tokenId) external view returns (address token); 10 | function calc_token_amount(uint256[4] calldata amounts, bool deposit) external returns (uint256 amount); 11 | function add_liquidity(uint256[4] calldata amounts, uint256 min_mint_amount) external; 12 | function get_dy(int128 sellTokenId, int128 buyTokenId, uint256 sellTokenAmt) external returns (uint256 buyTokenAmt); 13 | function exchange(int128 sellTokenId, int128 buyTokenId, uint256 sellTokenAmt, uint256 minBuyToken) external; 14 | function remove_liquidity_imbalance(uint256[4] calldata amounts, uint256 max_burn_amount) external; 15 | } 16 | 17 | interface ISwerveZap { 18 | function calc_withdraw_one_coin(uint256 _token_amount, int128 i) external returns (uint256 amount); 19 | } 20 | 21 | 22 | contract SwerveHelpers is Stores, DSMath { 23 | /** 24 | * @dev Return Swerve Swap Address 25 | */ 26 | function getSwerveSwapAddr() internal pure returns (address) { 27 | return 0x329239599afB305DA0A2eC69c58F8a6697F9F88d; 28 | } 29 | 30 | /** 31 | * @dev Return Swerve Token Address 32 | */ 33 | function getSwerveTokenAddr() internal pure returns (address) { 34 | return 0x77C6E4a580c0dCE4E5c7a17d0bc077188a83A059; 35 | } 36 | 37 | /** 38 | * @dev Return Swerve Zap Address 39 | */ 40 | function getSwerveZapAddr() internal pure returns (address) { 41 | return 0xa746c67eB7915Fa832a4C2076D403D4B68085431; 42 | } 43 | 44 | function convert18ToDec(uint _dec, uint256 _amt) internal pure returns (uint256 amt) { 45 | amt = (_amt / 10 ** (18 - _dec)); 46 | } 47 | 48 | function convertTo18(uint _dec, uint256 _amt) internal pure returns (uint256 amt) { 49 | amt = mul(_amt, 10 ** (18 - _dec)); 50 | } 51 | 52 | function getTokenI(address token) internal pure returns (int128 i) { 53 | if (token == address(0x6B175474E89094C44Da98b954EedeAC495271d0F)) { 54 | // DAI Token 55 | i = 0; 56 | } else if (token == address(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48)) { 57 | // USDC Token 58 | i = 1; 59 | } else if (token == address(0xdAC17F958D2ee523a2206206994597C13D831ec7)) { 60 | // USDT Token 61 | i = 2; 62 | } else if (token == address(0x0000000000085d4780B73119b644AE5ecd22b376)) { 63 | // TUSD Token 64 | i = 3; 65 | } else { 66 | revert("token-not-found."); 67 | } 68 | } 69 | } 70 | 71 | contract SwerveProtocol is SwerveHelpers { 72 | 73 | event LogSell( 74 | address indexed buyToken, 75 | address indexed sellToken, 76 | uint256 buyAmt, 77 | uint256 sellAmt, 78 | uint256 getId, 79 | uint256 setId 80 | ); 81 | event LogDeposit(address token, uint256 amt, uint256 mintAmt, uint256 getId, uint256 setId); 82 | event LogWithdraw(address token, uint256 amt, uint256 burnAmt, uint256 getId, uint256 setId); 83 | 84 | /** 85 | * @dev Sell Stable ERC20_Token. 86 | * @param buyAddr buying token address. 87 | * @param sellAddr selling token amount. 88 | * @param sellAmt selling token amount. 89 | * @param unitAmt unit amount of buyAmt/sellAmt with slippage. 90 | * @param getId Get token amount at this ID from `InstaMemory` Contract. 91 | * @param setId Set token amount at this ID in `InstaMemory` Contract. 92 | */ 93 | function sell( 94 | address buyAddr, 95 | address sellAddr, 96 | uint sellAmt, 97 | uint unitAmt, 98 | uint getId, 99 | uint setId 100 | ) external payable { 101 | uint _sellAmt = getUint(getId, sellAmt); 102 | ISwerve swerve = ISwerve(getSwerveSwapAddr()); 103 | TokenInterface _buyToken = TokenInterface(buyAddr); 104 | TokenInterface _sellToken = TokenInterface(sellAddr); 105 | _sellAmt = _sellAmt == uint(-1) ? _sellToken.balanceOf(address(this)) : _sellAmt; 106 | _sellToken.approve(address(swerve), _sellAmt); 107 | 108 | uint _slippageAmt = convert18ToDec(_buyToken.decimals(), wmul(unitAmt, convertTo18(_sellToken.decimals(), _sellAmt))); 109 | 110 | uint intialBal = _buyToken.balanceOf(address(this)); 111 | swerve.exchange(getTokenI(sellAddr), getTokenI(buyAddr), _sellAmt, _slippageAmt); 112 | uint finalBal = _buyToken.balanceOf(address(this)); 113 | 114 | uint _buyAmt = sub(finalBal, intialBal); 115 | 116 | setUint(setId, _buyAmt); 117 | 118 | emit LogSell(buyAddr, sellAddr, _buyAmt, _sellAmt, getId, setId); 119 | bytes32 _eventCode = keccak256("LogSell(address,address,uint256,uint256,uint256,uint256)"); 120 | bytes memory _eventParam = abi.encode(buyAddr, sellAddr, _buyAmt, _sellAmt, getId, setId); 121 | emitEvent(_eventCode, _eventParam); 122 | 123 | } 124 | 125 | /** 126 | * @dev Deposit Token. 127 | * @param token token address. 128 | * @param amt token amount. 129 | * @param unitAmt unit amount of swerve_amt/token_amt with slippage. 130 | * @param getId Get token amount at this ID from `InstaMemory` Contract. 131 | * @param setId Set token amount at this ID in `InstaMemory` Contract. 132 | */ 133 | function deposit( 134 | address token, 135 | uint amt, 136 | uint unitAmt, 137 | uint getId, 138 | uint setId 139 | ) external payable { 140 | uint256 _amt = getUint(getId, amt); 141 | TokenInterface tokenContract = TokenInterface(token); 142 | 143 | _amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt; 144 | uint[4] memory _amts; 145 | _amts[uint(getTokenI(token))] = _amt; 146 | 147 | tokenContract.approve(getSwerveSwapAddr(), _amt); 148 | 149 | uint _amt18 = convertTo18(tokenContract.decimals(), _amt); 150 | uint _slippageAmt = wmul(unitAmt, _amt18); 151 | 152 | TokenInterface swerveTokenContract = TokenInterface(getSwerveTokenAddr()); 153 | uint initialSwerveBal = swerveTokenContract.balanceOf(address(this)); 154 | 155 | ISwerve(getSwerveSwapAddr()).add_liquidity(_amts, _slippageAmt); 156 | 157 | uint finalSwerveBal = swerveTokenContract.balanceOf(address(this)); 158 | 159 | uint mintAmt = sub(finalSwerveBal, initialSwerveBal); 160 | 161 | setUint(setId, mintAmt); 162 | 163 | emit LogDeposit(token, _amt, mintAmt, getId, setId); 164 | bytes32 _eventCode = keccak256("LogDeposit(address,uint256,uint256,uint256,uint256)"); 165 | bytes memory _eventParam = abi.encode(token, _amt, mintAmt, getId, setId); 166 | emitEvent(_eventCode, _eventParam); 167 | } 168 | 169 | /** 170 | * @dev Withdraw Token. 171 | * @param token token address. 172 | * @param amt token amount. 173 | * @param unitAmt unit amount of swerve_amt/token_amt with slippage. 174 | * @param getId Get token amount at this ID from `InstaMemory` Contract. 175 | * @param setId Set token amount at this ID in `InstaMemory` Contract. 176 | */ 177 | function withdraw( 178 | address token, 179 | uint256 amt, 180 | uint256 unitAmt, 181 | uint getId, 182 | uint setId 183 | ) external payable { 184 | uint _amt = getUint(getId, amt); 185 | int128 tokenId = getTokenI(token); 186 | 187 | TokenInterface swerveTokenContract = TokenInterface(getSwerveTokenAddr()); 188 | ISwerveZap swerveZap = ISwerveZap(getSwerveZapAddr()); 189 | ISwerve swerveSwap = ISwerve(getSwerveSwapAddr()); 190 | 191 | uint _swerveAmt; 192 | uint[4] memory _amts; 193 | if (_amt == uint(-1)) { 194 | _swerveAmt = swerveTokenContract.balanceOf(address(this)); 195 | _amt = swerveZap.calc_withdraw_one_coin(_swerveAmt, tokenId); 196 | _amts[uint(tokenId)] = _amt; 197 | } else { 198 | _amts[uint(tokenId)] = _amt; 199 | _swerveAmt = swerveSwap.calc_token_amount(_amts, false); 200 | } 201 | 202 | 203 | uint _amt18 = convertTo18(TokenInterface(token).decimals(), _amt); 204 | uint _slippageAmt = wmul(unitAmt, _amt18); 205 | 206 | swerveTokenContract.approve(address(swerveSwap), 0); 207 | swerveTokenContract.approve(address(swerveSwap), _slippageAmt); 208 | 209 | swerveSwap.remove_liquidity_imbalance(_amts, _slippageAmt); 210 | 211 | setUint(setId, _amt); 212 | 213 | emit LogWithdraw(token, _amt, _swerveAmt, getId, setId); 214 | bytes32 _eventCode = keccak256("LogWithdraw(address,uint256,uint256,uint256,uint256)"); 215 | bytes memory _eventParam = abi.encode(token, _amt, _swerveAmt, getId, setId); 216 | emitEvent(_eventCode, _eventParam); 217 | } 218 | 219 | } 220 | 221 | contract ConnectSwerve is SwerveProtocol { 222 | string public name = "Swerve-swUSD-v1.0"; 223 | } 224 | -------------------------------------------------------------------------------- /contracts/flashloan/dydx.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | pragma experimental ABIEncoderV2; 3 | 4 | import "@studydefi/money-legos/dydx/contracts/DydxFlashloanBase.sol"; 5 | import "@studydefi/money-legos/dydx/contracts/ICallee.sol"; 6 | 7 | import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; 8 | import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol"; 9 | import { DSMath } from "../common/math.sol"; 10 | 11 | interface DSAInterface { 12 | function cast(address[] calldata _targets, bytes[] calldata _datas, address _origin) external payable; 13 | } 14 | 15 | contract Helper { 16 | struct CastData { 17 | address dsa; 18 | address token; 19 | uint amount; 20 | address[] targets; 21 | bytes[] data; 22 | } 23 | 24 | function encodeDsaAddr(address dsa, bytes memory data) internal view returns (bytes memory _data) { 25 | CastData memory cd; 26 | (cd.token, cd.amount, cd.targets, cd.data) = abi.decode(data, (address, uint256, address[], bytes[])); 27 | _data = abi.encode(dsa, cd.token, cd.amount, cd.targets, cd.data); 28 | } 29 | } 30 | 31 | contract DydxFlashloaner is ICallee, DydxFlashloanBase, DSMath, Helper { 32 | using SafeERC20 for IERC20; 33 | 34 | // address public constant soloAddr = 0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e; 35 | // address public constant wethAddr = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; 36 | // address public constant ethAddr = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; 37 | 38 | address public constant soloAddr = 0x4EC3570cADaAEE08Ae384779B0f3A45EF85289DE; 39 | address public constant wethAddr = 0xd0A1E359811322d97991E03f863a0C30C2cF029C; 40 | address public constant ethAddr = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; 41 | 42 | event LogDydxFlashLoan( 43 | address indexed sender, 44 | address indexed token, 45 | uint amount 46 | ); 47 | 48 | function callFunction( 49 | address sender, 50 | Account.Info memory account, 51 | bytes memory data 52 | ) public override { 53 | require(sender == address(this), "not-same-sender"); 54 | CastData memory cd; 55 | (cd.dsa, cd.token, cd.amount, cd.targets, cd.data) = abi.decode( 56 | data, 57 | (address, address, uint256, address[], bytes[]) 58 | ); 59 | 60 | IERC20 tokenContract; 61 | if (cd.token == ethAddr) { 62 | tokenContract = IERC20(wethAddr); 63 | tokenContract.approve(wethAddr, cd.amount); 64 | tokenContract.withdraw(cd.amount); 65 | payable(cd.dsa).transfer(cd.amount); 66 | } else { 67 | tokenContract = IERC20(cd.token); 68 | tokenContract.safeTransfer(cd.dsa, cd.amount); 69 | } 70 | 71 | DSAInterface(cd.dsa).cast(cd.targets, cd.data, 0xB7fA44c2E964B6EB24893f7082Ecc08c8d0c0F87); 72 | 73 | if (cd.token == ethAddr) { 74 | tokenContract.deposit.value(cd.amount)(); 75 | } 76 | 77 | } 78 | 79 | function initiateFlashLoan(address _token, uint256 _amount, bytes calldata data) external { 80 | ISoloMargin solo = ISoloMargin(soloAddr); 81 | 82 | uint256 marketId = _getMarketIdFromTokenAddress(soloAddr, _token); 83 | 84 | IERC20(_token).approve(soloAddr, _amount + 2); 85 | 86 | Actions.ActionArgs[] memory operations = new Actions.ActionArgs[](3); 87 | 88 | operations[0] = _getWithdrawAction(marketId, _amount); 89 | operations[1] = _getCallAction(encodeDsaAddr(msg.sender, data)); 90 | operations[2] = _getDepositAction(marketId, _amount + 2); 91 | 92 | Account.Info[] memory accountInfos = new Account.Info[](1); 93 | accountInfos[0] = _getAccountInfo(); 94 | 95 | IERC20 _tokenContract = IERC20(_token); 96 | uint iniBal = _tokenContract.balanceOf(address(this)); 97 | 98 | solo.operate(accountInfos, operations); 99 | 100 | uint finBal = _tokenContract.balanceOf(address(this)); 101 | require(sub(iniBal, finBal) < 5, "amount-paid-less"); 102 | } 103 | 104 | } 105 | 106 | contract InstaDydxFlashLoan is DydxFlashloaner { 107 | 108 | receive() external payable {} 109 | } -------------------------------------------------------------------------------- /contracts/mapping/1inch.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | pragma experimental ABIEncoderV2; 3 | 4 | interface IndexInterface { 5 | function master() external view returns (address); 6 | } 7 | 8 | interface ConnectorsInterface { 9 | function chief(address) external view returns (bool); 10 | } 11 | 12 | contract Helpers { 13 | 14 | event LogChangeOneProto(address oneProto); 15 | 16 | address public constant connectors = 0xD6A602C01a023B98Ecfb29Df02FBA380d3B21E0c; 17 | address public constant instaIndex = 0x2971AdFa57b20E5a416aE5a708A8655A9c74f723; 18 | address public oneProtoAddress; 19 | 20 | modifier isChief { 21 | require( 22 | ConnectorsInterface(connectors).chief(msg.sender) || 23 | IndexInterface(instaIndex).master() == msg.sender, "not-Chief"); 24 | _; 25 | } 26 | 27 | function changeOneProtoAddress(address _oneProtoAddr) external isChief { 28 | require(_oneProtoAddr != address(0), "oneProtoAddress-is-address(0)"); 29 | require(oneProtoAddress != _oneProtoAddr, "Same-oneProtoAddress"); 30 | 31 | oneProtoAddress = _oneProtoAddr; 32 | emit LogChangeOneProto(_oneProtoAddr); 33 | } 34 | } 35 | 36 | contract InstaOneMapping is Helpers { 37 | constructor () public { 38 | oneProtoAddress = 0x6cb2291A3c3794fcA0F5b6E34a8E6eA7933CA667; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /contracts/mapping/curve_gauge_mapping.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | pragma experimental ABIEncoderV2; 3 | 4 | interface ConnectorsInterface { 5 | function chief(address) external view returns (bool); 6 | } 7 | 8 | interface IndexInterface { 9 | function master() external view returns (address); 10 | } 11 | 12 | contract BytesHelper { 13 | /** 14 | * @dev Convert String to bytes32. 15 | */ 16 | function stringToBytes32(string memory str) internal pure returns (bytes32 result) { 17 | require(bytes(str).length != 0, "String-Empty"); 18 | // solium-disable-next-line security/no-inline-assembly 19 | assembly { 20 | result := mload(add(str, 32)) 21 | } 22 | } 23 | } 24 | 25 | contract Helpers is BytesHelper { 26 | address public constant connectors = 0xD6A602C01a023B98Ecfb29Df02FBA380d3B21E0c; 27 | address public constant instaIndex = 0x2971AdFa57b20E5a416aE5a708A8655A9c74f723; 28 | uint public version = 1; 29 | 30 | mapping (bytes32 => GaugeData) public gaugeMapping; 31 | 32 | struct GaugeData { 33 | address gaugeAddress; 34 | bool rewardToken; 35 | } 36 | 37 | event LogAddGaugeMapping( 38 | string gaugeName, 39 | address gaugeAddress, 40 | bool rewardToken 41 | ); 42 | 43 | event LogRemoveGaugeMapping( 44 | string gaugeName, 45 | address gaugeAddress 46 | ); 47 | 48 | modifier isChief virtual { 49 | require( 50 | ConnectorsInterface(connectors).chief(msg.sender) || 51 | IndexInterface(instaIndex).master() == msg.sender, "not-Chief"); 52 | _; 53 | } 54 | 55 | function _addGaugeMapping( 56 | string memory gaugeName, 57 | address gaugeAddress, 58 | bool rewardToken 59 | ) internal { 60 | require(gaugeAddress != address(0), "gaugeAddress-not-vaild"); 61 | require(bytes(gaugeName).length <= 32, "Length-exceeds"); 62 | bytes32 gaugeType = stringToBytes32(gaugeName); 63 | require(gaugeMapping[gaugeType].gaugeAddress == address(0), "gaugePool-already-added"); 64 | 65 | gaugeMapping[gaugeType].gaugeAddress = gaugeAddress; 66 | gaugeMapping[gaugeType].rewardToken = rewardToken; 67 | 68 | emit LogAddGaugeMapping(gaugeName, gaugeAddress, rewardToken); 69 | } 70 | 71 | function addGaugeMappings( 72 | string[] memory gaugeNames, 73 | address[] memory gaugeAddresses, 74 | bool[] memory rewardTokens 75 | ) public isChief { 76 | require(gaugeNames.length == gaugeAddresses.length && gaugeAddresses.length == rewardTokens.length, "length-not-match"); 77 | for (uint32 i; i < gaugeNames.length; i++) { 78 | _addGaugeMapping(gaugeNames[i], gaugeAddresses[i], rewardTokens[i]); 79 | } 80 | } 81 | 82 | function removeGaugeMapping(string memory gaugeName, address gaugeAddress) public isChief { 83 | require(gaugeAddress != address(0), "gaugeAddress-not-vaild"); 84 | bytes32 gaugeType = stringToBytes32(gaugeName); 85 | require(gaugeMapping[gaugeType].gaugeAddress == gaugeAddress, "different-gauge-pool"); 86 | 87 | delete gaugeMapping[gaugeType]; 88 | 89 | emit LogRemoveGaugeMapping( 90 | gaugeName, 91 | gaugeAddress 92 | ); 93 | } 94 | } 95 | 96 | contract CurveGaugeMapping is Helpers { 97 | string constant public name = "Curve-Gauge-Mapping-v1"; 98 | 99 | constructor ( 100 | string[] memory gaugeNames, 101 | address[] memory gaugeAddresses, 102 | bool[] memory rewardTokens 103 | ) public { 104 | require(gaugeNames.length == gaugeAddresses.length && gaugeAddresses.length == rewardTokens.length, "length-not-match"); 105 | for (uint32 i; i < gaugeNames.length; i++) { 106 | _addGaugeMapping(gaugeNames[i], gaugeAddresses[i], rewardTokens[i]); 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /contracts/mapping/instapoolFee.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | pragma experimental ABIEncoderV2; 3 | 4 | interface IndexInterface { 5 | function master() external view returns (address); 6 | } 7 | 8 | contract Helpers { 9 | 10 | event LogChangeFee(uint256 _fee); 11 | event LogChangeFeeCollector(address _feeCollector); 12 | 13 | address public constant instaIndex = 0x2971AdFa57b20E5a416aE5a708A8655A9c74f723; 14 | uint256 public fee; 15 | address public feeCollector; 16 | 17 | modifier isChief { 18 | require(IndexInterface(instaIndex).master() == msg.sender, "not-Master"); 19 | _; 20 | } 21 | 22 | function changeFee(uint256 _fee) external isChief { 23 | require(_fee <= 2 * 10 ** 15, "Fee is more than 0.2%"); 24 | fee = uint64(_fee); 25 | emit LogChangeFee(_fee); 26 | } 27 | 28 | function changeFeeCollector(address _feeCollector) external isChief { 29 | require(feeCollector != _feeCollector, "Same-feeCollector"); 30 | require(_feeCollector != address(0), "feeCollector-is-address(0)"); 31 | feeCollector = _feeCollector; 32 | emit LogChangeFeeCollector(_feeCollector); 33 | } 34 | } 35 | 36 | contract InstaPoolFee is Helpers { 37 | constructor () public { 38 | fee = 9 * 10 ** 14; // 0.09% 39 | feeCollector = IndexInterface(instaIndex).master(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /contracts/mapping/staking.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | pragma experimental ABIEncoderV2; 3 | 4 | interface ConnectorsInterface { 5 | function chief(address) external view returns (bool); 6 | } 7 | 8 | interface IndexInterface { 9 | function master() external view returns (address); 10 | } 11 | 12 | contract BytesHelper { 13 | /** 14 | * @dev Convert String to bytes32. 15 | */ 16 | function stringToBytes32(string memory str) internal pure returns (bytes32 result) { 17 | require(bytes(str).length != 0, "String-Empty"); 18 | // solium-disable-next-line security/no-inline-assembly 19 | assembly { 20 | result := mload(add(str, 32)) 21 | } 22 | } 23 | 24 | /** 25 | * @dev Convert bytes32 to String. 26 | */ 27 | function bytes32ToString(bytes32 _bytes32) internal pure returns (string memory) { 28 | bytes32 _temp; 29 | uint count; 30 | for (uint256 i; i < 32; i++) { 31 | _temp = _bytes32[i]; 32 | if( _temp != bytes32(0)) { 33 | count += 1; 34 | } 35 | } 36 | bytes memory bytesArray = new bytes(count); 37 | for (uint256 i; i < count; i++) { 38 | bytesArray[i] = (_bytes32[i]); 39 | } 40 | return (string(bytesArray)); 41 | } 42 | } 43 | 44 | contract Helpers is BytesHelper { 45 | address public constant connectors = 0xD6A602C01a023B98Ecfb29Df02FBA380d3B21E0c; 46 | address public constant instaIndex = 0x2971AdFa57b20E5a416aE5a708A8655A9c74f723; 47 | uint public version = 1; 48 | 49 | mapping (bytes32 => StakingData) public stakingMapping; 50 | 51 | struct StakingData { 52 | address stakingPool; 53 | address stakingToken; 54 | address rewardToken; 55 | } 56 | 57 | event LogAddStakingMapping( 58 | string stakingName, 59 | bytes32 stakingType, 60 | address stakingAddress, 61 | address stakingToken, 62 | address rewardToken 63 | ); 64 | event LogRemoveStakingMapping( 65 | string stakingName, 66 | bytes32 stakingType, 67 | address stakingAddress, 68 | address stakingToken, 69 | address rewardToken 70 | ); 71 | modifier isChief virtual { 72 | require( 73 | ConnectorsInterface(connectors).chief(msg.sender) || 74 | IndexInterface(instaIndex).master() == msg.sender, "not-Chief"); 75 | _; 76 | } 77 | 78 | function addStakingMapping( 79 | string memory stakingName, 80 | address stakingAddress, 81 | address stakingToken, 82 | address rewardToken 83 | ) public isChief { 84 | require(stakingAddress != address(0), "stakingAddress-not-vaild"); 85 | require(stakingToken != address(0), "stakingToken-not-vaild"); 86 | require(rewardToken != address(0), "rewardToken-not-vaild"); 87 | require(bytes(stakingName).length <= 32, "Length-exceeds"); 88 | bytes32 stakeType = stringToBytes32(stakingName); 89 | require(stakingMapping[stakeType].stakingPool == address(0), "StakingPool-already-added"); 90 | require(stakingMapping[stakeType].stakingToken == address(0), "StakingToken-already-added"); 91 | require(stakingMapping[stakeType].rewardToken == address(0), "rewardToken-already-added"); 92 | 93 | stakingMapping[stakeType] = StakingData( 94 | stakingAddress, 95 | stakingToken, 96 | rewardToken 97 | ); 98 | emit LogAddStakingMapping(stakingName, stakeType, stakingAddress, stakingToken, rewardToken); 99 | } 100 | 101 | function removeStakingMapping(string memory stakingName, address stakingAddress) public isChief { 102 | require(stakingAddress != address(0), "stakingAddress-not-vaild"); 103 | bytes32 stakeType = stringToBytes32(stakingName); 104 | require(stakingMapping[stakeType].stakingPool == stakingAddress, "different-staking-pool"); 105 | 106 | emit LogRemoveStakingMapping( 107 | stakingName, 108 | stakeType, 109 | stakingAddress, 110 | stakingMapping[stakeType].stakingToken, 111 | stakingMapping[stakeType].rewardToken 112 | ); 113 | delete stakingMapping[stakeType]; 114 | } 115 | } 116 | 117 | contract InstaStakingMapping is Helpers { 118 | string constant public name = "Staking-Mapping-v1"; 119 | } 120 | -------------------------------------------------------------------------------- /contracts/static/basic.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | 3 | /** 4 | * @title StaticConnectBasic. 5 | * @dev Static Connector to withdraw assets. 6 | */ 7 | 8 | interface TokenInterface { 9 | function balanceOf(address) external view returns (uint); 10 | function transfer(address, uint) external returns (bool); 11 | } 12 | 13 | interface AccountInterface { 14 | function isAuth(address) external view returns (bool); 15 | } 16 | 17 | interface EventInterface { 18 | function emitEvent(uint _connectorType, uint _connectorID, bytes32 _eventCode, bytes calldata _eventData) external; 19 | } 20 | 21 | contract Memory { 22 | 23 | /** 24 | * @dev Return InstaEvent Address. 25 | */ 26 | function getEventAddr() internal pure returns (address) { 27 | return 0x2af7ea6Cb911035f3eb1ED895Cb6692C39ecbA97; 28 | } 29 | 30 | function connectorID() public pure returns(uint _type, uint _id) { 31 | (_type, _id) = (2, 1); 32 | } 33 | 34 | } 35 | 36 | contract BasicResolver is Memory { 37 | 38 | event LogWithdraw(address erc20, uint tokenAmt, address to); 39 | 40 | /** 41 | * @dev ETH Address. 42 | */ 43 | function getEthAddr() internal pure returns (address) { 44 | return 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; 45 | } 46 | 47 | /** 48 | * @dev Withdraw Assets To Smart Account. 49 | * @param erc20 Token Address. 50 | * @param tokenAmt Token Amount. 51 | */ 52 | function withdraw( 53 | address erc20, 54 | uint tokenAmt 55 | ) external payable { 56 | uint amt; 57 | if (erc20 == getEthAddr()) { 58 | amt = tokenAmt == uint(-1) ? address(this).balance : tokenAmt; 59 | msg.sender.transfer(amt); 60 | } else { 61 | TokenInterface token = TokenInterface(erc20); 62 | amt = tokenAmt == uint(-1) ? token.balanceOf(address(this)) : tokenAmt; 63 | token.transfer(msg.sender, amt); 64 | } 65 | 66 | emit LogWithdraw(erc20, amt, msg.sender); 67 | 68 | bytes32 _eventCode = keccak256("LogWithdraw(address,uint256,address)"); 69 | bytes memory _eventParam = abi.encode(erc20, amt, msg.sender); 70 | (uint _type, uint _id) = connectorID(); 71 | EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam); 72 | } 73 | 74 | } 75 | 76 | 77 | contract StaticConnectBasic is BasicResolver { 78 | string public constant name = "Static-Basic-v1"; 79 | } -------------------------------------------------------------------------------- /contracts/static/maker.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | 3 | interface TokenInterface { 4 | function approve(address, uint) external; 5 | function transfer(address, uint) external; 6 | function transferFrom(address, address, uint) external; 7 | function deposit() external payable; 8 | function withdraw(uint) external; 9 | function balanceOf(address) external view returns (uint); 10 | } 11 | 12 | interface ManagerLike { 13 | function cdpCan(address, uint, address) external view returns (uint); 14 | function ilks(uint) external view returns (bytes32); 15 | function owns(uint) external view returns (address); 16 | function give(uint, address) external; 17 | function urns(uint) external view returns (address); 18 | function vat() external view returns (address); 19 | function frob(uint, int, int) external; 20 | function flux(uint, address, uint) external; 21 | } 22 | 23 | interface VatLike { 24 | function can(address, address) external view returns (uint); 25 | function dai(address) external view returns (uint); 26 | function hope(address) external; 27 | function urns(bytes32, address) external view returns (uint, uint); 28 | } 29 | 30 | interface TokenJoinInterface { 31 | function dec() external returns (uint); 32 | function gem() external returns (TokenInterface); 33 | function join(address, uint) external payable; 34 | function exit(address, uint) external; 35 | } 36 | 37 | interface DaiJoinInterface { 38 | function vat() external returns (VatLike); 39 | function exit(address, uint) external; 40 | } 41 | 42 | interface PotLike { 43 | function pie(address) external view returns (uint); 44 | function drip() external returns (uint); 45 | function exit(uint) external; 46 | } 47 | 48 | interface AccountInterface { 49 | function isAuth(address _user) external view returns (bool); 50 | } 51 | 52 | interface InstaMapping { 53 | function gemJoinMapping(bytes32) external view returns (address); 54 | } 55 | 56 | interface EventInterface { 57 | function emitEvent(uint _connectorType, uint _connectorID, bytes32 _eventCode, bytes calldata _eventData) external; 58 | } 59 | 60 | contract DSMath { 61 | 62 | uint256 constant RAY = 10 ** 27; 63 | 64 | function mul(uint x, uint y) internal pure returns (uint z) { 65 | require(y == 0 || (z = x * y) / y == x, "math-not-safe"); 66 | } 67 | 68 | function convertTo18(uint _dec, uint256 _amt) internal pure returns (uint256 amt) { 69 | amt = mul(_amt, 10 ** (18 - _dec)); 70 | } 71 | 72 | function toInt(uint x) internal pure returns (int y) { 73 | y = int(x); 74 | require(y >= 0, "int-overflow"); 75 | } 76 | 77 | function convert18ToDec(uint _dec, uint256 _amt) internal pure returns (uint256 amt) { 78 | amt = (_amt / 10 ** (18 - _dec)); 79 | } 80 | } 81 | 82 | 83 | contract Helpers is DSMath { 84 | /** 85 | * @dev Return ETH Address. 86 | */ 87 | function getAddressETH() internal pure returns (address) { 88 | return 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; 89 | } 90 | 91 | /** 92 | * @dev Return WETH Address. 93 | */ 94 | function getAddressWETH() internal pure returns (address) { 95 | return 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; 96 | } 97 | 98 | /** 99 | * @dev Return InstaEvent Address. 100 | */ 101 | function getEventAddr() internal pure returns (address) { 102 | return 0x2af7ea6Cb911035f3eb1ED895Cb6692C39ecbA97; 103 | } 104 | 105 | /** 106 | * @dev Connector Details 107 | */ 108 | function connectorID() public pure returns(uint _type, uint _id) { 109 | (_type, _id) = (2, 2); 110 | } 111 | 112 | /** 113 | * @dev Return InstaMapping Address. 114 | */ 115 | function getMappingAddr() internal pure returns (address) { 116 | return 0xe81F70Cc7C0D46e12d70efc60607F16bbD617E88; 117 | } 118 | } 119 | 120 | 121 | contract MakerMCDAddresses is Helpers { 122 | /** 123 | * @dev Return Maker MCD Manager Address. 124 | */ 125 | function getMcdManager() internal pure returns (address) { 126 | return 0x5ef30b9986345249bc32d8928B7ee64DE9435E39; 127 | } 128 | 129 | /** 130 | * @dev Return Maker MCD DAI_Join Address. 131 | */ 132 | function getMcdDaiJoin() internal pure returns (address) { 133 | return 0x9759A6Ac90977b93B58547b4A71c78317f391A28; 134 | } 135 | 136 | /** 137 | * @dev Return Maker MCD Pot Address. 138 | */ 139 | function getMcdPot() internal pure returns (address) { 140 | return 0x197E90f9FAD81970bA7976f33CbD77088E5D7cf7; 141 | } 142 | } 143 | 144 | 145 | contract MakerHelpers is MakerMCDAddresses { 146 | /** 147 | * @dev Get Vault's ilk. 148 | */ 149 | function getVaultData(ManagerLike managerContract, uint vault) internal view returns (bytes32 ilk, address urn) { 150 | ilk = managerContract.ilks(vault); 151 | urn = managerContract.urns(vault); 152 | } 153 | 154 | /** 155 | * @dev Gem Join address is ETH type collateral. 156 | */ 157 | function isEth(address tknAddr) internal pure returns (bool) { 158 | return tknAddr == getAddressWETH() ? true : false; 159 | } 160 | } 161 | 162 | 163 | contract BasicResolver is MakerHelpers { 164 | event LogWithdraw(uint256 indexed vault, bytes32 indexed ilk, uint256 tokenAmt); 165 | 166 | 167 | /** 168 | * @dev Withdraw ETH/ERC20_Token Collateral. 169 | * @param vault Vault ID. 170 | * @param amt token amount to withdraw. 171 | */ 172 | function withdraw( 173 | uint vault, 174 | uint amt 175 | ) external payable { 176 | ManagerLike managerContract = ManagerLike(getMcdManager()); 177 | 178 | (bytes32 ilk, address urn) = getVaultData(managerContract, vault); 179 | 180 | address colAddr = InstaMapping(getMappingAddr()).gemJoinMapping(ilk); 181 | TokenJoinInterface tokenJoinContract = TokenJoinInterface(colAddr); 182 | 183 | uint _amt = amt; 184 | uint _amt18; 185 | if (_amt == uint(-1)) { 186 | (_amt18,) = VatLike(managerContract.vat()).urns(ilk, urn); 187 | _amt = convert18ToDec(tokenJoinContract.dec(), _amt18); 188 | } else { 189 | _amt18 = convertTo18(tokenJoinContract.dec(), _amt); 190 | } 191 | 192 | managerContract.frob( 193 | vault, 194 | -toInt(_amt18), 195 | 0 196 | ); 197 | 198 | managerContract.flux( 199 | vault, 200 | address(this), 201 | _amt18 202 | ); 203 | 204 | TokenInterface tokenContract = tokenJoinContract.gem(); 205 | 206 | if (isEth(address(tokenContract))) { 207 | tokenJoinContract.exit(address(this), _amt); 208 | tokenContract.withdraw(_amt); 209 | } else { 210 | tokenJoinContract.exit(address(this), _amt); 211 | } 212 | 213 | emit LogWithdraw(vault, ilk, _amt); 214 | bytes32 _eventCode = keccak256("LogWithdraw(uint256,bytes32,uint256)"); 215 | bytes memory _eventParam = abi.encode(vault, ilk, _amt); 216 | (uint _type, uint _id) = connectorID(); 217 | EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam); 218 | } 219 | 220 | } 221 | 222 | 223 | contract DsrResolver is BasicResolver { 224 | event LogWithdrawDai(uint256 tokenAmt); 225 | 226 | /** 227 | * @dev Withdraw DAI from DSR. 228 | * @param amt DAI amount to withdraw. 229 | */ 230 | function withdrawDai(uint amt) external payable { 231 | address daiJoin = getMcdDaiJoin(); 232 | 233 | DaiJoinInterface daiJoinContract = DaiJoinInterface(daiJoin); 234 | VatLike vat = daiJoinContract.vat(); 235 | PotLike potContract = PotLike(getMcdPot()); 236 | 237 | uint chi = potContract.drip(); 238 | uint pie; 239 | uint _amt = amt; 240 | if (_amt == uint(-1)) { 241 | pie = potContract.pie(address(this)); 242 | _amt = mul(chi, pie) / RAY; 243 | } else { 244 | pie = mul(_amt, RAY) / chi; 245 | } 246 | 247 | potContract.exit(pie); 248 | 249 | uint bal = vat.dai(address(this)); 250 | if (vat.can(address(this), address(daiJoin)) == 0) { 251 | vat.hope(daiJoin); 252 | } 253 | daiJoinContract.exit( 254 | address(this), 255 | bal >= mul(_amt, RAY) ? _amt : bal / RAY 256 | ); 257 | 258 | emit LogWithdrawDai(_amt); 259 | bytes32 _eventCode = keccak256("LogWithdrawDai(uint256)"); 260 | bytes memory _eventParam = abi.encode(_amt); 261 | (uint _type, uint _id) = connectorID(); 262 | EventInterface(getEventAddr()).emitEvent(_type, _id, _eventCode, _eventParam); 263 | } 264 | } 265 | 266 | contract StaticConnectMaker is DsrResolver { 267 | string public constant name = "Static-MakerDao-v1"; 268 | } -------------------------------------------------------------------------------- /contracts/tests/MockCurveGauge.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | pragma experimental ABIEncoderV2; 3 | 4 | import { ConnectCurveGauge } from "../connectors/curve_gauge.sol"; 5 | 6 | contract MockCurveGauge is ConnectCurveGauge{ 7 | address public curveMintorAddr; 8 | address public curveGaugeMappingAddr; 9 | 10 | constructor(address _curveMintorAddr, address _curveGaugeMappingAddr) public { 11 | curveMintorAddr = _curveMintorAddr; 12 | curveGaugeMappingAddr = _curveGaugeMappingAddr; 13 | } 14 | 15 | function emitEvent(bytes32 eventCode, bytes memory eventData) override internal {} 16 | 17 | function getCurveGaugeMappingAddr() override internal view returns (address) { 18 | return curveGaugeMappingAddr; 19 | } 20 | 21 | function getCurveMintorAddr() override internal view returns (address) { 22 | return curveMintorAddr; 23 | } 24 | 25 | function setUint(uint setId, uint val) override internal {} 26 | } 27 | 28 | -------------------------------------------------------------------------------- /contracts/tests/MockCurveGaugeMapping.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | pragma experimental ABIEncoderV2; 3 | 4 | import { CurveGaugeMapping } from "../mapping/curve_gauge_mapping.sol"; 5 | 6 | contract MockCurveGaugeMapping is CurveGaugeMapping { 7 | constructor( 8 | string[] memory gaugeNames, 9 | address[] memory gaugeAddresses, 10 | bool[] memory rewardTokens 11 | ) public CurveGaugeMapping(gaugeNames, gaugeAddresses, rewardTokens) { 12 | } 13 | modifier isChief override {_;} 14 | } 15 | -------------------------------------------------------------------------------- /contracts/tests/MockCurveVesting.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | 3 | import { ConnectCurveVestingProtocol } from "../connectors/curve_vesting.sol"; 4 | 5 | contract MockConnectCurveVestingProtocol is ConnectCurveVestingProtocol{ 6 | address public curveTokenAddr; 7 | address public curveVestingAddr; 8 | 9 | constructor(address _curveVestingAddr, address _curveTokenAddr) public { 10 | curveVestingAddr = _curveVestingAddr; 11 | curveTokenAddr = _curveTokenAddr; 12 | } 13 | 14 | function getCurveTokenAddr() override internal view returns (address) { 15 | return curveTokenAddr; 16 | } 17 | 18 | function getCurveVestingAddr() override internal view returns (address) { 19 | return curveVestingAddr; 20 | } 21 | 22 | function emitEvent(bytes32 eventCode, bytes memory eventData) override internal {} 23 | function setUint(uint setId, uint val) override internal {} 24 | } 25 | -------------------------------------------------------------------------------- /contracts/tests/MockInstaMapping.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | 3 | import { InstaStakingMapping } from "../mapping/staking.sol"; 4 | 5 | contract MockInstaMapping is InstaStakingMapping { 6 | modifier isChief override {_;} 7 | } 8 | -------------------------------------------------------------------------------- /contracts/tests/MockStaking.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | pragma experimental ABIEncoderV2; 3 | 4 | import { ConnectStaking } from "../connectors/staking.sol"; 5 | 6 | contract MockSynthetixStaking is ConnectStaking{ 7 | address public synthetixStakingAddr; 8 | address public instaMappingAddr; 9 | 10 | constructor(address _synthetixStakingAddr, address _instaMappingAddr) public { 11 | synthetixStakingAddr = _synthetixStakingAddr; 12 | instaMappingAddr = _instaMappingAddr; 13 | } 14 | 15 | function emitEvent(bytes32 eventCode, bytes memory eventData) override internal {} 16 | 17 | function getMappingAddr() override internal view returns (address) { 18 | return instaMappingAddr; 19 | } 20 | 21 | function setUint(uint setId, uint val) override internal {} 22 | } 23 | -------------------------------------------------------------------------------- /contracts/tests/mockOneProto.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.6.0; 2 | pragma experimental ABIEncoderV2; 3 | 4 | import { ConnectOne } from "../connectors/1inch.sol"; 5 | 6 | contract MockConnectOne is ConnectOne { 7 | address public oneProtoAddr; 8 | 9 | constructor(address _oneProtoAddr) public { 10 | oneProtoAddr = _oneProtoAddr; 11 | } 12 | 13 | function emitEvent(bytes32 eventCode, bytes memory eventData) override internal {} 14 | 15 | function setUint(uint setId, uint val) override internal {} 16 | 17 | function sub(uint x, uint y) internal override pure returns (uint z) { 18 | z = 21 * 10 ** 18; 19 | } 20 | 21 | function getOneProtoAddress() internal override view returns (address payable) { 22 | return payable(oneProtoAddr); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /migrations/1_initial_migration.js: -------------------------------------------------------------------------------- 1 | const Migrations = artifacts.require("Migrations"); 2 | 3 | module.exports = function(deployer) { 4 | deployer.deploy(Migrations); 5 | }; 6 | -------------------------------------------------------------------------------- /migrations/2_deploy_connector.js: -------------------------------------------------------------------------------- 1 | // const CurveProtocol = artifacts.require("CurveProtocol"); 2 | // const ConnectSBTCCurve = artifacts.require("ConnectSBTCCurve"); 3 | // const MockContract = artifacts.require("MockContract"); 4 | // const MockSynthetixStaking = artifacts.require("MockSynthetixStaking"); 5 | // const ConnectSynthetixStaking = artifacts.require("ConnectSynthetixStaking"); 6 | 7 | // const connectorsABI = require("../test/abi/connectors.json"); 8 | // let connectorsAddr = "0xD6A602C01a023B98Ecfb29Df02FBA380d3B21E0c"; 9 | // let connectorInstance = new web3.eth.Contract(connectorsABI, connectorsAddr); 10 | 11 | module.exports = async function(deployer) { 12 | // deployer.deploy(CurveProtocol); 13 | // let connectorLength = await connectorInstance.methods.connectorLength().call(); 14 | // deployer.deploy(MockContract).then(function () { 15 | // // return deployer.deploy(MockSynthetixStaking, MockContract.address, 1, +connectorLength + 1); 16 | // // return deployer.deploy(ConnectSynthetixStaking, MockContract.address); 17 | // return deployer.deploy(MockSynthetixStaking, MockContract.address); 18 | // }); 19 | 20 | }; 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dsa-connectors", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "truffle-config.js", 6 | "directories": {}, 7 | "scripts": { 8 | "test": "truffle test", 9 | "coverage": "./node_modules/.bin/solidity-coverage", 10 | "solium": "solium -d contracts/", 11 | "build-contracts": "sol-merger \"./contracts/connectors/mock.sol\" ./contracts/build", 12 | "ganache": "ganache-cli" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "git+https://github.com/InstaDApp/dsa-connectors.git" 17 | }, 18 | "author": "InstaDApp", 19 | "license": "MIT", 20 | "bugs": { 21 | "url": "https://github.com/InstaDApp/dsa-connectors/issues" 22 | }, 23 | "homepage": "https://github.com/InstaDApp/dsa-connectors#readme", 24 | "dependencies": { 25 | "@openzeppelin/contracts": "^3.0.1", 26 | "@openzeppelin/upgrades": "^2.8.0", 27 | "@truffle/artifactor": "^4.0.45", 28 | "chalk": "^4.0.0", 29 | "dotenv": "^7.0.0", 30 | "ethereumjs-abi": "^0.6.8", 31 | "minimist": "^1.2.5", 32 | "solc": "^0.6.0", 33 | "truffle-assertions": "^0.9.2", 34 | "truffle-hdwallet-provider": "^1.0.17", 35 | "truffle-plugin-verify": "^0.3.10", 36 | "truffle-verify": "^1.0.8" 37 | }, 38 | "devDependencies": { 39 | "@nomiclabs/buidler": "^1.3.8", 40 | "@nomiclabs/buidler-truffle5": "^1.3.4", 41 | "@nomiclabs/buidler-web3": "^1.3.4", 42 | "@openzeppelin/test-helpers": "^0.5.6", 43 | "@studydefi/money-legos": "^2.3.7", 44 | "ganache-cli": "^6.10.0-beta.2", 45 | "sol-merger": "^2.0.1", 46 | "solidity-coverage": "0.5.11", 47 | "solium": "1.2.3", 48 | "web3": "^1.2.9" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /tenderly.yaml: -------------------------------------------------------------------------------- 1 | account_id: "" 2 | exports: 3 | ganache: 4 | project_slug: dsa 5 | rpc_address: 127.0.0.1:8545 6 | protocol: "" 7 | forked_network: Mainnet 8 | chain_config: 9 | homestead_block: 0 10 | eip150_block: 0 11 | eip150_hash: "0x0000000000000000000000000000000000000000000000000000000000000000" 12 | eip155_block: 0 13 | eip158_block: 0 14 | byzantium_block: 0 15 | constantinople_block: 0 16 | petersburg_block: 0 17 | istanbul_block: 0 18 | project_slug: "" 19 | -------------------------------------------------------------------------------- /test/CurveGauge.js: -------------------------------------------------------------------------------- 1 | const { 2 | BN, // Big Number support 3 | expectEvent, // Assertions for emitted events 4 | expectRevert, // Assertions for transactions that should fail 5 | balance, 6 | ether 7 | } = require('@openzeppelin/test-helpers'); 8 | 9 | const MockContract = artifacts.require("MockContract"); 10 | const MockCurveGauge = artifacts.require('MockCurveGauge'); 11 | const MockCurveGaugeMapping = artifacts.require('MockCurveGaugeMapping'); 12 | const erc20ABI = require("./abi/erc20.js"); 13 | const gaugeABI = require("./abi/curveGauge.json"); 14 | 15 | contract("ConnectCurveGauge", async accounts => { 16 | const [sender, receiver] = accounts; 17 | let mock, mockCurveGauge, mockCurveGaugeMapping; 18 | 19 | before(async function () { 20 | mock = await MockContract.new(); 21 | let names = ["compound", "susd"] 22 | let poolAddress = [mock.address, mock.address] 23 | let rewardArr = [false, true] 24 | mockCurveGaugeMapping = await MockCurveGaugeMapping.new(names, poolAddress, rewardArr); 25 | mockCurveGauge = await MockCurveGauge.new(mock.address, mockCurveGaugeMapping.address); 26 | // lp_token = new web3.eth.Contract(erc20ABI, mock.address); 27 | curveGauge = new web3.eth.Contract(gaugeABI, mock.address) 28 | // mocking lp_token 29 | let lp_token = await curveGauge.methods.lp_token().encodeABI(); 30 | await mock.givenMethodReturnAddress(lp_token, mock.address); 31 | // mocking crv_token 32 | let crv_token = await curveGauge.methods.crv_token().encodeABI(); 33 | await mock.givenMethodReturnAddress(crv_token, mock.address); 34 | // mocking rewarded_token 35 | let rewarded_token = await curveGauge.methods.rewarded_token().encodeABI(); 36 | await mock.givenMethodReturnAddress(rewarded_token, mock.address); 37 | 38 | // await mockCurveGaugeMapping.addGaugeMapping('compound', mock.address, false); 39 | // await mockCurveGaugeMapping.addGaugeMapping('susd', mock.address, true); 40 | }) 41 | 42 | it('can deposit into compound gauge', async function() { 43 | const tx = await mockCurveGauge.deposit( 44 | "compound", 45 | 10000000, 46 | 0, 47 | 0 48 | ) 49 | expectEvent(tx, "LogDeposit", { 50 | amount: "10000000", 51 | getId: "0", 52 | setId: "0" 53 | }); 54 | }); 55 | 56 | it('can claim reward from compound gauge', async function() { 57 | const tx = await mockCurveGauge.claimReward( 58 | "compound", 59 | 0, 60 | 0 61 | ) 62 | expectEvent(tx, "LogClaimedReward"); 63 | }); 64 | 65 | it('can withdraw from compound gauge', async function() { 66 | const tx = await mockCurveGauge.withdraw( 67 | "compound", 68 | 10000000, 69 | 0, 70 | 0, 71 | 0, 72 | 0 73 | ) 74 | expectEvent(tx, "LogClaimedReward"); 75 | expectEvent(tx, "LogWithdraw", { 76 | amount: "10000000", 77 | getId: "0", 78 | setId: "0" 79 | }); 80 | }); 81 | 82 | it('can deposit into susd gauge', async function() { 83 | const tx = await mockCurveGauge.deposit( 84 | "susd", 85 | 10000000, 86 | 0, 87 | 0 88 | ) 89 | expectEvent(tx, "LogDeposit", { 90 | amount: "10000000", 91 | getId: "0", 92 | setId: "0" 93 | }); 94 | }); 95 | 96 | it('can claim reward from susd gauge', async function() { 97 | const tx = await mockCurveGauge.claimReward( 98 | "susd", 99 | 0, 100 | 0 101 | ) 102 | expectEvent(tx, "LogClaimedReward"); 103 | }); 104 | 105 | it('can withdraw from susd gauge', async function() { 106 | const tx = await mockCurveGauge.withdraw( 107 | "susd", 108 | 10000000, 109 | 0, 110 | 0, 111 | 0, 112 | 0 113 | ) 114 | expectEvent(tx, "LogClaimedReward"); 115 | expectEvent(tx, "LogWithdraw", { 116 | amount: "10000000", 117 | getId: "0", 118 | setId: "0" 119 | }); 120 | }); 121 | 122 | it('cannot deposit into unknown gauge', async function() { 123 | const tx = mockCurveGauge.deposit( 124 | "unknown", 125 | 10000000, 126 | 0, 127 | 0 128 | ) 129 | await expectRevert(tx, "wrong-gauge-pool-name") 130 | }); 131 | 132 | it('cannot claim reward from unknown gauge', async function() { 133 | const tx = mockCurveGauge.claimReward( 134 | "unknown", 135 | 0, 136 | 0 137 | ) 138 | await expectRevert(tx, "wrong-gauge-pool-name") 139 | }); 140 | 141 | it('cannot withdraw from unknown gauge', async function() { 142 | const tx = mockCurveGauge.withdraw( 143 | "unknown", 144 | 10000000, 145 | 0, 146 | 0, 147 | 0, 148 | 0 149 | ) 150 | await expectRevert(tx, "wrong-gauge-pool-name") 151 | }); 152 | 153 | it('can add multiple gauge mappings', async function() { 154 | const tx = await mockCurveGaugeMapping.addGaugeMappings(['sbtc'], [mock.address], [true]); 155 | expectEvent(tx, "LogAddGaugeMapping"); 156 | }); 157 | }) 158 | -------------------------------------------------------------------------------- /test/CurveProtocol.js: -------------------------------------------------------------------------------- 1 | const CurveProtocol = artifacts.require('CurveProtocol') 2 | const daiABI = require('./abi/dai'); 3 | const erc20 = require('./abi/erc20') 4 | const swap_abi = require('./abi/swap') 5 | const { ether, balance } = require('@openzeppelin/test-helpers'); 6 | const uniswap = require("@studydefi/money-legos/uniswap"); 7 | 8 | const BN = require('bn.js') 9 | 10 | const chai = require('chai') 11 | const expect = chai.expect 12 | chai.use(require('chai-bn')(BN)); 13 | 14 | // userAddress must be unlocked using --unlock ADDRESS 15 | const userAddress = '0xfcd22438ad6ed564a1c26151df73f6b33b817b56'; 16 | const daiAddress = '0x6b175474e89094c44da98b954eedeac495271d0f'; 17 | const daiContract = new web3.eth.Contract(daiABI, daiAddress); 18 | 19 | const usdcAddress = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' 20 | const usdcContract = new web3.eth.Contract(erc20, usdcAddress); 21 | 22 | const swap = '0xA5407eAE9Ba41422680e2e00537571bcC53efBfD' 23 | const swapContract = new web3.eth.Contract(swap_abi, swap) 24 | 25 | const swapToken = '0xC25a3A3b969415c80451098fa907EC722572917F' 26 | const tokenContract = new web3.eth.Contract(erc20, swapToken) 27 | 28 | contract('Curve Protocol', async accounts => { 29 | let account, contract; 30 | 31 | beforeEach(async function() { 32 | account = accounts[0] 33 | contract = await CurveProtocol.deployed() 34 | 35 | let uniswapFactory = new web3.eth.Contract( 36 | uniswap.factory.abi, 37 | uniswap.factory.address 38 | ); 39 | 40 | const daiExchangeAddress = await uniswapFactory.methods.getExchange( 41 | daiAddress, 42 | ).call(); 43 | 44 | const daiExchange = new web3.eth.Contract( 45 | uniswap.exchange.abi, 46 | daiExchangeAddress 47 | ); 48 | 49 | const daiBefore = await daiContract.methods.balanceOf(userAddress).call(); 50 | 51 | await daiExchange.methods.ethToTokenSwapInput( 52 | 1, // min amount of token retrieved 53 | 2525644800, // random timestamp in the future (year 2050) 54 | ).send( 55 | { 56 | gas: 4000000, 57 | value: ether("5"), 58 | from: userAddress 59 | } 60 | ); 61 | 62 | let daiAfter = await daiContract.methods.balanceOf(userAddress).call(); 63 | 64 | expect(daiAfter - daiBefore).to.be.at.least(+ether("1000")); 65 | }); 66 | 67 | it('should send ether to the user address', async () => { 68 | const ethBalanceBefore = await balance.current(userAddress); 69 | // Send 0.1 eth to userAddress to have gas to send an ERC20 tx. 70 | await web3.eth.sendTransaction({ 71 | from: accounts[0], 72 | to: userAddress, 73 | value: ether('0.1') 74 | }); 75 | const ethBalanceAfter = await balance.current(userAddress); 76 | expect(+ethBalanceAfter - +ethBalanceBefore).to.equal(+ether('0.1')) 77 | }); 78 | 79 | it('should transfer DAI to CurveProtocol', async () => { 80 | // Get 100 DAI for first 5 accounts 81 | // daiAddress is passed to ganache-cli with flag `--unlock` 82 | // so we can use the `transfer` method 83 | // 84 | // Note: This only works as userAddress has 2546221640728945323079640 Dai, 85 | // should remove this dependence in the future 86 | const daiBalanceUser = await daiContract.methods.balanceOf(userAddress).call(); 87 | await daiContract.methods 88 | .transfer(contract.address, ether('100').toString()) 89 | .send({ from: userAddress, gasLimit: 800000 }); 90 | const daiBalance = await daiContract.methods.balanceOf(contract.address).call(); 91 | expect(+daiBalance).to.be.at.least(+ether('100')) 92 | }); 93 | 94 | it('should approve DAI to CurveProtocol', async() => { 95 | await daiContract.methods 96 | .approve(contract.address, ether('100').toString()) 97 | .send({ from: account, gasLimit: 800000 }); 98 | const daiAllowance = await daiContract.methods.allowance(account, contract.address).call() 99 | expect(+daiAllowance).to.be.at.least(+ether('100')) 100 | }); 101 | 102 | /* Deprecated as CurveProtocol is not ICurve and exchange has been implemented into sell method 103 | it('should exchange', async () => { 104 | let account = accounts[0] 105 | let contract = await CurveProtocol.deployed() 106 | 107 | // Get 100 DAI for first 5 accounts 108 | console.log('before'); 109 | let get_dy = await contract.get_dy.call(0, 1, ether('1').toString()) 110 | console.log('after'); 111 | let min_dy = +get_dy * 0.99 112 | let receipt = await contract.exchange(0, 1, ether('1').toString(), 1, { from: account }) 113 | let buyAmount = receipt.logs[0].args.buyAmount.toString() 114 | expect(+buyAmount).to.be.at.least(min_dy); 115 | }); 116 | */ 117 | 118 | /* Deprecated as CurveProtocol is not ICurve and calc_token_amount has been implemented into withdraw method 119 | it('should add liquidity', async () => { 120 | let account = accounts[0] 121 | let contract = await CurveProtocol.deployed() 122 | 123 | let amounts = [ether('1').toString(), 0, 0, 0] 124 | let token_amount = await contract.calc_token_amount.call(amounts, true) 125 | 126 | let receipt = await contract.add_liquidity(amounts, 1, { from: account }) 127 | let mintAmount = receipt.logs[0].args.mintAmount.toString() 128 | expect(+mintAmount).to.be.at.least(+mintAmount) 129 | }) 130 | 131 | it('should remove liquidity imbalance', async () => { 132 | let account = accounts[0] 133 | let contract = await CurveProtocol.deployed() 134 | 135 | let tokenBalance = await tokenContract.methods.balanceOf(contract.address).call() 136 | let receipt = await contract.remove_liquidity_imbalance(["100000000000", 0, 0, 0], { from: account }) 137 | let burnAmount = receipt.logs[0].args.burnAmount.toString() 138 | let tokenBalanceAfter = await tokenContract.methods.balanceOf(contract.address).call() 139 | 140 | //weird Ganache errors sometimes "cannot decode event" 141 | console.log(+tokenBalance, +tokenBalanceAfter, +burnAmount) 142 | //expect(BN(tokenBalance)).to.be.a.bignumber.equal(BN(tokenBalanceAfter).add(burnAmount)) 143 | 144 | }) 145 | 146 | it('should remove liquidity in one coin', async() => { 147 | let account = accounts[0] 148 | let contract = await CurveProtocol.deployed() 149 | 150 | let daiBalance = await daiContract.methods.balanceOf(contract.address).call() 151 | let receipt = await contract.remove_liquidity_one_coin("100000000000", 0, 1, { from: account }) 152 | let withdrawnAmount = receipt.logs[0].args.withdrawnAmount.toString() 153 | let daiBalanceAfter = await daiContract.methods.balanceOf(contract.address).call() 154 | 155 | //weird Ganache errors sometimes "cannot decode event" 156 | console.log(+daiBalance, +daiBalanceAfter, +withdrawnAmount) 157 | //expect(BN(daiBalance)).to.be.a.bignumber.equal(BN(daiBalanceAfter).sub(withdrawnAmount)); 158 | }) 159 | */ 160 | }); 161 | -------------------------------------------------------------------------------- /test/CurveSBTCProtocol.js: -------------------------------------------------------------------------------- 1 | const { 2 | BN, // Big Number support 3 | expectEvent, // Assertions for emitted events 4 | expectRevert, // Assertions for transactions that should fail 5 | balance, 6 | ether 7 | } = require('@openzeppelin/test-helpers'); 8 | 9 | const ConnectSBTCCurve = artifacts.require('ConnectSBTCCurve'); 10 | const erc20 = require("@studydefi/money-legos/erc20"); 11 | const uniswap = require("@studydefi/money-legos/uniswap"); 12 | const sbtcABI = require("./abi/sbtc.json"); 13 | const erc20ABI = require("./abi/erc20.js"); 14 | const connectorsABI = require("./abi/connectors.json"); 15 | const accountABI = require("./abi/account.json"); 16 | const curveSwap = require("./abi/curveSwap.json"); 17 | 18 | contract('ConnectSBTCCurve', async accounts => { 19 | const [sender, receiver] = accounts; 20 | let masterAddress = "0xfcd22438ad6ed564a1c26151df73f6b33b817b56"; 21 | let accountID = 7; 22 | let dsrAddr = "0xEEB007bea2Bbb0cA6502217E8867f8f7b021B8D5"; 23 | 24 | let connectorsAddr = "0xD6A602C01a023B98Ecfb29Df02FBA380d3B21E0c"; 25 | let connectorInstance = new web3.eth.Contract(connectorsABI, connectorsAddr); 26 | 27 | // let accountAddr = "0x939Daad09fC4A9B8f8A9352A485DAb2df4F4B3F8"; 28 | let accountInstance = new web3.eth.Contract(accountABI, dsrAddr); 29 | let connectSBTCCurve; 30 | let wbtcContract = new web3.eth.Contract(erc20.wbtc.abi, erc20.wbtc.address); 31 | 32 | before(async function () { 33 | connectSBTCCurve = await ConnectSBTCCurve.deployed(); 34 | 35 | let uniswapFactory = new web3.eth.Contract( 36 | uniswap.factory.abi, 37 | uniswap.factory.address 38 | ); 39 | 40 | const wbtcExchangeAddress = await uniswapFactory.methods.getExchange( 41 | erc20.wbtc.address, 42 | ).call(); 43 | 44 | const wbtcExchange = new web3.eth.Contract( 45 | uniswap.exchange.abi, 46 | wbtcExchangeAddress 47 | ); 48 | 49 | const wbtcBefore = await wbtcContract.methods.balanceOf(sender).call(); 50 | console.log("Sender WBTC Before: ", wbtcBefore.toString()); 51 | 52 | const balanceBefore = await web3.eth.getBalance(sender); 53 | console.log("Sender Balance Before: ", balanceBefore.toString()); 54 | 55 | await wbtcExchange.methods.ethToTokenSwapInput( 56 | 1, // min amount of token retrieved 57 | 2525644800, // random timestamp in the future (year 2050) 58 | ).send( 59 | { 60 | gas: 4000000, 61 | value: ether("10"), 62 | from: sender 63 | } 64 | ); 65 | 66 | let wbtcAfter = await wbtcContract.methods.balanceOf(sender).call(); 67 | console.log("Sender WBTC After: ", wbtcAfter.toString()); 68 | const balanceAfter = await web3.eth.getBalance(sender); 69 | console.log("Sender Balance After: ", balanceAfter.toString()); 70 | 71 | expect(wbtcAfter - wbtcBefore).to.be.at.least(10000000); 72 | 73 | // send WBTC to master 74 | await wbtcContract.methods.transfer(dsrAddr, 10000000).send({from: sender}); 75 | // send WBTC to connector 76 | // await wbtcContract.methods.transfer(connectSBTCCurve.address, 10000000).send({from: sender}); 77 | 78 | // Send ETH to master 79 | await web3.eth.sendTransaction({from: sender, to: masterAddress, value: ether("5")}); 80 | 81 | // Enable the the given connector address 82 | await connectorInstance.methods.enable(connectSBTCCurve.address).send({from: masterAddress}); 83 | // check if the give connector address is enabled. 84 | let isEnabled = await connectorInstance.methods.connectors(connectSBTCCurve.address).call(); 85 | assert.ok(isEnabled); 86 | }); 87 | 88 | it('can sell WBTC for SBTC', async function () { 89 | const sbtcContract = new web3.eth.Contract(sbtcABI, "0xfe18be6b3bd88a2d2a7f928d00292e7a9963cfc6"); 90 | 91 | const sbtcBefore = await sbtcContract.methods.balanceOf(dsrAddr).call(); 92 | console.log("Master SBTC Before: ", sbtcBefore.toString()); 93 | let wbtcBefore = await wbtcContract.methods.balanceOf(dsrAddr).call(); 94 | console.log("Master WBTC Before: ", wbtcBefore.toString()); 95 | 96 | const encoded = await connectSBTCCurve.contract.methods.sell( 97 | "0xfe18be6b3bd88a2d2a7f928d00292e7a9963cfc6", 98 | erc20.wbtc.address, 99 | 10000000, 100 | ( 0.09 / 0.1 * 1e18 ).toString(), 101 | 0, 102 | 0, 103 | ).encodeABI(); 104 | 105 | await wbtcContract.methods.approve("0x7fC77b5c7614E1533320Ea6DDc2Eb61fa00A9714", 10000000).send({from: masterAddress}); 106 | const curveSwapContract = new web3.eth.Contract(curveSwap, "0x7fC77b5c7614E1533320Ea6DDc2Eb61fa00A9714"); 107 | const tx = await curveSwapContract.methods.exchange(1, 2, 1000000, 1).send({ from: masterAddress }); 108 | console.log(tx); 109 | 110 | // const tx = await connectSBTCCurve.contract.methods.sell( 111 | // "0xfe18be6b3bd88a2d2a7f928d00292e7a9963cfc6", 112 | // erc20.wbtc.address, 113 | // 1000000, 114 | // 1, 115 | // 0, 116 | // 0, 117 | // ).send({from: masterAddress}); 118 | // console.log(tx); 119 | 120 | //Inputs for `cast()` function of DSA Account. 121 | const castInputs = [ 122 | [connectSBTCCurve.address], 123 | [encoded], 124 | masterAddress 125 | ] 126 | 127 | // Execute `cast()` function 128 | // const tx = await accountInstance.methods.cast(...castInputs).send({from: masterAddress}); 129 | // console.log(tx); 130 | 131 | let wbtcAfter = await wbtcContract.methods.balanceOf(dsrAddr).call(); 132 | console.log("Master WBTC After: ", wbtcAfter.toString()); 133 | const sbtcAfter = await sbtcContract.methods.balanceOf(dsrAddr).call(); 134 | console.log("Master SBTC After: ", sbtcAfter.toString()); 135 | expect(sbtcAfter - sbtcBefore).to.be.at.least(+ether("0.09")); 136 | }); 137 | 138 | it('can add and remove liquidity for wbtc', async function() { 139 | const curveTokenContract = new web3.eth.Contract( 140 | erc20ABI, 141 | "0x075b1bb99792c9e1041ba13afef80c91a1e70fb3" 142 | ) 143 | 144 | let wbtcBefore = await wbtcContract.methods.balanceOf(dsrAddr).call(); 145 | console.log("Master WBTC Before: ", wbtcBefore.toString()); 146 | 147 | const encodedDeposit = await connectSBTCCurve.contract.methods.deposit( 148 | erc20.wbtc.address, 149 | 10000000, 150 | ( 0.09 / 0.1 * 1e18 ).toString(), 151 | 0, 152 | 0 153 | ).encodeABI(); 154 | 155 | //Inputs for `cast()` function of DSA Account. 156 | const castInputsDeposit = [ 157 | [connectSBTCCurve.address], 158 | [encodedDeposit], 159 | masterAddress 160 | ] 161 | 162 | // Execute `cast()` function 163 | const txDeposit = await accountInstance.methods.cast(...castInputsDeposit).send({from: masterAddress}); 164 | console.log(txDeposit); 165 | 166 | const balanceDeposit = await curveTokenContract.methods.balanceOf(dsrAddr); 167 | 168 | expect(balanceDeposit).to.be.at.least(ether("0.09")); 169 | 170 | const encodedWithdraw = await connectSBTCCurve.contract.methods.withdraw( 171 | erc20.wbtc.address, 172 | 10000000, 173 | ( 0.09 / 0.1 * 1e18 ).toString(), 174 | 0, 175 | 0 176 | ).encodeABI(); 177 | 178 | //Inputs for `cast()` function of DSA Account. 179 | const castInputsWithdraw = [ 180 | [connectSBTCCurve.address], 181 | [encodedWithdraw], 182 | masterAddress 183 | ] 184 | 185 | // Execute `cast()` function 186 | const txWithdraw = await accountInstance.methods.cast(...castInputsWithdraw).send({from: masterAddress}); 187 | console.log(txWithdraw); 188 | 189 | const balanceWithdraw = await curveTokenContract.methods.balanceOf(dsrAddr); 190 | 191 | expect(balanceWithdraw).to.equal(0); 192 | }); 193 | 194 | }); 195 | -------------------------------------------------------------------------------- /test/CurveVestingProtocol.js: -------------------------------------------------------------------------------- 1 | const { 2 | BN, // Big Number support 3 | expectEvent, // Assertions for emitted events 4 | expectRevert, // Assertions for transactions that should fail 5 | balance, 6 | ether 7 | } = require('@openzeppelin/test-helpers'); 8 | 9 | const MockContract = artifacts.require("MockContract"); 10 | const MockConnectCurveVestingProtocol = artifacts.require('MockConnectCurveVestingProtocol'); 11 | const erc20ABI = require("./abi/erc20.js"); 12 | const curveVestingABI = require("./abi/curveVesting.json"); 13 | 14 | contract("ConnectCurveVestingProtocol", async accounts => { 15 | const [sender, receiver] = accounts; 16 | let mock, token, curveVesting; 17 | 18 | before(async function(){ 19 | mock = await MockContract.new(); 20 | mockConnectCurveVestingProtocol = await MockConnectCurveVestingProtocol.new(mock.address, mock.address) 21 | token = new web3.eth.Contract(erc20ABI, mock.address); 22 | curveVesting = new web3.eth.Contract(curveVestingABI, mock.address); 23 | 24 | // mocking balanceOf 25 | let balanceOf = await token.methods.balanceOf(mockConnectCurveVestingProtocol.address).encodeABI(); 26 | await mock.givenMethodReturnUint(balanceOf, 10000000); 27 | }) 28 | 29 | it('can claim CRV', async function() { 30 | const tx = await mockConnectCurveVestingProtocol.claim( 31 | 0, 32 | 0 33 | ) 34 | expectEvent(tx, "LogClaim"); 35 | }); 36 | }) 37 | -------------------------------------------------------------------------------- /test/SynthetixProtocol.js: -------------------------------------------------------------------------------- 1 | const { 2 | BN, // Big Number support 3 | expectEvent, // Assertions for emitted events 4 | expectRevert, // Assertions for transactions that should fail 5 | balance, 6 | ether 7 | } = require('@openzeppelin/test-helpers'); 8 | 9 | const MockContract = artifacts.require("MockContract"); 10 | const MockSynthetixStaking = artifacts.require('MockSynthetixStaking'); 11 | const MockInstaMapping = artifacts.require('MockInstaMapping'); 12 | const erc20ABI = require("./abi/erc20.js"); 13 | const synthetixStaking = require("./abi/synthetixStaking.json"); 14 | 15 | contract('ConnectSynthetixStaking', async accounts => { 16 | const [sender, receiver] = accounts; 17 | let mock, mockSynthetixStaking, stakingContract, token; 18 | let instaMapping; 19 | 20 | before(async function () { 21 | mock = await MockContract.new(); 22 | mockInstaMapping = await MockInstaMapping.new(); 23 | mockSynthetixStaking = await MockSynthetixStaking.new(mock.address, mockInstaMapping.address); 24 | stakingContract = new web3.eth.Contract(synthetixStaking, mock.address); 25 | token = new web3.eth.Contract(erc20ABI, mock.address); 26 | mockInstaMapping.addStakingMapping('snx', mock.address, mock.address); 27 | 28 | // mocking balanceOf 29 | let balanceOf = await token.methods.balanceOf(mockSynthetixStaking.address).encodeABI(); 30 | await mock.givenMethodReturnUint(balanceOf, 10000000); 31 | 32 | // mocking approve 33 | let approve = await token.methods.approve(mockSynthetixStaking.address, 10000000).encodeABI(); 34 | await mock.givenMethodReturnBool(approve, "true"); 35 | 36 | }) 37 | 38 | it('can deposit', async function() { 39 | // mocking stake 40 | let stake = await stakingContract.methods.stake(10000000).encodeABI(); 41 | await mock.givenMethodReturnBool(stake, "true"); 42 | 43 | const tx = await mockSynthetixStaking.deposit( 44 | "snx", 45 | 10000000, 46 | 0, 47 | 0 48 | ) 49 | expectEvent(tx, "LogDeposit"); 50 | }); 51 | 52 | it('can withdraw', async function() { 53 | // mocking withdraw 54 | let withdraw = await stakingContract.methods.withdraw(10000000).encodeABI(); 55 | await mock.givenMethodReturnBool(withdraw, "true"); 56 | // mocking getReward 57 | let reward = await stakingContract.methods.getReward().encodeABI(); 58 | await mock.givenMethodReturnBool(reward, "true"); 59 | 60 | const tx = await mockSynthetixStaking.withdraw( 61 | "snx", 62 | 10000000, 63 | 0, 64 | 111, 65 | 112 66 | ) 67 | expectEvent(tx, "LogWithdraw"); 68 | expectEvent(tx, "LogClaimedReward"); 69 | }); 70 | 71 | it('can claim reward', async function() { 72 | // mocking getReward 73 | let reward = await stakingContract.methods.getReward().encodeABI(); 74 | await mock.givenMethodReturnBool(reward, "true"); 75 | const tx = await mockSynthetixStaking.claimReward( 76 | "snx", 77 | 112 78 | ) 79 | expectEvent(tx, "LogClaimedReward"); 80 | }); 81 | 82 | it('cannot deposit if pool removed', async function() { 83 | mockInstaMapping.removeStakingMapping('snx', mock.address); 84 | // mocking stake 85 | let stake = await stakingContract.methods.stake(10000000).encodeABI(); 86 | await mock.givenMethodReturnBool(stake, "true"); 87 | 88 | const tx = mockSynthetixStaking.deposit( 89 | "snx", 90 | 10000000, 91 | 0, 92 | 0 93 | ) 94 | expectRevert(tx, "Wrong Staking Name"); 95 | }); 96 | 97 | }) 98 | -------------------------------------------------------------------------------- /test/abi/1proto.json: -------------------------------------------------------------------------------- 1 | [{"inputs":[{"internalType":"contract IOneSplitMulti","name":"impl","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"newImpl","type":"address"}],"name":"ImplementationUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IERC20","name":"fromToken","type":"address"},{"indexed":true,"internalType":"contract IERC20","name":"destToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"fromTokenAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"destTokenAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"minReturn","type":"uint256"},{"indexed":false,"internalType":"uint256[]","name":"distribution","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"flags","type":"uint256[]"},{"indexed":false,"internalType":"address","name":"referral","type":"address"},{"indexed":false,"internalType":"uint256","name":"feePercent","type":"uint256"}],"name":"Swapped","type":"event"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"constant":true,"inputs":[],"name":"chi","outputs":[{"internalType":"contract IFreeFromUpTo","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"contract IERC20","name":"asset","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"claimAsset","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"contract IERC20","name":"fromToken","type":"address"},{"internalType":"contract IERC20","name":"destToken","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"parts","type":"uint256"},{"internalType":"uint256","name":"flags","type":"uint256"}],"name":"getExpectedReturn","outputs":[{"internalType":"uint256","name":"returnAmount","type":"uint256"},{"internalType":"uint256[]","name":"distribution","type":"uint256[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"contract IERC20","name":"fromToken","type":"address"},{"internalType":"contract IERC20","name":"destToken","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"parts","type":"uint256"},{"internalType":"uint256","name":"flags","type":"uint256"},{"internalType":"uint256","name":"destTokenEthPriceTimesGasPrice","type":"uint256"}],"name":"getExpectedReturnWithGas","outputs":[{"internalType":"uint256","name":"returnAmount","type":"uint256"},{"internalType":"uint256","name":"estimateGasAmount","type":"uint256"},{"internalType":"uint256[]","name":"distribution","type":"uint256[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"contract IERC20[]","name":"tokens","type":"address[]"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256[]","name":"parts","type":"uint256[]"},{"internalType":"uint256[]","name":"flags","type":"uint256[]"},{"internalType":"uint256[]","name":"destTokenEthPriceTimesGasPrices","type":"uint256[]"}],"name":"getExpectedReturnWithGasMulti","outputs":[{"internalType":"uint256[]","name":"returnAmounts","type":"uint256[]"},{"internalType":"uint256","name":"estimateGasAmount","type":"uint256"},{"internalType":"uint256[]","name":"distribution","type":"uint256[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isOwner","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"oneSplitImpl","outputs":[{"internalType":"contract IOneSplitMulti","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"renounceOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract IOneSplitMulti","name":"impl","type":"address"}],"name":"setNewImpl","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract IERC20","name":"fromToken","type":"address"},{"internalType":"contract IERC20","name":"destToken","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minReturn","type":"uint256"},{"internalType":"uint256[]","name":"distribution","type":"uint256[]"},{"internalType":"uint256","name":"flags","type":"uint256"}],"name":"swap","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract IERC20[]","name":"tokens","type":"address[]"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minReturn","type":"uint256"},{"internalType":"uint256[]","name":"distribution","type":"uint256[]"},{"internalType":"uint256[]","name":"flags","type":"uint256[]"}],"name":"swapMulti","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract IERC20","name":"fromToken","type":"address"},{"internalType":"contract IERC20","name":"destToken","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minReturn","type":"uint256"},{"internalType":"uint256[]","name":"distribution","type":"uint256[]"},{"internalType":"uint256","name":"flags","type":"uint256"},{"internalType":"address","name":"referral","type":"address"},{"internalType":"uint256","name":"feePercent","type":"uint256"}],"name":"swapWithReferral","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"internalType":"contract IERC20[]","name":"tokens","type":"address[]"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"minReturn","type":"uint256"},{"internalType":"uint256[]","name":"distribution","type":"uint256[]"},{"internalType":"uint256[]","name":"flags","type":"uint256[]"},{"internalType":"address","name":"referral","type":"address"},{"internalType":"uint256","name":"feePercent","type":"uint256"}],"name":"swapWithReferralMulti","outputs":[{"internalType":"uint256","name":"returnAmount","type":"uint256"}],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}] -------------------------------------------------------------------------------- /test/abi/account.json: -------------------------------------------------------------------------------- 1 | [{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"origin","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"LogCast","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"}],"name":"LogDisable","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"}],"name":"LogEnable","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bool","name":"_shield","type":"bool"}],"name":"LogSwitchShield","type":"event"},{"inputs":[{"internalType":"address[]","name":"_targets","type":"address[]"},{"internalType":"bytes[]","name":"_datas","type":"bytes[]"},{"internalType":"address","name":"_origin","type":"address"}],"name":"cast","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"disable","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"enable","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"instaIndex","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"isAuth","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"shield","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"_shield","type":"bool"}],"name":"switchShield","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"version","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}] 2 | -------------------------------------------------------------------------------- /test/abi/connectors.json: -------------------------------------------------------------------------------- 1 | [{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addr","type":"address"}],"name":"LogAddController","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"connector","type":"address"}],"name":"LogDisable","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"connector","type":"address"}],"name":"LogEnable","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"connector","type":"address"}],"name":"LogEnableStatic","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addr","type":"address"}],"name":"LogRemoveController","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"chief","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"connectorArray","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"connectorCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"connectorLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"connectors","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_connector","type":"address"}],"name":"disable","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_userAddress","type":"address"}],"name":"disableChief","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_connector","type":"address"}],"name":"enable","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_userAddress","type":"address"}],"name":"enableChief","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_connector","type":"address"}],"name":"enableStatic","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"instaIndex","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"_connectors","type":"address[]"}],"name":"isConnector","outputs":[{"internalType":"bool","name":"isOk","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"_connectors","type":"address[]"}],"name":"isStaticConnector","outputs":[{"internalType":"bool","name":"isOk","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"staticConnectorArray","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"staticConnectorLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"staticConnectors","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}] 2 | -------------------------------------------------------------------------------- /test/abi/crvRenWSBTC.json: -------------------------------------------------------------------------------- 1 | [{"name":"Transfer","inputs":[{"type":"address","name":"_from","indexed":true},{"type":"address","name":"_to","indexed":true},{"type":"uint256","name":"_value","indexed":false}],"anonymous":false,"type":"event"},{"name":"Approval","inputs":[{"type":"address","name":"_owner","indexed":true},{"type":"address","name":"_spender","indexed":true},{"type":"uint256","name":"_value","indexed":false}],"anonymous":false,"type":"event"},{"outputs":[],"inputs":[{"type":"string","name":"_name"},{"type":"string","name":"_symbol"},{"type":"uint256","name":"_decimals"},{"type":"uint256","name":"_supply"}],"constant":false,"payable":false,"type":"constructor"},{"name":"set_minter","outputs":[],"inputs":[{"type":"address","name":"_minter"}],"constant":false,"payable":false,"type":"function","gas":36247},{"name":"totalSupply","outputs":[{"type":"uint256","name":"out"}],"inputs":[],"constant":true,"payable":false,"type":"function","gas":1181},{"name":"allowance","outputs":[{"type":"uint256","name":"out"}],"inputs":[{"type":"address","name":"_owner"},{"type":"address","name":"_spender"}],"constant":true,"payable":false,"type":"function","gas":1519},{"name":"transfer","outputs":[{"type":"bool","name":"out"}],"inputs":[{"type":"address","name":"_to"},{"type":"uint256","name":"_value"}],"constant":false,"payable":false,"type":"function","gas":74802},{"name":"transferFrom","outputs":[{"type":"bool","name":"out"}],"inputs":[{"type":"address","name":"_from"},{"type":"address","name":"_to"},{"type":"uint256","name":"_value"}],"constant":false,"payable":false,"type":"function","gas":111953},{"name":"approve","outputs":[{"type":"bool","name":"out"}],"inputs":[{"type":"address","name":"_spender"},{"type":"uint256","name":"_value"}],"constant":false,"payable":false,"type":"function","gas":39012},{"name":"mint","outputs":[],"inputs":[{"type":"address","name":"_to"},{"type":"uint256","name":"_value"}],"constant":false,"payable":false,"type":"function","gas":75733},{"name":"burn","outputs":[],"inputs":[{"type":"uint256","name":"_value"}],"constant":false,"payable":false,"type":"function","gas":76623},{"name":"burnFrom","outputs":[],"inputs":[{"type":"address","name":"_to"},{"type":"uint256","name":"_value"}],"constant":false,"payable":false,"type":"function","gas":76696},{"name":"name","outputs":[{"type":"string","name":"out"}],"inputs":[],"constant":true,"payable":false,"type":"function","gas":7853},{"name":"symbol","outputs":[{"type":"string","name":"out"}],"inputs":[],"constant":true,"payable":false,"type":"function","gas":6906},{"name":"decimals","outputs":[{"type":"uint256","name":"out"}],"inputs":[],"constant":true,"payable":false,"type":"function","gas":1511},{"name":"balanceOf","outputs":[{"type":"uint256","name":"out"}],"inputs":[{"type":"address","name":"arg0"}],"constant":true,"payable":false,"type":"function","gas":1695}] 2 | -------------------------------------------------------------------------------- /test/abi/curveGauge.json: -------------------------------------------------------------------------------- 1 | [{"name":"Deposit","inputs":[{"type":"address","name":"provider","indexed":true},{"type":"uint256","name":"value","indexed":false}],"anonymous":false,"type":"event"},{"name":"Withdraw","inputs":[{"type":"address","name":"provider","indexed":true},{"type":"uint256","name":"value","indexed":false}],"anonymous":false,"type":"event"},{"name":"UpdateLiquidityLimit","inputs":[{"type":"address","name":"user","indexed":false},{"type":"uint256","name":"original_balance","indexed":false},{"type":"uint256","name":"original_supply","indexed":false},{"type":"uint256","name":"working_balance","indexed":false},{"type":"uint256","name":"working_supply","indexed":false}],"anonymous":false,"type":"event"},{"outputs":[],"inputs":[{"type":"address","name":"lp_addr"},{"type":"address","name":"_minter"},{"type":"address","name":"_reward_contract"},{"type":"address","name":"_rewarded_token"}],"stateMutability":"nonpayable","type":"constructor"},{"name":"user_checkpoint","outputs":[{"type":"bool","name":""}],"inputs":[{"type":"address","name":"addr"}],"stateMutability":"nonpayable","type":"function","gas":2311984},{"name":"claimable_tokens","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"addr"}],"stateMutability":"nonpayable","type":"function","gas":2231138},{"name":"claimable_reward","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"addr"}],"stateMutability":"view","type":"function","gas":7300},{"name":"kick","outputs":[],"inputs":[{"type":"address","name":"addr"}],"stateMutability":"nonpayable","type":"function","gas":2317383},{"name":"set_approve_deposit","outputs":[],"inputs":[{"type":"address","name":"addr"},{"type":"bool","name":"can_deposit"}],"stateMutability":"nonpayable","type":"function","gas":35826},{"name":"deposit","outputs":[],"inputs":[{"type":"uint256","name":"_value"}],"stateMutability":"nonpayable","type":"function"},{"name":"deposit","outputs":[],"inputs":[{"type":"uint256","name":"_value"},{"type":"address","name":"addr"}],"stateMutability":"nonpayable","type":"function"},{"name":"withdraw","outputs":[],"inputs":[{"type":"uint256","name":"_value"}],"stateMutability":"nonpayable","type":"function"},{"name":"withdraw","outputs":[],"inputs":[{"type":"uint256","name":"_value"},{"type":"bool","name":"claim_rewards"}],"stateMutability":"nonpayable","type":"function"},{"name":"claim_rewards","outputs":[],"inputs":[],"stateMutability":"nonpayable","type":"function"},{"name":"claim_rewards","outputs":[],"inputs":[{"type":"address","name":"addr"}],"stateMutability":"nonpayable","type":"function"},{"name":"integrate_checkpoint","outputs":[{"type":"uint256","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":2387},{"name":"minter","outputs":[{"type":"address","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1511},{"name":"crv_token","outputs":[{"type":"address","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1541},{"name":"lp_token","outputs":[{"type":"address","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1571},{"name":"controller","outputs":[{"type":"address","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1601},{"name":"voting_escrow","outputs":[{"type":"address","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1631},{"name":"balanceOf","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"arg0"}],"stateMutability":"view","type":"function","gas":1815},{"name":"totalSupply","outputs":[{"type":"uint256","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1691},{"name":"future_epoch_time","outputs":[{"type":"uint256","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1721},{"name":"approved_to_deposit","outputs":[{"type":"bool","name":""}],"inputs":[{"type":"address","name":"arg0"},{"type":"address","name":"arg1"}],"stateMutability":"view","type":"function","gas":2059},{"name":"working_balances","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"arg0"}],"stateMutability":"view","type":"function","gas":1935},{"name":"working_supply","outputs":[{"type":"uint256","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1811},{"name":"period","outputs":[{"type":"int128","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1841},{"name":"period_timestamp","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"uint256","name":"arg0"}],"stateMutability":"view","type":"function","gas":1980},{"name":"integrate_inv_supply","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"uint256","name":"arg0"}],"stateMutability":"view","type":"function","gas":2010},{"name":"integrate_inv_supply_of","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"arg0"}],"stateMutability":"view","type":"function","gas":2085},{"name":"integrate_checkpoint_of","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"arg0"}],"stateMutability":"view","type":"function","gas":2115},{"name":"integrate_fraction","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"arg0"}],"stateMutability":"view","type":"function","gas":2145},{"name":"inflation_rate","outputs":[{"type":"uint256","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":2021},{"name":"reward_contract","outputs":[{"type":"address","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":2051},{"name":"rewarded_token","outputs":[{"type":"address","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":2081},{"name":"reward_integral","outputs":[{"type":"uint256","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":2111},{"name":"reward_integral_for","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"arg0"}],"stateMutability":"view","type":"function","gas":2295},{"name":"rewards_for","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"arg0"}],"stateMutability":"view","type":"function","gas":2325},{"name":"claimed_rewards_for","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"arg0"}],"stateMutability":"view","type":"function","gas":2355}] 2 | -------------------------------------------------------------------------------- /test/abi/curveSwap.json: -------------------------------------------------------------------------------- 1 | [{"name":"TokenExchange","inputs":[{"type":"address","name":"buyer","indexed":true},{"type":"int128","name":"sold_id","indexed":false},{"type":"uint256","name":"tokens_sold","indexed":false},{"type":"int128","name":"bought_id","indexed":false},{"type":"uint256","name":"tokens_bought","indexed":false}],"anonymous":false,"type":"event"},{"name":"AddLiquidity","inputs":[{"type":"address","name":"provider","indexed":true},{"type":"uint256[3]","name":"token_amounts","indexed":false},{"type":"uint256[3]","name":"fees","indexed":false},{"type":"uint256","name":"invariant","indexed":false},{"type":"uint256","name":"token_supply","indexed":false}],"anonymous":false,"type":"event"},{"name":"RemoveLiquidity","inputs":[{"type":"address","name":"provider","indexed":true},{"type":"uint256[3]","name":"token_amounts","indexed":false},{"type":"uint256[3]","name":"fees","indexed":false},{"type":"uint256","name":"token_supply","indexed":false}],"anonymous":false,"type":"event"},{"name":"RemoveLiquidityOne","inputs":[{"type":"address","name":"provider","indexed":true},{"type":"uint256","name":"token_amount","indexed":false},{"type":"uint256","name":"coin_amount","indexed":false}],"anonymous":false,"type":"event"},{"name":"RemoveLiquidityImbalance","inputs":[{"type":"address","name":"provider","indexed":true},{"type":"uint256[3]","name":"token_amounts","indexed":false},{"type":"uint256[3]","name":"fees","indexed":false},{"type":"uint256","name":"invariant","indexed":false},{"type":"uint256","name":"token_supply","indexed":false}],"anonymous":false,"type":"event"},{"name":"CommitNewAdmin","inputs":[{"type":"uint256","name":"deadline","indexed":true,"unit":"sec"},{"type":"address","name":"admin","indexed":true}],"anonymous":false,"type":"event"},{"name":"NewAdmin","inputs":[{"type":"address","name":"admin","indexed":true}],"anonymous":false,"type":"event"},{"name":"CommitNewFee","inputs":[{"type":"uint256","name":"deadline","indexed":true,"unit":"sec"},{"type":"uint256","name":"fee","indexed":false},{"type":"uint256","name":"admin_fee","indexed":false}],"anonymous":false,"type":"event"},{"name":"NewFee","inputs":[{"type":"uint256","name":"fee","indexed":false},{"type":"uint256","name":"admin_fee","indexed":false}],"anonymous":false,"type":"event"},{"name":"RampA","inputs":[{"type":"uint256","name":"old_A","indexed":false},{"type":"uint256","name":"new_A","indexed":false},{"type":"uint256","name":"initial_time","indexed":false,"unit":"sec"},{"type":"uint256","name":"future_time","indexed":false,"unit":"sec"}],"anonymous":false,"type":"event"},{"name":"StopRampA","inputs":[{"type":"uint256","name":"A","indexed":false},{"type":"uint256","name":"t","indexed":false,"unit":"sec"}],"anonymous":false,"type":"event"},{"outputs":[],"inputs":[{"type":"address[3]","name":"_coins"},{"type":"address","name":"_pool_token"},{"type":"uint256","name":"_A"},{"type":"uint256","name":"_fee"}],"constant":false,"payable":false,"type":"constructor"},{"name":"A","outputs":[{"type":"uint256","name":""}],"inputs":[],"constant":true,"payable":false,"type":"function","gas":5227},{"name":"get_virtual_price","outputs":[{"type":"uint256","name":""}],"inputs":[],"constant":true,"payable":false,"type":"function","gas":1150488},{"name":"calc_token_amount","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"uint256[3]","name":"amounts"},{"type":"bool","name":"deposit"}],"constant":true,"payable":false,"type":"function","gas":4526955},{"name":"add_liquidity","outputs":[],"inputs":[{"type":"uint256[3]","name":"amounts"},{"type":"uint256","name":"min_mint_amount"}],"constant":false,"payable":false,"type":"function","gas":6972762},{"name":"get_dy","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"int128","name":"i"},{"type":"int128","name":"j"},{"type":"uint256","name":"dx"}],"constant":true,"payable":false,"type":"function","gas":2687932},{"name":"get_dy_underlying","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"int128","name":"i"},{"type":"int128","name":"j"},{"type":"uint256","name":"dx"}],"constant":true,"payable":false,"type":"function","gas":2687745},{"name":"exchange","outputs":[],"inputs":[{"type":"int128","name":"i"},{"type":"int128","name":"j"},{"type":"uint256","name":"dx"},{"type":"uint256","name":"min_dy"}],"constant":false,"payable":false,"type":"function","gas":5499133},{"name":"remove_liquidity","outputs":[],"inputs":[{"type":"uint256","name":"_amount"},{"type":"uint256[3]","name":"min_amounts"}],"constant":false,"payable":false,"type":"function","gas":196975},{"name":"remove_liquidity_imbalance","outputs":[],"inputs":[{"type":"uint256[3]","name":"amounts"},{"type":"uint256","name":"max_burn_amount"}],"constant":false,"payable":false,"type":"function","gas":6972281},{"name":"calc_withdraw_one_coin","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"uint256","name":"_token_amount"},{"type":"int128","name":"i"}],"constant":true,"payable":false,"type":"function","gas":15405},{"name":"remove_liquidity_one_coin","outputs":[],"inputs":[{"type":"uint256","name":"_token_amount"},{"type":"int128","name":"i"},{"type":"uint256","name":"min_amount"}],"constant":false,"payable":false,"type":"function","gas":4044074},{"name":"ramp_A","outputs":[],"inputs":[{"type":"uint256","name":"_future_A"},{"type":"uint256","unit":"sec","name":"_future_time"}],"constant":false,"payable":false,"type":"function","gas":151937},{"name":"stop_ramp_A","outputs":[],"inputs":[],"constant":false,"payable":false,"type":"function","gas":148697},{"name":"commit_new_fee","outputs":[],"inputs":[{"type":"uint256","name":"new_fee"},{"type":"uint256","name":"new_admin_fee"}],"constant":false,"payable":false,"type":"function","gas":110521},{"name":"apply_new_fee","outputs":[],"inputs":[],"constant":false,"payable":false,"type":"function","gas":97220},{"name":"revert_new_parameters","outputs":[],"inputs":[],"constant":false,"payable":false,"type":"function","gas":21955},{"name":"commit_transfer_ownership","outputs":[],"inputs":[{"type":"address","name":"_owner"}],"constant":false,"payable":false,"type":"function","gas":74632},{"name":"apply_transfer_ownership","outputs":[],"inputs":[],"constant":false,"payable":false,"type":"function","gas":60688},{"name":"revert_transfer_ownership","outputs":[],"inputs":[],"constant":false,"payable":false,"type":"function","gas":22045},{"name":"withdraw_admin_fees","outputs":[],"inputs":[],"constant":false,"payable":false,"type":"function","gas":17565},{"name":"kill_me","outputs":[],"inputs":[],"constant":false,"payable":false,"type":"function","gas":37998},{"name":"unkill_me","outputs":[],"inputs":[],"constant":false,"payable":false,"type":"function","gas":22135},{"name":"coins","outputs":[{"type":"address","name":""}],"inputs":[{"type":"int128","name":"arg0"}],"constant":true,"payable":false,"type":"function","gas":2310},{"name":"balances","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"int128","name":"arg0"}],"constant":true,"payable":false,"type":"function","gas":2340},{"name":"fee","outputs":[{"type":"uint256","name":""}],"inputs":[],"constant":true,"payable":false,"type":"function","gas":2171},{"name":"admin_fee","outputs":[{"type":"uint256","name":""}],"inputs":[],"constant":true,"payable":false,"type":"function","gas":2201},{"name":"owner","outputs":[{"type":"address","name":""}],"inputs":[],"constant":true,"payable":false,"type":"function","gas":2231},{"name":"initial_A","outputs":[{"type":"uint256","name":""}],"inputs":[],"constant":true,"payable":false,"type":"function","gas":2261},{"name":"future_A","outputs":[{"type":"uint256","name":""}],"inputs":[],"constant":true,"payable":false,"type":"function","gas":2291},{"name":"initial_A_time","outputs":[{"type":"uint256","unit":"sec","name":""}],"inputs":[],"constant":true,"payable":false,"type":"function","gas":2321},{"name":"future_A_time","outputs":[{"type":"uint256","unit":"sec","name":""}],"inputs":[],"constant":true,"payable":false,"type":"function","gas":2351},{"name":"admin_actions_deadline","outputs":[{"type":"uint256","unit":"sec","name":""}],"inputs":[],"constant":true,"payable":false,"type":"function","gas":2381},{"name":"transfer_ownership_deadline","outputs":[{"type":"uint256","unit":"sec","name":""}],"inputs":[],"constant":true,"payable":false,"type":"function","gas":2411},{"name":"future_fee","outputs":[{"type":"uint256","name":""}],"inputs":[],"constant":true,"payable":false,"type":"function","gas":2441},{"name":"future_admin_fee","outputs":[{"type":"uint256","name":""}],"inputs":[],"constant":true,"payable":false,"type":"function","gas":2471},{"name":"future_owner","outputs":[{"type":"address","name":""}],"inputs":[],"constant":true,"payable":false,"type":"function","gas":2501}] 2 | -------------------------------------------------------------------------------- /test/abi/curveVesting.json: -------------------------------------------------------------------------------- 1 | [{"name":"Fund","inputs":[{"type":"address","name":"recipient","indexed":true},{"type":"uint256","name":"amount","indexed":false}],"anonymous":false,"type":"event"},{"name":"Claim","inputs":[{"type":"address","name":"recipient","indexed":true},{"type":"uint256","name":"claimed","indexed":false}],"anonymous":false,"type":"event"},{"name":"ToggleDisable","inputs":[{"type":"address","name":"recipient","indexed":false},{"type":"bool","name":"disabled","indexed":false}],"anonymous":false,"type":"event"},{"name":"CommitOwnership","inputs":[{"type":"address","name":"admin","indexed":false}],"anonymous":false,"type":"event"},{"name":"ApplyOwnership","inputs":[{"type":"address","name":"admin","indexed":false}],"anonymous":false,"type":"event"},{"outputs":[],"inputs":[{"type":"address","name":"_token"},{"type":"uint256","name":"_start_time"},{"type":"uint256","name":"_end_time"},{"type":"bool","name":"_can_disable"},{"type":"address[4]","name":"_fund_admins"}],"stateMutability":"nonpayable","type":"constructor"},{"name":"add_tokens","outputs":[],"inputs":[{"type":"uint256","name":"_amount"}],"stateMutability":"nonpayable","type":"function","gas":39108},{"name":"fund","outputs":[],"inputs":[{"type":"address[100]","name":"_recipients"},{"type":"uint256[100]","name":"_amounts"}],"stateMutability":"nonpayable","type":"function","gas":3962646},{"name":"toggle_disable","outputs":[],"inputs":[{"type":"address","name":"_recipient"}],"stateMutability":"nonpayable","type":"function","gas":40280},{"name":"disable_can_disable","outputs":[],"inputs":[],"stateMutability":"nonpayable","type":"function","gas":21295},{"name":"disable_fund_admins","outputs":[],"inputs":[],"stateMutability":"nonpayable","type":"function","gas":21325},{"name":"vestedSupply","outputs":[{"type":"uint256","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":4468},{"name":"lockedSupply","outputs":[{"type":"uint256","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":5465},{"name":"vestedOf","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"_recipient"}],"stateMutability":"view","type":"function","gas":5163},{"name":"balanceOf","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"_recipient"}],"stateMutability":"view","type":"function","gas":6275},{"name":"lockedOf","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"_recipient"}],"stateMutability":"view","type":"function","gas":6305},{"name":"claim","outputs":[],"inputs":[],"stateMutability":"nonpayable","type":"function"},{"name":"claim","outputs":[],"inputs":[{"type":"address","name":"addr"}],"stateMutability":"nonpayable","type":"function"},{"name":"commit_transfer_ownership","outputs":[{"type":"bool","name":""}],"inputs":[{"type":"address","name":"addr"}],"stateMutability":"nonpayable","type":"function","gas":38032},{"name":"apply_transfer_ownership","outputs":[{"type":"bool","name":""}],"inputs":[],"stateMutability":"nonpayable","type":"function","gas":38932},{"name":"token","outputs":[{"type":"address","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1601},{"name":"start_time","outputs":[{"type":"uint256","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1631},{"name":"end_time","outputs":[{"type":"uint256","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1661},{"name":"initial_locked","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"arg0"}],"stateMutability":"view","type":"function","gas":1845},{"name":"total_claimed","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"arg0"}],"stateMutability":"view","type":"function","gas":1875},{"name":"initial_locked_supply","outputs":[{"type":"uint256","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1751},{"name":"unallocated_supply","outputs":[{"type":"uint256","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1781},{"name":"can_disable","outputs":[{"type":"bool","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1811},{"name":"disabled_at","outputs":[{"type":"uint256","name":""}],"inputs":[{"type":"address","name":"arg0"}],"stateMutability":"view","type":"function","gas":1995},{"name":"admin","outputs":[{"type":"address","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1871},{"name":"future_admin","outputs":[{"type":"address","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1901},{"name":"fund_admins_enabled","outputs":[{"type":"bool","name":""}],"inputs":[],"stateMutability":"view","type":"function","gas":1931},{"name":"fund_admins","outputs":[{"type":"bool","name":""}],"inputs":[{"type":"address","name":"arg0"}],"stateMutability":"view","type":"function","gas":2115}] 2 | -------------------------------------------------------------------------------- /test/abi/dai.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | { 3 | constant: true, 4 | inputs: [], 5 | name: 'name', 6 | outputs: [{ name: '', type: 'bytes32' }], 7 | payable: false, 8 | stateMutability: 'view', 9 | type: 'function' 10 | }, 11 | { 12 | constant: false, 13 | inputs: [], 14 | name: 'stop', 15 | outputs: [], 16 | payable: false, 17 | stateMutability: 'nonpayable', 18 | type: 'function' 19 | }, 20 | { 21 | constant: false, 22 | inputs: [ 23 | { name: 'guy', type: 'address' }, 24 | { name: 'wad', type: 'uint256' } 25 | ], 26 | name: 'approve', 27 | outputs: [{ name: '', type: 'bool' }], 28 | payable: false, 29 | stateMutability: 'nonpayable', 30 | type: 'function' 31 | }, 32 | { 33 | constant: false, 34 | inputs: [{ name: 'owner_', type: 'address' }], 35 | name: 'setOwner', 36 | outputs: [], 37 | payable: false, 38 | stateMutability: 'nonpayable', 39 | type: 'function' 40 | }, 41 | { 42 | constant: true, 43 | inputs: [], 44 | name: 'totalSupply', 45 | outputs: [{ name: '', type: 'uint256' }], 46 | payable: false, 47 | stateMutability: 'view', 48 | type: 'function' 49 | }, 50 | { 51 | constant: false, 52 | inputs: [ 53 | { name: 'src', type: 'address' }, 54 | { name: 'dst', type: 'address' }, 55 | { name: 'wad', type: 'uint256' } 56 | ], 57 | name: 'transferFrom', 58 | outputs: [{ name: '', type: 'bool' }], 59 | payable: false, 60 | stateMutability: 'nonpayable', 61 | type: 'function' 62 | }, 63 | { 64 | constant: true, 65 | inputs: [], 66 | name: 'decimals', 67 | outputs: [{ name: '', type: 'uint256' }], 68 | payable: false, 69 | stateMutability: 'view', 70 | type: 'function' 71 | }, 72 | { 73 | constant: false, 74 | inputs: [ 75 | { name: 'guy', type: 'address' }, 76 | { name: 'wad', type: 'uint256' } 77 | ], 78 | name: 'mint', 79 | outputs: [], 80 | payable: false, 81 | stateMutability: 'nonpayable', 82 | type: 'function' 83 | }, 84 | { 85 | constant: false, 86 | inputs: [{ name: 'wad', type: 'uint256' }], 87 | name: 'burn', 88 | outputs: [], 89 | payable: false, 90 | stateMutability: 'nonpayable', 91 | type: 'function' 92 | }, 93 | { 94 | constant: false, 95 | inputs: [{ name: 'name_', type: 'bytes32' }], 96 | name: 'setName', 97 | outputs: [], 98 | payable: false, 99 | stateMutability: 'nonpayable', 100 | type: 'function' 101 | }, 102 | { 103 | constant: true, 104 | inputs: [{ name: 'src', type: 'address' }], 105 | name: 'balanceOf', 106 | outputs: [{ name: '', type: 'uint256' }], 107 | payable: false, 108 | stateMutability: 'view', 109 | type: 'function' 110 | }, 111 | { 112 | constant: true, 113 | inputs: [], 114 | name: 'stopped', 115 | outputs: [{ name: '', type: 'bool' }], 116 | payable: false, 117 | stateMutability: 'view', 118 | type: 'function' 119 | }, 120 | { 121 | constant: false, 122 | inputs: [{ name: 'authority_', type: 'address' }], 123 | name: 'setAuthority', 124 | outputs: [], 125 | payable: false, 126 | stateMutability: 'nonpayable', 127 | type: 'function' 128 | }, 129 | { 130 | constant: true, 131 | inputs: [], 132 | name: 'owner', 133 | outputs: [{ name: '', type: 'address' }], 134 | payable: false, 135 | stateMutability: 'view', 136 | type: 'function' 137 | }, 138 | { 139 | constant: true, 140 | inputs: [], 141 | name: 'symbol', 142 | outputs: [{ name: '', type: 'bytes32' }], 143 | payable: false, 144 | stateMutability: 'view', 145 | type: 'function' 146 | }, 147 | { 148 | constant: false, 149 | inputs: [ 150 | { name: 'guy', type: 'address' }, 151 | { name: 'wad', type: 'uint256' } 152 | ], 153 | name: 'burn', 154 | outputs: [], 155 | payable: false, 156 | stateMutability: 'nonpayable', 157 | type: 'function' 158 | }, 159 | { 160 | constant: false, 161 | inputs: [{ name: 'wad', type: 'uint256' }], 162 | name: 'mint', 163 | outputs: [], 164 | payable: false, 165 | stateMutability: 'nonpayable', 166 | type: 'function' 167 | }, 168 | { 169 | constant: false, 170 | inputs: [ 171 | { name: 'dst', type: 'address' }, 172 | { name: 'wad', type: 'uint256' } 173 | ], 174 | name: 'transfer', 175 | outputs: [{ name: '', type: 'bool' }], 176 | payable: false, 177 | stateMutability: 'nonpayable', 178 | type: 'function' 179 | }, 180 | { 181 | constant: false, 182 | inputs: [ 183 | { name: 'dst', type: 'address' }, 184 | { name: 'wad', type: 'uint256' } 185 | ], 186 | name: 'push', 187 | outputs: [], 188 | payable: false, 189 | stateMutability: 'nonpayable', 190 | type: 'function' 191 | }, 192 | { 193 | constant: false, 194 | inputs: [ 195 | { name: 'src', type: 'address' }, 196 | { name: 'dst', type: 'address' }, 197 | { name: 'wad', type: 'uint256' } 198 | ], 199 | name: 'move', 200 | outputs: [], 201 | payable: false, 202 | stateMutability: 'nonpayable', 203 | type: 'function' 204 | }, 205 | { 206 | constant: false, 207 | inputs: [], 208 | name: 'start', 209 | outputs: [], 210 | payable: false, 211 | stateMutability: 'nonpayable', 212 | type: 'function' 213 | }, 214 | { 215 | constant: true, 216 | inputs: [], 217 | name: 'authority', 218 | outputs: [{ name: '', type: 'address' }], 219 | payable: false, 220 | stateMutability: 'view', 221 | type: 'function' 222 | }, 223 | { 224 | constant: false, 225 | inputs: [{ name: 'guy', type: 'address' }], 226 | name: 'approve', 227 | outputs: [{ name: '', type: 'bool' }], 228 | payable: false, 229 | stateMutability: 'nonpayable', 230 | type: 'function' 231 | }, 232 | { 233 | constant: true, 234 | inputs: [ 235 | { name: 'src', type: 'address' }, 236 | { name: 'guy', type: 'address' } 237 | ], 238 | name: 'allowance', 239 | outputs: [{ name: '', type: 'uint256' }], 240 | payable: false, 241 | stateMutability: 'view', 242 | type: 'function' 243 | }, 244 | { 245 | constant: false, 246 | inputs: [ 247 | { name: 'src', type: 'address' }, 248 | { name: 'wad', type: 'uint256' } 249 | ], 250 | name: 'pull', 251 | outputs: [], 252 | payable: false, 253 | stateMutability: 'nonpayable', 254 | type: 'function' 255 | }, 256 | { 257 | inputs: [{ name: 'symbol_', type: 'bytes32' }], 258 | payable: false, 259 | stateMutability: 'nonpayable', 260 | type: 'constructor' 261 | }, 262 | { 263 | anonymous: false, 264 | inputs: [ 265 | { indexed: true, name: 'guy', type: 'address' }, 266 | { indexed: false, name: 'wad', type: 'uint256' } 267 | ], 268 | name: 'Mint', 269 | type: 'event' 270 | }, 271 | { 272 | anonymous: false, 273 | inputs: [ 274 | { indexed: true, name: 'guy', type: 'address' }, 275 | { indexed: false, name: 'wad', type: 'uint256' } 276 | ], 277 | name: 'Burn', 278 | type: 'event' 279 | }, 280 | { 281 | anonymous: false, 282 | inputs: [{ indexed: true, name: 'authority', type: 'address' }], 283 | name: 'LogSetAuthority', 284 | type: 'event' 285 | }, 286 | { 287 | anonymous: false, 288 | inputs: [{ indexed: true, name: 'owner', type: 'address' }], 289 | name: 'LogSetOwner', 290 | type: 'event' 291 | }, 292 | { 293 | anonymous: true, 294 | inputs: [ 295 | { indexed: true, name: 'sig', type: 'bytes4' }, 296 | { indexed: true, name: 'guy', type: 'address' }, 297 | { indexed: true, name: 'foo', type: 'bytes32' }, 298 | { indexed: true, name: 'bar', type: 'bytes32' }, 299 | { indexed: false, name: 'wad', type: 'uint256' }, 300 | { indexed: false, name: 'fax', type: 'bytes' } 301 | ], 302 | name: 'LogNote', 303 | type: 'event' 304 | }, 305 | { 306 | anonymous: false, 307 | inputs: [ 308 | { indexed: true, name: 'src', type: 'address' }, 309 | { indexed: true, name: 'guy', type: 'address' }, 310 | { indexed: false, name: 'wad', type: 'uint256' } 311 | ], 312 | name: 'Approval', 313 | type: 'event' 314 | }, 315 | { 316 | anonymous: false, 317 | inputs: [ 318 | { indexed: true, name: 'src', type: 'address' }, 319 | { indexed: true, name: 'dst', type: 'address' }, 320 | { indexed: false, name: 'wad', type: 'uint256' } 321 | ], 322 | name: 'Transfer', 323 | type: 'event' 324 | } 325 | ]; 326 | -------------------------------------------------------------------------------- /test/abi/erc20.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | { 3 | constant: true, 4 | inputs: [], 5 | name: 'name', 6 | outputs: [{ name: '', type: 'bytes32' }], 7 | payable: false, 8 | stateMutability: 'view', 9 | type: 'function' 10 | }, 11 | { 12 | constant: false, 13 | inputs: [], 14 | name: 'stop', 15 | outputs: [], 16 | payable: false, 17 | stateMutability: 'nonpayable', 18 | type: 'function' 19 | }, 20 | { 21 | constant: false, 22 | inputs: [ 23 | { name: 'guy', type: 'address' }, 24 | { name: 'wad', type: 'uint256' } 25 | ], 26 | name: 'approve', 27 | outputs: [{ name: '', type: 'bool' }], 28 | payable: false, 29 | stateMutability: 'nonpayable', 30 | type: 'function' 31 | }, 32 | { 33 | constant: false, 34 | inputs: [{ name: 'owner_', type: 'address' }], 35 | name: 'setOwner', 36 | outputs: [], 37 | payable: false, 38 | stateMutability: 'nonpayable', 39 | type: 'function' 40 | }, 41 | { 42 | constant: true, 43 | inputs: [], 44 | name: 'totalSupply', 45 | outputs: [{ name: '', type: 'uint256' }], 46 | payable: false, 47 | stateMutability: 'view', 48 | type: 'function' 49 | }, 50 | { 51 | constant: false, 52 | inputs: [ 53 | { name: 'src', type: 'address' }, 54 | { name: 'dst', type: 'address' }, 55 | { name: 'wad', type: 'uint256' } 56 | ], 57 | name: 'transferFrom', 58 | outputs: [{ name: '', type: 'bool' }], 59 | payable: false, 60 | stateMutability: 'nonpayable', 61 | type: 'function' 62 | }, 63 | { 64 | constant: true, 65 | inputs: [], 66 | name: 'decimals', 67 | outputs: [{ name: '', type: 'uint256' }], 68 | payable: false, 69 | stateMutability: 'view', 70 | type: 'function' 71 | }, 72 | { 73 | constant: false, 74 | inputs: [ 75 | { name: 'guy', type: 'address' }, 76 | { name: 'wad', type: 'uint256' } 77 | ], 78 | name: 'mint', 79 | outputs: [], 80 | payable: false, 81 | stateMutability: 'nonpayable', 82 | type: 'function' 83 | }, 84 | { 85 | constant: false, 86 | inputs: [{ name: 'wad', type: 'uint256' }], 87 | name: 'burn', 88 | outputs: [], 89 | payable: false, 90 | stateMutability: 'nonpayable', 91 | type: 'function' 92 | }, 93 | { 94 | constant: false, 95 | inputs: [{ name: 'name_', type: 'bytes32' }], 96 | name: 'setName', 97 | outputs: [], 98 | payable: false, 99 | stateMutability: 'nonpayable', 100 | type: 'function' 101 | }, 102 | { 103 | constant: true, 104 | inputs: [{ name: 'src', type: 'address' }], 105 | name: 'balanceOf', 106 | outputs: [{ name: '', type: 'uint256' }], 107 | payable: false, 108 | stateMutability: 'view', 109 | type: 'function' 110 | }, 111 | { 112 | constant: true, 113 | inputs: [], 114 | name: 'stopped', 115 | outputs: [{ name: '', type: 'bool' }], 116 | payable: false, 117 | stateMutability: 'view', 118 | type: 'function' 119 | }, 120 | { 121 | constant: false, 122 | inputs: [{ name: 'authority_', type: 'address' }], 123 | name: 'setAuthority', 124 | outputs: [], 125 | payable: false, 126 | stateMutability: 'nonpayable', 127 | type: 'function' 128 | }, 129 | { 130 | constant: true, 131 | inputs: [], 132 | name: 'owner', 133 | outputs: [{ name: '', type: 'address' }], 134 | payable: false, 135 | stateMutability: 'view', 136 | type: 'function' 137 | }, 138 | { 139 | constant: true, 140 | inputs: [], 141 | name: 'symbol', 142 | outputs: [{ name: '', type: 'bytes32' }], 143 | payable: false, 144 | stateMutability: 'view', 145 | type: 'function' 146 | }, 147 | { 148 | constant: false, 149 | inputs: [ 150 | { name: 'guy', type: 'address' }, 151 | { name: 'wad', type: 'uint256' } 152 | ], 153 | name: 'burn', 154 | outputs: [], 155 | payable: false, 156 | stateMutability: 'nonpayable', 157 | type: 'function' 158 | }, 159 | { 160 | constant: false, 161 | inputs: [{ name: 'wad', type: 'uint256' }], 162 | name: 'mint', 163 | outputs: [], 164 | payable: false, 165 | stateMutability: 'nonpayable', 166 | type: 'function' 167 | }, 168 | { 169 | constant: false, 170 | inputs: [ 171 | { name: 'dst', type: 'address' }, 172 | { name: 'wad', type: 'uint256' } 173 | ], 174 | name: 'transfer', 175 | outputs: [{ name: '', type: 'bool' }], 176 | payable: false, 177 | stateMutability: 'nonpayable', 178 | type: 'function' 179 | }, 180 | { 181 | constant: false, 182 | inputs: [ 183 | { name: 'dst', type: 'address' }, 184 | { name: 'wad', type: 'uint256' } 185 | ], 186 | name: 'push', 187 | outputs: [], 188 | payable: false, 189 | stateMutability: 'nonpayable', 190 | type: 'function' 191 | }, 192 | { 193 | constant: false, 194 | inputs: [ 195 | { name: 'src', type: 'address' }, 196 | { name: 'dst', type: 'address' }, 197 | { name: 'wad', type: 'uint256' } 198 | ], 199 | name: 'move', 200 | outputs: [], 201 | payable: false, 202 | stateMutability: 'nonpayable', 203 | type: 'function' 204 | }, 205 | { 206 | constant: false, 207 | inputs: [], 208 | name: 'start', 209 | outputs: [], 210 | payable: false, 211 | stateMutability: 'nonpayable', 212 | type: 'function' 213 | }, 214 | { 215 | constant: true, 216 | inputs: [], 217 | name: 'authority', 218 | outputs: [{ name: '', type: 'address' }], 219 | payable: false, 220 | stateMutability: 'view', 221 | type: 'function' 222 | }, 223 | { 224 | constant: false, 225 | inputs: [{ name: 'guy', type: 'address' }], 226 | name: 'approve', 227 | outputs: [{ name: '', type: 'bool' }], 228 | payable: false, 229 | stateMutability: 'nonpayable', 230 | type: 'function' 231 | }, 232 | { 233 | constant: true, 234 | inputs: [ 235 | { name: 'src', type: 'address' }, 236 | { name: 'guy', type: 'address' } 237 | ], 238 | name: 'allowance', 239 | outputs: [{ name: '', type: 'uint256' }], 240 | payable: false, 241 | stateMutability: 'view', 242 | type: 'function' 243 | }, 244 | { 245 | constant: false, 246 | inputs: [ 247 | { name: 'src', type: 'address' }, 248 | { name: 'wad', type: 'uint256' } 249 | ], 250 | name: 'pull', 251 | outputs: [], 252 | payable: false, 253 | stateMutability: 'nonpayable', 254 | type: 'function' 255 | }, 256 | { 257 | inputs: [{ name: 'symbol_', type: 'bytes32' }], 258 | payable: false, 259 | stateMutability: 'nonpayable', 260 | type: 'constructor' 261 | }, 262 | { 263 | anonymous: false, 264 | inputs: [ 265 | { indexed: true, name: 'guy', type: 'address' }, 266 | { indexed: false, name: 'wad', type: 'uint256' } 267 | ], 268 | name: 'Mint', 269 | type: 'event' 270 | }, 271 | { 272 | anonymous: false, 273 | inputs: [ 274 | { indexed: true, name: 'guy', type: 'address' }, 275 | { indexed: false, name: 'wad', type: 'uint256' } 276 | ], 277 | name: 'Burn', 278 | type: 'event' 279 | }, 280 | { 281 | anonymous: false, 282 | inputs: [{ indexed: true, name: 'authority', type: 'address' }], 283 | name: 'LogSetAuthority', 284 | type: 'event' 285 | }, 286 | { 287 | anonymous: false, 288 | inputs: [{ indexed: true, name: 'owner', type: 'address' }], 289 | name: 'LogSetOwner', 290 | type: 'event' 291 | }, 292 | { 293 | anonymous: true, 294 | inputs: [ 295 | { indexed: true, name: 'sig', type: 'bytes4' }, 296 | { indexed: true, name: 'guy', type: 'address' }, 297 | { indexed: true, name: 'foo', type: 'bytes32' }, 298 | { indexed: true, name: 'bar', type: 'bytes32' }, 299 | { indexed: false, name: 'wad', type: 'uint256' }, 300 | { indexed: false, name: 'fax', type: 'bytes' } 301 | ], 302 | name: 'LogNote', 303 | type: 'event' 304 | }, 305 | { 306 | anonymous: false, 307 | inputs: [ 308 | { indexed: true, name: 'src', type: 'address' }, 309 | { indexed: true, name: 'guy', type: 'address' }, 310 | { indexed: false, name: 'wad', type: 'uint256' } 311 | ], 312 | name: 'Approval', 313 | type: 'event' 314 | }, 315 | { 316 | anonymous: false, 317 | inputs: [ 318 | { indexed: true, name: 'src', type: 'address' }, 319 | { indexed: true, name: 'dst', type: 'address' }, 320 | { indexed: false, name: 'wad', type: 'uint256' } 321 | ], 322 | name: 'Transfer', 323 | type: 'event' 324 | } 325 | ]; 326 | -------------------------------------------------------------------------------- /test/abi/sbtc.json: -------------------------------------------------------------------------------- 1 | [{"constant":true,"inputs":[],"name":"name","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_owner","type":"address"}],"name":"nominateNewOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"from","type":"address"},{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"decimals","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"nominatedOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_target","type":"address"}],"name":"setTarget","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"acceptOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"callData","type":"bytes"},{"name":"numTopics","type":"uint256"},{"name":"topic1","type":"bytes32"},{"name":"topic2","type":"bytes32"},{"name":"topic3","type":"bytes32"},{"name":"topic4","type":"bytes32"}],"name":"_emit","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"useDELEGATECALL","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"symbol","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"value","type":"bool"}],"name":"setUseDELEGATECALL","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"target","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"},{"name":"spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_owner","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"newTarget","type":"address"}],"name":"TargetUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"newOwner","type":"address"}],"name":"OwnerNominated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"oldOwner","type":"address"},{"indexed":false,"name":"newOwner","type":"address"}],"name":"OwnerChanged","type":"event"}] 2 | -------------------------------------------------------------------------------- /test/abi/synthetixStaking.json: -------------------------------------------------------------------------------- 1 | [{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_rewardsDistribution","type":"address"},{"internalType":"address","name":"_rewardsToken","type":"address"},{"internalType":"address","name":"_stakingToken","type":"address"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldOwner","type":"address"},{"indexed":false,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnerChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnerNominated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Recovered","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"}],"name":"RewardAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"reward","type":"uint256"}],"name":"RewardPaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Staked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Withdrawn","type":"event"},{"constant":true,"inputs":[],"name":"DURATION","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"acceptOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"earned","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"exit","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"getReward","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"getRewardForDuration","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"lastTimeRewardApplicable","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"lastUpdateTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_owner","type":"address"}],"name":"nominateNewOwner","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"nominatedOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"reward","type":"uint256"}],"name":"notifyRewardAmount","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"periodFinish","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"tokenAmount","type":"uint256"}],"name":"recoverERC20","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"rewardPerToken","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"rewardPerTokenStored","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"rewardRate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"rewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"rewardsDistribution","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"rewardsToken","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"_rewardsDistribution","type":"address"}],"name":"setRewardsDistribution","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"stake","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"stakingToken","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"userRewardPerTokenPaid","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdraw","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}] 2 | -------------------------------------------------------------------------------- /test/dai.js: -------------------------------------------------------------------------------- 1 | // const { BN, ether, balance } = require('openzeppelin-test-helpers'); 2 | // const { expect } = require('chai'); 3 | // const { asyncForEach } = require('./utils'); 4 | 5 | // // ABI 6 | // const daiABI = require('./abi/dai'); 7 | 8 | // // userAddress must be unlocked using --unlock ADDRESS 9 | // const userAddress = '0x9eb7f2591ed42dee9315b6e2aaf21ba85ea69f8c'; 10 | // const daiAddress = '0x6b175474e89094c44da98b954eedeac495271d0f'; 11 | // const daiContract = new web3.eth.Contract(daiABI, daiAddress); 12 | 13 | // contract('Truffle Mint DAI', async accounts => { 14 | // it('should send ether to the DAI address', async () => { 15 | // // Send 0.1 eth to userAddress to have gas to send an ERC20 tx. 16 | // await web3.eth.sendTransaction({ 17 | // from: accounts[0], 18 | // to: userAddress, 19 | // value: ether('0.1') 20 | // }); 21 | // const ethBalance = await balance.current(userAddress); 22 | // expect(new BN(ethBalance)).to.be.bignumber.least(new BN(ether('0.1'))); 23 | // }); 24 | 25 | // it('should mint DAI for our first 5 generated accounts', async () => { 26 | // // Get 100 DAI for first 5 accounts 27 | // await asyncForEach(accounts.slice(0, 5), async account => { 28 | // // daiAddress is passed to ganache-cli with flag `--unlock` 29 | // // so we can use the `transfer` method 30 | // await daiContract.methods 31 | // .transfer(account, ether('100').toString()) 32 | // .send({ from: userAddress, gasLimit: 800000 }); 33 | // const daiBalance = await daiContract.methods.balanceOf(account).call(); 34 | // expect(new BN(daiBalance)).to.be.bignumber.least(ether('100')); 35 | // }); 36 | // }); 37 | // }); 38 | 39 | 40 | // contract('Truffle Approve DAI', async accounts => { 41 | 42 | // it('should mint DAI for our first 5 generated accounts', async () => { 43 | // // Get 100 DAI for first 5 accounts 44 | // await asyncForEach(accounts.slice(0, 5), async account => { 45 | // // daiAddress is passed to ganache-cli with flag `--unlock` 46 | // // so we can use the `transfer` method 47 | // await daiContract.methods 48 | // .approve('0xDCa32D06633e49F4731cF473587691355F24476a', "1000000000000000000000000000") 49 | // .send({ from: account, gasLimit: 800000 }); 50 | 51 | // console.log(await daiContract.methods.allowance(account, '0xA5407eAE9Ba41422680e2e00537571bcC53efBfD').call()) 52 | // }); 53 | // }); 54 | // }); -------------------------------------------------------------------------------- /test/oneProto.js: -------------------------------------------------------------------------------- 1 | const { 2 | BN, // Big Number support 3 | expectEvent, // Assertions for emitted events 4 | expectRevert, // Assertions for transactions that should fail 5 | balance, 6 | ether 7 | } = require('@openzeppelin/test-helpers'); 8 | 9 | const MockContract = artifacts.require("MockContract"); 10 | const MockConnectOne = artifacts.require('MockConnectOne'); 11 | const erc20ABI = require("./abi/erc20.js"); 12 | const oneProto = require("./abi/1proto.json"); 13 | 14 | contract('ConnectOneProto', async accounts => { 15 | const [sender, receiver] = accounts; 16 | let mock, mockConnectOneProto, oneProtoContract, sellToken, buyToken, sellAmt; 17 | 18 | before(async function () { 19 | mock = await MockContract.new(); 20 | mockConnectOneProto = await MockConnectOne.new(mock.address); 21 | oneProtoContract = new web3.eth.Contract(oneProto, mock.address); 22 | sellToken = new web3.eth.Contract(erc20ABI, mock.address); 23 | buyToken = new web3.eth.Contract(erc20ABI, mock.address); 24 | sellAmt = String(20 * 10 ** 18); 25 | 26 | 27 | // mocking balanceOf 28 | let balanceOf = await sellToken.methods.balanceOf(mockConnectOneProto.address).encodeABI(); 29 | await mock.givenMethodReturnUint(balanceOf, sellAmt); 30 | 31 | // mocking balanceOf 32 | let decimals = await sellToken.methods.decimals().encodeABI(); 33 | await mock.givenMethodReturnUint(decimals, 18); 34 | 35 | // mocking balanceOf 36 | let decimalsBuy = await buyToken.methods.decimals().encodeABI(); 37 | await mock.givenMethodReturnUint(decimalsBuy, 18); 38 | 39 | // mocking approve 40 | let approve = await sellToken.methods.approve(mockConnectOneProto.address, sellAmt).encodeABI(); 41 | await mock.givenMethodReturnBool(approve, "true"); 42 | 43 | }) 44 | 45 | it('can sell DAI <> USDC', async function() { 46 | let getExpectedReturn = await oneProtoContract.methods.getExpectedReturn( 47 | mock.address, 48 | mock.address, 49 | sellAmt, 50 | 5, 51 | 0 52 | ).encodeABI(); 53 | await mock.givenMethodReturn(getExpectedReturn, web3.eth.abi.encodeParameters(["uint256", "uint256[]"], [20000, [0,0,0,1]])); 54 | // mocking stake 55 | let swapWithReferral = await oneProtoContract.methods.swapWithReferral( 56 | mock.address, 57 | mock.address, 58 | sellAmt, 59 | 1, 60 | [0,1,0], 61 | 0, 62 | mock.address, 63 | 0 64 | ).encodeABI(); 65 | await mock.givenMethodReturnBool(swapWithReferral, "true"); 66 | 67 | const tx = await mockConnectOneProto.sell( 68 | mock.address, 69 | mock.address, 70 | sellAmt, 71 | String(99 * 10 ** 16), 72 | 0, 73 | 0 74 | ) 75 | let obj = { 76 | buyAmt: 100000 77 | }; 78 | expectEvent(tx, "LogSell", obj); 79 | }); 80 | 81 | // it('can withdraw', async function() { 82 | // // mocking withdraw 83 | // let withdraw = await stakingContract.methods.withdraw(10000000).encodeABI(); 84 | // await mock.givenMethodReturnBool(withdraw, "true"); 85 | // // mocking getReward 86 | // let reward = await stakingContract.methods.getReward().encodeABI(); 87 | // await mock.givenMethodReturnBool(reward, "true"); 88 | 89 | // const tx = await mockSynthetixStaking.withdraw( 90 | // "snx", 91 | // 10000000, 92 | // 0, 93 | // 111, 94 | // 112 95 | // ) 96 | // expectEvent(tx, "LogWithdraw"); 97 | // expectEvent(tx, "LogClaimedReward"); 98 | // }); 99 | 100 | // it('can claim reward', async function() { 101 | // // mocking getReward 102 | // let reward = await stakingContract.methods.getReward().encodeABI(); 103 | // await mock.givenMethodReturnBool(reward, "true"); 104 | // const tx = await mockSynthetixStaking.claimReward( 105 | // "snx", 106 | // 112 107 | // ) 108 | // expectEvent(tx, "LogClaimedReward"); 109 | // }); 110 | 111 | // it('cannot deposit if pool removed', async function() { 112 | // mockInstaMapping.removeStakingMapping('snx', mock.address); 113 | // // mocking stake 114 | // let stake = await stakingContract.methods.stake(10000000).encodeABI(); 115 | // await mock.givenMethodReturnBool(stake, "true"); 116 | 117 | // const tx = mockSynthetixStaking.deposit( 118 | // "snx", 119 | // 10000000, 120 | // 0, 121 | // 0 122 | // ) 123 | // expectRevert(tx, "Wrong Staking Name"); 124 | // }); 125 | 126 | }) 127 | -------------------------------------------------------------------------------- /test/utils.js: -------------------------------------------------------------------------------- 1 | module.exports.asyncForEach = async (array, callback) => { 2 | for (let index = 0; index < array.length; index++) { 3 | await callback(array[index], index, array); 4 | } 5 | }; 6 | -------------------------------------------------------------------------------- /truffle-config.js: -------------------------------------------------------------------------------- 1 | const HDWalletProvider = require('truffle-hdwallet-provider'); 2 | const dotenv = require('dotenv'); 3 | dotenv.config(); 4 | 5 | const infuraKey = process.env.infura_key; 6 | const mnemonic = process.env.mnemonic_key; 7 | module.exports = { 8 | plugins: [ 9 | 'truffle-plugin-verify', 10 | ], 11 | api_keys: { 12 | etherscan: process.env.etherscan_key 13 | }, 14 | 15 | networks: { 16 | development: { 17 | host: "127.0.0.1", 18 | port: 8545, 19 | network_id: "*", 20 | }, 21 | 22 | proxy: { 23 | host: "127.0.0.1", 24 | port: 9545, 25 | network_id: "*", 26 | }, 27 | 28 | live: { 29 | provider: () => new HDWalletProvider(mnemonic, `https://mainnet.infura.io/v3/${infuraKey}`), 30 | network_id: 1, 31 | gasPrice: 6000000001, 32 | skipDryRun: true 33 | }, 34 | 35 | ropsten: { 36 | provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/${infuraKey}`), 37 | network_id: 3, // Ropsten's id 38 | gas: 5500000, // Ropsten has a lower block limit than mainnet 39 | confirmations: 2, // # of confs to wait between deployments. (default: 0) 40 | timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50) 41 | skipDryRun: true // Skip dry run before migrations? (default: false for public nets ) 42 | }, 43 | 44 | kovan: { 45 | provider: () => new HDWalletProvider(mnemonic, `https://kovan.infura.io/v3/${infuraKey}`), 46 | network_id: 42, // kovan's id 47 | gas: 3716887, // kovan has a lower block limit than mainnet 48 | confirmations: 2, // # of confs to wait between deployments. (default: 0) 49 | timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50) 50 | skipDryRun: true // Skip dry run before migrations? (default: false for public nets ) 51 | }, 52 | }, 53 | 54 | // Set default mocha options here, use special reporters etc. 55 | mocha: { 56 | timeout: 100000 57 | }, 58 | 59 | // Configure your compilers 60 | compilers: { 61 | solc: { 62 | version: "v0.6.2", 63 | settings: { 64 | optimizer: { 65 | enabled: true, 66 | }, 67 | // evmVersion: "istanbul" 68 | } 69 | } 70 | } 71 | } 72 | --------------------------------------------------------------------------------