From f26b3c92386e37e890df96b0a2fce650db575478 Mon Sep 17 00:00:00 2001 From: Makeev Ivan Date: Tue, 11 Jan 2022 10:54:38 +0300 Subject: [PATCH 01/10] fix: empty string address --- src/constants/aliases.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constants/aliases.ts b/src/constants/aliases.ts index 51768d7b..f42ed018 100644 --- a/src/constants/aliases.ts +++ b/src/constants/aliases.ts @@ -10,7 +10,7 @@ export const ALIASES_ETHEREUM = { export const ALIASES_POLYGON = { "crv": "0x172370d5cd63279efa6d502dab29171933a610af", - "minter": "", + "minter": "0xd061D61a4d941c39E5453435B6345Dc261C2fcE0", "voting_escrow": "0x5f3b5DfEb7B28CDbD7FAba78963EE202a494e2A2", "gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB", "address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383", From 5bb9be34c64bcaf2906218b684c06793ad0fe0bf Mon Sep 17 00:00:00 2001 From: Makeev Ivan Date: Tue, 11 Jan 2022 11:52:56 +0300 Subject: [PATCH 02/10] fix: https in stats URLs --- src/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 48383c13..a79d423c 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -246,9 +246,9 @@ export const _getUsdRate = async (assetId: string): Promise => { export const _getStatsUrl = (isCrypto = false): string => { if (curve.chainId === 1 || curve.chainId === 1337) { - return isCrypto ? "http://stats.curve.fi/raw-stats-crypto/apys.json" : "http://stats.curve.fi/raw-stats/apys.json"; + return isCrypto ? "https://stats.curve.fi/raw-stats-crypto/apys.json" : "https://stats.curve.fi/raw-stats/apys.json"; } else if (curve.chainId === 137) { - return "http://stats.curve.fi/raw-stats-polygon/apys.json" + return "https://stats.curve.fi/raw-stats-polygon/apys.json" } else { throw Error(`Unsupported network id${curve.chainId}`) } From e0a5c3dfef3597d8dff998e0d69f6b27c797f3c6 Mon Sep 17 00:00:00 2001 From: Makeev Ivan Date: Tue, 11 Jan 2022 22:04:56 +0300 Subject: [PATCH 03/10] feat: ramping A parameters --- src/pools.ts | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/src/pools.ts b/src/pools.ts index d0217916..7a07de97 100644 --- a/src/pools.ts +++ b/src/pools.ts @@ -184,15 +184,35 @@ export class Pool { return ethers.utils.formatUnits(_expected); } - private getParameters = async (): Promise<{ virtualPrice: string, fee: string, adminFee: string, A: string, gamma?: string }> => { + private getParameters = async (): Promise<{ + virtualPrice: string, + fee: string, + adminFee: string, + A: string, + future_A?: string, + initial_A?: string, + future_A_time?: number, + initial_A_time?: number, + gamma?: string, + }> => { + const multicallContract = curve.contracts[this.swap].multicallContract; + const calls = [ - curve.contracts[this.swap].multicallContract.get_virtual_price(), - curve.contracts[this.swap].multicallContract.fee(), - curve.contracts[this.swap].multicallContract.admin_fee(), - curve.contracts[this.swap].multicallContract.A(), + multicallContract.get_virtual_price(), + multicallContract.fee(), + multicallContract.admin_fee(), + multicallContract.A(), ] - - if (this.isCrypto) calls.push(curve.contracts[this.swap].multicallContract.gamma()) + if (this.isCrypto) calls.push(multicallContract.gamma()) + + const additionalCalls = this.isCrypto ? [] : [multicallContract.future_A()]; + if ('initial_A' in multicallContract) { + additionalCalls.push( + multicallContract.initial_A(), + multicallContract.future_A_time(), + multicallContract.initial_A_time() + ); + } const [_virtualPrice, _fee, _adminFee, _A, _gamma] = await curve.multicallProvider.all(calls) as ethers.BigNumber[]; const [virtualPrice, fee, adminFee, A, gamma] = [ @@ -204,7 +224,16 @@ export class Pool { ] - return { virtualPrice, fee, adminFee, A, gamma }; + const A_PRECISION = curve.chainId === 1 && ['compound', 'usdt', 'y', 'busd', 'susd', 'pax', 'ren', 'sbtc', 'hbtc', '3pool'].includes(this.name) ? 1 : 100; + const [_future_A, _initial_A, _future_A_time, _initial_A_time] = await curve.multicallProvider.all(additionalCalls) as ethers.BigNumber[] + const [future_A, initial_A, future_A_time, initial_A_time] = [ + _future_A ? String(Number(ethers.utils.formatUnits(_future_A, 0)) / A_PRECISION) : undefined, + _initial_A ? String(Number(ethers.utils.formatUnits(_initial_A, 0)) / A_PRECISION) : undefined, + _future_A_time ? Number(ethers.utils.formatUnits(_future_A_time, 0)) * 1000 : undefined, + _initial_A_time ? Number(ethers.utils.formatUnits(_initial_A_time, 0)) * 1000 : undefined, + ] + + return { virtualPrice, fee, adminFee, A, future_A, initial_A, future_A_time, initial_A_time, gamma }; } private getPoolBalances = async (): Promise => { From 0a1634cad6fba19d05e42924ae510f7b03ac00e2 Mon Sep 17 00:00:00 2001 From: Makeev Ivan Date: Wed, 12 Jan 2022 12:05:01 +0300 Subject: [PATCH 04/10] fix: underlying coins in getTotalLiquidity --- src/pools.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pools.ts b/src/pools.ts index 7a07de97..4d013dbc 100644 --- a/src/pools.ts +++ b/src/pools.ts @@ -273,10 +273,10 @@ export class Pool { } private getTotalLiquidity = async (): Promise => { - const balances = await this.getPoolWrappedBalances(); + const balances = await this.getPoolBalances(); const promises = []; - for (const addr of this.coinAddresses) { + for (const addr of this.underlyingCoinAddresses) { promises.push(_getUsdRate(addr)) } From 050e857667a65d904c8bc74a5e45306227218529 Mon Sep 17 00:00:00 2001 From: Makeev Ivan Date: Wed, 12 Jan 2022 12:23:56 +0300 Subject: [PATCH 05/10] BREAKING: getBaseApy returns object --- src/pools.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/pools.ts b/src/pools.ts index 4d013dbc..5a509932 100644 --- a/src/pools.ts +++ b/src/pools.ts @@ -80,7 +80,7 @@ export class Pool { getPoolWrappedBalances: () => Promise, getTotalLiquidity: () => Promise, getVolume: () => Promise, - getBaseApy: () => Promise<[daily: string, weekly: string, monthly: string, total: string]>, + getBaseApy: () => Promise<{day: string, week: string, month: string, total: string}>, getTokenApy: () => Promise<[baseApy: string, boostedApy: string]>, getRewardsApy: () => Promise, } @@ -297,14 +297,21 @@ export class Pool { return String(volume * usdRate) } - private getBaseApy = async (): Promise<[daily: string, weekly: string, monthly: string, total: string]> => { + private getBaseApy = async (): Promise<{day: string, week: string, month: string, total: string}> => { const name = (this.name === 'ren' && curve.chainId === 1) ? 'ren2' : this.name === 'sbtc' ? 'rens' : this.name; const statsUrl = _getStatsUrl(this.isCrypto); const apy = (await axios.get(statsUrl)).data.apy; - return [apy.day[name], apy.week[name], apy.month[name], apy.total[name]].map( + const formattedApy = [apy.day[name], apy.week[name], apy.month[name], apy.total[name]].map( (x: number) => (x * 100).toFixed(4) ) as [daily: string, weekly: string, monthly: string, total: string] + + return { + day: formattedApy[0], + week: formattedApy[1], + month: formattedApy[2], + total: formattedApy[3], + } } private getTokenApy = async (): Promise<[baseApy: string, boostedApy: string]> => { From cda359b059b3464b33901ff7f6a68c88aec4deb1 Mon Sep 17 00:00:00 2001 From: Makeev Ivan Date: Wed, 12 Jan 2022 12:31:41 +0300 Subject: [PATCH 06/10] feat: getPoolList --- src/index.ts | 3 ++- src/utils.ts | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index ca82b205..c6007324 100644 --- a/src/index.ts +++ b/src/index.ts @@ -36,7 +36,7 @@ import { withdrawLockedCrvEstimateGas, withdrawLockedCrv, } from "./boosting"; -import { getBalances, getAllowance, hasAllowance, ensureAllowanceEstimateGas, ensureAllowance } from "./utils"; +import { getBalances, getAllowance, hasAllowance, ensureAllowanceEstimateGas, ensureAllowance, getPoolList } from "./utils"; async function init ( providerType: 'JsonRpc' | 'Web3' | 'Infura' | 'Alchemy', @@ -56,6 +56,7 @@ function setCustomFeeData (customFeeData: { gasPrice?: number, maxFeePerGas?: nu const curve = { init, + getPoolList, setCustomFeeData, signerAddress: '', chainId: 0, diff --git a/src/utils.ts b/src/utils.ts index a79d423c..82fdd27d 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -253,3 +253,5 @@ export const _getStatsUrl = (isCrypto = false): string => { throw Error(`Unsupported network id${curve.chainId}`) } } + +export const getPoolList = (): string[] => Object.keys(POOLS_DATA); From 6f455f9841a2633bbeb2bcc91c47160659f0981b Mon Sep 17 00:00:00 2001 From: Makeev Ivan Date: Wed, 12 Jan 2022 12:43:53 +0300 Subject: [PATCH 07/10] docs: updated stats section in README --- README.md | 43 ++++++++++++++++++++++++------------------- test/readme.test.ts | 20 ++++++++++---------- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 161fa094..27662da0 100644 --- a/README.md +++ b/README.md @@ -218,41 +218,46 @@ import curve from "@curvefi/api"; (async () => { await curve.init('JsonRpc', {}, {gasPrice: 0, maxFeePerGas: 0, maxPriorityFeePerGas: 0}); - const saave = new curve.Pool('aave'); + const aave = new curve.Pool('aave'); - console.log(await saave.stats.getParameters()); + console.log(await aave.stats.getParameters()); // { - // virtualPrice: '1.051888073134291314', + // virtualPrice: '1.082056814810440924', // fee: '0.04', // adminFee: '0.02', - // A: '100', + // A: '2000', + // future_A: '2000', + // initial_A: '200', + // future_A_time: 1628525830000, + // initial_A_time: 1627923611000, // gamma: undefined // } + + + console.log(await aave.stats.getPoolBalances()); + // [ '19619514.600802512613372364', '18740372.790339', '16065974.167437' ] - console.log(await saave.stats.getPoolBalances()); - // [ '56379002.278506498342855456', '40931955.428972956435172989' ] - - console.log(await saave.stats.getPoolWrappedBalances()); - // [ '56379002.278506498342855456', '40931955.428972956435172989' ] + console.log(await aave.stats.getPoolWrappedBalances()); + // [ '19619514.600802512613372364', '18740372.790339', '16065974.167437' ] - console.log(await saave.stats.getTotalLiquidity()); - // 97172772.77289483 + console.log(await aave.stats.getTotalLiquidity()); + // 54425861.55857851 - console.log(await saave.stats.getVolume()); - // 1022328.1797568246 + console.log(await aave.stats.getVolume()); + // 175647.68180084194 - console.log(await saave.stats.getBaseApy()); - // [ '3.2200', '3.5690', '3.0858', '5.9629' ] + console.log(await aave.stats.getBaseApy()); + // { day: '3.2015', week: '3.1185', month: '3.1318', total: '7.7286' } - console.log(await saave.stats.getTokenApy()); - // [ '0.0167', '0.0417' ] + console.log(await aave.stats.getTokenApy()); + // [ '0.4093', '1.0233' ] - console.log(await saave.stats.getRewardsApy()); + console.log(await aave.stats.getRewardsApy()); // [ // { // token: '0x4da27a545c0c5B758a6BA100e3a049001de870f5', // symbol: 'stkAAVE', - // apy: '0.5807714739298449' + // apy: '0.4978306501849664' // } // ] })() diff --git a/test/readme.test.ts b/test/readme.test.ts index bc53ba92..1b5f7709 100644 --- a/test/readme.test.ts +++ b/test/readme.test.ts @@ -33,16 +33,16 @@ const balancesTest = async () => { const statsTest = async () => { await curve.init('JsonRpc', {}, { gasPrice: 0 }); - const saave = new curve.Pool('aave'); - - console.log(await saave.stats.getParameters()); - console.log(await saave.stats.getPoolBalances()); - console.log(await saave.stats.getPoolWrappedBalances()); - console.log(await saave.stats.getTotalLiquidity()); - console.log(await saave.stats.getVolume()); - console.log(await saave.stats.getBaseApy()); - console.log(await saave.stats.getTokenApy()); - console.log(await saave.stats.getRewardsApy()); + const aave = new curve.Pool('aave'); + + console.log(await aave.stats.getParameters()); + console.log(await aave.stats.getPoolBalances()); + console.log(await aave.stats.getPoolWrappedBalances()); + console.log(await aave.stats.getTotalLiquidity()); + console.log(await aave.stats.getVolume()); + console.log(await aave.stats.getBaseApy()); + console.log(await aave.stats.getTokenApy()); + console.log(await aave.stats.getRewardsApy()); } const poolTest = async () => { From 12cfe00abd712082cf27e7436bc7aaa44d2256bf Mon Sep 17 00:00:00 2001 From: Makeev Ivan Date: Wed, 12 Jan 2022 16:44:30 +0300 Subject: [PATCH 08/10] docs: available pools --- README.md | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 27662da0..c4d31ba4 100644 --- a/README.md +++ b/README.md @@ -122,12 +122,36 @@ const WalletProvider: FunctionComponent = ({ children }) => { ... ``` +## Available pools +```ts +import curve from "@curvefi/api"; + +(async () => { + await curve.init('JsonRpc', {}, {gasPrice: 0, maxFeePerGas: 0, maxPriorityFeePerGas: 0}); + + console.log(curve.getPoolList()); + // [ + // 'compound', 'usdt', 'y', 'busd', + // 'susd', 'pax', 'ren', 'sbtc', + // 'hbtc', '3pool', 'gusd', 'husd', + // 'usdk', 'usdn', 'musd', 'rsv', + // 'tbtc', 'dusd', 'pbtc', 'bbtc', + // 'obtc', 'seth', 'eurs', 'ust', + // 'aave', 'steth', 'saave', 'ankreth', + // 'usdp', 'ib', 'link', 'tusd', + // 'frax', 'lusd', 'busdv2', 'reth', + // 'alusd', 'mim', 'tricrypto2', 'eurt', + // 'eurtusd', 'crveth', 'cvxeth' + // ] +})() +```` + ## Balances ```ts import curve from "@curvefi/api"; (async () => { - await curve.init('JsonRpc', {}, { gasPrice: 0, maxFeePerGas: 0, maxPriorityFeePerGas: 0, chainId: 1 }); + await curve.init('JsonRpc', {}, { gasPrice: 0, maxFeePerGas: 0, maxPriorityFeePerGas: 0 }); console.log(await curve.getBalances(['DAI', 'sUSD'])); // OR console.log(await curve.getBalances(['0x6B175474E89094C44Da98b954EedeAC495271d0F', '0x57Ab1ec28D129707052df4dF418D58a2D46d5f51'])); From 28c4a6f7b9ff7a01bed325d3582ad2d2384b099d Mon Sep 17 00:00:00 2001 From: Makeev Ivan Date: Wed, 12 Jan 2022 16:45:24 +0300 Subject: [PATCH 09/10] ci: allow-unknown commits in publish workflow --- .github/workflows/publish.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 2c10b2d3..625a5a07 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -18,6 +18,8 @@ jobs: - name: Changelog id: Changelog uses: scottbrenner/generate-changelog-action@master + with: + allow-unknown: true - name: Create Release id: create_release uses: actions/create-release@v1 From 14968a9d10100bd15872c4e1b8e07ec29d313194 Mon Sep 17 00:00:00 2001 From: Makeev Ivan Date: Wed, 12 Jan 2022 16:46:51 +0300 Subject: [PATCH 10/10] build: v1.15.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b327f545..6cbe5214 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@curvefi/api", - "version": "1.15.0", + "version": "1.15.1", "description": "JavaScript library for curve.fi", "main": "lib/index.js", "scripts": {