Skip to content

Commit

Permalink
fix calc fee (#298)
Browse files Browse the repository at this point in the history
* fix calc fee

* patch

---------

Co-authored-by: Junlin <[email protected]>
  • Loading branch information
lanceaper and Junlin authored Jul 17, 2024
1 parent 661ccd1 commit 5334387
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aperture_finance/uniswap-v3-automation-sdk",
"version": "3.4.20",
"version": "3.4.21",
"description": "SDK for Aperture's Uniswap V3 automation platform",
"author": "Aperture Finance <[email protected]>",
"license": "MIT",
Expand Down
8 changes: 5 additions & 3 deletions src/viem/aggregator/optimalRebalanceV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,10 @@ export async function optimalRebalanceV2(
.mul(tokenPrices[1])
.div(10 ** position.token1.decimals);

if (token0USD.eq(0) || token1USD.eq(0)) {
getLogger().error('Invalid token USD value', {
const positionUSD = token0USD.add(token1USD);

if (positionUSD.eq(0)) {
getLogger().error('Invalid position USD value', {
poolAmountIn,
zeroForOne,
receive0,
Expand All @@ -142,13 +144,13 @@ export async function optimalRebalanceV2(
token1USD: token1USD.toFixed(5),
...logdata,
});

return {
feeBips: 0n,
feeUSD: '0',
};
}

const positionUSD = token0USD.add(token1USD);
return {
feeBips: BigInt(feeUSD.div(positionUSD).mul(feeCoefficient).toFixed(0)),
feeUSD: feeUSD.toFixed(5),
Expand Down

0 comments on commit 5334387

Please sign in to comment.