Claim LP Rewards
Example of code that claim liquidity provider rewards from Aquarius pool
Last updated
Example of code that claim liquidity provider rewards from Aquarius pool
Last updated
In this section, we demonstrate how to claim accrued rewards from a specific Aquarius AMM pool. For this example, we will use this this XLM-AQUA pool.
To claim your rewards, you need to make a deposit in the pool where the rewards are distributed. Rewards are accrued every second.
Scroll here to see the complete code.
Specify user secret key and pool address: To claim from a pool, you need your user secret key and the pool address from which you want to claim the rewards.
# Distributor's secret key (ensure this is kept secure)
user_secret_key = "S..."
# XLM/AQUA pool address
pool_address = "CCY2PXGMKNQHO7WNYXEWX76L2C5BH3JUW3RCATGUYKY7QQTRILBZIFWV"
Make a contract call to the pool's "claim" method.
def execute_claim():
# Initialize Soroban and Horizon servers
server = SorobanServer(SOROBAN_SERVER_RPC)
horizon_server = Server(HORIZON_SERVER)
# Load distributor's keypair using the secret key
keypair = Keypair.from_secret(user_secret_key)
# Load the distributor's account information from Soroban server
account = server.load_account(keypair.public_key)
# Build the claim transaction
tx_builder = TransactionBuilder(
source_account=account,
network_passphrase=NETWORK_PASSPHRASE,
base_fee=1000000 # Set base fee; adjust as necessary
).set_timeout(3600) # Set transaction timeout
# Append the invoke_contract_function operation for claim
tx = tx_builder.append_invoke_contract_function_op(
contract_id=pool_address,
function_name="claim",
parameters=[
Address(keypair.public_key).to_xdr_sc_val(), # Distributor's address
],
)
tx = server.prepare_transaction(tx.build())
tx.sign(keypair)
tx_response = horizon_server.submit_transaction(tx)
transaction_meta = xdr.TransactionMeta.from_xdr(tx_response['result_meta_xdr'])
tx_result = transaction_meta.v3.soroban_meta.return_value
if not tx_result:
raise RuntimeError
amount = u128_to_int(tx_result.u128)
print("Claim successful!")
print(f"Received {amount / 10 ** 7} AQUA")
This code claim rewards from the pool with Aquarius AMM on mainnet.
To successfully execute the code, provide the secret key of a Stellar account with share in the pool where the rewards are distributed.