Skip to content

Commit

Permalink
feat: avalanche
Browse files Browse the repository at this point in the history
  • Loading branch information
dev committed Mar 18, 2021
1 parent a45a075 commit 0b20e47
Show file tree
Hide file tree
Showing 14 changed files with 379 additions and 34,061 deletions.
4 changes: 2 additions & 2 deletions .env
@@ -1,3 +1,3 @@
REACT_APP_CHAIN_ID="1"
REACT_APP_CHAIN_ID="43113"
REACT_APP_GOOGLE_ANALYTICS_MEASUREMENT_ID=""
REACT_APP_NETWORK_URL=""
REACT_APP_NETWORK_URL="https://api.avax-test.network/ext/bc/C/rpc"
34,121 changes: 314 additions & 33,807 deletions package-lock.json

Large diffs are not rendered by default.

21 changes: 0 additions & 21 deletions src/components/MyActivityCard.tsx
Expand Up @@ -18,15 +18,6 @@ function MyActivityCard({ historicalPoolData }: Props): ReactElement | null {

const historicalFormattedData = historicalPoolData
? {
totalDepositsBTC: commify(
formatBNToString(historicalPoolData.totalDepositsBTC, 36, 6),
),
totalWithdrawalsBTC: commify(
formatBNToString(historicalPoolData.totalWithdrawalsBTC, 36, 6),
),
totalProfitBTC: commify(
formatBNToString(historicalPoolData.totalProfitBTC, 36, 6),
),
totalDepositsUSD: commify(
formatBNToString(historicalPoolData.totalDepositsUSD, 36, 2),
),
Expand All @@ -44,26 +35,14 @@ function MyActivityCard({ historicalPoolData }: Props): ReactElement | null {
<h4>{t("myActivity")}</h4>
{historicalFormattedData ? (
<div className="activityTable">
<div key="deposits-btc">
<span className="label">BTC {t("deposit")}</span>
<span>{historicalFormattedData.totalDepositsBTC}</span>
</div>
<div key="deposits-usd">
<span className="label">USD {t("deposit")}</span>
<span>{`$${historicalFormattedData.totalDepositsUSD}`}</span>
</div>
<div key="withdrawals-btc">
<span className="label">BTC {t("withdrawal")}</span>
<span>{historicalFormattedData.totalWithdrawalsBTC}</span>
</div>
<div key="withdrawals-usd">
<span className="label">USD {t("withdrawal")}</span>
<span>{`$${historicalFormattedData.totalWithdrawalsUSD}`}</span>
</div>
<div key="profit-btc">
<span className="label">BTC {t("profit")}</span>
<span>{historicalFormattedData.totalProfitBTC}</span>
</div>
<div key="profit-usd">
<span className="label">USD {t("profit")}</span>
<span>{`$${historicalFormattedData.totalProfitUSD}`}</span>
Expand Down
3 changes: 2 additions & 1 deletion src/connectors/index.ts
Expand Up @@ -17,6 +17,7 @@ if (typeof NETWORK_URL === "undefined") {

export const network = new NetworkConnector({
urls: { [NETWORK_CHAIN_ID]: NETWORK_URL },
defaultChainId: NETWORK_CHAIN_ID,
})

// eslint-disable-next-line @typescript-eslint/unbound-method
Expand All @@ -30,7 +31,7 @@ export function getNetworkLibrary(): Web3Provider {
export const injected = new InjectedConnector({
// mainnet, ropsten, rinkeby, goerli, kovan, local buidler
// see: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md
supportedChainIds: [1, 3, 4, 5, 42, 31337],
supportedChainIds: [43113, 43114],
})

export const walletconnect = new WalletConnectConnector({
Expand Down
5 changes: 0 additions & 5 deletions src/constants/abis/swap.json
Expand Up @@ -373,11 +373,6 @@
"internalType": "uint256",
"name": "deadline",
"type": "uint256"
},
{
"internalType": "bytes32[]",
"name": "merkleProof",
"type": "bytes32[]"
}
],
"name": "addLiquidity",
Expand Down
145 changes: 24 additions & 121 deletions src/constants/index.ts
@@ -1,25 +1,21 @@
import daiLogo from "../assets/icons/dai.svg"
import renbtcLogo from "../assets/icons/renbtc.svg"
import saddleLogo from "../assets/icons/logo.svg"
import sbtcLogo from "../assets/icons/sbtc.svg"
import susdLogo from "../assets/icons/susd.svg"
import tbtcLogo from "../assets/icons/tbtc.svg"
import usdcLogo from "../assets/icons/usdc.svg"
import usdtLogo from "../assets/icons/usdt.svg"
import wbtcLogo from "../assets/icons/wbtc.svg"

export const NetworkContextName = "NETWORK"
export const BTC_POOL_NAME = "BTC Pool"
export const STABLECOIN_POOL_NAME = "Stablecoin Pool"
export type PoolName = typeof BTC_POOL_NAME | typeof STABLECOIN_POOL_NAME
export type PoolName = typeof STABLECOIN_POOL_NAME

export const GAS_PRICE = 470

export enum ChainId {
MAINNET = 1,
AVALANCHE = 1,
// ROPSTEN = 3,
// RINKEBY = 4,
// GÖRLI = 5,
// KOVAN = 42,
HARDHAT = 31337,
FUJI = 43113,
}

export class Token {
Expand Down Expand Up @@ -47,46 +43,25 @@ export class Token {
}
}

export const BLOCK_TIME = 15000
export const BLOCK_TIME = 3000

export const STABLECOIN_SWAP_ADDRESSES: { [chainId in ChainId]: string } = {
[ChainId.MAINNET]: "0x4f6A43Ad7cba042606dECaCA730d4CE0A57ac62e",
[ChainId.HARDHAT]: "0x1613beB3B2C4f22Ee086B2b38C1476A3cE7f78E8",
}

export const BTC_SWAP_ADDRESSES: { [chainId in ChainId]: string } = {
[ChainId.MAINNET]: "0x4f6A43Ad7cba042606dECaCA730d4CE0A57ac62e",
[ChainId.HARDHAT]: "0x851356ae760d987E095750cCeb3bC6014560891C",
[ChainId.AVALANCHE]: "0x4f6A43Ad7cba042606dECaCA730d4CE0A57ac62e",
[ChainId.FUJI]: "0xa818a4E693132CFf3E9677474a1F57f0F7D2fe8d",
}

export const MERKLETREE_DATA: { [chainId in ChainId]: string } = {
[ChainId.MAINNET]: "mainnetTestAccounts.json",
[ChainId.HARDHAT]: "hardhat.json",
[ChainId.AVALANCHE]: "AVALANCHETestAccounts.json",
[ChainId.FUJI]: "FUJI.json",
}

export const STABLECOIN_SWAP_TOKEN_CONTRACT_ADDRESSES: {
[chainId in ChainId]: string
} = {
[ChainId.MAINNET]: "",
[ChainId.HARDHAT]: "0x6A358FD7B7700887b0cd974202CdF93208F793E2",
}

export const BTC_SWAP_TOKEN_CONTRACT_ADDRESSES: {
[chainId in ChainId]: string
} = {
[ChainId.MAINNET]: "0xC28DF698475dEC994BE00C9C9D8658A548e6304F",
[ChainId.HARDHAT]: "0xB955b6c65Ff69bfe07A557aa385055282b8a5eA3",
[ChainId.AVALANCHE]: "",
[ChainId.FUJI]: "0x748e67353306b3183E8Bc9C27fE60a017E99d4D4",
}

export const BTC_SWAP_TOKEN = new Token(
BTC_SWAP_TOKEN_CONTRACT_ADDRESSES,
18,
"saddleBTC",
"saddlebtc",
"Saddle TBTC/WBTC/RENBTC/SBTC",
saddleLogo,
)

export const STABLECOIN_SWAP_TOKEN = new Token(
STABLECOIN_SWAP_TOKEN_CONTRACT_ADDRESSES,
18,
Expand All @@ -98,8 +73,8 @@ export const STABLECOIN_SWAP_TOKEN = new Token(

// Stablecoins
const DAI_CONTRACT_ADDRESSES: { [chainId in ChainId]: string } = {
[ChainId.MAINNET]: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
[ChainId.HARDHAT]: "0x5FbDB2315678afecb367f032d93F642f64180aa3",
[ChainId.AVALANCHE]: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
[ChainId.FUJI]: "0xBF967f44dB44380CD38B76AaD850f8B2f98a29aD",
}
export const DAI = new Token(
DAI_CONTRACT_ADDRESSES,
Expand All @@ -111,8 +86,8 @@ export const DAI = new Token(
)

const USDC_CONTRACT_ADDRESSES: { [chainId in ChainId]: string } = {
[ChainId.MAINNET]: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
[ChainId.HARDHAT]: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
[ChainId.AVALANCHE]: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
[ChainId.FUJI]: "0x6275B63A4eE560004c34431e573314426906cee9",
}
export const USDC = new Token(
USDC_CONTRACT_ADDRESSES,
Expand All @@ -124,8 +99,8 @@ export const USDC = new Token(
)

const USDT_CONTRACT_ADDRESSES: { [chainId in ChainId]: string } = {
[ChainId.MAINNET]: "0xdac17f958d2ee523a2206206994597c13d831ec7",
[ChainId.HARDHAT]: "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0",
[ChainId.AVALANCHE]: "0xdac17f958d2ee523a2206206994597c13d831ec7",
[ChainId.FUJI]: "0xa6c062F1F8EAbEC4384bB2c2f65abBf710cd2998",
}
export const USDT = new Token(
USDT_CONTRACT_ADDRESSES,
Expand All @@ -136,80 +111,12 @@ export const USDT = new Token(
usdtLogo,
)

const SUSD_CONTRACT_ADDRESSES: { [chainId in ChainId]: string } = {
[ChainId.MAINNET]: "0x57ab1ec28d129707052df4df418d58a2d46d5f51",
[ChainId.HARDHAT]: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9",
}
export const SUSD = new Token(
SUSD_CONTRACT_ADDRESSES,
18,
"SUSD",
"nusd",
"sUSD",
susdLogo,
)

export const STABLECOIN_POOL_TOKENS = [DAI, USDC, USDT, SUSD]

// Tokenized BTC
const TBTC_CONTRACT_ADDRESSES: { [chainId in ChainId]: string } = {
[ChainId.MAINNET]: "0x8daebade922df735c38c80c7ebd708af50815faa",
[ChainId.HARDHAT]: "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9",
}
export const TBTC = new Token(
TBTC_CONTRACT_ADDRESSES,
18,
"TBTC",
"tbtc",
"tBTC",
tbtcLogo,
)

const WBTC_CONTRACT_ADDRESSES: { [chainId in ChainId]: string } = {
[ChainId.MAINNET]: "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599",
[ChainId.HARDHAT]: "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707",
}
export const WBTC = new Token(
WBTC_CONTRACT_ADDRESSES,
8,
"WBTC",
"wrapped-bitcoin",
"WBTC",
wbtcLogo,
)

const RENBTC_CONTRACT_ADDRESSES: { [chainId in ChainId]: string } = {
[ChainId.MAINNET]: "0xeb4c2781e4eba804ce9a9803c67d0893436bb27d",
[ChainId.HARDHAT]: "0x0165878A594ca255338adfa4d48449f69242Eb8F",
}
export const RENBTC = new Token(
RENBTC_CONTRACT_ADDRESSES,
8,
"RENBTC",
"renbtc",
"renBTC",
renbtcLogo,
)

const SBTC_CONTRACT_ADDRESSES: { [chainId in ChainId]: string } = {
[ChainId.MAINNET]: "0xfe18be6b3bd88a2d2a7f928d00292e7a9963cfc6",
[ChainId.HARDHAT]: "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853",
}
export const SBTC = new Token(
SBTC_CONTRACT_ADDRESSES,
18,
"SBTC",
"sbtc",
"sBTC",
sbtcLogo,
)

export const BTC_POOL_TOKENS = [TBTC, WBTC, RENBTC, SBTC]
export const STABLECOIN_POOL_TOKENS = [DAI, USDC, USDT]

// maps a symbol string to a token object
export const TOKENS_MAP: {
[symbol: string]: Token
} = STABLECOIN_POOL_TOKENS.concat(BTC_POOL_TOKENS).reduce(
} = STABLECOIN_POOL_TOKENS.reduce(
(acc, token) => ({ ...acc, [token.symbol]: token }),
{},
)
Expand All @@ -220,10 +127,6 @@ export const POOLS_MAP: {
poolTokens: Token[]
}
} = {
[BTC_POOL_NAME]: {
lpToken: BTC_SWAP_TOKEN,
poolTokens: BTC_POOL_TOKENS,
},
[STABLECOIN_POOL_NAME]: {
lpToken: STABLECOIN_SWAP_TOKEN,
poolTokens: STABLECOIN_POOL_TOKENS,
Expand All @@ -239,12 +142,12 @@ export const TRANSACTION_TYPES = {
export const POOL_FEE_PRECISION = 10

export const DEPLOYED_BLOCK: { [chainId in ChainId]: number } = {
[ChainId.MAINNET]: 11656944,
[ChainId.HARDHAT]: 0,
[ChainId.AVALANCHE]: 11656944,
[ChainId.FUJI]: 10000,
}

export const POOL_STATS_URL: { [chainId in ChainId]: string } = {
[ChainId.MAINNET]: "https://ipfs.saddle.exchange/pool-stats.json",
[ChainId.HARDHAT]:
[ChainId.AVALANCHE]: "https://ipfs.saddle.exchange/pool-stats.json",
[ChainId.FUJI]:
"https://mehmeta-team-bucket.storage.fleek.co/pool-stats-dev.json",
}
1 change: 0 additions & 1 deletion src/hooks/useApproveAndDeposit.ts
Expand Up @@ -137,7 +137,6 @@ export function useApproveAndDeposit(
POOL.poolTokens.map(({ symbol }) => state[symbol].valueSafe),
minToMint,
Math.round(new Date().getTime() / 1000 + 60 * deadline),
[],
{
gasPrice,
},
Expand Down
6 changes: 1 addition & 5 deletions src/hooks/useApproveAndSwap.ts
@@ -1,6 +1,4 @@
import {
BTC_POOL_NAME,
BTC_POOL_TOKENS,
PoolName,
STABLECOIN_POOL_NAME,
STABLECOIN_POOL_TOKENS,
Expand Down Expand Up @@ -53,9 +51,7 @@ export function useApproveAndSwap(
infiniteApproval,
} = useSelector((state: AppState) => state.user)
let POOL_TOKENS: Token[]
if (poolName === BTC_POOL_NAME) {
POOL_TOKENS = BTC_POOL_TOKENS
} else if (poolName === STABLECOIN_POOL_NAME) {
if (poolName === STABLECOIN_POOL_NAME) {
POOL_TOKENS = STABLECOIN_POOL_TOKENS
} else {
throw new Error("useApproveAndSwap requires a valid pool name")
Expand Down

0 comments on commit 0b20e47

Please sign in to comment.