@lavarage/sdk 6.1.4 → 6.2.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/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +68 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +69 -28
- package/dist/index.mjs.map +1 -1
- package/index.ts +72 -25
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -46,7 +46,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
46
46
|
import { BN } from "@coral-xyz/anchor";
|
|
47
47
|
import bs58 from "bs58";
|
|
48
48
|
import { AddressLookupTableAccount, ComputeBudgetProgram, PublicKey, SystemProgram, SYSVAR_CLOCK_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, Transaction, TransactionInstruction, TransactionMessage, VersionedTransaction } from "@solana/web3.js";
|
|
49
|
-
import { ASSOCIATED_TOKEN_PROGRAM_ID, createAssociatedTokenAccountInstruction,
|
|
49
|
+
import { ASSOCIATED_TOKEN_PROGRAM_ID, createAssociatedTokenAccountInstruction, getAccount, getAssociatedTokenAddressSync, TOKEN_PROGRAM_ID, TokenAccountNotFoundError, TokenInvalidAccountOwnerError } from "@solana/spl-token";
|
|
50
50
|
|
|
51
51
|
// idl/lavarage.ts
|
|
52
52
|
var IDL = {
|
|
@@ -2514,7 +2514,15 @@ var getAllPositions = (lavarageProgram) => {
|
|
|
2514
2514
|
{ dataSize: 178 }
|
|
2515
2515
|
]);
|
|
2516
2516
|
};
|
|
2517
|
-
var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage, randomSeed, partnerFeeRecipient) => __async(void 0, null, function* () {
|
|
2517
|
+
var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage, randomSeed, partnerFeeRecipient, partnerFeeMarkup) => __async(void 0, null, function* () {
|
|
2518
|
+
let partnerFeeMarkupAsPkey;
|
|
2519
|
+
if (partnerFeeMarkup) {
|
|
2520
|
+
const feeBuffer = Buffer.alloc(8);
|
|
2521
|
+
feeBuffer.writeBigUInt64LE(BigInt(partnerFeeMarkup));
|
|
2522
|
+
const feeBuffer32 = Buffer.alloc(32);
|
|
2523
|
+
feeBuffer32.set(feeBuffer, 0);
|
|
2524
|
+
partnerFeeMarkupAsPkey = new PublicKey(feeBuffer32);
|
|
2525
|
+
}
|
|
2518
2526
|
const positionAccount = getPositionAccountPDA(lavarageProgram, offer, randomSeed.publicKey);
|
|
2519
2527
|
const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(offer.account.collateralType);
|
|
2520
2528
|
const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
|
|
@@ -2567,10 +2575,14 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
2567
2575
|
clock: SYSVAR_CLOCK_PUBKEY,
|
|
2568
2576
|
randomAccountAsId: randomSeed.publicKey.toBase58(),
|
|
2569
2577
|
feeReceipient: "6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"
|
|
2570
|
-
}).remainingAccounts(partnerFeeRecipient ? [{
|
|
2578
|
+
}).remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
|
|
2571
2579
|
pubkey: partnerFeeRecipient,
|
|
2572
2580
|
isSigner: false,
|
|
2573
2581
|
isWritable: true
|
|
2582
|
+
}, {
|
|
2583
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
2584
|
+
isSigner: false,
|
|
2585
|
+
isWritable: false
|
|
2574
2586
|
}] : []).instruction();
|
|
2575
2587
|
const openAddCollateralInstruction = yield lavarageProgram.methods.tradingOpenAddCollateral(offer.account.interestRate).accountsStrict({
|
|
2576
2588
|
tradingPool: offer.publicKey,
|
|
@@ -2600,7 +2612,15 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
2600
2612
|
const tx = new VersionedTransaction(messageV0);
|
|
2601
2613
|
return tx;
|
|
2602
2614
|
});
|
|
2603
|
-
var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage, randomSeed, quoteToken, partnerFeeRecipient) => __async(void 0, null, function* () {
|
|
2615
|
+
var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage, randomSeed, quoteToken, partnerFeeRecipient, partnerFeeMarkup) => __async(void 0, null, function* () {
|
|
2616
|
+
let partnerFeeMarkupAsPkey;
|
|
2617
|
+
if (partnerFeeMarkup) {
|
|
2618
|
+
const feeBuffer = Buffer.alloc(8);
|
|
2619
|
+
feeBuffer.writeBigUInt64LE(BigInt(partnerFeeMarkup));
|
|
2620
|
+
const feeBuffer32 = Buffer.alloc(32);
|
|
2621
|
+
feeBuffer32.set(feeBuffer, 0);
|
|
2622
|
+
partnerFeeMarkupAsPkey = new PublicKey(feeBuffer32);
|
|
2623
|
+
}
|
|
2604
2624
|
const positionAccount = getPositionAccountPDA(lavarageProgram, offer, randomSeed.publicKey);
|
|
2605
2625
|
const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(offer.account.collateralType);
|
|
2606
2626
|
const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
|
|
@@ -2658,10 +2678,14 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
2658
2678
|
toTokenAccount: getAssociatedTokenAddressSync(quoteToken, lavarageProgram.provider.publicKey, true, quoteTokenProgram),
|
|
2659
2679
|
tokenProgram,
|
|
2660
2680
|
fromTokenAccount: getAssociatedTokenAddressSync(quoteToken, offer.account.nodeWallet, true, tokenProgram)
|
|
2661
|
-
}).remainingAccounts(partnerFeeRecipient ? [{
|
|
2681
|
+
}).remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
|
|
2662
2682
|
pubkey: partnerFeeRecipient,
|
|
2663
2683
|
isSigner: false,
|
|
2664
2684
|
isWritable: true
|
|
2685
|
+
}, {
|
|
2686
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
2687
|
+
isSigner: false,
|
|
2688
|
+
isWritable: false
|
|
2665
2689
|
}] : []).instruction();
|
|
2666
2690
|
const openAddCollateralInstruction = yield lavarageProgram.methods.tradingOpenAddCollateral(offer.account.interestRate).accountsStrict({
|
|
2667
2691
|
tradingPool: offer.publicKey,
|
|
@@ -2817,7 +2841,15 @@ var partialRepayV2 = (lavarageProgram, position, repaymentBps) => __async(void 0
|
|
|
2817
2841
|
}).compileToV0Message();
|
|
2818
2842
|
return new VersionedTransaction(messageV0);
|
|
2819
2843
|
});
|
|
2820
|
-
var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFeeRecipient,
|
|
2844
|
+
var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFeeRecipient, partnerFeeMarkup) => __async(void 0, null, function* () {
|
|
2845
|
+
let partnerFeeMarkupAsPkey;
|
|
2846
|
+
if (partnerFeeMarkup) {
|
|
2847
|
+
const feeBuffer = Buffer.alloc(8);
|
|
2848
|
+
feeBuffer.writeBigUInt64LE(BigInt(partnerFeeMarkup));
|
|
2849
|
+
const feeBuffer32 = Buffer.alloc(32);
|
|
2850
|
+
feeBuffer32.set(feeBuffer, 0);
|
|
2851
|
+
partnerFeeMarkupAsPkey = new PublicKey(feeBuffer32);
|
|
2852
|
+
}
|
|
2821
2853
|
if (position.account.pool.toBase58() != offer.publicKey.toBase58()) throw "Mismatch offer";
|
|
2822
2854
|
const pool = offer;
|
|
2823
2855
|
const poolPubKey = offer.publicKey;
|
|
@@ -2880,10 +2912,14 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
|
|
|
2880
2912
|
clock: SYSVAR_CLOCK_PUBKEY,
|
|
2881
2913
|
randomAccountAsId: position.account.seed,
|
|
2882
2914
|
feeReceipient: "6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"
|
|
2883
|
-
}).remainingAccounts(partnerFeeRecipient ? [{
|
|
2915
|
+
}).remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
|
|
2884
2916
|
pubkey: partnerFeeRecipient,
|
|
2885
2917
|
isSigner: false,
|
|
2886
2918
|
isWritable: true
|
|
2919
|
+
}, {
|
|
2920
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
2921
|
+
isSigner: false,
|
|
2922
|
+
isWritable: false
|
|
2887
2923
|
}] : []).instruction();
|
|
2888
2924
|
} else {
|
|
2889
2925
|
repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(new BN(jupInstruction.quoteResponse.outAmount), new BN(9998)).accountsStrict({
|
|
@@ -2895,10 +2931,14 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
|
|
|
2895
2931
|
clock: SYSVAR_CLOCK_PUBKEY,
|
|
2896
2932
|
randomAccountAsId: position.account.seed,
|
|
2897
2933
|
feeReceipient: "6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"
|
|
2898
|
-
}).remainingAccounts(partnerFeeRecipient ? [{
|
|
2934
|
+
}).remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
|
|
2899
2935
|
pubkey: partnerFeeRecipient,
|
|
2900
2936
|
isSigner: false,
|
|
2901
2937
|
isWritable: true
|
|
2938
|
+
}, {
|
|
2939
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
2940
|
+
isSigner: false,
|
|
2941
|
+
isWritable: false
|
|
2902
2942
|
}] : []).instruction();
|
|
2903
2943
|
const { setupInstructions, swapInstruction: swapInstructionPayload, cleanupInstruction, addressLookupTableAddresses } = jupiterSellIx;
|
|
2904
2944
|
jupiterIxs = [
|
|
@@ -2913,14 +2953,7 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
|
|
|
2913
2953
|
toTokenAccount.instruction,
|
|
2914
2954
|
closePositionIx,
|
|
2915
2955
|
...jupiterIxs,
|
|
2916
|
-
repaySolIx
|
|
2917
|
-
profitFeeMarkup && partnerFeeRecipient ? SystemProgram.transfer(
|
|
2918
|
-
{
|
|
2919
|
-
fromPubkey: lavarageProgram.provider.publicKey,
|
|
2920
|
-
toPubkey: partnerFeeRecipient,
|
|
2921
|
-
lamports: profit.toNumber() > 0 ? profit.mul(new BN(profitFeeMarkup * 1e4)).div(new BN(1e4)).toNumber() : 0
|
|
2922
|
-
}
|
|
2923
|
-
) : null
|
|
2956
|
+
repaySolIx
|
|
2924
2957
|
].filter((i) => !!i);
|
|
2925
2958
|
const messageV0 = new TransactionMessage({
|
|
2926
2959
|
payerKey: lavarageProgram.provider.publicKey,
|
|
@@ -2930,7 +2963,15 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
|
|
|
2930
2963
|
const tx = new VersionedTransaction(messageV0);
|
|
2931
2964
|
return tx;
|
|
2932
2965
|
});
|
|
2933
|
-
var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken, partnerFeeRecipient,
|
|
2966
|
+
var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken, partnerFeeRecipient, partnerFeeMarkup) => __async(void 0, null, function* () {
|
|
2967
|
+
let partnerFeeMarkupAsPkey;
|
|
2968
|
+
if (partnerFeeMarkup) {
|
|
2969
|
+
const feeBuffer = Buffer.alloc(8);
|
|
2970
|
+
feeBuffer.writeBigUInt64LE(BigInt(partnerFeeMarkup));
|
|
2971
|
+
const feeBuffer32 = Buffer.alloc(32);
|
|
2972
|
+
feeBuffer32.set(feeBuffer, 0);
|
|
2973
|
+
partnerFeeMarkupAsPkey = new PublicKey(feeBuffer32);
|
|
2974
|
+
}
|
|
2934
2975
|
if (position.account.pool.toBase58() != offer.publicKey.toBase58()) throw "Mismatch offer";
|
|
2935
2976
|
const pool = offer;
|
|
2936
2977
|
const poolPubKey = offer.publicKey;
|
|
@@ -2999,10 +3040,14 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
|
|
|
2999
3040
|
tokenProgram: quoteTokenProgram,
|
|
3000
3041
|
toTokenAccount: getAssociatedTokenAddressSync(quoteToken, pool.account.nodeWallet, true, quoteTokenProgram),
|
|
3001
3042
|
mint: quoteToken
|
|
3002
|
-
}).remainingAccounts(partnerFeeRecipient ? [{
|
|
3043
|
+
}).remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
|
|
3003
3044
|
pubkey: partnerFeeRecipient,
|
|
3004
3045
|
isSigner: false,
|
|
3005
3046
|
isWritable: true
|
|
3047
|
+
}, {
|
|
3048
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
3049
|
+
isSigner: false,
|
|
3050
|
+
isWritable: false
|
|
3006
3051
|
}] : []).instruction();
|
|
3007
3052
|
} else {
|
|
3008
3053
|
repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(new BN(jupInstruction.quoteResponse.outAmount), new BN(9998)).accountsStrict({
|
|
@@ -3018,10 +3063,14 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
|
|
|
3018
3063
|
tokenProgram: quoteTokenProgram,
|
|
3019
3064
|
toTokenAccount: getAssociatedTokenAddressSync(quoteToken, pool.account.nodeWallet, true, quoteTokenProgram),
|
|
3020
3065
|
mint: quoteToken
|
|
3021
|
-
}).remainingAccounts(partnerFeeRecipient ? [{
|
|
3066
|
+
}).remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
|
|
3022
3067
|
pubkey: partnerFeeRecipient,
|
|
3023
3068
|
isSigner: false,
|
|
3024
3069
|
isWritable: true
|
|
3070
|
+
}, {
|
|
3071
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
3072
|
+
isSigner: false,
|
|
3073
|
+
isWritable: false
|
|
3025
3074
|
}] : []).instruction();
|
|
3026
3075
|
const { setupInstructions, swapInstruction: swapInstructionPayload, cleanupInstruction, addressLookupTableAddresses } = jupiterSellIx;
|
|
3027
3076
|
jupiterIxs = [
|
|
@@ -3036,15 +3085,7 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
|
|
|
3036
3085
|
toTokenAccount.instruction,
|
|
3037
3086
|
closePositionIx,
|
|
3038
3087
|
...jupiterIxs,
|
|
3039
|
-
repaySolIx
|
|
3040
|
-
profitFeeMarkup && partnerFeeRecipient ? createTransferInstruction(
|
|
3041
|
-
getAssociatedTokenAddressSync(quoteToken, lavarageProgram.provider.publicKey, false, quoteTokenProgram),
|
|
3042
|
-
partnerFeeRecipient,
|
|
3043
|
-
lavarageProgram.provider.publicKey,
|
|
3044
|
-
profit.toNumber() > 0 ? profit.mul(new BN(profitFeeMarkup * 1e3)).div(new BN(1e3)).toNumber() : 0,
|
|
3045
|
-
[],
|
|
3046
|
-
quoteTokenProgram
|
|
3047
|
-
) : null
|
|
3088
|
+
repaySolIx
|
|
3048
3089
|
].filter((i) => !!i);
|
|
3049
3090
|
const messageV0 = new TransactionMessage({
|
|
3050
3091
|
payerKey: lavarageProgram.provider.publicKey,
|