forked from joshstevens19/simple-uniswap-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdex.types.ts
More file actions
248 lines (227 loc) · 7.6 KB
/
dex.types.ts
File metadata and controls
248 lines (227 loc) · 7.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
import type { ChainId } from '@chain-toolkit/schemas'
import type { Address } from '@multicall-toolkit/types'
import type { Protocols } from './contract-detail.types'
import type { DexMulticallProviderContext } from './dex-provider.types'
import type { MultiPriceContext } from './price-source.types'
import type { TokenListContext } from './token-list.types'
import type { TradeFormat, TradeFormatOptions } from './trade.types'
import type { Version } from './version.types'
/** Represents the types of decentralized exchanges (DEX) supported. */
export type DexType =
| 'DOVESWAP'
| 'ENERGISWAP'
| 'PANCAKESWAP'
| 'PANGOLIN'
| 'PULSEX'
| 'QUICKSWAP'
| 'SUSHISWAP'
| 'TRADERJOE'
| 'UNISWAP'
| 'YETISWAP'
/** Represents the type for custom DEX configurations. */
export type CustomDexType = DexType | 'CUSTOM'
/** Represents a tag used to identify DEX instances, which can be a standard DEX or a custom string. */
export type DexTag = DexType | string
/** Represents the version of the DEX, such as v2 or v3. */
export type DexProtocol = 'protocolV2' | 'protocolV3'
/** Represents a key for a DEX configuration. */
export type DexKey = {
/**
* A tag or identifier for the specific DEX configuration.
*/
dexTag: DexTag
/**
* The protocol of the DEX (e.g., 'protocolV2', 'protocolV3').
*/
protocol: DexProtocol
/**
* The dex version.
*/
version: Version
}
/** Represents the base configuration for a DEX. */
export type DexConfigBase = {
/** The type of the DEX. */
dexType: DexType
/** Multi-contract details used for interacting with the DEX. */
protocols: Protocols
/** The tag used to identify the DEX instance. */
dexTag: DexTag
}
/** A mapping of DEX tags to their respective configurations. */
export type DexConfigsByDex = Record<DexTag, DexConfigBase>
/** Represents the configuration of a DEX for a specific chain. */
export type DexChainConfig = {
/** The type of the DEX. */
dexType: DexType
/** The chain ID of the network the DEX is operating on. */
chainId: ChainId
}
/** Represents the context for a DEX and its associated chain configurations. */
export type DexChainContext = DexChainConfig | DexChainConfig[]
/** Represents the context for one or more DEX configurations. */
export type DexConfigContext = DexConfigBase | DexConfigBase[]
/** Represents the base context for a DEX configuration. */
export type DexConfigBaseContext =
| {
/** The type of the DEX. */
dexType: DexType
/** Multi-contract details used for interacting with the DEX. */
protocols: Protocols
/**
* Optional tag to identify the DEX.
* If not provided, it will use the `dexType`.
*/
dexTag?: DexTag
}
| {
/** Represents a custom DEX type. */
dexType: 'CUSTOM'
/** Multi-contract details used for interacting with the custom DEX. */
protocols: Protocols
/** The tag used to identify the custom DEX. */
dexTag: DexTag
}
/** Represents the overall context of a DEX, including its type and configuration. */
export type DexContext =
| DexType
| DexConfigBaseContext
| (DexType | DexConfigBaseContext)[]
/** Represents the full configuration for a DEX. */
export type DexConfig = DexConfigBase & {
/** The title or name of the DEX. */
title: string
/** The chain ID of the network the DEX operates on. */
chainId: ChainId
/** Optional logo URL for the DEX. */
logoUrl?: string
/** Optional color for branding the DEX. */
color?: string
/** Default input/output token pairs used on the DEX. */
defaultPairs?: {
/** The address of the input token. */
inputAddress: Address
/** The address of the output token. */
outputAddress: Address
}
}
// ------------------------
// Dex Settings
// ------------------------
/**
* Settings related to gas for the trade.
*/
export type GasSettings = {
/** Must return the gas price in GWEI. */
getGasPrice: () => Promise<string>
}
export type ProtocolSettings = {
[keyof in DexProtocol]?: {
enabled: boolean
includeVersions?: Version[]
excludeVersions?: Version[]
}
}
/**
* Configuration settings for DEX operations.
*/
export type DexSettings = {
/**
* The address that will receive the output tokens or LP tokens.
* If not provided, the default is to send the output tokens to the address initiating the swap.
*
* @default ''
*/
recipient: Address
/**
* Slippage tolerance in percentage, e.g., 0.005 represents 0.5% slippage.
*
* @default 0.005
*/
slippage: number
/**
* The number of minutes before the transaction expires.
*
* @default 20
*/
deadlineMinutes: number
/**
* Disable multihops, forcing direct routes.
*
* @default false
*/
disableMultihops: boolean
/**
* Prevent the built-in block listener from observing changes.
*
* @default false
*/
disableObserver: boolean
/**
* Number of blocks to skip between each quote, reducing the number of calls to the node.
*
* @default 0
*/
observerBlockSkip: number
/**
* Filter to choose which DEX versions to use. Defaults to all.
*
* @default All protocols of targeted DEXs
*/
protocolSettings: ProtocolSettings
/**
* Gas price settings, where the `getGasPrice` function returns the gas price in GWEI.
*
* @default undefined
*/
gasSettings?: GasSettings
/**
* Whether to approve the the maximum token amount, or the exact token amount.
*
* @default true
*/
approveMax?: boolean
/**
* Multiplier for the token approval amount to add a buffer.
* Only applies when `approveMax` is false.
* For example, a value of 1.05 represents a 5% buffer.
*
* @default 1.05
*/
approvalBufferFactor?: number
}
// ------------------------
// Dex Factory Args
// ------------------------
/**
* Represents the base arguments required for the DexFactory.
*/
export type DexFactoryBaseArgs<TFormat extends TradeFormat = 'readable'> = {
/** The wallet address of the user initiating the liquidity operation. */
walletAddress: Address
/** The context of the DEX (Decentralized Exchange) where the operation is performed. */
dexContext: DexContext
/** (Optional) The price context for multiple tokens. */
multiPriceContext?: MultiPriceContext
/** (Optional) The context of the token list to be used. Provide an empty array to disable the token list. */
tokenListContext?: TokenListContext
/**
* The format in which the liquidity context's number values will be returned.
* Defaults to { type: `readable`, options: { locales: 'en' }}
*
* - `'readable'`: Returns a human-readable string with grouping (thousands separators) and specified decimal places (e.g., "1,234.567").
* - `'decimal'`: Outputs a precise decimal string representation without grouping, maintaining the decimal places specified (e.g., "1234.567").
* - `'wei'`: Outputs the value in its smallest unit, suitable for precise blockchain interactions (e.g., "1000000000000000000" for 1 Ether).
* - `'hex'`: Returns a hexadecimal string representation, useful for encoding values in blockchain transactions (e.g., "0x158e460913d000000000").
* - `'dexnumber'`: Returns the current instance as a `DexNumber` object.
* - `'bignumber'`: Returns an instance of `BigNumber` from `bignumber.js`.
* - `'ethers'`: Returns a `BigNumber` instance from `ethers.js`.
* - `'bigint'`: Converts and returns the value as a native JavaScript `BigInt`.
*/
format?: TradeFormatOptions<TFormat>
}
/**
* Public arguments used to initialize a Dex Factory.
*/
export type DexArgs<TFormat extends TradeFormat = 'readable'> =
DexFactoryBaseArgs<TFormat> & { providerContext: DexMulticallProviderContext }