@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { TxSender } from './types';
|
|
2
|
+
import { TxSender, TxSigAndSlot } from './types';
|
|
3
3
|
import { Commitment, ConfirmOptions, RpcResponseAndContext, Signer, SignatureResult, Transaction, TransactionSignature, Connection } from '@solana/web3.js';
|
|
4
4
|
import { AnchorProvider } from '@project-serum/anchor';
|
|
5
5
|
declare type ResolveReference = {
|
|
@@ -11,7 +11,7 @@ export declare class RetryTxSender implements TxSender {
|
|
|
11
11
|
retrySleep: number;
|
|
12
12
|
additionalConnections: Connection[];
|
|
13
13
|
constructor(provider: AnchorProvider, timeout?: number, retrySleep?: number, additionalConnections?: Connection[]);
|
|
14
|
-
send(tx: Transaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions): Promise<
|
|
14
|
+
send(tx: Transaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions): Promise<TxSigAndSlot>;
|
|
15
15
|
prepareTx(tx: Transaction, additionalSigners: Array<Signer>, opts: ConfirmOptions): Promise<Transaction>;
|
|
16
16
|
confirmTransaction(signature: TransactionSignature, commitment?: Commitment): Promise<RpcResponseAndContext<SignatureResult>>;
|
|
17
17
|
getTimestamp(): number;
|
package/lib/tx/retryTxSender.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -24,133 +15,127 @@ class RetryTxSender {
|
|
|
24
15
|
this.retrySleep = retrySleep !== null && retrySleep !== void 0 ? retrySleep : DEFAULT_RETRY;
|
|
25
16
|
this.additionalConnections = additionalConnections;
|
|
26
17
|
}
|
|
27
|
-
send(tx, additionalSigners, opts) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
18
|
+
async send(tx, additionalSigners, opts) {
|
|
19
|
+
if (additionalSigners === undefined) {
|
|
20
|
+
additionalSigners = [];
|
|
21
|
+
}
|
|
22
|
+
if (opts === undefined) {
|
|
23
|
+
opts = this.provider.opts;
|
|
24
|
+
}
|
|
25
|
+
await this.prepareTx(tx, additionalSigners, opts);
|
|
26
|
+
const rawTransaction = tx.serialize();
|
|
27
|
+
const startTime = this.getTimestamp();
|
|
28
|
+
const txid = await this.provider.connection.sendRawTransaction(rawTransaction, opts);
|
|
29
|
+
this.sendToAdditionalConnections(rawTransaction, opts);
|
|
30
|
+
let done = false;
|
|
31
|
+
const resolveReference = {
|
|
32
|
+
resolve: undefined,
|
|
33
|
+
};
|
|
34
|
+
const stopWaiting = () => {
|
|
35
|
+
done = true;
|
|
36
|
+
if (resolveReference.resolve) {
|
|
37
|
+
resolveReference.resolve();
|
|
34
38
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
resolveReference.resolve();
|
|
39
|
+
};
|
|
40
|
+
(async () => {
|
|
41
|
+
while (!done && this.getTimestamp() - startTime < this.timeout) {
|
|
42
|
+
await this.sleep(resolveReference);
|
|
43
|
+
if (!done) {
|
|
44
|
+
this.provider.connection
|
|
45
|
+
.sendRawTransaction(rawTransaction, opts)
|
|
46
|
+
.catch((e) => {
|
|
47
|
+
console.error(e);
|
|
48
|
+
stopWaiting();
|
|
49
|
+
});
|
|
50
|
+
this.sendToAdditionalConnections(rawTransaction, opts);
|
|
48
51
|
}
|
|
49
|
-
};
|
|
50
|
-
(() => __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
while (!done && this.getTimestamp() - startTime < this.timeout) {
|
|
52
|
-
yield this.sleep(resolveReference);
|
|
53
|
-
if (!done) {
|
|
54
|
-
this.provider.connection
|
|
55
|
-
.sendRawTransaction(rawTransaction, opts)
|
|
56
|
-
.catch((e) => {
|
|
57
|
-
console.error(e);
|
|
58
|
-
stopWaiting();
|
|
59
|
-
});
|
|
60
|
-
this.sendToAdditionalConnections(rawTransaction, opts);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}))();
|
|
64
|
-
try {
|
|
65
|
-
yield this.confirmTransaction(txid, opts.commitment);
|
|
66
|
-
}
|
|
67
|
-
catch (e) {
|
|
68
|
-
console.error(e);
|
|
69
|
-
throw e;
|
|
70
52
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
53
|
+
})();
|
|
54
|
+
let slot;
|
|
55
|
+
try {
|
|
56
|
+
const result = await this.confirmTransaction(txid, opts.commitment);
|
|
57
|
+
slot = result.context.slot;
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
console.error(e);
|
|
61
|
+
throw e;
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
stopWaiting();
|
|
65
|
+
}
|
|
66
|
+
return { txSig: txid, slot };
|
|
76
67
|
}
|
|
77
|
-
prepareTx(tx, additionalSigners, opts) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
tx.partialSign(kp);
|
|
86
|
-
});
|
|
87
|
-
return tx;
|
|
68
|
+
async prepareTx(tx, additionalSigners, opts) {
|
|
69
|
+
tx.feePayer = this.provider.wallet.publicKey;
|
|
70
|
+
tx.recentBlockhash = (await this.provider.connection.getRecentBlockhash(opts.preflightCommitment)).blockhash;
|
|
71
|
+
await this.provider.wallet.signTransaction(tx);
|
|
72
|
+
additionalSigners
|
|
73
|
+
.filter((s) => s !== undefined)
|
|
74
|
+
.forEach((kp) => {
|
|
75
|
+
tx.partialSign(kp);
|
|
88
76
|
});
|
|
77
|
+
return tx;
|
|
89
78
|
}
|
|
90
|
-
confirmTransaction(signature, commitment) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
subscriptionIds.push(subscriptionId);
|
|
126
|
-
return confirmPromise;
|
|
79
|
+
async confirmTransaction(signature, commitment) {
|
|
80
|
+
let decodedSignature;
|
|
81
|
+
try {
|
|
82
|
+
decodedSignature = bs58_1.default.decode(signature);
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
throw new Error('signature must be base58 encoded: ' + signature);
|
|
86
|
+
}
|
|
87
|
+
(0, assert_1.default)(decodedSignature.length === 64, 'signature has invalid length');
|
|
88
|
+
const start = Date.now();
|
|
89
|
+
const subscriptionCommitment = commitment || this.provider.opts.commitment;
|
|
90
|
+
const subscriptionIds = new Array();
|
|
91
|
+
const connections = [
|
|
92
|
+
this.provider.connection,
|
|
93
|
+
...this.additionalConnections,
|
|
94
|
+
];
|
|
95
|
+
let response = null;
|
|
96
|
+
const promises = connections.map((connection, i) => {
|
|
97
|
+
let subscriptionId;
|
|
98
|
+
const confirmPromise = new Promise((resolve, reject) => {
|
|
99
|
+
try {
|
|
100
|
+
subscriptionId = connection.onSignature(signature, (result, context) => {
|
|
101
|
+
subscriptionIds[i] = undefined;
|
|
102
|
+
response = {
|
|
103
|
+
context,
|
|
104
|
+
value: result,
|
|
105
|
+
};
|
|
106
|
+
resolve(null);
|
|
107
|
+
}, subscriptionCommitment);
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
reject(err);
|
|
111
|
+
}
|
|
127
112
|
});
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
113
|
+
subscriptionIds.push(subscriptionId);
|
|
114
|
+
return confirmPromise;
|
|
115
|
+
});
|
|
116
|
+
try {
|
|
117
|
+
await this.promiseTimeout(promises, this.timeout);
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
for (const [i, subscriptionId] of subscriptionIds.entries()) {
|
|
121
|
+
if (subscriptionId) {
|
|
122
|
+
connections[i].removeSignatureListener(subscriptionId);
|
|
136
123
|
}
|
|
137
124
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
125
|
+
}
|
|
126
|
+
if (response === null) {
|
|
127
|
+
const duration = (Date.now() - start) / 1000;
|
|
128
|
+
throw new Error(`Transaction was not confirmed in ${duration.toFixed(2)} seconds. It is unknown if it succeeded or failed. Check signature ${signature} using the Solana Explorer or CLI tools.`);
|
|
129
|
+
}
|
|
130
|
+
return response;
|
|
144
131
|
}
|
|
145
132
|
getTimestamp() {
|
|
146
133
|
return new Date().getTime();
|
|
147
134
|
}
|
|
148
|
-
sleep(reference) {
|
|
149
|
-
return
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
setTimeout(resolve, this.retrySleep);
|
|
153
|
-
});
|
|
135
|
+
async sleep(reference) {
|
|
136
|
+
return new Promise((resolve) => {
|
|
137
|
+
reference.resolve = resolve;
|
|
138
|
+
setTimeout(resolve, this.retrySleep);
|
|
154
139
|
});
|
|
155
140
|
}
|
|
156
141
|
promiseTimeout(promises, timeoutMs) {
|
package/lib/tx/types.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { Provider } from '@project-serum/anchor';
|
|
2
2
|
import { ConfirmOptions, Signer, Transaction, TransactionSignature } from '@solana/web3.js';
|
|
3
|
+
export declare type TxSigAndSlot = {
|
|
4
|
+
txSig: TransactionSignature;
|
|
5
|
+
slot: number;
|
|
6
|
+
};
|
|
3
7
|
export interface TxSender {
|
|
4
8
|
provider: Provider;
|
|
5
|
-
send(tx: Transaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions): Promise<
|
|
9
|
+
send(tx: Transaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions): Promise<TxSigAndSlot>;
|
|
6
10
|
}
|
package/lib/tx/utils.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Transaction, TransactionInstruction } from '@solana/web3.js';
|
|
2
|
-
export declare function wrapInTx(instruction: TransactionInstruction): Transaction;
|
|
2
|
+
export declare function wrapInTx(instruction: TransactionInstruction, computeUnits?: number): Transaction;
|
package/lib/tx/utils.js
CHANGED
|
@@ -2,7 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.wrapInTx = void 0;
|
|
4
4
|
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const COMPUTE_UNITS_DEFAULT = 200000;
|
|
6
|
+
function wrapInTx(instruction, computeUnits = 500000 // 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);
|
|
7
16
|
}
|
|
8
17
|
exports.wrapInTx = wrapInTx;
|
package/lib/types.d.ts
CHANGED
|
@@ -9,6 +9,14 @@ export declare class SwapDirection {
|
|
|
9
9
|
remove: {};
|
|
10
10
|
};
|
|
11
11
|
}
|
|
12
|
+
export declare class BankBalanceType {
|
|
13
|
+
static readonly DEPOSIT: {
|
|
14
|
+
deposit: {};
|
|
15
|
+
};
|
|
16
|
+
static readonly BORROW: {
|
|
17
|
+
borrow: {};
|
|
18
|
+
};
|
|
19
|
+
}
|
|
12
20
|
export declare class PositionDirection {
|
|
13
21
|
static readonly LONG: {
|
|
14
22
|
long: {};
|
|
@@ -24,6 +32,9 @@ export declare class OracleSource {
|
|
|
24
32
|
static readonly SWITCHBOARD: {
|
|
25
33
|
switchboard: {};
|
|
26
34
|
};
|
|
35
|
+
static readonly QUOTE_ASSET: {
|
|
36
|
+
quoteAsset: {};
|
|
37
|
+
};
|
|
27
38
|
}
|
|
28
39
|
export declare class OrderType {
|
|
29
40
|
static readonly LIMIT: {
|
|
@@ -87,55 +98,27 @@ export declare class OrderTriggerCondition {
|
|
|
87
98
|
};
|
|
88
99
|
}
|
|
89
100
|
export declare function isVariant(object: unknown, type: string): boolean;
|
|
101
|
+
export declare function isOneOfVariant(object: unknown, types: string[]): boolean;
|
|
90
102
|
export declare enum TradeSide {
|
|
91
103
|
None = 0,
|
|
92
104
|
Buy = 1,
|
|
93
105
|
Sell = 2
|
|
94
106
|
}
|
|
95
107
|
export declare type CandleResolution = '1' | '5' | '15' | '60' | '240' | 'D' | 'W' | 'M';
|
|
96
|
-
export declare type TradeHistoryAccount = {
|
|
97
|
-
head: BN;
|
|
98
|
-
tradeRecords: TradeRecord[];
|
|
99
|
-
};
|
|
100
|
-
export declare type DepositHistoryAccount = {
|
|
101
|
-
head: BN;
|
|
102
|
-
depositRecords: DepositRecord[];
|
|
103
|
-
};
|
|
104
|
-
export declare type ExtendedCurveHistoryAccount = {
|
|
105
|
-
head: BN;
|
|
106
|
-
curveRecords: ExtendedCurveRecord[];
|
|
107
|
-
};
|
|
108
|
-
export declare type FundingRateHistoryAccount = {
|
|
109
|
-
head: BN;
|
|
110
|
-
fundingRateRecords: FundingRateRecord[];
|
|
111
|
-
};
|
|
112
|
-
export declare type FundingPaymentHistoryAccount = {
|
|
113
|
-
head: BN;
|
|
114
|
-
fundingPaymentRecords: FundingPaymentRecord[];
|
|
115
|
-
};
|
|
116
|
-
export declare type LiquidationHistoryAccount = {
|
|
117
|
-
head: BN;
|
|
118
|
-
liquidationRecords: LiquidationRecord[];
|
|
119
|
-
};
|
|
120
|
-
export declare type OrderHistoryAccount = {
|
|
121
|
-
head: BN;
|
|
122
|
-
lastOrderId: BN;
|
|
123
|
-
orderRecords: OrderRecord[];
|
|
124
|
-
};
|
|
125
108
|
export declare type DepositRecord = {
|
|
126
109
|
ts: BN;
|
|
127
|
-
recordId: BN;
|
|
128
110
|
userAuthority: PublicKey;
|
|
129
111
|
user: PublicKey;
|
|
130
112
|
direction: {
|
|
131
113
|
deposit?: any;
|
|
132
114
|
withdraw?: any;
|
|
133
115
|
};
|
|
134
|
-
|
|
135
|
-
cumulativeDepositsBefore: BN;
|
|
116
|
+
bankIndex: BN;
|
|
136
117
|
amount: BN;
|
|
118
|
+
from?: PublicKey;
|
|
119
|
+
to?: PublicKey;
|
|
137
120
|
};
|
|
138
|
-
export declare type
|
|
121
|
+
export declare type CurveRecord = {
|
|
139
122
|
ts: BN;
|
|
140
123
|
recordId: BN;
|
|
141
124
|
marketIndex: BN;
|
|
@@ -154,27 +137,6 @@ export declare type ExtendedCurveRecord = {
|
|
|
154
137
|
oraclePrice: BN;
|
|
155
138
|
tradeId: BN;
|
|
156
139
|
};
|
|
157
|
-
export declare type TradeRecord = {
|
|
158
|
-
ts: BN;
|
|
159
|
-
recordId: BN;
|
|
160
|
-
userAuthority: PublicKey;
|
|
161
|
-
user: PublicKey;
|
|
162
|
-
direction: {
|
|
163
|
-
long?: any;
|
|
164
|
-
short?: any;
|
|
165
|
-
};
|
|
166
|
-
baseAssetAmount: BN;
|
|
167
|
-
quoteAssetAmount: BN;
|
|
168
|
-
markPriceBefore: BN;
|
|
169
|
-
markPriceAfter: BN;
|
|
170
|
-
fee: BN;
|
|
171
|
-
quoteAssetAmountSurplus: BN;
|
|
172
|
-
refereeDiscount: BN;
|
|
173
|
-
tokenDiscount: BN;
|
|
174
|
-
marketIndex: BN;
|
|
175
|
-
liquidation: boolean;
|
|
176
|
-
oraclePrice: BN;
|
|
177
|
-
};
|
|
178
140
|
export declare type FundingRateRecord = {
|
|
179
141
|
ts: BN;
|
|
180
142
|
recordId: BN;
|
|
@@ -187,7 +149,6 @@ export declare type FundingRateRecord = {
|
|
|
187
149
|
};
|
|
188
150
|
export declare type FundingPaymentRecord = {
|
|
189
151
|
ts: BN;
|
|
190
|
-
recordId: BN;
|
|
191
152
|
userAuthority: PublicKey;
|
|
192
153
|
user: PublicKey;
|
|
193
154
|
marketIndex: BN;
|
|
@@ -217,41 +178,33 @@ export declare type LiquidationRecord = {
|
|
|
217
178
|
};
|
|
218
179
|
export declare type OrderRecord = {
|
|
219
180
|
ts: BN;
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
181
|
+
taker: PublicKey;
|
|
182
|
+
maker: PublicKey;
|
|
183
|
+
takerOrder: Order;
|
|
184
|
+
makerOrder: Order;
|
|
224
185
|
action: OrderAction;
|
|
225
186
|
filler: PublicKey;
|
|
187
|
+
fillRecordId: BN;
|
|
188
|
+
marketIndex: BN;
|
|
226
189
|
baseAssetAmountFilled: BN;
|
|
227
190
|
quoteAssetAmountFilled: BN;
|
|
228
|
-
|
|
191
|
+
makerRebate: BN;
|
|
192
|
+
takerFee: BN;
|
|
229
193
|
fillerReward: BN;
|
|
230
|
-
tradeRecordId: BN;
|
|
231
194
|
quoteAssetAmountSurplus: BN;
|
|
195
|
+
oraclePrice: BN;
|
|
232
196
|
};
|
|
233
197
|
export declare type StateAccount = {
|
|
234
198
|
admin: PublicKey;
|
|
235
199
|
fundingPaused: boolean;
|
|
236
200
|
exchangePaused: boolean;
|
|
237
201
|
adminControlsPrices: boolean;
|
|
238
|
-
collateralMint: PublicKey;
|
|
239
|
-
collateralVault: PublicKey;
|
|
240
|
-
collateralVaultAuthority: PublicKey;
|
|
241
|
-
collateralVaultNonce: number;
|
|
242
202
|
insuranceVault: PublicKey;
|
|
243
203
|
insuranceVaultAuthority: PublicKey;
|
|
244
204
|
insuranceVaultNonce: number;
|
|
245
205
|
marginRatioInitial: BN;
|
|
246
206
|
marginRatioMaintenance: BN;
|
|
247
207
|
marginRatioPartial: BN;
|
|
248
|
-
markets: PublicKey;
|
|
249
|
-
curveHistory: PublicKey;
|
|
250
|
-
depositHistory: PublicKey;
|
|
251
|
-
fundingRateHistory: PublicKey;
|
|
252
|
-
fundingPaymentHistory: PublicKey;
|
|
253
|
-
tradeHistory: PublicKey;
|
|
254
|
-
liquidationHistory: PublicKey;
|
|
255
208
|
partialLiquidationClosePercentageNumerator: BN;
|
|
256
209
|
partialLiquidationClosePercentageDenominator: BN;
|
|
257
210
|
partialLiquidationPenaltyPercentageNumerator: BN;
|
|
@@ -267,27 +220,49 @@ export declare type StateAccount = {
|
|
|
267
220
|
discountMint: PublicKey;
|
|
268
221
|
oracleGuardRails: OracleGuardRails;
|
|
269
222
|
maxDeposit: BN;
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
};
|
|
273
|
-
export declare type OrderStateAccount = {
|
|
274
|
-
orderHistory: PublicKey;
|
|
275
|
-
orderFillerRewardStructure: OrderFillerRewardStructure;
|
|
223
|
+
numberOfMarkets: BN;
|
|
224
|
+
numberOfBanks: BN;
|
|
276
225
|
minOrderQuoteAssetAmount: BN;
|
|
277
226
|
};
|
|
278
|
-
export declare type
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
227
|
+
export declare type MarketAccount = {
|
|
228
|
+
initialized: boolean;
|
|
229
|
+
marketIndex: BN;
|
|
230
|
+
pubkey: PublicKey;
|
|
282
231
|
amm: AMM;
|
|
283
232
|
baseAssetAmount: BN;
|
|
284
233
|
baseAssetAmountLong: BN;
|
|
285
234
|
baseAssetAmountShort: BN;
|
|
286
|
-
initialized: boolean;
|
|
287
235
|
openInterest: BN;
|
|
288
236
|
marginRatioInitial: number;
|
|
289
237
|
marginRatioMaintenance: number;
|
|
290
238
|
marginRatioPartial: number;
|
|
239
|
+
nextFillRecordId: BN;
|
|
240
|
+
pnlPool: PoolBalance;
|
|
241
|
+
};
|
|
242
|
+
export declare type BankAccount = {
|
|
243
|
+
bankIndex: BN;
|
|
244
|
+
pubkey: PublicKey;
|
|
245
|
+
mint: PublicKey;
|
|
246
|
+
vault: PublicKey;
|
|
247
|
+
vaultAuthority: PublicKey;
|
|
248
|
+
vaultAuthorityNonce: number;
|
|
249
|
+
decimals: number;
|
|
250
|
+
optimalUtilization: BN;
|
|
251
|
+
optimalBorrowRate: BN;
|
|
252
|
+
maxBorrowRate: BN;
|
|
253
|
+
cumulativeDepositInterest: BN;
|
|
254
|
+
cumulativeBorrowInterest: BN;
|
|
255
|
+
depositBalance: BN;
|
|
256
|
+
borrowBalance: BN;
|
|
257
|
+
lastUpdated: BN;
|
|
258
|
+
oracle: PublicKey;
|
|
259
|
+
initialAssetWeight: BN;
|
|
260
|
+
maintenanceAssetWeight: BN;
|
|
261
|
+
initialLiabilityWeight: BN;
|
|
262
|
+
maintenanceLiabilityWeight: BN;
|
|
263
|
+
};
|
|
264
|
+
export declare type PoolBalance = {
|
|
265
|
+
balance: BN;
|
|
291
266
|
};
|
|
292
267
|
export declare type AMM = {
|
|
293
268
|
baseAssetReserve: BN;
|
|
@@ -312,45 +287,66 @@ export declare type AMM = {
|
|
|
312
287
|
totalFeeWithdrawn: BN;
|
|
313
288
|
totalFee: BN;
|
|
314
289
|
minimumQuoteAssetTradeSize: BN;
|
|
315
|
-
|
|
290
|
+
baseAssetAmountStepSize: BN;
|
|
316
291
|
lastOraclePrice: BN;
|
|
317
292
|
baseSpread: number;
|
|
293
|
+
curveUpdateIntensity: number;
|
|
294
|
+
netBaseAssetAmount: BN;
|
|
295
|
+
quoteAssetAmountLong: BN;
|
|
296
|
+
quoteAssetAmountShort: BN;
|
|
297
|
+
terminalQuoteAssetReserve: BN;
|
|
298
|
+
feePool: PoolBalance;
|
|
299
|
+
totalExchangeFee: BN;
|
|
300
|
+
totalMmFee: BN;
|
|
301
|
+
netRevenueSinceLastFunding: BN;
|
|
302
|
+
lastUpdateSlot: BN;
|
|
303
|
+
lastBidPriceTwap: BN;
|
|
304
|
+
lastAskPriceTwap: BN;
|
|
305
|
+
longSpread: BN;
|
|
306
|
+
shortSpread: BN;
|
|
318
307
|
};
|
|
319
308
|
export declare type UserPosition = {
|
|
320
309
|
baseAssetAmount: BN;
|
|
321
310
|
lastCumulativeFundingRate: BN;
|
|
322
311
|
marketIndex: BN;
|
|
323
312
|
quoteAssetAmount: BN;
|
|
313
|
+
quoteEntryAmount: BN;
|
|
324
314
|
openOrders: BN;
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
user: PublicKey;
|
|
315
|
+
unsettledPnl: BN;
|
|
316
|
+
openBids: BN;
|
|
317
|
+
openAsks: BN;
|
|
329
318
|
};
|
|
330
319
|
export declare type UserAccount = {
|
|
331
320
|
authority: PublicKey;
|
|
321
|
+
name: number[];
|
|
322
|
+
userId: number;
|
|
323
|
+
bankBalances: UserBankBalance[];
|
|
332
324
|
collateral: BN;
|
|
333
325
|
cumulativeDeposits: BN;
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
};
|
|
341
|
-
|
|
326
|
+
fees: {
|
|
327
|
+
totalFeePaid: BN;
|
|
328
|
+
totalFeeRebate: BN;
|
|
329
|
+
totalTokenDiscount: BN;
|
|
330
|
+
totalReferralReward: BN;
|
|
331
|
+
totalRefereeDiscount: BN;
|
|
332
|
+
};
|
|
333
|
+
positions: UserPosition[];
|
|
342
334
|
orders: Order[];
|
|
343
|
-
|
|
335
|
+
};
|
|
336
|
+
export declare type UserBankBalance = {
|
|
337
|
+
bankIndex: BN;
|
|
338
|
+
balanceType: BankBalanceType;
|
|
339
|
+
balance: BN;
|
|
344
340
|
};
|
|
345
341
|
export declare type Order = {
|
|
346
342
|
status: OrderStatus;
|
|
347
343
|
orderType: OrderType;
|
|
348
344
|
ts: BN;
|
|
345
|
+
slot: BN;
|
|
349
346
|
orderId: BN;
|
|
350
347
|
userOrderId: number;
|
|
351
348
|
marketIndex: BN;
|
|
352
349
|
price: BN;
|
|
353
|
-
userBaseAssetAmount: BN;
|
|
354
350
|
baseAssetAmount: BN;
|
|
355
351
|
baseAssetAmountFilled: BN;
|
|
356
352
|
quoteAssetAmount: BN;
|
|
@@ -361,10 +357,14 @@ export declare type Order = {
|
|
|
361
357
|
triggerPrice: BN;
|
|
362
358
|
triggerCondition: OrderTriggerCondition;
|
|
363
359
|
discountTier: OrderDiscountTier;
|
|
360
|
+
existingPositionDirection: PositionDirection;
|
|
364
361
|
referrer: PublicKey;
|
|
365
362
|
postOnly: boolean;
|
|
366
363
|
immediateOrCancel: boolean;
|
|
367
364
|
oraclePriceOffset: BN;
|
|
365
|
+
auctionDuration: number;
|
|
366
|
+
auctionStartPrice: BN;
|
|
367
|
+
auctionEndPrice: BN;
|
|
368
368
|
};
|
|
369
369
|
export declare type OrderParams = {
|
|
370
370
|
orderType: OrderType;
|
|
@@ -388,6 +388,10 @@ export declare type OrderParams = {
|
|
|
388
388
|
referrer: boolean;
|
|
389
389
|
};
|
|
390
390
|
};
|
|
391
|
+
export declare type MakerInfo = {
|
|
392
|
+
maker: PublicKey;
|
|
393
|
+
order: Order;
|
|
394
|
+
};
|
|
391
395
|
export interface IWallet {
|
|
392
396
|
signTransaction(tx: Transaction): Promise<Transaction>;
|
|
393
397
|
signAllTransactions(txs: Transaction[]): Promise<Transaction[]>;
|
|
@@ -424,6 +428,9 @@ export declare type FeeStructure = {
|
|
|
424
428
|
refereeDiscountNumerator: BN;
|
|
425
429
|
refereeDiscountDenominator: BN;
|
|
426
430
|
};
|
|
431
|
+
makerRebateNumerator: BN;
|
|
432
|
+
makerRebateDenominator: BN;
|
|
433
|
+
fillerRewardStructure: OrderFillerRewardStructure;
|
|
427
434
|
};
|
|
428
435
|
export declare type OracleGuardRails = {
|
|
429
436
|
priceDivergence: {
|