@kamino-finance/klend-sdk 2.13.10 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README_KAMINO_MANAGER.md +69 -0
- package/dist/classes/index.d.ts +2 -0
- package/dist/classes/index.js +2 -0
- package/dist/classes/index.js.map +1 -1
- package/dist/classes/manager.d.ts +145 -0
- package/dist/classes/manager.js +313 -0
- package/dist/classes/manager.js.map +1 -0
- package/dist/classes/reserve.d.ts +13 -2
- package/dist/classes/reserve.js +753 -0
- package/dist/classes/reserve.js.map +1 -1
- package/dist/classes/vault.d.ts +150 -0
- package/dist/classes/vault.js +615 -0
- package/dist/classes/vault.js.map +1 -0
- package/dist/client_kamino_manager.d.ts +11 -0
- package/dist/client_kamino_manager.js +465 -0
- package/dist/client_kamino_manager.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/accounts/Reserve.d.ts +89 -0
- package/dist/idl_codegen_kamino_vault/accounts/Reserve.js +164 -0
- package/dist/idl_codegen_kamino_vault/accounts/Reserve.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts +68 -0
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js +179 -0
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/accounts/index.d.ts +4 -0
- package/dist/idl_codegen_kamino_vault/accounts/index.js +8 -0
- package/dist/idl_codegen_kamino_vault/accounts/index.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/errors/anchor.d.ts +434 -0
- package/dist/idl_codegen_kamino_vault/errors/anchor.js +713 -0
- package/dist/idl_codegen_kamino_vault/errors/anchor.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/errors/custom.d.ts +194 -0
- package/dist/idl_codegen_kamino_vault/errors/custom.js +322 -0
- package/dist/idl_codegen_kamino_vault/errors/custom.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/errors/index.d.ts +5 -0
- package/dist/idl_codegen_kamino_vault/errors/index.js +65 -0
- package/dist/idl_codegen_kamino_vault/errors/index.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/deposit.d.ts +19 -0
- package/dist/idl_codegen_kamino_vault/instructions/deposit.js +58 -0
- package/dist/idl_codegen_kamino_vault/instructions/deposit.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/index.d.ts +10 -0
- package/dist/idl_codegen_kamino_vault/instructions/index.js +14 -0
- package/dist/idl_codegen_kamino_vault/instructions/index.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/initVault.d.ts +13 -0
- package/dist/idl_codegen_kamino_vault/instructions/initVault.js +23 -0
- package/dist/idl_codegen_kamino_vault/instructions/initVault.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/invest.d.ts +18 -0
- package/dist/idl_codegen_kamino_vault/instructions/invest.js +43 -0
- package/dist/idl_codegen_kamino_vault/instructions/invest.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.d.ts +19 -0
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.js +58 -0
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/withdraw.d.ts +27 -0
- package/dist/idl_codegen_kamino_vault/instructions/withdraw.js +77 -0
- package/dist/idl_codegen_kamino_vault/instructions/withdraw.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/programId.d.ts +3 -0
- package/dist/idl_codegen_kamino_vault/programId.js +9 -0
- package/dist/idl_codegen_kamino_vault/programId.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/BigFractionBytes.d.ts +27 -0
- package/dist/idl_codegen_kamino_vault/types/BigFractionBytes.js +70 -0
- package/dist/idl_codegen_kamino_vault/types/BigFractionBytes.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/BorrowRateCurve.d.ts +27 -0
- package/dist/idl_codegen_kamino_vault/types/BorrowRateCurve.js +62 -0
- package/dist/idl_codegen_kamino_vault/types/BorrowRateCurve.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/CurvePoint.d.ts +26 -0
- package/dist/idl_codegen_kamino_vault/types/CurvePoint.js +66 -0
- package/dist/idl_codegen_kamino_vault/types/CurvePoint.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/LastUpdate.d.ts +47 -0
- package/dist/idl_codegen_kamino_vault/types/LastUpdate.js +81 -0
- package/dist/idl_codegen_kamino_vault/types/LastUpdate.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/PriceHeuristic.d.ts +41 -0
- package/dist/idl_codegen_kamino_vault/types/PriceHeuristic.js +75 -0
- package/dist/idl_codegen_kamino_vault/types/PriceHeuristic.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/PythConfiguration.d.ts +25 -0
- package/dist/idl_codegen_kamino_vault/types/PythConfiguration.js +62 -0
- package/dist/idl_codegen_kamino_vault/types/PythConfiguration.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveCollateral.d.ts +53 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveCollateral.js +93 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveCollateral.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveConfig.d.ts +361 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveConfig.js +231 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveConfig.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveFees.d.ts +78 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveFees.js +82 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveFees.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveLiquidity.d.ts +173 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveLiquidity.js +166 -0
- package/dist/idl_codegen_kamino_vault/types/ReserveLiquidity.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/ScopeConfiguration.d.ts +41 -0
- package/dist/idl_codegen_kamino_vault/types/ScopeConfiguration.js +76 -0
- package/dist/idl_codegen_kamino_vault/types/ScopeConfiguration.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/SwitchboardConfiguration.d.ts +30 -0
- package/dist/idl_codegen_kamino_vault/types/SwitchboardConfiguration.js +67 -0
- package/dist/idl_codegen_kamino_vault/types/SwitchboardConfiguration.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/TokenInfo.d.ts +117 -0
- package/dist/idl_codegen_kamino_vault/types/TokenInfo.js +128 -0
- package/dist/idl_codegen_kamino_vault/types/TokenInfo.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/VaultAllocation.d.ts +56 -0
- package/dist/idl_codegen_kamino_vault/types/VaultAllocation.js +104 -0
- package/dist/idl_codegen_kamino_vault/types/VaultAllocation.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.d.ts +38 -0
- package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.js +86 -0
- package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.js.map +1 -0
- package/dist/idl_codegen_kamino_vault/types/index.d.ts +30 -0
- package/dist/idl_codegen_kamino_vault/types/index.js +34 -0
- package/dist/idl_codegen_kamino_vault/types/index.js.map +1 -0
- package/dist/utils/constants.d.ts +1 -0
- package/dist/utils/constants.js +2 -1
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/instruction.d.ts +1 -0
- package/dist/utils/instruction.js +7 -0
- package/dist/utils/instruction.js.map +1 -1
- package/dist/utils/managerTypes.d.ts +137 -0
- package/dist/utils/managerTypes.js +295 -0
- package/dist/utils/managerTypes.js.map +1 -0
- package/dist/utils/sendTransactionsUtils.d.ts +40 -0
- package/dist/utils/sendTransactionsUtils.js +154 -0
- package/dist/utils/sendTransactionsUtils.js.map +1 -0
- package/package.json +2 -1
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
## Kamino Manager CLI
|
|
2
|
+
|
|
3
|
+
In order to use the CLI, the followign `.env` configuration is required:
|
|
4
|
+
```
|
|
5
|
+
ADMIN="../staging_owner.json"
|
|
6
|
+
RPC="https://rpc.ironforge.network/mainnet?apiKey=01HVK9A9XRZWKKDZMDDD94R5J6"
|
|
7
|
+
KLEND_PROGRAM_ID_MAINNET="KLend2g3cP87fffoy8q1mQqGKjrxjC8boSyAYavgmjD"
|
|
8
|
+
KVAULT_PROGRAM_ID_MAINNET="kvauTFR8qm1dhniz6pYuBZkuene3Hfrs1VQhVRgCNrr"
|
|
9
|
+
KLEND_PROGRAM_ID_STAGING="SLendK7ySfcEzyaFqy93gDnD3RtrpXJcnRwb6zFHJSh"
|
|
10
|
+
KVAULT_PROGRAM_ID_STAGING="STkvh7ostar39Fwr4uZKASs1RNNuYMFMTsE77FiRsL2"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
#### Create a new market
|
|
14
|
+
`npx ts-node src/client_kamino_manager.ts create-market --staging`
|
|
15
|
+
|
|
16
|
+
- bs58 - is a boolean flag. If set it will print the bs58 txn instead of executing. Should be used for multisig
|
|
17
|
+
- staging - is a boolean flag. If set, staging programs will be used
|
|
18
|
+
- multisig - address string to be used as admin PublicKey. To be used in conjunction with bs58 flag
|
|
19
|
+
|
|
20
|
+
#### Add a new asset to market / Create new reserve
|
|
21
|
+
`npx ts-node src/client_kamino_manager.ts add-asset-to-market --market market_address --mint token_mint --mint-program-id TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA --reserve-config-path ./configs/reserve_config_example.json --staging`
|
|
22
|
+
|
|
23
|
+
- market - address to create the reserve for
|
|
24
|
+
- mint - the liquidity mint to create the reserve for
|
|
25
|
+
- mint-program-id - the program id of the mint - `TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA` - spl token program `TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb` - for token 2022 token program
|
|
26
|
+
- bs58 - is a boolean flag. If set it will print the bs58 txn instead of executing. Should be used for multisig
|
|
27
|
+
- staging - is a boolean flag. If set, staging programs will be used
|
|
28
|
+
- multisig - address string to be used as admin PublicKey. To be used in conjunction with bs58 flag
|
|
29
|
+
|
|
30
|
+
#### Update a reserve config
|
|
31
|
+
`npx ts-node src/client_kamino_manager.ts update-reserve-config --reserve reserve_address --reserve-config-path ./configs/reserve_config_example.json --staging --update-entire-config`
|
|
32
|
+
|
|
33
|
+
- reserve - address to update the reserve config for
|
|
34
|
+
- reserve-config-path - the path to the config file to be used
|
|
35
|
+
- update-entire-config - wether to update the entrie reserve config or just the difference between current on-chain state and given config
|
|
36
|
+
- bs58 - is a boolean flag. If set it will print the bs58 txn instead of executing. Should be used for multisig
|
|
37
|
+
- staging - is a boolean flag. If set, staging programs will be used
|
|
38
|
+
|
|
39
|
+
#### Download a reserve config
|
|
40
|
+
|
|
41
|
+
In order to update a reserve config, you need the latest reserve configuration, to modify. To get the latest, this command can be used:
|
|
42
|
+
|
|
43
|
+
`npx ts-node src/client_kamino_manager.ts download-reserve-config --reserve reserve_address --staging`
|
|
44
|
+
|
|
45
|
+
- reserve - address to update the reserve config for
|
|
46
|
+
- staging - is a boolean flag. If set, staging programs will be used
|
|
47
|
+
|
|
48
|
+
#### Create a vault
|
|
49
|
+
`npx ts-node src/client_kamino_manager.ts create-vault --mint token_mint --staging`
|
|
50
|
+
|
|
51
|
+
- mint - the liquidity mint to create the reserve for
|
|
52
|
+
- bs58 - is a boolean flag. If set it will print the bs58 txn instead of executing. Should be used for multisig
|
|
53
|
+
- staging - is a boolean flag. If set, staging programs will be used
|
|
54
|
+
- multisig - address string to be used as admin PublicKey. To be used in conjunction with bs58 flag
|
|
55
|
+
|
|
56
|
+
#### Update vault reserve allocation
|
|
57
|
+
`npx ts-node src/client_kamino_manager.ts update-vault-reserve-allocation --vault vault_address --reserve reserve_address --allocation-weight number --allocation-cap number --staging`
|
|
58
|
+
|
|
59
|
+
- vault - the vault address to add/update the reserve allocation for
|
|
60
|
+
- reserve - the reserve address to add/update the reserve allocation for
|
|
61
|
+
- allocation-weight - the allocation weight for given reserve; only relevant in relation with the other reserve allocation weights
|
|
62
|
+
- allocation-cap - the allocation cap in decimal (not lamports) for given reserve
|
|
63
|
+
- bs58 - is a boolean flag. If set it will print the bs58 txn instead of executing. Should be used for multisig
|
|
64
|
+
- staging - is a boolean flag. If set, staging programs will be used
|
|
65
|
+
- multisig - address string to be used as admin PublicKey. To be used in conjunction with bs58 flag
|
|
66
|
+
|
|
67
|
+
#### Get oracle mappings
|
|
68
|
+
This can be used to get scope oracle mappings to be used when configuring the reserve oracle config.
|
|
69
|
+
`npx ts-node src/client_kamino_manager.ts get-oracle-mappings`
|
package/dist/classes/index.d.ts
CHANGED
package/dist/classes/index.js
CHANGED
|
@@ -22,4 +22,6 @@ __exportStar(require("./reserve"), exports);
|
|
|
22
22
|
__exportStar(require("./shared"), exports);
|
|
23
23
|
__exportStar(require("./utils"), exports);
|
|
24
24
|
__exportStar(require("./jupiterPerps"), exports);
|
|
25
|
+
__exportStar(require("./manager"), exports);
|
|
26
|
+
__exportStar(require("./vault"), exports);
|
|
25
27
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/classes/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,0CAAwB;AACxB,2CAAyB;AACzB,+CAA6B;AAC7B,4CAA0B;AAC1B,2CAAyB;AACzB,0CAAwB;AACxB,iDAA+B","sourcesContent":["export * from './action';\nexport * from './curve';\nexport * from './market';\nexport * from './obligation';\nexport * from './reserve';\nexport * from './shared';\nexport * from './utils';\nexport * from './jupiterPerps';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/classes/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,0CAAwB;AACxB,2CAAyB;AACzB,+CAA6B;AAC7B,4CAA0B;AAC1B,2CAAyB;AACzB,0CAAwB;AACxB,iDAA+B;AAC/B,4CAA0B;AAC1B,0CAAwB","sourcesContent":["export * from './action';\nexport * from './curve';\nexport * from './market';\nexport * from './obligation';\nexport * from './reserve';\nexport * from './shared';\nexport * from './utils';\nexport * from './jupiterPerps';\nexport * from './manager';\nexport * from './vault';\n"]}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { Connection, Keypair, PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
2
|
+
import { KaminoVault, KaminoVaultClient, KaminoVaultConfig, ReserveAllocationConfig } from './vault';
|
|
3
|
+
import { AddAssetToMarketParams, CreateKaminoMarketParams, ENV, MarketWithAddress, PubkeyHashMap, Reserve, ReserveWithAddress, ScopeOracleConfig } from '../lib';
|
|
4
|
+
import { ReserveConfig } from '../idl_codegen/types';
|
|
5
|
+
import Decimal from 'decimal.js';
|
|
6
|
+
/**
|
|
7
|
+
* KaminoManager is a class that provides a high-level interface to interact with the Kamino Lend and Kamino Vault programs, in order to create and manage a market, as well as vaults
|
|
8
|
+
*/
|
|
9
|
+
export declare class KaminoManager {
|
|
10
|
+
private readonly _connection;
|
|
11
|
+
private readonly _kaminoVaultProgramId;
|
|
12
|
+
private readonly _kaminoLendProgramId;
|
|
13
|
+
private readonly _vaultClient;
|
|
14
|
+
recentSlotDurationMs: number;
|
|
15
|
+
constructor(connection: Connection, kaminoLendProgramId?: PublicKey, kaminoVaultProgramId?: PublicKey, recentSlotDurationMs?: number);
|
|
16
|
+
getConnection(): Connection;
|
|
17
|
+
getProgramID(): PublicKey;
|
|
18
|
+
/**
|
|
19
|
+
* This is a function that helps quickly setting up a reserve for an asset with a default config. The config can be modified later on.
|
|
20
|
+
* @param params.admin - the admin of the market
|
|
21
|
+
* @returns market keypair - keypair used for market account creation -> to be signed with when executing the transaction
|
|
22
|
+
* @returns ixns - an array of ixns for creating and initializing the market account
|
|
23
|
+
*/
|
|
24
|
+
createMarketIxs(params: CreateKaminoMarketParams): Promise<{
|
|
25
|
+
market: Keypair;
|
|
26
|
+
ixns: TransactionInstruction[];
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* This is a function that helps quickly setting up a reserve for an asset with a default config. The config can be modified later on.
|
|
30
|
+
* @param params.admin - the admin of the reserve
|
|
31
|
+
* @param params.marketAddress - the market to create a reserve for, only the market admin can create a reserve for the market
|
|
32
|
+
* @param params.assetConfig - an object that helps generate a default reserve config with some inputs which have to be configured before calling this function
|
|
33
|
+
* @returns reserve - keypair used for reserve creation -> to be signed with when executing the transaction
|
|
34
|
+
* @returns txnIxns - an array of arrays of ixns -> first array for reserve creation, second for updating it with correct params
|
|
35
|
+
*/
|
|
36
|
+
addAssetToMarketIxs(params: AddAssetToMarketParams): Promise<{
|
|
37
|
+
reserve: Keypair;
|
|
38
|
+
txnIxns: TransactionInstruction[][];
|
|
39
|
+
}>;
|
|
40
|
+
/**
|
|
41
|
+
* This method will create a vault with a given config. The config can be changed later on, but it is recommended to set it up correctly from the start
|
|
42
|
+
* @param vaultConfig - the config object used to create a vault
|
|
43
|
+
* @returns vault - keypair, should be used to sign the transaction which creates the vault account
|
|
44
|
+
* @returns ixns - an array of instructions to create the vault
|
|
45
|
+
*/
|
|
46
|
+
createVaultIxs(vaultConfig: KaminoVaultConfig): Promise<{
|
|
47
|
+
vault: Keypair;
|
|
48
|
+
ixns: TransactionInstruction[];
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* This method updates the vault reserve allocation cofnig for an exiting vault reserve, or adds a new reserve to the vault if it does not exist.
|
|
52
|
+
* @param vault - vault to be updated
|
|
53
|
+
* @param reserveAllocationConfig - new reserve allocation config
|
|
54
|
+
* @returns - a list of instructions
|
|
55
|
+
*/
|
|
56
|
+
updateVaultReserveAllocationIxs(vault: KaminoVault, reserveAllocationConfig: ReserveAllocationConfig): Promise<TransactionInstruction>;
|
|
57
|
+
/**
|
|
58
|
+
* This method retruns the reserve config for a given reserve
|
|
59
|
+
* @param reserve - reserve to get the config for
|
|
60
|
+
* @returns - the reserve config
|
|
61
|
+
*/
|
|
62
|
+
getReserveConfig(reserve: PublicKey): Promise<ReserveConfig>;
|
|
63
|
+
/**
|
|
64
|
+
* This function enables the update of the scope oracle configuration. In order to get a list of scope prices, getScopeOracleConfigs can be used
|
|
65
|
+
* @param market - lending market which owns the reserve
|
|
66
|
+
* @param reserve - reserve which to be updated
|
|
67
|
+
* @param scopeOracleConfig - new scope oracle config
|
|
68
|
+
* @param scopeTwapConfig - new scope twap config
|
|
69
|
+
* @param maxAgeBufferSeconds - buffer to be added to onchain max_age - if oracle price is older than that, txns interacting with the reserve will fail
|
|
70
|
+
* @returns - an array of instructions used update the oracle configuration
|
|
71
|
+
*/
|
|
72
|
+
updateReserveScopeOracleConfigurationIxs(market: MarketWithAddress, reserve: ReserveWithAddress, scopeOracleConfig: ScopeOracleConfig, scopeTwapConfig?: ScopeOracleConfig, maxAgeBufferSeconds?: number): Promise<TransactionInstruction[]>;
|
|
73
|
+
/**
|
|
74
|
+
* This function updates the given reserve with a new config. It can either update the entire reserve config or just update fields which differ between given reserve and existing reserve
|
|
75
|
+
* @param marketWithAddress - the market that owns the reserve to be updated
|
|
76
|
+
* @param reserve - the reserve to be updated
|
|
77
|
+
* @param config - the new reserve configuration to be used for the update
|
|
78
|
+
* @param reserveStateOverride - the reserve state, useful to provide, if already fetched outside this method, in order to avoid an extra rpc call to fetch it. Make sure the reserveConfig has not been updated since fetching the reserveState that you pass in.
|
|
79
|
+
* @param updateEntireConfig - when set to false, it will only update fields that are different between @param config and reserveState.config, set to true it will always update entire reserve config. An entire reserveConfig update might be too large for a multisig transaction
|
|
80
|
+
* @returns - an array of multiple update ixns. If there are many fields that are being updated without the updateEntireConfig=true, multiple transactions might be required to fit all ixns.
|
|
81
|
+
*/
|
|
82
|
+
updateReserveIxs(marketWithAddress: MarketWithAddress, reserve: PublicKey, config: ReserveConfig, reserveStateOverride?: Reserve, updateEntireConfig?: boolean): Promise<TransactionInstruction[]>;
|
|
83
|
+
/**
|
|
84
|
+
* This function creates instructions to deposit into a vault. It will also create ATA creation instructions for the vault shares that the user receives in return
|
|
85
|
+
* @param user - user to deposit
|
|
86
|
+
* @param vault - vault to deposit into
|
|
87
|
+
* @param tokenAmount - token amount to be deposited, in decimals (will be converted in lamports)
|
|
88
|
+
* @returns - an array of instructions to be used to be executed
|
|
89
|
+
*/
|
|
90
|
+
depositToVaultIxs(user: PublicKey, vault: KaminoVault, tokenAmount: Decimal): Promise<TransactionInstruction[]>;
|
|
91
|
+
/**
|
|
92
|
+
* This function will return the missing ATA creation instructions, as well as one or multiple withdraw instructions, based on how many reserves it's needed to withdraw from. This might have to be split in multiple transactions
|
|
93
|
+
* @param user - user to withdraw
|
|
94
|
+
* @param vault - vault to withdraw from
|
|
95
|
+
* @param shareAmount - share amount to withdraw, in order to withdraw everything, any value > user share amount
|
|
96
|
+
* @param slot - current slot, used to estimate the interest earned in the different reserves with allocation from the vault
|
|
97
|
+
* @returns an array of instructions to be executed
|
|
98
|
+
*/
|
|
99
|
+
withdrawFromVaultIxs(user: PublicKey, vault: KaminoVault, shareAmount: Decimal, slot: number): Promise<TransactionInstruction[]>;
|
|
100
|
+
/**
|
|
101
|
+
* This method calculates the token per share value. This will always change based on interest earned from the vault, but calculating it requires a bunch of rpc requests. Caching this for a short duration would be optimal
|
|
102
|
+
* @param vault - vault to calculate tokensPerShare for
|
|
103
|
+
* @param slot - current slot, used to estimate the interest earned in the different reserves with allocation from the vault
|
|
104
|
+
* @returns - token per share value
|
|
105
|
+
*/
|
|
106
|
+
getTokensPerShareSingleVault(vault: KaminoVault, slot: number): Promise<Decimal>;
|
|
107
|
+
/**
|
|
108
|
+
* This method returns the user shares balance for a given vault
|
|
109
|
+
* @param user - user to calculate the shares balance for
|
|
110
|
+
* @param vault - vault to calculate shares balance for
|
|
111
|
+
* @returns - user share balance in decimal (not lamports)
|
|
112
|
+
*/
|
|
113
|
+
getUserSharesBalanceSingleVault(user: PublicKey, vault: KaminoVault): Promise<Decimal>;
|
|
114
|
+
/**
|
|
115
|
+
* This method returns the user shares balance for all existing vaults
|
|
116
|
+
* @param user - user to calculate the shares balance for
|
|
117
|
+
* @param vaultsOverride - the kamino vaults if already fetched, in order to reduce rpc calls
|
|
118
|
+
* @returns - hash map with keyh as vault address and value as user share balance in decimal (not lamports)
|
|
119
|
+
*/
|
|
120
|
+
getUserSharesBalanceAllVaults(user: PublicKey, vaultsOverride: KaminoVault[]): Promise<PubkeyHashMap<PublicKey, Decimal>>;
|
|
121
|
+
/**
|
|
122
|
+
* @returns - the KaminoVault client
|
|
123
|
+
*/
|
|
124
|
+
getKaminoVaultClient(): KaminoVaultClient;
|
|
125
|
+
/**
|
|
126
|
+
* This will trigger invest by balancing, based on weights, the reserve allocations of the vault. It can either withdraw or deposit into reserves to balance them. This is a function that should be cranked
|
|
127
|
+
* @param kaminoVault - vault to invest from
|
|
128
|
+
* @returns - an array of invest instructions for each invest action required for the vault reserves
|
|
129
|
+
*/
|
|
130
|
+
investAllReserves(kaminoVault: KaminoVault): Promise<TransactionInstruction[]>;
|
|
131
|
+
/**
|
|
132
|
+
* This will trigger invest by balancing, based on weights, the reserve allocation of the vault. It can either withdraw or deposit into the given reserve to balance it
|
|
133
|
+
* @param kaminoVault - vault to invest from
|
|
134
|
+
* @param reserve - reserve to invest into or disinvest from
|
|
135
|
+
* @returns - an array of invest instructions for each invest action required for the vault reserves
|
|
136
|
+
*/
|
|
137
|
+
investSingleReserve(kaminoVault: KaminoVault, reserveWithAddress: ReserveWithAddress): Promise<TransactionInstruction>;
|
|
138
|
+
/**
|
|
139
|
+
* This retruns an array of scope oracle configs to be used to set the scope price and twap oracles for a reserve
|
|
140
|
+
* @param feed - scope feed to fetch prices from
|
|
141
|
+
* @param cluster - cluster to fetch from, this should be left unchanged unless working on devnet or locally
|
|
142
|
+
* @returns - an array of scope oracle configs
|
|
143
|
+
*/
|
|
144
|
+
getScopeOracleConfigs(feed?: string, cluster?: ENV): Promise<Array<ScopeOracleConfig>>;
|
|
145
|
+
}
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.KaminoManager = void 0;
|
|
16
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
17
|
+
const vault_1 = require("./vault");
|
|
18
|
+
const lib_1 = require("../lib");
|
|
19
|
+
const programId_1 = require("../idl_codegen/programId");
|
|
20
|
+
const scope_sdk_1 = require("@hubbleprotocol/scope-sdk");
|
|
21
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
22
|
+
const types_1 = require("../idl_codegen/types");
|
|
23
|
+
/**
|
|
24
|
+
* KaminoManager is a class that provides a high-level interface to interact with the Kamino Lend and Kamino Vault programs, in order to create and manage a market, as well as vaults
|
|
25
|
+
*/
|
|
26
|
+
class KaminoManager {
|
|
27
|
+
constructor(connection, kaminoLendProgramId, kaminoVaultProgramId, recentSlotDurationMs) {
|
|
28
|
+
this._connection = connection;
|
|
29
|
+
this._kaminoVaultProgramId = kaminoVaultProgramId ? kaminoVaultProgramId : vault_1.kaminoVaultId;
|
|
30
|
+
this._kaminoLendProgramId = kaminoLendProgramId ? kaminoLendProgramId : programId_1.PROGRAM_ID;
|
|
31
|
+
this.recentSlotDurationMs = recentSlotDurationMs ? recentSlotDurationMs : lib_1.DEFAULT_RECENT_SLOT_DURATION_MS;
|
|
32
|
+
this._vaultClient = new vault_1.KaminoVaultClient(connection, this._kaminoVaultProgramId, this._kaminoLendProgramId, this.recentSlotDurationMs);
|
|
33
|
+
}
|
|
34
|
+
getConnection() {
|
|
35
|
+
return this._connection;
|
|
36
|
+
}
|
|
37
|
+
getProgramID() {
|
|
38
|
+
return this._kaminoVaultProgramId;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* This is a function that helps quickly setting up a reserve for an asset with a default config. The config can be modified later on.
|
|
42
|
+
* @param params.admin - the admin of the market
|
|
43
|
+
* @returns market keypair - keypair used for market account creation -> to be signed with when executing the transaction
|
|
44
|
+
* @returns ixns - an array of ixns for creating and initializing the market account
|
|
45
|
+
*/
|
|
46
|
+
createMarketIxs(params) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const marketAccount = web3_js_1.Keypair.generate();
|
|
49
|
+
const size = lib_1.LendingMarket.layout.span + 8;
|
|
50
|
+
const [lendingMarketAuthority, _] = (0, lib_1.lendingMarketAuthPda)(marketAccount.publicKey, this._kaminoLendProgramId);
|
|
51
|
+
const createMarketIxns = [];
|
|
52
|
+
createMarketIxns.push(web3_js_1.SystemProgram.createAccount({
|
|
53
|
+
fromPubkey: params.admin,
|
|
54
|
+
newAccountPubkey: marketAccount.publicKey,
|
|
55
|
+
lamports: yield this._connection.getMinimumBalanceForRentExemption(size),
|
|
56
|
+
space: size,
|
|
57
|
+
programId: this._kaminoLendProgramId,
|
|
58
|
+
}));
|
|
59
|
+
const accounts = {
|
|
60
|
+
lendingMarketOwner: params.admin,
|
|
61
|
+
lendingMarket: marketAccount.publicKey,
|
|
62
|
+
lendingMarketAuthority: lendingMarketAuthority,
|
|
63
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
64
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
65
|
+
};
|
|
66
|
+
const args = {
|
|
67
|
+
quoteCurrency: Array(32).fill(0),
|
|
68
|
+
};
|
|
69
|
+
createMarketIxns.push((0, lib_1.initLendingMarket)(args, accounts, this._kaminoLendProgramId));
|
|
70
|
+
return { market: marketAccount, ixns: createMarketIxns };
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* This is a function that helps quickly setting up a reserve for an asset with a default config. The config can be modified later on.
|
|
75
|
+
* @param params.admin - the admin of the reserve
|
|
76
|
+
* @param params.marketAddress - the market to create a reserve for, only the market admin can create a reserve for the market
|
|
77
|
+
* @param params.assetConfig - an object that helps generate a default reserve config with some inputs which have to be configured before calling this function
|
|
78
|
+
* @returns reserve - keypair used for reserve creation -> to be signed with when executing the transaction
|
|
79
|
+
* @returns txnIxns - an array of arrays of ixns -> first array for reserve creation, second for updating it with correct params
|
|
80
|
+
*/
|
|
81
|
+
addAssetToMarketIxs(params) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
const market = yield lib_1.LendingMarket.fetch(this._connection, params.marketAddress, this._kaminoLendProgramId);
|
|
84
|
+
if (!market) {
|
|
85
|
+
throw new Error('Market not found');
|
|
86
|
+
}
|
|
87
|
+
const marketWithAddress = { address: params.marketAddress, state: market };
|
|
88
|
+
const reserveAccount = web3_js_1.Keypair.generate();
|
|
89
|
+
const createReserveInstructions = yield (0, lib_1.createReserveIxs)(this._connection, params.admin, params.marketAddress, params.assetConfig.mint, reserveAccount.publicKey, this._kaminoLendProgramId);
|
|
90
|
+
const updateReserveInstructions = yield this.updateReserveIxs(marketWithAddress, reserveAccount.publicKey, params.assetConfig.getReserveConfig(), undefined, true);
|
|
91
|
+
const txnIxns = [];
|
|
92
|
+
txnIxns.push(createReserveInstructions);
|
|
93
|
+
txnIxns.push(updateReserveInstructions);
|
|
94
|
+
return { reserve: reserveAccount, txnIxns };
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* This method will create a vault with a given config. The config can be changed later on, but it is recommended to set it up correctly from the start
|
|
99
|
+
* @param vaultConfig - the config object used to create a vault
|
|
100
|
+
* @returns vault - keypair, should be used to sign the transaction which creates the vault account
|
|
101
|
+
* @returns ixns - an array of instructions to create the vault
|
|
102
|
+
*/
|
|
103
|
+
createVaultIxs(vaultConfig) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
return this._vaultClient.createVaultIxs(vaultConfig);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* This method updates the vault reserve allocation cofnig for an exiting vault reserve, or adds a new reserve to the vault if it does not exist.
|
|
110
|
+
* @param vault - vault to be updated
|
|
111
|
+
* @param reserveAllocationConfig - new reserve allocation config
|
|
112
|
+
* @returns - a list of instructions
|
|
113
|
+
*/
|
|
114
|
+
updateVaultReserveAllocationIxs(vault, reserveAllocationConfig) {
|
|
115
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
+
return this._vaultClient.updateReserveAllocationIxs(vault, reserveAllocationConfig);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* This method retruns the reserve config for a given reserve
|
|
121
|
+
* @param reserve - reserve to get the config for
|
|
122
|
+
* @returns - the reserve config
|
|
123
|
+
*/
|
|
124
|
+
getReserveConfig(reserve) {
|
|
125
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
126
|
+
const reserveState = yield lib_1.Reserve.fetch(this._connection, reserve);
|
|
127
|
+
if (!reserveState) {
|
|
128
|
+
throw new Error('Reserve not found');
|
|
129
|
+
}
|
|
130
|
+
return reserveState.config;
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* This function enables the update of the scope oracle configuration. In order to get a list of scope prices, getScopeOracleConfigs can be used
|
|
135
|
+
* @param market - lending market which owns the reserve
|
|
136
|
+
* @param reserve - reserve which to be updated
|
|
137
|
+
* @param scopeOracleConfig - new scope oracle config
|
|
138
|
+
* @param scopeTwapConfig - new scope twap config
|
|
139
|
+
* @param maxAgeBufferSeconds - buffer to be added to onchain max_age - if oracle price is older than that, txns interacting with the reserve will fail
|
|
140
|
+
* @returns - an array of instructions used update the oracle configuration
|
|
141
|
+
*/
|
|
142
|
+
updateReserveScopeOracleConfigurationIxs(market_1, reserve_1, scopeOracleConfig_1, scopeTwapConfig_1) {
|
|
143
|
+
return __awaiter(this, arguments, void 0, function* (market, reserve, scopeOracleConfig, scopeTwapConfig, maxAgeBufferSeconds = 20) {
|
|
144
|
+
const reserveConfig = reserve.state.config;
|
|
145
|
+
let scopeTwapId = scope_sdk_1.U16_MAX;
|
|
146
|
+
if (scopeTwapConfig) {
|
|
147
|
+
scopeTwapId = scopeTwapConfig.oracleId;
|
|
148
|
+
// if(scopeTwapConfig.twapSourceId !== scopeOracleConfig.oracleId) {
|
|
149
|
+
// throw new Error('Twap source id must match oracle id');
|
|
150
|
+
// }
|
|
151
|
+
}
|
|
152
|
+
const { scopeConfiguration } = (0, lib_1.getReserveOracleConfigs)({
|
|
153
|
+
scopePriceConfigAddress: scopeOracleConfig.scopePriceConfigAddress,
|
|
154
|
+
scopeChain: [scopeOracleConfig.oracleId],
|
|
155
|
+
scopeTwapChain: [scopeTwapId],
|
|
156
|
+
});
|
|
157
|
+
const newReserveConfig = new types_1.ReserveConfig(Object.assign(Object.assign({}, reserveConfig), { tokenInfo: Object.assign(Object.assign({}, reserveConfig.tokenInfo), { scopeConfiguration: scopeConfiguration,
|
|
158
|
+
// TODO: Decide if we want to keep this maxAge override for twap & price
|
|
159
|
+
maxAgeTwapSeconds: scopeTwapConfig
|
|
160
|
+
? new bn_js_1.default(scopeTwapConfig.max_age + maxAgeBufferSeconds)
|
|
161
|
+
: reserveConfig.tokenInfo.maxAgeTwapSeconds, maxAgePriceSeconds: new bn_js_1.default(scopeOracleConfig.max_age + maxAgeBufferSeconds) }) }));
|
|
162
|
+
return this.updateReserveIxs(market, reserve.address, newReserveConfig, reserve.state);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* This function updates the given reserve with a new config. It can either update the entire reserve config or just update fields which differ between given reserve and existing reserve
|
|
167
|
+
* @param marketWithAddress - the market that owns the reserve to be updated
|
|
168
|
+
* @param reserve - the reserve to be updated
|
|
169
|
+
* @param config - the new reserve configuration to be used for the update
|
|
170
|
+
* @param reserveStateOverride - the reserve state, useful to provide, if already fetched outside this method, in order to avoid an extra rpc call to fetch it. Make sure the reserveConfig has not been updated since fetching the reserveState that you pass in.
|
|
171
|
+
* @param updateEntireConfig - when set to false, it will only update fields that are different between @param config and reserveState.config, set to true it will always update entire reserve config. An entire reserveConfig update might be too large for a multisig transaction
|
|
172
|
+
* @returns - an array of multiple update ixns. If there are many fields that are being updated without the updateEntireConfig=true, multiple transactions might be required to fit all ixns.
|
|
173
|
+
*/
|
|
174
|
+
updateReserveIxs(marketWithAddress_1, reserve_1, config_1, reserveStateOverride_1) {
|
|
175
|
+
return __awaiter(this, arguments, void 0, function* (marketWithAddress, reserve, config, reserveStateOverride, updateEntireConfig = false) {
|
|
176
|
+
const reserveState = reserveStateOverride
|
|
177
|
+
? reserveStateOverride
|
|
178
|
+
: (yield lib_1.Reserve.fetch(this._connection, reserve, this._kaminoLendProgramId));
|
|
179
|
+
const ixns = [];
|
|
180
|
+
if (!reserveState || updateEntireConfig) {
|
|
181
|
+
ixns.push((0, lib_1.updateEntireReserveConfigIx)(marketWithAddress, reserve, config, this._kaminoLendProgramId));
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
ixns.push(...(0, lib_1.parseForChangesReserveConfigAndGetIxs)(marketWithAddress, reserveState, reserve, config, this._kaminoLendProgramId));
|
|
185
|
+
}
|
|
186
|
+
return ixns;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* This function creates instructions to deposit into a vault. It will also create ATA creation instructions for the vault shares that the user receives in return
|
|
191
|
+
* @param user - user to deposit
|
|
192
|
+
* @param vault - vault to deposit into
|
|
193
|
+
* @param tokenAmount - token amount to be deposited, in decimals (will be converted in lamports)
|
|
194
|
+
* @returns - an array of instructions to be used to be executed
|
|
195
|
+
*/
|
|
196
|
+
depositToVaultIxs(user, vault, tokenAmount) {
|
|
197
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
198
|
+
return this._vaultClient.depositIxs(user, vault, tokenAmount);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* This function will return the missing ATA creation instructions, as well as one or multiple withdraw instructions, based on how many reserves it's needed to withdraw from. This might have to be split in multiple transactions
|
|
203
|
+
* @param user - user to withdraw
|
|
204
|
+
* @param vault - vault to withdraw from
|
|
205
|
+
* @param shareAmount - share amount to withdraw, in order to withdraw everything, any value > user share amount
|
|
206
|
+
* @param slot - current slot, used to estimate the interest earned in the different reserves with allocation from the vault
|
|
207
|
+
* @returns an array of instructions to be executed
|
|
208
|
+
*/
|
|
209
|
+
withdrawFromVaultIxs(user, vault, shareAmount, slot) {
|
|
210
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
211
|
+
return this._vaultClient.withdrawIxs(user, vault, shareAmount, slot);
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* This method calculates the token per share value. This will always change based on interest earned from the vault, but calculating it requires a bunch of rpc requests. Caching this for a short duration would be optimal
|
|
216
|
+
* @param vault - vault to calculate tokensPerShare for
|
|
217
|
+
* @param slot - current slot, used to estimate the interest earned in the different reserves with allocation from the vault
|
|
218
|
+
* @returns - token per share value
|
|
219
|
+
*/
|
|
220
|
+
getTokensPerShareSingleVault(vault, slot) {
|
|
221
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
222
|
+
return this._vaultClient.getTokensPerShareSingleVault(vault, slot);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* This method returns the user shares balance for a given vault
|
|
227
|
+
* @param user - user to calculate the shares balance for
|
|
228
|
+
* @param vault - vault to calculate shares balance for
|
|
229
|
+
* @returns - user share balance in decimal (not lamports)
|
|
230
|
+
*/
|
|
231
|
+
getUserSharesBalanceSingleVault(user, vault) {
|
|
232
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
233
|
+
return this._vaultClient.getUserSharesBalanceSingleVault(user, vault);
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* This method returns the user shares balance for all existing vaults
|
|
238
|
+
* @param user - user to calculate the shares balance for
|
|
239
|
+
* @param vaultsOverride - the kamino vaults if already fetched, in order to reduce rpc calls
|
|
240
|
+
* @returns - hash map with keyh as vault address and value as user share balance in decimal (not lamports)
|
|
241
|
+
*/
|
|
242
|
+
getUserSharesBalanceAllVaults(user, vaultsOverride) {
|
|
243
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
244
|
+
return this._vaultClient.getUserSharesBalanceAllVaults(user, vaultsOverride);
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* @returns - the KaminoVault client
|
|
249
|
+
*/
|
|
250
|
+
getKaminoVaultClient() {
|
|
251
|
+
return this._vaultClient;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* This will trigger invest by balancing, based on weights, the reserve allocations of the vault. It can either withdraw or deposit into reserves to balance them. This is a function that should be cranked
|
|
255
|
+
* @param kaminoVault - vault to invest from
|
|
256
|
+
* @returns - an array of invest instructions for each invest action required for the vault reserves
|
|
257
|
+
*/
|
|
258
|
+
investAllReserves(kaminoVault) {
|
|
259
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
260
|
+
return this._vaultClient.investAllReservesIxs(kaminoVault);
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* This will trigger invest by balancing, based on weights, the reserve allocation of the vault. It can either withdraw or deposit into the given reserve to balance it
|
|
265
|
+
* @param kaminoVault - vault to invest from
|
|
266
|
+
* @param reserve - reserve to invest into or disinvest from
|
|
267
|
+
* @returns - an array of invest instructions for each invest action required for the vault reserves
|
|
268
|
+
*/
|
|
269
|
+
investSingleReserve(kaminoVault, reserveWithAddress) {
|
|
270
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
271
|
+
return this._vaultClient.investSingleReserveIxs(kaminoVault, reserveWithAddress);
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* This retruns an array of scope oracle configs to be used to set the scope price and twap oracles for a reserve
|
|
276
|
+
* @param feed - scope feed to fetch prices from
|
|
277
|
+
* @param cluster - cluster to fetch from, this should be left unchanged unless working on devnet or locally
|
|
278
|
+
* @returns - an array of scope oracle configs
|
|
279
|
+
*/
|
|
280
|
+
getScopeOracleConfigs() {
|
|
281
|
+
return __awaiter(this, arguments, void 0, function* (feed = 'hubble', cluster = 'mainnet-beta') {
|
|
282
|
+
const scopeOracleConfigs = [];
|
|
283
|
+
const scope = new scope_sdk_1.Scope(cluster, this._connection);
|
|
284
|
+
const oracleMappings = yield scope.getOracleMappings({ feed: feed });
|
|
285
|
+
const [, feedConfig] = yield scope.getFeedConfiguration({ feed: feed });
|
|
286
|
+
const tokenMetadatas = yield scope_sdk_1.TokenMetadatas.fetch(this._connection, feedConfig.tokensMetadata);
|
|
287
|
+
const decoder = new TextDecoder('utf-8');
|
|
288
|
+
console.log('feedConfig.tokensMetadata', feedConfig.tokensMetadata);
|
|
289
|
+
if (tokenMetadatas === null) {
|
|
290
|
+
throw new Error('TokenMetadatas not found');
|
|
291
|
+
}
|
|
292
|
+
for (let index = 0; index < oracleMappings.priceInfoAccounts.length; index++) {
|
|
293
|
+
if (!oracleMappings.priceInfoAccounts[index].equals(web3_js_1.PublicKey.default)) {
|
|
294
|
+
const name = decoder.decode(Uint8Array.from(tokenMetadatas.metadatasArray[index].name)).replace(/\0/g, '');
|
|
295
|
+
const oracleType = (0, lib_1.parseOracleType)(oracleMappings.priceTypes[index]);
|
|
296
|
+
scopeOracleConfigs.push({
|
|
297
|
+
scopePriceConfigAddress: feedConfig.oraclePrices,
|
|
298
|
+
name: name,
|
|
299
|
+
oracleType: oracleType,
|
|
300
|
+
oracleId: index,
|
|
301
|
+
oracleAccount: oracleMappings.priceInfoAccounts[index],
|
|
302
|
+
twapEnabled: oracleMappings.twapEnabled[index] === 1,
|
|
303
|
+
twapSourceId: oracleMappings.twapSource[index],
|
|
304
|
+
max_age: tokenMetadatas.metadatasArray[index].maxAgePriceSlots.toNumber(),
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
return scopeOracleConfigs;
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
} // KaminoManager
|
|
312
|
+
exports.KaminoManager = KaminoManager;
|
|
313
|
+
//# sourceMappingURL=manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manager.js","sourceRoot":"","sources":["../../src/classes/manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6CAOyB;AACzB,mCAAoH;AACpH,gCAoBgB;AAChB,wDAAsD;AACtD,yDAA2E;AAC3E,kDAAuB;AACvB,gDAAqD;AAGrD;;GAEG;AACH,MAAa,aAAa;IAOxB,YACE,UAAsB,EACtB,mBAA+B,EAC/B,oBAAgC,EAChC,oBAA6B;QAE7B,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,qBAAqB,GAAG,oBAAoB,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,qBAAa,CAAC;QACzF,IAAI,CAAC,oBAAoB,GAAG,mBAAmB,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,sBAAU,CAAC;QACnF,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,C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,CAAC,CAAC;oBAErE,kBAAkB,CAAC,IAAI,CAAC;wBACtB,uBAAuB,EAAE,UAAU,CAAC,YAAY;wBAChD,IAAI,EAAE,IAAI;wBACV,UAAU,EAAE,UAAU;wBACtB,QAAQ,EAAE,KAAK;wBACf,aAAa,EAAE,cAAc,CAAC,iBAAiB,CAAC,KAAK,CAAC;wBACtD,WAAW,EAAE,cAAc,CAAC,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC;wBACpD,YAAY,EAAE,cAAc,CAAC,UAAU,CAAC,KAAK,CAAC;wBAC9C,OAAO,EAAE,cAAc,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,gBAAgB,CAAC,QAAQ,EAAE;qBAC1E,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YAED,OAAO,kBAAkB,CAAC;QAC5B,CAAC;KAAA;CACF,CAAC,gBAAgB;AA1XlB,sCA0XC","sourcesContent":["import {\n Connection,\n Keypair,\n PublicKey,\n SystemProgram,\n SYSVAR_RENT_PUBKEY,\n TransactionInstruction,\n} from '@solana/web3.js';\nimport { KaminoVault, KaminoVaultClient, KaminoVaultConfig, kaminoVaultId, ReserveAllocationConfig } from './vault';\nimport {\n AddAssetToMarketParams,\n CreateKaminoMarketParams,\n createReserveIxs,\n DEFAULT_RECENT_SLOT_DURATION_MS,\n ENV,\n getReserveOracleConfigs,\n initLendingMarket,\n InitLendingMarketAccounts,\n InitLendingMarketArgs,\n LendingMarket,\n lendingMarketAuthPda,\n MarketWithAddress,\n parseForChangesReserveConfigAndGetIxs,\n parseOracleType,\n PubkeyHashMap,\n Reserve,\n ReserveWithAddress,\n ScopeOracleConfig,\n updateEntireReserveConfigIx,\n} from '../lib';\nimport { PROGRAM_ID } from '../idl_codegen/programId';\nimport { Scope, TokenMetadatas, U16_MAX } from '@hubbleprotocol/scope-sdk';\nimport BN from 'bn.js';\nimport { ReserveConfig } from '../idl_codegen/types';\nimport Decimal from 'decimal.js';\n\n/**\n * KaminoManager is a class that provides a high-level interface to interact with the Kamino Lend and Kamino Vault programs, in order to create and manage a market, as well as vaults\n */\nexport class KaminoManager {\n private readonly _connection: Connection;\n private readonly _kaminoVaultProgramId: PublicKey;\n private readonly _kaminoLendProgramId: PublicKey;\n private readonly _vaultClient: KaminoVaultClient;\n recentSlotDurationMs: number;\n\n constructor(\n connection: Connection,\n kaminoLendProgramId?: PublicKey,\n kaminoVaultProgramId?: PublicKey,\n recentSlotDurationMs?: number\n ) {\n this._connection = connection;\n this._kaminoVaultProgramId = kaminoVaultProgramId ? kaminoVaultProgramId : kaminoVaultId;\n this._kaminoLendProgramId = kaminoLendProgramId ? kaminoLendProgramId : PROGRAM_ID;\n this.recentSlotDurationMs = recentSlotDurationMs ? recentSlotDurationMs : DEFAULT_RECENT_SLOT_DURATION_MS;\n this._vaultClient = new KaminoVaultClient(\n connection,\n this._kaminoVaultProgramId,\n this._kaminoLendProgramId,\n this.recentSlotDurationMs\n );\n }\n\n getConnection() {\n return this._connection;\n }\n\n getProgramID() {\n return this._kaminoVaultProgramId;\n }\n\n /**\n * This is a function that helps quickly setting up a reserve for an asset with a default config. The config can be modified later on.\n * @param params.admin - the admin of the market\n * @returns market keypair - keypair used for market account creation -> to be signed with when executing the transaction\n * @returns ixns - an array of ixns for creating and initializing the market account\n */\n async createMarketIxs(\n params: CreateKaminoMarketParams\n ): Promise<{ market: Keypair; ixns: TransactionInstruction[] }> {\n const marketAccount = Keypair.generate();\n const size = LendingMarket.layout.span + 8;\n const [lendingMarketAuthority, _] = lendingMarketAuthPda(marketAccount.publicKey, this._kaminoLendProgramId);\n const createMarketIxns: TransactionInstruction[] = [];\n\n createMarketIxns.push(\n SystemProgram.createAccount({\n fromPubkey: params.admin,\n newAccountPubkey: marketAccount.publicKey,\n lamports: await this._connection.getMinimumBalanceForRentExemption(size),\n space: size,\n programId: this._kaminoLendProgramId,\n })\n );\n\n const accounts: InitLendingMarketAccounts = {\n lendingMarketOwner: params.admin,\n lendingMarket: marketAccount.publicKey,\n lendingMarketAuthority: lendingMarketAuthority,\n systemProgram: SystemProgram.programId,\n rent: SYSVAR_RENT_PUBKEY,\n };\n\n const args: InitLendingMarketArgs = {\n quoteCurrency: Array(32).fill(0),\n };\n\n createMarketIxns.push(initLendingMarket(args, accounts, this._kaminoLendProgramId));\n\n return { market: marketAccount, ixns: createMarketIxns };\n }\n\n /**\n * This is a function that helps quickly setting up a reserve for an asset with a default config. The config can be modified later on.\n * @param params.admin - the admin of the reserve\n * @param params.marketAddress - the market to create a reserve for, only the market admin can create a reserve for the market\n * @param params.assetConfig - an object that helps generate a default reserve config with some inputs which have to be configured before calling this function\n * @returns reserve - keypair used for reserve creation -> to be signed with when executing the transaction\n * @returns txnIxns - an array of arrays of ixns -> first array for reserve creation, second for updating it with correct params\n */\n async addAssetToMarketIxs(\n params: AddAssetToMarketParams\n ): Promise<{ reserve: Keypair; txnIxns: TransactionInstruction[][] }> {\n const market = await LendingMarket.fetch(this._connection, params.marketAddress, this._kaminoLendProgramId);\n if (!market) {\n throw new Error('Market not found');\n }\n const marketWithAddress: MarketWithAddress = { address: params.marketAddress, state: market };\n\n const reserveAccount = Keypair.generate();\n\n const createReserveInstructions = await createReserveIxs(\n this._connection,\n params.admin,\n params.marketAddress,\n params.assetConfig.mint,\n reserveAccount.publicKey,\n this._kaminoLendProgramId\n );\n\n const updateReserveInstructions = await this.updateReserveIxs(\n marketWithAddress,\n reserveAccount.publicKey,\n params.assetConfig.getReserveConfig(),\n undefined,\n true\n );\n\n const txnIxns: TransactionInstruction[][] = [];\n txnIxns.push(createReserveInstructions);\n txnIxns.push(updateReserveInstructions);\n\n return { reserve: reserveAccount, txnIxns };\n }\n\n /**\n * This method will create a vault with a given config. The config can be changed later on, but it is recommended to set it up correctly from the start\n * @param vaultConfig - the config object used to create a vault\n * @returns vault - keypair, should be used to sign the transaction which creates the vault account\n * @returns ixns - an array of instructions to create the vault\n */\n async createVaultIxs(vaultConfig: KaminoVaultConfig): Promise<{ vault: Keypair; ixns: TransactionInstruction[] }> {\n return this._vaultClient.createVaultIxs(vaultConfig);\n }\n\n /**\n * This method updates the vault reserve allocation cofnig for an exiting vault reserve, or adds a new reserve to the vault if it does not exist.\n * @param vault - vault to be updated\n * @param reserveAllocationConfig - new reserve allocation config\n * @returns - a list of instructions\n */\n async updateVaultReserveAllocationIxs(\n vault: KaminoVault,\n reserveAllocationConfig: ReserveAllocationConfig\n ): Promise<TransactionInstruction> {\n return this._vaultClient.updateReserveAllocationIxs(vault, reserveAllocationConfig);\n }\n\n /**\n * This method retruns the reserve config for a given reserve\n * @param reserve - reserve to get the config for\n * @returns - the reserve config\n */\n async getReserveConfig(reserve: PublicKey): Promise<ReserveConfig> {\n const reserveState = await Reserve.fetch(this._connection, reserve);\n if (!reserveState) {\n throw new Error('Reserve not found');\n }\n return reserveState.config;\n }\n\n /**\n * This function enables the update of the scope oracle configuration. In order to get a list of scope prices, getScopeOracleConfigs can be used\n * @param market - lending market which owns the reserve\n * @param reserve - reserve which to be updated\n * @param scopeOracleConfig - new scope oracle config\n * @param scopeTwapConfig - new scope twap config\n * @param maxAgeBufferSeconds - buffer to be added to onchain max_age - if oracle price is older than that, txns interacting with the reserve will fail\n * @returns - an array of instructions used update the oracle configuration\n */\n async updateReserveScopeOracleConfigurationIxs(\n market: MarketWithAddress,\n reserve: ReserveWithAddress,\n scopeOracleConfig: ScopeOracleConfig,\n scopeTwapConfig?: ScopeOracleConfig,\n maxAgeBufferSeconds: number = 20\n ): Promise<TransactionInstruction[]> {\n const reserveConfig = reserve.state.config;\n\n let scopeTwapId = U16_MAX;\n if (scopeTwapConfig) {\n scopeTwapId = scopeTwapConfig.oracleId;\n\n // if(scopeTwapConfig.twapSourceId !== scopeOracleConfig.oracleId) {\n // throw new Error('Twap source id must match oracle id');\n // }\n }\n\n const { scopeConfiguration } = getReserveOracleConfigs({\n scopePriceConfigAddress: scopeOracleConfig.scopePriceConfigAddress,\n scopeChain: [scopeOracleConfig.oracleId],\n scopeTwapChain: [scopeTwapId],\n });\n\n const newReserveConfig = new ReserveConfig({\n ...reserveConfig,\n tokenInfo: {\n ...reserveConfig.tokenInfo,\n scopeConfiguration: scopeConfiguration,\n // TODO: Decide if we want to keep this maxAge override for twap & price\n maxAgeTwapSeconds: scopeTwapConfig\n ? new BN(scopeTwapConfig.max_age + maxAgeBufferSeconds)\n : reserveConfig.tokenInfo.maxAgeTwapSeconds,\n maxAgePriceSeconds: new BN(scopeOracleConfig.max_age + maxAgeBufferSeconds),\n },\n });\n\n return this.updateReserveIxs(market, reserve.address, newReserveConfig, reserve.state);\n }\n\n /**\n * This function updates the given reserve with a new config. It can either update the entire reserve config or just update fields which differ between given reserve and existing reserve\n * @param marketWithAddress - the market that owns the reserve to be updated\n * @param reserve - the reserve to be updated\n * @param config - the new reserve configuration to be used for the update\n * @param reserveStateOverride - the reserve state, useful to provide, if already fetched outside this method, in order to avoid an extra rpc call to fetch it. Make sure the reserveConfig has not been updated since fetching the reserveState that you pass in.\n * @param updateEntireConfig - when set to false, it will only update fields that are different between @param config and reserveState.config, set to true it will always update entire reserve config. An entire reserveConfig update might be too large for a multisig transaction\n * @returns - an array of multiple update ixns. If there are many fields that are being updated without the updateEntireConfig=true, multiple transactions might be required to fit all ixns.\n */\n async updateReserveIxs(\n marketWithAddress: MarketWithAddress,\n reserve: PublicKey,\n config: ReserveConfig,\n reserveStateOverride?: Reserve,\n updateEntireConfig: boolean = false\n ): Promise<TransactionInstruction[]> {\n const reserveState = reserveStateOverride\n ? reserveStateOverride\n : (await Reserve.fetch(this._connection, reserve, this._kaminoLendProgramId))!;\n const ixns: TransactionInstruction[] = [];\n\n if (!reserveState || updateEntireConfig) {\n ixns.push(updateEntireReserveConfigIx(marketWithAddress, reserve, config, this._kaminoLendProgramId));\n } else {\n ixns.push(\n ...parseForChangesReserveConfigAndGetIxs(\n marketWithAddress,\n reserveState,\n reserve,\n config,\n this._kaminoLendProgramId\n )\n );\n }\n\n return ixns;\n }\n\n /**\n * This function creates instructions to deposit into a vault. It will also create ATA creation instructions for the vault shares that the user receives in return\n * @param user - user to deposit\n * @param vault - vault to deposit into\n * @param tokenAmount - token amount to be deposited, in decimals (will be converted in lamports)\n * @returns - an array of instructions to be used to be executed\n */\n async depositToVaultIxs(\n user: PublicKey,\n vault: KaminoVault,\n tokenAmount: Decimal\n ): Promise<TransactionInstruction[]> {\n return this._vaultClient.depositIxs(user, vault, tokenAmount);\n }\n\n /**\n * This function will return the missing ATA creation instructions, as well as one or multiple withdraw instructions, based on how many reserves it's needed to withdraw from. This might have to be split in multiple transactions\n * @param user - user to withdraw\n * @param vault - vault to withdraw from\n * @param shareAmount - share amount to withdraw, in order to withdraw everything, any value > user share amount\n * @param slot - current slot, used to estimate the interest earned in the different reserves with allocation from the vault\n * @returns an array of instructions to be executed\n */\n async withdrawFromVaultIxs(\n user: PublicKey,\n vault: KaminoVault,\n shareAmount: Decimal,\n slot: number\n ): Promise<TransactionInstruction[]> {\n return this._vaultClient.withdrawIxs(user, vault, shareAmount, slot);\n }\n\n /**\n * This method calculates the token per share value. This will always change based on interest earned from the vault, but calculating it requires a bunch of rpc requests. Caching this for a short duration would be optimal\n * @param vault - vault to calculate tokensPerShare for\n * @param slot - current slot, used to estimate the interest earned in the different reserves with allocation from the vault\n * @returns - token per share value\n */\n async getTokensPerShareSingleVault(vault: KaminoVault, slot: number): Promise<Decimal> {\n return this._vaultClient.getTokensPerShareSingleVault(vault, slot);\n }\n\n /**\n * This method returns the user shares balance for a given vault\n * @param user - user to calculate the shares balance for\n * @param vault - vault to calculate shares balance for\n * @returns - user share balance in decimal (not lamports)\n */\n async getUserSharesBalanceSingleVault(user: PublicKey, vault: KaminoVault): Promise<Decimal> {\n return this._vaultClient.getUserSharesBalanceSingleVault(user, vault);\n }\n\n /**\n * This method returns the user shares balance for all existing vaults\n * @param user - user to calculate the shares balance for\n * @param vaultsOverride - the kamino vaults if already fetched, in order to reduce rpc calls\n * @returns - hash map with keyh as vault address and value as user share balance in decimal (not lamports)\n */\n async getUserSharesBalanceAllVaults(\n user: PublicKey,\n vaultsOverride: KaminoVault[]\n ): Promise<PubkeyHashMap<PublicKey, Decimal>> {\n return this._vaultClient.getUserSharesBalanceAllVaults(user, vaultsOverride);\n }\n\n /**\n * @returns - the KaminoVault client\n */\n getKaminoVaultClient(): KaminoVaultClient {\n return this._vaultClient;\n }\n\n /**\n * This will trigger invest by balancing, based on weights, the reserve allocations of the vault. It can either withdraw or deposit into reserves to balance them. This is a function that should be cranked\n * @param kaminoVault - vault to invest from\n * @returns - an array of invest instructions for each invest action required for the vault reserves\n */\n async investAllReserves(kaminoVault: KaminoVault): Promise<TransactionInstruction[]> {\n return this._vaultClient.investAllReservesIxs(kaminoVault);\n }\n\n /**\n * This will trigger invest by balancing, based on weights, the reserve allocation of the vault. It can either withdraw or deposit into the given reserve to balance it\n * @param kaminoVault - vault to invest from\n * @param reserve - reserve to invest into or disinvest from\n * @returns - an array of invest instructions for each invest action required for the vault reserves\n */\n async investSingleReserve(\n kaminoVault: KaminoVault,\n reserveWithAddress: ReserveWithAddress\n ): Promise<TransactionInstruction> {\n return this._vaultClient.investSingleReserveIxs(kaminoVault, reserveWithAddress);\n }\n\n /**\n * This retruns an array of scope oracle configs to be used to set the scope price and twap oracles for a reserve\n * @param feed - scope feed to fetch prices from\n * @param cluster - cluster to fetch from, this should be left unchanged unless working on devnet or locally\n * @returns - an array of scope oracle configs\n */\n async getScopeOracleConfigs(\n feed: string = 'hubble',\n cluster: ENV = 'mainnet-beta'\n ): Promise<Array<ScopeOracleConfig>> {\n const scopeOracleConfigs: Array<ScopeOracleConfig> = [];\n\n const scope = new Scope(cluster, this._connection);\n const oracleMappings = await scope.getOracleMappings({ feed: feed });\n const [, feedConfig] = await scope.getFeedConfiguration({ feed: feed });\n const tokenMetadatas = await TokenMetadatas.fetch(this._connection, feedConfig.tokensMetadata);\n const decoder = new TextDecoder('utf-8');\n\n console.log('feedConfig.tokensMetadata', feedConfig.tokensMetadata);\n\n if (tokenMetadatas === null) {\n throw new Error('TokenMetadatas not found');\n }\n\n for (let index = 0; index < oracleMappings.priceInfoAccounts.length; index++) {\n if (!oracleMappings.priceInfoAccounts[index].equals(PublicKey.default)) {\n const name = decoder.decode(Uint8Array.from(tokenMetadatas.metadatasArray[index].name)).replace(/\\0/g, '');\n const oracleType = parseOracleType(oracleMappings.priceTypes[index]);\n\n scopeOracleConfigs.push({\n scopePriceConfigAddress: feedConfig.oraclePrices,\n name: name,\n oracleType: oracleType,\n oracleId: index,\n oracleAccount: oracleMappings.priceInfoAccounts[index],\n twapEnabled: oracleMappings.twapEnabled[index] === 1,\n twapSourceId: oracleMappings.twapSource[index],\n max_age: tokenMetadatas.metadatasArray[index].maxAgePriceSlots.toNumber(),\n });\n }\n }\n\n return scopeOracleConfigs;\n }\n} // KaminoManager\n"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { AccountInfo, Connection, PublicKey } from '@solana/web3.js';
|
|
1
|
+
import { AccountInfo, Connection, PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
2
2
|
import Decimal from 'decimal.js';
|
|
3
|
-
import { TokenOracleData } from '../utils';
|
|
3
|
+
import { MarketWithAddress, TokenOracleData } from '../utils';
|
|
4
4
|
import { ReserveDataType } from './shared';
|
|
5
5
|
import { Reserve } from '../idl_codegen/accounts';
|
|
6
|
+
import { BorrowRateCurve, ReserveConfig } from '../idl_codegen/types';
|
|
6
7
|
import { ActionType } from './action';
|
|
7
8
|
import { KaminoMarket } from './market';
|
|
8
9
|
export declare const DEFAULT_RECENT_SLOT_DURATION_MS = 450;
|
|
@@ -215,3 +216,13 @@ export declare class KaminoReserve {
|
|
|
215
216
|
*/
|
|
216
217
|
private approximateCompoundedInterest;
|
|
217
218
|
}
|
|
219
|
+
export declare function createReserveIxs(connection: Connection, owner: PublicKey, lendingMarket: PublicKey, liquidityMint: PublicKey, reserveAddress: PublicKey, programId: PublicKey): Promise<TransactionInstruction[]>;
|
|
220
|
+
export declare function updateReserveConfigIx(marketWithAddress: MarketWithAddress, reserveAddress: PublicKey, modeDiscriminator: number, value: Uint8Array, programId: PublicKey): TransactionInstruction;
|
|
221
|
+
export declare function updateEntireReserveConfigIx(marketWithAddress: MarketWithAddress, reserveAddress: PublicKey, reserveConfig: ReserveConfig, programId: PublicKey): TransactionInstruction;
|
|
222
|
+
export declare function parseForChangesReserveConfigAndGetIxs(marketWithAddress: MarketWithAddress, reserve: Reserve | undefined, reserveAddress: PublicKey, reserveConfig: ReserveConfig, programId: PublicKey): TransactionInstruction[];
|
|
223
|
+
export declare function updateReserveConfigEncodedValue(discriminator: number, value: number | number[] | BorrowRateCurve | PublicKey): Uint8Array;
|
|
224
|
+
export declare function serializeBorrowRateCurve(curve: BorrowRateCurve): Buffer;
|
|
225
|
+
export type ReserveWithAddress = {
|
|
226
|
+
address: PublicKey;
|
|
227
|
+
state: Reserve;
|
|
228
|
+
};
|