@haven-fi/solauto-sdk 1.0.101 → 1.0.102
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/transactions/transactionUtils.d.ts +2 -2
- package/dist/transactions/transactionUtils.d.ts.map +1 -1
- package/dist/transactions/transactionUtils.js +8 -4
- package/dist/utils/accountUtils.d.ts +2 -0
- package/dist/utils/accountUtils.d.ts.map +1 -1
- package/dist/utils/accountUtils.js +11 -0
- package/package.json +1 -1
- package/src/transactions/transactionUtils.ts +11 -6
- package/src/utils/accountUtils.ts +11 -1
- package/tests/transactions/solautoMarginfi.ts +7 -7
@@ -1,5 +1,5 @@
|
|
1
1
|
import { TransactionBuilder, Umi } from "@metaplex-foundation/umi";
|
2
|
-
import {
|
2
|
+
import { PublicKey } from "@solana/web3.js";
|
3
3
|
import { ReferralState } from "../generated";
|
4
4
|
import { SolautoClient } from "../clients/solautoClient";
|
5
5
|
export declare function rebalanceChoresBefore(client: SolautoClient, tx: TransactionBuilder, accountsGettingCreated: string[]): Promise<TransactionBuilder>;
|
@@ -8,5 +8,5 @@ export declare function buildSolautoRebalanceTransaction(client: SolautoClient,
|
|
8
8
|
tx: TransactionBuilder;
|
9
9
|
lookupTableAddresses: string[];
|
10
10
|
} | undefined>;
|
11
|
-
export declare function convertReferralFeesToDestination(umi: Umi, referralState: ReferralState, tokenAccount:
|
11
|
+
export declare function convertReferralFeesToDestination(umi: Umi, referralState: ReferralState, tokenAccount: PublicKey): Promise<[TransactionBuilder, string[]] | undefined>;
|
12
12
|
//# sourceMappingURL=transactionUtils.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;
|
1
|
+
{"version":3,"file":"transactionUtils.d.ts","sourceRoot":"","sources":["../../src/transactions/transactionUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EAClB,GAAG,EAGJ,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,SAAS,EAA8B,MAAM,iBAAiB,CAAC;AAMxE,OAAO,EAGL,aAAa,EASd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAuMzD,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,EACtB,sBAAsB,EAAE,MAAM,EAAE,GAC/B,OAAO,CAAC,kBAAkB,CAAC,CA8G7B;AAkLD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,EAAE,EAAE,kBAAkB,GACrB,OAAO,CAAC,CAAC,kBAAkB,EAAE,kBAAkB,CAAC,CAAC,CA4BnD;AAED,wBAAsB,gCAAgC,CACpD,MAAM,EAAE,aAAa,EACrB,2BAA2B,CAAC,EAAE,MAAM,EACpC,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC;IACT,EAAE,EAAE,kBAAkB,CAAC;IACvB,oBAAoB,EAAE,MAAM,EAAE,CAAC;CAChC,GACG,SAAS,CACZ,CAyHA;AAED,wBAAsB,gCAAgC,CACpD,GAAG,EAAE,GAAG,EACR,aAAa,EAAE,aAAa,EAC5B,YAAY,EAAE,SAAS,GACtB,OAAO,CAAC,CAAC,kBAAkB,EAAE,MAAM,EAAE,CAAC,GAAG,SAAS,CAAC,CAmCrD"}
|
@@ -373,10 +373,14 @@ async function buildSolautoRebalanceTransaction(client, targetLiqUtilizationRate
|
|
373
373
|
};
|
374
374
|
}
|
375
375
|
async function convertReferralFeesToDestination(umi, referralState, tokenAccount) {
|
376
|
+
const tokenAccountData = await (0, accountUtils_1.getTokenAccountData)(umi, tokenAccount);
|
377
|
+
if (!tokenAccountData || tokenAccountData.amount === BigInt(0)) {
|
378
|
+
return undefined;
|
379
|
+
}
|
376
380
|
const { lookupTableAddresses, setupInstructions, swapIx } = await (0, jupiterUtils_1.getJupSwapTransaction)(umi.identity, {
|
377
|
-
amount:
|
381
|
+
amount: tokenAccountData.amount,
|
378
382
|
destinationWallet: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(referralState.publicKey),
|
379
|
-
inputMint:
|
383
|
+
inputMint: tokenAccountData.mint,
|
380
384
|
outputMint: (0, umi_web3js_adapters_1.toWeb3JsPublicKey)(referralState.destFeesMint),
|
381
385
|
exactIn: true,
|
382
386
|
slippageBpsIncFactor: 0.15,
|
@@ -385,10 +389,10 @@ async function convertReferralFeesToDestination(umi, referralState, tokenAccount
|
|
385
389
|
.add(setupInstructions)
|
386
390
|
.add((0, generated_1.convertReferralFees)(umi, {
|
387
391
|
signer: umi.identity,
|
388
|
-
intermediaryTa: (0, umi_1.publicKey)((0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(umi.identity.publicKey),
|
392
|
+
intermediaryTa: (0, umi_1.publicKey)((0, accountUtils_1.getTokenAccount)((0, umi_web3js_adapters_1.toWeb3JsPublicKey)(umi.identity.publicKey), tokenAccountData.mint)),
|
389
393
|
ixsSysvar: (0, umi_1.publicKey)(web3_js_1.SYSVAR_INSTRUCTIONS_PUBKEY),
|
390
394
|
referralState: referralState.publicKey,
|
391
|
-
referralFeesTa: (0, umi_1.publicKey)(tokenAccount
|
395
|
+
referralFeesTa: (0, umi_1.publicKey)(tokenAccount),
|
392
396
|
}))
|
393
397
|
.add(swapIx);
|
394
398
|
return [tx, lookupTableAddresses];
|
@@ -1,8 +1,10 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
|
+
import { Umi } from "@metaplex-foundation/umi";
|
2
3
|
export declare function bufferFromU8(num: number): Buffer;
|
3
4
|
export declare function bufferFromU64(num: bigint): Buffer;
|
4
5
|
export declare function getTokenAccount(wallet: PublicKey, tokenMint: PublicKey): PublicKey;
|
5
6
|
export declare function getTokenAccounts(wallet: PublicKey, tokenMints: PublicKey[]): PublicKey[];
|
7
|
+
export declare function getTokenAccountData(umi: Umi, tokenAccount: PublicKey): Promise<import("@solana/spl-token").RawAccount | undefined>;
|
6
8
|
export declare function getSolautoPositionAccount(signer: PublicKey, positionId: number): PublicKey;
|
7
9
|
export declare function getReferralState(authority: PublicKey): PublicKey;
|
8
10
|
export declare function getMarginfiAccountPDA(solautoPositionAccount: PublicKey, marginfiAccountSeedIdx: bigint): Promise<PublicKey>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"accountUtils.d.ts","sourceRoot":"","sources":["../../src/utils/accountUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;
|
1
|
+
{"version":3,"file":"accountUtils.d.ts","sourceRoot":"","sources":["../../src/utils/accountUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,OAAO,EAAa,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAE1D,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIhD;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIjD;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,GAAG,SAAS,CAMlF;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,CAExF;AAED,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,GAAG,EAAE,YAAY,EAAE,SAAS,+DAO1E;AAED,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,SAAS,EACjB,UAAU,EAAE,MAAM,aAQnB;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,SAAS,aAUpD;AAED,wBAAsB,qBAAqB,CACzC,sBAAsB,EAAE,SAAS,EACjC,sBAAsB,EAAE,MAAM,sBAa/B"}
|
@@ -4,12 +4,14 @@ exports.bufferFromU8 = bufferFromU8;
|
|
4
4
|
exports.bufferFromU64 = bufferFromU64;
|
5
5
|
exports.getTokenAccount = getTokenAccount;
|
6
6
|
exports.getTokenAccounts = getTokenAccounts;
|
7
|
+
exports.getTokenAccountData = getTokenAccountData;
|
7
8
|
exports.getSolautoPositionAccount = getSolautoPositionAccount;
|
8
9
|
exports.getReferralState = getReferralState;
|
9
10
|
exports.getMarginfiAccountPDA = getMarginfiAccountPDA;
|
10
11
|
const web3_js_1 = require("@solana/web3.js");
|
11
12
|
const spl_token_1 = require("@solana/spl-token");
|
12
13
|
const generated_1 = require("../generated");
|
14
|
+
const umi_1 = require("@metaplex-foundation/umi");
|
13
15
|
function bufferFromU8(num) {
|
14
16
|
const buffer = Buffer.alloc(1);
|
15
17
|
buffer.writeUInt8(num);
|
@@ -26,6 +28,15 @@ function getTokenAccount(wallet, tokenMint) {
|
|
26
28
|
function getTokenAccounts(wallet, tokenMints) {
|
27
29
|
return tokenMints.map(x => getTokenAccount(wallet, x));
|
28
30
|
}
|
31
|
+
async function getTokenAccountData(umi, tokenAccount) {
|
32
|
+
const resp = await umi.rpc.getAccount((0, umi_1.publicKey)(tokenAccount));
|
33
|
+
if (resp.exists) {
|
34
|
+
return spl_token_1.AccountLayout.decode(resp.data);
|
35
|
+
}
|
36
|
+
else {
|
37
|
+
return undefined;
|
38
|
+
}
|
39
|
+
}
|
29
40
|
function getSolautoPositionAccount(signer, positionId) {
|
30
41
|
const [positionAccount, _] = web3_js_1.PublicKey.findProgramAddressSync([bufferFromU8(positionId), signer.toBuffer()], new web3_js_1.PublicKey(generated_1.SOLAUTO_PROGRAM_ID));
|
31
42
|
return positionAccount;
|
package/package.json
CHANGED
@@ -48,7 +48,7 @@ import {
|
|
48
48
|
uint8ArrayToBigInt,
|
49
49
|
} from "../utils/numberUtils";
|
50
50
|
import { eligibleForRebalance } from "../utils/solauto/generalUtils";
|
51
|
-
import { getTokenAccount } from "../utils/accountUtils";
|
51
|
+
import { getTokenAccount, getTokenAccountData } from "../utils/accountUtils";
|
52
52
|
import {
|
53
53
|
getLendingAccountBorrowInstructionDataSerializer,
|
54
54
|
getLendingAccountDepositInstructionDataSerializer,
|
@@ -684,13 +684,18 @@ export async function buildSolautoRebalanceTransaction(
|
|
684
684
|
export async function convertReferralFeesToDestination(
|
685
685
|
umi: Umi,
|
686
686
|
referralState: ReferralState,
|
687
|
-
tokenAccount:
|
687
|
+
tokenAccount: PublicKey
|
688
688
|
): Promise<[TransactionBuilder, string[]] | undefined> {
|
689
|
+
const tokenAccountData = await getTokenAccountData(umi, tokenAccount);
|
690
|
+
if (!tokenAccountData || tokenAccountData.amount === BigInt(0)) {
|
691
|
+
return undefined;
|
692
|
+
}
|
693
|
+
|
689
694
|
const { lookupTableAddresses, setupInstructions, swapIx } =
|
690
695
|
await getJupSwapTransaction(umi.identity, {
|
691
|
-
amount:
|
696
|
+
amount: tokenAccountData.amount,
|
692
697
|
destinationWallet: toWeb3JsPublicKey(referralState.publicKey),
|
693
|
-
inputMint:
|
698
|
+
inputMint: tokenAccountData.mint,
|
694
699
|
outputMint: toWeb3JsPublicKey(referralState.destFeesMint),
|
695
700
|
exactIn: true,
|
696
701
|
slippageBpsIncFactor: 0.15,
|
@@ -704,12 +709,12 @@ export async function convertReferralFeesToDestination(
|
|
704
709
|
intermediaryTa: publicKey(
|
705
710
|
getTokenAccount(
|
706
711
|
toWeb3JsPublicKey(umi.identity.publicKey),
|
707
|
-
|
712
|
+
tokenAccountData.mint
|
708
713
|
)
|
709
714
|
),
|
710
715
|
ixsSysvar: publicKey(SYSVAR_INSTRUCTIONS_PUBKEY),
|
711
716
|
referralState: referralState.publicKey,
|
712
|
-
referralFeesTa: publicKey(tokenAccount
|
717
|
+
referralFeesTa: publicKey(tokenAccount),
|
713
718
|
})
|
714
719
|
)
|
715
720
|
.add(swapIx);
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { PublicKey } from "@solana/web3.js";
|
2
|
-
import { getAssociatedTokenAddressSync } from "@solana/spl-token";
|
2
|
+
import { AccountLayout as SplTokenAccountLayout, getAssociatedTokenAddressSync } from "@solana/spl-token";
|
3
3
|
import { SOLAUTO_PROGRAM_ID } from "../generated";
|
4
|
+
import { publicKey, Umi } from "@metaplex-foundation/umi";
|
4
5
|
|
5
6
|
export function bufferFromU8(num: number): Buffer {
|
6
7
|
const buffer = Buffer.alloc(1);
|
@@ -26,6 +27,15 @@ export function getTokenAccounts(wallet: PublicKey, tokenMints: PublicKey[]): Pu
|
|
26
27
|
return tokenMints.map(x => getTokenAccount(wallet, x));
|
27
28
|
}
|
28
29
|
|
30
|
+
export async function getTokenAccountData(umi: Umi, tokenAccount: PublicKey) {
|
31
|
+
const resp = await umi.rpc.getAccount(publicKey(tokenAccount));
|
32
|
+
if (resp.exists) {
|
33
|
+
return SplTokenAccountLayout.decode(resp.data);
|
34
|
+
} else {
|
35
|
+
return undefined;
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
29
39
|
export function getSolautoPositionAccount(
|
30
40
|
signer: PublicKey,
|
31
41
|
positionId: number
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { describe, it } from "mocha";
|
2
|
-
import { none, some } from "@metaplex-foundation/umi";
|
2
|
+
import { none, publicKey, some } from "@metaplex-foundation/umi";
|
3
3
|
import { setupTest } from "../shared";
|
4
4
|
import {
|
5
5
|
SolautoMarginfiClient,
|
@@ -154,11 +154,11 @@ describe("Solauto Marginfi tests", async () => {
|
|
154
154
|
// )
|
155
155
|
// );
|
156
156
|
|
157
|
-
await new TransactionsManager(
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
).clientSend(transactionItems);
|
157
|
+
// await new TransactionsManager(
|
158
|
+
// client,
|
159
|
+
// undefined,
|
160
|
+
// !payForTransactions,
|
161
|
+
// useJitoBundle
|
162
|
+
// ).clientSend(transactionItems);
|
163
163
|
});
|
164
164
|
});
|