@lifi/sdk 3.11.3 → 3.12.0
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.
- package/package.json +3 -3
- package/src/_cjs/core/EVM/EVMStepExecutor.js +24 -14
- package/src/_cjs/core/EVM/EVMStepExecutor.js.map +1 -1
- package/src/_cjs/core/EVM/parseEVMErrors.js +2 -1
- package/src/_cjs/core/EVM/parseEVMErrors.js.map +1 -1
- package/src/_cjs/core/EVM/uns/constants.js +2 -0
- package/src/_cjs/core/EVM/uns/constants.js.map +1 -1
- package/src/_cjs/core/EVM/uns/resolveUNSAddress.js +6 -6
- package/src/_cjs/core/EVM/waitForBatchTransactionReceipt.js +11 -9
- package/src/_cjs/core/EVM/waitForBatchTransactionReceipt.js.map +1 -1
- package/src/_cjs/index.js +3 -2
- package/src/_cjs/index.js.map +1 -1
- package/src/_cjs/services/api.js +13 -6
- package/src/_cjs/services/api.js.map +1 -1
- package/src/_cjs/version.js +1 -1
- package/src/_esm/core/EVM/EVMStepExecutor.js +28 -18
- package/src/_esm/core/EVM/EVMStepExecutor.js.map +1 -1
- package/src/_esm/core/EVM/parseEVMErrors.js +21 -12
- package/src/_esm/core/EVM/parseEVMErrors.js.map +1 -1
- package/src/_esm/core/EVM/uns/constants.js +2 -0
- package/src/_esm/core/EVM/uns/constants.js.map +1 -1
- package/src/_esm/core/EVM/uns/resolveUNSAddress.js +6 -6
- package/src/_esm/core/EVM/waitForBatchTransactionReceipt.js +11 -10
- package/src/_esm/core/EVM/waitForBatchTransactionReceipt.js.map +1 -1
- package/src/_esm/index.js +1 -1
- package/src/_esm/index.js.map +1 -1
- package/src/_esm/services/api.js +11 -11
- package/src/_esm/services/api.js.map +1 -1
- package/src/_esm/version.js +1 -1
- package/src/_types/core/EVM/EVMStepExecutor.d.ts.map +1 -1
- package/src/_types/core/EVM/parseEVMErrors.d.ts.map +1 -1
- package/src/_types/core/EVM/uns/constants.d.ts.map +1 -1
- package/src/_types/core/EVM/waitForBatchTransactionReceipt.d.ts +2 -1
- package/src/_types/core/EVM/waitForBatchTransactionReceipt.d.ts.map +1 -1
- package/src/_types/index.d.ts +1 -1
- package/src/_types/index.d.ts.map +1 -1
- package/src/_types/services/api.d.ts +5 -4
- package/src/_types/services/api.d.ts.map +1 -1
- package/src/_types/services/types.d.ts +6 -1
- package/src/_types/services/types.d.ts.map +1 -1
- package/src/_types/version.d.ts +1 -1
- package/src/core/EVM/EVMStepExecutor.ts +42 -27
- package/src/core/EVM/parseEVMErrors.ts +21 -12
- package/src/core/EVM/uns/constants.ts +2 -0
- package/src/core/EVM/uns/resolveUNSAddress.ts +6 -6
- package/src/core/EVM/waitForBatchTransactionReceipt.ts +13 -13
- package/src/index.ts +1 -0
- package/src/services/api.ts +41 -8
- package/src/services/types.ts +12 -1
- 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
|
|
32
|
+
const unsChain = CHAIN_ID_UNS_CHAIN_MAP[chain]
|
|
33
33
|
|
|
34
34
|
if (family) {
|
|
35
35
|
if (token) {
|
|
36
|
-
keys.push(`token.${family}.${
|
|
36
|
+
keys.push(`token.${family}.${unsChain}.${token}.address`)
|
|
37
37
|
}
|
|
38
|
-
if (
|
|
39
|
-
keys.push(`token.${family}.${
|
|
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
|
|
48
|
-
keys.push(`crypto.${
|
|
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
|
|
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.'
|
package/src/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ export { isBatchingSupported } from './core/EVM/isBatchingSupported.js'
|
|
|
12
12
|
export { getNativePermit } from './core/EVM/permits/getNativePermit.js'
|
|
13
13
|
export {
|
|
14
14
|
revokeTokenApproval,
|
|
15
|
+
setAllowance,
|
|
15
16
|
setTokenAllowance,
|
|
16
17
|
} from './core/EVM/setAllowance.js'
|
|
17
18
|
export {
|
package/src/services/api.ts
CHANGED
|
@@ -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 {
|
|
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
|
|
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}/
|
|
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:
|
|
297
|
+
params: QuoteRequestFromAmount,
|
|
265
298
|
options?: RequestOptions
|
|
266
299
|
): Promise<LiFiStep> => {
|
|
267
|
-
const requiredParameters: Array<keyof
|
|
300
|
+
const requiredParameters: Array<keyof QuoteRequestFromAmount> = [
|
|
268
301
|
'fromChain',
|
|
269
302
|
'fromToken',
|
|
270
303
|
'fromAddress',
|
package/src/services/types.ts
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
import type {
|
|
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.
|
|
2
|
+
export const version = '3.12.0'
|