@@ -13,7 +13,7 @@ import {
1313
1414// Pinocchio program ID (from deployed keypair)
1515const PINOCCHIO_PROGRAM_ID = new PublicKey (
16- "6yfXVhNgRKRk7YHFT8nTkVpFn5zXktbJddPUWK7jFAGX"
16+ "6yfXVhNgRKRk7YHFT8nTkVpFn5zXktbJddPUWK7jFAGX" ,
1717) ;
1818
1919// Seeds for PDAs
@@ -47,7 +47,8 @@ describe("executor-quoter comparison", () => {
4747 } ) ;
4848
4949 // Load wallet from default location
50- const walletPath = process . env . ANCHOR_WALLET || "/Users/smurf/.config/solana/id.json" ;
50+ const walletPath =
51+ process . env . ANCHOR_WALLET || "/Users/smurf/.config/solana/id.json" ;
5152 const secretKey = JSON . parse ( require ( "fs" ) . readFileSync ( walletPath , "utf8" ) ) ;
5253 const payer = Keypair . fromSecretKey ( new Uint8Array ( secretKey ) ) ;
5354 const wallet = new anchor . Wallet ( payer ) ;
@@ -60,7 +61,7 @@ describe("executor-quoter comparison", () => {
6061
6162 const anchorProgram = new Program < ExecutorQuoterAnchor > (
6263 require ( "../target/idl/executor_quoter_anchor.json" ) ,
63- provider
64+ provider ,
6465 ) ;
6566 const updater = Keypair . generate ( ) ;
6667
@@ -80,9 +81,7 @@ describe("executor-quoter comparison", () => {
8081 const gasResults : GasResult [ ] = [ ] ;
8182
8283 // Helper to get compute units from transaction
83- async function getComputeUnits (
84- signature : string
85- ) : Promise < number > {
84+ async function getComputeUnits ( signature : string ) : Promise < number > {
8685 // Wait a bit for the tx to finalize
8786 await new Promise ( ( resolve ) => setTimeout ( resolve , 500 ) ) ;
8887 const tx = await connection . getTransaction ( signature , {
@@ -101,7 +100,7 @@ describe("executor-quoter comparison", () => {
101100 updaterAddress : PublicKey ,
102101 srcTokenDecimals : number ,
103102 payeeAddress : Uint8Array ,
104- bump : number
103+ bump : number ,
105104 ) : Buffer {
106105 const data = Buffer . alloc ( 1 + 32 + 32 + 1 + 1 + 30 + 32 ) ; // discriminator + quoter + updater + decimals + bump + padding + payee
107106 let offset = 0 ;
@@ -126,7 +125,7 @@ describe("executor-quoter comparison", () => {
126125 enabled : number ,
127126 gasPriceDecimals : number ,
128127 nativeDecimals : number ,
129- bump : number
128+ bump : number ,
130129 ) : Buffer {
131130 // UpdateChainInfoData struct is 8 bytes (u16 + u8 + u8 + u8 + u8 + 2 bytes padding)
132131 const data = Buffer . alloc ( 1 + 8 ) ; // discriminator + struct
@@ -153,7 +152,7 @@ describe("executor-quoter comparison", () => {
153152 srcPrice : bigint ,
154153 dstGasPrice : bigint ,
155154 baseFee : bigint ,
156- bump : number
155+ bump : number ,
157156 ) : Buffer {
158157 // UpdateQuoteData struct is 40 bytes (u16 + u8 bump + 5 bytes padding + 4 u64s)
159158 const data = Buffer . alloc ( 1 + 40 ) ; // discriminator + struct
@@ -181,10 +180,10 @@ describe("executor-quoter comparison", () => {
181180 dstAddr : Uint8Array ,
182181 refundAddr : Uint8Array ,
183182 requestBytes : Uint8Array ,
184- relayInstructions : Uint8Array
183+ relayInstructions : Uint8Array ,
185184 ) : Buffer {
186185 const data = Buffer . alloc (
187- 1 + 2 + 32 + 32 + 4 + requestBytes . length + 4 + relayInstructions . length
186+ 1 + 2 + 32 + 32 + 4 + requestBytes . length + 4 + relayInstructions . length ,
188187 ) ;
189188 let offset = 0 ;
190189 data . writeUInt8 ( 3 , offset ) ; // RequestQuote discriminator
@@ -228,46 +227,47 @@ describe("executor-quoter comparison", () => {
228227 // Airdrop to payer
229228 const payerAirdropSig = await connection . requestAirdrop (
230229 payer . publicKey ,
231- 100 * anchor . web3 . LAMPORTS_PER_SOL
230+ 100 * anchor . web3 . LAMPORTS_PER_SOL ,
232231 ) ;
233232 await connection . confirmTransaction ( payerAirdropSig , "confirmed" ) ;
234- console . log ( `Payer balance: ${ await connection . getBalance ( payer . publicKey ) } ` ) ;
233+ console . log (
234+ `Payer balance: ${ await connection . getBalance ( payer . publicKey ) } ` ,
235+ ) ;
235236
236237 // Airdrop to updater
237238 const sig = await connection . requestAirdrop (
238239 updater . publicKey ,
239- 10 * anchor . web3 . LAMPORTS_PER_SOL
240+ 10 * anchor . web3 . LAMPORTS_PER_SOL ,
240241 ) ;
241242 await connection . confirmTransaction ( sig , "confirmed" ) ;
242243
243244 // Derive Anchor PDAs
244245 [ anchorConfigPda ] = PublicKey . findProgramAddressSync (
245246 [ CONFIG_SEED ] ,
246- anchorProgram . programId
247+ anchorProgram . programId ,
247248 ) ;
248249 const chainIdBytes = Buffer . alloc ( 2 ) ;
249250 chainIdBytes . writeUInt16LE ( TEST_CHAIN_ID ) ;
250251 [ anchorChainInfoPda ] = PublicKey . findProgramAddressSync (
251252 [ CHAIN_INFO_SEED , chainIdBytes ] ,
252- anchorProgram . programId
253+ anchorProgram . programId ,
253254 ) ;
254255 [ anchorQuotePda ] = PublicKey . findProgramAddressSync (
255256 [ QUOTE_SEED , chainIdBytes ] ,
256- anchorProgram . programId
257+ anchorProgram . programId ,
257258 ) ;
258259
259260 // Derive Pinocchio PDAs
260- [ pinocchioConfigPda , pinocchioConfigBump ] = PublicKey . findProgramAddressSync (
261- [ CONFIG_SEED ] ,
262- PINOCCHIO_PROGRAM_ID
263- ) ;
264- [ pinocchioChainInfoPda , pinocchioChainInfoBump ] = PublicKey . findProgramAddressSync (
265- [ CHAIN_INFO_SEED , chainIdBytes ] ,
266- PINOCCHIO_PROGRAM_ID
267- ) ;
261+ [ pinocchioConfigPda , pinocchioConfigBump ] =
262+ PublicKey . findProgramAddressSync ( [ CONFIG_SEED ] , PINOCCHIO_PROGRAM_ID ) ;
263+ [ pinocchioChainInfoPda , pinocchioChainInfoBump ] =
264+ PublicKey . findProgramAddressSync (
265+ [ CHAIN_INFO_SEED , chainIdBytes ] ,
266+ PINOCCHIO_PROGRAM_ID ,
267+ ) ;
268268 [ pinocchioQuotePda , pinocchioQuoteBump ] = PublicKey . findProgramAddressSync (
269269 [ QUOTE_SEED , chainIdBytes ] ,
270- PINOCCHIO_PROGRAM_ID
270+ PINOCCHIO_PROGRAM_ID ,
271271 ) ;
272272 } ) ;
273273
@@ -361,7 +361,10 @@ describe("executor-quoter comparison", () => {
361361 const dstAddr = new Uint8Array ( 32 ) ;
362362 const refundAddr = new Uint8Array ( 32 ) ;
363363 payer . publicKey . toBuffer ( ) . copy ( refundAddr ) ;
364- const relayInstructions = buildRelayInstructions ( TEST_GAS_LIMIT , BigInt ( 0 ) ) ;
364+ const relayInstructions = buildRelayInstructions (
365+ TEST_GAS_LIMIT ,
366+ BigInt ( 0 ) ,
367+ ) ;
365368
366369 const sig = await anchorProgram . methods
367370 . requestQuote ( {
@@ -392,7 +395,10 @@ describe("executor-quoter comparison", () => {
392395 const dstAddr = new Uint8Array ( 32 ) ;
393396 const refundAddr = new Uint8Array ( 32 ) ;
394397 payer . publicKey . toBuffer ( ) . copy ( refundAddr ) ;
395- const relayInstructions = buildRelayInstructions ( TEST_GAS_LIMIT , BigInt ( 0 ) ) ;
398+ const relayInstructions = buildRelayInstructions (
399+ TEST_GAS_LIMIT ,
400+ BigInt ( 0 ) ,
401+ ) ;
396402
397403 const sig = await anchorProgram . methods
398404 . requestExecutionQuote ( {
@@ -430,23 +436,32 @@ describe("executor-quoter comparison", () => {
430436 updater . publicKey ,
431437 9 ,
432438 payeeAddress ,
433- pinocchioConfigBump
439+ pinocchioConfigBump ,
434440 ) ;
435441
436442 const ix = new TransactionInstruction ( {
437443 programId : PINOCCHIO_PROGRAM_ID ,
438444 keys : [
439445 { pubkey : payer . publicKey , isSigner : true , isWritable : true } ,
440446 { pubkey : pinocchioConfigPda , isSigner : false , isWritable : true } ,
441- { pubkey : SystemProgram . programId , isSigner : false , isWritable : false } ,
447+ {
448+ pubkey : SystemProgram . programId ,
449+ isSigner : false ,
450+ isWritable : false ,
451+ } ,
442452 ] ,
443453 data,
444454 } ) ;
445455
446456 const tx = new Transaction ( ) . add ( ix ) ;
447- const sig = await sendAndConfirmTransaction ( provider . connection , tx , [ payer ] , {
448- commitment : "confirmed" ,
449- } ) ;
457+ const sig = await sendAndConfirmTransaction (
458+ provider . connection ,
459+ tx ,
460+ [ payer ] ,
461+ {
462+ commitment : "confirmed" ,
463+ } ,
464+ ) ;
450465
451466 const computeUnits = await getComputeUnits ( sig ) ;
452467 gasResults . push ( {
@@ -464,7 +479,7 @@ describe("executor-quoter comparison", () => {
464479 1 , // enabled
465480 GAS_PRICE_DECIMALS ,
466481 NATIVE_DECIMALS ,
467- pinocchioChainInfoBump
482+ pinocchioChainInfoBump ,
468483 ) ;
469484
470485 const ix = new TransactionInstruction ( {
@@ -474,7 +489,11 @@ describe("executor-quoter comparison", () => {
474489 { pubkey : updater . publicKey , isSigner : true , isWritable : false } ,
475490 { pubkey : pinocchioConfigPda , isSigner : false , isWritable : false } ,
476491 { pubkey : pinocchioChainInfoPda , isSigner : false , isWritable : true } ,
477- { pubkey : SystemProgram . programId , isSigner : false , isWritable : false } ,
492+ {
493+ pubkey : SystemProgram . programId ,
494+ isSigner : false ,
495+ isWritable : false ,
496+ } ,
478497 ] ,
479498 data,
480499 } ) ;
@@ -484,7 +503,7 @@ describe("executor-quoter comparison", () => {
484503 provider . connection ,
485504 tx ,
486505 [ payer , updater ] ,
487- { commitment : "confirmed" }
506+ { commitment : "confirmed" } ,
488507 ) ;
489508
490509 const computeUnits = await getComputeUnits ( sig ) ;
@@ -504,7 +523,7 @@ describe("executor-quoter comparison", () => {
504523 TEST_SRC_PRICE ,
505524 TEST_DST_GAS_PRICE ,
506525 TEST_BASE_FEE ,
507- pinocchioQuoteBump
526+ pinocchioQuoteBump ,
508527 ) ;
509528
510529 const ix = new TransactionInstruction ( {
@@ -514,7 +533,11 @@ describe("executor-quoter comparison", () => {
514533 { pubkey : updater . publicKey , isSigner : true , isWritable : false } ,
515534 { pubkey : pinocchioConfigPda , isSigner : false , isWritable : false } ,
516535 { pubkey : pinocchioQuotePda , isSigner : false , isWritable : true } ,
517- { pubkey : SystemProgram . programId , isSigner : false , isWritable : false } ,
536+ {
537+ pubkey : SystemProgram . programId ,
538+ isSigner : false ,
539+ isWritable : false ,
540+ } ,
518541 ] ,
519542 data,
520543 } ) ;
@@ -524,7 +547,7 @@ describe("executor-quoter comparison", () => {
524547 provider . connection ,
525548 tx ,
526549 [ payer , updater ] ,
527- { commitment : "confirmed" }
550+ { commitment : "confirmed" } ,
528551 ) ;
529552
530553 const computeUnits = await getComputeUnits ( sig ) ;
@@ -541,14 +564,17 @@ describe("executor-quoter comparison", () => {
541564 const dstAddr = new Uint8Array ( 32 ) ;
542565 const refundAddr = new Uint8Array ( 32 ) ;
543566 payer . publicKey . toBuffer ( ) . copy ( refundAddr ) ;
544- const relayInstructions = buildRelayInstructions ( TEST_GAS_LIMIT , BigInt ( 0 ) ) ;
567+ const relayInstructions = buildRelayInstructions (
568+ TEST_GAS_LIMIT ,
569+ BigInt ( 0 ) ,
570+ ) ;
545571
546572 const data = buildPinocchioRequestQuoteData (
547573 TEST_CHAIN_ID ,
548574 dstAddr ,
549575 refundAddr ,
550576 new Uint8Array ( 0 ) ,
551- relayInstructions
577+ relayInstructions ,
552578 ) ;
553579
554580 const ix = new TransactionInstruction ( {
@@ -562,9 +588,14 @@ describe("executor-quoter comparison", () => {
562588 } ) ;
563589
564590 const tx = new Transaction ( ) . add ( ix ) ;
565- const sig = await sendAndConfirmTransaction ( provider . connection , tx , [ payer ] , {
566- commitment : "confirmed" ,
567- } ) ;
591+ const sig = await sendAndConfirmTransaction (
592+ provider . connection ,
593+ tx ,
594+ [ payer ] ,
595+ {
596+ commitment : "confirmed" ,
597+ } ,
598+ ) ;
568599
569600 const computeUnits = await getComputeUnits ( sig ) ;
570601 gasResults . push ( {
@@ -580,15 +611,18 @@ describe("executor-quoter comparison", () => {
580611 const dstAddr = new Uint8Array ( 32 ) ;
581612 const refundAddr = new Uint8Array ( 32 ) ;
582613 payer . publicKey . toBuffer ( ) . copy ( refundAddr ) ;
583- const relayInstructions = buildRelayInstructions ( TEST_GAS_LIMIT , BigInt ( 0 ) ) ;
614+ const relayInstructions = buildRelayInstructions (
615+ TEST_GAS_LIMIT ,
616+ BigInt ( 0 ) ,
617+ ) ;
584618
585619 // RequestExecutionQuote is discriminator 4
586620 const data = buildPinocchioRequestQuoteData (
587621 TEST_CHAIN_ID ,
588622 dstAddr ,
589623 refundAddr ,
590624 new Uint8Array ( 0 ) ,
591- relayInstructions
625+ relayInstructions ,
592626 ) ;
593627 data . writeUInt8 ( 4 , 0 ) ; // Change discriminator to RequestExecutionQuote
594628
@@ -603,9 +637,14 @@ describe("executor-quoter comparison", () => {
603637 } ) ;
604638
605639 const tx = new Transaction ( ) . add ( ix ) ;
606- const sig = await sendAndConfirmTransaction ( provider . connection , tx , [ payer ] , {
607- commitment : "confirmed" ,
608- } ) ;
640+ const sig = await sendAndConfirmTransaction (
641+ provider . connection ,
642+ tx ,
643+ [ payer ] ,
644+ {
645+ commitment : "confirmed" ,
646+ } ,
647+ ) ;
609648
610649 const computeUnits = await getComputeUnits ( sig ) ;
611650 gasResults . push ( {
@@ -621,8 +660,12 @@ describe("executor-quoter comparison", () => {
621660 describe ( "Gas Comparison Summary" , ( ) => {
622661 it ( "prints comparison table" , ( ) => {
623662 console . log ( "\n=== Gas Comparison (Compute Units) ===\n" ) ;
624- console . log ( "| Instruction | Anchor CU | Pinocchio CU | Difference | Savings % |" ) ;
625- console . log ( "|------------------------|-----------|--------------|------------|-----------|" ) ;
663+ console . log (
664+ "| Instruction | Anchor CU | Pinocchio CU | Difference | Savings % |" ,
665+ ) ;
666+ console . log (
667+ "|------------------------|-----------|--------------|------------|-----------|" ,
668+ ) ;
626669
627670 const instructions = [
628671 "initialize" ,
@@ -634,17 +677,17 @@ describe("executor-quoter comparison", () => {
634677
635678 for ( const instruction of instructions ) {
636679 const anchor = gasResults . find (
637- ( r ) => r . program === "Anchor" && r . instruction === instruction
680+ ( r ) => r . program === "Anchor" && r . instruction === instruction ,
638681 ) ;
639682 const pinocchio = gasResults . find (
640- ( r ) => r . program === "Pinocchio" && r . instruction === instruction
683+ ( r ) => r . program === "Pinocchio" && r . instruction === instruction ,
641684 ) ;
642685
643686 if ( anchor && pinocchio ) {
644687 const diff = anchor . computeUnits - pinocchio . computeUnits ;
645688 const savings = ( ( diff / anchor . computeUnits ) * 100 ) . toFixed ( 1 ) ;
646689 console . log (
647- `| ${ instruction . padEnd ( 22 ) } | ${ anchor . computeUnits . toString ( ) . padStart ( 9 ) } | ${ pinocchio . computeUnits . toString ( ) . padStart ( 12 ) } | ${ diff . toString ( ) . padStart ( 10 ) } | ${ savings . padStart ( 8 ) } % |`
690+ `| ${ instruction . padEnd ( 22 ) } | ${ anchor . computeUnits . toString ( ) . padStart ( 9 ) } | ${ pinocchio . computeUnits . toString ( ) . padStart ( 12 ) } | ${ diff . toString ( ) . padStart ( 10 ) } | ${ savings . padStart ( 8 ) } % |` ,
648691 ) ;
649692 }
650693 }
@@ -655,7 +698,9 @@ describe("executor-quoter comparison", () => {
655698 console . log ( "| Anchor | 277600 |" ) ;
656699 console . log ( "| Pinocchio | 56176 |" ) ;
657700 console . log ( `| Difference | ${ 277600 - 56176 } |` ) ;
658- console . log ( `| Savings | ${ ( ( 1 - 56176 / 277600 ) * 100 ) . toFixed ( 1 ) } % |` ) ;
701+ console . log (
702+ `| Savings | ${ ( ( 1 - 56176 / 277600 ) * 100 ) . toFixed ( 1 ) } % |` ,
703+ ) ;
659704 } ) ;
660705 } ) ;
661706} ) ;
0 commit comments