@openocean.finance/widget 1.0.2 → 1.0.4
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 -5
- package/src/components/AmountInput/AmountInput.tsx +2 -10
- package/src/components/AmountInput/AmountInputEndAdornment.tsx +82 -46
- package/src/components/AmountInput/PriceFormHelperText.tsx +13 -13
- package/src/components/Avatar/TokenAvatar.tsx +1 -1
- package/src/components/ChainSelect/ChainSelect.tsx +1 -1
- package/src/components/ChainSelect/useChainSelect.ts +1 -1
- package/src/components/ContractComponent/ItemPrice.tsx +1 -1
- package/src/components/ContractComponent/NFT/types.ts +1 -1
- package/src/components/Messages/WarningMessages.tsx +5 -5
- package/src/components/Messages/useMessageQueue.ts +1 -1
- package/src/components/RouteCard/RouteCard.tsx +2 -2
- package/src/components/RouteCard/RouteCardEssentials.tsx +1 -1
- package/src/components/RouteCard/getMatchingLabels.ts +1 -1
- package/src/components/RouteCard/types.ts +1 -1
- package/src/components/Routes/RoutesExpanded.tsx +1 -1
- package/src/components/Step/CircularProgress.style.tsx +1 -1
- package/src/components/Step/CircularProgress.tsx +1 -1
- package/src/components/Step/DestinationWalletAddress.tsx +2 -2
- package/src/components/Step/Step.tsx +6 -3
- package/src/components/Step/StepList.tsx +1 -1
- package/src/components/Step/StepProcess.tsx +2 -2
- package/src/components/StepActions/StepActions.tsx +5 -5
- package/src/components/StepActions/StepFees.tsx +2 -2
- package/src/components/StepActions/types.ts +3 -3
- package/src/components/Timer/RouteTimer.tsx +1 -1
- package/src/components/Timer/StepTimer.tsx +5 -5
- package/src/components/Token/Token.tsx +9 -7
- package/src/components/TokenList/TokenListItem.tsx +1 -1
- package/src/components/TokenList/types.ts +1 -1
- package/src/components/TokenRate/TokenRate.tsx +1 -1
- package/src/components/TransactionDetails.tsx +1 -1
- package/src/config/coinbase.ts +1 -1
- package/src/config/metaMask.ts +1 -1
- package/src/hooks/useAddressValidation.ts +2 -2
- package/src/hooks/useAvailableChains.ts +2 -2
- package/src/hooks/useChains.ts +1 -1
- package/src/hooks/useExplorer.ts +4 -2
- package/src/hooks/useFromTokenSufficiency.ts +1 -1
- package/src/hooks/useGasRecommendation.ts +4 -1
- package/src/hooks/useGasSufficiency.ts +7 -3
- package/src/hooks/useInitializer.ts +1 -1
- package/src/hooks/useIsBatchingSupported.ts +2 -2
- package/src/hooks/useIsCompatibleDestinationAccount.ts +1 -1
- package/src/hooks/useIsContractAddress.ts +1 -1
- package/src/hooks/useProcessMessage.ts +23 -23
- package/src/hooks/useRouteExecution.ts +5 -2
- package/src/hooks/useRoutes.ts +4 -4
- package/src/hooks/useToAddressRequirements.ts +1 -1
- package/src/hooks/useToAddressReset.ts +1 -1
- package/src/hooks/useTokenBalance.ts +5 -1
- package/src/hooks/useTokenBalances.ts +1 -1
- package/src/hooks/useTokenSearch.ts +5 -2
- package/src/hooks/useTokens.ts +6 -5
- package/src/hooks/useTools.ts +1 -1
- package/src/hooks/useTransactionDetails.ts +2 -2
- package/src/hooks/useTransactionHistory.ts +8 -2
- package/src/index.ts +2 -2
- package/src/pages/MainPage/MainWarningMessages.tsx +1 -1
- package/src/pages/RoutesPage/RoutesPage.tsx +1 -1
- package/src/pages/SelectChainPage/SelectChainPage.tsx +1 -1
- package/src/pages/SelectEnabledToolsPage.tsx +1 -1
- package/src/pages/SettingsPage/RoutePrioritySettings.tsx +1 -1
- package/src/pages/TransactionDetailsPage/TransactionDetailsPage.tsx +7 -4
- package/src/pages/TransactionDetailsPage/TransferIdCard.tsx +3 -2
- package/src/pages/TransactionHistoryPage/TransactionHistoryItem.tsx +2 -2
- package/src/pages/TransactionHistoryPage/TransactionHistoryPage.tsx +1 -1
- package/src/pages/TransactionPage/ExchangeRateBottomSheet.tsx +1 -1
- package/src/pages/TransactionPage/TokenValueBottomSheet.tsx +2 -2
- package/src/pages/TransactionPage/TransactionPage.tsx +1 -1
- package/src/pages/TransactionPage/types.ts +1 -1
- package/src/providers/WalletProvider/EVMProvider.tsx +1 -1
- package/src/providers/WalletProvider/SDKProviders.tsx +8 -2
- package/src/providers/WalletProvider/SVMProvider.tsx +1 -1
- package/src/providers/WalletProvider/UTXOProvider.tsx +1 -1
- package/src/providers/WalletProvider/useExternalWalletProvider.ts +1 -1
- package/src/providers/WidgetProvider/WidgetProvider.tsx +2 -2
- package/src/services/DebridgeService.ts +26 -107
- package/src/services/ExecuteRoute.ts +55 -26
- package/src/stores/form/types.ts +1 -1
- package/src/stores/routes/createRouteExecutionStore.ts +1 -1
- package/src/stores/routes/types.ts +1 -1
- package/src/stores/routes/utils.ts +1 -1
- package/src/stores/settings/types.ts +1 -1
- package/src/types/events.ts +6 -1
- package/src/types/token.ts +1 -1
- package/src/types/widget.ts +10 -10
- package/src/utils/chainType.ts +1 -1
- package/src/utils/converters.ts +2 -2
- package/src/utils/fees.ts +6 -1
- package/src/utils/getPriceImpact.ts +1 -1
- /package/src/icons/{lifi.ts → openocean.ts} +0 -0
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { getConnectorClient as getBigmiConnectorClient } from '@bigmi/client'
|
|
2
2
|
import { useConfig as useBigmiConfig } from '@bigmi/react'
|
|
3
|
-
import type { SDKProvider } from '@
|
|
4
|
-
import {
|
|
3
|
+
import type { SDKProvider } from '@openocean.finance/widget-sdk'
|
|
4
|
+
import {
|
|
5
|
+
ChainType,
|
|
6
|
+
EVM,
|
|
7
|
+
Solana,
|
|
8
|
+
UTXO,
|
|
9
|
+
config,
|
|
10
|
+
} from '@openocean.finance/widget-sdk'
|
|
5
11
|
import type { SignerWalletAdapter } from '@solana/wallet-adapter-base'
|
|
6
12
|
import { useWallet } from '@solana/wallet-adapter-react'
|
|
7
13
|
import { useEffect } from 'react'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChainType } from '@
|
|
1
|
+
import { ChainType } from '@openocean.finance/widget-sdk'
|
|
2
2
|
import { ConnectionContext } from '@solana/wallet-adapter-react'
|
|
3
3
|
import { type FC, type PropsWithChildren, useContext } from 'react'
|
|
4
4
|
import { isItemAllowed } from '../../utils/item.js'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BigmiContext } from '@bigmi/react'
|
|
2
|
-
import { ChainType } from '@
|
|
2
|
+
import { ChainType } from '@openocean.finance/widget-sdk'
|
|
3
3
|
import { type FC, type PropsWithChildren, useContext } from 'react'
|
|
4
4
|
import { isItemAllowed } from '../../utils/item.js'
|
|
5
5
|
import { useWidgetConfig } from '../WidgetProvider/WidgetProvider.js'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChainType } from '@
|
|
1
|
+
import { ChainType } from '@openocean.finance/widget-sdk'
|
|
2
2
|
import { useContext, useMemo } from 'react'
|
|
3
3
|
import { useWidgetConfig } from '../WidgetProvider/WidgetProvider.js'
|
|
4
4
|
import { EVMExternalContext } from './EVMExternalContext.js'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { SDKConfig } from '@
|
|
2
|
-
import { config, createConfig } from '@
|
|
1
|
+
import type { SDKConfig } from '@openocean.finance/widget-sdk'
|
|
2
|
+
import { config, createConfig } from '@openocean.finance/widget-sdk'
|
|
3
3
|
import { createContext, useContext, useId, useMemo } from 'react'
|
|
4
4
|
import { version } from '../../config/version.js'
|
|
5
5
|
import { useSettingsActions } from '../../stores/settings/useSettingsActions.js'
|
|
@@ -41,6 +41,32 @@ interface BuildSolanaBridgeDataParams {
|
|
|
41
41
|
// Define mapping between chain IDs and Debridge internal chain IDs
|
|
42
42
|
const DEBRIDGE_CHAIN_IDS: Record<number | string, string> = {
|
|
43
43
|
1151111081099710: '7565164', // Solana
|
|
44
|
+
100: '100000002', // Gnosis Chain
|
|
45
|
+
42161: '42161', // Arbitrum
|
|
46
|
+
43114: '43114', // Avalanche
|
|
47
|
+
56: '56', // BNB Chain
|
|
48
|
+
1: '1', // Ethereum
|
|
49
|
+
137: '137', // Polygon
|
|
50
|
+
250: '250', // Fantom
|
|
51
|
+
59144: '59144', // Linea
|
|
52
|
+
10: '10', // Optimism
|
|
53
|
+
8453: '8453', // Base
|
|
54
|
+
245022934: '100000001', // Neon
|
|
55
|
+
1890: '100000003', // Lightlink (suspended)
|
|
56
|
+
1088: '100000004', // Metis
|
|
57
|
+
7171: '100000005', // Bitrock
|
|
58
|
+
4158: '100000006', // CrossFi
|
|
59
|
+
388: '100000010', // Cronos zkEVM
|
|
60
|
+
1514: '100000013', // Story
|
|
61
|
+
146: '100000014', // Sonic
|
|
62
|
+
48900: '100000015', // Zircuit
|
|
63
|
+
2741: '100000017', // Abstract
|
|
64
|
+
80094: '100000020', // Berachain
|
|
65
|
+
60808: '100000021', // BOB
|
|
66
|
+
999: '100000022', // HyperEVM
|
|
67
|
+
5000: '100000023', // Mantle
|
|
68
|
+
747: '100000009', // Flow
|
|
69
|
+
32769: '100000008', // Zilliqa
|
|
44
70
|
// Other EVM chain IDs use numeric strings directly
|
|
45
71
|
}
|
|
46
72
|
|
|
@@ -59,89 +85,6 @@ const NATIVE_TOKEN_ADDRESSES = [
|
|
|
59
85
|
'', // Empty string might be used in some cases
|
|
60
86
|
].map((addr) => addr.toLowerCase())
|
|
61
87
|
|
|
62
|
-
// Contract addresses and configurations
|
|
63
|
-
const CONTRACT_CONFIG: Record<number, Record<string, any>> = {
|
|
64
|
-
56: {
|
|
65
|
-
// BSC
|
|
66
|
-
debridge: '0x...', // Supplement Debridge contract address
|
|
67
|
-
ooSwap: '0x22fefa40802E7aD7878FdE48700462e3f920E2C5',
|
|
68
|
-
bridgeId: { debridge: 22 /* Example ID */ },
|
|
69
|
-
messageBus: { debridge: '0x...' /* Example */ },
|
|
70
|
-
middlewareId: { ooSwap: 11 },
|
|
71
|
-
},
|
|
72
|
-
250: {
|
|
73
|
-
// Fantom
|
|
74
|
-
debridge: '0x...',
|
|
75
|
-
ooSwap: '0x521a8903B8D4C21b55768aE14f6cA31879B98d5e',
|
|
76
|
-
bridgeId: { debridge: 22 },
|
|
77
|
-
messageBus: { debridge: '0x...' },
|
|
78
|
-
middlewareId: { ooSwap: 5 },
|
|
79
|
-
},
|
|
80
|
-
137: {
|
|
81
|
-
// Polygon
|
|
82
|
-
debridge: '0x...',
|
|
83
|
-
ooSwap: '0x22fefa40802E7aD7878FdE48700462e3f920E2C5',
|
|
84
|
-
bridgeId: { debridge: 22 },
|
|
85
|
-
messageBus: { debridge: '0x...' },
|
|
86
|
-
middlewareId: { ooSwap: 7 },
|
|
87
|
-
},
|
|
88
|
-
43114: {
|
|
89
|
-
// Avalanche
|
|
90
|
-
debridge: '0x...',
|
|
91
|
-
ooSwap: '0x521a8903B8D4C21b55768aE14f6cA31879B98d5e',
|
|
92
|
-
bridgeId: { debridge: 22 },
|
|
93
|
-
messageBus: { debridge: '0x...' },
|
|
94
|
-
middlewareId: { ooSwap: 7 },
|
|
95
|
-
},
|
|
96
|
-
1: {
|
|
97
|
-
// Ethereum
|
|
98
|
-
debridge: '0x...',
|
|
99
|
-
ooSwap: '0xf951a9ea6b8400de7094d4b2b8d2ff2176d7ca81',
|
|
100
|
-
bridgeId: { debridge: 22 },
|
|
101
|
-
messageBus: { debridge: '0x...' },
|
|
102
|
-
middlewareId: { ooSwap: 11 },
|
|
103
|
-
},
|
|
104
|
-
42161: {
|
|
105
|
-
// Arbitrum
|
|
106
|
-
debridge: '0x65C757C04141a1602705F1F90260FEd66a86d0b8',
|
|
107
|
-
ooSwap: '0x900822ea09123b5583ef5ca8fd8ca542ea21699a',
|
|
108
|
-
bridgeId: { debridge: 22 },
|
|
109
|
-
messageBus: { debridge: '0x...' /* Needs supplement */ },
|
|
110
|
-
middlewareId: { ooSwap: 6 },
|
|
111
|
-
},
|
|
112
|
-
10: {
|
|
113
|
-
// Optimism
|
|
114
|
-
debridge: '0x...',
|
|
115
|
-
ooSwap: '0x521a8903B8D4C21b55768aE14f6cA31879B98d5e',
|
|
116
|
-
bridgeId: { debridge: 22 },
|
|
117
|
-
messageBus: { debridge: '0x...' },
|
|
118
|
-
middlewareId: { ooSwap: 2 },
|
|
119
|
-
},
|
|
120
|
-
324: {
|
|
121
|
-
// zkSync Era
|
|
122
|
-
debridge: '0x...',
|
|
123
|
-
ooSwap: '0xB6d35eE980Cde5e706C0866DF0122b076D26C44d',
|
|
124
|
-
bridgeId: { debridge: 22 },
|
|
125
|
-
messageBus: { debridge: '0x...' },
|
|
126
|
-
middlewareId: { ooSwap: 1 },
|
|
127
|
-
},
|
|
128
|
-
8453: {
|
|
129
|
-
// Base
|
|
130
|
-
debridge: '0x4045734fe21c7B7E0cE516BE009780Cc2BA39A8f',
|
|
131
|
-
// ooSwap: '...', // Base chain might not have ooSwap
|
|
132
|
-
bridgeId: { debridge: 3 },
|
|
133
|
-
messageBus: { debridge: '0x...' /* Needs supplement */ },
|
|
134
|
-
// middlewareId: {},
|
|
135
|
-
},
|
|
136
|
-
7565164: {
|
|
137
|
-
// Solana (Special handling)
|
|
138
|
-
debridge: '', // Solana might not need EVM address, but program ID
|
|
139
|
-
bridgeId: { debridge: -1 /* Placeholder */ },
|
|
140
|
-
messageBus: {},
|
|
141
|
-
},
|
|
142
|
-
// ... Add other chain Debridge configurations
|
|
143
|
-
}
|
|
144
|
-
|
|
145
88
|
// Native token information
|
|
146
89
|
const NATIVE_TOKENS: Record<number, Asset> = {
|
|
147
90
|
1: {
|
|
@@ -292,30 +235,6 @@ export class DebridgeService {
|
|
|
292
235
|
return NATIVE_TOKENS[chainId]
|
|
293
236
|
}
|
|
294
237
|
|
|
295
|
-
/**
|
|
296
|
-
* Get contract configuration information for specified chain and contract type
|
|
297
|
-
* @param chainId Chain ID
|
|
298
|
-
* @param contractType Contract type ('debridge', 'ooSwap', 'bridgeId', 'messageBus', 'middlewareId')
|
|
299
|
-
* @param subType Optional, for getting specific values under 'bridgeId', 'messageBus', 'middlewareId'
|
|
300
|
-
* @returns Configuration value or undefined
|
|
301
|
-
*/
|
|
302
|
-
private static getContractConfig(
|
|
303
|
-
chainId: number,
|
|
304
|
-
contractType: string,
|
|
305
|
-
subType?: string
|
|
306
|
-
): any {
|
|
307
|
-
const chainConfig = CONTRACT_CONFIG[chainId]
|
|
308
|
-
if (!chainConfig) {
|
|
309
|
-
console.warn(`No contract config found for chainId: ${chainId}`)
|
|
310
|
-
return undefined
|
|
311
|
-
}
|
|
312
|
-
const typeConfig = chainConfig[contractType]
|
|
313
|
-
if (subType) {
|
|
314
|
-
return typeConfig ? typeConfig[subType] : undefined
|
|
315
|
-
}
|
|
316
|
-
return typeConfig
|
|
317
|
-
}
|
|
318
|
-
|
|
319
238
|
/**
|
|
320
239
|
* Get Debridge internal chain ID
|
|
321
240
|
* @param chainId Original chain ID
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import type { ExecutionStatus, LiFiStep, Process, Route } from '@lifi/sdk'
|
|
2
1
|
import type { Account } from '@openocean.finance/wallet-management'
|
|
2
|
+
import type {
|
|
3
|
+
ExecutionStatus,
|
|
4
|
+
OpenOceanStep,
|
|
5
|
+
Process,
|
|
6
|
+
Route,
|
|
7
|
+
} from '@openocean.finance/widget-sdk'
|
|
3
8
|
import { Connection, Transaction, VersionedTransaction } from '@solana/web3.js'
|
|
4
9
|
import type { Config } from 'wagmi'
|
|
5
10
|
import { getPublicClient, getWalletClient } from 'wagmi/actions'
|
|
@@ -22,7 +27,7 @@ interface ExecuteRouteOptions {
|
|
|
22
27
|
onOpenWalletMenu?: () => void
|
|
23
28
|
}
|
|
24
29
|
|
|
25
|
-
interface
|
|
30
|
+
interface ExtendedOpenOceanStep extends OpenOceanStep {
|
|
26
31
|
execution?: {
|
|
27
32
|
status: ExecutionStatus
|
|
28
33
|
process: Process[]
|
|
@@ -33,7 +38,7 @@ interface ExtendedLiFiStep extends LiFiStep {
|
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
interface ExtendedRoute extends Route {
|
|
36
|
-
steps:
|
|
41
|
+
steps: ExtendedOpenOceanStep[]
|
|
37
42
|
data: {
|
|
38
43
|
prependedOperatingExpenseCost: string
|
|
39
44
|
}
|
|
@@ -41,7 +46,7 @@ interface ExtendedRoute extends Route {
|
|
|
41
46
|
|
|
42
47
|
// Execute Solana transaction
|
|
43
48
|
async function executeSolanaSwap(
|
|
44
|
-
step:
|
|
49
|
+
step: ExtendedOpenOceanStep,
|
|
45
50
|
options: ExecuteRouteOptions,
|
|
46
51
|
process: Process,
|
|
47
52
|
route: ExtendedRoute
|
|
@@ -53,7 +58,9 @@ async function executeSolanaSwap(
|
|
|
53
58
|
}
|
|
54
59
|
|
|
55
60
|
let transaction: any = ''
|
|
56
|
-
|
|
61
|
+
const connection = new Connection(
|
|
62
|
+
'https://burned-practical-bird.solana-mainnet.quiknode.pro/33f4786133c252415e194b29ee69ffc7671480ab'
|
|
63
|
+
)
|
|
57
64
|
const txData: any = step.transactionRequest?.data || ''
|
|
58
65
|
const dexId = step.transactionRequest?.type || 0
|
|
59
66
|
if (step.action.fromChainId === step.action.toChainId) {
|
|
@@ -64,10 +71,7 @@ async function executeSolanaSwap(
|
|
|
64
71
|
}
|
|
65
72
|
} else {
|
|
66
73
|
transaction = VersionedTransaction.deserialize(hexToUint8Array(txData.slice(2)))
|
|
67
|
-
|
|
68
|
-
connection = new Connection(
|
|
69
|
-
'https://burned-practical-bird.solana-mainnet.quiknode.pro/33f4786133c252415e194b29ee69ffc7671480ab'
|
|
70
|
-
)
|
|
74
|
+
|
|
71
75
|
const { blockhash } = await connection.getLatestBlockhash();
|
|
72
76
|
transaction.message.recentBlockhash = blockhash;
|
|
73
77
|
}
|
|
@@ -84,7 +88,6 @@ async function executeSolanaSwap(
|
|
|
84
88
|
throw new Error('Failed to sign transaction')
|
|
85
89
|
}
|
|
86
90
|
|
|
87
|
-
|
|
88
91
|
// Serialize signed transaction
|
|
89
92
|
const serializedTransaction = signedTx.serialize({
|
|
90
93
|
verifySignatures: false,
|
|
@@ -136,24 +139,44 @@ async function executeSolanaSwap(
|
|
|
136
139
|
|
|
137
140
|
// Execute EVM transaction
|
|
138
141
|
async function executeEvmSwap(
|
|
139
|
-
step:
|
|
142
|
+
step: ExtendedOpenOceanStep,
|
|
140
143
|
options: ExecuteRouteOptions,
|
|
141
144
|
process: Process,
|
|
142
145
|
route: ExtendedRoute
|
|
143
146
|
): Promise<void> {
|
|
144
147
|
try {
|
|
145
148
|
const walletClient = await getWalletClient(options.wagmiConfig)
|
|
149
|
+
|
|
150
|
+
// Check if wallet is connected
|
|
146
151
|
if (!walletClient) {
|
|
147
|
-
// If disconnect callback exists, disconnect the current connection first
|
|
148
152
|
if (options.account?.connector && options.onDisconnect) {
|
|
149
153
|
await options.onDisconnect(options.account)
|
|
150
154
|
}
|
|
151
|
-
// Open wallet menu to let user reconnect
|
|
152
155
|
if (options.onOpenWalletMenu) {
|
|
153
156
|
options.onOpenWalletMenu()
|
|
154
157
|
}
|
|
155
158
|
throw new Error('Please connect wallet first')
|
|
156
159
|
}
|
|
160
|
+
|
|
161
|
+
// Check if current chain matches target chain
|
|
162
|
+
const currentChainId = walletClient.chain.id
|
|
163
|
+
const targetChainId = step.action.fromChainId
|
|
164
|
+
|
|
165
|
+
if (currentChainId !== targetChainId) {
|
|
166
|
+
try {
|
|
167
|
+
// Try to switch to target chain
|
|
168
|
+
await walletClient.switchChain({ id: targetChainId })
|
|
169
|
+
|
|
170
|
+
// Get updated walletClient after chain switch
|
|
171
|
+
const updatedWalletClient = await getWalletClient(options.wagmiConfig)
|
|
172
|
+
if (!updatedWalletClient || updatedWalletClient.chain.id !== targetChainId) {
|
|
173
|
+
throw new Error('Failed to switch chain')
|
|
174
|
+
}
|
|
175
|
+
} catch (error) {
|
|
176
|
+
console.error('Failed to switch chain:', error)
|
|
177
|
+
throw new Error(`Please manually switch to chain ID: ${targetChainId}`)
|
|
178
|
+
}
|
|
179
|
+
}
|
|
157
180
|
|
|
158
181
|
const publicClient = getPublicClient(options.wagmiConfig)
|
|
159
182
|
if (!publicClient) {
|
|
@@ -168,20 +191,24 @@ async function executeEvmSwap(
|
|
|
168
191
|
throw new Error('Public client not found')
|
|
169
192
|
}
|
|
170
193
|
|
|
171
|
-
console.log(
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
194
|
+
console.log(
|
|
195
|
+
'Current Chain:',
|
|
196
|
+
publicClient.chain?.id,
|
|
197
|
+
publicClient.chain?.name
|
|
198
|
+
)
|
|
199
|
+
console.log('Token Address:', step.action.fromToken.address)
|
|
200
|
+
console.log('Token Chain ID:', step.action.fromToken.chainId)
|
|
201
|
+
console.log('Owner Address:', walletClient.account.address)
|
|
202
|
+
console.log('Spender Address:', step.estimate.approvalAddress)
|
|
176
203
|
|
|
177
204
|
// Check token approval
|
|
178
205
|
if (
|
|
179
206
|
step.action.fromToken.address !==
|
|
180
207
|
'0x0000000000000000000000000000000000000000'
|
|
181
208
|
) {
|
|
182
|
-
let allowance
|
|
209
|
+
let allowance = 0n
|
|
183
210
|
try {
|
|
184
|
-
|
|
211
|
+
allowance = (await publicClient.readContract({
|
|
185
212
|
address: step.action.fromToken.address as `0x${string}`,
|
|
186
213
|
abi: [
|
|
187
214
|
{
|
|
@@ -200,18 +227,20 @@ async function executeEvmSwap(
|
|
|
200
227
|
walletClient.account.address,
|
|
201
228
|
step.estimate.approvalAddress as `0x${string}`,
|
|
202
229
|
],
|
|
203
|
-
})) as bigint
|
|
230
|
+
})) as bigint
|
|
204
231
|
} catch (error) {
|
|
205
|
-
console.error(
|
|
232
|
+
console.error('Failed to read allowance:', error)
|
|
206
233
|
// Log additional context
|
|
207
|
-
console.error(
|
|
208
|
-
console.error(
|
|
209
|
-
console.error(
|
|
234
|
+
console.error('Context - Step:', JSON.stringify(step, null, 2))
|
|
235
|
+
console.error('Context - Route:', JSON.stringify(route, null, 2))
|
|
236
|
+
console.error('Context - Public Client Chain:', publicClient.chain)
|
|
210
237
|
// Re-throw the error or handle it appropriately
|
|
211
238
|
// throw new Error(`Failed to read allowance for token ${step.action.fromToken.address}: ${error instanceof Error ? error.message : String(error)}`);
|
|
212
239
|
}
|
|
213
240
|
|
|
214
|
-
const amount =
|
|
241
|
+
const amount =
|
|
242
|
+
BigInt(step.action.fromAmount) +
|
|
243
|
+
BigInt(route?.data?.prependedOperatingExpenseCost || '0')
|
|
215
244
|
if (allowance < BigInt(amount)) {
|
|
216
245
|
const approvalAmount = options.infiniteApproval
|
|
217
246
|
? BigInt(
|
package/src/stores/form/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Route, RouteExtended } from '@
|
|
1
|
+
import type { Route, RouteExtended } from '@openocean.finance/widget-sdk'
|
|
2
2
|
import type { StateCreator } from 'zustand'
|
|
3
3
|
import { persist } from 'zustand/middleware'
|
|
4
4
|
import { createWithEqualityFn } from 'zustand/traditional'
|
package/src/types/events.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
ChainId,
|
|
3
|
+
ChainType,
|
|
4
|
+
Process,
|
|
5
|
+
Route,
|
|
6
|
+
} from '@openocean.finance/widget-sdk'
|
|
2
7
|
import type { DefaultValues } from '../stores/form/types.js'
|
|
3
8
|
import type { SettingsProps } from '../stores/settings/types.js'
|
|
4
9
|
import type { NavigationRouteType } from '../utils/navigationRoutes.js'
|
package/src/types/token.ts
CHANGED
package/src/types/widget.ts
CHANGED
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
BaseToken,
|
|
3
|
-
ChainType,
|
|
4
|
-
ContractCall,
|
|
5
|
-
Order,
|
|
6
|
-
RouteOptions,
|
|
7
|
-
SDKConfig,
|
|
8
|
-
StaticToken,
|
|
9
|
-
Token,
|
|
10
|
-
} from '@lifi/sdk'
|
|
11
1
|
import type {
|
|
12
2
|
Components,
|
|
13
3
|
PaletteMode,
|
|
@@ -17,6 +7,16 @@ import type {
|
|
|
17
7
|
Theme,
|
|
18
8
|
} from '@mui/material'
|
|
19
9
|
import type { TypographyOptions } from '@mui/material/styles/createTypography.js'
|
|
10
|
+
import type {
|
|
11
|
+
BaseToken,
|
|
12
|
+
ChainType,
|
|
13
|
+
ContractCall,
|
|
14
|
+
Order,
|
|
15
|
+
RouteOptions,
|
|
16
|
+
SDKConfig,
|
|
17
|
+
StaticToken,
|
|
18
|
+
Token,
|
|
19
|
+
} from '@openocean.finance/widget-sdk'
|
|
20
20
|
import type {
|
|
21
21
|
CSSProperties,
|
|
22
22
|
MutableRefObject,
|
package/src/utils/chainType.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isUTXOAddress } from '@bigmi/core'
|
|
2
|
-
import { ChainId, ChainType, isSVMAddress } from '@
|
|
2
|
+
import { ChainId, ChainType, isSVMAddress } from '@openocean.finance/widget-sdk'
|
|
3
3
|
import { isAddress as isEVMAddress } from 'viem'
|
|
4
4
|
|
|
5
5
|
const chainTypeAddressValidation = {
|
package/src/utils/converters.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
Substatus,
|
|
8
8
|
TokenAmount,
|
|
9
9
|
ToolsResponse,
|
|
10
|
-
} from '@
|
|
10
|
+
} from '@openocean.finance/widget-sdk'
|
|
11
11
|
import type { RouteExecution } from '../stores/routes/types.js'
|
|
12
12
|
import { formatTokenPrice } from './format.js'
|
|
13
13
|
|
|
@@ -146,7 +146,7 @@ export const buildRouteFromTxHistory = (
|
|
|
146
146
|
steps: [
|
|
147
147
|
{
|
|
148
148
|
id: crypto.randomUUID(),
|
|
149
|
-
type: '
|
|
149
|
+
type: 'openocean',
|
|
150
150
|
tool: tx.tool,
|
|
151
151
|
toolDetails: usedTool,
|
|
152
152
|
action: {
|
package/src/utils/fees.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
FeeCost,
|
|
3
|
+
GasCost,
|
|
4
|
+
RouteExtended,
|
|
5
|
+
Token,
|
|
6
|
+
} from '@openocean.finance/widget-sdk'
|
|
2
7
|
import { formatTokenPrice } from './format.js'
|
|
3
8
|
|
|
4
9
|
export interface FeesBreakdown {
|
|
File without changes
|