diff --git a/.github/workflows/playground-check.yaml b/.github/workflows/playground-check.yaml index b61a6cb832..b19c9b6836 100644 --- a/.github/workflows/playground-check.yaml +++ b/.github/workflows/playground-check.yaml @@ -14,6 +14,9 @@ jobs: - 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 diff --git a/playground/test_playground.sh b/playground/test_playground.sh index f34ed1574b..75c39630a8 100755 --- a/playground/test_playground.sh +++ b/playground/test_playground.sh @@ -9,8 +9,9 @@ set -u HOST=localhost:8080 SELLTOKEN="0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" BUYTOKEN="0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" -RECEIVER="0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC" +RECEIVER="0x94766c15b0862Dd15F9f884D85aC1AAd34199a5f" AMOUNT="1000000000000000000" +PRIVATEKEY="0x93de76e801fcc65f0f517c3ca716bfc49a83a922ede9d770dd788e9e47d14f60" # cast wallet new # Run test flow @@ -40,9 +41,59 @@ 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, + "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 --fail-with-body -s -X 'POST' \ +orderUid=$( curl -v -X 'POST' \ "http://$HOST/api/v1/orders" \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ @@ -53,13 +104,13 @@ orderUid=$( curl --fail-with-body -s -X 'POST' \ "sellAmount": "'$sellAmount'", "buyAmount": "'$buyAmount'", "validTo": '$validTo', - "feeAmount": "0", + "feeAmount": "'$feeAmount'", "kind": "buy", "partiallyFillable": false, "sellTokenBalance": "erc20", "buyTokenBalance": "erc20", - "signingScheme": "presign", - "signature": "0x", + "signingScheme": "eip712", + "signature": "'$signature'", "from": "'$RECEIVER'", "appData": "{\"version\":\"1.3.0\",\"metadata\":{}}", "appDataHash": "0xa872cd1c41362821123e195e2dc6a3f19502a451e1fb2a1f861131526e98fdc7"