test-rrr-sdk
Version:
An SDK for building applications on top of Raydium.
1 lines • 684 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/marshmallow/index.ts","../../../src/marshmallow/buffer-layout.ts","../../../src/raydium/cpmm/layout.ts","../../../src/raydium/cpmm/instruction.ts","../../../src/common/accountInfo.ts","../../../src/common/logger.ts","../../../src/common/bignumber.ts","../../../node_modules/decimal.js/decimal.mjs","../../../src/module/amount.ts","../../../src/module/formatter.ts","../../../src/module/fraction.ts","../../../src/common/constant.ts","../../../src/raydium/token/constant.ts","../../../src/module/token.ts","../../../src/common/pubKey.ts","../../../src/module/currency.ts","../../../src/module/percent.ts","../../../src/module/price.ts","../../../src/common/utility.ts","../../../src/common/pda.ts","../../../src/common/txTool/txUtils.ts","../../../src/common/txTool/txType.ts","../../../src/common/programId.ts","../../../src/common/transfer.ts","../../../src/common/txTool/lookupTable.ts","../../../src/common/txTool/txTool.ts","../../../src/common/fee.ts","../../../src/raydium/cpmm/pda.ts","../../../src/raydium/clmm/clmm.ts","../../../src/raydium/token/utils.ts","../../../src/raydium/clmm/instrument.ts","../../../src/raydium/clmm/utils/tick.ts","../../../src/raydium/clmm/utils/constants.ts","../../../src/raydium/clmm/utils/math.ts","../../../src/raydium/clmm/utils/pda.ts","../../../src/raydium/clmm/utils/pool.ts","../../../src/raydium/clmm/utils/position.ts","../../../src/raydium/clmm/utils/tickarrayBitmap.ts","../../../src/raydium/clmm/layout.ts","../../../src/raydium/cpmm/curve/calculator.ts","../../../src/raydium/cpmm/curve/constantProduct.ts","../../../src/raydium/cpmm/curve/fee.ts"],"sourcesContent":["import { PublicKey } from \"@solana/web3.js\";\nimport BN, { isBN } from \"bn.js\";\n\nimport {\n bits,\n blob,\n Blob,\n Layout,\n offset as _offset,\n seq as _seq,\n Structure as _Structure,\n u32 as _u32,\n u8 as _u8,\n UInt,\n union as _union,\n Union as _Union,\n} from \"./buffer-layout\";\n\nexport * from \"./buffer-layout\";\nexport { blob };\n\nexport class BNLayout<P extends string = \"\"> extends Layout<BN, P> {\n blob: Layout<Buffer>;\n signed: boolean;\n\n constructor(span: number, signed: boolean, property?: P) {\n //@ts-expect-error type wrong for super()'s type different from extends, but it desn't matter\n super(span, property);\n this.blob = blob(span);\n this.signed = signed;\n }\n\n /** @override */\n decode(b: Buffer, offset = 0): BN {\n const num = new BN(this.blob.decode(b, offset), 10, \"le\");\n if (this.signed) {\n return num.fromTwos(this.span * 8).clone();\n }\n return num;\n }\n\n /** @override */\n encode(src: BN, b: Buffer, offset = 0): number {\n if (typeof src === \"number\") src = new BN(src); // src will pass a number accidently in union\n if (this.signed) {\n src = src.toTwos(this.span * 8);\n }\n return this.blob.encode(src.toArrayLike(Buffer, \"le\", this.span), b, offset);\n }\n}\n\nexport class WideBits<P extends string = \"\"> extends Layout<Record<string, boolean>, P> {\n _lower: any;\n _upper: any;\n // TODO: unknown\n constructor(property?: P) {\n //@ts-expect-error type wrong for super()'s type different from extends , but it desn't matter\n super(8, property);\n this._lower = bits(_u32(), false);\n this._upper = bits(_u32(), false);\n }\n\n addBoolean(property: string): void {\n if (this._lower.fields.length < 32) {\n this._lower.addBoolean(property);\n } else {\n this._upper.addBoolean(property);\n }\n }\n\n decode(b: Buffer, offset = 0): Record<string, boolean> {\n const lowerDecoded = this._lower.decode(b, offset);\n const upperDecoded = this._upper.decode(b, offset + this._lower.span);\n return { ...lowerDecoded, ...upperDecoded };\n }\n\n encode(src: any /* TEMP */, b: Buffer, offset = 0): any {\n return this._lower.encode(src, b, offset) + this._upper.encode(src, b, offset + this._lower.span);\n }\n}\n\nexport function u8<P extends string = \"\">(property?: P): UInt<number, P> {\n return new UInt(1, property);\n}\n\nexport function u32<P extends string = \"\">(property?: P): UInt<number, P> {\n return new UInt(4, property);\n}\n\nexport function u64<P extends string = \"\">(property?: P): BNLayout<P> {\n return new BNLayout(8, false, property);\n}\n\nexport function u128<P extends string = \"\">(property?: P): BNLayout<P> {\n return new BNLayout(16, false, property);\n}\n\nexport function i8<P extends string = \"\">(property?: P): BNLayout<P> {\n return new BNLayout(1, true, property);\n}\n\nexport function i64<P extends string = \"\">(property?: P): BNLayout<P> {\n return new BNLayout(8, true, property);\n}\n\nexport function i128<P extends string = \"\">(property?: P): BNLayout<P> {\n return new BNLayout(16, true, property);\n}\n\nexport class WrappedLayout<T, U, P extends string = \"\"> extends Layout<U, P> {\n layout: Layout<T>;\n decoder: (data: T) => U;\n encoder: (src: U) => T;\n\n constructor(layout: Layout<T>, decoder: (data: T) => U, encoder: (src: U) => T, property?: P) {\n //@ts-expect-error type wrong for super()'s type different from extends , but it desn't matter\n super(layout.span, property);\n this.layout = layout;\n this.decoder = decoder;\n this.encoder = encoder;\n }\n\n decode(b: Buffer, offset?: number): U {\n return this.decoder(this.layout.decode(b, offset));\n }\n\n encode(src: U, b: Buffer, offset?: number): number {\n return this.layout.encode(this.encoder(src), b, offset);\n }\n\n getSpan(b: Buffer, offset?: number): number {\n return this.layout.getSpan(b, offset);\n }\n}\n\nexport function publicKey<P extends string = \"\">(property?: P): Layout<PublicKey, P> {\n return new WrappedLayout(\n blob(32),\n (b: Buffer) => new PublicKey(b),\n (key: PublicKey) => key.toBuffer(),\n property,\n );\n}\n\nexport class OptionLayout<T, P> extends Layout<T | null, P> {\n layout: Layout<T>;\n discriminator: Layout<number>;\n\n constructor(layout: Layout<T>, property?: P) {\n //@ts-expect-error type wrong for super()'s type different from extends , but it desn't matter\n super(-1, property);\n this.layout = layout;\n this.discriminator = _u8();\n }\n\n encode(src: T | null, b: Buffer, offset = 0): number {\n if (src === null || src === undefined) {\n return this.discriminator.encode(0, b, offset);\n }\n this.discriminator.encode(1, b, offset);\n return this.layout.encode(src, b, offset + 1) + 1;\n }\n\n decode(b: Buffer, offset = 0): T | null {\n const discriminator = this.discriminator.decode(b, offset);\n if (discriminator === 0) {\n return null;\n } else if (discriminator === 1) {\n return this.layout.decode(b, offset + 1);\n }\n throw new Error(\"Invalid option \" + this.property);\n }\n\n getSpan(b: Buffer, offset = 0): number {\n const discriminator = this.discriminator.decode(b, offset);\n if (discriminator === 0) {\n return 1;\n } else if (discriminator === 1) {\n return this.layout.getSpan(b, offset + 1) + 1;\n }\n throw new Error(\"Invalid option \" + this.property);\n }\n}\n\nexport function option<T, P extends string = \"\">(layout: Layout<T>, property?: P): Layout<T | null, P> {\n return new OptionLayout<T, P>(layout, property);\n}\n\nexport function bool<P extends string = \"\">(property?: P): Layout<boolean, P> {\n return new WrappedLayout(_u8(), decodeBool, encodeBool, property);\n}\n\nexport function decodeBool(value: number): boolean {\n if (value === 0) {\n return false;\n } else if (value === 1) {\n return true;\n }\n throw new Error(\"Invalid bool: \" + value);\n}\n\nexport function encodeBool(value: boolean): number {\n return value ? 1 : 0;\n}\n\nexport function vec<T, P extends string = \"\">(elementLayout: Layout<T>, property?: P): Layout<T[], P> {\n const length = _u32(\"length\");\n const layout: Layout<{ values: T[] }> = struct([\n length,\n seq(elementLayout, _offset(length, -length.span), \"values\"),\n ]) as any; // Something I don't know\n return new WrappedLayout(\n layout,\n ({ values }) => values,\n (values) => ({ values }),\n property,\n );\n}\n\nexport function tagged<T, P extends string = \"\">(tag: BN, layout: Layout<T>, property?: P): Layout<T, P> {\n const wrappedLayout: Layout<{ tag: BN; data: T }> = struct([u64(\"tag\"), layout.replicate(\"data\")]) as any; // Something I don't know\n\n function decodeTag({ tag: receivedTag, data }: { tag: BN; data: T }): T {\n if (!receivedTag.eq(tag)) {\n throw new Error(\"Invalid tag, expected: \" + tag.toString(\"hex\") + \", got: \" + receivedTag.toString(\"hex\"));\n }\n return data;\n }\n\n return new WrappedLayout(wrappedLayout, decodeTag, (data) => ({ tag, data }), property);\n}\n\nexport function vecU8<P extends string = \"\">(property?: P): Layout<Buffer, P> {\n const length = _u32(\"length\");\n const layout: Layout<{ data: Buffer }> = struct([length, blob(_offset(length, -length.span), \"data\")]) as any; // Something I don't know\n return new WrappedLayout(\n layout,\n ({ data }) => data,\n (data) => ({ data }),\n property,\n );\n}\n\nexport function str<P extends string = \"\">(property?: P): Layout<string, P> {\n return new WrappedLayout(\n vecU8(),\n (data) => data.toString(\"utf-8\"),\n (s) => Buffer.from(s, \"utf-8\"),\n property,\n );\n}\n\nexport interface EnumLayout<T, P extends string = \"\"> extends Layout<T, P> {\n registry: Record<string, Layout<any>>;\n}\n\nexport function rustEnum<T, P extends string = \"\">(variants: Layout<any>[], property?: P): EnumLayout<T, P> {\n const unionLayout = _union(_u8(), property);\n variants.forEach((variant, index) => unionLayout.addVariant(index, variant, variant.property));\n return unionLayout as any; // ?why use UnionLayout? This must be a fault\n}\n\nexport function array<T, P extends string = \"\">(\n elementLayout: Layout<T>,\n length: number,\n property?: P,\n): Layout<T[], P> {\n const layout = struct([seq(elementLayout, length, \"values\")]) as any as Layout<{ values: T[] }>; // Something I don't know\n return new WrappedLayout(\n layout,\n ({ values }) => values,\n (values) => ({ values }),\n property,\n );\n}\n\nexport class Structure<T, P, D extends { [key: string]: any; }> extends _Structure<T, P, D> {\n /** @override */\n decode(b: Buffer, offset?: number): D {\n return super.decode(b, offset);\n }\n}\n\nexport function struct<T, P extends string = \"\">(\n fields: T,\n property?: P,\n decodePrefixes?: boolean,\n): T extends Layout<infer Value, infer Property>[]\n ? Structure<\n Value,\n P,\n {\n [K in Exclude<Extract<Property, string>, \"\">]: Extract<T[number], Layout<any, K>> extends Layout<infer V, any>\n ? V\n : any;\n }\n >\n : any {\n //@ts-expect-error this type is not quite satisfied the define, but, never no need to worry about.\n return new Structure(fields, property, decodePrefixes);\n}\n\nexport type GetLayoutSchemaFromStructure<T extends Structure<any, any, any>> = T extends Structure<any, any, infer S>\n ? S\n : any;\nexport type GetStructureFromLayoutSchema<S extends { [key: string]: any; }> = Structure<any, any, S>;\n\nexport class Union<Schema extends { [key: string]: any; }> extends _Union<Schema> {\n encodeInstruction(instruction: any): Buffer {\n const instructionMaxSpan = Math.max(...Object.values(this.registry).map((r) => r.span));\n const b = Buffer.alloc(instructionMaxSpan);\n return b.slice(0, this.encode(instruction, b));\n }\n\n decodeInstruction(instruction: any): Partial<Schema> {\n return this.decode(instruction);\n }\n}\nexport function union<UnionSchema extends { [key: string]: any } = any>(\n discr: any,\n defaultLayout?: any,\n property?: string,\n): Union<UnionSchema> {\n return new Union(discr, defaultLayout, property);\n}\n\nclass Zeros extends Blob {\n decode(b: Buffer, offset: number): Buffer {\n const slice = super.decode(b, offset);\n if (!slice.every((v) => v === 0)) {\n throw new Error(\"nonzero padding bytes\");\n }\n return slice;\n }\n}\n\nexport function zeros(length: number): Zeros {\n return new Zeros(length);\n}\n\nexport function seq<T, P extends string = \"\", AnotherP extends string = \"\">(\n elementLayout: Layout<T, P>,\n count: number | BN | Layout<BN | number, P>,\n property?: AnotherP,\n): Layout<T[], AnotherP> {\n let parsedCount: number;\n const superCount =\n typeof count === \"number\"\n ? count\n : isBN(count)\n ? count.toNumber()\n : new Proxy(count as unknown as Layout<number> /* pretend to be Layout<number> */, {\n get(target, property): any {\n if (!parsedCount) {\n // get count in targetLayout. note that count may be BN\n const countProperty = Reflect.get(target, \"count\");\n\n // let targetLayout's property:count be a number\n parsedCount = isBN(countProperty) ? countProperty.toNumber() : countProperty;\n\n // record the count\n Reflect.set(target, \"count\", parsedCount);\n }\n return Reflect.get(target, property);\n },\n set(target, property, value): any {\n if (property === \"count\") {\n parsedCount = value;\n }\n return Reflect.set(target, property, value);\n },\n });\n\n // @ts-expect-error force type\n return _seq(elementLayout, superCount, property);\n}\n","import {\n bits as _bits,\n BitStructure as _BitStructure,\n blob as _blob,\n Blob as _Blob,\n cstr as _cstr,\n f32 as _f32,\n f32be as _f32be,\n f64 as _f64,\n f64be as _f64be,\n greedy as _greedy,\n Layout as _Layout,\n ns64 as _ns64,\n ns64be as _ns64be,\n nu64 as _nu64,\n nu64be as _nu64be,\n offset as _offset,\n s16 as _s16,\n s16be as _s16be,\n s24 as _s24,\n s24be as _s24be,\n s32 as _s32,\n s32be as _s32be,\n s40 as _s40,\n s40be as _s40be,\n s48 as _s48,\n s48be as _s48be,\n s8 as _s8,\n seq as _seq,\n struct as _struct,\n Structure as _Structure,\n u16 as _u16,\n u16be as _u16be,\n u24 as _u24,\n u24be as _u24be,\n u32 as _u32,\n u32be as _u32be,\n u40 as _u40,\n u40be as _u40be,\n u48 as _u48,\n u48be as _u48be,\n u8 as _u8,\n UInt as _UInt,\n union as _union,\n Union as _Union,\n unionLayoutDiscriminator as _unionLayoutDiscriminator,\n utf8 as _utf8,\n} from \"@solana/buffer-layout\";\n\n//#region ------------------- Layout -------------------\nexport interface Layout<T = any, P = \"\"> {\n span: number;\n property?: P;\n decode(b: Buffer, offset?: number): T;\n encode(src: T, b: Buffer, offset?: number): number;\n getSpan(b: Buffer, offset?: number): number;\n replicate<AP extends string>(name: AP): Layout<T, AP>;\n}\nexport interface LayoutConstructor {\n new <T, P>(): Layout<T, P>; // for class extends syntex\n new <T, P>(span?: T, property?: P): Layout<T, P>;\n readonly prototype: Layout;\n}\nexport const Layout = _Layout as unknown as LayoutConstructor;\n//#endregion\n\n//#region ------------------- Structure -------------------\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport interface Structure<T = any, P = \"\", DecodeSchema extends { [key: string]: any } = any>\n extends Layout<DecodeSchema, P> {\n span: number;\n decode(b: Buffer, offset?: number): DecodeSchema;\n layoutFor<AP extends string>(property: AP): Layout<DecodeSchema[AP]>;\n offsetOf<AP extends string>(property: AP): number;\n}\ninterface StructureConstructor {\n new <T = any, P = \"\", DecodeSchema extends { [key: string]: any } = any>(): Structure<T, P, DecodeSchema>;\n new <T = any, P = \"\", DecodeSchema extends { [key: string]: any } = any>(\n fields: T,\n property?: P,\n decodePrefixes?: boolean,\n ): Structure<T, P, DecodeSchema>;\n}\nexport const Structure = _Structure as unknown as StructureConstructor;\n//#endregion\n\n//#region ------------------- Union -------------------\nexport interface Union<UnionSchema extends { [key: string]: any } = any> extends Layout {\n registry: object;\n decode(b: Buffer, offset?: number): Partial<UnionSchema>;\n addVariant(\n variant: number,\n layout: Structure<any, any, Partial<UnionSchema>> | Layout<any, keyof UnionSchema>,\n property?: string,\n ): any /* TEMP: code in Layout.js 1809 */;\n}\ninterface UnionConstructor {\n new <UnionSchema extends { [key: string]: any } = any>(): Union<UnionSchema>;\n new <UnionSchema extends { [key: string]: any } = any>(\n discr: Layout<any, any>,\n defaultLayout: Layout<any, any>,\n property?: string,\n ): Union<UnionSchema>;\n}\nexport const Union = _Union as unknown as UnionConstructor;\n//#endregion\n\n//#region ------------------- BitStructure -------------------\nexport type BitStructure<T = unknown /* TEMP */, P = \"\"> = Layout<T, P>;\ninterface BitStructureConstructor {\n new (...params: any[]): BitStructure;\n}\nexport const BitStructure = _BitStructure as BitStructureConstructor;\n//#endregion\n\n//#region ------------------- UInt -------------------\nexport type UInt<T = any, P = \"\"> = Layout<T, P>;\ninterface UIntConstructor {\n new <T, P>(span?: T, property?: P): UInt<T, P>;\n}\nexport const UInt = _UInt as UIntConstructor;\n//#endregion\n\n//#region ------------------- Blob -------------------\nexport type Blob<P extends string = \"\"> = Layout<Buffer, P>;\ninterface BlobConstructor {\n new (...params: ConstructorParameters<LayoutConstructor>): Blob;\n}\nexport const Blob = _Blob as unknown as BlobConstructor;\n//#endregion\n\nexport const greedy = _greedy as <P extends string = \"\">(elementSpan?: number, property?: P) => Layout<number, P>;\nexport const u8 = _u8 as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const u16 = _u16 as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const u24 = _u24 as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const u32 = _u32 as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const u40 = _u40 as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const u48 = _u48 as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const nu64 = _nu64 as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const u16be = _u16be as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const u24be = _u24be as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const u32be = _u32be as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const u40be = _u40be as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const u48be = _u48be as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const nu64be = _nu64be as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const s8 = _s8 as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const s16 = _s16 as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const s24 = _s24 as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const s32 = _s32 as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const s40 = _s40 as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const s48 = _s48 as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const ns64 = _ns64 as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const s16be = _s16be as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const s24be = _s24be as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const s32be = _s32be as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const s40be = _s40be as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const s48be = _s48be as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const ns64be = _ns64be as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const f32 = _f32 as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const f32be = _f32be as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const f64 = _f64 as <P extends string = \"\">(property?: P) => Layout<number, P>;\nexport const f64be = _f64be as <P extends string = \"\">(property?: P) => Layout<number, P>;\n\nexport const struct = _struct as <T, P extends string = \"\">(\n fields: T,\n property?: P,\n decodePrefixes?: boolean,\n) => T extends Layout<infer Value, infer Property>[]\n ? Structure<\n Value,\n P,\n {\n [K in Exclude<Extract<Property, string>, \"\">]: Extract<T[number], Layout<any, K>> extends Layout<infer V, any>\n ? V\n : any;\n }\n >\n : any;\n\nexport const seq = _seq as unknown as <T, P>(\n elementLayout: Layout<T, string>,\n count: number | Layout<number, string>,\n property?: P,\n) => Layout<T[]>;\nexport const union = _union as <UnionSchema extends { [key: string]: any } = any>(\n discr: Layout<any, any>,\n defaultLayout?: any,\n property?: string,\n) => Union<UnionSchema>;\nexport const unionLayoutDiscriminator = _unionLayoutDiscriminator as <P extends string = \"\">(\n layout: Layout<any, P>,\n property?: P,\n) => any;\nexport const blob = _blob as unknown as <P extends string = \"\">(\n length: number | Layout<number, P>,\n property?: P,\n) => Blob<P>;\nexport const cstr = _cstr as <P extends string = \"\">(property?: P) => Layout<string, P>;\nexport const utf8 = _utf8 as <P extends string = \"\">(maxSpan: number, property?: P) => Layout<string, P>;\nexport const bits = _bits as unknown as <T, P extends string = \"\">(\n word: Layout<T>,\n msb?: boolean,\n property?: P,\n) => BitStructure<T, P>; // TODO: not quite sure\nexport const offset = _offset as unknown as <T, P extends string = \"\">(\n layout: Layout<T, P>,\n offset?: number,\n property?: P,\n) => Layout<T, P>;\n\nexport type GetStructureSchema<T extends Structure> = T extends Structure<any, any, infer S> ? S : unknown;\n","import { blob, bool, publicKey, seq, struct, u16, u64, u8, u128 } from \"../../marshmallow\";\n\nexport const CpmmConfigInfoLayout = struct([\n blob(8),\n u8(\"bump\"),\n bool(\"disableCreatePool\"),\n u16(\"index\"),\n u64(\"tradeFeeRate\"),\n u64(\"protocolFeeRate\"),\n u64(\"fundFeeRate\"),\n u64(\"createPoolFee\"),\n\n publicKey(\"protocolOwner\"),\n publicKey(\"fundOwner\"),\n seq(u64(), 16),\n]);\n\nexport const CpmmPoolInfoLayout = struct([\n blob(8),\n\n publicKey(\"configId\"),\n publicKey(\"poolCreator\"),\n publicKey(\"vaultA\"),\n publicKey(\"vaultB\"),\n\n publicKey(\"mintLp\"),\n publicKey(\"mintA\"),\n publicKey(\"mintB\"),\n\n publicKey(\"mintProgramA\"),\n publicKey(\"mintProgramB\"),\n\n publicKey(\"observationId\"),\n\n u8(\"bump\"),\n u8(\"status\"),\n\n u8(\"lpDecimals\"),\n u8(\"mintDecimalA\"),\n u8(\"mintDecimalB\"),\n\n u64(\"lpAmount\"),\n u64(\"protocolFeesMintA\"),\n u64(\"protocolFeesMintB\"),\n u64(\"fundFeesMintA\"),\n u64(\"fundFeesMintB\"),\n u64(\"openTime\"),\n\n seq(u64(), 32),\n]);\n","import BN from \"bn.js\";\n\nimport { AccountMeta, PublicKey, TransactionInstruction, Signer, Keypair, SystemProgram } from \"@solana/web3.js\";\nimport { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID } from \"@solana/spl-token\";\nimport {\n MEMO_PROGRAM_ID2,\n RENT_PROGRAM_ID,\n SYSTEM_PROGRAM_ID,\n METADATA_PROGRAM_ID,\n createLogger,\n CREATE_CPMM_POOL_PROGRAM,\n CREATE_CPMM_POOL_AUTH,\n InstructionType,\n} from \"@/common\";\nimport { getCpmmPdaPoolId, getCpLockPda } from \"./pda\";\n\nimport { struct, u64, bool } from \"@/marshmallow\";\nimport { ReturnTypeMakeInstructions } from \"@/raydium/type\";\nimport { ApiV3PoolInfoStandardItemCpmm, CpmmKeys } from \"@/api\";\nimport { getATAAddress } from \"@/common\";\nimport { getPdaMetadataKey } from \"../clmm\";\nimport { CpmmLockExtInfo } from \"./type\";\n\nconst logger = createLogger(\"Raydium_cpmm\");\nconst anchorDataBuf = {\n initialize: [175, 175, 109, 31, 13, 152, 155, 237],\n deposit: [242, 35, 198, 137, 82, 225, 242, 182],\n withdraw: [183, 18, 70, 156, 148, 109, 161, 34],\n swapBaseInput: [143, 190, 90, 218, 196, 30, 51, 222],\n swapBaseOutput: [55, 217, 98, 86, 163, 74, 180, 173],\n lockCpLiquidity: [216, 157, 29, 78, 38, 51, 31, 26],\n collectCpFee: [8, 30, 51, 199, 209, 184, 247, 133],\n};\n\nexport function makeCreateCpmmPoolInInstruction(\n programId: PublicKey,\n creator: PublicKey,\n configId: PublicKey,\n authority: PublicKey,\n poolId: PublicKey,\n mintA: PublicKey,\n mintB: PublicKey,\n lpMint: PublicKey,\n userVaultA: PublicKey,\n userVaultB: PublicKey,\n userLpAccount: PublicKey,\n vaultA: PublicKey,\n vaultB: PublicKey,\n createPoolFeeAccount: PublicKey,\n mintProgramA: PublicKey,\n mintProgramB: PublicKey,\n observationId: PublicKey,\n\n amountMaxA: BN,\n amountMaxB: BN,\n openTime: BN,\n): TransactionInstruction {\n const dataLayout = struct([u64(\"amountMaxA\"), u64(\"amountMaxB\"), u64(\"openTime\")]);\n\n const pdaPoolId = getCpmmPdaPoolId(programId, configId, mintA, mintB).publicKey;\n\n const keys: Array<AccountMeta> = [\n { pubkey: creator, isSigner: true, isWritable: false },\n { pubkey: configId, isSigner: false, isWritable: false },\n { pubkey: authority, isSigner: false, isWritable: false },\n { pubkey: poolId, isSigner: !poolId.equals(pdaPoolId), isWritable: true },\n { pubkey: mintA, isSigner: false, isWritable: false },\n { pubkey: mintB, isSigner: false, isWritable: false },\n { pubkey: lpMint, isSigner: false, isWritable: true },\n { pubkey: userVaultA, isSigner: false, isWritable: true },\n { pubkey: userVaultB, isSigner: false, isWritable: true },\n { pubkey: userLpAccount, isSigner: false, isWritable: true },\n { pubkey: vaultA, isSigner: false, isWritable: true },\n { pubkey: vaultB, isSigner: false, isWritable: true },\n { pubkey: createPoolFeeAccount, isSigner: false, isWritable: true },\n { pubkey: observationId, isSigner: false, isWritable: true },\n\n { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: mintProgramA, isSigner: false, isWritable: false },\n { pubkey: mintProgramB, isSigner: false, isWritable: false },\n { pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: SYSTEM_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: RENT_PROGRAM_ID, isSigner: false, isWritable: false },\n ];\n\n const data = Buffer.alloc(dataLayout.span);\n dataLayout.encode(\n {\n amountMaxA,\n amountMaxB,\n openTime,\n },\n data,\n );\n\n return new TransactionInstruction({\n keys,\n programId,\n data: Buffer.from([...anchorDataBuf.initialize, ...data]),\n });\n}\n\nexport function makeDepositCpmmInInstruction(\n programId: PublicKey,\n owner: PublicKey,\n authority: PublicKey,\n poolId: PublicKey,\n userLpAccount: PublicKey,\n userVaultA: PublicKey,\n userVaultB: PublicKey,\n vaultA: PublicKey,\n vaultB: PublicKey,\n mintA: PublicKey,\n mintB: PublicKey,\n lpMint: PublicKey,\n\n lpAmount: BN,\n amountMaxA: BN,\n amountMaxB: BN,\n): TransactionInstruction {\n const dataLayout = struct([u64(\"lpAmount\"), u64(\"amountMaxA\"), u64(\"amountMaxB\")]);\n\n const keys: Array<AccountMeta> = [\n { pubkey: owner, isSigner: true, isWritable: false },\n { pubkey: authority, isSigner: false, isWritable: false },\n { pubkey: poolId, isSigner: false, isWritable: true },\n { pubkey: userLpAccount, isSigner: false, isWritable: true },\n { pubkey: userVaultA, isSigner: false, isWritable: true },\n { pubkey: userVaultB, isSigner: false, isWritable: true },\n { pubkey: vaultA, isSigner: false, isWritable: true },\n { pubkey: vaultB, isSigner: false, isWritable: true },\n { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: TOKEN_2022_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: mintA, isSigner: false, isWritable: false },\n { pubkey: mintB, isSigner: false, isWritable: false },\n { pubkey: lpMint, isSigner: false, isWritable: true },\n ];\n\n const data = Buffer.alloc(dataLayout.span);\n logger.debug(\"cpmm deposit data\", {\n lpAmount: lpAmount.toString(),\n amountMaxA: amountMaxA.toString(),\n amountMaxB: amountMaxB.toString(),\n });\n dataLayout.encode(\n {\n lpAmount,\n amountMaxA,\n amountMaxB,\n },\n data,\n );\n\n return new TransactionInstruction({\n keys,\n programId,\n data: Buffer.from([...anchorDataBuf.deposit, ...data]),\n });\n}\n\nexport function makeWithdrawCpmmInInstruction(\n programId: PublicKey,\n owner: PublicKey,\n authority: PublicKey,\n poolId: PublicKey,\n userLpAccount: PublicKey,\n userVaultA: PublicKey,\n userVaultB: PublicKey,\n vaultA: PublicKey,\n vaultB: PublicKey,\n mintA: PublicKey,\n mintB: PublicKey,\n lpMint: PublicKey,\n\n lpAmount: BN,\n amountMinA: BN,\n amountMinB: BN,\n): TransactionInstruction {\n const dataLayout = struct([u64(\"lpAmount\"), u64(\"amountMinA\"), u64(\"amountMinB\")]);\n\n const keys: Array<AccountMeta> = [\n { pubkey: owner, isSigner: true, isWritable: false },\n { pubkey: authority, isSigner: false, isWritable: false },\n { pubkey: poolId, isSigner: false, isWritable: true },\n { pubkey: userLpAccount, isSigner: false, isWritable: true },\n { pubkey: userVaultA, isSigner: false, isWritable: true },\n { pubkey: userVaultB, isSigner: false, isWritable: true },\n { pubkey: vaultA, isSigner: false, isWritable: true },\n { pubkey: vaultB, isSigner: false, isWritable: true },\n { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: TOKEN_2022_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: mintA, isSigner: false, isWritable: false },\n { pubkey: mintB, isSigner: false, isWritable: false },\n { pubkey: lpMint, isSigner: false, isWritable: true },\n { pubkey: MEMO_PROGRAM_ID2, isSigner: false, isWritable: false },\n ];\n\n const data = Buffer.alloc(dataLayout.span);\n dataLayout.encode(\n {\n lpAmount,\n amountMinA,\n amountMinB,\n },\n data,\n );\n\n return new TransactionInstruction({\n keys,\n programId,\n data: Buffer.from([...anchorDataBuf.withdraw, ...data]),\n });\n}\n\nexport function makeSwapCpmmBaseInInstruction(\n programId: PublicKey,\n payer: PublicKey,\n authority: PublicKey,\n configId: PublicKey,\n poolId: PublicKey,\n userInputAccount: PublicKey,\n userOutputAccount: PublicKey,\n inputVault: PublicKey,\n outputVault: PublicKey,\n inputTokenProgram: PublicKey,\n outputTokenProgram: PublicKey,\n inputMint: PublicKey,\n outputMint: PublicKey,\n observationId: PublicKey,\n\n amountIn: BN,\n amounOutMin: BN,\n): TransactionInstruction {\n const dataLayout = struct([u64(\"amountIn\"), u64(\"amounOutMin\")]);\n\n const keys: Array<AccountMeta> = [\n { pubkey: payer, isSigner: true, isWritable: false },\n { pubkey: authority, isSigner: false, isWritable: false },\n { pubkey: configId, isSigner: false, isWritable: false },\n { pubkey: poolId, isSigner: false, isWritable: true },\n { pubkey: userInputAccount, isSigner: false, isWritable: true },\n { pubkey: userOutputAccount, isSigner: false, isWritable: true },\n { pubkey: inputVault, isSigner: false, isWritable: true },\n { pubkey: outputVault, isSigner: false, isWritable: true },\n { pubkey: inputTokenProgram, isSigner: false, isWritable: false },\n { pubkey: outputTokenProgram, isSigner: false, isWritable: false },\n { pubkey: inputMint, isSigner: false, isWritable: false },\n { pubkey: outputMint, isSigner: false, isWritable: false },\n { pubkey: observationId, isSigner: false, isWritable: true },\n ];\n\n const data = Buffer.alloc(dataLayout.span);\n dataLayout.encode(\n {\n amountIn,\n amounOutMin,\n },\n data,\n );\n\n return new TransactionInstruction({\n keys,\n programId,\n data: Buffer.from([...anchorDataBuf.swapBaseInput, ...data]),\n });\n}\nexport function makeSwapCpmmBaseOutInstruction(\n programId: PublicKey,\n payer: PublicKey,\n authority: PublicKey,\n configId: PublicKey,\n poolId: PublicKey,\n userInputAccount: PublicKey,\n userOutputAccount: PublicKey,\n inputVault: PublicKey,\n outputVault: PublicKey,\n inputTokenProgram: PublicKey,\n outputTokenProgram: PublicKey,\n inputMint: PublicKey,\n outputMint: PublicKey,\n observationId: PublicKey,\n\n amountInMax: BN,\n amountOut: BN,\n): TransactionInstruction {\n const dataLayout = struct([u64(\"amountInMax\"), u64(\"amountOut\")]);\n\n const keys: Array<AccountMeta> = [\n { pubkey: payer, isSigner: true, isWritable: false },\n { pubkey: authority, isSigner: false, isWritable: false },\n { pubkey: configId, isSigner: false, isWritable: false },\n { pubkey: poolId, isSigner: false, isWritable: true },\n { pubkey: userInputAccount, isSigner: false, isWritable: true },\n { pubkey: userOutputAccount, isSigner: false, isWritable: true },\n { pubkey: inputVault, isSigner: false, isWritable: true },\n { pubkey: outputVault, isSigner: false, isWritable: true },\n { pubkey: inputTokenProgram, isSigner: false, isWritable: false },\n { pubkey: outputTokenProgram, isSigner: false, isWritable: false },\n { pubkey: inputMint, isSigner: false, isWritable: false },\n { pubkey: outputMint, isSigner: false, isWritable: false },\n { pubkey: observationId, isSigner: false, isWritable: true },\n ];\n\n const data = Buffer.alloc(dataLayout.span);\n dataLayout.encode(\n {\n amountInMax,\n amountOut,\n },\n data,\n );\n\n return new TransactionInstruction({\n keys,\n programId,\n data: Buffer.from([...anchorDataBuf.swapBaseOutput, ...data]),\n });\n}\n\nexport async function makeCpmmLockInstruction(props: {\n poolInfo: ApiV3PoolInfoStandardItemCpmm;\n poolKeys: CpmmKeys;\n ownerInfo: {\n feePayer: PublicKey;\n wallet: PublicKey;\n };\n feeNftOwner: PublicKey;\n\n lockProgram: PublicKey;\n lockAuthProgram: PublicKey;\n lpAmount: BN;\n withMetadata?: boolean;\n getEphemeralSigners?: (k: number) => any;\n}): Promise<ReturnTypeMakeInstructions<CpmmLockExtInfo>> {\n const { ownerInfo, poolInfo, poolKeys, feeNftOwner, getEphemeralSigners } = props;\n\n const signers: Signer[] = [];\n const [poolId, lpMint] = [new PublicKey(poolInfo.id), new PublicKey(poolInfo.lpMint.address)];\n\n let nftMintAccount: PublicKey;\n if (getEphemeralSigners) {\n nftMintAccount = new PublicKey((await getEphemeralSigners(1))[0]);\n } else {\n const _k = Keypair.generate();\n signers.push(_k);\n nftMintAccount = _k.publicKey;\n }\n\n const { publicKey: nftAccount } = getATAAddress(feeNftOwner, nftMintAccount, TOKEN_PROGRAM_ID);\n const { publicKey: metadataAccount } = getPdaMetadataKey(nftMintAccount);\n const { publicKey: lockPda } = getCpLockPda(props.lockProgram, nftMintAccount);\n\n const { publicKey: userLpVault } = getATAAddress(ownerInfo.wallet, lpMint, TOKEN_PROGRAM_ID);\n const { publicKey: lockLpVault } = getATAAddress(props.lockAuthProgram, lpMint, TOKEN_PROGRAM_ID);\n\n const ins = cpmmLockPositionInstruction({\n programId: props.lockProgram,\n auth: props.lockAuthProgram,\n payer: ownerInfo.feePayer,\n liquidityOwner: ownerInfo.wallet,\n nftOwner: feeNftOwner,\n nftMint: nftMintAccount,\n nftAccount,\n poolId,\n lockPda,\n mintLp: lpMint,\n userLpVault,\n lockLpVault,\n poolVaultA: new PublicKey(poolKeys.vault.A),\n poolVaultB: new PublicKey(poolKeys.vault.B),\n metadataAccount,\n lpAmount: props.lpAmount,\n withMetadata: props.withMetadata ?? true,\n });\n\n return {\n address: {\n nftMint: nftMintAccount,\n nftAccount,\n metadataAccount,\n lockPda,\n userLpVault,\n lockLpVault,\n },\n instructions: [ins],\n signers,\n instructionTypes: [InstructionType.CpmmLockLp],\n lookupTableAddress: [],\n };\n}\n\nexport function cpmmLockPositionInstruction({\n programId,\n auth,\n payer,\n liquidityOwner,\n nftOwner,\n nftMint,\n nftAccount,\n poolId,\n lockPda,\n mintLp,\n userLpVault,\n lockLpVault,\n poolVaultA,\n poolVaultB,\n metadataAccount,\n lpAmount,\n withMetadata,\n}: {\n programId: PublicKey;\n auth: PublicKey;\n payer: PublicKey;\n liquidityOwner: PublicKey;\n nftOwner: PublicKey;\n nftMint: PublicKey;\n nftAccount: PublicKey;\n poolId: PublicKey;\n lockPda: PublicKey;\n mintLp: PublicKey;\n userLpVault: PublicKey;\n lockLpVault: PublicKey;\n poolVaultA: PublicKey;\n poolVaultB: PublicKey;\n metadataAccount: PublicKey;\n lpAmount: BN;\n withMetadata: boolean;\n}): TransactionInstruction {\n const keys = [\n { pubkey: auth, isSigner: false, isWritable: false },\n { pubkey: payer, isSigner: true, isWritable: true },\n { pubkey: liquidityOwner, isSigner: true, isWritable: false },\n { pubkey: nftOwner, isSigner: false, isWritable: false },\n { pubkey: nftMint, isSigner: true, isWritable: true },\n { pubkey: nftAccount, isSigner: false, isWritable: true },\n { pubkey: poolId, isSigner: false, isWritable: false },\n { pubkey: lockPda, isSigner: false, isWritable: true },\n { pubkey: mintLp, isSigner: false, isWritable: false },\n { pubkey: userLpVault, isSigner: false, isWritable: true },\n { pubkey: lockLpVault, isSigner: false, isWritable: true },\n { pubkey: poolVaultA, isSigner: false, isWritable: true },\n { pubkey: poolVaultB, isSigner: false, isWritable: true },\n { pubkey: metadataAccount, isSigner: false, isWritable: true },\n { pubkey: RENT_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: SystemProgram.programId, isSigner: false, isWritable: false },\n { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: METADATA_PROGRAM_ID, isSigner: false, isWritable: false },\n ];\n const dataLayout = struct([u64(\"lpAmount\"), bool(\"withMetadata\")]);\n const data = Buffer.alloc(dataLayout.span);\n dataLayout.encode(\n {\n lpAmount,\n withMetadata,\n },\n data,\n );\n const aData = Buffer.from([...anchorDataBuf.lockCpLiquidity, ...data]);\n return new TransactionInstruction({\n keys,\n programId,\n data: aData,\n });\n}\n\nexport function collectCpFeeInstruction({\n programId,\n nftOwner,\n auth,\n nftAccount,\n lockPda,\n poolId,\n mintLp,\n userVaultA,\n userVaultB,\n poolVaultA,\n poolVaultB,\n mintA,\n mintB,\n lockLpVault,\n lpFeeAmount,\n cpmmProgram,\n cpmmAuthProgram,\n}: {\n programId: PublicKey;\n nftOwner: PublicKey;\n auth: PublicKey;\n nftMint: PublicKey;\n nftAccount: PublicKey;\n lockPda: PublicKey;\n poolId: PublicKey;\n mintLp: PublicKey;\n userVaultA: PublicKey;\n userVaultB: PublicKey;\n poolVaultA: PublicKey;\n poolVaultB: PublicKey;\n mintA: PublicKey;\n mintB: PublicKey;\n lockLpVault: PublicKey;\n lpFeeAmount: BN;\n cpmmProgram?: PublicKey;\n cpmmAuthProgram?: PublicKey;\n}): TransactionInstruction {\n const keys = [\n { pubkey: auth, isSigner: false, isWritable: false },\n { pubkey: nftOwner, isSigner: true, isWritable: false },\n // { pubkey: nftMint, isSigner: false, isWritable: true },\n { pubkey: nftAccount, isSigner: false, isWritable: true },\n { pubkey: lockPda, isSigner: false, isWritable: true },\n { pubkey: cpmmProgram ?? CREATE_CPMM_POOL_PROGRAM, isSigner: false, isWritable: false },\n { pubkey: cpmmAuthProgram ?? CREATE_CPMM_POOL_AUTH, isSigner: false, isWritable: false },\n { pubkey: poolId, isSigner: false, isWritable: true },\n { pubkey: mintLp, isSigner: false, isWritable: true },\n { pubkey: userVaultA, isSigner: false, isWritable: true },\n { pubkey: userVaultB, isSigner: false, isWritable: true },\n { pubkey: poolVaultA, isSigner: false, isWritable: true },\n { pubkey: poolVaultB, isSigner: false, isWritable: true },\n { pubkey: mintA, isSigner: false, isWritable: false },\n { pubkey: mintB, isSigner: false, isWritable: false },\n { pubkey: lockLpVault, isSigner: false, isWritable: true },\n // { pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: TOKEN_2022_PROGRAM_ID, isSigner: false, isWritable: false },\n { pubkey: MEMO_PROGRAM_ID2, isSigner: false, isWritable: false },\n ];\n const dataLayout = struct([u64(\"lpFeeAmount\")]);\n const data = Buffer.alloc(dataLayout.span);\n dataLayout.encode(\n {\n lpFeeAmount,\n },\n data,\n );\n const aData = Buffer.from([...anchorDataBuf.collectCpFee, ...data]);\n return new TransactionInstruction({\n keys,\n programId,\n data: aData,\n });\n}\n","import { AccountInfo, Commitment, Connection, PublicKey } from \"@solana/web3.js\";\nimport { ReturnTypeFetchMultipleMintInfos } from \"../raydium/type\";\nimport { WSOLMint, chunkArray, solToWSol } from \"./\";\nimport { createLogger } from \"./logger\";\nimport { MINT_SIZE, TOKEN_PROGRAM_ID, getTransferFeeConfig, unpackMint } from \"@solana/spl-token\";\n\ninterface MultipleAccountsJsonRpcResponse {\n jsonrpc: string;\n id: string;\n error?: {\n code: number;\n message: string;\n };\n result: {\n context: { slot: number };\n value: { data: Array<string>; executable: boolean; lamports: number; owner: string; rentEpoch: number }[];\n };\n}\n\nexport interface GetMultipleAccountsInfoConfig {\n batchRequest?: boolean;\n commitment?: Commitment;\n chunkCount?: number;\n}\n\nconst logger = createLogger(\"Raydium_accountInfo_util\");\n\nexport async function getMultipleAccountsInfo(\n connection: Connection,\n publicKeys: PublicKey[],\n config?: GetMultipleAccountsInfoConfig,\n): Promise<(AccountInfo<Buffer> | null)[]> {\n const {\n batchRequest,\n commitment = \"confirmed\",\n chunkCount = 100,\n } = {\n batchRequest: false,\n ...config,\n };\n\n const chunkedKeys = chunkArray(publicKeys, chunkCount);\n let results: (AccountInfo<Buffer> | null)[][] = new Array(chunkedKeys.length).fill([]);\n\n if (batchRequest) {\n const batch = chunkedKeys.map((keys) => {\n const args = connection._buildArgs([keys.map((key) => key.toBase58())], commitment, \"base64\");\n return {\n methodName: \"getMultipleAccounts\",\n args,\n };\n });\n\n const _batch = chunkArray(batch, 10);\n\n const unsafeResponse: MultipleAccountsJsonRpcResponse[] = await (\n await Promise.all(_batch.map(async (i) => await (connection as any)._rpcBatchRequest(i)))\n ).flat();\n results = unsafeResponse.map((unsafeRes: MultipleAccountsJsonRpcResponse) => {\n if (unsafeRes.error)\n logger.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${unsafeRes.error.message}`);\n\n return unsafeRes.result.value.map((accountInfo) => {\n if (accountInfo) {\n const { data, executable, lamports, owner, rentEpoch } = accountInfo;\n\n if (data.length !== 2 && data[1] !== \"base64\") logger.logWithError(`info must be base64 encoded, RPC_ERROR`);\n\n return {\n data: Buffer.from(data[0], \"base64\"),\n executable,\n lamports,\n owner: new PublicKey(owner),\n rentEpoch,\n };\n }\n return null;\n });\n });\n } else {\n try {\n results = (await Promise.all(\n chunkedKeys.map((keys) => connection.getMultipleAccountsInfo(keys, commitment)),\n )) as (AccountInfo<Buffer> | null)[][];\n } catch (error) {\n if (error instanceof Error) {\n logger.logWithError(`failed to get info for multiple accounts, RPC_ERROR, ${error.message}`);\n }\n }\n }\n\n return results.flat();\n}\n\nexport async function getMultipleAccountsInfoWithCustomFlags<T extends { pubkey: PublicKey }>(\n connection: Connection,\n publicKeysWithCustomFlag: T[],\n config?: GetMultipleAccountsInfoConfig,\n): Promise<({ accountInfo: AccountInfo<Buffer> | null } & T)[]> {\n const multipleAccountsInfo = await getMultipleAccountsInfo(\n connection,\n publicKeysWithCustomFlag.map((o) => o.pubkey),\n config,\n );\n\n return publicKeysWithCustomFlag.map((o, idx) => ({ ...o, accountInfo: multipleAccountsInfo[idx] }));\n}\n\nexport enum AccountType {\n Uninitialized,\n Mint,\n Account,\n}\nexport const ACCOUNT_TYPE_SIZE = 1;\n\nexport async function fetchMultipleMintInfos({\n connection,\n mints,\n config,\n}: {\n connection: Connection;\n mints: PublicKey[];\n config?: { batchRequest?: boolean };\n}): Promise<ReturnTypeFetchMultipleMintInfos> {\n if (mints.length === 0) return {};\n const mintInfos = await getMultipleAccountsInfoWithCustomFlags(\n connection,\n mints.map((i) => ({ pubkey: solToWSol(i) })),\n config,\n );\n\n const mintK: ReturnTypeFetchMultipleMintInfos = {};\n for (const i of mintInfos) {\n if (!i.accountInfo || i.accountInfo.data.length < MINT_SIZE) {\n console.log(\"invalid mint account\", i.pubkey.toBase58());\n continue;\n }\n const t = unpackMint(i.pubkey, i.accountInfo, i.accountInfo?.owner);\n mintK[i.pubkey.toString()] = {\n ...t,\n programId: i.accountInfo?.owner || TOKEN_PROGRAM_ID,\n feeConfig: getTransferFeeConfig(t) ?? undefined,\n };\n }\n mintK[PublicKey.default.toBase58()] = mintK[WSOLMint.toBase58()];\n\n return mintK;\n}\n","import { get, set } from \"lodash\";\n\nexport type ModuleName = \"Common.Api\";\n\nexport enum LogLevel {\n Error,\n Warning,\n Info,\n Debug,\n}\nexport class Logger {\n private logLevel: LogLevel;\n private name: string;\n constructor(params: { name: string; logLevel?: LogLevel }) {\n this.logLevel = params.logLevel !== undefined ? params.logLevel : LogLevel.Error;\n this.name = params.name;\n }\n\n set level(logLevel: LogLevel) {\n this.logLevel = logLevel;\n }\n get time(): string {\n return Date.now().toString();\n }\n get moduleName(): string {\n return this.name;\n }\n\n private isLogLevel(level: LogLevel): boolean {\n return level <= this.logLevel;\n }\n\n public error(...props): Logger {\n if (!this.isLogLevel(LogLevel.Error)) return this;\n console.error(this.time, this.name, \"sdk logger error\", ...props);\n return this;\n }\n\n public logWithError(...props): Logger {\n // this.error(...props)\n const msg = props.map((arg) => (typeof arg === \"object\" ? JSON.stringify(arg) : arg)).join(\", \");\n throw new Error(msg);\n }\n\n public warning(...props): Logger {\n if (!this.isLogLevel(LogLevel.Warning)) return this;\n console.warn(this.time, this.name, \"sdk logger warning\", ...props);\n return this;\n }\n\n public info(...props): Logger {\n if (!this.isLogLevel(LogLevel.Info)) return this;\n console.info(this.time, this.name, \"sdk logger info\", ...props);\n return this;\n }\n\n public debug(...props): Logger {\n if (!this.isLogLevel(LogLevel.Debug)) return this;\n console.debug(this.time, this.name, \"sdk logger debug\", ...props);\n return this;\n }\n}\n\nconst moduleLoggers: { [key in ModuleName]?: Logger } = {};\nconst moduleLevels: { [key in ModuleName]?: LogLevel } = {};\n\nexport function createLogger(moduleName: string): Logger {\n let logger = get(moduleLoggers, moduleName);\n if (!logger) {\n // default level is error\n const logLevel = get(moduleLevels, moduleName);\n\n logger = new Logger({ name: moduleName, logLevel });\n set(moduleLoggers, moduleName, logger);\n }\n\n return logger;\n}\n\nexport function setLoggerLevel(moduleName: string, level: LogLevel): void {\n set(moduleLevels, moduleName, level);\n\n const logger = get(moduleLoggers, moduleName);\n if (logger) logger.level = level;\n}\n","import BN from \"bn.js\";\nimport Decimal from \"decimal.js\";\nimport { CurrencyAmount, TokenAmount } from \"../module/amount\";\nimport { Currency } from \"../module/currency\";\nimport { Fraction } from \"../module/fraction\";\nimport { Percent } from \"../module/percent\";\nimport { Price } from \"../module/price\";\nimport { Token } from \"../module/token\";\nimport { SplToken, TokenJson } from \"../raydium/token/type\";\nimport { ReplaceType } from \"../raydium/type\";\nimport { parseBigNumberish } from \"./constant\";\nimport { mul } from \"./fractionUtil\";\nimport { notInnerObject } from \"./utility\";\n\nexport const BN_ZERO = new BN(0);\nexport const BN_ONE = new BN(1);\nexport const BN_TWO = new BN(2);\nexport const BN_THREE = new BN(3);\nexport const BN_FIVE = new BN(5);\nexport const BN_TEN = new BN(10);\nexport const BN_100 = new BN(100);\nexport const BN_1000 = new BN(1000);\nexport const BN_10000 = new BN(10000);\nexport type BigNumberish = BN | string | number | bigint;\nexport type Numberish = number | string | bigint | Fraction | BN;\n\nexport function tenExponential(shift: BigNumberish): BN {\n return BN_TEN.pow(parseBigNumberish(shift));\n}\n\n/**\n *\n * @example\n * getIntInfo(0.34) => { numerator: '34', denominator: '100'}\n * getIntInfo('0.34') //=> { numerator: '34', denominator: '100'}\n */\nexport function parseNumberInfo(n: Numberish | undefined): {\n denominator: string;\n numerator: string;\n sign?: string;\n int?: string;\n dec?: string;\n} {\n if (n === undefined) return { denominator: \"1\", numerator: \"0\" };\n if (n instanceof BN) {\n