Skip to content

Commit

Permalink
fix logic for zero max cap
Browse files Browse the repository at this point in the history
  • Loading branch information
trinitys7 committed Aug 23, 2024
1 parent aba6c2a commit 90c34a4
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
5 changes: 3 additions & 2 deletions contracts/consumer/converter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,11 +640,12 @@ impl ConverterApi for ConverterContract<'_> {
let channel = IBC_CHANNEL.load(ctx.deps.storage)?;

// Recalculate the price when unbond
let amount = self.invert_price(ctx.deps.as_ref(), amount)?;
let inverted_amount = self.invert_price(ctx.deps.as_ref(), amount.clone())?;
let packet = ConsumerPacket::InternalUnstake {
delegator,
validator,
amount,
normalize_amount: amount,
inverted_amount,
};
let msg = IbcMsg::SendPacket {
channel_id: channel.endpoint.channel_id,
Expand Down
6 changes: 4 additions & 2 deletions contracts/consumer/converter/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,14 +273,16 @@ pub fn ibc_packet_ack(
if let ConsumerPacket::InternalUnstake {
delegator,
validator,
amount,
normalize_amount,
inverted_amount: _,
} = packet
{

// execute virtual contract's internal unbond
let msg = virtual_staking_api::sv::ExecMsg::InternalUnbond {
delegator,
validator,
amount,
amount: normalize_amount,
};
let msg = WasmMsg::Execute {
contract_addr: contract.virtual_stake.load(deps.storage)?.into(),
Expand Down
16 changes: 14 additions & 2 deletions contracts/consumer/virtual-staking/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ impl VirtualStakingApi for VirtualStakingContract<'_> {
fn internal_unbond(
&self,
ctx: ExecCtx<VirtualStakeCustomQuery>,
_delegator: String,
delegator: String,
validator: String,
amount: Coin,
) -> Result<Response<VirtualStakeCustomMsg>, Self::Error> {
Expand Down Expand Up @@ -526,7 +526,19 @@ impl VirtualStakingApi for VirtualStakingContract<'_> {
)
.collect::<Result<_, _>>()?;
self.bonded.save(ctx.deps.storage, &requests)?;
Ok(Response::new())

let mut msgs: Vec<_> = vec![];
msgs.push(VirtualStakeMsg::UpdateDelegation {
amount: amount.clone(),
is_deduct: true,
delegator,
validator: validator.clone(),
});
msgs.push(VirtualStakeMsg::Unbond {
amount,
validator,
});
Ok(Response::new().add_messages(msgs))
}

// FIXME: need to handle custom message types and queries
Expand Down
4 changes: 2 additions & 2 deletions contracts/provider/external-staking/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,8 @@ impl ExternalStakingContract<'_> {

// Commit sub amount, saturating if slashed
let amount = min(amount.amount, stake.stake.high());
stake.stake.commit_sub(amount);

stake.stake.sub(amount, Uint128::zero())?;
let unbond = PendingUnbond {
amount,
release_at: env.block.time,
Expand Down
5 changes: 3 additions & 2 deletions contracts/provider/external-staking/src/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,10 @@ pub fn ibc_packet_receive(
ConsumerPacket::InternalUnstake {
delegator,
validator,
amount,
normalize_amount: _,
inverted_amount,
} => {
let evt = contract.internal_unstake(deps, env, delegator, validator, amount)?;
let evt = contract.internal_unstake(deps, env, delegator, validator, inverted_amount)?;
let ack = ack_success(&DistributeAck {})?;
IbcReceiveResponse::new().set_ack(ack).add_event(evt)
}
Expand Down
3 changes: 2 additions & 1 deletion packages/apis/src/ibc/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ pub enum ConsumerPacket {
/// This is the local (provider-side) denom that is held in the vault.
/// It will be converted to the consumer-side staking token in the converter with help
/// of the price feed.
amount: Coin,
normalize_amount: Coin,
inverted_amount: Coin,
},
/// This is part of the rewards protocol
Distribute {
Expand Down

0 comments on commit 90c34a4

Please sign in to comment.