Skip to content

Commit

Permalink
update idl + codegen (#440)
Browse files Browse the repository at this point in the history
* update idl + codegen

* add idl in hubble-idl package
  • Loading branch information
silviutroscot authored Dec 20, 2023
1 parent f172f82 commit d5cfddd
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 3 deletions.
29 changes: 28 additions & 1 deletion packages/hubble-idl/src/kamino.json
Original file line number Diff line number Diff line change
Expand Up @@ -1994,6 +1994,11 @@
"name": "instructionSysvarAccount",
"isMut": false,
"isSigner": false
},
{
"name": "consensusAccount",
"isMut": false,
"isSigner": false
}
],
"args": [
Expand Down Expand Up @@ -2374,6 +2379,11 @@
"name": "instructionSysvarAccount",
"isMut": false,
"isSigner": false
},
{
"name": "consensusAccount",
"isMut": false,
"isSigner": false
}
],
"args": [
Expand Down Expand Up @@ -2468,6 +2478,11 @@
"name": "instructionSysvarAccount",
"isMut": false,
"isSigner": false
},
{
"name": "consensusAccount",
"isMut": false,
"isSigner": false
}
],
"args": [
Expand Down Expand Up @@ -3848,6 +3863,10 @@
"defined": "WithdrawalCaps"
}
},
{
"name": "swapUnevenAuthority",
"type": "publicKey"
},
{
"name": "padding3",
"type": "u64"
Expand All @@ -3857,7 +3876,7 @@
"type": {
"array": [
"u128",
21
19
]
}
},
Expand Down Expand Up @@ -5052,6 +5071,9 @@
},
{
"name": "UpdateRebalancesCapCurrentTotal"
},
{
"name": "UpdateSwapUnevenAuthority"
}
]
}
Expand Down Expand Up @@ -6416,6 +6438,11 @@
"code": 6140,
"name": "RebalancesCapReached",
"msg": "Rebalance caps reached, no rebalances are allowed until the end of the current interval"
},
{
"code": 6141,
"name": "SwapUnevenInvalidAuthority",
"msg": "Cannot swap uneven because authority is set and the given signer does not correspond"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export interface WhirlpoolStrategyFields {
lastSwapUnevenStepTimestamp: BN
farm: PublicKey
rebalancesCap: types.WithdrawalCapsFields
swapUnevenAuthority: PublicKey
padding3: BN
padding4: Array<BN>
padding5: Array<BN>
Expand Down Expand Up @@ -201,6 +202,7 @@ export interface WhirlpoolStrategyJSON {
lastSwapUnevenStepTimestamp: string
farm: string
rebalancesCap: types.WithdrawalCapsJSON
swapUnevenAuthority: string
padding3: string
padding4: Array<string>
padding5: Array<string>
Expand Down Expand Up @@ -303,6 +305,7 @@ export class WhirlpoolStrategy {
readonly lastSwapUnevenStepTimestamp: BN
readonly farm: PublicKey
readonly rebalancesCap: types.WithdrawalCaps
readonly swapUnevenAuthority: PublicKey
readonly padding3: BN
readonly padding4: Array<BN>
readonly padding5: Array<BN>
Expand Down Expand Up @@ -407,8 +410,9 @@ export class WhirlpoolStrategy {
borsh.u64("lastSwapUnevenStepTimestamp"),
borsh.publicKey("farm"),
types.WithdrawalCaps.layout("rebalancesCap"),
borsh.publicKey("swapUnevenAuthority"),
borsh.u64("padding3"),
borsh.array(borsh.u128(), 21, "padding4"),
borsh.array(borsh.u128(), 19, "padding4"),
borsh.array(borsh.u128(), 32, "padding5"),
borsh.array(borsh.u128(), 32, "padding6"),
borsh.array(borsh.u128(), 32, "padding7"),
Expand Down Expand Up @@ -519,6 +523,7 @@ export class WhirlpoolStrategy {
this.lastSwapUnevenStepTimestamp = fields.lastSwapUnevenStepTimestamp
this.farm = fields.farm
this.rebalancesCap = new types.WithdrawalCaps({ ...fields.rebalancesCap })
this.swapUnevenAuthority = fields.swapUnevenAuthority
this.padding3 = fields.padding3
this.padding4 = fields.padding4
this.padding5 = fields.padding5
Expand Down Expand Up @@ -668,6 +673,7 @@ export class WhirlpoolStrategy {
lastSwapUnevenStepTimestamp: dec.lastSwapUnevenStepTimestamp,
farm: dec.farm,
rebalancesCap: types.WithdrawalCaps.fromDecoded(dec.rebalancesCap),
swapUnevenAuthority: dec.swapUnevenAuthority,
padding3: dec.padding3,
padding4: dec.padding4,
padding5: dec.padding5,
Expand Down Expand Up @@ -776,6 +782,7 @@ export class WhirlpoolStrategy {
lastSwapUnevenStepTimestamp: this.lastSwapUnevenStepTimestamp.toString(),
farm: this.farm.toString(),
rebalancesCap: this.rebalancesCap.toJSON(),
swapUnevenAuthority: this.swapUnevenAuthority.toString(),
padding3: this.padding3.toString(),
padding4: this.padding4.map((item) => item.toString()),
padding5: this.padding5.map((item) => item.toString()),
Expand Down Expand Up @@ -890,6 +897,7 @@ export class WhirlpoolStrategy {
lastSwapUnevenStepTimestamp: new BN(obj.lastSwapUnevenStepTimestamp),
farm: new PublicKey(obj.farm),
rebalancesCap: types.WithdrawalCaps.fromJSON(obj.rebalancesCap),
swapUnevenAuthority: new PublicKey(obj.swapUnevenAuthority),
padding3: new BN(obj.padding3),
padding4: obj.padding4.map((item) => new BN(item)),
padding5: obj.padding5.map((item) => new BN(item)),
Expand Down
17 changes: 17 additions & 0 deletions packages/kamino-sdk/src/kamino-client/errors/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export type CustomError =
| SwapUnevenTooEarly
| FlashSwapTooEarly
| RebalancesCapReached
| SwapUnevenInvalidAuthority

export class IntegerOverflow extends Error {
static readonly code = 6000
Expand Down Expand Up @@ -1722,6 +1723,20 @@ export class RebalancesCapReached extends Error {
}
}

export class SwapUnevenInvalidAuthority extends Error {
static readonly code = 6141
readonly code = 6141
readonly name = "SwapUnevenInvalidAuthority"
readonly msg =
"Cannot swap uneven because authority is set and the given signer does not correspond"

constructor(readonly logs?: string[]) {
super(
"6141: Cannot swap uneven because authority is set and the given signer does not correspond"
)
}
}

export function fromCode(code: number, logs?: string[]): CustomError | null {
switch (code) {
case 6000:
Expand Down Expand Up @@ -2006,6 +2021,8 @@ export function fromCode(code: number, logs?: string[]): CustomError | null {
return new FlashSwapTooEarly(logs)
case 6140:
return new RebalancesCapReached(logs)
case 6141:
return new SwapUnevenInvalidAuthority(logs)
}

return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface FlashSwapUnevenVaultsEndAccounts {
tokenInfos: PublicKey
tokenProgram: PublicKey
instructionSysvarAccount: PublicKey
consensusAccount: PublicKey
}

export const layout = borsh.struct([
Expand Down Expand Up @@ -65,6 +66,7 @@ export function flashSwapUnevenVaultsEnd(
isSigner: false,
isWritable: false,
},
{ pubkey: accounts.consensusAccount, isSigner: false, isWritable: false },
]
const identifier = Buffer.from([226, 2, 190, 101, 202, 132, 156, 20])
const buffer = Buffer.alloc(1000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface FlashSwapUnevenVaultsStartAccounts {
tokenInfos: PublicKey
tokenProgram: PublicKey
instructionSysvarAccount: PublicKey
consensusAccount: PublicKey
}

export const layout = borsh.struct([borsh.u64("amount"), borsh.bool("aToB")])
Expand Down Expand Up @@ -62,6 +63,7 @@ export function flashSwapUnevenVaultsStart(
isSigner: false,
isWritable: false,
},
{ pubkey: accounts.consensusAccount, isSigner: false, isWritable: false },
]
const identifier = Buffer.from([129, 111, 174, 12, 10, 60, 149, 193])
const buffer = Buffer.alloc(1000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface SwapUnevenVaultsAccounts {
tokenInfos: PublicKey
tokenProgram: PublicKey
instructionSysvarAccount: PublicKey
consensusAccount: PublicKey
}

export const layout = borsh.struct([borsh.u64("targetLimitBps")])
Expand Down Expand Up @@ -69,6 +70,7 @@ export function swapUnevenVaults(
isSigner: false,
isWritable: false,
},
{ pubkey: accounts.consensusAccount, isSigner: false, isWritable: false },
]
const identifier = Buffer.from([143, 212, 101, 95, 105, 209, 184, 1])
const buffer = Buffer.alloc(1000)
Expand Down
29 changes: 28 additions & 1 deletion packages/kamino-sdk/src/kamino-client/kamino.json
Original file line number Diff line number Diff line change
Expand Up @@ -1994,6 +1994,11 @@
"name": "instructionSysvarAccount",
"isMut": false,
"isSigner": false
},
{
"name": "consensusAccount",
"isMut": false,
"isSigner": false
}
],
"args": [
Expand Down Expand Up @@ -2374,6 +2379,11 @@
"name": "instructionSysvarAccount",
"isMut": false,
"isSigner": false
},
{
"name": "consensusAccount",
"isMut": false,
"isSigner": false
}
],
"args": [
Expand Down Expand Up @@ -2468,6 +2478,11 @@
"name": "instructionSysvarAccount",
"isMut": false,
"isSigner": false
},
{
"name": "consensusAccount",
"isMut": false,
"isSigner": false
}
],
"args": [
Expand Down Expand Up @@ -3848,6 +3863,10 @@
"defined": "WithdrawalCaps"
}
},
{
"name": "swapUnevenAuthority",
"type": "publicKey"
},
{
"name": "padding3",
"type": "u64"
Expand All @@ -3857,7 +3876,7 @@
"type": {
"array": [
"u128",
21
19
]
}
},
Expand Down Expand Up @@ -5052,6 +5071,9 @@
},
{
"name": "UpdateRebalancesCapCurrentTotal"
},
{
"name": "UpdateSwapUnevenAuthority"
}
]
}
Expand Down Expand Up @@ -6416,6 +6438,11 @@
"code": 6140,
"name": "RebalancesCapReached",
"msg": "Rebalance caps reached, no rebalances are allowed until the end of the current interval"
},
{
"code": 6141,
"name": "SwapUnevenInvalidAuthority",
"msg": "Cannot swap uneven because authority is set and the given signer does not correspond"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,29 @@ export class UpdateRebalancesCapCurrentTotal {
}
}

export interface UpdateSwapUnevenAuthorityJSON {
kind: "UpdateSwapUnevenAuthority"
}

export class UpdateSwapUnevenAuthority {
static readonly discriminator = 50
static readonly kind = "UpdateSwapUnevenAuthority"
readonly discriminator = 50
readonly kind = "UpdateSwapUnevenAuthority"

toJSON(): UpdateSwapUnevenAuthorityJSON {
return {
kind: "UpdateSwapUnevenAuthority",
}
}

toEncodable() {
return {
UpdateSwapUnevenAuthority: {},
}
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function fromDecoded(obj: any): types.StrategyConfigOptionKind {
if (typeof obj !== "object") {
Expand Down Expand Up @@ -1309,6 +1332,9 @@ export function fromDecoded(obj: any): types.StrategyConfigOptionKind {
if ("UpdateRebalancesCapCurrentTotal" in obj) {
return new UpdateRebalancesCapCurrentTotal()
}
if ("UpdateSwapUnevenAuthority" in obj) {
return new UpdateSwapUnevenAuthority()
}

throw new Error("Invalid enum object")
}
Expand Down Expand Up @@ -1467,6 +1493,9 @@ export function fromJSON(
case "UpdateRebalancesCapCurrentTotal": {
return new UpdateRebalancesCapCurrentTotal()
}
case "UpdateSwapUnevenAuthority": {
return new UpdateSwapUnevenAuthority()
}
}
}

Expand Down Expand Up @@ -1522,6 +1551,7 @@ export function layout(property?: string) {
borsh.struct([], "UpdateRebalancesCapCapacity"),
borsh.struct([], "UpdateRebalancesCapInterval"),
borsh.struct([], "UpdateRebalancesCapCurrentTotal"),
borsh.struct([], "UpdateSwapUnevenAuthority"),
])
if (property !== undefined) {
return ret.replicate(property)
Expand Down
2 changes: 2 additions & 0 deletions packages/kamino-sdk/src/kamino-client/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ export type StrategyConfigOptionKind =
| StrategyConfigOption.UpdateRebalancesCapCapacity
| StrategyConfigOption.UpdateRebalancesCapInterval
| StrategyConfigOption.UpdateRebalancesCapCurrentTotal
| StrategyConfigOption.UpdateSwapUnevenAuthority
export type StrategyConfigOptionJSON =
| StrategyConfigOption.UpdateDepositCapJSON
| StrategyConfigOption.UpdateDepositCapIxnJSON
Expand Down Expand Up @@ -295,6 +296,7 @@ export type StrategyConfigOptionJSON =
| StrategyConfigOption.UpdateRebalancesCapCapacityJSON
| StrategyConfigOption.UpdateRebalancesCapIntervalJSON
| StrategyConfigOption.UpdateRebalancesCapCurrentTotalJSON
| StrategyConfigOption.UpdateSwapUnevenAuthorityJSON

export { StrategyStatus }

Expand Down

0 comments on commit d5cfddd

Please sign in to comment.