@kamino-finance/klend-sdk 2.13.2 → 2.13.3

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.
@@ -154,4 +154,5 @@ export declare class KaminoAction {
154
154
  }>;
155
155
  getObligationPda(): PublicKey;
156
156
  getAdditionalDepositReservesList(): PublicKey[];
157
+ private static getReferrerKey;
157
158
  }
@@ -84,11 +84,7 @@ class KaminoAction {
84
84
  }
85
85
  const { userTokenAccountAddress, userCollateralAccountAddress } = KaminoAction.getUserAccountAddresses(payer !== null && payer !== void 0 ? payer : owner, reserve.state);
86
86
  const { kaminoObligation, depositReserves, borrowReserves, distinctReserveCount } = yield KaminoAction.loadObligation(action, kaminoMarket, owner, reserve.address, obligation);
87
- const [_, userMetadata] = yield kaminoMarket.getUserMetadata(owner);
88
- if (userMetadata) {
89
- referrer = userMetadata.referrer;
90
- }
91
- const referrerKey = kaminoObligation ? kaminoObligation.state.referrer : referrer;
87
+ const referrerKey = yield this.getReferrerKey(kaminoMarket, owner, kaminoObligation, referrer);
92
88
  return new KaminoAction(kaminoMarket, owner, kaminoObligation || obligation, userTokenAccountAddress, userCollateralAccountAddress, mint, distinctReserveCount, amount, depositReserves, borrowReserves, reserve, currentSlot, hostAta, undefined, undefined, undefined, undefined, referrerKey, payer);
93
89
  });
94
90
  }
@@ -151,7 +147,7 @@ class KaminoAction {
151
147
  if (!firstKaminoReserve) {
152
148
  throw new Error(`Reserve ${firstReserve.toBase58()} not found`);
153
149
  }
154
- const axn = yield KaminoAction.initialize('refreshObligation', '0', firstKaminoReserve === null || firstKaminoReserve === void 0 ? void 0 : firstKaminoReserve.getLiquidityMint(), obligation.state.owner, kaminoMarket, obligation, kaminoMarket.programId, currentSlot);
150
+ const axn = yield KaminoAction.initialize('refreshObligation', '0', firstKaminoReserve === null || firstKaminoReserve === void 0 ? void 0 : firstKaminoReserve.getLiquidityMint(), obligation.state.owner, kaminoMarket, obligation, undefined, currentSlot);
155
151
  if (extraComputeBudget > 0) {
156
152
  axn.addComputeBudgetIxn(extraComputeBudget);
157
153
  }
@@ -167,7 +163,7 @@ class KaminoAction {
167
163
  if (!firstKaminoReserve) {
168
164
  throw new Error(`Reserve ${firstReserve.toBase58()} not found`);
169
165
  }
170
- const axn = yield KaminoAction.initialize('requestElevationGroup', '0', firstKaminoReserve === null || firstKaminoReserve === void 0 ? void 0 : firstKaminoReserve.getLiquidityMint(), obligation.state.owner, kaminoMarket, obligation, kaminoMarket.programId, currentSlot);
166
+ const axn = yield KaminoAction.initialize('requestElevationGroup', '0', firstKaminoReserve === null || firstKaminoReserve === void 0 ? void 0 : firstKaminoReserve.getLiquidityMint(), obligation.state.owner, kaminoMarket, obligation, undefined, currentSlot);
171
167
  if (extraComputeBudget > 0) {
172
168
  axn.addComputeBudgetIxn(extraComputeBudget);
173
169
  }
@@ -1490,11 +1486,7 @@ class KaminoAction {
1490
1486
  const { userTokenAccountAddress: userOutflowTokenAccountAddress, userCollateralAccountAddress: userOutflowCollateralAccountAddress, } = KaminoAction.getUserAccountAddresses(payer, outflowReserve.state);
1491
1487
  const { userTokenAccountAddress: userInflowTokenAccountAddress, userCollateralAccountAddress: userInflowCollateralAccountAddress, } = KaminoAction.getUserAccountAddresses(payer, inflowReserve.state);
1492
1488
  const { kaminoObligation, depositReserves, borrowReserves, distinctReserveCount } = yield KaminoAction.loadObligation(action, kaminoMarket, obligationOwner, inflowReserve.address, obligation, outflowReserve.address);
1493
- const [_, userMetadata] = yield kaminoMarket.getUserMetadata(payer);
1494
- if (userMetadata) {
1495
- referrer = userMetadata.referrer;
1496
- }
1497
- const referrerKey = kaminoObligation ? kaminoObligation.state.referrer : referrer;
1489
+ const referrerKey = yield this.getReferrerKey(kaminoMarket, payer, kaminoObligation, referrer);
1498
1490
  let userTokenAccountAddress;
1499
1491
  let userCollateralAccountAddress;
1500
1492
  let additionalUserTokenAccountAddress;
@@ -1533,9 +1525,7 @@ class KaminoAction {
1533
1525
  if (reserve === undefined) {
1534
1526
  throw new Error(`Reserve ${mint} not found in market ${kaminoMarket.getAddress().toBase58()}`);
1535
1527
  }
1536
- const { atas, createAtasIxns } = yield (0, utils_1.getAtasWithCreateIxnsIfMissing)(kaminoMarket.getConnection(), owner, [
1537
- reserve.getLiquidityMint(),
1538
- ]);
1528
+ const { atas, createAtasIxns } = yield (0, utils_1.getAtasWithCreateIxnsIfMissing)(kaminoMarket.getConnection(), owner, [reserve.getLiquidityMint()], [reserve.getLiquidityTokenProgram()]);
1539
1529
  const userTokenAccountAddress = atas[0];
1540
1530
  return {
1541
1531
  axn: new KaminoAction(kaminoMarket, owner, new ObligationType_1.VanillaObligation(kaminoMarket.programId), userTokenAccountAddress, web3_js_1.PublicKey.default, mint, 0, new bn_js_1.default(0), [], [], reserve, currentSlot, hostAta, undefined, undefined, undefined, undefined, undefined),
@@ -1565,6 +1555,23 @@ class KaminoAction {
1565
1555
  }
1566
1556
  return depositReservesList;
1567
1557
  }
1558
+ static getReferrerKey(kaminoMarket, owner, kaminoObligation, referrer) {
1559
+ return __awaiter(this, void 0, void 0, function* () {
1560
+ let referrerKey = referrer;
1561
+ if (!referrer || referrer.equals(web3_js_1.PublicKey.default)) {
1562
+ if (kaminoObligation === null) {
1563
+ const [_, userMetadata] = yield kaminoMarket.getUserMetadata(owner);
1564
+ if (userMetadata) {
1565
+ referrerKey = userMetadata.referrer;
1566
+ }
1567
+ }
1568
+ else {
1569
+ referrerKey = kaminoObligation.state.referrer;
1570
+ }
1571
+ }
1572
+ return referrerKey;
1573
+ });
1574
+ }
1568
1575
  }
1569
1576
  exports.KaminoAction = KaminoAction;
1570
1577
  //# sourceMappingURL=action.js.map