Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playground check #3079

Merged
merged 39 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
2865046
Added new workflow file
mstrug Oct 21, 2024
3ea4444
Added querying order test script
mstrug Oct 21, 2024
1a989f2
Added submitting an order
mstrug Oct 21, 2024
7e14681
Added workflow run on pull request
mstrug Oct 22, 2024
6645221
Added signing order proposal using foundry cast
mstrug Oct 23, 2024
c8d80b4
Updated test script
mstrug Oct 24, 2024
5b71460
Fixed script to pass recovered signer validation
mstrug Oct 24, 2024
ed1544f
Test script cleanup
mstrug Oct 24, 2024
1950774
Propper handling of sellAmount
mstrug Oct 24, 2024
1a8e630
Added wrapping of ETH
mstrug Oct 25, 2024
d5e062f
Added allowances, cleanup
mstrug Oct 25, 2024
b910a21
Updated workflow file
mstrug Oct 25, 2024
7082d38
Added CI job step to free some space in runner image
mstrug Oct 25, 2024
2acd01b
Limited parallel docker compose build
mstrug Oct 25, 2024
3e14f82
Updated workflow file
mstrug Oct 25, 2024
98c05c3
Using container chain-1 cast for sending transactions
mstrug Oct 28, 2024
da918f7
Increased script timeout to 300sec
mstrug Oct 28, 2024
ff42a07
Added 2% slippage
mstrug Oct 28, 2024
3cd6c7c
Another workaround for yarn error
mstrug Oct 28, 2024
7fef055
Seepdup freeing image space
mstrug Oct 28, 2024
3a774e2
Added slippage calculation
mstrug Oct 28, 2024
0872605
Fixed cast call
mstrug Oct 28, 2024
291f4c6
Added storing of docker logs
mstrug Oct 28, 2024
e984344
Updated buyAmmount with slippage
mstrug Oct 28, 2024
9b5c6b6
Merge branch 'main' into ci/playground-check
mstrug Oct 28, 2024
7c970ce
Added run schedule and fixed typoo
mstrug Oct 28, 2024
f0b7298
Updated test script according to comments
mstrug Oct 29, 2024
34046e8
Merge branch 'main' into ci/playground-check
mstrug Oct 29, 2024
44cd21d
Added curl retries
mstrug Oct 29, 2024
8834535
Added waiting for services to be ready
mstrug Oct 29, 2024
c2a0842
Added Slack notificatino on job fail
mstrug Oct 30, 2024
a41c6a1
Added temporary step to test fail scenario
mstrug Oct 30, 2024
15edf3b
Fixed env vars
mstrug Oct 30, 2024
1ac9857
Fixed env vars #2
mstrug Oct 30, 2024
4b10329
Added more conext information to slack notification
mstrug Oct 30, 2024
6806d3d
Added option to specify Slack channel ID
mstrug Oct 30, 2024
b468e2e
Added link for artifacts download
mstrug Oct 30, 2024
5a7737e
Switched to #alerts-barn channel
mstrug Oct 30, 2024
015cb13
Removed testing of failed scenario step
mstrug Oct 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/playground-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Plauground operation check

on:
pull_request:
workflow_dispatch:

jobs:
playground-check:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install dependency
run: sudo apt-get -qq update && sudo apt-get -y -q install curl jq

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Setup environment
run: |
cp playground/.env.example playground/.env
sed -i -e 's/ETH_RPC_URL=.*/ETH_RPC_URL=$FORK_URL_MAINNET/g' playground/.env
cat playground/.env

- name: Start docker containers
run: |
cd playground
docker compose -f docker-compose.fork.yml up -d

- name: Execute validation script
run: playground/test_playground.sh
128 changes: 128 additions & 0 deletions playground/test_playground.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#!/bin/bash

# Fail on all errors
set -e
# Fail on expand of unset variables
set -u

# Setup parameters
HOST=localhost:8080
SELLTOKEN="0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
BUYTOKEN="0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"
RECEIVER="0x94766c15b0862Dd15F9f884D85aC1AAd34199a5f"
AMOUNT="1000000000000000000"
PRIVATEKEY="0x93de76e801fcc65f0f517c3ca716bfc49a83a922ede9d770dd788e9e47d14f60" # cast wallet new
mstrug marked this conversation as resolved.
Show resolved Hide resolved

# Run test flow

echo "Request price qoute for buying USDC for WETH"
quote_reponse=$( curl --fail-with-body -s -X 'POST' \
"http://$HOST/api/v1/quote" \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"sellToken": "'$SELLTOKEN'",
"buyToken": "'$BUYTOKEN'",
"from": "'$RECEIVER'",
"receiver": "'$RECEIVER'",
"sellTokenBalance": "erc20",
"buyTokenBalance": "erc20",
"priceQuality": "fast",
mstrug marked this conversation as resolved.
Show resolved Hide resolved
"signingScheme": "eip712",
"onchainOrder": false,
"partiallyFillable": false,
"kind": "sell",
"sellAmountBeforeFee": "'$AMOUNT'",
"appData": "{\"version\":\"1.3.0\",\"metadata\":{}}",
"appDataHash": "0xa872cd1c41362821123e195e2dc6a3f19502a451e1fb2a1f861131526e98fdc7"
}')
sellAmount=$(jq -r --args '.quote.sellAmount' <<< "${quote_reponse}")
buyAmount=$(jq -r --args '.quote.buyAmount' <<< "${quote_reponse}")
feeAmount=$(jq -r --args '.quote.feeAmount' <<< "${quote_reponse}")
#echo -e $sellAmount"\n"$buyAmount"\n"$feeAmount
validTo=$(($(date +%s) + 120)) # validity time: now + 2 minutes
#order="0x"$(printf '%s' "$quote_reponse" | hexdump -ve '/1 "%02X"') #"$quote_reponse #(jq -r --args '.quote' <<< "${quote_reponse}")

echo $quote_reponse

# Filter out unneeded fields
order_proposal=$(jq -r --args '.quote|=(.appData=.appDataHash) | del(.quote.appDataHash, .quote.signingScheme) | .quote' <<< "${quote_reponse}")

# Prepare EIP-712 typed struct
eip712_typed_struct='{
"types": {
"EIP712Domain": [
{ "name": "name", "type": "string" },
{ "name": "version", "type": "string" },
{ "name": "chainId", "type": "uint256" },
{ "name": "verifyingContract", "type": "address" }
],
"Order": [
{ "name": "sellToken", "type": "address" },
{ "name": "buyToken", "type": "address" },
{ "name": "receiver", "type": "address" },
{ "name": "sellAmount", "type": "uint256" },
{ "name": "buyAmount", "type": "uint256" },
{ "name": "validTo", "type": "uint32" },
{ "name": "appData", "type": "bytes32" },
{ "name": "feeAmount", "type": "uint256" },
{ "name": "kind", "type": "string" },
{ "name": "partiallyFillable", "type": "bool" },
{ "name": "sellTokenBalance", "type": "string" },
{ "name": "buyTokenBalance", "type": "string" }
]
},
"primaryType": "Order",
"domain": {
"name": "Gnosis Protocol",
"version": "v2",
"chainId": 100,
mstrug marked this conversation as resolved.
Show resolved Hide resolved
"verifyingContract": "0x9008D19f58AAbD9eD0D60971565AA8510560ab41"
},
"message": '$order_proposal'
}'

# Validate if json is well formatted and compact it
eip712_typed_struct=$(jq -r -c <<< "${eip712_typed_struct}")

# Dump to file as there are some spaces in field values
echo $eip712_typed_struct > tmp.json

# sign quote_reponse with private key
signature=$(cast wallet sign --private-key $PRIVATEKEY --data --from-file tmp.json)
echo "Intent signature:" $signature

echo "Submit an order"
orderUid=$( curl -v -X 'POST' \
"http://$HOST/api/v1/orders" \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"sellToken": "'$SELLTOKEN'",
"buyToken": "'$BUYTOKEN'",
"receiver": "'$RECEIVER'",
"sellAmount": "'$sellAmount'",
"buyAmount": "'$buyAmount'",
"validTo": '$validTo',
"feeAmount": "'$feeAmount'",
mstrug marked this conversation as resolved.
Show resolved Hide resolved
"kind": "buy",
"partiallyFillable": false,
"sellTokenBalance": "erc20",
"buyTokenBalance": "erc20",
"signingScheme": "eip712",
"signature": "'$signature'",
"from": "'$RECEIVER'",
"appData": "{\"version\":\"1.3.0\",\"metadata\":{}}",
"appDataHash": "0xa872cd1c41362821123e195e2dc6a3f19502a451e1fb2a1f861131526e98fdc7"
}')
orderUid=${orderUid:1:-1} # remove quotes
echo "Order UID: $orderUid"

for i in $(seq 1 60);
mstrug marked this conversation as resolved.
Show resolved Hide resolved
do
orderStatus=$( curl --fail-with-body -s -X 'GET' \
"http://$HOST/api/v1/orders/$orderUid/status" \
-H 'accept: application/json' | jq -r '.type')
echo "Order status: $orderStatus"
sleep 2
done
Loading