Skip to content

Commit

Permalink
check if versioned tx has lookup tables.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpe7s committed Oct 10, 2024
1 parent 866c1a7 commit 251593d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ public static void main(final String[] args) throws InterruptedException {

final int pageLimit = 100;
long beginRequest = System.currentTimeMillis();
var signaturesFuture = rpcClient.getSignaturesForAddress(
meteoraProgramId, pageLimit
);
var signaturesFuture = rpcClient.getSignaturesForAddress(meteoraProgramId, pageLimit);

for (long minMillisBetweenRequests = 5_000; ; ) {
final var signatures = signaturesFuture.join();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,26 @@ public static void main(final String[] args) {

final Instruction[] instructions;
if (skeleton.isLegacy()) {
instructions = skeleton.parseInstructions(skeleton.parseAccounts());
instructions = skeleton.parseLegacyInstructions();
} else {
// Fetch Lookup tables to allow parsing of versioned transactions.
final int txVersion = skeleton.version();
if (txVersion == 0) {
final var tableAccountInfos = rpcClient.getMultipleAccounts(
Arrays.asList(skeleton.lookupTableAccounts()),
AddressLookupTable.FACTORY
).join();

final var lookupTables = tableAccountInfos.stream()
.map(AccountInfo::data)
.collect(Collectors.toUnmodifiableMap(AddressLookupTable::address, Function.identity()));

instructions = skeleton.parseInstructions(skeleton.parseAccounts(lookupTables));
final var tableAccounts = skeleton.lookupTableAccounts();
if (tableAccounts.length == 0) {
instructions = skeleton.parseInstructionsWithoutTableAccounts();
} else {
final var tableAccountInfos = rpcClient.getMultipleAccounts(
Arrays.asList(tableAccounts),
AddressLookupTable.FACTORY
).join();

final var lookupTables = tableAccountInfos.stream()
.map(AccountInfo::data)
.collect(Collectors.toUnmodifiableMap(AddressLookupTable::address, Function.identity()));

instructions = skeleton.parseInstructions(skeleton.parseAccounts(lookupTables));
}
} else {
throw new IllegalStateException("Unhandled tx version " + txVersion);
}
Expand Down Expand Up @@ -101,6 +106,7 @@ public static void main(final String[] args) {
final var usdcTokenMint = driftClient.spotMarket(DriftAsset.USDC).mint();
final var usdcTokenContext = verifiedTokens.get(usdcTokenMint);

// Limit Long 0.1 @ 111 on SOL-PERP [reduceOnly=false] [postOnly=MustPostOnly]
System.out.format("""
%s %s %s @ %s on %s [reduceOnly=%b] [postOnly=%s]
""",
Expand Down

0 comments on commit 251593d

Please sign in to comment.