Skip to content

Commit

Permalink
Merge pull request #70 from curvefi/xDai
Browse files Browse the repository at this point in the history
xDai
  • Loading branch information
Macket authored Jul 26, 2022
2 parents 12e8ccf + a21dbb4 commit 4d38c75
Show file tree
Hide file tree
Showing 19 changed files with 246 additions and 54 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@curvefi/api",
"version": "2.7.0",
"version": "2.8.0",
"description": "JavaScript library for curve.fi",
"main": "lib/index.js",
"author": "Macket",
Expand Down
26 changes: 0 additions & 26 deletions src/constants/abis/3pool/swap.json
Original file line number Diff line number Diff line change
Expand Up @@ -378,32 +378,6 @@
"type": "function",
"gas": "2673791"
},
{
"name": "get_dy_underlying",
"outputs": [
{
"type": "uint256",
"name": ""
}
],
"inputs": [
{
"type": "int128",
"name": "i"
},
{
"type": "int128",
"name": "j"
},
{
"type": "uint256",
"name": "dx"
}
],
"stateMutability": "view",
"type": "function",
"gas": "2673474"
},
{
"name": "exchange",
"outputs": [],
Expand Down
15 changes: 14 additions & 1 deletion src/constants/aliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,17 @@ export const ALIASES_OPTIMISM = lowerCaseValues({
"factory": '0x2db0E83599a91b508Ac268a6197b8B14F5e72840',
"crypto_factory": '0xF18056Bbd320E96A48e3Fbf8bC061322531aac99', // <--- TODO CHANGE
"registry_exchange": "",
});
});

export const ALIASES_XDAI = lowerCaseValues({
"crv": "0x712b3d230f3c1c19db860d80619288b1f0bdd0bd",
"minter": "0xabC000d88f23Bb45525E447528DBF656A9D55bf5",
"voting_escrow": "0x5f3b5DfEb7B28CDbD7FAba78963EE202a494e2A2",
"gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
"address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383",
"router": "0xfA9a30350048B2BF66865ee20363067c66f67e58",
"deposit_and_stake": "0xB7De33440B7171159a9718CBE748086cecDd9685",
"factory": '0xD19Baeadc667Cf2015e395f2B08668Ef120f41F5',
"crypto_factory": '0xF18056Bbd320E96A48e3Fbf8bC061322531aac99', // <--- TODO CHANGE
"registry_exchange": "",
});
18 changes: 18 additions & 0 deletions src/constants/coins/xdai.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { lowerCaseValues } from "../utils";

export const COINS_XDAI: { [index: string]: string } = lowerCaseValues({
'crv': '0x712b3d230f3c1c19db860d80619288b1f0bdd0bd',

// --- USD ---

'wxdai': '0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d',
'usdc': '0xDDAfbb505ad214D7b80b1f830fcCc89B60fb7A83',
'usdt': '0x4ECaBa5870353805a9F068101A40E0f32ed605C6',
'rai': '0xd7a28aa9c470e7e9d8c676bcd5dd2f40c5683afa',
'x3crv': '0x1337BedC9D22ecbe766dF105c9623922A27963EC',
})

export const cTokensXDai = []; //.map((a) => a.toLowerCase());
export const yTokensXDai = []; //.map((a) => a.toLowerCase());
export const ycTokensXDai = []; //.map((a) => a.toLowerCase());
export const aTokensXDai = []; //.map((a) => a.toLowerCase());
2 changes: 2 additions & 0 deletions src/constants/pools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { POOLS_DATA_FANTOM } from "./fantom";
import { POOLS_DATA_AVALANCHE } from "./avalanche";
import { POOLS_DATA_ARBITRUM } from "./arbitrum";
import { POOLS_DATA_OPTIMISM } from "./optimism";
import { POOLS_DATA_XDAI } from "./xdai";

export {
POOLS_DATA_ETHEREUM,
Expand All @@ -12,4 +13,5 @@ export {
POOLS_DATA_AVALANCHE,
POOLS_DATA_ARBITRUM,
POOLS_DATA_OPTIMISM,
POOLS_DATA_XDAI,
};
67 changes: 67 additions & 0 deletions src/constants/pools/xdai.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import tripoolSwapABI from '../abis/3pool/swap.json';
import raiSwapABI from '../abis/rai/swap.json';
import raiZapABI from '../abis/rai/deposit.json';
import gaugeRewardsOnlyABI from '../abis/gauge_rewards_only.json';
import streamerABI from '../abis/streamer.json';
import { lowerCasePoolDataAddresses } from "../utils";
import { IPoolData } from "../../interfaces";

export const POOLS_DATA_XDAI: { [index: string]: IPoolData } = lowerCasePoolDataAddresses({
'3pool': {
name: "3pool",
full_name: "3pool",
symbol: "3pool",
reference_asset: 'USD',
swap_address: '0x7f90122BF0700F9E7e1F688fe926940E8839F353',
token_address: '0x1337BedC9D22ecbe766dF105c9623922A27963EC',
gauge_address: '0x78CF256256C8089d68Cde634Cf7cDEFb39286470', // Rewards-Only
sCurveRewards_address: '0x6C09F6727113543Fd061a721da512B7eFCDD0267',
is_plain: true,
underlying_coins: ['WXDAI', 'USDC', 'USDT'],
wrapped_coins: ['WXDAI', 'USDC', 'USDT'],
underlying_coin_addresses: [
'0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d',
'0xDDAfbb505ad214D7b80b1f830fcCc89B60fb7A83',
'0x4ECaBa5870353805a9F068101A40E0f32ed605C6',
],
wrapped_coin_addresses: [
'0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d',
'0xDDAfbb505ad214D7b80b1f830fcCc89B60fb7A83',
'0x4ECaBa5870353805a9F068101A40E0f32ed605C6',
],
underlying_decimals: [18, 6, 6],
wrapped_decimals: [18, 6, 6],
swap_abi: tripoolSwapABI,
gauge_abi: gaugeRewardsOnlyABI,
sCurveRewards_abi: streamerABI,
},
rai: {
name: "rai",
full_name: "rai",
symbol: "rai",
reference_asset: 'USD',
swap_address: '0x85bA9Dfb4a3E4541420Fc75Be02E2B42042D7e46',
token_address: '0x36390a1Ae126f16C5D222CB1F2AB341dD09f2FEC',
gauge_address: '0x0000000000000000000000000000000000000000', // NO GAUGE FOR THIS POOL BUT NECESSARY TO AVOID REVERTS
deposit_address: '0xdf6eb52c4A9d7d5964b918c50D47a643Fd7D3D4c',
is_meta: true,
base_pool: '3pool',
underlying_coins: ['RAI', 'WXDAI', 'USDC', 'USDT'],
wrapped_coins: ['RAI', 'x3CRV'],
underlying_coin_addresses: [
'0xd7a28aa9c470e7e9d8c676bcd5dd2f40c5683afa',
'0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d',
'0xDDAfbb505ad214D7b80b1f830fcCc89B60fb7A83',
'0x4ECaBa5870353805a9F068101A40E0f32ed605C6',
],
wrapped_coin_addresses: [
'0xd7a28aa9c470e7e9d8c676bcd5dd2f40c5683afa',
'0x1337BedC9D22ecbe766dF105c9623922A27963EC',
],
underlying_decimals: [18, 18, 6, 6],
wrapped_decimals: [18, 18],
swap_abi: raiSwapABI,
gauge_abi: gaugeRewardsOnlyABI,
deposit_abi: raiZapABI,
},
});
33 changes: 24 additions & 9 deletions src/curve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,24 @@ import {
POOLS_DATA_AVALANCHE,
POOLS_DATA_ARBITRUM,
POOLS_DATA_OPTIMISM,
POOLS_DATA_XDAI,
} from './constants/pools';
import { COINS_ETHEREUM, cTokensEthereum, yTokensEthereum, ycTokensEthereum, aTokensEthereum } from "./constants/coins/ethereum";
import { COINS_OPTIMISM, cTokensOptimism, yTokensOptimism, ycTokensOptimism, aTokensOptimism } from "./constants/coins/optimism";
import { COINS_POLYGON, cTokensPolygon, yTokensPolygon, ycTokensPolygon, aTokensPolygon } from "./constants/coins/polygon";
import { COINS_FANTOM, cTokensFantom, yTokensFantom, ycTokensFantom, aTokensFantom } from "./constants/coins/fantom";
import { COINS_AVALANCHE, cTokensAvalanche, yTokensAvalanche, ycTokensAvalanche, aTokensAvalanche } from "./constants/coins/avalanche";
import { COINS_ARBITRUM, cTokensArbitrum, yTokensArbitrum, ycTokensArbitrum, aTokensArbitrum } from "./constants/coins/arbitrum";
import {
ALIASES_ETHEREUM,
ALIASES_OPTIMISM,
ALIASES_POLYGON,
ALIASES_FANTOM,
ALIASES_AVALANCHE,
ALIASES_ARBITRUM,
ALIASES_XDAI,
} from "./constants/aliases";
import { COINS_ETHEREUM, cTokensEthereum, yTokensEthereum, ycTokensEthereum, aTokensEthereum } from "./constants/coins/ethereum";
import { COINS_OPTIMISM, cTokensOptimism, yTokensOptimism, ycTokensOptimism, aTokensOptimism } from "./constants/coins/optimism";
import { COINS_POLYGON, cTokensPolygon, yTokensPolygon, ycTokensPolygon, aTokensPolygon } from "./constants/coins/polygon";
import { COINS_FANTOM, cTokensFantom, yTokensFantom, ycTokensFantom, aTokensFantom } from "./constants/coins/fantom";
import { COINS_AVALANCHE, cTokensAvalanche, yTokensAvalanche, ycTokensAvalanche, aTokensAvalanche } from "./constants/coins/avalanche";
import { COINS_ARBITRUM, cTokensArbitrum, yTokensArbitrum, ycTokensArbitrum, aTokensArbitrum } from "./constants/coins/arbitrum";
import { COINS_XDAI, cTokensXDai, yTokensXDai, ycTokensXDai, aTokensXDai } from "./constants/coins/xdai";
import { lowerCasePoolDataAddresses, extractDecimals, extractGauges } from "./constants/utils";


Expand All @@ -65,6 +68,16 @@ export const NETWORK_CONSTANTS: { [index: number]: any } = {
ycTokens: ycTokensOptimism,
aTokens: aTokensOptimism,
},
100: {
NAME: 'xdai',
ALIASES: ALIASES_XDAI,
POOLS_DATA: POOLS_DATA_XDAI,
COINS: COINS_XDAI,
cTokens: cTokensXDai,
yTokens: yTokensXDai,
ycTokens: ycTokensXDai,
aTokens: aTokensXDai,
},
137: {
NAME: 'polygon',
ALIASES: ALIASES_POLYGON,
Expand Down Expand Up @@ -262,9 +275,11 @@ class Curve implements ICurve {
}
}

this.contracts[pool.gauge_address] = {
contract: new Contract(pool.gauge_address, pool.gauge_abi, this.signer || this.provider),
multicallContract: new MulticallContract(pool.gauge_address, pool.gauge_abi),
if (pool.gauge_address !== ethers.constants.AddressZero) {
this.contracts[pool.gauge_address] = {
contract: new Contract(pool.gauge_address, pool.gauge_abi, this.signer || this.provider),
multicallContract: new MulticallContract(pool.gauge_address, pool.gauge_abi),
}
}

if (pool.deposit_address && !this.contracts[pool.deposit_address]) {
Expand Down
6 changes: 6 additions & 0 deletions src/factory/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ export function setFactoryZapContracts(this: ICurve): void {
contract: new Contract(metaUsdZapAddress, factoryDepositABI, this.signer || this.provider),
multicallContract: new MulticallContract(metaUsdZapAddress, factoryDepositABI),
};
} else if (this.chainId === 100) {
const metaUsdZapAddress = "0x87C067fAc25f123554a0E76596BF28cFa37fD5E9".toLowerCase();
this.contracts[metaUsdZapAddress] = {
contract: new Contract(metaUsdZapAddress, factoryDepositABI, this.signer || this.provider),
multicallContract: new MulticallContract(metaUsdZapAddress, factoryDepositABI),
};
} else if (this.chainId === 137) {
const metaUsdZapAddress = "0x5ab5C56B9db92Ba45a0B46a207286cD83C15C939".toLowerCase();
this.contracts[metaUsdZapAddress] = {
Expand Down
39 changes: 39 additions & 0 deletions src/factory/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,26 @@ export const implementationABIDictOptimism: IDict<any> = {
"0x8474DdbE98F5aA3179B3B3F5942D724aFcdec9f6": Plain4OptimizedABI,
}

export const implementationABIDictXDai: IDict<any> = {
"0x4A5bF7Ab9A8202692051c19B102d3eDD62aaBAE6": MetaUSDABI,
"0x0B4dc7A945695D11FD83e40B2DfC2B896A02395F": MetaUSDBalancesABI,

"0x04e39EF8332e979Cf8e4f8891E64934FF65F231b": Plain2BasicABI,
"0xC9438d8928486bD9621D326002F4672bF684187A": Plain2BalancesABI,
"0x2b70A5B878665FfDB4A06Ba40a264d6c70f68F4B": Plain2ETHABI,
"0x2D036f0Ff6F440dB623e0D9D3B5Daa509e5500C3": Plain2OptimizedABI,

"0xec9cEBE650E181079576C1b6d0d2e092B1EdfF13": Plain3BasicABI,
"0xe8269B33E47761f552E1a3070119560d5fa8bBD6": Plain3BalancesABI,
"0x114C4042B11a2b16F58Fe1BFe847589a122F678a": Plain3ETHABI,
"0x4244eB811D6e0Ef302326675207A95113dB4E1F8": Plain3OptimizedABI,

"0x66B5792ED50a2a7405Ea75C4B6B1913eF4E46661": Plain4BasicABI,
"0xcB4eB43E31C830e22baF764c64F11F32C280496c": Plain4BalancesABI,
"0xc1C49622b63B961ce1D352ecb7D8261Ab5556695": Plain4ETHABI,
"0x0E2615ce69Cd3Dc3Ff6f66a975bEa0655F3bA7b9": Plain4OptimizedABI,
}

export const implementationBasePoolIdDictEthereum: IDict<string> = {
"0x5F890841f657d90E081bAbdB532A05996Af79Fe6": "3pool",

Expand Down Expand Up @@ -225,6 +245,11 @@ export const implementationBasePoolIdDictOptimism: IDict<string> = {
"0xADf698e4d8Df08b3E2c79682891636eF00F6e205": "3pool",
}

export const implementationBasePoolIdDictXDai: IDict<string> = {
"0x4A5bF7Ab9A8202692051c19B102d3eDD62aaBAE6": "3pool",
"0x0B4dc7A945695D11FD83e40B2DfC2B896A02395F": "3pool",
}

export const basePoolIdZapDictEthereum: IDict<string> = {
'3pool': "0xA79828DF1850E8a3A3064576f380D90aECDD3359".toLowerCase(),
fraxusdc: "0x08780fb7E580e492c1935bEe4fA5920b94AA95Da".toLowerCase(),
Expand Down Expand Up @@ -257,6 +282,10 @@ export const basePoolIdZapDictOptimism: IDict<string> = {
"3pool": "0x167e42a1c7ab4be03764a2222aac57f5f6754411".toLowerCase(),
}

export const basePoolIdZapDictXDai: IDict<string> = {
"3pool": "0x87C067fAc25f123554a0E76596BF28cFa37fD5E9".toLowerCase(),
}

export const NATIVE_TOKEN_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
export const NATIVE_TOKENS: { [index: number]: { symbol: string, wrappedSymbol: string, wrappedAddress: string }} = {
1: { // ETH
Expand All @@ -269,6 +298,11 @@ export const NATIVE_TOKENS: { [index: number]: { symbol: string, wrappedSymbol:
wrappedSymbol: 'WETH',
wrappedAddress: '0x4200000000000000000000000000000000000006'.toLowerCase(),
},
100: { // XDAI
symbol: 'XDAi',
wrappedSymbol: 'WXDAI',
wrappedAddress: '0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d'.toLowerCase(),
},
137: { // POLYGON
symbol: 'MATIC',
wrappedSymbol: 'WMATIC',
Expand Down Expand Up @@ -297,6 +331,11 @@ export const FACTORY_CONSTANTS: { [index: number]: { implementationABIDict: IDic
implementationBasePoolIdDict: implementationBasePoolIdDictOptimism,
basePoolIdZapDict: basePoolIdZapDictOptimism,
},
100: { // XDAI
implementationABIDict: implementationABIDictXDai,
implementationBasePoolIdDict: implementationBasePoolIdDictXDai,
basePoolIdZapDict: basePoolIdZapDictXDai,
},
137: { // POLYGON
implementationABIDict: implementationABIDictPolygon,
implementationBasePoolIdDict: implementationBasePoolIdDictPolygon,
Expand Down
1 change: 1 addition & 0 deletions src/factory/factory-crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ function getExistingCoinAddressNameDict(this: ICurve): IDict<string> {

if (this.chainId === 1) dict[NATIVE_TOKEN_ADDRESS] = "ETH"
if (this.chainId === 10) dict[NATIVE_TOKEN_ADDRESS] = "ETH"
if (this.chainId === 100) dict[NATIVE_TOKEN_ADDRESS] = "XDAI"
if (this.chainId === 137) dict[NATIVE_TOKEN_ADDRESS] = "MATIC"
if (this.chainId === 250) dict[NATIVE_TOKEN_ADDRESS] = "FTM"
if (this.chainId === 43114) dict[NATIVE_TOKEN_ADDRESS] = "AVAX"
Expand Down
18 changes: 10 additions & 8 deletions src/factory/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import ERC20ABI from "../constants/abis/ERC20.json";
import factoryDepositABI from "../constants/abis/factoryPools/deposit.json";
import factoryGaugeABI from "../constants/abis/gauge_factory.json";
import { setFactoryZapContracts } from "./common";
import { FACTORY_CONSTANTS } from "./constants";
import { FACTORY_CONSTANTS, NATIVE_TOKEN_ADDRESS } from "./constants";

const BLACK_LIST: { [index: number]: any } = {
1: [],
10: [],
100: [],
137: [
"0x666dc3b4babfd063faf965bd020024af0dc51b64",
"0xe4199bc5c5c1f63dba47b56b6db7144c51cf0bf8",
Expand Down Expand Up @@ -160,12 +161,13 @@ function getExistingCoinAddressNameDict(this: ICurve): IDict<string> {
});
}

if (this.chainId === 1) dict["0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"] = "ETH"
if (this.chainId === 10) dict["0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"] = "ETH"
if (this.chainId === 137) dict["0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"] = "MATIC"
if (this.chainId === 250) dict["0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"] = "FTM"
if (this.chainId === 43114) dict["0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"] = "AVAX"
if (this.chainId === 42161) dict["0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"] = "ETH"
if (this.chainId === 1) dict[NATIVE_TOKEN_ADDRESS] = "ETH"
if (this.chainId === 10) dict[NATIVE_TOKEN_ADDRESS] = "ETH"
if (this.chainId === 100) dict[NATIVE_TOKEN_ADDRESS] = "XDAI"
if (this.chainId === 137) dict[NATIVE_TOKEN_ADDRESS] = "MATIC"
if (this.chainId === 250) dict[NATIVE_TOKEN_ADDRESS] = "FTM"
if (this.chainId === 43114) dict[NATIVE_TOKEN_ADDRESS] = "AVAX"
if (this.chainId === 42161) dict[NATIVE_TOKEN_ADDRESS] = "ETH"

return dict
}
Expand Down Expand Up @@ -227,7 +229,7 @@ async function getCoinAddressDecimalsDict(
coinAddrNamesDict[addr] = decimals[i];
});

coinAddrNamesDict['0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'] = 18
coinAddrNamesDict[NATIVE_TOKEN_ADDRESS] = 18

return coinAddrNamesDict
}
Expand Down
2 changes: 1 addition & 1 deletion src/pools/PoolTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ export class PoolTemplate {
private statsRewardsApy = async (): Promise<IReward[]> => {
if (this.gauge === ethers.constants.AddressZero) return [];

if ([10, 137, 250, 43114, 42161].includes(curve.chainId)) {
if ([10, 100, 137, 250, 43114, 42161].includes(curve.chainId)) {
const apy: IReward[] = [];
const rewardTokens = await this.rewardTokens();
for (const rewardToken of rewardTokens) {
Expand Down
5 changes: 4 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ export const _getUsdRate = async (assetId: string): Promise<number> => {
let chainName = {
1: 'ethereum',
10: 'optimistic-ethereum',
100: 'xdai',
137: 'polygon-pos',
250: 'fantom',
43114: 'avalanche',
Expand All @@ -272,7 +273,8 @@ export const _getUsdRate = async (assetId: string): Promise<number> => {

const nativeTokenName = {
1: 'ethereum',
10: 'optimism',
10: 'ethereum',
100: 'xdai',
137: 'matic-network',
250: 'fantom',
43114: 'avalanche-2',
Expand Down Expand Up @@ -327,6 +329,7 @@ export const getTVL = async (chainId = curve.chainId): Promise<number> => {
const network = {
1: "ethereum",
10: 'optimism',
100: 'xdai',
137: "polygon",
250: "fantom",
43114: "avalanche",
Expand Down
Loading

0 comments on commit 4d38c75

Please sign in to comment.