From 33b3a60d65b51ae6c1de2ae057dea123288de43d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Brzezin=CC=81ski?= Date: Mon, 2 Oct 2023 16:23:53 +0200 Subject: [PATCH 1/3] update mango settings lib --- components/instructions/programs/mangoV4.tsx | 12 +++++++----- package.json | 2 +- utils/Mango/listingTools.ts | 16 ++++++++++++++-- yarn.lock | 8 ++++---- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/components/instructions/programs/mangoV4.tsx b/components/instructions/programs/mangoV4.tsx index 92dfb74ca0..8f409cd22f 100644 --- a/components/instructions/programs/mangoV4.tsx +++ b/components/instructions/programs/mangoV4.tsx @@ -17,8 +17,8 @@ import EmptyWallet, { getBestMarket, EditTokenArgsFormatted, isPythOracle, - getFormattedListingPresets, FlatEditArgs, + getFormattedListingPresets, } from '@utils/Mango/listingTools' import { secondsToHours } from 'date-fns' import WarningFilledIcon from '@carbon/icons-react/lib/WarningFilled' @@ -795,6 +795,7 @@ const instructions = () => ({ } if (mint) { + const bank = mangoGroup.getFirstBankByMint(mint) mintData = tokenPriceService.getTokenInfo(mint.toBase58()) const oracle = args.oracleOpt || @@ -807,11 +808,12 @@ const instructions = () => ({ priceImpact: '0', } - const suggestedPreset = getFormattedListingPresets(!!isPyth)[ - liqudityTier.tier! - ] + const suggestedPreset = getFormattedListingPresets( + !!isPyth, + bank.nativeDeposits().mul(bank.price).toNumber() + )[liqudityTier.tier!] suggestedUntrusted = liqudityTier.tier === 'UNTRUSTED' - + console.log(suggestedPreset) const suggestedFormattedPreset: | EditTokenArgsFormatted | Record = Object.keys(suggestedPreset).length diff --git a/package.json b/package.json index ced7b3deaa..a1d970630e 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ }, "dependencies": { "@blockworks-foundation/mango-v4": "0.19.29", - "@blockworks-foundation/mango-v4-settings": "0.2.10", + "@blockworks-foundation/mango-v4-settings": "0.2.13", "@blockworks-foundation/mangolana": "0.0.1-beta.15", "@bonfida/spl-name-service": "0.1.47", "@bundlr-network/client": "0.7.15", diff --git a/utils/Mango/listingTools.ts b/utils/Mango/listingTools.ts index 7ea74f1277..3e1976a127 100644 --- a/utils/Mango/listingTools.ts +++ b/utils/Mango/listingTools.ts @@ -8,6 +8,7 @@ import { LISTING_PRESETS_KEYS, LISTING_PRESETS_PYTH, ListingPreset, + getTierWithAdjustedNetBorrows, } from '@blockworks-foundation/mango-v4-settings/lib/helpers/listingTools' import { AnchorProvider, Program, Wallet } from '@coral-xyz/anchor' import { MAINNET_USDC_MINT } from '@foresight-tmp/foresight-sdk/dist/consts' @@ -157,12 +158,23 @@ type ProposedListingPresets = { [key in LISTING_PRESETS_KEYS]: FormattedListingPreset } -export const getFormattedListingPresets = (isPythOracle: boolean) => { +export const getFormattedListingPresets = ( + isPythOracle: boolean, + currentTotalDepositsInUsdc?: number +) => { const PRESETS = isPythOracle ? LISTING_PRESETS_PYTH : LISTING_PRESETS + const PROPOSED_LISTING_PRESETS: ProposedListingPresets = Object.keys( PRESETS ).reduce((accumulator, key) => { - accumulator[key] = transformPresetToProposed(PRESETS[key]) + accumulator[key] = transformPresetToProposed( + !currentTotalDepositsInUsdc + ? PRESETS[key] + : getTierWithAdjustedNetBorrows( + PRESETS[key], + currentTotalDepositsInUsdc + ) + ) return accumulator }, {} as ProposedListingPresets) return PROPOSED_LISTING_PRESETS diff --git a/yarn.lock b/yarn.lock index d67100da89..b41bd79626 100644 --- a/yarn.lock +++ b/yarn.lock @@ -452,10 +452,10 @@ resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39" integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw== -"@blockworks-foundation/mango-v4-settings@0.2.10": - version "0.2.10" - resolved "https://registry.yarnpkg.com/@blockworks-foundation/mango-v4-settings/-/mango-v4-settings-0.2.10.tgz#d09a74b743b1eb44bcad46b09680035fb8ec5a85" - integrity sha512-pQ7TfAxBdoF0fNVQ7PsT4TW5cpGibTjZadXcYlbyfetxQbTQS9mgghfGaq/TDFz/rHa6FS2FJ0xCJBoy7FNDbg== +"@blockworks-foundation/mango-v4-settings@0.2.13": + version "0.2.13" + resolved "https://registry.yarnpkg.com/@blockworks-foundation/mango-v4-settings/-/mango-v4-settings-0.2.13.tgz#c75c1ea2e8e4c7888e45e979d75d18a2342142bf" + integrity sha512-C5djeBkeM1u2IuFTu9qu9B78iCdq2Fu/M2VEXUlZWDBmU3eMUMtQ60qc+nBL+HedrBriApM4WaRSu/RwBs3IBQ== dependencies: bn.js "^5.2.1" eslint-config-prettier "^9.0.0" From 43bebe4f878bd4a2dd77f3067f6c733e515632d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Brzezin=CC=81ski?= Date: Mon, 2 Oct 2023 16:39:21 +0200 Subject: [PATCH 2/3] unlock daily --- .../components/Account/LockTokensModal.tsx | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/VoteStakeRegistry/components/Account/LockTokensModal.tsx b/VoteStakeRegistry/components/Account/LockTokensModal.tsx index 0e042f0f2f..f4bd7b58ef 100644 --- a/VoteStakeRegistry/components/Account/LockTokensModal.tsx +++ b/VoteStakeRegistry/components/Account/LockTokensModal.tsx @@ -376,16 +376,10 @@ const LockTokensModal = ({ onChange={(type) => setLockupType( //@ts-ignore - lockupTypes - .filter( - (x) => x.value !== MONTHLY && x.value !== DAILY - ) - .find((t) => t.displayName === type) + lockupTypes.find((t) => t.displayName === type) ) } - values={lockupTypes - .filter((x) => x.value !== MONTHLY && x.value !== DAILY) - .map((type) => type.displayName)} + values={lockupTypes.map((type) => type.displayName)} /> From f702da1689a3c865b2ce31bf026bc07f51688075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Brzezin=CC=81ski?= Date: Mon, 2 Oct 2023 16:41:02 +0200 Subject: [PATCH 3/3] fix --- VoteStakeRegistry/components/Account/LockTokensModal.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/VoteStakeRegistry/components/Account/LockTokensModal.tsx b/VoteStakeRegistry/components/Account/LockTokensModal.tsx index f4bd7b58ef..7e94e1aa01 100644 --- a/VoteStakeRegistry/components/Account/LockTokensModal.tsx +++ b/VoteStakeRegistry/components/Account/LockTokensModal.tsx @@ -37,7 +37,6 @@ import { Period, VestingPeriod, vestingPeriods, - DAILY, } from 'VoteStakeRegistry/tools/types' import BigNumber from 'bignumber.js' import useVotePluginsClientStore from 'stores/useVotePluginsClientStore'