From 789e8979209df5f6159b14015b3bab25d810259d Mon Sep 17 00:00:00 2001 From: Jeremy Lee <37092291+yogurtandjam@users.noreply.github.com> Date: Wed, 19 Jun 2024 17:02:29 -0400 Subject: [PATCH] feat: enable testnet OTE flows (#446) --- .../state/v2/supervisor/AccountSupervisor.kt | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/AccountSupervisor.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/AccountSupervisor.kt index 13096d860..2c2ee9a06 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/AccountSupervisor.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/v2/supervisor/AccountSupervisor.kt @@ -755,6 +755,56 @@ internal open class AccountSupervisor( } } + private fun transferNobleBalanceSkip(amount: BigDecimal) { + val url = helper.configs.skipV2MsgsDirect() + val fromChain = helper.configs.nobleChainId() + val fromToken = helper.configs.nobleDenom + val nobleAddress = accountAddress.toNobleAddress() ?: return + val chainId = helper.environment.dydxChainId ?: return + val dydxTokenDemon = helper.environment.tokens["usdc"]?.denom ?: return + val body: Map = mapOf( + "amount_in" to amount.toPlainString(), +// from noble denom and chain + "source_asset_denom" to fromToken, + "source_asset_chain_id" to fromChain, +// to dydx denom and chain + "dest_asset_denom" to dydxTokenDemon, + "dest_asset_chain_id" to chainId, + "chain_ids_to_addresses" to mapOf( + fromChain to nobleAddress, + chainId to accountAddress, + ), + "slippage_tolerance_percent" to SLIPPAGE_PERCENT, + ) + val header = + iMapOf( + "Content-Type" to "application/json", + ) + helper.post(url, header, body.toJsonPrettyPrint()) { _, response, code, _ -> + if (response == null) { + val json = helper.parser.decodeJsonObject(response) + if (json != null) { + val skipRoutePayloadProcessor = SkipRoutePayloadProcessor(parser = helper.parser) + val processedPayload = skipRoutePayloadProcessor.received(existing = mapOf(), payload = json) + val ibcPayload = + helper.parser.asString( + processedPayload.get("data"), + ) + if (ibcPayload != null) { + helper.transaction(TransactionType.SendNobleIBC, ibcPayload) { + val error = helper.parseTransactionResponse(it) + if (error != null) { + Logger.e { "transferNobleBalanceSkip error: $error" } + } + } + } + } + } else { + Logger.e { "transferNobleBalanceSkip error, code: $code" } + } + } + } + private fun handleComplianceResponse(response: String?, httpCode: Int): ComplianceStatus { var complianceStatus = ComplianceStatus.UNKNOWN var updatedAt: String? = null