Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show current bank values in token edit #1914

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 97 additions & 2 deletions components/instructions/programs/mangoV4.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
Bank,
MANGO_V4_ID,
MangoClient,
OracleProvider,
Expand All @@ -20,6 +21,7 @@ import EmptyWallet, {
FlatEditArgs,
getFormattedListingPresets,
decodePriceFromOracleAi,
getFormattedBankValues,
} from '@utils/Mango/listingTools'
import { secondsToHours } from 'date-fns'
import WarningFilledIcon from '@carbon/icons-react/lib/WarningFilled'
Expand Down Expand Up @@ -756,6 +758,10 @@ const instructions = () => ({
let suggestedUntrusted = false
let invalidKeys: (keyof EditTokenArgsFormatted)[] = []
let invalidFields: Partial<EditTokenArgsFormatted> = {}
let bank: null | Bank = null
let bankFormattedValues: null | ReturnType<
typeof getFormattedBankValues
> = null

const parsedArgs: Partial<EditTokenArgsFormatted> = {
tokenIndex: args.tokenIndex,
Expand Down Expand Up @@ -843,7 +849,8 @@ const instructions = () => ({
}

if (mint) {
const bank = mangoGroup.getFirstBankByMint(mint)
bank = mangoGroup.getFirstBankByMint(mint)
bankFormattedValues = getFormattedBankValues(mangoGroup, bank)
mintData = tokenPriceService.getTokenInfo(mint.toBase58())
const isPyth = bank?.oracleProvider === OracleProvider.Pyth
const midPriceImpacts = getMidPriceImpacts(mangoGroup.pis)
Expand Down Expand Up @@ -953,6 +960,9 @@ const instructions = () => ({
</h3>
)}
<div className="py-4">
<div className="flex mb-2">
<div className="w-3 h-3 bg-white mr-2"></div> - Current values
</div>
<div className="flex mb-2">
<div className="w-3 h-3 bg-orange mr-2"></div> - Proposed values
</div>
Expand All @@ -972,6 +982,10 @@ const instructions = () => ({
/>
<DisplayNullishProperty
label="Oracle Confidence Filter"
currentValue={
bankFormattedValues?.oracleConfFilter &&
`${bankFormattedValues.oracleConfFilter}%`
}
value={
parsedArgs.oracleConfidenceFilter &&
`${parsedArgs.oracleConfidenceFilter}%`
Expand All @@ -983,11 +997,16 @@ const instructions = () => ({
/>
<DisplayNullishProperty
label="Oracle Max Staleness Slots"
currentValue={bankFormattedValues?.maxStalenessSlots}
value={parsedArgs.oracleMaxStalenessSlots}
suggestedVal={invalidFields.oracleMaxStalenessSlots}
/>
<DisplayNullishProperty
label="Interest rate adjustment factor"
currentValue={
bankFormattedValues?.adjustmentFactor &&
`${bankFormattedValues.adjustmentFactor}%`
}
value={
parsedArgs.adjustmentFactor &&
`${parsedArgs.adjustmentFactor}%`
Expand All @@ -1003,6 +1022,9 @@ const instructions = () => ({
parsedArgs.interestRateUtilizationPoint0 &&
`${parsedArgs.interestRateUtilizationPoint0}%`
}
currentValue={
bankFormattedValues?.util0 && `${bankFormattedValues.util0}%`
}
suggestedVal={
invalidFields.interestRateUtilizationPoint0 &&
`${invalidFields.interestRateUtilizationPoint0}%`
Expand All @@ -1014,6 +1036,9 @@ const instructions = () => ({
parsedArgs.interestRatePoint0 &&
`${parsedArgs.interestRatePoint0}%`
}
currentValue={
bankFormattedValues?.rate0 && `${bankFormattedValues.rate0}%`
}
suggestedVal={
invalidFields.interestRatePoint0 &&
`${invalidFields.interestRatePoint0}%`
Expand All @@ -1025,6 +1050,9 @@ const instructions = () => ({
parsedArgs.interestRateUtilizationPoint1 &&
`${parsedArgs.interestRateUtilizationPoint1}%`
}
currentValue={
bankFormattedValues?.util1 && `${bankFormattedValues?.util1}%`
}
suggestedVal={
invalidFields.interestRateUtilizationPoint1 &&
`${invalidFields.interestRateUtilizationPoint1}%`
Expand All @@ -1036,6 +1064,9 @@ const instructions = () => ({
parsedArgs.interestRatePoint1 &&
`${parsedArgs.interestRatePoint1}%`
}
currentValue={
bankFormattedValues?.rate1 && `${bankFormattedValues.rate1}%`
}
suggestedVal={
invalidFields.interestRatePoint1 &&
`${invalidFields.interestRatePoint1}%`
Expand All @@ -1044,6 +1075,10 @@ const instructions = () => ({
<DisplayNullishProperty
label="Interest rate max rate"
value={parsedArgs.maxRate && `${parsedArgs.maxRate}%`}
currentValue={
bankFormattedValues?.maxRate &&
`${bankFormattedValues.maxRate}%`
}
suggestedVal={
invalidFields.maxRate && `${invalidFields.maxRate}%`
}
Expand All @@ -1053,6 +1088,10 @@ const instructions = () => ({
value={
parsedArgs.loanFeeRate && `${parsedArgs.loanFeeRate} bps`
}
currentValue={
bankFormattedValues?.loanFeeRate &&
`${bankFormattedValues.loanFeeRate} bps`
}
suggestedVal={
invalidFields.loanFeeRate &&
`${invalidFields.loanFeeRate} bps`
Expand All @@ -1064,6 +1103,10 @@ const instructions = () => ({
parsedArgs.loanOriginationFeeRate &&
`${parsedArgs.loanOriginationFeeRate} bps`
}
currentValue={
bankFormattedValues?.loanOriginationFeeRate &&
`${bankFormattedValues.loanOriginationFeeRate} bps`
}
suggestedVal={
invalidFields.loanOriginationFeeRate &&
`${invalidFields.loanOriginationFeeRate} bps`
Expand All @@ -1072,28 +1115,36 @@ const instructions = () => ({
<DisplayNullishProperty
label="Maintenance Asset Weight"
value={parsedArgs.maintAssetWeight}
currentValue={bankFormattedValues?.maintAssetWeight}
suggestedVal={invalidFields.maintAssetWeight}
/>
<DisplayNullishProperty
label="Init Asset Weight"
value={parsedArgs.initAssetWeight}
currentValue={bankFormattedValues?.initAssetWeight}
suggestedVal={invalidFields.initAssetWeight}
/>
<DisplayNullishProperty
label="Maintenance Liab Weight"
value={parsedArgs.maintLiabWeight}
currentValue={bankFormattedValues?.maintLiabWeight}
suggestedVal={invalidFields.maintLiabWeight}
/>
<DisplayNullishProperty
label="Init Liab Weight"
value={parsedArgs.initLiabWeight}
currentValue={bankFormattedValues?.initLiabWeight}
suggestedVal={invalidFields.initLiabWeight}
/>
<DisplayNullishProperty
label="Liquidation Fee"
value={
parsedArgs.liquidationFee && `${parsedArgs.liquidationFee}%`
}
currentValue={
bankFormattedValues?.liquidationFee &&
`${bankFormattedValues.liquidationFee}%`
}
suggestedVal={
invalidFields.liquidationFee &&
`${invalidFields.liquidationFee}%`
Expand All @@ -1105,6 +1156,10 @@ const instructions = () => ({
parsedArgs.minVaultToDepositsRatio &&
`${parsedArgs.minVaultToDepositsRatio}%`
}
currentValue={
bankFormattedValues?.minVaultToDepositsRatio &&
`${bankFormattedValues.minVaultToDepositsRatio}%`
}
suggestedVal={
invalidFields.minVaultToDepositsRatio &&
`${invalidFields.minVaultToDepositsRatio}%`
Expand All @@ -1116,6 +1171,10 @@ const instructions = () => ({
parsedArgs.netBorrowLimitWindowSizeTs &&
`${parsedArgs.netBorrowLimitWindowSizeTs}H`
}
currentValue={
bankFormattedValues?.netBorrowLimitWindowSizeTs &&
`${bankFormattedValues.netBorrowLimitWindowSizeTs}H`
}
suggestedVal={
invalidFields.netBorrowLimitWindowSizeTs &&
`${invalidFields.netBorrowLimitWindowSizeTs}H`
Expand All @@ -1127,6 +1186,10 @@ const instructions = () => ({
parsedArgs.netBorrowLimitPerWindowQuote &&
`$${parsedArgs.netBorrowLimitPerWindowQuote}`
}
currentValue={
bankFormattedValues?.netBorrowLimitPerWindowQuote &&
`$${bankFormattedValues.netBorrowLimitPerWindowQuote}`
}
suggestedVal={
invalidFields.netBorrowLimitPerWindowQuote &&
`$${invalidFields.netBorrowLimitPerWindowQuote}`
Expand All @@ -1138,6 +1201,10 @@ const instructions = () => ({
parsedArgs.borrowWeightScaleStartQuote &&
`$${parsedArgs.borrowWeightScaleStartQuote}`
}
currentValue={
bankFormattedValues?.borrowWeightScaleStartQuote &&
`$${bankFormattedValues.borrowWeightScaleStartQuote}`
}
suggestedVal={
invalidFields.borrowWeightScaleStartQuote &&
`$${invalidFields.borrowWeightScaleStartQuote}`
Expand All @@ -1149,6 +1216,10 @@ const instructions = () => ({
parsedArgs.depositWeightScaleStartQuote &&
`$${parsedArgs.depositWeightScaleStartQuote}`
}
currentValue={
bankFormattedValues?.depositWeightScaleStartQuote &&
`$${bankFormattedValues.depositWeightScaleStartQuote}`
}
suggestedVal={
invalidFields.depositWeightScaleStartQuote &&
`$${invalidFields.depositWeightScaleStartQuote}`
Expand All @@ -1157,30 +1228,46 @@ const instructions = () => ({
<DisplayNullishProperty
label="Group Insurance Fund"
value={parsedArgs.groupInsuranceFund?.toString()}
currentValue={
mint
? mangoGroup.mintInfosMapByMint
.get(mint.toBase58())
?.groupInsuranceFund.toString()
: undefined
}
suggestedVal={invalidFields.groupInsuranceFund?.toString()}
/>
<DisplayNullishProperty
label="Oracle"
value={args.oracleOpt?.toBase58()}
currentValue={bankFormattedValues?.oracle}
/>
<DisplayNullishProperty
label="Token Conditional Swap Maker Fee Rate"
value={parsedArgs.tokenConditionalSwapMakerFeeRate}
currentValue={
bankFormattedValues?.tokenConditionalSwapMakerFeeRate
}
suggestedVal={invalidFields.tokenConditionalSwapMakerFeeRate}
/>
<DisplayNullishProperty
label="Token Conditional Swap Taker Fee Rate"
value={parsedArgs.tokenConditionalSwapTakerFeeRate}
currentValue={
bankFormattedValues?.tokenConditionalSwapTakerFeeRate
}
suggestedVal={invalidFields.tokenConditionalSwapTakerFeeRate}
/>
<DisplayNullishProperty
label="Flash Loan Deposit Fee Rate"
value={parsedArgs.flashLoanDepositFeeRate}
currentValue={bankFormattedValues?.flashLoanDepositFeeRate}
suggestedVal={invalidFields.flashLoanDepositFeeRate}
/>
<DisplayNullishProperty
label="Reduce only"
value={parsedArgs.reduceOnly}
currentValue={bankFormattedValues?.reduceOnly}
/>
</div>
<h3>Raw values</h3>
Expand Down Expand Up @@ -1420,16 +1507,24 @@ const DisplayNullishProperty = ({
label,
value,
suggestedVal,
currentValue,
}: {
label: string
currentValue?: string | null | undefined | number
value: string | null | undefined | number
suggestedVal?: string | null | undefined | number
}) =>
value ? (
<div className="flex space-x-3">
<div>{label}:</div>
<div className="flex">
<div className={`${suggestedVal ? 'text-orange' : ''}`}>{value}</div>
<div className={`${currentValue ? 'text-grey' : ''}`}>
{currentValue}
</div>
</div>
{<div className="mx-1">/</div>}
<div className="flex">
<div className="text-orange">{value}</div>
</div>
{suggestedVal && <div className="mx-1">/</div>}
{suggestedVal && <div className="text-green">{suggestedVal}</div>}
Expand Down
Loading