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
13 changes: 13 additions & 0 deletions src/abis/v2/userManager.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
[
{
"inputs": [],
"name": "maxOverdueTime",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "AmountZero",
Expand Down
46 changes: 34 additions & 12 deletions src/components/modals/VouchModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ import useForm from "hooks/useForm";
import useLabels from "hooks/useLabels";
import { useVouchers } from "providers/VouchersData";
import { useVouchees } from "providers/VoucheesData";
import { BlockSpeed, SECONDS_PER_DAY, ZERO } from "constants";
import { useVersion } from "providers/Version";
import { useProtocol } from "providers/ProtocolData";
import { useNetwork } from "wagmi";

export const VOUCH_MODAL = "vouch-modal";

Expand All @@ -34,8 +38,11 @@ export default function VouchModal({
showAddressSummary = true,
address: initialAddress = null,
}) {
const { isV2 } = useVersion();
const { close } = useModals();
const { chain } = useNetwork();

const { data: protocol } = useProtocol();
const { refetch: refetchMember } = useMember();
const { refetch: refetchVouchers } = useVouchers();
const { refetch: refetchVouchees } = useVouchees();
Expand All @@ -45,6 +52,21 @@ export default function VouchModal({

const [address, setAddress] = useState(initialAddress);

const { overdueTime = ZERO, overdueBlocks = ZERO, maxOverdueTime = ZERO } = protocol;

const versioned = (v1, v2) => (isV2 ? v2 : v1);

const overdueDays = versioned(overdueBlocks, overdueTime.mul(1000))
.mul(versioned(BlockSpeed[chain.id], 1))
.div(SECONDS_PER_DAY * 1000)
.toNumber();

const maxOverdueDays = versioned(overdueBlocks, overdueTime.mul(1000))
.add(maxOverdueTime.mul(1000))
.mul(versioned(BlockSpeed[chain.id], 1))
.div(SECONDS_PER_DAY * 1000)
.toNumber();

const buttonProps = useWrite({
contract: "userManager",
method: "updateTrust",
Expand Down Expand Up @@ -73,9 +95,7 @@ export default function VouchModal({
<Modal className="VouchModal">
<Modal.Header onClose={handleClose} title={title} subTitle={subTitle} />
<Modal.Body>
{address && showAddressSummary && (
<AddressSummary address={address} />
)}
{address && showAddressSummary && <AddressSummary address={address} />}
<AddressInput
defaultValue={initialAddress}
label="Address or ENS of recipient"
Expand Down Expand Up @@ -116,17 +136,19 @@ export default function VouchModal({
items={[
{
label: "Time to default",
value: "30 days",
value: `${overdueDays} days`,
tooltip: {
content: "How long an account can go without making at least a minimum payment",
}
content:
"How long an account can go without making at least a minimum payment",
},
},
{
label: "Time to write-off",
value: "90 days",
value: `${maxOverdueDays} days`,
tooltip: {
content: "Time an account can be in default until it can be publicly written-off",
}
content:
"Time an account can be in default until it can be publicly written-off",
},
},
]}
/>
Expand All @@ -139,9 +161,9 @@ export default function VouchModal({
title="Vouching puts your staked funds at risk"
>
<Text m={0}>
If an account you vouch for doesn't pay the minimum due within 30
days, they'll be in a defaulted state. If they stay that way for
90 days, your stake could be lost permanently to cover their debt.
If an account you vouch for doesn't pay the minimum due within 30 days, they'll be in
a defaulted state. If they stay that way for 90 days, your stake could be lost
permanently to cover their debt.
</Text>
</ExpandingInfo>

Expand Down
28 changes: 13 additions & 15 deletions src/providers/ProtocolData.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,7 @@ export const useProtocolData = (chainId) => {
},
];

const userManagerFunctionNames = [
"maxStakeAmount",
"newMemberFee",
"totalStaked",
"totalFrozen",
];
const userManagerFunctionNames = ["maxStakeAmount", "newMemberFee", "totalStaked", "totalFrozen"];

const uTokenFunctionNames = [
"reserveFactorMantissa",
Expand Down Expand Up @@ -80,6 +75,14 @@ export const useProtocolData = (chainId) => {

const unionTokenFunctionNames = ["totalSupply"];

const v2Functions = [
{
...userManagerContract,
functionName: "maxOverdueTime",
chainId,
},
];

const contracts = [
...buildContractConfigs(assetManagerContract, assetManagerCalls, chainId),
...buildContractConfigs(
Expand Down Expand Up @@ -116,6 +119,7 @@ export const useProtocolData = (chainId) => {
unionTokenFunctionNames.map((n) => ({ functionName: n })),
chainId
),
...(version === Versions.V2 ? v2Functions : []),
];

const resp = useContractReads({
Expand All @@ -129,10 +133,8 @@ export const useProtocolData = (chainId) => {
...(isMainnet ? governorFunctionsNames : []),
...(isMainnet ? timelockFunctionNames : []),
...unionTokenFunctionNames,
].reduce(
(acc, functionName, i) => ({ ...acc, [functionName]: data[i] }),
{}
),
...(version === Versions.V2 ? v2Functions.map((f) => f.functionName) : []),
].reduce((acc, functionName, i) => ({ ...acc, [functionName]: data[i] }), {}),
contracts: contracts,
});

Expand Down Expand Up @@ -164,9 +166,5 @@ export default function ProtocolData({ children }) {

const { data } = useProtocolData(chainId);

return (
<ProtocolContext.Provider value={{ data }}>
{children}
</ProtocolContext.Provider>
);
return <ProtocolContext.Provider value={{ data }}>{children}</ProtocolContext.Provider>;
}