@kamino-finance/klend-sdk 3.2.21 → 3.2.22
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.js
CHANGED
|
@@ -880,7 +880,7 @@ class KaminoAction {
|
|
|
880
880
|
}
|
|
881
881
|
addSupportIxsWithoutInitObligation(action_1, includeAtaIxns_1) {
|
|
882
882
|
return __awaiter(this, arguments, void 0, function* (action, includeAtaIxns, addAsSupportIx = 'setup', requestElevationGroup = false, addInitObligationForFarm = false, isClosingPosition = false, twoTokenAction = false, overrideElevationGroupRequest) {
|
|
883
|
-
var _a, _b;
|
|
883
|
+
var _a, _b, _c;
|
|
884
884
|
// TODO: why are we not doing this first?
|
|
885
885
|
if (includeAtaIxns) {
|
|
886
886
|
yield this.addAtaIxs(action);
|
|
@@ -999,59 +999,82 @@ class KaminoAction {
|
|
|
999
999
|
else {
|
|
1000
1000
|
this.addRefreshObligationIx(addAsSupportIx, false);
|
|
1001
1001
|
}
|
|
1002
|
-
if (
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
if ((action === 'depositAndBorrow' || action === 'borrow') && requestElevationGroup) {
|
|
1017
|
-
let emodeGroupsDebt = this.reserve.state.config.elevationGroups;
|
|
1018
|
-
let emodeGroupsColl = this.reserve.state.config.elevationGroups;
|
|
1019
|
-
let debtReserve = this.reserve.address;
|
|
1020
|
-
if (action === 'depositAndBorrow') {
|
|
1021
|
-
emodeGroupsDebt = this.outflowReserve.state.config.elevationGroups;
|
|
1022
|
-
debtReserve = this.outflowReserve.address;
|
|
1023
|
-
}
|
|
1024
|
-
else if (action === 'borrow') {
|
|
1025
|
-
const depositReserve = this.obligation.state.deposits.find((x) => !x.depositReserve.equals(web3_js_1.PublicKey.default)).depositReserve;
|
|
1026
|
-
const collReserve = this.kaminoMarket.getReserveByAddress(depositReserve);
|
|
1027
|
-
emodeGroupsColl = collReserve.state.config.elevationGroups;
|
|
1028
|
-
}
|
|
1029
|
-
const groups = this.kaminoMarket.state.elevationGroups;
|
|
1030
|
-
const commonElevationGroups = [...emodeGroupsColl].filter((item) => emodeGroupsDebt.includes(item) && item !== 0 && groups[item - 1].debtReserve.equals(debtReserve));
|
|
1031
|
-
console.log('Groups of coll reserve', emodeGroupsColl, 'Groups of debt reserve', emodeGroupsDebt, 'Common groups', commonElevationGroups);
|
|
1032
|
-
if (commonElevationGroups.length === 0) {
|
|
1033
|
-
console.log('No common elevation groups found, staying with default');
|
|
1002
|
+
if (requestElevationGroup) {
|
|
1003
|
+
if (action === 'repay') {
|
|
1004
|
+
const repayObligationLiquidity = this.obligation.borrows.get(this.reserve.address);
|
|
1005
|
+
if (!repayObligationLiquidity) {
|
|
1006
|
+
throw new Error(`Could not find debt reserve ${this.reserve.address} in obligation`);
|
|
1007
|
+
}
|
|
1008
|
+
if (new decimal_js_1.default(repayObligationLiquidity.amount).lte(new decimal_js_1.default(this.amount.toString())) &&
|
|
1009
|
+
this.obligation.borrows.size === 1 &&
|
|
1010
|
+
((_a = this.obligation) === null || _a === void 0 ? void 0 : _a.state.elevationGroup) !== 0) {
|
|
1011
|
+
this.addRefreshReserveIxs(allReservesExcludingCurrent, 'cleanup');
|
|
1012
|
+
// Skip the borrow reserve, since we repay in the same tx
|
|
1013
|
+
this.addRefreshObligationIx('cleanup', true);
|
|
1014
|
+
this.addRequestElevationIx(overrideElevationGroupRequest !== null && overrideElevationGroupRequest !== void 0 ? overrideElevationGroupRequest : 0, 'cleanup', true);
|
|
1015
|
+
}
|
|
1034
1016
|
}
|
|
1035
|
-
else {
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
}
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
if (action === '
|
|
1046
|
-
this.
|
|
1017
|
+
else if (action === 'depositAndBorrow' || action === 'borrow') {
|
|
1018
|
+
let newElevationGroup = -1;
|
|
1019
|
+
let addAsSupportIx = 'setup';
|
|
1020
|
+
if (overrideElevationGroupRequest !== undefined) {
|
|
1021
|
+
newElevationGroup = overrideElevationGroupRequest;
|
|
1022
|
+
}
|
|
1023
|
+
else {
|
|
1024
|
+
let emodeGroupsDebt = this.reserve.state.config.elevationGroups;
|
|
1025
|
+
let emodeGroupsColl = this.reserve.state.config.elevationGroups;
|
|
1026
|
+
let debtReserve = this.reserve.address;
|
|
1027
|
+
if (action === 'depositAndBorrow') {
|
|
1028
|
+
emodeGroupsDebt = this.outflowReserve.state.config.elevationGroups;
|
|
1029
|
+
debtReserve = this.outflowReserve.address;
|
|
1030
|
+
addAsSupportIx = 'inBetween';
|
|
1031
|
+
}
|
|
1032
|
+
else if (action === 'borrow') {
|
|
1033
|
+
const depositReserve = this.obligation.state.deposits.find((x) => !x.depositReserve.equals(web3_js_1.PublicKey.default)).depositReserve;
|
|
1034
|
+
const collReserve = this.kaminoMarket.getReserveByAddress(depositReserve);
|
|
1035
|
+
emodeGroupsColl = collReserve.state.config.elevationGroups;
|
|
1047
1036
|
addAsSupportIx = 'setup';
|
|
1048
1037
|
}
|
|
1049
|
-
|
|
1038
|
+
const groups = this.kaminoMarket.state.elevationGroups;
|
|
1039
|
+
const commonElevationGroups = [...emodeGroupsColl].filter((item) => emodeGroupsDebt.includes(item) && item !== 0 && groups[item - 1].debtReserve.equals(debtReserve));
|
|
1040
|
+
console.log('Groups of coll reserve', emodeGroupsColl, 'Groups of debt reserve', emodeGroupsDebt, 'Common groups', commonElevationGroups);
|
|
1041
|
+
if (commonElevationGroups.length === 0) {
|
|
1042
|
+
console.log('No common elevation groups found, staying with default');
|
|
1043
|
+
}
|
|
1044
|
+
else {
|
|
1045
|
+
const eModeGroupWithMaxLtvAndDebtReserve = commonElevationGroups.reduce((prev, curr) => {
|
|
1046
|
+
const prevGroup = groups.find((group) => group.id === prev);
|
|
1047
|
+
const currGroup = groups.find((group) => group.id === curr);
|
|
1048
|
+
return prevGroup.ltvPct > currGroup.ltvPct ? prev : curr;
|
|
1049
|
+
});
|
|
1050
|
+
const eModeGroup = groups.find((group) => group.id === eModeGroupWithMaxLtvAndDebtReserve).id;
|
|
1051
|
+
console.log('Setting eModeGroup to', eModeGroup);
|
|
1052
|
+
if (eModeGroup !== 0 && eModeGroup !== ((_b = this.obligation) === null || _b === void 0 ? void 0 : _b.state.elevationGroup)) {
|
|
1053
|
+
newElevationGroup = eModeGroup;
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
console.log('newElevationGroup', newElevationGroup, addAsSupportIx);
|
|
1058
|
+
if (newElevationGroup >= 0) {
|
|
1059
|
+
this.addRequestElevationIx(newElevationGroup, addAsSupportIx);
|
|
1050
1060
|
this.addRefreshReserveIxs(allReservesExcludingCurrent, addAsSupportIx);
|
|
1051
1061
|
this.addRefreshReserveIxs(currentReserveAddresses.toArray(), addAsSupportIx);
|
|
1052
1062
|
this.addRefreshObligationIx(addAsSupportIx);
|
|
1063
|
+
if (action === 'borrow') {
|
|
1064
|
+
this.obligation.refreshedStats.potentialElevationGroupUpdate = newElevationGroup;
|
|
1065
|
+
}
|
|
1053
1066
|
}
|
|
1054
1067
|
}
|
|
1068
|
+
else if (action === 'deposit' &&
|
|
1069
|
+
overrideElevationGroupRequest !== undefined &&
|
|
1070
|
+
overrideElevationGroupRequest !== ((_c = this.obligation) === null || _c === void 0 ? void 0 : _c.state.elevationGroup)) {
|
|
1071
|
+
const addAsSupportIx = 'setup';
|
|
1072
|
+
console.log('Deposit: Requesting elevation group', overrideElevationGroupRequest);
|
|
1073
|
+
this.addRequestElevationIx(overrideElevationGroupRequest, addAsSupportIx);
|
|
1074
|
+
this.addRefreshReserveIxs(allReservesExcludingCurrent, addAsSupportIx);
|
|
1075
|
+
this.addRefreshReserveIxs(currentReserveAddresses.toArray(), addAsSupportIx);
|
|
1076
|
+
this.addRefreshObligationIx(addAsSupportIx);
|
|
1077
|
+
}
|
|
1055
1078
|
}
|
|
1056
1079
|
if (addAsSupportIx === 'setup') {
|
|
1057
1080
|
// If this is an setup ixn (therefore not an in-between), it means it's either a one off action
|