Skip to content

Instantly share code, notes, and snippets.

@cdm
Created May 25, 2022 11:03
Show Gist options
  • Save cdm/8e474272ddd765d03c0311d10c85ae08 to your computer and use it in GitHub Desktop.
Save cdm/8e474272ddd765d03c0311d10c85ae08 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
import os
import requests
# ACCOUNT TYPES (DO NOT EDIT)
account_type_taker_fees = "ACCOUNT_TYPE_REWARD_TAKER_PAID_FEES" # Per asset reward account for fees paid by takers
account_type_maker_fees = "ACCOUNT_TYPE_REWARD_MAKER_RECEIVED_FEES" # Per asset reward account for fees received by makers
account_type_lp_fees = "ACCOUNT_TYPE_REWARD_LP_RECEIVED_FEES" # Per asset reward account for fees received by liquidity providers
account_type_market_proposers = "ACCOUNT_TYPE_REWARD_MARKET_PROPOSERS" # Per asset reward account for market proposers when the market goes above a trading threshold
# DISPATCH METRIC TYPES (DO NOT EDIT)
dispatch_type_taker_fees = "DISPATCH_METRIC_TAKER_FEES_PAID" # Dispatch metric that is using the total taker fees paid in the market
dispatch_type_maker_fees = "DISPATCH_METRIC_MAKER_FEES_RECEIVED" # Dispatch metric that is using the total maker fees received in the market
dispatch_type_lp_fees = "DISPATCH_METRIC_LP_FEES_RECEIVED" # Dispatch metric that is using the total LP fees received in the market
dispatch_type_market_value = "DISPATCH_METRIC_MARKET_VALUE" # Dispatch metric that is using total value of the market if above the required threshold and not paid given proposer bonus yet
# EDIT YOUR REWARD VALUES BELOW
target_market_ids = ["YOUR_MARKET_ID"]
reward_asset_id = "YOUR_REWARD_ASSET_ID"
settlement_asset_id = "YOUR_SETTLEMENT_ASSET_ID"
reward_account_type = account_type_maker_fees
dispatch_metric_type = dispatch_type_maker_fees
transfer_amount = 100 # 100000000000000000000 (equivalent note dp conversion is automatic below)
transfer_asset_dp = 18 # Note: 18dp for ethereum assets
transfer_dp_converted_amount = str(int(transfer_amount*10**transfer_asset_dp))
starting_epoch_for_rewards = "" # Note: set this to a numeric value if you do not want to use the current epoch
scale_factor = "1" # Note: leave at value 1 for linear recurring transfer
# END REWARD VALUES
node_url_rest = os.getenv("NODE_URL_REST")
wallet_server_url = os.getenv("WALLETSERVER_URL")
wallet_name = os.getenv("WALLET_NAME")
wallet_passphrase = os.getenv("WALLET_PASSPHRASE")
"""
Transfer to reward pool from connected wallet for given asset / market(s)
"""
print(f"Logging into wallet: {wallet_name}")
# Log in to an existing wallet
req = {"wallet": wallet_name, "passphrase": wallet_passphrase}
response = requests.post(f"{wallet_server_url}/api/v1/auth/token", json=req)
token = response.json()["token"]
assert token != ""
print("Logged in to wallet successfully")
# List key pairs and select public key to use
headers = {"Authorization": f"Bearer {token}"}
response = requests.get(f"{wallet_server_url}/api/v1/keys", headers=headers)
keys = response.json()["keys"]
pubkey = keys[0]["pub"]
assert pubkey != ""
print(f"Selected pubkey: {pubkey}")
print()
if starting_epoch_for_rewards != "":
print(f"Retrieving current epoch")
print()
# Request the latest epoch data from data node API
url = f"{node_url_rest}/epochs"
response = requests.get(url)
# The "seq" field contains the current epoch sequence number
current_epoch = response.json()["epoch"]["seq"]
print(f"Current epoch: {current_epoch}")
starting_epoch_for_rewards = current_epoch
# Build and send the transfer request...
print(f"Topping up reward pool for {settlement_asset_id} in {reward_asset_id}")
print()
transfer = {
"transfer":{
"amount": transfer_dp_converted_amount,
"asset": reward_asset_id,
"fromAccountType": "ACCOUNT_TYPE_GENERAL",
"toAccountType": reward_account_type,
"to":"0000000000000000000000000000000000000000000000000000000000000000",
"recurring":{
"dispatchStrategy":{
"assetForMetric": settlement_asset_id,
"metric": dispatch_metric_type,
"markets": target_market_ids
},
"startEpoch": starting_epoch_for_rewards,
"factor": scale_factor
}
},
"pubKey": pubkey,
"propagate": True
}
print(transfer)
url = f"{wallet_server_url}/api/v1/command/sync"
response = requests.post(url, headers=headers, json=transfer)
print("Signed transfer command and sent to Vega")
print(response.json())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment