@drift-labs/sdk 0.1.36-master.7 → 0.2.0-master.2

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.
Files changed (197) hide show
  1. package/lib/accounts/bulkAccountLoader.d.ts +6 -6
  2. package/lib/accounts/bulkAccountLoader.js +81 -95
  3. package/lib/accounts/bulkUserSubscription.js +13 -57
  4. package/lib/accounts/fetch.d.ts +4 -0
  5. package/lib/accounts/fetch.js +18 -0
  6. package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +34 -38
  7. package/lib/accounts/pollingClearingHouseAccountSubscriber.js +224 -224
  8. package/lib/accounts/pollingOracleSubscriber.d.ts +3 -3
  9. package/lib/accounts/pollingOracleSubscriber.js +37 -49
  10. package/lib/accounts/pollingTokenAccountSubscriber.d.ts +3 -3
  11. package/lib/accounts/pollingTokenAccountSubscriber.js +35 -50
  12. package/lib/accounts/pollingUserAccountSubscriber.d.ts +7 -13
  13. package/lib/accounts/pollingUserAccountSubscriber.js +71 -134
  14. package/lib/accounts/types.d.ts +34 -41
  15. package/lib/accounts/webSocketAccountSubscriber.d.ts +6 -4
  16. package/lib/accounts/webSocketAccountSubscriber.js +39 -35
  17. package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +33 -28
  18. package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +153 -185
  19. package/lib/accounts/webSocketUserAccountSubscriber.d.ts +5 -11
  20. package/lib/accounts/webSocketUserAccountSubscriber.js +22 -67
  21. package/lib/addresses/marketAddresses.d.ts +4 -0
  22. package/lib/addresses/marketAddresses.js +15 -0
  23. package/lib/addresses/pda.d.ts +12 -0
  24. package/lib/addresses/pda.js +83 -0
  25. package/lib/admin.d.ts +9 -17
  26. package/lib/admin.js +375 -558
  27. package/lib/clearingHouse.d.ts +86 -109
  28. package/lib/clearingHouse.js +828 -895
  29. package/lib/clearingHouseConfig.d.ts +34 -0
  30. package/lib/clearingHouseConfig.js +2 -0
  31. package/lib/clearingHouseUser.d.ts +19 -22
  32. package/lib/clearingHouseUser.js +155 -141
  33. package/lib/clearingHouseUserConfig.d.ts +14 -0
  34. package/lib/clearingHouseUserConfig.js +2 -0
  35. package/lib/config.d.ts +12 -0
  36. package/lib/config.js +35 -4
  37. package/lib/constants/banks.d.ts +16 -0
  38. package/lib/constants/banks.js +34 -0
  39. package/lib/constants/markets.d.ts +8 -3
  40. package/lib/constants/markets.js +13 -206
  41. package/lib/constants/numericConstants.d.ts +17 -0
  42. package/lib/constants/numericConstants.js +23 -6
  43. package/lib/events/eventList.d.ts +22 -0
  44. package/lib/events/eventList.js +77 -0
  45. package/lib/events/eventSubscriber.d.ts +34 -0
  46. package/lib/events/eventSubscriber.js +126 -0
  47. package/lib/events/fetchLogs.d.ts +13 -0
  48. package/lib/events/fetchLogs.js +39 -0
  49. package/lib/events/pollingLogProvider.d.ts +15 -0
  50. package/lib/events/pollingLogProvider.js +53 -0
  51. package/lib/events/sort.d.ts +2 -0
  52. package/lib/events/sort.js +44 -0
  53. package/lib/events/txEventCache.d.ts +24 -0
  54. package/lib/events/txEventCache.js +71 -0
  55. package/lib/events/types.d.ts +49 -0
  56. package/lib/events/types.js +20 -0
  57. package/lib/events/webSocketLogProvider.d.ts +12 -0
  58. package/lib/events/webSocketLogProvider.js +30 -0
  59. package/lib/examples/makeTradeExample.js +26 -27
  60. package/lib/factory/bigNum.d.ts +118 -0
  61. package/lib/factory/bigNum.js +364 -0
  62. package/lib/factory/oracleClient.d.ts +1 -2
  63. package/lib/factory/oracleClient.js +6 -2
  64. package/lib/idl/clearing_house.json +2287 -2938
  65. package/lib/index.d.ts +12 -4
  66. package/lib/index.js +12 -4
  67. package/lib/math/amm.d.ts +24 -29
  68. package/lib/math/amm.js +239 -178
  69. package/lib/math/auction.d.ts +5 -0
  70. package/lib/math/auction.js +39 -0
  71. package/lib/math/bankBalance.d.ts +9 -0
  72. package/lib/math/bankBalance.js +75 -0
  73. package/lib/math/conversion.d.ts +0 -1
  74. package/lib/math/conversion.js +1 -5
  75. package/lib/math/funding.d.ts +6 -6
  76. package/lib/math/funding.js +158 -175
  77. package/lib/math/market.d.ts +6 -6
  78. package/lib/math/market.js +10 -9
  79. package/lib/math/orders.d.ts +5 -0
  80. package/lib/math/orders.js +31 -1
  81. package/lib/math/position.d.ts +7 -5
  82. package/lib/math/position.js +27 -27
  83. package/lib/math/repeg.d.ts +22 -0
  84. package/lib/math/repeg.js +128 -0
  85. package/lib/math/trade.d.ts +5 -4
  86. package/lib/math/trade.js +29 -21
  87. package/lib/mockUSDCFaucet.js +87 -116
  88. package/lib/oracles/oracleClientCache.d.ts +8 -0
  89. package/lib/oracles/oracleClientCache.js +19 -0
  90. package/lib/oracles/pythClient.d.ts +3 -5
  91. package/lib/oracles/pythClient.js +12 -31
  92. package/lib/oracles/quoteAssetOracleClient.d.ts +9 -0
  93. package/lib/oracles/quoteAssetOracleClient.js +21 -0
  94. package/lib/oracles/switchboardClient.d.ts +3 -5
  95. package/lib/oracles/switchboardClient.js +29 -50
  96. package/lib/oracles/types.d.ts +6 -1
  97. package/lib/orders.d.ts +6 -7
  98. package/lib/orders.js +10 -80
  99. package/lib/slot/SlotSubscriber.d.ts +12 -0
  100. package/lib/slot/SlotSubscriber.js +23 -0
  101. package/lib/tx/retryTxSender.d.ts +2 -2
  102. package/lib/tx/retryTxSender.js +108 -123
  103. package/lib/tx/types.d.ts +5 -1
  104. package/lib/tx/utils.d.ts +1 -1
  105. package/lib/tx/utils.js +11 -2
  106. package/lib/types.d.ts +110 -109
  107. package/lib/types.js +14 -1
  108. package/lib/userName.d.ts +4 -0
  109. package/lib/userName.js +20 -0
  110. package/lib/util/computeUnits.js +10 -21
  111. package/lib/util/tps.js +11 -22
  112. package/lib/wallet.js +7 -20
  113. package/package.json +11 -4
  114. package/src/accounts/bulkAccountLoader.ts +21 -15
  115. package/src/accounts/bulkUserSubscription.ts +1 -45
  116. package/src/accounts/fetch.ts +33 -0
  117. package/src/accounts/pollingClearingHouseAccountSubscriber.ts +249 -214
  118. package/src/accounts/pollingOracleSubscriber.ts +16 -8
  119. package/src/accounts/pollingTokenAccountSubscriber.ts +11 -8
  120. package/src/accounts/pollingUserAccountSubscriber.ts +21 -86
  121. package/src/accounts/types.ts +41 -70
  122. package/src/accounts/webSocketAccountSubscriber.ts +33 -16
  123. package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +190 -240
  124. package/src/accounts/webSocketUserAccountSubscriber.ts +11 -71
  125. package/src/addresses/marketAddresses.ts +18 -0
  126. package/src/addresses/pda.ts +118 -0
  127. package/src/admin.ts +218 -346
  128. package/src/clearingHouse.ts +983 -952
  129. package/src/clearingHouseConfig.ts +37 -0
  130. package/src/clearingHouseUser.ts +275 -185
  131. package/src/clearingHouseUserConfig.ts +18 -0
  132. package/src/config.ts +54 -1
  133. package/src/constants/banks.ts +43 -0
  134. package/src/constants/markets.ts +16 -207
  135. package/src/constants/numericConstants.ts +34 -5
  136. package/src/events/eventList.ts +94 -0
  137. package/src/events/eventSubscriber.ts +194 -0
  138. package/src/events/fetchLogs.ts +80 -0
  139. package/src/events/pollingLogProvider.ts +79 -0
  140. package/src/events/sort.ts +65 -0
  141. package/src/events/txEventCache.ts +74 -0
  142. package/src/events/types.ts +98 -0
  143. package/src/events/webSocketLogProvider.ts +38 -0
  144. package/src/examples/makeTradeExample.ts +20 -11
  145. package/src/factory/bigNum.ts +524 -0
  146. package/src/factory/oracleClient.ts +7 -4
  147. package/src/idl/clearing_house.json +2287 -2938
  148. package/src/index.ts +12 -4
  149. package/src/math/amm.ts +414 -245
  150. package/src/math/auction.ts +39 -0
  151. package/src/math/bankBalance.ts +112 -0
  152. package/src/math/conversion.ts +1 -11
  153. package/src/math/funding.ts +12 -9
  154. package/src/math/market.ts +37 -30
  155. package/src/math/orders.ts +38 -0
  156. package/src/math/position.ts +48 -35
  157. package/src/math/repeg.ts +176 -0
  158. package/src/math/trade.ts +45 -35
  159. package/src/math/utils.js +27 -0
  160. package/src/math/utils.js.map +1 -0
  161. package/src/oracles/oracleClientCache.ts +20 -0
  162. package/src/oracles/pythClient.ts +4 -11
  163. package/src/oracles/quoteAssetOracleClient.ts +25 -0
  164. package/src/oracles/switchboardClient.ts +11 -24
  165. package/src/oracles/types.ts +7 -1
  166. package/src/orders.ts +24 -126
  167. package/src/slot/SlotSubscriber.ts +32 -0
  168. package/src/tx/retryTxSender.ts +6 -4
  169. package/src/tx/types.ts +6 -1
  170. package/src/tx/utils.ts +22 -3
  171. package/src/types.ts +111 -122
  172. package/src/userName.ts +20 -0
  173. package/src/util/computeUnits.js +17 -0
  174. package/src/util/computeUnits.js.map +1 -0
  175. package/tests/bn/test.ts +255 -0
  176. package/tsconfig.json +12 -12
  177. package/lib/addresses.d.ts +0 -10
  178. package/lib/addresses.js +0 -93
  179. package/lib/constants/accounts.d.ts +0 -15
  180. package/lib/constants/accounts.js +0 -18
  181. package/lib/factory/clearingHouse.d.ts +0 -35
  182. package/lib/factory/clearingHouse.js +0 -81
  183. package/lib/factory/clearingHouseUser.d.ts +0 -19
  184. package/lib/factory/clearingHouseUser.js +0 -34
  185. package/lib/math/insuranceFund.d.ts +0 -15
  186. package/lib/math/insuranceFund.js +0 -33
  187. package/lib/settlement.d.ts +0 -4
  188. package/lib/settlement.js +0 -10
  189. package/lib/tx/defaultTxSender.d.ts +0 -8
  190. package/lib/tx/defaultTxSender.js +0 -12
  191. package/src/addresses.ts +0 -82
  192. package/src/constants/accounts.ts +0 -26
  193. package/src/factory/clearingHouse.ts +0 -173
  194. package/src/factory/clearingHouseUser.ts +0 -73
  195. package/src/math/insuranceFund.ts +0 -29
  196. package/src/settlement.ts +0 -9
  197. 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, authority) {
19
- this.type = 'websocket';
8
+ constructor(program, userAccountPublicKey) {
20
9
  this.isSubscribed = false;
21
10
  this.program = program;
22
- this.authority = authority;
11
+ this.userAccountPublicKey = userAccountPublicKey;
23
12
  this.eventEmitter = new events_1.EventEmitter();
24
13
  }
25
- subscribe() {
26
- return __awaiter(this, void 0, void 0, function* () {
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
- return __awaiter(this, void 0, void 0, function* () {
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
- return __awaiter(this, void 0, void 0, function* () {
64
- if (!this.isSubscribed) {
65
- return;
66
- }
67
- yield Promise.all([
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
- getUserAccount() {
42
+ getUserAccountAndSlot() {
81
43
  this.assertIsSubscribed();
82
- return this.userDataAccountSubscriber.data;
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,4 @@
1
+ /// <reference types="bn.js" />
2
+ import { PublicKey } from '@solana/web3.js';
3
+ import { BN } from '@project-serum/anchor';
4
+ export declare function getMarketAddress(programId: PublicKey, marketIndex: BN): Promise<PublicKey>;
@@ -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,20 +1,14 @@
1
1
  /// <reference types="bn.js" />
2
- import { ConfirmOptions, Connection, PublicKey, TransactionSignature } from '@solana/web3.js';
3
- import { FeeStructure, IWallet, OracleGuardRails, OracleSource, OrderFillerRewardStructure } from './types';
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
- static from(connection: Connection, wallet: IWallet, clearingHouseProgramId: PublicKey, opts?: ConfirmOptions): Admin;
8
- initialize(usdcMint: PublicKey, adminControlsPrices: boolean): Promise<[
9
- TransactionSignature,
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): 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>;
@@ -23,8 +17,10 @@ export declare class Admin extends ClearingHouse {
23
17
  withdrawFees(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,12 @@ 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
- updateMarketMinimumBaseAssetTradeSize(marketIndex: BN, minimumTradeSize: BN): Promise<TransactionSignature>;
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
- transferFromInsuranceVaultToCollateralVault(): Promise<TransactionSignature>;
46
- adminUpdateUserForgoSettlement(authority: PublicKey): Promise<TransactionSignature>;
47
- initializeSettlementState(): Promise<TransactionSignature>;
48
- updateSettlementState(): Promise<TransactionSignature>;
49
- updateSettlementStateEnabled(enabled: boolean): Promise<TransactionSignature>;
41
+ updateOrderAuctionTime(time: BN | number): Promise<TransactionSignature>;
50
42
  }