Skip to content

Commit

Permalink
Peter/fix bridge dust value validation (#1374)
Browse files Browse the repository at this point in the history
* chore: update monetary to latest 0.7.3

* fix: dust value calculation
  • Loading branch information
peterslany authored Jun 28, 2023
1 parent 06b0ca4 commit ef2e8dd
Showing 1 changed file with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,6 @@ const RedeemForm = ({
const currentRequestLimit = getRequestLimit(redeemLimit, selectedVault, premium?.redeemLimit, isPremiumRedeem);
const redeemBalance = assetBalance.gt(currentRequestLimit) ? currentRequestLimit : assetBalance;

const transferAmountSchemaParams = {
governanceBalance,
maxAmount: redeemBalance,
minAmount: dustValue
};

const getTransactionArgs = useCallback(
(values: BridgeRedeemFormData): TransactionArgs<Transaction.REDEEM_REQUEST> | undefined => {
const amount = values[BRIDGE_REDEEM_AMOUNT_FIELD];
Expand Down Expand Up @@ -161,6 +155,20 @@ const RedeemForm = ({
transaction.execute(...args);
};

const monetaryAmount = newSafeMonetaryAmount(amount || 0, WRAPPED_TOKEN, true);

const bridgeFee = monetaryAmount.mul(feeRate);

const totalFees = bridgeFee.add(currentInclusionFee);

const minAmount = totalFees.add(dustValue).add(newMonetaryAmount(1, WRAPPED_TOKEN));

const transferAmountSchemaParams = {
governanceBalance,
maxAmount: redeemBalance,
minAmount
};

const form = useForm<BridgeRedeemFormData>({
initialValues: {
[BRIDGE_REDEEM_AMOUNT_FIELD]: '',
Expand Down Expand Up @@ -226,15 +234,10 @@ const RedeemForm = ({
setSelectedVault(vault);
};

const monetaryAmount = newSafeMonetaryAmount(amount || 0, WRAPPED_TOKEN, true);
const amountUSD = monetaryAmount
? convertMonetaryAmountToValueInUSD(monetaryAmount, getTokenPrice(prices, monetaryAmount.currency.ticker)?.usd) || 0
: 0;

const bridgeFee = monetaryAmount.mul(feeRate);

const totalFees = bridgeFee.add(currentInclusionFee);

const totalAmount = monetaryAmount.gte(totalFees)
? monetaryAmount.sub(totalFees)
: newMonetaryAmount(0, WRAPPED_TOKEN);
Expand Down

2 comments on commit ef2e8dd

@vercel
Copy link

@vercel vercel bot commented on ef2e8dd Jun 28, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on ef2e8dd Jun 28, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.