Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Leverager: fetch version from contract #1390

Merged
merged 3 commits into from
May 6, 2024
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
15 changes: 12 additions & 3 deletions contexts/LeveragerContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import { debtManagerABI } from 'types/abi';
import useStETHNativeAPR from 'hooks/useStETHNativeAPR';
import useIsPermit from 'hooks/useIsPermit';
import { gasLimit } from 'utils/gas';
import useContractVersion from 'hooks/useContractVersion';

type Params<T extends ExtractAbiFunctionNames<typeof debtManagerABI>> = AbiParametersToPrimitiveTypes<
ExtractAbiFunction<typeof debtManagerABI, T>['inputs']
Expand Down Expand Up @@ -198,6 +199,7 @@ export const LeveragerContextProvider: FC<PropsWithChildren> = ({ children }) =>
const stETHNativeAPR = useStETHNativeAPR();

const minLeverageRatio = 1;
const contractVersion = useContractVersion();

const [leverageStatus, setLeverageStatus] = useState<LeverageStatus>();

Expand Down Expand Up @@ -391,8 +393,14 @@ export const LeveragerContextProvider: FC<PropsWithChildren> = ({ children }) =>
);

const setCollateralSymbol = useCallback(
(collateralSymbol: string) => setBorrowSymbol(collateralSymbol),
[setBorrowSymbol],
(collateralSymbol: string) => {
const marketAccount = getMarketAccount(collateralSymbol);
setBorrowSymbol(collateralSymbol);
if (marketAccount && !marketAccount.isCollateral) {
return setErrorData({ status: true, message: t('Please set this asset as collateral in your dashboard') });
}
},
[getMarketAccount, setBorrowSymbol, t],
);

const setSecondaryOperation = useCallback((secondaryOperation: 'deposit' | 'withdraw') => {
Expand Down Expand Up @@ -798,7 +806,7 @@ export const LeveragerContextProvider: FC<PropsWithChildren> = ({ children }) =>
primaryType: 'Permit',
domain: {
name: who.startsWith('market') ? '' : await assetIn.read.name(opts),
version: '1',
version: await contractVersion(verifyingContract),
chainId: chain.id,
verifyingContract,
},
Expand Down Expand Up @@ -832,6 +840,7 @@ export const LeveragerContextProvider: FC<PropsWithChildren> = ({ children }) =>
[
assetIn,
chain.id,
contractVersion,
debtManager,
isPermit,
maIn,
Expand Down
1 change: 1 addition & 0 deletions contexts/OperationContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export const OperationContextProvider: FC<PropsWithChildren<Props>> = ({ args, c
const marketContract = useMarket(marketAccount?.market);
const ETHRouterContract = useETHRouter();
const { installmentsOptions, installmentsDetails } = useInstallmentsData({
operation,
qty,
date,
symbol: marketSymbol,
Expand Down
13 changes: 11 additions & 2 deletions hooks/useInstallmentsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import globalUtilization from '@exactly/lib/esm/interest-rate-model/globalUtiliz
import useAccountData from 'hooks/useAccountData';
import { INTERVAL } from 'utils/utils';
import useIRM from 'hooks/useIRM';
import { Operation } from 'types/Operation';

export default function useInstallmentsData({
operation,
qty,
date,
symbol,
installments,
}: {
operation: Operation;
qty: string;
date?: bigint;
symbol: string;
Expand All @@ -23,7 +26,13 @@ export default function useInstallmentsData({

const getDetails = useCallback(
(amount: bigint, installments_: bigint, firstMaturity: bigint) => {
if (amount === 0n || irmParameters === undefined || marketAccount === undefined) return;
if (
amount === 0n ||
irmParameters === undefined ||
marketAccount === undefined ||
operation !== 'borrowAtMaturity'
)
return;
const {
floatingUtilization,
totalFloatingBorrowAssets,
Expand Down Expand Up @@ -66,7 +75,7 @@ export default function useInstallmentsData({
effectiveRate,
};
},
[irmParameters, marketAccount],
[irmParameters, marketAccount, operation],
);

const installmentsOptions = useMemo(() => {
Expand Down
3 changes: 2 additions & 1 deletion i18n/es/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -632,5 +632,6 @@
" In {{installments}} installments": "En {{installments}} cuotas",
"Repay Amount": "Monto a Pagar",
"Join the waitlist": "Únete a la lista de espera",
"The first onchain debit & credit card.": "La primer tarjeta de débito y crédito onchain."
"The first onchain debit & credit card.": "La primer tarjeta de débito y crédito onchain.",
"Please set this asset as collateral in your dashboard": "Por favor, establece este activo como colateral en tu panel de control"
}
Loading