Use methods of AKKA
There are many methods in AKKA object that help you implement an app for swapping tokens.
All methods defined in AKKA take an optional input which is an instance of RequestOptions
.
You can use this to customize your request.
Additionally, all the methods introduced in this page will also throw an instance of HTTPError
if the request fails.
getSpender method
The getSpender
method takes one mandatory input. It is an instance of SpenderRequest
.
This method will return a Promise
of SpenderResponse
which contains an attribute named address, and if the requested chainId is supported by AKKA it would be the address of the contract of AKKA for that chain.
Example usage:
getApproveTransaction method
This method takes as input an instance of ApproveTransactionRequest
.
It contains the chainId
, the tokenAddress
and optionally the amount
to be approved. If the amount is not present, it'll default to maximum possible amount. The return value of this method is a Promise of type ApproveTransactionResponse
.
It contains the data required to send an approve transaction with the given amount and the given token to the AKKA contract. This data needs to be signed by user wallet before being sent into an actual transaction.
Example usage:
getAllowance method
This method takes as input an object of type AllowanceRequest
, which has the following interface.
The return value is a Promise of type AllowanceResponse
and contains the amount of the given token from the given address that is allowed to spend by the AKKA contract.
Example usage:
getTokens method
The input of this method needs to be of type TokensRequest
.
When invoked, this method will return a Promise of type TokensResponse
.
This response contains the data of the tokens that are supported by the AKKA contract in the given chainId.
Example usage:
getQuote method
This method must be called with an input of type QuoteRequest
.
src
is the token address which the user has and wants to swap, dst
is the token address which they want to take and amount
is the amount of src
they want to exchange.
The return value is a Promise of QuoteResponse
, looking like this:
It will always contain the toAmount
parameter, which tells the amount of the dst
token that is received if the swap is done through the suggested route of AKKA. Optionally, if the includeTokensInfo
parameter is set to true
, the response would also contain the information of src
and dst
tokens in fromToken
and toToken
parameter. And likewise, if the includeProtocols
parameter is set to true
, the response will also contain the suggested routes for making the swap inside the protocols
parameter.
Example usage:
getSwap method
The input of this method is of type OnChainSwapRequest
, and the interface for it is given below:
The first 4 parameters are the same as the previous method. from
is the address of the wallet which holds the src
token, and slippage
is a number between 0 and 50 indicating the allowed percentage of slippage in received amount of dst
token.
The return value is an object with the following type:
The toAmount
is the same as the previous method. The tx
parameter contains the required data for sending into a transaction, after being signed of course.
Example usage:
Last updated