Skip to content

Commit

Permalink
(fix) handle no router available on base
Browse files Browse the repository at this point in the history
  • Loading branch information
fengtality committed Jul 25, 2024
1 parent 9aff42d commit 187c3c6
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 45,709 deletions.
22 changes: 17 additions & 5 deletions src/connectors/uniswap/uniswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { getAddress } from 'ethers/lib/utils';
export class Uniswap implements Uniswapish {
private static _instances: { [name: string]: Uniswap };
private chain: Ethereum | Polygon;
private _alphaRouter: AlphaRouter;
private _alphaRouter: AlphaRouter | null;
private _router: string;
private _routerAbi: ContractInterface;
private _gasLimitEstimate: number;
Expand All @@ -67,10 +67,13 @@ export class Uniswap implements Uniswapish {
this.chainId = this.chain.chainId;
this._ttl = UniswapConfig.config.ttl;
this._maximumHops = UniswapConfig.config.maximumHops;
this._alphaRouter = new AlphaRouter({
chainId: this.chainId,
provider: this.chain.provider,
});
this._alphaRouter = null;
if (this.chainId !== 8453) {
this._alphaRouter = new AlphaRouter({
chainId: this.chainId,
provider: this.chain.provider,
});
}
this._routerAbi = routerAbi.abi;
this._gasLimitEstimate = UniswapConfig.config.gasLimitEstimate;
this._router = config.uniswapV3SmartOrderRouterAddress(network);
Expand Down Expand Up @@ -143,6 +146,9 @@ export class Uniswap implements Uniswapish {
* AlphaRouter instance.
*/
public get alphaRouter(): AlphaRouter {
if (this._alphaRouter === null) {
throw new Error('AlphaRouter is not initialized');
}
return this._alphaRouter;
}

Expand Down Expand Up @@ -219,6 +225,9 @@ export class Uniswap implements Uniswapish {
);

if (this._useRouter) {
if (this._alphaRouter === null) {
throw new Error('AlphaRouter is not initialized');
}
const route = await this._alphaRouter.route(
nativeTokenAmount,
quoteToken,
Expand Down Expand Up @@ -299,6 +308,9 @@ export class Uniswap implements Uniswapish {
);

if (this._useRouter) {
if (this._alphaRouter === null) {
throw new Error('AlphaRouter is not initialized');
}
const route = await this._alphaRouter.route(
nativeTokenAmount,
quoteToken,
Expand Down
10 changes: 1 addition & 9 deletions src/templates/ethereum.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,9 @@ networks:
chainID: 8453
nodeURL: https://mainnet.base.org
tokenListType: FILE
tokenListSource: /home/gateway/conf/lists/base_tokens_mainnet.json
tokenListSource: /home/gateway/conf/lists/base_uniswap_20240411.json
nativeCurrencySymbol: ETH
gasPriceRefreshInterval: 60
base-sepolia:
chainID: 84532
nodeURL: https://sepolia.base.org
tokenListType: FILE
tokenListSource: /home/gateway/conf/lists/base_tokens_sepolia.json
nativeCurrencySymbol: ETH
gasPriceRefreshInterval: 60


# if you use the gas assumptions below, your wallet needs >0.1 ETH balance for gas
gasLimitTransaction: 3000000
Expand Down
Loading

0 comments on commit 187c3c6

Please sign in to comment.