@kamino-finance/klend-sdk 5.11.5 → 5.11.6
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 +4 -12
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +76 -149
- package/dist/classes/action.js.map +1 -1
- package/dist/utils/constants.d.ts +5 -0
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/constants.js +6 -1
- package/dist/utils/constants.js.map +1 -1
- package/package.json +1 -1
- package/src/classes/action.ts +82 -189
- package/src/utils/constants.ts +6 -0
package/src/classes/action.ts
CHANGED
|
@@ -63,6 +63,7 @@ import {
|
|
|
63
63
|
getAssociatedTokenAddress,
|
|
64
64
|
ScopePriceRefreshConfig,
|
|
65
65
|
createAtasIdempotent,
|
|
66
|
+
SOL_PADDING_FOR_INTEREST,
|
|
66
67
|
obligationFarmStatePda,
|
|
67
68
|
} from '../utils';
|
|
68
69
|
import { getTokenIdsForScopeRefresh, KaminoMarket } from './market';
|
|
@@ -75,8 +76,6 @@ import { VanillaObligation } from '../utils/ObligationType';
|
|
|
75
76
|
import { PROGRAM_ID } from '../lib';
|
|
76
77
|
import { Scope } from '@kamino-finance/scope-sdk';
|
|
77
78
|
|
|
78
|
-
const SOL_PADDING_FOR_INTEREST = new BN('1000000');
|
|
79
|
-
|
|
80
79
|
export type ActionType =
|
|
81
80
|
| 'deposit'
|
|
82
81
|
| 'borrow'
|
|
@@ -108,12 +107,6 @@ export class KaminoAction {
|
|
|
108
107
|
|
|
109
108
|
referrer: PublicKey;
|
|
110
109
|
|
|
111
|
-
userTokenAccountAddress: PublicKey;
|
|
112
|
-
|
|
113
|
-
userCollateralAccountAddress: PublicKey;
|
|
114
|
-
|
|
115
|
-
additionalTokenAccountAddress?: PublicKey;
|
|
116
|
-
|
|
117
110
|
/**
|
|
118
111
|
* Null unless the obligation is not passed
|
|
119
112
|
*/
|
|
@@ -143,12 +136,6 @@ export class KaminoAction {
|
|
|
143
136
|
cleanupIxs: Array<TransactionInstruction>;
|
|
144
137
|
cleanupIxsLabels: Array<string>;
|
|
145
138
|
|
|
146
|
-
preTxnIxs: Array<TransactionInstruction>;
|
|
147
|
-
preTxnIxsLabels: Array<string>;
|
|
148
|
-
|
|
149
|
-
postTxnIxs: Array<TransactionInstruction>;
|
|
150
|
-
postTxnIxsLabels: Array<string>;
|
|
151
|
-
|
|
152
139
|
refreshFarmsCleanupTxnIxs: Array<TransactionInstruction>;
|
|
153
140
|
refreshFarmsCleanupTxnIxsLabels: Array<string>;
|
|
154
141
|
|
|
@@ -163,8 +150,6 @@ export class KaminoAction {
|
|
|
163
150
|
kaminoMarket: KaminoMarket,
|
|
164
151
|
owner: PublicKey,
|
|
165
152
|
obligation: KaminoObligation | ObligationType | null,
|
|
166
|
-
userTokenAccountAddress: PublicKey,
|
|
167
|
-
userCollateralAccountAddress: PublicKey,
|
|
168
153
|
mint: PublicKey,
|
|
169
154
|
positions: number,
|
|
170
155
|
amount: string | BN,
|
|
@@ -173,7 +158,6 @@ export class KaminoAction {
|
|
|
173
158
|
reserveState: KaminoReserve,
|
|
174
159
|
currentSlot: number,
|
|
175
160
|
secondaryMint?: PublicKey,
|
|
176
|
-
additionalTokenAccountAddress?: PublicKey,
|
|
177
161
|
outflowReserveState?: KaminoReserve,
|
|
178
162
|
outflowAmount?: string | BN,
|
|
179
163
|
referrer?: PublicKey,
|
|
@@ -191,8 +175,6 @@ export class KaminoAction {
|
|
|
191
175
|
this.amount = new BN(amount);
|
|
192
176
|
this.mint = mint;
|
|
193
177
|
this.positions = positions;
|
|
194
|
-
this.userTokenAccountAddress = userTokenAccountAddress;
|
|
195
|
-
this.userCollateralAccountAddress = userCollateralAccountAddress;
|
|
196
178
|
this.computeBudgetIxs = [];
|
|
197
179
|
this.computeBudgetIxsLabels = [];
|
|
198
180
|
this.setupIxs = [];
|
|
@@ -203,15 +185,10 @@ export class KaminoAction {
|
|
|
203
185
|
this.lendingIxsLabels = [];
|
|
204
186
|
this.cleanupIxs = [];
|
|
205
187
|
this.cleanupIxsLabels = [];
|
|
206
|
-
this.preTxnIxs = [];
|
|
207
|
-
this.preTxnIxsLabels = [];
|
|
208
|
-
this.postTxnIxs = [];
|
|
209
|
-
this.postTxnIxsLabels = [];
|
|
210
188
|
this.refreshFarmsCleanupTxnIxs = [];
|
|
211
189
|
this.refreshFarmsCleanupTxnIxsLabels = [];
|
|
212
190
|
this.depositReserves = depositReserves;
|
|
213
191
|
this.borrowReserves = borrowReserves;
|
|
214
|
-
this.additionalTokenAccountAddress = additionalTokenAccountAddress;
|
|
215
192
|
this.secondaryMint = secondaryMint;
|
|
216
193
|
this.reserve = reserveState;
|
|
217
194
|
this.outflowReserve = outflowReserveState;
|
|
@@ -237,11 +214,6 @@ export class KaminoAction {
|
|
|
237
214
|
throw new Error(`Reserve ${mint} not found in market ${kaminoMarket.getAddress().toBase58()}`);
|
|
238
215
|
}
|
|
239
216
|
|
|
240
|
-
const { userTokenAccountAddress, userCollateralAccountAddress } = KaminoAction.getUserAccountAddresses(
|
|
241
|
-
payer ?? owner,
|
|
242
|
-
reserve.state
|
|
243
|
-
);
|
|
244
|
-
|
|
245
217
|
const { kaminoObligation, depositReserves, borrowReserves, distinctReserveCount } =
|
|
246
218
|
await KaminoAction.loadObligation(action, kaminoMarket, owner, reserve.address, obligation);
|
|
247
219
|
|
|
@@ -251,8 +223,6 @@ export class KaminoAction {
|
|
|
251
223
|
kaminoMarket,
|
|
252
224
|
owner,
|
|
253
225
|
kaminoObligation || obligation,
|
|
254
|
-
userTokenAccountAddress,
|
|
255
|
-
userCollateralAccountAddress,
|
|
256
226
|
mint,
|
|
257
227
|
distinctReserveCount,
|
|
258
228
|
amount,
|
|
@@ -263,7 +233,6 @@ export class KaminoAction {
|
|
|
263
233
|
undefined,
|
|
264
234
|
undefined,
|
|
265
235
|
undefined,
|
|
266
|
-
undefined,
|
|
267
236
|
referrerKey,
|
|
268
237
|
payer
|
|
269
238
|
);
|
|
@@ -1055,8 +1024,8 @@ export class KaminoAction {
|
|
|
1055
1024
|
currentSlot
|
|
1056
1025
|
);
|
|
1057
1026
|
|
|
1058
|
-
axn.
|
|
1059
|
-
axn.
|
|
1027
|
+
axn.setupIxs.push(...createAtaIxs);
|
|
1028
|
+
axn.setupIxsLabels.push(`createAtasIxs[${axn.owner.toString()}]`);
|
|
1060
1029
|
|
|
1061
1030
|
if (!axn.referrer.equals(PublicKey.default)) {
|
|
1062
1031
|
const referrerTokenState = referrerTokenStatePda(
|
|
@@ -1076,25 +1045,10 @@ export class KaminoAction {
|
|
|
1076
1045
|
}
|
|
1077
1046
|
|
|
1078
1047
|
async getTransactions() {
|
|
1079
|
-
|
|
1080
|
-
preLendingTxn: Transaction | null;
|
|
1081
|
-
lendingTxn: Transaction | null;
|
|
1082
|
-
postLendingTxn: Transaction | null;
|
|
1083
|
-
} = {
|
|
1084
|
-
preLendingTxn: null,
|
|
1085
|
-
lendingTxn: null,
|
|
1086
|
-
postLendingTxn: null,
|
|
1087
|
-
};
|
|
1088
|
-
|
|
1089
|
-
if (this.preTxnIxs.length) {
|
|
1090
|
-
txns.preLendingTxn = new Transaction({
|
|
1091
|
-
feePayer: this.owner,
|
|
1092
|
-
recentBlockhash: (await this.kaminoMarket.getConnection().getLatestBlockhash()).blockhash,
|
|
1093
|
-
}).add(...this.preTxnIxs);
|
|
1094
|
-
}
|
|
1048
|
+
let txns: Transaction;
|
|
1095
1049
|
|
|
1096
1050
|
if (this.lendingIxs.length === 2) {
|
|
1097
|
-
txns
|
|
1051
|
+
txns = new Transaction({
|
|
1098
1052
|
feePayer: this.owner,
|
|
1099
1053
|
recentBlockhash: (await this.kaminoMarket.getConnection().getLatestBlockhash()).blockhash,
|
|
1100
1054
|
}).add(
|
|
@@ -1105,30 +1059,19 @@ export class KaminoAction {
|
|
|
1105
1059
|
...this.cleanupIxs
|
|
1106
1060
|
);
|
|
1107
1061
|
} else {
|
|
1108
|
-
txns
|
|
1062
|
+
txns = new Transaction({
|
|
1109
1063
|
feePayer: this.owner,
|
|
1110
1064
|
recentBlockhash: (await this.kaminoMarket.getConnection().getLatestBlockhash()).blockhash,
|
|
1111
1065
|
}).add(...this.setupIxs, ...this.lendingIxs, ...this.cleanupIxs);
|
|
1112
1066
|
}
|
|
1113
1067
|
|
|
1114
|
-
if (this.postTxnIxs.length) {
|
|
1115
|
-
txns.postLendingTxn = new Transaction({
|
|
1116
|
-
feePayer: this.owner,
|
|
1117
|
-
recentBlockhash: (await this.kaminoMarket.getConnection().getLatestBlockhash()).blockhash,
|
|
1118
|
-
}).add(...this.postTxnIxs);
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
1068
|
return txns;
|
|
1122
1069
|
}
|
|
1123
1070
|
|
|
1124
1071
|
async sendTransactions(sendTransaction: (txn: Transaction, connection: Connection) => Promise<TransactionSignature>) {
|
|
1125
1072
|
const txns = await this.getTransactions();
|
|
1126
1073
|
|
|
1127
|
-
await this.sendSingleTransaction(txns
|
|
1128
|
-
|
|
1129
|
-
const signature = await this.sendSingleTransaction(txns.lendingTxn, sendTransaction);
|
|
1130
|
-
|
|
1131
|
-
await this.sendSingleTransaction(txns.postLendingTxn, sendTransaction);
|
|
1074
|
+
const signature = await this.sendSingleTransaction(txns, sendTransaction);
|
|
1132
1075
|
|
|
1133
1076
|
return signature;
|
|
1134
1077
|
}
|
|
@@ -1153,11 +1096,7 @@ export class KaminoAction {
|
|
|
1153
1096
|
) {
|
|
1154
1097
|
const txns = await this.getTransactions();
|
|
1155
1098
|
|
|
1156
|
-
await this.simulateSingleTransaction(txns
|
|
1157
|
-
|
|
1158
|
-
const signature = await this.simulateSingleTransaction(txns.lendingTxn, sendTransaction);
|
|
1159
|
-
|
|
1160
|
-
await this.simulateSingleTransaction(txns.postLendingTxn, sendTransaction);
|
|
1099
|
+
const signature = await this.simulateSingleTransaction(txns, sendTransaction);
|
|
1161
1100
|
|
|
1162
1101
|
return signature;
|
|
1163
1102
|
}
|
|
@@ -1188,8 +1127,8 @@ export class KaminoAction {
|
|
|
1188
1127
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1189
1128
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1190
1129
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
1191
|
-
userSourceLiquidity: this.
|
|
1192
|
-
userDestinationCollateral: this.
|
|
1130
|
+
userSourceLiquidity: this.getUserTokenAccountAddress(this.reserve),
|
|
1131
|
+
userDestinationCollateral: this.getUserCollateralAccountAddress(this.reserve),
|
|
1193
1132
|
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1194
1133
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1195
1134
|
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
@@ -1214,8 +1153,8 @@ export class KaminoAction {
|
|
|
1214
1153
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1215
1154
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1216
1155
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
1217
|
-
userSourceCollateral: this.
|
|
1218
|
-
userDestinationLiquidity: this.
|
|
1156
|
+
userSourceCollateral: this.getUserCollateralAccountAddress(this.reserve),
|
|
1157
|
+
userDestinationLiquidity: this.getUserTokenAccountAddress(this.reserve),
|
|
1219
1158
|
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1220
1159
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1221
1160
|
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
@@ -1243,7 +1182,7 @@ export class KaminoAction {
|
|
|
1243
1182
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1244
1183
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
1245
1184
|
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
1246
|
-
userSourceLiquidity: this.
|
|
1185
|
+
userSourceLiquidity: this.getUserTokenAccountAddress(this.reserve),
|
|
1247
1186
|
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1248
1187
|
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1249
1188
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
@@ -1285,7 +1224,7 @@ export class KaminoAction {
|
|
|
1285
1224
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1286
1225
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
1287
1226
|
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
1288
|
-
userSourceLiquidity: this.
|
|
1227
|
+
userSourceLiquidity: this.getUserTokenAccountAddress(this.reserve),
|
|
1289
1228
|
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1290
1229
|
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1291
1230
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
@@ -1313,7 +1252,7 @@ export class KaminoAction {
|
|
|
1313
1252
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1314
1253
|
depositReserve: this.reserve.address,
|
|
1315
1254
|
reserveDestinationCollateral: this.reserve.state.collateral.supplyVault,
|
|
1316
|
-
userSourceCollateral: this.
|
|
1255
|
+
userSourceCollateral: this.getUserCollateralAccountAddress(this.reserve),
|
|
1317
1256
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
1318
1257
|
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1319
1258
|
},
|
|
@@ -1349,7 +1288,7 @@ export class KaminoAction {
|
|
|
1349
1288
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1350
1289
|
depositReserve: this.reserve.address,
|
|
1351
1290
|
reserveDestinationCollateral: this.reserve.state.collateral.supplyVault,
|
|
1352
|
-
userSourceCollateral: this.
|
|
1291
|
+
userSourceCollateral: this.getUserCollateralAccountAddress(this.reserve),
|
|
1353
1292
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
1354
1293
|
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
1355
1294
|
},
|
|
@@ -1384,7 +1323,7 @@ export class KaminoAction {
|
|
|
1384
1323
|
borrowReserve: this.reserve.address,
|
|
1385
1324
|
borrowReserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1386
1325
|
reserveSourceLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
1387
|
-
userDestinationLiquidity: this.
|
|
1326
|
+
userDestinationLiquidity: this.getUserTokenAccountAddress(this.reserve),
|
|
1388
1327
|
borrowReserveLiquidityFeeReceiver: this.reserve.state.liquidity.feeVault,
|
|
1389
1328
|
referrerTokenState: referrerTokenStatePda(this.referrer, this.reserve.address, this.kaminoMarket.programId)[0],
|
|
1390
1329
|
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
@@ -1431,7 +1370,7 @@ export class KaminoAction {
|
|
|
1431
1370
|
borrowReserve: this.reserve.address,
|
|
1432
1371
|
borrowReserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1433
1372
|
reserveSourceLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
1434
|
-
userDestinationLiquidity: this.
|
|
1373
|
+
userDestinationLiquidity: this.getUserTokenAccountAddress(this.reserve),
|
|
1435
1374
|
borrowReserveLiquidityFeeReceiver: this.reserve.state.liquidity.feeVault,
|
|
1436
1375
|
referrerTokenState: referrerTokenStatePda(
|
|
1437
1376
|
this.referrer,
|
|
@@ -1471,7 +1410,7 @@ export class KaminoAction {
|
|
|
1471
1410
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
1472
1411
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1473
1412
|
reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
|
|
1474
|
-
userDestinationLiquidity: this.
|
|
1413
|
+
userDestinationLiquidity: this.getUserTokenAccountAddress(this.reserve),
|
|
1475
1414
|
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1476
1415
|
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1477
1416
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
@@ -1513,7 +1452,7 @@ export class KaminoAction {
|
|
|
1513
1452
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
1514
1453
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1515
1454
|
reserveSourceCollateral: this.reserve.state.collateral.supplyVault,
|
|
1516
|
-
userDestinationLiquidity: this.
|
|
1455
|
+
userDestinationLiquidity: this.getUserTokenAccountAddress(this.reserve),
|
|
1517
1456
|
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1518
1457
|
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1519
1458
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
@@ -1549,7 +1488,7 @@ export class KaminoAction {
|
|
|
1549
1488
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1550
1489
|
repayReserve: this.reserve.address,
|
|
1551
1490
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1552
|
-
userSourceLiquidity: this.
|
|
1491
|
+
userSourceLiquidity: this.getTokenAccountAddressByUser(this.reserve, this.payer),
|
|
1553
1492
|
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
1554
1493
|
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1555
1494
|
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
@@ -1594,7 +1533,7 @@ export class KaminoAction {
|
|
|
1594
1533
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1595
1534
|
repayReserve: this.reserve.address,
|
|
1596
1535
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1597
|
-
userSourceLiquidity: this.
|
|
1536
|
+
userSourceLiquidity: this.getTokenAccountAddressByUser(this.reserve, this.payer),
|
|
1598
1537
|
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
1599
1538
|
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1600
1539
|
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
@@ -1630,7 +1569,7 @@ export class KaminoAction {
|
|
|
1630
1569
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1631
1570
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
1632
1571
|
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
1633
|
-
userSourceLiquidity: this.
|
|
1572
|
+
userSourceLiquidity: this.getUserTokenAccountAddress(this.reserve),
|
|
1634
1573
|
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1635
1574
|
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1636
1575
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
@@ -1644,10 +1583,6 @@ export class KaminoAction {
|
|
|
1644
1583
|
throw new Error(`outflowReserve not set`);
|
|
1645
1584
|
}
|
|
1646
1585
|
|
|
1647
|
-
if (!this.additionalTokenAccountAddress) {
|
|
1648
|
-
throw new Error(`additionalTokenAccountAddress not set`);
|
|
1649
|
-
}
|
|
1650
|
-
|
|
1651
1586
|
if (!this.outflowAmount) {
|
|
1652
1587
|
throw new Error(`outflowAmount not set`);
|
|
1653
1588
|
}
|
|
@@ -1672,7 +1607,7 @@ export class KaminoAction {
|
|
|
1672
1607
|
borrowReserve: this.outflowReserve.address,
|
|
1673
1608
|
borrowReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
1674
1609
|
reserveSourceLiquidity: this.outflowReserve.state.liquidity.supplyVault,
|
|
1675
|
-
userDestinationLiquidity: this.
|
|
1610
|
+
userDestinationLiquidity: this.getUserTokenAccountAddress(this.outflowReserve),
|
|
1676
1611
|
borrowReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
|
|
1677
1612
|
referrerTokenState: referrerTokenStatePda(
|
|
1678
1613
|
this.referrer,
|
|
@@ -1722,7 +1657,7 @@ export class KaminoAction {
|
|
|
1722
1657
|
reserveLiquiditySupply: this.reserve.state.liquidity.supplyVault,
|
|
1723
1658
|
reserveCollateralMint: this.reserve.getCTokenMint(),
|
|
1724
1659
|
reserveDestinationDepositCollateral: this.reserve.state.collateral.supplyVault, // destinationCollateral
|
|
1725
|
-
userSourceLiquidity: this.
|
|
1660
|
+
userSourceLiquidity: this.getUserTokenAccountAddress(this.reserve),
|
|
1726
1661
|
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1727
1662
|
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1728
1663
|
liquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
@@ -1739,10 +1674,6 @@ export class KaminoAction {
|
|
|
1739
1674
|
throw new Error(`outflowReserve not set`);
|
|
1740
1675
|
}
|
|
1741
1676
|
|
|
1742
|
-
if (!this.additionalTokenAccountAddress) {
|
|
1743
|
-
throw new Error(`additionalTokenAccountAddress not set`);
|
|
1744
|
-
}
|
|
1745
|
-
|
|
1746
1677
|
if (!this.outflowAmount) {
|
|
1747
1678
|
throw new Error(`outflowAmount not set`);
|
|
1748
1679
|
}
|
|
@@ -1781,7 +1712,7 @@ export class KaminoAction {
|
|
|
1781
1712
|
borrowReserve: this.outflowReserve.address,
|
|
1782
1713
|
borrowReserveLiquidityMint: this.outflowReserve.getLiquidityMint(),
|
|
1783
1714
|
reserveSourceLiquidity: this.outflowReserve.state.liquidity.supplyVault,
|
|
1784
|
-
userDestinationLiquidity: this.
|
|
1715
|
+
userDestinationLiquidity: this.getUserTokenAccountAddress(this.outflowReserve),
|
|
1785
1716
|
borrowReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
|
|
1786
1717
|
referrerTokenState: referrerTokenStatePda(
|
|
1787
1718
|
this.referrer,
|
|
@@ -1823,7 +1754,7 @@ export class KaminoAction {
|
|
|
1823
1754
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1824
1755
|
repayReserve: this.reserve!.address,
|
|
1825
1756
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1826
|
-
userSourceLiquidity: this.
|
|
1757
|
+
userSourceLiquidity: this.getUserTokenAccountAddress(this.reserve),
|
|
1827
1758
|
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
1828
1759
|
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1829
1760
|
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
@@ -1838,10 +1769,6 @@ export class KaminoAction {
|
|
|
1838
1769
|
throw new Error(`outflowReserve not set`);
|
|
1839
1770
|
}
|
|
1840
1771
|
|
|
1841
|
-
if (!this.additionalTokenAccountAddress) {
|
|
1842
|
-
throw new Error(`additionalTokenAccountAddress not set`);
|
|
1843
|
-
}
|
|
1844
|
-
|
|
1845
1772
|
if (!this.outflowAmount) {
|
|
1846
1773
|
throw new Error(`outflowAmount not set`);
|
|
1847
1774
|
}
|
|
@@ -1861,7 +1788,7 @@ export class KaminoAction {
|
|
|
1861
1788
|
reserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
1862
1789
|
reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
1863
1790
|
reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
|
|
1864
|
-
userDestinationLiquidity: this.
|
|
1791
|
+
userDestinationLiquidity: this.getUserTokenAccountAddress(this.outflowReserve),
|
|
1865
1792
|
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1866
1793
|
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1867
1794
|
liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
@@ -1905,7 +1832,7 @@ export class KaminoAction {
|
|
|
1905
1832
|
lendingMarket: this.kaminoMarket.getAddress(),
|
|
1906
1833
|
repayReserve: this.reserve!.address,
|
|
1907
1834
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
1908
|
-
userSourceLiquidity: this.
|
|
1835
|
+
userSourceLiquidity: this.getUserTokenAccountAddress(this.reserve),
|
|
1909
1836
|
reserveDestinationLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
1910
1837
|
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
1911
1838
|
instructionSysvarAccount: SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
@@ -1924,10 +1851,6 @@ export class KaminoAction {
|
|
|
1924
1851
|
throw new Error(`outflowReserve not set`);
|
|
1925
1852
|
}
|
|
1926
1853
|
|
|
1927
|
-
if (!this.additionalTokenAccountAddress) {
|
|
1928
|
-
throw new Error(`additionalTokenAccountAddress not set`);
|
|
1929
|
-
}
|
|
1930
|
-
|
|
1931
1854
|
if (!this.outflowAmount) {
|
|
1932
1855
|
throw new Error(`outflowAmount not set`);
|
|
1933
1856
|
}
|
|
@@ -1961,7 +1884,7 @@ export class KaminoAction {
|
|
|
1961
1884
|
reserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
1962
1885
|
reserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
1963
1886
|
reserveSourceCollateral: this.outflowReserve.state.collateral.supplyVault,
|
|
1964
|
-
userDestinationLiquidity: this.
|
|
1887
|
+
userDestinationLiquidity: this.getUserTokenAccountAddress(this.outflowReserve),
|
|
1965
1888
|
placeholderUserDestinationCollateral: this.kaminoMarket.programId,
|
|
1966
1889
|
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
1967
1890
|
liquidityTokenProgram: this.outflowReserve.getLiquidityTokenProgram(),
|
|
@@ -1980,9 +1903,6 @@ export class KaminoAction {
|
|
|
1980
1903
|
if (!this.outflowReserve) {
|
|
1981
1904
|
throw Error(`Withdraw reserve during liquidation is not defined`);
|
|
1982
1905
|
}
|
|
1983
|
-
if (!this.additionalTokenAccountAddress) {
|
|
1984
|
-
throw Error(`Liquidating token account address is not defined`);
|
|
1985
|
-
}
|
|
1986
1906
|
|
|
1987
1907
|
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
1988
1908
|
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
@@ -2009,9 +1929,9 @@ export class KaminoAction {
|
|
|
2009
1929
|
withdrawReserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
2010
1930
|
withdrawReserveCollateralSupply: this.outflowReserve.state.collateral.supplyVault,
|
|
2011
1931
|
withdrawReserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
2012
|
-
userSourceLiquidity: this.
|
|
2013
|
-
userDestinationCollateral: this.
|
|
2014
|
-
userDestinationLiquidity: this.
|
|
1932
|
+
userSourceLiquidity: this.getUserTokenAccountAddress(this.reserve),
|
|
1933
|
+
userDestinationCollateral: this.getUserCollateralAccountAddress(this.outflowReserve),
|
|
1934
|
+
userDestinationLiquidity: this.getUserTokenAccountAddress(this.outflowReserve),
|
|
2015
1935
|
withdrawReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
|
|
2016
1936
|
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
2017
1937
|
repayLiquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
@@ -2032,9 +1952,6 @@ export class KaminoAction {
|
|
|
2032
1952
|
if (!this.outflowReserve) {
|
|
2033
1953
|
throw Error(`Withdraw reserve during liquidation is not defined`);
|
|
2034
1954
|
}
|
|
2035
|
-
if (!this.additionalTokenAccountAddress) {
|
|
2036
|
-
throw Error(`Liquidating token account address is not defined`);
|
|
2037
|
-
}
|
|
2038
1955
|
|
|
2039
1956
|
const depositReservesList = this.getAdditionalDepositReservesList();
|
|
2040
1957
|
const depositReserveAccountMetas = depositReservesList.map((reserve) => {
|
|
@@ -2085,9 +2002,9 @@ export class KaminoAction {
|
|
|
2085
2002
|
withdrawReserveCollateralMint: this.outflowReserve.getCTokenMint(),
|
|
2086
2003
|
withdrawReserveCollateralSupply: this.outflowReserve.state.collateral.supplyVault,
|
|
2087
2004
|
withdrawReserveLiquiditySupply: this.outflowReserve.state.liquidity.supplyVault,
|
|
2088
|
-
userSourceLiquidity: this.
|
|
2089
|
-
userDestinationCollateral: this.
|
|
2090
|
-
userDestinationLiquidity: this.
|
|
2005
|
+
userSourceLiquidity: this.getUserTokenAccountAddress(this.reserve),
|
|
2006
|
+
userDestinationCollateral: this.getUserCollateralAccountAddress(this.outflowReserve),
|
|
2007
|
+
userDestinationLiquidity: this.getUserTokenAccountAddress(this.outflowReserve),
|
|
2091
2008
|
withdrawReserveLiquidityFeeReceiver: this.outflowReserve.state.liquidity.feeVault,
|
|
2092
2009
|
collateralTokenProgram: TOKEN_PROGRAM_ID,
|
|
2093
2010
|
repayLiquidityTokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
@@ -2920,7 +2837,7 @@ export class KaminoAction {
|
|
|
2920
2837
|
reserveLiquidityMint: this.reserve.getLiquidityMint(),
|
|
2921
2838
|
referrerTokenState: referrerTokenStateAddress,
|
|
2922
2839
|
reserveSupplyLiquidity: this.reserve.state.liquidity.supplyVault,
|
|
2923
|
-
referrerTokenAccount: this.
|
|
2840
|
+
referrerTokenAccount: this.getUserTokenAccountAddress(this.reserve),
|
|
2924
2841
|
lendingMarketAuthority: this.kaminoMarket.getLendingMarketAuthority(),
|
|
2925
2842
|
tokenProgram: this.reserve.getLiquidityTokenProgram(),
|
|
2926
2843
|
},
|
|
@@ -2947,7 +2864,7 @@ export class KaminoAction {
|
|
|
2947
2864
|
this.reserve.getLiquidityMint(),
|
|
2948
2865
|
this.owner,
|
|
2949
2866
|
this.reserve.getLiquidityTokenProgram(),
|
|
2950
|
-
this.
|
|
2867
|
+
this.getUserTokenAccountAddress(this.reserve)
|
|
2951
2868
|
);
|
|
2952
2869
|
|
|
2953
2870
|
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
@@ -2956,7 +2873,7 @@ export class KaminoAction {
|
|
|
2956
2873
|
|
|
2957
2874
|
if (action === 'liquidate') {
|
|
2958
2875
|
if (!this.outflowReserve) {
|
|
2959
|
-
throw new Error(`Outflow reserve state not found ${this.
|
|
2876
|
+
throw new Error(`Outflow reserve state not found ${this.secondaryMint}`);
|
|
2960
2877
|
}
|
|
2961
2878
|
|
|
2962
2879
|
const [, createUserTokenAccountIx] = createAssociatedTokenAccountIdempotentInstruction(
|
|
@@ -2964,40 +2881,36 @@ export class KaminoAction {
|
|
|
2964
2881
|
this.outflowReserve.getLiquidityMint(),
|
|
2965
2882
|
this.owner,
|
|
2966
2883
|
this.outflowReserve.getLiquidityTokenProgram(),
|
|
2967
|
-
this.
|
|
2884
|
+
this.getUserTokenAccountAddress(this.outflowReserve)
|
|
2968
2885
|
);
|
|
2969
2886
|
|
|
2970
2887
|
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
2971
|
-
this.setupIxsLabels.unshift(`CreateUserAta[${this.
|
|
2888
|
+
this.setupIxsLabels.unshift(`CreateUserAta[${this.getUserTokenAccountAddress(this.outflowReserve).toBase58()}]`);
|
|
2972
2889
|
|
|
2973
2890
|
const [, createUserCollateralAccountIx] = createAssociatedTokenAccountIdempotentInstruction(
|
|
2974
2891
|
this.owner,
|
|
2975
2892
|
this.outflowReserve.getCTokenMint(),
|
|
2976
2893
|
this.owner,
|
|
2977
2894
|
TOKEN_PROGRAM_ID,
|
|
2978
|
-
this.
|
|
2895
|
+
this.getUserCollateralAccountAddress(this.outflowReserve)
|
|
2979
2896
|
);
|
|
2980
2897
|
|
|
2981
2898
|
this.setupIxs.unshift(createUserCollateralAccountIx);
|
|
2982
|
-
this.setupIxsLabels.unshift(
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
throw new Error(`Additional token account address not found ${this.mint}`);
|
|
2986
|
-
}
|
|
2899
|
+
this.setupIxsLabels.unshift(
|
|
2900
|
+
`CreateCollateralUserAta[${this.getUserCollateralAccountAddress(this.outflowReserve).toString()}]`
|
|
2901
|
+
);
|
|
2987
2902
|
}
|
|
2988
2903
|
|
|
2989
2904
|
if (action === 'depositAndBorrow' || (action === 'repayAndWithdraw' && !this.secondaryMint?.equals(NATIVE_MINT))) {
|
|
2990
|
-
if (!this.additionalTokenAccountAddress) {
|
|
2991
|
-
throw new Error(`Additional token account address not found ${this.secondaryMint}`);
|
|
2992
|
-
}
|
|
2993
|
-
|
|
2994
2905
|
if (!this.outflowReserve) {
|
|
2995
2906
|
throw new Error(`Outflow reserve state not found ${this.mint}`);
|
|
2996
2907
|
}
|
|
2997
2908
|
|
|
2909
|
+
const additionalUserTokenAccountAddress = this.getUserTokenAccountAddress(this.outflowReserve);
|
|
2910
|
+
|
|
2998
2911
|
const additionalUserTokenAccountInfo = await this.kaminoMarket
|
|
2999
2912
|
.getConnection()
|
|
3000
|
-
.getAccountInfo(
|
|
2913
|
+
.getAccountInfo(additionalUserTokenAccountAddress);
|
|
3001
2914
|
|
|
3002
2915
|
if (!additionalUserTokenAccountInfo) {
|
|
3003
2916
|
const [, createUserTokenAccountIx] = createAssociatedTokenAccountIdempotentInstruction(
|
|
@@ -3005,7 +2918,7 @@ export class KaminoAction {
|
|
|
3005
2918
|
this.outflowReserve.getLiquidityMint(),
|
|
3006
2919
|
this.owner,
|
|
3007
2920
|
this.outflowReserve.getLiquidityTokenProgram(),
|
|
3008
|
-
|
|
2921
|
+
additionalUserTokenAccountAddress
|
|
3009
2922
|
);
|
|
3010
2923
|
|
|
3011
2924
|
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
@@ -3019,23 +2932,24 @@ export class KaminoAction {
|
|
|
3019
2932
|
this.reserve.getLiquidityMint(),
|
|
3020
2933
|
this.owner,
|
|
3021
2934
|
this.reserve.getLiquidityTokenProgram(),
|
|
3022
|
-
this.
|
|
2935
|
+
this.getUserTokenAccountAddress(this.reserve)
|
|
3023
2936
|
);
|
|
3024
|
-
this.
|
|
3025
|
-
this.
|
|
2937
|
+
this.setupIxs.unshift(createUserTokenAccountIx);
|
|
2938
|
+
this.setupIxsLabels.unshift(`CreateUserAta[${this.getUserTokenAccountAddress(this.reserve).toBase58()}]`);
|
|
3026
2939
|
}
|
|
3027
2940
|
if (action === 'mint') {
|
|
3028
|
-
const collateralMintPubkey = this.reserve.getCTokenMint();
|
|
3029
2941
|
const [, createUserCollateralAccountIx] = createAssociatedTokenAccountIdempotentInstruction(
|
|
3030
2942
|
this.owner,
|
|
3031
|
-
|
|
2943
|
+
this.reserve.getCTokenMint(),
|
|
3032
2944
|
this.owner,
|
|
3033
2945
|
TOKEN_PROGRAM_ID,
|
|
3034
|
-
this.
|
|
2946
|
+
this.getUserCollateralAccountAddress(this.reserve)
|
|
3035
2947
|
);
|
|
3036
2948
|
|
|
3037
2949
|
this.setupIxs.unshift(createUserCollateralAccountIx);
|
|
3038
|
-
this.setupIxsLabels.unshift(
|
|
2950
|
+
this.setupIxsLabels.unshift(
|
|
2951
|
+
`CreateCollateralUserAta[${this.getUserCollateralAccountAddress(this.reserve).toString()}]`
|
|
2952
|
+
);
|
|
3039
2953
|
}
|
|
3040
2954
|
}
|
|
3041
2955
|
|
|
@@ -3077,12 +2991,14 @@ export class KaminoAction {
|
|
|
3077
2991
|
);
|
|
3078
2992
|
}
|
|
3079
2993
|
|
|
3080
|
-
let userTokenAccountAddress = this.
|
|
2994
|
+
let userTokenAccountAddress = this.getUserTokenAccountAddress(this.reserve);
|
|
3081
2995
|
if (this.secondaryMint?.equals(NATIVE_MINT)) {
|
|
3082
|
-
if (!this.
|
|
3083
|
-
throw new Error(`
|
|
2996
|
+
if (!this.outflowReserve) {
|
|
2997
|
+
throw new Error(`Outflow reserve state not found ${this.secondaryMint}`);
|
|
3084
2998
|
}
|
|
3085
|
-
|
|
2999
|
+
|
|
3000
|
+
const additionalUserTokenAccountAddress = this.getUserTokenAccountAddress(this.outflowReserve);
|
|
3001
|
+
userTokenAccountAddress = additionalUserTokenAccountAddress;
|
|
3086
3002
|
}
|
|
3087
3003
|
|
|
3088
3004
|
const userWSOLAccountInfo = await this.kaminoMarket.getConnection().getAccountInfo(userTokenAccountAddress);
|
|
@@ -3094,7 +3010,7 @@ export class KaminoAction {
|
|
|
3094
3010
|
action === 'deposit' ||
|
|
3095
3011
|
action === 'repay' ||
|
|
3096
3012
|
action === 'mint' ||
|
|
3097
|
-
(action === 'liquidate' && this.
|
|
3013
|
+
(action === 'liquidate' && this.mint?.equals(NATIVE_MINT)); // only sync WSOL amount if liquidator repays SOL which is secondaryMint
|
|
3098
3014
|
|
|
3099
3015
|
const transferLamportsIx = SystemProgram.transfer({
|
|
3100
3016
|
fromPubkey: this.owner,
|
|
@@ -3163,16 +3079,6 @@ export class KaminoAction {
|
|
|
3163
3079
|
throw new Error('reserve states are not fetched');
|
|
3164
3080
|
}
|
|
3165
3081
|
|
|
3166
|
-
const {
|
|
3167
|
-
userTokenAccountAddress: userOutflowTokenAccountAddress,
|
|
3168
|
-
userCollateralAccountAddress: userOutflowCollateralAccountAddress,
|
|
3169
|
-
} = KaminoAction.getUserAccountAddresses(payer, outflowReserve.state);
|
|
3170
|
-
|
|
3171
|
-
const {
|
|
3172
|
-
userTokenAccountAddress: userInflowTokenAccountAddress,
|
|
3173
|
-
userCollateralAccountAddress: userInflowCollateralAccountAddress,
|
|
3174
|
-
} = KaminoAction.getUserAccountAddresses(payer, inflowReserve.state);
|
|
3175
|
-
|
|
3176
3082
|
const { kaminoObligation, depositReserves, borrowReserves, distinctReserveCount } =
|
|
3177
3083
|
await KaminoAction.loadObligation(
|
|
3178
3084
|
action,
|
|
@@ -3184,30 +3090,12 @@ export class KaminoAction {
|
|
|
3184
3090
|
);
|
|
3185
3091
|
const referrerKey = await this.getReferrerKey(kaminoMarket, payer, kaminoObligation, referrer);
|
|
3186
3092
|
|
|
3187
|
-
let userTokenAccountAddress: PublicKey;
|
|
3188
|
-
let userCollateralAccountAddress: PublicKey;
|
|
3189
|
-
let additionalUserTokenAccountAddress: PublicKey;
|
|
3190
3093
|
let secondaryMint: PublicKey;
|
|
3191
3094
|
let primaryMint: PublicKey;
|
|
3192
3095
|
|
|
3193
|
-
if (action === 'liquidate') {
|
|
3194
|
-
userTokenAccountAddress = userOutflowTokenAccountAddress;
|
|
3195
|
-
userCollateralAccountAddress = userOutflowCollateralAccountAddress;
|
|
3196
|
-
additionalUserTokenAccountAddress = userInflowTokenAccountAddress;
|
|
3197
|
-
primaryMint = outflowTokenMint;
|
|
3198
|
-
secondaryMint = inflowTokenMint;
|
|
3199
|
-
} else if (action === 'depositAndBorrow') {
|
|
3200
|
-
userTokenAccountAddress = userInflowTokenAccountAddress;
|
|
3201
|
-
userCollateralAccountAddress = userInflowCollateralAccountAddress;
|
|
3202
|
-
additionalUserTokenAccountAddress = userOutflowTokenAccountAddress;
|
|
3096
|
+
if (action === 'liquidate' || action === 'depositAndBorrow' || action === 'repayAndWithdraw') {
|
|
3203
3097
|
primaryMint = inflowTokenMint;
|
|
3204
3098
|
secondaryMint = outflowTokenMint;
|
|
3205
|
-
} else if (action === 'repayAndWithdraw') {
|
|
3206
|
-
primaryMint = inflowTokenMint;
|
|
3207
|
-
secondaryMint = outflowTokenMint;
|
|
3208
|
-
userTokenAccountAddress = userInflowTokenAccountAddress;
|
|
3209
|
-
userCollateralAccountAddress = userOutflowCollateralAccountAddress;
|
|
3210
|
-
additionalUserTokenAccountAddress = userOutflowTokenAccountAddress;
|
|
3211
3099
|
} else {
|
|
3212
3100
|
throw new Error('Invalid action');
|
|
3213
3101
|
}
|
|
@@ -3216,8 +3104,6 @@ export class KaminoAction {
|
|
|
3216
3104
|
kaminoMarket,
|
|
3217
3105
|
payer,
|
|
3218
3106
|
kaminoObligation || obligation,
|
|
3219
|
-
userTokenAccountAddress,
|
|
3220
|
-
userCollateralAccountAddress,
|
|
3221
3107
|
primaryMint,
|
|
3222
3108
|
distinctReserveCount,
|
|
3223
3109
|
inflowAmount,
|
|
@@ -3226,7 +3112,6 @@ export class KaminoAction {
|
|
|
3226
3112
|
inflowReserve,
|
|
3227
3113
|
currentSlot,
|
|
3228
3114
|
secondaryMint,
|
|
3229
|
-
additionalUserTokenAccountAddress,
|
|
3230
3115
|
outflowReserve,
|
|
3231
3116
|
outflowAmount,
|
|
3232
3117
|
referrerKey
|
|
@@ -3244,22 +3129,18 @@ export class KaminoAction {
|
|
|
3244
3129
|
throw new Error(`Reserve ${mint} not found in market ${kaminoMarket.getAddress().toBase58()}`);
|
|
3245
3130
|
}
|
|
3246
3131
|
|
|
3247
|
-
const [{
|
|
3132
|
+
const [{ createAtaIx }] = createAtasIdempotent(owner, [
|
|
3248
3133
|
{
|
|
3249
3134
|
mint: reserve.getLiquidityMint(),
|
|
3250
3135
|
tokenProgram: reserve.getLiquidityTokenProgram(),
|
|
3251
3136
|
},
|
|
3252
3137
|
]);
|
|
3253
3138
|
|
|
3254
|
-
const userTokenAccountAddress = ata;
|
|
3255
|
-
|
|
3256
3139
|
return {
|
|
3257
3140
|
axn: new KaminoAction(
|
|
3258
3141
|
kaminoMarket,
|
|
3259
3142
|
owner,
|
|
3260
3143
|
new VanillaObligation(kaminoMarket.programId),
|
|
3261
|
-
userTokenAccountAddress,
|
|
3262
|
-
PublicKey.default,
|
|
3263
3144
|
mint,
|
|
3264
3145
|
0,
|
|
3265
3146
|
new BN(0),
|
|
@@ -3336,6 +3217,18 @@ export class KaminoAction {
|
|
|
3336
3217
|
return referrerKey;
|
|
3337
3218
|
}
|
|
3338
3219
|
|
|
3220
|
+
getUserTokenAccountAddress(reserve: KaminoReserve): PublicKey {
|
|
3221
|
+
return getAssociatedTokenAddress(reserve.getLiquidityMint(), this.owner, true, reserve.getLiquidityTokenProgram());
|
|
3222
|
+
}
|
|
3223
|
+
|
|
3224
|
+
getTokenAccountAddressByUser(reserve: KaminoReserve, user: PublicKey): PublicKey {
|
|
3225
|
+
return getAssociatedTokenAddress(reserve.getLiquidityMint(), user, true, reserve.getLiquidityTokenProgram());
|
|
3226
|
+
}
|
|
3227
|
+
|
|
3228
|
+
getUserCollateralAccountAddress(reserve: KaminoReserve): PublicKey {
|
|
3229
|
+
return getAssociatedTokenAddress(reserve.getCTokenMint(), this.owner, true);
|
|
3230
|
+
}
|
|
3231
|
+
|
|
3339
3232
|
public static actionToIxs(action: KaminoAction): Array<TransactionInstruction> {
|
|
3340
3233
|
const ixs: TransactionInstruction[] = [...action.computeBudgetIxs, ...action.setupIxs];
|
|
3341
3234
|
ixs.push(...KaminoAction.actionToLendingIxs(action));
|
|
@@ -3362,13 +3255,13 @@ export class KaminoAction {
|
|
|
3362
3255
|
}
|
|
3363
3256
|
|
|
3364
3257
|
public static actionToLendingIxLabels(action: KaminoAction): Array<string> {
|
|
3365
|
-
const
|
|
3258
|
+
const labels: string[] = [];
|
|
3366
3259
|
for (let i = 0; i < action.lendingIxsLabels.length; i++) {
|
|
3367
|
-
|
|
3260
|
+
labels.push(action.lendingIxsLabels[i]);
|
|
3368
3261
|
if (i !== action.lendingIxsLabels.length - 1) {
|
|
3369
|
-
|
|
3262
|
+
labels.push(...action.inBetweenIxsLabels);
|
|
3370
3263
|
}
|
|
3371
3264
|
}
|
|
3372
|
-
return
|
|
3265
|
+
return labels;
|
|
3373
3266
|
}
|
|
3374
3267
|
}
|