-
Notifications
You must be signed in to change notification settings - Fork 17
/
create_ltu.ts
60 lines (51 loc) · 1.81 KB
/
create_ltu.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { AnchorProvider, BN, Wallet } from "@coral-xyz/anchor";
import {
Connection,
AddressLookupTableProgram,
TransactionMessage,
VersionedTransaction,
} from "@solana/web3.js";
import { authority } from "./utils";
import { RPC } from "./utils";
import { OpenBookV2Client } from "@openbook-dex/openbook-v2";
async function main() {
const wallet = new Wallet(authority);
const provider = new AnchorProvider(new Connection(RPC), wallet, {
commitment: "confirmed",
});
const client = new OpenBookV2Client(provider);
// Step 1 - Get a lookup table address and create lookup table instruction
const [txInstructions, lookupTableAddress] =
AddressLookupTableProgram.createLookupTable({
authority: wallet.publicKey,
payer: wallet.publicKey,
recentSlot: await client.connection.getSlot(),
});
// Step 2 - Log Lookup Table Address
console.log("Lookup Table Address:", lookupTableAddress.toBase58());
let latestBlockhash = await client.connection.getLatestBlockhash("finalized");
const messageV0 = new TransactionMessage({
payerKey: wallet.publicKey,
recentBlockhash: latestBlockhash.blockhash,
instructions: [txInstructions],
}).compileToV0Message();
const transaction = new VersionedTransaction(messageV0);
transaction.sign([wallet.payer]);
const txid = await client.connection.sendTransaction(transaction, {
maxRetries: 5,
});
const confirmation = await client.connection.confirmTransaction({
signature: txid,
blockhash: latestBlockhash.blockhash,
lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
});
if (confirmation.value.err) {
throw new Error(" ❌ - Transaction not confirmed.");
}
console.log(
"🎉 Transaction succesfully confirmed!",
"\n",
`https://explorer.solana.com/tx/${txid}?cluster=devnet`
);
}
main();