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

[WIP] Add Arbitrum support #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/api/utils/coingecko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ export const ETH_CURRENCY_CODE = 'eth';
* @title CoinGeckoDataService
* @author Set Protocol
*
* A utility library for fetching token metadata and coin prices from Coingecko for Ethereum
* and Polygon chains
* A utility library for fetching token metadata and coin prices from Coingecko
* + Ethereum: (1)
* + Polygon (137)
* + Arbitrum (42161)
*/
export class CoinGeckoDataService {
chainId: number;
Expand Down Expand Up @@ -102,6 +104,9 @@ export class CoinGeckoDataService {
case 137:
this.tokenList = await this.fetchPolygonTokenList();
break;
case 42161:
this.tokenList = await this.fetchArbitrumTokenList();
break;
}
this.tokenMap = this.convertTokenListToAddressMap(this.tokenList);

Expand Down Expand Up @@ -136,6 +141,7 @@ export class CoinGeckoDataService {
switch (this.chainId) {
case 1: return 'ethereum';
case 137: return 'polygon-pos';
case 42161: return 'arbitrum';
default: return '';
}
}
Expand Down Expand Up @@ -244,4 +250,10 @@ export class CoinGeckoDataService {
const data = (await axios.get(url)).data;
return data;
}

private async fetchArbitrumTokenList(): Promise<CoinGeckoTokenData[]> {
const url = 'https://bridge.arbitrum.io/token-list-42161.json';
const response = await axios.get(url);
return response.data.tokens;
}
}
2 changes: 1 addition & 1 deletion src/assertions/CommonAssertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class CommonAssertions {
}

public isSupportedChainId(chainId: number) {
const validChainIds = [1, 137];
const validChainIds = [1, 137, 42161];

if ( !validChainIds.includes(chainId)) {
throw new Error(`Unsupported chainId: ${chainId}. Must be one of ${validChainIds}`);
Expand Down
41 changes: 41 additions & 0 deletions test/fixtures/tradeQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,47 @@ export const tradeQuoteFixtures = {
},
},

// Endpoint used by UniswapV3
arbitrumBridgeTokenRequest: 'https://bridge.arbitrum.io/token-list-42161.json',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

arbitrumBridgeTokenResponse: {
data: {
tokens: [{
'chainId': 42161,
'address': '0x0e15258734300290a651FdBAe8dEb039a8E7a2FA',
'name': 'Alchemy',
'symbol': 'ALCH',
'decimals': 18,
'logoURI': '',
'extensions': {
'l1Address': '0x0000A1c00009A619684135B824Ba02f7FbF3A572',
'l1GatewayAddress': '0xa3A7B6F88361F48403514059F1F16C8E78d60EeC',
},
}, {
'chainId': 42161,
'address': '0xBfa641051Ba0a0Ad1b0AcF549a89536A0D76472E',
'name': 'Badger',
'symbol': 'BADGER',
'decimals': 18,
'logoURI': '',
'extensions': {
'l1Address': '0x3472A5A71965499acd81997a54BBA8D852C6E53d',
'l1GatewayAddress': '0xa3A7B6F88361F48403514059F1F16C8E78d60EeC',
},
}, {
'chainId': 42161,
'address': '0x040d1EdC9569d4Bab2D15287Dc5A4F10F56a56B8',
'name': 'Balancer',
'symbol': 'BAL',
'decimals': 18,
'logoURI': '',
'extensions': {
'l1Address': '0xba100000625a3754423978a60c9317c58a424e3D',
'l1GatewayAddress': '0xa3A7B6F88361F48403514059F1F16C8E78d60EeC',
},
}],
},
},

coinGeckoPricesRequestEth: 'https://api.coingecko.com/api/v3/simple/token_price/ethereum?contract_addresses=0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2,0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2,0x0bc529c00c6401aef6d220be8c6ea1667f6ad93e&vs_currencies=usd,usd,usd',
coinGeckoPricesResponseEth: {
data: {
Expand Down