Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create memo field for transferInput #401

Merged
merged 2 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Expand Up @@ -25,6 +25,7 @@ enum class TransferInputField(val rawValue: String) {
chain("chain"),
token("token"),
address("address"),
MEMO("memo"),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol this is for linting purposes, but yeah the other enum vals should be renamed at some point (would rather not incorporate into this PR)

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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class TransferInputTests : V3BaseTests() {

testTransferOutTransferInput()
perp.log("Transfer Out", time)

testTransferInputTypeChange()
}

private fun testDepositTransferInput() {
Expand Down Expand Up @@ -414,6 +416,10 @@ class TransferInputTests : V3BaseTests() {
perp.transfer("5000.0", TransferInputField.usdcSize)
}, null)

test({
perp.transfer("test memo", TransferInputField.MEMO)
}, null)

test(
{
perp.transfer("1000.0", TransferInputField.usdcSize)
Expand All @@ -423,6 +429,7 @@ class TransferInputTests : V3BaseTests() {
"input": {
"transfer": {
"type": "TRANSFER_OUT",
"memo": "test memo",
"size": {
"usdcSize": 1000.0
},
Expand Down Expand Up @@ -469,4 +476,70 @@ class TransferInputTests : V3BaseTests() {
},
)
}

private fun testTransferInputTypeChange() {
test(
{
perp.transfer("DEPOSIT", TransferInputField.type)
},
"""
{
"input": {
"transfer": {
"type": "DEPOSIT",
"memo": null
}
}
}
""".trimIndent(),
)

test(
{
perp.transfer("TRANSFER_OUT", TransferInputField.type)
},
"""
{
"input": {
"transfer": {
"type": "TRANSFER_OUT",
"memo": null
}
}
}
""".trimIndent(),
)

test(
{
perp.transfer("test memo", TransferInputField.MEMO)
},
"""
{
"input": {
"transfer": {
"type": "TRANSFER_OUT",
"memo": "test memo"
}
}
}
""".trimIndent(),
)

test(
{
perp.transfer("WITHDRAWAL", TransferInputField.type)
},
"""
{
"input": {
"transfer": {
"type": "WITHDRAWAL",
"memo": null
}
}
}
""".trimIndent(),
)
}
}
Loading