@drift-labs/sdk 0.2.0-master.9 → 0.2.0-temp.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.
- package/lib/admin.d.ts +3 -3
- package/lib/admin.js +6 -6
- package/lib/clearingHouse.d.ts +15 -4
- package/lib/clearingHouse.js +200 -37
- package/lib/clearingHouseUser.d.ts +2 -2
- package/lib/clearingHouseUser.js +8 -17
- package/lib/config.js +1 -1
- package/lib/constants/banks.js +2 -3
- package/lib/constants/numericConstants.d.ts +1 -0
- package/lib/constants/numericConstants.js +2 -1
- package/lib/events/eventList.d.ts +1 -0
- package/lib/events/eventList.js +10 -0
- package/lib/events/txEventCache.d.ts +2 -0
- package/lib/events/txEventCache.js +14 -0
- package/lib/idl/clearing_house.json +484 -103
- package/lib/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/orders.js +1 -1
- package/lib/{mockUSDCFaucet.d.ts → tokenFaucet.d.ts} +7 -5
- package/lib/{mockUSDCFaucet.js → tokenFaucet.js} +41 -40
- package/lib/types.d.ts +62 -13
- package/lib/types.js +12 -1
- package/lib/util/computeUnits.js +1 -1
- package/package.json +1 -1
- package/src/admin.js +517 -0
- package/src/admin.ts +7 -7
- package/src/clearingHouse.ts +335 -47
- 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 +2 -3
- 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.ts +10 -0
- package/src/events/txEventCache.ts +16 -0
- package/src/factory/bigNum.js +37 -11
- package/src/idl/clearing_house.json +484 -103
- package/src/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
- package/src/index.js +1 -1
- package/src/index.ts +1 -1
- package/src/mockUSDCFaucet.js +276 -167
- package/src/orders.ts +2 -1
- package/src/tokenFaucet.js +189 -0
- package/src/{mockUSDCFaucet.ts → tokenFaucet.ts} +48 -59
- package/src/types.js +12 -1
- package/src/types.ts +63 -13
- package/src/{accounts/fetch.js → util/computeUnits.js} +11 -13
- package/src/util/computeUnits.ts +1 -1
- package/src/util/getTokenAddress.js +9 -0
- package/src/addresses/pda.js +0 -104
- package/src/math/bankBalance.js +0 -75
- package/src/math/market.js +0 -57
- package/src/math/orders.js +0 -110
- package/src/math/position.js +0 -140
- package/src/orders.js +0 -134
- package/src/tx/retryTxSender.js +0 -188
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
|
|
|
@@ -86,7 +86,8 @@ export class Admin extends ClearingHouse {
|
|
|
86
86
|
maintenanceAssetWeight: BN,
|
|
87
87
|
initialLiabilityWeight: BN,
|
|
88
88
|
maintenanceLiabilityWeight: BN,
|
|
89
|
-
imfFactor = new BN(0)
|
|
89
|
+
imfFactor = new BN(0),
|
|
90
|
+
liquidationFee = ZERO
|
|
90
91
|
): Promise<TransactionSignature> {
|
|
91
92
|
const bankIndex = this.getStateAccount().numberOfBanks;
|
|
92
93
|
const bank = await getBankPublicKey(this.program.programId, bankIndex);
|
|
@@ -111,6 +112,7 @@ export class Admin extends ClearingHouse {
|
|
|
111
112
|
initialLiabilityWeight,
|
|
112
113
|
maintenanceLiabilityWeight,
|
|
113
114
|
imfFactor,
|
|
115
|
+
liquidationFee,
|
|
114
116
|
{
|
|
115
117
|
accounts: {
|
|
116
118
|
admin: this.wallet.publicKey,
|
|
@@ -146,8 +148,8 @@ export class Admin extends ClearingHouse {
|
|
|
146
148
|
pegMultiplier: BN = PEG_PRECISION,
|
|
147
149
|
oracleSource: OracleSource = OracleSource.PYTH,
|
|
148
150
|
marginRatioInitial = 2000,
|
|
149
|
-
|
|
150
|
-
|
|
151
|
+
marginRatioMaintenance = 500,
|
|
152
|
+
liquidationFee = ZERO
|
|
151
153
|
): Promise<TransactionSignature> {
|
|
152
154
|
const marketPublicKey = await getMarketPublicKey(
|
|
153
155
|
this.program.programId,
|
|
@@ -161,8 +163,8 @@ export class Admin extends ClearingHouse {
|
|
|
161
163
|
pegMultiplier,
|
|
162
164
|
oracleSource,
|
|
163
165
|
marginRatioInitial,
|
|
164
|
-
marginRatioPartial,
|
|
165
166
|
marginRatioMaintenance,
|
|
167
|
+
liquidationFee,
|
|
166
168
|
{
|
|
167
169
|
accounts: {
|
|
168
170
|
state: await this.getStatePublicKey(),
|
|
@@ -422,12 +424,10 @@ export class Admin extends ClearingHouse {
|
|
|
422
424
|
public async updateMarginRatio(
|
|
423
425
|
marketIndex: BN,
|
|
424
426
|
marginRatioInitial: number,
|
|
425
|
-
marginRatioPartial: number,
|
|
426
427
|
marginRatioMaintenance: number
|
|
427
428
|
): Promise<TransactionSignature> {
|
|
428
429
|
return await this.program.rpc.updateMarginRatio(
|
|
429
430
|
marginRatioInitial,
|
|
430
|
-
marginRatioPartial,
|
|
431
431
|
marginRatioMaintenance,
|
|
432
432
|
{
|
|
433
433
|
accounts: {
|