Skip to content

Commit

Permalink
Merge branch 'main' into orders-processor
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredvu authored May 29, 2024
2 parents 9d24e37 + fbf610c commit 5fc5a97
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ internal fun V4StateManagerAdaptor.retrieveDepositExchanges() {
internal fun V4StateManagerAdaptor.retrieveDepositRoute(state: PerpetualState?) {
val isCctp = state?.input?.transfer?.isCctp ?: false
when (appConfigs.squidVersion) {
AppConfigs.SquidVersion.V1, AppConfigs.SquidVersion.V2WithdrawalOnly -> retrieveDepositRouteV1(
AppConfigs.SquidVersion.V2WithdrawalOnly -> retrieveDepositRouteV1(
state,
)

Expand Down Expand Up @@ -273,7 +273,7 @@ internal fun V4StateManagerAdaptor.retrieveWithdrawalRoute(
val isCctp = cctpChainIds?.any { it.isCctpEnabled(state?.input?.transfer) } ?: false
val isExchange = state?.input?.transfer?.exchange != null
when (appConfigs.squidVersion) {
AppConfigs.SquidVersion.V1, AppConfigs.SquidVersion.V2DepositOnly -> retrieveWithdrawalRouteV1(
AppConfigs.SquidVersion.V2DepositOnly -> retrieveWithdrawalRouteV1(
state,
decimals,
gas,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import exchange.dydx.abacus.state.model.onChainRewardTokenPrice
import exchange.dydx.abacus.state.model.onChainRewardsParams
import exchange.dydx.abacus.state.model.onChainUserFeeTier
import exchange.dydx.abacus.state.model.onChainUserStats
import exchange.dydx.abacus.state.model.squidChains
import exchange.dydx.abacus.state.model.squidTokens
import exchange.dydx.abacus.state.model.squidV2SdkInfo
import exchange.dydx.abacus.state.model.updateHeight
import exchange.dydx.abacus.utils.CoroutineTimer
Expand Down Expand Up @@ -294,20 +292,8 @@ class V4StateManagerAdaptor(
override fun didSetReadyToConnect(readyToConnect: Boolean) {
super.didSetReadyToConnect(readyToConnect)
if (readyToConnect) {
when (appConfigs.squidVersion) {
AppConfigs.SquidVersion.V1 -> {
retrieveTransferChains()
retrieveTransferTokens()
}

AppConfigs.SquidVersion.V2,
AppConfigs.SquidVersion.V2DepositOnly,
AppConfigs.SquidVersion.V2WithdrawalOnly -> {
retrieveTransferAssets()
retrieveCctpChainIds()
}
}

retrieveTransferAssets()
retrieveCctpChainIds()
retrieveDepositExchanges()
bestEffortConnectChain()
retrieveLaunchIncentiveSeasons()
Expand Down Expand Up @@ -734,20 +720,6 @@ class V4StateManagerAdaptor(
}
}

private fun retrieveTransferChains() {
val oldState = stateMachine.state
val url = configs.squidChains()
val squidIntegratorId = environment.squidIntegratorId
if (url != null && squidIntegratorId != null) {
val header = iMapOf("x-integrator-id" to squidIntegratorId)
get(url, null, header) { _, response, httpCode, _ ->
if (success(httpCode) && response != null) {
update(stateMachine.squidChains(response), oldState)
}
}
}
}

private fun retrieveTransferAssets() {
val oldState = stateMachine.state
val url = configs.squidV2Assets()
Expand All @@ -762,20 +734,6 @@ class V4StateManagerAdaptor(
}
}

private fun retrieveTransferTokens() {
val oldState = stateMachine.state
val url = configs.squidToken()
val squidIntegratorId = environment.squidIntegratorId
if (url != null && squidIntegratorId != null) {
val header = iMapOf("x-integrator-id" to squidIntegratorId)
get(url, null, header) { _, response, httpCode, _ ->
if (success(httpCode) && response != null) {
update(stateMachine.squidTokens(response), oldState)
}
}
}
}

private fun parseHeight(response: String) {
val json = parser.decodeJsonObject(response)
if (json != null && json["error"] != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ class AppConfigs(
var enableLogger: Boolean = false,
) {
enum class SquidVersion {
V1,
V2,
V2DepositOnly,
V2WithdrawalOnly,
}
var squidVersion: SquidVersion = SquidVersion.V1
var squidVersion: SquidVersion = SquidVersion.V2

companion object {
val forApp = AppConfigs(subscribeToCandles = true, loadRemote = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,12 @@ data class OnboardingConfigs(
val retrieveSquidRoutes: Boolean,
) {
enum class SquidVersion {
V1,
V2,
V2DepositOnly,
V2WithdrawalOnly,
}

var squidVersion: SquidVersion = SquidVersion.V1
var squidVersion: SquidVersion = SquidVersion.V2

companion object {
val forApp = OnboardingConfigs(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ import exchange.dydx.abacus.state.manager.HumanReadableWithdrawPayload
import exchange.dydx.abacus.state.manager.pendingCctpWithdraw
import exchange.dydx.abacus.state.model.TradingStateMachine
import exchange.dydx.abacus.state.model.TransferInputField
import exchange.dydx.abacus.state.model.squidChains
import exchange.dydx.abacus.state.model.squidRoute
import exchange.dydx.abacus.state.model.squidRouteV2
import exchange.dydx.abacus.state.model.squidStatus
import exchange.dydx.abacus.state.model.squidTokens
import exchange.dydx.abacus.state.model.squidV2SdkInfo
import exchange.dydx.abacus.state.model.transfer
import exchange.dydx.abacus.utils.AnalyticsUtils
Expand Down Expand Up @@ -67,33 +65,8 @@ internal class OnboardingSupervisor(
}

private fun retrieveSquidRoutes() {
when (configs.squidVersion) {
OnboardingConfigs.SquidVersion.V1 -> {
retrieveTransferChains()
retrieveTransferTokens()
}

OnboardingConfigs.SquidVersion.V2,
OnboardingConfigs.SquidVersion.V2DepositOnly,
OnboardingConfigs.SquidVersion.V2WithdrawalOnly -> {
retrieveTransferAssets()
retrieveCctpChainIds()
}
}
}

private fun retrieveTransferChains() {
val oldState = stateMachine.state
val url = helper.configs.squidChains()
val squidIntegratorId = helper.environment.squidIntegratorId
if (url != null && squidIntegratorId != null) {
val header = iMapOf("x-integrator-id" to squidIntegratorId)
helper.get(url, null, header) { _, response, httpCode, _ ->
if (helper.success(httpCode) && response != null) {
update(stateMachine.squidChains(response), oldState)
}
}
}
retrieveTransferAssets()
retrieveCctpChainIds()
}

private fun retrieveTransferAssets() {
Expand All @@ -110,20 +83,6 @@ internal class OnboardingSupervisor(
}
}

private fun retrieveTransferTokens() {
val oldState = stateMachine.state
val url = helper.configs.squidToken()
val squidIntegratorId = helper.environment.squidIntegratorId
if (url != null && squidIntegratorId != null) {
val header = iMapOf("x-integrator-id" to squidIntegratorId)
helper.get(url, null, header) { _, response, httpCode, _ ->
if (helper.success(httpCode) && response != null) {
update(stateMachine.squidTokens(response), oldState)
}
}
}
}

private fun retrieveCctpChainIds() {
val url = "${helper.deploymentUri}/configs/cctp.json"
helper.get(url) { _, response, _, _ ->
Expand Down Expand Up @@ -176,7 +135,7 @@ internal class OnboardingSupervisor(
) {
val isCctp = state?.input?.transfer?.isCctp ?: false
when (configs.squidVersion) {
OnboardingConfigs.SquidVersion.V1, OnboardingConfigs.SquidVersion.V2WithdrawalOnly -> retrieveDepositRouteV1(
OnboardingConfigs.SquidVersion.V2WithdrawalOnly -> retrieveDepositRouteV1(
state,
accountAddress,
sourceAddress,
Expand Down Expand Up @@ -530,7 +489,7 @@ internal class OnboardingSupervisor(
CctpConfig.cctpChainIds?.any { it.isCctpEnabled(state?.input?.transfer) } ?: false
val isExchange = state?.input?.transfer?.exchange != null
when (configs.squidVersion) {
OnboardingConfigs.SquidVersion.V1, OnboardingConfigs.SquidVersion.V2DepositOnly -> retrieveWithdrawalRouteV1(
OnboardingConfigs.SquidVersion.V2DepositOnly -> retrieveWithdrawalRouteV1(
state,
decimals,
gas,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ class V4ForegroundCycleTests : NetworkTests() {
"https://indexer.v4staging.dydx.exchange/v4/time",
"https://api.examples.com/configs/markets.json",
"https://api.dydx.exchange/v4/geo",
"https://squid-api-git-main-cosmos-testnet-0xsquid.vercel.app/v1/chains",
"https://squid-api-git-main-cosmos-testnet-0xsquid.vercel.app/v1/tokens",
"https://testnet.v2.api.squidrouter.com/v2/sdk-info",
"https://api.examples.com/configs/cctp.json",
"https://api.examples.com/configs/exchanges.json",
"https://indexer.v4staging.dydx.exchange/v4/height",
"https://dydx.exchange/v4-launch-incentive/query/ccar-perpetuals"
Expand Down Expand Up @@ -169,8 +169,8 @@ class V4ForegroundCycleTests : NetworkTests() {
"https://indexer.v4staging.dydx.exchange/v4/time",
"https://api.examples.com/configs/markets.json",
"https://api.dydx.exchange/v4/geo",
"https://squid-api-git-main-cosmos-testnet-0xsquid.vercel.app/v1/chains",
"https://squid-api-git-main-cosmos-testnet-0xsquid.vercel.app/v1/tokens",
"https://testnet.v2.api.squidrouter.com/v2/sdk-info",
"https://api.examples.com/configs/cctp.json",
"https://api.examples.com/configs/exchanges.json",
"https://indexer.v4staging.dydx.exchange/v4/height",
"https://dydx.exchange/v4-launch-incentive/query/ccar-perpetuals",
Expand Down Expand Up @@ -221,8 +221,8 @@ class V4ForegroundCycleTests : NetworkTests() {
"https://indexer.v4staging.dydx.exchange/v4/time",
"https://api.examples.com/configs/markets.json",
"https://api.dydx.exchange/v4/geo",
"https://squid-api-git-main-cosmos-testnet-0xsquid.vercel.app/v1/chains",
"https://squid-api-git-main-cosmos-testnet-0xsquid.vercel.app/v1/tokens",
"https://testnet.v2.api.squidrouter.com/v2/sdk-info",
"https://api.examples.com/configs/cctp.json",
"https://api.examples.com/configs/exchanges.json",
"https://indexer.v4staging.dydx.exchange/v4/height",
"https://dydx.exchange/v4-launch-incentive/query/ccar-perpetuals",
Expand Down Expand Up @@ -261,8 +261,8 @@ class V4ForegroundCycleTests : NetworkTests() {
"https://indexer.v4staging.dydx.exchange/v4/time",
"https://api.examples.com/configs/markets.json",
"https://api.dydx.exchange/v4/geo",
"https://squid-api-git-main-cosmos-testnet-0xsquid.vercel.app/v1/chains",
"https://squid-api-git-main-cosmos-testnet-0xsquid.vercel.app/v1/tokens",
"https://testnet.v2.api.squidrouter.com/v2/sdk-info",
"https://api.examples.com/configs/cctp.json",
"https://api.examples.com/configs/exchanges.json",
"https://indexer.v4staging.dydx.exchange/v4/height",
"https://dydx.exchange/v4-launch-incentive/query/ccar-perpetuals",
Expand Down Expand Up @@ -325,8 +325,8 @@ class V4ForegroundCycleTests : NetworkTests() {
"https://indexer.v4staging.dydx.exchange/v4/time",
"https://api.examples.com/configs/markets.json",
"https://api.dydx.exchange/v4/geo",
"https://squid-api-git-main-cosmos-testnet-0xsquid.vercel.app/v1/chains",
"https://squid-api-git-main-cosmos-testnet-0xsquid.vercel.app/v1/tokens",
"https://testnet.v2.api.squidrouter.com/v2/sdk-info",
"https://api.examples.com/configs/cctp.json",
"https://api.examples.com/configs/exchanges.json",
"https://indexer.v4staging.dydx.exchange/v4/height",
"https://dydx.exchange/v4-launch-incentive/query/ccar-perpetuals",
Expand Down Expand Up @@ -378,8 +378,8 @@ class V4ForegroundCycleTests : NetworkTests() {
"https://indexer.v4staging.dydx.exchange/v4/time",
"https://api.examples.com/configs/markets.json",
"https://api.dydx.exchange/v4/geo",
"https://squid-api-git-main-cosmos-testnet-0xsquid.vercel.app/v1/chains",
"https://squid-api-git-main-cosmos-testnet-0xsquid.vercel.app/v1/tokens",
"https://testnet.v2.api.squidrouter.com/v2/sdk-info",
"https://api.examples.com/configs/cctp.json",
"https://api.examples.com/configs/exchanges.json",
"https://indexer.v4staging.dydx.exchange/v4/height",
"https://dydx.exchange/v4-launch-incentive/query/ccar-perpetuals",
Expand Down Expand Up @@ -461,8 +461,8 @@ class V4ForegroundCycleTests : NetworkTests() {
"https://indexer.v4staging.dydx.exchange/v4/time",
"https://api.examples.com/configs/markets.json",
"https://api.dydx.exchange/v4/geo",
"https://squid-api-git-main-cosmos-testnet-0xsquid.vercel.app/v1/chains",
"https://squid-api-git-main-cosmos-testnet-0xsquid.vercel.app/v1/tokens",
"https://testnet.v2.api.squidrouter.com/v2/sdk-info",
"https://api.examples.com/configs/cctp.json",
"https://api.examples.com/configs/exchanges.json",
"https://indexer.v4staging.dydx.exchange/v4/height",
"https://dydx.exchange/v4-launch-incentive/query/ccar-perpetuals",
Expand Down Expand Up @@ -509,8 +509,8 @@ class V4ForegroundCycleTests : NetworkTests() {
"https://indexer.v4staging.dydx.exchange/v4/time",
"https://api.examples.com/configs/markets.json",
"https://api.dydx.exchange/v4/geo",
"https://squid-api-git-main-cosmos-testnet-0xsquid.vercel.app/v1/chains",
"https://squid-api-git-main-cosmos-testnet-0xsquid.vercel.app/v1/tokens",
"https://testnet.v2.api.squidrouter.com/v2/sdk-info",
"https://api.examples.com/configs/cctp.json",
"https://api.examples.com/configs/exchanges.json",
"https://indexer.v4staging.dydx.exchange/v4/height",
"https://dydx.exchange/v4-launch-incentive/query/ccar-perpetuals",
Expand Down Expand Up @@ -590,8 +590,8 @@ class V4ForegroundCycleTests : NetworkTests() {
"https://indexer.v4staging.dydx.exchange/v4/time",
"https://api.examples.com/configs/markets.json",
"https://api.dydx.exchange/v4/geo",
"https://squid-api-git-main-cosmos-testnet-0xsquid.vercel.app/v1/chains",
"https://squid-api-git-main-cosmos-testnet-0xsquid.vercel.app/v1/tokens",
"https://testnet.v2.api.squidrouter.com/v2/sdk-info",
"https://api.examples.com/configs/cctp.json",
"https://api.examples.com/configs/exchanges.json",
"https://indexer.v4staging.dydx.exchange/v4/height",
"https://dydx.exchange/v4-launch-incentive/query/ccar-perpetuals",
Expand Down
Loading

0 comments on commit 5fc5a97

Please sign in to comment.