@drift-labs/sdk 0.2.0-master.3 → 0.2.0-master.31
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/README.md +13 -13
- package/lib/accounts/bulkUserStatsSubscription.d.ts +7 -0
- package/lib/accounts/bulkUserStatsSubscription.js +21 -0
- package/lib/accounts/bulkUserSubscription.js +0 -1
- package/lib/accounts/fetch.d.ts +2 -1
- package/lib/accounts/fetch.js +9 -1
- package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +16 -16
- package/lib/accounts/pollingClearingHouseAccountSubscriber.js +31 -28
- package/lib/accounts/pollingUserStatsAccountSubscriber.d.ts +27 -0
- package/lib/accounts/pollingUserStatsAccountSubscriber.js +113 -0
- package/lib/accounts/types.d.ts +22 -11
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +17 -17
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +37 -35
- package/lib/accounts/webSocketUserStatsAccountSubsriber.d.ts +20 -0
- package/lib/accounts/webSocketUserStatsAccountSubsriber.js +47 -0
- package/lib/addresses/marketAddresses.d.ts +1 -3
- package/lib/addresses/pda.d.ts +10 -4
- package/lib/addresses/pda.js +51 -14
- package/lib/admin.d.ts +42 -26
- package/lib/admin.js +228 -81
- package/lib/clearingHouse.d.ts +130 -49
- package/lib/clearingHouse.js +1256 -367
- package/lib/clearingHouseConfig.d.ts +4 -4
- package/lib/clearingHouseUser.d.ts +51 -39
- package/lib/clearingHouseUser.js +408 -191
- package/lib/clearingHouseUserStats.d.ts +18 -0
- package/lib/clearingHouseUserStats.js +49 -0
- package/lib/clearingHouseUserStatsConfig.d.ts +14 -0
- package/lib/clearingHouseUserStatsConfig.js +2 -0
- package/lib/config.d.ts +7 -9
- package/lib/config.js +21 -21
- package/lib/constants/numericConstants.d.ts +25 -12
- package/lib/constants/numericConstants.js +35 -21
- package/lib/constants/perpMarkets.d.ts +18 -0
- package/lib/constants/{markets.js → perpMarkets.js} +7 -7
- package/lib/constants/spotMarkets.d.ts +19 -0
- package/lib/constants/spotMarkets.js +53 -0
- package/lib/dlob/DLOB.d.ts +74 -0
- package/lib/dlob/DLOB.js +595 -0
- package/lib/dlob/DLOBNode.d.ts +54 -0
- package/lib/dlob/DLOBNode.js +85 -0
- package/lib/dlob/NodeList.d.ts +26 -0
- package/lib/dlob/NodeList.js +139 -0
- package/lib/events/eventList.js +3 -0
- package/lib/events/eventSubscriber.d.ts +4 -2
- package/lib/events/eventSubscriber.js +16 -9
- package/lib/events/fetchLogs.d.ts +10 -1
- package/lib/events/fetchLogs.js +27 -7
- package/lib/events/pollingLogProvider.d.ts +2 -1
- package/lib/events/pollingLogProvider.js +6 -2
- package/lib/events/sort.js +8 -11
- package/lib/events/types.d.ts +8 -2
- package/lib/events/types.js +6 -0
- package/lib/examples/makeTradeExample.js +20 -8
- package/lib/factory/bigNum.d.ts +2 -0
- package/lib/factory/bigNum.js +48 -10
- package/lib/idl/clearing_house.json +4889 -1529
- package/lib/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
- package/lib/index.d.ts +21 -6
- package/lib/index.js +25 -6
- package/lib/math/amm.d.ts +9 -6
- package/lib/math/amm.js +91 -66
- package/lib/math/auction.js +4 -1
- package/lib/math/conversion.js +1 -1
- package/lib/math/funding.d.ts +6 -6
- package/lib/math/funding.js +11 -10
- package/lib/math/insurance.d.ts +4 -0
- package/lib/math/insurance.js +27 -0
- package/lib/math/margin.d.ts +11 -0
- package/lib/math/margin.js +77 -0
- package/lib/math/market.d.ts +14 -9
- package/lib/math/market.js +72 -10
- package/lib/math/oracles.d.ts +4 -0
- package/lib/math/oracles.js +36 -8
- package/lib/math/orders.d.ts +6 -2
- package/lib/math/orders.js +78 -3
- package/lib/math/position.d.ts +21 -13
- package/lib/math/position.js +76 -36
- package/lib/math/repeg.js +14 -5
- package/lib/math/spotBalance.d.ts +22 -0
- package/lib/math/spotBalance.js +192 -0
- package/lib/math/spotMarket.d.ts +4 -0
- package/lib/math/spotMarket.js +8 -0
- package/lib/math/spotPosition.d.ts +6 -0
- package/lib/math/spotPosition.js +23 -0
- package/lib/math/trade.d.ts +10 -10
- package/lib/math/trade.js +32 -39
- package/lib/oracles/pythClient.js +1 -1
- package/lib/oracles/quoteAssetOracleClient.js +1 -1
- package/lib/oracles/switchboardClient.js +1 -1
- package/lib/orderParams.d.ts +14 -5
- package/lib/orderParams.js +12 -92
- package/lib/serum/serumSubscriber.d.ts +23 -0
- package/lib/serum/serumSubscriber.js +41 -0
- package/lib/serum/types.d.ts +11 -0
- package/lib/serum/types.js +2 -0
- package/lib/slot/SlotSubscriber.d.ts +7 -0
- package/lib/slot/SlotSubscriber.js +3 -0
- package/lib/{mockUSDCFaucet.d.ts → tokenFaucet.d.ts} +8 -5
- package/lib/{mockUSDCFaucet.js → tokenFaucet.js} +63 -51
- package/lib/tx/retryTxSender.d.ts +1 -1
- package/lib/tx/retryTxSender.js +13 -4
- package/lib/tx/types.d.ts +1 -1
- package/lib/tx/utils.js +1 -1
- package/lib/types.d.ts +566 -138
- package/lib/types.js +129 -5
- package/lib/userMap/userMap.d.ts +25 -0
- package/lib/userMap/userMap.js +73 -0
- package/lib/userMap/userStatsMap.d.ts +19 -0
- package/lib/userMap/userStatsMap.js +68 -0
- package/lib/util/computeUnits.js +1 -1
- package/lib/util/getTokenAddress.d.ts +2 -0
- package/lib/util/getTokenAddress.js +9 -0
- package/package.json +12 -6
- package/src/accounts/bulkUserStatsSubscription.ts +33 -0
- package/src/accounts/bulkUserSubscription.ts +0 -1
- package/src/accounts/fetch.ts +27 -2
- package/src/accounts/pollingClearingHouseAccountSubscriber.ts +46 -42
- package/src/accounts/pollingUserStatsAccountSubscriber.ts +172 -0
- package/src/accounts/types.ts +31 -11
- package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +64 -59
- package/src/accounts/webSocketUserStatsAccountSubsriber.ts +80 -0
- package/src/addresses/marketAddresses.ts +1 -2
- package/src/addresses/pda.ts +88 -14
- package/src/admin.ts +452 -147
- package/src/assert/assert.js +9 -0
- package/src/clearingHouse.ts +2066 -467
- package/src/clearingHouseConfig.ts +4 -3
- package/src/clearingHouseUser.ts +747 -294
- package/src/clearingHouseUserStats.ts +75 -0
- package/src/clearingHouseUserStatsConfig.ts +18 -0
- package/src/config.ts +30 -31
- package/src/constants/numericConstants.ts +48 -25
- package/src/constants/{markets.ts → perpMarkets.ts} +10 -10
- package/src/constants/spotMarkets.ts +73 -0
- package/src/dlob/DLOB.ts +953 -0
- package/src/dlob/DLOBNode.ts +167 -0
- package/src/dlob/NodeList.ts +189 -0
- package/src/events/eventList.js +77 -0
- package/src/events/eventList.ts +3 -0
- package/src/events/eventSubscriber.ts +20 -12
- package/src/events/fetchLogs.ts +35 -8
- package/src/events/pollingLogProvider.ts +10 -2
- package/src/events/sort.ts +11 -15
- package/src/events/types.ts +19 -1
- package/src/examples/makeTradeExample.js +157 -0
- package/src/examples/makeTradeExample.ts +32 -14
- package/src/factory/bigNum.ts +65 -13
- package/src/idl/clearing_house.json +4889 -1529
- package/src/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
- package/src/index.ts +21 -6
- package/src/math/amm.ts +171 -88
- package/src/math/auction.ts +5 -1
- package/src/math/conversion.ts +2 -2
- package/src/math/funding.ts +20 -18
- package/src/math/insurance.ts +35 -0
- package/src/math/margin.ts +127 -0
- package/src/math/market.ts +145 -14
- package/src/math/oracles.ts +63 -9
- package/src/math/orders.ts +138 -4
- package/src/math/position.ts +119 -58
- package/src/math/repeg.ts +16 -6
- package/src/math/spotBalance.ts +319 -0
- package/src/math/spotMarket.ts +9 -0
- package/src/math/spotPosition.ts +47 -0
- package/src/math/trade.ts +53 -59
- package/src/oracles/pythClient.ts +2 -2
- package/src/oracles/quoteAssetOracleClient.ts +2 -2
- package/src/oracles/switchboardClient.ts +2 -2
- package/src/orderParams.ts +24 -137
- package/src/serum/serumSubscriber.ts +80 -0
- package/src/serum/types.ts +13 -0
- package/src/slot/SlotSubscriber.ts +11 -1
- package/src/token/index.js +38 -0
- package/src/{mockUSDCFaucet.ts → tokenFaucet.ts} +82 -70
- package/src/tx/retryTxSender.ts +16 -5
- package/src/tx/types.js +2 -0
- package/src/tx/types.ts +2 -1
- package/src/tx/utils.js +17 -0
- package/src/tx/utils.ts +1 -1
- package/src/types.ts +533 -140
- package/src/userMap/userMap.ts +100 -0
- package/src/userMap/userStatsMap.ts +110 -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/getTokenAddress.ts +18 -0
- package/src/util/promiseTimeout.js +14 -0
- package/src/util/tps.js +27 -0
- package/tests/bn/test.ts +24 -10
- package/tests/dlob/helpers.ts +397 -0
- package/tests/dlob/test.ts +3688 -0
- package/lib/constants/banks.d.ts +0 -16
- package/lib/constants/banks.js +0 -34
- package/lib/constants/markets.d.ts +0 -19
- package/lib/math/bankBalance.d.ts +0 -9
- package/lib/math/bankBalance.js +0 -75
- package/lib/math/state.d.ts +0 -8
- package/lib/math/state.js +0 -15
- package/lib/orders.d.ts +0 -8
- package/lib/orders.js +0 -134
- package/src/constants/banks.ts +0 -43
- package/src/math/bankBalance.ts +0 -112
- package/src/math/state.ts +0 -14
- package/src/math/utils.js +0 -27
- package/src/math/utils.js.map +0 -1
- package/src/orders.ts +0 -244
- package/src/util/computeUnits.js.map +0 -1
package/lib/admin.js
CHANGED
|
@@ -29,28 +29,26 @@ const types_1 = require("./types");
|
|
|
29
29
|
const anchor_1 = require("@project-serum/anchor");
|
|
30
30
|
const anchor = __importStar(require("@project-serum/anchor"));
|
|
31
31
|
const pda_1 = require("./addresses/pda");
|
|
32
|
+
const utils_1 = require("./math/utils");
|
|
32
33
|
const spl_token_1 = require("@solana/spl-token");
|
|
33
34
|
const clearingHouse_1 = require("./clearingHouse");
|
|
34
35
|
const numericConstants_1 = require("./constants/numericConstants");
|
|
35
36
|
const trade_1 = require("./math/trade");
|
|
36
37
|
const amm_1 = require("./math/amm");
|
|
37
38
|
class Admin extends clearingHouse_1.ClearingHouse {
|
|
38
|
-
async initialize(usdcMint,
|
|
39
|
+
async initialize(usdcMint, _adminControlsPrices) {
|
|
39
40
|
const stateAccountRPCResponse = await this.connection.getParsedAccountInfo(await this.getStatePublicKey());
|
|
40
41
|
if (stateAccountRPCResponse.value !== null) {
|
|
41
42
|
throw new Error('Clearing house already initialized');
|
|
42
43
|
}
|
|
43
|
-
const [insuranceVaultPublicKey] = await web3_js_1.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('insurance_vault'))], this.program.programId);
|
|
44
|
-
const [insuranceVaultAuthority] = await web3_js_1.PublicKey.findProgramAddress([insuranceVaultPublicKey.toBuffer()], this.program.programId);
|
|
45
44
|
const [clearingHouseStatePublicKey] = await (0, pda_1.getClearingHouseStateAccountPublicKeyAndNonce)(this.program.programId);
|
|
46
|
-
const initializeTx = await this.program.transaction.initialize(
|
|
45
|
+
const initializeTx = await this.program.transaction.initialize({
|
|
47
46
|
accounts: {
|
|
48
47
|
admin: this.wallet.publicKey,
|
|
49
48
|
state: clearingHouseStatePublicKey,
|
|
50
49
|
quoteAssetMint: usdcMint,
|
|
51
|
-
insuranceVault: insuranceVaultPublicKey,
|
|
52
|
-
insuranceVaultAuthority: insuranceVaultAuthority,
|
|
53
50
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
51
|
+
clearingHouseSigner: this.getSignerPublicKey(),
|
|
54
52
|
systemProgram: anchor.web3.SystemProgram.programId,
|
|
55
53
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
56
54
|
},
|
|
@@ -58,19 +56,20 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
58
56
|
const { txSig: initializeTxSig } = await this.txSender.send(initializeTx, [], this.opts);
|
|
59
57
|
return [initializeTxSig];
|
|
60
58
|
}
|
|
61
|
-
async
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
const initializeTx = await this.program.transaction.
|
|
59
|
+
async initializeSpotMarket(mint, optimalUtilization, optimalRate, maxRate, oracle, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor = new anchor_1.BN(0), liquidationFee = numericConstants_1.ZERO, activeStatus = true) {
|
|
60
|
+
const spotMarketIndex = this.getStateAccount().numberOfSpotMarkets;
|
|
61
|
+
const spotMarket = await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex);
|
|
62
|
+
const spotMarketVault = await (0, pda_1.getSpotMarketVaultPublicKey)(this.program.programId, spotMarketIndex);
|
|
63
|
+
const insuranceFundVault = await (0, pda_1.getInsuranceFundVaultPublicKey)(this.program.programId, spotMarketIndex);
|
|
64
|
+
const initializeTx = await this.program.transaction.initializeSpotMarket(optimalUtilization, optimalRate, maxRate, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor, liquidationFee, activeStatus, {
|
|
67
65
|
accounts: {
|
|
68
66
|
admin: this.wallet.publicKey,
|
|
69
67
|
state: await this.getStatePublicKey(),
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
68
|
+
spotMarket,
|
|
69
|
+
spotMarketVault,
|
|
70
|
+
insuranceFundVault,
|
|
71
|
+
clearingHouseSigner: this.getSignerPublicKey(),
|
|
72
|
+
spotMarketMint: mint,
|
|
74
73
|
oracle,
|
|
75
74
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
76
75
|
systemProgram: anchor.web3.SystemProgram.programId,
|
|
@@ -78,16 +77,35 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
78
77
|
},
|
|
79
78
|
});
|
|
80
79
|
const { txSig } = await this.txSender.send(initializeTx, [], this.opts);
|
|
81
|
-
await this.accountSubscriber.
|
|
80
|
+
await this.accountSubscriber.addSpotMarket(spotMarketIndex);
|
|
82
81
|
await this.accountSubscriber.addOracle({
|
|
83
82
|
source: oracleSource,
|
|
84
83
|
publicKey: oracle,
|
|
85
84
|
});
|
|
86
85
|
return txSig;
|
|
87
86
|
}
|
|
88
|
-
async
|
|
87
|
+
async initializeSerumFulfillmentConfig(marketIndex, serumMarket, serumProgram) {
|
|
88
|
+
const serumOpenOrders = (0, pda_1.getSerumOpenOrdersPublicKey)(this.program.programId, serumMarket);
|
|
89
|
+
const serumFulfillmentConfig = (0, pda_1.getSerumFulfillmentConfigPublicKey)(this.program.programId, serumMarket);
|
|
90
|
+
return await this.program.rpc.initializeSerumFulfillmentConfig(marketIndex, {
|
|
91
|
+
accounts: {
|
|
92
|
+
admin: this.wallet.publicKey,
|
|
93
|
+
state: await this.getStatePublicKey(),
|
|
94
|
+
baseSpotMarket: this.getSpotMarketAccount(marketIndex).pubkey,
|
|
95
|
+
quoteSpotMarket: this.getQuoteSpotMarketAccount().pubkey,
|
|
96
|
+
clearingHouseSigner: this.getSignerPublicKey(),
|
|
97
|
+
serumProgram,
|
|
98
|
+
serumMarket,
|
|
99
|
+
serumOpenOrders,
|
|
100
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
101
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
102
|
+
serumFulfillmentConfig,
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
async initializeMarket(priceOracle, baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier = numericConstants_1.PEG_PRECISION, oracleSource = types_1.OracleSource.PYTH, marginRatioInitial = 2000, marginRatioMaintenance = 500, liquidationFee = numericConstants_1.ZERO, activeStatus = true) {
|
|
89
107
|
const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, this.getStateAccount().numberOfMarkets);
|
|
90
|
-
const initializeMarketTx = await this.program.transaction.initializeMarket(baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier, oracleSource, marginRatioInitial,
|
|
108
|
+
const initializeMarketTx = await this.program.transaction.initializeMarket(baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier, oracleSource, marginRatioInitial, marginRatioMaintenance, liquidationFee, activeStatus, {
|
|
91
109
|
accounts: {
|
|
92
110
|
state: await this.getStatePublicKey(),
|
|
93
111
|
admin: this.wallet.publicKey,
|
|
@@ -98,20 +116,23 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
98
116
|
},
|
|
99
117
|
});
|
|
100
118
|
const { txSig } = await this.txSender.send(initializeMarketTx, [], this.opts);
|
|
101
|
-
await this.accountSubscriber.
|
|
119
|
+
await this.accountSubscriber.addPerpMarket(this.getStateAccount().numberOfMarkets);
|
|
102
120
|
await this.accountSubscriber.addOracle({
|
|
103
121
|
source: oracleSource,
|
|
104
122
|
publicKey: priceOracle,
|
|
105
123
|
});
|
|
106
124
|
return txSig;
|
|
107
125
|
}
|
|
108
|
-
async moveAmmPrice(baseAssetReserve, quoteAssetReserve,
|
|
126
|
+
async moveAmmPrice(marketIndex, baseAssetReserve, quoteAssetReserve, sqrtK) {
|
|
109
127
|
const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex);
|
|
110
|
-
|
|
128
|
+
if (sqrtK == undefined) {
|
|
129
|
+
sqrtK = (0, utils_1.squareRootBN)(baseAssetReserve.mul(quoteAssetReserve));
|
|
130
|
+
}
|
|
131
|
+
return await this.program.rpc.moveAmmPrice(baseAssetReserve, quoteAssetReserve, sqrtK, {
|
|
111
132
|
accounts: {
|
|
112
133
|
state: await this.getStatePublicKey(),
|
|
113
134
|
admin: this.wallet.publicKey,
|
|
114
|
-
|
|
135
|
+
perpMarket: marketPublicKey,
|
|
115
136
|
},
|
|
116
137
|
});
|
|
117
138
|
}
|
|
@@ -121,27 +142,36 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
121
142
|
state: await this.getStatePublicKey(),
|
|
122
143
|
admin: this.wallet.publicKey,
|
|
123
144
|
market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
|
|
124
|
-
oracle: this.
|
|
145
|
+
oracle: this.getPerpMarketAccount(marketIndex).amm.oracle,
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
async updateConcentrationScale(marketIndex, concentrationScale) {
|
|
150
|
+
return await this.program.rpc.updateConcentrationCoef(concentrationScale, {
|
|
151
|
+
accounts: {
|
|
152
|
+
state: await this.getStatePublicKey(),
|
|
153
|
+
admin: this.wallet.publicKey,
|
|
154
|
+
market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
|
|
125
155
|
},
|
|
126
156
|
});
|
|
127
157
|
}
|
|
128
|
-
async moveAmmToPrice(
|
|
129
|
-
const market = this.
|
|
158
|
+
async moveAmmToPrice(perpMarketIndex, targetPrice) {
|
|
159
|
+
const market = this.getPerpMarketAccount(perpMarketIndex);
|
|
130
160
|
const [direction, tradeSize, _] = (0, trade_1.calculateTargetPriceTrade)(market, targetPrice, new anchor_1.BN(1000), 'quote', undefined //todo
|
|
131
161
|
);
|
|
132
162
|
const [newQuoteAssetAmount, newBaseAssetAmount] = (0, amm_1.calculateAmmReservesAfterSwap)(market.amm, 'quote', tradeSize, (0, amm_1.getSwapDirection)('quote', direction));
|
|
133
|
-
const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId,
|
|
134
|
-
return await this.program.rpc.moveAmmPrice(newBaseAssetAmount, newQuoteAssetAmount, {
|
|
163
|
+
const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, perpMarketIndex);
|
|
164
|
+
return await this.program.rpc.moveAmmPrice(newBaseAssetAmount, newQuoteAssetAmount, market.amm.sqrtK, {
|
|
135
165
|
accounts: {
|
|
136
166
|
state: await this.getStatePublicKey(),
|
|
137
167
|
admin: this.wallet.publicKey,
|
|
138
|
-
|
|
168
|
+
perpMarket: marketPublicKey,
|
|
139
169
|
},
|
|
140
170
|
});
|
|
141
171
|
}
|
|
142
172
|
async repegAmmCurve(newPeg, marketIndex) {
|
|
143
173
|
const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex);
|
|
144
|
-
const ammData = this.
|
|
174
|
+
const ammData = this.getPerpMarketAccount(marketIndex).amm;
|
|
145
175
|
return await this.program.rpc.repegAmmCurve(newPeg, {
|
|
146
176
|
accounts: {
|
|
147
177
|
state: await this.getStatePublicKey(),
|
|
@@ -152,7 +182,7 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
152
182
|
});
|
|
153
183
|
}
|
|
154
184
|
async updateAmmOracleTwap(marketIndex) {
|
|
155
|
-
const ammData = this.
|
|
185
|
+
const ammData = this.getPerpMarketAccount(marketIndex).amm;
|
|
156
186
|
const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex);
|
|
157
187
|
return await this.program.rpc.updateAmmOracleTwap({
|
|
158
188
|
accounts: {
|
|
@@ -164,7 +194,7 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
164
194
|
});
|
|
165
195
|
}
|
|
166
196
|
async resetAmmOracleTwap(marketIndex) {
|
|
167
|
-
const ammData = this.
|
|
197
|
+
const ammData = this.getPerpMarketAccount(marketIndex).amm;
|
|
168
198
|
const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex);
|
|
169
199
|
return await this.program.rpc.resetAmmOracleTwap({
|
|
170
200
|
accounts: {
|
|
@@ -175,45 +205,17 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
175
205
|
},
|
|
176
206
|
});
|
|
177
207
|
}
|
|
178
|
-
async
|
|
179
|
-
const
|
|
180
|
-
return await this.program.rpc.
|
|
181
|
-
accounts: {
|
|
182
|
-
admin: this.wallet.publicKey,
|
|
183
|
-
state: await this.getStatePublicKey(),
|
|
184
|
-
insuranceVault: state.insuranceVault,
|
|
185
|
-
insuranceVaultAuthority: state.insuranceVaultAuthority,
|
|
186
|
-
recipient: recipient,
|
|
187
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
188
|
-
},
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
async withdrawFees(marketIndex, amount, recipient) {
|
|
192
|
-
const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex);
|
|
193
|
-
const bank = this.getQuoteAssetBankAccount();
|
|
194
|
-
return await this.program.rpc.withdrawFees(amount, {
|
|
195
|
-
accounts: {
|
|
196
|
-
admin: this.wallet.publicKey,
|
|
197
|
-
state: await this.getStatePublicKey(),
|
|
198
|
-
market: marketPublicKey,
|
|
199
|
-
bank: bank.pubkey,
|
|
200
|
-
bankVault: bank.vault,
|
|
201
|
-
bankVaultAuthority: bank.vaultAuthority,
|
|
202
|
-
recipient: recipient,
|
|
203
|
-
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
204
|
-
},
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
async withdrawFromInsuranceVaultToMarket(marketIndex, amount) {
|
|
208
|
-
const state = await this.getStateAccount();
|
|
209
|
-
return await this.program.rpc.withdrawFromInsuranceVaultToMarket(amount, {
|
|
208
|
+
async depositIntoMarketFeePool(marketIndex, amount, sourceVault) {
|
|
209
|
+
const spotMarket = this.getQuoteSpotMarketAccount();
|
|
210
|
+
return await this.program.rpc.depositIntoMarketFeePool(amount, {
|
|
210
211
|
accounts: {
|
|
211
212
|
admin: this.wallet.publicKey,
|
|
212
213
|
state: await this.getStatePublicKey(),
|
|
213
214
|
market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
215
|
+
sourceVault,
|
|
216
|
+
clearingHouseSigner: this.getSignerPublicKey(),
|
|
217
|
+
quoteSpotMarket: spotMarket.pubkey,
|
|
218
|
+
spotMarketVault: spotMarket.vault,
|
|
217
219
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
218
220
|
},
|
|
219
221
|
});
|
|
@@ -237,8 +239,8 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
237
239
|
},
|
|
238
240
|
});
|
|
239
241
|
}
|
|
240
|
-
async updateMarginRatio(marketIndex, marginRatioInitial,
|
|
241
|
-
return await this.program.rpc.updateMarginRatio(marginRatioInitial,
|
|
242
|
+
async updateMarginRatio(marketIndex, marginRatioInitial, marginRatioMaintenance) {
|
|
243
|
+
return await this.program.rpc.updateMarginRatio(marginRatioInitial, marginRatioMaintenance, {
|
|
242
244
|
accounts: {
|
|
243
245
|
admin: this.wallet.publicKey,
|
|
244
246
|
state: await this.getStatePublicKey(),
|
|
@@ -255,6 +257,15 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
255
257
|
},
|
|
256
258
|
});
|
|
257
259
|
}
|
|
260
|
+
async updateAmmJitIntensity(marketIndex, ammJitIntensity) {
|
|
261
|
+
return await this.program.rpc.updateAmmJitIntensity(ammJitIntensity, {
|
|
262
|
+
accounts: {
|
|
263
|
+
admin: this.wallet.publicKey,
|
|
264
|
+
state: await this.getStatePublicKey(),
|
|
265
|
+
market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
|
|
266
|
+
},
|
|
267
|
+
});
|
|
268
|
+
}
|
|
258
269
|
async updateMarketMaxSpread(marketIndex, maxSpread) {
|
|
259
270
|
return await this.program.rpc.updateMarketMaxSpread(maxSpread, {
|
|
260
271
|
accounts: {
|
|
@@ -304,16 +315,16 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
304
315
|
},
|
|
305
316
|
});
|
|
306
317
|
}
|
|
307
|
-
async
|
|
308
|
-
return await this.program.rpc.
|
|
318
|
+
async updatePerpFeeStructure(feeStructure) {
|
|
319
|
+
return await this.program.rpc.updatePerpFeeStructure(feeStructure, {
|
|
309
320
|
accounts: {
|
|
310
321
|
admin: this.wallet.publicKey,
|
|
311
322
|
state: await this.getStatePublicKey(),
|
|
312
323
|
},
|
|
313
324
|
});
|
|
314
325
|
}
|
|
315
|
-
async
|
|
316
|
-
return await this.program.rpc.
|
|
326
|
+
async updateSpotFeeStructure(feeStructure) {
|
|
327
|
+
return await this.program.rpc.updateSpotFeeStructure(feeStructure, {
|
|
317
328
|
accounts: {
|
|
318
329
|
admin: this.wallet.publicKey,
|
|
319
330
|
state: await this.getStatePublicKey(),
|
|
@@ -328,6 +339,60 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
328
339
|
},
|
|
329
340
|
});
|
|
330
341
|
}
|
|
342
|
+
async updateWithdrawGuardThreshold(marketIndex, withdrawGuardThreshold) {
|
|
343
|
+
return await this.program.rpc.updateWithdrawGuardThreshold(withdrawGuardThreshold, {
|
|
344
|
+
accounts: {
|
|
345
|
+
admin: this.wallet.publicKey,
|
|
346
|
+
state: await this.getStatePublicKey(),
|
|
347
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex),
|
|
348
|
+
},
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
async updateSpotMarketIfFactor(marketIndex, userIfFactor, totalIfFactor) {
|
|
352
|
+
return await this.program.rpc.updateSpotMarketIfFactor(marketIndex, userIfFactor, totalIfFactor, {
|
|
353
|
+
accounts: {
|
|
354
|
+
admin: this.wallet.publicKey,
|
|
355
|
+
state: await this.getStatePublicKey(),
|
|
356
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex),
|
|
357
|
+
},
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
async updateSpotMarketRevenueSettlePeriod(marketIndex, revenueSettlePeriod) {
|
|
361
|
+
return await this.program.rpc.updateSpotMarketRevenueSettlePeriod(revenueSettlePeriod, {
|
|
362
|
+
accounts: {
|
|
363
|
+
admin: this.wallet.publicKey,
|
|
364
|
+
state: await this.getStatePublicKey(),
|
|
365
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex),
|
|
366
|
+
},
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
async updateSpotMarketMaxTokenDeposits(marketIndex, maxTokenDeposits) {
|
|
370
|
+
return await this.program.rpc.updateSpotMarketMaxTokenDeposits(maxTokenDeposits, {
|
|
371
|
+
accounts: {
|
|
372
|
+
admin: this.wallet.publicKey,
|
|
373
|
+
state: await this.getStatePublicKey(),
|
|
374
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex),
|
|
375
|
+
},
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
async updateInsuranceWithdrawEscrowPeriod(marketIndex, insuranceWithdrawEscrowPeriod) {
|
|
379
|
+
return await this.program.rpc.updateInsuranceWithdrawEscrowPeriod(insuranceWithdrawEscrowPeriod, {
|
|
380
|
+
accounts: {
|
|
381
|
+
admin: this.wallet.publicKey,
|
|
382
|
+
state: await this.getStatePublicKey(),
|
|
383
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex),
|
|
384
|
+
},
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
async updateLpCooldownTime(marketIndex, cooldownTime) {
|
|
388
|
+
return await this.program.rpc.updateLpCooldownTime(cooldownTime, {
|
|
389
|
+
accounts: {
|
|
390
|
+
admin: this.wallet.publicKey,
|
|
391
|
+
state: await this.getStatePublicKey(),
|
|
392
|
+
market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
|
|
393
|
+
},
|
|
394
|
+
});
|
|
395
|
+
}
|
|
331
396
|
async updateMarketOracle(marketIndex, oracle, oracleSource) {
|
|
332
397
|
return await this.program.rpc.updateMarketOracle(oracle, oracleSource, {
|
|
333
398
|
accounts: {
|
|
@@ -355,6 +420,15 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
355
420
|
},
|
|
356
421
|
});
|
|
357
422
|
}
|
|
423
|
+
async updateMarketExpiry(perpMarketIndex, expiryTs) {
|
|
424
|
+
return await this.program.rpc.updateMarketExpiry(expiryTs, {
|
|
425
|
+
accounts: {
|
|
426
|
+
admin: this.wallet.publicKey,
|
|
427
|
+
state: await this.getStatePublicKey(),
|
|
428
|
+
perpMarket: await (0, pda_1.getMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
429
|
+
},
|
|
430
|
+
});
|
|
431
|
+
}
|
|
358
432
|
async updateWhitelistMint(whitelistMint) {
|
|
359
433
|
return await this.program.rpc.updateWhitelistMint(whitelistMint, {
|
|
360
434
|
accounts: {
|
|
@@ -379,35 +453,108 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
379
453
|
},
|
|
380
454
|
});
|
|
381
455
|
}
|
|
382
|
-
async
|
|
383
|
-
return await this.program.rpc.
|
|
456
|
+
async updateSpotMarketMarginWeights(spotMarketIndex, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor = new anchor_1.BN(0)) {
|
|
457
|
+
return await this.program.rpc.updateSpotMarketMarginWeights(initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor, {
|
|
384
458
|
accounts: {
|
|
385
459
|
admin: this.wallet.publicKey,
|
|
386
460
|
state: await this.getStatePublicKey(),
|
|
461
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
387
462
|
},
|
|
388
463
|
});
|
|
389
464
|
}
|
|
390
|
-
async
|
|
391
|
-
return await this.program.rpc.
|
|
465
|
+
async updateSpotMarketAssetTier(spotMarketIndex, assetTier) {
|
|
466
|
+
return await this.program.rpc.updateSpotMarketAssetTier(assetTier, {
|
|
392
467
|
accounts: {
|
|
393
468
|
admin: this.wallet.publicKey,
|
|
394
469
|
state: await this.getStatePublicKey(),
|
|
470
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
395
471
|
},
|
|
396
472
|
});
|
|
397
473
|
}
|
|
398
|
-
async
|
|
399
|
-
return await this.program.rpc.
|
|
474
|
+
async updateSpotMarketStatus(spotMarketIndex, marketStatus) {
|
|
475
|
+
return await this.program.rpc.updateSpotMarketStatus(marketStatus, {
|
|
400
476
|
accounts: {
|
|
401
477
|
admin: this.wallet.publicKey,
|
|
402
478
|
state: await this.getStatePublicKey(),
|
|
479
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
480
|
+
},
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
async updatePerpMarketStatus(perpMarketIndex, marketStatus) {
|
|
484
|
+
return await this.program.rpc.updatePerpMarketStatus(marketStatus, {
|
|
485
|
+
accounts: {
|
|
486
|
+
admin: this.wallet.publicKey,
|
|
487
|
+
state: await this.getStatePublicKey(),
|
|
488
|
+
market: await (0, pda_1.getMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
489
|
+
},
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
async updatePerpMarketContractTier(perpMarketIndex, contractTier) {
|
|
493
|
+
return await this.program.rpc.updatePerpMarketContractTier(contractTier, {
|
|
494
|
+
accounts: {
|
|
495
|
+
admin: this.wallet.publicKey,
|
|
496
|
+
state: await this.getStatePublicKey(),
|
|
497
|
+
market: await (0, pda_1.getMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
498
|
+
},
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
async updateExchangeStatus(exchangeStatus) {
|
|
502
|
+
return await this.program.rpc.updateExchangeStatus(exchangeStatus, {
|
|
503
|
+
accounts: {
|
|
504
|
+
admin: this.wallet.publicKey,
|
|
505
|
+
state: await this.getStatePublicKey(),
|
|
506
|
+
},
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
async updatePerpAuctionDuration(minDuration) {
|
|
510
|
+
return await this.program.rpc.updatePerpAuctionDuration(typeof minDuration === 'number' ? minDuration : minDuration.toNumber(), {
|
|
511
|
+
accounts: {
|
|
512
|
+
admin: this.wallet.publicKey,
|
|
513
|
+
state: await this.getStatePublicKey(),
|
|
514
|
+
},
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
async updateSpotAuctionDuration(defaultAuctionDuration) {
|
|
518
|
+
return await this.program.rpc.updateSpotAuctionDuration(defaultAuctionDuration, {
|
|
519
|
+
accounts: {
|
|
520
|
+
admin: this.wallet.publicKey,
|
|
521
|
+
state: await this.getStatePublicKey(),
|
|
522
|
+
},
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
async updateMaxBaseAssetAmountRatio(marketIndex, maxBaseAssetAmountRatio) {
|
|
526
|
+
return await this.program.rpc.updateMaxBaseAssetAmountRatio(maxBaseAssetAmountRatio, {
|
|
527
|
+
accounts: {
|
|
528
|
+
admin: this.wallet.publicKey,
|
|
529
|
+
state: await this.getStatePublicKey(),
|
|
530
|
+
market: this.getPerpMarketAccount(marketIndex).pubkey,
|
|
531
|
+
},
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
async updateMaxSlippageRatio(marketIndex, maxSlippageRatio) {
|
|
535
|
+
return await this.program.rpc.updateMaxSlippageRatio(maxSlippageRatio, {
|
|
536
|
+
accounts: {
|
|
537
|
+
admin: this.wallet.publicKey,
|
|
538
|
+
state: await this.getStatePublicKey(),
|
|
539
|
+
market: this.getPerpMarketAccount(marketIndex).pubkey,
|
|
540
|
+
},
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
async updateMarketMaxImbalances(marketIndex, unrealizedMaxImbalance, maxRevenueWithdrawPerPeriod, quoteMaxInsurance) {
|
|
544
|
+
return await this.program.rpc.updateMarketMaxImbalances(unrealizedMaxImbalance, maxRevenueWithdrawPerPeriod, quoteMaxInsurance, {
|
|
545
|
+
accounts: {
|
|
546
|
+
admin: this.wallet.publicKey,
|
|
547
|
+
state: await this.getStatePublicKey(),
|
|
548
|
+
market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
|
|
403
549
|
},
|
|
404
550
|
});
|
|
405
551
|
}
|
|
406
|
-
async
|
|
407
|
-
return await this.program.rpc.
|
|
552
|
+
async updateSerumVault(srmVault) {
|
|
553
|
+
return await this.program.rpc.updateSerumVault({
|
|
408
554
|
accounts: {
|
|
409
555
|
admin: this.wallet.publicKey,
|
|
410
556
|
state: await this.getStatePublicKey(),
|
|
557
|
+
srmVault: srmVault,
|
|
411
558
|
},
|
|
412
559
|
});
|
|
413
560
|
}
|