Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contracts/addresses/1.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"debtInFrontHelper": "0x4bb5e28fdb12891369b560f2fab3c032600677c6",
"exchangeHelpers": "0x2f60bab0072abec7058017f48d7256ec288c8686",
"exchangeHelpersV2": "0xe453b864d3841469763bda2437e3dd0e38dca222",
"redemptionHelper": "0x0000000000000000000000000000000000000000",
"redemptionHelper": "0xb366256d033ae7e4f7bddec822a5adec9df07b80",
"branches": [
{
"collSymbol": "WETH",
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/.env
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ NEXT_PUBLIC_CONTRACT_LQTY_STAKING=0x4f9fbb3f1e99b56e0fe2892e623ed36a76fc605d
NEXT_PUBLIC_CONTRACT_LQTY_TOKEN=0x6dea81c8171d0ba574754ef6f8b412f2ed88c54d
NEXT_PUBLIC_CONTRACT_LUSD_TOKEN=0x5f98805a4e8be255a32880fdec7f6728c6568ba0
NEXT_PUBLIC_CONTRACT_MULTI_TROVE_GETTER=0xfa61db085510c64b83056db3a7acf3b6f631d235
NEXT_PUBLIC_CONTRACT_REDEMPTION_HELPER=0x0000000000000000000000000000000000000000
NEXT_PUBLIC_CONTRACT_REDEMPTION_HELPER=0xb366256d033ae7e4f7bddec822a5adec9df07b80
NEXT_PUBLIC_CONTRACT_WETH=0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2

###########
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/comps/AppLayout/BottomBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Image from "next/image";
import { AboutButton } from "./AboutButton";

const DISPLAYED_PRICES = ["LQTY", "BOLD", "ETH"] as const;
const ENABLE_REDEEM = false;
const ENABLE_REDEEM = true;

export function BottomBar() {
const account = useAccount();
Expand Down
4 changes: 4 additions & 0 deletions frontend/app/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export const TROVE_STATUS_CLOSED_BY_OWNER = 2;
export const TROVE_STATUS_CLOSED_BY_LIQUIDATION = 3;
export const TROVE_STATUS_ZOMBIE = 4;

export const REDEMPTION_MAX_ITERATIONS_PER_COLL = 25;
export const REDEMPTION_FEE_HIGH = 0.01; // 1%
export const REDEMPTION_SLIPPAGE_TOLERANCE = 0.001; // 0.1%

// XXX what is the point of this?
export const MAX_COLLATERAL_DEPOSITS: Record<CollateralSymbol, dn.Dnum> = {
ETH: dn.from(100_000_000n, 18),
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/src/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -368,13 +368,13 @@ export default {
action: "Next: Summary",
},
rewardsPanel: {
boldRewardsLabel: (collateral: N) => <>Your BOLD rewards will be paid out</>,
boldRewardsLabel: "Your BOLD rewards will be paid out",
collRewardsLabel: (collateral: N) => <>Your {collateral} rewards will be paid out</>,
expectedGasFeeLabel: "Expected gas fee",
action: "Next: Summary",
},
compoundPanel: {
boldRewardsLabel: (collateral: N) => <>Your BOLD rewards will be used to top-up your deposit</>,
boldRewardsLabel: "Your BOLD rewards will be used to top-up your deposit",
collRewardsLabel: (collateral: N) => <>Your {collateral} rewards will remain in your deposit</>,
expectedGasFeeLabel: "Expected gas fee",
action: "Next: Summary",
Expand Down
42 changes: 41 additions & 1 deletion frontend/app/src/liquity-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { dnum18, DNUM_0, dnumOrNull, jsonStringifyWithDnum } from "@/src/dnum-ut
import { CHAIN_BLOCK_EXPLORER, ENV_BRANCHES, LEGACY_CHECK, LIQUITY_STATS_URL } from "@/src/env";
import { getRedemptionRisk } from "@/src/liquity-math";
import { combineStatus } from "@/src/query-utils";
import { useDebounced } from "@/src/react-utils";
import { usePrice } from "@/src/services/Prices";
import {
getAllInterestRateBrackets,
Expand All @@ -52,7 +53,7 @@ import * as dn from "dnum";
import { useMemo } from "react";
import * as v from "valibot";
import { encodeAbiParameters, erc20Abi, isAddressEqual, keccak256, parseAbiParameters, zeroAddress } from "viem";
import { useBalance, useConfig as useWagmiConfig, useReadContract, useReadContracts } from "wagmi";
import { useBalance, useConfig as useWagmiConfig, useReadContract, useReadContracts, useSimulateContract } from "wagmi";
import { readContract, readContracts } from "wagmi/actions";

export function shortenTroveId(troveId: TroveId, chars = 8) {
Expand Down Expand Up @@ -1479,3 +1480,42 @@ export function useRedemptionRiskOfInterestRate(
return { status, data: getRedemptionRisk(data.debtInFront, data.totalDebt) };
}, [status, data]);
}

export interface RedemptionSimulationParams {
boldAmount: Dnum;
maxIterationsPerCollateral: number;
}

export function useRedemptionSimulation(params: RedemptionSimulationParams) {
const boldAmount = dn.from(params.boldAmount, 18)[0];
const maxIterationsPerCollateral = BigInt(params.maxIterationsPerCollateral);

const values = useMemo(() => ({
boldAmount,
maxIterationsPerCollateral,
}), [boldAmount, maxIterationsPerCollateral]);

const [debounced, bouncing] = useDebounced(values);
const RedemptionHelper = getProtocolContract("RedemptionHelper");

// We'd love to use `useReadContract()` for this, but wagmi/viem won't let us
// do that for mutating functions, even though it's a perfectly valid use case.
// We could hack the ABI, but that's yucky.
return useSimulateContract({
...RedemptionHelper,
functionName: "truncateRedemption",
args: [debounced.boldAmount, debounced.maxIterationsPerCollateral],

query: {
refetchInterval: 12_000,
enabled: !bouncing,

select: ({ result: [truncatedBold, feePct, output] }) => ({
bouncing,
truncatedBold: dnum18(truncatedBold),
feePct: dnum18(feePct),
collRedeemed: output.map(({ coll }) => dnum18(coll)),
}),
},
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function PanelClaimRewards({
<Rewards
amount={position?.rewards?.bold ?? DNUM_0}
amountUsd={boldRewardsUsd ?? DNUM_0}
label={content.earnScreen.rewardsPanel.boldRewardsLabel(collateral.name)}
label={content.earnScreen.rewardsPanel.boldRewardsLabel}
symbol="BOLD"
/>
<Rewards
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/screens/EarnPoolScreen/PanelCompound.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function PanelCompound({
<Rewards
amount={position?.rewards?.bold ?? DNUM_0}
amountUsd={boldRewardsUsd ?? DNUM_0}
label={content.earnScreen.compoundPanel.boldRewardsLabel(collateral.name)}
label={content.earnScreen.compoundPanel.boldRewardsLabel}
symbol="BOLD"
/>
<Rewards
Expand Down
Loading
Loading