Skip to content

Commit

Permalink
First step cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
feli-xlabs committed Jan 15, 2025
1 parent f91ae86 commit 0c933de
Show file tree
Hide file tree
Showing 87 changed files with 353 additions and 4,908 deletions.
9 changes: 0 additions & 9 deletions core/base/src/utils/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ export function throws(fn: () => any): boolean {
}
}

export function range<T extends bigint | number>(from: T, to: T): T[] {
function* generator(from: T, to: T) {
for (let i = from; from < to; i++) {
yield i;
}
}
return Array.from(generator(from, to));
}

/**
* Maps an object to another by applying the given function to every "leaf" property
* (_i.e._ neither object nor array).
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@types/chai": "^4.3.5",
"@types/jest": "^29.5.12",
"@types/mocha": "^10.0.1",
"@types/node": "^20.17.9",
"@types/node": "^20.17.10",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"chai": "^4.3.7",
"jest": "^29.7.0",
Expand Down
1 change: 0 additions & 1 deletion platforms/solana/protocols/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"dependencies": {
"@wormhole-foundation/sdk-connect": "1.0.3",
"@wormhole-foundation/sdk-solana": "1.0.3",
"@coral-xyz/borsh": "0.30.1",
"@coral-xyz/anchor": "0.30.1",
"@solana/web3.js": "^1.95.8"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import {
chainToChainId,
enumItem,
Layout,
} from '@wormhole-foundation/sdk-base';
import { layoutItems } from '@wormhole-foundation/sdk-definitions';
import type { Layout } from '@wormhole-foundation/sdk-connect';
import { layoutItems } from '@wormhole-foundation/sdk-connect';
import { chainToChainId, enumItem } from '@wormhole-foundation/sdk-base';

const versionItem = <const N extends number>(custom: N) =>
({ name: 'version', binary: 'uint', size: 1, custom, omit: true }) as const;
Expand Down Expand Up @@ -81,6 +78,12 @@ const postedVaaV1Layout = [
...emitterAddressAndPayloadLayout,
] as const satisfies Layout;

/**
* Covers:
* - A VAA;
* - A message;
* - An unreliable message.
*/
export const accountDataLayout = {
binary: 'switch',
idSize: 3,
Expand Down
75 changes: 31 additions & 44 deletions platforms/solana/protocols/core/src/core.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
import type { Program } from '@coral-xyz/anchor';
import { Program } from '@coral-xyz/anchor';
import { Keypair, Transaction, PublicKey } from '@solana/web3.js';
import {
createVAA,
deserializeLayout,
toChain,
} from '@wormhole-foundation/sdk-connect';
import {
SolanaAddress,
SolanaPlatform,
SolanaUnsignedTransaction,
} from '@wormhole-foundation/sdk-solana';
import { accountDataLayout } from './accountLayout.js';
import { IDL } from './types.js';

import type {
CompiledInstruction,
Connection,
MessageAccountKeys,
MessageCompiledInstruction,
PublicKey,
TransactionResponse,
VersionedTransactionResponse,
} from '@solana/web3.js';
import { Keypair, Transaction } from '@solana/web3.js';
import type {
ChainId,
AnySolanaAddress,
SolanaChains,
SolanaTransaction,
} from '@wormhole-foundation/sdk-solana';
import type {
ChainsConfig,
Contracts,
Network,
Expand All @@ -20,64 +36,33 @@ import type {
WormholeCore,
WormholeMessageId,
} from '@wormhole-foundation/sdk-connect';
import {
createVAA,
toChain,
toChainId,
} from '@wormhole-foundation/sdk-connect';
import type {
AnySolanaAddress,
SolanaChains,
SolanaTransaction,
} from '@wormhole-foundation/sdk-solana';
import {
SolanaAddress,
SolanaPlatform,
SolanaUnsignedTransaction,
} from '@wormhole-foundation/sdk-solana';
import { deserializePostMessage } from './postMessageLayout.js';
import type { Wormhole as WormholeCoreContract } from './types.js';
import type { BridgeData } from './utils/index.js';
import {
createBridgeFeeTransferInstruction,
createPostMessageInstruction,
createPostVaaInstruction,
createReadOnlyWormholeProgramInterface,
createVerifySignaturesInstructions,
derivePostedVaaKey,
getGuardianSet,
getWormholeBridgeData,
} from './utils/index.js';

const SOLANA_SEQ_LOG = 'Program log: Sequence: ';

export class SolanaWormholeCore<N extends Network, C extends SolanaChains>
implements WormholeCore<N, C>
{
readonly chainId: ChainId;
readonly coreBridge: Program<WormholeCoreContract>;
readonly address: string;
protected bridgeData?: BridgeData;
get address() {
return this.coreBridge.programId;
}

constructor(
readonly network: N,
readonly chain: C,
readonly connection: Connection,
readonly contracts: Contracts,
) {
this.chainId = toChainId(chain);

const coreBridgeAddress = contracts.coreBridge;
if (!coreBridgeAddress)
if (contracts.coreBridge === undefined) {
throw new Error(
`CoreBridge contract Address for chain ${chain} not found`,
);
}

this.address = coreBridgeAddress;

this.coreBridge = createReadOnlyWormholeProgramInterface(
coreBridgeAddress,
connection,
this.coreBridge = new Program(
{ ...IDL, address: contracts.coreBridge },
{ connection },
);
}

Expand Down Expand Up @@ -123,7 +108,9 @@ export class SolanaWormholeCore<N extends Network, C extends SolanaChains>
}

async getMessageFee(): Promise<bigint> {
//return this.coreBridge.account.bridgeData.;
await this.ensureBridgeConfig();

return this.bridgeData!.config.fee;
}

Expand Down Expand Up @@ -356,7 +343,7 @@ export class SolanaWormholeCore<N extends Network, C extends SolanaChains>
sequence,
nonce,
payload,
} = deserializePostMessage(new Uint8Array(acctInfo?.data!));
} = deserializeLayout(accountDataLayout, acctInfo?.data);

return createVAA('Uint8Array', {
guardianSet: await this.getGuardianSetIndex(),
Expand Down
3 changes: 1 addition & 2 deletions platforms/solana/protocols/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ registerProtocol(_platform, 'WormholeCore', SolanaWormholeCore);

export * from './core.js';
export * from './types.js';
export * as utils from './utils/index.js';
export * from './postMessageLayout.js';
export * from './accountLayout.js';
27 changes: 0 additions & 27 deletions platforms/solana/protocols/core/src/postMessageLayout.ts

This file was deleted.

Loading

0 comments on commit 0c933de

Please sign in to comment.