@drift-labs/sdk 2.23.0 → 2.25.0-beta.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/README.md +1 -1
- package/lib/accounts/fetch.d.ts +1 -1
- package/lib/accounts/pollingDriftClientAccountSubscriber.d.ts +1 -1
- package/lib/accounts/pollingOracleAccountSubscriber.d.ts +1 -1
- package/lib/accounts/pollingTokenAccountSubscriber.d.ts +1 -1
- package/lib/accounts/pollingUserAccountSubscriber.d.ts +1 -1
- package/lib/accounts/pollingUserStatsAccountSubscriber.d.ts +1 -1
- package/lib/accounts/webSocketAccountSubscriber.d.ts +1 -1
- package/lib/accounts/webSocketDriftClientAccountSubscriber.d.ts +1 -1
- package/lib/accounts/webSocketUserAccountSubscriber.d.ts +1 -1
- package/lib/accounts/webSocketUserStatsAccountSubsriber.d.ts +1 -1
- package/lib/addresses/pda.d.ts +1 -2
- package/lib/addresses/pda.js +1 -1
- package/lib/adminClient.d.ts +3 -3
- package/lib/adminClient.js +16 -4
- package/lib/constants/numericConstants.d.ts +59 -61
- package/lib/constants/perpMarkets.js +21 -1
- package/lib/constants/spotMarkets.d.ts +0 -1
- package/lib/dlob/DLOB.d.ts +0 -1
- package/lib/dlob/DLOBNode.d.ts +0 -1
- package/lib/dlob/DLOBOrders.d.ts +1 -1
- package/lib/dlob/DLOBOrders.js +1 -1
- package/lib/dlob/NodeList.d.ts +0 -1
- package/lib/driftClient.d.ts +58 -24
- package/lib/driftClient.js +152 -136
- package/lib/events/eventSubscriber.d.ts +1 -1
- package/lib/events/eventSubscriber.js +3 -2
- package/lib/events/fetchLogs.d.ts +1 -1
- package/lib/events/fetchLogs.js +3 -2
- package/lib/examples/loadDlob.js +1 -1
- package/lib/examples/makeTradeExample.js +1 -1
- package/lib/factory/bigNum.d.ts +8 -9
- package/lib/factory/bigNum.js +1 -1
- package/lib/factory/oracleClient.js +1 -1
- package/lib/idl/drift.json +216 -14
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/math/amm.d.ts +2 -3
- package/lib/math/amm.js +1 -1
- package/lib/math/auction.d.ts +0 -1
- package/lib/math/conversion.d.ts +1 -2
- package/lib/math/funding.d.ts +1 -2
- package/lib/math/funding.js +1 -1
- package/lib/math/insurance.d.ts +1 -1
- package/lib/math/insurance.js +17 -1
- package/lib/math/margin.d.ts +1 -2
- package/lib/math/margin.js +1 -1
- package/lib/math/market.d.ts +1 -2
- package/lib/math/market.js +1 -1
- package/lib/math/oracles.d.ts +0 -1
- package/lib/math/oracles.js +2 -3
- package/lib/math/orders.d.ts +1 -2
- package/lib/math/orders.js +1 -1
- package/lib/math/position.d.ts +0 -1
- package/lib/math/repeg.d.ts +1 -2
- package/lib/math/repeg.js +1 -1
- package/lib/math/spotBalance.d.ts +1 -2
- package/lib/math/spotBalance.js +1 -1
- package/lib/math/spotMarket.d.ts +1 -2
- package/lib/math/spotMarket.js +1 -1
- package/lib/math/spotPosition.d.ts +1 -2
- package/lib/math/trade.d.ts +1 -2
- package/lib/math/trade.js +1 -1
- package/lib/math/utils.d.ts +0 -1
- package/lib/oracles/pythClient.d.ts +2 -3
- package/lib/oracles/pythClient.js +1 -1
- package/lib/oracles/quoteAssetOracleClient.js +1 -1
- package/lib/oracles/types.d.ts +1 -2
- package/lib/orderParams.d.ts +1 -2
- package/lib/serum/serumSubscriber.d.ts +1 -2
- package/lib/serum/serumSubscriber.js +1 -1
- package/lib/tokenFaucet.d.ts +2 -3
- package/lib/tokenFaucet.js +2 -2
- package/lib/tx/retryTxSender.d.ts +1 -1
- package/lib/tx/types.d.ts +1 -1
- package/lib/types.d.ts +9 -3
- package/lib/types.js +2 -1
- package/lib/user.d.ts +0 -1
- package/package.json +2 -2
- package/src/accounts/fetch.ts +1 -1
- package/src/accounts/pollingDriftClientAccountSubscriber.ts +1 -1
- package/src/accounts/pollingOracleAccountSubscriber.ts +1 -1
- package/src/accounts/pollingTokenAccountSubscriber.ts +1 -1
- package/src/accounts/pollingUserAccountSubscriber.ts +1 -1
- package/src/accounts/pollingUserStatsAccountSubscriber.ts +1 -1
- package/src/accounts/webSocketAccountSubscriber.ts +1 -1
- package/src/accounts/webSocketDriftClientAccountSubscriber.ts +1 -1
- package/src/accounts/webSocketUserAccountSubscriber.ts +1 -1
- package/src/accounts/webSocketUserStatsAccountSubsriber.ts +1 -1
- package/src/addresses/pda.ts +2 -2
- package/src/adminClient.ts +30 -2
- package/src/constants/perpMarkets.ts +21 -1
- package/src/dlob/DLOBOrders.ts +2 -2
- package/src/driftClient.ts +266 -163
- package/src/events/eventSubscriber.ts +7 -3
- package/src/events/fetchLogs.ts +7 -3
- package/src/examples/loadDlob.ts +1 -1
- package/src/examples/makeTradeExample.ts +1 -1
- package/src/factory/bigNum.ts +1 -1
- package/src/factory/oracleClient.ts +1 -1
- package/src/idl/drift.json +216 -14
- package/src/index.ts +1 -1
- package/src/math/amm.ts +1 -1
- package/src/math/funding.ts +1 -1
- package/src/math/insurance.ts +29 -0
- package/src/math/margin.ts +1 -1
- package/src/math/market.ts +1 -1
- package/src/math/oracles.ts +2 -3
- package/src/math/orders.ts +1 -1
- package/src/math/repeg.ts +1 -1
- package/src/math/spotBalance.ts +1 -1
- package/src/math/spotMarket.ts +1 -1
- package/src/math/spotPosition.ts +1 -1
- package/src/math/trade.ts +1 -1
- package/src/oracles/pythClient.ts +1 -1
- package/src/oracles/quoteAssetOracleClient.ts +1 -1
- package/src/oracles/types.ts +1 -1
- package/src/orderParams.ts +1 -1
- package/src/serum/serumSubscriber.ts +1 -1
- package/src/tokenFaucet.ts +2 -2
- package/src/tx/retryTxSender.ts +1 -1
- package/src/tx/types.ts +1 -1
- package/src/types.ts +8 -1
- package/src/userMap/userStatsMap.ts +1 -1
package/README.md
CHANGED
|
@@ -76,7 +76,7 @@ convertToNumber(new BN(10500), new BN(1000)); // = 10.5
|
|
|
76
76
|
### Setting up an account and making a trade
|
|
77
77
|
|
|
78
78
|
```typescript
|
|
79
|
-
import { AnchorProvider, BN } from '@
|
|
79
|
+
import { AnchorProvider, BN } from '@coral-xyz/anchor';
|
|
80
80
|
import { Token, TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
81
81
|
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
|
|
82
82
|
import {
|
package/lib/accounts/fetch.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Connection, PublicKey } from '@solana/web3.js';
|
|
2
2
|
import { UserAccount, UserStatsAccount } from '../types';
|
|
3
|
-
import { Program } from '@
|
|
3
|
+
import { Program } from '@coral-xyz/anchor';
|
|
4
4
|
export declare function fetchUserAccounts(connection: Connection, program: Program, authority: PublicKey, limit?: number): Promise<(UserAccount | undefined)[]>;
|
|
5
5
|
export declare function fetchUserAccountsUsingKeys(connection: Connection, program: Program, userAccountPublicKeys: PublicKey[]): Promise<(UserAccount | undefined)[]>;
|
|
6
6
|
export declare function fetchUserStatsAccount(connection: Connection, program: Program, authority: PublicKey): Promise<UserStatsAccount | undefined>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { DataAndSlot, AccountToPoll, DriftClientAccountEvents, DriftClientAccountSubscriber, OraclesToPoll } from './types';
|
|
3
|
-
import { Program } from '@
|
|
3
|
+
import { Program } from '@coral-xyz/anchor';
|
|
4
4
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
5
5
|
import { EventEmitter } from 'events';
|
|
6
6
|
import { SpotMarketAccount, PerpMarketAccount, StateAccount, UserAccount } from '../types';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { DataAndSlot, OracleEvents, OracleAccountSubscriber } from './types';
|
|
3
|
-
import { Program } from '@
|
|
3
|
+
import { Program } from '@coral-xyz/anchor';
|
|
4
4
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
5
5
|
import { EventEmitter } from 'events';
|
|
6
6
|
import { PublicKey } from '@solana/web3.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { DataAndSlot, TokenAccountEvents, TokenAccountSubscriber } from './types';
|
|
3
|
-
import { Program } from '@
|
|
3
|
+
import { Program } from '@coral-xyz/anchor';
|
|
4
4
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
5
5
|
import { EventEmitter } from 'events';
|
|
6
6
|
import { PublicKey } from '@solana/web3.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { DataAndSlot, AccountToPoll, UserAccountEvents, UserAccountSubscriber } from './types';
|
|
3
|
-
import { Program } from '@
|
|
3
|
+
import { Program } from '@coral-xyz/anchor';
|
|
4
4
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
5
5
|
import { EventEmitter } from 'events';
|
|
6
6
|
import { PublicKey } from '@solana/web3.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { DataAndSlot, AccountToPoll, UserStatsAccountSubscriber, UserStatsAccountEvents } from './types';
|
|
3
|
-
import { Program } from '@
|
|
3
|
+
import { Program } from '@coral-xyz/anchor';
|
|
4
4
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
5
5
|
import { EventEmitter } from 'events';
|
|
6
6
|
import { PublicKey } from '@solana/web3.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { DataAndSlot, BufferAndSlot, AccountSubscriber } from './types';
|
|
3
|
-
import { Program } from '@
|
|
3
|
+
import { Program } from '@coral-xyz/anchor';
|
|
4
4
|
import { AccountInfo, Context, PublicKey } from '@solana/web3.js';
|
|
5
5
|
export declare class WebSocketAccountSubscriber<T> implements AccountSubscriber<T> {
|
|
6
6
|
dataAndSlot?: DataAndSlot<T>;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { DriftClientAccountSubscriber, DriftClientAccountEvents, DataAndSlot } from './types';
|
|
3
3
|
import { AccountSubscriber } from './types';
|
|
4
4
|
import { SpotMarketAccount, PerpMarketAccount, StateAccount } from '../types';
|
|
5
|
-
import { Program } from '@
|
|
5
|
+
import { Program } from '@coral-xyz/anchor';
|
|
6
6
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
7
7
|
import { EventEmitter } from 'events';
|
|
8
8
|
import { PublicKey } from '@solana/web3.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { DataAndSlot, AccountSubscriber, UserAccountEvents, UserAccountSubscriber } from './types';
|
|
3
|
-
import { Program } from '@
|
|
3
|
+
import { Program } from '@coral-xyz/anchor';
|
|
4
4
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
5
5
|
import { EventEmitter } from 'events';
|
|
6
6
|
import { PublicKey } from '@solana/web3.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { DataAndSlot, AccountSubscriber, UserStatsAccountSubscriber, UserStatsAccountEvents } from './types';
|
|
3
|
-
import { Program } from '@
|
|
3
|
+
import { Program } from '@coral-xyz/anchor';
|
|
4
4
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
5
5
|
import { EventEmitter } from 'events';
|
|
6
6
|
import { PublicKey } from '@solana/web3.js';
|
package/lib/addresses/pda.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
import { PublicKey } from '@solana/web3.js';
|
|
3
|
-
import { BN } from '@
|
|
2
|
+
import { BN } from '@coral-xyz/anchor';
|
|
4
3
|
export declare function getDriftStateAccountPublicKeyAndNonce(programId: PublicKey): Promise<[PublicKey, number]>;
|
|
5
4
|
export declare function getDriftStateAccountPublicKey(programId: PublicKey): Promise<PublicKey>;
|
|
6
5
|
export declare function getUserAccountPublicKeyAndNonce(programId: PublicKey, authority: PublicKey, subAccountId?: number): Promise<[PublicKey, number]>;
|
package/lib/addresses/pda.js
CHANGED
|
@@ -25,7 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.getReferrerNamePublicKeySync = exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getDriftSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKey = exports.getPerpMarketPublicKey = exports.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getDriftStateAccountPublicKey = exports.getDriftStateAccountPublicKeyAndNonce = void 0;
|
|
27
27
|
const web3_js_1 = require("@solana/web3.js");
|
|
28
|
-
const anchor = __importStar(require("@
|
|
28
|
+
const anchor = __importStar(require("@coral-xyz/anchor"));
|
|
29
29
|
async function getDriftStateAccountPublicKeyAndNonce(programId) {
|
|
30
30
|
return web3_js_1.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('drift_state'))], programId);
|
|
31
31
|
}
|
package/lib/adminClient.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
import { PublicKey, TransactionSignature } from '@solana/web3.js';
|
|
3
2
|
import { FeeStructure, OracleGuardRails, OracleSource, ExchangeStatus, MarketStatus, ContractTier, AssetTier, SpotFulfillmentConfigStatus } from './types';
|
|
4
|
-
import { BN } from '@
|
|
3
|
+
import { BN } from '@coral-xyz/anchor';
|
|
5
4
|
import { DriftClient } from './driftClient';
|
|
6
5
|
export declare class AdminClient extends DriftClient {
|
|
7
6
|
initialize(usdcMint: PublicKey, _adminControlsPrices: boolean): Promise<[TransactionSignature]>;
|
|
8
7
|
initializeSpotMarket(mint: PublicKey, optimalUtilization: number, optimalRate: number, maxRate: number, oracle: PublicKey, oracleSource: OracleSource, initialAssetWeight: number, maintenanceAssetWeight: number, initialLiabilityWeight: number, maintenanceLiabilityWeight: number, imfFactor?: number, liquidatorFee?: number, activeStatus?: boolean, name?: string): Promise<TransactionSignature>;
|
|
9
8
|
initializeSerumFulfillmentConfig(marketIndex: number, serumMarket: PublicKey, serumProgram: PublicKey): Promise<TransactionSignature>;
|
|
10
|
-
initializePerpMarket(priceOracle: PublicKey, baseAssetReserve: BN, quoteAssetReserve: BN, periodicity: BN, pegMultiplier?: BN, oracleSource?: OracleSource, marginRatioInitial?: number, marginRatioMaintenance?: number, liquidatorFee?: number, activeStatus?: boolean, name?: string): Promise<TransactionSignature>;
|
|
9
|
+
initializePerpMarket(marketIndex: number, priceOracle: PublicKey, baseAssetReserve: BN, quoteAssetReserve: BN, periodicity: BN, pegMultiplier?: BN, oracleSource?: OracleSource, marginRatioInitial?: number, marginRatioMaintenance?: number, liquidatorFee?: number, activeStatus?: boolean, name?: string): Promise<TransactionSignature>;
|
|
10
|
+
deleteInitializedPerpMarket(marketIndex: number): Promise<TransactionSignature>;
|
|
11
11
|
moveAmmPrice(perpMarketIndex: number, baseAssetReserve: BN, quoteAssetReserve: BN, sqrtK?: BN): Promise<TransactionSignature>;
|
|
12
12
|
updateK(perpMarketIndex: number, sqrtK: BN): Promise<TransactionSignature>;
|
|
13
13
|
updatePerpMarketConcentrationScale(perpMarketIndex: number, concentrationScale: BN): Promise<TransactionSignature>;
|
package/lib/adminClient.js
CHANGED
|
@@ -27,8 +27,8 @@ exports.AdminClient = void 0;
|
|
|
27
27
|
const web3_js_1 = require("@solana/web3.js");
|
|
28
28
|
const types_1 = require("./types");
|
|
29
29
|
const userName_1 = require("./userName");
|
|
30
|
-
const anchor_1 = require("@
|
|
31
|
-
const anchor = __importStar(require("@
|
|
30
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
|
31
|
+
const anchor = __importStar(require("@coral-xyz/anchor"));
|
|
32
32
|
const pda_1 = require("./addresses/pda");
|
|
33
33
|
const utils_1 = require("./math/utils");
|
|
34
34
|
const spl_token_1 = require("@solana/spl-token");
|
|
@@ -107,11 +107,11 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
107
107
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
108
108
|
return txSig;
|
|
109
109
|
}
|
|
110
|
-
async initializePerpMarket(priceOracle, baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier = numericConstants_1.PEG_PRECISION, oracleSource = types_1.OracleSource.PYTH, marginRatioInitial = 2000, marginRatioMaintenance = 500, liquidatorFee = 0, activeStatus = true, name = userName_1.DEFAULT_MARKET_NAME) {
|
|
110
|
+
async initializePerpMarket(marketIndex, priceOracle, baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier = numericConstants_1.PEG_PRECISION, oracleSource = types_1.OracleSource.PYTH, marginRatioInitial = 2000, marginRatioMaintenance = 500, liquidatorFee = 0, activeStatus = true, name = userName_1.DEFAULT_MARKET_NAME) {
|
|
111
111
|
const currentPerpMarketIndex = this.getStateAccount().numberOfMarkets;
|
|
112
112
|
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, currentPerpMarketIndex);
|
|
113
113
|
const nameBuffer = (0, userName_1.encodeName)(name);
|
|
114
|
-
const initializeMarketTx = await this.program.transaction.initializePerpMarket(baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier, oracleSource, marginRatioInitial, marginRatioMaintenance, liquidatorFee, activeStatus, nameBuffer, {
|
|
114
|
+
const initializeMarketTx = await this.program.transaction.initializePerpMarket(marketIndex, baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier, oracleSource, marginRatioInitial, marginRatioMaintenance, liquidatorFee, activeStatus, nameBuffer, {
|
|
115
115
|
accounts: {
|
|
116
116
|
state: await this.getStatePublicKey(),
|
|
117
117
|
admin: this.wallet.publicKey,
|
|
@@ -132,6 +132,18 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
132
132
|
});
|
|
133
133
|
return txSig;
|
|
134
134
|
}
|
|
135
|
+
async deleteInitializedPerpMarket(marketIndex) {
|
|
136
|
+
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, marketIndex);
|
|
137
|
+
const deleteInitializeMarketTx = await this.program.transaction.deleteInitializedPerpMarket(marketIndex, {
|
|
138
|
+
accounts: {
|
|
139
|
+
state: await this.getStatePublicKey(),
|
|
140
|
+
admin: this.wallet.publicKey,
|
|
141
|
+
perpMarket: perpMarketPublicKey,
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
const { txSig } = await this.sendTransaction(deleteInitializeMarketTx, [], this.opts);
|
|
145
|
+
return txSig;
|
|
146
|
+
}
|
|
135
147
|
async moveAmmPrice(perpMarketIndex, baseAssetReserve, quoteAssetReserve, sqrtK) {
|
|
136
148
|
const marketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
|
|
137
149
|
if (sqrtK == undefined) {
|
|
@@ -1,62 +1,60 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const
|
|
8
|
-
export declare const
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const
|
|
14
|
-
export declare const
|
|
15
|
-
export declare const
|
|
16
|
-
export declare const
|
|
17
|
-
export declare const
|
|
18
|
-
export declare const
|
|
19
|
-
export declare const
|
|
20
|
-
export declare const
|
|
21
|
-
export declare const
|
|
22
|
-
export declare const
|
|
23
|
-
export declare const
|
|
24
|
-
export declare const
|
|
25
|
-
export declare const
|
|
26
|
-
export declare const
|
|
27
|
-
export declare const
|
|
28
|
-
export declare const
|
|
29
|
-
export declare const
|
|
30
|
-
export declare const
|
|
31
|
-
export declare const
|
|
32
|
-
export declare const
|
|
33
|
-
export declare const
|
|
34
|
-
export declare const
|
|
35
|
-
export declare const
|
|
36
|
-
export declare const
|
|
37
|
-
export declare const
|
|
38
|
-
export declare const
|
|
39
|
-
export declare const
|
|
40
|
-
export declare const
|
|
41
|
-
export declare const
|
|
42
|
-
export declare const
|
|
43
|
-
export declare const
|
|
44
|
-
export declare const
|
|
45
|
-
export declare const
|
|
46
|
-
export declare const
|
|
47
|
-
export declare const
|
|
48
|
-
export declare const
|
|
49
|
-
export declare const
|
|
50
|
-
export declare const
|
|
51
|
-
export declare const
|
|
52
|
-
export declare const
|
|
53
|
-
export declare const
|
|
54
|
-
export declare const
|
|
55
|
-
export declare const
|
|
56
|
-
export declare const ONE_HOUR: BN;
|
|
57
|
-
export declare const ONE_YEAR: BN;
|
|
1
|
+
export declare const ZERO: any;
|
|
2
|
+
export declare const ONE: any;
|
|
3
|
+
export declare const TWO: any;
|
|
4
|
+
export declare const THREE: any;
|
|
5
|
+
export declare const FOUR: any;
|
|
6
|
+
export declare const FIVE: any;
|
|
7
|
+
export declare const SIX: any;
|
|
8
|
+
export declare const SEVEN: any;
|
|
9
|
+
export declare const EIGHT: any;
|
|
10
|
+
export declare const NINE: any;
|
|
11
|
+
export declare const TEN: any;
|
|
12
|
+
export declare const TEN_THOUSAND: any;
|
|
13
|
+
export declare const BN_MAX: any;
|
|
14
|
+
export declare const TEN_MILLION: any;
|
|
15
|
+
export declare const MAX_LEVERAGE: any;
|
|
16
|
+
export declare const MAX_LEVERAGE_ORDER_SIZE: any;
|
|
17
|
+
export declare const PERCENTAGE_PRECISION_EXP: any;
|
|
18
|
+
export declare const PERCENTAGE_PRECISION: any;
|
|
19
|
+
export declare const CONCENTRATION_PRECISION: any;
|
|
20
|
+
export declare const QUOTE_PRECISION_EXP: any;
|
|
21
|
+
export declare const FUNDING_RATE_BUFFER_PRECISION_EXP: any;
|
|
22
|
+
export declare const PRICE_PRECISION_EXP: any;
|
|
23
|
+
export declare const FUNDING_RATE_PRECISION_EXP: any;
|
|
24
|
+
export declare const PEG_PRECISION_EXP: any;
|
|
25
|
+
export declare const AMM_RESERVE_PRECISION_EXP: any;
|
|
26
|
+
export declare const SPOT_MARKET_RATE_PRECISION_EXP: any;
|
|
27
|
+
export declare const SPOT_MARKET_RATE_PRECISION: any;
|
|
28
|
+
export declare const SPOT_MARKET_CUMULATIVE_INTEREST_PRECISION_EXP: any;
|
|
29
|
+
export declare const SPOT_MARKET_CUMULATIVE_INTEREST_PRECISION: any;
|
|
30
|
+
export declare const SPOT_MARKET_UTILIZATION_PRECISION_EXP: any;
|
|
31
|
+
export declare const SPOT_MARKET_UTILIZATION_PRECISION: any;
|
|
32
|
+
export declare const SPOT_MARKET_WEIGHT_PRECISION: any;
|
|
33
|
+
export declare const SPOT_MARKET_BALANCE_PRECISION_EXP: any;
|
|
34
|
+
export declare const SPOT_MARKET_BALANCE_PRECISION: any;
|
|
35
|
+
export declare const SPOT_MARKET_IMF_PRECISION_EXP: any;
|
|
36
|
+
export declare const SPOT_MARKET_IMF_PRECISION: any;
|
|
37
|
+
export declare const LIQUIDATION_FEE_PRECISION: any;
|
|
38
|
+
export declare const QUOTE_PRECISION: any;
|
|
39
|
+
export declare const PRICE_PRECISION: any;
|
|
40
|
+
export declare const FUNDING_RATE_PRECISION: any;
|
|
41
|
+
export declare const FUNDING_RATE_BUFFER_PRECISION: any;
|
|
42
|
+
export declare const PEG_PRECISION: any;
|
|
43
|
+
export declare const AMM_RESERVE_PRECISION: any;
|
|
44
|
+
export declare const BASE_PRECISION: any;
|
|
45
|
+
export declare const BASE_PRECISION_EXP: any;
|
|
46
|
+
export declare const AMM_TO_QUOTE_PRECISION_RATIO: any;
|
|
47
|
+
export declare const PRICE_DIV_PEG: any;
|
|
48
|
+
export declare const PRICE_TO_QUOTE_PRECISION: any;
|
|
49
|
+
export declare const AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO: any;
|
|
50
|
+
export declare const MARGIN_PRECISION: any;
|
|
51
|
+
export declare const BID_ASK_SPREAD_PRECISION: any;
|
|
52
|
+
export declare const LIQUIDATION_PCT_PRECISION: any;
|
|
53
|
+
export declare const FIVE_MINUTE: any;
|
|
54
|
+
export declare const ONE_HOUR: any;
|
|
55
|
+
export declare const ONE_YEAR: any;
|
|
58
56
|
export declare const QUOTE_SPOT_MARKET_INDEX = 0;
|
|
59
|
-
export declare const LAMPORTS_PRECISION:
|
|
60
|
-
export declare const LAMPORTS_EXP:
|
|
61
|
-
export declare const OPEN_ORDER_MARGIN_REQUIREMENT:
|
|
62
|
-
export declare const DEFAULT_REVENUE_SINCE_LAST_FUNDING_SPREAD_RETREAT:
|
|
57
|
+
export declare const LAMPORTS_PRECISION: any;
|
|
58
|
+
export declare const LAMPORTS_EXP: any;
|
|
59
|
+
export declare const OPEN_ORDER_MARGIN_REQUIREMENT: any;
|
|
60
|
+
export declare const DEFAULT_REVENUE_SINCE_LAST_FUNDING_SPREAD_RETREAT: any;
|
|
@@ -46,7 +46,7 @@ exports.DevnetPerpMarkets = [
|
|
|
46
46
|
},
|
|
47
47
|
{
|
|
48
48
|
fullName: 'Bonk',
|
|
49
|
-
category: ['Meme'],
|
|
49
|
+
category: ['Meme', 'Dog'],
|
|
50
50
|
symbol: '1MBONK-PERP',
|
|
51
51
|
baseAssetSymbol: '1MBONK',
|
|
52
52
|
marketIndex: 4,
|
|
@@ -74,6 +74,16 @@ exports.DevnetPerpMarkets = [
|
|
|
74
74
|
launchTs: 1679501812000,
|
|
75
75
|
oracleSource: __1.OracleSource.PYTH,
|
|
76
76
|
},
|
|
77
|
+
{
|
|
78
|
+
fullName: 'Doge',
|
|
79
|
+
category: ['Meme', 'Dog'],
|
|
80
|
+
symbol: 'DOGE-PERP',
|
|
81
|
+
baseAssetSymbol: 'DOGE',
|
|
82
|
+
marketIndex: 7,
|
|
83
|
+
oracle: new web3_js_1.PublicKey('4L6YhY8VvUgmqG5MvJkUJATtzB2rFqdrJwQCmFLv4Jzy'),
|
|
84
|
+
launchTs: 1680808053000,
|
|
85
|
+
oracleSource: __1.OracleSource.PYTH,
|
|
86
|
+
},
|
|
77
87
|
];
|
|
78
88
|
exports.MainnetPerpMarkets = [
|
|
79
89
|
{
|
|
@@ -146,6 +156,16 @@ exports.MainnetPerpMarkets = [
|
|
|
146
156
|
launchTs: 1679501812000,
|
|
147
157
|
oracleSource: __1.OracleSource.PYTH,
|
|
148
158
|
},
|
|
159
|
+
{
|
|
160
|
+
fullName: 'Doge',
|
|
161
|
+
category: ['Meme', 'Dog'],
|
|
162
|
+
symbol: 'DOGE-PERP',
|
|
163
|
+
baseAssetSymbol: 'DOGE',
|
|
164
|
+
marketIndex: 7,
|
|
165
|
+
oracle: new web3_js_1.PublicKey('FsSM3s38PX9K7Dn6eGzuE29S2Dsk1Sss1baytTQdCaQj'),
|
|
166
|
+
launchTs: 1680808053000,
|
|
167
|
+
oracleSource: __1.OracleSource.PYTH,
|
|
168
|
+
},
|
|
149
169
|
];
|
|
150
170
|
exports.PerpMarkets = {
|
|
151
171
|
devnet: exports.DevnetPerpMarkets,
|
package/lib/dlob/DLOB.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
import { NodeList } from './NodeList';
|
|
3
2
|
import { MarketType, BN, DriftClient, Order, SpotMarketAccount, PerpMarketAccount, OraclePriceData, SlotSubscriber, MarketTypeStr, StateAccount, UserMap, OrderRecord, OrderActionRecord } from '..';
|
|
4
3
|
import { PublicKey } from '@solana/web3.js';
|
package/lib/dlob/DLOBNode.d.ts
CHANGED
package/lib/dlob/DLOBOrders.d.ts
CHANGED
package/lib/dlob/DLOBOrders.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.DLOBOrdersCoder = void 0;
|
|
7
|
-
const idl_1 = require("@
|
|
7
|
+
const idl_1 = require("@coral-xyz/anchor/dist/cjs/coder/borsh/idl");
|
|
8
8
|
const dlobIdl_json_1 = __importDefault(require("./dlobIdl.json"));
|
|
9
9
|
class DLOBOrdersCoder {
|
|
10
10
|
constructor(idl) {
|
package/lib/dlob/NodeList.d.ts
CHANGED
package/lib/driftClient.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import * as anchor from '@project-serum/anchor';
|
|
2
|
+
import { AnchorProvider, BN, Program, ProgramAccount } from '@coral-xyz/anchor';
|
|
3
|
+
import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, ReferrerInfo, MarketType, TxParams, SerumV3FulfillmentConfigAccount, ReferrerNameAccount, OrderTriggerCondition, PerpMarketExtendedInfo, UserStatsAccount, ModifyOrderParams } from './types';
|
|
4
|
+
import * as anchor from '@coral-xyz/anchor';
|
|
6
5
|
import { Connection, PublicKey, TransactionSignature, ConfirmOptions, Transaction, TransactionInstruction, AccountMeta, Signer, AddressLookupTableAccount } from '@solana/web3.js';
|
|
7
6
|
import { TokenFaucet } from './tokenFaucet';
|
|
8
7
|
import { EventEmitter } from 'events';
|
|
@@ -104,6 +103,7 @@ export declare class DriftClient {
|
|
|
104
103
|
updateUserDelegate(delegate: PublicKey, subAccountId?: number): Promise<TransactionSignature>;
|
|
105
104
|
fetchAllUserAccounts(includeIdle?: boolean): Promise<ProgramAccount<UserAccount>[]>;
|
|
106
105
|
getUserAccountsForDelegate(delegate: PublicKey): Promise<UserAccount[]>;
|
|
106
|
+
getUserAccountsAndAddressesForAuthority(authority: PublicKey): Promise<ProgramAccount<UserAccount>[]>;
|
|
107
107
|
getUserAccountsForAuthority(authority: PublicKey): Promise<UserAccount[]>;
|
|
108
108
|
getReferredUserStatsAccountsByReferrer(referrer: PublicKey): Promise<UserStatsAccount[]>;
|
|
109
109
|
getReferrerNameAccountsForAuthority(authority: PublicKey): Promise<ReferrerNameAccount[]>;
|
|
@@ -246,57 +246,73 @@ export declare class DriftClient {
|
|
|
246
246
|
/**
|
|
247
247
|
* Modifies an open order (spot or perp) by closing it and replacing it with a new order.
|
|
248
248
|
* @param orderId: The open order to modify
|
|
249
|
-
* @param
|
|
250
|
-
* @param
|
|
251
|
-
* @param
|
|
252
|
-
* @param
|
|
249
|
+
* @param newDirection: The new direction for the order
|
|
250
|
+
* @param newBaseAmount: The new base amount for the order
|
|
251
|
+
* @param newLimitPice: The new limit price for the order
|
|
252
|
+
* @param newOraclePriceOffset: The new oracle price offset for the order
|
|
253
253
|
* @param newTriggerPrice: Optional - Thew new trigger price for the order.
|
|
254
|
-
* @param
|
|
255
|
-
* @param
|
|
256
|
-
* @param
|
|
257
|
-
* @param
|
|
254
|
+
* @param auctionDuration:
|
|
255
|
+
* @param auctionStartPrice:
|
|
256
|
+
* @param auctionEndPrice:
|
|
257
|
+
* @param reduceOnly:
|
|
258
|
+
* @param postOnly:
|
|
259
|
+
* @param immediateOrCancel:
|
|
260
|
+
* @param maxTs:
|
|
258
261
|
* @returns
|
|
259
262
|
*/
|
|
260
|
-
modifyOrder({ orderId, newBaseAmount, newLimitPrice, newOraclePriceOffset,
|
|
263
|
+
modifyOrder({ orderId, newDirection, newBaseAmount, newLimitPrice, newOraclePriceOffset, newTriggerPrice, newTriggerCondition, auctionDuration, auctionStartPrice, auctionEndPrice, reduceOnly, postOnly, immediateOrCancel, maxTs, txParams, }: {
|
|
261
264
|
orderId: number;
|
|
265
|
+
newDirection?: PositionDirection;
|
|
262
266
|
newBaseAmount?: BN;
|
|
263
267
|
newLimitPrice?: BN;
|
|
264
268
|
newOraclePriceOffset?: number;
|
|
265
|
-
newOrderType?: OrderType;
|
|
266
269
|
newTriggerPrice?: BN;
|
|
267
270
|
newTriggerCondition?: OrderTriggerCondition;
|
|
268
|
-
isSpot?: boolean;
|
|
269
271
|
auctionDuration?: number;
|
|
270
272
|
auctionStartPrice?: BN;
|
|
271
273
|
auctionEndPrice?: BN;
|
|
274
|
+
reduceOnly?: boolean;
|
|
275
|
+
postOnly?: boolean;
|
|
276
|
+
immediateOrCancel?: boolean;
|
|
277
|
+
maxTs?: BN;
|
|
278
|
+
txParams?: TxParams;
|
|
272
279
|
}): Promise<TransactionSignature>;
|
|
280
|
+
getModifyOrderIx(orderId: number, orderParams: ModifyOrderParams): Promise<TransactionInstruction>;
|
|
273
281
|
/**
|
|
274
282
|
* Modifies an open order by closing it and replacing it with a new order.
|
|
275
283
|
* @param userOrderId: The open order to modify
|
|
276
|
-
* @param
|
|
277
|
-
* @param
|
|
278
|
-
* @param
|
|
279
|
-
* @param
|
|
284
|
+
* @param newDirection: The new direction for the order
|
|
285
|
+
* @param newBaseAmount: The new base amount for the order
|
|
286
|
+
* @param newLimitPice: The new limit price for the order
|
|
287
|
+
* @param newOraclePriceOffset: The new oracle price offset for the order
|
|
280
288
|
* @param newTriggerPrice: Optional - Thew new trigger price for the order.
|
|
281
|
-
* @param isSpot: Set to true if the order is a spot order
|
|
282
289
|
* @param auctionDuration: Only required if order type changed to market from something else
|
|
283
290
|
* @param auctionStartPrice: Only required if order type changed to market from something else
|
|
284
291
|
* @param auctionEndPrice: Only required if order type changed to market from something else
|
|
292
|
+
* @param reduceOnly:
|
|
293
|
+
* @param postOnly:
|
|
294
|
+
* @param immediateOrCancel:
|
|
295
|
+
* @param maxTs:
|
|
285
296
|
* @returns
|
|
286
297
|
*/
|
|
287
|
-
modifyOrderByUserOrderId({ userOrderId, newBaseAmount, newLimitPrice, newOraclePriceOffset,
|
|
298
|
+
modifyOrderByUserOrderId({ userOrderId, newDirection, newBaseAmount, newLimitPrice, newOraclePriceOffset, newTriggerPrice, newTriggerCondition, auctionDuration, auctionStartPrice, auctionEndPrice, reduceOnly, postOnly, immediateOrCancel, maxTs, txParams, }: {
|
|
288
299
|
userOrderId: number;
|
|
300
|
+
newDirection?: PositionDirection;
|
|
289
301
|
newBaseAmount?: BN;
|
|
290
302
|
newLimitPrice?: BN;
|
|
291
303
|
newOraclePriceOffset?: number;
|
|
292
|
-
newOrderType?: OrderType;
|
|
293
304
|
newTriggerPrice?: BN;
|
|
294
305
|
newTriggerCondition?: OrderTriggerCondition;
|
|
295
|
-
isSpot?: boolean;
|
|
296
306
|
auctionDuration?: number;
|
|
297
307
|
auctionStartPrice?: BN;
|
|
298
308
|
auctionEndPrice?: BN;
|
|
309
|
+
reduceOnly?: boolean;
|
|
310
|
+
postOnly?: boolean;
|
|
311
|
+
immediateOrCancel?: boolean;
|
|
312
|
+
maxTs?: BN;
|
|
313
|
+
txParams?: TxParams;
|
|
299
314
|
}): Promise<TransactionSignature>;
|
|
315
|
+
getModifyOrderByUserIdIx(userOrderId: number, orderParams: ModifyOrderParams): Promise<TransactionInstruction>;
|
|
300
316
|
settlePNLs(users: {
|
|
301
317
|
settleeUserAccountPublicKey: PublicKey;
|
|
302
318
|
settleeUserAccount: UserAccount;
|
|
@@ -324,7 +340,25 @@ export declare class DriftClient {
|
|
|
324
340
|
getOracleDataForSpotMarket(marketIndex: number): OraclePriceData;
|
|
325
341
|
initializeInsuranceFundStake(marketIndex: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
326
342
|
getInitializeInsuranceFundStakeIx(marketIndex: number): Promise<TransactionInstruction>;
|
|
327
|
-
|
|
343
|
+
getAddInsuranceFundStakeIx(marketIndex: number, amount: BN, collateralAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
|
|
344
|
+
/**
|
|
345
|
+
* Add to an insurance fund stake and optionally initialize the account
|
|
346
|
+
*/
|
|
347
|
+
addInsuranceFundStake({ marketIndex, amount, collateralAccountPublicKey, initializeStakeAccount, }: {
|
|
348
|
+
/**
|
|
349
|
+
* Spot market index
|
|
350
|
+
*/
|
|
351
|
+
marketIndex: number;
|
|
352
|
+
amount: BN;
|
|
353
|
+
/**
|
|
354
|
+
* The account where the funds to stake come from. Usually an associated token account
|
|
355
|
+
*/
|
|
356
|
+
collateralAccountPublicKey: PublicKey;
|
|
357
|
+
/**
|
|
358
|
+
* Add instructions to initialize the staking account -- required if its the first time the currrent authority has staked in this market
|
|
359
|
+
*/
|
|
360
|
+
initializeStakeAccount?: boolean;
|
|
361
|
+
}): Promise<TransactionSignature>;
|
|
328
362
|
requestRemoveInsuranceFundStake(marketIndex: number, amount: BN): Promise<TransactionSignature>;
|
|
329
363
|
cancelRequestRemoveInsuranceFundStake(marketIndex: number): Promise<TransactionSignature>;
|
|
330
364
|
removeInsuranceFundStake(marketIndex: number, collateralAccountPublicKey: PublicKey): Promise<TransactionSignature>;
|