|
1 | 1 | import { BorshEventCoder, Idl, utils } from "@coral-xyz/anchor"; |
2 | | -import web3, { |
3 | | - Address, |
4 | | - AddressesByLookupTableAddress, |
5 | | - appendTransactionMessageInstruction, |
6 | | - appendTransactionMessageInstructions, |
7 | | - Commitment, |
8 | | - compressTransactionMessageUsingAddressLookupTables as compressTxWithAlt, |
9 | | - getSignatureFromTransaction, |
10 | | - GetSignaturesForAddressApi, |
11 | | - GetTransactionApi, |
12 | | - IInstruction, |
13 | | - KeyPairSigner, |
14 | | - pipe, |
15 | | - Rpc, |
16 | | - RpcSubscriptions, |
17 | | - RpcTransport, |
18 | | - sendAndConfirmTransactionFactory, |
19 | | - Signature, |
20 | | - SignatureNotificationsApi, |
21 | | - signTransactionMessageWithSigners, |
22 | | - SlotNotificationsApi, |
23 | | - SolanaRpcApiFromTransport, |
24 | | -} from "@solana/kit"; |
25 | | - |
26 | | -import { |
27 | | - fetchAddressLookupTable, |
28 | | - findAddressLookupTablePda, |
29 | | - getCreateLookupTableInstructionAsync, |
30 | | - getExtendLookupTableInstruction, |
31 | | -} from "@solana-program/address-lookup-table"; |
32 | | -import { createDefaultTransaction, signAndSendTransaction } from "../../../test/svm/utils"; |
| 2 | +import web3, { Address, Commitment, GetSignaturesForAddressApi, GetTransactionApi, Signature } from "@solana/kit"; |
| 3 | +import { RpcClient } from "./types"; |
33 | 4 |
|
34 | 5 | type GetTransactionReturnType = ReturnType<GetTransactionApi["getTransaction"]>; |
35 | 6 |
|
@@ -170,76 +141,3 @@ export async function readFillEventFromFillStatusPda( |
170 | 141 | const events = await readEvents(client, signatures[signatures.length - 1].signature, programId, programIdl); |
171 | 142 | return { event: events[0], slot: Number(signatures[signatures.length - 1].slot) }; |
172 | 143 | } |
173 | | - |
174 | | -export async function createAlt(client: RpcClient, authority: KeyPairSigner): Promise<Address> { |
175 | | - const recentSlot = await client.rpc.getSlot({ commitment: "finalized" }).send(); |
176 | | - |
177 | | - const [alt] = await findAddressLookupTablePda({ |
178 | | - authority: authority.address, |
179 | | - recentSlot, |
180 | | - }); |
181 | | - |
182 | | - const createAltIx = await getCreateLookupTableInstructionAsync({ |
183 | | - authority, |
184 | | - recentSlot, |
185 | | - }); |
186 | | - |
187 | | - await pipe( |
188 | | - await createDefaultTransaction(client, authority), |
189 | | - (tx) => appendTransactionMessageInstruction(createAltIx, tx), |
190 | | - (tx) => signAndSendTransaction(client, tx) |
191 | | - ); |
192 | | - |
193 | | - return alt; |
194 | | -} |
195 | | - |
196 | | -export async function extendAlt(client: RpcClient, authority: KeyPairSigner, alt: Address, addresses: Address[]) { |
197 | | - const extendAltIx = getExtendLookupTableInstruction({ |
198 | | - address: alt, |
199 | | - authority, |
200 | | - payer: authority, |
201 | | - addresses, |
202 | | - }); |
203 | | - |
204 | | - await pipe( |
205 | | - await createDefaultTransaction(client, authority), |
206 | | - (tx) => appendTransactionMessageInstruction(extendAltIx, tx), |
207 | | - (tx) => signAndSendTransaction(client, tx) |
208 | | - ); |
209 | | - |
210 | | - const altAccount = await fetchAddressLookupTable(client.rpc, alt); |
211 | | - |
212 | | - const addressesByLookupTableAddress: AddressesByLookupTableAddress = {}; |
213 | | - addressesByLookupTableAddress[alt] = altAccount.data.addresses; |
214 | | - |
215 | | - // Delay a second here to let lookup table warm up |
216 | | - await sleep(1000); |
217 | | - |
218 | | - return addressesByLookupTableAddress; |
219 | | -} |
220 | | - |
221 | | -async function sleep(ms: number) { |
222 | | - return new Promise((resolve) => setTimeout(resolve, ms)); |
223 | | -} |
224 | | - |
225 | | -export async function sendTransactionWithLookupTable( |
226 | | - client: RpcClient, |
227 | | - payer: KeyPairSigner, |
228 | | - instructions: IInstruction[], |
229 | | - addressesByLookupTableAddress: AddressesByLookupTableAddress |
230 | | -) { |
231 | | - return pipe( |
232 | | - await createDefaultTransaction(client, payer), |
233 | | - (tx) => appendTransactionMessageInstructions(instructions, tx), |
234 | | - (tx) => compressTxWithAlt(tx, addressesByLookupTableAddress), |
235 | | - (tx) => signTransactionMessageWithSigners(tx), |
236 | | - async (tx) => { |
237 | | - const signedTx = await tx; |
238 | | - await sendAndConfirmTransactionFactory(client)(signedTx, { |
239 | | - commitment: "confirmed", |
240 | | - skipPreflight: false, |
241 | | - }); |
242 | | - return getSignatureFromTransaction(signedTx); |
243 | | - } |
244 | | - ); |
245 | | -} |
0 commit comments