@lifi/sdk 3.0.0-beta.0 → 3.0.0-beta.2

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 (99) hide show
  1. package/package.json +4 -4
  2. package/src/_cjs/core/EVM/EVM.js +1 -2
  3. package/src/_cjs/core/EVM/EVM.js.map +1 -1
  4. package/src/_cjs/core/EVM/getAllowance.js.map +1 -1
  5. package/src/_cjs/core/EVM/types.js +1 -2
  6. package/src/_cjs/core/EVM/types.js.map +1 -1
  7. package/src/_cjs/core/Solana/KeypairWalletAdapter.js +3 -3
  8. package/src/_cjs/core/Solana/KeypairWalletAdapter.js.map +1 -1
  9. package/src/_cjs/core/Solana/Solana.js +1 -2
  10. package/src/_cjs/core/Solana/Solana.js.map +1 -1
  11. package/src/_cjs/core/Solana/SolanaStepExecutor.js +7 -3
  12. package/src/_cjs/core/Solana/SolanaStepExecutor.js.map +1 -1
  13. package/src/_cjs/core/Solana/isAddress.js +1 -2
  14. package/src/_cjs/core/Solana/isAddress.js.map +1 -1
  15. package/src/_cjs/core/Solana/types.js +2 -2
  16. package/src/_cjs/core/Solana/types.js.map +1 -1
  17. package/src/_cjs/core/StatusManager.js +4 -3
  18. package/src/_cjs/core/StatusManager.js.map +1 -1
  19. package/src/_cjs/core/prepareRestart.js.map +1 -1
  20. package/src/_cjs/core/utils.js +3 -4
  21. package/src/_cjs/core/utils.js.map +1 -1
  22. package/src/_cjs/core/waitForReceivingTransaction.js +1 -2
  23. package/src/_cjs/core/waitForReceivingTransaction.js.map +1 -1
  24. package/src/_cjs/createConfig.js +2 -3
  25. package/src/_cjs/createConfig.js.map +1 -1
  26. package/src/_cjs/index.js +3 -1
  27. package/src/_cjs/index.js.map +1 -1
  28. package/src/_cjs/services/balance.js +1 -1
  29. package/src/_cjs/services/balance.js.map +1 -1
  30. package/src/_cjs/utils/base64ToUint8Array.js +1 -2
  31. package/src/_cjs/utils/base64ToUint8Array.js.map +1 -1
  32. package/src/_cjs/version.js +1 -1
  33. package/src/_esm/core/EVM/getAllowance.js.map +1 -1
  34. package/src/_esm/core/EVM/setAllowance.js +8 -8
  35. package/src/_esm/core/EVM/types.js.map +1 -1
  36. package/src/_esm/core/Solana/KeypairWalletAdapter.js +3 -3
  37. package/src/_esm/core/Solana/KeypairWalletAdapter.js.map +1 -1
  38. package/src/_esm/core/Solana/SolanaStepExecutor.js +7 -3
  39. package/src/_esm/core/Solana/SolanaStepExecutor.js.map +1 -1
  40. package/src/_esm/core/StatusManager.js +4 -3
  41. package/src/_esm/core/StatusManager.js.map +1 -1
  42. package/src/_esm/core/prepareRestart.js +0 -45
  43. package/src/_esm/core/prepareRestart.js.map +1 -1
  44. package/src/_esm/core/utils.js.map +1 -1
  45. package/src/_esm/index.js +2 -2
  46. package/src/_esm/index.js.map +1 -1
  47. package/src/_esm/services/balance.js +1 -1
  48. package/src/_esm/services/balance.js.map +1 -1
  49. package/src/_esm/version.js +1 -1
  50. package/src/_types/core/EVM/EVMStepExecutor.d.ts.map +1 -1
  51. package/src/_types/core/EVM/checkAllowance.d.ts.map +1 -1
  52. package/src/_types/core/EVM/getAllowance.d.ts +2 -2
  53. package/src/_types/core/EVM/getAllowance.d.ts.map +1 -1
  54. package/src/_types/core/EVM/getENSAddress.d.ts.map +1 -1
  55. package/src/_types/core/EVM/getEVMBalance.d.ts.map +1 -1
  56. package/src/_types/core/EVM/publicClient.d.ts.map +1 -1
  57. package/src/_types/core/EVM/setAllowance.d.ts +8 -8
  58. package/src/_types/core/EVM/setAllowance.d.ts.map +1 -1
  59. package/src/_types/core/EVM/switchChain.d.ts.map +1 -1
  60. package/src/_types/core/EVM/types.d.ts +6 -6
  61. package/src/_types/core/EVM/types.d.ts.map +1 -1
  62. package/src/_types/core/EVM/utils.d.ts.map +1 -1
  63. package/src/_types/core/Solana/KeypairWalletAdapter.d.ts.map +1 -1
  64. package/src/_types/core/Solana/SolanaStepExecutor.d.ts.map +1 -1
  65. package/src/_types/core/Solana/connection.d.ts.map +1 -1
  66. package/src/_types/core/Solana/getSolanaBalance.d.ts.map +1 -1
  67. package/src/_types/core/StatusManager.d.ts +4 -4
  68. package/src/_types/core/StatusManager.d.ts.map +1 -1
  69. package/src/_types/core/checkBalance.d.ts.map +1 -1
  70. package/src/_types/core/execution.d.ts.map +1 -1
  71. package/src/_types/core/prepareRestart.d.ts.map +1 -1
  72. package/src/_types/core/provider.d.ts.map +1 -1
  73. package/src/_types/core/rpc.d.ts.map +1 -1
  74. package/src/_types/core/stepComparison.d.ts.map +1 -1
  75. package/src/_types/core/utils.d.ts +2 -2
  76. package/src/_types/core/utils.d.ts.map +1 -1
  77. package/src/_types/index.d.ts +2 -2
  78. package/src/_types/index.d.ts.map +1 -1
  79. package/src/_types/request.d.ts.map +1 -1
  80. package/src/_types/services/api.d.ts.map +1 -1
  81. package/src/_types/services/balance.d.ts.map +1 -1
  82. package/src/_types/services/getNameServiceAddress.d.ts.map +1 -1
  83. package/src/_types/typeguards.d.ts.map +1 -1
  84. package/src/_types/utils/getTransactionMessage.d.ts.map +1 -1
  85. package/src/_types/utils/parseBackendError.d.ts.map +1 -1
  86. package/src/_types/utils/parseError.d.ts.map +1 -1
  87. package/src/_types/utils/utils.d.ts.map +1 -1
  88. package/src/_types/version.d.ts +1 -1
  89. package/src/core/EVM/getAllowance.ts +2 -2
  90. package/src/core/EVM/setAllowance.ts +8 -8
  91. package/src/core/EVM/types.ts +6 -6
  92. package/src/core/Solana/KeypairWalletAdapter.ts +3 -3
  93. package/src/core/Solana/SolanaStepExecutor.ts +8 -3
  94. package/src/core/StatusManager.ts +9 -7
  95. package/src/core/prepareRestart.ts +0 -56
  96. package/src/core/utils.ts +6 -3
  97. package/src/index.ts +8 -2
  98. package/src/services/balance.ts +1 -3
  99. package/src/version.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"parseError.d.ts","sourceRoot":"","sources":["../../utils/parseError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAMpD,OAAO,EAIL,SAAS,EAOV,MAAM,aAAa,CAAA;AAGpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,eAAO,MAAM,UAAU,MAClB,GAAG,SACC,QAAQ,YACL,OAAO,KAChB,QAAQ,SAAS,CAyJnB,CAAA"}
1
+ {"version":3,"file":"parseError.d.ts","sourceRoot":"","sources":["../../utils/parseError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAMpD,OAAO,EAIL,SAAS,EAOV,MAAM,aAAa,CAAA;AAGpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,eAAO,MAAM,UAAU,MAClB,GAAG,SACC,QAAQ,YACL,OAAO,KAChB,OAAO,CAAC,SAAS,CAyJnB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../utils/utils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,IAAI,OAAQ,MAAM,KAAG,QAAQ,SAAS,CAIlD,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,eAAe,gBAChB,MAAM,QAAQ,CAAC,GAAG,SAAS,CAAC,uBAErC,QAAQ,CAAC,CAWX,CAAA;AAED,eAAO,MAAM,aAAa,YAAa,MAAM,KAAG,OAK/C,CAAA;AAED,eAAO,MAAM,oBAAoB,YAAa,MAAM,KAAG,OAUtD,CAAA"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../utils/utils.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,IAAI,OAAQ,MAAM,KAAG,OAAO,CAAC,SAAS,CAIlD,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAAU,CAAC,YAC3B,MAAM,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,uBAErC,OAAO,CAAC,CAAC,CAWX,CAAA;AAED,eAAO,MAAM,aAAa,YAAa,MAAM,KAAG,OAK/C,CAAA;AAED,eAAO,MAAM,oBAAoB,YAAa,MAAM,KAAG,OAUtD,CAAA"}
@@ -1,3 +1,3 @@
1
1
  export declare const name = "@lifi/sdk";
2
- export declare const version = "3.0.0-beta.0";
2
+ export declare const version = "3.0.0-beta.2";
3
3
  //# sourceMappingURL=version.d.ts.map
@@ -1,4 +1,4 @@
1
- import type { ChainId, Token } from '@lifi/types'
1
+ import type { BaseToken, ChainId } from '@lifi/types'
2
2
  import type { Address } from 'viem'
3
3
  import { getContract } from 'viem'
4
4
  import { isNativeTokenAddress } from '../../utils/utils.js'
@@ -83,7 +83,7 @@ export const getAllowanceMulticall = async (
83
83
  * @returns Returns allowance
84
84
  */
85
85
  export const getTokenAllowance = async (
86
- token: Token,
86
+ token: BaseToken,
87
87
  ownerAddress: string,
88
88
  spenderAddress: string
89
89
  ): Promise<bigint | undefined> => {
@@ -68,11 +68,11 @@ export const setAllowance = async (
68
68
  /**
69
69
  * Set approval for a certain token and amount.
70
70
  * @param request - The approval request
71
- * @param request.walletClient
72
- * @param request.token
73
- * @param request.spenderAddress
74
- * @param request.amount
75
- * @param request.infiniteApproval
71
+ * @param request.walletClient - The Viem wallet client used to send the transaction
72
+ * @param request.token - The token for which to set the allowance
73
+ * @param request.spenderAddress - The address of the spender
74
+ * @param request.amount - The amount of tokens to approve
75
+ * @param request.infiniteApproval - If true, sets the approval to the maximum uint256 value
76
76
  * @returns Returns Hash or nothing
77
77
  */
78
78
  export const setTokenAllowance = async ({
@@ -110,9 +110,9 @@ export const setTokenAllowance = async ({
110
110
  /**
111
111
  * Revoke approval for a certain token.
112
112
  * @param request - The revoke request
113
- * @param request.walletClient
114
- * @param request.token
115
- * @param request.spenderAddress
113
+ * @param request.walletClient - The Viem wallet client used to send the transaction
114
+ * @param request.token - The token for which to revoke the allowance
115
+ * @param request.spenderAddress - The address of the spender
116
116
  * @returns Returns Hash or nothing
117
117
  */
118
118
  export const revokeTokenApproval = async ({
@@ -1,4 +1,4 @@
1
- import { ChainType, type Token } from '@lifi/types'
1
+ import { ChainType, type BaseToken } from '@lifi/types'
2
2
  import type { Hash, WalletClient } from 'viem'
3
3
  import type { SwitchChainHook } from '../types.js'
4
4
  import { type SDKProvider } from '../types.js'
@@ -19,24 +19,24 @@ export function isEVM(provider: SDKProvider): provider is EVMProvider {
19
19
  }
20
20
 
21
21
  export type TokenSpender = {
22
- token: Token
22
+ token: BaseToken
23
23
  spenderAddress: string
24
24
  }
25
25
 
26
26
  export type TokenAllowance = {
27
- token: Token
27
+ token: BaseToken
28
28
  allowance?: bigint
29
29
  }
30
30
 
31
31
  export type TokenSpenderAllowance = {
32
- token: Token
32
+ token: BaseToken
33
33
  spenderAddress: string
34
34
  allowance?: bigint
35
35
  }
36
36
 
37
37
  export interface ApproveTokenRequest {
38
38
  walletClient: WalletClient
39
- token: Token
39
+ token: BaseToken
40
40
  spenderAddress: string
41
41
  amount: bigint
42
42
  infiniteApproval?: boolean
@@ -44,7 +44,7 @@ export interface ApproveTokenRequest {
44
44
 
45
45
  export interface RevokeApprovalRequest {
46
46
  walletClient: WalletClient
47
- token: Token
47
+ token: BaseToken
48
48
  spenderAddress: string
49
49
  }
50
50
 
@@ -16,7 +16,7 @@ import type {
16
16
  VersionedTransaction,
17
17
  } from '@solana/web3.js'
18
18
  import { Keypair } from '@solana/web3.js'
19
- import { decode } from 'bs58'
19
+ import * as bs58 from 'bs58'
20
20
 
21
21
  export const KeypairWalletName =
22
22
  'Keypair Wallet' as WalletName<'Keypair Wallet'>
@@ -48,7 +48,7 @@ export class KeypairWalletAdapter
48
48
  throw new WalletConfigError()
49
49
  }
50
50
  super()
51
- this._keypair = Keypair.fromSecretKey(decode(privateKey))
51
+ this._keypair = Keypair.fromSecretKey(bs58.decode(privateKey))
52
52
  }
53
53
 
54
54
  get connecting() {
@@ -67,7 +67,7 @@ export class KeypairWalletAdapter
67
67
  if (!privateKey) {
68
68
  throw new WalletConfigError()
69
69
  }
70
- this._keypair = Keypair.fromSecretKey(decode(privateKey))
70
+ this._keypair = Keypair.fromSecretKey(bs58.decode(privateKey))
71
71
  }
72
72
 
73
73
  async disconnect(): Promise<void> {
@@ -213,9 +213,13 @@ export class SolanaStepExecutor extends BaseStepExecutor {
213
213
  }
214
214
 
215
215
  if (confirmedTx?.err) {
216
+ const reason =
217
+ typeof confirmedTx.err === 'object'
218
+ ? JSON.stringify(confirmedTx.err)
219
+ : confirmedTx.err
216
220
  throw new TransactionError(
217
221
  LiFiErrorCode.TransactionFailed,
218
- `Transaction failed: ${confirmedTx?.err}`
222
+ `Transaction failed: ${reason}`
219
223
  )
220
224
  }
221
225
 
@@ -260,6 +264,7 @@ export class SolanaStepExecutor extends BaseStepExecutor {
260
264
  }
261
265
 
262
266
  // STEP 5: Wait for the receiving chain
267
+ const processTxHash = process.txHash
263
268
  if (isBridgeExecution) {
264
269
  process = this.statusManager.findOrCreateProcess(
265
270
  step,
@@ -269,11 +274,11 @@ export class SolanaStepExecutor extends BaseStepExecutor {
269
274
  }
270
275
  let statusResponse: FullStatusData
271
276
  try {
272
- if (!process.txHash) {
277
+ if (!processTxHash) {
273
278
  throw new Error('Transaction hash is undefined.')
274
279
  }
275
280
  statusResponse = (await waitForReceivingTransaction(
276
- process.txHash,
281
+ processTxHash,
277
282
  this.statusManager,
278
283
  process.type,
279
284
  step
@@ -1,11 +1,11 @@
1
1
  import type {
2
2
  Execution,
3
+ ExecutionStatus,
3
4
  LiFiStep,
4
5
  Process,
6
+ ProcessStatus,
5
7
  ProcessType,
6
- Status,
7
8
  } from '@lifi/types'
8
- import { emptyExecution } from '@lifi/types'
9
9
  import { executionState } from './executionState.js'
10
10
  import type { LiFiStepExtended } from './types.js'
11
11
  import { getProcessMessage } from './utils.js'
@@ -44,8 +44,10 @@ export class StatusManager {
44
44
  */
45
45
  initExecutionObject = (step: LiFiStepExtended): Execution => {
46
46
  if (!step.execution) {
47
- step.execution = structuredClone<Execution>(emptyExecution)
48
- step.execution.status = 'PENDING'
47
+ step.execution = {
48
+ status: 'PENDING',
49
+ process: [],
50
+ }
49
51
  this.updateStepInRoute(step)
50
52
  }
51
53
 
@@ -67,7 +69,7 @@ export class StatusManager {
67
69
  */
68
70
  updateExecution(
69
71
  step: LiFiStepExtended,
70
- status: Status,
72
+ status: ExecutionStatus,
71
73
  execution?: Partial<Execution>
72
74
  ): LiFiStep {
73
75
  if (!step.execution) {
@@ -94,7 +96,7 @@ export class StatusManager {
94
96
  findOrCreateProcess = (
95
97
  step: LiFiStepExtended,
96
98
  type: ProcessType,
97
- status?: Status
99
+ status?: ProcessStatus
98
100
  ): Process => {
99
101
  if (!step.execution?.process) {
100
102
  throw new Error("Execution hasn't been initialized.")
@@ -133,7 +135,7 @@ export class StatusManager {
133
135
  updateProcess = (
134
136
  step: LiFiStepExtended,
135
137
  type: ProcessType,
136
- status: Status,
138
+ status: ProcessStatus,
137
139
  params?: OptionalParameters
138
140
  ): Process => {
139
141
  if (!step.execution) {
@@ -7,68 +7,12 @@ export const prepareRestart = async (route: RouteExtended) => {
7
7
  const stepHasFailed = step.execution?.status === 'FAILED'
8
8
 
9
9
  if (stepHasFailed) {
10
- // await handleErrorType(walletClient, step)
11
10
  deleteFailedProcesses(step)
12
11
  deleteTransactionData(step)
13
12
  }
14
13
  }
15
14
  }
16
15
 
17
- // const handleErrorType = async (walletClient: WalletClient, step: LiFiStep) => {
18
- // const client = walletClient.extend(publicActions)
19
-
20
- // const isGasLimitError = step.execution?.process.some(
21
- // (p) => p.error?.code === LiFiErrorCode.GasLimitError
22
- // )
23
- // const isGasPriceError = step.execution?.process.some(
24
- // (p) => p.error?.code === LiFiErrorCode.TransactionUnderpriced
25
- // )
26
-
27
- // const { transactionRequest } = step
28
-
29
- // if (isGasLimitError) {
30
- // if (transactionRequest) {
31
- // let gasLimit = transactionRequest.gasLimit
32
-
33
- // try {
34
- // gasLimit = await client.estimateGas(transactionRequest)
35
- // } catch (error) {}
36
-
37
- // if (gasLimit) {
38
- // transactionRequest.gasLimit = BigNumber.from(
39
- // `${(BigInt(gasLimit.toString()) * 125n) / 100n}`
40
- // )
41
- // }
42
- // }
43
-
44
- // step.estimate.gasCosts?.forEach(
45
- // (gasCost) =>
46
- // (gasCost.limit = `${Math.round(Number(gasCost.limit) * 1.25)}`)
47
- // )
48
- // }
49
-
50
- // if (isGasPriceError) {
51
- // if (transactionRequest) {
52
- // let gasPrice = transactionRequest.gasPrice
53
-
54
- // try {
55
- // gasPrice = await client.getGasPrice()
56
- // } catch (error) {}
57
-
58
- // if (gasPrice) {
59
- // transactionRequest.gasPrice = BigNumber.from(
60
- // `${(BigInt(gasPrice.toString()) * 125n) / 100n}`
61
- // )
62
- // }
63
- // }
64
-
65
- // step.estimate.gasCosts?.forEach(
66
- // (gasCost) =>
67
- // (gasCost.price = `${Math.round(Number(gasCost.price) * 1.25)}`)
68
- // )
69
- // }
70
- // }
71
-
72
16
  const deleteFailedProcesses = (step: LiFiStepExtended) => {
73
17
  if (step.execution) {
74
18
  step.execution.process = step.execution.process.filter(
package/src/core/utils.ts CHANGED
@@ -1,12 +1,15 @@
1
1
  import {
2
2
  type LiFiStep,
3
+ type ProcessStatus,
3
4
  type ProcessType,
4
- type Status,
5
5
  type StatusMessage,
6
6
  type Substatus,
7
7
  } from '@lifi/types'
8
8
 
9
- const processMessages: Record<ProcessType, Partial<Record<Status, string>>> = {
9
+ const processMessages: Record<
10
+ ProcessType,
11
+ Partial<Record<ProcessStatus, string>>
12
+ > = {
10
13
  TOKEN_ALLOWANCE: {
11
14
  STARTED: 'Setting token allowance.',
12
15
  PENDING: 'Waiting for token allowance.',
@@ -61,7 +64,7 @@ const substatusMessages: Record<
61
64
 
62
65
  export function getProcessMessage(
63
66
  type: ProcessType,
64
- status: Status
67
+ status: ProcessStatus
65
68
  ): string | undefined {
66
69
  const processMessage = processMessages[type][status]
67
70
  return processMessage
package/src/index.ts CHANGED
@@ -1,8 +1,14 @@
1
1
  export * from '@lifi/types'
2
2
  export { config } from './config.js'
3
3
  export { EVM } from './core/EVM/EVM.js'
4
- export { getTokenAllowance } from './core/EVM/getAllowance.js'
5
- export { setTokenAllowance } from './core/EVM/setAllowance.js'
4
+ export {
5
+ getTokenAllowance,
6
+ getTokenAllowanceMulticall,
7
+ } from './core/EVM/getAllowance.js'
8
+ export {
9
+ revokeTokenApproval,
10
+ setTokenAllowance,
11
+ } from './core/EVM/setAllowance.js'
6
12
  export type {
7
13
  MultisigConfig,
8
14
  MultisigTransaction,
@@ -66,9 +66,7 @@ export const getTokenBalancesByChain = async (
66
66
  const tokenList = Object.values(tokensByChain).flat()
67
67
  const invalidTokens = tokenList.filter((token) => !isToken(token))
68
68
  if (invalidTokens.length) {
69
- throw new ValidationError(
70
- `Invalid token passed: address "${invalidTokens[0].address}" on chainId "${invalidTokens[0].chainId}"`
71
- )
69
+ throw new ValidationError(`Invalid tokens passed.`)
72
70
  }
73
71
 
74
72
  const tokenAmountsByChain: { [chainId: number]: TokenAmount[] } = {}
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/sdk'
2
- export const version = '3.0.0-beta.0'
2
+ export const version = '3.0.0-beta.2'