Skip to main content

Position Creator Smart Contract (1.0.0)

Download OpenAPI specification:Download

The Position Creator Smart Contract simplifies the process of staking KFI in the Energy Factory contract. While the Energy Factory exclusively accepts KFI for locking, this contract allows users to send any token listed in the DeFi ecosystem.

Overview

The Position Creator contract provides:

  • Automatic Token Conversion: Convert any listed token to KFI via liquidity pool swaps
  • One-Step Staking: Swap and lock tokens in a single transaction
  • Slippage Protection: Ensure minimum output amount to protect against price fluctuations

Prerequisites

For this contract to work, the following must be in place:

  • Router SC: Facilitates token conversion to KFI using pair contracts
  • Pair Contract SC: Manages liquidity pairs for swap operations
  • Energy Factory SC: Manages energy and all staking-related operations
  • Whitelist: This contract's address must be registered in the Energy Factory whitelist

Endpoints

Write operations that modify contract state

Create Energy Position

Creates an energy position by converting sent tokens to KFI, locking them in the Energy Factory, and providing slippage protection.

Process:

  1. If the sent token is not KFI, performs swap operations to convert to KFI
  2. Locks the KFI in the Energy Factory to receive Energy
  3. Validates slippage (minimum amount) and reverts if exceeded
  4. Returns any residual balance to the caller

Slippage Protection: The min_amount_out parameter ensures that if the final KFI amount after swaps is less than this value, the transaction will revert with "Slippage exceeded" error.

Swap Operations: When sending a token other than KFI, you must provide the swap route. Each swap operation in the list contains:

  • Pair address for the swap
  • Token to receive from that swap

Payment: Any token listed in the DeFi (KLV, KFI, USDT, etc.)

Request Body schema: application/json
required
scAddress
required
string

Position Creator contract address

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

Arguments:

  • lock_epochs (u64): Number of epochs to lock tokens
  • min_amount_out (BigUint): Minimum expected KFI amount after conversion (slippage protection)
  • swap_operations (optional, list): List of swap operations to convert tokens to KFI
    • Each operation contains: pair_address, token_out
value
required
string

Token payment to convert and stake

Responses

Request samples

Content type
application/json
Example
{
  • "scAddress": "klv1qqqqqqqqqqqqqpgqmmwcqes3hu9ws02rwfdp8rslh6cv92ate36stnt88h",
  • "funcName": "createEnergyPosition",
  • "args": [
    ],
  • "value": "KFI=10000000"
}

Response samples

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