Skip to content

Commit

Permalink
Feature/edit token mango suggest fix (#1869)
Browse files Browse the repository at this point in the history
  • Loading branch information
abrzezinski94 authored Oct 12, 2023
1 parent 4cd1b74 commit 5327c51
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 13 deletions.
53 changes: 47 additions & 6 deletions components/instructions/programs/mangoV4.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
MANGO_V4_ID,
MangoClient,
OracleProvider,
USDC_MINT,
toUiDecimals,
} from '@blockworks-foundation/mango-v4'
Expand All @@ -16,7 +17,6 @@ import EmptyWallet, {
getOracle,
getBestMarket,
EditTokenArgsFormatted,
isPythOracle,
FlatEditArgs,
getFormattedListingPresets,
} from '@utils/Mango/listingTools'
Expand All @@ -28,8 +28,13 @@ import tokenPriceService, {
TokenInfoWithoutDecimals,
} from '@utils/services/tokenPrice'
import {
LISTING_PRESETS,
LISTING_PRESETS_KEYS,
LISTING_PRESETS_PYTH,
MidPriceImpact,
coinTiersToNames,
getMidPriceImpacts,
getProposedTier,
} from '@blockworks-foundation/mango-v4-settings/lib/helpers/listingTools'
import { tryParseKey } from '@tools/validators/pubkey'
import Loading from '@components/Loading'
Expand Down Expand Up @@ -797,12 +802,41 @@ const instructions = () => ({
if (mint) {
const bank = mangoGroup.getFirstBankByMint(mint)
mintData = tokenPriceService.getTokenInfo(mint.toBase58())
const oracle =
args.oracleOpt ||
mangoGroup.banksMapByMint.get(mint.toBase58())![0]!.oracle
const isPyth = await isPythOracle(connection, oracle)
const isPyth = bank?.oracleProvider === OracleProvider.Pyth
const midPriceImpacts = getMidPriceImpacts(mangoGroup.pis)

const PRESETS = isPyth ? LISTING_PRESETS_PYTH : LISTING_PRESETS

const tokenToPriceImpact = midPriceImpacts
.filter((x) => x.avg_price_impact_percent < 1)
.reduce(
(acc: { [key: string]: MidPriceImpact }, val: MidPriceImpact) => {
if (
!acc[val.symbol] ||
val.target_amount > acc[val.symbol].target_amount
) {
acc[val.symbol] = val
}
return acc
},
{}
)

const priceImpact = tokenToPriceImpact[getApiTokenName(bank.name)]

const suggestedTier = getProposedTier(
PRESETS,
priceImpact?.target_amount,
bank.oracleProvider === OracleProvider.Pyth
)

liqudityTier = !mint.equals(USDC_MINT)
? await getSuggestedCoinTier(mint.toBase58(), !!isPyth)
? {
tier: suggestedTier,
priceImpact: priceImpact
? priceImpact.avg_price_impact_percent.toString()
: '',
}
: {
tier: 'ULTRA_PREMIUM',
priceImpact: '0',
Expand Down Expand Up @@ -1464,3 +1498,10 @@ const REDUCE_ONLY_OPTIONS = [
// const preimage = `${nameSpace}:${name}`
// return Buffer.from(sha256.digest(preimage)).slice(0, 8)
// }

const getApiTokenName = (bankName: string) => {
if (bankName === 'ETH (Portal)') {
return 'ETH'
}
return bankName
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"dependencies": {
"@blockworks-foundation/mango-mints-redemption": "0.0.8",
"@blockworks-foundation/mango-v4": "0.19.29",
"@blockworks-foundation/mango-v4-settings": "0.2.13",
"@blockworks-foundation/mango-v4-settings": "0.2.16",
"@blockworks-foundation/mangolana": "0.0.1-beta.15",
"@bonfida/spl-name-service": "0.1.47",
"@bundlr-network/client": "0.7.15",
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,10 @@
keccak256 "^1.0.6"
merkletreejs "^0.3.10"

"@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==
"@blockworks-foundation/[email protected].16":
version "0.2.16"
resolved "https://registry.yarnpkg.com/@blockworks-foundation/mango-v4-settings/-/mango-v4-settings-0.2.16.tgz#63f03c13d1677461ea42d3b1e9171042830c6cdc"
integrity sha512-9GCRZkVqTQsEUkqx/488pmSWM8I74Ght5AEzMPsuS5XlRGWIDjytWoBE0Y9wFVPrnRw2THTj0ZQft+vDwCYDCA==
dependencies:
bn.js "^5.2.1"
eslint-config-prettier "^9.0.0"
Expand Down Expand Up @@ -6294,12 +6294,12 @@ ansi-escapes@^4.2.1:
dependencies:
type-fest "^0.21.3"

[email protected]:
[email protected], ansi-regex@^2.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.1.tgz#123d6479e92ad45ad897d4054e3c7ca7db4944e1"
integrity sha512-+O9Jct8wf++lXxxFc4hc8LsjaSq0HFzzL7cVsw8pRDIPdjKD2mT4ytDZlLuSBZ4cLKZFXIrMGO7DbQCtMJJMKw==

"ansi-regex@>=3.0.1 <=5.0.1", ansi-regex@^2.0.0, ansi-regex@^3.0.0, ansi-regex@^4.1.0, ansi-regex@^5.0.0, ansi-regex@^5.0.1:
"ansi-regex@>=3.0.1 <=5.0.1", ansi-regex@^3.0.0, ansi-regex@^4.1.0, ansi-regex@^5.0.0, ansi-regex@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304"
integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==
Expand Down

1 comment on commit 5327c51

@vercel
Copy link

@vercel vercel bot commented on 5327c51 Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

governance-ui – ./

governance-ui-solana-labs.vercel.app
app.realms.today
governance-ui-git-main-solana-labs.vercel.app

Please sign in to comment.