@drift-labs/sdk 2.74.0-beta.4 → 2.74.0-beta.6
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/dlob/orderBookLevels.js +6 -0
- package/lib/driftClient.d.ts +5 -0
- package/lib/driftClient.js +17 -0
- package/package.json +1 -1
- package/src/dlob/orderBookLevels.ts +6 -0
- package/src/driftClient.ts +37 -0
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.74.0-beta.
|
|
1
|
+
2.74.0-beta.6
|
|
@@ -122,6 +122,9 @@ function getVammL2Generator({ marketAccount, oraclePriceData, numOrders, now, to
|
|
|
122
122
|
[afterSwapQuoteReserves, afterSwapBaseReserves] =
|
|
123
123
|
(0, __1.calculateAmmReservesAfterSwap)(bidAmm, 'quote', quoteSwapped, __1.SwapDirection.REMOVE);
|
|
124
124
|
baseSwapped = bidAmm.baseAssetReserve.sub(afterSwapBaseReserves).abs();
|
|
125
|
+
if (baseSwapped.eq(__1.ZERO)) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
125
128
|
if (remainingBaseLiquidity.lt(baseSwapped)) {
|
|
126
129
|
baseSwapped = remainingBaseLiquidity;
|
|
127
130
|
[afterSwapQuoteReserves, afterSwapBaseReserves] =
|
|
@@ -170,6 +173,9 @@ function getVammL2Generator({ marketAccount, oraclePriceData, numOrders, now, to
|
|
|
170
173
|
[afterSwapQuoteReserves, afterSwapBaseReserves] =
|
|
171
174
|
(0, __1.calculateAmmReservesAfterSwap)(askAmm, 'quote', quoteSwapped, __1.SwapDirection.ADD);
|
|
172
175
|
baseSwapped = askAmm.baseAssetReserve.sub(afterSwapBaseReserves).abs();
|
|
176
|
+
if (baseSwapped.eq(__1.ZERO)) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
173
179
|
if (remainingBaseLiquidity.lt(baseSwapped)) {
|
|
174
180
|
baseSwapped = remainingBaseLiquidity;
|
|
175
181
|
[afterSwapQuoteReserves, afterSwapBaseReserves] =
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -134,6 +134,11 @@ export declare class DriftClient {
|
|
|
134
134
|
subAccountId: number;
|
|
135
135
|
}[]): Promise<TransactionSignature>;
|
|
136
136
|
getUpdateAdvancedDlpIx(advancedLp: boolean, subAccountId: number): Promise<anchor.web3.TransactionInstruction>;
|
|
137
|
+
updateUserReduceOnly(updates: {
|
|
138
|
+
reduceOnly: boolean;
|
|
139
|
+
subAccountId: number;
|
|
140
|
+
}[]): Promise<TransactionSignature>;
|
|
141
|
+
getUpdateUserReduceOnlyIx(reduceOnly: boolean, subAccountId: number): Promise<anchor.web3.TransactionInstruction>;
|
|
137
142
|
fetchAllUserAccounts(includeIdle?: boolean): Promise<ProgramAccount<UserAccount>[]>;
|
|
138
143
|
getUserAccountsForDelegate(delegate: PublicKey): Promise<UserAccount[]>;
|
|
139
144
|
getUserAccountsAndAddressesForAuthority(authority: PublicKey): Promise<ProgramAccount<UserAccount>[]>;
|
package/lib/driftClient.js
CHANGED
|
@@ -627,6 +627,23 @@ class DriftClient {
|
|
|
627
627
|
});
|
|
628
628
|
return ix;
|
|
629
629
|
}
|
|
630
|
+
async updateUserReduceOnly(updates) {
|
|
631
|
+
const ixs = await Promise.all(updates.map(async ({ reduceOnly, subAccountId }) => {
|
|
632
|
+
return await this.getUpdateUserReduceOnlyIx(reduceOnly, subAccountId);
|
|
633
|
+
}));
|
|
634
|
+
const tx = await this.buildTransaction(ixs, this.txParams);
|
|
635
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
636
|
+
return txSig;
|
|
637
|
+
}
|
|
638
|
+
async getUpdateUserReduceOnlyIx(reduceOnly, subAccountId) {
|
|
639
|
+
const ix = await this.program.instruction.updateUserReduceOnly(subAccountId, reduceOnly, {
|
|
640
|
+
accounts: {
|
|
641
|
+
user: (0, pda_1.getUserAccountPublicKeySync)(this.program.programId, this.wallet.publicKey, subAccountId),
|
|
642
|
+
authority: this.wallet.publicKey,
|
|
643
|
+
},
|
|
644
|
+
});
|
|
645
|
+
return ix;
|
|
646
|
+
}
|
|
630
647
|
async fetchAllUserAccounts(includeIdle = true) {
|
|
631
648
|
let filters = undefined;
|
|
632
649
|
if (!includeIdle) {
|
package/package.json
CHANGED
|
@@ -219,6 +219,9 @@ export function getVammL2Generator({
|
|
|
219
219
|
);
|
|
220
220
|
|
|
221
221
|
baseSwapped = bidAmm.baseAssetReserve.sub(afterSwapBaseReserves).abs();
|
|
222
|
+
if (baseSwapped.eq(ZERO)) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
222
225
|
if (remainingBaseLiquidity.lt(baseSwapped)) {
|
|
223
226
|
baseSwapped = remainingBaseLiquidity;
|
|
224
227
|
[afterSwapQuoteReserves, afterSwapBaseReserves] =
|
|
@@ -299,6 +302,9 @@ export function getVammL2Generator({
|
|
|
299
302
|
);
|
|
300
303
|
|
|
301
304
|
baseSwapped = askAmm.baseAssetReserve.sub(afterSwapBaseReserves).abs();
|
|
305
|
+
if (baseSwapped.eq(ZERO)) {
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
302
308
|
if (remainingBaseLiquidity.lt(baseSwapped)) {
|
|
303
309
|
baseSwapped = remainingBaseLiquidity;
|
|
304
310
|
[afterSwapQuoteReserves, afterSwapBaseReserves] =
|
package/src/driftClient.ts
CHANGED
|
@@ -1074,6 +1074,43 @@ export class DriftClient {
|
|
|
1074
1074
|
return ix;
|
|
1075
1075
|
}
|
|
1076
1076
|
|
|
1077
|
+
public async updateUserReduceOnly(
|
|
1078
|
+
updates: { reduceOnly: boolean; subAccountId: number }[]
|
|
1079
|
+
): Promise<TransactionSignature> {
|
|
1080
|
+
const ixs = await Promise.all(
|
|
1081
|
+
updates.map(async ({ reduceOnly, subAccountId }) => {
|
|
1082
|
+
return await this.getUpdateUserReduceOnlyIx(reduceOnly, subAccountId);
|
|
1083
|
+
})
|
|
1084
|
+
);
|
|
1085
|
+
|
|
1086
|
+
const tx = await this.buildTransaction(ixs, this.txParams);
|
|
1087
|
+
|
|
1088
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
1089
|
+
return txSig;
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
public async getUpdateUserReduceOnlyIx(
|
|
1093
|
+
reduceOnly: boolean,
|
|
1094
|
+
subAccountId: number
|
|
1095
|
+
) {
|
|
1096
|
+
const ix = await this.program.instruction.updateUserReduceOnly(
|
|
1097
|
+
subAccountId,
|
|
1098
|
+
reduceOnly,
|
|
1099
|
+
{
|
|
1100
|
+
accounts: {
|
|
1101
|
+
user: getUserAccountPublicKeySync(
|
|
1102
|
+
this.program.programId,
|
|
1103
|
+
this.wallet.publicKey,
|
|
1104
|
+
subAccountId
|
|
1105
|
+
),
|
|
1106
|
+
authority: this.wallet.publicKey,
|
|
1107
|
+
},
|
|
1108
|
+
}
|
|
1109
|
+
);
|
|
1110
|
+
|
|
1111
|
+
return ix;
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1077
1114
|
public async fetchAllUserAccounts(
|
|
1078
1115
|
includeIdle = true
|
|
1079
1116
|
): Promise<ProgramAccount<UserAccount>[]> {
|