From c30e21e1b34551443f754a48d99adbc90f840fa3 Mon Sep 17 00:00:00 2001 From: macket Date: Sat, 26 Aug 2023 21:15:47 +0400 Subject: [PATCH 1/3] fix: collateral duplication --- src/constants/utils.ts | 2 ++ src/crvusd.ts | 35 ++++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/constants/utils.ts b/src/constants/utils.ts index 4e07500..9f28924 100644 --- a/src/constants/utils.ts +++ b/src/constants/utils.ts @@ -7,6 +7,8 @@ export const lowerCaseLlammasAddresses = (llammas: IDict): IDict c.toLowerCase()); + const res: string[] = (await this.multicallProvider.all(calls) as string[]).map((c) => c.toLowerCase()); + const collaterals = res.filter((a, i) => i % 3 == 0) as string[]; + const amms = res.filter((a, i) => i % 3 == 1) as string[]; + const controllers = res.filter((a, i) => i % 3 == 2) as string[]; if (collaterals.length > 0) { for (const collateral of collaterals) this.setContract(collateral, ERC20ABI); @@ -174,9 +181,7 @@ class Crvusd implements Icrvusd { for (const collateral of collaterals) { calls.push( this.contracts[collateral].multicallContract.symbol(), - this.contracts[collateral].multicallContract.decimals(), - factoryMulticallContract.get_amm(collateral), - factoryMulticallContract.get_controller(collateral) + this.contracts[collateral].multicallContract.decimals() ) } const res = (await this.multicallProvider.all(calls)).map((x) => { @@ -184,18 +189,18 @@ class Crvusd implements Icrvusd { return x; }); - for (const collateral_address of collaterals) { - const is_eth = collateral_address === this.constants.WETH; - const [collateral_symbol, collateral_decimals, amm_address, controller_address] = res.splice(0, 4) as [string, number, string, string]; - this.setContract(amm_address, llammaABI); - this.setContract(controller_address, controllerABI); - const monetary_policy_address = await this.contracts[controller_address].contract.monetary_policy(this.constantOptions); + for (let i = 0; i < collaterals.length; i++) { + const is_eth = collaterals[i] === this.constants.WETH; + const [collateral_symbol, collateral_decimals] = res.splice(0, 2) as [string, number]; + this.setContract(amms[i], llammaABI); + this.setContract(controllers[i], controllerABI); + const monetary_policy_address = (await this.contracts[controllers[i]].contract.monetary_policy(this.constantOptions)).toLowerCase(); this.setContract(monetary_policy_address, MonetaryPolicy2ABI); this.constants.LLAMMAS[is_eth ? "eth" : collateral_symbol.toLowerCase()] = { - amm_address, - controller_address, + amm_address: amms[i], + controller_address: controllers[i], monetary_policy_address, - collateral_address: is_eth ? "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" : collateral_address, + collateral_address: is_eth ? "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" : collaterals[i], leverage_zap: "0x0000000000000000000000000000000000000000", collateral_symbol: is_eth ? "ETH" : collateral_symbol, collateral_decimals, From 8d8e666f3378442984bb862a7199cd37d3324cf6 Mon Sep 17 00:00:00 2001 From: macket Date: Sat, 26 Aug 2023 21:19:29 +0400 Subject: [PATCH 2/3] fix: userLoss --- src/external-api.ts | 7 ++----- src/llammas/LlammaTemplate.ts | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/external-api.ts b/src/external-api.ts index b9262a7..3c88289 100644 --- a/src/external-api.ts +++ b/src/external-api.ts @@ -16,12 +16,9 @@ export const _getPoolsFromApi = memoize( ) export const _getUserCollateral = memoize( - async (network: INetworkName, collateral: string, user: string, collateralDecimals = 18): Promise => { - console.log(network, collateral, user); - const url = `https://prices.curve.fi/v1/stablecoin/collateral/events/${network}/${collateral}/${user}`; - console.log(url); + async (network: INetworkName, controller: string, user: string, collateralDecimals = 18): Promise => { + const url = `https://prices.curve.fi/v1/stablecoin/controller/events/${network}/${controller}/${user}`; const response = await axios.get(url, { validateStatus: () => true }); - console.log(response); return crvusd.formatUnits(crvusd.parseUnits(response.data.total_collateral ?? "0.0", 0), collateralDecimals); }, { diff --git a/src/llammas/LlammaTemplate.ts b/src/llammas/LlammaTemplate.ts index bfe67e2..84d1be9 100644 --- a/src/llammas/LlammaTemplate.ts +++ b/src/llammas/LlammaTemplate.ts @@ -436,7 +436,7 @@ export class LlammaTemplate { public async userLoss(userAddress = ""): Promise<{ deposited_collateral: string, current_collateral_estimation: string, loss: string, loss_pct: string }> { userAddress = _getAddress(userAddress); const [deposited_collateral, _current_collateral_estimation] = await Promise.all([ - _getUserCollateral(crvusd.constants.NETWORK_NAME, this.collateral, userAddress, this.collateralDecimals), + _getUserCollateral(crvusd.constants.NETWORK_NAME, this.controller, userAddress, this.collateralDecimals), crvusd.contracts[this.address].contract.get_y_up(userAddress), ]); const current_collateral_estimation = crvusd.formatUnits(_current_collateral_estimation, this.collateralDecimals); From 3c85b0bd8ca4625522fc70360fa9b86b678ac4cd Mon Sep 17 00:00:00 2001 From: macket Date: Sat, 26 Aug 2023 21:19:50 +0400 Subject: [PATCH 3/3] build: v1.3.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 283272d..f3292dd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@curvefi/stablecoin-api", - "version": "1.3.4", + "version": "1.3.5", "description": "JavaScript library for Curve Stablecoin", "main": "lib/index.js", "author": "Macket",