diff --git a/deps/whirlpool.so b/deps/whirlpool.so index 6cd75cc7..21b0c2fc 100644 Binary files a/deps/whirlpool.so and b/deps/whirlpool.so differ diff --git a/packages/kamino-sdk/src/Kamino.ts b/packages/kamino-sdk/src/Kamino.ts index 04017fc9..e7c8ef60 100644 --- a/packages/kamino-sdk/src/Kamino.ts +++ b/packages/kamino-sdk/src/Kamino.ts @@ -106,7 +106,6 @@ import { ProfiledFunctionExecution, noopProfiledFunctionExecution, MaybeTokensBalances, - ProportionalMintingMethod, PerformanceFees, PriceReferenceType, InputRebalanceFieldInfo, @@ -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, @@ -348,7 +338,6 @@ import { getBinFromBinArray, getBinFromBinArrays, getBinIdFromPriceWithDecimals, - getPriceOfBinByBinId, getPriceOfBinByBinIdWithDecimals, MeteoraPosition, } from './utils/meteora'; diff --git a/packages/kamino-sdk/src/whirpools-client/accounts/FeeTier.ts b/packages/kamino-sdk/src/whirpools-client/accounts/FeeTier.ts index f4b50dc4..a7ea3dd9 100644 --- a/packages/kamino-sdk/src/whirpools-client/accounts/FeeTier.ts +++ b/packages/kamino-sdk/src/whirpools-client/accounts/FeeTier.ts @@ -1,80 +1,90 @@ -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 { - const info = await c.getAccountInfo(address); + static async fetch( + c: Connection, + address: PublicKey, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID + ): Promise { + 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> { - const infos = await c.getMultipleAccountsInfo(addresses); + static async fetchMultiple( + c: Connection, + addresses: PublicKey[], + programId: PublicKey = WHIRLPOOL_PROGRAM_ID + ): Promise> { + 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 { @@ -82,7 +92,7 @@ export class FeeTier { whirlpoolsConfig: this.whirlpoolsConfig.toString(), tickSpacing: this.tickSpacing, defaultFeeRate: this.defaultFeeRate, - }; + } } static fromJSON(obj: FeeTierJSON): FeeTier { @@ -90,6 +100,6 @@ export class FeeTier { whirlpoolsConfig: new PublicKey(obj.whirlpoolsConfig), tickSpacing: obj.tickSpacing, defaultFeeRate: obj.defaultFeeRate, - }); + }) } } diff --git a/packages/kamino-sdk/src/whirpools-client/accounts/Position.ts b/packages/kamino-sdk/src/whirpools-client/accounts/Position.ts index 18de3a17..f934ddb3 100644 --- a/packages/kamino-sdk/src/whirpools-client/accounts/Position.ts +++ b/packages/kamino-sdk/src/whirpools-client/accounts/Position.ts @@ -1,109 +1,121 @@ -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 PositionFields { - whirlpool: PublicKey; - positionMint: PublicKey; - liquidity: BN; - tickLowerIndex: number; - tickUpperIndex: number; - feeGrowthCheckpointA: BN; - feeOwedA: BN; - feeGrowthCheckpointB: BN; - feeOwedB: BN; - rewardInfos: Array; + whirlpool: PublicKey + positionMint: PublicKey + liquidity: BN + tickLowerIndex: number + tickUpperIndex: number + feeGrowthCheckpointA: BN + feeOwedA: BN + feeGrowthCheckpointB: BN + feeOwedB: BN + rewardInfos: Array } export interface PositionJSON { - whirlpool: string; - positionMint: string; - liquidity: string; - tickLowerIndex: number; - tickUpperIndex: number; - feeGrowthCheckpointA: string; - feeOwedA: string; - feeGrowthCheckpointB: string; - feeOwedB: string; - rewardInfos: Array; + whirlpool: string + positionMint: string + liquidity: string + tickLowerIndex: number + tickUpperIndex: number + feeGrowthCheckpointA: string + feeOwedA: string + feeGrowthCheckpointB: string + feeOwedB: string + rewardInfos: Array } export class Position { - readonly whirlpool: PublicKey; - readonly positionMint: PublicKey; - readonly liquidity: BN; - readonly tickLowerIndex: number; - readonly tickUpperIndex: number; - readonly feeGrowthCheckpointA: BN; - readonly feeOwedA: BN; - readonly feeGrowthCheckpointB: BN; - readonly feeOwedB: BN; - readonly rewardInfos: Array; - - static readonly discriminator = Buffer.from([170, 188, 143, 228, 122, 64, 247, 208]); + readonly whirlpool: PublicKey + readonly positionMint: PublicKey + readonly liquidity: BN + readonly tickLowerIndex: number + readonly tickUpperIndex: number + readonly feeGrowthCheckpointA: BN + readonly feeOwedA: BN + readonly feeGrowthCheckpointB: BN + readonly feeOwedB: BN + readonly rewardInfos: Array + + static readonly discriminator = Buffer.from([ + 170, 188, 143, 228, 122, 64, 247, 208, + ]) static readonly layout = borsh.struct([ - borsh.publicKey('whirlpool'), - borsh.publicKey('positionMint'), - borsh.u128('liquidity'), - borsh.i32('tickLowerIndex'), - borsh.i32('tickUpperIndex'), - borsh.u128('feeGrowthCheckpointA'), - borsh.u64('feeOwedA'), - borsh.u128('feeGrowthCheckpointB'), - borsh.u64('feeOwedB'), - borsh.array(types.PositionRewardInfo.layout(), 3, 'rewardInfos'), - ]); + borsh.publicKey("whirlpool"), + borsh.publicKey("positionMint"), + borsh.u128("liquidity"), + borsh.i32("tickLowerIndex"), + borsh.i32("tickUpperIndex"), + borsh.u128("feeGrowthCheckpointA"), + borsh.u64("feeOwedA"), + borsh.u128("feeGrowthCheckpointB"), + borsh.u64("feeOwedB"), + borsh.array(types.PositionRewardInfo.layout(), 3, "rewardInfos"), + ]) constructor(fields: PositionFields) { - this.whirlpool = fields.whirlpool; - this.positionMint = fields.positionMint; - this.liquidity = fields.liquidity; - this.tickLowerIndex = fields.tickLowerIndex; - this.tickUpperIndex = fields.tickUpperIndex; - this.feeGrowthCheckpointA = fields.feeGrowthCheckpointA; - this.feeOwedA = fields.feeOwedA; - this.feeGrowthCheckpointB = fields.feeGrowthCheckpointB; - this.feeOwedB = fields.feeOwedB; - this.rewardInfos = fields.rewardInfos.map((item) => new types.PositionRewardInfo({ ...item })); + this.whirlpool = fields.whirlpool + this.positionMint = fields.positionMint + this.liquidity = fields.liquidity + this.tickLowerIndex = fields.tickLowerIndex + this.tickUpperIndex = fields.tickUpperIndex + this.feeGrowthCheckpointA = fields.feeGrowthCheckpointA + this.feeOwedA = fields.feeOwedA + this.feeGrowthCheckpointB = fields.feeGrowthCheckpointB + this.feeOwedB = fields.feeOwedB + this.rewardInfos = fields.rewardInfos.map( + (item) => new types.PositionRewardInfo({ ...item }) + ) } - static async fetch(c: Connection, address: PublicKey): Promise { - const info = await c.getAccountInfo(address); + static async fetch( + c: Connection, + address: PublicKey, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID + ): Promise { + 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> { - const infos = await c.getMultipleAccountsInfo(addresses); + static async fetchMultiple( + c: Connection, + addresses: PublicKey[], + programId: PublicKey = WHIRLPOOL_PROGRAM_ID + ): Promise> { + 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): Position { if (!data.slice(0, 8).equals(Position.discriminator)) { - throw new Error('invalid account discriminator'); + throw new Error("invalid account discriminator") } - const dec = Position.layout.decode(data.slice(8)); + const dec = Position.layout.decode(data.slice(8)) return new Position({ whirlpool: dec.whirlpool, @@ -115,10 +127,12 @@ export class Position { feeOwedA: dec.feeOwedA, feeGrowthCheckpointB: dec.feeGrowthCheckpointB, feeOwedB: dec.feeOwedB, - rewardInfos: dec.rewardInfos.map((item: any /* eslint-disable-line @typescript-eslint/no-explicit-any */) => - types.PositionRewardInfo.fromDecoded(item) + rewardInfos: dec.rewardInfos.map( + ( + item: any /* eslint-disable-line @typescript-eslint/no-explicit-any */ + ) => types.PositionRewardInfo.fromDecoded(item) ), - }); + }) } toJSON(): PositionJSON { @@ -133,7 +147,7 @@ export class Position { feeGrowthCheckpointB: this.feeGrowthCheckpointB.toString(), feeOwedB: this.feeOwedB.toString(), rewardInfos: this.rewardInfos.map((item) => item.toJSON()), - }; + } } static fromJSON(obj: PositionJSON): Position { @@ -147,7 +161,9 @@ export class Position { feeOwedA: new BN(obj.feeOwedA), feeGrowthCheckpointB: new BN(obj.feeGrowthCheckpointB), feeOwedB: new BN(obj.feeOwedB), - rewardInfos: obj.rewardInfos.map((item) => types.PositionRewardInfo.fromJSON(item)), - }); + rewardInfos: obj.rewardInfos.map((item) => + types.PositionRewardInfo.fromJSON(item) + ), + }) } } diff --git a/packages/kamino-sdk/src/whirpools-client/accounts/PositionBundle.ts b/packages/kamino-sdk/src/whirpools-client/accounts/PositionBundle.ts new file mode 100644 index 00000000..ff076dc2 --- /dev/null +++ b/packages/kamino-sdk/src/whirpools-client/accounts/PositionBundle.ts @@ -0,0 +1,97 @@ +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 PositionBundleFields { + positionBundleMint: PublicKey + positionBitmap: Array +} + +export interface PositionBundleJSON { + positionBundleMint: string + positionBitmap: Array +} + +export class PositionBundle { + readonly positionBundleMint: PublicKey + readonly positionBitmap: Array + + static readonly discriminator = Buffer.from([ + 129, 169, 175, 65, 185, 95, 32, 100, + ]) + + static readonly layout = borsh.struct([ + borsh.publicKey("positionBundleMint"), + borsh.array(borsh.u8(), 32, "positionBitmap"), + ]) + + constructor(fields: PositionBundleFields) { + this.positionBundleMint = fields.positionBundleMint + this.positionBitmap = fields.positionBitmap + } + + static async fetch( + c: Connection, + address: PublicKey, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID + ): Promise { + const info = await c.getAccountInfo(address) + + if (info === null) { + return null + } + if (!info.owner.equals(programId)) { + throw new Error("account doesn't belong to this program") + } + + return this.decode(info.data) + } + + static async fetchMultiple( + c: Connection, + addresses: PublicKey[], + programId: PublicKey = WHIRLPOOL_PROGRAM_ID + ): Promise> { + const infos = await c.getMultipleAccountsInfo(addresses) + + return infos.map((info) => { + if (info === null) { + return null + } + if (!info.owner.equals(programId)) { + throw new Error("account doesn't belong to this program") + } + + return this.decode(info.data) + }) + } + + static decode(data: Buffer): PositionBundle { + if (!data.slice(0, 8).equals(PositionBundle.discriminator)) { + throw new Error("invalid account discriminator") + } + + const dec = PositionBundle.layout.decode(data.slice(8)) + + return new PositionBundle({ + positionBundleMint: dec.positionBundleMint, + positionBitmap: dec.positionBitmap, + }) + } + + toJSON(): PositionBundleJSON { + return { + positionBundleMint: this.positionBundleMint.toString(), + positionBitmap: this.positionBitmap, + } + } + + static fromJSON(obj: PositionBundleJSON): PositionBundle { + return new PositionBundle({ + positionBundleMint: new PublicKey(obj.positionBundleMint), + positionBitmap: obj.positionBitmap, + }) + } +} diff --git a/packages/kamino-sdk/src/whirpools-client/accounts/TickArray.ts b/packages/kamino-sdk/src/whirpools-client/accounts/TickArray.ts index f51dccd2..5aad80fc 100644 --- a/packages/kamino-sdk/src/whirpools-client/accounts/TickArray.ts +++ b/packages/kamino-sdk/src/whirpools-client/accounts/TickArray.ts @@ -1,82 +1,94 @@ -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 TickArrayFields { - startTickIndex: number; - ticks: Array; - whirlpool: PublicKey; + startTickIndex: number + ticks: Array + whirlpool: PublicKey } export interface TickArrayJSON { - startTickIndex: number; - ticks: Array; - whirlpool: string; + startTickIndex: number + ticks: Array + whirlpool: string } export class TickArray { - readonly startTickIndex: number; - readonly ticks: Array; - readonly whirlpool: PublicKey; + readonly startTickIndex: number + readonly ticks: Array + readonly whirlpool: PublicKey - static readonly discriminator = Buffer.from([69, 97, 189, 190, 110, 7, 66, 187]); + static readonly discriminator = Buffer.from([ + 69, 97, 189, 190, 110, 7, 66, 187, + ]) static readonly layout = borsh.struct([ - borsh.i32('startTickIndex'), - borsh.array(types.Tick.layout(), 88, 'ticks'), - borsh.publicKey('whirlpool'), - ]); + borsh.i32("startTickIndex"), + borsh.array(types.Tick.layout(), 88, "ticks"), + borsh.publicKey("whirlpool"), + ]) constructor(fields: TickArrayFields) { - this.startTickIndex = fields.startTickIndex; - this.ticks = fields.ticks.map((item) => new types.Tick({ ...item })); - this.whirlpool = fields.whirlpool; + this.startTickIndex = fields.startTickIndex + this.ticks = fields.ticks.map((item) => new types.Tick({ ...item })) + this.whirlpool = fields.whirlpool } - static async fetch(c: Connection, address: PublicKey): Promise { - const info = await c.getAccountInfo(address); + static async fetch( + c: Connection, + address: PublicKey, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID + ): Promise { + 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> { - const infos = await c.getMultipleAccountsInfo(addresses); + static async fetchMultiple( + c: Connection, + addresses: PublicKey[], + programId: PublicKey = WHIRLPOOL_PROGRAM_ID + ): Promise> { + 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): TickArray { if (!data.slice(0, 8).equals(TickArray.discriminator)) { - throw new Error('invalid account discriminator'); + throw new Error("invalid account discriminator") } - const dec = TickArray.layout.decode(data.slice(8)); + const dec = TickArray.layout.decode(data.slice(8)) return new TickArray({ startTickIndex: dec.startTickIndex, - ticks: dec.ticks.map((item: any /* eslint-disable-line @typescript-eslint/no-explicit-any */) => - types.Tick.fromDecoded(item) + ticks: dec.ticks.map( + ( + item: any /* eslint-disable-line @typescript-eslint/no-explicit-any */ + ) => types.Tick.fromDecoded(item) ), whirlpool: dec.whirlpool, - }); + }) } toJSON(): TickArrayJSON { @@ -84,7 +96,7 @@ export class TickArray { startTickIndex: this.startTickIndex, ticks: this.ticks.map((item) => item.toJSON()), whirlpool: this.whirlpool.toString(), - }; + } } static fromJSON(obj: TickArrayJSON): TickArray { @@ -92,6 +104,6 @@ export class TickArray { startTickIndex: obj.startTickIndex, ticks: obj.ticks.map((item) => types.Tick.fromJSON(item)), whirlpool: new PublicKey(obj.whirlpool), - }); + }) } } diff --git a/packages/kamino-sdk/src/whirpools-client/accounts/TokenBadge.ts b/packages/kamino-sdk/src/whirpools-client/accounts/TokenBadge.ts new file mode 100644 index 00000000..1fa4937f --- /dev/null +++ b/packages/kamino-sdk/src/whirpools-client/accounts/TokenBadge.ts @@ -0,0 +1,97 @@ +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 TokenBadgeFields { + whirlpoolsConfig: PublicKey + tokenMint: PublicKey +} + +export interface TokenBadgeJSON { + whirlpoolsConfig: string + tokenMint: string +} + +export class TokenBadge { + readonly whirlpoolsConfig: PublicKey + readonly tokenMint: PublicKey + + static readonly discriminator = Buffer.from([ + 116, 219, 204, 229, 249, 116, 255, 150, + ]) + + static readonly layout = borsh.struct([ + borsh.publicKey("whirlpoolsConfig"), + borsh.publicKey("tokenMint"), + ]) + + constructor(fields: TokenBadgeFields) { + this.whirlpoolsConfig = fields.whirlpoolsConfig + this.tokenMint = fields.tokenMint + } + + static async fetch( + c: Connection, + address: PublicKey, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID + ): Promise { + const info = await c.getAccountInfo(address) + + if (info === null) { + return null + } + if (!info.owner.equals(programId)) { + throw new Error("account doesn't belong to this program") + } + + return this.decode(info.data) + } + + static async fetchMultiple( + c: Connection, + addresses: PublicKey[], + programId: PublicKey = WHIRLPOOL_PROGRAM_ID + ): Promise> { + const infos = await c.getMultipleAccountsInfo(addresses) + + return infos.map((info) => { + if (info === null) { + return null + } + if (!info.owner.equals(programId)) { + throw new Error("account doesn't belong to this program") + } + + return this.decode(info.data) + }) + } + + static decode(data: Buffer): TokenBadge { + if (!data.slice(0, 8).equals(TokenBadge.discriminator)) { + throw new Error("invalid account discriminator") + } + + const dec = TokenBadge.layout.decode(data.slice(8)) + + return new TokenBadge({ + whirlpoolsConfig: dec.whirlpoolsConfig, + tokenMint: dec.tokenMint, + }) + } + + toJSON(): TokenBadgeJSON { + return { + whirlpoolsConfig: this.whirlpoolsConfig.toString(), + tokenMint: this.tokenMint.toString(), + } + } + + static fromJSON(obj: TokenBadgeJSON): TokenBadge { + return new TokenBadge({ + whirlpoolsConfig: new PublicKey(obj.whirlpoolsConfig), + tokenMint: new PublicKey(obj.tokenMint), + }) + } +} diff --git a/packages/kamino-sdk/src/whirpools-client/accounts/Whirlpool.ts b/packages/kamino-sdk/src/whirpools-client/accounts/Whirlpool.ts index da2e927e..110fbc60 100644 --- a/packages/kamino-sdk/src/whirpools-client/accounts/Whirlpool.ts +++ b/packages/kamino-sdk/src/whirpools-client/accounts/Whirlpool.ts @@ -1,154 +1,166 @@ -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 WhirlpoolFields { - whirlpoolsConfig: PublicKey; - whirlpoolBump: Array; - tickSpacing: number; - tickSpacingSeed: Array; - feeRate: number; - protocolFeeRate: number; - liquidity: BN; - sqrtPrice: BN; - tickCurrentIndex: number; - protocolFeeOwedA: BN; - protocolFeeOwedB: BN; - tokenMintA: PublicKey; - tokenVaultA: PublicKey; - feeGrowthGlobalA: BN; - tokenMintB: PublicKey; - tokenVaultB: PublicKey; - feeGrowthGlobalB: BN; - rewardLastUpdatedTimestamp: BN; - rewardInfos: Array; + whirlpoolsConfig: PublicKey + whirlpoolBump: Array + tickSpacing: number + tickSpacingSeed: Array + feeRate: number + protocolFeeRate: number + liquidity: BN + sqrtPrice: BN + tickCurrentIndex: number + protocolFeeOwedA: BN + protocolFeeOwedB: BN + tokenMintA: PublicKey + tokenVaultA: PublicKey + feeGrowthGlobalA: BN + tokenMintB: PublicKey + tokenVaultB: PublicKey + feeGrowthGlobalB: BN + rewardLastUpdatedTimestamp: BN + rewardInfos: Array } export interface WhirlpoolJSON { - whirlpoolsConfig: string; - whirlpoolBump: Array; - tickSpacing: number; - tickSpacingSeed: Array; - feeRate: number; - protocolFeeRate: number; - liquidity: string; - sqrtPrice: string; - tickCurrentIndex: number; - protocolFeeOwedA: string; - protocolFeeOwedB: string; - tokenMintA: string; - tokenVaultA: string; - feeGrowthGlobalA: string; - tokenMintB: string; - tokenVaultB: string; - feeGrowthGlobalB: string; - rewardLastUpdatedTimestamp: string; - rewardInfos: Array; + whirlpoolsConfig: string + whirlpoolBump: Array + tickSpacing: number + tickSpacingSeed: Array + feeRate: number + protocolFeeRate: number + liquidity: string + sqrtPrice: string + tickCurrentIndex: number + protocolFeeOwedA: string + protocolFeeOwedB: string + tokenMintA: string + tokenVaultA: string + feeGrowthGlobalA: string + tokenMintB: string + tokenVaultB: string + feeGrowthGlobalB: string + rewardLastUpdatedTimestamp: string + rewardInfos: Array } export class Whirlpool { - readonly whirlpoolsConfig: PublicKey; - readonly whirlpoolBump: Array; - readonly tickSpacing: number; - readonly tickSpacingSeed: Array; - readonly feeRate: number; - readonly protocolFeeRate: number; - readonly liquidity: BN; - readonly sqrtPrice: BN; - readonly tickCurrentIndex: number; - readonly protocolFeeOwedA: BN; - readonly protocolFeeOwedB: BN; - readonly tokenMintA: PublicKey; - readonly tokenVaultA: PublicKey; - readonly feeGrowthGlobalA: BN; - readonly tokenMintB: PublicKey; - readonly tokenVaultB: PublicKey; - readonly feeGrowthGlobalB: BN; - readonly rewardLastUpdatedTimestamp: BN; - readonly rewardInfos: Array; - - static readonly discriminator = Buffer.from([63, 149, 209, 12, 225, 128, 99, 9]); + readonly whirlpoolsConfig: PublicKey + readonly whirlpoolBump: Array + readonly tickSpacing: number + readonly tickSpacingSeed: Array + readonly feeRate: number + readonly protocolFeeRate: number + readonly liquidity: BN + readonly sqrtPrice: BN + readonly tickCurrentIndex: number + readonly protocolFeeOwedA: BN + readonly protocolFeeOwedB: BN + readonly tokenMintA: PublicKey + readonly tokenVaultA: PublicKey + readonly feeGrowthGlobalA: BN + readonly tokenMintB: PublicKey + readonly tokenVaultB: PublicKey + readonly feeGrowthGlobalB: BN + readonly rewardLastUpdatedTimestamp: BN + readonly rewardInfos: Array + + static readonly discriminator = Buffer.from([ + 63, 149, 209, 12, 225, 128, 99, 9, + ]) static readonly layout = borsh.struct([ - borsh.publicKey('whirlpoolsConfig'), - borsh.array(borsh.u8(), 1, 'whirlpoolBump'), - borsh.u16('tickSpacing'), - borsh.array(borsh.u8(), 2, 'tickSpacingSeed'), - borsh.u16('feeRate'), - borsh.u16('protocolFeeRate'), - borsh.u128('liquidity'), - borsh.u128('sqrtPrice'), - borsh.i32('tickCurrentIndex'), - borsh.u64('protocolFeeOwedA'), - borsh.u64('protocolFeeOwedB'), - borsh.publicKey('tokenMintA'), - borsh.publicKey('tokenVaultA'), - borsh.u128('feeGrowthGlobalA'), - borsh.publicKey('tokenMintB'), - borsh.publicKey('tokenVaultB'), - borsh.u128('feeGrowthGlobalB'), - borsh.u64('rewardLastUpdatedTimestamp'), - borsh.array(types.WhirlpoolRewardInfo.layout(), 3, 'rewardInfos'), - ]); + borsh.publicKey("whirlpoolsConfig"), + borsh.array(borsh.u8(), 1, "whirlpoolBump"), + borsh.u16("tickSpacing"), + borsh.array(borsh.u8(), 2, "tickSpacingSeed"), + borsh.u16("feeRate"), + borsh.u16("protocolFeeRate"), + borsh.u128("liquidity"), + borsh.u128("sqrtPrice"), + borsh.i32("tickCurrentIndex"), + borsh.u64("protocolFeeOwedA"), + borsh.u64("protocolFeeOwedB"), + borsh.publicKey("tokenMintA"), + borsh.publicKey("tokenVaultA"), + borsh.u128("feeGrowthGlobalA"), + borsh.publicKey("tokenMintB"), + borsh.publicKey("tokenVaultB"), + borsh.u128("feeGrowthGlobalB"), + borsh.u64("rewardLastUpdatedTimestamp"), + borsh.array(types.WhirlpoolRewardInfo.layout(), 3, "rewardInfos"), + ]) constructor(fields: WhirlpoolFields) { - this.whirlpoolsConfig = fields.whirlpoolsConfig; - this.whirlpoolBump = fields.whirlpoolBump; - this.tickSpacing = fields.tickSpacing; - this.tickSpacingSeed = fields.tickSpacingSeed; - this.feeRate = fields.feeRate; - this.protocolFeeRate = fields.protocolFeeRate; - this.liquidity = fields.liquidity; - this.sqrtPrice = fields.sqrtPrice; - this.tickCurrentIndex = fields.tickCurrentIndex; - this.protocolFeeOwedA = fields.protocolFeeOwedA; - this.protocolFeeOwedB = fields.protocolFeeOwedB; - this.tokenMintA = fields.tokenMintA; - this.tokenVaultA = fields.tokenVaultA; - this.feeGrowthGlobalA = fields.feeGrowthGlobalA; - this.tokenMintB = fields.tokenMintB; - this.tokenVaultB = fields.tokenVaultB; - this.feeGrowthGlobalB = fields.feeGrowthGlobalB; - this.rewardLastUpdatedTimestamp = fields.rewardLastUpdatedTimestamp; - this.rewardInfos = fields.rewardInfos.map((item) => new types.WhirlpoolRewardInfo({ ...item })); + this.whirlpoolsConfig = fields.whirlpoolsConfig + this.whirlpoolBump = fields.whirlpoolBump + this.tickSpacing = fields.tickSpacing + this.tickSpacingSeed = fields.tickSpacingSeed + this.feeRate = fields.feeRate + this.protocolFeeRate = fields.protocolFeeRate + this.liquidity = fields.liquidity + this.sqrtPrice = fields.sqrtPrice + this.tickCurrentIndex = fields.tickCurrentIndex + this.protocolFeeOwedA = fields.protocolFeeOwedA + this.protocolFeeOwedB = fields.protocolFeeOwedB + this.tokenMintA = fields.tokenMintA + this.tokenVaultA = fields.tokenVaultA + this.feeGrowthGlobalA = fields.feeGrowthGlobalA + this.tokenMintB = fields.tokenMintB + this.tokenVaultB = fields.tokenVaultB + this.feeGrowthGlobalB = fields.feeGrowthGlobalB + this.rewardLastUpdatedTimestamp = fields.rewardLastUpdatedTimestamp + this.rewardInfos = fields.rewardInfos.map( + (item) => new types.WhirlpoolRewardInfo({ ...item }) + ) } - static async fetch(c: Connection, address: PublicKey): Promise { - const info = await c.getAccountInfo(address); + static async fetch( + c: Connection, + address: PublicKey, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID + ): Promise { + 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> { - const infos = await c.getMultipleAccountsInfo(addresses); + static async fetchMultiple( + c: Connection, + addresses: PublicKey[], + programId: PublicKey = WHIRLPOOL_PROGRAM_ID + ): Promise> { + 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): Whirlpool { if (!data.slice(0, 8).equals(Whirlpool.discriminator)) { - throw new Error('invalid account discriminator'); + throw new Error("invalid account discriminator") } - const dec = Whirlpool.layout.decode(data.slice(8)); + const dec = Whirlpool.layout.decode(data.slice(8)) return new Whirlpool({ whirlpoolsConfig: dec.whirlpoolsConfig, @@ -169,10 +181,12 @@ export class Whirlpool { tokenVaultB: dec.tokenVaultB, feeGrowthGlobalB: dec.feeGrowthGlobalB, rewardLastUpdatedTimestamp: dec.rewardLastUpdatedTimestamp, - rewardInfos: dec.rewardInfos.map((item: any /* eslint-disable-line @typescript-eslint/no-explicit-any */) => - types.WhirlpoolRewardInfo.fromDecoded(item) + rewardInfos: dec.rewardInfos.map( + ( + item: any /* eslint-disable-line @typescript-eslint/no-explicit-any */ + ) => types.WhirlpoolRewardInfo.fromDecoded(item) ), - }); + }) } toJSON(): WhirlpoolJSON { @@ -196,7 +210,7 @@ export class Whirlpool { feeGrowthGlobalB: this.feeGrowthGlobalB.toString(), rewardLastUpdatedTimestamp: this.rewardLastUpdatedTimestamp.toString(), rewardInfos: this.rewardInfos.map((item) => item.toJSON()), - }; + } } static fromJSON(obj: WhirlpoolJSON): Whirlpool { @@ -219,7 +233,9 @@ export class Whirlpool { tokenVaultB: new PublicKey(obj.tokenVaultB), feeGrowthGlobalB: new BN(obj.feeGrowthGlobalB), rewardLastUpdatedTimestamp: new BN(obj.rewardLastUpdatedTimestamp), - rewardInfos: obj.rewardInfos.map((item) => types.WhirlpoolRewardInfo.fromJSON(item)), - }); + rewardInfos: obj.rewardInfos.map((item) => + types.WhirlpoolRewardInfo.fromJSON(item) + ), + }) } } diff --git a/packages/kamino-sdk/src/whirpools-client/accounts/WhirlpoolsConfig.ts b/packages/kamino-sdk/src/whirpools-client/accounts/WhirlpoolsConfig.ts index f3e6798e..19bcddf9 100644 --- a/packages/kamino-sdk/src/whirpools-client/accounts/WhirlpoolsConfig.ts +++ b/packages/kamino-sdk/src/whirpools-client/accounts/WhirlpoolsConfig.ts @@ -1,103 +1,119 @@ -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 WhirlpoolsConfigFields { - feeAuthority: PublicKey; - collectProtocolFeesAuthority: PublicKey; - rewardEmissionsSuperAuthority: PublicKey; - defaultProtocolFeeRate: number; + feeAuthority: PublicKey + collectProtocolFeesAuthority: PublicKey + rewardEmissionsSuperAuthority: PublicKey + defaultProtocolFeeRate: number } export interface WhirlpoolsConfigJSON { - feeAuthority: string; - collectProtocolFeesAuthority: string; - rewardEmissionsSuperAuthority: string; - defaultProtocolFeeRate: number; + feeAuthority: string + collectProtocolFeesAuthority: string + rewardEmissionsSuperAuthority: string + defaultProtocolFeeRate: number } export class WhirlpoolsConfig { - readonly feeAuthority: PublicKey; - readonly collectProtocolFeesAuthority: PublicKey; - readonly rewardEmissionsSuperAuthority: PublicKey; - readonly defaultProtocolFeeRate: number; + readonly feeAuthority: PublicKey + readonly collectProtocolFeesAuthority: PublicKey + readonly rewardEmissionsSuperAuthority: PublicKey + readonly defaultProtocolFeeRate: number - static readonly discriminator = Buffer.from([157, 20, 49, 224, 217, 87, 193, 254]); + static readonly discriminator = Buffer.from([ + 157, 20, 49, 224, 217, 87, 193, 254, + ]) static readonly layout = borsh.struct([ - borsh.publicKey('feeAuthority'), - borsh.publicKey('collectProtocolFeesAuthority'), - borsh.publicKey('rewardEmissionsSuperAuthority'), - borsh.u16('defaultProtocolFeeRate'), - ]); + borsh.publicKey("feeAuthority"), + borsh.publicKey("collectProtocolFeesAuthority"), + borsh.publicKey("rewardEmissionsSuperAuthority"), + borsh.u16("defaultProtocolFeeRate"), + ]) constructor(fields: WhirlpoolsConfigFields) { - this.feeAuthority = fields.feeAuthority; - this.collectProtocolFeesAuthority = fields.collectProtocolFeesAuthority; - this.rewardEmissionsSuperAuthority = fields.rewardEmissionsSuperAuthority; - this.defaultProtocolFeeRate = fields.defaultProtocolFeeRate; + this.feeAuthority = fields.feeAuthority + this.collectProtocolFeesAuthority = fields.collectProtocolFeesAuthority + this.rewardEmissionsSuperAuthority = fields.rewardEmissionsSuperAuthority + this.defaultProtocolFeeRate = fields.defaultProtocolFeeRate } - static async fetch(c: Connection, address: PublicKey): Promise { - const info = await c.getAccountInfo(address); + static async fetch( + c: Connection, + address: PublicKey, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID + ): Promise { + 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> { - const infos = await c.getMultipleAccountsInfo(addresses); + static async fetchMultiple( + c: Connection, + addresses: PublicKey[], + programId: PublicKey = WHIRLPOOL_PROGRAM_ID + ): Promise> { + 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): WhirlpoolsConfig { if (!data.slice(0, 8).equals(WhirlpoolsConfig.discriminator)) { - throw new Error('invalid account discriminator'); + throw new Error("invalid account discriminator") } - const dec = WhirlpoolsConfig.layout.decode(data.slice(8)); + const dec = WhirlpoolsConfig.layout.decode(data.slice(8)) return new WhirlpoolsConfig({ feeAuthority: dec.feeAuthority, collectProtocolFeesAuthority: dec.collectProtocolFeesAuthority, rewardEmissionsSuperAuthority: dec.rewardEmissionsSuperAuthority, defaultProtocolFeeRate: dec.defaultProtocolFeeRate, - }); + }) } toJSON(): WhirlpoolsConfigJSON { return { feeAuthority: this.feeAuthority.toString(), - collectProtocolFeesAuthority: this.collectProtocolFeesAuthority.toString(), - rewardEmissionsSuperAuthority: this.rewardEmissionsSuperAuthority.toString(), + collectProtocolFeesAuthority: + this.collectProtocolFeesAuthority.toString(), + rewardEmissionsSuperAuthority: + this.rewardEmissionsSuperAuthority.toString(), defaultProtocolFeeRate: this.defaultProtocolFeeRate, - }; + } } static fromJSON(obj: WhirlpoolsConfigJSON): WhirlpoolsConfig { return new WhirlpoolsConfig({ feeAuthority: new PublicKey(obj.feeAuthority), - collectProtocolFeesAuthority: new PublicKey(obj.collectProtocolFeesAuthority), - rewardEmissionsSuperAuthority: new PublicKey(obj.rewardEmissionsSuperAuthority), + collectProtocolFeesAuthority: new PublicKey( + obj.collectProtocolFeesAuthority + ), + rewardEmissionsSuperAuthority: new PublicKey( + obj.rewardEmissionsSuperAuthority + ), defaultProtocolFeeRate: obj.defaultProtocolFeeRate, - }); + }) } } diff --git a/packages/kamino-sdk/src/whirpools-client/accounts/WhirlpoolsConfigExtension.ts b/packages/kamino-sdk/src/whirpools-client/accounts/WhirlpoolsConfigExtension.ts new file mode 100644 index 00000000..59d54ee2 --- /dev/null +++ b/packages/kamino-sdk/src/whirpools-client/accounts/WhirlpoolsConfigExtension.ts @@ -0,0 +1,107 @@ +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 WhirlpoolsConfigExtensionFields { + whirlpoolsConfig: PublicKey + configExtensionAuthority: PublicKey + tokenBadgeAuthority: PublicKey +} + +export interface WhirlpoolsConfigExtensionJSON { + whirlpoolsConfig: string + configExtensionAuthority: string + tokenBadgeAuthority: string +} + +export class WhirlpoolsConfigExtension { + readonly whirlpoolsConfig: PublicKey + readonly configExtensionAuthority: PublicKey + readonly tokenBadgeAuthority: PublicKey + + static readonly discriminator = Buffer.from([ + 2, 99, 215, 163, 240, 26, 153, 58, + ]) + + static readonly layout = borsh.struct([ + borsh.publicKey("whirlpoolsConfig"), + borsh.publicKey("configExtensionAuthority"), + borsh.publicKey("tokenBadgeAuthority"), + ]) + + constructor(fields: WhirlpoolsConfigExtensionFields) { + this.whirlpoolsConfig = fields.whirlpoolsConfig + this.configExtensionAuthority = fields.configExtensionAuthority + this.tokenBadgeAuthority = fields.tokenBadgeAuthority + } + + static async fetch( + c: Connection, + address: PublicKey, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID + ): Promise { + const info = await c.getAccountInfo(address) + + if (info === null) { + return null + } + if (!info.owner.equals(programId)) { + throw new Error("account doesn't belong to this program") + } + + return this.decode(info.data) + } + + static async fetchMultiple( + c: Connection, + addresses: PublicKey[], + programId: PublicKey = WHIRLPOOL_PROGRAM_ID + ): Promise> { + const infos = await c.getMultipleAccountsInfo(addresses) + + return infos.map((info) => { + if (info === null) { + return null + } + if (!info.owner.equals(programId)) { + throw new Error("account doesn't belong to this program") + } + + return this.decode(info.data) + }) + } + + static decode(data: Buffer): WhirlpoolsConfigExtension { + if (!data.slice(0, 8).equals(WhirlpoolsConfigExtension.discriminator)) { + throw new Error("invalid account discriminator") + } + + const dec = WhirlpoolsConfigExtension.layout.decode(data.slice(8)) + + return new WhirlpoolsConfigExtension({ + whirlpoolsConfig: dec.whirlpoolsConfig, + configExtensionAuthority: dec.configExtensionAuthority, + tokenBadgeAuthority: dec.tokenBadgeAuthority, + }) + } + + toJSON(): WhirlpoolsConfigExtensionJSON { + return { + whirlpoolsConfig: this.whirlpoolsConfig.toString(), + configExtensionAuthority: this.configExtensionAuthority.toString(), + tokenBadgeAuthority: this.tokenBadgeAuthority.toString(), + } + } + + static fromJSON( + obj: WhirlpoolsConfigExtensionJSON + ): WhirlpoolsConfigExtension { + return new WhirlpoolsConfigExtension({ + whirlpoolsConfig: new PublicKey(obj.whirlpoolsConfig), + configExtensionAuthority: new PublicKey(obj.configExtensionAuthority), + tokenBadgeAuthority: new PublicKey(obj.tokenBadgeAuthority), + }) + } +} diff --git a/packages/kamino-sdk/src/whirpools-client/accounts/index.ts b/packages/kamino-sdk/src/whirpools-client/accounts/index.ts index 0f3f34fa..e62c4d11 100644 --- a/packages/kamino-sdk/src/whirpools-client/accounts/index.ts +++ b/packages/kamino-sdk/src/whirpools-client/accounts/index.ts @@ -1,3 +1,8 @@ +export { WhirlpoolsConfigExtension } from "./WhirlpoolsConfigExtension" +export type { + WhirlpoolsConfigExtensionFields, + WhirlpoolsConfigExtensionJSON, +} from "./WhirlpoolsConfigExtension" export { WhirlpoolsConfig } from "./WhirlpoolsConfig" export type { WhirlpoolsConfigFields, @@ -5,9 +10,13 @@ export type { } from "./WhirlpoolsConfig" export { FeeTier } from "./FeeTier" export type { FeeTierFields, FeeTierJSON } from "./FeeTier" +export { PositionBundle } from "./PositionBundle" +export type { PositionBundleFields, PositionBundleJSON } from "./PositionBundle" export { Position } from "./Position" export type { PositionFields, PositionJSON } from "./Position" export { TickArray } from "./TickArray" export type { TickArrayFields, TickArrayJSON } from "./TickArray" +export { TokenBadge } from "./TokenBadge" +export type { TokenBadgeFields, TokenBadgeJSON } from "./TokenBadge" export { Whirlpool } from "./Whirlpool" export type { WhirlpoolFields, WhirlpoolJSON } from "./Whirlpool" diff --git a/packages/kamino-sdk/src/whirpools-client/errors/anchor.ts b/packages/kamino-sdk/src/whirpools-client/errors/anchor.ts index a4f79a25..f40da698 100644 --- a/packages/kamino-sdk/src/whirpools-client/errors/anchor.ts +++ b/packages/kamino-sdk/src/whirpools-client/errors/anchor.ts @@ -25,6 +25,7 @@ export type AnchorError = | ConstraintMintFreezeAuthority | ConstraintMintDecimals | ConstraintSpace + | ConstraintAccountIsNone | RequireViolated | RequireEqViolated | RequireKeysEqViolated @@ -50,7 +51,6 @@ export type AnchorError = | AccountSysvarMismatch | AccountReallocExceedsLimit | AccountDuplicateReallocs - | StateInvalidAddress | DeclaredProgramIdMismatch | Deprecated @@ -138,10 +138,10 @@ export class ConstraintHasOne extends Error { static readonly code = 2001 readonly code = 2001 readonly name = "ConstraintHasOne" - readonly msg = "A has_one constraint was violated" + readonly msg = "A has one constraint was violated" constructor(readonly logs?: string[]) { - super("2001: A has_one constraint was violated") + super("2001: A has one constraint was violated") } } @@ -215,10 +215,10 @@ export class ConstraintState extends Error { static readonly code = 2008 readonly code = 2008 readonly name = "ConstraintState" - readonly msg = "A state constraint was violated" + readonly msg = "Deprecated Error, feel free to replace with something else" constructor(readonly logs?: string[]) { - super("2008: A state constraint was violated") + super("2008: Deprecated Error, feel free to replace with something else") } } @@ -343,6 +343,17 @@ export class ConstraintSpace extends Error { } } +export class ConstraintAccountIsNone extends Error { + static readonly code = 2020 + readonly code = 2020 + readonly name = "ConstraintAccountIsNone" + readonly msg = "A required account for the constraint is None" + + constructor(readonly logs?: string[]) { + super("2020: A required account for the constraint is None") + } +} + export class RequireViolated extends Error { static readonly code = 2500 readonly code = 2500 @@ -624,17 +635,6 @@ export class AccountDuplicateReallocs extends Error { } } -export class StateInvalidAddress extends Error { - static readonly code = 4000 - readonly code = 4000 - readonly name = "StateInvalidAddress" - readonly msg = "The given state account does not have the correct address" - - constructor(readonly logs?: string[]) { - super("4000: The given state account does not have the correct address") - } -} - export class DeclaredProgramIdMismatch extends Error { static readonly code = 4100 readonly code = 4100 @@ -711,6 +711,8 @@ export function fromCode(code: number, logs?: string[]): AnchorError | null { return new ConstraintMintDecimals(logs) case 2019: return new ConstraintSpace(logs) + case 2020: + return new ConstraintAccountIsNone(logs) case 2500: return new RequireViolated(logs) case 2501: @@ -761,8 +763,6 @@ export function fromCode(code: number, logs?: string[]): AnchorError | null { return new AccountReallocExceedsLimit(logs) case 3017: return new AccountDuplicateReallocs(logs) - case 4000: - return new StateInvalidAddress(logs) case 4100: return new DeclaredProgramIdMismatch(logs) case 5000: diff --git a/packages/kamino-sdk/src/whirpools-client/errors/custom.ts b/packages/kamino-sdk/src/whirpools-client/errors/custom.ts index e40a19c8..6fbd4160 100644 --- a/packages/kamino-sdk/src/whirpools-client/errors/custom.ts +++ b/packages/kamino-sdk/src/whirpools-client/errors/custom.ts @@ -40,6 +40,19 @@ export type CustomError = | TickArraySequenceInvalidIndex | AmountCalcOverflow | AmountRemainingOverflow + | InvalidIntermediaryMint + | DuplicateTwoHopPool + | InvalidBundleIndex + | BundledPositionAlreadyOpened + | BundledPositionAlreadyClosed + | PositionBundleNotDeletable + | UnsupportedTokenMint + | RemainingAccountsInvalidSlice + | RemainingAccountsInsufficient + | NoExtraAccountsForTransferHook + | IntermediateTokenAmountMismatch + | TransferFeeCalculationError + | RemainingAccountsDuplicatedAccountsType export class InvalidEnum extends Error { static readonly code = 6000 @@ -501,6 +514,149 @@ export class AmountRemainingOverflow extends Error { } } +export class InvalidIntermediaryMint extends Error { + static readonly code = 6041 + readonly code = 6041 + readonly name = "InvalidIntermediaryMint" + readonly msg = "Invalid intermediary mint" + + constructor(readonly logs?: string[]) { + super("6041: Invalid intermediary mint") + } +} + +export class DuplicateTwoHopPool extends Error { + static readonly code = 6042 + readonly code = 6042 + readonly name = "DuplicateTwoHopPool" + readonly msg = "Duplicate two hop pool" + + constructor(readonly logs?: string[]) { + super("6042: Duplicate two hop pool") + } +} + +export class InvalidBundleIndex extends Error { + static readonly code = 6043 + readonly code = 6043 + readonly name = "InvalidBundleIndex" + readonly msg = "Bundle index is out of bounds" + + constructor(readonly logs?: string[]) { + super("6043: Bundle index is out of bounds") + } +} + +export class BundledPositionAlreadyOpened extends Error { + static readonly code = 6044 + readonly code = 6044 + readonly name = "BundledPositionAlreadyOpened" + readonly msg = "Position has already been opened" + + constructor(readonly logs?: string[]) { + super("6044: Position has already been opened") + } +} + +export class BundledPositionAlreadyClosed extends Error { + static readonly code = 6045 + readonly code = 6045 + readonly name = "BundledPositionAlreadyClosed" + readonly msg = "Position has already been closed" + + constructor(readonly logs?: string[]) { + super("6045: Position has already been closed") + } +} + +export class PositionBundleNotDeletable extends Error { + static readonly code = 6046 + readonly code = 6046 + readonly name = "PositionBundleNotDeletable" + readonly msg = "Unable to delete PositionBundle with open positions" + + constructor(readonly logs?: string[]) { + super("6046: Unable to delete PositionBundle with open positions") + } +} + +export class UnsupportedTokenMint extends Error { + static readonly code = 6047 + readonly code = 6047 + readonly name = "UnsupportedTokenMint" + readonly msg = "Token mint has unsupported attributes" + + constructor(readonly logs?: string[]) { + super("6047: Token mint has unsupported attributes") + } +} + +export class RemainingAccountsInvalidSlice extends Error { + static readonly code = 6048 + readonly code = 6048 + readonly name = "RemainingAccountsInvalidSlice" + readonly msg = "Invalid remaining accounts" + + constructor(readonly logs?: string[]) { + super("6048: Invalid remaining accounts") + } +} + +export class RemainingAccountsInsufficient extends Error { + static readonly code = 6049 + readonly code = 6049 + readonly name = "RemainingAccountsInsufficient" + readonly msg = "Insufficient remaining accounts" + + constructor(readonly logs?: string[]) { + super("6049: Insufficient remaining accounts") + } +} + +export class NoExtraAccountsForTransferHook extends Error { + static readonly code = 6050 + readonly code = 6050 + readonly name = "NoExtraAccountsForTransferHook" + readonly msg = "Unable to call transfer hook without extra accounts" + + constructor(readonly logs?: string[]) { + super("6050: Unable to call transfer hook without extra accounts") + } +} + +export class IntermediateTokenAmountMismatch extends Error { + static readonly code = 6051 + readonly code = 6051 + readonly name = "IntermediateTokenAmountMismatch" + readonly msg = "Output and input amount mismatch" + + constructor(readonly logs?: string[]) { + super("6051: Output and input amount mismatch") + } +} + +export class TransferFeeCalculationError extends Error { + static readonly code = 6052 + readonly code = 6052 + readonly name = "TransferFeeCalculationError" + readonly msg = "Transfer fee calculation failed" + + constructor(readonly logs?: string[]) { + super("6052: Transfer fee calculation failed") + } +} + +export class RemainingAccountsDuplicatedAccountsType extends Error { + static readonly code = 6053 + readonly code = 6053 + readonly name = "RemainingAccountsDuplicatedAccountsType" + readonly msg = "Same accounts type is provided more than once" + + constructor(readonly logs?: string[]) { + super("6053: Same accounts type is provided more than once") + } +} + export function fromCode(code: number, logs?: string[]): CustomError | null { switch (code) { case 6000: @@ -585,6 +741,32 @@ export function fromCode(code: number, logs?: string[]): CustomError | null { return new AmountCalcOverflow(logs) case 6040: return new AmountRemainingOverflow(logs) + case 6041: + return new InvalidIntermediaryMint(logs) + case 6042: + return new DuplicateTwoHopPool(logs) + case 6043: + return new InvalidBundleIndex(logs) + case 6044: + return new BundledPositionAlreadyOpened(logs) + case 6045: + return new BundledPositionAlreadyClosed(logs) + case 6046: + return new PositionBundleNotDeletable(logs) + case 6047: + return new UnsupportedTokenMint(logs) + case 6048: + return new RemainingAccountsInvalidSlice(logs) + case 6049: + return new RemainingAccountsInsufficient(logs) + case 6050: + return new NoExtraAccountsForTransferHook(logs) + case 6051: + return new IntermediateTokenAmountMismatch(logs) + case 6052: + return new TransferFeeCalculationError(logs) + case 6053: + return new RemainingAccountsDuplicatedAccountsType(logs) } return null diff --git a/packages/kamino-sdk/src/whirpools-client/errors/index.ts b/packages/kamino-sdk/src/whirpools-client/errors/index.ts index 1e411d73..fd0849fa 100644 --- a/packages/kamino-sdk/src/whirpools-client/errors/index.ts +++ b/packages/kamino-sdk/src/whirpools-client/errors/index.ts @@ -1,45 +1,62 @@ -import { WHIRLPOOL_PROGRAM_ID } from '../programId'; -import * as anchor from './anchor'; -import * as custom from './custom'; - -export function fromCode(code: number, logs?: string[]): custom.CustomError | anchor.AnchorError | null { - return code >= 6000 ? custom.fromCode(code, logs) : anchor.fromCode(code, logs); +import { PublicKey } from "@solana/web3.js" +import { WHIRLPOOL_PROGRAM_ID } from "../programId" +import * as anchor from "./anchor" +import * as custom from "./custom" + +export function fromCode( + code: number, + logs?: string[] +): custom.CustomError | anchor.AnchorError | null { + return code >= 6000 + ? custom.fromCode(code, logs) + : anchor.fromCode(code, logs) } -function hasOwnProperty(obj: X, prop: Y): obj is X & Record { - return Object.hasOwnProperty.call(obj, prop); +function hasOwnProperty( + obj: X, + prop: Y +): obj is X & Record { + return Object.hasOwnProperty.call(obj, prop) } -const errorRe = /Program (\w+) failed: custom program error: (\w+)/; - -export function fromTxError(err: unknown): custom.CustomError | anchor.AnchorError | null { - if (typeof err !== 'object' || err === null || !hasOwnProperty(err, 'logs') || !Array.isArray(err.logs)) { - return null; +const errorRe = /Program (\w+) failed: custom program error: (\w+)/ + +export function fromTxError( + err: unknown, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +): custom.CustomError | anchor.AnchorError | null { + if ( + typeof err !== "object" || + err === null || + !hasOwnProperty(err, "logs") || + !Array.isArray(err.logs) + ) { + return null } - let firstMatch: RegExpExecArray | null = null; + let firstMatch: RegExpExecArray | null = null for (const logLine of err.logs) { - firstMatch = errorRe.exec(logLine); + firstMatch = errorRe.exec(logLine) if (firstMatch !== null) { - break; + break } } if (firstMatch === null) { - return null; + return null } - const [programIdRaw, codeRaw] = firstMatch.slice(1); - if (programIdRaw !== WHIRLPOOL_PROGRAM_ID.toString()) { - return null; + const [programIdRaw, codeRaw] = firstMatch.slice(1) + if (programIdRaw !== programId.toString()) { + return null } - let errorCode: number; + let errorCode: number try { - errorCode = parseInt(codeRaw, 16); + errorCode = parseInt(codeRaw, 16) } catch (parseErr) { - return null; + return null } - return fromCode(errorCode, err.logs); + return fromCode(errorCode, err.logs) } diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/closeBundledPosition.ts b/packages/kamino-sdk/src/whirpools-client/instructions/closeBundledPosition.ts new file mode 100644 index 00000000..79df49b6 --- /dev/null +++ b/packages/kamino-sdk/src/whirpools-client/instructions/closeBundledPosition.ts @@ -0,0 +1,52 @@ +import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 CloseBundledPositionArgs { + bundleIndex: number +} + +export interface CloseBundledPositionAccounts { + bundledPosition: PublicKey + positionBundle: PublicKey + positionBundleTokenAccount: PublicKey + positionBundleAuthority: PublicKey + receiver: PublicKey +} + +export const layout = borsh.struct([borsh.u16("bundleIndex")]) + +export function closeBundledPosition( + args: CloseBundledPositionArgs, + accounts: CloseBundledPositionAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { + const keys: Array = [ + { pubkey: accounts.bundledPosition, isSigner: false, isWritable: true }, + { pubkey: accounts.positionBundle, isSigner: false, isWritable: true }, + { + pubkey: accounts.positionBundleTokenAccount, + isSigner: false, + isWritable: false, + }, + { + pubkey: accounts.positionBundleAuthority, + isSigner: true, + isWritable: false, + }, + { pubkey: accounts.receiver, isSigner: false, isWritable: true }, + ] + const identifier = Buffer.from([41, 36, 216, 245, 27, 85, 103, 67]) + const buffer = Buffer.alloc(1000) + const len = layout.encode( + { + bundleIndex: args.bundleIndex, + }, + buffer + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix +} diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/closePosition.ts b/packages/kamino-sdk/src/whirpools-client/instructions/closePosition.ts index fc0cd6cc..166e63dc 100644 --- a/packages/kamino-sdk/src/whirpools-client/instructions/closePosition.ts +++ b/packages/kamino-sdk/src/whirpools-client/instructions/closePosition.ts @@ -1,19 +1,22 @@ -import { TransactionInstruction, PublicKey, AccountMeta } from '@solana/web3.js'; // eslint-disable-line @typescript-eslint/no-unused-vars -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 { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 ClosePositionAccounts { - positionAuthority: PublicKey; - receiver: PublicKey; - position: PublicKey; - positionMint: PublicKey; - positionTokenAccount: PublicKey; - tokenProgram: PublicKey; + positionAuthority: PublicKey + receiver: PublicKey + position: PublicKey + positionMint: PublicKey + positionTokenAccount: PublicKey + tokenProgram: PublicKey } -export function closePosition(accounts: ClosePositionAccounts) { +export function closePosition( + accounts: ClosePositionAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { const keys: Array = [ { pubkey: accounts.positionAuthority, isSigner: true, isWritable: false }, { pubkey: accounts.receiver, isSigner: false, isWritable: true }, @@ -25,9 +28,9 @@ export function closePosition(accounts: ClosePositionAccounts) { isWritable: true, }, { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false }, - ]; - const identifier = Buffer.from([123, 134, 81, 0, 49, 68, 98, 98]); - const data = identifier; - const ix = new TransactionInstruction({ keys, programId: WHIRLPOOL_PROGRAM_ID, data }); - return ix; + ] + const identifier = Buffer.from([123, 134, 81, 0, 49, 68, 98, 98]) + const data = identifier + const ix = new TransactionInstruction({ keys, programId, data }) + return ix } diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/collectFees.ts b/packages/kamino-sdk/src/whirpools-client/instructions/collectFees.ts index 10d1e0a6..83feebc9 100644 --- a/packages/kamino-sdk/src/whirpools-client/instructions/collectFees.ts +++ b/packages/kamino-sdk/src/whirpools-client/instructions/collectFees.ts @@ -1,22 +1,25 @@ -import { TransactionInstruction, PublicKey, AccountMeta } from '@solana/web3.js'; // eslint-disable-line @typescript-eslint/no-unused-vars -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 { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 CollectFeesAccounts { - whirlpool: PublicKey; - positionAuthority: PublicKey; - position: PublicKey; - positionTokenAccount: PublicKey; - tokenOwnerAccountA: PublicKey; - tokenVaultA: PublicKey; - tokenOwnerAccountB: PublicKey; - tokenVaultB: PublicKey; - tokenProgram: PublicKey; + whirlpool: PublicKey + positionAuthority: PublicKey + position: PublicKey + positionTokenAccount: PublicKey + tokenOwnerAccountA: PublicKey + tokenVaultA: PublicKey + tokenOwnerAccountB: PublicKey + tokenVaultB: PublicKey + tokenProgram: PublicKey } -export function collectFees(accounts: CollectFeesAccounts) { +export function collectFees( + accounts: CollectFeesAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { const keys: Array = [ { pubkey: accounts.whirlpool, isSigner: false, isWritable: false }, { pubkey: accounts.positionAuthority, isSigner: true, isWritable: false }, @@ -31,9 +34,9 @@ export function collectFees(accounts: CollectFeesAccounts) { { pubkey: accounts.tokenOwnerAccountB, isSigner: false, isWritable: true }, { pubkey: accounts.tokenVaultB, isSigner: false, isWritable: true }, { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false }, - ]; - const identifier = Buffer.from([164, 152, 207, 99, 30, 186, 19, 182]); - const data = identifier; - const ix = new TransactionInstruction({ keys, programId: WHIRLPOOL_PROGRAM_ID, data }); - return ix; + ] + const identifier = Buffer.from([164, 152, 207, 99, 30, 186, 19, 182]) + const data = identifier + const ix = new TransactionInstruction({ keys, programId, data }) + return ix } diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/collectFeesV2.ts b/packages/kamino-sdk/src/whirpools-client/instructions/collectFeesV2.ts new file mode 100644 index 00000000..b0b5e785 --- /dev/null +++ b/packages/kamino-sdk/src/whirpools-client/instructions/collectFeesV2.ts @@ -0,0 +1,71 @@ +import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 CollectFeesV2Args { + remainingAccountsInfo: types.RemainingAccountsInfoFields | null +} + +export interface CollectFeesV2Accounts { + whirlpool: PublicKey + positionAuthority: PublicKey + position: PublicKey + positionTokenAccount: PublicKey + tokenMintA: PublicKey + tokenMintB: PublicKey + tokenOwnerAccountA: PublicKey + tokenVaultA: PublicKey + tokenOwnerAccountB: PublicKey + tokenVaultB: PublicKey + tokenProgramA: PublicKey + tokenProgramB: PublicKey + memoProgram: PublicKey +} + +export const layout = borsh.struct([ + borsh.option(types.RemainingAccountsInfo.layout(), "remainingAccountsInfo"), +]) + +export function collectFeesV2( + args: CollectFeesV2Args, + accounts: CollectFeesV2Accounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { + const keys: Array = [ + { pubkey: accounts.whirlpool, isSigner: false, isWritable: false }, + { pubkey: accounts.positionAuthority, isSigner: true, isWritable: false }, + { pubkey: accounts.position, isSigner: false, isWritable: true }, + { + pubkey: accounts.positionTokenAccount, + isSigner: false, + isWritable: false, + }, + { pubkey: accounts.tokenMintA, isSigner: false, isWritable: false }, + { pubkey: accounts.tokenMintB, isSigner: false, isWritable: false }, + { pubkey: accounts.tokenOwnerAccountA, isSigner: false, isWritable: true }, + { pubkey: accounts.tokenVaultA, isSigner: false, isWritable: true }, + { pubkey: accounts.tokenOwnerAccountB, isSigner: false, isWritable: true }, + { pubkey: accounts.tokenVaultB, isSigner: false, isWritable: true }, + { pubkey: accounts.tokenProgramA, isSigner: false, isWritable: false }, + { pubkey: accounts.tokenProgramB, isSigner: false, isWritable: false }, + { pubkey: accounts.memoProgram, isSigner: false, isWritable: false }, + ] + const identifier = Buffer.from([207, 117, 95, 191, 229, 180, 226, 15]) + const buffer = Buffer.alloc(1000) + const len = layout.encode( + { + remainingAccountsInfo: + (args.remainingAccountsInfo && + types.RemainingAccountsInfo.toEncodable( + args.remainingAccountsInfo + )) || + null, + }, + buffer + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix +} diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/collectProtocolFees.ts b/packages/kamino-sdk/src/whirpools-client/instructions/collectProtocolFees.ts index c7882a38..905dee15 100644 --- a/packages/kamino-sdk/src/whirpools-client/instructions/collectProtocolFees.ts +++ b/packages/kamino-sdk/src/whirpools-client/instructions/collectProtocolFees.ts @@ -1,21 +1,24 @@ -import { TransactionInstruction, PublicKey, AccountMeta } from '@solana/web3.js'; // eslint-disable-line @typescript-eslint/no-unused-vars -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 { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 CollectProtocolFeesAccounts { - whirlpoolsConfig: PublicKey; - whirlpool: PublicKey; - collectProtocolFeesAuthority: PublicKey; - tokenVaultA: PublicKey; - tokenVaultB: PublicKey; - tokenDestinationA: PublicKey; - tokenDestinationB: PublicKey; - tokenProgram: PublicKey; + whirlpoolsConfig: PublicKey + whirlpool: PublicKey + collectProtocolFeesAuthority: PublicKey + tokenVaultA: PublicKey + tokenVaultB: PublicKey + tokenDestinationA: PublicKey + tokenDestinationB: PublicKey + tokenProgram: PublicKey } -export function collectProtocolFees(accounts: CollectProtocolFeesAccounts) { +export function collectProtocolFees( + accounts: CollectProtocolFeesAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { const keys: Array = [ { pubkey: accounts.whirlpoolsConfig, isSigner: false, isWritable: false }, { pubkey: accounts.whirlpool, isSigner: false, isWritable: true }, @@ -29,9 +32,9 @@ export function collectProtocolFees(accounts: CollectProtocolFeesAccounts) { { pubkey: accounts.tokenDestinationA, isSigner: false, isWritable: true }, { pubkey: accounts.tokenDestinationB, isSigner: false, isWritable: true }, { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false }, - ]; - const identifier = Buffer.from([22, 67, 23, 98, 150, 178, 70, 220]); - const data = identifier; - const ix = new TransactionInstruction({ keys, programId: WHIRLPOOL_PROGRAM_ID, data }); - return ix; + ] + const identifier = Buffer.from([22, 67, 23, 98, 150, 178, 70, 220]) + const data = identifier + const ix = new TransactionInstruction({ keys, programId, data }) + return ix } diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/collectProtocolFeesV2.ts b/packages/kamino-sdk/src/whirpools-client/instructions/collectProtocolFeesV2.ts new file mode 100644 index 00000000..dea81045 --- /dev/null +++ b/packages/kamino-sdk/src/whirpools-client/instructions/collectProtocolFeesV2.ts @@ -0,0 +1,69 @@ +import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 CollectProtocolFeesV2Args { + remainingAccountsInfo: types.RemainingAccountsInfoFields | null +} + +export interface CollectProtocolFeesV2Accounts { + whirlpoolsConfig: PublicKey + whirlpool: PublicKey + collectProtocolFeesAuthority: PublicKey + tokenMintA: PublicKey + tokenMintB: PublicKey + tokenVaultA: PublicKey + tokenVaultB: PublicKey + tokenDestinationA: PublicKey + tokenDestinationB: PublicKey + tokenProgramA: PublicKey + tokenProgramB: PublicKey + memoProgram: PublicKey +} + +export const layout = borsh.struct([ + borsh.option(types.RemainingAccountsInfo.layout(), "remainingAccountsInfo"), +]) + +export function collectProtocolFeesV2( + args: CollectProtocolFeesV2Args, + accounts: CollectProtocolFeesV2Accounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { + const keys: Array = [ + { pubkey: accounts.whirlpoolsConfig, isSigner: false, isWritable: false }, + { pubkey: accounts.whirlpool, isSigner: false, isWritable: true }, + { + pubkey: accounts.collectProtocolFeesAuthority, + isSigner: true, + isWritable: false, + }, + { pubkey: accounts.tokenMintA, isSigner: false, isWritable: false }, + { pubkey: accounts.tokenMintB, isSigner: false, isWritable: false }, + { pubkey: accounts.tokenVaultA, isSigner: false, isWritable: true }, + { pubkey: accounts.tokenVaultB, isSigner: false, isWritable: true }, + { pubkey: accounts.tokenDestinationA, isSigner: false, isWritable: true }, + { pubkey: accounts.tokenDestinationB, isSigner: false, isWritable: true }, + { pubkey: accounts.tokenProgramA, isSigner: false, isWritable: false }, + { pubkey: accounts.tokenProgramB, isSigner: false, isWritable: false }, + { pubkey: accounts.memoProgram, isSigner: false, isWritable: false }, + ] + const identifier = Buffer.from([103, 128, 222, 134, 114, 200, 22, 200]) + const buffer = Buffer.alloc(1000) + const len = layout.encode( + { + remainingAccountsInfo: + (args.remainingAccountsInfo && + types.RemainingAccountsInfo.toEncodable( + args.remainingAccountsInfo + )) || + null, + }, + buffer + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix +} diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/collectReward.ts b/packages/kamino-sdk/src/whirpools-client/instructions/collectReward.ts index d3bea884..34e99800 100644 --- a/packages/kamino-sdk/src/whirpools-client/instructions/collectReward.ts +++ b/packages/kamino-sdk/src/whirpools-client/instructions/collectReward.ts @@ -1,26 +1,30 @@ -import { TransactionInstruction, PublicKey, AccountMeta } from '@solana/web3.js'; // eslint-disable-line @typescript-eslint/no-unused-vars -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 { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 CollectRewardArgs { - rewardIndex: number; + rewardIndex: number } export interface CollectRewardAccounts { - whirlpool: PublicKey; - positionAuthority: PublicKey; - position: PublicKey; - positionTokenAccount: PublicKey; - rewardOwnerAccount: PublicKey; - rewardVault: PublicKey; - tokenProgram: PublicKey; + whirlpool: PublicKey + positionAuthority: PublicKey + position: PublicKey + positionTokenAccount: PublicKey + rewardOwnerAccount: PublicKey + rewardVault: PublicKey + tokenProgram: PublicKey } -export const layout = borsh.struct([borsh.u8('rewardIndex')]); +export const layout = borsh.struct([borsh.u8("rewardIndex")]) -export function collectReward(args: CollectRewardArgs, accounts: CollectRewardAccounts) { +export function collectReward( + args: CollectRewardArgs, + accounts: CollectRewardAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { const keys: Array = [ { pubkey: accounts.whirlpool, isSigner: false, isWritable: false }, { pubkey: accounts.positionAuthority, isSigner: true, isWritable: false }, @@ -33,16 +37,16 @@ export function collectReward(args: CollectRewardArgs, accounts: CollectRewardAc { pubkey: accounts.rewardOwnerAccount, isSigner: false, isWritable: true }, { pubkey: accounts.rewardVault, isSigner: false, isWritable: true }, { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false }, - ]; - const identifier = Buffer.from([70, 5, 132, 87, 86, 235, 177, 34]); - const buffer = Buffer.alloc(1000); + ] + const identifier = Buffer.from([70, 5, 132, 87, 86, 235, 177, 34]) + const buffer = Buffer.alloc(1000) const len = layout.encode( { rewardIndex: args.rewardIndex, }, buffer - ); - const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len); - const ix = new TransactionInstruction({ keys, programId: WHIRLPOOL_PROGRAM_ID, data }); - return ix; + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix } diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/collectRewardV2.ts b/packages/kamino-sdk/src/whirpools-client/instructions/collectRewardV2.ts new file mode 100644 index 00000000..54ecdf3e --- /dev/null +++ b/packages/kamino-sdk/src/whirpools-client/instructions/collectRewardV2.ts @@ -0,0 +1,66 @@ +import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 CollectRewardV2Args { + rewardIndex: number + remainingAccountsInfo: types.RemainingAccountsInfoFields | null +} + +export interface CollectRewardV2Accounts { + whirlpool: PublicKey + positionAuthority: PublicKey + position: PublicKey + positionTokenAccount: PublicKey + rewardOwnerAccount: PublicKey + rewardMint: PublicKey + rewardVault: PublicKey + rewardTokenProgram: PublicKey + memoProgram: PublicKey +} + +export const layout = borsh.struct([ + borsh.u8("rewardIndex"), + borsh.option(types.RemainingAccountsInfo.layout(), "remainingAccountsInfo"), +]) + +export function collectRewardV2( + args: CollectRewardV2Args, + accounts: CollectRewardV2Accounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { + const keys: Array = [ + { pubkey: accounts.whirlpool, isSigner: false, isWritable: false }, + { pubkey: accounts.positionAuthority, isSigner: true, isWritable: false }, + { pubkey: accounts.position, isSigner: false, isWritable: true }, + { + pubkey: accounts.positionTokenAccount, + isSigner: false, + isWritable: false, + }, + { pubkey: accounts.rewardOwnerAccount, isSigner: false, isWritable: true }, + { pubkey: accounts.rewardMint, isSigner: false, isWritable: false }, + { pubkey: accounts.rewardVault, isSigner: false, isWritable: true }, + { pubkey: accounts.rewardTokenProgram, isSigner: false, isWritable: false }, + { pubkey: accounts.memoProgram, isSigner: false, isWritable: false }, + ] + const identifier = Buffer.from([177, 107, 37, 180, 160, 19, 49, 209]) + const buffer = Buffer.alloc(1000) + const len = layout.encode( + { + rewardIndex: args.rewardIndex, + remainingAccountsInfo: + (args.remainingAccountsInfo && + types.RemainingAccountsInfo.toEncodable( + args.remainingAccountsInfo + )) || + null, + }, + buffer + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix +} diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/decreaseLiquidity.ts b/packages/kamino-sdk/src/whirpools-client/instructions/decreaseLiquidity.ts index 149efffe..dfe45c00 100644 --- a/packages/kamino-sdk/src/whirpools-client/instructions/decreaseLiquidity.ts +++ b/packages/kamino-sdk/src/whirpools-client/instructions/decreaseLiquidity.ts @@ -1,32 +1,40 @@ -import { TransactionInstruction, PublicKey, AccountMeta } from '@solana/web3.js'; // eslint-disable-line @typescript-eslint/no-unused-vars -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 { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 DecreaseLiquidityArgs { - liquidityAmount: BN; - tokenMinA: BN; - tokenMinB: BN; + liquidityAmount: BN + tokenMinA: BN + tokenMinB: BN } export interface DecreaseLiquidityAccounts { - whirlpool: PublicKey; - tokenProgram: PublicKey; - positionAuthority: PublicKey; - position: PublicKey; - positionTokenAccount: PublicKey; - tokenOwnerAccountA: PublicKey; - tokenOwnerAccountB: PublicKey; - tokenVaultA: PublicKey; - tokenVaultB: PublicKey; - tickArrayLower: PublicKey; - tickArrayUpper: PublicKey; + whirlpool: PublicKey + tokenProgram: PublicKey + positionAuthority: PublicKey + position: PublicKey + positionTokenAccount: PublicKey + tokenOwnerAccountA: PublicKey + tokenOwnerAccountB: PublicKey + tokenVaultA: PublicKey + tokenVaultB: PublicKey + tickArrayLower: PublicKey + tickArrayUpper: PublicKey } -export const layout = borsh.struct([borsh.u128('liquidityAmount'), borsh.u64('tokenMinA'), borsh.u64('tokenMinB')]); +export const layout = borsh.struct([ + borsh.u128("liquidityAmount"), + borsh.u64("tokenMinA"), + borsh.u64("tokenMinB"), +]) -export function decreaseLiquidity(args: DecreaseLiquidityArgs, accounts: DecreaseLiquidityAccounts) { +export function decreaseLiquidity( + args: DecreaseLiquidityArgs, + accounts: DecreaseLiquidityAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { const keys: Array = [ { pubkey: accounts.whirlpool, isSigner: false, isWritable: true }, { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false }, @@ -43,9 +51,9 @@ export function decreaseLiquidity(args: DecreaseLiquidityArgs, accounts: Decreas { pubkey: accounts.tokenVaultB, isSigner: false, isWritable: true }, { pubkey: accounts.tickArrayLower, isSigner: false, isWritable: true }, { pubkey: accounts.tickArrayUpper, isSigner: false, isWritable: true }, - ]; - const identifier = Buffer.from([160, 38, 208, 111, 104, 91, 44, 1]); - const buffer = Buffer.alloc(1000); + ] + const identifier = Buffer.from([160, 38, 208, 111, 104, 91, 44, 1]) + const buffer = Buffer.alloc(1000) const len = layout.encode( { liquidityAmount: args.liquidityAmount, @@ -53,8 +61,8 @@ export function decreaseLiquidity(args: DecreaseLiquidityArgs, accounts: Decreas tokenMinB: args.tokenMinB, }, buffer - ); - const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len); - const ix = new TransactionInstruction({ keys, programId: WHIRLPOOL_PROGRAM_ID, data }); - return ix; + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix } diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/decreaseLiquidityV2.ts b/packages/kamino-sdk/src/whirpools-client/instructions/decreaseLiquidityV2.ts new file mode 100644 index 00000000..e2ccdfd2 --- /dev/null +++ b/packages/kamino-sdk/src/whirpools-client/instructions/decreaseLiquidityV2.ts @@ -0,0 +1,84 @@ +import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 DecreaseLiquidityV2Args { + liquidityAmount: BN + tokenMinA: BN + tokenMinB: BN + remainingAccountsInfo: types.RemainingAccountsInfoFields | null +} + +export interface DecreaseLiquidityV2Accounts { + whirlpool: PublicKey + tokenProgramA: PublicKey + tokenProgramB: PublicKey + memoProgram: PublicKey + positionAuthority: PublicKey + position: PublicKey + positionTokenAccount: PublicKey + tokenMintA: PublicKey + tokenMintB: PublicKey + tokenOwnerAccountA: PublicKey + tokenOwnerAccountB: PublicKey + tokenVaultA: PublicKey + tokenVaultB: PublicKey + tickArrayLower: PublicKey + tickArrayUpper: PublicKey +} + +export const layout = borsh.struct([ + borsh.u128("liquidityAmount"), + borsh.u64("tokenMinA"), + borsh.u64("tokenMinB"), + borsh.option(types.RemainingAccountsInfo.layout(), "remainingAccountsInfo"), +]) + +export function decreaseLiquidityV2( + args: DecreaseLiquidityV2Args, + accounts: DecreaseLiquidityV2Accounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { + const keys: Array = [ + { pubkey: accounts.whirlpool, isSigner: false, isWritable: true }, + { pubkey: accounts.tokenProgramA, isSigner: false, isWritable: false }, + { pubkey: accounts.tokenProgramB, isSigner: false, isWritable: false }, + { pubkey: accounts.memoProgram, isSigner: false, isWritable: false }, + { pubkey: accounts.positionAuthority, isSigner: true, isWritable: false }, + { pubkey: accounts.position, isSigner: false, isWritable: true }, + { + pubkey: accounts.positionTokenAccount, + isSigner: false, + isWritable: false, + }, + { pubkey: accounts.tokenMintA, isSigner: false, isWritable: false }, + { pubkey: accounts.tokenMintB, isSigner: false, isWritable: false }, + { pubkey: accounts.tokenOwnerAccountA, isSigner: false, isWritable: true }, + { pubkey: accounts.tokenOwnerAccountB, isSigner: false, isWritable: true }, + { pubkey: accounts.tokenVaultA, isSigner: false, isWritable: true }, + { pubkey: accounts.tokenVaultB, isSigner: false, isWritable: true }, + { pubkey: accounts.tickArrayLower, isSigner: false, isWritable: true }, + { pubkey: accounts.tickArrayUpper, isSigner: false, isWritable: true }, + ] + const identifier = Buffer.from([58, 127, 188, 62, 79, 82, 196, 96]) + const buffer = Buffer.alloc(1000) + const len = layout.encode( + { + liquidityAmount: args.liquidityAmount, + tokenMinA: args.tokenMinA, + tokenMinB: args.tokenMinB, + remainingAccountsInfo: + (args.remainingAccountsInfo && + types.RemainingAccountsInfo.toEncodable( + args.remainingAccountsInfo + )) || + null, + }, + buffer + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix +} diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/deletePositionBundle.ts b/packages/kamino-sdk/src/whirpools-client/instructions/deletePositionBundle.ts new file mode 100644 index 00000000..8a97fef6 --- /dev/null +++ b/packages/kamino-sdk/src/whirpools-client/instructions/deletePositionBundle.ts @@ -0,0 +1,36 @@ +import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 DeletePositionBundleAccounts { + positionBundle: PublicKey + positionBundleMint: PublicKey + positionBundleTokenAccount: PublicKey + positionBundleOwner: PublicKey + receiver: PublicKey + tokenProgram: PublicKey +} + +export function deletePositionBundle( + accounts: DeletePositionBundleAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { + const keys: Array = [ + { pubkey: accounts.positionBundle, isSigner: false, isWritable: true }, + { pubkey: accounts.positionBundleMint, isSigner: false, isWritable: true }, + { + pubkey: accounts.positionBundleTokenAccount, + isSigner: false, + isWritable: true, + }, + { pubkey: accounts.positionBundleOwner, isSigner: true, isWritable: false }, + { pubkey: accounts.receiver, isSigner: false, isWritable: true }, + { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false }, + ] + const identifier = Buffer.from([100, 25, 99, 2, 217, 239, 124, 173]) + const data = identifier + const ix = new TransactionInstruction({ keys, programId, data }) + return ix +} diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/deleteTokenBadge.ts b/packages/kamino-sdk/src/whirpools-client/instructions/deleteTokenBadge.ts new file mode 100644 index 00000000..73b1c9d9 --- /dev/null +++ b/packages/kamino-sdk/src/whirpools-client/instructions/deleteTokenBadge.ts @@ -0,0 +1,36 @@ +import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 DeleteTokenBadgeAccounts { + whirlpoolsConfig: PublicKey + whirlpoolsConfigExtension: PublicKey + tokenBadgeAuthority: PublicKey + tokenMint: PublicKey + tokenBadge: PublicKey + receiver: PublicKey +} + +export function deleteTokenBadge( + accounts: DeleteTokenBadgeAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { + const keys: Array = [ + { pubkey: accounts.whirlpoolsConfig, isSigner: false, isWritable: false }, + { + pubkey: accounts.whirlpoolsConfigExtension, + isSigner: false, + isWritable: false, + }, + { pubkey: accounts.tokenBadgeAuthority, isSigner: true, isWritable: false }, + { pubkey: accounts.tokenMint, isSigner: false, isWritable: false }, + { pubkey: accounts.tokenBadge, isSigner: false, isWritable: true }, + { pubkey: accounts.receiver, isSigner: false, isWritable: true }, + ] + const identifier = Buffer.from([53, 146, 68, 8, 18, 117, 17, 185]) + const data = identifier + const ix = new TransactionInstruction({ keys, programId, data }) + return ix +} diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/increaseLiquidity.ts b/packages/kamino-sdk/src/whirpools-client/instructions/increaseLiquidity.ts index 67e4b05e..f709120e 100644 --- a/packages/kamino-sdk/src/whirpools-client/instructions/increaseLiquidity.ts +++ b/packages/kamino-sdk/src/whirpools-client/instructions/increaseLiquidity.ts @@ -1,32 +1,40 @@ -import { TransactionInstruction, PublicKey, AccountMeta } from '@solana/web3.js'; // eslint-disable-line @typescript-eslint/no-unused-vars -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 { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 IncreaseLiquidityArgs { - liquidityAmount: BN; - tokenMaxA: BN; - tokenMaxB: BN; + liquidityAmount: BN + tokenMaxA: BN + tokenMaxB: BN } export interface IncreaseLiquidityAccounts { - whirlpool: PublicKey; - tokenProgram: PublicKey; - positionAuthority: PublicKey; - position: PublicKey; - positionTokenAccount: PublicKey; - tokenOwnerAccountA: PublicKey; - tokenOwnerAccountB: PublicKey; - tokenVaultA: PublicKey; - tokenVaultB: PublicKey; - tickArrayLower: PublicKey; - tickArrayUpper: PublicKey; + whirlpool: PublicKey + tokenProgram: PublicKey + positionAuthority: PublicKey + position: PublicKey + positionTokenAccount: PublicKey + tokenOwnerAccountA: PublicKey + tokenOwnerAccountB: PublicKey + tokenVaultA: PublicKey + tokenVaultB: PublicKey + tickArrayLower: PublicKey + tickArrayUpper: PublicKey } -export const layout = borsh.struct([borsh.u128('liquidityAmount'), borsh.u64('tokenMaxA'), borsh.u64('tokenMaxB')]); +export const layout = borsh.struct([ + borsh.u128("liquidityAmount"), + borsh.u64("tokenMaxA"), + borsh.u64("tokenMaxB"), +]) -export function increaseLiquidity(args: IncreaseLiquidityArgs, accounts: IncreaseLiquidityAccounts) { +export function increaseLiquidity( + args: IncreaseLiquidityArgs, + accounts: IncreaseLiquidityAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { const keys: Array = [ { pubkey: accounts.whirlpool, isSigner: false, isWritable: true }, { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false }, @@ -43,9 +51,9 @@ export function increaseLiquidity(args: IncreaseLiquidityArgs, accounts: Increas { pubkey: accounts.tokenVaultB, isSigner: false, isWritable: true }, { pubkey: accounts.tickArrayLower, isSigner: false, isWritable: true }, { pubkey: accounts.tickArrayUpper, isSigner: false, isWritable: true }, - ]; - const identifier = Buffer.from([46, 156, 243, 118, 13, 205, 251, 178]); - const buffer = Buffer.alloc(1000); + ] + const identifier = Buffer.from([46, 156, 243, 118, 13, 205, 251, 178]) + const buffer = Buffer.alloc(1000) const len = layout.encode( { liquidityAmount: args.liquidityAmount, @@ -53,8 +61,8 @@ export function increaseLiquidity(args: IncreaseLiquidityArgs, accounts: Increas tokenMaxB: args.tokenMaxB, }, buffer - ); - const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len); - const ix = new TransactionInstruction({ keys, programId: WHIRLPOOL_PROGRAM_ID, data }); - return ix; + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix } diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/increaseLiquidityV2.ts b/packages/kamino-sdk/src/whirpools-client/instructions/increaseLiquidityV2.ts new file mode 100644 index 00000000..7882ffbf --- /dev/null +++ b/packages/kamino-sdk/src/whirpools-client/instructions/increaseLiquidityV2.ts @@ -0,0 +1,84 @@ +import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 IncreaseLiquidityV2Args { + liquidityAmount: BN + tokenMaxA: BN + tokenMaxB: BN + remainingAccountsInfo: types.RemainingAccountsInfoFields | null +} + +export interface IncreaseLiquidityV2Accounts { + whirlpool: PublicKey + tokenProgramA: PublicKey + tokenProgramB: PublicKey + memoProgram: PublicKey + positionAuthority: PublicKey + position: PublicKey + positionTokenAccount: PublicKey + tokenMintA: PublicKey + tokenMintB: PublicKey + tokenOwnerAccountA: PublicKey + tokenOwnerAccountB: PublicKey + tokenVaultA: PublicKey + tokenVaultB: PublicKey + tickArrayLower: PublicKey + tickArrayUpper: PublicKey +} + +export const layout = borsh.struct([ + borsh.u128("liquidityAmount"), + borsh.u64("tokenMaxA"), + borsh.u64("tokenMaxB"), + borsh.option(types.RemainingAccountsInfo.layout(), "remainingAccountsInfo"), +]) + +export function increaseLiquidityV2( + args: IncreaseLiquidityV2Args, + accounts: IncreaseLiquidityV2Accounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { + const keys: Array = [ + { pubkey: accounts.whirlpool, isSigner: false, isWritable: true }, + { pubkey: accounts.tokenProgramA, isSigner: false, isWritable: false }, + { pubkey: accounts.tokenProgramB, isSigner: false, isWritable: false }, + { pubkey: accounts.memoProgram, isSigner: false, isWritable: false }, + { pubkey: accounts.positionAuthority, isSigner: true, isWritable: false }, + { pubkey: accounts.position, isSigner: false, isWritable: true }, + { + pubkey: accounts.positionTokenAccount, + isSigner: false, + isWritable: false, + }, + { pubkey: accounts.tokenMintA, isSigner: false, isWritable: false }, + { pubkey: accounts.tokenMintB, isSigner: false, isWritable: false }, + { pubkey: accounts.tokenOwnerAccountA, isSigner: false, isWritable: true }, + { pubkey: accounts.tokenOwnerAccountB, isSigner: false, isWritable: true }, + { pubkey: accounts.tokenVaultA, isSigner: false, isWritable: true }, + { pubkey: accounts.tokenVaultB, isSigner: false, isWritable: true }, + { pubkey: accounts.tickArrayLower, isSigner: false, isWritable: true }, + { pubkey: accounts.tickArrayUpper, isSigner: false, isWritable: true }, + ] + const identifier = Buffer.from([133, 29, 89, 223, 69, 238, 176, 10]) + const buffer = Buffer.alloc(1000) + const len = layout.encode( + { + liquidityAmount: args.liquidityAmount, + tokenMaxA: args.tokenMaxA, + tokenMaxB: args.tokenMaxB, + remainingAccountsInfo: + (args.remainingAccountsInfo && + types.RemainingAccountsInfo.toEncodable( + args.remainingAccountsInfo + )) || + null, + }, + buffer + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix +} diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/index.ts b/packages/kamino-sdk/src/whirpools-client/instructions/index.ts index ce191e67..04133ef3 100644 --- a/packages/kamino-sdk/src/whirpools-client/instructions/index.ts +++ b/packages/kamino-sdk/src/whirpools-client/instructions/index.ts @@ -90,3 +90,72 @@ export type { } from "./setRewardAuthorityBySuperAuthority" export { setRewardEmissionsSuperAuthority } from "./setRewardEmissionsSuperAuthority" export type { SetRewardEmissionsSuperAuthorityAccounts } from "./setRewardEmissionsSuperAuthority" +export { twoHopSwap } from "./twoHopSwap" +export type { TwoHopSwapArgs, TwoHopSwapAccounts } from "./twoHopSwap" +export { initializePositionBundle } from "./initializePositionBundle" +export type { InitializePositionBundleAccounts } from "./initializePositionBundle" +export { initializePositionBundleWithMetadata } from "./initializePositionBundleWithMetadata" +export type { InitializePositionBundleWithMetadataAccounts } from "./initializePositionBundleWithMetadata" +export { deletePositionBundle } from "./deletePositionBundle" +export type { DeletePositionBundleAccounts } from "./deletePositionBundle" +export { openBundledPosition } from "./openBundledPosition" +export type { + OpenBundledPositionArgs, + OpenBundledPositionAccounts, +} from "./openBundledPosition" +export { closeBundledPosition } from "./closeBundledPosition" +export type { + CloseBundledPositionArgs, + CloseBundledPositionAccounts, +} from "./closeBundledPosition" +export { collectFeesV2 } from "./collectFeesV2" +export type { CollectFeesV2Args, CollectFeesV2Accounts } from "./collectFeesV2" +export { collectProtocolFeesV2 } from "./collectProtocolFeesV2" +export type { + CollectProtocolFeesV2Args, + CollectProtocolFeesV2Accounts, +} from "./collectProtocolFeesV2" +export { collectRewardV2 } from "./collectRewardV2" +export type { + CollectRewardV2Args, + CollectRewardV2Accounts, +} from "./collectRewardV2" +export { decreaseLiquidityV2 } from "./decreaseLiquidityV2" +export type { + DecreaseLiquidityV2Args, + DecreaseLiquidityV2Accounts, +} from "./decreaseLiquidityV2" +export { increaseLiquidityV2 } from "./increaseLiquidityV2" +export type { + IncreaseLiquidityV2Args, + IncreaseLiquidityV2Accounts, +} from "./increaseLiquidityV2" +export { initializePoolV2 } from "./initializePoolV2" +export type { + InitializePoolV2Args, + InitializePoolV2Accounts, +} from "./initializePoolV2" +export { initializeRewardV2 } from "./initializeRewardV2" +export type { + InitializeRewardV2Args, + InitializeRewardV2Accounts, +} from "./initializeRewardV2" +export { setRewardEmissionsV2 } from "./setRewardEmissionsV2" +export type { + SetRewardEmissionsV2Args, + SetRewardEmissionsV2Accounts, +} from "./setRewardEmissionsV2" +export { swapV2 } from "./swapV2" +export type { SwapV2Args, SwapV2Accounts } from "./swapV2" +export { twoHopSwapV2 } from "./twoHopSwapV2" +export type { TwoHopSwapV2Args, TwoHopSwapV2Accounts } from "./twoHopSwapV2" +export { initializeConfigExtension } from "./initializeConfigExtension" +export type { InitializeConfigExtensionAccounts } from "./initializeConfigExtension" +export { setConfigExtensionAuthority } from "./setConfigExtensionAuthority" +export type { SetConfigExtensionAuthorityAccounts } from "./setConfigExtensionAuthority" +export { setTokenBadgeAuthority } from "./setTokenBadgeAuthority" +export type { SetTokenBadgeAuthorityAccounts } from "./setTokenBadgeAuthority" +export { initializeTokenBadge } from "./initializeTokenBadge" +export type { InitializeTokenBadgeAccounts } from "./initializeTokenBadge" +export { deleteTokenBadge } from "./deleteTokenBadge" +export type { DeleteTokenBadgeAccounts } from "./deleteTokenBadge" diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/initializeConfig.ts b/packages/kamino-sdk/src/whirpools-client/instructions/initializeConfig.ts index 8290072b..9e91a1eb 100644 --- a/packages/kamino-sdk/src/whirpools-client/instructions/initializeConfig.ts +++ b/packages/kamino-sdk/src/whirpools-client/instructions/initializeConfig.ts @@ -1,37 +1,41 @@ -import { TransactionInstruction, PublicKey, AccountMeta } from '@solana/web3.js'; // eslint-disable-line @typescript-eslint/no-unused-vars -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 { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 InitializeConfigArgs { - feeAuthority: PublicKey; - collectProtocolFeesAuthority: PublicKey; - rewardEmissionsSuperAuthority: PublicKey; - defaultProtocolFeeRate: number; + feeAuthority: PublicKey + collectProtocolFeesAuthority: PublicKey + rewardEmissionsSuperAuthority: PublicKey + defaultProtocolFeeRate: number } export interface InitializeConfigAccounts { - config: PublicKey; - funder: PublicKey; - systemProgram: PublicKey; + config: PublicKey + funder: PublicKey + systemProgram: PublicKey } export const layout = borsh.struct([ - borsh.publicKey('feeAuthority'), - borsh.publicKey('collectProtocolFeesAuthority'), - borsh.publicKey('rewardEmissionsSuperAuthority'), - borsh.u16('defaultProtocolFeeRate'), -]); + borsh.publicKey("feeAuthority"), + borsh.publicKey("collectProtocolFeesAuthority"), + borsh.publicKey("rewardEmissionsSuperAuthority"), + borsh.u16("defaultProtocolFeeRate"), +]) -export function initializeConfig(args: InitializeConfigArgs, accounts: InitializeConfigAccounts) { +export function initializeConfig( + args: InitializeConfigArgs, + accounts: InitializeConfigAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { const keys: Array = [ { pubkey: accounts.config, isSigner: true, isWritable: true }, { pubkey: accounts.funder, isSigner: true, isWritable: true }, { pubkey: accounts.systemProgram, isSigner: false, isWritable: false }, - ]; - const identifier = Buffer.from([208, 127, 21, 1, 194, 190, 196, 70]); - const buffer = Buffer.alloc(1000); + ] + const identifier = Buffer.from([208, 127, 21, 1, 194, 190, 196, 70]) + const buffer = Buffer.alloc(1000) const len = layout.encode( { feeAuthority: args.feeAuthority, @@ -40,8 +44,8 @@ export function initializeConfig(args: InitializeConfigArgs, accounts: Initializ defaultProtocolFeeRate: args.defaultProtocolFeeRate, }, buffer - ); - const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len); - const ix = new TransactionInstruction({ keys, programId: WHIRLPOOL_PROGRAM_ID, data }); - return ix; + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix } diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/initializeConfigExtension.ts b/packages/kamino-sdk/src/whirpools-client/instructions/initializeConfigExtension.ts new file mode 100644 index 00000000..2bc0983d --- /dev/null +++ b/packages/kamino-sdk/src/whirpools-client/instructions/initializeConfigExtension.ts @@ -0,0 +1,30 @@ +import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 InitializeConfigExtensionAccounts { + config: PublicKey + configExtension: PublicKey + funder: PublicKey + feeAuthority: PublicKey + systemProgram: PublicKey +} + +export function initializeConfigExtension( + accounts: InitializeConfigExtensionAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { + const keys: Array = [ + { pubkey: accounts.config, isSigner: false, isWritable: false }, + { pubkey: accounts.configExtension, isSigner: false, isWritable: true }, + { pubkey: accounts.funder, isSigner: true, isWritable: true }, + { pubkey: accounts.feeAuthority, isSigner: true, isWritable: false }, + { pubkey: accounts.systemProgram, isSigner: false, isWritable: false }, + ] + const identifier = Buffer.from([55, 9, 53, 9, 114, 57, 209, 52]) + const data = identifier + const ix = new TransactionInstruction({ keys, programId, data }) + return ix +} diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/initializeFeeTier.ts b/packages/kamino-sdk/src/whirpools-client/instructions/initializeFeeTier.ts index 60c6a1c8..5f76a91f 100644 --- a/packages/kamino-sdk/src/whirpools-client/instructions/initializeFeeTier.ts +++ b/packages/kamino-sdk/src/whirpools-client/instructions/initializeFeeTier.ts @@ -1,42 +1,49 @@ -import { TransactionInstruction, PublicKey, AccountMeta } from '@solana/web3.js'; // eslint-disable-line @typescript-eslint/no-unused-vars -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 { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 InitializeFeeTierArgs { - tickSpacing: number; - defaultFeeRate: number; + tickSpacing: number + defaultFeeRate: number } export interface InitializeFeeTierAccounts { - config: PublicKey; - feeTier: PublicKey; - funder: PublicKey; - feeAuthority: PublicKey; - systemProgram: PublicKey; + config: PublicKey + feeTier: PublicKey + funder: PublicKey + feeAuthority: PublicKey + systemProgram: PublicKey } -export const layout = borsh.struct([borsh.u16('tickSpacing'), borsh.u16('defaultFeeRate')]); +export const layout = borsh.struct([ + borsh.u16("tickSpacing"), + borsh.u16("defaultFeeRate"), +]) -export function initializeFeeTier(args: InitializeFeeTierArgs, accounts: InitializeFeeTierAccounts) { +export function initializeFeeTier( + args: InitializeFeeTierArgs, + accounts: InitializeFeeTierAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { const keys: Array = [ { pubkey: accounts.config, isSigner: false, isWritable: false }, { pubkey: accounts.feeTier, isSigner: false, isWritable: true }, { pubkey: accounts.funder, isSigner: true, isWritable: true }, { pubkey: accounts.feeAuthority, isSigner: true, isWritable: false }, { pubkey: accounts.systemProgram, isSigner: false, isWritable: false }, - ]; - const identifier = Buffer.from([183, 74, 156, 160, 112, 2, 42, 30]); - const buffer = Buffer.alloc(1000); + ] + const identifier = Buffer.from([183, 74, 156, 160, 112, 2, 42, 30]) + const buffer = Buffer.alloc(1000) const len = layout.encode( { tickSpacing: args.tickSpacing, defaultFeeRate: args.defaultFeeRate, }, buffer - ); - const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len); - const ix = new TransactionInstruction({ keys, programId: WHIRLPOOL_PROGRAM_ID, data }); - return ix; + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix } diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/initializePool.ts b/packages/kamino-sdk/src/whirpools-client/instructions/initializePool.ts index aaba1bbb..1b8b137e 100644 --- a/packages/kamino-sdk/src/whirpools-client/instructions/initializePool.ts +++ b/packages/kamino-sdk/src/whirpools-client/instructions/initializePool.ts @@ -1,36 +1,40 @@ -import { TransactionInstruction, PublicKey, AccountMeta } from '@solana/web3.js'; // eslint-disable-line @typescript-eslint/no-unused-vars -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 { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 InitializePoolArgs { - bumps: types.WhirlpoolBumpsFields; - tickSpacing: number; - initialSqrtPrice: BN; + bumps: types.WhirlpoolBumpsFields + tickSpacing: number + initialSqrtPrice: BN } export interface InitializePoolAccounts { - whirlpoolsConfig: PublicKey; - tokenMintA: PublicKey; - tokenMintB: PublicKey; - funder: PublicKey; - whirlpool: PublicKey; - tokenVaultA: PublicKey; - tokenVaultB: PublicKey; - feeTier: PublicKey; - tokenProgram: PublicKey; - systemProgram: PublicKey; - rent: PublicKey; + whirlpoolsConfig: PublicKey + tokenMintA: PublicKey + tokenMintB: PublicKey + funder: PublicKey + whirlpool: PublicKey + tokenVaultA: PublicKey + tokenVaultB: PublicKey + feeTier: PublicKey + tokenProgram: PublicKey + systemProgram: PublicKey + rent: PublicKey } export const layout = borsh.struct([ - types.WhirlpoolBumps.layout('bumps'), - borsh.u16('tickSpacing'), - borsh.u128('initialSqrtPrice'), -]); + types.WhirlpoolBumps.layout("bumps"), + borsh.u16("tickSpacing"), + borsh.u128("initialSqrtPrice"), +]) -export function initializePool(args: InitializePoolArgs, accounts: InitializePoolAccounts) { +export function initializePool( + args: InitializePoolArgs, + accounts: InitializePoolAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { const keys: Array = [ { pubkey: accounts.whirlpoolsConfig, isSigner: false, isWritable: false }, { pubkey: accounts.tokenMintA, isSigner: false, isWritable: false }, @@ -43,9 +47,9 @@ export function initializePool(args: InitializePoolArgs, accounts: InitializePoo { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false }, { pubkey: accounts.systemProgram, isSigner: false, isWritable: false }, { pubkey: accounts.rent, isSigner: false, isWritable: false }, - ]; - const identifier = Buffer.from([95, 180, 10, 172, 84, 174, 232, 40]); - const buffer = Buffer.alloc(1000); + ] + const identifier = Buffer.from([95, 180, 10, 172, 84, 174, 232, 40]) + const buffer = Buffer.alloc(1000) const len = layout.encode( { bumps: types.WhirlpoolBumps.toEncodable(args.bumps), @@ -53,8 +57,8 @@ export function initializePool(args: InitializePoolArgs, accounts: InitializePoo initialSqrtPrice: args.initialSqrtPrice, }, buffer - ); - const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len); - const ix = new TransactionInstruction({ keys, programId: WHIRLPOOL_PROGRAM_ID, data }); - return ix; + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix } diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/initializePoolV2.ts b/packages/kamino-sdk/src/whirpools-client/instructions/initializePoolV2.ts new file mode 100644 index 00000000..20da0b7e --- /dev/null +++ b/packages/kamino-sdk/src/whirpools-client/instructions/initializePoolV2.ts @@ -0,0 +1,67 @@ +import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 InitializePoolV2Args { + tickSpacing: number + initialSqrtPrice: BN +} + +export interface InitializePoolV2Accounts { + whirlpoolsConfig: PublicKey + tokenMintA: PublicKey + tokenMintB: PublicKey + tokenBadgeA: PublicKey + tokenBadgeB: PublicKey + funder: PublicKey + whirlpool: PublicKey + tokenVaultA: PublicKey + tokenVaultB: PublicKey + feeTier: PublicKey + tokenProgramA: PublicKey + tokenProgramB: PublicKey + systemProgram: PublicKey + rent: PublicKey +} + +export const layout = borsh.struct([ + borsh.u16("tickSpacing"), + borsh.u128("initialSqrtPrice"), +]) + +export function initializePoolV2( + args: InitializePoolV2Args, + accounts: InitializePoolV2Accounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { + const keys: Array = [ + { pubkey: accounts.whirlpoolsConfig, isSigner: false, isWritable: false }, + { pubkey: accounts.tokenMintA, isSigner: false, isWritable: false }, + { pubkey: accounts.tokenMintB, isSigner: false, isWritable: false }, + { pubkey: accounts.tokenBadgeA, isSigner: false, isWritable: false }, + { pubkey: accounts.tokenBadgeB, isSigner: false, isWritable: false }, + { pubkey: accounts.funder, isSigner: true, isWritable: true }, + { pubkey: accounts.whirlpool, isSigner: false, isWritable: true }, + { pubkey: accounts.tokenVaultA, isSigner: true, isWritable: true }, + { pubkey: accounts.tokenVaultB, isSigner: true, isWritable: true }, + { pubkey: accounts.feeTier, isSigner: false, isWritable: false }, + { pubkey: accounts.tokenProgramA, isSigner: false, isWritable: false }, + { pubkey: accounts.tokenProgramB, isSigner: false, isWritable: false }, + { pubkey: accounts.systemProgram, isSigner: false, isWritable: false }, + { pubkey: accounts.rent, isSigner: false, isWritable: false }, + ] + const identifier = Buffer.from([207, 45, 87, 242, 27, 63, 204, 67]) + const buffer = Buffer.alloc(1000) + const len = layout.encode( + { + tickSpacing: args.tickSpacing, + initialSqrtPrice: args.initialSqrtPrice, + }, + buffer + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix +} diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/initializePositionBundle.ts b/packages/kamino-sdk/src/whirpools-client/instructions/initializePositionBundle.ts new file mode 100644 index 00000000..8cd38f78 --- /dev/null +++ b/packages/kamino-sdk/src/whirpools-client/instructions/initializePositionBundle.ts @@ -0,0 +1,50 @@ +import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 InitializePositionBundleAccounts { + positionBundle: PublicKey + positionBundleMint: PublicKey + positionBundleTokenAccount: PublicKey + positionBundleOwner: PublicKey + funder: PublicKey + tokenProgram: PublicKey + systemProgram: PublicKey + rent: PublicKey + associatedTokenProgram: PublicKey +} + +export function initializePositionBundle( + accounts: InitializePositionBundleAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { + const keys: Array = [ + { pubkey: accounts.positionBundle, isSigner: false, isWritable: true }, + { pubkey: accounts.positionBundleMint, isSigner: true, isWritable: true }, + { + pubkey: accounts.positionBundleTokenAccount, + isSigner: false, + isWritable: true, + }, + { + pubkey: accounts.positionBundleOwner, + isSigner: false, + isWritable: false, + }, + { pubkey: accounts.funder, isSigner: true, isWritable: true }, + { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false }, + { pubkey: accounts.systemProgram, isSigner: false, isWritable: false }, + { pubkey: accounts.rent, isSigner: false, isWritable: false }, + { + pubkey: accounts.associatedTokenProgram, + isSigner: false, + isWritable: false, + }, + ] + const identifier = Buffer.from([117, 45, 241, 149, 24, 18, 194, 65]) + const data = identifier + const ix = new TransactionInstruction({ keys, programId, data }) + return ix +} diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/initializePositionBundleWithMetadata.ts b/packages/kamino-sdk/src/whirpools-client/instructions/initializePositionBundleWithMetadata.ts new file mode 100644 index 00000000..966e046a --- /dev/null +++ b/packages/kamino-sdk/src/whirpools-client/instructions/initializePositionBundleWithMetadata.ts @@ -0,0 +1,60 @@ +import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 InitializePositionBundleWithMetadataAccounts { + positionBundle: PublicKey + positionBundleMint: PublicKey + positionBundleMetadata: PublicKey + positionBundleTokenAccount: PublicKey + positionBundleOwner: PublicKey + funder: PublicKey + metadataUpdateAuth: PublicKey + tokenProgram: PublicKey + systemProgram: PublicKey + rent: PublicKey + associatedTokenProgram: PublicKey + metadataProgram: PublicKey +} + +export function initializePositionBundleWithMetadata( + accounts: InitializePositionBundleWithMetadataAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { + const keys: Array = [ + { pubkey: accounts.positionBundle, isSigner: false, isWritable: true }, + { pubkey: accounts.positionBundleMint, isSigner: true, isWritable: true }, + { + pubkey: accounts.positionBundleMetadata, + isSigner: false, + isWritable: true, + }, + { + pubkey: accounts.positionBundleTokenAccount, + isSigner: false, + isWritable: true, + }, + { + pubkey: accounts.positionBundleOwner, + isSigner: false, + isWritable: false, + }, + { pubkey: accounts.funder, isSigner: true, isWritable: true }, + { pubkey: accounts.metadataUpdateAuth, isSigner: false, isWritable: false }, + { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false }, + { pubkey: accounts.systemProgram, isSigner: false, isWritable: false }, + { pubkey: accounts.rent, isSigner: false, isWritable: false }, + { + pubkey: accounts.associatedTokenProgram, + isSigner: false, + isWritable: false, + }, + { pubkey: accounts.metadataProgram, isSigner: false, isWritable: false }, + ] + const identifier = Buffer.from([93, 124, 16, 179, 249, 131, 115, 245]) + const data = identifier + const ix = new TransactionInstruction({ keys, programId, data }) + return ix +} diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/initializeReward.ts b/packages/kamino-sdk/src/whirpools-client/instructions/initializeReward.ts index 54243bd8..cd0b84a0 100644 --- a/packages/kamino-sdk/src/whirpools-client/instructions/initializeReward.ts +++ b/packages/kamino-sdk/src/whirpools-client/instructions/initializeReward.ts @@ -1,27 +1,31 @@ -import { TransactionInstruction, PublicKey, AccountMeta } from '@solana/web3.js'; // eslint-disable-line @typescript-eslint/no-unused-vars -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 { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 InitializeRewardArgs { - rewardIndex: number; + rewardIndex: number } export interface InitializeRewardAccounts { - rewardAuthority: PublicKey; - funder: PublicKey; - whirlpool: PublicKey; - rewardMint: PublicKey; - rewardVault: PublicKey; - tokenProgram: PublicKey; - systemProgram: PublicKey; - rent: PublicKey; + rewardAuthority: PublicKey + funder: PublicKey + whirlpool: PublicKey + rewardMint: PublicKey + rewardVault: PublicKey + tokenProgram: PublicKey + systemProgram: PublicKey + rent: PublicKey } -export const layout = borsh.struct([borsh.u8('rewardIndex')]); +export const layout = borsh.struct([borsh.u8("rewardIndex")]) -export function initializeReward(args: InitializeRewardArgs, accounts: InitializeRewardAccounts) { +export function initializeReward( + args: InitializeRewardArgs, + accounts: InitializeRewardAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { const keys: Array = [ { pubkey: accounts.rewardAuthority, isSigner: true, isWritable: false }, { pubkey: accounts.funder, isSigner: true, isWritable: true }, @@ -31,16 +35,16 @@ export function initializeReward(args: InitializeRewardArgs, accounts: Initializ { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false }, { pubkey: accounts.systemProgram, isSigner: false, isWritable: false }, { pubkey: accounts.rent, isSigner: false, isWritable: false }, - ]; - const identifier = Buffer.from([95, 135, 192, 196, 242, 129, 230, 68]); - const buffer = Buffer.alloc(1000); + ] + const identifier = Buffer.from([95, 135, 192, 196, 242, 129, 230, 68]) + const buffer = Buffer.alloc(1000) const len = layout.encode( { rewardIndex: args.rewardIndex, }, buffer - ); - const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len); - const ix = new TransactionInstruction({ keys, programId: WHIRLPOOL_PROGRAM_ID, data }); - return ix; + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix } diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/initializeRewardV2.ts b/packages/kamino-sdk/src/whirpools-client/instructions/initializeRewardV2.ts new file mode 100644 index 00000000..f8afd3bb --- /dev/null +++ b/packages/kamino-sdk/src/whirpools-client/instructions/initializeRewardV2.ts @@ -0,0 +1,52 @@ +import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 InitializeRewardV2Args { + rewardIndex: number +} + +export interface InitializeRewardV2Accounts { + rewardAuthority: PublicKey + funder: PublicKey + whirlpool: PublicKey + rewardMint: PublicKey + rewardTokenBadge: PublicKey + rewardVault: PublicKey + rewardTokenProgram: PublicKey + systemProgram: PublicKey + rent: PublicKey +} + +export const layout = borsh.struct([borsh.u8("rewardIndex")]) + +export function initializeRewardV2( + args: InitializeRewardV2Args, + accounts: InitializeRewardV2Accounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { + const keys: Array = [ + { pubkey: accounts.rewardAuthority, isSigner: true, isWritable: false }, + { pubkey: accounts.funder, isSigner: true, isWritable: true }, + { pubkey: accounts.whirlpool, isSigner: false, isWritable: true }, + { pubkey: accounts.rewardMint, isSigner: false, isWritable: false }, + { pubkey: accounts.rewardTokenBadge, isSigner: false, isWritable: false }, + { pubkey: accounts.rewardVault, isSigner: true, isWritable: true }, + { pubkey: accounts.rewardTokenProgram, isSigner: false, isWritable: false }, + { pubkey: accounts.systemProgram, isSigner: false, isWritable: false }, + { pubkey: accounts.rent, isSigner: false, isWritable: false }, + ] + const identifier = Buffer.from([91, 1, 77, 50, 235, 229, 133, 49]) + const buffer = Buffer.alloc(1000) + const len = layout.encode( + { + rewardIndex: args.rewardIndex, + }, + buffer + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix +} diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/initializeTickArray.ts b/packages/kamino-sdk/src/whirpools-client/instructions/initializeTickArray.ts index 3d5cdbff..a78d4fc9 100644 --- a/packages/kamino-sdk/src/whirpools-client/instructions/initializeTickArray.ts +++ b/packages/kamino-sdk/src/whirpools-client/instructions/initializeTickArray.ts @@ -1,38 +1,42 @@ -import { TransactionInstruction, PublicKey, AccountMeta } from '@solana/web3.js'; // eslint-disable-line @typescript-eslint/no-unused-vars -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 { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 InitializeTickArrayArgs { - startTickIndex: number; + startTickIndex: number } export interface InitializeTickArrayAccounts { - whirlpool: PublicKey; - funder: PublicKey; - tickArray: PublicKey; - systemProgram: PublicKey; + whirlpool: PublicKey + funder: PublicKey + tickArray: PublicKey + systemProgram: PublicKey } -export const layout = borsh.struct([borsh.i32('startTickIndex')]); +export const layout = borsh.struct([borsh.i32("startTickIndex")]) -export function initializeTickArray(args: InitializeTickArrayArgs, accounts: InitializeTickArrayAccounts) { +export function initializeTickArray( + args: InitializeTickArrayArgs, + accounts: InitializeTickArrayAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { const keys: Array = [ { pubkey: accounts.whirlpool, isSigner: false, isWritable: false }, { pubkey: accounts.funder, isSigner: true, isWritable: true }, { pubkey: accounts.tickArray, isSigner: false, isWritable: true }, { pubkey: accounts.systemProgram, isSigner: false, isWritable: false }, - ]; - const identifier = Buffer.from([11, 188, 193, 214, 141, 91, 149, 184]); - const buffer = Buffer.alloc(1000); + ] + const identifier = Buffer.from([11, 188, 193, 214, 141, 91, 149, 184]) + const buffer = Buffer.alloc(1000) const len = layout.encode( { startTickIndex: args.startTickIndex, }, buffer - ); - const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len); - const ix = new TransactionInstruction({ keys, programId: WHIRLPOOL_PROGRAM_ID, data }); - return ix; + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix } diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/initializeTokenBadge.ts b/packages/kamino-sdk/src/whirpools-client/instructions/initializeTokenBadge.ts new file mode 100644 index 00000000..1bd8aba0 --- /dev/null +++ b/packages/kamino-sdk/src/whirpools-client/instructions/initializeTokenBadge.ts @@ -0,0 +1,38 @@ +import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 InitializeTokenBadgeAccounts { + whirlpoolsConfig: PublicKey + whirlpoolsConfigExtension: PublicKey + tokenBadgeAuthority: PublicKey + tokenMint: PublicKey + tokenBadge: PublicKey + funder: PublicKey + systemProgram: PublicKey +} + +export function initializeTokenBadge( + accounts: InitializeTokenBadgeAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { + const keys: Array = [ + { pubkey: accounts.whirlpoolsConfig, isSigner: false, isWritable: false }, + { + pubkey: accounts.whirlpoolsConfigExtension, + isSigner: false, + isWritable: false, + }, + { pubkey: accounts.tokenBadgeAuthority, isSigner: true, isWritable: false }, + { pubkey: accounts.tokenMint, isSigner: false, isWritable: false }, + { pubkey: accounts.tokenBadge, isSigner: false, isWritable: true }, + { pubkey: accounts.funder, isSigner: true, isWritable: true }, + { pubkey: accounts.systemProgram, isSigner: false, isWritable: false }, + ] + const identifier = Buffer.from([253, 77, 205, 95, 27, 224, 89, 223]) + const data = identifier + const ix = new TransactionInstruction({ keys, programId, data }) + return ix +} diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/openBundledPosition.ts b/packages/kamino-sdk/src/whirpools-client/instructions/openBundledPosition.ts new file mode 100644 index 00000000..d2be7d40 --- /dev/null +++ b/packages/kamino-sdk/src/whirpools-client/instructions/openBundledPosition.ts @@ -0,0 +1,66 @@ +import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 OpenBundledPositionArgs { + bundleIndex: number + tickLowerIndex: number + tickUpperIndex: number +} + +export interface OpenBundledPositionAccounts { + bundledPosition: PublicKey + positionBundle: PublicKey + positionBundleTokenAccount: PublicKey + positionBundleAuthority: PublicKey + whirlpool: PublicKey + funder: PublicKey + systemProgram: PublicKey + rent: PublicKey +} + +export const layout = borsh.struct([ + borsh.u16("bundleIndex"), + borsh.i32("tickLowerIndex"), + borsh.i32("tickUpperIndex"), +]) + +export function openBundledPosition( + args: OpenBundledPositionArgs, + accounts: OpenBundledPositionAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { + const keys: Array = [ + { pubkey: accounts.bundledPosition, isSigner: false, isWritable: true }, + { pubkey: accounts.positionBundle, isSigner: false, isWritable: true }, + { + pubkey: accounts.positionBundleTokenAccount, + isSigner: false, + isWritable: false, + }, + { + pubkey: accounts.positionBundleAuthority, + isSigner: true, + isWritable: false, + }, + { pubkey: accounts.whirlpool, isSigner: false, isWritable: false }, + { pubkey: accounts.funder, isSigner: true, isWritable: true }, + { pubkey: accounts.systemProgram, isSigner: false, isWritable: false }, + { pubkey: accounts.rent, isSigner: false, isWritable: false }, + ] + const identifier = Buffer.from([169, 113, 126, 171, 213, 172, 212, 49]) + const buffer = Buffer.alloc(1000) + const len = layout.encode( + { + bundleIndex: args.bundleIndex, + tickLowerIndex: args.tickLowerIndex, + tickUpperIndex: args.tickUpperIndex, + }, + buffer + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix +} diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/openPosition.ts b/packages/kamino-sdk/src/whirpools-client/instructions/openPosition.ts index 97675e95..7416cc0a 100644 --- a/packages/kamino-sdk/src/whirpools-client/instructions/openPosition.ts +++ b/packages/kamino-sdk/src/whirpools-client/instructions/openPosition.ts @@ -1,35 +1,39 @@ -import { TransactionInstruction, PublicKey, AccountMeta } from '@solana/web3.js'; // eslint-disable-line @typescript-eslint/no-unused-vars -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 { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 OpenPositionArgs { - bumps: types.OpenPositionBumpsFields; - tickLowerIndex: number; - tickUpperIndex: number; + bumps: types.OpenPositionBumpsFields + tickLowerIndex: number + tickUpperIndex: number } export interface OpenPositionAccounts { - funder: PublicKey; - owner: PublicKey; - position: PublicKey; - positionMint: PublicKey; - positionTokenAccount: PublicKey; - whirlpool: PublicKey; - tokenProgram: PublicKey; - systemProgram: PublicKey; - rent: PublicKey; - associatedTokenProgram: PublicKey; + funder: PublicKey + owner: PublicKey + position: PublicKey + positionMint: PublicKey + positionTokenAccount: PublicKey + whirlpool: PublicKey + tokenProgram: PublicKey + systemProgram: PublicKey + rent: PublicKey + associatedTokenProgram: PublicKey } export const layout = borsh.struct([ - types.OpenPositionBumps.layout('bumps'), - borsh.i32('tickLowerIndex'), - borsh.i32('tickUpperIndex'), -]); + types.OpenPositionBumps.layout("bumps"), + borsh.i32("tickLowerIndex"), + borsh.i32("tickUpperIndex"), +]) -export function openPosition(args: OpenPositionArgs, accounts: OpenPositionAccounts) { +export function openPosition( + args: OpenPositionArgs, + accounts: OpenPositionAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { const keys: Array = [ { pubkey: accounts.funder, isSigner: true, isWritable: true }, { pubkey: accounts.owner, isSigner: false, isWritable: false }, @@ -49,9 +53,9 @@ export function openPosition(args: OpenPositionArgs, accounts: OpenPositionAccou isSigner: false, isWritable: false, }, - ]; - const identifier = Buffer.from([135, 128, 47, 77, 15, 152, 240, 49]); - const buffer = Buffer.alloc(1000); + ] + const identifier = Buffer.from([135, 128, 47, 77, 15, 152, 240, 49]) + const buffer = Buffer.alloc(1000) const len = layout.encode( { bumps: types.OpenPositionBumps.toEncodable(args.bumps), @@ -59,8 +63,8 @@ export function openPosition(args: OpenPositionArgs, accounts: OpenPositionAccou tickUpperIndex: args.tickUpperIndex, }, buffer - ); - const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len); - const ix = new TransactionInstruction({ keys, programId: WHIRLPOOL_PROGRAM_ID, data }); - return ix; + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix } diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/openPositionWithMetadata.ts b/packages/kamino-sdk/src/whirpools-client/instructions/openPositionWithMetadata.ts index fe63795e..9c4bbed8 100644 --- a/packages/kamino-sdk/src/whirpools-client/instructions/openPositionWithMetadata.ts +++ b/packages/kamino-sdk/src/whirpools-client/instructions/openPositionWithMetadata.ts @@ -1,40 +1,41 @@ -import { TransactionInstruction, PublicKey, AccountMeta } from '@solana/web3.js'; // eslint-disable-line @typescript-eslint/no-unused-vars -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 { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 OpenPositionWithMetadataArgs { - bumps: types.OpenPositionWithMetadataBumpsFields; - tickLowerIndex: number; - tickUpperIndex: number; + bumps: types.OpenPositionWithMetadataBumpsFields + tickLowerIndex: number + tickUpperIndex: number } export interface OpenPositionWithMetadataAccounts { - funder: PublicKey; - owner: PublicKey; - position: PublicKey; - positionMint: PublicKey; - positionMetadataAccount: PublicKey; - positionTokenAccount: PublicKey; - whirlpool: PublicKey; - tokenProgram: PublicKey; - systemProgram: PublicKey; - rent: PublicKey; - associatedTokenProgram: PublicKey; - metadataProgram: PublicKey; - metadataUpdateAuth: PublicKey; + funder: PublicKey + owner: PublicKey + position: PublicKey + positionMint: PublicKey + positionMetadataAccount: PublicKey + positionTokenAccount: PublicKey + whirlpool: PublicKey + tokenProgram: PublicKey + systemProgram: PublicKey + rent: PublicKey + associatedTokenProgram: PublicKey + metadataProgram: PublicKey + metadataUpdateAuth: PublicKey } export const layout = borsh.struct([ - types.OpenPositionWithMetadataBumps.layout('bumps'), - borsh.i32('tickLowerIndex'), - borsh.i32('tickUpperIndex'), -]); + types.OpenPositionWithMetadataBumps.layout("bumps"), + borsh.i32("tickLowerIndex"), + borsh.i32("tickUpperIndex"), +]) export function openPositionWithMetadata( args: OpenPositionWithMetadataArgs, - accounts: OpenPositionWithMetadataAccounts + accounts: OpenPositionWithMetadataAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID ) { const keys: Array = [ { pubkey: accounts.funder, isSigner: true, isWritable: true }, @@ -62,9 +63,9 @@ export function openPositionWithMetadata( }, { pubkey: accounts.metadataProgram, isSigner: false, isWritable: false }, { pubkey: accounts.metadataUpdateAuth, isSigner: false, isWritable: false }, - ]; - const identifier = Buffer.from([242, 29, 134, 48, 58, 110, 14, 60]); - const buffer = Buffer.alloc(1000); + ] + const identifier = Buffer.from([242, 29, 134, 48, 58, 110, 14, 60]) + const buffer = Buffer.alloc(1000) const len = layout.encode( { bumps: types.OpenPositionWithMetadataBumps.toEncodable(args.bumps), @@ -72,8 +73,8 @@ export function openPositionWithMetadata( tickUpperIndex: args.tickUpperIndex, }, buffer - ); - const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len); - const ix = new TransactionInstruction({ keys, programId: WHIRLPOOL_PROGRAM_ID, data }); - return ix; + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix } diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/setCollectProtocolFeesAuthority.ts b/packages/kamino-sdk/src/whirpools-client/instructions/setCollectProtocolFeesAuthority.ts index 9c14e15d..8353e085 100644 --- a/packages/kamino-sdk/src/whirpools-client/instructions/setCollectProtocolFeesAuthority.ts +++ b/packages/kamino-sdk/src/whirpools-client/instructions/setCollectProtocolFeesAuthority.ts @@ -1,16 +1,19 @@ -import { TransactionInstruction, PublicKey, AccountMeta } from '@solana/web3.js'; // eslint-disable-line @typescript-eslint/no-unused-vars -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 { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 SetCollectProtocolFeesAuthorityAccounts { - whirlpoolsConfig: PublicKey; - collectProtocolFeesAuthority: PublicKey; - newCollectProtocolFeesAuthority: PublicKey; + whirlpoolsConfig: PublicKey + collectProtocolFeesAuthority: PublicKey + newCollectProtocolFeesAuthority: PublicKey } -export function setCollectProtocolFeesAuthority(accounts: SetCollectProtocolFeesAuthorityAccounts) { +export function setCollectProtocolFeesAuthority( + accounts: SetCollectProtocolFeesAuthorityAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { const keys: Array = [ { pubkey: accounts.whirlpoolsConfig, isSigner: false, isWritable: true }, { @@ -23,9 +26,9 @@ export function setCollectProtocolFeesAuthority(accounts: SetCollectProtocolFees isSigner: false, isWritable: false, }, - ]; - const identifier = Buffer.from([34, 150, 93, 244, 139, 225, 233, 67]); - const data = identifier; - const ix = new TransactionInstruction({ keys, programId: WHIRLPOOL_PROGRAM_ID, data }); - return ix; + ] + const identifier = Buffer.from([34, 150, 93, 244, 139, 225, 233, 67]) + const data = identifier + const ix = new TransactionInstruction({ keys, programId, data }) + return ix } diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/setConfigExtensionAuthority.ts b/packages/kamino-sdk/src/whirpools-client/instructions/setConfigExtensionAuthority.ts new file mode 100644 index 00000000..9899c77c --- /dev/null +++ b/packages/kamino-sdk/src/whirpools-client/instructions/setConfigExtensionAuthority.ts @@ -0,0 +1,40 @@ +import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 SetConfigExtensionAuthorityAccounts { + whirlpoolsConfig: PublicKey + whirlpoolsConfigExtension: PublicKey + configExtensionAuthority: PublicKey + newConfigExtensionAuthority: PublicKey +} + +export function setConfigExtensionAuthority( + accounts: SetConfigExtensionAuthorityAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { + const keys: Array = [ + { pubkey: accounts.whirlpoolsConfig, isSigner: false, isWritable: false }, + { + pubkey: accounts.whirlpoolsConfigExtension, + isSigner: false, + isWritable: true, + }, + { + pubkey: accounts.configExtensionAuthority, + isSigner: true, + isWritable: false, + }, + { + pubkey: accounts.newConfigExtensionAuthority, + isSigner: false, + isWritable: false, + }, + ] + const identifier = Buffer.from([44, 94, 241, 116, 24, 188, 60, 143]) + const data = identifier + const ix = new TransactionInstruction({ keys, programId, data }) + return ix +} diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/setDefaultFeeRate.ts b/packages/kamino-sdk/src/whirpools-client/instructions/setDefaultFeeRate.ts index f54f27ea..8b64e380 100644 --- a/packages/kamino-sdk/src/whirpools-client/instructions/setDefaultFeeRate.ts +++ b/packages/kamino-sdk/src/whirpools-client/instructions/setDefaultFeeRate.ts @@ -1,36 +1,40 @@ -import { TransactionInstruction, PublicKey, AccountMeta } from '@solana/web3.js'; // eslint-disable-line @typescript-eslint/no-unused-vars -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 { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 SetDefaultFeeRateArgs { - defaultFeeRate: number; + defaultFeeRate: number } export interface SetDefaultFeeRateAccounts { - whirlpoolsConfig: PublicKey; - feeTier: PublicKey; - feeAuthority: PublicKey; + whirlpoolsConfig: PublicKey + feeTier: PublicKey + feeAuthority: PublicKey } -export const layout = borsh.struct([borsh.u16('defaultFeeRate')]); +export const layout = borsh.struct([borsh.u16("defaultFeeRate")]) -export function setDefaultFeeRate(args: SetDefaultFeeRateArgs, accounts: SetDefaultFeeRateAccounts) { +export function setDefaultFeeRate( + args: SetDefaultFeeRateArgs, + accounts: SetDefaultFeeRateAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { const keys: Array = [ { pubkey: accounts.whirlpoolsConfig, isSigner: false, isWritable: false }, { pubkey: accounts.feeTier, isSigner: false, isWritable: true }, { pubkey: accounts.feeAuthority, isSigner: true, isWritable: false }, - ]; - const identifier = Buffer.from([118, 215, 214, 157, 182, 229, 208, 228]); - const buffer = Buffer.alloc(1000); + ] + const identifier = Buffer.from([118, 215, 214, 157, 182, 229, 208, 228]) + const buffer = Buffer.alloc(1000) const len = layout.encode( { defaultFeeRate: args.defaultFeeRate, }, buffer - ); - const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len); - const ix = new TransactionInstruction({ keys, programId: WHIRLPOOL_PROGRAM_ID, data }); - return ix; + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix } diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/setDefaultProtocolFeeRate.ts b/packages/kamino-sdk/src/whirpools-client/instructions/setDefaultProtocolFeeRate.ts index 718e0ce6..3fea7a03 100644 --- a/packages/kamino-sdk/src/whirpools-client/instructions/setDefaultProtocolFeeRate.ts +++ b/packages/kamino-sdk/src/whirpools-client/instructions/setDefaultProtocolFeeRate.ts @@ -1,37 +1,38 @@ -import { TransactionInstruction, PublicKey, AccountMeta } from '@solana/web3.js'; // eslint-disable-line @typescript-eslint/no-unused-vars -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 { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 SetDefaultProtocolFeeRateArgs { - defaultProtocolFeeRate: number; + defaultProtocolFeeRate: number } export interface SetDefaultProtocolFeeRateAccounts { - whirlpoolsConfig: PublicKey; - feeAuthority: PublicKey; + whirlpoolsConfig: PublicKey + feeAuthority: PublicKey } -export const layout = borsh.struct([borsh.u16('defaultProtocolFeeRate')]); +export const layout = borsh.struct([borsh.u16("defaultProtocolFeeRate")]) export function setDefaultProtocolFeeRate( args: SetDefaultProtocolFeeRateArgs, - accounts: SetDefaultProtocolFeeRateAccounts + accounts: SetDefaultProtocolFeeRateAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID ) { const keys: Array = [ { pubkey: accounts.whirlpoolsConfig, isSigner: false, isWritable: true }, { pubkey: accounts.feeAuthority, isSigner: true, isWritable: false }, - ]; - const identifier = Buffer.from([107, 205, 249, 226, 151, 35, 86, 0]); - const buffer = Buffer.alloc(1000); + ] + const identifier = Buffer.from([107, 205, 249, 226, 151, 35, 86, 0]) + const buffer = Buffer.alloc(1000) const len = layout.encode( { defaultProtocolFeeRate: args.defaultProtocolFeeRate, }, buffer - ); - const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len); - const ix = new TransactionInstruction({ keys, programId: WHIRLPOOL_PROGRAM_ID, data }); - return ix; + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix } diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/setFeeAuthority.ts b/packages/kamino-sdk/src/whirpools-client/instructions/setFeeAuthority.ts index 244df573..21f90a32 100644 --- a/packages/kamino-sdk/src/whirpools-client/instructions/setFeeAuthority.ts +++ b/packages/kamino-sdk/src/whirpools-client/instructions/setFeeAuthority.ts @@ -1,23 +1,26 @@ -import { TransactionInstruction, PublicKey, AccountMeta } from '@solana/web3.js'; // eslint-disable-line @typescript-eslint/no-unused-vars -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 { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 SetFeeAuthorityAccounts { - whirlpoolsConfig: PublicKey; - feeAuthority: PublicKey; - newFeeAuthority: PublicKey; + whirlpoolsConfig: PublicKey + feeAuthority: PublicKey + newFeeAuthority: PublicKey } -export function setFeeAuthority(accounts: SetFeeAuthorityAccounts) { +export function setFeeAuthority( + accounts: SetFeeAuthorityAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { const keys: Array = [ { pubkey: accounts.whirlpoolsConfig, isSigner: false, isWritable: true }, { pubkey: accounts.feeAuthority, isSigner: true, isWritable: false }, { pubkey: accounts.newFeeAuthority, isSigner: false, isWritable: false }, - ]; - const identifier = Buffer.from([31, 1, 50, 87, 237, 101, 97, 132]); - const data = identifier; - const ix = new TransactionInstruction({ keys, programId: WHIRLPOOL_PROGRAM_ID, data }); - return ix; + ] + const identifier = Buffer.from([31, 1, 50, 87, 237, 101, 97, 132]) + const data = identifier + const ix = new TransactionInstruction({ keys, programId, data }) + return ix } diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/setFeeRate.ts b/packages/kamino-sdk/src/whirpools-client/instructions/setFeeRate.ts index 6a89527a..199ab9e9 100644 --- a/packages/kamino-sdk/src/whirpools-client/instructions/setFeeRate.ts +++ b/packages/kamino-sdk/src/whirpools-client/instructions/setFeeRate.ts @@ -1,36 +1,40 @@ -import { TransactionInstruction, PublicKey, AccountMeta } from '@solana/web3.js'; // eslint-disable-line @typescript-eslint/no-unused-vars -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 { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 SetFeeRateArgs { - feeRate: number; + feeRate: number } export interface SetFeeRateAccounts { - whirlpoolsConfig: PublicKey; - whirlpool: PublicKey; - feeAuthority: PublicKey; + whirlpoolsConfig: PublicKey + whirlpool: PublicKey + feeAuthority: PublicKey } -export const layout = borsh.struct([borsh.u16('feeRate')]); +export const layout = borsh.struct([borsh.u16("feeRate")]) -export function setFeeRate(args: SetFeeRateArgs, accounts: SetFeeRateAccounts) { +export function setFeeRate( + args: SetFeeRateArgs, + accounts: SetFeeRateAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { const keys: Array = [ { pubkey: accounts.whirlpoolsConfig, isSigner: false, isWritable: false }, { pubkey: accounts.whirlpool, isSigner: false, isWritable: true }, { pubkey: accounts.feeAuthority, isSigner: true, isWritable: false }, - ]; - const identifier = Buffer.from([53, 243, 137, 65, 8, 140, 158, 6]); - const buffer = Buffer.alloc(1000); + ] + const identifier = Buffer.from([53, 243, 137, 65, 8, 140, 158, 6]) + const buffer = Buffer.alloc(1000) const len = layout.encode( { feeRate: args.feeRate, }, buffer - ); - const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len); - const ix = new TransactionInstruction({ keys, programId: WHIRLPOOL_PROGRAM_ID, data }); - return ix; + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix } diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/setProtocolFeeRate.ts b/packages/kamino-sdk/src/whirpools-client/instructions/setProtocolFeeRate.ts index 978a5b23..9df98b98 100644 --- a/packages/kamino-sdk/src/whirpools-client/instructions/setProtocolFeeRate.ts +++ b/packages/kamino-sdk/src/whirpools-client/instructions/setProtocolFeeRate.ts @@ -1,36 +1,40 @@ -import { TransactionInstruction, PublicKey, AccountMeta } from '@solana/web3.js'; // eslint-disable-line @typescript-eslint/no-unused-vars -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 { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 SetProtocolFeeRateArgs { - protocolFeeRate: number; + protocolFeeRate: number } export interface SetProtocolFeeRateAccounts { - whirlpoolsConfig: PublicKey; - whirlpool: PublicKey; - feeAuthority: PublicKey; + whirlpoolsConfig: PublicKey + whirlpool: PublicKey + feeAuthority: PublicKey } -export const layout = borsh.struct([borsh.u16('protocolFeeRate')]); +export const layout = borsh.struct([borsh.u16("protocolFeeRate")]) -export function setProtocolFeeRate(args: SetProtocolFeeRateArgs, accounts: SetProtocolFeeRateAccounts) { +export function setProtocolFeeRate( + args: SetProtocolFeeRateArgs, + accounts: SetProtocolFeeRateAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { const keys: Array = [ { pubkey: accounts.whirlpoolsConfig, isSigner: false, isWritable: false }, { pubkey: accounts.whirlpool, isSigner: false, isWritable: true }, { pubkey: accounts.feeAuthority, isSigner: true, isWritable: false }, - ]; - const identifier = Buffer.from([95, 7, 4, 50, 154, 79, 156, 131]); - const buffer = Buffer.alloc(1000); + ] + const identifier = Buffer.from([95, 7, 4, 50, 154, 79, 156, 131]) + const buffer = Buffer.alloc(1000) const len = layout.encode( { protocolFeeRate: args.protocolFeeRate, }, buffer - ); - const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len); - const ix = new TransactionInstruction({ keys, programId: WHIRLPOOL_PROGRAM_ID, data }); - return ix; + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix } diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/setRewardAuthority.ts b/packages/kamino-sdk/src/whirpools-client/instructions/setRewardAuthority.ts index 586c29ab..a321b8ef 100644 --- a/packages/kamino-sdk/src/whirpools-client/instructions/setRewardAuthority.ts +++ b/packages/kamino-sdk/src/whirpools-client/instructions/setRewardAuthority.ts @@ -1,36 +1,40 @@ -import { TransactionInstruction, PublicKey, AccountMeta } from '@solana/web3.js'; // eslint-disable-line @typescript-eslint/no-unused-vars -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 { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 SetRewardAuthorityArgs { - rewardIndex: number; + rewardIndex: number } export interface SetRewardAuthorityAccounts { - whirlpool: PublicKey; - rewardAuthority: PublicKey; - newRewardAuthority: PublicKey; + whirlpool: PublicKey + rewardAuthority: PublicKey + newRewardAuthority: PublicKey } -export const layout = borsh.struct([borsh.u8('rewardIndex')]); +export const layout = borsh.struct([borsh.u8("rewardIndex")]) -export function setRewardAuthority(args: SetRewardAuthorityArgs, accounts: SetRewardAuthorityAccounts) { +export function setRewardAuthority( + args: SetRewardAuthorityArgs, + accounts: SetRewardAuthorityAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { const keys: Array = [ { pubkey: accounts.whirlpool, isSigner: false, isWritable: true }, { pubkey: accounts.rewardAuthority, isSigner: true, isWritable: false }, { pubkey: accounts.newRewardAuthority, isSigner: false, isWritable: false }, - ]; - const identifier = Buffer.from([34, 39, 183, 252, 83, 28, 85, 127]); - const buffer = Buffer.alloc(1000); + ] + const identifier = Buffer.from([34, 39, 183, 252, 83, 28, 85, 127]) + const buffer = Buffer.alloc(1000) const len = layout.encode( { rewardIndex: args.rewardIndex, }, buffer - ); - const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len); - const ix = new TransactionInstruction({ keys, programId: WHIRLPOOL_PROGRAM_ID, data }); - return ix; + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix } diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/setRewardAuthorityBySuperAuthority.ts b/packages/kamino-sdk/src/whirpools-client/instructions/setRewardAuthorityBySuperAuthority.ts index 3c222dba..15d59b49 100644 --- a/packages/kamino-sdk/src/whirpools-client/instructions/setRewardAuthorityBySuperAuthority.ts +++ b/packages/kamino-sdk/src/whirpools-client/instructions/setRewardAuthorityBySuperAuthority.ts @@ -1,25 +1,26 @@ -import { TransactionInstruction, PublicKey, AccountMeta } from '@solana/web3.js'; // eslint-disable-line @typescript-eslint/no-unused-vars -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 { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 SetRewardAuthorityBySuperAuthorityArgs { - rewardIndex: number; + rewardIndex: number } export interface SetRewardAuthorityBySuperAuthorityAccounts { - whirlpoolsConfig: PublicKey; - whirlpool: PublicKey; - rewardEmissionsSuperAuthority: PublicKey; - newRewardAuthority: PublicKey; + whirlpoolsConfig: PublicKey + whirlpool: PublicKey + rewardEmissionsSuperAuthority: PublicKey + newRewardAuthority: PublicKey } -export const layout = borsh.struct([borsh.u8('rewardIndex')]); +export const layout = borsh.struct([borsh.u8("rewardIndex")]) export function setRewardAuthorityBySuperAuthority( args: SetRewardAuthorityBySuperAuthorityArgs, - accounts: SetRewardAuthorityBySuperAuthorityAccounts + accounts: SetRewardAuthorityBySuperAuthorityAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID ) { const keys: Array = [ { pubkey: accounts.whirlpoolsConfig, isSigner: false, isWritable: false }, @@ -30,16 +31,16 @@ export function setRewardAuthorityBySuperAuthority( isWritable: false, }, { pubkey: accounts.newRewardAuthority, isSigner: false, isWritable: false }, - ]; - const identifier = Buffer.from([240, 154, 201, 198, 148, 93, 56, 25]); - const buffer = Buffer.alloc(1000); + ] + const identifier = Buffer.from([240, 154, 201, 198, 148, 93, 56, 25]) + const buffer = Buffer.alloc(1000) const len = layout.encode( { rewardIndex: args.rewardIndex, }, buffer - ); - const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len); - const ix = new TransactionInstruction({ keys, programId: WHIRLPOOL_PROGRAM_ID, data }); - return ix; + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix } diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/setRewardEmissions.ts b/packages/kamino-sdk/src/whirpools-client/instructions/setRewardEmissions.ts index 579fd977..c410a732 100644 --- a/packages/kamino-sdk/src/whirpools-client/instructions/setRewardEmissions.ts +++ b/packages/kamino-sdk/src/whirpools-client/instructions/setRewardEmissions.ts @@ -1,38 +1,45 @@ -import { TransactionInstruction, PublicKey, AccountMeta } from '@solana/web3.js'; // eslint-disable-line @typescript-eslint/no-unused-vars -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 { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 SetRewardEmissionsArgs { - rewardIndex: number; - emissionsPerSecondX64: BN; + rewardIndex: number + emissionsPerSecondX64: BN } export interface SetRewardEmissionsAccounts { - whirlpool: PublicKey; - rewardAuthority: PublicKey; - rewardVault: PublicKey; + whirlpool: PublicKey + rewardAuthority: PublicKey + rewardVault: PublicKey } -export const layout = borsh.struct([borsh.u8('rewardIndex'), borsh.u128('emissionsPerSecondX64')]); +export const layout = borsh.struct([ + borsh.u8("rewardIndex"), + borsh.u128("emissionsPerSecondX64"), +]) -export function setRewardEmissions(args: SetRewardEmissionsArgs, accounts: SetRewardEmissionsAccounts) { +export function setRewardEmissions( + args: SetRewardEmissionsArgs, + accounts: SetRewardEmissionsAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { const keys: Array = [ { pubkey: accounts.whirlpool, isSigner: false, isWritable: true }, { pubkey: accounts.rewardAuthority, isSigner: true, isWritable: false }, { pubkey: accounts.rewardVault, isSigner: false, isWritable: false }, - ]; - const identifier = Buffer.from([13, 197, 86, 168, 109, 176, 27, 244]); - const buffer = Buffer.alloc(1000); + ] + const identifier = Buffer.from([13, 197, 86, 168, 109, 176, 27, 244]) + const buffer = Buffer.alloc(1000) const len = layout.encode( { rewardIndex: args.rewardIndex, emissionsPerSecondX64: args.emissionsPerSecondX64, }, buffer - ); - const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len); - const ix = new TransactionInstruction({ keys, programId: WHIRLPOOL_PROGRAM_ID, data }); - return ix; + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix } diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/setRewardEmissionsSuperAuthority.ts b/packages/kamino-sdk/src/whirpools-client/instructions/setRewardEmissionsSuperAuthority.ts index 7cebe9b8..94e81b5f 100644 --- a/packages/kamino-sdk/src/whirpools-client/instructions/setRewardEmissionsSuperAuthority.ts +++ b/packages/kamino-sdk/src/whirpools-client/instructions/setRewardEmissionsSuperAuthority.ts @@ -1,16 +1,19 @@ -import { TransactionInstruction, PublicKey, AccountMeta } from '@solana/web3.js'; // eslint-disable-line @typescript-eslint/no-unused-vars -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 { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 SetRewardEmissionsSuperAuthorityAccounts { - whirlpoolsConfig: PublicKey; - rewardEmissionsSuperAuthority: PublicKey; - newRewardEmissionsSuperAuthority: PublicKey; + whirlpoolsConfig: PublicKey + rewardEmissionsSuperAuthority: PublicKey + newRewardEmissionsSuperAuthority: PublicKey } -export function setRewardEmissionsSuperAuthority(accounts: SetRewardEmissionsSuperAuthorityAccounts) { +export function setRewardEmissionsSuperAuthority( + accounts: SetRewardEmissionsSuperAuthorityAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { const keys: Array = [ { pubkey: accounts.whirlpoolsConfig, isSigner: false, isWritable: true }, { @@ -23,9 +26,9 @@ export function setRewardEmissionsSuperAuthority(accounts: SetRewardEmissionsSup isSigner: false, isWritable: false, }, - ]; - const identifier = Buffer.from([207, 5, 200, 209, 122, 56, 82, 183]); - const data = identifier; - const ix = new TransactionInstruction({ keys, programId: WHIRLPOOL_PROGRAM_ID, data }); - return ix; + ] + const identifier = Buffer.from([207, 5, 200, 209, 122, 56, 82, 183]) + const data = identifier + const ix = new TransactionInstruction({ keys, programId, data }) + return ix } diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/setRewardEmissionsV2.ts b/packages/kamino-sdk/src/whirpools-client/instructions/setRewardEmissionsV2.ts new file mode 100644 index 00000000..0ae36c0e --- /dev/null +++ b/packages/kamino-sdk/src/whirpools-client/instructions/setRewardEmissionsV2.ts @@ -0,0 +1,45 @@ +import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 SetRewardEmissionsV2Args { + rewardIndex: number + emissionsPerSecondX64: BN +} + +export interface SetRewardEmissionsV2Accounts { + whirlpool: PublicKey + rewardAuthority: PublicKey + rewardVault: PublicKey +} + +export const layout = borsh.struct([ + borsh.u8("rewardIndex"), + borsh.u128("emissionsPerSecondX64"), +]) + +export function setRewardEmissionsV2( + args: SetRewardEmissionsV2Args, + accounts: SetRewardEmissionsV2Accounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { + const keys: Array = [ + { pubkey: accounts.whirlpool, isSigner: false, isWritable: true }, + { pubkey: accounts.rewardAuthority, isSigner: true, isWritable: false }, + { pubkey: accounts.rewardVault, isSigner: false, isWritable: false }, + ] + const identifier = Buffer.from([114, 228, 72, 32, 193, 48, 160, 102]) + const buffer = Buffer.alloc(1000) + const len = layout.encode( + { + rewardIndex: args.rewardIndex, + emissionsPerSecondX64: args.emissionsPerSecondX64, + }, + buffer + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix +} diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/setTokenBadgeAuthority.ts b/packages/kamino-sdk/src/whirpools-client/instructions/setTokenBadgeAuthority.ts new file mode 100644 index 00000000..32284783 --- /dev/null +++ b/packages/kamino-sdk/src/whirpools-client/instructions/setTokenBadgeAuthority.ts @@ -0,0 +1,40 @@ +import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 SetTokenBadgeAuthorityAccounts { + whirlpoolsConfig: PublicKey + whirlpoolsConfigExtension: PublicKey + configExtensionAuthority: PublicKey + newTokenBadgeAuthority: PublicKey +} + +export function setTokenBadgeAuthority( + accounts: SetTokenBadgeAuthorityAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { + const keys: Array = [ + { pubkey: accounts.whirlpoolsConfig, isSigner: false, isWritable: false }, + { + pubkey: accounts.whirlpoolsConfigExtension, + isSigner: false, + isWritable: true, + }, + { + pubkey: accounts.configExtensionAuthority, + isSigner: true, + isWritable: false, + }, + { + pubkey: accounts.newTokenBadgeAuthority, + isSigner: false, + isWritable: false, + }, + ] + const identifier = Buffer.from([207, 202, 4, 32, 205, 79, 13, 178]) + const data = identifier + const ix = new TransactionInstruction({ keys, programId, data }) + return ix +} diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/swap.ts b/packages/kamino-sdk/src/whirpools-client/instructions/swap.ts index 1592b505..98a74332 100644 --- a/packages/kamino-sdk/src/whirpools-client/instructions/swap.ts +++ b/packages/kamino-sdk/src/whirpools-client/instructions/swap.ts @@ -1,40 +1,44 @@ -import { TransactionInstruction, PublicKey, AccountMeta } from '@solana/web3.js'; // eslint-disable-line @typescript-eslint/no-unused-vars -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 { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 SwapArgs { - amount: BN; - otherAmountThreshold: BN; - sqrtPriceLimit: BN; - exactInput: boolean; - aToB: boolean; + amount: BN + otherAmountThreshold: BN + sqrtPriceLimit: BN + amountSpecifiedIsInput: boolean + aToB: boolean } export interface SwapAccounts { - tokenProgram: PublicKey; - tokenAuthority: PublicKey; - whirlpool: PublicKey; - tokenOwnerAccountA: PublicKey; - tokenVaultA: PublicKey; - tokenOwnerAccountB: PublicKey; - tokenVaultB: PublicKey; - tickArray0: PublicKey; - tickArray1: PublicKey; - tickArray2: PublicKey; - oracle: PublicKey; + tokenProgram: PublicKey + tokenAuthority: PublicKey + whirlpool: PublicKey + tokenOwnerAccountA: PublicKey + tokenVaultA: PublicKey + tokenOwnerAccountB: PublicKey + tokenVaultB: PublicKey + tickArray0: PublicKey + tickArray1: PublicKey + tickArray2: PublicKey + oracle: PublicKey } export const layout = borsh.struct([ - borsh.u64('amount'), - borsh.u64('otherAmountThreshold'), - borsh.u128('sqrtPriceLimit'), - borsh.bool('exactInput'), - borsh.bool('aToB'), -]); + borsh.u64("amount"), + borsh.u64("otherAmountThreshold"), + borsh.u128("sqrtPriceLimit"), + borsh.bool("amountSpecifiedIsInput"), + borsh.bool("aToB"), +]) -export function swap(args: SwapArgs, accounts: SwapAccounts) { +export function swap( + args: SwapArgs, + accounts: SwapAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { const keys: Array = [ { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false }, { pubkey: accounts.tokenAuthority, isSigner: true, isWritable: false }, @@ -47,20 +51,20 @@ export function swap(args: SwapArgs, accounts: SwapAccounts) { { pubkey: accounts.tickArray1, isSigner: false, isWritable: true }, { pubkey: accounts.tickArray2, isSigner: false, isWritable: true }, { pubkey: accounts.oracle, isSigner: false, isWritable: false }, - ]; - const identifier = Buffer.from([248, 198, 158, 145, 225, 117, 135, 200]); - const buffer = Buffer.alloc(1000); + ] + const identifier = Buffer.from([248, 198, 158, 145, 225, 117, 135, 200]) + const buffer = Buffer.alloc(1000) const len = layout.encode( { amount: args.amount, otherAmountThreshold: args.otherAmountThreshold, sqrtPriceLimit: args.sqrtPriceLimit, - exactInput: args.exactInput, + amountSpecifiedIsInput: args.amountSpecifiedIsInput, aToB: args.aToB, }, buffer - ); - const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len); - const ix = new TransactionInstruction({ keys, programId: WHIRLPOOL_PROGRAM_ID, data }); - return ix; + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix } diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/swapV2.ts b/packages/kamino-sdk/src/whirpools-client/instructions/swapV2.ts new file mode 100644 index 00000000..6938428e --- /dev/null +++ b/packages/kamino-sdk/src/whirpools-client/instructions/swapV2.ts @@ -0,0 +1,86 @@ +import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 SwapV2Args { + amount: BN + otherAmountThreshold: BN + sqrtPriceLimit: BN + amountSpecifiedIsInput: boolean + aToB: boolean + remainingAccountsInfo: types.RemainingAccountsInfoFields | null +} + +export interface SwapV2Accounts { + tokenProgramA: PublicKey + tokenProgramB: PublicKey + memoProgram: PublicKey + tokenAuthority: PublicKey + whirlpool: PublicKey + tokenMintA: PublicKey + tokenMintB: PublicKey + tokenOwnerAccountA: PublicKey + tokenVaultA: PublicKey + tokenOwnerAccountB: PublicKey + tokenVaultB: PublicKey + tickArray0: PublicKey + tickArray1: PublicKey + tickArray2: PublicKey + oracle: PublicKey +} + +export const layout = borsh.struct([ + borsh.u64("amount"), + borsh.u64("otherAmountThreshold"), + borsh.u128("sqrtPriceLimit"), + borsh.bool("amountSpecifiedIsInput"), + borsh.bool("aToB"), + borsh.option(types.RemainingAccountsInfo.layout(), "remainingAccountsInfo"), +]) + +export function swapV2( + args: SwapV2Args, + accounts: SwapV2Accounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { + const keys: Array = [ + { pubkey: accounts.tokenProgramA, isSigner: false, isWritable: false }, + { pubkey: accounts.tokenProgramB, isSigner: false, isWritable: false }, + { pubkey: accounts.memoProgram, isSigner: false, isWritable: false }, + { pubkey: accounts.tokenAuthority, isSigner: true, isWritable: false }, + { pubkey: accounts.whirlpool, isSigner: false, isWritable: true }, + { pubkey: accounts.tokenMintA, isSigner: false, isWritable: false }, + { pubkey: accounts.tokenMintB, isSigner: false, isWritable: false }, + { pubkey: accounts.tokenOwnerAccountA, isSigner: false, isWritable: true }, + { pubkey: accounts.tokenVaultA, isSigner: false, isWritable: true }, + { pubkey: accounts.tokenOwnerAccountB, isSigner: false, isWritable: true }, + { pubkey: accounts.tokenVaultB, isSigner: false, isWritable: true }, + { pubkey: accounts.tickArray0, isSigner: false, isWritable: true }, + { pubkey: accounts.tickArray1, isSigner: false, isWritable: true }, + { pubkey: accounts.tickArray2, isSigner: false, isWritable: true }, + { pubkey: accounts.oracle, isSigner: false, isWritable: true }, + ] + const identifier = Buffer.from([43, 4, 237, 11, 26, 201, 30, 98]) + const buffer = Buffer.alloc(1000) + const len = layout.encode( + { + amount: args.amount, + otherAmountThreshold: args.otherAmountThreshold, + sqrtPriceLimit: args.sqrtPriceLimit, + amountSpecifiedIsInput: args.amountSpecifiedIsInput, + aToB: args.aToB, + remainingAccountsInfo: + (args.remainingAccountsInfo && + types.RemainingAccountsInfo.toEncodable( + args.remainingAccountsInfo + )) || + null, + }, + buffer + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix +} diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/twoHopSwap.ts b/packages/kamino-sdk/src/whirpools-client/instructions/twoHopSwap.ts new file mode 100644 index 00000000..b86f30c3 --- /dev/null +++ b/packages/kamino-sdk/src/whirpools-client/instructions/twoHopSwap.ts @@ -0,0 +1,110 @@ +import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 TwoHopSwapArgs { + amount: BN + otherAmountThreshold: BN + amountSpecifiedIsInput: boolean + aToBOne: boolean + aToBTwo: boolean + sqrtPriceLimitOne: BN + sqrtPriceLimitTwo: BN +} + +export interface TwoHopSwapAccounts { + tokenProgram: PublicKey + tokenAuthority: PublicKey + whirlpoolOne: PublicKey + whirlpoolTwo: PublicKey + tokenOwnerAccountOneA: PublicKey + tokenVaultOneA: PublicKey + tokenOwnerAccountOneB: PublicKey + tokenVaultOneB: PublicKey + tokenOwnerAccountTwoA: PublicKey + tokenVaultTwoA: PublicKey + tokenOwnerAccountTwoB: PublicKey + tokenVaultTwoB: PublicKey + tickArrayOne0: PublicKey + tickArrayOne1: PublicKey + tickArrayOne2: PublicKey + tickArrayTwo0: PublicKey + tickArrayTwo1: PublicKey + tickArrayTwo2: PublicKey + oracleOne: PublicKey + oracleTwo: PublicKey +} + +export const layout = borsh.struct([ + borsh.u64("amount"), + borsh.u64("otherAmountThreshold"), + borsh.bool("amountSpecifiedIsInput"), + borsh.bool("aToBOne"), + borsh.bool("aToBTwo"), + borsh.u128("sqrtPriceLimitOne"), + borsh.u128("sqrtPriceLimitTwo"), +]) + +export function twoHopSwap( + args: TwoHopSwapArgs, + accounts: TwoHopSwapAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { + const keys: Array = [ + { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false }, + { pubkey: accounts.tokenAuthority, isSigner: true, isWritable: false }, + { pubkey: accounts.whirlpoolOne, isSigner: false, isWritable: true }, + { pubkey: accounts.whirlpoolTwo, isSigner: false, isWritable: true }, + { + pubkey: accounts.tokenOwnerAccountOneA, + isSigner: false, + isWritable: true, + }, + { pubkey: accounts.tokenVaultOneA, isSigner: false, isWritable: true }, + { + pubkey: accounts.tokenOwnerAccountOneB, + isSigner: false, + isWritable: true, + }, + { pubkey: accounts.tokenVaultOneB, isSigner: false, isWritable: true }, + { + pubkey: accounts.tokenOwnerAccountTwoA, + isSigner: false, + isWritable: true, + }, + { pubkey: accounts.tokenVaultTwoA, isSigner: false, isWritable: true }, + { + pubkey: accounts.tokenOwnerAccountTwoB, + isSigner: false, + isWritable: true, + }, + { pubkey: accounts.tokenVaultTwoB, isSigner: false, isWritable: true }, + { pubkey: accounts.tickArrayOne0, isSigner: false, isWritable: true }, + { pubkey: accounts.tickArrayOne1, isSigner: false, isWritable: true }, + { pubkey: accounts.tickArrayOne2, isSigner: false, isWritable: true }, + { pubkey: accounts.tickArrayTwo0, isSigner: false, isWritable: true }, + { pubkey: accounts.tickArrayTwo1, isSigner: false, isWritable: true }, + { pubkey: accounts.tickArrayTwo2, isSigner: false, isWritable: true }, + { pubkey: accounts.oracleOne, isSigner: false, isWritable: false }, + { pubkey: accounts.oracleTwo, isSigner: false, isWritable: false }, + ] + const identifier = Buffer.from([195, 96, 237, 108, 68, 162, 219, 230]) + const buffer = Buffer.alloc(1000) + const len = layout.encode( + { + amount: args.amount, + otherAmountThreshold: args.otherAmountThreshold, + amountSpecifiedIsInput: args.amountSpecifiedIsInput, + aToBOne: args.aToBOne, + aToBTwo: args.aToBTwo, + sqrtPriceLimitOne: args.sqrtPriceLimitOne, + sqrtPriceLimitTwo: args.sqrtPriceLimitTwo, + }, + buffer + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix +} diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/twoHopSwapV2.ts b/packages/kamino-sdk/src/whirpools-client/instructions/twoHopSwapV2.ts new file mode 100644 index 00000000..c13e3281 --- /dev/null +++ b/packages/kamino-sdk/src/whirpools-client/instructions/twoHopSwapV2.ts @@ -0,0 +1,134 @@ +import { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 TwoHopSwapV2Args { + amount: BN + otherAmountThreshold: BN + amountSpecifiedIsInput: boolean + aToBOne: boolean + aToBTwo: boolean + sqrtPriceLimitOne: BN + sqrtPriceLimitTwo: BN + remainingAccountsInfo: types.RemainingAccountsInfoFields | null +} + +export interface TwoHopSwapV2Accounts { + whirlpoolOne: PublicKey + whirlpoolTwo: PublicKey + tokenMintInput: PublicKey + tokenMintIntermediate: PublicKey + tokenMintOutput: PublicKey + tokenProgramInput: PublicKey + tokenProgramIntermediate: PublicKey + tokenProgramOutput: PublicKey + tokenOwnerAccountInput: PublicKey + tokenVaultOneInput: PublicKey + tokenVaultOneIntermediate: PublicKey + tokenVaultTwoIntermediate: PublicKey + tokenVaultTwoOutput: PublicKey + tokenOwnerAccountOutput: PublicKey + tokenAuthority: PublicKey + tickArrayOne0: PublicKey + tickArrayOne1: PublicKey + tickArrayOne2: PublicKey + tickArrayTwo0: PublicKey + tickArrayTwo1: PublicKey + tickArrayTwo2: PublicKey + oracleOne: PublicKey + oracleTwo: PublicKey + memoProgram: PublicKey +} + +export const layout = borsh.struct([ + borsh.u64("amount"), + borsh.u64("otherAmountThreshold"), + borsh.bool("amountSpecifiedIsInput"), + borsh.bool("aToBOne"), + borsh.bool("aToBTwo"), + borsh.u128("sqrtPriceLimitOne"), + borsh.u128("sqrtPriceLimitTwo"), + borsh.option(types.RemainingAccountsInfo.layout(), "remainingAccountsInfo"), +]) + +export function twoHopSwapV2( + args: TwoHopSwapV2Args, + accounts: TwoHopSwapV2Accounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { + const keys: Array = [ + { pubkey: accounts.whirlpoolOne, isSigner: false, isWritable: true }, + { pubkey: accounts.whirlpoolTwo, isSigner: false, isWritable: true }, + { pubkey: accounts.tokenMintInput, isSigner: false, isWritable: false }, + { + pubkey: accounts.tokenMintIntermediate, + isSigner: false, + isWritable: false, + }, + { pubkey: accounts.tokenMintOutput, isSigner: false, isWritable: false }, + { pubkey: accounts.tokenProgramInput, isSigner: false, isWritable: false }, + { + pubkey: accounts.tokenProgramIntermediate, + isSigner: false, + isWritable: false, + }, + { pubkey: accounts.tokenProgramOutput, isSigner: false, isWritable: false }, + { + pubkey: accounts.tokenOwnerAccountInput, + isSigner: false, + isWritable: true, + }, + { pubkey: accounts.tokenVaultOneInput, isSigner: false, isWritable: true }, + { + pubkey: accounts.tokenVaultOneIntermediate, + isSigner: false, + isWritable: true, + }, + { + pubkey: accounts.tokenVaultTwoIntermediate, + isSigner: false, + isWritable: true, + }, + { pubkey: accounts.tokenVaultTwoOutput, isSigner: false, isWritable: true }, + { + pubkey: accounts.tokenOwnerAccountOutput, + isSigner: false, + isWritable: true, + }, + { pubkey: accounts.tokenAuthority, isSigner: true, isWritable: false }, + { pubkey: accounts.tickArrayOne0, isSigner: false, isWritable: true }, + { pubkey: accounts.tickArrayOne1, isSigner: false, isWritable: true }, + { pubkey: accounts.tickArrayOne2, isSigner: false, isWritable: true }, + { pubkey: accounts.tickArrayTwo0, isSigner: false, isWritable: true }, + { pubkey: accounts.tickArrayTwo1, isSigner: false, isWritable: true }, + { pubkey: accounts.tickArrayTwo2, isSigner: false, isWritable: true }, + { pubkey: accounts.oracleOne, isSigner: false, isWritable: true }, + { pubkey: accounts.oracleTwo, isSigner: false, isWritable: true }, + { pubkey: accounts.memoProgram, isSigner: false, isWritable: false }, + ] + const identifier = Buffer.from([186, 143, 209, 29, 254, 2, 194, 117]) + const buffer = Buffer.alloc(1000) + const len = layout.encode( + { + amount: args.amount, + otherAmountThreshold: args.otherAmountThreshold, + amountSpecifiedIsInput: args.amountSpecifiedIsInput, + aToBOne: args.aToBOne, + aToBTwo: args.aToBTwo, + sqrtPriceLimitOne: args.sqrtPriceLimitOne, + sqrtPriceLimitTwo: args.sqrtPriceLimitTwo, + remainingAccountsInfo: + (args.remainingAccountsInfo && + types.RemainingAccountsInfo.toEncodable( + args.remainingAccountsInfo + )) || + null, + }, + buffer + ) + const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len) + const ix = new TransactionInstruction({ keys, programId, data }) + return ix +} diff --git a/packages/kamino-sdk/src/whirpools-client/instructions/updateFeesAndRewards.ts b/packages/kamino-sdk/src/whirpools-client/instructions/updateFeesAndRewards.ts index 53b8d6c4..926cb3db 100644 --- a/packages/kamino-sdk/src/whirpools-client/instructions/updateFeesAndRewards.ts +++ b/packages/kamino-sdk/src/whirpools-client/instructions/updateFeesAndRewards.ts @@ -1,25 +1,28 @@ -import { TransactionInstruction, PublicKey, AccountMeta } from '@solana/web3.js'; // eslint-disable-line @typescript-eslint/no-unused-vars -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 { TransactionInstruction, PublicKey, AccountMeta } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +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 UpdateFeesAndRewardsAccounts { - whirlpool: PublicKey; - position: PublicKey; - tickArrayLower: PublicKey; - tickArrayUpper: PublicKey; + whirlpool: PublicKey + position: PublicKey + tickArrayLower: PublicKey + tickArrayUpper: PublicKey } -export function updateFeesAndRewards(accounts: UpdateFeesAndRewardsAccounts) { +export function updateFeesAndRewards( + accounts: UpdateFeesAndRewardsAccounts, + programId: PublicKey = WHIRLPOOL_PROGRAM_ID +) { const keys: Array = [ { pubkey: accounts.whirlpool, isSigner: false, isWritable: true }, { pubkey: accounts.position, isSigner: false, isWritable: true }, { pubkey: accounts.tickArrayLower, isSigner: false, isWritable: false }, { pubkey: accounts.tickArrayUpper, isSigner: false, isWritable: false }, - ]; - const identifier = Buffer.from([154, 230, 250, 13, 236, 209, 75, 223]); - const data = identifier; - const ix = new TransactionInstruction({ keys, programId: WHIRLPOOL_PROGRAM_ID, data }); - return ix; + ] + const identifier = Buffer.from([154, 230, 250, 13, 236, 209, 75, 223]) + const data = identifier + const ix = new TransactionInstruction({ keys, programId, data }) + return ix } diff --git a/packages/kamino-sdk/src/whirpools-client/programId.ts b/packages/kamino-sdk/src/whirpools-client/programId.ts index e322b7e7..8d0e3359 100644 --- a/packages/kamino-sdk/src/whirpools-client/programId.ts +++ b/packages/kamino-sdk/src/whirpools-client/programId.ts @@ -1,10 +1,10 @@ import { PublicKey } from '@solana/web3.js'; // Program ID passed with the cli --program-id flag when running the code generator. Do not edit, it will get overwritten. -export const PROGRAM_ID_CLI = new PublicKey('whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc'); +export const WHIRLPOOL_PROGRAM_ID_CLI = new PublicKey('whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc'); // This constant will not get overwritten on subsequent code generations and it's safe to modify it's value. -export let WHIRLPOOL_PROGRAM_ID: PublicKey = PROGRAM_ID_CLI; +export let WHIRLPOOL_PROGRAM_ID: PublicKey = WHIRLPOOL_PROGRAM_ID_CLI; export const setWhirlpoolsProgramId = (programId: PublicKey) => { WHIRLPOOL_PROGRAM_ID = programId; diff --git a/packages/kamino-sdk/src/whirpools-client/types/AccountsType.ts b/packages/kamino-sdk/src/whirpools-client/types/AccountsType.ts new file mode 100644 index 00000000..c406450e --- /dev/null +++ b/packages/kamino-sdk/src/whirpools-client/types/AccountsType.ts @@ -0,0 +1,208 @@ +import { PublicKey } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars +import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars +import * as borsh from "@coral-xyz/borsh" + +export interface TransferHookAJSON { + kind: "TransferHookA" +} + +export class TransferHookA { + static readonly discriminator = 0 + static readonly kind = "TransferHookA" + readonly discriminator = 0 + readonly kind = "TransferHookA" + + toJSON(): TransferHookAJSON { + return { + kind: "TransferHookA", + } + } + + toEncodable() { + return { + TransferHookA: {}, + } + } +} + +export interface TransferHookBJSON { + kind: "TransferHookB" +} + +export class TransferHookB { + static readonly discriminator = 1 + static readonly kind = "TransferHookB" + readonly discriminator = 1 + readonly kind = "TransferHookB" + + toJSON(): TransferHookBJSON { + return { + kind: "TransferHookB", + } + } + + toEncodable() { + return { + TransferHookB: {}, + } + } +} + +export interface TransferHookRewardJSON { + kind: "TransferHookReward" +} + +export class TransferHookReward { + static readonly discriminator = 2 + static readonly kind = "TransferHookReward" + readonly discriminator = 2 + readonly kind = "TransferHookReward" + + toJSON(): TransferHookRewardJSON { + return { + kind: "TransferHookReward", + } + } + + toEncodable() { + return { + TransferHookReward: {}, + } + } +} + +export interface TransferHookInputJSON { + kind: "TransferHookInput" +} + +export class TransferHookInput { + static readonly discriminator = 3 + static readonly kind = "TransferHookInput" + readonly discriminator = 3 + readonly kind = "TransferHookInput" + + toJSON(): TransferHookInputJSON { + return { + kind: "TransferHookInput", + } + } + + toEncodable() { + return { + TransferHookInput: {}, + } + } +} + +export interface TransferHookIntermediateJSON { + kind: "TransferHookIntermediate" +} + +export class TransferHookIntermediate { + static readonly discriminator = 4 + static readonly kind = "TransferHookIntermediate" + readonly discriminator = 4 + readonly kind = "TransferHookIntermediate" + + toJSON(): TransferHookIntermediateJSON { + return { + kind: "TransferHookIntermediate", + } + } + + toEncodable() { + return { + TransferHookIntermediate: {}, + } + } +} + +export interface TransferHookOutputJSON { + kind: "TransferHookOutput" +} + +export class TransferHookOutput { + static readonly discriminator = 5 + static readonly kind = "TransferHookOutput" + readonly discriminator = 5 + readonly kind = "TransferHookOutput" + + toJSON(): TransferHookOutputJSON { + return { + kind: "TransferHookOutput", + } + } + + toEncodable() { + return { + TransferHookOutput: {}, + } + } +} + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +export function fromDecoded(obj: any): types.AccountsTypeKind { + if (typeof obj !== "object") { + throw new Error("Invalid enum object") + } + + if ("TransferHookA" in obj) { + return new TransferHookA() + } + if ("TransferHookB" in obj) { + return new TransferHookB() + } + if ("TransferHookReward" in obj) { + return new TransferHookReward() + } + if ("TransferHookInput" in obj) { + return new TransferHookInput() + } + if ("TransferHookIntermediate" in obj) { + return new TransferHookIntermediate() + } + if ("TransferHookOutput" in obj) { + return new TransferHookOutput() + } + + throw new Error("Invalid enum object") +} + +export function fromJSON(obj: types.AccountsTypeJSON): types.AccountsTypeKind { + switch (obj.kind) { + case "TransferHookA": { + return new TransferHookA() + } + case "TransferHookB": { + return new TransferHookB() + } + case "TransferHookReward": { + return new TransferHookReward() + } + case "TransferHookInput": { + return new TransferHookInput() + } + case "TransferHookIntermediate": { + return new TransferHookIntermediate() + } + case "TransferHookOutput": { + return new TransferHookOutput() + } + } +} + +export function layout(property?: string) { + const ret = borsh.rustEnum([ + borsh.struct([], "TransferHookA"), + borsh.struct([], "TransferHookB"), + borsh.struct([], "TransferHookReward"), + borsh.struct([], "TransferHookInput"), + borsh.struct([], "TransferHookIntermediate"), + borsh.struct([], "TransferHookOutput"), + ]) + if (property !== undefined) { + return ret.replicate(property) + } + return ret +} diff --git a/packages/kamino-sdk/src/whirpools-client/types/CurrIndex.ts b/packages/kamino-sdk/src/whirpools-client/types/CurrIndex.ts index 41747019..5a6940c1 100644 --- a/packages/kamino-sdk/src/whirpools-client/types/CurrIndex.ts +++ b/packages/kamino-sdk/src/whirpools-client/types/CurrIndex.ts @@ -1,7 +1,7 @@ import { PublicKey } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars -import * as borsh from "@project-serum/borsh" +import * as borsh from "@coral-xyz/borsh" export interface BelowJSON { kind: "Below" diff --git a/packages/kamino-sdk/src/whirpools-client/types/Direction.ts b/packages/kamino-sdk/src/whirpools-client/types/Direction.ts index 2ffe2f1d..a485e388 100644 --- a/packages/kamino-sdk/src/whirpools-client/types/Direction.ts +++ b/packages/kamino-sdk/src/whirpools-client/types/Direction.ts @@ -1,7 +1,7 @@ import { PublicKey } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars -import * as borsh from "@project-serum/borsh" +import * as borsh from "@coral-xyz/borsh" export interface LeftJSON { kind: "Left" diff --git a/packages/kamino-sdk/src/whirpools-client/types/OpenPositionBumps.ts b/packages/kamino-sdk/src/whirpools-client/types/OpenPositionBumps.ts index 40af58f2..80ee886c 100644 --- a/packages/kamino-sdk/src/whirpools-client/types/OpenPositionBumps.ts +++ b/packages/kamino-sdk/src/whirpools-client/types/OpenPositionBumps.ts @@ -1,7 +1,7 @@ import { PublicKey } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars -import * as borsh from "@project-serum/borsh" +import * as borsh from "@coral-xyz/borsh" export interface OpenPositionBumpsFields { positionBump: number diff --git a/packages/kamino-sdk/src/whirpools-client/types/OpenPositionWithMetadataBumps.ts b/packages/kamino-sdk/src/whirpools-client/types/OpenPositionWithMetadataBumps.ts index 163403c1..3837af1a 100644 --- a/packages/kamino-sdk/src/whirpools-client/types/OpenPositionWithMetadataBumps.ts +++ b/packages/kamino-sdk/src/whirpools-client/types/OpenPositionWithMetadataBumps.ts @@ -1,7 +1,7 @@ import { PublicKey } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars -import * as borsh from "@project-serum/borsh" +import * as borsh from "@coral-xyz/borsh" export interface OpenPositionWithMetadataBumpsFields { positionBump: number diff --git a/packages/kamino-sdk/src/whirpools-client/types/PositionRewardInfo.ts b/packages/kamino-sdk/src/whirpools-client/types/PositionRewardInfo.ts index d268f087..2a11427e 100644 --- a/packages/kamino-sdk/src/whirpools-client/types/PositionRewardInfo.ts +++ b/packages/kamino-sdk/src/whirpools-client/types/PositionRewardInfo.ts @@ -1,7 +1,7 @@ import { PublicKey } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars -import * as borsh from "@project-serum/borsh" +import * as borsh from "@coral-xyz/borsh" export interface PositionRewardInfoFields { growthInsideCheckpoint: BN diff --git a/packages/kamino-sdk/src/whirpools-client/types/RemainingAccountsInfo.ts b/packages/kamino-sdk/src/whirpools-client/types/RemainingAccountsInfo.ts new file mode 100644 index 00000000..1b14c00b --- /dev/null +++ b/packages/kamino-sdk/src/whirpools-client/types/RemainingAccountsInfo.ts @@ -0,0 +1,66 @@ +import { PublicKey } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars +import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars +import * as borsh from "@coral-xyz/borsh" + +export interface RemainingAccountsInfoFields { + slices: Array +} + +export interface RemainingAccountsInfoJSON { + slices: Array +} + +export class RemainingAccountsInfo { + readonly slices: Array + + constructor(fields: RemainingAccountsInfoFields) { + this.slices = fields.slices.map( + (item) => new types.RemainingAccountsSlice({ ...item }) + ) + } + + static layout(property?: string) { + return borsh.struct( + [borsh.vec(types.RemainingAccountsSlice.layout(), "slices")], + property + ) + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + static fromDecoded(obj: any) { + return new RemainingAccountsInfo({ + slices: obj.slices.map( + ( + item: any /* eslint-disable-line @typescript-eslint/no-explicit-any */ + ) => types.RemainingAccountsSlice.fromDecoded(item) + ), + }) + } + + static toEncodable(fields: RemainingAccountsInfoFields) { + return { + slices: fields.slices.map((item) => + types.RemainingAccountsSlice.toEncodable(item) + ), + } + } + + toJSON(): RemainingAccountsInfoJSON { + return { + slices: this.slices.map((item) => item.toJSON()), + } + } + + static fromJSON(obj: RemainingAccountsInfoJSON): RemainingAccountsInfo { + return new RemainingAccountsInfo({ + slices: obj.slices.map((item) => + types.RemainingAccountsSlice.fromJSON(item) + ), + }) + } + + toEncodable() { + return RemainingAccountsInfo.toEncodable(this) + } +} diff --git a/packages/kamino-sdk/src/whirpools-client/types/RemainingAccountsSlice.ts b/packages/kamino-sdk/src/whirpools-client/types/RemainingAccountsSlice.ts new file mode 100644 index 00000000..27546bc2 --- /dev/null +++ b/packages/kamino-sdk/src/whirpools-client/types/RemainingAccountsSlice.ts @@ -0,0 +1,64 @@ +import { PublicKey } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars +import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars +import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars +import * as borsh from "@coral-xyz/borsh" + +export interface RemainingAccountsSliceFields { + accountsType: types.AccountsTypeKind + length: number +} + +export interface RemainingAccountsSliceJSON { + accountsType: types.AccountsTypeJSON + length: number +} + +export class RemainingAccountsSlice { + readonly accountsType: types.AccountsTypeKind + readonly length: number + + constructor(fields: RemainingAccountsSliceFields) { + this.accountsType = fields.accountsType + this.length = fields.length + } + + static layout(property?: string) { + return borsh.struct( + [types.AccountsType.layout("accountsType"), borsh.u8("length")], + property + ) + } + + // eslint-disable-next-line @typescript-eslint/no-explicit-any + static fromDecoded(obj: any) { + return new RemainingAccountsSlice({ + accountsType: types.AccountsType.fromDecoded(obj.accountsType), + length: obj.length, + }) + } + + static toEncodable(fields: RemainingAccountsSliceFields) { + return { + accountsType: fields.accountsType.toEncodable(), + length: fields.length, + } + } + + toJSON(): RemainingAccountsSliceJSON { + return { + accountsType: this.accountsType.toJSON(), + length: this.length, + } + } + + static fromJSON(obj: RemainingAccountsSliceJSON): RemainingAccountsSlice { + return new RemainingAccountsSlice({ + accountsType: types.AccountsType.fromJSON(obj.accountsType), + length: obj.length, + }) + } + + toEncodable() { + return RemainingAccountsSlice.toEncodable(this) + } +} diff --git a/packages/kamino-sdk/src/whirpools-client/types/Tick.ts b/packages/kamino-sdk/src/whirpools-client/types/Tick.ts index d266e0be..1481fe99 100644 --- a/packages/kamino-sdk/src/whirpools-client/types/Tick.ts +++ b/packages/kamino-sdk/src/whirpools-client/types/Tick.ts @@ -1,7 +1,7 @@ import { PublicKey } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars -import * as borsh from "@project-serum/borsh" +import * as borsh from "@coral-xyz/borsh" export interface TickFields { initialized: boolean diff --git a/packages/kamino-sdk/src/whirpools-client/types/TickLabel.ts b/packages/kamino-sdk/src/whirpools-client/types/TickLabel.ts index 2d76a6e3..8acfb392 100644 --- a/packages/kamino-sdk/src/whirpools-client/types/TickLabel.ts +++ b/packages/kamino-sdk/src/whirpools-client/types/TickLabel.ts @@ -1,7 +1,7 @@ import { PublicKey } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars -import * as borsh from "@project-serum/borsh" +import * as borsh from "@coral-xyz/borsh" export interface UpperJSON { kind: "Upper" diff --git a/packages/kamino-sdk/src/whirpools-client/types/WhirlpoolBumps.ts b/packages/kamino-sdk/src/whirpools-client/types/WhirlpoolBumps.ts index 66264849..d6de681a 100644 --- a/packages/kamino-sdk/src/whirpools-client/types/WhirlpoolBumps.ts +++ b/packages/kamino-sdk/src/whirpools-client/types/WhirlpoolBumps.ts @@ -1,7 +1,7 @@ import { PublicKey } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars -import * as borsh from "@project-serum/borsh" +import * as borsh from "@coral-xyz/borsh" export interface WhirlpoolBumpsFields { whirlpoolBump: number diff --git a/packages/kamino-sdk/src/whirpools-client/types/WhirlpoolRewardInfo.ts b/packages/kamino-sdk/src/whirpools-client/types/WhirlpoolRewardInfo.ts index 3e5b557a..76e2473f 100644 --- a/packages/kamino-sdk/src/whirpools-client/types/WhirlpoolRewardInfo.ts +++ b/packages/kamino-sdk/src/whirpools-client/types/WhirlpoolRewardInfo.ts @@ -1,7 +1,7 @@ import { PublicKey } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars -import * as borsh from "@project-serum/borsh" +import * as borsh from "@coral-xyz/borsh" export interface WhirlpoolRewardInfoFields { mint: PublicKey diff --git a/packages/kamino-sdk/src/whirpools-client/types/index.ts b/packages/kamino-sdk/src/whirpools-client/types/index.ts index ab7b3174..dce336d4 100644 --- a/packages/kamino-sdk/src/whirpools-client/types/index.ts +++ b/packages/kamino-sdk/src/whirpools-client/types/index.ts @@ -1,6 +1,7 @@ import * as CurrIndex from "./CurrIndex" import * as TickLabel from "./TickLabel" import * as Direction from "./Direction" +import * as AccountsType from "./AccountsType" export { OpenPositionBumps } from "./OpenPositionBumps" export type { @@ -26,6 +27,16 @@ export type { } from "./WhirlpoolRewardInfo" export { WhirlpoolBumps } from "./WhirlpoolBumps" export type { WhirlpoolBumpsFields, WhirlpoolBumpsJSON } from "./WhirlpoolBumps" +export { RemainingAccountsSlice } from "./RemainingAccountsSlice" +export type { + RemainingAccountsSliceFields, + RemainingAccountsSliceJSON, +} from "./RemainingAccountsSlice" +export { RemainingAccountsInfo } from "./RemainingAccountsInfo" +export type { + RemainingAccountsInfoFields, + RemainingAccountsInfoJSON, +} from "./RemainingAccountsInfo" export { CurrIndex } export type CurrIndexKind = CurrIndex.Below | CurrIndex.Inside | CurrIndex.Above @@ -43,3 +54,20 @@ export { Direction } export type DirectionKind = Direction.Left | Direction.Right export type DirectionJSON = Direction.LeftJSON | Direction.RightJSON + +export { AccountsType } + +export type AccountsTypeKind = + | AccountsType.TransferHookA + | AccountsType.TransferHookB + | AccountsType.TransferHookReward + | AccountsType.TransferHookInput + | AccountsType.TransferHookIntermediate + | AccountsType.TransferHookOutput +export type AccountsTypeJSON = + | AccountsType.TransferHookAJSON + | AccountsType.TransferHookBJSON + | AccountsType.TransferHookRewardJSON + | AccountsType.TransferHookInputJSON + | AccountsType.TransferHookIntermediateJSON + | AccountsType.TransferHookOutputJSON diff --git a/packages/kamino-sdk/tests/orca_utils.ts b/packages/kamino-sdk/tests/orca_utils.ts index e5e84fb6..aeaa4f47 100644 --- a/packages/kamino-sdk/tests/orca_utils.ts +++ b/packages/kamino-sdk/tests/orca_utils.ts @@ -3,7 +3,9 @@ import { DeployedPool, range } from './utils'; import * as WhirlpoolInstructions from '../src/whirpools-client/instructions'; import * as anchor from '@project-serum/anchor'; import { sendTransactionWithLogs, TOKEN_PROGRAM_ID } from '../src'; -import { PROGRAM_ID_CLI as WHIRLPOOL_PROGRAM_ID } from '../src/whirpools-client/programId'; +import { + WHIRLPOOL_PROGRAM_ID_CLI as WHIRLPOOL_PROGRAM_ID +} from '../src/whirpools-client/programId'; import { orderMints } from './raydium_utils'; import Decimal from 'decimal.js'; import { getStartTickIndex, priceToSqrtX64 } from '@orca-so/whirlpool-sdk'; @@ -79,18 +81,20 @@ export async function initializeWhirlpool( tickSize ); + const [tokenBadgeA] = getTokenBadge(WHIRLPOOL_PROGRAM_ID, config.publicKey, tokenMintA); + const [tokenBadgeB] = getTokenBadge(WHIRLPOOL_PROGRAM_ID, config.publicKey, tokenMintB); + { let tokenAVault = Keypair.generate(); let tokenBVault = Keypair.generate(); let initialPrice = 1.0; - let initialisePoolArgs: WhirlpoolInstructions.InitializePoolArgs = { + let initialisePoolArgs: WhirlpoolInstructions.InitializePoolV2Args = { tickSpacing: tickSize, - bumps: { whirlpoolBump: whirlpoolBump }, initialSqrtPrice: new anchor.BN(priceToSqrtX64(new Decimal(initialPrice), 6, 6)), }; - let initializePoolAccounts: WhirlpoolInstructions.InitializePoolAccounts = { + let initializePoolAccounts: WhirlpoolInstructions.InitializePoolV2Accounts = { whirlpoolsConfig: config.publicKey, tokenMintA: tokenMintA, tokenMintB: tokenMintB, @@ -99,17 +103,20 @@ export async function initializeWhirlpool( tokenVaultA: tokenAVault.publicKey, tokenVaultB: tokenBVault.publicKey, feeTier: feeTierPk, - tokenProgram: TOKEN_PROGRAM_ID, + tokenBadgeA, + tokenBadgeB, + tokenProgramA: TOKEN_PROGRAM_ID, + tokenProgramB: TOKEN_PROGRAM_ID, systemProgram: anchor.web3.SystemProgram.programId, rent: anchor.web3.SYSVAR_RENT_PUBKEY, }; const tx = new Transaction(); - let initializeIx = WhirlpoolInstructions.initializePool(initialisePoolArgs, initializePoolAccounts); + let initializeIx = WhirlpoolInstructions.initializePoolV2(initialisePoolArgs, initializePoolAccounts); tx.add(initializeIx); let sig = await sendTransactionWithLogs(connection, tx, signer.publicKey, [signer, tokenAVault, tokenBVault]); - console.log('InitializePool:', sig); + console.log('InitializePoolV2:', sig); } { @@ -185,7 +192,7 @@ export async function initTickArrayInstruction( startTick: number, programId: PublicKey ): Promise { - const [tickArrayPda, _tickArrayPdaBump] = await getTickArray(programId, whirlpool, startTick); + const [tickArrayPda, _tickArrayPdaBump] = getTickArray(programId, whirlpool, startTick); let initTickArrayArgs: WhirlpoolInstructions.InitializeTickArrayArgs = { startTickIndex: startTick, @@ -199,17 +206,29 @@ export async function initTickArrayInstruction( return WhirlpoolInstructions.initializeTickArray(initTickArrayArgs, initTickArrayAccounts); } -async function getTickArray( +function getTickArray( programId: PublicKey, whirlpoolAddress: PublicKey, startTick: number -): Promise<[anchor.web3.PublicKey, number]> { - return anchor.web3.PublicKey.findProgramAddress( +): [PublicKey, number] { + return anchor.web3.PublicKey.findProgramAddressSync( [Buffer.from('tick_array'), whirlpoolAddress.toBuffer(), Buffer.from(startTick.toString())], programId ); } +function getTokenBadge( + programId: PublicKey, + whirlpoolsConfigAddress: PublicKey, + tokenMintKey: PublicKey +): [PublicKey, number] { + return PublicKey.findProgramAddressSync([ + Buffer.from('token_badge'), + whirlpoolsConfigAddress.toBuffer(), + tokenMintKey.toBuffer() + ], programId); +} + export async function getTickArrayPubkeysFromRangeOrca( connection: Connection, whirlpool: PublicKey,