From ee498ebf8861a036977eb296617ecd6c9cf44845 Mon Sep 17 00:00:00 2001 From: solpkr <96340731+solpkr@users.noreply.github.com> Date: Mon, 27 Feb 2023 11:38:55 +0000 Subject: [PATCH] reduce transaction size by using duplicate pks for coinFee and pcFee (#17) Co-authored-by: solpkr --- src/scripts/crank.ts | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/src/scripts/crank.ts b/src/scripts/crank.ts index b9b4084..75d2f49 100644 --- a/src/scripts/crank.ts +++ b/src/scripts/crank.ts @@ -1,6 +1,3 @@ -/** - This will probably move to its own repo at some point but easier to keep it here for now - */ import * as os from 'os'; import * as fs from 'fs'; import { @@ -13,12 +10,11 @@ import { BlockhashWithExpiryBlockHeight, TransactionInstruction, } from '@solana/web3.js'; -import {getMultipleAccounts,loadMultipleOpenbookMarkets,getMultipleAssociatedTokenAddresses, sleep, chunk} from '../utils/utils'; +import {getMultipleAccounts, loadMultipleOpenbookMarkets, sleep, chunk} from '../utils/utils'; import BN from 'bn.js'; import {decodeEventQueue, DexInstructions} from '@project-serum/serum'; -import { Token, TOKEN_PROGRAM_ID } from '@solana/spl-token'; -import { Logger } from 'tslog'; -import axios from "axios" +import {Logger} from 'tslog'; +import axios from "axios"; const URL_MARKETS_BY_VOLUME = 'https://openserum.io/api/serum/markets.json?min24hVolume='; const VOLUME_THRESHOLD = 1000; @@ -128,22 +124,6 @@ async function run() { log.info("Cranking the following markets"); marketsList.forEach(m => log.info(`${m.name}: ${m.address}`)); - const quoteToken = new Token( - connection, - spotMarkets[0].quoteMintAddress, - TOKEN_PROGRAM_ID, - payer, - ); - const quoteWallet = await quoteToken - .getOrCreateAssociatedAccountInfo(payer.publicKey) - .then((a) => a.address); - - //get the token accounts for each basemint & the associated account address for our token account - const tokenAccounts = spotMarkets.map( - (market) => market['_decoded'].baseMint - ); - const baseWallets = await getMultipleAssociatedTokenAddresses(connection,payer,tokenAccounts); - const eventQueuePks = spotMarkets.map( (market) => market['_decoded'].eventQueue, ); @@ -189,11 +169,13 @@ async function run() { .map((s) => new PublicKey(s)) .sort((a, b) => a.toBuffer().swap64().compare(b.toBuffer().swap64())); + //coinFee & pcFee are redundant for cranking. Instead, we pass spotMarkets[i]['_decoded'].eventQueue + //using duplicate accounts will reduce transaction size const instr = DexInstructions.consumeEvents({ market: spotMarkets[i].publicKey, eventQueue: spotMarkets[i]['_decoded'].eventQueue, - coinFee: baseWallets[i], - pcFee: quoteWallet, + coinFee: spotMarkets[i]['_decoded'].eventQueue, + pcFee: spotMarkets[i]['_decoded'].eventQueue, openOrdersAccounts, limit: consumeEventsLimit, programId: serumProgramId, @@ -259,8 +241,6 @@ async function run() { } - - } catch (e) { if (e instanceof Error) {