@kamino-finance/klend-sdk 5.11.6-beta.0 → 5.11.7
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 +27 -35
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +198 -344
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/index.d.ts +1 -0
- package/dist/classes/index.d.ts.map +1 -1
- package/dist/classes/index.js +1 -0
- package/dist/classes/index.js.map +1 -1
- package/dist/classes/manager.d.ts +6 -1
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +16 -1
- 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 +30 -16
- package/dist/classes/market.js.map +1 -1
- package/dist/classes/obligation.d.ts +2 -0
- package/dist/classes/obligation.d.ts.map +1 -1
- package/dist/classes/obligation.js +5 -0
- package/dist/classes/obligation.js.map +1 -1
- package/dist/classes/types.d.ts.map +1 -1
- package/dist/classes/vault.d.ts +1 -0
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +26 -20
- package/dist/classes/vault.js.map +1 -1
- package/dist/client_kamino_manager.d.ts.map +1 -1
- package/dist/client_kamino_manager.js +11 -0
- package/dist/client_kamino_manager.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts +6 -3
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js +13 -7
- package/dist/idl_codegen_kamino_vault/accounts/VaultState.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/errors/custom.d.ts +25 -1
- package/dist/idl_codegen_kamino_vault/errors/custom.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/errors/custom.js +43 -1
- 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 +1 -0
- package/dist/idl_codegen_kamino_vault/instructions/initVault.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/instructions/initVault.js +1 -0
- 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 +13 -0
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.js +25 -1
- 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 +10 -8
- 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 +11 -6
- package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
- package/dist/leverage/operations.d.ts +9 -7
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +78 -66
- 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/accountListing.d.ts +4 -4
- package/dist/utils/accountListing.d.ts.map +1 -1
- package/dist/utils/accountListing.js +3 -3
- package/dist/utils/accountListing.js.map +1 -1
- package/dist/utils/constants.d.ts +6 -0
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/constants.js +7 -1
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/managerTypes.d.ts.map +1 -1
- package/dist/utils/managerTypes.js +7 -52
- 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 +4 -3
- package/dist/utils/oracle.js.map +1 -1
- package/package.json +2 -2
- package/src/classes/action.ts +225 -400
- package/src/classes/index.ts +1 -0
- package/src/classes/manager.ts +27 -1
- package/src/classes/market.ts +34 -25
- package/src/classes/obligation.ts +6 -0
- package/src/classes/types.ts +1 -1
- package/src/classes/vault.ts +28 -24
- package/src/client.ts +40 -9
- package/src/client_kamino_manager.ts +15 -0
- package/src/idl_codegen_kamino_vault/accounts/VaultState.ts +17 -9
- package/src/idl_codegen_kamino_vault/errors/custom.ts +42 -0
- package/src/idl_codegen_kamino_vault/instructions/giveUpPendingFees.ts +2 -2
- package/src/idl_codegen_kamino_vault/instructions/initVault.ts +2 -0
- 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 +30 -0
- package/src/idl_codegen_kamino_vault/types/index.ts +2 -0
- package/src/idl_kamino_vault.json +35 -8
- package/src/lending_operations/repay_with_collateral_operations.ts +15 -11
- package/src/lending_operations/swap_collateral_operations.ts +19 -7
- package/src/leverage/operations.ts +114 -66
- package/src/leverage/types.ts +4 -4
- package/src/utils/ObligationType.ts +1 -1
- package/src/utils/accountListing.ts +11 -7
- package/src/utils/constants.ts +7 -0
- package/src/utils/managerTypes.ts +10 -52
- package/src/utils/oracle.ts +7 -6
package/dist/classes/action.js
CHANGED
|
@@ -10,13 +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");
|
|
13
14
|
const obligation_1 = require("./obligation");
|
|
14
15
|
const types_1 = require("../idl_codegen/types");
|
|
15
16
|
const farms_sdk_1 = require("@kamino-finance/farms-sdk");
|
|
16
17
|
const ObligationType_1 = require("../utils/ObligationType");
|
|
17
18
|
const lib_1 = require("../lib");
|
|
18
|
-
const scope_sdk_1 = require("@kamino-finance/scope-sdk");
|
|
19
|
-
const SOL_PADDING_FOR_INTEREST = new bn_js_1.default('1000000');
|
|
20
19
|
class KaminoAction {
|
|
21
20
|
kaminoMarket;
|
|
22
21
|
reserve;
|
|
@@ -25,9 +24,6 @@ class KaminoAction {
|
|
|
25
24
|
payer;
|
|
26
25
|
obligation = null;
|
|
27
26
|
referrer;
|
|
28
|
-
userTokenAccountAddress;
|
|
29
|
-
userCollateralAccountAddress;
|
|
30
|
-
additionalTokenAccountAddress;
|
|
31
27
|
/**
|
|
32
28
|
* Null unless the obligation is not passed
|
|
33
29
|
*/
|
|
@@ -47,17 +43,13 @@ class KaminoAction {
|
|
|
47
43
|
lendingIxsLabels;
|
|
48
44
|
cleanupIxs;
|
|
49
45
|
cleanupIxsLabels;
|
|
50
|
-
preTxnIxs;
|
|
51
|
-
preTxnIxsLabels;
|
|
52
|
-
postTxnIxs;
|
|
53
|
-
postTxnIxsLabels;
|
|
54
46
|
refreshFarmsCleanupTxnIxs;
|
|
55
47
|
refreshFarmsCleanupTxnIxsLabels;
|
|
56
48
|
depositReserves;
|
|
57
49
|
borrowReserves;
|
|
58
50
|
preLoadedDepositReservesSameTx;
|
|
59
51
|
currentSlot;
|
|
60
|
-
constructor(kaminoMarket, owner, obligation,
|
|
52
|
+
constructor(kaminoMarket, owner, obligation, mint, positions, amount, depositReserves, borrowReserves, reserveState, currentSlot, secondaryMint, outflowReserveState, outflowAmount, referrer, payer) {
|
|
61
53
|
if (obligation instanceof obligation_1.KaminoObligation) {
|
|
62
54
|
this.obligation = obligation;
|
|
63
55
|
}
|
|
@@ -70,8 +62,6 @@ class KaminoAction {
|
|
|
70
62
|
this.amount = new bn_js_1.default(amount);
|
|
71
63
|
this.mint = mint;
|
|
72
64
|
this.positions = positions;
|
|
73
|
-
this.userTokenAccountAddress = userTokenAccountAddress;
|
|
74
|
-
this.userCollateralAccountAddress = userCollateralAccountAddress;
|
|
75
65
|
this.computeBudgetIxs = [];
|
|
76
66
|
this.computeBudgetIxsLabels = [];
|
|
77
67
|
this.setupIxs = [];
|
|
@@ -82,15 +72,10 @@ class KaminoAction {
|
|
|
82
72
|
this.lendingIxsLabels = [];
|
|
83
73
|
this.cleanupIxs = [];
|
|
84
74
|
this.cleanupIxsLabels = [];
|
|
85
|
-
this.preTxnIxs = [];
|
|
86
|
-
this.preTxnIxsLabels = [];
|
|
87
|
-
this.postTxnIxs = [];
|
|
88
|
-
this.postTxnIxsLabels = [];
|
|
89
75
|
this.refreshFarmsCleanupTxnIxs = [];
|
|
90
76
|
this.refreshFarmsCleanupTxnIxsLabels = [];
|
|
91
77
|
this.depositReserves = depositReserves;
|
|
92
78
|
this.borrowReserves = borrowReserves;
|
|
93
|
-
this.additionalTokenAccountAddress = additionalTokenAccountAddress;
|
|
94
79
|
this.secondaryMint = secondaryMint;
|
|
95
80
|
this.reserve = reserveState;
|
|
96
81
|
this.outflowReserve = outflowReserveState;
|
|
@@ -104,10 +89,9 @@ class KaminoAction {
|
|
|
104
89
|
if (reserve === undefined) {
|
|
105
90
|
throw new Error(`Reserve ${mint} not found in market ${kaminoMarket.getAddress().toBase58()}`);
|
|
106
91
|
}
|
|
107
|
-
const { userTokenAccountAddress, userCollateralAccountAddress } = KaminoAction.getUserAccountAddresses(payer ?? owner, reserve.state);
|
|
108
92
|
const { kaminoObligation, depositReserves, borrowReserves, distinctReserveCount } = await KaminoAction.loadObligation(action, kaminoMarket, owner, reserve.address, obligation);
|
|
109
93
|
const referrerKey = await this.getReferrerKey(kaminoMarket, owner, kaminoObligation, referrer);
|
|
110
|
-
return new KaminoAction(kaminoMarket, owner, kaminoObligation || obligation,
|
|
94
|
+
return new KaminoAction(kaminoMarket, owner, kaminoObligation || obligation, mint, distinctReserveCount, amount, depositReserves, borrowReserves, reserve, currentSlot, undefined, undefined, undefined, referrerKey, payer);
|
|
111
95
|
}
|
|
112
96
|
static getUserAccountAddresses(owner, reserve) {
|
|
113
97
|
const userTokenAccountAddress = (0, utils_1.getAssociatedTokenAddress)(reserve.liquidity.mintPubkey, owner, true, reserve.liquidity.tokenProgram, spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID);
|
|
@@ -180,27 +164,18 @@ class KaminoAction {
|
|
|
180
164
|
axn.addRequestElevationIx(elevationGroup, 'setup');
|
|
181
165
|
return axn;
|
|
182
166
|
}
|
|
183
|
-
static async buildDepositTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
167
|
+
static async buildDepositTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
184
168
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
185
169
|
requestElevationGroup = false, // to be requested *before* the deposit
|
|
186
170
|
includeUserMetadata = true, // if true it includes user metadata
|
|
187
|
-
createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0,
|
|
171
|
+
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
|
|
188
172
|
) {
|
|
189
173
|
const axn = await KaminoAction.initialize('deposit', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
190
174
|
const addInitObligationForFarm = true;
|
|
191
175
|
if (extraComputeBudget > 0) {
|
|
192
176
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
193
177
|
}
|
|
194
|
-
|
|
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);
|
|
178
|
+
await axn.addSupportIxs('deposit', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, scopeRefreshConfig, createLookupTable, undefined, overrideElevationGroupRequest);
|
|
204
179
|
if (useV2Ixs) {
|
|
205
180
|
axn.addDepositIxV2();
|
|
206
181
|
}
|
|
@@ -210,54 +185,30 @@ class KaminoAction {
|
|
|
210
185
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
211
186
|
return axn;
|
|
212
187
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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({
|
|
188
|
+
async addScopeRefreshIxs(scope, tokens, feed = 'hubble') {
|
|
189
|
+
this.setupIxsLabels.unshift(`refreshScopePrices`);
|
|
190
|
+
this.setupIxs.unshift(await scope.refreshPriceListIx({
|
|
238
191
|
feed: feed,
|
|
239
192
|
}, tokens));
|
|
240
193
|
}
|
|
241
|
-
static async buildBorrowTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
194
|
+
static async buildBorrowTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
242
195
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
243
196
|
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
|
|
244
|
-
createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0,
|
|
197
|
+
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
|
|
245
198
|
) {
|
|
246
199
|
const axn = await KaminoAction.initialize('borrow', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
247
200
|
const addInitObligationForFarm = true;
|
|
248
201
|
if (extraComputeBudget > 0) {
|
|
249
202
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
250
203
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
258
|
-
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
204
|
+
if (!axn.referrer.equals(web3_js_1.PublicKey.default)) {
|
|
205
|
+
const referrerTokenState = (0, utils_1.referrerTokenStatePda)(axn.referrer, axn.reserve.address, axn.kaminoMarket.programId)[0];
|
|
206
|
+
const account = await axn.kaminoMarket.getConnection().getAccountInfo(referrerTokenState);
|
|
207
|
+
if (!account) {
|
|
208
|
+
axn.addInitReferrerTokenStateIx(axn.reserve, referrerTokenState);
|
|
209
|
+
}
|
|
259
210
|
}
|
|
260
|
-
await axn.addSupportIxs('borrow', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, createLookupTable, undefined, overrideElevationGroupRequest);
|
|
211
|
+
await axn.addSupportIxs('borrow', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, scopeRefreshConfig, createLookupTable, undefined, overrideElevationGroupRequest);
|
|
261
212
|
if (useV2Ixs) {
|
|
262
213
|
axn.addBorrowIxV2();
|
|
263
214
|
}
|
|
@@ -267,69 +218,42 @@ class KaminoAction {
|
|
|
267
218
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
268
219
|
return axn;
|
|
269
220
|
}
|
|
270
|
-
static async buildDepositReserveLiquidityTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
221
|
+
static async buildDepositReserveLiquidityTxns(kaminoMarket, amount, mint, owner, obligation, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
271
222
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas
|
|
272
|
-
requestElevationGroup = false, referrer = web3_js_1.PublicKey.default, currentSlot = 0
|
|
223
|
+
requestElevationGroup = false, referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
|
|
273
224
|
const axn = await KaminoAction.initialize('mint', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
274
225
|
const addInitObligationForFarm = true;
|
|
275
226
|
if (extraComputeBudget > 0) {
|
|
276
227
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
277
228
|
}
|
|
278
|
-
|
|
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);
|
|
229
|
+
await axn.addSupportIxs('mint', includeAtaIxns, requestElevationGroup, false, addInitObligationForFarm, false, scopeRefreshConfig, false);
|
|
288
230
|
axn.addDepositReserveLiquidityIx();
|
|
289
231
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
290
232
|
return axn;
|
|
291
233
|
}
|
|
292
|
-
static async buildRedeemReserveCollateralTxns(kaminoMarket, amount, mint, owner, obligation, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
234
|
+
static async buildRedeemReserveCollateralTxns(kaminoMarket, amount, mint, owner, obligation, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
293
235
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas
|
|
294
|
-
requestElevationGroup = false, referrer = web3_js_1.PublicKey.default, currentSlot = 0
|
|
236
|
+
requestElevationGroup = false, referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
|
|
295
237
|
const axn = await KaminoAction.initialize('redeem', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
296
238
|
const addInitObligationForFarm = true;
|
|
297
239
|
if (extraComputeBudget > 0) {
|
|
298
240
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
299
241
|
}
|
|
300
|
-
|
|
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);
|
|
242
|
+
await axn.addSupportIxs('redeem', includeAtaIxns, requestElevationGroup, false, addInitObligationForFarm, false, scopeRefreshConfig, false);
|
|
310
243
|
axn.addRedeemReserveCollateralIx();
|
|
311
244
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
312
245
|
return axn;
|
|
313
246
|
}
|
|
314
|
-
static async buildDepositObligationCollateralTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
247
|
+
static async buildDepositObligationCollateralTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
315
248
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas
|
|
316
249
|
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
|
|
317
|
-
createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0
|
|
250
|
+
createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
|
|
318
251
|
const axn = await KaminoAction.initialize('depositCollateral', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
319
252
|
const addInitObligationForFarm = true;
|
|
320
253
|
if (extraComputeBudget > 0) {
|
|
321
254
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
322
255
|
}
|
|
323
|
-
|
|
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);
|
|
256
|
+
await axn.addSupportIxs('depositCollateral', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, scopeRefreshConfig, createLookupTable);
|
|
333
257
|
if (useV2Ixs) {
|
|
334
258
|
axn.addDepositObligationCollateralIxV2();
|
|
335
259
|
}
|
|
@@ -339,10 +263,10 @@ class KaminoAction {
|
|
|
339
263
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
340
264
|
return axn;
|
|
341
265
|
}
|
|
342
|
-
static async buildDepositAndBorrowTxns(kaminoMarket, depositAmount, depositMint, borrowAmount, borrowMint, payer, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
266
|
+
static async buildDepositAndBorrowTxns(kaminoMarket, depositAmount, depositMint, borrowAmount, borrowMint, payer, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
343
267
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
344
268
|
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
|
|
345
|
-
createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0
|
|
269
|
+
createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0) {
|
|
346
270
|
const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'depositAndBorrow', depositAmount, depositMint, borrowMint, payer, payer, obligation, borrowAmount, referrer, currentSlot);
|
|
347
271
|
const addInitObligationForFarmForDeposit = true;
|
|
348
272
|
const addInitObligationForFarmForBorrow = false;
|
|
@@ -350,17 +274,14 @@ class KaminoAction {
|
|
|
350
274
|
if (extraComputeBudget > 0) {
|
|
351
275
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
352
276
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
const tokenIds = axn.getTokenIdsForScopeRefresh(kaminoMarket, allReserves);
|
|
360
|
-
if (tokenIds.length > 0 && scopeRefresh.includeScopeRefresh) {
|
|
361
|
-
await axn.addScopeRefreshIxs(tokenIds, scopeRefresh.scopeFeed);
|
|
277
|
+
if (!axn.referrer.equals(web3_js_1.PublicKey.default)) {
|
|
278
|
+
const referrerTokenState = (0, utils_1.referrerTokenStatePda)(axn.referrer, axn.outflowReserve.address, axn.kaminoMarket.programId)[0];
|
|
279
|
+
const account = await axn.kaminoMarket.getConnection().getAccountInfo(referrerTokenState);
|
|
280
|
+
if (!account) {
|
|
281
|
+
axn.addInitReferrerTokenStateIx(axn.outflowReserve, referrerTokenState);
|
|
282
|
+
}
|
|
362
283
|
}
|
|
363
|
-
await axn.addSupportIxs('deposit', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForDeposit, useV2Ixs, createLookupTable, twoTokenAction);
|
|
284
|
+
await axn.addSupportIxs('deposit', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForDeposit, useV2Ixs, undefined, createLookupTable, twoTokenAction);
|
|
364
285
|
if (useV2Ixs) {
|
|
365
286
|
await axn.addDepositAndBorrowIxV2();
|
|
366
287
|
}
|
|
@@ -369,12 +290,24 @@ class KaminoAction {
|
|
|
369
290
|
}
|
|
370
291
|
await axn.addInBetweenIxs('depositAndBorrow', includeAtaIxns, requestElevationGroup, addInitObligationForFarmForBorrow, useV2Ixs);
|
|
371
292
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
293
|
+
// Create the scope refresh ixn in here to ensure it's the first ixn in the txn
|
|
294
|
+
const allReserves = new utils_1.PublicKeySet([
|
|
295
|
+
...axn.depositReserves,
|
|
296
|
+
...axn.borrowReserves,
|
|
297
|
+
axn.reserve.address,
|
|
298
|
+
...(axn.outflowReserve ? [axn.outflowReserve.address] : []),
|
|
299
|
+
...(axn.preLoadedDepositReservesSameTx ? axn.preLoadedDepositReservesSameTx : []),
|
|
300
|
+
]).toArray();
|
|
301
|
+
const tokenIds = (0, market_1.getTokenIdsForScopeRefresh)(axn.kaminoMarket, allReserves);
|
|
302
|
+
if (tokenIds.length > 0 && scopeRefreshConfig) {
|
|
303
|
+
await axn.addScopeRefreshIxs(scopeRefreshConfig.scope, tokenIds, scopeRefreshConfig.scopeFeed);
|
|
304
|
+
}
|
|
372
305
|
return axn;
|
|
373
306
|
}
|
|
374
|
-
static async buildRepayAndWithdrawTxns(kaminoMarket, repayAmount, repayMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
307
|
+
static async buildRepayAndWithdrawTxns(kaminoMarket, repayAmount, repayMint, withdrawAmount, withdrawMint, payer, currentSlot, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
375
308
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
376
309
|
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata,
|
|
377
|
-
createLookupTable = true, referrer = web3_js_1.PublicKey.default
|
|
310
|
+
createLookupTable = true, referrer = web3_js_1.PublicKey.default) {
|
|
378
311
|
const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'repayAndWithdraw', repayAmount, repayMint, withdrawMint, payer, payer, obligation, withdrawAmount, referrer, currentSlot);
|
|
379
312
|
const addInitObligationForFarmForRepay = true;
|
|
380
313
|
const addInitObligationForFarmForWithdraw = false;
|
|
@@ -382,17 +315,7 @@ class KaminoAction {
|
|
|
382
315
|
if (extraComputeBudget > 0) {
|
|
383
316
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
384
317
|
}
|
|
385
|
-
|
|
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);
|
|
318
|
+
await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarmForRepay, useV2Ixs, undefined, createLookupTable, twoTokenAction);
|
|
396
319
|
const withdrawCollateralAmount = axn.getWithdrawCollateralAmount(axn.outflowReserve, axn.outflowAmount);
|
|
397
320
|
if (useV2Ixs) {
|
|
398
321
|
await axn.addRepayAndWithdrawIxsV2(withdrawCollateralAmount);
|
|
@@ -402,13 +325,25 @@ class KaminoAction {
|
|
|
402
325
|
}
|
|
403
326
|
await axn.addInBetweenIxs('repayAndWithdraw', includeAtaIxns, requestElevationGroup, addInitObligationForFarmForWithdraw, useV2Ixs);
|
|
404
327
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
328
|
+
// Create the scope refresh ixn in here to ensure it's the first ixn in the txn
|
|
329
|
+
const allReserves = new utils_1.PublicKeySet([
|
|
330
|
+
...axn.depositReserves,
|
|
331
|
+
...axn.borrowReserves,
|
|
332
|
+
axn.reserve.address,
|
|
333
|
+
...(axn.outflowReserve ? [axn.outflowReserve.address] : []),
|
|
334
|
+
...(axn.preLoadedDepositReservesSameTx ? axn.preLoadedDepositReservesSameTx : []),
|
|
335
|
+
]).toArray();
|
|
336
|
+
const tokenIds = (0, market_1.getTokenIdsForScopeRefresh)(axn.kaminoMarket, allReserves);
|
|
337
|
+
if (tokenIds.length > 0 && scopeRefreshConfig) {
|
|
338
|
+
await axn.addScopeRefreshIxs(scopeRefreshConfig.scope, tokenIds, scopeRefreshConfig.scopeFeed);
|
|
339
|
+
}
|
|
405
340
|
return axn;
|
|
406
341
|
}
|
|
407
|
-
static async buildWithdrawTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
342
|
+
static async buildWithdrawTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
408
343
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas,
|
|
409
344
|
requestElevationGroup = false, // to be requested *after* the withdraw
|
|
410
345
|
includeUserMetadata = true, // if true it includes user metadata
|
|
411
|
-
createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0,
|
|
346
|
+
createLookupTable = true, referrer = web3_js_1.PublicKey.default, currentSlot = 0, overrideElevationGroupRequest,
|
|
412
347
|
// Optional customizations which may be needed if the obligation was mutated by some previous ixn.
|
|
413
348
|
obligationCustomizations) {
|
|
414
349
|
const axn = await KaminoAction.initialize('withdraw', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot);
|
|
@@ -417,16 +352,7 @@ class KaminoAction {
|
|
|
417
352
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
418
353
|
}
|
|
419
354
|
axn.depositReserves.push(...(obligationCustomizations?.addedDepositReserves || []));
|
|
420
|
-
|
|
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);
|
|
355
|
+
await axn.addSupportIxs('withdraw', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, scopeRefreshConfig, createLookupTable, false, overrideElevationGroupRequest);
|
|
430
356
|
const collateralAmount = axn.getWithdrawCollateralAmount(axn.reserve, axn.amount);
|
|
431
357
|
if (useV2Ixs) {
|
|
432
358
|
await axn.addWithdrawIxV2(collateralAmount);
|
|
@@ -452,22 +378,13 @@ class KaminoAction {
|
|
|
452
378
|
* @param includeUserMetadata - if true it includes user metadata
|
|
453
379
|
* @param referrer
|
|
454
380
|
*/
|
|
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
|
|
381
|
+
static async buildRepayTxns(kaminoMarket, amount, mint, owner, obligation, useV2Ixs, scopeRefreshConfig, currentSlot, payer = undefined, extraComputeBudget = 1_000_000, includeAtaIxns = true, requestElevationGroup = false, includeUserMetadata = true, createLookupTable = true, referrer = web3_js_1.PublicKey.default) {
|
|
456
382
|
const axn = await KaminoAction.initialize('repay', amount, mint, owner, kaminoMarket, obligation, referrer, currentSlot, payer);
|
|
457
383
|
const addInitObligationForFarm = true;
|
|
458
384
|
if (extraComputeBudget > 0) {
|
|
459
385
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
460
386
|
}
|
|
461
|
-
|
|
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);
|
|
387
|
+
await axn.addSupportIxs('repay', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, scopeRefreshConfig, createLookupTable);
|
|
471
388
|
if (useV2Ixs) {
|
|
472
389
|
await axn.addRepayIxV2();
|
|
473
390
|
}
|
|
@@ -477,26 +394,16 @@ class KaminoAction {
|
|
|
477
394
|
axn.addRefreshFarmsCleanupTxnIxsToCleanupIxs();
|
|
478
395
|
return axn;
|
|
479
396
|
}
|
|
480
|
-
static async buildLiquidateTxns(kaminoMarket, amount, minCollateralReceiveAmount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, useV2Ixs, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
397
|
+
static async buildLiquidateTxns(kaminoMarket, amount, minCollateralReceiveAmount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, useV2Ixs, scopeRefreshConfig, extraComputeBudget = 1_000_000, // if > 0 then adds the ixn
|
|
481
398
|
includeAtaIxns = true, // if true it includes create and close wsol and token atas, and creates all other token atas if they don't exist
|
|
482
399
|
requestElevationGroup = false, includeUserMetadata = true, // if true it includes user metadata
|
|
483
|
-
createLookupTable = true, referrer = web3_js_1.PublicKey.default, maxAllowedLtvOverridePercent = 0, currentSlot = 0
|
|
400
|
+
createLookupTable = true, referrer = web3_js_1.PublicKey.default, maxAllowedLtvOverridePercent = 0, currentSlot = 0) {
|
|
484
401
|
const axn = await KaminoAction.initializeMultiTokenAction(kaminoMarket, 'liquidate', amount, repayTokenMint, withdrawTokenMint, liquidator, obligationOwner, obligation, minCollateralReceiveAmount, referrer, currentSlot);
|
|
485
402
|
const addInitObligationForFarm = true;
|
|
486
403
|
if (extraComputeBudget > 0) {
|
|
487
404
|
axn.addComputeBudgetIxn(extraComputeBudget);
|
|
488
405
|
}
|
|
489
|
-
|
|
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);
|
|
406
|
+
await axn.addSupportIxs('liquidate', includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, scopeRefreshConfig, createLookupTable);
|
|
500
407
|
if (useV2Ixs) {
|
|
501
408
|
await axn.addLiquidateIxV2(maxAllowedLtvOverridePercent);
|
|
502
409
|
}
|
|
@@ -508,49 +415,38 @@ class KaminoAction {
|
|
|
508
415
|
}
|
|
509
416
|
static async buildWithdrawReferrerFeeTxns(owner, tokenMint, kaminoMarket, currentSlot = 0) {
|
|
510
417
|
const { axn, createAtaIxs } = await KaminoAction.initializeWithdrawReferrerFees(tokenMint, owner, kaminoMarket, currentSlot);
|
|
511
|
-
axn.
|
|
512
|
-
axn.
|
|
418
|
+
axn.setupIxs.push(...createAtaIxs);
|
|
419
|
+
axn.setupIxsLabels.push(`createAtasIxs[${axn.owner.toString()}]`);
|
|
420
|
+
if (!axn.referrer.equals(web3_js_1.PublicKey.default)) {
|
|
421
|
+
const referrerTokenState = (0, utils_1.referrerTokenStatePda)(axn.referrer, axn.reserve.address, axn.kaminoMarket.programId)[0];
|
|
422
|
+
const account = await axn.kaminoMarket.getConnection().getAccountInfo(referrerTokenState);
|
|
423
|
+
if (!account) {
|
|
424
|
+
axn.addInitReferrerTokenStateIx(axn.reserve, referrerTokenState);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
513
427
|
axn.addRefreshReserveIxs([axn.reserve.address]);
|
|
514
428
|
axn.addWithdrawReferrerFeesIxs();
|
|
515
429
|
return axn;
|
|
516
430
|
}
|
|
517
431
|
async getTransactions() {
|
|
518
|
-
|
|
519
|
-
preLendingTxn: null,
|
|
520
|
-
lendingTxn: null,
|
|
521
|
-
postLendingTxn: null,
|
|
522
|
-
};
|
|
523
|
-
if (this.preTxnIxs.length) {
|
|
524
|
-
txns.preLendingTxn = new web3_js_1.Transaction({
|
|
525
|
-
feePayer: this.owner,
|
|
526
|
-
recentBlockhash: (await this.kaminoMarket.getConnection().getLatestBlockhash()).blockhash,
|
|
527
|
-
}).add(...this.preTxnIxs);
|
|
528
|
-
}
|
|
432
|
+
let txns;
|
|
529
433
|
if (this.lendingIxs.length === 2) {
|
|
530
|
-
txns
|
|
434
|
+
txns = new web3_js_1.Transaction({
|
|
531
435
|
feePayer: this.owner,
|
|
532
436
|
recentBlockhash: (await this.kaminoMarket.getConnection().getLatestBlockhash()).blockhash,
|
|
533
437
|
}).add(...this.setupIxs, ...[this.lendingIxs[0]], ...this.inBetweenIxs, ...[this.lendingIxs[1]], ...this.cleanupIxs);
|
|
534
438
|
}
|
|
535
439
|
else {
|
|
536
|
-
txns
|
|
440
|
+
txns = new web3_js_1.Transaction({
|
|
537
441
|
feePayer: this.owner,
|
|
538
442
|
recentBlockhash: (await this.kaminoMarket.getConnection().getLatestBlockhash()).blockhash,
|
|
539
443
|
}).add(...this.setupIxs, ...this.lendingIxs, ...this.cleanupIxs);
|
|
540
444
|
}
|
|
541
|
-
if (this.postTxnIxs.length) {
|
|
542
|
-
txns.postLendingTxn = new web3_js_1.Transaction({
|
|
543
|
-
feePayer: this.owner,
|
|
544
|
-
recentBlockhash: (await this.kaminoMarket.getConnection().getLatestBlockhash()).blockhash,
|
|
545
|
-
}).add(...this.postTxnIxs);
|
|
546
|
-
}
|
|
547
445
|
return txns;
|
|
548
446
|
}
|
|
549
447
|
async sendTransactions(sendTransaction) {
|
|
550
448
|
const txns = await this.getTransactions();
|
|
551
|
-
await this.sendSingleTransaction(txns
|
|
552
|
-
const signature = await this.sendSingleTransaction(txns.lendingTxn, sendTransaction);
|
|
553
|
-
await this.sendSingleTransaction(txns.postLendingTxn, sendTransaction);
|
|
449
|
+
const signature = await this.sendSingleTransaction(txns, sendTransaction);
|
|
554
450
|
return signature;
|
|
555
451
|
}
|
|
556
452
|
async sendSingleTransaction(txn, sendTransaction) {
|
|
@@ -562,9 +458,7 @@ class KaminoAction {
|
|
|
562
458
|
}
|
|
563
459
|
async simulateTransactions(sendTransaction) {
|
|
564
460
|
const txns = await this.getTransactions();
|
|
565
|
-
await this.simulateSingleTransaction(txns
|
|
566
|
-
const signature = await this.simulateSingleTransaction(txns.lendingTxn, sendTransaction);
|
|
567
|
-
await this.simulateSingleTransaction(txns.postLendingTxn, sendTransaction);
|
|
461
|
+
const signature = await this.simulateSingleTransaction(txns, sendTransaction);
|
|
568
462
|
return signature;
|
|
569
463
|
}
|
|
570
464
|
async simulateSingleTransaction(txn, sendTransaction) {
|
|
@@ -584,8 +478,8 @@ class KaminoAction {
|
|
|
584
478
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
585
479
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
586
480
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
587
|
-
userSourceLiquidity: this.
|
|
588
|
-
userDestinationCollateral: this.
|
|
481
|
+
userSourceLiquidity: this.getUserTokenAccountAddress(this.reserve),
|
|
482
|
+
userDestinationCollateral: this.getUserCollateralAccountAddress(this.reserve),
|
|
589
483
|
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
590
484
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
591
485
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
@@ -603,8 +497,8 @@ class KaminoAction {
|
|
|
603
497
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
604
498
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
605
499
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
606
|
-
userSourceCollateral: this.
|
|
607
|
-
userDestinationLiquidity: this.
|
|
500
|
+
userSourceCollateral: this.getUserCollateralAccountAddress(this.reserve),
|
|
501
|
+
userDestinationLiquidity: this.getUserTokenAccountAddress(this.reserve),
|
|
608
502
|
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
609
503
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
610
504
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
@@ -625,7 +519,7 @@ class KaminoAction {
|
|
|
625
519
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
626
520
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
627
521
|
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
628
|
-
userSourceLiquidity: this.
|
|
522
|
+
userSourceLiquidity: this.getUserTokenAccountAddress(this.reserve),
|
|
629
523
|
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
630
524
|
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
631
525
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
@@ -635,8 +529,8 @@ class KaminoAction {
|
|
|
635
529
|
addDepositIxV2() {
|
|
636
530
|
const farmsAccounts = this.reserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
|
|
637
531
|
? {
|
|
638
|
-
obligationFarmUserState:
|
|
639
|
-
reserveFarmState:
|
|
532
|
+
obligationFarmUserState: this.kaminoMarket.programId,
|
|
533
|
+
reserveFarmState: this.kaminoMarket.programId,
|
|
640
534
|
}
|
|
641
535
|
: {
|
|
642
536
|
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmCollateral)[0],
|
|
@@ -656,7 +550,7 @@ class KaminoAction {
|
|
|
656
550
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
657
551
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
658
552
|
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
659
|
-
userSourceLiquidity: this.
|
|
553
|
+
userSourceLiquidity: this.getUserTokenAccountAddress(this.reserve),
|
|
660
554
|
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
661
555
|
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
662
556
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
@@ -677,7 +571,7 @@ class KaminoAction {
|
|
|
677
571
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
678
572
|
depositReserve: this.reserve.address,
|
|
679
573
|
reserveDestinationCollateral: this.reserve.state.collateral.supplyVault,
|
|
680
|
-
userSourceCollateral: this.
|
|
574
|
+
userSourceCollateral: this.getUserCollateralAccountAddress(this.reserve),
|
|
681
575
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
682
576
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
683
577
|
}, this.kaminoMarket.programId));
|
|
@@ -685,8 +579,8 @@ class KaminoAction {
|
|
|
685
579
|
addDepositObligationCollateralIxV2() {
|
|
686
580
|
const farmsAccounts = this.reserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
|
|
687
581
|
? {
|
|
688
|
-
obligationFarmUserState:
|
|
689
|
-
reserveFarmState:
|
|
582
|
+
obligationFarmUserState: this.kaminoMarket.programId,
|
|
583
|
+
reserveFarmState: this.kaminoMarket.programId,
|
|
690
584
|
}
|
|
691
585
|
: {
|
|
692
586
|
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmCollateral)[0],
|
|
@@ -702,7 +596,7 @@ class KaminoAction {
|
|
|
702
596
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
703
597
|
depositReserve: this.reserve.address,
|
|
704
598
|
reserveDestinationCollateral: this.reserve.state.collateral.supplyVault,
|
|
705
|
-
userSourceCollateral: this.
|
|
599
|
+
userSourceCollateral: this.getUserCollateralAccountAddress(this.reserve),
|
|
706
600
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
707
601
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
708
602
|
},
|
|
@@ -728,7 +622,7 @@ class KaminoAction {
|
|
|
728
622
|
borrowReserve: this.reserve.address,
|
|
729
623
|
borrowReserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
730
624
|
reserveSourceLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
731
|
-
userDestinationLiquidity: this.
|
|
625
|
+
userDestinationLiquidity: this.getUserTokenAccountAddress(this.reserve),
|
|
732
626
|
borrowReserveLiquidityFeeReceiver: this.reserve.state.liquidity.feeVault,
|
|
733
627
|
referrerTokenState: (0, utils_1.referrerTokenStatePda)(this.referrer, this.reserve.address, this.kaminoMarket.programId)[0],
|
|
734
628
|
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
@@ -748,8 +642,8 @@ class KaminoAction {
|
|
|
748
642
|
});
|
|
749
643
|
const farmsAccounts = this.reserve.state.farmDebt.equals(web3_js_1.PublicKey.default)
|
|
750
644
|
? {
|
|
751
|
-
obligationFarmUserState:
|
|
752
|
-
reserveFarmState:
|
|
645
|
+
obligationFarmUserState: this.kaminoMarket.programId,
|
|
646
|
+
reserveFarmState: this.kaminoMarket.programId,
|
|
753
647
|
}
|
|
754
648
|
: {
|
|
755
649
|
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
@@ -766,7 +660,7 @@ class KaminoAction {
|
|
|
766
660
|
borrowReserve: this.reserve.address,
|
|
767
661
|
borrowReserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
768
662
|
reserveSourceLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
769
|
-
userDestinationLiquidity: this.
|
|
663
|
+
userDestinationLiquidity: this.getUserTokenAccountAddress(this.reserve),
|
|
770
664
|
borrowReserveLiquidityFeeReceiver: this.reserve.state.liquidity.feeVault,
|
|
771
665
|
referrerTokenState: (0, utils_1.referrerTokenStatePda)(this.referrer, this.reserve.address, this.kaminoMarket.programId)[0],
|
|
772
666
|
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
@@ -796,7 +690,7 @@ class KaminoAction {
|
|
|
796
690
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
797
691
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
798
692
|
reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
|
|
799
|
-
userDestinationLiquidity: this.
|
|
693
|
+
userDestinationLiquidity: this.getUserTokenAccountAddress(this.reserve),
|
|
800
694
|
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
801
695
|
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
802
696
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
@@ -806,8 +700,8 @@ class KaminoAction {
|
|
|
806
700
|
async addWithdrawIxV2(collateralAmount) {
|
|
807
701
|
const farmsAccounts = this.reserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
|
|
808
702
|
? {
|
|
809
|
-
obligationFarmUserState:
|
|
810
|
-
reserveFarmState:
|
|
703
|
+
obligationFarmUserState: this.kaminoMarket.programId,
|
|
704
|
+
reserveFarmState: this.kaminoMarket.programId,
|
|
811
705
|
}
|
|
812
706
|
: {
|
|
813
707
|
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmCollateral)[0],
|
|
@@ -827,7 +721,7 @@ class KaminoAction {
|
|
|
827
721
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
828
722
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
829
723
|
reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
|
|
830
|
-
userDestinationLiquidity: this.
|
|
724
|
+
userDestinationLiquidity: this.getUserTokenAccountAddress(this.reserve),
|
|
831
725
|
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
832
726
|
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
833
727
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
@@ -852,7 +746,7 @@ class KaminoAction {
|
|
|
852
746
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
853
747
|
repayReserve: this.reserve.address,
|
|
854
748
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
855
|
-
userSourceLiquidity: this.
|
|
749
|
+
userSourceLiquidity: this.getTokenAccountAddressByUser(this.reserve, this.payer),
|
|
856
750
|
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
857
751
|
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
858
752
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
@@ -866,8 +760,8 @@ class KaminoAction {
|
|
|
866
760
|
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
867
761
|
const farmsAccounts = this.reserve.state.farmDebt.equals(web3_js_1.PublicKey.default)
|
|
868
762
|
? {
|
|
869
|
-
obligationFarmUserState:
|
|
870
|
-
reserveFarmState:
|
|
763
|
+
obligationFarmUserState: this.kaminoMarket.programId,
|
|
764
|
+
reserveFarmState: this.kaminoMarket.programId,
|
|
871
765
|
}
|
|
872
766
|
: {
|
|
873
767
|
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
@@ -885,7 +779,7 @@ class KaminoAction {
|
|
|
885
779
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
886
780
|
repayReserve: this.reserve.address,
|
|
887
781
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
888
|
-
userSourceLiquidity: this.
|
|
782
|
+
userSourceLiquidity: this.getTokenAccountAddressByUser(this.reserve, this.payer),
|
|
889
783
|
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
890
784
|
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
891
785
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
@@ -913,7 +807,7 @@ class KaminoAction {
|
|
|
913
807
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
914
808
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
915
809
|
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
916
|
-
userSourceLiquidity: this.
|
|
810
|
+
userSourceLiquidity: this.getUserTokenAccountAddress(this.reserve),
|
|
917
811
|
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
918
812
|
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
919
813
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
@@ -922,9 +816,6 @@ class KaminoAction {
|
|
|
922
816
|
if (!this.outflowReserve) {
|
|
923
817
|
throw new Error(`outflowReserve not set`);
|
|
924
818
|
}
|
|
925
|
-
if (!this.additionalTokenAccountAddress) {
|
|
926
|
-
throw new Error(`additionalTokenAccountAddress not set`);
|
|
927
|
-
}
|
|
928
819
|
if (!this.outflowAmount) {
|
|
929
820
|
throw new Error(`outflowAmount not set`);
|
|
930
821
|
}
|
|
@@ -945,7 +836,7 @@ class KaminoAction {
|
|
|
945
836
|
borrowReserve: this.outflowReserve.address,
|
|
946
837
|
borrowReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
947
838
|
reserveSourceLiquidity: this.outflowReserve.state.liquidity.supplyVault,
|
|
948
|
-
userDestinationLiquidity: this.
|
|
839
|
+
userDestinationLiquidity: this.getUserTokenAccountAddress(this.outflowReserve),
|
|
949
840
|
borrowReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
|
|
950
841
|
referrerTokenState: (0, utils_1.referrerTokenStatePda)(this.referrer, this.outflowReserve.address, this.kaminoMarket.programId)[0],
|
|
951
842
|
tokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
@@ -957,8 +848,8 @@ class KaminoAction {
|
|
|
957
848
|
async addDepositAndBorrowIxV2() {
|
|
958
849
|
const collateralFarmsAccounts = this.reserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
|
|
959
850
|
? {
|
|
960
|
-
obligationFarmUserState:
|
|
961
|
-
reserveFarmState:
|
|
851
|
+
obligationFarmUserState: this.kaminoMarket.programId,
|
|
852
|
+
reserveFarmState: this.kaminoMarket.programId,
|
|
962
853
|
}
|
|
963
854
|
: {
|
|
964
855
|
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmCollateral)[0],
|
|
@@ -979,7 +870,7 @@ class KaminoAction {
|
|
|
979
870
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
980
871
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
981
872
|
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
982
|
-
userSourceLiquidity: this.
|
|
873
|
+
userSourceLiquidity: this.getUserTokenAccountAddress(this.reserve),
|
|
983
874
|
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
984
875
|
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
985
876
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
@@ -991,9 +882,6 @@ class KaminoAction {
|
|
|
991
882
|
if (!this.outflowReserve) {
|
|
992
883
|
throw new Error(`outflowReserve not set`);
|
|
993
884
|
}
|
|
994
|
-
if (!this.additionalTokenAccountAddress) {
|
|
995
|
-
throw new Error(`additionalTokenAccountAddress not set`);
|
|
996
|
-
}
|
|
997
885
|
if (!this.outflowAmount) {
|
|
998
886
|
throw new Error(`outflowAmount not set`);
|
|
999
887
|
}
|
|
@@ -1006,8 +894,8 @@ class KaminoAction {
|
|
|
1006
894
|
});
|
|
1007
895
|
const debtFarmsAccounts = this.outflowReserve.state.farmDebt.equals(web3_js_1.PublicKey.default)
|
|
1008
896
|
? {
|
|
1009
|
-
obligationFarmUserState:
|
|
1010
|
-
reserveFarmState:
|
|
897
|
+
obligationFarmUserState: this.kaminoMarket.programId,
|
|
898
|
+
reserveFarmState: this.kaminoMarket.programId,
|
|
1011
899
|
}
|
|
1012
900
|
: {
|
|
1013
901
|
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.outflowReserve.state.farmDebt)[0],
|
|
@@ -1024,7 +912,7 @@ class KaminoAction {
|
|
|
1024
912
|
borrowReserve: this.outflowReserve.address,
|
|
1025
913
|
borrowReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
1026
914
|
reserveSourceLiquidity: this.outflowReserve.state.liquidity.supplyVault,
|
|
1027
|
-
userDestinationLiquidity: this.
|
|
915
|
+
userDestinationLiquidity: this.getUserTokenAccountAddress(this.outflowReserve),
|
|
1028
916
|
borrowReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
|
|
1029
917
|
referrerTokenState: (0, utils_1.referrerTokenStatePda)(this.referrer, this.outflowReserve.address, this.kaminoMarket.programId)[0],
|
|
1030
918
|
tokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
@@ -1051,7 +939,7 @@ class KaminoAction {
|
|
|
1051
939
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1052
940
|
repayReserve: this.reserve.address,
|
|
1053
941
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1054
|
-
userSourceLiquidity: this.
|
|
942
|
+
userSourceLiquidity: this.getUserTokenAccountAddress(this.reserve),
|
|
1055
943
|
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
1056
944
|
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1057
945
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
@@ -1061,9 +949,6 @@ class KaminoAction {
|
|
|
1061
949
|
if (!this.outflowReserve) {
|
|
1062
950
|
throw new Error(`outflowReserve not set`);
|
|
1063
951
|
}
|
|
1064
|
-
if (!this.additionalTokenAccountAddress) {
|
|
1065
|
-
throw new Error(`additionalTokenAccountAddress not set`);
|
|
1066
|
-
}
|
|
1067
952
|
if (!this.outflowAmount) {
|
|
1068
953
|
throw new Error(`outflowAmount not set`);
|
|
1069
954
|
}
|
|
@@ -1079,7 +964,7 @@ class KaminoAction {
|
|
|
1079
964
|
reserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
1080
965
|
reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
1081
966
|
reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
|
|
1082
|
-
userDestinationLiquidity: this.
|
|
967
|
+
userDestinationLiquidity: this.getUserTokenAccountAddress(this.outflowReserve),
|
|
1083
968
|
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1084
969
|
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
1085
970
|
liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
@@ -1095,8 +980,8 @@ class KaminoAction {
|
|
|
1095
980
|
});
|
|
1096
981
|
const debtFarmsAccounts = this.reserve.state.farmDebt.equals(web3_js_1.PublicKey.default)
|
|
1097
982
|
? {
|
|
1098
|
-
obligationFarmUserState:
|
|
1099
|
-
reserveFarmState:
|
|
983
|
+
obligationFarmUserState: this.kaminoMarket.programId,
|
|
984
|
+
reserveFarmState: this.kaminoMarket.programId,
|
|
1100
985
|
}
|
|
1101
986
|
: {
|
|
1102
987
|
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
@@ -1111,7 +996,7 @@ class KaminoAction {
|
|
|
1111
996
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1112
997
|
repayReserve: this.reserve.address,
|
|
1113
998
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1114
|
-
userSourceLiquidity: this.
|
|
999
|
+
userSourceLiquidity: this.getUserTokenAccountAddress(this.reserve),
|
|
1115
1000
|
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
1116
1001
|
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1117
1002
|
instructionSysvarAccount: web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
@@ -1125,16 +1010,13 @@ class KaminoAction {
|
|
|
1125
1010
|
if (!this.outflowReserve) {
|
|
1126
1011
|
throw new Error(`outflowReserve not set`);
|
|
1127
1012
|
}
|
|
1128
|
-
if (!this.additionalTokenAccountAddress) {
|
|
1129
|
-
throw new Error(`additionalTokenAccountAddress not set`);
|
|
1130
|
-
}
|
|
1131
1013
|
if (!this.outflowAmount) {
|
|
1132
1014
|
throw new Error(`outflowAmount not set`);
|
|
1133
1015
|
}
|
|
1134
1016
|
const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
|
|
1135
1017
|
? {
|
|
1136
|
-
obligationFarmUserState:
|
|
1137
|
-
reserveFarmState:
|
|
1018
|
+
obligationFarmUserState: this.kaminoMarket.programId,
|
|
1019
|
+
reserveFarmState: this.kaminoMarket.programId,
|
|
1138
1020
|
}
|
|
1139
1021
|
: {
|
|
1140
1022
|
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.outflowReserve.state.farmCollateral)[0],
|
|
@@ -1153,7 +1035,7 @@ class KaminoAction {
|
|
|
1153
1035
|
reserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
1154
1036
|
reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
1155
1037
|
reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
|
|
1156
|
-
userDestinationLiquidity: this.
|
|
1038
|
+
userDestinationLiquidity: this.getUserTokenAccountAddress(this.outflowReserve),
|
|
1157
1039
|
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1158
1040
|
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
1159
1041
|
liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
@@ -1168,9 +1050,6 @@ class KaminoAction {
|
|
|
1168
1050
|
if (!this.outflowReserve) {
|
|
1169
1051
|
throw Error(`Withdraw reserve during liquidation is not defined`);
|
|
1170
1052
|
}
|
|
1171
|
-
if (!this.additionalTokenAccountAddress) {
|
|
1172
|
-
throw Error(`Liquidating token account address is not defined`);
|
|
1173
|
-
}
|
|
1174
1053
|
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
1175
1054
|
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
1176
1055
|
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
@@ -1193,9 +1072,9 @@ class KaminoAction {
|
|
|
1193
1072
|
withdrawReserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
1194
1073
|
withdrawReserveCollateralSupply: this.outflowReserve.state.collateral.supplyVault,
|
|
1195
1074
|
withdrawReserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
1196
|
-
userSourceLiquidity: this.
|
|
1197
|
-
userDestinationCollateral: this.
|
|
1198
|
-
userDestinationLiquidity: this.
|
|
1075
|
+
userSourceLiquidity: this.getUserTokenAccountAddress(this.reserve),
|
|
1076
|
+
userDestinationCollateral: this.getUserCollateralAccountAddress(this.outflowReserve),
|
|
1077
|
+
userDestinationLiquidity: this.getUserTokenAccountAddress(this.outflowReserve),
|
|
1199
1078
|
withdrawReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
|
|
1200
1079
|
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
1201
1080
|
repayLiquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
@@ -1213,17 +1092,14 @@ class KaminoAction {
|
|
|
1213
1092
|
if (!this.outflowReserve) {
|
|
1214
1093
|
throw Error(`Withdraw reserve during liquidation is not defined`);
|
|
1215
1094
|
}
|
|
1216
|
-
if (!this.additionalTokenAccountAddress) {
|
|
1217
|
-
throw Error(`Liquidating token account address is not defined`);
|
|
1218
|
-
}
|
|
1219
1095
|
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
1220
1096
|
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
1221
1097
|
return { pubkey: reserve, isSigner: false, isWritable: true };
|
|
1222
1098
|
});
|
|
1223
1099
|
const collateralFarmsAccounts = this.outflowReserve.state.farmCollateral.equals(web3_js_1.PublicKey.default)
|
|
1224
1100
|
? {
|
|
1225
|
-
obligationFarmUserState:
|
|
1226
|
-
reserveFarmState:
|
|
1101
|
+
obligationFarmUserState: this.kaminoMarket.programId,
|
|
1102
|
+
reserveFarmState: this.kaminoMarket.programId,
|
|
1227
1103
|
}
|
|
1228
1104
|
: {
|
|
1229
1105
|
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.outflowReserve.state.farmCollateral)[0],
|
|
@@ -1231,8 +1107,8 @@ class KaminoAction {
|
|
|
1231
1107
|
};
|
|
1232
1108
|
const debtFarmsAccounts = this.reserve.state.farmDebt.equals(web3_js_1.PublicKey.default)
|
|
1233
1109
|
? {
|
|
1234
|
-
obligationFarmUserState:
|
|
1235
|
-
reserveFarmState:
|
|
1110
|
+
obligationFarmUserState: this.kaminoMarket.programId,
|
|
1111
|
+
reserveFarmState: this.kaminoMarket.programId,
|
|
1236
1112
|
}
|
|
1237
1113
|
: {
|
|
1238
1114
|
obligationFarmUserState: (0, utils_1.obligationFarmStatePda)(this.getObligationPda(), this.reserve.state.farmDebt)[0],
|
|
@@ -1257,9 +1133,9 @@ class KaminoAction {
|
|
|
1257
1133
|
withdrawReserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
1258
1134
|
withdrawReserveCollateralSupply: this.outflowReserve.state.collateral.supplyVault,
|
|
1259
1135
|
withdrawReserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
1260
|
-
userSourceLiquidity: this.
|
|
1261
|
-
userDestinationCollateral: this.
|
|
1262
|
-
userDestinationLiquidity: this.
|
|
1136
|
+
userSourceLiquidity: this.getUserTokenAccountAddress(this.reserve),
|
|
1137
|
+
userDestinationCollateral: this.getUserCollateralAccountAddress(this.outflowReserve),
|
|
1138
|
+
userDestinationLiquidity: this.getUserTokenAccountAddress(this.outflowReserve),
|
|
1263
1139
|
withdrawReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
|
|
1264
1140
|
collateralTokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
1265
1141
|
repayLiquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
@@ -1521,7 +1397,7 @@ class KaminoAction {
|
|
|
1521
1397
|
}
|
|
1522
1398
|
}
|
|
1523
1399
|
}
|
|
1524
|
-
async addSupportIxs(action, includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, createLookupTable, twoTokenAction = false, overrideElevationGroupRequest) {
|
|
1400
|
+
async addSupportIxs(action, includeAtaIxns, requestElevationGroup, includeUserMetadata, addInitObligationForFarm, useV2Ixs, scopeRefreshConfig, createLookupTable, twoTokenAction = false, overrideElevationGroupRequest) {
|
|
1525
1401
|
if (!['mint', 'redeem'].includes(action)) {
|
|
1526
1402
|
const [, ownerUserMetadata] = await this.kaminoMarket.getUserMetadata(this.owner);
|
|
1527
1403
|
if (!ownerUserMetadata && includeUserMetadata) {
|
|
@@ -1534,16 +1410,20 @@ class KaminoAction {
|
|
|
1534
1410
|
}
|
|
1535
1411
|
this.addInitUserMetadataIxs(lookupTable);
|
|
1536
1412
|
}
|
|
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
|
-
}
|
|
1544
1413
|
await this.addInitObligationIxs();
|
|
1545
1414
|
}
|
|
1546
1415
|
await this.addSupportIxsWithoutInitObligation(action, includeAtaIxns, useV2Ixs, 'setup', requestElevationGroup, addInitObligationForFarm, twoTokenAction, overrideElevationGroupRequest);
|
|
1416
|
+
const allReserves = new utils_1.PublicKeySet([
|
|
1417
|
+
...this.depositReserves,
|
|
1418
|
+
...this.borrowReserves,
|
|
1419
|
+
this.reserve.address,
|
|
1420
|
+
...(this.outflowReserve ? [this.outflowReserve.address] : []),
|
|
1421
|
+
...(this.preLoadedDepositReservesSameTx ? this.preLoadedDepositReservesSameTx : []),
|
|
1422
|
+
]).toArray();
|
|
1423
|
+
const tokenIds = (0, market_1.getTokenIdsForScopeRefresh)(this.kaminoMarket, allReserves);
|
|
1424
|
+
if (tokenIds.length > 0 && scopeRefreshConfig) {
|
|
1425
|
+
await this.addScopeRefreshIxs(scopeRefreshConfig.scope, tokenIds, scopeRefreshConfig.scopeFeed);
|
|
1426
|
+
}
|
|
1547
1427
|
}
|
|
1548
1428
|
static optionalAccount(pubkey, programId = lib_1.PROGRAM_ID) {
|
|
1549
1429
|
if ((0, utils_1.isNotNullPubkey)(pubkey)) {
|
|
@@ -1836,25 +1716,18 @@ class KaminoAction {
|
|
|
1836
1716
|
this.setupIxs.push(initUserMetadataIx);
|
|
1837
1717
|
this.setupIxsLabels.push(`initUserMetadata[${userMetadataAddress.toString()}]`);
|
|
1838
1718
|
}
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
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
|
-
}
|
|
1719
|
+
addInitReferrerTokenStateIx(reserve, referrerTokenState) {
|
|
1720
|
+
const initReferrerTokenStateIx = (0, instructions_1.initReferrerTokenState)({
|
|
1721
|
+
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1722
|
+
payer: this.owner,
|
|
1723
|
+
reserve: reserve.address,
|
|
1724
|
+
referrer: this.referrer,
|
|
1725
|
+
referrerTokenState,
|
|
1726
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
1727
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
1728
|
+
}, this.kaminoMarket.programId);
|
|
1729
|
+
this.setupIxs.unshift(initReferrerTokenStateIx);
|
|
1730
|
+
this.setupIxsLabels.unshift(`InitReferrerTokenState[${referrerTokenState.toString()} res=${reserve.address}]`);
|
|
1858
1731
|
}
|
|
1859
1732
|
addWithdrawReferrerFeesIxs() {
|
|
1860
1733
|
const referrerTokenStateAddress = (0, utils_1.referrerTokenStatePda)(this.owner, this.reserve.address, this.kaminoMarket.programId)[0];
|
|
@@ -1865,7 +1738,7 @@ class KaminoAction {
|
|
|
1865
1738
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1866
1739
|
referrerTokenState: referrerTokenStateAddress,
|
|
1867
1740
|
reserveSupplyLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
1868
|
-
referrerTokenAccount: this.
|
|
1741
|
+
referrerTokenAccount: this.getUserTokenAccountAddress(this.reserve),
|
|
1869
1742
|
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
1870
1743
|
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1871
1744
|
}, this.kaminoMarket.programId);
|
|
@@ -1881,50 +1754,44 @@ class KaminoAction {
|
|
|
1881
1754
|
await this.updateWSOLAccount(action);
|
|
1882
1755
|
}
|
|
1883
1756
|
if ((action === 'withdraw' || action === 'borrow' || action === 'redeem') && !this.mint.equals(spl_token_1.NATIVE_MINT)) {
|
|
1884
|
-
const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.reserve.getLiquidityMint(), this.owner, this.reserve.getLiquidityTokenProgram(), this.
|
|
1757
|
+
const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.reserve.getLiquidityMint(), this.owner, this.reserve.getLiquidityTokenProgram(), this.getUserTokenAccountAddress(this.reserve));
|
|
1885
1758
|
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
1886
1759
|
this.setupIxsLabels.unshift(`CreateLiquidityUserAta[${this.owner}]`);
|
|
1887
1760
|
}
|
|
1888
1761
|
if (action === 'liquidate') {
|
|
1889
1762
|
if (!this.outflowReserve) {
|
|
1890
|
-
throw new Error(`Outflow reserve state not found ${this.
|
|
1763
|
+
throw new Error(`Outflow reserve state not found ${this.secondaryMint}`);
|
|
1891
1764
|
}
|
|
1892
|
-
const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.outflowReserve.getLiquidityMint(), this.owner, this.outflowReserve.getLiquidityTokenProgram(), this.
|
|
1765
|
+
const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.outflowReserve.getLiquidityMint(), this.owner, this.outflowReserve.getLiquidityTokenProgram(), this.getUserTokenAccountAddress(this.outflowReserve));
|
|
1893
1766
|
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
1894
|
-
this.setupIxsLabels.unshift(`CreateUserAta[${this.
|
|
1895
|
-
const [, createUserCollateralAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.outflowReserve.getCTokenMint(), this.owner, spl_token_1.TOKEN_PROGRAM_ID, this.
|
|
1767
|
+
this.setupIxsLabels.unshift(`CreateUserAta[${this.getUserTokenAccountAddress(this.outflowReserve).toBase58()}]`);
|
|
1768
|
+
const [, createUserCollateralAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.outflowReserve.getCTokenMint(), this.owner, spl_token_1.TOKEN_PROGRAM_ID, this.getUserCollateralAccountAddress(this.outflowReserve));
|
|
1896
1769
|
this.setupIxs.unshift(createUserCollateralAccountIx);
|
|
1897
|
-
this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.
|
|
1898
|
-
if (!this.additionalTokenAccountAddress) {
|
|
1899
|
-
throw new Error(`Additional token account address not found ${this.mint}`);
|
|
1900
|
-
}
|
|
1770
|
+
this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.getUserCollateralAccountAddress(this.outflowReserve).toString()}]`);
|
|
1901
1771
|
}
|
|
1902
1772
|
if (action === 'depositAndBorrow' || (action === 'repayAndWithdraw' && !this.secondaryMint?.equals(spl_token_1.NATIVE_MINT))) {
|
|
1903
|
-
if (!this.additionalTokenAccountAddress) {
|
|
1904
|
-
throw new Error(`Additional token account address not found ${this.secondaryMint}`);
|
|
1905
|
-
}
|
|
1906
1773
|
if (!this.outflowReserve) {
|
|
1907
1774
|
throw new Error(`Outflow reserve state not found ${this.mint}`);
|
|
1908
1775
|
}
|
|
1776
|
+
const additionalUserTokenAccountAddress = this.getUserTokenAccountAddress(this.outflowReserve);
|
|
1909
1777
|
const additionalUserTokenAccountInfo = await this.kaminoMarket
|
|
1910
1778
|
.getConnection()
|
|
1911
|
-
.getAccountInfo(
|
|
1779
|
+
.getAccountInfo(additionalUserTokenAccountAddress);
|
|
1912
1780
|
if (!additionalUserTokenAccountInfo) {
|
|
1913
|
-
const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.outflowReserve.getLiquidityMint(), this.owner, this.outflowReserve.getLiquidityTokenProgram(),
|
|
1781
|
+
const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.outflowReserve.getLiquidityMint(), this.owner, this.outflowReserve.getLiquidityTokenProgram(), additionalUserTokenAccountAddress);
|
|
1914
1782
|
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
1915
1783
|
this.setupIxsLabels.unshift(`CreateAdditionalUserTokenAta[${this.owner}]`);
|
|
1916
1784
|
}
|
|
1917
1785
|
}
|
|
1918
1786
|
if (action === 'withdraw' || action === 'mint' || action === 'deposit' || action === 'repayAndWithdraw') {
|
|
1919
|
-
const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.reserve.getLiquidityMint(), this.owner, this.reserve.getLiquidityTokenProgram(), this.
|
|
1920
|
-
this.
|
|
1921
|
-
this.
|
|
1787
|
+
const [, createUserTokenAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.reserve.getLiquidityMint(), this.owner, this.reserve.getLiquidityTokenProgram(), this.getUserTokenAccountAddress(this.reserve));
|
|
1788
|
+
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
1789
|
+
this.setupIxsLabels.unshift(`CreateUserAta[${this.getUserTokenAccountAddress(this.reserve).toBase58()}]`);
|
|
1922
1790
|
}
|
|
1923
1791
|
if (action === 'mint') {
|
|
1924
|
-
const
|
|
1925
|
-
const [, createUserCollateralAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, collateralMintPubkey, this.owner, spl_token_1.TOKEN_PROGRAM_ID, this.userCollateralAccountAddress);
|
|
1792
|
+
const [, createUserCollateralAccountIx] = (0, utils_1.createAssociatedTokenAccountIdempotentInstruction)(this.owner, this.reserve.getCTokenMint(), this.owner, spl_token_1.TOKEN_PROGRAM_ID, this.getUserCollateralAccountAddress(this.reserve));
|
|
1926
1793
|
this.setupIxs.unshift(createUserCollateralAccountIx);
|
|
1927
|
-
this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.
|
|
1794
|
+
this.setupIxsLabels.unshift(`CreateCollateralUserAta[${this.getUserCollateralAccountAddress(this.reserve).toString()}]`);
|
|
1928
1795
|
}
|
|
1929
1796
|
}
|
|
1930
1797
|
async updateWSOLAccount(action) {
|
|
@@ -1947,15 +1814,16 @@ class KaminoAction {
|
|
|
1947
1814
|
safeRepay = new bn_js_1.default(Math.floor(obligation_1.KaminoObligation.getBorrowAmount(borrow)
|
|
1948
1815
|
.mul(cumulativeBorrowRateReserve)
|
|
1949
1816
|
.div(cumulativeBorrowRateObligation)
|
|
1950
|
-
.add(new decimal_js_1.default(SOL_PADDING_FOR_INTEREST.toString()))
|
|
1817
|
+
.add(new decimal_js_1.default(utils_1.SOL_PADDING_FOR_INTEREST.toString()))
|
|
1951
1818
|
.toNumber()).toString());
|
|
1952
1819
|
}
|
|
1953
|
-
let userTokenAccountAddress = this.
|
|
1820
|
+
let userTokenAccountAddress = this.getUserTokenAccountAddress(this.reserve);
|
|
1954
1821
|
if (this.secondaryMint?.equals(spl_token_1.NATIVE_MINT)) {
|
|
1955
|
-
if (!this.
|
|
1956
|
-
throw new Error(`
|
|
1822
|
+
if (!this.outflowReserve) {
|
|
1823
|
+
throw new Error(`Outflow reserve state not found ${this.secondaryMint}`);
|
|
1957
1824
|
}
|
|
1958
|
-
|
|
1825
|
+
const additionalUserTokenAccountAddress = this.getUserTokenAccountAddress(this.outflowReserve);
|
|
1826
|
+
userTokenAccountAddress = additionalUserTokenAccountAddress;
|
|
1959
1827
|
}
|
|
1960
1828
|
const userWSOLAccountInfo = await this.kaminoMarket.getConnection().getAccountInfo(userTokenAccountAddress);
|
|
1961
1829
|
const rentExempt = await this.kaminoMarket.getConnection().getMinimumBalanceForRentExemption(165);
|
|
@@ -1963,7 +1831,7 @@ class KaminoAction {
|
|
|
1963
1831
|
const sendAction = action === 'deposit' ||
|
|
1964
1832
|
action === 'repay' ||
|
|
1965
1833
|
action === 'mint' ||
|
|
1966
|
-
(action === 'liquidate' && this.
|
|
1834
|
+
(action === 'liquidate' && this.mint?.equals(spl_token_1.NATIVE_MINT)); // only sync WSOL amount if liquidator repays SOL which is secondaryMint
|
|
1967
1835
|
const transferLamportsIx = web3_js_1.SystemProgram.transfer({
|
|
1968
1836
|
fromPubkey: this.owner,
|
|
1969
1837
|
toPubkey: userTokenAccountAddress,
|
|
@@ -2003,55 +1871,32 @@ class KaminoAction {
|
|
|
2003
1871
|
if (!outflowReserve || !inflowReserve) {
|
|
2004
1872
|
throw new Error('reserve states are not fetched');
|
|
2005
1873
|
}
|
|
2006
|
-
const { userTokenAccountAddress: userOutflowTokenAccountAddress, userCollateralAccountAddress: userOutflowCollateralAccountAddress, } = KaminoAction.getUserAccountAddresses(payer, outflowReserve.state);
|
|
2007
|
-
const { userTokenAccountAddress: userInflowTokenAccountAddress, userCollateralAccountAddress: userInflowCollateralAccountAddress, } = KaminoAction.getUserAccountAddresses(payer, inflowReserve.state);
|
|
2008
1874
|
const { kaminoObligation, depositReserves, borrowReserves, distinctReserveCount } = await KaminoAction.loadObligation(action, kaminoMarket, obligationOwner, inflowReserve.address, obligation, outflowReserve.address);
|
|
2009
1875
|
const referrerKey = await this.getReferrerKey(kaminoMarket, payer, kaminoObligation, referrer);
|
|
2010
|
-
let userTokenAccountAddress;
|
|
2011
|
-
let userCollateralAccountAddress;
|
|
2012
|
-
let additionalUserTokenAccountAddress;
|
|
2013
1876
|
let secondaryMint;
|
|
2014
1877
|
let primaryMint;
|
|
2015
|
-
if (action === 'liquidate') {
|
|
2016
|
-
userTokenAccountAddress = userOutflowTokenAccountAddress;
|
|
2017
|
-
userCollateralAccountAddress = userOutflowCollateralAccountAddress;
|
|
2018
|
-
additionalUserTokenAccountAddress = userInflowTokenAccountAddress;
|
|
2019
|
-
primaryMint = outflowTokenMint;
|
|
2020
|
-
secondaryMint = inflowTokenMint;
|
|
2021
|
-
}
|
|
2022
|
-
else if (action === 'depositAndBorrow') {
|
|
2023
|
-
userTokenAccountAddress = userInflowTokenAccountAddress;
|
|
2024
|
-
userCollateralAccountAddress = userInflowCollateralAccountAddress;
|
|
2025
|
-
additionalUserTokenAccountAddress = userOutflowTokenAccountAddress;
|
|
1878
|
+
if (action === 'liquidate' || action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
|
|
2026
1879
|
primaryMint = inflowTokenMint;
|
|
2027
1880
|
secondaryMint = outflowTokenMint;
|
|
2028
1881
|
}
|
|
2029
|
-
else if (action === 'repayAndWithdraw') {
|
|
2030
|
-
primaryMint = inflowTokenMint;
|
|
2031
|
-
secondaryMint = outflowTokenMint;
|
|
2032
|
-
userTokenAccountAddress = userInflowTokenAccountAddress;
|
|
2033
|
-
userCollateralAccountAddress = userOutflowCollateralAccountAddress;
|
|
2034
|
-
additionalUserTokenAccountAddress = userOutflowTokenAccountAddress;
|
|
2035
|
-
}
|
|
2036
1882
|
else {
|
|
2037
1883
|
throw new Error('Invalid action');
|
|
2038
1884
|
}
|
|
2039
|
-
return new KaminoAction(kaminoMarket, payer, kaminoObligation || obligation,
|
|
1885
|
+
return new KaminoAction(kaminoMarket, payer, kaminoObligation || obligation, primaryMint, distinctReserveCount, inflowAmount, depositReserves, borrowReserves, inflowReserve, currentSlot, secondaryMint, outflowReserve, outflowAmount, referrerKey);
|
|
2040
1886
|
}
|
|
2041
1887
|
static async initializeWithdrawReferrerFees(mint, owner, kaminoMarket, currentSlot = 0) {
|
|
2042
1888
|
const reserve = kaminoMarket.getReserveByMint(mint);
|
|
2043
1889
|
if (reserve === undefined) {
|
|
2044
1890
|
throw new Error(`Reserve ${mint} not found in market ${kaminoMarket.getAddress().toBase58()}`);
|
|
2045
1891
|
}
|
|
2046
|
-
const [{
|
|
1892
|
+
const [{ createAtaIx }] = (0, utils_1.createAtasIdempotent)(owner, [
|
|
2047
1893
|
{
|
|
2048
1894
|
mint: reserve.getLiquidityMint(),
|
|
2049
1895
|
tokenProgram: reserve.getLiquidityTokenProgram(),
|
|
2050
1896
|
},
|
|
2051
1897
|
]);
|
|
2052
|
-
const userTokenAccountAddress = ata;
|
|
2053
1898
|
return {
|
|
2054
|
-
axn: new KaminoAction(kaminoMarket, owner, new ObligationType_1.VanillaObligation(kaminoMarket.programId),
|
|
1899
|
+
axn: new KaminoAction(kaminoMarket, owner, new ObligationType_1.VanillaObligation(kaminoMarket.programId), mint, 0, new bn_js_1.default(0), [], [], reserve, currentSlot, undefined, undefined, undefined, undefined, undefined),
|
|
2055
1900
|
createAtaIxs: [createAtaIx],
|
|
2056
1901
|
};
|
|
2057
1902
|
}
|
|
@@ -2098,6 +1943,15 @@ class KaminoAction {
|
|
|
2098
1943
|
}
|
|
2099
1944
|
return referrerKey;
|
|
2100
1945
|
}
|
|
1946
|
+
getUserTokenAccountAddress(reserve) {
|
|
1947
|
+
return (0, utils_1.getAssociatedTokenAddress)(reserve.getLiquidityMint(), this.owner, true, reserve.getLiquidityTokenProgram());
|
|
1948
|
+
}
|
|
1949
|
+
getTokenAccountAddressByUser(reserve, user) {
|
|
1950
|
+
return (0, utils_1.getAssociatedTokenAddress)(reserve.getLiquidityMint(), user, true, reserve.getLiquidityTokenProgram());
|
|
1951
|
+
}
|
|
1952
|
+
getUserCollateralAccountAddress(reserve) {
|
|
1953
|
+
return (0, utils_1.getAssociatedTokenAddress)(reserve.getCTokenMint(), this.owner, true);
|
|
1954
|
+
}
|
|
2101
1955
|
static actionToIxs(action) {
|
|
2102
1956
|
const ixs = [...action.computeBudgetIxs, ...action.setupIxs];
|
|
2103
1957
|
ixs.push(...KaminoAction.actionToLendingIxs(action));
|
|
@@ -2121,14 +1975,14 @@ class KaminoAction {
|
|
|
2121
1975
|
return labels;
|
|
2122
1976
|
}
|
|
2123
1977
|
static actionToLendingIxLabels(action) {
|
|
2124
|
-
const
|
|
1978
|
+
const labels = [];
|
|
2125
1979
|
for (let i = 0; i < action.lendingIxsLabels.length; i++) {
|
|
2126
|
-
|
|
1980
|
+
labels.push(action.lendingIxsLabels[i]);
|
|
2127
1981
|
if (i !== action.lendingIxsLabels.length - 1) {
|
|
2128
|
-
|
|
1982
|
+
labels.push(...action.inBetweenIxsLabels);
|
|
2129
1983
|
}
|
|
2130
1984
|
}
|
|
2131
|
-
return
|
|
1985
|
+
return labels;
|
|
2132
1986
|
}
|
|
2133
1987
|
}
|
|
2134
1988
|
exports.KaminoAction = KaminoAction;
|