Energy Factory Smart Contract (1.0.0)
Download OpenAPI specification:Download
The Energy Factory smart contract manages the XKFI token system and energy accumulation mechanism in Bitcoin.me DeFi.
XKFI is the locked version of KFI token. By locking KFI tokens for a specific period (1, 2, or 4 years), accounts accumulate Energy which provides various benefits including fee collection and protocol rewards.
When locking KFI, users receive an XKFI SFT with metadata containing:
original_token_id: The original token ID (e.g., KFI)original_token_nonce: The SFT nonceunlock_epoch: Epoch when KFI will be available for unlock
Lock Tokens
Lock KFI tokens until a specified unlock epoch and receive XKFI SFT tokens at a 1:1 ratio.
Accepted input token types:
- Base asset token (KFI)
- Token from old factory (extends all periods to the provided option)
- Previously locked token (extends period to the provided option)
Process:
- Verifies contract is not paused and lock option is valid
- Gets payment (KLV or KDA token)
- Calculates unlock_epoch (must be greater than current epoch)
- Locks token according to type and conditions
- Sends LOCKED tokens to destination address
Note: If a lockTokens has the same metadata, amount is added to the existing SFT instead of creating a new one with a different nonce.
Request Body schema: application/jsonrequired
| scAddress required | string Energy Factory contract address |
| funcName required | string Value: "lockTokens" |
| args required | Array of strings Arguments in hexadecimal:
|
Responses
Request samples
- Payload
{- "scAddress": "klv1qqqqqqqqqqqqqpgq9696g7x76kwrrh02fahn4rpem4v595t8c0nqgxzpmu",
- "funcName": "lockTokens",
- "args": [
- "0168"
]
}Response samples
- 200
{- "data": {
- "returnData": [
- "string"
], - "returnCode": "string",
- "returnMessage": "string"
}, - "error": "string",
- "code": "string"
}Unlock Tokens
Unlock tokens that were previously locked using lockTokens.
Expected Payment: LOCKED (XKFI) tokens
Process:
- Verifies contract is not paused
- Gets current epoch and caller address
- Initializes output payment representing unlocked tokens
- Updates caller's energy:
- Gets non-empty payments and verifies all are the same token
- For each payment, retrieves locked token attributes and unlocks
- Updates energy based on unlocked amount and unlock epoch
- Merges unlocked tokens to output payment
- Sends unlocked tokens to caller address
Request Body schema: application/jsonrequired
| scAddress required | string Energy Factory contract address |
| funcName required | string Value: "unlockTokens" |
| args | Array of strings No arguments required (payment is the LOCKED tokens) |
Responses
Request samples
- Payload
{- "scAddress": "string",
- "funcName": "unlockTokens",
- "args": [
- "string"
]
}Response samples
- 200
{- "data": {
- "returnData": [
- "string"
], - "returnCode": "string",
- "returnMessage": "string"
}, - "error": "string",
- "code": "string"
}Extend Lock Period
Extend the lock period for tokens. Used internally by proxy-dex.
Expected Payment: KDA payment (must be a locked token)
Requirements:
- Contract must not be paused
- Lock option must be valid
- Caller must be in token transfer whitelist
Process:
- Verifies contract is not paused and lock option is valid
- Gets caller address and verifies it's in token transfer whitelist
- Gets payment and verifies it's the correct type
- Calculates unlock_epoch (must be greater than current epoch)
- Updates user energy, extending token lock period
- Sends corresponding tokens back to caller
Request Body schema: application/jsonrequired
| scAddress required | string |
| funcName required | string Value: "extendLockPeriod" |
| args required | Array of strings
|
Responses
Request samples
- Payload
{- "scAddress": "string",
- "funcName": "extendLockPeriod",
- "args": [
- "string"
]
}Response samples
- 200
{- "data": {
- "returnData": [
- "string"
], - "returnCode": "string",
- "returnMessage": "string"
}, - "error": "string",
- "code": "string"
}Unlock Early (with penalty)
Instantly unlock locked tokens with a penalty. The penalty increases with remaining lock time.
Expected Payment: KDA payment (XKFI tokens)
Process:
- Verifies contract is not paused
- Gets caller and determines user with energy from optional parameter
- Performs common lock period reduction using received payment
- Converts unlocked tokens to KDA payment format
- Calculates amount to burn based on penalty applied to payment value
- Updates tokens to burn amount
- Updates user energy with new energy entry
- Unbonds tokens from user
- Returns unlocked tokens
Penalty Calculation:
- Penalty percentage increases with longer remaining lock periods
- Query
getPenaltyAmountto calculate exact penalty before calling
Example Response (receipts):
{
"assetId": "XKFI-2AR6/2",
"assetType": "SemiFungible",
"from": "klv17e8zzgn73h6ehe3c6q9vlt77kuxk5euddmhymy5uhv2rhv0dc0nqlfp0ap",
"to": "klv1qqqqqqqqqqqqqpgq9696g7x76kwrrh02fahn4rpem4v595t8c0nqgxzpmu",
"value": 100000000
}
Request Body schema: application/jsonrequired
| scAddress required | string |
| funcName required | string Value: "unlockEarly" |
| args | Array of strings
|
Responses
Request samples
- Payload
{- "scAddress": "klv1qqqqqqqqqqqqqpgq9696g7x76kwrrh02fahn4rpem4v595t8c0nqgxzpmu",
- "funcName": "unlockEarly",
- "args": [ ]
}Response samples
- 200
{- "data": {
- "returnData": [
- "string"
], - "returnCode": "string",
- "returnMessage": "string"
}, - "error": "string",
- "code": "string"
}