-
Notifications
You must be signed in to change notification settings - Fork 13
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
Get rid of repeated web3.eth.getChainId() calls #32
Conversation
@@ -17,21 +17,23 @@ export abstract class Pair { | |||
public pairKey: string | null = null; | |||
public tokenA: Address = ""; | |||
public tokenB: Address = ""; | |||
protected swappaPairAddress: Address = ""; | |||
private swappaPairAddress: Address = ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make private now that the child classes do not need to set this directly anymore
|
||
public async init(): Promise<void> { | ||
const r = await this._init() | ||
this.pairKey = r.pairKey | ||
this.tokenA = r.tokenA | ||
this.tokenB = r.tokenB | ||
this.swappaPairAddress = r.swappaPairAddress |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constructor should have already set up the correct pair addr
@@ -25,6 +25,7 @@ export class RegistryUniswapV2 extends Registry { | |||
} | |||
|
|||
findPairs = async (tokenWhitelist: Address[]): Promise<Pair[]> => { | |||
const chainId = await this.web3.eth.getChainId() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make each registry as part of findPairs
grab the chainID exactly once, and instantiate all pairs with that chainId
@@ -17,12 +17,7 @@ interface AddressesByNetwork { | |||
alfajores?: Address, | |||
} | |||
|
|||
export const selectAddress = async (web3: Web3, addresses: AddressesByNetwork) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
selectAddress
is sync now that we require the chainId to be passed in directly
caller is responsible to make the minimal number of getChainId()
calls
Every single pair was making a getChainID() call to load its network address inside
init()
.This is unnecessary, lift it up to the registry level as part of
findPairs()
to retrieve the chain ID and pass into constructor of Pair.Make initialization faster and more scalable for thousands of pairs.
This also makes it easier for me to bulk instantiate and refresh all pairs now that the swappa pair address is not part of
async init()