Skip to content

Commit

Permalink
Merge pull request #780 from yieldprotocol/dev
Browse files Browse the repository at this point in the history
merge Dev updates
  • Loading branch information
brucedonovan authored Jan 21, 2022
2 parents 2b50d9c + b75796f commit c02cd27
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 97 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "app-v2",
"version": "2.0.60",
"version": "2.0.62",
"private": true,
"dependencies": {
"@multiavatar/multiavatar": "^1.0.6",
Expand Down
1 change: 1 addition & 0 deletions src/components/settings/SlippageSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const SlippageSetting = () => {
reverse
plain
type="number"
inputMode="decimal"
value={input || ''}
onChange={(event: any) => setInput(event.target.value)}
/>
Expand Down
30 changes: 14 additions & 16 deletions src/contexts/yieldEnv.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@
"CompoundMultiOracle" : "0x53FBa816BD69a7f2a096f58687f87dd3020d0d5c",
"ChainlinkMultiOracle": "0xcDCe5C87f691058B61f3A65913f1a3cBCbAd9F52",
"CompositeMultiOracle": "0xA81414a544D0bd8a28257F4038D3D24B08Dd9Bb4",
"YearnVaultMultiOracle": "0xC597E9cA52Afc13F7F5EDdaC9e53DEF569236016",
"Witch": "0x53C3760670f6091E1eC76B4dd27f73ba4CAd5061",
"lidoWrapHandler": "0x491aB93faa921C8E634F891F96512Be14fD3DbB1"
"lidoWrapHandler": "0x491aB93faa921C8E634F891F96512Be14fD3DbB1",
"YearnVaultMultiOracle": "0xC597E9cA52Afc13F7F5EDdaC9e53DEF569236016"
},
"4": {
"Cauldron": "0x8390Cd98C116F269a6E6A3b50Fb03B0931423164",
"Ladle": "0xbC0200F0AAD7C1c0bBB1CC7885E1e796DFFac3e0",
"Cauldron": "0xb2cf78ccA863675Ef61a0c696885DED0C833F8f3",
"Ladle": "0x45f502A7358ec631c7a422270922d7dFA142cb9C",
"CompoundMultiOracle" : "0xeCA876c39DF7b75281Ea78eB35912fa1CC8f9482",
"ChainlinkMultiOracle": "0xBDBF01Ee32485aF94e316C395765F5Af2bf4b4dB",
"CompositeMultiOracle": "0x8482BF1e17ceF57109F34C259d39d5B9BB9A4e13",
"YearnVaultMultiOracle": "0x88175a3e14F905ecCe464aF2A8E99f26159d4Cb8",
"Witch": "0x458098338c136D1c4410910e6F893316D86Ba837",
"lidoWrapHandler": "0x80d0CfceE7dfa135189e44d617032d5A7Cc2705b"
"Witch": "0x5cEe0925647722e7ed32dcaf5A2DeFD3872Edb6F",
"lidoWrapHandler": "0x80d0CfceE7dfa135189e44d617032d5A7Cc2705b",
"YearnVaultMultiOracle": "0x88175a3e14F905ecCe464aF2A8E99f26159d4Cb8"
},
"42": {
"Cauldron": "0xacb1fb5E88ba69E12BDE76A4c373F1935d9fe912",
"Cauldron": "0x82Dfaef826C8c190E9b472896a9a99165Ccee35a",
"Ladle": "0xe7bae0445B9a1DBE834a7379fbE23C6d2Bd61C59",
"CompoundMultiOracle" : "0x23F5F7a17117ba794Fcc5F46Fbf635edD2596Bb6",
"ChainlinkMultiOracle": "0xBcdc8bad83ca8053DFA6B1CBAEB7E71699254a3b",
"CompositeMultiOracle": "0xaF45D0277399E79Bf599d72fF4521f8Dc4A060E1",
"YearnVaultMultiOracle": "0xaF45D0277399E79Bf599d72fF4521f8Dc4A060E1",
"Witch": "0xA421B81481e0d150740f8F137FB10b1b747974a8",
"lidoWrapHandler": "0x491aB93faa921C8E634F891F96512Be14fD3DbB1"
"lidoWrapHandler": "0x491aB93faa921C8E634F891F96512Be14fD3DbB1",
"YearnVaultMultiOracle": "0xaF45D0277399E79Bf599d72fF4521f8Dc4A060E1"
},
"421611": {
"Cauldron": "0x589fb605D165D0cd32608cC44dAcB87151d3B913",
Expand All @@ -46,12 +46,10 @@
"0x8e8D6aB093905C400D583EfD37fbeEB1ee1c0c39"
],
"4": [
"0x1B496E901263b1EFa32880D6d13e325A8cb2D5c1",
"0x3a333FEc691DFCa0907Bc80024C27d0bbe7D022f",
"0x455F45e240436B75218E71B72472fad1a28Bc7A9",
"0xE40D644017BfC8b233bEf9cE2Eab55b512B964B4",
"0x4ABe302854c59546E37f46a8aa5DF482cFC683B0",
"0xccf1374c3d12AE3aAd51419e2CDed785C39d47A7"
"0x8468B9154D777Dc4520fDA275d30D8D663841C1d",
"0x6020a656a0421aFd96b02523D17fA23E206CD453",
"0x1a017DBc08317b105E266139F888c7ae6eDd6a0F",
"0xc946e0b5e815a7b22F563a569895663BE54f152A"
],
"42": [
"0xad1fBd05f4FDB81C1bAE82172E9913a7c4152154",
Expand Down
65 changes: 32 additions & 33 deletions src/hooks/actionHooks/useAddLiquidity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
IUserContext,
IUserContextActions,
IUserContextState,
ISettingsContext,
} from '../../types';
import { cleanValue, getTxCode } from '../../utils/appUtils';
import { BLANK_VAULT } from '../../utils/constants';
Expand All @@ -27,12 +28,12 @@ import { ChainContext } from '../../contexts/ChainContext';
export const useAddLiquidity = () => {
const {
settingsState: { slippageTolerance, diagnostics, approveMax },
} = useContext(SettingsContext);
} = useContext(SettingsContext) as ISettingsContext;

const {
chainState: { contractMap },
} = useContext(ChainContext);
const { userState, userActions }: { userState: IUserContextState; userActions: IUserContextActions } = useContext(
const { userState, userActions }: { userState: IUserContextState; userActions: IUserContextActions } = useContext(
UserContext
) as IUserContext;
const { activeAccount: account, assetMap, seriesMap } = userState;
Expand All @@ -59,12 +60,12 @@ export const useAddLiquidity = () => {
const cleanInput = cleanValue(input, base?.decimals!);

const _input = ethers.utils.parseUnits(cleanInput, base?.decimals);
const _inputLessSlippage = calculateSlippage(_input, slippageTolerance, true);
const _inputLessSlippage = calculateSlippage(_input, slippageTolerance.toString(), true);

const [cachedBaseReserves, cachedFyTokenReserves] = await series?.poolContract.getCache()!;
const cachedRealReserves = cachedFyTokenReserves.sub(series?.totalSupply!);

const _fyTokenToBeMinted = fyTokenForMint(
const [_fyTokenToBeMinted] = fyTokenForMint(
cachedBaseReserves,
cachedRealReserves,
cachedFyTokenReserves,
Expand All @@ -76,8 +77,7 @@ export const useAddLiquidity = () => {
slippageTolerance
);

console.log(cachedBaseReserves.toString(), cachedRealReserves.toString())

console.log(cachedBaseReserves.toString(), cachedRealReserves.toString());
const [minRatio, maxRatio] = calcPoolRatios(cachedBaseReserves, cachedRealReserves);

const [_baseToPool, _baseToFyToken] = splitLiquidity(
Expand All @@ -87,37 +87,36 @@ export const useAddLiquidity = () => {
true
) as [BigNumber, BigNumber];

const _baseToPoolWithSlippage = BigNumber.from(calculateSlippage(_baseToPool, slippageTolerance));
const _baseToPoolWithSlippage = BigNumber.from(calculateSlippage(_baseToPool, slippageTolerance.toString()));

/* if approveMAx, check if signature is still required */
const alreadyApproved = (await base.getAllowance(account!, ladleAddress)).gt(_input);

/* DIAGNOSITCS */

console.log(
'input: ',
_input.toString(),
'inputLessSlippage: ',
_inputLessSlippage.toString(),
'base: ',
cachedBaseReserves.toString(),
'real: ',
cachedRealReserves.toString(),
'virtual: ',
cachedFyTokenReserves.toString(),
'>> baseSplit: ',
_baseToPool.toString(),
'>> fyTokenSplit: ',
_baseToFyToken.toString(),
'>> baseSplitWithSlippage: ',
_baseToPoolWithSlippage.toString(),
'>> minRatio',
minRatio.toString(),
'>> maxRatio',
maxRatio.toString(),
'matching vault id',
matchingVaultId
);
console.log(
'input: ',
_input.toString(),
'inputLessSlippage: ',
_inputLessSlippage.toString(),
'base: ',
cachedBaseReserves.toString(),
'real: ',
cachedRealReserves.toString(),
'virtual: ',
cachedFyTokenReserves.toString(),
'>> baseSplit: ',
_baseToPool.toString(),
'>> fyTokenSplit: ',
_baseToFyToken.toString(),
'>> baseSplitWithSlippage: ',
_baseToPoolWithSlippage.toString(),
'>> minRatio',
minRatio.toString(),
'>> maxRatio',
maxRatio.toString(),
'matching vault id',
matchingVaultId
);

/**
* GET SIGNTURE/APPROVAL DATA
Expand All @@ -128,7 +127,7 @@ export const useAddLiquidity = () => {
target: base,
spender: 'LADLE',
amount: _input,
ignoreIf: alreadyApproved===true,
ignoreIf: alreadyApproved === true,
},
],
txCode
Expand Down
10 changes: 5 additions & 5 deletions src/hooks/viewHelperHooks/usePoolHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useContext, useEffect, useState } from 'react';
import { ethers, BigNumber } from 'ethers';
import { UserContext } from '../../contexts/UserContext';
import { IAsset, ISeries, IStrategy, IVault } from '../../types';
import { IAsset, ISeries, ISettingsContext, IStrategy, IVault } from '../../types';
import { cleanValue } from '../../utils/appUtils';
import {
fyTokenForMint,
Expand All @@ -10,14 +10,15 @@ import {
maxFyTokenOut,
burnFromStrategy,
burn,
calculateSlippage,
} from '../../utils/yieldMath';
import { SettingsContext } from '../../contexts/SettingsContext';

export const usePoolHelpers = (input: string | undefined, removeLiquidityView: boolean = false) => {
/* STATE FROM CONTEXT */
const {
settingsState: { slippageTolerance, diagnostics },
} = useContext(SettingsContext);
} = useContext(SettingsContext) as ISettingsContext;

const {
userState: { selectedSeries, selectedBase, selectedStrategy, seriesMap, vaultMap, assetMap, activeAccount },
Expand Down Expand Up @@ -120,11 +121,11 @@ export const usePoolHelpers = (input: string | undefined, removeLiquidityView: b
strategySeries.decimals
);

_fyTokenToBuy = fyTokenForMint(
[_fyTokenToBuy] = fyTokenForMint(
strategySeries.baseReserves,
strategySeries.fyTokenRealReserves,
strategySeries.fyTokenReserves,
_input,
calculateSlippage(_input, slippageTolerance.toString(), true),
strategySeries.getTimeTillMaturity(),
strategySeries.ts,
strategySeries.g1,
Expand Down Expand Up @@ -217,7 +218,6 @@ export const usePoolHelpers = (input: string | undefined, removeLiquidityView: b
setRemoveBaseReceived_(ethers.utils.formatUnits(_baseVal, strategySeries.decimals));
setRemoveFyTokenReceived(_fyTokenVal);
setRemoveFyTokenReceived_(ethers.utils.formatUnits(_fyTokenVal, strategySeries.decimals));

} else {
/* CASE> fytokenReceived less than debt : USE REMOVE OPTION 1 */
diagnostics &&
Expand Down
Loading

0 comments on commit c02cd27

Please sign in to comment.