@drift-labs/sdk 0.2.0-master.1 → 0.2.0-master.12
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/accounts/types.d.ts +1 -0
- package/lib/admin.d.ts +8 -5
- package/lib/admin.js +43 -11
- package/lib/clearingHouse.d.ts +35 -20
- package/lib/clearingHouse.js +497 -154
- package/lib/clearingHouseUser.d.ts +12 -17
- package/lib/clearingHouseUser.js +97 -88
- package/lib/config.js +1 -1
- package/lib/constants/banks.d.ts +2 -2
- package/lib/constants/banks.js +12 -4
- package/lib/constants/numericConstants.d.ts +4 -0
- package/lib/constants/numericConstants.js +5 -1
- package/lib/events/eventList.js +3 -0
- package/lib/events/types.d.ts +2 -1
- package/lib/factory/bigNum.d.ts +9 -2
- package/lib/factory/bigNum.js +50 -16
- package/lib/idl/clearing_house.json +858 -177
- package/lib/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
- package/lib/index.d.ts +4 -2
- package/lib/index.js +8 -2
- package/lib/math/amm.d.ts +6 -1
- package/lib/math/amm.js +124 -41
- package/lib/math/auction.js +4 -1
- package/lib/math/bankBalance.d.ts +3 -1
- package/lib/math/bankBalance.js +54 -1
- package/lib/math/margin.d.ts +11 -0
- package/lib/math/margin.js +72 -0
- package/lib/math/market.d.ts +4 -1
- package/lib/math/market.js +35 -1
- package/lib/math/orders.d.ts +2 -2
- package/lib/math/orders.js +18 -11
- package/lib/math/position.d.ts +8 -0
- package/lib/math/position.js +44 -12
- package/lib/math/repeg.js +1 -1
- package/lib/math/trade.d.ts +1 -1
- package/lib/math/trade.js +7 -10
- package/lib/orderParams.d.ts +14 -5
- package/lib/orderParams.js +8 -96
- package/lib/orders.d.ts +2 -4
- package/lib/orders.js +7 -161
- package/lib/slot/SlotSubscriber.d.ts +7 -0
- package/lib/slot/SlotSubscriber.js +3 -0
- package/lib/{mockUSDCFaucet.d.ts → tokenFaucet.d.ts} +8 -5
- package/lib/{mockUSDCFaucet.js → tokenFaucet.js} +63 -51
- package/lib/tx/retryTxSender.js +9 -2
- package/lib/tx/utils.js +1 -1
- package/lib/types.d.ts +159 -15
- package/lib/types.js +59 -1
- package/lib/util/computeUnits.js +1 -1
- package/lib/util/getTokenAddress.d.ts +2 -0
- package/lib/util/getTokenAddress.js +9 -0
- package/package.json +3 -3
- package/src/accounts/bulkAccountLoader.js +197 -0
- package/src/accounts/bulkUserSubscription.js +33 -0
- package/src/accounts/pollingClearingHouseAccountSubscriber.js +311 -0
- package/src/accounts/pollingOracleSubscriber.js +93 -0
- package/src/accounts/pollingTokenAccountSubscriber.js +90 -0
- package/src/accounts/pollingUserAccountSubscriber.js +132 -0
- package/src/accounts/types.js +10 -0
- package/src/accounts/utils.js +7 -0
- package/src/accounts/webSocketAccountSubscriber.js +93 -0
- package/src/accounts/webSocketClearingHouseAccountSubscriber.js +233 -0
- package/src/accounts/webSocketUserAccountSubscriber.js +62 -0
- package/src/addresses/marketAddresses.js +26 -0
- package/src/admin.ts +66 -14
- package/src/assert/assert.js +9 -0
- package/src/clearingHouse.ts +836 -254
- package/src/clearingHouseConfig.js +2 -0
- package/src/clearingHouseUser.ts +219 -121
- package/src/clearingHouseUserConfig.js +2 -0
- package/src/config.ts +1 -1
- package/src/constants/banks.js +42 -0
- package/src/constants/banks.ts +14 -4
- package/src/constants/markets.js +42 -0
- package/src/constants/numericConstants.js +41 -0
- package/src/constants/numericConstants.ts +5 -0
- package/src/events/eventList.js +77 -0
- package/src/events/eventList.ts +3 -0
- package/src/events/eventSubscriber.js +139 -0
- package/src/events/fetchLogs.js +50 -0
- package/src/events/pollingLogProvider.js +64 -0
- package/src/events/sort.js +44 -0
- package/src/events/txEventCache.js +71 -0
- package/src/events/types.js +20 -0
- package/src/events/types.ts +2 -0
- package/src/events/webSocketLogProvider.js +41 -0
- package/src/examples/makeTradeExample.js +80 -0
- package/src/factory/bigNum.js +390 -0
- package/src/factory/bigNum.ts +65 -18
- package/src/factory/oracleClient.js +20 -0
- package/src/idl/clearing_house.json +858 -177
- package/src/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
- package/src/index.js +69 -0
- package/src/index.ts +4 -2
- package/src/math/amm.js +369 -0
- package/src/math/amm.ts +207 -52
- package/src/math/auction.js +42 -0
- package/src/math/auction.ts +5 -1
- package/src/math/bankBalance.ts +98 -1
- package/src/math/conversion.js +11 -0
- package/src/math/funding.js +248 -0
- package/src/math/margin.ts +124 -0
- package/src/math/market.ts +66 -1
- package/src/math/oracles.js +26 -0
- package/src/math/orders.ts +17 -13
- package/src/math/position.ts +63 -9
- package/src/math/repeg.js +128 -0
- package/src/math/repeg.ts +2 -1
- package/src/math/state.js +15 -0
- package/src/math/trade.js +253 -0
- package/src/math/trade.ts +23 -25
- package/src/math/utils.js +0 -1
- package/src/mockUSDCFaucet.js +280 -0
- package/src/oracles/oracleClientCache.js +19 -0
- package/src/oracles/pythClient.js +46 -0
- package/src/oracles/quoteAssetOracleClient.js +32 -0
- package/src/oracles/switchboardClient.js +69 -0
- package/src/oracles/types.js +2 -0
- package/src/orderParams.js +20 -0
- package/src/orderParams.ts +20 -141
- package/src/orders.ts +10 -287
- package/src/slot/SlotSubscriber.js +39 -0
- package/src/slot/SlotSubscriber.ts +11 -1
- package/src/token/index.js +38 -0
- package/src/tokenFaucet.js +189 -0
- package/src/{mockUSDCFaucet.ts → tokenFaucet.ts} +82 -70
- package/src/tx/retryTxSender.ts +11 -3
- package/src/tx/types.js +2 -0
- package/src/tx/utils.js +17 -0
- package/src/tx/utils.ts +1 -1
- package/src/types.js +125 -0
- package/src/types.ts +155 -17
- package/src/userName.js +20 -0
- package/src/util/computeUnits.js +21 -11
- package/src/util/computeUnits.ts +1 -1
- package/src/util/getTokenAddress.js +9 -0
- package/src/util/getTokenAddress.ts +18 -0
- package/src/util/promiseTimeout.js +14 -0
- package/src/util/tps.js +27 -0
- package/src/wallet.js +35 -0
- package/tests/bn/test.ts +2 -0
- package/src/util/computeUnits.js.map +0 -1
|
@@ -3,7 +3,6 @@ import { AnchorProvider, Idl, Program } from '@project-serum/anchor';
|
|
|
3
3
|
import {
|
|
4
4
|
AccountInfo,
|
|
5
5
|
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
6
|
-
MintLayout,
|
|
7
6
|
Token,
|
|
8
7
|
TOKEN_PROGRAM_ID,
|
|
9
8
|
} from '@solana/spl-token';
|
|
@@ -11,27 +10,28 @@ import {
|
|
|
11
10
|
ConfirmOptions,
|
|
12
11
|
Connection,
|
|
13
12
|
PublicKey,
|
|
14
|
-
SystemProgram,
|
|
15
13
|
SYSVAR_RENT_PUBKEY,
|
|
16
14
|
Transaction,
|
|
17
15
|
TransactionInstruction,
|
|
18
16
|
TransactionSignature,
|
|
19
17
|
} from '@solana/web3.js';
|
|
20
18
|
import { BN } from '.';
|
|
21
|
-
import
|
|
19
|
+
import tokenFaucet from './idl/token_faucet.json';
|
|
22
20
|
import { IWallet } from './types';
|
|
23
21
|
|
|
24
|
-
export class
|
|
22
|
+
export class TokenFaucet {
|
|
25
23
|
connection: Connection;
|
|
26
24
|
wallet: IWallet;
|
|
27
25
|
public program: Program;
|
|
28
26
|
provider: AnchorProvider;
|
|
27
|
+
mint: PublicKey;
|
|
29
28
|
opts?: ConfirmOptions;
|
|
30
29
|
|
|
31
30
|
public constructor(
|
|
32
31
|
connection: Connection,
|
|
33
32
|
wallet: IWallet,
|
|
34
33
|
programId: PublicKey,
|
|
34
|
+
mint: PublicKey,
|
|
35
35
|
opts?: ConfirmOptions
|
|
36
36
|
) {
|
|
37
37
|
this.connection = connection;
|
|
@@ -39,93 +39,92 @@ export class MockUSDCFaucet {
|
|
|
39
39
|
this.opts = opts || AnchorProvider.defaultOptions();
|
|
40
40
|
const provider = new AnchorProvider(connection, wallet, this.opts);
|
|
41
41
|
this.provider = provider;
|
|
42
|
-
this.program = new Program(
|
|
42
|
+
this.program = new Program(tokenFaucet as Idl, programId, provider);
|
|
43
|
+
this.mint = mint;
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
public async
|
|
46
|
+
public async getFaucetConfigPublicKeyAndNonce(): Promise<
|
|
46
47
|
[PublicKey, number]
|
|
47
48
|
> {
|
|
48
49
|
return anchor.web3.PublicKey.findProgramAddress(
|
|
49
|
-
[
|
|
50
|
+
[
|
|
51
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('faucet_config')),
|
|
52
|
+
this.mint.toBuffer(),
|
|
53
|
+
],
|
|
50
54
|
this.program.programId
|
|
51
55
|
);
|
|
52
56
|
}
|
|
53
57
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
public async getMintAuthority(): Promise<PublicKey> {
|
|
59
|
+
return (
|
|
60
|
+
await anchor.web3.PublicKey.findProgramAddress(
|
|
61
|
+
[
|
|
62
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('mint_authority')),
|
|
63
|
+
this.mint.toBuffer(),
|
|
64
|
+
],
|
|
65
|
+
this.program.programId
|
|
66
|
+
)
|
|
61
67
|
)[0];
|
|
62
|
-
return this.mockUSDCFaucetStatePublicKey;
|
|
63
68
|
}
|
|
64
69
|
|
|
65
|
-
public async
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
);
|
|
69
|
-
if (stateAccountRPCResponse.value !== null) {
|
|
70
|
-
throw new Error('Faucet already initialized');
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const fakeUSDCMint = anchor.web3.Keypair.generate();
|
|
74
|
-
const createUSDCMintAccountIx = SystemProgram.createAccount({
|
|
75
|
-
fromPubkey: this.wallet.publicKey,
|
|
76
|
-
newAccountPubkey: fakeUSDCMint.publicKey,
|
|
77
|
-
lamports: await Token.getMinBalanceRentForExemptMint(this.connection),
|
|
78
|
-
space: MintLayout.span,
|
|
79
|
-
programId: TOKEN_PROGRAM_ID,
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
const [mintAuthority, _mintAuthorityNonce] =
|
|
83
|
-
await PublicKey.findProgramAddress(
|
|
84
|
-
[fakeUSDCMint.publicKey.toBuffer()],
|
|
85
|
-
this.program.programId
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
const initUSDCMintIx = Token.createInitMintInstruction(
|
|
89
|
-
TOKEN_PROGRAM_ID,
|
|
90
|
-
fakeUSDCMint.publicKey,
|
|
91
|
-
6,
|
|
92
|
-
mintAuthority,
|
|
93
|
-
null
|
|
94
|
-
);
|
|
70
|
+
public async getFaucetConfigPublicKey(): Promise<PublicKey> {
|
|
71
|
+
return (await this.getFaucetConfigPublicKeyAndNonce())[0];
|
|
72
|
+
}
|
|
95
73
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
74
|
+
public async initialize(): Promise<TransactionSignature> {
|
|
75
|
+
const [faucetConfigPublicKey] =
|
|
76
|
+
await this.getFaucetConfigPublicKeyAndNonce();
|
|
77
|
+
return await this.program.rpc.initialize({
|
|
99
78
|
accounts: {
|
|
100
|
-
|
|
79
|
+
faucetConfig: faucetConfigPublicKey,
|
|
101
80
|
admin: this.wallet.publicKey,
|
|
102
|
-
mintAccount:
|
|
81
|
+
mintAccount: this.mint,
|
|
103
82
|
rent: SYSVAR_RENT_PUBKEY,
|
|
104
83
|
systemProgram: anchor.web3.SystemProgram.programId,
|
|
84
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
105
85
|
},
|
|
106
|
-
instructions: [createUSDCMintAccountIx, initUSDCMintIx],
|
|
107
|
-
signers: [fakeUSDCMint],
|
|
108
86
|
});
|
|
109
87
|
}
|
|
110
88
|
|
|
111
89
|
public async fetchState(): Promise<any> {
|
|
112
|
-
return await this.program.account.
|
|
113
|
-
await this.
|
|
90
|
+
return await this.program.account.faucetConfig.fetch(
|
|
91
|
+
await this.getFaucetConfigPublicKey()
|
|
114
92
|
);
|
|
115
93
|
}
|
|
116
94
|
|
|
95
|
+
private async mintToUserIx(userTokenAccount: PublicKey, amount: BN) {
|
|
96
|
+
return this.program.instruction.mintToUser(amount, {
|
|
97
|
+
accounts: {
|
|
98
|
+
faucetConfig: await this.getFaucetConfigPublicKey(),
|
|
99
|
+
mintAccount: this.mint,
|
|
100
|
+
userTokenAccount,
|
|
101
|
+
mintAuthority: await this.getMintAuthority(),
|
|
102
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
117
107
|
public async mintToUser(
|
|
118
108
|
userTokenAccount: PublicKey,
|
|
119
109
|
amount: BN
|
|
120
110
|
): Promise<TransactionSignature> {
|
|
121
|
-
const
|
|
122
|
-
|
|
111
|
+
const mintIx = await this.mintToUserIx(userTokenAccount, amount);
|
|
112
|
+
|
|
113
|
+
const tx = new Transaction().add(mintIx);
|
|
114
|
+
|
|
115
|
+
const txSig = await this.program.provider.sendAndConfirm(tx, [], this.opts);
|
|
116
|
+
|
|
117
|
+
return txSig;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
public async transferMintAuthority(): Promise<TransactionSignature> {
|
|
121
|
+
return await this.program.rpc.transferMintAuthority({
|
|
123
122
|
accounts: {
|
|
124
|
-
|
|
125
|
-
mintAccount:
|
|
126
|
-
|
|
127
|
-
mintAuthority: state.mintAuthority,
|
|
123
|
+
faucetConfig: await this.getFaucetConfigPublicKey(),
|
|
124
|
+
mintAccount: this.mint,
|
|
125
|
+
mintAuthority: await this.getMintAuthority(),
|
|
128
126
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
127
|
+
admin: this.wallet.publicKey,
|
|
129
128
|
},
|
|
130
129
|
});
|
|
131
130
|
}
|
|
@@ -134,12 +133,33 @@ export class MockUSDCFaucet {
|
|
|
134
133
|
userPublicKey: PublicKey,
|
|
135
134
|
amount: BN
|
|
136
135
|
): Promise<[PublicKey, TransactionSignature]> {
|
|
136
|
+
const tx = new Transaction();
|
|
137
|
+
|
|
137
138
|
const [associatedTokenPublicKey, createAssociatedAccountIx, mintToTx] =
|
|
138
139
|
await this.createAssociatedTokenAccountAndMintToInstructions(
|
|
139
140
|
userPublicKey,
|
|
140
141
|
amount
|
|
141
142
|
);
|
|
142
|
-
|
|
143
|
+
|
|
144
|
+
let associatedTokenAccountExists = false;
|
|
145
|
+
|
|
146
|
+
try {
|
|
147
|
+
const assosciatedTokenAccount = await this.connection.getAccountInfo(
|
|
148
|
+
associatedTokenPublicKey
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
associatedTokenAccountExists = !!assosciatedTokenAccount;
|
|
152
|
+
} catch (e) {
|
|
153
|
+
// token account doesn't exist
|
|
154
|
+
associatedTokenAccountExists = false;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const skipAccountCreation = associatedTokenAccountExists;
|
|
158
|
+
|
|
159
|
+
if (!skipAccountCreation) tx.add(createAssociatedAccountIx);
|
|
160
|
+
|
|
161
|
+
tx.add(mintToTx);
|
|
162
|
+
|
|
143
163
|
const txSig = await this.program.provider.sendAndConfirm(tx, [], this.opts);
|
|
144
164
|
return [associatedTokenPublicKey, txSig];
|
|
145
165
|
}
|
|
@@ -164,15 +184,7 @@ export class MockUSDCFaucet {
|
|
|
164
184
|
this.wallet.publicKey
|
|
165
185
|
);
|
|
166
186
|
|
|
167
|
-
const mintToIx = await this.
|
|
168
|
-
accounts: {
|
|
169
|
-
mockUsdcFaucetState: await this.getMockUSDCFaucetStatePublicKey(),
|
|
170
|
-
mintAccount: state.mint,
|
|
171
|
-
userTokenAccount: associateTokenPublicKey,
|
|
172
|
-
mintAuthority: state.mintAuthority,
|
|
173
|
-
tokenProgram: TOKEN_PROGRAM_ID,
|
|
174
|
-
},
|
|
175
|
-
});
|
|
187
|
+
const mintToIx = await this.mintToUserIx(associateTokenPublicKey, amount);
|
|
176
188
|
|
|
177
189
|
return [associateTokenPublicKey, createAssociatedAccountIx, mintToIx];
|
|
178
190
|
}
|
package/src/tx/retryTxSender.ts
CHANGED
|
@@ -56,9 +56,17 @@ export class RetryTxSender implements TxSender {
|
|
|
56
56
|
const rawTransaction = tx.serialize();
|
|
57
57
|
const startTime = this.getTimestamp();
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
let txid: TransactionSignature;
|
|
60
|
+
try {
|
|
61
|
+
txid = await this.provider.connection.sendRawTransaction(
|
|
62
|
+
rawTransaction,
|
|
63
|
+
opts
|
|
64
|
+
);
|
|
65
|
+
this.sendToAdditionalConnections(rawTransaction, opts);
|
|
66
|
+
} catch (e) {
|
|
67
|
+
console.error(e);
|
|
68
|
+
throw e;
|
|
69
|
+
}
|
|
62
70
|
|
|
63
71
|
let done = false;
|
|
64
72
|
const resolveReference: ResolveReference = {
|
package/src/tx/types.js
ADDED
package/src/tx/utils.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wrapInTx = void 0;
|
|
4
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
const COMPUTE_UNITS_DEFAULT = 200000;
|
|
6
|
+
function wrapInTx(instruction, computeUnits = 600000 // TODO, requires less code change
|
|
7
|
+
) {
|
|
8
|
+
const tx = new web3_js_1.Transaction();
|
|
9
|
+
if (computeUnits != COMPUTE_UNITS_DEFAULT) {
|
|
10
|
+
tx.add(web3_js_1.ComputeBudgetProgram.requestUnits({
|
|
11
|
+
units: computeUnits,
|
|
12
|
+
additionalFee: 0,
|
|
13
|
+
}));
|
|
14
|
+
}
|
|
15
|
+
return tx.add(instruction);
|
|
16
|
+
}
|
|
17
|
+
exports.wrapInTx = wrapInTx;
|
package/src/tx/utils.ts
CHANGED
|
@@ -8,7 +8,7 @@ const COMPUTE_UNITS_DEFAULT = 200_000;
|
|
|
8
8
|
|
|
9
9
|
export function wrapInTx(
|
|
10
10
|
instruction: TransactionInstruction,
|
|
11
|
-
computeUnits =
|
|
11
|
+
computeUnits = 600_000 // TODO, requires less code change
|
|
12
12
|
): Transaction {
|
|
13
13
|
const tx = new Transaction();
|
|
14
14
|
if (computeUnits != COMPUTE_UNITS_DEFAULT) {
|
package/src/types.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DefaultOrderParams = exports.LiquidationType = exports.TradeSide = exports.isOneOfVariant = exports.isVariant = exports.OrderTriggerCondition = exports.OrderActionExplanation = exports.OrderAction = exports.OrderDiscountTier = exports.OrderStatus = exports.OrderType = exports.OracleSource = exports.DepositDirection = exports.PositionDirection = exports.BankBalanceType = exports.SwapDirection = void 0;
|
|
4
|
+
const _1 = require(".");
|
|
5
|
+
// # Utility Types / Enums / Constants
|
|
6
|
+
class SwapDirection {
|
|
7
|
+
}
|
|
8
|
+
exports.SwapDirection = SwapDirection;
|
|
9
|
+
SwapDirection.ADD = { add: {} };
|
|
10
|
+
SwapDirection.REMOVE = { remove: {} };
|
|
11
|
+
class BankBalanceType {
|
|
12
|
+
}
|
|
13
|
+
exports.BankBalanceType = BankBalanceType;
|
|
14
|
+
BankBalanceType.DEPOSIT = { deposit: {} };
|
|
15
|
+
BankBalanceType.BORROW = { borrow: {} };
|
|
16
|
+
class PositionDirection {
|
|
17
|
+
}
|
|
18
|
+
exports.PositionDirection = PositionDirection;
|
|
19
|
+
PositionDirection.LONG = { long: {} };
|
|
20
|
+
PositionDirection.SHORT = { short: {} };
|
|
21
|
+
class DepositDirection {
|
|
22
|
+
}
|
|
23
|
+
exports.DepositDirection = DepositDirection;
|
|
24
|
+
DepositDirection.DEPOSIT = { deposit: {} };
|
|
25
|
+
DepositDirection.WITHDRAW = { withdraw: {} };
|
|
26
|
+
class OracleSource {
|
|
27
|
+
}
|
|
28
|
+
exports.OracleSource = OracleSource;
|
|
29
|
+
OracleSource.PYTH = { pyth: {} };
|
|
30
|
+
OracleSource.SWITCHBOARD = { switchboard: {} };
|
|
31
|
+
OracleSource.QUOTE_ASSET = { quoteAsset: {} };
|
|
32
|
+
class OrderType {
|
|
33
|
+
}
|
|
34
|
+
exports.OrderType = OrderType;
|
|
35
|
+
OrderType.LIMIT = { limit: {} };
|
|
36
|
+
OrderType.TRIGGER_MARKET = { triggerMarket: {} };
|
|
37
|
+
OrderType.TRIGGER_LIMIT = { triggerLimit: {} };
|
|
38
|
+
OrderType.MARKET = { market: {} };
|
|
39
|
+
class OrderStatus {
|
|
40
|
+
}
|
|
41
|
+
exports.OrderStatus = OrderStatus;
|
|
42
|
+
OrderStatus.INIT = { init: {} };
|
|
43
|
+
OrderStatus.OPEN = { open: {} };
|
|
44
|
+
class OrderDiscountTier {
|
|
45
|
+
}
|
|
46
|
+
exports.OrderDiscountTier = OrderDiscountTier;
|
|
47
|
+
OrderDiscountTier.NONE = { none: {} };
|
|
48
|
+
OrderDiscountTier.FIRST = { first: {} };
|
|
49
|
+
OrderDiscountTier.SECOND = { second: {} };
|
|
50
|
+
OrderDiscountTier.THIRD = { third: {} };
|
|
51
|
+
OrderDiscountTier.FOURTH = { fourth: {} };
|
|
52
|
+
class OrderAction {
|
|
53
|
+
}
|
|
54
|
+
exports.OrderAction = OrderAction;
|
|
55
|
+
OrderAction.PLACE = { place: {} };
|
|
56
|
+
OrderAction.CANCEL = { cancel: {} };
|
|
57
|
+
OrderAction.EXPIRE = { expire: {} };
|
|
58
|
+
OrderAction.FILL = { fill: {} };
|
|
59
|
+
OrderAction.TRIGGER = { trigger: {} };
|
|
60
|
+
class OrderActionExplanation {
|
|
61
|
+
}
|
|
62
|
+
exports.OrderActionExplanation = OrderActionExplanation;
|
|
63
|
+
OrderActionExplanation.NONE = { none: {} };
|
|
64
|
+
OrderActionExplanation.BREACHED_MARGIN_REQUIREMENT = {
|
|
65
|
+
breachedMarginRequirement: {},
|
|
66
|
+
};
|
|
67
|
+
OrderActionExplanation.ORACLE_PRICE_BREACHED_LIMIT_PRICE = {
|
|
68
|
+
oraclePriceBreachedLimitPrice: {},
|
|
69
|
+
};
|
|
70
|
+
OrderActionExplanation.MARKET_ORDER_FILLED_TO_LIMIT_PRICE = {
|
|
71
|
+
marketOrderFilledToLimitPrice: {},
|
|
72
|
+
};
|
|
73
|
+
class OrderTriggerCondition {
|
|
74
|
+
}
|
|
75
|
+
exports.OrderTriggerCondition = OrderTriggerCondition;
|
|
76
|
+
OrderTriggerCondition.ABOVE = { above: {} };
|
|
77
|
+
OrderTriggerCondition.BELOW = { below: {} };
|
|
78
|
+
function isVariant(object, type) {
|
|
79
|
+
return object.hasOwnProperty(type);
|
|
80
|
+
}
|
|
81
|
+
exports.isVariant = isVariant;
|
|
82
|
+
function isOneOfVariant(object, types) {
|
|
83
|
+
return types.reduce((result, type) => {
|
|
84
|
+
return result || object.hasOwnProperty(type);
|
|
85
|
+
}, false);
|
|
86
|
+
}
|
|
87
|
+
exports.isOneOfVariant = isOneOfVariant;
|
|
88
|
+
var TradeSide;
|
|
89
|
+
(function (TradeSide) {
|
|
90
|
+
TradeSide[TradeSide["None"] = 0] = "None";
|
|
91
|
+
TradeSide[TradeSide["Buy"] = 1] = "Buy";
|
|
92
|
+
TradeSide[TradeSide["Sell"] = 2] = "Sell";
|
|
93
|
+
})(TradeSide = exports.TradeSide || (exports.TradeSide = {}));
|
|
94
|
+
class LiquidationType {
|
|
95
|
+
}
|
|
96
|
+
exports.LiquidationType = LiquidationType;
|
|
97
|
+
LiquidationType.LIQUIDATE_PERP = { liquidatePerp: {} };
|
|
98
|
+
LiquidationType.LIQUIDATE_BORROW = { liquidateBorrow: {} };
|
|
99
|
+
LiquidationType.LIQUIDATE_BORROW_FOR_PERP_PNL = {
|
|
100
|
+
liquidateBorrowForPerpPnl: {},
|
|
101
|
+
};
|
|
102
|
+
LiquidationType.LIQUIDATE_PERP_PNL_FOR_DEPOSIT = {
|
|
103
|
+
liquidatePerpPnlForDeposit: {},
|
|
104
|
+
};
|
|
105
|
+
exports.DefaultOrderParams = {
|
|
106
|
+
orderType: OrderType.MARKET,
|
|
107
|
+
userOrderId: 0,
|
|
108
|
+
direction: PositionDirection.LONG,
|
|
109
|
+
baseAssetAmount: _1.ZERO,
|
|
110
|
+
price: _1.ZERO,
|
|
111
|
+
marketIndex: _1.ZERO,
|
|
112
|
+
reduceOnly: false,
|
|
113
|
+
postOnly: false,
|
|
114
|
+
immediateOrCancel: false,
|
|
115
|
+
triggerPrice: _1.ZERO,
|
|
116
|
+
triggerCondition: OrderTriggerCondition.ABOVE,
|
|
117
|
+
positionLimit: _1.ZERO,
|
|
118
|
+
oraclePriceOffset: _1.ZERO,
|
|
119
|
+
padding0: _1.ZERO,
|
|
120
|
+
padding1: _1.ZERO,
|
|
121
|
+
optionalAccounts: {
|
|
122
|
+
discountToken: false,
|
|
123
|
+
referrer: false,
|
|
124
|
+
},
|
|
125
|
+
};
|