@lifi/sdk 3.0.2-beta.0 → 3.1.0-beta.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 +12 -11
- package/src/_cjs/core/EVM/EVMStepExecutor.js.map +1 -1
- package/src/_cjs/core/EVM/checkAllowance.js +3 -4
- package/src/_cjs/core/EVM/checkAllowance.js.map +1 -1
- package/src/_cjs/core/EVM/multisig.js +4 -3
- package/src/_cjs/core/EVM/multisig.js.map +1 -1
- package/src/_cjs/core/EVM/parseEVMErrors.js +38 -0
- package/src/_cjs/core/EVM/parseEVMErrors.js.map +1 -0
- package/src/_cjs/core/EVM/publicClient.js +8 -3
- package/src/_cjs/core/EVM/publicClient.js.map +1 -1
- package/src/_cjs/core/EVM/switchChain.js +4 -3
- package/src/_cjs/core/EVM/switchChain.js.map +1 -1
- package/src/_cjs/core/Solana/SolanaStepExecutor.js +42 -24
- package/src/_cjs/core/Solana/SolanaStepExecutor.js.map +1 -1
- package/src/_cjs/core/Solana/connection.js.map +1 -1
- package/src/_cjs/core/Solana/parseSolanaErrors.js +33 -0
- package/src/_cjs/core/Solana/parseSolanaErrors.js.map +1 -0
- package/src/_cjs/core/checkBalance.js +2 -2
- package/src/_cjs/core/checkBalance.js.map +1 -1
- package/src/_cjs/core/stepComparison.js +3 -3
- package/src/_cjs/core/stepComparison.js.map +1 -1
- package/src/_cjs/core/waitForReceivingTransaction.js +1 -1
- package/src/_cjs/core/waitForReceivingTransaction.js.map +1 -1
- package/src/_cjs/errors/SDKError.js +48 -0
- package/src/_cjs/errors/SDKError.js.map +1 -0
- package/src/_cjs/errors/baseError.js +30 -0
- package/src/_cjs/errors/baseError.js.map +1 -0
- package/src/_cjs/errors/constants.js +48 -0
- package/src/_cjs/errors/constants.js.map +1 -0
- package/src/_cjs/errors/errors.js +48 -0
- package/src/_cjs/errors/errors.js.map +1 -0
- package/src/_cjs/errors/httpError.js +101 -0
- package/src/_cjs/errors/httpError.js.map +1 -0
- package/src/_cjs/errors/index.js +11 -0
- package/src/_cjs/errors/index.js.map +1 -0
- package/src/_cjs/errors/utils/baseErrorRootCause.js +21 -0
- package/src/_cjs/errors/utils/baseErrorRootCause.js.map +1 -0
- package/src/_cjs/errors/utils/rootCause.js +12 -0
- package/src/_cjs/errors/utils/rootCause.js.map +1 -0
- package/src/_cjs/helpers.js +13 -8
- package/src/_cjs/helpers.js.map +1 -1
- package/src/_cjs/index.js +2 -4
- package/src/_cjs/index.js.map +1 -1
- package/src/_cjs/request.js +37 -34
- package/src/_cjs/request.js.map +1 -1
- package/src/_cjs/services/api.js +61 -132
- package/src/_cjs/services/api.js.map +1 -1
- package/src/_cjs/services/balance.js +1 -1
- package/src/_cjs/services/balance.js.map +1 -1
- package/src/_cjs/types/request.js +3 -0
- package/src/_cjs/types/request.js.map +1 -0
- package/src/_cjs/utils/errors.js +0 -183
- package/src/_cjs/utils/errors.js.map +1 -1
- package/src/_cjs/utils/index.js +1 -2
- package/src/_cjs/utils/index.js.map +1 -1
- package/src/_cjs/version.js +1 -1
- package/src/_esm/core/EVM/EVMStepExecutor.js +8 -7
- package/src/_esm/core/EVM/EVMStepExecutor.js.map +1 -1
- package/src/_esm/core/EVM/checkAllowance.js +3 -4
- package/src/_esm/core/EVM/checkAllowance.js.map +1 -1
- package/src/_esm/core/EVM/multisig.js +2 -1
- package/src/_esm/core/EVM/multisig.js.map +1 -1
- package/src/_esm/core/EVM/parseEVMErrors.js +35 -0
- package/src/_esm/core/EVM/parseEVMErrors.js.map +1 -0
- package/src/_esm/core/EVM/publicClient.js +9 -4
- package/src/_esm/core/EVM/publicClient.js.map +1 -1
- package/src/_esm/core/EVM/switchChain.js +2 -1
- package/src/_esm/core/EVM/switchChain.js.map +1 -1
- package/src/_esm/core/Solana/SolanaStepExecutor.js +52 -25
- package/src/_esm/core/Solana/SolanaStepExecutor.js.map +1 -1
- package/src/_esm/core/Solana/connection.js +2 -3
- package/src/_esm/core/Solana/connection.js.map +1 -1
- package/src/_esm/core/Solana/parseSolanaErrors.js +29 -0
- package/src/_esm/core/Solana/parseSolanaErrors.js.map +1 -0
- package/src/_esm/core/checkBalance.js +2 -2
- package/src/_esm/core/checkBalance.js.map +1 -1
- package/src/_esm/core/stepComparison.js +3 -3
- package/src/_esm/core/stepComparison.js.map +1 -1
- package/src/_esm/core/waitForReceivingTransaction.js +1 -1
- package/src/_esm/core/waitForReceivingTransaction.js.map +1 -1
- package/src/_esm/errors/SDKError.js +47 -0
- package/src/_esm/errors/SDKError.js.map +1 -0
- package/src/_esm/errors/baseError.js +28 -0
- package/src/_esm/errors/baseError.js.map +1 -0
- package/src/_esm/errors/constants.js +45 -0
- package/src/_esm/errors/constants.js.map +1 -0
- package/src/_esm/errors/errors.js +38 -0
- package/src/_esm/errors/errors.js.map +1 -0
- package/src/_esm/errors/httpError.js +97 -0
- package/src/_esm/errors/httpError.js.map +1 -0
- package/src/_esm/errors/index.js +8 -0
- package/src/_esm/errors/index.js.map +1 -0
- package/src/_esm/errors/utils/baseErrorRootCause.js +16 -0
- package/src/_esm/errors/utils/baseErrorRootCause.js.map +1 -0
- package/src/_esm/errors/utils/rootCause.js +8 -0
- package/src/_esm/errors/utils/rootCause.js.map +1 -0
- package/src/_esm/helpers.js +16 -9
- package/src/_esm/helpers.js.map +1 -1
- package/src/_esm/index.js +2 -2
- package/src/_esm/index.js.map +1 -1
- package/src/_esm/request.js +38 -35
- package/src/_esm/request.js.map +1 -1
- package/src/_esm/services/api.js +61 -133
- package/src/_esm/services/api.js.map +1 -1
- package/src/_esm/services/balance.js +4 -4
- package/src/_esm/services/balance.js.map +1 -1
- package/src/_esm/types/request.js +2 -0
- package/src/_esm/types/request.js.map +1 -0
- package/src/_esm/utils/errors.js +1 -173
- package/src/_esm/utils/errors.js.map +1 -1
- package/src/_esm/utils/index.js +1 -2
- package/src/_esm/utils/index.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/checkAllowance.d.ts.map +1 -1
- package/src/_types/core/EVM/multisig.d.ts.map +1 -1
- package/src/_types/core/EVM/parseEVMErrors.d.ts +4 -0
- package/src/_types/core/EVM/parseEVMErrors.d.ts.map +1 -0
- package/src/_types/core/EVM/publicClient.d.ts.map +1 -1
- package/src/_types/core/EVM/switchChain.d.ts.map +1 -1
- package/src/_types/core/Solana/SolanaStepExecutor.d.ts.map +1 -1
- package/src/_types/core/Solana/connection.d.ts +2 -3
- package/src/_types/core/Solana/connection.d.ts.map +1 -1
- package/src/_types/core/Solana/parseSolanaErrors.d.ts +4 -0
- package/src/_types/core/Solana/parseSolanaErrors.d.ts.map +1 -0
- package/src/_types/core/stepComparison.d.ts.map +1 -1
- package/src/_types/errors/SDKError.d.ts +12 -0
- package/src/_types/errors/SDKError.d.ts.map +1 -0
- package/src/_types/errors/baseError.d.ts +7 -0
- package/src/_types/errors/baseError.d.ts.map +1 -0
- package/src/_types/errors/constants.d.ts +43 -0
- package/src/_types/errors/constants.d.ts.map +1 -0
- package/src/_types/errors/errors.d.ts +24 -0
- package/src/_types/errors/errors.d.ts.map +1 -0
- package/src/_types/errors/httpError.d.ts +21 -0
- package/src/_types/errors/httpError.d.ts.map +1 -0
- package/src/_types/errors/index.d.ts +8 -0
- package/src/_types/errors/index.d.ts.map +1 -0
- package/src/_types/errors/utils/baseErrorRootCause.d.ts +4 -0
- package/src/_types/errors/utils/baseErrorRootCause.d.ts.map +1 -0
- package/src/_types/errors/utils/rootCause.d.ts +2 -0
- package/src/_types/errors/utils/rootCause.d.ts.map +1 -0
- package/src/_types/helpers.d.ts +5 -4
- package/src/_types/helpers.d.ts.map +1 -1
- package/src/_types/index.d.ts +2 -2
- package/src/_types/index.d.ts.map +1 -1
- package/src/_types/request.d.ts +1 -5
- package/src/_types/request.d.ts.map +1 -1
- package/src/_types/services/api.d.ts.map +1 -1
- package/src/_types/services/balance.d.ts +3 -3
- package/src/_types/types/request.d.ts +4 -0
- package/src/_types/types/request.d.ts.map +1 -0
- package/src/_types/utils/errors.d.ts +0 -109
- package/src/_types/utils/errors.d.ts.map +1 -1
- package/src/_types/utils/index.d.ts +1 -2
- package/src/_types/utils/index.d.ts.map +1 -1
- package/src/_types/version.d.ts +1 -1
- package/src/core/EVM/EVMStepExecutor.ts +14 -12
- package/src/core/EVM/checkAllowance.ts +3 -4
- package/src/core/EVM/multisig.ts +2 -1
- package/src/core/EVM/parseEVMErrors.ts +60 -0
- package/src/core/EVM/publicClient.ts +9 -4
- package/src/core/EVM/switchChain.ts +2 -1
- package/src/core/Solana/SolanaStepExecutor.ts +67 -34
- package/src/core/Solana/connection.ts +2 -3
- package/src/core/Solana/parseSolanaErrors.ts +45 -0
- package/src/core/checkBalance.ts +2 -2
- package/src/core/stepComparison.ts +3 -4
- package/src/core/waitForReceivingTransaction.ts +1 -1
- package/src/errors/SDKError.ts +25 -0
- package/src/errors/baseError.ts +22 -0
- package/src/errors/constants.ts +45 -0
- package/src/errors/errors.ts +44 -0
- package/src/errors/httpError.ts +93 -0
- package/src/errors/index.ts +7 -0
- package/src/errors/utils/baseErrorRootCause.ts +18 -0
- package/src/errors/utils/rootCause.ts +7 -0
- package/src/helpers.ts +23 -16
- package/src/index.ts +2 -2
- package/src/request.ts +52 -38
- package/src/services/api.ts +109 -157
- package/src/services/balance.ts +4 -4
- package/src/types/request.ts +3 -0
- package/src/utils/errors.ts +0 -233
- package/src/utils/index.ts +1 -2
- package/src/version.ts +1 -1
- package/src/_cjs/utils/parseBackendError.js +0 -27
- package/src/_cjs/utils/parseBackendError.js.map +0 -1
- package/src/_cjs/utils/parseError.js +0 -69
- package/src/_cjs/utils/parseError.js.map +0 -1
- package/src/_esm/utils/parseBackendError.js +0 -24
- package/src/_esm/utils/parseBackendError.js.map +0 -1
- package/src/_esm/utils/parseError.js +0 -100
- package/src/_esm/utils/parseError.js.map +0 -1
- package/src/_types/utils/parseBackendError.d.ts +0 -3
- package/src/_types/utils/parseBackendError.d.ts.map +0 -1
- package/src/_types/utils/parseError.d.ts +0 -35
- package/src/_types/utils/parseError.d.ts.map +0 -1
- package/src/utils/parseBackendError.ts +0 -50
- package/src/utils/parseError.ts +0 -210
package/src/helpers.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { LiFiStep, Route } from '@lifi/types'
|
|
2
|
-
import { request } from './request.js'
|
|
3
|
-
import type { TenderlyResponse } from './types/index.js'
|
|
4
|
-
import { ValidationError } from './utils/errors.js'
|
|
5
1
|
import { name, version } from './version.js'
|
|
2
|
+
import { ValidationError } from './errors/errors.js'
|
|
3
|
+
import { SDKError } from './errors/SDKError.js'
|
|
4
|
+
import type { Route, LiFiStep } from '@lifi/types'
|
|
6
5
|
|
|
7
6
|
export const checkPackageUpdates = async (
|
|
8
7
|
packageName?: string,
|
|
@@ -10,12 +9,11 @@ export const checkPackageUpdates = async (
|
|
|
10
9
|
) => {
|
|
11
10
|
try {
|
|
12
11
|
const pkgName = packageName ?? name
|
|
13
|
-
const response = await
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
)
|
|
17
|
-
const latestVersion = response.version
|
|
12
|
+
const response = await fetch(`https://registry.npmjs.org/${pkgName}/latest`)
|
|
13
|
+
const reponseBody = await response.json()
|
|
14
|
+
const latestVersion = reponseBody.version
|
|
18
15
|
const currentVersion = packageVersion ?? version
|
|
16
|
+
|
|
19
17
|
if (latestVersion > currentVersion) {
|
|
20
18
|
console.warn(
|
|
21
19
|
// eslint-disable-next-line max-len
|
|
@@ -30,16 +28,22 @@ export const checkPackageUpdates = async (
|
|
|
30
28
|
/**
|
|
31
29
|
* Converts a quote to Route
|
|
32
30
|
* @param step - Step returned from the quote endpoint.
|
|
31
|
+
* @param txHash
|
|
32
|
+
* @param chainId
|
|
33
33
|
* @returns - The route to be executed.
|
|
34
|
-
* @throws {
|
|
34
|
+
* @throws {BaseError} Throws a ValidationError if the step has missing values.
|
|
35
35
|
*/
|
|
36
36
|
export const convertQuoteToRoute = (step: LiFiStep): Route => {
|
|
37
37
|
if (!step.estimate.fromAmountUSD) {
|
|
38
|
-
throw new
|
|
38
|
+
throw new SDKError(
|
|
39
|
+
new ValidationError("Missing 'fromAmountUSD' in step estimate.")
|
|
40
|
+
)
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
if (!step.estimate.toAmountUSD) {
|
|
42
|
-
throw new
|
|
44
|
+
throw new SDKError(
|
|
45
|
+
new ValidationError("Missing 'toAmountUSD' in step estimate.")
|
|
46
|
+
)
|
|
43
47
|
}
|
|
44
48
|
|
|
45
49
|
const route: Route = {
|
|
@@ -61,9 +65,12 @@ export const convertQuoteToRoute = (step: LiFiStep): Route => {
|
|
|
61
65
|
}
|
|
62
66
|
|
|
63
67
|
export const fetchTxErrorDetails = async (txHash: string, chainId: number) => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
68
|
+
try {
|
|
69
|
+
const response = await fetch(
|
|
70
|
+
`https://api.tenderly.co/api/v1/public-contract/${chainId}/tx/${txHash}`
|
|
71
|
+
)
|
|
72
|
+
const reponseBody = await response.json()
|
|
67
73
|
|
|
68
|
-
|
|
74
|
+
return reponseBody
|
|
75
|
+
} catch (_) {}
|
|
69
76
|
}
|
package/src/index.ts
CHANGED
|
@@ -26,5 +26,5 @@ export * from './services/api.js'
|
|
|
26
26
|
export * from './services/balance.js'
|
|
27
27
|
export * from './services/getNameServiceAddress.js'
|
|
28
28
|
export * from './types/index.js'
|
|
29
|
-
export * from './
|
|
30
|
-
export {
|
|
29
|
+
export * from './errors/index.js'
|
|
30
|
+
export { type ErrorCode } from './errors/index.js'
|
package/src/request.ts
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import { config } from './config.js'
|
|
2
|
-
import { HTTPError } from './
|
|
2
|
+
import { HTTPError } from './errors/httpError.js'
|
|
3
3
|
import { wait } from './utils/utils.js'
|
|
4
|
+
import { ValidationError } from './errors/errors.js'
|
|
5
|
+
import { SDKError } from './errors/SDKError.js'
|
|
6
|
+
import type { ExtendedRequestInit } from './types/request.js'
|
|
4
7
|
import { version } from './version.js'
|
|
5
8
|
|
|
6
9
|
export const requestSettings = {
|
|
7
10
|
retries: 1,
|
|
8
11
|
}
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
retries
|
|
12
|
-
|
|
13
|
-
}
|
|
13
|
+
const stripExtendRequestInitProperties = ({
|
|
14
|
+
retries,
|
|
15
|
+
...rest
|
|
16
|
+
}: ExtendedRequestInit): RequestInit => ({
|
|
17
|
+
...rest,
|
|
18
|
+
})
|
|
14
19
|
|
|
15
20
|
export const request = async <T = Response>(
|
|
16
21
|
url: RequestInfo | URL,
|
|
@@ -19,61 +24,70 @@ export const request = async <T = Response>(
|
|
|
19
24
|
}
|
|
20
25
|
): Promise<T> => {
|
|
21
26
|
const { userId, integrator, widgetVersion, apiKey } = config.get()
|
|
27
|
+
|
|
22
28
|
if (!integrator) {
|
|
23
|
-
throw new
|
|
24
|
-
|
|
29
|
+
throw new SDKError(
|
|
30
|
+
new ValidationError(
|
|
31
|
+
'You need to provide the Integrator property. Please see documentation https://docs.li.fi/integrate-li.fi-js-sdk/set-up-the-sdk'
|
|
32
|
+
)
|
|
25
33
|
)
|
|
26
34
|
}
|
|
35
|
+
|
|
27
36
|
options.retries = options.retries ?? requestSettings.retries
|
|
28
|
-
try {
|
|
29
|
-
if (!options.skipTrackingHeaders) {
|
|
30
|
-
if (apiKey) {
|
|
31
|
-
options.headers = {
|
|
32
|
-
...options.headers,
|
|
33
|
-
'x-lifi-api-key': apiKey,
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
try {
|
|
39
|
+
if (apiKey) {
|
|
40
|
+
options.headers = {
|
|
41
|
+
...options.headers,
|
|
42
|
+
'x-lifi-api-key': apiKey,
|
|
42
43
|
}
|
|
44
|
+
}
|
|
43
45
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
46
|
+
if (userId) {
|
|
47
|
+
options.headers = {
|
|
48
|
+
...options.headers,
|
|
49
|
+
'x-lifi-userid': userId,
|
|
49
50
|
}
|
|
51
|
+
}
|
|
50
52
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
53
|
+
if (widgetVersion) {
|
|
54
|
+
options.headers = {
|
|
55
|
+
...options.headers,
|
|
56
|
+
'x-lifi-widget': widgetVersion,
|
|
56
57
|
}
|
|
58
|
+
}
|
|
57
59
|
|
|
58
|
-
|
|
60
|
+
if (version) {
|
|
59
61
|
options.headers = {
|
|
60
62
|
...options.headers,
|
|
61
|
-
'x-lifi-
|
|
63
|
+
'x-lifi-sdk': version,
|
|
62
64
|
}
|
|
63
65
|
}
|
|
64
66
|
|
|
65
|
-
|
|
67
|
+
// integrator is mandatory during SDK initialization
|
|
68
|
+
options.headers = {
|
|
69
|
+
...options.headers,
|
|
70
|
+
'x-lifi-integrator': integrator,
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const response: Response = await fetch(
|
|
74
|
+
url,
|
|
75
|
+
stripExtendRequestInitProperties(options)
|
|
76
|
+
)
|
|
77
|
+
|
|
66
78
|
if (!response.ok) {
|
|
67
|
-
throw new HTTPError(response)
|
|
79
|
+
throw new HTTPError(response, url, options)
|
|
68
80
|
}
|
|
69
81
|
|
|
70
|
-
|
|
71
|
-
return data
|
|
82
|
+
return await response.json()
|
|
72
83
|
} catch (error) {
|
|
73
|
-
if (options.retries > 0 && (error as HTTPError)
|
|
84
|
+
if (options.retries > 0 && (error as HTTPError).status === 500) {
|
|
74
85
|
await wait(500)
|
|
75
86
|
return request<T>(url, { ...options, retries: options.retries - 1 })
|
|
76
87
|
}
|
|
77
|
-
|
|
88
|
+
|
|
89
|
+
await (error as HTTPError).buildAdditionalDetails?.()
|
|
90
|
+
|
|
91
|
+
throw new SDKError(error as HTTPError)
|
|
78
92
|
}
|
|
79
93
|
}
|
package/src/services/api.ts
CHANGED
|
@@ -27,8 +27,8 @@ import type {
|
|
|
27
27
|
import { config } from '../config.js'
|
|
28
28
|
import { request } from '../request.js'
|
|
29
29
|
import { isRoutesRequest, isStep } from '../typeguards.js'
|
|
30
|
-
import { ValidationError } from '../
|
|
31
|
-
import {
|
|
30
|
+
import { ValidationError } from '../errors/errors.js'
|
|
31
|
+
import { SDKError } from '../errors/SDKError.js'
|
|
32
32
|
/**
|
|
33
33
|
* Fetch information about a Token
|
|
34
34
|
* @param chain - Id or key of the chain that contains the token
|
|
@@ -43,25 +43,24 @@ export const getToken = async (
|
|
|
43
43
|
options?: RequestOptions
|
|
44
44
|
): Promise<Token> => {
|
|
45
45
|
if (!chain) {
|
|
46
|
-
throw new
|
|
46
|
+
throw new SDKError(
|
|
47
|
+
new ValidationError('Required parameter "chain" is missing.')
|
|
48
|
+
)
|
|
47
49
|
}
|
|
48
50
|
if (!token) {
|
|
49
|
-
throw new
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
const response = await request<Token>(
|
|
53
|
-
`${config.get().apiUrl}/token?${new URLSearchParams({
|
|
54
|
-
chain,
|
|
55
|
-
token,
|
|
56
|
-
} as Record<string, string>)}`,
|
|
57
|
-
{
|
|
58
|
-
signal: options?.signal,
|
|
59
|
-
}
|
|
51
|
+
throw new SDKError(
|
|
52
|
+
new ValidationError('Required parameter "token" is missing.')
|
|
60
53
|
)
|
|
61
|
-
return response
|
|
62
|
-
} catch (e) {
|
|
63
|
-
throw await parseBackendError(e)
|
|
64
54
|
}
|
|
55
|
+
return await request<Token>(
|
|
56
|
+
`${config.get().apiUrl}/token?${new URLSearchParams({
|
|
57
|
+
chain,
|
|
58
|
+
token,
|
|
59
|
+
} as Record<string, string>)}`,
|
|
60
|
+
{
|
|
61
|
+
signal: options?.signal,
|
|
62
|
+
}
|
|
63
|
+
)
|
|
65
64
|
}
|
|
66
65
|
|
|
67
66
|
/**
|
|
@@ -85,8 +84,10 @@ export const getQuote = async (
|
|
|
85
84
|
]
|
|
86
85
|
requiredParameters.forEach((requiredParameter) => {
|
|
87
86
|
if (!params[requiredParameter]) {
|
|
88
|
-
throw new
|
|
89
|
-
|
|
87
|
+
throw new SDKError(
|
|
88
|
+
new ValidationError(
|
|
89
|
+
`Required parameter "${requiredParameter}" is missing.`
|
|
90
|
+
)
|
|
90
91
|
)
|
|
91
92
|
}
|
|
92
93
|
})
|
|
@@ -110,19 +111,14 @@ export const getQuote = async (
|
|
|
110
111
|
delete params[key as keyof QuoteRequest]
|
|
111
112
|
)
|
|
112
113
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
)
|
|
122
|
-
return response
|
|
123
|
-
} catch (e) {
|
|
124
|
-
throw await parseBackendError(e)
|
|
125
|
-
}
|
|
114
|
+
return await request<LiFiStep>(
|
|
115
|
+
`${_config.apiUrl}/quote?${new URLSearchParams(
|
|
116
|
+
params as unknown as Record<string, string>
|
|
117
|
+
)}`,
|
|
118
|
+
{
|
|
119
|
+
signal: options?.signal,
|
|
120
|
+
}
|
|
121
|
+
)
|
|
126
122
|
}
|
|
127
123
|
|
|
128
124
|
/**
|
|
@@ -148,8 +144,10 @@ export const getContractCallsQuote = async (
|
|
|
148
144
|
]
|
|
149
145
|
requiredParameters.forEach((requiredParameter) => {
|
|
150
146
|
if (!params[requiredParameter]) {
|
|
151
|
-
throw new
|
|
152
|
-
|
|
147
|
+
throw new SDKError(
|
|
148
|
+
new ValidationError(
|
|
149
|
+
`Required parameter "${requiredParameter}" is missing.`
|
|
150
|
+
)
|
|
153
151
|
)
|
|
154
152
|
}
|
|
155
153
|
})
|
|
@@ -167,22 +165,14 @@ export const getContractCallsQuote = async (
|
|
|
167
165
|
params.denyExchanges ??= _config.routeOptions?.exchanges?.deny
|
|
168
166
|
params.preferExchanges ??= _config.routeOptions?.exchanges?.prefer
|
|
169
167
|
// send request
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
body: JSON.stringify(params),
|
|
179
|
-
signal: options?.signal,
|
|
180
|
-
}
|
|
181
|
-
)
|
|
182
|
-
return response
|
|
183
|
-
} catch (e) {
|
|
184
|
-
throw await parseBackendError(e)
|
|
185
|
-
}
|
|
168
|
+
return await request<LiFiStep>(`${_config.apiUrl}/quote/contractCalls`, {
|
|
169
|
+
method: 'POST',
|
|
170
|
+
headers: {
|
|
171
|
+
'Content-Type': 'application/json',
|
|
172
|
+
},
|
|
173
|
+
body: JSON.stringify(params),
|
|
174
|
+
signal: options?.signal,
|
|
175
|
+
})
|
|
186
176
|
}
|
|
187
177
|
|
|
188
178
|
/**
|
|
@@ -197,22 +187,19 @@ export const getStatus = async (
|
|
|
197
187
|
options?: RequestOptions
|
|
198
188
|
): Promise<StatusResponse> => {
|
|
199
189
|
if (!params.txHash) {
|
|
200
|
-
throw new
|
|
190
|
+
throw new SDKError(
|
|
191
|
+
new ValidationError('Required parameter "txHash" is missing.')
|
|
192
|
+
)
|
|
201
193
|
}
|
|
202
194
|
const queryParams = new URLSearchParams(
|
|
203
195
|
params as unknown as Record<string, string>
|
|
204
196
|
)
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
)
|
|
212
|
-
return response
|
|
213
|
-
} catch (e) {
|
|
214
|
-
throw await parseBackendError(e)
|
|
215
|
-
}
|
|
197
|
+
return await request<StatusResponse>(
|
|
198
|
+
`${config.get().apiUrl}/status?${queryParams}`,
|
|
199
|
+
{
|
|
200
|
+
signal: options?.signal,
|
|
201
|
+
}
|
|
202
|
+
)
|
|
216
203
|
}
|
|
217
204
|
|
|
218
205
|
/**
|
|
@@ -233,19 +220,16 @@ export const getChains = async (
|
|
|
233
220
|
delete params[key as keyof ChainsRequest]
|
|
234
221
|
)
|
|
235
222
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
} catch (e) {
|
|
247
|
-
throw await parseBackendError(e)
|
|
248
|
-
}
|
|
223
|
+
|
|
224
|
+
const response = await request<ChainsResponse>(
|
|
225
|
+
`${config.get().apiUrl}/chains?${new URLSearchParams(
|
|
226
|
+
params as Record<string, string>
|
|
227
|
+
)}`,
|
|
228
|
+
{
|
|
229
|
+
signal: options?.signal,
|
|
230
|
+
}
|
|
231
|
+
)
|
|
232
|
+
return response.chains
|
|
249
233
|
}
|
|
250
234
|
|
|
251
235
|
/**
|
|
@@ -260,7 +244,7 @@ export const getRoutes = async (
|
|
|
260
244
|
options?: RequestOptions
|
|
261
245
|
): Promise<RoutesResponse> => {
|
|
262
246
|
if (!isRoutesRequest(params)) {
|
|
263
|
-
throw new ValidationError('Invalid routes request.')
|
|
247
|
+
throw new SDKError(new ValidationError('Invalid routes request.'))
|
|
264
248
|
}
|
|
265
249
|
const _config = config.get()
|
|
266
250
|
// apply defaults
|
|
@@ -269,23 +253,15 @@ export const getRoutes = async (
|
|
|
269
253
|
..._config.routeOptions,
|
|
270
254
|
...params.options,
|
|
271
255
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
body: JSON.stringify(params),
|
|
282
|
-
signal: options?.signal,
|
|
283
|
-
}
|
|
284
|
-
)
|
|
285
|
-
return response
|
|
286
|
-
} catch (e) {
|
|
287
|
-
throw await parseBackendError(e)
|
|
288
|
-
}
|
|
256
|
+
|
|
257
|
+
return await request<RoutesResponse>(`${_config.apiUrl}/advanced/routes`, {
|
|
258
|
+
method: 'POST',
|
|
259
|
+
headers: {
|
|
260
|
+
'Content-Type': 'application/json',
|
|
261
|
+
},
|
|
262
|
+
body: JSON.stringify(params),
|
|
263
|
+
signal: options?.signal,
|
|
264
|
+
})
|
|
289
265
|
}
|
|
290
266
|
|
|
291
267
|
/**
|
|
@@ -304,22 +280,18 @@ export const getStepTransaction = async (
|
|
|
304
280
|
// eslint-disable-next-line no-console
|
|
305
281
|
console.warn('SDK Validation: Invalid Step', step)
|
|
306
282
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
return response
|
|
320
|
-
} catch (e) {
|
|
321
|
-
throw await parseBackendError(e)
|
|
322
|
-
}
|
|
283
|
+
|
|
284
|
+
return await request<LiFiStep>(
|
|
285
|
+
`${config.get().apiUrl}/advanced/stepTransaction`,
|
|
286
|
+
{
|
|
287
|
+
method: 'POST',
|
|
288
|
+
headers: {
|
|
289
|
+
'Content-Type': 'application/json',
|
|
290
|
+
},
|
|
291
|
+
body: JSON.stringify(step),
|
|
292
|
+
signal: options?.signal,
|
|
293
|
+
}
|
|
294
|
+
)
|
|
323
295
|
}
|
|
324
296
|
|
|
325
297
|
/**
|
|
@@ -339,19 +311,14 @@ export const getTools = async (
|
|
|
339
311
|
delete params[key as keyof ToolsRequest]
|
|
340
312
|
)
|
|
341
313
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
)
|
|
351
|
-
return response
|
|
352
|
-
} catch (e) {
|
|
353
|
-
throw await parseBackendError(e)
|
|
354
|
-
}
|
|
314
|
+
return await request<ToolsResponse>(
|
|
315
|
+
`${config.get().apiUrl}/tools?${new URLSearchParams(
|
|
316
|
+
params as Record<string, string>
|
|
317
|
+
)}`,
|
|
318
|
+
{
|
|
319
|
+
signal: options?.signal,
|
|
320
|
+
}
|
|
321
|
+
)
|
|
355
322
|
}
|
|
356
323
|
|
|
357
324
|
/**
|
|
@@ -372,19 +339,14 @@ export const getTokens = async (
|
|
|
372
339
|
)
|
|
373
340
|
}
|
|
374
341
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
)
|
|
384
|
-
return response
|
|
385
|
-
} catch (e) {
|
|
386
|
-
throw await parseBackendError(e)
|
|
387
|
-
}
|
|
342
|
+
return await request<TokensResponse>(
|
|
343
|
+
`${config.get().apiUrl}/tokens?${new URLSearchParams(
|
|
344
|
+
params as Record<string, string>
|
|
345
|
+
)}`,
|
|
346
|
+
{
|
|
347
|
+
signal: options?.signal,
|
|
348
|
+
}
|
|
349
|
+
)
|
|
388
350
|
}
|
|
389
351
|
|
|
390
352
|
/**
|
|
@@ -399,7 +361,9 @@ export const getGasRecommendation = async (
|
|
|
399
361
|
options?: RequestOptions
|
|
400
362
|
): Promise<GasRecommendationResponse> => {
|
|
401
363
|
if (!params.chainId) {
|
|
402
|
-
throw new
|
|
364
|
+
throw new SDKError(
|
|
365
|
+
new ValidationError('Required parameter "chainId" is missing.')
|
|
366
|
+
)
|
|
403
367
|
}
|
|
404
368
|
|
|
405
369
|
const url = new URL(`${config.get().apiUrl}/gas/suggestion/${params.chainId}`)
|
|
@@ -410,14 +374,9 @@ export const getGasRecommendation = async (
|
|
|
410
374
|
url.searchParams.append('fromToken', params.fromToken)
|
|
411
375
|
}
|
|
412
376
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
})
|
|
417
|
-
return response
|
|
418
|
-
} catch (e) {
|
|
419
|
-
throw await parseBackendError(e)
|
|
420
|
-
}
|
|
377
|
+
return await request<GasRecommendationResponse>(url.toString(), {
|
|
378
|
+
signal: options?.signal,
|
|
379
|
+
})
|
|
421
380
|
}
|
|
422
381
|
|
|
423
382
|
/**
|
|
@@ -465,12 +424,8 @@ export const getConnections = async (
|
|
|
465
424
|
})
|
|
466
425
|
}
|
|
467
426
|
})
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
return response
|
|
471
|
-
} catch (e) {
|
|
472
|
-
throw await parseBackendError(e)
|
|
473
|
-
}
|
|
427
|
+
|
|
428
|
+
return await request<ConnectionsResponse>(url, options)
|
|
474
429
|
}
|
|
475
430
|
|
|
476
431
|
export const getTransactionHistory = async (
|
|
@@ -478,7 +433,9 @@ export const getTransactionHistory = async (
|
|
|
478
433
|
options?: RequestOptions
|
|
479
434
|
): Promise<TransactionAnalyticsResponse> => {
|
|
480
435
|
if (!wallet) {
|
|
481
|
-
throw new
|
|
436
|
+
throw new SDKError(
|
|
437
|
+
new ValidationError('Required parameter "wallet" is missing.')
|
|
438
|
+
)
|
|
482
439
|
}
|
|
483
440
|
|
|
484
441
|
const _config = config.get()
|
|
@@ -500,10 +457,5 @@ export const getTransactionHistory = async (
|
|
|
500
457
|
url.searchParams.append('toTimestamp', toTimestamp.toString())
|
|
501
458
|
}
|
|
502
459
|
|
|
503
|
-
|
|
504
|
-
const response = await request<TransactionAnalyticsResponse>(url, options)
|
|
505
|
-
return response
|
|
506
|
-
} catch (e) {
|
|
507
|
-
throw await parseBackendError(e)
|
|
508
|
-
}
|
|
460
|
+
return await request<TransactionAnalyticsResponse>(url, options)
|
|
509
461
|
}
|
package/src/services/balance.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { Token, TokenAmount } from '@lifi/types'
|
|
2
2
|
import { config } from '../config.js'
|
|
3
3
|
import { isToken } from '../typeguards.js'
|
|
4
|
-
import { ValidationError } from '../
|
|
4
|
+
import { ValidationError } from '../errors/errors.js'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Returns the balances of a specific token a wallet holds across all aggregated chains.
|
|
8
8
|
* @param walletAddress - A wallet address.
|
|
9
9
|
* @param token - A Token object.
|
|
10
10
|
* @returns An object containing the token and the amounts on different chains.
|
|
11
|
-
* @throws {
|
|
11
|
+
* @throws {BaseError} Throws a ValidationError if parameters are invalid.
|
|
12
12
|
*/
|
|
13
13
|
export const getTokenBalance = async (
|
|
14
14
|
walletAddress: string,
|
|
@@ -23,7 +23,7 @@ export const getTokenBalance = async (
|
|
|
23
23
|
* @param walletAddress - A wallet address.
|
|
24
24
|
* @param tokens - A list of Token objects.
|
|
25
25
|
* @returns A list of objects containing the tokens and the amounts on different chains.
|
|
26
|
-
* @throws {
|
|
26
|
+
* @throws {BaseError} Throws a ValidationError if parameters are invalid.
|
|
27
27
|
*/
|
|
28
28
|
export const getTokenBalances = async (
|
|
29
29
|
walletAddress: string,
|
|
@@ -53,7 +53,7 @@ export const getTokenBalances = async (
|
|
|
53
53
|
* @param walletAddress - A walletaddress.
|
|
54
54
|
* @param tokensByChain - A list of Token objects organized by chain ids.
|
|
55
55
|
* @returns A list of objects containing the tokens and the amounts on different chains organized by the chosen chains.
|
|
56
|
-
* @throws {
|
|
56
|
+
* @throws {BaseError} Throws a ValidationError if parameters are invalid.
|
|
57
57
|
*/
|
|
58
58
|
export const getTokenBalancesByChain = async (
|
|
59
59
|
walletAddress: string,
|