Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true

jobs:
ci:
name: Build & Test
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v2

- name: Install dependencies
run: bun install --frozen-lockfile

- name: Check formatting & lint
run: bun run check:ci

- name: Typecheck
run: bun run typecheck

- name: Build
run: bun run build

- name: Test
run: bun test
39 changes: 39 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"$schema": "https://biomejs.dev/schemas/2.4.0/schema.json",
"vcs": {
"enabled": true,
"clientKind": "git",
"useIgnoreFile": true
},
"formatter": {
"indentStyle": "space",
"indentWidth": 2
},
"javascript": {
"formatter": {
"quoteStyle": "double",
"semicolons": "always",
"trailingCommas": "all"
}
},
"linter": {
"rules": {
"recommended": true,
"suspicious": {
"noExplicitAny": "warn"
},
"style": {
"noNonNullAssertion": "warn"
}
}
},
"files": {
"includes": [
"**",
"!dist",
"!src/clients/ts",
"!src/interfaces/abis",
"!src/interfaces/idls"
]
}
}
19 changes: 19 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/baseToSolanaCall.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createBridgeClient } from "../src";
import { makeSolanaAdapter } from "../src/adapters/chains/solana/adapter";
import { makeEvmAdapter } from "../src/adapters/chains/evm/adapter";
import { makeSolanaAdapter } from "../src/adapters/chains/solana/adapter";
import { BASE_MAINNET_CHAIN_ID } from "../src/core/protocol/router";
import { loadSolanaKeypair } from "../src/node";

Expand Down
7 changes: 5 additions & 2 deletions examples/call.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createBridgeClient } from "../src";
import { makeSolanaAdapter } from "../src/adapters/chains/solana/adapter";
import { makeEvmAdapter } from "../src/adapters/chains/evm/adapter";
import { makeSolanaAdapter } from "../src/adapters/chains/solana/adapter";
import { BASE_MAINNET_CHAIN_ID } from "../src/core/protocol/router";
import { loadSolanaKeypair } from "../src/node";

Expand All @@ -24,7 +24,10 @@ async function main() {
});

const op = await client.call({
route: { sourceChain: "solana:mainnet", destinationChain: BASE_MAINNET_CHAIN_ID },
route: {
sourceChain: "solana:mainnet",
destinationChain: BASE_MAINNET_CHAIN_ID,
},
call: {
kind: "evm",
call: {
Expand Down
7 changes: 5 additions & 2 deletions examples/evmToSolanaTokenTransfer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createBridgeClient } from "../src";
import { makeSolanaAdapter } from "../src/adapters/chains/solana/adapter";
import { makeEvmAdapter } from "../src/adapters/chains/evm/adapter";
import { makeSolanaAdapter } from "../src/adapters/chains/solana/adapter";
import { BASE_MAINNET_CHAIN_ID } from "../src/core/protocol/router";
import { loadSolanaKeypair } from "../src/node";

Expand Down Expand Up @@ -33,7 +33,10 @@ async function main() {
});

const op = await client.transfer({
route: { sourceChain: BASE_MAINNET_CHAIN_ID, destinationChain: "solana:mainnet" },
route: {
sourceChain: BASE_MAINNET_CHAIN_ID,
destinationChain: "solana:mainnet",
},
asset: {
kind: "token",
address: "0x0000000000000000000000000000000000000000",
Expand Down
4 changes: 2 additions & 2 deletions examples/transfer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createBridgeClient } from "../src";
import { base, solanaMainnet } from "../src/chains";
import { makeSolanaAdapter } from "../src/adapters/chains/solana/adapter";
import { makeEvmAdapter } from "../src/adapters/chains/evm/adapter";
import { makeSolanaAdapter } from "../src/adapters/chains/solana/adapter";
import { base, solanaMainnet } from "../src/chains";
import { loadSolanaKeypair } from "../src/node";

// Example: Solana -> Base (EVM) transfer (native SOL)
Expand Down
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@
"types": "tsc -p tsconfig.build.json",
"test": "bun test",
"typecheck": "tsc --noEmit",
"dev": "bun --hot ./index.ts"
"dev": "bun --hot ./index.ts",
"lint": "biome lint --write .",
"lint:check": "biome lint .",
"format": "biome format --write .",
"format:check": "biome format .",
"check": "biome check --write .",
"check:ci": "biome check ."
},
"keywords": [
"bridge",
Expand All @@ -41,6 +47,7 @@
"author": "Base",
"license": "MIT",
"devDependencies": {
"@biomejs/biome": "2.3.15",
"@types/bun": "1.3.2",
"typescript": "5.9.3"
},
Expand Down
10 changes: 5 additions & 5 deletions src/adapters/chains/evm/adapter.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { ChainRef } from "../../../core/types";
import {
type Chain,
createPublicClient,
createWalletClient,
http,
type Chain,
type Hash,
type Hex,
http,
type PublicClient,
type WalletClient,
} from "viem";
import { privateKeyToAccount } from "viem/accounts";
import type { ChainRef } from "../../../core/types";
import type { EvmAdapterConfig, EvmChainAdapter } from "./types";

function makeViemChain(chainId: number): Chain {
Expand All @@ -23,7 +23,7 @@ function makeViemChain(chainId: number): Chain {
}

function hasViemChain(
config: EvmAdapterConfig
config: EvmAdapterConfig,
): config is Extract<EvmAdapterConfig, { chain: unknown }> {
return (config as any).chain != null;
}
Expand All @@ -36,7 +36,7 @@ export function makeEvmAdapter(config: EvmAdapterConfig): EvmChainAdapter {
: config.chainId;
const chain: ChainRef = { id: `eip155:${chainId}` };
const viemChain = hasViemChain(config)
? (config.chain as any).viem ?? config.chain
? ((config.chain as any).viem ?? config.chain)
: makeViemChain(chainId);

const publicClient = createPublicClient({
Expand Down
4 changes: 2 additions & 2 deletions src/adapters/chains/evm/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ChainAdapter, ChainRef } from "../../../core/types";
import type { Chain, Hash, Hex, PublicClient, WalletClient } from "viem";
import type { ChainAdapter, ChainRef } from "../../../core/types";

export type EvmWalletConfig =
| { type: "privateKey"; key: Hex }
Expand Down Expand Up @@ -48,6 +48,6 @@ export interface EvmChainAdapter extends ChainAdapter {

/** Convenience reads */
getTransactionReceipt(
hash: Hash
hash: Hash,
): Promise<Awaited<ReturnType<PublicClient["getTransactionReceipt"]>>>;
}
8 changes: 4 additions & 4 deletions src/adapters/chains/solana/adapter.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {
createSolanaRpc,
type Account,
createSolanaRpc,
type Address as SolAddress,
} from "@solana/kit";
import type { ChainRef } from "../../../core/types";
import {
fetchOutgoingMessage,
type OutgoingMessage,
} from "../../../clients/ts/src/bridge";
import type { ChainRef } from "../../../core/types";
import type { SolanaAdapterConfig, SolanaChainAdapter } from "./types";

/**
Expand All @@ -26,7 +26,7 @@ import type { SolanaAdapterConfig, SolanaChainAdapter } from "./types";
* });
*/
export function makeSolanaAdapter(
config: SolanaAdapterConfig
config: SolanaAdapterConfig,
): SolanaChainAdapter {
const payer = config.payer.signer;
const chain: ChainRef = config.chain ?? { id: "solana:mainnet" };
Expand All @@ -41,7 +41,7 @@ export function makeSolanaAdapter(
await rpc.getLatestBlockhash().send();
},
async fetchOutgoingMessage(
address: SolAddress
address: SolAddress,
): Promise<Account<OutgoingMessage, string>> {
return await fetchOutgoingMessage(rpc, address);
},
Expand Down
6 changes: 3 additions & 3 deletions src/adapters/chains/solana/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type {
Account,
Address as SolAddress,
KeyPairSigner,
Address as SolAddress,
} from "@solana/kit";
import type { ChainAdapter, ChainRef } from "../../../core/types";
import type { OutgoingMessage } from "../../../clients/ts/src/bridge";
import type { ChainAdapter, ChainRef } from "../../../core/types";

export type SolanaPayerConfig = { type: "signer"; signer: KeyPairSigner };

Expand All @@ -22,6 +22,6 @@ export interface SolanaChainAdapter extends ChainAdapter {
readonly payer: KeyPairSigner;

fetchOutgoingMessage(
address: SolAddress
address: SolAddress,
): Promise<Account<OutgoingMessage, string>>;
}
2 changes: 1 addition & 1 deletion src/core/capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function isTerminalStatus(s: ExecutionStatus): boolean {

export function isAllowedTransition(
from: ExecutionStatus["type"],
to: ExecutionStatus["type"]
to: ExecutionStatus["type"],
): boolean {
if (from === to) return true;
if (to === "Failed" || to === "Expired") return true;
Expand Down
Loading