Skip to content

Commit

Permalink
Introduce wallet connection type enum (#656)
Browse files Browse the repository at this point in the history
  • Loading branch information
tian000 authored Sep 16, 2024
1 parent 672a52a commit 2ea207a
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 26 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.5"
version = "1.11.6"

repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import exchange.dydx.abacus.state.model.ClosePositionInputField
import exchange.dydx.abacus.state.model.TradeInputField
import exchange.dydx.abacus.state.model.TransferInputField
import exchange.dydx.abacus.state.model.TriggerOrdersInputField
import exchange.dydx.abacus.state.model.WalletConnectionType
import exchange.dydx.abacus.utils.IList
import kotlin.js.JsExport

Expand Down Expand Up @@ -110,7 +111,7 @@ interface AsyncAbacusStateManagerSingletonProtocol {
var sourceAddress: String?
var subaccountNumber: Int
var market: String?
var cosmosWalletConnected: Boolean?
var walletConnectionType: WalletConnectionType?
}

@JsExport
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package exchange.dydx.abacus.state.model

import kollections.JsExport
import kotlinx.serialization.Serializable

@JsExport
@Serializable
enum class WalletConnectionType(val rawValue: String) { Ethereum("Ethereum"), Cosmos("Cosmos"), Solana("Solana") }
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import exchange.dydx.abacus.state.model.ClosePositionInputField
import exchange.dydx.abacus.state.model.TradeInputField
import exchange.dydx.abacus.state.model.TransferInputField
import exchange.dydx.abacus.state.model.TriggerOrdersInputField
import exchange.dydx.abacus.state.model.WalletConnectionType
import exchange.dydx.abacus.state.v2.supervisor.AppConfigsV2
import exchange.dydx.abacus.utils.CoroutineTimer
import exchange.dydx.abacus.utils.DummyFormatter
Expand Down Expand Up @@ -140,7 +141,7 @@ class AsyncAbacusStateManagerV2(
value?.historicalPnlPeriod = historicalPnlPeriod
value?.candlesResolution = candlesResolution
value?.readyToConnect = readyToConnect
value?.cosmosWalletConnected = cosmosWalletConnected
value?.walletConnectionType = walletConnectionType
field = value
}
}
Expand Down Expand Up @@ -187,11 +188,11 @@ class AsyncAbacusStateManagerV2(
}
}

override var cosmosWalletConnected: Boolean? = false
override var walletConnectionType: WalletConnectionType? = WalletConnectionType.Ethereum
set(value) {
field = value
ioImplementations.threading?.async(ThreadingType.abacus) {
adaptor?.cosmosWalletConnected = field
adaptor?.walletConnectionType = field
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import exchange.dydx.abacus.state.model.TradeInputField
import exchange.dydx.abacus.state.model.TradingStateMachine
import exchange.dydx.abacus.state.model.TransferInputField
import exchange.dydx.abacus.state.model.TriggerOrdersInputField
import exchange.dydx.abacus.state.model.WalletConnectionType
import exchange.dydx.abacus.state.model.tradeInMarket
import exchange.dydx.abacus.state.v2.supervisor.AccountsSupervisor
import exchange.dydx.abacus.state.v2.supervisor.AppConfigsV2
Expand All @@ -68,7 +69,6 @@ import exchange.dydx.abacus.state.v2.supervisor.commitClosePosition
import exchange.dydx.abacus.state.v2.supervisor.commitPlaceOrder
import exchange.dydx.abacus.state.v2.supervisor.commitTriggerOrders
import exchange.dydx.abacus.state.v2.supervisor.connectedSubaccountNumber
import exchange.dydx.abacus.state.v2.supervisor.cosmosWalletConnected
import exchange.dydx.abacus.state.v2.supervisor.depositPayload
import exchange.dydx.abacus.state.v2.supervisor.faucet
import exchange.dydx.abacus.state.v2.supervisor.marketId
Expand All @@ -85,6 +85,7 @@ import exchange.dydx.abacus.state.v2.supervisor.trade
import exchange.dydx.abacus.state.v2.supervisor.triggerCompliance
import exchange.dydx.abacus.state.v2.supervisor.triggerOrders
import exchange.dydx.abacus.state.v2.supervisor.triggerOrdersPayload
import exchange.dydx.abacus.state.v2.supervisor.walletConnectionType
import exchange.dydx.abacus.state.v2.supervisor.withdrawPayload
import exchange.dydx.abacus.utils.AnalyticsUtils
import exchange.dydx.abacus.utils.GEO_POLLING_DURATION_SECONDS
Expand Down Expand Up @@ -281,13 +282,13 @@ internal class StateManagerAdaptorV2(
accounts.accountAddress = value
}

internal var cosmosWalletConnected: Boolean?
internal var walletConnectionType: WalletConnectionType?
get() {
return accounts.cosmosWalletConnected
return accounts.walletConnectionType
}
set(value) {
accounts.cosmosWalletConnected = value
onboarding.cosmosWalletConnected = value
accounts.walletConnectionType = value
onboarding.walletConnectionType = value
}

internal var sourceAddress: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import exchange.dydx.abacus.state.model.ClosePositionInputField
import exchange.dydx.abacus.state.model.TradeInputField
import exchange.dydx.abacus.state.model.TradingStateMachine
import exchange.dydx.abacus.state.model.TriggerOrdersInputField
import exchange.dydx.abacus.state.model.WalletConnectionType
import exchange.dydx.abacus.state.model.account
import exchange.dydx.abacus.state.model.historicalTradingRewards
import exchange.dydx.abacus.state.model.launchIncentivePoints
Expand Down Expand Up @@ -125,10 +126,10 @@ internal open class AccountSupervisor(
}
}

var cosmosWalletConnected: Boolean? = false
var walletConnectionType: WalletConnectionType? = WalletConnectionType.Ethereum
internal set(value) {
field = value
if (value == true) {
if (value == WalletConnectionType.Cosmos) {
nobleBalancesTimer?.cancel()
nobleBalancesTimer = null
}
Expand Down Expand Up @@ -462,7 +463,7 @@ internal open class AccountSupervisor(
}

private fun retrieveNobleBalance() {
if (cosmosWalletConnected == true) {
if (walletConnectionType == WalletConnectionType.Cosmos) {
nobleBalancesTimer = null
return
}
Expand Down Expand Up @@ -1085,7 +1086,7 @@ internal open class AccountSupervisor(
pushNotificationRegistrationHandler.sendPushNotificationToken(
token = pushNotificationToken,
languageCode = pushNotificationLanguageCode,
isKepler = cosmosWalletConnected ?: false,
isKepler = walletConnectionType == WalletConnectionType.Cosmos,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import exchange.dydx.abacus.state.model.ClosePositionInputField
import exchange.dydx.abacus.state.model.TradeInputField
import exchange.dydx.abacus.state.model.TradingStateMachine
import exchange.dydx.abacus.state.model.TriggerOrdersInputField
import exchange.dydx.abacus.state.model.WalletConnectionType
import exchange.dydx.abacus.utils.AnalyticsUtils
import exchange.dydx.abacus.utils.IMap
import exchange.dydx.abacus.utils.iMapOf
Expand Down Expand Up @@ -223,12 +224,12 @@ internal var AccountsSupervisor.accountAddress: String?
}
}

internal var AccountsSupervisor.cosmosWalletConnected: Boolean?
internal var AccountsSupervisor.walletConnectionType: WalletConnectionType?
get() {
return account?.cosmosWalletConnected
return account?.walletConnectionType
}
set(value) {
account?.cosmosWalletConnected = value
account?.walletConnectionType = value
}

internal var AccountsSupervisor.sourceAddress: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import exchange.dydx.abacus.state.manager.SystemUtils
import exchange.dydx.abacus.state.manager.pendingCctpWithdraw
import exchange.dydx.abacus.state.model.TradingStateMachine
import exchange.dydx.abacus.state.model.TransferInputField
import exchange.dydx.abacus.state.model.WalletConnectionType
import exchange.dydx.abacus.state.model.evmSwapVenues
import exchange.dydx.abacus.state.model.routerChains
import exchange.dydx.abacus.state.model.routerStatus
Expand Down Expand Up @@ -88,12 +89,18 @@ internal class OnboardingSupervisor(
private val configs: OnboardingConfigs,
) : NetworkSupervisor(stateMachine, helper, analyticsUtils) {

var cosmosWalletConnected: Boolean? = false
var walletConnectionType: WalletConnectionType? = WalletConnectionType.Ethereum
set(value) {
if (field != value) {
field = value
stateMachine.routerProcessor.selectedChainType =
if (value == true) ChainType.COSMOS else ChainType.EVM
if (value == WalletConnectionType.Cosmos) {
ChainType.COSMOS
} else if (value === WalletConnectionType.Solana) {
ChainType.SVM
} else {
ChainType.EVM
}
}
}

Expand Down Expand Up @@ -248,7 +255,12 @@ internal class OnboardingSupervisor(
val fromTokenDenomForAPIUse = fromTokenSkipDenom ?: fromTokenDenom
val fromAmount = helper.parser.asDecimal(state.input.transfer.size?.size)?.let {
val decimals =
helper.parser.asInt(stateMachine.routerProcessor.selectedTokenDecimals(tokenAddress = fromTokenDenom, selectedChainId = fromChain))
helper.parser.asInt(
stateMachine.routerProcessor.selectedTokenDecimals(
tokenAddress = fromTokenDenom,
selectedChainId = fromChain,
),
)
if (decimals != null) {
(it * Numeric.decimal.TEN.pow(decimals)).toBigInteger()
} else {
Expand Down Expand Up @@ -302,7 +314,10 @@ internal class OnboardingSupervisor(
Logger.ddInfo(body.toIMap(), { "retrieveSkipDepositRouteNonCCTP payload sending" })
helper.post(url, header, body.toJsonPrettyPrint()) { _, response, code, headers ->
if (response != null) {
Logger.ddInfo(helper.parser.decodeJsonObject(response), { "retrieveSkipDepositRouteCCTP payload received" })
Logger.ddInfo(
helper.parser.decodeJsonObject(response),
{ "retrieveSkipDepositRouteCCTP payload received" },
)
val currentFromAmount = stateMachine.state?.input?.transfer?.size?.size
val oldFromAmount = oldState?.input?.transfer?.size?.size
if (currentFromAmount == oldFromAmount) {
Expand All @@ -327,7 +342,12 @@ internal class OnboardingSupervisor(
val fromChain = state?.input?.transfer?.chain ?: return
val fromToken = state.input.transfer.token ?: return
val fromAmount = helper.parser.asDecimal(state.input.transfer.size?.size)?.let {
val decimals = helper.parser.asInt(stateMachine.routerProcessor.selectedTokenDecimals(tokenAddress = fromToken, selectedChainId = fromChain))
val decimals = helper.parser.asInt(
stateMachine.routerProcessor.selectedTokenDecimals(
tokenAddress = fromToken,
selectedChainId = fromChain,
),
)
if (decimals != null) {
(it * Numeric.decimal.TEN.pow(decimals)).toBigInteger()
} else {
Expand Down Expand Up @@ -362,7 +382,10 @@ internal class OnboardingSupervisor(
Logger.ddInfo(body.toIMap(), { "retrieveSkipDepositRouteCCTP payload sending" })
helper.post(url, header, body.toJsonPrettyPrint()) { _, response, code, headers ->
if (response != null) {
Logger.ddInfo(helper.parser.decodeJsonObject(response), { "retrieveSkipDepositRouteCCTP payload received" })
Logger.ddInfo(
helper.parser.decodeJsonObject(response),
{ "retrieveSkipDepositRouteCCTP payload received" },
)
val currentFromAmount = stateMachine.state?.input?.transfer?.size?.size
val oldFromAmount = oldState?.input?.transfer?.size?.size
if (currentFromAmount == oldFromAmount) {
Expand Down Expand Up @@ -718,7 +741,10 @@ internal class OnboardingSupervisor(
Logger.ddInfo(body.toIMap(), { "retrieveSkipWithdrawalRouteNonCCTP payload sending" })
helper.post(url, header, body.toJsonPrettyPrint()) { _, response, code, headers ->
if (response != null) {
Logger.ddInfo(helper.parser.decodeJsonObject(response), { "retrieveSkipWithdrawalRouteNonCCTP payload received" })
Logger.ddInfo(
helper.parser.decodeJsonObject(response),
{ "retrieveSkipWithdrawalRouteNonCCTP payload received" },
)
update(stateMachine.squidRoute(response, subaccountNumber ?: 0, null), oldState)
} else {
Logger.e { "retrieveSkipWithdrawalRouteNonCCTP error, code: $code" }
Expand Down Expand Up @@ -776,7 +802,10 @@ internal class OnboardingSupervisor(
Logger.ddInfo(body.toIMap(), { "retrieveSkipWithdrawalRouteCCTP payload sending" })
helper.post(url, header, body.toJsonPrettyPrint()) { _, response, code, _ ->
if (response != null) {
Logger.ddInfo(helper.parser.decodeJsonObject(response), { "retrieveSkipWithdrawalRouteCCTP payload received" })
Logger.ddInfo(
helper.parser.decodeJsonObject(response),
{ "retrieveSkipWithdrawalRouteCCTP payload received" },
)
val currentFromAmount = stateMachine.state?.input?.transfer?.size?.size
val oldFromAmount = oldState?.input?.transfer?.size?.size
if (currentFromAmount == oldFromAmount) {
Expand Down
2 changes: 1 addition & 1 deletion v4_abacus.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'v4_abacus'
spec.version = '1.11.5'
spec.version = '1.11.6'
spec.homepage = 'https://github.com/dydxprotocol/v4-abacus'
spec.source = { :http=> ''}
spec.authors = ''
Expand Down

0 comments on commit 2ea207a

Please sign in to comment.