Skip to content

Commit

Permalink
Merge pull request #1046 from PrimeDAO/fix/1038-celo-token-allow-list
Browse files Browse the repository at this point in the history
1038 - feat(services): add allowList for "custom proxy" tokens
  • Loading branch information
hiaux0 authored May 30, 2022
2 parents afc1aea + 2f2ee16 commit ec49a08
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/services/TokenService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,30 @@ import TokenMetadataService from "services/TokenMetadataService";
import { AxiosService } from "services/axiosService";
import { TimingService } from "services/TimingService";

type AllowListTokenMap = Record<string, ITokenInfo>

const allowListTokenMap: AllowListTokenMap = {
/**
* FIXME: Find a way to validate custom proxy implementation.
* Celo token on Ethererum uses a custom proxy implementation
* https://etherscan.io/address/0xC95DC0ECEEC11aB8b2BFa1AfF3C223C5dC006fAD#readProxyContract
* Since we have not found a way to validate it programmatically, use this allow list.
*/
"0xC95DC0ECEEC11aB8b2BFa1AfF3C223C5dC006fAD": {
address: "0xC95DC0ECEEC11aB8b2BFa1AfF3C223C5dC006fAD",
name: "Celo",
symbol: "CELO",
decimals: 18,
logoURI: "https://s2.coinmarketcap.com/static/img/coins/64x64/5567.png",
},
};

function isAllowListToken(tokenAddress: string): boolean {
if (EthereumService.targetedNetwork !== "mainnet") return false;

return Object.keys(allowListTokenMap).includes(tokenAddress);
}

@autoinject
export class TokenService {

Expand Down Expand Up @@ -201,6 +225,9 @@ export class TokenService {
}

public async getTokenInfoFromAddress(tokenAddress: Address): Promise<ITokenInfo> {
if (isAllowListToken(tokenAddress)) {
return Promise.resolve(allowListTokenMap[tokenAddress]);
}

let resolver: (value: ITokenInfo | PromiseLike<ITokenInfo>) => void;
let rejector: (reason?: any) => void;
Expand Down Expand Up @@ -287,6 +314,10 @@ export class TokenService {
}

public async isERC20Token(tokenAddress: Address): Promise<boolean> {
if (isAllowListToken(tokenAddress)) {
return Promise.resolve(true);
}

let isOk = true;

TimingService.start(`isERC20Token-${tokenAddress}`);
Expand Down

1 comment on commit ec49a08

@vercel
Copy link

@vercel vercel bot commented on ec49a08 May 30, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.