Skip to content

Commit

Permalink
Big Swap Feedback (#122)
Browse files Browse the repository at this point in the history
* since expected slippage could be negative we need to get its absolute value to actually check if it is greater than the max allowed depeg

* update language of depeg warning. the price is not depegged yet but would be by the action. also reduce the words to make it clearer

* rename depeg var to be more clear what its for

---------

Co-authored-by: Aaron <[email protected]>
  • Loading branch information
aaronmgdr and aaronmgdr authored Feb 7, 2024
1 parent b34439a commit 644c671
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/cli/src/commands/exchange/celo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { checkNotDangerousExchange } from '../../utils/exchange'
import { enumEntriesDupWithLowercase } from '../../utils/helpers'
import { getMentoBroker } from '../../utils/mento-broker-adaptor'

const depeggedPricePercentage = 20
const MAX_DEPEG_PRICE_PERCENTAGE = 20

const stableTokenOptions = enumEntriesDupWithLowercase(Object.entries(StableToken))
export default class ExchangeCelo extends BaseCommand {
Expand Down Expand Up @@ -75,7 +75,7 @@ export default class ExchangeCelo extends BaseCommand {
kit,
sellAmount,
new BigNumber(expectedAmountToReceive.toString()),
depeggedPricePercentage,
MAX_DEPEG_PRICE_PERCENTAGE,
stableTokenInfos[stableToken]
)
if (!check) {
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/exchange-stable-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { binaryPrompt, displaySendEthersTxViaCK, displaySendTx } from './utils/c
import { CustomFlags } from './utils/command'
import { checkNotDangerousExchange } from './utils/exchange'
import { getMentoBroker } from './utils/mento-broker-adaptor'
const depeggedPricePercentage = 20
const MAX_DEPEG_PRICE_PERCENTAGE = 20
export default class ExchangeStableBase extends BaseCommand {
static flags = {
...BaseCommand.flags,
Expand Down Expand Up @@ -68,7 +68,7 @@ export default class ExchangeStableBase extends BaseCommand {
kit,
sellAmount,
new BigNumber(expectedAmountToReceive.toString()),
depeggedPricePercentage,
MAX_DEPEG_PRICE_PERCENTAGE,
stableTokenInfos[this._stableCurrency as StableToken],
true
)
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/utils/exchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function checkNotDangerousExchange(
kit: ContractKit,
sellAmount: BigNumber,
quotedAmountToReceiveWithBuffer: BigNumber,
depeggedPricePercentage: number,
maxDepegPricePercentage: number,
stableTokenInfo: StableTokenInfo = stableTokenInfos[StableToken.cUSD],
flipOracle = false
): Promise<boolean> {
Expand All @@ -37,11 +37,11 @@ export async function checkNotDangerousExchange(
quotedAmountToReceiveWithBuffer,
oracleMedianRate
)
if (expectedSlippage > depeggedPricePercentage) {
if (Math.abs(expectedSlippage) > Math.abs(maxDepegPricePercentage)) {
const check = await binaryPrompt(
`Warning ${
stableTokenInfo.symbol
} price here (i.e. on-chain) is depegged by ${expectedSlippage}% which is >${depeggedPricePercentage}% from the oracle prices ${oracleMedianRate.toString()} (i.e. swap prices). Are you sure you want to continue?`,
} price here (i.e. on-chain) would be depegged by ${expectedSlippage}% from the oracle prices ${oracleMedianRate.toString()} (i.e. swap prices). Are you sure you want to continue?`,
true
)
return check
Expand Down

0 comments on commit 644c671

Please sign in to comment.