@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/tests/bn/test.ts
ADDED
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { BN } from '@project-serum/anchor';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
import { BigNum } from '../../src/factory/bigNum';
|
|
4
|
+
import {
|
|
5
|
+
AMM_RESERVE_PRECISION_EXP,
|
|
6
|
+
BASE_PRECISION_EXP,
|
|
7
|
+
TEN_THOUSAND,
|
|
8
|
+
} from '../../src/constants/numericConstants';
|
|
9
|
+
// if you used the '@types/mocha' method to install mocha type definitions, uncomment the following line
|
|
10
|
+
// import 'mocha';
|
|
11
|
+
|
|
12
|
+
describe('BigNum Tests', () => {
|
|
13
|
+
it('basic string representations are correct', () => {
|
|
14
|
+
const bn = BigNum.from(TEN_THOUSAND);
|
|
15
|
+
expect(bn.toString()).to.equal('10000');
|
|
16
|
+
expect(bn.print()).to.equal('10000');
|
|
17
|
+
|
|
18
|
+
const bn2 = BigNum.from(TEN_THOUSAND, new BN(4));
|
|
19
|
+
expect(bn2.toString()).to.equal('10000');
|
|
20
|
+
expect(bn2.print()).to.equal('1.0000');
|
|
21
|
+
|
|
22
|
+
const bn3 = BigNum.from(new BN('123456789'), new BN(4));
|
|
23
|
+
expect(bn3.toString()).to.equal('123456789');
|
|
24
|
+
expect(bn3.print()).to.equal('12345.6789');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('can do basic maths correctly', () => {
|
|
28
|
+
const val1 = BigNum.from(10 ** 4, 2).mul(BigNum.from(123456));
|
|
29
|
+
|
|
30
|
+
expect(val1.toString()).to.equal('1234560000');
|
|
31
|
+
|
|
32
|
+
// should trim one point of precision off
|
|
33
|
+
const val2 = val1.div(BigNum.from(10 ** 5));
|
|
34
|
+
|
|
35
|
+
expect(val2.toString()).to.equal('12345');
|
|
36
|
+
expect(val2.print()).to.equal('123.45');
|
|
37
|
+
|
|
38
|
+
// Trying to represent a 33.33333333% figure to precision 4
|
|
39
|
+
const baseNumberPrecision = 10;
|
|
40
|
+
const adjustmentPrecision = 4;
|
|
41
|
+
|
|
42
|
+
const currentNumber = 400 * 10 ** baseNumberPrecision;
|
|
43
|
+
const comparisonNumber = 300 * 10 ** baseNumberPrecision;
|
|
44
|
+
|
|
45
|
+
const val3 = BigNum.from(currentNumber, baseNumberPrecision)
|
|
46
|
+
.sub(BigNum.from(comparisonNumber, baseNumberPrecision))
|
|
47
|
+
.mul(BigNum.from(10 ** adjustmentPrecision, adjustmentPrecision))
|
|
48
|
+
.mul(BigNum.from(100))
|
|
49
|
+
.div(BigNum.from(comparisonNumber, baseNumberPrecision))
|
|
50
|
+
.abs();
|
|
51
|
+
|
|
52
|
+
expect(val3.toString()).to.equal('333333');
|
|
53
|
+
expect(val3.print()).to.equal('33.3333');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('can shift numbers correctly', () => {
|
|
57
|
+
const val1 = BigNum.from(new BN(`319657850313098510000000000`), 23).shift(
|
|
58
|
+
new BN(-10)
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
expect(val1.toString()).to.equal(`31965785031309851`);
|
|
62
|
+
expect(val1.print()).to.equal(`3196.5785031309851`);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('can print numbers correctly', () => {
|
|
66
|
+
// Case 1
|
|
67
|
+
const val = BigNum.from(123456789, 5);
|
|
68
|
+
|
|
69
|
+
expect(val.toString()).to.equal('123456789');
|
|
70
|
+
|
|
71
|
+
expect(val.print()).to.equal('1234.56789');
|
|
72
|
+
|
|
73
|
+
expect(val.toFixed(3)).to.equal('1234.567');
|
|
74
|
+
|
|
75
|
+
expect(val.toPrecision(1)).to.equal('1e3');
|
|
76
|
+
expect(val.toPrecision(3)).to.equal('123e1');
|
|
77
|
+
expect(val.toPrecision(4)).to.equal('1234');
|
|
78
|
+
expect(val.toPrecision(5)).to.equal('1234.5');
|
|
79
|
+
expect(val.toPrecision(11)).to.equal('1234.5678900');
|
|
80
|
+
|
|
81
|
+
// Case 2
|
|
82
|
+
const val2 = BigNum.from(1, 5);
|
|
83
|
+
|
|
84
|
+
expect(val2.toString()).to.equal('1');
|
|
85
|
+
|
|
86
|
+
expect(val2.print()).to.equal('0.00001');
|
|
87
|
+
|
|
88
|
+
// Case 3
|
|
89
|
+
const val3 = BigNum.from(101003, 5);
|
|
90
|
+
|
|
91
|
+
expect(val3.toString()).to.equal('101003');
|
|
92
|
+
|
|
93
|
+
expect(val3.print()).to.equal('1.01003');
|
|
94
|
+
expect(val3.toPrecision(7)).to.equal('1.010030');
|
|
95
|
+
|
|
96
|
+
// Case 4
|
|
97
|
+
const rawQuoteValue = 1;
|
|
98
|
+
const entryPriceNum = 40;
|
|
99
|
+
const val4 = BigNum.from(rawQuoteValue * 10 ** 8)
|
|
100
|
+
.shift(AMM_RESERVE_PRECISION_EXP)
|
|
101
|
+
.div(BigNum.from(entryPriceNum * 10 ** 8));
|
|
102
|
+
|
|
103
|
+
expect(val4.toString()).to.equal('250000000000');
|
|
104
|
+
expect(val4.print()).to.equal('0.0250000000000');
|
|
105
|
+
expect(val4.toFixed(3)).to.equal('0.025');
|
|
106
|
+
expect(val4.toPrecision(4)).to.equal('0.025');
|
|
107
|
+
|
|
108
|
+
// Case 5
|
|
109
|
+
expect(BigNum.fromPrint('1').toMillified()).to.equal('1.00');
|
|
110
|
+
expect(BigNum.fromPrint('12').toMillified()).to.equal('12.0');
|
|
111
|
+
expect(BigNum.fromPrint('123').toMillified()).to.equal('123');
|
|
112
|
+
expect(BigNum.fromPrint('1234').toMillified()).to.equal('1.23K');
|
|
113
|
+
expect(BigNum.fromPrint('12345').toMillified()).to.equal('12.3K');
|
|
114
|
+
expect(BigNum.fromPrint('123456').toMillified()).to.equal('123K');
|
|
115
|
+
expect(BigNum.fromPrint('1234567').toMillified()).to.equal('1.23M');
|
|
116
|
+
expect(BigNum.fromPrint('12345678').toMillified()).to.equal('12.3M');
|
|
117
|
+
expect(BigNum.fromPrint('123456789').toMillified()).to.equal('123M');
|
|
118
|
+
|
|
119
|
+
expect(BigNum.fromPrint('1').toMillified(5)).to.equal('1.0000');
|
|
120
|
+
expect(BigNum.fromPrint('12').toMillified(5)).to.equal('12.000');
|
|
121
|
+
expect(BigNum.fromPrint('123').toMillified(5)).to.equal('123.00');
|
|
122
|
+
expect(BigNum.fromPrint('1234').toMillified(5)).to.equal('1.2340K');
|
|
123
|
+
expect(BigNum.fromPrint('12345').toMillified(5)).to.equal('12.345K');
|
|
124
|
+
expect(BigNum.fromPrint('123456').toMillified(5)).to.equal('123.45K');
|
|
125
|
+
expect(BigNum.fromPrint('1234567').toMillified(5)).to.equal('1.2345M');
|
|
126
|
+
expect(BigNum.fromPrint('12345678').toMillified(5)).to.equal('12.345M');
|
|
127
|
+
expect(BigNum.fromPrint('123456789').toMillified(5)).to.equal('123.45M');
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('can initialise from string values correctly', () => {
|
|
131
|
+
// Case 1
|
|
132
|
+
|
|
133
|
+
const baseAmountVal1 = '14.33';
|
|
134
|
+
const val1 = BigNum.fromPrint(baseAmountVal1, BASE_PRECISION_EXP);
|
|
135
|
+
|
|
136
|
+
expect(val1.toString()).to.equal('143300000000000');
|
|
137
|
+
expect(val1.print()).to.equal('14.3300000000000');
|
|
138
|
+
|
|
139
|
+
const baseAmountVal2 = '34.1';
|
|
140
|
+
const val2 = BigNum.fromPrint(baseAmountVal2, BASE_PRECISION_EXP);
|
|
141
|
+
|
|
142
|
+
expect(val2.printShort()).to.equal('34.1');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('is immutable', () => {
|
|
146
|
+
// Case 1
|
|
147
|
+
const initVal = BigNum.from(1);
|
|
148
|
+
const postShift = initVal.shift(new BN(10), true);
|
|
149
|
+
const postScale = postShift.scale(1, 10 ** 10);
|
|
150
|
+
|
|
151
|
+
expect(initVal.toString()).to.equal(postScale.toString());
|
|
152
|
+
expect(initVal === postShift).to.equal(false);
|
|
153
|
+
expect(initVal.val === postShift.val).to.equal(false);
|
|
154
|
+
expect(initVal === postScale).to.equal(false);
|
|
155
|
+
expect(initVal.val === postScale.val).to.equal(false);
|
|
156
|
+
expect(postShift === postScale).to.equal(false);
|
|
157
|
+
expect(postShift.val === postScale.val).to.equal(false);
|
|
158
|
+
|
|
159
|
+
const postMul = postScale.mul(new BN(1000));
|
|
160
|
+
const postDiv = postMul.div(new BN(1000));
|
|
161
|
+
|
|
162
|
+
expect(postMul.toString()).to.equal('1000');
|
|
163
|
+
expect(postDiv.toString()).to.equal('1');
|
|
164
|
+
expect(postMul === postDiv).to.equal(false);
|
|
165
|
+
expect(postMul.val === postDiv.val).to.equal(false);
|
|
166
|
+
|
|
167
|
+
const postAdd = postDiv.add(BigNum.from(new BN(1000)));
|
|
168
|
+
const postSub = postAdd.sub(BigNum.from(new BN(1000)));
|
|
169
|
+
|
|
170
|
+
expect(postAdd.toString()).to.equal('1001');
|
|
171
|
+
expect(postSub.toString()).to.equal('1');
|
|
172
|
+
expect(postAdd === postSub).to.equal(false);
|
|
173
|
+
expect(postAdd.val === postSub.val).to.equal(false);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('serializes properly', () => {
|
|
177
|
+
// JSON
|
|
178
|
+
let val = BigNum.from(new BN('123456'), 3);
|
|
179
|
+
expect(val.toString()).to.equal('123456');
|
|
180
|
+
val = val.shift(new BN(3));
|
|
181
|
+
expect(val.toString()).to.equal('123456000');
|
|
182
|
+
expect(val.print()).to.equal('123.456000');
|
|
183
|
+
|
|
184
|
+
const stringified = JSON.stringify(val);
|
|
185
|
+
|
|
186
|
+
expect(stringified).to.equal('{"val":"123456000","precision":"6"}');
|
|
187
|
+
|
|
188
|
+
let parsed = BigNum.fromJSON(JSON.parse(stringified));
|
|
189
|
+
expect(parsed.toString()).to.equal('123456000');
|
|
190
|
+
expect(parsed.print()).to.equal('123.456000');
|
|
191
|
+
|
|
192
|
+
parsed = parsed.shift(new BN(3));
|
|
193
|
+
expect(parsed.toString()).to.equal('123456000000');
|
|
194
|
+
expect(parsed.print()).to.equal('123.456000000');
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it('can convert to a percentage', () => {
|
|
198
|
+
// JSON
|
|
199
|
+
const val = BigNum.from(new BN('100000'), 3);
|
|
200
|
+
const val2 = BigNum.from(new BN('200000'), 3);
|
|
201
|
+
const val3 = BigNum.from(new BN('66666'), 3);
|
|
202
|
+
const val4 = BigNum.from(new BN('50000'), 3);
|
|
203
|
+
const val5 = BigNum.from(new BN('700000'), 3);
|
|
204
|
+
|
|
205
|
+
expect(val.toPercentage(val2, 3)).to.equal('50.0');
|
|
206
|
+
expect(val.toPercentage(val2, 4)).to.equal('50.00');
|
|
207
|
+
expect(val3.toPercentage(val2, 4)).to.equal('33.33');
|
|
208
|
+
expect(val4.toPercentage(val2, 4)).to.equal('25.00');
|
|
209
|
+
expect(val.toPercentage(val5, 6)).to.equal('14.2857');
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('can print without unnecessary trailing zeroes', () => {
|
|
213
|
+
const rawQuoteValue = 1;
|
|
214
|
+
const entryPriceNum = 40;
|
|
215
|
+
const val = BigNum.from(rawQuoteValue * 10 ** 8)
|
|
216
|
+
.shift(AMM_RESERVE_PRECISION_EXP)
|
|
217
|
+
.div(BigNum.from(entryPriceNum * 10 ** 8));
|
|
218
|
+
|
|
219
|
+
expect(val.toString()).to.equal('250000000000');
|
|
220
|
+
expect(val.printShort()).to.equal('0.025');
|
|
221
|
+
|
|
222
|
+
const val2 = BigNum.from(10000, 4);
|
|
223
|
+
expect(val2.print()).to.equal('1.0000');
|
|
224
|
+
expect(val2.printShort()).to.equal('1');
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it('can pretty print', () => {
|
|
228
|
+
const val = BigNum.from('123');
|
|
229
|
+
expect(val.prettyPrint()).to.equal('123');
|
|
230
|
+
|
|
231
|
+
const val2 = BigNum.from('1234');
|
|
232
|
+
expect(val2.prettyPrint()).to.equal('1,234');
|
|
233
|
+
|
|
234
|
+
const val3 = BigNum.from('123456');
|
|
235
|
+
expect(val3.prettyPrint()).to.equal('123,456');
|
|
236
|
+
|
|
237
|
+
const val4 = BigNum.from('1234567');
|
|
238
|
+
expect(val4.prettyPrint()).to.equal('1,234,567');
|
|
239
|
+
|
|
240
|
+
const val5 = BigNum.from('12345678');
|
|
241
|
+
expect(val5.prettyPrint()).to.equal('12,345,678');
|
|
242
|
+
|
|
243
|
+
const val6 = BigNum.from('123456', 3);
|
|
244
|
+
expect(val6.prettyPrint()).to.equal('123.456');
|
|
245
|
+
|
|
246
|
+
const val7 = BigNum.from('123456789', 3);
|
|
247
|
+
expect(val7.prettyPrint()).to.equal('123,456.789');
|
|
248
|
+
|
|
249
|
+
const val8 = BigNum.from('1000000000000', 6);
|
|
250
|
+
expect(val8.prettyPrint()).to.equal('1,000,000');
|
|
251
|
+
|
|
252
|
+
const val9 = BigNum.from('1000000000123', 6);
|
|
253
|
+
expect(val9.prettyPrint()).to.equal('1,000,000.000123');
|
|
254
|
+
});
|
|
255
|
+
});
|
package/tsconfig.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"target": "ES2019",
|
|
5
|
+
"esModuleInterop": true,
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"outDir": "./lib",
|
|
8
|
+
"resolveJsonModule": true,
|
|
9
|
+
"skipLibCheck": true
|
|
10
|
+
},
|
|
11
|
+
"include": ["src"],
|
|
12
|
+
"exclude": ["node_modules", "tests"]
|
|
13
|
+
}
|
package/lib/addresses.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { PublicKey } from '@solana/web3.js';
|
|
2
|
-
export declare function getClearingHouseStateAccountPublicKeyAndNonce(programId: PublicKey): Promise<[PublicKey, number]>;
|
|
3
|
-
export declare function getOrderStateAccountPublicKey(programId: PublicKey): Promise<PublicKey>;
|
|
4
|
-
export declare function getOrderStateAccountPublicKeyAndNonce(programId: PublicKey): Promise<[PublicKey, number]>;
|
|
5
|
-
export declare function getClearingHouseStateAccountPublicKey(programId: PublicKey): Promise<PublicKey>;
|
|
6
|
-
export declare function getUserAccountPublicKeyAndNonce(programId: PublicKey, authority: PublicKey): Promise<[PublicKey, number]>;
|
|
7
|
-
export declare function getUserAccountPublicKey(programId: PublicKey, authority: PublicKey): Promise<PublicKey>;
|
|
8
|
-
export declare function getUserOrdersAccountPublicKeyAndNonce(programId: PublicKey, userAccount: PublicKey): Promise<[PublicKey, number]>;
|
|
9
|
-
export declare function getUserOrdersAccountPublicKey(programId: PublicKey, userAccount: PublicKey): Promise<PublicKey>;
|
package/lib/addresses.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.getUserOrdersAccountPublicKey = exports.getUserOrdersAccountPublicKeyAndNonce = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getClearingHouseStateAccountPublicKey = exports.getOrderStateAccountPublicKeyAndNonce = exports.getOrderStateAccountPublicKey = exports.getClearingHouseStateAccountPublicKeyAndNonce = void 0;
|
|
36
|
-
const anchor = __importStar(require("@project-serum/anchor"));
|
|
37
|
-
function getClearingHouseStateAccountPublicKeyAndNonce(programId) {
|
|
38
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
-
return anchor.web3.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('clearing_house'))], programId);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
exports.getClearingHouseStateAccountPublicKeyAndNonce = getClearingHouseStateAccountPublicKeyAndNonce;
|
|
43
|
-
function getOrderStateAccountPublicKey(programId) {
|
|
44
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
return (yield getOrderStateAccountPublicKeyAndNonce(programId))[0];
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
exports.getOrderStateAccountPublicKey = getOrderStateAccountPublicKey;
|
|
49
|
-
function getOrderStateAccountPublicKeyAndNonce(programId) {
|
|
50
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
return anchor.web3.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('order_state'))], programId);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
exports.getOrderStateAccountPublicKeyAndNonce = getOrderStateAccountPublicKeyAndNonce;
|
|
55
|
-
function getClearingHouseStateAccountPublicKey(programId) {
|
|
56
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
return (yield getClearingHouseStateAccountPublicKeyAndNonce(programId))[0];
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
exports.getClearingHouseStateAccountPublicKey = getClearingHouseStateAccountPublicKey;
|
|
61
|
-
function getUserAccountPublicKeyAndNonce(programId, authority) {
|
|
62
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
-
return anchor.web3.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('user')), authority.toBuffer()], programId);
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
exports.getUserAccountPublicKeyAndNonce = getUserAccountPublicKeyAndNonce;
|
|
67
|
-
function getUserAccountPublicKey(programId, authority) {
|
|
68
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
return (yield getUserAccountPublicKeyAndNonce(programId, authority))[0];
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
exports.getUserAccountPublicKey = getUserAccountPublicKey;
|
|
73
|
-
function getUserOrdersAccountPublicKeyAndNonce(programId, userAccount) {
|
|
74
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
-
return anchor.web3.PublicKey.findProgramAddress([
|
|
76
|
-
Buffer.from(anchor.utils.bytes.utf8.encode('user_orders')),
|
|
77
|
-
userAccount.toBuffer(),
|
|
78
|
-
], programId);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
exports.getUserOrdersAccountPublicKeyAndNonce = getUserOrdersAccountPublicKeyAndNonce;
|
|
82
|
-
function getUserOrdersAccountPublicKey(programId, userAccount) {
|
|
83
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
84
|
-
return (yield getUserOrdersAccountPublicKeyAndNonce(programId, userAccount))[0];
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
exports.getUserOrdersAccountPublicKey = getUserOrdersAccountPublicKey;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { PublicKey } from '@solana/web3.js';
|
|
2
|
-
export declare const CLEARING_HOUSE_STATE_ACCOUNTS: {
|
|
3
|
-
dammHkt7jmytvbS3nHTxQNEcP59aE57nxwV21YdqEDN: {
|
|
4
|
-
state: PublicKey;
|
|
5
|
-
markets: PublicKey;
|
|
6
|
-
orderState: PublicKey;
|
|
7
|
-
tradeHistory: PublicKey;
|
|
8
|
-
depositHistory: PublicKey;
|
|
9
|
-
fundingPaymentHistory: PublicKey;
|
|
10
|
-
fundingRateHistory: PublicKey;
|
|
11
|
-
extendedCurveHistory: PublicKey;
|
|
12
|
-
liquidationHistory: PublicKey;
|
|
13
|
-
orderHistory: PublicKey;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CLEARING_HOUSE_STATE_ACCOUNTS = void 0;
|
|
4
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
-
exports.CLEARING_HOUSE_STATE_ACCOUNTS = {
|
|
6
|
-
dammHkt7jmytvbS3nHTxQNEcP59aE57nxwV21YdqEDN: {
|
|
7
|
-
state: new web3_js_1.PublicKey('FExhvPycCCwYnZGeDsVtLhpEQ3yEkVY2k1HuPyfLj91L'),
|
|
8
|
-
markets: new web3_js_1.PublicKey('773hq3SbGPKVj93TXi5qV5CREuhxobywfALjS3XVHhLH'),
|
|
9
|
-
orderState: new web3_js_1.PublicKey('4cC34bWwTPGncBaX2S6v5mH3Lj4Nb3byPMrxQSDcY985'),
|
|
10
|
-
tradeHistory: new web3_js_1.PublicKey('FCuCXEoQppoaCYdttA7rK3HNQfYkTNEGpwuBESzYcENp'),
|
|
11
|
-
depositHistory: new web3_js_1.PublicKey('C7rF2Qy2rnDGQLRijBRRArJyaeuQcFi81BXDrUCQ45ya'),
|
|
12
|
-
fundingPaymentHistory: new web3_js_1.PublicKey('895iPhzwT2tBufLnRpYtBG3gif1HDDUfpH2AqbS5joo4'),
|
|
13
|
-
fundingRateHistory: new web3_js_1.PublicKey('BWiJLMbmrwfqHVpcPJa8715XamNyNYamDDKQVQMnduEC'),
|
|
14
|
-
extendedCurveHistory: new web3_js_1.PublicKey('7vBbqvMdtZLQdTVdzt5y63pZdAFE5W42kP3avngSJKCk'),
|
|
15
|
-
liquidationHistory: new web3_js_1.PublicKey('CSFaaf8yVoTx6NcXUKtNPYAewv76CH2jATqSVRBvUWKM'),
|
|
16
|
-
orderHistory: new web3_js_1.PublicKey('DZ7XfUqyHoRKnJLRApxmJ943xHJ7NDBUTqpbooviEtbU'),
|
|
17
|
-
},
|
|
18
|
-
};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { ConfirmOptions, Connection, PublicKey } from '@solana/web3.js';
|
|
2
|
-
import { IWallet } from '../types';
|
|
3
|
-
import { BulkAccountLoader } from '../accounts/bulkAccountLoader';
|
|
4
|
-
import { ClearingHouse } from '../clearingHouse';
|
|
5
|
-
import { Admin } from '../admin';
|
|
6
|
-
export declare type ClearingHouseConfigType = 'websocket' | 'polling' | 'custom';
|
|
7
|
-
declare type BaseClearingHouseConfig = {
|
|
8
|
-
type: ClearingHouseConfigType;
|
|
9
|
-
connection: Connection;
|
|
10
|
-
wallet: IWallet;
|
|
11
|
-
programID: PublicKey;
|
|
12
|
-
opts?: ConfirmOptions;
|
|
13
|
-
txSenderConfig?: TxSenderConfig;
|
|
14
|
-
};
|
|
15
|
-
declare type WebSocketClearingHouseConfiguration = BaseClearingHouseConfig;
|
|
16
|
-
declare type PollingClearingHouseConfiguration = BaseClearingHouseConfig & {
|
|
17
|
-
accountLoader: BulkAccountLoader;
|
|
18
|
-
};
|
|
19
|
-
declare type ClearingHouseConfig = PollingClearingHouseConfiguration | WebSocketClearingHouseConfiguration;
|
|
20
|
-
export declare type TxSenderType = 'default' | 'retry';
|
|
21
|
-
declare type BaseTxSenderConfig = {
|
|
22
|
-
type: TxSenderType;
|
|
23
|
-
};
|
|
24
|
-
declare type DefaultTxSenderConfig = BaseTxSenderConfig;
|
|
25
|
-
declare type RetryTxSenderConfig = BaseTxSenderConfig & {
|
|
26
|
-
timeout?: number;
|
|
27
|
-
retrySleep?: number;
|
|
28
|
-
additionalConnections?: Connection[];
|
|
29
|
-
};
|
|
30
|
-
declare type TxSenderConfig = DefaultTxSenderConfig | RetryTxSenderConfig;
|
|
31
|
-
export declare function getWebSocketClearingHouseConfig(connection: Connection, wallet: IWallet, programID: PublicKey, opts?: ConfirmOptions, txSenderConfig?: TxSenderConfig): WebSocketClearingHouseConfiguration;
|
|
32
|
-
export declare function getPollingClearingHouseConfig(connection: Connection, wallet: IWallet, programID: PublicKey, accountLoader: BulkAccountLoader, opts?: ConfirmOptions, txSenderConfig?: TxSenderConfig): PollingClearingHouseConfiguration;
|
|
33
|
-
export declare function getClearingHouse(config: ClearingHouseConfig): ClearingHouse;
|
|
34
|
-
export declare function getAdmin(config: ClearingHouseConfig): Admin;
|
|
35
|
-
export {};
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getAdmin = exports.getClearingHouse = exports.getPollingClearingHouseConfig = exports.getWebSocketClearingHouseConfig = void 0;
|
|
7
|
-
const anchor_1 = require("@project-serum/anchor");
|
|
8
|
-
const clearingHouse_1 = require("../clearingHouse");
|
|
9
|
-
const clearing_house_json_1 = __importDefault(require("../idl/clearing_house.json"));
|
|
10
|
-
const webSocketClearingHouseAccountSubscriber_1 = require("../accounts/webSocketClearingHouseAccountSubscriber");
|
|
11
|
-
const defaultTxSender_1 = require("../tx/defaultTxSender");
|
|
12
|
-
const pollingClearingHouseAccountSubscriber_1 = require("../accounts/pollingClearingHouseAccountSubscriber");
|
|
13
|
-
const admin_1 = require("../admin");
|
|
14
|
-
const retryTxSender_1 = require("../tx/retryTxSender");
|
|
15
|
-
function getWebSocketClearingHouseConfig(connection, wallet, programID, opts = anchor_1.AnchorProvider.defaultOptions(), txSenderConfig) {
|
|
16
|
-
return {
|
|
17
|
-
type: 'websocket',
|
|
18
|
-
connection,
|
|
19
|
-
wallet,
|
|
20
|
-
programID,
|
|
21
|
-
opts,
|
|
22
|
-
txSenderConfig,
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
exports.getWebSocketClearingHouseConfig = getWebSocketClearingHouseConfig;
|
|
26
|
-
function getPollingClearingHouseConfig(connection, wallet, programID, accountLoader, opts = anchor_1.AnchorProvider.defaultOptions(), txSenderConfig) {
|
|
27
|
-
return {
|
|
28
|
-
type: 'polling',
|
|
29
|
-
connection,
|
|
30
|
-
wallet,
|
|
31
|
-
programID,
|
|
32
|
-
accountLoader,
|
|
33
|
-
opts,
|
|
34
|
-
txSenderConfig,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
exports.getPollingClearingHouseConfig = getPollingClearingHouseConfig;
|
|
38
|
-
function getClearingHouse(config) {
|
|
39
|
-
var _a;
|
|
40
|
-
const provider = new anchor_1.AnchorProvider(config.connection, config.wallet, config.opts);
|
|
41
|
-
const program = new anchor_1.Program(clearing_house_json_1.default, config.programID, provider);
|
|
42
|
-
let accountSubscriber;
|
|
43
|
-
if (config.type === 'websocket') {
|
|
44
|
-
accountSubscriber = new webSocketClearingHouseAccountSubscriber_1.WebSocketClearingHouseAccountSubscriber(program);
|
|
45
|
-
}
|
|
46
|
-
else if (config.type === 'polling') {
|
|
47
|
-
accountSubscriber = new pollingClearingHouseAccountSubscriber_1.PollingClearingHouseAccountSubscriber(program, config.accountLoader);
|
|
48
|
-
}
|
|
49
|
-
let txSender;
|
|
50
|
-
if (((_a = config.txSenderConfig) === null || _a === void 0 ? void 0 : _a.type) === 'retry') {
|
|
51
|
-
const txSenderConfig = config.txSenderConfig;
|
|
52
|
-
txSender = new retryTxSender_1.RetryTxSender(provider, txSenderConfig.timeout, txSenderConfig.retrySleep, txSenderConfig.additionalConnections);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
txSender = new defaultTxSender_1.DefaultTxSender(provider);
|
|
56
|
-
}
|
|
57
|
-
return new clearingHouse_1.ClearingHouse(config.connection, config.wallet, program, accountSubscriber, txSender, config.opts);
|
|
58
|
-
}
|
|
59
|
-
exports.getClearingHouse = getClearingHouse;
|
|
60
|
-
function getAdmin(config) {
|
|
61
|
-
var _a;
|
|
62
|
-
const provider = new anchor_1.AnchorProvider(config.connection, config.wallet, config.opts);
|
|
63
|
-
const program = new anchor_1.Program(clearing_house_json_1.default, config.programID, provider);
|
|
64
|
-
let accountSubscriber;
|
|
65
|
-
if (config.type === 'websocket') {
|
|
66
|
-
accountSubscriber = new webSocketClearingHouseAccountSubscriber_1.WebSocketClearingHouseAccountSubscriber(program);
|
|
67
|
-
}
|
|
68
|
-
else if (config.type === 'polling') {
|
|
69
|
-
accountSubscriber = new pollingClearingHouseAccountSubscriber_1.PollingClearingHouseAccountSubscriber(program, config.accountLoader);
|
|
70
|
-
}
|
|
71
|
-
let txSender;
|
|
72
|
-
if (((_a = config.txSenderConfig) === null || _a === void 0 ? void 0 : _a.type) === 'retry') {
|
|
73
|
-
const txSenderConfig = config.txSenderConfig;
|
|
74
|
-
txSender = new retryTxSender_1.RetryTxSender(provider, txSenderConfig.timeout, txSenderConfig.retrySleep, txSenderConfig.additionalConnections);
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
txSender = new defaultTxSender_1.DefaultTxSender(provider);
|
|
78
|
-
}
|
|
79
|
-
return new admin_1.Admin(config.connection, config.wallet, program, accountSubscriber, txSender, config.opts);
|
|
80
|
-
}
|
|
81
|
-
exports.getAdmin = getAdmin;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { PublicKey } from '@solana/web3.js';
|
|
2
|
-
import { ClearingHouse } from '../clearingHouse';
|
|
3
|
-
import { BulkAccountLoader } from '../accounts/bulkAccountLoader';
|
|
4
|
-
import { ClearingHouseUser } from '../clearingHouseUser';
|
|
5
|
-
export declare type ClearingHouseUserConfigType = 'websocket' | 'polling' | 'custom';
|
|
6
|
-
declare type BaseClearingHouseUserConfig = {
|
|
7
|
-
type: ClearingHouseUserConfigType;
|
|
8
|
-
clearingHouse: ClearingHouse;
|
|
9
|
-
authority: PublicKey;
|
|
10
|
-
};
|
|
11
|
-
declare type WebSocketClearingHouseUserConfig = BaseClearingHouseUserConfig;
|
|
12
|
-
declare type PollingClearingHouseUserConfig = BaseClearingHouseUserConfig & {
|
|
13
|
-
accountLoader: BulkAccountLoader;
|
|
14
|
-
};
|
|
15
|
-
declare type ClearingHouseUserConfig = PollingClearingHouseUserConfig | WebSocketClearingHouseUserConfig;
|
|
16
|
-
export declare function getWebSocketClearingHouseUserConfig(clearingHouse: ClearingHouse, authority: PublicKey): WebSocketClearingHouseUserConfig;
|
|
17
|
-
export declare function getPollingClearingHouseUserConfig(clearingHouse: ClearingHouse, authority: PublicKey, accountLoader: BulkAccountLoader): PollingClearingHouseUserConfig;
|
|
18
|
-
export declare function getClearingHouseUser(config: ClearingHouseUserConfig): ClearingHouseUser;
|
|
19
|
-
export {};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getClearingHouseUser = exports.getPollingClearingHouseUserConfig = exports.getWebSocketClearingHouseUserConfig = void 0;
|
|
4
|
-
const clearingHouseUser_1 = require("../clearingHouseUser");
|
|
5
|
-
const webSocketUserAccountSubscriber_1 = require("../accounts/webSocketUserAccountSubscriber");
|
|
6
|
-
const pollingUserAccountSubscriber_1 = require("../accounts/pollingUserAccountSubscriber");
|
|
7
|
-
function getWebSocketClearingHouseUserConfig(clearingHouse, authority) {
|
|
8
|
-
return {
|
|
9
|
-
type: 'websocket',
|
|
10
|
-
clearingHouse,
|
|
11
|
-
authority,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
exports.getWebSocketClearingHouseUserConfig = getWebSocketClearingHouseUserConfig;
|
|
15
|
-
function getPollingClearingHouseUserConfig(clearingHouse, authority, accountLoader) {
|
|
16
|
-
return {
|
|
17
|
-
type: 'polling',
|
|
18
|
-
clearingHouse,
|
|
19
|
-
authority,
|
|
20
|
-
accountLoader,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
exports.getPollingClearingHouseUserConfig = getPollingClearingHouseUserConfig;
|
|
24
|
-
function getClearingHouseUser(config) {
|
|
25
|
-
let accountSubscriber;
|
|
26
|
-
if (config.type === 'websocket') {
|
|
27
|
-
accountSubscriber = new webSocketUserAccountSubscriber_1.WebSocketUserAccountSubscriber(config.clearingHouse.program, config.authority);
|
|
28
|
-
}
|
|
29
|
-
else if (config.type === 'polling') {
|
|
30
|
-
accountSubscriber = new pollingUserAccountSubscriber_1.PollingUserAccountSubscriber(config.clearingHouse.program, config.authority, config.accountLoader);
|
|
31
|
-
}
|
|
32
|
-
return new clearingHouseUser_1.ClearingHouseUser(config.clearingHouse, config.authority, accountSubscriber);
|
|
33
|
-
}
|
|
34
|
-
exports.getClearingHouseUser = getClearingHouseUser;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
|
-
import { MarketsAccount, StateAccount } from '../types';
|
|
3
|
-
import { BN } from '../';
|
|
4
|
-
import { Connection } from '@solana/web3.js';
|
|
5
|
-
/**
|
|
6
|
-
* In the case of a levered loss, the exchange first pays out undistributed fees and then the insurance fund.
|
|
7
|
-
* Thus the de facto size of the insurance fund is the amount in the insurance vault plus the sum of each markets
|
|
8
|
-
* undistributed fees.
|
|
9
|
-
*
|
|
10
|
-
* @param connection
|
|
11
|
-
* @param state
|
|
12
|
-
* @param marketsAccount
|
|
13
|
-
* @returns Precision : QUOTE_ASSET_PRECISION
|
|
14
|
-
*/
|
|
15
|
-
export declare function calculateInsuranceFundSize(connection: Connection, state: StateAccount, marketsAccount: MarketsAccount): Promise<BN>;
|
|
@@ -1,33 +0,0 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.calculateInsuranceFundSize = void 0;
|
|
13
|
-
const __1 = require("../");
|
|
14
|
-
/**
|
|
15
|
-
* In the case of a levered loss, the exchange first pays out undistributed fees and then the insurance fund.
|
|
16
|
-
* Thus the de facto size of the insurance fund is the amount in the insurance vault plus the sum of each markets
|
|
17
|
-
* undistributed fees.
|
|
18
|
-
*
|
|
19
|
-
* @param connection
|
|
20
|
-
* @param state
|
|
21
|
-
* @param marketsAccount
|
|
22
|
-
* @returns Precision : QUOTE_ASSET_PRECISION
|
|
23
|
-
*/
|
|
24
|
-
function calculateInsuranceFundSize(connection, state, marketsAccount) {
|
|
25
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
const insuranceVaultPublicKey = state.insuranceVault;
|
|
27
|
-
const insuranceVaultAmount = new __1.BN((yield connection.getTokenAccountBalance(insuranceVaultPublicKey)).value.amount);
|
|
28
|
-
return marketsAccount.markets.reduce((insuranceVaultAmount, market) => {
|
|
29
|
-
return insuranceVaultAmount.add(market.amm.totalFee.div(new __1.BN(2)));
|
|
30
|
-
}, insuranceVaultAmount);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
exports.calculateInsuranceFundSize = calculateInsuranceFundSize;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { TxSender } from './types';
|
|
2
|
-
import { ConfirmOptions, Signer, Transaction, TransactionSignature } from '@solana/web3.js';
|
|
3
|
-
import { AnchorProvider } from '@project-serum/anchor';
|
|
4
|
-
export declare class DefaultTxSender implements TxSender {
|
|
5
|
-
provider: AnchorProvider;
|
|
6
|
-
constructor(provider: AnchorProvider);
|
|
7
|
-
send(tx: Transaction, additionalSigners?: Array<Signer>, opts?: ConfirmOptions): Promise<TransactionSignature>;
|
|
8
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DefaultTxSender = void 0;
|
|
4
|
-
class DefaultTxSender {
|
|
5
|
-
constructor(provider) {
|
|
6
|
-
this.provider = provider;
|
|
7
|
-
}
|
|
8
|
-
send(tx, additionalSigners, opts) {
|
|
9
|
-
return this.provider.sendAndConfirm(tx, additionalSigners, opts);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
exports.DefaultTxSender = DefaultTxSender;
|