Skip to content

Commit

Permalink
Move token addresses to the tokens config file (#3418)
Browse files Browse the repository at this point in the history
* Move token addresses to the tokens config file

* Fixing files using old addresses

* Fix type errors

* Fix lido mock

---------

Co-authored-by: Alberto Gualis <[email protected]>
  • Loading branch information
timjrobinson and agualis authored May 24, 2023
1 parent 5b18123 commit 21823d4
Show file tree
Hide file tree
Showing 32 changed files with 121 additions and 128 deletions.
5 changes: 4 additions & 1 deletion src/components/cards/PairPriceGraph/PairPriceGraph.vue
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ const {
);
const equivalentTokenPairs = [
[appNetworkConfig.addresses.weth, appNetworkConfig.nativeAsset.address],
[
appNetworkConfig.tokens.Addresses.wNativeAsset,
appNetworkConfig.tokens.Addresses.nativeAsset,
],
];
const allChartValuesEqual = computed(() =>
Expand Down
4 changes: 0 additions & 4 deletions src/components/cards/SwapCard/SwapCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,6 @@ export default defineComponent({
setTokenOutAmount(assetOutAmount);
}
}
function switchToWETH() {
tokenInAddress.value = appNetworkConfig.addresses.weth;
}
function handlePreviewButton() {
swapping.resetSubmissionError();
modalSwapPreviewIsOpen.value = true;
Expand Down Expand Up @@ -447,7 +444,6 @@ export default defineComponent({
handlePreviewButton,
handlePreviewModalClose,
// methods
switchToWETH,
handleErrorButtonClick,
};
},
Expand Down
19 changes: 10 additions & 9 deletions src/components/cards/SwapCard/SwapRoute.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import BigNumber from 'bignumber.js';
import useNumbers, { FNumFormats } from '@/composables/useNumbers';
import { useTokens } from '@/providers/tokens.provider';
import { NATIVE_ASSET_ADDRESS } from '@/constants/tokens';
import {
NATIVE_ASSET_ADDRESS,
WRAPPED_NATIVE_ASSET_ADDRESS,
} from '@/constants/tokens';
import { isSameAddress } from '@/lib/utils';
import { SorReturn } from '@/lib/utils/balancer/helpers/sor/sorManager';
import useWeb3 from '@/services/web3/useWeb3';
import { networkSlug } from '@/composables/useNetwork';
interface Props {
Expand Down Expand Up @@ -46,7 +48,6 @@ const props = defineProps<Props>();
const { fNum } = useNumbers();
const { appNetworkConfig } = useWeb3();
const { getToken } = useTokens();
const visible = ref(false);
Expand Down Expand Up @@ -97,13 +98,13 @@ function getV2Routes(
addresses: string[]
): Route[] {
// ) {
const { addresses: constants } = appNetworkConfig;
addressIn =
addressIn === NATIVE_ASSET_ADDRESS ? constants.weth : getAddress(addressIn);
addressIn === NATIVE_ASSET_ADDRESS
? WRAPPED_NATIVE_ASSET_ADDRESS
: getAddress(addressIn);
addressOut =
addressOut === NATIVE_ASSET_ADDRESS
? constants.weth
? WRAPPED_NATIVE_ASSET_ADDRESS
: getAddress(addressOut);
if (
Expand Down Expand Up @@ -131,11 +132,11 @@ function getV2Routes(
if (rawPool) {
const tokenIn =
addresses[swap.assetInIndex] === AddressZero
? constants.weth
? WRAPPED_NATIVE_ASSET_ADDRESS
: getAddress(addresses[swap.assetInIndex]);
const tokenOut =
addresses[swap.assetOutIndex] === AddressZero
? constants.weth
? WRAPPED_NATIVE_ASSET_ADDRESS
: getAddress(addresses[swap.assetOutIndex]);
const isDirectSwap =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ const { networkSlug } = useNetwork();
/**
* COMPUTED
*/
const stETH = computed(() => getToken(networkConfig.addresses.stETH));
const wstETH = computed(() => getToken(networkConfig.addresses.wstETH));
const stETH = computed(() =>
getToken(networkConfig.tokens.Addresses.stETH || '')
);
const wstETH = computed(() =>
getToken(networkConfig.tokens.Addresses.wstETH || '')
);
</script>

<template>
Expand Down
14 changes: 9 additions & 5 deletions src/components/inputs/TokenSearchInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { useI18n } from 'vue-i18n';
import SelectTokenModal from '@/components/modals/SelectTokenModal/SelectTokenModal.vue';
import { useTokens } from '@/providers/tokens.provider';
import useVeBal from '@/composables/useVeBAL';
import { NATIVE_ASSET_ADDRESS, TOKENS } from '@/constants/tokens';
import {
NATIVE_ASSET_ADDRESS,
TOKENS,
WRAPPED_NATIVE_ASSET_ADDRESS,
} from '@/constants/tokens';
import { includesAddress } from '@/lib/utils';
import useWeb3 from '@/services/web3/useWeb3';
Expand Down Expand Up @@ -36,7 +40,7 @@ const selectTokenModal = ref(false);
* COMPOSABLES
*/
const { getToken, tokens, balances } = useTokens();
const { account, appNetworkConfig } = useWeb3();
const { account } = useWeb3();
const { veBalTokenInfo } = useVeBal();
const { t } = useI18n();
const { upToMediumBreakpoint } = useBreakpoints();
Expand Down Expand Up @@ -93,10 +97,10 @@ const selectableTokensAddresses = computed<string[]>(() => {
*/
function addToken(token: string) {
let _token = token;
// special case for ETH where we want it to filter as WETH regardless
// as ETH is the native asset
// special case for the native asset where we want it to filter as
// wrapped native asset regardless as the native asset can't be in pools
if (getAddress(token) === NATIVE_ASSET_ADDRESS) {
_token = appNetworkConfig.addresses.weth;
_token = WRAPPED_NATIVE_ASSET_ADDRESS;
}
// const newSelected = [...props.modelValue, _token];
emit('add', _token);
Expand Down
12 changes: 6 additions & 6 deletions src/components/tooltips/APRTooltip/APRTooltip.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,15 @@ describe('APRTooltip', () => {
tokenAprs: {
total: 166,
breakdown: {
[configService.network.addresses.wstETH]: 166,
[configService.network.tokens.Addresses.wstETH || '']: 166,
},
},
min: 166,
max: 166,
};
const poolMock: Pool = {
...EmptyPoolMock,
tokensList: [configService.network.addresses.wstETH],
tokensList: [configService.network.tokens.Addresses.wstETH || ''],
};
const { getByTestId } = renderComponent(APRTooltip, {
props: {
Expand All @@ -214,7 +214,7 @@ describe('APRTooltip', () => {
};
const poolMock: Pool = {
...EmptyPoolMock,
tokensList: [configService.network.addresses.stMATIC],
tokensList: [configService.network.tokens.Addresses.stMATIC || ''],
};
const { getByTestId } = renderComponent(APRTooltip, {
props: {
Expand All @@ -233,15 +233,15 @@ describe('APRTooltip', () => {
tokenAprs: {
total: 73,
breakdown: {
[configService.network.addresses.rETH]: 73,
[configService.network.tokens.Addresses.rETH || '']: 73,
},
},
min: 102,
max: 102,
};
const poolMock: Pool = {
...EmptyPoolMock,
tokensList: [configService.network.addresses.rETH],
tokensList: [configService.network.tokens.Addresses.rETH || ''],
};
const { getByTestId } = renderComponent(APRTooltip, {
props: {
Expand Down Expand Up @@ -270,7 +270,7 @@ describe('APRTooltip', () => {
};
const poolMock: Pool = {
...EmptyPoolMock,
tokensList: [configService.network.addresses.rETH],
tokensList: [configService.network.tokens.Addresses.rETH || ''],
};
const { getByTestId } = renderComponent(APRTooltip, {
props: {
Expand Down
4 changes: 1 addition & 3 deletions src/composables/swap/useSor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ describe('setSwapCost', () => {
const sorManager = new SorManager(
rpcProviderService.jsonProvider,
BigNumber.from(1),
1,
1,
'1'
1
);

const mockedSorManager = vi.mocked(sorManager);
Expand Down
15 changes: 5 additions & 10 deletions src/composables/swap/useSor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useI18n } from 'vue-i18n';

import { NATIVE_ASSET_ADDRESS } from '@/constants/tokens';
import { getBalancerSDK } from '@/dependencies/balancer-sdk';
import { bnum, isSameAddress } from '@/lib/utils';
import { bnum } from '@/lib/utils';
import {
SorManager,
SorReturn,
Expand Down Expand Up @@ -231,9 +231,7 @@ export default function useSor({
sorManager = new SorManager(
rpcProviderService.jsonProvider,
BigNumber.from(GAS_PRICE),
Number(MAX_POOLS),
configService.network.chainId,
configService.network.addresses.weth
Number(MAX_POOLS)
);

fetchPools();
Expand Down Expand Up @@ -299,9 +297,9 @@ export default function useSor({
// wstETH. This is a crude hack to replace token in/out address
// with wstETH so the index mapping works.
if (isStEthAddress(tokenInAddressInput.value))
tokenInAddress = configService.network.addresses.wstETH;
tokenInAddress = configService.network.tokens.Addresses.wstETH || '';
if (isStEthAddress(tokenOutAddressInput.value))
tokenOutAddress = configService.network.addresses.wstETH;
tokenOutAddress = configService.network.tokens.Addresses.wstETH || '';

const tokenInPosition = result.tokenAddresses.indexOf(
tokenInAddress.toLowerCase()
Expand Down Expand Up @@ -791,10 +789,7 @@ export default function useSor({
address: string;
isInputToken: boolean;
}): Promise<BigNumber> {
if (
isSameAddress(address, appNetworkConfig.addresses.stETH) &&
isMainnet.value
) {
if (isStEthAddress(address) && isMainnet.value) {
return convertStEthWrap({ amount, isWrap: isInputToken });
}
return amount;
Expand Down
5 changes: 4 additions & 1 deletion src/constants/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import { configService } from '@/services/config/config.service';
/**
* CONSTANTS
*/
export const NATIVE_ASSET_ADDRESS = configService.network.nativeAsset.address;
export const NATIVE_ASSET_ADDRESS =
configService.network.tokens.Addresses.nativeAsset;
export const WRAPPED_NATIVE_ASSET_ADDRESS =
configService.network.tokens.Addresses.wNativeAsset;
export const DEFAULT_TOKEN_DECIMALS = 18;

export const TOKENS = configService.network.tokens;
5 changes: 0 additions & 5 deletions src/lib/config/arbitrum/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ const contracts: Contracts = {
vault: arbitrum.Vault,
weightedPoolFactory: arbitrum.WeightedPoolFactory,
stablePoolFactory: '0x2433477A10FC5d31B9513C638F19eE85CaED53Fd',
weth: '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1',
stMATIC: '',
rETH: '0xEC70Dcb4A1EFa46b8F2D97C310C9c4790ba5ffA8',
stETH: '',
wstETH: '0x5979d7b546e38e414f7e9822514be443a4800529',
lidoRelayer: '',
balancerHelpers: arbitrum.BalancerHelpers,
batchRelayer: arbitrum.BalancerRelayer,
Expand Down
2 changes: 2 additions & 0 deletions src/lib/config/arbitrum/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const tokens: TokenConstants = {
wNativeAsset: '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1',
WETH: '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1',
BAL: '0x040d1EdC9569d4Bab2D15287Dc5A4F10F56a56B8',
rETH: '0xEC70Dcb4A1EFa46b8F2D97C310C9c4790ba5ffA8',
wstETH: '0x5979d7b546e38e414f7e9822514be443a4800529',
},
};

Expand Down
5 changes: 0 additions & 5 deletions src/lib/config/docker/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ const contracts: Contracts = {
vault: '0x293f6758Fe4a4343E367Ac8E6A697eC6315fBEd7',
weightedPoolFactory: '0xE48Aae4178612fdF77af25C83fa1099491A8AD1B',
stablePoolFactory: '0xb4F97F452D71C3bba3c30c554305A7250c08b23A',
weth: '0x6c37Fa9557C135dF4323004D3f0549f3e94F112D',
rETH: '0xae78736Cd615f374D3085123A210448E74Fc6393',
stMATIC: '',
stETH: '0xae7ab96520de3a18e5e111b5eaab095312d7fe84',
wstETH: '0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
lidoRelayer: '',
balancerHelpers: '',
batchRelayer: '',
Expand Down
5 changes: 0 additions & 5 deletions src/lib/config/gnosis-chain/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ const contracts: Contracts = {
vault: gnosis.Vault,
weightedPoolFactory: gnosis.WeightedPoolFactory,
stablePoolFactory: gnosis.StablePoolFactory,
weth: '0xe91d153e0b41518a2ce8dd3d7944fa863463a97d',
rETH: '',
stMATIC: '',
stETH: '',
wstETH: '',
lidoRelayer: '',
balancerHelpers: gnosis.BalancerHelpers,
batchRelayer: gnosis.BalancerRelayer,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/config/gnosis-chain/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const tokens: TokenConstants = {
},
Addresses: {
nativeAsset: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
wNativeAsset: '0xe91d153e0b41518a2ce8dd3d7944fa863463a97d',
wNativeAsset: '0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d',
WETH: '0x6A023CCd1ff6F2045C3309768eAd9E68F978f6e1',
BAL: '0x7eF541E2a22058048904fE5744f9c7E4C57AF717',
},
Expand Down
5 changes: 0 additions & 5 deletions src/lib/config/goerli/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ const contracts: Contracts = {
vault: goerli.Vault,
weightedPoolFactory: goerli.WeightedPoolFactory,
stablePoolFactory: '0x44afeb87c871D8fEA9398a026DeA2BD3A13F5769',
weth: '0xdFCeA9088c8A88A76FF74892C1457C17dfeef9C1',
rETH: '0x178E141a0E3b34152f73Ff610437A7bf9B83267A',
stMATIC: '0x3a58a54c066fdc0f2d55fc9c89f0415c92ebf3c4',
stETH: '0x1643E812aE58766192Cf7D2Cf9567dF2C37e9B7F',
wstETH: '0x6320cD32aA674d2898A68ec82e869385Fc5f7E2f',
lidoRelayer: goerli.LidoRelayer,
balancerHelpers: goerli.BalancerHelpers,
batchRelayer: goerli.BalancerRelayer,
Expand Down
4 changes: 4 additions & 0 deletions src/lib/config/goerli/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const tokens: TokenConstants = {
BAL: '0xfA8449189744799aD2AcE7e0EBAC8BB7575eff47',
bbaUSD: '0x13ACD41C585d7EbB4a9460f7C8f50BE60DC080Cd',
bbaUSDv2: '0x3d5981bdd8d3e49eb7bbdc1d2b156a3ee019c18e',
rETH: '0x178E141a0E3b34152f73Ff610437A7bf9B83267A',
stMATIC: '0x3a58a54c066fdc0f2d55fc9c89f0415c92ebf3c4',
stETH: '0x1643E812aE58766192Cf7D2Cf9567dF2C37e9B7F',
wstETH: '0x6320cD32aA674d2898A68ec82e869385Fc5f7E2f',
},
PriceChainMap: {
/**
Expand Down
5 changes: 0 additions & 5 deletions src/lib/config/mainnet/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ const contracts: Contracts = {
vault: mainnet.Vault,
weightedPoolFactory: mainnet.WeightedPoolFactory,
stablePoolFactory: '0xc66Ba2B6595D3613CCab350C886aCE23866EDe24',
weth: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
rETH: '0xae78736Cd615f374D3085123A210448E74Fc6393',
stMATIC: '',
stETH: '0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84',
wstETH: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
lidoRelayer: mainnet.LidoRelayer,
balancerHelpers: mainnet.BalancerHelpers,
batchRelayer: mainnet.BalancerRelayer,
Expand Down
3 changes: 3 additions & 0 deletions src/lib/config/mainnet/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const tokens: TokenConstants = {
BAL: '0xba100000625a3754423978a60c9317c58a424e3d',
bbaUSD: '0x7B50775383d3D6f0215A8F290f2C9e2eEBBEceb2',
bbaUSDv2: '0xA13a9247ea42D743238089903570127DdA72fE44',
rETH: '0xae78736Cd615f374D3085123A210448E74Fc6393',
stETH: '0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84',
wstETH: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
},
DisableInternalBalanceWithdrawals: [
'0xEb91861f8A4e1C12333F42DCE8fB0Ecdc28dA716',
Expand Down
5 changes: 0 additions & 5 deletions src/lib/config/optimism/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ const contracts: Contracts = {
vault: '',
weightedPoolFactory: optimism.WeightedPoolFactory,
stablePoolFactory: '',
weth: '',
rETH: '',
stMATIC: '',
stETH: '',
wstETH: '',
lidoRelayer: '',
balancerHelpers: '',
batchRelayer: optimism.BalancerRelayer,
Expand Down
5 changes: 0 additions & 5 deletions src/lib/config/polygon/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ const contracts: Contracts = {
vault: polygon.Vault,
weightedPoolFactory: polygon.WeightedPoolFactory,
stablePoolFactory: '0xc66Ba2B6595D3613CCab350C886aCE23866EDe24',
weth: '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270',
rETH: '0x0266F4F08D82372CF0FcbCCc0Ff74309089c74d1',
stMATIC: '0x3a58a54c066fdc0f2d55fc9c89f0415c92ebf3c4',
stETH: '',
wstETH: '',
lidoRelayer: '',
balancerHelpers: '0x94905e703fead7f0fd0eee355d267ee909784e6d',
batchRelayer: polygon.BalancerRelayer,
Expand Down
3 changes: 3 additions & 0 deletions src/lib/config/polygon/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const tokens: TokenConstants = {
wNativeAsset: '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270',
WETH: '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619',
BAL: '0x9a71012b13ca4d3d0cdc72a177df3ef03b0e76a3',
wstETH: '0x03b54a6e9a984069379fae1a4fc4dbae93b3bccd',
rETH: '0x0266F4F08D82372CF0FcbCCc0Ff74309089c74d1',
stMATIC: '0x3a58a54c066fdc0f2d55fc9c89f0415c92ebf3c4',
},
};

Expand Down
Loading

0 comments on commit 21823d4

Please sign in to comment.