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

Filtered withdrawal assets by cctp.json #763

Merged
merged 6 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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.13.37"
version = "1.13.38"

repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal class TransferInputProcessor(
private val parser: ParserProtocol,
private val calculator: TransferInputCalculatorV2 = TransferInputCalculatorV2(parser = parser),
private val routerProcessor: IRouterProcessor,
private val environment: V4Environment?
private val environment: V4Environment?,
) {
fun transfer(
inputState: InternalInputState,
Expand Down Expand Up @@ -250,8 +250,16 @@ internal class TransferInputProcessor(
private fun updateWithdrawalOptions(
transfer: InternalTransferInputState,
) {
val chains: IList<SelectionOption> = transfer.chains?.toIList() ?: iListOf()
val assets: IList<SelectionOption> = transfer.tokens?.toIList() ?: iListOf()
val chains: IList<SelectionOption> = if (environment?.isMainNet == true && environment?.featureFlags?.cctpWithdrawalOnly == true) {
transfer.cctpChains?.toIList() ?: iListOf()
} else {
transfer.chains?.toIList() ?: iListOf()
}
val assets: IList<SelectionOption> = if (environment?.isMainNet == true && environment?.featureFlags?.cctpWithdrawalOnly == true) {
transfer.cctpTokens?.toIList() ?: iListOf()
} else {
transfer.tokens?.toIList() ?: iListOf()
}
var exchanges: IMutableList<SelectionOption>? = null
exchangeList?.let { data ->
exchanges = iMutableListOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ internal class SkipProcessor(
): Map<String, Any>? {
throw NotImplementedError("receivedV2SdkInfo is not implemented in SkipProcessor!")
}

override 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.output.input.TransferInputTokenResource
import exchange.dydx.abacus.output.input.TransferOutInputOptions
import exchange.dydx.abacus.output.input.TransferType
import exchange.dydx.abacus.output.input.WithdrawalInputOptions
import exchange.dydx.abacus.state.manager.CctpConfig

internal data class InternalTransferInputState(
var chains: List<SelectionOption>? = null,
Expand All @@ -33,7 +34,19 @@ internal data class InternalTransferInputState(
var summary: TransferInputSummary? = null,
var resources: TransferInputResources? = null,
var route: Map<String, Any>? = null,
)
) {
val cctpChains: List<SelectionOption>? // chains filtered by cctp.json
get() =
chains?.filter { chain ->
CctpConfig.cctpChainIds?.any { it.chainId == chain.type } == true
}

val cctpTokens: List<SelectionOption>? // tokens filtered by cctp.json
get() =
tokens?.filter { token ->
CctpConfig.cctpChainIds?.any { it.tokenAddress.lowercase() == token.type.lowercase() } == true
}
}

internal fun TransferInputSize.Companion.safeCreate(existing: TransferInputSize?): TransferInputSize {
return existing ?: TransferInputSize(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ data class EnvironmentLinks(
data class EnvironmentFeatureFlags(
val withdrawalSafetyEnabled: Boolean,
val isSlTpLimitOrdersEnabled: Boolean,
val cctpWithdrawalOnly: Boolean,
) {
companion object {
fun parse(
Expand All @@ -146,10 +147,12 @@ data class EnvironmentFeatureFlags(
): EnvironmentFeatureFlags {
val withdrawalSafetyEnabled = parser.asBool(data?.get("withdrawalSafetyEnabled")) ?: false
val isSlTpLimitOrdersEnabled = parser.asBool(data?.get("isSlTpLimitOrdersEnabled")) ?: false
val cctpWithdrawalOnly = parser.asBool(data?.get("CCTPWithdrawalOnly")) ?: false

return EnvironmentFeatureFlags(
withdrawalSafetyEnabled,
isSlTpLimitOrdersEnabled,
cctpWithdrawalOnly,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class AbacusMockData {
featureFlags = EnvironmentFeatureFlags(
withdrawalSafetyEnabled = true,
isSlTpLimitOrdersEnabled = true,
cctpWithdrawalOnly = true,
),
)
}
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.13.37'
spec.version = '1.13.38'
spec.homepage = 'https://github.com/dydxprotocol/v4-abacus'
spec.source = { :http=> ''}
spec.authors = ''
Expand Down