@openocean.finance/widget 1.0.39 → 1.0.41

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openocean.finance/widget",
3
- "version": "1.0.39",
3
+ "version": "1.0.41",
4
4
  "description": "Openocean Widget for cross-chain bridging and swapping. It will drive your multi-chain strategy and attract new users from everywhere.",
5
5
  "type": "module",
6
6
  "main": "./dist/esm/index.js",
@@ -40,25 +40,25 @@
40
40
  "openocean"
41
41
  ],
42
42
  "dependencies": {
43
+ "@across-protocol/app-sdk": "^0.2.0",
43
44
  "@bigmi/client": "^0.1.1",
44
45
  "@bigmi/core": "^0.1.1",
46
+ "@defuse-protocol/one-click-sdk-typescript": "^0.1.2",
45
47
  "@emotion/react": "^11.14.0",
46
48
  "@emotion/styled": "^11.14.0",
49
+ "@lifi/sdk": "^3.6.8",
50
+ "@mayanfinance/swap-sdk": "^11.0.1",
47
51
  "@mui/icons-material": "6.0.2",
48
52
  "@mui/material": "^6.4.8",
49
53
  "@mui/system": "^6.4.8",
50
- "@openocean.finance/wallet-management": "^1.0.12",
51
- "@openocean.finance/widget-sdk": "^1.0.10",
52
- "@across-protocol/app-sdk": "^0.2.0",
54
+ "@openocean.finance/wallet-management": "^1.0.13",
55
+ "@openocean.finance/widget-sdk": "^1.0.12",
53
56
  "@near-wallet-selector/react-hook": "^9.0.0",
54
57
  "@reservoir0x/relay-sdk": "^2.4.0",
55
- "@lifi/sdk": "^3.6.8",
56
- "@mayanfinance/swap-sdk": "^11.0.1",
57
- "@defuse-protocol/one-click-sdk-typescript": "^0.1.2",
58
+ "@reservoir0x/relay-solana-wallet-adapter": "^2.0.5",
58
59
  "@solana/wallet-adapter-base": "^0.9.24",
59
60
  "@solana/web3.js": "^1.98.0",
60
61
  "@tanstack/react-virtual": "^3.13.4",
61
- "@reservoir0x/relay-solana-wallet-adapter": "^2.0.5",
62
62
  "ethers": "^6.13.5",
63
63
  "i18next": "^24.2.3",
64
64
  "microdiff": "^1.5.0",
@@ -37,4 +37,7 @@ export const DEFAULT_CHAIN_IDS = [
37
37
  10143, // Monad Testnet
38
38
  1151111081099710, // Solana
39
39
  999, // HyperEvm
40
+ 9745, // Plasma
41
+ 98866, // Plume
42
+ 239, // Tac
40
43
  ];
@@ -1,2 +1,2 @@
1
1
  export const name = '@openocean.finance/widget'
2
- export const version = '1.0.39'
2
+ export const version = '1.0.41'
@@ -17,6 +17,7 @@ export enum NonEvmChain {
17
17
  Near = 'near',
18
18
  Bitcoin = 20000000000001,
19
19
  Solana = 1151111081099710,
20
+ Plasma = 9745,
20
21
  }
21
22
 
22
23
  export const BitcoinToken = {
@@ -48,6 +49,10 @@ export const NonEvmChainInfo: {
48
49
  name: 'Solana',
49
50
  icon: 'https://solana.com/favicon.png',
50
51
  },
52
+ [NonEvmChain.Plasma]: {
53
+ name: 'Plasma',
54
+ icon: 'https://storage.googleapis.com/ks-setting-1d682dca/285205e7-a16d-421c-a794-67439cd6b54f1751515894455.png',
55
+ },
51
56
  }
52
57
 
53
58
  export const NOT_SUPPORTED_CHAINS_PRICE_SERVICE = [
@@ -59,6 +64,7 @@ export const NOT_SUPPORTED_CHAINS_PRICE_SERVICE = [
59
64
  NonEvmChain.Solana,
60
65
  NonEvmChain.Bitcoin,
61
66
  NonEvmChain.Near,
67
+ NonEvmChain.Plasma,
62
68
  ]
63
69
 
64
70
  export interface QuoteParams {
@@ -38,13 +38,10 @@ const mappingChain: Record<string, ChainName> = {
38
38
  [ChainId.HYE]: 'hyperevm',
39
39
  [ChainId.SOL]: 'solana',
40
40
  [ChainId.SUI]: 'sui',
41
+ // [ChainId.PLA]: 'plasma',
41
42
  }
42
43
 
43
44
  export class MayanAdapter extends BaseSwapAdapter {
44
- constructor() {
45
- super()
46
- }
47
-
48
45
  getName(): string {
49
46
  return 'Mayan'
50
47
  }
@@ -60,6 +57,9 @@ export class MayanAdapter extends BaseSwapAdapter {
60
57
  }
61
58
 
62
59
  async getQuote(params: EvmQuoteParams): Promise<NormalizedQuote> {
60
+ if (params.fromChain === ChainId.SOL) {
61
+ throw new Error('No quotes found')
62
+ }
63
63
  const quoteParams = {
64
64
  amount: +formatUnits(BigInt(params.amount), params.fromToken.decimals),
65
65
  fromToken: params.fromToken.isNative
@@ -119,40 +119,63 @@ export class MayanAdapter extends BaseSwapAdapter {
119
119
  { quote }: Quote,
120
120
  walletClient: WalletClient
121
121
  ): Promise<NormalizedTxResponse> {
122
- const account = walletClient.account?.address
123
- if (!account) throw new Error('WalletClient account is not defined')
124
-
125
- const res = getSwapFromEvmTxPayload(
126
- quote.rawQuote as MayanQuote,
127
- account,
128
- quote.quoteParams.recipient,
129
- { evm: CROSS_CHAIN_FEE_RECEIVER },
130
- account,
131
- quote.quoteParams.fromChain,
132
- null,
133
- null
134
- )
122
+ const account: any = quote.quoteParams.sender
123
+ if (!account) {
124
+ throw new Error('WalletClient account is not defined')
125
+ }
135
126
 
136
- if (res.to && res.value && res.data) {
137
- const tx = await walletClient.sendTransaction({
138
- chain: undefined,
127
+ if (!quote.quoteParams.fromChain) {
128
+ throw new Error(`Invalid fromChain: ${quote.quoteParams.fromChain}`)
129
+ }
130
+ const fromChain =
131
+ quote.quoteParams.fromChain === ChainId.SOL
132
+ ? 'solana'
133
+ : quote.quoteParams.fromChain
134
+
135
+ if (fromChain === 'solana') {
136
+ // const res = getSwapSolana({
137
+ // amountIn64: quote.quoteParams.amount,
138
+ // fromToken: quote.quoteParams.fromToken,
139
+ // minMiddleAmount: 0,
140
+ // middleToken: quote.quoteParams.toToken,
141
+ // userWallet: account,
142
+ // slippageBps: quote.quoteParams.slippage,
143
+ // referrerAddress: CROSS_CHAIN_FEE_RECEIVER,
144
+ // })
145
+ // debugger
146
+ } else {
147
+ const res = getSwapFromEvmTxPayload(
148
+ quote.rawQuote as MayanQuote,
149
+ account,
150
+ quote.quoteParams.recipient,
151
+ { evm: CROSS_CHAIN_FEE_RECEIVER },
139
152
  account,
140
- to: res.to as `0x${string}`,
141
- value: BigInt(res.value),
142
- data: res.data as `0x${string}`,
143
- })
144
- return {
145
- sender: quote.quoteParams.sender,
146
- id: tx, // specific id for each provider
147
- sourceTxHash: tx,
148
- adapter: this.getName(),
149
- sourceChain: quote.quoteParams.fromChain,
150
- targetChain: quote.quoteParams.toChain,
151
- inputAmount: quote.quoteParams.amount,
152
- outputAmount: quote.outputAmount.toString(),
153
- sourceToken: quote.quoteParams.fromToken,
154
- targetToken: quote.quoteParams.toToken,
155
- timestamp: new Date().getTime(),
153
+ fromChain,
154
+ null,
155
+ null
156
+ )
157
+ if (res.to && res.value && res.data) {
158
+ const tx = await walletClient.sendTransaction({
159
+ chain: undefined,
160
+ account: account as `0x${string}`,
161
+ to: res.to as `0x${string}`,
162
+ value: BigInt(res.value),
163
+ data: res.data as `0x${string}`,
164
+ kzg: undefined,
165
+ })
166
+ return {
167
+ sender: quote.quoteParams.sender,
168
+ id: tx, // specific id for each provider
169
+ sourceTxHash: tx,
170
+ adapter: this.getName(),
171
+ sourceChain: quote.quoteParams.fromChain,
172
+ targetChain: quote.quoteParams.toChain,
173
+ inputAmount: quote.quoteParams.amount,
174
+ outputAmount: quote.outputAmount.toString(),
175
+ sourceToken: quote.quoteParams.fromToken,
176
+ targetToken: quote.quoteParams.toToken,
177
+ timestamp: new Date().getTime(),
178
+ }
156
179
  }
157
180
  }
158
181
 
@@ -69,6 +69,35 @@ const hyperEvm = defineChain({
69
69
  },
70
70
  })
71
71
 
72
+ const plasma = defineChain({
73
+ id: 9745,
74
+ name: 'Plasma',
75
+ blockTime: 1000,
76
+ nativeCurrency: {
77
+ name: 'Plasma',
78
+ symbol: 'XPL',
79
+ decimals: 18,
80
+ },
81
+ rpcUrls: {
82
+ default: {
83
+ http: ['https://rpc.plasma.to'],
84
+ },
85
+ },
86
+ blockExplorers: {
87
+ default: {
88
+ name: 'PlasmaScan',
89
+ url: 'https://plasmascan.to',
90
+ },
91
+ },
92
+ contracts: {
93
+ multicall3: {
94
+ address: '0xcA11bde05977b3631167028862bE2a173976CA11',
95
+ blockCreated: 0,
96
+ },
97
+ },
98
+ })
99
+
100
+
72
101
  const SolanaChainId = 792703809
73
102
 
74
103
  const solanaChain = {
@@ -103,6 +132,7 @@ export class RelayAdapter extends BaseSwapAdapter {
103
132
  ronin,
104
133
  unichain,
105
134
  hyperEvm,
135
+ plasma
106
136
  ]
107
137
  .map(convertViemChainToRelayChain)
108
138
  .concat(solanaChain as any),
@@ -116,7 +146,7 @@ export class RelayAdapter extends BaseSwapAdapter {
116
146
  return 'https://storage.googleapis.com/ks-setting-1d682dca/84e906bb-eaeb-45d3-a64c-2aa9c84eb3ea1747759080942.png'
117
147
  }
118
148
  getSupportedChains(): Chain[] {
119
- return [NonEvmChain.Solana, ...MAINNET_NETWORKS]
149
+ return [NonEvmChain.Solana, NonEvmChain.Plasma, ...MAINNET_NETWORKS]
120
150
  // return [...MAINNET_NETWORKS]
121
151
  }
122
152
 
@@ -154,6 +184,7 @@ export class RelayAdapter extends BaseSwapAdapter {
154
184
  fee: params.feeBps.toString(),
155
185
  },
156
186
  ],
187
+ protocolVersion:'preferV2'
157
188
  // includedSwapSources: ['open-ocean'],
158
189
  },
159
190
  })
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+
1
2
  export type * from '@openocean.finance/widget-sdk'
2
3
  export { ChainType, ChainId, CoinKey } from '@openocean.finance/widget-sdk'
3
4
  export { App as OpenOceanWidget } from './App.js'
@@ -28,4 +29,4 @@ export { getPriceImpact } from './utils/getPriceImpact.js'
28
29
  export { percentFormatter } from './utils/percentFormatter.js'
29
30
  export { compactNumberFormatter } from './utils/compactNumberFormatter.js'
30
31
  export { currencyExtendedFormatter } from './utils/currencyExtendedFormatter.js'
31
- export { navigationRoutes } from './utils/navigationRoutes.js'
32
+ export { navigationRoutes } from './utils/navigationRoutes.js'
@@ -13,7 +13,7 @@ import {
13
13
  isRouteRefunded,
14
14
  } from './utils.js'
15
15
 
16
- const replaceBigInts = (obj: any): any => {
16
+ const replaceBigInts = (obj: any, visited = new WeakSet()): any => {
17
17
  if (obj === null || obj === undefined) {
18
18
  return obj
19
19
  }
@@ -22,14 +22,28 @@ const replaceBigInts = (obj: any): any => {
22
22
  return obj.toString()
23
23
  }
24
24
 
25
+ // 检查循环引用
26
+ if (typeof obj === 'object' && visited.has(obj)) {
27
+ return '[Circular Reference]'
28
+ }
29
+
25
30
  if (Array.isArray(obj)) {
26
- return obj.map(replaceBigInts)
31
+ visited.add(obj)
32
+ const result = obj.map((item) => replaceBigInts(item, visited))
33
+ visited.delete(obj)
34
+ return result
27
35
  }
28
36
 
29
37
  if (typeof obj === 'object') {
30
- return Object.fromEntries(
31
- Object.entries(obj).map(([key, value]) => [key, replaceBigInts(value)])
38
+ visited.add(obj)
39
+ const result = Object.fromEntries(
40
+ Object.entries(obj).map(([key, value]) => [
41
+ key,
42
+ replaceBigInts(value, visited),
43
+ ])
32
44
  )
45
+ visited.delete(obj)
46
+ return result
33
47
  }
34
48
 
35
49
  return obj