-
Notifications
You must be signed in to change notification settings - Fork 228
fix: oracle sync and protocol-wide vault withdrawal protection #2142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
f247bcb
ed4f651
6978542
0a3cdd1
b8cf264
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3788,6 +3788,11 @@ export class DriftClient { | |
| txParams?: TxParams, | ||
| updateFuel = false | ||
| ): Promise<TransactionSignature> { | ||
| // Ensure the destination account is not the vault itself to prevent state inconsistency | ||
| const spotMarket = this.getSpotMarketAccount(marketIndex); | ||
| if (spotMarket.vault.equals(associatedTokenAddress)) { | ||
| throw Error('Destination associatedTokenAddress cannot be the same as the spot market vault'); | ||
| } | ||
| const additionalSigners: Array<Signer> = []; | ||
|
|
||
| const withdrawIxs = await this.getWithdrawalIxs( | ||
|
|
@@ -4371,6 +4376,12 @@ export class DriftClient { | |
| subAccountId?: number, | ||
| txParams?: TxParams | ||
| ): Promise<TransactionSignature> { | ||
| // Ensure the destination account is not the vault itself to prevent state inconsistency | ||
| const spotMarket = this.getSpotMarketAccount(QUOTE_SPOT_MARKET_INDEX); | ||
| if (spotMarket.vault.equals(userTokenAccount)) { | ||
| throw Error('Destination userTokenAccount cannot be the same as the spot market vault'); | ||
| } | ||
|
Comment on lines
+4379
to
+4383
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this validation into the shared ix path and derive the vault from the perp market. This check is currently bypassable because 🔧 Suggested fix public async withdrawFromIsolatedPerpPosition(
amount: BN,
perpMarketIndex: number,
userTokenAccount: PublicKey,
subAccountId?: number,
txParams?: TxParams
): Promise<TransactionSignature> {
- // Ensure the destination account is not the vault itself to prevent state inconsistency
- const spotMarket = this.getSpotMarketAccount(QUOTE_SPOT_MARKET_INDEX);
- if (spotMarket.vault.equals(userTokenAccount)) {
- throw Error('Destination userTokenAccount cannot be the same as the spot market vault');
- }
-
const instructions =
await this.getWithdrawFromIsolatedPerpPositionIxsBundle(
amount,private assertDestinationIsNotVault(
spotMarketVault: PublicKey,
destination: PublicKey,
label: string
): void {
if (spotMarketVault.equals(destination)) {
throw new Error(`Destination ${label} cannot be the same as the spot market vault`);
}
}
public async getWithdrawFromIsolatedPerpPositionIx(
amount: BN,
perpMarketIndex: number,
userTokenAccount: PublicKey,
subAccountId?: number
): Promise<TransactionInstruction> {
const userAccountPublicKey = await getUserAccountPublicKey(
this.program.programId,
this.authority,
subAccountId ?? this.activeSubAccountId
);
const perpMarketAccount = this.getPerpMarketAccount(perpMarketIndex);
const spotMarketIndex = perpMarketAccount.quoteSpotMarketIndex;
const spotMarketAccount = this.getSpotMarketAccount(spotMarketIndex);
this.assertDestinationIsNotVault(
spotMarketAccount.vault,
userTokenAccount,
'userTokenAccount'
);
// existing logic...
}🤖 Prompt for AI Agents |
||
|
|
||
| const instructions = | ||
| await this.getWithdrawFromIsolatedPerpPositionIxsBundle( | ||
| amount, | ||
|
|
@@ -9466,6 +9477,7 @@ export class DriftClient { | |
| remainingAccounts: remainingAccounts, | ||
| } | ||
| ); | ||
|
|
||
| } | ||
|
|
||
| public async getJupiterLiquidateSpotWithSwapIxV6({ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.