@openocean.finance/widget 1.0.51 → 1.0.53
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/AppProvider.js +2 -1
- package/dist/esm/AppProvider.js.map +1 -1
- package/dist/esm/components/BaseTransactionButton/BaseTransactionButton.js +21 -0
- package/dist/esm/components/BaseTransactionButton/BaseTransactionButton.js.map +1 -1
- package/dist/esm/components/TokenList/VirtualizedTokenList.js +1 -1
- package/dist/esm/components/TokenList/VirtualizedTokenList.js.map +1 -1
- package/dist/esm/components/TransactionDetails.js +6 -0
- package/dist/esm/components/TransactionDetails.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/NearIntentsAdapter.js +94 -25
- package/dist/esm/cross/adapters/NearIntentsAdapter.js.map +1 -1
- package/dist/esm/cross/constants/index.d.ts +1 -1
- package/dist/esm/cross/constants/index.js +1 -0
- package/dist/esm/cross/constants/index.js.map +1 -1
- package/dist/esm/cross/crossChainQuote.d.ts +3 -2
- package/dist/esm/cross/crossChainQuote.js +2 -2
- package/dist/esm/cross/crossChainQuote.js.map +1 -1
- package/dist/esm/hooks/useGasPrice.js +2 -2
- package/dist/esm/hooks/useGasPrice.js.map +1 -1
- package/dist/esm/hooks/useGasRecommendation.d.ts +1 -1
- package/dist/esm/hooks/useGasRecommendation.js +7 -1
- package/dist/esm/hooks/useGasRecommendation.js.map +1 -1
- package/dist/esm/hooks/useRouteExecution.js +5 -0
- package/dist/esm/hooks/useRouteExecution.js.map +1 -1
- package/dist/esm/hooks/useRoutes.js +1 -1
- package/dist/esm/hooks/useRoutes.js.map +1 -1
- package/dist/esm/hooks/useToken.js.map +1 -1
- package/dist/esm/providers/WalletProvider/NearProvider.d.ts +3 -0
- package/dist/esm/providers/WalletProvider/NearProvider.js +95 -0
- package/dist/esm/providers/WalletProvider/NearProvider.js.map +1 -0
- package/dist/esm/providers/WalletProvider/SDKProviders.js +4 -1
- package/dist/esm/providers/WalletProvider/SDKProviders.js.map +1 -1
- package/dist/esm/providers/WalletProvider/useExternalWalletProvider.js +1 -1
- package/dist/esm/providers/WalletProvider/useExternalWalletProvider.js.map +1 -1
- package/dist/esm/services/ExecuteRoute.d.ts +1 -0
- package/dist/esm/services/ExecuteRoute.js +121 -0
- package/dist/esm/services/ExecuteRoute.js.map +1 -1
- package/dist/esm/services/OpenOceanService.d.ts +5 -1
- package/dist/esm/services/OpenOceanService.js +121 -6
- package/dist/esm/services/OpenOceanService.js.map +1 -1
- package/package.json +9 -5
- package/src/AppProvider.tsx +8 -5
- package/src/components/BaseTransactionButton/BaseTransactionButton.tsx +20 -0
- package/src/components/TokenList/VirtualizedTokenList.tsx +1 -1
- package/src/components/TransactionDetails.tsx +17 -11
- package/src/config/version.ts +1 -1
- package/src/cross/adapters/NearIntentsAdapter.ts +100 -28
- package/src/cross/constants/index.ts +1 -0
- package/src/cross/crossChainQuote.ts +6 -2
- package/src/hooks/useGasPrice.ts +2 -2
- package/src/hooks/useGasRecommendation.ts +8 -1
- package/src/hooks/useRouteExecution.ts +5 -0
- package/src/hooks/useRoutes.ts +1 -1
- package/src/hooks/useToken.ts +0 -1
- package/src/providers/WalletProvider/NearProvider.tsx +110 -0
- package/src/providers/WalletProvider/SDKProviders.tsx +5 -0
- package/src/providers/WalletProvider/useExternalWalletProvider.ts +1 -1
- package/src/services/ExecuteRoute.ts +134 -1
- package/src/services/OpenOceanService.ts +135 -7
|
@@ -57,15 +57,68 @@ export class OpenOceanService {
|
|
|
57
57
|
disabledDexIds?: string
|
|
58
58
|
enabledDexIds?: string
|
|
59
59
|
referrer?: string
|
|
60
|
+
account?: string
|
|
61
|
+
inTokenDecimals?: number
|
|
62
|
+
outTokenDecimals?: number
|
|
60
63
|
}) {
|
|
64
|
+
const isNearChain = params.chain === '20000000000006' || params.chain === 'near'
|
|
65
|
+
// Near 链使用特殊的 API 端点和参数格式
|
|
66
|
+
if (isNearChain) {
|
|
67
|
+
const nearApiUrl = 'https://ethapi.openocean.finance/v1/near'
|
|
68
|
+
|
|
69
|
+
// 计算 amountAll(格式化后的金额,用于显示)
|
|
70
|
+
let amountAll = ''
|
|
71
|
+
if (params.inTokenDecimals !== undefined) {
|
|
72
|
+
const amountBigInt = BigInt(params.amount)
|
|
73
|
+
const decimals = BigInt(10 ** params.inTokenDecimals)
|
|
74
|
+
const wholePart = amountBigInt / decimals
|
|
75
|
+
const fractionalPart = amountBigInt % decimals
|
|
76
|
+
if (fractionalPart === 0n) {
|
|
77
|
+
amountAll = wholePart.toString()
|
|
78
|
+
} else {
|
|
79
|
+
const fractionalStr = fractionalPart.toString().padStart(params.inTokenDecimals, '0')
|
|
80
|
+
// 移除尾部的 0,但保留至少一位小数
|
|
81
|
+
const trimmedFractional = fractionalStr.replace(/0+$/, '') || '0'
|
|
82
|
+
amountAll = `${wholePart}.${trimmedFractional}`
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// 转换 slippage:从 0.01 (1%) 转为 100 (百分比格式)
|
|
87
|
+
const slippagePercent = params.slippage
|
|
88
|
+
? Math.floor(Number(params.slippage) * 100).toString()
|
|
89
|
+
: '100' // 默认 1%
|
|
90
|
+
|
|
91
|
+
const queryParams = new URLSearchParams({
|
|
92
|
+
quoteType: 'swap',
|
|
93
|
+
inTokenSymbol: params.inTokenSymbol,
|
|
94
|
+
inTokenAddress: params.inTokenAddress,
|
|
95
|
+
outTokenSymbol: params.outTokenSymbol,
|
|
96
|
+
outTokenAddress: params.outTokenAddress,
|
|
97
|
+
amount: params.amount,
|
|
98
|
+
...(amountAll && { amountAll }),
|
|
99
|
+
slippage: slippagePercent,
|
|
100
|
+
gasPrice: params.gasPrice || '5000000000',
|
|
101
|
+
referrer: params.referrer || '0x3487ef9f9b36547e43268b8f0e2349a226c70b53',
|
|
102
|
+
disabledDexIds: params.disabledDexIds || '',
|
|
103
|
+
disableRfq: '', // Near API 特有参数
|
|
104
|
+
...(params.account && { account: params.account }),
|
|
105
|
+
})
|
|
106
|
+
const response = await fetch(`${nearApiUrl}/quote?${queryParams.toString()}`)
|
|
107
|
+
return {
|
|
108
|
+
data: await response.json(),
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// 其他链使用原有逻辑
|
|
61
113
|
const apiUrl = this.getApiUrl(params.chain)
|
|
62
114
|
const slippage = (Number(params.slippage || 0.01)).toString();
|
|
115
|
+
|
|
63
116
|
const queryParams = new URLSearchParams({
|
|
64
117
|
quoteType: 'quote',
|
|
65
118
|
inTokenSymbol: params.inTokenSymbol,
|
|
66
|
-
inTokenAddress: params.inTokenAddress,
|
|
119
|
+
inTokenAddress: this.getSolanaAddress(params.chain, params.inTokenAddress),
|
|
67
120
|
outTokenSymbol: params.outTokenSymbol,
|
|
68
|
-
outTokenAddress: params.outTokenAddress,
|
|
121
|
+
outTokenAddress: this.getSolanaAddress(params.chain, params.outTokenAddress),
|
|
69
122
|
amountDecimals: params.amount,
|
|
70
123
|
slippage,
|
|
71
124
|
gasPriceDecimals: params.gasPrice || '',
|
|
@@ -73,7 +126,6 @@ export class OpenOceanService {
|
|
|
73
126
|
enabledDexIds: params.enabledDexIds || '',
|
|
74
127
|
referrer: params.referrer || '0x3487ef9f9b36547e43268b8f0e2349a226c70b53',
|
|
75
128
|
})
|
|
76
|
-
|
|
77
129
|
const response = await fetch(`${apiUrl}/quote?${queryParams.toString()}`)
|
|
78
130
|
return response.json()
|
|
79
131
|
}
|
|
@@ -93,7 +145,66 @@ export class OpenOceanService {
|
|
|
93
145
|
referrer?: string,
|
|
94
146
|
referrerFee?: string,
|
|
95
147
|
referrerFeeShare?: string
|
|
148
|
+
inTokenDecimals?: number
|
|
96
149
|
}) {
|
|
150
|
+
const isNearChain = params.chain === '20000000000006' || params.chain === 'near'
|
|
151
|
+
|
|
152
|
+
// Near 链使用特殊的 API 端点和参数格式
|
|
153
|
+
if (isNearChain) {
|
|
154
|
+
const nearApiUrl = 'https://ethapi.openocean.finance/v1/near'
|
|
155
|
+
|
|
156
|
+
// 计算 amountAll(格式化后的金额,用于显示)
|
|
157
|
+
let amountAll = ''
|
|
158
|
+
if (params.inTokenDecimals !== undefined) {
|
|
159
|
+
const amountBigInt = BigInt(params.amount)
|
|
160
|
+
const decimals = BigInt(10 ** params.inTokenDecimals)
|
|
161
|
+
const wholePart = amountBigInt / decimals
|
|
162
|
+
const fractionalPart = amountBigInt % decimals
|
|
163
|
+
if (fractionalPart === 0n) {
|
|
164
|
+
amountAll = wholePart.toString()
|
|
165
|
+
} else {
|
|
166
|
+
const fractionalStr = fractionalPart.toString().padStart(params.inTokenDecimals, '0')
|
|
167
|
+
// 移除尾部的 0,但保留至少一位小数
|
|
168
|
+
const trimmedFractional = fractionalStr.replace(/0+$/, '') || '0'
|
|
169
|
+
amountAll = `${wholePart}.${trimmedFractional}`
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// 转换 slippage:从 0.01 (1%) 转为 100 (百分比格式)
|
|
174
|
+
const slippagePercent = params.slippage
|
|
175
|
+
? Math.floor(Number(params.slippage) * 100).toString()
|
|
176
|
+
: '100' // 默认 1%
|
|
177
|
+
|
|
178
|
+
const queryParams = new URLSearchParams({
|
|
179
|
+
quoteType: 'swap',
|
|
180
|
+
inTokenSymbol: params.inTokenSymbol,
|
|
181
|
+
inTokenAddress: params.inTokenAddress,
|
|
182
|
+
outTokenSymbol: params.outTokenSymbol,
|
|
183
|
+
outTokenAddress: params.outTokenAddress,
|
|
184
|
+
amount: params.amount,
|
|
185
|
+
...(amountAll && { amountAll }),
|
|
186
|
+
gasPrice: params.gasPrice || '5000000000',
|
|
187
|
+
disabledDexIds: params.disabledDexIds || '',
|
|
188
|
+
slippage: slippagePercent,
|
|
189
|
+
account: params.account,
|
|
190
|
+
referrer: params.referrer || '0x3487ef9f9b36547e43268b8f0e2349a226c70b53',
|
|
191
|
+
flags: '0', // Near API 特有参数
|
|
192
|
+
disableRfq: '', // Near API 特有参数
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
const response = await fetch(`${nearApiUrl}/swap-quote?${queryParams.toString()}`)
|
|
196
|
+
const data = await response.json()
|
|
197
|
+
return {
|
|
198
|
+
|
|
199
|
+
data: {
|
|
200
|
+
...data,
|
|
201
|
+
data: data.transaction,
|
|
202
|
+
price_impact: 0
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// 其他链使用原有逻辑
|
|
97
208
|
const apiUrl = this.getApiUrl(params.chain)
|
|
98
209
|
const slippage = (Number(params.slippage || 0.01)).toString();
|
|
99
210
|
const referrer: any = {
|
|
@@ -176,7 +287,7 @@ export class OpenOceanService {
|
|
|
176
287
|
}
|
|
177
288
|
|
|
178
289
|
static async getGasPrice(chain: string) {
|
|
179
|
-
if (!chain || chain === '1151111081099710' || chain === '20000000000001') {
|
|
290
|
+
if (!chain || chain === '1151111081099710' || chain === '20000000000001' || chain === '20000000000006') {
|
|
180
291
|
return {
|
|
181
292
|
data: {
|
|
182
293
|
gasPrice: '1000000000000000000',
|
|
@@ -186,6 +297,13 @@ export class OpenOceanService {
|
|
|
186
297
|
// const apiUrl = this.getApiUrl(chain)
|
|
187
298
|
const response = await fetch(`${this.API_V4_URL}/${chain}/gasPrice`)
|
|
188
299
|
const { data } = await response.json()
|
|
300
|
+
if (chain == '1') {
|
|
301
|
+
return {
|
|
302
|
+
standard: data?.standard?.maxFeePerGas || '101021713',
|
|
303
|
+
instant: data?.instant?.maxFeePerGas || '101021713',
|
|
304
|
+
fast: data?.fast?.maxFeePerGas || '101021713',
|
|
305
|
+
}
|
|
306
|
+
}
|
|
189
307
|
return data
|
|
190
308
|
}
|
|
191
309
|
|
|
@@ -255,9 +373,19 @@ export class OpenOceanService {
|
|
|
255
373
|
let url = `${this.API_V3_URL}/solana/getRpc`
|
|
256
374
|
const response = await fetch(url)
|
|
257
375
|
const data = await response.json()
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
376
|
+
if (data.data?.openapi_v1) {
|
|
377
|
+
let rpcUrl = data.data?.openapi_v1?.[0] || ''
|
|
378
|
+
this.solanaRpcUrl = rpcUrl
|
|
379
|
+
}
|
|
380
|
+
if (data.data?.openapi_v2) {
|
|
381
|
+
let rpcUrl = data.data?.openapi_v2?.[0] || ''
|
|
382
|
+
this.solanaRpcUrl = rpcUrl
|
|
383
|
+
}
|
|
384
|
+
if (data.data?.openapi_v3) {
|
|
385
|
+
let rpcUrl = data.data?.openapi_v3?.[0] || ''
|
|
386
|
+
this.solanaRpcUrl = rpcUrl
|
|
387
|
+
}
|
|
388
|
+
return this.solanaRpcUrl
|
|
261
389
|
}
|
|
262
390
|
}
|
|
263
391
|
|