Skip to content

Commit

Permalink
Update whirlpool test program + codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotkennedy committed Jul 27, 2024
1 parent a2a4393 commit c2da05b
Show file tree
Hide file tree
Showing 76 changed files with 3,382 additions and 946 deletions.
Binary file modified deps/whirlpool.so
Binary file not shown.
13 changes: 1 addition & 12 deletions packages/kamino-sdk/src/Kamino.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ import {
ProfiledFunctionExecution,
noopProfiledFunctionExecution,
MaybeTokensBalances,
ProportionalMintingMethod,
PerformanceFees,
PriceReferenceType,
InputRebalanceFieldInfo,
Expand Down Expand Up @@ -199,25 +198,16 @@ import {
import { signTerms, SignTermsAccounts, SignTermsArgs } from './kamino-client/instructions';
import { Pool } from './services/RaydiumPoolsResponse';
import {
UpdateDepositCap,
UpdateDepositCapIxn,
UpdateWithdrawFee,
UpdateDepositFee,
UpdateReward0Fee,
UpdateReward1Fee,
UpdateReward2Fee,
UpdateCollectFeesFee,
UpdateRebalanceType,
UpdateLookupTable,
UpdateDepositMintingMethod,
UpdateReferencePriceType,
} from './kamino-client/types/StrategyConfigOption';
import {
DefaultDepositCap,
DefaultDepositCapPerIx,
DefaultPerformanceFeeBps,
DefaultWithdrawFeeBps,
} from './constants/DefaultStrategyConfig';
import { DefaultPerformanceFeeBps } from './constants/DefaultStrategyConfig';
import {
ADDRESS_LUT_PROGRAM_ID,
CONSENSUS_ID,
Expand Down Expand Up @@ -348,7 +338,6 @@ import {
getBinFromBinArray,
getBinFromBinArrays,
getBinIdFromPriceWithDecimals,
getPriceOfBinByBinId,
getPriceOfBinByBinIdWithDecimals,
MeteoraPosition,
} from './utils/meteora';
Expand Down
90 changes: 50 additions & 40 deletions packages/kamino-sdk/src/whirpools-client/accounts/FeeTier.ts
Original file line number Diff line number Diff line change
@@ -1,95 +1,105 @@
import { PublicKey, Connection } from '@solana/web3.js';
import BN from 'bn.js'; // eslint-disable-line @typescript-eslint/no-unused-vars
import * as borsh from '@project-serum/borsh'; // eslint-disable-line @typescript-eslint/no-unused-vars
import * as types from '../types'; // eslint-disable-line @typescript-eslint/no-unused-vars
import { WHIRLPOOL_PROGRAM_ID } from '../programId';
import { PublicKey, Connection } from "@solana/web3.js"
import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
import * as borsh from "@coral-xyz/borsh" // eslint-disable-line @typescript-eslint/no-unused-vars
import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
import { WHIRLPOOL_PROGRAM_ID } from "../programId"

export interface FeeTierFields {
whirlpoolsConfig: PublicKey;
tickSpacing: number;
defaultFeeRate: number;
whirlpoolsConfig: PublicKey
tickSpacing: number
defaultFeeRate: number
}

export interface FeeTierJSON {
whirlpoolsConfig: string;
tickSpacing: number;
defaultFeeRate: number;
whirlpoolsConfig: string
tickSpacing: number
defaultFeeRate: number
}

export class FeeTier {
readonly whirlpoolsConfig: PublicKey;
readonly tickSpacing: number;
readonly defaultFeeRate: number;
readonly whirlpoolsConfig: PublicKey
readonly tickSpacing: number
readonly defaultFeeRate: number

static readonly discriminator = Buffer.from([56, 75, 159, 76, 142, 68, 190, 105]);
static readonly discriminator = Buffer.from([
56, 75, 159, 76, 142, 68, 190, 105,
])

static readonly layout = borsh.struct([
borsh.publicKey('whirlpoolsConfig'),
borsh.u16('tickSpacing'),
borsh.u16('defaultFeeRate'),
]);
borsh.publicKey("whirlpoolsConfig"),
borsh.u16("tickSpacing"),
borsh.u16("defaultFeeRate"),
])

constructor(fields: FeeTierFields) {
this.whirlpoolsConfig = fields.whirlpoolsConfig;
this.tickSpacing = fields.tickSpacing;
this.defaultFeeRate = fields.defaultFeeRate;
this.whirlpoolsConfig = fields.whirlpoolsConfig
this.tickSpacing = fields.tickSpacing
this.defaultFeeRate = fields.defaultFeeRate
}

static async fetch(c: Connection, address: PublicKey): Promise<FeeTier | null> {
const info = await c.getAccountInfo(address);
static async fetch(
c: Connection,
address: PublicKey,
programId: PublicKey = WHIRLPOOL_PROGRAM_ID
): Promise<FeeTier | null> {
const info = await c.getAccountInfo(address)

if (info === null) {
return null;
return null
}
if (!info.owner.equals(WHIRLPOOL_PROGRAM_ID)) {
throw new Error("account doesn't belong to this program");
if (!info.owner.equals(programId)) {
throw new Error("account doesn't belong to this program")
}

return this.decode(info.data);
return this.decode(info.data)
}

static async fetchMultiple(c: Connection, addresses: PublicKey[]): Promise<Array<FeeTier | null>> {
const infos = await c.getMultipleAccountsInfo(addresses);
static async fetchMultiple(
c: Connection,
addresses: PublicKey[],
programId: PublicKey = WHIRLPOOL_PROGRAM_ID
): Promise<Array<FeeTier | null>> {
const infos = await c.getMultipleAccountsInfo(addresses)

return infos.map((info) => {
if (info === null) {
return null;
return null
}
if (!info.owner.equals(WHIRLPOOL_PROGRAM_ID)) {
throw new Error("account doesn't belong to this program");
if (!info.owner.equals(programId)) {
throw new Error("account doesn't belong to this program")
}

return this.decode(info.data);
});
return this.decode(info.data)
})
}

static decode(data: Buffer): FeeTier {
if (!data.slice(0, 8).equals(FeeTier.discriminator)) {
throw new Error('invalid account discriminator');
throw new Error("invalid account discriminator")
}

const dec = FeeTier.layout.decode(data.slice(8));
const dec = FeeTier.layout.decode(data.slice(8))

return new FeeTier({
whirlpoolsConfig: dec.whirlpoolsConfig,
tickSpacing: dec.tickSpacing,
defaultFeeRate: dec.defaultFeeRate,
});
})
}

toJSON(): FeeTierJSON {
return {
whirlpoolsConfig: this.whirlpoolsConfig.toString(),
tickSpacing: this.tickSpacing,
defaultFeeRate: this.defaultFeeRate,
};
}
}

static fromJSON(obj: FeeTierJSON): FeeTier {
return new FeeTier({
whirlpoolsConfig: new PublicKey(obj.whirlpoolsConfig),
tickSpacing: obj.tickSpacing,
defaultFeeRate: obj.defaultFeeRate,
});
})
}
}
Loading

0 comments on commit c2da05b

Please sign in to comment.