@lifi/sdk 3.11.4 → 3.12.1

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 (50) hide show
  1. package/package.json +5 -5
  2. package/src/_cjs/core/EVM/EVMStepExecutor.js +24 -14
  3. package/src/_cjs/core/EVM/EVMStepExecutor.js.map +1 -1
  4. package/src/_cjs/core/EVM/parseEVMErrors.js +2 -1
  5. package/src/_cjs/core/EVM/parseEVMErrors.js.map +1 -1
  6. package/src/_cjs/core/EVM/typeguards.js +3 -2
  7. package/src/_cjs/core/EVM/typeguards.js.map +1 -1
  8. package/src/_cjs/core/EVM/uns/constants.js +2 -0
  9. package/src/_cjs/core/EVM/uns/constants.js.map +1 -1
  10. package/src/_cjs/core/EVM/uns/resolveUNSAddress.js +6 -6
  11. package/src/_cjs/core/EVM/waitForBatchTransactionReceipt.js +11 -9
  12. package/src/_cjs/core/EVM/waitForBatchTransactionReceipt.js.map +1 -1
  13. package/src/_cjs/services/api.js +13 -6
  14. package/src/_cjs/services/api.js.map +1 -1
  15. package/src/_cjs/version.js +1 -1
  16. package/src/_esm/core/EVM/EVMStepExecutor.js +28 -18
  17. package/src/_esm/core/EVM/EVMStepExecutor.js.map +1 -1
  18. package/src/_esm/core/EVM/parseEVMErrors.js +21 -12
  19. package/src/_esm/core/EVM/parseEVMErrors.js.map +1 -1
  20. package/src/_esm/core/EVM/typeguards.js +3 -2
  21. package/src/_esm/core/EVM/typeguards.js.map +1 -1
  22. package/src/_esm/core/EVM/uns/constants.js +2 -0
  23. package/src/_esm/core/EVM/uns/constants.js.map +1 -1
  24. package/src/_esm/core/EVM/uns/resolveUNSAddress.js +6 -6
  25. package/src/_esm/core/EVM/waitForBatchTransactionReceipt.js +11 -10
  26. package/src/_esm/core/EVM/waitForBatchTransactionReceipt.js.map +1 -1
  27. package/src/_esm/services/api.js +11 -11
  28. package/src/_esm/services/api.js.map +1 -1
  29. package/src/_esm/version.js +1 -1
  30. package/src/_types/core/EVM/EVMStepExecutor.d.ts.map +1 -1
  31. package/src/_types/core/EVM/parseEVMErrors.d.ts.map +1 -1
  32. package/src/_types/core/EVM/typeguards.d.ts +2 -2
  33. package/src/_types/core/EVM/typeguards.d.ts.map +1 -1
  34. package/src/_types/core/EVM/uns/constants.d.ts.map +1 -1
  35. package/src/_types/core/EVM/waitForBatchTransactionReceipt.d.ts +2 -1
  36. package/src/_types/core/EVM/waitForBatchTransactionReceipt.d.ts.map +1 -1
  37. package/src/_types/services/api.d.ts +5 -4
  38. package/src/_types/services/api.d.ts.map +1 -1
  39. package/src/_types/services/types.d.ts +6 -1
  40. package/src/_types/services/types.d.ts.map +1 -1
  41. package/src/_types/version.d.ts +1 -1
  42. package/src/core/EVM/EVMStepExecutor.ts +42 -27
  43. package/src/core/EVM/parseEVMErrors.ts +21 -12
  44. package/src/core/EVM/typeguards.ts +10 -4
  45. package/src/core/EVM/uns/constants.ts +2 -0
  46. package/src/core/EVM/uns/resolveUNSAddress.ts +6 -6
  47. package/src/core/EVM/waitForBatchTransactionReceipt.ts +13 -13
  48. package/src/services/api.ts +41 -8
  49. package/src/services/types.ts +12 -1
  50. package/src/version.ts +1 -1
@@ -29,14 +29,14 @@ export const resolveUNSAddress = async (
29
29
  // handle token based resolution
30
30
  if (chain) {
31
31
  const family = CHAIN_TYPE_FAMILY_MAP[chainType]
32
- const unschain = CHAIN_ID_UNS_CHAIN_MAP[chain]
32
+ const unsChain = CHAIN_ID_UNS_CHAIN_MAP[chain]
33
33
 
34
34
  if (family) {
35
35
  if (token) {
36
- keys.push(`token.${family}.${unschain}.${token}.address`)
36
+ keys.push(`token.${family}.${unsChain}.${token}.address`)
37
37
  }
38
- if (unschain) {
39
- keys.push(`token.${family}.${unschain}.address`)
38
+ if (unsChain) {
39
+ keys.push(`token.${family}.${unsChain}.address`)
40
40
  }
41
41
 
42
42
  keys.push(`token.${family}.address`)
@@ -44,8 +44,8 @@ export const resolveUNSAddress = async (
44
44
  }
45
45
 
46
46
  // fallback to chain based resolution
47
- const unschainType = CHAIN_TYPE_UNS_CHAIN_MAP[chainType]
48
- keys.push(`crypto.${unschainType}.address`)
47
+ const unsChainType = CHAIN_TYPE_UNS_CHAIN_MAP[chainType]
48
+ keys.push(`crypto.${unsChainType}.address`)
49
49
 
50
50
  for (const key of keys) {
51
51
  const address =
@@ -1,5 +1,5 @@
1
1
  import type { Client, Hash } from 'viem'
2
- import { waitForCallsStatus } from 'viem/actions'
2
+ import { type GetCallsStatusReturnType, waitForCallsStatus } from 'viem/actions'
3
3
  import { getAction } from 'viem/utils'
4
4
  import { LiFiErrorCode } from '../../errors/constants.js'
5
5
  import { TransactionError } from '../../errors/errors.js'
@@ -7,9 +7,10 @@ import type { WalletCallReceipt } from './types.js'
7
7
 
8
8
  export const waitForBatchTransactionReceipt = async (
9
9
  client: Client,
10
- batchHash: Hash
10
+ batchHash: Hash,
11
+ onFailed?: (result: GetCallsStatusReturnType) => void
11
12
  ): Promise<WalletCallReceipt> => {
12
- const { receipts, status, statusCode } = await getAction(
13
+ const result = await getAction(
13
14
  client,
14
15
  waitForCallsStatus,
15
16
  'waitForCallsStatus'
@@ -18,30 +19,29 @@ export const waitForBatchTransactionReceipt = async (
18
19
  timeout: 3_600_000 * 24,
19
20
  })
20
21
 
21
- if (
22
- status === 'success' ||
23
- // @ts-expect-error: for backwards compatibility
24
- status === 'CONFIRMED'
25
- ) {
22
+ if (result.status === 'success') {
26
23
  if (
27
- !receipts?.length ||
28
- !receipts.every((receipt) => receipt.transactionHash) ||
29
- receipts.some((receipt) => receipt.status === 'reverted')
24
+ !result.receipts?.length ||
25
+ !result.receipts.every((receipt) => receipt.transactionHash) ||
26
+ result.receipts.some((receipt) => receipt.status === 'reverted')
30
27
  ) {
28
+ onFailed?.(result)
31
29
  throw new TransactionError(
32
30
  LiFiErrorCode.TransactionFailed,
33
31
  'Transaction was reverted.'
34
32
  )
35
33
  }
36
- const transactionReceipt = receipts.at(-1)!
34
+ const transactionReceipt = result.receipts.at(-1)!
37
35
  return transactionReceipt
38
36
  }
39
- if (statusCode >= 400 && statusCode < 500) {
37
+ if (result.statusCode >= 400 && result.statusCode < 500) {
38
+ onFailed?.(result)
40
39
  throw new TransactionError(
41
40
  LiFiErrorCode.TransactionCanceled,
42
41
  'Transaction was canceled.'
43
42
  )
44
43
  }
44
+ onFailed?.(result)
45
45
  throw new TransactionError(
46
46
  LiFiErrorCode.TransactionFailed,
47
47
  'Transaction failed.'
@@ -12,7 +12,6 @@ import {
12
12
  isContractCallsRequestWithFromAmount,
13
13
  isContractCallsRequestWithToAmount,
14
14
  type LiFiStep,
15
- type QuoteRequest,
16
15
  type RelayerQuoteResponse,
17
16
  type RelayRequest,
18
17
  type RelayResponse,
@@ -42,7 +41,12 @@ import { SDKError } from '../errors/SDKError.js'
42
41
  import { request } from '../request.js'
43
42
  import { isRoutesRequest, isStep } from '../typeguards.js'
44
43
  import { withDedupe } from '../utils/withDedupe.js'
45
- import type { GetStatusRequestExtended } from './types.js'
44
+ import type {
45
+ GetStatusRequestExtended,
46
+ QuoteRequest,
47
+ QuoteRequestFromAmount,
48
+ QuoteRequestToAmount,
49
+ } from './types.js'
46
50
 
47
51
  /**
48
52
  * Get a quote for a token transfer
@@ -51,18 +55,26 @@ import type { GetStatusRequestExtended } from './types.js'
51
55
  * @throws {LiFiError} - Throws a LiFiError if request fails
52
56
  * @returns Quote for a token transfer
53
57
  */
54
- export const getQuote = async (
58
+ export async function getQuote(
59
+ params: QuoteRequestFromAmount,
60
+ options?: RequestOptions
61
+ ): Promise<LiFiStep>
62
+ export async function getQuote(
63
+ params: QuoteRequestToAmount,
64
+ options?: RequestOptions
65
+ ): Promise<LiFiStep>
66
+ export async function getQuote(
55
67
  params: QuoteRequest,
56
68
  options?: RequestOptions
57
- ): Promise<LiFiStep> => {
69
+ ): Promise<LiFiStep> {
58
70
  const requiredParameters: Array<keyof QuoteRequest> = [
59
71
  'fromChain',
60
72
  'fromToken',
61
73
  'fromAddress',
62
- 'fromAmount',
63
74
  'toChain',
64
75
  'toToken',
65
76
  ]
77
+
66
78
  for (const requiredParameter of requiredParameters) {
67
79
  if (!params[requiredParameter]) {
68
80
  throw new SDKError(
@@ -72,6 +84,27 @@ export const getQuote = async (
72
84
  )
73
85
  }
74
86
  }
87
+
88
+ const isFromAmountRequest =
89
+ 'fromAmount' in params && params.fromAmount !== undefined
90
+ const isToAmountRequest =
91
+ 'toAmount' in params && params.toAmount !== undefined
92
+
93
+ if (!isFromAmountRequest && !isToAmountRequest) {
94
+ throw new SDKError(
95
+ new ValidationError(
96
+ 'Required parameter "fromAmount" or "toAmount" is missing.'
97
+ )
98
+ )
99
+ }
100
+
101
+ if (isFromAmountRequest && isToAmountRequest) {
102
+ throw new SDKError(
103
+ new ValidationError(
104
+ 'Cannot provide both "fromAmount" and "toAmount" parameters.'
105
+ )
106
+ )
107
+ }
75
108
  const _config = config.get()
76
109
  // apply defaults
77
110
  params.integrator ??= _config.integrator
@@ -93,7 +126,7 @@ export const getQuote = async (
93
126
  }
94
127
 
95
128
  return await request<LiFiStep>(
96
- `${_config.apiUrl}/quote?${new URLSearchParams(
129
+ `${_config.apiUrl}/${isFromAmountRequest ? 'quote' : 'quote/toAmount'}?${new URLSearchParams(
97
130
  params as unknown as Record<string, string>
98
131
  )}`,
99
132
  {
@@ -261,10 +294,10 @@ export const getStatus = async (
261
294
  * @returns Relayer quote for a token transfer
262
295
  */
263
296
  export const getRelayerQuote = async (
264
- params: QuoteRequest,
297
+ params: QuoteRequestFromAmount,
265
298
  options?: RequestOptions
266
299
  ): Promise<LiFiStep> => {
267
- const requiredParameters: Array<keyof QuoteRequest> = [
300
+ const requiredParameters: Array<keyof QuoteRequestFromAmount> = [
268
301
  'fromChain',
269
302
  'fromToken',
270
303
  'fromAddress',
@@ -1,5 +1,16 @@
1
- import type { GetStatusRequest } from '@lifi/types'
1
+ import type {
2
+ GetStatusRequest,
3
+ QuoteRequest as QuoteRequestBase,
4
+ } from '@lifi/types'
2
5
 
3
6
  export type GetStatusRequestExtended = GetStatusRequest & {
4
7
  fromAddress?: string
5
8
  }
9
+
10
+ export type QuoteRequestFromAmount = QuoteRequestBase
11
+
12
+ export type QuoteRequestToAmount = Omit<QuoteRequestBase, 'fromAmount'> & {
13
+ toAmount: string
14
+ }
15
+
16
+ export type QuoteRequest = QuoteRequestFromAmount | QuoteRequestToAmount
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/sdk'
2
- export const version = '3.11.4'
2
+ export const version = '3.12.1'