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

added checking/claiming rewards scripts #83

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
44 changes: 36 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -132,17 +133,17 @@ Using the previous example we could have two cases:
<tr><th> Commodity A | Currency B </th><th> Commodity B | Currency A </th></tr>
<tr><td>

| 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 |

</td><td>

| 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 |

</td></tr>
</table>
Expand Down Expand Up @@ -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 <PATH_TO_YOUR_PAYMENT_SIGNING_KEY>
```

To claim your rewards, run the following command:

```shell
./scripts/claim-bot-rewards.sh <PATH_TO_YOUR_PAYMENT_SIGNING_KEY> <PATH_TO_YOUR_CARDANO_NODE_SOCKET>
```

## Troubleshooting

### Provider related error messages
Expand Down
26 changes: 26 additions & 0 deletions scripts/check-bot-rewards.sh
Original file line number Diff line number Diff line change
@@ -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 ""
66 changes: 66 additions & 0 deletions scripts/claim-bot-rewards.sh
Original file line number Diff line number Diff line change
@@ -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\":[],\"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 ""
Loading