├── .env.example ├── .gitattributes ├── .github └── workflows │ └── run-tests.yml ├── .gitignore ├── .solcover.ts ├── README.md ├── audits ├── v1_PeckShield_Mar_2020.pdf ├── v1_samczsun_Mar_2020.md └── v2_PeckShield_Mar_2021.pdf ├── contracts ├── registry │ ├── index.sol │ └── list.sol ├── v1 │ ├── account.sol │ ├── connectors.sol │ ├── connectors │ │ ├── auth.sol │ │ └── basic.sol │ ├── event.sol │ ├── memory.sol │ └── test │ │ ├── InstaAccountV3.test.sol │ │ ├── InstaAccountV4.test.sol │ │ ├── check.test.sol │ │ ├── connector.registry.test.sol │ │ └── staticConnector.test.sol └── v2 │ ├── accounts │ ├── default │ │ ├── implementation_default.sol │ │ └── readme.md │ ├── module1 │ │ ├── Implementation_m1.sol │ │ └── readme.md │ ├── test │ │ ├── ERC1155.token.test.sol │ │ ├── ImplementationBetaTest.sol │ │ ├── Implementation_m2.test.sol │ │ ├── Implmentation_account.test.sol │ │ ├── NFT.test.sol │ │ └── implementation_default.v2.test.sol │ └── variables.sol │ ├── connectors │ └── test │ │ ├── auth.test.sol │ │ ├── betamode.test.sol │ │ ├── compound.test.sol │ │ ├── connector.registry.test.sol │ │ └── emitEvent.test.sol │ ├── proxy │ ├── accountProxy.sol │ ├── connectorsProxy.sol │ └── dummyConnectorsImpl.sol │ ├── registry │ ├── connectors.sol │ └── implementations.sol │ └── timelock │ ├── chiefTimelock.sol │ └── timelock.sol ├── docs └── addresses.json ├── hardhat.config.ts ├── package-lock.json ├── package.json ├── scripts ├── constant │ ├── abi │ │ ├── basics │ │ │ └── erc20.json │ │ ├── connectors │ │ │ ├── auth.json │ │ │ ├── basic.json │ │ │ ├── compound.json │ │ │ ├── maker.json │ │ │ └── uniswap.json │ │ └── read │ │ │ ├── compound.json │ │ │ ├── core.json │ │ │ ├── erc20.json │ │ │ ├── maker.json │ │ │ └── uniswap.json │ ├── abis.ts │ ├── addresses.ts │ └── tokens.ts ├── deployAll.ts ├── deployChiefTimelock.ts ├── deployConnector.ts ├── deployConnectors.ts ├── deployContract.ts ├── deployContracts.ts ├── deployTimelock.ts ├── deploy_v2.ts ├── enableConnector.ts ├── encodeSpells.ts ├── expectEvent.ts ├── flatten.sh ├── getMasterSigner.ts └── spells │ └── addAuth.ts ├── test ├── README.md ├── betamode.test.ts ├── core.test.ts ├── insta-index.test.ts ├── insta-list.test.ts ├── mainnet.test.ts ├── v1.test.ts ├── v2.proxy.default.test.ts └── v2.test.ts └── tsconfig.json /.env.example: -------------------------------------------------------------------------------- 1 | ALCHEMY_ID="" 2 | ETHERSCAN="" 3 | PRIVATE_KEY=" Connectors Registry Module Address). 35 | mapping (uint => address) public connectors; 36 | // Check Modules(Account Module Version => Check Module Address). 37 | mapping (uint => address) public check; 38 | // Account Modules(Account Module Version => Account Module Address). 39 | mapping (uint => address) public account; 40 | // Version Count of Account Modules. 41 | uint public versionCount; 42 | 43 | /** 44 | * @dev Throws if the sender not is Master Address. 45 | */ 46 | modifier isMaster() { 47 | require(msg.sender == master, "not-master"); 48 | _; 49 | } 50 | 51 | /** 52 | * @dev Change the Master Address. 53 | * @param _newMaster New Master Address. 54 | */ 55 | function changeMaster(address _newMaster) external isMaster { 56 | require(_newMaster != master, "already-a-master"); 57 | require(_newMaster != address(0), "not-valid-address"); 58 | require(newMaster != _newMaster, "already-a-new-master"); 59 | newMaster = _newMaster; 60 | emit LogNewMaster(_newMaster); 61 | } 62 | 63 | function updateMaster() external { 64 | require(newMaster != address(0), "not-valid-address"); 65 | require(msg.sender == newMaster, "not-master"); 66 | master = newMaster; 67 | newMaster = address(0); 68 | emit LogUpdateMaster(master); 69 | } 70 | 71 | /** 72 | * @dev Change the Check Address of a specific Account Module version. 73 | * @param accountVersion Account Module version. 74 | * @param _newCheck The New Check Address. 75 | */ 76 | function changeCheck(uint accountVersion, address _newCheck) external isMaster { 77 | require(_newCheck != check[accountVersion], "already-a-check"); 78 | check[accountVersion] = _newCheck; 79 | emit LogNewCheck(accountVersion, _newCheck); 80 | } 81 | 82 | /** 83 | * @dev Add New Account Module. 84 | * @param _newAccount The New Account Module Address. 85 | * @param _connectors Connectors Registry Module Address. 86 | * @param _check Check Module Address. 87 | */ 88 | function addNewAccount(address _newAccount, address _connectors, address _check) external isMaster { 89 | require(_newAccount != address(0), "not-valid-address"); 90 | versionCount++; 91 | require(AccountInterface(_newAccount).version() == versionCount, "not-valid-version"); 92 | account[versionCount] = _newAccount; 93 | if (_connectors != address(0)) connectors[versionCount] = _connectors; 94 | if (_check != address(0)) check[versionCount] = _check; 95 | emit LogNewAccount(_newAccount, _connectors, _check); 96 | } 97 | 98 | } 99 | 100 | contract CloneFactory is AddressIndex { 101 | /** 102 | * @dev Clone a new Account Module. 103 | * @param version Account Module version to clone. 104 | */ 105 | function createClone(uint version) internal returns (address result) { 106 | bytes20 targetBytes = bytes20(account[version]); 107 | // solium-disable-next-line security/no-inline-assembly 108 | assembly { 109 | let clone := mload(0x40) 110 | mstore(clone, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000) 111 | mstore(add(clone, 0x14), targetBytes) 112 | mstore(add(clone, 0x28), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000) 113 | result := create(0, clone, 0x37) 114 | } 115 | } 116 | 117 | /** 118 | * @dev Check if Account Module is a clone. 119 | * @param version Account Module version. 120 | * @param query Account Module Address. 121 | */ 122 | function isClone(uint version, address query) external view returns (bool result) { 123 | bytes20 targetBytes = bytes20(account[version]); 124 | // solium-disable-next-line security/no-inline-assembly 125 | assembly { 126 | let clone := mload(0x40) 127 | mstore(clone, 0x363d3d373d3d3d363d7300000000000000000000000000000000000000000000) 128 | mstore(add(clone, 0xa), targetBytes) 129 | mstore(add(clone, 0x1e), 0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000) 130 | 131 | let other := add(clone, 0x40) 132 | extcodecopy(query, other, 0, 0x2d) 133 | result := and( 134 | eq(mload(clone), mload(other)), 135 | eq(mload(add(clone, 0xd)), mload(add(other, 0xd))) 136 | ) 137 | } 138 | } 139 | } 140 | 141 | contract InstaIndex is CloneFactory { 142 | 143 | event LogAccountCreated(address sender, address indexed owner, address indexed account, address indexed origin); 144 | 145 | /** 146 | * @dev Create a new DeFi Smart Account for a user and run cast function in the new Smart Account. 147 | * @param _owner Owner of the Smart Account. 148 | * @param accountVersion Account Module version. 149 | * @param _targets Array of Target to run cast function. 150 | * @param _datas Array of Data(callData) to run cast function. 151 | * @param _origin Where Smart Account is created. 152 | */ 153 | function buildWithCast( 154 | address _owner, 155 | uint accountVersion, 156 | address[] calldata _targets, 157 | bytes[] calldata _datas, 158 | address _origin 159 | ) external payable returns (address _account) { 160 | _account = build(_owner, accountVersion, _origin); 161 | if (_targets.length > 0) AccountInterface(_account).cast{value: msg.value}(_targets, _datas, _origin); 162 | } 163 | 164 | /** 165 | * @dev Create a new DeFi Smart Account for a user. 166 | * @param _owner Owner of the Smart Account. 167 | * @param accountVersion Account Module version. 168 | * @param _origin Where Smart Account is created. 169 | */ 170 | function build( 171 | address _owner, 172 | uint accountVersion, 173 | address _origin 174 | ) public returns (address _account) { 175 | require(accountVersion != 0 && accountVersion <= versionCount, "not-valid-account"); 176 | _account = createClone(accountVersion); 177 | ListInterface(list).init(_account); 178 | AccountInterface(_account).enable(_owner); 179 | emit LogAccountCreated(msg.sender, _owner, _account, _origin); 180 | } 181 | 182 | /** 183 | * @dev Setup Initial things for InstaIndex, after its been deployed and can be only run once. 184 | * @param _master The Master Address. 185 | * @param _list The List Address. 186 | * @param _account The Account Module Address. 187 | * @param _connectors The Connectors Registry Module Address. 188 | */ 189 | function setBasics( 190 | address _master, 191 | address _list, 192 | address _account, 193 | address _connectors 194 | ) external { 195 | require( 196 | master == address(0) && 197 | list == address(0) && 198 | account[1] == address(0) && 199 | connectors[1] == address(0) && 200 | versionCount == 0, 201 | "already-defined" 202 | ); 203 | master = _master; 204 | list = _list; 205 | versionCount++; 206 | account[versionCount] = _account; 207 | connectors[versionCount] = _connectors; 208 | } 209 | 210 | } -------------------------------------------------------------------------------- /contracts/registry/list.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.0; 2 | 3 | /** 4 | * @title InstaList 5 | * @dev Registry For DeFi Smart Account Authorised user. 6 | */ 7 | 8 | interface AccountInterface { 9 | function isAuth(address _user) external view returns (bool); 10 | } 11 | 12 | 13 | contract DSMath { 14 | 15 | function add(uint64 x, uint64 y) internal pure returns (uint64 z) { 16 | require((z = x + y) >= x, "ds-math-add-overflow"); 17 | } 18 | 19 | function sub(uint64 x, uint64 y) internal pure returns (uint64 z) { 20 | require((z = x - y) <= x, "ds-math-sub-underflow"); 21 | } 22 | 23 | } 24 | 25 | 26 | contract Variables is DSMath { 27 | 28 | // InstaIndex Address. 29 | address public immutable instaIndex; 30 | 31 | constructor (address _instaIndex) { 32 | instaIndex = _instaIndex; 33 | } 34 | 35 | // Smart Account Count. 36 | uint64 public accounts; 37 | // Smart Account ID (Smart Account Address => Account ID). 38 | mapping (address => uint64) public accountID; 39 | // Smart Account Address (Smart Account ID => Smart Account Address). 40 | mapping (uint64 => address) public accountAddr; 41 | 42 | // User Link (User Address => UserLink(Account ID of First and Last And Count of Smart Accounts)). 43 | mapping (address => UserLink) public userLink; 44 | // Linked List of Users (User Address => Smart Account ID => UserList(Previous and next Account ID)). 45 | mapping (address => mapping(uint64 => UserList)) public userList; 46 | 47 | struct UserLink { 48 | uint64 first; 49 | uint64 last; 50 | uint64 count; 51 | } 52 | struct UserList { 53 | uint64 prev; 54 | uint64 next; 55 | } 56 | 57 | // Account Link (Smart Account ID => AccountLink). 58 | mapping (uint64 => AccountLink) public accountLink; // account => account linked list connection 59 | // Linked List of Accounts (Smart Account ID => Account Address => AccountList). 60 | mapping (uint64 => mapping (address => AccountList)) public accountList; // account => user address => list 61 | 62 | struct AccountLink { 63 | address first; 64 | address last; 65 | uint64 count; 66 | } 67 | struct AccountList { 68 | address prev; 69 | address next; 70 | } 71 | 72 | } 73 | 74 | contract Configure is Variables { 75 | 76 | constructor (address _instaIndex) Variables(_instaIndex) { 77 | } 78 | 79 | /** 80 | * @dev Add Account to User Linked List. 81 | * @param _owner Account Owner. 82 | * @param _account Smart Account Address. 83 | */ 84 | function addAccount(address _owner, uint64 _account) internal { 85 | if (userLink[_owner].last != 0) { 86 | userList[_owner][_account].prev = userLink[_owner].last; 87 | userList[_owner][userLink[_owner].last].next = _account; 88 | } 89 | if (userLink[_owner].first == 0) userLink[_owner].first = _account; 90 | userLink[_owner].last = _account; 91 | userLink[_owner].count = add(userLink[_owner].count, 1); 92 | } 93 | 94 | /** 95 | * @dev Remove Account from User Linked List. 96 | * @param _owner Account Owner/User. 97 | * @param _account Smart Account Address. 98 | */ 99 | function removeAccount(address _owner, uint64 _account) internal { 100 | uint64 _prev = userList[_owner][_account].prev; 101 | uint64 _next = userList[_owner][_account].next; 102 | if (_prev != 0) userList[_owner][_prev].next = _next; 103 | if (_next != 0) userList[_owner][_next].prev = _prev; 104 | if (_prev == 0) userLink[_owner].first = _next; 105 | if (_next == 0) userLink[_owner].last = _prev; 106 | userLink[_owner].count = sub(userLink[_owner].count, 1); 107 | delete userList[_owner][_account]; 108 | } 109 | 110 | /** 111 | * @dev Add Owner to Account Linked List. 112 | * @param _owner Account Owner. 113 | * @param _account Smart Account Address. 114 | */ 115 | function addUser(address _owner, uint64 _account) internal { 116 | if (accountLink[_account].last != address(0)) { 117 | accountList[_account][_owner].prev = accountLink[_account].last; 118 | accountList[_account][accountLink[_account].last].next = _owner; 119 | } 120 | if (accountLink[_account].first == address(0)) accountLink[_account].first = _owner; 121 | accountLink[_account].last = _owner; 122 | accountLink[_account].count = add(accountLink[_account].count, 1); 123 | } 124 | 125 | /** 126 | * @dev Remove Owner from Account Linked List. 127 | * @param _owner Account Owner. 128 | * @param _account Smart Account Address. 129 | */ 130 | function removeUser(address _owner, uint64 _account) internal { 131 | address _prev = accountList[_account][_owner].prev; 132 | address _next = accountList[_account][_owner].next; 133 | if (_prev != address(0)) accountList[_account][_prev].next = _next; 134 | if (_next != address(0)) accountList[_account][_next].prev = _prev; 135 | if (_prev == address(0)) accountLink[_account].first = _next; 136 | if (_next == address(0)) accountLink[_account].last = _prev; 137 | accountLink[_account].count = sub(accountLink[_account].count, 1); 138 | delete accountList[_account][_owner]; 139 | } 140 | 141 | } 142 | 143 | contract InstaList is Configure { 144 | constructor (address _instaIndex) public Configure(_instaIndex) {} 145 | 146 | 147 | /** 148 | * @dev Enable Auth for Smart Account. 149 | * @param _owner Owner Address. 150 | */ 151 | function addAuth(address _owner) external { 152 | require(accountID[msg.sender] != 0, "not-account"); 153 | require(AccountInterface(msg.sender).isAuth(_owner), "not-owner"); 154 | addAccount(_owner, accountID[msg.sender]); 155 | addUser(_owner, accountID[msg.sender]); 156 | } 157 | 158 | /** 159 | * @dev Disable Auth for Smart Account. 160 | * @param _owner Owner Address. 161 | */ 162 | function removeAuth(address _owner) external { 163 | require(accountID[msg.sender] != 0, "not-account"); 164 | require(!AccountInterface(msg.sender).isAuth(_owner), "already-owner"); 165 | removeAccount(_owner, accountID[msg.sender]); 166 | removeUser(_owner, accountID[msg.sender]); 167 | } 168 | 169 | /** 170 | * @dev Setup Initial configuration of Smart Account. 171 | * @param _account Smart Account Address. 172 | */ 173 | function init(address _account) external { 174 | require(msg.sender == instaIndex, "not-index"); 175 | accounts++; 176 | accountID[_account] = accounts; 177 | accountAddr[accounts] = _account; 178 | } 179 | 180 | } -------------------------------------------------------------------------------- /contracts/v1/account.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.0; 2 | pragma experimental ABIEncoderV2; 3 | 4 | /** 5 | * @title InstaAccount. 6 | * @dev DeFi Smart Account Wallet. 7 | */ 8 | 9 | interface IndexInterface { 10 | function connectors(uint version) external view returns (address); 11 | function check(uint version) external view returns (address); 12 | function list() external view returns (address); 13 | } 14 | 15 | interface ConnectorsInterface { 16 | function isConnector(address[] calldata logicAddr) external view returns (bool); 17 | function isStaticConnector(address[] calldata logicAddr) external view returns (bool); 18 | } 19 | 20 | interface CheckInterface { 21 | function isOk() external view returns (bool); 22 | } 23 | 24 | interface ListInterface { 25 | function addAuth(address user) external; 26 | function removeAuth(address user) external; 27 | } 28 | 29 | 30 | contract Record { 31 | 32 | event LogEnable(address indexed user); 33 | event LogDisable(address indexed user); 34 | event LogSwitchShield(bool _shield); 35 | 36 | // InstaIndex Address. 37 | address public immutable instaIndex; 38 | // The Account Module Version. 39 | uint public constant version = 1; 40 | // Auth Module(Address of Auth => bool). 41 | mapping (address => bool) private auth; 42 | // Is shield true/false. 43 | bool public shield; 44 | 45 | constructor (address _instaIndex) { 46 | instaIndex = _instaIndex; 47 | } 48 | 49 | /** 50 | * @dev Check for Auth if enabled. 51 | * @param user address/user/owner. 52 | */ 53 | function isAuth(address user) public view returns (bool) { 54 | return auth[user]; 55 | } 56 | 57 | /** 58 | * @dev Change Shield State. 59 | */ 60 | function switchShield(bool _shield) external { 61 | require(auth[msg.sender], "not-self"); 62 | require(shield != _shield, "shield is set"); 63 | shield = _shield; 64 | emit LogSwitchShield(shield); 65 | } 66 | 67 | /** 68 | * @dev Enable New User. 69 | * @param user Owner of the Smart Account. 70 | */ 71 | function enable(address user) public { 72 | require(msg.sender == address(this) || msg.sender == instaIndex, "not-self-index"); 73 | require(user != address(0), "not-valid"); 74 | require(!auth[user], "already-enabled"); 75 | auth[user] = true; 76 | ListInterface(IndexInterface(instaIndex).list()).addAuth(user); 77 | emit LogEnable(user); 78 | } 79 | 80 | /** 81 | * @dev Disable User. 82 | * @param user Owner of the Smart Account. 83 | */ 84 | function disable(address user) public { 85 | require(msg.sender == address(this), "not-self"); 86 | require(user != address(0), "not-valid"); 87 | require(auth[user], "already-disabled"); 88 | delete auth[user]; 89 | ListInterface(IndexInterface(instaIndex).list()).removeAuth(user); 90 | emit LogDisable(user); 91 | } 92 | 93 | } 94 | 95 | contract InstaAccount is Record { 96 | 97 | constructor (address _instaIndex) public Record(_instaIndex) { 98 | } 99 | 100 | event LogCast(address indexed origin, address indexed sender, uint value); 101 | 102 | receive() external payable {} 103 | 104 | /** 105 | * @dev Delegate the calls to Connector And this function is ran by cast(). 106 | * @param _target Target to of Connector. 107 | * @param _data CallData of function in Connector. 108 | */ 109 | function spell(address _target, bytes memory _data) internal { 110 | require(_target != address(0), "target-invalid"); 111 | assembly { 112 | let succeeded := delegatecall(gas(), _target, add(_data, 0x20), mload(_data), 0, 0) 113 | 114 | switch iszero(succeeded) 115 | case 1 { 116 | // throw if delegatecall failed 117 | let size := returndatasize() 118 | returndatacopy(0x00, 0x00, size) 119 | revert(0x00, size) 120 | } 121 | } 122 | } 123 | 124 | /** 125 | * @dev This is the main function, Where all the different functions are called 126 | * from Smart Account. 127 | * @param _targets Array of Target(s) to of Connector. 128 | * @param _datas Array of Calldata(S) of function. 129 | */ 130 | function cast( 131 | address[] calldata _targets, 132 | bytes[] calldata _datas, 133 | address _origin 134 | ) 135 | external 136 | payable 137 | { 138 | require(isAuth(msg.sender) || msg.sender == instaIndex, "permission-denied"); 139 | require(_targets.length == _datas.length , "array-length-invalid"); 140 | IndexInterface indexContract = IndexInterface(instaIndex); 141 | bool isShield = shield; 142 | if (!isShield) { 143 | require(ConnectorsInterface(indexContract.connectors(version)).isConnector(_targets), "not-connector"); 144 | } else { 145 | require(ConnectorsInterface(indexContract.connectors(version)).isStaticConnector(_targets), "not-static-connector"); 146 | } 147 | for (uint i = 0; i < _targets.length; i++) { 148 | spell(_targets[i], _datas[i]); 149 | } 150 | address _check = indexContract.check(version); 151 | if (_check != address(0) && !isShield) require(CheckInterface(_check).isOk(), "not-ok"); 152 | emit LogCast(_origin, msg.sender, msg.value); 153 | } 154 | 155 | } -------------------------------------------------------------------------------- /contracts/v1/connectors.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.0; 2 | 3 | /** 4 | * @title InstaConnectors 5 | * @dev Registry for Connectors. 6 | */ 7 | 8 | 9 | interface IndexInterface { 10 | function master() external view returns (address); 11 | } 12 | 13 | interface ConnectorInterface { 14 | function connectorID() external view returns(uint _type, uint _id); 15 | function name() external view returns (string memory); 16 | } 17 | 18 | 19 | contract DSMath { 20 | 21 | function add(uint x, uint y) internal pure returns (uint z) { 22 | require((z = x + y) >= x, "ds-math-add-overflow"); 23 | } 24 | 25 | function sub(uint x, uint y) internal pure returns (uint z) { 26 | require((z = x - y) <= x, "ds-math-sub-underflow"); 27 | } 28 | 29 | } 30 | 31 | contract Controllers is DSMath { 32 | 33 | event LogAddController(address indexed addr); 34 | event LogRemoveController(address indexed addr); 35 | 36 | // InstaIndex Address. 37 | address public immutable instaIndex; 38 | 39 | constructor (address _instaIndex) { 40 | instaIndex = _instaIndex; 41 | } 42 | 43 | // Enabled Chief(Address of Chief => bool). 44 | mapping(address => bool) public chief; 45 | // Enabled Connectors(Connector Address => bool). 46 | mapping(address => bool) public connectors; 47 | // Enabled Static Connectors(Connector Address => bool). 48 | mapping(address => bool) public staticConnectors; 49 | 50 | /** 51 | * @dev Throws if the sender not is Master Address from InstaIndex 52 | * or Enabled Chief. 53 | */ 54 | modifier isChief { 55 | require(chief[msg.sender] || msg.sender == IndexInterface(instaIndex).master(), "not-an-chief"); 56 | _; 57 | } 58 | 59 | /** 60 | * @dev Enable a Chief. 61 | * @param _userAddress Chief Address. 62 | */ 63 | function enableChief(address _userAddress) external isChief { 64 | chief[_userAddress] = true; 65 | emit LogAddController(_userAddress); 66 | } 67 | 68 | /** 69 | * @dev Disables a Chief. 70 | * @param _userAddress Chief Address. 71 | */ 72 | function disableChief(address _userAddress) external isChief { 73 | delete chief[_userAddress]; 74 | emit LogRemoveController(_userAddress); 75 | } 76 | 77 | } 78 | 79 | 80 | contract Listings is Controllers { 81 | 82 | constructor (address _instaIndex) Controllers(_instaIndex) { 83 | } 84 | 85 | // Connectors Array. 86 | address[] public connectorArray; 87 | // Count of Connector's Enabled. 88 | uint public connectorCount; 89 | 90 | /** 91 | * @dev Add Connector to Connector's array. 92 | * @param _connector Connector Address. 93 | **/ 94 | function addToArr(address _connector) internal { 95 | require(_connector != address(0), "Not-valid-connector"); 96 | (, uint _id) = ConnectorInterface(_connector).connectorID(); 97 | require(_id == (connectorArray.length+1),"ConnectorID-doesnt-match"); 98 | ConnectorInterface(_connector).name(); // Checking if connector has function name() 99 | connectorArray.push(_connector); 100 | } 101 | 102 | // Static Connectors Array. 103 | address[] public staticConnectorArray; 104 | 105 | /** 106 | * @dev Add Connector to Static Connector's array. 107 | * @param _connector Static Connector Address. 108 | **/ 109 | function addToArrStatic(address _connector) internal { 110 | require(_connector != address(0), "Not-valid-connector"); 111 | (, uint _id) = ConnectorInterface(_connector).connectorID(); 112 | require(_id == (staticConnectorArray.length+1),"ConnectorID-doesnt-match"); 113 | ConnectorInterface(_connector).name(); // Checking if connector has function name() 114 | staticConnectorArray.push(_connector); 115 | } 116 | 117 | } 118 | 119 | 120 | contract InstaConnectors is Listings { 121 | 122 | constructor (address _instaIndex) public Listings(_instaIndex) { 123 | } 124 | 125 | event LogEnable(address indexed connector); 126 | event LogDisable(address indexed connector); 127 | event LogEnableStatic(address indexed connector); 128 | 129 | /** 130 | * @dev Enable Connector. 131 | * @param _connector Connector Address. 132 | */ 133 | function enable(address _connector) external isChief { 134 | require(!connectors[_connector], "already-enabled"); 135 | addToArr(_connector); 136 | connectors[_connector] = true; 137 | connectorCount++; 138 | emit LogEnable(_connector); 139 | } 140 | /** 141 | * @dev Disable Connector. 142 | * @param _connector Connector Address. 143 | */ 144 | function disable(address _connector) external isChief { 145 | require(connectors[_connector], "already-disabled"); 146 | delete connectors[_connector]; 147 | connectorCount--; 148 | emit LogDisable(_connector); 149 | } 150 | 151 | /** 152 | * @dev Enable Static Connector. 153 | * @param _connector Static Connector Address. 154 | */ 155 | function enableStatic(address _connector) external isChief { 156 | require(!staticConnectors[_connector], "already-enabled"); 157 | addToArrStatic(_connector); 158 | staticConnectors[_connector] = true; 159 | emit LogEnableStatic(_connector); 160 | } 161 | 162 | /** 163 | * @dev Check if Connector addresses are enabled. 164 | * @param _connectors Array of Connector Addresses. 165 | */ 166 | function isConnector(address[] calldata _connectors) external view returns (bool isOk) { 167 | isOk = true; 168 | for (uint i = 0; i < _connectors.length; i++) { 169 | if (!connectors[_connectors[i]]) { 170 | isOk = false; 171 | break; 172 | } 173 | } 174 | } 175 | 176 | /** 177 | * @dev Check if Connector addresses are static enabled. 178 | * @param _connectors Array of Connector Addresses. 179 | */ 180 | function isStaticConnector(address[] calldata _connectors) external view returns (bool isOk) { 181 | isOk = true; 182 | for (uint i = 0; i < _connectors.length; i++) { 183 | if (!staticConnectors[_connectors[i]]) { 184 | isOk = false; 185 | break; 186 | } 187 | } 188 | } 189 | 190 | /** 191 | * @dev get Connector's Array length. 192 | */ 193 | function connectorLength() external view returns (uint) { 194 | return connectorArray.length; 195 | } 196 | 197 | /** 198 | * @dev get Static Connector's Array length. 199 | */ 200 | function staticConnectorLength() external view returns (uint) { 201 | return staticConnectorArray.length; 202 | } 203 | } -------------------------------------------------------------------------------- /contracts/v1/connectors/auth.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.0; 2 | 3 | /** 4 | * @title ConnectAuth. 5 | * @dev Connector For Adding Auth. 6 | */ 7 | 8 | interface AccountInterface { 9 | function enable(address user) external; 10 | function disable(address user) external; 11 | } 12 | 13 | interface EventInterface { 14 | function emitEvent(uint _connectorType, uint _connectorID, bytes32 _eventCode, bytes calldata _eventData) external; 15 | } 16 | 17 | 18 | contract Basics { 19 | 20 | /** 21 | * @dev InstaEvent Address. 22 | */ 23 | address public immutable instaEventAddress; 24 | constructor (address _instaEventAddress) { 25 | instaEventAddress = _instaEventAddress; 26 | } 27 | 28 | /** 29 | * @dev Connector ID and Type. 30 | */ 31 | function connectorID() public pure returns(uint _type, uint _id) { 32 | (_type, _id) = (1, 1); 33 | } 34 | 35 | } 36 | 37 | 38 | contract Auth is Basics { 39 | 40 | constructor (address _instaEventAddress) Basics(_instaEventAddress) {} 41 | 42 | event LogAddAuth(address indexed _msgSender, address indexed _auth); 43 | event LogRemoveAuth(address indexed _msgSender, address indexed _auth); 44 | 45 | /** 46 | * @dev Add New Owner 47 | * @param user User Address. 48 | */ 49 | function addModule(address user) public payable { 50 | AccountInterface(address(this)).enable(user); 51 | 52 | emit LogAddAuth(msg.sender, user); 53 | 54 | bytes32 _eventCode = keccak256("LogAddAuth(address,address)"); 55 | bytes memory _eventParam = abi.encode(msg.sender, user); 56 | (uint _type, uint _id) = connectorID(); 57 | EventInterface(instaEventAddress).emitEvent(_type, _id, _eventCode, _eventParam); 58 | } 59 | 60 | /** 61 | * @dev Remove New Owner 62 | * @param user User Address. 63 | */ 64 | function removeModule(address user) public payable { 65 | AccountInterface(address(this)).disable(user); 66 | 67 | emit LogRemoveAuth(msg.sender, user); 68 | 69 | bytes32 _eventCode = keccak256("LogRemoveAuth(address,address)"); 70 | bytes memory _eventParam = abi.encode(msg.sender, user); 71 | (uint _type, uint _id) = connectorID(); 72 | EventInterface(instaEventAddress).emitEvent(_type, _id, _eventCode, _eventParam); 73 | } 74 | 75 | } 76 | 77 | 78 | contract ConnectAuth is Auth { 79 | 80 | constructor (address _instaEventAddress) public Auth(_instaEventAddress) {} 81 | string constant public name = "Auth-v1"; 82 | } -------------------------------------------------------------------------------- /contracts/v1/connectors/basic.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.0; 2 | 3 | /** 4 | * @title ConnectBasic. 5 | * @dev Connector to deposit/withdraw assets. 6 | */ 7 | 8 | interface ERC20Interface { 9 | function allowance(address, address) external view returns (uint); 10 | function balanceOf(address) external view returns (uint); 11 | function approve(address, uint) external; 12 | function transfer(address, uint) external returns (bool); 13 | function transferFrom(address, address, uint) external returns (bool); 14 | } 15 | 16 | interface AccountInterface { 17 | function isAuth(address _user) external view returns (bool); 18 | } 19 | 20 | interface MemoryInterface { 21 | function getUint(uint _id) external returns (uint _num); 22 | function setUint(uint _id, uint _val) external; 23 | } 24 | 25 | interface EventInterface { 26 | function emitEvent(uint _connectorType, uint _connectorID, bytes32 _eventCode, bytes calldata _eventData) external; 27 | } 28 | 29 | contract Memory { 30 | 31 | /** 32 | * @dev InstaMemory Address. 33 | */ 34 | address public immutable instaMemoryAddress; 35 | 36 | constructor (address _instaMemoryAddress) { 37 | instaMemoryAddress = _instaMemoryAddress; 38 | } 39 | 40 | /** 41 | * @dev Get Stored Uint Value From InstaMemory. 42 | * @param getId Storage ID. 43 | * @param val if any value. 44 | */ 45 | function getUint(uint getId, uint val) internal returns (uint returnVal) { 46 | returnVal = getId == 0 ? val : MemoryInterface(instaMemoryAddress).getUint(getId); 47 | } 48 | 49 | /** 50 | * @dev Store Uint Value In InstaMemory. 51 | * @param setId Storage ID. 52 | * @param val Value To store. 53 | */ 54 | function setUint(uint setId, uint val) internal { 55 | if (setId != 0) MemoryInterface(instaMemoryAddress).setUint(setId, val); 56 | } 57 | 58 | /** 59 | * @dev Connector ID and Type. 60 | */ 61 | function connectorID() public pure returns(uint _type, uint _id) { 62 | (_type, _id) = (1, 2); 63 | } 64 | 65 | } 66 | 67 | contract BasicResolver is Memory { 68 | 69 | event LogDeposit(address indexed erc20, uint256 tokenAmt, uint256 getId, uint256 setId); 70 | event LogWithdraw(address indexed erc20, uint256 tokenAmt, address indexed to, uint256 getId, uint256 setId); 71 | 72 | /** 73 | * @dev InstaEvent Address. 74 | */ 75 | address public immutable instaEventAddress; 76 | 77 | constructor (address _instaEventAddress, address _instaMemoryAddress) Memory(_instaMemoryAddress) { 78 | instaEventAddress = _instaEventAddress; 79 | } 80 | /** 81 | * @dev ETH Address. 82 | */ 83 | function getEthAddr() public pure returns (address) { 84 | return 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; 85 | } 86 | 87 | /** 88 | * @dev Deposit Assets To Smart Account. 89 | * @param erc20 Token Address. 90 | * @param tokenAmt Token Amount. 91 | * @param getId Get Storage ID. 92 | * @param setId Set Storage ID. 93 | */ 94 | function deposit(address erc20, uint tokenAmt, uint getId, uint setId) public payable { 95 | uint amt = getUint(getId, tokenAmt); 96 | if (erc20 != getEthAddr()) { 97 | ERC20Interface token = ERC20Interface(erc20); 98 | amt = amt == uint(-1) ? token.balanceOf(msg.sender) : amt; 99 | token.transferFrom(msg.sender, address(this), amt); 100 | } else { 101 | require(msg.value == amt || amt == uint(-1), "invalid-ether-amount"); 102 | amt = msg.value; 103 | } 104 | setUint(setId, amt); 105 | 106 | emit LogDeposit(erc20, amt, getId, setId); 107 | 108 | bytes32 _eventCode = keccak256("LogDeposit(address,uint256,uint256,uint256)"); 109 | bytes memory _eventParam = abi.encode(erc20, amt, getId, setId); 110 | (uint _type, uint _id) = connectorID(); 111 | EventInterface(instaEventAddress).emitEvent(_type, _id, _eventCode, _eventParam); 112 | } 113 | 114 | /** 115 | * @dev Withdraw Assets To Smart Account. 116 | * @param erc20 Token Address. 117 | * @param tokenAmt Token Amount. 118 | * @param to Withdraw token address. 119 | * @param getId Get Storage ID. 120 | * @param setId Set Storage ID. 121 | */ 122 | function withdraw( 123 | address erc20, 124 | uint tokenAmt, 125 | address payable to, 126 | uint getId, 127 | uint setId 128 | ) public payable { 129 | require(AccountInterface(address(this)).isAuth(to), "invalid-to-address"); 130 | uint amt = getUint(getId, tokenAmt); 131 | if (erc20 == getEthAddr()) { 132 | amt = amt == uint(-1) ? address(this).balance : amt; 133 | to.transfer(amt); 134 | } else { 135 | ERC20Interface token = ERC20Interface(erc20); 136 | amt = amt == uint(-1) ? token.balanceOf(address(this)) : amt; 137 | token.transfer(to, amt); 138 | } 139 | setUint(setId, amt); 140 | 141 | emit LogWithdraw(erc20, amt, to, getId, setId); 142 | 143 | bytes32 _eventCode = keccak256("LogWithdraw(address,uint256,address,uint256,uint256)"); 144 | bytes memory _eventParam = abi.encode(erc20, amt, to, getId, setId); 145 | (uint _type, uint _id) = connectorID(); 146 | EventInterface(instaEventAddress).emitEvent(_type, _id, _eventCode, _eventParam); 147 | } 148 | 149 | } 150 | 151 | 152 | contract ConnectBasic is BasicResolver { 153 | 154 | constructor (address _instaEventAddress, address _instaMemoryAddress) public BasicResolver(_instaEventAddress, _instaMemoryAddress) {} 155 | string public constant name = "Basic-v1"; 156 | } -------------------------------------------------------------------------------- /contracts/v1/event.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.0; 2 | 3 | interface ListInterface { 4 | function accountID(address) external view returns (uint64); 5 | } 6 | 7 | 8 | contract InstaEvent { 9 | 10 | address public immutable instaList; 11 | 12 | constructor (address _instaList) public { 13 | instaList = _instaList; 14 | } 15 | 16 | event LogEvent(uint64 connectorType, uint64 indexed connectorID, uint64 indexed accountID, bytes32 indexed eventCode, bytes eventData); 17 | 18 | function emitEvent(uint _connectorType, uint _connectorID, bytes32 _eventCode, bytes calldata _eventData) external { 19 | uint64 _ID = ListInterface(instaList).accountID(msg.sender); 20 | require(_ID != 0, "not-SA"); 21 | emit LogEvent(uint64(_connectorType), uint64(_connectorID), _ID, _eventCode, _eventData); 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /contracts/v1/memory.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.0; 2 | 3 | /** 4 | * @title InstaMemory. 5 | * @dev Store Data For Cast Function. 6 | */ 7 | 8 | contract InstaMemory { 9 | 10 | // Memory Bytes (Smart Account Address => Storage ID => Bytes). 11 | mapping (address => mapping (uint => bytes32)) internal mbytes; // Use it to store execute data and delete in the same transaction 12 | // Memory Uint (Smart Account Address => Storage ID => Uint). 13 | mapping (address => mapping (uint => uint)) internal muint; // Use it to store execute data and delete in the same transaction 14 | // Memory Address (Smart Account Address => Storage ID => Address). 15 | mapping (address => mapping (uint => address)) internal maddr; // Use it to store execute data and delete in the same transaction 16 | 17 | /** 18 | * @dev Store Bytes. 19 | * @param _id Storage ID. 20 | * @param _byte bytes data to store. 21 | */ 22 | function setBytes(uint _id, bytes32 _byte) public { 23 | mbytes[msg.sender][_id] = _byte; 24 | } 25 | 26 | /** 27 | * @dev Get Stored Bytes. 28 | * @param _id Storage ID. 29 | */ 30 | function getBytes(uint _id) public returns (bytes32 _byte) { 31 | _byte = mbytes[msg.sender][_id]; 32 | delete mbytes[msg.sender][_id]; 33 | } 34 | 35 | /** 36 | * @dev Store Uint. 37 | * @param _id Storage ID. 38 | * @param _num uint data to store. 39 | */ 40 | function setUint(uint _id, uint _num) public { 41 | muint[msg.sender][_id] = _num; 42 | } 43 | 44 | /** 45 | * @dev Get Stored Uint. 46 | * @param _id Storage ID. 47 | */ 48 | function getUint(uint _id) public returns (uint _num) { 49 | _num = muint[msg.sender][_id]; 50 | delete muint[msg.sender][_id]; 51 | } 52 | 53 | /** 54 | * @dev Store Address. 55 | * @param _id Storage ID. 56 | * @param _addr Address data to store. 57 | */ 58 | function setAddr(uint _id, address _addr) public { 59 | maddr[msg.sender][_id] = _addr; 60 | } 61 | 62 | /** 63 | * @dev Get Stored Address. 64 | * @param _id Storage ID. 65 | */ 66 | function getAddr(uint _id) public returns (address _addr) { 67 | _addr = maddr[msg.sender][_id]; 68 | delete maddr[msg.sender][_id]; 69 | } 70 | 71 | } -------------------------------------------------------------------------------- /contracts/v1/test/InstaAccountV3.test.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.0; 2 | pragma experimental ABIEncoderV2; 3 | 4 | /** 5 | * @title Test InstaAccount. 6 | * @dev DeFi Smart Account Wallet. 7 | */ 8 | 9 | contract Record { 10 | uint256 public constant version = 3; 11 | } 12 | 13 | contract InstaAccountV3 is Record { 14 | receive() external payable {} 15 | } 16 | -------------------------------------------------------------------------------- /contracts/v1/test/InstaAccountV4.test.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.0; 2 | pragma experimental ABIEncoderV2; 3 | 4 | /** 5 | * @title Test InstaAccount. 6 | * @dev DeFi Smart Account Wallet. 7 | */ 8 | 9 | contract Record { 10 | uint256 public constant version = 4; 11 | } 12 | 13 | contract InstaAccountV4 is Record { 14 | receive() external payable {} 15 | } 16 | -------------------------------------------------------------------------------- /contracts/v1/test/check.test.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.7.0; 3 | 4 | contract Change { 5 | bool public status; 6 | 7 | function change(bool _status) public { 8 | status = _status; 9 | } 10 | } 11 | 12 | contract InstaCheck is Change { 13 | function isOk() external view returns (bool ok) { 14 | return status; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /contracts/v1/test/connector.registry.test.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.0; 2 | 3 | /** 4 | * @title InstaConnectors 5 | * @dev Registry for Connectors. 6 | */ 7 | 8 | interface IndexInterface { 9 | function master() external view returns (address); 10 | } 11 | 12 | interface ConnectorInterface { 13 | function connectorID() external view returns (uint256 _type, uint256 _id); 14 | 15 | function name() external view returns (string memory); 16 | } 17 | 18 | contract DSMath { 19 | function add(uint256 x, uint256 y) internal pure returns (uint256 z) { 20 | require((z = x + y) >= x, "ds-math-add-overflow"); 21 | } 22 | 23 | function sub(uint256 x, uint256 y) internal pure returns (uint256 z) { 24 | require((z = x - y) <= x, "ds-math-sub-underflow"); 25 | } 26 | } 27 | 28 | contract Controllers is DSMath { 29 | event LogAddController(address indexed addr); 30 | event LogRemoveController(address indexed addr); 31 | 32 | // InstaIndex Address. 33 | address public immutable instaIndex; 34 | 35 | constructor(address _instaIndex) { 36 | instaIndex = _instaIndex; 37 | } 38 | 39 | // Enabled Chief(Address of Chief => bool). 40 | mapping(address => bool) public chief; 41 | // Enabled Connectors(Connector Address => bool). 42 | mapping(address => bool) public connectors; 43 | // Enabled Static Connectors(Connector Address => bool). 44 | mapping(address => bool) public staticConnectors; 45 | 46 | /** 47 | * @dev Throws if the sender not is Master Address from InstaIndex 48 | * or Enabled Chief. 49 | */ 50 | modifier isChief() { 51 | require( 52 | chief[msg.sender] || 53 | msg.sender == IndexInterface(instaIndex).master(), 54 | "not-an-chief" 55 | ); 56 | _; 57 | } 58 | 59 | /** 60 | * @dev Enable a Chief. 61 | * @param _userAddress Chief Address. 62 | */ 63 | function enableChief(address _userAddress) external isChief { 64 | chief[_userAddress] = true; 65 | emit LogAddController(_userAddress); 66 | } 67 | 68 | /** 69 | * @dev Disables a Chief. 70 | * @param _userAddress Chief Address. 71 | */ 72 | function disableChief(address _userAddress) external isChief { 73 | delete chief[_userAddress]; 74 | emit LogRemoveController(_userAddress); 75 | } 76 | } 77 | 78 | contract Listings is Controllers { 79 | constructor(address _instaIndex) Controllers(_instaIndex) {} 80 | 81 | // Connectors Array. 82 | address[] public connectorArray; 83 | // Count of Connector's Enabled. 84 | uint256 public connectorCount; 85 | 86 | /** 87 | * @dev Add Connector to Connector's array. 88 | * @param _connector Connector Address. 89 | **/ 90 | function addToArr(address _connector) internal { 91 | require(_connector != address(0), "Not-valid-connector"); 92 | (, uint256 _id) = ConnectorInterface(_connector).connectorID(); 93 | require(_id == (connectorArray.length + 1), "ConnectorID-doesnt-match"); 94 | ConnectorInterface(_connector).name(); // Checking if connector has function name() 95 | connectorArray.push(_connector); 96 | } 97 | 98 | // Static Connectors Array. 99 | address[] public staticConnectorArray; 100 | 101 | /** 102 | * @dev Add Connector to Static Connector's array. 103 | * @param _connector Static Connector Address. 104 | **/ 105 | function addToArrStatic(address _connector) internal { 106 | require(_connector != address(0), "Not-valid-connector"); 107 | (, uint256 _id) = ConnectorInterface(_connector).connectorID(); 108 | require( 109 | _id == (staticConnectorArray.length + 1), 110 | "ConnectorID-doesnt-match" 111 | ); 112 | ConnectorInterface(_connector).name(); // Checking if connector has function name() 113 | staticConnectorArray.push(_connector); 114 | } 115 | } 116 | 117 | contract InstaConnectorsTest is Listings { 118 | constructor(address _instaIndex) public Listings(_instaIndex) {} 119 | 120 | event LogEnable(address indexed connector); 121 | event LogDisable(address indexed connector); 122 | event LogEnableStatic(address indexed connector); 123 | 124 | /** 125 | * @dev Enable Connector. 126 | * @param _connector Connector Address. 127 | */ 128 | function enable(address _connector) external isChief { 129 | require(!connectors[_connector], "already-enabled"); 130 | addToArr(_connector); 131 | connectors[_connector] = true; 132 | connectorCount++; 133 | emit LogEnable(_connector); 134 | } 135 | 136 | /** 137 | * @dev Disable Connector. 138 | * @param _connector Connector Address. 139 | */ 140 | function disable(address _connector) external isChief { 141 | require(connectors[_connector], "already-disabled"); 142 | delete connectors[_connector]; 143 | connectorCount--; 144 | emit LogDisable(_connector); 145 | } 146 | 147 | /** 148 | * @dev Enable Static Connector. 149 | * @param _connector Static Connector Address. 150 | */ 151 | function enableStatic(address _connector) external isChief { 152 | require(!staticConnectors[_connector], "already-enabled"); 153 | addToArrStatic(_connector); 154 | staticConnectors[_connector] = true; 155 | emit LogEnableStatic(_connector); 156 | } 157 | 158 | /** 159 | * @dev Check if Connector addresses are enabled. 160 | * @param _connectors Array of Connector Addresses. 161 | */ 162 | function isConnector(address[] calldata _connectors) 163 | external 164 | view 165 | returns (bool isOk) 166 | { 167 | isOk = true; 168 | } 169 | 170 | /** 171 | * @dev Check if Connector addresses are static enabled. 172 | * @param _connectors Array of Connector Addresses. 173 | */ 174 | function isStaticConnector(address[] calldata _connectors) 175 | external 176 | view 177 | returns (bool isOk) 178 | { 179 | isOk = true; 180 | for (uint256 i = 0; i < _connectors.length; i++) { 181 | if (!staticConnectors[_connectors[i]]) { 182 | isOk = false; 183 | break; 184 | } 185 | } 186 | } 187 | 188 | /** 189 | * @dev get Connector's Array length. 190 | */ 191 | function connectorLength() external view returns (uint256) { 192 | return connectorArray.length; 193 | } 194 | 195 | /** 196 | * @dev get Static Connector's Array length. 197 | */ 198 | function staticConnectorLength() external view returns (uint256) { 199 | return staticConnectorArray.length; 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /contracts/v1/test/staticConnector.test.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.0; 2 | 3 | /** 4 | * @title Staic connector. 5 | * @dev Connector For Testing Static connectors. 6 | */ 7 | 8 | contract StaticTest { 9 | /** 10 | * @dev Connector ID and Type. 11 | */ 12 | function connectorID() public pure returns (uint256 _type, uint256 _id) { 13 | (_type, _id) = (1, 4); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /contracts/v2/accounts/default/implementation_default.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.0; 2 | pragma experimental ABIEncoderV2; 3 | 4 | import { Variables } from "../variables.sol"; 5 | 6 | interface IndexInterface { 7 | function list() external view returns (address); 8 | } 9 | 10 | interface ListInterface { 11 | function addAuth(address user) external; 12 | 13 | function removeAuth(address user) external; 14 | } 15 | 16 | contract Constants is Variables { 17 | uint256 public constant implementationVersion = 1; 18 | // InstaIndex Address. 19 | address public immutable instaIndex; 20 | // The Account Module Version. 21 | uint256 public constant version = 2; 22 | 23 | constructor(address _instaIndex) { 24 | instaIndex = _instaIndex; 25 | } 26 | } 27 | 28 | contract Record is Constants { 29 | constructor(address _instaIndex) Constants(_instaIndex) {} 30 | 31 | event LogEnableUser(address indexed user); 32 | event LogDisableUser(address indexed user); 33 | event LogBetaMode(bool indexed beta); 34 | 35 | /** 36 | * @dev Check for Auth if enabled. 37 | * @param user address/user/owner. 38 | */ 39 | function isAuth(address user) public view returns (bool) { 40 | return _auth[user]; 41 | } 42 | 43 | /** 44 | * @dev Check if Beta mode is enabled or not 45 | */ 46 | function isBeta() public view returns (bool) { 47 | return _beta; 48 | } 49 | 50 | /** 51 | * @dev Enable New User. 52 | * @param user Owner address 53 | */ 54 | function enable(address user) public { 55 | require( 56 | msg.sender == address(this) || msg.sender == instaIndex, 57 | "not-self-index" 58 | ); 59 | require(user != address(0), "not-valid"); 60 | require(!_auth[user], "already-enabled"); 61 | _auth[user] = true; 62 | ListInterface(IndexInterface(instaIndex).list()).addAuth(user); 63 | emit LogEnableUser(user); 64 | } 65 | 66 | /** 67 | * @dev Disable User. 68 | * @param user Owner address 69 | */ 70 | function disable(address user) public { 71 | require(msg.sender == address(this), "not-self"); 72 | require(user != address(0), "not-valid"); 73 | require(_auth[user], "already-disabled"); 74 | delete _auth[user]; 75 | ListInterface(IndexInterface(instaIndex).list()).removeAuth(user); 76 | emit LogDisableUser(user); 77 | } 78 | 79 | function toggleBeta() public { 80 | require(msg.sender == address(this), "not-self"); 81 | _beta = !_beta; 82 | emit LogBetaMode(_beta); 83 | } 84 | 85 | /** 86 | * @dev ERC721 token receiver 87 | */ 88 | function onERC721Received( 89 | address, 90 | address, 91 | uint256, 92 | bytes calldata 93 | ) external returns (bytes4) { 94 | return 0x150b7a02; // bytes4(keccak256("onERC721Received(address,address,uint256,bytes)")) 95 | } 96 | 97 | /** 98 | * @dev ERC1155 token receiver 99 | */ 100 | function onERC1155Received( 101 | address, 102 | address, 103 | uint256, 104 | uint256, 105 | bytes memory 106 | ) external returns (bytes4) { 107 | return 0xf23a6e61; // bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)")) 108 | } 109 | 110 | /** 111 | * @dev ERC1155 token receiver 112 | */ 113 | function onERC1155BatchReceived( 114 | address, 115 | address, 116 | uint256[] calldata, 117 | uint256[] calldata, 118 | bytes calldata 119 | ) external returns (bytes4) { 120 | return 0xbc197c81; // bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)")) 121 | } 122 | } 123 | 124 | contract InstaDefaultImplementation is Record { 125 | constructor(address _instaIndex) public Record(_instaIndex) {} 126 | 127 | receive() external payable {} 128 | } 129 | -------------------------------------------------------------------------------- /contracts/v2/accounts/default/readme.md: -------------------------------------------------------------------------------- 1 | # Default Module 2 | 3 | ### Details 4 | - Contains basics smart account setters & getters function. Eg:- enable/disable new owners, 5 | - Module called by default if the function that user is trying to call is not defined in implementations.sol located at ../../registry/implementations.sol. If that function is not available in default module then smart account throws error. -------------------------------------------------------------------------------- /contracts/v2/accounts/module1/Implementation_m1.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.0; 2 | pragma experimental ABIEncoderV2; 3 | 4 | import { Variables } from "../variables.sol"; 5 | 6 | /** 7 | * @title InstaAccountV2. 8 | * @dev DeFi Smart Account Wallet. 9 | */ 10 | 11 | interface ConnectorsInterface { 12 | function isConnectors(string[] calldata connectorNames) external view returns (bool, address[] memory); 13 | } 14 | 15 | contract Constants is Variables { 16 | // InstaIndex Address. 17 | address internal immutable instaIndex; 18 | // Connectors Address. 19 | address public immutable connectorsM1; 20 | 21 | constructor(address _instaIndex, address _connectors) { 22 | connectorsM1 = _connectors; 23 | instaIndex = _instaIndex; 24 | } 25 | } 26 | 27 | contract InstaImplementationM1 is Constants { 28 | 29 | constructor(address _instaIndex, address _connectors) Constants(_instaIndex, _connectors) {} 30 | 31 | function decodeEvent(bytes memory response) internal pure returns (string memory _eventCode, bytes memory _eventParams) { 32 | if (response.length > 0) { 33 | (_eventCode, _eventParams) = abi.decode(response, (string, bytes)); 34 | } 35 | } 36 | 37 | event LogCast( 38 | address indexed origin, 39 | address indexed sender, 40 | uint256 value, 41 | string[] targetsNames, 42 | address[] targets, 43 | string[] eventNames, 44 | bytes[] eventParams 45 | ); 46 | 47 | receive() external payable {} 48 | 49 | /** 50 | * @dev Delegate the calls to Connector. 51 | * @param _target Connector address 52 | * @param _data CallData of function. 53 | */ 54 | function spell(address _target, bytes memory _data) internal returns (bytes memory response) { 55 | require(_target != address(0), "target-invalid"); 56 | assembly { 57 | let succeeded := delegatecall(gas(), _target, add(_data, 0x20), mload(_data), 0, 0) 58 | let size := returndatasize() 59 | 60 | response := mload(0x40) 61 | mstore(0x40, add(response, and(add(add(size, 0x20), 0x1f), not(0x1f)))) 62 | mstore(response, size) 63 | returndatacopy(add(response, 0x20), 0, size) 64 | 65 | switch iszero(succeeded) 66 | case 1 { 67 | // throw if delegatecall failed 68 | returndatacopy(0x00, 0x00, size) 69 | revert(0x00, size) 70 | } 71 | } 72 | } 73 | 74 | /** 75 | * @dev This is the main function, Where all the different functions are called 76 | * from Smart Account. 77 | * @param _targetNames Array of Connector address. 78 | * @param _datas Array of Calldata. 79 | */ 80 | function cast( 81 | string[] calldata _targetNames, 82 | bytes[] calldata _datas, 83 | address _origin 84 | ) 85 | external 86 | payable 87 | returns (bytes32) // Dummy return to fix instaIndex buildWithCast function 88 | { 89 | uint256 _length = _targetNames.length; 90 | require(_auth[msg.sender] || msg.sender == instaIndex, "1: permission-denied"); 91 | require(_length != 0, "1: length-invalid"); 92 | require(_length == _datas.length , "1: array-length-invalid"); 93 | 94 | string[] memory eventNames = new string[](_length); 95 | bytes[] memory eventParams = new bytes[](_length); 96 | 97 | (bool isOk, address[] memory _targets) = ConnectorsInterface(connectorsM1).isConnectors(_targetNames); 98 | 99 | require(isOk, "1: not-connector"); 100 | 101 | for (uint i = 0; i < _length; i++) { 102 | bytes memory response = spell(_targets[i], _datas[i]); 103 | (eventNames[i], eventParams[i]) = decodeEvent(response); 104 | } 105 | 106 | emit LogCast( 107 | _origin, 108 | msg.sender, 109 | msg.value, 110 | _targetNames, 111 | _targets, 112 | eventNames, 113 | eventParams 114 | ); 115 | } 116 | } -------------------------------------------------------------------------------- /contracts/v2/accounts/module1/readme.md: -------------------------------------------------------------------------------- 1 | # Default Module 2 | 3 | ### Details 4 | - Contains most core functions of smart account name `cast()`. Is only called by owners of smart accounts and has full fledge access over smart account. Used to also access all the DSA. 5 | - Using `cast()` user can access the connectors which allows smart account to interact with protocols or setup any settings on smart account. 6 | -------------------------------------------------------------------------------- /contracts/v2/accounts/test/ERC1155.token.test.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.0; 2 | 3 | import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol"; 4 | 5 | /** 6 | * ERC1155 Token contract 7 | * For testing purpose. 8 | */ 9 | 10 | contract TokenTest is ERC1155 { 11 | constructor() public ERC1155("https://token.example/api/item/{id}.json") {} 12 | 13 | uint256 public constant _token1 = 0; 14 | uint256 public constant _token2 = 1; 15 | 16 | event LogTransferERC1155( 17 | address from, 18 | address to, 19 | uint256 tokenId, 20 | uint256 amount 21 | ); 22 | event LogTransferBatchERC1155( 23 | address from, 24 | address to, 25 | uint256[] tokenIds, 26 | uint256[] amounts 27 | ); 28 | 29 | function transfer1155( 30 | address _to, 31 | uint256 id, 32 | uint256 amount 33 | ) public { 34 | _mint(msg.sender, id, amount, ""); 35 | safeTransferFrom(msg.sender, _to, id, amount, ""); 36 | 37 | emit LogTransferERC1155(msg.sender, _to, id, amount); 38 | } 39 | 40 | function transferBatch1155( 41 | address _to, 42 | uint256[] memory ids, 43 | uint256[] memory amounts 44 | ) public { 45 | _mintBatch(msg.sender, ids, amounts, ""); 46 | safeBatchTransferFrom(msg.sender, _to, ids, amounts, ""); 47 | 48 | emit LogTransferBatchERC1155(msg.sender, _to, ids, amounts); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /contracts/v2/accounts/test/ImplementationBetaTest.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.0; 2 | pragma experimental ABIEncoderV2; 3 | 4 | import {Variables} from "../variables.sol"; 5 | 6 | /** 7 | * @title InstaAccountV2. 8 | * @dev DeFi Smart Account Wallet. 9 | */ 10 | 11 | interface ConnectorsInterface { 12 | function isConnectors(string[] calldata connectorNames) 13 | external 14 | view 15 | returns (bool, address[] memory); 16 | } 17 | 18 | contract Constants is Variables { 19 | // InstaIndex Address. 20 | address internal immutable instaIndex; 21 | // Connectors Address. 22 | address public immutable connectorsM1; 23 | 24 | constructor(address _instaIndex, address _connectors) { 25 | connectorsM1 = _connectors; 26 | instaIndex = _instaIndex; 27 | } 28 | } 29 | 30 | contract InstaImplementationBetaTest is Constants { 31 | constructor(address _instaIndex, address _connectors) 32 | Constants(_instaIndex, _connectors) 33 | {} 34 | 35 | function decodeEvent(bytes memory response) 36 | internal 37 | pure 38 | returns (string memory _eventCode, bytes memory _eventParams) 39 | { 40 | if (response.length > 0) { 41 | (_eventCode, _eventParams) = abi.decode(response, (string, bytes)); 42 | } 43 | } 44 | 45 | event LogCast( 46 | address indexed origin, 47 | address indexed sender, 48 | uint256 value, 49 | string[] targetsNames, 50 | address[] targets, 51 | string[] eventNames, 52 | bytes[] eventParams 53 | ); 54 | 55 | receive() external payable {} 56 | 57 | /** 58 | * @dev Delegate the calls to Connector. 59 | * @param _target Connector address 60 | * @param _data CallData of function. 61 | */ 62 | function spell(address _target, bytes memory _data) 63 | internal 64 | returns (bytes memory response) 65 | { 66 | require(_target != address(0), "target-invalid"); 67 | assembly { 68 | let succeeded := delegatecall( 69 | gas(), 70 | _target, 71 | add(_data, 0x20), 72 | mload(_data), 73 | 0, 74 | 0 75 | ) 76 | let size := returndatasize() 77 | 78 | response := mload(0x40) 79 | mstore( 80 | 0x40, 81 | add(response, and(add(add(size, 0x20), 0x1f), not(0x1f))) 82 | ) 83 | mstore(response, size) 84 | returndatacopy(add(response, 0x20), 0, size) 85 | 86 | switch iszero(succeeded) 87 | case 1 { 88 | // throw if delegatecall failed 89 | returndatacopy(0x00, 0x00, size) 90 | revert(0x00, size) 91 | } 92 | } 93 | } 94 | 95 | /** 96 | * @dev This is the main function, Where all the different functions are called 97 | * from Smart Account. 98 | * @param _targetNames Array of Connector address. 99 | * @param _datas Array of Calldata. 100 | */ 101 | function castBeta( 102 | string[] calldata _targetNames, 103 | bytes[] calldata _datas, 104 | address _origin 105 | ) 106 | external 107 | payable 108 | returns ( 109 | bytes32 // Dummy return to fix instaIndex buildWithCast function 110 | ) 111 | { 112 | require(_beta, "Beta-does-not-enabled"); 113 | uint256 _length = _targetNames.length; 114 | require( 115 | _auth[msg.sender] || msg.sender == instaIndex, 116 | "1: permission-denied" 117 | ); 118 | require(_length != 0, "1: length-invalid"); 119 | require(_length == _datas.length, "1: array-length-invalid"); 120 | 121 | string[] memory eventNames = new string[](_length); 122 | bytes[] memory eventParams = new bytes[](_length); 123 | 124 | (bool isOk, address[] memory _targets) = ConnectorsInterface( 125 | connectorsM1 126 | ).isConnectors(_targetNames); 127 | 128 | require(isOk, "1: not-connector"); 129 | 130 | for (uint256 i = 0; i < _length; i++) { 131 | bytes memory response = spell(_targets[i], _datas[i]); 132 | (eventNames[i], eventParams[i]) = decodeEvent(response); 133 | } 134 | 135 | emit LogCast( 136 | _origin, 137 | msg.sender, 138 | msg.value, 139 | _targetNames, 140 | _targets, 141 | eventNames, 142 | eventParams 143 | ); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /contracts/v2/accounts/test/Implementation_m2.test.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.0; 2 | pragma experimental ABIEncoderV2; 3 | import "hardhat/console.sol"; 4 | 5 | 6 | /** 7 | * @title InstaAccountV2 Mapping 2. 8 | * @dev DeFi Smart Account Wallet. 9 | */ 10 | 11 | interface DefaultImplementation { 12 | function version() external view returns(uint); 13 | function isAuth(address) external view returns(bool); 14 | } 15 | 16 | interface IndexInterface { 17 | function connectors(uint version) external view returns (address); 18 | function check(uint version) external view returns (address); 19 | } 20 | 21 | interface ConnectorsInterface { 22 | function isConnectors(string[] calldata connectorNames) external view returns (bool, address[] memory); 23 | } 24 | 25 | interface CheckInterface { 26 | function isOk() external view returns (bool); 27 | } 28 | 29 | contract InstaImplementationM2 { 30 | address internal immutable instaIndex; 31 | // Connnectors Address. 32 | address public immutable connectorsM2; 33 | 34 | constructor(address _instaIndex, address _connectors) { 35 | connectorsM2 = _connectors; 36 | instaIndex = _instaIndex; 37 | } 38 | 39 | function decodeEvent(bytes memory response) internal pure returns (string memory _eventCode, bytes memory _eventParams) { 40 | (_eventCode, _eventParams) = abi.decode(response, (string, bytes)); 41 | } 42 | 43 | event LogCast( 44 | address indexed origin, 45 | address indexed sender, 46 | uint value, 47 | string[] targetsNames, 48 | address[] targets, 49 | string[] eventNames, 50 | bytes[] eventParams 51 | ); 52 | 53 | receive() external payable {} 54 | 55 | /** 56 | * @dev Delegate the calls to Connector And this function is ran by cast(). 57 | * @param _target Target to of Connector. 58 | * @param _data CallData of function in Connector. 59 | */ 60 | function spell(address _target, bytes memory _data) internal returns (bytes memory response) { 61 | require(_target != address(0), "target-invalid"); 62 | assembly { 63 | let succeeded := delegatecall(gas(), _target, add(_data, 0x20), mload(_data), 0, 0) 64 | let size := returndatasize() 65 | 66 | response := mload(0x40) 67 | mstore(0x40, add(response, and(add(add(size, 0x20), 0x1f), not(0x1f)))) 68 | mstore(response, size) 69 | returndatacopy(add(response, 0x20), 0, size) 70 | 71 | switch iszero(succeeded) 72 | case 1 { 73 | // throw if delegatecall failed 74 | returndatacopy(0x00, 0x00, size) 75 | revert(0x00, size) 76 | } 77 | } 78 | } 79 | 80 | /** 81 | * @dev This is the main function, Where all the different functions are called 82 | * from Smart Account. 83 | * @param _targetNames Array of Target(s) to of Connector. 84 | * @param _datas Array of Calldata(S) of function. 85 | */ 86 | function castWithFlashloan( 87 | string[] calldata _targetNames, 88 | bytes[] calldata _datas, 89 | address _origin 90 | ) 91 | external 92 | payable 93 | returns (bytes32) // Dummy return to fix instaIndex buildWithCast function 94 | { 95 | 96 | DefaultImplementation defaultImplementation = DefaultImplementation(address(this)); 97 | uint256 _length = _targetNames.length; 98 | 99 | require(defaultImplementation.isAuth(msg.sender) || msg.sender == address(instaIndex), "InstaImplementationM1: permission-denied"); 100 | require(_length == _datas.length , "InstaImplementationM1: array-length-invalid"); 101 | 102 | string[] memory eventNames = new string[](_length); 103 | bytes[] memory eventParams = new bytes[](_length); 104 | 105 | (bool isOk, address[] memory _targets) = ConnectorsInterface(connectorsM2).isConnectors(_targetNames); 106 | require(isOk, "1: not-connector"); 107 | 108 | for (uint i = 0; i < _targets.length; i++) { 109 | bytes memory response = spell(_targets[i], _datas[i]); 110 | (eventNames[i], eventParams[i]) = decodeEvent(response); 111 | } 112 | 113 | emit LogCast( 114 | _origin, 115 | msg.sender, 116 | msg.value, 117 | _targetNames, 118 | _targets, 119 | eventNames, 120 | eventParams 121 | ); 122 | } 123 | 124 | } -------------------------------------------------------------------------------- /contracts/v2/accounts/test/Implmentation_account.test.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.0; 2 | pragma experimental ABIEncoderV2; 3 | 4 | /** 5 | * Test ImplementationM0 6 | * Defi Smart Account 7 | * Not a complete or correct contract. 8 | */ 9 | interface IndexInterface { 10 | function list() external view returns (address); 11 | } 12 | 13 | interface ListInterface { 14 | function addAuth(address user) external; 15 | } 16 | 17 | contract CommonSetup { 18 | // Auth Module(Address of Auth => bool). 19 | mapping(address => bool) internal auth; 20 | } 21 | 22 | contract Record is CommonSetup { 23 | address public immutable instaIndex; 24 | 25 | constructor(address _instaIndex) { 26 | instaIndex = _instaIndex; 27 | } 28 | 29 | event LogEnableUser(address indexed user); 30 | event LogPayEther(uint256 amt); 31 | 32 | /** 33 | * @dev Test function to check transfer of ether, should not be used. 34 | * @param _account account module address. 35 | */ 36 | function handlePayment(address payable _account) public payable { 37 | _account.transfer(msg.value); 38 | emit LogPayEther(msg.value); 39 | } 40 | } 41 | 42 | contract InstaImplementationM0Test is Record { 43 | constructor(address _instaIndex) Record(_instaIndex) {} 44 | } 45 | -------------------------------------------------------------------------------- /contracts/v2/accounts/test/NFT.test.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.0; 2 | 3 | import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; 4 | 5 | /** 6 | * ERC721 Token contract 7 | * For testing purpose. 8 | */ 9 | 10 | contract NFTTest is ERC721 { 11 | constructor() public ERC721("NFTTest", "NFT") {} 12 | 13 | uint256 public _tokenIds; 14 | 15 | event LogTransferERC721(address from, address to, uint256 tokenId); 16 | 17 | function transferNFT(address _to) public { 18 | _tokenIds++; 19 | 20 | uint256 newItemId = _tokenIds; 21 | _mint(msg.sender, newItemId); 22 | safeTransferFrom(msg.sender, _to, newItemId); 23 | 24 | emit LogTransferERC721(msg.sender, _to, newItemId); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /contracts/v2/accounts/test/implementation_default.v2.test.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.0; 2 | 3 | pragma experimental ABIEncoderV2; 4 | 5 | interface IndexInterface { 6 | function list() external view returns (address); 7 | } 8 | 9 | interface CheckInterface { 10 | function isOk() external view returns (bool); 11 | } 12 | 13 | interface ListInterface { 14 | function addAuth(address user) external; 15 | 16 | function removeAuth(address user) external; 17 | } 18 | 19 | contract CommonSetup { 20 | uint256 public constant implementationVersion = 2; 21 | // InstaIndex Address. 22 | address public constant instaIndex = 23 | 0x2971AdFa57b20E5a416aE5a708A8655A9c74f723; 24 | // The Account Module Version. 25 | uint256 public constant version = 2; 26 | // Auth Module(Address of Auth => bool). 27 | mapping(address => bool) internal auth; 28 | // Is shield true/false. 29 | bool public shield; 30 | // Auth Module(Address of Auth => bool). 31 | mapping(address => bool) internal checkMapping; 32 | } 33 | 34 | contract Record is CommonSetup { 35 | event LogReceiveEther(uint256 amt); 36 | event LogEnableUser(address indexed user); 37 | event LogDisableUser(address indexed user); 38 | event LogSwitchShield(bool _shield); 39 | event LogCheckMapping(address user, bool check); 40 | 41 | /** 42 | * @dev Check for Auth if enabled. 43 | * @param user address/user/owner. 44 | */ 45 | function isAuth(address user) public view returns (bool) { 46 | return auth[user]; 47 | } 48 | 49 | /** 50 | * @dev Change Shield State. 51 | */ 52 | function switchShield(bool _shield) external { 53 | require(auth[msg.sender], "not-self"); 54 | require(shield != _shield, "shield is set"); 55 | shield = _shield; 56 | emit LogSwitchShield(shield); 57 | } 58 | 59 | function editCheckMapping(address user, bool _bool) public { 60 | require(msg.sender == address(this), "not-self-index"); 61 | require(user != address(0), "not-valid"); 62 | checkMapping[user] = _bool; 63 | emit LogCheckMapping(user, _bool); 64 | } 65 | 66 | /** 67 | * @dev Enable New User. 68 | * @param user Owner of the Smart Account. 69 | */ 70 | function enable(address user) public { 71 | require( 72 | msg.sender == address(this) || 73 | msg.sender == instaIndex || 74 | isAuth(msg.sender), 75 | "not-self-index" 76 | ); 77 | require(user != address(0), "not-valid"); 78 | require(!auth[user], "already-enabled"); 79 | auth[user] = true; 80 | ListInterface(IndexInterface(instaIndex).list()).addAuth(user); 81 | emit LogEnableUser(user); 82 | } 83 | 84 | /** 85 | * @dev Disable User. 86 | * @param user Owner of the Smart Account. 87 | */ 88 | function disable(address user) public { 89 | require(msg.sender == address(this) || isAuth(msg.sender), "not-self"); 90 | require(user != address(0), "not-valid"); 91 | require(auth[user], "already-disabled"); 92 | delete auth[user]; 93 | ListInterface(IndexInterface(instaIndex).list()).removeAuth(user); 94 | emit LogDisableUser(user); 95 | } 96 | 97 | /** 98 | * @dev Test function to check receival of ether to contract. 99 | */ 100 | function receiveEther() public payable { 101 | emit LogReceiveEther(msg.value); 102 | } 103 | } 104 | 105 | contract InstaDefaultImplementationV2 is Record { 106 | receive() external payable {} 107 | } 108 | -------------------------------------------------------------------------------- /contracts/v2/accounts/variables.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.0; 2 | 3 | contract Variables { 4 | // Auth Module(Address of Auth => bool). 5 | mapping (address => bool) internal _auth; 6 | // enable beta mode to access all the beta features. 7 | bool internal _beta; 8 | } -------------------------------------------------------------------------------- /contracts/v2/connectors/test/auth.test.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.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 ListInterface { 15 | struct UserLink { 16 | uint64 first; 17 | uint64 last; 18 | uint64 count; 19 | } 20 | 21 | struct UserList { 22 | uint64 prev; 23 | uint64 next; 24 | } 25 | 26 | struct AccountLink { 27 | address first; 28 | address last; 29 | uint64 count; 30 | } 31 | 32 | struct AccountList { 33 | address prev; 34 | address next; 35 | } 36 | 37 | function accounts() external view returns (uint); 38 | function accountID(address) external view returns (uint64); 39 | function accountAddr(uint64) external view returns (address); 40 | function userLink(address) external view returns (UserLink memory); 41 | function userList(address, uint64) external view returns (UserList memory); 42 | function accountLink(uint64) external view returns (AccountLink memory); 43 | function accountList(uint64, address) external view returns (AccountList memory); 44 | } 45 | 46 | 47 | contract Basics { 48 | /** 49 | * @dev Return Address. 50 | */ 51 | address public immutable instaList; 52 | 53 | constructor(address _instaList) { 54 | instaList = _instaList; 55 | } 56 | 57 | } 58 | 59 | contract Helpers is Basics { 60 | constructor(address _instaList) Basics(_instaList) {} 61 | 62 | function checkAuthCount() internal view returns (uint count) { 63 | ListInterface listContract = ListInterface(instaList); 64 | uint64 accountId = listContract.accountID(address(this)); 65 | count = listContract.accountLink(accountId).count; 66 | } 67 | } 68 | 69 | contract Auth is Helpers { 70 | constructor(address _instaList) Helpers(_instaList) {} 71 | 72 | event LogAddAuth(address indexed _msgSender, address indexed _authority); 73 | event LogRemoveAuth(address indexed _msgSender, address indexed _authority); 74 | 75 | /** 76 | * @dev Add New authority 77 | * @param authority authority Address. 78 | */ 79 | function add(address authority) external payable returns (string memory _eventName, bytes memory _eventParam) { 80 | AccountInterface(address(this)).enable(authority); 81 | 82 | emit LogAddAuth(msg.sender, authority); 83 | 84 | // _eventCode = keccak256("LogAddAuth(address,address)"); 85 | _eventName = "LogAddAuth(address,address)"; 86 | _eventParam = abi.encode(msg.sender, authority); 87 | } 88 | 89 | /** 90 | * @dev Remove authority 91 | * @param authority authority Address. 92 | */ 93 | function remove(address authority) external payable returns (string memory _eventName, bytes memory _eventParam) { 94 | require(checkAuthCount() > 1, "Removing-all-authorities"); 95 | AccountInterface(address(this)).disable(authority); 96 | 97 | emit LogRemoveAuth(msg.sender, authority); 98 | 99 | // _eventCode = keccak256("LogRemoveAuth(address,address)"); 100 | _eventName = "LogRemoveAuth(address,address)"; 101 | _eventParam = abi.encode(msg.sender, authority); 102 | } 103 | 104 | } 105 | 106 | 107 | contract ConnectV2Auth is Auth { 108 | constructor(address _instaList) Auth(_instaList) {} 109 | string public constant name = "Auth-v1"; 110 | } -------------------------------------------------------------------------------- /contracts/v2/connectors/test/betamode.test.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.0; 2 | 3 | /** 4 | * @dev betamode connect 5 | */ 6 | 7 | interface AccountInterface { 8 | function enable(address) external; 9 | function disable(address) external; 10 | function isAuth(address) external view returns (bool); 11 | function isBeta() external view returns (bool); 12 | function toggleBeta() external; 13 | } 14 | 15 | contract Events { 16 | event LogEnableBeta(); 17 | event LogDisableBeta(); 18 | } 19 | 20 | abstract contract Resolver is Events { 21 | /** 22 | * @dev Enable beta mode 23 | * @notice enabling beta mode gives early access to new/risky features 24 | */ 25 | function enable() external payable returns (string memory _eventName, bytes memory _eventParam) { 26 | AccountInterface _dsa = AccountInterface(address(this)); 27 | require(!_dsa.isBeta(), "beta-already-enabled"); 28 | _dsa.toggleBeta(); 29 | 30 | _eventName = "LogEnableBeta()"; 31 | } 32 | 33 | /** 34 | * @dev Disable beta mode 35 | * @notice disabling beta mode removes early access to new/risky features 36 | */ 37 | function disable() external payable returns (string memory _eventName, bytes memory _eventParam) { 38 | AccountInterface _dsa = AccountInterface(address(this)); 39 | require(_dsa.isBeta(), "beta-already-disabled"); 40 | _dsa.toggleBeta(); 41 | 42 | _eventName = "LogDisableBeta()"; 43 | } 44 | } 45 | 46 | contract ConnectV2Beta is Resolver { 47 | string public constant name = "Beta-v1"; 48 | } -------------------------------------------------------------------------------- /contracts/v2/connectors/test/compound.test.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.0; 2 | 3 | interface CTokenInterface { 4 | function mint(uint mintAmount) external returns (uint); 5 | function redeem(uint redeemTokens) external returns (uint); 6 | function borrow(uint borrowAmount) external returns (uint); 7 | function repayBorrow(uint repayAmount) external returns (uint); 8 | function repayBorrowBehalf(address borrower, uint repayAmount) external returns (uint); // For ERC20 9 | function liquidateBorrow(address borrower, uint repayAmount, address cTokenCollateral) external returns (uint); 10 | 11 | function borrowBalanceCurrent(address account) external returns (uint); 12 | function redeemUnderlying(uint redeemAmount) external returns (uint); 13 | function exchangeRateCurrent() external returns (uint); 14 | 15 | function balanceOf(address owner) external view returns (uint256 balance); 16 | } 17 | 18 | interface CETHInterface { 19 | function mint() external payable; 20 | function repayBorrow() external payable; 21 | function repayBorrowBehalf(address borrower) external payable; 22 | function liquidateBorrow(address borrower, address cTokenCollateral) external payable; 23 | } 24 | 25 | interface TokenInterface { 26 | function allowance(address, address) external view returns (uint); 27 | function balanceOf(address) external view returns (uint); 28 | function approve(address, uint) external; 29 | function transfer(address, uint) external returns (bool); 30 | function transferFrom(address, address, uint) external returns (bool); 31 | } 32 | 33 | interface ComptrollerInterface { 34 | function enterMarkets(address[] calldata cTokens) external returns (uint[] memory); 35 | function exitMarket(address cTokenAddress) external returns (uint); 36 | function getAssetsIn(address account) external view returns (address[] memory); 37 | function getAccountLiquidity(address account) external view returns (uint, uint, uint); 38 | function claimComp(address) external; 39 | } 40 | 41 | interface InstaMapping { 42 | function cTokenMapping(address) external view returns (address); 43 | } 44 | 45 | interface MemoryInterface { 46 | function getUint(uint _id) external returns (uint _num); 47 | function setUint(uint _id, uint _val) external; 48 | } 49 | 50 | contract DSMath { 51 | 52 | function add(uint x, uint y) internal pure returns (uint z) { 53 | require((z = x + y) >= x, "math-not-safe"); 54 | } 55 | 56 | function mul(uint x, uint y) internal pure returns (uint z) { 57 | require(y == 0 || (z = x * y) / y == x, "math-not-safe"); 58 | } 59 | 60 | uint constant WAD = 10 ** 18; 61 | 62 | function wmul(uint x, uint y) internal pure returns (uint z) { 63 | z = add(mul(x, y), WAD / 2) / WAD; 64 | } 65 | 66 | function wdiv(uint x, uint y) internal pure returns (uint z) { 67 | z = add(mul(x, WAD), y / 2) / y; 68 | } 69 | 70 | function sub(uint x, uint y) internal pure returns (uint z) { 71 | require((z = x - y) <= x, "ds-math-sub-underflow"); 72 | } 73 | 74 | } 75 | 76 | 77 | contract Helpers is DSMath { 78 | /** 79 | * @dev Return ethereum address 80 | */ 81 | function getAddressETH() internal pure returns (address) { 82 | return 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; // ETH Address 83 | } 84 | 85 | /** 86 | * @dev Return Memory Variable Address 87 | */ 88 | function getMemoryAddr() internal pure returns (address) { 89 | return 0x8a5419CfC711B2343c17a6ABf4B2bAFaBb06957F; // InstaMemory Address 90 | } 91 | 92 | /** 93 | * @dev Get Uint value from InstaMemory Contract. 94 | */ 95 | function getUint(uint getId, uint val) internal returns (uint returnVal) { 96 | returnVal = getId == 0 ? val : MemoryInterface(getMemoryAddr()).getUint(getId); 97 | } 98 | 99 | /** 100 | * @dev Set Uint value in InstaMemory Contract. 101 | */ 102 | function setUint(uint setId, uint val) internal { 103 | if (setId != 0) MemoryInterface(getMemoryAddr()).setUint(setId, val); 104 | } 105 | } 106 | 107 | 108 | contract CompoundHelpers is Helpers { 109 | /** 110 | * @dev Return Compound Comptroller Address 111 | */ 112 | function getComptrollerAddress() internal pure returns (address) { 113 | return 0x3d9819210A31b4961b30EF54bE2aeD79B9c9Cd3B; 114 | } 115 | 116 | /** 117 | * @dev Return COMP Token Address. 118 | */ 119 | function getCompTokenAddress() internal pure returns (address) { 120 | return 0xc00e94Cb662C3520282E6f5717214004A7f26888; 121 | } 122 | 123 | /** 124 | * @dev Return InstaDApp Mapping Addresses 125 | */ 126 | function getMappingAddr() internal pure returns (address) { 127 | return 0xe81F70Cc7C0D46e12d70efc60607F16bbD617E88; // InstaMapping Address 128 | } 129 | 130 | /** 131 | * @dev enter compound market 132 | */ 133 | function enterMarket(address cToken) internal { 134 | ComptrollerInterface troller = ComptrollerInterface(getComptrollerAddress()); 135 | address[] memory markets = troller.getAssetsIn(address(this)); 136 | bool isEntered = false; 137 | for (uint i = 0; i < markets.length; i++) { 138 | if (markets[i] == cToken) { 139 | isEntered = true; 140 | } 141 | } 142 | if (!isEntered) { 143 | address[] memory toEnter = new address[](1); 144 | toEnter[0] = cToken; 145 | troller.enterMarkets(toEnter); 146 | } 147 | } 148 | } 149 | 150 | 151 | contract BasicResolver is CompoundHelpers { 152 | event LogDeposit(address indexed token, address cToken, uint256 tokenAmt, uint256 getId, uint256 setId); 153 | event LogWithdraw(address indexed token, address cToken, uint256 tokenAmt, uint256 getId, uint256 setId); 154 | event LogBorrow(address indexed token, address cToken, uint256 tokenAmt, uint256 getId, uint256 setId); 155 | event LogPayback(address indexed token, address cToken, uint256 tokenAmt, uint256 getId, uint256 setId); 156 | 157 | /** 158 | * @dev Deposit ETH/ERC20_Token. 159 | * @param token token address to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) 160 | * @param amt token amount to deposit. 161 | * @param getId Get token amount at this ID from `InstaMemory` Contract. 162 | * @param setId Set token amount at this ID in `InstaMemory` Contract. 163 | */ 164 | function deposit( 165 | address token, 166 | uint amt, 167 | uint getId, 168 | uint setId 169 | ) external payable returns (string memory _eventName, bytes memory _eventParam) { 170 | uint _amt = getUint(getId, amt); 171 | address cToken = InstaMapping(getMappingAddr()).cTokenMapping(token); 172 | enterMarket(cToken); 173 | if (token == getAddressETH()) { 174 | _amt = _amt == uint(-1) ? address(this).balance : _amt; 175 | CETHInterface(cToken).mint{value: _amt}(); 176 | } else { 177 | TokenInterface tokenContract = TokenInterface(token); 178 | _amt = _amt == uint(-1) ? tokenContract.balanceOf(address(this)) : _amt; 179 | tokenContract.approve(cToken, _amt); 180 | require(CTokenInterface(cToken).mint(_amt) == 0, "deposit-failed"); 181 | } 182 | setUint(setId, _amt); 183 | 184 | emit LogDeposit(token, cToken, _amt, getId, setId); 185 | 186 | _eventName = "LogDeposit(address,address,uint256,uint256,uint256)"; 187 | _eventParam = abi.encode(token, cToken, _amt, getId, setId); 188 | } 189 | 190 | /** 191 | * @dev Withdraw ETH/ERC20_Token. 192 | * @param token token address to withdraw.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) 193 | * @param amt token amount to withdraw. 194 | * @param getId Get token amount at this ID from `InstaMemory` Contract. 195 | * @param setId Set token amount at this ID in `InstaMemory` Contract. 196 | */ 197 | function withdraw( 198 | address token, 199 | uint amt, 200 | uint getId, 201 | uint setId 202 | ) external payable returns (string memory _eventName, bytes memory _eventParam) { 203 | uint _amt = getUint(getId, amt); 204 | address cToken = InstaMapping(getMappingAddr()).cTokenMapping(token); 205 | CTokenInterface cTokenContract = CTokenInterface(cToken); 206 | if (_amt == uint(-1)) { 207 | TokenInterface tokenContract = TokenInterface(token); 208 | uint initialBal = token == getAddressETH() ? address(this).balance : tokenContract.balanceOf(address(this)); 209 | require(cTokenContract.redeem(cTokenContract.balanceOf(address(this))) == 0, "full-withdraw-failed"); 210 | uint finalBal = token == getAddressETH() ? address(this).balance : tokenContract.balanceOf(address(this)); 211 | _amt = finalBal - initialBal; 212 | } else { 213 | require(cTokenContract.redeemUnderlying(_amt) == 0, "withdraw-failed"); 214 | } 215 | setUint(setId, _amt); 216 | 217 | emit LogWithdraw(token, cToken, _amt, getId, setId); 218 | 219 | _eventName = "LogWithdraw(address,address,uint256,uint256,uint256)"; 220 | _eventParam = abi.encode(token, cToken, _amt, getId, setId); 221 | } 222 | 223 | /** 224 | * @dev Borrow ETH/ERC20_Token. 225 | * @param token token address to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) 226 | * @param amt token amount to borrow. 227 | * @param getId Get token amount at this ID from `InstaMemory` Contract. 228 | * @param setId Set token amount at this ID in `InstaMemory` Contract. 229 | */ 230 | function borrow( 231 | address token, 232 | uint amt, 233 | uint getId, 234 | uint setId 235 | ) external payable returns (string memory _eventName, bytes memory _eventParam) { 236 | uint _amt = getUint(getId, amt); 237 | address cToken = InstaMapping(getMappingAddr()).cTokenMapping(token); 238 | enterMarket(cToken); 239 | require(CTokenInterface(cToken).borrow(_amt) == 0, "borrow-failed"); 240 | setUint(setId, _amt); 241 | 242 | emit LogBorrow(token, cToken, _amt, getId, setId); 243 | 244 | _eventName = "LogBorrow(address,address,uint256,uint256,uint256)"; 245 | _eventParam = abi.encode(token, cToken, _amt, getId, setId); 246 | } 247 | 248 | /** 249 | * @dev Payback borrowed ETH/ERC20_Token. 250 | * @param token token address to payback.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) 251 | * @param amt token amount to payback. 252 | * @param getId Get token amount at this ID from `InstaMemory` Contract. 253 | * @param setId Set token amount at this ID in `InstaMemory` Contract. 254 | */ 255 | function payback( 256 | address token, 257 | uint amt, 258 | uint getId, 259 | uint setId 260 | ) external payable returns (string memory _eventName, bytes memory _eventParam) { 261 | uint _amt = getUint(getId, amt); 262 | address cToken = InstaMapping(getMappingAddr()).cTokenMapping(token); 263 | CTokenInterface cTokenContract = CTokenInterface(cToken); 264 | _amt = _amt == uint(-1) ? cTokenContract.borrowBalanceCurrent(address(this)) : _amt; 265 | 266 | if (token == getAddressETH()) { 267 | require(address(this).balance >= _amt, "not-enough-eth"); 268 | CETHInterface(cToken).repayBorrow{value: _amt}(); 269 | } else { 270 | TokenInterface tokenContract = TokenInterface(token); 271 | require(tokenContract.balanceOf(address(this)) >= _amt, "not-enough-token"); 272 | tokenContract.approve(cToken, _amt); 273 | require(cTokenContract.repayBorrow(_amt) == 0, "repay-failed."); 274 | } 275 | setUint(setId, _amt); 276 | 277 | emit LogPayback(token, cToken, _amt, getId, setId); 278 | 279 | _eventName = "LogPayback(address,address,uint256,uint256,uint256)"; 280 | _eventParam = abi.encode(token, cToken, _amt, getId, setId); 281 | } 282 | } 283 | 284 | contract ConnectCompound is BasicResolver { 285 | string public name = "Compound-v1"; 286 | } 287 | -------------------------------------------------------------------------------- /contracts/v2/connectors/test/connector.registry.test.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.0; 2 | pragma experimental ABIEncoderV2; 3 | 4 | /** 5 | * @title InstaConnectorsV2 6 | * @dev Registry for Connectors. 7 | */ 8 | 9 | interface IndexInterface { 10 | function master() external view returns (address); 11 | } 12 | 13 | interface ConnectorInterface { 14 | function name() external view returns (string memory); 15 | } 16 | 17 | contract Controllers { 18 | event LogController(address indexed addr, bool indexed isChief); 19 | 20 | // InstaIndex Address. 21 | address public immutable instaIndex; 22 | 23 | constructor(address _instaIndex) { 24 | instaIndex = _instaIndex; 25 | } 26 | 27 | // Enabled Chief(Address of Chief => bool). 28 | mapping(address => bool) public chief; 29 | // Enabled Connectors(Connector name => address). 30 | mapping(string => address) public connectors; 31 | 32 | /** 33 | * @dev Throws if the sender not is Master Address from InstaIndex 34 | * or Enabled Chief. 35 | */ 36 | modifier isChief() { 37 | require( 38 | chief[msg.sender] || 39 | msg.sender == IndexInterface(instaIndex).master(), 40 | "not-an-chief" 41 | ); 42 | _; 43 | } 44 | 45 | /** 46 | * @dev Toggle a Chief. Enable if disable & vice versa 47 | * @param _chiefAddress Chief Address. 48 | */ 49 | function toggleChief(address _chiefAddress) external { 50 | require( 51 | msg.sender == IndexInterface(instaIndex).master(), 52 | "toggleChief: not-master" 53 | ); 54 | chief[_chiefAddress] = !chief[_chiefAddress]; 55 | emit LogController(_chiefAddress, chief[_chiefAddress]); 56 | } 57 | } 58 | 59 | contract InstaConnectorsV2Test is Controllers { 60 | event LogConnectorAdded( 61 | bytes32 indexed connectorNameHash, 62 | string connectorName, 63 | address indexed connector 64 | ); 65 | event LogConnectorUpdated( 66 | bytes32 indexed connectorNameHash, 67 | string connectorName, 68 | address indexed oldConnector, 69 | address indexed newConnector 70 | ); 71 | event LogConnectorRemoved( 72 | bytes32 indexed connectorNameHash, 73 | string connectorName, 74 | address indexed connector 75 | ); 76 | 77 | constructor(address _instaIndex) public Controllers(_instaIndex) {} 78 | 79 | /** 80 | * @dev Add Connectors 81 | * @param _connectorNames Array of Connector Names. 82 | * @param _connectors Array of Connector Address. 83 | */ 84 | function addConnectors( 85 | string[] calldata _connectorNames, 86 | address[] calldata _connectors 87 | ) external isChief { 88 | require( 89 | _connectorNames.length == _connectors.length, 90 | "addConnectors: not same length" 91 | ); 92 | for (uint256 i = 0; i < _connectors.length; i++) { 93 | require( 94 | connectors[_connectorNames[i]] == address(0), 95 | "addConnectors: _connectorName added already" 96 | ); 97 | require( 98 | _connectors[i] != address(0), 99 | "addConnectors: _connectors address not vaild" 100 | ); 101 | ConnectorInterface(_connectors[i]).name(); // Checking if connector has function name() 102 | connectors[_connectorNames[i]] = _connectors[i]; 103 | emit LogConnectorAdded( 104 | keccak256(abi.encodePacked(_connectorNames[i])), 105 | _connectorNames[i], 106 | _connectors[i] 107 | ); 108 | } 109 | } 110 | 111 | /** 112 | * @dev Update Connectors 113 | * @param _connectorNames Array of Connector Names. 114 | * @param _connectors Array of Connector Address. 115 | */ 116 | function updateConnectors( 117 | string[] calldata _connectorNames, 118 | address[] calldata _connectors 119 | ) external isChief { 120 | require( 121 | _connectorNames.length == _connectors.length, 122 | "updateConnectors: not same length" 123 | ); 124 | for (uint256 i = 0; i < _connectors.length; i++) { 125 | require( 126 | connectors[_connectorNames[i]] != address(0), 127 | "updateConnectors: _connectorName not added to update" 128 | ); 129 | require( 130 | _connectors[i] != address(0), 131 | "updateConnectors: _connector address is not vaild" 132 | ); 133 | ConnectorInterface(_connectors[i]).name(); // Checking if connector has function name() 134 | emit LogConnectorUpdated( 135 | keccak256(abi.encodePacked(_connectorNames[i])), 136 | _connectorNames[i], 137 | connectors[_connectorNames[i]], 138 | _connectors[i] 139 | ); 140 | connectors[_connectorNames[i]] = _connectors[i]; 141 | } 142 | } 143 | 144 | /** 145 | * @dev Remove Connectors 146 | * @param _connectorNames Array of Connector Names. 147 | */ 148 | function removeConnectors(string[] calldata _connectorNames) 149 | external 150 | isChief 151 | { 152 | for (uint256 i = 0; i < _connectorNames.length; i++) { 153 | require( 154 | connectors[_connectorNames[i]] != address(0), 155 | "removeConnectors: _connectorName not added to update" 156 | ); 157 | emit LogConnectorRemoved( 158 | keccak256(abi.encodePacked(_connectorNames[i])), 159 | _connectorNames[i], 160 | connectors[_connectorNames[i]] 161 | ); 162 | delete connectors[_connectorNames[i]]; 163 | } 164 | } 165 | 166 | /** 167 | * @dev Check if Connector addresses are enabled. 168 | * @param _connectors Array of Connector Names. 169 | */ 170 | function isConnectors(string[] calldata _connectorNames) 171 | external 172 | view 173 | returns (bool isOk, address[] memory _connectors) 174 | { 175 | isOk = true; 176 | uint256 len = _connectorNames.length; 177 | _connectors = new address[](len); 178 | for (uint256 i = 0; i < _connectors.length; i++) { 179 | _connectors[i] = connectors[_connectorNames[i]]; 180 | } 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /contracts/v2/connectors/test/emitEvent.test.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.0; 2 | 3 | contract ConnectV2EmitEvent { 4 | 5 | event LogEmitEvent(address indexed dsaAddress, address indexed _sender); 6 | 7 | function emitEvent() public payable returns (string memory _eventName, bytes memory _eventParam) { 8 | emit LogEmitEvent(address(this), msg.sender); 9 | 10 | _eventName = "LogEmitEvent(address,address)"; 11 | _eventParam = abi.encode(address(this), msg.sender); 12 | } 13 | 14 | string constant public name = "EmitEvent-v1"; 15 | } -------------------------------------------------------------------------------- /contracts/v2/proxy/accountProxy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.7.0; 3 | 4 | interface AccountImplementations { 5 | function getImplementation(bytes4 _sig) external view returns (address); 6 | } 7 | 8 | /** 9 | * @dev This abstract contract provides a fallback function that delegates all calls to another contract using the EVM 10 | * instruction `delegatecall`. 11 | */ 12 | contract InstaAccountV2 { 13 | 14 | AccountImplementations public immutable implementations; 15 | 16 | constructor(address _implementations) { 17 | implementations = AccountImplementations(_implementations); 18 | } 19 | 20 | /** 21 | * @dev Delegates the current call to `implementation`. 22 | * 23 | * This function does not return to its internall call site, it will return directly to the external caller. 24 | */ 25 | function _delegate(address implementation) internal { 26 | // solhint-disable-next-line no-inline-assembly 27 | assembly { 28 | // Copy msg.data. We take full control of memory in this inline assembly 29 | // block because it will not return to Solidity code. We overwrite the 30 | // Solidity scratch pad at memory position 0. 31 | calldatacopy(0, 0, calldatasize()) 32 | 33 | // Call the implementation. 34 | // out and outsize are 0 because we don't know the size yet. 35 | let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0) 36 | 37 | // Copy the returned data. 38 | returndatacopy(0, 0, returndatasize()) 39 | 40 | switch result 41 | // delegatecall returns 0 on error. 42 | case 0 { revert(0, returndatasize()) } 43 | default { return(0, returndatasize()) } 44 | } 45 | } 46 | 47 | /** 48 | * @dev Delegates the current call to the address returned by Implementations registry. 49 | * 50 | * This function does not return to its internall call site, it will return directly to the external caller. 51 | */ 52 | function _fallback(bytes4 _sig) internal { 53 | address _implementation = implementations.getImplementation(_sig); 54 | require(_implementation != address(0), "InstaAccountV2: Not able to find _implementation"); 55 | _delegate(_implementation); 56 | } 57 | 58 | /** 59 | * @dev Fallback function that delegates calls to the address returned by Implementations registry. 60 | */ 61 | fallback () external payable { 62 | _fallback(msg.sig); 63 | } 64 | 65 | /** 66 | * @dev Fallback function that delegates calls to the address returned by Implementations registry. 67 | */ 68 | receive () external payable { 69 | if (msg.sig != 0x00000000) { 70 | _fallback(msg.sig); 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /contracts/v2/proxy/connectorsProxy.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.7.0; 3 | 4 | import "@openzeppelin/contracts/proxy/TransparentUpgradeableProxy.sol"; 5 | 6 | contract InstaConnectorsV2Proxy is TransparentUpgradeableProxy { 7 | constructor(address _logic, address admin_, bytes memory _data) public TransparentUpgradeableProxy(_logic, admin_, _data) {} 8 | } -------------------------------------------------------------------------------- /contracts/v2/proxy/dummyConnectorsImpl.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.0; 2 | 3 | contract InstaConnectorsV2Impl { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /contracts/v2/registry/connectors.sol: -------------------------------------------------------------------------------- 1 | pragma solidity ^0.7.0; 2 | pragma experimental ABIEncoderV2; 3 | 4 | /** 5 | * @title InstaConnectorsV2 6 | * @dev Registry for Connectors. 7 | */ 8 | 9 | interface IndexInterface { 10 | function master() external view returns (address); 11 | } 12 | 13 | interface ConnectorInterface { 14 | function name() external view returns (string memory); 15 | } 16 | 17 | contract Controllers { 18 | 19 | event LogController(address indexed addr, bool indexed isChief); 20 | 21 | // InstaIndex Address. 22 | address public immutable instaIndex; 23 | 24 | constructor(address _instaIndex) { 25 | instaIndex = _instaIndex; 26 | } 27 | 28 | // Enabled Chief(Address of Chief => bool). 29 | mapping(address => bool) public chief; 30 | // Enabled Connectors(Connector name => address). 31 | mapping(string => address) public connectors; 32 | 33 | /** 34 | * @dev Throws if the sender not is Master Address from InstaIndex 35 | * or Enabled Chief. 36 | */ 37 | modifier isChief { 38 | require(chief[msg.sender] || msg.sender == IndexInterface(instaIndex).master(), "not-an-chief"); 39 | _; 40 | } 41 | 42 | /** 43 | * @dev Toggle a Chief. Enable if disable & vice versa 44 | * @param _chiefAddress Chief Address. 45 | */ 46 | function toggleChief(address _chiefAddress) external { 47 | require(msg.sender == IndexInterface(instaIndex).master(), "toggleChief: not-master"); 48 | chief[_chiefAddress] = !chief[_chiefAddress]; 49 | emit LogController(_chiefAddress, chief[_chiefAddress]); 50 | } 51 | } 52 | 53 | 54 | contract InstaConnectorsV2 is Controllers { 55 | event LogConnectorAdded( 56 | bytes32 indexed connectorNameHash, 57 | string connectorName, 58 | address indexed connector 59 | ); 60 | event LogConnectorUpdated( 61 | bytes32 indexed connectorNameHash, 62 | string connectorName, 63 | address indexed oldConnector, 64 | address indexed newConnector 65 | ); 66 | event LogConnectorRemoved( 67 | bytes32 indexed connectorNameHash, 68 | string connectorName, 69 | address indexed connector 70 | ); 71 | 72 | constructor(address _instaIndex) public Controllers(_instaIndex) {} 73 | 74 | /** 75 | * @dev Add Connectors 76 | * @param _connectorNames Array of Connector Names. 77 | * @param _connectors Array of Connector Address. 78 | */ 79 | function addConnectors(string[] calldata _connectorNames, address[] calldata _connectors) external isChief { 80 | require(_connectorNames.length == _connectors.length, "addConnectors: not same length"); 81 | for (uint i = 0; i < _connectors.length; i++) { 82 | require(connectors[_connectorNames[i]] == address(0), "addConnectors: _connectorName added already"); 83 | require(_connectors[i] != address(0), "addConnectors: _connectors address not vaild"); 84 | ConnectorInterface(_connectors[i]).name(); // Checking if connector has function name() 85 | connectors[_connectorNames[i]] = _connectors[i]; 86 | emit LogConnectorAdded(keccak256(abi.encodePacked(_connectorNames[i])), _connectorNames[i], _connectors[i]); 87 | } 88 | } 89 | 90 | /** 91 | * @dev Update Connectors 92 | * @param _connectorNames Array of Connector Names. 93 | * @param _connectors Array of Connector Address. 94 | */ 95 | function updateConnectors(string[] calldata _connectorNames, address[] calldata _connectors) external isChief { 96 | require(_connectorNames.length == _connectors.length, "updateConnectors: not same length"); 97 | for (uint i = 0; i < _connectors.length; i++) { 98 | require(connectors[_connectorNames[i]] != address(0), "updateConnectors: _connectorName not added to update"); 99 | require(_connectors[i] != address(0), "updateConnectors: _connector address is not vaild"); 100 | ConnectorInterface(_connectors[i]).name(); // Checking if connector has function name() 101 | emit LogConnectorUpdated(keccak256(abi.encodePacked(_connectorNames[i])), _connectorNames[i], connectors[_connectorNames[i]], _connectors[i]); 102 | connectors[_connectorNames[i]] = _connectors[i]; 103 | } 104 | } 105 | 106 | /** 107 | * @dev Remove Connectors 108 | * @param _connectorNames Array of Connector Names. 109 | */ 110 | function removeConnectors(string[] calldata _connectorNames) external isChief { 111 | for (uint i = 0; i < _connectorNames.length; i++) { 112 | require(connectors[_connectorNames[i]] != address(0), "removeConnectors: _connectorName not added to update"); 113 | emit LogConnectorRemoved(keccak256(abi.encodePacked(_connectorNames[i])), _connectorNames[i], connectors[_connectorNames[i]]); 114 | delete connectors[_connectorNames[i]]; 115 | } 116 | } 117 | 118 | /** 119 | * @dev Check if Connector addresses are enabled. 120 | * @param _connectors Array of Connector Names. 121 | */ 122 | function isConnectors(string[] calldata _connectorNames) external view returns (bool isOk, address[] memory _connectors) { 123 | isOk = true; 124 | uint len = _connectorNames.length; 125 | _connectors = new address[](len); 126 | for (uint i = 0; i < _connectors.length; i++) { 127 | _connectors[i] = connectors[_connectorNames[i]]; 128 | if (_connectors[i] == address(0)) { 129 | isOk = false; 130 | break; 131 | } 132 | } 133 | } 134 | } -------------------------------------------------------------------------------- /contracts/v2/registry/implementations.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.7.0; 3 | 4 | interface IndexInterface { 5 | function master() external view returns (address); 6 | } 7 | 8 | contract Setup { 9 | address public defaultImplementation; 10 | 11 | mapping (bytes4 => address) internal sigImplementations; 12 | 13 | mapping (address => bytes4[]) internal implementationSigs; 14 | } 15 | 16 | contract Implementations is Setup { 17 | event LogSetDefaultImplementation(address indexed oldImplementation, address indexed newImplementation); 18 | event LogAddImplementation(address indexed implementation, bytes4[] sigs); 19 | event LogRemoveImplementation(address indexed implementation, bytes4[] sigs); 20 | 21 | IndexInterface immutable public instaIndex; 22 | 23 | constructor(address _instaIndex) { 24 | instaIndex = IndexInterface(_instaIndex); 25 | } 26 | 27 | modifier isMaster() { 28 | require(msg.sender == instaIndex.master(), "Implementations: not-master"); 29 | _; 30 | } 31 | 32 | function setDefaultImplementation(address _defaultImplementation) external isMaster { 33 | require(_defaultImplementation != address(0), "Implementations: _defaultImplementation address not valid"); 34 | require(_defaultImplementation != defaultImplementation, "Implementations: _defaultImplementation cannot be same"); 35 | emit LogSetDefaultImplementation(defaultImplementation, _defaultImplementation); 36 | defaultImplementation = _defaultImplementation; 37 | } 38 | 39 | function addImplementation(address _implementation, bytes4[] calldata _sigs) external isMaster { 40 | require(_implementation != address(0), "Implementations: _implementation not valid."); 41 | require(implementationSigs[_implementation].length == 0, "Implementations: _implementation already added."); 42 | for (uint i = 0; i < _sigs.length; i++) { 43 | bytes4 _sig = _sigs[i]; 44 | require(sigImplementations[_sig] == address(0), "Implementations: _sig already added"); 45 | sigImplementations[_sig] = _implementation; 46 | } 47 | implementationSigs[_implementation] = _sigs; 48 | emit LogAddImplementation(_implementation, _sigs); 49 | } 50 | 51 | function removeImplementation(address _implementation) external isMaster { 52 | require(_implementation != address(0), "Implementations: _implementation not valid."); 53 | require(implementationSigs[_implementation].length != 0, "Implementations: _implementation not found."); 54 | bytes4[] memory sigs = implementationSigs[_implementation]; 55 | for (uint i = 0; i < sigs.length; i++) { 56 | bytes4 sig = sigs[i]; 57 | delete sigImplementations[sig]; 58 | } 59 | delete implementationSigs[_implementation]; 60 | emit LogRemoveImplementation(_implementation, sigs); 61 | 62 | } 63 | } 64 | 65 | contract InstaImplementations is Implementations { 66 | constructor(address _instaIndex) public Implementations(_instaIndex) {} 67 | 68 | function getImplementation(bytes4 _sig) external view returns (address) { 69 | address _implementation = sigImplementations[_sig]; 70 | return _implementation == address(0) ? defaultImplementation : _implementation; 71 | } 72 | 73 | function getImplementationSigs(address _impl) external view returns (bytes4[] memory) { 74 | return implementationSigs[_impl]; 75 | } 76 | 77 | function getSigImplementation(bytes4 _sig) external view returns (address) { 78 | return sigImplementations[_sig]; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /contracts/v2/timelock/chiefTimelock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.7.0; 3 | pragma experimental ABIEncoderV2; 4 | 5 | import { TimelockController } from "@openzeppelin/contracts/access/TimelockController.sol"; 6 | 7 | interface IndexInterface { 8 | function master() external view returns (address); 9 | function changeMaster(address) external; 10 | function updateMaster() external; 11 | } 12 | 13 | contract InstaChiefTimelockContract is TimelockController { 14 | 15 | constructor (address[] memory chiefMultiSig) public TimelockController(2 days, chiefMultiSig, chiefMultiSig) { 16 | require(chiefMultiSig.length == 1, "chiefMultiSig length != 1"); 17 | } 18 | } -------------------------------------------------------------------------------- /contracts/v2/timelock/timelock.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.7.0; 3 | pragma experimental ABIEncoderV2; 4 | 5 | import {TimelockController} from "@openzeppelin/contracts/access/TimelockController.sol"; 6 | import { Initializable } from "@openzeppelin/contracts/proxy/Initializable.sol"; 7 | 8 | interface IndexInterface { 9 | function master() external view returns (address); 10 | function changeMaster(address) external; 11 | function updateMaster() external; 12 | } 13 | 14 | contract InstaTimelockContract is Initializable, TimelockController { 15 | 16 | IndexInterface constant public instaIndex = IndexInterface(0x2971AdFa57b20E5a416aE5a708A8655A9c74f723); 17 | address constant public governanceTimelock = 0xC7Cb1dE2721BFC0E0DA1b9D526bCdC54eF1C0eFC; 18 | 19 | constructor (address[] memory masterSig) public TimelockController(10 days, masterSig, masterSig){ 20 | } 21 | 22 | function initialize() external initializer { 23 | instaIndex.updateMaster(); 24 | instaIndex.changeMaster(governanceTimelock); 25 | } 26 | } -------------------------------------------------------------------------------- /docs/addresses.json: -------------------------------------------------------------------------------- 1 | { 2 | "mainnet": { 3 | "InstaIndex": "0x2971AdFa57b20E5a416aE5a708A8655A9c74f723", 4 | "InstaList": "0x4c8a1BEb8a87765788946D6B19C6C6355194AbEb", 5 | "versions": { 6 | "v1": { 7 | "InstaAccount": "0x939Daad09fC4A9B8f8A9352A485DAb2df4F4B3F8", 8 | "InstaConnectors": "0xD6A602C01a023B98Ecfb29Df02FBA380d3B21E0c", 9 | "InstaEvent": "0x2af7ea6Cb911035f3eb1ED895Cb6692C39ecbA97", 10 | "InstaMemory": "0x8a5419CfC711B2343c17a6ABf4B2bAFaBb06957F" 11 | }, 12 | "v2": { 13 | "InstaAccountV2": "0xFE02a32Cbe0CB9ad9A945576A5bb53A3C123A3A3", 14 | "InstaConnectorsV2Proxy": "0x7D53E606308A2E0A1D396F30dc305cc7f8483436", 15 | "InstaConnectorsV2": "0x97b0B3A8bDeFE8cB9563a3c610019Ad10DB8aD11", 16 | "InstaImplementations": "0xCBA828153d3a85b30B5b912e1f2daCac5816aE9D", 17 | "InstaDefaultImplementation": "0x28aDcDC02Ca7B3EDf11924102726066AA0fA7010", 18 | "InstaImplementationM1": "0x8a3462A50e1a9Fe8c9e7d9023CAcbD9a98D90021", 19 | "InstaChiefTimelockContract": "0xb3e586BCE929312e8B0685E2c12c1d6dbbcdc370" 20 | } 21 | } 22 | }, 23 | "polygon": { 24 | "InstaIndex": "0xA9B99766E6C676Cf1975c0D3166F96C0848fF5ad", 25 | "InstaList": "0x839c2D3aDe63DF5b0b8F3E57D5e145057Ab41556", 26 | "versions": { 27 | "v1": { 28 | "InstaAccount": "0xA7c805e4ad4E7B51d2a1eB442B2014a9B63D3703", 29 | "InstaConnectors": "0x3254Ce8f5b1c82431B8f21Df01918342215825C2", 30 | "InstaEvent": "0xA4BF319968986D2352FA1c550D781bBFCCE3FcaB", 31 | "InstaMemory": "0x6C7256cf7C003dD85683339F75DdE9971f98f2FD" 32 | }, 33 | "v2": { 34 | "InstaAccountV2": "0x28846f4051EB05594B3fF9dE76b7B5bf00431155", 35 | "InstaConnectorsV2Proxy": "0x01fEF4d2B513C9F69E34b2f93Ef707FA9Ff60109", 36 | "InstaConnectorsV2": "0x2A00684bFAb9717C21271E0751BCcb7d2D763c88", 37 | "InstaImplementations": "0x39d3d5e7c11D61E072511485878dd84711c19d4A", 38 | "InstaDefaultImplementation": "0xFc8CcEFeB8bD4e637C787c70F7bf7c2E7Ba9aDdf", 39 | "InstaImplementationM1": "0x4aec8c5b1cf3498bef061e13d8e7f646feeb7029", 40 | "InstaImplementationM2": "0x2638c8950e04ef002d083f62aeaa10ee32f1ae60" 41 | } 42 | } 43 | }, 44 | "arbitrum": { 45 | "InstaIndex": "0x1eE00C305C51Ff3bE60162456A9B533C07cD9288", 46 | "InstaList": "0x3565F6057b7fFE36984779A507fC87b31EFb0f09", 47 | "versions": { 48 | "v1": { 49 | "InstaAccount": "0xeD06918EEA2C241D51230aB9e226276dE939C979", 50 | "InstaConnectors": "0xE1594fd3603EDe6502A1cbC73489a26587Dc68BF", 51 | "InstaEvent": "0xDF64FCfe45Df50db726bBB90c9Aff84879586D1C", 52 | "InstaMemory": "0xc109f7Ef06152c3a63dc7254fD861E612d3Ac571" 53 | }, 54 | "v2": { 55 | "InstaAccountV2": "0x857f3b524317C0C403EC40e01837F1B160F9E7Ab", 56 | "InstaConnectorsV2Proxy": "0xFD48Bef7F198B561D5198bE19c14142a0574b859", 57 | "InstaConnectorsV2": "0x67fCE99Dd6d8d659eea2a1ac1b8881c57eb6592B", 58 | "InstaImplementations": "0xF3Bb2FbdCDa1B8B6d19f513D69462eA548d0eF12", 59 | "InstaDefaultImplementation": "0x0C25490d97594D513Fd8a80C51e4900252fA18bF", 60 | "InstaImplementationM1": "0x3d464f9762493a7Cecb59119a8eCdd54e46b969F" 61 | } 62 | } 63 | }, 64 | "avax": { 65 | "InstaIndex": "0x6CE3e607C808b4f4C26B7F6aDAeB619e49CAbb25", 66 | "InstaList": "0x9926955e0Dd681Dc303370C52f4Ad0a4dd061687", 67 | "versions": { 68 | "v1": { 69 | "InstaAccount": "0xA9B99766E6C676Cf1975c0D3166F96C0848fF5ad", 70 | "InstaConnectors": "0x839c2D3aDe63DF5b0b8F3E57D5e145057Ab41556", 71 | "InstaEvent": "0xA7c805e4ad4E7B51d2a1eB442B2014a9B63D3703", 72 | "InstaMemory": "0x3254Ce8f5b1c82431B8f21Df01918342215825C2" 73 | }, 74 | "v2": { 75 | "InstaAccountV2": "0x0a0a82D2F86b9E46AE60E22FCE4e8b916F858Ddc", 76 | "InstaConnectorsV2Proxy": "0x6C7256cf7C003dD85683339F75DdE9971f98f2FD", 77 | "InstaConnectorsV2": "0x127d8cD0E2b2E0366D522DeA53A787bfE9002C14", 78 | "InstaImplementations": "0x01fEF4d2B513C9F69E34b2f93Ef707FA9Ff60109", 79 | "InstaDefaultImplementation": "0x39d3d5e7c11D61E072511485878dd84711c19d4A", 80 | "InstaImplementationM1": "0x28846f4051EB05594B3fF9dE76b7B5bf00431155" 81 | } 82 | } 83 | }, 84 | "optimism": { 85 | "InstaIndex": "0x6CE3e607C808b4f4C26B7F6aDAeB619e49CAbb25", 86 | "InstaList": "0x9926955e0Dd681Dc303370C52f4Ad0a4dd061687", 87 | "versions": { 88 | "v1": { 89 | "InstaAccount": "0xA9B99766E6C676Cf1975c0D3166F96C0848fF5ad", 90 | "InstaConnectors": "0x839c2D3aDe63DF5b0b8F3E57D5e145057Ab41556", 91 | "InstaEvent": "0xA7c805e4ad4E7B51d2a1eB442B2014a9B63D3703", 92 | "InstaMemory": "0x3254Ce8f5b1c82431B8f21Df01918342215825C2" 93 | }, 94 | "v2": { 95 | "InstaAccountV2": "0x0a0a82D2F86b9E46AE60E22FCE4e8b916F858Ddc", 96 | "InstaConnectorsV2Proxy": "0x6C7256cf7C003dD85683339F75DdE9971f98f2FD", 97 | "InstaConnectorsV2": "0x127d8cD0E2b2E0366D522DeA53A787bfE9002C14", 98 | "InstaImplementations": "0x01fEF4d2B513C9F69E34b2f93Ef707FA9Ff60109", 99 | "InstaDefaultImplementation": "0x39d3d5e7c11D61E072511485878dd84711c19d4A", 100 | "InstaImplementationM1": "0x28846f4051EB05594B3fF9dE76b7B5bf00431155" 101 | } 102 | } 103 | }, 104 | "fantom": { 105 | "InstaIndex": "0x2fa042BEEB7A40A7078EaA5aC755e3842248292b", 106 | "InstaList": "0x10e166c3FAF887D8a61dE6c25039231eE694E926", 107 | "versions": { 108 | "v1": { 109 | "InstaAccount": "0x97dC007cdb5198Bb0aC3b021560B03e8e673aEC8", 110 | "InstaConnectors": "0x2c58Ea01B0CD0cF539a8772383D9d6CBCa5A113d", 111 | "InstaEvent": "0x8D4E8B7B4F456166B63f953B6ad976141190bb72", 112 | "InstaMemory": "0x56439117379A53bE3CC2C55217251e2481B7a1C8" 113 | }, 114 | "v2": { 115 | "InstaAccountV2": "0x1a0862ecA9eAc5028aBdf85bD095fd13a7eebA2f", 116 | "InstaConnectorsV2Proxy": "0xda9B270A5525BF9d441eCAAa89315bC5FA3a97E5", 117 | "InstaConnectorsV2": "0x819910794a030403F69247E1e5C0bBfF1593B968", 118 | "InstaImplementations": "0xF0b36681C9d3ED74227880646De41c4a979AC191", 119 | "InstaDefaultImplementation": "0xC03e0427ED59de7E2895a3AE4203df3872a68643", 120 | "InstaImplementationM1": "0xd99C200bfE30F0AA602E01fa4E3a88Be5B23DED7" 121 | } 122 | } 123 | }, 124 | "base": { 125 | "InstaIndex": "0x6CE3e607C808b4f4C26B7F6aDAeB619e49CAbb25", 126 | "InstaList": "0x9926955e0Dd681Dc303370C52f4Ad0a4dd061687", 127 | "versions": { 128 | "v1": { 129 | "InstaAccount": "0xA9B99766E6C676Cf1975c0D3166F96C0848fF5ad", 130 | "InstaConnectors": "0x839c2D3aDe63DF5b0b8F3E57D5e145057Ab41556", 131 | "InstaEvent": "0xA7c805e4ad4E7B51d2a1eB442B2014a9B63D3703", 132 | "InstaMemory": "0x3254Ce8f5b1c82431B8f21Df01918342215825C2" 133 | }, 134 | "v2": { 135 | "InstaAccountV2": "0xA4BF319968986D2352FA1c550D781bBFCCE3FcaB", 136 | "InstaConnectorsV2Proxy": "0x6C7256cf7C003dD85683339F75DdE9971f98f2FD", 137 | "InstaConnectorsV2": "0x127d8cD0E2b2E0366D522DeA53A787bfE9002C14", 138 | "InstaImplementations": "0x01fEF4d2B513C9F69E34b2f93Ef707FA9Ff60109", 139 | "InstaDefaultImplementation": "0x39d3d5e7c11D61E072511485878dd84711c19d4A", 140 | "InstaImplementationM1": "0x28846f4051EB05594B3fF9dE76b7B5bf00431155" 141 | } 142 | } 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /hardhat.config.ts: -------------------------------------------------------------------------------- 1 | // // Buidler 2 | import "@nomiclabs/hardhat-ethers"; 3 | import "@nomiclabs/hardhat-waffle"; 4 | import "@nomiclabs/hardhat-web3"; 5 | import "@nomiclabs/hardhat-etherscan"; 6 | import "@tenderly/hardhat-tenderly"; 7 | import "hardhat-deploy"; 8 | import "hardhat-deploy-ethers"; 9 | import "@openzeppelin/hardhat-upgrades"; 10 | import "@typechain/hardhat"; 11 | import "hardhat-gas-reporter"; 12 | import "solidity-coverage"; 13 | 14 | import { resolve } from "path"; 15 | import { config as dotenvConfig } from "dotenv"; 16 | import { HardhatUserConfig } from "hardhat/config"; 17 | import { NetworkUserConfig } from "hardhat/types"; 18 | import { utils } from "ethers"; 19 | import Web3 from "web3"; 20 | 21 | dotenvConfig({ path: resolve(__dirname, "./.env") }); 22 | 23 | const chainIds = { 24 | ganache: 1337, 25 | hardhat: 31337, 26 | mainnet: 1, 27 | avalanche: 43114, 28 | polygon: 137, 29 | arbitrum: 42161, 30 | }; 31 | 32 | const ALCHEMY_ID = process.env.ALCHEMY_ID; 33 | const PRIVATE_KEY = process.env.PRIVATE_KEY; 34 | const ETHERSCAN_API = process.env.ETHERSCAN_API_KEY; 35 | const POLYGONSCAN_API = process.env.POLYGON_API_KEY; 36 | const ARBISCAN_API = process.env.ARBISCAN_API_KEY; 37 | const SNOWTRACE_API = process.env.SNOWTRACE_API_KEY; 38 | const mnemonic = 39 | process.env.MNEMONIC ?? 40 | "test test test test test test test test test test test junk"; 41 | 42 | function createConfig(network: string) { 43 | return { 44 | url: getNetworkUrl(network), 45 | accounts: !!PRIVATE_KEY ? [`0x${PRIVATE_KEY}`] : { mnemonic }, 46 | timeout: 150000, 47 | }; 48 | } 49 | 50 | function getNetworkUrl(networkType: string) { 51 | if (networkType === "avalanche") 52 | return "https://api.avax.network/ext/bc/C/rpc"; 53 | else if (networkType === "polygon") 54 | return `https://polygon-mainnet.g.alchemy.com/v2/${ALCHEMY_ID}`; 55 | else if (networkType === "arbitrum") 56 | return `https://arb-mainnet.g.alchemy.com/v2/${ALCHEMY_ID}`; 57 | else if (networkType === "kovan") 58 | return `https://arb-mainnet.g.alchemy.com/v2/${ALCHEMY_ID}`; 59 | else return `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_ID}`; 60 | } 61 | const INSTA_MASTER = "0xb1DC62EC38E6E3857a887210C38418E4A17Da5B2"; 62 | 63 | // ================================= CONFIG ========================================= 64 | const config = { 65 | defaultNetwork: "hardhat", 66 | gasReporter: { 67 | enabled: true, 68 | currency: "ETH", 69 | coinmarketcap: process.env.COINMARKETCAP_API_KEY 70 | }, 71 | tenderly: { 72 | project: "team-development", 73 | username: "InstaDApp", 74 | forkNetwork: "1", 75 | }, 76 | networks: { 77 | hardhat: { 78 | forking: { 79 | url: String(getNetworkUrl(String(process.env.networkType))), 80 | // blockNumber: 11739260,` 81 | blockNumber: 15010000, 82 | }, 83 | blockGasLimit: 12000000, 84 | masterAddress: INSTA_MASTER, 85 | }, 86 | kovan: createConfig("kovan"), 87 | mainnet: createConfig("mainnet"), 88 | matic: createConfig("polygon"), 89 | avax: createConfig("avalanche"), 90 | arbitrum: createConfig("arbitrum"), 91 | }, 92 | solidity: { 93 | compilers: [ 94 | { 95 | version: "0.6.0", 96 | settings: { 97 | optimizer: { enabled: false }, 98 | }, 99 | }, 100 | { 101 | version: "0.6.8", 102 | settings: { 103 | optimizer: { enabled: false }, 104 | }, 105 | }, 106 | { 107 | version: "0.7.0", 108 | settings: { 109 | optimizer: { enabled: false }, 110 | }, 111 | }, 112 | ], 113 | }, 114 | paths: { 115 | artifacts: "./artifacts", 116 | cache: "./cache", 117 | sources: "./contracts", 118 | tests: "./test", 119 | }, 120 | etherscan: { 121 | apiKey: process.env.ETHERSCAN, 122 | }, 123 | typechain: { 124 | outDir: "typechain", 125 | target: "ethers-v5", 126 | }, 127 | mocha: { 128 | timeout: 10000 * 1000, // 10,000 seconds 129 | }, 130 | }; 131 | export default config; 132 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dsa-contracts", 3 | "version": "1.0.0", 4 | "description": "", 5 | "directories": { 6 | "test": "test" 7 | }, 8 | "scripts": { 9 | "test": "hardhat test", 10 | "coverage": "hardhat coverage --solcoverjs .solcover.ts --testfiles 'test/**.test.ts'", 11 | "compile": "hardhat compile" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "git+https://github.com/InstaDApp/smart-account.git" 16 | }, 17 | "author": "", 18 | "license": "ISC", 19 | "bugs": { 20 | "url": "https://github.com/InstaDApp/smart-account/issues" 21 | }, 22 | "homepage": "https://github.com/InstaDApp/smart-account#readme", 23 | "dependencies": { 24 | "@nomiclabs/hardhat-ethers": "^2.0.2", 25 | "@nomiclabs/hardhat-etherscan": "^3.1.7", 26 | "@nomiclabs/hardhat-waffle": "^2.0.1", 27 | "@nomiclabs/hardhat-web3": "^2.0.0", 28 | "@openzeppelin/contracts": "^3.4.1-solc-0.7", 29 | "@openzeppelin/upgrades": "^2.8.0", 30 | "@typechain/ethers-v5": "^8.0.5", 31 | "@typechain/hardhat": "^3.1.0", 32 | "dotenv": "^7.0.0", 33 | "ethereum-waffle": "^3.2.1", 34 | "ethereumjs-abi": "^0.6.8", 35 | "ethers": "^5.0.26", 36 | "hardhat": "^2.6.3", 37 | "hardhat-deploy": "^0.9.1", 38 | "hardhat-deploy-ethers": "^0.3.0-beta.10", 39 | "replace-in-file": "^5.0.2", 40 | "solc": "^0.6.12", 41 | "typechain": "^6.0.5", 42 | "web3-abi-helper": "^4.1.0" 43 | }, 44 | "devDependencies": { 45 | "@nomiclabs/hardhat-ethers": "^2.0.2", 46 | "@nomiclabs/hardhat-waffle": "^2.0.1", 47 | "@openzeppelin/hardhat-upgrades": "^1.6.0", 48 | "@openzeppelin/test-helpers": "^0.5.10", 49 | "@tenderly/hardhat-tenderly": "^1.1.0-beta.4", 50 | "@types/chai": "^4.3.0", 51 | "@types/mocha": "^9.0.0", 52 | "@types/node": "^16.11.12", 53 | "chai": "^4.3.4", 54 | "ethereum-waffle": "^3.2.1", 55 | "ethers": "^5.0.26", 56 | "hardhat": "^2.0.8", 57 | "hardhat-gas-reporter": "^1.0.8", 58 | "solidity-coverage": "^0.7.21", 59 | "ts-node": "^10.4.0", 60 | "typescript": "^4.5.4" 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /scripts/constant/abi/basics/erc20.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "constant": true, 4 | "inputs": [], 5 | "name": "name", 6 | "outputs": [ 7 | { 8 | "name": "", 9 | "type": "string" 10 | } 11 | ], 12 | "payable": false, 13 | "stateMutability": "view", 14 | "type": "function" 15 | }, 16 | { 17 | "constant": false, 18 | "inputs": [ 19 | { 20 | "name": "_spender", 21 | "type": "address" 22 | }, 23 | { 24 | "name": "_value", 25 | "type": "uint256" 26 | } 27 | ], 28 | "name": "approve", 29 | "outputs": [ 30 | { 31 | "name": "", 32 | "type": "bool" 33 | } 34 | ], 35 | "payable": false, 36 | "stateMutability": "nonpayable", 37 | "type": "function" 38 | }, 39 | { 40 | "constant": true, 41 | "inputs": [], 42 | "name": "totalSupply", 43 | "outputs": [ 44 | { 45 | "name": "", 46 | "type": "uint256" 47 | } 48 | ], 49 | "payable": false, 50 | "stateMutability": "view", 51 | "type": "function" 52 | }, 53 | { 54 | "constant": false, 55 | "inputs": [ 56 | { 57 | "name": "_from", 58 | "type": "address" 59 | }, 60 | { 61 | "name": "_to", 62 | "type": "address" 63 | }, 64 | { 65 | "name": "_value", 66 | "type": "uint256" 67 | } 68 | ], 69 | "name": "transferFrom", 70 | "outputs": [ 71 | { 72 | "name": "", 73 | "type": "bool" 74 | } 75 | ], 76 | "payable": false, 77 | "stateMutability": "nonpayable", 78 | "type": "function" 79 | }, 80 | { 81 | "constant": true, 82 | "inputs": [], 83 | "name": "decimals", 84 | "outputs": [ 85 | { 86 | "name": "", 87 | "type": "uint8" 88 | } 89 | ], 90 | "payable": false, 91 | "stateMutability": "view", 92 | "type": "function" 93 | }, 94 | { 95 | "constant": true, 96 | "inputs": [ 97 | { 98 | "name": "_owner", 99 | "type": "address" 100 | } 101 | ], 102 | "name": "balanceOf", 103 | "outputs": [ 104 | { 105 | "name": "balance", 106 | "type": "uint256" 107 | } 108 | ], 109 | "payable": false, 110 | "stateMutability": "view", 111 | "type": "function" 112 | }, 113 | { 114 | "constant": true, 115 | "inputs": [], 116 | "name": "symbol", 117 | "outputs": [ 118 | { 119 | "name": "", 120 | "type": "string" 121 | } 122 | ], 123 | "payable": false, 124 | "stateMutability": "view", 125 | "type": "function" 126 | }, 127 | { 128 | "constant": false, 129 | "inputs": [ 130 | { 131 | "name": "_to", 132 | "type": "address" 133 | }, 134 | { 135 | "name": "_value", 136 | "type": "uint256" 137 | } 138 | ], 139 | "name": "transfer", 140 | "outputs": [ 141 | { 142 | "name": "", 143 | "type": "bool" 144 | } 145 | ], 146 | "payable": false, 147 | "stateMutability": "nonpayable", 148 | "type": "function" 149 | }, 150 | { 151 | "constant": true, 152 | "inputs": [ 153 | { 154 | "name": "_owner", 155 | "type": "address" 156 | }, 157 | { 158 | "name": "_spender", 159 | "type": "address" 160 | } 161 | ], 162 | "name": "allowance", 163 | "outputs": [ 164 | { 165 | "name": "", 166 | "type": "uint256" 167 | } 168 | ], 169 | "payable": false, 170 | "stateMutability": "view", 171 | "type": "function" 172 | }, 173 | { 174 | "payable": true, 175 | "stateMutability": "payable", 176 | "type": "fallback" 177 | }, 178 | { 179 | "anonymous": false, 180 | "inputs": [ 181 | { 182 | "indexed": true, 183 | "name": "owner", 184 | "type": "address" 185 | }, 186 | { 187 | "indexed": true, 188 | "name": "spender", 189 | "type": "address" 190 | }, 191 | { 192 | "indexed": false, 193 | "name": "value", 194 | "type": "uint256" 195 | } 196 | ], 197 | "name": "Approval", 198 | "type": "event" 199 | }, 200 | { 201 | "anonymous": false, 202 | "inputs": [ 203 | { 204 | "indexed": true, 205 | "name": "from", 206 | "type": "address" 207 | }, 208 | { 209 | "indexed": true, 210 | "name": "to", 211 | "type": "address" 212 | }, 213 | { 214 | "indexed": false, 215 | "name": "value", 216 | "type": "uint256" 217 | } 218 | ], 219 | "name": "Transfer", 220 | "type": "event" 221 | } 222 | ] 223 | -------------------------------------------------------------------------------- /scripts/constant/abi/connectors/auth.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "anonymous": false, 4 | "inputs": [ 5 | { 6 | "indexed": true, 7 | "internalType": "address", 8 | "name": "_msgSender", 9 | "type": "address" 10 | }, 11 | { 12 | "indexed": true, 13 | "internalType": "address", 14 | "name": "_authority", 15 | "type": "address" 16 | } 17 | ], 18 | "name": "LogAddAuth", 19 | "type": "event" 20 | }, 21 | { 22 | "anonymous": false, 23 | "inputs": [ 24 | { 25 | "indexed": true, 26 | "internalType": "address", 27 | "name": "_msgSender", 28 | "type": "address" 29 | }, 30 | { 31 | "indexed": true, 32 | "internalType": "address", 33 | "name": "_authority", 34 | "type": "address" 35 | } 36 | ], 37 | "name": "LogRemoveAuth", 38 | "type": "event" 39 | }, 40 | { 41 | "inputs": [ 42 | { 43 | "internalType": "address", 44 | "name": "authority", 45 | "type": "address" 46 | } 47 | ], 48 | "name": "add", 49 | "outputs": [], 50 | "stateMutability": "payable", 51 | "type": "function" 52 | }, 53 | { 54 | "inputs": [], 55 | "name": "connectorID", 56 | "outputs": [ 57 | { 58 | "internalType": "uint256", 59 | "name": "_type", 60 | "type": "uint256" 61 | }, 62 | { 63 | "internalType": "uint256", 64 | "name": "_id", 65 | "type": "uint256" 66 | } 67 | ], 68 | "stateMutability": "pure", 69 | "type": "function" 70 | }, 71 | { 72 | "inputs": [], 73 | "name": "name", 74 | "outputs": [ 75 | { 76 | "internalType": "string", 77 | "name": "", 78 | "type": "string" 79 | } 80 | ], 81 | "stateMutability": "view", 82 | "type": "function" 83 | }, 84 | { 85 | "inputs": [ 86 | { 87 | "internalType": "address", 88 | "name": "authority", 89 | "type": "address" 90 | } 91 | ], 92 | "name": "remove", 93 | "outputs": [], 94 | "stateMutability": "payable", 95 | "type": "function" 96 | } 97 | ] 98 | -------------------------------------------------------------------------------- /scripts/constant/abi/connectors/basic.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "anonymous": false, 4 | "inputs": [ 5 | { 6 | "indexed": true, 7 | "internalType": "address", 8 | "name": "erc20", 9 | "type": "address" 10 | }, 11 | { 12 | "indexed": false, 13 | "internalType": "uint256", 14 | "name": "tokenAmt", 15 | "type": "uint256" 16 | }, 17 | { 18 | "indexed": false, 19 | "internalType": "uint256", 20 | "name": "getId", 21 | "type": "uint256" 22 | }, 23 | { 24 | "indexed": false, 25 | "internalType": "uint256", 26 | "name": "setId", 27 | "type": "uint256" 28 | } 29 | ], 30 | "name": "LogDeposit", 31 | "type": "event" 32 | }, 33 | { 34 | "anonymous": false, 35 | "inputs": [ 36 | { 37 | "indexed": true, 38 | "internalType": "address", 39 | "name": "erc20", 40 | "type": "address" 41 | }, 42 | { 43 | "indexed": false, 44 | "internalType": "uint256", 45 | "name": "tokenAmt", 46 | "type": "uint256" 47 | }, 48 | { 49 | "indexed": true, 50 | "internalType": "address", 51 | "name": "to", 52 | "type": "address" 53 | }, 54 | { 55 | "indexed": false, 56 | "internalType": "uint256", 57 | "name": "getId", 58 | "type": "uint256" 59 | }, 60 | { 61 | "indexed": false, 62 | "internalType": "uint256", 63 | "name": "setId", 64 | "type": "uint256" 65 | } 66 | ], 67 | "name": "LogWithdraw", 68 | "type": "event" 69 | }, 70 | { 71 | "inputs": [], 72 | "name": "connectorID", 73 | "outputs": [ 74 | { "internalType": "uint256", "name": "_type", "type": "uint256" }, 75 | { "internalType": "uint256", "name": "_id", "type": "uint256" } 76 | ], 77 | "stateMutability": "pure", 78 | "type": "function" 79 | }, 80 | { 81 | "inputs": [ 82 | { "internalType": "address", "name": "erc20", "type": "address" }, 83 | { "internalType": "uint256", "name": "tokenAmt", "type": "uint256" }, 84 | { "internalType": "uint256", "name": "getId", "type": "uint256" }, 85 | { "internalType": "uint256", "name": "setId", "type": "uint256" } 86 | ], 87 | "name": "deposit", 88 | "outputs": [], 89 | "stateMutability": "payable", 90 | "type": "function" 91 | }, 92 | { 93 | "inputs": [], 94 | "name": "getEthAddr", 95 | "outputs": [{ "internalType": "address", "name": "", "type": "address" }], 96 | "stateMutability": "pure", 97 | "type": "function" 98 | }, 99 | { 100 | "inputs": [], 101 | "name": "getEventAddr", 102 | "outputs": [{ "internalType": "address", "name": "", "type": "address" }], 103 | "stateMutability": "pure", 104 | "type": "function" 105 | }, 106 | { 107 | "inputs": [], 108 | "name": "getMemoryAddr", 109 | "outputs": [{ "internalType": "address", "name": "", "type": "address" }], 110 | "stateMutability": "pure", 111 | "type": "function" 112 | }, 113 | { 114 | "inputs": [], 115 | "name": "name", 116 | "outputs": [{ "internalType": "string", "name": "", "type": "string" }], 117 | "stateMutability": "view", 118 | "type": "function" 119 | }, 120 | { 121 | "inputs": [ 122 | { "internalType": "address", "name": "erc20", "type": "address" }, 123 | { "internalType": "uint256", "name": "tokenAmt", "type": "uint256" }, 124 | { "internalType": "address payable", "name": "to", "type": "address" }, 125 | { "internalType": "uint256", "name": "getId", "type": "uint256" }, 126 | { "internalType": "uint256", "name": "setId", "type": "uint256" } 127 | ], 128 | "name": "withdraw", 129 | "outputs": [], 130 | "stateMutability": "payable", 131 | "type": "function" 132 | } 133 | ] 134 | -------------------------------------------------------------------------------- /scripts/constant/abi/connectors/compound.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "anonymous": false, 4 | "inputs": [ 5 | { 6 | "indexed": true, 7 | "internalType": "address", 8 | "name": "token", 9 | "type": "address" 10 | }, 11 | { 12 | "indexed": false, 13 | "internalType": "address", 14 | "name": "cToken", 15 | "type": "address" 16 | }, 17 | { 18 | "indexed": false, 19 | "internalType": "uint256", 20 | "name": "tokenAmt", 21 | "type": "uint256" 22 | }, 23 | { 24 | "indexed": false, 25 | "internalType": "uint256", 26 | "name": "getId", 27 | "type": "uint256" 28 | }, 29 | { 30 | "indexed": false, 31 | "internalType": "uint256", 32 | "name": "setId", 33 | "type": "uint256" 34 | } 35 | ], 36 | "name": "LogBorrow", 37 | "type": "event" 38 | }, 39 | { 40 | "anonymous": false, 41 | "inputs": [ 42 | { 43 | "indexed": true, 44 | "internalType": "address", 45 | "name": "token", 46 | "type": "address" 47 | }, 48 | { 49 | "indexed": false, 50 | "internalType": "address", 51 | "name": "cToken", 52 | "type": "address" 53 | }, 54 | { 55 | "indexed": false, 56 | "internalType": "uint256", 57 | "name": "tokenAmt", 58 | "type": "uint256" 59 | }, 60 | { 61 | "indexed": false, 62 | "internalType": "uint256", 63 | "name": "getId", 64 | "type": "uint256" 65 | }, 66 | { 67 | "indexed": false, 68 | "internalType": "uint256", 69 | "name": "setId", 70 | "type": "uint256" 71 | } 72 | ], 73 | "name": "LogDeposit", 74 | "type": "event" 75 | }, 76 | { 77 | "anonymous": false, 78 | "inputs": [ 79 | { 80 | "indexed": true, 81 | "internalType": "address", 82 | "name": "token", 83 | "type": "address" 84 | }, 85 | { 86 | "indexed": false, 87 | "internalType": "address", 88 | "name": "cToken", 89 | "type": "address" 90 | }, 91 | { 92 | "indexed": false, 93 | "internalType": "uint256", 94 | "name": "tokenAmt", 95 | "type": "uint256" 96 | }, 97 | { 98 | "indexed": false, 99 | "internalType": "uint256", 100 | "name": "cTokenAmt", 101 | "type": "uint256" 102 | }, 103 | { 104 | "indexed": false, 105 | "internalType": "uint256", 106 | "name": "getId", 107 | "type": "uint256" 108 | }, 109 | { 110 | "indexed": false, 111 | "internalType": "uint256", 112 | "name": "setId", 113 | "type": "uint256" 114 | } 115 | ], 116 | "name": "LogDepositCToken", 117 | "type": "event" 118 | }, 119 | { 120 | "anonymous": false, 121 | "inputs": [ 122 | { 123 | "indexed": true, 124 | "internalType": "address", 125 | "name": "borrower", 126 | "type": "address" 127 | }, 128 | { 129 | "indexed": true, 130 | "internalType": "address", 131 | "name": "tokenToPay", 132 | "type": "address" 133 | }, 134 | { 135 | "indexed": true, 136 | "internalType": "address", 137 | "name": "tokenInReturn", 138 | "type": "address" 139 | }, 140 | { 141 | "indexed": false, 142 | "internalType": "uint256", 143 | "name": "tokenAmt", 144 | "type": "uint256" 145 | }, 146 | { 147 | "indexed": false, 148 | "internalType": "uint256", 149 | "name": "getId", 150 | "type": "uint256" 151 | }, 152 | { 153 | "indexed": false, 154 | "internalType": "uint256", 155 | "name": "setId", 156 | "type": "uint256" 157 | } 158 | ], 159 | "name": "LogLiquidate", 160 | "type": "event" 161 | }, 162 | { 163 | "anonymous": false, 164 | "inputs": [ 165 | { 166 | "indexed": true, 167 | "internalType": "address", 168 | "name": "token", 169 | "type": "address" 170 | }, 171 | { 172 | "indexed": false, 173 | "internalType": "address", 174 | "name": "cToken", 175 | "type": "address" 176 | }, 177 | { 178 | "indexed": false, 179 | "internalType": "uint256", 180 | "name": "tokenAmt", 181 | "type": "uint256" 182 | }, 183 | { 184 | "indexed": false, 185 | "internalType": "uint256", 186 | "name": "getId", 187 | "type": "uint256" 188 | }, 189 | { 190 | "indexed": false, 191 | "internalType": "uint256", 192 | "name": "setId", 193 | "type": "uint256" 194 | } 195 | ], 196 | "name": "LogPayback", 197 | "type": "event" 198 | }, 199 | { 200 | "anonymous": false, 201 | "inputs": [ 202 | { 203 | "indexed": true, 204 | "internalType": "address", 205 | "name": "borrower", 206 | "type": "address" 207 | }, 208 | { 209 | "indexed": true, 210 | "internalType": "address", 211 | "name": "token", 212 | "type": "address" 213 | }, 214 | { 215 | "indexed": false, 216 | "internalType": "address", 217 | "name": "cToken", 218 | "type": "address" 219 | }, 220 | { 221 | "indexed": false, 222 | "internalType": "uint256", 223 | "name": "tokenAmt", 224 | "type": "uint256" 225 | }, 226 | { 227 | "indexed": false, 228 | "internalType": "uint256", 229 | "name": "getId", 230 | "type": "uint256" 231 | }, 232 | { 233 | "indexed": false, 234 | "internalType": "uint256", 235 | "name": "setId", 236 | "type": "uint256" 237 | } 238 | ], 239 | "name": "LogPaybackBehalf", 240 | "type": "event" 241 | }, 242 | { 243 | "anonymous": false, 244 | "inputs": [ 245 | { 246 | "indexed": true, 247 | "internalType": "address", 248 | "name": "token", 249 | "type": "address" 250 | }, 251 | { 252 | "indexed": false, 253 | "internalType": "address", 254 | "name": "cToken", 255 | "type": "address" 256 | }, 257 | { 258 | "indexed": false, 259 | "internalType": "uint256", 260 | "name": "tokenAmt", 261 | "type": "uint256" 262 | }, 263 | { 264 | "indexed": false, 265 | "internalType": "uint256", 266 | "name": "getId", 267 | "type": "uint256" 268 | }, 269 | { 270 | "indexed": false, 271 | "internalType": "uint256", 272 | "name": "setId", 273 | "type": "uint256" 274 | } 275 | ], 276 | "name": "LogWithdraw", 277 | "type": "event" 278 | }, 279 | { 280 | "anonymous": false, 281 | "inputs": [ 282 | { 283 | "indexed": true, 284 | "internalType": "address", 285 | "name": "token", 286 | "type": "address" 287 | }, 288 | { 289 | "indexed": false, 290 | "internalType": "address", 291 | "name": "cToken", 292 | "type": "address" 293 | }, 294 | { 295 | "indexed": false, 296 | "internalType": "uint256", 297 | "name": "cTokenAmt", 298 | "type": "uint256" 299 | }, 300 | { 301 | "indexed": false, 302 | "internalType": "uint256", 303 | "name": "getId", 304 | "type": "uint256" 305 | }, 306 | { 307 | "indexed": false, 308 | "internalType": "uint256", 309 | "name": "setId", 310 | "type": "uint256" 311 | } 312 | ], 313 | "name": "LogWithdrawCToken", 314 | "type": "event" 315 | }, 316 | { 317 | "inputs": [ 318 | { "internalType": "address", "name": "token", "type": "address" }, 319 | { "internalType": "uint256", "name": "amt", "type": "uint256" }, 320 | { "internalType": "uint256", "name": "getId", "type": "uint256" }, 321 | { "internalType": "uint256", "name": "setId", "type": "uint256" } 322 | ], 323 | "name": "borrow", 324 | "outputs": [], 325 | "stateMutability": "payable", 326 | "type": "function" 327 | }, 328 | { 329 | "inputs": [], 330 | "name": "connectorID", 331 | "outputs": [ 332 | { "internalType": "uint256", "name": "_type", "type": "uint256" }, 333 | { "internalType": "uint256", "name": "_id", "type": "uint256" } 334 | ], 335 | "stateMutability": "pure", 336 | "type": "function" 337 | }, 338 | { 339 | "inputs": [ 340 | { "internalType": "address", "name": "token", "type": "address" }, 341 | { "internalType": "uint256", "name": "amt", "type": "uint256" }, 342 | { "internalType": "uint256", "name": "getId", "type": "uint256" }, 343 | { "internalType": "uint256", "name": "setId", "type": "uint256" } 344 | ], 345 | "name": "deposit", 346 | "outputs": [], 347 | "stateMutability": "payable", 348 | "type": "function" 349 | }, 350 | { 351 | "inputs": [ 352 | { "internalType": "address", "name": "token", "type": "address" }, 353 | { "internalType": "uint256", "name": "amt", "type": "uint256" }, 354 | { "internalType": "uint256", "name": "getId", "type": "uint256" }, 355 | { "internalType": "uint256", "name": "setId", "type": "uint256" } 356 | ], 357 | "name": "depositCToken", 358 | "outputs": [], 359 | "stateMutability": "payable", 360 | "type": "function" 361 | }, 362 | { 363 | "inputs": [ 364 | { "internalType": "address", "name": "borrower", "type": "address" }, 365 | { "internalType": "address", "name": "tokenToPay", "type": "address" }, 366 | { "internalType": "address", "name": "tokenInReturn", "type": "address" }, 367 | { "internalType": "uint256", "name": "amt", "type": "uint256" }, 368 | { "internalType": "uint256", "name": "getId", "type": "uint256" }, 369 | { "internalType": "uint256", "name": "setId", "type": "uint256" } 370 | ], 371 | "name": "liquidate", 372 | "outputs": [], 373 | "stateMutability": "payable", 374 | "type": "function" 375 | }, 376 | { 377 | "inputs": [], 378 | "name": "name", 379 | "outputs": [{ "internalType": "string", "name": "", "type": "string" }], 380 | "stateMutability": "view", 381 | "type": "function" 382 | }, 383 | { 384 | "inputs": [ 385 | { "internalType": "address", "name": "token", "type": "address" }, 386 | { "internalType": "uint256", "name": "amt", "type": "uint256" }, 387 | { "internalType": "uint256", "name": "getId", "type": "uint256" }, 388 | { "internalType": "uint256", "name": "setId", "type": "uint256" } 389 | ], 390 | "name": "payback", 391 | "outputs": [], 392 | "stateMutability": "payable", 393 | "type": "function" 394 | }, 395 | { 396 | "inputs": [ 397 | { "internalType": "address", "name": "borrower", "type": "address" }, 398 | { "internalType": "address", "name": "token", "type": "address" }, 399 | { "internalType": "uint256", "name": "amt", "type": "uint256" }, 400 | { "internalType": "uint256", "name": "getId", "type": "uint256" }, 401 | { "internalType": "uint256", "name": "setId", "type": "uint256" } 402 | ], 403 | "name": "paybackBehalf", 404 | "outputs": [], 405 | "stateMutability": "payable", 406 | "type": "function" 407 | }, 408 | { 409 | "inputs": [ 410 | { "internalType": "address", "name": "token", "type": "address" }, 411 | { "internalType": "uint256", "name": "amt", "type": "uint256" }, 412 | { "internalType": "uint256", "name": "getId", "type": "uint256" }, 413 | { "internalType": "uint256", "name": "setId", "type": "uint256" } 414 | ], 415 | "name": "withdraw", 416 | "outputs": [], 417 | "stateMutability": "payable", 418 | "type": "function" 419 | }, 420 | { 421 | "inputs": [ 422 | { "internalType": "address", "name": "token", "type": "address" }, 423 | { "internalType": "uint256", "name": "cTokenAmt", "type": "uint256" }, 424 | { "internalType": "uint256", "name": "getId", "type": "uint256" }, 425 | { "internalType": "uint256", "name": "setId", "type": "uint256" } 426 | ], 427 | "name": "withdrawCToken", 428 | "outputs": [], 429 | "stateMutability": "payable", 430 | "type": "function" 431 | }, 432 | { 433 | "inputs": [ 434 | { 435 | "internalType": "uint256", 436 | "name": "setId", 437 | "type": "uint256" 438 | } 439 | ], 440 | "name": "ClaimComp", 441 | "outputs": [], 442 | "stateMutability": "payable", 443 | "type": "function" 444 | } 445 | ] 446 | -------------------------------------------------------------------------------- /scripts/constant/abi/connectors/uniswap.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "inputs": [ 4 | { 5 | "internalType": "address", 6 | "name": "buyAddr", 7 | "type": "address" 8 | }, 9 | { 10 | "internalType": "address", 11 | "name": "sellAddr", 12 | "type": "address" 13 | }, 14 | { 15 | "internalType": "uint256", 16 | "name": "buyAmt", 17 | "type": "uint256" 18 | }, 19 | { 20 | "internalType": "uint256", 21 | "name": "unitAmt", 22 | "type": "uint256" 23 | }, 24 | { 25 | "internalType": "uint256", 26 | "name": "getId", 27 | "type": "uint256" 28 | }, 29 | { 30 | "internalType": "uint256", 31 | "name": "setId", 32 | "type": "uint256" 33 | } 34 | ], 35 | "name": "buy", 36 | "outputs": [], 37 | "stateMutability": "payable", 38 | "type": "function" 39 | }, 40 | { 41 | "inputs": [ 42 | { 43 | "internalType": "address", 44 | "name": "tokenA", 45 | "type": "address" 46 | }, 47 | { 48 | "internalType": "address", 49 | "name": "tokenB", 50 | "type": "address" 51 | }, 52 | { 53 | "internalType": "uint256", 54 | "name": "amtA", 55 | "type": "uint256" 56 | }, 57 | { 58 | "internalType": "uint256", 59 | "name": "unitAmt", 60 | "type": "uint256" 61 | }, 62 | { 63 | "internalType": "uint256", 64 | "name": "slippage", 65 | "type": "uint256" 66 | }, 67 | { 68 | "internalType": "uint256", 69 | "name": "getId", 70 | "type": "uint256" 71 | }, 72 | { 73 | "internalType": "uint256", 74 | "name": "setId", 75 | "type": "uint256" 76 | } 77 | ], 78 | "name": "deposit", 79 | "outputs": [], 80 | "stateMutability": "payable", 81 | "type": "function" 82 | }, 83 | { 84 | "inputs": [], 85 | "name": "name", 86 | "outputs": [ 87 | { 88 | "internalType": "string", 89 | "name": "", 90 | "type": "string" 91 | } 92 | ], 93 | "stateMutability": "view", 94 | "type": "function" 95 | }, 96 | { 97 | "inputs": [ 98 | { 99 | "internalType": "address", 100 | "name": "buyAddr", 101 | "type": "address" 102 | }, 103 | { 104 | "internalType": "address", 105 | "name": "sellAddr", 106 | "type": "address" 107 | }, 108 | { 109 | "internalType": "uint256", 110 | "name": "sellAmt", 111 | "type": "uint256" 112 | }, 113 | { 114 | "internalType": "uint256", 115 | "name": "unitAmt", 116 | "type": "uint256" 117 | }, 118 | { 119 | "internalType": "uint256", 120 | "name": "getId", 121 | "type": "uint256" 122 | }, 123 | { 124 | "internalType": "uint256", 125 | "name": "setId", 126 | "type": "uint256" 127 | } 128 | ], 129 | "name": "sell", 130 | "outputs": [], 131 | "stateMutability": "payable", 132 | "type": "function" 133 | }, 134 | { 135 | "inputs": [ 136 | { 137 | "internalType": "address", 138 | "name": "tokenA", 139 | "type": "address" 140 | }, 141 | { 142 | "internalType": "address", 143 | "name": "tokenB", 144 | "type": "address" 145 | }, 146 | { 147 | "internalType": "uint256", 148 | "name": "uniAmt", 149 | "type": "uint256" 150 | }, 151 | { 152 | "internalType": "uint256", 153 | "name": "unitAmtA", 154 | "type": "uint256" 155 | }, 156 | { 157 | "internalType": "uint256", 158 | "name": "unitAmtB", 159 | "type": "uint256" 160 | }, 161 | { 162 | "internalType": "uint256", 163 | "name": "getId", 164 | "type": "uint256" 165 | }, 166 | { 167 | "internalType": "uint256[]", 168 | "name": "setIds", 169 | "type": "uint256[]" 170 | } 171 | ], 172 | "name": "withdraw", 173 | "outputs": [], 174 | "stateMutability": "payable", 175 | "type": "function" 176 | } 177 | ] 178 | -------------------------------------------------------------------------------- /scripts/constant/abi/read/compound.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "inputs": [], 4 | "name": "getCETHAddress", 5 | "outputs": [{ "internalType": "address", "name": "", "type": "address" }], 6 | "stateMutability": "pure", 7 | "type": "function" 8 | }, 9 | { 10 | "inputs": [], 11 | "name": "getCompReadAddress", 12 | "outputs": [{ "internalType": "address", "name": "", "type": "address" }], 13 | "stateMutability": "pure", 14 | "type": "function" 15 | }, 16 | { 17 | "inputs": [], 18 | "name": "getCompToken", 19 | "outputs": [ 20 | { 21 | "internalType": "contract TokenInterface", 22 | "name": "", 23 | "type": "address" 24 | } 25 | ], 26 | "stateMutability": "pure", 27 | "type": "function" 28 | }, 29 | { 30 | "inputs": [ 31 | { "internalType": "address", "name": "owner", "type": "address" }, 32 | { "internalType": "address[]", "name": "cAddress", "type": "address[]" } 33 | ], 34 | "name": "getCompoundData", 35 | "outputs": [ 36 | { 37 | "components": [ 38 | { 39 | "internalType": "uint256", 40 | "name": "tokenPriceInEth", 41 | "type": "uint256" 42 | }, 43 | { 44 | "internalType": "uint256", 45 | "name": "tokenPriceInUsd", 46 | "type": "uint256" 47 | }, 48 | { 49 | "internalType": "uint256", 50 | "name": "exchangeRateStored", 51 | "type": "uint256" 52 | }, 53 | { 54 | "internalType": "uint256", 55 | "name": "balanceOfUser", 56 | "type": "uint256" 57 | }, 58 | { 59 | "internalType": "uint256", 60 | "name": "borrowBalanceStoredUser", 61 | "type": "uint256" 62 | }, 63 | { 64 | "internalType": "uint256", 65 | "name": "supplyRatePerBlock", 66 | "type": "uint256" 67 | }, 68 | { 69 | "internalType": "uint256", 70 | "name": "borrowRatePerBlock", 71 | "type": "uint256" 72 | } 73 | ], 74 | "internalType": "struct Helpers.CompData[]", 75 | "name": "", 76 | "type": "tuple[]" 77 | } 78 | ], 79 | "stateMutability": "view", 80 | "type": "function" 81 | }, 82 | { 83 | "inputs": [], 84 | "name": "getComptroller", 85 | "outputs": [ 86 | { 87 | "internalType": "contract ComptrollerLensInterface", 88 | "name": "", 89 | "type": "address" 90 | } 91 | ], 92 | "stateMutability": "pure", 93 | "type": "function" 94 | }, 95 | { 96 | "inputs": [], 97 | "name": "getOracleAddress", 98 | "outputs": [{ "internalType": "address", "name": "", "type": "address" }], 99 | "stateMutability": "pure", 100 | "type": "function" 101 | }, 102 | { 103 | "inputs": [ 104 | { "internalType": "address", "name": "owner", "type": "address" }, 105 | { "internalType": "address[]", "name": "cAddress", "type": "address[]" } 106 | ], 107 | "name": "getPosition", 108 | "outputs": [ 109 | { 110 | "components": [ 111 | { 112 | "internalType": "uint256", 113 | "name": "tokenPriceInEth", 114 | "type": "uint256" 115 | }, 116 | { 117 | "internalType": "uint256", 118 | "name": "tokenPriceInUsd", 119 | "type": "uint256" 120 | }, 121 | { 122 | "internalType": "uint256", 123 | "name": "exchangeRateStored", 124 | "type": "uint256" 125 | }, 126 | { 127 | "internalType": "uint256", 128 | "name": "balanceOfUser", 129 | "type": "uint256" 130 | }, 131 | { 132 | "internalType": "uint256", 133 | "name": "borrowBalanceStoredUser", 134 | "type": "uint256" 135 | }, 136 | { 137 | "internalType": "uint256", 138 | "name": "supplyRatePerBlock", 139 | "type": "uint256" 140 | }, 141 | { 142 | "internalType": "uint256", 143 | "name": "borrowRatePerBlock", 144 | "type": "uint256" 145 | } 146 | ], 147 | "internalType": "struct Helpers.CompData[]", 148 | "name": "", 149 | "type": "tuple[]" 150 | }, 151 | { 152 | "components": [ 153 | { "internalType": "uint256", "name": "balance", "type": "uint256" }, 154 | { "internalType": "uint256", "name": "votes", "type": "uint256" }, 155 | { "internalType": "address", "name": "delegate", "type": "address" }, 156 | { "internalType": "uint256", "name": "allocated", "type": "uint256" } 157 | ], 158 | "internalType": "struct CompReadInterface.CompBalanceMetadataExt", 159 | "name": "", 160 | "type": "tuple" 161 | } 162 | ], 163 | "stateMutability": "nonpayable", 164 | "type": "function" 165 | }, 166 | { 167 | "inputs": [ 168 | { "internalType": "address", "name": "cToken", "type": "address" }, 169 | { "internalType": "address", "name": "token", "type": "address" } 170 | ], 171 | "name": "getPriceInEth", 172 | "outputs": [ 173 | { "internalType": "uint256", "name": "priceInETH", "type": "uint256" }, 174 | { "internalType": "uint256", "name": "priceInUSD", "type": "uint256" } 175 | ], 176 | "stateMutability": "view", 177 | "type": "function" 178 | }, 179 | { 180 | "inputs": [], 181 | "name": "name", 182 | "outputs": [{ "internalType": "string", "name": "", "type": "string" }], 183 | "stateMutability": "view", 184 | "type": "function" 185 | } 186 | ] 187 | -------------------------------------------------------------------------------- /scripts/constant/abi/read/core.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "inputs": [ 4 | { "internalType": "address", "name": "_index", "type": "address" }, 5 | { "internalType": "address", "name": "gnosisFactory", "type": "address" } 6 | ], 7 | "stateMutability": "nonpayable", 8 | "type": "constructor" 9 | }, 10 | { 11 | "inputs": [], 12 | "name": "connectors", 13 | "outputs": [{ "internalType": "address", "name": "", "type": "address" }], 14 | "stateMutability": "view", 15 | "type": "function" 16 | }, 17 | { 18 | "inputs": [{ "internalType": "uint64", "name": "id", "type": "uint64" }], 19 | "name": "getAccount", 20 | "outputs": [ 21 | { "internalType": "address", "name": "account", "type": "address" } 22 | ], 23 | "stateMutability": "view", 24 | "type": "function" 25 | }, 26 | { 27 | "inputs": [ 28 | { "internalType": "address", "name": "account", "type": "address" } 29 | ], 30 | "name": "getAccountAuthorities", 31 | "outputs": [ 32 | { "internalType": "address[]", "name": "", "type": "address[]" } 33 | ], 34 | "stateMutability": "view", 35 | "type": "function" 36 | }, 37 | { 38 | "inputs": [ 39 | { "internalType": "address", "name": "account", "type": "address" } 40 | ], 41 | "name": "getAccountAuthoritiesTypes", 42 | "outputs": [ 43 | { 44 | "components": [ 45 | { "internalType": "address", "name": "owner", "type": "address" }, 46 | { "internalType": "uint256", "name": "authType", "type": "uint256" } 47 | ], 48 | "internalType": "struct AccountResolver.AuthType[]", 49 | "name": "", 50 | "type": "tuple[]" 51 | } 52 | ], 53 | "stateMutability": "view", 54 | "type": "function" 55 | }, 56 | { 57 | "inputs": [ 58 | { "internalType": "address", "name": "account", "type": "address" } 59 | ], 60 | "name": "getAccountDetails", 61 | "outputs": [ 62 | { 63 | "components": [ 64 | { "internalType": "uint256", "name": "ID", "type": "uint256" }, 65 | { "internalType": "address", "name": "account", "type": "address" }, 66 | { "internalType": "uint256", "name": "version", "type": "uint256" }, 67 | { 68 | "internalType": "address[]", 69 | "name": "authorities", 70 | "type": "address[]" 71 | } 72 | ], 73 | "internalType": "struct AccountResolver.AccountData", 74 | "name": "", 75 | "type": "tuple" 76 | } 77 | ], 78 | "stateMutability": "view", 79 | "type": "function" 80 | }, 81 | { 82 | "inputs": [{ "internalType": "uint256", "name": "id", "type": "uint256" }], 83 | "name": "getAccountIdDetails", 84 | "outputs": [ 85 | { 86 | "components": [ 87 | { "internalType": "uint256", "name": "ID", "type": "uint256" }, 88 | { "internalType": "address", "name": "account", "type": "address" }, 89 | { "internalType": "uint256", "name": "version", "type": "uint256" }, 90 | { 91 | "internalType": "address[]", 92 | "name": "authorities", 93 | "type": "address[]" 94 | } 95 | ], 96 | "internalType": "struct AccountResolver.AccountData", 97 | "name": "", 98 | "type": "tuple" 99 | } 100 | ], 101 | "stateMutability": "view", 102 | "type": "function" 103 | }, 104 | { 105 | "inputs": [ 106 | { "internalType": "address[]", "name": "accounts", "type": "address[]" } 107 | ], 108 | "name": "getAccountVersions", 109 | "outputs": [ 110 | { "internalType": "uint256[]", "name": "", "type": "uint256[]" } 111 | ], 112 | "stateMutability": "view", 113 | "type": "function" 114 | }, 115 | { 116 | "inputs": [ 117 | { "internalType": "address", "name": "authority", "type": "address" } 118 | ], 119 | "name": "getAuthorityAccounts", 120 | "outputs": [ 121 | { "internalType": "address[]", "name": "", "type": "address[]" } 122 | ], 123 | "stateMutability": "view", 124 | "type": "function" 125 | }, 126 | { 127 | "inputs": [ 128 | { "internalType": "address", "name": "authority", "type": "address" } 129 | ], 130 | "name": "getAuthorityDetails", 131 | "outputs": [ 132 | { 133 | "components": [ 134 | { "internalType": "uint64[]", "name": "IDs", "type": "uint64[]" }, 135 | { 136 | "internalType": "address[]", 137 | "name": "accounts", 138 | "type": "address[]" 139 | }, 140 | { 141 | "internalType": "uint256[]", 142 | "name": "versions", 143 | "type": "uint256[]" 144 | } 145 | ], 146 | "internalType": "struct AccountResolver.AuthorityData", 147 | "name": "", 148 | "type": "tuple" 149 | } 150 | ], 151 | "stateMutability": "view", 152 | "type": "function" 153 | }, 154 | { 155 | "inputs": [ 156 | { "internalType": "address", "name": "authority", "type": "address" } 157 | ], 158 | "name": "getAuthorityIDs", 159 | "outputs": [{ "internalType": "uint64[]", "name": "", "type": "uint64[]" }], 160 | "stateMutability": "view", 161 | "type": "function" 162 | }, 163 | { 164 | "inputs": [ 165 | { 166 | "internalType": "address[]", 167 | "name": "authorities", 168 | "type": "address[]" 169 | } 170 | ], 171 | "name": "getAuthorityTypes", 172 | "outputs": [ 173 | { 174 | "components": [ 175 | { "internalType": "address", "name": "owner", "type": "address" }, 176 | { "internalType": "uint256", "name": "authType", "type": "uint256" } 177 | ], 178 | "internalType": "struct AccountResolver.AuthType[]", 179 | "name": "", 180 | "type": "tuple[]" 181 | } 182 | ], 183 | "stateMutability": "view", 184 | "type": "function" 185 | }, 186 | { 187 | "inputs": [ 188 | { "internalType": "address", "name": "_addr", "type": "address" } 189 | ], 190 | "name": "getContractCode", 191 | "outputs": [{ "internalType": "bytes", "name": "o_code", "type": "bytes" }], 192 | "stateMutability": "view", 193 | "type": "function" 194 | }, 195 | { 196 | "inputs": [], 197 | "name": "getEnabledConnectors", 198 | "outputs": [ 199 | { "internalType": "address[]", "name": "", "type": "address[]" } 200 | ], 201 | "stateMutability": "view", 202 | "type": "function" 203 | }, 204 | { 205 | "inputs": [], 206 | "name": "getEnabledConnectorsData", 207 | "outputs": [ 208 | { 209 | "components": [ 210 | { "internalType": "address", "name": "connector", "type": "address" }, 211 | { 212 | "internalType": "uint256", 213 | "name": "connectorID", 214 | "type": "uint256" 215 | }, 216 | { "internalType": "string", "name": "name", "type": "string" } 217 | ], 218 | "internalType": "struct ConnectorsResolver.ConnectorsData[]", 219 | "name": "", 220 | "type": "tuple[]" 221 | } 222 | ], 223 | "stateMutability": "view", 224 | "type": "function" 225 | }, 226 | { 227 | "inputs": [ 228 | { "internalType": "address", "name": "account", "type": "address" } 229 | ], 230 | "name": "getID", 231 | "outputs": [{ "internalType": "uint256", "name": "id", "type": "uint256" }], 232 | "stateMutability": "view", 233 | "type": "function" 234 | }, 235 | { 236 | "inputs": [{ "internalType": "uint256", "name": "id", "type": "uint256" }], 237 | "name": "getIDAuthorities", 238 | "outputs": [ 239 | { "internalType": "address[]", "name": "", "type": "address[]" } 240 | ], 241 | "stateMutability": "view", 242 | "type": "function" 243 | }, 244 | { 245 | "inputs": [], 246 | "name": "getStaticConnectors", 247 | "outputs": [ 248 | { "internalType": "address[]", "name": "", "type": "address[]" } 249 | ], 250 | "stateMutability": "view", 251 | "type": "function" 252 | }, 253 | { 254 | "inputs": [], 255 | "name": "getStaticConnectorsData", 256 | "outputs": [ 257 | { 258 | "components": [ 259 | { "internalType": "address", "name": "connector", "type": "address" }, 260 | { 261 | "internalType": "uint256", 262 | "name": "connectorID", 263 | "type": "uint256" 264 | }, 265 | { "internalType": "string", "name": "name", "type": "string" } 266 | ], 267 | "internalType": "struct ConnectorsResolver.ConnectorsData[]", 268 | "name": "", 269 | "type": "tuple[]" 270 | } 271 | ], 272 | "stateMutability": "view", 273 | "type": "function" 274 | }, 275 | { 276 | "inputs": [], 277 | "name": "index", 278 | "outputs": [{ "internalType": "address", "name": "", "type": "address" }], 279 | "stateMutability": "view", 280 | "type": "function" 281 | }, 282 | { 283 | "inputs": [ 284 | { "internalType": "address", "name": "account", "type": "address" } 285 | ], 286 | "name": "isShield", 287 | "outputs": [{ "internalType": "bool", "name": "shield", "type": "bool" }], 288 | "stateMutability": "view", 289 | "type": "function" 290 | }, 291 | { 292 | "inputs": [], 293 | "name": "list", 294 | "outputs": [{ "internalType": "address", "name": "", "type": "address" }], 295 | "stateMutability": "view", 296 | "type": "function" 297 | }, 298 | { 299 | "inputs": [], 300 | "name": "name", 301 | "outputs": [{ "internalType": "string", "name": "", "type": "string" }], 302 | "stateMutability": "view", 303 | "type": "function" 304 | }, 305 | { 306 | "inputs": [], 307 | "name": "version", 308 | "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], 309 | "stateMutability": "view", 310 | "type": "function" 311 | } 312 | ] 313 | -------------------------------------------------------------------------------- /scripts/constant/abi/read/erc20.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "inputs": [ 4 | { 5 | "internalType": "address", 6 | "name": "owner", 7 | "type": "address" 8 | }, 9 | { 10 | "internalType": "address", 11 | "name": "spender", 12 | "type": "address" 13 | }, 14 | { 15 | "internalType": "address[]", 16 | "name": "tknAddress", 17 | "type": "address[]" 18 | } 19 | ], 20 | "name": "getAllowances", 21 | "outputs": [ 22 | { 23 | "internalType": "uint256[]", 24 | "name": "", 25 | "type": "uint256[]" 26 | } 27 | ], 28 | "stateMutability": "view", 29 | "type": "function" 30 | }, 31 | { 32 | "inputs": [ 33 | { 34 | "internalType": "address", 35 | "name": "owner", 36 | "type": "address" 37 | }, 38 | { 39 | "internalType": "address[]", 40 | "name": "tknAddress", 41 | "type": "address[]" 42 | } 43 | ], 44 | "name": "getBalances", 45 | "outputs": [ 46 | { 47 | "internalType": "uint256[]", 48 | "name": "", 49 | "type": "uint256[]" 50 | } 51 | ], 52 | "stateMutability": "view", 53 | "type": "function" 54 | }, 55 | { 56 | "inputs": [], 57 | "name": "name", 58 | "outputs": [ 59 | { 60 | "internalType": "string", 61 | "name": "", 62 | "type": "string" 63 | } 64 | ], 65 | "stateMutability": "view", 66 | "type": "function" 67 | } 68 | ] 69 | -------------------------------------------------------------------------------- /scripts/constant/abi/read/maker.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "inputs": [ 4 | { 5 | "internalType": "string[]", 6 | "name": "name", 7 | "type": "string[]" 8 | } 9 | ], 10 | "name": "getColInfo", 11 | "outputs": [ 12 | { 13 | "components": [ 14 | { 15 | "internalType": "uint256", 16 | "name": "borrowRate", 17 | "type": "uint256" 18 | }, 19 | { 20 | "internalType": "uint256", 21 | "name": "price", 22 | "type": "uint256" 23 | }, 24 | { 25 | "internalType": "uint256", 26 | "name": "liquidationRatio", 27 | "type": "uint256" 28 | }, 29 | { 30 | "internalType": "uint256", 31 | "name": "debtCeiling", 32 | "type": "uint256" 33 | }, 34 | { 35 | "internalType": "uint256", 36 | "name": "totalDebt", 37 | "type": "uint256" 38 | } 39 | ], 40 | "internalType": "struct Helpers.ColInfo[]", 41 | "name": "", 42 | "type": "tuple[]" 43 | } 44 | ], 45 | "stateMutability": "view", 46 | "type": "function" 47 | }, 48 | { 49 | "inputs": [ 50 | { 51 | "internalType": "address", 52 | "name": "owner", 53 | "type": "address" 54 | } 55 | ], 56 | "name": "getDaiPosition", 57 | "outputs": [ 58 | { 59 | "internalType": "uint256", 60 | "name": "amt", 61 | "type": "uint256" 62 | }, 63 | { 64 | "internalType": "uint256", 65 | "name": "dsr", 66 | "type": "uint256" 67 | } 68 | ], 69 | "stateMutability": "view", 70 | "type": "function" 71 | }, 72 | { 73 | "inputs": [], 74 | "name": "getDsrRate", 75 | "outputs": [ 76 | { 77 | "internalType": "uint256", 78 | "name": "dsr", 79 | "type": "uint256" 80 | } 81 | ], 82 | "stateMutability": "view", 83 | "type": "function" 84 | }, 85 | { 86 | "inputs": [], 87 | "name": "getMcdAddresses", 88 | "outputs": [ 89 | { 90 | "internalType": "address", 91 | "name": "", 92 | "type": "address" 93 | } 94 | ], 95 | "stateMutability": "pure", 96 | "type": "function" 97 | }, 98 | { 99 | "inputs": [ 100 | { 101 | "internalType": "uint256", 102 | "name": "id", 103 | "type": "uint256" 104 | } 105 | ], 106 | "name": "getVaultById", 107 | "outputs": [ 108 | { 109 | "components": [ 110 | { 111 | "internalType": "uint256", 112 | "name": "id", 113 | "type": "uint256" 114 | }, 115 | { 116 | "internalType": "address", 117 | "name": "owner", 118 | "type": "address" 119 | }, 120 | { 121 | "internalType": "string", 122 | "name": "colType", 123 | "type": "string" 124 | }, 125 | { 126 | "internalType": "uint256", 127 | "name": "collateral", 128 | "type": "uint256" 129 | }, 130 | { 131 | "internalType": "uint256", 132 | "name": "art", 133 | "type": "uint256" 134 | }, 135 | { 136 | "internalType": "uint256", 137 | "name": "debt", 138 | "type": "uint256" 139 | }, 140 | { 141 | "internalType": "uint256", 142 | "name": "liquidatedCol", 143 | "type": "uint256" 144 | }, 145 | { 146 | "internalType": "uint256", 147 | "name": "borrowRate", 148 | "type": "uint256" 149 | }, 150 | { 151 | "internalType": "uint256", 152 | "name": "colPrice", 153 | "type": "uint256" 154 | }, 155 | { 156 | "internalType": "uint256", 157 | "name": "liquidationRatio", 158 | "type": "uint256" 159 | }, 160 | { 161 | "internalType": "address", 162 | "name": "vaultAddress", 163 | "type": "address" 164 | } 165 | ], 166 | "internalType": "struct Helpers.VaultData", 167 | "name": "", 168 | "type": "tuple" 169 | } 170 | ], 171 | "stateMutability": "view", 172 | "type": "function" 173 | }, 174 | { 175 | "inputs": [ 176 | { 177 | "internalType": "address", 178 | "name": "owner", 179 | "type": "address" 180 | } 181 | ], 182 | "name": "getVaults", 183 | "outputs": [ 184 | { 185 | "components": [ 186 | { 187 | "internalType": "uint256", 188 | "name": "id", 189 | "type": "uint256" 190 | }, 191 | { 192 | "internalType": "address", 193 | "name": "owner", 194 | "type": "address" 195 | }, 196 | { 197 | "internalType": "string", 198 | "name": "colType", 199 | "type": "string" 200 | }, 201 | { 202 | "internalType": "uint256", 203 | "name": "collateral", 204 | "type": "uint256" 205 | }, 206 | { 207 | "internalType": "uint256", 208 | "name": "art", 209 | "type": "uint256" 210 | }, 211 | { 212 | "internalType": "uint256", 213 | "name": "debt", 214 | "type": "uint256" 215 | }, 216 | { 217 | "internalType": "uint256", 218 | "name": "liquidatedCol", 219 | "type": "uint256" 220 | }, 221 | { 222 | "internalType": "uint256", 223 | "name": "borrowRate", 224 | "type": "uint256" 225 | }, 226 | { 227 | "internalType": "uint256", 228 | "name": "colPrice", 229 | "type": "uint256" 230 | }, 231 | { 232 | "internalType": "uint256", 233 | "name": "liquidationRatio", 234 | "type": "uint256" 235 | }, 236 | { 237 | "internalType": "address", 238 | "name": "vaultAddress", 239 | "type": "address" 240 | } 241 | ], 242 | "internalType": "struct Helpers.VaultData[]", 243 | "name": "", 244 | "type": "tuple[]" 245 | } 246 | ], 247 | "stateMutability": "view", 248 | "type": "function" 249 | }, 250 | { 251 | "inputs": [], 252 | "name": "name", 253 | "outputs": [ 254 | { 255 | "internalType": "string", 256 | "name": "", 257 | "type": "string" 258 | } 259 | ], 260 | "stateMutability": "view", 261 | "type": "function" 262 | } 263 | ] 264 | -------------------------------------------------------------------------------- /scripts/constant/abi/read/uniswap.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "inputs": [ 4 | { 5 | "internalType": "address", 6 | "name": "buyAddr", 7 | "type": "address" 8 | }, 9 | { 10 | "internalType": "address", 11 | "name": "sellAddr", 12 | "type": "address" 13 | }, 14 | { 15 | "internalType": "uint256", 16 | "name": "sellAmt", 17 | "type": "uint256" 18 | }, 19 | { 20 | "internalType": "uint256", 21 | "name": "slippage", 22 | "type": "uint256" 23 | } 24 | ], 25 | "name": "getBuyAmount", 26 | "outputs": [ 27 | { 28 | "internalType": "uint256", 29 | "name": "buyAmt", 30 | "type": "uint256" 31 | }, 32 | { 33 | "internalType": "uint256", 34 | "name": "unitAmt", 35 | "type": "uint256" 36 | } 37 | ], 38 | "stateMutability": "view", 39 | "type": "function" 40 | }, 41 | { 42 | "inputs": [ 43 | { 44 | "internalType": "address", 45 | "name": "tokenA", 46 | "type": "address" 47 | }, 48 | { 49 | "internalType": "address", 50 | "name": "tokenB", 51 | "type": "address" 52 | }, 53 | { 54 | "internalType": "uint256", 55 | "name": "amtA", 56 | "type": "uint256" 57 | } 58 | ], 59 | "name": "getDepositAmount", 60 | "outputs": [ 61 | { 62 | "internalType": "uint256", 63 | "name": "amtB", 64 | "type": "uint256" 65 | }, 66 | { 67 | "internalType": "uint256", 68 | "name": "unitAmt", 69 | "type": "uint256" 70 | } 71 | ], 72 | "stateMutability": "view", 73 | "type": "function" 74 | }, 75 | { 76 | "inputs": [ 77 | { 78 | "internalType": "address", 79 | "name": "tokenA", 80 | "type": "address" 81 | }, 82 | { 83 | "internalType": "address", 84 | "name": "tokenB", 85 | "type": "address" 86 | }, 87 | { 88 | "internalType": "uint256", 89 | "name": "amtA", 90 | "type": "uint256" 91 | }, 92 | { 93 | "internalType": "uint256", 94 | "name": "amtB", 95 | "type": "uint256" 96 | } 97 | ], 98 | "name": "getDepositAmountNewPool", 99 | "outputs": [ 100 | { 101 | "internalType": "uint256", 102 | "name": "unitAmt", 103 | "type": "uint256" 104 | } 105 | ], 106 | "stateMutability": "view", 107 | "type": "function" 108 | }, 109 | { 110 | "inputs": [], 111 | "name": "getEthAddr", 112 | "outputs": [ 113 | { 114 | "internalType": "address", 115 | "name": "", 116 | "type": "address" 117 | } 118 | ], 119 | "stateMutability": "pure", 120 | "type": "function" 121 | }, 122 | { 123 | "inputs": [ 124 | { 125 | "internalType": "address", 126 | "name": "owner", 127 | "type": "address" 128 | }, 129 | { 130 | "components": [ 131 | { 132 | "internalType": "address", 133 | "name": "tokenA", 134 | "type": "address" 135 | }, 136 | { 137 | "internalType": "address", 138 | "name": "tokenB", 139 | "type": "address" 140 | } 141 | ], 142 | "internalType": "struct Resolver.TokenPair[]", 143 | "name": "tokenPairs", 144 | "type": "tuple[]" 145 | } 146 | ], 147 | "name": "getPosition", 148 | "outputs": [ 149 | { 150 | "components": [ 151 | { 152 | "internalType": "uint256", 153 | "name": "tokenAShareAmt", 154 | "type": "uint256" 155 | }, 156 | { 157 | "internalType": "uint256", 158 | "name": "tokenBShareAmt", 159 | "type": "uint256" 160 | }, 161 | { 162 | "internalType": "uint256", 163 | "name": "uniAmt", 164 | "type": "uint256" 165 | }, 166 | { 167 | "internalType": "uint256", 168 | "name": "totalSupply", 169 | "type": "uint256" 170 | } 171 | ], 172 | "internalType": "struct Resolver.PoolData[]", 173 | "name": "", 174 | "type": "tuple[]" 175 | } 176 | ], 177 | "stateMutability": "view", 178 | "type": "function" 179 | }, 180 | { 181 | "inputs": [ 182 | { 183 | "internalType": "address", 184 | "name": "buyAddr", 185 | "type": "address" 186 | }, 187 | { 188 | "internalType": "address", 189 | "name": "sellAddr", 190 | "type": "address" 191 | }, 192 | { 193 | "internalType": "uint256", 194 | "name": "buyAmt", 195 | "type": "uint256" 196 | }, 197 | { 198 | "internalType": "uint256", 199 | "name": "slippage", 200 | "type": "uint256" 201 | } 202 | ], 203 | "name": "getSellAmount", 204 | "outputs": [ 205 | { 206 | "internalType": "uint256", 207 | "name": "sellAmt", 208 | "type": "uint256" 209 | }, 210 | { 211 | "internalType": "uint256", 212 | "name": "unitAmt", 213 | "type": "uint256" 214 | } 215 | ], 216 | "stateMutability": "view", 217 | "type": "function" 218 | }, 219 | { 220 | "inputs": [ 221 | { 222 | "internalType": "address", 223 | "name": "tokenA", 224 | "type": "address" 225 | }, 226 | { 227 | "internalType": "address", 228 | "name": "tokenB", 229 | "type": "address" 230 | }, 231 | { 232 | "internalType": "uint256", 233 | "name": "uniAmt", 234 | "type": "uint256" 235 | }, 236 | { 237 | "internalType": "uint256", 238 | "name": "slippage", 239 | "type": "uint256" 240 | } 241 | ], 242 | "name": "getWithdrawAmounts", 243 | "outputs": [ 244 | { 245 | "internalType": "uint256", 246 | "name": "amtA", 247 | "type": "uint256" 248 | }, 249 | { 250 | "internalType": "uint256", 251 | "name": "amtB", 252 | "type": "uint256" 253 | }, 254 | { 255 | "internalType": "uint256", 256 | "name": "unitAmtA", 257 | "type": "uint256" 258 | }, 259 | { 260 | "internalType": "uint256", 261 | "name": "unitAmtB", 262 | "type": "uint256" 263 | } 264 | ], 265 | "stateMutability": "view", 266 | "type": "function" 267 | }, 268 | { 269 | "inputs": [], 270 | "name": "name", 271 | "outputs": [ 272 | { 273 | "internalType": "string", 274 | "name": "", 275 | "type": "string" 276 | } 277 | ], 278 | "stateMutability": "view", 279 | "type": "function" 280 | } 281 | ] 282 | -------------------------------------------------------------------------------- /scripts/constant/abis.ts: -------------------------------------------------------------------------------- 1 | export default { 2 | connectors: { 3 | basic: require("./abi/connectors/basic.json"), 4 | auth: require("./abi/connectors/auth.json"), 5 | compound: require("./abi/connectors/compound.json"), 6 | maker: require("./abi/connectors/maker.json"), 7 | uniswap: require("./abi/connectors/uniswap.json"), 8 | }, 9 | read: { 10 | core: require("./abi/read/core.json"), 11 | compound: require("./abi/read/compound.json"), 12 | maker: require("./abi/read/maker.json"), 13 | erc20: require("./abi/read/erc20.json"), 14 | }, 15 | basic: { 16 | erc20: require("./abi/basics/erc20.json"), 17 | }, 18 | }; 19 | -------------------------------------------------------------------------------- /scripts/constant/addresses.ts: -------------------------------------------------------------------------------- 1 | export default { 2 | connectors: { 3 | basic: "0xe5398f279175962E56fE4c5E0b62dc7208EF36c6", 4 | auth: "0xd1aff9f2acf800c876c409100d6f39aea93fc3d9", 5 | compound: "0x07F81230d73a78f63F0c2A3403AD281b067d28F8", 6 | maker: "0x6c4E4D4aB22cAB08b8498a3A232D92609e8b2d62", 7 | uniswap: "0x62EbfF47B2Ba3e47796efaE7C51676762dC961c0", 8 | }, 9 | read: { 10 | core: "0x621AD080ad3B839e7b19e040C77F05213AB71524", 11 | erc20: "0x6d9c624844e61280c19fd7ef588d79a6de893d64", 12 | compound: "0x1f22D77365d8BFE3b901C33C83C01B584F946617", 13 | maker: "0x0A7008B38E7015F8C36A49eEbc32513ECA8801E5", 14 | uniswap: "0x492e5f3f01d20513fc0d53ca0215b6499faec8a0", 15 | }, 16 | InstaIndex: { 17 | mainnet: "0x2971adfa57b20e5a416ae5a708a8655a9c74f723", 18 | polygon: "0xA9B99766E6C676Cf1975c0D3166F96C0848fF5ad", 19 | arbitrum: "0x1eE00C305C51Ff3bE60162456A9B533C07cD9288", 20 | avalanche: "0x6CE3e607C808b4f4C26B7F6aDAeB619e49CAbb25", 21 | }, 22 | }; 23 | -------------------------------------------------------------------------------- /scripts/constant/tokens.ts: -------------------------------------------------------------------------------- 1 | export default { 2 | eth: { 3 | type: "token", 4 | symbol: "ETH", 5 | name: "Ethereum", 6 | address: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", 7 | decimals: 18, 8 | }, 9 | dai: { 10 | type: "token", 11 | symbol: "DAI", 12 | name: "DAI Stable", 13 | address: "0x6B175474E89094C44Da98b954EedeAC495271d0F", 14 | decimals: 18, 15 | }, 16 | usdc: { 17 | type: "token", 18 | symbol: "USDC", 19 | name: "USD Coin", 20 | address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", 21 | decimals: 6, 22 | }, 23 | }; 24 | -------------------------------------------------------------------------------- /scripts/deployAll.ts: -------------------------------------------------------------------------------- 1 | import { BytesLike } from "ethers"; 2 | import hre from "hardhat"; 3 | const { web3, ethers } = hre; 4 | import instaDeployContract from "./deployContract"; 5 | 6 | async function main() { 7 | const [deployer] = await ethers.getSigners(); 8 | const deployerAddress = deployer.address; 9 | 10 | console.log(`Deployer Address: ${deployerAddress}`); 11 | 12 | console.log(" Deploying Contracts to", hre.network.name, "..."); 13 | 14 | const instaIndex = await instaDeployContract("InstaIndex", []); 15 | 16 | const instaList = await instaDeployContract("InstaList", [ 17 | instaIndex.address, 18 | ]); 19 | 20 | const instaAccount = await instaDeployContract("InstaAccount", [ 21 | instaIndex.address, 22 | ]); 23 | 24 | const instaConnectors = await instaDeployContract("InstaConnectors", [ 25 | instaIndex.address, 26 | ]); 27 | 28 | const instaEvent = await instaDeployContract("InstaEvent", [ 29 | instaList.address, 30 | ]); 31 | 32 | const instaMemory = await instaDeployContract("InstaMemory", []); 33 | 34 | const instaConnectorsV2Impl = await instaDeployContract( 35 | "InstaConnectorsV2Impl", 36 | [] 37 | ); 38 | 39 | const instaConnectorsV2Proxy = await instaDeployContract( 40 | "InstaConnectorsV2Proxy", 41 | [ 42 | instaConnectorsV2Impl.address, 43 | "0x9800020b610194dBa52CF606E8Aa142F9F256166", 44 | "0x", 45 | ] 46 | ); 47 | 48 | const instaConnectorsV2 = await instaDeployContract("InstaConnectorsV2", [ 49 | instaIndex.address, 50 | ]); 51 | 52 | const implementationsMapping = await instaDeployContract( 53 | "InstaImplementations", 54 | [instaIndex.address] 55 | ); 56 | 57 | const instaAccountV2Proxy = await instaDeployContract("InstaAccountV2", [ 58 | implementationsMapping.address, 59 | ]); 60 | 61 | const instaAccountV2DefaultImpl = await instaDeployContract( 62 | "InstaDefaultImplementation", 63 | [instaIndex.address] 64 | ); 65 | 66 | const instaAccountV2ImplM1 = await instaDeployContract( 67 | "InstaImplementationM1", 68 | [instaIndex.address, instaConnectorsV2.address] 69 | ); 70 | 71 | console.log("\n########### setBasics ########"); 72 | 73 | const setBasicsArgs: [string, string, string, string] = [ 74 | deployerAddress, 75 | instaList.address, 76 | instaAccount.address, 77 | instaConnectors.address, 78 | ]; 79 | 80 | const tx = await instaIndex.setBasics(...setBasicsArgs); 81 | const txDetails = await tx.wait(); 82 | console.log(` 83 | status: ${txDetails.status == 1}, 84 | tx: ${txDetails.transactionHash}, 85 | `); 86 | console.log("###########"); 87 | 88 | console.log("\n########### Add DSAv2 Implementations ########"); 89 | let txSetDefaultImplementation = await implementationsMapping.setDefaultImplementation( 90 | instaAccountV2DefaultImpl.address 91 | ); 92 | let txSetDefaultImplementationDetails = await txSetDefaultImplementation.wait(); 93 | 94 | const implementationV1Args: [string, BytesLike[]] = [ 95 | instaAccountV2ImplM1.address, 96 | ["cast(string[],bytes[],address)"].map((a) => 97 | web3.utils.keccak256(a).slice(0, 10) 98 | ), 99 | ]; 100 | const txAddImplementation = await implementationsMapping.addImplementation( 101 | ...implementationV1Args 102 | ); 103 | const txAddImplementationDetails = await txAddImplementation.wait(); 104 | console.log(` 105 | status: ${txAddImplementationDetails.status == 1}, 106 | tx: ${txAddImplementationDetails.transactionHash}, 107 | `); 108 | console.log("###########\n"); 109 | 110 | console.log("\n\n########### Add DSAv2 ########"); 111 | const addNewAccountArgs: [string, string, string] = [ 112 | instaAccountV2Proxy.address, 113 | instaConnectorsV2Proxy.address, 114 | ethers.constants.AddressZero, 115 | ]; 116 | const txAddNewAccount = await instaIndex.addNewAccount(...addNewAccountArgs); 117 | const txDetailsAddNewAccount = await txAddNewAccount.wait(); 118 | 119 | console.log(` 120 | status: ${txDetailsAddNewAccount.status == 1}, 121 | tx: ${txDetailsAddNewAccount.transactionHash}, 122 | `); 123 | console.log("###########\n"); 124 | 125 | if (hre.network.name === "mainnet" || hre.network.name === "kovan") { 126 | // InstaIndex 127 | await hre.run("verify:verify", { 128 | address: instaIndex.address, 129 | constructorArguments: [], 130 | }); 131 | 132 | // InstaList 133 | await hre.run("verify:verify", { 134 | address: instaList.address, 135 | constructorArguments: [instaIndex.address], 136 | }); 137 | 138 | // InstaAccount 139 | await hre.run("verify:verify", { 140 | address: instaAccount.address, 141 | constructorArguments: [instaIndex.address], 142 | }); 143 | 144 | // InstaConnectors 145 | await hre.run("verify:verify", { 146 | address: instaConnectors.address, 147 | constructorArguments: [instaIndex.address], 148 | }); 149 | 150 | // InstaEvent 151 | await hre.run("verify:verify", { 152 | address: instaEvent.address, 153 | constructorArguments: [instaList.address], 154 | }); 155 | 156 | // InstaMemory 157 | await hre.run("verify:verify", { 158 | address: instaMemory.address, 159 | constructorArguments: [], 160 | }); 161 | 162 | // v2 163 | await hre.run("verify:verify", { 164 | address: instaConnectorsV2Impl.address, 165 | constructorArguments: [], 166 | contract: 167 | "contracts/v2/proxy/dummyConnectorsImpl.sol:InstaConnectorsV2Impl", 168 | }); 169 | await hre.run("verify:verify", { 170 | address: instaConnectorsV2Proxy.address, 171 | constructorArguments: [ 172 | instaConnectorsV2Impl.address, 173 | "0x9800020b610194dBa52CF606E8Aa142F9F256166", 174 | "0x", 175 | ], 176 | contract: "contracts/v2/proxy/connectorsProxy.sol:InstaConnectorsV2Proxy", 177 | }); 178 | 179 | await hre.run("verify:verify", { 180 | address: instaConnectorsV2.address, 181 | constructorArguments: [], 182 | }); 183 | 184 | await hre.run("verify:verify", { 185 | address: implementationsMapping.address, 186 | constructorArguments: [], 187 | }); 188 | 189 | await hre.run("verify:verify", { 190 | address: instaAccountV2DefaultImpl.address, 191 | constructorArguments: [], 192 | }); 193 | 194 | await hre.run("verify:verify", { 195 | address: instaAccountV2ImplM1.address, 196 | constructorArguments: [instaConnectorsV2.address], 197 | }); 198 | 199 | await hre.run("verify:verify", { 200 | address: instaAccountV2Proxy.address, 201 | constructorArguments: [implementationsMapping.address], 202 | }); 203 | } else { 204 | console.log("Contracts deployed to", hre.network.name); 205 | } 206 | } 207 | 208 | main() 209 | .then(() => process.exit(0)) 210 | .catch((error) => { 211 | console.error(error); 212 | process.exit(1); 213 | }); 214 | -------------------------------------------------------------------------------- /scripts/deployChiefTimelock.ts: -------------------------------------------------------------------------------- 1 | import hre from "hardhat"; 2 | const { ethers } = hre; 3 | import instaDeployContract from "./deployContract"; 4 | 5 | async function main() { 6 | const chiefMultiSig = "0xa8c31E39e40E6765BEdBd83D92D6AA0B33f1CCC5"; 7 | 8 | const instaTimelockContract = await instaDeployContract( 9 | "InstaChiefTimelockContract", 10 | [[chiefMultiSig]] 11 | ); 12 | 13 | if (hre.network.name === "mainnet" || hre.network.name === "kovan") { 14 | await hre.run("verify:verify", { 15 | address: instaTimelockContract.address, 16 | constructorArguments: [[chiefMultiSig]], 17 | }); 18 | } else { 19 | console.log(`Contracts deployed to ${hre.network.name}`); 20 | } 21 | } 22 | 23 | main() 24 | .then(() => process.exit(0)) 25 | .catch((error) => { 26 | console.error(error); 27 | process.exit(1); 28 | }); 29 | -------------------------------------------------------------------------------- /scripts/deployConnector.ts: -------------------------------------------------------------------------------- 1 | import abis from "./constant/abis"; 2 | import addresses from "./constant/addresses"; 3 | 4 | import hre from "hardhat"; 5 | const { ethers } = hre; 6 | 7 | export default async function ({ connectorName, contract, factory }, args?) { 8 | const ConnectorInstance = ( 9 | await ethers.getContractFactory(contract) 10 | ); 11 | const connectorInstance = await ConnectorInstance.deploy(...args); 12 | await connectorInstance.deployed(); 13 | 14 | console.log(`${connectorName} Deployed: ${connectorInstance.address}`); 15 | 16 | addresses.connectors[connectorName] = connectorInstance.address; 17 | abis.connectors[connectorName] = factory.abi; 18 | 19 | return connectorInstance; 20 | } 21 | -------------------------------------------------------------------------------- /scripts/deployConnectors.ts: -------------------------------------------------------------------------------- 1 | import hre from "hardhat"; 2 | import deployConnector from "./deployConnector"; 3 | 4 | export default async function (connectors: any[]) { 5 | const instances = await Promise.all( 6 | connectors.map(async (connector) => { 7 | const instance = await deployConnector({ 8 | connectorName: connector.connectorName, 9 | contract: connector.contract, 10 | factory: connector.abi, 11 | }); 12 | return instance; 13 | }) 14 | ); 15 | 16 | return instances; 17 | } 18 | -------------------------------------------------------------------------------- /scripts/deployContract.ts: -------------------------------------------------------------------------------- 1 | import hre from "hardhat"; 2 | const { ethers } = hre; 3 | 4 | export default async function ( 5 | factoryName: string, 6 | constructorArguments: Array> 7 | ) { 8 | const contractInstance = await ethers.getContractFactory(factoryName); 9 | const contract = await contractInstance.deploy(...constructorArguments); 10 | await contract.deployed(); 11 | 12 | console.log( 13 | `Contract ${factoryName} deployed at ${contract.address} on ${hre.network.name}` 14 | ); 15 | 16 | return contract; 17 | } 18 | -------------------------------------------------------------------------------- /scripts/deployContracts.ts: -------------------------------------------------------------------------------- 1 | import hre from "hardhat"; 2 | const { ethers } = hre; 3 | import addresses from "./constant/addresses"; 4 | import instaDeployContract from "./deployContract"; 5 | 6 | const networkType = process.env.networkType ?? "mainnet"; 7 | const INSTA_INDEX = addresses.InstaIndex[networkType]; 8 | 9 | export default async function () { 10 | const instaIndex = await ethers.getContractAt("InstaIndex", INSTA_INDEX); 11 | 12 | const instaConnectorsV2 = await instaDeployContract("InstaConnectorsV2", [ 13 | instaIndex.address, 14 | ]); 15 | 16 | const implementationsMapping = await instaDeployContract( 17 | "InstaImplementations", 18 | [instaIndex.address] 19 | ); 20 | 21 | const instaAccountV2Proxy = await instaDeployContract("InstaAccountV2", [ 22 | implementationsMapping.address, 23 | ]); 24 | 25 | const instaAccountV2DefaultImpl = await instaDeployContract( 26 | "InstaDefaultImplementation", 27 | [instaIndex.address] 28 | ); 29 | 30 | const instaAccountV2ImplM1 = await instaDeployContract( 31 | "InstaImplementationM1", 32 | [instaIndex.address, instaConnectorsV2.address] 33 | ); 34 | 35 | const instaAccountV2ImplM2 = await instaDeployContract( 36 | "InstaImplementationM2", 37 | [instaIndex.address, instaConnectorsV2.address] 38 | ); 39 | 40 | return { 41 | instaIndex, 42 | instaConnectorsV2, 43 | implementationsMapping, 44 | instaAccountV2Proxy, 45 | instaAccountV2DefaultImpl, 46 | instaAccountV2ImplM1, 47 | instaAccountV2ImplM2, 48 | }; 49 | } 50 | -------------------------------------------------------------------------------- /scripts/deployTimelock.ts: -------------------------------------------------------------------------------- 1 | import hre from "hardhat"; 2 | const { ethers } = hre; 3 | import instaDeployContract from "./deployContract"; 4 | 5 | async function main() { 6 | const masterSig = "0xa8c31E39e40E6765BEdBd83D92D6AA0B33f1CCC5"; 7 | 8 | const instaTimelockContract = await instaDeployContract( 9 | "InstaTimelockContract", 10 | [[masterSig]] 11 | ); 12 | 13 | if (hre.network.name === "mainnet" || hre.network.name === "kovan") { 14 | await hre.run("verify:verify", { 15 | address: instaTimelockContract.address, 16 | constructorArguments: [], 17 | }); 18 | } else { 19 | console.log(`Contracts deployed to ${hre.network.name}`); 20 | } 21 | } 22 | 23 | main() 24 | .then(() => process.exit(0)) 25 | .catch((error) => { 26 | console.error(error); 27 | process.exit(1); 28 | }); 29 | -------------------------------------------------------------------------------- /scripts/deploy_v2.ts: -------------------------------------------------------------------------------- 1 | import hre from "hardhat"; 2 | const { ethers } = hre; 3 | import addresses from "./constant/addresses"; 4 | import instaDeployContract from "./deployContract"; 5 | 6 | const networkType = String(process.env.networkType) ?? "mainnet"; 7 | const INSTA_INDEX = addresses.InstaIndex[networkType]; 8 | 9 | async function main() { 10 | const instaConnectorsV2Impl = await instaDeployContract( 11 | "InstaConnectorsV2Impl", 12 | [] 13 | ); 14 | 15 | const instaConnectorsV2Proxy = await instaDeployContract( 16 | "InstaConnectorsV2Proxy", 17 | [ 18 | instaConnectorsV2Impl.address, 19 | "0x9800020b610194dBa52CF606E8Aa142F9F256166", 20 | "0x", 21 | ] 22 | ); 23 | 24 | const instaConnectorsV2 = await instaDeployContract("InstaConnectorsV2", [ 25 | INSTA_INDEX, 26 | ]); 27 | 28 | const implementationsMapping = await instaDeployContract( 29 | "InstaImplementations", 30 | [INSTA_INDEX] 31 | ); 32 | 33 | const instaAccountV2Proxy = await instaDeployContract("InstaAccountV2", [ 34 | implementationsMapping.address, 35 | ]); 36 | 37 | const instaAccountV2DefaultImpl = await instaDeployContract( 38 | "InstaDefaultImplementation", 39 | [INSTA_INDEX] 40 | ); 41 | 42 | const instaAccountV2ImplM1 = await instaDeployContract( 43 | "InstaImplementationM1", 44 | [INSTA_INDEX, instaConnectorsV2.address] 45 | ); 46 | 47 | if (hre.network.name === "mainnet" || hre.network.name === "kovan") { 48 | await hre.run("verify:verify", { 49 | address: instaConnectorsV2Impl.address, 50 | constructorArguments: [], 51 | contract: 52 | "contracts/v2/proxy/dummyConnectorsImpl.sol:InstaConnectorsV2Impl", 53 | }); 54 | await hre.run("verify:verify", { 55 | address: instaConnectorsV2Proxy.address, 56 | constructorArguments: [ 57 | instaConnectorsV2Impl.address, 58 | "0x9800020b610194dBa52CF606E8Aa142F9F256166", 59 | "0x", 60 | ], 61 | contract: "contracts/v2/proxy/connectorsProxy.sol:InstaConnectorsV2Proxy", 62 | }); 63 | 64 | await hre.run("verify:verify", { 65 | address: "0x97b0B3A8bDeFE8cB9563a3c610019Ad10DB8aD11", 66 | constructorArguments: [INSTA_INDEX], 67 | }); 68 | 69 | await hre.run("verify:verify", { 70 | address: implementationsMapping.address, 71 | constructorArguments: [INSTA_INDEX], 72 | }); 73 | 74 | await hre.run("verify:verify", { 75 | address: instaAccountV2DefaultImpl.address, 76 | constructorArguments: [INSTA_INDEX], 77 | }); 78 | 79 | await hre.run("verify:verify", { 80 | address: instaAccountV2ImplM1.address, 81 | constructorArguments: [INSTA_INDEX, instaConnectorsV2.address], 82 | }); 83 | 84 | await hre.run("verify:verify", { 85 | address: instaAccountV2Proxy.address, 86 | constructorArguments: [implementationsMapping.address], 87 | }); 88 | } else { 89 | console.log(`Contracts deployed to ${hre.network.name}`); 90 | } 91 | } 92 | 93 | main() 94 | .then(() => process.exit(0)) 95 | .catch((error) => { 96 | console.error(error); 97 | process.exit(1); 98 | }); 99 | -------------------------------------------------------------------------------- /scripts/enableConnector.ts: -------------------------------------------------------------------------------- 1 | import abis from "./constant/abis"; 2 | import addresses from "./constant/addresses"; 3 | 4 | export default function ({ connectorName, address, abi }) { 5 | addresses.connectors[connectorName] = address; 6 | abis.connectors[connectorName] = abi; 7 | 8 | return { addresses, abis }; 9 | } 10 | -------------------------------------------------------------------------------- /scripts/encodeSpells.ts: -------------------------------------------------------------------------------- 1 | import abis from "./constant/abis"; 2 | import addresses from "./constant/addresses"; 3 | import hre from "hardhat"; 4 | const { web3 } = hre; 5 | 6 | export default function (spells: any[]) { 7 | const targets = spells.map((a: { connector: any }) => a.connector); 8 | const calldatas = spells.map( 9 | (a: { method: any; connector: string | number; args: any }) => { 10 | const functionName = a.method; 11 | const abi = abis.connectors[a.connector].find((b: { name: any }) => { 12 | return b.name === functionName; 13 | }); 14 | if (!abi) throw new Error("Couldn't find function"); 15 | return web3.eth.abi.encodeFunctionCall(abi, a.args); 16 | } 17 | ); 18 | return [targets, calldatas]; 19 | } 20 | -------------------------------------------------------------------------------- /scripts/expectEvent.ts: -------------------------------------------------------------------------------- 1 | import hre from "hardhat"; 2 | const { web3 } = hre; 3 | import { expect } from "chai"; 4 | 5 | export default function ( 6 | receipt: any, 7 | abi: any[], 8 | eventName?: any, 9 | eventArgs?: any, 10 | castEvents?: string | any[] 11 | ) { 12 | const requiredEventABI = abi 13 | .filter((a) => a.type === "event") 14 | .find((a) => a.name === eventName); 15 | if (!requiredEventABI) throw new Error(`${eventName} not found`); 16 | const eventHash = web3.utils.keccak256( 17 | `${requiredEventABI.name}(${requiredEventABI.inputs 18 | .map((a: { type: any }) => a.type) 19 | .toString()})` 20 | ); 21 | const requiredEvent = receipt.events.find( 22 | (a: { topics: any[] }) => a.topics[0] === eventHash 23 | ); 24 | expect(!!requiredEvent).to.be.true; 25 | const decodedEvent = web3.eth.abi.decodeLog( 26 | requiredEventABI.inputs, 27 | requiredEvent.data, 28 | requiredEvent.topics.slice(1) 29 | ); 30 | 31 | if (eventArgs) { 32 | Object.keys(eventArgs).forEach((name) => { 33 | if (!decodedEvent[name]) throw new Error(`${name} arg not found`); 34 | expect(eventArgs[name]).to.be.equal(decodedEvent[name]); 35 | }); 36 | } 37 | if (castEvents && castEvents.length > 0) { 38 | for (const castEvent of castEvents) { 39 | const abi = castEvent.abi; 40 | const eventName = castEvent.eventName; 41 | const eventParams = castEvent.eventParams; 42 | 43 | const eventArgs = requiredEvent.args; 44 | expect(!!eventArgs).to.be.true; 45 | 46 | const ABI = abi 47 | .filter((a: { type: string }) => a.type === "event") 48 | .find((a: { name: any }) => a.name === eventName); 49 | 50 | if (eventName) { 51 | const eventSignature = `${ABI.name}(${ABI.inputs 52 | .map((a: { type: any }) => a.type) 53 | .toString()})`; 54 | expect(eventArgs.eventNames).to.include(eventSignature); 55 | } 56 | 57 | if (eventParams) { 58 | const eventParamHash = web3.eth.abi.encodeParameters( 59 | ABI.inputs, 60 | eventParams 61 | ); 62 | expect(eventArgs.eventParams).to.include(eventParamHash); 63 | } 64 | } 65 | } 66 | return requiredEvent; 67 | } 68 | -------------------------------------------------------------------------------- /scripts/flatten.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | baseContractPath='contracts' 4 | function find() { 5 | for file in "$1"/*; do 6 | if [[ -d "$file" ]]; then 7 | # echo "directory $file" 8 | mkdir flatten/$file 9 | find $file 10 | elif [[ -f "$file" ]]; then 11 | echo "Created [`basename "$file"`]" 12 | npx hardhat flatten $file > flatten/$file 13 | fi 14 | done 15 | } 16 | 17 | rm -rf flatten/$baseContractPath 18 | mkdir flatten/$baseContractPath 19 | find $baseContractPath -------------------------------------------------------------------------------- /scripts/getMasterSigner.ts: -------------------------------------------------------------------------------- 1 | import hre from "hardhat"; 2 | const { ethers } = hre; 3 | import addresses from "./constant/addresses"; 4 | 5 | const networkType = process.env.networkType ?? "mainnet"; 6 | const INSTA_INDEX = addresses.InstaIndex[networkType]; 7 | 8 | export default async function () { 9 | const instaIndex = await ethers.getContractAt("InstaIndex", INSTA_INDEX); 10 | 11 | const masterAddress = await instaIndex.master(); // TODO: make it constant? 12 | await hre.network.provider.request({ 13 | method: "hardhat_impersonateAccount", 14 | params: [masterAddress], 15 | }); 16 | 17 | return ethers.provider.getSigner(masterAddress); 18 | } 19 | -------------------------------------------------------------------------------- /scripts/spells/addAuth.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import hre from "hardhat"; 3 | const { ethers } = hre; 4 | 5 | import encodeSpells from "../encodeSpells"; 6 | 7 | module.exports = async function ( 8 | dsaWallet: any, 9 | userWallet: any, 10 | toAddAuthAddress: any 11 | ) { 12 | const spells = [ 13 | { 14 | connector: "auth", 15 | method: "add", 16 | args: [toAddAuthAddress], 17 | }, 18 | ]; 19 | const tx = await dsaWallet 20 | .connect(userWallet) 21 | .cast( 22 | ...encodeSpells(spells), 23 | "0xA35f3FEFEcb5160327d1B6A210b60D1e1d7968e3" 24 | ); 25 | return tx; 26 | }; 27 | -------------------------------------------------------------------------------- /test/betamode.test.ts: -------------------------------------------------------------------------------- 1 | import { expect } from "chai"; 2 | import hre from "hardhat"; 3 | import deployContracts from "../scripts/deployContracts"; 4 | import deployConnector from "../scripts/deployConnector"; 5 | import encodeSpells from "../scripts/encodeSpells"; 6 | import getMasterSigner from "../scripts/getMasterSigner"; 7 | import addresses from "../scripts/constant/addresses"; 8 | import { 9 | InstaDefaultImplementationV2__factory, 10 | ConnectV2Beta__factory, 11 | } from "../typechain"; 12 | const { ethers, web3, deployments, waffle } = hre; 13 | const { provider, deployContract } = waffle; 14 | import type { Signer, Contract } from "ethers"; 15 | 16 | describe("Betamode", function () { 17 | const address_zero = "0x0000000000000000000000000000000000000000"; 18 | 19 | let instaConnectorsV2: Contract, 20 | implementationsMapping: Contract, 21 | instaAccountV2Proxy: Contract, 22 | instaAccountV2ImplM1: Contract, 23 | instaAccountV2ImplM2: Contract, 24 | instaAccountV2DefaultImpl: Contract, 25 | instaAccountV2DefaultImplV2: Contract, 26 | instaIndex: Contract, 27 | instaAccountV2ImplBeta: Contract; 28 | 29 | const instaAccountV2DefaultImplSigsV2 = [ 30 | "enable(address)", 31 | "disable(address)", 32 | "isAuth(address)", 33 | "switchShield(bool)", 34 | "shield()", 35 | "isBeta() returns bool", 36 | "toogleBeta()", 37 | ].map((a) => web3.utils.keccak256(a).slice(0, 10)); 38 | 39 | const instaAccountV2ImplM1Sigs = ["cast(string[],bytes[],address)"].map((a) => 40 | web3.utils.keccak256(a).slice(0, 10) 41 | ); 42 | 43 | const instaAccountV2ImplBetaSigs = ["castBeta(string[],bytes[],address)"].map( 44 | (a) => web3.utils.keccak256(a).slice(0, 10) 45 | ); 46 | 47 | let masterSigner: Signer; 48 | 49 | let acountV2DsaM1Wallet0: Contract; 50 | let acountV2DsaDefaultWallet0: Contract; 51 | let acountV2DsaBetaWallet0: Contract; 52 | 53 | const wallets = provider.getWallets(); 54 | let [wallet0] = wallets; 55 | before(async () => { 56 | await hre.network.provider.request({ 57 | method: "hardhat_reset", 58 | params: [ 59 | { 60 | forking: { 61 | // @ts-ignore 62 | jsonRpcUrl: hre.config.networks.hardhat.forking.url, 63 | blockNumber: 12068005, 64 | }, 65 | }, 66 | ], 67 | }); 68 | const result = await deployContracts(); 69 | instaAccountV2DefaultImpl = result.instaAccountV2DefaultImpl; 70 | instaIndex = result.instaIndex; 71 | instaConnectorsV2 = result.instaConnectorsV2; 72 | implementationsMapping = result.implementationsMapping; 73 | instaAccountV2Proxy = result.instaAccountV2Proxy; 74 | instaAccountV2ImplM1 = result.instaAccountV2ImplM1; 75 | instaAccountV2ImplM2 = result.instaAccountV2ImplM2; 76 | 77 | const InstaAccountV2ImplBeta = await ethers.getContractFactory( 78 | "InstaImplementationBetaTest" 79 | ); 80 | instaAccountV2ImplBeta = await InstaAccountV2ImplBeta.deploy( 81 | instaIndex.address, 82 | instaConnectorsV2.address 83 | ); 84 | masterSigner = await getMasterSigner(); 85 | instaAccountV2DefaultImplV2 = await deployContract( 86 | masterSigner, 87 | InstaDefaultImplementationV2__factory, 88 | [] 89 | ); 90 | }); 91 | 92 | it("Should have contracts deployed.", async function () { 93 | expect(!!instaConnectorsV2.address).to.be.true; 94 | expect(!!implementationsMapping.address).to.be.true; 95 | expect(!!instaAccountV2Proxy.address).to.be.true; 96 | expect(!!instaAccountV2ImplM1.address).to.be.true; 97 | expect(!!instaAccountV2ImplM2.address).to.be.true; 98 | }); 99 | 100 | describe("Implementations", function () { 101 | it("Should add default implementation to mapping.", async function () { 102 | const tx = await implementationsMapping 103 | .connect(masterSigner) 104 | .setDefaultImplementation(instaAccountV2DefaultImpl.address); 105 | await tx.wait(); 106 | expect(await implementationsMapping.defaultImplementation()).to.be.equal( 107 | instaAccountV2DefaultImpl.address 108 | ); 109 | }); 110 | 111 | it("Should add instaAccountV2ImplM1 sigs to mapping.", async function () { 112 | const tx = await implementationsMapping 113 | .connect(masterSigner) 114 | .addImplementation( 115 | instaAccountV2ImplM1.address, 116 | instaAccountV2ImplM1Sigs 117 | ); 118 | await tx.wait(); 119 | expect( 120 | await implementationsMapping.getSigImplementation( 121 | instaAccountV2ImplM1Sigs[0] 122 | ) 123 | ).to.be.equal(instaAccountV2ImplM1.address); 124 | ( 125 | await implementationsMapping.getImplementationSigs( 126 | instaAccountV2ImplM1.address 127 | ) 128 | ).forEach((a: any, i: any) => { 129 | expect(a).to.be.eq(instaAccountV2ImplM1Sigs[i]); 130 | }); 131 | }); 132 | 133 | it("Should add instaAccountV2ImplBeta sigs to mapping.", async function () { 134 | const tx = await implementationsMapping 135 | .connect(masterSigner) 136 | .addImplementation( 137 | instaAccountV2ImplBeta.address, 138 | instaAccountV2ImplBetaSigs 139 | ); 140 | await tx.wait(); 141 | expect( 142 | await implementationsMapping.getSigImplementation( 143 | instaAccountV2ImplBetaSigs[0] 144 | ) 145 | ).to.be.equal(instaAccountV2ImplBeta.address); 146 | ( 147 | await implementationsMapping.getImplementationSigs( 148 | instaAccountV2ImplBeta.address 149 | ) 150 | ).forEach((a, i) => { 151 | expect(a).to.be.eq(instaAccountV2ImplBetaSigs[i]); 152 | }); 153 | }); 154 | 155 | it("Should add InstaAccountV2 in Index.sol", async function () { 156 | const tx = await instaIndex 157 | .connect(masterSigner) 158 | .addNewAccount(instaAccountV2Proxy.address, address_zero, address_zero); 159 | await tx.wait(); 160 | expect(await instaIndex.account(2)).to.be.equal( 161 | instaAccountV2Proxy.address 162 | ); 163 | }); 164 | 165 | it("Should add InstaDefaultImplementationV2 sigs to mapping.", async function () { 166 | const tx = await implementationsMapping 167 | .connect(masterSigner) 168 | .addImplementation( 169 | instaAccountV2DefaultImplV2.address, 170 | instaAccountV2DefaultImplSigsV2 171 | ); 172 | await tx.wait(); 173 | expect( 174 | await implementationsMapping.getSigImplementation( 175 | instaAccountV2DefaultImplSigsV2[0] 176 | ) 177 | ).to.be.equal(instaAccountV2DefaultImplV2.address); 178 | ( 179 | await implementationsMapping.getImplementationSigs( 180 | instaAccountV2DefaultImplV2.address 181 | ) 182 | ).forEach((a, i) => { 183 | expect(a).to.be.eq(instaAccountV2DefaultImplSigsV2[i]); 184 | }); 185 | }); 186 | }); 187 | 188 | describe("Beta-mode", function () { 189 | it("Should build DSA v2", async function () { 190 | const tx = await instaIndex 191 | .connect(wallet0) 192 | .build(wallet0.address, 2, wallet0.address); 193 | const dsaWalletAddress = "0xC13920c134d38408871E7AF5C102894CB5180B92"; 194 | expect((await tx.wait()).events[1].args.account).to.be.equal( 195 | dsaWalletAddress 196 | ); 197 | acountV2DsaM1Wallet0 = await ethers.getContractAt( 198 | "InstaImplementationM1", 199 | dsaWalletAddress 200 | ); 201 | 202 | acountV2DsaDefaultWallet0 = await ethers.getContractAt( 203 | "InstaDefaultImplementation", 204 | dsaWalletAddress 205 | ); 206 | acountV2DsaBetaWallet0 = await ethers.getContractAt( 207 | "InstaImplementationBetaTest", 208 | dsaWalletAddress 209 | ); 210 | }); 211 | 212 | it("Should deploy Beta connector", async function () { 213 | const connectorName = "betaV2"; 214 | await deployConnector({ 215 | connectorName, 216 | contract: "ConnectV2Beta", 217 | factory: ConnectV2Beta__factory, 218 | }); 219 | expect(!!addresses.connectors["betaV2"]).to.be.true; 220 | const tx = await instaConnectorsV2 221 | .connect(masterSigner) 222 | .addConnectors(["betaV2"], [addresses.connectors["betaV2"]]); 223 | const receipt = await tx.wait(); 224 | const events = receipt.events; 225 | expect(events[0].args.connectorNameHash).to.be.eq( 226 | web3.utils.keccak256(connectorName) 227 | ); 228 | expect(events[0].args.connectorName).to.be.eq(connectorName); 229 | }); 230 | 231 | it("Should enable/disable beta-mode", async function () { 232 | const spell0 = { 233 | connector: "betaV2", 234 | method: "enable", 235 | args: [], 236 | }; 237 | const encodedSpells = encodeSpells([spell0]); 238 | const tx0 = await acountV2DsaM1Wallet0 239 | .connect(wallet0) 240 | .cast(encodedSpells[0], encodedSpells[1], wallet0.address); 241 | const receipt0 = await tx0.wait(); 242 | 243 | let enabled = await acountV2DsaDefaultWallet0.connect(wallet0).isBeta(); 244 | expect(enabled).to.equal(true); 245 | 246 | const spell1 = { 247 | connector: "betaV2", 248 | method: "disable", 249 | args: [], 250 | }; 251 | const encodedSpell1 = encodeSpells([spell1]); 252 | const tx1 = await acountV2DsaBetaWallet0 253 | .connect(wallet0) 254 | .castBeta(encodedSpell1[0], encodedSpell1[1], wallet0.address); 255 | const receipt1 = await tx1.wait(); 256 | 257 | enabled = await acountV2DsaDefaultWallet0.connect(wallet0).isBeta(); 258 | expect(enabled).to.equal(false); 259 | }); 260 | }); 261 | }); 262 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | // tsconfig.json 2 | { 3 | "compilerOptions": { 4 | "esModuleInterop": true, 5 | "forceConsistentCasingInFileNames": true, 6 | "lib": [ 7 | "es5", 8 | "es6" 9 | ], 10 | "module": "commonjs", 11 | "moduleResolution": "node", 12 | "outDir": "dist", 13 | "resolveJsonModule": true, 14 | "noImplicitAny": false, 15 | "sourceMap": true, 16 | "strict": true, 17 | "target": "es5", 18 | }, 19 | "exclude": [ 20 | "artifacts", 21 | "node_modules" 22 | ], 23 | "files": [ 24 | "./hardhat.config.ts" 25 | ], 26 | "include": [ 27 | "artifacts/**/*", 28 | "artifacts/**/*.json", 29 | "scripts/**/*", 30 | "tasks/**/*", 31 | "test/**/*", 32 | "typechain/**/*", 33 | "types/**/*" 34 | ] 35 | } --------------------------------------------------------------------------------