Skip to content

Commit

Permalink
feat: enable testnet
Browse files Browse the repository at this point in the history
  • Loading branch information
yogurtandjam committed Jun 17, 2024
1 parent e364db6 commit b8684b2
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface IRouterProcessor {
var tokens: List<Any>?
var chains: List<Any>?
var exchangeDestinationChainId: String?

fun receivedChains(
existing: Map<String, Any>?,
payload: Map<String, Any>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import exchange.dydx.abacus.processor.router.squid.SquidStatusProcessor
import exchange.dydx.abacus.protocols.ParserProtocol
import exchange.dydx.abacus.state.internalstate.InternalTransferInputState
import exchange.dydx.abacus.state.manager.CctpConfig.cctpChainIds
import exchange.dydx.abacus.utils.NATIVE_TOKEN_DEFAULT_ADDRESS
import exchange.dydx.abacus.utils.mutable
import exchange.dydx.abacus.utils.safeSet

Expand Down Expand Up @@ -47,9 +48,12 @@ internal class SkipProcessor(
modified = it.mutable()
}
val chainOptions = chainOptions()

internalState.chains = chainOptions
val selectedChainId = defaultChainId()
// We diff based on map values in order to determine whether to return new state
// Until we diff on `internalState` changes we need to update old map state as well
modified.safeSet("transfer.depositOptions.chains", chainOptions)
modified.safeSet("transfer.withdrawOptions.chains", chainOptions)
modified.safeSet("transfer.chain", selectedChainId)
selectedChainId?.let {
internalState.chainResources = chainResources(chainId = selectedChainId)
Expand Down Expand Up @@ -118,7 +122,6 @@ internal class SkipProcessor(
return receivedRoute(existing, payload, requestId)
}

// TODO: deduplicate this from squid
override fun usdcAmount(data: Map<String, Any>): Double? {
var toAmountUSD = parser.asString(parser.value(data, "transfer.route.toAmountUSD"))
toAmountUSD = toAmountUSD?.replace(",", "")
Expand All @@ -141,12 +144,19 @@ internal class SkipProcessor(
override fun updateTokensDefaults(modified: MutableMap<String, Any>, selectedChainId: String?) {
val tokenOptions = tokenOptions(selectedChainId)
internalState.tokens = tokenOptions
modified.safeSet("transfer.token", defaultTokenAddress(selectedChainId))
modified.safeSet("transfer.token ", defaultTokenAddress(selectedChainId))
modified.safeSet("transfer.depositOptions.tokens", tokenOptions)
modified.safeSet("transfer.withdrawalOptions.tokens", tokenOptions)
internalState.tokenResources = tokenResources(selectedChainId)
}

private fun getChainById(chainId: String): Map<String, Any>? {
return parser.asNativeMap(this.chains?.find { parser.asString(parser.asNativeMap(it)?.get("chain_id")) == chainId })
}

override fun defaultChainId(): String? {
val selectedChain = parser.asNativeMap(this.chains?.find { parser.asString(parser.asNativeMap(it)?.get("chain_id")) == "1" })
// eth mainnet chainId is 1
val selectedChain = getChainById("1") ?: parser.asNativeMap(this.chains?.firstOrNull())

return parser.asString(selectedChain?.get("chain_id"))
}
Expand Down Expand Up @@ -181,7 +191,7 @@ internal class SkipProcessor(
val assetsMapForChainId = parser.asNativeMap(this.skipTokens?.get(chainIdToUse))
val assetsForChainId = parser.asNativeList(assetsMapForChainId?.get("assets"))
// coinbase exchange chainId is noble-1. we only allow usdc withdrawals from it
if (chainId === "noble-1") {
if (chainId === exchangeDestinationChainId) {
return assetsForChainId?.filter {
parser.asString(parser.asNativeMap(it)?.get("denom")) == "uusdc"
}
Expand All @@ -198,7 +208,7 @@ internal class SkipProcessor(
val denom = parser.asString(token["denom"])
if (denom?.endsWith("native") == true) {
token["skipDenom"] = denom
token["denom"] = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"
token["denom"] = NATIVE_TOKEN_DEFAULT_ADDRESS
}
filteredTokens.add(token.toMap())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,20 @@ class V4StateManagerConfigs(
return if (environment.isMainNet) "noble-1" else "grand-1"
}

fun osmosisChainId(): String? {
return if (environment.isMainNet) "osmosis-1" else "osmosis-5"
fun osmosisChainId(): String {
return if (environment.isMainNet) "osmosis-1" else "osmo-test-5"
}

fun neutronChainId(): String {
return if (environment.isMainNet) "neutron-1" else "pion-1"
}

fun skipV1Chains(): String {
return "$skipHost/v1/info/chains?include_evm=true"
return "$skipHost/v1/info/chains?include_evm=true$onlyTestnets"
}

fun skipV1Assets(): String {
return "$skipHost/v1/fungible/assets?include_evm_assets=true"
return "$skipHost/v1/fungible/assets?include_evm_assets=true$onlyTestnets"
}

fun skipV2MsgsDirect(): String {
Expand All @@ -121,6 +125,11 @@ class V4StateManagerConfigs(

val nobleDenom = "uusdc"

private val onlyTestnets: String
get() {
return if (environment.isMainNet) "" else "&only_testnets=true"
}

private val skipHost: String
get() {
return "https://api.skip.money"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1018,10 +1018,9 @@ internal class OnboardingSupervisor(
return
}
if (fromAmount <= 0) return
val osmosisAddress = accountAddress.toOsmosisAddress() ?: return
val nobleAddress = accountAddress.toNobleAddress() ?: return
val osmosisChainId = helper.configs.osmosisChainId() ?: return
val osmosisChainId = helper.configs.osmosisChainId()
val nobleChainId = helper.configs.nobleChainId()
val neutronChainId = helper.configs.neutronChainId()
val fromChain = helper.environment.dydxChainId ?: return
val fromToken = helper.environment.tokens["usdc"]?.denom ?: return
val fromAmountString = helper.parser.asString(fromAmount) ?: return
Expand All @@ -1034,9 +1033,9 @@ internal class OnboardingSupervisor(
"dest_asset_chain_id" to toChain,
"chain_ids_to_addresses" to mapOf(
fromChain to accountAddress,
osmosisChainId to osmosisAddress,
nobleChainId to nobleAddress,
"neutron-1" to accountAddress.toNeutronAddress(),
osmosisChainId to accountAddress.toOsmosisAddress(),
nobleChainId to accountAddress.toNobleAddress(),
neutronChainId to accountAddress.toNeutronAddress(),
toChain to toAddress,
),
"allow_multi_tx" to true,
Expand Down
2 changes: 2 additions & 0 deletions src/commonMain/kotlin/exchange.dydx.abacus/utils/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ internal const val QUANTUM_MULTIPLIER = 1_000_000

// Route Param Constants
internal const val SLIPPAGE_PERCENT = "1"

internal const val NATIVE_TOKEN_DEFAULT_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"

0 comments on commit b8684b2

Please sign in to comment.