@lavarage/sdk 6.1.9 → 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 +92 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +93 -28
- package/dist/index.mjs.map +1 -1
- package/index.ts +90 -49
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -127,7 +127,15 @@ export const openTradeV1 = async (lavarageProgram: Program<Lavarage>, offer: Pro
|
|
|
127
127
|
swapInstruction: Record<string, unknown>
|
|
128
128
|
addressLookupTableAddresses: string[]
|
|
129
129
|
}
|
|
130
|
-
}, marginSOL: BN, leverage: number, randomSeed: Keypair, partnerFeeRecipient?: PublicKey) => {
|
|
130
|
+
}, marginSOL: BN, leverage: number, randomSeed: Keypair, partnerFeeRecipient?: PublicKey, partnerFeeMarkup?: number) => {
|
|
131
|
+
let partnerFeeMarkupAsPkey
|
|
132
|
+
if (partnerFeeMarkup) {
|
|
133
|
+
const feeBuffer = Buffer.alloc(8)
|
|
134
|
+
feeBuffer.writeBigUInt64LE(BigInt(partnerFeeMarkup))
|
|
135
|
+
const feeBuffer32 = Buffer.alloc(32)
|
|
136
|
+
feeBuffer32.set(feeBuffer, 0)
|
|
137
|
+
partnerFeeMarkupAsPkey = new PublicKey(feeBuffer32)
|
|
138
|
+
}
|
|
131
139
|
// assuming all token accounts are created prior
|
|
132
140
|
const positionAccount = getPositionAccountPDA(lavarageProgram, offer, randomSeed.publicKey)
|
|
133
141
|
|
|
@@ -201,11 +209,15 @@ export const openTradeV1 = async (lavarageProgram: Program<Lavarage>, offer: Pro
|
|
|
201
209
|
randomAccountAsId: randomSeed.publicKey.toBase58(),
|
|
202
210
|
feeReceipient: '6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF',
|
|
203
211
|
})
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
212
|
+
.remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
|
|
213
|
+
pubkey: partnerFeeRecipient,
|
|
214
|
+
isSigner: false,
|
|
215
|
+
isWritable: true,
|
|
216
|
+
}, {
|
|
217
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
218
|
+
isSigner: false,
|
|
219
|
+
isWritable: false,
|
|
220
|
+
}] : [])
|
|
209
221
|
.instruction()
|
|
210
222
|
|
|
211
223
|
const openAddCollateralInstruction = await lavarageProgram.methods
|
|
@@ -255,7 +267,15 @@ export const openTradeV2 = async (lavarageProgram: Program<LavarageV2>, offer: P
|
|
|
255
267
|
swapInstruction: Record<string, unknown>
|
|
256
268
|
addressLookupTableAddresses: string[]
|
|
257
269
|
}
|
|
258
|
-
}, marginSOL: BN, leverage: number, randomSeed: Keypair, quoteToken: PublicKey, partnerFeeRecipient?: PublicKey) => {
|
|
270
|
+
}, marginSOL: BN, leverage: number, randomSeed: Keypair, quoteToken: PublicKey, partnerFeeRecipient?: PublicKey, partnerFeeMarkup?: number) => {
|
|
271
|
+
let partnerFeeMarkupAsPkey
|
|
272
|
+
if (partnerFeeMarkup) {
|
|
273
|
+
const feeBuffer = Buffer.alloc(8)
|
|
274
|
+
feeBuffer.writeBigUInt64LE(BigInt(partnerFeeMarkup))
|
|
275
|
+
const feeBuffer32 = Buffer.alloc(32)
|
|
276
|
+
feeBuffer32.set(feeBuffer, 0)
|
|
277
|
+
partnerFeeMarkupAsPkey = new PublicKey(feeBuffer32)
|
|
278
|
+
}
|
|
259
279
|
// assuming all token accounts are created prior
|
|
260
280
|
const positionAccount = getPositionAccountPDA(lavarageProgram, offer, randomSeed.publicKey)
|
|
261
281
|
|
|
@@ -335,11 +355,15 @@ export const openTradeV2 = async (lavarageProgram: Program<LavarageV2>, offer: P
|
|
|
335
355
|
tokenProgram: tokenProgram!,
|
|
336
356
|
fromTokenAccount: getAssociatedTokenAddressSync(quoteToken, offer.account.nodeWallet, true, tokenProgram),
|
|
337
357
|
})
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
358
|
+
.remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
|
|
359
|
+
pubkey: partnerFeeRecipient,
|
|
360
|
+
isSigner: false,
|
|
361
|
+
isWritable: true,
|
|
362
|
+
}, {
|
|
363
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
364
|
+
isSigner: false,
|
|
365
|
+
isWritable: false,
|
|
366
|
+
}] : [])
|
|
343
367
|
.instruction()
|
|
344
368
|
|
|
345
369
|
const openAddCollateralInstruction = await lavarageProgram.methods
|
|
@@ -572,7 +596,15 @@ export const closeTradeV1 = async (lavarageProgram: Program<Lavarage>, position:
|
|
|
572
596
|
addressLookupTableAddresses: string[]
|
|
573
597
|
},
|
|
574
598
|
quoteResponse: any
|
|
575
|
-
}, partnerFeeRecipient?: PublicKey,
|
|
599
|
+
}, partnerFeeRecipient?: PublicKey, partnerFeeMarkup?: number) => {
|
|
600
|
+
let partnerFeeMarkupAsPkey
|
|
601
|
+
if (partnerFeeMarkup) {
|
|
602
|
+
const feeBuffer = Buffer.alloc(8)
|
|
603
|
+
feeBuffer.writeBigUInt64LE(BigInt(partnerFeeMarkup))
|
|
604
|
+
const feeBuffer32 = Buffer.alloc(32)
|
|
605
|
+
feeBuffer32.set(feeBuffer, 0)
|
|
606
|
+
partnerFeeMarkupAsPkey = new PublicKey(feeBuffer32)
|
|
607
|
+
}
|
|
576
608
|
if (position.account.pool.toBase58() != offer.publicKey.toBase58()) throw "Mismatch offer"
|
|
577
609
|
const pool = offer
|
|
578
610
|
const poolPubKey = offer.publicKey
|
|
@@ -661,11 +693,15 @@ export const closeTradeV1 = async (lavarageProgram: Program<Lavarage>, position:
|
|
|
661
693
|
randomAccountAsId: position.account.seed,
|
|
662
694
|
feeReceipient: '6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF',
|
|
663
695
|
})
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
696
|
+
.remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
|
|
697
|
+
pubkey: partnerFeeRecipient,
|
|
698
|
+
isSigner: false,
|
|
699
|
+
isWritable: true,
|
|
700
|
+
}, {
|
|
701
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
702
|
+
isSigner: false,
|
|
703
|
+
isWritable: false,
|
|
704
|
+
}] : [])
|
|
669
705
|
.instruction()
|
|
670
706
|
} else {
|
|
671
707
|
repaySolIx = await lavarageProgram.methods
|
|
@@ -680,11 +716,15 @@ export const closeTradeV1 = async (lavarageProgram: Program<Lavarage>, position:
|
|
|
680
716
|
randomAccountAsId: position.account.seed,
|
|
681
717
|
feeReceipient: '6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF',
|
|
682
718
|
})
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
719
|
+
.remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
|
|
720
|
+
pubkey: partnerFeeRecipient,
|
|
721
|
+
isSigner: false,
|
|
722
|
+
isWritable: true,
|
|
723
|
+
}, {
|
|
724
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
725
|
+
isSigner: false,
|
|
726
|
+
isWritable: false,
|
|
727
|
+
}] : [])
|
|
688
728
|
.instruction()
|
|
689
729
|
const { setupInstructions, swapInstruction: swapInstructionPayload, cleanupInstruction, addressLookupTableAddresses } = jupiterSellIx!
|
|
690
730
|
jupiterIxs = [
|
|
@@ -700,13 +740,6 @@ export const closeTradeV1 = async (lavarageProgram: Program<Lavarage>, position:
|
|
|
700
740
|
closePositionIx,
|
|
701
741
|
...jupiterIxs,
|
|
702
742
|
repaySolIx,
|
|
703
|
-
profitFeeMarkup && partnerFeeRecipient ? SystemProgram.transfer(
|
|
704
|
-
{
|
|
705
|
-
fromPubkey: lavarageProgram.provider.publicKey!,
|
|
706
|
-
toPubkey: partnerFeeRecipient!,
|
|
707
|
-
lamports: profit.toNumber() > 0 ? profit.mul(new BN(profitFeeMarkup * 10000)).div(new BN(10000)).toNumber() : 0
|
|
708
|
-
}
|
|
709
|
-
) : null,
|
|
710
743
|
].filter(i => !!i)
|
|
711
744
|
|
|
712
745
|
const messageV0 = new TransactionMessage({
|
|
@@ -737,7 +770,15 @@ export const closeTradeV2 = async (lavarageProgram: Program<LavarageV2>, positio
|
|
|
737
770
|
addressLookupTableAddresses: string[]
|
|
738
771
|
},
|
|
739
772
|
quoteResponse: any
|
|
740
|
-
}, quoteToken: PublicKey, partnerFeeRecipient?: PublicKey,
|
|
773
|
+
}, quoteToken: PublicKey, partnerFeeRecipient?: PublicKey, partnerFeeMarkup?: number) => {
|
|
774
|
+
let partnerFeeMarkupAsPkey
|
|
775
|
+
if (partnerFeeMarkup) {
|
|
776
|
+
const feeBuffer = Buffer.alloc(8)
|
|
777
|
+
feeBuffer.writeBigUInt64LE(BigInt(partnerFeeMarkup))
|
|
778
|
+
const feeBuffer32 = Buffer.alloc(32)
|
|
779
|
+
feeBuffer32.set(feeBuffer, 0)
|
|
780
|
+
partnerFeeMarkupAsPkey = new PublicKey(feeBuffer32)
|
|
781
|
+
}
|
|
741
782
|
if (position.account.pool.toBase58() != offer.publicKey.toBase58()) throw "Mismatch offer"
|
|
742
783
|
const pool = offer
|
|
743
784
|
const poolPubKey = offer.publicKey
|
|
@@ -829,11 +870,15 @@ export const closeTradeV2 = async (lavarageProgram: Program<LavarageV2>, positio
|
|
|
829
870
|
toTokenAccount: getAssociatedTokenAddressSync(quoteToken, pool.account.nodeWallet, true, quoteTokenProgram),
|
|
830
871
|
mint: quoteToken,
|
|
831
872
|
})
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
873
|
+
.remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
|
|
874
|
+
pubkey: partnerFeeRecipient,
|
|
875
|
+
isSigner: false,
|
|
876
|
+
isWritable: true,
|
|
877
|
+
}, {
|
|
878
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
879
|
+
isSigner: false,
|
|
880
|
+
isWritable: false,
|
|
881
|
+
}] : [])
|
|
837
882
|
.instruction()
|
|
838
883
|
} else {
|
|
839
884
|
repaySolIx = await lavarageProgram.methods
|
|
@@ -852,11 +897,15 @@ export const closeTradeV2 = async (lavarageProgram: Program<LavarageV2>, positio
|
|
|
852
897
|
toTokenAccount: getAssociatedTokenAddressSync(quoteToken, pool.account.nodeWallet, true, quoteTokenProgram),
|
|
853
898
|
mint: quoteToken,
|
|
854
899
|
})
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
900
|
+
.remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
|
|
901
|
+
pubkey: partnerFeeRecipient,
|
|
902
|
+
isSigner: false,
|
|
903
|
+
isWritable: true,
|
|
904
|
+
}, {
|
|
905
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
906
|
+
isSigner: false,
|
|
907
|
+
isWritable: false,
|
|
908
|
+
}] : [])
|
|
860
909
|
.instruction()
|
|
861
910
|
const { setupInstructions, swapInstruction: swapInstructionPayload, cleanupInstruction, addressLookupTableAddresses } = jupiterSellIx!
|
|
862
911
|
jupiterIxs = [
|
|
@@ -872,14 +921,6 @@ export const closeTradeV2 = async (lavarageProgram: Program<LavarageV2>, positio
|
|
|
872
921
|
closePositionIx,
|
|
873
922
|
...jupiterIxs,
|
|
874
923
|
repaySolIx,
|
|
875
|
-
profitFeeMarkup && partnerFeeRecipient ? createTransferInstruction(
|
|
876
|
-
getAssociatedTokenAddressSync(quoteToken, lavarageProgram.provider.publicKey!, false, quoteTokenProgram),
|
|
877
|
-
partnerFeeRecipient,
|
|
878
|
-
lavarageProgram.provider.publicKey!,
|
|
879
|
-
profit.toNumber() > 0 ? profit.mul(new BN(profitFeeMarkup * 1000)).div(new BN(1000)).toNumber() : 0,
|
|
880
|
-
[],
|
|
881
|
-
quoteTokenProgram!,
|
|
882
|
-
) : null,
|
|
883
924
|
].filter(i => !!i)
|
|
884
925
|
|
|
885
926
|
const messageV0 = new TransactionMessage({
|