In this lab you will learn how to setup a Liquidity Pool. The original Elrond's Pair SC will not be used, but we will use a simplified version.
Please clone the git repo from here.
Tasks for this practical session:
Please check interaction script. You can use this file by sourcing it:
costin@Byblos:~/facultate/cursuri/fob/Foundation-Of-Blockchains/labs/lab07/lab07/interaction$ . testnet.snippets.sh costin@Byblos:~/facultate/cursuri/fob/Foundation-Of-Blockchains/labs/lab07/lab07/interaction$ issueToken FobToken FOB INFO:accounts:Account.sync_nonce() INFO:accounts:Account.sync_nonce() done: 59 INFO:transactions:Transaction.send: nonce=59 INFO:transactions:Hash: 0a735360d68047ace30a26e64c7b0e67b654d227400b3929332efa05a52db344 INFO:utils:View this transaction in the Elrond Testnet Explorer: https://testnet-explorer.elrond.com/transactions/0a735360d68047ace30a26e64c7b0e67b654d227400b3929332efa05a52db344 { "emittedTransaction": { "nonce": 59, "value": "50000000000000000", "receiver": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u", "sender": "erd1ld6er5zpdze3cynzkapur9qhzh826jje6n87g7tvdfrtszs8jn2qv44nqd", "gasPrice": 1000000000, "gasLimit": 60000000, "data": "aXNzdWVANDY2RjYyNTQ2RjZCNjU2RUA0NjRGNDJARkZGRkZGRkZGRkZGRkZGRkZGRkZAMTI=", "chainID": "T", "version": 1, "signature": "c30f1b3bf9edf0e4dea32ca89ba950165bb2d027797bfaf4d2629b6bec341464c7bd4cd93174fc440857b067871fffedb610272afb9013190dc1a5a03d65d709" }, "emittedTransactionData": "issue@466F62546F6B656E@464F42@FFFFFFFFFFFFFFFFFFFF@12", "emittedTransactionHash": "0a735360d68047ace30a26e64c7b0e67b654d227400b3929332efa05a52db344", "contractAddress": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u" }
Use set_transfer_exec_gas_limit function to set the gas limit for transfer. This will set the transfer_exec_gas_limit variable from storage and will be further used by the contract.
Use setLpTokenIdentifier endpoint to set the LP Token for the Pair SC. This token will be used when users add and remove liquidity. For X Token1 and X Token2, the users will receive Y LP Token as proof that they provided liquidity. The user will use the LP Token to remove liquidity and get the tokens back.
Use setSpecialRole to provide the Pair SC setSpecialRoleToken role so that it can create LP Tokens.
When deployed, the Pair SC is in ActiveNoSwaps state. Check this code. You will have to call resume endpoint to change to state to Active so that swaps may be performed.
Now that the Pair SC is configured, you can call addLiquidity and removeLiquidity.
The transactions should follow the order:
MultiESDTNFTTransfer@Contract_address_in_hex@02@Token1Identifier_in_hex@Token1Nonce_in_hex@Token1Value_in_hex@Token2Identifier_in_hex@Token2Nonce_in_hex@Token2Value_in_hex@myEndpoint_in_hex@parameters
Now with the SC configured and having liquidity, you can perform swaps using swap_tokens_fixed_input and swap_tokens_fixed_output. Remember the difference from last lab?
This Pair SC has a vulnerability. Can you find it?