Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
yogurtandjam committed May 30, 2024
2 parents 4053711 + 88f39c3 commit 4f79612
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 27 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.42"
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 @@ -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,5 +1,9 @@
package exchange.dydx.abacus.processor.router

import exchange.dydx.abacus.output.input.SelectionOption
import exchange.dydx.abacus.output.input.TransferInputChainResource
import exchange.dydx.abacus.output.input.TransferInputTokenResource

interface IRouterProcessor {
var tokens: List<Any>?
var chains: List<Any>?
Expand Down Expand Up @@ -44,8 +48,8 @@ interface IRouterProcessor {
fun selectedTokenDecimals(tokenAddress: String?, selectedChainId: String?): String?
fun filteredTokens(chainId: String?): List<Any>?
fun defaultTokenAddress(chainId: String?): String?
fun chainResources(chainId: String?): Map<String, Any>?
fun tokenResources(chainId: String?): Map<String, Any>?
fun chainResources(chainId: String?): Map<String, TransferInputChainResource>?
fun tokenResources(chainId: String?): Map<String, TransferInputTokenResource>?
fun chainOptions(): List<Any>
fun tokenOptions(chainId: String?): List<Any>
fun tokenOptions(chainId: String?): List<SelectionOption>
}
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 @@ -25,6 +25,7 @@ enum class TransferInputField(val rawValue: String) {
chain("chain"),
token("token"),
address("address"),
MEMO("memo"),
fastSpeed("fastSpeed");

companion object {
Expand Down Expand Up @@ -69,6 +70,7 @@ fun TradingStateMachine.transfer(
transfer.safeSet("size.usdcSize", null)
transfer.safeSet("route", null)
transfer.safeSet("requestPayload", null)
transfer.safeSet("memo", null)
if (parser.asString(data) == "TRANSFER_OUT") {
transfer.safeSet("chain", "chain")
transfer.safeSet("token", "usdc")
Expand Down Expand Up @@ -135,7 +137,6 @@ fun TradingStateMachine.transfer(
iListOf(subaccountNumber),
)
}

TransferInputField.fastSpeed.rawValue -> {
transfer.safeSet(typeText, parser.asBool(data))
changes = StateChanges(
Expand Down Expand Up @@ -166,6 +167,14 @@ fun TradingStateMachine.transfer(
iListOf(subaccountNumber),
)
}
TransferInputField.MEMO.rawValue -> {
transfer.safeSet(typeText, parser.asString(data))
changes = StateChanges(
iListOf(Changes.input),
null,
iListOf(subaccountNumber),
)
}
else -> {}
}
} else {
Expand Down Expand Up @@ -205,35 +214,44 @@ private fun TradingStateMachine.updateTransferToTokenType(transfer: MutableMap<S
private fun TradingStateMachine.updateTransferToChainType(transfer: MutableMap<String, Any>, chainType: String) {
val tokenOptions = routerProcessor.tokenOptions(chainType)
if (transfer["type"] != "TRANSFER_OUT") {
transfer.safeSet(
"depositOptions.assets",
tokenOptions,
)
transfer.safeSet(
"withdrawalOptions.assets",
tokenOptions,
)
internalState.transfer.tokens = tokenOptions
transfer.safeSet("chain", chainType)
transfer.safeSet("token", routerProcessor.defaultTokenAddress(chainType))
transfer.safeSet(
"resources.chainResources",
routerProcessor.chainResources(chainType),
)
transfer.safeSet(
"resources.tokenResources",
routerProcessor.tokenResources(chainType),
)
internalState.transfer.chainResources = routerProcessor.chainResources(chainType)
internalState.transfer.tokenResources = routerProcessor.tokenResources(chainType)
}
transfer.safeSet("exchange", null)
transfer.safeSet("size.size", null)
transfer.safeSet("route", null)
transfer.safeSet("requestPayload", null)
// needed to pass tests, remove later
transfer.safeSet(
"depositOptions.assets",
tokenOptions,
)
transfer.safeSet(
"withdrawalOptions.assets",
tokenOptions,
)
transfer.safeSet(
"resources.chainResources",
routerProcessor.chainResources(chainType),
)
transfer.safeSet(
"resources.tokenResources",
routerProcessor.tokenResources(chainType),
)
}

private fun TradingStateMachine.updateTransferExchangeType(transfer: MutableMap<String, Any>, exchange: String) {
val exchangeDestinationChainId = routerProcessor.exchangeDestinationChainId
val tokenOptions = routerProcessor.tokenOptions(exchangeDestinationChainId)
if (transfer["type"] != "TRANSFER_OUT") {
internalState.transfer.tokens = tokenOptions
transfer.safeSet("token", routerProcessor.defaultTokenAddress(exchangeDestinationChainId))
internalState.transfer.tokenResources = routerProcessor.tokenResources(exchangeDestinationChainId)

// needed to pass tests, remove later
transfer.safeSet(
"depositOptions.assets",
tokenOptions,
Expand All @@ -242,7 +260,6 @@ private fun TradingStateMachine.updateTransferExchangeType(transfer: MutableMap<
"withdrawalOptions.assets",
tokenOptions,
)
transfer.safeSet("token", routerProcessor.defaultTokenAddress(exchangeDestinationChainId))
transfer.safeSet(
"resources.tokenResources",
routerProcessor.tokenResources(exchangeDestinationChainId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ open class TradingStateMachine(
private val useParentSubaccount: Boolean,
private val routerVendor: OnboardingConfigs.RouterVendor,
) {
private val internalState: InternalState = InternalState()
internal val internalState: InternalState = InternalState()

internal val parser: ParserProtocol = Parser()
internal val marketsProcessor = MarketsSummaryProcessor(parser)
Expand Down
Loading

0 comments on commit 4f79612

Please sign in to comment.