@drift-labs/sdk 2.110.0-beta.23 → 2.110.0-beta.25
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/VERSION +1 -1
- package/lib/browser/adminClient.d.ts +4 -4
- package/lib/browser/adminClient.js +10 -8
- package/lib/browser/idl/drift.json +21 -3
- package/lib/browser/math/spotBalance.js +7 -1
- package/lib/node/adminClient.d.ts +4 -4
- package/lib/node/adminClient.js +10 -8
- package/lib/node/idl/drift.json +21 -3
- package/lib/node/math/spotBalance.js +7 -1
- package/package.json +1 -1
- package/src/adminClient.ts +16 -6
- package/src/idl/drift.json +21 -3
- package/src/math/spotBalance.ts +25 -10
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.110.0-beta.
|
|
1
|
+
2.110.0-beta.25
|
|
@@ -107,8 +107,8 @@ export declare class AdminClient extends DriftClient {
|
|
|
107
107
|
getUpdateInsuranceFundUnstakingPeriodIx(spotMarketIndex: number, insuranceWithdrawEscrowPeriod: BN): Promise<TransactionInstruction>;
|
|
108
108
|
updateLpCooldownTime(cooldownTime: BN): Promise<TransactionSignature>;
|
|
109
109
|
getUpdateLpCooldownTimeIx(cooldownTime: BN): Promise<TransactionInstruction>;
|
|
110
|
-
updatePerpMarketOracle(perpMarketIndex: number, oracle: PublicKey, oracleSource: OracleSource): Promise<TransactionSignature>;
|
|
111
|
-
getUpdatePerpMarketOracleIx(perpMarketIndex: number, oracle: PublicKey, oracleSource: OracleSource): Promise<TransactionInstruction>;
|
|
110
|
+
updatePerpMarketOracle(perpMarketIndex: number, oracle: PublicKey, oracleSource: OracleSource, skipInvaraintCheck?: boolean): Promise<TransactionSignature>;
|
|
111
|
+
getUpdatePerpMarketOracleIx(perpMarketIndex: number, oracle: PublicKey, oracleSource: OracleSource, skipInvaraintCheck?: boolean): Promise<TransactionInstruction>;
|
|
112
112
|
updatePerpMarketStepSizeAndTickSize(perpMarketIndex: number, stepSize: BN, tickSize: BN): Promise<TransactionSignature>;
|
|
113
113
|
getUpdatePerpMarketStepSizeAndTickSizeIx(perpMarketIndex: number, stepSize: BN, tickSize: BN): Promise<TransactionInstruction>;
|
|
114
114
|
updatePerpMarketMinOrderSize(perpMarketIndex: number, orderSize: BN): Promise<TransactionSignature>;
|
|
@@ -119,8 +119,8 @@ export declare class AdminClient extends DriftClient {
|
|
|
119
119
|
getUpdateSpotMarketMinOrderSizeIx(spotMarketIndex: number, orderSize: BN): Promise<TransactionInstruction>;
|
|
120
120
|
updatePerpMarketExpiry(perpMarketIndex: number, expiryTs: BN): Promise<TransactionSignature>;
|
|
121
121
|
getUpdatePerpMarketExpiryIx(perpMarketIndex: number, expiryTs: BN): Promise<TransactionInstruction>;
|
|
122
|
-
updateSpotMarketOracle(spotMarketIndex: number, oracle: PublicKey, oracleSource: OracleSource): Promise<TransactionSignature>;
|
|
123
|
-
getUpdateSpotMarketOracleIx(spotMarketIndex: number, oracle: PublicKey, oracleSource: OracleSource): Promise<TransactionInstruction>;
|
|
122
|
+
updateSpotMarketOracle(spotMarketIndex: number, oracle: PublicKey, oracleSource: OracleSource, skipInvaraintCheck?: boolean): Promise<TransactionSignature>;
|
|
123
|
+
getUpdateSpotMarketOracleIx(spotMarketIndex: number, oracle: PublicKey, oracleSource: OracleSource, skipInvaraintCheck?: boolean): Promise<TransactionInstruction>;
|
|
124
124
|
updateSpotMarketOrdersEnabled(spotMarketIndex: number, ordersEnabled: boolean): Promise<TransactionSignature>;
|
|
125
125
|
getUpdateSpotMarketOrdersEnabledIx(spotMarketIndex: number, ordersEnabled: boolean): Promise<TransactionInstruction>;
|
|
126
126
|
updateSpotMarketIfPausedOperations(spotMarketIndex: number, pausedOperations: number): Promise<TransactionSignature>;
|
|
@@ -1002,14 +1002,14 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
1002
1002
|
},
|
|
1003
1003
|
});
|
|
1004
1004
|
}
|
|
1005
|
-
async updatePerpMarketOracle(perpMarketIndex, oracle, oracleSource) {
|
|
1006
|
-
const updatePerpMarketOracleIx = await this.getUpdatePerpMarketOracleIx(perpMarketIndex, oracle, oracleSource);
|
|
1005
|
+
async updatePerpMarketOracle(perpMarketIndex, oracle, oracleSource, skipInvaraintCheck = false) {
|
|
1006
|
+
const updatePerpMarketOracleIx = await this.getUpdatePerpMarketOracleIx(perpMarketIndex, oracle, oracleSource, skipInvaraintCheck);
|
|
1007
1007
|
const tx = await this.buildTransaction(updatePerpMarketOracleIx);
|
|
1008
1008
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
1009
1009
|
return txSig;
|
|
1010
1010
|
}
|
|
1011
|
-
async getUpdatePerpMarketOracleIx(perpMarketIndex, oracle, oracleSource) {
|
|
1012
|
-
return await this.program.instruction.updatePerpMarketOracle(oracle, oracleSource, {
|
|
1011
|
+
async getUpdatePerpMarketOracleIx(perpMarketIndex, oracle, oracleSource, skipInvaraintCheck = false) {
|
|
1012
|
+
return await this.program.instruction.updatePerpMarketOracle(oracle, oracleSource, skipInvaraintCheck, {
|
|
1013
1013
|
accounts: {
|
|
1014
1014
|
admin: this.isSubscribed
|
|
1015
1015
|
? this.getStateAccount().admin
|
|
@@ -1017,6 +1017,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
1017
1017
|
state: await this.getStatePublicKey(),
|
|
1018
1018
|
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
1019
1019
|
oracle: oracle,
|
|
1020
|
+
oldOracle: this.getPerpMarketAccount(perpMarketIndex).amm.oracle,
|
|
1020
1021
|
},
|
|
1021
1022
|
});
|
|
1022
1023
|
}
|
|
@@ -1113,14 +1114,14 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
1113
1114
|
},
|
|
1114
1115
|
});
|
|
1115
1116
|
}
|
|
1116
|
-
async updateSpotMarketOracle(spotMarketIndex, oracle, oracleSource) {
|
|
1117
|
-
const updateSpotMarketOracleIx = await this.getUpdateSpotMarketOracleIx(spotMarketIndex, oracle, oracleSource);
|
|
1117
|
+
async updateSpotMarketOracle(spotMarketIndex, oracle, oracleSource, skipInvaraintCheck = false) {
|
|
1118
|
+
const updateSpotMarketOracleIx = await this.getUpdateSpotMarketOracleIx(spotMarketIndex, oracle, oracleSource, skipInvaraintCheck);
|
|
1118
1119
|
const tx = await this.buildTransaction(updateSpotMarketOracleIx);
|
|
1119
1120
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
1120
1121
|
return txSig;
|
|
1121
1122
|
}
|
|
1122
|
-
async getUpdateSpotMarketOracleIx(spotMarketIndex, oracle, oracleSource) {
|
|
1123
|
-
return await this.program.instruction.updateSpotMarketOracle(oracle, oracleSource, {
|
|
1123
|
+
async getUpdateSpotMarketOracleIx(spotMarketIndex, oracle, oracleSource, skipInvaraintCheck = false) {
|
|
1124
|
+
return await this.program.instruction.updateSpotMarketOracle(oracle, oracleSource, skipInvaraintCheck, {
|
|
1124
1125
|
accounts: {
|
|
1125
1126
|
admin: this.isSubscribed
|
|
1126
1127
|
? this.getStateAccount().admin
|
|
@@ -1128,6 +1129,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
1128
1129
|
state: await this.getStatePublicKey(),
|
|
1129
1130
|
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
1130
1131
|
oracle: oracle,
|
|
1132
|
+
oldOracle: this.getSpotMarketAccount(spotMarketIndex).oracle,
|
|
1131
1133
|
},
|
|
1132
1134
|
});
|
|
1133
1135
|
}
|
|
@@ -5260,6 +5260,11 @@
|
|
|
5260
5260
|
"name": "oracle",
|
|
5261
5261
|
"isMut": false,
|
|
5262
5262
|
"isSigner": false
|
|
5263
|
+
},
|
|
5264
|
+
{
|
|
5265
|
+
"name": "oldOracle",
|
|
5266
|
+
"isMut": false,
|
|
5267
|
+
"isSigner": false
|
|
5263
5268
|
}
|
|
5264
5269
|
],
|
|
5265
5270
|
"args": [
|
|
@@ -5272,6 +5277,10 @@
|
|
|
5272
5277
|
"type": {
|
|
5273
5278
|
"defined": "OracleSource"
|
|
5274
5279
|
}
|
|
5280
|
+
},
|
|
5281
|
+
{
|
|
5282
|
+
"name": "skipInvariantCheck",
|
|
5283
|
+
"type": "bool"
|
|
5275
5284
|
}
|
|
5276
5285
|
]
|
|
5277
5286
|
},
|
|
@@ -5879,6 +5888,11 @@
|
|
|
5879
5888
|
{
|
|
5880
5889
|
"name": "updatePerpMarketOracle",
|
|
5881
5890
|
"accounts": [
|
|
5891
|
+
{
|
|
5892
|
+
"name": "admin",
|
|
5893
|
+
"isMut": false,
|
|
5894
|
+
"isSigner": true
|
|
5895
|
+
},
|
|
5882
5896
|
{
|
|
5883
5897
|
"name": "state",
|
|
5884
5898
|
"isMut": false,
|
|
@@ -5895,9 +5909,9 @@
|
|
|
5895
5909
|
"isSigner": false
|
|
5896
5910
|
},
|
|
5897
5911
|
{
|
|
5898
|
-
"name": "
|
|
5912
|
+
"name": "oldOracle",
|
|
5899
5913
|
"isMut": false,
|
|
5900
|
-
"isSigner":
|
|
5914
|
+
"isSigner": false
|
|
5901
5915
|
}
|
|
5902
5916
|
],
|
|
5903
5917
|
"args": [
|
|
@@ -5910,6 +5924,10 @@
|
|
|
5910
5924
|
"type": {
|
|
5911
5925
|
"defined": "OracleSource"
|
|
5912
5926
|
}
|
|
5927
|
+
},
|
|
5928
|
+
{
|
|
5929
|
+
"name": "skipInvariantCheck",
|
|
5930
|
+
"type": "bool"
|
|
5913
5931
|
}
|
|
5914
5932
|
]
|
|
5915
5933
|
},
|
|
@@ -10890,7 +10908,7 @@
|
|
|
10890
10908
|
{
|
|
10891
10909
|
"name": "postedSlotTail",
|
|
10892
10910
|
"docs": [
|
|
10893
|
-
"Last 8 bits of the slot the order was posted on-chain (not order slot for
|
|
10911
|
+
"Last 8 bits of the slot the order was posted on-chain (not order slot for signed msg orders)"
|
|
10894
10912
|
],
|
|
10895
10913
|
"type": "u8"
|
|
10896
10914
|
},
|
|
@@ -342,7 +342,13 @@ function calculateWithdrawLimit(spotMarket, now) {
|
|
|
342
342
|
.add(marketDepositTokenAmount.mul(sinceLast))
|
|
343
343
|
.div(sinceLast.add(sinceStart));
|
|
344
344
|
const lesserDepositAmount = anchor_1.BN.min(marketDepositTokenAmount, depositTokenTwapLive);
|
|
345
|
-
|
|
345
|
+
let maxBorrowTokensTwap;
|
|
346
|
+
if (spotMarket.poolId == 0) {
|
|
347
|
+
maxBorrowTokensTwap = anchor_1.BN.max(spotMarket.withdrawGuardThreshold, anchor_1.BN.min(anchor_1.BN.max(marketDepositTokenAmount.div(new anchor_1.BN(6)), borrowTokenTwapLive.add(lesserDepositAmount.div(new anchor_1.BN(10)))), lesserDepositAmount.sub(lesserDepositAmount.div(new anchor_1.BN(5))))); // main pool between ~15-80% utilization with 10% friction on twap
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
maxBorrowTokensTwap = anchor_1.BN.max(spotMarket.withdrawGuardThreshold, anchor_1.BN.min(anchor_1.BN.max(marketDepositTokenAmount.div(new anchor_1.BN(2)), borrowTokenTwapLive.add(lesserDepositAmount.div(new anchor_1.BN(3)))), lesserDepositAmount.sub(lesserDepositAmount.div(new anchor_1.BN(10))))); // isolated pool between ~50-90% utilization with 33% friction on twap
|
|
351
|
+
}
|
|
346
352
|
const minDepositTokensTwap = depositTokenTwapLive.sub(anchor_1.BN.max(depositTokenTwapLive.div(new anchor_1.BN(4)), anchor_1.BN.min(spotMarket.withdrawGuardThreshold, depositTokenTwapLive)));
|
|
347
353
|
const { minDepositTokensForUtilization, maxBorrowTokensForUtilization } = calculateTokenUtilizationLimits(marketDepositTokenAmount, marketBorrowTokenAmount, spotMarket);
|
|
348
354
|
const minDepositTokens = anchor_1.BN.max(minDepositTokensForUtilization, minDepositTokensTwap);
|
|
@@ -107,8 +107,8 @@ export declare class AdminClient extends DriftClient {
|
|
|
107
107
|
getUpdateInsuranceFundUnstakingPeriodIx(spotMarketIndex: number, insuranceWithdrawEscrowPeriod: BN): Promise<TransactionInstruction>;
|
|
108
108
|
updateLpCooldownTime(cooldownTime: BN): Promise<TransactionSignature>;
|
|
109
109
|
getUpdateLpCooldownTimeIx(cooldownTime: BN): Promise<TransactionInstruction>;
|
|
110
|
-
updatePerpMarketOracle(perpMarketIndex: number, oracle: PublicKey, oracleSource: OracleSource): Promise<TransactionSignature>;
|
|
111
|
-
getUpdatePerpMarketOracleIx(perpMarketIndex: number, oracle: PublicKey, oracleSource: OracleSource): Promise<TransactionInstruction>;
|
|
110
|
+
updatePerpMarketOracle(perpMarketIndex: number, oracle: PublicKey, oracleSource: OracleSource, skipInvaraintCheck?: boolean): Promise<TransactionSignature>;
|
|
111
|
+
getUpdatePerpMarketOracleIx(perpMarketIndex: number, oracle: PublicKey, oracleSource: OracleSource, skipInvaraintCheck?: boolean): Promise<TransactionInstruction>;
|
|
112
112
|
updatePerpMarketStepSizeAndTickSize(perpMarketIndex: number, stepSize: BN, tickSize: BN): Promise<TransactionSignature>;
|
|
113
113
|
getUpdatePerpMarketStepSizeAndTickSizeIx(perpMarketIndex: number, stepSize: BN, tickSize: BN): Promise<TransactionInstruction>;
|
|
114
114
|
updatePerpMarketMinOrderSize(perpMarketIndex: number, orderSize: BN): Promise<TransactionSignature>;
|
|
@@ -119,8 +119,8 @@ export declare class AdminClient extends DriftClient {
|
|
|
119
119
|
getUpdateSpotMarketMinOrderSizeIx(spotMarketIndex: number, orderSize: BN): Promise<TransactionInstruction>;
|
|
120
120
|
updatePerpMarketExpiry(perpMarketIndex: number, expiryTs: BN): Promise<TransactionSignature>;
|
|
121
121
|
getUpdatePerpMarketExpiryIx(perpMarketIndex: number, expiryTs: BN): Promise<TransactionInstruction>;
|
|
122
|
-
updateSpotMarketOracle(spotMarketIndex: number, oracle: PublicKey, oracleSource: OracleSource): Promise<TransactionSignature>;
|
|
123
|
-
getUpdateSpotMarketOracleIx(spotMarketIndex: number, oracle: PublicKey, oracleSource: OracleSource): Promise<TransactionInstruction>;
|
|
122
|
+
updateSpotMarketOracle(spotMarketIndex: number, oracle: PublicKey, oracleSource: OracleSource, skipInvaraintCheck?: boolean): Promise<TransactionSignature>;
|
|
123
|
+
getUpdateSpotMarketOracleIx(spotMarketIndex: number, oracle: PublicKey, oracleSource: OracleSource, skipInvaraintCheck?: boolean): Promise<TransactionInstruction>;
|
|
124
124
|
updateSpotMarketOrdersEnabled(spotMarketIndex: number, ordersEnabled: boolean): Promise<TransactionSignature>;
|
|
125
125
|
getUpdateSpotMarketOrdersEnabledIx(spotMarketIndex: number, ordersEnabled: boolean): Promise<TransactionInstruction>;
|
|
126
126
|
updateSpotMarketIfPausedOperations(spotMarketIndex: number, pausedOperations: number): Promise<TransactionSignature>;
|
package/lib/node/adminClient.js
CHANGED
|
@@ -1002,14 +1002,14 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
1002
1002
|
},
|
|
1003
1003
|
});
|
|
1004
1004
|
}
|
|
1005
|
-
async updatePerpMarketOracle(perpMarketIndex, oracle, oracleSource) {
|
|
1006
|
-
const updatePerpMarketOracleIx = await this.getUpdatePerpMarketOracleIx(perpMarketIndex, oracle, oracleSource);
|
|
1005
|
+
async updatePerpMarketOracle(perpMarketIndex, oracle, oracleSource, skipInvaraintCheck = false) {
|
|
1006
|
+
const updatePerpMarketOracleIx = await this.getUpdatePerpMarketOracleIx(perpMarketIndex, oracle, oracleSource, skipInvaraintCheck);
|
|
1007
1007
|
const tx = await this.buildTransaction(updatePerpMarketOracleIx);
|
|
1008
1008
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
1009
1009
|
return txSig;
|
|
1010
1010
|
}
|
|
1011
|
-
async getUpdatePerpMarketOracleIx(perpMarketIndex, oracle, oracleSource) {
|
|
1012
|
-
return await this.program.instruction.updatePerpMarketOracle(oracle, oracleSource, {
|
|
1011
|
+
async getUpdatePerpMarketOracleIx(perpMarketIndex, oracle, oracleSource, skipInvaraintCheck = false) {
|
|
1012
|
+
return await this.program.instruction.updatePerpMarketOracle(oracle, oracleSource, skipInvaraintCheck, {
|
|
1013
1013
|
accounts: {
|
|
1014
1014
|
admin: this.isSubscribed
|
|
1015
1015
|
? this.getStateAccount().admin
|
|
@@ -1017,6 +1017,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
1017
1017
|
state: await this.getStatePublicKey(),
|
|
1018
1018
|
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
1019
1019
|
oracle: oracle,
|
|
1020
|
+
oldOracle: this.getPerpMarketAccount(perpMarketIndex).amm.oracle,
|
|
1020
1021
|
},
|
|
1021
1022
|
});
|
|
1022
1023
|
}
|
|
@@ -1113,14 +1114,14 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
1113
1114
|
},
|
|
1114
1115
|
});
|
|
1115
1116
|
}
|
|
1116
|
-
async updateSpotMarketOracle(spotMarketIndex, oracle, oracleSource) {
|
|
1117
|
-
const updateSpotMarketOracleIx = await this.getUpdateSpotMarketOracleIx(spotMarketIndex, oracle, oracleSource);
|
|
1117
|
+
async updateSpotMarketOracle(spotMarketIndex, oracle, oracleSource, skipInvaraintCheck = false) {
|
|
1118
|
+
const updateSpotMarketOracleIx = await this.getUpdateSpotMarketOracleIx(spotMarketIndex, oracle, oracleSource, skipInvaraintCheck);
|
|
1118
1119
|
const tx = await this.buildTransaction(updateSpotMarketOracleIx);
|
|
1119
1120
|
const { txSig } = await this.sendTransaction(tx, [], this.opts);
|
|
1120
1121
|
return txSig;
|
|
1121
1122
|
}
|
|
1122
|
-
async getUpdateSpotMarketOracleIx(spotMarketIndex, oracle, oracleSource) {
|
|
1123
|
-
return await this.program.instruction.updateSpotMarketOracle(oracle, oracleSource, {
|
|
1123
|
+
async getUpdateSpotMarketOracleIx(spotMarketIndex, oracle, oracleSource, skipInvaraintCheck = false) {
|
|
1124
|
+
return await this.program.instruction.updateSpotMarketOracle(oracle, oracleSource, skipInvaraintCheck, {
|
|
1124
1125
|
accounts: {
|
|
1125
1126
|
admin: this.isSubscribed
|
|
1126
1127
|
? this.getStateAccount().admin
|
|
@@ -1128,6 +1129,7 @@ class AdminClient extends driftClient_1.DriftClient {
|
|
|
1128
1129
|
state: await this.getStatePublicKey(),
|
|
1129
1130
|
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
1130
1131
|
oracle: oracle,
|
|
1132
|
+
oldOracle: this.getSpotMarketAccount(spotMarketIndex).oracle,
|
|
1131
1133
|
},
|
|
1132
1134
|
});
|
|
1133
1135
|
}
|
package/lib/node/idl/drift.json
CHANGED
|
@@ -5260,6 +5260,11 @@
|
|
|
5260
5260
|
"name": "oracle",
|
|
5261
5261
|
"isMut": false,
|
|
5262
5262
|
"isSigner": false
|
|
5263
|
+
},
|
|
5264
|
+
{
|
|
5265
|
+
"name": "oldOracle",
|
|
5266
|
+
"isMut": false,
|
|
5267
|
+
"isSigner": false
|
|
5263
5268
|
}
|
|
5264
5269
|
],
|
|
5265
5270
|
"args": [
|
|
@@ -5272,6 +5277,10 @@
|
|
|
5272
5277
|
"type": {
|
|
5273
5278
|
"defined": "OracleSource"
|
|
5274
5279
|
}
|
|
5280
|
+
},
|
|
5281
|
+
{
|
|
5282
|
+
"name": "skipInvariantCheck",
|
|
5283
|
+
"type": "bool"
|
|
5275
5284
|
}
|
|
5276
5285
|
]
|
|
5277
5286
|
},
|
|
@@ -5879,6 +5888,11 @@
|
|
|
5879
5888
|
{
|
|
5880
5889
|
"name": "updatePerpMarketOracle",
|
|
5881
5890
|
"accounts": [
|
|
5891
|
+
{
|
|
5892
|
+
"name": "admin",
|
|
5893
|
+
"isMut": false,
|
|
5894
|
+
"isSigner": true
|
|
5895
|
+
},
|
|
5882
5896
|
{
|
|
5883
5897
|
"name": "state",
|
|
5884
5898
|
"isMut": false,
|
|
@@ -5895,9 +5909,9 @@
|
|
|
5895
5909
|
"isSigner": false
|
|
5896
5910
|
},
|
|
5897
5911
|
{
|
|
5898
|
-
"name": "
|
|
5912
|
+
"name": "oldOracle",
|
|
5899
5913
|
"isMut": false,
|
|
5900
|
-
"isSigner":
|
|
5914
|
+
"isSigner": false
|
|
5901
5915
|
}
|
|
5902
5916
|
],
|
|
5903
5917
|
"args": [
|
|
@@ -5910,6 +5924,10 @@
|
|
|
5910
5924
|
"type": {
|
|
5911
5925
|
"defined": "OracleSource"
|
|
5912
5926
|
}
|
|
5927
|
+
},
|
|
5928
|
+
{
|
|
5929
|
+
"name": "skipInvariantCheck",
|
|
5930
|
+
"type": "bool"
|
|
5913
5931
|
}
|
|
5914
5932
|
]
|
|
5915
5933
|
},
|
|
@@ -10890,7 +10908,7 @@
|
|
|
10890
10908
|
{
|
|
10891
10909
|
"name": "postedSlotTail",
|
|
10892
10910
|
"docs": [
|
|
10893
|
-
"Last 8 bits of the slot the order was posted on-chain (not order slot for
|
|
10911
|
+
"Last 8 bits of the slot the order was posted on-chain (not order slot for signed msg orders)"
|
|
10894
10912
|
],
|
|
10895
10913
|
"type": "u8"
|
|
10896
10914
|
},
|
|
@@ -342,7 +342,13 @@ function calculateWithdrawLimit(spotMarket, now) {
|
|
|
342
342
|
.add(marketDepositTokenAmount.mul(sinceLast))
|
|
343
343
|
.div(sinceLast.add(sinceStart));
|
|
344
344
|
const lesserDepositAmount = anchor_1.BN.min(marketDepositTokenAmount, depositTokenTwapLive);
|
|
345
|
-
|
|
345
|
+
let maxBorrowTokensTwap;
|
|
346
|
+
if (spotMarket.poolId == 0) {
|
|
347
|
+
maxBorrowTokensTwap = anchor_1.BN.max(spotMarket.withdrawGuardThreshold, anchor_1.BN.min(anchor_1.BN.max(marketDepositTokenAmount.div(new anchor_1.BN(6)), borrowTokenTwapLive.add(lesserDepositAmount.div(new anchor_1.BN(10)))), lesserDepositAmount.sub(lesserDepositAmount.div(new anchor_1.BN(5))))); // main pool between ~15-80% utilization with 10% friction on twap
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
maxBorrowTokensTwap = anchor_1.BN.max(spotMarket.withdrawGuardThreshold, anchor_1.BN.min(anchor_1.BN.max(marketDepositTokenAmount.div(new anchor_1.BN(2)), borrowTokenTwapLive.add(lesserDepositAmount.div(new anchor_1.BN(3)))), lesserDepositAmount.sub(lesserDepositAmount.div(new anchor_1.BN(10))))); // isolated pool between ~50-90% utilization with 33% friction on twap
|
|
351
|
+
}
|
|
346
352
|
const minDepositTokensTwap = depositTokenTwapLive.sub(anchor_1.BN.max(depositTokenTwapLive.div(new anchor_1.BN(4)), anchor_1.BN.min(spotMarket.withdrawGuardThreshold, depositTokenTwapLive)));
|
|
347
353
|
const { minDepositTokensForUtilization, maxBorrowTokensForUtilization } = calculateTokenUtilizationLimits(marketDepositTokenAmount, marketBorrowTokenAmount, spotMarket);
|
|
348
354
|
const minDepositTokens = anchor_1.BN.max(minDepositTokensForUtilization, minDepositTokensTwap);
|
package/package.json
CHANGED
package/src/adminClient.ts
CHANGED
|
@@ -2175,12 +2175,14 @@ export class AdminClient extends DriftClient {
|
|
|
2175
2175
|
public async updatePerpMarketOracle(
|
|
2176
2176
|
perpMarketIndex: number,
|
|
2177
2177
|
oracle: PublicKey,
|
|
2178
|
-
oracleSource: OracleSource
|
|
2178
|
+
oracleSource: OracleSource,
|
|
2179
|
+
skipInvaraintCheck = false
|
|
2179
2180
|
): Promise<TransactionSignature> {
|
|
2180
2181
|
const updatePerpMarketOracleIx = await this.getUpdatePerpMarketOracleIx(
|
|
2181
2182
|
perpMarketIndex,
|
|
2182
2183
|
oracle,
|
|
2183
|
-
oracleSource
|
|
2184
|
+
oracleSource,
|
|
2185
|
+
skipInvaraintCheck
|
|
2184
2186
|
);
|
|
2185
2187
|
|
|
2186
2188
|
const tx = await this.buildTransaction(updatePerpMarketOracleIx);
|
|
@@ -2193,11 +2195,13 @@ export class AdminClient extends DriftClient {
|
|
|
2193
2195
|
public async getUpdatePerpMarketOracleIx(
|
|
2194
2196
|
perpMarketIndex: number,
|
|
2195
2197
|
oracle: PublicKey,
|
|
2196
|
-
oracleSource: OracleSource
|
|
2198
|
+
oracleSource: OracleSource,
|
|
2199
|
+
skipInvaraintCheck = false
|
|
2197
2200
|
): Promise<TransactionInstruction> {
|
|
2198
2201
|
return await this.program.instruction.updatePerpMarketOracle(
|
|
2199
2202
|
oracle,
|
|
2200
2203
|
oracleSource,
|
|
2204
|
+
skipInvaraintCheck,
|
|
2201
2205
|
{
|
|
2202
2206
|
accounts: {
|
|
2203
2207
|
admin: this.isSubscribed
|
|
@@ -2209,6 +2213,7 @@ export class AdminClient extends DriftClient {
|
|
|
2209
2213
|
perpMarketIndex
|
|
2210
2214
|
),
|
|
2211
2215
|
oracle: oracle,
|
|
2216
|
+
oldOracle: this.getPerpMarketAccount(perpMarketIndex).amm.oracle,
|
|
2212
2217
|
},
|
|
2213
2218
|
}
|
|
2214
2219
|
);
|
|
@@ -2419,12 +2424,14 @@ export class AdminClient extends DriftClient {
|
|
|
2419
2424
|
public async updateSpotMarketOracle(
|
|
2420
2425
|
spotMarketIndex: number,
|
|
2421
2426
|
oracle: PublicKey,
|
|
2422
|
-
oracleSource: OracleSource
|
|
2427
|
+
oracleSource: OracleSource,
|
|
2428
|
+
skipInvaraintCheck = false
|
|
2423
2429
|
): Promise<TransactionSignature> {
|
|
2424
2430
|
const updateSpotMarketOracleIx = await this.getUpdateSpotMarketOracleIx(
|
|
2425
2431
|
spotMarketIndex,
|
|
2426
2432
|
oracle,
|
|
2427
|
-
oracleSource
|
|
2433
|
+
oracleSource,
|
|
2434
|
+
skipInvaraintCheck
|
|
2428
2435
|
);
|
|
2429
2436
|
|
|
2430
2437
|
const tx = await this.buildTransaction(updateSpotMarketOracleIx);
|
|
@@ -2437,11 +2444,13 @@ export class AdminClient extends DriftClient {
|
|
|
2437
2444
|
public async getUpdateSpotMarketOracleIx(
|
|
2438
2445
|
spotMarketIndex: number,
|
|
2439
2446
|
oracle: PublicKey,
|
|
2440
|
-
oracleSource: OracleSource
|
|
2447
|
+
oracleSource: OracleSource,
|
|
2448
|
+
skipInvaraintCheck = false
|
|
2441
2449
|
): Promise<TransactionInstruction> {
|
|
2442
2450
|
return await this.program.instruction.updateSpotMarketOracle(
|
|
2443
2451
|
oracle,
|
|
2444
2452
|
oracleSource,
|
|
2453
|
+
skipInvaraintCheck,
|
|
2445
2454
|
{
|
|
2446
2455
|
accounts: {
|
|
2447
2456
|
admin: this.isSubscribed
|
|
@@ -2453,6 +2462,7 @@ export class AdminClient extends DriftClient {
|
|
|
2453
2462
|
spotMarketIndex
|
|
2454
2463
|
),
|
|
2455
2464
|
oracle: oracle,
|
|
2465
|
+
oldOracle: this.getSpotMarketAccount(spotMarketIndex).oracle,
|
|
2456
2466
|
},
|
|
2457
2467
|
}
|
|
2458
2468
|
);
|
package/src/idl/drift.json
CHANGED
|
@@ -5260,6 +5260,11 @@
|
|
|
5260
5260
|
"name": "oracle",
|
|
5261
5261
|
"isMut": false,
|
|
5262
5262
|
"isSigner": false
|
|
5263
|
+
},
|
|
5264
|
+
{
|
|
5265
|
+
"name": "oldOracle",
|
|
5266
|
+
"isMut": false,
|
|
5267
|
+
"isSigner": false
|
|
5263
5268
|
}
|
|
5264
5269
|
],
|
|
5265
5270
|
"args": [
|
|
@@ -5272,6 +5277,10 @@
|
|
|
5272
5277
|
"type": {
|
|
5273
5278
|
"defined": "OracleSource"
|
|
5274
5279
|
}
|
|
5280
|
+
},
|
|
5281
|
+
{
|
|
5282
|
+
"name": "skipInvariantCheck",
|
|
5283
|
+
"type": "bool"
|
|
5275
5284
|
}
|
|
5276
5285
|
]
|
|
5277
5286
|
},
|
|
@@ -5879,6 +5888,11 @@
|
|
|
5879
5888
|
{
|
|
5880
5889
|
"name": "updatePerpMarketOracle",
|
|
5881
5890
|
"accounts": [
|
|
5891
|
+
{
|
|
5892
|
+
"name": "admin",
|
|
5893
|
+
"isMut": false,
|
|
5894
|
+
"isSigner": true
|
|
5895
|
+
},
|
|
5882
5896
|
{
|
|
5883
5897
|
"name": "state",
|
|
5884
5898
|
"isMut": false,
|
|
@@ -5895,9 +5909,9 @@
|
|
|
5895
5909
|
"isSigner": false
|
|
5896
5910
|
},
|
|
5897
5911
|
{
|
|
5898
|
-
"name": "
|
|
5912
|
+
"name": "oldOracle",
|
|
5899
5913
|
"isMut": false,
|
|
5900
|
-
"isSigner":
|
|
5914
|
+
"isSigner": false
|
|
5901
5915
|
}
|
|
5902
5916
|
],
|
|
5903
5917
|
"args": [
|
|
@@ -5910,6 +5924,10 @@
|
|
|
5910
5924
|
"type": {
|
|
5911
5925
|
"defined": "OracleSource"
|
|
5912
5926
|
}
|
|
5927
|
+
},
|
|
5928
|
+
{
|
|
5929
|
+
"name": "skipInvariantCheck",
|
|
5930
|
+
"type": "bool"
|
|
5913
5931
|
}
|
|
5914
5932
|
]
|
|
5915
5933
|
},
|
|
@@ -10890,7 +10908,7 @@
|
|
|
10890
10908
|
{
|
|
10891
10909
|
"name": "postedSlotTail",
|
|
10892
10910
|
"docs": [
|
|
10893
|
-
"Last 8 bits of the slot the order was posted on-chain (not order slot for
|
|
10911
|
+
"Last 8 bits of the slot the order was posted on-chain (not order slot for signed msg orders)"
|
|
10894
10912
|
],
|
|
10895
10913
|
"type": "u8"
|
|
10896
10914
|
},
|
package/src/math/spotBalance.ts
CHANGED
|
@@ -554,16 +554,31 @@ export function calculateWithdrawLimit(
|
|
|
554
554
|
marketDepositTokenAmount,
|
|
555
555
|
depositTokenTwapLive
|
|
556
556
|
);
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
557
|
+
let maxBorrowTokensTwap;
|
|
558
|
+
|
|
559
|
+
if (spotMarket.poolId == 0) {
|
|
560
|
+
maxBorrowTokensTwap = BN.max(
|
|
561
|
+
spotMarket.withdrawGuardThreshold,
|
|
562
|
+
BN.min(
|
|
563
|
+
BN.max(
|
|
564
|
+
marketDepositTokenAmount.div(new BN(6)),
|
|
565
|
+
borrowTokenTwapLive.add(lesserDepositAmount.div(new BN(10)))
|
|
566
|
+
),
|
|
567
|
+
lesserDepositAmount.sub(lesserDepositAmount.div(new BN(5)))
|
|
568
|
+
)
|
|
569
|
+
); // main pool between ~15-80% utilization with 10% friction on twap
|
|
570
|
+
} else {
|
|
571
|
+
maxBorrowTokensTwap = BN.max(
|
|
572
|
+
spotMarket.withdrawGuardThreshold,
|
|
573
|
+
BN.min(
|
|
574
|
+
BN.max(
|
|
575
|
+
marketDepositTokenAmount.div(new BN(2)),
|
|
576
|
+
borrowTokenTwapLive.add(lesserDepositAmount.div(new BN(3)))
|
|
577
|
+
),
|
|
578
|
+
lesserDepositAmount.sub(lesserDepositAmount.div(new BN(10)))
|
|
579
|
+
)
|
|
580
|
+
); // isolated pool between ~50-90% utilization with 33% friction on twap
|
|
581
|
+
}
|
|
567
582
|
|
|
568
583
|
const minDepositTokensTwap = depositTokenTwapLive.sub(
|
|
569
584
|
BN.max(
|