@drift-labs/sdk 0.1.36-master.5 → 0.2.0-master.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/lib/accounts/bulkAccountLoader.d.ts +7 -6
- package/lib/accounts/bulkAccountLoader.js +83 -93
- package/lib/accounts/bulkUserSubscription.js +13 -57
- package/lib/accounts/fetch.d.ts +4 -0
- package/lib/accounts/fetch.js +18 -0
- package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +34 -38
- package/lib/accounts/pollingClearingHouseAccountSubscriber.js +224 -224
- package/lib/accounts/pollingOracleSubscriber.d.ts +3 -3
- package/lib/accounts/pollingOracleSubscriber.js +37 -49
- package/lib/accounts/pollingTokenAccountSubscriber.d.ts +3 -3
- package/lib/accounts/pollingTokenAccountSubscriber.js +35 -50
- package/lib/accounts/pollingUserAccountSubscriber.d.ts +7 -13
- package/lib/accounts/pollingUserAccountSubscriber.js +71 -134
- package/lib/accounts/types.d.ts +34 -41
- package/lib/accounts/webSocketAccountSubscriber.d.ts +6 -4
- package/lib/accounts/webSocketAccountSubscriber.js +39 -35
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +33 -28
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +153 -185
- package/lib/accounts/webSocketUserAccountSubscriber.d.ts +5 -11
- package/lib/accounts/webSocketUserAccountSubscriber.js +22 -67
- package/lib/addresses/marketAddresses.d.ts +4 -0
- package/lib/addresses/marketAddresses.js +15 -0
- package/lib/addresses/pda.d.ts +12 -0
- package/lib/addresses/pda.js +83 -0
- package/lib/admin.d.ts +8 -12
- package/lib/admin.js +366 -490
- package/lib/clearingHouse.d.ts +84 -103
- package/lib/clearingHouse.js +779 -810
- package/lib/clearingHouseConfig.d.ts +34 -0
- package/lib/clearingHouseConfig.js +2 -0
- package/lib/clearingHouseUser.d.ts +19 -18
- package/lib/clearingHouseUser.js +157 -115
- package/lib/clearingHouseUserConfig.d.ts +14 -0
- package/lib/clearingHouseUserConfig.js +2 -0
- package/lib/config.d.ts +12 -0
- package/lib/config.js +35 -4
- package/lib/constants/banks.d.ts +16 -0
- package/lib/constants/banks.js +34 -0
- package/lib/constants/markets.d.ts +8 -3
- package/lib/constants/markets.js +13 -206
- package/lib/constants/numericConstants.d.ts +16 -0
- package/lib/constants/numericConstants.js +22 -6
- package/lib/events/eventList.d.ts +22 -0
- package/lib/events/eventList.js +77 -0
- package/lib/events/eventSubscriber.d.ts +34 -0
- package/lib/events/eventSubscriber.js +126 -0
- package/lib/events/fetchLogs.d.ts +13 -0
- package/lib/events/fetchLogs.js +39 -0
- package/lib/events/pollingLogProvider.d.ts +15 -0
- package/lib/events/pollingLogProvider.js +53 -0
- package/lib/events/sort.d.ts +2 -0
- package/lib/events/sort.js +44 -0
- package/lib/events/txEventCache.d.ts +24 -0
- package/lib/events/txEventCache.js +71 -0
- package/lib/events/types.d.ts +49 -0
- package/lib/events/types.js +20 -0
- package/lib/events/webSocketLogProvider.d.ts +12 -0
- package/lib/events/webSocketLogProvider.js +30 -0
- package/lib/examples/makeTradeExample.js +26 -27
- package/lib/factory/bigNum.d.ts +112 -0
- package/lib/factory/bigNum.js +356 -0
- package/lib/factory/oracleClient.d.ts +1 -2
- package/lib/factory/oracleClient.js +6 -2
- package/lib/idl/clearing_house.json +1739 -2287
- package/lib/index.d.ts +13 -4
- package/lib/index.js +13 -4
- package/lib/math/amm.d.ts +19 -29
- package/lib/math/amm.js +129 -179
- package/lib/math/auction.d.ts +5 -0
- package/lib/math/auction.js +39 -0
- package/lib/math/bankBalance.d.ts +9 -0
- package/lib/math/bankBalance.js +75 -0
- package/lib/math/conversion.d.ts +0 -1
- package/lib/math/conversion.js +1 -5
- package/lib/math/funding.d.ts +6 -6
- package/lib/math/funding.js +158 -175
- package/lib/math/market.d.ts +6 -6
- package/lib/math/market.js +10 -9
- package/lib/math/oracles.d.ts +3 -0
- package/lib/math/oracles.js +26 -0
- package/lib/math/orders.d.ts +5 -0
- package/lib/math/orders.js +31 -1
- package/lib/math/position.d.ts +7 -4
- package/lib/math/position.js +27 -9
- package/lib/math/repeg.d.ts +22 -0
- package/lib/math/repeg.js +128 -0
- package/lib/math/trade.d.ts +13 -8
- package/lib/math/trade.js +85 -22
- package/lib/mockUSDCFaucet.js +87 -116
- package/lib/oracles/oracleClientCache.d.ts +8 -0
- package/lib/oracles/oracleClientCache.js +19 -0
- package/lib/oracles/pythClient.d.ts +3 -5
- package/lib/oracles/pythClient.js +12 -30
- package/lib/oracles/quoteAssetOracleClient.d.ts +9 -0
- package/lib/oracles/quoteAssetOracleClient.js +21 -0
- package/lib/oracles/switchboardClient.d.ts +3 -5
- package/lib/oracles/switchboardClient.js +29 -47
- package/lib/oracles/types.d.ts +7 -1
- package/lib/orders.d.ts +6 -6
- package/lib/orders.js +10 -9
- package/lib/slot/SlotSubscriber.d.ts +12 -0
- package/lib/slot/SlotSubscriber.js +23 -0
- package/lib/tx/retryTxSender.d.ts +2 -2
- package/lib/tx/retryTxSender.js +108 -123
- package/lib/tx/types.d.ts +5 -1
- package/lib/tx/utils.d.ts +1 -1
- package/lib/tx/utils.js +11 -2
- package/lib/types.d.ts +105 -98
- package/lib/types.js +13 -1
- package/lib/userName.d.ts +4 -0
- package/lib/userName.js +20 -0
- package/lib/util/computeUnits.js +10 -21
- package/lib/util/tps.js +11 -22
- package/lib/wallet.js +7 -20
- package/package.json +10 -3
- package/src/accounts/bulkAccountLoader.ts +26 -15
- package/src/accounts/bulkUserSubscription.ts +1 -45
- package/src/accounts/fetch.ts +33 -0
- package/src/accounts/pollingClearingHouseAccountSubscriber.ts +249 -214
- package/src/accounts/pollingOracleSubscriber.ts +16 -8
- package/src/accounts/pollingTokenAccountSubscriber.ts +11 -8
- package/src/accounts/pollingUserAccountSubscriber.ts +21 -86
- package/src/accounts/types.ts +41 -70
- package/src/accounts/webSocketAccountSubscriber.ts +33 -16
- package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +190 -240
- package/src/accounts/webSocketUserAccountSubscriber.ts +11 -71
- package/src/addresses/marketAddresses.ts +18 -0
- package/src/addresses/pda.ts +118 -0
- package/src/admin.ts +209 -267
- package/src/clearingHouse.ts +921 -829
- package/src/clearingHouseConfig.ts +37 -0
- package/src/clearingHouseUser.ts +280 -127
- package/src/clearingHouseUserConfig.ts +18 -0
- package/src/config.ts +54 -1
- package/src/constants/banks.ts +43 -0
- package/src/constants/markets.ts +16 -207
- package/src/constants/numericConstants.ts +33 -5
- package/src/events/eventList.ts +94 -0
- package/src/events/eventSubscriber.ts +194 -0
- package/src/events/fetchLogs.ts +80 -0
- package/src/events/pollingLogProvider.ts +79 -0
- package/src/events/sort.ts +65 -0
- package/src/events/txEventCache.ts +74 -0
- package/src/events/types.ts +98 -0
- package/src/events/webSocketLogProvider.ts +38 -0
- package/src/examples/makeTradeExample.ts +20 -11
- package/src/factory/bigNum.ts +507 -0
- package/src/factory/oracleClient.ts +7 -4
- package/src/idl/clearing_house.json +1739 -2287
- package/src/index.ts +13 -4
- package/src/math/amm.ts +229 -245
- package/src/math/auction.ts +39 -0
- package/src/math/bankBalance.ts +112 -0
- package/src/math/conversion.ts +1 -11
- package/src/math/funding.ts +12 -9
- package/src/math/market.ts +37 -30
- package/src/math/oracles.ts +36 -0
- package/src/math/orders.ts +38 -0
- package/src/math/position.ts +48 -13
- package/src/math/repeg.ts +175 -0
- package/src/math/trade.ts +114 -36
- package/src/math/utils.js +27 -0
- package/src/math/utils.js.map +1 -0
- package/src/oracles/oracleClientCache.ts +20 -0
- package/src/oracles/pythClient.ts +5 -11
- package/src/oracles/quoteAssetOracleClient.ts +25 -0
- package/src/oracles/switchboardClient.ts +16 -24
- package/src/oracles/types.ts +8 -1
- package/src/orders.ts +35 -20
- package/src/slot/SlotSubscriber.ts +32 -0
- package/src/tx/retryTxSender.ts +6 -4
- package/src/tx/types.ts +6 -1
- package/src/tx/utils.ts +22 -3
- package/src/types.ts +108 -110
- package/src/userName.ts +20 -0
- package/src/util/computeUnits.js +17 -0
- package/src/util/computeUnits.js.map +1 -0
- package/tests/bn/test.ts +255 -0
- package/tsconfig.json +12 -12
- package/lib/addresses.d.ts +0 -9
- package/lib/addresses.js +0 -87
- package/lib/constants/accounts.d.ts +0 -15
- package/lib/constants/accounts.js +0 -18
- package/lib/factory/clearingHouse.d.ts +0 -35
- package/lib/factory/clearingHouse.js +0 -81
- package/lib/factory/clearingHouseUser.d.ts +0 -19
- package/lib/factory/clearingHouseUser.js +0 -34
- package/lib/math/insuranceFund.d.ts +0 -15
- package/lib/math/insuranceFund.js +0 -33
- package/lib/tx/defaultTxSender.d.ts +0 -8
- package/lib/tx/defaultTxSender.js +0 -12
- package/src/addresses.ts +0 -71
- package/src/constants/accounts.ts +0 -26
- package/src/factory/clearingHouse.ts +0 -173
- package/src/factory/clearingHouseUser.ts +0 -73
- package/src/math/insuranceFund.ts +0 -29
- package/src/tx/defaultTxSender.ts +0 -24
package/src/tx/retryTxSender.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TxSender } from './types';
|
|
1
|
+
import { TxSender, TxSigAndSlot } from './types';
|
|
2
2
|
import {
|
|
3
3
|
Commitment,
|
|
4
4
|
ConfirmOptions,
|
|
@@ -43,7 +43,7 @@ export class RetryTxSender implements TxSender {
|
|
|
43
43
|
tx: Transaction,
|
|
44
44
|
additionalSigners?: Array<Signer>,
|
|
45
45
|
opts?: ConfirmOptions
|
|
46
|
-
): Promise<
|
|
46
|
+
): Promise<TxSigAndSlot> {
|
|
47
47
|
if (additionalSigners === undefined) {
|
|
48
48
|
additionalSigners = [];
|
|
49
49
|
}
|
|
@@ -86,8 +86,10 @@ export class RetryTxSender implements TxSender {
|
|
|
86
86
|
}
|
|
87
87
|
})();
|
|
88
88
|
|
|
89
|
+
let slot: number;
|
|
89
90
|
try {
|
|
90
|
-
await this.confirmTransaction(txid, opts.commitment);
|
|
91
|
+
const result = await this.confirmTransaction(txid, opts.commitment);
|
|
92
|
+
slot = result.context.slot;
|
|
91
93
|
} catch (e) {
|
|
92
94
|
console.error(e);
|
|
93
95
|
throw e;
|
|
@@ -95,7 +97,7 @@ export class RetryTxSender implements TxSender {
|
|
|
95
97
|
stopWaiting();
|
|
96
98
|
}
|
|
97
99
|
|
|
98
|
-
return txid;
|
|
100
|
+
return { txSig: txid, slot };
|
|
99
101
|
}
|
|
100
102
|
|
|
101
103
|
async prepareTx(
|
package/src/tx/types.ts
CHANGED
|
@@ -6,6 +6,11 @@ import {
|
|
|
6
6
|
TransactionSignature,
|
|
7
7
|
} from '@solana/web3.js';
|
|
8
8
|
|
|
9
|
+
export type TxSigAndSlot = {
|
|
10
|
+
txSig: TransactionSignature;
|
|
11
|
+
slot: number;
|
|
12
|
+
};
|
|
13
|
+
|
|
9
14
|
export interface TxSender {
|
|
10
15
|
provider: Provider;
|
|
11
16
|
|
|
@@ -13,5 +18,5 @@ export interface TxSender {
|
|
|
13
18
|
tx: Transaction,
|
|
14
19
|
additionalSigners?: Array<Signer>,
|
|
15
20
|
opts?: ConfirmOptions
|
|
16
|
-
): Promise<
|
|
21
|
+
): Promise<TxSigAndSlot>;
|
|
17
22
|
}
|
package/src/tx/utils.ts
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Transaction,
|
|
3
|
+
TransactionInstruction,
|
|
4
|
+
ComputeBudgetProgram,
|
|
5
|
+
} from '@solana/web3.js';
|
|
2
6
|
|
|
3
|
-
|
|
4
|
-
|
|
7
|
+
const COMPUTE_UNITS_DEFAULT = 200_000;
|
|
8
|
+
|
|
9
|
+
export function wrapInTx(
|
|
10
|
+
instruction: TransactionInstruction,
|
|
11
|
+
computeUnits = 500_000 // TODO, requires less code change
|
|
12
|
+
): Transaction {
|
|
13
|
+
const tx = new Transaction();
|
|
14
|
+
if (computeUnits != COMPUTE_UNITS_DEFAULT) {
|
|
15
|
+
tx.add(
|
|
16
|
+
ComputeBudgetProgram.requestUnits({
|
|
17
|
+
units: computeUnits,
|
|
18
|
+
additionalFee: 0,
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return tx.add(instruction);
|
|
5
24
|
}
|
package/src/types.ts
CHANGED
|
@@ -7,6 +7,11 @@ export class SwapDirection {
|
|
|
7
7
|
static readonly REMOVE = { remove: {} };
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
export class BankBalanceType {
|
|
11
|
+
static readonly DEPOSIT = { deposit: {} };
|
|
12
|
+
static readonly BORROW = { borrow: {} };
|
|
13
|
+
}
|
|
14
|
+
|
|
10
15
|
export class PositionDirection {
|
|
11
16
|
static readonly LONG = { long: {} };
|
|
12
17
|
static readonly SHORT = { short: {} };
|
|
@@ -15,6 +20,7 @@ export class PositionDirection {
|
|
|
15
20
|
export class OracleSource {
|
|
16
21
|
static readonly PYTH = { pyth: {} };
|
|
17
22
|
static readonly SWITCHBOARD = { switchboard: {} };
|
|
23
|
+
static readonly QUOTE_ASSET = { quoteAsset: {} };
|
|
18
24
|
}
|
|
19
25
|
|
|
20
26
|
export class OrderType {
|
|
@@ -53,6 +59,12 @@ export function isVariant(object: unknown, type: string) {
|
|
|
53
59
|
return object.hasOwnProperty(type);
|
|
54
60
|
}
|
|
55
61
|
|
|
62
|
+
export function isOneOfVariant(object: unknown, types: string[]) {
|
|
63
|
+
return types.reduce((result, type) => {
|
|
64
|
+
return result || object.hasOwnProperty(type);
|
|
65
|
+
}, false);
|
|
66
|
+
}
|
|
67
|
+
|
|
56
68
|
export enum TradeSide {
|
|
57
69
|
None = 0,
|
|
58
70
|
Buy = 1,
|
|
@@ -69,58 +81,21 @@ export type CandleResolution =
|
|
|
69
81
|
| 'W'
|
|
70
82
|
| 'M';
|
|
71
83
|
|
|
72
|
-
// # ClearingHouse Account Types
|
|
73
|
-
export type TradeHistoryAccount = {
|
|
74
|
-
head: BN;
|
|
75
|
-
tradeRecords: TradeRecord[];
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
export type DepositHistoryAccount = {
|
|
79
|
-
head: BN;
|
|
80
|
-
depositRecords: DepositRecord[];
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
export type ExtendedCurveHistoryAccount = {
|
|
84
|
-
head: BN;
|
|
85
|
-
curveRecords: ExtendedCurveRecord[];
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
export type FundingRateHistoryAccount = {
|
|
89
|
-
head: BN;
|
|
90
|
-
fundingRateRecords: FundingRateRecord[];
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export type FundingPaymentHistoryAccount = {
|
|
94
|
-
head: BN;
|
|
95
|
-
fundingPaymentRecords: FundingPaymentRecord[];
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
export type LiquidationHistoryAccount = {
|
|
99
|
-
head: BN;
|
|
100
|
-
liquidationRecords: LiquidationRecord[];
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
export type OrderHistoryAccount = {
|
|
104
|
-
head: BN;
|
|
105
|
-
lastOrderId: BN;
|
|
106
|
-
orderRecords: OrderRecord[];
|
|
107
|
-
};
|
|
108
|
-
|
|
109
84
|
export type DepositRecord = {
|
|
110
85
|
ts: BN;
|
|
111
|
-
recordId: BN;
|
|
112
86
|
userAuthority: PublicKey;
|
|
113
87
|
user: PublicKey;
|
|
114
88
|
direction: {
|
|
115
89
|
deposit?: any;
|
|
116
90
|
withdraw?: any;
|
|
117
91
|
};
|
|
118
|
-
|
|
119
|
-
cumulativeDepositsBefore: BN;
|
|
92
|
+
bankIndex: BN;
|
|
120
93
|
amount: BN;
|
|
94
|
+
from?: PublicKey;
|
|
95
|
+
to?: PublicKey;
|
|
121
96
|
};
|
|
122
97
|
|
|
123
|
-
export type
|
|
98
|
+
export type CurveRecord = {
|
|
124
99
|
ts: BN;
|
|
125
100
|
recordId: BN;
|
|
126
101
|
marketIndex: BN;
|
|
@@ -140,28 +115,6 @@ export type ExtendedCurveRecord = {
|
|
|
140
115
|
tradeId: BN;
|
|
141
116
|
};
|
|
142
117
|
|
|
143
|
-
export type TradeRecord = {
|
|
144
|
-
ts: BN;
|
|
145
|
-
recordId: BN;
|
|
146
|
-
userAuthority: PublicKey;
|
|
147
|
-
user: PublicKey;
|
|
148
|
-
direction: {
|
|
149
|
-
long?: any;
|
|
150
|
-
short?: any;
|
|
151
|
-
};
|
|
152
|
-
baseAssetAmount: BN;
|
|
153
|
-
quoteAssetAmount: BN;
|
|
154
|
-
markPriceBefore: BN;
|
|
155
|
-
markPriceAfter: BN;
|
|
156
|
-
fee: BN;
|
|
157
|
-
quoteAssetAmountSurplus: BN;
|
|
158
|
-
refereeDiscount: BN;
|
|
159
|
-
tokenDiscount: BN;
|
|
160
|
-
marketIndex: BN;
|
|
161
|
-
liquidation: boolean;
|
|
162
|
-
oraclePrice: BN;
|
|
163
|
-
};
|
|
164
|
-
|
|
165
118
|
export type FundingRateRecord = {
|
|
166
119
|
ts: BN;
|
|
167
120
|
recordId: BN;
|
|
@@ -175,7 +128,6 @@ export type FundingRateRecord = {
|
|
|
175
128
|
|
|
176
129
|
export type FundingPaymentRecord = {
|
|
177
130
|
ts: BN;
|
|
178
|
-
recordId: BN;
|
|
179
131
|
userAuthority: PublicKey;
|
|
180
132
|
user: PublicKey;
|
|
181
133
|
marketIndex: BN;
|
|
@@ -207,18 +159,21 @@ export type LiquidationRecord = {
|
|
|
207
159
|
|
|
208
160
|
export type OrderRecord = {
|
|
209
161
|
ts: BN;
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
162
|
+
taker: PublicKey;
|
|
163
|
+
maker: PublicKey;
|
|
164
|
+
takerOrder: Order;
|
|
165
|
+
makerOrder: Order;
|
|
214
166
|
action: OrderAction;
|
|
215
167
|
filler: PublicKey;
|
|
168
|
+
fillRecordId: BN;
|
|
169
|
+
marketIndex: BN;
|
|
216
170
|
baseAssetAmountFilled: BN;
|
|
217
171
|
quoteAssetAmountFilled: BN;
|
|
218
|
-
|
|
172
|
+
makerRebate: BN;
|
|
173
|
+
takerFee: BN;
|
|
219
174
|
fillerReward: BN;
|
|
220
|
-
tradeRecordId: BN;
|
|
221
175
|
quoteAssetAmountSurplus: BN;
|
|
176
|
+
oraclePrice: BN;
|
|
222
177
|
};
|
|
223
178
|
|
|
224
179
|
export type StateAccount = {
|
|
@@ -226,23 +181,12 @@ export type StateAccount = {
|
|
|
226
181
|
fundingPaused: boolean;
|
|
227
182
|
exchangePaused: boolean;
|
|
228
183
|
adminControlsPrices: boolean;
|
|
229
|
-
collateralMint: PublicKey;
|
|
230
|
-
collateralVault: PublicKey;
|
|
231
|
-
collateralVaultAuthority: PublicKey;
|
|
232
|
-
collateralVaultNonce: number;
|
|
233
184
|
insuranceVault: PublicKey;
|
|
234
185
|
insuranceVaultAuthority: PublicKey;
|
|
235
186
|
insuranceVaultNonce: number;
|
|
236
187
|
marginRatioInitial: BN;
|
|
237
188
|
marginRatioMaintenance: BN;
|
|
238
189
|
marginRatioPartial: BN;
|
|
239
|
-
markets: PublicKey;
|
|
240
|
-
curveHistory: PublicKey;
|
|
241
|
-
depositHistory: PublicKey;
|
|
242
|
-
fundingRateHistory: PublicKey;
|
|
243
|
-
fundingPaymentHistory: PublicKey;
|
|
244
|
-
tradeHistory: PublicKey;
|
|
245
|
-
liquidationHistory: PublicKey;
|
|
246
190
|
partialLiquidationClosePercentageNumerator: BN;
|
|
247
191
|
partialLiquidationClosePercentageDenominator: BN;
|
|
248
192
|
partialLiquidationPenaltyPercentageNumerator: BN;
|
|
@@ -258,30 +202,52 @@ export type StateAccount = {
|
|
|
258
202
|
discountMint: PublicKey;
|
|
259
203
|
oracleGuardRails: OracleGuardRails;
|
|
260
204
|
maxDeposit: BN;
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
export type OrderStateAccount = {
|
|
266
|
-
orderHistory: PublicKey;
|
|
267
|
-
orderFillerRewardStructure: OrderFillerRewardStructure;
|
|
205
|
+
numberOfMarkets: BN;
|
|
206
|
+
numberOfBanks: BN;
|
|
268
207
|
minOrderQuoteAssetAmount: BN;
|
|
269
208
|
};
|
|
270
209
|
|
|
271
|
-
export type
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
export type Market = {
|
|
210
|
+
export type MarketAccount = {
|
|
211
|
+
initialized: boolean;
|
|
212
|
+
marketIndex: BN;
|
|
213
|
+
pubkey: PublicKey;
|
|
276
214
|
amm: AMM;
|
|
277
215
|
baseAssetAmount: BN;
|
|
278
216
|
baseAssetAmountLong: BN;
|
|
279
217
|
baseAssetAmountShort: BN;
|
|
280
|
-
initialized: boolean;
|
|
281
218
|
openInterest: BN;
|
|
282
219
|
marginRatioInitial: number;
|
|
283
220
|
marginRatioMaintenance: number;
|
|
284
221
|
marginRatioPartial: number;
|
|
222
|
+
nextFillRecordId: BN;
|
|
223
|
+
pnlPool: PoolBalance;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
export type BankAccount = {
|
|
227
|
+
bankIndex: BN;
|
|
228
|
+
pubkey: PublicKey;
|
|
229
|
+
mint: PublicKey;
|
|
230
|
+
vault: PublicKey;
|
|
231
|
+
vaultAuthority: PublicKey;
|
|
232
|
+
vaultAuthorityNonce: number;
|
|
233
|
+
decimals: number;
|
|
234
|
+
optimalUtilization: BN;
|
|
235
|
+
optimalBorrowRate: BN;
|
|
236
|
+
maxBorrowRate: BN;
|
|
237
|
+
cumulativeDepositInterest: BN;
|
|
238
|
+
cumulativeBorrowInterest: BN;
|
|
239
|
+
depositBalance: BN;
|
|
240
|
+
borrowBalance: BN;
|
|
241
|
+
lastUpdated: BN;
|
|
242
|
+
oracle: PublicKey;
|
|
243
|
+
initialAssetWeight: BN;
|
|
244
|
+
maintenanceAssetWeight: BN;
|
|
245
|
+
initialLiabilityWeight: BN;
|
|
246
|
+
maintenanceLiabilityWeight: BN;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
export type PoolBalance = {
|
|
250
|
+
balance: BN;
|
|
285
251
|
};
|
|
286
252
|
|
|
287
253
|
export type AMM = {
|
|
@@ -307,9 +273,23 @@ export type AMM = {
|
|
|
307
273
|
totalFeeWithdrawn: BN;
|
|
308
274
|
totalFee: BN;
|
|
309
275
|
minimumQuoteAssetTradeSize: BN;
|
|
310
|
-
|
|
276
|
+
baseAssetAmountStepSize: BN;
|
|
311
277
|
lastOraclePrice: BN;
|
|
312
278
|
baseSpread: number;
|
|
279
|
+
curveUpdateIntensity: number;
|
|
280
|
+
netBaseAssetAmount: BN;
|
|
281
|
+
quoteAssetAmountLong: BN;
|
|
282
|
+
quoteAssetAmountShort: BN;
|
|
283
|
+
terminalQuoteAssetReserve: BN;
|
|
284
|
+
feePool: PoolBalance;
|
|
285
|
+
totalExchangeFee: BN;
|
|
286
|
+
totalMmFee: BN;
|
|
287
|
+
netRevenueSinceLastFunding: BN;
|
|
288
|
+
lastUpdateSlot: BN;
|
|
289
|
+
lastBidPriceTwap: BN;
|
|
290
|
+
lastAskPriceTwap: BN;
|
|
291
|
+
longSpread: BN;
|
|
292
|
+
shortSpread: BN;
|
|
313
293
|
};
|
|
314
294
|
|
|
315
295
|
// # User Account Types
|
|
@@ -318,40 +298,46 @@ export type UserPosition = {
|
|
|
318
298
|
lastCumulativeFundingRate: BN;
|
|
319
299
|
marketIndex: BN;
|
|
320
300
|
quoteAssetAmount: BN;
|
|
301
|
+
quoteEntryAmount: BN;
|
|
321
302
|
openOrders: BN;
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
positions: UserPosition[];
|
|
326
|
-
user: PublicKey;
|
|
303
|
+
unsettledPnl: BN;
|
|
304
|
+
openBids: BN;
|
|
305
|
+
openAsks: BN;
|
|
327
306
|
};
|
|
328
307
|
|
|
329
308
|
export type UserAccount = {
|
|
330
309
|
authority: PublicKey;
|
|
310
|
+
name: number[];
|
|
311
|
+
userId: number;
|
|
312
|
+
bankBalances: UserBankBalance[];
|
|
331
313
|
collateral: BN;
|
|
332
314
|
cumulativeDeposits: BN;
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
315
|
+
fees: {
|
|
316
|
+
totalFeePaid: BN;
|
|
317
|
+
totalFeeRebate: BN;
|
|
318
|
+
totalTokenDiscount: BN;
|
|
319
|
+
totalReferralReward: BN;
|
|
320
|
+
totalRefereeDiscount: BN;
|
|
321
|
+
};
|
|
322
|
+
positions: UserPosition[];
|
|
323
|
+
orders: Order[];
|
|
339
324
|
};
|
|
340
325
|
|
|
341
|
-
export type
|
|
342
|
-
|
|
343
|
-
|
|
326
|
+
export type UserBankBalance = {
|
|
327
|
+
bankIndex: BN;
|
|
328
|
+
balanceType: BankBalanceType;
|
|
329
|
+
balance: BN;
|
|
344
330
|
};
|
|
345
331
|
|
|
346
332
|
export type Order = {
|
|
347
333
|
status: OrderStatus;
|
|
348
334
|
orderType: OrderType;
|
|
349
335
|
ts: BN;
|
|
336
|
+
slot: BN;
|
|
350
337
|
orderId: BN;
|
|
351
338
|
userOrderId: number;
|
|
352
339
|
marketIndex: BN;
|
|
353
340
|
price: BN;
|
|
354
|
-
userBaseAssetAmount: BN;
|
|
355
341
|
baseAssetAmount: BN;
|
|
356
342
|
baseAssetAmountFilled: BN;
|
|
357
343
|
quoteAssetAmount: BN;
|
|
@@ -362,10 +348,14 @@ export type Order = {
|
|
|
362
348
|
triggerPrice: BN;
|
|
363
349
|
triggerCondition: OrderTriggerCondition;
|
|
364
350
|
discountTier: OrderDiscountTier;
|
|
351
|
+
existingPositionDirection: PositionDirection,
|
|
365
352
|
referrer: PublicKey;
|
|
366
353
|
postOnly: boolean;
|
|
367
354
|
immediateOrCancel: boolean;
|
|
368
355
|
oraclePriceOffset: BN;
|
|
356
|
+
auctionDuration: number;
|
|
357
|
+
auctionStartPrice: BN;
|
|
358
|
+
auctionEndPrice: BN;
|
|
369
359
|
};
|
|
370
360
|
|
|
371
361
|
export type OrderParams = {
|
|
@@ -391,6 +381,11 @@ export type OrderParams = {
|
|
|
391
381
|
};
|
|
392
382
|
};
|
|
393
383
|
|
|
384
|
+
export type MakerInfo = {
|
|
385
|
+
maker: PublicKey;
|
|
386
|
+
order: Order;
|
|
387
|
+
};
|
|
388
|
+
|
|
394
389
|
// # Misc Types
|
|
395
390
|
export interface IWallet {
|
|
396
391
|
signTransaction(tx: Transaction): Promise<Transaction>;
|
|
@@ -429,6 +424,9 @@ export type FeeStructure = {
|
|
|
429
424
|
refereeDiscountNumerator: BN;
|
|
430
425
|
refereeDiscountDenominator: BN;
|
|
431
426
|
};
|
|
427
|
+
makerRebateNumerator: BN;
|
|
428
|
+
makerRebateDenominator: BN;
|
|
429
|
+
fillerRewardStructure: OrderFillerRewardStructure;
|
|
432
430
|
};
|
|
433
431
|
|
|
434
432
|
export type OracleGuardRails = {
|
package/src/userName.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const MAX_NAME_LENGTH = 32;
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_USER_NAME = 'Main Account';
|
|
4
|
+
|
|
5
|
+
export function encodeName(name: string): number[] {
|
|
6
|
+
if (name.length > MAX_NAME_LENGTH) {
|
|
7
|
+
throw Error(`User name (${name}) longer than 32 characters`);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const buffer = Buffer.alloc(32);
|
|
11
|
+
buffer.fill(name);
|
|
12
|
+
buffer.fill(' ', name.length);
|
|
13
|
+
|
|
14
|
+
return Array(...buffer);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function decodeName(bytes: number[]): string {
|
|
18
|
+
const buffer = Buffer.from(bytes);
|
|
19
|
+
return buffer.toString('utf8').trim();
|
|
20
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findComputeUnitConsumption = void 0;
|
|
4
|
+
async function findComputeUnitConsumption(programId, connection, txSignature, commitment = 'confirmed') {
|
|
5
|
+
const tx = await connection.getTransaction(txSignature, { commitment });
|
|
6
|
+
const computeUnits = [];
|
|
7
|
+
const regex = new RegExp(`Program ${programId.toString()} consumed ([0-9]{0,6}) of 200000 compute units`);
|
|
8
|
+
tx.meta.logMessages.forEach((logMessage) => {
|
|
9
|
+
const match = logMessage.match(regex);
|
|
10
|
+
if (match && match[1]) {
|
|
11
|
+
computeUnits.push(match[1]);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
return computeUnits;
|
|
15
|
+
}
|
|
16
|
+
exports.findComputeUnitConsumption = findComputeUnitConsumption;
|
|
17
|
+
//# sourceMappingURL=computeUnits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"computeUnits.js","sourceRoot":"","sources":["computeUnits.ts"],"names":[],"mappings":";;;AAEO,KAAK,UAAU,0BAA0B,CAC/C,SAAoB,EACpB,UAAsB,EACtB,WAAmB,EACnB,aAAuB,WAAW;IAElC,MAAM,EAAE,GAAG,MAAM,UAAU,CAAC,cAAc,CAAC,WAAW,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;IACxE,MAAM,YAAY,GAAG,EAAE,CAAC;IACxB,MAAM,KAAK,GAAG,IAAI,MAAM,CACvB,WAAW,SAAS,CAAC,QAAQ,EAAE,gDAAgD,CAC/E,CAAC;IACF,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE;QAC1C,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACtC,IAAI,KAAK,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE;YACtB,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;SAC5B;IACF,CAAC,CAAC,CAAC;IACH,OAAO,YAAY,CAAC;AACrB,CAAC;AAlBD,gEAkBC"}
|