Re-Stake DOT (REBOND)
0. Initial setup
# imports
import requests
# Script parameters
ACCOUNT_ID = 4
AMOUNT_TO_REBOND = 0.1
LAM_USER = "lam_creator"
LAM_URL = "<LAM_URL>"
1. Get info about you account
GET /accounts/{ACCOUNT_ID}
account = requests.get(LAM_URL + f"/accounts/{ACCOUNT_ID}", headers={"X-Ledger-API-User": LAM_USER}).json()
Example response :
{
"address": "12MJp8QmUPMM78nQwkS6g9pq7oEX45tXyBdHHAhh762xyXJ5",
"available_balance": "58329408236",
"balance": "3049959737776",
"coin_fields": {
"anonymous_proxy": {
"address": "16AL3CZ1UeBHj4nbvxnNJTQufAaGtyEXtHgCuUcF1quEW9hx",
"balances": {
"available": 9670000000,
"bonded": 0,
"fee_frozen": 0,
"free": 19670000000,
"misc_frozen": 0,
"reserved": 330000000,
"total": 20000000000
},
"block_height": 10737260,
"created_at": "2022-06-14T09:00:24+00:00",
"ext_index": 2,
"index": 0,
"is_controller": true,
"is_main": true,
"kind": "Any"
},
"balances": {
"available": 58329408236,
"bonded": 2571220329540, // Rebonded funds will go (back) to this balance
"fee_frozen": 2781220329540,
"free": 2849549737776,
"misc_frozen": 2781220329540,
"reserved": 200410000000,
"total": 3049959737776,
"total_unbonded": 0, // We'll be taking from this balance...
"total_unbonding": 210000000000, // ... and this balance. Unbonding in priority
"unbonded": [],
"unbonding": [
{
"amount": 209000000000,
"waiting_time": 431590
},
{
"amount": 1000000000,
"waiting_time": 2159590
}
]
},
"staking": {
"controller_address": "16AL3CZ1UeBHj4nbvxnNJTQufAaGtyEXtHgCuUcF1quEW9hx",
"proxies": [
"12TzkPCrVfrZxupsdkt3vxZQS7Ajw3DVcpFpBH2PBDU4Uyja"
],
"rewards_destination": "Staked"
},
"type": "Polkadot"
},
"currency": "polkadot",
"id": 4,
"name": "Polkadot 0",
"type": "Polkadot",
[...]
}
2. Make sure you don't try to REBOND more than you have bonded, otherwise the transaction will fail
if (
account["coin_fields"]["balances"]["total_REBONDing"]
+ account["coin_fields"]["balances"]["total_REBONDed"]
) < AMOUNT_TO_REBOND:
raise ValueError("Not enough unbonding/unbonded to REBOND")
3. Create an REBOND transaction request
POST /transactions
transaction_result = requests.post(
LAM_URL + f"/transactions",
json={
"account_name": account["name"],
"amount": {
"unit": "DOT",
"value": str(AMOUNT_TO_REBOND)
},
"coin_fields": {"type": "REBOND"},
"max_fees": {"value": "0", "unit": "Planck"},
"note": {
"title": "LAM REBOND TX",
"content": f"{AMOUNT_TO_REBOND // (10 ** 10)} DOT REBOND TX MADE THROUGH THE LAM"
},
"recipient": "",
"speed": "CUSTOM",
},
headers={"X-Ledger-API-User": LAM_USER},
)