@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/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
|
|
|
@@ -200,10 +208,15 @@ export const openTradeV1 = async (lavarageProgram: Program<Lavarage>, offer: Pro
|
|
|
200
208
|
clock: SYSVAR_CLOCK_PUBKEY,
|
|
201
209
|
randomAccountAsId: randomSeed.publicKey.toBase58(),
|
|
202
210
|
feeReceipient: '6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF',
|
|
203
|
-
})
|
|
211
|
+
})
|
|
212
|
+
.remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
|
|
204
213
|
pubkey: partnerFeeRecipient,
|
|
205
214
|
isSigner: false,
|
|
206
215
|
isWritable: true,
|
|
216
|
+
}, {
|
|
217
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
218
|
+
isSigner: false,
|
|
219
|
+
isWritable: false,
|
|
207
220
|
}] : [])
|
|
208
221
|
.instruction()
|
|
209
222
|
|
|
@@ -254,7 +267,15 @@ export const openTradeV2 = async (lavarageProgram: Program<LavarageV2>, offer: P
|
|
|
254
267
|
swapInstruction: Record<string, unknown>
|
|
255
268
|
addressLookupTableAddresses: string[]
|
|
256
269
|
}
|
|
257
|
-
}, 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
|
+
}
|
|
258
279
|
// assuming all token accounts are created prior
|
|
259
280
|
const positionAccount = getPositionAccountPDA(lavarageProgram, offer, randomSeed.publicKey)
|
|
260
281
|
|
|
@@ -333,10 +354,15 @@ export const openTradeV2 = async (lavarageProgram: Program<LavarageV2>, offer: P
|
|
|
333
354
|
toTokenAccount: getAssociatedTokenAddressSync(quoteToken, lavarageProgram.provider.publicKey!, true, quoteTokenProgram),
|
|
334
355
|
tokenProgram: tokenProgram!,
|
|
335
356
|
fromTokenAccount: getAssociatedTokenAddressSync(quoteToken, offer.account.nodeWallet, true, tokenProgram),
|
|
336
|
-
})
|
|
357
|
+
})
|
|
358
|
+
.remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
|
|
337
359
|
pubkey: partnerFeeRecipient,
|
|
338
360
|
isSigner: false,
|
|
339
361
|
isWritable: true,
|
|
362
|
+
}, {
|
|
363
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
364
|
+
isSigner: false,
|
|
365
|
+
isWritable: false,
|
|
340
366
|
}] : [])
|
|
341
367
|
.instruction()
|
|
342
368
|
|
|
@@ -570,7 +596,15 @@ export const closeTradeV1 = async (lavarageProgram: Program<Lavarage>, position:
|
|
|
570
596
|
addressLookupTableAddresses: string[]
|
|
571
597
|
},
|
|
572
598
|
quoteResponse: any
|
|
573
|
-
}, 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
|
+
}
|
|
574
608
|
if (position.account.pool.toBase58() != offer.publicKey.toBase58()) throw "Mismatch offer"
|
|
575
609
|
const pool = offer
|
|
576
610
|
const poolPubKey = offer.publicKey
|
|
@@ -658,10 +692,15 @@ export const closeTradeV1 = async (lavarageProgram: Program<Lavarage>, position:
|
|
|
658
692
|
clock: SYSVAR_CLOCK_PUBKEY,
|
|
659
693
|
randomAccountAsId: position.account.seed,
|
|
660
694
|
feeReceipient: '6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF',
|
|
661
|
-
})
|
|
695
|
+
})
|
|
696
|
+
.remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
|
|
662
697
|
pubkey: partnerFeeRecipient,
|
|
663
698
|
isSigner: false,
|
|
664
699
|
isWritable: true,
|
|
700
|
+
}, {
|
|
701
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
702
|
+
isSigner: false,
|
|
703
|
+
isWritable: false,
|
|
665
704
|
}] : [])
|
|
666
705
|
.instruction()
|
|
667
706
|
} else {
|
|
@@ -676,10 +715,15 @@ export const closeTradeV1 = async (lavarageProgram: Program<Lavarage>, position:
|
|
|
676
715
|
clock: SYSVAR_CLOCK_PUBKEY,
|
|
677
716
|
randomAccountAsId: position.account.seed,
|
|
678
717
|
feeReceipient: '6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF',
|
|
679
|
-
})
|
|
718
|
+
})
|
|
719
|
+
.remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
|
|
680
720
|
pubkey: partnerFeeRecipient,
|
|
681
721
|
isSigner: false,
|
|
682
722
|
isWritable: true,
|
|
723
|
+
}, {
|
|
724
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
725
|
+
isSigner: false,
|
|
726
|
+
isWritable: false,
|
|
683
727
|
}] : [])
|
|
684
728
|
.instruction()
|
|
685
729
|
const { setupInstructions, swapInstruction: swapInstructionPayload, cleanupInstruction, addressLookupTableAddresses } = jupiterSellIx!
|
|
@@ -696,13 +740,6 @@ export const closeTradeV1 = async (lavarageProgram: Program<Lavarage>, position:
|
|
|
696
740
|
closePositionIx,
|
|
697
741
|
...jupiterIxs,
|
|
698
742
|
repaySolIx,
|
|
699
|
-
profitFeeMarkup && partnerFeeRecipient ? SystemProgram.transfer(
|
|
700
|
-
{
|
|
701
|
-
fromPubkey: lavarageProgram.provider.publicKey!,
|
|
702
|
-
toPubkey: partnerFeeRecipient!,
|
|
703
|
-
lamports: profit.toNumber() > 0 ? profit.mul(new BN(profitFeeMarkup * 10000)).div(new BN(10000)).toNumber() : 0
|
|
704
|
-
}
|
|
705
|
-
) : null,
|
|
706
743
|
].filter(i => !!i)
|
|
707
744
|
|
|
708
745
|
const messageV0 = new TransactionMessage({
|
|
@@ -733,7 +770,15 @@ export const closeTradeV2 = async (lavarageProgram: Program<LavarageV2>, positio
|
|
|
733
770
|
addressLookupTableAddresses: string[]
|
|
734
771
|
},
|
|
735
772
|
quoteResponse: any
|
|
736
|
-
}, 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
|
+
}
|
|
737
782
|
if (position.account.pool.toBase58() != offer.publicKey.toBase58()) throw "Mismatch offer"
|
|
738
783
|
const pool = offer
|
|
739
784
|
const poolPubKey = offer.publicKey
|
|
@@ -824,10 +869,15 @@ export const closeTradeV2 = async (lavarageProgram: Program<LavarageV2>, positio
|
|
|
824
869
|
tokenProgram: quoteTokenProgram!,
|
|
825
870
|
toTokenAccount: getAssociatedTokenAddressSync(quoteToken, pool.account.nodeWallet, true, quoteTokenProgram),
|
|
826
871
|
mint: quoteToken,
|
|
827
|
-
})
|
|
872
|
+
})
|
|
873
|
+
.remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
|
|
828
874
|
pubkey: partnerFeeRecipient,
|
|
829
875
|
isSigner: false,
|
|
830
876
|
isWritable: true,
|
|
877
|
+
}, {
|
|
878
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
879
|
+
isSigner: false,
|
|
880
|
+
isWritable: false,
|
|
831
881
|
}] : [])
|
|
832
882
|
.instruction()
|
|
833
883
|
} else {
|
|
@@ -846,10 +896,15 @@ export const closeTradeV2 = async (lavarageProgram: Program<LavarageV2>, positio
|
|
|
846
896
|
tokenProgram: quoteTokenProgram!,
|
|
847
897
|
toTokenAccount: getAssociatedTokenAddressSync(quoteToken, pool.account.nodeWallet, true, quoteTokenProgram),
|
|
848
898
|
mint: quoteToken,
|
|
849
|
-
})
|
|
899
|
+
})
|
|
900
|
+
.remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
|
|
850
901
|
pubkey: partnerFeeRecipient,
|
|
851
902
|
isSigner: false,
|
|
852
903
|
isWritable: true,
|
|
904
|
+
}, {
|
|
905
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
906
|
+
isSigner: false,
|
|
907
|
+
isWritable: false,
|
|
853
908
|
}] : [])
|
|
854
909
|
.instruction()
|
|
855
910
|
const { setupInstructions, swapInstruction: swapInstructionPayload, cleanupInstruction, addressLookupTableAddresses } = jupiterSellIx!
|
|
@@ -866,14 +921,6 @@ export const closeTradeV2 = async (lavarageProgram: Program<LavarageV2>, positio
|
|
|
866
921
|
closePositionIx,
|
|
867
922
|
...jupiterIxs,
|
|
868
923
|
repaySolIx,
|
|
869
|
-
profitFeeMarkup && partnerFeeRecipient ? createTransferInstruction(
|
|
870
|
-
getAssociatedTokenAddressSync(quoteToken, lavarageProgram.provider.publicKey!, false, quoteTokenProgram),
|
|
871
|
-
partnerFeeRecipient,
|
|
872
|
-
lavarageProgram.provider.publicKey!,
|
|
873
|
-
profit.toNumber() > 0 ? profit.mul(new BN(profitFeeMarkup * 1000)).div(new BN(1000)).toNumber() : 0,
|
|
874
|
-
[],
|
|
875
|
-
quoteTokenProgram!,
|
|
876
|
-
) : null,
|
|
877
924
|
].filter(i => !!i)
|
|
878
925
|
|
|
879
926
|
const messageV0 = new TransactionMessage({
|