Skip to content
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

feat: MU03 support on Celo mainnet #103

Closed
wants to merge 12 commits into from
12 changes: 3 additions & 9 deletions src/components/input/TokenSelectField.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
import { useField } from 'formik'
import { useMemo } from 'react'
import { ChevronIcon } from 'src/components/Chevron'
import { Select } from 'src/components/input/Select'
import { TokenId, getTokenById, getTokenOptionsByChainId } from 'src/config/tokens'
import { TokenId, getTokenById } from 'src/config/tokens'
import { TokenIcon } from 'src/images/tokens/TokenIcon'
import { useNetwork } from 'wagmi'

type Props = {
name: string
label: string
onChange?: (optionValue: string) => void
tokenOptions: TokenId[]
}

const DEFAULT_VALUE = {
label: 'Select Token',
value: '',
}

export function TokenSelectField({ name, label, onChange }: Props) {
export function TokenSelectField({ name, label, onChange, tokenOptions }: Props) {
const [field, , helpers] = useField<string>(name)

const { chain } = useNetwork()
const tokenOptions = useMemo(() => {
return chain ? getTokenOptionsByChainId(chain.id) : Object.values(TokenId)
}, [chain])

const handleChange = (optionValue: string) => {
helpers.setValue(optionValue || '')
if (onChange) onChange(optionValue)
Expand Down
74 changes: 72 additions & 2 deletions src/config/exchanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,31 @@ export const AlfajoresExchanges: Exchange[] = [
'0x87D61dA3d668797786D73BC674F053f87111570d',
],
},
{
providerAddr: '0x9B64E8EaBD1a035b148cE970d3319c5C3Ad53EC3',
id: '0x3e6d9109df536ba3f4c166e598bdfe132dca06573a54ca40c2b6f23ac6bd6cc6',
assets: [
'0x10c892A6EC43a53E45D0B916B4b7D383B1b78C0F',
'0x87D61dA3d668797786D73BC674F053f87111570d',
],
},
{
providerAddr: '0x9B64E8EaBD1a035b148cE970d3319c5C3Ad53EC3',
id: '0xcfaa6be9334ee54fda94f2cfdf4c8bc376f24ce008ab9559b2a06b9fc388e78c',
assets: [
'0xE4D517785D091D3c54818832dB6094bcc2744545',
'0x87D61dA3d668797786D73BC674F053f87111570d',
],
},
{
providerAddr: '0x9B64E8EaBD1a035b148cE970d3319c5C3Ad53EC3',
id: '0xe807b1ebe8b57ac4e5c1b8d51fcf8e3b21e919fd788bab807886c4f446a74d37',
assets: [
'0x10c892A6EC43a53E45D0B916B4b7D383B1b78C0F',
'0x6e673502c5b55F3169657C004e5797fFE5be6653',
],
},
]

export const BaklavaExchanges: Exchange[] = [
{
providerAddr: '0xFF9a3da00F42839CD6D33AD7adf50bCc97B41411',
Expand Down Expand Up @@ -75,8 +98,31 @@ export const BaklavaExchanges: Exchange[] = [
'0xD4079B322c392D6b196f90AA4c439fC2C16d6770',
],
},
{
providerAddr: '0xFF9a3da00F42839CD6D33AD7adf50bCc97B41411',
id: '0x3e6d9109df536ba3f4c166e598bdfe132dca06573a54ca40c2b6f23ac6bd6cc6',
assets: [
'0xf9ecE301247aD2CE21894941830A2470f4E774ca',
'0xD4079B322c392D6b196f90AA4c439fC2C16d6770',
],
},
{
providerAddr: '0xFF9a3da00F42839CD6D33AD7adf50bCc97B41411',
id: '0xcfaa6be9334ee54fda94f2cfdf4c8bc376f24ce008ab9559b2a06b9fc388e78c',
assets: [
'0x6a0EEf2bed4C30Dc2CB42fe6c5f01F80f7EF16d1',
'0xD4079B322c392D6b196f90AA4c439fC2C16d6770',
],
},
{
providerAddr: '0xFF9a3da00F42839CD6D33AD7adf50bCc97B41411',
id: '0xe807b1ebe8b57ac4e5c1b8d51fcf8e3b21e919fd788bab807886c4f446a74d37',
assets: [
'0xf9ecE301247aD2CE21894941830A2470f4E774ca',
'0x6f90ac394b1F45290d3023e4Ba0203005cAF2A4B',
],
},
]

export const CeloExchanges: Exchange[] = [
{
providerAddr: '0x22d9db95E6Ae61c104A7B6F6C78D7993B94ec901',
Expand Down Expand Up @@ -110,6 +156,30 @@ export const CeloExchanges: Exchange[] = [
'0xEB466342C4d449BC9f53A865D5Cb90586f405215',
],
},
{
providerAddr: '0x22d9db95E6Ae61c104A7B6F6C78D7993B94ec901',
id: '0xf418803158d881fda22694067bf6479476cec22ecfeeca2f6a65a6259bdbb9c0',
assets: [
'0xD8763CBa276a3738E6DE85b4b3bF5FDed6D6cA73',
'0xEB466342C4d449BC9f53A865D5Cb90586f405215',
],
},
{
providerAddr: '0x22d9db95E6Ae61c104A7B6F6C78D7993B94ec901',
id: '0x40c8472edd23f2976b0503db2692e8f06f0eb52db690e84697cad36a6b44e2df',
assets: [
'0xe8537a3d056DA446677B9E9d6c5dB704EaAb4787',
'0xEB466342C4d449BC9f53A865D5Cb90586f405215',
],
},
{
providerAddr: '0x22d9db95E6Ae61c104A7B6F6C78D7993B94ec901',
id: '0xfca6d94b46122eb9a4b86cf9d3e1e856fea8a826d0fc26c5baf17c43fbaf0f48',
assets: [
'0xD8763CBa276a3738E6DE85b4b3bF5FDed6D6cA73',
'0x061cc5a2C863E0C1Cb404006D559dB18A34C762d',
],
},
]

export const MentoExchanges: Record<ChainId, Array<Exchange>> = {
Expand Down
41 changes: 40 additions & 1 deletion src/config/tokens.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ChainId } from 'src/config/chains'
import { MentoExchanges } from 'src/config/exchanges'
import { Color } from 'src/styles/Color'
import { areAddressesEqual } from 'src/utils/addresses'

Expand All @@ -20,6 +21,7 @@ export enum TokenId {
cEUR = 'cEUR',
cREAL = 'cREAL',
axlUSDC = 'axlUSDC',
axlEUROC = 'axlEUROC',
}

export const NativeStableTokenIds = [TokenId.cUSD, TokenId.cEUR, TokenId.cREAL]
Expand Down Expand Up @@ -62,12 +64,21 @@ export const axlUSDC: Token = Object.freeze({
decimals: 6,
})

export const axlEUROC: Token = Object.freeze({
id: TokenId.axlEUROC,
symbol: TokenId.axlEUROC,
name: 'Axelar EUROC',
color: Color.usdcBlue, // TODO: Change to EUROC
decimals: 6,
})

export const Tokens: Record<TokenId, Token> = {
CELO,
cUSD,
cEUR,
cREAL,
axlUSDC,
axlEUROC,
}

export const TokenAddresses: Record<ChainId, Record<TokenId, Address>> = Object.freeze({
Expand All @@ -77,20 +88,23 @@ export const TokenAddresses: Record<ChainId, Record<TokenId, Address>> = Object.
[TokenId.cEUR]: '0x10c892A6EC43a53E45D0B916B4b7D383B1b78C0F',
[TokenId.cREAL]: '0xE4D517785D091D3c54818832dB6094bcc2744545',
[TokenId.axlUSDC]: '0x87D61dA3d668797786D73BC674F053f87111570d',
[TokenId.axlEUROC]: '0x6e673502c5b55F3169657C004e5797fFE5be6653',
},
[ChainId.Baklava]: {
[TokenId.CELO]: '0xdDc9bE57f553fe75752D61606B94CBD7e0264eF8',
[TokenId.cUSD]: '0x62492A644A588FD904270BeD06ad52B9abfEA1aE',
[TokenId.cEUR]: '0xf9ecE301247aD2CE21894941830A2470f4E774ca',
[TokenId.cREAL]: '0x6a0EEf2bed4C30Dc2CB42fe6c5f01F80f7EF16d1',
[TokenId.axlUSDC]: '0xD4079B322c392D6b196f90AA4c439fC2C16d6770',
[TokenId.axlEUROC]: '0x6f90ac394b1F45290d3023e4Ba0203005cAF2A4B',
},
[ChainId.Celo]: {
[TokenId.CELO]: '0x471EcE3750Da237f93B8E339c536989b8978a438',
[TokenId.cUSD]: '0x765DE816845861e75A25fCA122bb6898B8B1282a',
[TokenId.cEUR]: '0xD8763CBa276a3738E6DE85b4b3bF5FDed6D6cA73',
[TokenId.cREAL]: '0xe8537a3d056DA446677B9E9d6c5dB704EaAb4787',
[TokenId.axlUSDC]: '0xEB466342C4d449BC9f53A865D5Cb90586f405215',
[TokenId.axlEUROC]: '0x061cc5a2C863E0C1Cb404006D559dB18A34C762d',
},
})

Expand All @@ -106,9 +120,34 @@ export function isNativeStableToken(tokenId: string) {
return NativeStableTokenIds.includes(tokenId as TokenId)
}

export function isSwappable(token_1: string, token_2: string, chainId: number) {
const exchanges = MentoExchanges[chainId as ChainId]

if (!exchanges) return false

if (token_1 === token_2) return false

return exchanges.some(
(obj) =>
obj.assets.includes(getTokenAddress(token_1 as TokenId, chainId)) &&
obj.assets.includes(getTokenAddress(token_2 as TokenId, chainId))
)
}

export function getSwappableTokenOptions(token: string, chainId: ChainId) {
return getTokenOptionsByChainId(chainId)
.filter((tkn) => isSwappable(tkn, token, chainId))
.filter((tkn) => token !== tkn)
}

export function getTokenOptionsByChainId(chainId: ChainId): TokenId[] {
const tokensForChain = TokenAddresses[chainId]
return tokensForChain ? (Object.keys(TokenAddresses[chainId]) as TokenId[]) : []

return tokensForChain
? Object.entries(tokensForChain)
.filter(([, tokenAddress]) => tokenAddress !== '') // Allows incomplete 'TokenAddresses' list i.e When tokens are not on all chains
.map(([tokenId]) => tokenId as TokenId)
: []
}

export function getTokenById(id: string): Token | null {
Expand Down
Loading