diff --git a/code/week10/add.sh b/code/week10/add.sh new file mode 100755 index 0000000..f178052 --- /dev/null +++ b/code/week10/add.sh @@ -0,0 +1,9 @@ +#1/bin/sh + +symbol=$( cat symbol.json ) +body="{\"apAmountA\":$2,\"apAmountB\":$4,\"apCoinB\":{\"unAssetClass\":[$symbol,{\"unTokenName\":\"$5\"}]},\"apCoinA\":{\"unAssetClass\":[$symbol,{\"unTokenName\":\"$3\"}]}}" +echo $body + +curl "http://localhost:8080/api/new/contract/instance/$(cat W$1.cid)/endpoint/add" \ +--header 'Content-Type: application/json' \ +--data-raw $body diff --git a/code/week10/app/uniswap-client.hs b/code/week10/app/uniswap-client.hs index 9833f1c..478d4be 100644 --- a/code/week10/app/uniswap-client.hs +++ b/code/week10/app/uniswap-client.hs @@ -10,7 +10,8 @@ import Control.Concurrent import Control.Exception import Control.Monad (forM_, when) import Control.Monad.IO.Class (MonadIO (..)) -import Data.Aeson (Result (..), ToJSON, decode, fromJSON) +import Data.Aeson (Result (..), ToJSON, decode, encode, fromJSON) +import qualified Data.ByteString.Lazy.Char8 as B8 import qualified Data.ByteString.Lazy as LB import Data.Monoid (Last (..)) import Data.Proxy (Proxy (..)) @@ -212,6 +213,8 @@ getStatus cid = runReq defaultHttpConfig $ do callEndpoint :: ToJSON a => UUID -> String -> a -> IO () callEndpoint cid name a = handle h $ runReq defaultHttpConfig $ do + liftIO $ printf "\npost request to 127.0.1:8080/api/new/contract/instance/%s/endpoint/%s\n" (show cid) name + liftIO $ printf "request body: %s\n\n" $ B8.unpack $ encode a v <- req POST (http "127.0.0.1" /: "api" /: "new" /: "contract" /: "instance" /: pack (show cid) /: "endpoint" /: pack name) diff --git a/code/week10/close.sh b/code/week10/close.sh new file mode 100755 index 0000000..00666e8 --- /dev/null +++ b/code/week10/close.sh @@ -0,0 +1,9 @@ +#1/bin/sh + +symbol=$( cat symbol.json ) +body="{\"clpCoinB\":{\"unAssetClass\":[$symbol,{\"unTokenName\":\"$3\"}]},\"clpCoinA\":{\"unAssetClass\":[$symbol,{\"unTokenName\":\"$2\"}]}}" +echo $body + +curl "http://localhost:8080/api/new/contract/instance/$(cat W$1.cid)/endpoint/close" \ +--header 'Content-Type: application/json' \ +--data-raw $body diff --git a/code/week10/create.sh b/code/week10/create.sh new file mode 100755 index 0000000..ef6c026 --- /dev/null +++ b/code/week10/create.sh @@ -0,0 +1,9 @@ +#1/bin/sh + +symbol=$( cat symbol.json ) +body="{\"cpAmountA\":$2,\"cpAmountB\":$4,\"cpCoinB\":{\"unAssetClass\":[$symbol,{\"unTokenName\":\"$5\"}]},\"cpCoinA\":{\"unAssetClass\":[$symbol,{\"unTokenName\":\"$3\"}]}}" +echo $body + +curl "http://localhost:8080/api/new/contract/instance/$(cat W$1.cid)/endpoint/create" \ +--header 'Content-Type: application/json' \ +--data-raw $body diff --git a/code/week10/funds.sh b/code/week10/funds.sh new file mode 100755 index 0000000..5edd5b1 --- /dev/null +++ b/code/week10/funds.sh @@ -0,0 +1,4 @@ +#1/bin/sh +curl "http://localhost:8080/api/new/contract/instance/$(cat W$1.cid)/endpoint/funds" \ +--header 'Content-Type: application/json' \ +--data-raw '[]' diff --git a/code/week10/logs.sh b/code/week10/logs.sh new file mode 100755 index 0000000..1bbeb4f --- /dev/null +++ b/code/week10/logs.sh @@ -0,0 +1,2 @@ +#1/bin/sh +curl "http://localhost:8080/api/new/contract/instance/$(cat W$1.cid)/status" | jq ".cicCurrentState.logs" diff --git a/code/week10/pools.sh b/code/week10/pools.sh new file mode 100755 index 0000000..00401b6 --- /dev/null +++ b/code/week10/pools.sh @@ -0,0 +1,4 @@ +#1/bin/sh +curl "http://localhost:8080/api/new/contract/instance/$(cat W$1.cid)/endpoint/pools" \ +--header 'Content-Type: application/json' \ +--data-raw '[]' diff --git a/code/week10/remove.sh b/code/week10/remove.sh new file mode 100755 index 0000000..4e130a5 --- /dev/null +++ b/code/week10/remove.sh @@ -0,0 +1,9 @@ +#1/bin/sh + +symbol=$( cat symbol.json ) +body="{\"rpCoinB\":{\"unAssetClass\":[$symbol,{\"unTokenName\":\"$4\"}]},\"rpDiff\":$2,\"rpCoinA\":{\"unAssetClass\":[$symbol,{\"unTokenName\":\"$3\"}]}}" +echo $body + +curl "http://localhost:8080/api/new/contract/instance/$(cat W$1.cid)/endpoint/remove" \ +--header 'Content-Type: application/json' \ +--data-raw $body diff --git a/code/week10/status.sh b/code/week10/status.sh new file mode 100755 index 0000000..3cef099 --- /dev/null +++ b/code/week10/status.sh @@ -0,0 +1,2 @@ +#1/bin/sh +curl "http://localhost:8080/api/new/contract/instance/$(cat W$1.cid)/status" | jq ".cicCurrentState.observableState" diff --git a/code/week10/swap.sh b/code/week10/swap.sh new file mode 100755 index 0000000..b6c229e --- /dev/null +++ b/code/week10/swap.sh @@ -0,0 +1,9 @@ +#1/bin/sh + +symbol=$( cat symbol.json ) +body="{\"spAmountA\":$2,\"spAmountB\":0,\"spCoinB\":{\"unAssetClass\":[$symbol,{\"unTokenName\":\"$4\"}]},\"spCoinA\":{\"unAssetClass\":[$symbol,{\"unTokenName\":\"$3\"}]}}" +echo $body + +curl "http://localhost:8080/api/new/contract/instance/$(cat W$1.cid)/endpoint/swap" \ +--header 'Content-Type: application/json' \ +--data-raw $body