@openocean.finance/widget 1.0.43 → 1.0.45
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/dist/esm/App.js.map +1 -1
- package/dist/esm/AppDrawer.style.d.ts +1 -1
- package/dist/esm/components/ActiveTransactions/ActiveTransactions.style.d.ts +2 -2
- package/dist/esm/components/AmountInput/AmountInput.style.d.ts +1 -1
- package/dist/esm/components/AmountInput/AmountInputAdornment.style.d.ts +1 -1
- package/dist/esm/components/AmountInput/AmountInputEndAdornment.js +37 -33
- package/dist/esm/components/AmountInput/AmountInputEndAdornment.js.map +1 -1
- package/dist/esm/components/Avatar/Avatar.style.d.ts +1 -1
- package/dist/esm/components/Avatar/SmallAvatar.d.ts +1 -1
- package/dist/esm/components/BaseTransactionButton/BaseTransactionButton.js +1 -1
- package/dist/esm/components/BaseTransactionButton/BaseTransactionButton.js.map +1 -1
- package/dist/esm/components/ButtonTertiary.d.ts +1 -1
- package/dist/esm/components/Card/CardHeader.d.ts +1 -1
- package/dist/esm/components/Card/CardIconButton.d.ts +1 -1
- package/dist/esm/components/Card/InputCard.d.ts +1 -1
- package/dist/esm/components/ContractComponent/NFT/NFT.style.d.ts +1 -1
- package/dist/esm/components/Header/Header.style.d.ts +2 -2
- package/dist/esm/components/Header/SettingsButton.style.d.ts +2 -2
- package/dist/esm/components/Header/WalletHeader.js +4 -4
- package/dist/esm/components/Header/WalletHeader.js.map +1 -1
- package/dist/esm/components/ListItem/ListItem.d.ts +1 -1
- package/dist/esm/components/Messages/WarningMessages.js +1 -0
- package/dist/esm/components/Messages/WarningMessages.js.map +1 -1
- package/dist/esm/components/Messages/useMessageQueue.js +1 -1
- package/dist/esm/components/Messages/useMessageQueue.js.map +1 -1
- package/dist/esm/components/Search/SearchInput.style.d.ts +1 -1
- package/dist/esm/components/SelectTokenButton/SelectTokenButton.style.d.ts +1 -1
- package/dist/esm/components/SendToWallet/SendToWallet.style.d.ts +1 -1
- package/dist/esm/components/Skeleton/WidgetSkeleton.style.d.ts +3 -3
- package/dist/esm/components/StepActions/StepActions.style.d.ts +1 -1
- package/dist/esm/components/Tabs/Tabs.style.d.ts +2 -2
- package/dist/esm/components/TokenList/TokenList.style.d.ts +2 -2
- package/dist/esm/components/TransactionDetails.js +4 -1
- package/dist/esm/components/TransactionDetails.js.map +1 -1
- package/dist/esm/config/defaultChainIds.js +3 -0
- package/dist/esm/config/defaultChainIds.js.map +1 -1
- package/dist/esm/config/version.d.ts +1 -1
- package/dist/esm/config/version.js +1 -1
- package/dist/esm/cross/adapters/AcrossAdapter.js +21 -22
- package/dist/esm/cross/adapters/AcrossAdapter.js.map +1 -1
- package/dist/esm/cross/adapters/BaseSwapAdapter.d.ts +17 -9
- package/dist/esm/cross/adapters/BaseSwapAdapter.js +15 -4
- package/dist/esm/cross/adapters/BaseSwapAdapter.js.map +1 -1
- package/dist/esm/cross/adapters/DebridgeAdapter.js +8 -7
- package/dist/esm/cross/adapters/DebridgeAdapter.js.map +1 -1
- package/dist/esm/cross/adapters/LifiAdapter.js +7 -6
- package/dist/esm/cross/adapters/LifiAdapter.js.map +1 -1
- package/dist/esm/cross/adapters/MayanAdapter.js +1 -2
- package/dist/esm/cross/adapters/MayanAdapter.js.map +1 -1
- package/dist/esm/cross/adapters/NearIntentsAdapter.d.ts +13 -6
- package/dist/esm/cross/adapters/NearIntentsAdapter.js +252 -75
- package/dist/esm/cross/adapters/NearIntentsAdapter.js.map +1 -1
- package/dist/esm/cross/adapters/OptimexAdapter.js +2 -1
- package/dist/esm/cross/adapters/OptimexAdapter.js.map +1 -1
- package/dist/esm/cross/adapters/OrbiterAdapter.js +9 -8
- package/dist/esm/cross/adapters/OrbiterAdapter.js.map +1 -1
- package/dist/esm/cross/adapters/RelayAdapter.js +40 -15
- package/dist/esm/cross/adapters/RelayAdapter.js.map +1 -1
- package/dist/esm/cross/adapters/SymbiosisAdapter.js +13 -14
- package/dist/esm/cross/adapters/SymbiosisAdapter.js.map +1 -1
- package/dist/esm/cross/adapters/XYFinanceAdapter.js +13 -17
- package/dist/esm/cross/adapters/XYFinanceAdapter.js.map +1 -1
- package/dist/esm/cross/adapters/index.d.ts +2 -0
- package/dist/esm/cross/adapters/index.js +2 -1
- package/dist/esm/cross/adapters/index.js.map +1 -1
- package/dist/esm/cross/constants/index.d.ts +3 -1
- package/dist/esm/cross/constants/index.js +2 -0
- package/dist/esm/cross/constants/index.js.map +1 -1
- package/dist/esm/cross/crossChainQuote.d.ts +1 -1
- package/dist/esm/cross/crossChainQuote.js +75 -12
- package/dist/esm/cross/crossChainQuote.js.map +1 -1
- package/dist/esm/cross/factory.d.ts +3 -1
- package/dist/esm/cross/factory.js +10 -12
- package/dist/esm/cross/factory.js.map +1 -1
- package/dist/esm/cross/registry.d.ts +1 -1
- package/dist/esm/hooks/useAvailableChains.js +47 -40
- package/dist/esm/hooks/useAvailableChains.js.map +1 -1
- package/dist/esm/hooks/useChains.js.map +1 -1
- package/dist/esm/hooks/useRoutes.js +11 -3
- package/dist/esm/hooks/useRoutes.js.map +1 -1
- package/dist/esm/hooks/useSwapOnly.js +8 -2
- package/dist/esm/hooks/useSwapOnly.js.map +1 -1
- package/dist/esm/hooks/useTokenAddressBalance.js.map +1 -1
- package/dist/esm/hooks/useTokens.d.ts +1 -0
- package/dist/esm/hooks/useTokens.js +14 -0
- package/dist/esm/hooks/useTokens.js.map +1 -1
- package/dist/esm/i18n/en.json +2 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/pages/MainPage/MainWarningMessages.js.map +1 -1
- package/dist/esm/pages/SendToWallet/BookmarksPage.js +1 -1
- package/dist/esm/pages/SendToWallet/BookmarksPage.js.map +1 -1
- package/dist/esm/pages/SendToWallet/RecentWalletsPage.js +2 -2
- package/dist/esm/pages/SendToWallet/RecentWalletsPage.js.map +1 -1
- package/dist/esm/pages/SendToWallet/SendToConfiguredWalletPage.js +2 -2
- package/dist/esm/pages/SendToWallet/SendToConfiguredWalletPage.js.map +1 -1
- package/dist/esm/pages/SendToWallet/SendToWalletPage.style.d.ts +5 -5
- package/dist/esm/pages/SettingsPage/SettingsCard/SettingCard.style.d.ts +1 -1
- package/dist/esm/providers/WidgetProvider/WidgetProvider.js.map +1 -1
- package/dist/esm/services/ExecuteRoute.d.ts +1 -0
- package/dist/esm/services/ExecuteRoute.js +292 -9
- package/dist/esm/services/ExecuteRoute.js.map +1 -1
- package/dist/esm/services/OpenOceanService.js +30 -4
- package/dist/esm/services/OpenOceanService.js.map +1 -1
- package/dist/esm/stores/bookmarks/createBookmarkStore.js.map +1 -1
- package/dist/esm/types/widget.d.ts +1 -1
- package/dist/esm/types/widget.js.map +1 -1
- package/dist/esm/utils/chainType.d.ts +1 -0
- package/dist/esm/utils/chainType.js +15 -0
- package/dist/esm/utils/chainType.js.map +1 -1
- package/dist/esm/utils/getPriceImpact.js +3 -3
- package/dist/esm/utils/getPriceImpact.js.map +1 -1
- package/package.json +19 -7
- package/src/App.tsx +0 -1
- package/src/components/AmountInput/AmountInputEndAdornment.tsx +39 -34
- package/src/components/BaseTransactionButton/BaseTransactionButton.tsx +3 -2
- package/src/components/Header/WalletHeader.tsx +4 -4
- package/src/components/Messages/WarningMessages.tsx +1 -0
- package/src/components/Messages/useMessageQueue.ts +1 -1
- package/src/components/TransactionDetails.tsx +8 -4
- package/src/config/defaultChainIds.ts +3 -0
- package/src/config/version.ts +1 -1
- package/src/cross/adapters/AcrossAdapter.ts +21 -22
- package/src/cross/adapters/BaseSwapAdapter.ts +24 -8
- package/src/cross/adapters/DebridgeAdapter.ts +11 -11
- package/src/cross/adapters/LifiAdapter.ts +11 -10
- package/src/cross/adapters/MayanAdapter.ts +1 -2
- package/src/cross/adapters/NearIntentsAdapter.ts +303 -129
- package/src/cross/adapters/OptimexAdapter.ts +12 -11
- package/src/cross/adapters/OrbiterAdapter.ts +17 -16
- package/src/cross/adapters/RelayAdapter.ts +42 -17
- package/src/cross/adapters/SymbiosisAdapter.ts +13 -14
- package/src/cross/adapters/XYFinanceAdapter.ts +15 -19
- package/src/cross/adapters/index.ts +2 -1
- package/src/cross/constants/index.ts +4 -0
- package/src/cross/crossChainQuote.ts +79 -21
- package/src/cross/factory.ts +12 -12
- package/src/cross/registry.ts +1 -1
- package/src/hooks/useAvailableChains.ts +50 -43
- package/src/hooks/useChains.ts +0 -1
- package/src/hooks/useExplorer.ts +6 -6
- package/src/hooks/useRoutes.ts +12 -4
- package/src/hooks/useSwapOnly.ts +9 -2
- package/src/hooks/useTokenAddressBalance.ts +1 -1
- package/src/hooks/useTokens.ts +20 -5
- package/src/i18n/en.json +2 -2
- package/src/index.ts +0 -1
- package/src/pages/MainPage/MainWarningMessages.tsx +0 -1
- package/src/pages/SendToWallet/BookmarksPage.tsx +1 -1
- package/src/pages/SendToWallet/RecentWalletsPage.tsx +2 -2
- package/src/pages/SendToWallet/SendToConfiguredWalletPage.tsx +2 -2
- package/src/providers/WidgetProvider/WidgetProvider.tsx +0 -1
- package/src/services/ExecuteRoute.ts +426 -64
- package/src/services/OpenOceanService.ts +31 -7
- package/src/stores/bookmarks/createBookmarkStore.ts +15 -15
- package/src/types/widget.ts +2 -1
- package/src/utils/chainType.ts +25 -1
- package/src/utils/getPriceImpact.ts +3 -3
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -30,14 +30,15 @@ import {
|
|
|
30
30
|
export const MappingChainIdToBlockChain: Record<string, string> = {
|
|
31
31
|
[NonEvmChain.Bitcoin]: 'btc',
|
|
32
32
|
[NonEvmChain.Solana]: 'sol',
|
|
33
|
-
[ChainId.
|
|
34
|
-
[ChainId.
|
|
35
|
-
[ChainId.
|
|
36
|
-
[ChainId.
|
|
37
|
-
[ChainId.
|
|
38
|
-
[ChainId.
|
|
33
|
+
[ChainId.ETH]: 'eth',
|
|
34
|
+
[ChainId.ARB]: 'arb',
|
|
35
|
+
[ChainId.BSC]: 'bsc',
|
|
36
|
+
[ChainId.ERA]: 'bera',
|
|
37
|
+
[ChainId.POL]: 'pol',
|
|
38
|
+
[ChainId.BAS]: 'base',
|
|
39
|
+
[ChainId.NEAR]: 'near',
|
|
40
|
+
[ChainId.MONAD]: 'monad',
|
|
39
41
|
}
|
|
40
|
-
|
|
41
42
|
const erc20Abi = [
|
|
42
43
|
{
|
|
43
44
|
inputs: [
|
|
@@ -51,13 +52,80 @@ const erc20Abi = [
|
|
|
51
52
|
},
|
|
52
53
|
]
|
|
53
54
|
|
|
55
|
+
export interface NearToken {
|
|
56
|
+
assetId: string
|
|
57
|
+
decimals: number
|
|
58
|
+
blockchain: string
|
|
59
|
+
symbol: string
|
|
60
|
+
price: number
|
|
61
|
+
priceUpdatedAt: number
|
|
62
|
+
contractAddress: string
|
|
63
|
+
logo: string
|
|
64
|
+
}
|
|
65
|
+
const getTokenLogoUrl = (token: NearToken) => {
|
|
66
|
+
const { symbol, contractAddress } = token
|
|
67
|
+
|
|
68
|
+
// For major tokens without contract addresses or as fallbacks
|
|
69
|
+
switch (symbol) {
|
|
70
|
+
case 'ETH':
|
|
71
|
+
return 'https://assets.coingecko.com/coins/images/279/small/ethereum.png'
|
|
72
|
+
case 'BTC':
|
|
73
|
+
case 'wBTC':
|
|
74
|
+
return 'https://assets.coingecko.com/coins/images/1/small/bitcoin.png'
|
|
75
|
+
case 'USDC':
|
|
76
|
+
return 'https://assets.coingecko.com/coins/images/6319/small/USD_Coin_icon.png'
|
|
77
|
+
case 'USDT':
|
|
78
|
+
return 'https://assets.coingecko.com/coins/images/325/small/Tether.png'
|
|
79
|
+
case 'DAI':
|
|
80
|
+
return 'https://assets.coingecko.com/coins/images/9956/small/4943.png'
|
|
81
|
+
case 'SOL':
|
|
82
|
+
return 'https://assets.coingecko.com/coins/images/4128/small/solana.png'
|
|
83
|
+
case 'NEAR':
|
|
84
|
+
case 'wNEAR':
|
|
85
|
+
return 'https://assets.coingecko.com/coins/images/10365/small/near.jpg'
|
|
86
|
+
case 'BNB':
|
|
87
|
+
return 'https://assets.coingecko.com/coins/images/825/small/bnb-icon2_2x.png'
|
|
88
|
+
case 'DOGE':
|
|
89
|
+
return 'https://assets.coingecko.com/coins/images/5/small/dogecoin.png'
|
|
90
|
+
case 'XRP':
|
|
91
|
+
return 'https://assets.coingecko.com/coins/images/44/small/xrp-symbol-white-128.png'
|
|
92
|
+
case 'TRX':
|
|
93
|
+
return 'https://assets.coingecko.com/coins/images/1094/small/tron-logo.png'
|
|
94
|
+
case 'FRAX':
|
|
95
|
+
return 'https://assets.coingecko.com/coins/images/13422/small/FRAX_icon.png'
|
|
96
|
+
case 'LINK':
|
|
97
|
+
return 'https://assets.coingecko.com/coins/images/877/small/chainlink-new-logo.png'
|
|
98
|
+
case 'UNI':
|
|
99
|
+
return 'https://assets.coingecko.com/coins/images/12504/small/uni.jpg'
|
|
100
|
+
case 'AAVE':
|
|
101
|
+
return 'https://assets.coingecko.com/coins/images/12645/small/AAVE.png'
|
|
102
|
+
case 'SHIB':
|
|
103
|
+
return 'https://assets.coingecko.com/coins/images/11939/small/shiba.png'
|
|
104
|
+
case 'PEPE':
|
|
105
|
+
return 'https://assets.coingecko.com/coins/images/29850/small/pepe-token.jpeg'
|
|
106
|
+
case 'REF':
|
|
107
|
+
return 'https://s2.coinmarketcap.com/static/img/coins/64x64/11809.png'
|
|
108
|
+
case 'AURORA':
|
|
109
|
+
return 'https://s2.coinmarketcap.com/static/img/coins/64x64/14803.png'
|
|
110
|
+
case 'BLACKDRAGON':
|
|
111
|
+
return 'https://s2.coinmarketcap.com/static/img/coins/64x64/29627.png'
|
|
112
|
+
// Add more cases as needed
|
|
113
|
+
default:
|
|
114
|
+
// Fallback to a generic token icon
|
|
115
|
+
return `https://raw.githubusercontent.com/Uniswap/assets/master/blockchains/ethereum/assets/0x${contractAddress}/logo.png`
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
54
119
|
export class NearIntentsAdapter extends BaseSwapAdapter {
|
|
120
|
+
private nearTokens: NearToken[] = []
|
|
55
121
|
constructor() {
|
|
56
122
|
super()
|
|
57
123
|
// Initialize the API client
|
|
58
|
-
OpenAPI.BASE = 'https://1click.chaindefuser.com'
|
|
59
|
-
OpenAPI.
|
|
60
|
-
|
|
124
|
+
// OpenAPI.BASE = 'https://1click.chaindefuser.com'
|
|
125
|
+
OpenAPI.BASE = 'https://1click.openocean.finance'
|
|
126
|
+
if (this.nearTokens.length === 0) {
|
|
127
|
+
this.getAllSupportedTokens()
|
|
128
|
+
}
|
|
61
129
|
}
|
|
62
130
|
|
|
63
131
|
getName(): string {
|
|
@@ -75,62 +143,131 @@ export class NearIntentsAdapter extends BaseSwapAdapter {
|
|
|
75
143
|
]
|
|
76
144
|
}
|
|
77
145
|
|
|
146
|
+
async getAllSupportedTokens(): Promise<void> {
|
|
147
|
+
fetch(`https://1click.chaindefuser.com/v0/tokens`, {
|
|
148
|
+
headers: {
|
|
149
|
+
'Authorization': `Bearer ${OpenAPI.TOKEN}`,
|
|
150
|
+
},
|
|
151
|
+
})
|
|
152
|
+
.then(res => res.json())
|
|
153
|
+
.then(res => {
|
|
154
|
+
const wNear = res.find((token: NearToken) => token.contractAddress === 'wrap.near')
|
|
155
|
+
|
|
156
|
+
const native: NearToken = wNear
|
|
157
|
+
? {
|
|
158
|
+
...wNear,
|
|
159
|
+
symbol: 'NEAR',
|
|
160
|
+
contractAddress: '',
|
|
161
|
+
assetId: 'near',
|
|
162
|
+
logo: getTokenLogoUrl(wNear),
|
|
163
|
+
}
|
|
164
|
+
: {
|
|
165
|
+
assetId: 'near',
|
|
166
|
+
decimals: 24,
|
|
167
|
+
blockchain: 'near',
|
|
168
|
+
symbol: 'NEAR',
|
|
169
|
+
price: 0,
|
|
170
|
+
priceUpdatedAt: 0,
|
|
171
|
+
contractAddress: '',
|
|
172
|
+
logo: getTokenLogoUrl(wNear),
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
this.nearTokens = [
|
|
176
|
+
native,
|
|
177
|
+
...(res?.map((item: NearToken) => {
|
|
178
|
+
if (item.blockchain == 'btc') {
|
|
179
|
+
console.log(item)
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
...item,
|
|
183
|
+
logo: getTokenLogoUrl(item),
|
|
184
|
+
}
|
|
185
|
+
}) || []),
|
|
186
|
+
]
|
|
187
|
+
localStorage.setItem('nearTokens', JSON.stringify(this.nearTokens))
|
|
188
|
+
})
|
|
189
|
+
.catch(error => {
|
|
190
|
+
console.error('Failed to fetch near tokens:', error)
|
|
191
|
+
let nearTokens = localStorage.getItem('nearTokens')
|
|
192
|
+
if (nearTokens) {
|
|
193
|
+
this.nearTokens = JSON.parse(nearTokens)
|
|
194
|
+
} else {
|
|
195
|
+
this.nearTokens = []
|
|
196
|
+
}
|
|
197
|
+
// Reset loading state on error
|
|
198
|
+
})
|
|
199
|
+
}
|
|
200
|
+
|
|
78
201
|
getSupportedTokens(_sourceChain: Chain, _destChain: Chain): Currency[] {
|
|
79
202
|
return []
|
|
80
203
|
}
|
|
81
204
|
|
|
82
205
|
async getQuote(params: NearQuoteParams): Promise<NormalizedQuote> {
|
|
83
206
|
const deadline = new Date()
|
|
84
|
-
|
|
85
207
|
// 1 hour for Bitcoin, 20 minutes for other chains
|
|
86
208
|
deadline.setSeconds(deadline.getSeconds() + (params.fromChain === NonEvmChain.Bitcoin ? 60 * 60 : 60 * 20))
|
|
209
|
+
if (this.nearTokens.length === 0) {
|
|
210
|
+
await this.getAllSupportedTokens()
|
|
211
|
+
}
|
|
87
212
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
? token.symbol.toLowerCase() === params.toToken.symbol?.toLowerCase() && token.assetId.includes('omft')
|
|
126
|
-
: token.contractAddress?.toLowerCase() === (params.toToken as any).wrapped?.address.toLowerCase())
|
|
127
|
-
)
|
|
128
|
-
})?.assetId
|
|
213
|
+
let fromAssetId: any = ''
|
|
214
|
+
if ((params.fromToken as any).address === 'near.near') {
|
|
215
|
+
fromAssetId = 'nep141:wrap.near'
|
|
216
|
+
} else {
|
|
217
|
+
fromAssetId = this.nearTokens.find(token => {
|
|
218
|
+
const blockchain = MappingChainIdToBlockChain[params.fromChain as ChainId]
|
|
219
|
+
|
|
220
|
+
if (params.fromChain === 1151111081099710) {
|
|
221
|
+
return (params.fromToken as SolanaToken).address === SOLANA_NATIVE
|
|
222
|
+
? token.symbol === 'SOL' && token.blockchain === 'sol'
|
|
223
|
+
: token.blockchain === blockchain && token.contractAddress === (params.fromToken as any).address
|
|
224
|
+
}
|
|
225
|
+
if (token.blockchain === blockchain) {
|
|
226
|
+
// console.log(token.symbol)
|
|
227
|
+
// console.log(token.assetId)
|
|
228
|
+
// console.log(token)
|
|
229
|
+
if (!token.contractAddress && (params.fromToken as any).isNative && token.symbol.toLowerCase() === params.fromToken.symbol?.toLowerCase()) {
|
|
230
|
+
return true
|
|
231
|
+
}
|
|
232
|
+
return token.contractAddress?.toLowerCase() === (params.fromToken as any).address.toLowerCase()
|
|
233
|
+
} else {
|
|
234
|
+
return false
|
|
235
|
+
}
|
|
236
|
+
})?.assetId
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
let toAssetId: any = ''
|
|
240
|
+
if ((params.toToken as any).address === 'near.near') {
|
|
241
|
+
toAssetId = 'nep141:wrap.near'
|
|
242
|
+
} else {
|
|
243
|
+
toAssetId = this.nearTokens.find((token: NearToken) => {
|
|
244
|
+
const blockchain = MappingChainIdToBlockChain[params.toChain as ChainId]
|
|
245
|
+
if (params.toChain === 1151111081099710) {
|
|
246
|
+
return (params.toToken as SolanaToken).address === SOLANA_NATIVE
|
|
247
|
+
? token.symbol === 'SOL' && token.blockchain === 'sol'
|
|
248
|
+
: token.blockchain === blockchain && token.contractAddress === (params.toToken as any).address
|
|
249
|
+
}
|
|
129
250
|
|
|
130
|
-
|
|
131
|
-
|
|
251
|
+
if (token.blockchain === blockchain) {
|
|
252
|
+
// console.log(token.symbol)
|
|
253
|
+
// console.log(token.assetId)
|
|
254
|
+
// console.log(token)
|
|
255
|
+
if (!token.contractAddress && (params.toToken as any).isNative && token.symbol.toLowerCase() === params.toToken.symbol?.toLowerCase()) {
|
|
256
|
+
return true
|
|
257
|
+
}
|
|
258
|
+
return token.contractAddress?.toLowerCase() === (params.toToken as any).address.toLowerCase()
|
|
259
|
+
} else {
|
|
260
|
+
return false
|
|
261
|
+
}
|
|
262
|
+
})?.assetId
|
|
132
263
|
}
|
|
133
264
|
|
|
265
|
+
if (!fromAssetId) {
|
|
266
|
+
throw new Error('not supported from token')
|
|
267
|
+
}
|
|
268
|
+
if (!toAssetId) {
|
|
269
|
+
throw new Error('not supported to token')
|
|
270
|
+
}
|
|
134
271
|
// Create a quote request
|
|
135
272
|
const quoteRequest: QuoteRequest = {
|
|
136
273
|
dry: true,
|
|
@@ -158,37 +295,47 @@ export class NearIntentsAdapter extends BaseSwapAdapter {
|
|
|
158
295
|
],
|
|
159
296
|
}
|
|
160
297
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
298
|
+
try {
|
|
299
|
+
const quote = await OneClickService.getQuote(quoteRequest)
|
|
300
|
+
const formattedInputAmount = formatUnits(BigInt(params.amount), params.fromToken.decimals)
|
|
301
|
+
const rawAmountOut = Number(quote?.quote?.amountOut ?? 0)
|
|
302
|
+
const amountOut = rawAmountOut / 10 ** params.toToken.decimals
|
|
303
|
+
const formattedOutputAmount = amountOut.toString()
|
|
304
|
+
const inputUsd = Number(quote?.quote?.amountInUsd ?? 0)
|
|
305
|
+
const outputUsd = +quote.quote.amountOutUsd
|
|
306
|
+
const platformFeePercent = (params.feeBps * 100) / 10_000
|
|
307
|
+
const protocolFee = +quote.quote.amountInUsd * params.feeBps / 10000
|
|
308
|
+
return {
|
|
309
|
+
quoteParams: params,
|
|
310
|
+
outputAmount: BigInt(rawAmountOut),
|
|
311
|
+
formattedOutputAmount,
|
|
312
|
+
inputUsd: +quote.quote.amountInUsd,
|
|
313
|
+
outputUsd: +quote.quote.amountOutUsd,
|
|
314
|
+
priceImpact: !inputUsd || !outputUsd ? NaN : ((inputUsd - outputUsd) * 100) / inputUsd,
|
|
315
|
+
rate: +formattedOutputAmount / +formattedInputAmount,
|
|
316
|
+
gasFeeUsd: 0,
|
|
317
|
+
timeEstimate: quote.quote.timeEstimate || 0,
|
|
318
|
+
contractAddress: ZERO_ADDRESS,
|
|
319
|
+
rawQuote: quote,
|
|
320
|
+
protocolFee: protocolFee,
|
|
321
|
+
platformFeePercent: platformFeePercent,
|
|
322
|
+
}
|
|
323
|
+
} catch (error) {
|
|
324
|
+
// console.log('NearIntentsAdapter getQuote error', error)
|
|
325
|
+
if (error && typeof error === 'object' && 'body' in error) {
|
|
326
|
+
const errorWithBody = error as { body?: { message?: string } }
|
|
327
|
+
if (errorWithBody.body?.message) {
|
|
328
|
+
throw new Error(errorWithBody.body.message)
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
throw error
|
|
182
332
|
}
|
|
183
333
|
}
|
|
184
334
|
|
|
185
335
|
async executeSwap(
|
|
186
336
|
{ quote }: Quote,
|
|
187
337
|
walletClient: WalletClient,
|
|
188
|
-
nearWallet?: ReturnType<typeof useWalletSelector
|
|
189
|
-
sendBtcFn?: (params: { recipient: string; amount: string | number }) => Promise<string>,
|
|
190
|
-
sendSolanaFn?: WalletAdapterProps['sendTransaction'],
|
|
191
|
-
solanaConnection?: Connection,
|
|
338
|
+
nearWallet?: ReturnType<typeof useWalletSelector>
|
|
192
339
|
): Promise<NormalizedTxResponse> {
|
|
193
340
|
const quoteParams = {
|
|
194
341
|
...quote.rawQuote.quoteRequest,
|
|
@@ -235,17 +382,28 @@ export class NearIntentsAdapter extends BaseSwapAdapter {
|
|
|
235
382
|
|
|
236
383
|
if (quote.quoteParams.fromChain === NonEvmChain.Solana) {
|
|
237
384
|
return new Promise<NormalizedTxResponse>(async (resolve, reject) => {
|
|
238
|
-
|
|
239
|
-
|
|
385
|
+
// Use walletClient (adaptedWallet) from ExecuteRoute.ts
|
|
386
|
+
const adaptedWallet = walletClient as any
|
|
387
|
+
|
|
388
|
+
if (!adaptedWallet || !adaptedWallet.sendTransaction) {
|
|
389
|
+
reject('Not connected or walletClient does not support sendTransaction')
|
|
390
|
+
return
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// Get connection from adaptedWallet (exposed by ExecuteRoute.ts)
|
|
394
|
+
const connection = adaptedWallet.connection
|
|
395
|
+
if (!connection) {
|
|
396
|
+
reject('Connection not available from walletClient')
|
|
240
397
|
return
|
|
241
398
|
}
|
|
399
|
+
|
|
242
400
|
const waitForConfirmation = async (txId: string) => {
|
|
243
401
|
try {
|
|
244
|
-
const latestBlockhash = await
|
|
402
|
+
const latestBlockhash = await connection.getLatestBlockhash()
|
|
245
403
|
|
|
246
404
|
// Wait for confirmation with timeout
|
|
247
405
|
const confirmation = await Promise.race([
|
|
248
|
-
|
|
406
|
+
connection.confirmTransaction(
|
|
249
407
|
{
|
|
250
408
|
signature: txId,
|
|
251
409
|
blockhash: latestBlockhash.blockhash,
|
|
@@ -268,9 +426,9 @@ export class NearIntentsAdapter extends BaseSwapAdapter {
|
|
|
268
426
|
console.error('Transaction confirmation failed:', confirmError)
|
|
269
427
|
|
|
270
428
|
// Check if transaction actually succeeded despite timeout
|
|
271
|
-
const txStatus = await
|
|
429
|
+
const txStatus = await connection.getSignatureStatus(txId)
|
|
272
430
|
if (txStatus?.value?.confirmationStatus !== 'confirmed') {
|
|
273
|
-
throw new Error(`Transaction was not confirmed: ${confirmError.message}`)
|
|
431
|
+
throw new Error(`Transaction was not confirmed: ${confirmError instanceof Error ? confirmError.message : 'Unknown error'}`)
|
|
274
432
|
}
|
|
275
433
|
}
|
|
276
434
|
}
|
|
@@ -279,11 +437,13 @@ export class NearIntentsAdapter extends BaseSwapAdapter {
|
|
|
279
437
|
const recipientPubkey = new PublicKey(depositAddress)
|
|
280
438
|
|
|
281
439
|
const fromToken = quote.quoteParams.fromToken as SolanaToken
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
440
|
+
if (fromToken.address === SOLANA_NATIVE) {
|
|
441
|
+
// Get latest blockhash before creating transaction
|
|
442
|
+
const { blockhash } = await connection.getLatestBlockhash('confirmed')
|
|
443
|
+
const transaction = new Transaction({
|
|
444
|
+
recentBlockhash: blockhash,
|
|
445
|
+
feePayer: fromPubkey,
|
|
446
|
+
}).add(
|
|
287
447
|
SystemProgram.transfer({
|
|
288
448
|
fromPubkey: fromPubkey,
|
|
289
449
|
toPubkey: recipientPubkey,
|
|
@@ -291,7 +451,9 @@ export class NearIntentsAdapter extends BaseSwapAdapter {
|
|
|
291
451
|
}),
|
|
292
452
|
)
|
|
293
453
|
try {
|
|
294
|
-
|
|
454
|
+
// Use adaptedWallet.sendTransaction (exposed by ExecuteRoute.ts)
|
|
455
|
+
const result = await adaptedWallet.sendTransaction(transaction)
|
|
456
|
+
const signature = result?.signature || result
|
|
295
457
|
await waitForConfirmation(signature)
|
|
296
458
|
|
|
297
459
|
resolve({
|
|
@@ -302,7 +464,7 @@ export class NearIntentsAdapter extends BaseSwapAdapter {
|
|
|
302
464
|
reject(error)
|
|
303
465
|
}
|
|
304
466
|
} else {
|
|
305
|
-
const mintPubkey = new PublicKey(fromToken.
|
|
467
|
+
const mintPubkey = new PublicKey(fromToken.address)
|
|
306
468
|
// Get associated token addresses
|
|
307
469
|
const senderTokenAddress = await getAssociatedTokenAddress(
|
|
308
470
|
mintPubkey,
|
|
@@ -318,11 +480,17 @@ export class NearIntentsAdapter extends BaseSwapAdapter {
|
|
|
318
480
|
TOKEN_PROGRAM_ID,
|
|
319
481
|
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
320
482
|
)
|
|
321
|
-
|
|
483
|
+
|
|
484
|
+
// Get latest blockhash before creating transaction
|
|
485
|
+
const { blockhash } = await connection.getLatestBlockhash('confirmed')
|
|
486
|
+
const transaction = new Transaction({
|
|
487
|
+
recentBlockhash: blockhash,
|
|
488
|
+
feePayer: fromPubkey,
|
|
489
|
+
})
|
|
322
490
|
|
|
323
491
|
try {
|
|
324
492
|
// Check if recipient's token account exists
|
|
325
|
-
await getAccount(
|
|
493
|
+
await getAccount(connection, recipientTokenAddress)
|
|
326
494
|
} catch (err) {
|
|
327
495
|
// Account doesn't exist, create it
|
|
328
496
|
console.log('Creating recipient token account...')
|
|
@@ -351,7 +519,9 @@ export class NearIntentsAdapter extends BaseSwapAdapter {
|
|
|
351
519
|
)
|
|
352
520
|
|
|
353
521
|
try {
|
|
354
|
-
|
|
522
|
+
// Use adaptedWallet.sendTransaction (exposed by ExecuteRoute.ts)
|
|
523
|
+
const result = await adaptedWallet.sendTransaction(transaction)
|
|
524
|
+
const signature = result?.signature || result
|
|
355
525
|
await waitForConfirmation(signature)
|
|
356
526
|
|
|
357
527
|
resolve({
|
|
@@ -368,15 +538,18 @@ export class NearIntentsAdapter extends BaseSwapAdapter {
|
|
|
368
538
|
|
|
369
539
|
if (quote.quoteParams.fromChain === NonEvmChain.Bitcoin) {
|
|
370
540
|
return new Promise<NormalizedTxResponse>(async (resolve, reject) => {
|
|
371
|
-
if (!
|
|
541
|
+
if (!walletClient || !walletClient.sendTransaction) {
|
|
372
542
|
reject('Not connected')
|
|
373
543
|
return
|
|
374
544
|
}
|
|
375
545
|
|
|
376
546
|
try {
|
|
377
|
-
const tx = await
|
|
547
|
+
const tx = await walletClient.sendTransaction({
|
|
378
548
|
recipient: depositAddress,
|
|
379
549
|
amount: quote.quoteParams.amount,
|
|
550
|
+
chain: undefined,
|
|
551
|
+
account: walletClient.account?.address as `0x${string}`,
|
|
552
|
+
kzg: undefined,
|
|
380
553
|
})
|
|
381
554
|
await OneClickService.submitDepositTx({
|
|
382
555
|
txHash: tx,
|
|
@@ -428,23 +601,23 @@ export class NearIntentsAdapter extends BaseSwapAdapter {
|
|
|
428
601
|
actions: [
|
|
429
602
|
isNative
|
|
430
603
|
? {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
604
|
+
type: 'Transfer',
|
|
605
|
+
params: {
|
|
606
|
+
deposit: quote.quoteParams.amount,
|
|
607
|
+
},
|
|
608
|
+
}
|
|
436
609
|
: {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
},
|
|
444
|
-
gas: '30000000000000',
|
|
445
|
-
deposit: '1',
|
|
610
|
+
type: 'FunctionCall',
|
|
611
|
+
params: {
|
|
612
|
+
methodName: 'ft_transfer',
|
|
613
|
+
args: {
|
|
614
|
+
receiver_id: depositAddress,
|
|
615
|
+
amount: quote.quoteParams.amount,
|
|
446
616
|
},
|
|
617
|
+
gas: '30000000000000',
|
|
618
|
+
deposit: '1',
|
|
447
619
|
},
|
|
620
|
+
},
|
|
448
621
|
],
|
|
449
622
|
})
|
|
450
623
|
|
|
@@ -489,21 +662,22 @@ export class NearIntentsAdapter extends BaseSwapAdapter {
|
|
|
489
662
|
|
|
490
663
|
const hash = await ((fromToken as any).isNative
|
|
491
664
|
? walletClient.sendTransaction({
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
665
|
+
to: depositAddress as `0x${string}`,
|
|
666
|
+
value: BigInt(quote.quoteParams.amount),
|
|
667
|
+
chain: undefined,
|
|
668
|
+
account,
|
|
669
|
+
kzg: undefined
|
|
670
|
+
})
|
|
497
671
|
: walletClient.writeContract({
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
672
|
+
address: ('contractAddress' in fromToken
|
|
673
|
+
? fromToken.contractAddress
|
|
674
|
+
: (fromToken as any).address) as `0x${string}`,
|
|
675
|
+
abi: erc20Abi,
|
|
676
|
+
functionName: 'transfer',
|
|
677
|
+
args: [depositAddress, quote.quoteParams.amount],
|
|
678
|
+
chain: undefined,
|
|
679
|
+
account,
|
|
680
|
+
}))
|
|
507
681
|
await OneClickService.submitDepositTx({
|
|
508
682
|
txHash: hash,
|
|
509
683
|
depositAddress,
|
|
@@ -530,10 +704,10 @@ export class NearIntentsAdapter extends BaseSwapAdapter {
|
|
|
530
704
|
res.status === 'SUCCESS'
|
|
531
705
|
? 'Success'
|
|
532
706
|
: res.status === 'FAILED'
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
707
|
+
? 'Failed'
|
|
708
|
+
: res.status === 'REFUNDED'
|
|
709
|
+
? 'Refunded'
|
|
710
|
+
: 'Processing',
|
|
537
711
|
}
|
|
538
712
|
}
|
|
539
713
|
}
|
|
@@ -59,7 +59,7 @@ export class OptimexAdapter extends BaseSwapAdapter {
|
|
|
59
59
|
return 'https://storage.googleapis.com/ks-setting-1d682dca/464ce79e-a906-4590-bf78-9054e606aa041749023419612.png'
|
|
60
60
|
}
|
|
61
61
|
getSupportedChains(): Chain[] {
|
|
62
|
-
return [NonEvmChain.Bitcoin, ChainId.
|
|
62
|
+
return [NonEvmChain.Bitcoin, ChainId.ETH]
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
getSupportedTokens(_sourceChain: Chain, _destChain: Chain): Currency[] {
|
|
@@ -76,17 +76,17 @@ export class OptimexAdapter extends BaseSwapAdapter {
|
|
|
76
76
|
const fromToken = isFromBtc
|
|
77
77
|
? { token_id: 'BTC', token_symbol: 'BTC' }
|
|
78
78
|
: this.tokens.find(item => {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
const address = (params.fromToken as any).isNative ? 'native' : (params.fromToken as any).wrapped.address
|
|
80
|
+
return item.network_id === 'ethereum' && address.toLowerCase() === item.token_address.toLowerCase()
|
|
81
|
+
})
|
|
82
82
|
const fromTokenId = fromToken?.token_id
|
|
83
83
|
|
|
84
84
|
const toToken = isToBtc
|
|
85
85
|
? { token_id: 'BTC', token_symbol: 'BTC' }
|
|
86
86
|
: this.tokens.find(item => {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
const address = (params.toToken as any).isNative ? 'native' : (params.toToken as any).wrapped.address
|
|
88
|
+
return item.network_id === 'ethereum' && address.toLowerCase() === item.token_address.toLowerCase()
|
|
89
|
+
})
|
|
90
90
|
const toTokenId = toToken?.token_id
|
|
91
91
|
|
|
92
92
|
if (!fromTokenId || !toTokenId) {
|
|
@@ -237,6 +237,7 @@ export class OptimexAdapter extends BaseSwapAdapter {
|
|
|
237
237
|
data: quote.rawQuote.txData.payload,
|
|
238
238
|
chain: undefined,
|
|
239
239
|
account,
|
|
240
|
+
kzg: undefined,
|
|
240
241
|
})
|
|
241
242
|
|
|
242
243
|
await fetch(`${OPTIMEX_API}/trades/${quote.rawQuote.txData.trade_id}/submit-tx`, {
|
|
@@ -264,10 +265,10 @@ export class OptimexAdapter extends BaseSwapAdapter {
|
|
|
264
265
|
status: ['Done', 'PaymentConfirmed'].includes(res?.data?.state)
|
|
265
266
|
? 'Success'
|
|
266
267
|
: ['Aborted', 'ToBeAborted', 'Failed', 'Failure', 'UserCancelled'].includes(res?.data?.state)
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
268
|
+
? 'Failed'
|
|
269
|
+
: res?.data?.state === 'Refunded'
|
|
270
|
+
? 'Refunded'
|
|
271
|
+
: 'Processing',
|
|
271
272
|
}
|
|
272
273
|
}
|
|
273
274
|
}
|