Skip to content

Commit

Permalink
Merge branch 'main' into cosmos-wallet-connected
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryz0nd authored May 31, 2024
2 parents 6fa0137 + 82f7f6d commit 2fb3550
Show file tree
Hide file tree
Showing 17 changed files with 552 additions and 74 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ allprojects {
}

group = "exchange.dydx.abacus"
version = "1.7.41"
version = "1.7.44"

repositories {
google()
Expand Down
79 changes: 77 additions & 2 deletions docs/Input/TransferInput.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ data class TransferInput(
 val fee: Double?,
 val chain: String?,
 val address: String?,
 val memo: String?,
 val depositOptions: DepositInputOptions?,
 val withdrawalOptions: WithdrawalInputOptions?,
 val transferOutOptions: TransferOutInputOptions?,
 val summary: TransferInputSummary?,
 val resources: TransferInputResources?,
 val requestPayload: TransferInputRequestPayload?
Expand Down Expand Up @@ -39,10 +42,22 @@ Selected chain to perform the transfer

Selected token address of the chain to perform the transfer

## memo

Memo for transfer

## depositOptions

structure of [DepositInputOptions](#DepositInputOptions)

## withdrawalOptions

structure of [WithdrawalInputOptions](#WithdrawalInputOptions)

## transferOutOptions

structure of [TransferOutInputOptions](#TransferOutInputOptions)

## summary

structure of [TransferInputSummary](#TransferInputSummary)
Expand Down Expand Up @@ -80,6 +95,66 @@ UX should let the user choose whether to use fast speed

Option of assets to choose from

# WithdrawalInputOptions

data class DepositInputOptions(
 val needsSize: Boolean?,
 val needsAddress: Boolean?,
 val needsFastSpeed: Boolean?,
&emsp;val exchanges: Array<SelectionOption>?
&emsp;val chains: Array<SelectionOption>?
&emsp;val assets: Array<SelectionOption>?
)

## needsSize

UX should let user enter the size

## needsAddress

UX should let user enter a wallet address

## needsFastSpeed

UX should let the user choose whether to use fast speed

## exchanges

Option of exchanges to choose from

## chains

Option of chains to choose from

## assets

Option of assets to choose from

# TransferOutInputOptions

data class TransferOutInputOptions(
&emsp;val needsSize: Boolean?,
&emsp;val needsAddress: Boolean?,
&emsp;val chains: Array<SelectionOption>?,
&emsp;val assets: Array<SelectionOption>?
)

## needsSize

UX should let user enter the size

## needsAddress

UX should let user enter a wallet address

## chains

Option of chains to choose from

## assets

Option of assets to choose from

# TransferInputSummary

data class TransferInputSummary(
Expand All @@ -102,7 +177,7 @@ Whether the transfer transaction can be filled

# TransferInputResources

The chain and token resources of the selected chain and its associated tokens. Use the chainId
The chain and token resources of the selected chain and its associated tokens. Use the chainId
and token address of the key to the maps, respectively, to get the resource.

data class TransferInputResources(
Expand Down Expand Up @@ -147,4 +222,4 @@ data class TransferInputRequestPayload(
&emsp;val gasPrice: String?,
&emsp;val maxFeePerGas: String?,
&emsp;val maxPriorityFeePerGas: String?
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ data class TransferOutInputOptions(
val needsSize: Boolean?,
val needsAddress: Boolean?,
val chains: IList<SelectionOption>?,
val assets: IList<SelectionOption>?
val assets: IList<SelectionOption>?,
) {
companion object {
internal fun create(
Expand Down Expand Up @@ -208,8 +208,8 @@ data class TransferOutInputOptions(
@Serializable
data class TransferInputChainResource(
val chainName: String?,
val rpc: String?,
val networkName: String?,
val rpc: String? = null,
val networkName: String? = null,
val chainId: Int?,
val iconUrl: String?
)
Expand Down Expand Up @@ -474,6 +474,7 @@ data class TransferInput(
val chain: String?,
val token: String?,
val address: String?,
val memo: String?,
val depositOptions: DepositInputOptions?,
val withdrawalOptions: WithdrawalInputOptions?,
val transferOutOptions: TransferOutInputOptions?,
Expand Down Expand Up @@ -509,6 +510,7 @@ data class TransferInput(
val chain = parser.asString(data["chain"])
val token = parser.asString(data["token"])
val address = parser.asString(data["address"])
val memo = parser.asString(data["memo"])

var depositOptions: DepositInputOptions? = null
if (type == TransferType.deposit) {
Expand Down Expand Up @@ -577,6 +579,7 @@ data class TransferInput(
existing.chain != chain ||
existing.token != token ||
existing.address != address ||
existing.memo != memo ||
existing.depositOptions != depositOptions ||
existing.withdrawalOptions != withdrawalOptions ||
existing.transferOutOptions != transferOutOptions ||
Expand All @@ -595,6 +598,7 @@ data class TransferInput(
chain,
token,
address,
memo,
depositOptions,
withdrawalOptions,
transferOutOptions,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
package exchange.dydx.abacus.processor.router.skip

import exchange.dydx.abacus.processor.base.BaseProcessor
import exchange.dydx.abacus.output.input.SelectionOption
import exchange.dydx.abacus.protocols.ParserProtocol

internal class SkipChainProcessor(parser: ParserProtocol) : BaseProcessor(parser) {
private val keyMap = mapOf(
"string" to mapOf(
"chain_name" to "stringKey",
"networkIdentifier" to "stringKey",
"chain_id" to "type",
"logo_uri" to "iconUrl",
),
)

override fun received(
existing: Map<String, Any>?,
internal class SkipChainProcessor(private val parser: ParserProtocol) {
fun received(
payload: Map<String, Any>
): Map<String, Any> {
return transform(existing, payload, keyMap)
): SelectionOption {
return SelectionOption(
stringKey = parser.asString(payload["network_identifier"]) ?: parser.asString(payload["chain_name"]),
string = parser.asString(payload["network_identifier"]) ?: parser.asString(payload["chain_name"]),
type = parser.asString(payload["chain_id"]) ?: "",
iconUrl = parser.asString(payload["logo_uri"]),
)
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
package exchange.dydx.abacus.processor.router.skip

import exchange.dydx.abacus.processor.base.BaseProcessor
import exchange.dydx.abacus.output.input.TransferInputChainResource
import exchange.dydx.abacus.protocols.ParserProtocol

internal class SkipChainResourceProcessor(parser: ParserProtocol) : BaseProcessor(parser) {
private val keyMap = mapOf(
"string" to mapOf(
"chain_name" to "chainName",
"rpc" to "rpc",
"networkName" to "networkName",
"chain_id" to "chainId",
"logo_uri" to "iconUrl",
),
)
internal class SkipChainResourceProcessor(private val parser: ParserProtocol) {

override fun received(
existing: Map<String, Any>?,
fun received(
payload: Map<String, Any>
): Map<String, Any> {
return transform(existing, payload, keyMap)
): TransferInputChainResource {
return TransferInputChainResource(
chainName = parser.asString(payload["chain_name"]),
rpc = parser.asString(payload["rpc"]),
networkName = parser.asString(payload["networkName"]),
chainId = parser.asInt(payload["chain_id"]),
iconUrl = parser.asString(payload["logo_uri"]),
)
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package exchange.dydx.abacus.processor.router.skip

import exchange.dydx.abacus.output.input.SelectionOption
import exchange.dydx.abacus.output.input.TransferInputChainResource
import exchange.dydx.abacus.processor.base.BaseProcessor
import exchange.dydx.abacus.processor.router.IRouterProcessor
import exchange.dydx.abacus.processor.router.SharedRouterProcessor
import exchange.dydx.abacus.protocols.ParserProtocol
import exchange.dydx.abacus.state.internalstate.InternalTransferInputState
import exchange.dydx.abacus.utils.mutable
import exchange.dydx.abacus.utils.safeSet

@Suppress("NotImplementedDeclaration")
internal class SkipProcessor(parser: ParserProtocol) : BaseProcessor(parser), IRouterProcessor {
internal class SkipProcessor(
parser: ParserProtocol,
private val internalState: InternalTransferInputState
) : BaseProcessor(parser), IRouterProcessor {
override var chains: List<Any>? = null

// possibly want to use a different variable so we aren't stuck with this bad type
Expand All @@ -26,8 +33,25 @@ internal class SkipProcessor(parser: ParserProtocol) : BaseProcessor(parser), IR
existing: Map<String, Any>?,
payload: Map<String, Any>
): Map<String, Any>? {
throw NotImplementedError("receivedChains is not implemented in SkipProcessor!")
if (this.chains != null) {
return existing
}
this.chains = parser.asNativeList(payload["chains"])
var modified = mutableMapOf<String, Any>()
existing?.let {
modified = it.mutable()
}
val chainOptions = chainOptions()

internalState.chains = chainOptions
val selectedChainId = defaultChainId()
modified.safeSet("transfer.chain", selectedChainId)
selectedChainId?.let {
internalState.chainResources = chainResources(chainId = selectedChainId)
}
return modified
}

override fun receivedTokens(
existing: Map<String, Any>?,
payload: Map<String, Any>
Expand Down Expand Up @@ -72,7 +96,9 @@ internal class SkipProcessor(parser: ParserProtocol) : BaseProcessor(parser), IR
}

override fun defaultChainId(): String? {
throw NotImplementedError("defaultChainId is not implemented in SkipProcessor!")
val selectedChain = parser.asNativeMap(this.chains?.find { parser.asString(parser.asNativeMap(it)?.get("chain_id")) == "1" })

return parser.asString(selectedChain?.get("chain_id"))
}

override fun selectedTokenSymbol(tokenAddress: String?): String? {
Expand All @@ -91,16 +117,41 @@ internal class SkipProcessor(parser: ParserProtocol) : BaseProcessor(parser), IR
throw NotImplementedError("defaultTokenAddress is not implemented in SkipProcessor!")
}

override fun chainResources(chainId: String?): Map<String, Any>? {
throw NotImplementedError("chainResources is not implemented in SkipProcessor!")
override fun chainResources(chainId: String?): Map<String, TransferInputChainResource>? {
val chainResources = mutableMapOf<String, TransferInputChainResource>()
chainId?.let {
this.chains?.find {
parser.asString(parser.asNativeMap(it)?.get("chain_id")) == chainId
}?.let {
val processor = SkipChainResourceProcessor(parser)
parser.asNativeMap(it)?.let { payload ->
chainResources[chainId] = processor.received(payload)
}
}
}
return chainResources
}

override fun tokenResources(chainId: String?): Map<String, Any>? {
throw NotImplementedError("tokenResources is not implemented in SkipProcessor!")
}

override fun chainOptions(): List<Any> {
throw NotImplementedError("chainOptions is not implemented in SkipProcessor!")
override fun chainOptions(): List<SelectionOption> {
val chainProcessor = SkipChainProcessor(parser)
val options = mutableListOf<SelectionOption>()

this.chains?.let {
for (chain in it) {
parser.asNativeMap(chain)?.let { chain ->
if (parser.asString(chain.get("chainType")) != "cosmos") {
options.add(chainProcessor.received(chain))
}
}
}
}

options.sortBy { parser.asString(it.stringKey) }
return options
}

override fun tokenOptions(chainId: String?): List<Any> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ internal class SquidProcessor(
override fun updateTokensDefaults(modified: MutableMap<String, Any>, selectedChainId: String?) {
val tokenOptions = tokenOptions(selectedChainId)
internalState.tokens = tokenOptions
modified.safeSet("transfer.depositOptions.assets", tokenOptions)
modified.safeSet("transfer.withdrawalOptions.assets", tokenOptions)
modified.safeSet("transfer.token", defaultTokenAddress(selectedChainId))
internalState.tokenResources = tokenResources(selectedChainId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,19 @@ class V4StateManagerConfigs(
return if (environment.isMainNet) "noble-1" else "grand-1"
}

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

fun nobleDenom(): String? {
return "uusdc"
}

private val skipHost: String
get() {
return "https://api.skip.money"
}

private val squidV2Host: String
get() {
return if (environment.isMainNet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import kollections.iListOf
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.jsonObject

internal fun TradingStateMachine.squidChains(payload: String): StateChanges? {
internal fun TradingStateMachine.routerChains(payload: String): StateChanges? {
val json = parser.decodeJsonObject(payload)
return if (json != null) {
input = squidProcessor.receivedChains(input, json)
Expand Down
Loading

0 comments on commit 2fb3550

Please sign in to comment.