mirror of
https://github.com/Instadapp/dsa-developers.git
synced 2024-07-29 21:56:57 +00:00
edits
This commit is contained in:
parent
bc83ebb6ab
commit
ab8903ee79
|
@ -1,7 +1,9 @@
|
||||||
# Fork-Ethereum-Mainnet
|
# Fork-Ethereum-Mainnet
|
||||||
|
|
||||||
Interact with InstaDApp DSA using Forked Mainnet from your local network
|
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.
|
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.
|
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
|
**Step 1:** Forking the Ethereum Mainnet
|
||||||
|
@ -11,6 +13,7 @@ Open terminal and run
|
||||||
```javascript
|
```javascript
|
||||||
ganache-cli --fork https://mainnet.infura.io/v3/{Project_Id} --unlock {Ethereum_Address} -p {Port_Number} --networkId 1
|
ganache-cli --fork https://mainnet.infura.io/v3/{Project_Id} --unlock {Ethereum_Address} -p {Port_Number} --networkId 1
|
||||||
```
|
```
|
||||||
|
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Parameters</th>
|
<th>Parameters</th>
|
||||||
|
@ -33,10 +36,8 @@ ganache-cli --fork https://mainnet.infura.io/v3/{Project_Id} --unlock {Ethereum_
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|
||||||
![alt text](https://github.com/InstaDApp/dsa-developers/blob/master/img/forkMainnet/infura.png)
|
![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
|
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
|
```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.
|
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.
|
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)
|
![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.
|
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)
|
![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.
|
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)
|
![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:
|
After making all the changes in the file execute the file using command:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
node dsa.js
|
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.
|
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
|
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:
|
To check the transaction receipt you can follow these steps:
|
||||||
|
|
||||||
|
|
||||||
Step 1: Open another terminal tab
|
Step 1: Open another terminal tab
|
||||||
|
|
||||||
Step 2: run
|
Step 2 (make sure you have truffle installed on your machine): run:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
truffle console
|
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
|
```javascript
|
||||||
receipt = await web3.eth.getTransactionReceipt({txHash})
|
receipt = await web3.eth.getTransactionReceipt({txHash})
|
||||||
```
|
```
|
||||||
|
|
||||||
![alt text](https://github.com/InstaDApp/dsa-developers/blob/master/img/forkMainnet/txHash.png)
|
![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.
|
This will return you something like this, if your transaction went through.
|
||||||
|
|
||||||
# Additional advice
|
# 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.
|
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)
|
![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.
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
# Using Tenderly to simulate a transaction
|
# 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.
|
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.
|
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)
|
![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.
|
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.
|
|
@ -7,6 +7,7 @@ DeFi Smart Accounts (DSA) are contract accounts **trustlessly owned by the user
|
||||||
## Prerequisite
|
## Prerequisite
|
||||||
- [web3](https://github.com/ethereum/web3.js/#installation) installed.
|
- [web3](https://github.com/ethereum/web3.js/#installation) installed.
|
||||||
- Instantiating web3
|
- Instantiating web3
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// in browser
|
// in browser
|
||||||
if (window.ethereum) {
|
if (window.ethereum) {
|
||||||
|
@ -20,13 +21,14 @@ if (window.ethereum) {
|
||||||
// in node.js
|
// in node.js
|
||||||
const web3 = new Web3(new Web3.providers.HttpProvider(ETH_NODE_URL))
|
const web3 = new Web3(new Web3.providers.HttpProvider(ETH_NODE_URL))
|
||||||
```
|
```
|
||||||
|
|
||||||
## Creating new DSA.
|
## Creating new DSA.
|
||||||
|
|
||||||
- Index Contract is the core contract of DSA and is a factory contract to deploy new DSA for users.
|
- Index Contract is the core contract of DSA and is a factory contract to deploy new DSA for users.
|
||||||
|
|
||||||
### .build()
|
### .build()
|
||||||
|
|
||||||
` function build(address _owner, uint accountVersion, address _origin)`
|
`function build(address _owner, uint accountVersion, address _origin)`
|
||||||
|
|
||||||
| Parameter | Type | Description|
|
| Parameter | Type | Description|
|
||||||
|--|--|--|
|
|--|--|--|
|
||||||
|
@ -56,10 +58,10 @@ new web3.eth.Contract(indexABI, indexAddress).methods
|
||||||
|
|
||||||
## Interacting with Your DSA.
|
## 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()
|
### .cast()
|
||||||
`function cast(address[] calldata _targets, bytes[] calldata _datas, address _origin)`
|
`function cast(address[] calldata _targets, bytes[] calldata _datas, address _origin)`
|
||||||
|
|
||||||
| Parameter | Type | Description|
|
| Parameter | Type | Description|
|
||||||
|--|--|--|
|
|--|--|--|
|
||||||
|
@ -67,45 +69,19 @@ new web3.eth.Contract(indexABI, indexAddress).methods
|
||||||
| `_datas` | bytes[] | Array of connector’s function callData.
|
| `_datas` | bytes[] | Array of connector’s function callData.
|
||||||
| `_origin` | address | Referral Address.
|
| `_origin` | address | Referral Address.
|
||||||
|
|
||||||
|
|
||||||
**Web3 Code Snippet to interact with DSA.**
|
**Web3 Code Snippet to interact with DSA.**
|
||||||
|
|
||||||
> Deposit Asset in Compound Protocol and start earning Interest.
|
Deposit Asset in Compound Protocol and start earning Interest.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
let DepositLogic = { // Desposit Function ABI of compound connector.
|
// compound connector desposit function interface
|
||||||
- inputs:
|
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
|
||||||
- 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.
|
|
||||||
let CompoundAddress = "0x547f1508a2a1ab0cb84dce4b3e09beb560bb44cb";
|
let CompoundAddress = "0x547f1508a2a1ab0cb84dce4b3e09beb560bb44cb";
|
||||||
|
|
||||||
let DSA_Address = "YOUR_DSA_ADDRESS" // Your DSA Address.
|
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.
|
// You need to create callData of a specific function of connector.
|
||||||
let depositArgs = [
|
let depositArgs = [
|
||||||
|
@ -115,7 +91,7 @@ let depositArgs = [
|
||||||
"0" // It should be zero
|
"0" // It should be zero
|
||||||
];
|
];
|
||||||
|
|
||||||
let depositCallData = web3.eth.abi.encodeFunctionCall(DepositLogic, depositArgs);
|
let depositCallData = web3.eth.abi.encodeFunctionCall(depositLogic, depositArgs);
|
||||||
|
|
||||||
// Interacting with DSA.
|
// Interacting with DSA.
|
||||||
new web3.eth.Contract(DSA_ABI, DSA_Address).methods
|
new web3.eth.Contract(DSA_ABI, DSA_Address).methods
|
||||||
|
@ -133,5 +109,3 @@ new web3.eth.Contract(DSA_ABI, DSA_Address).methods
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
**Note:** We use a mock address to indicate ETH in connectors: `0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE`
|
**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.].
|
|
Loading…
Reference in New Issue
Block a user