Skip to content

Commit

Permalink
update mango settings lib
Browse files Browse the repository at this point in the history
  • Loading branch information
abrzezinski94 committed Oct 2, 2023
1 parent eab95b1 commit 33b3a60
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
12 changes: 7 additions & 5 deletions components/instructions/programs/mangoV4.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -795,6 +795,7 @@ const instructions = () => ({
}

if (mint) {
const bank = mangoGroup.getFirstBankByMint(mint)
mintData = tokenPriceService.getTokenInfo(mint.toBase58())
const oracle =
args.oracleOpt ||
Expand All @@ -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<string, never> = Object.keys(suggestedPreset).length
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 14 additions & 2 deletions utils/Mango/listingTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -452,10 +452,10 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==

"@blockworks-foundation/[email protected].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/[email protected].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"
Expand Down

0 comments on commit 33b3a60

Please sign in to comment.