-
Notifications
You must be signed in to change notification settings - Fork 17
/
update_ltu.ts
65 lines (59 loc) · 2.04 KB
/
update_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
61
62
63
64
65
import { AnchorProvider, Wallet } from "@coral-xyz/anchor";
import {
PublicKey,
Connection,
AddressLookupTableProgram,
TransactionMessage,
VersionedTransaction,
} from "@solana/web3.js";
import { authority } from "./utils";
import { RPC } from "./utils";
import { OpenBookV2Client } from "@openbook-dex/openbook-v2";
const LOOKUP_TABLE_ADDRESS = new PublicKey("89PiVrPT2LRdQncErZxPSAKfB6WXqZdX9Hx8UBTzbfN8");
const addressesToAdd = [new PublicKey("")];
async function main() {
const wallet = new Wallet(authority);
const provider = new AnchorProvider(new Connection(RPC), wallet, {
commitment: "confirmed",
});
const client = new OpenBookV2Client(provider);
const addAddressesInstruction = AddressLookupTableProgram.extendLookupTable({
payer: wallet.publicKey,
authority: wallet.publicKey,
lookupTable: LOOKUP_TABLE_ADDRESS,
addresses: addressesToAdd,
});
let latestBlockhash = await client.connection.getLatestBlockhash("finalized");
console.log(
" ✅ - Fetched latest blockhash. Last valid height:",
latestBlockhash.lastValidBlockHeight
);
const messageV0 = new TransactionMessage({
payerKey: wallet.publicKey,
recentBlockhash: latestBlockhash.blockhash,
instructions: [addAddressesInstruction],
}).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`
);
console.log(
`Lookup Table Entries: `,
`https://explorer.solana.com/address/${LOOKUP_TABLE_ADDRESS.toString()}/entries?cluster=devnet`
);
}
main();