Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
FEAT: Split adapters to separate packages (#4)
Browse files Browse the repository at this point in the history
Bridge Adapter Updates
  • Loading branch information
rogaldh authored Dec 1, 2023
1 parent d4d8929 commit 6c2eebf
Show file tree
Hide file tree
Showing 133 changed files with 4,748 additions and 4,499 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
.vim
dist
dist-ssr
esm
node_modules
public/dist
server/dist
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
**/.turbo
**/storybook-static
**/dist/**
**/esm/**
.pnpm-store
.changeset
2 changes: 1 addition & 1 deletion BRIDGE_OVERVIEW.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This document covers the existing bridges available and how this package attempt
- Stable bridges: DeBridge, Wormhole.

- TODO:
- [] Mayan
- [x] Mayan
- [] CCTP
- [] AllBridge

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export abstract class AbstractBridgeAdapter {
To start developing, you may use these:

- `pnpm demo`. The demo application will be served on a local system.
- `pnpm dev`. It will build all the packages in watch mode as well as spin up a local development server with the demo application.
- `pnpm playground`. It will run a sandbox powered by Storybook and build all the needed packages in the watch mode (see the `playground` script at the root package. Those scripts might be used separately for human-friendly logging).
- `pnpm dev`. It will build all the packages in watch mode.

### Building

Expand Down
8 changes: 8 additions & 0 deletions apps/bridge-adapter-demo/next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
eslint: {
ignoreDuringBuilds: true,
},
webpack: (config) => {
config.resolve.fallback = { fs: false };

return config;
},
};

module.exports = nextConfig;
20 changes: 11 additions & 9 deletions apps/bridge-adapter-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,29 @@
"version": "0.1.0",
"private": true,
"scripts": {
"build-demo": "next build",
"clean": "rm -rf .turbo && rm -rf dist && rm -rf node_modules",
"demo": "next dev",
"dev": "next dev",
"dev-build": "next build",
"lint": "next lint",
"build-demo": "next build",
"_demo-dev": "next dev",
"start": "next start"
},
"dependencies": {
"@solana/bridge-adapter-react": "^0.1.0",
"@solana/bridge-adapter-react-ui": "^0.1.0",
"@solana/bridge-adapter-debridge-adapter": "^0.1.0",
"@solana/bridge-adapter-wormhole-adapter": "^0.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@solana/bridge-adapter-react": "^0.1.0",
"@solana/bridge-adapter-react-ui": "^0.1.0",
"@types/node": "^20",
"@types/react": "^18.2.13",
"@types/react-dom": "^18.2.6",
"eslint": "^8.29.0",
"eslint-config-next": "^13.4.7",
"next": "13.4.6",
"next": "^13.4.6",
"typescript": "^5.1.3"
},
"optionalDependencies": {
"net": "^1.0.2",
"tls": "^0.0.1"
}
}
50 changes: 30 additions & 20 deletions apps/bridge-adapter-demo/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
"use client";
import "@solana/bridge-adapter-react-ui/index.css";
import * as BridgeAdapterReact from "@solana/bridge-adapter-react";
import {
BridgeAdapterProvider,
EvmWalletProvider,
SolanaWalletProvider,
} from "@solana/bridge-adapter-react";
import * as React from "react";
import * as WalletAdapters from "@solana/wallet-adapter-wallets";
import {
SolflareWalletAdapter,
CoinbaseWalletAdapter,
} from "@solana/wallet-adapter-wallets";
import Head from "next/head";
import styles from "../styles/Home.module.css";
import { BridgeAdapter } from "@solana/bridge-adapter-react-ui";

import { Inter } from "next/font/google";

const inter = Inter({ subsets: ["latin"] });
import { DeBridgeBridgeAdapter } from "@solana/bridge-adapter-debridge-adapter/esm";
import { WormholeBridgeAdapter } from "@solana/bridge-adapter-wormhole-adapter/esm";

const solanaRpcUrl = process.env.NEXT_PUBLIC_SOLANA_RPC_URL;

Expand All @@ -29,10 +35,7 @@ export default function Home({
() =>
typeof globalThis.window === "undefined"
? []
: [
new WalletAdapters.SolflareWalletAdapter(),
new WalletAdapters.CoinbaseWalletAdapter(),
],
: [new SolflareWalletAdapter(), new CoinbaseWalletAdapter()],
[],
);

Expand All @@ -47,6 +50,11 @@ export default function Home({
[title],
);

const adapters = React.useMemo(
() => [DeBridgeBridgeAdapter, WormholeBridgeAdapter],
[],
);

// eslint-disable-next-line react-hooks/rules-of-hooks
const [error, setError] = React.useState<Error | undefined>();

Expand All @@ -57,30 +65,32 @@ export default function Home({
<meta name="description" content="Generated by create next app" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="/favicon.ico" />
<style>
@import
url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&display=swap');
</style>
</Head>
<main className={`${styles.main} ${inter.className}`}>
<BridgeAdapterReact.SolanaWalletProvider
<main className={`${styles.main}`}>
<SolanaWalletProvider
autoConnect={false}
onError={(e: Error) => setError(e)}
wallets={wallets}
>
<BridgeAdapterReact.EvmWalletProvider
<EvmWalletProvider
coinbaseWalletSettings={evmSettings.coinbaseWalletSettings}
walletConnectProjectId={evmSettings.walletConnectProjectId}
>
<BridgeAdapterReact.BridgeAdapterProvider
bridgeAdapterSettings={{
allow: ["deBridge", "wormhole"],
}}
<BridgeAdapterProvider
adapters={adapters}
error={error}
settings={{
solana: { solanaRpcUrl },
}}
>
<BridgeAdapter className={styles.inner} title={title} />
</BridgeAdapterReact.BridgeAdapterProvider>
</BridgeAdapterReact.EvmWalletProvider>
</BridgeAdapterReact.SolanaWalletProvider>
</BridgeAdapterProvider>
</EvmWalletProvider>
</SolanaWalletProvider>
</main>
</>
);
Expand Down
1 change: 1 addition & 0 deletions apps/bridge-adapter-demo/src/styles/Home.module.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.main {
display: flex;
font-family: 'Inter', sans-serif;
flex-direction: column;
justify-content: space-between;
align-items: center;
Expand Down
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
"name": "bridge-adapter-sdk",
"private": true,
"type": "module",
"license": "SEE LICENSE IN ./LICENSE",
"scripts": {
"build": "turbo run build",
"build-core": "turbo run build-core",
"build-demo": "turbo run build-demo",
"build-packages": "turbo run build-packages",
"dev": "turbo run dev --concurrency=14",
"build-storybook": "turbo run build-storybook -- --quiet",
"changeset": "changeset",
"ci:publish": "turbo run build-packages && changeset publish",
"ci:publish": "turbo run build-pkg && changeset publish",
"ci:version": "changeset version",
"clean": "turbo run clean && rm -rf node_modules",
"demo": "turbo run demo",
"dev": "turbo run dev --continue",
"format": "prettier -w \"**/*.{js,cjs,ts,tsx,md,json}\"",
"lint": "turbo run lint && manypkg check",
"playground": "npx concurrently \"pnpm --filter @solana/bridge-adapter-react-ui playground\" \"pnpm run dev\"",
"playground": "pnpm --filter @solana/bridge-adapter-react-ui playground",
"test": "turbo run test",
"version-packages": "changeset version"
},
Expand All @@ -40,25 +40,25 @@
"prettier": "^2.8.0",
"rimraf": "^5.0.1",
"tsup": "^7.0.0",
"turbo": "1.10.13"
"turbo": "1.10.13",
"zod": "^3.22.4"
},
"packageManager": "[email protected]",
"pnpm": {
"overrides": {
"lodash@<4.17.11": ">=4.17.11",
"ajv@<6.12.3": ">=6.12.3",
"jsonwebtoken@<=8.5.1": ">=9.0.0",
"ws@>=6.0.0 <6.2.2": ">=6.2.2",
"lodash@<4.17.20": ">=4.17.20",
"postcss@<8.4.31": ">=8.4.31",
"axios@>=0.8.1 <1.6.0": ">=1.6.0",
"moment@<2.29.2": ">=2.29.2",
"moment@>=2.18.0 <2.29.4": ">=2.29.4",
"qs@>=6.5.0 <6.5.3": ">=6.5.3",
"lodash@>=3.7.0 <4.17.19": ">=4.17.19",
"lodash@<4.17.12": ">=4.17.12",
"lodash@<4.17.21": ">=4.17.21",
"tough-cookie@<4.1.3": ">=4.1.3",
"jsonwebtoken@<9.0.0": ">=9.0.0",
"lodash@<4.17.12": ">=4.17.12",
"qs@>=6.5.0 <6.5.3": ">=6.5.3",
"graphql@>=16.3.0 <16.8.1": ">=16.8.1",
"postcss@<8.4.31": ">=8.4.31"
"zod@<=3.22.2": ">=3.22.3"
}
}
}
1 change: 1 addition & 0 deletions packages/adapters/deBridge/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @solana/bridge-adapter-debridge-adapter
5 changes: 5 additions & 0 deletions packages/adapters/deBridge/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh -e
rm -rf .turbo
rm -rf node_modules
rm -rf dist
rm -rf esm
69 changes: 69 additions & 0 deletions packages/adapters/deBridge/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"name": "@solana/bridge-adapter-debridge-adapter",
"version": "0.1.0",
"license": "SEE LICENSE IN ../../../LICENSE",
"sideEffects": false,
"type": "module",
"exports": {
".": {
"import": "./esm/index.js",
"types": "./esm/index.d.ts"
},
"./esm": {
"import": "./esm/index.js",
"types": "./esm/index.d.ts"
}
},
"main": "./esm/index.js",
"module": "./esm/index.js",
"types": "./esm/index.d.ts",
"files": [
"dist/**",
"esm/**",
"src/**"
],
"scripts": {
"build/dist": "tsup src/index.tsx --env.ESM_ONLY=true",
"build/browser": "pnpm build/dist --platform=browser",
"build/esm": "tsc --build tsconfig.esm.json --verbose",
"build": "pnpm run build/esm",
"clean": "./clean.sh",
"lint": "eslint \"src/**/*.ts*\"",
"test": "pnpm run test-types",
"test-types": "tsc --noEmit"
},
"eslintConfig": {
"parserOptions": {
"project": true
},
"extends": [
"bridge-adapter-sdk"
]
},
"dependencies": {
"@certusone/wormhole-sdk": "^0.10.4",
"csv42": "^4.0.0"
},
"devDependencies": {
"@solana/bridge-adapter-core": "^0.1.0",
"@solana/web3.js": "^1.78.0",
"@types/web3": "^1.2.2",
"bridge-adapter-sdk-tsconfig": "^0.1.1",
"debug": "^4.3.4",
"eslint": "^8.29.0",
"eslint-config-bridge-adapter-sdk": "^0.0.0",
"tsup": "^7.0.0",
"typescript": "^5.1.3",
"undici": "^5.26.2",
"valibot": "^0.3.0",
"viem": "^1.4.1"
},
"peerDependencies": {
"@solana/web3.js": "^1.78.0",
"valibot": "^0.3.0",
"viem": "^1.4.1"
},
"publishConfig": {
"access": "public"
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ChainName, Token } from "@solana/bridge-adapter-core";
import { zeroAddress } from "viem";
import {
arbitrum,
Expand All @@ -8,8 +9,6 @@ import {
optimism,
polygon,
} from "viem/chains";
import type { ChainName } from "../types/Chain";
import type { Token } from "../types/Token";

export function chainIdToChainName(chainId: number): ChainName | undefined {
switch (chainId) {
Expand Down Expand Up @@ -38,47 +37,6 @@ export function chainIdToChainName(chainId: number): ChainName | undefined {
}
}

export function chainNameToViemChain(chainName: ChainName) {
switch (chainName) {
case "Ethereum": {
return mainnet;
}
case "Arbitrum": {
return arbitrum;
}
case "Optimism": {
return optimism;
}
case "Avalanche": {
return avalanche;
}
case "BSC": {
return bsc;
}
case "Polygon": {
return polygon;
}
case "Solana": {
throw new Error("Viem does not support Solana");
}
default: {
throw new Error("Invalid chain name");
}
}
}

export const SOLANA_FAKE_CHAIN_ID = -1;
export function chainNameToChainId(
chainName: ChainName,
solanaChainOverride: number = SOLANA_FAKE_CHAIN_ID,
) {
if (chainName === "Solana") {
return solanaChainOverride;
}
const chain = chainNameToViemChain(chainName);
return chain.id;
}

export function chainNameToNativeCurrency(chainName: ChainName): Token {
const ethCoin = {
address: zeroAddress,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FeeToken } from "../types/Token";
import type { FeeToken } from "@solana/bridge-adapter-core";

export function dedupFeesTokens(fees: FeeToken[]): FeeToken[] {
const dedupFees = fees.reduce((prev, curr) => {
Expand Down
Loading

0 comments on commit 6c2eebf

Please sign in to comment.