@drift-labs/sdk 2.0.8 → 2.0.10
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/lib/adminClient.d.ts +1 -0
- package/lib/adminClient.js +10 -1
- package/lib/driftClient.d.ts +1 -0
- package/lib/driftClient.js +8 -0
- package/lib/factory/bigNum.js +6 -10
- package/lib/idl/drift.json +25 -0
- package/lib/math/amm.js +1 -1
- package/lib/userMap/userMap.d.ts +1 -0
- package/lib/userMap/userMap.js +3 -0
- package/lib/userMap/userStatsMap.d.ts +1 -0
- package/lib/userMap/userStatsMap.js +3 -0
- package/package.json +1 -1
- package/src/adminClient.ts +17 -1
- package/src/driftClient.ts +16 -0
- package/src/factory/bigNum.ts +5 -11
- package/src/idl/drift.json +25 -0
- package/src/math/amm.ts +1 -1
- package/src/userMap/userMap.ts +4 -0
- package/src/userMap/userStatsMap.ts +4 -0
package/lib/adminClient.d.ts
CHANGED
|
@@ -42,6 +42,7 @@ export declare class AdminClient extends DriftClient {
|
|
|
42
42
|
updateSpotMarketMinOrderSize(spotMarketIndex: number, orderSize: BN): Promise<TransactionSignature>;
|
|
43
43
|
updatePerpMarketExpiry(perpMarketIndex: number, expiryTs: BN): Promise<TransactionSignature>;
|
|
44
44
|
updateSpotMarketOracle(spotMarketIndex: number, oracle: PublicKey, oracleSource: OracleSource): Promise<TransactionSignature>;
|
|
45
|
+
updateSpotMarketOrdersEnabled(spotMarketIndex: number, ordersEnabled: boolean): Promise<TransactionSignature>;
|
|
45
46
|
updateSpotMarketExpiry(spotMarketIndex: number, expiryTs: BN): Promise<TransactionSignature>;
|
|
46
47
|
updateWhitelistMint(whitelistMint?: PublicKey): Promise<TransactionSignature>;
|
|
47
48
|
updateDiscountMint(discountMint: PublicKey): Promise<TransactionSignature>;
|
package/lib/adminClient.js
CHANGED
|
@@ -449,7 +449,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
449
449
|
});
|
|
450
450
|
}
|
|
451
451
|
async updateSpotMarketOracle(spotMarketIndex, oracle, oracleSource) {
|
|
452
|
-
return await this.program.rpc.
|
|
452
|
+
return await this.program.rpc.updateSpotMarketOracle(oracle, oracleSource, {
|
|
453
453
|
accounts: {
|
|
454
454
|
admin: this.wallet.publicKey,
|
|
455
455
|
state: await this.getStatePublicKey(),
|
|
@@ -458,6 +458,15 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
458
458
|
},
|
|
459
459
|
});
|
|
460
460
|
}
|
|
461
|
+
async updateSpotMarketOrdersEnabled(spotMarketIndex, ordersEnabled) {
|
|
462
|
+
return await this.program.rpc.updateSpotMarketOrdersEnabled(ordersEnabled, {
|
|
463
|
+
accounts: {
|
|
464
|
+
admin: this.wallet.publicKey,
|
|
465
|
+
state: await this.getStatePublicKey(),
|
|
466
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
467
|
+
},
|
|
468
|
+
});
|
|
469
|
+
}
|
|
461
470
|
async updateSpotMarketExpiry(spotMarketIndex, expiryTs) {
|
|
462
471
|
return await this.program.rpc.updateSpotMarketExpiry(expiryTs, {
|
|
463
472
|
accounts: {
|
package/lib/driftClient.d.ts
CHANGED
|
@@ -82,6 +82,7 @@ export declare class DriftClient {
|
|
|
82
82
|
getInitializeUserStatsIx(): Promise<TransactionInstruction>;
|
|
83
83
|
updateUserName(name: string, subAccountId?: number): Promise<TransactionSignature>;
|
|
84
84
|
updateUserCustomMarginRatio(marginRatio: number, subAccountId?: number): Promise<TransactionSignature>;
|
|
85
|
+
updateUserMarginTradingEnabled(marginTradingEnabled: boolean, subAccountId?: number): Promise<TransactionSignature>;
|
|
85
86
|
updateUserDelegate(delegate: PublicKey, subAccountId?: number): Promise<TransactionSignature>;
|
|
86
87
|
getUserAccountsForDelegate(delegate: PublicKey): Promise<UserAccount[]>;
|
|
87
88
|
getUserAccountsForAuthority(authority: PublicKey): Promise<UserAccount[]>;
|
package/lib/driftClient.js
CHANGED
|
@@ -333,6 +333,14 @@ class DriftClient {
|
|
|
333
333
|
},
|
|
334
334
|
});
|
|
335
335
|
}
|
|
336
|
+
async updateUserMarginTradingEnabled(marginTradingEnabled, subAccountId = 0) {
|
|
337
|
+
return await this.program.rpc.updateUserMarginTradingEnabled(subAccountId, marginTradingEnabled, {
|
|
338
|
+
accounts: {
|
|
339
|
+
user: await this.getUserAccountPublicKey(),
|
|
340
|
+
authority: this.wallet.publicKey,
|
|
341
|
+
},
|
|
342
|
+
});
|
|
343
|
+
}
|
|
336
344
|
async updateUserDelegate(delegate, subAccountId = 0) {
|
|
337
345
|
return await this.program.rpc.updateUserDelegate(subAccountId, delegate, {
|
|
338
346
|
accounts: {
|
package/lib/factory/bigNum.js
CHANGED
|
@@ -316,19 +316,15 @@ class BigNum {
|
|
|
316
316
|
let val = usingCustomPrecision
|
|
317
317
|
? this.prettyPrint(useTradePrecision, precisionOverride)
|
|
318
318
|
: BigNum.fromPrint(this.toFixed(2), new anchor_1.BN(2)).prettyPrint();
|
|
319
|
-
// Append
|
|
319
|
+
// Append trailing zeroes out to 2 decimal places if not using custom precision
|
|
320
320
|
if (!usingCustomPrecision) {
|
|
321
321
|
const [_, rightSide] = val.split(BigNum.delim);
|
|
322
322
|
const trailingLength = (_a = rightSide === null || rightSide === void 0 ? void 0 : rightSide.length) !== null && _a !== void 0 ? _a : 0;
|
|
323
|
-
if (trailingLength
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
}
|
|
329
|
-
else {
|
|
330
|
-
val = `${val}${new Array(2 - trailingLength).fill('0').join('')}`;
|
|
331
|
-
}
|
|
323
|
+
if (trailingLength === 0) {
|
|
324
|
+
val = `${val}${BigNum.delim}00`;
|
|
325
|
+
}
|
|
326
|
+
else if (trailingLength === 1) {
|
|
327
|
+
val = `${val}0`;
|
|
332
328
|
}
|
|
333
329
|
}
|
|
334
330
|
return `${prefix}${val.replace('-', '')}`;
|
package/lib/idl/drift.json
CHANGED
|
@@ -733,6 +733,31 @@
|
|
|
733
733
|
}
|
|
734
734
|
]
|
|
735
735
|
},
|
|
736
|
+
{
|
|
737
|
+
"name": "updateUserMarginTradingEnabled",
|
|
738
|
+
"accounts": [
|
|
739
|
+
{
|
|
740
|
+
"name": "user",
|
|
741
|
+
"isMut": true,
|
|
742
|
+
"isSigner": false
|
|
743
|
+
},
|
|
744
|
+
{
|
|
745
|
+
"name": "authority",
|
|
746
|
+
"isMut": false,
|
|
747
|
+
"isSigner": true
|
|
748
|
+
}
|
|
749
|
+
],
|
|
750
|
+
"args": [
|
|
751
|
+
{
|
|
752
|
+
"name": "subAccountId",
|
|
753
|
+
"type": "u16"
|
|
754
|
+
},
|
|
755
|
+
{
|
|
756
|
+
"name": "marginTradingEnabled",
|
|
757
|
+
"type": "bool"
|
|
758
|
+
}
|
|
759
|
+
]
|
|
760
|
+
},
|
|
736
761
|
{
|
|
737
762
|
"name": "updateUserDelegate",
|
|
738
763
|
"accounts": [
|
package/lib/math/amm.js
CHANGED
|
@@ -218,7 +218,7 @@ exports.calculateMaxSpread = calculateMaxSpread;
|
|
|
218
218
|
function calculateSpreadBN(baseSpread, lastOracleReservePriceSpreadPct, lastOracleConfPct, maxSpread, quoteAssetReserve, terminalQuoteAssetReserve, pegMultiplier, netBaseAssetAmount, reservePrice, totalFeeMinusDistributions, baseAssetReserve, minBaseAssetReserve, maxBaseAssetReserve) {
|
|
219
219
|
let longSpread = baseSpread / 2;
|
|
220
220
|
let shortSpread = baseSpread / 2;
|
|
221
|
-
if (lastOracleReservePriceSpreadPct.
|
|
221
|
+
if (lastOracleReservePriceSpreadPct.gte(numericConstants_1.ZERO)) {
|
|
222
222
|
shortSpread = Math.max(shortSpread, lastOracleReservePriceSpreadPct.abs().toNumber() +
|
|
223
223
|
lastOracleConfPct.toNumber());
|
|
224
224
|
}
|
package/lib/userMap/userMap.d.ts
CHANGED
package/lib/userMap/userMap.js
CHANGED
package/package.json
CHANGED
package/src/adminClient.ts
CHANGED
|
@@ -852,7 +852,7 @@ export class AdminClient extends DriftClient {
|
|
|
852
852
|
oracle: PublicKey,
|
|
853
853
|
oracleSource: OracleSource
|
|
854
854
|
): Promise<TransactionSignature> {
|
|
855
|
-
return await this.program.rpc.
|
|
855
|
+
return await this.program.rpc.updateSpotMarketOracle(oracle, oracleSource, {
|
|
856
856
|
accounts: {
|
|
857
857
|
admin: this.wallet.publicKey,
|
|
858
858
|
state: await this.getStatePublicKey(),
|
|
@@ -865,6 +865,22 @@ export class AdminClient extends DriftClient {
|
|
|
865
865
|
});
|
|
866
866
|
}
|
|
867
867
|
|
|
868
|
+
public async updateSpotMarketOrdersEnabled(
|
|
869
|
+
spotMarketIndex: number,
|
|
870
|
+
ordersEnabled: boolean
|
|
871
|
+
): Promise<TransactionSignature> {
|
|
872
|
+
return await this.program.rpc.updateSpotMarketOrdersEnabled(ordersEnabled, {
|
|
873
|
+
accounts: {
|
|
874
|
+
admin: this.wallet.publicKey,
|
|
875
|
+
state: await this.getStatePublicKey(),
|
|
876
|
+
spotMarket: await getSpotMarketPublicKey(
|
|
877
|
+
this.program.programId,
|
|
878
|
+
spotMarketIndex
|
|
879
|
+
),
|
|
880
|
+
},
|
|
881
|
+
});
|
|
882
|
+
}
|
|
883
|
+
|
|
868
884
|
public async updateSpotMarketExpiry(
|
|
869
885
|
spotMarketIndex: number,
|
|
870
886
|
expiryTs: BN
|
package/src/driftClient.ts
CHANGED
|
@@ -556,6 +556,22 @@ export class DriftClient {
|
|
|
556
556
|
);
|
|
557
557
|
}
|
|
558
558
|
|
|
559
|
+
public async updateUserMarginTradingEnabled(
|
|
560
|
+
marginTradingEnabled: boolean,
|
|
561
|
+
subAccountId = 0
|
|
562
|
+
): Promise<TransactionSignature> {
|
|
563
|
+
return await this.program.rpc.updateUserMarginTradingEnabled(
|
|
564
|
+
subAccountId,
|
|
565
|
+
marginTradingEnabled,
|
|
566
|
+
{
|
|
567
|
+
accounts: {
|
|
568
|
+
user: await this.getUserAccountPublicKey(),
|
|
569
|
+
authority: this.wallet.publicKey,
|
|
570
|
+
},
|
|
571
|
+
}
|
|
572
|
+
);
|
|
573
|
+
}
|
|
574
|
+
|
|
559
575
|
public async updateUserDelegate(
|
|
560
576
|
delegate: PublicKey,
|
|
561
577
|
subAccountId = 0
|
package/src/factory/bigNum.ts
CHANGED
|
@@ -481,21 +481,15 @@ export class BigNum {
|
|
|
481
481
|
? this.prettyPrint(useTradePrecision, precisionOverride)
|
|
482
482
|
: BigNum.fromPrint(this.toFixed(2), new BN(2)).prettyPrint();
|
|
483
483
|
|
|
484
|
-
// Append
|
|
484
|
+
// Append trailing zeroes out to 2 decimal places if not using custom precision
|
|
485
485
|
if (!usingCustomPrecision) {
|
|
486
486
|
const [_, rightSide] = val.split(BigNum.delim);
|
|
487
|
-
|
|
488
487
|
const trailingLength = rightSide?.length ?? 0;
|
|
489
488
|
|
|
490
|
-
if (trailingLength
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
if (trailingLength === 0 && numHasDecimals) {
|
|
495
|
-
val = `${val}.00`;
|
|
496
|
-
} else {
|
|
497
|
-
val = `${val}${new Array(2 - trailingLength).fill('0').join('')}`;
|
|
498
|
-
}
|
|
489
|
+
if (trailingLength === 0) {
|
|
490
|
+
val = `${val}${BigNum.delim}00`;
|
|
491
|
+
} else if (trailingLength === 1) {
|
|
492
|
+
val = `${val}0`;
|
|
499
493
|
}
|
|
500
494
|
}
|
|
501
495
|
|
package/src/idl/drift.json
CHANGED
|
@@ -733,6 +733,31 @@
|
|
|
733
733
|
}
|
|
734
734
|
]
|
|
735
735
|
},
|
|
736
|
+
{
|
|
737
|
+
"name": "updateUserMarginTradingEnabled",
|
|
738
|
+
"accounts": [
|
|
739
|
+
{
|
|
740
|
+
"name": "user",
|
|
741
|
+
"isMut": true,
|
|
742
|
+
"isSigner": false
|
|
743
|
+
},
|
|
744
|
+
{
|
|
745
|
+
"name": "authority",
|
|
746
|
+
"isMut": false,
|
|
747
|
+
"isSigner": true
|
|
748
|
+
}
|
|
749
|
+
],
|
|
750
|
+
"args": [
|
|
751
|
+
{
|
|
752
|
+
"name": "subAccountId",
|
|
753
|
+
"type": "u16"
|
|
754
|
+
},
|
|
755
|
+
{
|
|
756
|
+
"name": "marginTradingEnabled",
|
|
757
|
+
"type": "bool"
|
|
758
|
+
}
|
|
759
|
+
]
|
|
760
|
+
},
|
|
736
761
|
{
|
|
737
762
|
"name": "updateUserDelegate",
|
|
738
763
|
"accounts": [
|
package/src/math/amm.ts
CHANGED
|
@@ -410,7 +410,7 @@ export function calculateSpreadBN(
|
|
|
410
410
|
let longSpread = baseSpread / 2;
|
|
411
411
|
let shortSpread = baseSpread / 2;
|
|
412
412
|
|
|
413
|
-
if (lastOracleReservePriceSpreadPct.
|
|
413
|
+
if (lastOracleReservePriceSpreadPct.gte(ZERO)) {
|
|
414
414
|
shortSpread = Math.max(
|
|
415
415
|
shortSpread,
|
|
416
416
|
lastOracleReservePriceSpreadPct.abs().toNumber() +
|
package/src/userMap/userMap.ts
CHANGED