@lavarage/sdk 6.5.0 → 6.7.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Program, ProgramAccount, BN } from '@coral-xyz/anchor';
2
2
  import { PublicKey, Keypair, VersionedTransaction } from '@solana/web3.js';
3
- import { Signer, BigNumberish, ContractTransaction, Provider } from 'ethers';
3
+ import { Provider, BigNumberish, ContractTransaction } from 'ethers';
4
4
 
5
5
  type Lavarage$1 = {
6
6
  "version": "0.1.0";
@@ -2675,13 +2675,13 @@ interface LiquidationEvent {
2675
2675
  }
2676
2676
 
2677
2677
  /**
2678
- * Opens a trading position on EVM chain
2679
- * @param signer - Ethers signer
2678
+ * Creates an unsigned transaction to open a trading position on EVM chain
2679
+ * @param provider - Ethers provider
2680
2680
  * @param borrowerOpsContractAddress - BorrowerOperations contract address
2681
2681
  * @param params - Trading parameters
2682
- * @returns Transaction object
2682
+ * @returns Unsigned transaction object
2683
2683
  */
2684
- declare const openPositionEvm: (signer: Signer, borrowerOpsContractAddress: string, { buyingCode, tokenCollateral, borrowAmount, tokenHolder, inchRouter, integratorFeeAddress, buyerContribution, }: {
2684
+ declare const openPositionEvm: (provider: Provider, borrowerOpsContractAddress: string, { buyingCode, tokenCollateral, borrowAmount, tokenHolder, inchRouter, integratorFeeAddress, buyerContribution, gasLimit, gasPrice, }: {
2685
2685
  buyingCode: string;
2686
2686
  tokenCollateral: string;
2687
2687
  borrowAmount: BigNumberish;
@@ -2689,20 +2689,24 @@ declare const openPositionEvm: (signer: Signer, borrowerOpsContractAddress: stri
2689
2689
  inchRouter: string;
2690
2690
  integratorFeeAddress?: string;
2691
2691
  buyerContribution: BigNumberish;
2692
+ gasLimit?: string | number;
2693
+ gasPrice?: string | number;
2692
2694
  }) => Promise<ContractTransaction>;
2693
2695
  /**
2694
- * Closes a trading position on EVM chain
2695
- * @param signer - Ethers signer
2696
+ * Creates an unsigned transaction to close a trading position on EVM chain
2697
+ * @param provider - Ethers provider
2696
2698
  * @param borrowerOpsContractAddress - BorrowerOperations contract address
2697
2699
  * @param params - Trading parameters
2698
- * @returns Transaction object
2700
+ * @returns Unsigned transaction object
2699
2701
  */
2700
- declare const closePositionEvm: (signer: Signer, borrowerOpsContractAddress: string, { loanId, sellingCode, tokenHolder, inchRouter, integratorFeeAddress, }: {
2702
+ declare const closePositionEvm: (provider: Provider, borrowerOpsContractAddress: string, { loanId, sellingCode, tokenHolder, inchRouter, integratorFeeAddress, gasLimit, gasPrice, }: {
2701
2703
  loanId: BigNumberish;
2702
2704
  sellingCode: string;
2703
2705
  tokenHolder: string;
2704
2706
  inchRouter: string;
2705
2707
  integratorFeeAddress?: string;
2708
+ gasLimit?: string | number;
2709
+ gasPrice?: string | number;
2706
2710
  }) => Promise<ContractTransaction>;
2707
2711
  /**
2708
2712
  * Get all positions from events
@@ -2841,7 +2845,7 @@ declare const openTradeV1: (lavarageProgram: Program<Lavarage$1>, offer: Program
2841
2845
  swapInstruction: Record<string, unknown>;
2842
2846
  addressLookupTableAddresses: string[];
2843
2847
  };
2844
- }, marginSOL: BN, leverage: number, randomSeed: Keypair, partnerFeeRecipient?: PublicKey, partnerFeeMarkup?: number) => Promise<VersionedTransaction>;
2848
+ }, marginSOL: BN, leverage: number, randomSeed: Keypair, tokenProgram: PublicKey, partnerFeeRecipient?: PublicKey, partnerFeeMarkup?: number) => Promise<VersionedTransaction>;
2845
2849
  declare const openTradeV2: (lavarageProgram: Program<Lavarage>, offer: ProgramAccount<{
2846
2850
  nodeWallet: PublicKey;
2847
2851
  interestRate: number;
@@ -2852,7 +2856,7 @@ declare const openTradeV2: (lavarageProgram: Program<Lavarage>, offer: ProgramAc
2852
2856
  swapInstruction: Record<string, unknown>;
2853
2857
  addressLookupTableAddresses: string[];
2854
2858
  };
2855
- }, marginSOL: BN, leverage: number, randomSeed: Keypair, quoteToken: PublicKey, partnerFeeRecipient?: PublicKey, partnerFeeMarkup?: number) => Promise<VersionedTransaction>;
2859
+ }, marginSOL: BN, leverage: number, randomSeed: Keypair, quoteToken: PublicKey, tokenProgram: PublicKey, partnerFeeRecipient?: PublicKey, partnerFeeMarkup?: number) => Promise<VersionedTransaction>;
2856
2860
  declare const createTpDelegate: (lavarageProgram: Program<Lavarage$1> | Program<Lavarage>, position: ProgramAccount<{
2857
2861
  pool: PublicKey;
2858
2862
  seed: PublicKey;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Program, ProgramAccount, BN } from '@coral-xyz/anchor';
2
2
  import { PublicKey, Keypair, VersionedTransaction } from '@solana/web3.js';
3
- import { Signer, BigNumberish, ContractTransaction, Provider } from 'ethers';
3
+ import { Provider, BigNumberish, ContractTransaction } from 'ethers';
4
4
 
5
5
  type Lavarage$1 = {
6
6
  "version": "0.1.0";
@@ -2675,13 +2675,13 @@ interface LiquidationEvent {
2675
2675
  }
2676
2676
 
2677
2677
  /**
2678
- * Opens a trading position on EVM chain
2679
- * @param signer - Ethers signer
2678
+ * Creates an unsigned transaction to open a trading position on EVM chain
2679
+ * @param provider - Ethers provider
2680
2680
  * @param borrowerOpsContractAddress - BorrowerOperations contract address
2681
2681
  * @param params - Trading parameters
2682
- * @returns Transaction object
2682
+ * @returns Unsigned transaction object
2683
2683
  */
2684
- declare const openPositionEvm: (signer: Signer, borrowerOpsContractAddress: string, { buyingCode, tokenCollateral, borrowAmount, tokenHolder, inchRouter, integratorFeeAddress, buyerContribution, }: {
2684
+ declare const openPositionEvm: (provider: Provider, borrowerOpsContractAddress: string, { buyingCode, tokenCollateral, borrowAmount, tokenHolder, inchRouter, integratorFeeAddress, buyerContribution, gasLimit, gasPrice, }: {
2685
2685
  buyingCode: string;
2686
2686
  tokenCollateral: string;
2687
2687
  borrowAmount: BigNumberish;
@@ -2689,20 +2689,24 @@ declare const openPositionEvm: (signer: Signer, borrowerOpsContractAddress: stri
2689
2689
  inchRouter: string;
2690
2690
  integratorFeeAddress?: string;
2691
2691
  buyerContribution: BigNumberish;
2692
+ gasLimit?: string | number;
2693
+ gasPrice?: string | number;
2692
2694
  }) => Promise<ContractTransaction>;
2693
2695
  /**
2694
- * Closes a trading position on EVM chain
2695
- * @param signer - Ethers signer
2696
+ * Creates an unsigned transaction to close a trading position on EVM chain
2697
+ * @param provider - Ethers provider
2696
2698
  * @param borrowerOpsContractAddress - BorrowerOperations contract address
2697
2699
  * @param params - Trading parameters
2698
- * @returns Transaction object
2700
+ * @returns Unsigned transaction object
2699
2701
  */
2700
- declare const closePositionEvm: (signer: Signer, borrowerOpsContractAddress: string, { loanId, sellingCode, tokenHolder, inchRouter, integratorFeeAddress, }: {
2702
+ declare const closePositionEvm: (provider: Provider, borrowerOpsContractAddress: string, { loanId, sellingCode, tokenHolder, inchRouter, integratorFeeAddress, gasLimit, gasPrice, }: {
2701
2703
  loanId: BigNumberish;
2702
2704
  sellingCode: string;
2703
2705
  tokenHolder: string;
2704
2706
  inchRouter: string;
2705
2707
  integratorFeeAddress?: string;
2708
+ gasLimit?: string | number;
2709
+ gasPrice?: string | number;
2706
2710
  }) => Promise<ContractTransaction>;
2707
2711
  /**
2708
2712
  * Get all positions from events
@@ -2841,7 +2845,7 @@ declare const openTradeV1: (lavarageProgram: Program<Lavarage$1>, offer: Program
2841
2845
  swapInstruction: Record<string, unknown>;
2842
2846
  addressLookupTableAddresses: string[];
2843
2847
  };
2844
- }, marginSOL: BN, leverage: number, randomSeed: Keypair, partnerFeeRecipient?: PublicKey, partnerFeeMarkup?: number) => Promise<VersionedTransaction>;
2848
+ }, marginSOL: BN, leverage: number, randomSeed: Keypair, tokenProgram: PublicKey, partnerFeeRecipient?: PublicKey, partnerFeeMarkup?: number) => Promise<VersionedTransaction>;
2845
2849
  declare const openTradeV2: (lavarageProgram: Program<Lavarage>, offer: ProgramAccount<{
2846
2850
  nodeWallet: PublicKey;
2847
2851
  interestRate: number;
@@ -2852,7 +2856,7 @@ declare const openTradeV2: (lavarageProgram: Program<Lavarage>, offer: ProgramAc
2852
2856
  swapInstruction: Record<string, unknown>;
2853
2857
  addressLookupTableAddresses: string[];
2854
2858
  };
2855
- }, marginSOL: BN, leverage: number, randomSeed: Keypair, quoteToken: PublicKey, partnerFeeRecipient?: PublicKey, partnerFeeMarkup?: number) => Promise<VersionedTransaction>;
2859
+ }, marginSOL: BN, leverage: number, randomSeed: Keypair, quoteToken: PublicKey, tokenProgram: PublicKey, partnerFeeRecipient?: PublicKey, partnerFeeMarkup?: number) => Promise<VersionedTransaction>;
2856
2860
  declare const createTpDelegate: (lavarageProgram: Program<Lavarage$1> | Program<Lavarage>, position: ProgramAccount<{
2857
2861
  pool: PublicKey;
2858
2862
  seed: PublicKey;
package/dist/index.js CHANGED
@@ -3434,51 +3434,64 @@ var tokenHolderAbi = [
3434
3434
  ];
3435
3435
 
3436
3436
  // evm.ts
3437
- var openPositionEvm = (_0, _1, _2) => __async(void 0, [_0, _1, _2], function* (signer, borrowerOpsContractAddress, {
3437
+ var openPositionEvm = (_0, _1, _2) => __async(void 0, [_0, _1, _2], function* (provider, borrowerOpsContractAddress, {
3438
3438
  buyingCode,
3439
3439
  tokenCollateral,
3440
3440
  borrowAmount,
3441
3441
  tokenHolder,
3442
3442
  inchRouter,
3443
3443
  integratorFeeAddress = import_ethers.ZeroAddress,
3444
- buyerContribution
3444
+ buyerContribution,
3445
+ gasLimit,
3446
+ gasPrice
3445
3447
  }) {
3446
3448
  const contract = new import_ethers.Contract(
3447
3449
  borrowerOpsContractAddress,
3448
3450
  borrowerOperationsAbi,
3449
- signer
3451
+ provider
3450
3452
  );
3451
- return contract.buy(
3453
+ const txOptions = {
3454
+ value: buyerContribution
3455
+ };
3456
+ if (gasLimit) txOptions.gasLimit = gasLimit;
3457
+ if (gasPrice) txOptions.gasPrice = gasPrice;
3458
+ return contract.buy.populateTransaction(
3452
3459
  buyingCode,
3453
3460
  tokenCollateral,
3454
3461
  borrowAmount,
3455
3462
  tokenHolder,
3456
3463
  inchRouter,
3457
3464
  integratorFeeAddress,
3458
- { value: buyerContribution }
3465
+ txOptions
3459
3466
  );
3460
3467
  });
3461
- var closePositionEvm = (_0, _1, _2) => __async(void 0, [_0, _1, _2], function* (signer, borrowerOpsContractAddress, {
3468
+ var closePositionEvm = (_0, _1, _2) => __async(void 0, [_0, _1, _2], function* (provider, borrowerOpsContractAddress, {
3462
3469
  loanId,
3463
3470
  sellingCode,
3464
3471
  tokenHolder,
3465
3472
  inchRouter,
3466
- integratorFeeAddress = import_ethers.ZeroAddress
3473
+ integratorFeeAddress = import_ethers.ZeroAddress,
3474
+ gasLimit,
3475
+ gasPrice
3467
3476
  }) {
3468
3477
  const contract = new import_ethers.Contract(
3469
3478
  borrowerOpsContractAddress,
3470
3479
  borrowerOperationsAbi,
3471
- signer
3480
+ provider
3472
3481
  );
3473
- return contract.sell(
3482
+ const txOptions = {};
3483
+ if (gasLimit) txOptions.gasLimit = gasLimit;
3484
+ if (gasPrice) txOptions.gasPrice = gasPrice;
3485
+ return contract.sell.populateTransaction(
3474
3486
  loanId,
3475
3487
  sellingCode,
3476
3488
  tokenHolder,
3477
3489
  inchRouter,
3478
- integratorFeeAddress
3490
+ integratorFeeAddress,
3491
+ Object.keys(txOptions).length > 0 ? txOptions : {}
3479
3492
  );
3480
3493
  });
3481
- function getPositionsEvm(provider, borrowerOpsContractAddress, fromBlock = 0) {
3494
+ function getPositionsEvm(provider, borrowerOpsContractAddress, fromBlock = 42960845) {
3482
3495
  return __async(this, null, function* () {
3483
3496
  const contract = new import_ethers.Contract(
3484
3497
  borrowerOpsContractAddress,
@@ -3489,7 +3502,7 @@ function getPositionsEvm(provider, borrowerOpsContractAddress, fromBlock = 0) {
3489
3502
  const events = yield contract.queryFilter(filter, fromBlock);
3490
3503
  return events.map((event) => {
3491
3504
  const {
3492
- trader,
3505
+ buyer,
3493
3506
  tokenCollateral,
3494
3507
  loanId,
3495
3508
  openingPositionSize,
@@ -3497,17 +3510,18 @@ function getPositionsEvm(provider, borrowerOpsContractAddress, fromBlock = 0) {
3497
3510
  initialMargin
3498
3511
  } = event.args;
3499
3512
  return {
3500
- trader,
3513
+ trader: buyer,
3501
3514
  tokenCollateral,
3502
3515
  loanId,
3503
3516
  openingPositionSize,
3504
3517
  collateralAmount,
3505
- initialMargin
3518
+ initialMargin,
3519
+ transactionHash: event.transactionHash
3506
3520
  };
3507
3521
  });
3508
3522
  });
3509
3523
  }
3510
- function getClosedPositionsEvm(provider, borrowerOpsContractAddress, fromBlock = 0) {
3524
+ function getClosedPositionsEvm(provider, borrowerOpsContractAddress, fromBlock = 42960845) {
3511
3525
  return __async(this, null, function* () {
3512
3526
  const contract = new import_ethers.Contract(
3513
3527
  borrowerOpsContractAddress,
@@ -3517,18 +3531,19 @@ function getClosedPositionsEvm(provider, borrowerOpsContractAddress, fromBlock =
3517
3531
  const filter = contract.filters.Sell();
3518
3532
  const events = yield contract.queryFilter(filter, fromBlock);
3519
3533
  return events.map((event) => {
3520
- const { trader, tokenCollateral, loanId, closingPositionSize, profit } = event.args;
3534
+ const { buyer, tokenCollateral, loanId, closingPositionSize, profit } = event.args;
3521
3535
  return {
3522
- trader,
3536
+ trader: buyer,
3523
3537
  tokenCollateral,
3524
3538
  loanId,
3525
3539
  closingPositionSize,
3526
- profit
3540
+ profit,
3541
+ transactionHash: event.transactionHash
3527
3542
  };
3528
3543
  });
3529
3544
  });
3530
3545
  }
3531
- function getLiquidatedPositionsEvm(provider, borrowerOpsContractAddress, fromBlock = 0) {
3546
+ function getLiquidatedPositionsEvm(provider, borrowerOpsContractAddress, fromBlock = 42960845) {
3532
3547
  return __async(this, null, function* () {
3533
3548
  const contract = new import_ethers.Contract(
3534
3549
  borrowerOpsContractAddress,
@@ -3539,18 +3554,19 @@ function getLiquidatedPositionsEvm(provider, borrowerOpsContractAddress, fromBlo
3539
3554
  const events = yield contract.queryFilter(filter, fromBlock);
3540
3555
  return events.map((event) => {
3541
3556
  const {
3542
- trader,
3557
+ borrower,
3543
3558
  tokenCollateral,
3544
3559
  loanId,
3545
3560
  closingPositionSize,
3546
3561
  liquidatorRepaidAmount
3547
3562
  } = event.args;
3548
3563
  return {
3549
- trader,
3564
+ trader: borrower,
3550
3565
  tokenCollateral,
3551
3566
  loanId,
3552
3567
  closingPositionSize,
3553
- liquidatorRepaidAmount
3568
+ liquidatorRepaidAmount,
3569
+ transactionHash: event.transactionHash
3554
3570
  };
3555
3571
  });
3556
3572
  });
@@ -3726,7 +3742,7 @@ var getLiquidatedPositions = (lavarageProgram) => {
3726
3742
  var getAllPositions = (lavarageProgram) => {
3727
3743
  return lavarageProgram.account.position.all([{ dataSize: 178 }]);
3728
3744
  };
3729
- var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage, randomSeed, partnerFeeRecipient, partnerFeeMarkup) => __async(void 0, null, function* () {
3745
+ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage, randomSeed, tokenProgram, partnerFeeRecipient, partnerFeeMarkup) => __async(void 0, null, function* () {
3730
3746
  let partnerFeeMarkupAsPkey;
3731
3747
  if (partnerFeeMarkup) {
3732
3748
  const feeBuffer = Buffer.alloc(8);
@@ -3740,10 +3756,6 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
3740
3756
  offer,
3741
3757
  randomSeed.publicKey
3742
3758
  );
3743
- const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(
3744
- offer.account.collateralType
3745
- );
3746
- const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
3747
3759
  const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(
3748
3760
  lavarageProgram,
3749
3761
  lavarageProgram.provider.publicKey,
@@ -3861,7 +3873,7 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
3861
3873
  const tx = new import_web3.VersionedTransaction(messageV0);
3862
3874
  return tx;
3863
3875
  });
3864
- var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage, randomSeed, quoteToken, partnerFeeRecipient, partnerFeeMarkup) => __async(void 0, null, function* () {
3876
+ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage, randomSeed, quoteToken, tokenProgram, partnerFeeRecipient, partnerFeeMarkup) => __async(void 0, null, function* () {
3865
3877
  let partnerFeeMarkupAsPkey;
3866
3878
  if (partnerFeeMarkup) {
3867
3879
  const feeBuffer = Buffer.alloc(8);
@@ -3875,10 +3887,6 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
3875
3887
  offer,
3876
3888
  randomSeed.publicKey
3877
3889
  );
3878
- const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(
3879
- offer.account.collateralType
3880
- );
3881
- const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
3882
3890
  const quoteMintAccount = yield lavarageProgram.provider.connection.getAccountInfo(quoteToken);
3883
3891
  const quoteTokenProgram = quoteMintAccount == null ? void 0 : quoteMintAccount.owner;
3884
3892
  const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(