@kamino-finance/klend-sdk 5.11.5 → 5.11.6-beta.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/dist/classes/action.d.ts +23 -23
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +195 -122
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/index.d.ts +0 -1
- package/dist/classes/index.d.ts.map +1 -1
- package/dist/classes/index.js +0 -1
- package/dist/classes/index.js.map +1 -1
- package/dist/classes/manager.d.ts +1 -6
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +1 -16
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/market.d.ts +3 -3
- package/dist/classes/market.d.ts.map +1 -1
- package/dist/classes/market.js +16 -30
- package/dist/classes/market.js.map +1 -1
- package/dist/classes/obligation.d.ts +0 -2
- package/dist/classes/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +0 -5
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/types.d.ts.map +1 -1
- package/dist/classes/vault.d.ts +0 -1
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +18 -21
- package/dist/classes/vault.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts +3 -6
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js +7 -13
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/errors/custom.d.ts +1 -25
- package/dist/idl_codegen_kamino_vault/errors/custom.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/errors/custom.js +1 -43
- package/dist/idl_codegen_kamino_vault/errors/custom.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.d.ts +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/giveUpPendingFees.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initVault.d.ts +0 -1
- package/dist/idl_codegen_kamino_vault/instructions/initVault.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initVault.js +0 -1
- package/dist/idl_codegen_kamino_vault/instructions/initVault.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.d.ts +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.d.ts +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateReserveAllocation.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.d.ts +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateSharesMetadata.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.d.ts +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/updateVaultConfig.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.d.ts +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.js +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/withdrawPendingFees.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.d.ts +0 -13
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.js +1 -25
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/index.d.ts +2 -2
- package/dist/idl_codegen_kamino_vault/types/index.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/index.js.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.d.ts +4 -4
- package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/repay_with_collateral_operations.js +8 -10
- package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.d.ts +2 -2
- package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
- package/dist/lending_operations/swap_collateral_operations.js +6 -11
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/leverage/operations.d.ts +7 -9
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +66 -78
- package/dist/leverage/operations.js.map +1 -1
- package/dist/leverage/types.d.ts +4 -4
- package/dist/leverage/types.d.ts.map +1 -1
- package/dist/utils/ObligationType.d.ts +1 -1
- package/dist/utils/ObligationType.d.ts.map +1 -1
- package/dist/utils/constants.d.ts +0 -1
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/constants.js +1 -2
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/managerTypes.d.ts.map +1 -1
- package/dist/utils/managerTypes.js +52 -7
- package/dist/utils/managerTypes.js.map +1 -1
- package/dist/utils/oracle.d.ts +3 -3
- package/dist/utils/oracle.d.ts.map +1 -1
- package/dist/utils/oracle.js +3 -4
- package/dist/utils/oracle.js.map +1 -1
- package/package.json +2 -2
- package/src/classes/action.ts +211 -143
- package/src/classes/index.ts +0 -1
- package/src/classes/manager.ts +1 -27
- package/src/classes/market.ts +25 -34
- package/src/classes/obligation.ts +0 -6
- package/src/classes/types.ts +1 -1
- package/src/classes/vault.ts +22 -23
- package/src/client.ts +3 -8
- package/src/idl_codegen_kamino_vault/accounts/VaultState.ts +9 -17
- package/src/idl_codegen_kamino_vault/errors/custom.ts +0 -42
- package/src/idl_codegen_kamino_vault/instructions/giveUpPendingFees.ts +2 -2
- package/src/idl_codegen_kamino_vault/instructions/initVault.ts +0 -2
- package/src/idl_codegen_kamino_vault/instructions/initializeSharesMetadata.ts +2 -2
- package/src/idl_codegen_kamino_vault/instructions/updateReserveAllocation.ts +2 -2
- package/src/idl_codegen_kamino_vault/instructions/updateSharesMetadata.ts +2 -2
- package/src/idl_codegen_kamino_vault/instructions/updateVaultConfig.ts +2 -2
- package/src/idl_codegen_kamino_vault/instructions/withdrawPendingFees.ts +2 -2
- package/src/idl_codegen_kamino_vault/types/VaultConfigField.ts +0 -30
- package/src/idl_codegen_kamino_vault/types/index.ts +0 -2
- package/src/idl_kamino_vault.json +8 -35
- package/src/lending_operations/repay_with_collateral_operations.ts +11 -15
- package/src/lending_operations/swap_collateral_operations.ts +7 -19
- package/src/leverage/operations.ts +66 -114
- package/src/leverage/types.ts +4 -4
- package/src/utils/ObligationType.ts +1 -1
- package/src/utils/constants.ts +0 -1
- package/src/utils/managerTypes.ts +52 -10
- package/src/utils/oracle.ts +6 -7
package/dist/classes/action.js
CHANGED
|
@@ -10,12 +10,12 @@ const bn_js_1 = __importDefault(require("bn.js"));
|
|
|
10
10
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
11
11
|
const instructions_1 = require("../idl_codegen/instructions");
|
|
12
12
|
const utils_1 = require("../utils");
|
|
13
|
-
const market_1 = require("./market");
|
|
14
13
|
const obligation_1 = require("./obligation");
|
|
15
14
|
const types_1 = require("../idl_codegen/types");
|
|
16
15
|
const farms_sdk_1 = require("@kamino-finance/farms-sdk");
|
|
17
16
|
const ObligationType_1 = require("../utils/ObligationType");
|
|
18
17
|
const lib_1 = require("../lib");
|
|
18
|
+
const scope_sdk_1 = require("@kamino-finance/scope-sdk");
|
|
19
19
|
const SOL_PADDING_FOR_INTEREST = new bn_js_1.default('1000000');
|
|
20
20
|
class KaminoAction {
|
|
21
21
|
kaminoMarket;
|
|
@@ -180,18 +180,27 @@ class KaminoAction {
|
|
|
180
180
|
axn.addRequestElevationIx(elevationGroup, 'setup');
|
|
181
181
|
return axn;
|
|
182
182
|
}
|
|
183
|
-
static async buildDepositTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs,
|
|
183
|
+
static async buildDepositTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
184
184
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
185
185
|
requestElevationGroup = false, // to be requested *before* the deposit
|
|
186
186
|
includeUserMetadata = true, // if true it includes user metadata
|
|
187
|
-
createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0, overrideElevationGroupRequest = undefined // if set, when an elevationgroup request is made, it will use this value
|
|
187
|
+
createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }, overrideElevationGroupRequest = undefined // if set, when an elevationgroup request is made, it will use this value
|
|
188
188
|
) {
|
|
189
189
|
const axn = await KaminoAction.initialize('deposit', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
190
190
|
const addInitObligationForFarm = true;
|
|
191
191
|
if (extraComputeBudget > 0) {
|
|
192
192
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
193
193
|
}
|
|
194
|
-
|
|
194
|
+
const allReserves = new utils_1.PublicKeySet([
|
|
195
|
+
...axn.depositReserves,
|
|
196
|
+
...axn.borrowReserves,
|
|
197
|
+
axn.reserve.address,
|
|
198
|
+
]).toArray();
|
|
199
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
200
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
201
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
202
|
+
}
|
|
203
|
+
await axn.addSupportIxs('deposit', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, createLookupTable, undefined, overrideElevationGroupRequest);
|
|
195
204
|
if (useV2Ixs) {
|
|
196
205
|
axn.addDepositIxV2();
|
|
197
206
|
}
|
|
@@ -201,30 +210,54 @@ class KaminoAction {
|
|
|
201
210
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
202
211
|
return axn;
|
|
203
212
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
213
|
+
getTokenIdsForScopeRefresh(kaminoMarket, reserves) {
|
|
214
|
+
const tokenIds = [];
|
|
215
|
+
for (const reserveAddress of reserves) {
|
|
216
|
+
const reserve = kaminoMarket.getReserveByAddress(reserveAddress);
|
|
217
|
+
if (!reserve) {
|
|
218
|
+
throw new Error(`Reserve not found for reserve ${reserveAddress.toBase58()}`);
|
|
219
|
+
}
|
|
220
|
+
if (!reserve.state.config.tokenInfo.scopeConfiguration.priceFeed.equals(web3_js_1.PublicKey.default)) {
|
|
221
|
+
reserve.state.config.tokenInfo.scopeConfiguration.priceChain.map((x) => {
|
|
222
|
+
if (x !== scope_sdk_1.U16_MAX) {
|
|
223
|
+
tokenIds.push(x);
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
reserve.state.config.tokenInfo.scopeConfiguration.twapChain.map((x) => {
|
|
227
|
+
if (x !== scope_sdk_1.U16_MAX) {
|
|
228
|
+
tokenIds.push(x);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return tokenIds;
|
|
234
|
+
}
|
|
235
|
+
async addScopeRefreshIxs(tokens, feed = 'hubble') {
|
|
236
|
+
this.preTxnIxsLabels.unshift(`refreshScopePrices`);
|
|
237
|
+
this.preTxnIxs.unshift(await this.kaminoMarket.scope.refreshPriceListIx({
|
|
207
238
|
feed: feed,
|
|
208
239
|
}, tokens));
|
|
209
240
|
}
|
|
210
|
-
static async buildBorrowTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs,
|
|
241
|
+
static async buildBorrowTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
211
242
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
212
243
|
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
|
|
213
|
-
createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0, overrideElevationGroupRequest = undefined // if set, when an elevationgroup request is made, it will use this value
|
|
244
|
+
createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }, overrideElevationGroupRequest = undefined // if set, when an elevationgroup request is made, it will use this value
|
|
214
245
|
) {
|
|
215
246
|
const axn = await KaminoAction.initialize('borrow', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
216
247
|
const addInitObligationForFarm = true;
|
|
217
248
|
if (extraComputeBudget > 0) {
|
|
218
249
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
219
250
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
251
|
+
const allReserves = new utils_1.PublicKeySet([
|
|
252
|
+
...axn.depositReserves,
|
|
253
|
+
...axn.borrowReserves,
|
|
254
|
+
axn.reserve.address,
|
|
255
|
+
]).toArray();
|
|
256
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
257
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
258
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
226
259
|
}
|
|
227
|
-
await axn.addSupportIxs('borrow', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs,
|
|
260
|
+
await axn.addSupportIxs('borrow', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, createLookupTable, undefined, overrideElevationGroupRequest);
|
|
228
261
|
if (useV2Ixs) {
|
|
229
262
|
axn.addBorrowIxV2();
|
|
230
263
|
}
|
|
@@ -234,42 +267,69 @@ class KaminoAction {
|
|
|
234
267
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
235
268
|
return axn;
|
|
236
269
|
}
|
|
237
|
-
static async buildDepositReserveLiquidityTxns(kaminoMarket, amount, mint, owner, obligation,
|
|
270
|
+
static async buildDepositReserveLiquidityTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
238
271
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas
|
|
239
|
-
requestElevationGroup = false, referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
|
|
272
|
+
requestElevationGroup = false, referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
240
273
|
const axn = await KaminoAction.initialize('mint', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
241
274
|
const addInitObligationForFarm = true;
|
|
242
275
|
if (extraComputeBudget > 0) {
|
|
243
276
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
244
277
|
}
|
|
245
|
-
|
|
278
|
+
const allReserves = new utils_1.PublicKeySet([
|
|
279
|
+
...axn.depositReserves,
|
|
280
|
+
...axn.borrowReserves,
|
|
281
|
+
axn.reserve.address,
|
|
282
|
+
]).toArray();
|
|
283
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
284
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
285
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
286
|
+
}
|
|
287
|
+
await axn.addSupportIxs('mint', includeAtaIxns, requestElevationGroup, false, addInitObligationForFarm, false, false);
|
|
246
288
|
axn.addDepositReserveLiquidityIx();
|
|
247
289
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
248
290
|
return axn;
|
|
249
291
|
}
|
|
250
|
-
static async buildRedeemReserveCollateralTxns(kaminoMarket, amount, mint, owner, obligation,
|
|
292
|
+
static async buildRedeemReserveCollateralTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
251
293
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas
|
|
252
|
-
requestElevationGroup = false, referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
|
|
294
|
+
requestElevationGroup = false, referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
253
295
|
const axn = await KaminoAction.initialize('redeem', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
254
296
|
const addInitObligationForFarm = true;
|
|
255
297
|
if (extraComputeBudget > 0) {
|
|
256
298
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
257
299
|
}
|
|
258
|
-
|
|
300
|
+
const allReserves = new utils_1.PublicKeySet([
|
|
301
|
+
...axn.depositReserves,
|
|
302
|
+
...axn.borrowReserves,
|
|
303
|
+
axn.reserve.address,
|
|
304
|
+
]).toArray();
|
|
305
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
306
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
307
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
308
|
+
}
|
|
309
|
+
await axn.addSupportIxs('redeem', includeAtaIxns, requestElevationGroup, false, addInitObligationForFarm, false, false);
|
|
259
310
|
axn.addRedeemReserveCollateralIx();
|
|
260
311
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
261
312
|
return axn;
|
|
262
313
|
}
|
|
263
|
-
static async buildDepositObligationCollateralTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs,
|
|
314
|
+
static async buildDepositObligationCollateralTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
264
315
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas
|
|
265
316
|
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
|
|
266
|
-
createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
|
|
317
|
+
createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
267
318
|
const axn = await KaminoAction.initialize('depositCollateral', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
268
319
|
const addInitObligationForFarm = true;
|
|
269
320
|
if (extraComputeBudget > 0) {
|
|
270
321
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
271
322
|
}
|
|
272
|
-
|
|
323
|
+
const allReserves = new utils_1.PublicKeySet([
|
|
324
|
+
...axn.depositReserves,
|
|
325
|
+
...axn.borrowReserves,
|
|
326
|
+
axn.reserve.address,
|
|
327
|
+
]).toArray();
|
|
328
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
329
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
330
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
331
|
+
}
|
|
332
|
+
await axn.addSupportIxs('depositCollateral', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, createLookupTable);
|
|
273
333
|
if (useV2Ixs) {
|
|
274
334
|
axn.addDepositObligationCollateralIxV2();
|
|
275
335
|
}
|
|
@@ -279,10 +339,10 @@ class KaminoAction {
|
|
|
279
339
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
280
340
|
return axn;
|
|
281
341
|
}
|
|
282
|
-
static async buildDepositAndBorrowTxns(kaminoMarket, depositAmount, depositMint, borrowAmount, borrowMint, payer, obligation, useV2Ixs,
|
|
342
|
+
static async buildDepositAndBorrowTxns(kaminoMarket, depositAmount, depositMint, borrowAmount, borrowMint, payer, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
283
343
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
284
344
|
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
|
|
285
|
-
createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
|
|
345
|
+
createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
286
346
|
const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'depositAndBorrow', depositAmount, depositMint, borrowMint, payer, payer, obligation, borrowAmount, referrer, currentSlot);
|
|
287
347
|
const addInitObligationForFarmForDeposit = true;
|
|
288
348
|
const addInitObligationForFarmForBorrow = false;
|
|
@@ -290,14 +350,17 @@ class KaminoAction {
|
|
|
290
350
|
if (extraComputeBudget > 0) {
|
|
291
351
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
292
352
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
353
|
+
const allReserves = new utils_1.PublicKeySet([
|
|
354
|
+
...axn.depositReserves,
|
|
355
|
+
...axn.borrowReserves,
|
|
356
|
+
axn.reserve.address,
|
|
357
|
+
axn.outflowReserve.address,
|
|
358
|
+
]).toArray();
|
|
359
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
360
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
361
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
299
362
|
}
|
|
300
|
-
await axn.addSupportIxs('deposit', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForDeposit, useV2Ixs,
|
|
363
|
+
await axn.addSupportIxs('deposit', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForDeposit, useV2Ixs, createLookupTable, twoTokenAction);
|
|
301
364
|
if (useV2Ixs) {
|
|
302
365
|
await axn.addDepositAndBorrowIxV2();
|
|
303
366
|
}
|
|
@@ -306,24 +369,12 @@ class KaminoAction {
|
|
|
306
369
|
}
|
|
307
370
|
await axn.addInBetweenIxs('depositAndBorrow', includeAtaIxns, requestElevationGroup, addInitObligationForFarmForBorrow, useV2Ixs);
|
|
308
371
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
309
|
-
// Create the scope refresh ixn in here to ensure it's the first ixn in the txn
|
|
310
|
-
const allReserves = new utils_1.PublicKeySet([
|
|
311
|
-
...axn.depositReserves,
|
|
312
|
-
...axn.borrowReserves,
|
|
313
|
-
axn.reserve.address,
|
|
314
|
-
...(axn.outflowReserve ? [axn.outflowReserve.address] : []),
|
|
315
|
-
...(axn.preLoadedDepositReservesSameTx ? axn.preLoadedDepositReservesSameTx : []),
|
|
316
|
-
]).toArray();
|
|
317
|
-
const tokenIds = (0, market_1.getTokenIdsForScopeRefresh)(axn.kaminoMarket, allReserves);
|
|
318
|
-
if (tokenIds.length > 0 && scopeRefreshConfig) {
|
|
319
|
-
await axn.addScopeRefreshIxs(scopeRefreshConfig.scope, tokenIds, scopeRefreshConfig.scopeFeed);
|
|
320
|
-
}
|
|
321
372
|
return axn;
|
|
322
373
|
}
|
|
323
|
-
static async buildRepayAndWithdrawTxns(kaminoMarket, repayAmount, repayMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, useV2Ixs,
|
|
374
|
+
static async buildRepayAndWithdrawTxns(kaminoMarket, repayAmount, repayMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
324
375
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
325
376
|
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
|
|
326
|
-
createLookupTable = true, referrer = web3_js_1.PublicKey.default) {
|
|
377
|
+
createLookupTable = true, referrer = web3_js_1.PublicKey.default, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
327
378
|
const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'repayAndWithdraw', repayAmount, repayMint, withdrawMint, payer, payer, obligation, withdrawAmount, referrer, currentSlot);
|
|
328
379
|
const addInitObligationForFarmForRepay = true;
|
|
329
380
|
const addInitObligationForFarmForWithdraw = false;
|
|
@@ -331,7 +382,17 @@ class KaminoAction {
|
|
|
331
382
|
if (extraComputeBudget > 0) {
|
|
332
383
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
333
384
|
}
|
|
334
|
-
|
|
385
|
+
const allReserves = new utils_1.PublicKeySet([
|
|
386
|
+
...axn.depositReserves,
|
|
387
|
+
...axn.borrowReserves,
|
|
388
|
+
axn.reserve.address,
|
|
389
|
+
axn.outflowReserve.address,
|
|
390
|
+
]).toArray();
|
|
391
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
392
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
393
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
394
|
+
}
|
|
395
|
+
await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForRepay, useV2Ixs, createLookupTable, twoTokenAction);
|
|
335
396
|
const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve, axn.outflowAmount);
|
|
336
397
|
if (useV2Ixs) {
|
|
337
398
|
await axn.addRepayAndWithdrawIxsV2(withdrawCollateralAmount);
|
|
@@ -341,25 +402,13 @@ class KaminoAction {
|
|
|
341
402
|
}
|
|
342
403
|
await axn.addInBetweenIxs('repayAndWithdraw', includeAtaIxns, requestElevationGroup, addInitObligationForFarmForWithdraw, useV2Ixs);
|
|
343
404
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
344
|
-
// Create the scope refresh ixn in here to ensure it's the first ixn in the txn
|
|
345
|
-
const allReserves = new utils_1.PublicKeySet([
|
|
346
|
-
...axn.depositReserves,
|
|
347
|
-
...axn.borrowReserves,
|
|
348
|
-
axn.reserve.address,
|
|
349
|
-
...(axn.outflowReserve ? [axn.outflowReserve.address] : []),
|
|
350
|
-
...(axn.preLoadedDepositReservesSameTx ? axn.preLoadedDepositReservesSameTx : []),
|
|
351
|
-
]).toArray();
|
|
352
|
-
const tokenIds = (0, market_1.getTokenIdsForScopeRefresh)(axn.kaminoMarket, allReserves);
|
|
353
|
-
if (tokenIds.length > 0 && scopeRefreshConfig) {
|
|
354
|
-
await axn.addScopeRefreshIxs(scopeRefreshConfig.scope, tokenIds, scopeRefreshConfig.scopeFeed);
|
|
355
|
-
}
|
|
356
405
|
return axn;
|
|
357
406
|
}
|
|
358
|
-
static async buildWithdrawTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs,
|
|
407
|
+
static async buildWithdrawTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
359
408
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
360
409
|
requestElevationGroup = false, // to be requested *after* the withdraw
|
|
361
410
|
includeUserMetadata = true, // if true it includes user metadata
|
|
362
|
-
createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0, overrideElevationGroupRequest,
|
|
411
|
+
createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0, scopeRefresh = undefined, overrideElevationGroupRequest,
|
|
363
412
|
// Optional customizations which may be needed if the obligation was mutated by some previous ixn.
|
|
364
413
|
obligationCustomizations) {
|
|
365
414
|
const axn = await KaminoAction.initialize('withdraw', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
@@ -368,7 +417,16 @@ class KaminoAction {
|
|
|
368
417
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
369
418
|
}
|
|
370
419
|
axn.depositReserves.push(...(obligationCustomizations?.addedDepositReserves || []));
|
|
371
|
-
|
|
420
|
+
const allReserves = new utils_1.PublicKeySet([
|
|
421
|
+
...axn.depositReserves,
|
|
422
|
+
...axn.borrowReserves,
|
|
423
|
+
axn.reserve.address,
|
|
424
|
+
]).toArray();
|
|
425
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
426
|
+
if (tokenIds.length > 0 && scopeRefresh && scopeRefresh.includeScopeRefresh) {
|
|
427
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
428
|
+
}
|
|
429
|
+
await axn.addSupportIxs('withdraw', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, createLookupTable, false, overrideElevationGroupRequest);
|
|
372
430
|
const collateralAmount = axn.getWithdrawCollateralAmount(axn.reserve, axn.amount);
|
|
373
431
|
if (useV2Ixs) {
|
|
374
432
|
await axn.addWithdrawIxV2(collateralAmount);
|
|
@@ -394,13 +452,22 @@ class KaminoAction {
|
|
|
394
452
|
* @param includeUserMetadata - if true it includes user metadata
|
|
395
453
|
* @param referrer
|
|
396
454
|
*/
|
|
397
|
-
static async buildRepayTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs,
|
|
455
|
+
static async buildRepayTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, currentSlot, payer = undefined, extraComputeBudget = 1_000_000, includeAtaIxns = true, requestElevationGroup = false, includeUserMetadata = true, createLookupTable = true, referrer = web3_js_1.PublicKey.default, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
398
456
|
const axn = await KaminoAction.initialize('repay', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot, payer);
|
|
399
457
|
const addInitObligationForFarm = true;
|
|
400
458
|
if (extraComputeBudget > 0) {
|
|
401
459
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
402
460
|
}
|
|
403
|
-
|
|
461
|
+
const allReserves = new utils_1.PublicKeySet([
|
|
462
|
+
...axn.depositReserves,
|
|
463
|
+
...axn.borrowReserves,
|
|
464
|
+
axn.reserve.address,
|
|
465
|
+
]).toArray();
|
|
466
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
467
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
468
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
469
|
+
}
|
|
470
|
+
await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, createLookupTable);
|
|
404
471
|
if (useV2Ixs) {
|
|
405
472
|
await axn.addRepayIxV2();
|
|
406
473
|
}
|
|
@@ -410,16 +477,26 @@ class KaminoAction {
|
|
|
410
477
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
411
478
|
return axn;
|
|
412
479
|
}
|
|
413
|
-
static async buildLiquidateTxns(kaminoMarket, amount, minCollateralReceiveAmount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, useV2Ixs,
|
|
480
|
+
static async buildLiquidateTxns(kaminoMarket, amount, minCollateralReceiveAmount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
414
481
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas, and creates all other token atas if they don't exist
|
|
415
482
|
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
|
|
416
|
-
createLookupTable = true, referrer = web3_js_1.PublicKey.default, maxAllowedLtvOverridePercent = 0, currentSlot = 0) {
|
|
483
|
+
createLookupTable = true, referrer = web3_js_1.PublicKey.default, maxAllowedLtvOverridePercent = 0, currentSlot = 0, scopeRefresh = { includeScopeRefresh: false, scopeFeed: 'hubble' }) {
|
|
417
484
|
const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'liquidate', amount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, minCollateralReceiveAmount, referrer, currentSlot);
|
|
418
485
|
const addInitObligationForFarm = true;
|
|
419
486
|
if (extraComputeBudget > 0) {
|
|
420
487
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
421
488
|
}
|
|
422
|
-
|
|
489
|
+
const allReserves = new utils_1.PublicKeySet([
|
|
490
|
+
...axn.depositReserves,
|
|
491
|
+
...axn.borrowReserves,
|
|
492
|
+
axn.reserve.address,
|
|
493
|
+
axn.outflowReserve.address,
|
|
494
|
+
]).toArray();
|
|
495
|
+
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
496
|
+
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
497
|
+
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
498
|
+
}
|
|
499
|
+
await axn.addSupportIxs('liquidate', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, createLookupTable);
|
|
423
500
|
if (useV2Ixs) {
|
|
424
501
|
await axn.addLiquidateIxV2(maxAllowedLtvOverridePercent);
|
|
425
502
|
}
|
|
@@ -433,13 +510,6 @@ class KaminoAction {
|
|
|
433
510
|
const { axn, createAtaIxs } = await KaminoAction.initializeWithdrawReferrerFees(tokenMint, owner, kaminoMarket, currentSlot);
|
|
434
511
|
axn.preTxnIxs.push(...createAtaIxs);
|
|
435
512
|
axn.preTxnIxsLabels.push(`createAtasIxs[${axn.userTokenAccountAddress.toString()}]`);
|
|
436
|
-
if (!axn.referrer.equals(web3_js_1.PublicKey.default)) {
|
|
437
|
-
const referrerTokenState = (0, utils_1.referrerTokenStatePda)(axn.referrer, axn.reserve.address, axn.kaminoMarket.programId)[0];
|
|
438
|
-
const account = await axn.kaminoMarket.getConnection().getAccountInfo(referrerTokenState);
|
|
439
|
-
if (!account) {
|
|
440
|
-
axn.addInitReferrerTokenStateIx(axn.reserve, referrerTokenState);
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
513
|
axn.addRefreshReserveIxs([axn.reserve.address]);
|
|
444
514
|
axn.addWithdrawReferrerFeesIxs();
|
|
445
515
|
return axn;
|
|
@@ -565,8 +635,8 @@ class KaminoAction {
|
|
|
565
635
|
addDepositIxV2() {
|
|
566
636
|
const farmsAccounts = this.reserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
|
|
567
637
|
? {
|
|
568
|
-
obligationFarmUserState:
|
|
569
|
-
reserveFarmState:
|
|
638
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
639
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
570
640
|
}
|
|
571
641
|
: {
|
|
572
642
|
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmCollateral)[0],
|
|
@@ -615,8 +685,8 @@ class KaminoAction {
|
|
|
615
685
|
addDepositObligationCollateralIxV2() {
|
|
616
686
|
const farmsAccounts = this.reserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
|
|
617
687
|
? {
|
|
618
|
-
obligationFarmUserState:
|
|
619
|
-
reserveFarmState:
|
|
688
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
689
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
620
690
|
}
|
|
621
691
|
: {
|
|
622
692
|
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmCollateral)[0],
|
|
@@ -678,8 +748,8 @@ class KaminoAction {
|
|
|
678
748
|
});
|
|
679
749
|
const farmsAccounts = this.reserve.state.farmDebt.equals(web3_js_1.PublicKey.default)
|
|
680
750
|
? {
|
|
681
|
-
obligationFarmUserState:
|
|
682
|
-
reserveFarmState:
|
|
751
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
752
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
683
753
|
}
|
|
684
754
|
: {
|
|
685
755
|
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
@@ -736,8 +806,8 @@ class KaminoAction {
|
|
|
736
806
|
async addWithdrawIxV2(collateralAmount) {
|
|
737
807
|
const farmsAccounts = this.reserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
|
|
738
808
|
? {
|
|
739
|
-
obligationFarmUserState:
|
|
740
|
-
reserveFarmState:
|
|
809
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
810
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
741
811
|
}
|
|
742
812
|
: {
|
|
743
813
|
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmCollateral)[0],
|
|
@@ -796,8 +866,8 @@ class KaminoAction {
|
|
|
796
866
|
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
797
867
|
const farmsAccounts = this.reserve.state.farmDebt.equals(web3_js_1.PublicKey.default)
|
|
798
868
|
? {
|
|
799
|
-
obligationFarmUserState:
|
|
800
|
-
reserveFarmState:
|
|
869
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
870
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
801
871
|
}
|
|
802
872
|
: {
|
|
803
873
|
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
@@ -887,8 +957,8 @@ class KaminoAction {
|
|
|
887
957
|
async addDepositAndBorrowIxV2() {
|
|
888
958
|
const collateralFarmsAccounts = this.reserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
|
|
889
959
|
? {
|
|
890
|
-
obligationFarmUserState:
|
|
891
|
-
reserveFarmState:
|
|
960
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
961
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
892
962
|
}
|
|
893
963
|
: {
|
|
894
964
|
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmCollateral)[0],
|
|
@@ -936,8 +1006,8 @@ class KaminoAction {
|
|
|
936
1006
|
});
|
|
937
1007
|
const debtFarmsAccounts = this.outflowReserve.state.farmDebt.equals(web3_js_1.PublicKey.default)
|
|
938
1008
|
? {
|
|
939
|
-
obligationFarmUserState:
|
|
940
|
-
reserveFarmState:
|
|
1009
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
1010
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
941
1011
|
}
|
|
942
1012
|
: {
|
|
943
1013
|
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.outflowReserve.state.farmDebt)[0],
|
|
@@ -1025,8 +1095,8 @@ class KaminoAction {
|
|
|
1025
1095
|
});
|
|
1026
1096
|
const debtFarmsAccounts = this.reserve.state.farmDebt.equals(web3_js_1.PublicKey.default)
|
|
1027
1097
|
? {
|
|
1028
|
-
obligationFarmUserState:
|
|
1029
|
-
reserveFarmState:
|
|
1098
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
1099
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
1030
1100
|
}
|
|
1031
1101
|
: {
|
|
1032
1102
|
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
@@ -1063,8 +1133,8 @@ class KaminoAction {
|
|
|
1063
1133
|
}
|
|
1064
1134
|
const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
|
|
1065
1135
|
? {
|
|
1066
|
-
obligationFarmUserState:
|
|
1067
|
-
reserveFarmState:
|
|
1136
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
1137
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
1068
1138
|
}
|
|
1069
1139
|
: {
|
|
1070
1140
|
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.outflowReserve.state.farmCollateral)[0],
|
|
@@ -1152,8 +1222,8 @@ class KaminoAction {
|
|
|
1152
1222
|
});
|
|
1153
1223
|
const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
|
|
1154
1224
|
? {
|
|
1155
|
-
obligationFarmUserState:
|
|
1156
|
-
reserveFarmState:
|
|
1225
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
1226
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
1157
1227
|
}
|
|
1158
1228
|
: {
|
|
1159
1229
|
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.outflowReserve.state.farmCollateral)[0],
|
|
@@ -1161,8 +1231,8 @@ class KaminoAction {
|
|
|
1161
1231
|
};
|
|
1162
1232
|
const debtFarmsAccounts = this.reserve.state.farmDebt.equals(web3_js_1.PublicKey.default)
|
|
1163
1233
|
? {
|
|
1164
|
-
obligationFarmUserState:
|
|
1165
|
-
reserveFarmState:
|
|
1234
|
+
obligationFarmUserState: lib_1.PROGRAM_ID,
|
|
1235
|
+
reserveFarmState: lib_1.PROGRAM_ID,
|
|
1166
1236
|
}
|
|
1167
1237
|
: {
|
|
1168
1238
|
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
@@ -1451,7 +1521,7 @@ class KaminoAction {
|
|
|
1451
1521
|
}
|
|
1452
1522
|
}
|
|
1453
1523
|
}
|
|
1454
|
-
async addSupportIxs(action, includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs,
|
|
1524
|
+
async addSupportIxs(action, includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, createLookupTable, twoTokenAction = false, overrideElevationGroupRequest) {
|
|
1455
1525
|
if (!['mint', 'redeem'].includes(action)) {
|
|
1456
1526
|
const [, ownerUserMetadata] = await this.kaminoMarket.getUserMetadata(this.owner);
|
|
1457
1527
|
if (!ownerUserMetadata && includeUserMetadata) {
|
|
@@ -1464,20 +1534,16 @@ class KaminoAction {
|
|
|
1464
1534
|
}
|
|
1465
1535
|
this.addInitUserMetadataIxs(lookupTable);
|
|
1466
1536
|
}
|
|
1537
|
+
if (['borrow', 'withdrawReferrerFees'].includes(action)) {
|
|
1538
|
+
await this.addInitReferrerTokenStateIx(this.reserve);
|
|
1539
|
+
}
|
|
1540
|
+
// depositAndBorrow
|
|
1541
|
+
if (action === 'deposit' && this.outflowReserve) {
|
|
1542
|
+
await this.addInitReferrerTokenStateIx(this.outflowReserve);
|
|
1543
|
+
}
|
|
1467
1544
|
await this.addInitObligationIxs();
|
|
1468
1545
|
}
|
|
1469
1546
|
await this.addSupportIxsWithoutInitObligation(action, includeAtaIxns, useV2Ixs, 'setup', requestElevationGroup, addInitObligationForFarm, twoTokenAction, overrideElevationGroupRequest);
|
|
1470
|
-
const allReserves = new utils_1.PublicKeySet([
|
|
1471
|
-
...this.depositReserves,
|
|
1472
|
-
...this.borrowReserves,
|
|
1473
|
-
this.reserve.address,
|
|
1474
|
-
...(this.outflowReserve ? [this.outflowReserve.address] : []),
|
|
1475
|
-
...(this.preLoadedDepositReservesSameTx ? this.preLoadedDepositReservesSameTx : []),
|
|
1476
|
-
]).toArray();
|
|
1477
|
-
const tokenIds = (0, market_1.getTokenIdsForScopeRefresh)(this.kaminoMarket, allReserves);
|
|
1478
|
-
if (tokenIds.length > 0 && scopeRefreshConfig) {
|
|
1479
|
-
await this.addScopeRefreshIxs(scopeRefreshConfig.scope, tokenIds, scopeRefreshConfig.scopeFeed);
|
|
1480
|
-
}
|
|
1481
1547
|
}
|
|
1482
1548
|
static optionalAccount(pubkey, programId = lib_1.PROGRAM_ID) {
|
|
1483
1549
|
if ((0, utils_1.isNotNullPubkey)(pubkey)) {
|
|
@@ -1770,18 +1836,25 @@ class KaminoAction {
|
|
|
1770
1836
|
this.setupIxs.push(initUserMetadataIx);
|
|
1771
1837
|
this.setupIxsLabels.push(`initUserMetadata[${userMetadataAddress.toString()}]`);
|
|
1772
1838
|
}
|
|
1773
|
-
addInitReferrerTokenStateIx(reserve
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1839
|
+
async addInitReferrerTokenStateIx(reserve) {
|
|
1840
|
+
if (this.referrer.equals(web3_js_1.PublicKey.default)) {
|
|
1841
|
+
return;
|
|
1842
|
+
}
|
|
1843
|
+
const referrerTokenState = (0, utils_1.referrerTokenStatePda)(this.referrer, reserve.address, this.kaminoMarket.programId)[0];
|
|
1844
|
+
const account = await this.kaminoMarket.getConnection().getAccountInfo(referrerTokenState);
|
|
1845
|
+
if (!account) {
|
|
1846
|
+
const initReferrerTokenStateIx = (0, instructions_1.initReferrerTokenState)({
|
|
1847
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1848
|
+
payer: this.owner,
|
|
1849
|
+
reserve: reserve.address,
|
|
1850
|
+
referrer: this.referrer,
|
|
1851
|
+
referrerTokenState,
|
|
1852
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
1853
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
1854
|
+
}, this.kaminoMarket.programId);
|
|
1855
|
+
this.setupIxs.unshift(initReferrerTokenStateIx);
|
|
1856
|
+
this.setupIxsLabels.unshift(`InitReferrerTokenState[${referrerTokenState.toString()} res=${reserve.address}]`);
|
|
1857
|
+
}
|
|
1785
1858
|
}
|
|
1786
1859
|
addWithdrawReferrerFeesIxs() {
|
|
1787
1860
|
const referrerTokenStateAddress = (0, utils_1.referrerTokenStatePda)(this.owner, this.reserve.address, this.kaminoMarket.programId)[0];
|