@lavarage/sdk 6.3.2 → 6.4.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/index.ts CHANGED
@@ -959,4 +959,98 @@ const getQuoteCurrencySpecificAddressLookupTable = (quoteCurrency: string) => {
959
959
  default:
960
960
  return '2EdNtwVhyjkEgkKDC7GShfSSczZYMKLuJraeoJzG4E4R'
961
961
  }
962
+ }
963
+
964
+ export const splitPositionV2 = async (lavarageProgram: Program<LavarageV2>, position: ProgramAccount<{
965
+ pool: PublicKey,
966
+ seed: PublicKey,
967
+ userPaid: BN,
968
+ amount: BN,
969
+ }>, offer: ProgramAccount<{
970
+ nodeWallet: PublicKey,
971
+ interestRate: number,
972
+ collateralType: PublicKey,
973
+ }>, quoteToken: PublicKey, propotionBps: number) => {
974
+ const positionAccountPDA = position.publicKey
975
+
976
+ const newPosition1Seed = Keypair.generate().publicKey
977
+ const newPosition2Seed = Keypair.generate().publicKey
978
+
979
+ const newPosition1AccountPDA = getPositionAccountPDA(lavarageProgram, offer, newPosition1Seed)
980
+ const newPosition2AccountPDA = getPositionAccountPDA(lavarageProgram, offer, newPosition2Seed)
981
+
982
+ const ix = await lavarageProgram.methods.tradingManagementSplitPosition(new BN(propotionBps), newPosition1Seed, newPosition2Seed)
983
+ .accountsStrict({
984
+ originalPosition: positionAccountPDA,
985
+ newPositionOne: newPosition1AccountPDA,
986
+ newPositionTwo: newPosition2AccountPDA,
987
+ trader: lavarageProgram.provider.publicKey!,
988
+ systemProgram: SystemProgram.programId,
989
+ })
990
+ .instruction()
991
+
992
+ const allInstructions = [
993
+ ix,
994
+ ].filter(i => !!i)
995
+
996
+ const { blockhash } = await lavarageProgram.provider.connection.getLatestBlockhash('finalized')
997
+
998
+ const messageV0 = new TransactionMessage({
999
+ payerKey: lavarageProgram.provider.publicKey!,
1000
+ recentBlockhash: blockhash,
1001
+ instructions: allInstructions,
1002
+ }).compileToV0Message()
1003
+
1004
+ const tx = new VersionedTransaction(messageV0)
1005
+
1006
+ return tx
1007
+ }
1008
+
1009
+ export const mergePositionV2 = async (lavarageProgram: Program<LavarageV2>, position1: ProgramAccount<{
1010
+ pool: PublicKey,
1011
+ seed: PublicKey,
1012
+ userPaid: BN,
1013
+ amount: BN,
1014
+ }>, position2: ProgramAccount<{
1015
+ pool: PublicKey,
1016
+ seed: PublicKey,
1017
+ userPaid: BN,
1018
+ amount: BN,
1019
+ }>, offer: ProgramAccount<{
1020
+ nodeWallet: PublicKey,
1021
+ interestRate: number,
1022
+ collateralType: PublicKey,
1023
+ }>, quoteToken: PublicKey) => {
1024
+ const positionAccountPDA1 = position1.publicKey
1025
+ const positionAccountPDA2 = position2.publicKey
1026
+
1027
+ const newPositionSeed = Keypair.generate().publicKey
1028
+
1029
+ const newPositionAccountPDA = getPositionAccountPDA(lavarageProgram, offer, newPositionSeed)
1030
+
1031
+ const ix = await lavarageProgram.methods.tradingManagementMergePositions(newPositionSeed)
1032
+ .accountsStrict({
1033
+ mergedPosition: newPositionAccountPDA,
1034
+ positionOne: positionAccountPDA1,
1035
+ positionTwo: positionAccountPDA2,
1036
+ trader: lavarageProgram.provider.publicKey!,
1037
+ systemProgram: SystemProgram.programId,
1038
+ })
1039
+ .instruction()
1040
+
1041
+ const allInstructions = [
1042
+ ix,
1043
+ ].filter(i => !!i)
1044
+
1045
+ const { blockhash } = await lavarageProgram.provider.connection.getLatestBlockhash('finalized')
1046
+
1047
+ const messageV0 = new TransactionMessage({
1048
+ payerKey: lavarageProgram.provider.publicKey!,
1049
+ recentBlockhash: blockhash,
1050
+ instructions: allInstructions,
1051
+ }).compileToV0Message()
1052
+
1053
+ const tx = new VersionedTransaction(messageV0)
1054
+
1055
+ return tx
962
1056
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lavarage/sdk",
3
- "version": "6.3.2",
3
+ "version": "6.4.0",
4
4
  "description": "Lavarage SDK",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",