@lifi/sdk 3.14.0-alpha.0 → 3.14.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/LICENSE +201 -165
- package/package.json +7 -7
- package/src/_cjs/core/EVM/EVMStepExecutor.js +9 -4
- package/src/_cjs/core/EVM/EVMStepExecutor.js.map +1 -1
- package/src/_cjs/core/Solana/SolanaStepExecutor.js +13 -12
- package/src/_cjs/core/Solana/SolanaStepExecutor.js.map +1 -1
- package/src/_cjs/core/Solana/connection.js +4 -15
- package/src/_cjs/core/Solana/connection.js.map +1 -1
- package/src/_cjs/core/Solana/jito/JitoConnection.js +51 -21
- package/src/_cjs/core/Solana/jito/JitoConnection.js.map +1 -1
- package/src/_cjs/core/Solana/jito/constants.js +10 -23
- package/src/_cjs/core/Solana/jito/constants.js.map +1 -1
- package/src/_cjs/core/Solana/jito/sendAndConfirmBundle.js +36 -84
- package/src/_cjs/core/Solana/jito/sendAndConfirmBundle.js.map +1 -1
- package/src/_cjs/index.js.map +1 -1
- package/src/_cjs/request.js +7 -3
- package/src/_cjs/request.js.map +1 -1
- package/src/_cjs/services/api.js +1 -2
- package/src/_cjs/services/api.js.map +1 -1
- package/src/_cjs/version.js +1 -1
- package/src/_cjs/version.js.map +1 -1
- package/src/_esm/core/EVM/EVMStepExecutor.js +10 -4
- package/src/_esm/core/EVM/EVMStepExecutor.js.map +1 -1
- package/src/_esm/core/Solana/SolanaStepExecutor.js +13 -12
- package/src/_esm/core/Solana/SolanaStepExecutor.js.map +1 -1
- package/src/_esm/core/Solana/connection.js +7 -20
- package/src/_esm/core/Solana/connection.js.map +1 -1
- package/src/_esm/core/Solana/jito/JitoConnection.js +72 -23
- package/src/_esm/core/Solana/jito/JitoConnection.js.map +1 -1
- package/src/_esm/core/Solana/jito/constants.js +10 -23
- package/src/_esm/core/Solana/jito/constants.js.map +1 -1
- package/src/_esm/core/Solana/jito/sendAndConfirmBundle.js +45 -104
- package/src/_esm/core/Solana/jito/sendAndConfirmBundle.js.map +1 -1
- package/src/_esm/index.js.map +1 -1
- package/src/_esm/request.js +7 -3
- package/src/_esm/request.js.map +1 -1
- package/src/_esm/services/api.js +3 -4
- package/src/_esm/services/api.js.map +1 -1
- package/src/_esm/version.js +1 -1
- package/src/_esm/version.js.map +1 -1
- package/src/_types/core/EVM/EVMStepExecutor.d.ts.map +1 -1
- package/src/_types/core/Solana/SolanaStepExecutor.d.ts.map +1 -1
- package/src/_types/core/Solana/connection.d.ts +4 -3
- package/src/_types/core/Solana/connection.d.ts.map +1 -1
- package/src/_types/core/Solana/jito/JitoConnection.d.ts +35 -5
- package/src/_types/core/Solana/jito/JitoConnection.d.ts.map +1 -1
- package/src/_types/core/Solana/jito/constants.d.ts +1 -2
- package/src/_types/core/Solana/jito/constants.d.ts.map +1 -1
- package/src/_types/core/Solana/jito/sendAndConfirmBundle.d.ts +2 -2
- package/src/_types/core/Solana/jito/sendAndConfirmBundle.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.map +1 -1
- package/src/_types/services/api.d.ts +1 -1
- package/src/_types/services/api.d.ts.map +1 -1
- package/src/_types/services/types.d.ts +0 -3
- package/src/_types/services/types.d.ts.map +1 -1
- package/src/_types/types/internal.d.ts +3 -0
- package/src/_types/types/internal.d.ts.map +1 -1
- package/src/_types/version.d.ts +1 -1
- package/src/_types/version.d.ts.map +1 -1
- package/src/core/EVM/EVMStepExecutor.ts +11 -3
- package/src/core/Solana/SolanaStepExecutor.ts +13 -12
- package/src/core/Solana/connection.ts +12 -25
- package/src/core/Solana/jito/JitoConnection.ts +97 -29
- package/src/core/Solana/jito/constants.ts +10 -25
- package/src/core/Solana/jito/sendAndConfirmBundle.ts +50 -135
- package/src/index.ts +6 -2
- package/src/request.ts +9 -3
- package/src/services/api.ts +4 -6
- package/src/services/types.ts +0 -4
- package/src/types/internal.ts +6 -0
- package/src/version.ts +1 -1
- package/src/_cjs/core/Solana/jito/isJitoRpc.js +0 -23
- package/src/_cjs/core/Solana/jito/isJitoRpc.js.map +0 -1
- package/src/_esm/core/Solana/jito/isJitoRpc.js +0 -21
- package/src/_esm/core/Solana/jito/isJitoRpc.js.map +0 -1
- package/src/_types/core/Solana/jito/isJitoRpc.d.ts +0 -2
- package/src/_types/core/Solana/jito/isJitoRpc.d.ts.map +0 -1
- package/src/core/Solana/jito/isJitoRpc.ts +0 -21
package/src/index.ts
CHANGED
|
@@ -125,12 +125,16 @@ export {
|
|
|
125
125
|
export { getNameServiceAddress } from './services/getNameServiceAddress.js'
|
|
126
126
|
export type {
|
|
127
127
|
GetStatusRequestExtended,
|
|
128
|
-
GetStepTransactionRequest,
|
|
129
128
|
QuoteRequest,
|
|
130
129
|
QuoteRequestFromAmount,
|
|
131
130
|
QuoteRequestToAmount,
|
|
132
131
|
} from './services/types.js'
|
|
133
|
-
export type {
|
|
132
|
+
export type {
|
|
133
|
+
RequestInterceptor,
|
|
134
|
+
RPCUrls,
|
|
135
|
+
SDKBaseConfig,
|
|
136
|
+
SDKConfig,
|
|
137
|
+
} from './types/internal.js'
|
|
134
138
|
export { checkPackageUpdates } from './utils/checkPackageUpdates.js'
|
|
135
139
|
export { convertQuoteToRoute } from './utils/convertQuoteToRoute.js'
|
|
136
140
|
export { fetchTxErrorDetails } from './utils/fetchTxErrorDetails.js'
|
package/src/request.ts
CHANGED
|
@@ -23,7 +23,8 @@ export const request = async <T = Response>(
|
|
|
23
23
|
retries: requestSettings.retries,
|
|
24
24
|
}
|
|
25
25
|
): Promise<T> => {
|
|
26
|
-
const { userId, integrator, widgetVersion, apiKey } =
|
|
26
|
+
const { userId, integrator, widgetVersion, apiKey, requestInterceptor } =
|
|
27
|
+
config.get()
|
|
27
28
|
|
|
28
29
|
if (!integrator) {
|
|
29
30
|
throw new SDKError(
|
|
@@ -70,6 +71,10 @@ export const request = async <T = Response>(
|
|
|
70
71
|
'x-lifi-integrator': integrator,
|
|
71
72
|
}
|
|
72
73
|
|
|
74
|
+
if (requestInterceptor) {
|
|
75
|
+
options = await requestInterceptor(options)
|
|
76
|
+
}
|
|
77
|
+
|
|
73
78
|
const response: Response = await fetch(
|
|
74
79
|
url,
|
|
75
80
|
stripExtendRequestInitProperties(options)
|
|
@@ -81,9 +86,10 @@ export const request = async <T = Response>(
|
|
|
81
86
|
|
|
82
87
|
return await response.json()
|
|
83
88
|
} catch (error) {
|
|
84
|
-
|
|
89
|
+
const retries = options.retries ?? 0
|
|
90
|
+
if (retries > 0 && (error as HTTPError).status === 500) {
|
|
85
91
|
await sleep(500)
|
|
86
|
-
return request<T>(url, { ...options, retries:
|
|
92
|
+
return request<T>(url, { ...options, retries: retries - 1 })
|
|
87
93
|
}
|
|
88
94
|
|
|
89
95
|
await (error as HTTPError).buildAdditionalDetails?.()
|
package/src/services/api.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
ChainId,
|
|
3
3
|
type ChainKey,
|
|
4
4
|
type ChainsRequest,
|
|
5
5
|
type ChainsResponse,
|
|
6
|
-
ChainType,
|
|
7
6
|
type ConnectionsRequest,
|
|
8
7
|
type ConnectionsResponse,
|
|
9
8
|
type ContractCallsQuoteRequest,
|
|
@@ -250,11 +249,10 @@ export const getStepTransaction = async (
|
|
|
250
249
|
|
|
251
250
|
const _config = config.get()
|
|
252
251
|
let requestUrl = `${_config.apiUrl}/advanced/stepTransaction`
|
|
253
|
-
const fromChain = await config.getChainById(step.action.fromChainId)
|
|
254
|
-
|
|
255
252
|
const isJitoBundleEnabled = Boolean(_config.routeOptions?.jitoBundle)
|
|
256
|
-
|
|
257
|
-
if (
|
|
253
|
+
|
|
254
|
+
if (isJitoBundleEnabled && step.action.fromChainId === ChainId.SOL) {
|
|
255
|
+
// add jitoBundle param to url if from chain is SVM and jitoBundle is enabled in config
|
|
258
256
|
const queryParams = new URLSearchParams({ jitoBundle: 'true' })
|
|
259
257
|
requestUrl = `${requestUrl}?${queryParams}`
|
|
260
258
|
}
|
package/src/services/types.ts
CHANGED
|
@@ -7,10 +7,6 @@ export type GetStatusRequestExtended = GetStatusRequest & {
|
|
|
7
7
|
fromAddress?: string
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export type GetStepTransactionRequest = {
|
|
11
|
-
jitoBundle?: boolean
|
|
12
|
-
}
|
|
13
|
-
|
|
14
10
|
export type QuoteRequestFromAmount = QuoteRequestBase
|
|
15
11
|
|
|
16
12
|
export type QuoteRequestToAmount = Omit<QuoteRequestBase, 'fromAmount'> & {
|
package/src/types/internal.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { ChainId, ExtendedChain, RouteOptions } from '@lifi/types'
|
|
2
2
|
import type { SDKProvider } from '../core/types.js'
|
|
3
|
+
import type { ExtendedRequestInit } from './request.js'
|
|
4
|
+
|
|
5
|
+
export type RequestInterceptor = (
|
|
6
|
+
request: ExtendedRequestInit
|
|
7
|
+
) => ExtendedRequestInit | Promise<ExtendedRequestInit>
|
|
3
8
|
|
|
4
9
|
export interface SDKBaseConfig {
|
|
5
10
|
apiKey?: string
|
|
@@ -14,6 +19,7 @@ export interface SDKBaseConfig {
|
|
|
14
19
|
widgetVersion?: string
|
|
15
20
|
preloadChains: boolean
|
|
16
21
|
debug: boolean
|
|
22
|
+
requestInterceptor?: RequestInterceptor
|
|
17
23
|
}
|
|
18
24
|
|
|
19
25
|
export interface SDKConfig extends Partial<Omit<SDKBaseConfig, 'integrator'>> {
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/sdk'
|
|
2
|
-
export const version = '3.14.0
|
|
2
|
+
export const version = '3.14.0'
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isJitoRpc = isJitoRpc;
|
|
4
|
-
async function isJitoRpc(rpcUrl) {
|
|
5
|
-
try {
|
|
6
|
-
const response = await fetch(rpcUrl, {
|
|
7
|
-
method: 'POST',
|
|
8
|
-
headers: { 'Content-Type': 'application/json' },
|
|
9
|
-
body: JSON.stringify({
|
|
10
|
-
jsonrpc: '2.0',
|
|
11
|
-
id: 1,
|
|
12
|
-
method: 'getTipAccounts',
|
|
13
|
-
params: [],
|
|
14
|
-
}),
|
|
15
|
-
});
|
|
16
|
-
const data = await response.json();
|
|
17
|
-
return !!data.result && !data.error;
|
|
18
|
-
}
|
|
19
|
-
catch {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=isJitoRpc.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isJitoRpc.js","sourceRoot":"","sources":["../../../../core/Solana/jito/isJitoRpc.ts"],"names":[],"mappings":";;AAAA,8BAoBC;AApBM,KAAK,UAAU,SAAS,CAAC,MAAc;IAC5C,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,MAAM,EAAE;YACnC,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,OAAO,EAAE,KAAK;gBACd,EAAE,EAAE,CAAC;gBACL,MAAM,EAAE,gBAAgB;gBACxB,MAAM,EAAE,EAAE;aACX,CAAC;SACH,CAAC,CAAA;QAEF,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;QAGlC,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAA;IACrC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export async function isJitoRpc(rpcUrl) {
|
|
2
|
-
try {
|
|
3
|
-
const response = await fetch(rpcUrl, {
|
|
4
|
-
method: 'POST',
|
|
5
|
-
headers: { 'Content-Type': 'application/json' },
|
|
6
|
-
body: JSON.stringify({
|
|
7
|
-
jsonrpc: '2.0',
|
|
8
|
-
id: 1,
|
|
9
|
-
method: 'getTipAccounts',
|
|
10
|
-
params: [],
|
|
11
|
-
}),
|
|
12
|
-
});
|
|
13
|
-
const data = await response.json();
|
|
14
|
-
// If we get a result (not a "method not found" error), it supports Jito
|
|
15
|
-
return !!data.result && !data.error;
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=isJitoRpc.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isJitoRpc.js","sourceRoot":"","sources":["../../../../core/Solana/jito/isJitoRpc.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,MAAc;IAC5C,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,MAAM,EAAE;YACnC,MAAM,EAAE,MAAM;YACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;YAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;gBACnB,OAAO,EAAE,KAAK;gBACd,EAAE,EAAE,CAAC;gBACL,MAAM,EAAE,gBAAgB;gBACxB,MAAM,EAAE,EAAE;aACX,CAAC;SACH,CAAC,CAAA;QAEF,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;QAElC,wEAAwE;QACxE,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,KAAK,CAAA;IACrC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isJitoRpc.d.ts","sourceRoot":"","sources":["../../../../core/Solana/jito/isJitoRpc.ts"],"names":[],"mappings":"AAAA,wBAAsB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAoBhE"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export async function isJitoRpc(rpcUrl: string): Promise<boolean> {
|
|
2
|
-
try {
|
|
3
|
-
const response = await fetch(rpcUrl, {
|
|
4
|
-
method: 'POST',
|
|
5
|
-
headers: { 'Content-Type': 'application/json' },
|
|
6
|
-
body: JSON.stringify({
|
|
7
|
-
jsonrpc: '2.0',
|
|
8
|
-
id: 1,
|
|
9
|
-
method: 'getTipAccounts',
|
|
10
|
-
params: [],
|
|
11
|
-
}),
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
const data = await response.json()
|
|
15
|
-
|
|
16
|
-
// If we get a result (not a "method not found" error), it supports Jito
|
|
17
|
-
return !!data.result && !data.error
|
|
18
|
-
} catch {
|
|
19
|
-
return false
|
|
20
|
-
}
|
|
21
|
-
}
|