@kamino-finance/klend-sdk 5.0.6 → 5.1.0
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/README_KAMINO_MANAGER.md +154 -17
- package/dist/classes/action.d.ts +5 -1
- package/dist/classes/action.d.ts.map +1 -1
- package/dist/classes/action.js +39 -26
- package/dist/classes/action.js.map +1 -1
- package/dist/classes/manager.d.ts +22 -0
- package/dist/classes/manager.d.ts.map +1 -1
- package/dist/classes/manager.js +29 -0
- package/dist/classes/manager.js.map +1 -1
- package/dist/classes/vault.d.ts +30 -0
- package/dist/classes/vault.d.ts.map +1 -1
- package/dist/classes/vault.js +177 -0
- package/dist/classes/vault.js.map +1 -1
- package/dist/client_kamino_manager.d.ts.map +1 -1
- package/dist/client_kamino_manager.js +113 -1
- package/dist/client_kamino_manager.js.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.d.ts +10 -10
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.d.ts.map +1 -1
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.js +52 -51
- package/dist/idl_codegen_kamino_vault/types/VaultConfigField.js.map +1 -1
- package/dist/leverage/operations.d.ts.map +1 -1
- package/dist/leverage/operations.js +3 -9
- package/dist/leverage/operations.js.map +1 -1
- package/dist/referrals/instructions.d.ts +2 -1
- package/dist/referrals/instructions.d.ts.map +1 -1
- package/dist/referrals/instructions.js +13 -8
- package/dist/referrals/instructions.js.map +1 -1
- package/dist/utils/ata.d.ts +1 -2
- package/dist/utils/ata.d.ts.map +1 -1
- package/dist/utils/ata.js +8 -15
- package/dist/utils/ata.js.map +1 -1
- package/package.json +1 -1
- package/src/classes/action.ts +41 -33
- package/src/classes/manager.ts +34 -0
- package/src/classes/vault.ts +250 -0
- package/src/client.ts +4 -20
- package/src/client_kamino_manager.ts +174 -1
- package/src/idl_codegen_kamino_vault/types/VaultConfigField.ts +116 -117
- package/src/leverage/operations.ts +3 -9
- package/src/referrals/instructions.ts +16 -9
- package/src/utils/ata.ts +8 -14
|
@@ -1,270 +1,269 @@
|
|
|
1
|
-
import { PublicKey } from
|
|
2
|
-
import BN from
|
|
3
|
-
import * as types from
|
|
4
|
-
import * as borsh from
|
|
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:
|
|
7
|
+
kind: 'PerformanceFeeBps';
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export class PerformanceFeeBps {
|
|
11
|
-
static readonly discriminator = 0
|
|
12
|
-
static readonly kind =
|
|
13
|
-
readonly discriminator = 0
|
|
14
|
-
readonly kind =
|
|
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:
|
|
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:
|
|
30
|
+
kind: 'ManagementFeeBps';
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export class ManagementFeeBps {
|
|
34
|
-
static readonly discriminator = 1
|
|
35
|
-
static readonly kind =
|
|
36
|
-
readonly discriminator = 1
|
|
37
|
-
readonly kind =
|
|
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:
|
|
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:
|
|
53
|
+
kind: 'MinDepositAmount';
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
export class MinDepositAmount {
|
|
57
|
-
static readonly discriminator = 2
|
|
58
|
-
static readonly kind =
|
|
59
|
-
readonly discriminator = 2
|
|
60
|
-
readonly kind =
|
|
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:
|
|
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:
|
|
76
|
+
kind: 'MinWithdrawAmount';
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
export class MinWithdrawAmount {
|
|
80
|
-
static readonly discriminator = 3
|
|
81
|
-
static readonly kind =
|
|
82
|
-
readonly discriminator = 3
|
|
83
|
-
readonly kind =
|
|
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:
|
|
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:
|
|
99
|
+
kind: 'MintInvestAmount';
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
export class MintInvestAmount {
|
|
103
|
-
static readonly discriminator = 4
|
|
104
|
-
static readonly kind =
|
|
105
|
-
readonly discriminator = 4
|
|
106
|
-
readonly kind =
|
|
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:
|
|
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:
|
|
122
|
+
kind: 'MinInvestDelaySlots';
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
export class MinInvestDelaySlots {
|
|
126
|
-
static readonly discriminator = 5
|
|
127
|
-
static readonly kind =
|
|
128
|
-
readonly discriminator = 5
|
|
129
|
-
readonly kind =
|
|
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:
|
|
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:
|
|
145
|
+
kind: 'CrankFundFeePerReserve';
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
export class CrankFundFeePerReserve {
|
|
149
|
-
static readonly discriminator = 6
|
|
150
|
-
static readonly kind =
|
|
151
|
-
readonly discriminator = 6
|
|
152
|
-
readonly kind =
|
|
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:
|
|
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:
|
|
168
|
+
kind: 'PendingVaultAdmin';
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
export class PendingVaultAdmin {
|
|
172
|
-
static readonly discriminator = 7
|
|
173
|
-
static readonly kind =
|
|
174
|
-
readonly discriminator = 7
|
|
175
|
-
readonly kind =
|
|
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:
|
|
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 !==
|
|
193
|
-
throw new Error(
|
|
192
|
+
if (typeof obj !== 'object') {
|
|
193
|
+
throw new Error('Invalid enum object');
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
|
|
197
|
-
|
|
196
|
+
console.log('');
|
|
197
|
+
if ('PerformanceFeeBps' in obj) {
|
|
198
|
+
return new PerformanceFeeBps();
|
|
198
199
|
}
|
|
199
|
-
if (
|
|
200
|
-
return new ManagementFeeBps()
|
|
200
|
+
if ('ManagementFeeBps' in obj) {
|
|
201
|
+
return new ManagementFeeBps();
|
|
201
202
|
}
|
|
202
|
-
if (
|
|
203
|
-
return new MinDepositAmount()
|
|
203
|
+
if ('MinDepositAmount' in obj) {
|
|
204
|
+
return new MinDepositAmount();
|
|
204
205
|
}
|
|
205
|
-
if (
|
|
206
|
-
return new MinWithdrawAmount()
|
|
206
|
+
if ('MinWithdrawAmount' in obj) {
|
|
207
|
+
return new MinWithdrawAmount();
|
|
207
208
|
}
|
|
208
|
-
if (
|
|
209
|
-
return new MintInvestAmount()
|
|
209
|
+
if ('MintInvestAmount' in obj) {
|
|
210
|
+
return new MintInvestAmount();
|
|
210
211
|
}
|
|
211
|
-
if (
|
|
212
|
-
return new MinInvestDelaySlots()
|
|
212
|
+
if ('MinInvestDelaySlots' in obj) {
|
|
213
|
+
return new MinInvestDelaySlots();
|
|
213
214
|
}
|
|
214
|
-
if (
|
|
215
|
-
return new CrankFundFeePerReserve()
|
|
215
|
+
if ('CrankFundFeePerReserve' in obj) {
|
|
216
|
+
return new CrankFundFeePerReserve();
|
|
216
217
|
}
|
|
217
|
-
if (
|
|
218
|
-
return new PendingVaultAdmin()
|
|
218
|
+
if ('PendingVaultAdmin' in obj) {
|
|
219
|
+
return new PendingVaultAdmin();
|
|
219
220
|
}
|
|
220
221
|
|
|
221
|
-
throw new Error(
|
|
222
|
+
throw new Error('Invalid enum object');
|
|
222
223
|
}
|
|
223
224
|
|
|
224
|
-
export function fromJSON(
|
|
225
|
-
obj: types.VaultConfigFieldJSON
|
|
226
|
-
): types.VaultConfigFieldKind {
|
|
225
|
+
export function fromJSON(obj: types.VaultConfigFieldJSON): types.VaultConfigFieldKind {
|
|
227
226
|
switch (obj.kind) {
|
|
228
|
-
case
|
|
229
|
-
return new PerformanceFeeBps()
|
|
227
|
+
case 'PerformanceFeeBps': {
|
|
228
|
+
return new PerformanceFeeBps();
|
|
230
229
|
}
|
|
231
|
-
case
|
|
232
|
-
return new ManagementFeeBps()
|
|
230
|
+
case 'ManagementFeeBps': {
|
|
231
|
+
return new ManagementFeeBps();
|
|
233
232
|
}
|
|
234
|
-
case
|
|
235
|
-
return new MinDepositAmount()
|
|
233
|
+
case 'MinDepositAmount': {
|
|
234
|
+
return new MinDepositAmount();
|
|
236
235
|
}
|
|
237
|
-
case
|
|
238
|
-
return new MinWithdrawAmount()
|
|
236
|
+
case 'MinWithdrawAmount': {
|
|
237
|
+
return new MinWithdrawAmount();
|
|
239
238
|
}
|
|
240
|
-
case
|
|
241
|
-
return new MintInvestAmount()
|
|
239
|
+
case 'MintInvestAmount': {
|
|
240
|
+
return new MintInvestAmount();
|
|
242
241
|
}
|
|
243
|
-
case
|
|
244
|
-
return new MinInvestDelaySlots()
|
|
242
|
+
case 'MinInvestDelaySlots': {
|
|
243
|
+
return new MinInvestDelaySlots();
|
|
245
244
|
}
|
|
246
|
-
case
|
|
247
|
-
return new CrankFundFeePerReserve()
|
|
245
|
+
case 'CrankFundFeePerReserve': {
|
|
246
|
+
return new CrankFundFeePerReserve();
|
|
248
247
|
}
|
|
249
|
-
case
|
|
250
|
-
return new PendingVaultAdmin()
|
|
248
|
+
case 'PendingVaultAdmin': {
|
|
249
|
+
return new PendingVaultAdmin();
|
|
251
250
|
}
|
|
252
251
|
}
|
|
253
252
|
}
|
|
254
253
|
|
|
255
254
|
export function layout(property?: string) {
|
|
256
255
|
const ret = borsh.rustEnum([
|
|
257
|
-
borsh.struct([],
|
|
258
|
-
borsh.struct([],
|
|
259
|
-
borsh.struct([],
|
|
260
|
-
borsh.struct([],
|
|
261
|
-
borsh.struct([],
|
|
262
|
-
borsh.struct([],
|
|
263
|
-
borsh.struct([],
|
|
264
|
-
borsh.struct([],
|
|
265
|
-
])
|
|
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
|
+
]);
|
|
266
265
|
if (property !== undefined) {
|
|
267
|
-
return ret.replicate(property)
|
|
266
|
+
return ret.replicate(property);
|
|
268
267
|
}
|
|
269
|
-
return ret
|
|
268
|
+
return ret;
|
|
270
269
|
}
|
|
@@ -526,9 +526,7 @@ async function buildDepositWithLeverageIxns(
|
|
|
526
526
|
...fillWsolAtaIxns,
|
|
527
527
|
...[flashBorrowIxn],
|
|
528
528
|
...kaminoDepositAndBorrowAction.setupIxs,
|
|
529
|
-
...
|
|
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
|
-
...
|
|
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
|
-
...
|
|
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 {
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
|
45
|
+
referrer,
|
|
40
46
|
},
|
|
41
47
|
{
|
|
42
48
|
lendingMarket: kaminoMarket.getAddress(),
|
|
43
|
-
payer
|
|
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
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
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
|
}
|