diff --git a/components/instructions/programs/mangoV4.tsx b/components/instructions/programs/mangoV4.tsx index 0a3dd94e39..e8d9e0778f 100644 --- a/components/instructions/programs/mangoV4.tsx +++ b/components/instructions/programs/mangoV4.tsx @@ -10,13 +10,14 @@ import { Connection, Keypair, PublicKey } from '@solana/web3.js' import EmptyWallet, { getSuggestedCoinTier, compareObjectsAndGetDifferentKeys, - ListingArgs, + FlatListingArgs, ListingArgsFormatted, getOracle, getBestMarket, EditTokenArgsFormatted, isPythOracle, getFormattedListingPresets, + FlatEditArgs, } from '@utils/Mango/listingTools' import { secondsToHours } from 'date-fns' import WarningFilledIcon from '@carbon/icons-react/lib/WarningFilled' @@ -225,7 +226,7 @@ const instructions = () => ({ const [info, proposedOracle, args] = await Promise.all([ displayArgs(connection, data), getOracle(connection, oracle), - getDataObjectFlattened(connection, data), + getDataObjectFlattened(connection, data), ]) const liqudityTier = await getSuggestedCoinTier( proposedMint.toBase58(), @@ -244,8 +245,9 @@ const instructions = () => ({ ? getFormattedListingValues({ tokenIndex: args.tokenIndex, name: args.name, + oracle: args.oracle, ...suggestedPreset, - } as ListingArgs) + }) : ({} as ListingArgsFormatted) const invalidKeys: (keyof ListingArgsFormatted)[] = Object.keys( @@ -692,7 +694,7 @@ const instructions = () => ({ const [mangoGroup, info, args] = await Promise.all([ client.getGroup(group), displayArgs(connection, data), - getDataObjectFlattened(connection, data), + getDataObjectFlattened(connection, data), ]) const mint = [...mangoGroup.mintInfosMapByMint.values()].find((x) => x.publicKey.equals(mintInfo) @@ -708,7 +710,7 @@ const instructions = () => ({ const parsedArgs: Partial = { tokenIndex: args.tokenIndex, - tokenName: args.name, + tokenName: args.nameOpt, oracleConfidenceFilter: args['oracleConfigOpt.confFilter'] !== undefined ? (args['oracleConfigOpt.confFilter'] * 100)?.toFixed(2) @@ -785,7 +787,10 @@ const instructions = () => ({ tokenConditionalSwapTakerFeeRate: args.tokenConditionalSwapTakerFeeRateOpt, flashLoanDepositFeeRate: args.flashLoanDepositFeeRateOpt, - reduceOnly: args.reduceOnlyOpt, + reduceOnly: + args.reduceOnlyOpt !== undefined + ? REDUCE_ONLY_OPTIONS[args.reduceOnlyOpt].name + : undefined, } if (mint) { @@ -807,9 +812,10 @@ const instructions = () => ({ ? { ...getFormattedListingValues({ tokenIndex: args.tokenIndex, - name: args.name, + name: args.nameOpt, + oracle: args.oracleOpt, ...suggestedPreset, - } as ListingArgs), + }), groupInsuranceFund: suggestedPreset.insuranceFound, } : {} @@ -1078,18 +1084,17 @@ const instructions = () => ({ value={parsedArgs.flashLoanDepositFeeRate} suggestedVal={invalidFields.flashLoanDepositFeeRate} /> - {typeof parsedArgs.reduceOnly === 'number' && ( - - )} +

Raw values

{info}
) } catch (e) { + console.log(e) const info = await displayArgs(connection, data) try { @@ -1375,10 +1380,11 @@ const DisplayListingProperty = ({ ) -const getFormattedListingValues = (args: ListingArgs) => { +const getFormattedListingValues = (args: FlatListingArgs) => { const formattedArgs: ListingArgsFormatted = { tokenIndex: args.tokenIndex, tokenName: args.name, + oracle: args.oracle?.toBase58(), oracleConfidenceFilter: (args['oracleConfig.confFilter'] * 100).toFixed(2), oracleMaxStalenessSlots: args['oracleConfig.maxStalenessSlots'], interestRateUtilizationPoint0: ( diff --git a/utils/Mango/listingTools.ts b/utils/Mango/listingTools.ts index 64c62d74c6..7ea74f1277 100644 --- a/utils/Mango/listingTools.ts +++ b/utils/Mango/listingTools.ts @@ -25,7 +25,7 @@ const MAINNET_PYTH_PROGRAM = new PublicKey( 'FsJ3A3u2vn5cTVofAjvy6y5kwABJAqYWpe4975bi2epH' ) -export type ListingArgs = { +export type FlatListingArgs = { name: string tokenIndex: number 'oracleConfig.confFilter': number @@ -56,6 +56,42 @@ export type ListingArgs = { tokenConditionalSwapTakerFeeRate: number flashLoanDepositFeeRate: number reduceOnly: number + groupInsuranceFund: boolean + oracle: PublicKey +} + +export type FlatEditArgs = { + nameOpt: string + tokenIndex: number + 'oracleConfigOpt.confFilter': number + 'oracleConfigOpt.maxStalenessSlots': number + 'interestRateParamsOpt.util0': number + 'interestRateParamsOpt.rate0': number + 'interestRateParamsOpt.util1': number + 'interestRateParamsOpt.rate1': number + 'interestRateParamsOpt.maxRate': number + 'interestRateParamsOpt.adjustmentFactor': number + loanFeeRateOpt: number + loanOriginationFeeRateOpt: number + maintAssetWeightOpt: number + initAssetWeightOpt: number + maintLiabWeightOpt: number + initLiabWeightOpt: number + liquidationFeeOpt: number + minVaultToDepositsRatioOpt: number + netBorrowLimitPerWindowQuoteOpt: number + netBorrowLimitWindowSizeTsOpt: number + borrowWeightScaleStartQuoteOpt: number + depositWeightScaleStartQuoteOpt: number + stablePriceDelayGrowthLimitOpt: number + stablePriceDelayIntervalSecondsOpt: number + stablePriceGrowthLimitOpt: number + tokenConditionalSwapMakerFeeRateOpt: number + tokenConditionalSwapTakerFeeRateOpt: number + flashLoanDepositFeeRateOpt: number + reduceOnlyOpt: number + groupInsuranceFundOpt: boolean + oracleOpt: PublicKey } export type ListingArgsFormatted = { @@ -88,41 +124,37 @@ export type ListingArgsFormatted = { tokenConditionalSwapTakerFeeRate: number flashLoanDepositFeeRate: number reduceOnly: string + oracle: string } export type EditTokenArgsFormatted = ListingArgsFormatted & { groupInsuranceFund: boolean } -const transformPresetToProposed = ( - listingPreset: ListingPreset | Record -) => { - const proposedPreset: PureListingArgsOrEmptyObj = - Object.keys(listingPreset).length !== 0 - ? { - ...(listingPreset as ListingPreset), - 'oracleConfig.maxStalenessSlots': listingPreset.maxStalenessSlots!, - 'oracleConfig.confFilter': listingPreset.oracleConfFilter, - 'interestRateParams.adjustmentFactor': listingPreset.adjustmentFactor, - 'interestRateParams.util0': listingPreset.util0, - 'interestRateParams.rate0': listingPreset.rate0, - 'interestRateParams.util1': listingPreset.util1, - 'interestRateParams.rate1': listingPreset.rate1, - 'interestRateParams.maxRate': listingPreset.maxRate, - } - : {} +const transformPresetToProposed = (listingPreset: ListingPreset) => { + const proposedPreset: FormattedListingPreset = { + ...listingPreset, + 'oracleConfig.maxStalenessSlots': listingPreset.maxStalenessSlots!, + 'oracleConfig.confFilter': listingPreset.oracleConfFilter, + 'interestRateParams.adjustmentFactor': listingPreset.adjustmentFactor, + 'interestRateParams.util0': listingPreset.util0, + 'interestRateParams.rate0': listingPreset.rate0, + 'interestRateParams.util1': listingPreset.util1, + 'interestRateParams.rate1': listingPreset.rate1, + 'interestRateParams.maxRate': listingPreset.maxRate, + groupInsuranceFund: listingPreset.insuranceFound, + } return proposedPreset } -type PureListingArgsOrEmptyObj = - | Record - | (Omit & { - preset_name: string - }) +type FormattedListingPreset = Omit< + FlatListingArgs, + 'name' | 'tokenIndex' | 'oracle' +> type ProposedListingPresets = { - [key in LISTING_PRESETS_KEYS]: PureListingArgsOrEmptyObj + [key in LISTING_PRESETS_KEYS]: FormattedListingPreset } export const getFormattedListingPresets = (isPythOracle: boolean) => {