@drift-labs/sdk-browser 2.113.0-beta.0 → 2.113.0-beta.2
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/addresses/pda.d.ts +1 -0
- package/lib/browser/addresses/pda.js +8 -1
- package/lib/browser/decode/user.js +1 -1
- package/lib/browser/dlob/DLOB.js +2 -2
- package/lib/browser/dlob/NodeList.js +1 -1
- package/lib/browser/driftClient.d.ts +6 -0
- package/lib/browser/driftClient.js +52 -0
- package/lib/browser/idl/drift.json +86 -0
- package/lib/browser/math/orders.js +3 -3
- package/lib/browser/types.d.ts +6 -0
- package/lib/browser/types.js +2 -0
- package/lib/browser/user.js +1 -1
- package/lib/node/addresses/pda.d.ts +1 -0
- package/lib/node/addresses/pda.js +8 -1
- package/lib/node/decode/user.js +1 -1
- package/lib/node/dlob/DLOB.js +2 -2
- package/lib/node/dlob/NodeList.js +1 -1
- package/lib/node/driftClient.d.ts +6 -0
- package/lib/node/driftClient.js +52 -0
- package/lib/node/idl/drift.json +86 -0
- package/lib/node/math/orders.js +3 -3
- package/lib/node/types.d.ts +6 -0
- package/lib/node/types.js +2 -0
- package/lib/node/user.js +1 -1
- package/package.json +1 -1
- package/src/addresses/pda.ts +13 -0
- package/src/decode/user.ts +1 -1
- package/src/dlob/DLOB.ts +2 -2
- package/src/dlob/NodeList.ts +1 -1
- package/src/driftClient.ts +103 -0
- package/src/idl/drift.json +86 -0
- package/src/math/orders.ts +3 -3
- package/src/types.ts +2 -0
- package/src/user.ts +1 -1
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.113.0-beta.
|
|
1
|
+
2.113.0-beta.2
|
|
@@ -10,6 +10,7 @@ export declare function getUserAccountPublicKeySync(programId: PublicKey, author
|
|
|
10
10
|
export declare function getUserStatsAccountPublicKey(programId: PublicKey, authority: PublicKey): PublicKey;
|
|
11
11
|
export declare function getFuelOverflowAccountPublicKey(programId: PublicKey, authority: PublicKey): PublicKey;
|
|
12
12
|
export declare function getSignedMsgUserAccountPublicKey(programId: PublicKey, authority: PublicKey): PublicKey;
|
|
13
|
+
export declare function getSignedMsgWsDelegatesAccountPublicKey(programId: PublicKey, authority: PublicKey): PublicKey;
|
|
13
14
|
export declare function getPerpMarketPublicKey(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
|
|
14
15
|
export declare function getPerpMarketPublicKeySync(programId: PublicKey, marketIndex: number): PublicKey;
|
|
15
16
|
export declare function getSpotMarketPublicKey(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.getProtectedMakerModeConfigPublicKey = exports.getHighLeverageModeConfigPublicKey = exports.getTokenProgramForSpotMarket = exports.getPythLazerOraclePublicKey = exports.getPythPullOraclePublicKey = exports.getPrelaunchOraclePublicKey = exports.getProtocolIfSharesTransferConfigPublicKey = exports.getReferrerNamePublicKeySync = exports.getOpenbookV2FulfillmentConfigPublicKey = exports.getPhoenixFulfillmentConfigPublicKey = exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getDriftSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKeySync = exports.getSpotMarketPublicKey = exports.getPerpMarketPublicKeySync = exports.getPerpMarketPublicKey = exports.getSignedMsgUserAccountPublicKey = exports.getFuelOverflowAccountPublicKey = exports.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getDriftStateAccountPublicKey = exports.getDriftStateAccountPublicKeyAndNonce = void 0;
|
|
26
|
+
exports.getProtectedMakerModeConfigPublicKey = exports.getHighLeverageModeConfigPublicKey = exports.getTokenProgramForSpotMarket = exports.getPythLazerOraclePublicKey = exports.getPythPullOraclePublicKey = exports.getPrelaunchOraclePublicKey = exports.getProtocolIfSharesTransferConfigPublicKey = exports.getReferrerNamePublicKeySync = exports.getOpenbookV2FulfillmentConfigPublicKey = exports.getPhoenixFulfillmentConfigPublicKey = exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getDriftSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKeySync = exports.getSpotMarketPublicKey = exports.getPerpMarketPublicKeySync = exports.getPerpMarketPublicKey = exports.getSignedMsgWsDelegatesAccountPublicKey = exports.getSignedMsgUserAccountPublicKey = exports.getFuelOverflowAccountPublicKey = 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
28
|
const anchor = __importStar(require("@coral-xyz/anchor"));
|
|
29
29
|
const spl_token_1 = require("@solana/spl-token");
|
|
@@ -76,6 +76,13 @@ function getSignedMsgUserAccountPublicKey(programId, authority) {
|
|
|
76
76
|
], programId)[0];
|
|
77
77
|
}
|
|
78
78
|
exports.getSignedMsgUserAccountPublicKey = getSignedMsgUserAccountPublicKey;
|
|
79
|
+
function getSignedMsgWsDelegatesAccountPublicKey(programId, authority) {
|
|
80
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
81
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('SIGNED_MSG_WS')),
|
|
82
|
+
authority.toBuffer(),
|
|
83
|
+
], programId)[0];
|
|
84
|
+
}
|
|
85
|
+
exports.getSignedMsgWsDelegatesAccountPublicKey = getSignedMsgWsDelegatesAccountPublicKey;
|
|
79
86
|
async function getPerpMarketPublicKey(programId, marketIndex) {
|
|
80
87
|
return (await web3_js_1.PublicKey.findProgramAddress([
|
|
81
88
|
Buffer.from(anchor.utils.bytes.utf8.encode('perp_market')),
|
|
@@ -121,7 +121,7 @@ function decodeUser(buffer) {
|
|
|
121
121
|
const orders = [];
|
|
122
122
|
for (let i = 0; i < 32; i++) {
|
|
123
123
|
// skip order if it's not open
|
|
124
|
-
if (buffer.readUint8(offset + 82)
|
|
124
|
+
if (buffer.readUint8(offset + 82) !== 1) {
|
|
125
125
|
offset += 96;
|
|
126
126
|
continue;
|
|
127
127
|
}
|
package/lib/browser/dlob/DLOB.js
CHANGED
|
@@ -73,7 +73,7 @@ class DLOB {
|
|
|
73
73
|
}
|
|
74
74
|
insertOrder(order, userAccount, slot, isUserProtectedMaker, onInsert) {
|
|
75
75
|
var _a;
|
|
76
|
-
if ((0, __1.isVariant)(order.status, '
|
|
76
|
+
if (!(0, __1.isVariant)(order.status, 'open')) {
|
|
77
77
|
return;
|
|
78
78
|
}
|
|
79
79
|
if (!(0, __1.isOneOfVariant)(order.orderType, SUPPORTED_ORDER_TYPES)) {
|
|
@@ -145,7 +145,7 @@ class DLOB {
|
|
|
145
145
|
}
|
|
146
146
|
delete(order, userAccount, slot, isUserProtectedMaker, onDelete) {
|
|
147
147
|
var _a;
|
|
148
|
-
if ((0, __1.isVariant)(order.status, '
|
|
148
|
+
if (!(0, __1.isVariant)(order.status, 'open')) {
|
|
149
149
|
return;
|
|
150
150
|
}
|
|
151
151
|
this.updateRestingLimitOrders(slot);
|
|
@@ -20,7 +20,7 @@ class NodeList {
|
|
|
20
20
|
this.nodeMap.clear();
|
|
21
21
|
}
|
|
22
22
|
insert(order, marketType, userAccount, isProtectedMaker, applyProtectedMakerOffset) {
|
|
23
|
-
if ((0, __1.isVariant)(order.status, '
|
|
23
|
+
if (!(0, __1.isVariant)(order.status, 'open')) {
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
26
|
const newNode = (0, DLOBNode_1.createNode)(this.nodeType, order, userAccount, isProtectedMaker, applyProtectedMakerOffset);
|
|
@@ -169,6 +169,12 @@ export declare class DriftClient {
|
|
|
169
169
|
getInitializeSignedMsgUserOrdersAccountIx(authority: PublicKey, numOrders: number): Promise<[PublicKey, TransactionInstruction]>;
|
|
170
170
|
resizeSignedMsgUserOrders(authority: PublicKey, numOrders: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
171
171
|
getResizeSignedMsgUserOrdersInstruction(authority: PublicKey, numOrders: number): Promise<TransactionInstruction>;
|
|
172
|
+
initializeSignedMsgWsDelegatesAccount(authority: PublicKey, delegates?: PublicKey[], txParams?: TxParams): Promise<TransactionSignature>;
|
|
173
|
+
getInitializeSignedMsgWsDelegatesAccountIx(authority: PublicKey, delegates?: PublicKey[]): Promise<TransactionInstruction>;
|
|
174
|
+
addSignedMsgWsDelegate(authority: PublicKey, delegate: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
|
|
175
|
+
getAddSignedMsgWsDelegateIx(authority: PublicKey, delegate: PublicKey): Promise<TransactionInstruction>;
|
|
176
|
+
removeSignedMsgWsDelegate(authority: PublicKey, delegate: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
|
|
177
|
+
getRemoveSignedMsgWsDelegateIx(authority: PublicKey, delegate: PublicKey): Promise<TransactionInstruction>;
|
|
172
178
|
initializeFuelOverflow(authority?: PublicKey): Promise<TransactionSignature>;
|
|
173
179
|
getInitializeFuelOverflowIx(authority?: PublicKey): Promise<TransactionInstruction>;
|
|
174
180
|
sweepFuel(authority?: PublicKey): Promise<TransactionSignature>;
|
|
@@ -667,6 +667,58 @@ class DriftClient {
|
|
|
667
667
|
});
|
|
668
668
|
return resizeUserAccountIx;
|
|
669
669
|
}
|
|
670
|
+
async initializeSignedMsgWsDelegatesAccount(authority, delegates = [], txParams) {
|
|
671
|
+
const ix = await this.getInitializeSignedMsgWsDelegatesAccountIx(authority, delegates);
|
|
672
|
+
const tx = await this.buildTransaction([ix], txParams);
|
|
673
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
674
|
+
return txSig;
|
|
675
|
+
}
|
|
676
|
+
async getInitializeSignedMsgWsDelegatesAccountIx(authority, delegates = []) {
|
|
677
|
+
const signedMsgWsDelegates = (0, pda_1.getSignedMsgWsDelegatesAccountPublicKey)(this.program.programId, authority);
|
|
678
|
+
const ix = await this.program.instruction.initializeSignedMsgWsDelegates(delegates, {
|
|
679
|
+
accounts: {
|
|
680
|
+
signedMsgWsDelegates,
|
|
681
|
+
authority: this.wallet.publicKey,
|
|
682
|
+
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
|
|
683
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
684
|
+
},
|
|
685
|
+
});
|
|
686
|
+
return ix;
|
|
687
|
+
}
|
|
688
|
+
async addSignedMsgWsDelegate(authority, delegate, txParams) {
|
|
689
|
+
const ix = await this.getAddSignedMsgWsDelegateIx(authority, delegate);
|
|
690
|
+
const tx = await this.buildTransaction([ix], txParams);
|
|
691
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
692
|
+
return txSig;
|
|
693
|
+
}
|
|
694
|
+
async getAddSignedMsgWsDelegateIx(authority, delegate) {
|
|
695
|
+
const signedMsgWsDelegates = (0, pda_1.getSignedMsgWsDelegatesAccountPublicKey)(this.program.programId, authority);
|
|
696
|
+
const ix = await this.program.instruction.changeSignedMsgWsDelegateStatus(delegate, true, {
|
|
697
|
+
accounts: {
|
|
698
|
+
signedMsgWsDelegates,
|
|
699
|
+
authority: this.wallet.publicKey,
|
|
700
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
701
|
+
},
|
|
702
|
+
});
|
|
703
|
+
return ix;
|
|
704
|
+
}
|
|
705
|
+
async removeSignedMsgWsDelegate(authority, delegate, txParams) {
|
|
706
|
+
const ix = await this.getRemoveSignedMsgWsDelegateIx(authority, delegate);
|
|
707
|
+
const tx = await this.buildTransaction([ix], txParams);
|
|
708
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
709
|
+
return txSig;
|
|
710
|
+
}
|
|
711
|
+
async getRemoveSignedMsgWsDelegateIx(authority, delegate) {
|
|
712
|
+
const signedMsgWsDelegates = (0, pda_1.getSignedMsgWsDelegatesAccountPublicKey)(this.program.programId, authority);
|
|
713
|
+
const ix = await this.program.instruction.changeSignedMsgWsDelegateStatus(delegate, false, {
|
|
714
|
+
accounts: {
|
|
715
|
+
signedMsgWsDelegates,
|
|
716
|
+
authority: this.wallet.publicKey,
|
|
717
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
718
|
+
},
|
|
719
|
+
});
|
|
720
|
+
return ix;
|
|
721
|
+
}
|
|
670
722
|
async initializeFuelOverflow(authority) {
|
|
671
723
|
const ix = await this.getInitializeFuelOverflowIx(authority);
|
|
672
724
|
const tx = await this.buildTransaction([ix], this.txParams);
|
|
@@ -155,6 +155,69 @@
|
|
|
155
155
|
}
|
|
156
156
|
]
|
|
157
157
|
},
|
|
158
|
+
{
|
|
159
|
+
"name": "initializeSignedMsgWsDelegates",
|
|
160
|
+
"accounts": [
|
|
161
|
+
{
|
|
162
|
+
"name": "signedMsgWsDelegates",
|
|
163
|
+
"isMut": true,
|
|
164
|
+
"isSigner": false
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
"name": "authority",
|
|
168
|
+
"isMut": true,
|
|
169
|
+
"isSigner": true
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
"name": "rent",
|
|
173
|
+
"isMut": false,
|
|
174
|
+
"isSigner": false
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
"name": "systemProgram",
|
|
178
|
+
"isMut": false,
|
|
179
|
+
"isSigner": false
|
|
180
|
+
}
|
|
181
|
+
],
|
|
182
|
+
"args": [
|
|
183
|
+
{
|
|
184
|
+
"name": "delegates",
|
|
185
|
+
"type": {
|
|
186
|
+
"vec": "publicKey"
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
]
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
"name": "changeSignedMsgWsDelegateStatus",
|
|
193
|
+
"accounts": [
|
|
194
|
+
{
|
|
195
|
+
"name": "signedMsgWsDelegates",
|
|
196
|
+
"isMut": true,
|
|
197
|
+
"isSigner": false
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
"name": "authority",
|
|
201
|
+
"isMut": true,
|
|
202
|
+
"isSigner": true
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
"name": "systemProgram",
|
|
206
|
+
"isMut": false,
|
|
207
|
+
"isSigner": false
|
|
208
|
+
}
|
|
209
|
+
],
|
|
210
|
+
"args": [
|
|
211
|
+
{
|
|
212
|
+
"name": "delegate",
|
|
213
|
+
"type": "publicKey"
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
"name": "add",
|
|
217
|
+
"type": "bool"
|
|
218
|
+
}
|
|
219
|
+
]
|
|
220
|
+
},
|
|
158
221
|
{
|
|
159
222
|
"name": "initializeFuelOverflow",
|
|
160
223
|
"accounts": [
|
|
@@ -6939,6 +7002,12 @@
|
|
|
6939
7002
|
{
|
|
6940
7003
|
"name": "reduceOnly",
|
|
6941
7004
|
"type": "bool"
|
|
7005
|
+
},
|
|
7006
|
+
{
|
|
7007
|
+
"name": "currentUsers",
|
|
7008
|
+
"type": {
|
|
7009
|
+
"option": "u32"
|
|
7010
|
+
}
|
|
6942
7011
|
}
|
|
6943
7012
|
]
|
|
6944
7013
|
}
|
|
@@ -7681,6 +7750,23 @@
|
|
|
7681
7750
|
]
|
|
7682
7751
|
}
|
|
7683
7752
|
},
|
|
7753
|
+
{
|
|
7754
|
+
"name": "SignedMsgWsDelegates",
|
|
7755
|
+
"docs": [
|
|
7756
|
+
"* Used to store authenticated delegates for swift-like ws connections"
|
|
7757
|
+
],
|
|
7758
|
+
"type": {
|
|
7759
|
+
"kind": "struct",
|
|
7760
|
+
"fields": [
|
|
7761
|
+
{
|
|
7762
|
+
"name": "delegates",
|
|
7763
|
+
"type": {
|
|
7764
|
+
"vec": "publicKey"
|
|
7765
|
+
}
|
|
7766
|
+
}
|
|
7767
|
+
]
|
|
7768
|
+
}
|
|
7769
|
+
},
|
|
7684
7770
|
{
|
|
7685
7771
|
"name": "SpotMarket",
|
|
7686
7772
|
"type": {
|
|
@@ -7,7 +7,7 @@ const anchor_1 = require("@coral-xyz/anchor");
|
|
|
7
7
|
const auction_1 = require("./auction");
|
|
8
8
|
const amm_1 = require("./amm");
|
|
9
9
|
function isOrderRiskIncreasing(user, order) {
|
|
10
|
-
if ((0, types_1.isVariant)(order.status, '
|
|
10
|
+
if (!(0, types_1.isVariant)(order.status, 'open')) {
|
|
11
11
|
return false;
|
|
12
12
|
}
|
|
13
13
|
const position = user.getPerpPosition(order.marketIndex) ||
|
|
@@ -34,7 +34,7 @@ function isOrderRiskIncreasing(user, order) {
|
|
|
34
34
|
}
|
|
35
35
|
exports.isOrderRiskIncreasing = isOrderRiskIncreasing;
|
|
36
36
|
function isOrderRiskIncreasingInSameDirection(user, order) {
|
|
37
|
-
if ((0, types_1.isVariant)(order.status, '
|
|
37
|
+
if (!(0, types_1.isVariant)(order.status, 'open')) {
|
|
38
38
|
return false;
|
|
39
39
|
}
|
|
40
40
|
const position = user.getPerpPosition(order.marketIndex) ||
|
|
@@ -56,7 +56,7 @@ function isOrderRiskIncreasingInSameDirection(user, order) {
|
|
|
56
56
|
}
|
|
57
57
|
exports.isOrderRiskIncreasingInSameDirection = isOrderRiskIncreasingInSameDirection;
|
|
58
58
|
function isOrderReduceOnly(user, order) {
|
|
59
|
-
if ((0, types_1.isVariant)(order.status, '
|
|
59
|
+
if (!(0, types_1.isVariant)(order.status, 'open')) {
|
|
60
60
|
return false;
|
|
61
61
|
}
|
|
62
62
|
const position = user.getPerpPosition(order.marketIndex) ||
|
package/lib/browser/types.d.ts
CHANGED
|
@@ -264,6 +264,12 @@ export declare class OrderStatus {
|
|
|
264
264
|
static readonly OPEN: {
|
|
265
265
|
open: {};
|
|
266
266
|
};
|
|
267
|
+
static readonly FILLED: {
|
|
268
|
+
filled: {};
|
|
269
|
+
};
|
|
270
|
+
static readonly CANCELED: {
|
|
271
|
+
canceled: {};
|
|
272
|
+
};
|
|
267
273
|
}
|
|
268
274
|
export declare class OrderAction {
|
|
269
275
|
static readonly PLACE: {
|
package/lib/browser/types.js
CHANGED
|
@@ -164,6 +164,8 @@ class OrderStatus {
|
|
|
164
164
|
exports.OrderStatus = OrderStatus;
|
|
165
165
|
OrderStatus.INIT = { init: {} };
|
|
166
166
|
OrderStatus.OPEN = { open: {} };
|
|
167
|
+
OrderStatus.FILLED = { filled: {} };
|
|
168
|
+
OrderStatus.CANCELED = { canceled: {} };
|
|
167
169
|
class OrderAction {
|
|
168
170
|
}
|
|
169
171
|
exports.OrderAction = OrderAction;
|
package/lib/browser/user.js
CHANGED
|
@@ -10,6 +10,7 @@ export declare function getUserAccountPublicKeySync(programId: PublicKey, author
|
|
|
10
10
|
export declare function getUserStatsAccountPublicKey(programId: PublicKey, authority: PublicKey): PublicKey;
|
|
11
11
|
export declare function getFuelOverflowAccountPublicKey(programId: PublicKey, authority: PublicKey): PublicKey;
|
|
12
12
|
export declare function getSignedMsgUserAccountPublicKey(programId: PublicKey, authority: PublicKey): PublicKey;
|
|
13
|
+
export declare function getSignedMsgWsDelegatesAccountPublicKey(programId: PublicKey, authority: PublicKey): PublicKey;
|
|
13
14
|
export declare function getPerpMarketPublicKey(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
|
|
14
15
|
export declare function getPerpMarketPublicKeySync(programId: PublicKey, marketIndex: number): PublicKey;
|
|
15
16
|
export declare function getSpotMarketPublicKey(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
|
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.getProtectedMakerModeConfigPublicKey = exports.getHighLeverageModeConfigPublicKey = exports.getTokenProgramForSpotMarket = exports.getPythLazerOraclePublicKey = exports.getPythPullOraclePublicKey = exports.getPrelaunchOraclePublicKey = exports.getProtocolIfSharesTransferConfigPublicKey = exports.getReferrerNamePublicKeySync = exports.getOpenbookV2FulfillmentConfigPublicKey = exports.getPhoenixFulfillmentConfigPublicKey = exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getDriftSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKeySync = exports.getSpotMarketPublicKey = exports.getPerpMarketPublicKeySync = exports.getPerpMarketPublicKey = exports.getSignedMsgUserAccountPublicKey = exports.getFuelOverflowAccountPublicKey = exports.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getDriftStateAccountPublicKey = exports.getDriftStateAccountPublicKeyAndNonce = void 0;
|
|
26
|
+
exports.getProtectedMakerModeConfigPublicKey = exports.getHighLeverageModeConfigPublicKey = exports.getTokenProgramForSpotMarket = exports.getPythLazerOraclePublicKey = exports.getPythPullOraclePublicKey = exports.getPrelaunchOraclePublicKey = exports.getProtocolIfSharesTransferConfigPublicKey = exports.getReferrerNamePublicKeySync = exports.getOpenbookV2FulfillmentConfigPublicKey = exports.getPhoenixFulfillmentConfigPublicKey = exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getDriftSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKeySync = exports.getSpotMarketPublicKey = exports.getPerpMarketPublicKeySync = exports.getPerpMarketPublicKey = exports.getSignedMsgWsDelegatesAccountPublicKey = exports.getSignedMsgUserAccountPublicKey = exports.getFuelOverflowAccountPublicKey = 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
28
|
const anchor = __importStar(require("@coral-xyz/anchor"));
|
|
29
29
|
const spl_token_1 = require("@solana/spl-token");
|
|
@@ -76,6 +76,13 @@ function getSignedMsgUserAccountPublicKey(programId, authority) {
|
|
|
76
76
|
], programId)[0];
|
|
77
77
|
}
|
|
78
78
|
exports.getSignedMsgUserAccountPublicKey = getSignedMsgUserAccountPublicKey;
|
|
79
|
+
function getSignedMsgWsDelegatesAccountPublicKey(programId, authority) {
|
|
80
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
81
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('SIGNED_MSG_WS')),
|
|
82
|
+
authority.toBuffer(),
|
|
83
|
+
], programId)[0];
|
|
84
|
+
}
|
|
85
|
+
exports.getSignedMsgWsDelegatesAccountPublicKey = getSignedMsgWsDelegatesAccountPublicKey;
|
|
79
86
|
async function getPerpMarketPublicKey(programId, marketIndex) {
|
|
80
87
|
return (await web3_js_1.PublicKey.findProgramAddress([
|
|
81
88
|
Buffer.from(anchor.utils.bytes.utf8.encode('perp_market')),
|
package/lib/node/decode/user.js
CHANGED
|
@@ -121,7 +121,7 @@ function decodeUser(buffer) {
|
|
|
121
121
|
const orders = [];
|
|
122
122
|
for (let i = 0; i < 32; i++) {
|
|
123
123
|
// skip order if it's not open
|
|
124
|
-
if (buffer.readUint8(offset + 82)
|
|
124
|
+
if (buffer.readUint8(offset + 82) !== 1) {
|
|
125
125
|
offset += 96;
|
|
126
126
|
continue;
|
|
127
127
|
}
|
package/lib/node/dlob/DLOB.js
CHANGED
|
@@ -73,7 +73,7 @@ class DLOB {
|
|
|
73
73
|
}
|
|
74
74
|
insertOrder(order, userAccount, slot, isUserProtectedMaker, onInsert) {
|
|
75
75
|
var _a;
|
|
76
|
-
if ((0, __1.isVariant)(order.status, '
|
|
76
|
+
if (!(0, __1.isVariant)(order.status, 'open')) {
|
|
77
77
|
return;
|
|
78
78
|
}
|
|
79
79
|
if (!(0, __1.isOneOfVariant)(order.orderType, SUPPORTED_ORDER_TYPES)) {
|
|
@@ -145,7 +145,7 @@ class DLOB {
|
|
|
145
145
|
}
|
|
146
146
|
delete(order, userAccount, slot, isUserProtectedMaker, onDelete) {
|
|
147
147
|
var _a;
|
|
148
|
-
if ((0, __1.isVariant)(order.status, '
|
|
148
|
+
if (!(0, __1.isVariant)(order.status, 'open')) {
|
|
149
149
|
return;
|
|
150
150
|
}
|
|
151
151
|
this.updateRestingLimitOrders(slot);
|
|
@@ -20,7 +20,7 @@ class NodeList {
|
|
|
20
20
|
this.nodeMap.clear();
|
|
21
21
|
}
|
|
22
22
|
insert(order, marketType, userAccount, isProtectedMaker, applyProtectedMakerOffset) {
|
|
23
|
-
if ((0, __1.isVariant)(order.status, '
|
|
23
|
+
if (!(0, __1.isVariant)(order.status, 'open')) {
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
26
|
const newNode = (0, DLOBNode_1.createNode)(this.nodeType, order, userAccount, isProtectedMaker, applyProtectedMakerOffset);
|
|
@@ -169,6 +169,12 @@ export declare class DriftClient {
|
|
|
169
169
|
getInitializeSignedMsgUserOrdersAccountIx(authority: PublicKey, numOrders: number): Promise<[PublicKey, TransactionInstruction]>;
|
|
170
170
|
resizeSignedMsgUserOrders(authority: PublicKey, numOrders: number, txParams?: TxParams): Promise<TransactionSignature>;
|
|
171
171
|
getResizeSignedMsgUserOrdersInstruction(authority: PublicKey, numOrders: number): Promise<TransactionInstruction>;
|
|
172
|
+
initializeSignedMsgWsDelegatesAccount(authority: PublicKey, delegates?: PublicKey[], txParams?: TxParams): Promise<TransactionSignature>;
|
|
173
|
+
getInitializeSignedMsgWsDelegatesAccountIx(authority: PublicKey, delegates?: PublicKey[]): Promise<TransactionInstruction>;
|
|
174
|
+
addSignedMsgWsDelegate(authority: PublicKey, delegate: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
|
|
175
|
+
getAddSignedMsgWsDelegateIx(authority: PublicKey, delegate: PublicKey): Promise<TransactionInstruction>;
|
|
176
|
+
removeSignedMsgWsDelegate(authority: PublicKey, delegate: PublicKey, txParams?: TxParams): Promise<TransactionSignature>;
|
|
177
|
+
getRemoveSignedMsgWsDelegateIx(authority: PublicKey, delegate: PublicKey): Promise<TransactionInstruction>;
|
|
172
178
|
initializeFuelOverflow(authority?: PublicKey): Promise<TransactionSignature>;
|
|
173
179
|
getInitializeFuelOverflowIx(authority?: PublicKey): Promise<TransactionInstruction>;
|
|
174
180
|
sweepFuel(authority?: PublicKey): Promise<TransactionSignature>;
|
package/lib/node/driftClient.js
CHANGED
|
@@ -667,6 +667,58 @@ class DriftClient {
|
|
|
667
667
|
});
|
|
668
668
|
return resizeUserAccountIx;
|
|
669
669
|
}
|
|
670
|
+
async initializeSignedMsgWsDelegatesAccount(authority, delegates = [], txParams) {
|
|
671
|
+
const ix = await this.getInitializeSignedMsgWsDelegatesAccountIx(authority, delegates);
|
|
672
|
+
const tx = await this.buildTransaction([ix], txParams);
|
|
673
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
674
|
+
return txSig;
|
|
675
|
+
}
|
|
676
|
+
async getInitializeSignedMsgWsDelegatesAccountIx(authority, delegates = []) {
|
|
677
|
+
const signedMsgWsDelegates = (0, pda_1.getSignedMsgWsDelegatesAccountPublicKey)(this.program.programId, authority);
|
|
678
|
+
const ix = await this.program.instruction.initializeSignedMsgWsDelegates(delegates, {
|
|
679
|
+
accounts: {
|
|
680
|
+
signedMsgWsDelegates,
|
|
681
|
+
authority: this.wallet.publicKey,
|
|
682
|
+
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
|
|
683
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
684
|
+
},
|
|
685
|
+
});
|
|
686
|
+
return ix;
|
|
687
|
+
}
|
|
688
|
+
async addSignedMsgWsDelegate(authority, delegate, txParams) {
|
|
689
|
+
const ix = await this.getAddSignedMsgWsDelegateIx(authority, delegate);
|
|
690
|
+
const tx = await this.buildTransaction([ix], txParams);
|
|
691
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
692
|
+
return txSig;
|
|
693
|
+
}
|
|
694
|
+
async getAddSignedMsgWsDelegateIx(authority, delegate) {
|
|
695
|
+
const signedMsgWsDelegates = (0, pda_1.getSignedMsgWsDelegatesAccountPublicKey)(this.program.programId, authority);
|
|
696
|
+
const ix = await this.program.instruction.changeSignedMsgWsDelegateStatus(delegate, true, {
|
|
697
|
+
accounts: {
|
|
698
|
+
signedMsgWsDelegates,
|
|
699
|
+
authority: this.wallet.publicKey,
|
|
700
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
701
|
+
},
|
|
702
|
+
});
|
|
703
|
+
return ix;
|
|
704
|
+
}
|
|
705
|
+
async removeSignedMsgWsDelegate(authority, delegate, txParams) {
|
|
706
|
+
const ix = await this.getRemoveSignedMsgWsDelegateIx(authority, delegate);
|
|
707
|
+
const tx = await this.buildTransaction([ix], txParams);
|
|
708
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
709
|
+
return txSig;
|
|
710
|
+
}
|
|
711
|
+
async getRemoveSignedMsgWsDelegateIx(authority, delegate) {
|
|
712
|
+
const signedMsgWsDelegates = (0, pda_1.getSignedMsgWsDelegatesAccountPublicKey)(this.program.programId, authority);
|
|
713
|
+
const ix = await this.program.instruction.changeSignedMsgWsDelegateStatus(delegate, false, {
|
|
714
|
+
accounts: {
|
|
715
|
+
signedMsgWsDelegates,
|
|
716
|
+
authority: this.wallet.publicKey,
|
|
717
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
718
|
+
},
|
|
719
|
+
});
|
|
720
|
+
return ix;
|
|
721
|
+
}
|
|
670
722
|
async initializeFuelOverflow(authority) {
|
|
671
723
|
const ix = await this.getInitializeFuelOverflowIx(authority);
|
|
672
724
|
const tx = await this.buildTransaction([ix], this.txParams);
|
package/lib/node/idl/drift.json
CHANGED
|
@@ -155,6 +155,69 @@
|
|
|
155
155
|
}
|
|
156
156
|
]
|
|
157
157
|
},
|
|
158
|
+
{
|
|
159
|
+
"name": "initializeSignedMsgWsDelegates",
|
|
160
|
+
"accounts": [
|
|
161
|
+
{
|
|
162
|
+
"name": "signedMsgWsDelegates",
|
|
163
|
+
"isMut": true,
|
|
164
|
+
"isSigner": false
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
"name": "authority",
|
|
168
|
+
"isMut": true,
|
|
169
|
+
"isSigner": true
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
"name": "rent",
|
|
173
|
+
"isMut": false,
|
|
174
|
+
"isSigner": false
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
"name": "systemProgram",
|
|
178
|
+
"isMut": false,
|
|
179
|
+
"isSigner": false
|
|
180
|
+
}
|
|
181
|
+
],
|
|
182
|
+
"args": [
|
|
183
|
+
{
|
|
184
|
+
"name": "delegates",
|
|
185
|
+
"type": {
|
|
186
|
+
"vec": "publicKey"
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
]
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
"name": "changeSignedMsgWsDelegateStatus",
|
|
193
|
+
"accounts": [
|
|
194
|
+
{
|
|
195
|
+
"name": "signedMsgWsDelegates",
|
|
196
|
+
"isMut": true,
|
|
197
|
+
"isSigner": false
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
"name": "authority",
|
|
201
|
+
"isMut": true,
|
|
202
|
+
"isSigner": true
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
"name": "systemProgram",
|
|
206
|
+
"isMut": false,
|
|
207
|
+
"isSigner": false
|
|
208
|
+
}
|
|
209
|
+
],
|
|
210
|
+
"args": [
|
|
211
|
+
{
|
|
212
|
+
"name": "delegate",
|
|
213
|
+
"type": "publicKey"
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
"name": "add",
|
|
217
|
+
"type": "bool"
|
|
218
|
+
}
|
|
219
|
+
]
|
|
220
|
+
},
|
|
158
221
|
{
|
|
159
222
|
"name": "initializeFuelOverflow",
|
|
160
223
|
"accounts": [
|
|
@@ -6939,6 +7002,12 @@
|
|
|
6939
7002
|
{
|
|
6940
7003
|
"name": "reduceOnly",
|
|
6941
7004
|
"type": "bool"
|
|
7005
|
+
},
|
|
7006
|
+
{
|
|
7007
|
+
"name": "currentUsers",
|
|
7008
|
+
"type": {
|
|
7009
|
+
"option": "u32"
|
|
7010
|
+
}
|
|
6942
7011
|
}
|
|
6943
7012
|
]
|
|
6944
7013
|
}
|
|
@@ -7681,6 +7750,23 @@
|
|
|
7681
7750
|
]
|
|
7682
7751
|
}
|
|
7683
7752
|
},
|
|
7753
|
+
{
|
|
7754
|
+
"name": "SignedMsgWsDelegates",
|
|
7755
|
+
"docs": [
|
|
7756
|
+
"* Used to store authenticated delegates for swift-like ws connections"
|
|
7757
|
+
],
|
|
7758
|
+
"type": {
|
|
7759
|
+
"kind": "struct",
|
|
7760
|
+
"fields": [
|
|
7761
|
+
{
|
|
7762
|
+
"name": "delegates",
|
|
7763
|
+
"type": {
|
|
7764
|
+
"vec": "publicKey"
|
|
7765
|
+
}
|
|
7766
|
+
}
|
|
7767
|
+
]
|
|
7768
|
+
}
|
|
7769
|
+
},
|
|
7684
7770
|
{
|
|
7685
7771
|
"name": "SpotMarket",
|
|
7686
7772
|
"type": {
|
package/lib/node/math/orders.js
CHANGED
|
@@ -7,7 +7,7 @@ const anchor_1 = require("@coral-xyz/anchor");
|
|
|
7
7
|
const auction_1 = require("./auction");
|
|
8
8
|
const amm_1 = require("./amm");
|
|
9
9
|
function isOrderRiskIncreasing(user, order) {
|
|
10
|
-
if ((0, types_1.isVariant)(order.status, '
|
|
10
|
+
if (!(0, types_1.isVariant)(order.status, 'open')) {
|
|
11
11
|
return false;
|
|
12
12
|
}
|
|
13
13
|
const position = user.getPerpPosition(order.marketIndex) ||
|
|
@@ -34,7 +34,7 @@ function isOrderRiskIncreasing(user, order) {
|
|
|
34
34
|
}
|
|
35
35
|
exports.isOrderRiskIncreasing = isOrderRiskIncreasing;
|
|
36
36
|
function isOrderRiskIncreasingInSameDirection(user, order) {
|
|
37
|
-
if ((0, types_1.isVariant)(order.status, '
|
|
37
|
+
if (!(0, types_1.isVariant)(order.status, 'open')) {
|
|
38
38
|
return false;
|
|
39
39
|
}
|
|
40
40
|
const position = user.getPerpPosition(order.marketIndex) ||
|
|
@@ -56,7 +56,7 @@ function isOrderRiskIncreasingInSameDirection(user, order) {
|
|
|
56
56
|
}
|
|
57
57
|
exports.isOrderRiskIncreasingInSameDirection = isOrderRiskIncreasingInSameDirection;
|
|
58
58
|
function isOrderReduceOnly(user, order) {
|
|
59
|
-
if ((0, types_1.isVariant)(order.status, '
|
|
59
|
+
if (!(0, types_1.isVariant)(order.status, 'open')) {
|
|
60
60
|
return false;
|
|
61
61
|
}
|
|
62
62
|
const position = user.getPerpPosition(order.marketIndex) ||
|
package/lib/node/types.d.ts
CHANGED
|
@@ -264,6 +264,12 @@ export declare class OrderStatus {
|
|
|
264
264
|
static readonly OPEN: {
|
|
265
265
|
open: {};
|
|
266
266
|
};
|
|
267
|
+
static readonly FILLED: {
|
|
268
|
+
filled: {};
|
|
269
|
+
};
|
|
270
|
+
static readonly CANCELED: {
|
|
271
|
+
canceled: {};
|
|
272
|
+
};
|
|
267
273
|
}
|
|
268
274
|
export declare class OrderAction {
|
|
269
275
|
static readonly PLACE: {
|
package/lib/node/types.js
CHANGED
|
@@ -164,6 +164,8 @@ class OrderStatus {
|
|
|
164
164
|
exports.OrderStatus = OrderStatus;
|
|
165
165
|
OrderStatus.INIT = { init: {} };
|
|
166
166
|
OrderStatus.OPEN = { open: {} };
|
|
167
|
+
OrderStatus.FILLED = { filled: {} };
|
|
168
|
+
OrderStatus.CANCELED = { canceled: {} };
|
|
167
169
|
class OrderAction {
|
|
168
170
|
}
|
|
169
171
|
exports.OrderAction = OrderAction;
|
package/lib/node/user.js
CHANGED
package/package.json
CHANGED
package/src/addresses/pda.ts
CHANGED
|
@@ -98,6 +98,19 @@ export function getSignedMsgUserAccountPublicKey(
|
|
|
98
98
|
)[0];
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
export function getSignedMsgWsDelegatesAccountPublicKey(
|
|
102
|
+
programId: PublicKey,
|
|
103
|
+
authority: PublicKey
|
|
104
|
+
): PublicKey {
|
|
105
|
+
return PublicKey.findProgramAddressSync(
|
|
106
|
+
[
|
|
107
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('SIGNED_MSG_WS')),
|
|
108
|
+
authority.toBuffer(),
|
|
109
|
+
],
|
|
110
|
+
programId
|
|
111
|
+
)[0];
|
|
112
|
+
}
|
|
113
|
+
|
|
101
114
|
export async function getPerpMarketPublicKey(
|
|
102
115
|
programId: PublicKey,
|
|
103
116
|
marketIndex: number
|
package/src/decode/user.ts
CHANGED
|
@@ -139,7 +139,7 @@ export function decodeUser(buffer: Buffer): UserAccount {
|
|
|
139
139
|
const orders: Order[] = [];
|
|
140
140
|
for (let i = 0; i < 32; i++) {
|
|
141
141
|
// skip order if it's not open
|
|
142
|
-
if (buffer.readUint8(offset + 82)
|
|
142
|
+
if (buffer.readUint8(offset + 82) !== 1) {
|
|
143
143
|
offset += 96;
|
|
144
144
|
continue;
|
|
145
145
|
}
|
package/src/dlob/DLOB.ts
CHANGED
|
@@ -188,7 +188,7 @@ export class DLOB {
|
|
|
188
188
|
isUserProtectedMaker: boolean,
|
|
189
189
|
onInsert?: OrderBookCallback
|
|
190
190
|
): void {
|
|
191
|
-
if (isVariant(order.status, '
|
|
191
|
+
if (!isVariant(order.status, 'open')) {
|
|
192
192
|
return;
|
|
193
193
|
}
|
|
194
194
|
|
|
@@ -290,7 +290,7 @@ export class DLOB {
|
|
|
290
290
|
isUserProtectedMaker: boolean,
|
|
291
291
|
onDelete?: OrderBookCallback
|
|
292
292
|
): void {
|
|
293
|
-
if (isVariant(order.status, '
|
|
293
|
+
if (!isVariant(order.status, 'open')) {
|
|
294
294
|
return;
|
|
295
295
|
}
|
|
296
296
|
|
package/src/dlob/NodeList.ts
CHANGED
package/src/driftClient.ts
CHANGED
|
@@ -102,6 +102,7 @@ import {
|
|
|
102
102
|
getUserAccountPublicKey,
|
|
103
103
|
getUserAccountPublicKeySync,
|
|
104
104
|
getUserStatsAccountPublicKey,
|
|
105
|
+
getSignedMsgWsDelegatesAccountPublicKey,
|
|
105
106
|
} from './addresses/pda';
|
|
106
107
|
import {
|
|
107
108
|
DataAndSlot,
|
|
@@ -1156,6 +1157,108 @@ export class DriftClient {
|
|
|
1156
1157
|
return resizeUserAccountIx;
|
|
1157
1158
|
}
|
|
1158
1159
|
|
|
1160
|
+
public async initializeSignedMsgWsDelegatesAccount(
|
|
1161
|
+
authority: PublicKey,
|
|
1162
|
+
delegates: PublicKey[] = [],
|
|
1163
|
+
txParams?: TxParams
|
|
1164
|
+
): Promise<TransactionSignature> {
|
|
1165
|
+
const ix = await this.getInitializeSignedMsgWsDelegatesAccountIx(
|
|
1166
|
+
authority,
|
|
1167
|
+
delegates
|
|
1168
|
+
);
|
|
1169
|
+
const tx = await this.buildTransaction([ix], txParams);
|
|
1170
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
1171
|
+
return txSig;
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
public async getInitializeSignedMsgWsDelegatesAccountIx(
|
|
1175
|
+
authority: PublicKey,
|
|
1176
|
+
delegates: PublicKey[] = []
|
|
1177
|
+
): Promise<TransactionInstruction> {
|
|
1178
|
+
const signedMsgWsDelegates = getSignedMsgWsDelegatesAccountPublicKey(
|
|
1179
|
+
this.program.programId,
|
|
1180
|
+
authority
|
|
1181
|
+
);
|
|
1182
|
+
const ix = await this.program.instruction.initializeSignedMsgWsDelegates(
|
|
1183
|
+
delegates,
|
|
1184
|
+
{
|
|
1185
|
+
accounts: {
|
|
1186
|
+
signedMsgWsDelegates,
|
|
1187
|
+
authority: this.wallet.publicKey,
|
|
1188
|
+
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
|
|
1189
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
1190
|
+
},
|
|
1191
|
+
}
|
|
1192
|
+
);
|
|
1193
|
+
return ix;
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
public async addSignedMsgWsDelegate(
|
|
1197
|
+
authority: PublicKey,
|
|
1198
|
+
delegate: PublicKey,
|
|
1199
|
+
txParams?: TxParams
|
|
1200
|
+
): Promise<TransactionSignature> {
|
|
1201
|
+
const ix = await this.getAddSignedMsgWsDelegateIx(authority, delegate);
|
|
1202
|
+
const tx = await this.buildTransaction([ix], txParams);
|
|
1203
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
1204
|
+
return txSig;
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
public async getAddSignedMsgWsDelegateIx(
|
|
1208
|
+
authority: PublicKey,
|
|
1209
|
+
delegate: PublicKey
|
|
1210
|
+
): Promise<TransactionInstruction> {
|
|
1211
|
+
const signedMsgWsDelegates = getSignedMsgWsDelegatesAccountPublicKey(
|
|
1212
|
+
this.program.programId,
|
|
1213
|
+
authority
|
|
1214
|
+
);
|
|
1215
|
+
const ix = await this.program.instruction.changeSignedMsgWsDelegateStatus(
|
|
1216
|
+
delegate,
|
|
1217
|
+
true,
|
|
1218
|
+
{
|
|
1219
|
+
accounts: {
|
|
1220
|
+
signedMsgWsDelegates,
|
|
1221
|
+
authority: this.wallet.publicKey,
|
|
1222
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
1223
|
+
},
|
|
1224
|
+
}
|
|
1225
|
+
);
|
|
1226
|
+
return ix;
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
public async removeSignedMsgWsDelegate(
|
|
1230
|
+
authority: PublicKey,
|
|
1231
|
+
delegate: PublicKey,
|
|
1232
|
+
txParams?: TxParams
|
|
1233
|
+
): Promise<TransactionSignature> {
|
|
1234
|
+
const ix = await this.getRemoveSignedMsgWsDelegateIx(authority, delegate);
|
|
1235
|
+
const tx = await this.buildTransaction([ix], txParams);
|
|
1236
|
+
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
1237
|
+
return txSig;
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
public async getRemoveSignedMsgWsDelegateIx(
|
|
1241
|
+
authority: PublicKey,
|
|
1242
|
+
delegate: PublicKey
|
|
1243
|
+
): Promise<TransactionInstruction> {
|
|
1244
|
+
const signedMsgWsDelegates = getSignedMsgWsDelegatesAccountPublicKey(
|
|
1245
|
+
this.program.programId,
|
|
1246
|
+
authority
|
|
1247
|
+
);
|
|
1248
|
+
const ix = await this.program.instruction.changeSignedMsgWsDelegateStatus(
|
|
1249
|
+
delegate,
|
|
1250
|
+
false,
|
|
1251
|
+
{
|
|
1252
|
+
accounts: {
|
|
1253
|
+
signedMsgWsDelegates,
|
|
1254
|
+
authority: this.wallet.publicKey,
|
|
1255
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
1256
|
+
},
|
|
1257
|
+
}
|
|
1258
|
+
);
|
|
1259
|
+
return ix;
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1159
1262
|
public async initializeFuelOverflow(
|
|
1160
1263
|
authority?: PublicKey
|
|
1161
1264
|
): Promise<TransactionSignature> {
|
package/src/idl/drift.json
CHANGED
|
@@ -155,6 +155,69 @@
|
|
|
155
155
|
}
|
|
156
156
|
]
|
|
157
157
|
},
|
|
158
|
+
{
|
|
159
|
+
"name": "initializeSignedMsgWsDelegates",
|
|
160
|
+
"accounts": [
|
|
161
|
+
{
|
|
162
|
+
"name": "signedMsgWsDelegates",
|
|
163
|
+
"isMut": true,
|
|
164
|
+
"isSigner": false
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
"name": "authority",
|
|
168
|
+
"isMut": true,
|
|
169
|
+
"isSigner": true
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
"name": "rent",
|
|
173
|
+
"isMut": false,
|
|
174
|
+
"isSigner": false
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
"name": "systemProgram",
|
|
178
|
+
"isMut": false,
|
|
179
|
+
"isSigner": false
|
|
180
|
+
}
|
|
181
|
+
],
|
|
182
|
+
"args": [
|
|
183
|
+
{
|
|
184
|
+
"name": "delegates",
|
|
185
|
+
"type": {
|
|
186
|
+
"vec": "publicKey"
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
]
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
"name": "changeSignedMsgWsDelegateStatus",
|
|
193
|
+
"accounts": [
|
|
194
|
+
{
|
|
195
|
+
"name": "signedMsgWsDelegates",
|
|
196
|
+
"isMut": true,
|
|
197
|
+
"isSigner": false
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
"name": "authority",
|
|
201
|
+
"isMut": true,
|
|
202
|
+
"isSigner": true
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
"name": "systemProgram",
|
|
206
|
+
"isMut": false,
|
|
207
|
+
"isSigner": false
|
|
208
|
+
}
|
|
209
|
+
],
|
|
210
|
+
"args": [
|
|
211
|
+
{
|
|
212
|
+
"name": "delegate",
|
|
213
|
+
"type": "publicKey"
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
"name": "add",
|
|
217
|
+
"type": "bool"
|
|
218
|
+
}
|
|
219
|
+
]
|
|
220
|
+
},
|
|
158
221
|
{
|
|
159
222
|
"name": "initializeFuelOverflow",
|
|
160
223
|
"accounts": [
|
|
@@ -6939,6 +7002,12 @@
|
|
|
6939
7002
|
{
|
|
6940
7003
|
"name": "reduceOnly",
|
|
6941
7004
|
"type": "bool"
|
|
7005
|
+
},
|
|
7006
|
+
{
|
|
7007
|
+
"name": "currentUsers",
|
|
7008
|
+
"type": {
|
|
7009
|
+
"option": "u32"
|
|
7010
|
+
}
|
|
6942
7011
|
}
|
|
6943
7012
|
]
|
|
6944
7013
|
}
|
|
@@ -7681,6 +7750,23 @@
|
|
|
7681
7750
|
]
|
|
7682
7751
|
}
|
|
7683
7752
|
},
|
|
7753
|
+
{
|
|
7754
|
+
"name": "SignedMsgWsDelegates",
|
|
7755
|
+
"docs": [
|
|
7756
|
+
"* Used to store authenticated delegates for swift-like ws connections"
|
|
7757
|
+
],
|
|
7758
|
+
"type": {
|
|
7759
|
+
"kind": "struct",
|
|
7760
|
+
"fields": [
|
|
7761
|
+
{
|
|
7762
|
+
"name": "delegates",
|
|
7763
|
+
"type": {
|
|
7764
|
+
"vec": "publicKey"
|
|
7765
|
+
}
|
|
7766
|
+
}
|
|
7767
|
+
]
|
|
7768
|
+
}
|
|
7769
|
+
},
|
|
7684
7770
|
{
|
|
7685
7771
|
"name": "SpotMarket",
|
|
7686
7772
|
"type": {
|
package/src/math/orders.ts
CHANGED
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
} from './amm';
|
|
23
23
|
|
|
24
24
|
export function isOrderRiskIncreasing(user: User, order: Order): boolean {
|
|
25
|
-
if (isVariant(order.status, '
|
|
25
|
+
if (!isVariant(order.status, 'open')) {
|
|
26
26
|
return false;
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -63,7 +63,7 @@ export function isOrderRiskIncreasingInSameDirection(
|
|
|
63
63
|
user: User,
|
|
64
64
|
order: Order
|
|
65
65
|
): boolean {
|
|
66
|
-
if (isVariant(order.status, '
|
|
66
|
+
if (!isVariant(order.status, 'open')) {
|
|
67
67
|
return false;
|
|
68
68
|
}
|
|
69
69
|
|
|
@@ -93,7 +93,7 @@ export function isOrderRiskIncreasingInSameDirection(
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
export function isOrderReduceOnly(user: User, order: Order): boolean {
|
|
96
|
-
if (isVariant(order.status, '
|
|
96
|
+
if (!isVariant(order.status, 'open')) {
|
|
97
97
|
return false;
|
|
98
98
|
}
|
|
99
99
|
|
package/src/types.ts
CHANGED
|
@@ -174,6 +174,8 @@ export class MarketType {
|
|
|
174
174
|
export class OrderStatus {
|
|
175
175
|
static readonly INIT = { init: {} };
|
|
176
176
|
static readonly OPEN = { open: {} };
|
|
177
|
+
static readonly FILLED = { filled: {} };
|
|
178
|
+
static readonly CANCELED = { canceled: {} };
|
|
177
179
|
}
|
|
178
180
|
|
|
179
181
|
export class OrderAction {
|