Approval
In order for Kima to move tokens on behalf of the user an on chain approval needs to happen. An approval has 3 components:
Owner address: User
Spender address: Kima Pool
Total amount: origin token amount plus gas fees
Getting the Kima Pool Address
Using the Kima Backend
GET /chains/pool
returns a list of pool addresses and balances for all supported chains.
Using the Kima API
EVM
ecdsa
0x9a721c664f9d69e4da24f91386086fbd81da23c1
Solana
eddsa
5tvyUUqPMWVGaVsRXHoQWqGw6h9uifM45BHCTQgzwSdr
Tron
ecdsa (base58)
TQ3qmAgUgMwrY9prMiHLZmF43G4Jk8bxNF
You can also obtain the pool addresses from the TSS endpoint. Use the type
in the chart above to determine which one to use.
GET https://api.sardis.kima.network/kima-finance/kima-blockchain/kima/tss_pubkey
Success Response:
tssPubkey
(array object)tssPubKey: string
ecdsa: string
eddsa: string
reserved: string
pagination
(object)nextKey: string | null
total: number
Note: for Tron, the hex ecdsa
address must be converted to a base 58 checksum address.
Getting the Service Fee
Using theKima Backend
To calculate the total amount, the service (gas) fees are needed. The Kima Backend has an endpoint that does all the calculations for you.
/submit/fees?amount=10&originChain=TRX&targetChain=ARB&deductFee=true&originSymbol=USDK
Success Response:
totalFee
(bigint string): sum of all fees in USDtotalFeeUsd
(number): sum of all fees in USDallowanceAmount
(bigint string): the token amount that needs to be approved. Can be passed directly to the contract call.decimals
(number): the number of decimals for the bigint amountsdeductFee
(boolean): whether the fees are deducted from the amount or notsubmitAmount
(bigint string): the amount that needs to be passed to the /submit endpointbreakdown
: individual feesamount
: fee amountfeeType
: 'gas' | 'service'chain
: chain short name
Chain Names
See the short names in the Supported blockchains section.
Using the Kima API
The Kima gas fee estimation endponts can also be called directly. In this case it is necessary to make 2 calls, one for the source chain and one for the target chain. Then the results can be combined to get the total fee.
The Kima API endpoint will soon be updated to perform the same calculations as the Kima Backend. We recommend using the Kima Backend for now.
GET https://fee.kima.network/fee/{chainName}
Example: https://fee.kima.network/fee/AVX
Response
result:
boolean
fee:
string
: dash delimited list<Amount USD>-<Timestamp>-<Amount Crypto>
Amount USD: the service fee amount in USD
Timestamp: Javascript timestamp in milliseconds
Amount Crypto: the fee amount in the native token of the given chain- i.e. AVAX
Calculating the Service Fee
To calculate the total service fee requires querying for the fees on both the source and target chains using the endpoint described above. There are a couple exceptions:
The fee is ZERO in the following cases as it is handled elsewhere:
Source or target chain is
FIAT
Target chain is
BTC
There is a constant value when the source chain is BTC
:
Source chain is BTC: 0.0004 BTC
Since the source and target chains can be different, the USD amount fee amounts should be used and added together. The user will pay the fee using the source token. Remember, even stable coins are not exactly one USD, so the USD fee amount should be converted into the source token amount using the USD price of the source token.
Code Sample
Putting it all together, the following is a typescript code example that queries the endpoint and calculates the total service fee.
Calculate the Approval Amount
Using the Kima Backend
Use the allowanceAmount
property returned from the /submit/fees
endpoint.
Using the Kima API
The approval amount will be different when deducting the fees or not.
When deducting the fees, the approval should be just the amount
Otherwise, the approval should be the amount plus the fees
Calling Approve
Once all the info has been collected it’s time to make the on chain call. The exact details of how this is done depends on the origin chain and library used.
The getClientsForChain()
and getPoolAdressesForChain()
would be utility functions defined elsewhere.
Last updated