Skip to content

Commit

Permalink
Merge pull request #193 from the-standard/202403-round
Browse files Browse the repository at this point in the history
feat: swap and debt rounding
  • Loading branch information
ZakMooney authored Apr 2, 2024
2 parents fc3bd15 + 0f164f6 commit b4d01c9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
39 changes: 19 additions & 20 deletions src/components/collateral/Debt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const Debt: React.FC<DebtProps> = ({
const [activeElement, setActiveElement] = useState(1);
// const { windowWidth, windowHeight } = useWindowSize();
const { address } = useAccount();
const [amount, setAmount] = useState<any>(0);
const [ amount, setAmount ] = useState<any>(BigInt(0));
const { vaultAddress } = useVaultAddressStore();
// const { vaultStore }: any = useVaultStore();
const { arbitrumsEuroAddress, arbitrumSepoliasEuroAddress } =
Expand All @@ -65,8 +65,6 @@ const Debt: React.FC<DebtProps> = ({
getCounter(1);
};

const amountInWei = parseEther(amount.toString());

const debtValue: any = ethers.BigNumber.from(currentVault?.status?.minted);

const eurosAddress = chainId === arbitrumSepolia.id ?
Expand Down Expand Up @@ -108,8 +106,8 @@ const Debt: React.FC<DebtProps> = ({

const handleAmount = (e: any) => {
if (Number(e.target.value) < 10n ** 21n) {
setAmount(Number(e.target.value));
getGreyBarUserInput(e.target.value);
setAmount(parseEther(e.target.value.toString()))
getGreyBarUserInput(formatEther(parseEther(e.target.value.toString())));
}
};

Expand All @@ -125,7 +123,7 @@ const Debt: React.FC<DebtProps> = ({
}

useEffect(() => {
setAmount(0);
setAmount(BigInt(0));
setActiveElement(4);
handleInputFocus();
getOperationType(4);
Expand All @@ -135,7 +133,7 @@ const Debt: React.FC<DebtProps> = ({
useEffect(() => {
return () => {
// Perform any cleanup tasks or actions you want before the component unmounts
setAmount(0);
setAmount(BigInt(0));
getGreyBarUserInput(0);
};
}, []);
Expand All @@ -149,7 +147,7 @@ const Debt: React.FC<DebtProps> = ({
abi: smartVaultAbi,
address: vaultAddress as any,
functionName: "mint",
args: [address as any, amountInWei],
args: [address as any, amount],
});

// getSnackBar('SUCCESS', 'Success!');
Expand All @@ -173,7 +171,7 @@ const Debt: React.FC<DebtProps> = ({
const handleCloseYield = () => setYieldModalOpen(false);

const burnFeeRate: bigint = currentVault?.burnFeeRate;
const repayFee = amountInWei * burnFeeRate / HUNDRED_PC;
const repayFee = amount * burnFeeRate / HUNDRED_PC;

const handleApprove = async () => {
setStage('APPROVE');
Expand Down Expand Up @@ -216,7 +214,7 @@ const Debt: React.FC<DebtProps> = ({
abi: smartVaultAbi,
address: vaultAddress as any,
functionName: "burn",
args: [amountInWei],
args: [amount],
});

// getSnackBar('SUCCESS', 'Success!');
Expand Down Expand Up @@ -312,15 +310,15 @@ const Debt: React.FC<DebtProps> = ({
};

const calculateRepaymentWithFee = () => {
return amountInWei + calculateRateAmount(amountInWei, currentVault?.burnFeeRate);
return amount + calculateRateAmount(amount, currentVault?.burnFeeRate);
}

const handleDebtAction = () => {
if (activeElement === 4) {
getCircularProgress(true);
handleMint();
} else {
if (amountInWei > currentVault?.status.minted) {
if (amount > currentVault?.status.minted) {
alert('Repayment amount exceeds debt in vault');
} else if (eurosWalletBalance < calculateRepaymentWithFee()) {
alert('Repayment amount exceeds your EUROs balance');
Expand Down Expand Up @@ -363,15 +361,15 @@ const Debt: React.FC<DebtProps> = ({
},
{
key: `Minting Fee (${toPercentage(currentVault?.mintFeeRate)}%)`,
value: formatEther(calculateRateAmount(amountInWei, currentVault?.mintFeeRate)),
value: formatEther(calculateRateAmount(amount, currentVault?.mintFeeRate)),
},
{
key: "Borrowing",
value: formatEther(amountInWei + calculateRateAmount(amountInWei, currentVault?.mintFeeRate)),
value: formatEther(amount + calculateRateAmount(amount, currentVault?.mintFeeRate)),
},
{
key: "Receiving",
value: amount,
value: formatEther(amount),
},
];
const repayValues = [
Expand All @@ -381,15 +379,15 @@ const Debt: React.FC<DebtProps> = ({
},
{
key: `Burn Fee (${toPercentage(currentVault?.burnFeeRate)}%)`,
value: formatEther(calculateRateAmount(amountInWei, currentVault?.burnFeeRate)),
value: formatEther(calculateRateAmount(amount, currentVault?.burnFeeRate)),
},
{
key: "Actual Repayment",
value: amount,
key: "Repaying",
value: formatEther(amount),
},
{
key: "Send",
value: formatEther(amountInWei + calculateRateAmount(amountInWei, currentVault?.burnFeeRate)),
key: "Sending",
value: formatEther(amount + calculateRateAmount(amount, currentVault?.burnFeeRate)),
},
];

Expand Down Expand Up @@ -634,6 +632,7 @@ const Debt: React.FC<DebtProps> = ({
marginLeft: "10px",
}}
clickFunction={handleDebtAction}
isDisabled={isPending}
>
{activeElement === 4 ? "Withdraw" : "Repay"}
</Button>
Expand Down
5 changes: 1 addition & 4 deletions src/components/collateral/actions/Swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const Swap: React.FC<SwapProps> = ({
setSwapLoading(true);
const swapIn = symbol;
const swapOut = receiveAsset;
const swapAmount = parseUnits(amount.toString(), decimals);
const swapAmount = parseUnits(amount.toString(), decimals).toString();
const response = await axios.get(
`https://smart-vault-api.thestandard.io/estimate_swap?in=${swapIn}&out=${swapOut}&amount=${swapAmount}`
);
Expand Down Expand Up @@ -170,9 +170,6 @@ const Swap: React.FC<SwapProps> = ({
handleAmount({ target: { value: formatted } });
};

console.log(123123, amount)
console.log(345345, receiveAmountFormatted)

if (vaultStore.status.version !== 1 && vaultStore.status.version !== 2) {
return (
<Box>
Expand Down

0 comments on commit b4d01c9

Please sign in to comment.