mirror of
https://github.com/FiloSpaTeam/plutus-pioneer-program.git
synced 2024-11-22 06:42:00 +01:00
removing liquidity
This commit is contained in:
parent
67f69605b7
commit
026a300bf4
1 changed files with 19 additions and 1 deletions
|
@ -50,6 +50,7 @@ main = do
|
||||||
Pools -> getPools cid
|
Pools -> getPools cid
|
||||||
Create amtA tnA amtB tnB -> createPool cid $ toCreateParams cs amtA tnA amtB tnB
|
Create amtA tnA amtB tnB -> createPool cid $ toCreateParams cs amtA tnA amtB tnB
|
||||||
Add amtA tnA amtB tnB -> addLiquidity cid $ toAddParams cs amtA tnA amtB tnB
|
Add amtA tnA amtB tnB -> addLiquidity cid $ toAddParams cs amtA tnA amtB tnB
|
||||||
|
Remove amt tnA tnB -> removeLiquidity cid $ toRemoveParams cs amt tnA tnB
|
||||||
Swap amtA tnA tnB -> swap cid $ toSwapParams cs amtA tnA tnB
|
Swap amtA tnA tnB -> swap cid $ toSwapParams cs amtA tnA tnB
|
||||||
go cid cs
|
go cid cs
|
||||||
|
|
||||||
|
@ -58,12 +59,13 @@ data Command =
|
||||||
| Pools
|
| Pools
|
||||||
| Create Integer Char Integer Char
|
| Create Integer Char Integer Char
|
||||||
| Add Integer Char Integer Char
|
| Add Integer Char Integer Char
|
||||||
|
| Remove Integer Char Char
|
||||||
| Swap Integer Char Char
|
| Swap Integer Char Char
|
||||||
deriving (Show, Read, Eq, Ord)
|
deriving (Show, Read, Eq, Ord)
|
||||||
|
|
||||||
readCommandIO :: IO Command
|
readCommandIO :: IO Command
|
||||||
readCommandIO = do
|
readCommandIO = do
|
||||||
putStrLn "Enter a command: Funds, Pools, Create amtA tnA amtB tnB, Add amtA tnA amtB tnB, Swap amtA tnA tnB"
|
putStrLn "Enter a command: Funds, Pools, Create amtA tnA amtB tnB, Add amtA tnA amtB tnB, Remove amt tnA tnB, Swap amtA tnA tnB"
|
||||||
s <- getLine
|
s <- getLine
|
||||||
maybe readCommandIO return $ readMaybe s
|
maybe readCommandIO return $ readMaybe s
|
||||||
|
|
||||||
|
@ -76,6 +78,9 @@ toCreateParams cs amtA tnA amtB tnB = US.CreateParams (toCoin cs tnA) (toCoin cs
|
||||||
toAddParams :: CurrencySymbol -> Integer -> Char -> Integer -> Char -> US.AddParams
|
toAddParams :: CurrencySymbol -> Integer -> Char -> Integer -> Char -> US.AddParams
|
||||||
toAddParams cs amtA tnA amtB tnB = US.AddParams (toCoin cs tnA) (toCoin cs tnB) (US.Amount amtA) (US.Amount amtB)
|
toAddParams cs amtA tnA amtB tnB = US.AddParams (toCoin cs tnA) (toCoin cs tnB) (US.Amount amtA) (US.Amount amtB)
|
||||||
|
|
||||||
|
toRemoveParams :: CurrencySymbol -> Integer -> Char -> Char -> US.RemoveParams
|
||||||
|
toRemoveParams cs amt tnA tnB = US.RemoveParams (toCoin cs tnA) (toCoin cs tnB) (US.Amount amt)
|
||||||
|
|
||||||
toSwapParams :: CurrencySymbol -> Integer -> Char -> Char -> US.SwapParams
|
toSwapParams :: CurrencySymbol -> Integer -> Char -> Char -> US.SwapParams
|
||||||
toSwapParams cs amtA tnA tnB = US.SwapParams (toCoin cs tnA) (toCoin cs tnB) (US.Amount amtA) (US.Amount 0)
|
toSwapParams cs amtA tnA tnB = US.SwapParams (toCoin cs tnA) (toCoin cs tnB) (US.Amount amtA) (US.Amount 0)
|
||||||
|
|
||||||
|
@ -148,6 +153,19 @@ addLiquidity cid ap = do
|
||||||
Left err' -> putStrLn $ "error: " ++ show err'
|
Left err' -> putStrLn $ "error: " ++ show err'
|
||||||
_ -> go
|
_ -> go
|
||||||
|
|
||||||
|
removeLiquidity :: UUID -> US.RemoveParams -> IO ()
|
||||||
|
removeLiquidity cid rp = do
|
||||||
|
callEndpoint cid "remove" rp
|
||||||
|
threadDelay 2_000_000
|
||||||
|
go
|
||||||
|
where
|
||||||
|
go = do
|
||||||
|
e <- getStatus cid
|
||||||
|
case e of
|
||||||
|
Right US.Removed -> putStrLn "removed"
|
||||||
|
Left err' -> putStrLn $ "error: " ++ show err'
|
||||||
|
_ -> go
|
||||||
|
|
||||||
swap :: UUID -> US.SwapParams -> IO ()
|
swap :: UUID -> US.SwapParams -> IO ()
|
||||||
swap cid sp = do
|
swap cid sp = do
|
||||||
callEndpoint cid "swap" sp
|
callEndpoint cid "swap" sp
|
||||||
|
|
Loading…
Reference in a new issue