@kamino-finance/klend-sdk 7.3.10-beta.0 → 7.3.10-beta.1

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.
Files changed (131) hide show
  1. package/dist/classes/action.d.ts +21 -91
  2. package/dist/classes/action.d.ts.map +1 -1
  3. package/dist/classes/action.js +152 -139
  4. package/dist/classes/action.js.map +1 -1
  5. package/dist/classes/actionTypes.d.ts +310 -0
  6. package/dist/classes/actionTypes.d.ts.map +1 -0
  7. package/dist/classes/actionTypes.js +3 -0
  8. package/dist/classes/actionTypes.js.map +1 -0
  9. package/dist/classes/configItems.d.ts +1 -6
  10. package/dist/classes/configItems.d.ts.map +1 -1
  11. package/dist/classes/configItems.js +1 -93
  12. package/dist/classes/configItems.js.map +1 -1
  13. package/dist/classes/farm_utils.d.ts +1 -1
  14. package/dist/classes/farm_utils.d.ts.map +1 -1
  15. package/dist/classes/farm_utils.js +3 -1
  16. package/dist/classes/farm_utils.js.map +1 -1
  17. package/dist/classes/market.d.ts +15 -10
  18. package/dist/classes/market.d.ts.map +1 -1
  19. package/dist/classes/market.js +49 -26
  20. package/dist/classes/market.js.map +1 -1
  21. package/dist/classes/obligation.d.ts +9 -9
  22. package/dist/classes/obligation.d.ts.map +1 -1
  23. package/dist/classes/obligation.js +48 -50
  24. package/dist/classes/obligation.js.map +1 -1
  25. package/dist/classes/obligationOrder.d.ts.map +1 -1
  26. package/dist/classes/obligationOrder.js +6 -3
  27. package/dist/classes/obligationOrder.js.map +1 -1
  28. package/dist/classes/reserve.d.ts +7 -3
  29. package/dist/classes/reserve.d.ts.map +1 -1
  30. package/dist/classes/reserve.js +31 -43
  31. package/dist/classes/reserve.js.map +1 -1
  32. package/dist/classes/shared.d.ts +3 -2
  33. package/dist/classes/shared.d.ts.map +1 -1
  34. package/dist/classes/vault.d.ts +28 -1
  35. package/dist/classes/vault.d.ts.map +1 -1
  36. package/dist/classes/vault.js +103 -6
  37. package/dist/classes/vault.js.map +1 -1
  38. package/dist/classes/vault_types.d.ts +2 -1
  39. package/dist/classes/vault_types.d.ts.map +1 -1
  40. package/dist/client/commands/borrow.d.ts +1 -1
  41. package/dist/client/commands/borrow.d.ts.map +1 -1
  42. package/dist/client/commands/borrow.js +11 -2
  43. package/dist/client/commands/borrow.js.map +1 -1
  44. package/dist/client/commands/deposit.d.ts +1 -1
  45. package/dist/client/commands/deposit.d.ts.map +1 -1
  46. package/dist/client/commands/deposit.js +11 -2
  47. package/dist/client/commands/deposit.js.map +1 -1
  48. package/dist/client/commands/printReserve.d.ts +1 -1
  49. package/dist/client/commands/printReserve.d.ts.map +1 -1
  50. package/dist/client/commands/printReserve.js +2 -4
  51. package/dist/client/commands/printReserve.js.map +1 -1
  52. package/dist/client/commands/repay.d.ts +1 -1
  53. package/dist/client/commands/repay.d.ts.map +1 -1
  54. package/dist/client/commands/repay.js +12 -2
  55. package/dist/client/commands/repay.js.map +1 -1
  56. package/dist/client/commands/withdraw.d.ts +1 -1
  57. package/dist/client/commands/withdraw.d.ts.map +1 -1
  58. package/dist/client/commands/withdraw.js +11 -2
  59. package/dist/client/commands/withdraw.js.map +1 -1
  60. package/dist/lending_operations/repay_with_collateral_calcs.d.ts +1 -1
  61. package/dist/lending_operations/repay_with_collateral_calcs.d.ts.map +1 -1
  62. package/dist/lending_operations/repay_with_collateral_calcs.js +2 -2
  63. package/dist/lending_operations/repay_with_collateral_calcs.js.map +1 -1
  64. package/dist/lending_operations/repay_with_collateral_operations.d.ts +4 -4
  65. package/dist/lending_operations/repay_with_collateral_operations.d.ts.map +1 -1
  66. package/dist/lending_operations/repay_with_collateral_operations.js +43 -10
  67. package/dist/lending_operations/repay_with_collateral_operations.js.map +1 -1
  68. package/dist/lending_operations/swap_collateral_operations.d.ts +4 -4
  69. package/dist/lending_operations/swap_collateral_operations.d.ts.map +1 -1
  70. package/dist/lending_operations/swap_collateral_operations.js +40 -21
  71. package/dist/lending_operations/swap_collateral_operations.js.map +1 -1
  72. package/dist/leverage/operations.d.ts +6 -6
  73. package/dist/leverage/operations.d.ts.map +1 -1
  74. package/dist/leverage/operations.js +167 -52
  75. package/dist/leverage/operations.js.map +1 -1
  76. package/dist/leverage/types.d.ts +2 -2
  77. package/dist/leverage/types.d.ts.map +1 -1
  78. package/dist/manager/client_kamino_manager.js +0 -2
  79. package/dist/manager/client_kamino_manager.js.map +1 -1
  80. package/dist/obligation_orders/price_based.js +5 -3
  81. package/dist/obligation_orders/price_based.js.map +1 -1
  82. package/dist/utils/Logger.d.ts +14 -0
  83. package/dist/utils/Logger.d.ts.map +1 -0
  84. package/dist/utils/Logger.js +12 -0
  85. package/dist/utils/Logger.js.map +1 -0
  86. package/dist/utils/ObligationType.d.ts +33 -1
  87. package/dist/utils/ObligationType.d.ts.map +1 -1
  88. package/dist/utils/ObligationType.js +81 -2
  89. package/dist/utils/ObligationType.js.map +1 -1
  90. package/dist/utils/api.d.ts +13 -4
  91. package/dist/utils/api.d.ts.map +1 -1
  92. package/dist/utils/api.js +33 -31
  93. package/dist/utils/api.js.map +1 -1
  94. package/dist/utils/userMetadata.d.ts +2 -2
  95. package/dist/utils/userMetadata.d.ts.map +1 -1
  96. package/dist/utils/userMetadata.js +49 -25
  97. package/dist/utils/userMetadata.js.map +1 -1
  98. package/dist/utils/validations.d.ts +1 -0
  99. package/dist/utils/validations.d.ts.map +1 -1
  100. package/dist/utils/validations.js +5 -0
  101. package/dist/utils/validations.js.map +1 -1
  102. package/package.json +1 -1
  103. package/src/classes/action.ts +346 -372
  104. package/src/classes/actionTypes.ts +295 -0
  105. package/src/classes/configItems.ts +1 -99
  106. package/src/classes/farm_utils.ts +5 -1
  107. package/src/classes/market.ts +74 -31
  108. package/src/classes/obligation.ts +54 -53
  109. package/src/classes/obligationOrder.ts +6 -3
  110. package/src/classes/reserve.ts +118 -122
  111. package/src/classes/shared.ts +4 -2
  112. package/src/classes/vault.ts +160 -7
  113. package/src/classes/vault_types.ts +2 -1
  114. package/src/client/client.ts +17 -18
  115. package/src/client/commands/borrow.ts +10 -9
  116. package/src/client/commands/deposit.ts +10 -9
  117. package/src/client/commands/printReserve.ts +2 -4
  118. package/src/client/commands/repay.ts +11 -10
  119. package/src/client/commands/withdraw.ts +15 -9
  120. package/src/lending_operations/repay_with_collateral_calcs.ts +3 -4
  121. package/src/lending_operations/repay_with_collateral_operations.ts +40 -38
  122. package/src/lending_operations/swap_collateral_operations.ts +47 -41
  123. package/src/leverage/operations.ts +168 -129
  124. package/src/leverage/types.ts +2 -2
  125. package/src/manager/client_kamino_manager.ts +0 -2
  126. package/src/obligation_orders/price_based.ts +7 -5
  127. package/src/utils/Logger.ts +14 -0
  128. package/src/utils/ObligationType.ts +92 -1
  129. package/src/utils/api.ts +56 -33
  130. package/src/utils/userMetadata.ts +64 -30
  131. package/src/utils/validations.ts +5 -0
@@ -32,15 +32,15 @@ async function main() {
32
32
  commands
33
33
  .command('print-borrow-rate')
34
34
  .option(`--url <string>`, 'The admin keypair file')
35
- .option(`--token <string>`, 'The token symbol')
35
+ .option(`--reserveAddress <string>`, 'The token symbol')
36
36
  .option(`--cluster <string>`, 'staging or mainnet-beta')
37
- .action(async ({ url, token, cluster }) => {
37
+ .action(async ({ url, reserveAddress, cluster }) => {
38
38
  const env = await initEnv(url);
39
39
 
40
40
  const programId = getProgramId(cluster);
41
41
  const kaminoMarket = await getMarket(env.c.rpc, programId);
42
42
 
43
- const reserve = kaminoMarket.getReserveBySymbol(token);
43
+ const reserve = kaminoMarket.getReserveByAddress(reserveAddress);
44
44
 
45
45
  const slot = await env.c.rpc.getSlot().send();
46
46
 
@@ -130,10 +130,9 @@ async function main() {
130
130
  .command('print-reserve')
131
131
  .option(`--url <string>`, 'The admin keypair file')
132
132
  .option(`--reserve <string>`, 'Reserve address')
133
- .option(`--symbol <string>`, 'Symbol (optional)')
134
- .action(async ({ url, reserve, symbol }) => {
133
+ .action(async ({ url, reserve }) => {
135
134
  const env = await initEnv(url);
136
- await printReserve(env.c.rpc, reserve, symbol);
135
+ await printReserve(env.c.rpc, reserve);
137
136
  });
138
137
 
139
138
  commands
@@ -148,48 +147,48 @@ async function main() {
148
147
  .command('deposit')
149
148
  .option(`--url <string>`, 'Custom RPC URL')
150
149
  .option(`--owner <string>`, 'Custom RPC URL')
151
- .option(`--token <string>`, 'Custom RPC URL')
150
+ .option(`--reserveAddress <string>`, 'Custom RPC URL')
152
151
  .option(`--amount <string>`, 'Custom RPC URL')
153
- .action(async ({ url, owner, token, amount }) => {
152
+ .action(async ({ url, owner, reserveAddress, amount }) => {
154
153
  const depositAmount = new BN(amount);
155
154
  const env = await initEnv(url, owner);
156
- await deposit(env, 'execute', token, depositAmount);
155
+ await deposit(env, 'execute', reserveAddress, depositAmount);
157
156
  });
158
157
 
159
158
  commands
160
159
  .command('withdraw')
161
160
  .option(`--url <string>`, 'Custom RPC URL')
162
161
  .option(`--owner <string>`, 'Custom RPC URL')
163
- .option(`--token <string>`, 'Custom RPC URL')
162
+ .option(`--reserveAddress <string>`, 'Custom RPC URL')
164
163
  .option(`--amount <string>`, 'Custom RPC URL')
165
- .action(async ({ url, owner, token, amount }) => {
164
+ .action(async ({ url, owner, reserveAddress, amount }) => {
166
165
  const withdrawAmount = new BN(amount);
167
166
  const env = await initEnv(url, owner);
168
- await withdraw(env, 'execute', token, withdrawAmount);
167
+ await withdraw(env, 'execute', reserveAddress, withdrawAmount);
169
168
  });
170
169
 
171
170
  commands
172
171
  .command('borrow')
173
172
  .option(`--url <string>`, 'Custom RPC URL')
174
173
  .option(`--owner <string>`, 'Custom RPC URL')
175
- .option(`--token <string>`, 'Custom RPC URL')
174
+ .option(`--reserveAddress <string>`, 'Custom RPC URL')
176
175
  .option(`--amount <string>`, 'Custom RPC URL')
177
- .action(async ({ url, owner, token, amount }) => {
176
+ .action(async ({ url, owner, reserveAddress, amount }) => {
178
177
  const borrowAmount = new BN(amount);
179
178
  const env = await initEnv(url, owner);
180
- await borrow(env, 'execute', token, borrowAmount);
179
+ await borrow(env, 'execute', reserveAddress, borrowAmount);
181
180
  });
182
181
 
183
182
  commands
184
183
  .command('repay')
185
184
  .option(`--url <string>`, 'Custom RPC URL')
186
185
  .option(`--owner <string>`, 'Custom RPC URL')
187
- .option(`--token <string>`, 'Custom RPC URL')
186
+ .option(`--reserveAddress <string>`, 'Custom RPC URL')
188
187
  .option(`--amount <string>`, 'Custom RPC URL')
189
- .action(async ({ url, owner, token, amount }) => {
188
+ .action(async ({ url, owner, reserveAddress, amount }) => {
190
189
  const repayAmount = new BN(amount);
191
190
  const env = await initEnv(url, owner);
192
- await repay(env, 'execute', token, repayAmount);
191
+ await repay(env, 'execute', reserveAddress, repayAmount);
193
192
  });
194
193
 
195
194
  commands
@@ -5,21 +5,22 @@ import { KaminoAction } from '../../classes';
5
5
  import { Scope } from '@kamino-finance/scope-sdk';
6
6
  import { CliEnv, SendTxMode } from '../tx/CliEnv';
7
7
  import { processTx } from '../tx/processor';
8
+ import { address } from '@solana/kit';
8
9
 
9
- export async function borrow(env: CliEnv, mode: SendTxMode, token: string, borrowAmount: BN): Promise<void> {
10
+ export async function borrow(env: CliEnv, mode: SendTxMode, reserveAddress: string, borrowAmount: BN): Promise<void> {
10
11
  const signer = await env.getSigner();
11
12
  const programId = getProgramId('staging');
12
13
  const kaminoMarket = await getMarket(env.c.rpc, programId);
13
14
  const scope = new Scope('mainnet-beta', env.c.rpc);
14
- const kaminoAction = await KaminoAction.buildBorrowTxns(
15
+ const kaminoAction = await KaminoAction.buildBorrowTxns({
15
16
  kaminoMarket,
16
- borrowAmount,
17
- kaminoMarket.getReserveBySymbol(token)!.getLiquidityMint(),
18
- signer,
19
- new VanillaObligation(STAGING_LENDING_MARKET),
20
- true,
21
- { scope, scopeConfigurations: await scope.getAllConfigurations() }
22
- );
17
+ amount: borrowAmount,
18
+ reserveAddress: address(reserveAddress),
19
+ owner: signer,
20
+ obligation: new VanillaObligation(STAGING_LENDING_MARKET),
21
+ useV2Ixs: true,
22
+ scopeRefreshConfig: { scope, scopeConfigurations: await scope.getAllConfigurations() },
23
+ });
23
24
  console.log('User obligation', await kaminoAction.getObligationPda());
24
25
 
25
26
  console.log('Borrow SetupIxs:', kaminoAction.setupIxsLabels);
@@ -5,21 +5,22 @@ import { Scope } from '@kamino-finance/scope-sdk';
5
5
  import { CliEnv, SendTxMode } from '../tx/CliEnv';
6
6
  import { getMarket, STAGING_LENDING_MARKET } from '../services/market';
7
7
  import { processTx } from '../tx/processor';
8
+ import { address } from '@solana/kit';
8
9
 
9
- export async function deposit(env: CliEnv, mode: SendTxMode, token: string, depositAmount: BN): Promise<void> {
10
+ export async function deposit(env: CliEnv, mode: SendTxMode, reserveAddress: string, depositAmount: BN): Promise<void> {
10
11
  const signer = await env.getSigner();
11
12
  const programId = getProgramId('staging');
12
13
  const kaminoMarket = await getMarket(env.c.rpc, programId);
13
14
  const scope = new Scope('mainnet-beta', env.c.rpc);
14
- const kaminoAction = await KaminoAction.buildDepositTxns(
15
+ const kaminoAction = await KaminoAction.buildDepositTxns({
15
16
  kaminoMarket,
16
- depositAmount,
17
- kaminoMarket.getReserveBySymbol(token)!.getLiquidityMint(),
18
- signer,
19
- new VanillaObligation(STAGING_LENDING_MARKET),
20
- true,
21
- { scope, scopeConfigurations: await scope.getAllConfigurations() }
22
- );
17
+ amount: depositAmount,
18
+ reserveAddress: address(reserveAddress),
19
+ owner: signer,
20
+ obligation: new VanillaObligation(STAGING_LENDING_MARKET),
21
+ useV2Ixs: true,
22
+ scopeRefreshConfig: { scope, scopeConfigurations: await scope.getAllConfigurations() },
23
+ });
23
24
  console.log('User obligation', await kaminoAction.getObligationPda());
24
25
 
25
26
  console.log('Deposit SetupIxs:', kaminoAction.setupIxsLabels);
@@ -2,12 +2,10 @@ import { getProgramId } from '../../utils';
2
2
  import { getMarket } from '../services/market';
3
3
  import { address, Rpc, SolanaRpcApi } from '@solana/kit';
4
4
 
5
- export async function printReserve(rpc: Rpc<SolanaRpcApi>, reserve?: string, symbol?: string): Promise<void> {
5
+ export async function printReserve(rpc: Rpc<SolanaRpcApi>, reserve: string): Promise<void> {
6
6
  const programId = getProgramId('staging');
7
7
  const kaminoMarket = await getMarket(rpc, programId);
8
- const result = reserve
9
- ? kaminoMarket.getReserveByAddress(address(reserve))
10
- : kaminoMarket.getReserveBySymbol(symbol!);
8
+ const result = kaminoMarket.getReserveByAddress(address(reserve));
11
9
  console.log(result);
12
10
  console.log(result?.stats?.reserveDepositLimit.toString());
13
11
  }
@@ -5,22 +5,23 @@ import { KaminoAction } from '../../classes';
5
5
  import { Scope } from '@kamino-finance/scope-sdk';
6
6
  import { processTx } from '../tx/processor';
7
7
  import { CliEnv, SendTxMode } from '../tx/CliEnv';
8
+ import { address } from '@solana/kit';
8
9
 
9
- export async function repay(env: CliEnv, mode: SendTxMode, token: string, borrowAmount: BN): Promise<void> {
10
+ export async function repay(env: CliEnv, mode: SendTxMode, reserveAddress: string, borrowAmount: BN): Promise<void> {
10
11
  const signer = await env.getSigner();
11
12
  const programId = getProgramId('staging');
12
13
  const kaminoMarket = await getMarket(env.c.rpc, programId);
13
14
  const scope = new Scope('mainnet-beta', env.c.rpc);
14
- const kaminoAction = await KaminoAction.buildRepayTxns(
15
+ const kaminoAction = await KaminoAction.buildRepayTxns({
15
16
  kaminoMarket,
16
- borrowAmount,
17
- kaminoMarket.getReserveBySymbol(token)!.getLiquidityMint(),
18
- signer,
19
- new VanillaObligation(STAGING_LENDING_MARKET),
20
- true,
21
- { scope, scopeConfigurations: await scope.getAllConfigurations() },
22
- await env.c.rpc.getSlot().send()
23
- );
17
+ amount: borrowAmount,
18
+ reserveAddress: address(reserveAddress),
19
+ owner: signer,
20
+ obligation: new VanillaObligation(STAGING_LENDING_MARKET),
21
+ useV2Ixs: true,
22
+ scopeRefreshConfig: { scope, scopeConfigurations: await scope.getAllConfigurations() },
23
+ currentSlot: await env.c.rpc.getSlot().send(),
24
+ });
24
25
  console.log('User obligation', await kaminoAction.getObligationPda());
25
26
 
26
27
  console.log('Repay SetupIxs:', kaminoAction.setupIxsLabels);
@@ -5,21 +5,27 @@ import { Scope } from '@kamino-finance/scope-sdk';
5
5
  import { CliEnv, SendTxMode } from '../tx/CliEnv';
6
6
  import { getMarket, STAGING_LENDING_MARKET } from '../services/market';
7
7
  import { processTx } from '../tx/processor';
8
+ import { address } from '@solana/kit';
8
9
 
9
- export async function withdraw(env: CliEnv, mode: SendTxMode, token: string, depositAmount: BN): Promise<void> {
10
+ export async function withdraw(
11
+ env: CliEnv,
12
+ mode: SendTxMode,
13
+ reserveAddress: string,
14
+ depositAmount: BN
15
+ ): Promise<void> {
10
16
  const signer = await env.getSigner();
11
17
  const programId = getProgramId('staging');
12
18
  const kaminoMarket = await getMarket(env.c.rpc, programId);
13
19
  const scope = new Scope('mainnet-beta', env.c.rpc);
14
- const kaminoAction = await KaminoAction.buildWithdrawTxns(
20
+ const kaminoAction = await KaminoAction.buildWithdrawTxns({
15
21
  kaminoMarket,
16
- depositAmount,
17
- kaminoMarket.getReserveBySymbol(token)!.getLiquidityMint(),
18
- signer,
19
- new VanillaObligation(STAGING_LENDING_MARKET),
20
- true,
21
- { scope, scopeConfigurations: await scope.getAllConfigurations() }
22
- );
22
+ amount: depositAmount,
23
+ reserveAddress: address(reserveAddress),
24
+ owner: signer,
25
+ obligation: new VanillaObligation(STAGING_LENDING_MARKET),
26
+ useV2Ixs: true,
27
+ scopeRefreshConfig: { scope, scopeConfigurations: await scope.getAllConfigurations() },
28
+ });
23
29
  console.log('User obligation', await kaminoAction.getObligationPda());
24
30
 
25
31
  console.log('Withdraw SetupIxs:', kaminoAction.setupIxsLabels);
@@ -174,7 +174,7 @@ export function estimateDebtRepaymentWithColl(props: {
174
174
  slippagePct: Decimal;
175
175
  flashLoanFeePct: Decimal;
176
176
  kaminoMarket: KaminoMarket;
177
- debtTokenMint: Address;
177
+ debtReserveAddress: Address;
178
178
  obligation: KaminoObligation;
179
179
  currentSlot: Slot;
180
180
  }): Decimal {
@@ -184,15 +184,14 @@ export function estimateDebtRepaymentWithColl(props: {
184
184
  slippagePct,
185
185
  flashLoanFeePct,
186
186
  kaminoMarket,
187
- debtTokenMint,
187
+ debtReserveAddress,
188
188
  obligation,
189
189
  currentSlot,
190
190
  } = props;
191
191
  const slippageMultiplier = new Decimal(1.0).add(slippagePct.div('100'));
192
192
  const flashLoanFeeMultiplier = new Decimal(1.0).add(flashLoanFeePct.div('100'));
193
193
 
194
- const debtReserve = kaminoMarket.getExistingReserveByMint(debtTokenMint);
195
-
194
+ const debtReserve = kaminoMarket.getExistingReserveByAddress(debtReserveAddress);
196
195
  const debtAfterSwap = collAmount.div(slippageMultiplier).div(priceDebtToColl);
197
196
  const debtAfterFlashLoanRepay = debtAfterSwap.div(flashLoanFeeMultiplier);
198
197
 
@@ -47,8 +47,8 @@ export type RepayWithCollInitialInputs<QuoteResponse> = {
47
47
 
48
48
  interface RepayWithCollSwapInputsProps<QuoteResponse> {
49
49
  kaminoMarket: KaminoMarket;
50
- debtTokenMint: Address;
51
- collTokenMint: Address;
50
+ debtReserveAddress: Address;
51
+ collReserveAddress: Address;
52
52
  owner: TransactionSigner;
53
53
  obligation: KaminoObligation;
54
54
  referrer: Option<Address>;
@@ -67,9 +67,9 @@ export enum MaxWithdrawLtvCheck {
67
67
  }
68
68
 
69
69
  export async function getRepayWithCollSwapInputs<QuoteResponse>({
70
- collTokenMint,
70
+ collReserveAddress,
71
71
  currentSlot,
72
- debtTokenMint,
72
+ debtReserveAddress,
73
73
  kaminoMarket,
74
74
  owner,
75
75
  obligation,
@@ -85,8 +85,10 @@ export async function getRepayWithCollSwapInputs<QuoteResponse>({
85
85
  flashLoanInfo: FlashLoanInfo;
86
86
  initialInputs: RepayWithCollInitialInputs<QuoteResponse>;
87
87
  }> {
88
- const collReserve = kaminoMarket.getExistingReserveByMint(collTokenMint);
89
- const debtReserve = kaminoMarket.getExistingReserveByMint(debtTokenMint);
88
+ const collReserve = kaminoMarket.getExistingReserveByAddress(collReserveAddress);
89
+ const debtReserve = kaminoMarket.getExistingReserveByAddress(debtReserveAddress);
90
+ const collTokenMint = collReserve.getLiquidityMint();
91
+ const debtTokenMint = debtReserve.getLiquidityMint();
90
92
 
91
93
  const {
92
94
  repayAmountLamports,
@@ -188,9 +190,9 @@ export async function getRepayWithCollIxs<QuoteResponse>({
188
190
  repayAmount,
189
191
  isClosingPosition,
190
192
  budgetAndPriorityFeeIxs,
191
- collTokenMint,
193
+ collReserveAddress,
192
194
  currentSlot,
193
- debtTokenMint,
195
+ debtReserveAddress,
194
196
  kaminoMarket,
195
197
  owner,
196
198
  obligation,
@@ -202,9 +204,9 @@ export async function getRepayWithCollIxs<QuoteResponse>({
202
204
  logger = console.log,
203
205
  }: RepayWithCollIxsProps<QuoteResponse>): Promise<Array<RepayWithCollIxsResponse<QuoteResponse>>> {
204
206
  const { swapInputs, initialInputs } = await getRepayWithCollSwapInputs({
205
- collTokenMint,
207
+ collReserveAddress,
206
208
  currentSlot,
207
- debtTokenMint,
209
+ debtReserveAddress,
208
210
  kaminoMarket,
209
211
  owner,
210
212
  obligation,
@@ -219,8 +221,8 @@ export async function getRepayWithCollIxs<QuoteResponse>({
219
221
  const { debtRepayAmountLamports, flashRepayAmountLamports, maxCollateralWithdrawLamports, swapQuote } = initialInputs;
220
222
  const { inputAmountLamports: collSwapInLamports } = swapInputs;
221
223
 
222
- const collReserve = kaminoMarket.getExistingReserveByMint(collTokenMint);
223
- const debtReserve = kaminoMarket.getExistingReserveByMint(debtTokenMint);
224
+ const collReserve = kaminoMarket.getExistingReserveByAddress(collReserveAddress);
225
+ const debtReserve = kaminoMarket.getExistingReserveByAddress(debtReserveAddress);
224
226
 
225
227
  // the client should use these values to prevent this input, but the tx may succeed, so we don't want to fail
226
228
  // there is also a chance that the tx will consume debt token from the user's ata which they would not expect
@@ -328,40 +330,40 @@ async function buildRepayWithCollateralIxs<QuoteResponse>(
328
330
  // 3. Repay using the flash borrowed funds & withdraw collateral to swap and pay the flash loan
329
331
  let repayAndWithdrawAction;
330
332
  if (maxWithdrawLtvCheck === MaxWithdrawLtvCheck.MAX_LTV) {
331
- repayAndWithdrawAction = await KaminoAction.buildRepayAndWithdrawTxns(
332
- market,
333
- isClosingPosition ? U64_MAX : debtRepayAmountLamports.toString(),
334
- debtReserve.getLiquidityMint(),
335
- isClosingPosition ? U64_MAX : collWithdrawLamports.toString(),
336
- collReserve.getLiquidityMint(),
337
- owner,
333
+ repayAndWithdrawAction = await KaminoAction.buildRepayAndWithdrawTxns({
334
+ kaminoMarket: market,
335
+ repayAmount: isClosingPosition ? U64_MAX : debtRepayAmountLamports.toString(),
336
+ repayReserveAddress: debtReserve.address,
337
+ withdrawAmount: isClosingPosition ? U64_MAX : collWithdrawLamports.toString(),
338
+ withdrawReserveAddress: collReserve.address,
339
+ payer: owner,
338
340
  currentSlot,
339
341
  obligation,
340
342
  useV2Ixs,
341
- undefined,
342
- 0,
343
- false,
343
+ scopeRefreshConfig: undefined,
344
+ extraComputeBudget: 0,
345
+ includeAtaIxs: false,
344
346
  requestElevationGroup,
345
- undefined,
346
- referrer
347
- );
347
+ initUserMetadata: undefined,
348
+ referrer,
349
+ });
348
350
  } else {
349
- repayAndWithdrawAction = await KaminoAction.buildRepayAndWithdrawV2Txns(
350
- market,
351
- isClosingPosition ? U64_MAX : debtRepayAmountLamports.toString(),
352
- debtReserve.getLiquidityMint(),
353
- isClosingPosition ? U64_MAX : collWithdrawLamports.toString(),
354
- collReserve.getLiquidityMint(),
355
- owner,
351
+ repayAndWithdrawAction = await KaminoAction.buildRepayAndWithdrawV2Txns({
352
+ kaminoMarket: market,
353
+ repayAmount: isClosingPosition ? U64_MAX : debtRepayAmountLamports.toString(),
354
+ repayReserveAddress: debtReserve.address,
355
+ withdrawAmount: isClosingPosition ? U64_MAX : collWithdrawLamports.toString(),
356
+ withdrawReserveAddress: collReserve.address,
357
+ payer: owner,
356
358
  currentSlot,
357
359
  obligation,
358
- undefined,
359
- 0,
360
- false,
360
+ scopeRefreshConfig: undefined,
361
+ extraComputeBudget: 0,
362
+ includeAtaIxs: false,
361
363
  requestElevationGroup,
362
- undefined,
363
- referrer
364
- );
364
+ initUserMetadata: undefined,
365
+ referrer,
366
+ });
365
367
  }
366
368
 
367
369
  // 4. Swap collateral to debt to repay flash loan
@@ -40,14 +40,14 @@ export interface SwapCollIxsInputs<QuoteResponse> {
40
40
  isClosingSourceColl: boolean;
41
41
 
42
42
  /**
43
- * The mint of the source collateral token (i.e. the current one).
43
+ * The address of the source collateral reserve (i.e. the current one).
44
44
  */
45
- sourceCollTokenMint: Address;
45
+ sourceCollReserveAddress: Address;
46
46
 
47
47
  /**
48
- * The mint of the target collateral token (i.e. the new one).
48
+ * The address of the target collateral reserve (i.e. the new one).
49
49
  */
50
- targetCollTokenMint: Address;
50
+ targetCollReserveAddress: Address;
51
51
 
52
52
  /**
53
53
  * An elevation group ID that the obligation should end up with after the collateral swap - it will be requested by
@@ -220,7 +220,7 @@ type SwapCollContext<QuoteResponse> = {
220
220
  function extractArgsAndContext<QuoteResponse>(
221
221
  inputs: SwapCollIxsInputs<QuoteResponse>
222
222
  ): [SwapCollArgs, SwapCollContext<QuoteResponse>] {
223
- if (inputs.sourceCollTokenMint === inputs.targetCollTokenMint) {
223
+ if (inputs.sourceCollReserveAddress === inputs.targetCollReserveAddress) {
224
224
  throw new Error(`Cannot swap from/to the same collateral`);
225
225
  }
226
226
  if (inputs.sourceCollSwapAmount.lte(0)) {
@@ -235,8 +235,14 @@ function extractArgsAndContext<QuoteResponse>(
235
235
  {
236
236
  budgetAndPriorityFeeIxs:
237
237
  inputs.budgetAndPriorityFeeIxs || getComputeBudgetAndPriorityFeeIxs(DEFAULT_MAX_COMPUTE_UNITS),
238
- sourceCollReserve: inputs.market.getExistingReserveByMint(inputs.sourceCollTokenMint, 'Current collateral'),
239
- targetCollReserve: inputs.market.getExistingReserveByMint(inputs.targetCollTokenMint, 'Target collateral'),
238
+ sourceCollReserve: inputs.market.getExistingReserveByAddress(
239
+ inputs.sourceCollReserveAddress,
240
+ 'Current collateral'
241
+ ),
242
+ targetCollReserve: inputs.market.getExistingReserveByAddress(
243
+ inputs.targetCollReserveAddress,
244
+ 'Target collateral'
245
+ ),
240
246
  logger: console.log,
241
247
  market: inputs.market,
242
248
  obligation: inputs.obligation,
@@ -395,22 +401,22 @@ async function getDepositTargetCollIxs(
395
401
  context: SwapCollContext<any>
396
402
  ): Promise<DepositTargetCollIxs> {
397
403
  const removesElevationGroup = mustRemoveElevationGroupBeforeDeposit(context);
398
- const depositCollAction = await KaminoAction.buildDepositTxns(
399
- context.market,
400
- targetCollAmount.mul(context.targetCollReserve.getMintFactor()).toString(), // in lamports
401
- context.targetCollReserve.getLiquidityMint(),
402
- context.owner,
403
- context.obligation,
404
- context.useV2Ixs,
405
- undefined, // we create the scope refresh ix outside of KaminoAction
406
- 0, // no extra compute budget
407
- false, // we do not need ATA ixs here (we construct and close them ourselves)
408
- removesElevationGroup, // we may need to (temporarily) remove the elevation group; the same or a different one will be set on withdraw, if requested
409
- { skipInitialization: true, skipLutCreation: true }, // we are dealing with an existing obligation, no need to create user metadata
410
- context.referrer,
411
- context.currentSlot,
412
- removesElevationGroup ? 0 : undefined // only applicable when removing the group
413
- );
404
+ const depositCollAction = await KaminoAction.buildDepositTxns({
405
+ kaminoMarket: context.market,
406
+ amount: targetCollAmount.mul(context.targetCollReserve.getMintFactor()).toString(), // in lamports
407
+ reserveAddress: context.targetCollReserve.address,
408
+ owner: context.owner,
409
+ obligation: context.obligation,
410
+ useV2Ixs: context.useV2Ixs,
411
+ scopeRefreshConfig: undefined, // we create the scope refresh ix outside of KaminoAction
412
+ extraComputeBudget: 0, // no extra compute budget
413
+ includeAtaIxs: false, // we do not need ATA ixs here (we construct and close them ourselves)
414
+ requestElevationGroup: removesElevationGroup, // we may need to (temporarily) remove the elevation group; the same or a different one will be set on withdraw, if requested
415
+ initUserMetadata: { skipInitialization: true, skipLutCreation: true }, // we are dealing with an existing obligation, no need to create user metadata
416
+ referrer: context.referrer,
417
+ currentSlot: context.currentSlot,
418
+ overrideElevationGroupRequest: removesElevationGroup ? 0 : undefined, // only applicable when removing the group
419
+ });
414
420
  return {
415
421
  ixs: KaminoAction.actionToIxs(depositCollAction),
416
422
  removesElevationGroup,
@@ -444,27 +450,27 @@ async function getWithdrawSourceCollIxs(
444
450
  ? U64_MAX
445
451
  : args.sourceCollSwapAmount.mul(context.sourceCollReserve.getMintFactor()).toString();
446
452
  const requestedElevationGroup = elevationGroupIdToRequestAfterWithdraw(args, depositRemovedElevationGroup, context);
447
- const withdrawCollAction = await KaminoAction.buildWithdrawTxns(
448
- context.market,
449
- withdrawnSourceCollLamports,
450
- context.sourceCollReserve.getLiquidityMint(),
451
- context.owner,
452
- context.obligation,
453
- context.useV2Ixs,
454
- undefined, // we create the scope refresh ix outside of KaminoAction
455
- 0, // no extra compute budget
456
- false, // we do not need ATA ixs here (we construct and close them ourselves)
457
- requestedElevationGroup !== undefined, // the `elevationGroupIdToRequestAfterWithdraw()` has already decided on this
458
- { skipInitialization: true, skipLutCreation: true }, // we are dealing with an existing obligation, no need to create user metadata
459
- context.referrer,
460
- context.currentSlot,
461
- requestedElevationGroup,
462
- context.obligation.deposits.has(context.targetCollReserve.address) // if our obligation already had the target coll...
453
+ const withdrawCollAction = await KaminoAction.buildWithdrawTxns({
454
+ kaminoMarket: context.market,
455
+ amount: withdrawnSourceCollLamports,
456
+ reserveAddress: context.sourceCollReserve.address,
457
+ owner: context.owner,
458
+ obligation: context.obligation,
459
+ useV2Ixs: context.useV2Ixs,
460
+ scopeRefreshConfig: undefined, // we create the scope refresh ix outside of KaminoAction
461
+ extraComputeBudget: 0, // no extra compute budget
462
+ includeAtaIxs: false, // we do not need ATA ixs here (we construct and close them ourselves)
463
+ requestElevationGroup: requestedElevationGroup !== undefined, // the `elevationGroupIdToRequestAfterWithdraw()` has already decided on this
464
+ initUserMetadata: { skipInitialization: true, skipLutCreation: true }, // we are dealing with an existing obligation, no need to create user metadata
465
+ referrer: context.referrer,
466
+ currentSlot: context.currentSlot,
467
+ overrideElevationGroupRequest: requestedElevationGroup,
468
+ obligationCustomizations: context.obligation.deposits.has(context.targetCollReserve.address) // if our obligation already had the target coll...
463
469
  ? undefined // ... then we need no customizations here, but otherwise...
464
470
  : {
465
471
  addedDepositReserves: [context.targetCollReserve.address], // ... we need to inform our infra that the obligation now has one more reserve that needs refreshing.
466
- }
467
- );
472
+ },
473
+ });
468
474
  return KaminoAction.actionToIxs(withdrawCollAction);
469
475
  }
470
476