Skip to content

Commit 090bc93

Browse files
committed
First step cleanup
1 parent f91ae86 commit 090bc93

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+344
-4891
lines changed

core/base/src/utils/misc.ts

-9
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,6 @@ export function throws(fn: () => any): boolean {
2626
}
2727
}
2828

29-
export function range<T extends bigint | number>(from: T, to: T): T[] {
30-
function* generator(from: T, to: T) {
31-
for (let i = from; from < to; i++) {
32-
yield i;
33-
}
34-
}
35-
return Array.from(generator(from, to));
36-
}
37-
3829
/**
3930
* Maps an object to another by applying the given function to every "leaf" property
4031
* (_i.e._ neither object nor array).

package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"@types/chai": "^4.3.5",
1010
"@types/jest": "^29.5.12",
1111
"@types/mocha": "^10.0.1",
12-
"@types/node": "^20.17.9",
12+
"@types/node": "^20.17.10",
1313
"@typescript-eslint/eslint-plugin": "^6.21.0",
1414
"chai": "^4.3.7",
1515
"jest": "^29.7.0",

platforms/solana/protocols/core/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
"dependencies": {
4848
"@wormhole-foundation/sdk-connect": "1.0.3",
4949
"@wormhole-foundation/sdk-solana": "1.0.3",
50-
"@coral-xyz/borsh": "0.30.1",
5150
"@coral-xyz/anchor": "0.30.1",
5251
"@solana/web3.js": "^1.95.8"
5352
},

platforms/solana/src/testing/accountVaaLayout.ts platforms/solana/protocols/core/src/accountLayout.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import {
2-
chainToChainId,
3-
enumItem,
4-
Layout,
5-
} from '@wormhole-foundation/sdk-base';
6-
import { layoutItems } from '@wormhole-foundation/sdk-definitions';
1+
import type { Layout } from '@wormhole-foundation/sdk-connect';
2+
import { layoutItems } from '@wormhole-foundation/sdk-connect';
3+
import { chainToChainId, enumItem } from '@wormhole-foundation/sdk-base';
74

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

81+
/**
82+
* Covers:
83+
* - A VAA;
84+
* - A message;
85+
* - An unreliable message.
86+
*/
8487
export const accountDataLayout = {
8588
binary: 'switch',
8689
idSize: 3,

platforms/solana/protocols/core/src/core.ts

+31-44
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
1-
import type { Program } from '@coral-xyz/anchor';
1+
import { Program } from '@coral-xyz/anchor';
2+
import { Keypair, Transaction, PublicKey } from '@solana/web3.js';
3+
import {
4+
createVAA,
5+
deserializeLayout,
6+
toChain,
7+
} from '@wormhole-foundation/sdk-connect';
8+
import {
9+
SolanaAddress,
10+
SolanaPlatform,
11+
SolanaUnsignedTransaction,
12+
} from '@wormhole-foundation/sdk-solana';
13+
import { accountDataLayout } from './accountLayout.js';
14+
import { IDL } from './types.js';
15+
216
import type {
317
CompiledInstruction,
418
Connection,
519
MessageAccountKeys,
620
MessageCompiledInstruction,
7-
PublicKey,
821
TransactionResponse,
922
VersionedTransactionResponse,
1023
} from '@solana/web3.js';
11-
import { Keypair, Transaction } from '@solana/web3.js';
1224
import type {
13-
ChainId,
25+
AnySolanaAddress,
26+
SolanaChains,
27+
SolanaTransaction,
28+
} from '@wormhole-foundation/sdk-solana';
29+
import type {
1430
ChainsConfig,
1531
Contracts,
1632
Network,
@@ -20,64 +36,33 @@ import type {
2036
WormholeCore,
2137
WormholeMessageId,
2238
} from '@wormhole-foundation/sdk-connect';
23-
import {
24-
createVAA,
25-
toChain,
26-
toChainId,
27-
} from '@wormhole-foundation/sdk-connect';
28-
import type {
29-
AnySolanaAddress,
30-
SolanaChains,
31-
SolanaTransaction,
32-
} from '@wormhole-foundation/sdk-solana';
33-
import {
34-
SolanaAddress,
35-
SolanaPlatform,
36-
SolanaUnsignedTransaction,
37-
} from '@wormhole-foundation/sdk-solana';
38-
import { deserializePostMessage } from './postMessageLayout.js';
3939
import type { Wormhole as WormholeCoreContract } from './types.js';
40-
import type { BridgeData } from './utils/index.js';
41-
import {
42-
createBridgeFeeTransferInstruction,
43-
createPostMessageInstruction,
44-
createPostVaaInstruction,
45-
createReadOnlyWormholeProgramInterface,
46-
createVerifySignaturesInstructions,
47-
derivePostedVaaKey,
48-
getGuardianSet,
49-
getWormholeBridgeData,
50-
} from './utils/index.js';
5140

5241
const SOLANA_SEQ_LOG = 'Program log: Sequence: ';
5342

5443
export class SolanaWormholeCore<N extends Network, C extends SolanaChains>
5544
implements WormholeCore<N, C>
5645
{
57-
readonly chainId: ChainId;
5846
readonly coreBridge: Program<WormholeCoreContract>;
59-
readonly address: string;
60-
protected bridgeData?: BridgeData;
47+
get address() {
48+
return this.coreBridge.programId;
49+
}
6150

6251
constructor(
6352
readonly network: N,
6453
readonly chain: C,
6554
readonly connection: Connection,
6655
readonly contracts: Contracts,
6756
) {
68-
this.chainId = toChainId(chain);
69-
70-
const coreBridgeAddress = contracts.coreBridge;
71-
if (!coreBridgeAddress)
57+
if (contracts.coreBridge === undefined) {
7258
throw new Error(
7359
`CoreBridge contract Address for chain ${chain} not found`,
7460
);
61+
}
7562

76-
this.address = coreBridgeAddress;
77-
78-
this.coreBridge = createReadOnlyWormholeProgramInterface(
79-
coreBridgeAddress,
80-
connection,
63+
this.coreBridge = new Program(
64+
{ ...IDL, address: contracts.coreBridge },
65+
{ connection },
8166
);
8267
}
8368

@@ -123,7 +108,9 @@ export class SolanaWormholeCore<N extends Network, C extends SolanaChains>
123108
}
124109

125110
async getMessageFee(): Promise<bigint> {
111+
//return this.coreBridge.account.bridgeData.;
126112
await this.ensureBridgeConfig();
113+
127114
return this.bridgeData!.config.fee;
128115
}
129116

@@ -356,7 +343,7 @@ export class SolanaWormholeCore<N extends Network, C extends SolanaChains>
356343
sequence,
357344
nonce,
358345
payload,
359-
} = deserializePostMessage(new Uint8Array(acctInfo?.data!));
346+
} = deserializeLayout(accountDataLayout, acctInfo?.data);
360347

361348
return createVAA('Uint8Array', {
362349
guardianSet: await this.getGuardianSetIndex(),

platforms/solana/protocols/core/src/index.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ registerProtocol(_platform, 'WormholeCore', SolanaWormholeCore);
66

77
export * from './core.js';
88
export * from './types.js';
9-
export * as utils from './utils/index.js';
10-
export * from './postMessageLayout.js';
9+
export * from './accountLayout.js';

platforms/solana/protocols/core/src/postMessageLayout.ts

-27
This file was deleted.

0 commit comments

Comments
 (0)