@lifi/sdk 4.0.0-alpha.1 → 4.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/LICENSE +201 -165
  2. package/dist/cjs/version.d.ts +1 -1
  3. package/dist/cjs/version.js +1 -1
  4. package/dist/esm/version.d.ts +1 -1
  5. package/dist/esm/version.js +1 -1
  6. package/dist/types/version.d.ts +1 -1
  7. package/package.json +16 -1
  8. package/src/version.ts +1 -1
  9. package/CHANGELOG.md +0 -1272
  10. package/package.json.tmp +0 -103
  11. package/src/actions/actions.unit.handlers.ts +0 -78
  12. package/src/actions/getChains.unit.spec.ts +0 -19
  13. package/src/actions/getConnections.unit.spec.ts +0 -45
  14. package/src/actions/getContractCallsQuote.unit.spec.ts +0 -323
  15. package/src/actions/getGasRecommendation.unit.spec.ts +0 -40
  16. package/src/actions/getNameServiceAddress.unit.spec.ts +0 -169
  17. package/src/actions/getQuote.int.spec.ts +0 -18
  18. package/src/actions/getQuote.unit.spec.ts +0 -154
  19. package/src/actions/getRelayedTransactionStatus.unit.spec.ts +0 -243
  20. package/src/actions/getRelayerQuote.unit.spec.ts +0 -220
  21. package/src/actions/getRoutes.unit.spec.ts +0 -112
  22. package/src/actions/getStatus.unit.spec.ts +0 -53
  23. package/src/actions/getStepTransaction.unit.spec.ts +0 -140
  24. package/src/actions/getToken.unit.spec.ts +0 -45
  25. package/src/actions/getTokenBalance.unit.spec.ts +0 -61
  26. package/src/actions/getTokenBalances.unit.spec.ts +0 -68
  27. package/src/actions/getTokenBalancesByChain.unit.spec.ts +0 -108
  28. package/src/actions/getTokens.unit.spec.ts +0 -16
  29. package/src/actions/getTools.unit.spec.ts +0 -20
  30. package/src/actions/getTransactionHistory.unit.spec.ts +0 -36
  31. package/src/actions/getWalletBalances.unit.spec.ts +0 -90
  32. package/src/actions/relayTransaction.unit.spec.ts +0 -229
  33. package/src/client/createClient.unit.spec.ts +0 -274
  34. package/src/client/getClientStorage.unit.spec.ts +0 -382
  35. package/src/core/StatusManager.unit.spec.ts +0 -298
  36. package/src/core/execution.unit.handlers.ts +0 -32
  37. package/src/core/execution.unit.mock.ts +0 -252
  38. package/src/core/execution.unit.spec.ts +0 -86
  39. package/src/core/stepComparison.unit.spec.ts +0 -89
  40. package/src/errors/SDKError.unit.spec.ts +0 -160
  41. package/src/errors/baseError.unit.spec.ts +0 -22
  42. package/src/errors/httpError.unit.spec.ts +0 -125
  43. package/src/errors/utils/baseErrorRootCause.unit.spec.ts +0 -89
  44. package/src/errors/utils/rootCause.unit.spec.ts +0 -36
  45. package/src/utils/checkPackageUpdates.unit.spec.ts +0 -71
  46. package/src/utils/convertQuoteToRoute.unit.spec.ts +0 -56
  47. package/src/utils/fetchTxErrorDetails.unit.spec.ts +0 -42
  48. package/src/utils/getTransactionMessage.unit.spec.ts +0 -38
  49. package/src/utils/isRoutesRequest.unit.spec.ts +0 -46
  50. package/src/utils/isStep.unit.spec.ts +0 -55
  51. package/src/utils/isToken.unit.spec.ts +0 -49
  52. package/src/utils/request.unit.spec.ts +0 -159
  53. package/src/utils/sleep.unit.spec.ts +0 -17
  54. package/src/utils/waitForResult.unit.spec.ts +0 -75
  55. package/src/utils/withDedupe.unit.spec.ts +0 -26
  56. package/tsconfig.json +0 -18
@@ -1,298 +0,0 @@
1
- import type { Route } from '@lifi/types'
2
- import type { Mock } from 'vitest'
3
- import { beforeEach, describe, expect, it, vi } from 'vitest'
4
- import type {
5
- ExecutionStatus,
6
- LiFiStepExtended,
7
- ProcessStatus,
8
- } from '../types/core.js'
9
- import {
10
- buildRouteObject,
11
- buildStepObject,
12
- SOME_DATE,
13
- } from './execution.unit.mock.js'
14
- import { executionState } from './executionState.js'
15
- import { StatusManager } from './StatusManager.js'
16
-
17
- // Note: using structuredClone when passing objects to the StatusManager shall make sure that we are not facing any unknown call-by-reference-issues anymore
18
-
19
- describe('StatusManager', () => {
20
- let statusManager: StatusManager
21
- let updateRouteHookMock: Mock
22
- let route: Route
23
- let step: LiFiStepExtended
24
-
25
- const expectCallbacksToHaveBeenCalledWith = (route: Route) => {
26
- expect(updateRouteHookMock).toHaveBeenCalledWith(route)
27
- }
28
-
29
- const initializeStatusManager = ({
30
- includingExecution,
31
- }: {
32
- includingExecution: boolean
33
- }): StatusManager => {
34
- step = buildStepObject({ includingExecution })
35
- route = buildRouteObject({ step })
36
-
37
- executionState.create({
38
- route,
39
- executionOptions: {
40
- updateRouteHook: updateRouteHookMock,
41
- },
42
- })
43
-
44
- return new StatusManager(route.id)
45
- }
46
-
47
- beforeEach(() => {
48
- updateRouteHookMock = vi.fn()
49
- vi.spyOn(Date, 'now').mockImplementation(() => SOME_DATE)
50
- })
51
-
52
- describe('initExecutionObject', () => {
53
- describe('when no execution is defined yet', () => {
54
- beforeEach(() => {
55
- statusManager = initializeStatusManager({ includingExecution: false })
56
- statusManager.initExecutionObject(step)
57
- })
58
-
59
- it('should create an empty execution & call the callbacks with the updated route', () => {
60
- const updatedStep = Object.assign({}, step, {
61
- execution: {
62
- status: 'PENDING',
63
- process: [],
64
- startedAt: SOME_DATE,
65
- },
66
- })
67
-
68
- const updatedRoute = Object.assign({}, route, {
69
- steps: [updatedStep],
70
- })
71
-
72
- expectCallbacksToHaveBeenCalledWith(updatedRoute)
73
- })
74
- })
75
-
76
- describe('when an execution is already defined', () => {
77
- beforeEach(() => {
78
- statusManager = initializeStatusManager({ includingExecution: true })
79
- statusManager.initExecutionObject(structuredClone(step))
80
- })
81
-
82
- it('should not call the callbacks', () => {
83
- expect(updateRouteHookMock).not.toHaveBeenCalled()
84
- })
85
- })
86
- })
87
-
88
- describe('updateExecution', () => {
89
- beforeEach(() => {
90
- vi.spyOn(Date, 'now').mockImplementation(() => SOME_DATE + 10)
91
- })
92
- describe('when no execution is defined yet', () => {
93
- beforeEach(() => {
94
- statusManager = initializeStatusManager({ includingExecution: false })
95
- })
96
-
97
- it('should throw an error', () => {
98
- // function has to be wrapped into a function https://jestjs.io/docs/expect#tothrowerror
99
- expect(() =>
100
- statusManager.updateExecution(structuredClone(step), 'DONE')
101
- ).toThrow("Can't update empty execution.")
102
- })
103
- })
104
-
105
- describe('when an execution is defined', () => {
106
- beforeEach(() => {
107
- statusManager = initializeStatusManager({ includingExecution: true })
108
- statusManager.updateExecution(structuredClone(step), 'DONE', {
109
- fromAmount: '123',
110
- toAmount: '312',
111
- })
112
- })
113
-
114
- it('should update the execution & call the callbacks with the updated route', () => {
115
- const updatedExecution = Object.assign({}, step.execution, {
116
- fromAmount: '123',
117
- toAmount: '312',
118
- status: 'DONE',
119
- })
120
-
121
- const updatedStep = Object.assign({}, step, {
122
- execution: updatedExecution,
123
- })
124
-
125
- const updatedRoute = Object.assign({}, route, {
126
- steps: [updatedStep],
127
- })
128
-
129
- expectCallbacksToHaveBeenCalledWith(updatedRoute)
130
- })
131
- })
132
- })
133
-
134
- describe('findOrCreateProcess', () => {
135
- describe('when no execution is defined yet', () => {
136
- beforeEach(() => {
137
- statusManager = initializeStatusManager({ includingExecution: false })
138
- })
139
-
140
- it('should throw an error', () => {
141
- expect(() =>
142
- statusManager.findOrCreateProcess({
143
- step: structuredClone(step),
144
- type: 'SWAP',
145
- })
146
- ).toThrow("Execution hasn't been initialized.")
147
- })
148
- })
149
-
150
- describe('when an execution is defined', () => {
151
- beforeEach(() => {
152
- statusManager = initializeStatusManager({ includingExecution: true })
153
- })
154
-
155
- describe('and the process already exists', () => {
156
- it('should return the process and not call the callbacks', () => {
157
- const process = statusManager.findOrCreateProcess({
158
- step: structuredClone(step),
159
- type: 'TOKEN_ALLOWANCE',
160
- })
161
-
162
- expect(process).toEqual(step.execution?.process[0])
163
-
164
- expect(updateRouteHookMock).not.toHaveBeenCalled()
165
- })
166
- })
167
-
168
- describe("and the process doesn't exist", () => {
169
- it('should create a process and call the callbacks with the updated route', () => {
170
- const process = statusManager.findOrCreateProcess({
171
- step: structuredClone(step),
172
- type: 'CROSS_CHAIN',
173
- })
174
-
175
- expect(process.type).toEqual('CROSS_CHAIN')
176
- expect(process.status).toEqual('STARTED')
177
- expect(process.message).toEqual('Preparing bridge transaction')
178
-
179
- const updatedExecution = Object.assign({}, step.execution, {
180
- process: [...step.execution!.process, process],
181
- })
182
-
183
- const updatedStep = Object.assign({}, step, {
184
- execution: updatedExecution,
185
- })
186
-
187
- const updatedRoute = Object.assign({}, route, {
188
- steps: [updatedStep],
189
- })
190
-
191
- expectCallbacksToHaveBeenCalledWith(updatedRoute)
192
- })
193
- })
194
- })
195
- })
196
-
197
- describe('updateProcess', () => {
198
- beforeEach(() => {
199
- statusManager = initializeStatusManager({ includingExecution: true })
200
- })
201
-
202
- describe('when no process can be found', () => {
203
- it('should throw an error', () => {
204
- expect(() =>
205
- statusManager.updateProcess(
206
- structuredClone(step),
207
- 'CROSS_CHAIN',
208
- 'CANCELLED'
209
- )
210
- ).toThrow("Can't find a process for the given type.")
211
- })
212
- })
213
-
214
- describe('when a process is found', () => {
215
- const statuses = [
216
- { status: 'ACTION_REQUIRED' },
217
- { status: 'PENDING' },
218
- { status: 'FAILED', doneAt: true },
219
- { status: 'DONE', doneAt: true },
220
- { status: 'CANCELLED', doneAt: true },
221
- ]
222
- for (const { status, doneAt } of statuses) {
223
- describe(`and the status is ${status}`, () => {
224
- it('should update the process and call the callbacks', () => {
225
- const process = statusManager.updateProcess(
226
- structuredClone(step),
227
- 'SWAP',
228
- status as ProcessStatus
229
- )
230
-
231
- expect(process.type).toEqual('SWAP')
232
- expect(process.status).toEqual(status)
233
- // expect(process.message).toEqual(
234
- // getProcessMessage('SWAP', status as Status)
235
- // )
236
- doneAt
237
- ? expect(process.doneAt).toBeDefined()
238
- : expect(process.doneAt).toBeUndefined()
239
-
240
- const notUpdateableStatus =
241
- status === 'DONE' || status === 'CANCELLED'
242
- const updatedExecution = Object.assign({}, step.execution, {
243
- process: [step.execution!.process[0], process],
244
- status: notUpdateableStatus
245
- ? step.execution!.status
246
- : (status as ExecutionStatus),
247
- })
248
-
249
- const updatedStep = { ...step, execution: updatedExecution }
250
-
251
- const updatedRoute = Object.assign({}, route, {
252
- steps: [updatedStep],
253
- })
254
-
255
- expectCallbacksToHaveBeenCalledWith(updatedRoute)
256
- })
257
- })
258
- }
259
- })
260
- })
261
-
262
- describe('removeProcess', () => {
263
- describe('when no execution is defined yet', () => {
264
- beforeEach(() => {
265
- statusManager = initializeStatusManager({ includingExecution: false })
266
- })
267
-
268
- it('should throw an error', () => {
269
- expect(() =>
270
- statusManager.removeProcess(structuredClone(step), 'TOKEN_ALLOWANCE')
271
- ).toThrow("Execution hasn't been initialized.")
272
- })
273
- })
274
-
275
- describe('when an execution is defined', () => {
276
- beforeEach(() => {
277
- statusManager = initializeStatusManager({ includingExecution: true })
278
- statusManager.removeProcess(structuredClone(step), 'TOKEN_ALLOWANCE')
279
- })
280
-
281
- it('should remove the process and call the callbacks', () => {
282
- const updatedExecution = Object.assign({}, step.execution, {
283
- process: [step.execution!.process[1]],
284
- })
285
-
286
- const updatedStep = Object.assign({}, step, {
287
- execution: updatedExecution,
288
- })
289
-
290
- const updatedRoute = Object.assign({}, route, {
291
- steps: [updatedStep],
292
- })
293
-
294
- expectCallbacksToHaveBeenCalledWith(updatedRoute)
295
- })
296
- })
297
- })
298
- })
@@ -1,32 +0,0 @@
1
- import { HttpResponse, http } from 'msw'
2
- import { createClient } from '../client/createClient.js'
3
- import {
4
- buildStepObject,
5
- mockChainsResponse,
6
- mockStatus,
7
- mockStepTransactionWithTxRequest,
8
- } from './execution.unit.mock.js'
9
-
10
- const client = createClient({
11
- integrator: 'lifi-sdk',
12
- })
13
-
14
- export const lifiHandlers = [
15
- http.post(`${client.config.apiUrl}/advanced/stepTransaction`, async () =>
16
- HttpResponse.json(
17
- mockStepTransactionWithTxRequest(
18
- buildStepObject({
19
- includingExecution: true,
20
- })
21
- )
22
- )
23
- ),
24
- http.get(`${client.config.apiUrl}/chains`, async () =>
25
- HttpResponse.json({
26
- chains: mockChainsResponse,
27
- })
28
- ),
29
- http.get(`${client.config.apiUrl}/status`, async () =>
30
- HttpResponse.json(mockStatus)
31
- ),
32
- ]
@@ -1,252 +0,0 @@
1
- import { findDefaultToken } from '@lifi/data-types'
2
- import type { LiFiStep, Route, Token } from '@lifi/types'
3
- import { ChainId, CoinKey } from '@lifi/types'
4
- import type { LiFiStepExtended } from '../types/core.js'
5
-
6
- const SOME_TOKEN: Token = {
7
- ...findDefaultToken(CoinKey.USDC, ChainId.DAI),
8
- priceUSD: '',
9
- }
10
- const SOME_OTHER_TOKEN: Token = {
11
- ...findDefaultToken(CoinKey.USDT, ChainId.DAI),
12
- priceUSD: '',
13
- }
14
-
15
- export const SOME_DATE = new Date('2021-04-10').getTime()
16
-
17
- export const mockChainsResponse = [
18
- {
19
- key: 'pol',
20
- chainType: 'EVM',
21
- name: 'Polygon',
22
- coin: 'MATIC',
23
- id: 137,
24
- mainnet: true,
25
- logoURI:
26
- 'https://raw.githubusercontent.com/lifinance/types/main/src/assets/icons/chains/polygon.svg',
27
- tokenlistUrl:
28
- 'https://unpkg.com/quickswap-default-token-list@1.0.71/build/quickswap-default.tokenlist.json',
29
- faucetUrls: ['https://stakely.io/faucet/polygon-matic'],
30
- multicallAddress: '0xcA11bde05977b3631167028862bE2a173976CA11',
31
- metamask: {
32
- chainId: '0x89',
33
- blockExplorerUrls: [
34
- 'https://polygonscan.com/',
35
- 'https://explorer-mainnet.maticvigil.com/',
36
- ],
37
- chainName: 'Matic(Polygon) Mainnet',
38
- nativeCurrency: {
39
- name: 'MATIC',
40
- symbol: 'MATIC',
41
- decimals: 18,
42
- },
43
- rpcUrls: [
44
- 'https://polygon-rpc.com/',
45
- 'https://rpc-mainnet.maticvigil.com/',
46
- ],
47
- },
48
- nativeToken: {
49
- address: '0x0000000000000000000000000000000000000000',
50
- chainId: 137,
51
- symbol: 'MATIC',
52
- decimals: 18,
53
- name: 'MATIC',
54
- priceUSD: '0.899628',
55
- logoURI:
56
- 'https://static.debank.com/image/matic_token/logo_url/matic/6f5a6b6f0732a7a235131bd7804d357c.png',
57
- coinKey: 'MATIC',
58
- },
59
- },
60
- ]
61
-
62
- const mockTransactionRequest = {
63
- transactionRequest: {
64
- data: '0xdata',
65
- to: '0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE',
66
- value: '0x0600830dbc7f5bf7',
67
- from: '0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0',
68
- chainId: 137,
69
- gasPrice: '0x27c01c1727',
70
- gasLimit: '682701',
71
- },
72
- }
73
-
74
- export const mockStatus = {
75
- status: 'DONE',
76
- receiving: true,
77
- sending: {
78
- amount: '123',
79
- gasAmount: '123',
80
- gasAmountUSD: '123',
81
- gasPrice: '123',
82
- gasToken: '123',
83
- gasUsed: '123',
84
- },
85
- }
86
-
87
- export const mockStepTransactionWithTxRequest = (
88
- step: LiFiStep = buildStepObject({
89
- includingExecution: false,
90
- })
91
- ) => ({
92
- ...step,
93
- transactionRequest: mockTransactionRequest,
94
- })
95
-
96
- export const buildStepObject = ({
97
- includingExecution = true,
98
- }: {
99
- includingExecution?: boolean
100
- }): LiFiStepExtended => ({
101
- id: '8d3a0474-4ee3-4a7a-90c7-2a2264b7f3a9',
102
- type: 'lifi',
103
- tool: '1inch',
104
- toolDetails: {
105
- key: '1inch',
106
- name: '1inch',
107
- logoURI:
108
- 'https://raw.githubusercontent.com/lifinance/types/main/src/assets/icons/exchanges/oneinch.png',
109
- },
110
- action: {
111
- fromChainId: 137,
112
- toChainId: 137,
113
- fromToken: SOME_TOKEN,
114
- toToken: SOME_OTHER_TOKEN,
115
- fromAmount: '1500000',
116
- slippage: 0.03,
117
- fromAddress: '0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0',
118
- toAddress: '0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0',
119
- },
120
- estimate: {
121
- fromAmount: '1000000',
122
- fromAmountUSD: '100',
123
- toAmount: '260982615655554',
124
- toAmountUSD: '26098',
125
- toAmountMin: '253153137185887',
126
- approvalAddress: '0x11111112542d85b3ef69ae05771c2dccff4faa26',
127
- executionDuration: 300,
128
- tool: '1inch',
129
- },
130
- includedSteps: [
131
- {
132
- id: 'f8474598-a553-4643-bbd1-bf8c77e679b3',
133
- type: 'swap',
134
- action: {
135
- fromChainId: 137,
136
- fromAmount: '5000000000000000000',
137
- fromToken: {
138
- address: '0x0000000000000000000000000000000000000000',
139
- chainId: 137,
140
- symbol: 'MATIC',
141
- decimals: 18,
142
- name: 'MATIC',
143
- priceUSD: '1.124763',
144
- logoURI:
145
- 'https://static.debank.com/image/matic_token/logo_url/matic/6f5a6b6f0732a7a235131bd7804d357c.png',
146
- coinKey: CoinKey.MATIC,
147
- },
148
- toChainId: 137,
149
- toToken: {
150
- address: '0xc2132d05d31c914a87c6611c10748aeb04b58e8f',
151
- chainId: 137,
152
- symbol: 'USDT',
153
- decimals: 6,
154
- name: '(PoS) Tether USD',
155
- priceUSD: '1.00081',
156
- logoURI:
157
- 'https://static.debank.com/image/coin/logo_url/usdt/23af7472292cb41dc39b3f1146ead0fe.png',
158
- coinKey: CoinKey.USDT,
159
- },
160
- slippage: 0.005,
161
- },
162
- estimate: {
163
- tool: '1inch',
164
- fromAmount: '5000000000000000000',
165
- toAmount: '5617317',
166
- toAmountMin: '5589230',
167
- approvalAddress: '0x1111111254eeb25477b68fb85ed929f73a960582',
168
- executionDuration: 30,
169
- feeCosts: [],
170
- gasCosts: [
171
- {
172
- type: 'SEND',
173
- price: '149725515512',
174
- estimate: '258059',
175
- limit: '344079',
176
- amount: '51517405651853448',
177
- amountUSD: '0.06',
178
- token: {
179
- address: '0x0000000000000000000000000000000000000000',
180
- chainId: 137,
181
- symbol: 'MATIC',
182
- decimals: 18,
183
- name: 'MATIC',
184
- priceUSD: '1.124763',
185
- logoURI:
186
- 'https://static.debank.com/image/matic_token/logo_url/matic/6f5a6b6f0732a7a235131bd7804d357c.png',
187
- coinKey: CoinKey.MATIC,
188
- },
189
- },
190
- ],
191
- },
192
- tool: '1inch',
193
- toolDetails: {
194
- key: '1inch',
195
- name: '1inch',
196
- logoURI:
197
- 'https://raw.githubusercontent.com/lifinance/types/main/src/assets/icons/exchanges/oneinch.png',
198
- },
199
- },
200
- ],
201
- execution: includingExecution
202
- ? {
203
- status: 'PENDING',
204
- startedAt: SOME_DATE,
205
- doneAt: SOME_DATE + 10,
206
- process: [
207
- {
208
- type: 'TOKEN_ALLOWANCE',
209
- startedAt: SOME_DATE,
210
- message: 'Somethings done',
211
- status: 'DONE',
212
- doneAt: SOME_DATE + 10,
213
- txHash: '0x11111112542d85b3ef69ae05771c2dccff4faa26',
214
- txLink: 'https://example.com',
215
- },
216
- {
217
- type: 'SWAP',
218
- startedAt: SOME_DATE + 20,
219
- message: 'Somethings pending',
220
- status: 'PENDING',
221
- },
222
- ],
223
- fromAmount: '1000000',
224
- toAmount: '261490494702370',
225
- }
226
- : undefined,
227
- })
228
-
229
- export const buildRouteObject = ({
230
- step = buildStepObject({}),
231
- }: {
232
- step?: LiFiStep
233
- }): Route => ({
234
- id: '0x433df53dbf6dbd7b946fc4f3b501c3ff32957d77d96c9d5ba1805b01eb6461cc',
235
- fromChainId: 137,
236
- fromAmountUSD: '1.00',
237
- fromAmount: '1000000',
238
- fromToken: SOME_TOKEN,
239
- fromAddress: '0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0',
240
- toChainId: 137,
241
- toAmountUSD: '1.00',
242
- toAmount: '260982615655554',
243
- toAmountMin: '253153137185887',
244
- toToken: SOME_OTHER_TOKEN,
245
- toAddress: '0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0',
246
- gasCostUSD: '0.01',
247
- steps: [step],
248
- insurance: {
249
- feeAmountUsd: '0',
250
- state: 'NOT_INSURABLE',
251
- },
252
- })
@@ -1,86 +0,0 @@
1
- import { setupServer } from 'msw/node'
2
- import type { Client } from 'viem'
3
- import { sendTransaction } from 'viem/actions'
4
- import {
5
- afterAll,
6
- afterEach,
7
- beforeAll,
8
- beforeEach,
9
- describe,
10
- expect,
11
- it,
12
- vi,
13
- } from 'vitest'
14
- import { createClient } from '../client/createClient.js'
15
- import { requestSettings } from '../utils/request.js'
16
- import { executeRoute } from './execution.js'
17
- import { lifiHandlers } from './execution.unit.handlers.js'
18
- import { buildRouteObject, buildStepObject } from './execution.unit.mock.js'
19
-
20
- const client = createClient({
21
- integrator: 'lifi-sdk',
22
- })
23
-
24
- let viemClient: Partial<Client>
25
-
26
- vi.mock('../balance', () => ({
27
- checkBalance: vi.fn(() => Promise.resolve([])),
28
- }))
29
-
30
- vi.mock('../execution/switchChain', () => ({
31
- switchChain: vi.fn(() => Promise.resolve(viemClient)),
32
- }))
33
-
34
- vi.mock('../allowance/getAllowance', () => ({
35
- getAllowance: vi.fn(() => Promise.resolve(1500000n)),
36
- }))
37
-
38
- const step = buildStepObject({
39
- includingExecution: true,
40
- })
41
-
42
- describe.skip('Should pick up gas from wallet client estimation', () => {
43
- const server = setupServer(...lifiHandlers)
44
-
45
- beforeAll(() => server.listen({ onUnhandledRequest: 'error' }))
46
-
47
- beforeEach(() => {
48
- requestSettings.retries = 0
49
- vi.clearAllMocks()
50
-
51
- viemClient = {
52
- sendTransaction: () => Promise.resolve('0xabc'),
53
- getChainId: () => Promise.resolve(137),
54
- getAddresses: () =>
55
- Promise.resolve(['0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0']),
56
- } as Partial<Client>
57
- })
58
-
59
- afterEach(() => server.resetHandlers())
60
- afterAll(() => {
61
- server.close()
62
- })
63
-
64
- it('should pick up gas limit + price estimation from wallet client', async () => {
65
- const route = buildRouteObject({
66
- step,
67
- })
68
-
69
- await executeRoute(client, route)
70
-
71
- expect(sendTransaction).toHaveBeenCalledWith(viemClient, {
72
- gasLimit: 125000n,
73
- gasPrice: 100000n,
74
- // TODO: Check the cause for gasLimit being outside transactionRequest. Currently working as expected in widget
75
- transactionRequest: {
76
- chainId: 137,
77
- data: '0xdata',
78
- from: '0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0',
79
- gasLimit: '682701',
80
- gasPrice: '0x27c01c1727',
81
- to: '0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE',
82
- value: '0x0600830dbc7f5bf7',
83
- },
84
- })
85
- })
86
- })