Unstake

This section describes how to unstake.

Overview

To unstake user needs to send message with OP::BURN to its Jetton Wallet and specify amount of stTON to burn. The TL-B scheme of burn request is following:

burn#595f07bc query_id:uint64 jetton_amount:Coins = InternalMsgBody;

Then message with OP::BURN_NOTIFICATION comes from Jetton Wallet to Financial contract. Financial checks that sender is valid and message has enough TON for burn notification and if everything is correct it deploys Unstake Request contract with user address (owner_address) and withdraw_ton_amount (int withdraw_ton_amount = muldiv(ton_total_supply, withdraw_jetton_amount, jetton_total_supply)). To retrieve ton_total_supply and jetton_total_supply (if needed) you have to invoke get_full_data method in Financial contract:

// TL-B:
get_full_data#_ = (
    jetton_total_supply:Coins 
    ton_total_supply:Coins 
    commission_total_supply:Coins
    commission_factor:uint16
    commission_address:MsgAddressInt
    admin_address:MsgAddressInt
    transaction_address:MsgAddressInt
    content:^Cell
    jetton_wallet_code:^Cell
    unstake_request_code:^Cell
    last_lockup_epoch:uint32
    lockup_supply:Coins
    next_lockup_supply:Coins
    later_lockup_supply:Coins
    next_unstake_request_index:uint64
)

The TL-B scheme of burn notification is following:

burn_notification#7bdd97de query_id:uint64 withdraw_jetton_amount:Coins owner_address:MsgAddressInt = InternalMsgBody;

After Unstake Request is deployed, anyone can send message to it. Contract checks that unlock timestamp has passed and if everything is correct it sends message to Financial with OP::UNSTAKE, ton amount, jetton amount (currently unused) and user address. The TL-B scheme of this message is following:

unstake#0000000a index:uint64 owner:MsgAddressInt withdraw_ton_amount:Coins withdraw_jetton_amount:Coins = InternalMsgBody;

Then Financial contract checks that its balance is enough (balance - MIN_TON_FOR_STORAGE >= withdraw_ton_amount) and if this condition is correct it empty message with value equal to unstake_amount (withdraw_ton_amount + msg_value - (storage_fee + LOCKUP_GAS_CONSUMPTION + UNSTAKE_GAS_CONSUMPTION) to user.

Otherwise, it sends message back to Unstake Request. The TL-B scheme of this message is following:

return_unstake_request#00000065 unlock_timestamp:uint32 = InternalMsgBody;

Last updated