Skip to content

Commit

Permalink
handle missing vaa hash cases in testnet
Browse files Browse the repository at this point in the history
Signed-off-by: bingyuyap <[email protected]>
  • Loading branch information
bingyuyap committed Aug 27, 2024
1 parent 6e060a1 commit 1e19cd3
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
8 changes: 4 additions & 4 deletions watcher/scripts/watchFtSolana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { FTSolanaWatcher } from '../src/watchers/FTSolanaWatcher';
import { FTEVMWatcher } from '../src/watchers/FTEVMWatcher';
import { Network } from '@wormhole-foundation/sdk-base';

const network = process.env.NETWORK === 'mainnet' ? 'Mainnet' : 'Testnet';
async function watchFtSolana(network: Network, fromSlot: number, toSlot: number) {
const watcher = new FTSolanaWatcher(network);
const batchSize = 1000;
Expand All @@ -16,9 +17,8 @@ async function watchFtSolana(network: Network, fromSlot: number, toSlot: number)
}
}

const network: Network = 'Mainnet';
const fromSlot = 285350104;
const toSlot = 285590214;
const fromSlot = 321556219;
const toSlot = 321807831;

async function watchFtArbitrum(network: Network, fromBlock: number, toBlock: number) {
const watcher = new FTEVMWatcher(network, 'Arbitrum');
Expand All @@ -34,5 +34,5 @@ async function watchFtArbitrum(network: Network, fromBlock: number, toBlock: num
const fromBlock = 245882389;
const toBlock = 246294436;

watchFtArbitrum(network, fromBlock, toBlock).then(() => console.log('Done watching ftArbitrum'));
// watchFtArbitrum(network, fromBlock, toBlock).then(() => console.log('Done watching ftArbitrum'));
watchFtSolana(network, fromSlot, toSlot).then(() => console.log('Done watching ftSolana'));
41 changes: 36 additions & 5 deletions watcher/src/watchers/FTSolanaWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export class FTSolanaWatcher extends SolanaWatcher {
readonly USDC_MINT: USDCMintAddress;
readonly TOKEN_ROUTER_PROGRAM_ID: TokenRouterProgramId;
readonly eventParser: EventParser;
readonly isTest: boolean;

constructor(network: Network, isTest: boolean = false) {
super(network, 'ft');
Expand All @@ -91,6 +92,7 @@ export class FTSolanaWatcher extends SolanaWatcher {
new PublicKey(this.MATCHING_ENGINE_PROGRAM_ID),
this.matchingEngineBorshCoder
);
this.isTest = isTest;

// hacky way to not connect to the db in tests
// this is to allow ci to run without a db
Expand Down Expand Up @@ -642,7 +644,7 @@ export class FTSolanaWatcher extends SolanaWatcher {
res: VersionedTransactionResponse,
ix: MessageCompiledInstruction,
seq: number
): Promise<FastTransferSettledInfo> {
): Promise<FastTransferSettledInfo | null> {
if (!res.meta?.innerInstructions) {
throw new Error(
`[parseSettleAuctionComplete] ${res.transaction.signatures[0]} no inner instructions`
Expand Down Expand Up @@ -688,7 +690,11 @@ export class FTSolanaWatcher extends SolanaWatcher {
// if there is a auction to settle, the auction must exist. And the pubkey
// will be in the db since we parse everything chronologically
const fast_vaa_hash = await this.getFastVaaHashFromAuctionPubkey(auctionAccountPubkey.pubkey);

// We want to return the info even without the vaa hash if its a testing environment
if (!fast_vaa_hash && !this.isTest) {
this.handleMissingFastVaaHash(auctionAccountPubkey.pubkey, 'parseSettleAuctionComplete');
return null;
}
const info = {
fast_vaa_hash: fast_vaa_hash,
repayment: BigInt(decodedData.data.amount.toString()),
Expand Down Expand Up @@ -721,7 +727,7 @@ export class FTSolanaWatcher extends SolanaWatcher {
async parseSettleAuctionNoneLocal(
res: VersionedTransactionResponse,
ix: MessageCompiledInstruction
): Promise<FastTransferSettledInfo> {
): Promise<FastTransferSettledInfo | null> {
const accountKeys = await this.getAccountsByParsedTransaction(res.transaction.signatures[0]);
const accountKeyIndexes = ix.accountKeyIndexes;
if (accountKeyIndexes.length < 7) {
Expand All @@ -731,7 +737,11 @@ export class FTSolanaWatcher extends SolanaWatcher {
const auction = accountKeys[accountKeyIndexes[6]];

const fast_vaa_hash = await this.getFastVaaHashFromAuctionPubkey(auction.pubkey);

// We want to return the info even without the vaa hash if its a testing environment
if (!fast_vaa_hash && !this.isTest) {
this.handleMissingFastVaaHash(auction.pubkey, 'parseSettleAuctionNoneLocal');
return null;
}
const info = {
fast_vaa_hash: fast_vaa_hash,
// No one executed anything so no repayment
Expand All @@ -754,7 +764,7 @@ export class FTSolanaWatcher extends SolanaWatcher {
async parseSettleAuctionNoneCctp(
res: VersionedTransactionResponse,
ix: MessageCompiledInstruction
): Promise<FastTransferSettledInfo> {
): Promise<FastTransferSettledInfo | null> {
const accountKeys = await this.getAccountsByParsedTransaction(res.transaction.signatures[0]);
const accountKeyIndexes = ix.accountKeyIndexes;

Expand All @@ -766,6 +776,11 @@ export class FTSolanaWatcher extends SolanaWatcher {
const auction = accountKeys[accountKeyIndexes[8]];

const fast_vaa_hash = await this.getFastVaaHashFromAuctionPubkey(auction.pubkey);
// We want to return the info even without the vaa hash if its a testing environment
if (!fast_vaa_hash && !this.isTest) {
this.handleMissingFastVaaHash(auction.pubkey, 'parseSettleAuctionNoneCctp');
return null;
}

const info = {
fast_vaa_hash: fast_vaa_hash,
Expand All @@ -778,6 +793,10 @@ export class FTSolanaWatcher extends SolanaWatcher {
};

await this.saveFastTransferInfo('fast_transfer_settlements', info);
await this.updateMarketOrder({
fast_vaa_hash,
status: FastTransferStatus.SETTLED,
});

return info;
}
Expand Down Expand Up @@ -1096,4 +1115,16 @@ export class FTSolanaWatcher extends SolanaWatcher {
throw error;
}
}

private handleMissingFastVaaHash(auctionPubkey: PublicKey, context: string): void {
if (this.network === 'Mainnet') {
throw new Error(
`[${context}] No fast_vaa_hash found for auction ${auctionPubkey.toBase58()} in mainnet`
);
} else {
this.logger.warn(
`[${context}] No fast_vaa_hash found for auction ${auctionPubkey.toBase58()} in testnet. Skipping...`
);
}
}
}
2 changes: 1 addition & 1 deletion watcher/src/watchers/__tests__/FTSolanaWatcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jest.setTimeout(60_000);
// This test is working, but testing it is not very useful since the return value is just the lastBlockKey.
// It is just an entrypoint to test the whole thing with a local postgres database.
// Skipping because it requires db
test.only('getMessagesByBlock', async () => {
test.skip('getMessagesByBlock', async () => {
const watcher = new FTSolanaWatcher('Testnet');
await watcher.getFtMessagesForBlocks(313236172, 314175735);
});
Expand Down

0 comments on commit 1e19cd3

Please sign in to comment.