Skip to content

Commit

Permalink
fix: update types with recent api changes
Browse files Browse the repository at this point in the history
  • Loading branch information
RanGojo committed Aug 5, 2024
1 parent b1293ce commit 1cd4b00
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 23 deletions.
10 changes: 9 additions & 1 deletion src/api/basic/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import {
AssetAndAmount,
WalletDetail,
WalletDetailsResponse,
TokenBalanceRequest,
TokenBalanceResponse,
} from '../shared/index.js'

export { AssetAndAmount, WalletDetail, WalletDetailsResponse }
export {
AssetAndAmount,
WalletDetail,
WalletDetailsResponse,
TokenBalanceRequest,
TokenBalanceResponse
}
29 changes: 29 additions & 0 deletions src/api/basic/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,32 @@ export type MetaResponse = {
tokens: Token[]
swappers: SwapperMeta[]
}

/**
* Custom token request
*
* @property {string} blockchain - The blockchain that token belong to
* @property {string} address - The contract address for the desired token
*
*/
export type CustomTokenRequest = {
blockchain: string
address: string
}

/**
* The custom token response which includes:
* Token details for user desired token that is not available on Rango official list.
* Currently supports Solana and EVM based blockchains.
*
* @property {Token} token - The destination asset
* @property {string | null} error - Error message
* @property {number | null} errorCode - Error code
* @property {number | null} traceId - Trace Id, for debug purpose
*/
export type CustomTokenResponse = {
token: Token
error: string | null
errorCode: number | null
traceId: number | null
}
10 changes: 9 additions & 1 deletion src/api/main/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ import {
AssetAndAmount,
WalletDetail,
WalletDetailsResponse,
TokenBalanceRequest,
TokenBalanceResponse,
} from '../shared/index.js'

export { AssetAndAmount, WalletDetail, WalletDetailsResponse }
export {
AssetAndAmount,
WalletDetail,
WalletDetailsResponse,
TokenBalanceRequest,
TokenBalanceResponse
}
4 changes: 2 additions & 2 deletions src/api/main/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export type TimeStat = {
*
* @property {RecommendedSlippage | null} recommendedSlippage
*
* @property {string[] | null} warnings - List of warnings for this swap step, usually null or empty
* @property {string[]} warnings - List of warnings for this swap step, it's usually an empty list
*
*/
export type SwapResult = {
Expand All @@ -226,5 +226,5 @@ export type SwapResult = {
includesDestinationTx: boolean
maxRequiredSign: number
recommendedSlippage: RecommendedSlippage | null
warnings: string[] | null
warnings: string[]
}
30 changes: 30 additions & 0 deletions src/api/main/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,33 @@ export type CompactMetaResponse = {
popularTokens: CompactToken[]
swappers: SwapperMeta[]
}


/**
* Custom token request
*
* @property {string} blockchain - The blockchain that token belong to
* @property {string} address - The contract address for the desired token
*
*/
export type CustomTokenRequest = {
blockchain: string
address: string
}

/**
* The custom token response which includes:
* Token details for user desired token that is not available on Rango official list.
* Currently supports Solana and EVM based blockchains.
*
* @property {Token} token - The destination asset
* @property {string | null} error - Error message
* @property {number | null} errorCode - Error code
* @property {number | null} traceId - Trace Id, for debug purpose
*/
export type CustomTokenResponse = {
token: Token
error: string | null
errorCode: number | null
traceId: number | null
}
28 changes: 9 additions & 19 deletions src/api/main/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export type InterChainMessage = {
* @property {number | null} [affiliatePercent] - If you want to change the default affiliate fee percentage, you can provide a new value here.
* @property {{ [key: string]: string }} [affiliateWallets] - If you want to change the default affiliate wallet addresses, you can provide new values here.
* (Map of route blockchains to affiliate address)
* @property {boolean} [disableMultiStepTx] - It should be false when the client wants multi-transactions step, default is true.
* @property {boolean} [disableMultiStepTx] - It should be false when client wants to support multi-transactions per route step. default is true.
* @property {string[]} [blockchains] - List of all accepted blockchains, an empty list means no filter is required
* @property {string[]} [swappers] - List of all accepted swappers, an empty list means no filter is required
* @property {boolean} [swappersExclude] - Indicates include/exclude mode for the swappers param
Expand Down Expand Up @@ -168,14 +168,12 @@ export type BestRouteRequest = {
* @property {Asset} from - The source asset
* @property {Asset} to - The destination asset
* @property {SimulationResult | null} result
* @property {BlockchainValidationStatus[] | null} validationStatus - Pre-requisites check result. It will be null if
* @property {BlockchainValidationStatus[]} validationStatus - Pre-requisites check result. It will be null if
* the request checkPrerequisites was false
* @property {string[]} diagnosisMessages - list of string messages that might be cause of not finding the route.
* It's just for display purposes
* @property {string[]} missingBlockchains - List of all blockchains which are necessary to be present for the best
* route and user has not provided any connected wallets for it. A null or empty list indicates that there is no problem.
* @property {boolean} processingLimitReached - A warning indicates that it took too much time to find the best
* route and the server could not find any routes from X to Y
* @property {boolean} walletNotSupportingFromBlockchain - A warning indicates that none of your wallets have the same
* blockchain as X asset
* @property {boolean} boolean - A The state of confirm swap
Expand All @@ -190,12 +188,10 @@ export type BestRouteResponse = {
from: Asset
to: Asset
result: SimulationResult | null
validationStatus: BlockchainValidationStatus[] | null
diagnosisMessages: string[] | null
missingBlockchains: string[] | null
processingLimitReached: boolean
validationStatus: BlockchainValidationStatus[]
diagnosisMessages: string[]
missingBlockchains: string[]
walletNotSupportingFromBlockchain: boolean
confirmSwapStatus?: boolean
error: string | null
errorCode: number | null
traceId: number | null
Expand Down Expand Up @@ -248,8 +244,6 @@ export type SimulationScore = {
* @property {SwapResult[]} swaps - List of required swaps to swap X to Y with the expected outputAmount
* @property {SimulationScore[]} scores - List of scores calculated for each preference aspect
* @property {RouteTag[]} tags - List of tags attributed to each route considering every aspect
* @property {BlockchainValidationStatus[] | null} validationStatus - Pre-requisites check result. It will be null if
* the request checkPrerequisites was false
* @property {string[]} missingBlockchains - List of all blockchains which are necessary to be present for the best
* route and user has not provided any connected wallets for it. A null or empty list indicates that there is no problem.
* @property {boolean} walletNotSupportingFromBlockchain - A warning indicates that none of your wallets have the same
Expand All @@ -262,15 +256,14 @@ export type MultiRouteSimulationResult = {
swaps: SwapResult[]
scores: { preferenceType: PreferenceType; score: number }[]
tags: RouteTag[]
validationStatus: BlockchainValidationStatus[] | null
missingBlockchains: string[] | null
missingBlockchains: string[]
walletNotSupportingFromBlockchain: boolean
}

/**
* The best route request body for multi-routing
*/
export type MultiRouteRequest = Omit<BestRouteRequest, 'selectedWallets' | 'destination'>
export type MultiRouteRequest = Omit<BestRouteRequest, 'selectedWallets' | 'destination' | 'checkPrerequisites' | 'forceExecution' | 'maxLength'>

/**
* The best route response for multi-routing, if the results field is empty, it means that no route is found
Expand All @@ -280,8 +273,6 @@ export type MultiRouteRequest = Omit<BestRouteRequest, 'selectedWallets' | 'dest
* @property {string} requestAmount - The human readable input amount from the request
* @property {string} routeId - The unique roteId generated for this request by server
* @property {MultiRouteSimulationResult} results - List of best routes data
* @property {boolean} processingLimitReached - A warning indicates that it took too much time to find the best
* route and the server could not find any routes from X to Y
* @property {string[]} diagnosisMessages - list of string messages that might be cause of not finding the route.
* It's just for display purposes
* @property {string | null} error - Error message
Expand All @@ -294,8 +285,7 @@ export type MultiRouteResponse = {
requestAmount: string
routeId: string
results: MultiRouteSimulationResult[]
processingLimitReached: boolean
diagnosisMessages: string[] | null
diagnosisMessages: string[]
error: string | null
errorCode: number | null
traceId: number | null
Expand Down Expand Up @@ -326,7 +316,7 @@ export type ConfirmRouteRequest = {
*/
export type ConfirmRouteResponse = {
ok: boolean
result: BestRouteResponse | null
result: Omit<BestRouteResponse, 'error' | 'errorCode' | 'traceId'> | null
error: string | null
errorCode: string | null
traceId: number | null
Expand Down
5 changes: 5 additions & 0 deletions src/api/main/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
TronTransaction,
TonTransaction,
} from '../shared/index.js'
import { Token } from './meta.js'
import { EvmTransaction, StarknetTransaction } from './txs/index.js'

export {
Expand Down Expand Up @@ -137,6 +138,8 @@ export type Transaction =
* the status is successful or failed, example: 1635271424813
* @property {string | null} extraMessage - A message in case of failure, that could be shown to the user
* @property {string | null} outputAmount - The output amount of the transaction if it was successful, exmaple: 0.28
* @property {Token | null} outputToken - The output token, it could be the desired token or the refunded token
* @property {string | null} outputType - Type of output token
* @property {Transaction | null} newTx - if a transaction needs more than one-step transaction to be signed by
* the user, the next step transaction will be returned in this field.
* @property {string | null} diagnosisUrl - In some special cases [e.g. AnySwap], the user should follow some steps
Expand All @@ -151,6 +154,8 @@ export type TransactionStatusResponse = {
timestamp: number | null
extraMessage: string | null
outputAmount: string | null
outputToken: Token | null
outputType: null | 'REVERTED_TO_INPUT' | 'MIDDLE_ASSET_IN_SRC' | 'MIDDLE_ASSET_IN_DEST' | 'DESIRED_OUTPUT'
newTx: Transaction | null
diagnosisUrl: string | null
explorerUrl: SwapExplorerUrl[] | null
Expand Down
32 changes: 32 additions & 0 deletions src/api/shared/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,35 @@ export type WalletDetail = {
export type WalletDetailsResponse = {
wallets: WalletDetail[]
}


/**
* The token balance request
*
* @property {string} walletAddress - The user wallet address
* @property {string} blockchain - The blockchain which this token belongs to
* @property {string} symbol - The token symbol, e.g: ADA
* @property {string | null} address - Smart contract address of token, null for native tokens
*
*/
export type TokenBalanceRequest = {
walletAddress: string
blockchain: string
symbol: string
address: string | null
}

/**
* The token balance response
*
* @property {number | null} balance - The balance for token
* @property {string | null} error - Error message
* @property {number | null} errorCode - Error code
* @property {number | null} traceId - Trace Id, for debug purpose
*/
export type TokenBalanceResponse = {
balance: number | null
error: string | null
errorCode: number | null
traceId: number | null
}
1 change: 1 addition & 0 deletions src/api/shared/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export enum RoutingResultType {
HIGH_IMPACT = 'HIGH_IMPACT',
NO_ROUTE = 'NO_ROUTE',
INPUT_LIMIT_ISSUE = 'INPUT_LIMIT_ISSUE',
HIGH_IMPACT_FOR_CREATE_TX = 'HIGH_IMPACT_FOR_CREATE_TX',
}

0 comments on commit 1cd4b00

Please sign in to comment.