import { describe, expect, it } from 'vitest'; import { PubkeyUtil } from '@saturnbtcio/arch-sdk'; import { PdaType } from '../pda-type'; import { Token } from '@saturnbtcio/pool-serde-sdk'; import { createNewAccount } from '../pda-finder'; // Mock the IArchProvider class MockArchProvider { async getAccountAddress(pubkey: Uint8Array): Promise { return PubkeyUtil.toHex(pubkey); } } describe('PDA Finder', () => { it('should correctly derive pool config PDA from given parameters', async () => { // Given parameters from the test request const feeTier = 20000; const token0: Token = { block: 1n, tx: 0 }; const token1: Token = { block: 0n, tx: 0 }; const programIdHex = 'f459378df0b7fee33978573c17811f581e78b2048cef120752d80673ffbfe2cd'; const expectedPoolConfigPubkeyHex = '2c91722775300124fc7063000080284f58bc81380a434021a34a53549f637ee3'; // Convert hex program ID to Pubkey const programId = PubkeyUtil.fromHex(programIdHex); // Create the PDA const createdAccount = await createNewAccount( { pdaType: PdaType.Config, feeTier, token0, token1, programId, }, new MockArchProvider() as any, ); // Verify that the derived PDA matches the expected value expect(createdAccount.pubkey).toBe(expectedPoolConfigPubkeyHex); }); it('should correctly derive the first 10 shard PDAs', async () => { // Given parameters const feeTier = 20000; const token0: Token = { block: 1n, tx: 0 }; const token1: Token = { block: 0n, tx: 0 }; const programIdHex = 'f459378df0b7fee33978573c17811f581e78b2048cef120752d80673ffbfe2cd'; const programId = PubkeyUtil.fromHex(programIdHex); // Expected shard pubkeys const expectedShardPubkeys = [ 'b5b689588887653700ee2b8d069cb76dc5af3afc4bb0592209cc2f5c6664c9fa', '1c1324029f52e2ddedc10c3a6d57a020a7ede2ad761f3df0f9c0b27094530f7b', '60c00c916ba2e0530aae85466f77d884991af4112b094be9b7ae78afc63624e9', 'ffa4339e5682731cff0fbc34e78de41d206b3a9e71d39ae04644043a86770212', 'aaf6972aab8ea5285769d142b3d5a1367976e25ee8a37ca49800829e6bebab9b', '333d13d293cd30fcb633744fc57e4b596d7a5fb9cd4d81fede0009eee244ed7e', 'a8c7d51c97dd02cd06be29a211c4ffdcb2ae4e679a2a725cdbc2c31fdc3db119', 'c61d117ad1b40dd9f71fa2a90b8976ba7e384cb9fc97f4c69612da6aa59c53cf', '9951aba7b21e1e110d0cfeef6b7aa9320d3bdef7d55742e60075521114c5013b', 'f8ef680d8eecd637c944f63e76da0eb362832ad074c2047835d78db3f300088d', ]; // Verify each shard pubkey for (let shardIdx = 0; shardIdx < 10; shardIdx++) { const createdAccount = await createNewAccount( { pdaType: PdaType.Shard, shardIdx, feeTier, token0, token1, programId, }, new MockArchProvider() as any, ); expect(createdAccount.pubkey).toBe(expectedShardPubkeys[shardIdx]); } }); it('should correctly derive position PDA from given user pubkey', async () => { // Given parameters const feeTier = 20000; const token0: Token = { block: 1n, tx: 0 }; const token1: Token = { block: 0n, tx: 0 }; const programIdHex = 'f459378df0b7fee33978573c17811f581e78b2048cef120752d80673ffbfe2cd'; const userPubkeyHex = '9d5a740b78cd79dd8682711209d1b3f6255fe0e2ecaade19fbecd7e47c87876b'; const expectedPositionPubkeyHex = '98b4577ef2be15041836b7be3ed69ee02e373f0d5dcb4b6c15e6fd8d30fd4cc9'; // Convert hex strings to Pubkeys const programId = PubkeyUtil.fromHex(programIdHex); const userPubKey = PubkeyUtil.fromHex(userPubkeyHex); // Create the position PDA const createdAccount = await createNewAccount( { pdaType: PdaType.Position, userPubKey, feeTier, token0, token1, programId, }, new MockArchProvider() as any, ); // Verify that the derived PDA matches the expected value expect(createdAccount.pubkey).toBe(expectedPositionPubkeyHex); }); });