@kamino-finance/klend-sdk 5.0.7 → 5.1.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 (51) hide show
  1. package/README_KAMINO_MANAGER.md +24 -3
  2. package/dist/classes/action.d.ts +5 -1
  3. package/dist/classes/action.d.ts.map +1 -1
  4. package/dist/classes/action.js +39 -26
  5. package/dist/classes/action.js.map +1 -1
  6. package/dist/classes/manager.d.ts +45 -2
  7. package/dist/classes/manager.d.ts.map +1 -1
  8. package/dist/classes/manager.js +54 -0
  9. package/dist/classes/manager.js.map +1 -1
  10. package/dist/classes/vault.d.ts +56 -4
  11. package/dist/classes/vault.d.ts.map +1 -1
  12. package/dist/classes/vault.js +107 -3
  13. package/dist/classes/vault.js.map +1 -1
  14. package/dist/client_kamino_manager.d.ts.map +1 -1
  15. package/dist/client_kamino_manager.js +6 -0
  16. package/dist/client_kamino_manager.js.map +1 -1
  17. package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts +9 -3
  18. package/dist/idl_codegen_kamino_vault/accounts/VaultState.d.ts.map +1 -1
  19. package/dist/idl_codegen_kamino_vault/accounts/VaultState.js +42 -32
  20. package/dist/idl_codegen_kamino_vault/accounts/VaultState.js.map +1 -1
  21. package/dist/idl_codegen_kamino_vault/types/VaultConfigField.d.ts +10 -10
  22. package/dist/idl_codegen_kamino_vault/types/VaultConfigField.d.ts.map +1 -1
  23. package/dist/idl_codegen_kamino_vault/types/VaultConfigField.js +51 -52
  24. package/dist/idl_codegen_kamino_vault/types/VaultConfigField.js.map +1 -1
  25. package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.d.ts +2 -2
  26. package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.d.ts.map +1 -1
  27. package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.js +4 -4
  28. package/dist/idl_codegen_kamino_vault/types/WithdrawalCaps.js.map +1 -1
  29. package/dist/leverage/operations.d.ts.map +1 -1
  30. package/dist/leverage/operations.js +3 -9
  31. package/dist/leverage/operations.js.map +1 -1
  32. package/dist/referrals/instructions.d.ts +2 -1
  33. package/dist/referrals/instructions.d.ts.map +1 -1
  34. package/dist/referrals/instructions.js +13 -8
  35. package/dist/referrals/instructions.js.map +1 -1
  36. package/dist/utils/ata.d.ts +1 -2
  37. package/dist/utils/ata.d.ts.map +1 -1
  38. package/dist/utils/ata.js +8 -15
  39. package/dist/utils/ata.js.map +1 -1
  40. package/package.json +1 -1
  41. package/src/classes/action.ts +41 -33
  42. package/src/classes/manager.ts +80 -1
  43. package/src/classes/vault.ts +158 -4
  44. package/src/client.ts +4 -20
  45. package/src/client_kamino_manager.ts +8 -0
  46. package/src/idl_codegen_kamino_vault/accounts/VaultState.ts +178 -175
  47. package/src/idl_codegen_kamino_vault/types/VaultConfigField.ts +117 -116
  48. package/src/idl_codegen_kamino_vault/types/WithdrawalCaps.ts +30 -30
  49. package/src/leverage/operations.ts +3 -9
  50. package/src/referrals/instructions.ts +16 -9
  51. package/src/utils/ata.ts +8 -14
@@ -1,269 +1,270 @@
1
- import { PublicKey } from '@solana/web3.js'; // eslint-disable-line @typescript-eslint/no-unused-vars
2
- import BN from 'bn.js'; // eslint-disable-line @typescript-eslint/no-unused-vars
3
- import * as types from '../types'; // eslint-disable-line @typescript-eslint/no-unused-vars
4
- import * as borsh from '@coral-xyz/borsh';
1
+ import { PublicKey } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars
2
+ import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
3
+ import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
4
+ import * as borsh from "@coral-xyz/borsh"
5
5
 
6
6
  export interface PerformanceFeeBpsJSON {
7
- kind: 'PerformanceFeeBps';
7
+ kind: "PerformanceFeeBps"
8
8
  }
9
9
 
10
10
  export class PerformanceFeeBps {
11
- static readonly discriminator = 0;
12
- static readonly kind = 'PerformanceFeeBps';
13
- readonly discriminator = 0;
14
- readonly kind = 'PerformanceFeeBps';
11
+ static readonly discriminator = 0
12
+ static readonly kind = "PerformanceFeeBps"
13
+ readonly discriminator = 0
14
+ readonly kind = "PerformanceFeeBps"
15
15
 
16
16
  toJSON(): PerformanceFeeBpsJSON {
17
17
  return {
18
- kind: 'PerformanceFeeBps',
19
- };
18
+ kind: "PerformanceFeeBps",
19
+ }
20
20
  }
21
21
 
22
22
  toEncodable() {
23
23
  return {
24
24
  PerformanceFeeBps: {},
25
- };
25
+ }
26
26
  }
27
27
  }
28
28
 
29
29
  export interface ManagementFeeBpsJSON {
30
- kind: 'ManagementFeeBps';
30
+ kind: "ManagementFeeBps"
31
31
  }
32
32
 
33
33
  export class ManagementFeeBps {
34
- static readonly discriminator = 1;
35
- static readonly kind = 'ManagementFeeBps';
36
- readonly discriminator = 1;
37
- readonly kind = 'ManagementFeeBps';
34
+ static readonly discriminator = 1
35
+ static readonly kind = "ManagementFeeBps"
36
+ readonly discriminator = 1
37
+ readonly kind = "ManagementFeeBps"
38
38
 
39
39
  toJSON(): ManagementFeeBpsJSON {
40
40
  return {
41
- kind: 'ManagementFeeBps',
42
- };
41
+ kind: "ManagementFeeBps",
42
+ }
43
43
  }
44
44
 
45
45
  toEncodable() {
46
46
  return {
47
47
  ManagementFeeBps: {},
48
- };
48
+ }
49
49
  }
50
50
  }
51
51
 
52
52
  export interface MinDepositAmountJSON {
53
- kind: 'MinDepositAmount';
53
+ kind: "MinDepositAmount"
54
54
  }
55
55
 
56
56
  export class MinDepositAmount {
57
- static readonly discriminator = 2;
58
- static readonly kind = 'MinDepositAmount';
59
- readonly discriminator = 2;
60
- readonly kind = 'MinDepositAmount';
57
+ static readonly discriminator = 2
58
+ static readonly kind = "MinDepositAmount"
59
+ readonly discriminator = 2
60
+ readonly kind = "MinDepositAmount"
61
61
 
62
62
  toJSON(): MinDepositAmountJSON {
63
63
  return {
64
- kind: 'MinDepositAmount',
65
- };
64
+ kind: "MinDepositAmount",
65
+ }
66
66
  }
67
67
 
68
68
  toEncodable() {
69
69
  return {
70
70
  MinDepositAmount: {},
71
- };
71
+ }
72
72
  }
73
73
  }
74
74
 
75
75
  export interface MinWithdrawAmountJSON {
76
- kind: 'MinWithdrawAmount';
76
+ kind: "MinWithdrawAmount"
77
77
  }
78
78
 
79
79
  export class MinWithdrawAmount {
80
- static readonly discriminator = 3;
81
- static readonly kind = 'MinWithdrawAmount';
82
- readonly discriminator = 3;
83
- readonly kind = 'MinWithdrawAmount';
80
+ static readonly discriminator = 3
81
+ static readonly kind = "MinWithdrawAmount"
82
+ readonly discriminator = 3
83
+ readonly kind = "MinWithdrawAmount"
84
84
 
85
85
  toJSON(): MinWithdrawAmountJSON {
86
86
  return {
87
- kind: 'MinWithdrawAmount',
88
- };
87
+ kind: "MinWithdrawAmount",
88
+ }
89
89
  }
90
90
 
91
91
  toEncodable() {
92
92
  return {
93
93
  MinWithdrawAmount: {},
94
- };
94
+ }
95
95
  }
96
96
  }
97
97
 
98
98
  export interface MintInvestAmountJSON {
99
- kind: 'MintInvestAmount';
99
+ kind: "MintInvestAmount"
100
100
  }
101
101
 
102
102
  export class MintInvestAmount {
103
- static readonly discriminator = 4;
104
- static readonly kind = 'MintInvestAmount';
105
- readonly discriminator = 4;
106
- readonly kind = 'MintInvestAmount';
103
+ static readonly discriminator = 4
104
+ static readonly kind = "MintInvestAmount"
105
+ readonly discriminator = 4
106
+ readonly kind = "MintInvestAmount"
107
107
 
108
108
  toJSON(): MintInvestAmountJSON {
109
109
  return {
110
- kind: 'MintInvestAmount',
111
- };
110
+ kind: "MintInvestAmount",
111
+ }
112
112
  }
113
113
 
114
114
  toEncodable() {
115
115
  return {
116
116
  MintInvestAmount: {},
117
- };
117
+ }
118
118
  }
119
119
  }
120
120
 
121
121
  export interface MinInvestDelaySlotsJSON {
122
- kind: 'MinInvestDelaySlots';
122
+ kind: "MinInvestDelaySlots"
123
123
  }
124
124
 
125
125
  export class MinInvestDelaySlots {
126
- static readonly discriminator = 5;
127
- static readonly kind = 'MinInvestDelaySlots';
128
- readonly discriminator = 5;
129
- readonly kind = 'MinInvestDelaySlots';
126
+ static readonly discriminator = 5
127
+ static readonly kind = "MinInvestDelaySlots"
128
+ readonly discriminator = 5
129
+ readonly kind = "MinInvestDelaySlots"
130
130
 
131
131
  toJSON(): MinInvestDelaySlotsJSON {
132
132
  return {
133
- kind: 'MinInvestDelaySlots',
134
- };
133
+ kind: "MinInvestDelaySlots",
134
+ }
135
135
  }
136
136
 
137
137
  toEncodable() {
138
138
  return {
139
139
  MinInvestDelaySlots: {},
140
- };
140
+ }
141
141
  }
142
142
  }
143
143
 
144
144
  export interface CrankFundFeePerReserveJSON {
145
- kind: 'CrankFundFeePerReserve';
145
+ kind: "CrankFundFeePerReserve"
146
146
  }
147
147
 
148
148
  export class CrankFundFeePerReserve {
149
- static readonly discriminator = 6;
150
- static readonly kind = 'CrankFundFeePerReserve';
151
- readonly discriminator = 6;
152
- readonly kind = 'CrankFundFeePerReserve';
149
+ static readonly discriminator = 6
150
+ static readonly kind = "CrankFundFeePerReserve"
151
+ readonly discriminator = 6
152
+ readonly kind = "CrankFundFeePerReserve"
153
153
 
154
154
  toJSON(): CrankFundFeePerReserveJSON {
155
155
  return {
156
- kind: 'CrankFundFeePerReserve',
157
- };
156
+ kind: "CrankFundFeePerReserve",
157
+ }
158
158
  }
159
159
 
160
160
  toEncodable() {
161
161
  return {
162
162
  CrankFundFeePerReserve: {},
163
- };
163
+ }
164
164
  }
165
165
  }
166
166
 
167
167
  export interface PendingVaultAdminJSON {
168
- kind: 'PendingVaultAdmin';
168
+ kind: "PendingVaultAdmin"
169
169
  }
170
170
 
171
171
  export class PendingVaultAdmin {
172
- static readonly discriminator = 7;
173
- static readonly kind = 'PendingVaultAdmin';
174
- readonly discriminator = 7;
175
- readonly kind = 'PendingVaultAdmin';
172
+ static readonly discriminator = 7
173
+ static readonly kind = "PendingVaultAdmin"
174
+ readonly discriminator = 7
175
+ readonly kind = "PendingVaultAdmin"
176
176
 
177
177
  toJSON(): PendingVaultAdminJSON {
178
178
  return {
179
- kind: 'PendingVaultAdmin',
180
- };
179
+ kind: "PendingVaultAdmin",
180
+ }
181
181
  }
182
182
 
183
183
  toEncodable() {
184
184
  return {
185
185
  PendingVaultAdmin: {},
186
- };
186
+ }
187
187
  }
188
188
  }
189
189
 
190
190
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
191
191
  export function fromDecoded(obj: any): types.VaultConfigFieldKind {
192
- if (typeof obj !== 'object') {
193
- throw new Error('Invalid enum object');
192
+ if (typeof obj !== "object") {
193
+ throw new Error("Invalid enum object")
194
194
  }
195
195
 
196
- console.log('');
197
- if ('PerformanceFeeBps' in obj) {
198
- return new PerformanceFeeBps();
196
+ if ("PerformanceFeeBps" in obj) {
197
+ return new PerformanceFeeBps()
199
198
  }
200
- if ('ManagementFeeBps' in obj) {
201
- return new ManagementFeeBps();
199
+ if ("ManagementFeeBps" in obj) {
200
+ return new ManagementFeeBps()
202
201
  }
203
- if ('MinDepositAmount' in obj) {
204
- return new MinDepositAmount();
202
+ if ("MinDepositAmount" in obj) {
203
+ return new MinDepositAmount()
205
204
  }
206
- if ('MinWithdrawAmount' in obj) {
207
- return new MinWithdrawAmount();
205
+ if ("MinWithdrawAmount" in obj) {
206
+ return new MinWithdrawAmount()
208
207
  }
209
- if ('MintInvestAmount' in obj) {
210
- return new MintInvestAmount();
208
+ if ("MintInvestAmount" in obj) {
209
+ return new MintInvestAmount()
211
210
  }
212
- if ('MinInvestDelaySlots' in obj) {
213
- return new MinInvestDelaySlots();
211
+ if ("MinInvestDelaySlots" in obj) {
212
+ return new MinInvestDelaySlots()
214
213
  }
215
- if ('CrankFundFeePerReserve' in obj) {
216
- return new CrankFundFeePerReserve();
214
+ if ("CrankFundFeePerReserve" in obj) {
215
+ return new CrankFundFeePerReserve()
217
216
  }
218
- if ('PendingVaultAdmin' in obj) {
219
- return new PendingVaultAdmin();
217
+ if ("PendingVaultAdmin" in obj) {
218
+ return new PendingVaultAdmin()
220
219
  }
221
220
 
222
- throw new Error('Invalid enum object');
221
+ throw new Error("Invalid enum object")
223
222
  }
224
223
 
225
- export function fromJSON(obj: types.VaultConfigFieldJSON): types.VaultConfigFieldKind {
224
+ export function fromJSON(
225
+ obj: types.VaultConfigFieldJSON
226
+ ): types.VaultConfigFieldKind {
226
227
  switch (obj.kind) {
227
- case 'PerformanceFeeBps': {
228
- return new PerformanceFeeBps();
228
+ case "PerformanceFeeBps": {
229
+ return new PerformanceFeeBps()
229
230
  }
230
- case 'ManagementFeeBps': {
231
- return new ManagementFeeBps();
231
+ case "ManagementFeeBps": {
232
+ return new ManagementFeeBps()
232
233
  }
233
- case 'MinDepositAmount': {
234
- return new MinDepositAmount();
234
+ case "MinDepositAmount": {
235
+ return new MinDepositAmount()
235
236
  }
236
- case 'MinWithdrawAmount': {
237
- return new MinWithdrawAmount();
237
+ case "MinWithdrawAmount": {
238
+ return new MinWithdrawAmount()
238
239
  }
239
- case 'MintInvestAmount': {
240
- return new MintInvestAmount();
240
+ case "MintInvestAmount": {
241
+ return new MintInvestAmount()
241
242
  }
242
- case 'MinInvestDelaySlots': {
243
- return new MinInvestDelaySlots();
243
+ case "MinInvestDelaySlots": {
244
+ return new MinInvestDelaySlots()
244
245
  }
245
- case 'CrankFundFeePerReserve': {
246
- return new CrankFundFeePerReserve();
246
+ case "CrankFundFeePerReserve": {
247
+ return new CrankFundFeePerReserve()
247
248
  }
248
- case 'PendingVaultAdmin': {
249
- return new PendingVaultAdmin();
249
+ case "PendingVaultAdmin": {
250
+ return new PendingVaultAdmin()
250
251
  }
251
252
  }
252
253
  }
253
254
 
254
255
  export function layout(property?: string) {
255
256
  const ret = borsh.rustEnum([
256
- borsh.struct([], 'PerformanceFeeBps'),
257
- borsh.struct([], 'ManagementFeeBps'),
258
- borsh.struct([], 'MinDepositAmount'),
259
- borsh.struct([], 'MinWithdrawAmount'),
260
- borsh.struct([], 'MintInvestAmount'),
261
- borsh.struct([], 'MinInvestDelaySlots'),
262
- borsh.struct([], 'CrankFundFeePerReserve'),
263
- borsh.struct([], 'PendingVaultAdmin'),
264
- ]);
257
+ borsh.struct([], "PerformanceFeeBps"),
258
+ borsh.struct([], "ManagementFeeBps"),
259
+ borsh.struct([], "MinDepositAmount"),
260
+ borsh.struct([], "MinWithdrawAmount"),
261
+ borsh.struct([], "MintInvestAmount"),
262
+ borsh.struct([], "MinInvestDelaySlots"),
263
+ borsh.struct([], "CrankFundFeePerReserve"),
264
+ borsh.struct([], "PendingVaultAdmin"),
265
+ ])
265
266
  if (property !== undefined) {
266
- return ret.replicate(property);
267
+ return ret.replicate(property)
267
268
  }
268
- return ret;
269
+ return ret
269
270
  }
@@ -1,46 +1,46 @@
1
- import { PublicKey } from '@solana/web3.js'; // eslint-disable-line @typescript-eslint/no-unused-vars
2
- import BN from 'bn.js'; // eslint-disable-line @typescript-eslint/no-unused-vars
3
- import * as types from '../types'; // eslint-disable-line @typescript-eslint/no-unused-vars
4
- import * as borsh from '@coral-xyz/borsh';
1
+ import { PublicKey } from "@solana/web3.js" // eslint-disable-line @typescript-eslint/no-unused-vars
2
+ import BN from "bn.js" // eslint-disable-line @typescript-eslint/no-unused-vars
3
+ import * as types from "../types" // eslint-disable-line @typescript-eslint/no-unused-vars
4
+ import * as borsh from "@coral-xyz/borsh"
5
5
 
6
6
  export interface WithdrawalCapsFields {
7
- configCapacity: BN;
8
- currentTotal: BN;
9
- lastIntervalStartTimestamp: BN;
10
- configIntervalLengthSeconds: BN;
7
+ configCapacity: BN
8
+ currentTotal: BN
9
+ lastIntervalStartTimestamp: BN
10
+ configIntervalLengthSeconds: BN
11
11
  }
12
12
 
13
13
  export interface WithdrawalCapsJSON {
14
- configCapacity: string;
15
- currentTotal: string;
16
- lastIntervalStartTimestamp: string;
17
- configIntervalLengthSeconds: string;
14
+ configCapacity: string
15
+ currentTotal: string
16
+ lastIntervalStartTimestamp: string
17
+ configIntervalLengthSeconds: string
18
18
  }
19
19
 
20
20
  /** Reserve Withdrawal Caps State */
21
21
  export class WithdrawalCaps {
22
- readonly configCapacity: BN;
23
- readonly currentTotal: BN;
24
- readonly lastIntervalStartTimestamp: BN;
25
- readonly configIntervalLengthSeconds: BN;
22
+ readonly configCapacity: BN
23
+ readonly currentTotal: BN
24
+ readonly lastIntervalStartTimestamp: BN
25
+ readonly configIntervalLengthSeconds: BN
26
26
 
27
27
  constructor(fields: WithdrawalCapsFields) {
28
- this.configCapacity = fields.configCapacity;
29
- this.currentTotal = fields.currentTotal;
30
- this.lastIntervalStartTimestamp = fields.lastIntervalStartTimestamp;
31
- this.configIntervalLengthSeconds = fields.configIntervalLengthSeconds;
28
+ this.configCapacity = fields.configCapacity
29
+ this.currentTotal = fields.currentTotal
30
+ this.lastIntervalStartTimestamp = fields.lastIntervalStartTimestamp
31
+ this.configIntervalLengthSeconds = fields.configIntervalLengthSeconds
32
32
  }
33
33
 
34
34
  static layout(property?: string) {
35
35
  return borsh.struct(
36
36
  [
37
- borsh.i64('configCapacity'),
38
- borsh.i64('currentTotal'),
39
- borsh.u64('lastIntervalStartTimestamp'),
40
- borsh.u64('configIntervalLengthSeconds'),
37
+ borsh.i64("configCapacity"),
38
+ borsh.i64("currentTotal"),
39
+ borsh.u64("lastIntervalStartTimestamp"),
40
+ borsh.u64("configIntervalLengthSeconds"),
41
41
  ],
42
42
  property
43
- );
43
+ )
44
44
  }
45
45
 
46
46
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -50,7 +50,7 @@ export class WithdrawalCaps {
50
50
  currentTotal: obj.currentTotal,
51
51
  lastIntervalStartTimestamp: obj.lastIntervalStartTimestamp,
52
52
  configIntervalLengthSeconds: obj.configIntervalLengthSeconds,
53
- });
53
+ })
54
54
  }
55
55
 
56
56
  static toEncodable(fields: WithdrawalCapsFields) {
@@ -59,7 +59,7 @@ export class WithdrawalCaps {
59
59
  currentTotal: fields.currentTotal,
60
60
  lastIntervalStartTimestamp: fields.lastIntervalStartTimestamp,
61
61
  configIntervalLengthSeconds: fields.configIntervalLengthSeconds,
62
- };
62
+ }
63
63
  }
64
64
 
65
65
  toJSON(): WithdrawalCapsJSON {
@@ -68,7 +68,7 @@ export class WithdrawalCaps {
68
68
  currentTotal: this.currentTotal.toString(),
69
69
  lastIntervalStartTimestamp: this.lastIntervalStartTimestamp.toString(),
70
70
  configIntervalLengthSeconds: this.configIntervalLengthSeconds.toString(),
71
- };
71
+ }
72
72
  }
73
73
 
74
74
  static fromJSON(obj: WithdrawalCapsJSON): WithdrawalCaps {
@@ -77,10 +77,10 @@ export class WithdrawalCaps {
77
77
  currentTotal: new BN(obj.currentTotal),
78
78
  lastIntervalStartTimestamp: new BN(obj.lastIntervalStartTimestamp),
79
79
  configIntervalLengthSeconds: new BN(obj.configIntervalLengthSeconds),
80
- });
80
+ })
81
81
  }
82
82
 
83
83
  toEncodable() {
84
- return WithdrawalCaps.toEncodable(this);
84
+ return WithdrawalCaps.toEncodable(this)
85
85
  }
86
86
  }
@@ -526,9 +526,7 @@ async function buildDepositWithLeverageIxns(
526
526
  ...fillWsolAtaIxns,
527
527
  ...[flashBorrowIxn],
528
528
  ...kaminoDepositAndBorrowAction.setupIxs,
529
- ...[kaminoDepositAndBorrowAction.lendingIxs[0]],
530
- ...kaminoDepositAndBorrowAction.inBetweenIxs,
531
- ...[kaminoDepositAndBorrowAction.lendingIxs[1]],
529
+ ...KaminoAction.actionToLendingIxs(kaminoDepositAndBorrowAction),
532
530
  ...kaminoDepositAndBorrowAction.cleanupIxs,
533
531
  ...swapInstructions,
534
532
  ...[flashRepayIxn],
@@ -541,9 +539,7 @@ async function buildDepositWithLeverageIxns(
541
539
  ...[flashBorrowIxn],
542
540
  ...swapInstructions,
543
541
  ...kaminoDepositAndBorrowAction.setupIxs,
544
- ...[kaminoDepositAndBorrowAction.lendingIxs[0]],
545
- ...kaminoDepositAndBorrowAction.inBetweenIxs,
546
- ...[kaminoDepositAndBorrowAction.lendingIxs[1]],
542
+ ...KaminoAction.actionToLendingIxs(kaminoDepositAndBorrowAction),
547
543
  ...kaminoDepositAndBorrowAction.cleanupIxs,
548
544
  ...[flashRepayIxn],
549
545
  ];
@@ -930,9 +926,7 @@ export async function buildWithdrawWithLeverageIxns(
930
926
  ...fillWsolAtaIxns,
931
927
  ...[flashBorrowIxn],
932
928
  ...repayAndWithdrawAction.setupIxs,
933
- ...[repayAndWithdrawAction.lendingIxs[0]],
934
- ...repayAndWithdrawAction.inBetweenIxs,
935
- ...[repayAndWithdrawAction.lendingIxs[1]],
929
+ ...KaminoAction.actionToLendingIxs(repayAndWithdrawAction),
936
930
  ...repayAndWithdrawAction.cleanupIxs,
937
931
  ...swapInstructions,
938
932
  ...[flashRepayIxn],
@@ -1,6 +1,6 @@
1
1
  import { PublicKey, SYSVAR_RENT_PUBKEY, SystemProgram, TransactionInstruction, Connection } from '@solana/web3.js';
2
2
  import { KaminoMarket } from '../classes';
3
- import { checkIfAccountExists, referrerStatePda, referrerTokenStatePda, shortUrlPda, userMetadataPda } from '../utils';
3
+ import { PublicKeySet, referrerStatePda, referrerTokenStatePda, shortUrlPda, userMetadataPda } from '../utils';
4
4
  import {
5
5
  PROGRAM_ID,
6
6
  ReferrerState,
@@ -12,9 +12,11 @@ import {
12
12
  export const getInitAllReferrerTokenStateIxns = async ({
13
13
  referrer,
14
14
  kaminoMarket,
15
+ payer = referrer,
15
16
  }: {
16
17
  referrer: PublicKey;
17
18
  kaminoMarket: KaminoMarket;
19
+ payer?: PublicKey;
18
20
  }) => {
19
21
  if (referrer.equals(PublicKey.default)) {
20
22
  throw new Error('Referrer not set');
@@ -25,27 +27,32 @@ export const getInitAllReferrerTokenStateIxns = async ({
25
27
  const initReferrerTokenStateIxns: TransactionInstruction[] = [];
26
28
 
27
29
  const tokenStatesToCreate: [PublicKey, PublicKey][] = [];
28
- for (const reserve of kaminoMarket.reserves.values()) {
29
- const referrerTokenStateAddress = referrerTokenStatePda(referrer, reserve.address, kaminoMarket.programId)[0];
30
-
31
- if (!(await checkIfAccountExists(kaminoMarket.getConnection(), referrerTokenStateAddress))) {
32
- tokenStatesToCreate.push([referrerTokenStateAddress, reserve?.address]);
30
+ const reserves = kaminoMarket.getReserves();
31
+ const referrerTokenStates = reserves.map((reserve) => {
32
+ return referrerTokenStatePda(referrer, reserve.address, kaminoMarket.programId)[0];
33
+ });
34
+ const uniqueReferrerTokenStates = new PublicKeySet<PublicKey>(referrerTokenStates).toArray();
35
+ const accounts = await kaminoMarket.getConnection().getMultipleAccountsInfo(uniqueReferrerTokenStates);
36
+ for (let i = 0; i < uniqueReferrerTokenStates.length; i++) {
37
+ if (!accounts[i]) {
38
+ tokenStatesToCreate.push([uniqueReferrerTokenStates[i], reserves[i].address]);
33
39
  }
34
40
  }
35
41
 
36
42
  tokenStatesToCreate.forEach(([referrerTokenStateAddress, reserveAddress]) => {
37
43
  const initReferrerTokenStateIx = initReferrerTokenState(
38
44
  {
39
- referrer: referrer,
45
+ referrer,
40
46
  },
41
47
  {
42
48
  lendingMarket: kaminoMarket.getAddress(),
43
- payer: referrer,
49
+ payer,
44
50
  reserve: reserveAddress,
45
51
  referrerTokenState: referrerTokenStateAddress,
46
52
  rent: SYSVAR_RENT_PUBKEY,
47
53
  systemProgram: SystemProgram.programId,
48
- }
54
+ },
55
+ kaminoMarket.programId
49
56
  );
50
57
 
51
58
  initReferrerTokenStateIxns.push(initReferrerTokenStateIx);
package/src/utils/ata.ts CHANGED
@@ -98,11 +98,6 @@ export function createAtasIdempotent(
98
98
  return res;
99
99
  }
100
100
 
101
- export const checkIfAccountExists = async (connection: Connection, account: PublicKey): Promise<boolean> => {
102
- const acc = await connection.getAccountInfo(account);
103
- return acc !== null;
104
- };
105
-
106
101
  export function getDepositWsolIxns(owner: PublicKey, ata: PublicKey, amountLamports: Decimal) {
107
102
  const ixns: TransactionInstruction[] = [];
108
103
 
@@ -158,15 +153,14 @@ export async function getTokenAccountBalance(provider: AnchorProvider, tokenAcco
158
153
  export async function getTokenAccountBalanceDecimal(
159
154
  connection: Connection,
160
155
  mint: PublicKey,
161
- owner: PublicKey
156
+ owner: PublicKey,
157
+ tokenProgram: PublicKey = TOKEN_PROGRAM_ID,
162
158
  ): Promise<Decimal> {
163
- const tokenAta = getAssociatedTokenAddress(mint, owner);
164
- const ataExists = await checkIfAccountExists(connection, tokenAta);
165
-
166
- if (!ataExists) {
167
- return new Decimal(0);
168
- } else {
169
- const tokenData = (await connection.getTokenAccountBalance(tokenAta)).value;
170
- return new Decimal(tokenData.uiAmountString!);
159
+ const ata = getAssociatedTokenAddress(mint, owner, true, tokenProgram);
160
+ const accInfo = await connection.getAccountInfo(ata);
161
+ if (accInfo === null) {
162
+ return new Decimal('0');
171
163
  }
164
+ const { value } = await connection.getTokenAccountBalance(ata);
165
+ return new Decimal(value.uiAmountString!);
172
166
  }