@curvefi/api 1.25.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +797 -590
- package/docs/v1/README.md +916 -0
- package/lib/boosting.d.ts +12 -12
- package/lib/boosting.js +23 -23
- package/lib/constants/abis/{json/2pool → 2pool}/swap.json +0 -0
- package/lib/constants/abis/{json/3pool → 3pool}/swap.json +0 -0
- package/lib/constants/abis/{json/4pool → 4pool}/swap.json +0 -0
- package/lib/constants/abis/{json/ERC20.json → ERC20.json} +0 -0
- package/lib/constants/abis/{json/aave → aave}/rewards.json +0 -0
- package/lib/constants/abis/{json/aave → aave}/swap.json +0 -0
- package/lib/constants/abis/{json/address_provider.json → address_provider.json} +0 -0
- package/lib/constants/abis/{json/ankreth → ankreth}/sCurveRewards.json +0 -0
- package/lib/constants/abis/{json/ankreth → ankreth}/swap.json +0 -0
- package/lib/constants/abis/{json/atricrypto3 → atricrypto3}/swap.json +0 -0
- package/lib/constants/abis/{json/atricrypto3 → atricrypto3}/zap.json +0 -0
- package/lib/constants/abis/{json/bbtc → bbtc}/deposit.json +0 -0
- package/lib/constants/abis/{json/bbtc → bbtc}/swap.json +0 -0
- package/lib/constants/abis/{json/busd → busd}/deposit.json +0 -0
- package/lib/constants/abis/{json/busd → busd}/swap.json +0 -0
- package/lib/constants/abis/{json/cERC20.json → cERC20.json} +0 -0
- package/lib/constants/abis/{json/compound → compound}/deposit.json +0 -0
- package/lib/constants/abis/{json/compound → compound}/swap.json +0 -0
- package/lib/constants/abis/{json/crveth → crveth}/swap.json +0 -0
- package/lib/constants/abis/{json/deposit_and_stake.json → deposit_and_stake.json} +0 -0
- package/lib/constants/abis/{json/dusd → dusd}/deposit.json +0 -0
- package/lib/constants/abis/{json/dusd → dusd}/sCurveRewards.json +0 -0
- package/lib/constants/abis/{json/dusd → dusd}/swap.json +0 -0
- package/lib/constants/abis/{json/eurs → eurs}/sCurveRewards.json +0 -0
- package/lib/constants/abis/{json/eurs → eurs}/swap.json +0 -0
- package/lib/constants/abis/{json/eursusd → eursusd}/swap.json +0 -0
- package/lib/constants/abis/{json/eurt → eurt}/swap.json +0 -0
- package/lib/constants/abis/{json/eurtusd → eurtusd}/deposit.json +0 -0
- package/lib/constants/abis/{json/eurtusd → eurtusd}/swap.json +0 -0
- package/lib/constants/abis/{json/factory-crypto → factory-crypto}/factory-crypto-pool-2.json +0 -0
- package/lib/constants/abis/{json/factory-crypto.json → factory-crypto.json} +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/DepositZapMetaBtcPolygon.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/DepositZapMetaUsdPolygon.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/MetaBTC.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/MetaBTCBalances.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/MetaBTCBalancesRen.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/MetaBTCRen.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/MetaUSD.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/MetaUSDBalances.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain2Balances.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain2Basic.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain2ETH.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain2Optimized.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain3Balances.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain3Basic.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain3ETH.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain3Optimized.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain4Balances.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain4Basic.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain4ETH.json +0 -0
- package/lib/constants/abis/{json/factory-v2 → factory-v2}/Plain4Optimized.json +0 -0
- package/lib/constants/abis/{json/factory.json → factory.json} +0 -0
- package/lib/constants/abis/{json/factoryPools → factoryPools}/deposit.json +0 -0
- package/lib/constants/abis/{json/factoryPools → factoryPools}/rewards.json +0 -0
- package/lib/constants/abis/{json/factoryPools → factoryPools}/swap.json +0 -0
- package/lib/constants/abis/{json/gauge.json → gauge.json} +0 -0
- package/lib/constants/abis/{json/gauge_factory.json → gauge_factory.json} +0 -0
- package/lib/constants/abis/{json/gauge_rewards_only.json → gauge_rewards_only.json} +0 -0
- package/lib/constants/abis/{json/gauge_synthetix.json → gauge_synthetix.json} +0 -0
- package/lib/constants/abis/{json/gauge_v2.json → gauge_v2.json} +0 -0
- package/lib/constants/abis/{json/gauge_v3.json → gauge_v3.json} +0 -0
- package/lib/constants/abis/{json/gauge_v4.json → gauge_v4.json} +0 -0
- package/lib/constants/abis/{json/gauge_v5.json → gauge_v5.json} +0 -0
- package/lib/constants/abis/{json/gaugecontroller.json → gaugecontroller.json} +0 -0
- package/lib/constants/abis/{json/gusd → gusd}/deposit.json +0 -0
- package/lib/constants/abis/{json/gusd → gusd}/swap.json +0 -0
- package/lib/constants/abis/{json/hbtc → hbtc}/swap.json +0 -0
- package/lib/constants/abis/{json/husd → husd}/deposit.json +0 -0
- package/lib/constants/abis/{json/husd → husd}/swap.json +0 -0
- package/lib/constants/abis/{json/ib → ib}/swap.json +0 -0
- package/lib/constants/abis/{json/iearn → iearn}/deposit.json +0 -0
- package/lib/constants/abis/{json/iearn → iearn}/sCurveRewards.json +0 -0
- package/lib/constants/abis/{json/iearn → iearn}/swap.json +0 -0
- package/lib/constants/abis/{json/link → link}/swap.json +0 -0
- package/lib/constants/abis/{json/minter.json → minter.json} +0 -0
- package/lib/constants/abis/{json/musd → musd}/deposit.json +0 -0
- package/lib/constants/abis/{json/musd → musd}/sCurveRewards.json +0 -0
- package/lib/constants/abis/{json/musd → musd}/swap.json +0 -0
- package/lib/constants/abis/{json/obtc → obtc}/deposit.json +0 -0
- package/lib/constants/abis/{json/obtc → obtc}/sCurveRewards.json +0 -0
- package/lib/constants/abis/{json/obtc → obtc}/swap.json +0 -0
- package/lib/constants/abis/{json/paave → paave}/rewards.json +0 -0
- package/lib/constants/abis/{json/pax → pax}/deposit.json +0 -0
- package/lib/constants/abis/{json/pax → pax}/swap.json +0 -0
- package/lib/constants/abis/{json/pbtc → pbtc}/deposit.json +0 -0
- package/lib/constants/abis/{json/pbtc → pbtc}/sCurveRewards.json +0 -0
- package/lib/constants/abis/{json/pbtc → pbtc}/swap.json +0 -0
- package/lib/constants/abis/{json/rai → rai}/deposit.json +0 -0
- package/lib/constants/abis/{json/rai → rai}/swap.json +0 -0
- package/lib/constants/abis/{json/registry_exchange.json → registry_exchange.json} +0 -0
- package/lib/constants/abis/{json/ren → ren}/swap.json +0 -0
- package/lib/constants/abis/{json/ren-polygon → ren-polygon}/swap.json +0 -0
- package/lib/constants/abis/{json/reth → reth}/swap.json +0 -0
- package/lib/constants/abis/{json/router.json → router.json} +0 -0
- package/lib/constants/abis/{json/rsv → rsv}/deposit.json +0 -0
- package/lib/constants/abis/{json/rsv → rsv}/sCurveRewards.json +0 -0
- package/lib/constants/abis/{json/rsv → rsv}/swap.json +0 -0
- package/lib/constants/abis/{json/saave → saave}/swap.json +0 -0
- package/lib/constants/abis/{json/sbtc → sbtc}/sCurveRewards.json +0 -0
- package/lib/constants/abis/{json/sbtc → sbtc}/swap.json +0 -0
- package/lib/constants/abis/{json/seth → seth}/swap.json +0 -0
- package/lib/constants/abis/{json/steth → steth}/sCurveRewards.json +0 -0
- package/lib/constants/abis/{json/steth → steth}/swap.json +0 -0
- package/lib/constants/abis/{json/streamer.json → streamer.json} +0 -0
- package/lib/constants/abis/{json/susdv2 → susdv2}/deposit.json +0 -0
- package/lib/constants/abis/{json/susdv2 → susdv2}/sCurveRewards.json +0 -0
- package/lib/constants/abis/{json/susdv2 → susdv2}/swap.json +0 -0
- package/lib/constants/abis/{json/tbtc → tbtc}/deposit.json +0 -0
- package/lib/constants/abis/{json/tbtc → tbtc}/sCurveRewards.json +0 -0
- package/lib/constants/abis/{json/tbtc → tbtc}/swap.json +0 -0
- package/lib/constants/abis/{json/tricrypto2 → tricrypto2}/deposit.json +0 -0
- package/lib/constants/abis/{json/tricrypto2 → tricrypto2}/swap.json +0 -0
- package/lib/constants/abis/{json/usdk → usdk}/deposit.json +0 -0
- package/lib/constants/abis/{json/usdk → usdk}/swap.json +0 -0
- package/lib/constants/abis/{json/usdn → usdn}/deposit.json +0 -0
- package/lib/constants/abis/{json/usdn → usdn}/swap.json +0 -0
- package/lib/constants/abis/{json/usdp → usdp}/deposit.json +0 -0
- package/lib/constants/abis/{json/usdp → usdp}/swap.json +0 -0
- package/lib/constants/abis/{json/usdt → usdt}/deposit.json +0 -0
- package/lib/constants/abis/{json/usdt → usdt}/swap.json +0 -0
- package/lib/constants/abis/{json/ust → ust}/deposit.json +0 -0
- package/lib/constants/abis/{json/ust → ust}/swap.json +0 -0
- package/lib/constants/abis/{json/votingescrow.json → votingescrow.json} +0 -0
- package/lib/constants/abis/{json/yERC20.json → yERC20.json} +0 -0
- package/lib/constants/aliases.d.ts +2 -24
- package/lib/constants/aliases.js +5 -4
- package/lib/constants/{coins-ethereum.d.ts → coins/ethereum.d.ts} +0 -9
- package/lib/constants/{coins-ethereum.js → coins/ethereum.js} +12 -23
- package/lib/constants/{coins-polygon.d.ts → coins/polygon.d.ts} +0 -12
- package/lib/constants/{coins-polygon.js → coins/polygon.js} +8 -20
- package/lib/constants/pools/ethereum.d.ts +2 -0
- package/lib/constants/{abis/abis-ethereum.js → pools/ethereum.js} +517 -1012
- package/lib/constants/pools/index.d.ts +3 -0
- package/lib/constants/pools/index.js +7 -0
- package/lib/constants/pools/polygon.d.ts +4 -0
- package/lib/constants/{abis/abis-polygon.js → pools/polygon.js} +53 -81
- package/lib/constants/utils.d.ts +5 -0
- package/lib/constants/utils.js +69 -0
- package/lib/curve.d.ts +10 -32
- package/lib/curve.js +188 -232
- package/lib/external-api.d.ts +3 -1
- package/lib/external-api.js +34 -1
- package/lib/factory/constants.d.ts +15 -15
- package/lib/factory/constants.js +19 -19
- package/lib/factory/factory-api.d.ts +2 -2
- package/lib/factory/factory-api.js +52 -45
- package/lib/factory/factory-crypto.d.ts +2 -2
- package/lib/factory/factory-crypto.js +23 -31
- package/lib/factory/factory.d.ts +2 -2
- package/lib/factory/factory.js +53 -66
- package/lib/index.d.ts +37 -53
- package/lib/index.js +28 -35
- package/lib/interfaces.d.ts +35 -72
- package/lib/pools/PoolTemplate.d.ts +212 -0
- package/lib/pools/PoolTemplate.js +2371 -0
- package/lib/pools/index.d.ts +3 -0
- package/lib/pools/index.js +7 -0
- package/lib/pools/mixins/common.d.ts +3 -0
- package/lib/pools/mixins/common.js +77 -0
- package/lib/pools/mixins/depositBalancedAmountsMixins.d.ts +5 -0
- package/lib/pools/mixins/depositBalancedAmountsMixins.js +145 -0
- package/lib/pools/mixins/depositBonusMixins.d.ts +5 -0
- package/lib/pools/mixins/depositBonusMixins.js +164 -0
- package/lib/pools/mixins/depositMixins.d.ts +5 -0
- package/lib/pools/mixins/depositMixins.js +373 -0
- package/lib/pools/mixins/depositWrappedMixins.d.ts +3 -0
- package/lib/pools/mixins/depositWrappedMixins.js +243 -0
- package/lib/pools/mixins/poolBalancesMixin.d.ts +4 -0
- package/lib/pools/mixins/poolBalancesMixin.js +129 -0
- package/lib/pools/mixins/swapMixins.d.ts +4 -0
- package/lib/pools/mixins/swapMixins.js +313 -0
- package/lib/pools/mixins/swapWrappedMixins.d.ts +4 -0
- package/lib/pools/mixins/swapWrappedMixins.js +297 -0
- package/lib/pools/mixins/withdrawExpectedMixins.d.ts +6 -0
- package/lib/pools/mixins/withdrawExpectedMixins.js +164 -0
- package/lib/pools/mixins/withdrawImbalanceMixins.d.ts +5 -0
- package/lib/pools/mixins/withdrawImbalanceMixins.js +348 -0
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.d.ts +3 -0
- package/lib/pools/mixins/withdrawImbalanceWrappedMixins.js +207 -0
- package/lib/pools/mixins/withdrawMixins.d.ts +5 -0
- package/lib/pools/mixins/withdrawMixins.js +347 -0
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.d.ts +5 -0
- package/lib/pools/mixins/withdrawOneCoinExpectedMixins.js +104 -0
- package/lib/pools/mixins/withdrawOneCoinMixins.d.ts +5 -0
- package/lib/pools/mixins/withdrawOneCoinMixins.js +347 -0
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.d.ts +3 -0
- package/lib/pools/mixins/withdrawOneCoinWrappedExpectedMixins.js +72 -0
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.d.ts +3 -0
- package/lib/pools/mixins/withdrawOneCoinWrappedMixins.js +205 -0
- package/lib/pools/mixins/withdrawWrappedMixins.d.ts +3 -0
- package/lib/pools/mixins/withdrawWrappedMixins.js +206 -0
- package/lib/pools/poolConstructor.d.ts +2 -0
- package/lib/pools/poolConstructor.js +228 -0
- package/lib/pools/utils.d.ts +4 -0
- package/lib/pools/utils.js +85 -0
- package/lib/router.d.ts +13 -0
- package/lib/router.js +651 -0
- package/lib/utils.d.ts +11 -16
- package/lib/utils.js +47 -130
- package/package.json +1 -1
- package/lib/constants/abis/abis-ethereum.d.ts +0 -4
- package/lib/constants/abis/abis-polygon.d.ts +0 -4
- package/lib/constants/abis/json/aRewards.json +0 -1
- package/lib/constants/abis/json/compound/migration.json +0 -57
- package/lib/constants/abis/json/compound/oldSwap.json +0 -688
- package/lib/constants/abis/json/ren/adapter.json +0 -1
- package/lib/constants/abis/json/sbtc/adapter.json +0 -1
- package/lib/pools.d.ts +0 -267
- package/lib/pools.js +0 -4742
package/lib/utils.d.ts
CHANGED
|
@@ -1,35 +1,30 @@
|
|
|
1
|
-
import memoize from 'memoizee';
|
|
2
1
|
import { ethers } from 'ethers';
|
|
3
2
|
import BigNumber from 'bignumber.js';
|
|
4
|
-
import {
|
|
3
|
+
import { IDict } from './interfaces';
|
|
5
4
|
export declare const MAX_ALLOWANCE: ethers.BigNumber;
|
|
6
5
|
export declare const BN: (val: number | string) => BigNumber;
|
|
7
6
|
export declare const toBN: (n: ethers.BigNumber, decimals?: number) => BigNumber;
|
|
8
7
|
export declare const toStringFromBN: (bn: BigNumber, decimals?: number) => string;
|
|
9
8
|
export declare const fromBN: (bn: BigNumber, decimals?: number) => ethers.BigNumber;
|
|
9
|
+
export declare const _cutZeros: (strn: string) => string;
|
|
10
|
+
export declare const checkNumber: (n: number | string) => number | string;
|
|
11
|
+
export declare const formatNumber: (n: number | string, decimals?: number) => string;
|
|
12
|
+
export declare const parseUnits: (n: number | string, decimals?: number) => ethers.BigNumber;
|
|
10
13
|
export declare const isEth: (address: string) => boolean;
|
|
11
14
|
export declare const getEthIndex: (addresses: string[]) => number;
|
|
12
15
|
export declare const _getCoinAddresses: (...coins: string[] | string[][]) => string[];
|
|
13
16
|
export declare const _getCoinDecimals: (...coinAddresses: string[] | string[][]) => number[];
|
|
14
|
-
export declare const _getBalances: (coins: string[], addresses: string[]) => Promise<
|
|
17
|
+
export declare const _getBalances: (coins: string[], addresses: string[]) => Promise<IDict<string[]>>;
|
|
15
18
|
export declare const _prepareAddresses: (addresses: string[] | string[][]) => string[];
|
|
16
|
-
export declare const getBalances: (coins: string[], ...addresses: string[] | string[][]) => Promise<
|
|
19
|
+
export declare const getBalances: (coins: string[], ...addresses: string[] | string[][]) => Promise<IDict<string[]> | string[]>;
|
|
17
20
|
export declare const _getAllowance: (coins: string[], address: string, spender: string) => Promise<ethers.BigNumber[]>;
|
|
18
21
|
export declare const getAllowance: (coins: string[], address: string, spender: string) => Promise<string[]>;
|
|
19
|
-
export declare const hasAllowance: (coins: string[], amounts: string[], address: string, spender: string) => Promise<boolean>;
|
|
22
|
+
export declare const hasAllowance: (coins: string[], amounts: (number | string)[], address: string, spender: string) => Promise<boolean>;
|
|
20
23
|
export declare const _ensureAllowance: (coins: string[], amounts: ethers.BigNumber[], spender: string) => Promise<string[]>;
|
|
21
|
-
export declare const ensureAllowanceEstimateGas: (coins: string[], amounts: string[], spender: string) => Promise<number>;
|
|
22
|
-
export declare const ensureAllowance: (coins: string[], amounts: string[], spender: string) => Promise<string[]>;
|
|
24
|
+
export declare const ensureAllowanceEstimateGas: (coins: string[], amounts: (number | string)[], spender: string) => Promise<number>;
|
|
25
|
+
export declare const ensureAllowance: (coins: string[], amounts: (number | string)[], spender: string) => Promise<string[]>;
|
|
23
26
|
export declare const getPoolNameBySwapAddress: (swapAddress: string) => string;
|
|
24
|
-
export declare const _getUsdPricesFromApi: () => Promise<
|
|
27
|
+
export declare const _getUsdPricesFromApi: () => Promise<IDict<number>>;
|
|
25
28
|
export declare const _getUsdRate: (assetId: string) => Promise<number>;
|
|
26
|
-
export declare const _getFactoryStatsUrl: () => string;
|
|
27
|
-
export declare const _getStatsUrl: (isCrypto?: boolean) => string;
|
|
28
|
-
export declare const _getStats: ((statsUrl: string) => Promise<IStats>) & memoize.Memoized<(statsUrl: string) => Promise<IStats>>;
|
|
29
|
-
export declare const _getFactoryStatsEthereum: ((statsUrl: string) => Promise<IStats>) & memoize.Memoized<(statsUrl: string) => Promise<IStats>>;
|
|
30
|
-
export declare const _getFactoryStatsPolygon: ((statsUrl: string) => Promise<IStats>) & memoize.Memoized<(statsUrl: string) => Promise<IStats>>;
|
|
31
|
-
export declare const getPoolList: () => string[];
|
|
32
|
-
export declare const getFactoryPoolList: () => string[];
|
|
33
|
-
export declare const getCryptoFactoryPoolList: () => string[];
|
|
34
29
|
export declare const getUsdRate: (coin: string) => Promise<number>;
|
|
35
30
|
export declare const getTVL: (chainId?: number) => Promise<number>;
|
package/lib/utils.js
CHANGED
|
@@ -59,13 +59,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
59
59
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
60
60
|
};
|
|
61
61
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
-
exports.getTVL = exports.getUsdRate = exports.
|
|
62
|
+
exports.getTVL = exports.getUsdRate = exports._getUsdRate = exports._getUsdPricesFromApi = exports.getPoolNameBySwapAddress = exports.ensureAllowance = exports.ensureAllowanceEstimateGas = exports._ensureAllowance = exports.hasAllowance = exports.getAllowance = exports._getAllowance = exports.getBalances = exports._prepareAddresses = exports._getBalances = exports._getCoinDecimals = exports._getCoinAddresses = exports.getEthIndex = exports.isEth = exports.parseUnits = exports.formatNumber = exports.checkNumber = exports._cutZeros = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.MAX_ALLOWANCE = void 0;
|
|
63
63
|
var axios_1 = __importDefault(require("axios"));
|
|
64
|
-
var memoizee_1 = __importDefault(require("memoizee"));
|
|
65
64
|
var ethers_1 = require("ethers");
|
|
66
65
|
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
67
66
|
var curve_1 = require("./curve");
|
|
68
|
-
var curve_2 = require("./curve");
|
|
69
67
|
var external_api_1 = require("./external-api");
|
|
70
68
|
var ETH_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';
|
|
71
69
|
exports.MAX_ALLOWANCE = ethers_1.ethers.BigNumber.from(2).pow(ethers_1.ethers.BigNumber.from(256)).sub(ethers_1.ethers.BigNumber.from(1));
|
|
@@ -87,6 +85,30 @@ var fromBN = function (bn, decimals) {
|
|
|
87
85
|
return ethers_1.ethers.utils.parseUnits((0, exports.toStringFromBN)(bn, decimals), decimals);
|
|
88
86
|
};
|
|
89
87
|
exports.fromBN = fromBN;
|
|
88
|
+
// Formatting numbers
|
|
89
|
+
var _cutZeros = function (strn) {
|
|
90
|
+
return strn.replace(/0+$/gi, '').replace(/\.$/gi, '');
|
|
91
|
+
};
|
|
92
|
+
exports._cutZeros = _cutZeros;
|
|
93
|
+
var checkNumber = function (n) {
|
|
94
|
+
if (Number(n) !== Number(n))
|
|
95
|
+
throw Error("".concat(n, " is not a number")); // NaN
|
|
96
|
+
return n;
|
|
97
|
+
};
|
|
98
|
+
exports.checkNumber = checkNumber;
|
|
99
|
+
var formatNumber = function (n, decimals) {
|
|
100
|
+
if (decimals === void 0) { decimals = 18; }
|
|
101
|
+
if (Number(n) !== Number(n))
|
|
102
|
+
throw Error("".concat(n, " is not a number")); // NaN
|
|
103
|
+
var _a = String(n).split("."), integer = _a[0], fractional = _a[1];
|
|
104
|
+
return !fractional ? integer : integer + "." + fractional.slice(0, decimals);
|
|
105
|
+
};
|
|
106
|
+
exports.formatNumber = formatNumber;
|
|
107
|
+
var parseUnits = function (n, decimals) {
|
|
108
|
+
if (decimals === void 0) { decimals = 18; }
|
|
109
|
+
return ethers_1.ethers.utils.parseUnits((0, exports.formatNumber)(n, decimals), decimals);
|
|
110
|
+
};
|
|
111
|
+
exports.parseUnits = parseUnits;
|
|
90
112
|
// -------------------
|
|
91
113
|
var isEth = function (address) { return address.toLowerCase() === ETH_ADDRESS.toLowerCase(); };
|
|
92
114
|
exports.isEth = isEth;
|
|
@@ -101,11 +123,11 @@ var _getCoinAddresses = function () {
|
|
|
101
123
|
if (coins.length == 1 && Array.isArray(coins[0]))
|
|
102
124
|
coins = coins[0];
|
|
103
125
|
coins = coins;
|
|
104
|
-
var coinAddresses = coins.map(function (c) { return
|
|
105
|
-
var availableAddresses = __spreadArray(__spreadArray(
|
|
126
|
+
var coinAddresses = coins.map(function (c) { return c.toLowerCase(); }).map(function (c) { return curve_1.curve.constants.COINS[c] || c; });
|
|
127
|
+
var availableAddresses = __spreadArray(__spreadArray([], Object.keys(curve_1.curve.constants.DECIMALS), true), curve_1.curve.constants.GAUGES, true);
|
|
106
128
|
for (var _a = 0, coinAddresses_1 = coinAddresses; _a < coinAddresses_1.length; _a++) {
|
|
107
129
|
var coinAddr = coinAddresses_1[_a];
|
|
108
|
-
if (!availableAddresses.includes(coinAddr
|
|
130
|
+
if (!availableAddresses.includes(coinAddr))
|
|
109
131
|
throw Error("Coin with address '".concat(coinAddr, "' is not available"));
|
|
110
132
|
}
|
|
111
133
|
return coinAddresses;
|
|
@@ -119,7 +141,7 @@ var _getCoinDecimals = function () {
|
|
|
119
141
|
if (coinAddresses.length == 1 && Array.isArray(coinAddresses[0]))
|
|
120
142
|
coinAddresses = coinAddresses[0];
|
|
121
143
|
coinAddresses = coinAddresses;
|
|
122
|
-
return coinAddresses.map(function (coinAddr) { var _a; return (_a =
|
|
144
|
+
return coinAddresses.map(function (coinAddr) { var _a; return (_a = curve_1.curve.constants.DECIMALS[coinAddr.toLowerCase()]) !== null && _a !== void 0 ? _a : 18; }); // 18 for gauges
|
|
123
145
|
};
|
|
124
146
|
exports._getCoinDecimals = _getCoinDecimals;
|
|
125
147
|
var _getBalances = function (coins, addresses) { return __awaiter(void 0, void 0, void 0, function () {
|
|
@@ -263,7 +285,7 @@ var hasAllowance = function (coins, amounts, address, spender) { return __awaite
|
|
|
263
285
|
return [4 /*yield*/, (0, exports._getAllowance)(coinAddresses, address, spender)];
|
|
264
286
|
case 1:
|
|
265
287
|
_allowance = _a.sent();
|
|
266
|
-
_amounts = amounts.map(function (a, i) { return
|
|
288
|
+
_amounts = amounts.map(function (a, i) { return (0, exports.parseUnits)(a, decimals[i]); });
|
|
267
289
|
return [2 /*return*/, _allowance.map(function (a, i) { return a.gte(_amounts[i]); }).reduce(function (a, b) { return a && b; })];
|
|
268
290
|
}
|
|
269
291
|
});
|
|
@@ -321,7 +343,7 @@ var ensureAllowanceEstimateGas = function (coins, amounts, spender) { return __a
|
|
|
321
343
|
case 0:
|
|
322
344
|
coinAddresses = (0, exports._getCoinAddresses)(coins);
|
|
323
345
|
decimals = (0, exports._getCoinDecimals)(coinAddresses);
|
|
324
|
-
_amounts = amounts.map(function (a, i) { return
|
|
346
|
+
_amounts = amounts.map(function (a, i) { return (0, exports.parseUnits)(a, decimals[i]); });
|
|
325
347
|
address = curve_1.curve.signerAddress;
|
|
326
348
|
return [4 /*yield*/, (0, exports._getAllowance)(coinAddresses, address, spender)];
|
|
327
349
|
case 1:
|
|
@@ -361,7 +383,7 @@ var ensureAllowance = function (coins, amounts, spender) { return __awaiter(void
|
|
|
361
383
|
case 0:
|
|
362
384
|
coinAddresses = (0, exports._getCoinAddresses)(coins);
|
|
363
385
|
decimals = (0, exports._getCoinDecimals)(coinAddresses);
|
|
364
|
-
_amounts = amounts.map(function (a, i) { return
|
|
386
|
+
_amounts = amounts.map(function (a, i) { return (0, exports.parseUnits)(a, decimals[i]); });
|
|
365
387
|
return [4 /*yield*/, (0, exports._ensureAllowance)(coinAddresses, _amounts, spender)];
|
|
366
388
|
case 1: return [2 /*return*/, _a.sent()];
|
|
367
389
|
}
|
|
@@ -369,16 +391,18 @@ var ensureAllowance = function (coins, amounts, spender) { return __awaiter(void
|
|
|
369
391
|
}); };
|
|
370
392
|
exports.ensureAllowance = ensureAllowance;
|
|
371
393
|
var getPoolNameBySwapAddress = function (swapAddress) {
|
|
372
|
-
|
|
394
|
+
var poolsData = __assign(__assign(__assign({}, curve_1.curve.constants.POOLS_DATA), curve_1.curve.constants.FACTORY_POOLS_DATA), curve_1.curve.constants.CRYPTO_FACTORY_POOLS_DATA);
|
|
395
|
+
return Object.entries(poolsData).filter(function (_a) {
|
|
373
396
|
var _ = _a[0], poolData = _a[1];
|
|
374
397
|
return poolData.swap_address.toLowerCase() === swapAddress.toLowerCase();
|
|
375
398
|
})[0][0];
|
|
376
399
|
};
|
|
377
400
|
exports.getPoolNameBySwapAddress = getPoolNameBySwapAddress;
|
|
378
401
|
var _getUsdPricesFromApi = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
379
|
-
var network, promises, allTypesExtendedPoolData, priceDict, _i, allTypesExtendedPoolData_1, extendedPoolData, _a, _b, pool, _c, _d, coin;
|
|
380
|
-
|
|
381
|
-
|
|
402
|
+
var network, promises, allTypesExtendedPoolData, priceDict, _i, allTypesExtendedPoolData_1, extendedPoolData, _a, _b, pool, _c, _d, coin, _e, _f, coin;
|
|
403
|
+
var _g;
|
|
404
|
+
return __generator(this, function (_h) {
|
|
405
|
+
switch (_h.label) {
|
|
382
406
|
case 0:
|
|
383
407
|
network = curve_1.curve.chainId === 137 ? "polygon" : "ethereum";
|
|
384
408
|
promises = [
|
|
@@ -389,7 +413,7 @@ var _getUsdPricesFromApi = function () { return __awaiter(void 0, void 0, void 0
|
|
|
389
413
|
];
|
|
390
414
|
return [4 /*yield*/, Promise.all(promises)];
|
|
391
415
|
case 1:
|
|
392
|
-
allTypesExtendedPoolData =
|
|
416
|
+
allTypesExtendedPoolData = _h.sent();
|
|
393
417
|
priceDict = {};
|
|
394
418
|
for (_i = 0, allTypesExtendedPoolData_1 = allTypesExtendedPoolData; _i < allTypesExtendedPoolData_1.length; _i++) {
|
|
395
419
|
extendedPoolData = allTypesExtendedPoolData_1[_i];
|
|
@@ -400,6 +424,11 @@ var _getUsdPricesFromApi = function () { return __awaiter(void 0, void 0, void 0
|
|
|
400
424
|
if (typeof coin.usdPrice === "number")
|
|
401
425
|
priceDict[coin.address.toLowerCase()] = coin.usdPrice;
|
|
402
426
|
}
|
|
427
|
+
for (_e = 0, _f = (_g = pool.gaugeRewards) !== null && _g !== void 0 ? _g : []; _e < _f.length; _e++) {
|
|
428
|
+
coin = _f[_e];
|
|
429
|
+
if (typeof coin.tokenPrice === "number")
|
|
430
|
+
priceDict[coin.tokenAddress.toLowerCase()] = coin.tokenPrice;
|
|
431
|
+
}
|
|
403
432
|
}
|
|
404
433
|
}
|
|
405
434
|
return [2 /*return*/, priceDict];
|
|
@@ -418,7 +447,7 @@ var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0,
|
|
|
418
447
|
pricesFromApi = _c.sent();
|
|
419
448
|
if (assetId.toLowerCase() in pricesFromApi)
|
|
420
449
|
return [2 /*return*/, pricesFromApi[assetId.toLowerCase()]];
|
|
421
|
-
if (assetId === 'USD' || (curve_1.curve.chainId === 137 && (assetId.toLowerCase() ===
|
|
450
|
+
if (assetId === 'USD' || (curve_1.curve.chainId === 137 && (assetId.toLowerCase() === curve_1.curve.constants.COINS.am3crv.toLowerCase())))
|
|
422
451
|
return [2 /*return*/, 1];
|
|
423
452
|
chainName = {
|
|
424
453
|
1: 'ethereum',
|
|
@@ -429,14 +458,14 @@ var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0,
|
|
|
429
458
|
throw Error('curve object is not initialized');
|
|
430
459
|
}
|
|
431
460
|
assetId = {
|
|
432
|
-
'EUR':
|
|
461
|
+
'EUR': curve_1.curve.constants.COINS.eurt,
|
|
433
462
|
'BTC': 'bitcoin',
|
|
434
463
|
'ETH': 'ethereum',
|
|
435
464
|
'LINK': 'link',
|
|
436
465
|
}[assetId] || assetId;
|
|
437
466
|
assetId = (0, exports.isEth)(assetId) ? "ethereum" : assetId.toLowerCase();
|
|
438
467
|
// No EURT on Coingecko Polygon
|
|
439
|
-
if (assetId.toLowerCase() ===
|
|
468
|
+
if (assetId.toLowerCase() === curve_1.curve.constants.COINS.eurt.toLowerCase()) {
|
|
440
469
|
chainName = 'ethereum';
|
|
441
470
|
assetId = '0xC581b735A1688071A1746c968e0798D642EDE491'.toLowerCase(); // EURT Ethereum
|
|
442
471
|
}
|
|
@@ -459,118 +488,6 @@ var _getUsdRate = function (assetId) { return __awaiter(void 0, void 0, void 0,
|
|
|
459
488
|
});
|
|
460
489
|
}); };
|
|
461
490
|
exports._getUsdRate = _getUsdRate;
|
|
462
|
-
var _getFactoryStatsUrl = function () {
|
|
463
|
-
if (curve_1.curve.chainId === 1 || curve_1.curve.chainId === 1337) {
|
|
464
|
-
return "https://curve-api-hplkiejxx-curvefi.vercel.app/api/getSubgraphData";
|
|
465
|
-
}
|
|
466
|
-
else if (curve_1.curve.chainId === 137) {
|
|
467
|
-
return "https://api.curve.fi/api/getFactoryAPYs-polygon";
|
|
468
|
-
}
|
|
469
|
-
else {
|
|
470
|
-
throw Error("Unsupported network id".concat(curve_1.curve.chainId));
|
|
471
|
-
}
|
|
472
|
-
};
|
|
473
|
-
exports._getFactoryStatsUrl = _getFactoryStatsUrl;
|
|
474
|
-
var _getStatsUrl = function (isCrypto) {
|
|
475
|
-
if (isCrypto === void 0) { isCrypto = false; }
|
|
476
|
-
if (curve_1.curve.chainId === 1 || curve_1.curve.chainId === 1337) {
|
|
477
|
-
return isCrypto ? "https://stats.curve.fi/raw-stats-crypto/apys.json" : "https://stats.curve.fi/raw-stats/apys.json";
|
|
478
|
-
}
|
|
479
|
-
else if (curve_1.curve.chainId === 137) {
|
|
480
|
-
return "https://stats.curve.fi/raw-stats-polygon/apys.json";
|
|
481
|
-
}
|
|
482
|
-
else {
|
|
483
|
-
throw Error("Unsupported network id".concat(curve_1.curve.chainId));
|
|
484
|
-
}
|
|
485
|
-
};
|
|
486
|
-
exports._getStatsUrl = _getStatsUrl;
|
|
487
|
-
exports._getStats = (0, memoizee_1.default)(function (statsUrl) { return __awaiter(void 0, void 0, void 0, function () {
|
|
488
|
-
var rawData, data;
|
|
489
|
-
return __generator(this, function (_a) {
|
|
490
|
-
switch (_a.label) {
|
|
491
|
-
case 0: return [4 /*yield*/, axios_1.default.get(statsUrl)];
|
|
492
|
-
case 1:
|
|
493
|
-
rawData = (_a.sent()).data;
|
|
494
|
-
data = {};
|
|
495
|
-
Object.keys(rawData.apy.day).forEach(function (poolName) {
|
|
496
|
-
var _a;
|
|
497
|
-
data[poolName] = {
|
|
498
|
-
volume: (_a = rawData.volume[poolName]) !== null && _a !== void 0 ? _a : 0,
|
|
499
|
-
apy: {
|
|
500
|
-
day: rawData.apy.day[poolName],
|
|
501
|
-
week: rawData.apy.week[poolName],
|
|
502
|
-
month: rawData.apy.month[poolName],
|
|
503
|
-
total: rawData.apy.total[poolName],
|
|
504
|
-
},
|
|
505
|
-
};
|
|
506
|
-
});
|
|
507
|
-
return [2 /*return*/, data];
|
|
508
|
-
}
|
|
509
|
-
});
|
|
510
|
-
}); }, {
|
|
511
|
-
promise: true,
|
|
512
|
-
maxAge: 10 * 60 * 1000, // 10m
|
|
513
|
-
});
|
|
514
|
-
exports._getFactoryStatsEthereum = (0, memoizee_1.default)(function (statsUrl) { return __awaiter(void 0, void 0, void 0, function () {
|
|
515
|
-
var rawData, data;
|
|
516
|
-
return __generator(this, function (_a) {
|
|
517
|
-
switch (_a.label) {
|
|
518
|
-
case 0: return [4 /*yield*/, axios_1.default.get(statsUrl)];
|
|
519
|
-
case 1:
|
|
520
|
-
rawData = (_a.sent()).data.data.poolList;
|
|
521
|
-
data = {};
|
|
522
|
-
rawData.forEach(function (item) {
|
|
523
|
-
var _a, _b, _c, _d, _e;
|
|
524
|
-
data[item.address.toLowerCase()] = {
|
|
525
|
-
volume: (_a = item.volumeUSD) !== null && _a !== void 0 ? _a : 0,
|
|
526
|
-
apy: {
|
|
527
|
-
day: (_b = item.latestDailyApy) !== null && _b !== void 0 ? _b : 0,
|
|
528
|
-
week: (_c = item.latestWeeklyApy) !== null && _c !== void 0 ? _c : 0,
|
|
529
|
-
month: (_d = item.latestWeeklyApy) !== null && _d !== void 0 ? _d : 0,
|
|
530
|
-
total: (_e = item.latestWeeklyApy) !== null && _e !== void 0 ? _e : 0,
|
|
531
|
-
},
|
|
532
|
-
};
|
|
533
|
-
});
|
|
534
|
-
return [2 /*return*/, data];
|
|
535
|
-
}
|
|
536
|
-
});
|
|
537
|
-
}); }, {
|
|
538
|
-
promise: true,
|
|
539
|
-
maxAge: 10 * 60 * 1000, // 10m
|
|
540
|
-
});
|
|
541
|
-
exports._getFactoryStatsPolygon = (0, memoizee_1.default)(function (statsUrl) { return __awaiter(void 0, void 0, void 0, function () {
|
|
542
|
-
var rawData, data;
|
|
543
|
-
return __generator(this, function (_a) {
|
|
544
|
-
switch (_a.label) {
|
|
545
|
-
case 0: return [4 /*yield*/, axios_1.default.get(statsUrl)];
|
|
546
|
-
case 1:
|
|
547
|
-
rawData = (_a.sent()).data.data.poolDetails;
|
|
548
|
-
data = {};
|
|
549
|
-
rawData.forEach(function (item) {
|
|
550
|
-
var _a, _b, _c, _d, _e;
|
|
551
|
-
data[item.poolAddress.toLowerCase()] = {
|
|
552
|
-
volume: (_a = item.volume) !== null && _a !== void 0 ? _a : 0,
|
|
553
|
-
apy: {
|
|
554
|
-
day: (_b = item.apy) !== null && _b !== void 0 ? _b : 0,
|
|
555
|
-
week: (_c = item.apy) !== null && _c !== void 0 ? _c : 0,
|
|
556
|
-
month: (_d = item.apy) !== null && _d !== void 0 ? _d : 0,
|
|
557
|
-
total: (_e = item.apy) !== null && _e !== void 0 ? _e : 0,
|
|
558
|
-
},
|
|
559
|
-
};
|
|
560
|
-
});
|
|
561
|
-
return [2 /*return*/, data];
|
|
562
|
-
}
|
|
563
|
-
});
|
|
564
|
-
}); }, {
|
|
565
|
-
promise: true,
|
|
566
|
-
maxAge: 10 * 60 * 1000, // 10m
|
|
567
|
-
});
|
|
568
|
-
var getPoolList = function () { return Object.keys(curve_1.POOLS_DATA); };
|
|
569
|
-
exports.getPoolList = getPoolList;
|
|
570
|
-
var getFactoryPoolList = function () { return Object.keys(curve_1.curve.constants.FACTORY_POOLS_DATA); };
|
|
571
|
-
exports.getFactoryPoolList = getFactoryPoolList;
|
|
572
|
-
var getCryptoFactoryPoolList = function () { return Object.keys(curve_1.curve.constants.CRYPTO_FACTORY_POOLS_DATA); };
|
|
573
|
-
exports.getCryptoFactoryPoolList = getCryptoFactoryPoolList;
|
|
574
491
|
var getUsdRate = function (coin) { return __awaiter(void 0, void 0, void 0, function () {
|
|
575
492
|
var coinAddress;
|
|
576
493
|
return __generator(this, function (_a) {
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
[{ "inputs": [], "payable": false, "stateMutability": "nonpayable", "type": "constructor" }, { "constant": true, "inputs": [], "name": "adai", "outputs": [{ "internalType": "contract IERC20", "name": "", "type": "address" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [{ "internalType": "uint256", "name": "_amount", "type": "uint256" }], "name": "claim", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [{ "internalType": "address", "name": "_claimer", "type": "address" }], "name": "claimable", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [], "name": "governance", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [{ "internalType": "address", "name": "_token", "type": "address" }, { "internalType": "uint256", "name": "_amount", "type": "uint256" }], "name": "seize", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [], "name": "yfi", "outputs": [{ "internalType": "contract IERC20", "name": "", "type": "address" }], "payable": false, "stateMutability": "view", "type": "function" }]
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"outputs": [],
|
|
4
|
-
"inputs": [
|
|
5
|
-
{
|
|
6
|
-
"type": "address",
|
|
7
|
-
"name": "_old"
|
|
8
|
-
},
|
|
9
|
-
{
|
|
10
|
-
"type": "address",
|
|
11
|
-
"name": "_old_token"
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
"type": "address",
|
|
15
|
-
"name": "_new"
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
"type": "address",
|
|
19
|
-
"name": "_new_token"
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
"type": "address[2]",
|
|
23
|
-
"name": "_coins"
|
|
24
|
-
}
|
|
25
|
-
],
|
|
26
|
-
"constant": false,
|
|
27
|
-
"payable": false,
|
|
28
|
-
"type": "constructor"
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
"name": "migrate",
|
|
32
|
-
"outputs": [],
|
|
33
|
-
"inputs": [],
|
|
34
|
-
"constant": false,
|
|
35
|
-
"payable": false,
|
|
36
|
-
"type": "function",
|
|
37
|
-
"gas": "106812"
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
"name": "coins",
|
|
41
|
-
"outputs": [
|
|
42
|
-
{
|
|
43
|
-
"type": "address",
|
|
44
|
-
"name": "out"
|
|
45
|
-
}
|
|
46
|
-
],
|
|
47
|
-
"inputs": [
|
|
48
|
-
{
|
|
49
|
-
"type": "int128",
|
|
50
|
-
"name": "arg0"
|
|
51
|
-
}
|
|
52
|
-
],
|
|
53
|
-
"stateMutability": "view",
|
|
54
|
-
"type": "function",
|
|
55
|
-
"gas": "1380"
|
|
56
|
-
}
|
|
57
|
-
]
|