Experiment the Factory Contract.
Once you are inside the soroban-preview-8 container (by bash quickstart.sh and bash run.sh) you can start experimenting with the SoroswapFactory contract.
Remember that the Factory contract will help users to create new Pair contracts that will act as liquidity pools for every pair of (token_a, token_b) pair:
1. Open and read the contract:
Open in your favourite IDE or text editor, and check the factory folder:
In the factory/src folder you will find:
The
lib.rsfile with theSoroswapFactoryfunctionsThe
pair.rsfile that basically imports the pair contractwasmfrom thecore/pairfolderThe
event.rsfile that defines the events that will be trigeredThe
test.rsfile.
2. Compile the contract
You can compile both contracts by just calling make build from the root directory, however, we can go contract by contract:
cd factory
make build3. Read and run the tests:
make test1.- First, set your enviromental variables
Read step 1) from the previous chapter
2.- Let's create two dummy tokens:
Read step 2) from the previous chapter
3.- Build both the Pair and the Factory contract
And set the FACTORY_WASM and PAIR_WASM that will tell where to find the build wasm for each contract:
4.- Install the Pair contract WASM
The Factory contract will deploy several instances of the Pair contract (one for each pair), so it requires that the pair contract has been installed in the ledger (but not necesarilly deployed!). Then, the Factory will use the pair wasm hash of the installed contract to deploy new instances of the Pair contract.
5.- Deploy and initialize the Factory contract
6.- Create a Pair contrract using the SoroswapFactory contract.
By calling the create_pair function inside the SoroswapFactory contract, the Factory will create a new Pair contract, and it will return its contract id:
You might want to call the all_pairs_length and get_pair functions to test that they work as expected:
7.- Test the Pair contract.
Now that a new Pair contract has been deployed by the Factory contract, it should behave as seen in the previous chapter. So, once you have the Pair contract_id given in step (6) now you can test all its functions.
In order to do this, please follow steps 5-7 from the previous chapter:
If you want to continue experimenting directly with the CLI, here aresome env variable setting that might be useful <3
You can go through all this steps just by doing:
Last updated