diff --git a/.changeset/rotten-coats-press.md b/.changeset/rotten-coats-press.md new file mode 100644 index 00000000..376296eb --- /dev/null +++ b/.changeset/rotten-coats-press.md @@ -0,0 +1,5 @@ +--- +"@macalinao/coda-visitors": patch +--- + +Update ATA refs diff --git a/.changeset/warm-readers-poke.md b/.changeset/warm-readers-poke.md new file mode 100644 index 00000000..80d6217f --- /dev/null +++ b/.changeset/warm-readers-poke.md @@ -0,0 +1,5 @@ +--- +"@macalinao/clients-kamino-lending": minor +--- + +Update Kamino Lending PDAs diff --git a/biome.jsonc b/biome.jsonc index 85b2124a..6908d919 100644 --- a/biome.jsonc +++ b/biome.jsonc @@ -1,5 +1,5 @@ { - "$schema": "https://biomejs.dev/schemas/2.2.5/schema.json", + "$schema": "https://biomejs.dev/schemas/2.2.6/schema.json", "extends": ["@macalinao/biome-config/base"], "files": { "ignoreUnknown": false, diff --git a/bun.lock b/bun.lock index 26c25e96..283b3008 100644 --- a/bun.lock +++ b/bun.lock @@ -4,14 +4,14 @@ "": { "name": "@macalinao/coda-monorepo", "devDependencies": { - "@biomejs/biome": "^2.2.5", + "@biomejs/biome": "^2.2.6", "@changesets/cli": "^2.29.7", "@macalinao/biome-config": "^0.1.2", "husky": "^9.1.7", "lint-staged": "^16.2.4", "turbo": "^2.5.8", "typedoc": "^0.28.14", - "typescript": "catalog:", + "typescript": "^5.9.3", }, }, "apps/docs": { diff --git a/clients/kamino-lending/coda.config.mjs b/clients/kamino-lending/coda.config.mjs index f80b795c..a5efb804 100644 --- a/clients/kamino-lending/coda.config.mjs +++ b/clients/kamino-lending/coda.config.mjs @@ -1,12 +1,20 @@ import { + accountValueNode, addPdasVisitor, + associatedTokenAccountValueNode, constantPdaSeedNodeFromString, defineConfig, numberTypeNode, + pdaLinkNode, + pdaSeedValueNode, + pdaValueNode, programLinkNode, publicKeyTypeNode, renameVisitor, + SYSVAR_INSTRUCTIONS_VALUE_NODE, stringTypeNode, + TOKEN_PROGRAM_VALUE_NODE, + updateAccountsVisitor, variablePdaSeedNode, } from "@macalinao/coda"; @@ -18,6 +26,144 @@ export default defineConfig({ npmPackageName: "@macalinao/clients-kamino-lending", }, instructionAccountDefaultValues: [ + // farms + ...["initializeFarm", "stake"].map((instruction) => ({ + instruction, + account: "farmVault", + defaultValue: pdaValueNode(pdaLinkNode("farmVault"), [ + pdaSeedValueNode("farmState", accountValueNode("farmState")), + pdaSeedValueNode("tokenMint", accountValueNode("tokenMint")), + ]), + })), + // note: delegated farms will have a different seed, the "owner" is the delegatee. + ...["harvestReward", "stake", "unstake", "withdrawUnstakedDeposits"].map( + (instruction) => ({ + instruction, + account: "userState", + defaultValue: pdaValueNode(pdaLinkNode("farmsUserState"), [ + pdaSeedValueNode("farmState", accountValueNode("farmState")), + pdaSeedValueNode("owner", accountValueNode("owner")), + ]), + }), + ), + { + instruction: "initializeUser", + account: "userState", + defaultValue: pdaValueNode(pdaLinkNode("farmsUserState"), [ + pdaSeedValueNode("farmState", accountValueNode("farmState")), + pdaSeedValueNode("owner", accountValueNode("delegatee")), + ]), + }, + { + account: "userRewardAta", + defaultValue: associatedTokenAccountValueNode({ + owner: accountValueNode("owner"), + mint: accountValueNode("rewardMint"), + tokenProgram: accountValueNode("tokenProgram"), + }), + }, + { + account: "rewardVault", + defaultValue: pdaValueNode(pdaLinkNode("rewardVault"), [ + pdaSeedValueNode("farmState", accountValueNode("farmState")), + pdaSeedValueNode("rewardMint", accountValueNode("rewardMint")), + ]), + }, + { + account: "rewardsVault", + defaultValue: pdaValueNode(pdaLinkNode("rewardVault"), [ + pdaSeedValueNode("farmState", accountValueNode("farmState")), + pdaSeedValueNode("rewardMint", accountValueNode("rewardMint")), + ]), + }, + { + account: "rewardsTreasuryVault", + defaultValue: pdaValueNode(pdaLinkNode("rewardTreasuryVault"), [ + pdaSeedValueNode("globalConfig", accountValueNode("globalConfig")), + pdaSeedValueNode("rewardMint", accountValueNode("rewardMint")), + ]), + }, + { + account: "rewardTreasuryVault", + defaultValue: pdaValueNode(pdaLinkNode("rewardTreasuryVault"), [ + pdaSeedValueNode("globalConfig", accountValueNode("globalConfig")), + pdaSeedValueNode("rewardMint", accountValueNode("rewardMint")), + ]), + }, + { + account: "treasuryVaultAuthority", + defaultValue: pdaValueNode(pdaLinkNode("treasuryVaultsAuthority"), [ + pdaSeedValueNode("globalConfig", accountValueNode("globalConfig")), + ]), + }, + { + account: "treasuryVaultsAuthority", + defaultValue: pdaValueNode(pdaLinkNode("treasuryVaultsAuthority"), [ + pdaSeedValueNode("globalConfig", accountValueNode("globalConfig")), + ]), + }, + { + account: "farmVaultsAuthority", + defaultValue: pdaValueNode(pdaLinkNode("farmVaultsAuthority"), [ + pdaSeedValueNode("farmState", accountValueNode("farmState")), + ]), + }, + + // lending + { + account: /collateralTokenProgram|liquidityTokenProgram/, + defaultValue: TOKEN_PROGRAM_VALUE_NODE, + }, + { + account: "feeReceiver", + defaultValue: pdaValueNode(pdaLinkNode("reserveFeeVault"), [ + pdaSeedValueNode("lendingMarket", accountValueNode("lendingMarket")), + pdaSeedValueNode("mint", accountValueNode("reserveLiquidityMint")), + ]), + }, + { + account: "reserveLiquiditySupply", + defaultValue: pdaValueNode(pdaLinkNode("reserveLiquiditySupply"), [ + pdaSeedValueNode("lendingMarket", accountValueNode("lendingMarket")), + pdaSeedValueNode("mint", accountValueNode("reserveLiquidityMint")), + ]), + }, + { + account: "reserveLiquidityFeeReceiver", + defaultValue: pdaValueNode(pdaLinkNode("reserveFeeVault"), [ + pdaSeedValueNode("lendingMarket", accountValueNode("lendingMarket")), + pdaSeedValueNode("mint", accountValueNode("reserveLiquidityMint")), + ]), + }, + { + account: "reserveCollateralMint", + defaultValue: pdaValueNode(pdaLinkNode("reserveCollateralMint"), [ + pdaSeedValueNode("lendingMarket", accountValueNode("lendingMarket")), + pdaSeedValueNode("mint", accountValueNode("reserveLiquidityMint")), + ]), + }, + { + account: "reserveCollateralSupply", + defaultValue: pdaValueNode(pdaLinkNode("reserveCollateralSupply"), [ + pdaSeedValueNode("lendingMarket", accountValueNode("lendingMarket")), + pdaSeedValueNode("mint", accountValueNode("reserveLiquidityMint")), + ]), + }, + { + instruction: "initGlobalConfig", + account: "globalConfig", + defaultValue: pdaValueNode(pdaLinkNode("lendingGlobalConfigState")), + }, + { + account: "lendingMarketAuthority", + defaultValue: pdaValueNode(pdaLinkNode("lendingMarketAuth"), [ + pdaSeedValueNode("lendingMarket", accountValueNode("lendingMarket")), + ]), + }, + { + account: /sysvarInfo|instructionSysvarAccount/, + defaultValue: SYSVAR_INSTRUCTIONS_VALUE_NODE, + }, { account: "farmsProgram", defaultValue: programLinkNode("farms"), @@ -28,15 +174,61 @@ export default defineConfig({ addPdasVisitor({ farms: [ { - name: "obligationFarmState", + name: "rewardTreasuryVault", + seeds: [ + constantPdaSeedNodeFromString("utf8", "tvault"), + variablePdaSeedNode("globalConfig", publicKeyTypeNode()), + variablePdaSeedNode("rewardMint", publicKeyTypeNode()), + ], + }, + { + name: "treasuryVaultsAuthority", + seeds: [ + constantPdaSeedNodeFromString("utf8", "authority"), + variablePdaSeedNode("globalConfig", publicKeyTypeNode()), + ], + }, + { + name: "farmVaultsAuthority", + seeds: [ + constantPdaSeedNodeFromString("utf8", "authority"), + variablePdaSeedNode("farmState", publicKeyTypeNode()), + ], + }, + { + name: "farmVault", + seeds: [ + constantPdaSeedNodeFromString("utf8", "fvault"), + variablePdaSeedNode("farmState", publicKeyTypeNode()), + variablePdaSeedNode("tokenMint", publicKeyTypeNode()), + ], + }, + { + name: "rewardVault", + seeds: [ + constantPdaSeedNodeFromString("utf8", "rvault"), + variablePdaSeedNode("farmState", publicKeyTypeNode()), + variablePdaSeedNode("rewardMint", publicKeyTypeNode()), + ], + }, + { + name: "farmsUserState", seeds: [ constantPdaSeedNodeFromString("utf8", "user"), - variablePdaSeedNode("farm", publicKeyTypeNode()), - variablePdaSeedNode("obligation", publicKeyTypeNode()), + variablePdaSeedNode("farmState", publicKeyTypeNode()), + variablePdaSeedNode( + "owner", + publicKeyTypeNode(), + "The user who is farming. This is sometimes the obligation in the case of delegated farms.", + ), ], }, ], kaminoLending: [ + { + name: "lendingGlobalConfigState", + seeds: [constantPdaSeedNodeFromString("utf8", "global_config")], + }, { name: "obligation", seeds: [ @@ -122,6 +314,7 @@ export default defineConfig({ farms: { accounts: { userState: "farmsUserState", + globalConfig: "farmsGlobalConfig", }, instructions: { idlMissingTypes: "farmsIdlMissingTypes", @@ -132,5 +325,30 @@ export default defineConfig({ }, }, }), + updateAccountsVisitor({ + // farms + farmsUserState: { + pda: pdaLinkNode("farmsUserState"), + }, + // lending + lendingGlobalConfig: { + pda: pdaLinkNode("lendingGlobalConfigState"), + }, + obligation: { + pda: pdaLinkNode("obligation"), + }, + userMetadata: { + pda: pdaLinkNode("userMetadata"), + }, + referrerTokenState: { + pda: pdaLinkNode("referrerTokenState"), + }, + referrerState: { + pda: pdaLinkNode("referrerState"), + }, + shortUrl: { + pda: pdaLinkNode("shortUrl"), + }, + }), ], }); diff --git a/clients/kamino-lending/idls/kamino_lending.json b/clients/kamino-lending/idls/kamino_lending.json index 02581295..6086a497 100644 --- a/clients/kamino-lending/idls/kamino_lending.json +++ b/clients/kamino-lending/idls/kamino_lending.json @@ -187,9 +187,12 @@ "discriminator": [61, 148, 100, 70, 143, 107, 17, 13], "accounts": [ { - "name": "lending_market_owner", + "name": "signer", "signer": true }, + { + "name": "global_config" + }, { "name": "lending_market" }, @@ -201,14 +204,18 @@ "args": [ { "name": "mode", - "type": "u64" + "type": { + "defined": { + "name": "UpdateConfigMode" + } + } }, { "name": "value", "type": "bytes" }, { - "name": "skip_validation", + "name": "skip_config_integrity_validation", "type": "bool" } ] @@ -249,8 +256,7 @@ "discriminator": [158, 201, 158, 189, 33, 93, 162, 103], "accounts": [ { - "name": "lending_market_owner", - "signer": true + "name": "global_config" }, { "name": "lending_market" @@ -269,12 +275,11 @@ "writable": true }, { - "name": "lending_market_owner_ata", + "name": "fee_collector_ata", "writable": true }, { - "name": "token_program", - "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" + "name": "token_program" } ], "args": [ @@ -304,8 +309,7 @@ "writable": true }, { - "name": "instruction_sysvar_account", - "address": "Sysvar1nstructions1111111111111111111111111" + "name": "instruction_sysvar_account" } ], "args": [ @@ -338,8 +342,7 @@ "writable": true }, { - "name": "instruction_sysvar_account", - "address": "Sysvar1nstructions1111111111111111111111111" + "name": "instruction_sysvar_account" } ] }, @@ -395,17 +398,6 @@ } ] }, - { - "name": "refresh_reserves_batch", - "discriminator": [144, 110, 26, 103, 162, 204, 252, 147], - "accounts": [], - "args": [ - { - "name": "skip_price_updates", - "type": "bool" - } - ] - }, { "name": "refresh_reserve", "discriminator": [2, 218, 138, 235, 79, 201, 25, 102], @@ -436,6 +428,17 @@ ], "args": [] }, + { + "name": "refresh_reserves_batch", + "discriminator": [144, 110, 26, 103, 162, 204, 252, 147], + "accounts": [], + "args": [ + { + "name": "skip_price_updates", + "type": "bool" + } + ] + }, { "name": "deposit_reserve_liquidity", "discriminator": [169, 201, 30, 126, 6, 205, 102, 68], @@ -480,8 +483,7 @@ "name": "liquidity_token_program" }, { - "name": "instruction_sysvar_account", - "address": "Sysvar1nstructions1111111111111111111111111" + "name": "instruction_sysvar_account" } ], "args": [ @@ -535,8 +537,7 @@ "name": "liquidity_token_program" }, { - "name": "instruction_sysvar_account", - "address": "Sysvar1nstructions1111111111111111111111111" + "name": "instruction_sysvar_account" } ], "args": [ @@ -736,12 +737,10 @@ "writable": true }, { - "name": "token_program", - "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" + "name": "token_program" }, { - "name": "instruction_sysvar_account", - "address": "Sysvar1nstructions1111111111111111111111111" + "name": "instruction_sysvar_account" } ], "args": [ @@ -785,8 +784,7 @@ "name": "token_program" }, { - "name": "instruction_sysvar_account", - "address": "Sysvar1nstructions1111111111111111111111111" + "name": "instruction_sysvar_account" } ] }, @@ -853,8 +851,7 @@ "name": "token_program" }, { - "name": "instruction_sysvar_account", - "address": "Sysvar1nstructions1111111111111111111111111" + "name": "instruction_sysvar_account" } ], "args": [ @@ -901,8 +898,7 @@ "name": "token_program" }, { - "name": "instruction_sysvar_account", - "address": "Sysvar1nstructions1111111111111111111111111" + "name": "instruction_sysvar_account" } ] }, @@ -978,8 +974,7 @@ "name": "token_program" }, { - "name": "instruction_sysvar_account", - "address": "Sysvar1nstructions1111111111111111111111111" + "name": "instruction_sysvar_account" } ], "args": [ @@ -1038,8 +1033,7 @@ "name": "token_program" }, { - "name": "instruction_sysvar_account", - "address": "Sysvar1nstructions1111111111111111111111111" + "name": "instruction_sysvar_account" } ] }, @@ -1103,8 +1097,7 @@ "name": "token_program" }, { - "name": "instruction_sysvar_account", - "address": "Sysvar1nstructions1111111111111111111111111" + "name": "instruction_sysvar_account" } ], "args": [ @@ -1151,8 +1144,7 @@ "name": "token_program" }, { - "name": "instruction_sysvar_account", - "address": "Sysvar1nstructions1111111111111111111111111" + "name": "instruction_sysvar_account" } ] }, @@ -1222,8 +1214,7 @@ "name": "token_program" }, { - "name": "instruction_sysvar_account", - "address": "Sysvar1nstructions1111111111111111111111111" + "name": "instruction_sysvar_account" } ] }, @@ -1279,8 +1270,7 @@ "name": "liquidity_token_program" }, { - "name": "instruction_sysvar_account", - "address": "Sysvar1nstructions1111111111111111111111111" + "name": "instruction_sysvar_account" } ] }, @@ -1385,8 +1375,7 @@ "name": "liquidity_token_program" }, { - "name": "instruction_sysvar_account", - "address": "Sysvar1nstructions1111111111111111111111111" + "name": "instruction_sysvar_account" } ] }, @@ -1442,8 +1431,7 @@ "name": "liquidity_token_program" }, { - "name": "instruction_sysvar_account", - "address": "Sysvar1nstructions1111111111111111111111111" + "name": "instruction_sysvar_account" } ] }, @@ -1545,8 +1533,7 @@ "name": "liquidity_token_program" }, { - "name": "instruction_sysvar_account", - "address": "Sysvar1nstructions1111111111111111111111111" + "name": "instruction_sysvar_account" } ], "args": [ @@ -1612,8 +1599,7 @@ "name": "liquidity_token_program" }, { - "name": "instruction_sysvar_account", - "address": "Sysvar1nstructions1111111111111111111111111" + "name": "instruction_sysvar_account" } ] }, @@ -1696,8 +1682,7 @@ "name": "liquidity_token_program" }, { - "name": "instruction_sysvar_account", - "address": "Sysvar1nstructions1111111111111111111111111" + "name": "instruction_sysvar_account" } ], "args": [ @@ -1763,8 +1748,7 @@ "name": "liquidity_token_program" }, { - "name": "instruction_sysvar_account", - "address": "Sysvar1nstructions1111111111111111111111111" + "name": "instruction_sysvar_account" } ] }, @@ -1868,8 +1852,7 @@ "name": "withdraw_liquidity_token_program" }, { - "name": "instruction_sysvar_account", - "address": "Sysvar1nstructions1111111111111111111111111" + "name": "instruction_sysvar_account" } ], "args": [ @@ -1906,7 +1889,8 @@ "name": "lending_market" }, { - "name": "lending_market_authority" + "name": "lending_market_authority", + "writable": true }, { "name": "repay_reserve", @@ -1964,8 +1948,7 @@ "name": "withdraw_liquidity_token_program" }, { - "name": "instruction_sysvar_account", - "address": "Sysvar1nstructions1111111111111111111111111" + "name": "instruction_sysvar_account" } ] }, @@ -2062,8 +2045,7 @@ "optional": true }, { - "name": "sysvar_info", - "address": "Sysvar1nstructions1111111111111111111111111" + "name": "sysvar_info" }, { "name": "token_program" @@ -2124,12 +2106,10 @@ "optional": true }, { - "name": "sysvar_info", - "address": "Sysvar1nstructions1111111111111111111111111" + "name": "sysvar_info" }, { - "name": "token_program", - "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" + "name": "token_program" } ], "args": [ @@ -2328,14 +2308,116 @@ ], "args": [] }, + { + "name": "set_obligation_order", + "discriminator": [81, 1, 99, 156, 211, 83, 78, 46], + "accounts": [ + { + "name": "owner", + "signer": true + }, + { + "name": "obligation", + "writable": true + }, + { + "name": "lending_market" + } + ], + "args": [ + { + "name": "index", + "type": "u8" + }, + { + "name": "order", + "type": { + "defined": { + "name": "ObligationOrderInput" + } + } + } + ] + }, + { + "name": "init_global_config", + "discriminator": [140, 136, 214, 48, 87, 0, 120, 255], + "accounts": [ + { + "name": "payer", + "writable": true, + "signer": true + }, + { + "name": "global_config", + "writable": true + }, + { + "name": "program_data" + }, + { + "name": "system_program" + }, + { + "name": "rent" + } + ], + "args": [] + }, + { + "name": "update_global_config", + "discriminator": [164, 84, 130, 189, 111, 58, 250, 200], + "accounts": [ + { + "name": "global_admin", + "signer": true + }, + { + "name": "global_config", + "writable": true + } + ], + "args": [ + { + "name": "mode", + "type": { + "defined": { + "name": "UpdateGlobalConfigMode" + } + } + }, + { + "name": "value", + "type": "bytes" + } + ] + }, + { + "name": "update_global_config_admin", + "discriminator": [184, 87, 23, 193, 156, 238, 175, 119], + "accounts": [ + { + "name": "pending_admin", + "signer": true + }, + { + "name": "global_config", + "writable": true + } + ], + "args": [] + }, { "name": "idl_missing_types", "discriminator": [130, 80, 38, 153, 80, 212, 182, 253], "accounts": [ { - "name": "lending_market_owner", + "name": "signer", "signer": true }, + { + "name": "global_config" + }, { "name": "lending_market" }, @@ -2409,6 +2491,10 @@ "name": "UserState", "discriminator": [72, 177, 85, 249, 76, 167, 186, 126] }, + { + "name": "LendingGlobalConfig", + "discriminator": [149, 8, 156, 202, 160, 252, 176, 217] + }, { "name": "LendingMarket", "discriminator": [246, 114, 50, 98, 72, 157, 28, 120] @@ -2861,8 +2947,8 @@ }, { "code": 6084, - "name": "ObligationInDeprecatedReserve", - "msg": "Obligation has a deposit in a deprecated reserve" + "name": "ObligationInObsoleteReserve", + "msg": "Obligation has a deposit or borrow in an obsolete reserve" }, { "code": 6085, @@ -2906,7 +2992,7 @@ }, { "code": 6093, - "name": "WorseLTVBlocked", + "name": "WorseLtvBlocked", "msg": "Cannot get the obligation in a worse position" }, { @@ -2941,8 +3027,8 @@ }, { "code": 6100, - "name": "LiquidationLowestLTVPriority", - "msg": "Liquidation must prioritize the collateral with the lowest LTV" + "name": "LiquidationLowestLiquidationLtvPriority", + "msg": "Liquidation must prioritize the collateral with the lowest liquidation LTV" }, { "code": 6101, @@ -3031,12 +3117,12 @@ }, { "code": 6118, - "name": "MinLtvAssetsPriority", - "msg": "The operation must prioritize the collateral with the lowest LTV" + "name": "LowestLtvAssetsPriority", + "msg": "Withdrawing must prioritize the collateral with the lowest reserve max-LTV" }, { "code": 6119, - "name": "WorseLTVThanUnhealthyLTV", + "name": "WorseLtvThanUnhealthyLtv", "msg": "Cannot get the obligation liquidatable" }, { @@ -3053,6 +3139,41 @@ "code": 6122, "name": "InsufficientRepayAmount", "msg": "Liquidator provided repay amount lower than required by liquidation rules" + }, + { + "code": 6123, + "name": "OrderIndexOutOfBounds", + "msg": "Obligation order of the given index cannot exist" + }, + { + "code": 6124, + "name": "InvalidOrderConfiguration", + "msg": "Given order configuration has wrong parameters" + }, + { + "code": 6125, + "name": "OrderConfigurationNotSupportedByObligation", + "msg": "Given order configuration cannot be used with the current state of the obligation" + }, + { + "code": 6126, + "name": "OperationNotPermittedWithCurrentObligationOrders", + "msg": "Single debt, single collateral obligation orders have to be cancelled before changing the deposit/borrow count" + }, + { + "code": 6127, + "name": "OperationNotPermittedMarketImmutable", + "msg": "Cannot update lending market because it is set as immutable" + }, + { + "code": 6128, + "name": "OrderCreationDisabled", + "msg": "Creation of new orders is disabled" + }, + { + "code": 6129, + "name": "NoUpgradeAuthority", + "msg": "Cannot initialize global config because there is no upgrade authority to the program" } ], "types": [ @@ -3083,7 +3204,7 @@ "name": "UpdateFeesFlashLoanFee" }, { - "name": "UpdateFeesReferralFeeBps" + "name": "DeprecatedUpdateFeesReferralFeeBps" }, { "name": "UpdateDepositLimit" @@ -3143,10 +3264,10 @@ "name": "UpdateDepositWithdrawalCap" }, { - "name": "UpdateDebtWithdrawalCapCurrentTotal" + "name": "DeprecatedUpdateDebtWithdrawalCapCurrentTotal" }, { - "name": "UpdateDepositWithdrawalCapCurrentTotal" + "name": "DeprecatedUpdateDepositWithdrawalCapCurrentTotal" }, { "name": "UpdateBadDebtLiquidationBonusBps" @@ -3207,6 +3328,9 @@ }, { "name": "UpdateDeleveragingBonusIncreaseBpsPerDay" + }, + { + "name": "UpdateProtocolOrderExecutionFee" } ] } @@ -3339,87 +3463,63 @@ }, { "name": "UpdateInitialDepositAmount" + }, + { + "name": "UpdateObligationOrderExecutionEnabled" + }, + { + "name": "UpdateImmutableFlag" + }, + { + "name": "UpdateObligationOrderCreationEnabled" } ] } }, { - "name": "LastUpdate", - "serialization": "bytemuck", - "repr": { - "kind": "c", - "packed": true - }, + "name": "UpdateGlobalConfigMode", "type": { - "kind": "struct", - "fields": [ - { - "name": "slot", - "type": "u64" - }, + "kind": "enum", + "variants": [ { - "name": "stale", - "type": "u8" + "name": "PendingAdmin" }, { - "name": "price_status", - "type": "u8" - }, - { - "name": "placeholder", - "type": { - "array": ["u8", 6] - } + "name": "FeeCollector" } ] } }, { - "name": "ElevationGroupLendingMarket", + "name": "LastUpdate", "serialization": "bytemuck", "repr": { "kind": "c", "packed": true }, + "docs": ["Last update state"], "type": { "kind": "struct", "fields": [ { - "name": "max_liquidation_bonus_bps", - "type": "u16" - }, - { - "name": "id", - "type": "u8" - }, - { - "name": "ltv_pct", - "type": "u8" - }, - { - "name": "liquidation_threshold_pct", - "type": "u8" - }, - { - "name": "allow_new_loans", - "type": "u8" + "name": "slot", + "docs": ["Last slot when updated"], + "type": "u64" }, { - "name": "max_reserves_as_collateral", + "name": "stale", + "docs": ["True when marked stale, false when slot updated"], "type": "u8" }, { - "name": "padding0", + "name": "price_status", + "docs": ["Status of the prices used to calculate the last update"], "type": "u8" }, { - "name": "debt_reserve", - "type": "pubkey" - }, - { - "name": "padding1", + "name": "placeholder", "type": { - "array": ["u64", 4] + "array": ["u8", 6] } } ] @@ -3460,6 +3560,7 @@ }, { "name": "debt_reserve", + "docs": ["Mandatory debt reserve for this elevation group"], "type": "pubkey" }, { @@ -3494,23 +3595,35 @@ "kind": "c", "packed": true }, + "docs": ["Obligation collateral state"], "type": { "kind": "struct", "fields": [ { "name": "deposit_reserve", + "docs": ["Reserve collateral is deposited to"], "type": "pubkey" }, { "name": "deposited_amount", + "docs": ["Amount of collateral deposited"], "type": "u64" }, { "name": "market_value_sf", + "docs": [ + "Collateral market value in quote currency (scaled fraction)" + ], "type": "u128" }, { "name": "borrowed_amount_against_this_collateral_in_elevation_group", + "docs": [ + "Debt amount (lamport) taken against this collateral.", + "(only meaningful if this obligation is part of an elevation group, otherwise 0)", + "This is only indicative of the debt computed on the last refresh obligation.", + "If the obligation have multiple collateral this value is the same for all of them." + ], "type": "u64" }, { @@ -3529,15 +3642,20 @@ "kind": "c", "packed": true }, + "docs": ["Obligation liquidity state"], "type": { "kind": "struct", "fields": [ { "name": "borrow_reserve", + "docs": ["Reserve liquidity is borrowed from"], "type": "pubkey" }, { "name": "cumulative_borrow_rate_bsf", + "docs": [ + "Borrow rate used for calculating interest (big scaled fraction)" + ], "type": { "defined": { "name": "BigFractionBytes" @@ -3550,18 +3668,30 @@ }, { "name": "borrowed_amount_sf", + "docs": [ + "Amount of liquidity borrowed plus interest (scaled fraction)" + ], "type": "u128" }, { "name": "market_value_sf", + "docs": [ + "Liquidity market value in quote currency (scaled fraction)" + ], "type": "u128" }, { "name": "borrow_factor_adjusted_market_value_sf", + "docs": [ + "Risk adjusted liquidity market value in quote currency - DEBUG ONLY - use market_value instead" + ], "type": "u128" }, { "name": "borrowed_amount_outside_elevation_groups", + "docs": [ + "Amount of liquidity borrowed outside of an elevation group" + ], "type": "u64" }, { @@ -3573,6 +3703,249 @@ ] } }, + { + "name": "ObligationOrderInput", + "docs": ["A single obligation order.", "See [Obligation::orders]."], + "type": { + "kind": "struct", + "fields": [ + { + "name": "condition_threshold_sf", + "docs": [ + "A threshold value used by the condition (scaled [Fraction]).", + "The exact meaning depends on the specific [Self::condition_type].", + "", + "Examples:", + "- when `condition_type == 2 (UserLtvBelow)`:", + "then a value of `0.455` here means that the order is active only when the obligation's", + "user LTV is less than `0.455` (i.e. < 45.5%).", + "- when `condition_type == 3 (DebtCollPriceRatioAbove)`:", + "assuming the obligation uses BTC collateral for SOL debt, then a value of `491.3` here", + "means that the order is active only when the BTC-SOL price is greater than `491.3` (i.e.", + "> 491.3 SOL per BTC)." + ], + "type": "u128" + }, + { + "name": "opportunity_parameter_sf", + "docs": [ + "A configuration parameter used by the opportunity (scaled [Fraction]).", + "The exact meaning depends on the specific [Self::opportunity_type].", + "", + "Examples:", + "- when `opportunity_type == 0 (DeleverageSingleDebtAmount)`:", + "Assuming the obligation uses BTC collateral for SOL debt, then a value of `1_234_000_000`", + "here means that a liquidator may repay up to 1234000000 lamports (i.e. 1.234 SOL) on this", + "obligation.", + "Note: the special value of [Fraction::MAX] is *not* allowed in this case.", + "- when `opportunity_type == 1 (DeleverageAllDebtAmount)`:", + "The only allowed value in this case is [Fraction::MAX] (to emphasize that *all* debt", + "should be repaid)." + ], + "type": "u128" + }, + { + "name": "min_execution_bonus_bps", + "docs": [ + "A *minimum* additional fraction of collateral transferred to the liquidator, in bps.", + "", + "The minimum bonus is applied exactly when the [Self::condition_threshold_sf] is met, and", + "grows linearly towards the [Self::max_execution_bonus_bps].", + "", + "Example: a value of `50` here means 50bps == 0.5% bonus for an \"LTV > 65%\" order, when", + "executed precisely at the moment LTV exceeds 65%." + ], + "type": "u16" + }, + { + "name": "max_execution_bonus_bps", + "docs": [ + "A *maximum* additional fraction of collateral transferred to the liquidator, in bps.", + "", + "The maximum bonus is applied at the relevant \"extreme\" state of the obligation, i.e.:", + "- for a stop-loss condition, it is a point at which the obligation becomes liquidatable;", + "- for a take-profit condition, it is a point at which obligation has 0% LTV.", + "", + "In non-extreme states, the actual bonus value is interpolated linearly, starting from", + "[Self::min_execution_bonus_bps] (at the point specified by the order's condition).", + "", + "Example: a value of `300` here means 300bps == 3.0% bonus for a \"debt/coll price > 140\"", + "order, when executed at a higher price = 200, at which the obligation's LTV happens to", + "be equal to its liquidation LTV." + ], + "type": "u16" + }, + { + "name": "condition_type", + "docs": [ + "Serialized [ConditionType].", + "The entire order is void when this is zeroed (i.e. representing [ConditionType::Never]).", + "", + "Example: a value of `2` here denotes `UserLtvBelow` condition type. Of course, to", + "interpret this condition, we also need to take the [Self::condition_threshold_sf] into", + "account." + ], + "type": "u8" + }, + { + "name": "opportunity_type", + "docs": [ + "Serialized [OpportunityType].", + "", + "Example: a value of `0` here denotes `DeleverageSingleDebtAmount` opportunity. Of course, to", + "interpret this opportunity, we also need to take the [Self::opportunity_parameter_sf] into", + "account." + ], + "type": "u8" + }, + { + "name": "padding1", + "docs": [ + "Internal padding.", + "The fields above take up 2+2+1+1 bytes = 48 bits, which means we need 80 bits = 10 bytes to", + "align with `u128`s." + ], + "type": { + "array": ["u8", 10] + } + }, + { + "name": "padding2", + "docs": [ + "End padding.", + "The total size of a single instance is 8*u128 = 128 bytes." + ], + "type": { + "array": ["u128", 5] + } + } + ] + } + }, + { + "name": "ObligationOrder", + "serialization": "bytemuck", + "repr": { + "kind": "c", + "packed": true + }, + "docs": ["A single obligation order.", "See [Obligation::orders]."], + "type": { + "kind": "struct", + "fields": [ + { + "name": "condition_threshold_sf", + "docs": [ + "A threshold value used by the condition (scaled [Fraction]).", + "The exact meaning depends on the specific [Self::condition_type].", + "", + "Examples:", + "- when `condition_type == 2 (UserLtvBelow)`:", + "then a value of `0.455` here means that the order is active only when the obligation's", + "user LTV is less than `0.455` (i.e. < 45.5%).", + "- when `condition_type == 3 (DebtCollPriceRatioAbove)`:", + "assuming the obligation uses BTC collateral for SOL debt, then a value of `491.3` here", + "means that the order is active only when the BTC-SOL price is greater than `491.3` (i.e.", + "> 491.3 SOL per BTC)." + ], + "type": "u128" + }, + { + "name": "opportunity_parameter_sf", + "docs": [ + "A configuration parameter used by the opportunity (scaled [Fraction]).", + "The exact meaning depends on the specific [Self::opportunity_type].", + "", + "Examples:", + "- when `opportunity_type == 0 (DeleverageSingleDebtAmount)`:", + "Assuming the obligation uses BTC collateral for SOL debt, then a value of `1_234_000_000`", + "here means that a liquidator may repay up to 1234000000 lamports (i.e. 1.234 SOL) on this", + "obligation.", + "Note: the special value of [Fraction::MAX] is *not* allowed in this case.", + "- when `opportunity_type == 1 (DeleverageAllDebtAmount)`:", + "The only allowed value in this case is [Fraction::MAX] (to emphasize that *all* debt", + "should be repaid)." + ], + "type": "u128" + }, + { + "name": "min_execution_bonus_bps", + "docs": [ + "A *minimum* additional fraction of collateral transferred to the liquidator, in bps.", + "", + "The minimum bonus is applied exactly when the [Self::condition_threshold_sf] is met, and", + "grows linearly towards the [Self::max_execution_bonus_bps].", + "", + "Example: a value of `50` here means 50bps == 0.5% bonus for an \"LTV > 65%\" order, when", + "executed precisely at the moment LTV exceeds 65%." + ], + "type": "u16" + }, + { + "name": "max_execution_bonus_bps", + "docs": [ + "A *maximum* additional fraction of collateral transferred to the liquidator, in bps.", + "", + "The maximum bonus is applied at the relevant \"extreme\" state of the obligation, i.e.:", + "- for a stop-loss condition, it is a point at which the obligation becomes liquidatable;", + "- for a take-profit condition, it is a point at which obligation has 0% LTV.", + "", + "In non-extreme states, the actual bonus value is interpolated linearly, starting from", + "[Self::min_execution_bonus_bps] (at the point specified by the order's condition).", + "", + "Example: a value of `300` here means 300bps == 3.0% bonus for a \"debt/coll price > 140\"", + "order, when executed at a higher price = 200, at which the obligation's LTV happens to", + "be equal to its liquidation LTV." + ], + "type": "u16" + }, + { + "name": "condition_type", + "docs": [ + "Serialized [ConditionType].", + "The entire order is void when this is zeroed (i.e. representing [ConditionType::Never]).", + "", + "Example: a value of `2` here denotes `UserLtvBelow` condition type. Of course, to", + "interpret this condition, we also need to take the [Self::condition_threshold_sf] into", + "account." + ], + "type": "u8" + }, + { + "name": "opportunity_type", + "docs": [ + "Serialized [OpportunityType].", + "", + "Example: a value of `0` here denotes `DeleverageSingleDebtAmount` opportunity. Of course, to", + "interpret this opportunity, we also need to take the [Self::opportunity_parameter_sf] into", + "account." + ], + "type": "u8" + }, + { + "name": "padding1", + "docs": [ + "Internal padding.", + "The fields above take up 2+2+1+1 bytes = 48 bits, which means we need 80 bits = 10 bytes to", + "align with `u128`s." + ], + "type": { + "array": ["u8", 10] + } + }, + { + "name": "padding2", + "docs": [ + "End padding.", + "The total size of a single instance is 8*u128 = 128 bytes." + ], + "type": { + "array": ["u128", 5] + } + } + ] + } + }, { "name": "AssetTier", "type": { @@ -3594,7 +3967,8 @@ "name": "BigFractionBytes", "serialization": "bytemuck", "repr": { - "kind": "c" + "kind": "c", + "packed": true }, "type": { "kind": "struct", @@ -3616,6 +3990,7 @@ }, { "name": "FeeCalculation", + "docs": ["Calculate fees exlusive or inclusive of an amount"], "type": { "kind": "enum", "variants": [ @@ -3635,19 +4010,23 @@ "kind": "c", "packed": true }, + "docs": ["Reserve collateral"], "type": { "kind": "struct", "fields": [ { "name": "mint_pubkey", + "docs": ["Reserve collateral mint address"], "type": "pubkey" }, { "name": "mint_total_supply", + "docs": ["Reserve collateral mint supply, used for exchange rate"], "type": "u64" }, { "name": "supply_vault", + "docs": ["Reserve collateral supply address"], "type": "pubkey" }, { @@ -3672,71 +4051,118 @@ "kind": "c", "packed": true }, + "docs": ["Reserve configuration values"], "type": { "kind": "struct", "fields": [ { "name": "status", + "docs": ["Status of the reserve Active/Obsolete/Hidden"], "type": "u8" }, { "name": "asset_tier", + "docs": [ + "Asset tier -> 0 - regular (collateral & debt), 1 - isolated collateral, 2 - isolated debt" + ], "type": "u8" }, { "name": "host_fixed_interest_rate_bps", + "docs": ["Flat rate that goes to the host"], "type": "u16" }, { "name": "reserved2", + "docs": [ + "[DEPRECATED] Space that used to hold 2 fields:", + "- Boost for side (debt or collateral)", + "- Reward points multiplier per obligation type", + "Can be re-used after making sure all underlying production account data is zeroed." + ], "type": { - "array": ["u8", 2] + "array": ["u8", 9] } }, { - "name": "reserved3", - "type": { - "array": ["u8", 8] - } + "name": "protocol_order_execution_fee_pct", + "docs": [ + "Cut of the order execution bonus that the protocol receives, as a percentage" + ], + "type": "u8" }, { "name": "protocol_take_rate_pct", + "docs": [ + "Protocol take rate is the amount borrowed interest protocol receives, as a percentage" + ], "type": "u8" }, { "name": "protocol_liquidation_fee_pct", + "docs": [ + "Cut of the liquidation bonus that the protocol receives, as a percentage" + ], "type": "u8" }, { "name": "loan_to_value_pct", + "docs": [ + "Target ratio of the value of borrows to deposits, as a percentage", + "0 if use as collateral is disabled" + ], "type": "u8" }, { "name": "liquidation_threshold_pct", + "docs": [ + "Loan to value ratio at which an obligation can be liquidated, as percentage" + ], "type": "u8" }, { "name": "min_liquidation_bonus_bps", + "docs": [ + "Minimum bonus a liquidator receives when repaying part of an unhealthy obligation, as bps" + ], "type": "u16" }, { "name": "max_liquidation_bonus_bps", + "docs": [ + "Maximum bonus a liquidator receives when repaying part of an unhealthy obligation, as bps" + ], "type": "u16" }, { "name": "bad_debt_liquidation_bonus_bps", + "docs": [ + "Bad debt liquidation bonus for an undercollateralized obligation, as bps" + ], "type": "u16" }, { "name": "deleveraging_margin_call_period_secs", + "docs": [ + "Time in seconds that must pass before redemptions are enabled after the deposit limit is", + "crossed.", + "Only relevant when `autodeleverage_enabled == 1`, and must not be 0 in such case." + ], "type": "u64" }, { "name": "deleveraging_threshold_decrease_bps_per_day", + "docs": [ + "The rate at which the deleveraging threshold decreases, in bps per day.", + "Only relevant when `autodeleverage_enabled == 1`, and must not be 0 in such case." + ], "type": "u64" }, { "name": "fees", + "docs": [ + "Program owner fees assessed, separate from gains due to interest accrual" + ], "type": { "defined": { "name": "ReserveFees" @@ -3745,6 +4171,7 @@ }, { "name": "borrow_rate_curve", + "docs": ["Borrow rate curve based on utilization"], "type": { "defined": { "name": "BorrowRateCurve" @@ -3753,18 +4180,26 @@ }, { "name": "borrow_factor_pct", + "docs": ["Borrow factor in percentage - used for risk adjustment"], "type": "u64" }, { "name": "deposit_limit", + "docs": [ + "Maximum deposit limit of liquidity in native units, u64::MAX for inf" + ], "type": "u64" }, { "name": "borrow_limit", + "docs": [ + "Maximum amount borrowed, u64::MAX for inf, 0 to disable borrows (protected deposits)" + ], "type": "u64" }, { "name": "token_info", + "docs": ["Token id from TokenInfos struct"], "type": { "defined": { "name": "TokenInfo" @@ -3773,6 +4208,7 @@ }, { "name": "deposit_withdrawal_cap", + "docs": ["Deposit withdrawal caps - deposit & redeem"], "type": { "defined": { "name": "WithdrawalCaps" @@ -3781,6 +4217,7 @@ }, { "name": "debt_withdrawal_cap", + "docs": ["Debt withdrawal caps - borrow & repay"], "type": { "defined": { "name": "WithdrawalCaps" @@ -3799,10 +4236,20 @@ }, { "name": "utilization_limit_block_borrowing_above_pct", + "docs": [ + "Utilization (in percentage) above which borrowing is blocked. 0 to disable." + ], "type": "u8" }, { "name": "autodeleverage_enabled", + "docs": [ + "Whether this reserve should be subject to auto-deleveraging after deposit or borrow limit is", + "crossed.", + "Besides this flag, the lending market's flag also needs to be enabled (logical `AND`).", + "**NOTE:** the manual \"target LTV\" deleveraging (enabled by the risk council for individual", + "obligations) is NOT affected by this flag." + ], "type": "u8" }, { @@ -3813,16 +4260,31 @@ }, { "name": "borrow_limit_outside_elevation_group", + "docs": [ + "Maximum amount liquidity of this reserve borrowed outside all elevation groups", + "- u64::MAX for inf", + "- 0 to disable borrows outside elevation groups" + ], "type": "u64" }, { "name": "borrow_limit_against_this_collateral_in_elevation_group", + "docs": [ + "Defines the maximum amount (in lamports of elevation group debt asset)", + "that can be borrowed when this reserve is used as collateral.", + "- u64::MAX for inf", + "- 0 to disable borrows in this elevation group (expected value for the debt asset)" + ], "type": { "array": ["u64", 32] } }, { "name": "deleveraging_bonus_increase_bps_per_day", + "docs": [ + "The rate at which the deleveraging-related liquidation bonus increases, in bps per day.", + "Only relevant when `autodeleverage_enabled == 1`, and must not be 0 in such case." + ], "type": "u64" } ] @@ -3846,21 +4308,42 @@ "name": "ReserveFees", "serialization": "bytemuck", "repr": { - "kind": "c" + "kind": "c", + "packed": true }, + "docs": [ + "Additional fee information on a reserve", + "", + "These exist separately from interest accrual fees, and are specifically for the program owner", + "and referral fee. The fees are paid out as a percentage of liquidity token amounts during", + "repayments and liquidations." + ], "type": { "kind": "struct", "fields": [ { "name": "borrow_fee_sf", + "docs": [ + "Fee assessed on `BorrowObligationLiquidity`, as scaled fraction (60 bits fractional part)", + "Must be between `0` and `2^60`, such that `2^60 = 1`. A few examples for", + "clarity:", + "1% = (1 << 60) / 100 = 11529215046068470", + "0.01% (1 basis point) = 115292150460685", + "0.00001% (Aave borrow fee) = 115292150461" + ], "type": "u64" }, { "name": "flash_loan_fee_sf", + "docs": [ + "Fee for flash loan, expressed as scaled fraction.", + "0.3% (Aave flash loan fee) = 0.003 * 2^60 = 3458764513820541" + ], "type": "u64" }, { "name": "padding", + "docs": ["Used for allignment"], "type": { "array": ["u8", 8] } @@ -3875,51 +4358,73 @@ "kind": "c", "packed": true }, + "docs": ["Reserve liquidity"], "type": { "kind": "struct", "fields": [ { "name": "mint_pubkey", + "docs": ["Reserve liquidity mint address"], "type": "pubkey" }, { "name": "supply_vault", + "docs": ["Reserve liquidity supply address"], "type": "pubkey" }, { "name": "fee_vault", + "docs": ["Reserve liquidity fee collection address"], "type": "pubkey" }, { "name": "available_amount", + "docs": ["Reserve liquidity available"], "type": "u64" }, { "name": "borrowed_amount_sf", + "docs": ["Reserve liquidity borrowed (scaled fraction)"], "type": "u128" }, { "name": "market_price_sf", + "docs": [ + "Reserve liquidity market price in quote currency (scaled fraction)" + ], "type": "u128" }, { "name": "market_price_last_updated_ts", + "docs": ["Unix timestamp of the market price (from the oracle)"], "type": "u64" }, { "name": "mint_decimals", + "docs": ["Reserve liquidity mint decimals"], "type": "u64" }, { "name": "deposit_limit_crossed_timestamp", + "docs": [ + "Timestamp when the last refresh reserve detected that the liquidity amount is above the deposit cap. When this threshold is crossed, then redemptions (auto-deleverage) are enabled.", + "If the threshold is not crossed, then the timestamp is set to 0" + ], "type": "u64" }, { "name": "borrow_limit_crossed_timestamp", + "docs": [ + "Timestamp when the last refresh reserve detected that the borrowed amount is above the borrow cap. When this threshold is crossed, then redemptions (auto-deleverage) are enabled.", + "If the threshold is not crossed, then the timestamp is set to 0" + ], "type": "u64" }, { "name": "cumulative_borrow_rate_bsf", + "docs": [ + "Reserve liquidity cumulative borrow rate (scaled fraction)" + ], "type": { "defined": { "name": "BigFractionBytes" @@ -3928,22 +4433,31 @@ }, { "name": "accumulated_protocol_fees_sf", + "docs": ["Reserve cumulative protocol fees (scaled fraction)"], "type": "u128" }, { "name": "accumulated_referrer_fees_sf", + "docs": ["Reserve cumulative referrer fees (scaled fraction)"], "type": "u128" }, { "name": "pending_referrer_fees_sf", + "docs": [ + "Reserve pending referrer fees, to be claimed in refresh_obligation by referrer or protocol (scaled fraction)" + ], "type": "u128" }, { "name": "absolute_referral_rate_sf", + "docs": [ + "Reserve referrer fee absolute rate calculated at each refresh_reserve operation (scaled fraction)" + ], "type": "u128" }, { "name": "token_program", + "docs": ["Token program of the liquidity mint"], "type": "pubkey" }, { @@ -3982,8 +4496,10 @@ "name": "WithdrawalCaps", "serialization": "bytemuck", "repr": { - "kind": "c" + "kind": "c", + "packed": true }, + "docs": ["Reserve Withdrawal Caps State"], "type": { "kind": "struct", "fields": [ @@ -4010,21 +4526,25 @@ "name": "PriceHeuristic", "serialization": "bytemuck", "repr": { - "kind": "c" + "kind": "c", + "packed": true }, "type": { "kind": "struct", "fields": [ { "name": "lower", + "docs": ["Lower value of acceptable price"], "type": "u64" }, { "name": "upper", + "docs": ["Upper value of acceptable price"], "type": "u64" }, { "name": "exp", + "docs": ["Number of decimals of the previously defined values"], "type": "u64" } ] @@ -4034,13 +4554,17 @@ "name": "PythConfiguration", "serialization": "bytemuck", "repr": { - "kind": "c" + "kind": "c", + "packed": true }, "type": { "kind": "struct", "fields": [ { "name": "price", + "docs": [ + "Pubkey of the base price feed (disabled if `null` or `default`)" + ], "type": "pubkey" } ] @@ -4050,23 +4574,31 @@ "name": "ScopeConfiguration", "serialization": "bytemuck", "repr": { - "kind": "c" + "kind": "c", + "packed": true }, "type": { "kind": "struct", "fields": [ { "name": "price_feed", + "docs": [ + "Pubkey of the scope price feed (disabled if `null` or `default`)" + ], "type": "pubkey" }, { "name": "price_chain", + "docs": [ + "This is the scope_id price chain that results in a price for the token" + ], "type": { "array": ["u16", 4] } }, { "name": "twap_chain", + "docs": ["This is the scope_id price chain for the twap"], "type": { "array": ["u16", 4] } @@ -4078,13 +4610,17 @@ "name": "SwitchboardConfiguration", "serialization": "bytemuck", "repr": { - "kind": "c" + "kind": "c", + "packed": true }, "type": { "kind": "struct", "fields": [ { "name": "price_aggregator", + "docs": [ + "Pubkey of the base price feed (disabled if `null` or `default`)" + ], "type": "pubkey" }, { @@ -4098,19 +4634,22 @@ "name": "TokenInfo", "serialization": "bytemuck", "repr": { - "kind": "c" + "kind": "c", + "packed": true }, "type": { "kind": "struct", "fields": [ { "name": "name", + "docs": ["UTF-8 encoded name of the token (null-terminated)"], "type": { "array": ["u8", 32] } }, { "name": "heuristic", + "docs": ["Heuristics limits of acceptable price"], "type": { "defined": { "name": "PriceHeuristic" @@ -4119,6 +4658,7 @@ }, { "name": "max_twap_divergence_bps", + "docs": ["Max divergence between twap and price in bps"], "type": "u64" }, { @@ -4131,6 +4671,7 @@ }, { "name": "scope_configuration", + "docs": ["Scope price configuration"], "type": { "defined": { "name": "ScopeConfiguration" @@ -4139,6 +4680,7 @@ }, { "name": "switchboard_configuration", + "docs": ["Switchboard configuration"], "type": { "defined": { "name": "SwitchboardConfiguration" @@ -4147,6 +4689,7 @@ }, { "name": "pyth_configuration", + "docs": ["Pyth configuration"], "type": { "defined": { "name": "PythConfiguration" @@ -4176,7 +4719,8 @@ "name": "BorrowRateCurve", "serialization": "bytemuck", "repr": { - "kind": "c" + "kind": "c", + "packed": true }, "type": { "kind": "struct", @@ -4201,7 +4745,8 @@ "name": "CurvePoint", "serialization": "bytemuck", "repr": { - "kind": "c" + "kind": "c", + "packed": true }, "type": { "kind": "struct", @@ -4241,6 +4786,7 @@ }, { "name": "is_farm_delegated", + "docs": ["Indicate if this user state is part of a delegated farm"], "type": "u8" }, { @@ -4251,12 +4797,17 @@ }, { "name": "rewards_tally_scaled", + "docs": [ + "Rewards tally used for computation of gained rewards", + "(scaled from `Decimal` representation)." + ], "type": { "array": ["u128", 10] } }, { "name": "rewards_issued_unclaimed", + "docs": ["Number of reward tokens ready for claim"], "type": { "array": ["u64", 10] } @@ -4269,30 +4820,51 @@ }, { "name": "active_stake_scaled", + "docs": [ + "User stake deposited and usable, generating rewards and fees.", + "(scaled from `Decimal` representation)." + ], "type": "u128" }, { "name": "pending_deposit_stake_scaled", + "docs": [ + "User stake deposited but not usable and not generating rewards yet.", + "(scaled from `Decimal` representation)." + ], "type": "u128" }, { "name": "pending_deposit_stake_ts", + "docs": [ + "After this timestamp, pending user stake can be moved to user stake", + "Initialized to now() + delayed user stake period" + ], "type": "u64" }, { "name": "pending_withdrawal_unstake_scaled", + "docs": [ + "User deposits unstaked, pending for withdrawal, not usable and not generating rewards.", + "(scaled from `Decimal` representation)." + ], "type": "u128" }, { "name": "pending_withdrawal_unstake_ts", + "docs": ["After this timestamp, user can withdraw their deposit."], "type": "u64" }, { "name": "bump", + "docs": ["User bump used for account address validation"], "type": "u64" }, { "name": "delegatee", + "docs": [ + "Delegatee used for initialisation - useful to check against" + ], "type": "pubkey" }, { @@ -4308,6 +4880,45 @@ ] } }, + { + "name": "LendingGlobalConfig", + "serialization": "bytemuck", + "repr": { + "kind": "c", + "packed": true + }, + "type": { + "kind": "struct", + "fields": [ + { + "name": "global_admin", + "docs": ["Global admin of the program"], + "type": "pubkey" + }, + { + "name": "pending_admin", + "docs": [ + "Pending admin must sign a specific transaction to become the global admin" + ], + "type": "pubkey" + }, + { + "name": "fee_collector", + "docs": [ + "Fee collector is the only allowed owner of token accounts receiving protocol fees" + ], + "type": "pubkey" + }, + { + "name": "padding", + "docs": ["Padding to make the struct size 1024 bytes"], + "type": { + "array": ["u8", 928] + } + } + ] + } + }, { "name": "LendingMarket", "serialization": "bytemuck", @@ -4320,28 +4931,41 @@ "fields": [ { "name": "version", + "docs": ["Version of lending market"], "type": "u64" }, { "name": "bump_seed", + "docs": ["Bump seed for derived authority address"], "type": "u64" }, { "name": "lending_market_owner", + "docs": ["Owner authority which can add new reserves"], "type": "pubkey" }, { "name": "lending_market_owner_cached", + "docs": [ + "Temporary cache of the lending market owner, used in update_lending_market_owner" + ], "type": "pubkey" }, { "name": "quote_currency", + "docs": [ + "Currency market prices are quoted in", + "e.g. \"USD\" null padded (`*b\"USD\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\"`) or a SPL token mint pubkey" + ], "type": { "array": ["u8", 32] } }, { "name": "referral_fee_bps", + "docs": [ + "Referral fee for the lending market, as bps out of the total protocol fee" + ], "type": "u16" }, { @@ -4350,6 +4974,12 @@ }, { "name": "autodeleverage_enabled", + "docs": [ + "Whether the obligations on this market should be subject to auto-deleveraging after deposit", + "or borrow limit is crossed.", + "Besides this flag, the particular reserve's flag also needs to be enabled (logical `AND`).", + "**NOTE:** this also affects the individual \"target LTV\" deleveraging." + ], "type": "u8" }, { @@ -4358,51 +4988,81 @@ }, { "name": "price_refresh_trigger_to_max_age_pct", + "docs": [ + "Refresh price from oracle only if it's older than this percentage of the price max age.", + "e.g. if the max age is set to 100s and this is set to 80%, the price will be refreshed if it's older than 80s.", + "Price is always refreshed if this set to 0." + ], "type": "u8" }, { "name": "liquidation_max_debt_close_factor_pct", + "docs": [ + "Percentage of the total borrowed value in an obligation available for liquidation" + ], "type": "u8" }, { "name": "insolvency_risk_unhealthy_ltv_pct", + "docs": [ + "Minimum acceptable unhealthy LTV before max_debt_close_factor_pct becomes 100%" + ], "type": "u8" }, { "name": "min_full_liquidation_value_threshold", + "docs": [ + "Minimum liquidation value threshold triggering full liquidation for an obligation" + ], "type": "u64" }, { "name": "max_liquidatable_debt_market_value_at_once", + "docs": ["Max allowed liquidation value in one ix call"], "type": "u64" }, { "name": "reserved0", + "docs": [ + "[DEPRECATED] Global maximum unhealthy borrow value allowed for any obligation" + ], "type": { "array": ["u8", 8] } }, { "name": "global_allowed_borrow_value", + "docs": [ + "Global maximum allowed borrow value allowed for any obligation" + ], "type": "u64" }, { "name": "risk_council", + "docs": [ + "The address of the risk council, in charge of making parameter and risk decisions on behalf of the protocol" + ], "type": "pubkey" }, { "name": "reserved1", + "docs": [ + "[DEPRECATED] Reward points multiplier per obligation type" + ], "type": { "array": ["u8", 8] } }, { "name": "elevation_groups", + "docs": [ + "Elevation groups are used to group together reserves that have the same risk parameters and can bump the ltv and liquidation threshold" + ], "type": { "array": [ { "defined": { - "name": "ElevationGroupLendingMarket" + "name": "ElevationGroupPod" } }, 32 @@ -4417,34 +5077,130 @@ }, { "name": "min_net_value_in_obligation_sf", + "docs": [ + "Min net value accepted to be found in a position after any lending action in an obligation (scaled by quote currency decimals)" + ], "type": "u128" }, { "name": "min_value_skip_liquidation_ltv_checks", + "docs": [ + "Minimum value to enforce smallest ltv priority checks on the collateral reserves on liquidation" + ], "type": "u64" }, { "name": "name", + "docs": ["Market name, zero-padded."], "type": { "array": ["u8", 32] } }, { "name": "min_value_skip_liquidation_bf_checks", + "docs": [ + "Minimum value to enforce highest borrow factor priority checks on the debt reserves on liquidation" + ], "type": "u64" }, { "name": "individual_autodeleverage_margin_call_period_secs", + "docs": [ + "Time (in seconds) that must pass before liquidation is allowed on an obligation that has", + "been individually marked for auto-deleveraging (by the risk council)." + ], "type": "u64" }, { "name": "min_initial_deposit_amount", + "docs": [ + "Minimum amount of deposit at creation of a reserve to prevent artificial inflation", + "Note: this amount cannot be recovered, the ctoken associated are never minted" + ], "type": "u64" }, + { + "name": "obligation_order_execution_enabled", + "docs": [ + "Whether the obligation orders should be evaluated during liquidations." + ], + "type": "u8" + }, + { + "name": "immutable", + "docs": ["Whether the lending market is set as immutable."], + "type": "u8" + }, + { + "name": "obligation_order_creation_enabled", + "docs": [ + "Whether new obligation orders can be created.", + "Note: updating or cancelling existing orders is *not* affected by this flag." + ], + "type": "u8" + }, + { + "name": "padding2", + "type": { + "array": ["u8", 5] + } + }, { "name": "padding1", "type": { - "array": ["u64", 170] + "array": ["u64", 169] + } + } + ] + } + }, + { + "name": "ElevationGroupPod", + "serialization": "bytemuck", + "repr": { + "kind": "c", + "packed": true + }, + "type": { + "kind": "struct", + "fields": [ + { + "name": "max_liquidation_bonus_bps", + "type": "u16" + }, + { + "name": "id", + "type": "u8" + }, + { + "name": "ltv_pct", + "type": "u8" + }, + { + "name": "liquidation_threshold_pct", + "type": "u8" + }, + { + "name": "allow_new_loans", + "type": "u8" + }, + { + "name": "max_reserves_as_collateral", + "type": "u8" + }, + { + "name": "padding0", + "type": "u8" + }, + { + "name": "debt_reserve", + "docs": ["Mandatory debt reserve for this elevation group"], + "type": "pubkey" + }, + { + "name": "padding1", + "type": { + "array": ["u64", 4] } } ] @@ -4457,15 +5213,20 @@ "kind": "c", "packed": true }, + "docs": ["Lending market obligation state"], "type": { "kind": "struct", "fields": [ { "name": "tag", + "docs": ["Version of the struct"], "type": "u64" }, { "name": "last_update", + "docs": [ + "Last update to collateral, liquidity, or their market values" + ], "type": { "defined": { "name": "LastUpdate" @@ -4474,14 +5235,19 @@ }, { "name": "lending_market", + "docs": ["Lending market address"], "type": "pubkey" }, { "name": "owner", + "docs": ["Owner authority which can borrow liquidity"], "type": "pubkey" }, { "name": "deposits", + "docs": [ + "Deposited collateral for the obligation, unique by deposit reserve address" + ], "type": { "array": [ { @@ -4495,14 +5261,21 @@ }, { "name": "lowest_reserve_deposit_liquidation_ltv", + "docs": [ + "Worst LTV for the collaterals backing the loan, represented as a percentage" + ], "type": "u64" }, { "name": "deposited_value_sf", + "docs": ["Market value of deposits (scaled fraction)"], "type": "u128" }, { "name": "borrows", + "docs": [ + "Borrowed liquidity for the obligation, unique by borrow reserve address" + ], "type": { "array": [ { @@ -4516,64 +5289,101 @@ }, { "name": "borrow_factor_adjusted_debt_value_sf", + "docs": [ + "Risk adjusted market value of borrows/debt (sum of price * borrowed_amount * borrow_factor) (scaled fraction)" + ], "type": "u128" }, { "name": "borrowed_assets_market_value_sf", + "docs": [ + "Market value of borrows - used for max_liquidatable_borrowed_amount (scaled fraction)" + ], "type": "u128" }, { "name": "allowed_borrow_value_sf", + "docs": [ + "The maximum borrow value at the weighted average loan to value ratio (scaled fraction)" + ], "type": "u128" }, { "name": "unhealthy_borrow_value_sf", + "docs": [ + "The dangerous borrow value at the weighted average liquidation threshold (scaled fraction)" + ], "type": "u128" }, { "name": "deposits_asset_tiers", + "docs": ["The asset tier of the deposits"], "type": { "array": ["u8", 8] } }, { "name": "borrows_asset_tiers", + "docs": ["The asset tier of the borrows"], "type": { "array": ["u8", 5] } }, { "name": "elevation_group", + "docs": ["The elevation group id the obligation opted into."], "type": "u8" }, { - "name": "num_of_obsolete_reserves", + "name": "num_of_obsolete_deposit_reserves", + "docs": [ + "The number of obsolete reserves the obligation has a deposit in" + ], "type": "u8" }, { "name": "has_debt", + "docs": [ + "Marked = 1 if borrows array is not empty, 0 = borrows empty" + ], "type": "u8" }, { "name": "referrer", + "docs": ["Wallet address of the referrer"], "type": "pubkey" }, { "name": "borrowing_disabled", + "docs": ["Marked = 1 if borrowing disabled, 0 = borrowing enabled"], "type": "u8" }, { "name": "autodeleverage_target_ltv_pct", + "docs": [ + "A target LTV set by the risk council when marking this obligation for deleveraging.", + "Only effective when `deleveraging_margin_call_started_slot != 0`." + ], "type": "u8" }, { "name": "lowest_reserve_deposit_max_ltv_pct", + "docs": [ + "The lowest max LTV found amongst the collateral deposits" + ], + "type": "u8" + }, + { + "name": "num_of_obsolete_borrow_reserves", + "docs": [ + "The number of obsolete reserves the obligation has a borrow in" + ], "type": "u8" }, { "name": "reserved", "type": { - "array": ["u8", 5] + "array": ["u8", 4] } }, { @@ -4582,12 +5392,33 @@ }, { "name": "autodeleverage_margin_call_started_timestamp", + "docs": [ + "A timestamp at which the risk council most-recently marked this obligation for deleveraging.", + "Zero if not currently subject to deleveraging." + ], "type": "u64" }, + { + "name": "orders", + "docs": [ + "Owner-defined, liquidator-executed orders applicable to this obligation.", + "Typical use-cases would be a stop-loss and a take-profit (possibly co-existing)." + ], + "type": { + "array": [ + { + "defined": { + "name": "ObligationOrder" + } + }, + 2 + ] + } + }, { "name": "padding3", "type": { - "array": ["u64", 125] + "array": ["u64", 93] } } ] @@ -4595,6 +5426,11 @@ }, { "name": "ReferrerState", + "serialization": "bytemuck", + "repr": { + "kind": "c", + "packed": true + }, "type": { "kind": "struct", "fields": [ @@ -4611,27 +5447,44 @@ }, { "name": "ReferrerTokenState", + "serialization": "bytemuck", + "repr": { + "kind": "c", + "packed": true + }, + "docs": [ + "Referrer account -> each owner can have multiple accounts for specific reserves" + ], "type": { "kind": "struct", "fields": [ { "name": "referrer", + "docs": ["Pubkey of the referrer/owner"], "type": "pubkey" }, { "name": "mint", + "docs": ["Token mint for the account"], "type": "pubkey" }, { "name": "amount_unclaimed_sf", + "docs": [ + "Amount that has been accumulated and not claimed yet -> available to claim (scaled fraction)" + ], "type": "u128" }, { "name": "amount_cumulative_sf", + "docs": [ + "Amount that has been accumulated in total -> both already claimed and unclaimed (scaled fraction)" + ], "type": "u128" }, { "name": "bump", + "docs": ["Referrer token state bump, used for address validation"], "type": "u64" }, { @@ -4661,23 +5514,34 @@ }, { "name": "UserMetadata", + "docs": [ + "Referrer account -> each owner can have multiple accounts for specific reserves" + ], "type": { "kind": "struct", "fields": [ { "name": "referrer", + "docs": [ + "Pubkey of the referrer/owner - pubkey::default if no referrer" + ], "type": "pubkey" }, { "name": "bump", + "docs": ["Bump used for validation of account address"], "type": "u64" }, { "name": "user_lookup_table", + "docs": [ + "User lookup table - used to store all user accounts - atas for each reserve mint, each obligation PDA, UserMetadata itself and all referrer_token_states if there is a referrer" + ], "type": "pubkey" }, { "name": "owner", + "docs": ["User metadata account owner"], "type": "pubkey" }, { @@ -4707,10 +5571,12 @@ "fields": [ { "name": "version", + "docs": ["Version of the reserve"], "type": "u64" }, { "name": "last_update", + "docs": ["Last slot when supply and rates updated"], "type": { "defined": { "name": "LastUpdate" @@ -4719,6 +5585,7 @@ }, { "name": "lending_market", + "docs": ["Lending market address"], "type": "pubkey" }, { @@ -4731,6 +5598,7 @@ }, { "name": "liquidity", + "docs": ["Reserve liquidity"], "type": { "defined": { "name": "ReserveLiquidity" @@ -4745,6 +5613,7 @@ }, { "name": "collateral", + "docs": ["Reserve collateral"], "type": { "defined": { "name": "ReserveCollateral" @@ -4759,6 +5628,7 @@ }, { "name": "config", + "docs": ["Reserve configuration values"], "type": { "defined": { "name": "ReserveConfig" @@ -4777,6 +5647,10 @@ }, { "name": "borrowed_amounts_against_this_reserve_in_elevation_groups", + "docs": [ + "Amount of token borrowed in lamport of debt asset in the given", + "elevation group when this reserve is part of the collaterals." + ], "type": { "array": ["u64", 32] } diff --git a/clients/kamino-lending/src/generated/accounts/globalConfig.ts b/clients/kamino-lending/src/generated/accounts/farmsGlobalConfig.ts similarity index 62% rename from clients/kamino-lending/src/generated/accounts/globalConfig.ts rename to clients/kamino-lending/src/generated/accounts/farmsGlobalConfig.ts index f72919f1..1f8da517 100644 --- a/clients/kamino-lending/src/generated/accounts/globalConfig.ts +++ b/clients/kamino-lending/src/generated/accounts/farmsGlobalConfig.ts @@ -43,17 +43,16 @@ import { transformEncoder, } from "@solana/kit"; -export const GLOBAL_CONFIG_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ - 149, 8, 156, 202, 160, 252, 176, 217, -]); +export const FARMS_GLOBAL_CONFIG_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([149, 8, 156, 202, 160, 252, 176, 217]); -export function getGlobalConfigDiscriminatorBytes(): ReadonlyUint8Array { +export function getFarmsGlobalConfigDiscriminatorBytes(): ReadonlyUint8Array { return fixEncoderSize(getBytesEncoder(), 8).encode( - GLOBAL_CONFIG_DISCRIMINATOR, + FARMS_GLOBAL_CONFIG_DISCRIMINATOR, ); } -export interface GlobalConfig { +export interface FarmsGlobalConfig { discriminator: ReadonlyUint8Array; globalAdmin: Address; treasuryFeeBps: bigint; @@ -63,7 +62,7 @@ export interface GlobalConfig { padding1: bigint[]; } -export interface GlobalConfigArgs { +export interface FarmsGlobalConfigArgs { globalAdmin: Address; treasuryFeeBps: number | bigint; treasuryVaultsAuthority: Address; @@ -72,7 +71,7 @@ export interface GlobalConfigArgs { padding1: (number | bigint)[]; } -export function getGlobalConfigEncoder(): FixedSizeEncoder { +export function getFarmsGlobalConfigEncoder(): FixedSizeEncoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], @@ -83,11 +82,11 @@ export function getGlobalConfigEncoder(): FixedSizeEncoder { ["pendingGlobalAdmin", getAddressEncoder()], ["padding1", getArrayEncoder(getU128Encoder(), { size: 126 })], ]), - (value) => ({ ...value, discriminator: GLOBAL_CONFIG_DISCRIMINATOR }), + (value) => ({ ...value, discriminator: FARMS_GLOBAL_CONFIG_DISCRIMINATOR }), ); } -export function getGlobalConfigDecoder(): FixedSizeDecoder { +export function getFarmsGlobalConfigDecoder(): FixedSizeDecoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], ["globalAdmin", getAddressDecoder()], @@ -99,62 +98,75 @@ export function getGlobalConfigDecoder(): FixedSizeDecoder { ]); } -export function getGlobalConfigCodec(): FixedSizeCodec< - GlobalConfigArgs, - GlobalConfig +export function getFarmsGlobalConfigCodec(): FixedSizeCodec< + FarmsGlobalConfigArgs, + FarmsGlobalConfig > { - return combineCodec(getGlobalConfigEncoder(), getGlobalConfigDecoder()); + return combineCodec( + getFarmsGlobalConfigEncoder(), + getFarmsGlobalConfigDecoder(), + ); } -export function decodeGlobalConfig( +export function decodeFarmsGlobalConfig( encodedAccount: EncodedAccount, -): Account; -export function decodeGlobalConfig( +): Account; +export function decodeFarmsGlobalConfig( encodedAccount: MaybeEncodedAccount, -): MaybeAccount; -export function decodeGlobalConfig( +): MaybeAccount; +export function decodeFarmsGlobalConfig( encodedAccount: EncodedAccount | MaybeEncodedAccount, -): Account | MaybeAccount { +): + | Account + | MaybeAccount { return decodeAccount( encodedAccount as MaybeEncodedAccount, - getGlobalConfigDecoder(), + getFarmsGlobalConfigDecoder(), ); } -export async function fetchGlobalConfig( +export async function fetchFarmsGlobalConfig( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, -): Promise> { - const maybeAccount = await fetchMaybeGlobalConfig(rpc, address, config); +): Promise> { + const maybeAccount = await fetchMaybeFarmsGlobalConfig(rpc, address, config); assertAccountExists(maybeAccount); return maybeAccount; } -export async function fetchMaybeGlobalConfig( +export async function fetchMaybeFarmsGlobalConfig< + TAddress extends string = string, +>( rpc: Parameters[0], address: Address, config?: FetchAccountConfig, -): Promise> { +): Promise> { const maybeAccount = await fetchEncodedAccount(rpc, address, config); - return decodeGlobalConfig(maybeAccount); + return decodeFarmsGlobalConfig(maybeAccount); } -export async function fetchAllGlobalConfig( +export async function fetchAllFarmsGlobalConfig( rpc: Parameters[0], addresses: Address[], config?: FetchAccountsConfig, -): Promise[]> { - const maybeAccounts = await fetchAllMaybeGlobalConfig(rpc, addresses, config); +): Promise[]> { + const maybeAccounts = await fetchAllMaybeFarmsGlobalConfig( + rpc, + addresses, + config, + ); assertAccountsExist(maybeAccounts); return maybeAccounts; } -export async function fetchAllMaybeGlobalConfig( +export async function fetchAllMaybeFarmsGlobalConfig( rpc: Parameters[0], addresses: Address[], config?: FetchAccountsConfig, -): Promise[]> { +): Promise[]> { const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); - return maybeAccounts.map((maybeAccount) => decodeGlobalConfig(maybeAccount)); + return maybeAccounts.map((maybeAccount) => + decodeFarmsGlobalConfig(maybeAccount), + ); } diff --git a/clients/kamino-lending/src/generated/accounts/farmsUserState.ts b/clients/kamino-lending/src/generated/accounts/farmsUserState.ts index e45ffc09..46508c89 100644 --- a/clients/kamino-lending/src/generated/accounts/farmsUserState.ts +++ b/clients/kamino-lending/src/generated/accounts/farmsUserState.ts @@ -19,6 +19,7 @@ import type { MaybeEncodedAccount, ReadonlyUint8Array, } from "@solana/kit"; +import type { FarmsUserStateSeeds } from "../pdas/index.js"; import { assertAccountExists, assertAccountsExist, @@ -44,6 +45,7 @@ import { getU128Encoder, transformEncoder, } from "@solana/kit"; +import { findFarmsUserStatePda } from "../pdas/index.js"; export const FARMS_USER_STATE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([72, 177, 85, 249, 76, 167, 186, 126]); @@ -264,3 +266,27 @@ export async function fetchAllMaybeFarmsUserState( decodeFarmsUserState(maybeAccount), ); } + +export async function fetchFarmsUserStateFromSeeds( + rpc: Parameters[0], + seeds: FarmsUserStateSeeds, + config: FetchAccountConfig & { programAddress?: Address } = {}, +): Promise> { + const maybeAccount = await fetchMaybeFarmsUserStateFromSeeds( + rpc, + seeds, + config, + ); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeFarmsUserStateFromSeeds( + rpc: Parameters[0], + seeds: FarmsUserStateSeeds, + config: FetchAccountConfig & { programAddress?: Address } = {}, +): Promise> { + const { programAddress, ...fetchConfig } = config; + const [address] = await findFarmsUserStatePda(seeds, { programAddress }); + return await fetchMaybeFarmsUserState(rpc, address, fetchConfig); +} diff --git a/clients/kamino-lending/src/generated/accounts/index.ts b/clients/kamino-lending/src/generated/accounts/index.ts index 0e6828fd..2f5e1d3d 100644 --- a/clients/kamino-lending/src/generated/accounts/index.ts +++ b/clients/kamino-lending/src/generated/accounts/index.ts @@ -7,8 +7,9 @@ */ export * from "./farmState.js"; +export * from "./farmsGlobalConfig.js"; export * from "./farmsUserState.js"; -export * from "./globalConfig.js"; +export * from "./lendingGlobalConfig.js"; export * from "./lendingMarket.js"; export * from "./obligation.js"; export * from "./oraclePrices.js"; diff --git a/clients/kamino-lending/src/generated/accounts/lendingGlobalConfig.ts b/clients/kamino-lending/src/generated/accounts/lendingGlobalConfig.ts new file mode 100644 index 00000000..5735fa20 --- /dev/null +++ b/clients/kamino-lending/src/generated/accounts/lendingGlobalConfig.ts @@ -0,0 +1,203 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Account, + Address, + EncodedAccount, + FetchAccountConfig, + FetchAccountsConfig, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + MaybeAccount, + MaybeEncodedAccount, + ReadonlyUint8Array, +} from "@solana/kit"; +import { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getArrayDecoder, + getArrayEncoder, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, +} from "@solana/kit"; +import { findLendingGlobalConfigStatePda } from "../pdas/index.js"; + +export const LENDING_GLOBAL_CONFIG_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([149, 8, 156, 202, 160, 252, 176, 217]); + +export function getLendingGlobalConfigDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + LENDING_GLOBAL_CONFIG_DISCRIMINATOR, + ); +} + +export interface LendingGlobalConfig { + discriminator: ReadonlyUint8Array; + /** Global admin of the program */ + globalAdmin: Address; + /** Pending admin must sign a specific transaction to become the global admin */ + pendingAdmin: Address; + /** Fee collector is the only allowed owner of token accounts receiving protocol fees */ + feeCollector: Address; + /** Padding to make the struct size 1024 bytes */ + padding: number[]; +} + +export interface LendingGlobalConfigArgs { + /** Global admin of the program */ + globalAdmin: Address; + /** Pending admin must sign a specific transaction to become the global admin */ + pendingAdmin: Address; + /** Fee collector is the only allowed owner of token accounts receiving protocol fees */ + feeCollector: Address; + /** Padding to make the struct size 1024 bytes */ + padding: number[]; +} + +export function getLendingGlobalConfigEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["globalAdmin", getAddressEncoder()], + ["pendingAdmin", getAddressEncoder()], + ["feeCollector", getAddressEncoder()], + ["padding", getArrayEncoder(getU8Encoder(), { size: 928 })], + ]), + (value) => ({ + ...value, + discriminator: LENDING_GLOBAL_CONFIG_DISCRIMINATOR, + }), + ); +} + +export function getLendingGlobalConfigDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["globalAdmin", getAddressDecoder()], + ["pendingAdmin", getAddressDecoder()], + ["feeCollector", getAddressDecoder()], + ["padding", getArrayDecoder(getU8Decoder(), { size: 928 })], + ]); +} + +export function getLendingGlobalConfigCodec(): FixedSizeCodec< + LendingGlobalConfigArgs, + LendingGlobalConfig +> { + return combineCodec( + getLendingGlobalConfigEncoder(), + getLendingGlobalConfigDecoder(), + ); +} + +export function decodeLendingGlobalConfig( + encodedAccount: EncodedAccount, +): Account; +export function decodeLendingGlobalConfig( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodeLendingGlobalConfig( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): + | Account + | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getLendingGlobalConfigDecoder(), + ); +} + +export async function fetchLendingGlobalConfig< + TAddress extends string = string, +>( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybeLendingGlobalConfig( + rpc, + address, + config, + ); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeLendingGlobalConfig< + TAddress extends string = string, +>( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeLendingGlobalConfig(maybeAccount); +} + +export async function fetchAllLendingGlobalConfig( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybeLendingGlobalConfig( + rpc, + addresses, + config, + ); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeLendingGlobalConfig( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => + decodeLendingGlobalConfig(maybeAccount), + ); +} + +export async function fetchLendingGlobalConfigFromSeeds( + rpc: Parameters[0], + + config: FetchAccountConfig & { programAddress?: Address } = {}, +): Promise> { + const maybeAccount = await fetchMaybeLendingGlobalConfigFromSeeds( + rpc, + config, + ); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeLendingGlobalConfigFromSeeds( + rpc: Parameters[0], + + config: FetchAccountConfig & { programAddress?: Address } = {}, +): Promise> { + const { programAddress, ...fetchConfig } = config; + const [address] = await findLendingGlobalConfigStatePda({ programAddress }); + return await fetchMaybeLendingGlobalConfig(rpc, address, fetchConfig); +} diff --git a/clients/kamino-lending/src/generated/accounts/lendingMarket.ts b/clients/kamino-lending/src/generated/accounts/lendingMarket.ts index 64a1cc9e..daaa8247 100644 --- a/clients/kamino-lending/src/generated/accounts/lendingMarket.ts +++ b/clients/kamino-lending/src/generated/accounts/lendingMarket.ts @@ -20,8 +20,8 @@ import type { ReadonlyUint8Array, } from "@solana/kit"; import type { - ElevationGroupLendingMarket, - ElevationGroupLendingMarketArgs, + ElevationGroupPod, + ElevationGroupPodArgs, } from "../types/index.js"; import { assertAccountExists, @@ -51,8 +51,8 @@ import { transformEncoder, } from "@solana/kit"; import { - getElevationGroupLendingMarketDecoder, - getElevationGroupLendingMarketEncoder, + getElevationGroupPodDecoder, + getElevationGroupPodEncoder, } from "../types/index.js"; export const LENDING_MARKET_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ @@ -67,62 +67,164 @@ export function getLendingMarketDiscriminatorBytes(): ReadonlyUint8Array { export interface LendingMarket { discriminator: ReadonlyUint8Array; + /** Version of lending market */ version: bigint; + /** Bump seed for derived authority address */ bumpSeed: bigint; + /** Owner authority which can add new reserves */ lendingMarketOwner: Address; + /** Temporary cache of the lending market owner, used in update_lending_market_owner */ lendingMarketOwnerCached: Address; + /** + * Currency market prices are quoted in + * e.g. "USD" null padded (`*b"USD\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"`) or a SPL token mint pubkey + */ quoteCurrency: number[]; + /** Referral fee for the lending market, as bps out of the total protocol fee */ referralFeeBps: number; emergencyMode: number; + /** + * Whether the obligations on this market should be subject to auto-deleveraging after deposit + * or borrow limit is crossed. + * Besides this flag, the particular reserve's flag also needs to be enabled (logical `AND`). + * **NOTE:** this also affects the individual "target LTV" deleveraging. + */ autodeleverageEnabled: number; borrowDisabled: number; + /** + * Refresh price from oracle only if it's older than this percentage of the price max age. + * e.g. if the max age is set to 100s and this is set to 80%, the price will be refreshed if it's older than 80s. + * Price is always refreshed if this set to 0. + */ priceRefreshTriggerToMaxAgePct: number; + /** Percentage of the total borrowed value in an obligation available for liquidation */ liquidationMaxDebtCloseFactorPct: number; + /** Minimum acceptable unhealthy LTV before max_debt_close_factor_pct becomes 100% */ insolvencyRiskUnhealthyLtvPct: number; + /** Minimum liquidation value threshold triggering full liquidation for an obligation */ minFullLiquidationValueThreshold: bigint; + /** Max allowed liquidation value in one ix call */ maxLiquidatableDebtMarketValueAtOnce: bigint; + /** [DEPRECATED] Global maximum unhealthy borrow value allowed for any obligation */ reserved0: number[]; + /** Global maximum allowed borrow value allowed for any obligation */ globalAllowedBorrowValue: bigint; + /** The address of the risk council, in charge of making parameter and risk decisions on behalf of the protocol */ riskCouncil: Address; + /** [DEPRECATED] Reward points multiplier per obligation type */ reserved1: number[]; - elevationGroups: ElevationGroupLendingMarket[]; + /** Elevation groups are used to group together reserves that have the same risk parameters and can bump the ltv and liquidation threshold */ + elevationGroups: ElevationGroupPod[]; elevationGroupPadding: bigint[]; + /** Min net value accepted to be found in a position after any lending action in an obligation (scaled by quote currency decimals) */ minNetValueInObligationSf: bigint; + /** Minimum value to enforce smallest ltv priority checks on the collateral reserves on liquidation */ minValueSkipLiquidationLtvChecks: bigint; + /** Market name, zero-padded. */ name: number[]; + /** Minimum value to enforce highest borrow factor priority checks on the debt reserves on liquidation */ minValueSkipLiquidationBfChecks: bigint; + /** + * Time (in seconds) that must pass before liquidation is allowed on an obligation that has + * been individually marked for auto-deleveraging (by the risk council). + */ individualAutodeleverageMarginCallPeriodSecs: bigint; + /** + * Minimum amount of deposit at creation of a reserve to prevent artificial inflation + * Note: this amount cannot be recovered, the ctoken associated are never minted + */ minInitialDepositAmount: bigint; + /** Whether the obligation orders should be evaluated during liquidations. */ + obligationOrderExecutionEnabled: number; + /** Whether the lending market is set as immutable. */ + immutable: number; + /** + * Whether new obligation orders can be created. + * Note: updating or cancelling existing orders is *not* affected by this flag. + */ + obligationOrderCreationEnabled: number; + padding2: number[]; padding1: bigint[]; } export interface LendingMarketArgs { + /** Version of lending market */ version: number | bigint; + /** Bump seed for derived authority address */ bumpSeed: number | bigint; + /** Owner authority which can add new reserves */ lendingMarketOwner: Address; + /** Temporary cache of the lending market owner, used in update_lending_market_owner */ lendingMarketOwnerCached: Address; + /** + * Currency market prices are quoted in + * e.g. "USD" null padded (`*b"USD\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"`) or a SPL token mint pubkey + */ quoteCurrency: number[]; + /** Referral fee for the lending market, as bps out of the total protocol fee */ referralFeeBps: number; emergencyMode: number; + /** + * Whether the obligations on this market should be subject to auto-deleveraging after deposit + * or borrow limit is crossed. + * Besides this flag, the particular reserve's flag also needs to be enabled (logical `AND`). + * **NOTE:** this also affects the individual "target LTV" deleveraging. + */ autodeleverageEnabled: number; borrowDisabled: number; + /** + * Refresh price from oracle only if it's older than this percentage of the price max age. + * e.g. if the max age is set to 100s and this is set to 80%, the price will be refreshed if it's older than 80s. + * Price is always refreshed if this set to 0. + */ priceRefreshTriggerToMaxAgePct: number; + /** Percentage of the total borrowed value in an obligation available for liquidation */ liquidationMaxDebtCloseFactorPct: number; + /** Minimum acceptable unhealthy LTV before max_debt_close_factor_pct becomes 100% */ insolvencyRiskUnhealthyLtvPct: number; + /** Minimum liquidation value threshold triggering full liquidation for an obligation */ minFullLiquidationValueThreshold: number | bigint; + /** Max allowed liquidation value in one ix call */ maxLiquidatableDebtMarketValueAtOnce: number | bigint; + /** [DEPRECATED] Global maximum unhealthy borrow value allowed for any obligation */ reserved0: number[]; + /** Global maximum allowed borrow value allowed for any obligation */ globalAllowedBorrowValue: number | bigint; + /** The address of the risk council, in charge of making parameter and risk decisions on behalf of the protocol */ riskCouncil: Address; + /** [DEPRECATED] Reward points multiplier per obligation type */ reserved1: number[]; - elevationGroups: ElevationGroupLendingMarketArgs[]; + /** Elevation groups are used to group together reserves that have the same risk parameters and can bump the ltv and liquidation threshold */ + elevationGroups: ElevationGroupPodArgs[]; elevationGroupPadding: (number | bigint)[]; + /** Min net value accepted to be found in a position after any lending action in an obligation (scaled by quote currency decimals) */ minNetValueInObligationSf: number | bigint; + /** Minimum value to enforce smallest ltv priority checks on the collateral reserves on liquidation */ minValueSkipLiquidationLtvChecks: number | bigint; + /** Market name, zero-padded. */ name: number[]; + /** Minimum value to enforce highest borrow factor priority checks on the debt reserves on liquidation */ minValueSkipLiquidationBfChecks: number | bigint; + /** + * Time (in seconds) that must pass before liquidation is allowed on an obligation that has + * been individually marked for auto-deleveraging (by the risk council). + */ individualAutodeleverageMarginCallPeriodSecs: number | bigint; + /** + * Minimum amount of deposit at creation of a reserve to prevent artificial inflation + * Note: this amount cannot be recovered, the ctoken associated are never minted + */ minInitialDepositAmount: number | bigint; + /** Whether the obligation orders should be evaluated during liquidations. */ + obligationOrderExecutionEnabled: number; + /** Whether the lending market is set as immutable. */ + immutable: number; + /** + * Whether new obligation orders can be created. + * Note: updating or cancelling existing orders is *not* affected by this flag. + */ + obligationOrderCreationEnabled: number; + padding2: number[]; padding1: (number | bigint)[]; } @@ -150,7 +252,7 @@ export function getLendingMarketEncoder(): FixedSizeEncoder { ["reserved1", getArrayEncoder(getU8Encoder(), { size: 8 })], [ "elevationGroups", - getArrayEncoder(getElevationGroupLendingMarketEncoder(), { size: 32 }), + getArrayEncoder(getElevationGroupPodEncoder(), { size: 32 }), ], ["elevationGroupPadding", getArrayEncoder(getU64Encoder(), { size: 90 })], ["minNetValueInObligationSf", getU128Encoder()], @@ -159,7 +261,11 @@ export function getLendingMarketEncoder(): FixedSizeEncoder { ["minValueSkipLiquidationBfChecks", getU64Encoder()], ["individualAutodeleverageMarginCallPeriodSecs", getU64Encoder()], ["minInitialDepositAmount", getU64Encoder()], - ["padding1", getArrayEncoder(getU64Encoder(), { size: 170 })], + ["obligationOrderExecutionEnabled", getU8Encoder()], + ["immutable", getU8Encoder()], + ["obligationOrderCreationEnabled", getU8Encoder()], + ["padding2", getArrayEncoder(getU8Encoder(), { size: 5 })], + ["padding1", getArrayEncoder(getU64Encoder(), { size: 169 })], ]), (value) => ({ ...value, discriminator: LENDING_MARKET_DISCRIMINATOR }), ); @@ -188,7 +294,7 @@ export function getLendingMarketDecoder(): FixedSizeDecoder { ["reserved1", getArrayDecoder(getU8Decoder(), { size: 8 })], [ "elevationGroups", - getArrayDecoder(getElevationGroupLendingMarketDecoder(), { size: 32 }), + getArrayDecoder(getElevationGroupPodDecoder(), { size: 32 }), ], ["elevationGroupPadding", getArrayDecoder(getU64Decoder(), { size: 90 })], ["minNetValueInObligationSf", getU128Decoder()], @@ -197,7 +303,11 @@ export function getLendingMarketDecoder(): FixedSizeDecoder { ["minValueSkipLiquidationBfChecks", getU64Decoder()], ["individualAutodeleverageMarginCallPeriodSecs", getU64Decoder()], ["minInitialDepositAmount", getU64Decoder()], - ["padding1", getArrayDecoder(getU64Decoder(), { size: 170 })], + ["obligationOrderExecutionEnabled", getU8Decoder()], + ["immutable", getU8Decoder()], + ["obligationOrderCreationEnabled", getU8Decoder()], + ["padding2", getArrayDecoder(getU8Decoder(), { size: 5 })], + ["padding1", getArrayDecoder(getU64Decoder(), { size: 169 })], ]); } diff --git a/clients/kamino-lending/src/generated/accounts/obligation.ts b/clients/kamino-lending/src/generated/accounts/obligation.ts index ac88b230..d20ba2f3 100644 --- a/clients/kamino-lending/src/generated/accounts/obligation.ts +++ b/clients/kamino-lending/src/generated/accounts/obligation.ts @@ -19,6 +19,7 @@ import type { MaybeEncodedAccount, ReadonlyUint8Array, } from "@solana/kit"; +import type { ObligationSeeds } from "../pdas/index.js"; import type { LastUpdate, LastUpdateArgs, @@ -26,6 +27,8 @@ import type { ObligationCollateralArgs, ObligationLiquidity, ObligationLiquidityArgs, + ObligationOrder, + ObligationOrderArgs, } from "../types/index.js"; import { assertAccountExists, @@ -52,6 +55,7 @@ import { getU128Encoder, transformEncoder, } from "@solana/kit"; +import { findObligationPda } from "../pdas/index.js"; import { getLastUpdateDecoder, getLastUpdateEncoder, @@ -59,6 +63,8 @@ import { getObligationCollateralEncoder, getObligationLiquidityDecoder, getObligationLiquidityEncoder, + getObligationOrderDecoder, + getObligationOrderEncoder, } from "../types/index.js"; export const OBLIGATION_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ @@ -71,58 +77,128 @@ export function getObligationDiscriminatorBytes(): ReadonlyUint8Array { export interface Obligation { discriminator: ReadonlyUint8Array; + /** Version of the struct */ tag: bigint; + /** Last update to collateral, liquidity, or their market values */ lastUpdate: LastUpdate; + /** Lending market address */ lendingMarket: Address; + /** Owner authority which can borrow liquidity */ owner: Address; + /** Deposited collateral for the obligation, unique by deposit reserve address */ deposits: ObligationCollateral[]; + /** Worst LTV for the collaterals backing the loan, represented as a percentage */ lowestReserveDepositLiquidationLtv: bigint; + /** Market value of deposits (scaled fraction) */ depositedValueSf: bigint; + /** Borrowed liquidity for the obligation, unique by borrow reserve address */ borrows: ObligationLiquidity[]; + /** Risk adjusted market value of borrows/debt (sum of price * borrowed_amount * borrow_factor) (scaled fraction) */ borrowFactorAdjustedDebtValueSf: bigint; + /** Market value of borrows - used for max_liquidatable_borrowed_amount (scaled fraction) */ borrowedAssetsMarketValueSf: bigint; + /** The maximum borrow value at the weighted average loan to value ratio (scaled fraction) */ allowedBorrowValueSf: bigint; + /** The dangerous borrow value at the weighted average liquidation threshold (scaled fraction) */ unhealthyBorrowValueSf: bigint; + /** The asset tier of the deposits */ depositsAssetTiers: number[]; + /** The asset tier of the borrows */ borrowsAssetTiers: number[]; + /** The elevation group id the obligation opted into. */ elevationGroup: number; - numOfObsoleteReserves: number; + /** The number of obsolete reserves the obligation has a deposit in */ + numOfObsoleteDepositReserves: number; + /** Marked = 1 if borrows array is not empty, 0 = borrows empty */ hasDebt: number; + /** Wallet address of the referrer */ referrer: Address; + /** Marked = 1 if borrowing disabled, 0 = borrowing enabled */ borrowingDisabled: number; + /** + * A target LTV set by the risk council when marking this obligation for deleveraging. + * Only effective when `deleveraging_margin_call_started_slot != 0`. + */ autodeleverageTargetLtvPct: number; + /** The lowest max LTV found amongst the collateral deposits */ lowestReserveDepositMaxLtvPct: number; + /** The number of obsolete reserves the obligation has a borrow in */ + numOfObsoleteBorrowReserves: number; reserved: number[]; highestBorrowFactorPct: bigint; + /** + * A timestamp at which the risk council most-recently marked this obligation for deleveraging. + * Zero if not currently subject to deleveraging. + */ autodeleverageMarginCallStartedTimestamp: bigint; + /** + * Owner-defined, liquidator-executed orders applicable to this obligation. + * Typical use-cases would be a stop-loss and a take-profit (possibly co-existing). + */ + orders: ObligationOrder[]; padding3: bigint[]; } export interface ObligationArgs { + /** Version of the struct */ tag: number | bigint; + /** Last update to collateral, liquidity, or their market values */ lastUpdate: LastUpdateArgs; + /** Lending market address */ lendingMarket: Address; + /** Owner authority which can borrow liquidity */ owner: Address; + /** Deposited collateral for the obligation, unique by deposit reserve address */ deposits: ObligationCollateralArgs[]; + /** Worst LTV for the collaterals backing the loan, represented as a percentage */ lowestReserveDepositLiquidationLtv: number | bigint; + /** Market value of deposits (scaled fraction) */ depositedValueSf: number | bigint; + /** Borrowed liquidity for the obligation, unique by borrow reserve address */ borrows: ObligationLiquidityArgs[]; + /** Risk adjusted market value of borrows/debt (sum of price * borrowed_amount * borrow_factor) (scaled fraction) */ borrowFactorAdjustedDebtValueSf: number | bigint; + /** Market value of borrows - used for max_liquidatable_borrowed_amount (scaled fraction) */ borrowedAssetsMarketValueSf: number | bigint; + /** The maximum borrow value at the weighted average loan to value ratio (scaled fraction) */ allowedBorrowValueSf: number | bigint; + /** The dangerous borrow value at the weighted average liquidation threshold (scaled fraction) */ unhealthyBorrowValueSf: number | bigint; + /** The asset tier of the deposits */ depositsAssetTiers: number[]; + /** The asset tier of the borrows */ borrowsAssetTiers: number[]; + /** The elevation group id the obligation opted into. */ elevationGroup: number; - numOfObsoleteReserves: number; + /** The number of obsolete reserves the obligation has a deposit in */ + numOfObsoleteDepositReserves: number; + /** Marked = 1 if borrows array is not empty, 0 = borrows empty */ hasDebt: number; + /** Wallet address of the referrer */ referrer: Address; + /** Marked = 1 if borrowing disabled, 0 = borrowing enabled */ borrowingDisabled: number; + /** + * A target LTV set by the risk council when marking this obligation for deleveraging. + * Only effective when `deleveraging_margin_call_started_slot != 0`. + */ autodeleverageTargetLtvPct: number; + /** The lowest max LTV found amongst the collateral deposits */ lowestReserveDepositMaxLtvPct: number; + /** The number of obsolete reserves the obligation has a borrow in */ + numOfObsoleteBorrowReserves: number; reserved: number[]; highestBorrowFactorPct: number | bigint; + /** + * A timestamp at which the risk council most-recently marked this obligation for deleveraging. + * Zero if not currently subject to deleveraging. + */ autodeleverageMarginCallStartedTimestamp: number | bigint; + /** + * Owner-defined, liquidator-executed orders applicable to this obligation. + * Typical use-cases would be a stop-loss and a take-profit (possibly co-existing). + */ + orders: ObligationOrderArgs[]; padding3: (number | bigint)[]; } @@ -151,16 +227,18 @@ export function getObligationEncoder(): FixedSizeEncoder { ["depositsAssetTiers", getArrayEncoder(getU8Encoder(), { size: 8 })], ["borrowsAssetTiers", getArrayEncoder(getU8Encoder(), { size: 5 })], ["elevationGroup", getU8Encoder()], - ["numOfObsoleteReserves", getU8Encoder()], + ["numOfObsoleteDepositReserves", getU8Encoder()], ["hasDebt", getU8Encoder()], ["referrer", getAddressEncoder()], ["borrowingDisabled", getU8Encoder()], ["autodeleverageTargetLtvPct", getU8Encoder()], ["lowestReserveDepositMaxLtvPct", getU8Encoder()], - ["reserved", getArrayEncoder(getU8Encoder(), { size: 5 })], + ["numOfObsoleteBorrowReserves", getU8Encoder()], + ["reserved", getArrayEncoder(getU8Encoder(), { size: 4 })], ["highestBorrowFactorPct", getU64Encoder()], ["autodeleverageMarginCallStartedTimestamp", getU64Encoder()], - ["padding3", getArrayEncoder(getU64Encoder(), { size: 125 })], + ["orders", getArrayEncoder(getObligationOrderEncoder(), { size: 2 })], + ["padding3", getArrayEncoder(getU64Encoder(), { size: 93 })], ]), (value) => ({ ...value, discriminator: OBLIGATION_DISCRIMINATOR }), ); @@ -187,16 +265,18 @@ export function getObligationDecoder(): FixedSizeDecoder { ["depositsAssetTiers", getArrayDecoder(getU8Decoder(), { size: 8 })], ["borrowsAssetTiers", getArrayDecoder(getU8Decoder(), { size: 5 })], ["elevationGroup", getU8Decoder()], - ["numOfObsoleteReserves", getU8Decoder()], + ["numOfObsoleteDepositReserves", getU8Decoder()], ["hasDebt", getU8Decoder()], ["referrer", getAddressDecoder()], ["borrowingDisabled", getU8Decoder()], ["autodeleverageTargetLtvPct", getU8Decoder()], ["lowestReserveDepositMaxLtvPct", getU8Decoder()], - ["reserved", getArrayDecoder(getU8Decoder(), { size: 5 })], + ["numOfObsoleteBorrowReserves", getU8Decoder()], + ["reserved", getArrayDecoder(getU8Decoder(), { size: 4 })], ["highestBorrowFactorPct", getU64Decoder()], ["autodeleverageMarginCallStartedTimestamp", getU64Decoder()], - ["padding3", getArrayDecoder(getU64Decoder(), { size: 125 })], + ["orders", getArrayDecoder(getObligationOrderDecoder(), { size: 2 })], + ["padding3", getArrayDecoder(getU64Decoder(), { size: 93 })], ]); } @@ -259,3 +339,23 @@ export async function fetchAllMaybeObligation( const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeObligation(maybeAccount)); } + +export async function fetchObligationFromSeeds( + rpc: Parameters[0], + seeds: ObligationSeeds, + config: FetchAccountConfig & { programAddress?: Address } = {}, +): Promise> { + const maybeAccount = await fetchMaybeObligationFromSeeds(rpc, seeds, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeObligationFromSeeds( + rpc: Parameters[0], + seeds: ObligationSeeds, + config: FetchAccountConfig & { programAddress?: Address } = {}, +): Promise> { + const { programAddress, ...fetchConfig } = config; + const [address] = await findObligationPda(seeds, { programAddress }); + return await fetchMaybeObligation(rpc, address, fetchConfig); +} diff --git a/clients/kamino-lending/src/generated/accounts/referrerState.ts b/clients/kamino-lending/src/generated/accounts/referrerState.ts index 0e1ce3f3..a9844c84 100644 --- a/clients/kamino-lending/src/generated/accounts/referrerState.ts +++ b/clients/kamino-lending/src/generated/accounts/referrerState.ts @@ -19,6 +19,7 @@ import type { MaybeEncodedAccount, ReadonlyUint8Array, } from "@solana/kit"; +import type { ReferrerStateSeeds } from "../pdas/index.js"; import { assertAccountExists, assertAccountsExist, @@ -36,6 +37,7 @@ import { getStructEncoder, transformEncoder, } from "@solana/kit"; +import { findReferrerStatePda } from "../pdas/index.js"; export const REFERRER_STATE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ 194, 81, 217, 103, 12, 19, 12, 66, @@ -140,3 +142,27 @@ export async function fetchAllMaybeReferrerState( const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeReferrerState(maybeAccount)); } + +export async function fetchReferrerStateFromSeeds( + rpc: Parameters[0], + seeds: ReferrerStateSeeds, + config: FetchAccountConfig & { programAddress?: Address } = {}, +): Promise> { + const maybeAccount = await fetchMaybeReferrerStateFromSeeds( + rpc, + seeds, + config, + ); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeReferrerStateFromSeeds( + rpc: Parameters[0], + seeds: ReferrerStateSeeds, + config: FetchAccountConfig & { programAddress?: Address } = {}, +): Promise> { + const { programAddress, ...fetchConfig } = config; + const [address] = await findReferrerStatePda(seeds, { programAddress }); + return await fetchMaybeReferrerState(rpc, address, fetchConfig); +} diff --git a/clients/kamino-lending/src/generated/accounts/referrerTokenState.ts b/clients/kamino-lending/src/generated/accounts/referrerTokenState.ts index 4fa3d006..368562ce 100644 --- a/clients/kamino-lending/src/generated/accounts/referrerTokenState.ts +++ b/clients/kamino-lending/src/generated/accounts/referrerTokenState.ts @@ -19,6 +19,7 @@ import type { MaybeEncodedAccount, ReadonlyUint8Array, } from "@solana/kit"; +import type { ReferrerTokenStateSeeds } from "../pdas/index.js"; import { assertAccountExists, assertAccountsExist, @@ -42,6 +43,7 @@ import { getU128Encoder, transformEncoder, } from "@solana/kit"; +import { findReferrerTokenStatePda } from "../pdas/index.js"; export const REFERRER_TOKEN_STATE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([39, 15, 208, 77, 32, 195, 105, 56]); @@ -54,19 +56,29 @@ export function getReferrerTokenStateDiscriminatorBytes(): ReadonlyUint8Array { export interface ReferrerTokenState { discriminator: ReadonlyUint8Array; + /** Pubkey of the referrer/owner */ referrer: Address; + /** Token mint for the account */ mint: Address; + /** Amount that has been accumulated and not claimed yet -> available to claim (scaled fraction) */ amountUnclaimedSf: bigint; + /** Amount that has been accumulated in total -> both already claimed and unclaimed (scaled fraction) */ amountCumulativeSf: bigint; + /** Referrer token state bump, used for address validation */ bump: bigint; padding: bigint[]; } export interface ReferrerTokenStateArgs { + /** Pubkey of the referrer/owner */ referrer: Address; + /** Token mint for the account */ mint: Address; + /** Amount that has been accumulated and not claimed yet -> available to claim (scaled fraction) */ amountUnclaimedSf: number | bigint; + /** Amount that has been accumulated in total -> both already claimed and unclaimed (scaled fraction) */ amountCumulativeSf: number | bigint; + /** Referrer token state bump, used for address validation */ bump: number | bigint; padding: (number | bigint)[]; } @@ -173,3 +185,27 @@ export async function fetchAllMaybeReferrerTokenState( decodeReferrerTokenState(maybeAccount), ); } + +export async function fetchReferrerTokenStateFromSeeds( + rpc: Parameters[0], + seeds: ReferrerTokenStateSeeds, + config: FetchAccountConfig & { programAddress?: Address } = {}, +): Promise> { + const maybeAccount = await fetchMaybeReferrerTokenStateFromSeeds( + rpc, + seeds, + config, + ); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeReferrerTokenStateFromSeeds( + rpc: Parameters[0], + seeds: ReferrerTokenStateSeeds, + config: FetchAccountConfig & { programAddress?: Address } = {}, +): Promise> { + const { programAddress, ...fetchConfig } = config; + const [address] = await findReferrerTokenStatePda(seeds, { programAddress }); + return await fetchMaybeReferrerTokenState(rpc, address, fetchConfig); +} diff --git a/clients/kamino-lending/src/generated/accounts/reserve.ts b/clients/kamino-lending/src/generated/accounts/reserve.ts index 5de83055..1ebd0723 100644 --- a/clients/kamino-lending/src/generated/accounts/reserve.ts +++ b/clients/kamino-lending/src/generated/accounts/reserve.ts @@ -71,35 +71,55 @@ export function getReserveDiscriminatorBytes(): ReadonlyUint8Array { export interface Reserve { discriminator: ReadonlyUint8Array; + /** Version of the reserve */ version: bigint; + /** Last slot when supply and rates updated */ lastUpdate: LastUpdate; + /** Lending market address */ lendingMarket: Address; farmCollateral: Address; farmDebt: Address; + /** Reserve liquidity */ liquidity: ReserveLiquidity; reserveLiquidityPadding: bigint[]; + /** Reserve collateral */ collateral: ReserveCollateral; reserveCollateralPadding: bigint[]; + /** Reserve configuration values */ config: ReserveConfig; configPadding: bigint[]; borrowedAmountOutsideElevationGroup: bigint; + /** + * Amount of token borrowed in lamport of debt asset in the given + * elevation group when this reserve is part of the collaterals. + */ borrowedAmountsAgainstThisReserveInElevationGroups: bigint[]; padding: bigint[]; } export interface ReserveArgs { + /** Version of the reserve */ version: number | bigint; + /** Last slot when supply and rates updated */ lastUpdate: LastUpdateArgs; + /** Lending market address */ lendingMarket: Address; farmCollateral: Address; farmDebt: Address; + /** Reserve liquidity */ liquidity: ReserveLiquidityArgs; reserveLiquidityPadding: (number | bigint)[]; + /** Reserve collateral */ collateral: ReserveCollateralArgs; reserveCollateralPadding: (number | bigint)[]; + /** Reserve configuration values */ config: ReserveConfigArgs; configPadding: (number | bigint)[]; borrowedAmountOutsideElevationGroup: number | bigint; + /** + * Amount of token borrowed in lamport of debt asset in the given + * elevation group when this reserve is part of the collaterals. + */ borrowedAmountsAgainstThisReserveInElevationGroups: (number | bigint)[]; padding: (number | bigint)[]; } diff --git a/clients/kamino-lending/src/generated/accounts/shortUrl.ts b/clients/kamino-lending/src/generated/accounts/shortUrl.ts index 3641ff70..bde5bc8f 100644 --- a/clients/kamino-lending/src/generated/accounts/shortUrl.ts +++ b/clients/kamino-lending/src/generated/accounts/shortUrl.ts @@ -19,6 +19,7 @@ import type { MaybeEncodedAccount, ReadonlyUint8Array, } from "@solana/kit"; +import type { ShortUrlSeeds } from "../pdas/index.js"; import { addDecoderSizePrefix, addEncoderSizePrefix, @@ -42,6 +43,7 @@ import { getUtf8Encoder, transformEncoder, } from "@solana/kit"; +import { findShortUrlPda } from "../pdas/index.js"; export const SHORT_URL_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ 28, 89, 174, 25, 226, 124, 126, 212, @@ -137,3 +139,23 @@ export async function fetchAllMaybeShortUrl( const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeShortUrl(maybeAccount)); } + +export async function fetchShortUrlFromSeeds( + rpc: Parameters[0], + seeds: ShortUrlSeeds, + config: FetchAccountConfig & { programAddress?: Address } = {}, +): Promise> { + const maybeAccount = await fetchMaybeShortUrlFromSeeds(rpc, seeds, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeShortUrlFromSeeds( + rpc: Parameters[0], + seeds: ShortUrlSeeds, + config: FetchAccountConfig & { programAddress?: Address } = {}, +): Promise> { + const { programAddress, ...fetchConfig } = config; + const [address] = await findShortUrlPda(seeds, { programAddress }); + return await fetchMaybeShortUrl(rpc, address, fetchConfig); +} diff --git a/clients/kamino-lending/src/generated/accounts/userMetadata.ts b/clients/kamino-lending/src/generated/accounts/userMetadata.ts index 72581dac..a2e922e4 100644 --- a/clients/kamino-lending/src/generated/accounts/userMetadata.ts +++ b/clients/kamino-lending/src/generated/accounts/userMetadata.ts @@ -19,6 +19,7 @@ import type { MaybeEncodedAccount, ReadonlyUint8Array, } from "@solana/kit"; +import type { UserMetadataSeeds } from "../pdas/index.js"; import { assertAccountExists, assertAccountsExist, @@ -40,6 +41,7 @@ import { getU64Encoder, transformEncoder, } from "@solana/kit"; +import { findUserMetadataPda } from "../pdas/index.js"; export const USER_METADATA_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ 157, 214, 220, 235, 98, 135, 171, 28, @@ -53,18 +55,26 @@ export function getUserMetadataDiscriminatorBytes(): ReadonlyUint8Array { export interface UserMetadata { discriminator: ReadonlyUint8Array; + /** Pubkey of the referrer/owner - pubkey::default if no referrer */ referrer: Address; + /** Bump used for validation of account address */ bump: bigint; + /** User lookup table - used to store all user accounts - atas for each reserve mint, each obligation PDA, UserMetadata itself and all referrer_token_states if there is a referrer */ userLookupTable: Address; + /** User metadata account owner */ owner: Address; padding1: bigint[]; padding2: bigint[]; } export interface UserMetadataArgs { + /** Pubkey of the referrer/owner - pubkey::default if no referrer */ referrer: Address; + /** Bump used for validation of account address */ bump: number | bigint; + /** User lookup table - used to store all user accounts - atas for each reserve mint, each obligation PDA, UserMetadata itself and all referrer_token_states if there is a referrer */ userLookupTable: Address; + /** User metadata account owner */ owner: Address; padding1: (number | bigint)[]; padding2: (number | bigint)[]; @@ -156,3 +166,27 @@ export async function fetchAllMaybeUserMetadata( const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); return maybeAccounts.map((maybeAccount) => decodeUserMetadata(maybeAccount)); } + +export async function fetchUserMetadataFromSeeds( + rpc: Parameters[0], + seeds: UserMetadataSeeds, + config: FetchAccountConfig & { programAddress?: Address } = {}, +): Promise> { + const maybeAccount = await fetchMaybeUserMetadataFromSeeds( + rpc, + seeds, + config, + ); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeUserMetadataFromSeeds( + rpc: Parameters[0], + seeds: UserMetadataSeeds, + config: FetchAccountConfig & { programAddress?: Address } = {}, +): Promise> { + const { programAddress, ...fetchConfig } = config; + const [address] = await findUserMetadataPda(seeds, { programAddress }); + return await fetchMaybeUserMetadata(rpc, address, fetchConfig); +} diff --git a/clients/kamino-lending/src/generated/accounts/userState.ts b/clients/kamino-lending/src/generated/accounts/userState.ts index ec7c74cf..8764df17 100644 --- a/clients/kamino-lending/src/generated/accounts/userState.ts +++ b/clients/kamino-lending/src/generated/accounts/userState.ts @@ -58,17 +58,42 @@ export interface UserState { userId: bigint; farmState: Address; owner: Address; + /** Indicate if this user state is part of a delegated farm */ isFarmDelegated: number; padding0: number[]; + /** + * Rewards tally used for computation of gained rewards + * (scaled from `Decimal` representation). + */ rewardsTallyScaled: bigint[]; + /** Number of reward tokens ready for claim */ rewardsIssuedUnclaimed: bigint[]; lastClaimTs: bigint[]; + /** + * User stake deposited and usable, generating rewards and fees. + * (scaled from `Decimal` representation). + */ activeStakeScaled: bigint; + /** + * User stake deposited but not usable and not generating rewards yet. + * (scaled from `Decimal` representation). + */ pendingDepositStakeScaled: bigint; + /** + * After this timestamp, pending user stake can be moved to user stake + * Initialized to now() + delayed user stake period + */ pendingDepositStakeTs: bigint; + /** + * User deposits unstaked, pending for withdrawal, not usable and not generating rewards. + * (scaled from `Decimal` representation). + */ pendingWithdrawalUnstakeScaled: bigint; + /** After this timestamp, user can withdraw their deposit. */ pendingWithdrawalUnstakeTs: bigint; + /** User bump used for account address validation */ bump: bigint; + /** Delegatee used for initialisation - useful to check against */ delegatee: Address; lastStakeTs: bigint; padding1: bigint[]; @@ -78,17 +103,42 @@ export interface UserStateArgs { userId: number | bigint; farmState: Address; owner: Address; + /** Indicate if this user state is part of a delegated farm */ isFarmDelegated: number; padding0: number[]; + /** + * Rewards tally used for computation of gained rewards + * (scaled from `Decimal` representation). + */ rewardsTallyScaled: (number | bigint)[]; + /** Number of reward tokens ready for claim */ rewardsIssuedUnclaimed: (number | bigint)[]; lastClaimTs: (number | bigint)[]; + /** + * User stake deposited and usable, generating rewards and fees. + * (scaled from `Decimal` representation). + */ activeStakeScaled: number | bigint; + /** + * User stake deposited but not usable and not generating rewards yet. + * (scaled from `Decimal` representation). + */ pendingDepositStakeScaled: number | bigint; + /** + * After this timestamp, pending user stake can be moved to user stake + * Initialized to now() + delayed user stake period + */ pendingDepositStakeTs: number | bigint; + /** + * User deposits unstaked, pending for withdrawal, not usable and not generating rewards. + * (scaled from `Decimal` representation). + */ pendingWithdrawalUnstakeScaled: number | bigint; + /** After this timestamp, user can withdraw their deposit. */ pendingWithdrawalUnstakeTs: number | bigint; + /** User bump used for account address validation */ bump: number | bigint; + /** Delegatee used for initialisation - useful to check against */ delegatee: Address; lastStakeTs: number | bigint; padding1: (number | bigint)[]; diff --git a/clients/kamino-lending/src/generated/errors/kaminoLending.ts b/clients/kamino-lending/src/generated/errors/kaminoLending.ts index 26a2b611..bf1c2368 100644 --- a/clients/kamino-lending/src/generated/errors/kaminoLending.ts +++ b/clients/kamino-lending/src/generated/errors/kaminoLending.ts @@ -182,8 +182,8 @@ export const KAMINO_LENDING_ERROR__SHORT_URL_NOT_ASCII_ALPHANUMERIC = 0x17c1; // export const KAMINO_LENDING_ERROR__RESERVE_OBSOLETE = 0x17c2; // 6082 /** ElevationGroupAlreadyActivated: Obligation already part of the same elevation group */ export const KAMINO_LENDING_ERROR__ELEVATION_GROUP_ALREADY_ACTIVATED = 0x17c3; // 6083 -/** ObligationInDeprecatedReserve: Obligation has a deposit in a deprecated reserve */ -export const KAMINO_LENDING_ERROR__OBLIGATION_IN_DEPRECATED_RESERVE = 0x17c4; // 6084 +/** ObligationInObsoleteReserve: Obligation has a deposit or borrow in an obsolete reserve */ +export const KAMINO_LENDING_ERROR__OBLIGATION_IN_OBSOLETE_RESERVE = 0x17c4; // 6084 /** ReferrerStateOwnerMismatch: Referrer state owner does not match the given signer */ export const KAMINO_LENDING_ERROR__REFERRER_STATE_OWNER_MISMATCH = 0x17c5; // 6085 /** UserMetadataOwnerAlreadySet: User metadata owner is already set */ @@ -200,8 +200,8 @@ export const KAMINO_LENDING_ERROR__DEPOSIT_LIMIT_EXCEEDED = 0x17ca; // 6090 export const KAMINO_LENDING_ERROR__BORROWING_DISABLED_OUTSIDE_ELEVATION_GROUP = 0x17cb; // 6091 /** NetValueRemainingTooSmall: Net value remaining too small */ export const KAMINO_LENDING_ERROR__NET_VALUE_REMAINING_TOO_SMALL = 0x17cc; // 6092 -/** WorseLTVBlocked: Cannot get the obligation in a worse position */ -export const KAMINO_LENDING_ERROR__WORSE_L_T_V_BLOCKED = 0x17cd; // 6093 +/** WorseLtvBlocked: Cannot get the obligation in a worse position */ +export const KAMINO_LENDING_ERROR__WORSE_LTV_BLOCKED = 0x17cd; // 6093 /** LiabilitiesBiggerThanAssets: Cannot have more liabilities than assets in a position */ export const KAMINO_LENDING_ERROR__LIABILITIES_BIGGER_THAN_ASSETS = 0x17ce; // 6094 /** ReserveTokenBalanceMismatch: Reserve state and token account cannot drift */ @@ -214,8 +214,8 @@ export const KAMINO_LENDING_ERROR__RESERVE_ACCOUNTING_MISMATCH = 0x17d1; // 6097 export const KAMINO_LENDING_ERROR__BORROWING_ABOVE_UTILIZATION_RATE_DISABLED = 0x17d2; // 6098 /** LiquidationBorrowFactorPriority: Liquidation must prioritize the debt with the highest borrow factor */ export const KAMINO_LENDING_ERROR__LIQUIDATION_BORROW_FACTOR_PRIORITY = 0x17d3; // 6099 -/** LiquidationLowestLTVPriority: Liquidation must prioritize the collateral with the lowest LTV */ -export const KAMINO_LENDING_ERROR__LIQUIDATION_LOWEST_L_T_V_PRIORITY = 0x17d4; // 6100 +/** LiquidationLowestLiquidationLtvPriority: Liquidation must prioritize the collateral with the lowest liquidation LTV */ +export const KAMINO_LENDING_ERROR__LIQUIDATION_LOWEST_LIQUIDATION_LTV_PRIORITY = 0x17d4; // 6100 /** ElevationGroupBorrowLimitExceeded: Elevation group borrow limit exceeded */ export const KAMINO_LENDING_ERROR__ELEVATION_GROUP_BORROW_LIMIT_EXCEEDED = 0x17d5; // 6101 /** ElevationGroupWithoutDebtReserve: The elevation group does not have a debt reserve defined */ @@ -250,16 +250,30 @@ export const KAMINO_LENDING_ERROR__OBLIGATION_CURRENTLY_MARKED_FOR_DELEVERAGING export const KAMINO_LENDING_ERROR__MAXIMUM_WITHDRAW_VALUE_ZERO = 0x17e4; // 6116 /** ZeroMaxLtvAssetsInDeposits: No max LTV 0 assets allowed in deposits for repay and withdraw */ export const KAMINO_LENDING_ERROR__ZERO_MAX_LTV_ASSETS_IN_DEPOSITS = 0x17e5; // 6117 -/** MinLtvAssetsPriority: The operation must prioritize the collateral with the lowest LTV */ -export const KAMINO_LENDING_ERROR__MIN_LTV_ASSETS_PRIORITY = 0x17e6; // 6118 -/** WorseLTVThanUnhealthyLTV: Cannot get the obligation liquidatable */ -export const KAMINO_LENDING_ERROR__WORSE_L_T_V_THAN_UNHEALTHY_L_T_V = 0x17e7; // 6119 +/** LowestLtvAssetsPriority: Withdrawing must prioritize the collateral with the lowest reserve max-LTV */ +export const KAMINO_LENDING_ERROR__LOWEST_LTV_ASSETS_PRIORITY = 0x17e6; // 6118 +/** WorseLtvThanUnhealthyLtv: Cannot get the obligation liquidatable */ +export const KAMINO_LENDING_ERROR__WORSE_LTV_THAN_UNHEALTHY_LTV = 0x17e7; // 6119 /** FarmAccountsMissing: Farm accounts to refresh are missing */ export const KAMINO_LENDING_ERROR__FARM_ACCOUNTS_MISSING = 0x17e8; // 6120 /** RepayTooSmallForFullLiquidation: Repay amount is too small to satisfy the mandatory full liquidation */ export const KAMINO_LENDING_ERROR__REPAY_TOO_SMALL_FOR_FULL_LIQUIDATION = 0x17e9; // 6121 /** InsufficientRepayAmount: Liquidator provided repay amount lower than required by liquidation rules */ export const KAMINO_LENDING_ERROR__INSUFFICIENT_REPAY_AMOUNT = 0x17ea; // 6122 +/** OrderIndexOutOfBounds: Obligation order of the given index cannot exist */ +export const KAMINO_LENDING_ERROR__ORDER_INDEX_OUT_OF_BOUNDS = 0x17eb; // 6123 +/** InvalidOrderConfiguration: Given order configuration has wrong parameters */ +export const KAMINO_LENDING_ERROR__INVALID_ORDER_CONFIGURATION = 0x17ec; // 6124 +/** OrderConfigurationNotSupportedByObligation: Given order configuration cannot be used with the current state of the obligation */ +export const KAMINO_LENDING_ERROR__ORDER_CONFIGURATION_NOT_SUPPORTED_BY_OBLIGATION = 0x17ed; // 6125 +/** OperationNotPermittedWithCurrentObligationOrders: Single debt, single collateral obligation orders have to be cancelled before changing the deposit/borrow count */ +export const KAMINO_LENDING_ERROR__OPERATION_NOT_PERMITTED_WITH_CURRENT_OBLIGATION_ORDERS = 0x17ee; // 6126 +/** OperationNotPermittedMarketImmutable: Cannot update lending market because it is set as immutable */ +export const KAMINO_LENDING_ERROR__OPERATION_NOT_PERMITTED_MARKET_IMMUTABLE = 0x17ef; // 6127 +/** OrderCreationDisabled: Creation of new orders is disabled */ +export const KAMINO_LENDING_ERROR__ORDER_CREATION_DISABLED = 0x17f0; // 6128 +/** NoUpgradeAuthority: Cannot initialize global config because there is no upgrade authority to the program */ +export const KAMINO_LENDING_ERROR__NO_UPGRADE_AUTHORITY = 0x17f1; // 6129 export type KaminoLendingError = | typeof KAMINO_LENDING_ERROR__BORROWING_ABOVE_UTILIZATION_RATE_DISABLED @@ -311,6 +325,7 @@ export type KaminoLendingError = | typeof KAMINO_LENDING_ERROR__INVALID_OBLIGATION_OWNER | typeof KAMINO_LENDING_ERROR__INVALID_OBLIGATION_SEEDS_VALUE | typeof KAMINO_LENDING_ERROR__INVALID_ORACLE_CONFIG + | typeof KAMINO_LENDING_ERROR__INVALID_ORDER_CONFIGURATION | typeof KAMINO_LENDING_ERROR__INVALID_PYTH_PRICE_ACCOUNT | typeof KAMINO_LENDING_ERROR__INVALID_SCOPE_PRICE_ACCOUNT | typeof KAMINO_LENDING_ERROR__INVALID_SIGNER @@ -324,18 +339,19 @@ export type KaminoLendingError = | typeof KAMINO_LENDING_ERROR__LENDING_MARKETS_MUST_MATCH | typeof KAMINO_LENDING_ERROR__LIABILITIES_BIGGER_THAN_ASSETS | typeof KAMINO_LENDING_ERROR__LIQUIDATION_BORROW_FACTOR_PRIORITY - | typeof KAMINO_LENDING_ERROR__LIQUIDATION_LOWEST_L_T_V_PRIORITY + | typeof KAMINO_LENDING_ERROR__LIQUIDATION_LOWEST_LIQUIDATION_LTV_PRIORITY | typeof KAMINO_LENDING_ERROR__LIQUIDATION_REWARD_TOO_SMALL | typeof KAMINO_LENDING_ERROR__LIQUIDATION_TOO_SMALL + | typeof KAMINO_LENDING_ERROR__LOWEST_LTV_ASSETS_PRIORITY | typeof KAMINO_LENDING_ERROR__MATH_OVERFLOW | typeof KAMINO_LENDING_ERROR__MAXIMUM_WITHDRAW_VALUE_ZERO - | typeof KAMINO_LENDING_ERROR__MIN_LTV_ASSETS_PRIORITY | typeof KAMINO_LENDING_ERROR__MULTIPLE_FLASH_BORROWS | typeof KAMINO_LENDING_ERROR__NEGATIVE_INTEREST_RATE | typeof KAMINO_LENDING_ERROR__NET_VALUE_REMAINING_TOO_SMALL | typeof KAMINO_LENDING_ERROR__NO_FARM_FOR_RESERVE | typeof KAMINO_LENDING_ERROR__NO_FLASH_REPAY_FOUND | typeof KAMINO_LENDING_ERROR__NO_PRICE_FOUND + | typeof KAMINO_LENDING_ERROR__NO_UPGRADE_AUTHORITY | typeof KAMINO_LENDING_ERROR__OBLIGATION_BORROWS_EMPTY | typeof KAMINO_LENDING_ERROR__OBLIGATION_BORROWS_ZERO | typeof KAMINO_LENDING_ERROR__OBLIGATION_COLLATERAL_EMPTY @@ -347,12 +363,17 @@ export type KaminoLendingError = | typeof KAMINO_LENDING_ERROR__OBLIGATION_ELEVATION_GROUP_MULTIPLE_DEBT_RESERVE | typeof KAMINO_LENDING_ERROR__OBLIGATION_EMPTY | typeof KAMINO_LENDING_ERROR__OBLIGATION_HEALTHY - | typeof KAMINO_LENDING_ERROR__OBLIGATION_IN_DEPRECATED_RESERVE + | typeof KAMINO_LENDING_ERROR__OBLIGATION_IN_OBSOLETE_RESERVE | typeof KAMINO_LENDING_ERROR__OBLIGATION_LIQUIDITY_EMPTY | typeof KAMINO_LENDING_ERROR__OBLIGATION_OWNERS_MUST_MATCH | typeof KAMINO_LENDING_ERROR__OBLIGATION_RESERVE_LIMIT | typeof KAMINO_LENDING_ERROR__OBLIGATIONS_MUST_MATCH | typeof KAMINO_LENDING_ERROR__OBLIGATION_STALE + | typeof KAMINO_LENDING_ERROR__OPERATION_NOT_PERMITTED_MARKET_IMMUTABLE + | typeof KAMINO_LENDING_ERROR__OPERATION_NOT_PERMITTED_WITH_CURRENT_OBLIGATION_ORDERS + | typeof KAMINO_LENDING_ERROR__ORDER_CONFIGURATION_NOT_SUPPORTED_BY_OBLIGATION + | typeof KAMINO_LENDING_ERROR__ORDER_CREATION_DISABLED + | typeof KAMINO_LENDING_ERROR__ORDER_INDEX_OUT_OF_BOUNDS | typeof KAMINO_LENDING_ERROR__PRICE_CONFIDENCE_TOO_WIDE | typeof KAMINO_LENDING_ERROR__PRICE_IS_BIGGER_THAN_HEURISTIC | typeof KAMINO_LENDING_ERROR__PRICE_IS_LOWER_THAN_HEURISTIC @@ -382,8 +403,8 @@ export type KaminoLendingError = | typeof KAMINO_LENDING_ERROR__WITHDRAWAL_CAP_REACHED | typeof KAMINO_LENDING_ERROR__WITHDRAW_TOO_LARGE | typeof KAMINO_LENDING_ERROR__WITHDRAW_TOO_SMALL - | typeof KAMINO_LENDING_ERROR__WORSE_L_T_V_BLOCKED - | typeof KAMINO_LENDING_ERROR__WORSE_L_T_V_THAN_UNHEALTHY_L_T_V + | typeof KAMINO_LENDING_ERROR__WORSE_LTV_BLOCKED + | typeof KAMINO_LENDING_ERROR__WORSE_LTV_THAN_UNHEALTHY_LTV | typeof KAMINO_LENDING_ERROR__ZERO_MAX_LTV_ASSETS_IN_DEPOSITS; let kaminoLendingErrorMessages: Record | undefined; @@ -472,6 +493,8 @@ if (true) { "Seeds must be default pubkeys for tag 0, and mint addresses for tag 1 or 2", [KAMINO_LENDING_ERROR__INVALID_ORACLE_CONFIG]: "Input oracle config is invalid", + [KAMINO_LENDING_ERROR__INVALID_ORDER_CONFIGURATION]: + "Given order configuration has wrong parameters", [KAMINO_LENDING_ERROR__INVALID_PYTH_PRICE_ACCOUNT]: "Pyth price account does not match configuration", [KAMINO_LENDING_ERROR__INVALID_SCOPE_PRICE_ACCOUNT]: @@ -494,17 +517,17 @@ if (true) { "Cannot have more liabilities than assets in a position", [KAMINO_LENDING_ERROR__LIQUIDATION_BORROW_FACTOR_PRIORITY]: "Liquidation must prioritize the debt with the highest borrow factor", - [KAMINO_LENDING_ERROR__LIQUIDATION_LOWEST_L_T_V_PRIORITY]: - "Liquidation must prioritize the collateral with the lowest LTV", + [KAMINO_LENDING_ERROR__LIQUIDATION_LOWEST_LIQUIDATION_LTV_PRIORITY]: + "Liquidation must prioritize the collateral with the lowest liquidation LTV", [KAMINO_LENDING_ERROR__LIQUIDATION_REWARD_TOO_SMALL]: "The reward amount is less than the minimum acceptable received liquidity", [KAMINO_LENDING_ERROR__LIQUIDATION_TOO_SMALL]: "Liquidation amount too small to receive collateral", + [KAMINO_LENDING_ERROR__LOWEST_LTV_ASSETS_PRIORITY]: + "Withdrawing must prioritize the collateral with the lowest reserve max-LTV", [KAMINO_LENDING_ERROR__MATH_OVERFLOW]: "Math operation overflow", [KAMINO_LENDING_ERROR__MAXIMUM_WITHDRAW_VALUE_ZERO]: "Maximum withdrawable value of this collateral is zero, LTV needs improved", - [KAMINO_LENDING_ERROR__MIN_LTV_ASSETS_PRIORITY]: - "The operation must prioritize the collateral with the lowest LTV", [KAMINO_LENDING_ERROR__MULTIPLE_FLASH_BORROWS]: "Multiple flash borrows not allowed in the same transaction", [KAMINO_LENDING_ERROR__NEGATIVE_INTEREST_RATE]: "Interest rate is negative", @@ -515,6 +538,8 @@ if (true) { [KAMINO_LENDING_ERROR__NO_FLASH_REPAY_FOUND]: "No corresponding repay found for flash borrow", [KAMINO_LENDING_ERROR__NO_PRICE_FOUND]: "No price found", + [KAMINO_LENDING_ERROR__NO_UPGRADE_AUTHORITY]: + "Cannot initialize global config because there is no upgrade authority to the program", [KAMINO_LENDING_ERROR__OBLIGATION_BORROWS_EMPTY]: "Obligation borrows are empty", [KAMINO_LENDING_ERROR__OBLIGATION_BORROWS_ZERO]: @@ -537,8 +562,8 @@ if (true) { "Obligation has no borrows or deposits.", [KAMINO_LENDING_ERROR__OBLIGATION_HEALTHY]: "Cannot liquidate healthy obligations", - [KAMINO_LENDING_ERROR__OBLIGATION_IN_DEPRECATED_RESERVE]: - "Obligation has a deposit in a deprecated reserve", + [KAMINO_LENDING_ERROR__OBLIGATION_IN_OBSOLETE_RESERVE]: + "Obligation has a deposit or borrow in an obsolete reserve", [KAMINO_LENDING_ERROR__OBLIGATION_LIQUIDITY_EMPTY]: "Obligation liquidity is empty", [KAMINO_LENDING_ERROR__OBLIGATION_OWNERS_MUST_MATCH]: @@ -548,6 +573,16 @@ if (true) { [KAMINO_LENDING_ERROR__OBLIGATIONS_MUST_MATCH]: "Obligations must match", [KAMINO_LENDING_ERROR__OBLIGATION_STALE]: "Obligation state needs to be refreshed", + [KAMINO_LENDING_ERROR__OPERATION_NOT_PERMITTED_MARKET_IMMUTABLE]: + "Cannot update lending market because it is set as immutable", + [KAMINO_LENDING_ERROR__OPERATION_NOT_PERMITTED_WITH_CURRENT_OBLIGATION_ORDERS]: + "Single debt, single collateral obligation orders have to be cancelled before changing the deposit/borrow count", + [KAMINO_LENDING_ERROR__ORDER_CONFIGURATION_NOT_SUPPORTED_BY_OBLIGATION]: + "Given order configuration cannot be used with the current state of the obligation", + [KAMINO_LENDING_ERROR__ORDER_CREATION_DISABLED]: + "Creation of new orders is disabled", + [KAMINO_LENDING_ERROR__ORDER_INDEX_OUT_OF_BOUNDS]: + "Obligation order of the given index cannot exist", [KAMINO_LENDING_ERROR__PRICE_CONFIDENCE_TOO_WIDE]: "Price confidence too wide", [KAMINO_LENDING_ERROR__PRICE_IS_BIGGER_THAN_HEURISTIC]: @@ -598,9 +633,9 @@ if (true) { [KAMINO_LENDING_ERROR__WITHDRAWAL_CAP_REACHED]: "Withdrawal cap is reached", [KAMINO_LENDING_ERROR__WITHDRAW_TOO_LARGE]: "Withdraw amount too large", [KAMINO_LENDING_ERROR__WITHDRAW_TOO_SMALL]: "Withdraw amount too small", - [KAMINO_LENDING_ERROR__WORSE_L_T_V_BLOCKED]: + [KAMINO_LENDING_ERROR__WORSE_LTV_BLOCKED]: "Cannot get the obligation in a worse position", - [KAMINO_LENDING_ERROR__WORSE_L_T_V_THAN_UNHEALTHY_L_T_V]: + [KAMINO_LENDING_ERROR__WORSE_LTV_THAN_UNHEALTHY_LTV]: "Cannot get the obligation liquidatable", [KAMINO_LENDING_ERROR__ZERO_MAX_LTV_ASSETS_IN_DEPOSITS]: "No max LTV 0 assets allowed in deposits for repay and withdraw", diff --git a/clients/kamino-lending/src/generated/instructions/addRewards.ts b/clients/kamino-lending/src/generated/instructions/addRewards.ts index 5a52447f..2bc3e3b7 100644 --- a/clients/kamino-lending/src/generated/instructions/addRewards.ts +++ b/clients/kamino-lending/src/generated/instructions/addRewards.ts @@ -35,8 +35,12 @@ import { getU64Encoder, transformEncoder, } from "@solana/kit"; +import { + findFarmVaultsAuthorityPda, + findRewardVaultPda, +} from "../pdas/index.js"; import { FARMS_PROGRAM_ADDRESS } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const ADD_REWARDS_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ 88, 186, 25, 227, 38, 137, 81, 23, @@ -132,6 +136,137 @@ export function getAddRewardsInstructionDataCodec(): FixedSizeCodec< ); } +export interface AddRewardsAsyncInput< + TAccountPayer extends string = string, + TAccountFarmState extends string = string, + TAccountRewardMint extends string = string, + TAccountRewardVault extends string = string, + TAccountFarmVaultsAuthority extends string = string, + TAccountPayerRewardTokenAta extends string = string, + TAccountScopePrices extends string = string, + TAccountTokenProgram extends string = string, +> { + payer: TransactionSigner; + farmState: Address; + rewardMint: Address; + rewardVault?: Address; + farmVaultsAuthority?: Address; + payerRewardTokenAta: Address; + scopePrices?: Address; + tokenProgram?: Address; + amount: AddRewardsInstructionDataArgs["amount"]; + rewardIndex: AddRewardsInstructionDataArgs["rewardIndex"]; +} + +export async function getAddRewardsInstructionAsync< + TAccountPayer extends string, + TAccountFarmState extends string, + TAccountRewardMint extends string, + TAccountRewardVault extends string, + TAccountFarmVaultsAuthority extends string, + TAccountPayerRewardTokenAta extends string, + TAccountScopePrices extends string, + TAccountTokenProgram extends string, + TProgramAddress extends Address = typeof FARMS_PROGRAM_ADDRESS, +>( + input: AddRewardsAsyncInput< + TAccountPayer, + TAccountFarmState, + TAccountRewardMint, + TAccountRewardVault, + TAccountFarmVaultsAuthority, + TAccountPayerRewardTokenAta, + TAccountScopePrices, + TAccountTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + AddRewardsInstruction< + TProgramAddress, + TAccountPayer, + TAccountFarmState, + TAccountRewardMint, + TAccountRewardVault, + TAccountFarmVaultsAuthority, + TAccountPayerRewardTokenAta, + TAccountScopePrices, + TAccountTokenProgram + > +> { + // Program address. + const programAddress = config?.programAddress ?? FARMS_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + farmState: { value: input.farmState ?? null, isWritable: true }, + rewardMint: { value: input.rewardMint ?? null, isWritable: false }, + rewardVault: { value: input.rewardVault ?? null, isWritable: true }, + farmVaultsAuthority: { + value: input.farmVaultsAuthority ?? null, + isWritable: false, + }, + payerRewardTokenAta: { + value: input.payerRewardTokenAta ?? null, + isWritable: true, + }, + scopePrices: { value: input.scopePrices ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.rewardVault.value) { + accounts.rewardVault.value = await findRewardVaultPda({ + farmState: expectAddress(accounts.farmState.value), + rewardMint: expectAddress(accounts.rewardMint.value), + }); + } + if (!accounts.farmVaultsAuthority.value) { + accounts.farmVaultsAuthority.value = await findFarmVaultsAuthorityPda({ + farmState: expectAddress(accounts.farmState.value), + }); + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.farmState), + getAccountMeta(accounts.rewardMint), + getAccountMeta(accounts.rewardVault), + getAccountMeta(accounts.farmVaultsAuthority), + getAccountMeta(accounts.payerRewardTokenAta), + getAccountMeta(accounts.scopePrices), + getAccountMeta(accounts.tokenProgram), + ], + data: getAddRewardsInstructionDataEncoder().encode( + args as AddRewardsInstructionDataArgs, + ), + programAddress, + } as AddRewardsInstruction< + TProgramAddress, + TAccountPayer, + TAccountFarmState, + TAccountRewardMint, + TAccountRewardVault, + TAccountFarmVaultsAuthority, + TAccountPayerRewardTokenAta, + TAccountScopePrices, + TAccountTokenProgram + >); +} + export interface AddRewardsInput< TAccountPayer extends string = string, TAccountFarmState extends string = string, diff --git a/clients/kamino-lending/src/generated/instructions/borrowObligationLiquidity.ts b/clients/kamino-lending/src/generated/instructions/borrowObligationLiquidity.ts index fff672a8..f75e76df 100644 --- a/clients/kamino-lending/src/generated/instructions/borrowObligationLiquidity.ts +++ b/clients/kamino-lending/src/generated/instructions/borrowObligationLiquidity.ts @@ -35,8 +35,9 @@ import { getU64Encoder, transformEncoder, } from "@solana/kit"; +import { findLendingMarketAuthPda } from "../pdas/index.js"; import { KAMINO_LENDING_PROGRAM_ADDRESS } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const BORROW_OBLIGATION_LIQUIDITY_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([121, 127, 18, 204, 73, 245, 225, 65]); @@ -152,6 +153,182 @@ export function getBorrowObligationLiquidityInstructionDataCodec(): FixedSizeCod ); } +export interface BorrowObligationLiquidityAsyncInput< + TAccountOwner extends string = string, + TAccountObligation extends string = string, + TAccountLendingMarket extends string = string, + TAccountLendingMarketAuthority extends string = string, + TAccountBorrowReserve extends string = string, + TAccountBorrowReserveLiquidityMint extends string = string, + TAccountReserveSourceLiquidity extends string = string, + TAccountBorrowReserveLiquidityFeeReceiver extends string = string, + TAccountUserDestinationLiquidity extends string = string, + TAccountReferrerTokenState extends string = string, + TAccountTokenProgram extends string = string, + TAccountInstructionSysvarAccount extends string = string, +> { + owner: TransactionSigner; + obligation: Address; + lendingMarket: Address; + lendingMarketAuthority?: Address; + borrowReserve: Address; + borrowReserveLiquidityMint: Address; + reserveSourceLiquidity: Address; + borrowReserveLiquidityFeeReceiver: Address; + userDestinationLiquidity: Address; + referrerTokenState?: Address; + tokenProgram?: Address; + instructionSysvarAccount?: Address; + liquidityAmount: BorrowObligationLiquidityInstructionDataArgs["liquidityAmount"]; +} + +export async function getBorrowObligationLiquidityInstructionAsync< + TAccountOwner extends string, + TAccountObligation extends string, + TAccountLendingMarket extends string, + TAccountLendingMarketAuthority extends string, + TAccountBorrowReserve extends string, + TAccountBorrowReserveLiquidityMint extends string, + TAccountReserveSourceLiquidity extends string, + TAccountBorrowReserveLiquidityFeeReceiver extends string, + TAccountUserDestinationLiquidity extends string, + TAccountReferrerTokenState extends string, + TAccountTokenProgram extends string, + TAccountInstructionSysvarAccount extends string, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, +>( + input: BorrowObligationLiquidityAsyncInput< + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountBorrowReserve, + TAccountBorrowReserveLiquidityMint, + TAccountReserveSourceLiquidity, + TAccountBorrowReserveLiquidityFeeReceiver, + TAccountUserDestinationLiquidity, + TAccountReferrerTokenState, + TAccountTokenProgram, + TAccountInstructionSysvarAccount + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + BorrowObligationLiquidityInstruction< + TProgramAddress, + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountBorrowReserve, + TAccountBorrowReserveLiquidityMint, + TAccountReserveSourceLiquidity, + TAccountBorrowReserveLiquidityFeeReceiver, + TAccountUserDestinationLiquidity, + TAccountReferrerTokenState, + TAccountTokenProgram, + TAccountInstructionSysvarAccount + > +> { + // Program address. + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + owner: { value: input.owner ?? null, isWritable: false }, + obligation: { value: input.obligation ?? null, isWritable: true }, + lendingMarket: { value: input.lendingMarket ?? null, isWritable: false }, + lendingMarketAuthority: { + value: input.lendingMarketAuthority ?? null, + isWritable: false, + }, + borrowReserve: { value: input.borrowReserve ?? null, isWritable: true }, + borrowReserveLiquidityMint: { + value: input.borrowReserveLiquidityMint ?? null, + isWritable: false, + }, + reserveSourceLiquidity: { + value: input.reserveSourceLiquidity ?? null, + isWritable: true, + }, + borrowReserveLiquidityFeeReceiver: { + value: input.borrowReserveLiquidityFeeReceiver ?? null, + isWritable: true, + }, + userDestinationLiquidity: { + value: input.userDestinationLiquidity ?? null, + isWritable: true, + }, + referrerTokenState: { + value: input.referrerTokenState ?? null, + isWritable: true, + }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + instructionSysvarAccount: { + value: input.instructionSysvarAccount ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.lendingMarketAuthority.value) { + accounts.lendingMarketAuthority.value = await findLendingMarketAuthPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + }); + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.instructionSysvarAccount.value) { + accounts.instructionSysvarAccount.value = + "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.owner), + getAccountMeta(accounts.obligation), + getAccountMeta(accounts.lendingMarket), + getAccountMeta(accounts.lendingMarketAuthority), + getAccountMeta(accounts.borrowReserve), + getAccountMeta(accounts.borrowReserveLiquidityMint), + getAccountMeta(accounts.reserveSourceLiquidity), + getAccountMeta(accounts.borrowReserveLiquidityFeeReceiver), + getAccountMeta(accounts.userDestinationLiquidity), + getAccountMeta(accounts.referrerTokenState), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.instructionSysvarAccount), + ], + data: getBorrowObligationLiquidityInstructionDataEncoder().encode( + args as BorrowObligationLiquidityInstructionDataArgs, + ), + programAddress, + } as BorrowObligationLiquidityInstruction< + TProgramAddress, + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountBorrowReserve, + TAccountBorrowReserveLiquidityMint, + TAccountReserveSourceLiquidity, + TAccountBorrowReserveLiquidityFeeReceiver, + TAccountUserDestinationLiquidity, + TAccountReferrerTokenState, + TAccountTokenProgram, + TAccountInstructionSysvarAccount + >); +} + export interface BorrowObligationLiquidityInput< TAccountOwner extends string = string, TAccountObligation extends string = string, diff --git a/clients/kamino-lending/src/generated/instructions/borrowObligationLiquidityV2.ts b/clients/kamino-lending/src/generated/instructions/borrowObligationLiquidityV2.ts index d55750c1..30367672 100644 --- a/clients/kamino-lending/src/generated/instructions/borrowObligationLiquidityV2.ts +++ b/clients/kamino-lending/src/generated/instructions/borrowObligationLiquidityV2.ts @@ -35,11 +35,12 @@ import { getU64Encoder, transformEncoder, } from "@solana/kit"; +import { findLendingMarketAuthPda } from "../pdas/index.js"; import { FARMS_PROGRAM_ADDRESS, KAMINO_LENDING_PROGRAM_ADDRESS, } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const BORROW_OBLIGATION_LIQUIDITY_V2_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([161, 128, 143, 245, 171, 199, 194, 6]); @@ -169,6 +170,216 @@ export function getBorrowObligationLiquidityV2InstructionDataCodec(): FixedSizeC ); } +export interface BorrowObligationLiquidityV2AsyncInput< + TAccountOwner extends string = string, + TAccountObligation extends string = string, + TAccountLendingMarket extends string = string, + TAccountLendingMarketAuthority extends string = string, + TAccountBorrowReserve extends string = string, + TAccountBorrowReserveLiquidityMint extends string = string, + TAccountReserveSourceLiquidity extends string = string, + TAccountBorrowReserveLiquidityFeeReceiver extends string = string, + TAccountUserDestinationLiquidity extends string = string, + TAccountReferrerTokenState extends string = string, + TAccountTokenProgram extends string = string, + TAccountInstructionSysvarAccount extends string = string, + TAccountObligationFarmUserState extends string = string, + TAccountReserveFarmState extends string = string, + TAccountFarmsProgram extends string = string, +> { + owner: TransactionSigner; + obligation: Address; + lendingMarket: Address; + lendingMarketAuthority?: Address; + borrowReserve: Address; + borrowReserveLiquidityMint: Address; + reserveSourceLiquidity: Address; + borrowReserveLiquidityFeeReceiver: Address; + userDestinationLiquidity: Address; + referrerTokenState?: Address; + tokenProgram?: Address; + instructionSysvarAccount?: Address; + obligationFarmUserState?: Address; + reserveFarmState?: Address; + farmsProgram?: Address; + liquidityAmount: BorrowObligationLiquidityV2InstructionDataArgs["liquidityAmount"]; +} + +export async function getBorrowObligationLiquidityV2InstructionAsync< + TAccountOwner extends string, + TAccountObligation extends string, + TAccountLendingMarket extends string, + TAccountLendingMarketAuthority extends string, + TAccountBorrowReserve extends string, + TAccountBorrowReserveLiquidityMint extends string, + TAccountReserveSourceLiquidity extends string, + TAccountBorrowReserveLiquidityFeeReceiver extends string, + TAccountUserDestinationLiquidity extends string, + TAccountReferrerTokenState extends string, + TAccountTokenProgram extends string, + TAccountInstructionSysvarAccount extends string, + TAccountObligationFarmUserState extends string, + TAccountReserveFarmState extends string, + TAccountFarmsProgram extends string, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, +>( + input: BorrowObligationLiquidityV2AsyncInput< + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountBorrowReserve, + TAccountBorrowReserveLiquidityMint, + TAccountReserveSourceLiquidity, + TAccountBorrowReserveLiquidityFeeReceiver, + TAccountUserDestinationLiquidity, + TAccountReferrerTokenState, + TAccountTokenProgram, + TAccountInstructionSysvarAccount, + TAccountObligationFarmUserState, + TAccountReserveFarmState, + TAccountFarmsProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + BorrowObligationLiquidityV2Instruction< + TProgramAddress, + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountBorrowReserve, + TAccountBorrowReserveLiquidityMint, + TAccountReserveSourceLiquidity, + TAccountBorrowReserveLiquidityFeeReceiver, + TAccountUserDestinationLiquidity, + TAccountReferrerTokenState, + TAccountTokenProgram, + TAccountInstructionSysvarAccount, + TAccountObligationFarmUserState, + TAccountReserveFarmState, + TAccountFarmsProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + owner: { value: input.owner ?? null, isWritable: false }, + obligation: { value: input.obligation ?? null, isWritable: true }, + lendingMarket: { value: input.lendingMarket ?? null, isWritable: false }, + lendingMarketAuthority: { + value: input.lendingMarketAuthority ?? null, + isWritable: false, + }, + borrowReserve: { value: input.borrowReserve ?? null, isWritable: true }, + borrowReserveLiquidityMint: { + value: input.borrowReserveLiquidityMint ?? null, + isWritable: false, + }, + reserveSourceLiquidity: { + value: input.reserveSourceLiquidity ?? null, + isWritable: true, + }, + borrowReserveLiquidityFeeReceiver: { + value: input.borrowReserveLiquidityFeeReceiver ?? null, + isWritable: true, + }, + userDestinationLiquidity: { + value: input.userDestinationLiquidity ?? null, + isWritable: true, + }, + referrerTokenState: { + value: input.referrerTokenState ?? null, + isWritable: true, + }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + instructionSysvarAccount: { + value: input.instructionSysvarAccount ?? null, + isWritable: false, + }, + obligationFarmUserState: { + value: input.obligationFarmUserState ?? null, + isWritable: true, + }, + reserveFarmState: { + value: input.reserveFarmState ?? null, + isWritable: true, + }, + farmsProgram: { value: input.farmsProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.lendingMarketAuthority.value) { + accounts.lendingMarketAuthority.value = await findLendingMarketAuthPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + }); + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.instructionSysvarAccount.value) { + accounts.instructionSysvarAccount.value = + "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; + } + if (!accounts.farmsProgram.value) { + accounts.farmsProgram.value = FARMS_PROGRAM_ADDRESS; + accounts.farmsProgram.isWritable = false; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.owner), + getAccountMeta(accounts.obligation), + getAccountMeta(accounts.lendingMarket), + getAccountMeta(accounts.lendingMarketAuthority), + getAccountMeta(accounts.borrowReserve), + getAccountMeta(accounts.borrowReserveLiquidityMint), + getAccountMeta(accounts.reserveSourceLiquidity), + getAccountMeta(accounts.borrowReserveLiquidityFeeReceiver), + getAccountMeta(accounts.userDestinationLiquidity), + getAccountMeta(accounts.referrerTokenState), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.instructionSysvarAccount), + getAccountMeta(accounts.obligationFarmUserState), + getAccountMeta(accounts.reserveFarmState), + getAccountMeta(accounts.farmsProgram), + ], + data: getBorrowObligationLiquidityV2InstructionDataEncoder().encode( + args as BorrowObligationLiquidityV2InstructionDataArgs, + ), + programAddress, + } as BorrowObligationLiquidityV2Instruction< + TProgramAddress, + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountBorrowReserve, + TAccountBorrowReserveLiquidityMint, + TAccountReserveSourceLiquidity, + TAccountBorrowReserveLiquidityFeeReceiver, + TAccountUserDestinationLiquidity, + TAccountReferrerTokenState, + TAccountTokenProgram, + TAccountInstructionSysvarAccount, + TAccountObligationFarmUserState, + TAccountReserveFarmState, + TAccountFarmsProgram + >); +} + export interface BorrowObligationLiquidityV2Input< TAccountOwner extends string = string, TAccountObligation extends string = string, diff --git a/clients/kamino-lending/src/generated/instructions/depositAndWithdraw.ts b/clients/kamino-lending/src/generated/instructions/depositAndWithdraw.ts index d69515c0..4b2b81a2 100644 --- a/clients/kamino-lending/src/generated/instructions/depositAndWithdraw.ts +++ b/clients/kamino-lending/src/generated/instructions/depositAndWithdraw.ts @@ -85,7 +85,7 @@ export type DepositAndWithdrawInstruction< | AccountMeta = string, TAccountDepositAccountsInstructionSysvarAccount extends | string - | AccountMeta = "Sysvar1nstructions1111111111111111111111111", + | AccountMeta = string, TAccountWithdrawAccountsOwner extends string | AccountMeta = string, TAccountWithdrawAccountsObligation extends string | AccountMeta = string, TAccountWithdrawAccountsLendingMarket extends string | AccountMeta = string, @@ -119,7 +119,7 @@ export type DepositAndWithdrawInstruction< | AccountMeta = string, TAccountWithdrawAccountsInstructionSysvarAccount extends | string - | AccountMeta = "Sysvar1nstructions1111111111111111111111111", + | AccountMeta = string, TAccountDepositFarmsAccountsObligationFarmUserState extends | string | AccountMeta = string, @@ -339,7 +339,7 @@ export interface DepositAndWithdrawInput< depositAccountsPlaceholderUserDestinationCollateral?: Address; depositAccountsCollateralTokenProgram: Address; depositAccountsLiquidityTokenProgram: Address; - depositAccountsInstructionSysvarAccount?: Address; + depositAccountsInstructionSysvarAccount: Address; withdrawAccountsOwner: TransactionSigner; withdrawAccountsObligation: Address; withdrawAccountsLendingMarket: Address; @@ -353,7 +353,7 @@ export interface DepositAndWithdrawInput< withdrawAccountsPlaceholderUserDestinationCollateral?: Address; withdrawAccountsCollateralTokenProgram: Address; withdrawAccountsLiquidityTokenProgram: Address; - withdrawAccountsInstructionSysvarAccount?: Address; + withdrawAccountsInstructionSysvarAccount: Address; depositFarmsAccountsObligationFarmUserState?: Address; depositFarmsAccountsReserveFarmState?: Address; withdrawFarmsAccountsObligationFarmUserState?: Address; @@ -616,14 +616,6 @@ export function getDepositAndWithdrawInstruction< const args = { ...input }; // Resolve default values. - if (!accounts.depositAccountsInstructionSysvarAccount.value) { - accounts.depositAccountsInstructionSysvarAccount.value = - "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; - } - if (!accounts.withdrawAccountsInstructionSysvarAccount.value) { - accounts.withdrawAccountsInstructionSysvarAccount.value = - "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; - } if (!accounts.farmsProgram.value) { accounts.farmsProgram.value = FARMS_PROGRAM_ADDRESS; accounts.farmsProgram.isWritable = false; diff --git a/clients/kamino-lending/src/generated/instructions/depositObligationCollateralV2.ts b/clients/kamino-lending/src/generated/instructions/depositObligationCollateralV2.ts index abe6c607..5f0013f2 100644 --- a/clients/kamino-lending/src/generated/instructions/depositObligationCollateralV2.ts +++ b/clients/kamino-lending/src/generated/instructions/depositObligationCollateralV2.ts @@ -35,11 +35,12 @@ import { getU64Encoder, transformEncoder, } from "@solana/kit"; +import { findLendingMarketAuthPda } from "../pdas/index.js"; import { FARMS_PROGRAM_ADDRESS, KAMINO_LENDING_PROGRAM_ADDRESS, } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const DEPOSIT_OBLIGATION_COLLATERAL_V2_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([137, 145, 151, 94, 167, 113, 4, 145]); @@ -155,6 +156,183 @@ export function getDepositObligationCollateralV2InstructionDataCodec(): FixedSiz ); } +export interface DepositObligationCollateralV2AsyncInput< + TAccountOwner extends string = string, + TAccountObligation extends string = string, + TAccountLendingMarket extends string = string, + TAccountDepositReserve extends string = string, + TAccountReserveDestinationCollateral extends string = string, + TAccountUserSourceCollateral extends string = string, + TAccountTokenProgram extends string = string, + TAccountInstructionSysvarAccount extends string = string, + TAccountLendingMarketAuthority extends string = string, + TAccountObligationFarmUserState extends string = string, + TAccountReserveFarmState extends string = string, + TAccountFarmsProgram extends string = string, +> { + owner: TransactionSigner; + obligation: Address; + lendingMarket: Address; + depositReserve: Address; + reserveDestinationCollateral: Address; + userSourceCollateral: Address; + tokenProgram?: Address; + instructionSysvarAccount?: Address; + lendingMarketAuthority?: Address; + obligationFarmUserState?: Address; + reserveFarmState?: Address; + farmsProgram?: Address; + collateralAmount: DepositObligationCollateralV2InstructionDataArgs["collateralAmount"]; +} + +export async function getDepositObligationCollateralV2InstructionAsync< + TAccountOwner extends string, + TAccountObligation extends string, + TAccountLendingMarket extends string, + TAccountDepositReserve extends string, + TAccountReserveDestinationCollateral extends string, + TAccountUserSourceCollateral extends string, + TAccountTokenProgram extends string, + TAccountInstructionSysvarAccount extends string, + TAccountLendingMarketAuthority extends string, + TAccountObligationFarmUserState extends string, + TAccountReserveFarmState extends string, + TAccountFarmsProgram extends string, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, +>( + input: DepositObligationCollateralV2AsyncInput< + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountDepositReserve, + TAccountReserveDestinationCollateral, + TAccountUserSourceCollateral, + TAccountTokenProgram, + TAccountInstructionSysvarAccount, + TAccountLendingMarketAuthority, + TAccountObligationFarmUserState, + TAccountReserveFarmState, + TAccountFarmsProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + DepositObligationCollateralV2Instruction< + TProgramAddress, + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountDepositReserve, + TAccountReserveDestinationCollateral, + TAccountUserSourceCollateral, + TAccountTokenProgram, + TAccountInstructionSysvarAccount, + TAccountLendingMarketAuthority, + TAccountObligationFarmUserState, + TAccountReserveFarmState, + TAccountFarmsProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + owner: { value: input.owner ?? null, isWritable: false }, + obligation: { value: input.obligation ?? null, isWritable: true }, + lendingMarket: { value: input.lendingMarket ?? null, isWritable: false }, + depositReserve: { value: input.depositReserve ?? null, isWritable: true }, + reserveDestinationCollateral: { + value: input.reserveDestinationCollateral ?? null, + isWritable: true, + }, + userSourceCollateral: { + value: input.userSourceCollateral ?? null, + isWritable: true, + }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + instructionSysvarAccount: { + value: input.instructionSysvarAccount ?? null, + isWritable: false, + }, + lendingMarketAuthority: { + value: input.lendingMarketAuthority ?? null, + isWritable: false, + }, + obligationFarmUserState: { + value: input.obligationFarmUserState ?? null, + isWritable: true, + }, + reserveFarmState: { + value: input.reserveFarmState ?? null, + isWritable: true, + }, + farmsProgram: { value: input.farmsProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.instructionSysvarAccount.value) { + accounts.instructionSysvarAccount.value = + "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; + } + if (!accounts.lendingMarketAuthority.value) { + accounts.lendingMarketAuthority.value = await findLendingMarketAuthPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + }); + } + if (!accounts.farmsProgram.value) { + accounts.farmsProgram.value = FARMS_PROGRAM_ADDRESS; + accounts.farmsProgram.isWritable = false; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.owner), + getAccountMeta(accounts.obligation), + getAccountMeta(accounts.lendingMarket), + getAccountMeta(accounts.depositReserve), + getAccountMeta(accounts.reserveDestinationCollateral), + getAccountMeta(accounts.userSourceCollateral), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.instructionSysvarAccount), + getAccountMeta(accounts.lendingMarketAuthority), + getAccountMeta(accounts.obligationFarmUserState), + getAccountMeta(accounts.reserveFarmState), + getAccountMeta(accounts.farmsProgram), + ], + data: getDepositObligationCollateralV2InstructionDataEncoder().encode( + args as DepositObligationCollateralV2InstructionDataArgs, + ), + programAddress, + } as DepositObligationCollateralV2Instruction< + TProgramAddress, + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountDepositReserve, + TAccountReserveDestinationCollateral, + TAccountUserSourceCollateral, + TAccountTokenProgram, + TAccountInstructionSysvarAccount, + TAccountLendingMarketAuthority, + TAccountObligationFarmUserState, + TAccountReserveFarmState, + TAccountFarmsProgram + >); +} + export interface DepositObligationCollateralV2Input< TAccountOwner extends string = string, TAccountObligation extends string = string, diff --git a/clients/kamino-lending/src/generated/instructions/depositReserveLiquidity.ts b/clients/kamino-lending/src/generated/instructions/depositReserveLiquidity.ts index fc9e1855..ee1bf313 100644 --- a/clients/kamino-lending/src/generated/instructions/depositReserveLiquidity.ts +++ b/clients/kamino-lending/src/generated/instructions/depositReserveLiquidity.ts @@ -35,8 +35,13 @@ import { getU64Encoder, transformEncoder, } from "@solana/kit"; +import { + findLendingMarketAuthPda, + findReserveCollateralMintPda, + findReserveLiquiditySupplyPda, +} from "../pdas/index.js"; import { KAMINO_LENDING_PROGRAM_ADDRESS } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const DEPOSIT_RESERVE_LIQUIDITY_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([169, 201, 30, 126, 6, 205, 102, 68]); @@ -58,8 +63,12 @@ export type DepositReserveLiquidityInstruction< TAccountReserveCollateralMint extends string | AccountMeta = string, TAccountUserSourceLiquidity extends string | AccountMeta = string, TAccountUserDestinationCollateral extends string | AccountMeta = string, - TAccountCollateralTokenProgram extends string | AccountMeta = string, - TAccountLiquidityTokenProgram extends string | AccountMeta = string, + TAccountCollateralTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TAccountLiquidityTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", TAccountInstructionSysvarAccount extends | string | AccountMeta = "Sysvar1nstructions1111111111111111111111111", @@ -148,6 +157,206 @@ export function getDepositReserveLiquidityInstructionDataCodec(): FixedSizeCodec ); } +export interface DepositReserveLiquidityAsyncInput< + TAccountOwner extends string = string, + TAccountReserve extends string = string, + TAccountLendingMarket extends string = string, + TAccountLendingMarketAuthority extends string = string, + TAccountReserveLiquidityMint extends string = string, + TAccountReserveLiquiditySupply extends string = string, + TAccountReserveCollateralMint extends string = string, + TAccountUserSourceLiquidity extends string = string, + TAccountUserDestinationCollateral extends string = string, + TAccountCollateralTokenProgram extends string = string, + TAccountLiquidityTokenProgram extends string = string, + TAccountInstructionSysvarAccount extends string = string, +> { + owner: TransactionSigner; + reserve: Address; + lendingMarket: Address; + lendingMarketAuthority?: Address; + reserveLiquidityMint: Address; + reserveLiquiditySupply?: Address; + reserveCollateralMint?: Address; + userSourceLiquidity: Address; + userDestinationCollateral: Address; + collateralTokenProgram?: Address; + liquidityTokenProgram?: Address; + instructionSysvarAccount?: Address; + liquidityAmount: DepositReserveLiquidityInstructionDataArgs["liquidityAmount"]; +} + +export async function getDepositReserveLiquidityInstructionAsync< + TAccountOwner extends string, + TAccountReserve extends string, + TAccountLendingMarket extends string, + TAccountLendingMarketAuthority extends string, + TAccountReserveLiquidityMint extends string, + TAccountReserveLiquiditySupply extends string, + TAccountReserveCollateralMint extends string, + TAccountUserSourceLiquidity extends string, + TAccountUserDestinationCollateral extends string, + TAccountCollateralTokenProgram extends string, + TAccountLiquidityTokenProgram extends string, + TAccountInstructionSysvarAccount extends string, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, +>( + input: DepositReserveLiquidityAsyncInput< + TAccountOwner, + TAccountReserve, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountReserveLiquidityMint, + TAccountReserveLiquiditySupply, + TAccountReserveCollateralMint, + TAccountUserSourceLiquidity, + TAccountUserDestinationCollateral, + TAccountCollateralTokenProgram, + TAccountLiquidityTokenProgram, + TAccountInstructionSysvarAccount + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + DepositReserveLiquidityInstruction< + TProgramAddress, + TAccountOwner, + TAccountReserve, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountReserveLiquidityMint, + TAccountReserveLiquiditySupply, + TAccountReserveCollateralMint, + TAccountUserSourceLiquidity, + TAccountUserDestinationCollateral, + TAccountCollateralTokenProgram, + TAccountLiquidityTokenProgram, + TAccountInstructionSysvarAccount + > +> { + // Program address. + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + owner: { value: input.owner ?? null, isWritable: false }, + reserve: { value: input.reserve ?? null, isWritable: true }, + lendingMarket: { value: input.lendingMarket ?? null, isWritable: false }, + lendingMarketAuthority: { + value: input.lendingMarketAuthority ?? null, + isWritable: false, + }, + reserveLiquidityMint: { + value: input.reserveLiquidityMint ?? null, + isWritable: false, + }, + reserveLiquiditySupply: { + value: input.reserveLiquiditySupply ?? null, + isWritable: true, + }, + reserveCollateralMint: { + value: input.reserveCollateralMint ?? null, + isWritable: true, + }, + userSourceLiquidity: { + value: input.userSourceLiquidity ?? null, + isWritable: true, + }, + userDestinationCollateral: { + value: input.userDestinationCollateral ?? null, + isWritable: true, + }, + collateralTokenProgram: { + value: input.collateralTokenProgram ?? null, + isWritable: false, + }, + liquidityTokenProgram: { + value: input.liquidityTokenProgram ?? null, + isWritable: false, + }, + instructionSysvarAccount: { + value: input.instructionSysvarAccount ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.lendingMarketAuthority.value) { + accounts.lendingMarketAuthority.value = await findLendingMarketAuthPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + }); + } + if (!accounts.reserveLiquiditySupply.value) { + accounts.reserveLiquiditySupply.value = await findReserveLiquiditySupplyPda( + { + lendingMarket: expectAddress(accounts.lendingMarket.value), + mint: expectAddress(accounts.reserveLiquidityMint.value), + }, + ); + } + if (!accounts.reserveCollateralMint.value) { + accounts.reserveCollateralMint.value = await findReserveCollateralMintPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + mint: expectAddress(accounts.reserveLiquidityMint.value), + }); + } + if (!accounts.collateralTokenProgram.value) { + accounts.collateralTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.liquidityTokenProgram.value) { + accounts.liquidityTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.instructionSysvarAccount.value) { + accounts.instructionSysvarAccount.value = + "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.owner), + getAccountMeta(accounts.reserve), + getAccountMeta(accounts.lendingMarket), + getAccountMeta(accounts.lendingMarketAuthority), + getAccountMeta(accounts.reserveLiquidityMint), + getAccountMeta(accounts.reserveLiquiditySupply), + getAccountMeta(accounts.reserveCollateralMint), + getAccountMeta(accounts.userSourceLiquidity), + getAccountMeta(accounts.userDestinationCollateral), + getAccountMeta(accounts.collateralTokenProgram), + getAccountMeta(accounts.liquidityTokenProgram), + getAccountMeta(accounts.instructionSysvarAccount), + ], + data: getDepositReserveLiquidityInstructionDataEncoder().encode( + args as DepositReserveLiquidityInstructionDataArgs, + ), + programAddress, + } as DepositReserveLiquidityInstruction< + TProgramAddress, + TAccountOwner, + TAccountReserve, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountReserveLiquidityMint, + TAccountReserveLiquiditySupply, + TAccountReserveCollateralMint, + TAccountUserSourceLiquidity, + TAccountUserDestinationCollateral, + TAccountCollateralTokenProgram, + TAccountLiquidityTokenProgram, + TAccountInstructionSysvarAccount + >); +} + export interface DepositReserveLiquidityInput< TAccountOwner extends string = string, TAccountReserve extends string = string, @@ -171,8 +380,8 @@ export interface DepositReserveLiquidityInput< reserveCollateralMint: Address; userSourceLiquidity: Address; userDestinationCollateral: Address; - collateralTokenProgram: Address; - liquidityTokenProgram: Address; + collateralTokenProgram?: Address; + liquidityTokenProgram?: Address; instructionSysvarAccount?: Address; liquidityAmount: DepositReserveLiquidityInstructionDataArgs["liquidityAmount"]; } @@ -277,6 +486,14 @@ export function getDepositReserveLiquidityInstruction< const args = { ...input }; // Resolve default values. + if (!accounts.collateralTokenProgram.value) { + accounts.collateralTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.liquidityTokenProgram.value) { + accounts.liquidityTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } if (!accounts.instructionSysvarAccount.value) { accounts.instructionSysvarAccount.value = "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; diff --git a/clients/kamino-lending/src/generated/instructions/depositReserveLiquidityAndObligationCollateral.ts b/clients/kamino-lending/src/generated/instructions/depositReserveLiquidityAndObligationCollateral.ts index 791a09c4..216a1ade 100644 --- a/clients/kamino-lending/src/generated/instructions/depositReserveLiquidityAndObligationCollateral.ts +++ b/clients/kamino-lending/src/generated/instructions/depositReserveLiquidityAndObligationCollateral.ts @@ -35,8 +35,13 @@ import { getU64Encoder, transformEncoder, } from "@solana/kit"; +import { + findLendingMarketAuthPda, + findReserveCollateralMintPda, + findReserveLiquiditySupplyPda, +} from "../pdas/index.js"; import { KAMINO_LENDING_PROGRAM_ADDRESS } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const DEPOSIT_RESERVE_LIQUIDITY_AND_OBLIGATION_COLLATERAL_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([129, 199, 4, 2, 222, 39, 26, 46]); @@ -64,8 +69,12 @@ export type DepositReserveLiquidityAndObligationCollateralInstruction< TAccountPlaceholderUserDestinationCollateral extends | string | AccountMeta = string, - TAccountCollateralTokenProgram extends string | AccountMeta = string, - TAccountLiquidityTokenProgram extends string | AccountMeta = string, + TAccountCollateralTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TAccountLiquidityTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", TAccountInstructionSysvarAccount extends | string | AccountMeta = "Sysvar1nstructions1111111111111111111111111", @@ -161,6 +170,225 @@ export function getDepositReserveLiquidityAndObligationCollateralInstructionData ); } +export interface DepositReserveLiquidityAndObligationCollateralAsyncInput< + TAccountOwner extends string = string, + TAccountObligation extends string = string, + TAccountLendingMarket extends string = string, + TAccountLendingMarketAuthority extends string = string, + TAccountReserve extends string = string, + TAccountReserveLiquidityMint extends string = string, + TAccountReserveLiquiditySupply extends string = string, + TAccountReserveCollateralMint extends string = string, + TAccountReserveDestinationDepositCollateral extends string = string, + TAccountUserSourceLiquidity extends string = string, + TAccountPlaceholderUserDestinationCollateral extends string = string, + TAccountCollateralTokenProgram extends string = string, + TAccountLiquidityTokenProgram extends string = string, + TAccountInstructionSysvarAccount extends string = string, +> { + owner: TransactionSigner; + obligation: Address; + lendingMarket: Address; + lendingMarketAuthority?: Address; + reserve: Address; + reserveLiquidityMint: Address; + reserveLiquiditySupply?: Address; + reserveCollateralMint?: Address; + reserveDestinationDepositCollateral: Address; + userSourceLiquidity: Address; + placeholderUserDestinationCollateral?: Address; + collateralTokenProgram?: Address; + liquidityTokenProgram?: Address; + instructionSysvarAccount?: Address; + liquidityAmount: DepositReserveLiquidityAndObligationCollateralInstructionDataArgs["liquidityAmount"]; +} + +export async function getDepositReserveLiquidityAndObligationCollateralInstructionAsync< + TAccountOwner extends string, + TAccountObligation extends string, + TAccountLendingMarket extends string, + TAccountLendingMarketAuthority extends string, + TAccountReserve extends string, + TAccountReserveLiquidityMint extends string, + TAccountReserveLiquiditySupply extends string, + TAccountReserveCollateralMint extends string, + TAccountReserveDestinationDepositCollateral extends string, + TAccountUserSourceLiquidity extends string, + TAccountPlaceholderUserDestinationCollateral extends string, + TAccountCollateralTokenProgram extends string, + TAccountLiquidityTokenProgram extends string, + TAccountInstructionSysvarAccount extends string, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, +>( + input: DepositReserveLiquidityAndObligationCollateralAsyncInput< + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountReserve, + TAccountReserveLiquidityMint, + TAccountReserveLiquiditySupply, + TAccountReserveCollateralMint, + TAccountReserveDestinationDepositCollateral, + TAccountUserSourceLiquidity, + TAccountPlaceholderUserDestinationCollateral, + TAccountCollateralTokenProgram, + TAccountLiquidityTokenProgram, + TAccountInstructionSysvarAccount + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + DepositReserveLiquidityAndObligationCollateralInstruction< + TProgramAddress, + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountReserve, + TAccountReserveLiquidityMint, + TAccountReserveLiquiditySupply, + TAccountReserveCollateralMint, + TAccountReserveDestinationDepositCollateral, + TAccountUserSourceLiquidity, + TAccountPlaceholderUserDestinationCollateral, + TAccountCollateralTokenProgram, + TAccountLiquidityTokenProgram, + TAccountInstructionSysvarAccount + > +> { + // Program address. + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + owner: { value: input.owner ?? null, isWritable: true }, + obligation: { value: input.obligation ?? null, isWritable: true }, + lendingMarket: { value: input.lendingMarket ?? null, isWritable: false }, + lendingMarketAuthority: { + value: input.lendingMarketAuthority ?? null, + isWritable: false, + }, + reserve: { value: input.reserve ?? null, isWritable: true }, + reserveLiquidityMint: { + value: input.reserveLiquidityMint ?? null, + isWritable: false, + }, + reserveLiquiditySupply: { + value: input.reserveLiquiditySupply ?? null, + isWritable: true, + }, + reserveCollateralMint: { + value: input.reserveCollateralMint ?? null, + isWritable: true, + }, + reserveDestinationDepositCollateral: { + value: input.reserveDestinationDepositCollateral ?? null, + isWritable: true, + }, + userSourceLiquidity: { + value: input.userSourceLiquidity ?? null, + isWritable: true, + }, + placeholderUserDestinationCollateral: { + value: input.placeholderUserDestinationCollateral ?? null, + isWritable: false, + }, + collateralTokenProgram: { + value: input.collateralTokenProgram ?? null, + isWritable: false, + }, + liquidityTokenProgram: { + value: input.liquidityTokenProgram ?? null, + isWritable: false, + }, + instructionSysvarAccount: { + value: input.instructionSysvarAccount ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.lendingMarketAuthority.value) { + accounts.lendingMarketAuthority.value = await findLendingMarketAuthPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + }); + } + if (!accounts.reserveLiquiditySupply.value) { + accounts.reserveLiquiditySupply.value = await findReserveLiquiditySupplyPda( + { + lendingMarket: expectAddress(accounts.lendingMarket.value), + mint: expectAddress(accounts.reserveLiquidityMint.value), + }, + ); + } + if (!accounts.reserveCollateralMint.value) { + accounts.reserveCollateralMint.value = await findReserveCollateralMintPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + mint: expectAddress(accounts.reserveLiquidityMint.value), + }); + } + if (!accounts.collateralTokenProgram.value) { + accounts.collateralTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.liquidityTokenProgram.value) { + accounts.liquidityTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.instructionSysvarAccount.value) { + accounts.instructionSysvarAccount.value = + "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.owner), + getAccountMeta(accounts.obligation), + getAccountMeta(accounts.lendingMarket), + getAccountMeta(accounts.lendingMarketAuthority), + getAccountMeta(accounts.reserve), + getAccountMeta(accounts.reserveLiquidityMint), + getAccountMeta(accounts.reserveLiquiditySupply), + getAccountMeta(accounts.reserveCollateralMint), + getAccountMeta(accounts.reserveDestinationDepositCollateral), + getAccountMeta(accounts.userSourceLiquidity), + getAccountMeta(accounts.placeholderUserDestinationCollateral), + getAccountMeta(accounts.collateralTokenProgram), + getAccountMeta(accounts.liquidityTokenProgram), + getAccountMeta(accounts.instructionSysvarAccount), + ], + data: getDepositReserveLiquidityAndObligationCollateralInstructionDataEncoder().encode( + args as DepositReserveLiquidityAndObligationCollateralInstructionDataArgs, + ), + programAddress, + } as DepositReserveLiquidityAndObligationCollateralInstruction< + TProgramAddress, + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountReserve, + TAccountReserveLiquidityMint, + TAccountReserveLiquiditySupply, + TAccountReserveCollateralMint, + TAccountReserveDestinationDepositCollateral, + TAccountUserSourceLiquidity, + TAccountPlaceholderUserDestinationCollateral, + TAccountCollateralTokenProgram, + TAccountLiquidityTokenProgram, + TAccountInstructionSysvarAccount + >); +} + export interface DepositReserveLiquidityAndObligationCollateralInput< TAccountOwner extends string = string, TAccountObligation extends string = string, @@ -188,8 +416,8 @@ export interface DepositReserveLiquidityAndObligationCollateralInput< reserveDestinationDepositCollateral: Address; userSourceLiquidity: Address; placeholderUserDestinationCollateral?: Address; - collateralTokenProgram: Address; - liquidityTokenProgram: Address; + collateralTokenProgram?: Address; + liquidityTokenProgram?: Address; instructionSysvarAccount?: Address; liquidityAmount: DepositReserveLiquidityAndObligationCollateralInstructionDataArgs["liquidityAmount"]; } @@ -305,6 +533,14 @@ export function getDepositReserveLiquidityAndObligationCollateralInstruction< const args = { ...input }; // Resolve default values. + if (!accounts.collateralTokenProgram.value) { + accounts.collateralTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.liquidityTokenProgram.value) { + accounts.liquidityTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } if (!accounts.instructionSysvarAccount.value) { accounts.instructionSysvarAccount.value = "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; diff --git a/clients/kamino-lending/src/generated/instructions/depositReserveLiquidityAndObligationCollateralV2.ts b/clients/kamino-lending/src/generated/instructions/depositReserveLiquidityAndObligationCollateralV2.ts index defe9906..6941b904 100644 --- a/clients/kamino-lending/src/generated/instructions/depositReserveLiquidityAndObligationCollateralV2.ts +++ b/clients/kamino-lending/src/generated/instructions/depositReserveLiquidityAndObligationCollateralV2.ts @@ -35,11 +35,16 @@ import { getU64Encoder, transformEncoder, } from "@solana/kit"; +import { + findLendingMarketAuthPda, + findReserveCollateralMintPda, + findReserveLiquiditySupplyPda, +} from "../pdas/index.js"; import { FARMS_PROGRAM_ADDRESS, KAMINO_LENDING_PROGRAM_ADDRESS, } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const DEPOSIT_RESERVE_LIQUIDITY_AND_OBLIGATION_COLLATERAL_V2_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([216, 224, 191, 27, 204, 151, 102, 175]); @@ -67,8 +72,12 @@ export type DepositReserveLiquidityAndObligationCollateralV2Instruction< TAccountPlaceholderUserDestinationCollateral extends | string | AccountMeta = string, - TAccountCollateralTokenProgram extends string | AccountMeta = string, - TAccountLiquidityTokenProgram extends string | AccountMeta = string, + TAccountCollateralTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TAccountLiquidityTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", TAccountInstructionSysvarAccount extends | string | AccountMeta = "Sysvar1nstructions1111111111111111111111111", @@ -178,6 +187,259 @@ export function getDepositReserveLiquidityAndObligationCollateralV2InstructionDa ); } +export interface DepositReserveLiquidityAndObligationCollateralV2AsyncInput< + TAccountOwner extends string = string, + TAccountObligation extends string = string, + TAccountLendingMarket extends string = string, + TAccountLendingMarketAuthority extends string = string, + TAccountReserve extends string = string, + TAccountReserveLiquidityMint extends string = string, + TAccountReserveLiquiditySupply extends string = string, + TAccountReserveCollateralMint extends string = string, + TAccountReserveDestinationDepositCollateral extends string = string, + TAccountUserSourceLiquidity extends string = string, + TAccountPlaceholderUserDestinationCollateral extends string = string, + TAccountCollateralTokenProgram extends string = string, + TAccountLiquidityTokenProgram extends string = string, + TAccountInstructionSysvarAccount extends string = string, + TAccountObligationFarmUserState extends string = string, + TAccountReserveFarmState extends string = string, + TAccountFarmsProgram extends string = string, +> { + owner: TransactionSigner; + obligation: Address; + lendingMarket: Address; + lendingMarketAuthority?: Address; + reserve: Address; + reserveLiquidityMint: Address; + reserveLiquiditySupply?: Address; + reserveCollateralMint?: Address; + reserveDestinationDepositCollateral: Address; + userSourceLiquidity: Address; + placeholderUserDestinationCollateral?: Address; + collateralTokenProgram?: Address; + liquidityTokenProgram?: Address; + instructionSysvarAccount?: Address; + obligationFarmUserState?: Address; + reserveFarmState?: Address; + farmsProgram?: Address; + liquidityAmount: DepositReserveLiquidityAndObligationCollateralV2InstructionDataArgs["liquidityAmount"]; +} + +export async function getDepositReserveLiquidityAndObligationCollateralV2InstructionAsync< + TAccountOwner extends string, + TAccountObligation extends string, + TAccountLendingMarket extends string, + TAccountLendingMarketAuthority extends string, + TAccountReserve extends string, + TAccountReserveLiquidityMint extends string, + TAccountReserveLiquiditySupply extends string, + TAccountReserveCollateralMint extends string, + TAccountReserveDestinationDepositCollateral extends string, + TAccountUserSourceLiquidity extends string, + TAccountPlaceholderUserDestinationCollateral extends string, + TAccountCollateralTokenProgram extends string, + TAccountLiquidityTokenProgram extends string, + TAccountInstructionSysvarAccount extends string, + TAccountObligationFarmUserState extends string, + TAccountReserveFarmState extends string, + TAccountFarmsProgram extends string, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, +>( + input: DepositReserveLiquidityAndObligationCollateralV2AsyncInput< + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountReserve, + TAccountReserveLiquidityMint, + TAccountReserveLiquiditySupply, + TAccountReserveCollateralMint, + TAccountReserveDestinationDepositCollateral, + TAccountUserSourceLiquidity, + TAccountPlaceholderUserDestinationCollateral, + TAccountCollateralTokenProgram, + TAccountLiquidityTokenProgram, + TAccountInstructionSysvarAccount, + TAccountObligationFarmUserState, + TAccountReserveFarmState, + TAccountFarmsProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + DepositReserveLiquidityAndObligationCollateralV2Instruction< + TProgramAddress, + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountReserve, + TAccountReserveLiquidityMint, + TAccountReserveLiquiditySupply, + TAccountReserveCollateralMint, + TAccountReserveDestinationDepositCollateral, + TAccountUserSourceLiquidity, + TAccountPlaceholderUserDestinationCollateral, + TAccountCollateralTokenProgram, + TAccountLiquidityTokenProgram, + TAccountInstructionSysvarAccount, + TAccountObligationFarmUserState, + TAccountReserveFarmState, + TAccountFarmsProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + owner: { value: input.owner ?? null, isWritable: true }, + obligation: { value: input.obligation ?? null, isWritable: true }, + lendingMarket: { value: input.lendingMarket ?? null, isWritable: false }, + lendingMarketAuthority: { + value: input.lendingMarketAuthority ?? null, + isWritable: false, + }, + reserve: { value: input.reserve ?? null, isWritable: true }, + reserveLiquidityMint: { + value: input.reserveLiquidityMint ?? null, + isWritable: false, + }, + reserveLiquiditySupply: { + value: input.reserveLiquiditySupply ?? null, + isWritable: true, + }, + reserveCollateralMint: { + value: input.reserveCollateralMint ?? null, + isWritable: true, + }, + reserveDestinationDepositCollateral: { + value: input.reserveDestinationDepositCollateral ?? null, + isWritable: true, + }, + userSourceLiquidity: { + value: input.userSourceLiquidity ?? null, + isWritable: true, + }, + placeholderUserDestinationCollateral: { + value: input.placeholderUserDestinationCollateral ?? null, + isWritable: false, + }, + collateralTokenProgram: { + value: input.collateralTokenProgram ?? null, + isWritable: false, + }, + liquidityTokenProgram: { + value: input.liquidityTokenProgram ?? null, + isWritable: false, + }, + instructionSysvarAccount: { + value: input.instructionSysvarAccount ?? null, + isWritable: false, + }, + obligationFarmUserState: { + value: input.obligationFarmUserState ?? null, + isWritable: true, + }, + reserveFarmState: { + value: input.reserveFarmState ?? null, + isWritable: true, + }, + farmsProgram: { value: input.farmsProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.lendingMarketAuthority.value) { + accounts.lendingMarketAuthority.value = await findLendingMarketAuthPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + }); + } + if (!accounts.reserveLiquiditySupply.value) { + accounts.reserveLiquiditySupply.value = await findReserveLiquiditySupplyPda( + { + lendingMarket: expectAddress(accounts.lendingMarket.value), + mint: expectAddress(accounts.reserveLiquidityMint.value), + }, + ); + } + if (!accounts.reserveCollateralMint.value) { + accounts.reserveCollateralMint.value = await findReserveCollateralMintPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + mint: expectAddress(accounts.reserveLiquidityMint.value), + }); + } + if (!accounts.collateralTokenProgram.value) { + accounts.collateralTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.liquidityTokenProgram.value) { + accounts.liquidityTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.instructionSysvarAccount.value) { + accounts.instructionSysvarAccount.value = + "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; + } + if (!accounts.farmsProgram.value) { + accounts.farmsProgram.value = FARMS_PROGRAM_ADDRESS; + accounts.farmsProgram.isWritable = false; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.owner), + getAccountMeta(accounts.obligation), + getAccountMeta(accounts.lendingMarket), + getAccountMeta(accounts.lendingMarketAuthority), + getAccountMeta(accounts.reserve), + getAccountMeta(accounts.reserveLiquidityMint), + getAccountMeta(accounts.reserveLiquiditySupply), + getAccountMeta(accounts.reserveCollateralMint), + getAccountMeta(accounts.reserveDestinationDepositCollateral), + getAccountMeta(accounts.userSourceLiquidity), + getAccountMeta(accounts.placeholderUserDestinationCollateral), + getAccountMeta(accounts.collateralTokenProgram), + getAccountMeta(accounts.liquidityTokenProgram), + getAccountMeta(accounts.instructionSysvarAccount), + getAccountMeta(accounts.obligationFarmUserState), + getAccountMeta(accounts.reserveFarmState), + getAccountMeta(accounts.farmsProgram), + ], + data: getDepositReserveLiquidityAndObligationCollateralV2InstructionDataEncoder().encode( + args as DepositReserveLiquidityAndObligationCollateralV2InstructionDataArgs, + ), + programAddress, + } as DepositReserveLiquidityAndObligationCollateralV2Instruction< + TProgramAddress, + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountReserve, + TAccountReserveLiquidityMint, + TAccountReserveLiquiditySupply, + TAccountReserveCollateralMint, + TAccountReserveDestinationDepositCollateral, + TAccountUserSourceLiquidity, + TAccountPlaceholderUserDestinationCollateral, + TAccountCollateralTokenProgram, + TAccountLiquidityTokenProgram, + TAccountInstructionSysvarAccount, + TAccountObligationFarmUserState, + TAccountReserveFarmState, + TAccountFarmsProgram + >); +} + export interface DepositReserveLiquidityAndObligationCollateralV2Input< TAccountOwner extends string = string, TAccountObligation extends string = string, @@ -208,8 +470,8 @@ export interface DepositReserveLiquidityAndObligationCollateralV2Input< reserveDestinationDepositCollateral: Address; userSourceLiquidity: Address; placeholderUserDestinationCollateral?: Address; - collateralTokenProgram: Address; - liquidityTokenProgram: Address; + collateralTokenProgram?: Address; + liquidityTokenProgram?: Address; instructionSysvarAccount?: Address; obligationFarmUserState?: Address; reserveFarmState?: Address; @@ -346,6 +608,14 @@ export function getDepositReserveLiquidityAndObligationCollateralV2Instruction< const args = { ...input }; // Resolve default values. + if (!accounts.collateralTokenProgram.value) { + accounts.collateralTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.liquidityTokenProgram.value) { + accounts.liquidityTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } if (!accounts.instructionSysvarAccount.value) { accounts.instructionSysvarAccount.value = "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; diff --git a/clients/kamino-lending/src/generated/instructions/flashBorrowReserveLiquidity.ts b/clients/kamino-lending/src/generated/instructions/flashBorrowReserveLiquidity.ts index 0a411a38..09a452ad 100644 --- a/clients/kamino-lending/src/generated/instructions/flashBorrowReserveLiquidity.ts +++ b/clients/kamino-lending/src/generated/instructions/flashBorrowReserveLiquidity.ts @@ -35,8 +35,12 @@ import { getU64Encoder, transformEncoder, } from "@solana/kit"; +import { + findLendingMarketAuthPda, + findReserveFeeVaultPda, +} from "../pdas/index.js"; import { KAMINO_LENDING_PROGRAM_ADDRESS } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const FLASH_BORROW_RESERVE_LIQUIDITY_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([135, 231, 52, 167, 7, 52, 212, 193]); @@ -150,6 +154,188 @@ export function getFlashBorrowReserveLiquidityInstructionDataCodec(): FixedSizeC ); } +export interface FlashBorrowReserveLiquidityAsyncInput< + TAccountUserTransferAuthority extends string = string, + TAccountLendingMarketAuthority extends string = string, + TAccountLendingMarket extends string = string, + TAccountReserve extends string = string, + TAccountReserveLiquidityMint extends string = string, + TAccountReserveSourceLiquidity extends string = string, + TAccountUserDestinationLiquidity extends string = string, + TAccountReserveLiquidityFeeReceiver extends string = string, + TAccountReferrerTokenState extends string = string, + TAccountReferrerAccount extends string = string, + TAccountSysvarInfo extends string = string, + TAccountTokenProgram extends string = string, +> { + userTransferAuthority: TransactionSigner; + lendingMarketAuthority?: Address; + lendingMarket: Address; + reserve: Address; + reserveLiquidityMint: Address; + reserveSourceLiquidity: Address; + userDestinationLiquidity: Address; + reserveLiquidityFeeReceiver?: Address; + referrerTokenState?: Address; + referrerAccount?: Address; + sysvarInfo?: Address; + tokenProgram?: Address; + liquidityAmount: FlashBorrowReserveLiquidityInstructionDataArgs["liquidityAmount"]; +} + +export async function getFlashBorrowReserveLiquidityInstructionAsync< + TAccountUserTransferAuthority extends string, + TAccountLendingMarketAuthority extends string, + TAccountLendingMarket extends string, + TAccountReserve extends string, + TAccountReserveLiquidityMint extends string, + TAccountReserveSourceLiquidity extends string, + TAccountUserDestinationLiquidity extends string, + TAccountReserveLiquidityFeeReceiver extends string, + TAccountReferrerTokenState extends string, + TAccountReferrerAccount extends string, + TAccountSysvarInfo extends string, + TAccountTokenProgram extends string, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, +>( + input: FlashBorrowReserveLiquidityAsyncInput< + TAccountUserTransferAuthority, + TAccountLendingMarketAuthority, + TAccountLendingMarket, + TAccountReserve, + TAccountReserveLiquidityMint, + TAccountReserveSourceLiquidity, + TAccountUserDestinationLiquidity, + TAccountReserveLiquidityFeeReceiver, + TAccountReferrerTokenState, + TAccountReferrerAccount, + TAccountSysvarInfo, + TAccountTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + FlashBorrowReserveLiquidityInstruction< + TProgramAddress, + TAccountUserTransferAuthority, + TAccountLendingMarketAuthority, + TAccountLendingMarket, + TAccountReserve, + TAccountReserveLiquidityMint, + TAccountReserveSourceLiquidity, + TAccountUserDestinationLiquidity, + TAccountReserveLiquidityFeeReceiver, + TAccountReferrerTokenState, + TAccountReferrerAccount, + TAccountSysvarInfo, + TAccountTokenProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + userTransferAuthority: { + value: input.userTransferAuthority ?? null, + isWritable: false, + }, + lendingMarketAuthority: { + value: input.lendingMarketAuthority ?? null, + isWritable: false, + }, + lendingMarket: { value: input.lendingMarket ?? null, isWritable: false }, + reserve: { value: input.reserve ?? null, isWritable: true }, + reserveLiquidityMint: { + value: input.reserveLiquidityMint ?? null, + isWritable: false, + }, + reserveSourceLiquidity: { + value: input.reserveSourceLiquidity ?? null, + isWritable: true, + }, + userDestinationLiquidity: { + value: input.userDestinationLiquidity ?? null, + isWritable: true, + }, + reserveLiquidityFeeReceiver: { + value: input.reserveLiquidityFeeReceiver ?? null, + isWritable: true, + }, + referrerTokenState: { + value: input.referrerTokenState ?? null, + isWritable: true, + }, + referrerAccount: { value: input.referrerAccount ?? null, isWritable: true }, + sysvarInfo: { value: input.sysvarInfo ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.lendingMarketAuthority.value) { + accounts.lendingMarketAuthority.value = await findLendingMarketAuthPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + }); + } + if (!accounts.reserveLiquidityFeeReceiver.value) { + accounts.reserveLiquidityFeeReceiver.value = await findReserveFeeVaultPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + mint: expectAddress(accounts.reserveLiquidityMint.value), + }); + } + if (!accounts.sysvarInfo.value) { + accounts.sysvarInfo.value = + "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.userTransferAuthority), + getAccountMeta(accounts.lendingMarketAuthority), + getAccountMeta(accounts.lendingMarket), + getAccountMeta(accounts.reserve), + getAccountMeta(accounts.reserveLiquidityMint), + getAccountMeta(accounts.reserveSourceLiquidity), + getAccountMeta(accounts.userDestinationLiquidity), + getAccountMeta(accounts.reserveLiquidityFeeReceiver), + getAccountMeta(accounts.referrerTokenState), + getAccountMeta(accounts.referrerAccount), + getAccountMeta(accounts.sysvarInfo), + getAccountMeta(accounts.tokenProgram), + ], + data: getFlashBorrowReserveLiquidityInstructionDataEncoder().encode( + args as FlashBorrowReserveLiquidityInstructionDataArgs, + ), + programAddress, + } as FlashBorrowReserveLiquidityInstruction< + TProgramAddress, + TAccountUserTransferAuthority, + TAccountLendingMarketAuthority, + TAccountLendingMarket, + TAccountReserve, + TAccountReserveLiquidityMint, + TAccountReserveSourceLiquidity, + TAccountUserDestinationLiquidity, + TAccountReserveLiquidityFeeReceiver, + TAccountReferrerTokenState, + TAccountReferrerAccount, + TAccountSysvarInfo, + TAccountTokenProgram + >); +} + export interface FlashBorrowReserveLiquidityInput< TAccountUserTransferAuthority extends string = string, TAccountLendingMarketAuthority extends string = string, diff --git a/clients/kamino-lending/src/generated/instructions/flashRepayReserveLiquidity.ts b/clients/kamino-lending/src/generated/instructions/flashRepayReserveLiquidity.ts index 11bfd6b7..a26fe060 100644 --- a/clients/kamino-lending/src/generated/instructions/flashRepayReserveLiquidity.ts +++ b/clients/kamino-lending/src/generated/instructions/flashRepayReserveLiquidity.ts @@ -37,8 +37,12 @@ import { getU64Encoder, transformEncoder, } from "@solana/kit"; +import { + findLendingMarketAuthPda, + findReserveFeeVaultPda, +} from "../pdas/index.js"; import { KAMINO_LENDING_PROGRAM_ADDRESS } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const FLASH_REPAY_RESERVE_LIQUIDITY_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([185, 117, 0, 203, 96, 245, 180, 186]); @@ -156,6 +160,189 @@ export function getFlashRepayReserveLiquidityInstructionDataCodec(): FixedSizeCo ); } +export interface FlashRepayReserveLiquidityAsyncInput< + TAccountUserTransferAuthority extends string = string, + TAccountLendingMarketAuthority extends string = string, + TAccountLendingMarket extends string = string, + TAccountReserve extends string = string, + TAccountReserveLiquidityMint extends string = string, + TAccountReserveDestinationLiquidity extends string = string, + TAccountUserSourceLiquidity extends string = string, + TAccountReserveLiquidityFeeReceiver extends string = string, + TAccountReferrerTokenState extends string = string, + TAccountReferrerAccount extends string = string, + TAccountSysvarInfo extends string = string, + TAccountTokenProgram extends string = string, +> { + userTransferAuthority: TransactionSigner; + lendingMarketAuthority?: Address; + lendingMarket: Address; + reserve: Address; + reserveLiquidityMint: Address; + reserveDestinationLiquidity: Address; + userSourceLiquidity: Address; + reserveLiquidityFeeReceiver?: Address; + referrerTokenState?: Address; + referrerAccount?: Address; + sysvarInfo?: Address; + tokenProgram?: Address; + liquidityAmount: FlashRepayReserveLiquidityInstructionDataArgs["liquidityAmount"]; + borrowInstructionIndex: FlashRepayReserveLiquidityInstructionDataArgs["borrowInstructionIndex"]; +} + +export async function getFlashRepayReserveLiquidityInstructionAsync< + TAccountUserTransferAuthority extends string, + TAccountLendingMarketAuthority extends string, + TAccountLendingMarket extends string, + TAccountReserve extends string, + TAccountReserveLiquidityMint extends string, + TAccountReserveDestinationLiquidity extends string, + TAccountUserSourceLiquidity extends string, + TAccountReserveLiquidityFeeReceiver extends string, + TAccountReferrerTokenState extends string, + TAccountReferrerAccount extends string, + TAccountSysvarInfo extends string, + TAccountTokenProgram extends string, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, +>( + input: FlashRepayReserveLiquidityAsyncInput< + TAccountUserTransferAuthority, + TAccountLendingMarketAuthority, + TAccountLendingMarket, + TAccountReserve, + TAccountReserveLiquidityMint, + TAccountReserveDestinationLiquidity, + TAccountUserSourceLiquidity, + TAccountReserveLiquidityFeeReceiver, + TAccountReferrerTokenState, + TAccountReferrerAccount, + TAccountSysvarInfo, + TAccountTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + FlashRepayReserveLiquidityInstruction< + TProgramAddress, + TAccountUserTransferAuthority, + TAccountLendingMarketAuthority, + TAccountLendingMarket, + TAccountReserve, + TAccountReserveLiquidityMint, + TAccountReserveDestinationLiquidity, + TAccountUserSourceLiquidity, + TAccountReserveLiquidityFeeReceiver, + TAccountReferrerTokenState, + TAccountReferrerAccount, + TAccountSysvarInfo, + TAccountTokenProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + userTransferAuthority: { + value: input.userTransferAuthority ?? null, + isWritable: false, + }, + lendingMarketAuthority: { + value: input.lendingMarketAuthority ?? null, + isWritable: false, + }, + lendingMarket: { value: input.lendingMarket ?? null, isWritable: false }, + reserve: { value: input.reserve ?? null, isWritable: true }, + reserveLiquidityMint: { + value: input.reserveLiquidityMint ?? null, + isWritable: false, + }, + reserveDestinationLiquidity: { + value: input.reserveDestinationLiquidity ?? null, + isWritable: true, + }, + userSourceLiquidity: { + value: input.userSourceLiquidity ?? null, + isWritable: true, + }, + reserveLiquidityFeeReceiver: { + value: input.reserveLiquidityFeeReceiver ?? null, + isWritable: true, + }, + referrerTokenState: { + value: input.referrerTokenState ?? null, + isWritable: true, + }, + referrerAccount: { value: input.referrerAccount ?? null, isWritable: true }, + sysvarInfo: { value: input.sysvarInfo ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.lendingMarketAuthority.value) { + accounts.lendingMarketAuthority.value = await findLendingMarketAuthPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + }); + } + if (!accounts.reserveLiquidityFeeReceiver.value) { + accounts.reserveLiquidityFeeReceiver.value = await findReserveFeeVaultPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + mint: expectAddress(accounts.reserveLiquidityMint.value), + }); + } + if (!accounts.sysvarInfo.value) { + accounts.sysvarInfo.value = + "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.userTransferAuthority), + getAccountMeta(accounts.lendingMarketAuthority), + getAccountMeta(accounts.lendingMarket), + getAccountMeta(accounts.reserve), + getAccountMeta(accounts.reserveLiquidityMint), + getAccountMeta(accounts.reserveDestinationLiquidity), + getAccountMeta(accounts.userSourceLiquidity), + getAccountMeta(accounts.reserveLiquidityFeeReceiver), + getAccountMeta(accounts.referrerTokenState), + getAccountMeta(accounts.referrerAccount), + getAccountMeta(accounts.sysvarInfo), + getAccountMeta(accounts.tokenProgram), + ], + data: getFlashRepayReserveLiquidityInstructionDataEncoder().encode( + args as FlashRepayReserveLiquidityInstructionDataArgs, + ), + programAddress, + } as FlashRepayReserveLiquidityInstruction< + TProgramAddress, + TAccountUserTransferAuthority, + TAccountLendingMarketAuthority, + TAccountLendingMarket, + TAccountReserve, + TAccountReserveLiquidityMint, + TAccountReserveDestinationLiquidity, + TAccountUserSourceLiquidity, + TAccountReserveLiquidityFeeReceiver, + TAccountReferrerTokenState, + TAccountReferrerAccount, + TAccountSysvarInfo, + TAccountTokenProgram + >); +} + export interface FlashRepayReserveLiquidityInput< TAccountUserTransferAuthority extends string = string, TAccountLendingMarketAuthority extends string = string, diff --git a/clients/kamino-lending/src/generated/instructions/harvestReward.ts b/clients/kamino-lending/src/generated/instructions/harvestReward.ts index d1ecc653..02416df6 100644 --- a/clients/kamino-lending/src/generated/instructions/harvestReward.ts +++ b/clients/kamino-lending/src/generated/instructions/harvestReward.ts @@ -27,16 +27,24 @@ import { combineCodec, fixDecoderSize, fixEncoderSize, + getAddressEncoder, getBytesDecoder, getBytesEncoder, + getProgramDerivedAddress, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, transformEncoder, } from "@solana/kit"; +import { + findFarmsUserStatePda, + findFarmVaultsAuthorityPda, + findRewardTreasuryVaultPda, + findRewardVaultPda, +} from "../pdas/index.js"; import { FARMS_PROGRAM_ADDRESS } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const HARVEST_REWARD_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ 68, 200, 228, 233, 184, 32, 226, 188, @@ -142,6 +150,183 @@ export function getHarvestRewardInstructionDataCodec(): FixedSizeCodec< ); } +export interface HarvestRewardAsyncInput< + TAccountOwner extends string = string, + TAccountUserState extends string = string, + TAccountFarmState extends string = string, + TAccountGlobalConfig extends string = string, + TAccountRewardMint extends string = string, + TAccountUserRewardAta extends string = string, + TAccountRewardsVault extends string = string, + TAccountRewardsTreasuryVault extends string = string, + TAccountFarmVaultsAuthority extends string = string, + TAccountScopePrices extends string = string, + TAccountTokenProgram extends string = string, +> { + owner: TransactionSigner; + userState?: Address; + farmState: Address; + globalConfig: Address; + rewardMint: Address; + userRewardAta?: Address; + rewardsVault?: Address; + rewardsTreasuryVault?: Address; + farmVaultsAuthority?: Address; + scopePrices?: Address; + tokenProgram?: Address; + rewardIndex: HarvestRewardInstructionDataArgs["rewardIndex"]; +} + +export async function getHarvestRewardInstructionAsync< + TAccountOwner extends string, + TAccountUserState extends string, + TAccountFarmState extends string, + TAccountGlobalConfig extends string, + TAccountRewardMint extends string, + TAccountUserRewardAta extends string, + TAccountRewardsVault extends string, + TAccountRewardsTreasuryVault extends string, + TAccountFarmVaultsAuthority extends string, + TAccountScopePrices extends string, + TAccountTokenProgram extends string, + TProgramAddress extends Address = typeof FARMS_PROGRAM_ADDRESS, +>( + input: HarvestRewardAsyncInput< + TAccountOwner, + TAccountUserState, + TAccountFarmState, + TAccountGlobalConfig, + TAccountRewardMint, + TAccountUserRewardAta, + TAccountRewardsVault, + TAccountRewardsTreasuryVault, + TAccountFarmVaultsAuthority, + TAccountScopePrices, + TAccountTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + HarvestRewardInstruction< + TProgramAddress, + TAccountOwner, + TAccountUserState, + TAccountFarmState, + TAccountGlobalConfig, + TAccountRewardMint, + TAccountUserRewardAta, + TAccountRewardsVault, + TAccountRewardsTreasuryVault, + TAccountFarmVaultsAuthority, + TAccountScopePrices, + TAccountTokenProgram + > +> { + // Program address. + const programAddress = config?.programAddress ?? FARMS_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + owner: { value: input.owner ?? null, isWritable: true }, + userState: { value: input.userState ?? null, isWritable: true }, + farmState: { value: input.farmState ?? null, isWritable: true }, + globalConfig: { value: input.globalConfig ?? null, isWritable: false }, + rewardMint: { value: input.rewardMint ?? null, isWritable: false }, + userRewardAta: { value: input.userRewardAta ?? null, isWritable: true }, + rewardsVault: { value: input.rewardsVault ?? null, isWritable: true }, + rewardsTreasuryVault: { + value: input.rewardsTreasuryVault ?? null, + isWritable: true, + }, + farmVaultsAuthority: { + value: input.farmVaultsAuthority ?? null, + isWritable: false, + }, + scopePrices: { value: input.scopePrices ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.userState.value) { + accounts.userState.value = await findFarmsUserStatePda({ + farmState: expectAddress(accounts.farmState.value), + owner: expectAddress(accounts.owner.value), + }); + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.userRewardAta.value) { + accounts.userRewardAta.value = await getProgramDerivedAddress({ + programAddress: + "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL" as Address<"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL">, + seeds: [ + getAddressEncoder().encode(expectAddress(accounts.owner.value)), + getAddressEncoder().encode(expectAddress(accounts.tokenProgram.value)), + getAddressEncoder().encode(expectAddress(accounts.rewardMint.value)), + ], + }); + } + if (!accounts.rewardsVault.value) { + accounts.rewardsVault.value = await findRewardVaultPda({ + farmState: expectAddress(accounts.farmState.value), + rewardMint: expectAddress(accounts.rewardMint.value), + }); + } + if (!accounts.rewardsTreasuryVault.value) { + accounts.rewardsTreasuryVault.value = await findRewardTreasuryVaultPda({ + globalConfig: expectAddress(accounts.globalConfig.value), + rewardMint: expectAddress(accounts.rewardMint.value), + }); + } + if (!accounts.farmVaultsAuthority.value) { + accounts.farmVaultsAuthority.value = await findFarmVaultsAuthorityPda({ + farmState: expectAddress(accounts.farmState.value), + }); + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.owner), + getAccountMeta(accounts.userState), + getAccountMeta(accounts.farmState), + getAccountMeta(accounts.globalConfig), + getAccountMeta(accounts.rewardMint), + getAccountMeta(accounts.userRewardAta), + getAccountMeta(accounts.rewardsVault), + getAccountMeta(accounts.rewardsTreasuryVault), + getAccountMeta(accounts.farmVaultsAuthority), + getAccountMeta(accounts.scopePrices), + getAccountMeta(accounts.tokenProgram), + ], + data: getHarvestRewardInstructionDataEncoder().encode( + args as HarvestRewardInstructionDataArgs, + ), + programAddress, + } as HarvestRewardInstruction< + TProgramAddress, + TAccountOwner, + TAccountUserState, + TAccountFarmState, + TAccountGlobalConfig, + TAccountRewardMint, + TAccountUserRewardAta, + TAccountRewardsVault, + TAccountRewardsTreasuryVault, + TAccountFarmVaultsAuthority, + TAccountScopePrices, + TAccountTokenProgram + >); +} + export interface HarvestRewardInput< TAccountOwner extends string = string, TAccountUserState extends string = string, diff --git a/clients/kamino-lending/src/generated/instructions/idlMissingTypes.ts b/clients/kamino-lending/src/generated/instructions/idlMissingTypes.ts index e7b43d02..fb24152e 100644 --- a/clients/kamino-lending/src/generated/instructions/idlMissingTypes.ts +++ b/clients/kamino-lending/src/generated/instructions/idlMissingTypes.ts @@ -79,7 +79,8 @@ export function getIdlMissingTypesDiscriminatorBytes(): ReadonlyUint8Array { export type IdlMissingTypesInstruction< TProgram extends string = typeof KAMINO_LENDING_PROGRAM_ADDRESS, - TAccountLendingMarketOwner extends string | AccountMeta = string, + TAccountSigner extends string | AccountMeta = string, + TAccountGlobalConfig extends string | AccountMeta = string, TAccountLendingMarket extends string | AccountMeta = string, TAccountReserve extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], @@ -87,10 +88,13 @@ export type IdlMissingTypesInstruction< InstructionWithData & InstructionWithAccounts< [ - TAccountLendingMarketOwner extends string - ? ReadonlySignerAccount & - AccountSignerMeta - : TAccountLendingMarketOwner, + TAccountSigner extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountSigner, + TAccountGlobalConfig extends string + ? ReadonlyAccount + : TAccountGlobalConfig, TAccountLendingMarket extends string ? ReadonlyAccount : TAccountLendingMarket, @@ -168,11 +172,13 @@ export function getIdlMissingTypesInstructionDataCodec(): Codec< } export interface IdlMissingTypesInput< - TAccountLendingMarketOwner extends string = string, + TAccountSigner extends string = string, + TAccountGlobalConfig extends string = string, TAccountLendingMarket extends string = string, TAccountReserve extends string = string, > { - lendingMarketOwner: TransactionSigner; + signer: TransactionSigner; + globalConfig: Address; lendingMarket: Address; reserve: Address; reserveFarmKind: IdlMissingTypesInstructionDataArgs["reserveFarmKind"]; @@ -185,20 +191,23 @@ export interface IdlMissingTypesInput< } export function getIdlMissingTypesInstruction< - TAccountLendingMarketOwner extends string, + TAccountSigner extends string, + TAccountGlobalConfig extends string, TAccountLendingMarket extends string, TAccountReserve extends string, TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, >( input: IdlMissingTypesInput< - TAccountLendingMarketOwner, + TAccountSigner, + TAccountGlobalConfig, TAccountLendingMarket, TAccountReserve >, config?: { programAddress?: TProgramAddress }, ): IdlMissingTypesInstruction< TProgramAddress, - TAccountLendingMarketOwner, + TAccountSigner, + TAccountGlobalConfig, TAccountLendingMarket, TAccountReserve > { @@ -208,10 +217,8 @@ export function getIdlMissingTypesInstruction< // Original accounts. const originalAccounts = { - lendingMarketOwner: { - value: input.lendingMarketOwner ?? null, - isWritable: false, - }, + signer: { value: input.signer ?? null, isWritable: false }, + globalConfig: { value: input.globalConfig ?? null, isWritable: false }, lendingMarket: { value: input.lendingMarket ?? null, isWritable: false }, reserve: { value: input.reserve ?? null, isWritable: true }, }; @@ -226,7 +233,8 @@ export function getIdlMissingTypesInstruction< const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ - getAccountMeta(accounts.lendingMarketOwner), + getAccountMeta(accounts.signer), + getAccountMeta(accounts.globalConfig), getAccountMeta(accounts.lendingMarket), getAccountMeta(accounts.reserve), ], @@ -236,7 +244,8 @@ export function getIdlMissingTypesInstruction< programAddress, } as IdlMissingTypesInstruction< TProgramAddress, - TAccountLendingMarketOwner, + TAccountSigner, + TAccountGlobalConfig, TAccountLendingMarket, TAccountReserve >); @@ -248,9 +257,10 @@ export interface ParsedIdlMissingTypesInstruction< > { programAddress: Address; accounts: { - lendingMarketOwner: TAccountMetas[0]; - lendingMarket: TAccountMetas[1]; - reserve: TAccountMetas[2]; + signer: TAccountMetas[0]; + globalConfig: TAccountMetas[1]; + lendingMarket: TAccountMetas[2]; + reserve: TAccountMetas[3]; }; data: IdlMissingTypesInstructionData; } @@ -263,7 +273,7 @@ export function parseIdlMissingTypesInstruction< InstructionWithAccounts & InstructionWithData, ): ParsedIdlMissingTypesInstruction { - if (instruction.accounts.length < 3) { + if (instruction.accounts.length < 4) { // TODO: Coded error. throw new Error("Not enough accounts"); } @@ -276,7 +286,8 @@ export function parseIdlMissingTypesInstruction< return { programAddress: instruction.programAddress, accounts: { - lendingMarketOwner: getNextAccount(), + signer: getNextAccount(), + globalConfig: getNextAccount(), lendingMarket: getNextAccount(), reserve: getNextAccount(), }, diff --git a/clients/kamino-lending/src/generated/instructions/index.ts b/clients/kamino-lending/src/generated/instructions/index.ts index 75c7aa38..c6f8a4a6 100644 --- a/clients/kamino-lending/src/generated/instructions/index.ts +++ b/clients/kamino-lending/src/generated/instructions/index.ts @@ -23,6 +23,7 @@ export * from "./flashRepayReserveLiquidity.js"; export * from "./harvestReward.js"; export * from "./idlMissingTypes.js"; export * from "./initFarmsForReserve.js"; +export * from "./initGlobalConfig.js"; export * from "./initializeFarm.js"; export * from "./initializeFarmDelegated.js"; export * from "./initializeGlobalConfig.js"; @@ -51,6 +52,7 @@ export * from "./repayObligationLiquidity.js"; export * from "./repayObligationLiquidityV2.js"; export * from "./requestElevationGroup.js"; export * from "./rewardUserOnce.js"; +export * from "./setObligationOrder.js"; export * from "./setStakeDelegated.js"; export * from "./socializeLoss.js"; export * from "./socializeLossV2.js"; @@ -60,6 +62,8 @@ export * from "./unstake.js"; export * from "./updateFarmAdmin.js"; export * from "./updateFarmConfig.js"; export * from "./updateGlobalConfig.js"; +export * from "./updateGlobalConfig.js"; +export * from "./updateGlobalConfigAdmin.js"; export * from "./updateGlobalConfigAdmin.js"; export * from "./updateLendingMarket.js"; export * from "./updateLendingMarketOwner.js"; diff --git a/clients/kamino-lending/src/generated/instructions/initFarmsForReserve.ts b/clients/kamino-lending/src/generated/instructions/initFarmsForReserve.ts index ab526d54..18f5278d 100644 --- a/clients/kamino-lending/src/generated/instructions/initFarmsForReserve.ts +++ b/clients/kamino-lending/src/generated/instructions/initFarmsForReserve.ts @@ -35,11 +35,12 @@ import { getU8Encoder, transformEncoder, } from "@solana/kit"; +import { findLendingMarketAuthPda } from "../pdas/index.js"; import { FARMS_PROGRAM_ADDRESS, KAMINO_LENDING_PROGRAM_ADDRESS, } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const INIT_FARMS_FOR_RESERVE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([218, 6, 62, 233, 1, 33, 232, 82]); @@ -147,6 +148,161 @@ export function getInitFarmsForReserveInstructionDataCodec(): FixedSizeCodec< ); } +export interface InitFarmsForReserveAsyncInput< + TAccountLendingMarketOwner extends string = string, + TAccountLendingMarket extends string = string, + TAccountLendingMarketAuthority extends string = string, + TAccountReserve extends string = string, + TAccountFarmsProgram extends string = string, + TAccountFarmsGlobalConfig extends string = string, + TAccountFarmState extends string = string, + TAccountFarmsVaultAuthority extends string = string, + TAccountRent extends string = string, + TAccountSystemProgram extends string = string, +> { + lendingMarketOwner: TransactionSigner; + lendingMarket: Address; + lendingMarketAuthority?: Address; + reserve: Address; + farmsProgram?: Address; + farmsGlobalConfig: Address; + farmState: Address; + farmsVaultAuthority: Address; + rent?: Address; + systemProgram?: Address; + mode: InitFarmsForReserveInstructionDataArgs["mode"]; +} + +export async function getInitFarmsForReserveInstructionAsync< + TAccountLendingMarketOwner extends string, + TAccountLendingMarket extends string, + TAccountLendingMarketAuthority extends string, + TAccountReserve extends string, + TAccountFarmsProgram extends string, + TAccountFarmsGlobalConfig extends string, + TAccountFarmState extends string, + TAccountFarmsVaultAuthority extends string, + TAccountRent extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, +>( + input: InitFarmsForReserveAsyncInput< + TAccountLendingMarketOwner, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountReserve, + TAccountFarmsProgram, + TAccountFarmsGlobalConfig, + TAccountFarmState, + TAccountFarmsVaultAuthority, + TAccountRent, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + InitFarmsForReserveInstruction< + TProgramAddress, + TAccountLendingMarketOwner, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountReserve, + TAccountFarmsProgram, + TAccountFarmsGlobalConfig, + TAccountFarmState, + TAccountFarmsVaultAuthority, + TAccountRent, + TAccountSystemProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + lendingMarketOwner: { + value: input.lendingMarketOwner ?? null, + isWritable: true, + }, + lendingMarket: { value: input.lendingMarket ?? null, isWritable: false }, + lendingMarketAuthority: { + value: input.lendingMarketAuthority ?? null, + isWritable: false, + }, + reserve: { value: input.reserve ?? null, isWritable: true }, + farmsProgram: { value: input.farmsProgram ?? null, isWritable: false }, + farmsGlobalConfig: { + value: input.farmsGlobalConfig ?? null, + isWritable: false, + }, + farmState: { value: input.farmState ?? null, isWritable: true }, + farmsVaultAuthority: { + value: input.farmsVaultAuthority ?? null, + isWritable: false, + }, + rent: { value: input.rent ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.lendingMarketAuthority.value) { + accounts.lendingMarketAuthority.value = await findLendingMarketAuthPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + }); + } + if (!accounts.farmsProgram.value) { + accounts.farmsProgram.value = FARMS_PROGRAM_ADDRESS; + accounts.farmsProgram.isWritable = false; + } + if (!accounts.rent.value) { + accounts.rent.value = + "SysvarRent111111111111111111111111111111111" as Address<"SysvarRent111111111111111111111111111111111">; + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.lendingMarketOwner), + getAccountMeta(accounts.lendingMarket), + getAccountMeta(accounts.lendingMarketAuthority), + getAccountMeta(accounts.reserve), + getAccountMeta(accounts.farmsProgram), + getAccountMeta(accounts.farmsGlobalConfig), + getAccountMeta(accounts.farmState), + getAccountMeta(accounts.farmsVaultAuthority), + getAccountMeta(accounts.rent), + getAccountMeta(accounts.systemProgram), + ], + data: getInitFarmsForReserveInstructionDataEncoder().encode( + args as InitFarmsForReserveInstructionDataArgs, + ), + programAddress, + } as InitFarmsForReserveInstruction< + TProgramAddress, + TAccountLendingMarketOwner, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountReserve, + TAccountFarmsProgram, + TAccountFarmsGlobalConfig, + TAccountFarmState, + TAccountFarmsVaultAuthority, + TAccountRent, + TAccountSystemProgram + >); +} + export interface InitFarmsForReserveInput< TAccountLendingMarketOwner extends string = string, TAccountLendingMarket extends string = string, diff --git a/clients/kamino-lending/src/generated/instructions/initGlobalConfig.ts b/clients/kamino-lending/src/generated/instructions/initGlobalConfig.ts new file mode 100644 index 00000000..25e687ed --- /dev/null +++ b/clients/kamino-lending/src/generated/instructions/initGlobalConfig.ts @@ -0,0 +1,335 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, + WritableSignerAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { findLendingGlobalConfigStatePda } from "../pdas/index.js"; +import { KAMINO_LENDING_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const INIT_GLOBAL_CONFIG_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([140, 136, 214, 48, 87, 0, 120, 255]); + +export function getInitGlobalConfigDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + INIT_GLOBAL_CONFIG_DISCRIMINATOR, + ); +} + +export type InitGlobalConfigInstruction< + TProgram extends string = typeof KAMINO_LENDING_PROGRAM_ADDRESS, + TAccountPayer extends string | AccountMeta = string, + TAccountGlobalConfig extends string | AccountMeta = string, + TAccountProgramData extends string | AccountMeta = string, + TAccountSystemProgram extends + | string + | AccountMeta = "11111111111111111111111111111111", + TAccountRent extends + | string + | AccountMeta = "SysvarRent111111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountGlobalConfig extends string + ? WritableAccount + : TAccountGlobalConfig, + TAccountProgramData extends string + ? ReadonlyAccount + : TAccountProgramData, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + TAccountRent extends string + ? ReadonlyAccount + : TAccountRent, + ...TRemainingAccounts, + ] + >; + +export interface InitGlobalConfigInstructionData { + discriminator: ReadonlyUint8Array; +} + +export interface InitGlobalConfigInstructionDataArgs {} + +export function getInitGlobalConfigInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), + (value) => ({ ...value, discriminator: INIT_GLOBAL_CONFIG_DISCRIMINATOR }), + ); +} + +export function getInitGlobalConfigInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ]); +} + +export function getInitGlobalConfigInstructionDataCodec(): FixedSizeCodec< + InitGlobalConfigInstructionDataArgs, + InitGlobalConfigInstructionData +> { + return combineCodec( + getInitGlobalConfigInstructionDataEncoder(), + getInitGlobalConfigInstructionDataDecoder(), + ); +} + +export interface InitGlobalConfigAsyncInput< + TAccountPayer extends string = string, + TAccountGlobalConfig extends string = string, + TAccountProgramData extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, +> { + payer: TransactionSigner; + globalConfig?: Address; + programData: Address; + systemProgram?: Address; + rent?: Address; +} + +export async function getInitGlobalConfigInstructionAsync< + TAccountPayer extends string, + TAccountGlobalConfig extends string, + TAccountProgramData extends string, + TAccountSystemProgram extends string, + TAccountRent extends string, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, +>( + input: InitGlobalConfigAsyncInput< + TAccountPayer, + TAccountGlobalConfig, + TAccountProgramData, + TAccountSystemProgram, + TAccountRent + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + InitGlobalConfigInstruction< + TProgramAddress, + TAccountPayer, + TAccountGlobalConfig, + TAccountProgramData, + TAccountSystemProgram, + TAccountRent + > +> { + // Program address. + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + globalConfig: { value: input.globalConfig ?? null, isWritable: true }, + programData: { value: input.programData ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + rent: { value: input.rent ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.globalConfig.value) { + accounts.globalConfig.value = await findLendingGlobalConfigStatePda(); + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + if (!accounts.rent.value) { + accounts.rent.value = + "SysvarRent111111111111111111111111111111111" as Address<"SysvarRent111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.globalConfig), + getAccountMeta(accounts.programData), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), + ], + data: getInitGlobalConfigInstructionDataEncoder().encode({}), + programAddress, + } as InitGlobalConfigInstruction< + TProgramAddress, + TAccountPayer, + TAccountGlobalConfig, + TAccountProgramData, + TAccountSystemProgram, + TAccountRent + >); +} + +export interface InitGlobalConfigInput< + TAccountPayer extends string = string, + TAccountGlobalConfig extends string = string, + TAccountProgramData extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, +> { + payer: TransactionSigner; + globalConfig: Address; + programData: Address; + systemProgram?: Address; + rent?: Address; +} + +export function getInitGlobalConfigInstruction< + TAccountPayer extends string, + TAccountGlobalConfig extends string, + TAccountProgramData extends string, + TAccountSystemProgram extends string, + TAccountRent extends string, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, +>( + input: InitGlobalConfigInput< + TAccountPayer, + TAccountGlobalConfig, + TAccountProgramData, + TAccountSystemProgram, + TAccountRent + >, + config?: { programAddress?: TProgramAddress }, +): InitGlobalConfigInstruction< + TProgramAddress, + TAccountPayer, + TAccountGlobalConfig, + TAccountProgramData, + TAccountSystemProgram, + TAccountRent +> { + // Program address. + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + globalConfig: { value: input.globalConfig ?? null, isWritable: true }, + programData: { value: input.programData ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + rent: { value: input.rent ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + if (!accounts.rent.value) { + accounts.rent.value = + "SysvarRent111111111111111111111111111111111" as Address<"SysvarRent111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.globalConfig), + getAccountMeta(accounts.programData), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), + ], + data: getInitGlobalConfigInstructionDataEncoder().encode({}), + programAddress, + } as InitGlobalConfigInstruction< + TProgramAddress, + TAccountPayer, + TAccountGlobalConfig, + TAccountProgramData, + TAccountSystemProgram, + TAccountRent + >); +} + +export interface ParsedInitGlobalConfigInstruction< + TProgram extends string = typeof KAMINO_LENDING_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + payer: TAccountMetas[0]; + globalConfig: TAccountMetas[1]; + programData: TAccountMetas[2]; + systemProgram: TAccountMetas[3]; + rent: TAccountMetas[4]; + }; + data: InitGlobalConfigInstructionData; +} + +export function parseInitGlobalConfigInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedInitGlobalConfigInstruction { + if (instruction.accounts.length < 5) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + payer: getNextAccount(), + globalConfig: getNextAccount(), + programData: getNextAccount(), + systemProgram: getNextAccount(), + rent: getNextAccount(), + }, + data: getInitGlobalConfigInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/kamino-lending/src/generated/instructions/initLendingMarket.ts b/clients/kamino-lending/src/generated/instructions/initLendingMarket.ts index be064b6b..a8ef47f3 100644 --- a/clients/kamino-lending/src/generated/instructions/initLendingMarket.ts +++ b/clients/kamino-lending/src/generated/instructions/initLendingMarket.ts @@ -37,8 +37,9 @@ import { getU8Encoder, transformEncoder, } from "@solana/kit"; +import { findLendingMarketAuthPda } from "../pdas/index.js"; import { KAMINO_LENDING_PROGRAM_ADDRESS } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const INIT_LENDING_MARKET_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([34, 162, 116, 14, 101, 137, 94, 239]); @@ -121,6 +122,111 @@ export function getInitLendingMarketInstructionDataCodec(): FixedSizeCodec< ); } +export interface InitLendingMarketAsyncInput< + TAccountLendingMarketOwner extends string = string, + TAccountLendingMarket extends string = string, + TAccountLendingMarketAuthority extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, +> { + lendingMarketOwner: TransactionSigner; + lendingMarket: Address; + lendingMarketAuthority?: Address; + systemProgram?: Address; + rent?: Address; + quoteCurrency: InitLendingMarketInstructionDataArgs["quoteCurrency"]; +} + +export async function getInitLendingMarketInstructionAsync< + TAccountLendingMarketOwner extends string, + TAccountLendingMarket extends string, + TAccountLendingMarketAuthority extends string, + TAccountSystemProgram extends string, + TAccountRent extends string, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, +>( + input: InitLendingMarketAsyncInput< + TAccountLendingMarketOwner, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountSystemProgram, + TAccountRent + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + InitLendingMarketInstruction< + TProgramAddress, + TAccountLendingMarketOwner, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountSystemProgram, + TAccountRent + > +> { + // Program address. + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + lendingMarketOwner: { + value: input.lendingMarketOwner ?? null, + isWritable: true, + }, + lendingMarket: { value: input.lendingMarket ?? null, isWritable: true }, + lendingMarketAuthority: { + value: input.lendingMarketAuthority ?? null, + isWritable: false, + }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + rent: { value: input.rent ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.lendingMarketAuthority.value) { + accounts.lendingMarketAuthority.value = await findLendingMarketAuthPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + }); + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + if (!accounts.rent.value) { + accounts.rent.value = + "SysvarRent111111111111111111111111111111111" as Address<"SysvarRent111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.lendingMarketOwner), + getAccountMeta(accounts.lendingMarket), + getAccountMeta(accounts.lendingMarketAuthority), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), + ], + data: getInitLendingMarketInstructionDataEncoder().encode( + args as InitLendingMarketInstructionDataArgs, + ), + programAddress, + } as InitLendingMarketInstruction< + TProgramAddress, + TAccountLendingMarketOwner, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountSystemProgram, + TAccountRent + >); +} + export interface InitLendingMarketInput< TAccountLendingMarketOwner extends string = string, TAccountLendingMarket extends string = string, diff --git a/clients/kamino-lending/src/generated/instructions/initObligationFarmsForReserve.ts b/clients/kamino-lending/src/generated/instructions/initObligationFarmsForReserve.ts index 70da5739..297686b0 100644 --- a/clients/kamino-lending/src/generated/instructions/initObligationFarmsForReserve.ts +++ b/clients/kamino-lending/src/generated/instructions/initObligationFarmsForReserve.ts @@ -35,11 +35,12 @@ import { getU8Encoder, transformEncoder, } from "@solana/kit"; +import { findLendingMarketAuthPda } from "../pdas/index.js"; import { FARMS_PROGRAM_ADDRESS, KAMINO_LENDING_PROGRAM_ADDRESS, } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const INIT_OBLIGATION_FARMS_FOR_RESERVE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([136, 63, 15, 186, 211, 152, 168, 164]); @@ -151,6 +152,163 @@ export function getInitObligationFarmsForReserveInstructionDataCodec(): FixedSiz ); } +export interface InitObligationFarmsForReserveAsyncInput< + TAccountPayer extends string = string, + TAccountOwner extends string = string, + TAccountObligation extends string = string, + TAccountLendingMarketAuthority extends string = string, + TAccountReserve extends string = string, + TAccountReserveFarmState extends string = string, + TAccountObligationFarm extends string = string, + TAccountLendingMarket extends string = string, + TAccountFarmsProgram extends string = string, + TAccountRent extends string = string, + TAccountSystemProgram extends string = string, +> { + payer: TransactionSigner; + owner: Address; + obligation: Address; + lendingMarketAuthority?: Address; + reserve: Address; + reserveFarmState: Address; + obligationFarm: Address; + lendingMarket: Address; + farmsProgram?: Address; + rent?: Address; + systemProgram?: Address; + mode: InitObligationFarmsForReserveInstructionDataArgs["mode"]; +} + +export async function getInitObligationFarmsForReserveInstructionAsync< + TAccountPayer extends string, + TAccountOwner extends string, + TAccountObligation extends string, + TAccountLendingMarketAuthority extends string, + TAccountReserve extends string, + TAccountReserveFarmState extends string, + TAccountObligationFarm extends string, + TAccountLendingMarket extends string, + TAccountFarmsProgram extends string, + TAccountRent extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, +>( + input: InitObligationFarmsForReserveAsyncInput< + TAccountPayer, + TAccountOwner, + TAccountObligation, + TAccountLendingMarketAuthority, + TAccountReserve, + TAccountReserveFarmState, + TAccountObligationFarm, + TAccountLendingMarket, + TAccountFarmsProgram, + TAccountRent, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + InitObligationFarmsForReserveInstruction< + TProgramAddress, + TAccountPayer, + TAccountOwner, + TAccountObligation, + TAccountLendingMarketAuthority, + TAccountReserve, + TAccountReserveFarmState, + TAccountObligationFarm, + TAccountLendingMarket, + TAccountFarmsProgram, + TAccountRent, + TAccountSystemProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + payer: { value: input.payer ?? null, isWritable: true }, + owner: { value: input.owner ?? null, isWritable: false }, + obligation: { value: input.obligation ?? null, isWritable: true }, + lendingMarketAuthority: { + value: input.lendingMarketAuthority ?? null, + isWritable: false, + }, + reserve: { value: input.reserve ?? null, isWritable: true }, + reserveFarmState: { + value: input.reserveFarmState ?? null, + isWritable: true, + }, + obligationFarm: { value: input.obligationFarm ?? null, isWritable: true }, + lendingMarket: { value: input.lendingMarket ?? null, isWritable: false }, + farmsProgram: { value: input.farmsProgram ?? null, isWritable: false }, + rent: { value: input.rent ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.lendingMarketAuthority.value) { + accounts.lendingMarketAuthority.value = await findLendingMarketAuthPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + }); + } + if (!accounts.farmsProgram.value) { + accounts.farmsProgram.value = FARMS_PROGRAM_ADDRESS; + accounts.farmsProgram.isWritable = false; + } + if (!accounts.rent.value) { + accounts.rent.value = + "SysvarRent111111111111111111111111111111111" as Address<"SysvarRent111111111111111111111111111111111">; + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.payer), + getAccountMeta(accounts.owner), + getAccountMeta(accounts.obligation), + getAccountMeta(accounts.lendingMarketAuthority), + getAccountMeta(accounts.reserve), + getAccountMeta(accounts.reserveFarmState), + getAccountMeta(accounts.obligationFarm), + getAccountMeta(accounts.lendingMarket), + getAccountMeta(accounts.farmsProgram), + getAccountMeta(accounts.rent), + getAccountMeta(accounts.systemProgram), + ], + data: getInitObligationFarmsForReserveInstructionDataEncoder().encode( + args as InitObligationFarmsForReserveInstructionDataArgs, + ), + programAddress, + } as InitObligationFarmsForReserveInstruction< + TProgramAddress, + TAccountPayer, + TAccountOwner, + TAccountObligation, + TAccountLendingMarketAuthority, + TAccountReserve, + TAccountReserveFarmState, + TAccountObligationFarm, + TAccountLendingMarket, + TAccountFarmsProgram, + TAccountRent, + TAccountSystemProgram + >); +} + export interface InitObligationFarmsForReserveInput< TAccountPayer extends string = string, TAccountOwner extends string = string, diff --git a/clients/kamino-lending/src/generated/instructions/initReserve.ts b/clients/kamino-lending/src/generated/instructions/initReserve.ts index b4355fea..3140ec85 100644 --- a/clients/kamino-lending/src/generated/instructions/initReserve.ts +++ b/clients/kamino-lending/src/generated/instructions/initReserve.ts @@ -33,8 +33,15 @@ import { getStructEncoder, transformEncoder, } from "@solana/kit"; +import { + findLendingMarketAuthPda, + findReserveCollateralMintPda, + findReserveCollateralSupplyPda, + findReserveFeeVaultPda, + findReserveLiquiditySupplyPda, +} from "../pdas/index.js"; import { KAMINO_LENDING_PROGRAM_ADDRESS } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const INIT_RESERVE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ 138, 245, 71, 225, 153, 4, 3, 43, @@ -61,8 +68,12 @@ export type InitReserveInstruction< TAccountRent extends | string | AccountMeta = "SysvarRent111111111111111111111111111111111", - TAccountLiquidityTokenProgram extends string | AccountMeta = string, - TAccountCollateralTokenProgram extends string | AccountMeta = string, + TAccountLiquidityTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TAccountCollateralTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", TAccountSystemProgram extends | string | AccountMeta = "11111111111111111111111111111111", @@ -147,6 +158,233 @@ export function getInitReserveInstructionDataCodec(): FixedSizeCodec< ); } +export interface InitReserveAsyncInput< + TAccountLendingMarketOwner extends string = string, + TAccountLendingMarket extends string = string, + TAccountLendingMarketAuthority extends string = string, + TAccountReserve extends string = string, + TAccountReserveLiquidityMint extends string = string, + TAccountReserveLiquiditySupply extends string = string, + TAccountFeeReceiver extends string = string, + TAccountReserveCollateralMint extends string = string, + TAccountReserveCollateralSupply extends string = string, + TAccountInitialLiquiditySource extends string = string, + TAccountRent extends string = string, + TAccountLiquidityTokenProgram extends string = string, + TAccountCollateralTokenProgram extends string = string, + TAccountSystemProgram extends string = string, +> { + lendingMarketOwner: TransactionSigner; + lendingMarket: Address; + lendingMarketAuthority?: Address; + reserve: Address; + reserveLiquidityMint: Address; + reserveLiquiditySupply?: Address; + feeReceiver?: Address; + reserveCollateralMint?: Address; + reserveCollateralSupply?: Address; + initialLiquiditySource: Address; + rent?: Address; + liquidityTokenProgram?: Address; + collateralTokenProgram?: Address; + systemProgram?: Address; +} + +export async function getInitReserveInstructionAsync< + TAccountLendingMarketOwner extends string, + TAccountLendingMarket extends string, + TAccountLendingMarketAuthority extends string, + TAccountReserve extends string, + TAccountReserveLiquidityMint extends string, + TAccountReserveLiquiditySupply extends string, + TAccountFeeReceiver extends string, + TAccountReserveCollateralMint extends string, + TAccountReserveCollateralSupply extends string, + TAccountInitialLiquiditySource extends string, + TAccountRent extends string, + TAccountLiquidityTokenProgram extends string, + TAccountCollateralTokenProgram extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, +>( + input: InitReserveAsyncInput< + TAccountLendingMarketOwner, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountReserve, + TAccountReserveLiquidityMint, + TAccountReserveLiquiditySupply, + TAccountFeeReceiver, + TAccountReserveCollateralMint, + TAccountReserveCollateralSupply, + TAccountInitialLiquiditySource, + TAccountRent, + TAccountLiquidityTokenProgram, + TAccountCollateralTokenProgram, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + InitReserveInstruction< + TProgramAddress, + TAccountLendingMarketOwner, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountReserve, + TAccountReserveLiquidityMint, + TAccountReserveLiquiditySupply, + TAccountFeeReceiver, + TAccountReserveCollateralMint, + TAccountReserveCollateralSupply, + TAccountInitialLiquiditySource, + TAccountRent, + TAccountLiquidityTokenProgram, + TAccountCollateralTokenProgram, + TAccountSystemProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + lendingMarketOwner: { + value: input.lendingMarketOwner ?? null, + isWritable: true, + }, + lendingMarket: { value: input.lendingMarket ?? null, isWritable: false }, + lendingMarketAuthority: { + value: input.lendingMarketAuthority ?? null, + isWritable: false, + }, + reserve: { value: input.reserve ?? null, isWritable: true }, + reserveLiquidityMint: { + value: input.reserveLiquidityMint ?? null, + isWritable: false, + }, + reserveLiquiditySupply: { + value: input.reserveLiquiditySupply ?? null, + isWritable: true, + }, + feeReceiver: { value: input.feeReceiver ?? null, isWritable: true }, + reserveCollateralMint: { + value: input.reserveCollateralMint ?? null, + isWritable: true, + }, + reserveCollateralSupply: { + value: input.reserveCollateralSupply ?? null, + isWritable: true, + }, + initialLiquiditySource: { + value: input.initialLiquiditySource ?? null, + isWritable: true, + }, + rent: { value: input.rent ?? null, isWritable: false }, + liquidityTokenProgram: { + value: input.liquidityTokenProgram ?? null, + isWritable: false, + }, + collateralTokenProgram: { + value: input.collateralTokenProgram ?? null, + isWritable: false, + }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.lendingMarketAuthority.value) { + accounts.lendingMarketAuthority.value = await findLendingMarketAuthPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + }); + } + if (!accounts.reserveLiquiditySupply.value) { + accounts.reserveLiquiditySupply.value = await findReserveLiquiditySupplyPda( + { + lendingMarket: expectAddress(accounts.lendingMarket.value), + mint: expectAddress(accounts.reserveLiquidityMint.value), + }, + ); + } + if (!accounts.feeReceiver.value) { + accounts.feeReceiver.value = await findReserveFeeVaultPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + mint: expectAddress(accounts.reserveLiquidityMint.value), + }); + } + if (!accounts.reserveCollateralMint.value) { + accounts.reserveCollateralMint.value = await findReserveCollateralMintPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + mint: expectAddress(accounts.reserveLiquidityMint.value), + }); + } + if (!accounts.reserveCollateralSupply.value) { + accounts.reserveCollateralSupply.value = + await findReserveCollateralSupplyPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + mint: expectAddress(accounts.reserveLiquidityMint.value), + }); + } + if (!accounts.rent.value) { + accounts.rent.value = + "SysvarRent111111111111111111111111111111111" as Address<"SysvarRent111111111111111111111111111111111">; + } + if (!accounts.liquidityTokenProgram.value) { + accounts.liquidityTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.collateralTokenProgram.value) { + accounts.collateralTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.lendingMarketOwner), + getAccountMeta(accounts.lendingMarket), + getAccountMeta(accounts.lendingMarketAuthority), + getAccountMeta(accounts.reserve), + getAccountMeta(accounts.reserveLiquidityMint), + getAccountMeta(accounts.reserveLiquiditySupply), + getAccountMeta(accounts.feeReceiver), + getAccountMeta(accounts.reserveCollateralMint), + getAccountMeta(accounts.reserveCollateralSupply), + getAccountMeta(accounts.initialLiquiditySource), + getAccountMeta(accounts.rent), + getAccountMeta(accounts.liquidityTokenProgram), + getAccountMeta(accounts.collateralTokenProgram), + getAccountMeta(accounts.systemProgram), + ], + data: getInitReserveInstructionDataEncoder().encode({}), + programAddress, + } as InitReserveInstruction< + TProgramAddress, + TAccountLendingMarketOwner, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountReserve, + TAccountReserveLiquidityMint, + TAccountReserveLiquiditySupply, + TAccountFeeReceiver, + TAccountReserveCollateralMint, + TAccountReserveCollateralSupply, + TAccountInitialLiquiditySource, + TAccountRent, + TAccountLiquidityTokenProgram, + TAccountCollateralTokenProgram, + TAccountSystemProgram + >); +} + export interface InitReserveInput< TAccountLendingMarketOwner extends string = string, TAccountLendingMarket extends string = string, @@ -174,8 +412,8 @@ export interface InitReserveInput< reserveCollateralSupply: Address; initialLiquiditySource: Address; rent?: Address; - liquidityTokenProgram: Address; - collateralTokenProgram: Address; + liquidityTokenProgram?: Address; + collateralTokenProgram?: Address; systemProgram?: Address; } @@ -288,6 +526,14 @@ export function getInitReserveInstruction< accounts.rent.value = "SysvarRent111111111111111111111111111111111" as Address<"SysvarRent111111111111111111111111111111111">; } + if (!accounts.liquidityTokenProgram.value) { + accounts.liquidityTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.collateralTokenProgram.value) { + accounts.collateralTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } if (!accounts.systemProgram.value) { accounts.systemProgram.value = "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; diff --git a/clients/kamino-lending/src/generated/instructions/initializeFarm.ts b/clients/kamino-lending/src/generated/instructions/initializeFarm.ts index a1d90792..67bea168 100644 --- a/clients/kamino-lending/src/generated/instructions/initializeFarm.ts +++ b/clients/kamino-lending/src/generated/instructions/initializeFarm.ts @@ -33,8 +33,9 @@ import { getStructEncoder, transformEncoder, } from "@solana/kit"; +import { findFarmVaultPda, findFarmVaultsAuthorityPda } from "../pdas/index.js"; import { FARMS_PROGRAM_ADDRESS } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const INITIALIZE_FARM_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array( [252, 28, 185, 172, 244, 74, 117, 165], @@ -129,6 +130,143 @@ export function getInitializeFarmInstructionDataCodec(): FixedSizeCodec< ); } +export interface InitializeFarmAsyncInput< + TAccountFarmAdmin extends string = string, + TAccountFarmState extends string = string, + TAccountGlobalConfig extends string = string, + TAccountFarmVault extends string = string, + TAccountFarmVaultsAuthority extends string = string, + TAccountTokenMint extends string = string, + TAccountTokenProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, +> { + farmAdmin: TransactionSigner; + farmState: Address; + globalConfig: Address; + farmVault?: Address; + farmVaultsAuthority?: Address; + tokenMint: Address; + tokenProgram?: Address; + systemProgram?: Address; + rent?: Address; +} + +export async function getInitializeFarmInstructionAsync< + TAccountFarmAdmin extends string, + TAccountFarmState extends string, + TAccountGlobalConfig extends string, + TAccountFarmVault extends string, + TAccountFarmVaultsAuthority extends string, + TAccountTokenMint extends string, + TAccountTokenProgram extends string, + TAccountSystemProgram extends string, + TAccountRent extends string, + TProgramAddress extends Address = typeof FARMS_PROGRAM_ADDRESS, +>( + input: InitializeFarmAsyncInput< + TAccountFarmAdmin, + TAccountFarmState, + TAccountGlobalConfig, + TAccountFarmVault, + TAccountFarmVaultsAuthority, + TAccountTokenMint, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountRent + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + InitializeFarmInstruction< + TProgramAddress, + TAccountFarmAdmin, + TAccountFarmState, + TAccountGlobalConfig, + TAccountFarmVault, + TAccountFarmVaultsAuthority, + TAccountTokenMint, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountRent + > +> { + // Program address. + const programAddress = config?.programAddress ?? FARMS_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + farmAdmin: { value: input.farmAdmin ?? null, isWritable: true }, + farmState: { value: input.farmState ?? null, isWritable: true }, + globalConfig: { value: input.globalConfig ?? null, isWritable: false }, + farmVault: { value: input.farmVault ?? null, isWritable: true }, + farmVaultsAuthority: { + value: input.farmVaultsAuthority ?? null, + isWritable: false, + }, + tokenMint: { value: input.tokenMint ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + rent: { value: input.rent ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.farmVault.value) { + accounts.farmVault.value = await findFarmVaultPda({ + farmState: expectAddress(accounts.farmState.value), + tokenMint: expectAddress(accounts.tokenMint.value), + }); + } + if (!accounts.farmVaultsAuthority.value) { + accounts.farmVaultsAuthority.value = await findFarmVaultsAuthorityPda({ + farmState: expectAddress(accounts.farmState.value), + }); + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + if (!accounts.rent.value) { + accounts.rent.value = + "SysvarRent111111111111111111111111111111111" as Address<"SysvarRent111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.farmAdmin), + getAccountMeta(accounts.farmState), + getAccountMeta(accounts.globalConfig), + getAccountMeta(accounts.farmVault), + getAccountMeta(accounts.farmVaultsAuthority), + getAccountMeta(accounts.tokenMint), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), + ], + data: getInitializeFarmInstructionDataEncoder().encode({}), + programAddress, + } as InitializeFarmInstruction< + TProgramAddress, + TAccountFarmAdmin, + TAccountFarmState, + TAccountGlobalConfig, + TAccountFarmVault, + TAccountFarmVaultsAuthority, + TAccountTokenMint, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountRent + >); +} + export interface InitializeFarmInput< TAccountFarmAdmin extends string = string, TAccountFarmState extends string = string, diff --git a/clients/kamino-lending/src/generated/instructions/initializeFarmDelegated.ts b/clients/kamino-lending/src/generated/instructions/initializeFarmDelegated.ts index 67e96845..42235889 100644 --- a/clients/kamino-lending/src/generated/instructions/initializeFarmDelegated.ts +++ b/clients/kamino-lending/src/generated/instructions/initializeFarmDelegated.ts @@ -34,8 +34,9 @@ import { getStructEncoder, transformEncoder, } from "@solana/kit"; +import { findFarmVaultsAuthorityPda } from "../pdas/index.js"; import { FARMS_PROGRAM_ADDRESS } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const INITIALIZE_FARM_DELEGATED_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([250, 84, 101, 25, 51, 77, 204, 91]); @@ -123,6 +124,117 @@ export function getInitializeFarmDelegatedInstructionDataCodec(): FixedSizeCodec ); } +export interface InitializeFarmDelegatedAsyncInput< + TAccountFarmAdmin extends string = string, + TAccountFarmDelegate extends string = string, + TAccountFarmState extends string = string, + TAccountGlobalConfig extends string = string, + TAccountFarmVaultsAuthority extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, +> { + farmAdmin: TransactionSigner; + farmDelegate: TransactionSigner; + farmState: Address; + globalConfig: Address; + farmVaultsAuthority?: Address; + systemProgram?: Address; + rent?: Address; +} + +export async function getInitializeFarmDelegatedInstructionAsync< + TAccountFarmAdmin extends string, + TAccountFarmDelegate extends string, + TAccountFarmState extends string, + TAccountGlobalConfig extends string, + TAccountFarmVaultsAuthority extends string, + TAccountSystemProgram extends string, + TAccountRent extends string, + TProgramAddress extends Address = typeof FARMS_PROGRAM_ADDRESS, +>( + input: InitializeFarmDelegatedAsyncInput< + TAccountFarmAdmin, + TAccountFarmDelegate, + TAccountFarmState, + TAccountGlobalConfig, + TAccountFarmVaultsAuthority, + TAccountSystemProgram, + TAccountRent + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + InitializeFarmDelegatedInstruction< + TProgramAddress, + TAccountFarmAdmin, + TAccountFarmDelegate, + TAccountFarmState, + TAccountGlobalConfig, + TAccountFarmVaultsAuthority, + TAccountSystemProgram, + TAccountRent + > +> { + // Program address. + const programAddress = config?.programAddress ?? FARMS_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + farmAdmin: { value: input.farmAdmin ?? null, isWritable: true }, + farmDelegate: { value: input.farmDelegate ?? null, isWritable: false }, + farmState: { value: input.farmState ?? null, isWritable: true }, + globalConfig: { value: input.globalConfig ?? null, isWritable: false }, + farmVaultsAuthority: { + value: input.farmVaultsAuthority ?? null, + isWritable: false, + }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + rent: { value: input.rent ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.farmVaultsAuthority.value) { + accounts.farmVaultsAuthority.value = await findFarmVaultsAuthorityPda({ + farmState: expectAddress(accounts.farmState.value), + }); + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + if (!accounts.rent.value) { + accounts.rent.value = + "SysvarRent111111111111111111111111111111111" as Address<"SysvarRent111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.farmAdmin), + getAccountMeta(accounts.farmDelegate), + getAccountMeta(accounts.farmState), + getAccountMeta(accounts.globalConfig), + getAccountMeta(accounts.farmVaultsAuthority), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), + ], + data: getInitializeFarmDelegatedInstructionDataEncoder().encode({}), + programAddress, + } as InitializeFarmDelegatedInstruction< + TProgramAddress, + TAccountFarmAdmin, + TAccountFarmDelegate, + TAccountFarmState, + TAccountGlobalConfig, + TAccountFarmVaultsAuthority, + TAccountSystemProgram, + TAccountRent + >); +} + export interface InitializeFarmDelegatedInput< TAccountFarmAdmin extends string = string, TAccountFarmDelegate extends string = string, diff --git a/clients/kamino-lending/src/generated/instructions/initializeGlobalConfig.ts b/clients/kamino-lending/src/generated/instructions/initializeGlobalConfig.ts index df4337c0..ddad406f 100644 --- a/clients/kamino-lending/src/generated/instructions/initializeGlobalConfig.ts +++ b/clients/kamino-lending/src/generated/instructions/initializeGlobalConfig.ts @@ -33,8 +33,9 @@ import { getStructEncoder, transformEncoder, } from "@solana/kit"; +import { findTreasuryVaultsAuthorityPda } from "../pdas/index.js"; import { FARMS_PROGRAM_ADDRESS } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const INITIALIZE_GLOBAL_CONFIG_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([113, 216, 122, 131, 225, 209, 22, 55]); @@ -107,6 +108,90 @@ export function getInitializeGlobalConfigInstructionDataCodec(): FixedSizeCodec< ); } +export interface InitializeGlobalConfigAsyncInput< + TAccountGlobalAdmin extends string = string, + TAccountGlobalConfig extends string = string, + TAccountTreasuryVaultsAuthority extends string = string, + TAccountSystemProgram extends string = string, +> { + globalAdmin: TransactionSigner; + globalConfig: Address; + treasuryVaultsAuthority?: Address; + systemProgram?: Address; +} + +export async function getInitializeGlobalConfigInstructionAsync< + TAccountGlobalAdmin extends string, + TAccountGlobalConfig extends string, + TAccountTreasuryVaultsAuthority extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof FARMS_PROGRAM_ADDRESS, +>( + input: InitializeGlobalConfigAsyncInput< + TAccountGlobalAdmin, + TAccountGlobalConfig, + TAccountTreasuryVaultsAuthority, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + InitializeGlobalConfigInstruction< + TProgramAddress, + TAccountGlobalAdmin, + TAccountGlobalConfig, + TAccountTreasuryVaultsAuthority, + TAccountSystemProgram + > +> { + // Program address. + const programAddress = config?.programAddress ?? FARMS_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + globalAdmin: { value: input.globalAdmin ?? null, isWritable: true }, + globalConfig: { value: input.globalConfig ?? null, isWritable: true }, + treasuryVaultsAuthority: { + value: input.treasuryVaultsAuthority ?? null, + isWritable: false, + }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.treasuryVaultsAuthority.value) { + accounts.treasuryVaultsAuthority.value = + await findTreasuryVaultsAuthorityPda({ + globalConfig: expectAddress(accounts.globalConfig.value), + }); + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.globalAdmin), + getAccountMeta(accounts.globalConfig), + getAccountMeta(accounts.treasuryVaultsAuthority), + getAccountMeta(accounts.systemProgram), + ], + data: getInitializeGlobalConfigInstructionDataEncoder().encode({}), + programAddress, + } as InitializeGlobalConfigInstruction< + TProgramAddress, + TAccountGlobalAdmin, + TAccountGlobalConfig, + TAccountTreasuryVaultsAuthority, + TAccountSystemProgram + >); +} + export interface InitializeGlobalConfigInput< TAccountGlobalAdmin extends string = string, TAccountGlobalConfig extends string = string, diff --git a/clients/kamino-lending/src/generated/instructions/initializeReward.ts b/clients/kamino-lending/src/generated/instructions/initializeReward.ts index df8e0af9..e2a06a85 100644 --- a/clients/kamino-lending/src/generated/instructions/initializeReward.ts +++ b/clients/kamino-lending/src/generated/instructions/initializeReward.ts @@ -33,8 +33,14 @@ import { getStructEncoder, transformEncoder, } from "@solana/kit"; +import { + findFarmVaultsAuthorityPda, + findRewardTreasuryVaultPda, + findRewardVaultPda, + findTreasuryVaultsAuthorityPda, +} from "../pdas/index.js"; import { FARMS_PROGRAM_ADDRESS } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const INITIALIZE_REWARD_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([95, 135, 192, 196, 242, 129, 230, 68]); @@ -136,6 +142,177 @@ export function getInitializeRewardInstructionDataCodec(): FixedSizeCodec< ); } +export interface InitializeRewardAsyncInput< + TAccountFarmAdmin extends string = string, + TAccountFarmState extends string = string, + TAccountGlobalConfig extends string = string, + TAccountRewardMint extends string = string, + TAccountRewardVault extends string = string, + TAccountRewardTreasuryVault extends string = string, + TAccountFarmVaultsAuthority extends string = string, + TAccountTreasuryVaultsAuthority extends string = string, + TAccountTokenProgram extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, +> { + farmAdmin: TransactionSigner; + farmState: Address; + globalConfig: Address; + rewardMint: Address; + rewardVault?: Address; + rewardTreasuryVault?: Address; + farmVaultsAuthority?: Address; + treasuryVaultsAuthority?: Address; + tokenProgram?: Address; + systemProgram?: Address; + rent?: Address; +} + +export async function getInitializeRewardInstructionAsync< + TAccountFarmAdmin extends string, + TAccountFarmState extends string, + TAccountGlobalConfig extends string, + TAccountRewardMint extends string, + TAccountRewardVault extends string, + TAccountRewardTreasuryVault extends string, + TAccountFarmVaultsAuthority extends string, + TAccountTreasuryVaultsAuthority extends string, + TAccountTokenProgram extends string, + TAccountSystemProgram extends string, + TAccountRent extends string, + TProgramAddress extends Address = typeof FARMS_PROGRAM_ADDRESS, +>( + input: InitializeRewardAsyncInput< + TAccountFarmAdmin, + TAccountFarmState, + TAccountGlobalConfig, + TAccountRewardMint, + TAccountRewardVault, + TAccountRewardTreasuryVault, + TAccountFarmVaultsAuthority, + TAccountTreasuryVaultsAuthority, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountRent + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + InitializeRewardInstruction< + TProgramAddress, + TAccountFarmAdmin, + TAccountFarmState, + TAccountGlobalConfig, + TAccountRewardMint, + TAccountRewardVault, + TAccountRewardTreasuryVault, + TAccountFarmVaultsAuthority, + TAccountTreasuryVaultsAuthority, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountRent + > +> { + // Program address. + const programAddress = config?.programAddress ?? FARMS_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + farmAdmin: { value: input.farmAdmin ?? null, isWritable: true }, + farmState: { value: input.farmState ?? null, isWritable: true }, + globalConfig: { value: input.globalConfig ?? null, isWritable: false }, + rewardMint: { value: input.rewardMint ?? null, isWritable: false }, + rewardVault: { value: input.rewardVault ?? null, isWritable: true }, + rewardTreasuryVault: { + value: input.rewardTreasuryVault ?? null, + isWritable: true, + }, + farmVaultsAuthority: { + value: input.farmVaultsAuthority ?? null, + isWritable: false, + }, + treasuryVaultsAuthority: { + value: input.treasuryVaultsAuthority ?? null, + isWritable: false, + }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + rent: { value: input.rent ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.rewardVault.value) { + accounts.rewardVault.value = await findRewardVaultPda({ + farmState: expectAddress(accounts.farmState.value), + rewardMint: expectAddress(accounts.rewardMint.value), + }); + } + if (!accounts.rewardTreasuryVault.value) { + accounts.rewardTreasuryVault.value = await findRewardTreasuryVaultPda({ + globalConfig: expectAddress(accounts.globalConfig.value), + rewardMint: expectAddress(accounts.rewardMint.value), + }); + } + if (!accounts.farmVaultsAuthority.value) { + accounts.farmVaultsAuthority.value = await findFarmVaultsAuthorityPda({ + farmState: expectAddress(accounts.farmState.value), + }); + } + if (!accounts.treasuryVaultsAuthority.value) { + accounts.treasuryVaultsAuthority.value = + await findTreasuryVaultsAuthorityPda({ + globalConfig: expectAddress(accounts.globalConfig.value), + }); + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + if (!accounts.rent.value) { + accounts.rent.value = + "SysvarRent111111111111111111111111111111111" as Address<"SysvarRent111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.farmAdmin), + getAccountMeta(accounts.farmState), + getAccountMeta(accounts.globalConfig), + getAccountMeta(accounts.rewardMint), + getAccountMeta(accounts.rewardVault), + getAccountMeta(accounts.rewardTreasuryVault), + getAccountMeta(accounts.farmVaultsAuthority), + getAccountMeta(accounts.treasuryVaultsAuthority), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), + ], + data: getInitializeRewardInstructionDataEncoder().encode({}), + programAddress, + } as InitializeRewardInstruction< + TProgramAddress, + TAccountFarmAdmin, + TAccountFarmState, + TAccountGlobalConfig, + TAccountRewardMint, + TAccountRewardVault, + TAccountRewardTreasuryVault, + TAccountFarmVaultsAuthority, + TAccountTreasuryVaultsAuthority, + TAccountTokenProgram, + TAccountSystemProgram, + TAccountRent + >); +} + export interface InitializeRewardInput< TAccountFarmAdmin extends string = string, TAccountFarmState extends string = string, diff --git a/clients/kamino-lending/src/generated/instructions/initializeUser.ts b/clients/kamino-lending/src/generated/instructions/initializeUser.ts index 1a966ffb..d5fbde85 100644 --- a/clients/kamino-lending/src/generated/instructions/initializeUser.ts +++ b/clients/kamino-lending/src/generated/instructions/initializeUser.ts @@ -34,8 +34,9 @@ import { getStructEncoder, transformEncoder, } from "@solana/kit"; +import { findFarmsUserStatePda } from "../pdas/index.js"; import { FARMS_PROGRAM_ADDRESS } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const INITIALIZE_USER_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array( [111, 17, 185, 250, 60, 122, 38, 254], @@ -125,6 +126,123 @@ export function getInitializeUserInstructionDataCodec(): FixedSizeCodec< ); } +export interface InitializeUserAsyncInput< + TAccountAuthority extends string = string, + TAccountPayer extends string = string, + TAccountOwner extends string = string, + TAccountDelegatee extends string = string, + TAccountUserState extends string = string, + TAccountFarmState extends string = string, + TAccountSystemProgram extends string = string, + TAccountRent extends string = string, +> { + authority: TransactionSigner; + payer: TransactionSigner; + owner: Address; + delegatee: Address; + userState?: Address; + farmState: Address; + systemProgram?: Address; + rent?: Address; +} + +export async function getInitializeUserInstructionAsync< + TAccountAuthority extends string, + TAccountPayer extends string, + TAccountOwner extends string, + TAccountDelegatee extends string, + TAccountUserState extends string, + TAccountFarmState extends string, + TAccountSystemProgram extends string, + TAccountRent extends string, + TProgramAddress extends Address = typeof FARMS_PROGRAM_ADDRESS, +>( + input: InitializeUserAsyncInput< + TAccountAuthority, + TAccountPayer, + TAccountOwner, + TAccountDelegatee, + TAccountUserState, + TAccountFarmState, + TAccountSystemProgram, + TAccountRent + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + InitializeUserInstruction< + TProgramAddress, + TAccountAuthority, + TAccountPayer, + TAccountOwner, + TAccountDelegatee, + TAccountUserState, + TAccountFarmState, + TAccountSystemProgram, + TAccountRent + > +> { + // Program address. + const programAddress = config?.programAddress ?? FARMS_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + authority: { value: input.authority ?? null, isWritable: false }, + payer: { value: input.payer ?? null, isWritable: true }, + owner: { value: input.owner ?? null, isWritable: false }, + delegatee: { value: input.delegatee ?? null, isWritable: false }, + userState: { value: input.userState ?? null, isWritable: true }, + farmState: { value: input.farmState ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + rent: { value: input.rent ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.userState.value) { + accounts.userState.value = await findFarmsUserStatePda({ + farmState: expectAddress(accounts.farmState.value), + owner: expectAddress(accounts.delegatee.value), + }); + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + if (!accounts.rent.value) { + accounts.rent.value = + "SysvarRent111111111111111111111111111111111" as Address<"SysvarRent111111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.authority), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.owner), + getAccountMeta(accounts.delegatee), + getAccountMeta(accounts.userState), + getAccountMeta(accounts.farmState), + getAccountMeta(accounts.systemProgram), + getAccountMeta(accounts.rent), + ], + data: getInitializeUserInstructionDataEncoder().encode({}), + programAddress, + } as InitializeUserInstruction< + TProgramAddress, + TAccountAuthority, + TAccountPayer, + TAccountOwner, + TAccountDelegatee, + TAccountUserState, + TAccountFarmState, + TAccountSystemProgram, + TAccountRent + >); +} + export interface InitializeUserInput< TAccountAuthority extends string = string, TAccountPayer extends string = string, diff --git a/clients/kamino-lending/src/generated/instructions/liquidateObligationAndRedeemReserveCollateral.ts b/clients/kamino-lending/src/generated/instructions/liquidateObligationAndRedeemReserveCollateral.ts index 912ff75d..08790219 100644 --- a/clients/kamino-lending/src/generated/instructions/liquidateObligationAndRedeemReserveCollateral.ts +++ b/clients/kamino-lending/src/generated/instructions/liquidateObligationAndRedeemReserveCollateral.ts @@ -35,8 +35,9 @@ import { getU64Encoder, transformEncoder, } from "@solana/kit"; +import { findLendingMarketAuthPda } from "../pdas/index.js"; import { KAMINO_LENDING_PROGRAM_ADDRESS } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const LIQUIDATE_OBLIGATION_AND_REDEEM_RESERVE_COLLATERAL_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([177, 71, 154, 188, 226, 133, 74, 55]); @@ -67,7 +68,9 @@ export type LiquidateObligationAndRedeemReserveCollateralInstruction< TAccountUserSourceLiquidity extends string | AccountMeta = string, TAccountUserDestinationCollateral extends string | AccountMeta = string, TAccountUserDestinationLiquidity extends string | AccountMeta = string, - TAccountCollateralTokenProgram extends string | AccountMeta = string, + TAccountCollateralTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", TAccountRepayLiquidityTokenProgram extends string | AccountMeta = string, TAccountWithdrawLiquidityTokenProgram extends string | AccountMeta = string, TAccountInstructionSysvarAccount extends @@ -191,6 +194,272 @@ export function getLiquidateObligationAndRedeemReserveCollateralInstructionDataC ); } +export interface LiquidateObligationAndRedeemReserveCollateralAsyncInput< + TAccountLiquidator extends string = string, + TAccountObligation extends string = string, + TAccountLendingMarket extends string = string, + TAccountLendingMarketAuthority extends string = string, + TAccountRepayReserve extends string = string, + TAccountRepayReserveLiquidityMint extends string = string, + TAccountRepayReserveLiquiditySupply extends string = string, + TAccountWithdrawReserve extends string = string, + TAccountWithdrawReserveLiquidityMint extends string = string, + TAccountWithdrawReserveCollateralMint extends string = string, + TAccountWithdrawReserveCollateralSupply extends string = string, + TAccountWithdrawReserveLiquiditySupply extends string = string, + TAccountWithdrawReserveLiquidityFeeReceiver extends string = string, + TAccountUserSourceLiquidity extends string = string, + TAccountUserDestinationCollateral extends string = string, + TAccountUserDestinationLiquidity extends string = string, + TAccountCollateralTokenProgram extends string = string, + TAccountRepayLiquidityTokenProgram extends string = string, + TAccountWithdrawLiquidityTokenProgram extends string = string, + TAccountInstructionSysvarAccount extends string = string, +> { + liquidator: TransactionSigner; + obligation: Address; + lendingMarket: Address; + lendingMarketAuthority?: Address; + repayReserve: Address; + repayReserveLiquidityMint: Address; + repayReserveLiquiditySupply: Address; + withdrawReserve: Address; + withdrawReserveLiquidityMint: Address; + withdrawReserveCollateralMint: Address; + withdrawReserveCollateralSupply: Address; + withdrawReserveLiquiditySupply: Address; + withdrawReserveLiquidityFeeReceiver: Address; + userSourceLiquidity: Address; + userDestinationCollateral: Address; + userDestinationLiquidity: Address; + collateralTokenProgram?: Address; + repayLiquidityTokenProgram: Address; + withdrawLiquidityTokenProgram: Address; + instructionSysvarAccount?: Address; + liquidityAmount: LiquidateObligationAndRedeemReserveCollateralInstructionDataArgs["liquidityAmount"]; + minAcceptableReceivedLiquidityAmount: LiquidateObligationAndRedeemReserveCollateralInstructionDataArgs["minAcceptableReceivedLiquidityAmount"]; + maxAllowedLtvOverridePercent: LiquidateObligationAndRedeemReserveCollateralInstructionDataArgs["maxAllowedLtvOverridePercent"]; +} + +export async function getLiquidateObligationAndRedeemReserveCollateralInstructionAsync< + TAccountLiquidator extends string, + TAccountObligation extends string, + TAccountLendingMarket extends string, + TAccountLendingMarketAuthority extends string, + TAccountRepayReserve extends string, + TAccountRepayReserveLiquidityMint extends string, + TAccountRepayReserveLiquiditySupply extends string, + TAccountWithdrawReserve extends string, + TAccountWithdrawReserveLiquidityMint extends string, + TAccountWithdrawReserveCollateralMint extends string, + TAccountWithdrawReserveCollateralSupply extends string, + TAccountWithdrawReserveLiquiditySupply extends string, + TAccountWithdrawReserveLiquidityFeeReceiver extends string, + TAccountUserSourceLiquidity extends string, + TAccountUserDestinationCollateral extends string, + TAccountUserDestinationLiquidity extends string, + TAccountCollateralTokenProgram extends string, + TAccountRepayLiquidityTokenProgram extends string, + TAccountWithdrawLiquidityTokenProgram extends string, + TAccountInstructionSysvarAccount extends string, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, +>( + input: LiquidateObligationAndRedeemReserveCollateralAsyncInput< + TAccountLiquidator, + TAccountObligation, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountRepayReserve, + TAccountRepayReserveLiquidityMint, + TAccountRepayReserveLiquiditySupply, + TAccountWithdrawReserve, + TAccountWithdrawReserveLiquidityMint, + TAccountWithdrawReserveCollateralMint, + TAccountWithdrawReserveCollateralSupply, + TAccountWithdrawReserveLiquiditySupply, + TAccountWithdrawReserveLiquidityFeeReceiver, + TAccountUserSourceLiquidity, + TAccountUserDestinationCollateral, + TAccountUserDestinationLiquidity, + TAccountCollateralTokenProgram, + TAccountRepayLiquidityTokenProgram, + TAccountWithdrawLiquidityTokenProgram, + TAccountInstructionSysvarAccount + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + LiquidateObligationAndRedeemReserveCollateralInstruction< + TProgramAddress, + TAccountLiquidator, + TAccountObligation, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountRepayReserve, + TAccountRepayReserveLiquidityMint, + TAccountRepayReserveLiquiditySupply, + TAccountWithdrawReserve, + TAccountWithdrawReserveLiquidityMint, + TAccountWithdrawReserveCollateralMint, + TAccountWithdrawReserveCollateralSupply, + TAccountWithdrawReserveLiquiditySupply, + TAccountWithdrawReserveLiquidityFeeReceiver, + TAccountUserSourceLiquidity, + TAccountUserDestinationCollateral, + TAccountUserDestinationLiquidity, + TAccountCollateralTokenProgram, + TAccountRepayLiquidityTokenProgram, + TAccountWithdrawLiquidityTokenProgram, + TAccountInstructionSysvarAccount + > +> { + // Program address. + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + liquidator: { value: input.liquidator ?? null, isWritable: false }, + obligation: { value: input.obligation ?? null, isWritable: true }, + lendingMarket: { value: input.lendingMarket ?? null, isWritable: false }, + lendingMarketAuthority: { + value: input.lendingMarketAuthority ?? null, + isWritable: false, + }, + repayReserve: { value: input.repayReserve ?? null, isWritable: true }, + repayReserveLiquidityMint: { + value: input.repayReserveLiquidityMint ?? null, + isWritable: false, + }, + repayReserveLiquiditySupply: { + value: input.repayReserveLiquiditySupply ?? null, + isWritable: true, + }, + withdrawReserve: { value: input.withdrawReserve ?? null, isWritable: true }, + withdrawReserveLiquidityMint: { + value: input.withdrawReserveLiquidityMint ?? null, + isWritable: false, + }, + withdrawReserveCollateralMint: { + value: input.withdrawReserveCollateralMint ?? null, + isWritable: true, + }, + withdrawReserveCollateralSupply: { + value: input.withdrawReserveCollateralSupply ?? null, + isWritable: true, + }, + withdrawReserveLiquiditySupply: { + value: input.withdrawReserveLiquiditySupply ?? null, + isWritable: true, + }, + withdrawReserveLiquidityFeeReceiver: { + value: input.withdrawReserveLiquidityFeeReceiver ?? null, + isWritable: true, + }, + userSourceLiquidity: { + value: input.userSourceLiquidity ?? null, + isWritable: true, + }, + userDestinationCollateral: { + value: input.userDestinationCollateral ?? null, + isWritable: true, + }, + userDestinationLiquidity: { + value: input.userDestinationLiquidity ?? null, + isWritable: true, + }, + collateralTokenProgram: { + value: input.collateralTokenProgram ?? null, + isWritable: false, + }, + repayLiquidityTokenProgram: { + value: input.repayLiquidityTokenProgram ?? null, + isWritable: false, + }, + withdrawLiquidityTokenProgram: { + value: input.withdrawLiquidityTokenProgram ?? null, + isWritable: false, + }, + instructionSysvarAccount: { + value: input.instructionSysvarAccount ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.lendingMarketAuthority.value) { + accounts.lendingMarketAuthority.value = await findLendingMarketAuthPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + }); + } + if (!accounts.collateralTokenProgram.value) { + accounts.collateralTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.instructionSysvarAccount.value) { + accounts.instructionSysvarAccount.value = + "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.liquidator), + getAccountMeta(accounts.obligation), + getAccountMeta(accounts.lendingMarket), + getAccountMeta(accounts.lendingMarketAuthority), + getAccountMeta(accounts.repayReserve), + getAccountMeta(accounts.repayReserveLiquidityMint), + getAccountMeta(accounts.repayReserveLiquiditySupply), + getAccountMeta(accounts.withdrawReserve), + getAccountMeta(accounts.withdrawReserveLiquidityMint), + getAccountMeta(accounts.withdrawReserveCollateralMint), + getAccountMeta(accounts.withdrawReserveCollateralSupply), + getAccountMeta(accounts.withdrawReserveLiquiditySupply), + getAccountMeta(accounts.withdrawReserveLiquidityFeeReceiver), + getAccountMeta(accounts.userSourceLiquidity), + getAccountMeta(accounts.userDestinationCollateral), + getAccountMeta(accounts.userDestinationLiquidity), + getAccountMeta(accounts.collateralTokenProgram), + getAccountMeta(accounts.repayLiquidityTokenProgram), + getAccountMeta(accounts.withdrawLiquidityTokenProgram), + getAccountMeta(accounts.instructionSysvarAccount), + ], + data: getLiquidateObligationAndRedeemReserveCollateralInstructionDataEncoder().encode( + args as LiquidateObligationAndRedeemReserveCollateralInstructionDataArgs, + ), + programAddress, + } as LiquidateObligationAndRedeemReserveCollateralInstruction< + TProgramAddress, + TAccountLiquidator, + TAccountObligation, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountRepayReserve, + TAccountRepayReserveLiquidityMint, + TAccountRepayReserveLiquiditySupply, + TAccountWithdrawReserve, + TAccountWithdrawReserveLiquidityMint, + TAccountWithdrawReserveCollateralMint, + TAccountWithdrawReserveCollateralSupply, + TAccountWithdrawReserveLiquiditySupply, + TAccountWithdrawReserveLiquidityFeeReceiver, + TAccountUserSourceLiquidity, + TAccountUserDestinationCollateral, + TAccountUserDestinationLiquidity, + TAccountCollateralTokenProgram, + TAccountRepayLiquidityTokenProgram, + TAccountWithdrawLiquidityTokenProgram, + TAccountInstructionSysvarAccount + >); +} + export interface LiquidateObligationAndRedeemReserveCollateralInput< TAccountLiquidator extends string = string, TAccountObligation extends string = string, @@ -229,7 +498,7 @@ export interface LiquidateObligationAndRedeemReserveCollateralInput< userSourceLiquidity: Address; userDestinationCollateral: Address; userDestinationLiquidity: Address; - collateralTokenProgram: Address; + collateralTokenProgram?: Address; repayLiquidityTokenProgram: Address; withdrawLiquidityTokenProgram: Address; instructionSysvarAccount?: Address; @@ -388,6 +657,10 @@ export function getLiquidateObligationAndRedeemReserveCollateralInstruction< const args = { ...input }; // Resolve default values. + if (!accounts.collateralTokenProgram.value) { + accounts.collateralTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } if (!accounts.instructionSysvarAccount.value) { accounts.instructionSysvarAccount.value = "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; diff --git a/clients/kamino-lending/src/generated/instructions/liquidateObligationAndRedeemReserveCollateralV2.ts b/clients/kamino-lending/src/generated/instructions/liquidateObligationAndRedeemReserveCollateralV2.ts index 4b5d9c0f..7d9a253f 100644 --- a/clients/kamino-lending/src/generated/instructions/liquidateObligationAndRedeemReserveCollateralV2.ts +++ b/clients/kamino-lending/src/generated/instructions/liquidateObligationAndRedeemReserveCollateralV2.ts @@ -105,7 +105,7 @@ export type LiquidateObligationAndRedeemReserveCollateralV2Instruction< | AccountMeta = string, TAccountLiquidationAccountsInstructionSysvarAccount extends | string - | AccountMeta = "Sysvar1nstructions1111111111111111111111111", + | AccountMeta = string, TAccountCollateralFarmsAccountsV2ObligationFarmUserState extends | string | AccountMeta = string, @@ -137,7 +137,7 @@ export type LiquidateObligationAndRedeemReserveCollateralV2Instruction< ? ReadonlyAccount : TAccountLiquidationAccountsLendingMarket, TAccountLiquidationAccountsLendingMarketAuthority extends string - ? ReadonlyAccount + ? WritableAccount : TAccountLiquidationAccountsLendingMarketAuthority, TAccountLiquidationAccountsRepayReserve extends string ? WritableAccount @@ -308,7 +308,7 @@ export interface LiquidateObligationAndRedeemReserveCollateralV2Input< liquidationAccountsCollateralTokenProgram: Address; liquidationAccountsRepayLiquidityTokenProgram: Address; liquidationAccountsWithdrawLiquidityTokenProgram: Address; - liquidationAccountsInstructionSysvarAccount?: Address; + liquidationAccountsInstructionSysvarAccount: Address; collateralFarmsAccountsV2ObligationFarmUserState?: Address; collateralFarmsAccountsV2ReserveFarmState?: Address; debtFarmsAccountsObligationFarmUserState?: Address; @@ -423,7 +423,7 @@ export function getLiquidateObligationAndRedeemReserveCollateralV2Instruction< }, liquidationAccountsLendingMarketAuthority: { value: input.liquidationAccountsLendingMarketAuthority ?? null, - isWritable: false, + isWritable: true, }, liquidationAccountsRepayReserve: { value: input.liquidationAccountsRepayReserve ?? null, @@ -517,10 +517,6 @@ export function getLiquidateObligationAndRedeemReserveCollateralV2Instruction< const args = { ...input }; // Resolve default values. - if (!accounts.liquidationAccountsInstructionSysvarAccount.value) { - accounts.liquidationAccountsInstructionSysvarAccount.value = - "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; - } if (!accounts.farmsProgram.value) { accounts.farmsProgram.value = FARMS_PROGRAM_ADDRESS; accounts.farmsProgram.isWritable = false; diff --git a/clients/kamino-lending/src/generated/instructions/redeemFees.ts b/clients/kamino-lending/src/generated/instructions/redeemFees.ts index 515d7d87..f7bd8b0e 100644 --- a/clients/kamino-lending/src/generated/instructions/redeemFees.ts +++ b/clients/kamino-lending/src/generated/instructions/redeemFees.ts @@ -30,8 +30,12 @@ import { getStructEncoder, transformEncoder, } from "@solana/kit"; +import { + findLendingMarketAuthPda, + findReserveFeeVaultPda, +} from "../pdas/index.js"; import { KAMINO_LENDING_PROGRAM_ADDRESS } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const REDEEM_FEES_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ 215, 39, 180, 41, 173, 46, 248, 220, @@ -111,6 +115,129 @@ export function getRedeemFeesInstructionDataCodec(): FixedSizeCodec< ); } +export interface RedeemFeesAsyncInput< + TAccountReserve extends string = string, + TAccountReserveLiquidityMint extends string = string, + TAccountReserveLiquidityFeeReceiver extends string = string, + TAccountReserveSupplyLiquidity extends string = string, + TAccountLendingMarket extends string = string, + TAccountLendingMarketAuthority extends string = string, + TAccountTokenProgram extends string = string, +> { + reserve: Address; + reserveLiquidityMint: Address; + reserveLiquidityFeeReceiver?: Address; + reserveSupplyLiquidity: Address; + lendingMarket: Address; + lendingMarketAuthority?: Address; + tokenProgram?: Address; +} + +export async function getRedeemFeesInstructionAsync< + TAccountReserve extends string, + TAccountReserveLiquidityMint extends string, + TAccountReserveLiquidityFeeReceiver extends string, + TAccountReserveSupplyLiquidity extends string, + TAccountLendingMarket extends string, + TAccountLendingMarketAuthority extends string, + TAccountTokenProgram extends string, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, +>( + input: RedeemFeesAsyncInput< + TAccountReserve, + TAccountReserveLiquidityMint, + TAccountReserveLiquidityFeeReceiver, + TAccountReserveSupplyLiquidity, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + RedeemFeesInstruction< + TProgramAddress, + TAccountReserve, + TAccountReserveLiquidityMint, + TAccountReserveLiquidityFeeReceiver, + TAccountReserveSupplyLiquidity, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountTokenProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + reserve: { value: input.reserve ?? null, isWritable: true }, + reserveLiquidityMint: { + value: input.reserveLiquidityMint ?? null, + isWritable: false, + }, + reserveLiquidityFeeReceiver: { + value: input.reserveLiquidityFeeReceiver ?? null, + isWritable: true, + }, + reserveSupplyLiquidity: { + value: input.reserveSupplyLiquidity ?? null, + isWritable: true, + }, + lendingMarket: { value: input.lendingMarket ?? null, isWritable: false }, + lendingMarketAuthority: { + value: input.lendingMarketAuthority ?? null, + isWritable: false, + }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.reserveLiquidityFeeReceiver.value) { + accounts.reserveLiquidityFeeReceiver.value = await findReserveFeeVaultPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + mint: expectAddress(accounts.reserveLiquidityMint.value), + }); + } + if (!accounts.lendingMarketAuthority.value) { + accounts.lendingMarketAuthority.value = await findLendingMarketAuthPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + }); + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.reserve), + getAccountMeta(accounts.reserveLiquidityMint), + getAccountMeta(accounts.reserveLiquidityFeeReceiver), + getAccountMeta(accounts.reserveSupplyLiquidity), + getAccountMeta(accounts.lendingMarket), + getAccountMeta(accounts.lendingMarketAuthority), + getAccountMeta(accounts.tokenProgram), + ], + data: getRedeemFeesInstructionDataEncoder().encode({}), + programAddress, + } as RedeemFeesInstruction< + TProgramAddress, + TAccountReserve, + TAccountReserveLiquidityMint, + TAccountReserveLiquidityFeeReceiver, + TAccountReserveSupplyLiquidity, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountTokenProgram + >); +} + export interface RedeemFeesInput< TAccountReserve extends string = string, TAccountReserveLiquidityMint extends string = string, diff --git a/clients/kamino-lending/src/generated/instructions/redeemReserveCollateral.ts b/clients/kamino-lending/src/generated/instructions/redeemReserveCollateral.ts index 6be40701..c5f953cd 100644 --- a/clients/kamino-lending/src/generated/instructions/redeemReserveCollateral.ts +++ b/clients/kamino-lending/src/generated/instructions/redeemReserveCollateral.ts @@ -35,8 +35,13 @@ import { getU64Encoder, transformEncoder, } from "@solana/kit"; +import { + findLendingMarketAuthPda, + findReserveCollateralMintPda, + findReserveLiquiditySupplyPda, +} from "../pdas/index.js"; import { KAMINO_LENDING_PROGRAM_ADDRESS } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const REDEEM_RESERVE_COLLATERAL_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([234, 117, 181, 125, 185, 142, 220, 29]); @@ -58,8 +63,12 @@ export type RedeemReserveCollateralInstruction< TAccountReserveLiquiditySupply extends string | AccountMeta = string, TAccountUserSourceCollateral extends string | AccountMeta = string, TAccountUserDestinationLiquidity extends string | AccountMeta = string, - TAccountCollateralTokenProgram extends string | AccountMeta = string, - TAccountLiquidityTokenProgram extends string | AccountMeta = string, + TAccountCollateralTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TAccountLiquidityTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", TAccountInstructionSysvarAccount extends | string | AccountMeta = "Sysvar1nstructions1111111111111111111111111", @@ -148,6 +157,206 @@ export function getRedeemReserveCollateralInstructionDataCodec(): FixedSizeCodec ); } +export interface RedeemReserveCollateralAsyncInput< + TAccountOwner extends string = string, + TAccountLendingMarket extends string = string, + TAccountReserve extends string = string, + TAccountLendingMarketAuthority extends string = string, + TAccountReserveLiquidityMint extends string = string, + TAccountReserveCollateralMint extends string = string, + TAccountReserveLiquiditySupply extends string = string, + TAccountUserSourceCollateral extends string = string, + TAccountUserDestinationLiquidity extends string = string, + TAccountCollateralTokenProgram extends string = string, + TAccountLiquidityTokenProgram extends string = string, + TAccountInstructionSysvarAccount extends string = string, +> { + owner: TransactionSigner; + lendingMarket: Address; + reserve: Address; + lendingMarketAuthority?: Address; + reserveLiquidityMint: Address; + reserveCollateralMint?: Address; + reserveLiquiditySupply?: Address; + userSourceCollateral: Address; + userDestinationLiquidity: Address; + collateralTokenProgram?: Address; + liquidityTokenProgram?: Address; + instructionSysvarAccount?: Address; + collateralAmount: RedeemReserveCollateralInstructionDataArgs["collateralAmount"]; +} + +export async function getRedeemReserveCollateralInstructionAsync< + TAccountOwner extends string, + TAccountLendingMarket extends string, + TAccountReserve extends string, + TAccountLendingMarketAuthority extends string, + TAccountReserveLiquidityMint extends string, + TAccountReserveCollateralMint extends string, + TAccountReserveLiquiditySupply extends string, + TAccountUserSourceCollateral extends string, + TAccountUserDestinationLiquidity extends string, + TAccountCollateralTokenProgram extends string, + TAccountLiquidityTokenProgram extends string, + TAccountInstructionSysvarAccount extends string, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, +>( + input: RedeemReserveCollateralAsyncInput< + TAccountOwner, + TAccountLendingMarket, + TAccountReserve, + TAccountLendingMarketAuthority, + TAccountReserveLiquidityMint, + TAccountReserveCollateralMint, + TAccountReserveLiquiditySupply, + TAccountUserSourceCollateral, + TAccountUserDestinationLiquidity, + TAccountCollateralTokenProgram, + TAccountLiquidityTokenProgram, + TAccountInstructionSysvarAccount + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + RedeemReserveCollateralInstruction< + TProgramAddress, + TAccountOwner, + TAccountLendingMarket, + TAccountReserve, + TAccountLendingMarketAuthority, + TAccountReserveLiquidityMint, + TAccountReserveCollateralMint, + TAccountReserveLiquiditySupply, + TAccountUserSourceCollateral, + TAccountUserDestinationLiquidity, + TAccountCollateralTokenProgram, + TAccountLiquidityTokenProgram, + TAccountInstructionSysvarAccount + > +> { + // Program address. + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + owner: { value: input.owner ?? null, isWritable: false }, + lendingMarket: { value: input.lendingMarket ?? null, isWritable: false }, + reserve: { value: input.reserve ?? null, isWritable: true }, + lendingMarketAuthority: { + value: input.lendingMarketAuthority ?? null, + isWritable: false, + }, + reserveLiquidityMint: { + value: input.reserveLiquidityMint ?? null, + isWritable: false, + }, + reserveCollateralMint: { + value: input.reserveCollateralMint ?? null, + isWritable: true, + }, + reserveLiquiditySupply: { + value: input.reserveLiquiditySupply ?? null, + isWritable: true, + }, + userSourceCollateral: { + value: input.userSourceCollateral ?? null, + isWritable: true, + }, + userDestinationLiquidity: { + value: input.userDestinationLiquidity ?? null, + isWritable: true, + }, + collateralTokenProgram: { + value: input.collateralTokenProgram ?? null, + isWritable: false, + }, + liquidityTokenProgram: { + value: input.liquidityTokenProgram ?? null, + isWritable: false, + }, + instructionSysvarAccount: { + value: input.instructionSysvarAccount ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.lendingMarketAuthority.value) { + accounts.lendingMarketAuthority.value = await findLendingMarketAuthPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + }); + } + if (!accounts.reserveCollateralMint.value) { + accounts.reserveCollateralMint.value = await findReserveCollateralMintPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + mint: expectAddress(accounts.reserveLiquidityMint.value), + }); + } + if (!accounts.reserveLiquiditySupply.value) { + accounts.reserveLiquiditySupply.value = await findReserveLiquiditySupplyPda( + { + lendingMarket: expectAddress(accounts.lendingMarket.value), + mint: expectAddress(accounts.reserveLiquidityMint.value), + }, + ); + } + if (!accounts.collateralTokenProgram.value) { + accounts.collateralTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.liquidityTokenProgram.value) { + accounts.liquidityTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.instructionSysvarAccount.value) { + accounts.instructionSysvarAccount.value = + "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.owner), + getAccountMeta(accounts.lendingMarket), + getAccountMeta(accounts.reserve), + getAccountMeta(accounts.lendingMarketAuthority), + getAccountMeta(accounts.reserveLiquidityMint), + getAccountMeta(accounts.reserveCollateralMint), + getAccountMeta(accounts.reserveLiquiditySupply), + getAccountMeta(accounts.userSourceCollateral), + getAccountMeta(accounts.userDestinationLiquidity), + getAccountMeta(accounts.collateralTokenProgram), + getAccountMeta(accounts.liquidityTokenProgram), + getAccountMeta(accounts.instructionSysvarAccount), + ], + data: getRedeemReserveCollateralInstructionDataEncoder().encode( + args as RedeemReserveCollateralInstructionDataArgs, + ), + programAddress, + } as RedeemReserveCollateralInstruction< + TProgramAddress, + TAccountOwner, + TAccountLendingMarket, + TAccountReserve, + TAccountLendingMarketAuthority, + TAccountReserveLiquidityMint, + TAccountReserveCollateralMint, + TAccountReserveLiquiditySupply, + TAccountUserSourceCollateral, + TAccountUserDestinationLiquidity, + TAccountCollateralTokenProgram, + TAccountLiquidityTokenProgram, + TAccountInstructionSysvarAccount + >); +} + export interface RedeemReserveCollateralInput< TAccountOwner extends string = string, TAccountLendingMarket extends string = string, @@ -171,8 +380,8 @@ export interface RedeemReserveCollateralInput< reserveLiquiditySupply: Address; userSourceCollateral: Address; userDestinationLiquidity: Address; - collateralTokenProgram: Address; - liquidityTokenProgram: Address; + collateralTokenProgram?: Address; + liquidityTokenProgram?: Address; instructionSysvarAccount?: Address; collateralAmount: RedeemReserveCollateralInstructionDataArgs["collateralAmount"]; } @@ -277,6 +486,14 @@ export function getRedeemReserveCollateralInstruction< const args = { ...input }; // Resolve default values. + if (!accounts.collateralTokenProgram.value) { + accounts.collateralTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.liquidityTokenProgram.value) { + accounts.liquidityTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } if (!accounts.instructionSysvarAccount.value) { accounts.instructionSysvarAccount.value = "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; diff --git a/clients/kamino-lending/src/generated/instructions/refreshObligationFarmsForReserve.ts b/clients/kamino-lending/src/generated/instructions/refreshObligationFarmsForReserve.ts index f078826e..b64fe997 100644 --- a/clients/kamino-lending/src/generated/instructions/refreshObligationFarmsForReserve.ts +++ b/clients/kamino-lending/src/generated/instructions/refreshObligationFarmsForReserve.ts @@ -35,11 +35,12 @@ import { getU8Encoder, transformEncoder, } from "@solana/kit"; +import { findLendingMarketAuthPda } from "../pdas/index.js"; import { FARMS_PROGRAM_ADDRESS, KAMINO_LENDING_PROGRAM_ADDRESS, } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const REFRESH_OBLIGATION_FARMS_FOR_RESERVE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([140, 144, 253, 21, 10, 74, 248, 3]); @@ -147,6 +148,158 @@ export function getRefreshObligationFarmsForReserveInstructionDataCodec(): Fixed ); } +export interface RefreshObligationFarmsForReserveAsyncInput< + TAccountCrank extends string = string, + TAccountObligation extends string = string, + TAccountLendingMarketAuthority extends string = string, + TAccountReserve extends string = string, + TAccountReserveFarmState extends string = string, + TAccountObligationFarmUserState extends string = string, + TAccountLendingMarket extends string = string, + TAccountFarmsProgram extends string = string, + TAccountRent extends string = string, + TAccountSystemProgram extends string = string, +> { + crank: TransactionSigner; + obligation: Address; + lendingMarketAuthority?: Address; + reserve: Address; + reserveFarmState: Address; + obligationFarmUserState: Address; + lendingMarket: Address; + farmsProgram?: Address; + rent?: Address; + systemProgram?: Address; + mode: RefreshObligationFarmsForReserveInstructionDataArgs["mode"]; +} + +export async function getRefreshObligationFarmsForReserveInstructionAsync< + TAccountCrank extends string, + TAccountObligation extends string, + TAccountLendingMarketAuthority extends string, + TAccountReserve extends string, + TAccountReserveFarmState extends string, + TAccountObligationFarmUserState extends string, + TAccountLendingMarket extends string, + TAccountFarmsProgram extends string, + TAccountRent extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, +>( + input: RefreshObligationFarmsForReserveAsyncInput< + TAccountCrank, + TAccountObligation, + TAccountLendingMarketAuthority, + TAccountReserve, + TAccountReserveFarmState, + TAccountObligationFarmUserState, + TAccountLendingMarket, + TAccountFarmsProgram, + TAccountRent, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + RefreshObligationFarmsForReserveInstruction< + TProgramAddress, + TAccountCrank, + TAccountObligation, + TAccountLendingMarketAuthority, + TAccountReserve, + TAccountReserveFarmState, + TAccountObligationFarmUserState, + TAccountLendingMarket, + TAccountFarmsProgram, + TAccountRent, + TAccountSystemProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + crank: { value: input.crank ?? null, isWritable: false }, + obligation: { value: input.obligation ?? null, isWritable: false }, + lendingMarketAuthority: { + value: input.lendingMarketAuthority ?? null, + isWritable: false, + }, + reserve: { value: input.reserve ?? null, isWritable: false }, + reserveFarmState: { + value: input.reserveFarmState ?? null, + isWritable: true, + }, + obligationFarmUserState: { + value: input.obligationFarmUserState ?? null, + isWritable: true, + }, + lendingMarket: { value: input.lendingMarket ?? null, isWritable: false }, + farmsProgram: { value: input.farmsProgram ?? null, isWritable: false }, + rent: { value: input.rent ?? null, isWritable: false }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.lendingMarketAuthority.value) { + accounts.lendingMarketAuthority.value = await findLendingMarketAuthPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + }); + } + if (!accounts.farmsProgram.value) { + accounts.farmsProgram.value = FARMS_PROGRAM_ADDRESS; + accounts.farmsProgram.isWritable = false; + } + if (!accounts.rent.value) { + accounts.rent.value = + "SysvarRent111111111111111111111111111111111" as Address<"SysvarRent111111111111111111111111111111111">; + } + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.crank), + getAccountMeta(accounts.obligation), + getAccountMeta(accounts.lendingMarketAuthority), + getAccountMeta(accounts.reserve), + getAccountMeta(accounts.reserveFarmState), + getAccountMeta(accounts.obligationFarmUserState), + getAccountMeta(accounts.lendingMarket), + getAccountMeta(accounts.farmsProgram), + getAccountMeta(accounts.rent), + getAccountMeta(accounts.systemProgram), + ], + data: getRefreshObligationFarmsForReserveInstructionDataEncoder().encode( + args as RefreshObligationFarmsForReserveInstructionDataArgs, + ), + programAddress, + } as RefreshObligationFarmsForReserveInstruction< + TProgramAddress, + TAccountCrank, + TAccountObligation, + TAccountLendingMarketAuthority, + TAccountReserve, + TAccountReserveFarmState, + TAccountObligationFarmUserState, + TAccountLendingMarket, + TAccountFarmsProgram, + TAccountRent, + TAccountSystemProgram + >); +} + export interface RefreshObligationFarmsForReserveInput< TAccountCrank extends string = string, TAccountObligation extends string = string, diff --git a/clients/kamino-lending/src/generated/instructions/repayAndWithdrawAndRedeem.ts b/clients/kamino-lending/src/generated/instructions/repayAndWithdrawAndRedeem.ts index 39f9e428..bb1d6578 100644 --- a/clients/kamino-lending/src/generated/instructions/repayAndWithdrawAndRedeem.ts +++ b/clients/kamino-lending/src/generated/instructions/repayAndWithdrawAndRedeem.ts @@ -69,7 +69,7 @@ export type RepayAndWithdrawAndRedeemInstruction< TAccountRepayAccountsTokenProgram extends string | AccountMeta = string, TAccountRepayAccountsInstructionSysvarAccount extends | string - | AccountMeta = "Sysvar1nstructions1111111111111111111111111", + | AccountMeta = string, TAccountWithdrawAccountsOwner extends string | AccountMeta = string, TAccountWithdrawAccountsObligation extends string | AccountMeta = string, TAccountWithdrawAccountsLendingMarket extends string | AccountMeta = string, @@ -103,7 +103,7 @@ export type RepayAndWithdrawAndRedeemInstruction< | AccountMeta = string, TAccountWithdrawAccountsInstructionSysvarAccount extends | string - | AccountMeta = "Sysvar1nstructions1111111111111111111111111", + | AccountMeta = string, TAccountCollateralFarmsAccountsObligationFarmUserState extends | string | AccountMeta = string, @@ -297,7 +297,7 @@ export interface RepayAndWithdrawAndRedeemInput< repayAccountsReserveDestinationLiquidity: Address; repayAccountsUserSourceLiquidity: Address; repayAccountsTokenProgram: Address; - repayAccountsInstructionSysvarAccount?: Address; + repayAccountsInstructionSysvarAccount: Address; withdrawAccountsOwner: TransactionSigner; withdrawAccountsObligation: Address; withdrawAccountsLendingMarket: Address; @@ -311,7 +311,7 @@ export interface RepayAndWithdrawAndRedeemInput< withdrawAccountsPlaceholderUserDestinationCollateral?: Address; withdrawAccountsCollateralTokenProgram: Address; withdrawAccountsLiquidityTokenProgram: Address; - withdrawAccountsInstructionSysvarAccount?: Address; + withdrawAccountsInstructionSysvarAccount: Address; collateralFarmsAccountsObligationFarmUserState?: Address; collateralFarmsAccountsReserveFarmState?: Address; repayDebtFarmsAccountsObligationFarmUserState?: Address; @@ -539,14 +539,6 @@ export function getRepayAndWithdrawAndRedeemInstruction< const args = { ...input }; // Resolve default values. - if (!accounts.repayAccountsInstructionSysvarAccount.value) { - accounts.repayAccountsInstructionSysvarAccount.value = - "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; - } - if (!accounts.withdrawAccountsInstructionSysvarAccount.value) { - accounts.withdrawAccountsInstructionSysvarAccount.value = - "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; - } if (!accounts.farmsProgram.value) { accounts.farmsProgram.value = FARMS_PROGRAM_ADDRESS; accounts.farmsProgram.isWritable = false; diff --git a/clients/kamino-lending/src/generated/instructions/repayObligationLiquidityV2.ts b/clients/kamino-lending/src/generated/instructions/repayObligationLiquidityV2.ts index 6c5b6ef8..f4f75978 100644 --- a/clients/kamino-lending/src/generated/instructions/repayObligationLiquidityV2.ts +++ b/clients/kamino-lending/src/generated/instructions/repayObligationLiquidityV2.ts @@ -35,11 +35,12 @@ import { getU64Encoder, transformEncoder, } from "@solana/kit"; +import { findLendingMarketAuthPda } from "../pdas/index.js"; import { FARMS_PROGRAM_ADDRESS, KAMINO_LENDING_PROGRAM_ADDRESS, } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const REPAY_OBLIGATION_LIQUIDITY_V2_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([116, 174, 213, 76, 180, 53, 210, 144]); @@ -159,6 +160,194 @@ export function getRepayObligationLiquidityV2InstructionDataCodec(): FixedSizeCo ); } +export interface RepayObligationLiquidityV2AsyncInput< + TAccountOwner extends string = string, + TAccountObligation extends string = string, + TAccountLendingMarket extends string = string, + TAccountRepayReserve extends string = string, + TAccountReserveLiquidityMint extends string = string, + TAccountReserveDestinationLiquidity extends string = string, + TAccountUserSourceLiquidity extends string = string, + TAccountTokenProgram extends string = string, + TAccountInstructionSysvarAccount extends string = string, + TAccountObligationFarmUserState extends string = string, + TAccountReserveFarmState extends string = string, + TAccountLendingMarketAuthority extends string = string, + TAccountFarmsProgram extends string = string, +> { + owner: TransactionSigner; + obligation: Address; + lendingMarket: Address; + repayReserve: Address; + reserveLiquidityMint: Address; + reserveDestinationLiquidity: Address; + userSourceLiquidity: Address; + tokenProgram?: Address; + instructionSysvarAccount?: Address; + obligationFarmUserState?: Address; + reserveFarmState?: Address; + lendingMarketAuthority?: Address; + farmsProgram?: Address; + liquidityAmount: RepayObligationLiquidityV2InstructionDataArgs["liquidityAmount"]; +} + +export async function getRepayObligationLiquidityV2InstructionAsync< + TAccountOwner extends string, + TAccountObligation extends string, + TAccountLendingMarket extends string, + TAccountRepayReserve extends string, + TAccountReserveLiquidityMint extends string, + TAccountReserveDestinationLiquidity extends string, + TAccountUserSourceLiquidity extends string, + TAccountTokenProgram extends string, + TAccountInstructionSysvarAccount extends string, + TAccountObligationFarmUserState extends string, + TAccountReserveFarmState extends string, + TAccountLendingMarketAuthority extends string, + TAccountFarmsProgram extends string, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, +>( + input: RepayObligationLiquidityV2AsyncInput< + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountRepayReserve, + TAccountReserveLiquidityMint, + TAccountReserveDestinationLiquidity, + TAccountUserSourceLiquidity, + TAccountTokenProgram, + TAccountInstructionSysvarAccount, + TAccountObligationFarmUserState, + TAccountReserveFarmState, + TAccountLendingMarketAuthority, + TAccountFarmsProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + RepayObligationLiquidityV2Instruction< + TProgramAddress, + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountRepayReserve, + TAccountReserveLiquidityMint, + TAccountReserveDestinationLiquidity, + TAccountUserSourceLiquidity, + TAccountTokenProgram, + TAccountInstructionSysvarAccount, + TAccountObligationFarmUserState, + TAccountReserveFarmState, + TAccountLendingMarketAuthority, + TAccountFarmsProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + owner: { value: input.owner ?? null, isWritable: false }, + obligation: { value: input.obligation ?? null, isWritable: true }, + lendingMarket: { value: input.lendingMarket ?? null, isWritable: false }, + repayReserve: { value: input.repayReserve ?? null, isWritable: true }, + reserveLiquidityMint: { + value: input.reserveLiquidityMint ?? null, + isWritable: false, + }, + reserveDestinationLiquidity: { + value: input.reserveDestinationLiquidity ?? null, + isWritable: true, + }, + userSourceLiquidity: { + value: input.userSourceLiquidity ?? null, + isWritable: true, + }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + instructionSysvarAccount: { + value: input.instructionSysvarAccount ?? null, + isWritable: false, + }, + obligationFarmUserState: { + value: input.obligationFarmUserState ?? null, + isWritable: true, + }, + reserveFarmState: { + value: input.reserveFarmState ?? null, + isWritable: true, + }, + lendingMarketAuthority: { + value: input.lendingMarketAuthority ?? null, + isWritable: false, + }, + farmsProgram: { value: input.farmsProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.instructionSysvarAccount.value) { + accounts.instructionSysvarAccount.value = + "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; + } + if (!accounts.lendingMarketAuthority.value) { + accounts.lendingMarketAuthority.value = await findLendingMarketAuthPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + }); + } + if (!accounts.farmsProgram.value) { + accounts.farmsProgram.value = FARMS_PROGRAM_ADDRESS; + accounts.farmsProgram.isWritable = false; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.owner), + getAccountMeta(accounts.obligation), + getAccountMeta(accounts.lendingMarket), + getAccountMeta(accounts.repayReserve), + getAccountMeta(accounts.reserveLiquidityMint), + getAccountMeta(accounts.reserveDestinationLiquidity), + getAccountMeta(accounts.userSourceLiquidity), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.instructionSysvarAccount), + getAccountMeta(accounts.obligationFarmUserState), + getAccountMeta(accounts.reserveFarmState), + getAccountMeta(accounts.lendingMarketAuthority), + getAccountMeta(accounts.farmsProgram), + ], + data: getRepayObligationLiquidityV2InstructionDataEncoder().encode( + args as RepayObligationLiquidityV2InstructionDataArgs, + ), + programAddress, + } as RepayObligationLiquidityV2Instruction< + TProgramAddress, + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountRepayReserve, + TAccountReserveLiquidityMint, + TAccountReserveDestinationLiquidity, + TAccountUserSourceLiquidity, + TAccountTokenProgram, + TAccountInstructionSysvarAccount, + TAccountObligationFarmUserState, + TAccountReserveFarmState, + TAccountLendingMarketAuthority, + TAccountFarmsProgram + >); +} + export interface RepayObligationLiquidityV2Input< TAccountOwner extends string = string, TAccountObligation extends string = string, diff --git a/clients/kamino-lending/src/generated/instructions/setObligationOrder.ts b/clients/kamino-lending/src/generated/instructions/setObligationOrder.ts new file mode 100644 index 00000000..29d1fd4e --- /dev/null +++ b/clients/kamino-lending/src/generated/instructions/setObligationOrder.ts @@ -0,0 +1,234 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import type { + ObligationOrderInput, + ObligationOrderInputArgs, +} from "../types/index.js"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, +} from "@solana/kit"; +import { KAMINO_LENDING_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; +import { + getObligationOrderInputDecoder, + getObligationOrderInputEncoder, +} from "../types/index.js"; + +export const SET_OBLIGATION_ORDER_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([81, 1, 99, 156, 211, 83, 78, 46]); + +export function getSetObligationOrderDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + SET_OBLIGATION_ORDER_DISCRIMINATOR, + ); +} + +export type SetObligationOrderInstruction< + TProgram extends string = typeof KAMINO_LENDING_PROGRAM_ADDRESS, + TAccountOwner extends string | AccountMeta = string, + TAccountObligation extends string | AccountMeta = string, + TAccountLendingMarket extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountOwner extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountOwner, + TAccountObligation extends string + ? WritableAccount + : TAccountObligation, + TAccountLendingMarket extends string + ? ReadonlyAccount + : TAccountLendingMarket, + ...TRemainingAccounts, + ] + >; + +export interface SetObligationOrderInstructionData { + discriminator: ReadonlyUint8Array; + index: number; + order: ObligationOrderInput; +} + +export interface SetObligationOrderInstructionDataArgs { + index: number; + order: ObligationOrderInputArgs; +} + +export function getSetObligationOrderInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["index", getU8Encoder()], + ["order", getObligationOrderInputEncoder()], + ]), + (value) => ({ + ...value, + discriminator: SET_OBLIGATION_ORDER_DISCRIMINATOR, + }), + ); +} + +export function getSetObligationOrderInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["index", getU8Decoder()], + ["order", getObligationOrderInputDecoder()], + ]); +} + +export function getSetObligationOrderInstructionDataCodec(): FixedSizeCodec< + SetObligationOrderInstructionDataArgs, + SetObligationOrderInstructionData +> { + return combineCodec( + getSetObligationOrderInstructionDataEncoder(), + getSetObligationOrderInstructionDataDecoder(), + ); +} + +export interface SetObligationOrderInput< + TAccountOwner extends string = string, + TAccountObligation extends string = string, + TAccountLendingMarket extends string = string, +> { + owner: TransactionSigner; + obligation: Address; + lendingMarket: Address; + index: SetObligationOrderInstructionDataArgs["index"]; + order: SetObligationOrderInstructionDataArgs["order"]; +} + +export function getSetObligationOrderInstruction< + TAccountOwner extends string, + TAccountObligation extends string, + TAccountLendingMarket extends string, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, +>( + input: SetObligationOrderInput< + TAccountOwner, + TAccountObligation, + TAccountLendingMarket + >, + config?: { programAddress?: TProgramAddress }, +): SetObligationOrderInstruction< + TProgramAddress, + TAccountOwner, + TAccountObligation, + TAccountLendingMarket +> { + // Program address. + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + owner: { value: input.owner ?? null, isWritable: false }, + obligation: { value: input.obligation ?? null, isWritable: true }, + lendingMarket: { value: input.lendingMarket ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.owner), + getAccountMeta(accounts.obligation), + getAccountMeta(accounts.lendingMarket), + ], + data: getSetObligationOrderInstructionDataEncoder().encode( + args as SetObligationOrderInstructionDataArgs, + ), + programAddress, + } as SetObligationOrderInstruction< + TProgramAddress, + TAccountOwner, + TAccountObligation, + TAccountLendingMarket + >); +} + +export interface ParsedSetObligationOrderInstruction< + TProgram extends string = typeof KAMINO_LENDING_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + owner: TAccountMetas[0]; + obligation: TAccountMetas[1]; + lendingMarket: TAccountMetas[2]; + }; + data: SetObligationOrderInstructionData; +} + +export function parseSetObligationOrderInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedSetObligationOrderInstruction { + if (instruction.accounts.length < 3) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + owner: getNextAccount(), + obligation: getNextAccount(), + lendingMarket: getNextAccount(), + }, + data: getSetObligationOrderInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/kamino-lending/src/generated/instructions/socializeLossV2.ts b/clients/kamino-lending/src/generated/instructions/socializeLossV2.ts index b686dee7..c44b4161 100644 --- a/clients/kamino-lending/src/generated/instructions/socializeLossV2.ts +++ b/clients/kamino-lending/src/generated/instructions/socializeLossV2.ts @@ -35,11 +35,12 @@ import { getU64Encoder, transformEncoder, } from "@solana/kit"; +import { findLendingMarketAuthPda } from "../pdas/index.js"; import { FARMS_PROGRAM_ADDRESS, KAMINO_LENDING_PROGRAM_ADDRESS, } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const SOCIALIZE_LOSS_V2_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([238, 95, 98, 220, 187, 40, 204, 154]); @@ -138,6 +139,149 @@ export function getSocializeLossV2InstructionDataCodec(): FixedSizeCodec< ); } +export interface SocializeLossV2AsyncInput< + TAccountRiskCouncil extends string = string, + TAccountObligation extends string = string, + TAccountLendingMarket extends string = string, + TAccountReserve extends string = string, + TAccountInstructionSysvarAccount extends string = string, + TAccountObligationFarmUserState extends string = string, + TAccountReserveFarmState extends string = string, + TAccountLendingMarketAuthority extends string = string, + TAccountFarmsProgram extends string = string, +> { + riskCouncil: TransactionSigner; + obligation: Address; + lendingMarket: Address; + reserve: Address; + instructionSysvarAccount?: Address; + obligationFarmUserState?: Address; + reserveFarmState?: Address; + lendingMarketAuthority?: Address; + farmsProgram?: Address; + liquidityAmount: SocializeLossV2InstructionDataArgs["liquidityAmount"]; +} + +export async function getSocializeLossV2InstructionAsync< + TAccountRiskCouncil extends string, + TAccountObligation extends string, + TAccountLendingMarket extends string, + TAccountReserve extends string, + TAccountInstructionSysvarAccount extends string, + TAccountObligationFarmUserState extends string, + TAccountReserveFarmState extends string, + TAccountLendingMarketAuthority extends string, + TAccountFarmsProgram extends string, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, +>( + input: SocializeLossV2AsyncInput< + TAccountRiskCouncil, + TAccountObligation, + TAccountLendingMarket, + TAccountReserve, + TAccountInstructionSysvarAccount, + TAccountObligationFarmUserState, + TAccountReserveFarmState, + TAccountLendingMarketAuthority, + TAccountFarmsProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + SocializeLossV2Instruction< + TProgramAddress, + TAccountRiskCouncil, + TAccountObligation, + TAccountLendingMarket, + TAccountReserve, + TAccountInstructionSysvarAccount, + TAccountObligationFarmUserState, + TAccountReserveFarmState, + TAccountLendingMarketAuthority, + TAccountFarmsProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + riskCouncil: { value: input.riskCouncil ?? null, isWritable: false }, + obligation: { value: input.obligation ?? null, isWritable: true }, + lendingMarket: { value: input.lendingMarket ?? null, isWritable: false }, + reserve: { value: input.reserve ?? null, isWritable: true }, + instructionSysvarAccount: { + value: input.instructionSysvarAccount ?? null, + isWritable: false, + }, + obligationFarmUserState: { + value: input.obligationFarmUserState ?? null, + isWritable: true, + }, + reserveFarmState: { + value: input.reserveFarmState ?? null, + isWritable: true, + }, + lendingMarketAuthority: { + value: input.lendingMarketAuthority ?? null, + isWritable: false, + }, + farmsProgram: { value: input.farmsProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.instructionSysvarAccount.value) { + accounts.instructionSysvarAccount.value = + "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; + } + if (!accounts.lendingMarketAuthority.value) { + accounts.lendingMarketAuthority.value = await findLendingMarketAuthPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + }); + } + if (!accounts.farmsProgram.value) { + accounts.farmsProgram.value = FARMS_PROGRAM_ADDRESS; + accounts.farmsProgram.isWritable = false; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.riskCouncil), + getAccountMeta(accounts.obligation), + getAccountMeta(accounts.lendingMarket), + getAccountMeta(accounts.reserve), + getAccountMeta(accounts.instructionSysvarAccount), + getAccountMeta(accounts.obligationFarmUserState), + getAccountMeta(accounts.reserveFarmState), + getAccountMeta(accounts.lendingMarketAuthority), + getAccountMeta(accounts.farmsProgram), + ], + data: getSocializeLossV2InstructionDataEncoder().encode( + args as SocializeLossV2InstructionDataArgs, + ), + programAddress, + } as SocializeLossV2Instruction< + TProgramAddress, + TAccountRiskCouncil, + TAccountObligation, + TAccountLendingMarket, + TAccountReserve, + TAccountInstructionSysvarAccount, + TAccountObligationFarmUserState, + TAccountReserveFarmState, + TAccountLendingMarketAuthority, + TAccountFarmsProgram + >); +} + export interface SocializeLossV2Input< TAccountRiskCouncil extends string = string, TAccountObligation extends string = string, diff --git a/clients/kamino-lending/src/generated/instructions/stake.ts b/clients/kamino-lending/src/generated/instructions/stake.ts index e23975d6..f9edcb31 100644 --- a/clients/kamino-lending/src/generated/instructions/stake.ts +++ b/clients/kamino-lending/src/generated/instructions/stake.ts @@ -35,8 +35,9 @@ import { getU64Encoder, transformEncoder, } from "@solana/kit"; +import { findFarmsUserStatePda, findFarmVaultPda } from "../pdas/index.js"; import { FARMS_PROGRAM_ADDRESS } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const STAKE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ 206, 176, 202, 18, 200, 209, 179, 108, @@ -128,6 +129,131 @@ export function getStakeInstructionDataCodec(): FixedSizeCodec< ); } +export interface StakeAsyncInput< + TAccountOwner extends string = string, + TAccountUserState extends string = string, + TAccountFarmState extends string = string, + TAccountFarmVault extends string = string, + TAccountUserAta extends string = string, + TAccountTokenMint extends string = string, + TAccountScopePrices extends string = string, + TAccountTokenProgram extends string = string, +> { + owner: TransactionSigner; + userState?: Address; + farmState: Address; + farmVault?: Address; + userAta: Address; + tokenMint: Address; + scopePrices?: Address; + tokenProgram?: Address; + amount: StakeInstructionDataArgs["amount"]; +} + +export async function getStakeInstructionAsync< + TAccountOwner extends string, + TAccountUserState extends string, + TAccountFarmState extends string, + TAccountFarmVault extends string, + TAccountUserAta extends string, + TAccountTokenMint extends string, + TAccountScopePrices extends string, + TAccountTokenProgram extends string, + TProgramAddress extends Address = typeof FARMS_PROGRAM_ADDRESS, +>( + input: StakeAsyncInput< + TAccountOwner, + TAccountUserState, + TAccountFarmState, + TAccountFarmVault, + TAccountUserAta, + TAccountTokenMint, + TAccountScopePrices, + TAccountTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + StakeInstruction< + TProgramAddress, + TAccountOwner, + TAccountUserState, + TAccountFarmState, + TAccountFarmVault, + TAccountUserAta, + TAccountTokenMint, + TAccountScopePrices, + TAccountTokenProgram + > +> { + // Program address. + const programAddress = config?.programAddress ?? FARMS_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + owner: { value: input.owner ?? null, isWritable: false }, + userState: { value: input.userState ?? null, isWritable: true }, + farmState: { value: input.farmState ?? null, isWritable: true }, + farmVault: { value: input.farmVault ?? null, isWritable: true }, + userAta: { value: input.userAta ?? null, isWritable: true }, + tokenMint: { value: input.tokenMint ?? null, isWritable: false }, + scopePrices: { value: input.scopePrices ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.userState.value) { + accounts.userState.value = await findFarmsUserStatePda({ + farmState: expectAddress(accounts.farmState.value), + owner: expectAddress(accounts.owner.value), + }); + } + if (!accounts.farmVault.value) { + accounts.farmVault.value = await findFarmVaultPda({ + farmState: expectAddress(accounts.farmState.value), + tokenMint: expectAddress(accounts.tokenMint.value), + }); + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.owner), + getAccountMeta(accounts.userState), + getAccountMeta(accounts.farmState), + getAccountMeta(accounts.farmVault), + getAccountMeta(accounts.userAta), + getAccountMeta(accounts.tokenMint), + getAccountMeta(accounts.scopePrices), + getAccountMeta(accounts.tokenProgram), + ], + data: getStakeInstructionDataEncoder().encode( + args as StakeInstructionDataArgs, + ), + programAddress, + } as StakeInstruction< + TProgramAddress, + TAccountOwner, + TAccountUserState, + TAccountFarmState, + TAccountFarmVault, + TAccountUserAta, + TAccountTokenMint, + TAccountScopePrices, + TAccountTokenProgram + >); +} + export interface StakeInput< TAccountOwner extends string = string, TAccountUserState extends string = string, diff --git a/clients/kamino-lending/src/generated/instructions/unstake.ts b/clients/kamino-lending/src/generated/instructions/unstake.ts index 9ed622f2..8c3c99c5 100644 --- a/clients/kamino-lending/src/generated/instructions/unstake.ts +++ b/clients/kamino-lending/src/generated/instructions/unstake.ts @@ -35,8 +35,9 @@ import { getU128Encoder, transformEncoder, } from "@solana/kit"; +import { findFarmsUserStatePda } from "../pdas/index.js"; import { FARMS_PROGRAM_ADDRESS } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const UNSTAKE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ 90, 95, 107, 42, 205, 124, 50, 225, @@ -110,6 +111,89 @@ export function getUnstakeInstructionDataCodec(): FixedSizeCodec< ); } +export interface UnstakeAsyncInput< + TAccountOwner extends string = string, + TAccountUserState extends string = string, + TAccountFarmState extends string = string, + TAccountScopePrices extends string = string, +> { + owner: TransactionSigner; + userState?: Address; + farmState: Address; + scopePrices?: Address; + stakeSharesScaled: UnstakeInstructionDataArgs["stakeSharesScaled"]; +} + +export async function getUnstakeInstructionAsync< + TAccountOwner extends string, + TAccountUserState extends string, + TAccountFarmState extends string, + TAccountScopePrices extends string, + TProgramAddress extends Address = typeof FARMS_PROGRAM_ADDRESS, +>( + input: UnstakeAsyncInput< + TAccountOwner, + TAccountUserState, + TAccountFarmState, + TAccountScopePrices + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + UnstakeInstruction< + TProgramAddress, + TAccountOwner, + TAccountUserState, + TAccountFarmState, + TAccountScopePrices + > +> { + // Program address. + const programAddress = config?.programAddress ?? FARMS_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + owner: { value: input.owner ?? null, isWritable: true }, + userState: { value: input.userState ?? null, isWritable: true }, + farmState: { value: input.farmState ?? null, isWritable: true }, + scopePrices: { value: input.scopePrices ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.userState.value) { + accounts.userState.value = await findFarmsUserStatePda({ + farmState: expectAddress(accounts.farmState.value), + owner: expectAddress(accounts.owner.value), + }); + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.owner), + getAccountMeta(accounts.userState), + getAccountMeta(accounts.farmState), + getAccountMeta(accounts.scopePrices), + ], + data: getUnstakeInstructionDataEncoder().encode( + args as UnstakeInstructionDataArgs, + ), + programAddress, + } as UnstakeInstruction< + TProgramAddress, + TAccountOwner, + TAccountUserState, + TAccountFarmState, + TAccountScopePrices + >); +} + export interface UnstakeInput< TAccountOwner extends string = string, TAccountUserState extends string = string, diff --git a/clients/kamino-lending/src/generated/instructions/updateGlobalConfig.ts b/clients/kamino-lending/src/generated/instructions/updateGlobalConfig.ts index 56e550d9..02918ca9 100644 --- a/clients/kamino-lending/src/generated/instructions/updateGlobalConfig.ts +++ b/clients/kamino-lending/src/generated/instructions/updateGlobalConfig.ts @@ -10,9 +10,9 @@ import type { AccountMeta, AccountSignerMeta, Address, - FixedSizeCodec, - FixedSizeDecoder, - FixedSizeEncoder, + Codec, + Decoder, + Encoder, Instruction, InstructionWithAccounts, InstructionWithData, @@ -22,22 +22,30 @@ import type { WritableAccount, } from "@solana/kit"; import type { ResolvedAccount } from "../shared/index.js"; +import type { + UpdateGlobalConfigMode, + UpdateGlobalConfigModeArgs, +} from "../types/index.js"; import { + addDecoderSizePrefix, + addEncoderSizePrefix, combineCodec, fixDecoderSize, fixEncoderSize, - getArrayDecoder, - getArrayEncoder, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, - getU8Decoder, - getU8Encoder, + getU32Decoder, + getU32Encoder, transformEncoder, } from "@solana/kit"; -import { FARMS_PROGRAM_ADDRESS } from "../programs/index.js"; +import { KAMINO_LENDING_PROGRAM_ADDRESS } from "../programs/index.js"; import { getAccountMetaFactory } from "../shared/index.js"; +import { + getUpdateGlobalConfigModeDecoder, + getUpdateGlobalConfigModeEncoder, +} from "../types/index.js"; export const UPDATE_GLOBAL_CONFIG_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([164, 84, 130, 189, 111, 58, 250, 200]); @@ -49,7 +57,7 @@ export function getUpdateGlobalConfigDiscriminatorBytes(): ReadonlyUint8Array { } export type UpdateGlobalConfigInstruction< - TProgram extends string = typeof FARMS_PROGRAM_ADDRESS, + TProgram extends string = typeof KAMINO_LENDING_PROGRAM_ADDRESS, TAccountGlobalAdmin extends string | AccountMeta = string, TAccountGlobalConfig extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], @@ -70,21 +78,21 @@ export type UpdateGlobalConfigInstruction< export interface UpdateGlobalConfigInstructionData { discriminator: ReadonlyUint8Array; - mode: number; - value: number[]; + mode: UpdateGlobalConfigMode; + value: ReadonlyUint8Array; } export interface UpdateGlobalConfigInstructionDataArgs { - mode: number; - value: number[]; + mode: UpdateGlobalConfigModeArgs; + value: ReadonlyUint8Array; } -export function getUpdateGlobalConfigInstructionDataEncoder(): FixedSizeEncoder { +export function getUpdateGlobalConfigInstructionDataEncoder(): Encoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], - ["mode", getU8Encoder()], - ["value", getArrayEncoder(getU8Encoder(), { size: 32 })], + ["mode", getUpdateGlobalConfigModeEncoder()], + ["value", addEncoderSizePrefix(getBytesEncoder(), getU32Encoder())], ]), (value) => ({ ...value, @@ -93,15 +101,15 @@ export function getUpdateGlobalConfigInstructionDataEncoder(): FixedSizeEncoder< ); } -export function getUpdateGlobalConfigInstructionDataDecoder(): FixedSizeDecoder { +export function getUpdateGlobalConfigInstructionDataDecoder(): Decoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], - ["mode", getU8Decoder()], - ["value", getArrayDecoder(getU8Decoder(), { size: 32 })], + ["mode", getUpdateGlobalConfigModeDecoder()], + ["value", addDecoderSizePrefix(getBytesDecoder(), getU32Decoder())], ]); } -export function getUpdateGlobalConfigInstructionDataCodec(): FixedSizeCodec< +export function getUpdateGlobalConfigInstructionDataCodec(): Codec< UpdateGlobalConfigInstructionDataArgs, UpdateGlobalConfigInstructionData > { @@ -124,7 +132,7 @@ export interface UpdateGlobalConfigInput< export function getUpdateGlobalConfigInstruction< TAccountGlobalAdmin extends string, TAccountGlobalConfig extends string, - TProgramAddress extends Address = typeof FARMS_PROGRAM_ADDRESS, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, >( input: UpdateGlobalConfigInput, config?: { programAddress?: TProgramAddress }, @@ -134,7 +142,8 @@ export function getUpdateGlobalConfigInstruction< TAccountGlobalConfig > { // Program address. - const programAddress = config?.programAddress ?? FARMS_PROGRAM_ADDRESS; + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { @@ -167,7 +176,7 @@ export function getUpdateGlobalConfigInstruction< } export interface ParsedUpdateGlobalConfigInstruction< - TProgram extends string = typeof FARMS_PROGRAM_ADDRESS, + TProgram extends string = typeof KAMINO_LENDING_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > { programAddress: Address; diff --git a/clients/kamino-lending/src/generated/instructions/updateGlobalConfigAdmin.ts b/clients/kamino-lending/src/generated/instructions/updateGlobalConfigAdmin.ts index f834ca5c..0cfd1760 100644 --- a/clients/kamino-lending/src/generated/instructions/updateGlobalConfigAdmin.ts +++ b/clients/kamino-lending/src/generated/instructions/updateGlobalConfigAdmin.ts @@ -32,7 +32,7 @@ import { getStructEncoder, transformEncoder, } from "@solana/kit"; -import { FARMS_PROGRAM_ADDRESS } from "../programs/index.js"; +import { KAMINO_LENDING_PROGRAM_ADDRESS } from "../programs/index.js"; import { getAccountMetaFactory } from "../shared/index.js"; export const UPDATE_GLOBAL_CONFIG_ADMIN_DISCRIMINATOR: ReadonlyUint8Array = @@ -45,18 +45,18 @@ export function getUpdateGlobalConfigAdminDiscriminatorBytes(): ReadonlyUint8Arr } export type UpdateGlobalConfigAdminInstruction< - TProgram extends string = typeof FARMS_PROGRAM_ADDRESS, - TAccountPendingGlobalAdmin extends string | AccountMeta = string, + TProgram extends string = typeof KAMINO_LENDING_PROGRAM_ADDRESS, + TAccountPendingAdmin extends string | AccountMeta = string, TAccountGlobalConfig extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], > = Instruction & InstructionWithData & InstructionWithAccounts< [ - TAccountPendingGlobalAdmin extends string - ? ReadonlySignerAccount & - AccountSignerMeta - : TAccountPendingGlobalAdmin, + TAccountPendingAdmin extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountPendingAdmin, TAccountGlobalConfig extends string ? WritableAccount : TAccountGlobalConfig, @@ -97,37 +97,35 @@ export function getUpdateGlobalConfigAdminInstructionDataCodec(): FixedSizeCodec } export interface UpdateGlobalConfigAdminInput< - TAccountPendingGlobalAdmin extends string = string, + TAccountPendingAdmin extends string = string, TAccountGlobalConfig extends string = string, > { - pendingGlobalAdmin: TransactionSigner; + pendingAdmin: TransactionSigner; globalConfig: Address; } export function getUpdateGlobalConfigAdminInstruction< - TAccountPendingGlobalAdmin extends string, + TAccountPendingAdmin extends string, TAccountGlobalConfig extends string, - TProgramAddress extends Address = typeof FARMS_PROGRAM_ADDRESS, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, >( input: UpdateGlobalConfigAdminInput< - TAccountPendingGlobalAdmin, + TAccountPendingAdmin, TAccountGlobalConfig >, config?: { programAddress?: TProgramAddress }, ): UpdateGlobalConfigAdminInstruction< TProgramAddress, - TAccountPendingGlobalAdmin, + TAccountPendingAdmin, TAccountGlobalConfig > { // Program address. - const programAddress = config?.programAddress ?? FARMS_PROGRAM_ADDRESS; + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { - pendingGlobalAdmin: { - value: input.pendingGlobalAdmin ?? null, - isWritable: false, - }, + pendingAdmin: { value: input.pendingAdmin ?? null, isWritable: false }, globalConfig: { value: input.globalConfig ?? null, isWritable: true }, }; const accounts = originalAccounts as Record< @@ -138,25 +136,25 @@ export function getUpdateGlobalConfigAdminInstruction< const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ - getAccountMeta(accounts.pendingGlobalAdmin), + getAccountMeta(accounts.pendingAdmin), getAccountMeta(accounts.globalConfig), ], data: getUpdateGlobalConfigAdminInstructionDataEncoder().encode({}), programAddress, } as UpdateGlobalConfigAdminInstruction< TProgramAddress, - TAccountPendingGlobalAdmin, + TAccountPendingAdmin, TAccountGlobalConfig >); } export interface ParsedUpdateGlobalConfigAdminInstruction< - TProgram extends string = typeof FARMS_PROGRAM_ADDRESS, + TProgram extends string = typeof KAMINO_LENDING_PROGRAM_ADDRESS, TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], > { programAddress: Address; accounts: { - pendingGlobalAdmin: TAccountMetas[0]; + pendingAdmin: TAccountMetas[0]; globalConfig: TAccountMetas[1]; }; data: UpdateGlobalConfigAdminInstructionData; @@ -183,7 +181,7 @@ export function parseUpdateGlobalConfigAdminInstruction< return { programAddress: instruction.programAddress, accounts: { - pendingGlobalAdmin: getNextAccount(), + pendingAdmin: getNextAccount(), globalConfig: getNextAccount(), }, data: getUpdateGlobalConfigAdminInstructionDataDecoder().decode( diff --git a/clients/kamino-lending/src/generated/instructions/updateReserveConfig.ts b/clients/kamino-lending/src/generated/instructions/updateReserveConfig.ts index 10de5dca..89642864 100644 --- a/clients/kamino-lending/src/generated/instructions/updateReserveConfig.ts +++ b/clients/kamino-lending/src/generated/instructions/updateReserveConfig.ts @@ -23,6 +23,7 @@ import type { WritableAccount, } from "@solana/kit"; import type { ResolvedAccount } from "../shared/index.js"; +import type { UpdateConfigMode, UpdateConfigModeArgs } from "../types/index.js"; import { addDecoderSizePrefix, addEncoderSizePrefix, @@ -37,12 +38,14 @@ import { getStructEncoder, getU32Decoder, getU32Encoder, - getU64Decoder, - getU64Encoder, transformEncoder, } from "@solana/kit"; import { KAMINO_LENDING_PROGRAM_ADDRESS } from "../programs/index.js"; import { getAccountMetaFactory } from "../shared/index.js"; +import { + getUpdateConfigModeDecoder, + getUpdateConfigModeEncoder, +} from "../types/index.js"; export const UPDATE_RESERVE_CONFIG_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([61, 148, 100, 70, 143, 107, 17, 13]); @@ -55,7 +58,8 @@ export function getUpdateReserveConfigDiscriminatorBytes(): ReadonlyUint8Array { export type UpdateReserveConfigInstruction< TProgram extends string = typeof KAMINO_LENDING_PROGRAM_ADDRESS, - TAccountLendingMarketOwner extends string | AccountMeta = string, + TAccountSigner extends string | AccountMeta = string, + TAccountGlobalConfig extends string | AccountMeta = string, TAccountLendingMarket extends string | AccountMeta = string, TAccountReserve extends string | AccountMeta = string, TRemainingAccounts extends readonly AccountMeta[] = [], @@ -63,10 +67,13 @@ export type UpdateReserveConfigInstruction< InstructionWithData & InstructionWithAccounts< [ - TAccountLendingMarketOwner extends string - ? ReadonlySignerAccount & - AccountSignerMeta - : TAccountLendingMarketOwner, + TAccountSigner extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountSigner, + TAccountGlobalConfig extends string + ? ReadonlyAccount + : TAccountGlobalConfig, TAccountLendingMarket extends string ? ReadonlyAccount : TAccountLendingMarket, @@ -79,24 +86,24 @@ export type UpdateReserveConfigInstruction< export interface UpdateReserveConfigInstructionData { discriminator: ReadonlyUint8Array; - mode: bigint; + mode: UpdateConfigMode; value: ReadonlyUint8Array; - skipValidation: boolean; + skipConfigIntegrityValidation: boolean; } export interface UpdateReserveConfigInstructionDataArgs { - mode: number | bigint; + mode: UpdateConfigModeArgs; value: ReadonlyUint8Array; - skipValidation: boolean; + skipConfigIntegrityValidation: boolean; } export function getUpdateReserveConfigInstructionDataEncoder(): Encoder { return transformEncoder( getStructEncoder([ ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], - ["mode", getU64Encoder()], + ["mode", getUpdateConfigModeEncoder()], ["value", addEncoderSizePrefix(getBytesEncoder(), getU32Encoder())], - ["skipValidation", getBooleanEncoder()], + ["skipConfigIntegrityValidation", getBooleanEncoder()], ]), (value) => ({ ...value, @@ -108,9 +115,9 @@ export function getUpdateReserveConfigInstructionDataEncoder(): Encoder { return getStructDecoder([ ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], - ["mode", getU64Decoder()], + ["mode", getUpdateConfigModeDecoder()], ["value", addDecoderSizePrefix(getBytesDecoder(), getU32Decoder())], - ["skipValidation", getBooleanDecoder()], + ["skipConfigIntegrityValidation", getBooleanDecoder()], ]); } @@ -125,33 +132,38 @@ export function getUpdateReserveConfigInstructionDataCodec(): Codec< } export interface UpdateReserveConfigInput< - TAccountLendingMarketOwner extends string = string, + TAccountSigner extends string = string, + TAccountGlobalConfig extends string = string, TAccountLendingMarket extends string = string, TAccountReserve extends string = string, > { - lendingMarketOwner: TransactionSigner; + signer: TransactionSigner; + globalConfig: Address; lendingMarket: Address; reserve: Address; mode: UpdateReserveConfigInstructionDataArgs["mode"]; value: UpdateReserveConfigInstructionDataArgs["value"]; - skipValidation: UpdateReserveConfigInstructionDataArgs["skipValidation"]; + skipConfigIntegrityValidation: UpdateReserveConfigInstructionDataArgs["skipConfigIntegrityValidation"]; } export function getUpdateReserveConfigInstruction< - TAccountLendingMarketOwner extends string, + TAccountSigner extends string, + TAccountGlobalConfig extends string, TAccountLendingMarket extends string, TAccountReserve extends string, TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, >( input: UpdateReserveConfigInput< - TAccountLendingMarketOwner, + TAccountSigner, + TAccountGlobalConfig, TAccountLendingMarket, TAccountReserve >, config?: { programAddress?: TProgramAddress }, ): UpdateReserveConfigInstruction< TProgramAddress, - TAccountLendingMarketOwner, + TAccountSigner, + TAccountGlobalConfig, TAccountLendingMarket, TAccountReserve > { @@ -161,10 +173,8 @@ export function getUpdateReserveConfigInstruction< // Original accounts. const originalAccounts = { - lendingMarketOwner: { - value: input.lendingMarketOwner ?? null, - isWritable: false, - }, + signer: { value: input.signer ?? null, isWritable: false }, + globalConfig: { value: input.globalConfig ?? null, isWritable: false }, lendingMarket: { value: input.lendingMarket ?? null, isWritable: false }, reserve: { value: input.reserve ?? null, isWritable: true }, }; @@ -179,7 +189,8 @@ export function getUpdateReserveConfigInstruction< const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ - getAccountMeta(accounts.lendingMarketOwner), + getAccountMeta(accounts.signer), + getAccountMeta(accounts.globalConfig), getAccountMeta(accounts.lendingMarket), getAccountMeta(accounts.reserve), ], @@ -189,7 +200,8 @@ export function getUpdateReserveConfigInstruction< programAddress, } as UpdateReserveConfigInstruction< TProgramAddress, - TAccountLendingMarketOwner, + TAccountSigner, + TAccountGlobalConfig, TAccountLendingMarket, TAccountReserve >); @@ -201,9 +213,10 @@ export interface ParsedUpdateReserveConfigInstruction< > { programAddress: Address; accounts: { - lendingMarketOwner: TAccountMetas[0]; - lendingMarket: TAccountMetas[1]; - reserve: TAccountMetas[2]; + signer: TAccountMetas[0]; + globalConfig: TAccountMetas[1]; + lendingMarket: TAccountMetas[2]; + reserve: TAccountMetas[3]; }; data: UpdateReserveConfigInstructionData; } @@ -216,7 +229,7 @@ export function parseUpdateReserveConfigInstruction< InstructionWithAccounts & InstructionWithData, ): ParsedUpdateReserveConfigInstruction { - if (instruction.accounts.length < 3) { + if (instruction.accounts.length < 4) { // TODO: Coded error. throw new Error("Not enough accounts"); } @@ -229,7 +242,8 @@ export function parseUpdateReserveConfigInstruction< return { programAddress: instruction.programAddress, accounts: { - lendingMarketOwner: getNextAccount(), + signer: getNextAccount(), + globalConfig: getNextAccount(), lendingMarket: getNextAccount(), reserve: getNextAccount(), }, diff --git a/clients/kamino-lending/src/generated/instructions/withdrawFromFarmVault.ts b/clients/kamino-lending/src/generated/instructions/withdrawFromFarmVault.ts index d7fb0a5d..0f941c69 100644 --- a/clients/kamino-lending/src/generated/instructions/withdrawFromFarmVault.ts +++ b/clients/kamino-lending/src/generated/instructions/withdrawFromFarmVault.ts @@ -35,8 +35,9 @@ import { getU64Encoder, transformEncoder, } from "@solana/kit"; +import { findFarmVaultsAuthorityPda } from "../pdas/index.js"; import { FARMS_PROGRAM_ADDRESS } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const WITHDRAW_FROM_FARM_VAULT_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([22, 82, 128, 250, 86, 79, 124, 78]); @@ -124,6 +125,117 @@ export function getWithdrawFromFarmVaultInstructionDataCodec(): FixedSizeCodec< ); } +export interface WithdrawFromFarmVaultAsyncInput< + TAccountWithdrawAuthority extends string = string, + TAccountFarmState extends string = string, + TAccountWithdrawerTokenAccount extends string = string, + TAccountFarmVault extends string = string, + TAccountFarmVaultsAuthority extends string = string, + TAccountTokenProgram extends string = string, +> { + withdrawAuthority: TransactionSigner; + farmState: Address; + withdrawerTokenAccount: Address; + farmVault: Address; + farmVaultsAuthority?: Address; + tokenProgram?: Address; + amount: WithdrawFromFarmVaultInstructionDataArgs["amount"]; +} + +export async function getWithdrawFromFarmVaultInstructionAsync< + TAccountWithdrawAuthority extends string, + TAccountFarmState extends string, + TAccountWithdrawerTokenAccount extends string, + TAccountFarmVault extends string, + TAccountFarmVaultsAuthority extends string, + TAccountTokenProgram extends string, + TProgramAddress extends Address = typeof FARMS_PROGRAM_ADDRESS, +>( + input: WithdrawFromFarmVaultAsyncInput< + TAccountWithdrawAuthority, + TAccountFarmState, + TAccountWithdrawerTokenAccount, + TAccountFarmVault, + TAccountFarmVaultsAuthority, + TAccountTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + WithdrawFromFarmVaultInstruction< + TProgramAddress, + TAccountWithdrawAuthority, + TAccountFarmState, + TAccountWithdrawerTokenAccount, + TAccountFarmVault, + TAccountFarmVaultsAuthority, + TAccountTokenProgram + > +> { + // Program address. + const programAddress = config?.programAddress ?? FARMS_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + withdrawAuthority: { + value: input.withdrawAuthority ?? null, + isWritable: true, + }, + farmState: { value: input.farmState ?? null, isWritable: true }, + withdrawerTokenAccount: { + value: input.withdrawerTokenAccount ?? null, + isWritable: true, + }, + farmVault: { value: input.farmVault ?? null, isWritable: true }, + farmVaultsAuthority: { + value: input.farmVaultsAuthority ?? null, + isWritable: false, + }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.farmVaultsAuthority.value) { + accounts.farmVaultsAuthority.value = await findFarmVaultsAuthorityPda({ + farmState: expectAddress(accounts.farmState.value), + }); + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.withdrawAuthority), + getAccountMeta(accounts.farmState), + getAccountMeta(accounts.withdrawerTokenAccount), + getAccountMeta(accounts.farmVault), + getAccountMeta(accounts.farmVaultsAuthority), + getAccountMeta(accounts.tokenProgram), + ], + data: getWithdrawFromFarmVaultInstructionDataEncoder().encode( + args as WithdrawFromFarmVaultInstructionDataArgs, + ), + programAddress, + } as WithdrawFromFarmVaultInstruction< + TProgramAddress, + TAccountWithdrawAuthority, + TAccountFarmState, + TAccountWithdrawerTokenAccount, + TAccountFarmVault, + TAccountFarmVaultsAuthority, + TAccountTokenProgram + >); +} + export interface WithdrawFromFarmVaultInput< TAccountWithdrawAuthority extends string = string, TAccountFarmState extends string = string, diff --git a/clients/kamino-lending/src/generated/instructions/withdrawObligationCollateral.ts b/clients/kamino-lending/src/generated/instructions/withdrawObligationCollateral.ts index 9ac37d86..fdbe6ca2 100644 --- a/clients/kamino-lending/src/generated/instructions/withdrawObligationCollateral.ts +++ b/clients/kamino-lending/src/generated/instructions/withdrawObligationCollateral.ts @@ -35,8 +35,9 @@ import { getU64Encoder, transformEncoder, } from "@solana/kit"; +import { findLendingMarketAuthPda } from "../pdas/index.js"; import { KAMINO_LENDING_PROGRAM_ADDRESS } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const WITHDRAW_OBLIGATION_COLLATERAL_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([37, 116, 205, 103, 243, 192, 92, 198]); @@ -138,6 +139,149 @@ export function getWithdrawObligationCollateralInstructionDataCodec(): FixedSize ); } +export interface WithdrawObligationCollateralAsyncInput< + TAccountOwner extends string = string, + TAccountObligation extends string = string, + TAccountLendingMarket extends string = string, + TAccountLendingMarketAuthority extends string = string, + TAccountWithdrawReserve extends string = string, + TAccountReserveSourceCollateral extends string = string, + TAccountUserDestinationCollateral extends string = string, + TAccountTokenProgram extends string = string, + TAccountInstructionSysvarAccount extends string = string, +> { + owner: TransactionSigner; + obligation: Address; + lendingMarket: Address; + lendingMarketAuthority?: Address; + withdrawReserve: Address; + reserveSourceCollateral: Address; + userDestinationCollateral: Address; + tokenProgram?: Address; + instructionSysvarAccount?: Address; + collateralAmount: WithdrawObligationCollateralInstructionDataArgs["collateralAmount"]; +} + +export async function getWithdrawObligationCollateralInstructionAsync< + TAccountOwner extends string, + TAccountObligation extends string, + TAccountLendingMarket extends string, + TAccountLendingMarketAuthority extends string, + TAccountWithdrawReserve extends string, + TAccountReserveSourceCollateral extends string, + TAccountUserDestinationCollateral extends string, + TAccountTokenProgram extends string, + TAccountInstructionSysvarAccount extends string, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, +>( + input: WithdrawObligationCollateralAsyncInput< + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountWithdrawReserve, + TAccountReserveSourceCollateral, + TAccountUserDestinationCollateral, + TAccountTokenProgram, + TAccountInstructionSysvarAccount + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + WithdrawObligationCollateralInstruction< + TProgramAddress, + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountWithdrawReserve, + TAccountReserveSourceCollateral, + TAccountUserDestinationCollateral, + TAccountTokenProgram, + TAccountInstructionSysvarAccount + > +> { + // Program address. + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + owner: { value: input.owner ?? null, isWritable: false }, + obligation: { value: input.obligation ?? null, isWritable: true }, + lendingMarket: { value: input.lendingMarket ?? null, isWritable: false }, + lendingMarketAuthority: { + value: input.lendingMarketAuthority ?? null, + isWritable: false, + }, + withdrawReserve: { value: input.withdrawReserve ?? null, isWritable: true }, + reserveSourceCollateral: { + value: input.reserveSourceCollateral ?? null, + isWritable: true, + }, + userDestinationCollateral: { + value: input.userDestinationCollateral ?? null, + isWritable: true, + }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + instructionSysvarAccount: { + value: input.instructionSysvarAccount ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.lendingMarketAuthority.value) { + accounts.lendingMarketAuthority.value = await findLendingMarketAuthPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + }); + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.instructionSysvarAccount.value) { + accounts.instructionSysvarAccount.value = + "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.owner), + getAccountMeta(accounts.obligation), + getAccountMeta(accounts.lendingMarket), + getAccountMeta(accounts.lendingMarketAuthority), + getAccountMeta(accounts.withdrawReserve), + getAccountMeta(accounts.reserveSourceCollateral), + getAccountMeta(accounts.userDestinationCollateral), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.instructionSysvarAccount), + ], + data: getWithdrawObligationCollateralInstructionDataEncoder().encode( + args as WithdrawObligationCollateralInstructionDataArgs, + ), + programAddress, + } as WithdrawObligationCollateralInstruction< + TProgramAddress, + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountWithdrawReserve, + TAccountReserveSourceCollateral, + TAccountUserDestinationCollateral, + TAccountTokenProgram, + TAccountInstructionSysvarAccount + >); +} + export interface WithdrawObligationCollateralInput< TAccountOwner extends string = string, TAccountObligation extends string = string, diff --git a/clients/kamino-lending/src/generated/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.ts b/clients/kamino-lending/src/generated/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.ts index 669f147b..13456008 100644 --- a/clients/kamino-lending/src/generated/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.ts +++ b/clients/kamino-lending/src/generated/instructions/withdrawObligationCollateralAndRedeemReserveCollateral.ts @@ -35,8 +35,13 @@ import { getU64Encoder, transformEncoder, } from "@solana/kit"; +import { + findLendingMarketAuthPda, + findReserveCollateralMintPda, + findReserveLiquiditySupplyPda, +} from "../pdas/index.js"; import { KAMINO_LENDING_PROGRAM_ADDRESS } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const WITHDRAW_OBLIGATION_COLLATERAL_AND_REDEEM_RESERVE_COLLATERAL_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([75, 93, 93, 220, 34, 150, 218, 196]); @@ -62,8 +67,12 @@ export type WithdrawObligationCollateralAndRedeemReserveCollateralInstruction< TAccountPlaceholderUserDestinationCollateral extends | string | AccountMeta = string, - TAccountCollateralTokenProgram extends string | AccountMeta = string, - TAccountLiquidityTokenProgram extends string | AccountMeta = string, + TAccountCollateralTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TAccountLiquidityTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", TAccountInstructionSysvarAccount extends | string | AccountMeta = "Sysvar1nstructions1111111111111111111111111", @@ -159,6 +168,225 @@ export function getWithdrawObligationCollateralAndRedeemReserveCollateralInstruc ); } +export interface WithdrawObligationCollateralAndRedeemReserveCollateralAsyncInput< + TAccountOwner extends string = string, + TAccountObligation extends string = string, + TAccountLendingMarket extends string = string, + TAccountLendingMarketAuthority extends string = string, + TAccountWithdrawReserve extends string = string, + TAccountReserveLiquidityMint extends string = string, + TAccountReserveSourceCollateral extends string = string, + TAccountReserveCollateralMint extends string = string, + TAccountReserveLiquiditySupply extends string = string, + TAccountUserDestinationLiquidity extends string = string, + TAccountPlaceholderUserDestinationCollateral extends string = string, + TAccountCollateralTokenProgram extends string = string, + TAccountLiquidityTokenProgram extends string = string, + TAccountInstructionSysvarAccount extends string = string, +> { + owner: TransactionSigner; + obligation: Address; + lendingMarket: Address; + lendingMarketAuthority?: Address; + withdrawReserve: Address; + reserveLiquidityMint: Address; + reserveSourceCollateral: Address; + reserveCollateralMint?: Address; + reserveLiquiditySupply?: Address; + userDestinationLiquidity: Address; + placeholderUserDestinationCollateral?: Address; + collateralTokenProgram?: Address; + liquidityTokenProgram?: Address; + instructionSysvarAccount?: Address; + collateralAmount: WithdrawObligationCollateralAndRedeemReserveCollateralInstructionDataArgs["collateralAmount"]; +} + +export async function getWithdrawObligationCollateralAndRedeemReserveCollateralInstructionAsync< + TAccountOwner extends string, + TAccountObligation extends string, + TAccountLendingMarket extends string, + TAccountLendingMarketAuthority extends string, + TAccountWithdrawReserve extends string, + TAccountReserveLiquidityMint extends string, + TAccountReserveSourceCollateral extends string, + TAccountReserveCollateralMint extends string, + TAccountReserveLiquiditySupply extends string, + TAccountUserDestinationLiquidity extends string, + TAccountPlaceholderUserDestinationCollateral extends string, + TAccountCollateralTokenProgram extends string, + TAccountLiquidityTokenProgram extends string, + TAccountInstructionSysvarAccount extends string, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, +>( + input: WithdrawObligationCollateralAndRedeemReserveCollateralAsyncInput< + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountWithdrawReserve, + TAccountReserveLiquidityMint, + TAccountReserveSourceCollateral, + TAccountReserveCollateralMint, + TAccountReserveLiquiditySupply, + TAccountUserDestinationLiquidity, + TAccountPlaceholderUserDestinationCollateral, + TAccountCollateralTokenProgram, + TAccountLiquidityTokenProgram, + TAccountInstructionSysvarAccount + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + WithdrawObligationCollateralAndRedeemReserveCollateralInstruction< + TProgramAddress, + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountWithdrawReserve, + TAccountReserveLiquidityMint, + TAccountReserveSourceCollateral, + TAccountReserveCollateralMint, + TAccountReserveLiquiditySupply, + TAccountUserDestinationLiquidity, + TAccountPlaceholderUserDestinationCollateral, + TAccountCollateralTokenProgram, + TAccountLiquidityTokenProgram, + TAccountInstructionSysvarAccount + > +> { + // Program address. + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + owner: { value: input.owner ?? null, isWritable: true }, + obligation: { value: input.obligation ?? null, isWritable: true }, + lendingMarket: { value: input.lendingMarket ?? null, isWritable: false }, + lendingMarketAuthority: { + value: input.lendingMarketAuthority ?? null, + isWritable: false, + }, + withdrawReserve: { value: input.withdrawReserve ?? null, isWritable: true }, + reserveLiquidityMint: { + value: input.reserveLiquidityMint ?? null, + isWritable: false, + }, + reserveSourceCollateral: { + value: input.reserveSourceCollateral ?? null, + isWritable: true, + }, + reserveCollateralMint: { + value: input.reserveCollateralMint ?? null, + isWritable: true, + }, + reserveLiquiditySupply: { + value: input.reserveLiquiditySupply ?? null, + isWritable: true, + }, + userDestinationLiquidity: { + value: input.userDestinationLiquidity ?? null, + isWritable: true, + }, + placeholderUserDestinationCollateral: { + value: input.placeholderUserDestinationCollateral ?? null, + isWritable: false, + }, + collateralTokenProgram: { + value: input.collateralTokenProgram ?? null, + isWritable: false, + }, + liquidityTokenProgram: { + value: input.liquidityTokenProgram ?? null, + isWritable: false, + }, + instructionSysvarAccount: { + value: input.instructionSysvarAccount ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.lendingMarketAuthority.value) { + accounts.lendingMarketAuthority.value = await findLendingMarketAuthPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + }); + } + if (!accounts.reserveCollateralMint.value) { + accounts.reserveCollateralMint.value = await findReserveCollateralMintPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + mint: expectAddress(accounts.reserveLiquidityMint.value), + }); + } + if (!accounts.reserveLiquiditySupply.value) { + accounts.reserveLiquiditySupply.value = await findReserveLiquiditySupplyPda( + { + lendingMarket: expectAddress(accounts.lendingMarket.value), + mint: expectAddress(accounts.reserveLiquidityMint.value), + }, + ); + } + if (!accounts.collateralTokenProgram.value) { + accounts.collateralTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.liquidityTokenProgram.value) { + accounts.liquidityTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.instructionSysvarAccount.value) { + accounts.instructionSysvarAccount.value = + "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.owner), + getAccountMeta(accounts.obligation), + getAccountMeta(accounts.lendingMarket), + getAccountMeta(accounts.lendingMarketAuthority), + getAccountMeta(accounts.withdrawReserve), + getAccountMeta(accounts.reserveLiquidityMint), + getAccountMeta(accounts.reserveSourceCollateral), + getAccountMeta(accounts.reserveCollateralMint), + getAccountMeta(accounts.reserveLiquiditySupply), + getAccountMeta(accounts.userDestinationLiquidity), + getAccountMeta(accounts.placeholderUserDestinationCollateral), + getAccountMeta(accounts.collateralTokenProgram), + getAccountMeta(accounts.liquidityTokenProgram), + getAccountMeta(accounts.instructionSysvarAccount), + ], + data: getWithdrawObligationCollateralAndRedeemReserveCollateralInstructionDataEncoder().encode( + args as WithdrawObligationCollateralAndRedeemReserveCollateralInstructionDataArgs, + ), + programAddress, + } as WithdrawObligationCollateralAndRedeemReserveCollateralInstruction< + TProgramAddress, + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountWithdrawReserve, + TAccountReserveLiquidityMint, + TAccountReserveSourceCollateral, + TAccountReserveCollateralMint, + TAccountReserveLiquiditySupply, + TAccountUserDestinationLiquidity, + TAccountPlaceholderUserDestinationCollateral, + TAccountCollateralTokenProgram, + TAccountLiquidityTokenProgram, + TAccountInstructionSysvarAccount + >); +} + export interface WithdrawObligationCollateralAndRedeemReserveCollateralInput< TAccountOwner extends string = string, TAccountObligation extends string = string, @@ -186,8 +414,8 @@ export interface WithdrawObligationCollateralAndRedeemReserveCollateralInput< reserveLiquiditySupply: Address; userDestinationLiquidity: Address; placeholderUserDestinationCollateral?: Address; - collateralTokenProgram: Address; - liquidityTokenProgram: Address; + collateralTokenProgram?: Address; + liquidityTokenProgram?: Address; instructionSysvarAccount?: Address; collateralAmount: WithdrawObligationCollateralAndRedeemReserveCollateralInstructionDataArgs["collateralAmount"]; } @@ -303,6 +531,14 @@ export function getWithdrawObligationCollateralAndRedeemReserveCollateralInstruc const args = { ...input }; // Resolve default values. + if (!accounts.collateralTokenProgram.value) { + accounts.collateralTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.liquidityTokenProgram.value) { + accounts.liquidityTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } if (!accounts.instructionSysvarAccount.value) { accounts.instructionSysvarAccount.value = "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; diff --git a/clients/kamino-lending/src/generated/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.ts b/clients/kamino-lending/src/generated/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.ts index 3c799647..482ac048 100644 --- a/clients/kamino-lending/src/generated/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.ts +++ b/clients/kamino-lending/src/generated/instructions/withdrawObligationCollateralAndRedeemReserveCollateralV2.ts @@ -35,11 +35,16 @@ import { getU64Encoder, transformEncoder, } from "@solana/kit"; +import { + findLendingMarketAuthPda, + findReserveCollateralMintPda, + findReserveLiquiditySupplyPda, +} from "../pdas/index.js"; import { FARMS_PROGRAM_ADDRESS, KAMINO_LENDING_PROGRAM_ADDRESS, } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const WITHDRAW_OBLIGATION_COLLATERAL_AND_REDEEM_RESERVE_COLLATERAL_V2_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([235, 52, 119, 152, 149, 197, 20, 7]); @@ -65,8 +70,12 @@ export type WithdrawObligationCollateralAndRedeemReserveCollateralV2Instruction< TAccountPlaceholderUserDestinationCollateral extends | string | AccountMeta = string, - TAccountCollateralTokenProgram extends string | AccountMeta = string, - TAccountLiquidityTokenProgram extends string | AccountMeta = string, + TAccountCollateralTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TAccountLiquidityTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", TAccountInstructionSysvarAccount extends | string | AccountMeta = "Sysvar1nstructions1111111111111111111111111", @@ -176,6 +185,259 @@ export function getWithdrawObligationCollateralAndRedeemReserveCollateralV2Instr ); } +export interface WithdrawObligationCollateralAndRedeemReserveCollateralV2AsyncInput< + TAccountOwner extends string = string, + TAccountObligation extends string = string, + TAccountLendingMarket extends string = string, + TAccountLendingMarketAuthority extends string = string, + TAccountWithdrawReserve extends string = string, + TAccountReserveLiquidityMint extends string = string, + TAccountReserveSourceCollateral extends string = string, + TAccountReserveCollateralMint extends string = string, + TAccountReserveLiquiditySupply extends string = string, + TAccountUserDestinationLiquidity extends string = string, + TAccountPlaceholderUserDestinationCollateral extends string = string, + TAccountCollateralTokenProgram extends string = string, + TAccountLiquidityTokenProgram extends string = string, + TAccountInstructionSysvarAccount extends string = string, + TAccountObligationFarmUserState extends string = string, + TAccountReserveFarmState extends string = string, + TAccountFarmsProgram extends string = string, +> { + owner: TransactionSigner; + obligation: Address; + lendingMarket: Address; + lendingMarketAuthority?: Address; + withdrawReserve: Address; + reserveLiquidityMint: Address; + reserveSourceCollateral: Address; + reserveCollateralMint?: Address; + reserveLiquiditySupply?: Address; + userDestinationLiquidity: Address; + placeholderUserDestinationCollateral?: Address; + collateralTokenProgram?: Address; + liquidityTokenProgram?: Address; + instructionSysvarAccount?: Address; + obligationFarmUserState?: Address; + reserveFarmState?: Address; + farmsProgram?: Address; + collateralAmount: WithdrawObligationCollateralAndRedeemReserveCollateralV2InstructionDataArgs["collateralAmount"]; +} + +export async function getWithdrawObligationCollateralAndRedeemReserveCollateralV2InstructionAsync< + TAccountOwner extends string, + TAccountObligation extends string, + TAccountLendingMarket extends string, + TAccountLendingMarketAuthority extends string, + TAccountWithdrawReserve extends string, + TAccountReserveLiquidityMint extends string, + TAccountReserveSourceCollateral extends string, + TAccountReserveCollateralMint extends string, + TAccountReserveLiquiditySupply extends string, + TAccountUserDestinationLiquidity extends string, + TAccountPlaceholderUserDestinationCollateral extends string, + TAccountCollateralTokenProgram extends string, + TAccountLiquidityTokenProgram extends string, + TAccountInstructionSysvarAccount extends string, + TAccountObligationFarmUserState extends string, + TAccountReserveFarmState extends string, + TAccountFarmsProgram extends string, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, +>( + input: WithdrawObligationCollateralAndRedeemReserveCollateralV2AsyncInput< + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountWithdrawReserve, + TAccountReserveLiquidityMint, + TAccountReserveSourceCollateral, + TAccountReserveCollateralMint, + TAccountReserveLiquiditySupply, + TAccountUserDestinationLiquidity, + TAccountPlaceholderUserDestinationCollateral, + TAccountCollateralTokenProgram, + TAccountLiquidityTokenProgram, + TAccountInstructionSysvarAccount, + TAccountObligationFarmUserState, + TAccountReserveFarmState, + TAccountFarmsProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + WithdrawObligationCollateralAndRedeemReserveCollateralV2Instruction< + TProgramAddress, + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountWithdrawReserve, + TAccountReserveLiquidityMint, + TAccountReserveSourceCollateral, + TAccountReserveCollateralMint, + TAccountReserveLiquiditySupply, + TAccountUserDestinationLiquidity, + TAccountPlaceholderUserDestinationCollateral, + TAccountCollateralTokenProgram, + TAccountLiquidityTokenProgram, + TAccountInstructionSysvarAccount, + TAccountObligationFarmUserState, + TAccountReserveFarmState, + TAccountFarmsProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + owner: { value: input.owner ?? null, isWritable: true }, + obligation: { value: input.obligation ?? null, isWritable: true }, + lendingMarket: { value: input.lendingMarket ?? null, isWritable: false }, + lendingMarketAuthority: { + value: input.lendingMarketAuthority ?? null, + isWritable: false, + }, + withdrawReserve: { value: input.withdrawReserve ?? null, isWritable: true }, + reserveLiquidityMint: { + value: input.reserveLiquidityMint ?? null, + isWritable: false, + }, + reserveSourceCollateral: { + value: input.reserveSourceCollateral ?? null, + isWritable: true, + }, + reserveCollateralMint: { + value: input.reserveCollateralMint ?? null, + isWritable: true, + }, + reserveLiquiditySupply: { + value: input.reserveLiquiditySupply ?? null, + isWritable: true, + }, + userDestinationLiquidity: { + value: input.userDestinationLiquidity ?? null, + isWritable: true, + }, + placeholderUserDestinationCollateral: { + value: input.placeholderUserDestinationCollateral ?? null, + isWritable: false, + }, + collateralTokenProgram: { + value: input.collateralTokenProgram ?? null, + isWritable: false, + }, + liquidityTokenProgram: { + value: input.liquidityTokenProgram ?? null, + isWritable: false, + }, + instructionSysvarAccount: { + value: input.instructionSysvarAccount ?? null, + isWritable: false, + }, + obligationFarmUserState: { + value: input.obligationFarmUserState ?? null, + isWritable: true, + }, + reserveFarmState: { + value: input.reserveFarmState ?? null, + isWritable: true, + }, + farmsProgram: { value: input.farmsProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.lendingMarketAuthority.value) { + accounts.lendingMarketAuthority.value = await findLendingMarketAuthPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + }); + } + if (!accounts.reserveCollateralMint.value) { + accounts.reserveCollateralMint.value = await findReserveCollateralMintPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + mint: expectAddress(accounts.reserveLiquidityMint.value), + }); + } + if (!accounts.reserveLiquiditySupply.value) { + accounts.reserveLiquiditySupply.value = await findReserveLiquiditySupplyPda( + { + lendingMarket: expectAddress(accounts.lendingMarket.value), + mint: expectAddress(accounts.reserveLiquidityMint.value), + }, + ); + } + if (!accounts.collateralTokenProgram.value) { + accounts.collateralTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.liquidityTokenProgram.value) { + accounts.liquidityTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.instructionSysvarAccount.value) { + accounts.instructionSysvarAccount.value = + "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; + } + if (!accounts.farmsProgram.value) { + accounts.farmsProgram.value = FARMS_PROGRAM_ADDRESS; + accounts.farmsProgram.isWritable = false; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.owner), + getAccountMeta(accounts.obligation), + getAccountMeta(accounts.lendingMarket), + getAccountMeta(accounts.lendingMarketAuthority), + getAccountMeta(accounts.withdrawReserve), + getAccountMeta(accounts.reserveLiquidityMint), + getAccountMeta(accounts.reserveSourceCollateral), + getAccountMeta(accounts.reserveCollateralMint), + getAccountMeta(accounts.reserveLiquiditySupply), + getAccountMeta(accounts.userDestinationLiquidity), + getAccountMeta(accounts.placeholderUserDestinationCollateral), + getAccountMeta(accounts.collateralTokenProgram), + getAccountMeta(accounts.liquidityTokenProgram), + getAccountMeta(accounts.instructionSysvarAccount), + getAccountMeta(accounts.obligationFarmUserState), + getAccountMeta(accounts.reserveFarmState), + getAccountMeta(accounts.farmsProgram), + ], + data: getWithdrawObligationCollateralAndRedeemReserveCollateralV2InstructionDataEncoder().encode( + args as WithdrawObligationCollateralAndRedeemReserveCollateralV2InstructionDataArgs, + ), + programAddress, + } as WithdrawObligationCollateralAndRedeemReserveCollateralV2Instruction< + TProgramAddress, + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountWithdrawReserve, + TAccountReserveLiquidityMint, + TAccountReserveSourceCollateral, + TAccountReserveCollateralMint, + TAccountReserveLiquiditySupply, + TAccountUserDestinationLiquidity, + TAccountPlaceholderUserDestinationCollateral, + TAccountCollateralTokenProgram, + TAccountLiquidityTokenProgram, + TAccountInstructionSysvarAccount, + TAccountObligationFarmUserState, + TAccountReserveFarmState, + TAccountFarmsProgram + >); +} + export interface WithdrawObligationCollateralAndRedeemReserveCollateralV2Input< TAccountOwner extends string = string, TAccountObligation extends string = string, @@ -206,8 +468,8 @@ export interface WithdrawObligationCollateralAndRedeemReserveCollateralV2Input< reserveLiquiditySupply: Address; userDestinationLiquidity: Address; placeholderUserDestinationCollateral?: Address; - collateralTokenProgram: Address; - liquidityTokenProgram: Address; + collateralTokenProgram?: Address; + liquidityTokenProgram?: Address; instructionSysvarAccount?: Address; obligationFarmUserState?: Address; reserveFarmState?: Address; @@ -344,6 +606,14 @@ export function getWithdrawObligationCollateralAndRedeemReserveCollateralV2Instr const args = { ...input }; // Resolve default values. + if (!accounts.collateralTokenProgram.value) { + accounts.collateralTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.liquidityTokenProgram.value) { + accounts.liquidityTokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } if (!accounts.instructionSysvarAccount.value) { accounts.instructionSysvarAccount.value = "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; diff --git a/clients/kamino-lending/src/generated/instructions/withdrawObligationCollateralV2.ts b/clients/kamino-lending/src/generated/instructions/withdrawObligationCollateralV2.ts index 0c9f2692..3a9e8901 100644 --- a/clients/kamino-lending/src/generated/instructions/withdrawObligationCollateralV2.ts +++ b/clients/kamino-lending/src/generated/instructions/withdrawObligationCollateralV2.ts @@ -35,11 +35,12 @@ import { getU64Encoder, transformEncoder, } from "@solana/kit"; +import { findLendingMarketAuthPda } from "../pdas/index.js"; import { FARMS_PROGRAM_ADDRESS, KAMINO_LENDING_PROGRAM_ADDRESS, } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const WITHDRAW_OBLIGATION_COLLATERAL_V2_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([202, 249, 117, 114, 231, 192, 47, 138]); @@ -155,6 +156,183 @@ export function getWithdrawObligationCollateralV2InstructionDataCodec(): FixedSi ); } +export interface WithdrawObligationCollateralV2AsyncInput< + TAccountOwner extends string = string, + TAccountObligation extends string = string, + TAccountLendingMarket extends string = string, + TAccountLendingMarketAuthority extends string = string, + TAccountWithdrawReserve extends string = string, + TAccountReserveSourceCollateral extends string = string, + TAccountUserDestinationCollateral extends string = string, + TAccountTokenProgram extends string = string, + TAccountInstructionSysvarAccount extends string = string, + TAccountObligationFarmUserState extends string = string, + TAccountReserveFarmState extends string = string, + TAccountFarmsProgram extends string = string, +> { + owner: TransactionSigner; + obligation: Address; + lendingMarket: Address; + lendingMarketAuthority?: Address; + withdrawReserve: Address; + reserveSourceCollateral: Address; + userDestinationCollateral: Address; + tokenProgram?: Address; + instructionSysvarAccount?: Address; + obligationFarmUserState?: Address; + reserveFarmState?: Address; + farmsProgram?: Address; + collateralAmount: WithdrawObligationCollateralV2InstructionDataArgs["collateralAmount"]; +} + +export async function getWithdrawObligationCollateralV2InstructionAsync< + TAccountOwner extends string, + TAccountObligation extends string, + TAccountLendingMarket extends string, + TAccountLendingMarketAuthority extends string, + TAccountWithdrawReserve extends string, + TAccountReserveSourceCollateral extends string, + TAccountUserDestinationCollateral extends string, + TAccountTokenProgram extends string, + TAccountInstructionSysvarAccount extends string, + TAccountObligationFarmUserState extends string, + TAccountReserveFarmState extends string, + TAccountFarmsProgram extends string, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, +>( + input: WithdrawObligationCollateralV2AsyncInput< + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountWithdrawReserve, + TAccountReserveSourceCollateral, + TAccountUserDestinationCollateral, + TAccountTokenProgram, + TAccountInstructionSysvarAccount, + TAccountObligationFarmUserState, + TAccountReserveFarmState, + TAccountFarmsProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + WithdrawObligationCollateralV2Instruction< + TProgramAddress, + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountWithdrawReserve, + TAccountReserveSourceCollateral, + TAccountUserDestinationCollateral, + TAccountTokenProgram, + TAccountInstructionSysvarAccount, + TAccountObligationFarmUserState, + TAccountReserveFarmState, + TAccountFarmsProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + owner: { value: input.owner ?? null, isWritable: false }, + obligation: { value: input.obligation ?? null, isWritable: true }, + lendingMarket: { value: input.lendingMarket ?? null, isWritable: false }, + lendingMarketAuthority: { + value: input.lendingMarketAuthority ?? null, + isWritable: false, + }, + withdrawReserve: { value: input.withdrawReserve ?? null, isWritable: true }, + reserveSourceCollateral: { + value: input.reserveSourceCollateral ?? null, + isWritable: true, + }, + userDestinationCollateral: { + value: input.userDestinationCollateral ?? null, + isWritable: true, + }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + instructionSysvarAccount: { + value: input.instructionSysvarAccount ?? null, + isWritable: false, + }, + obligationFarmUserState: { + value: input.obligationFarmUserState ?? null, + isWritable: true, + }, + reserveFarmState: { + value: input.reserveFarmState ?? null, + isWritable: true, + }, + farmsProgram: { value: input.farmsProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.lendingMarketAuthority.value) { + accounts.lendingMarketAuthority.value = await findLendingMarketAuthPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + }); + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.instructionSysvarAccount.value) { + accounts.instructionSysvarAccount.value = + "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; + } + if (!accounts.farmsProgram.value) { + accounts.farmsProgram.value = FARMS_PROGRAM_ADDRESS; + accounts.farmsProgram.isWritable = false; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.owner), + getAccountMeta(accounts.obligation), + getAccountMeta(accounts.lendingMarket), + getAccountMeta(accounts.lendingMarketAuthority), + getAccountMeta(accounts.withdrawReserve), + getAccountMeta(accounts.reserveSourceCollateral), + getAccountMeta(accounts.userDestinationCollateral), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.instructionSysvarAccount), + getAccountMeta(accounts.obligationFarmUserState), + getAccountMeta(accounts.reserveFarmState), + getAccountMeta(accounts.farmsProgram), + ], + data: getWithdrawObligationCollateralV2InstructionDataEncoder().encode( + args as WithdrawObligationCollateralV2InstructionDataArgs, + ), + programAddress, + } as WithdrawObligationCollateralV2Instruction< + TProgramAddress, + TAccountOwner, + TAccountObligation, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountWithdrawReserve, + TAccountReserveSourceCollateral, + TAccountUserDestinationCollateral, + TAccountTokenProgram, + TAccountInstructionSysvarAccount, + TAccountObligationFarmUserState, + TAccountReserveFarmState, + TAccountFarmsProgram + >); +} + export interface WithdrawObligationCollateralV2Input< TAccountOwner extends string = string, TAccountObligation extends string = string, diff --git a/clients/kamino-lending/src/generated/instructions/withdrawProtocolFee.ts b/clients/kamino-lending/src/generated/instructions/withdrawProtocolFee.ts index 379372b5..9bc53aea 100644 --- a/clients/kamino-lending/src/generated/instructions/withdrawProtocolFee.ts +++ b/clients/kamino-lending/src/generated/instructions/withdrawProtocolFee.ts @@ -8,7 +8,6 @@ import type { AccountMeta, - AccountSignerMeta, Address, FixedSizeCodec, FixedSizeDecoder, @@ -17,9 +16,7 @@ import type { InstructionWithAccounts, InstructionWithData, ReadonlyAccount, - ReadonlySignerAccount, ReadonlyUint8Array, - TransactionSigner, WritableAccount, } from "@solana/kit"; import type { ResolvedAccount } from "../shared/index.js"; @@ -35,8 +32,9 @@ import { getU64Encoder, transformEncoder, } from "@solana/kit"; +import { findLendingMarketAuthPda } from "../pdas/index.js"; import { KAMINO_LENDING_PROGRAM_ADDRESS } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const WITHDRAW_PROTOCOL_FEE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([158, 201, 158, 189, 33, 93, 162, 103]); @@ -49,13 +47,13 @@ export function getWithdrawProtocolFeeDiscriminatorBytes(): ReadonlyUint8Array { export type WithdrawProtocolFeeInstruction< TProgram extends string = typeof KAMINO_LENDING_PROGRAM_ADDRESS, - TAccountLendingMarketOwner extends string | AccountMeta = string, + TAccountGlobalConfig extends string | AccountMeta = string, TAccountLendingMarket extends string | AccountMeta = string, TAccountReserve extends string | AccountMeta = string, TAccountReserveLiquidityMint extends string | AccountMeta = string, TAccountLendingMarketAuthority extends string | AccountMeta = string, TAccountFeeVault extends string | AccountMeta = string, - TAccountLendingMarketOwnerAta extends string | AccountMeta = string, + TAccountFeeCollectorAta extends string | AccountMeta = string, TAccountTokenProgram extends | string | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", @@ -64,10 +62,9 @@ export type WithdrawProtocolFeeInstruction< InstructionWithData & InstructionWithAccounts< [ - TAccountLendingMarketOwner extends string - ? ReadonlySignerAccount & - AccountSignerMeta - : TAccountLendingMarketOwner, + TAccountGlobalConfig extends string + ? ReadonlyAccount + : TAccountGlobalConfig, TAccountLendingMarket extends string ? ReadonlyAccount : TAccountLendingMarket, @@ -83,9 +80,9 @@ export type WithdrawProtocolFeeInstruction< TAccountFeeVault extends string ? WritableAccount : TAccountFeeVault, - TAccountLendingMarketOwnerAta extends string - ? WritableAccount - : TAccountLendingMarketOwnerAta, + TAccountFeeCollectorAta extends string + ? WritableAccount + : TAccountFeeCollectorAta, TAccountTokenProgram extends string ? ReadonlyAccount : TAccountTokenProgram, @@ -132,58 +129,183 @@ export function getWithdrawProtocolFeeInstructionDataCodec(): FixedSizeCodec< ); } +export interface WithdrawProtocolFeeAsyncInput< + TAccountGlobalConfig extends string = string, + TAccountLendingMarket extends string = string, + TAccountReserve extends string = string, + TAccountReserveLiquidityMint extends string = string, + TAccountLendingMarketAuthority extends string = string, + TAccountFeeVault extends string = string, + TAccountFeeCollectorAta extends string = string, + TAccountTokenProgram extends string = string, +> { + globalConfig: Address; + lendingMarket: Address; + reserve: Address; + reserveLiquidityMint: Address; + lendingMarketAuthority?: Address; + feeVault: Address; + feeCollectorAta: Address; + tokenProgram?: Address; + amount: WithdrawProtocolFeeInstructionDataArgs["amount"]; +} + +export async function getWithdrawProtocolFeeInstructionAsync< + TAccountGlobalConfig extends string, + TAccountLendingMarket extends string, + TAccountReserve extends string, + TAccountReserveLiquidityMint extends string, + TAccountLendingMarketAuthority extends string, + TAccountFeeVault extends string, + TAccountFeeCollectorAta extends string, + TAccountTokenProgram extends string, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, +>( + input: WithdrawProtocolFeeAsyncInput< + TAccountGlobalConfig, + TAccountLendingMarket, + TAccountReserve, + TAccountReserveLiquidityMint, + TAccountLendingMarketAuthority, + TAccountFeeVault, + TAccountFeeCollectorAta, + TAccountTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + WithdrawProtocolFeeInstruction< + TProgramAddress, + TAccountGlobalConfig, + TAccountLendingMarket, + TAccountReserve, + TAccountReserveLiquidityMint, + TAccountLendingMarketAuthority, + TAccountFeeVault, + TAccountFeeCollectorAta, + TAccountTokenProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + globalConfig: { value: input.globalConfig ?? null, isWritable: false }, + lendingMarket: { value: input.lendingMarket ?? null, isWritable: false }, + reserve: { value: input.reserve ?? null, isWritable: false }, + reserveLiquidityMint: { + value: input.reserveLiquidityMint ?? null, + isWritable: false, + }, + lendingMarketAuthority: { + value: input.lendingMarketAuthority ?? null, + isWritable: false, + }, + feeVault: { value: input.feeVault ?? null, isWritable: true }, + feeCollectorAta: { value: input.feeCollectorAta ?? null, isWritable: true }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.lendingMarketAuthority.value) { + accounts.lendingMarketAuthority.value = await findLendingMarketAuthPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + }); + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.globalConfig), + getAccountMeta(accounts.lendingMarket), + getAccountMeta(accounts.reserve), + getAccountMeta(accounts.reserveLiquidityMint), + getAccountMeta(accounts.lendingMarketAuthority), + getAccountMeta(accounts.feeVault), + getAccountMeta(accounts.feeCollectorAta), + getAccountMeta(accounts.tokenProgram), + ], + data: getWithdrawProtocolFeeInstructionDataEncoder().encode( + args as WithdrawProtocolFeeInstructionDataArgs, + ), + programAddress, + } as WithdrawProtocolFeeInstruction< + TProgramAddress, + TAccountGlobalConfig, + TAccountLendingMarket, + TAccountReserve, + TAccountReserveLiquidityMint, + TAccountLendingMarketAuthority, + TAccountFeeVault, + TAccountFeeCollectorAta, + TAccountTokenProgram + >); +} + export interface WithdrawProtocolFeeInput< - TAccountLendingMarketOwner extends string = string, + TAccountGlobalConfig extends string = string, TAccountLendingMarket extends string = string, TAccountReserve extends string = string, TAccountReserveLiquidityMint extends string = string, TAccountLendingMarketAuthority extends string = string, TAccountFeeVault extends string = string, - TAccountLendingMarketOwnerAta extends string = string, + TAccountFeeCollectorAta extends string = string, TAccountTokenProgram extends string = string, > { - lendingMarketOwner: TransactionSigner; + globalConfig: Address; lendingMarket: Address; reserve: Address; reserveLiquidityMint: Address; lendingMarketAuthority: Address; feeVault: Address; - lendingMarketOwnerAta: Address; + feeCollectorAta: Address; tokenProgram?: Address; amount: WithdrawProtocolFeeInstructionDataArgs["amount"]; } export function getWithdrawProtocolFeeInstruction< - TAccountLendingMarketOwner extends string, + TAccountGlobalConfig extends string, TAccountLendingMarket extends string, TAccountReserve extends string, TAccountReserveLiquidityMint extends string, TAccountLendingMarketAuthority extends string, TAccountFeeVault extends string, - TAccountLendingMarketOwnerAta extends string, + TAccountFeeCollectorAta extends string, TAccountTokenProgram extends string, TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, >( input: WithdrawProtocolFeeInput< - TAccountLendingMarketOwner, + TAccountGlobalConfig, TAccountLendingMarket, TAccountReserve, TAccountReserveLiquidityMint, TAccountLendingMarketAuthority, TAccountFeeVault, - TAccountLendingMarketOwnerAta, + TAccountFeeCollectorAta, TAccountTokenProgram >, config?: { programAddress?: TProgramAddress }, ): WithdrawProtocolFeeInstruction< TProgramAddress, - TAccountLendingMarketOwner, + TAccountGlobalConfig, TAccountLendingMarket, TAccountReserve, TAccountReserveLiquidityMint, TAccountLendingMarketAuthority, TAccountFeeVault, - TAccountLendingMarketOwnerAta, + TAccountFeeCollectorAta, TAccountTokenProgram > { // Program address. @@ -192,10 +314,7 @@ export function getWithdrawProtocolFeeInstruction< // Original accounts. const originalAccounts = { - lendingMarketOwner: { - value: input.lendingMarketOwner ?? null, - isWritable: false, - }, + globalConfig: { value: input.globalConfig ?? null, isWritable: false }, lendingMarket: { value: input.lendingMarket ?? null, isWritable: false }, reserve: { value: input.reserve ?? null, isWritable: false }, reserveLiquidityMint: { @@ -207,10 +326,7 @@ export function getWithdrawProtocolFeeInstruction< isWritable: false, }, feeVault: { value: input.feeVault ?? null, isWritable: true }, - lendingMarketOwnerAta: { - value: input.lendingMarketOwnerAta ?? null, - isWritable: true, - }, + feeCollectorAta: { value: input.feeCollectorAta ?? null, isWritable: true }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, }; const accounts = originalAccounts as Record< @@ -230,13 +346,13 @@ export function getWithdrawProtocolFeeInstruction< const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); return Object.freeze({ accounts: [ - getAccountMeta(accounts.lendingMarketOwner), + getAccountMeta(accounts.globalConfig), getAccountMeta(accounts.lendingMarket), getAccountMeta(accounts.reserve), getAccountMeta(accounts.reserveLiquidityMint), getAccountMeta(accounts.lendingMarketAuthority), getAccountMeta(accounts.feeVault), - getAccountMeta(accounts.lendingMarketOwnerAta), + getAccountMeta(accounts.feeCollectorAta), getAccountMeta(accounts.tokenProgram), ], data: getWithdrawProtocolFeeInstructionDataEncoder().encode( @@ -245,13 +361,13 @@ export function getWithdrawProtocolFeeInstruction< programAddress, } as WithdrawProtocolFeeInstruction< TProgramAddress, - TAccountLendingMarketOwner, + TAccountGlobalConfig, TAccountLendingMarket, TAccountReserve, TAccountReserveLiquidityMint, TAccountLendingMarketAuthority, TAccountFeeVault, - TAccountLendingMarketOwnerAta, + TAccountFeeCollectorAta, TAccountTokenProgram >); } @@ -262,13 +378,13 @@ export interface ParsedWithdrawProtocolFeeInstruction< > { programAddress: Address; accounts: { - lendingMarketOwner: TAccountMetas[0]; + globalConfig: TAccountMetas[0]; lendingMarket: TAccountMetas[1]; reserve: TAccountMetas[2]; reserveLiquidityMint: TAccountMetas[3]; lendingMarketAuthority: TAccountMetas[4]; feeVault: TAccountMetas[5]; - lendingMarketOwnerAta: TAccountMetas[6]; + feeCollectorAta: TAccountMetas[6]; tokenProgram: TAccountMetas[7]; }; data: WithdrawProtocolFeeInstructionData; @@ -295,13 +411,13 @@ export function parseWithdrawProtocolFeeInstruction< return { programAddress: instruction.programAddress, accounts: { - lendingMarketOwner: getNextAccount(), + globalConfig: getNextAccount(), lendingMarket: getNextAccount(), reserve: getNextAccount(), reserveLiquidityMint: getNextAccount(), lendingMarketAuthority: getNextAccount(), feeVault: getNextAccount(), - lendingMarketOwnerAta: getNextAccount(), + feeCollectorAta: getNextAccount(), tokenProgram: getNextAccount(), }, data: getWithdrawProtocolFeeInstructionDataDecoder().decode( diff --git a/clients/kamino-lending/src/generated/instructions/withdrawReferrerFees.ts b/clients/kamino-lending/src/generated/instructions/withdrawReferrerFees.ts index 42d8253d..7974b363 100644 --- a/clients/kamino-lending/src/generated/instructions/withdrawReferrerFees.ts +++ b/clients/kamino-lending/src/generated/instructions/withdrawReferrerFees.ts @@ -33,8 +33,9 @@ import { getStructEncoder, transformEncoder, } from "@solana/kit"; +import { findLendingMarketAuthPda } from "../pdas/index.js"; import { KAMINO_LENDING_PROGRAM_ADDRESS } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const WITHDRAW_REFERRER_FEES_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([171, 118, 121, 201, 233, 140, 23, 228]); @@ -127,6 +128,142 @@ export function getWithdrawReferrerFeesInstructionDataCodec(): FixedSizeCodec< ); } +export interface WithdrawReferrerFeesAsyncInput< + TAccountReferrer extends string = string, + TAccountReferrerTokenState extends string = string, + TAccountReserve extends string = string, + TAccountReserveLiquidityMint extends string = string, + TAccountReserveSupplyLiquidity extends string = string, + TAccountReferrerTokenAccount extends string = string, + TAccountLendingMarket extends string = string, + TAccountLendingMarketAuthority extends string = string, + TAccountTokenProgram extends string = string, +> { + referrer: TransactionSigner; + referrerTokenState: Address; + reserve: Address; + reserveLiquidityMint: Address; + reserveSupplyLiquidity: Address; + referrerTokenAccount: Address; + lendingMarket: Address; + lendingMarketAuthority?: Address; + tokenProgram?: Address; +} + +export async function getWithdrawReferrerFeesInstructionAsync< + TAccountReferrer extends string, + TAccountReferrerTokenState extends string, + TAccountReserve extends string, + TAccountReserveLiquidityMint extends string, + TAccountReserveSupplyLiquidity extends string, + TAccountReferrerTokenAccount extends string, + TAccountLendingMarket extends string, + TAccountLendingMarketAuthority extends string, + TAccountTokenProgram extends string, + TProgramAddress extends Address = typeof KAMINO_LENDING_PROGRAM_ADDRESS, +>( + input: WithdrawReferrerFeesAsyncInput< + TAccountReferrer, + TAccountReferrerTokenState, + TAccountReserve, + TAccountReserveLiquidityMint, + TAccountReserveSupplyLiquidity, + TAccountReferrerTokenAccount, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + WithdrawReferrerFeesInstruction< + TProgramAddress, + TAccountReferrer, + TAccountReferrerTokenState, + TAccountReserve, + TAccountReserveLiquidityMint, + TAccountReserveSupplyLiquidity, + TAccountReferrerTokenAccount, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountTokenProgram + > +> { + // Program address. + const programAddress = + config?.programAddress ?? KAMINO_LENDING_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + referrer: { value: input.referrer ?? null, isWritable: true }, + referrerTokenState: { + value: input.referrerTokenState ?? null, + isWritable: true, + }, + reserve: { value: input.reserve ?? null, isWritable: true }, + reserveLiquidityMint: { + value: input.reserveLiquidityMint ?? null, + isWritable: false, + }, + reserveSupplyLiquidity: { + value: input.reserveSupplyLiquidity ?? null, + isWritable: true, + }, + referrerTokenAccount: { + value: input.referrerTokenAccount ?? null, + isWritable: true, + }, + lendingMarket: { value: input.lendingMarket ?? null, isWritable: false }, + lendingMarketAuthority: { + value: input.lendingMarketAuthority ?? null, + isWritable: false, + }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.lendingMarketAuthority.value) { + accounts.lendingMarketAuthority.value = await findLendingMarketAuthPda({ + lendingMarket: expectAddress(accounts.lendingMarket.value), + }); + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.referrer), + getAccountMeta(accounts.referrerTokenState), + getAccountMeta(accounts.reserve), + getAccountMeta(accounts.reserveLiquidityMint), + getAccountMeta(accounts.reserveSupplyLiquidity), + getAccountMeta(accounts.referrerTokenAccount), + getAccountMeta(accounts.lendingMarket), + getAccountMeta(accounts.lendingMarketAuthority), + getAccountMeta(accounts.tokenProgram), + ], + data: getWithdrawReferrerFeesInstructionDataEncoder().encode({}), + programAddress, + } as WithdrawReferrerFeesInstruction< + TProgramAddress, + TAccountReferrer, + TAccountReferrerTokenState, + TAccountReserve, + TAccountReserveLiquidityMint, + TAccountReserveSupplyLiquidity, + TAccountReferrerTokenAccount, + TAccountLendingMarket, + TAccountLendingMarketAuthority, + TAccountTokenProgram + >); +} + export interface WithdrawReferrerFeesInput< TAccountReferrer extends string = string, TAccountReferrerTokenState extends string = string, diff --git a/clients/kamino-lending/src/generated/instructions/withdrawReward.ts b/clients/kamino-lending/src/generated/instructions/withdrawReward.ts index e5ccb2a6..d7786a45 100644 --- a/clients/kamino-lending/src/generated/instructions/withdrawReward.ts +++ b/clients/kamino-lending/src/generated/instructions/withdrawReward.ts @@ -35,8 +35,12 @@ import { getU64Encoder, transformEncoder, } from "@solana/kit"; +import { + findFarmVaultsAuthorityPda, + findRewardVaultPda, +} from "../pdas/index.js"; import { FARMS_PROGRAM_ADDRESS } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const WITHDRAW_REWARD_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array( [191, 187, 176, 137, 9, 25, 187, 244], @@ -134,6 +138,137 @@ export function getWithdrawRewardInstructionDataCodec(): FixedSizeCodec< ); } +export interface WithdrawRewardAsyncInput< + TAccountFarmAdmin extends string = string, + TAccountFarmState extends string = string, + TAccountRewardMint extends string = string, + TAccountRewardVault extends string = string, + TAccountFarmVaultsAuthority extends string = string, + TAccountAdminRewardTokenAta extends string = string, + TAccountScopePrices extends string = string, + TAccountTokenProgram extends string = string, +> { + farmAdmin: TransactionSigner; + farmState: Address; + rewardMint: Address; + rewardVault?: Address; + farmVaultsAuthority?: Address; + adminRewardTokenAta: Address; + scopePrices?: Address; + tokenProgram?: Address; + amount: WithdrawRewardInstructionDataArgs["amount"]; + rewardIndex: WithdrawRewardInstructionDataArgs["rewardIndex"]; +} + +export async function getWithdrawRewardInstructionAsync< + TAccountFarmAdmin extends string, + TAccountFarmState extends string, + TAccountRewardMint extends string, + TAccountRewardVault extends string, + TAccountFarmVaultsAuthority extends string, + TAccountAdminRewardTokenAta extends string, + TAccountScopePrices extends string, + TAccountTokenProgram extends string, + TProgramAddress extends Address = typeof FARMS_PROGRAM_ADDRESS, +>( + input: WithdrawRewardAsyncInput< + TAccountFarmAdmin, + TAccountFarmState, + TAccountRewardMint, + TAccountRewardVault, + TAccountFarmVaultsAuthority, + TAccountAdminRewardTokenAta, + TAccountScopePrices, + TAccountTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + WithdrawRewardInstruction< + TProgramAddress, + TAccountFarmAdmin, + TAccountFarmState, + TAccountRewardMint, + TAccountRewardVault, + TAccountFarmVaultsAuthority, + TAccountAdminRewardTokenAta, + TAccountScopePrices, + TAccountTokenProgram + > +> { + // Program address. + const programAddress = config?.programAddress ?? FARMS_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + farmAdmin: { value: input.farmAdmin ?? null, isWritable: true }, + farmState: { value: input.farmState ?? null, isWritable: true }, + rewardMint: { value: input.rewardMint ?? null, isWritable: false }, + rewardVault: { value: input.rewardVault ?? null, isWritable: true }, + farmVaultsAuthority: { + value: input.farmVaultsAuthority ?? null, + isWritable: false, + }, + adminRewardTokenAta: { + value: input.adminRewardTokenAta ?? null, + isWritable: true, + }, + scopePrices: { value: input.scopePrices ?? null, isWritable: false }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.rewardVault.value) { + accounts.rewardVault.value = await findRewardVaultPda({ + farmState: expectAddress(accounts.farmState.value), + rewardMint: expectAddress(accounts.rewardMint.value), + }); + } + if (!accounts.farmVaultsAuthority.value) { + accounts.farmVaultsAuthority.value = await findFarmVaultsAuthorityPda({ + farmState: expectAddress(accounts.farmState.value), + }); + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.farmAdmin), + getAccountMeta(accounts.farmState), + getAccountMeta(accounts.rewardMint), + getAccountMeta(accounts.rewardVault), + getAccountMeta(accounts.farmVaultsAuthority), + getAccountMeta(accounts.adminRewardTokenAta), + getAccountMeta(accounts.scopePrices), + getAccountMeta(accounts.tokenProgram), + ], + data: getWithdrawRewardInstructionDataEncoder().encode( + args as WithdrawRewardInstructionDataArgs, + ), + programAddress, + } as WithdrawRewardInstruction< + TProgramAddress, + TAccountFarmAdmin, + TAccountFarmState, + TAccountRewardMint, + TAccountRewardVault, + TAccountFarmVaultsAuthority, + TAccountAdminRewardTokenAta, + TAccountScopePrices, + TAccountTokenProgram + >); +} + export interface WithdrawRewardInput< TAccountFarmAdmin extends string = string, TAccountFarmState extends string = string, diff --git a/clients/kamino-lending/src/generated/instructions/withdrawSlashedAmount.ts b/clients/kamino-lending/src/generated/instructions/withdrawSlashedAmount.ts index 91b29a69..97941c33 100644 --- a/clients/kamino-lending/src/generated/instructions/withdrawSlashedAmount.ts +++ b/clients/kamino-lending/src/generated/instructions/withdrawSlashedAmount.ts @@ -33,8 +33,9 @@ import { getStructEncoder, transformEncoder, } from "@solana/kit"; +import { findFarmVaultsAuthorityPda } from "../pdas/index.js"; import { FARMS_PROGRAM_ADDRESS } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const WITHDRAW_SLASHED_AMOUNT_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([202, 217, 67, 74, 172, 22, 140, 216]); @@ -115,6 +116,108 @@ export function getWithdrawSlashedAmountInstructionDataCodec(): FixedSizeCodec< ); } +export interface WithdrawSlashedAmountAsyncInput< + TAccountCrank extends string = string, + TAccountFarmState extends string = string, + TAccountSlashedAmountSpillAddress extends string = string, + TAccountFarmVault extends string = string, + TAccountFarmVaultsAuthority extends string = string, + TAccountTokenProgram extends string = string, +> { + crank: TransactionSigner; + farmState: Address; + slashedAmountSpillAddress: Address; + farmVault: Address; + farmVaultsAuthority?: Address; + tokenProgram?: Address; +} + +export async function getWithdrawSlashedAmountInstructionAsync< + TAccountCrank extends string, + TAccountFarmState extends string, + TAccountSlashedAmountSpillAddress extends string, + TAccountFarmVault extends string, + TAccountFarmVaultsAuthority extends string, + TAccountTokenProgram extends string, + TProgramAddress extends Address = typeof FARMS_PROGRAM_ADDRESS, +>( + input: WithdrawSlashedAmountAsyncInput< + TAccountCrank, + TAccountFarmState, + TAccountSlashedAmountSpillAddress, + TAccountFarmVault, + TAccountFarmVaultsAuthority, + TAccountTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + WithdrawSlashedAmountInstruction< + TProgramAddress, + TAccountCrank, + TAccountFarmState, + TAccountSlashedAmountSpillAddress, + TAccountFarmVault, + TAccountFarmVaultsAuthority, + TAccountTokenProgram + > +> { + // Program address. + const programAddress = config?.programAddress ?? FARMS_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + crank: { value: input.crank ?? null, isWritable: true }, + farmState: { value: input.farmState ?? null, isWritable: true }, + slashedAmountSpillAddress: { + value: input.slashedAmountSpillAddress ?? null, + isWritable: true, + }, + farmVault: { value: input.farmVault ?? null, isWritable: true }, + farmVaultsAuthority: { + value: input.farmVaultsAuthority ?? null, + isWritable: false, + }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.farmVaultsAuthority.value) { + accounts.farmVaultsAuthority.value = await findFarmVaultsAuthorityPda({ + farmState: expectAddress(accounts.farmState.value), + }); + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.crank), + getAccountMeta(accounts.farmState), + getAccountMeta(accounts.slashedAmountSpillAddress), + getAccountMeta(accounts.farmVault), + getAccountMeta(accounts.farmVaultsAuthority), + getAccountMeta(accounts.tokenProgram), + ], + data: getWithdrawSlashedAmountInstructionDataEncoder().encode({}), + programAddress, + } as WithdrawSlashedAmountInstruction< + TProgramAddress, + TAccountCrank, + TAccountFarmState, + TAccountSlashedAmountSpillAddress, + TAccountFarmVault, + TAccountFarmVaultsAuthority, + TAccountTokenProgram + >); +} + export interface WithdrawSlashedAmountInput< TAccountCrank extends string = string, TAccountFarmState extends string = string, diff --git a/clients/kamino-lending/src/generated/instructions/withdrawTreasury.ts b/clients/kamino-lending/src/generated/instructions/withdrawTreasury.ts index 14fa00fb..04c1b5aa 100644 --- a/clients/kamino-lending/src/generated/instructions/withdrawTreasury.ts +++ b/clients/kamino-lending/src/generated/instructions/withdrawTreasury.ts @@ -35,8 +35,12 @@ import { getU64Encoder, transformEncoder, } from "@solana/kit"; +import { + findRewardTreasuryVaultPda, + findTreasuryVaultsAuthorityPda, +} from "../pdas/index.js"; import { FARMS_PROGRAM_ADDRESS } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const WITHDRAW_TREASURY_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([40, 63, 122, 158, 144, 216, 83, 96]); @@ -125,6 +129,132 @@ export function getWithdrawTreasuryInstructionDataCodec(): FixedSizeCodec< ); } +export interface WithdrawTreasuryAsyncInput< + TAccountGlobalAdmin extends string = string, + TAccountGlobalConfig extends string = string, + TAccountRewardMint extends string = string, + TAccountRewardTreasuryVault extends string = string, + TAccountTreasuryVaultAuthority extends string = string, + TAccountWithdrawDestinationTokenAccount extends string = string, + TAccountTokenProgram extends string = string, +> { + globalAdmin: TransactionSigner; + globalConfig: Address; + rewardMint: Address; + rewardTreasuryVault?: Address; + treasuryVaultAuthority?: Address; + withdrawDestinationTokenAccount: Address; + tokenProgram?: Address; + amount: WithdrawTreasuryInstructionDataArgs["amount"]; +} + +export async function getWithdrawTreasuryInstructionAsync< + TAccountGlobalAdmin extends string, + TAccountGlobalConfig extends string, + TAccountRewardMint extends string, + TAccountRewardTreasuryVault extends string, + TAccountTreasuryVaultAuthority extends string, + TAccountWithdrawDestinationTokenAccount extends string, + TAccountTokenProgram extends string, + TProgramAddress extends Address = typeof FARMS_PROGRAM_ADDRESS, +>( + input: WithdrawTreasuryAsyncInput< + TAccountGlobalAdmin, + TAccountGlobalConfig, + TAccountRewardMint, + TAccountRewardTreasuryVault, + TAccountTreasuryVaultAuthority, + TAccountWithdrawDestinationTokenAccount, + TAccountTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + WithdrawTreasuryInstruction< + TProgramAddress, + TAccountGlobalAdmin, + TAccountGlobalConfig, + TAccountRewardMint, + TAccountRewardTreasuryVault, + TAccountTreasuryVaultAuthority, + TAccountWithdrawDestinationTokenAccount, + TAccountTokenProgram + > +> { + // Program address. + const programAddress = config?.programAddress ?? FARMS_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + globalAdmin: { value: input.globalAdmin ?? null, isWritable: true }, + globalConfig: { value: input.globalConfig ?? null, isWritable: false }, + rewardMint: { value: input.rewardMint ?? null, isWritable: false }, + rewardTreasuryVault: { + value: input.rewardTreasuryVault ?? null, + isWritable: true, + }, + treasuryVaultAuthority: { + value: input.treasuryVaultAuthority ?? null, + isWritable: false, + }, + withdrawDestinationTokenAccount: { + value: input.withdrawDestinationTokenAccount ?? null, + isWritable: true, + }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.rewardTreasuryVault.value) { + accounts.rewardTreasuryVault.value = await findRewardTreasuryVaultPda({ + globalConfig: expectAddress(accounts.globalConfig.value), + rewardMint: expectAddress(accounts.rewardMint.value), + }); + } + if (!accounts.treasuryVaultAuthority.value) { + accounts.treasuryVaultAuthority.value = + await findTreasuryVaultsAuthorityPda({ + globalConfig: expectAddress(accounts.globalConfig.value), + }); + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.globalAdmin), + getAccountMeta(accounts.globalConfig), + getAccountMeta(accounts.rewardMint), + getAccountMeta(accounts.rewardTreasuryVault), + getAccountMeta(accounts.treasuryVaultAuthority), + getAccountMeta(accounts.withdrawDestinationTokenAccount), + getAccountMeta(accounts.tokenProgram), + ], + data: getWithdrawTreasuryInstructionDataEncoder().encode( + args as WithdrawTreasuryInstructionDataArgs, + ), + programAddress, + } as WithdrawTreasuryInstruction< + TProgramAddress, + TAccountGlobalAdmin, + TAccountGlobalConfig, + TAccountRewardMint, + TAccountRewardTreasuryVault, + TAccountTreasuryVaultAuthority, + TAccountWithdrawDestinationTokenAccount, + TAccountTokenProgram + >); +} + export interface WithdrawTreasuryInput< TAccountGlobalAdmin extends string = string, TAccountGlobalConfig extends string = string, diff --git a/clients/kamino-lending/src/generated/instructions/withdrawUnstakedDeposits.ts b/clients/kamino-lending/src/generated/instructions/withdrawUnstakedDeposits.ts index 21e6ffba..fe4b1d36 100644 --- a/clients/kamino-lending/src/generated/instructions/withdrawUnstakedDeposits.ts +++ b/clients/kamino-lending/src/generated/instructions/withdrawUnstakedDeposits.ts @@ -33,8 +33,12 @@ import { getStructEncoder, transformEncoder, } from "@solana/kit"; +import { + findFarmsUserStatePda, + findFarmVaultsAuthorityPda, +} from "../pdas/index.js"; import { FARMS_PROGRAM_ADDRESS } from "../programs/index.js"; -import { getAccountMetaFactory } from "../shared/index.js"; +import { expectAddress, getAccountMetaFactory } from "../shared/index.js"; export const WITHDRAW_UNSTAKED_DEPOSITS_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([36, 102, 187, 49, 220, 36, 132, 67]); @@ -119,6 +123,119 @@ export function getWithdrawUnstakedDepositsInstructionDataCodec(): FixedSizeCode ); } +export interface WithdrawUnstakedDepositsAsyncInput< + TAccountOwner extends string = string, + TAccountUserState extends string = string, + TAccountFarmState extends string = string, + TAccountUserAta extends string = string, + TAccountFarmVault extends string = string, + TAccountFarmVaultsAuthority extends string = string, + TAccountTokenProgram extends string = string, +> { + owner: TransactionSigner; + userState?: Address; + farmState: Address; + userAta: Address; + farmVault: Address; + farmVaultsAuthority?: Address; + tokenProgram?: Address; +} + +export async function getWithdrawUnstakedDepositsInstructionAsync< + TAccountOwner extends string, + TAccountUserState extends string, + TAccountFarmState extends string, + TAccountUserAta extends string, + TAccountFarmVault extends string, + TAccountFarmVaultsAuthority extends string, + TAccountTokenProgram extends string, + TProgramAddress extends Address = typeof FARMS_PROGRAM_ADDRESS, +>( + input: WithdrawUnstakedDepositsAsyncInput< + TAccountOwner, + TAccountUserState, + TAccountFarmState, + TAccountUserAta, + TAccountFarmVault, + TAccountFarmVaultsAuthority, + TAccountTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): Promise< + WithdrawUnstakedDepositsInstruction< + TProgramAddress, + TAccountOwner, + TAccountUserState, + TAccountFarmState, + TAccountUserAta, + TAccountFarmVault, + TAccountFarmVaultsAuthority, + TAccountTokenProgram + > +> { + // Program address. + const programAddress = config?.programAddress ?? FARMS_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + owner: { value: input.owner ?? null, isWritable: true }, + userState: { value: input.userState ?? null, isWritable: true }, + farmState: { value: input.farmState ?? null, isWritable: true }, + userAta: { value: input.userAta ?? null, isWritable: true }, + farmVault: { value: input.farmVault ?? null, isWritable: true }, + farmVaultsAuthority: { + value: input.farmVaultsAuthority ?? null, + isWritable: false, + }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.userState.value) { + accounts.userState.value = await findFarmsUserStatePda({ + farmState: expectAddress(accounts.farmState.value), + owner: expectAddress(accounts.owner.value), + }); + } + if (!accounts.farmVaultsAuthority.value) { + accounts.farmVaultsAuthority.value = await findFarmVaultsAuthorityPda({ + farmState: expectAddress(accounts.farmState.value), + }); + } + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.owner), + getAccountMeta(accounts.userState), + getAccountMeta(accounts.farmState), + getAccountMeta(accounts.userAta), + getAccountMeta(accounts.farmVault), + getAccountMeta(accounts.farmVaultsAuthority), + getAccountMeta(accounts.tokenProgram), + ], + data: getWithdrawUnstakedDepositsInstructionDataEncoder().encode({}), + programAddress, + } as WithdrawUnstakedDepositsInstruction< + TProgramAddress, + TAccountOwner, + TAccountUserState, + TAccountFarmState, + TAccountUserAta, + TAccountFarmVault, + TAccountFarmVaultsAuthority, + TAccountTokenProgram + >); +} + export interface WithdrawUnstakedDepositsInput< TAccountOwner extends string = string, TAccountUserState extends string = string, diff --git a/clients/kamino-lending/src/generated/pdas/obligationFarmState.ts b/clients/kamino-lending/src/generated/pdas/farmVault.ts similarity index 70% rename from clients/kamino-lending/src/generated/pdas/obligationFarmState.ts rename to clients/kamino-lending/src/generated/pdas/farmVault.ts index 5ca20f4b..d9f05064 100644 --- a/clients/kamino-lending/src/generated/pdas/obligationFarmState.ts +++ b/clients/kamino-lending/src/generated/pdas/farmVault.ts @@ -13,13 +13,13 @@ import { getUtf8Encoder, } from "@solana/kit"; -export interface ObligationFarmStateSeeds { - farm: Address; - obligation: Address; +export interface FarmVaultSeeds { + farmState: Address; + tokenMint: Address; } -export async function findObligationFarmStatePda( - seeds: ObligationFarmStateSeeds, +export async function findFarmVaultPda( + seeds: FarmVaultSeeds, config: { programAddress?: Address | undefined } = {}, ): Promise { const { @@ -28,9 +28,9 @@ export async function findObligationFarmStatePda( return await getProgramDerivedAddress({ programAddress, seeds: [ - getUtf8Encoder().encode("user"), - getAddressEncoder().encode(seeds.farm), - getAddressEncoder().encode(seeds.obligation), + getUtf8Encoder().encode("fvault"), + getAddressEncoder().encode(seeds.farmState), + getAddressEncoder().encode(seeds.tokenMint), ], }); } diff --git a/clients/kamino-lending/src/generated/pdas/farmVaultsAuthority.ts b/clients/kamino-lending/src/generated/pdas/farmVaultsAuthority.ts new file mode 100644 index 00000000..ac15f077 --- /dev/null +++ b/clients/kamino-lending/src/generated/pdas/farmVaultsAuthority.ts @@ -0,0 +1,34 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { Address, ProgramDerivedAddress } from "@solana/kit"; +import { + getAddressEncoder, + getProgramDerivedAddress, + getUtf8Encoder, +} from "@solana/kit"; + +export interface FarmVaultsAuthoritySeeds { + farmState: Address; +} + +export async function findFarmVaultsAuthorityPda( + seeds: FarmVaultsAuthoritySeeds, + config: { programAddress?: Address | undefined } = {}, +): Promise { + const { + programAddress = "FarmsPZpWu9i7Kky8tPN37rs2TpmMrAZrC7S7vJa91Hr" as Address<"FarmsPZpWu9i7Kky8tPN37rs2TpmMrAZrC7S7vJa91Hr">, + } = config; + return await getProgramDerivedAddress({ + programAddress, + seeds: [ + getUtf8Encoder().encode("authority"), + getAddressEncoder().encode(seeds.farmState), + ], + }); +} diff --git a/clients/kamino-lending/src/generated/pdas/farmsUserState.ts b/clients/kamino-lending/src/generated/pdas/farmsUserState.ts new file mode 100644 index 00000000..b4e333aa --- /dev/null +++ b/clients/kamino-lending/src/generated/pdas/farmsUserState.ts @@ -0,0 +1,37 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { Address, ProgramDerivedAddress } from "@solana/kit"; +import { + getAddressEncoder, + getProgramDerivedAddress, + getUtf8Encoder, +} from "@solana/kit"; + +export interface FarmsUserStateSeeds { + farmState: Address; + /** The user who is farming. This is sometimes the obligation in the case of delegated farms. */ + owner: Address; +} + +export async function findFarmsUserStatePda( + seeds: FarmsUserStateSeeds, + config: { programAddress?: Address | undefined } = {}, +): Promise { + const { + programAddress = "FarmsPZpWu9i7Kky8tPN37rs2TpmMrAZrC7S7vJa91Hr" as Address<"FarmsPZpWu9i7Kky8tPN37rs2TpmMrAZrC7S7vJa91Hr">, + } = config; + return await getProgramDerivedAddress({ + programAddress, + seeds: [ + getUtf8Encoder().encode("user"), + getAddressEncoder().encode(seeds.farmState), + getAddressEncoder().encode(seeds.owner), + ], + }); +} diff --git a/clients/kamino-lending/src/generated/pdas/index.ts b/clients/kamino-lending/src/generated/pdas/index.ts index ddc4a1ff..0a685218 100644 --- a/clients/kamino-lending/src/generated/pdas/index.ts +++ b/clients/kamino-lending/src/generated/pdas/index.ts @@ -6,14 +6,20 @@ * @see https://github.com/codama-idl/codama */ +export * from "./farmsUserState.js"; +export * from "./farmVault.js"; +export * from "./farmVaultsAuthority.js"; +export * from "./lendingGlobalConfigState.js"; export * from "./lendingMarketAuth.js"; export * from "./obligation.js"; -export * from "./obligationFarmState.js"; export * from "./referrerState.js"; export * from "./referrerTokenState.js"; export * from "./reserveCollateralMint.js"; export * from "./reserveCollateralSupply.js"; export * from "./reserveFeeVault.js"; export * from "./reserveLiquiditySupply.js"; +export * from "./rewardTreasuryVault.js"; +export * from "./rewardVault.js"; export * from "./shortUrl.js"; +export * from "./treasuryVaultsAuthority.js"; export * from "./userMetadata.js"; diff --git a/clients/kamino-lending/src/generated/pdas/lendingGlobalConfigState.ts b/clients/kamino-lending/src/generated/pdas/lendingGlobalConfigState.ts new file mode 100644 index 00000000..1a7921ac --- /dev/null +++ b/clients/kamino-lending/src/generated/pdas/lendingGlobalConfigState.ts @@ -0,0 +1,22 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { Address, ProgramDerivedAddress } from "@solana/kit"; +import { getProgramDerivedAddress, getUtf8Encoder } from "@solana/kit"; + +export async function findLendingGlobalConfigStatePda( + config: { programAddress?: Address | undefined } = {}, +): Promise { + const { + programAddress = "KLend2g3cP87fffoy8q1mQqGKjrxjC8boSyAYavgmjD" as Address<"KLend2g3cP87fffoy8q1mQqGKjrxjC8boSyAYavgmjD">, + } = config; + return await getProgramDerivedAddress({ + programAddress, + seeds: [getUtf8Encoder().encode("global_config")], + }); +} diff --git a/clients/kamino-lending/src/generated/pdas/rewardTreasuryVault.ts b/clients/kamino-lending/src/generated/pdas/rewardTreasuryVault.ts new file mode 100644 index 00000000..98327015 --- /dev/null +++ b/clients/kamino-lending/src/generated/pdas/rewardTreasuryVault.ts @@ -0,0 +1,36 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { Address, ProgramDerivedAddress } from "@solana/kit"; +import { + getAddressEncoder, + getProgramDerivedAddress, + getUtf8Encoder, +} from "@solana/kit"; + +export interface RewardTreasuryVaultSeeds { + globalConfig: Address; + rewardMint: Address; +} + +export async function findRewardTreasuryVaultPda( + seeds: RewardTreasuryVaultSeeds, + config: { programAddress?: Address | undefined } = {}, +): Promise { + const { + programAddress = "FarmsPZpWu9i7Kky8tPN37rs2TpmMrAZrC7S7vJa91Hr" as Address<"FarmsPZpWu9i7Kky8tPN37rs2TpmMrAZrC7S7vJa91Hr">, + } = config; + return await getProgramDerivedAddress({ + programAddress, + seeds: [ + getUtf8Encoder().encode("tvault"), + getAddressEncoder().encode(seeds.globalConfig), + getAddressEncoder().encode(seeds.rewardMint), + ], + }); +} diff --git a/clients/kamino-lending/src/generated/pdas/rewardVault.ts b/clients/kamino-lending/src/generated/pdas/rewardVault.ts new file mode 100644 index 00000000..3fcbb865 --- /dev/null +++ b/clients/kamino-lending/src/generated/pdas/rewardVault.ts @@ -0,0 +1,36 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { Address, ProgramDerivedAddress } from "@solana/kit"; +import { + getAddressEncoder, + getProgramDerivedAddress, + getUtf8Encoder, +} from "@solana/kit"; + +export interface RewardVaultSeeds { + farmState: Address; + rewardMint: Address; +} + +export async function findRewardVaultPda( + seeds: RewardVaultSeeds, + config: { programAddress?: Address | undefined } = {}, +): Promise { + const { + programAddress = "FarmsPZpWu9i7Kky8tPN37rs2TpmMrAZrC7S7vJa91Hr" as Address<"FarmsPZpWu9i7Kky8tPN37rs2TpmMrAZrC7S7vJa91Hr">, + } = config; + return await getProgramDerivedAddress({ + programAddress, + seeds: [ + getUtf8Encoder().encode("rvault"), + getAddressEncoder().encode(seeds.farmState), + getAddressEncoder().encode(seeds.rewardMint), + ], + }); +} diff --git a/clients/kamino-lending/src/generated/pdas/treasuryVaultsAuthority.ts b/clients/kamino-lending/src/generated/pdas/treasuryVaultsAuthority.ts new file mode 100644 index 00000000..f475fe7e --- /dev/null +++ b/clients/kamino-lending/src/generated/pdas/treasuryVaultsAuthority.ts @@ -0,0 +1,34 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { Address, ProgramDerivedAddress } from "@solana/kit"; +import { + getAddressEncoder, + getProgramDerivedAddress, + getUtf8Encoder, +} from "@solana/kit"; + +export interface TreasuryVaultsAuthoritySeeds { + globalConfig: Address; +} + +export async function findTreasuryVaultsAuthorityPda( + seeds: TreasuryVaultsAuthoritySeeds, + config: { programAddress?: Address | undefined } = {}, +): Promise { + const { + programAddress = "FarmsPZpWu9i7Kky8tPN37rs2TpmMrAZrC7S7vJa91Hr" as Address<"FarmsPZpWu9i7Kky8tPN37rs2TpmMrAZrC7S7vJa91Hr">, + } = config; + return await getProgramDerivedAddress({ + programAddress, + seeds: [ + getUtf8Encoder().encode("authority"), + getAddressEncoder().encode(seeds.globalConfig), + ], + }); +} diff --git a/clients/kamino-lending/src/generated/programs/farms.ts b/clients/kamino-lending/src/generated/programs/farms.ts index 46942dd1..e1407212 100644 --- a/clients/kamino-lending/src/generated/programs/farms.ts +++ b/clients/kamino-lending/src/generated/programs/farms.ts @@ -41,7 +41,7 @@ export const FARMS_PROGRAM_ADDRESS = export enum FarmsAccount { FarmState = 0, - GlobalConfig = 1, + FarmsGlobalConfig = 1, FarmsUserState = 2, OraclePrices = 3, } @@ -70,7 +70,7 @@ export function identifyFarmsAccount( 0, ) ) { - return FarmsAccount.GlobalConfig; + return FarmsAccount.FarmsGlobalConfig; } if ( containsBytes( diff --git a/clients/kamino-lending/src/generated/programs/kaminoLending.ts b/clients/kamino-lending/src/generated/programs/kaminoLending.ts index 3789ccb1..5f550b8f 100644 --- a/clients/kamino-lending/src/generated/programs/kaminoLending.ts +++ b/clients/kamino-lending/src/generated/programs/kaminoLending.ts @@ -21,6 +21,7 @@ import type { ParsedFlashRepayReserveLiquidityInstruction, ParsedIdlMissingTypesInstruction, ParsedInitFarmsForReserveInstruction, + ParsedInitGlobalConfigInstruction, ParsedInitLendingMarketInstruction, ParsedInitObligationFarmsForReserveInstruction, ParsedInitObligationInstruction, @@ -41,8 +42,11 @@ import type { ParsedRepayObligationLiquidityInstruction, ParsedRepayObligationLiquidityV2Instruction, ParsedRequestElevationGroupInstruction, + ParsedSetObligationOrderInstruction, ParsedSocializeLossInstruction, ParsedSocializeLossV2Instruction, + ParsedUpdateGlobalConfigAdminInstruction, + ParsedUpdateGlobalConfigInstruction, ParsedUpdateLendingMarketInstruction, ParsedUpdateLendingMarketOwnerInstruction, ParsedUpdateReserveConfigInstruction, @@ -60,13 +64,14 @@ export const KAMINO_LENDING_PROGRAM_ADDRESS = export enum KaminoLendingAccount { UserState = 0, - LendingMarket = 1, - Obligation = 2, - ReferrerState = 3, - ReferrerTokenState = 4, - ShortUrl = 5, - UserMetadata = 6, - Reserve = 7, + LendingGlobalConfig = 1, + LendingMarket = 2, + Obligation = 3, + ReferrerState = 4, + ReferrerTokenState = 5, + ShortUrl = 6, + UserMetadata = 7, + Reserve = 8, } export function identifyKaminoLendingAccount( @@ -84,6 +89,17 @@ export function identifyKaminoLendingAccount( ) { return KaminoLendingAccount.UserState; } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([149, 8, 156, 202, 160, 252, 176, 217]), + ), + 0, + ) + ) { + return KaminoLendingAccount.LendingGlobalConfig; + } if ( containsBytes( data, @@ -178,8 +194,8 @@ export enum KaminoLendingInstruction { SocializeLoss = 8, SocializeLossV2 = 9, MarkObligationForDeleveraging = 10, - RefreshReservesBatch = 11, - RefreshReserve = 12, + RefreshReserve = 11, + RefreshReservesBatch = 12, DepositReserveLiquidity = 13, RedeemReserveCollateral = 14, InitObligation = 15, @@ -210,7 +226,11 @@ export enum KaminoLendingInstruction { WithdrawReferrerFees = 40, InitReferrerStateAndShortUrl = 41, DeleteReferrerStateAndShortUrl = 42, - IdlMissingTypes = 43, + SetObligationOrder = 43, + InitGlobalConfig = 44, + UpdateGlobalConfig = 45, + UpdateGlobalConfigAdmin = 46, + IdlMissingTypes = 47, } export function identifyKaminoLendingInstruction( @@ -342,23 +362,23 @@ export function identifyKaminoLendingInstruction( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( - new Uint8Array([144, 110, 26, 103, 162, 204, 252, 147]), + new Uint8Array([2, 218, 138, 235, 79, 201, 25, 102]), ), 0, ) ) { - return KaminoLendingInstruction.RefreshReservesBatch; + return KaminoLendingInstruction.RefreshReserve; } if ( containsBytes( data, fixEncoderSize(getBytesEncoder(), 8).encode( - new Uint8Array([2, 218, 138, 235, 79, 201, 25, 102]), + new Uint8Array([144, 110, 26, 103, 162, 204, 252, 147]), ), 0, ) ) { - return KaminoLendingInstruction.RefreshReserve; + return KaminoLendingInstruction.RefreshReservesBatch; } if ( containsBytes( @@ -690,6 +710,50 @@ export function identifyKaminoLendingInstruction( ) { return KaminoLendingInstruction.DeleteReferrerStateAndShortUrl; } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([81, 1, 99, 156, 211, 83, 78, 46]), + ), + 0, + ) + ) { + return KaminoLendingInstruction.SetObligationOrder; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([140, 136, 214, 48, 87, 0, 120, 255]), + ), + 0, + ) + ) { + return KaminoLendingInstruction.InitGlobalConfig; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([164, 84, 130, 189, 111, 58, 250, 200]), + ), + 0, + ) + ) { + return KaminoLendingInstruction.UpdateGlobalConfig; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([184, 87, 23, 193, 156, 238, 175, 119]), + ), + 0, + ) + ) { + return KaminoLendingInstruction.UpdateGlobalConfigAdmin; + } if ( containsBytes( data, @@ -742,12 +806,12 @@ export type ParsedKaminoLendingInstruction< | ({ instructionType: KaminoLendingInstruction.MarkObligationForDeleveraging; } & ParsedMarkObligationForDeleveragingInstruction) - | ({ - instructionType: KaminoLendingInstruction.RefreshReservesBatch; - } & ParsedRefreshReservesBatchInstruction) | ({ instructionType: KaminoLendingInstruction.RefreshReserve; } & ParsedRefreshReserveInstruction) + | ({ + instructionType: KaminoLendingInstruction.RefreshReservesBatch; + } & ParsedRefreshReservesBatchInstruction) | ({ instructionType: KaminoLendingInstruction.DepositReserveLiquidity; } & ParsedDepositReserveLiquidityInstruction) @@ -838,6 +902,18 @@ export type ParsedKaminoLendingInstruction< | ({ instructionType: KaminoLendingInstruction.DeleteReferrerStateAndShortUrl; } & ParsedDeleteReferrerStateAndShortUrlInstruction) + | ({ + instructionType: KaminoLendingInstruction.SetObligationOrder; + } & ParsedSetObligationOrderInstruction) + | ({ + instructionType: KaminoLendingInstruction.InitGlobalConfig; + } & ParsedInitGlobalConfigInstruction) + | ({ + instructionType: KaminoLendingInstruction.UpdateGlobalConfig; + } & ParsedUpdateGlobalConfigInstruction) + | ({ + instructionType: KaminoLendingInstruction.UpdateGlobalConfigAdmin; + } & ParsedUpdateGlobalConfigAdminInstruction) | ({ instructionType: KaminoLendingInstruction.IdlMissingTypes; } & ParsedIdlMissingTypesInstruction); diff --git a/clients/kamino-lending/src/generated/types/elevationGroup.ts b/clients/kamino-lending/src/generated/types/elevationGroup.ts index 1af1922a..797352ed 100644 --- a/clients/kamino-lending/src/generated/types/elevationGroup.ts +++ b/clients/kamino-lending/src/generated/types/elevationGroup.ts @@ -36,6 +36,7 @@ export interface ElevationGroup { allowNewLoans: number; maxReservesAsCollateral: number; padding0: number; + /** Mandatory debt reserve for this elevation group */ debtReserve: Address; padding1: bigint[]; } @@ -48,6 +49,7 @@ export interface ElevationGroupArgs { allowNewLoans: number; maxReservesAsCollateral: number; padding0: number; + /** Mandatory debt reserve for this elevation group */ debtReserve: Address; padding1: (number | bigint)[]; } diff --git a/clients/kamino-lending/src/generated/types/elevationGroupLendingMarket.ts b/clients/kamino-lending/src/generated/types/elevationGroupPod.ts similarity index 78% rename from clients/kamino-lending/src/generated/types/elevationGroupLendingMarket.ts rename to clients/kamino-lending/src/generated/types/elevationGroupPod.ts index 1354338a..a6cbf56f 100644 --- a/clients/kamino-lending/src/generated/types/elevationGroupLendingMarket.ts +++ b/clients/kamino-lending/src/generated/types/elevationGroupPod.ts @@ -28,7 +28,7 @@ import { getU64Encoder, } from "@solana/kit"; -export interface ElevationGroupLendingMarket { +export interface ElevationGroupPod { maxLiquidationBonusBps: number; id: number; ltvPct: number; @@ -36,11 +36,12 @@ export interface ElevationGroupLendingMarket { allowNewLoans: number; maxReservesAsCollateral: number; padding0: number; + /** Mandatory debt reserve for this elevation group */ debtReserve: Address; padding1: bigint[]; } -export interface ElevationGroupLendingMarketArgs { +export interface ElevationGroupPodArgs { maxLiquidationBonusBps: number; id: number; ltvPct: number; @@ -48,11 +49,12 @@ export interface ElevationGroupLendingMarketArgs { allowNewLoans: number; maxReservesAsCollateral: number; padding0: number; + /** Mandatory debt reserve for this elevation group */ debtReserve: Address; padding1: (number | bigint)[]; } -export function getElevationGroupLendingMarketEncoder(): FixedSizeEncoder { +export function getElevationGroupPodEncoder(): FixedSizeEncoder { return getStructEncoder([ ["maxLiquidationBonusBps", getU16Encoder()], ["id", getU8Encoder()], @@ -66,7 +68,7 @@ export function getElevationGroupLendingMarketEncoder(): FixedSizeEncoder { +export function getElevationGroupPodDecoder(): FixedSizeDecoder { return getStructDecoder([ ["maxLiquidationBonusBps", getU16Decoder()], ["id", getU8Decoder()], @@ -80,12 +82,12 @@ export function getElevationGroupLendingMarketDecoder(): FixedSizeDecoder { return combineCodec( - getElevationGroupLendingMarketEncoder(), - getElevationGroupLendingMarketDecoder(), + getElevationGroupPodEncoder(), + getElevationGroupPodDecoder(), ); } diff --git a/clients/kamino-lending/src/generated/types/feeCalculation.ts b/clients/kamino-lending/src/generated/types/feeCalculation.ts index e686909c..7321bc2c 100644 --- a/clients/kamino-lending/src/generated/types/feeCalculation.ts +++ b/clients/kamino-lending/src/generated/types/feeCalculation.ts @@ -13,6 +13,7 @@ import type { } from "@solana/kit"; import { combineCodec, getEnumDecoder, getEnumEncoder } from "@solana/kit"; +/** Calculate fees exlusive or inclusive of an amount */ export enum FeeCalculation { Exclusive = 0, Inclusive = 1, diff --git a/clients/kamino-lending/src/generated/types/index.ts b/clients/kamino-lending/src/generated/types/index.ts index 8c6d46b1..1fd48340 100644 --- a/clients/kamino-lending/src/generated/types/index.ts +++ b/clients/kamino-lending/src/generated/types/index.ts @@ -12,7 +12,7 @@ export * from "./borrowRateCurve.js"; export * from "./curvePoint.js"; export * from "./datedPrice.js"; export * from "./elevationGroup.js"; -export * from "./elevationGroupLendingMarket.js"; +export * from "./elevationGroupPod.js"; export * from "./farmConfigOption.js"; export * from "./farmsTokenInfo.js"; export * from "./feeCalculation.js"; @@ -22,6 +22,8 @@ export * from "./lastUpdate.js"; export * from "./lockingMode.js"; export * from "./obligationCollateral.js"; export * from "./obligationLiquidity.js"; +export * from "./obligationOrder.js"; +export * from "./obligationOrderInput.js"; export * from "./price.js"; export * from "./priceHeuristic.js"; export * from "./pythConfiguration.js"; @@ -40,6 +42,7 @@ export * from "./switchboardConfiguration.js"; export * from "./timeUnit.js"; export * from "./tokenInfo.js"; export * from "./updateConfigMode.js"; +export * from "./updateGlobalConfigMode.js"; export * from "./updateLendingMarketConfigValue.js"; export * from "./updateLendingMarketMode.js"; export * from "./withdrawalCaps.js"; diff --git a/clients/kamino-lending/src/generated/types/lastUpdate.ts b/clients/kamino-lending/src/generated/types/lastUpdate.ts index ca121b26..b37d83a2 100644 --- a/clients/kamino-lending/src/generated/types/lastUpdate.ts +++ b/clients/kamino-lending/src/generated/types/lastUpdate.ts @@ -23,16 +23,23 @@ import { getU64Encoder, } from "@solana/kit"; +/** Last update state */ export interface LastUpdate { + /** Last slot when updated */ slot: bigint; + /** True when marked stale, false when slot updated */ stale: number; + /** Status of the prices used to calculate the last update */ priceStatus: number; placeholder: number[]; } export interface LastUpdateArgs { + /** Last slot when updated */ slot: number | bigint; + /** True when marked stale, false when slot updated */ stale: number; + /** Status of the prices used to calculate the last update */ priceStatus: number; placeholder: number[]; } diff --git a/clients/kamino-lending/src/generated/types/obligationCollateral.ts b/clients/kamino-lending/src/generated/types/obligationCollateral.ts index a255148a..db176dbf 100644 --- a/clients/kamino-lending/src/generated/types/obligationCollateral.ts +++ b/clients/kamino-lending/src/generated/types/obligationCollateral.ts @@ -26,18 +26,37 @@ import { getU128Encoder, } from "@solana/kit"; +/** Obligation collateral state */ export interface ObligationCollateral { + /** Reserve collateral is deposited to */ depositReserve: Address; + /** Amount of collateral deposited */ depositedAmount: bigint; + /** Collateral market value in quote currency (scaled fraction) */ marketValueSf: bigint; + /** + * Debt amount (lamport) taken against this collateral. + * (only meaningful if this obligation is part of an elevation group, otherwise 0) + * This is only indicative of the debt computed on the last refresh obligation. + * If the obligation have multiple collateral this value is the same for all of them. + */ borrowedAmountAgainstThisCollateralInElevationGroup: bigint; padding: bigint[]; } export interface ObligationCollateralArgs { + /** Reserve collateral is deposited to */ depositReserve: Address; + /** Amount of collateral deposited */ depositedAmount: number | bigint; + /** Collateral market value in quote currency (scaled fraction) */ marketValueSf: number | bigint; + /** + * Debt amount (lamport) taken against this collateral. + * (only meaningful if this obligation is part of an elevation group, otherwise 0) + * This is only indicative of the debt computed on the last refresh obligation. + * If the obligation have multiple collateral this value is the same for all of them. + */ borrowedAmountAgainstThisCollateralInElevationGroup: number | bigint; padding: (number | bigint)[]; } diff --git a/clients/kamino-lending/src/generated/types/obligationLiquidity.ts b/clients/kamino-lending/src/generated/types/obligationLiquidity.ts index a6f0537f..f87ec7fc 100644 --- a/clients/kamino-lending/src/generated/types/obligationLiquidity.ts +++ b/clients/kamino-lending/src/generated/types/obligationLiquidity.ts @@ -31,24 +31,37 @@ import { getBigFractionBytesEncoder, } from "./index.js"; +/** Obligation liquidity state */ export interface ObligationLiquidity { + /** Reserve liquidity is borrowed from */ borrowReserve: Address; + /** Borrow rate used for calculating interest (big scaled fraction) */ cumulativeBorrowRateBsf: BigFractionBytes; padding: bigint; + /** Amount of liquidity borrowed plus interest (scaled fraction) */ borrowedAmountSf: bigint; + /** Liquidity market value in quote currency (scaled fraction) */ marketValueSf: bigint; + /** Risk adjusted liquidity market value in quote currency - DEBUG ONLY - use market_value instead */ borrowFactorAdjustedMarketValueSf: bigint; + /** Amount of liquidity borrowed outside of an elevation group */ borrowedAmountOutsideElevationGroups: bigint; padding2: bigint[]; } export interface ObligationLiquidityArgs { + /** Reserve liquidity is borrowed from */ borrowReserve: Address; + /** Borrow rate used for calculating interest (big scaled fraction) */ cumulativeBorrowRateBsf: BigFractionBytesArgs; padding: number | bigint; + /** Amount of liquidity borrowed plus interest (scaled fraction) */ borrowedAmountSf: number | bigint; + /** Liquidity market value in quote currency (scaled fraction) */ marketValueSf: number | bigint; + /** Risk adjusted liquidity market value in quote currency - DEBUG ONLY - use market_value instead */ borrowFactorAdjustedMarketValueSf: number | bigint; + /** Amount of liquidity borrowed outside of an elevation group */ borrowedAmountOutsideElevationGroups: number | bigint; padding2: (number | bigint)[]; } diff --git a/clients/kamino-lending/src/generated/types/obligationOrder.ts b/clients/kamino-lending/src/generated/types/obligationOrder.ts new file mode 100644 index 00000000..05f97b21 --- /dev/null +++ b/clients/kamino-lending/src/generated/types/obligationOrder.ts @@ -0,0 +1,233 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, +} from "@solana/kit"; +import { + combineCodec, + getArrayDecoder, + getArrayEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU16Decoder, + getU16Encoder, + getU128Decoder, + getU128Encoder, +} from "@solana/kit"; + +/** + * A single obligation order. + * See [Obligation::orders]. + */ +export interface ObligationOrder { + /** + * A threshold value used by the condition (scaled [Fraction]). + * The exact meaning depends on the specific [Self::condition_type]. + * + * Examples: + * - when `condition_type == 2 (UserLtvBelow)`: + * then a value of `0.455` here means that the order is active only when the obligation's + * user LTV is less than `0.455` (i.e. < 45.5%). + * - when `condition_type == 3 (DebtCollPriceRatioAbove)`: + * assuming the obligation uses BTC collateral for SOL debt, then a value of `491.3` here + * means that the order is active only when the BTC-SOL price is greater than `491.3` (i.e. + * > 491.3 SOL per BTC). + */ + conditionThresholdSf: bigint; + /** + * A configuration parameter used by the opportunity (scaled [Fraction]). + * The exact meaning depends on the specific [Self::opportunity_type]. + * + * Examples: + * - when `opportunity_type == 0 (DeleverageSingleDebtAmount)`: + * Assuming the obligation uses BTC collateral for SOL debt, then a value of `1_234_000_000` + * here means that a liquidator may repay up to 1234000000 lamports (i.e. 1.234 SOL) on this + * obligation. + * Note: the special value of [Fraction::MAX] is *not* allowed in this case. + * - when `opportunity_type == 1 (DeleverageAllDebtAmount)`: + * The only allowed value in this case is [Fraction::MAX] (to emphasize that *all* debt + * should be repaid). + */ + opportunityParameterSf: bigint; + /** + * A *minimum* additional fraction of collateral transferred to the liquidator, in bps. + * + * The minimum bonus is applied exactly when the [Self::condition_threshold_sf] is met, and + * grows linearly towards the [Self::max_execution_bonus_bps]. + * + * Example: a value of `50` here means 50bps == 0.5% bonus for an "LTV > 65%" order, when + * executed precisely at the moment LTV exceeds 65%. + */ + minExecutionBonusBps: number; + /** + * A *maximum* additional fraction of collateral transferred to the liquidator, in bps. + * + * The maximum bonus is applied at the relevant "extreme" state of the obligation, i.e.: + * - for a stop-loss condition, it is a point at which the obligation becomes liquidatable; + * - for a take-profit condition, it is a point at which obligation has 0% LTV. + * + * In non-extreme states, the actual bonus value is interpolated linearly, starting from + * [Self::min_execution_bonus_bps] (at the point specified by the order's condition). + * + * Example: a value of `300` here means 300bps == 3.0% bonus for a "debt/coll price > 140" + * order, when executed at a higher price = 200, at which the obligation's LTV happens to + * be equal to its liquidation LTV. + */ + maxExecutionBonusBps: number; + /** + * Serialized [ConditionType]. + * The entire order is void when this is zeroed (i.e. representing [ConditionType::Never]). + * + * Example: a value of `2` here denotes `UserLtvBelow` condition type. Of course, to + * interpret this condition, we also need to take the [Self::condition_threshold_sf] into + * account. + */ + conditionType: number; + /** + * Serialized [OpportunityType]. + * + * Example: a value of `0` here denotes `DeleverageSingleDebtAmount` opportunity. Of course, to + * interpret this opportunity, we also need to take the [Self::opportunity_parameter_sf] into + * account. + */ + opportunityType: number; + /** + * Internal padding. + * The fields above take up 2+2+1+1 bytes = 48 bits, which means we need 80 bits = 10 bytes to + * align with `u128`s. + */ + padding1: number[]; + /** + * End padding. + * The total size of a single instance is 8*u128 = 128 bytes. + */ + padding2: bigint[]; +} + +export interface ObligationOrderArgs { + /** + * A threshold value used by the condition (scaled [Fraction]). + * The exact meaning depends on the specific [Self::condition_type]. + * + * Examples: + * - when `condition_type == 2 (UserLtvBelow)`: + * then a value of `0.455` here means that the order is active only when the obligation's + * user LTV is less than `0.455` (i.e. < 45.5%). + * - when `condition_type == 3 (DebtCollPriceRatioAbove)`: + * assuming the obligation uses BTC collateral for SOL debt, then a value of `491.3` here + * means that the order is active only when the BTC-SOL price is greater than `491.3` (i.e. + * > 491.3 SOL per BTC). + */ + conditionThresholdSf: number | bigint; + /** + * A configuration parameter used by the opportunity (scaled [Fraction]). + * The exact meaning depends on the specific [Self::opportunity_type]. + * + * Examples: + * - when `opportunity_type == 0 (DeleverageSingleDebtAmount)`: + * Assuming the obligation uses BTC collateral for SOL debt, then a value of `1_234_000_000` + * here means that a liquidator may repay up to 1234000000 lamports (i.e. 1.234 SOL) on this + * obligation. + * Note: the special value of [Fraction::MAX] is *not* allowed in this case. + * - when `opportunity_type == 1 (DeleverageAllDebtAmount)`: + * The only allowed value in this case is [Fraction::MAX] (to emphasize that *all* debt + * should be repaid). + */ + opportunityParameterSf: number | bigint; + /** + * A *minimum* additional fraction of collateral transferred to the liquidator, in bps. + * + * The minimum bonus is applied exactly when the [Self::condition_threshold_sf] is met, and + * grows linearly towards the [Self::max_execution_bonus_bps]. + * + * Example: a value of `50` here means 50bps == 0.5% bonus for an "LTV > 65%" order, when + * executed precisely at the moment LTV exceeds 65%. + */ + minExecutionBonusBps: number; + /** + * A *maximum* additional fraction of collateral transferred to the liquidator, in bps. + * + * The maximum bonus is applied at the relevant "extreme" state of the obligation, i.e.: + * - for a stop-loss condition, it is a point at which the obligation becomes liquidatable; + * - for a take-profit condition, it is a point at which obligation has 0% LTV. + * + * In non-extreme states, the actual bonus value is interpolated linearly, starting from + * [Self::min_execution_bonus_bps] (at the point specified by the order's condition). + * + * Example: a value of `300` here means 300bps == 3.0% bonus for a "debt/coll price > 140" + * order, when executed at a higher price = 200, at which the obligation's LTV happens to + * be equal to its liquidation LTV. + */ + maxExecutionBonusBps: number; + /** + * Serialized [ConditionType]. + * The entire order is void when this is zeroed (i.e. representing [ConditionType::Never]). + * + * Example: a value of `2` here denotes `UserLtvBelow` condition type. Of course, to + * interpret this condition, we also need to take the [Self::condition_threshold_sf] into + * account. + */ + conditionType: number; + /** + * Serialized [OpportunityType]. + * + * Example: a value of `0` here denotes `DeleverageSingleDebtAmount` opportunity. Of course, to + * interpret this opportunity, we also need to take the [Self::opportunity_parameter_sf] into + * account. + */ + opportunityType: number; + /** + * Internal padding. + * The fields above take up 2+2+1+1 bytes = 48 bits, which means we need 80 bits = 10 bytes to + * align with `u128`s. + */ + padding1: number[]; + /** + * End padding. + * The total size of a single instance is 8*u128 = 128 bytes. + */ + padding2: (number | bigint)[]; +} + +export function getObligationOrderEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ["conditionThresholdSf", getU128Encoder()], + ["opportunityParameterSf", getU128Encoder()], + ["minExecutionBonusBps", getU16Encoder()], + ["maxExecutionBonusBps", getU16Encoder()], + ["conditionType", getU8Encoder()], + ["opportunityType", getU8Encoder()], + ["padding1", getArrayEncoder(getU8Encoder(), { size: 10 })], + ["padding2", getArrayEncoder(getU128Encoder(), { size: 5 })], + ]); +} + +export function getObligationOrderDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["conditionThresholdSf", getU128Decoder()], + ["opportunityParameterSf", getU128Decoder()], + ["minExecutionBonusBps", getU16Decoder()], + ["maxExecutionBonusBps", getU16Decoder()], + ["conditionType", getU8Decoder()], + ["opportunityType", getU8Decoder()], + ["padding1", getArrayDecoder(getU8Decoder(), { size: 10 })], + ["padding2", getArrayDecoder(getU128Decoder(), { size: 5 })], + ]); +} + +export function getObligationOrderCodec(): FixedSizeCodec< + ObligationOrderArgs, + ObligationOrder +> { + return combineCodec(getObligationOrderEncoder(), getObligationOrderDecoder()); +} diff --git a/clients/kamino-lending/src/generated/types/obligationOrderInput.ts b/clients/kamino-lending/src/generated/types/obligationOrderInput.ts new file mode 100644 index 00000000..e21ab3af --- /dev/null +++ b/clients/kamino-lending/src/generated/types/obligationOrderInput.ts @@ -0,0 +1,236 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, +} from "@solana/kit"; +import { + combineCodec, + getArrayDecoder, + getArrayEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU16Decoder, + getU16Encoder, + getU128Decoder, + getU128Encoder, +} from "@solana/kit"; + +/** + * A single obligation order. + * See [Obligation::orders]. + */ +export interface ObligationOrderInput { + /** + * A threshold value used by the condition (scaled [Fraction]). + * The exact meaning depends on the specific [Self::condition_type]. + * + * Examples: + * - when `condition_type == 2 (UserLtvBelow)`: + * then a value of `0.455` here means that the order is active only when the obligation's + * user LTV is less than `0.455` (i.e. < 45.5%). + * - when `condition_type == 3 (DebtCollPriceRatioAbove)`: + * assuming the obligation uses BTC collateral for SOL debt, then a value of `491.3` here + * means that the order is active only when the BTC-SOL price is greater than `491.3` (i.e. + * > 491.3 SOL per BTC). + */ + conditionThresholdSf: bigint; + /** + * A configuration parameter used by the opportunity (scaled [Fraction]). + * The exact meaning depends on the specific [Self::opportunity_type]. + * + * Examples: + * - when `opportunity_type == 0 (DeleverageSingleDebtAmount)`: + * Assuming the obligation uses BTC collateral for SOL debt, then a value of `1_234_000_000` + * here means that a liquidator may repay up to 1234000000 lamports (i.e. 1.234 SOL) on this + * obligation. + * Note: the special value of [Fraction::MAX] is *not* allowed in this case. + * - when `opportunity_type == 1 (DeleverageAllDebtAmount)`: + * The only allowed value in this case is [Fraction::MAX] (to emphasize that *all* debt + * should be repaid). + */ + opportunityParameterSf: bigint; + /** + * A *minimum* additional fraction of collateral transferred to the liquidator, in bps. + * + * The minimum bonus is applied exactly when the [Self::condition_threshold_sf] is met, and + * grows linearly towards the [Self::max_execution_bonus_bps]. + * + * Example: a value of `50` here means 50bps == 0.5% bonus for an "LTV > 65%" order, when + * executed precisely at the moment LTV exceeds 65%. + */ + minExecutionBonusBps: number; + /** + * A *maximum* additional fraction of collateral transferred to the liquidator, in bps. + * + * The maximum bonus is applied at the relevant "extreme" state of the obligation, i.e.: + * - for a stop-loss condition, it is a point at which the obligation becomes liquidatable; + * - for a take-profit condition, it is a point at which obligation has 0% LTV. + * + * In non-extreme states, the actual bonus value is interpolated linearly, starting from + * [Self::min_execution_bonus_bps] (at the point specified by the order's condition). + * + * Example: a value of `300` here means 300bps == 3.0% bonus for a "debt/coll price > 140" + * order, when executed at a higher price = 200, at which the obligation's LTV happens to + * be equal to its liquidation LTV. + */ + maxExecutionBonusBps: number; + /** + * Serialized [ConditionType]. + * The entire order is void when this is zeroed (i.e. representing [ConditionType::Never]). + * + * Example: a value of `2` here denotes `UserLtvBelow` condition type. Of course, to + * interpret this condition, we also need to take the [Self::condition_threshold_sf] into + * account. + */ + conditionType: number; + /** + * Serialized [OpportunityType]. + * + * Example: a value of `0` here denotes `DeleverageSingleDebtAmount` opportunity. Of course, to + * interpret this opportunity, we also need to take the [Self::opportunity_parameter_sf] into + * account. + */ + opportunityType: number; + /** + * Internal padding. + * The fields above take up 2+2+1+1 bytes = 48 bits, which means we need 80 bits = 10 bytes to + * align with `u128`s. + */ + padding1: number[]; + /** + * End padding. + * The total size of a single instance is 8*u128 = 128 bytes. + */ + padding2: bigint[]; +} + +export interface ObligationOrderInputArgs { + /** + * A threshold value used by the condition (scaled [Fraction]). + * The exact meaning depends on the specific [Self::condition_type]. + * + * Examples: + * - when `condition_type == 2 (UserLtvBelow)`: + * then a value of `0.455` here means that the order is active only when the obligation's + * user LTV is less than `0.455` (i.e. < 45.5%). + * - when `condition_type == 3 (DebtCollPriceRatioAbove)`: + * assuming the obligation uses BTC collateral for SOL debt, then a value of `491.3` here + * means that the order is active only when the BTC-SOL price is greater than `491.3` (i.e. + * > 491.3 SOL per BTC). + */ + conditionThresholdSf: number | bigint; + /** + * A configuration parameter used by the opportunity (scaled [Fraction]). + * The exact meaning depends on the specific [Self::opportunity_type]. + * + * Examples: + * - when `opportunity_type == 0 (DeleverageSingleDebtAmount)`: + * Assuming the obligation uses BTC collateral for SOL debt, then a value of `1_234_000_000` + * here means that a liquidator may repay up to 1234000000 lamports (i.e. 1.234 SOL) on this + * obligation. + * Note: the special value of [Fraction::MAX] is *not* allowed in this case. + * - when `opportunity_type == 1 (DeleverageAllDebtAmount)`: + * The only allowed value in this case is [Fraction::MAX] (to emphasize that *all* debt + * should be repaid). + */ + opportunityParameterSf: number | bigint; + /** + * A *minimum* additional fraction of collateral transferred to the liquidator, in bps. + * + * The minimum bonus is applied exactly when the [Self::condition_threshold_sf] is met, and + * grows linearly towards the [Self::max_execution_bonus_bps]. + * + * Example: a value of `50` here means 50bps == 0.5% bonus for an "LTV > 65%" order, when + * executed precisely at the moment LTV exceeds 65%. + */ + minExecutionBonusBps: number; + /** + * A *maximum* additional fraction of collateral transferred to the liquidator, in bps. + * + * The maximum bonus is applied at the relevant "extreme" state of the obligation, i.e.: + * - for a stop-loss condition, it is a point at which the obligation becomes liquidatable; + * - for a take-profit condition, it is a point at which obligation has 0% LTV. + * + * In non-extreme states, the actual bonus value is interpolated linearly, starting from + * [Self::min_execution_bonus_bps] (at the point specified by the order's condition). + * + * Example: a value of `300` here means 300bps == 3.0% bonus for a "debt/coll price > 140" + * order, when executed at a higher price = 200, at which the obligation's LTV happens to + * be equal to its liquidation LTV. + */ + maxExecutionBonusBps: number; + /** + * Serialized [ConditionType]. + * The entire order is void when this is zeroed (i.e. representing [ConditionType::Never]). + * + * Example: a value of `2` here denotes `UserLtvBelow` condition type. Of course, to + * interpret this condition, we also need to take the [Self::condition_threshold_sf] into + * account. + */ + conditionType: number; + /** + * Serialized [OpportunityType]. + * + * Example: a value of `0` here denotes `DeleverageSingleDebtAmount` opportunity. Of course, to + * interpret this opportunity, we also need to take the [Self::opportunity_parameter_sf] into + * account. + */ + opportunityType: number; + /** + * Internal padding. + * The fields above take up 2+2+1+1 bytes = 48 bits, which means we need 80 bits = 10 bytes to + * align with `u128`s. + */ + padding1: number[]; + /** + * End padding. + * The total size of a single instance is 8*u128 = 128 bytes. + */ + padding2: (number | bigint)[]; +} + +export function getObligationOrderInputEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ["conditionThresholdSf", getU128Encoder()], + ["opportunityParameterSf", getU128Encoder()], + ["minExecutionBonusBps", getU16Encoder()], + ["maxExecutionBonusBps", getU16Encoder()], + ["conditionType", getU8Encoder()], + ["opportunityType", getU8Encoder()], + ["padding1", getArrayEncoder(getU8Encoder(), { size: 10 })], + ["padding2", getArrayEncoder(getU128Encoder(), { size: 5 })], + ]); +} + +export function getObligationOrderInputDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["conditionThresholdSf", getU128Decoder()], + ["opportunityParameterSf", getU128Decoder()], + ["minExecutionBonusBps", getU16Decoder()], + ["maxExecutionBonusBps", getU16Decoder()], + ["conditionType", getU8Decoder()], + ["opportunityType", getU8Decoder()], + ["padding1", getArrayDecoder(getU8Decoder(), { size: 10 })], + ["padding2", getArrayDecoder(getU128Decoder(), { size: 5 })], + ]); +} + +export function getObligationOrderInputCodec(): FixedSizeCodec< + ObligationOrderInputArgs, + ObligationOrderInput +> { + return combineCodec( + getObligationOrderInputEncoder(), + getObligationOrderInputDecoder(), + ); +} diff --git a/clients/kamino-lending/src/generated/types/priceHeuristic.ts b/clients/kamino-lending/src/generated/types/priceHeuristic.ts index dab1490b..29cee2f0 100644 --- a/clients/kamino-lending/src/generated/types/priceHeuristic.ts +++ b/clients/kamino-lending/src/generated/types/priceHeuristic.ts @@ -20,14 +20,20 @@ import { } from "@solana/kit"; export interface PriceHeuristic { + /** Lower value of acceptable price */ lower: bigint; + /** Upper value of acceptable price */ upper: bigint; + /** Number of decimals of the previously defined values */ exp: bigint; } export interface PriceHeuristicArgs { + /** Lower value of acceptable price */ lower: number | bigint; + /** Upper value of acceptable price */ upper: number | bigint; + /** Number of decimals of the previously defined values */ exp: number | bigint; } diff --git a/clients/kamino-lending/src/generated/types/pythConfiguration.ts b/clients/kamino-lending/src/generated/types/pythConfiguration.ts index 62978757..442e1825 100644 --- a/clients/kamino-lending/src/generated/types/pythConfiguration.ts +++ b/clients/kamino-lending/src/generated/types/pythConfiguration.ts @@ -21,6 +21,7 @@ import { } from "@solana/kit"; export interface PythConfiguration { + /** Pubkey of the base price feed (disabled if `null` or `default`) */ price: Address; } diff --git a/clients/kamino-lending/src/generated/types/reserveCollateral.ts b/clients/kamino-lending/src/generated/types/reserveCollateral.ts index 85b4a958..1f8c2fd4 100644 --- a/clients/kamino-lending/src/generated/types/reserveCollateral.ts +++ b/clients/kamino-lending/src/generated/types/reserveCollateral.ts @@ -26,17 +26,24 @@ import { getU128Encoder, } from "@solana/kit"; +/** Reserve collateral */ export interface ReserveCollateral { + /** Reserve collateral mint address */ mintPubkey: Address; + /** Reserve collateral mint supply, used for exchange rate */ mintTotalSupply: bigint; + /** Reserve collateral supply address */ supplyVault: Address; padding1: bigint[]; padding2: bigint[]; } export interface ReserveCollateralArgs { + /** Reserve collateral mint address */ mintPubkey: Address; + /** Reserve collateral mint supply, used for exchange rate */ mintTotalSupply: number | bigint; + /** Reserve collateral supply address */ supplyVault: Address; padding1: (number | bigint)[]; padding2: (number | bigint)[]; diff --git a/clients/kamino-lending/src/generated/types/reserveConfig.ts b/clients/kamino-lending/src/generated/types/reserveConfig.ts index f527d3ca..0cafb304 100644 --- a/clients/kamino-lending/src/generated/types/reserveConfig.ts +++ b/clients/kamino-lending/src/generated/types/reserveConfig.ts @@ -45,69 +45,190 @@ import { getWithdrawalCapsEncoder, } from "./index.js"; +/** Reserve configuration values */ export interface ReserveConfig { + /** Status of the reserve Active/Obsolete/Hidden */ status: number; + /** Asset tier -> 0 - regular (collateral & debt), 1 - isolated collateral, 2 - isolated debt */ assetTier: number; + /** Flat rate that goes to the host */ hostFixedInterestRateBps: number; + /** + * [DEPRECATED] Space that used to hold 2 fields: + * - Boost for side (debt or collateral) + * - Reward points multiplier per obligation type + * Can be re-used after making sure all underlying production account data is zeroed. + */ reserved2: number[]; - reserved3: number[]; + /** Cut of the order execution bonus that the protocol receives, as a percentage */ + protocolOrderExecutionFeePct: number; + /** Protocol take rate is the amount borrowed interest protocol receives, as a percentage */ protocolTakeRatePct: number; + /** Cut of the liquidation bonus that the protocol receives, as a percentage */ protocolLiquidationFeePct: number; + /** + * Target ratio of the value of borrows to deposits, as a percentage + * 0 if use as collateral is disabled + */ loanToValuePct: number; + /** Loan to value ratio at which an obligation can be liquidated, as percentage */ liquidationThresholdPct: number; + /** Minimum bonus a liquidator receives when repaying part of an unhealthy obligation, as bps */ minLiquidationBonusBps: number; + /** Maximum bonus a liquidator receives when repaying part of an unhealthy obligation, as bps */ maxLiquidationBonusBps: number; + /** Bad debt liquidation bonus for an undercollateralized obligation, as bps */ badDebtLiquidationBonusBps: number; + /** + * Time in seconds that must pass before redemptions are enabled after the deposit limit is + * crossed. + * Only relevant when `autodeleverage_enabled == 1`, and must not be 0 in such case. + */ deleveragingMarginCallPeriodSecs: bigint; + /** + * The rate at which the deleveraging threshold decreases, in bps per day. + * Only relevant when `autodeleverage_enabled == 1`, and must not be 0 in such case. + */ deleveragingThresholdDecreaseBpsPerDay: bigint; + /** Program owner fees assessed, separate from gains due to interest accrual */ fees: ReserveFees; + /** Borrow rate curve based on utilization */ borrowRateCurve: BorrowRateCurve; + /** Borrow factor in percentage - used for risk adjustment */ borrowFactorPct: bigint; + /** Maximum deposit limit of liquidity in native units, u64::MAX for inf */ depositLimit: bigint; + /** Maximum amount borrowed, u64::MAX for inf, 0 to disable borrows (protected deposits) */ borrowLimit: bigint; + /** Token id from TokenInfos struct */ tokenInfo: TokenInfo; + /** Deposit withdrawal caps - deposit & redeem */ depositWithdrawalCap: WithdrawalCaps; + /** Debt withdrawal caps - borrow & repay */ debtWithdrawalCap: WithdrawalCaps; elevationGroups: number[]; disableUsageAsCollOutsideEmode: number; + /** Utilization (in percentage) above which borrowing is blocked. 0 to disable. */ utilizationLimitBlockBorrowingAbovePct: number; + /** + * Whether this reserve should be subject to auto-deleveraging after deposit or borrow limit is + * crossed. + * Besides this flag, the lending market's flag also needs to be enabled (logical `AND`). + * **NOTE:** the manual "target LTV" deleveraging (enabled by the risk council for individual + * obligations) is NOT affected by this flag. + */ autodeleverageEnabled: number; reserved1: number[]; + /** + * Maximum amount liquidity of this reserve borrowed outside all elevation groups + * - u64::MAX for inf + * - 0 to disable borrows outside elevation groups + */ borrowLimitOutsideElevationGroup: bigint; + /** + * Defines the maximum amount (in lamports of elevation group debt asset) + * that can be borrowed when this reserve is used as collateral. + * - u64::MAX for inf + * - 0 to disable borrows in this elevation group (expected value for the debt asset) + */ borrowLimitAgainstThisCollateralInElevationGroup: bigint[]; + /** + * The rate at which the deleveraging-related liquidation bonus increases, in bps per day. + * Only relevant when `autodeleverage_enabled == 1`, and must not be 0 in such case. + */ deleveragingBonusIncreaseBpsPerDay: bigint; } export interface ReserveConfigArgs { + /** Status of the reserve Active/Obsolete/Hidden */ status: number; + /** Asset tier -> 0 - regular (collateral & debt), 1 - isolated collateral, 2 - isolated debt */ assetTier: number; + /** Flat rate that goes to the host */ hostFixedInterestRateBps: number; + /** + * [DEPRECATED] Space that used to hold 2 fields: + * - Boost for side (debt or collateral) + * - Reward points multiplier per obligation type + * Can be re-used after making sure all underlying production account data is zeroed. + */ reserved2: number[]; - reserved3: number[]; + /** Cut of the order execution bonus that the protocol receives, as a percentage */ + protocolOrderExecutionFeePct: number; + /** Protocol take rate is the amount borrowed interest protocol receives, as a percentage */ protocolTakeRatePct: number; + /** Cut of the liquidation bonus that the protocol receives, as a percentage */ protocolLiquidationFeePct: number; + /** + * Target ratio of the value of borrows to deposits, as a percentage + * 0 if use as collateral is disabled + */ loanToValuePct: number; + /** Loan to value ratio at which an obligation can be liquidated, as percentage */ liquidationThresholdPct: number; + /** Minimum bonus a liquidator receives when repaying part of an unhealthy obligation, as bps */ minLiquidationBonusBps: number; + /** Maximum bonus a liquidator receives when repaying part of an unhealthy obligation, as bps */ maxLiquidationBonusBps: number; + /** Bad debt liquidation bonus for an undercollateralized obligation, as bps */ badDebtLiquidationBonusBps: number; + /** + * Time in seconds that must pass before redemptions are enabled after the deposit limit is + * crossed. + * Only relevant when `autodeleverage_enabled == 1`, and must not be 0 in such case. + */ deleveragingMarginCallPeriodSecs: number | bigint; + /** + * The rate at which the deleveraging threshold decreases, in bps per day. + * Only relevant when `autodeleverage_enabled == 1`, and must not be 0 in such case. + */ deleveragingThresholdDecreaseBpsPerDay: number | bigint; + /** Program owner fees assessed, separate from gains due to interest accrual */ fees: ReserveFeesArgs; + /** Borrow rate curve based on utilization */ borrowRateCurve: BorrowRateCurveArgs; + /** Borrow factor in percentage - used for risk adjustment */ borrowFactorPct: number | bigint; + /** Maximum deposit limit of liquidity in native units, u64::MAX for inf */ depositLimit: number | bigint; + /** Maximum amount borrowed, u64::MAX for inf, 0 to disable borrows (protected deposits) */ borrowLimit: number | bigint; + /** Token id from TokenInfos struct */ tokenInfo: TokenInfoArgs; + /** Deposit withdrawal caps - deposit & redeem */ depositWithdrawalCap: WithdrawalCapsArgs; + /** Debt withdrawal caps - borrow & repay */ debtWithdrawalCap: WithdrawalCapsArgs; elevationGroups: number[]; disableUsageAsCollOutsideEmode: number; + /** Utilization (in percentage) above which borrowing is blocked. 0 to disable. */ utilizationLimitBlockBorrowingAbovePct: number; + /** + * Whether this reserve should be subject to auto-deleveraging after deposit or borrow limit is + * crossed. + * Besides this flag, the lending market's flag also needs to be enabled (logical `AND`). + * **NOTE:** the manual "target LTV" deleveraging (enabled by the risk council for individual + * obligations) is NOT affected by this flag. + */ autodeleverageEnabled: number; reserved1: number[]; + /** + * Maximum amount liquidity of this reserve borrowed outside all elevation groups + * - u64::MAX for inf + * - 0 to disable borrows outside elevation groups + */ borrowLimitOutsideElevationGroup: number | bigint; + /** + * Defines the maximum amount (in lamports of elevation group debt asset) + * that can be borrowed when this reserve is used as collateral. + * - u64::MAX for inf + * - 0 to disable borrows in this elevation group (expected value for the debt asset) + */ borrowLimitAgainstThisCollateralInElevationGroup: (number | bigint)[]; + /** + * The rate at which the deleveraging-related liquidation bonus increases, in bps per day. + * Only relevant when `autodeleverage_enabled == 1`, and must not be 0 in such case. + */ deleveragingBonusIncreaseBpsPerDay: number | bigint; } @@ -116,8 +237,8 @@ export function getReserveConfigEncoder(): FixedSizeEncoder { ["status", getU8Encoder()], ["assetTier", getU8Encoder()], ["hostFixedInterestRateBps", getU16Encoder()], - ["reserved2", getArrayEncoder(getU8Encoder(), { size: 2 })], - ["reserved3", getArrayEncoder(getU8Encoder(), { size: 8 })], + ["reserved2", getArrayEncoder(getU8Encoder(), { size: 9 })], + ["protocolOrderExecutionFeePct", getU8Encoder()], ["protocolTakeRatePct", getU8Encoder()], ["protocolLiquidationFeePct", getU8Encoder()], ["loanToValuePct", getU8Encoder()], @@ -154,8 +275,8 @@ export function getReserveConfigDecoder(): FixedSizeDecoder { ["status", getU8Decoder()], ["assetTier", getU8Decoder()], ["hostFixedInterestRateBps", getU16Decoder()], - ["reserved2", getArrayDecoder(getU8Decoder(), { size: 2 })], - ["reserved3", getArrayDecoder(getU8Decoder(), { size: 8 })], + ["reserved2", getArrayDecoder(getU8Decoder(), { size: 9 })], + ["protocolOrderExecutionFeePct", getU8Decoder()], ["protocolTakeRatePct", getU8Decoder()], ["protocolLiquidationFeePct", getU8Decoder()], ["loanToValuePct", getU8Decoder()], diff --git a/clients/kamino-lending/src/generated/types/reserveFees.ts b/clients/kamino-lending/src/generated/types/reserveFees.ts index 3efe4e71..4e289c5d 100644 --- a/clients/kamino-lending/src/generated/types/reserveFees.ts +++ b/clients/kamino-lending/src/generated/types/reserveFees.ts @@ -23,15 +23,48 @@ import { getU64Encoder, } from "@solana/kit"; +/** + * Additional fee information on a reserve + * + * These exist separately from interest accrual fees, and are specifically for the program owner + * and referral fee. The fees are paid out as a percentage of liquidity token amounts during + * repayments and liquidations. + */ export interface ReserveFees { + /** + * Fee assessed on `BorrowObligationLiquidity`, as scaled fraction (60 bits fractional part) + * Must be between `0` and `2^60`, such that `2^60 = 1`. A few examples for + * clarity: + * 1% = (1 << 60) / 100 = 11529215046068470 + * 0.01% (1 basis point) = 115292150460685 + * 0.00001% (Aave borrow fee) = 115292150461 + */ borrowFeeSf: bigint; + /** + * Fee for flash loan, expressed as scaled fraction. + * 0.3% (Aave flash loan fee) = 0.003 * 2^60 = 3458764513820541 + */ flashLoanFeeSf: bigint; + /** Used for allignment */ padding: number[]; } export interface ReserveFeesArgs { + /** + * Fee assessed on `BorrowObligationLiquidity`, as scaled fraction (60 bits fractional part) + * Must be between `0` and `2^60`, such that `2^60 = 1`. A few examples for + * clarity: + * 1% = (1 << 60) / 100 = 11529215046068470 + * 0.01% (1 basis point) = 115292150460685 + * 0.00001% (Aave borrow fee) = 115292150461 + */ borrowFeeSf: number | bigint; + /** + * Fee for flash loan, expressed as scaled fraction. + * 0.3% (Aave flash loan fee) = 0.003 * 2^60 = 3458764513820541 + */ flashLoanFeeSf: number | bigint; + /** Used for allignment */ padding: number[]; } diff --git a/clients/kamino-lending/src/generated/types/reserveLiquidity.ts b/clients/kamino-lending/src/generated/types/reserveLiquidity.ts index 11b62123..8d2162d6 100644 --- a/clients/kamino-lending/src/generated/types/reserveLiquidity.ts +++ b/clients/kamino-lending/src/generated/types/reserveLiquidity.ts @@ -31,43 +31,88 @@ import { getBigFractionBytesEncoder, } from "./index.js"; +/** Reserve liquidity */ export interface ReserveLiquidity { + /** Reserve liquidity mint address */ mintPubkey: Address; + /** Reserve liquidity supply address */ supplyVault: Address; + /** Reserve liquidity fee collection address */ feeVault: Address; + /** Reserve liquidity available */ availableAmount: bigint; + /** Reserve liquidity borrowed (scaled fraction) */ borrowedAmountSf: bigint; + /** Reserve liquidity market price in quote currency (scaled fraction) */ marketPriceSf: bigint; + /** Unix timestamp of the market price (from the oracle) */ marketPriceLastUpdatedTs: bigint; + /** Reserve liquidity mint decimals */ mintDecimals: bigint; + /** + * Timestamp when the last refresh reserve detected that the liquidity amount is above the deposit cap. When this threshold is crossed, then redemptions (auto-deleverage) are enabled. + * If the threshold is not crossed, then the timestamp is set to 0 + */ depositLimitCrossedTimestamp: bigint; + /** + * Timestamp when the last refresh reserve detected that the borrowed amount is above the borrow cap. When this threshold is crossed, then redemptions (auto-deleverage) are enabled. + * If the threshold is not crossed, then the timestamp is set to 0 + */ borrowLimitCrossedTimestamp: bigint; + /** Reserve liquidity cumulative borrow rate (scaled fraction) */ cumulativeBorrowRateBsf: BigFractionBytes; + /** Reserve cumulative protocol fees (scaled fraction) */ accumulatedProtocolFeesSf: bigint; + /** Reserve cumulative referrer fees (scaled fraction) */ accumulatedReferrerFeesSf: bigint; + /** Reserve pending referrer fees, to be claimed in refresh_obligation by referrer or protocol (scaled fraction) */ pendingReferrerFeesSf: bigint; + /** Reserve referrer fee absolute rate calculated at each refresh_reserve operation (scaled fraction) */ absoluteReferralRateSf: bigint; + /** Token program of the liquidity mint */ tokenProgram: Address; padding2: bigint[]; padding3: bigint[]; } export interface ReserveLiquidityArgs { + /** Reserve liquidity mint address */ mintPubkey: Address; + /** Reserve liquidity supply address */ supplyVault: Address; + /** Reserve liquidity fee collection address */ feeVault: Address; + /** Reserve liquidity available */ availableAmount: number | bigint; + /** Reserve liquidity borrowed (scaled fraction) */ borrowedAmountSf: number | bigint; + /** Reserve liquidity market price in quote currency (scaled fraction) */ marketPriceSf: number | bigint; + /** Unix timestamp of the market price (from the oracle) */ marketPriceLastUpdatedTs: number | bigint; + /** Reserve liquidity mint decimals */ mintDecimals: number | bigint; + /** + * Timestamp when the last refresh reserve detected that the liquidity amount is above the deposit cap. When this threshold is crossed, then redemptions (auto-deleverage) are enabled. + * If the threshold is not crossed, then the timestamp is set to 0 + */ depositLimitCrossedTimestamp: number | bigint; + /** + * Timestamp when the last refresh reserve detected that the borrowed amount is above the borrow cap. When this threshold is crossed, then redemptions (auto-deleverage) are enabled. + * If the threshold is not crossed, then the timestamp is set to 0 + */ borrowLimitCrossedTimestamp: number | bigint; + /** Reserve liquidity cumulative borrow rate (scaled fraction) */ cumulativeBorrowRateBsf: BigFractionBytesArgs; + /** Reserve cumulative protocol fees (scaled fraction) */ accumulatedProtocolFeesSf: number | bigint; + /** Reserve cumulative referrer fees (scaled fraction) */ accumulatedReferrerFeesSf: number | bigint; + /** Reserve pending referrer fees, to be claimed in refresh_obligation by referrer or protocol (scaled fraction) */ pendingReferrerFeesSf: number | bigint; + /** Reserve referrer fee absolute rate calculated at each refresh_reserve operation (scaled fraction) */ absoluteReferralRateSf: number | bigint; + /** Token program of the liquidity mint */ tokenProgram: Address; padding2: (number | bigint)[]; padding3: (number | bigint)[]; diff --git a/clients/kamino-lending/src/generated/types/scopeConfiguration.ts b/clients/kamino-lending/src/generated/types/scopeConfiguration.ts index 5b245c41..9d19f6db 100644 --- a/clients/kamino-lending/src/generated/types/scopeConfiguration.ts +++ b/clients/kamino-lending/src/generated/types/scopeConfiguration.ts @@ -25,8 +25,11 @@ import { } from "@solana/kit"; export interface ScopeConfiguration { + /** Pubkey of the scope price feed (disabled if `null` or `default`) */ priceFeed: Address; + /** This is the scope_id price chain that results in a price for the token */ priceChain: number[]; + /** This is the scope_id price chain for the twap */ twapChain: number[]; } diff --git a/clients/kamino-lending/src/generated/types/switchboardConfiguration.ts b/clients/kamino-lending/src/generated/types/switchboardConfiguration.ts index afa70c26..30d466be 100644 --- a/clients/kamino-lending/src/generated/types/switchboardConfiguration.ts +++ b/clients/kamino-lending/src/generated/types/switchboardConfiguration.ts @@ -21,6 +21,7 @@ import { } from "@solana/kit"; export interface SwitchboardConfiguration { + /** Pubkey of the base price feed (disabled if `null` or `default`) */ priceAggregator: Address; twapAggregator: Address; } diff --git a/clients/kamino-lending/src/generated/types/tokenInfo.ts b/clients/kamino-lending/src/generated/types/tokenInfo.ts index c8de4f5a..f1e6a759 100644 --- a/clients/kamino-lending/src/generated/types/tokenInfo.ts +++ b/clients/kamino-lending/src/generated/types/tokenInfo.ts @@ -44,13 +44,19 @@ import { } from "./index.js"; export interface TokenInfo { + /** UTF-8 encoded name of the token (null-terminated) */ name: number[]; + /** Heuristics limits of acceptable price */ heuristic: PriceHeuristic; + /** Max divergence between twap and price in bps */ maxTwapDivergenceBps: bigint; maxAgePriceSeconds: bigint; maxAgeTwapSeconds: bigint; + /** Scope price configuration */ scopeConfiguration: ScopeConfiguration; + /** Switchboard configuration */ switchboardConfiguration: SwitchboardConfiguration; + /** Pyth configuration */ pythConfiguration: PythConfiguration; blockPriceUsage: number; reserved: number[]; @@ -58,13 +64,19 @@ export interface TokenInfo { } export interface TokenInfoArgs { + /** UTF-8 encoded name of the token (null-terminated) */ name: number[]; + /** Heuristics limits of acceptable price */ heuristic: PriceHeuristicArgs; + /** Max divergence between twap and price in bps */ maxTwapDivergenceBps: number | bigint; maxAgePriceSeconds: number | bigint; maxAgeTwapSeconds: number | bigint; + /** Scope price configuration */ scopeConfiguration: ScopeConfigurationArgs; + /** Switchboard configuration */ switchboardConfiguration: SwitchboardConfigurationArgs; + /** Pyth configuration */ pythConfiguration: PythConfigurationArgs; blockPriceUsage: number; reserved: number[]; diff --git a/clients/kamino-lending/src/generated/types/updateConfigMode.ts b/clients/kamino-lending/src/generated/types/updateConfigMode.ts index 46b6393b..277450fd 100644 --- a/clients/kamino-lending/src/generated/types/updateConfigMode.ts +++ b/clients/kamino-lending/src/generated/types/updateConfigMode.ts @@ -21,7 +21,7 @@ export enum UpdateConfigMode { UpdateProtocolTakeRate = 4, UpdateFeesBorrowFee = 5, UpdateFeesFlashLoanFee = 6, - UpdateFeesReferralFeeBps = 7, + DeprecatedUpdateFeesReferralFeeBps = 7, UpdateDepositLimit = 8, UpdateBorrowLimit = 9, UpdateTokenInfoLowerHeuristic = 10, @@ -41,8 +41,8 @@ export enum UpdateConfigMode { UpdateEntireReserveConfig = 24, UpdateDebtWithdrawalCap = 25, UpdateDepositWithdrawalCap = 26, - UpdateDebtWithdrawalCapCurrentTotal = 27, - UpdateDepositWithdrawalCapCurrentTotal = 28, + DeprecatedUpdateDebtWithdrawalCapCurrentTotal = 27, + DeprecatedUpdateDepositWithdrawalCapCurrentTotal = 28, UpdateBadDebtLiquidationBonusBps = 29, UpdateMinLiquidationBonusBps = 30, UpdateDeleveragingMarginCallPeriod = 31, @@ -63,6 +63,7 @@ export enum UpdateConfigMode { UpdateHostFixedInterestRateBps = 46, UpdateAutodeleverageEnabled = 47, UpdateDeleveragingBonusIncreaseBpsPerDay = 48, + UpdateProtocolOrderExecutionFee = 49, } export type UpdateConfigModeArgs = UpdateConfigMode; diff --git a/clients/kamino-lending/src/generated/types/updateGlobalConfigMode.ts b/clients/kamino-lending/src/generated/types/updateGlobalConfigMode.ts new file mode 100644 index 00000000..771e284a --- /dev/null +++ b/clients/kamino-lending/src/generated/types/updateGlobalConfigMode.ts @@ -0,0 +1,39 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, +} from "@solana/kit"; +import { combineCodec, getEnumDecoder, getEnumEncoder } from "@solana/kit"; + +export enum UpdateGlobalConfigMode { + PendingAdmin = 0, + FeeCollector = 1, +} + +export type UpdateGlobalConfigModeArgs = UpdateGlobalConfigMode; + +export function getUpdateGlobalConfigModeEncoder(): FixedSizeEncoder { + return getEnumEncoder(UpdateGlobalConfigMode); +} + +export function getUpdateGlobalConfigModeDecoder(): FixedSizeDecoder { + return getEnumDecoder(UpdateGlobalConfigMode); +} + +export function getUpdateGlobalConfigModeCodec(): FixedSizeCodec< + UpdateGlobalConfigModeArgs, + UpdateGlobalConfigMode +> { + return combineCodec( + getUpdateGlobalConfigModeEncoder(), + getUpdateGlobalConfigModeDecoder(), + ); +} diff --git a/clients/kamino-lending/src/generated/types/updateLendingMarketMode.ts b/clients/kamino-lending/src/generated/types/updateLendingMarketMode.ts index 5726db2b..a061db0c 100644 --- a/clients/kamino-lending/src/generated/types/updateLendingMarketMode.ts +++ b/clients/kamino-lending/src/generated/types/updateLendingMarketMode.ts @@ -36,6 +36,9 @@ export enum UpdateLendingMarketMode { UpdateName = 19, UpdateIndividualAutodeleverageMarginCallPeriodSecs = 20, UpdateInitialDepositAmount = 21, + UpdateObligationOrderExecutionEnabled = 22, + UpdateImmutableFlag = 23, + UpdateObligationOrderCreationEnabled = 24, } export type UpdateLendingMarketModeArgs = UpdateLendingMarketMode; diff --git a/clients/kamino-lending/src/generated/types/withdrawalCaps.ts b/clients/kamino-lending/src/generated/types/withdrawalCaps.ts index 6bc5484d..6887ca88 100644 --- a/clients/kamino-lending/src/generated/types/withdrawalCaps.ts +++ b/clients/kamino-lending/src/generated/types/withdrawalCaps.ts @@ -21,6 +21,7 @@ import { getU64Encoder, } from "@solana/kit"; +/** Reserve Withdrawal Caps State */ export interface WithdrawalCaps { configCapacity: bigint; currentTotal: bigint; diff --git a/packages/coda-visitors/src/nodes/associated-token-account-value-node.ts b/packages/coda-visitors/src/nodes/associated-token-account-value-node.ts index b341fe35..f29166bd 100644 --- a/packages/coda-visitors/src/nodes/associated-token-account-value-node.ts +++ b/packages/coda-visitors/src/nodes/associated-token-account-value-node.ts @@ -1,16 +1,18 @@ import type { AccountValueNode, PublicKeyValueNode } from "codama"; +import { ASSOCIATED_TOKEN_PROGRAM_ADDRESS } from "@solana-program/token"; import { pdaNode, pdaSeedValueNode, pdaValueNode, publicKeyTypeNode, - publicKeyValueNode, variablePdaSeedNode, } from "codama"; +import { TOKEN_PROGRAM_VALUE_NODE } from "./program-value-nodes.js"; export const associatedTokenAccountPdaNode = pdaNode({ name: "associatedTokenAccount", - programId: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL", + docs: "Associated Token Account", + programId: ASSOCIATED_TOKEN_PROGRAM_ADDRESS, seeds: [ variablePdaSeedNode("owner", publicKeyTypeNode()), variablePdaSeedNode("tokenProgram", publicKeyTypeNode()), @@ -21,9 +23,7 @@ export const associatedTokenAccountPdaNode = pdaNode({ export const associatedTokenAccountValueNode = ({ owner, mint, - tokenProgram = publicKeyValueNode( - "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", - ), + tokenProgram = TOKEN_PROGRAM_VALUE_NODE, }: { owner: AccountValueNode; mint: AccountValueNode;