Differences

This shows you the differences between two versions of the page.

Link to this comparison view

fob:laboratoare:08 [2022/12/14 20:37]
costin.carabas
fob:laboratoare:08 [2022/12/15 18:28] (current)
costin.carabas
Line 6: Line 6:
  
 Tasks for this practical session: Tasks for this practical session:
 +  - Create tokens: First Token, Second Token, LiquidityPool Token (see previous labs)
   - Build SC (see previous labs)   - Build SC (see previous labs)
   - Deploy SC (see previous labs)   - Deploy SC (see previous labs)
-  - Create tokens: First Token, Second Token, LiquidityPool Token (see previous labs) 
   - Set Roles of deployed SC: setTransferExecGasLimit,​ setLpTokenIdentifier,​ setSpecialRoleToken   - Set Roles of deployed SC: setTransferExecGasLimit,​ setLpTokenIdentifier,​ setSpecialRoleToken
   - Add Liquidity   - Add Liquidity
Line 14: Line 14:
   - Perform Swaps: Trade token1 for token2   - Perform Swaps: Trade token1 for token2
  
-Please check [[https://​github.com/​systems-cs-pub-ro/​Foundation-Of-Blockchains/​tree/​master/​labs/​lab07/​lab07/​interaction|interaction ​folder]].+Please check [[https://​github.com/​systems-cs-pub-ro/​Foundation-Of-Blockchains/​blob/​master/​labs/​lab07/​lab07/​interaction/​testnet.snippets.sh|interaction ​script]].
 You can use this file by sourcing it: You can use this file by sourcing it:
 <​code>​ <​code>​
Line 53: Line 53:
  
 When deployed, the Pair SC is in **ActiveNoSwaps** state. Check [[https://​github.com/​systems-cs-pub-ro/​Foundation-Of-Blockchains/​blob/​5634f03ce56ba191a0e6685f6b5e675f02c9431f/​labs/​lab07/​lab07/​src/​lib.rs#​L73|this code]]. You will have to call [[https://​github.com/​systems-cs-pub-ro/​Foundation-Of-Blockchains/​blob/​5634f03ce56ba191a0e6685f6b5e675f02c9431f/​labs/​lab07/​lab07/​src/​config.rs#​L43|resume]] endpoint to change to state to **Active** so that swaps may be performed. When deployed, the Pair SC is in **ActiveNoSwaps** state. Check [[https://​github.com/​systems-cs-pub-ro/​Foundation-Of-Blockchains/​blob/​5634f03ce56ba191a0e6685f6b5e675f02c9431f/​labs/​lab07/​lab07/​src/​lib.rs#​L73|this code]]. You will have to call [[https://​github.com/​systems-cs-pub-ro/​Foundation-Of-Blockchains/​blob/​5634f03ce56ba191a0e6685f6b5e675f02c9431f/​labs/​lab07/​lab07/​src/​config.rs#​L43|resume]] endpoint to change to state to **Active** so that swaps may be performed.
 +
 +=== Add and Remove Liquidity ===
 +
 +<note warning>​To add liquidity to the Pair SC you have to send two tokens. Please use [[https://​docs.elrond.com/​sdk-and-tools/​erdpy/​smart-contract-interactions/#​multi-esdt-transfer|Multi ESDT Transfer]] documentation.</​note>​
 +
 +Now that the Pair SC is configured, you can call [[https://​github.com/​systems-cs-pub-ro/​Foundation-Of-Blockchains/​blob/​5634f03ce56ba191a0e6685f6b5e675f02c9431f/​labs/​lab07/​lab07/​src/​lib.rs#​L88|addLiquidity]] and [[https://​github.com/​systems-cs-pub-ro/​Foundation-Of-Blockchains/​blob/​5634f03ce56ba191a0e6685f6b5e675f02c9431f/​labs/​lab07/​lab07/​src/​lib.rs#​L190|removeLiquidity]].
 +<note important>​Check the transactions. What tokens were sent/​received?</​note>​
 +
 +The transactions should follow the order:
 +<​code>​
 +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
 +</​code>​
 +
 +=== Swaps ===
 +
 +Now with the SC configured and having liquidity, you can perform swaps using [[https://​github.com/​systems-cs-pub-ro/​Foundation-Of-Blockchains/​blob/​5634f03ce56ba191a0e6685f6b5e675f02c9431f/​labs/​lab07/​lab07/​src/​lib.rs#​L351|swap_tokens_fixed_input]] and [[https://​github.com/​systems-cs-pub-ro/​Foundation-Of-Blockchains/​blob/​5634f03ce56ba191a0e6685f6b5e675f02c9431f/​labs/​lab07/​lab07/​src/​lib.rs#​L438|swap_tokens_fixed_output]]. Remember the difference from last lab?
 +<note important>​What happens with the ratio Token1/​Token2?</​note>​
 +
 +=== Bonus ===
 +
 +This Pair SC has a vulnerability. Can you find it?
fob/laboratoare/08.1671043025.txt.gz · Last modified: 2022/12/14 20:37 by costin.carabas
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0