Skip to content

Commit dd88b41

Browse files
authored
fix: cancel signer and 1 wei precision for non accuring collaterals (#2796)
1 parent e3e226b commit dd88b41

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

src/components/transactions/CancelCowOrder/CancelCowOrderActions.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import { useModalContext } from 'src/hooks/useModal';
66
import { ActionName, SwapActionFields, TransactionHistoryItem } from 'src/modules/history/types';
77
import { useRootStore } from 'src/store/root';
88
import { getErrorTextFromError, TxAction } from 'src/ui-config/errorMapping';
9-
import { wagmiConfig } from 'src/ui-config/wagmiConfig';
109
import { updateCowOrderStatus } from 'src/utils/swapAdapterHistory';
11-
import { getWalletClient } from 'wagmi/actions';
1210

1311
import { COW_ENV, getCowAdapter } from '../Swap/helpers/cow';
1412
import { TxActionsWrapper } from '../TxActionsWrapper';
@@ -32,15 +30,12 @@ export const CancelCowOrderActions = ({ cowOrder, blocked }: CancelCowOrderActio
3230
const adapter = await getCowAdapter(cowOrder.chainId);
3331
AdapterContext.getInstance().setAdapter(adapter);
3432
const orderBookApi = new OrderBookApi({ chainId: cowOrder.chainId, env: COW_ENV });
35-
const walletClient = await getWalletClient(wagmiConfig, { chainId: cowOrder.chainId });
36-
37-
if (!walletClient || !walletClient.account) {
38-
throw new Error('Wallet not connected for signing');
39-
}
33+
const signer = adapter.signer;
34+
if (!signer) throw new Error('Wallet not connected for signing');
4035
const { signature, signingScheme } = await OrderSigningUtils.signOrderCancellation(
4136
cowOrder.id,
4237
cowOrder.chainId,
43-
walletClient
38+
signer
4439
);
4540
await orderBookApi.sendSignedOrderCancellations({
4641
orderUids: [cowOrder.id],

src/components/transactions/Swap/modals/request/CollateralSwapModalContent.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { valueToBigNumber } from '@aave/math-utils';
12
import { SupportedChainId, WRAPPED_NATIVE_CURRENCIES } from '@cowprotocol/cow-sdk';
23
import { useQueryClient } from '@tanstack/react-query';
34
import {
@@ -158,14 +159,25 @@ const getTokensFrom = (
158159
)
159160
: undefined;
160161

162+
let balance = position.underlyingBalance;
163+
if (position.reserve.supplyAPY === '0') {
164+
// remove one wei from balance because is rounded up
165+
const balanceBN = valueToBigNumber(balance);
166+
const decimals = balanceBN.decimalPlaces();
167+
if (decimals && decimals > 15) {
168+
const oneWei = valueToBigNumber(1).dividedBy(10 ** (decimals ?? 18));
169+
balance = balanceBN.minus(oneWei).toString();
170+
}
171+
}
172+
161173
return {
162174
addressToSwap: position.reserve.aTokenAddress,
163175
addressForUsdPrice: position.reserve.aTokenAddress,
164176
underlyingAddress: position.reserve.underlyingAsset,
165177
decimals: baseToken.decimals,
166178
symbol: nativeToken?.symbol ?? baseToken.symbol,
167179
name: nativeToken?.name ?? baseToken.name,
168-
balance: position.underlyingBalance,
180+
balance,
169181
chainId,
170182
usdPrice: position.reserve.priceInUSD,
171183
supplyAPY: position.reserve.supplyAPY,

0 commit comments

Comments
 (0)