@drift-labs/sdk 0.2.0-temp.0 → 0.2.0-temp.1
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/admin.d.ts +7 -5
- package/lib/admin.js +34 -11
- package/lib/clearingHouse.d.ts +23 -9
- package/lib/clearingHouse.js +335 -95
- package/lib/clearingHouseUser.d.ts +2 -2
- package/lib/clearingHouseUser.js +8 -17
- package/lib/config.js +1 -1
- package/lib/constants/banks.js +9 -2
- package/lib/constants/numericConstants.d.ts +1 -0
- package/lib/constants/numericConstants.js +2 -1
- package/lib/idl/clearing_house.json +689 -153
- package/lib/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
- package/lib/index.d.ts +3 -2
- package/lib/index.js +7 -2
- package/lib/math/amm.js +7 -35
- package/lib/math/auction.js +4 -1
- package/lib/math/orders.d.ts +2 -2
- package/lib/math/orders.js +19 -2
- package/lib/math/position.js +3 -1
- package/lib/math/trade.d.ts +1 -1
- package/lib/math/trade.js +7 -10
- package/lib/orderParams.d.ts +14 -5
- package/lib/orderParams.js +8 -96
- package/lib/orders.js +1 -1
- package/lib/slot/SlotSubscriber.d.ts +7 -0
- package/lib/slot/SlotSubscriber.js +3 -0
- package/lib/{mockUSDCFaucet.d.ts → tokenFaucet.d.ts} +7 -5
- package/lib/{mockUSDCFaucet.js → tokenFaucet.js} +41 -40
- package/lib/tx/utils.js +1 -1
- package/lib/types.d.ts +132 -14
- package/lib/types.js +52 -1
- package/lib/util/computeUnits.js +1 -1
- package/package.json +3 -3
- package/src/accounts/bulkAccountLoader.js +197 -0
- package/src/accounts/bulkUserSubscription.js +33 -0
- package/src/accounts/pollingClearingHouseAccountSubscriber.js +311 -0
- package/src/accounts/pollingOracleSubscriber.js +93 -0
- package/src/accounts/pollingTokenAccountSubscriber.js +90 -0
- package/src/accounts/pollingUserAccountSubscriber.js +132 -0
- package/src/accounts/types.js +10 -0
- package/src/accounts/utils.js +7 -0
- package/src/accounts/webSocketAccountSubscriber.js +93 -0
- package/src/accounts/webSocketClearingHouseAccountSubscriber.js +233 -0
- package/src/accounts/webSocketUserAccountSubscriber.js +62 -0
- package/src/addresses/marketAddresses.js +26 -0
- package/src/admin.js +517 -0
- package/src/admin.ts +53 -14
- package/src/assert/assert.js +9 -0
- package/src/clearingHouse.ts +510 -131
- package/src/clearingHouseConfig.js +2 -0
- package/src/clearingHouseUser.ts +12 -23
- package/src/clearingHouseUserConfig.js +2 -0
- package/src/config.js +67 -0
- package/src/config.ts +1 -1
- package/src/constants/banks.js +42 -0
- package/src/constants/banks.ts +9 -2
- package/src/constants/markets.js +42 -0
- package/src/constants/numericConstants.js +41 -0
- package/src/constants/numericConstants.ts +1 -0
- package/src/events/eventList.js +77 -0
- package/src/events/eventSubscriber.js +139 -0
- package/src/events/fetchLogs.js +50 -0
- package/src/events/pollingLogProvider.js +64 -0
- package/src/events/sort.js +44 -0
- package/src/events/txEventCache.js +71 -0
- package/src/events/types.js +20 -0
- package/src/events/webSocketLogProvider.js +41 -0
- package/src/examples/makeTradeExample.js +80 -0
- package/src/factory/bigNum.js +390 -0
- package/src/factory/oracleClient.js +20 -0
- package/src/idl/clearing_house.json +689 -153
- package/src/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
- package/src/index.js +69 -0
- package/src/index.ts +3 -2
- package/src/math/amm.js +369 -0
- package/src/math/amm.ts +19 -49
- package/src/math/auction.js +42 -0
- package/src/math/auction.ts +5 -1
- package/src/math/conversion.js +11 -0
- package/src/math/funding.js +248 -0
- package/src/math/oracles.js +26 -0
- package/src/math/orders.ts +17 -3
- package/src/math/position.ts +5 -1
- package/src/math/repeg.js +128 -0
- package/src/math/state.js +15 -0
- package/src/math/trade.js +253 -0
- package/src/math/trade.ts +23 -25
- package/src/math/utils.js +0 -1
- package/src/mockUSDCFaucet.js +280 -0
- package/src/oracles/oracleClientCache.js +19 -0
- package/src/oracles/pythClient.js +46 -0
- package/src/oracles/quoteAssetOracleClient.js +32 -0
- package/src/oracles/switchboardClient.js +69 -0
- package/src/oracles/types.js +2 -0
- package/src/orderParams.js +20 -0
- package/src/orderParams.ts +20 -141
- package/src/orders.ts +2 -1
- package/src/slot/SlotSubscriber.js +39 -0
- package/src/slot/SlotSubscriber.ts +11 -1
- package/src/token/index.js +38 -0
- package/src/tokenFaucet.js +189 -0
- package/src/{mockUSDCFaucet.ts → tokenFaucet.ts} +48 -59
- package/src/tx/types.js +2 -0
- package/src/tx/utils.js +17 -0
- package/src/tx/utils.ts +1 -1
- package/src/types.js +125 -0
- package/src/types.ts +128 -15
- package/src/userName.js +20 -0
- package/src/util/computeUnits.js +21 -11
- package/src/util/computeUnits.ts +1 -1
- package/src/util/getTokenAddress.js +9 -0
- package/src/util/promiseTimeout.js +14 -0
- package/src/util/tps.js +27 -0
- package/src/wallet.js +35 -0
- package/src/util/computeUnits.js.map +0 -1
package/src/admin.js
ADDED
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.Admin = void 0;
|
|
32
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
33
|
+
const types_1 = require("./types");
|
|
34
|
+
const anchor_1 = require("@project-serum/anchor");
|
|
35
|
+
const anchor = __importStar(require("@project-serum/anchor"));
|
|
36
|
+
const pda_1 = require("./addresses/pda");
|
|
37
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
38
|
+
const clearingHouse_1 = require("./clearingHouse");
|
|
39
|
+
const numericConstants_1 = require("./constants/numericConstants");
|
|
40
|
+
const trade_1 = require("./math/trade");
|
|
41
|
+
const amm_1 = require("./math/amm");
|
|
42
|
+
class Admin extends clearingHouse_1.ClearingHouse {
|
|
43
|
+
initialize(usdcMint, adminControlsPrices) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const stateAccountRPCResponse = yield this.connection.getParsedAccountInfo(yield this.getStatePublicKey());
|
|
46
|
+
if (stateAccountRPCResponse.value !== null) {
|
|
47
|
+
throw new Error('Clearing house already initialized');
|
|
48
|
+
}
|
|
49
|
+
const [insuranceVaultPublicKey] = yield web3_js_1.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('insurance_vault'))], this.program.programId);
|
|
50
|
+
const [insuranceVaultAuthority] = yield web3_js_1.PublicKey.findProgramAddress([insuranceVaultPublicKey.toBuffer()], this.program.programId);
|
|
51
|
+
const [clearingHouseStatePublicKey] = yield pda_1.getClearingHouseStateAccountPublicKeyAndNonce(this.program.programId);
|
|
52
|
+
const initializeTx = yield this.program.transaction.initialize(adminControlsPrices, {
|
|
53
|
+
accounts: {
|
|
54
|
+
admin: this.wallet.publicKey,
|
|
55
|
+
state: clearingHouseStatePublicKey,
|
|
56
|
+
quoteAssetMint: usdcMint,
|
|
57
|
+
insuranceVault: insuranceVaultPublicKey,
|
|
58
|
+
insuranceVaultAuthority: insuranceVaultAuthority,
|
|
59
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
60
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
61
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
const { txSig: initializeTxSig } = yield this.txSender.send(initializeTx, [], this.opts);
|
|
65
|
+
return [initializeTxSig];
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
initializeBank(mint, optimalUtilization, optimalRate, maxRate, oracle, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor = new anchor_1.BN(0), liquidationFee = numericConstants_1.ZERO) {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
const bankIndex = this.getStateAccount().numberOfBanks;
|
|
71
|
+
const bank = yield pda_1.getBankPublicKey(this.program.programId, bankIndex);
|
|
72
|
+
const bankVault = yield pda_1.getBankVaultPublicKey(this.program.programId, bankIndex);
|
|
73
|
+
const bankVaultAuthority = yield pda_1.getBankVaultAuthorityPublicKey(this.program.programId, bankIndex);
|
|
74
|
+
const initializeTx = yield this.program.transaction.initializeBank(optimalUtilization, optimalRate, maxRate, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor, liquidationFee, {
|
|
75
|
+
accounts: {
|
|
76
|
+
admin: this.wallet.publicKey,
|
|
77
|
+
state: yield this.getStatePublicKey(),
|
|
78
|
+
bank,
|
|
79
|
+
bankVault,
|
|
80
|
+
bankVaultAuthority,
|
|
81
|
+
bankMint: mint,
|
|
82
|
+
oracle,
|
|
83
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
84
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
85
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
const { txSig } = yield this.txSender.send(initializeTx, [], this.opts);
|
|
89
|
+
yield this.accountSubscriber.addBank(bankIndex);
|
|
90
|
+
yield this.accountSubscriber.addOracle({
|
|
91
|
+
source: oracleSource,
|
|
92
|
+
publicKey: oracle,
|
|
93
|
+
});
|
|
94
|
+
return txSig;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
initializeMarket(priceOracle, baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier = numericConstants_1.PEG_PRECISION, oracleSource = types_1.OracleSource.PYTH, marginRatioInitial = 2000, marginRatioMaintenance = 500, liquidationFee = numericConstants_1.ZERO) {
|
|
98
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
+
const marketPublicKey = yield pda_1.getMarketPublicKey(this.program.programId, this.getStateAccount().numberOfMarkets);
|
|
100
|
+
const initializeMarketTx = yield this.program.transaction.initializeMarket(baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier, oracleSource, marginRatioInitial, marginRatioMaintenance, liquidationFee, {
|
|
101
|
+
accounts: {
|
|
102
|
+
state: yield this.getStatePublicKey(),
|
|
103
|
+
admin: this.wallet.publicKey,
|
|
104
|
+
oracle: priceOracle,
|
|
105
|
+
market: marketPublicKey,
|
|
106
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
107
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
const { txSig } = yield this.txSender.send(initializeMarketTx, [], this.opts);
|
|
111
|
+
yield this.accountSubscriber.addMarket(this.getStateAccount().numberOfMarkets);
|
|
112
|
+
yield this.accountSubscriber.addOracle({
|
|
113
|
+
source: oracleSource,
|
|
114
|
+
publicKey: priceOracle,
|
|
115
|
+
});
|
|
116
|
+
return txSig;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
moveAmmPrice(baseAssetReserve, quoteAssetReserve, marketIndex) {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
const marketPublicKey = yield pda_1.getMarketPublicKey(this.program.programId, marketIndex);
|
|
122
|
+
return yield this.program.rpc.moveAmmPrice(baseAssetReserve, quoteAssetReserve, {
|
|
123
|
+
accounts: {
|
|
124
|
+
state: yield this.getStatePublicKey(),
|
|
125
|
+
admin: this.wallet.publicKey,
|
|
126
|
+
market: marketPublicKey,
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
updateK(sqrtK, marketIndex) {
|
|
132
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
133
|
+
return yield this.program.rpc.updateK(sqrtK, {
|
|
134
|
+
accounts: {
|
|
135
|
+
state: yield this.getStatePublicKey(),
|
|
136
|
+
admin: this.wallet.publicKey,
|
|
137
|
+
market: yield pda_1.getMarketPublicKey(this.program.programId, marketIndex),
|
|
138
|
+
oracle: this.getMarketAccount(marketIndex).amm.oracle,
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
moveAmmToPrice(marketIndex, targetPrice) {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
+
const market = this.getMarketAccount(marketIndex);
|
|
146
|
+
const [direction, tradeSize, _] = trade_1.calculateTargetPriceTrade(market, targetPrice, new anchor_1.BN(1000), 'quote', undefined //todo
|
|
147
|
+
);
|
|
148
|
+
const [newQuoteAssetAmount, newBaseAssetAmount] = amm_1.calculateAmmReservesAfterSwap(market.amm, 'quote', tradeSize, amm_1.getSwapDirection('quote', direction));
|
|
149
|
+
const marketPublicKey = yield pda_1.getMarketPublicKey(this.program.programId, marketIndex);
|
|
150
|
+
return yield this.program.rpc.moveAmmPrice(newBaseAssetAmount, newQuoteAssetAmount, {
|
|
151
|
+
accounts: {
|
|
152
|
+
state: yield this.getStatePublicKey(),
|
|
153
|
+
admin: this.wallet.publicKey,
|
|
154
|
+
market: marketPublicKey,
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
repegAmmCurve(newPeg, marketIndex) {
|
|
160
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
161
|
+
const marketPublicKey = yield pda_1.getMarketPublicKey(this.program.programId, marketIndex);
|
|
162
|
+
const ammData = this.getMarketAccount(marketIndex).amm;
|
|
163
|
+
return yield this.program.rpc.repegAmmCurve(newPeg, {
|
|
164
|
+
accounts: {
|
|
165
|
+
state: yield this.getStatePublicKey(),
|
|
166
|
+
admin: this.wallet.publicKey,
|
|
167
|
+
oracle: ammData.oracle,
|
|
168
|
+
market: marketPublicKey,
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
updateAmmOracleTwap(marketIndex) {
|
|
174
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
175
|
+
const ammData = this.getMarketAccount(marketIndex).amm;
|
|
176
|
+
const marketPublicKey = yield pda_1.getMarketPublicKey(this.program.programId, marketIndex);
|
|
177
|
+
return yield this.program.rpc.updateAmmOracleTwap({
|
|
178
|
+
accounts: {
|
|
179
|
+
state: yield this.getStatePublicKey(),
|
|
180
|
+
admin: this.wallet.publicKey,
|
|
181
|
+
oracle: ammData.oracle,
|
|
182
|
+
market: marketPublicKey,
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
resetAmmOracleTwap(marketIndex) {
|
|
188
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
189
|
+
const ammData = this.getMarketAccount(marketIndex).amm;
|
|
190
|
+
const marketPublicKey = yield pda_1.getMarketPublicKey(this.program.programId, marketIndex);
|
|
191
|
+
return yield this.program.rpc.resetAmmOracleTwap({
|
|
192
|
+
accounts: {
|
|
193
|
+
state: yield this.getStatePublicKey(),
|
|
194
|
+
admin: this.wallet.publicKey,
|
|
195
|
+
oracle: ammData.oracle,
|
|
196
|
+
market: marketPublicKey,
|
|
197
|
+
},
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
withdrawFromInsuranceVault(amount, recipient) {
|
|
202
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
203
|
+
const state = yield this.getStateAccount();
|
|
204
|
+
const bank = this.getQuoteAssetBankAccount();
|
|
205
|
+
return yield this.program.rpc.withdrawFromInsuranceVault(amount, {
|
|
206
|
+
accounts: {
|
|
207
|
+
admin: this.wallet.publicKey,
|
|
208
|
+
state: yield this.getStatePublicKey(),
|
|
209
|
+
bank: bank.pubkey,
|
|
210
|
+
insuranceVault: state.insuranceVault,
|
|
211
|
+
insuranceVaultAuthority: state.insuranceVaultAuthority,
|
|
212
|
+
recipient: recipient,
|
|
213
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
214
|
+
},
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
withdrawFromMarketToInsuranceVault(marketIndex, amount, recipient) {
|
|
219
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
220
|
+
const marketPublicKey = yield pda_1.getMarketPublicKey(this.program.programId, marketIndex);
|
|
221
|
+
const bank = this.getQuoteAssetBankAccount();
|
|
222
|
+
return yield this.program.rpc.withdrawFromMarketToInsuranceVault(amount, {
|
|
223
|
+
accounts: {
|
|
224
|
+
admin: this.wallet.publicKey,
|
|
225
|
+
state: yield this.getStatePublicKey(),
|
|
226
|
+
market: marketPublicKey,
|
|
227
|
+
bank: bank.pubkey,
|
|
228
|
+
bankVault: bank.vault,
|
|
229
|
+
bankVaultAuthority: bank.vaultAuthority,
|
|
230
|
+
recipient: recipient,
|
|
231
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
withdrawFromInsuranceVaultToMarket(marketIndex, amount) {
|
|
237
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
238
|
+
const state = yield this.getStateAccount();
|
|
239
|
+
const bank = this.getQuoteAssetBankAccount();
|
|
240
|
+
return yield this.program.rpc.withdrawFromInsuranceVaultToMarket(amount, {
|
|
241
|
+
accounts: {
|
|
242
|
+
admin: this.wallet.publicKey,
|
|
243
|
+
state: yield this.getStatePublicKey(),
|
|
244
|
+
market: yield pda_1.getMarketPublicKey(this.program.programId, marketIndex),
|
|
245
|
+
insuranceVault: state.insuranceVault,
|
|
246
|
+
insuranceVaultAuthority: state.insuranceVaultAuthority,
|
|
247
|
+
bank: bank.pubkey,
|
|
248
|
+
bankVault: bank.vault,
|
|
249
|
+
bankVaultAuthority: bank.vaultAuthority,
|
|
250
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
251
|
+
},
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
updateAdmin(admin) {
|
|
256
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
257
|
+
return yield this.program.rpc.updateAdmin(admin, {
|
|
258
|
+
accounts: {
|
|
259
|
+
admin: this.wallet.publicKey,
|
|
260
|
+
state: yield this.getStatePublicKey(),
|
|
261
|
+
},
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
updateCurveUpdateIntensity(marketIndex, curveUpdateIntensity) {
|
|
266
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
267
|
+
// assert(curveUpdateIntensity >= 0 && curveUpdateIntensity <= 100);
|
|
268
|
+
// assert(Number.isInteger(curveUpdateIntensity));
|
|
269
|
+
return yield this.program.rpc.updateCurveUpdateIntensity(curveUpdateIntensity, {
|
|
270
|
+
accounts: {
|
|
271
|
+
admin: this.wallet.publicKey,
|
|
272
|
+
state: yield this.getStatePublicKey(),
|
|
273
|
+
market: yield pda_1.getMarketPublicKey(this.program.programId, marketIndex),
|
|
274
|
+
},
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
updateMarginRatio(marketIndex, marginRatioInitial, marginRatioMaintenance) {
|
|
279
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
280
|
+
return yield this.program.rpc.updateMarginRatio(marginRatioInitial, marginRatioMaintenance, {
|
|
281
|
+
accounts: {
|
|
282
|
+
admin: this.wallet.publicKey,
|
|
283
|
+
state: yield this.getStatePublicKey(),
|
|
284
|
+
market: yield pda_1.getMarketPublicKey(this.program.programId, marketIndex),
|
|
285
|
+
},
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
updateMarketBaseSpread(marketIndex, baseSpread) {
|
|
290
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
291
|
+
return yield this.program.rpc.updateMarketBaseSpread(baseSpread, {
|
|
292
|
+
accounts: {
|
|
293
|
+
admin: this.wallet.publicKey,
|
|
294
|
+
state: yield this.getStatePublicKey(),
|
|
295
|
+
market: yield pda_1.getMarketPublicKey(this.program.programId, marketIndex),
|
|
296
|
+
},
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
updateMarketMaxSpread(marketIndex, maxSpread) {
|
|
301
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
302
|
+
return yield this.program.rpc.updateMarketMaxSpread(maxSpread, {
|
|
303
|
+
accounts: {
|
|
304
|
+
admin: this.wallet.publicKey,
|
|
305
|
+
state: yield this.getStatePublicKey(),
|
|
306
|
+
market: yield pda_1.getMarketPublicKey(this.program.programId, marketIndex),
|
|
307
|
+
},
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
updatePartialLiquidationClosePercentage(numerator, denominator) {
|
|
312
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
313
|
+
return yield this.program.rpc.updatePartialLiquidationClosePercentage(numerator, denominator, {
|
|
314
|
+
accounts: {
|
|
315
|
+
admin: this.wallet.publicKey,
|
|
316
|
+
state: yield this.getStatePublicKey(),
|
|
317
|
+
},
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
updatePartialLiquidationPenaltyPercentage(numerator, denominator) {
|
|
322
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
323
|
+
return yield this.program.rpc.updatePartialLiquidationPenaltyPercentage(numerator, denominator, {
|
|
324
|
+
accounts: {
|
|
325
|
+
admin: this.wallet.publicKey,
|
|
326
|
+
state: yield this.getStatePublicKey(),
|
|
327
|
+
},
|
|
328
|
+
});
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
updateFullLiquidationPenaltyPercentage(numerator, denominator) {
|
|
332
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
333
|
+
return yield this.program.rpc.updateFullLiquidationPenaltyPercentage(numerator, denominator, {
|
|
334
|
+
accounts: {
|
|
335
|
+
admin: this.wallet.publicKey,
|
|
336
|
+
state: yield this.getStatePublicKey(),
|
|
337
|
+
},
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
updatePartialLiquidationShareDenominator(denominator) {
|
|
342
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
343
|
+
return yield this.program.rpc.updatePartialLiquidationLiquidatorShareDenominator(denominator, {
|
|
344
|
+
accounts: {
|
|
345
|
+
admin: this.wallet.publicKey,
|
|
346
|
+
state: yield this.getStatePublicKey(),
|
|
347
|
+
},
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
updateFullLiquidationShareDenominator(denominator) {
|
|
352
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
353
|
+
return yield this.program.rpc.updateFullLiquidationLiquidatorShareDenominator(denominator, {
|
|
354
|
+
accounts: {
|
|
355
|
+
admin: this.wallet.publicKey,
|
|
356
|
+
state: yield this.getStatePublicKey(),
|
|
357
|
+
},
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
updateOrderFillerRewardStructure(orderFillerRewardStructure) {
|
|
362
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
363
|
+
return yield this.program.rpc.updateOrderFillerRewardStructure(orderFillerRewardStructure, {
|
|
364
|
+
accounts: {
|
|
365
|
+
admin: this.wallet.publicKey,
|
|
366
|
+
state: yield this.getStatePublicKey(),
|
|
367
|
+
},
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
updateFee(fees) {
|
|
372
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
373
|
+
return yield this.program.rpc.updateFee(fees, {
|
|
374
|
+
accounts: {
|
|
375
|
+
admin: this.wallet.publicKey,
|
|
376
|
+
state: yield this.getStatePublicKey(),
|
|
377
|
+
},
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
updateOracleGuardRails(oracleGuardRails) {
|
|
382
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
383
|
+
return yield this.program.rpc.updateOracleGuardRails(oracleGuardRails, {
|
|
384
|
+
accounts: {
|
|
385
|
+
admin: this.wallet.publicKey,
|
|
386
|
+
state: yield this.getStatePublicKey(),
|
|
387
|
+
},
|
|
388
|
+
});
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
updateMarketOracle(marketIndex, oracle, oracleSource) {
|
|
392
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
393
|
+
return yield this.program.rpc.updateMarketOracle(oracle, oracleSource, {
|
|
394
|
+
accounts: {
|
|
395
|
+
admin: this.wallet.publicKey,
|
|
396
|
+
state: yield this.getStatePublicKey(),
|
|
397
|
+
market: yield pda_1.getMarketPublicKey(this.program.programId, marketIndex),
|
|
398
|
+
},
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
updateMarketMinimumQuoteAssetTradeSize(marketIndex, minimumTradeSize) {
|
|
403
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
404
|
+
return yield this.program.rpc.updateMarketMinimumQuoteAssetTradeSize(minimumTradeSize, {
|
|
405
|
+
accounts: {
|
|
406
|
+
admin: this.wallet.publicKey,
|
|
407
|
+
state: yield this.getStatePublicKey(),
|
|
408
|
+
market: yield pda_1.getMarketPublicKey(this.program.programId, marketIndex),
|
|
409
|
+
},
|
|
410
|
+
});
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
updateMarketBaseAssetAmountStepSize(marketIndex, stepSize) {
|
|
414
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
415
|
+
return yield this.program.rpc.updateMarketBaseAssetAmountStepSize(stepSize, {
|
|
416
|
+
accounts: {
|
|
417
|
+
admin: this.wallet.publicKey,
|
|
418
|
+
state: yield this.getStatePublicKey(),
|
|
419
|
+
market: yield pda_1.getMarketPublicKey(this.program.programId, marketIndex),
|
|
420
|
+
},
|
|
421
|
+
});
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
updateWhitelistMint(whitelistMint) {
|
|
425
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
426
|
+
return yield this.program.rpc.updateWhitelistMint(whitelistMint, {
|
|
427
|
+
accounts: {
|
|
428
|
+
admin: this.wallet.publicKey,
|
|
429
|
+
state: yield this.getStatePublicKey(),
|
|
430
|
+
},
|
|
431
|
+
});
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
updateDiscountMint(discountMint) {
|
|
435
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
436
|
+
return yield this.program.rpc.updateDiscountMint(discountMint, {
|
|
437
|
+
accounts: {
|
|
438
|
+
admin: this.wallet.publicKey,
|
|
439
|
+
state: yield this.getStatePublicKey(),
|
|
440
|
+
},
|
|
441
|
+
});
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
updateMaxDeposit(maxDeposit) {
|
|
445
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
446
|
+
return yield this.program.rpc.updateMaxDeposit(maxDeposit, {
|
|
447
|
+
accounts: {
|
|
448
|
+
admin: this.wallet.publicKey,
|
|
449
|
+
state: yield this.getStatePublicKey(),
|
|
450
|
+
},
|
|
451
|
+
});
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
updateFundingPaused(fundingPaused) {
|
|
455
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
456
|
+
return yield this.program.rpc.updateFundingPaused(fundingPaused, {
|
|
457
|
+
accounts: {
|
|
458
|
+
admin: this.wallet.publicKey,
|
|
459
|
+
state: yield this.getStatePublicKey(),
|
|
460
|
+
},
|
|
461
|
+
});
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
updateExchangePaused(exchangePaused) {
|
|
465
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
466
|
+
return yield this.program.rpc.updateExchangePaused(exchangePaused, {
|
|
467
|
+
accounts: {
|
|
468
|
+
admin: this.wallet.publicKey,
|
|
469
|
+
state: yield this.getStatePublicKey(),
|
|
470
|
+
},
|
|
471
|
+
});
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
disableAdminControlsPrices() {
|
|
475
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
476
|
+
return yield this.program.rpc.disableAdminControlsPrices({
|
|
477
|
+
accounts: {
|
|
478
|
+
admin: this.wallet.publicKey,
|
|
479
|
+
state: yield this.getStatePublicKey(),
|
|
480
|
+
},
|
|
481
|
+
});
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
updateAuctionDuration(minDuration, maxDuration) {
|
|
485
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
486
|
+
return yield this.program.rpc.updateAuctionDuration(typeof minDuration === 'number' ? minDuration : minDuration.toNumber(), typeof maxDuration === 'number' ? maxDuration : maxDuration.toNumber(), {
|
|
487
|
+
accounts: {
|
|
488
|
+
admin: this.wallet.publicKey,
|
|
489
|
+
state: yield this.getStatePublicKey(),
|
|
490
|
+
},
|
|
491
|
+
});
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
updateMaxBaseAssetAmountRatio(marketIndex, maxBaseAssetAmountRatio) {
|
|
495
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
496
|
+
return yield this.program.rpc.updateMaxBaseAssetAmountRatio(maxBaseAssetAmountRatio, {
|
|
497
|
+
accounts: {
|
|
498
|
+
admin: this.wallet.publicKey,
|
|
499
|
+
state: yield this.getStatePublicKey(),
|
|
500
|
+
market: this.getMarketAccount(marketIndex).pubkey,
|
|
501
|
+
},
|
|
502
|
+
});
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
updateMaxSlippageRatio(marketIndex, maxSlippageRatio) {
|
|
506
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
507
|
+
return yield this.program.rpc.updateMaxSlippageRatio(maxSlippageRatio, {
|
|
508
|
+
accounts: {
|
|
509
|
+
admin: this.wallet.publicKey,
|
|
510
|
+
state: yield this.getStatePublicKey(),
|
|
511
|
+
market: this.getMarketAccount(marketIndex).pubkey,
|
|
512
|
+
},
|
|
513
|
+
});
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
exports.Admin = Admin;
|
package/src/admin.ts
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
} from './addresses/pda';
|
|
21
21
|
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
22
22
|
import { ClearingHouse } from './clearingHouse';
|
|
23
|
-
import { PEG_PRECISION } from './constants/numericConstants';
|
|
23
|
+
import { PEG_PRECISION, ZERO } from './constants/numericConstants';
|
|
24
24
|
import { calculateTargetPriceTrade } from './math/trade';
|
|
25
25
|
import { calculateAmmReservesAfterSwap, getSwapDirection } from './math/amm';
|
|
26
26
|
|
|
@@ -85,7 +85,9 @@ export class Admin extends ClearingHouse {
|
|
|
85
85
|
initialAssetWeight: BN,
|
|
86
86
|
maintenanceAssetWeight: BN,
|
|
87
87
|
initialLiabilityWeight: BN,
|
|
88
|
-
maintenanceLiabilityWeight: BN
|
|
88
|
+
maintenanceLiabilityWeight: BN,
|
|
89
|
+
imfFactor = new BN(0),
|
|
90
|
+
liquidationFee = ZERO
|
|
89
91
|
): Promise<TransactionSignature> {
|
|
90
92
|
const bankIndex = this.getStateAccount().numberOfBanks;
|
|
91
93
|
const bank = await getBankPublicKey(this.program.programId, bankIndex);
|
|
@@ -109,6 +111,8 @@ export class Admin extends ClearingHouse {
|
|
|
109
111
|
maintenanceAssetWeight,
|
|
110
112
|
initialLiabilityWeight,
|
|
111
113
|
maintenanceLiabilityWeight,
|
|
114
|
+
imfFactor,
|
|
115
|
+
liquidationFee,
|
|
112
116
|
{
|
|
113
117
|
accounts: {
|
|
114
118
|
admin: this.wallet.publicKey,
|
|
@@ -144,8 +148,8 @@ export class Admin extends ClearingHouse {
|
|
|
144
148
|
pegMultiplier: BN = PEG_PRECISION,
|
|
145
149
|
oracleSource: OracleSource = OracleSource.PYTH,
|
|
146
150
|
marginRatioInitial = 2000,
|
|
147
|
-
|
|
148
|
-
|
|
151
|
+
marginRatioMaintenance = 500,
|
|
152
|
+
liquidationFee = ZERO
|
|
149
153
|
): Promise<TransactionSignature> {
|
|
150
154
|
const marketPublicKey = await getMarketPublicKey(
|
|
151
155
|
this.program.programId,
|
|
@@ -159,8 +163,8 @@ export class Admin extends ClearingHouse {
|
|
|
159
163
|
pegMultiplier,
|
|
160
164
|
oracleSource,
|
|
161
165
|
marginRatioInitial,
|
|
162
|
-
marginRatioPartial,
|
|
163
166
|
marginRatioMaintenance,
|
|
167
|
+
liquidationFee,
|
|
164
168
|
{
|
|
165
169
|
accounts: {
|
|
166
170
|
state: await this.getStatePublicKey(),
|
|
@@ -329,10 +333,12 @@ export class Admin extends ClearingHouse {
|
|
|
329
333
|
recipient: PublicKey
|
|
330
334
|
): Promise<TransactionSignature> {
|
|
331
335
|
const state = await this.getStateAccount();
|
|
336
|
+
const bank = this.getQuoteAssetBankAccount();
|
|
332
337
|
return await this.program.rpc.withdrawFromInsuranceVault(amount, {
|
|
333
338
|
accounts: {
|
|
334
339
|
admin: this.wallet.publicKey,
|
|
335
340
|
state: await this.getStatePublicKey(),
|
|
341
|
+
bank: bank.pubkey,
|
|
336
342
|
insuranceVault: state.insuranceVault,
|
|
337
343
|
insuranceVaultAuthority: state.insuranceVaultAuthority,
|
|
338
344
|
recipient: recipient,
|
|
@@ -341,7 +347,7 @@ export class Admin extends ClearingHouse {
|
|
|
341
347
|
});
|
|
342
348
|
}
|
|
343
349
|
|
|
344
|
-
public async
|
|
350
|
+
public async withdrawFromMarketToInsuranceVault(
|
|
345
351
|
marketIndex: BN,
|
|
346
352
|
amount: BN,
|
|
347
353
|
recipient: PublicKey
|
|
@@ -351,7 +357,7 @@ export class Admin extends ClearingHouse {
|
|
|
351
357
|
marketIndex
|
|
352
358
|
);
|
|
353
359
|
const bank = this.getQuoteAssetBankAccount();
|
|
354
|
-
return await this.program.rpc.
|
|
360
|
+
return await this.program.rpc.withdrawFromMarketToInsuranceVault(amount, {
|
|
355
361
|
accounts: {
|
|
356
362
|
admin: this.wallet.publicKey,
|
|
357
363
|
state: await this.getStatePublicKey(),
|
|
@@ -370,6 +376,8 @@ export class Admin extends ClearingHouse {
|
|
|
370
376
|
amount: BN
|
|
371
377
|
): Promise<TransactionSignature> {
|
|
372
378
|
const state = await this.getStateAccount();
|
|
379
|
+
const bank = this.getQuoteAssetBankAccount();
|
|
380
|
+
|
|
373
381
|
return await this.program.rpc.withdrawFromInsuranceVaultToMarket(amount, {
|
|
374
382
|
accounts: {
|
|
375
383
|
admin: this.wallet.publicKey,
|
|
@@ -377,7 +385,9 @@ export class Admin extends ClearingHouse {
|
|
|
377
385
|
market: await getMarketPublicKey(this.program.programId, marketIndex),
|
|
378
386
|
insuranceVault: state.insuranceVault,
|
|
379
387
|
insuranceVaultAuthority: state.insuranceVaultAuthority,
|
|
380
|
-
|
|
388
|
+
bank: bank.pubkey,
|
|
389
|
+
bankVault: bank.vault,
|
|
390
|
+
bankVaultAuthority: bank.vaultAuthority,
|
|
381
391
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
382
392
|
},
|
|
383
393
|
});
|
|
@@ -414,12 +424,10 @@ export class Admin extends ClearingHouse {
|
|
|
414
424
|
public async updateMarginRatio(
|
|
415
425
|
marketIndex: BN,
|
|
416
426
|
marginRatioInitial: number,
|
|
417
|
-
marginRatioPartial: number,
|
|
418
427
|
marginRatioMaintenance: number
|
|
419
428
|
): Promise<TransactionSignature> {
|
|
420
429
|
return await this.program.rpc.updateMarginRatio(
|
|
421
430
|
marginRatioInitial,
|
|
422
|
-
marginRatioPartial,
|
|
423
431
|
marginRatioMaintenance,
|
|
424
432
|
{
|
|
425
433
|
accounts: {
|
|
@@ -675,11 +683,13 @@ export class Admin extends ClearingHouse {
|
|
|
675
683
|
});
|
|
676
684
|
}
|
|
677
685
|
|
|
678
|
-
public async
|
|
679
|
-
|
|
686
|
+
public async updateAuctionDuration(
|
|
687
|
+
minDuration: BN | number,
|
|
688
|
+
maxDuration: BN | number
|
|
680
689
|
): Promise<TransactionSignature> {
|
|
681
|
-
return await this.program.rpc.
|
|
682
|
-
typeof
|
|
690
|
+
return await this.program.rpc.updateAuctionDuration(
|
|
691
|
+
typeof minDuration === 'number' ? minDuration : minDuration.toNumber(),
|
|
692
|
+
typeof maxDuration === 'number' ? maxDuration : maxDuration.toNumber(),
|
|
683
693
|
{
|
|
684
694
|
accounts: {
|
|
685
695
|
admin: this.wallet.publicKey,
|
|
@@ -688,4 +698,33 @@ export class Admin extends ClearingHouse {
|
|
|
688
698
|
}
|
|
689
699
|
);
|
|
690
700
|
}
|
|
701
|
+
|
|
702
|
+
public async updateMaxBaseAssetAmountRatio(
|
|
703
|
+
marketIndex: BN,
|
|
704
|
+
maxBaseAssetAmountRatio: number
|
|
705
|
+
): Promise<TransactionSignature> {
|
|
706
|
+
return await this.program.rpc.updateMaxBaseAssetAmountRatio(
|
|
707
|
+
maxBaseAssetAmountRatio,
|
|
708
|
+
{
|
|
709
|
+
accounts: {
|
|
710
|
+
admin: this.wallet.publicKey,
|
|
711
|
+
state: await this.getStatePublicKey(),
|
|
712
|
+
market: this.getMarketAccount(marketIndex).pubkey,
|
|
713
|
+
},
|
|
714
|
+
}
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
public async updateMaxSlippageRatio(
|
|
719
|
+
marketIndex: BN,
|
|
720
|
+
maxSlippageRatio: number
|
|
721
|
+
): Promise<TransactionSignature> {
|
|
722
|
+
return await this.program.rpc.updateMaxSlippageRatio(maxSlippageRatio, {
|
|
723
|
+
accounts: {
|
|
724
|
+
admin: this.wallet.publicKey,
|
|
725
|
+
state: await this.getStatePublicKey(),
|
|
726
|
+
market: this.getMarketAccount(marketIndex).pubkey,
|
|
727
|
+
},
|
|
728
|
+
});
|
|
729
|
+
}
|
|
691
730
|
}
|