@lifi/sdk 3.0.0-alpha.27 → 3.0.0-alpha.29
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/constants.js +2 -1
- package/src/_cjs/constants.js.map +1 -1
- package/src/_cjs/core/EVM/EVMStepExecutor.js.map +1 -1
- package/src/_cjs/core/EVM/switchChain.js.map +1 -1
- package/src/_cjs/core/Solana/SolanaStepExecutor.js.map +1 -1
- package/src/_cjs/core/Solana/getSolanaBalance.js +23 -13
- package/src/_cjs/core/Solana/getSolanaBalance.js.map +1 -1
- package/src/_cjs/core/StatusManager.js.map +1 -1
- package/src/_cjs/core/execution.js +1 -1
- package/src/_cjs/core/execution.js.map +1 -1
- package/src/_cjs/core/executionState.js.map +1 -1
- package/src/_cjs/core/prepareRestart.js.map +1 -1
- package/src/_cjs/createConfig.js +4 -2
- package/src/_cjs/createConfig.js.map +1 -1
- package/src/_cjs/request.js +5 -5
- package/src/_cjs/request.js.map +1 -1
- package/src/_cjs/services/api.js +21 -1
- package/src/_cjs/services/api.js.map +1 -1
- package/src/_cjs/version.js +1 -1
- package/src/_esm/constants.js +1 -0
- package/src/_esm/constants.js.map +1 -1
- package/src/_esm/core/EVM/EVMStepExecutor.js.map +1 -1
- package/src/_esm/core/EVM/switchChain.js.map +1 -1
- package/src/_esm/core/Solana/SolanaStepExecutor.js.map +1 -1
- package/src/_esm/core/Solana/getSolanaBalance.js +23 -13
- package/src/_esm/core/Solana/getSolanaBalance.js.map +1 -1
- package/src/_esm/core/StatusManager.js.map +1 -1
- package/src/_esm/core/execution.js +1 -1
- package/src/_esm/core/execution.js.map +1 -1
- package/src/_esm/core/executionState.js.map +1 -1
- package/src/_esm/core/prepareRestart.js.map +1 -1
- package/src/_esm/createConfig.js +4 -2
- package/src/_esm/createConfig.js.map +1 -1
- package/src/_esm/request.js +5 -5
- package/src/_esm/request.js.map +1 -1
- package/src/_esm/services/api.js +19 -0
- package/src/_esm/services/api.js.map +1 -1
- package/src/_esm/version.js +1 -1
- package/src/_types/constants.d.ts +1 -0
- package/src/_types/constants.d.ts.map +1 -1
- package/src/_types/core/EVM/EVMStepExecutor.d.ts +2 -3
- package/src/_types/core/EVM/EVMStepExecutor.d.ts.map +1 -1
- package/src/_types/core/EVM/switchChain.d.ts +2 -3
- package/src/_types/core/EVM/switchChain.d.ts.map +1 -1
- package/src/_types/core/Solana/SolanaStepExecutor.d.ts +4 -5
- package/src/_types/core/Solana/SolanaStepExecutor.d.ts.map +1 -1
- package/src/_types/core/Solana/getSolanaBalance.d.ts.map +1 -1
- package/src/_types/core/Solana/types.d.ts +2 -2
- package/src/_types/core/Solana/types.d.ts.map +1 -1
- package/src/_types/core/StatusManager.d.ts +6 -5
- package/src/_types/core/StatusManager.d.ts.map +1 -1
- package/src/_types/core/execution.d.ts +5 -5
- package/src/_types/core/execution.d.ts.map +1 -1
- package/src/_types/core/executionState.d.ts +4 -5
- package/src/_types/core/executionState.d.ts.map +1 -1
- package/src/_types/core/prepareRestart.d.ts +2 -2
- package/src/_types/core/prepareRestart.d.ts.map +1 -1
- package/src/_types/core/types.d.ts +8 -2
- package/src/_types/core/types.d.ts.map +1 -1
- package/src/_types/createConfig.d.ts.map +1 -1
- package/src/_types/services/api.d.ts +2 -1
- package/src/_types/services/api.d.ts.map +1 -1
- package/src/_types/version.d.ts +1 -1
- package/src/constants.ts +1 -0
- package/src/core/EVM/EVMStepExecutor.ts +7 -7
- package/src/core/EVM/switchChain.ts +2 -3
- package/src/core/Solana/SolanaStepExecutor.ts +10 -10
- package/src/core/Solana/getSolanaBalance.ts +28 -18
- package/src/core/Solana/types.ts +2 -2
- package/src/core/StatusManager.ts +10 -5
- package/src/core/execution.ts +9 -9
- package/src/core/executionState.ts +5 -6
- package/src/core/prepareRestart.ts +4 -3
- package/src/core/types.ts +10 -1
- package/src/createConfig.ts +19 -17
- package/src/request.ts +5 -5
- package/src/services/api.ts +36 -1
- package/src/version.ts +1 -1
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ExtendedTransactionInfo,
|
|
3
|
-
FullStatusData,
|
|
4
|
-
LiFiStep,
|
|
5
|
-
} from '@lifi/types'
|
|
1
|
+
import type { ExtendedTransactionInfo, FullStatusData } from '@lifi/types'
|
|
6
2
|
import type {
|
|
7
3
|
Address,
|
|
8
4
|
Hash,
|
|
@@ -25,7 +21,11 @@ import {
|
|
|
25
21
|
import { BaseStepExecutor } from '../BaseStepExecutor.js'
|
|
26
22
|
import { checkBalance } from '../checkBalance.js'
|
|
27
23
|
import { stepComparison } from '../stepComparison.js'
|
|
28
|
-
import type {
|
|
24
|
+
import type {
|
|
25
|
+
LiFiStepExtended,
|
|
26
|
+
StepExecutorOptions,
|
|
27
|
+
TransactionParameters,
|
|
28
|
+
} from '../types.js'
|
|
29
29
|
import { getSubstatusMessage } from '../utils.js'
|
|
30
30
|
import { waitForReceivingTransaction } from '../waitForReceivingTransaction.js'
|
|
31
31
|
import { checkAllowance } from './checkAllowance.js'
|
|
@@ -56,7 +56,7 @@ export class EVMStepExecutor extends BaseStepExecutor {
|
|
|
56
56
|
throw new Error('checkChain is not implemented.')
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
executeStep = async (step:
|
|
59
|
+
executeStep = async (step: LiFiStepExtended): Promise<LiFiStepExtended> => {
|
|
60
60
|
// Make sure that the chain is still correct
|
|
61
61
|
|
|
62
62
|
// Find if it's bridging and the step is waiting for a transaction on the receiving chain
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { LiFiStep } from '@lifi/types'
|
|
2
1
|
import type { WalletClient } from 'viem'
|
|
3
2
|
import { LiFiErrorCode, ProviderError } from '../../utils/errors.js'
|
|
4
3
|
import type { StatusManager } from '../StatusManager.js'
|
|
5
|
-
import type { SwitchChainHook } from '../types.js'
|
|
4
|
+
import type { LiFiStepExtended, SwitchChainHook } from '../types.js'
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* This method checks whether the wallet client is configured for the correct chain.
|
|
@@ -24,7 +23,7 @@ import type { SwitchChainHook } from '../types.js'
|
|
|
24
23
|
export const switchChain = async (
|
|
25
24
|
walletClient: WalletClient,
|
|
26
25
|
statusManager: StatusManager,
|
|
27
|
-
step:
|
|
26
|
+
step: LiFiStepExtended,
|
|
28
27
|
allowUserInteraction: boolean,
|
|
29
28
|
switchChainHook?: SwitchChainHook
|
|
30
29
|
): Promise<WalletClient | undefined> => {
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
FullStatusData,
|
|
4
|
-
LiFiStep,
|
|
5
|
-
} from '@lifi/types'
|
|
6
|
-
import type { WalletAdapter } from '@solana/wallet-adapter-base'
|
|
1
|
+
import type { ExtendedTransactionInfo, FullStatusData } from '@lifi/types'
|
|
2
|
+
import type { Adapter } from '@solana/wallet-adapter-base'
|
|
7
3
|
import {
|
|
8
4
|
VersionedTransaction,
|
|
9
5
|
type TransactionConfirmationStrategy,
|
|
@@ -20,24 +16,28 @@ import {
|
|
|
20
16
|
import { BaseStepExecutor } from '../BaseStepExecutor.js'
|
|
21
17
|
import { checkBalance } from '../checkBalance.js'
|
|
22
18
|
import { stepComparison } from '../stepComparison.js'
|
|
23
|
-
import type {
|
|
19
|
+
import type {
|
|
20
|
+
LiFiStepExtended,
|
|
21
|
+
StepExecutorOptions,
|
|
22
|
+
TransactionParameters,
|
|
23
|
+
} from '../types.js'
|
|
24
24
|
import { getSubstatusMessage } from '../utils.js'
|
|
25
25
|
import { waitForReceivingTransaction } from '../waitForReceivingTransaction.js'
|
|
26
26
|
import { getSolanaConnection } from './connection.js'
|
|
27
27
|
|
|
28
28
|
export interface SolanaStepExecutorOptions extends StepExecutorOptions {
|
|
29
|
-
walletAdapter:
|
|
29
|
+
walletAdapter: Adapter
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export class SolanaStepExecutor extends BaseStepExecutor {
|
|
33
|
-
private walletAdapter:
|
|
33
|
+
private walletAdapter: Adapter
|
|
34
34
|
|
|
35
35
|
constructor(options: SolanaStepExecutorOptions) {
|
|
36
36
|
super(options)
|
|
37
37
|
this.walletAdapter = options.walletAdapter
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
executeStep = async (step:
|
|
40
|
+
executeStep = async (step: LiFiStepExtended): Promise<LiFiStepExtended> => {
|
|
41
41
|
step.execution = this.statusManager.initExecutionObject(step)
|
|
42
42
|
|
|
43
43
|
const fromChain = await config.getChainById(step.action.fromChainId)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ChainId, Token, TokenAmount } from '@lifi/types'
|
|
2
2
|
import { PublicKey } from '@solana/web3.js'
|
|
3
|
+
import { wrappedSolAddress } from '../../constants.js'
|
|
3
4
|
import { getSolanaConnection } from './connection.js'
|
|
4
5
|
import { TokenProgramAddress } from './types.js'
|
|
5
6
|
|
|
@@ -26,36 +27,45 @@ const getSolanaBalanceDefault = async (
|
|
|
26
27
|
walletAddress: string
|
|
27
28
|
): Promise<TokenAmount[]> => {
|
|
28
29
|
const connection = await getSolanaConnection()
|
|
29
|
-
const blockNumber = await connection.getSlot()
|
|
30
30
|
const accountPublicKey = new PublicKey(walletAddress)
|
|
31
31
|
const tokenProgramPublicKey = new PublicKey(TokenProgramAddress)
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
const [slot, balance, tokenAccountsByOwner] = await Promise.allSettled([
|
|
33
|
+
connection.getSlot(),
|
|
34
|
+
connection.getBalance(accountPublicKey),
|
|
35
|
+
connection.getParsedTokenAccountsByOwner(accountPublicKey, {
|
|
35
36
|
programId: tokenProgramPublicKey,
|
|
36
|
-
}
|
|
37
|
-
)
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
}),
|
|
38
|
+
])
|
|
39
|
+
const blockNumber = slot.status === 'fulfilled' ? BigInt(slot.value) : 0n
|
|
40
|
+
const solBalance = balance.status === 'fulfilled' ? BigInt(balance.value) : 0n
|
|
41
|
+
const walletTokenAmounts =
|
|
42
|
+
tokenAccountsByOwner.status === 'fulfilled'
|
|
43
|
+
? tokenAccountsByOwner.value.value.reduce(
|
|
44
|
+
(tokenAmounts, value) => {
|
|
45
|
+
const amount = BigInt(
|
|
46
|
+
value.account.data.parsed.info.tokenAmount.amount
|
|
47
|
+
)
|
|
48
|
+
if (amount > 0n) {
|
|
49
|
+
tokenAmounts[value.account.data.parsed.info.mint] = amount
|
|
50
|
+
}
|
|
51
|
+
return tokenAmounts
|
|
52
|
+
},
|
|
53
|
+
{} as Record<string, bigint>
|
|
54
|
+
)
|
|
55
|
+
: {}
|
|
56
|
+
walletTokenAmounts[wrappedSolAddress] ??= 0n
|
|
57
|
+
walletTokenAmounts[wrappedSolAddress] += solBalance
|
|
48
58
|
const tokenAmounts: TokenAmount[] = tokens.map((token) => {
|
|
49
59
|
if (walletTokenAmounts[token.address]) {
|
|
50
60
|
return {
|
|
51
61
|
...token,
|
|
52
62
|
amount: walletTokenAmounts[token.address],
|
|
53
|
-
blockNumber
|
|
63
|
+
blockNumber,
|
|
54
64
|
}
|
|
55
65
|
}
|
|
56
66
|
return {
|
|
57
67
|
...token,
|
|
58
|
-
blockNumber
|
|
68
|
+
blockNumber,
|
|
59
69
|
}
|
|
60
70
|
})
|
|
61
71
|
return tokenAmounts
|
package/src/core/Solana/types.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ChainType, type ChainId } from '@lifi/types'
|
|
2
|
-
import type {
|
|
2
|
+
import type { Adapter } from '@solana/wallet-adapter-base'
|
|
3
3
|
import { type SDKProvider } from '../types.js'
|
|
4
4
|
|
|
5
5
|
export interface SolanaProviderOptions {
|
|
6
|
-
getWalletAdapter?: () => Promise<
|
|
6
|
+
getWalletAdapter?: () => Promise<Adapter>
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export interface SolanaProvider extends SDKProvider {
|
|
@@ -8,6 +8,7 @@ import type {
|
|
|
8
8
|
} from '@lifi/types'
|
|
9
9
|
import { emptyExecution } from '@lifi/types'
|
|
10
10
|
import { executionState } from './executionState.js'
|
|
11
|
+
import type { LiFiStepExtended } from './types.js'
|
|
11
12
|
import { getProcessMessage } from './utils.js'
|
|
12
13
|
|
|
13
14
|
interface Receipt {
|
|
@@ -53,7 +54,7 @@ export class StatusManager {
|
|
|
53
54
|
* @param step The current step in execution
|
|
54
55
|
* @returns The initialized execution object for this step and a function to update this step
|
|
55
56
|
*/
|
|
56
|
-
initExecutionObject = (step:
|
|
57
|
+
initExecutionObject = (step: LiFiStepExtended): Execution => {
|
|
57
58
|
if (!step.execution) {
|
|
58
59
|
step.execution = structuredClone<Execution>(emptyExecution)
|
|
59
60
|
step.execution.status = 'PENDING'
|
|
@@ -76,7 +77,11 @@ export class StatusManager {
|
|
|
76
77
|
* @param receipt Optional. Information about received tokens
|
|
77
78
|
* @returns The step with the updated execution object
|
|
78
79
|
*/
|
|
79
|
-
updateExecution(
|
|
80
|
+
updateExecution(
|
|
81
|
+
step: LiFiStepExtended,
|
|
82
|
+
status: Status,
|
|
83
|
+
receipt?: Receipt
|
|
84
|
+
): LiFiStep {
|
|
80
85
|
if (!step.execution) {
|
|
81
86
|
throw Error("Can't update empty execution.")
|
|
82
87
|
}
|
|
@@ -99,7 +104,7 @@ export class StatusManager {
|
|
|
99
104
|
* @returns Returns process.
|
|
100
105
|
*/
|
|
101
106
|
findOrCreateProcess = (
|
|
102
|
-
step:
|
|
107
|
+
step: LiFiStepExtended,
|
|
103
108
|
type: ProcessType,
|
|
104
109
|
status?: Status
|
|
105
110
|
): Process => {
|
|
@@ -138,7 +143,7 @@ export class StatusManager {
|
|
|
138
143
|
* @returns The update process
|
|
139
144
|
*/
|
|
140
145
|
updateProcess = (
|
|
141
|
-
step:
|
|
146
|
+
step: LiFiStepExtended,
|
|
142
147
|
type: ProcessType,
|
|
143
148
|
status: Status,
|
|
144
149
|
params?: OptionalParameters
|
|
@@ -199,7 +204,7 @@ export class StatusManager {
|
|
|
199
204
|
* @param step The step where the process should be removed from
|
|
200
205
|
* @param type The process type to remove
|
|
201
206
|
*/
|
|
202
|
-
removeProcess = (step:
|
|
207
|
+
removeProcess = (step: LiFiStepExtended, type: ProcessType): void => {
|
|
203
208
|
if (!step.execution) {
|
|
204
209
|
throw new Error("Execution hasn't been initialized.")
|
|
205
210
|
}
|
package/src/core/execution.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Route } from '@lifi/types'
|
|
|
3
3
|
import { config } from '../config.js'
|
|
4
4
|
import { executionState } from './executionState.js'
|
|
5
5
|
import { prepareRestart } from './prepareRestart.js'
|
|
6
|
-
import type { ExecutionOptions } from './types.js'
|
|
6
|
+
import type { ExecutionOptions, RouteExtended } from './types.js'
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Execute a route.
|
|
@@ -15,7 +15,7 @@ import type { ExecutionOptions } from './types.js'
|
|
|
15
15
|
export const executeRoute = async (
|
|
16
16
|
route: Route,
|
|
17
17
|
executionOptions?: ExecutionOptions
|
|
18
|
-
): Promise<
|
|
18
|
+
): Promise<RouteExtended> => {
|
|
19
19
|
// Deep clone to prevent side effects
|
|
20
20
|
const clonedRoute = structuredClone<Route>(route)
|
|
21
21
|
|
|
@@ -42,7 +42,7 @@ export const executeRoute = async (
|
|
|
42
42
|
export const resumeRoute = async (
|
|
43
43
|
route: Route,
|
|
44
44
|
executionOptions?: ExecutionOptions
|
|
45
|
-
): Promise<
|
|
45
|
+
): Promise<RouteExtended> => {
|
|
46
46
|
// Deep clone to prevent side effects
|
|
47
47
|
const clonedRoute = structuredClone<Route>(route)
|
|
48
48
|
|
|
@@ -74,9 +74,9 @@ export const resumeRoute = async (
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
const executeSteps = async (
|
|
77
|
-
route:
|
|
77
|
+
route: RouteExtended,
|
|
78
78
|
executionOptions?: ExecutionOptions
|
|
79
|
-
): Promise<
|
|
79
|
+
): Promise<RouteExtended> => {
|
|
80
80
|
executionState.create(route, executionOptions)
|
|
81
81
|
|
|
82
82
|
// Loop over steps and execute them
|
|
@@ -195,17 +195,17 @@ export const stopRouteExecution = (route: Route): Route => {
|
|
|
195
195
|
})
|
|
196
196
|
}
|
|
197
197
|
executionState.delete(route.id)
|
|
198
|
-
return route
|
|
198
|
+
return execution.route
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
/**
|
|
202
202
|
* Get the list of active routes.
|
|
203
203
|
* @returns A list of routes.
|
|
204
204
|
*/
|
|
205
|
-
export const getActiveRoutes = ():
|
|
205
|
+
export const getActiveRoutes = (): RouteExtended[] => {
|
|
206
206
|
return Object.values(executionState.state)
|
|
207
207
|
.map((dict) => dict?.route)
|
|
208
|
-
.filter(Boolean) as
|
|
208
|
+
.filter(Boolean) as RouteExtended[]
|
|
209
209
|
}
|
|
210
210
|
|
|
211
211
|
/**
|
|
@@ -213,6 +213,6 @@ export const getActiveRoutes = (): Route[] => {
|
|
|
213
213
|
* @param routeId - A route id.
|
|
214
214
|
* @returns The updated route.
|
|
215
215
|
*/
|
|
216
|
-
export const getActiveRoute = (routeId: string):
|
|
216
|
+
export const getActiveRoute = (routeId: string): RouteExtended | undefined => {
|
|
217
217
|
return executionState.get(routeId)?.route
|
|
218
218
|
}
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ExecutionOptions, StepExecutor } from './types.js'
|
|
1
|
+
import type { ExecutionOptions, RouteExtended, StepExecutor } from './types.js'
|
|
3
2
|
|
|
4
3
|
export interface ExecutionData {
|
|
5
|
-
route:
|
|
4
|
+
route: RouteExtended
|
|
6
5
|
executors: StepExecutor[]
|
|
7
6
|
executionOptions?: ExecutionOptions
|
|
8
|
-
promise?: Promise<
|
|
7
|
+
promise?: Promise<RouteExtended>
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
export interface ExecutionState {
|
|
12
11
|
state: Partial<Record<string, ExecutionData>>
|
|
13
12
|
get(routeId: string): ExecutionData | undefined
|
|
14
13
|
create(
|
|
15
|
-
route:
|
|
14
|
+
route: RouteExtended,
|
|
16
15
|
executionOptions?: ExecutionOptions,
|
|
17
|
-
promise?: Promise<
|
|
16
|
+
promise?: Promise<RouteExtended>
|
|
18
17
|
): ExecutionData
|
|
19
18
|
delete(routeId: string): void
|
|
20
19
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { LiFiStep
|
|
1
|
+
import type { LiFiStep } from '@lifi/types'
|
|
2
|
+
import type { LiFiStepExtended, RouteExtended } from './types.js'
|
|
2
3
|
|
|
3
|
-
export const prepareRestart = async (route:
|
|
4
|
+
export const prepareRestart = async (route: RouteExtended) => {
|
|
4
5
|
for (let index = 0; index < route.steps.length; index++) {
|
|
5
6
|
const step = route.steps[index]
|
|
6
7
|
const stepHasFailed = step.execution?.status === 'FAILED'
|
|
@@ -68,7 +69,7 @@ export const prepareRestart = async (route: Route) => {
|
|
|
68
69
|
// }
|
|
69
70
|
// }
|
|
70
71
|
|
|
71
|
-
const deleteFailedProcesses = (step:
|
|
72
|
+
const deleteFailedProcesses = (step: LiFiStepExtended) => {
|
|
72
73
|
if (step.execution) {
|
|
73
74
|
step.execution.process = step.execution.process.filter(
|
|
74
75
|
(process) => process.status === 'DONE'
|
package/src/core/types.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
ChainType,
|
|
3
|
+
Execution,
|
|
3
4
|
LiFiStep,
|
|
4
5
|
Route,
|
|
5
6
|
Token,
|
|
@@ -29,7 +30,15 @@ export interface StepExecutor {
|
|
|
29
30
|
allowUserInteraction: boolean
|
|
30
31
|
allowExecution: boolean
|
|
31
32
|
setInteraction(settings?: InteractionSettings): void
|
|
32
|
-
executeStep(step:
|
|
33
|
+
executeStep(step: LiFiStepExtended): Promise<LiFiStepExtended>
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface RouteExtended extends Omit<Route, 'steps'> {
|
|
37
|
+
steps: LiFiStepExtended[]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface LiFiStepExtended extends LiFiStep {
|
|
41
|
+
execution?: Execution
|
|
33
42
|
}
|
|
34
43
|
|
|
35
44
|
export type TransactionParameters = {
|
package/src/createConfig.ts
CHANGED
|
@@ -20,27 +20,29 @@ function createBaseConfig(options: SDKOptions) {
|
|
|
20
20
|
export async function createChainsConfig() {
|
|
21
21
|
const _config = config.get()
|
|
22
22
|
const chainTypes = _config.providers?.map((provider) => provider.type)
|
|
23
|
-
config.loading = getChains({ chainTypes: chainTypes })
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
23
|
+
config.loading = getChains({ chainTypes: chainTypes })
|
|
24
|
+
.then((chains) => {
|
|
25
|
+
config.chains = chains
|
|
26
|
+
const evmProvider = _config.providers?.find(isEVM)
|
|
27
|
+
const multicallAddresses: Partial<Record<ChainId, string>> = {}
|
|
28
|
+
for (const chain of chains) {
|
|
29
|
+
const chainId = chain.id as ChainId
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
// set RPCs if they were not configured by the user before
|
|
32
|
+
if (!_config.rpcUrls[chainId]?.length) {
|
|
33
|
+
_config.rpcUrls[chainId] = chain.metamask.rpcUrls
|
|
34
|
+
}
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
// set multicall addresses if they exist and were not configured by the user before
|
|
37
|
+
if (chain.multicallAddress && !evmProvider?.multicall?.[chainId]) {
|
|
38
|
+
multicallAddresses[chainId] = chain.multicallAddress
|
|
39
|
+
}
|
|
38
40
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
41
|
+
evmProvider?.setOptions({
|
|
42
|
+
multicall: multicallAddresses,
|
|
43
|
+
})
|
|
42
44
|
})
|
|
43
|
-
|
|
45
|
+
.catch()
|
|
44
46
|
await config.loading
|
|
45
47
|
}
|
|
46
48
|
|
package/src/request.ts
CHANGED
|
@@ -29,35 +29,35 @@ export const request = async <T = Response>(
|
|
|
29
29
|
if (!options.skipTrackingHeaders) {
|
|
30
30
|
if (apiKey) {
|
|
31
31
|
options.headers = {
|
|
32
|
-
...options
|
|
32
|
+
...options.headers,
|
|
33
33
|
'x-lifi-api-key': apiKey,
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
if (userId) {
|
|
38
38
|
options.headers = {
|
|
39
|
-
...options
|
|
39
|
+
...options.headers,
|
|
40
40
|
'x-lifi-userid': userId,
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
if (widgetVersion) {
|
|
45
45
|
options.headers = {
|
|
46
|
-
...options
|
|
46
|
+
...options.headers,
|
|
47
47
|
'x-lifi-widget': widgetVersion,
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
if (version) {
|
|
52
52
|
options.headers = {
|
|
53
|
-
...options
|
|
53
|
+
...options.headers,
|
|
54
54
|
'x-lifi-sdk': version,
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
// integrator is mandatory during SDK initialization
|
|
59
59
|
options.headers = {
|
|
60
|
-
...options
|
|
60
|
+
...options.headers,
|
|
61
61
|
'x-lifi-integrator': integrator,
|
|
62
62
|
}
|
|
63
63
|
}
|
package/src/services/api.ts
CHANGED
|
@@ -21,13 +21,14 @@ import type {
|
|
|
21
21
|
TokensResponse,
|
|
22
22
|
ToolsRequest,
|
|
23
23
|
ToolsResponse,
|
|
24
|
+
WalletAnalytics,
|
|
25
|
+
WalletAnalyticsRequest,
|
|
24
26
|
} from '@lifi/types'
|
|
25
27
|
import { config } from '../config.js'
|
|
26
28
|
import { request } from '../request.js'
|
|
27
29
|
import { isRoutesRequest, isStep } from '../typeguards.js'
|
|
28
30
|
import { ValidationError } from '../utils/errors.js'
|
|
29
31
|
import { parseBackendError } from '../utils/parseBackendError.js'
|
|
30
|
-
|
|
31
32
|
/**
|
|
32
33
|
* Fetch information about a Token
|
|
33
34
|
* @param chain - Id or key of the chain that contains the token
|
|
@@ -470,3 +471,37 @@ export const getConnections = async (
|
|
|
470
471
|
throw await parseBackendError(e)
|
|
471
472
|
}
|
|
472
473
|
}
|
|
474
|
+
|
|
475
|
+
export const getTransactionHistory = async (
|
|
476
|
+
walletAnalyticsRequest: WalletAnalyticsRequest
|
|
477
|
+
): Promise<WalletAnalytics> => {
|
|
478
|
+
const _config = config.get()
|
|
479
|
+
|
|
480
|
+
if (!walletAnalyticsRequest.fromTimestamp) {
|
|
481
|
+
throw new ValidationError('Required parameter "fromTimestamp" is missing.')
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
if (!walletAnalyticsRequest.toTimestamp) {
|
|
485
|
+
throw new ValidationError('Required parameter "toTimestamp" is missing.')
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
const url = new URL(
|
|
489
|
+
`${_config.apiUrl}/analytics/wallets/${walletAnalyticsRequest.walletAddress}`
|
|
490
|
+
)
|
|
491
|
+
|
|
492
|
+
url.searchParams.append(
|
|
493
|
+
'fromTimestamp',
|
|
494
|
+
walletAnalyticsRequest.fromTimestamp.toString()
|
|
495
|
+
)
|
|
496
|
+
|
|
497
|
+
url.searchParams.append(
|
|
498
|
+
'toTimestamp',
|
|
499
|
+
walletAnalyticsRequest.toTimestamp.toString()
|
|
500
|
+
)
|
|
501
|
+
try {
|
|
502
|
+
const response = await request<WalletAnalytics>(url)
|
|
503
|
+
return response
|
|
504
|
+
} catch (e) {
|
|
505
|
+
throw await parseBackendError(e)
|
|
506
|
+
}
|
|
507
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export const name = '@lifi/sdk'
|
|
2
|
-
export const version = '3.0.0-alpha.
|
|
2
|
+
export const version = '3.0.0-alpha.29'
|