@lavarage/sdk 5.1.0 → 6.0.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.mjs CHANGED
@@ -28,7 +28,7 @@ var __async = (__this, __arguments, generator) => {
28
28
  import { BN } from "@coral-xyz/anchor";
29
29
  import bs58 from "bs58";
30
30
  import { AddressLookupTableAccount, ComputeBudgetProgram, PublicKey, SystemProgram, SYSVAR_CLOCK_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, Transaction, TransactionInstruction, TransactionMessage, VersionedTransaction } from "@solana/web3.js";
31
- import { ASSOCIATED_TOKEN_PROGRAM_ID, createAssociatedTokenAccountInstruction, getAccount, getAssociatedTokenAddressSync, TOKEN_PROGRAM_ID, TokenAccountNotFoundError, TokenInvalidAccountOwnerError } from "@solana/spl-token";
31
+ import { ASSOCIATED_TOKEN_PROGRAM_ID, createAssociatedTokenAccountInstruction, createTransferInstruction, getAccount, getAssociatedTokenAddressSync, TokenAccountNotFoundError, TokenInvalidAccountOwnerError } from "@solana/spl-token";
32
32
 
33
33
  // idl/lavarage.ts
34
34
  var IDL = {
@@ -788,123 +788,6 @@ var IDL = {
788
788
  }
789
789
  ],
790
790
  "args": []
791
- },
792
- {
793
- "name": "delegateExecuteTp",
794
- "accounts": [
795
- {
796
- "name": "delegate",
797
- "isMut": true,
798
- "isSigner": false
799
- },
800
- {
801
- "name": "delegateOperator",
802
- "isMut": false,
803
- "isSigner": true
804
- },
805
- {
806
- "name": "account",
807
- "isMut": true,
808
- "isSigner": false
809
- },
810
- {
811
- "name": "tradingPool",
812
- "isMut": true,
813
- "isSigner": false
814
- },
815
- {
816
- "name": "tokenProgram",
817
- "isMut": false,
818
- "isSigner": false
819
- },
820
- {
821
- "name": "positionTokenAccount",
822
- "isMut": true,
823
- "isSigner": false
824
- },
825
- {
826
- "name": "delegateTokenAccount",
827
- "isMut": true,
828
- "isSigner": false
829
- },
830
- {
831
- "name": "systemProgram",
832
- "isMut": false,
833
- "isSigner": false
834
- }
835
- ],
836
- "args": [
837
- {
838
- "name": "seed",
839
- "type": "publicKey"
840
- }
841
- ]
842
- },
843
- {
844
- "name": "delegateClosePosition",
845
- "accounts": [
846
- {
847
- "name": "delegate",
848
- "isMut": true,
849
- "isSigner": false
850
- },
851
- {
852
- "name": "delegateOperator",
853
- "isMut": false,
854
- "isSigner": true
855
- },
856
- {
857
- "name": "account",
858
- "isMut": true,
859
- "isSigner": false
860
- },
861
- {
862
- "name": "tradingPool",
863
- "isMut": true,
864
- "isSigner": false
865
- },
866
- {
867
- "name": "nodeWallet",
868
- "isMut": true,
869
- "isSigner": false
870
- },
871
- {
872
- "name": "tokenProgram",
873
- "isMut": false,
874
- "isSigner": false
875
- },
876
- {
877
- "name": "nodeWalletTokenAccount",
878
- "isMut": true,
879
- "isSigner": false
880
- },
881
- {
882
- "name": "delegateTokenAccount",
883
- "isMut": true,
884
- "isSigner": false
885
- },
886
- {
887
- "name": "feeTokenAccount",
888
- "isMut": true,
889
- "isSigner": false
890
- },
891
- {
892
- "name": "profitTokenAccount",
893
- "isMut": true,
894
- "isSigner": false
895
- },
896
- {
897
- "name": "systemProgram",
898
- "isMut": false,
899
- "isSigner": false
900
- }
901
- ],
902
- "args": [
903
- {
904
- "name": "closingPositionSize",
905
- "type": "u64"
906
- }
907
- ]
908
791
  }
909
792
  ],
910
793
  "accounts": [
@@ -2092,123 +1975,6 @@ var IDL2 = {
2092
1975
  }
2093
1976
  ]
2094
1977
  },
2095
- {
2096
- "name": "delegateExecuteTp",
2097
- "accounts": [
2098
- {
2099
- "name": "delegate",
2100
- "isMut": true,
2101
- "isSigner": false
2102
- },
2103
- {
2104
- "name": "delegateOperator",
2105
- "isMut": false,
2106
- "isSigner": true
2107
- },
2108
- {
2109
- "name": "account",
2110
- "isMut": true,
2111
- "isSigner": false
2112
- },
2113
- {
2114
- "name": "tradingPool",
2115
- "isMut": true,
2116
- "isSigner": false
2117
- },
2118
- {
2119
- "name": "tokenProgram",
2120
- "isMut": false,
2121
- "isSigner": false
2122
- },
2123
- {
2124
- "name": "positionTokenAccount",
2125
- "isMut": true,
2126
- "isSigner": false
2127
- },
2128
- {
2129
- "name": "delegateTokenAccount",
2130
- "isMut": true,
2131
- "isSigner": false
2132
- },
2133
- {
2134
- "name": "systemProgram",
2135
- "isMut": false,
2136
- "isSigner": false
2137
- }
2138
- ],
2139
- "args": [
2140
- {
2141
- "name": "seed",
2142
- "type": "publicKey"
2143
- }
2144
- ]
2145
- },
2146
- {
2147
- "name": "delegateClosePosition",
2148
- "accounts": [
2149
- {
2150
- "name": "delegate",
2151
- "isMut": true,
2152
- "isSigner": false
2153
- },
2154
- {
2155
- "name": "delegateOperator",
2156
- "isMut": false,
2157
- "isSigner": true
2158
- },
2159
- {
2160
- "name": "account",
2161
- "isMut": true,
2162
- "isSigner": false
2163
- },
2164
- {
2165
- "name": "tradingPool",
2166
- "isMut": true,
2167
- "isSigner": false
2168
- },
2169
- {
2170
- "name": "nodeWallet",
2171
- "isMut": true,
2172
- "isSigner": false
2173
- },
2174
- {
2175
- "name": "tokenProgram",
2176
- "isMut": false,
2177
- "isSigner": false
2178
- },
2179
- {
2180
- "name": "nodeWalletTokenAccount",
2181
- "isMut": true,
2182
- "isSigner": false
2183
- },
2184
- {
2185
- "name": "delegateTokenAccount",
2186
- "isMut": true,
2187
- "isSigner": false
2188
- },
2189
- {
2190
- "name": "feeTokenAccount",
2191
- "isMut": true,
2192
- "isSigner": false
2193
- },
2194
- {
2195
- "name": "profitTokenAccount",
2196
- "isMut": true,
2197
- "isSigner": false
2198
- },
2199
- {
2200
- "name": "systemProgram",
2201
- "isMut": false,
2202
- "isSigner": false
2203
- }
2204
- ],
2205
- "args": [
2206
- {
2207
- "name": "closingPositionSize",
2208
- "type": "u64"
2209
- }
2210
- ]
2211
- },
2212
1978
  {
2213
1979
  "name": "tradingRemoveTpDelegate",
2214
1980
  "accounts": [
@@ -2632,9 +2398,9 @@ function getPda(seed, programId) {
2632
2398
  function getPositionAccountPDA(lavarageProgram, offer, seed) {
2633
2399
  return getPda([Buffer.from("position"), lavarageProgram.provider.publicKey.toBuffer(), offer.publicKey.toBuffer(), seed.toBuffer()], lavarageProgram.programId);
2634
2400
  }
2635
- function getTokenAccountOrCreateIfNotExists(lavarageProgram, ownerPublicKey, tokenAddress) {
2401
+ function getTokenAccountOrCreateIfNotExists(lavarageProgram, ownerPublicKey, tokenAddress, tokenProgram) {
2636
2402
  return __async(this, null, function* () {
2637
- const associatedTokenAddress = getAssociatedTokenAddressSync(tokenAddress, ownerPublicKey, true, TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID);
2403
+ const associatedTokenAddress = getAssociatedTokenAddressSync(tokenAddress, ownerPublicKey, true, tokenProgram, ASSOCIATED_TOKEN_PROGRAM_ID);
2638
2404
  try {
2639
2405
  const tokenAccount = yield getAccount(lavarageProgram.provider.connection, associatedTokenAddress, "finalized");
2640
2406
  return { account: tokenAccount, instruction: null };
@@ -2645,7 +2411,7 @@ function getTokenAccountOrCreateIfNotExists(lavarageProgram, ownerPublicKey, tok
2645
2411
  associatedTokenAddress,
2646
2412
  ownerPublicKey,
2647
2413
  tokenAddress,
2648
- TOKEN_PROGRAM_ID,
2414
+ tokenProgram,
2649
2415
  ASSOCIATED_TOKEN_PROGRAM_ID
2650
2416
  );
2651
2417
  return {
@@ -2732,8 +2498,10 @@ var getAllPositions = (lavarageProgram) => {
2732
2498
  };
2733
2499
  var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage, randomSeed, partnerFeeRecipient) => __async(void 0, null, function* () {
2734
2500
  const positionAccount = getPositionAccountPDA(lavarageProgram, offer, randomSeed.publicKey);
2735
- const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, lavarageProgram.provider.publicKey, offer.account.collateralType);
2736
- const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, positionAccount, offer.account.collateralType);
2501
+ const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(offer.account.collateralType);
2502
+ const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
2503
+ const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, lavarageProgram.provider.publicKey, offer.account.collateralType, tokenProgram);
2504
+ const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, positionAccount, offer.account.collateralType, tokenProgram);
2737
2505
  const tokenAccountCreationTx = new Transaction();
2738
2506
  if (fromTokenAccount.instruction) {
2739
2507
  tokenAccountCreationTx.add(fromTokenAccount.instruction);
@@ -2816,8 +2584,12 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2816
2584
  });
2817
2585
  var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage, randomSeed, quoteToken, partnerFeeRecipient) => __async(void 0, null, function* () {
2818
2586
  const positionAccount = getPositionAccountPDA(lavarageProgram, offer, randomSeed.publicKey);
2819
- const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, lavarageProgram.provider.publicKey, offer.account.collateralType);
2820
- const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, positionAccount, offer.account.collateralType);
2587
+ const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(offer.account.collateralType);
2588
+ const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
2589
+ const quoteMintAccount = yield lavarageProgram.provider.connection.getAccountInfo(quoteToken);
2590
+ const quoteTokenProgram = quoteMintAccount == null ? void 0 : quoteMintAccount.owner;
2591
+ const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, lavarageProgram.provider.publicKey, offer.account.collateralType, tokenProgram);
2592
+ const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, positionAccount, offer.account.collateralType, tokenProgram);
2821
2593
  const tokenAccountCreationTx = new Transaction();
2822
2594
  if (fromTokenAccount.instruction) {
2823
2595
  tokenAccountCreationTx.add(fromTokenAccount.instruction);
@@ -2865,9 +2637,9 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2865
2637
  clock: SYSVAR_CLOCK_PUBKEY,
2866
2638
  randomAccountAsId: randomSeed.publicKey.toBase58(),
2867
2639
  feeTokenAccount: getAssociatedTokenAddressSync(quoteToken, new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF")),
2868
- toTokenAccount: getAssociatedTokenAddressSync(quoteToken, lavarageProgram.provider.publicKey),
2869
- tokenProgram: TOKEN_PROGRAM_ID,
2870
- fromTokenAccount: getAssociatedTokenAddressSync(quoteToken, offer.account.nodeWallet, true)
2640
+ toTokenAccount: getAssociatedTokenAddressSync(quoteToken, lavarageProgram.provider.publicKey, true, quoteTokenProgram),
2641
+ tokenProgram,
2642
+ fromTokenAccount: getAssociatedTokenAddressSync(quoteToken, offer.account.nodeWallet, true, tokenProgram)
2871
2643
  }).remainingAccounts(partnerFeeRecipient ? [{
2872
2644
  pubkey: partnerFeeRecipient,
2873
2645
  isSigner: false,
@@ -2986,9 +2758,11 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
2986
2758
  const pool = offer;
2987
2759
  const poolPubKey = offer.publicKey;
2988
2760
  const tokenAddressPubKey = new PublicKey(offer.account.collateralType);
2761
+ const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(offer.account.collateralType);
2762
+ const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
2989
2763
  const positionAccountPDA = position.publicKey;
2990
- const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, positionAccountPDA, tokenAddressPubKey);
2991
- const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, lavarageProgram.provider.publicKey, tokenAddressPubKey);
2764
+ const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, positionAccountPDA, tokenAddressPubKey, tokenProgram);
2765
+ const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, lavarageProgram.provider.publicKey, tokenAddressPubKey, tokenProgram);
2992
2766
  const jupiterSellIx = jupInstruction.instructions;
2993
2767
  const deserializeInstruction = (instruction) => {
2994
2768
  return new TransactionInstruction({
@@ -3027,7 +2801,7 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
3027
2801
  clock: SYSVAR_CLOCK_PUBKEY,
3028
2802
  systemProgram: SystemProgram.programId,
3029
2803
  trader: lavarageProgram.provider.publicKey,
3030
- tokenProgram: TOKEN_PROGRAM_ID,
2804
+ tokenProgram,
3031
2805
  randomAccountAsId: position.account.seed
3032
2806
  }).instruction();
3033
2807
  let repaySolIx = null;
@@ -3097,9 +2871,13 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
3097
2871
  const pool = offer;
3098
2872
  const poolPubKey = offer.publicKey;
3099
2873
  const tokenAddressPubKey = new PublicKey(offer.account.collateralType);
2874
+ const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(offer.account.collateralType);
2875
+ const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
2876
+ const quoteMintAccount = yield lavarageProgram.provider.connection.getAccountInfo(quoteToken);
2877
+ const quoteTokenProgram = quoteMintAccount == null ? void 0 : quoteMintAccount.owner;
3100
2878
  const positionAccountPDA = position.publicKey;
3101
- const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, positionAccountPDA, tokenAddressPubKey);
3102
- const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, lavarageProgram.provider.publicKey, tokenAddressPubKey);
2879
+ const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, positionAccountPDA, tokenAddressPubKey, tokenProgram);
2880
+ const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, lavarageProgram.provider.publicKey, tokenAddressPubKey, tokenProgram);
3103
2881
  const jupiterSellIx = jupInstruction.instructions;
3104
2882
  const deserializeInstruction = (instruction) => {
3105
2883
  return new TransactionInstruction({
@@ -3138,7 +2916,7 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
3138
2916
  clock: SYSVAR_CLOCK_PUBKEY,
3139
2917
  systemProgram: SystemProgram.programId,
3140
2918
  trader: lavarageProgram.provider.publicKey,
3141
- tokenProgram: TOKEN_PROGRAM_ID,
2919
+ tokenProgram,
3142
2920
  randomAccountAsId: position.account.seed
3143
2921
  }).instruction();
3144
2922
  let repaySolIx = null;
@@ -3152,10 +2930,10 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
3152
2930
  systemProgram: SystemProgram.programId,
3153
2931
  clock: SYSVAR_CLOCK_PUBKEY,
3154
2932
  randomAccountAsId: position.account.seed,
3155
- feeTokenAccount: getAssociatedTokenAddressSync(quoteToken, new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF")),
3156
- fromTokenAccount: getAssociatedTokenAddressSync(quoteToken, lavarageProgram.provider.publicKey),
3157
- tokenProgram: TOKEN_PROGRAM_ID,
3158
- toTokenAccount: getAssociatedTokenAddressSync(quoteToken, pool.account.nodeWallet, true),
2933
+ feeTokenAccount: getAssociatedTokenAddressSync(quoteToken, new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"), false, quoteTokenProgram),
2934
+ fromTokenAccount: getAssociatedTokenAddressSync(quoteToken, lavarageProgram.provider.publicKey, false, quoteTokenProgram),
2935
+ tokenProgram: quoteTokenProgram,
2936
+ toTokenAccount: getAssociatedTokenAddressSync(quoteToken, pool.account.nodeWallet, true, quoteTokenProgram),
3159
2937
  mint: quoteToken
3160
2938
  }).remainingAccounts(partnerFeeRecipient ? [{
3161
2939
  pubkey: partnerFeeRecipient,
@@ -3171,10 +2949,10 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
3171
2949
  systemProgram: SystemProgram.programId,
3172
2950
  clock: SYSVAR_CLOCK_PUBKEY,
3173
2951
  randomAccountAsId: position.account.seed,
3174
- feeTokenAccount: getAssociatedTokenAddressSync(quoteToken, new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF")),
3175
- fromTokenAccount: getAssociatedTokenAddressSync(quoteToken, lavarageProgram.provider.publicKey),
3176
- tokenProgram: TOKEN_PROGRAM_ID,
3177
- toTokenAccount: getAssociatedTokenAddressSync(quoteToken, pool.account.nodeWallet, true),
2952
+ feeTokenAccount: getAssociatedTokenAddressSync(quoteToken, new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"), false, quoteTokenProgram),
2953
+ fromTokenAccount: getAssociatedTokenAddressSync(quoteToken, lavarageProgram.provider.publicKey, false, quoteTokenProgram),
2954
+ tokenProgram: quoteTokenProgram,
2955
+ toTokenAccount: getAssociatedTokenAddressSync(quoteToken, pool.account.nodeWallet, true, quoteTokenProgram),
3178
2956
  mint: quoteToken
3179
2957
  }).remainingAccounts(partnerFeeRecipient ? [{
3180
2958
  pubkey: partnerFeeRecipient,
@@ -3195,12 +2973,13 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
3195
2973
  closePositionIx,
3196
2974
  ...jupiterIxs,
3197
2975
  repaySolIx,
3198
- profitFeeMarkup && partnerFeeRecipient ? SystemProgram.transfer(
3199
- {
3200
- fromPubkey: lavarageProgram.provider.publicKey,
3201
- toPubkey: partnerFeeRecipient,
3202
- lamports: profit.toNumber() > 0 ? profit.mul(new BN(profitFeeMarkup * 1e3)).div(new BN(1e3)).toNumber() : 0
3203
- }
2976
+ profitFeeMarkup && partnerFeeRecipient ? createTransferInstruction(
2977
+ getAssociatedTokenAddressSync(quoteToken, lavarageProgram.provider.publicKey, false, quoteTokenProgram),
2978
+ partnerFeeRecipient,
2979
+ lavarageProgram.provider.publicKey,
2980
+ profit.toNumber() > 0 ? profit.mul(new BN(profitFeeMarkup * 1e3)).div(new BN(1e3)).toNumber() : 0,
2981
+ [],
2982
+ quoteTokenProgram
3204
2983
  ) : null
3205
2984
  ].filter((i) => !!i);
3206
2985
  const messageV0 = new TransactionMessage({