Connect swap B for A: buy A and sell B
Complete the reverse swap path, exchanging token B for token A in the market maker model. Lets connect the Swap function Swap B for A = Buy A & Sell B Step 1.
Lets connect the Swap function Swap B for A = Buy A & Sell B
Step 1:
Connect the Pool from the swap function to the Token B pool of the liquidity pool, with a RESOURCE connection.Settings:
- Type = All
Direction of Flow: from Pool in swap function to Token B Pool in the LP
Step 2:
From The Liquidity Pool, connect the Token B pool, to the New TokenA Balance Register, using a state connection. Settings:
- Formula = aI
Direction of Flow: From Token A Pool (LP) to Register (Swap Function)
Step 3:
From the Liquidity Pool, connect the Invariant K Register to the New TokenA Balance Register with a state connector. Settings:
- Formula = K
Direction of Flow: From Register (LP) to Register (Swap Function)
Step 4:
From the Liquidity Pool, use a state connection to connect the Token A Pool to the Amount Out Token A Register. Settings:
- Formula = aO
Direction of Flow: From TokenA Pool (LP) to Register (Swap Function)
Step 5:
From The Liquidity Pool, connect the Token B pool, to the Price AB Register, using a state connector. Settings:
- Formula = TokenB
Direction of Flow: From Token B Pool (LP) to Register (Swap Function)
Step 6:
From The Liquidity Pool, connect the Token A pool, to the Price AB Register, using a state connection. Settings:
- Formula = TokenA
Direction of Flow: From Token A Pool (LP) to Register (Swap Function)
NOTE: u now have all the variables you need for this register to complete its formula TokenA/TokenB
Step 7:
From The Liquidity Pool, connect the Token A pool, to the Token A Sink, using a RESOURCE connection. Settings:
- Type = Number, value 0
Direction of Flow: From Token A Pool (LP) to Sink (Swap Function)
Step 8:
From the swap function, connect the Amount Out TokenA register to the RESOURCE connection that is flowing to the Token A Sink. Settings:
- Type = Change value
- Formula = Overwrite
Direction of Flow: From Amount Out Token A Register (Swap function) to Resource connection
Great Job, now everything should be connected. Press play and see what happens.
You should see the swap trigger, triggering the source of a swap function and the assets moving to and out of the Liquidity pool, with the invariant K, returning back to the same number as when it started.