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

fix/dont use router in uniswaplp #153

Merged
merged 5 commits into from
Jul 14, 2023
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
5 changes: 3 additions & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ jobs:
- name: Build project
run: yarn build

- name: Replace testnet nodeURL for local hardhat node
- name: Replace testnet nodeURL and lists path
run: |
mkdir conf db
cp -r src/templates/* conf
cp -rf src/templates/* conf
sed -i 's|/home/gateway/conf/lists/|conf/lists/|g' ./conf/*.yml
sed -i 's/https:\/\/rpc.ankr.com\/eth_goerli/http:\/\/127.0.0.1:8545\//g' ./conf/ethereum.yml
sed -i 's/https:\/\/arbitrum-rinkeby.infura.io\/v3/http:\/\/127.0.0.1:8545\//g' ./conf/ethereum.yml
sed -i 's/https:\/\/rpc.ankr.com\/optimism/http:\/\/127.0.0.1:8545\//g' ./conf/ethereum.yml
Expand Down
57 changes: 7 additions & 50 deletions src/connectors/uniswap/uniswap.lp.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,9 @@ import {
} from '../../services/error-handler';
import { UniswapConfig } from './uniswap.config';
import { Contract, ContractInterface } from '@ethersproject/contracts';
import {
Token,
Fraction,
CurrencyAmount,
Percent,
Price,
} from '@uniswap/sdk-core';
import { Token, CurrencyAmount, Percent, Price } from '@uniswap/sdk-core';
import * as uniV3 from '@uniswap/v3-sdk';
import {
AlphaRouter,
SwapToRatioResponse,
SwapToRatioStatus,
} from '@uniswap/smart-order-router';
import { AlphaRouter } from '@uniswap/smart-order-router';
import { providers, Wallet, Signer, utils } from 'ethers';
import { percentRegexp } from '../../services/config-manager-v2';
import { Ethereum } from '../../chains/ethereum/ethereum';
Expand Down Expand Up @@ -384,44 +374,11 @@ export class UniswapLPHelper {
useFullPrecision: true,
});

const autorouterRoute: SwapToRatioResponse =
await this.alphaRouter.routeToRatio(
CurrencyAmount.fromRawAmount(
token0,
utils.parseUnits(amount0, token0.decimals).toString()
),
CurrencyAmount.fromRawAmount(
token1,
utils.parseUnits(amount1, token1.decimals).toString()
),
position,
{
ratioErrorTolerance: new Fraction(1, 100),
maxIterations: 6,
},
{
swapOptions: swapOptions,
addLiquidityOptions: addLiquidityOptions,
}
);

let methodParameters: uniV3.MethodParameters;
let swapReq = false;
if (autorouterRoute.status === SwapToRatioStatus.SUCCESS) {
swapReq = true;
methodParameters = autorouterRoute.result
.methodParameters as uniV3.MethodParameters;
} else if (autorouterRoute.status === SwapToRatioStatus.NO_SWAP_NEEDED) {
methodParameters = uniV3.NonfungiblePositionManager.addCallParameters(
position,
{ ...swapOptions, ...addLiquidityOptions }
);
} else {
throw new Error(
`Unable to add liquidity - ${SwapToRatioStatus[autorouterRoute.status]}`
);
}
return { ...methodParameters, swapRequired: swapReq };
const methodParameters = uniV3.NonfungiblePositionManager.addCallParameters(
position,
{ ...swapOptions, ...addLiquidityOptions }
);
return { ...methodParameters, swapRequired: false };
}

async reducePositionHelper(
Expand Down