Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

feat: move shared contract addresses to shared repo #58

Merged
merged 9 commits into from
Jun 9, 2023

Conversation

cbachmeier
Copy link
Contributor

@cbachmeier cbachmeier commented Jun 8, 2023

We want to consolidate much of the repeated code in the UX and BE involved with launching on a new chain. This PR is to centralize a lot of the Uni contract addresses across chains in one place.

I've also restructured how these contracts are stored, so instead of a series of repeated strings such as SEPOLIA_V3_CORE_FACTORY_ADDRESSES without any programmatic method to enforce consistency, there is a new datatype ChainAddresses whose fields correspond to the related contract. There is a map CHAIN_TO_ADDRESSES_MAP which will return all the ChainAddresses for a given ChainId. This helps simplify a lot of the helper consts such as V3_CORE_FACTORY_ADDRESSES which is now simply a reduce function across all SUPPORTED_CHAINS.

Last change primarily affecting UX is I've swapped SupportedChainId for ChainId and now SUPPORTED_CHAINS is an array which is the subset of all available Chains where Uni addresses have been deployed. This is the format used by the BE and is more robust than the previous sole SupportedChainId. This will change will likely require some small refactoring on the UX but will have us closer aligned to the BE.

src/constants.ts Outdated
BNB = 56
}

export const SUPPORTED_CHAINS = [
ChainId.MAINNET,
ChainId.RINKEBY,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can get rid of some of these chains - theyre gone forever

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rinkeby, ropsten (i think on L2s too), and kovan as well - all test networks that dont exist anymore

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lynnshaoyu I brought these chains over from the BE repo, can we deprecate across the org?

Copy link
Contributor Author

@cbachmeier cbachmeier Jun 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confirmed offline that these can be removed across the org

@lynnshaoyu lynnshaoyu self-requested a review June 8, 2023 17:41
tickLensAddress: '0xd7f33bcdb21b359c8ee6f0251d30e94832baad07'
}

export const CHAIN_TO_ADDRESSES_MAP: Record<SupportedChainsType, ChainAddresses> = {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yay! this will make sor code referencing the addresses a lot simpler!

src/addresses.ts Outdated
v1MixedRouteQuoterAddress?: string
}

const DEFAULT_NETWORKS = [ChainId.MAINNET, ChainId.GOERLI, ChainId.SEPOLIA]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what makes a network default? slightly confused that sepolia is part of this when it doesn't use the DEFAULT_ADDRESSES unlike goerli and mainnet

Copy link
Contributor Author

@cbachmeier cbachmeier Jun 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good callout, it's mainly used in the constructSameAddressMap which I put Sepolia in as it shares a uni address, but this was a mistake as it doesn't share many address overlaps as you pointed out and additional ones such as ens registrar for example. I will remove it from DEFAULT_NETWORKS and instead append it to the UNI_ADDRESSES map individually

@cbachmeier cbachmeier marked this pull request as ready for review June 8, 2023 22:07
@cbachmeier cbachmeier changed the title [WIP] feat: move shared contract addresses to shared repo feat: move shared contract addresses to shared repo Jun 8, 2023
@cbachmeier
Copy link
Contributor Author

Take a look at #59 to see how a new chain's addresses (Avalanche) are added

Comment on lines +19 to +23
return DEFAULT_NETWORKS.concat(additionalNetworks).reduce<AddressMap>((memo, chainId) => {
memo[chainId] = address
return memo
}, {})
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the DEFAULT_NETWORKS piece a bit confusing personally--I know you've copied it from interface and divergent implementations would be a little annoying, but requiring explicit enumeration of the full set at runtime feels more predictable to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think the added clarity is worth the tradeoff of the redundancy of having to copy&paste Mainnet and Goerli in several locations? Could we address this in a different way such as renaming DEFAULT_NETWORKS?

@cbachmeier cbachmeier merged commit 08fdaaf into main Jun 9, 2023
@cbachmeier cbachmeier deleted the cab/chain_addresses branch June 9, 2023 21:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants