@drift-labs/sdk 0.1.36-master.7 → 0.2.0-master.10
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/bulkAccountLoader.d.ts +6 -6
- package/lib/accounts/bulkAccountLoader.js +81 -95
- package/lib/accounts/bulkUserSubscription.js +13 -57
- package/lib/accounts/fetch.d.ts +4 -0
- package/lib/accounts/fetch.js +18 -0
- package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +34 -38
- package/lib/accounts/pollingClearingHouseAccountSubscriber.js +224 -224
- package/lib/accounts/pollingOracleSubscriber.d.ts +3 -3
- package/lib/accounts/pollingOracleSubscriber.js +37 -49
- package/lib/accounts/pollingTokenAccountSubscriber.d.ts +3 -3
- package/lib/accounts/pollingTokenAccountSubscriber.js +35 -50
- package/lib/accounts/pollingUserAccountSubscriber.d.ts +7 -13
- package/lib/accounts/pollingUserAccountSubscriber.js +71 -134
- package/lib/accounts/types.d.ts +34 -41
- package/lib/accounts/webSocketAccountSubscriber.d.ts +6 -4
- package/lib/accounts/webSocketAccountSubscriber.js +39 -35
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +33 -28
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +153 -185
- package/lib/accounts/webSocketUserAccountSubscriber.d.ts +5 -11
- package/lib/accounts/webSocketUserAccountSubscriber.js +22 -67
- package/lib/addresses/marketAddresses.d.ts +4 -0
- package/lib/addresses/marketAddresses.js +15 -0
- package/lib/addresses/pda.d.ts +12 -0
- package/lib/addresses/pda.js +83 -0
- package/lib/admin.d.ts +12 -18
- package/lib/admin.js +398 -558
- package/lib/clearingHouse.d.ts +83 -109
- package/lib/clearingHouse.js +832 -893
- package/lib/clearingHouseConfig.d.ts +34 -0
- package/lib/clearingHouseConfig.js +2 -0
- package/lib/clearingHouseUser.d.ts +19 -22
- package/lib/clearingHouseUser.js +155 -141
- package/lib/clearingHouseUserConfig.d.ts +14 -0
- package/lib/clearingHouseUserConfig.js +2 -0
- package/lib/config.d.ts +12 -0
- package/lib/config.js +35 -4
- package/lib/constants/banks.d.ts +16 -0
- package/lib/constants/banks.js +41 -0
- package/lib/constants/markets.d.ts +8 -3
- package/lib/constants/markets.js +13 -206
- package/lib/constants/numericConstants.d.ts +17 -0
- package/lib/constants/numericConstants.js +23 -6
- package/lib/events/eventList.d.ts +22 -0
- package/lib/events/eventList.js +77 -0
- package/lib/events/eventSubscriber.d.ts +34 -0
- package/lib/events/eventSubscriber.js +126 -0
- package/lib/events/fetchLogs.d.ts +13 -0
- package/lib/events/fetchLogs.js +39 -0
- package/lib/events/pollingLogProvider.d.ts +15 -0
- package/lib/events/pollingLogProvider.js +53 -0
- package/lib/events/sort.d.ts +2 -0
- package/lib/events/sort.js +44 -0
- package/lib/events/txEventCache.d.ts +24 -0
- package/lib/events/txEventCache.js +71 -0
- package/lib/events/types.d.ts +49 -0
- package/lib/events/types.js +20 -0
- package/lib/events/webSocketLogProvider.d.ts +12 -0
- package/lib/events/webSocketLogProvider.js +30 -0
- package/lib/examples/makeTradeExample.js +26 -27
- package/lib/factory/bigNum.d.ts +118 -0
- package/lib/factory/bigNum.js +364 -0
- package/lib/factory/oracleClient.d.ts +1 -2
- package/lib/factory/oracleClient.js +6 -2
- package/lib/idl/clearing_house.json +2258 -2774
- package/lib/index.d.ts +14 -5
- package/lib/index.js +18 -5
- package/lib/math/amm.d.ts +24 -29
- package/lib/math/amm.js +209 -176
- package/lib/math/auction.d.ts +5 -0
- package/lib/math/auction.js +42 -0
- package/lib/math/bankBalance.d.ts +9 -0
- package/lib/math/bankBalance.js +75 -0
- package/lib/math/conversion.d.ts +0 -1
- package/lib/math/conversion.js +1 -5
- package/lib/math/funding.d.ts +6 -6
- package/lib/math/funding.js +158 -175
- package/lib/math/market.d.ts +6 -6
- package/lib/math/market.js +10 -9
- package/lib/math/orders.d.ts +6 -1
- package/lib/math/orders.js +38 -1
- package/lib/math/position.d.ts +7 -5
- package/lib/math/position.js +29 -27
- package/lib/math/repeg.d.ts +22 -0
- package/lib/math/repeg.js +128 -0
- package/lib/math/trade.d.ts +5 -4
- package/lib/math/trade.js +29 -24
- package/lib/mockUSDCFaucet.js +87 -116
- package/lib/oracles/oracleClientCache.d.ts +8 -0
- package/lib/oracles/oracleClientCache.js +19 -0
- package/lib/oracles/pythClient.d.ts +3 -5
- package/lib/oracles/pythClient.js +12 -31
- package/lib/oracles/quoteAssetOracleClient.d.ts +9 -0
- package/lib/oracles/quoteAssetOracleClient.js +21 -0
- package/lib/oracles/switchboardClient.d.ts +3 -5
- package/lib/oracles/switchboardClient.js +29 -50
- package/lib/oracles/types.d.ts +6 -1
- package/lib/orderParams.d.ts +14 -5
- package/lib/orderParams.js +8 -96
- package/lib/orders.d.ts +6 -7
- package/lib/orders.js +11 -89
- package/lib/slot/SlotSubscriber.d.ts +19 -0
- package/lib/slot/SlotSubscriber.js +26 -0
- package/lib/tx/retryTxSender.d.ts +2 -2
- package/lib/tx/retryTxSender.js +108 -123
- package/lib/tx/types.d.ts +5 -1
- package/lib/tx/utils.d.ts +1 -1
- package/lib/tx/utils.js +11 -2
- package/lib/types.d.ts +180 -110
- package/lib/types.js +54 -1
- package/lib/userName.d.ts +4 -0
- package/lib/userName.js +20 -0
- package/lib/util/computeUnits.js +10 -21
- package/lib/util/tps.js +11 -22
- package/lib/wallet.js +7 -20
- package/package.json +11 -4
- package/src/accounts/bulkAccountLoader.js +197 -0
- package/src/accounts/bulkAccountLoader.ts +21 -15
- package/src/accounts/bulkUserSubscription.js +33 -0
- package/src/accounts/bulkUserSubscription.ts +1 -45
- package/src/accounts/fetch.js +29 -0
- package/src/accounts/fetch.ts +33 -0
- package/src/accounts/pollingClearingHouseAccountSubscriber.js +311 -0
- package/src/accounts/pollingClearingHouseAccountSubscriber.ts +249 -214
- package/src/accounts/pollingOracleSubscriber.js +93 -0
- package/src/accounts/pollingOracleSubscriber.ts +16 -8
- package/src/accounts/pollingTokenAccountSubscriber.js +90 -0
- package/src/accounts/pollingTokenAccountSubscriber.ts +11 -8
- package/src/accounts/pollingUserAccountSubscriber.js +132 -0
- package/src/accounts/pollingUserAccountSubscriber.ts +21 -86
- package/src/accounts/types.js +10 -0
- package/src/accounts/types.ts +41 -70
- package/src/accounts/utils.js +7 -0
- package/src/accounts/webSocketAccountSubscriber.js +93 -0
- package/src/accounts/webSocketAccountSubscriber.ts +33 -16
- package/src/accounts/webSocketClearingHouseAccountSubscriber.js +233 -0
- package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +190 -240
- package/src/accounts/webSocketUserAccountSubscriber.js +62 -0
- package/src/accounts/webSocketUserAccountSubscriber.ts +11 -71
- package/src/addresses/marketAddresses.js +26 -0
- package/src/addresses/marketAddresses.ts +18 -0
- package/{lib/addresses.js → src/addresses/pda.js} +45 -34
- package/src/addresses/pda.ts +118 -0
- package/src/admin.ts +247 -336
- package/src/assert/assert.js +9 -0
- package/src/clearingHouse.ts +1023 -1026
- package/src/clearingHouseConfig.ts +37 -0
- package/src/clearingHouseUser.ts +275 -185
- package/src/clearingHouseUserConfig.ts +18 -0
- package/src/config.ts +54 -1
- package/src/constants/banks.ts +50 -0
- package/src/constants/markets.ts +16 -207
- package/src/constants/numericConstants.ts +34 -5
- package/src/events/eventList.js +77 -0
- package/src/events/eventList.ts +94 -0
- package/src/events/eventSubscriber.js +139 -0
- package/src/events/eventSubscriber.ts +194 -0
- package/src/events/fetchLogs.js +50 -0
- package/src/events/fetchLogs.ts +80 -0
- package/src/events/pollingLogProvider.js +64 -0
- package/src/events/pollingLogProvider.ts +79 -0
- package/src/events/sort.js +44 -0
- package/src/events/sort.ts +65 -0
- package/src/events/txEventCache.js +71 -0
- package/src/events/txEventCache.ts +74 -0
- package/src/events/types.js +20 -0
- package/src/events/types.ts +98 -0
- package/src/events/webSocketLogProvider.js +41 -0
- package/src/events/webSocketLogProvider.ts +38 -0
- package/src/examples/makeTradeExample.js +80 -0
- package/src/examples/makeTradeExample.ts +20 -11
- package/src/factory/bigNum.js +364 -0
- package/src/factory/bigNum.ts +524 -0
- package/src/factory/oracleClient.js +20 -0
- package/src/factory/oracleClient.ts +7 -4
- package/src/idl/clearing_house.json +2258 -2774
- package/src/index.js +69 -0
- package/src/index.ts +14 -5
- package/src/math/amm.js +369 -0
- package/src/math/amm.ts +382 -243
- package/src/math/auction.js +42 -0
- package/src/math/auction.ts +43 -0
- package/src/math/bankBalance.js +75 -0
- package/src/math/bankBalance.ts +112 -0
- package/src/math/conversion.js +11 -0
- package/src/math/conversion.ts +1 -11
- package/src/math/funding.js +248 -0
- package/src/math/funding.ts +12 -9
- package/src/math/market.js +57 -0
- package/src/math/market.ts +37 -30
- package/src/math/oracles.js +26 -0
- package/src/math/orders.js +110 -0
- package/src/math/orders.ts +43 -1
- package/src/math/position.js +140 -0
- package/src/math/position.ts +52 -35
- package/src/math/repeg.js +128 -0
- package/src/math/repeg.ts +176 -0
- package/src/math/state.js +15 -0
- package/src/math/trade.js +253 -0
- package/src/math/trade.ts +55 -47
- package/src/math/utils.js +26 -0
- package/src/math/utils.js.map +1 -0
- package/src/mockUSDCFaucet.js +171 -0
- package/src/oracles/oracleClientCache.js +19 -0
- package/src/oracles/oracleClientCache.ts +20 -0
- package/src/oracles/pythClient.js +46 -0
- package/src/oracles/pythClient.ts +4 -11
- package/src/oracles/quoteAssetOracleClient.js +32 -0
- package/src/oracles/quoteAssetOracleClient.ts +25 -0
- package/src/oracles/switchboardClient.js +69 -0
- package/src/oracles/switchboardClient.ts +11 -24
- package/src/oracles/types.js +2 -0
- package/src/oracles/types.ts +7 -1
- package/src/orderParams.js +20 -0
- package/src/orderParams.ts +20 -141
- package/src/orders.js +134 -0
- package/src/orders.ts +25 -134
- package/src/slot/SlotSubscriber.js +39 -0
- package/src/slot/SlotSubscriber.ts +42 -0
- package/src/token/index.js +38 -0
- package/src/tx/retryTxSender.js +188 -0
- package/src/tx/retryTxSender.ts +6 -4
- package/src/tx/types.js +2 -0
- package/src/tx/types.ts +6 -1
- package/src/tx/utils.js +17 -0
- package/src/tx/utils.ts +22 -3
- package/src/types.js +114 -0
- package/src/types.ts +176 -124
- package/src/userName.js +20 -0
- package/src/userName.ts +20 -0
- package/src/util/promiseTimeout.js +14 -0
- package/src/util/tps.js +27 -0
- package/src/wallet.js +35 -0
- package/tests/bn/test.ts +255 -0
- package/tsconfig.json +12 -12
- package/lib/addresses.d.ts +0 -10
- package/lib/constants/accounts.d.ts +0 -15
- package/lib/constants/accounts.js +0 -18
- package/lib/factory/clearingHouse.d.ts +0 -35
- package/lib/factory/clearingHouse.js +0 -81
- package/lib/factory/clearingHouseUser.d.ts +0 -19
- package/lib/factory/clearingHouseUser.js +0 -34
- package/lib/math/insuranceFund.d.ts +0 -15
- package/lib/math/insuranceFund.js +0 -33
- package/lib/settlement.d.ts +0 -4
- package/lib/settlement.js +0 -10
- package/lib/tx/defaultTxSender.d.ts +0 -8
- package/lib/tx/defaultTxSender.js +0 -12
- package/src/addresses.ts +0 -82
- package/src/constants/accounts.ts +0 -26
- package/src/factory/clearingHouse.ts +0 -173
- package/src/factory/clearingHouseUser.ts +0 -73
- package/src/math/insuranceFund.ts +0 -29
- package/src/settlement.ts +0 -9
- package/src/tx/defaultTxSender.ts +0 -24
package/src/admin.ts
CHANGED
|
@@ -1,58 +1,34 @@
|
|
|
1
1
|
import {
|
|
2
|
-
ConfirmOptions,
|
|
3
|
-
Connection,
|
|
4
2
|
PublicKey,
|
|
5
3
|
SYSVAR_RENT_PUBKEY,
|
|
6
4
|
TransactionSignature,
|
|
7
5
|
} from '@solana/web3.js';
|
|
8
6
|
import {
|
|
9
7
|
FeeStructure,
|
|
10
|
-
IWallet,
|
|
11
8
|
OracleGuardRails,
|
|
12
9
|
OracleSource,
|
|
13
10
|
OrderFillerRewardStructure,
|
|
14
11
|
} from './types';
|
|
15
|
-
import { BN
|
|
12
|
+
import { BN } from '@project-serum/anchor';
|
|
16
13
|
import * as anchor from '@project-serum/anchor';
|
|
17
14
|
import {
|
|
18
|
-
getClearingHouseStateAccountPublicKey,
|
|
19
15
|
getClearingHouseStateAccountPublicKeyAndNonce,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
getBankVaultAuthorityPublicKey,
|
|
17
|
+
getBankPublicKey,
|
|
18
|
+
getBankVaultPublicKey,
|
|
19
|
+
getMarketPublicKey,
|
|
20
|
+
} from './addresses/pda';
|
|
24
21
|
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
25
22
|
import { ClearingHouse } from './clearingHouse';
|
|
26
23
|
import { PEG_PRECISION } from './constants/numericConstants';
|
|
27
24
|
import { calculateTargetPriceTrade } from './math/trade';
|
|
28
25
|
import { calculateAmmReservesAfterSwap, getSwapDirection } from './math/amm';
|
|
29
|
-
import {
|
|
30
|
-
getAdmin,
|
|
31
|
-
getWebSocketClearingHouseConfig,
|
|
32
|
-
} from './factory/clearingHouse';
|
|
33
26
|
|
|
34
27
|
export class Admin extends ClearingHouse {
|
|
35
|
-
public static from(
|
|
36
|
-
connection: Connection,
|
|
37
|
-
wallet: IWallet,
|
|
38
|
-
clearingHouseProgramId: PublicKey,
|
|
39
|
-
opts: ConfirmOptions = AnchorProvider.defaultOptions()
|
|
40
|
-
): Admin {
|
|
41
|
-
const config = getWebSocketClearingHouseConfig(
|
|
42
|
-
connection,
|
|
43
|
-
wallet,
|
|
44
|
-
clearingHouseProgramId,
|
|
45
|
-
opts
|
|
46
|
-
);
|
|
47
|
-
return getAdmin(config);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
28
|
public async initialize(
|
|
51
29
|
usdcMint: PublicKey,
|
|
52
30
|
adminControlsPrices: boolean
|
|
53
|
-
): Promise<
|
|
54
|
-
[TransactionSignature, TransactionSignature, TransactionSignature]
|
|
55
|
-
> {
|
|
31
|
+
): Promise<[TransactionSignature]> {
|
|
56
32
|
const stateAccountRPCResponse = await this.connection.getParsedAccountInfo(
|
|
57
33
|
await this.getStatePublicKey()
|
|
58
34
|
);
|
|
@@ -60,160 +36,109 @@ export class Admin extends ClearingHouse {
|
|
|
60
36
|
throw new Error('Clearing house already initialized');
|
|
61
37
|
}
|
|
62
38
|
|
|
63
|
-
const [
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
const [collateralVaultAuthority, _collateralVaultAuthorityNonce] =
|
|
70
|
-
await PublicKey.findProgramAddress(
|
|
71
|
-
[collateralVaultPublicKey.toBuffer()],
|
|
72
|
-
this.program.programId
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
const [insuranceVaultPublicKey, insuranceVaultNonce] =
|
|
76
|
-
await PublicKey.findProgramAddress(
|
|
77
|
-
[Buffer.from(anchor.utils.bytes.utf8.encode('insurance_vault'))],
|
|
78
|
-
this.program.programId
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
const [insuranceVaultAuthority, _insuranceVaultAuthorityNonce] =
|
|
82
|
-
await PublicKey.findProgramAddress(
|
|
83
|
-
[insuranceVaultPublicKey.toBuffer()],
|
|
84
|
-
this.program.programId
|
|
85
|
-
);
|
|
39
|
+
const [insuranceVaultPublicKey] = await PublicKey.findProgramAddress(
|
|
40
|
+
[Buffer.from(anchor.utils.bytes.utf8.encode('insurance_vault'))],
|
|
41
|
+
this.program.programId
|
|
42
|
+
);
|
|
86
43
|
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const tradeHistory = anchor.web3.Keypair.generate();
|
|
92
|
-
const liquidationHistory = anchor.web3.Keypair.generate();
|
|
93
|
-
const curveHistory = anchor.web3.Keypair.generate();
|
|
44
|
+
const [insuranceVaultAuthority] = await PublicKey.findProgramAddress(
|
|
45
|
+
[insuranceVaultPublicKey.toBuffer()],
|
|
46
|
+
this.program.programId
|
|
47
|
+
);
|
|
94
48
|
|
|
95
|
-
const [clearingHouseStatePublicKey
|
|
49
|
+
const [clearingHouseStatePublicKey] =
|
|
96
50
|
await getClearingHouseStateAccountPublicKeyAndNonce(
|
|
97
51
|
this.program.programId
|
|
98
52
|
);
|
|
99
53
|
const initializeTx = await this.program.transaction.initialize(
|
|
100
|
-
clearingHouseNonce,
|
|
101
|
-
collateralVaultNonce,
|
|
102
|
-
insuranceVaultNonce,
|
|
103
54
|
adminControlsPrices,
|
|
104
55
|
{
|
|
105
56
|
accounts: {
|
|
106
57
|
admin: this.wallet.publicKey,
|
|
107
58
|
state: clearingHouseStatePublicKey,
|
|
108
|
-
|
|
109
|
-
collateralVault: collateralVaultPublicKey,
|
|
110
|
-
collateralVaultAuthority: collateralVaultAuthority,
|
|
59
|
+
quoteAssetMint: usdcMint,
|
|
111
60
|
insuranceVault: insuranceVaultPublicKey,
|
|
112
61
|
insuranceVaultAuthority: insuranceVaultAuthority,
|
|
113
|
-
markets: markets.publicKey,
|
|
114
62
|
rent: SYSVAR_RENT_PUBKEY,
|
|
115
63
|
systemProgram: anchor.web3.SystemProgram.programId,
|
|
116
64
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
117
65
|
},
|
|
118
|
-
instructions: [
|
|
119
|
-
await this.program.account.markets.createInstruction(markets),
|
|
120
|
-
],
|
|
121
66
|
}
|
|
122
67
|
);
|
|
123
68
|
|
|
124
|
-
const initializeTxSig = await this.txSender.send(
|
|
69
|
+
const { txSig: initializeTxSig } = await this.txSender.send(
|
|
125
70
|
initializeTx,
|
|
126
|
-
[
|
|
71
|
+
[],
|
|
127
72
|
this.opts
|
|
128
73
|
);
|
|
129
74
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
accounts: {
|
|
133
|
-
admin: this.wallet.publicKey,
|
|
134
|
-
state: clearingHouseStatePublicKey,
|
|
135
|
-
depositHistory: depositHistory.publicKey,
|
|
136
|
-
fundingRateHistory: fundingRateHistory.publicKey,
|
|
137
|
-
fundingPaymentHistory: fundingPaymentHistory.publicKey,
|
|
138
|
-
tradeHistory: tradeHistory.publicKey,
|
|
139
|
-
liquidationHistory: liquidationHistory.publicKey,
|
|
140
|
-
curveHistory: curveHistory.publicKey,
|
|
141
|
-
rent: SYSVAR_RENT_PUBKEY,
|
|
142
|
-
systemProgram: anchor.web3.SystemProgram.programId,
|
|
143
|
-
},
|
|
144
|
-
instructions: [
|
|
145
|
-
await this.program.account.fundingRateHistory.createInstruction(
|
|
146
|
-
fundingRateHistory
|
|
147
|
-
),
|
|
148
|
-
await this.program.account.fundingPaymentHistory.createInstruction(
|
|
149
|
-
fundingPaymentHistory
|
|
150
|
-
),
|
|
151
|
-
await this.program.account.tradeHistory.createInstruction(
|
|
152
|
-
tradeHistory
|
|
153
|
-
),
|
|
154
|
-
await this.program.account.liquidationHistory.createInstruction(
|
|
155
|
-
liquidationHistory
|
|
156
|
-
),
|
|
157
|
-
await this.program.account.depositHistory.createInstruction(
|
|
158
|
-
depositHistory
|
|
159
|
-
),
|
|
160
|
-
await this.program.account.extendedCurveHistory.createInstruction(
|
|
161
|
-
curveHistory
|
|
162
|
-
),
|
|
163
|
-
],
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
const initializeHistoryTxSig = await this.txSender.send(
|
|
167
|
-
initializeHistoryTx,
|
|
168
|
-
[
|
|
169
|
-
depositHistory,
|
|
170
|
-
fundingPaymentHistory,
|
|
171
|
-
tradeHistory,
|
|
172
|
-
liquidationHistory,
|
|
173
|
-
fundingRateHistory,
|
|
174
|
-
curveHistory,
|
|
175
|
-
],
|
|
176
|
-
this.opts
|
|
177
|
-
);
|
|
75
|
+
return [initializeTxSig];
|
|
76
|
+
}
|
|
178
77
|
|
|
179
|
-
|
|
78
|
+
public async initializeBank(
|
|
79
|
+
mint: PublicKey,
|
|
80
|
+
optimalUtilization: BN,
|
|
81
|
+
optimalRate: BN,
|
|
82
|
+
maxRate: BN,
|
|
83
|
+
oracle: PublicKey,
|
|
84
|
+
oracleSource: OracleSource,
|
|
85
|
+
initialAssetWeight: BN,
|
|
86
|
+
maintenanceAssetWeight: BN,
|
|
87
|
+
initialLiabilityWeight: BN,
|
|
88
|
+
maintenanceLiabilityWeight: BN,
|
|
89
|
+
imfFactor = new BN(0)
|
|
90
|
+
): Promise<TransactionSignature> {
|
|
91
|
+
const bankIndex = this.getStateAccount().numberOfBanks;
|
|
92
|
+
const bank = await getBankPublicKey(this.program.programId, bankIndex);
|
|
180
93
|
|
|
181
|
-
|
|
182
|
-
|
|
94
|
+
const bankVault = await getBankVaultPublicKey(
|
|
95
|
+
this.program.programId,
|
|
96
|
+
bankIndex
|
|
97
|
+
);
|
|
183
98
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const clearingHouseStatePublicKey =
|
|
189
|
-
await getClearingHouseStateAccountPublicKey(this.program.programId);
|
|
99
|
+
const bankVaultAuthority = await getBankVaultAuthorityPublicKey(
|
|
100
|
+
this.program.programId,
|
|
101
|
+
bankIndex
|
|
102
|
+
);
|
|
190
103
|
|
|
191
|
-
const
|
|
192
|
-
|
|
104
|
+
const initializeTx = await this.program.transaction.initializeBank(
|
|
105
|
+
optimalUtilization,
|
|
106
|
+
optimalRate,
|
|
107
|
+
maxRate,
|
|
108
|
+
oracleSource,
|
|
109
|
+
initialAssetWeight,
|
|
110
|
+
maintenanceAssetWeight,
|
|
111
|
+
initialLiabilityWeight,
|
|
112
|
+
maintenanceLiabilityWeight,
|
|
113
|
+
imfFactor,
|
|
114
|
+
{
|
|
193
115
|
accounts: {
|
|
194
116
|
admin: this.wallet.publicKey,
|
|
195
|
-
state:
|
|
196
|
-
|
|
197
|
-
|
|
117
|
+
state: await this.getStatePublicKey(),
|
|
118
|
+
bank,
|
|
119
|
+
bankVault,
|
|
120
|
+
bankVaultAuthority,
|
|
121
|
+
bankMint: mint,
|
|
122
|
+
oracle,
|
|
198
123
|
rent: SYSVAR_RENT_PUBKEY,
|
|
199
124
|
systemProgram: anchor.web3.SystemProgram.programId,
|
|
125
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
200
126
|
},
|
|
201
|
-
|
|
202
|
-
await this.program.account.orderHistory.createInstruction(
|
|
203
|
-
orderHistory
|
|
204
|
-
),
|
|
205
|
-
],
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
return await this.txSender.send(
|
|
209
|
-
initializeOrderStateTx,
|
|
210
|
-
[orderHistory],
|
|
211
|
-
this.opts
|
|
127
|
+
}
|
|
212
128
|
);
|
|
129
|
+
|
|
130
|
+
const { txSig } = await this.txSender.send(initializeTx, [], this.opts);
|
|
131
|
+
|
|
132
|
+
await this.accountSubscriber.addBank(bankIndex);
|
|
133
|
+
await this.accountSubscriber.addOracle({
|
|
134
|
+
source: oracleSource,
|
|
135
|
+
publicKey: oracle,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
return txSig;
|
|
213
139
|
}
|
|
214
140
|
|
|
215
141
|
public async initializeMarket(
|
|
216
|
-
marketIndex: BN,
|
|
217
142
|
priceOracle: PublicKey,
|
|
218
143
|
baseAssetReserve: BN,
|
|
219
144
|
quoteAssetReserve: BN,
|
|
@@ -224,12 +149,12 @@ export class Admin extends ClearingHouse {
|
|
|
224
149
|
marginRatioPartial = 625,
|
|
225
150
|
marginRatioMaintenance = 500
|
|
226
151
|
): Promise<TransactionSignature> {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
152
|
+
const marketPublicKey = await getMarketPublicKey(
|
|
153
|
+
this.program.programId,
|
|
154
|
+
this.getStateAccount().numberOfMarkets
|
|
155
|
+
);
|
|
230
156
|
|
|
231
157
|
const initializeMarketTx = await this.program.transaction.initializeMarket(
|
|
232
|
-
marketIndex,
|
|
233
158
|
baseAssetReserve,
|
|
234
159
|
quoteAssetReserve,
|
|
235
160
|
periodicity,
|
|
@@ -243,11 +168,27 @@ export class Admin extends ClearingHouse {
|
|
|
243
168
|
state: await this.getStatePublicKey(),
|
|
244
169
|
admin: this.wallet.publicKey,
|
|
245
170
|
oracle: priceOracle,
|
|
246
|
-
|
|
171
|
+
market: marketPublicKey,
|
|
172
|
+
rent: SYSVAR_RENT_PUBKEY,
|
|
173
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
247
174
|
},
|
|
248
175
|
}
|
|
249
176
|
);
|
|
250
|
-
|
|
177
|
+
const { txSig } = await this.txSender.send(
|
|
178
|
+
initializeMarketTx,
|
|
179
|
+
[],
|
|
180
|
+
this.opts
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
await this.accountSubscriber.addMarket(
|
|
184
|
+
this.getStateAccount().numberOfMarkets
|
|
185
|
+
);
|
|
186
|
+
await this.accountSubscriber.addOracle({
|
|
187
|
+
source: oracleSource,
|
|
188
|
+
publicKey: priceOracle,
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
return txSig;
|
|
251
192
|
}
|
|
252
193
|
|
|
253
194
|
public async moveAmmPrice(
|
|
@@ -255,16 +196,19 @@ export class Admin extends ClearingHouse {
|
|
|
255
196
|
quoteAssetReserve: BN,
|
|
256
197
|
marketIndex: BN
|
|
257
198
|
): Promise<TransactionSignature> {
|
|
258
|
-
const
|
|
199
|
+
const marketPublicKey = await getMarketPublicKey(
|
|
200
|
+
this.program.programId,
|
|
201
|
+
marketIndex
|
|
202
|
+
);
|
|
203
|
+
|
|
259
204
|
return await this.program.rpc.moveAmmPrice(
|
|
260
205
|
baseAssetReserve,
|
|
261
206
|
quoteAssetReserve,
|
|
262
|
-
marketIndex,
|
|
263
207
|
{
|
|
264
208
|
accounts: {
|
|
265
209
|
state: await this.getStatePublicKey(),
|
|
266
210
|
admin: this.wallet.publicKey,
|
|
267
|
-
|
|
211
|
+
market: marketPublicKey,
|
|
268
212
|
},
|
|
269
213
|
}
|
|
270
214
|
);
|
|
@@ -274,51 +218,28 @@ export class Admin extends ClearingHouse {
|
|
|
274
218
|
sqrtK: BN,
|
|
275
219
|
marketIndex: BN
|
|
276
220
|
): Promise<TransactionSignature> {
|
|
277
|
-
|
|
278
|
-
const markets = this.getMarketsAccount();
|
|
279
|
-
const marketData = markets.markets[marketIndex.toNumber()];
|
|
280
|
-
const ammData = marketData.amm;
|
|
281
|
-
|
|
282
|
-
return await this.program.rpc.updateK(sqrtK, marketIndex, {
|
|
221
|
+
return await this.program.rpc.updateK(sqrtK, {
|
|
283
222
|
accounts: {
|
|
284
223
|
state: await this.getStatePublicKey(),
|
|
285
224
|
admin: this.wallet.publicKey,
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
oracle: ammData.oracle,
|
|
225
|
+
market: await getMarketPublicKey(this.program.programId, marketIndex),
|
|
226
|
+
oracle: this.getMarketAccount(marketIndex).amm.oracle,
|
|
289
227
|
},
|
|
290
228
|
});
|
|
291
229
|
}
|
|
292
230
|
|
|
293
|
-
public async updateCurveHistory(): Promise<TransactionSignature> {
|
|
294
|
-
const extendedCurveHistory = anchor.web3.Keypair.generate();
|
|
295
|
-
|
|
296
|
-
const state = this.getStateAccount();
|
|
297
|
-
return await this.program.rpc.updateCurveHistory({
|
|
298
|
-
accounts: {
|
|
299
|
-
state: await this.getStatePublicKey(),
|
|
300
|
-
admin: this.wallet.publicKey,
|
|
301
|
-
curveHistory: state.curveHistory,
|
|
302
|
-
extendedCurveHistory: extendedCurveHistory.publicKey,
|
|
303
|
-
},
|
|
304
|
-
instructions: [
|
|
305
|
-
await this.program.account.extendedCurveHistory.createInstruction(
|
|
306
|
-
extendedCurveHistory
|
|
307
|
-
),
|
|
308
|
-
],
|
|
309
|
-
signers: [extendedCurveHistory],
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
|
|
313
231
|
public async moveAmmToPrice(
|
|
314
232
|
marketIndex: BN,
|
|
315
233
|
targetPrice: BN
|
|
316
234
|
): Promise<TransactionSignature> {
|
|
317
|
-
const market = this.
|
|
235
|
+
const market = this.getMarketAccount(marketIndex);
|
|
318
236
|
|
|
319
237
|
const [direction, tradeSize, _] = calculateTargetPriceTrade(
|
|
320
238
|
market,
|
|
321
|
-
targetPrice
|
|
239
|
+
targetPrice,
|
|
240
|
+
new BN(1000),
|
|
241
|
+
'quote',
|
|
242
|
+
undefined //todo
|
|
322
243
|
);
|
|
323
244
|
|
|
324
245
|
const [newQuoteAssetAmount, newBaseAssetAmount] =
|
|
@@ -329,16 +250,19 @@ export class Admin extends ClearingHouse {
|
|
|
329
250
|
getSwapDirection('quote', direction)
|
|
330
251
|
);
|
|
331
252
|
|
|
332
|
-
const
|
|
253
|
+
const marketPublicKey = await getMarketPublicKey(
|
|
254
|
+
this.program.programId,
|
|
255
|
+
marketIndex
|
|
256
|
+
);
|
|
257
|
+
|
|
333
258
|
return await this.program.rpc.moveAmmPrice(
|
|
334
259
|
newBaseAssetAmount,
|
|
335
260
|
newQuoteAssetAmount,
|
|
336
|
-
marketIndex,
|
|
337
261
|
{
|
|
338
262
|
accounts: {
|
|
339
263
|
state: await this.getStatePublicKey(),
|
|
340
264
|
admin: this.wallet.publicKey,
|
|
341
|
-
|
|
265
|
+
market: marketPublicKey,
|
|
342
266
|
},
|
|
343
267
|
}
|
|
344
268
|
);
|
|
@@ -348,18 +272,18 @@ export class Admin extends ClearingHouse {
|
|
|
348
272
|
newPeg: BN,
|
|
349
273
|
marketIndex: BN
|
|
350
274
|
): Promise<TransactionSignature> {
|
|
351
|
-
const
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
275
|
+
const marketPublicKey = await getMarketPublicKey(
|
|
276
|
+
this.program.programId,
|
|
277
|
+
marketIndex
|
|
278
|
+
);
|
|
279
|
+
const ammData = this.getMarketAccount(marketIndex).amm;
|
|
355
280
|
|
|
356
|
-
return await this.program.rpc.repegAmmCurve(newPeg,
|
|
281
|
+
return await this.program.rpc.repegAmmCurve(newPeg, {
|
|
357
282
|
accounts: {
|
|
358
283
|
state: await this.getStatePublicKey(),
|
|
359
284
|
admin: this.wallet.publicKey,
|
|
360
285
|
oracle: ammData.oracle,
|
|
361
|
-
|
|
362
|
-
curveHistory: state.extendedCurveHistory,
|
|
286
|
+
market: marketPublicKey,
|
|
363
287
|
},
|
|
364
288
|
});
|
|
365
289
|
}
|
|
@@ -367,18 +291,18 @@ export class Admin extends ClearingHouse {
|
|
|
367
291
|
public async updateAmmOracleTwap(
|
|
368
292
|
marketIndex: BN
|
|
369
293
|
): Promise<TransactionSignature> {
|
|
370
|
-
const
|
|
371
|
-
const
|
|
372
|
-
|
|
373
|
-
|
|
294
|
+
const ammData = this.getMarketAccount(marketIndex).amm;
|
|
295
|
+
const marketPublicKey = await getMarketPublicKey(
|
|
296
|
+
this.program.programId,
|
|
297
|
+
marketIndex
|
|
298
|
+
);
|
|
374
299
|
|
|
375
|
-
return await this.program.rpc.updateAmmOracleTwap(
|
|
300
|
+
return await this.program.rpc.updateAmmOracleTwap({
|
|
376
301
|
accounts: {
|
|
377
302
|
state: await this.getStatePublicKey(),
|
|
378
303
|
admin: this.wallet.publicKey,
|
|
379
304
|
oracle: ammData.oracle,
|
|
380
|
-
|
|
381
|
-
curveHistory: state.extendedCurveHistory,
|
|
305
|
+
market: marketPublicKey,
|
|
382
306
|
},
|
|
383
307
|
});
|
|
384
308
|
}
|
|
@@ -386,18 +310,18 @@ export class Admin extends ClearingHouse {
|
|
|
386
310
|
public async resetAmmOracleTwap(
|
|
387
311
|
marketIndex: BN
|
|
388
312
|
): Promise<TransactionSignature> {
|
|
389
|
-
const
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
|
|
313
|
+
const ammData = this.getMarketAccount(marketIndex).amm;
|
|
314
|
+
const marketPublicKey = await getMarketPublicKey(
|
|
315
|
+
this.program.programId,
|
|
316
|
+
marketIndex
|
|
317
|
+
);
|
|
393
318
|
|
|
394
|
-
return await this.program.rpc.resetAmmOracleTwap(
|
|
319
|
+
return await this.program.rpc.resetAmmOracleTwap({
|
|
395
320
|
accounts: {
|
|
396
321
|
state: await this.getStatePublicKey(),
|
|
397
322
|
admin: this.wallet.publicKey,
|
|
398
323
|
oracle: ammData.oracle,
|
|
399
|
-
|
|
400
|
-
curveHistory: state.extendedCurveHistory,
|
|
324
|
+
market: marketPublicKey,
|
|
401
325
|
},
|
|
402
326
|
});
|
|
403
327
|
}
|
|
@@ -407,10 +331,12 @@ export class Admin extends ClearingHouse {
|
|
|
407
331
|
recipient: PublicKey
|
|
408
332
|
): Promise<TransactionSignature> {
|
|
409
333
|
const state = await this.getStateAccount();
|
|
334
|
+
const bank = this.getQuoteAssetBankAccount();
|
|
410
335
|
return await this.program.rpc.withdrawFromInsuranceVault(amount, {
|
|
411
336
|
accounts: {
|
|
412
337
|
admin: this.wallet.publicKey,
|
|
413
338
|
state: await this.getStatePublicKey(),
|
|
339
|
+
bank: bank.pubkey,
|
|
414
340
|
insuranceVault: state.insuranceVault,
|
|
415
341
|
insuranceVaultAuthority: state.insuranceVaultAuthority,
|
|
416
342
|
recipient: recipient,
|
|
@@ -419,19 +345,24 @@ export class Admin extends ClearingHouse {
|
|
|
419
345
|
});
|
|
420
346
|
}
|
|
421
347
|
|
|
422
|
-
public async
|
|
348
|
+
public async withdrawFromMarketToInsuranceVault(
|
|
423
349
|
marketIndex: BN,
|
|
424
350
|
amount: BN,
|
|
425
351
|
recipient: PublicKey
|
|
426
352
|
): Promise<TransactionSignature> {
|
|
427
|
-
const
|
|
428
|
-
|
|
353
|
+
const marketPublicKey = await getMarketPublicKey(
|
|
354
|
+
this.program.programId,
|
|
355
|
+
marketIndex
|
|
356
|
+
);
|
|
357
|
+
const bank = this.getQuoteAssetBankAccount();
|
|
358
|
+
return await this.program.rpc.withdrawFromMarketToInsuranceVault(amount, {
|
|
429
359
|
accounts: {
|
|
430
360
|
admin: this.wallet.publicKey,
|
|
431
361
|
state: await this.getStatePublicKey(),
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
362
|
+
market: marketPublicKey,
|
|
363
|
+
bank: bank.pubkey,
|
|
364
|
+
bankVault: bank.vault,
|
|
365
|
+
bankVaultAuthority: bank.vaultAuthority,
|
|
435
366
|
recipient: recipient,
|
|
436
367
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
437
368
|
},
|
|
@@ -443,21 +374,21 @@ export class Admin extends ClearingHouse {
|
|
|
443
374
|
amount: BN
|
|
444
375
|
): Promise<TransactionSignature> {
|
|
445
376
|
const state = await this.getStateAccount();
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
{
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
}
|
|
460
|
-
);
|
|
377
|
+
const bank = this.getQuoteAssetBankAccount();
|
|
378
|
+
|
|
379
|
+
return await this.program.rpc.withdrawFromInsuranceVaultToMarket(amount, {
|
|
380
|
+
accounts: {
|
|
381
|
+
admin: this.wallet.publicKey,
|
|
382
|
+
state: await this.getStatePublicKey(),
|
|
383
|
+
market: await getMarketPublicKey(this.program.programId, marketIndex),
|
|
384
|
+
insuranceVault: state.insuranceVault,
|
|
385
|
+
insuranceVaultAuthority: state.insuranceVaultAuthority,
|
|
386
|
+
bank: bank.pubkey,
|
|
387
|
+
bankVault: bank.vault,
|
|
388
|
+
bankVaultAuthority: bank.vaultAuthority,
|
|
389
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
|
390
|
+
},
|
|
391
|
+
});
|
|
461
392
|
}
|
|
462
393
|
|
|
463
394
|
public async updateAdmin(admin: PublicKey): Promise<TransactionSignature> {
|
|
@@ -469,6 +400,25 @@ export class Admin extends ClearingHouse {
|
|
|
469
400
|
});
|
|
470
401
|
}
|
|
471
402
|
|
|
403
|
+
public async updateCurveUpdateIntensity(
|
|
404
|
+
marketIndex: BN,
|
|
405
|
+
curveUpdateIntensity: number
|
|
406
|
+
): Promise<TransactionSignature> {
|
|
407
|
+
// assert(curveUpdateIntensity >= 0 && curveUpdateIntensity <= 100);
|
|
408
|
+
// assert(Number.isInteger(curveUpdateIntensity));
|
|
409
|
+
|
|
410
|
+
return await this.program.rpc.updateCurveUpdateIntensity(
|
|
411
|
+
curveUpdateIntensity,
|
|
412
|
+
{
|
|
413
|
+
accounts: {
|
|
414
|
+
admin: this.wallet.publicKey,
|
|
415
|
+
state: await this.getStatePublicKey(),
|
|
416
|
+
market: await getMarketPublicKey(this.program.programId, marketIndex),
|
|
417
|
+
},
|
|
418
|
+
}
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
|
|
472
422
|
public async updateMarginRatio(
|
|
473
423
|
marketIndex: BN,
|
|
474
424
|
marginRatioInitial: number,
|
|
@@ -476,7 +426,6 @@ export class Admin extends ClearingHouse {
|
|
|
476
426
|
marginRatioMaintenance: number
|
|
477
427
|
): Promise<TransactionSignature> {
|
|
478
428
|
return await this.program.rpc.updateMarginRatio(
|
|
479
|
-
marketIndex,
|
|
480
429
|
marginRatioInitial,
|
|
481
430
|
marginRatioPartial,
|
|
482
431
|
marginRatioMaintenance,
|
|
@@ -484,7 +433,7 @@ export class Admin extends ClearingHouse {
|
|
|
484
433
|
accounts: {
|
|
485
434
|
admin: this.wallet.publicKey,
|
|
486
435
|
state: await this.getStatePublicKey(),
|
|
487
|
-
|
|
436
|
+
market: await getMarketPublicKey(this.program.programId, marketIndex),
|
|
488
437
|
},
|
|
489
438
|
}
|
|
490
439
|
);
|
|
@@ -494,17 +443,26 @@ export class Admin extends ClearingHouse {
|
|
|
494
443
|
marketIndex: BN,
|
|
495
444
|
baseSpread: number
|
|
496
445
|
): Promise<TransactionSignature> {
|
|
497
|
-
return await this.program.rpc.updateMarketBaseSpread(
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
446
|
+
return await this.program.rpc.updateMarketBaseSpread(baseSpread, {
|
|
447
|
+
accounts: {
|
|
448
|
+
admin: this.wallet.publicKey,
|
|
449
|
+
state: await this.getStatePublicKey(),
|
|
450
|
+
market: await getMarketPublicKey(this.program.programId, marketIndex),
|
|
451
|
+
},
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
public async updateMarketMaxSpread(
|
|
456
|
+
marketIndex: BN,
|
|
457
|
+
maxSpread: number
|
|
458
|
+
): Promise<TransactionSignature> {
|
|
459
|
+
return await this.program.rpc.updateMarketMaxSpread(maxSpread, {
|
|
460
|
+
accounts: {
|
|
461
|
+
admin: this.wallet.publicKey,
|
|
462
|
+
state: await this.getStatePublicKey(),
|
|
463
|
+
market: await getMarketPublicKey(this.program.programId, marketIndex),
|
|
464
|
+
},
|
|
465
|
+
});
|
|
508
466
|
}
|
|
509
467
|
|
|
510
468
|
public async updatePartialLiquidationClosePercentage(
|
|
@@ -592,7 +550,6 @@ export class Admin extends ClearingHouse {
|
|
|
592
550
|
accounts: {
|
|
593
551
|
admin: this.wallet.publicKey,
|
|
594
552
|
state: await this.getStatePublicKey(),
|
|
595
|
-
orderState: await this.getOrderStatePublicKey(),
|
|
596
553
|
},
|
|
597
554
|
}
|
|
598
555
|
);
|
|
@@ -623,52 +580,42 @@ export class Admin extends ClearingHouse {
|
|
|
623
580
|
oracle: PublicKey,
|
|
624
581
|
oracleSource: OracleSource
|
|
625
582
|
): Promise<TransactionSignature> {
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
admin: this.wallet.publicKey,
|
|
634
|
-
state: await this.getStatePublicKey(),
|
|
635
|
-
markets: state.markets,
|
|
636
|
-
},
|
|
637
|
-
}
|
|
638
|
-
);
|
|
583
|
+
return await this.program.rpc.updateMarketOracle(oracle, oracleSource, {
|
|
584
|
+
accounts: {
|
|
585
|
+
admin: this.wallet.publicKey,
|
|
586
|
+
state: await this.getStatePublicKey(),
|
|
587
|
+
market: await getMarketPublicKey(this.program.programId, marketIndex),
|
|
588
|
+
},
|
|
589
|
+
});
|
|
639
590
|
}
|
|
640
591
|
|
|
641
592
|
public async updateMarketMinimumQuoteAssetTradeSize(
|
|
642
593
|
marketIndex: BN,
|
|
643
594
|
minimumTradeSize: BN
|
|
644
595
|
): Promise<TransactionSignature> {
|
|
645
|
-
const state = this.getStateAccount();
|
|
646
596
|
return await this.program.rpc.updateMarketMinimumQuoteAssetTradeSize(
|
|
647
|
-
marketIndex,
|
|
648
597
|
minimumTradeSize,
|
|
649
598
|
{
|
|
650
599
|
accounts: {
|
|
651
600
|
admin: this.wallet.publicKey,
|
|
652
601
|
state: await this.getStatePublicKey(),
|
|
653
|
-
|
|
602
|
+
market: await getMarketPublicKey(this.program.programId, marketIndex),
|
|
654
603
|
},
|
|
655
604
|
}
|
|
656
605
|
);
|
|
657
606
|
}
|
|
658
607
|
|
|
659
|
-
public async
|
|
608
|
+
public async updateMarketBaseAssetAmountStepSize(
|
|
660
609
|
marketIndex: BN,
|
|
661
|
-
|
|
610
|
+
stepSize: BN
|
|
662
611
|
): Promise<TransactionSignature> {
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
marketIndex,
|
|
666
|
-
minimumTradeSize,
|
|
612
|
+
return await this.program.rpc.updateMarketBaseAssetAmountStepSize(
|
|
613
|
+
stepSize,
|
|
667
614
|
{
|
|
668
615
|
accounts: {
|
|
669
616
|
admin: this.wallet.publicKey,
|
|
670
617
|
state: await this.getStatePublicKey(),
|
|
671
|
-
|
|
618
|
+
market: await getMarketPublicKey(this.program.programId, marketIndex),
|
|
672
619
|
},
|
|
673
620
|
}
|
|
674
621
|
);
|
|
@@ -736,83 +683,47 @@ export class Admin extends ClearingHouse {
|
|
|
736
683
|
});
|
|
737
684
|
}
|
|
738
685
|
|
|
739
|
-
public async
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
accounts: {
|
|
743
|
-
admin: this.wallet.publicKey,
|
|
744
|
-
state: await this.getStatePublicKey(),
|
|
745
|
-
insuranceVault: state.insuranceVault,
|
|
746
|
-
insuranceVaultAuthority: state.insuranceVaultAuthority,
|
|
747
|
-
collateralVault: state.collateralVault,
|
|
748
|
-
tokenProgram: TOKEN_PROGRAM_ID,
|
|
749
|
-
},
|
|
750
|
-
});
|
|
751
|
-
}
|
|
752
|
-
|
|
753
|
-
public async adminUpdateUserForgoSettlement(
|
|
754
|
-
authority: PublicKey
|
|
686
|
+
public async updateAuctionDuration(
|
|
687
|
+
minDuration: BN | number,
|
|
688
|
+
maxDuration: BN | number
|
|
755
689
|
): Promise<TransactionSignature> {
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
user: user,
|
|
766
|
-
},
|
|
767
|
-
});
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
public async initializeSettlementState(): Promise<TransactionSignature> {
|
|
771
|
-
const settlementState = await getSettlementStatePublicKey(
|
|
772
|
-
this.program.programId
|
|
690
|
+
return await this.program.rpc.updateAuctionDuration(
|
|
691
|
+
typeof minDuration === 'number' ? minDuration : minDuration.toNumber(),
|
|
692
|
+
typeof maxDuration === 'number' ? maxDuration : maxDuration.toNumber(),
|
|
693
|
+
{
|
|
694
|
+
accounts: {
|
|
695
|
+
admin: this.wallet.publicKey,
|
|
696
|
+
state: await this.getStatePublicKey(),
|
|
697
|
+
},
|
|
698
|
+
}
|
|
773
699
|
);
|
|
774
|
-
|
|
775
|
-
const settlementSize = await this.getTotalSettlementSize();
|
|
776
|
-
|
|
777
|
-
return await this.program.rpc.initializeSettlementState(settlementSize, {
|
|
778
|
-
accounts: {
|
|
779
|
-
admin: this.wallet.publicKey,
|
|
780
|
-
state: await this.getStatePublicKey(),
|
|
781
|
-
settlementState: settlementState,
|
|
782
|
-
rent: SYSVAR_RENT_PUBKEY,
|
|
783
|
-
systemProgram: anchor.web3.SystemProgram.programId,
|
|
784
|
-
collateralVault: (await this.getStateAccount()).collateralVault,
|
|
785
|
-
},
|
|
786
|
-
});
|
|
787
700
|
}
|
|
788
701
|
|
|
789
|
-
public async
|
|
790
|
-
|
|
791
|
-
|
|
702
|
+
public async updateMaxBaseAssetAmountRatio(
|
|
703
|
+
marketIndex: BN,
|
|
704
|
+
maxBaseAssetAmountRatio: number
|
|
705
|
+
): Promise<TransactionSignature> {
|
|
706
|
+
return await this.program.rpc.updateMaxBaseAssetAmountRatio(
|
|
707
|
+
maxBaseAssetAmountRatio,
|
|
708
|
+
{
|
|
709
|
+
accounts: {
|
|
710
|
+
admin: this.wallet.publicKey,
|
|
711
|
+
state: await this.getStatePublicKey(),
|
|
712
|
+
market: this.getMarketAccount(marketIndex).pubkey,
|
|
713
|
+
},
|
|
714
|
+
}
|
|
792
715
|
);
|
|
793
|
-
|
|
794
|
-
return await this.program.rpc.updateSettlementState({
|
|
795
|
-
accounts: {
|
|
796
|
-
admin: this.wallet.publicKey,
|
|
797
|
-
state: await this.getStatePublicKey(),
|
|
798
|
-
settlementState: settlementState,
|
|
799
|
-
collateralVault: (await this.getStateAccount()).collateralVault,
|
|
800
|
-
},
|
|
801
|
-
});
|
|
802
716
|
}
|
|
803
717
|
|
|
804
|
-
public async
|
|
805
|
-
|
|
718
|
+
public async updateMaxSlippageRatio(
|
|
719
|
+
marketIndex: BN,
|
|
720
|
+
maxSlippageRatio: number
|
|
806
721
|
): Promise<TransactionSignature> {
|
|
807
|
-
|
|
808
|
-
this.program.programId
|
|
809
|
-
);
|
|
810
|
-
|
|
811
|
-
return await this.program.rpc.updateSettlementStateEnabled(enabled, {
|
|
722
|
+
return await this.program.rpc.updateMaxSlippageRatio(maxSlippageRatio, {
|
|
812
723
|
accounts: {
|
|
813
724
|
admin: this.wallet.publicKey,
|
|
814
725
|
state: await this.getStatePublicKey(),
|
|
815
|
-
|
|
726
|
+
market: this.getMarketAccount(marketIndex).pubkey,
|
|
816
727
|
},
|
|
817
728
|
});
|
|
818
729
|
}
|