11import type { Idl } from "@coral-xyz/anchor" ;
22import { BN } from "@coral-xyz/anchor" ;
33import { BorshAccountsCoder } from "@coral-xyz/anchor" ;
4+ import { convertIdlToCamelCase } from "@coral-xyz/anchor/dist/cjs/idl" ;
45import type { PublicKey } from "@solana/web3.js" ;
56import WhirlpoolIDL from "../../artifacts/whirlpool.json" ;
67
@@ -17,37 +18,41 @@ import WhirlpoolIDL from "../../artifacts/whirlpool.json";
1718 * @category Network
1819 */
1920export enum AccountName {
20- WhirlpoolsConfig = "WhirlpoolsConfig " ,
21- Position = "Position " ,
22- TickArray = "TickArray " ,
23- DynamicTickArray = "DynamicTickArray " ,
24- Whirlpool = "Whirlpool " ,
25- FeeTier = "FeeTier " ,
26- PositionBundle = "PositionBundle " ,
27- WhirlpoolsConfigExtension = "WhirlpoolsConfigExtension " ,
28- TokenBadge = "TokenBadge " ,
29- LockConfig = "LockConfig " ,
30- Oracle = "Oracle " ,
31- AdaptiveFeeTier = "AdaptiveFeeTier " ,
21+ WhirlpoolsConfig = "whirlpoolsConfig " ,
22+ Position = "position " ,
23+ TickArray = "tickArray " ,
24+ DynamicTickArray = "dynamicTickArray " ,
25+ Whirlpool = "whirlpool " ,
26+ FeeTier = "feeTier " ,
27+ PositionBundle = "positionBundle " ,
28+ WhirlpoolsConfigExtension = "whirlpoolsConfigExtension " ,
29+ TokenBadge = "tokenBadge " ,
30+ LockConfig = "lockConfig " ,
31+ Oracle = "oracle " ,
32+ AdaptiveFeeTier = "adaptiveFeeTier " ,
3233}
3334
3435export const WHIRLPOOL_IDL = WhirlpoolIDL as Idl ;
3536
3637/**
3738 * The Anchor coder for the Whirlpool program.
3839 * @category Solana Accounts
40+ *
41+ * BorshAccountsCoder does not handle the snake -> camel case
42+ * mapping handled internally by the normal Anchor coder, so
43+ * we must handle ourselves.
3944 */
40- export const WHIRLPOOL_CODER = new BorshAccountsCoder ( WHIRLPOOL_IDL ) ;
45+ export const WHIRLPOOL_CODER = new BorshAccountsCoder (
46+ convertIdlToCamelCase ( WHIRLPOOL_IDL ) ,
47+ ) ;
4148
4249/**
4350 * Get the size of an account owned by the Whirlpool program in bytes.
4451 * @param accountName Whirlpool account name
4552 * @returns Size in bytes of the account
4653 */
4754export function getAccountSize ( accountName : AccountName ) {
48- const size = WHIRLPOOL_CODER . size (
49- WHIRLPOOL_IDL . accounts ! . find ( ( account ) => account . name === accountName ) ! ,
50- ) ;
55+ const size = WHIRLPOOL_CODER . size ( accountName ) ;
5156 return size + RESERVED_BYTES [ accountName ] ;
5257}
5358
0 commit comments