From d1f01b67f12c26457eafb88511668d42a54497cb Mon Sep 17 00:00:00 2001 From: Atatakai Date: Mon, 25 Mar 2024 21:46:31 +0400 Subject: [PATCH 1/3] Audit fixes --- .../ServiceState/1StepPreRegistration/index.jsx | 2 ++ .../ServiceState/2StepActiveRegistration/index.jsx | 6 +++++- .../components/ListServices/ServiceState/utils.jsx | 13 +++++++------ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/apps/autonolas-registry/components/ListServices/ServiceState/1StepPreRegistration/index.jsx b/apps/autonolas-registry/components/ListServices/ServiceState/1StepPreRegistration/index.jsx index ac3c5a33..07f374e7 100644 --- a/apps/autonolas-registry/components/ListServices/ServiceState/1StepPreRegistration/index.jsx +++ b/apps/autonolas-registry/components/ListServices/ServiceState/1StepPreRegistration/index.jsx @@ -39,6 +39,8 @@ export const PreRegistration = ({ account, chainId, serviceId, + // any amount if not ETH token substitute with 1 + amountToApprove: 1 }); } diff --git a/apps/autonolas-registry/components/ListServices/ServiceState/2StepActiveRegistration/index.jsx b/apps/autonolas-registry/components/ListServices/ServiceState/2StepActiveRegistration/index.jsx index 3a7a8b71..c02775cf 100644 --- a/apps/autonolas-registry/components/ListServices/ServiceState/2StepActiveRegistration/index.jsx +++ b/apps/autonolas-registry/components/ListServices/ServiceState/2StepActiveRegistration/index.jsx @@ -1,5 +1,6 @@ import { useState, useEffect } from 'react'; import PropTypes from 'prop-types'; +import { ethers } from 'ethers' import { Divider, Typography } from 'antd'; import { convertToEth, @@ -132,7 +133,10 @@ export const ActiveRegistration = ({ // if not eth, check if the user has sufficient token balance // and if not, approve the token if (!isEthToken && !isSvm) { - await checkAndApproveToken({ account, chainId, serviceId }); + await checkAndApproveToken({ account, chainId, serviceId, amountToApprove: ethers.utils.parseUnits( + `${totalBonds}`, + 'ether', + )}); } // check if the agent instances are valid diff --git a/apps/autonolas-registry/components/ListServices/ServiceState/utils.jsx b/apps/autonolas-registry/components/ListServices/ServiceState/utils.jsx index 9f228f80..68c61ca5 100644 --- a/apps/autonolas-registry/components/ListServices/ServiceState/utils.jsx +++ b/apps/autonolas-registry/components/ListServices/ServiceState/utils.jsx @@ -68,7 +68,7 @@ export const getServiceOwner = async (id) => { return response; }; -const hasSufficientTokenRequest = async ({ account, chainId, serviceId }) => { +const hasSufficientTokenRequest = async ({ account, chainId, serviceId, amountToApprove }) => { /** * - fetch the token address from the serviceId * - fetch the allowance of the token using the token address @@ -78,19 +78,19 @@ const hasSufficientTokenRequest = async ({ account, chainId, serviceId }) => { const response = await contract.methods .allowance(account, ADDRESSES[chainId].serviceRegistryTokenUtility) .call(); - return !(ethers.BigNumber.from(response) < ethers.constants.MaxUint256); + return !(ethers.BigNumber.from(response) < amountToApprove); }; /** * Approves token */ -const approveToken = async ({ account, chainId, serviceId }) => { +const approveToken = async ({ account, chainId, serviceId, amountToApprove }) => { const { token } = await getTokenDetailsRequest(serviceId); const contract = getGenericErc20Contract(token); const fn = contract.methods .approve( ADDRESSES[chainId].serviceRegistryTokenUtility, - ethers.constants.MaxUint256, + amountToApprove, ) .send({ from: account }); @@ -98,15 +98,16 @@ const approveToken = async ({ account, chainId, serviceId }) => { return response; }; -export const checkAndApproveToken = async ({ account, chainId, serviceId }) => { +export const checkAndApproveToken = async ({ account, chainId, serviceId, amountToApprove }) => { const hasTokenBalance = await hasSufficientTokenRequest({ account, chainId, serviceId, + amountToApprove }); if (!hasTokenBalance) { - const response = await approveToken({ account, chainId, serviceId }); + const response = await approveToken({ account, chainId, serviceId, amountToApprove }); return response; } From f1562668acf5a9acded9204017af1470d0167056 Mon Sep 17 00:00:00 2001 From: Oaksprout <66292936+oaksprout@users.noreply.github.com> Date: Mon, 25 Mar 2024 18:49:07 +0000 Subject: [PATCH 2/3] Update index.jsx --- .../ListServices/ServiceState/1StepPreRegistration/index.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/autonolas-registry/components/ListServices/ServiceState/1StepPreRegistration/index.jsx b/apps/autonolas-registry/components/ListServices/ServiceState/1StepPreRegistration/index.jsx index 07f374e7..0aa4ce9f 100644 --- a/apps/autonolas-registry/components/ListServices/ServiceState/1StepPreRegistration/index.jsx +++ b/apps/autonolas-registry/components/ListServices/ServiceState/1StepPreRegistration/index.jsx @@ -39,7 +39,7 @@ export const PreRegistration = ({ account, chainId, serviceId, - // any amount if not ETH token substitute with 1 + // any amount, if not ETH token substitute with 1 amountToApprove: 1 }); } From 4870fc0b163757f1f22d3e70a0ed9b19354344b6 Mon Sep 17 00:00:00 2001 From: Atatakai Date: Tue, 26 Mar 2024 14:19:28 +0400 Subject: [PATCH 3/3] Add formatting --- .../ServiceState/2StepActiveRegistration/index.jsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/autonolas-registry/components/ListServices/ServiceState/2StepActiveRegistration/index.jsx b/apps/autonolas-registry/components/ListServices/ServiceState/2StepActiveRegistration/index.jsx index c02775cf..bef81019 100644 --- a/apps/autonolas-registry/components/ListServices/ServiceState/2StepActiveRegistration/index.jsx +++ b/apps/autonolas-registry/components/ListServices/ServiceState/2StepActiveRegistration/index.jsx @@ -1,6 +1,6 @@ import { useState, useEffect } from 'react'; import PropTypes from 'prop-types'; -import { ethers } from 'ethers' +import { ethers } from 'ethers'; import { Divider, Typography } from 'antd'; import { convertToEth, @@ -133,10 +133,12 @@ export const ActiveRegistration = ({ // if not eth, check if the user has sufficient token balance // and if not, approve the token if (!isEthToken && !isSvm) { - await checkAndApproveToken({ account, chainId, serviceId, amountToApprove: ethers.utils.parseUnits( - `${totalBonds}`, - 'ether', - )}); + await checkAndApproveToken({ + account, + chainId, + serviceId, + amountToApprove: ethers.utils.parseUnits(`${totalBonds}`, 'ether'), + }); } // check if the agent instances are valid