Skip to content

Commit d7fc284

Browse files
authored
sdk: update deprecated solana web3.js methods (#515)
* sdk: update deprecated solana web3.js methods * use sendAndConfirmTransaction
1 parent 00f83aa commit d7fc284

File tree

2 files changed

+75
-53
lines changed

2 files changed

+75
-53
lines changed

solana/tests/anchor.test.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ import {
2424
import { SolanaWormholeCore } from "@wormhole-foundation/sdk-solana-core";
2525
import * as fs from "fs";
2626

27-
import { PublicKey, SystemProgram, Transaction } from "@solana/web3.js";
27+
import {
28+
PublicKey,
29+
sendAndConfirmTransaction,
30+
SystemProgram,
31+
Transaction,
32+
} from "@solana/web3.js";
2833
import { DummyTransferHook } from "../ts/idl/1_0_0/ts/dummy_transfer_hook.js";
2934
import { SolanaNtt } from "../ts/sdk/index.js";
3035

@@ -154,13 +159,14 @@ describe("example-native-token-transfers", () => {
154159
)
155160
);
156161

157-
const { blockhash } = await connection.getRecentBlockhash();
162+
const { blockhash } = await connection.getLatestBlockhash();
158163

159164
transaction.feePayer = payer.publicKey;
160165
transaction.recentBlockhash = blockhash;
161166

162-
const txid = await connection.sendTransaction(transaction, [payer, mint]);
163-
await connection.confirmTransaction(txid, "confirmed");
167+
await sendAndConfirmTransaction(connection, transaction, [payer, mint], {
168+
commitment: "confirmed",
169+
});
164170

165171
tokenAccount = await spl.createAssociatedTokenAccount(
166172
connection,
@@ -266,12 +272,13 @@ describe("example-native-token-transfers", () => {
266272
initializeExtraAccountMetaListInstruction
267273
);
268274
transaction.feePayer = payer.publicKey;
269-
const { blockhash } = await connection.getRecentBlockhash();
275+
const { blockhash } = await connection.getLatestBlockhash();
270276
transaction.recentBlockhash = blockhash;
271277

272278
transaction.sign(payer);
273-
const txid = await connection.sendTransaction(transaction, [payer]);
274-
await connection.confirmTransaction(txid, "confirmed");
279+
await sendAndConfirmTransaction(connection, transaction, [payer], {
280+
commitment: "confirmed",
281+
});
275282
});
276283

277284
test("Can send tokens", async () => {

solana/ts/sdk/ntt.ts

Lines changed: 61 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
WormholeNttTransceiver,
3030
} from "@wormhole-foundation/sdk-definitions-ntt";
3131
import {
32-
AnySolanaAddress,
32+
AnySolanaAddress,
3333
SolanaAddress,
3434
SolanaChains,
3535
SolanaPlatform,
@@ -46,16 +46,15 @@ import { NTT, NttQuoter, WEI_PER_GWEI } from "../lib/index.js";
4646

4747
import { IdlVersion, NttBindings, getNttProgram } from "../lib/bindings.js";
4848

49-
export class SolanaNttWormholeTransceiver<N extends Network, C extends SolanaChains>
50-
implements NttTransceiver<N, C, WormholeNttTransceiver.VAA> {
51-
52-
constructor(
53-
readonly manager: SolanaNtt<N, C>,
54-
readonly address: PublicKey
55-
) {}
49+
export class SolanaNttWormholeTransceiver<
50+
N extends Network,
51+
C extends SolanaChains
52+
> implements NttTransceiver<N, C, WormholeNttTransceiver.VAA>
53+
{
54+
constructor(readonly manager: SolanaNtt<N, C>, readonly address: PublicKey) {}
5655

5756
async getPauser(): Promise<AccountAddress<C> | null> {
58-
return null
57+
return null;
5958
}
6059

6160
async *setPauser(_newPauser: AccountAddress<C>, _payer: AccountAddress<C>) {
@@ -71,7 +70,10 @@ export class SolanaNttWormholeTransceiver<N extends Network, C extends SolanaCha
7170
}
7271

7372
getAddress(): ChainAddress<C> {
74-
return { chain: this.manager.chain, address: toUniversal(this.manager.chain, this.address.toBase58()) };
73+
return {
74+
chain: this.manager.chain,
75+
address: toUniversal(this.manager.chain, this.address.toBase58()),
76+
};
7577
}
7678

7779
async *setPeer(peer: ChainAddress<C>, payer: AccountAddress<C>) {
@@ -94,7 +96,8 @@ export class SolanaNttWormholeTransceiver<N extends Network, C extends SolanaCha
9496
}
9597

9698
export class SolanaNtt<N extends Network, C extends SolanaChains>
97-
implements Ntt<N, C> {
99+
implements Ntt<N, C>
100+
{
98101
core: SolanaWormholeCore<N, C>;
99102
pdas: NTT.Pdas;
100103

@@ -149,7 +152,10 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
149152
if (ix !== 0) return null;
150153
if (this.whTransceiverAddress === undefined) return null;
151154

152-
return new SolanaNttWormholeTransceiver(this, new PublicKey(this.whTransceiverAddress));
155+
return new SolanaNttWormholeTransceiver(
156+
this,
157+
new PublicKey(this.whTransceiverAddress)
158+
);
153159
}
154160

155161
async getMode(): Promise<Ntt.Mode> {
@@ -190,7 +196,7 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
190196

191197
async getThreshold(): Promise<number> {
192198
const config = await this.getConfig();
193-
return config.threshold
199+
return config.threshold;
194200
}
195201

196202
async getOwner(): Promise<AccountAddress<C>> {
@@ -199,7 +205,7 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
199205
}
200206

201207
async getPauser(): Promise<AccountAddress<C> | null> {
202-
return null
208+
return null;
203209
}
204210

205211
async *setOwner(newOwner: AnySolanaAddress, payer: AccountAddress<C>) {
@@ -280,12 +286,17 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
280286
}
281287

282288
async getPeer<C extends Chain>(chain: C): Promise<Ntt.Peer<C> | null> {
283-
const peer = await this.program.account.nttManagerPeer.fetchNullable(this.pdas.peerAccount(chain));
289+
const peer = await this.program.account.nttManagerPeer.fetchNullable(
290+
this.pdas.peerAccount(chain)
291+
);
284292

285293
if (!peer) return null;
286294

287295
return {
288-
address: { chain: chain, address: toUniversal(chain, new Uint8Array(peer.address)) },
296+
address: {
297+
chain: chain,
298+
address: toUniversal(chain, new Uint8Array(peer.address)),
299+
},
289300
tokenDecimals: peer.tokenDecimals,
290301
inboundLimit: await this.getInboundLimit(chain),
291302
};
@@ -308,7 +319,7 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
308319
);
309320
} catch (e) {
310321
// This might happen if e.g. the program is not deployed yet.
311-
const version = "2.0.0"
322+
const version = "2.0.0";
312323
return version;
313324
}
314325
}
@@ -504,17 +515,17 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
504515
const transferIx =
505516
config.mode.locking != null
506517
? NTT.createTransferLockInstruction(
507-
this.program,
508-
config,
509-
txArgs,
510-
this.pdas
511-
)
518+
this.program,
519+
config,
520+
txArgs,
521+
this.pdas
522+
)
512523
: NTT.createTransferBurnInstruction(
513-
this.program,
514-
config,
515-
txArgs,
516-
this.pdas
517-
);
524+
this.program,
525+
config,
526+
txArgs,
527+
this.pdas
528+
);
518529

519530
const releaseIx = NTT.createReleaseOutboundInstruction(
520531
this.program,
@@ -555,10 +566,12 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
555566
luts.push(await this.getAddressLookupTable());
556567
} catch {}
557568

569+
const { blockhash } = await this.connection.getLatestBlockhash();
570+
558571
const messageV0 = new TransactionMessage({
559572
payerKey: payerAddress,
560573
instructions: tx.instructions,
561-
recentBlockhash: (await this.connection.getRecentBlockhash()).blockhash,
574+
recentBlockhash: blockhash,
562575
}).compileToV0Message(luts);
563576

564577
const vtx = new VersionedTransaction(messageV0);
@@ -654,15 +667,15 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
654667
const releaseIx =
655668
config.mode.locking != null
656669
? NTT.createReleaseInboundUnlockInstruction(
657-
this.program,
658-
config,
659-
releaseArgs
660-
)
670+
this.program,
671+
config,
672+
releaseArgs
673+
)
661674
: NTT.createReleaseInboundMintInstruction(
662-
this.program,
663-
config,
664-
releaseArgs
665-
);
675+
this.program,
676+
config,
677+
releaseArgs
678+
);
666679

667680
const tx = new Transaction();
668681
tx.feePayer = senderAddress;
@@ -673,10 +686,12 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
673686
luts.push(await this.getAddressLookupTable());
674687
} catch {}
675688

689+
const { blockhash } = await this.connection.getLatestBlockhash();
690+
676691
const messageV0 = new TransactionMessage({
677692
payerKey: senderAddress,
678693
instructions: tx.instructions,
679-
recentBlockhash: (await this.connection.getRecentBlockhash()).blockhash,
694+
recentBlockhash: blockhash,
680695
}).compileToV0Message(luts);
681696

682697
const vtx = new VersionedTransaction(messageV0);
@@ -820,15 +835,15 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
820835
tx.add(
821836
await (config.mode.locking != null
822837
? NTT.createReleaseInboundUnlockInstruction(
823-
this.program,
824-
config,
825-
releaseArgs
826-
)
838+
this.program,
839+
config,
840+
releaseArgs
841+
)
827842
: NTT.createReleaseInboundMintInstruction(
828-
this.program,
829-
config,
830-
releaseArgs
831-
))
843+
this.program,
844+
config,
845+
releaseArgs
846+
))
832847
);
833848

834849
yield this.createUnsignedTx(
@@ -890,7 +905,7 @@ export class SolanaNtt<N extends Network, C extends SolanaChains>
890905
delete a[k];
891906
}
892907
}
893-
}
908+
};
894909

895910
deleteMatching(remote, local);
896911

0 commit comments

Comments
 (0)