From b8cd259a4130606b7a7695fc23dbb0a727ed96f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Br=C3=BCnjes?= Date: Mon, 5 Feb 2024 22:08:50 +0100 Subject: [PATCH 1/2] added checking/claiming rewards scripts --- README.md | 44 +++++++++++++++++++----- scripts/check-bot-rewards.sh | 26 ++++++++++++++ scripts/claim-bot-rewards.sh | 66 ++++++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+), 8 deletions(-) create mode 100755 scripts/check-bot-rewards.sh create mode 100755 scripts/claim-bot-rewards.sh diff --git a/README.md b/README.md index 56b8f13..005dcaa 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ - 🎓 [Crash Course](#crash-course-geniusyield-dex-orders-and-the-smart-order-routers) - 🚀 [Building and running](#building-and-running-the-smart-order-router) - 🧠 [Strategies](#strategies) +- 💰 [Yield Accelerator Rewards](#yield-accelerator-rewards) - 🛠️ [Troubleshooting](#troubleshooting) - ⚖️ [License](#license) @@ -132,17 +133,17 @@ Using the previous example we could have two cases: Commodity A | Currency B Commodity B | Currency A -| Amount | Price | Type | -|:-----------:|:-------------:|:------:| -| `10 GENS` | `2 ADA` | Sell | -| `8 GENS` | `2.5 ADA` | Buy | +| Amount | Price | Type | +| :-------: | :-------: | :---: | +| `10 GENS` | `2 ADA` | Sell | +| `8 GENS` | `2.5 ADA` | Buy | -| Amount | Price | Type | -|:-----------:|:--------------:|:------:| -| `20 ADA` | `0.4 GENS` | Sell | -| `20 ADA` | `0.5 GENS` | Buy | +| Amount | Price | Type | +| :------: | :--------: | :---: | +| `20 ADA` | `0.4 GENS` | Sell | +| `20 ADA` | `0.5 GENS` | Buy | @@ -571,6 +572,33 @@ Questions: Choosing between one strategy or the other will always enforce some m will it be possible to merge the two strategies into a single one? Or it will be better to run two different SOR instances? +## Yield Accelerator Rewards + +SOR's fill orders and therefore participate in the GeniusYield Yield Accelerator Program and accumulate rewards. + +Traders wishing to check and claim their rewards can easily do so in the [GeniusYield UI](https://app.geniusyield.co/earn), +but unfortunately, at the moment, the UI only works for users who connect their wallets to the UI and are identified by +the wallet stake key hash. + +An SOR, on the other hand, normally just uses a simple payment signing key and an associated address without staking component. + +To allow SOR operators to check and claim rewards, we are providing two simple bash scripts, +one for [checking](./scripts/check-bot-rewards.sh) and one for [claiming](./scripts/claim-bot-rewards.sh) rewards. +Both scripts require the `cardano-cli` to be installed and available in the `PATH`, and in order to claim, +you additionally need a connection to a running Cardano node. + +To check your rewards, run the following command: + +```shell +./scripts/check-bot-rewards.sh +``` + +To claim your rewards, run the following command: + +```shell +./scripts/claim-bot-rewards.sh +``` + ## Troubleshooting ### Provider related error messages diff --git a/scripts/check-bot-rewards.sh b/scripts/check-bot-rewards.sh new file mode 100755 index 0000000..d4c79bd --- /dev/null +++ b/scripts/check-bot-rewards.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +echo "bot payment signing key file: $1" + +VKEY_TMP_FILE=$(mktemp) +cardano-cli key verification-key --signing-key-file "$1" --verification-key-file "$VKEY_TMP_FILE" + +PKH_TMP_FILE=$(mktemp) +cardano-cli address key-hash --payment-verification-key-file "$VKEY_TMP_FILE" --out-file "$PKH_TMP_FILE" +PKH=$(cat "$PKH_TMP_FILE") +echo "bot pubkey hash: $PKH" + +rm "$VKEY_TMP_FILE" +rm "$PKH_TMP_FILE" + +curl 'https://api.geniusyield.co/user/connect' \ + -H 'content-type: application/json' \ + --data-raw "{\"walletStakeKeyHash\":\"$PKH\",\"userType\":\"INDIVIDUAL\"}" \ + --compressed > /dev/null 2>&1 + +curl 'https://api.geniusyield.co/yield-farming/rewards' \ + -H "authorization: WalletStakeKeyHash $PKH" \ + -H 'content-type: application/json' \ + --compressed + +echo "" diff --git a/scripts/claim-bot-rewards.sh b/scripts/claim-bot-rewards.sh new file mode 100755 index 0000000..5bbccab --- /dev/null +++ b/scripts/claim-bot-rewards.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +echo "node socket path: $2" +echo "bot payment signing key file: $1" + +VKEY_TMP_FILE=$(mktemp) +cardano-cli key verification-key --signing-key-file "$1" --verification-key-file "$VKEY_TMP_FILE" + +PKH_TMP_FILE=$(mktemp) +cardano-cli address key-hash --payment-verification-key-file "$VKEY_TMP_FILE" --out-file "$PKH_TMP_FILE" +PKH=$(cat "$PKH_TMP_FILE") +echo "bot pubkey hash: $PKH" + +ADDR_TMP_FILE=$(mktemp) +cardano-cli address build --mainnet --payment-verification-key-file "$VKEY_TMP_FILE" --out-file "$ADDR_TMP_FILE" +ADDR=$(cat "$ADDR_TMP_FILE") +echo "bot address (Bech32): $ADDR" + +CBOR=$(cardano-cli address info --address "$ADDR" | jq .base16) +echo "bot address (CBOR): $CBOR" + +rm "$VKEY_TMP_FILE" +rm "$PKH_TMP_FILE" +rm "$ADDR_TMP_FILE" + +curl 'https://api.geniusyield.co/user/connect' \ + -H 'content-type: application/json' \ + --data-raw "{\"walletStakeKeyHash\":\"$PKH\",\"userType\":\"INDIVIDUAL\"}" \ + --compressed > /dev/null 2>&1 + +DATA="{\"walletAddress\":$CBOR,\"walletRewardAddresses\":[\"e1$PKH\"],\"walletStakeKeyHash\":\"$PKH\",\"collateralUtxo\":[\"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"],\"walletUnusedAddresses\":[$CBOR],\"walletUsedAddresses\":[$CBOR]}" + +PAYLOAD=$(curl -s 'https://api.geniusyield.co/yield-farming/rewards/claim' \ + -H "authorization: WalletStakeKeyHash $PKH" \ + -H 'content-type: application/json' \ + --data-raw "$DATA" \ + --compressed | jq .transactionPayload) + +echo "" +echo "tx payload: $PAYLOAD" +echo "" + +TX=$(cat << EOF +{ + "type": "Witnessed Tx BabbageEra", + "description": "Ledger Cddl Format", + "cborHex": $PAYLOAD +} +EOF +) + +TX_TMP_FILE=$(mktemp) +echo "$TX" > $TX_TMP_FILE + +cardano-cli transaction sign --mainnet --tx-file "$TX_TMP_FILE" --signing-key-file "$1" --out-file "$TX_TMP_FILE" +cardano-cli transaction view --tx-file "$TX_TMP_FILE" +echo "" + +TID=$(cardano-cli transaction txid --tx-file "$TX_TMP_FILE") + +cardano-cli transaction submit --socket-path "$2" --mainnet --tx-file "$TX_TMP_FILE" + +rm $TX_TMP_FILE + +echo "tx-id: $TID" +echo "" From e1811d9576daf380e9b84b35691cf7536ba5c189 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Br=C3=BCnjes?= Date: Tue, 6 Feb 2024 07:15:55 +0100 Subject: [PATCH 2/2] Update scripts/claim-bot-rewards.sh Co-authored-by: Sourabh --- scripts/claim-bot-rewards.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/claim-bot-rewards.sh b/scripts/claim-bot-rewards.sh index 5bbccab..fc93845 100755 --- a/scripts/claim-bot-rewards.sh +++ b/scripts/claim-bot-rewards.sh @@ -28,7 +28,7 @@ curl 'https://api.geniusyield.co/user/connect' \ --data-raw "{\"walletStakeKeyHash\":\"$PKH\",\"userType\":\"INDIVIDUAL\"}" \ --compressed > /dev/null 2>&1 -DATA="{\"walletAddress\":$CBOR,\"walletRewardAddresses\":[\"e1$PKH\"],\"walletStakeKeyHash\":\"$PKH\",\"collateralUtxo\":[\"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"],\"walletUnusedAddresses\":[$CBOR],\"walletUsedAddresses\":[$CBOR]}" +DATA="{\"walletAddress\":$CBOR,\"walletRewardAddresses\":[\"e1$PKH\"],\"walletStakeKeyHash\":\"$PKH\",\"collateralUtxo\":[\"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"],\"walletUnusedAddresses\":[],\"walletUsedAddresses\":[$CBOR]}" PAYLOAD=$(curl -s 'https://api.geniusyield.co/yield-farming/rewards/claim' \ -H "authorization: WalletStakeKeyHash $PKH" \