@kamino-finance/klend-sdk 5.0.7 → 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/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/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/client.ts +4 -20
- package/src/leverage/operations.ts +3 -9
- package/src/referrals/instructions.ts +16 -9
- package/src/utils/ata.ts +8 -14
|
@@ -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
|
}
|