Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update quote request from & to amount types #287

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lifi/types",
"version": "15.15.0",
"version": "15.16.0-alpha.1",
"description": "Types for the LI.FI stack",
"keywords": [
"sdk",
Expand Down
27 changes: 21 additions & 6 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,10 @@ export interface ToolConfiguration {
preferExchanges?: string[]
}

export interface QuoteRequest extends ToolConfiguration, TimingStrings {
export interface PartialQuoteRequest extends ToolConfiguration, TimingStrings {
fromChain: number | string
fromToken: string
fromAddress: string
fromAmount: string

toChain: number | string
toToken: string
Expand All @@ -274,7 +273,7 @@ export interface QuoteRequest extends ToolConfiguration, TimingStrings {
referrer?: string
fee?: number | string
allowDestinationCall?: boolean // (default : true) // destination calls are enabled by default
fromAmountForGas?: string // the amount of token to convert to gas

maxPriceImpact?: number // hide routes with price impact greater than or equal to this value
skipSimulation?: boolean

Expand All @@ -284,11 +283,26 @@ export interface QuoteRequest extends ToolConfiguration, TimingStrings {
insurance?: boolean // indicates whether the user wants a quote with bridge insurance
}

export interface QuoteFromAmountRequest extends PartialQuoteRequest {
fromAmountForGas?: string // the amount of token to convert to gas
fromAmount: string
}

export interface QuoteToAmountRequest
extends Omit<QuoteRequest, 'fromAmount' | 'fromAmountForGas' | 'insurance'> {
extends Omit<PartialQuoteRequest, 'insurance'> {
toAmount: string
}

export type QuoteRequest = QuoteFromAmountRequest | QuoteToAmountRequest

export const isQuoteRequestWithFromAmount = (
r: QuoteRequest
): r is QuoteFromAmountRequest => 'fromAmount' in r

export const isQuoteRequestWithToAmount = (
r: QuoteRequest
): r is QuoteToAmountRequest => 'toAmount' in r

export interface ContractCall {
fromAmount: string
fromTokenAddress: string
Expand Down Expand Up @@ -331,12 +345,13 @@ export type ContractCallsQuoteRequestFromAmount =
export type ContractCallsQuoteRequest =
| ContractCallsQuoteRequestFromAmount
| ContractCallsQuoteRequestToAmount

export const isContractCallsRequestWithFromAmount = (
r: ContractCallsQuoteRequestFromAmount | ContractCallsQuoteRequestToAmount
r: ContractCallsQuoteRequest
): r is ContractCallsQuoteRequestFromAmount => 'fromAmount' in r

export const isContractCallsRequestWithToAmount = (
r: ContractCallsQuoteRequestFromAmount | ContractCallsQuoteRequestToAmount
r: ContractCallsQuoteRequest
): r is ContractCallsQuoteRequestToAmount => 'toAmount' in r

/* @deprecated */
Expand Down