Skip to content

Commit

Permalink
(clean-up) uniswap avalanche chain/network
Browse files Browse the repository at this point in the history
  • Loading branch information
isreallee82 committed Jun 3, 2024
1 parent 288f8de commit ccb4cc0
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/connectors/uniswap/uniswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ export class Uniswap implements Uniswapish {
baseToken: Token,
quoteToken: Token,
amount: BigNumber,
allowedSlippage?: string
allowedSlippage?: string,
poolId?: string
): Promise<ExpectedTrade> {
const nativeTokenAmount: CurrencyAmount<Token> =
CurrencyAmount.fromRawAmount(baseToken, amount.toString());
Expand Down Expand Up @@ -246,7 +247,7 @@ export class Uniswap implements Uniswapish {
);
return { trade: route.trade, expectedAmount };
} else {
const pool = await this.getPool(baseToken, quoteToken, this._feeTier);
const pool = await this.getPool(baseToken, quoteToken, this._feeTier, poolId);
if (!pool) {
throw new UniswapishPriceError(
`priceSwapIn: no trade pair found for ${baseToken.address} to ${quoteToken.address}.`
Expand Down Expand Up @@ -291,7 +292,8 @@ export class Uniswap implements Uniswapish {
quoteToken: Token,
baseToken: Token,
amount: BigNumber,
allowedSlippage?: string
allowedSlippage?: string,
poolId?: string
): Promise<ExpectedTrade> {
const nativeTokenAmount: CurrencyAmount<Token> =
CurrencyAmount.fromRawAmount(baseToken, amount.toString());
Expand Down Expand Up @@ -325,7 +327,7 @@ export class Uniswap implements Uniswapish {
);
return { trade: route.trade, expectedAmount };
} else {
const pool = await this.getPool(quoteToken, baseToken, this._feeTier);
const pool = await this.getPool(quoteToken, baseToken, this._feeTier, poolId);
if (!pool) {
throw new UniswapishPriceError(
`priceSwapOut: no trade pair found for ${quoteToken.address} to ${baseToken.address}.`
Expand Down Expand Up @@ -426,20 +428,21 @@ export class Uniswap implements Uniswapish {
private async getPool(
tokenA: Token,
tokenB: Token,
feeTier: FeeAmount
feeTier: FeeAmount,
poolId?: string
): Promise<Pool | null> {
const uniswapFactory = new Contract(
this._factory,
IUniswapV3FactoryABI,
this.chain.provider
);
// Use Uniswap V3 factory to get pool address instead of `Pool.getAddress` to check if pool exists.
const poolAddress = await uniswapFactory.getPool(
const poolAddress = poolId || await uniswapFactory.getPool(
tokenA.address,
tokenB.address,
feeTier
);
if (poolAddress === constants.AddressZero) {
if (poolAddress === constants.AddressZero || poolAddress === undefined || poolAddress === '') {
return null;
}
const poolContract = new Contract(
Expand All @@ -448,16 +451,17 @@ export class Uniswap implements Uniswapish {
this.chain.provider
);

const [liquidity, slot0] = await Promise.all([
const [liquidity, slot0, fee] = await Promise.all([
poolContract.liquidity(),
poolContract.slot0(),
poolContract.fee(),
]);
const [sqrtPriceX96, tick] = slot0;

const pool = new Pool(
tokenA,
tokenB,
this._feeTier,
fee,
sqrtPriceX96,
liquidity,
tick
Expand Down

0 comments on commit ccb4cc0

Please sign in to comment.