@lifi/sdk 3.0.0-alpha.55 → 3.0.0-alpha.57
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 +4 -4
- package/src/_cjs/core/EVM/EVM.js +3 -3
- package/src/_cjs/core/EVM/EVM.js.map +1 -1
- package/src/_cjs/core/EVM/EVMStepExecutor.js +3 -0
- package/src/_cjs/core/EVM/EVMStepExecutor.js.map +1 -1
- package/src/_cjs/core/EVM/getENSAddress.js +20 -0
- package/src/_cjs/core/EVM/getENSAddress.js.map +1 -0
- package/src/_cjs/core/EVM/publicClient.js +8 -0
- package/src/_cjs/core/EVM/publicClient.js.map +1 -1
- package/src/_cjs/core/EVM/utils.js +2 -2
- package/src/_cjs/core/EVM/utils.js.map +1 -1
- package/src/_cjs/core/Solana/Solana.js +4 -10
- package/src/_cjs/core/Solana/Solana.js.map +1 -1
- package/src/_cjs/core/Solana/getSNSAddress.js +26 -0
- package/src/_cjs/core/Solana/getSNSAddress.js.map +1 -0
- package/src/_cjs/core/Solana/isAddress.js +15 -0
- package/src/_cjs/core/Solana/isAddress.js.map +1 -0
- package/src/_cjs/core/checkBalance.js +1 -1
- package/src/_cjs/core/checkBalance.js.map +1 -1
- package/src/_cjs/core/utils.js +1 -1
- package/src/_cjs/core/utils.js.map +1 -1
- package/src/_cjs/core/waitForReceivingTransaction.js +2 -2
- package/src/_cjs/core/waitForReceivingTransaction.js.map +1 -1
- package/src/_cjs/index.js +1 -0
- package/src/_cjs/index.js.map +1 -1
- package/src/_cjs/services/api.js +5 -7
- package/src/_cjs/services/api.js.map +1 -1
- package/src/_cjs/services/getNameServiceAddress.js +29 -0
- package/src/_cjs/services/getNameServiceAddress.js.map +1 -0
- package/src/_cjs/version.js +1 -1
- package/src/_esm/core/EVM/EVM.js +3 -3
- package/src/_esm/core/EVM/EVM.js.map +1 -1
- package/src/_esm/core/EVM/EVMStepExecutor.js +3 -0
- package/src/_esm/core/EVM/EVMStepExecutor.js.map +1 -1
- package/src/_esm/core/EVM/getENSAddress.js +17 -0
- package/src/_esm/core/EVM/getENSAddress.js.map +1 -0
- package/src/_esm/core/EVM/publicClient.js +9 -0
- package/src/_esm/core/EVM/publicClient.js.map +1 -1
- package/src/_esm/core/EVM/utils.js +2 -3
- package/src/_esm/core/EVM/utils.js.map +1 -1
- package/src/_esm/core/Solana/Solana.js +4 -10
- package/src/_esm/core/Solana/Solana.js.map +1 -1
- package/src/_esm/core/Solana/getSNSAddress.js +26 -0
- package/src/_esm/core/Solana/getSNSAddress.js.map +1 -0
- package/src/_esm/core/Solana/isAddress.js +11 -0
- package/src/_esm/core/Solana/isAddress.js.map +1 -0
- package/src/_esm/core/checkBalance.js +1 -1
- package/src/_esm/core/checkBalance.js.map +1 -1
- package/src/_esm/core/utils.js +1 -1
- package/src/_esm/core/utils.js.map +1 -1
- package/src/_esm/core/waitForReceivingTransaction.js +2 -2
- package/src/_esm/core/waitForReceivingTransaction.js.map +1 -1
- package/src/_esm/index.js +1 -0
- package/src/_esm/index.js.map +1 -1
- package/src/_esm/services/api.js +3 -5
- package/src/_esm/services/api.js.map +1 -1
- package/src/_esm/services/getNameServiceAddress.js +25 -0
- package/src/_esm/services/getNameServiceAddress.js.map +1 -0
- package/src/_esm/version.js +1 -1
- package/src/_types/core/EVM/EVM.d.ts.map +1 -1
- package/src/_types/core/EVM/EVMStepExecutor.d.ts.map +1 -1
- package/src/_types/core/EVM/getENSAddress.d.ts +2 -0
- package/src/_types/core/EVM/getENSAddress.d.ts.map +1 -0
- package/src/_types/core/EVM/publicClient.d.ts.map +1 -1
- package/src/_types/core/EVM/utils.d.ts +1 -1
- package/src/_types/core/EVM/utils.d.ts.map +1 -1
- package/src/_types/core/Solana/Solana.d.ts.map +1 -1
- package/src/_types/core/Solana/getSNSAddress.d.ts +2 -0
- package/src/_types/core/Solana/getSNSAddress.d.ts.map +1 -0
- package/src/_types/core/Solana/isAddress.d.ts +2 -0
- package/src/_types/core/Solana/isAddress.d.ts.map +1 -0
- package/src/_types/core/provider.d.ts.map +1 -1
- package/src/_types/core/types.d.ts +1 -0
- package/src/_types/core/types.d.ts.map +1 -1
- package/src/_types/index.d.ts +1 -0
- 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 +2 -2
- package/src/_types/services/api.d.ts.map +1 -1
- package/src/_types/services/getNameServiceAddress.d.ts +3 -0
- package/src/_types/services/getNameServiceAddress.d.ts.map +1 -0
- package/src/_types/utils/utils.d.ts.map +1 -1
- package/src/_types/version.d.ts +1 -1
- package/src/core/EVM/EVM.ts +3 -3
- package/src/core/EVM/EVMStepExecutor.ts +6 -0
- package/src/core/EVM/getENSAddress.ts +18 -0
- package/src/core/EVM/publicClient.ts +9 -1
- package/src/core/EVM/utils.ts +2 -3
- package/src/core/Solana/Solana.ts +4 -9
- package/src/core/Solana/getSNSAddress.ts +33 -0
- package/src/core/Solana/isAddress.ts +10 -0
- package/src/core/types.ts +1 -0
- package/src/core/waitForReceivingTransaction.ts +1 -1
- package/src/index.ts +1 -0
- package/src/services/api.ts +6 -8
- package/src/services/getNameServiceAddress.ts +30 -0
- package/src/version.ts +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { ChainId } from '@lifi/types'
|
|
1
2
|
import type { PublicClient } from 'viem'
|
|
2
3
|
import { createPublicClient, fallback, http } from 'viem'
|
|
3
|
-
import type
|
|
4
|
+
import { mainnet, type Chain } from 'viem/chains'
|
|
4
5
|
import { config } from '../../config.js'
|
|
5
6
|
import { getRpcUrls } from '../rpc.js'
|
|
6
7
|
|
|
@@ -32,6 +33,13 @@ export const getPublicClient = async (
|
|
|
32
33
|
public: { http: _chain.metamask.rpcUrls },
|
|
33
34
|
},
|
|
34
35
|
}
|
|
36
|
+
// Add ENS contracts
|
|
37
|
+
if (chain.id === ChainId.ETH) {
|
|
38
|
+
chain.contracts = {
|
|
39
|
+
...mainnet.contracts,
|
|
40
|
+
...chain.contracts,
|
|
41
|
+
}
|
|
42
|
+
}
|
|
35
43
|
publicClients[chainId] = createPublicClient({
|
|
36
44
|
chain: chain,
|
|
37
45
|
transport: fallback(fallbackTransports),
|
package/src/core/EVM/utils.ts
CHANGED
|
@@ -42,8 +42,7 @@ export const getMulticallAddress = async (
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
// Modified viem retryDelay exponential backoff function.
|
|
45
|
-
// Together with adjusted retryCount gives us 25 seconds to wait for the block or transaction.
|
|
46
45
|
export const retryDelay = ({ count }: { count: number; error: Error }) =>
|
|
47
|
-
Math.min(~~(1 << count) * 200,
|
|
46
|
+
Math.min(~~(1 << count) * 200, 3000)
|
|
48
47
|
|
|
49
|
-
export const retryCount =
|
|
48
|
+
export const retryCount = 20
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ChainType } from '@lifi/types'
|
|
2
|
-
import { PublicKey } from '@solana/web3.js'
|
|
3
2
|
import type { StepExecutorOptions } from '../types.js'
|
|
4
3
|
import { SolanaStepExecutor } from './SolanaStepExecutor.js'
|
|
4
|
+
import { getSNSAddress } from './getSNSAddress.js'
|
|
5
5
|
import { getSolanaBalance } from './getSolanaBalance.js'
|
|
6
|
+
import { isAddress } from './isAddress.js'
|
|
6
7
|
import type { SolanaProvider, SolanaProviderOptions } from './types.js'
|
|
7
8
|
|
|
8
9
|
export function Solana(options?: SolanaProviderOptions): SolanaProvider {
|
|
@@ -11,14 +12,8 @@ export function Solana(options?: SolanaProviderOptions): SolanaProvider {
|
|
|
11
12
|
get type() {
|
|
12
13
|
return ChainType.SVM
|
|
13
14
|
},
|
|
14
|
-
isAddress
|
|
15
|
-
|
|
16
|
-
new PublicKey(address)
|
|
17
|
-
return true
|
|
18
|
-
} catch (error) {
|
|
19
|
-
return false
|
|
20
|
-
}
|
|
21
|
-
},
|
|
15
|
+
isAddress,
|
|
16
|
+
resolveAddress: getSNSAddress,
|
|
22
17
|
getBalance: getSolanaBalance,
|
|
23
18
|
async getStepExecutor(
|
|
24
19
|
options: StepExecutorOptions
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { isAddress } from './isAddress.js'
|
|
2
|
+
|
|
3
|
+
interface SNSResult {
|
|
4
|
+
s: 'ok' | 'error'
|
|
5
|
+
result: string
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// Subject to change
|
|
9
|
+
// https://github.com/Bonfida/sns-sdk?tab=readme-ov-file#sdk-proxy
|
|
10
|
+
export const getSNSAddress = async (name: string) => {
|
|
11
|
+
try {
|
|
12
|
+
if (!name.endsWith('.sol')) {
|
|
13
|
+
return
|
|
14
|
+
}
|
|
15
|
+
// const rpcUrl = await getRpcUrl(ChainId.SOL)
|
|
16
|
+
const snsWorkerUrl = `https://sns-sdk-proxy.bonfida.workers.dev/resolve/${name}`
|
|
17
|
+
const response: Response = await fetch(snsWorkerUrl)
|
|
18
|
+
if (!response.ok) {
|
|
19
|
+
return
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const data: SNSResult = await response.json()
|
|
23
|
+
|
|
24
|
+
if (!isAddress(data.result)) {
|
|
25
|
+
return
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return data.result
|
|
29
|
+
} catch (_) {
|
|
30
|
+
// ignore
|
|
31
|
+
return
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/core/types.ts
CHANGED
|
@@ -12,6 +12,7 @@ import type { WalletClient } from 'viem'
|
|
|
12
12
|
export interface SDKProvider {
|
|
13
13
|
readonly type: ChainType
|
|
14
14
|
isAddress(address: string): boolean
|
|
15
|
+
resolveAddress(name: string): Promise<string | undefined>
|
|
15
16
|
getStepExecutor(options: StepExecutorOptions): Promise<StepExecutor>
|
|
16
17
|
getBalance(walletAddress: string, tokens: Token[]): Promise<TokenAmount[]>
|
|
17
18
|
}
|
|
@@ -23,10 +23,10 @@ export async function waitForReceivingTransaction(
|
|
|
23
23
|
let statusResponse: StatusResponse
|
|
24
24
|
try {
|
|
25
25
|
statusResponse = await getStatus({
|
|
26
|
-
bridge: step.tool,
|
|
27
26
|
fromChain: step.action.fromChainId,
|
|
28
27
|
toChain: step.action.toChainId,
|
|
29
28
|
txHash,
|
|
29
|
+
...(step.tool !== 'custom' && { bridge: step.tool }),
|
|
30
30
|
})
|
|
31
31
|
} catch (e: any) {
|
|
32
32
|
console.debug('Fetching status from backend failed.', e)
|
package/src/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ export { createConfig } from './createConfig.js'
|
|
|
12
12
|
export * from './helpers.js'
|
|
13
13
|
export * from './services/api.js'
|
|
14
14
|
export * from './services/balance.js'
|
|
15
|
+
export * from './services/getNameServiceAddress.js'
|
|
15
16
|
export * from './types/index.js'
|
|
16
17
|
export * from './utils/errors.js'
|
|
17
18
|
export { LiFiError, type ErrorCode } from './utils/errors.js'
|
package/src/services/api.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type {
|
|
|
5
5
|
ChainsResponse,
|
|
6
6
|
ConnectionsRequest,
|
|
7
7
|
ConnectionsResponse,
|
|
8
|
-
|
|
8
|
+
ContractCallsQuoteRequest,
|
|
9
9
|
ExtendedChain,
|
|
10
10
|
GasRecommendationRequest,
|
|
11
11
|
GasRecommendationResponse,
|
|
@@ -132,21 +132,19 @@ export const getQuote = async (
|
|
|
132
132
|
* @throws {LiFiError} - Throws a LiFiError if request fails
|
|
133
133
|
* @returns - Returns step.
|
|
134
134
|
*/
|
|
135
|
-
export const
|
|
136
|
-
params:
|
|
135
|
+
export const getContractCallsQuote = async (
|
|
136
|
+
params: ContractCallsQuoteRequest,
|
|
137
137
|
options?: RequestOptions
|
|
138
138
|
): Promise<LiFiStep> => {
|
|
139
139
|
// validation
|
|
140
|
-
const requiredParameters: Array<keyof
|
|
140
|
+
const requiredParameters: Array<keyof ContractCallsQuoteRequest> = [
|
|
141
141
|
'fromChain',
|
|
142
142
|
'fromToken',
|
|
143
143
|
'fromAddress',
|
|
144
144
|
'toChain',
|
|
145
145
|
'toToken',
|
|
146
146
|
'toAmount',
|
|
147
|
-
'
|
|
148
|
-
'toContractCallData',
|
|
149
|
-
'toContractGasLimit',
|
|
147
|
+
'contractCalls',
|
|
150
148
|
]
|
|
151
149
|
requiredParameters.forEach((requiredParameter) => {
|
|
152
150
|
if (!params[requiredParameter]) {
|
|
@@ -171,7 +169,7 @@ export const getContractCallQuote = async (
|
|
|
171
169
|
// send request
|
|
172
170
|
try {
|
|
173
171
|
const response = await request<LiFiStep>(
|
|
174
|
-
`${_config.apiUrl}/quote/
|
|
172
|
+
`${_config.apiUrl}/quote/contractCalls`,
|
|
175
173
|
{
|
|
176
174
|
method: 'POST',
|
|
177
175
|
headers: {
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ChainType } from '@lifi/types'
|
|
2
|
+
import { config } from '../config.js'
|
|
3
|
+
|
|
4
|
+
export const getNameServiceAddress = async (
|
|
5
|
+
name: string,
|
|
6
|
+
chainType?: ChainType
|
|
7
|
+
): Promise<string | undefined> => {
|
|
8
|
+
try {
|
|
9
|
+
let providers = config.get().providers
|
|
10
|
+
if (chainType) {
|
|
11
|
+
providers = providers.filter((provider) => provider.type === chainType)
|
|
12
|
+
}
|
|
13
|
+
const resolvers = providers.map((provider) => provider.resolveAddress)
|
|
14
|
+
if (!resolvers.length) {
|
|
15
|
+
return
|
|
16
|
+
}
|
|
17
|
+
const result = await Promise.any(
|
|
18
|
+
resolvers.map(async (resolve) => {
|
|
19
|
+
const address = await resolve(name)
|
|
20
|
+
if (!address) {
|
|
21
|
+
throw undefined
|
|
22
|
+
}
|
|
23
|
+
return address
|
|
24
|
+
})
|
|
25
|
+
)
|
|
26
|
+
return result
|
|
27
|
+
} catch (_) {
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
}
|
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.57'
|