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.
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
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
Create Energy Position
Creates an energy position by converting sent tokens to KFI, locking them in the Energy Factory, and providing slippage protection.
Process:
- If the sent token is not KFI, performs swap operations to convert to KFI
- Locks the KFI in the Energy Factory to receive Energy
- Validates slippage (minimum amount) and reverts if exceeded
- 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/jsonrequired
| scAddress required | string Position Creator contract address |
| funcName required | string Value: "createEnergyPosition" |
| args required | Array of strings Arguments:
|
| value required | string Token payment to convert and stake |
Responses
Request samples
- Payload
{- "scAddress": "klv1qqqqqqqqqqqqqpgqmmwcqes3hu9ws02rwfdp8rslh6cv92ate36stnt88h",
- "funcName": "createEnergyPosition",
- "args": [
- "u64:360",
- "BigUint:10000000"
], - "value": "KFI=10000000"
}Response samples
- 200
{- "data": {
- "returnData": [
- "string"
], - "returnCode": "string",
- "returnMessage": "string"
}, - "error": "string",
- "code": "string"
}