Skip to content

(Extended) Add support for deposit of non base collateral assets#39

Open
ex10ded wants to merge 14 commits into
starkware-libs:changes-for-new-versionfrom
x10xchange:changes-for-new-version
Open

(Extended) Add support for deposit of non base collateral assets#39
ex10ded wants to merge 14 commits into
starkware-libs:changes-for-new-versionfrom
x10xchange:changes-for-new-version

Conversation

@ex10ded

@ex10ded ex10ded commented Sep 10, 2025

Copy link
Copy Markdown
Collaborator

This change is Reviewable

{{github_username}} and others added 2 commits September 9, 2025 16:35
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@ex10ded ex10ded changed the title (Extended) vault Tokenisation changes (Extended) Add support for deposit of non base collateral assets Sep 12, 2025
@ex10ded ex10ded force-pushed the changes-for-new-version branch from 2d72a88 to 23d1221 Compare September 12, 2025 16:31

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Deposit Cancellation Fails for Non-Base Assets

The cancel_deposit function was not updated for multiple asset types. It incorrectly uses the base collateral token contract and quantum, leading to an invalid deposit hash for non-base collateral assets. This prevents users from canceling these deposits and may cause incorrect token transfers.

workspace/apps/perpetuals/contracts/src/core/components/deposit/deposit.cairo#L124-L186

},
);
}
/// Cancel deposit is called by the user to cancel a deposit request which did not take
/// place yet.
///
/// Validations:
/// - The deposit requested to cancel exists, is not canceled and is not processed.
/// - The cancellation delay has passed.
///
/// Execution:
/// - Transfers the quantized amount back to the user.
/// - Updates the deposit status to canceled.
/// - Emits a DepositCanceled event.
fn cancel_deposit(
ref self: ComponentState<TContractState>,
position_id: PositionId,
quantized_amount: u64,
salt: felt252,
) {
let caller_address = get_caller_address();
let assets = get_dep_component!(@self, Assets);
let token_contract = assets.get_collateral_token_contract();
let deposit_hash = deposit_hash(
token_address: token_contract.contract_address,
depositor: caller_address,
:position_id,
:quantized_amount,
:salt,
);
// Validations
match self.get_deposit_status(:deposit_hash) {
DepositStatus::PENDING(deposit_timestamp) => assert(
Time::now() > deposit_timestamp.add(self.cancel_delay.read()),
errors::DEPOSIT_NOT_CANCELABLE,
),
DepositStatus::NOT_REGISTERED => panic_with_felt252(errors::DEPOSIT_NOT_REGISTERED),
DepositStatus::PROCESSED => panic_with_felt252(errors::DEPOSIT_ALREADY_PROCESSED),
DepositStatus::CANCELED => panic_with_felt252(errors::DEPOSIT_ALREADY_CANCELED),
}
self.registered_deposits.write(key: deposit_hash, value: DepositStatus::CANCELED);
let quantum = assets.get_collateral_quantum();
let unquantized_amount = quantized_amount * quantum.into();
token_contract.transfer(recipient: caller_address, amount: unquantized_amount.into());
self
.emit(
events::DepositCanceled {
position_id,
depositing_address: caller_address,
collateral_id: assets.get_collateral_id(),
quantized_amount,
unquantized_amount,
deposit_request_hash: deposit_hash,
salt,
},
);
}
/// Process deposit a collateral amount from the 'depositing_address' to a given position.

Fix in Cursor Fix in Web


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant