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 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
27 changes: 17 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,23 @@ Calldata: 0x414bf389000000000000000000000000dac17f958d2ee523a2206206994597c13d83
./bin/cli quote --tokenIn 0x2791bca1f2de4661ed88a30c99a7a9449aa84174 --tokenOut 0x7ceb23fd6bc0add59e62ac25578270cff1b9f619 --amount 5 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 137
```

## Celo Mainnet

```
./bin/cli quote --tokenIn CELO --tokenOut 0x765DE816845861e75A25fCA122bb6898B8B1282a --amount 5 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 42220
```

## Adding a new Chain

The main components to complete are:
* Deploy contracts on chain, add the pools to subgraph
* Populate v3 providers in `src/providers/v3/subgraph-provider` and `src/providers/v3/static-subgraph-provider`
* Populate chainId and addresses in `src/util/chains.ts` and `src/util/addresses.ts`
* Populate token providers in `src/providers/caching-token-provider` and `src/providers/token-provider.ts`
* Populate gas constants in `src/routers/alpha-router/gas-models/*`
* Populate bases in `src/routers/legacy-router/bases.ts`
* Populate `test/integ/routers/alpha-router/alpha-router.integration.test.ts` and `src/providers/v2/static-subgraph-provider.ts`
* Populate `src/routers/alpha-router/*`
* Add a log to `/CHANGELOG.md`
* Run `npm run integ-test` successfully

- Deploy contracts on chain, add the pools to subgraph
- Populate v3 providers in `src/providers/v3/subgraph-provider` and `src/providers/v3/static-subgraph-provider`
- Populate chainId and addresses in `src/util/chains.ts` and `src/util/addresses.ts`
- Populate token providers in `src/providers/caching-token-provider` and `src/providers/token-provider.ts`
- Populate gas constants in `src/routers/alpha-router/gas-models/*`
- Populate bases in `src/routers/legacy-router/bases.ts`
- Populate `test/integ/routers/alpha-router/alpha-router.integration.test.ts` and `src/providers/v2/static-subgraph-provider.ts`
- Populate `src/routers/alpha-router/*`
- Add a log to `/CHANGELOG.md`
- Run `npm run integ-test` successfully
29 changes: 14 additions & 15 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 @@ -85,20 +84,20 @@ export class Quote extends BaseCommand {
const tokenProvider = this.tokenProvider;
const router = this.router;

const tokenAccessor = await tokenProvider.getTokens([
tokenInStr,
tokenOutStr,
]);
// if the tokenIn str is 'ETH' or 'MATIC' or in NATIVE_NAMES_BY_ID
const tokenIn: Currency = NATIVE_NAMES_BY_ID[chainId]!.includes(tokenInStr)
? nativeOnChain(chainId)
: (await tokenProvider.getTokens([tokenInStr])).getTokenByAddress(
tokenInStr
)!;

// if the tokenIn str is 'ETH' or 'MATIC' or NATIVE_CURRENCY_STRING
const tokenIn: Currency =
tokenInStr in NativeCurrencyName
? nativeOnChain(chainId)
: tokenAccessor.getTokenByAddress(tokenInStr)!;
const tokenOut: Currency =
tokenOutStr in NativeCurrencyName
? nativeOnChain(chainId)
: tokenAccessor.getTokenByAddress(tokenOutStr)!;
const tokenOut: Currency = NATIVE_NAMES_BY_ID[chainId]!.includes(
tokenOutStr
)
? nativeOnChain(chainId)
: (await tokenProvider.getTokens([tokenOutStr])).getTokenByAddress(
tokenOutStr
)!;

let swapRoutes: SwapRoute | null;
if (exactIn) {
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