@drift-labs/sdk 0.2.0-master.24 → 0.2.0-master.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +13 -13
- package/lib/accounts/pollingClearingHouseAccountSubscriber.js +27 -27
- package/lib/accounts/types.d.ts +8 -9
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +14 -14
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +35 -34
- package/lib/addresses/pda.d.ts +8 -6
- package/lib/addresses/pda.js +35 -27
- package/lib/admin.d.ts +9 -6
- package/lib/admin.js +90 -54
- package/lib/clearingHouse.d.ts +71 -42
- package/lib/clearingHouse.js +765 -282
- package/lib/clearingHouseConfig.d.ts +2 -2
- package/lib/clearingHouseUser.d.ts +19 -17
- package/lib/clearingHouseUser.js +145 -123
- package/lib/config.d.ts +7 -7
- package/lib/config.js +21 -21
- package/lib/constants/numericConstants.d.ts +12 -12
- package/lib/constants/numericConstants.js +13 -13
- package/lib/constants/{markets.d.ts → perpMarkets.d.ts} +5 -5
- package/{src/constants/markets.js → lib/constants/perpMarkets.js} +4 -4
- package/lib/constants/{banks.d.ts → spotMarkets.d.ts} +6 -6
- package/lib/constants/{banks.js → spotMarkets.js} +16 -16
- 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/types.d.ts +4 -2
- package/lib/events/types.js +2 -0
- package/lib/examples/makeTradeExample.js +18 -6
- package/lib/idl/clearing_house.json +1128 -347
- package/lib/index.d.ts +6 -3
- package/lib/index.js +6 -3
- package/lib/math/amm.d.ts +5 -3
- package/lib/math/amm.js +42 -4
- package/lib/math/funding.d.ts +6 -6
- package/lib/math/funding.js +2 -1
- package/lib/math/margin.d.ts +4 -4
- package/lib/math/margin.js +18 -11
- package/lib/math/market.d.ts +10 -9
- package/lib/math/market.js +29 -6
- package/lib/math/oracles.d.ts +2 -1
- package/lib/math/oracles.js +11 -1
- package/lib/math/orders.d.ts +5 -5
- package/lib/math/position.d.ts +13 -13
- package/lib/math/position.js +19 -19
- package/lib/math/spotBalance.d.ts +19 -0
- package/lib/math/spotBalance.js +176 -0
- package/lib/math/spotMarket.d.ts +4 -0
- package/lib/math/spotMarket.js +8 -0
- package/lib/math/spotPosition.d.ts +2 -0
- package/lib/math/spotPosition.js +8 -0
- package/lib/math/state.js +2 -2
- package/lib/math/trade.d.ts +4 -4
- package/lib/orderParams.d.ts +4 -4
- package/lib/orderParams.js +12 -4
- 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/tx/retryTxSender.d.ts +1 -1
- package/lib/tx/retryTxSender.js +4 -2
- package/lib/tx/types.d.ts +1 -1
- package/lib/types.d.ts +148 -39
- package/lib/types.js +37 -9
- package/my-script/.env +7 -0
- package/my-script/getUserStats.ts +106 -0
- package/my-script/multiConnections.ts +119 -0
- package/my-script/test-regex.ts +11 -0
- package/my-script/utils.ts +52 -0
- package/package.json +1 -1
- package/src/accounts/bulkAccountLoader.js +249 -0
- package/src/accounts/bulkUserStatsSubscription.js +75 -0
- package/src/accounts/bulkUserSubscription.js +75 -0
- package/src/accounts/fetch.js +92 -0
- package/src/accounts/pollingClearingHouseAccountSubscriber.js +465 -0
- package/src/accounts/pollingClearingHouseAccountSubscriber.ts +38 -38
- package/src/accounts/pollingOracleSubscriber.js +156 -0
- package/src/accounts/pollingTokenAccountSubscriber.js +141 -0
- package/src/accounts/pollingUserAccountSubscriber.js +208 -0
- package/src/accounts/pollingUserStatsAccountSubscriber.js +208 -0
- package/src/accounts/types.js +28 -0
- package/src/accounts/types.ts +11 -9
- package/src/accounts/utils.js +7 -0
- package/src/accounts/webSocketAccountSubscriber.js +138 -0
- package/src/accounts/webSocketClearingHouseAccountSubscriber.js +433 -0
- package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +59 -52
- package/src/accounts/webSocketUserAccountSubscriber.js +113 -0
- package/src/accounts/webSocketUserStatsAccountSubsriber.js +113 -0
- package/src/addresses/pda.js +186 -0
- package/src/addresses/pda.ts +56 -42
- package/src/admin.js +1284 -0
- package/src/admin.ts +149 -75
- package/src/assert/assert.js +1 -1
- package/src/clearingHouse.js +3433 -0
- package/src/clearingHouse.ts +1097 -380
- package/src/clearingHouseConfig.js +2 -0
- package/src/clearingHouseConfig.ts +2 -2
- package/src/clearingHouseUser.js +874 -0
- package/src/clearingHouseUser.ts +237 -172
- package/src/clearingHouseUserConfig.js +2 -0
- package/src/clearingHouseUserStats.js +115 -0
- package/src/clearingHouseUserStatsConfig.js +2 -0
- package/src/config.js +80 -0
- package/src/config.ts +30 -30
- package/src/constants/numericConstants.js +18 -11
- package/src/constants/numericConstants.ts +17 -15
- package/{lib/constants/markets.js → src/constants/perpMarkets.js} +11 -11
- package/src/constants/{markets.ts → perpMarkets.ts} +5 -5
- package/src/constants/spotMarkets.js +51 -0
- package/src/constants/{banks.ts → spotMarkets.ts} +19 -19
- package/src/events/eventList.js +66 -23
- package/src/events/eventSubscriber.js +202 -0
- package/src/events/eventSubscriber.ts +20 -12
- package/src/events/fetchLogs.js +117 -0
- package/src/events/fetchLogs.ts +35 -8
- package/src/events/pollingLogProvider.js +113 -0
- package/src/events/pollingLogProvider.ts +10 -2
- package/src/events/sort.js +41 -0
- package/src/events/txEventCache.js +22 -19
- package/src/events/types.js +25 -0
- package/src/events/types.ts +7 -1
- package/src/events/webSocketLogProvider.js +76 -0
- package/src/examples/makeTradeExample.ts +27 -6
- package/src/factory/bigNum.js +183 -180
- package/src/factory/oracleClient.js +9 -9
- package/src/idl/clearing_house.json +1128 -347
- package/src/index.js +75 -0
- package/src/index.ts +6 -3
- package/src/math/amm.js +422 -0
- package/src/math/amm.ts +73 -5
- package/src/math/auction.js +10 -10
- package/src/math/conversion.js +4 -3
- package/src/math/funding.js +223 -175
- package/src/math/funding.ts +7 -7
- package/src/math/insurance.js +27 -0
- package/src/math/margin.js +77 -0
- package/src/math/margin.ts +34 -23
- package/src/math/market.js +105 -0
- package/src/math/market.ts +71 -19
- package/src/math/oracles.js +40 -10
- package/src/math/oracles.ts +18 -1
- package/src/math/orders.js +153 -0
- package/src/math/orders.ts +5 -5
- package/src/math/position.js +172 -0
- package/src/math/position.ts +31 -31
- package/src/math/repeg.js +40 -40
- package/src/math/spotBalance.js +176 -0
- package/src/math/spotBalance.ts +290 -0
- package/src/math/spotMarket.js +8 -0
- package/src/math/spotMarket.ts +9 -0
- package/src/math/spotPosition.js +8 -0
- package/src/math/spotPosition.ts +6 -0
- package/src/math/state.ts +2 -2
- package/src/math/trade.js +81 -74
- package/src/math/trade.ts +4 -4
- package/src/math/utils.js +8 -7
- package/src/oracles/oracleClientCache.js +10 -9
- package/src/oracles/pythClient.js +52 -17
- package/src/oracles/quoteAssetOracleClient.js +44 -13
- package/src/oracles/switchboardClient.js +69 -37
- package/src/oracles/types.js +1 -1
- package/src/orderParams.js +14 -6
- package/src/orderParams.ts +16 -8
- package/src/serum/serumSubscriber.js +102 -0
- package/src/serum/serumSubscriber.ts +80 -0
- package/src/serum/types.js +2 -0
- package/src/serum/types.ts +13 -0
- package/src/slot/SlotSubscriber.js +67 -20
- package/src/token/index.js +4 -4
- package/src/tokenFaucet.js +288 -154
- package/src/tx/retryTxSender.js +280 -0
- package/src/tx/retryTxSender.ts +5 -2
- package/src/tx/types.js +1 -1
- package/src/tx/types.ts +2 -1
- package/src/tx/utils.js +7 -6
- package/src/types.js +216 -0
- package/src/types.ts +131 -39
- package/src/userName.js +5 -5
- package/src/util/computeUnits.js +46 -11
- package/src/util/promiseTimeout.js +5 -5
- package/src/util/tps.js +46 -12
- package/src/wallet.js +55 -18
- package/lib/math/bankBalance.d.ts +0 -15
- package/lib/math/bankBalance.js +0 -150
- package/src/addresses/marketAddresses.js +0 -26
- package/src/constants/banks.js +0 -42
- package/src/examples/makeTradeExample.js +0 -80
- package/src/math/bankBalance.ts +0 -258
- package/src/math/state.js +0 -15
- package/src/math/utils.js.map +0 -1
- package/src/util/getTokenAddress.js +0 -9
package/lib/admin.js
CHANGED
|
@@ -29,6 +29,7 @@ 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");
|
|
@@ -40,17 +41,16 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
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);
|
|
45
|
+
const [insuranceVaultPublicKey] = await web3_js_1.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('insurance_vault'))], this.program.programId);
|
|
46
46
|
const initializeTx = await this.program.transaction.initialize(adminControlsPrices, {
|
|
47
47
|
accounts: {
|
|
48
48
|
admin: this.wallet.publicKey,
|
|
49
49
|
state: clearingHouseStatePublicKey,
|
|
50
50
|
quoteAssetMint: usdcMint,
|
|
51
|
-
insuranceVault: insuranceVaultPublicKey,
|
|
52
|
-
insuranceVaultAuthority: insuranceVaultAuthority,
|
|
53
51
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
52
|
+
insuranceVault: insuranceVaultPublicKey,
|
|
53
|
+
clearingHouseSigner: this.getSignerPublicKey(),
|
|
54
54
|
systemProgram: anchor.web3.SystemProgram.programId,
|
|
55
55
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
56
56
|
},
|
|
@@ -58,23 +58,20 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
58
58
|
const { txSig: initializeTxSig } = await this.txSender.send(initializeTx, [], this.opts);
|
|
59
59
|
return [initializeTxSig];
|
|
60
60
|
}
|
|
61
|
-
async
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
const
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
const insuranceFundVaultAuthority = await (0, pda_1.getInsuranceFundVaultAuthorityPublicKey)(this.program.programId, bankIndex);
|
|
68
|
-
const initializeTx = await this.program.transaction.initializeBank(optimalUtilization, optimalRate, maxRate, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor, liquidationFee, {
|
|
61
|
+
async initializeSpotMarket(mint, optimalUtilization, optimalRate, maxRate, oracle, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor = new anchor_1.BN(0), liquidationFee = numericConstants_1.ZERO) {
|
|
62
|
+
const spotMarketIndex = this.getStateAccount().numberOfSpotMarkets;
|
|
63
|
+
const spotMarket = await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex);
|
|
64
|
+
const spotMarketVault = await (0, pda_1.getSpotMarketVaultPublicKey)(this.program.programId, spotMarketIndex);
|
|
65
|
+
const insuranceFundVault = await (0, pda_1.getInsuranceFundVaultPublicKey)(this.program.programId, spotMarketIndex);
|
|
66
|
+
const initializeTx = await this.program.transaction.initializeSpotMarket(optimalUtilization, optimalRate, maxRate, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor, liquidationFee, {
|
|
69
67
|
accounts: {
|
|
70
68
|
admin: this.wallet.publicKey,
|
|
71
69
|
state: await this.getStatePublicKey(),
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
bankVaultAuthority,
|
|
70
|
+
spotMarket,
|
|
71
|
+
spotMarketVault,
|
|
75
72
|
insuranceFundVault,
|
|
76
|
-
|
|
77
|
-
|
|
73
|
+
clearingHouseSigner: this.getSignerPublicKey(),
|
|
74
|
+
spotMarketMint: mint,
|
|
78
75
|
oracle,
|
|
79
76
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
80
77
|
systemProgram: anchor.web3.SystemProgram.programId,
|
|
@@ -82,13 +79,32 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
82
79
|
},
|
|
83
80
|
});
|
|
84
81
|
const { txSig } = await this.txSender.send(initializeTx, [], this.opts);
|
|
85
|
-
await this.accountSubscriber.
|
|
82
|
+
await this.accountSubscriber.addSpotMarket(spotMarketIndex);
|
|
86
83
|
await this.accountSubscriber.addOracle({
|
|
87
84
|
source: oracleSource,
|
|
88
85
|
publicKey: oracle,
|
|
89
86
|
});
|
|
90
87
|
return txSig;
|
|
91
88
|
}
|
|
89
|
+
async initializeSerumFulfillmentConfig(marketIndex, serumMarket, serumProgram) {
|
|
90
|
+
const serumOpenOrders = (0, pda_1.getSerumOpenOrdersPublicKey)(this.program.programId, serumMarket);
|
|
91
|
+
const serumFulfillmentConfig = (0, pda_1.getSerumFulfillmentConfigPublicKey)(this.program.programId, serumMarket);
|
|
92
|
+
return await this.program.rpc.initializeSerumFulfillmentConfig(marketIndex, {
|
|
93
|
+
accounts: {
|
|
94
|
+
admin: this.wallet.publicKey,
|
|
95
|
+
state: await this.getStatePublicKey(),
|
|
96
|
+
baseSpotMarket: this.getSpotMarketAccount(marketIndex).pubkey,
|
|
97
|
+
quoteSpotMarket: this.getQuoteSpotMarketAccount().pubkey,
|
|
98
|
+
clearingHouseSigner: this.getSignerPublicKey(),
|
|
99
|
+
serumProgram,
|
|
100
|
+
serumMarket,
|
|
101
|
+
serumOpenOrders,
|
|
102
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
103
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
104
|
+
serumFulfillmentConfig,
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
}
|
|
92
108
|
async initializeMarket(priceOracle, baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier = numericConstants_1.PEG_PRECISION, oracleSource = types_1.OracleSource.PYTH, marginRatioInitial = 2000, marginRatioMaintenance = 500, liquidationFee = numericConstants_1.ZERO) {
|
|
93
109
|
const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, this.getStateAccount().numberOfMarkets);
|
|
94
110
|
const initializeMarketTx = await this.program.transaction.initializeMarket(baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier, oracleSource, marginRatioInitial, marginRatioMaintenance, liquidationFee, {
|
|
@@ -102,20 +118,23 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
102
118
|
},
|
|
103
119
|
});
|
|
104
120
|
const { txSig } = await this.txSender.send(initializeMarketTx, [], this.opts);
|
|
105
|
-
await this.accountSubscriber.
|
|
121
|
+
await this.accountSubscriber.addPerpMarket(this.getStateAccount().numberOfMarkets);
|
|
106
122
|
await this.accountSubscriber.addOracle({
|
|
107
123
|
source: oracleSource,
|
|
108
124
|
publicKey: priceOracle,
|
|
109
125
|
});
|
|
110
126
|
return txSig;
|
|
111
127
|
}
|
|
112
|
-
async moveAmmPrice(baseAssetReserve, quoteAssetReserve,
|
|
128
|
+
async moveAmmPrice(marketIndex, baseAssetReserve, quoteAssetReserve, sqrtK) {
|
|
113
129
|
const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex);
|
|
114
|
-
|
|
130
|
+
if (sqrtK == undefined) {
|
|
131
|
+
sqrtK = (0, utils_1.squareRootBN)(baseAssetReserve.mul(quoteAssetReserve));
|
|
132
|
+
}
|
|
133
|
+
return await this.program.rpc.moveAmmPrice(baseAssetReserve, quoteAssetReserve, sqrtK, {
|
|
115
134
|
accounts: {
|
|
116
135
|
state: await this.getStatePublicKey(),
|
|
117
136
|
admin: this.wallet.publicKey,
|
|
118
|
-
|
|
137
|
+
perpMarket: marketPublicKey,
|
|
119
138
|
},
|
|
120
139
|
});
|
|
121
140
|
}
|
|
@@ -125,27 +144,27 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
125
144
|
state: await this.getStatePublicKey(),
|
|
126
145
|
admin: this.wallet.publicKey,
|
|
127
146
|
market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
|
|
128
|
-
oracle: this.
|
|
147
|
+
oracle: this.getPerpMarketAccount(marketIndex).amm.oracle,
|
|
129
148
|
},
|
|
130
149
|
});
|
|
131
150
|
}
|
|
132
|
-
async moveAmmToPrice(
|
|
133
|
-
const market = this.
|
|
151
|
+
async moveAmmToPrice(perpMarketIndex, targetPrice) {
|
|
152
|
+
const market = this.getPerpMarketAccount(perpMarketIndex);
|
|
134
153
|
const [direction, tradeSize, _] = (0, trade_1.calculateTargetPriceTrade)(market, targetPrice, new anchor_1.BN(1000), 'quote', undefined //todo
|
|
135
154
|
);
|
|
136
155
|
const [newQuoteAssetAmount, newBaseAssetAmount] = (0, amm_1.calculateAmmReservesAfterSwap)(market.amm, 'quote', tradeSize, (0, amm_1.getSwapDirection)('quote', direction));
|
|
137
|
-
const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId,
|
|
138
|
-
return await this.program.rpc.moveAmmPrice(newBaseAssetAmount, newQuoteAssetAmount, {
|
|
156
|
+
const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, perpMarketIndex);
|
|
157
|
+
return await this.program.rpc.moveAmmPrice(newBaseAssetAmount, newQuoteAssetAmount, market.amm.sqrtK, {
|
|
139
158
|
accounts: {
|
|
140
159
|
state: await this.getStatePublicKey(),
|
|
141
160
|
admin: this.wallet.publicKey,
|
|
142
|
-
|
|
161
|
+
perpMarket: marketPublicKey,
|
|
143
162
|
},
|
|
144
163
|
});
|
|
145
164
|
}
|
|
146
165
|
async repegAmmCurve(newPeg, marketIndex) {
|
|
147
166
|
const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex);
|
|
148
|
-
const ammData = this.
|
|
167
|
+
const ammData = this.getPerpMarketAccount(marketIndex).amm;
|
|
149
168
|
return await this.program.rpc.repegAmmCurve(newPeg, {
|
|
150
169
|
accounts: {
|
|
151
170
|
state: await this.getStatePublicKey(),
|
|
@@ -156,7 +175,7 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
156
175
|
});
|
|
157
176
|
}
|
|
158
177
|
async updateAmmOracleTwap(marketIndex) {
|
|
159
|
-
const ammData = this.
|
|
178
|
+
const ammData = this.getPerpMarketAccount(marketIndex).amm;
|
|
160
179
|
const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex);
|
|
161
180
|
return await this.program.rpc.updateAmmOracleTwap({
|
|
162
181
|
accounts: {
|
|
@@ -168,7 +187,7 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
168
187
|
});
|
|
169
188
|
}
|
|
170
189
|
async resetAmmOracleTwap(marketIndex) {
|
|
171
|
-
const ammData = this.
|
|
190
|
+
const ammData = this.getPerpMarketAccount(marketIndex).amm;
|
|
172
191
|
const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex);
|
|
173
192
|
return await this.program.rpc.resetAmmOracleTwap({
|
|
174
193
|
accounts: {
|
|
@@ -181,14 +200,14 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
181
200
|
}
|
|
182
201
|
async withdrawFromInsuranceVault(amount, recipient) {
|
|
183
202
|
const state = await this.getStateAccount();
|
|
184
|
-
const
|
|
203
|
+
const spotMarket = this.getQuoteSpotMarketAccount();
|
|
185
204
|
return await this.program.rpc.withdrawFromInsuranceVault(amount, {
|
|
186
205
|
accounts: {
|
|
187
206
|
admin: this.wallet.publicKey,
|
|
188
207
|
state: await this.getStatePublicKey(),
|
|
189
|
-
|
|
208
|
+
spotMarket: spotMarket.pubkey,
|
|
190
209
|
insuranceVault: state.insuranceVault,
|
|
191
|
-
|
|
210
|
+
clearingHouseSigner: this.getSignerPublicKey(),
|
|
192
211
|
recipient: recipient,
|
|
193
212
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
194
213
|
},
|
|
@@ -196,15 +215,15 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
196
215
|
}
|
|
197
216
|
async withdrawFromMarketToInsuranceVault(marketIndex, amount, recipient) {
|
|
198
217
|
const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex);
|
|
199
|
-
const
|
|
218
|
+
const spotMarket = this.getQuoteSpotMarketAccount();
|
|
200
219
|
return await this.program.rpc.withdrawFromMarketToInsuranceVault(amount, {
|
|
201
220
|
accounts: {
|
|
202
221
|
admin: this.wallet.publicKey,
|
|
203
222
|
state: await this.getStatePublicKey(),
|
|
204
223
|
market: marketPublicKey,
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
224
|
+
spotMarket: spotMarket.pubkey,
|
|
225
|
+
spotMarketVault: spotMarket.vault,
|
|
226
|
+
clearingHouseSigner: this.getSignerPublicKey(),
|
|
208
227
|
recipient: recipient,
|
|
209
228
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
210
229
|
},
|
|
@@ -212,17 +231,16 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
212
231
|
}
|
|
213
232
|
async withdrawFromInsuranceVaultToMarket(marketIndex, amount) {
|
|
214
233
|
const state = await this.getStateAccount();
|
|
215
|
-
const
|
|
234
|
+
const spotMarket = this.getQuoteSpotMarketAccount();
|
|
216
235
|
return await this.program.rpc.withdrawFromInsuranceVaultToMarket(amount, {
|
|
217
236
|
accounts: {
|
|
218
237
|
admin: this.wallet.publicKey,
|
|
219
238
|
state: await this.getStatePublicKey(),
|
|
220
239
|
market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
|
|
221
240
|
insuranceVault: state.insuranceVault,
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
bankVaultAuthority: bank.vaultAuthority,
|
|
241
|
+
clearingHouseSigner: this.getSignerPublicKey(),
|
|
242
|
+
quoteSpotMarket: spotMarket.pubkey,
|
|
243
|
+
spotMarketVault: spotMarket.vault,
|
|
226
244
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
227
245
|
},
|
|
228
246
|
});
|
|
@@ -346,30 +364,30 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
346
364
|
},
|
|
347
365
|
});
|
|
348
366
|
}
|
|
349
|
-
async
|
|
350
|
-
return await this.program.rpc.
|
|
367
|
+
async updateWithdrawGuardThreshold(marketIndex, withdrawGuardThreshold) {
|
|
368
|
+
return await this.program.rpc.updateWithdrawGuardThreshold(withdrawGuardThreshold, {
|
|
351
369
|
accounts: {
|
|
352
370
|
admin: this.wallet.publicKey,
|
|
353
371
|
state: await this.getStatePublicKey(),
|
|
354
|
-
|
|
372
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex),
|
|
355
373
|
},
|
|
356
374
|
});
|
|
357
375
|
}
|
|
358
|
-
async
|
|
359
|
-
return await this.program.rpc.
|
|
376
|
+
async updateSpotMarketIfFactor(marketIndex, userIfFactor, totalIfFactor, liquidationIfFactor) {
|
|
377
|
+
return await this.program.rpc.updateSpotMarketIfFactor(marketIndex, userIfFactor, totalIfFactor, liquidationIfFactor, {
|
|
360
378
|
accounts: {
|
|
361
379
|
admin: this.wallet.publicKey,
|
|
362
380
|
state: await this.getStatePublicKey(),
|
|
363
|
-
|
|
381
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex),
|
|
364
382
|
},
|
|
365
383
|
});
|
|
366
384
|
}
|
|
367
|
-
async
|
|
368
|
-
return await this.program.rpc.
|
|
385
|
+
async updateInsuranceWithdrawEscrowPeriod(marketIndex, insuranceWithdrawEscrowPeriod) {
|
|
386
|
+
return await this.program.rpc.updateInsuranceWithdrawEscrowPeriod(insuranceWithdrawEscrowPeriod, {
|
|
369
387
|
accounts: {
|
|
370
388
|
admin: this.wallet.publicKey,
|
|
371
389
|
state: await this.getStatePublicKey(),
|
|
372
|
-
|
|
390
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex),
|
|
373
391
|
},
|
|
374
392
|
});
|
|
375
393
|
}
|
|
@@ -409,6 +427,15 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
409
427
|
},
|
|
410
428
|
});
|
|
411
429
|
}
|
|
430
|
+
async updateMarketExpiry(perpMarketIndex, expiryTs) {
|
|
431
|
+
return await this.program.rpc.updateMarketExpiry(expiryTs, {
|
|
432
|
+
accounts: {
|
|
433
|
+
admin: this.wallet.publicKey,
|
|
434
|
+
state: await this.getStatePublicKey(),
|
|
435
|
+
perpMarket: await (0, pda_1.getMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
436
|
+
},
|
|
437
|
+
});
|
|
438
|
+
}
|
|
412
439
|
async updateWhitelistMint(whitelistMint) {
|
|
413
440
|
return await this.program.rpc.updateWhitelistMint(whitelistMint, {
|
|
414
441
|
accounts: {
|
|
@@ -470,7 +497,7 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
470
497
|
accounts: {
|
|
471
498
|
admin: this.wallet.publicKey,
|
|
472
499
|
state: await this.getStatePublicKey(),
|
|
473
|
-
market: this.
|
|
500
|
+
market: this.getPerpMarketAccount(marketIndex).pubkey,
|
|
474
501
|
},
|
|
475
502
|
});
|
|
476
503
|
}
|
|
@@ -479,7 +506,16 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
479
506
|
accounts: {
|
|
480
507
|
admin: this.wallet.publicKey,
|
|
481
508
|
state: await this.getStatePublicKey(),
|
|
482
|
-
market: this.
|
|
509
|
+
market: this.getPerpMarketAccount(marketIndex).pubkey,
|
|
510
|
+
},
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
async updateMarketMaxImbalances(marketIndex, unrealizedMaxImbalance, maxRevenueWithdrawPerPeriod, quoteMaxInsurance) {
|
|
514
|
+
return await this.program.rpc.updateMarketMaxImbalances(unrealizedMaxImbalance, maxRevenueWithdrawPerPeriod, quoteMaxInsurance, {
|
|
515
|
+
accounts: {
|
|
516
|
+
admin: this.wallet.publicKey,
|
|
517
|
+
state: await this.getStatePublicKey(),
|
|
518
|
+
market: await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex),
|
|
483
519
|
},
|
|
484
520
|
});
|
|
485
521
|
}
|
package/lib/clearingHouse.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="bn.js" />
|
|
3
3
|
import { AnchorProvider, BN, Program } from '@project-serum/anchor';
|
|
4
|
-
import { StateAccount, IWallet, PositionDirection, UserAccount,
|
|
5
|
-
import { Connection, PublicKey, TransactionSignature, ConfirmOptions, TransactionInstruction, AccountMeta } from '@solana/web3.js';
|
|
4
|
+
import { StateAccount, IWallet, PositionDirection, UserAccount, PerpMarketAccount, OrderParams, Order, SpotMarketAccount, SpotPosition, MakerInfo, TakerInfo, OptionalOrderParams, ReferrerInfo, MarketType, SerumV3FulfillmentConfigAccount } from './types';
|
|
5
|
+
import { Connection, PublicKey, TransactionSignature, ConfirmOptions, Transaction, TransactionInstruction, AccountMeta } from '@solana/web3.js';
|
|
6
6
|
import { TokenFaucet } from './tokenFaucet';
|
|
7
7
|
import { EventEmitter } from 'events';
|
|
8
8
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
@@ -47,12 +47,15 @@ export declare class ClearingHouse {
|
|
|
47
47
|
unsubscribeUsers(): Promise<void>[];
|
|
48
48
|
statePublicKey?: PublicKey;
|
|
49
49
|
getStatePublicKey(): Promise<PublicKey>;
|
|
50
|
+
signerPublicKey?: PublicKey;
|
|
51
|
+
getSignerPublicKey(): PublicKey;
|
|
50
52
|
getStateAccount(): StateAccount;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
getPerpMarketAccount(marketIndex: BN | number): PerpMarketAccount | undefined;
|
|
54
|
+
getPerpMarketAccounts(): PerpMarketAccount[];
|
|
55
|
+
getSpotMarketAccount(marketIndex: BN | number): SpotMarketAccount | undefined;
|
|
56
|
+
getQuoteSpotMarketAccount(): SpotMarketAccount;
|
|
55
57
|
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
|
|
58
|
+
getSerumV3FulfillmentConfig(serumMarket: PublicKey): Promise<SerumV3FulfillmentConfigAccount>;
|
|
56
59
|
/**
|
|
57
60
|
* Update the wallet to use for clearing house transactions and linked user account
|
|
58
61
|
* @param newWallet
|
|
@@ -65,6 +68,7 @@ export declare class ClearingHouse {
|
|
|
65
68
|
initializeUserAccount(userId?: number, name?: string, referrerInfo?: ReferrerInfo): Promise<[TransactionSignature, PublicKey]>;
|
|
66
69
|
getInitializeUserInstructions(userId?: number, name?: string, referrerInfo?: ReferrerInfo): Promise<[PublicKey, TransactionInstruction]>;
|
|
67
70
|
getInitializeUserStatsIx(): Promise<TransactionInstruction>;
|
|
71
|
+
updateUserName(name: string, userId?: number): Promise<TransactionSignature>;
|
|
68
72
|
getUser(userId?: number): ClearingHouseUser;
|
|
69
73
|
getUsers(): ClearingHouseUser[];
|
|
70
74
|
getUserStats(): ClearingHouseUserStats;
|
|
@@ -73,17 +77,18 @@ export declare class ClearingHouse {
|
|
|
73
77
|
getUserAccountPublicKey(): Promise<PublicKey>;
|
|
74
78
|
getUserAccount(userId?: number): UserAccount | undefined;
|
|
75
79
|
getUserAccountAndSlot(userId?: number): DataAndSlot<UserAccount> | undefined;
|
|
76
|
-
|
|
80
|
+
getSpotPosition(marketIndex: number | BN): SpotPosition | undefined;
|
|
77
81
|
getQuoteAssetTokenAmount(): BN;
|
|
78
82
|
getRemainingAccounts(params: {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
83
|
+
writablePerpMarketIndex?: BN;
|
|
84
|
+
writableSpotMarketIndex?: BN;
|
|
85
|
+
readablePerpMarketIndex?: BN;
|
|
86
|
+
readableSpotMarketIndex?: BN;
|
|
82
87
|
}): AccountMeta[];
|
|
83
88
|
getOrder(orderId: BN | number): Order | undefined;
|
|
84
89
|
getOrderByUserId(userOrderId: number): Order | undefined;
|
|
85
|
-
deposit(amount: BN,
|
|
86
|
-
getDepositInstruction(amount: BN,
|
|
90
|
+
deposit(amount: BN, marketIndex: BN, collateralAccountPublicKey: PublicKey, userId?: number, reduceOnly?: boolean): Promise<TransactionSignature>;
|
|
91
|
+
getDepositInstruction(amount: BN, marketIndex: BN, userTokenAccount: PublicKey, userId?: number, reduceOnly?: boolean, userInitialized?: boolean): Promise<TransactionInstruction>;
|
|
87
92
|
private checkIfAccountExists;
|
|
88
93
|
private getSolWithdrawalIxs;
|
|
89
94
|
private getWrappedSolAccountCreationIxs;
|
|
@@ -91,20 +96,20 @@ export declare class ClearingHouse {
|
|
|
91
96
|
* Creates the Clearing House User account for a user, and deposits some initial collateral
|
|
92
97
|
* @param amount
|
|
93
98
|
* @param userTokenAccount
|
|
94
|
-
* @param
|
|
99
|
+
* @param marketIndex
|
|
95
100
|
* @param userId
|
|
96
101
|
* @param name
|
|
97
102
|
* @param fromUserId
|
|
98
103
|
* @returns
|
|
99
104
|
*/
|
|
100
|
-
initializeUserAccountAndDepositCollateral(amount: BN, userTokenAccount: PublicKey,
|
|
101
|
-
initializeUserAccountForDevnet(userId: number, name: string,
|
|
102
|
-
withdraw(amount: BN,
|
|
103
|
-
getWithdrawIx(amount: BN,
|
|
104
|
-
transferDeposit(amount: BN,
|
|
105
|
-
getTransferDepositIx(amount: BN,
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
initializeUserAccountAndDepositCollateral(amount: BN, userTokenAccount: PublicKey, marketIndex?: BN, userId?: number, name?: string, fromUserId?: number, referrerInfo?: ReferrerInfo): Promise<[TransactionSignature, PublicKey]>;
|
|
106
|
+
initializeUserAccountForDevnet(userId: number, name: string, marketIndex: BN, tokenFaucet: TokenFaucet, amount: BN, referrerInfo?: ReferrerInfo): Promise<[TransactionSignature, PublicKey]>;
|
|
107
|
+
withdraw(amount: BN, marketIndex: BN, userTokenAccount: PublicKey, reduceOnly?: boolean): Promise<TransactionSignature>;
|
|
108
|
+
getWithdrawIx(amount: BN, marketIndex: BN, userTokenAccount: PublicKey, reduceOnly?: boolean): Promise<TransactionInstruction>;
|
|
109
|
+
transferDeposit(amount: BN, marketIndex: BN, fromUserId: number, toUserId: number): Promise<TransactionSignature>;
|
|
110
|
+
getTransferDepositIx(amount: BN, marketIndex: BN, fromUserId: number, toUserId: number): Promise<TransactionInstruction>;
|
|
111
|
+
updateSpotMarketCumulativeInterest(marketIndex: BN): Promise<TransactionSignature>;
|
|
112
|
+
updateSpotMarketCumulativeInterestIx(marketIndex: BN): Promise<TransactionInstruction>;
|
|
108
113
|
settleLP(settleeUserAccountPublicKey: PublicKey, marketIndex: BN): Promise<TransactionSignature>;
|
|
109
114
|
settleLPIx(settleeUserAccountPublicKey: PublicKey, marketIndex: BN): Promise<TransactionInstruction>;
|
|
110
115
|
removeLiquidity(marketIndex: BN, sharesToBurn?: BN): Promise<TransactionSignature>;
|
|
@@ -112,19 +117,39 @@ export declare class ClearingHouse {
|
|
|
112
117
|
addLiquidity(amount: BN, marketIndex: BN): Promise<TransactionSignature>;
|
|
113
118
|
getAddLiquidityIx(amount: BN, marketIndex: BN): Promise<TransactionInstruction>;
|
|
114
119
|
openPosition(direction: PositionDirection, amount: BN, marketIndex: BN, limitPrice?: BN): Promise<TransactionSignature>;
|
|
120
|
+
sendSignedTx(tx: Transaction): Promise<TransactionSignature>;
|
|
121
|
+
/**
|
|
122
|
+
* Sends a market order and returns a signed tx which can fill the order against the vamm, which the caller can use to fill their own order if required.
|
|
123
|
+
* @param orderParams
|
|
124
|
+
* @param userAccountPublicKey
|
|
125
|
+
* @param userAccount
|
|
126
|
+
* @returns
|
|
127
|
+
*/
|
|
128
|
+
sendMarketOrderAndGetSignedFillTx(orderParams: OptionalOrderParams, userAccountPublicKey: PublicKey, userAccount: UserAccount): Promise<{
|
|
129
|
+
txSig: TransactionSignature;
|
|
130
|
+
signedFillTx: Transaction;
|
|
131
|
+
}>;
|
|
115
132
|
placeOrder(orderParams: OptionalOrderParams): Promise<TransactionSignature>;
|
|
116
|
-
getOrderParams(optionalOrderParams: OptionalOrderParams): OrderParams;
|
|
133
|
+
getOrderParams(optionalOrderParams: OptionalOrderParams, marketType: MarketType): OrderParams;
|
|
117
134
|
getPlaceOrderIx(orderParams: OptionalOrderParams): Promise<TransactionInstruction>;
|
|
118
135
|
updateAMMs(marketIndexes: BN[]): Promise<TransactionSignature>;
|
|
119
136
|
getUpdateAMMsIx(marketIndexes: BN[]): Promise<TransactionInstruction>;
|
|
137
|
+
settleExpiredMarket(marketIndex: BN): Promise<TransactionSignature>;
|
|
138
|
+
getSettleExpiredMarketIx(marketIndex: BN): Promise<TransactionInstruction>;
|
|
120
139
|
cancelOrder(orderId?: BN): Promise<TransactionSignature>;
|
|
121
140
|
getCancelOrderIx(orderId?: BN): Promise<TransactionInstruction>;
|
|
122
141
|
cancelOrderByUserId(userOrderId: number): Promise<TransactionSignature>;
|
|
123
142
|
getCancelOrderByUserIdIx(userOrderId: number): Promise<TransactionInstruction>;
|
|
124
143
|
fillOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
|
|
125
|
-
getFillOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
144
|
+
getFillOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
145
|
+
placeSpotOrder(orderParams: OptionalOrderParams): Promise<TransactionSignature>;
|
|
146
|
+
getPlaceSpotOrderIx(orderParams: OptionalOrderParams): Promise<TransactionInstruction>;
|
|
147
|
+
fillSpotOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
|
|
148
|
+
getFillSpotOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
126
149
|
triggerOrder(userAccountPublicKey: PublicKey, user: UserAccount, order: Order): Promise<TransactionSignature>;
|
|
127
150
|
getTriggerOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order): Promise<TransactionInstruction>;
|
|
151
|
+
triggerSpotOrder(userAccountPublicKey: PublicKey, user: UserAccount, order: Order): Promise<TransactionSignature>;
|
|
152
|
+
getTriggerSpotOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order): Promise<TransactionInstruction>;
|
|
128
153
|
placeAndTake(orderParams: OptionalOrderParams, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
|
|
129
154
|
getPlaceAndTakeIx(orderParams: OptionalOrderParams, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
130
155
|
placeAndMake(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
|
|
@@ -141,22 +166,24 @@ export declare class ClearingHouse {
|
|
|
141
166
|
}[], marketIndex: BN): Promise<TransactionSignature>;
|
|
142
167
|
settlePNL(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: BN): Promise<TransactionSignature>;
|
|
143
168
|
settlePNLIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: BN): Promise<TransactionInstruction>;
|
|
169
|
+
settleExpiredPosition(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: BN): Promise<TransactionSignature>;
|
|
170
|
+
getSettleExpiredPositionIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: BN): Promise<TransactionInstruction>;
|
|
144
171
|
liquidatePerp(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: BN, maxBaseAssetAmount: BN): Promise<TransactionSignature>;
|
|
145
172
|
getLiquidatePerpIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: BN, maxBaseAssetAmount: BN): Promise<TransactionInstruction>;
|
|
146
|
-
liquidateBorrow(userAccountPublicKey: PublicKey, userAccount: UserAccount,
|
|
147
|
-
getLiquidateBorrowIx(userAccountPublicKey: PublicKey, userAccount: UserAccount,
|
|
148
|
-
liquidateBorrowForPerpPnl(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: BN,
|
|
149
|
-
getLiquidateBorrowForPerpPnlIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: BN,
|
|
150
|
-
liquidatePerpPnlForDeposit(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: BN,
|
|
151
|
-
getLiquidatePerpPnlForDepositIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: BN,
|
|
152
|
-
resolvePerpBankruptcy(userAccountPublicKey: PublicKey, userAccount: UserAccount,
|
|
153
|
-
getResolvePerpBankruptcyIx(userAccountPublicKey: PublicKey, userAccount: UserAccount,
|
|
154
|
-
resolveBorrowBankruptcy(userAccountPublicKey: PublicKey, userAccount: UserAccount,
|
|
155
|
-
getResolveBorrowBankruptcyIx(userAccountPublicKey: PublicKey, userAccount: UserAccount,
|
|
173
|
+
liquidateBorrow(userAccountPublicKey: PublicKey, userAccount: UserAccount, assetmarketIndex: BN, liabilitymarketIndex: BN, maxLiabilityTransfer: BN): Promise<TransactionSignature>;
|
|
174
|
+
getLiquidateBorrowIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, assetmarketIndex: BN, liabilitymarketIndex: BN, maxLiabilityTransfer: BN): Promise<TransactionInstruction>;
|
|
175
|
+
liquidateBorrowForPerpPnl(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: BN, liabilitymarketIndex: BN, maxLiabilityTransfer: BN): Promise<TransactionSignature>;
|
|
176
|
+
getLiquidateBorrowForPerpPnlIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: BN, liabilitymarketIndex: BN, maxLiabilityTransfer: BN): Promise<TransactionInstruction>;
|
|
177
|
+
liquidatePerpPnlForDeposit(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: BN, assetMarketIndex: BN, maxPnlTransfer: BN): Promise<TransactionSignature>;
|
|
178
|
+
getLiquidatePerpPnlForDepositIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: BN, assetMarketIndex: BN, maxPnlTransfer: BN): Promise<TransactionInstruction>;
|
|
179
|
+
resolvePerpBankruptcy(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: BN): Promise<TransactionSignature>;
|
|
180
|
+
getResolvePerpBankruptcyIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: BN): Promise<TransactionInstruction>;
|
|
181
|
+
resolveBorrowBankruptcy(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: BN): Promise<TransactionSignature>;
|
|
182
|
+
getResolveBorrowBankruptcyIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: BN): Promise<TransactionInstruction>;
|
|
156
183
|
getRemainingAccountsWithCounterparty(params: {
|
|
157
184
|
counterPartyUserAccount: UserAccount;
|
|
158
|
-
|
|
159
|
-
|
|
185
|
+
writablePerpMarketIndex?: BN;
|
|
186
|
+
writableSpotMarketIndexes?: BN[];
|
|
160
187
|
}): AccountMeta[];
|
|
161
188
|
updateFundingRate(oracle: PublicKey, marketIndex: BN): Promise<TransactionSignature>;
|
|
162
189
|
getUpdateFundingRateIx(oracle: PublicKey, marketIndex: BN): Promise<TransactionInstruction>;
|
|
@@ -164,11 +191,13 @@ export declare class ClearingHouse {
|
|
|
164
191
|
getSettleFundingPaymentIx(userAccount: PublicKey): Promise<TransactionInstruction>;
|
|
165
192
|
triggerEvent(eventName: keyof ClearingHouseAccountEvents, data?: any): void;
|
|
166
193
|
getOracleDataForMarket(marketIndex: BN): OraclePriceData;
|
|
167
|
-
initializeInsuranceFundStake(
|
|
168
|
-
getInitializeInsuranceFundStakeIx(
|
|
169
|
-
addInsuranceFundStake(
|
|
170
|
-
requestRemoveInsuranceFundStake(
|
|
171
|
-
cancelRequestRemoveInsuranceFundStake(
|
|
172
|
-
removeInsuranceFundStake(
|
|
173
|
-
settleRevenueToInsuranceFund(
|
|
194
|
+
initializeInsuranceFundStake(marketIndex: BN): Promise<TransactionSignature>;
|
|
195
|
+
getInitializeInsuranceFundStakeIx(marketIndex: BN): Promise<TransactionInstruction>;
|
|
196
|
+
addInsuranceFundStake(marketIndex: BN, amount: BN, collateralAccountPublicKey: PublicKey): Promise<TransactionSignature>;
|
|
197
|
+
requestRemoveInsuranceFundStake(marketIndex: BN, amount: BN): Promise<TransactionSignature>;
|
|
198
|
+
cancelRequestRemoveInsuranceFundStake(marketIndex: BN): Promise<TransactionSignature>;
|
|
199
|
+
removeInsuranceFundStake(marketIndex: BN, collateralAccountPublicKey: PublicKey): Promise<TransactionSignature>;
|
|
200
|
+
settleRevenueToInsuranceFund(marketIndex: BN): Promise<TransactionSignature>;
|
|
201
|
+
resolvePerpPnlDeficit(spotMarketIndex: BN, perpMarketIndex: BN): Promise<TransactionSignature>;
|
|
202
|
+
getResolvePerpPnlDeficitIx(spotMarketIndex: BN, perpMarketIndex: BN): Promise<TransactionInstruction>;
|
|
174
203
|
}
|