Skip to content

Commit

Permalink
Merge pull request #3 from Aperture-Finance/scroll-dev
Browse files Browse the repository at this point in the history
Add Scroll mainnet to Aperture's uniswap smart order router npmjs pac…
  • Loading branch information
gnarlycow authored Jan 25, 2024
2 parents 9a3a0cd + 2900a23 commit 96b79fa
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aperture_finance/uniswap-smart-order-router",
"version": "0.2.0",
"version": "0.3.0",
"description": "Uniswap Smart Order Router",
"main": "build/main/index.js",
"typings": "build/main/index.d.ts",
Expand Down
30 changes: 30 additions & 0 deletions src/providers/token-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,30 @@ export const DAI_MANTA_PACIFIC = new Token(
'Dai Stablecoin'
);

export const USDC_SCROLL = new Token(
ChainId.SCROLL,
'0x06eFdBFf2a14a7c8E15944D1F4A48F9F95F663A4',
6,
'USDC',
'USD Coin'
);

export const USDT_SCROLL = new Token(
ChainId.SCROLL,
'0xf55BEC9cafDbE8730f096Aa55dad6D22d44099Df',
6,
'USDT',
'Tether USD'
);

export const DAI_SCROLL = new Token(
ChainId.SCROLL,
'0xcA77eB3fEFe3725Dc33bccB54eDEFc3D9f764f97',
18,
'DAI',
'Dai Stablecoin'
);

export class TokenProvider implements ITokenProvider {
constructor(
private chainId: ChainId,
Expand Down Expand Up @@ -774,6 +798,8 @@ export const DAI_ON = (chainId: ChainId): Token => {
return DAI_AVAX;
case ChainId.MANTA_PACIFIC:
return DAI_MANTA_PACIFIC;
case ChainId.SCROLL:
return DAI_SCROLL;
default:
throw new Error(`Chain id: ${chainId} not supported`);
}
Expand All @@ -795,6 +821,8 @@ export const USDT_ON = (chainId: ChainId): Token => {
return USDT_BNB;
case ChainId.MANTA_PACIFIC:
return USDT_MANTA_PACIFIC;
case ChainId.SCROLL:
return USDT_SCROLL;
default:
throw new Error(`Chain id: ${chainId} not supported`);
}
Expand Down Expand Up @@ -836,6 +864,8 @@ export const USDC_ON = (chainId: ChainId): Token => {
return USDC_MANTA_PACIFIC_TESTNET;
case ChainId.MANTA_PACIFIC:
return USDC_MANTA_PACIFIC;
case ChainId.SCROLL:
return USDC_SCROLL;
default:
throw new Error(`Chain id: ${chainId} not supported`);
}
Expand Down
1 change: 1 addition & 0 deletions src/providers/v2/static-subgraph-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const BASES_TO_CHECK_TRADES_AGAINST: ChainTokenList = {
[ChainId.BASE]: [],
[ChainId.MANTA_PACIFIC_TESTNET]: [],
[ChainId.MANTA_PACIFIC]: [],
[ChainId.SCROLL]: [],
};

/**
Expand Down
9 changes: 9 additions & 0 deletions src/providers/v3/static-subgraph-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
DAI_OPTIMISM,
DAI_OPTIMISM_GOERLI,
DAI_POLYGON_MUMBAI,
DAI_SCROLL,
ETH_BNB,
OP_OPTIMISM,
USDC_ARBITRUM,
Expand All @@ -47,6 +48,7 @@ import {
USDC_OPTIMISM,
USDC_OPTIMISM_GOERLI,
USDC_POLYGON,
USDC_SCROLL,
USDC_SEPOLIA,
USDT_ARBITRUM,
USDT_BNB,
Expand All @@ -55,6 +57,7 @@ import {
USDT_MANTA_PACIFIC,
USDT_OPTIMISM,
USDT_OPTIMISM_GOERLI,
USDT_SCROLL,
WBTC_ARBITRUM,
WBTC_GNOSIS,
WBTC_GOERLI,
Expand Down Expand Up @@ -169,6 +172,12 @@ const BASES_TO_CHECK_TRADES_AGAINST: ChainTokenList = {
USDT_MANTA_PACIFIC,
DAI_MANTA_PACIFIC,
],
[ChainId.SCROLL]: [
WRAPPED_NATIVE_CURRENCY[ChainId.SCROLL],
USDC_SCROLL,
DAI_SCROLL,
USDT_SCROLL,
],
};

/**
Expand Down
2 changes: 2 additions & 0 deletions src/providers/v3/subgraph-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ const SUBGRAPH_URL_BY_CHAIN: { [chainId in ChainId]?: string } = {
'https://d3lcl3uht06cq4.cloudfront.net/subgraphs/name/aperture/uniswap-v3',
[ChainId.MANTA_PACIFIC]:
'https://api.goldsky.com/api/public/project_clnz7akg41cv72ntv0uhyd3ai/subgraphs/aperture/uniswap-v3/gn',
[ChainId.SCROLL]:
'https://api.goldsky.com/api/public/project_clnz7akg41cv72ntv0uhyd3ai/subgraphs/aperture-scroll/uniswap-v3/gn',
};

const PAGE_SIZE = 1000; // 1k is max possible query size from subgraph.
Expand Down
1 change: 1 addition & 0 deletions src/routers/alpha-router/alpha-router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ export class AlphaRouter
case ChainId.OPTIMISM_GOERLI:
case ChainId.MANTA_PACIFIC:
case ChainId.MANTA_PACIFIC_TESTNET:
case ChainId.SCROLL:
this.onChainQuoteProvider = new OnChainQuoteProvider(
chainId,
provider,
Expand Down
4 changes: 4 additions & 0 deletions src/routers/alpha-router/gas-models/gas-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
DAI_OPTIMISM,
DAI_OPTIMISM_GOERLI,
DAI_POLYGON_MUMBAI,
DAI_SCROLL,
DAI_SEPOLIA,
USDC_ARBITRUM,
USDC_ARBITRUM_GOERLI,
Expand All @@ -30,6 +31,7 @@ import {
USDC_OPTIMISM,
USDC_OPTIMISM_GOERLI,
USDC_POLYGON,
USDC_SCROLL,
USDC_SEPOLIA,
USDT_ARBITRUM,
USDT_BNB,
Expand All @@ -38,6 +40,7 @@ import {
USDT_MANTA_PACIFIC,
USDT_OPTIMISM,
USDT_OPTIMISM_GOERLI,
USDT_SCROLL,
WBTC_GOERLI,
} from '../../../providers/token-provider';
import { IV2PoolProvider } from '../../../providers/v2/pool-provider';
Expand Down Expand Up @@ -85,6 +88,7 @@ export const usdGasTokensByChain: { [chainId in ChainId]?: Token[] } = {
USDC_MANTA_PACIFIC,
USDT_MANTA_PACIFIC,
],
[ChainId.SCROLL]: [DAI_SCROLL, USDC_SCROLL, USDT_SCROLL],
};

export type L1ToL2GasCosts = {
Expand Down
3 changes: 3 additions & 0 deletions src/routers/alpha-router/gas-models/v3/gas-costs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const BASE_SWAP_COST = (id: ChainId): BigNumber => {
case ChainId.BASE_GOERLI:
case ChainId.MANTA_PACIFIC_TESTNET:
case ChainId.MANTA_PACIFIC:
case ChainId.SCROLL:
return BigNumber.from(2000);
case ChainId.ARBITRUM_ONE:
case ChainId.ARBITRUM_GOERLI:
Expand Down Expand Up @@ -55,6 +56,7 @@ export const COST_PER_INIT_TICK = (id: ChainId): BigNumber => {
case ChainId.BASE_GOERLI:
case ChainId.MANTA_PACIFIC_TESTNET:
case ChainId.MANTA_PACIFIC:
case ChainId.SCROLL:
return BigNumber.from(31000);
case ChainId.ARBITRUM_ONE:
case ChainId.ARBITRUM_GOERLI:
Expand Down Expand Up @@ -85,6 +87,7 @@ export const COST_PER_HOP = (id: ChainId): BigNumber => {
case ChainId.BASE_GOERLI:
case ChainId.MANTA_PACIFIC_TESTNET:
case ChainId.MANTA_PACIFIC:
case ChainId.SCROLL:
return BigNumber.from(80000);
case ChainId.ARBITRUM_ONE:
case ChainId.ARBITRUM_GOERLI:
Expand Down
9 changes: 9 additions & 0 deletions src/routers/legacy-router/bases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ import {
DAI_BNB,
DAI_MAINNET,
DAI_MANTA_PACIFIC,
DAI_SCROLL,
ITokenProvider,
USDC_AVAX,
USDC_BASE,
USDC_BNB,
USDC_MAINNET,
USDC_MANTA_PACIFIC,
USDC_MANTA_PACIFIC_TESTNET,
USDC_SCROLL,
USDT_BNB,
USDT_MAINNET,
USDT_MANTA_PACIFIC,
USDT_SCROLL,
WBTC_MAINNET,
WMATIC_POLYGON,
WMATIC_POLYGON_MUMBAI,
Expand Down Expand Up @@ -82,6 +85,12 @@ export const BASES_TO_CHECK_TRADES_AGAINST = (
USDC_MANTA_PACIFIC,
USDT_MANTA_PACIFIC,
],
[ChainId.SCROLL]: [
WRAPPED_NATIVE_CURRENCY[ChainId.SCROLL]!,
USDC_SCROLL,
USDT_SCROLL,
DAI_SCROLL,
],
};
};

Expand Down
10 changes: 10 additions & 0 deletions src/util/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const V3_CORE_FACTORY_ADDRESSES: AddressMap = {
CHAIN_TO_ADDRESSES_MAP[ChainId.MANTA_PACIFIC_TESTNET].v3CoreFactoryAddress,
[ChainId.MANTA_PACIFIC]:
CHAIN_TO_ADDRESSES_MAP[ChainId.MANTA_PACIFIC].v3CoreFactoryAddress,
[ChainId.SCROLL]: CHAIN_TO_ADDRESSES_MAP[ChainId.SCROLL].v3CoreFactoryAddress,
// TODO: Gnosis + Moonbeam contracts to be deployed
};

Expand All @@ -56,6 +57,7 @@ export const QUOTER_V2_ADDRESSES: AddressMap = {
CHAIN_TO_ADDRESSES_MAP[ChainId.MANTA_PACIFIC_TESTNET].quoterAddress,
[ChainId.MANTA_PACIFIC]:
CHAIN_TO_ADDRESSES_MAP[ChainId.MANTA_PACIFIC].quoterAddress,
[ChainId.SCROLL]: CHAIN_TO_ADDRESSES_MAP[ChainId.SCROLL].quoterAddress,
// TODO: Gnosis + Moonbeam contracts to be deployed
};

Expand Down Expand Up @@ -86,6 +88,7 @@ export const UNISWAP_MULTICALL_ADDRESSES: AddressMap = {
CHAIN_TO_ADDRESSES_MAP[ChainId.MANTA_PACIFIC_TESTNET].multicallAddress,
[ChainId.MANTA_PACIFIC]:
CHAIN_TO_ADDRESSES_MAP[ChainId.MANTA_PACIFIC].multicallAddress,
[ChainId.SCROLL]: CHAIN_TO_ADDRESSES_MAP[ChainId.SCROLL].multicallAddress,
// TODO: Gnosis + Moonbeam contracts to be deployed
};

Expand Down Expand Up @@ -213,4 +216,11 @@ export const WETH9: {
'WETH',
'Wrapped Ether'
),
[ChainId.SCROLL]: new Token(
ChainId.SCROLL,
'0x5300000000000000000000000000000000000004',
18,
'WETH',
'Wrapped Ether'
),
};
14 changes: 14 additions & 0 deletions src/util/chain-to-addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export enum ChainId {
BASE = 8453,
MANTA_PACIFIC_TESTNET = 3441005,
MANTA_PACIFIC = 169,
SCROLL = 534352,
}

type ChainAddresses = {
Expand Down Expand Up @@ -170,6 +171,17 @@ const MANTA_PACIFIC_ADDRESSES: ChainAddresses = {
swapRouter02Address: '0x3488d5A2D0281f546e43435715C436b46Ec1C678',
};

const SCROLL_ADDRESSES: ChainAddresses = {
v3CoreFactoryAddress: '0x70C62C8b8e801124A4Aa81ce07b637A3e83cb919',
multicallAddress: '0xC1D2e074C38FdD5CA965000668420C80316F0915',
quoterAddress: '0x2566e082Cb1656d22BCbe5644F5b997D194b5299',
v3MigratorAddress: '0xF00577B5Dd0DA227298E954Ed11356F264Cf93d4',
nonfungiblePositionManagerAddress:
'0xB39002E4033b162fAc607fc3471E205FA2aE5967',
tickLensAddress: '0x85780e12e90D2a684eB8E7404c985b5B5c8ce7E9',
swapRouter02Address: '0xfc30937f5cDe93Df8d48aCAF7e6f5D8D8A31F636',
};

export const SUPPORTED_CHAINS = [
ChainId.MAINNET,
ChainId.OPTIMISM,
Expand All @@ -188,6 +200,7 @@ export const SUPPORTED_CHAINS = [
ChainId.BASE_GOERLI,
ChainId.MANTA_PACIFIC_TESTNET,
ChainId.MANTA_PACIFIC,
ChainId.SCROLL,
] as const;
export type SupportedChainsType = typeof SUPPORTED_CHAINS[number];

Expand All @@ -212,4 +225,5 @@ export const CHAIN_TO_ADDRESSES_MAP: Record<
[ChainId.BASE_GOERLI]: BASE_GOERLI_ADDRESSES,
[ChainId.MANTA_PACIFIC_TESTNET]: MANTA_PACIFIC_TESTNET_ADDRESSES,
[ChainId.MANTA_PACIFIC]: MANTA_PACIFIC_ADDRESSES,
[ChainId.SCROLL]: SCROLL_ADDRESSES,
};
21 changes: 21 additions & 0 deletions src/util/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const HAS_L1_FEE = [
ChainId.BASE_GOERLI,
ChainId.MANTA_PACIFIC_TESTNET,
ChainId.MANTA_PACIFIC,
ChainId.SCROLL,
];

export const NETWORKS_WITH_SAME_UNISWAP_ADDRESSES = [
Expand Down Expand Up @@ -64,6 +65,8 @@ export const ID_TO_CHAIN_ID = (id: number): ChainId => {
return ChainId.MANTA_PACIFIC_TESTNET;
case 169:
return ChainId.MANTA_PACIFIC;
case 534352:
return ChainId.SCROLL;
default:
throw new Error(`Unknown chain id: ${id}`);
}
Expand All @@ -89,6 +92,7 @@ export enum ChainName {
BASE_GOERLI = 'base-goerli',
MANTA_PACIFIC_TESTNET = 'manta-pacific-testnet',
MANTA_PACIFIC = 'manta-pacific',
SCROLL = 'scroll',
}

export enum NativeCurrencyName {
Expand Down Expand Up @@ -168,6 +172,11 @@ export const NATIVE_NAMES_BY_ID: { [chainId: number]: string[] } = {
'ETHER',
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
],
[ChainId.SCROLL]: [
'ETH',
'ETHER',
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
],
};

export const NATIVE_CURRENCY: { [chainId: number]: NativeCurrencyName } = {
Expand All @@ -189,6 +198,7 @@ export const NATIVE_CURRENCY: { [chainId: number]: NativeCurrencyName } = {
[ChainId.BASE]: NativeCurrencyName.ETHER,
[ChainId.MANTA_PACIFIC_TESTNET]: NativeCurrencyName.ETHER,
[ChainId.MANTA_PACIFIC]: NativeCurrencyName.ETHER,
[ChainId.SCROLL]: NativeCurrencyName.ETHER,
};

export const ID_TO_NETWORK_NAME = (id: number): ChainName => {
Expand Down Expand Up @@ -231,6 +241,8 @@ export const ID_TO_NETWORK_NAME = (id: number): ChainName => {
return ChainName.MANTA_PACIFIC_TESTNET;
case 169:
return ChainName.MANTA_PACIFIC;
case 534352:
return ChainName.SCROLL;
default:
throw new Error(`Unknown chain id: ${id}`);
}
Expand Down Expand Up @@ -274,6 +286,8 @@ export const ID_TO_PROVIDER = (id: ChainId): string => {
return process.env.JSON_RPC_PROVIDER_MANTA_PACIFIC_TESTNET!;
case ChainId.MANTA_PACIFIC:
return process.env.JSON_RPC_PROVIDER_MANTA_PACIFIC!;
case ChainId.SCROLL:
return process.env.JSON_RPC_PROVIDER_SCROLL!;
default:
throw new Error(`Chain id: ${id} not supported`);
}
Expand Down Expand Up @@ -415,6 +429,13 @@ export const WRAPPED_NATIVE_CURRENCY: { [chainId in ChainId]: Token } = {
'WETH',
'Wrapped Ether'
),
[ChainId.SCROLL]: new Token(
ChainId.SCROLL,
'0x5300000000000000000000000000000000000004',
18,
'WETH',
'Wrapped Ether'
),
};

function isMatic(
Expand Down
Loading

0 comments on commit 96b79fa

Please sign in to comment.