@drift-labs/sdk 0.1.36-master.7 → 0.2.0-master.10
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 +6 -6
- package/lib/accounts/bulkAccountLoader.js +81 -95
- 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 +12 -18
- package/lib/admin.js +398 -558
- package/lib/clearingHouse.d.ts +83 -109
- package/lib/clearingHouse.js +832 -893
- package/lib/clearingHouseConfig.d.ts +34 -0
- package/lib/clearingHouseConfig.js +2 -0
- package/lib/clearingHouseUser.d.ts +19 -22
- package/lib/clearingHouseUser.js +155 -141
- 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 +41 -0
- package/lib/constants/markets.d.ts +8 -3
- package/lib/constants/markets.js +13 -206
- package/lib/constants/numericConstants.d.ts +17 -0
- package/lib/constants/numericConstants.js +23 -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 +118 -0
- package/lib/factory/bigNum.js +364 -0
- package/lib/factory/oracleClient.d.ts +1 -2
- package/lib/factory/oracleClient.js +6 -2
- package/lib/idl/clearing_house.json +2258 -2774
- package/lib/index.d.ts +14 -5
- package/lib/index.js +18 -5
- package/lib/math/amm.d.ts +24 -29
- package/lib/math/amm.js +209 -176
- package/lib/math/auction.d.ts +5 -0
- package/lib/math/auction.js +42 -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/orders.d.ts +6 -1
- package/lib/math/orders.js +38 -1
- package/lib/math/position.d.ts +7 -5
- package/lib/math/position.js +29 -27
- package/lib/math/repeg.d.ts +22 -0
- package/lib/math/repeg.js +128 -0
- package/lib/math/trade.d.ts +5 -4
- package/lib/math/trade.js +29 -24
- 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 -31
- 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 -50
- package/lib/oracles/types.d.ts +6 -1
- package/lib/orderParams.d.ts +14 -5
- package/lib/orderParams.js +8 -96
- package/lib/orders.d.ts +6 -7
- package/lib/orders.js +11 -89
- package/lib/slot/SlotSubscriber.d.ts +19 -0
- package/lib/slot/SlotSubscriber.js +26 -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 +180 -110
- package/lib/types.js +54 -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 +11 -4
- package/src/accounts/bulkAccountLoader.js +197 -0
- package/src/accounts/bulkAccountLoader.ts +21 -15
- package/src/accounts/bulkUserSubscription.js +33 -0
- package/src/accounts/bulkUserSubscription.ts +1 -45
- package/src/accounts/fetch.js +29 -0
- package/src/accounts/fetch.ts +33 -0
- package/src/accounts/pollingClearingHouseAccountSubscriber.js +311 -0
- package/src/accounts/pollingClearingHouseAccountSubscriber.ts +249 -214
- package/src/accounts/pollingOracleSubscriber.js +93 -0
- package/src/accounts/pollingOracleSubscriber.ts +16 -8
- package/src/accounts/pollingTokenAccountSubscriber.js +90 -0
- package/src/accounts/pollingTokenAccountSubscriber.ts +11 -8
- package/src/accounts/pollingUserAccountSubscriber.js +132 -0
- package/src/accounts/pollingUserAccountSubscriber.ts +21 -86
- package/src/accounts/types.js +10 -0
- package/src/accounts/types.ts +41 -70
- package/src/accounts/utils.js +7 -0
- package/src/accounts/webSocketAccountSubscriber.js +93 -0
- package/src/accounts/webSocketAccountSubscriber.ts +33 -16
- package/src/accounts/webSocketClearingHouseAccountSubscriber.js +233 -0
- package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +190 -240
- package/src/accounts/webSocketUserAccountSubscriber.js +62 -0
- package/src/accounts/webSocketUserAccountSubscriber.ts +11 -71
- package/src/addresses/marketAddresses.js +26 -0
- package/src/addresses/marketAddresses.ts +18 -0
- package/{lib/addresses.js → src/addresses/pda.js} +45 -34
- package/src/addresses/pda.ts +118 -0
- package/src/admin.ts +247 -336
- package/src/assert/assert.js +9 -0
- package/src/clearingHouse.ts +1023 -1026
- package/src/clearingHouseConfig.ts +37 -0
- package/src/clearingHouseUser.ts +275 -185
- package/src/clearingHouseUserConfig.ts +18 -0
- package/src/config.ts +54 -1
- package/src/constants/banks.ts +50 -0
- package/src/constants/markets.ts +16 -207
- package/src/constants/numericConstants.ts +34 -5
- package/src/events/eventList.js +77 -0
- package/src/events/eventList.ts +94 -0
- package/src/events/eventSubscriber.js +139 -0
- package/src/events/eventSubscriber.ts +194 -0
- package/src/events/fetchLogs.js +50 -0
- package/src/events/fetchLogs.ts +80 -0
- package/src/events/pollingLogProvider.js +64 -0
- package/src/events/pollingLogProvider.ts +79 -0
- package/src/events/sort.js +44 -0
- package/src/events/sort.ts +65 -0
- package/src/events/txEventCache.js +71 -0
- package/src/events/txEventCache.ts +74 -0
- package/src/events/types.js +20 -0
- package/src/events/types.ts +98 -0
- package/src/events/webSocketLogProvider.js +41 -0
- package/src/events/webSocketLogProvider.ts +38 -0
- package/src/examples/makeTradeExample.js +80 -0
- package/src/examples/makeTradeExample.ts +20 -11
- package/src/factory/bigNum.js +364 -0
- package/src/factory/bigNum.ts +524 -0
- package/src/factory/oracleClient.js +20 -0
- package/src/factory/oracleClient.ts +7 -4
- package/src/idl/clearing_house.json +2258 -2774
- package/src/index.js +69 -0
- package/src/index.ts +14 -5
- package/src/math/amm.js +369 -0
- package/src/math/amm.ts +382 -243
- package/src/math/auction.js +42 -0
- package/src/math/auction.ts +43 -0
- package/src/math/bankBalance.js +75 -0
- package/src/math/bankBalance.ts +112 -0
- package/src/math/conversion.js +11 -0
- package/src/math/conversion.ts +1 -11
- package/src/math/funding.js +248 -0
- package/src/math/funding.ts +12 -9
- package/src/math/market.js +57 -0
- package/src/math/market.ts +37 -30
- package/src/math/oracles.js +26 -0
- package/src/math/orders.js +110 -0
- package/src/math/orders.ts +43 -1
- package/src/math/position.js +140 -0
- package/src/math/position.ts +52 -35
- package/src/math/repeg.js +128 -0
- package/src/math/repeg.ts +176 -0
- package/src/math/state.js +15 -0
- package/src/math/trade.js +253 -0
- package/src/math/trade.ts +55 -47
- package/src/math/utils.js +26 -0
- package/src/math/utils.js.map +1 -0
- package/src/mockUSDCFaucet.js +171 -0
- package/src/oracles/oracleClientCache.js +19 -0
- package/src/oracles/oracleClientCache.ts +20 -0
- package/src/oracles/pythClient.js +46 -0
- package/src/oracles/pythClient.ts +4 -11
- package/src/oracles/quoteAssetOracleClient.js +32 -0
- package/src/oracles/quoteAssetOracleClient.ts +25 -0
- package/src/oracles/switchboardClient.js +69 -0
- package/src/oracles/switchboardClient.ts +11 -24
- package/src/oracles/types.js +2 -0
- package/src/oracles/types.ts +7 -1
- package/src/orderParams.js +20 -0
- package/src/orderParams.ts +20 -141
- package/src/orders.js +134 -0
- package/src/orders.ts +25 -134
- package/src/slot/SlotSubscriber.js +39 -0
- package/src/slot/SlotSubscriber.ts +42 -0
- package/src/token/index.js +38 -0
- package/src/tx/retryTxSender.js +188 -0
- package/src/tx/retryTxSender.ts +6 -4
- package/src/tx/types.js +2 -0
- package/src/tx/types.ts +6 -1
- package/src/tx/utils.js +17 -0
- package/src/tx/utils.ts +22 -3
- package/src/types.js +114 -0
- package/src/types.ts +176 -124
- package/src/userName.js +20 -0
- package/src/userName.ts +20 -0
- package/src/util/promiseTimeout.js +14 -0
- package/src/util/tps.js +27 -0
- package/src/wallet.js +35 -0
- package/tests/bn/test.ts +255 -0
- package/tsconfig.json +12 -12
- package/lib/addresses.d.ts +0 -10
- 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/settlement.d.ts +0 -4
- package/lib/settlement.js +0 -10
- package/lib/tx/defaultTxSender.d.ts +0 -8
- package/lib/tx/defaultTxSender.js +0 -12
- package/src/addresses.ts +0 -82
- 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/settlement.ts +0 -9
- package/src/tx/defaultTxSender.ts +0 -24
|
@@ -1,92 +1,47 @@
|
|
|
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
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.WebSocketUserAccountSubscriber = void 0;
|
|
13
4
|
const types_1 = require("./types");
|
|
14
5
|
const events_1 = require("events");
|
|
15
|
-
const addresses_1 = require("../addresses");
|
|
16
6
|
const webSocketAccountSubscriber_1 = require("./webSocketAccountSubscriber");
|
|
17
7
|
class WebSocketUserAccountSubscriber {
|
|
18
|
-
constructor(program,
|
|
19
|
-
this.type = 'websocket';
|
|
8
|
+
constructor(program, userAccountPublicKey) {
|
|
20
9
|
this.isSubscribed = false;
|
|
21
10
|
this.program = program;
|
|
22
|
-
this.
|
|
11
|
+
this.userAccountPublicKey = userAccountPublicKey;
|
|
23
12
|
this.eventEmitter = new events_1.EventEmitter();
|
|
24
13
|
}
|
|
25
|
-
subscribe() {
|
|
26
|
-
|
|
27
|
-
if (this.isSubscribed) {
|
|
28
|
-
return true;
|
|
29
|
-
}
|
|
30
|
-
const userPublicKey = yield (0, addresses_1.getUserAccountPublicKey)(this.program.programId, this.authority);
|
|
31
|
-
this.userDataAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('user', this.program, userPublicKey);
|
|
32
|
-
yield this.userDataAccountSubscriber.subscribe((data) => {
|
|
33
|
-
this.eventEmitter.emit('userAccountData', data);
|
|
34
|
-
this.eventEmitter.emit('update');
|
|
35
|
-
});
|
|
36
|
-
const userAccountData = this.userDataAccountSubscriber.data;
|
|
37
|
-
this.userPositionsAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('userPositions', this.program, userAccountData.positions);
|
|
38
|
-
yield this.userPositionsAccountSubscriber.subscribe((data) => {
|
|
39
|
-
this.eventEmitter.emit('userPositionsData', data);
|
|
40
|
-
this.eventEmitter.emit('update');
|
|
41
|
-
});
|
|
42
|
-
const userOrdersPublicKey = yield (0, addresses_1.getUserOrdersAccountPublicKey)(this.program.programId, userPublicKey);
|
|
43
|
-
this.userOrdersAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('userOrders', this.program, userOrdersPublicKey);
|
|
44
|
-
yield this.userOrdersAccountSubscriber.subscribe((data) => {
|
|
45
|
-
this.eventEmitter.emit('userOrdersData', data);
|
|
46
|
-
this.eventEmitter.emit('update');
|
|
47
|
-
});
|
|
48
|
-
this.eventEmitter.emit('update');
|
|
49
|
-
this.isSubscribed = true;
|
|
14
|
+
async subscribe() {
|
|
15
|
+
if (this.isSubscribed) {
|
|
50
16
|
return true;
|
|
17
|
+
}
|
|
18
|
+
this.userDataAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('user', this.program, this.userAccountPublicKey);
|
|
19
|
+
await this.userDataAccountSubscriber.subscribe((data) => {
|
|
20
|
+
this.eventEmitter.emit('userAccountUpdate', data);
|
|
21
|
+
this.eventEmitter.emit('update');
|
|
51
22
|
});
|
|
23
|
+
this.eventEmitter.emit('update');
|
|
24
|
+
this.isSubscribed = true;
|
|
25
|
+
return true;
|
|
52
26
|
}
|
|
53
|
-
fetch() {
|
|
54
|
-
|
|
55
|
-
yield Promise.all([
|
|
56
|
-
this.userDataAccountSubscriber.fetch(),
|
|
57
|
-
this.userPositionsAccountSubscriber.fetch(),
|
|
58
|
-
this.userOrdersAccountSubscriber.fetch(),
|
|
59
|
-
]);
|
|
60
|
-
});
|
|
27
|
+
async fetch() {
|
|
28
|
+
await Promise.all([this.userDataAccountSubscriber.fetch()]);
|
|
61
29
|
}
|
|
62
|
-
unsubscribe() {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
this.userDataAccountSubscriber.unsubscribe(),
|
|
69
|
-
this.userPositionsAccountSubscriber.unsubscribe(),
|
|
70
|
-
yield this.userOrdersAccountSubscriber.unsubscribe(),
|
|
71
|
-
]);
|
|
72
|
-
this.isSubscribed = false;
|
|
73
|
-
});
|
|
30
|
+
async unsubscribe() {
|
|
31
|
+
if (!this.isSubscribed) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
await Promise.all([this.userDataAccountSubscriber.unsubscribe()]);
|
|
35
|
+
this.isSubscribed = false;
|
|
74
36
|
}
|
|
75
37
|
assertIsSubscribed() {
|
|
76
38
|
if (!this.isSubscribed) {
|
|
77
39
|
throw new types_1.NotSubscribedError('You must call `subscribe` before using this function');
|
|
78
40
|
}
|
|
79
41
|
}
|
|
80
|
-
|
|
42
|
+
getUserAccountAndSlot() {
|
|
81
43
|
this.assertIsSubscribed();
|
|
82
|
-
return this.userDataAccountSubscriber.
|
|
83
|
-
}
|
|
84
|
-
getUserPositionsAccount() {
|
|
85
|
-
this.assertIsSubscribed();
|
|
86
|
-
return this.userPositionsAccountSubscriber.data;
|
|
87
|
-
}
|
|
88
|
-
getUserOrdersAccount() {
|
|
89
|
-
return this.userOrdersAccountSubscriber.data;
|
|
44
|
+
return this.userDataAccountSubscriber.dataAndSlot;
|
|
90
45
|
}
|
|
91
46
|
}
|
|
92
47
|
exports.WebSocketUserAccountSubscriber = WebSocketUserAccountSubscriber;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getMarketAddress = void 0;
|
|
4
|
+
const pda_1 = require("./pda");
|
|
5
|
+
const CACHE = new Map();
|
|
6
|
+
async function getMarketAddress(programId, marketIndex) {
|
|
7
|
+
const cacheKey = `${programId.toString()}-${marketIndex.toString()}`;
|
|
8
|
+
if (CACHE.has(cacheKey)) {
|
|
9
|
+
return CACHE.get(cacheKey);
|
|
10
|
+
}
|
|
11
|
+
const publicKey = await (0, pda_1.getMarketPublicKey)(programId, marketIndex);
|
|
12
|
+
CACHE.set(cacheKey, publicKey);
|
|
13
|
+
return publicKey;
|
|
14
|
+
}
|
|
15
|
+
exports.getMarketAddress = getMarketAddress;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
2
|
+
import { PublicKey } from '@solana/web3.js';
|
|
3
|
+
import { BN } from '@project-serum/anchor';
|
|
4
|
+
export declare function getClearingHouseStateAccountPublicKeyAndNonce(programId: PublicKey): Promise<[PublicKey, number]>;
|
|
5
|
+
export declare function getClearingHouseStateAccountPublicKey(programId: PublicKey): Promise<PublicKey>;
|
|
6
|
+
export declare function getUserAccountPublicKeyAndNonce(programId: PublicKey, authority: PublicKey, userId?: number): Promise<[PublicKey, number]>;
|
|
7
|
+
export declare function getUserAccountPublicKey(programId: PublicKey, authority: PublicKey, userId?: number): Promise<PublicKey>;
|
|
8
|
+
export declare function getUserAccountPublicKeySync(programId: PublicKey, authority: PublicKey, userId?: number): PublicKey;
|
|
9
|
+
export declare function getMarketPublicKey(programId: PublicKey, marketIndex: BN): Promise<PublicKey>;
|
|
10
|
+
export declare function getBankPublicKey(programId: PublicKey, bankIndex: BN): Promise<PublicKey>;
|
|
11
|
+
export declare function getBankVaultPublicKey(programId: PublicKey, bankIndex: BN): Promise<PublicKey>;
|
|
12
|
+
export declare function getBankVaultAuthorityPublicKey(programId: PublicKey, bankIndex: BN): Promise<PublicKey>;
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.getBankVaultAuthorityPublicKey = exports.getBankVaultPublicKey = exports.getBankPublicKey = exports.getMarketPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getClearingHouseStateAccountPublicKey = exports.getClearingHouseStateAccountPublicKeyAndNonce = void 0;
|
|
27
|
+
const anchor = __importStar(require("@project-serum/anchor"));
|
|
28
|
+
async function getClearingHouseStateAccountPublicKeyAndNonce(programId) {
|
|
29
|
+
return anchor.web3.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('clearing_house'))], programId);
|
|
30
|
+
}
|
|
31
|
+
exports.getClearingHouseStateAccountPublicKeyAndNonce = getClearingHouseStateAccountPublicKeyAndNonce;
|
|
32
|
+
async function getClearingHouseStateAccountPublicKey(programId) {
|
|
33
|
+
return (await getClearingHouseStateAccountPublicKeyAndNonce(programId))[0];
|
|
34
|
+
}
|
|
35
|
+
exports.getClearingHouseStateAccountPublicKey = getClearingHouseStateAccountPublicKey;
|
|
36
|
+
async function getUserAccountPublicKeyAndNonce(programId, authority, userId = 0) {
|
|
37
|
+
return anchor.web3.PublicKey.findProgramAddress([
|
|
38
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('user')),
|
|
39
|
+
authority.toBuffer(),
|
|
40
|
+
Uint8Array.from([userId]),
|
|
41
|
+
], programId);
|
|
42
|
+
}
|
|
43
|
+
exports.getUserAccountPublicKeyAndNonce = getUserAccountPublicKeyAndNonce;
|
|
44
|
+
async function getUserAccountPublicKey(programId, authority, userId = 0) {
|
|
45
|
+
return (await getUserAccountPublicKeyAndNonce(programId, authority, userId))[0];
|
|
46
|
+
}
|
|
47
|
+
exports.getUserAccountPublicKey = getUserAccountPublicKey;
|
|
48
|
+
function getUserAccountPublicKeySync(programId, authority, userId = 0) {
|
|
49
|
+
return anchor.web3.PublicKey.findProgramAddressSync([
|
|
50
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('user')),
|
|
51
|
+
authority.toBuffer(),
|
|
52
|
+
Uint8Array.from([userId]),
|
|
53
|
+
], programId)[0];
|
|
54
|
+
}
|
|
55
|
+
exports.getUserAccountPublicKeySync = getUserAccountPublicKeySync;
|
|
56
|
+
async function getMarketPublicKey(programId, marketIndex) {
|
|
57
|
+
return (await anchor.web3.PublicKey.findProgramAddress([
|
|
58
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('market')),
|
|
59
|
+
marketIndex.toArrayLike(Buffer, 'le', 8),
|
|
60
|
+
], programId))[0];
|
|
61
|
+
}
|
|
62
|
+
exports.getMarketPublicKey = getMarketPublicKey;
|
|
63
|
+
async function getBankPublicKey(programId, bankIndex) {
|
|
64
|
+
return (await anchor.web3.PublicKey.findProgramAddress([
|
|
65
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('bank')),
|
|
66
|
+
bankIndex.toArrayLike(Buffer, 'le', 8),
|
|
67
|
+
], programId))[0];
|
|
68
|
+
}
|
|
69
|
+
exports.getBankPublicKey = getBankPublicKey;
|
|
70
|
+
async function getBankVaultPublicKey(programId, bankIndex) {
|
|
71
|
+
return (await anchor.web3.PublicKey.findProgramAddress([
|
|
72
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('bank_vault')),
|
|
73
|
+
bankIndex.toArrayLike(Buffer, 'le', 8),
|
|
74
|
+
], programId))[0];
|
|
75
|
+
}
|
|
76
|
+
exports.getBankVaultPublicKey = getBankVaultPublicKey;
|
|
77
|
+
async function getBankVaultAuthorityPublicKey(programId, bankIndex) {
|
|
78
|
+
return (await anchor.web3.PublicKey.findProgramAddress([
|
|
79
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('bank_vault_authority')),
|
|
80
|
+
bankIndex.toArrayLike(Buffer, 'le', 8),
|
|
81
|
+
], programId))[0];
|
|
82
|
+
}
|
|
83
|
+
exports.getBankVaultAuthorityPublicKey = getBankVaultAuthorityPublicKey;
|
package/lib/admin.d.ts
CHANGED
|
@@ -1,30 +1,26 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
|
-
import {
|
|
3
|
-
import { FeeStructure,
|
|
2
|
+
import { PublicKey, TransactionSignature } from '@solana/web3.js';
|
|
3
|
+
import { FeeStructure, OracleGuardRails, OracleSource, OrderFillerRewardStructure } from './types';
|
|
4
4
|
import { BN } from '@project-serum/anchor';
|
|
5
5
|
import { ClearingHouse } from './clearingHouse';
|
|
6
6
|
export declare class Admin extends ClearingHouse {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
TransactionSignature,
|
|
11
|
-
TransactionSignature
|
|
12
|
-
]>;
|
|
13
|
-
initializeOrderState(): Promise<TransactionSignature>;
|
|
14
|
-
initializeMarket(marketIndex: BN, priceOracle: PublicKey, baseAssetReserve: BN, quoteAssetReserve: BN, periodicity: BN, pegMultiplier?: BN, oracleSource?: OracleSource, marginRatioInitial?: number, marginRatioPartial?: number, marginRatioMaintenance?: number): Promise<TransactionSignature>;
|
|
7
|
+
initialize(usdcMint: PublicKey, adminControlsPrices: boolean): Promise<[TransactionSignature]>;
|
|
8
|
+
initializeBank(mint: PublicKey, optimalUtilization: BN, optimalRate: BN, maxRate: BN, oracle: PublicKey, oracleSource: OracleSource, initialAssetWeight: BN, maintenanceAssetWeight: BN, initialLiabilityWeight: BN, maintenanceLiabilityWeight: BN, imfFactor?: BN): Promise<TransactionSignature>;
|
|
9
|
+
initializeMarket(priceOracle: PublicKey, baseAssetReserve: BN, quoteAssetReserve: BN, periodicity: BN, pegMultiplier?: BN, oracleSource?: OracleSource, marginRatioInitial?: number, marginRatioPartial?: number, marginRatioMaintenance?: number): Promise<TransactionSignature>;
|
|
15
10
|
moveAmmPrice(baseAssetReserve: BN, quoteAssetReserve: BN, marketIndex: BN): Promise<TransactionSignature>;
|
|
16
11
|
updateK(sqrtK: BN, marketIndex: BN): Promise<TransactionSignature>;
|
|
17
|
-
updateCurveHistory(): Promise<TransactionSignature>;
|
|
18
12
|
moveAmmToPrice(marketIndex: BN, targetPrice: BN): Promise<TransactionSignature>;
|
|
19
13
|
repegAmmCurve(newPeg: BN, marketIndex: BN): Promise<TransactionSignature>;
|
|
20
14
|
updateAmmOracleTwap(marketIndex: BN): Promise<TransactionSignature>;
|
|
21
15
|
resetAmmOracleTwap(marketIndex: BN): Promise<TransactionSignature>;
|
|
22
16
|
withdrawFromInsuranceVault(amount: BN, recipient: PublicKey): Promise<TransactionSignature>;
|
|
23
|
-
|
|
17
|
+
withdrawFromMarketToInsuranceVault(marketIndex: BN, amount: BN, recipient: PublicKey): Promise<TransactionSignature>;
|
|
24
18
|
withdrawFromInsuranceVaultToMarket(marketIndex: BN, amount: BN): Promise<TransactionSignature>;
|
|
25
19
|
updateAdmin(admin: PublicKey): Promise<TransactionSignature>;
|
|
20
|
+
updateCurveUpdateIntensity(marketIndex: BN, curveUpdateIntensity: number): Promise<TransactionSignature>;
|
|
26
21
|
updateMarginRatio(marketIndex: BN, marginRatioInitial: number, marginRatioPartial: number, marginRatioMaintenance: number): Promise<TransactionSignature>;
|
|
27
22
|
updateMarketBaseSpread(marketIndex: BN, baseSpread: number): Promise<TransactionSignature>;
|
|
23
|
+
updateMarketMaxSpread(marketIndex: BN, maxSpread: number): Promise<TransactionSignature>;
|
|
28
24
|
updatePartialLiquidationClosePercentage(numerator: BN, denominator: BN): Promise<TransactionSignature>;
|
|
29
25
|
updatePartialLiquidationPenaltyPercentage(numerator: BN, denominator: BN): Promise<TransactionSignature>;
|
|
30
26
|
updateFullLiquidationPenaltyPercentage(numerator: BN, denominator: BN): Promise<TransactionSignature>;
|
|
@@ -35,16 +31,14 @@ export declare class Admin extends ClearingHouse {
|
|
|
35
31
|
updateOracleGuardRails(oracleGuardRails: OracleGuardRails): Promise<TransactionSignature>;
|
|
36
32
|
updateMarketOracle(marketIndex: BN, oracle: PublicKey, oracleSource: OracleSource): Promise<TransactionSignature>;
|
|
37
33
|
updateMarketMinimumQuoteAssetTradeSize(marketIndex: BN, minimumTradeSize: BN): Promise<TransactionSignature>;
|
|
38
|
-
|
|
34
|
+
updateMarketBaseAssetAmountStepSize(marketIndex: BN, stepSize: BN): Promise<TransactionSignature>;
|
|
39
35
|
updateWhitelistMint(whitelistMint?: PublicKey): Promise<TransactionSignature>;
|
|
40
36
|
updateDiscountMint(discountMint: PublicKey): Promise<TransactionSignature>;
|
|
41
37
|
updateMaxDeposit(maxDeposit: BN): Promise<TransactionSignature>;
|
|
42
38
|
updateFundingPaused(fundingPaused: boolean): Promise<TransactionSignature>;
|
|
43
39
|
updateExchangePaused(exchangePaused: boolean): Promise<TransactionSignature>;
|
|
44
40
|
disableAdminControlsPrices(): Promise<TransactionSignature>;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
updateSettlementState(): Promise<TransactionSignature>;
|
|
49
|
-
updateSettlementStateEnabled(enabled: boolean): Promise<TransactionSignature>;
|
|
41
|
+
updateAuctionDuration(minDuration: BN | number, maxDuration: BN | number): Promise<TransactionSignature>;
|
|
42
|
+
updateMaxBaseAssetAmountRatio(marketIndex: BN, maxBaseAssetAmountRatio: number): Promise<TransactionSignature>;
|
|
43
|
+
updateMaxSlippageRatio(marketIndex: BN, maxSlippageRatio: number): Promise<TransactionSignature>;
|
|
50
44
|
}
|