From ab8903ee7969fdb677d1b0d5e8347c076aa37db0 Mon Sep 17 00:00:00 2001 From: Sowmay Jain Date: Tue, 9 Jun 2020 21:59:43 +1000 Subject: [PATCH] edits --- forkMainnet.md => fork-mainnet.md | 25 +++++++----- tenderly.md => tenderly-simulation.md | 5 +-- web3.md => web3-implementation.md | 56 +++++++-------------------- 3 files changed, 32 insertions(+), 54 deletions(-) rename forkMainnet.md => fork-mainnet.md (96%) rename tenderly.md => tenderly-simulation.md (99%) rename web3.md => web3-implementation.md (68%) diff --git a/forkMainnet.md b/fork-mainnet.md similarity index 96% rename from forkMainnet.md rename to fork-mainnet.md index 40eb9b6..a41a32e 100644 --- a/forkMainnet.md +++ b/fork-mainnet.md @@ -1,7 +1,9 @@ # Fork-Ethereum-Mainnet + Interact with InstaDApp DSA using Forked Mainnet from your local network When you want to interact with contracts that are deployed on the Ethereum mainnet for development purpose without spending any ether you can fork the mainnet from a particular block number and then interact with that forked mainnet on your local machine. + So, today we will take a look at how you can fork the mainnet and interact with DSA contracts and spells. **Step 1:** Forking the Ethereum Mainnet @@ -11,6 +13,7 @@ Open terminal and run ```javascript ganache-cli --fork https://mainnet.infura.io/v3/{Project_Id} --unlock {Ethereum_Address} -p {Port_Number} --networkId 1 ``` + @@ -33,10 +36,8 @@ ganache-cli --fork https://mainnet.infura.io/v3/{Project_Id} --unlock {Ethereum_
Parameters
- ![alt text](https://github.com/InstaDApp/dsa-developers/blob/master/img/forkMainnet/infura.png) - If you want to fork mainnet at a particular block number you can do that by providing value of Block_Number after infura Project_ID ```javascript @@ -58,9 +59,11 @@ After cloning run ```javascript npm install``` in the cloned repo directory. Before interacting with DSA make sure you have configured .env file which contains the private key, Ethereum address and Infura project Id. Now, open `dsa.js` file and check if the port number of your ganache-cli matches with the web3 providers. + ![alt text](https://github.com/InstaDApp/dsa-developers/blob/master/img/forkMainnet/web3.png) Now, you can interact with the DSA by using the `dsa.js` file. If you don’t have any DSA account you can create one by uncommenting this section from `dsa.js` file. + ![alt text](https://github.com/InstaDApp/dsa-developers/blob/master/img/forkMainnet/buildFunc.png) The file contains a section where you can add your spells by default it contains spells for deposit and withdraw methods of Compound Connector. @@ -72,37 +75,41 @@ File also contains methods for account setup and transfer. ![alt text](https://github.com/InstaDApp/dsa-developers/blob/master/img/forkMainnet/spells.png) After making all the changes in the file execute the file using command: + ```javascript node dsa.js ``` + This may take few minutes as ganache has to fetch contracts from mainnet and then work on them so be patient, if you want to know if it has stuck or not then head to the tab on console where the ganache-cli is working and check if it is making some calls. + If you are using the default `dsa.js` file then output will contain `dsa accounts linked to your ethereum address` and `transaction hash`that `dsa.cast()` function returns To check the transaction receipt you can follow these steps: - Step 1: Open another terminal tab -Step 2: run +Step 2 (make sure you have truffle installed on your machine): run: + ```javascript truffle console ``` -(make sure you have truffle installed on your machine) -Step 3: In the truffle console, run +Step 3: In the truffle console, run: ```javascript receipt = await web3.eth.getTransactionReceipt({txHash}) ``` + ![alt text](https://github.com/InstaDApp/dsa-developers/blob/master/img/forkMainnet/txHash.png) This will return you something like this, if your transaction went through. # Additional advice -If you want to use any particular token then you can unlock address which holds that token and you can get list of all token holders on -ethplorer. + +If you want to use any particular token then you can unlock address which holds that token and you can get list of all token holders on ethplorer. If you encounter error saying : “Error: Returned error: Returned error: project ID does not have access to archive state”. Trying reloading the ganache-cli as this will most probably fix this. + ![alt text](https://github.com/InstaDApp/dsa-developers/blob/master/img/forkMainnet/data.png) -**Note:** This is not the best way to interact with DSA as you might face a lot of errors in the process of interacting on forked mainnet. The best way is still the Ethereum Mainnet. +**Note:** This is not the best way to interact with DSA as you might face a lot of errors in the process of interacting on forked mainnet. The best way is still the Ethereum Mainnet. \ No newline at end of file diff --git a/tenderly.md b/tenderly-simulation.md similarity index 99% rename from tenderly.md rename to tenderly-simulation.md index 0ae020a..c66211f 100644 --- a/tenderly.md +++ b/tenderly-simulation.md @@ -1,4 +1,3 @@ - # Using Tenderly to simulate a transaction Tenderly is a Smart contract monitoring and alerting tool. With tenderly you can monitor smart contracts on multiple Ethereum networks. Recently, tenderly has come up with a great feature of simulating a transaction on Ethereum network which makes debugging a lot more easier than before. @@ -63,10 +62,8 @@ You can also take a look at the whole Stack Trace which your transaction went th If you want to know about the contracts that were involved in the transaction you can navigate to the `Contracts` section and take a look. - ![alt text](https://github.com/InstaDApp/dsa-developers/blob/master/img/tenderly/gasProfiler.png) There is also a feature of `Gas Profiler` which provides you with a gas usage breakdown by the function call. - -Using these steps you can simulate a transaction on tenderly and debug your transaction. +Using these steps you can simulate a transaction on tenderly and debug your transaction. \ No newline at end of file diff --git a/web3.md b/web3-implementation.md similarity index 68% rename from web3.md rename to web3-implementation.md index 7b69eee..fb6b1a8 100644 --- a/web3.md +++ b/web3-implementation.md @@ -7,6 +7,7 @@ DeFi Smart Accounts (DSA) are contract accounts **trustlessly owned by the user ## Prerequisite - [web3](https://github.com/ethereum/web3.js/#installation) installed. - Instantiating web3 + ```javascript // in browser if (window.ethereum) { @@ -20,13 +21,14 @@ if (window.ethereum) { // in node.js const web3 = new Web3(new Web3.providers.HttpProvider(ETH_NODE_URL)) ``` + ## Creating new DSA. - Index Contract is the core contract of DSA and is a factory contract to deploy new DSA for users. ### .build() - ` function build(address _owner, uint accountVersion, address _origin)` +`function build(address _owner, uint accountVersion, address _origin)` | Parameter | Type | Description| |--|--|--| @@ -56,10 +58,10 @@ new web3.eth.Contract(indexABI, indexAddress).methods ## Interacting with Your DSA. - Once DSA is created, You can interact with your DSA. +Once DSA is created, You can interact with your DSA. ### .cast() - `function cast(address[] calldata _targets, bytes[] calldata _datas, address _origin)` +`function cast(address[] calldata _targets, bytes[] calldata _datas, address _origin)` | Parameter | Type | Description| |--|--|--| @@ -67,45 +69,19 @@ new web3.eth.Contract(indexABI, indexAddress).methods | `_datas` | bytes[] | Array of connector’s function callData. | `_origin` | address | Referral Address. - **Web3 Code Snippet to interact with DSA.** -> Deposit Asset in Compound Protocol and start earning Interest. -```javascript -let DepositLogic = { // Desposit Function ABI of compound connector. - - inputs: - - [ - - { - - internalType: "address", - - name: "token", - - type: "address" - - }, - - { - - internalType: "uint256", - - name: "amt", - - type: "uint256" - - }, - - { - - internalType: "uint256", - - name: "getId", - - type: "uint256" - - }, - - { - - internalType: "uint256", - - name: "setId", - - type: "uint256" - - } - - ], - - name: "deposit", - - outputs: [ ], - - stateMutability: "payable", - - type: "function" -}; -// Address of compound Connector. +Deposit Asset in Compound Protocol and start earning Interest. + +```javascript +// compound connector desposit function interface +let depositLogic = [{inputs:[{internalType:"address",name:"token",type:"address"},{internalType:"uint256",name:"amt",type:"uint256"},{internalType:"uint256",name:"getId",type:"uint256"},{internalType:"uint256", name:"setId",type:"uint256"}],name:"deposit",outputs:[],stateMutability:"payable",type:"function"}]; + +// compound connector address let CompoundAddress = "0x547f1508a2a1ab0cb84dce4b3e09beb560bb44cb"; let DSA_Address = "YOUR_DSA_ADDRESS" // Your DSA Address. -let DSA_ABI = ["Copy and paste ABI here"] // ABI of DSA Contract. +let DSA_ABI = ["COPY_PASTE_DSA_ABI_HERE"] // ABI of DSA Contract. // You need to create callData of a specific function of connector. let depositArgs = [ @@ -115,7 +91,7 @@ let depositArgs = [ "0" // It should be zero ]; -let depositCallData = web3.eth.abi.encodeFunctionCall(DepositLogic, depositArgs); +let depositCallData = web3.eth.abi.encodeFunctionCall(depositLogic, depositArgs); // Interacting with DSA. new web3.eth.Contract(DSA_ABI, DSA_Address).methods @@ -132,6 +108,4 @@ new web3.eth.Contract(DSA_ABI, DSA_Address).methods return error; }); ``` -**Note:** We use a mock address to indicate ETH in connectors: `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE` - -To interact with other Protocols using DSA, here are the available connector[link-to-connectors.]. +**Note:** We use a mock address to indicate ETH in connectors: `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE` \ No newline at end of file