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
File renamed without changes.
15 changes: 15 additions & 0 deletions clients/ts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# @base/bridge

To install dependencies:

```bash
bun install
```

To run:

```bash
bun run index.ts
```

This project was created using `bun init` in bun v1.2.18. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
112 changes: 112 additions & 0 deletions clients/ts/bun.lock

Large diffs are not rendered by default.

65 changes: 65 additions & 0 deletions clients/ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"name": "@base/bridge",
"version": "1.0.0",
"description": "TypeScript SDK for Base-Solana bridge operations",
"sideEffects": false,
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.js"
},
"./bridge": {
"types": "./dist/bridge/index.d.ts",
"import": "./dist/bridge/index.js",
"require": "./dist/bridge/index.js"
},
"./base-relayer": {
"types": "./dist/base-relayer/index.d.ts",
"import": "./dist/base-relayer/index.js",
"require": "./dist/base-relayer/index.js"
}
},
"files": [
"./dist",
"README.md"
],
"scripts": {
"build": "bun run clean && bun run tsc",
"clean": "rm -rf dist",
"prepublishOnly": "bun run build"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
},
"keywords": [
"base",
"solana",
"bridge",
"cross-chain",
"typescript",
"sdk"
],
"author": "Base Team",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/base/bridge.git"
},
"bugs": {
"url": "https://github.com/base/bridge/issues"
},
"homepage": "https://github.com/base/bridge#readme",
"devDependencies": {
"@types/bun": "latest",
"typescript": "^5.9.2"
},
"peerDependencies": {
"@solana/kit": "^2.3.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import {
transformEncoder,
type Account,
type Address,
type Codec,
type Decoder,
type EncodedAccount,
type Encoder,
type FetchAccountConfig,
type FetchAccountsConfig,
type FixedSizeCodec,
type FixedSizeDecoder,
type FixedSizeEncoder,
type MaybeAccount,
type MaybeEncodedAccount,
type ReadonlyUint8Array,
Expand Down Expand Up @@ -78,7 +78,7 @@ export type CfgArgs = {
gasConfig: GasConfigArgs;
};

export function getCfgEncoder(): Encoder<CfgArgs> {
export function getCfgEncoder(): FixedSizeEncoder<CfgArgs> {
return transformEncoder(
getStructEncoder([
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
Expand All @@ -91,7 +91,7 @@ export function getCfgEncoder(): Encoder<CfgArgs> {
);
}

export function getCfgDecoder(): Decoder<Cfg> {
export function getCfgDecoder(): FixedSizeDecoder<Cfg> {
return getStructDecoder([
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
['nonce', getU64Decoder()],
Expand All @@ -101,7 +101,7 @@ export function getCfgDecoder(): Decoder<Cfg> {
]);
}

export function getCfgCodec(): Codec<CfgArgs, Cfg> {
export function getCfgCodec(): FixedSizeCodec<CfgArgs, Cfg> {
return combineCodec(getCfgEncoder(), getCfgDecoder());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ import {
transformEncoder,
type Account,
type Address,
type Codec,
type Decoder,
type EncodedAccount,
type Encoder,
type FetchAccountConfig,
type FetchAccountsConfig,
type FixedSizeCodec,
type FixedSizeDecoder,
type FixedSizeEncoder,
type MaybeAccount,
type MaybeEncodedAccount,
type ReadonlyUint8Array,
Expand Down Expand Up @@ -60,7 +60,7 @@ export type MessageToRelayArgs = {
gasLimit: number | bigint;
};

export function getMessageToRelayEncoder(): Encoder<MessageToRelayArgs> {
export function getMessageToRelayEncoder(): FixedSizeEncoder<MessageToRelayArgs> {
return transformEncoder(
getStructEncoder([
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
Expand All @@ -72,7 +72,7 @@ export function getMessageToRelayEncoder(): Encoder<MessageToRelayArgs> {
);
}

export function getMessageToRelayDecoder(): Decoder<MessageToRelay> {
export function getMessageToRelayDecoder(): FixedSizeDecoder<MessageToRelay> {
return getStructDecoder([
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
['nonce', getU64Decoder()],
Expand All @@ -81,7 +81,7 @@ export function getMessageToRelayDecoder(): Decoder<MessageToRelay> {
]);
}

export function getMessageToRelayCodec(): Codec<
export function getMessageToRelayCodec(): FixedSizeCodec<
MessageToRelayArgs,
MessageToRelay
> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import {
getStructDecoder,
getStructEncoder,
transformEncoder,
type AccountMeta,
type AccountSignerMeta,
type Address,
type Codec,
type Decoder,
type Encoder,
type IAccountMeta,
type IAccountSignerMeta,
type IInstruction,
type IInstructionWithAccounts,
type IInstructionWithData,
type FixedSizeCodec,
type FixedSizeDecoder,
type FixedSizeEncoder,
type Instruction,
type InstructionWithAccounts,
type InstructionWithData,
type ReadonlyAccount,
type ReadonlySignerAccount,
type ReadonlyUint8Array,
Expand Down Expand Up @@ -56,25 +56,25 @@ export function getInitializeDiscriminatorBytes() {

export type InitializeInstruction<
TProgram extends string = typeof BASE_RELAYER_PROGRAM_ADDRESS,
TAccountPayer extends string | IAccountMeta<string> = string,
TAccountCfg extends string | IAccountMeta<string> = string,
TAccountGuardian extends string | IAccountMeta<string> = string,
TAccountPayer extends string | AccountMeta<string> = string,
TAccountCfg extends string | AccountMeta<string> = string,
TAccountGuardian extends string | AccountMeta<string> = string,
TAccountSystemProgram extends
| string
| IAccountMeta<string> = '11111111111111111111111111111111',
TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
> = IInstruction<TProgram> &
IInstructionWithData<Uint8Array> &
IInstructionWithAccounts<
| AccountMeta<string> = '11111111111111111111111111111111',
TRemainingAccounts extends readonly AccountMeta<string>[] = [],
> = Instruction<TProgram> &
InstructionWithData<ReadonlyUint8Array> &
InstructionWithAccounts<
[
TAccountPayer extends string
? WritableSignerAccount<TAccountPayer> &
IAccountSignerMeta<TAccountPayer>
AccountSignerMeta<TAccountPayer>
: TAccountPayer,
TAccountCfg extends string ? WritableAccount<TAccountCfg> : TAccountCfg,
TAccountGuardian extends string
? ReadonlySignerAccount<TAccountGuardian> &
IAccountSignerMeta<TAccountGuardian>
AccountSignerMeta<TAccountGuardian>
: TAccountGuardian,
TAccountSystemProgram extends string
? ReadonlyAccount<TAccountSystemProgram>
Expand All @@ -96,7 +96,7 @@ export type InitializeInstructionDataArgs = {
gasConfig: GasConfigArgs;
};

export function getInitializeInstructionDataEncoder(): Encoder<InitializeInstructionDataArgs> {
export function getInitializeInstructionDataEncoder(): FixedSizeEncoder<InitializeInstructionDataArgs> {
return transformEncoder(
getStructEncoder([
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
Expand All @@ -108,7 +108,7 @@ export function getInitializeInstructionDataEncoder(): Encoder<InitializeInstruc
);
}

export function getInitializeInstructionDataDecoder(): Decoder<InitializeInstructionData> {
export function getInitializeInstructionDataDecoder(): FixedSizeDecoder<InitializeInstructionData> {
return getStructDecoder([
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
['newGuardian', getAddressDecoder()],
Expand All @@ -117,7 +117,7 @@ export function getInitializeInstructionDataDecoder(): Decoder<InitializeInstruc
]);
}

export function getInitializeInstructionDataCodec(): Codec<
export function getInitializeInstructionDataCodec(): FixedSizeCodec<
InitializeInstructionDataArgs,
InitializeInstructionData
> {
Expand Down Expand Up @@ -230,7 +230,7 @@ export function getInitializeInstruction<

export type ParsedInitializeInstruction<
TProgram extends string = typeof BASE_RELAYER_PROGRAM_ADDRESS,
TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[],
TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[],
> = {
programAddress: Address<TProgram>;
accounts: {
Expand Down Expand Up @@ -266,19 +266,19 @@ export type ParsedInitializeInstruction<

export function parseInitializeInstruction<
TProgram extends string,
TAccountMetas extends readonly IAccountMeta[],
TAccountMetas extends readonly AccountMeta[],
>(
instruction: IInstruction<TProgram> &
IInstructionWithAccounts<TAccountMetas> &
IInstructionWithData<Uint8Array>
instruction: Instruction<TProgram> &
InstructionWithAccounts<TAccountMetas> &
InstructionWithData<ReadonlyUint8Array>
): ParsedInitializeInstruction<TProgram, TAccountMetas> {
if (instruction.accounts.length < 4) {
// TODO: Coded error.
throw new Error('Not enough accounts');
}
let accountIndex = 0;
const getNextAccount = () => {
const accountMeta = instruction.accounts![accountIndex]!;
const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!;
accountIndex += 1;
return accountMeta;
};
Expand Down
Loading