@drift-labs/sdk-browser 2.155.0-beta.2 → 2.155.0-beta.4
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/accounts/grpcAccountSubscriber.d.ts +0 -1
- package/lib/browser/accounts/grpcMultiAccountSubscriber.d.ts +0 -1
- package/lib/browser/accounts/grpcProgramAccountSubscriber.d.ts +0 -1
- package/lib/browser/accounts/laserProgramAccountSubscriber.d.ts +0 -1
- package/lib/browser/accounts/webSocketAccountSubscriber.d.ts +0 -1
- package/lib/browser/accounts/webSocketDriftClientAccountSubscriber.d.ts +0 -1
- package/lib/browser/accounts/webSocketProgramAccountSubscriber.d.ts +0 -1
- package/lib/browser/driftClient.d.ts +1 -2
- package/lib/browser/driftClient.js +5 -6
- package/lib/browser/oracles/pythPullClient.d.ts +2 -2
- package/lib/browser/oracles/pythPullClient.js +5 -2
- package/lib/browser/pyth/constants.d.ts +3 -0
- package/lib/browser/pyth/constants.js +6 -0
- package/lib/browser/pyth/index.d.ts +3 -0
- package/lib/browser/pyth/index.js +10 -0
- package/lib/browser/pyth/types.d.ts +2226 -0
- package/lib/browser/pyth/types.js +2224 -0
- package/lib/browser/pyth/utils.d.ts +2 -0
- package/lib/browser/pyth/utils.js +10 -0
- package/lib/browser/swap/UnifiedSwapClient.js +1 -10
- package/lib/browser/titan/titanClient.d.ts +4 -5
- package/lib/browser/titan/titanClient.js +2 -16
- package/lib/node/accounts/grpcAccountSubscriber.d.ts +0 -1
- package/lib/node/accounts/grpcAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts +0 -1
- package/lib/node/accounts/grpcMultiAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/grpcProgramAccountSubscriber.d.ts +0 -1
- package/lib/node/accounts/grpcProgramAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/laserProgramAccountSubscriber.d.ts +0 -1
- package/lib/node/accounts/laserProgramAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketAccountSubscriber.d.ts +0 -1
- package/lib/node/accounts/webSocketAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketDriftClientAccountSubscriber.d.ts +0 -1
- package/lib/node/accounts/webSocketDriftClientAccountSubscriber.d.ts.map +1 -1
- package/lib/node/accounts/webSocketProgramAccountSubscriber.d.ts +0 -1
- package/lib/node/accounts/webSocketProgramAccountSubscriber.d.ts.map +1 -1
- package/lib/node/driftClient.d.ts +1 -2
- package/lib/node/driftClient.d.ts.map +1 -1
- package/lib/node/driftClient.js +5 -6
- package/lib/node/oracles/pythPullClient.d.ts +2 -2
- package/lib/node/oracles/pythPullClient.d.ts.map +1 -1
- package/lib/node/oracles/pythPullClient.js +5 -2
- package/lib/node/pyth/constants.d.ts +4 -0
- package/lib/node/pyth/constants.d.ts.map +1 -0
- package/lib/node/pyth/constants.js +6 -0
- package/lib/node/pyth/index.d.ts +4 -0
- package/lib/node/pyth/index.d.ts.map +1 -0
- package/lib/node/pyth/index.js +10 -0
- package/lib/node/pyth/types.d.ts +2227 -0
- package/lib/node/pyth/types.d.ts.map +1 -0
- package/lib/node/pyth/types.js +2224 -0
- package/lib/node/pyth/utils.d.ts +3 -0
- package/lib/node/pyth/utils.d.ts.map +1 -0
- package/lib/node/pyth/utils.js +10 -0
- package/lib/node/swap/UnifiedSwapClient.d.ts.map +1 -1
- package/lib/node/swap/UnifiedSwapClient.js +1 -10
- package/lib/node/titan/titanClient.d.ts +4 -5
- package/lib/node/titan/titanClient.d.ts.map +1 -1
- package/lib/node/titan/titanClient.js +2 -16
- package/package.json +3 -4
- package/src/driftClient.ts +9 -11
- package/src/oracles/pythPullClient.ts +4 -5
- package/src/pyth/constants.ts +9 -0
- package/src/pyth/index.ts +11 -0
- package/src/pyth/types.ts +4453 -0
- package/src/pyth/utils.ts +13 -0
- package/src/swap/UnifiedSwapClient.ts +2 -13
- package/src/titan/titanClient.ts +4 -28
- package/tests/decode/test.ts +2 -1
- package/tests/dlob/helpers.ts +0 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
|
|
3
|
+
export const getGuardianSetPda = (
|
|
4
|
+
guardianSetIndex: number,
|
|
5
|
+
wormholeProgramId: PublicKey
|
|
6
|
+
) => {
|
|
7
|
+
const guardianSetIndexBuf = Buffer.alloc(4);
|
|
8
|
+
guardianSetIndexBuf.writeUInt32BE(guardianSetIndex, 0);
|
|
9
|
+
return PublicKey.findProgramAddressSync(
|
|
10
|
+
[Buffer.from('GuardianSet'), guardianSetIndexBuf],
|
|
11
|
+
wormholeProgramId
|
|
12
|
+
)[0];
|
|
13
|
+
};
|
|
@@ -11,11 +11,7 @@ import {
|
|
|
11
11
|
JupiterClient,
|
|
12
12
|
QuoteResponse as JupiterQuoteResponse,
|
|
13
13
|
} from '../jupiter/jupiterClient';
|
|
14
|
-
import {
|
|
15
|
-
TitanClient,
|
|
16
|
-
QuoteResponse as TitanQuoteResponse,
|
|
17
|
-
SwapMode as TitanSwapMode,
|
|
18
|
-
} from '../titan/titanClient';
|
|
14
|
+
import { TitanClient, SwapMode as TitanSwapMode } from '../titan/titanClient';
|
|
19
15
|
|
|
20
16
|
export type SwapMode = 'ExactIn' | 'ExactOut';
|
|
21
17
|
export type SwapClientType = 'jupiter' | 'titan';
|
|
@@ -167,18 +163,11 @@ export class UnifiedSwapClient {
|
|
|
167
163
|
return { transaction };
|
|
168
164
|
} else {
|
|
169
165
|
const titanClient = this.client as TitanClient;
|
|
170
|
-
const {
|
|
166
|
+
const { userPublicKey } = params;
|
|
171
167
|
|
|
172
168
|
// For Titan, we need to reconstruct the parameters from the quote
|
|
173
|
-
const titanQuote = quote as TitanQuoteResponse;
|
|
174
169
|
const result = await titanClient.getSwap({
|
|
175
|
-
inputMint: new PublicKey(titanQuote.inputMint),
|
|
176
|
-
outputMint: new PublicKey(titanQuote.outputMint),
|
|
177
|
-
amount: new BN(titanQuote.inAmount),
|
|
178
170
|
userPublicKey,
|
|
179
|
-
slippageBps: slippageBps || titanQuote.slippageBps,
|
|
180
|
-
swapMode: titanQuote.swapMode,
|
|
181
|
-
sizeConstraint: 1280 - 375, // MAX_TX_BYTE_SIZE - buffer for drift instructions
|
|
182
171
|
});
|
|
183
172
|
|
|
184
173
|
return {
|
package/src/titan/titanClient.ts
CHANGED
|
@@ -287,21 +287,11 @@ export class TitanClient {
|
|
|
287
287
|
* Get a swap transaction for quote
|
|
288
288
|
*/
|
|
289
289
|
public async getSwap({
|
|
290
|
-
inputMint,
|
|
291
|
-
outputMint,
|
|
292
|
-
amount,
|
|
293
290
|
userPublicKey,
|
|
294
|
-
maxAccounts = 50, // 50 is an estimated amount with buffer
|
|
295
|
-
slippageBps,
|
|
296
|
-
swapMode,
|
|
297
|
-
onlyDirectRoutes,
|
|
298
|
-
excludeDexes,
|
|
299
|
-
sizeConstraint,
|
|
300
|
-
accountsLimitWritable,
|
|
301
291
|
}: {
|
|
302
|
-
inputMint
|
|
303
|
-
outputMint
|
|
304
|
-
amount
|
|
292
|
+
inputMint?: PublicKey;
|
|
293
|
+
outputMint?: PublicKey;
|
|
294
|
+
amount?: BN;
|
|
305
295
|
userPublicKey: PublicKey;
|
|
306
296
|
maxAccounts?: number;
|
|
307
297
|
slippageBps?: number;
|
|
@@ -314,22 +304,8 @@ export class TitanClient {
|
|
|
314
304
|
transactionMessage: TransactionMessage;
|
|
315
305
|
lookupTables: AddressLookupTableAccount[];
|
|
316
306
|
}> {
|
|
317
|
-
const params = this.buildParams({
|
|
318
|
-
inputMint,
|
|
319
|
-
outputMint,
|
|
320
|
-
amount,
|
|
321
|
-
userPublicKey,
|
|
322
|
-
maxAccounts,
|
|
323
|
-
slippageBps,
|
|
324
|
-
swapMode,
|
|
325
|
-
onlyDirectRoutes,
|
|
326
|
-
excludeDexes,
|
|
327
|
-
sizeConstraint,
|
|
328
|
-
accountsLimitWritable,
|
|
329
|
-
});
|
|
330
|
-
|
|
331
307
|
// Check if we have cached quote data that matches the current parameters
|
|
332
|
-
if (!this.lastQuoteData
|
|
308
|
+
if (!this.lastQuoteData) {
|
|
333
309
|
throw new Error(
|
|
334
310
|
'No matching quote data found. Please get a fresh quote before attempting to swap.'
|
|
335
311
|
);
|
package/tests/decode/test.ts
CHANGED
|
@@ -187,10 +187,11 @@ function testPerpPosition(anchor: PerpPosition, custom: PerpPosition) {
|
|
|
187
187
|
assert(anchor.openAsks.eq(custom.openAsks));
|
|
188
188
|
assert(anchor.settledPnl.eq(custom.settledPnl));
|
|
189
189
|
assert(anchor.lpShares.eq(custom.lpShares));
|
|
190
|
-
assert(anchor.lastBaseAssetAmountPerLp.eq(custom.lastBaseAssetAmountPerLp));
|
|
191
190
|
assert(anchor.lastQuoteAssetAmountPerLp.eq(custom.lastQuoteAssetAmountPerLp));
|
|
192
191
|
assert(anchor.openOrders === custom.openOrders);
|
|
193
192
|
assert(anchor.perLpBase === custom.perLpBase);
|
|
193
|
+
assert(anchor.isolatedPositionScaledBalance.eq(custom.isolatedPositionScaledBalance));
|
|
194
|
+
assert(anchor.positionFlag === custom.positionFlag);
|
|
194
195
|
}
|
|
195
196
|
|
|
196
197
|
function* getOrders(orders: Order[]) {
|
package/tests/dlob/helpers.ts
CHANGED