Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eclipse Support #353

Merged
merged 14 commits into from
Nov 7, 2024
7 changes: 7 additions & 0 deletions .changeset/quiet-wasps-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@reservoir0x/relay-svm-wallet-adapter': patch
'@reservoir0x/relay-sdk': patch
'@reservoir0x/relay-kit-ui': patch
---

Support for eclipse svm
8 changes: 5 additions & 3 deletions demo/context/walletFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React, { createContext, useContext, useState, ReactNode } from 'react'

interface WalletFilterContextState {
walletFilter?: 'EVM' | 'SOL' | 'BTC'
setWalletFilter: (value: 'EVM' | 'SOL' | 'BTC' | undefined) => void
walletFilter?: 'EVM' | 'SOL' | 'ECLIPSE' | 'BTC'
setWalletFilter: (
value: 'EVM' | 'SOL' | 'BTC' | 'ECLIPSE' | undefined
) => void
}

const WalletFilterContext = createContext<WalletFilterContextState | undefined>(
Expand All @@ -13,7 +15,7 @@ export const WalletFilterProvider: React.FC<{ children: ReactNode }> = ({
children
}) => {
const [walletFilter, setWalletFilter] = useState<
'EVM' | 'SOL' | 'BTC' | undefined
'EVM' | 'SOL' | 'ECLIPSE' | 'BTC' | undefined
>(undefined)

return (
Expand Down
17 changes: 9 additions & 8 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@
"trailingComma": "none"
},
"dependencies": {
"@dynamic-labs/bitcoin": "^3.3.0",
"@dynamic-labs/ethereum": "^3.3.0",
"@dynamic-labs/sdk-react-core": "^3.3.0",
"@dynamic-labs/solana": "^3.3.0",
"@dynamic-labs/utils": "^3.4.2",
"@dynamic-labs/wagmi-connector": "^3.3.0",
"@dynamic-labs/bitcoin": "4.0.0-alpha.21",
"@dynamic-labs/eclipse": "4.0.0-alpha.21",
"@dynamic-labs/ethereum": "4.0.0-alpha.21",
"@dynamic-labs/sdk-react-core": "4.0.0-alpha.21",
"@dynamic-labs/solana": "4.0.0-alpha.21",
"@dynamic-labs/utils": "4.0.0-alpha.21",
"@dynamic-labs/wagmi-connector": "4.0.0-alpha.21",
"@radix-ui/colors": "^0.1.8",
"@reservoir0x/relay-bitcoin-wallet-adapter": "workspace:*",
"@reservoir0x/relay-kit-hooks": "workspace:*",
"@reservoir0x/relay-kit-ui": "workspace:*",
"@reservoir0x/relay-sdk": "workspace:*",
"@reservoir0x/relay-solana-wallet-adapter": "workspace:*",
"@reservoir0x/relay-svm-wallet-adapter": "workspace:*",
"@solana/web3.js": "^1.95.3",
"@tanstack/react-query": "^5.20.2",
"@types/node": "^22.5.4",
Expand All @@ -37,7 +38,7 @@
"wagmi": "~2.9.8"
},
"devDependencies": {
"@dynamic-labs/types": "^3.3.0",
"@dynamic-labs/types": "4.0.0-alpha.21",
"@types/node": "^12.12.21",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
Expand Down
6 changes: 4 additions & 2 deletions demo/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { HttpTransport } from 'viem'
import { chainIdToAlchemyNetworkMap } from 'utils/chainIdToAlchemyNetworkMap'
import { useWalletFilter, WalletFilterProvider } from 'context/walletFilter'
import { pipe } from '@dynamic-labs/utils'
import { EclipseWalletConnectors } from '@dynamic-labs/eclipse'

type AppWrapperProps = {
children: ReactNode
Expand All @@ -52,7 +53,7 @@ const AppWrapper: FC<AppWrapperProps> = ({ children }) => {
}, [router.query.api])

const { chains, viemChains } = useRelayChains(relayApi, {
includeChains: '8253038'
includeChains: '9286185,8253038'
})

useEffect(() => {
Expand Down Expand Up @@ -170,7 +171,8 @@ const AppWrapper: FC<AppWrapperProps> = ({ children }) => {
walletConnectors: [
EthereumWalletConnectors,
SolanaWalletConnectors,
BitcoinWalletConnectors
BitcoinWalletConnectors,
EclipseWalletConnectors
],
cssOverrides: `
[data-testid="send-balance-button"] {
Expand Down
2 changes: 1 addition & 1 deletion demo/pages/sdk/actions/swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ConnectButton } from 'components/ConnectButton'
import { useDynamicContext } from '@dynamic-labs/sdk-react-core'
import { isEthereumWallet } from '@dynamic-labs/ethereum'
import { isSolanaWallet } from '@dynamic-labs/solana'
import { adaptSolanaWallet } from '@reservoir0x/relay-solana-wallet-adapter'
import { adaptSolanaWallet } from '@reservoir0x/relay-svm-wallet-adapter'
import { adaptBitcoinWallet } from '@reservoir0x/relay-bitcoin-wallet-adapter'
import { adaptViemWallet } from '@reservoir0x/relay-sdk'
import { isBitcoinWallet } from '@dynamic-labs/bitcoin'
Expand Down
4 changes: 3 additions & 1 deletion demo/pages/ui/chain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
RelayChain
} from '@reservoir0x/relay-sdk'
import { isSolanaWallet } from '@dynamic-labs/solana'
import { adaptSolanaWallet } from '@reservoir0x/relay-solana-wallet-adapter'
import { adaptSolanaWallet } from '@reservoir0x/relay-svm-wallet-adapter'
import { isEthereumWallet } from '@dynamic-labs/ethereum'
import { useWalletFilter } from 'context/walletFilter'
import { isBitcoinWallet } from '@dynamic-labs/bitcoin'
Expand Down Expand Up @@ -167,6 +167,8 @@ const ChainWidgetPage: NextPage = () => {
setWalletFilter('SOL')
} else if (chain?.id === 8253038) {
setWalletFilter('BTC')
} else if (chain?.id === 9286185) {
setWalletFilter('ECLIPSE')
} else {
setWalletFilter(undefined)
}
Expand Down
32 changes: 20 additions & 12 deletions demo/pages/ui/swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { useEffect, useMemo, useRef, useState } from 'react'
import { isEthereumWallet } from '@dynamic-labs/ethereum'
import { isSolanaWallet } from '@dynamic-labs/solana'
import { adaptSolanaWallet } from '@reservoir0x/relay-solana-wallet-adapter'
import { adaptSolanaWallet } from '@reservoir0x/relay-svm-wallet-adapter'
import {
AdaptedWallet,
adaptViemWallet,
Expand All @@ -24,6 +24,7 @@ import { LinkedWallet } from '@reservoir0x/relay-kit-ui'
import { adaptBitcoinWallet } from '@reservoir0x/relay-bitcoin-wallet-adapter'
import { isBitcoinWallet } from '@dynamic-labs/bitcoin'
import { convertToLinkedWallet } from 'utils/dynamic'
import { isEclipseWallet } from '@dynamic-labs/eclipse'

const SwapWidgetPage: NextPage = () => {
useDynamicEvents('walletAdded', (newWallet) => {
Expand Down Expand Up @@ -68,17 +69,7 @@ const SwapWidgetPage: NextPage = () => {
try {
if (primaryWallet !== null) {
let adaptedWallet: AdaptedWallet | undefined
if (isSolanaWallet(primaryWallet)) {
const connection = await primaryWallet.getConnection()
const signer = await primaryWallet.getSigner()

adaptedWallet = adaptSolanaWallet(
primaryWallet.address,
792703809,
connection,
signer.signAndSendTransaction
)
} else if (isEthereumWallet(primaryWallet)) {
if (isEthereumWallet(primaryWallet)) {
const walletClient = await primaryWallet.getWalletClient()
adaptedWallet = adaptViemWallet(walletClient)
} else if (isBitcoinWallet(primaryWallet)) {
Expand All @@ -99,6 +90,21 @@ const SwapWidgetPage: NextPage = () => {
}
}
)
} else if (
isSolanaWallet(primaryWallet) ||
isEclipseWallet(primaryWallet)
) {
const connection = await (primaryWallet as any).getConnection()
const signer = await (primaryWallet as any).getSigner()
const _chainId = isEclipseWallet(primaryWallet)
? 9286185
: 792703809
adaptedWallet = adaptSolanaWallet(
primaryWallet.address,
_chainId,
connection,
signer.signAndSendTransaction
)
}
setWallet(adaptedWallet)
} else {
Expand Down Expand Up @@ -169,6 +175,8 @@ const SwapWidgetPage: NextPage = () => {
setWalletFilter('SOL')
} else if (chain?.id === 8253038) {
setWalletFilter('BTC')
} else if (chain?.id === 9286185) {
setWalletFilter('ECLIPSE')
} else {
setWalletFilter(undefined)
}
Expand Down
5 changes: 3 additions & 2 deletions demo/utils/dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const convertToLinkedWallet = (wallet: Wallet): LinkedWallet => {
let walletChain = wallet.chain.toLowerCase()
let vmType: 'evm' | 'svm' | 'bvm' = 'evm'

if (walletChain === 'sol') {
if (walletChain === 'sol' || walletChain === 'eclipse') {
vmType = 'svm'
} else if (walletChain === 'btc') {
vmType = 'bvm'
Expand All @@ -69,6 +69,7 @@ export const convertToLinkedWallet = (wallet: Wallet): LinkedWallet => {
return {
address,
walletLogoUrl: walletIcon,
vmType
vmType,
connector: wallet.connector.key
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"build:ui": "pnpm run -C packages/ui build",
"build:hooks": "pnpm run -C packages/hooks build",
"build:sdk": "pnpm run -C packages/sdk build",
"build:adapter": "pnpm run -C packages/relay-ethers-wallet-adapter build && pnpm run -C packages/relay-solana-wallet-adapter build && pnpm run -C packages/relay-bitcoin-wallet-adapter build",
"build:adapter": "pnpm run -C packages/relay-ethers-wallet-adapter build && pnpm run -C packages/relay-svm-wallet-adapter build && pnpm run -C packages/relay-bitcoin-wallet-adapter build",
"syncSdkTypes": "node packages/sdk/scripts/sync-api.mjs",
"sdk": "pnpm run -C packages/sdk dev",
"typecheck": "tsc --noEmit",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @reservoir0x/relay-solana-wallet-adapter
# @reservoir0x/relay-svm-wallet-adapter

## 2.0.5

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@reservoir0x/relay-solana-wallet-adapter",
"name": "@reservoir0x/relay-svm-wallet-adapter",
"version": "2.0.5",
"description": "A Solana adapter for use in @reservoir0x/relay-sdk",
"description": "An SVM (Solana Virtual Machine) adapter for use in @reservoir0x/relay-sdk",
"type": "module",
"source": "./src/index.ts",
"main": "./_cjs/src/index.js",
Expand Down Expand Up @@ -36,12 +36,16 @@
},
"keywords": [
"solana",
"eclipse",
"reservoir",
"relay-solana-wallet-adapter",
"relay-svm-wallet-adapter",
"reservoir-solana-wallet-adapter",
"relay",
"protocol",
"sdk-adapter"
"sdk-adapter",
"svm",
"solana-virtual-machine"
],
"publishConfig": {
"access": "public"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ export const adaptSolanaWallet = (
signature: TransactionSignature
}>
): AdaptedWallet => {
let _chainId = chainId
const getChainId = async () => {
return _chainId
}

return {
vmType: 'svm',
getChainId: async () => {
return chainId
},
getChainId,
address: async () => {
return walletAddress
},
Expand Down Expand Up @@ -100,9 +103,9 @@ export const adaptSolanaWallet = (
txHash
}
},
//@ts-ignore
switchChain: (chainId: number) => {
throw 'Not yet implemented'
_chainId = chainId
return new Promise((res) => res())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"compilerOptions": {
"baseUrl": ".",
"paths": {
"~relay-solana-wallet-adapter/*": ["./src/*"],
"~relay-svm-wallet-adapter/*": ["./src/*"],
},
},
"watchOptions": {
Expand Down
13 changes: 3 additions & 10 deletions packages/sdk/src/actions/getPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import {
type SimulateContractRequest
} from '../utils/index.js'
import { getClient } from '../client.js'
import type { ChainVM, Execute, paths } from '../types/index.js'
import type { Execute, paths } from '../types/index.js'
import { getDeadAddress } from '../constants/address.js'
import { svmChainIds } from '../constants/svm.js'
import { bvmChainIds } from '../constants/bvm.js'

export type PriceBody = NonNullable<
paths['/price']['post']['requestBody']['content']['application/json']
Expand Down Expand Up @@ -76,13 +74,8 @@ export async function getPrice(
return tx
})
}
let vmType: ChainVM = 'evm'
if (svmChainIds.includes(originChainId)) {
vmType = 'svm'
} else if (bvmChainIds.includes(originChainId)) {
vmType = 'bvm'
}
const deadAddress = getDeadAddress(vmType)
const originChain = client.chains.find((chain) => chain.id === originChainId)
const deadAddress = getDeadAddress(originChain?.vmType, originChain?.id)

const query: PriceBody = {
user: user ?? deadAddress,
Expand Down
6 changes: 4 additions & 2 deletions packages/sdk/src/constants/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ export const evmDeadAddress =
'0x000000000000000000000000000000000000dead' as const
export const solDeadAddress =
'CbKGgVKLJFb8bBrf58DnAkdryX6ubewVytn7X957YwNr' as const
export const eclipseDeadAddress =
'CrfbABN2sSvmoZLu9eDDfXpaC2nHg42R7AXbHs9eg4S9' as const
export const bitcoinDeadAddress = 'bc1q4vxn43l44h30nkluqfxd9eckf45vr2awz38lwa'

export const getDeadAddress = (vmType?: ChainVM) => {
export const getDeadAddress = (vmType?: ChainVM, chainId?: number) => {
if (vmType === 'svm') {
return solDeadAddress
return chainId === 9286185 ? eclipseDeadAddress : solDeadAddress
} else if (vmType === 'bvm') {
return bitcoinDeadAddress
} else {
Expand Down
1 change: 0 additions & 1 deletion packages/sdk/src/constants/svm.ts

This file was deleted.

8 changes: 7 additions & 1 deletion packages/ui/src/components/common/CustomAddressModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type { AdaptedWallet, RelayChain } from '@reservoir0x/relay-sdk'
import type { LinkedWallet } from '../../types/index.js'
import { truncateAddress } from '../../utils/truncate.js'
import { isValidAddress } from '../../utils/address.js'
import { eclipse, eclipseWallets } from '../../utils/solana.js'

type Props = {
open: boolean
Expand Down Expand Up @@ -53,7 +54,12 @@ export const CustomAddressModal: FC<Props> = ({
const availableWallets = useMemo(
() =>
linkedWallets.filter((wallet) =>
isValidAddress(toChain?.vmType, wallet.address)
isValidAddress(
toChain?.vmType,
wallet.address,
toChain?.id,
wallet.connector
)
),
[toChain, linkedWallets]
)
Expand Down
Loading