Alammex
Search…
⌃K

Alammex Referral Program

A program to reward developers who leverage Alammex.

Overview

Alammex has exposed APIs (and SDKs that wrap the API calls) for fetching quotes for swaps and executing said quotes. To incentivize usage of these APIs, Alammex offers a referral program, where developers can earn 50% of the Alammex commissions generated by traffic through API calls.

How to participate?

The interface for fetching the transaction groups for executing an Alammex quote includes a referrer address field. If this field is set, 50% of Alammex commissions will be sent to an escrow (logic signature) account that can only be accessed by the given referrer address. An escrow account is used in order to handle opt ins of assets that the given referrer address has not opted into.
Alammex has exposed a simple API that returns the escrow account address for any referrer address input:
https://app.alammex.com/api/treasuryAddress?address=<referrer_address>
Here is an example.
Note: The escrow account must be funded with a minimum balance of 0.1 ALGO before any non-ALGO assets can be deposited to it.
For visibility, here is the Pyteal of the logic signature template used to generate the escrow address. If you replace the <REFERRER_ADDRESS> placeholders with an Algorand address, compile the logic signature and print its address, it will match the output from the Alammex treasuryAddress API.
def logicsig():
# general safety condition for escrows
safety_cond = And(
Txn.close_remainder_to() == Global.zero_address(),
Txn.asset_close_to() == Global.zero_address(),
Txn.rekey_to() == Global.zero_address(),
)
# asset opt in
approve_asset_opt_in_with_payment = And(
Gtxn[Txn.group_index() - Int(1)].type_enum() == TxnType.Payment,
Gtxn[Txn.group_index() - Int(1)].sender() != Txn.sender(),
Gtxn[Txn.group_index() - Int(1)].receiver() == Txn.sender(),
Gtxn[Txn.group_index() - Int(1)].amount() == Int(101000),
Txn.type_enum() == TxnType.AssetTransfer,
Txn.asset_amount() == Int(0),
Txn.asset_receiver() == Txn.sender(),
)
# withdrawal
approve_withdrawal = And(
Gtxn[0].type_enum() == TxnType.Payment,
Gtxn[0].sender() != Txn.sender(),
Gtxn[0].receiver() == Txn.sender(),
Gtxn[0].amount() == Int(2000),
Txn.group_index() == Int(1),
Or(
And(Txn.type_enum() == TxnType.AssetTransfer, Txn.asset_receiver() == Addr(<REFERRER_ADDRESS>)),
And(Txn.type_enum() == TxnType.Payment, Txn.receiver() == Addr(<REFERRER_ADDRESS>)),
)
)
router = Cond(
[Txn.asset_receiver() == Txn.sender(), approve_asset_opt_in_with_payment],
[Txn.asset_receiver() != Txn.sender(), approve_withdrawal]
)
return And(safety_cond, router)

Redeeming Commissions from Escrow

Assets from the escrow account can only be sent to the referrer address that was used to generate the escrow account.
In the near future, there will be a web interface to connect a referrer wallet and generate/sign the transactions to redeem the commissions from the escrow account. Until then, here is a script to redeem rewards to a referrer address from an escrow account:
from algosdk.future.transaction import AssetTransferTxn, LogicSig, LogicSigTransaction, PaymentTxn
from algosdk.v2client.algod import AlgodClient
from algosdk import mnemonic, encoding, transaction
import base64
# referrer details
referrer = '<INSERT_REFERRER_ADDRESS>'
referrerSecretKey = mnemonic.to_private_key('<INSERT_REFERRER_MNEMONIC>')
# client initialization
algodUri = '<INSERT_ALGOD_URI>'
algodToken = '<INSERT_ALGOD_TOKEN>'
algodHeaders = {
# INSERT ALGOD HEADERS
}
client = AlgodClient(algodToken, algodUri, algodHeaders)
# escrow generation
lsigTemplatebytes = 'BCACAQQmASA/Z9KfB6i0YpMy9iD9fhVopMk24qsAsbmpuUS9r61vAjEJMgMSMRUyAxIQMSAyAxIQMRQxABJAAEAxFDEAE0AAAQAzABAiEjMAADEAExAzAAcxABIQMwAIgdAPEhAxFiISEDEQIxIxFCgSEDEQIhIxBygSEBEQQgA5MRYiCTgQIhIxFiIJOAAxABMQMRYiCTgHMQASEDEWIgk4CIGIlQYSEDEQIxIQMRKBABIQMRQxABIQEEM='
t = lsigTemplatebytes.encode()
program = bytearray(base64.decodebytes(t))
referrerEscrowBytes = program[0:8] + bytearray(encoding.decode_address(referrer)) + program[40:]
referrerEscrowLSig = LogicSig(program=referrerEscrowBytes)
account_info = client.account_info(referrerEscrowLSig.address())
# withdraw algo
if account_info['amount-without-pending-rewards'] - account_info['min-balance'] > 0:
txn1 = PaymentTxn(
sender=referrer,
receiver=referrerEscrowLSig.address(),
sp=client.suggested_params(),
amt=2000,
)
txn2 = PaymentTxn(
sender=referrerEscrowLSig.address(),
receiver=referrer,
sp=client.suggested_params(),
amt=account_info['amount-without-pending-rewards'] - (account_info['min-balance']),
)
txns = transaction.assign_group_id([txn1, txn2])
txns[0] = txns[0].sign(referrerSecretKey)
txns[1] = LogicSigTransaction(txns[1], referrerEscrowLSig)
client.send_transactions(txns)
# withdraw assets
assets = account_info['assets']
for asset in assets:
txn1 = PaymentTxn(
sender=referrer,
receiver=referrerEscrowLSig.address(),
sp=client.suggested_params(),
amt=2000,
)
txn2 = AssetTransferTxn(
sender=referrerEscrowLSig.address(),
receiver=referrer,
sp=client.suggested_params(),
amt=asset['amount'],
index=asset['asset-id'],
)
txns = transaction.assign_group_id([txn1, txn2])
txns[0] = txns[0].sign(referrerSecretKey)
txns[1] = LogicSigTransaction(txns[1], referrerEscrowLSig)
client.send_transactions(txns)