@drift-labs/sdk 2.103.0-beta.0 → 2.103.0-beta.1
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/VERSION +1 -1
- package/lib/browser/driftClient.d.ts +1 -0
- package/lib/browser/driftClient.js +31 -0
- package/lib/node/driftClient.d.ts +1 -0
- package/lib/node/driftClient.js +31 -0
- package/package.json +1 -1
- package/src/driftClient.ts +49 -0
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.103.0-beta.
|
|
1
|
+
2.103.0-beta.1
|
|
@@ -703,6 +703,7 @@ export declare class DriftClient {
|
|
|
703
703
|
settlePNL(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
704
704
|
settlePNLIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: number): Promise<TransactionInstruction>;
|
|
705
705
|
settleMultiplePNLs(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndexes: number[], mode: SettlePnlMode, txParams?: TxParams): Promise<TransactionSignature>;
|
|
706
|
+
settleMultiplePNLsMultipleTxs(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndexes: number[], mode: SettlePnlMode, txParams?: TxParams): Promise<TransactionSignature[]>;
|
|
706
707
|
settleMultiplePNLsIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndexes: number[], mode: SettlePnlMode): Promise<TransactionInstruction>;
|
|
707
708
|
getSetUserStatusToBeingLiquidatedIx(userAccountPublicKey: PublicKey, userAccount: UserAccount): Promise<TransactionInstruction>;
|
|
708
709
|
setUserStatusToBeingLiquidated(userAccountPublicKey: PublicKey, userAccount: UserAccount): Promise<TransactionSignature>;
|
|
@@ -3626,6 +3626,37 @@ class DriftClient {
|
|
|
3626
3626
|
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.settleMultiplePNLsIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndexes, mode), txParams), [], this.opts);
|
|
3627
3627
|
return txSig;
|
|
3628
3628
|
}
|
|
3629
|
+
async settleMultiplePNLsMultipleTxs(settleeUserAccountPublicKey, settleeUserAccount, marketIndexes, mode, txParams) {
|
|
3630
|
+
// need multiple TXs because settling more than 4 markets won't fit in a single TX
|
|
3631
|
+
const txsToSign = [];
|
|
3632
|
+
const marketIndexesInFourGroups = [];
|
|
3633
|
+
for (let i = 0; i < marketIndexes.length; i += 4) {
|
|
3634
|
+
marketIndexesInFourGroups.push(marketIndexes.slice(i, i + 4));
|
|
3635
|
+
}
|
|
3636
|
+
for (const marketIndexes of marketIndexesInFourGroups) {
|
|
3637
|
+
const ix = await this.settleMultiplePNLsIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndexes, mode);
|
|
3638
|
+
const computeUnits = Math.min(300000 * marketIndexes.length, 1400000);
|
|
3639
|
+
const tx = await this.buildTransaction(ix, {
|
|
3640
|
+
...txParams,
|
|
3641
|
+
computeUnits,
|
|
3642
|
+
});
|
|
3643
|
+
txsToSign.push(tx);
|
|
3644
|
+
}
|
|
3645
|
+
const txsMap = {};
|
|
3646
|
+
let i = 1;
|
|
3647
|
+
for (const tx of txsToSign) {
|
|
3648
|
+
txsMap[`tx-${i}`] = tx;
|
|
3649
|
+
i++;
|
|
3650
|
+
}
|
|
3651
|
+
const signedTxs = (await this.txHandler.getSignedTransactionMap(txsMap, this.provider.wallet)).signedTxMap;
|
|
3652
|
+
const txSigs = [];
|
|
3653
|
+
for (const key in signedTxs) {
|
|
3654
|
+
const tx = signedTxs[key];
|
|
3655
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts, true);
|
|
3656
|
+
txSigs.push(txSig);
|
|
3657
|
+
}
|
|
3658
|
+
return txSigs;
|
|
3659
|
+
}
|
|
3629
3660
|
async settleMultiplePNLsIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndexes, mode) {
|
|
3630
3661
|
const remainingAccounts = this.getRemainingAccounts({
|
|
3631
3662
|
userAccounts: [settleeUserAccount],
|
|
@@ -703,6 +703,7 @@ export declare class DriftClient {
|
|
|
703
703
|
settlePNL(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
704
704
|
settlePNLIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: number): Promise<TransactionInstruction>;
|
|
705
705
|
settleMultiplePNLs(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndexes: number[], mode: SettlePnlMode, txParams?: TxParams): Promise<TransactionSignature>;
|
|
706
|
+
settleMultiplePNLsMultipleTxs(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndexes: number[], mode: SettlePnlMode, txParams?: TxParams): Promise<TransactionSignature[]>;
|
|
706
707
|
settleMultiplePNLsIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndexes: number[], mode: SettlePnlMode): Promise<TransactionInstruction>;
|
|
707
708
|
getSetUserStatusToBeingLiquidatedIx(userAccountPublicKey: PublicKey, userAccount: UserAccount): Promise<TransactionInstruction>;
|
|
708
709
|
setUserStatusToBeingLiquidated(userAccountPublicKey: PublicKey, userAccount: UserAccount): Promise<TransactionSignature>;
|
package/lib/node/driftClient.js
CHANGED
|
@@ -3626,6 +3626,37 @@ class DriftClient {
|
|
|
3626
3626
|
const { txSig } = await this.sendTransaction(await this.buildTransaction(await this.settleMultiplePNLsIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndexes, mode), txParams), [], this.opts);
|
|
3627
3627
|
return txSig;
|
|
3628
3628
|
}
|
|
3629
|
+
async settleMultiplePNLsMultipleTxs(settleeUserAccountPublicKey, settleeUserAccount, marketIndexes, mode, txParams) {
|
|
3630
|
+
// need multiple TXs because settling more than 4 markets won't fit in a single TX
|
|
3631
|
+
const txsToSign = [];
|
|
3632
|
+
const marketIndexesInFourGroups = [];
|
|
3633
|
+
for (let i = 0; i < marketIndexes.length; i += 4) {
|
|
3634
|
+
marketIndexesInFourGroups.push(marketIndexes.slice(i, i + 4));
|
|
3635
|
+
}
|
|
3636
|
+
for (const marketIndexes of marketIndexesInFourGroups) {
|
|
3637
|
+
const ix = await this.settleMultiplePNLsIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndexes, mode);
|
|
3638
|
+
const computeUnits = Math.min(300000 * marketIndexes.length, 1400000);
|
|
3639
|
+
const tx = await this.buildTransaction(ix, {
|
|
3640
|
+
...txParams,
|
|
3641
|
+
computeUnits,
|
|
3642
|
+
});
|
|
3643
|
+
txsToSign.push(tx);
|
|
3644
|
+
}
|
|
3645
|
+
const txsMap = {};
|
|
3646
|
+
let i = 1;
|
|
3647
|
+
for (const tx of txsToSign) {
|
|
3648
|
+
txsMap[`tx-${i}`] = tx;
|
|
3649
|
+
i++;
|
|
3650
|
+
}
|
|
3651
|
+
const signedTxs = (await this.txHandler.getSignedTransactionMap(txsMap, this.provider.wallet)).signedTxMap;
|
|
3652
|
+
const txSigs = [];
|
|
3653
|
+
for (const key in signedTxs) {
|
|
3654
|
+
const tx = signedTxs[key];
|
|
3655
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts, true);
|
|
3656
|
+
txSigs.push(txSig);
|
|
3657
|
+
}
|
|
3658
|
+
return txSigs;
|
|
3659
|
+
}
|
|
3629
3660
|
async settleMultiplePNLsIx(settleeUserAccountPublicKey, settleeUserAccount, marketIndexes, mode) {
|
|
3630
3661
|
const remainingAccounts = this.getRemainingAccounts({
|
|
3631
3662
|
userAccounts: [settleeUserAccount],
|
package/package.json
CHANGED
package/src/driftClient.ts
CHANGED
|
@@ -6792,6 +6792,55 @@ export class DriftClient {
|
|
|
6792
6792
|
return txSig;
|
|
6793
6793
|
}
|
|
6794
6794
|
|
|
6795
|
+
public async settleMultiplePNLsMultipleTxs(
|
|
6796
|
+
settleeUserAccountPublicKey: PublicKey,
|
|
6797
|
+
settleeUserAccount: UserAccount,
|
|
6798
|
+
marketIndexes: number[],
|
|
6799
|
+
mode: SettlePnlMode,
|
|
6800
|
+
txParams?: TxParams
|
|
6801
|
+
): Promise<TransactionSignature[]> {
|
|
6802
|
+
// need multiple TXs because settling more than 4 markets won't fit in a single TX
|
|
6803
|
+
const txsToSign: (Transaction | VersionedTransaction)[] = [];
|
|
6804
|
+
const marketIndexesInFourGroups: number[][] = [];
|
|
6805
|
+
for (let i = 0; i < marketIndexes.length; i += 4) {
|
|
6806
|
+
marketIndexesInFourGroups.push(marketIndexes.slice(i, i + 4));
|
|
6807
|
+
}
|
|
6808
|
+
|
|
6809
|
+
for (const marketIndexes of marketIndexesInFourGroups) {
|
|
6810
|
+
const ix = await this.settleMultiplePNLsIx(
|
|
6811
|
+
settleeUserAccountPublicKey,
|
|
6812
|
+
settleeUserAccount,
|
|
6813
|
+
marketIndexes,
|
|
6814
|
+
mode
|
|
6815
|
+
);
|
|
6816
|
+
const computeUnits = Math.min(300_000 * marketIndexes.length, 1_400_000);
|
|
6817
|
+
const tx = await this.buildTransaction(ix, {
|
|
6818
|
+
...txParams,
|
|
6819
|
+
computeUnits,
|
|
6820
|
+
});
|
|
6821
|
+
txsToSign.push(tx);
|
|
6822
|
+
}
|
|
6823
|
+
|
|
6824
|
+
const txsMap: Record<string, Transaction | VersionedTransaction> = {};
|
|
6825
|
+
let i = 1;
|
|
6826
|
+
for (const tx of txsToSign) {
|
|
6827
|
+
txsMap[`tx-${i}`] = tx;
|
|
6828
|
+
i++;
|
|
6829
|
+
}
|
|
6830
|
+
const signedTxs = (
|
|
6831
|
+
await this.txHandler.getSignedTransactionMap(txsMap, this.provider.wallet)
|
|
6832
|
+
).signedTxMap;
|
|
6833
|
+
|
|
6834
|
+
const txSigs: TransactionSignature[] = [];
|
|
6835
|
+
for (const key in signedTxs) {
|
|
6836
|
+
const tx = signedTxs[key];
|
|
6837
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts, true);
|
|
6838
|
+
txSigs.push(txSig);
|
|
6839
|
+
}
|
|
6840
|
+
|
|
6841
|
+
return txSigs;
|
|
6842
|
+
}
|
|
6843
|
+
|
|
6795
6844
|
public async settleMultiplePNLsIx(
|
|
6796
6845
|
settleeUserAccountPublicKey: PublicKey,
|
|
6797
6846
|
settleeUserAccount: UserAccount,
|