Skip to main content

Token Unstake Smart Contract (1.0.0)

Download OpenAPI specification:Download

The Token Unstake Smart Contract handles all unbonding/unstaking logic for XKFI tokens. This contract was designed to keep the Energy Factory SC as simple as possible by separating the unlock/unbond functionality into a dedicated contract.

Overview

The Token Unstake contract provides:

  • Token Claiming: Claim unlocked tokens after the unbonding period
  • Unbonding Management: Track tokens that are in the unbonding process
  • Penalty Application: Apply penalties based on the lock duration of newly unlocked tokens

Unbonding Process

The system maintains a record of tokens eligible for unlocking:

  • Each entry includes the unbonding epoch
  • Only tokens past their unbonding epoch can be claimed
  • Penalty fees are calculated based on the lock duration

ABI

ABI reference for the Token Unstake smart contract (TokenUnstakeModule). Framework: klever-sc v0.45.0.

claimUnlockedTokens

Claims tokens that have already passed the unbonding period.

{
  "name": "claimUnlockedTokens",
  "mutability": "mutable",
  "inputs": [],
  "outputs": [
    { "type": "variadic<KdaTokenPayment>", "multi_result": true }
  ]
}

cancelUnbond

Cancels unbonding and recovers the locked tokens.

{
  "name": "cancelUnbond",
  "mutability": "mutable",
  "inputs": [],
  "outputs": [
    { "type": "variadic<KdaTokenPayment>", "multi_result": true }
  ]
}

UnstakePair Type

{
  "UnstakePair": {
    "type": "struct",
    "fields": [
      { "name": "unlock_epoch", "type": "u64" },
      { "name": "locked_tokens", "type": "KdaTokenPayment" },
      { "name": "unlocked_tokens", "type": "KdaTokenPayment" }
    ]
  }
}

Endpoints

Write operations that modify contract state

Claim Unlocked Tokens

Allows users to claim their unlocked tokens after the unbonding period has completed.

Process:

  1. System checks the user's list of tokens eligible for unlocking
  2. Only tokens past their unbonding epoch are processed
  3. A penalty fee is applied based on the lock duration
  4. Remaining tokens are sent to the user

Penalty Calculation: The penalty is calculated based on the original lock duration of the tokens being claimed. Longer lock periods result in higher penalties when unlocking early.

Important Notes:

  • Only tokens that have completed the unbonding period will be sent
  • If some tokens are still in the unbonding period, they remain in the contract
  • The user can call this endpoint multiple times as tokens become available

Example Response (receipts):

{
  "assetId": "KFI",
  "assetType": "Fungible",
  "from": "klv1qqqqqqqqqqqqqpgqk3zk5vnmm9xlz0da3ue6c4ghwjml7v3mx04s80t06t",
  "to": "klv1qqqqqqqqqqqqqpgqxs9ps7dv7dw3fta05unryxhu5vt9lacnx04sw904q3",
  "type": 0,
  "typeString": "Transfer",
  "value": 60000000
},
{
  "assetId": "XKFI-Y5SU/1",
  "assetType": "SemiFungible",
  "from": "klv1qqqqqqqqqqqqqpgqk3zk5vnmm9xlz0da3ue6c4ghwjml7v3mx04s80t06t",
  "to": "klv17e8zzgn73h6ehe3c6q9vlt77kuxk5euddmhymy5uhv2rhv0dc0nqlfp0ap",
  "type": 0,
  "typeString": "Transfer",
  "value": 100000000
}
Request Body schema: application/json
required
scAddress
required
string

Token Unstake contract address

funcName
required
string
Value: "claimUnlockedTokens"
args
Array of strings

No arguments required

Responses

Request samples

Content type
application/json
{
  • "scAddress": "klv1qqqqqqqqqqqqqpgqk3zk5vnmm9xlz0da3ue6c4ghwjml7v3mx04s80t06t",
  • "funcName": "claimUnlockedTokens",
  • "args": [ ]
}

Response samples

Content type
application/json
{
  • "data": {
    },
  • "error": "string",
  • "code": "string"
}