Skip to content

Commit

Permalink
(clean-up) uniswapLp avalanche chain/network
Browse files Browse the repository at this point in the history
  • Loading branch information
isreallee82 committed Jun 3, 2024
1 parent 69a1582 commit 8185014
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
24 changes: 13 additions & 11 deletions src/connectors/uniswap/uniswap.lp.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import {
} from './uniswap.lp.interfaces';
import * as math from 'mathjs';
import { getAddress } from 'ethers/lib/utils';
import { Avalanche } from '../../chains/avalanche/avalanche';

export class UniswapLPHelper {
protected ethereum: Ethereum;
protected chain: Ethereum | Avalanche;
protected chainId;
private _factory: string;
private _router: string;
Expand All @@ -32,17 +33,17 @@ export class UniswapLPHelper {
private _poolAbi: ContractInterface;
private _alphaRouter: AlphaRouter;
private tokenList: Record<string, Token> = {};
private _chain: string;
private _ready: boolean = false;
public abiDecoder: any;

constructor(chain: string, network: string) {
this.ethereum = Ethereum.getInstance(network);
this._chain = chain;
this.chainId = this.ethereum.chainId;
if (chain === 'ethereum') {
this.chain = Ethereum.getInstance(network);
} else this.chain = Avalanche.getInstance(network);
this.chainId = this.chain.chainId;
this._alphaRouter = new AlphaRouter({
chainId: this.chainId,
provider: this.ethereum.provider,
provider: this.chain.provider,
});
this._factory = UniswapConfig.config.uniswapV3FactoryAddress(network);
this._router =
Expand Down Expand Up @@ -103,12 +104,13 @@ export class UniswapLPHelper {
}

public async init() {
if (this._chain == 'ethereum' && !this.ethereum.ready())
const chainName = this.chain.chainName.toString();
if (!this.chain.ready())
throw new InitializationError(
SERVICE_UNITIALIZED_ERROR_MESSAGE('ETH'),
SERVICE_UNITIALIZED_ERROR_MESSAGE(chainName),
SERVICE_UNITIALIZED_ERROR_CODE
);
for (const token of this.ethereum.storedTokenList) {
for (const token of this.chain.storedTokenList) {
this.tokenList[token.address] = new Token(
this.chainId,
token.address,
Expand Down Expand Up @@ -158,7 +160,7 @@ export class UniswapLPHelper {
): Promise<PoolState> {
const poolContract = this.getPoolContract(
poolAddress,
this.ethereum.provider
this.chain.provider
);
const minTick = uniV3.nearestUsableTick(
uniV3.TickMath.MIN_TICK,
Expand Down Expand Up @@ -225,7 +227,7 @@ export class UniswapLPHelper {
const poolContract = new Contract(
uniV3.Pool.getAddress(token0, token1, fee, undefined, this._factory),
this.poolAbi,
this.ethereum.provider
this.chain.provider
);
for (
let x = Math.ceil(period / interval) * interval;
Expand Down
10 changes: 5 additions & 5 deletions src/connectors/uniswap/uniswap.lp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ export class UniswapLP extends UniswapLPHelper implements UniswapLPish {
}

async getPosition(tokenId: number): Promise<PositionInfo> {
const contract = this.getContract('nft', this.ethereum.provider);
const contract = this.getContract('nft', this.chain.provider);
const requests = [
contract.positions(tokenId),
this.collectFees(this.ethereum.provider, tokenId), // static call to calculate earned fees
this.collectFees(this.chain.provider, tokenId), // static call to calculate earned fees
];
const positionInfoReq = await Promise.allSettled(requests);
const rejected = positionInfoReq.filter(
Expand Down Expand Up @@ -141,7 +141,7 @@ export class UniswapLP extends UniswapLPHelper implements UniswapLPish {
);

if (nonce === undefined) {
nonce = await this.ethereum.nonceManager.getNextNonce(wallet.address);
nonce = await this.chain.nonceManager.getNextNonce(wallet.address);
}

const tx = await wallet.sendTransaction({
Expand Down Expand Up @@ -179,7 +179,7 @@ export class UniswapLP extends UniswapLPHelper implements UniswapLPish {
);

if (nonce === undefined) {
nonce = await this.ethereum.nonceManager.getNextNonce(wallet.address);
nonce = await this.chain.nonceManager.getNextNonce(wallet.address);
}

const tx = await contract.multicall(
Expand Down Expand Up @@ -219,7 +219,7 @@ export class UniswapLP extends UniswapLPHelper implements UniswapLPish {
} else {
collectData.recipient = wallet.address;
if (nonce === undefined) {
nonce = await this.ethereum.nonceManager.getNextNonce(wallet.address);
nonce = await this.chain.nonceManager.getNextNonce(wallet.address);
}
return await contract.collect(
collectData,
Expand Down

0 comments on commit 8185014

Please sign in to comment.