@drift-labs/sdk 0.2.0-master.14 → 0.2.0-master.17
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/bulkUserStatsSubscription.d.ts +7 -0
- package/lib/accounts/bulkUserStatsSubscription.js +21 -0
- package/lib/accounts/bulkUserSubscription.js +0 -1
- package/lib/accounts/types.d.ts +0 -1
- package/lib/factory/bigNum.js +7 -9
- package/lib/index.d.ts +5 -0
- package/lib/index.js +5 -0
- package/lib/math/bankBalance.js +2 -2
- package/lib/types.d.ts +4 -1
- package/package.json +1 -1
- package/src/accounts/bulkUserStatsSubscription.ts +33 -0
- package/src/accounts/bulkUserSubscription.ts +0 -1
- package/src/factory/bigNum.ts +6 -7
- package/src/index.ts +5 -0
- package/src/math/bankBalance.ts +2 -2
- package/src/types.ts +4 -1
- package/tests/bn/test.ts +8 -0
- package/src/addresses/marketAddresses.js +0 -26
- package/src/assert/assert.js +0 -9
- package/src/constants/banks.js +0 -42
- package/src/constants/markets.js +0 -42
- package/src/constants/numericConstants.js +0 -41
- package/src/events/eventList.js +0 -77
- package/src/events/eventSubscriber.js +0 -139
- package/src/events/fetchLogs.js +0 -50
- package/src/events/pollingLogProvider.js +0 -64
- package/src/events/sort.js +0 -44
- package/src/events/txEventCache.js +0 -71
- package/src/events/types.js +0 -20
- package/src/events/webSocketLogProvider.js +0 -41
- package/src/examples/makeTradeExample.js +0 -80
- package/src/factory/bigNum.js +0 -390
- package/src/factory/oracleClient.js +0 -20
- package/src/math/amm.js +0 -369
- package/src/math/auction.js +0 -42
- package/src/math/conversion.js +0 -11
- package/src/math/funding.js +0 -248
- package/src/math/oracles.js +0 -26
- package/src/math/repeg.js +0 -128
- package/src/math/state.js +0 -15
- package/src/math/trade.js +0 -253
- package/src/math/utils.js +0 -26
- package/src/math/utils.js.map +0 -1
- package/src/oracles/oracleClientCache.js +0 -19
- package/src/oracles/pythClient.js +0 -46
- package/src/oracles/quoteAssetOracleClient.js +0 -32
- package/src/oracles/switchboardClient.js +0 -69
- package/src/oracles/types.js +0 -2
- package/src/orderParams.js +0 -20
- package/src/slot/SlotSubscriber.js +0 -39
- package/src/token/index.js +0 -38
- package/src/tokenFaucet.js +0 -189
- package/src/tx/types.js +0 -2
- package/src/tx/utils.js +0 -17
- package/src/types.js +0 -125
- package/src/userName.js +0 -20
- package/src/util/computeUnits.js +0 -27
- package/src/util/getTokenAddress.js +0 -9
- package/src/util/promiseTimeout.js +0 -14
- package/src/util/tps.js +0 -27
- package/src/wallet.js +0 -35
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ClearingHouseUserStats } from '../clearingHouseUserStats';
|
|
2
|
+
import { BulkAccountLoader } from './bulkAccountLoader';
|
|
3
|
+
/**
|
|
4
|
+
* @param userStats
|
|
5
|
+
* @param accountLoader
|
|
6
|
+
*/
|
|
7
|
+
export declare function bulkPollingUserStatsSubscribe(userStats: ClearingHouseUserStats[], accountLoader: BulkAccountLoader): Promise<void>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bulkPollingUserStatsSubscribe = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* @param userStats
|
|
6
|
+
* @param accountLoader
|
|
7
|
+
*/
|
|
8
|
+
async function bulkPollingUserStatsSubscribe(userStats, accountLoader) {
|
|
9
|
+
if (userStats.length === 0) {
|
|
10
|
+
await accountLoader.load();
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
await Promise.all(userStats.map((userStat) => {
|
|
14
|
+
return userStat.accountSubscriber.addToAccountLoader();
|
|
15
|
+
}));
|
|
16
|
+
await accountLoader.load();
|
|
17
|
+
await Promise.all(userStats.map(async (userStat) => {
|
|
18
|
+
return userStat.subscribe();
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
exports.bulkPollingUserStatsSubscribe = bulkPollingUserStatsSubscribe;
|
|
@@ -11,7 +11,6 @@ async function bulkPollingUserSubscribe(users, accountLoader) {
|
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
13
|
await Promise.all(users.map((user) => {
|
|
14
|
-
// Pull the keys from the authority map so we can skip fetching them in addToAccountLoader
|
|
15
14
|
return user.accountSubscriber.addToAccountLoader();
|
|
16
15
|
}));
|
|
17
16
|
await accountLoader.load();
|
package/lib/accounts/types.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="bn.js" />
|
|
3
|
-
/// <reference types="node" />
|
|
4
3
|
import { BankAccount, MarketAccount, OracleSource, StateAccount, UserAccount, UserStatsAccount } from '../types';
|
|
5
4
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
6
5
|
import { EventEmitter } from 'events';
|
package/lib/factory/bigNum.js
CHANGED
|
@@ -137,7 +137,8 @@ class BigNum {
|
|
|
137
137
|
*/
|
|
138
138
|
print() {
|
|
139
139
|
(0, assert_1.assert)(this.precision.gte(numericConstants_1.ZERO), 'Tried to print a BN with precision lower than zero');
|
|
140
|
-
const
|
|
140
|
+
const isNeg = this.isNeg();
|
|
141
|
+
const plainString = this.abs().toString();
|
|
141
142
|
const precisionNum = this.precision.toNumber();
|
|
142
143
|
// make a string with at least the precisionNum number of zeroes
|
|
143
144
|
let printString = [
|
|
@@ -152,14 +153,11 @@ class BigNum {
|
|
|
152
153
|
// remove leading zeroes
|
|
153
154
|
printString = printString.replace(/^0+/, '');
|
|
154
155
|
// add zero if leading delim
|
|
155
|
-
if (
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if (printString[0] === BigNum.delim)
|
|
161
|
-
printString = `0${printString}`;
|
|
162
|
-
}
|
|
156
|
+
if (printString[0] === BigNum.delim)
|
|
157
|
+
printString = `0${printString}`;
|
|
158
|
+
// Add minus if negative
|
|
159
|
+
if (isNeg)
|
|
160
|
+
printString = `-${printString}`;
|
|
163
161
|
// remove trailing delim
|
|
164
162
|
if (printString[printString.length - 1] === BigNum.delim)
|
|
165
163
|
printString = printString.slice(0, printString.length - 1);
|
package/lib/index.d.ts
CHANGED
|
@@ -11,14 +11,19 @@ export * from './accounts/fetch';
|
|
|
11
11
|
export * from './accounts/webSocketClearingHouseAccountSubscriber';
|
|
12
12
|
export * from './accounts/bulkAccountLoader';
|
|
13
13
|
export * from './accounts/bulkUserSubscription';
|
|
14
|
+
export * from './accounts/bulkUserStatsSubscription';
|
|
14
15
|
export * from './accounts/pollingClearingHouseAccountSubscriber';
|
|
15
16
|
export * from './accounts/pollingOracleSubscriber';
|
|
16
17
|
export * from './accounts/pollingTokenAccountSubscriber';
|
|
18
|
+
export * from './accounts/pollingUserAccountSubscriber';
|
|
19
|
+
export * from './accounts/pollingUserStatsAccountSubscriber';
|
|
17
20
|
export * from './accounts/types';
|
|
18
21
|
export * from './addresses/pda';
|
|
19
22
|
export * from './admin';
|
|
20
23
|
export * from './clearingHouseUser';
|
|
21
24
|
export * from './clearingHouseUserConfig';
|
|
25
|
+
export * from './clearingHouseUserStats';
|
|
26
|
+
export * from './clearingHouseUserStatsConfig';
|
|
22
27
|
export * from './clearingHouse';
|
|
23
28
|
export * from './factory/oracleClient';
|
|
24
29
|
export * from './factory/bigNum';
|
package/lib/index.js
CHANGED
|
@@ -34,14 +34,19 @@ __exportStar(require("./accounts/fetch"), exports);
|
|
|
34
34
|
__exportStar(require("./accounts/webSocketClearingHouseAccountSubscriber"), exports);
|
|
35
35
|
__exportStar(require("./accounts/bulkAccountLoader"), exports);
|
|
36
36
|
__exportStar(require("./accounts/bulkUserSubscription"), exports);
|
|
37
|
+
__exportStar(require("./accounts/bulkUserStatsSubscription"), exports);
|
|
37
38
|
__exportStar(require("./accounts/pollingClearingHouseAccountSubscriber"), exports);
|
|
38
39
|
__exportStar(require("./accounts/pollingOracleSubscriber"), exports);
|
|
39
40
|
__exportStar(require("./accounts/pollingTokenAccountSubscriber"), exports);
|
|
41
|
+
__exportStar(require("./accounts/pollingUserAccountSubscriber"), exports);
|
|
42
|
+
__exportStar(require("./accounts/pollingUserStatsAccountSubscriber"), exports);
|
|
40
43
|
__exportStar(require("./accounts/types"), exports);
|
|
41
44
|
__exportStar(require("./addresses/pda"), exports);
|
|
42
45
|
__exportStar(require("./admin"), exports);
|
|
43
46
|
__exportStar(require("./clearingHouseUser"), exports);
|
|
44
47
|
__exportStar(require("./clearingHouseUserConfig"), exports);
|
|
48
|
+
__exportStar(require("./clearingHouseUserStats"), exports);
|
|
49
|
+
__exportStar(require("./clearingHouseUserStatsConfig"), exports);
|
|
45
50
|
__exportStar(require("./clearingHouse"), exports);
|
|
46
51
|
__exportStar(require("./factory/oracleClient"), exports);
|
|
47
52
|
__exportStar(require("./factory/bigNum"), exports);
|
package/lib/math/bankBalance.js
CHANGED
|
@@ -109,7 +109,7 @@ function calculateInterestAccumulated(bank, now) {
|
|
|
109
109
|
.mul(borrowRateSlope)
|
|
110
110
|
.div(numericConstants_1.BANK_UTILIZATION_PRECISION);
|
|
111
111
|
}
|
|
112
|
-
const timeSinceLastUpdate = now.sub(bank.
|
|
112
|
+
const timeSinceLastUpdate = now.sub(bank.lastInterestTs);
|
|
113
113
|
const modifiedBorrowRate = interest_rate.mul(timeSinceLastUpdate);
|
|
114
114
|
const modifiedDepositRate = modifiedBorrowRate
|
|
115
115
|
.mul(utilization)
|
|
@@ -130,7 +130,7 @@ function calculateWithdrawLimit(bank, now) {
|
|
|
130
130
|
const bankDepositTokenAmount = getTokenAmount(bank.depositBalance, bank, types_1.BankBalanceType.DEPOSIT);
|
|
131
131
|
const bankBorrowTokenAmount = getTokenAmount(bank.borrowBalance, bank, types_1.BankBalanceType.BORROW);
|
|
132
132
|
const twentyFourHours = new anchor_1.BN(60 * 60 * 24);
|
|
133
|
-
const sinceLast = now.sub(bank.
|
|
133
|
+
const sinceLast = now.sub(bank.lastTwapTs);
|
|
134
134
|
const sinceStart = anchor_1.BN.max(numericConstants_1.ZERO, twentyFourHours.sub(sinceLast));
|
|
135
135
|
const borrowTokenTwapLive = bank.borrowTokenTwap
|
|
136
136
|
.mul(sinceStart)
|
package/lib/types.d.ts
CHANGED
|
@@ -368,7 +368,8 @@ export declare type BankAccount = {
|
|
|
368
368
|
cumulativeBorrowInterest: BN;
|
|
369
369
|
depositBalance: BN;
|
|
370
370
|
borrowBalance: BN;
|
|
371
|
-
|
|
371
|
+
lastInterestTs: BN;
|
|
372
|
+
lastTwapTs: BN;
|
|
372
373
|
oracle: PublicKey;
|
|
373
374
|
initialAssetWeight: BN;
|
|
374
375
|
maintenanceAssetWeight: BN;
|
|
@@ -469,6 +470,8 @@ export declare type UserStatsAccount = {
|
|
|
469
470
|
totalReferralReward: BN;
|
|
470
471
|
totalRefereeDiscount: BN;
|
|
471
472
|
};
|
|
473
|
+
authority: PublicKey;
|
|
474
|
+
referrer: PublicKey;
|
|
472
475
|
};
|
|
473
476
|
export declare type UserAccount = {
|
|
474
477
|
authority: PublicKey;
|
package/package.json
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ClearingHouseUserStats } from '../clearingHouseUserStats';
|
|
2
|
+
import { BulkAccountLoader } from './bulkAccountLoader';
|
|
3
|
+
import { PollingUserStatsAccountSubscriber } from './pollingUserStatsAccountSubscriber';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param userStats
|
|
7
|
+
* @param accountLoader
|
|
8
|
+
*/
|
|
9
|
+
export async function bulkPollingUserStatsSubscribe(
|
|
10
|
+
userStats: ClearingHouseUserStats[],
|
|
11
|
+
accountLoader: BulkAccountLoader
|
|
12
|
+
): Promise<void> {
|
|
13
|
+
if (userStats.length === 0) {
|
|
14
|
+
await accountLoader.load();
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
await Promise.all(
|
|
19
|
+
userStats.map((userStat) => {
|
|
20
|
+
return (
|
|
21
|
+
userStat.accountSubscriber as PollingUserStatsAccountSubscriber
|
|
22
|
+
).addToAccountLoader();
|
|
23
|
+
})
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
await accountLoader.load();
|
|
27
|
+
|
|
28
|
+
await Promise.all(
|
|
29
|
+
userStats.map(async (userStat) => {
|
|
30
|
+
return userStat.subscribe();
|
|
31
|
+
})
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -17,7 +17,6 @@ export async function bulkPollingUserSubscribe(
|
|
|
17
17
|
|
|
18
18
|
await Promise.all(
|
|
19
19
|
users.map((user) => {
|
|
20
|
-
// Pull the keys from the authority map so we can skip fetching them in addToAccountLoader
|
|
21
20
|
return (
|
|
22
21
|
user.accountSubscriber as PollingUserAccountSubscriber
|
|
23
22
|
).addToAccountLoader();
|
package/src/factory/bigNum.ts
CHANGED
|
@@ -211,7 +211,8 @@ export class BigNum {
|
|
|
211
211
|
'Tried to print a BN with precision lower than zero'
|
|
212
212
|
);
|
|
213
213
|
|
|
214
|
-
const
|
|
214
|
+
const isNeg = this.isNeg();
|
|
215
|
+
const plainString = this.abs().toString();
|
|
215
216
|
const precisionNum = this.precision.toNumber();
|
|
216
217
|
|
|
217
218
|
// make a string with at least the precisionNum number of zeroes
|
|
@@ -230,12 +231,10 @@ export class BigNum {
|
|
|
230
231
|
printString = printString.replace(/^0+/, '');
|
|
231
232
|
|
|
232
233
|
// add zero if leading delim
|
|
233
|
-
if (
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
if (printString[0] === BigNum.delim) printString = `0${printString}`;
|
|
238
|
-
}
|
|
234
|
+
if (printString[0] === BigNum.delim) printString = `0${printString}`;
|
|
235
|
+
|
|
236
|
+
// Add minus if negative
|
|
237
|
+
if (isNeg) printString = `-${printString}`;
|
|
239
238
|
|
|
240
239
|
// remove trailing delim
|
|
241
240
|
if (printString[printString.length - 1] === BigNum.delim)
|
package/src/index.ts
CHANGED
|
@@ -12,14 +12,19 @@ export * from './accounts/fetch';
|
|
|
12
12
|
export * from './accounts/webSocketClearingHouseAccountSubscriber';
|
|
13
13
|
export * from './accounts/bulkAccountLoader';
|
|
14
14
|
export * from './accounts/bulkUserSubscription';
|
|
15
|
+
export * from './accounts/bulkUserStatsSubscription';
|
|
15
16
|
export * from './accounts/pollingClearingHouseAccountSubscriber';
|
|
16
17
|
export * from './accounts/pollingOracleSubscriber';
|
|
17
18
|
export * from './accounts/pollingTokenAccountSubscriber';
|
|
19
|
+
export * from './accounts/pollingUserAccountSubscriber';
|
|
20
|
+
export * from './accounts/pollingUserStatsAccountSubscriber';
|
|
18
21
|
export * from './accounts/types';
|
|
19
22
|
export * from './addresses/pda';
|
|
20
23
|
export * from './admin';
|
|
21
24
|
export * from './clearingHouseUser';
|
|
22
25
|
export * from './clearingHouseUserConfig';
|
|
26
|
+
export * from './clearingHouseUserStats';
|
|
27
|
+
export * from './clearingHouseUserStatsConfig';
|
|
23
28
|
export * from './clearingHouse';
|
|
24
29
|
export * from './factory/oracleClient';
|
|
25
30
|
export * from './factory/bigNum';
|
package/src/math/bankBalance.ts
CHANGED
|
@@ -187,7 +187,7 @@ export function calculateInterestAccumulated(
|
|
|
187
187
|
.div(BANK_UTILIZATION_PRECISION);
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
-
const timeSinceLastUpdate = now.sub(bank.
|
|
190
|
+
const timeSinceLastUpdate = now.sub(bank.lastInterestTs);
|
|
191
191
|
|
|
192
192
|
const modifiedBorrowRate = interest_rate.mul(timeSinceLastUpdate);
|
|
193
193
|
|
|
@@ -224,7 +224,7 @@ export function calculateWithdrawLimit(
|
|
|
224
224
|
);
|
|
225
225
|
|
|
226
226
|
const twentyFourHours = new BN(60 * 60 * 24);
|
|
227
|
-
const sinceLast = now.sub(bank.
|
|
227
|
+
const sinceLast = now.sub(bank.lastTwapTs);
|
|
228
228
|
const sinceStart = BN.max(ZERO, twentyFourHours.sub(sinceLast));
|
|
229
229
|
const borrowTokenTwapLive = bank.borrowTokenTwap
|
|
230
230
|
.mul(sinceStart)
|
package/src/types.ts
CHANGED
|
@@ -350,7 +350,8 @@ export type BankAccount = {
|
|
|
350
350
|
cumulativeBorrowInterest: BN;
|
|
351
351
|
depositBalance: BN;
|
|
352
352
|
borrowBalance: BN;
|
|
353
|
-
|
|
353
|
+
lastInterestTs: BN;
|
|
354
|
+
lastTwapTs: BN;
|
|
354
355
|
oracle: PublicKey;
|
|
355
356
|
initialAssetWeight: BN;
|
|
356
357
|
maintenanceAssetWeight: BN;
|
|
@@ -457,6 +458,8 @@ export type UserStatsAccount = {
|
|
|
457
458
|
totalReferralReward: BN;
|
|
458
459
|
totalRefereeDiscount: BN;
|
|
459
460
|
};
|
|
461
|
+
authority: PublicKey;
|
|
462
|
+
referrer: PublicKey;
|
|
460
463
|
};
|
|
461
464
|
|
|
462
465
|
export type UserAccount = {
|
package/tests/bn/test.ts
CHANGED
|
@@ -127,6 +127,14 @@ describe('BigNum Tests', () => {
|
|
|
127
127
|
expect(BigNum.fromPrint('123456789').toMillified(5)).to.equal('123.45M');
|
|
128
128
|
|
|
129
129
|
expect(BigNum.from(-95, 2).print()).to.equal('-0.95');
|
|
130
|
+
|
|
131
|
+
// Case 6 strange numbers
|
|
132
|
+
expect(BigNum.from('-100', 2).print()).to.equal('-1.00');
|
|
133
|
+
expect(BigNum.from('-8402189', 13).print()).to.equal('-0.0000008402189');
|
|
134
|
+
expect(BigNum.from('-10000000000000', 13).print()).to.equal(
|
|
135
|
+
'-1.0000000000000'
|
|
136
|
+
);
|
|
137
|
+
expect(BigNum.from('-100', 6).print()).to.equal('-0.000100');
|
|
130
138
|
});
|
|
131
139
|
|
|
132
140
|
it('can initialise from string values correctly', () => {
|
|
@@ -1,26 +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.getMarketAddress = void 0;
|
|
13
|
-
const pda_1 = require("./pda");
|
|
14
|
-
const CACHE = new Map();
|
|
15
|
-
function getMarketAddress(programId, marketIndex) {
|
|
16
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
const cacheKey = `${programId.toString()}-${marketIndex.toString()}`;
|
|
18
|
-
if (CACHE.has(cacheKey)) {
|
|
19
|
-
return CACHE.get(cacheKey);
|
|
20
|
-
}
|
|
21
|
-
const publicKey = yield pda_1.getMarketPublicKey(programId, marketIndex);
|
|
22
|
-
CACHE.set(cacheKey, publicKey);
|
|
23
|
-
return publicKey;
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
exports.getMarketAddress = getMarketAddress;
|
package/src/assert/assert.js
DELETED
package/src/constants/banks.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Banks = exports.MainnetBanks = exports.DevnetBanks = exports.WRAPPED_SOL_MINT = void 0;
|
|
4
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
-
const __1 = require("../");
|
|
6
|
-
exports.WRAPPED_SOL_MINT = new web3_js_1.PublicKey('So11111111111111111111111111111111111111112');
|
|
7
|
-
exports.DevnetBanks = [
|
|
8
|
-
{
|
|
9
|
-
symbol: 'USDC',
|
|
10
|
-
bankIndex: new __1.BN(0),
|
|
11
|
-
oracle: web3_js_1.PublicKey.default,
|
|
12
|
-
oracleSource: __1.OracleSource.QUOTE_ASSET,
|
|
13
|
-
mint: new web3_js_1.PublicKey('8zGuJQqwhZafTah7Uc7Z4tXRnguqkn5KLFAP8oV6PHe2'),
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
symbol: 'SOL',
|
|
17
|
-
bankIndex: new __1.BN(1),
|
|
18
|
-
oracle: new web3_js_1.PublicKey('J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix'),
|
|
19
|
-
oracleSource: __1.OracleSource.PYTH,
|
|
20
|
-
mint: new web3_js_1.PublicKey(exports.WRAPPED_SOL_MINT),
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
symbol: 'BTC',
|
|
24
|
-
bankIndex: new __1.BN(2),
|
|
25
|
-
oracle: new web3_js_1.PublicKey('HovQMDrbAgAYPCmHVSrezcSmkMtXSSUsLDFANExrZh2J'),
|
|
26
|
-
oracleSource: __1.OracleSource.PYTH,
|
|
27
|
-
mint: new web3_js_1.PublicKey('3BZPwbcqB5kKScF3TEXxwNfx5ipV13kbRVDvfVp5c6fv'),
|
|
28
|
-
},
|
|
29
|
-
];
|
|
30
|
-
exports.MainnetBanks = [
|
|
31
|
-
{
|
|
32
|
-
symbol: 'USDC',
|
|
33
|
-
bankIndex: new __1.BN(0),
|
|
34
|
-
oracle: web3_js_1.PublicKey.default,
|
|
35
|
-
oracleSource: __1.OracleSource.QUOTE_ASSET,
|
|
36
|
-
mint: new web3_js_1.PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'),
|
|
37
|
-
},
|
|
38
|
-
];
|
|
39
|
-
exports.Banks = {
|
|
40
|
-
devnet: exports.DevnetBanks,
|
|
41
|
-
'mainnet-beta': exports.MainnetBanks,
|
|
42
|
-
};
|
package/src/constants/markets.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Markets = exports.MainnetMarkets = exports.DevnetMarkets = void 0;
|
|
4
|
-
const __1 = require("../");
|
|
5
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
-
exports.DevnetMarkets = [
|
|
7
|
-
{
|
|
8
|
-
fullName: 'Solana',
|
|
9
|
-
category: ['L1', 'Infra'],
|
|
10
|
-
symbol: 'SOL-PERP',
|
|
11
|
-
baseAssetSymbol: 'SOL',
|
|
12
|
-
marketIndex: new __1.BN(0),
|
|
13
|
-
oracle: new web3_js_1.PublicKey('J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix'),
|
|
14
|
-
launchTs: 1655751353000,
|
|
15
|
-
oracleSource: __1.OracleSource.PYTH,
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
fullName: 'Bitcoin',
|
|
19
|
-
category: ['L1', 'Payment'],
|
|
20
|
-
symbol: 'BTC-PERP',
|
|
21
|
-
baseAssetSymbol: 'BTC',
|
|
22
|
-
marketIndex: new __1.BN(1),
|
|
23
|
-
oracle: new web3_js_1.PublicKey('HovQMDrbAgAYPCmHVSrezcSmkMtXSSUsLDFANExrZh2J'),
|
|
24
|
-
launchTs: 1655751353000,
|
|
25
|
-
oracleSource: __1.OracleSource.PYTH,
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
fullName: 'Ethereum',
|
|
29
|
-
category: ['L1', 'Infra'],
|
|
30
|
-
symbol: 'ETH-PERP',
|
|
31
|
-
baseAssetSymbol: 'ETH',
|
|
32
|
-
marketIndex: new __1.BN(2),
|
|
33
|
-
oracle: new web3_js_1.PublicKey('EdVCmQ9FSPcVe5YySXDPCRmc8aDQLKJ9xvYBMZPie1Vw'),
|
|
34
|
-
launchTs: 1637691133472,
|
|
35
|
-
oracleSource: __1.OracleSource.PYTH,
|
|
36
|
-
},
|
|
37
|
-
];
|
|
38
|
-
exports.MainnetMarkets = [];
|
|
39
|
-
exports.Markets = {
|
|
40
|
-
devnet: exports.DevnetMarkets,
|
|
41
|
-
'mainnet-beta': [],
|
|
42
|
-
};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.QUOTE_ASSET_BANK_INDEX = exports.ONE_YEAR = exports.BID_ASK_SPREAD_PRECISION = exports.MARGIN_PRECISION = exports.AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO = exports.PRICE_TO_QUOTE_PRECISION = exports.PRICE_DIV_PEG = exports.AMM_TO_QUOTE_PRECISION_RATIO = exports.BASE_PRECISION_EXP = exports.BASE_PRECISION = exports.AMM_RESERVE_PRECISION = exports.PEG_PRECISION = exports.FUNDING_PAYMENT_PRECISION = exports.MARK_PRICE_PRECISION = exports.QUOTE_PRECISION = exports.LIQUIDATION_FEE_PRECISION = exports.BANK_BALANCE_PRECISION = exports.BANK_BALANCE_PRECISION_EXP = exports.BANK_WEIGHT_PRECISION = exports.BANK_RATE_PRECISION = exports.BANK_UTILIZATION_PRECISION = exports.BANK_CUMULATIVE_INTEREST_PRECISION = exports.BANK_INTEREST_PRECISION = exports.AMM_RESERVE_PRECISION_EXP = exports.PEG_PRECISION_EXP = exports.FUNDING_RATE_PRECISION_EXP = exports.MARK_PRICE_PRECISION_EXP = exports.FUNDING_PAYMENT_PRECISION_EXP = exports.QUOTE_PRECISION_EXP = exports.MAX_LEVERAGE = exports.TEN_MILLION = exports.BN_MAX = exports.TEN_THOUSAND = exports.TEN = exports.TWO = exports.ONE = exports.ZERO = void 0;
|
|
4
|
-
const __1 = require("../");
|
|
5
|
-
exports.ZERO = new __1.BN(0);
|
|
6
|
-
exports.ONE = new __1.BN(1);
|
|
7
|
-
exports.TWO = new __1.BN(2);
|
|
8
|
-
exports.TEN = new __1.BN(10);
|
|
9
|
-
exports.TEN_THOUSAND = new __1.BN(10000);
|
|
10
|
-
exports.BN_MAX = new __1.BN(Number.MAX_SAFE_INTEGER);
|
|
11
|
-
exports.TEN_MILLION = exports.TEN_THOUSAND.mul(exports.TEN_THOUSAND);
|
|
12
|
-
exports.MAX_LEVERAGE = new __1.BN(5);
|
|
13
|
-
exports.QUOTE_PRECISION_EXP = new __1.BN(6);
|
|
14
|
-
exports.FUNDING_PAYMENT_PRECISION_EXP = new __1.BN(4);
|
|
15
|
-
exports.MARK_PRICE_PRECISION_EXP = new __1.BN(10);
|
|
16
|
-
exports.FUNDING_RATE_PRECISION_EXP = exports.MARK_PRICE_PRECISION_EXP.mul(exports.FUNDING_PAYMENT_PRECISION_EXP);
|
|
17
|
-
exports.PEG_PRECISION_EXP = new __1.BN(3);
|
|
18
|
-
exports.AMM_RESERVE_PRECISION_EXP = new __1.BN(13);
|
|
19
|
-
exports.BANK_INTEREST_PRECISION = new __1.BN(1000000);
|
|
20
|
-
exports.BANK_CUMULATIVE_INTEREST_PRECISION = new __1.BN(10000000000);
|
|
21
|
-
exports.BANK_UTILIZATION_PRECISION = new __1.BN(1000000);
|
|
22
|
-
exports.BANK_RATE_PRECISION = new __1.BN(1000000);
|
|
23
|
-
exports.BANK_WEIGHT_PRECISION = new __1.BN(100);
|
|
24
|
-
exports.BANK_BALANCE_PRECISION_EXP = new __1.BN(6);
|
|
25
|
-
exports.BANK_BALANCE_PRECISION = new __1.BN(10).pow(exports.BANK_BALANCE_PRECISION_EXP);
|
|
26
|
-
exports.LIQUIDATION_FEE_PRECISION = new __1.BN(1000000);
|
|
27
|
-
exports.QUOTE_PRECISION = new __1.BN(10).pow(exports.QUOTE_PRECISION_EXP);
|
|
28
|
-
exports.MARK_PRICE_PRECISION = new __1.BN(10).pow(exports.MARK_PRICE_PRECISION_EXP);
|
|
29
|
-
exports.FUNDING_PAYMENT_PRECISION = new __1.BN(10).pow(exports.FUNDING_PAYMENT_PRECISION_EXP);
|
|
30
|
-
exports.PEG_PRECISION = new __1.BN(10).pow(exports.PEG_PRECISION_EXP);
|
|
31
|
-
exports.AMM_RESERVE_PRECISION = new __1.BN(10).pow(exports.AMM_RESERVE_PRECISION_EXP);
|
|
32
|
-
exports.BASE_PRECISION = exports.AMM_RESERVE_PRECISION;
|
|
33
|
-
exports.BASE_PRECISION_EXP = exports.AMM_RESERVE_PRECISION_EXP;
|
|
34
|
-
exports.AMM_TO_QUOTE_PRECISION_RATIO = exports.AMM_RESERVE_PRECISION.div(exports.QUOTE_PRECISION); // 10^7
|
|
35
|
-
exports.PRICE_DIV_PEG = exports.MARK_PRICE_PRECISION.div(exports.PEG_PRECISION); //10^7
|
|
36
|
-
exports.PRICE_TO_QUOTE_PRECISION = exports.MARK_PRICE_PRECISION.div(exports.QUOTE_PRECISION);
|
|
37
|
-
exports.AMM_TIMES_PEG_TO_QUOTE_PRECISION_RATIO = exports.AMM_RESERVE_PRECISION.mul(exports.PEG_PRECISION).div(exports.QUOTE_PRECISION); // 10^10
|
|
38
|
-
exports.MARGIN_PRECISION = exports.TEN_THOUSAND;
|
|
39
|
-
exports.BID_ASK_SPREAD_PRECISION = new __1.BN(1000000);
|
|
40
|
-
exports.ONE_YEAR = new __1.BN(31536000);
|
|
41
|
-
exports.QUOTE_ASSET_BANK_INDEX = new __1.BN(0);
|
package/src/events/eventList.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EventList = void 0;
|
|
4
|
-
class Node {
|
|
5
|
-
constructor(event, next, prev) {
|
|
6
|
-
this.event = event;
|
|
7
|
-
this.next = next;
|
|
8
|
-
this.prev = prev;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
class EventList {
|
|
12
|
-
constructor(eventType, maxSize, sortFn, orderDirection) {
|
|
13
|
-
this.eventType = eventType;
|
|
14
|
-
this.maxSize = maxSize;
|
|
15
|
-
this.sortFn = sortFn;
|
|
16
|
-
this.orderDirection = orderDirection;
|
|
17
|
-
this.size = 0;
|
|
18
|
-
}
|
|
19
|
-
insert(event) {
|
|
20
|
-
this.size++;
|
|
21
|
-
const newNode = new Node(event);
|
|
22
|
-
if (this.head === undefined) {
|
|
23
|
-
this.head = this.tail = newNode;
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
if (this.sortFn(this.head.event, newNode.event) ===
|
|
27
|
-
(this.orderDirection === 'asc' ? 'less than' : 'greater than')) {
|
|
28
|
-
this.head.prev = newNode;
|
|
29
|
-
newNode.next = this.head;
|
|
30
|
-
this.head = newNode;
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
let currentNode = this.head;
|
|
34
|
-
while (currentNode.next !== undefined &&
|
|
35
|
-
this.sortFn(currentNode.next.event, newNode.event) !==
|
|
36
|
-
(this.orderDirection === 'asc' ? 'less than' : 'greater than')) {
|
|
37
|
-
currentNode = currentNode.next;
|
|
38
|
-
}
|
|
39
|
-
newNode.next = currentNode.next;
|
|
40
|
-
if (currentNode.next !== undefined) {
|
|
41
|
-
newNode.next.prev = newNode;
|
|
42
|
-
}
|
|
43
|
-
currentNode.next = newNode;
|
|
44
|
-
newNode.prev = currentNode;
|
|
45
|
-
}
|
|
46
|
-
if (this.size > this.maxSize) {
|
|
47
|
-
this.detach();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
detach() {
|
|
51
|
-
const node = this.tail;
|
|
52
|
-
if (node.prev !== undefined) {
|
|
53
|
-
node.prev.next = node.next;
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
this.head = node.next;
|
|
57
|
-
}
|
|
58
|
-
if (node.next !== undefined) {
|
|
59
|
-
node.next.prev = node.prev;
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
this.tail = node.prev;
|
|
63
|
-
}
|
|
64
|
-
this.size--;
|
|
65
|
-
}
|
|
66
|
-
toArray() {
|
|
67
|
-
return Array.from(this);
|
|
68
|
-
}
|
|
69
|
-
*[Symbol.iterator]() {
|
|
70
|
-
let node = this.head;
|
|
71
|
-
while (node) {
|
|
72
|
-
yield node.event;
|
|
73
|
-
node = node.next;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
exports.EventList = EventList;
|