Skip to content

Commit

Permalink
chore: cleanup squid code [OTE-365] [1/n] (dydxprotocol#647)
Browse files Browse the repository at this point in the history
  • Loading branch information
yogurtandjam authored Sep 12, 2024
1 parent 50ac9d4 commit 532581a
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 1,157 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ allprojects {
}

group = "exchange.dydx.abacus"
version = "1.11.0"
version = "1.11.1"

repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import exchange.dydx.abacus.output.input.OrderType
import exchange.dydx.abacus.output.input.ReceiptLine
import exchange.dydx.abacus.output.input.TransferType
import exchange.dydx.abacus.state.internalstate.InternalInputState
import exchange.dydx.abacus.state.manager.StatsigConfig

internal class ReceiptCalculator {
fun calculate(
Expand Down Expand Up @@ -52,30 +51,17 @@ internal class ReceiptCalculator {
InputType.TRANSFER -> {
when (input.transfer.type) {
TransferType.deposit, TransferType.withdrawal -> {
if (StatsigConfig.useSkip) {
listOf(
ReceiptLine.Equity,
ReceiptLine.BuyingPower,
ReceiptLine.BridgeFee,
// add these back when supported by Skip
listOf(
ReceiptLine.Equity,
ReceiptLine.BuyingPower,
ReceiptLine.BridgeFee,
// add these back when supported by Skip
// ReceiptLine.ExchangeRate,
// ReceiptLine.ExchangeReceived,
// ReceiptLine.Fee,
ReceiptLine.Slippage,
ReceiptLine.TransferRouteEstimatedDuration,
)
} else {
listOf(
ReceiptLine.Equity,
ReceiptLine.BuyingPower,
ReceiptLine.ExchangeRate,
ReceiptLine.ExchangeReceived,
ReceiptLine.Fee,
// ReceiptLine.BridgeFee,
ReceiptLine.Slippage,
ReceiptLine.TransferRouteEstimatedDuration,
)
}
ReceiptLine.Slippage,
ReceiptLine.TransferRouteEstimatedDuration,
)
}

TransferType.transferOut -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,7 @@ class V4Environment(
@JsExport
@Suppress("PropertyName")
data object StatsigConfig {
var useSkip: Boolean = false
var ff_enable_evm_swaps: Boolean = false
var ff_enable_evm_swaps: Boolean = true
var dc_max_safe_bridge_fees: Float = Float.POSITIVE_INFINITY
var ff_enable_limit_close: Boolean = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ import exchange.dydx.abacus.processor.input.ClosePositionInputProcessor
import exchange.dydx.abacus.processor.input.TradeInputProcessor
import exchange.dydx.abacus.processor.launchIncentive.LaunchIncentiveProcessor
import exchange.dydx.abacus.processor.markets.MarketsSummaryProcessor
import exchange.dydx.abacus.processor.router.IRouterProcessor
import exchange.dydx.abacus.processor.router.skip.SkipProcessor
import exchange.dydx.abacus.processor.router.squid.SquidProcessor
import exchange.dydx.abacus.processor.wallet.WalletProcessor
import exchange.dydx.abacus.protocols.LocalizerProtocol
import exchange.dydx.abacus.protocols.ParserProtocol
Expand All @@ -65,7 +63,6 @@ import exchange.dydx.abacus.state.internalstate.InternalAccountState
import exchange.dydx.abacus.state.internalstate.InternalState
import exchange.dydx.abacus.state.manager.BlockAndTime
import exchange.dydx.abacus.state.manager.EnvironmentFeatureFlags
import exchange.dydx.abacus.state.manager.StatsigConfig
import exchange.dydx.abacus.state.manager.TokenInfo
import exchange.dydx.abacus.state.manager.V4Environment
import exchange.dydx.abacus.utils.IList
Expand Down Expand Up @@ -125,21 +122,11 @@ open class TradingStateMachine(
}
internal val walletProcessor = WalletProcessor(parser, localizer)
internal val configsProcessor = ConfigsProcessor(parser, localizer)
private val skipProcessor = SkipProcessor(
internal val routerProcessor = SkipProcessor(
parser = parser,
internalState = internalState.input.transfer,
staticTyping = staticTyping,
)
private val squidProcessor = SquidProcessor(
parser = parser,
internalState = internalState.input.transfer,
staticTyping = staticTyping,
)
internal val routerProcessor: IRouterProcessor
get() {
if (StatsigConfig.useSkip) return skipProcessor
return squidProcessor
}
internal val rewardsProcessor = RewardsParamsProcessor(parser)
internal val launchIncentiveProcessor = LaunchIncentiveProcessor(parser)
internal val tradeInputProcessor = TradeInputProcessor(parser)
Expand Down Expand Up @@ -1182,30 +1169,17 @@ open class TradingStateMachine(
val type = parser.asString(transfer["type"]) ?: return null
return when (type) {
"DEPOSIT", "WITHDRAWAL" -> {
if (StatsigConfig.useSkip) {
listOf(
ReceiptLine.Equity.rawValue,
ReceiptLine.BuyingPower.rawValue,
ReceiptLine.BridgeFee.rawValue,
// add these back when supported by Skip
listOf(
ReceiptLine.Equity.rawValue,
ReceiptLine.BuyingPower.rawValue,
ReceiptLine.BridgeFee.rawValue,
// add these back when supported by Skip
// ReceiptLine.ExchangeRate.rawValue,
// ReceiptLine.ExchangeReceived.rawValue,
// ReceiptLine.Fee.rawValue,
ReceiptLine.Slippage.rawValue,
ReceiptLine.TransferRouteEstimatedDuration.rawValue,
)
} else {
listOf(
ReceiptLine.Equity.rawValue,
ReceiptLine.BuyingPower.rawValue,
ReceiptLine.ExchangeRate.rawValue,
ReceiptLine.ExchangeReceived.rawValue,
ReceiptLine.Fee.rawValue,
// ReceiptLine.BridgeFee.rawValue,
ReceiptLine.Slippage.rawValue,
ReceiptLine.TransferRouteEstimatedDuration.rawValue,
)
}
ReceiptLine.Slippage.rawValue,
ReceiptLine.TransferRouteEstimatedDuration.rawValue,
)
}

"TRANSFER_OUT" -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import exchange.dydx.abacus.state.manager.HumanReadablePlaceOrderPayload
import exchange.dydx.abacus.state.manager.HumanReadableSubaccountTransferPayload
import exchange.dydx.abacus.state.manager.HumanReadableTriggerOrdersPayload
import exchange.dydx.abacus.state.manager.HumanReadableWithdrawPayload
import exchange.dydx.abacus.state.manager.StatsigConfig
import exchange.dydx.abacus.state.manager.pendingCctpWithdraw
import exchange.dydx.abacus.state.manager.processingCctpWithdraw
import exchange.dydx.abacus.state.manager.utils.Address
Expand Down Expand Up @@ -600,68 +599,7 @@ internal open class AccountSupervisor(
}

private fun sweepNobleBalanceToDydx(amount: BigDecimal) {
if (StatsigConfig.useSkip) {
sweepNobleBalanceToDydxSkip(amount = amount)
} else {
sweepNobleBalanceToDydxSquid(amount = amount)
}
}

private fun sweepNobleBalanceToDydxSquid(amount: BigDecimal) {
val url = helper.configs.squidRoute()
val fromChain = helper.configs.nobleChainId()
val fromToken = helper.configs.nobleDenom
val nobleAddress = accountAddress.toNobleAddress()
val chainId = helper.environment.dydxChainId
val squidIntegratorId = helper.environment.squidIntegratorId
val dydxTokenDemon = helper.environment.tokens["usdc"]?.denom
if (url != null &&
fromChain != null &&
fromToken != null &&
nobleAddress != null &&
chainId != null &&
dydxTokenDemon != null &&
squidIntegratorId != null
) {
val params: Map<String, String> =
mapOf(
"fromChain" to fromChain,
"fromToken" to fromToken,
"fromAddress" to nobleAddress,
"fromAmount" to amount.toPlainString(),
"toChain" to chainId,
"toToken" to dydxTokenDemon,
"toAddress" to accountAddress.toString(),
"slippage" to "1",
"enableForecall" to "false",
)
val header =
iMapOf(
"x-integrator-id" to squidIntegratorId,
)
helper.get(url, params, header) { _, response, code, _ ->
if (response != null) {
val json = helper.parser.decodeJsonObject(response)
val ibcPayload =
helper.parser.asString(
helper.parser.value(
json,
"route.transactionRequest.data",
),
)
if (ibcPayload != null) {
helper.transaction(TransactionType.SendNobleIBC, ibcPayload) {
val error = helper.parseTransactionResponse(it)
if (error != null) {
Logger.e { "sweepNobleBalanceToDydxSquid error: $error" }
}
}
}
} else {
Logger.e { "sweepNobleBalanceToDydxSquid error, code: $code" }
}
}
}
sweepNobleBalanceToDydxSkip(amount = amount)
}

private fun sweepNobleBalanceToDydxSkip(amount: BigDecimal) {
Expand Down
Loading

0 comments on commit 532581a

Please sign in to comment.