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

should be able to quote in native currency string #123

Merged
merged 3 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
allow for other strings to map to native currency objects
  • Loading branch information
snreynolds committed Jul 20, 2022
commit 2fd7facd1b132a6de4b463a2854fffe26ffc6f16
13 changes: 5 additions & 8 deletions cli/commands/quote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import dotenv from 'dotenv';
import _ from 'lodash';
import {
ID_TO_CHAIN_ID,
NativeCurrencyName,
nativeOnChain,
parseAmount,
SwapRoute,
} from '../../src';
import { TO_PROTOCOL } from '../../src/util';
import { NATIVE_NAMES_BY_ID, TO_PROTOCOL } from '../../src/util';
import { BaseCommand } from '../base-command';

dotenv.config();
Expand Down Expand Up @@ -86,17 +85,15 @@ export class Quote extends BaseCommand {
const router = this.router;

// if the tokenIn str is 'ETH' or 'MATIC' or NATIVE_CURRENCY_STRING, quote with the wrapped native currency
const tokenIn: Currency = (<any>Object)
.values(NativeCurrencyName)
.includes(tokenInStr)
const tokenIn: Currency = NATIVE_NAMES_BY_ID[chainId]!.includes(tokenInStr)
? nativeOnChain(chainId)
: (await tokenProvider.getTokens([tokenInStr])).getTokenByAddress(
tokenInStr
)!;

const tokenOut: Currency = (<any>Object)
.values(NativeCurrencyName)
.includes(tokenOutStr)
const tokenOut: Currency = NATIVE_NAMES_BY_ID[chainId]!.includes(
tokenOutStr
)
? nativeOnChain(chainId)
: (await tokenProvider.getTokens([tokenOutStr])).getTokenByAddress(
tokenOutStr
Expand Down
58 changes: 57 additions & 1 deletion src/util/chains.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Currency, Ether, NativeCurrency, Token } from '@uniswap/sdk-core';

import { WGLMR_MOONBEAM, WXDAI_GNOSIS } from '../providers';

export enum ChainId {
MAINNET = 1,
ROPSTEN = 3,
Expand Down Expand Up @@ -129,6 +129,62 @@ export enum NativeCurrencyName {
GNOSIS = 'XDAI',
MOONBEAM = 'GLMR',
}
export const NATIVE_NAMES_BY_ID: { [chainId: number]: string[] } = {
[ChainId.MAINNET]: [
'ETH',
'ETHER',
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
],
[ChainId.RINKEBY]: [
'ETH',
'ETHER',
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
],
[ChainId.GÖRLI]: [
'ETH',
'ETHER',
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
],
[ChainId.KOVAN]: [
'ETH',
'ETHER',
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
],
[ChainId.ROPSTEN]: [
'ETH',
'ETHER',
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
],
[ChainId.OPTIMISM]: [
'ETH',
'ETHER',
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
],
[ChainId.OPTIMISTIC_KOVAN]: [
'ETH',
'ETHER',
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
],
[ChainId.ARBITRUM_ONE]: [
'ETH',
'ETHER',
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
],
[ChainId.ARBITRUM_RINKEBY]: [
'ETH',
'ETHER',
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
],
[ChainId.POLYGON]: ['MATIC', '0x0000000000000000000000000000000000001010'],
[ChainId.POLYGON_MUMBAI]: [
'MATIC',
'0x0000000000000000000000000000000000001010',
],
[ChainId.CELO]: ['CELO'],
[ChainId.CELO_ALFAJORES]: ['CELO'],
[ChainId.GNOSIS]: ['XDAI'],
[ChainId.MOONBEAM]: ['GLMR'],
};

export const NATIVE_CURRENCY: { [chainId: number]: NativeCurrencyName } = {
[ChainId.MAINNET]: NativeCurrencyName.ETHER,
Expand Down