4 - Balancer-v2
L1X-EVM is a robust and reliable system that is ready for production use in the DeFi market. Our demo highlights the practical Host and Runtime functions of the L1X L1 layer and showcases its capabilities using a complex use case, the balancer-v2 protocol.
1.1. Create an empty folder for this demonstration:
1.2. Change your current directory to the newly created folder:
2.1. Make sure you can access the
l1x-forge
tool from your command line. If you don't havel1x-forge
installed, follow the instructions in Step 2: Checking the L1X Tool before proceeding.2.2. Use the
l1x-forge
command to create a new project workspace. We'll name itl1x_demo04_balancer_v2
and use the templatel1x-balancer-v2
:2.3. After running the command, you'll receive a confirmation message indicating the successful creation of the "l1x_demo04_balancer_v2" contract:
2.4. Your workspace will now be populated with content from the template.
3.1. Introduction to Devbox Shell and Workflow Commands
If you're new to the l1x-sde template workspace, it's a good idea to familiarize yourself with the basics of the devbox shell and workflow commands. This will help you get started more smoothly. You can review the following links for an overview:
3.2. Default Commands to Begin With
To start using the workspace, there are some default commands you can use:
Activate the Shell: To access the devbox shell, simply enter the following command in your terminal:
List Default Commands: To see a list of the built-in default commands available in the devbox shell, you can use the following command:
Initialize the Workspace: To prepare your workspace for building and testing, run:
Now you have all the necessary tools and packages to work with the demo template workspace.
In this section, we'll walk you through the process of building and deploying the BalancerPool smart contracts.
4.1 For this demonstration, we'll use the super
key from the predefined wallet in l1x-conf/l1x_dev_wallets.yaml
.
This same key serves as the owner for the pool, as specified in the
l1x-eth-contracts/Balancer-v2/pkg/pool-stable/deploy/input.json
file.
4.2 Start the hardhat
local node
Open your workspace devbox shell terminal and run this command:
4.3 Compiling and Deploying the Contract for l1x-evm
To compile and deploy the contracts located at l1x-eth-contracts/Balancer-v2/pkg/pool-stable
, execute this command:
When you run this command, it will:
Generate EVM bytecode object files in the
./l1x-evm-artifacts
folder, as shown below:Automatically update the contract address registry at
l1x-conf/config-contract-address-registry.yaml
.
This updated address from the contract address registry will be used in the transaction JSON payload files located in
l1x-conf/scripts
to interact with the deployed contracts, as shown below:
That's it! You've successfully completed the steps for building and deploying the smart contracts.
In this step, we will walk you through the process of configuring local development l1x-chain network.
5.1 Choose the Chain Type: To begin, select the
"L1X_CFG_CHAIN_TYPE": "local_devnet"
option. Next, open a new terminal and activate the devbox shell:5.2 Start the Devnode Services: While in the devbox shell, run the following command:
5.3 Wait for Services to Initialize: After executing the previous command, please wait for approximately 160 seconds. During this time, the services will start up and become operational. You will also observe the L1X node beginning to produce blocks.
5.4 Verify DevNet Service Status: To ensure that everything is running smoothly, use the following command to check the service status:
5.5 Troubleshooting: Occasionally, we might encounter a problem where the
l1x-node-client
server and thecassandra
DB service do not sync properly, as indicated by the state shown in the image below.
To fix this issue and get your setup back on track, follow these simple steps:
These commands will help reset and restart the necessary components. Your setup should work smoothly after completing these steps.
6.1 Obtain the PoolID
To retrieve the PoolID from the deployed pool instance, refer to the tag key
creationCodePool.txt
in thel1x-conf/config-contract-address-registry.yaml
address registry file. In this case, use the address09796da51ef92af5ccb4965d3fe10b9cae61db0c
. And update the filel1x-conf/scripts/043-01-test-evm-pool-getpoolid.json
with noted info
In your devbox shell terminal, execute the following command:
Take note of the poolID, which is highlighted within the "data:" field. In this context, it is
0x8c9f70606ca7d0ba5639a002e1889a1c4a92bd54000000000000000000000000
.
6.2 Obtain the TokenList
Update
input.json
inl1x-eth-contracts/Balancer-v2/pkg/pool-stable/deploy/
with the PoolID you obtained.
Generate ABI encoded calldata to retrieve the tokenlist from
creationVault.txt
.
Take note of the highlighted calldata, which you can find in the "data:" field. In this case, it is
0xf94d46688c9f70606ca7d0ba5639a002e1889a1c4a92bd54000000000000000000000000
.To obtain the TokenList from the deployed vault instance, refer to the tag key
creationVault.txt
in thel1x-conf/config-contract-address-registry.yaml
address registry file. Use the address199202a07fd7bd18e6f0cf252d694ec84f37f40b
for this context, and update043-02-test-evm-pool-gettokenlist.json
inl1x-conf/scripts/
with the information you noted.
In your devbox shell terminal, run the following command:
Take note of the highlighted "data:" field, and then decode the ABI encoded raw data to get the following token address information:
ERC202: 0x25c77f9c598ecc4bc3eaeb58188c07d80605a9ea
Pool: 0x8c9f70606ca7d0ba5639a002e1889a1c4a92bd54
ERC20: 0xe088b9ad19e5766ecdab0a2e1ccdc7f061ffe155
6.3 Approving ERC20 and ERC202 Tokens for the Vault
Open
input.json
located atl1x-eth-contracts/Balancer-v2/pkg/pool-stable/deploy/
. Update the token balance to be approved for the Vault. For this demo, we'll approve a balance of One hundred million tokens.
Generate ABI encoded calldata to approve the tokens for the Vault using the following command:
Take note of the highlighted calldata and update the l1x-conf/scripts/043-03-test-evm-approve-erc20.json
and l1x-conf/scripts/043-04-test-evm-approve-erc201.json
files with the calldata and the appropriate token contract addresses.
Execute the following command:
This process approves ERC20 and ERC202 tokens for the Vault.
6.4 Initializing the Pool
To kickstart your deployed pool, follow these simple steps:
Open the
input.json
file found inl1x-eth-contracts/Balancer-v2/pkg/pool-stable/deploy/
. Update it with the information you collected during Step 6.2: Obtaining the TokenList. The image below highlights the fields that need updating:
Now, let's generate ABI encoded calldata to initialize your pool. In your devbox shell terminal, use the following command:
You'll see the generated calldata, which is highlighted in the "data:" field.
Find the
creationVault.txt
tag key in thel1x-conf/config-contract-address-registry.yaml
address registry file. Depending on your situation, choose the appropriate address. For our example, we'll assume the address is00578931a9d5b5ca359c5b9bcd0a4efb6cef1a7d
. Update the043-05-test-evm-init-pool.json
file inl1x-conf/scripts/
with this information:
Finally, to complete the initialization of your pool, run this command in your devbox shell terminal:
Now, let's join the pool using the Ava
key from the default wallet.
Open the
input.json
file inl1x-eth-contracts/Balancer-v2/pkg/pool-stable/deploy/
. Update it with thejoinPoolCall::tokenlist
information from Step 6.2: Obtaining the TokenList. Just like before, the image below shows the fields that need your attention:
To generate the ABI encoded calldata for joining the pool, run this command in your devbox shell terminal:
Make a note of the highlighted calldata, located in the "data:" field.
Find the
creationVault.txt
tag key in thel1x-conf/config-contract-address-registry.yaml
address registry file, and, based on your context, select the appropriate address. For our example, let's stick with00578931a9d5b5ca359c5b9bcd0a4efb6cef1a7d
. Update the043-05-test-evm-init-pool.json
file inl1x-conf/scripts/
with this information:
To finish the process of joining the pool, execute this command in your devbox shell terminal:
now user Ava
is part of the pool!
By following these steps, you can successfully initialise and join the deployed pool.
Last updated