Skip to content
This repository has been archived by the owner on Feb 9, 2025. It is now read-only.

Commit

Permalink
add tier matching mango (#2087)
Browse files Browse the repository at this point in the history
  • Loading branch information
abrzezinski94 authored Jan 27, 2024
1 parent 596ea98 commit 3c894bd
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 23 deletions.
61 changes: 41 additions & 20 deletions components/instructions/programs/mangoV4.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,30 @@ const instructions = () => ({

const formattedProposedArgs = getFormattedListingValues(args)

const suggestedPreset = getFormattedListingPresets(
const formattedSuggestedPresets = getFormattedListingPresets(
proposedOracle.type === 'Pyth',
0,
mintInfo?.account.decimals || 0,
oracleData.uiPrice
)[presetInfo.presetKey]
)

const currentListingArgsMatchedTier = Object.values(
formattedSuggestedPresets
).find((preset) => {
const formattedPreset = getFormattedListingValues({
tokenIndex: args.tokenIndex,
name: args.name,
oracle: args.oracle,
...preset,
})

return (
JSON.stringify(formattedProposedArgs) ===
JSON.stringify(formattedPreset)
)
})

const suggestedPreset = formattedSuggestedPresets[presetInfo.presetKey]

const suggestedFormattedPreset: ListingArgsFormatted = Object.keys(
suggestedPreset
Expand Down Expand Up @@ -292,7 +310,7 @@ const instructions = () => ({
if (x === 'depositLimit') {
return !isDifferenceWithin5Percent(
Number(formattedProposedArgs['depositLimit'] || 0),
Number(suggestedFormattedPreset['depositLimit'])
Number(suggestedFormattedPreset['depositLimit'] || 0)
)
}
return true
Expand Down Expand Up @@ -356,6 +374,13 @@ const instructions = () => ({
carefully
</h3>
)}
{currentListingArgsMatchedTier && (
<h3 className="text-green flex items-center">
<CheckCircleIcon className="h-4 w-4 fill-current mr-2 flex-shrink-0" />
Full match found with tier {/* @ts-ignore */}
{currentListingArgsMatchedTier.preset_name}
</h3>
)}
{isMintOnCurve && (
<div className="text-orange pt-4">
Proposed token has open mint
Expand Down Expand Up @@ -536,17 +561,17 @@ const instructions = () => ({
label="Flash Loan Deposit Fee Rate"
valKey="flashLoanSwapFeeRate"
/>
<DisplayNullishProperty
<DisplayListingProperty
label="Deposit Limit"
value={`${
mintInfo
val={`${
mintInfo && formattedProposedArgs.depositLimit
? toUiDecimals(
new BN(formattedProposedArgs.depositLimit.toString()),
mintInfo.account.decimals
)
: formattedProposedArgs.depositLimit
} ${args.name} ($${
mintInfo
mintInfo && formattedProposedArgs.depositLimit
? (
toUiDecimals(
new BN(formattedProposedArgs.depositLimit.toString()),
Expand All @@ -555,23 +580,19 @@ const instructions = () => ({
).toFixed(0)
: 0
})`}
suggestedVal={`${
suggestedVal={
mintInfo && invalidFields?.depositLimit
? toUiDecimals(
? `${toUiDecimals(
new BN(invalidFields.depositLimit.toString()),
mintInfo.account.decimals
)
: invalidFields.depositLimit
} ${args.name} ($${
mintInfo && invalidFields.depositLimit
? (
)} ${args.name} ($${(
toUiDecimals(
new BN(invalidFields.depositLimit.toString()),
mintInfo.account.decimals
) * oracleData.uiPrice
).toFixed(0)
: 0
})`}
).toFixed(0)})`
: undefined
}
/>
<DisplayListingPropertyWrapped
label="Interest Target Utilization"
Expand All @@ -581,9 +602,9 @@ const instructions = () => ({
label="Interest Curve Scaling"
valKey="interestCurveScaling"
/>
<DisplayNullishProperty
<DisplayListingProperty
label="Group Insurance Fund"
value={formattedProposedArgs.groupInsuranceFund.toString()}
val={formattedProposedArgs.groupInsuranceFund?.toString()}
suggestedVal={invalidFields.groupInsuranceFund?.toString()}
/>
</div>
Expand Down Expand Up @@ -1013,7 +1034,7 @@ const instructions = () => ({
if (x === 'depositLimit') {
return !isDifferenceWithin5Percent(
Number(parsedArgs['depositLimit'] || 0),
Number(suggestedFormattedPreset['depositLimit'])
Number(suggestedFormattedPreset['depositLimit'] || 0)
)
}
return true
Expand Down
9 changes: 6 additions & 3 deletions utils/Mango/listingTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export type FlatListingArgs = {
name: string
tokenIndex: number
'oracleConfig.confFilter': number
'oracleConfig.maxStalenessSlots': number
'oracleConfig.maxStalenessSlots': number | null
'interestRateParams.util0': number
'interestRateParams.rate0': number
'interestRateParams.util1': number
Expand Down Expand Up @@ -130,7 +130,7 @@ export type ListingArgsFormatted = {
tokenIndex: number
tokenName: string
oracleConfidenceFilter: string
oracleMaxStalenessSlots: number
oracleMaxStalenessSlots: number | null
interestRateUtilizationPoint1: string
interestRateUtilizationPoint0: string
interestRatePoint0: string
Expand Down Expand Up @@ -175,7 +175,10 @@ export type EditTokenArgsFormatted = ListingArgsFormatted & {
const transformPresetToProposed = (listingPreset: LISTING_PRESET) => {
const proposedPreset: FormattedListingPreset = {
...listingPreset,
'oracleConfig.maxStalenessSlots': listingPreset.maxStalenessSlots!,
'oracleConfig.maxStalenessSlots':
listingPreset.maxStalenessSlots === -1
? null
: listingPreset.maxStalenessSlots!,
'oracleConfig.confFilter': listingPreset.oracleConfFilter,
'interestRateParams.adjustmentFactor': listingPreset.adjustmentFactor,
'interestRateParams.util0': listingPreset.util0,
Expand Down

1 comment on commit 3c894bd

@vercel
Copy link

@vercel vercel bot commented on 3c894bd Jan 27, 2024

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-git-main-solana-labs.vercel.app
governance-ui-solana-labs.vercel.app
app.realms.today

Please sign in to comment.