|
| 1 | +package exchange.dydx.abacus.functional |
| 2 | + |
| 3 | +import exchange.dydx.abacus.output.TransferStatus |
| 4 | +import exchange.dydx.abacus.output.input.TransferInput |
| 5 | +import exchange.dydx.abacus.output.input.TransferInputSummary |
| 6 | + |
| 7 | +interface ClientTrackableEvent { |
| 8 | + val name: String |
| 9 | + val customParameters: Map<String, Any> |
| 10 | +} |
| 11 | + |
| 12 | +class ClientTrackableEventType { |
| 13 | + |
| 14 | + class AppStart : ClientTrackableEvent { |
| 15 | + override val name: String |
| 16 | + get() = "AppStart" |
| 17 | + |
| 18 | + override val customParameters: Map<String, Any> |
| 19 | + get() = emptyMap() |
| 20 | + } |
| 21 | + |
| 22 | + class DeepLinkHandled(private val url: String, private val succeeded: Boolean) : |
| 23 | + ClientTrackableEvent { |
| 24 | + override val name: String get() = "DeeplinkHandled" |
| 25 | + override val customParameters: Map<String, Any> |
| 26 | + get() = mapOf( |
| 27 | + "url" to url, |
| 28 | + "succeeded" to succeeded, |
| 29 | + ) |
| 30 | + } |
| 31 | + |
| 32 | + class NotificationPermissionsChanged(private val isAuthorized: Boolean) : ClientTrackableEvent { |
| 33 | + override val name: String get() = "NotificationPermissionsChanged" |
| 34 | + override val customParameters: Map<String, Any> |
| 35 | + get() = mapOf( |
| 36 | + "is_authorized" to isAuthorized, |
| 37 | + ) |
| 38 | + |
| 39 | + override fun toString(): String = name |
| 40 | + } |
| 41 | + |
| 42 | + class ModeSelectorEvent(private val fromMode: String, private val toMode: String) : |
| 43 | + ClientTrackableEvent { |
| 44 | + override val name: String get() = "ModeSelectorEvent" |
| 45 | + override val customParameters: Map<String, Any> |
| 46 | + get() = mapOf( |
| 47 | + "from" to fromMode, |
| 48 | + "to" to toMode, |
| 49 | + ) |
| 50 | + } |
| 51 | + |
| 52 | + class OnboardingStepChanged( |
| 53 | + private val step: String, |
| 54 | + private val state: String |
| 55 | + ) : ClientTrackableEvent { |
| 56 | + override val name: String get() = "OnboardingStepChanged" |
| 57 | + override val customParameters: Map<String, Any> |
| 58 | + get() = mapOf( |
| 59 | + "step" to step, |
| 60 | + "state" to state, |
| 61 | + ) |
| 62 | + } |
| 63 | + |
| 64 | + class VaultFormPreviewStep( |
| 65 | + private val amount: Double, |
| 66 | + private val type: String |
| 67 | + ) : ClientTrackableEvent { |
| 68 | + override val name: String get() = "VaultFormPreviewStep" |
| 69 | + override val customParameters: Map<String, Any> |
| 70 | + get() = mapOf( |
| 71 | + "amount" to amount, |
| 72 | + "operation" to type, |
| 73 | + ) |
| 74 | + } |
| 75 | + |
| 76 | + class AttemptVaultOperation( |
| 77 | + private val type: String, |
| 78 | + private val amount: Double?, |
| 79 | + private val slippage: Double? |
| 80 | + ) : ClientTrackableEvent { |
| 81 | + override val name: String get() = "AttemptVaultOperation" |
| 82 | + |
| 83 | + override val customParameters: Map<String, Any> |
| 84 | + get() = |
| 85 | + mapOf( |
| 86 | + "operation" to type, |
| 87 | + "amount" to amount, |
| 88 | + "slippage" to slippage, |
| 89 | + ).filterValues { it != null } as Map<String, Any> |
| 90 | + } |
| 91 | + |
| 92 | + class SuccessfulVaultOperation( |
| 93 | + private val type: String, |
| 94 | + private val amount: Double, |
| 95 | + private val amountDiff: Double |
| 96 | + ) : ClientTrackableEvent { |
| 97 | + override val name: String get() = "SuccessfulVaultOperation" |
| 98 | + override val customParameters: Map<String, Any> get() = mapOf( |
| 99 | + "operation" to type, |
| 100 | + "amount" to amount, |
| 101 | + "amountDiff" to amountDiff, |
| 102 | + ) |
| 103 | + |
| 104 | + override fun toString(): String = name |
| 105 | + } |
| 106 | + |
| 107 | + class VaultOperationProtocolError( |
| 108 | + private val type: String |
| 109 | + ) : ClientTrackableEvent { |
| 110 | + override val name: String get() = "VaultOperationProtocolError" |
| 111 | + override val customParameters: Map<String, Any> get() = mapOf( |
| 112 | + "operation" to type, |
| 113 | + ) |
| 114 | + } |
| 115 | + |
| 116 | + class RoutingEvent( |
| 117 | + private val fromPath: String? = null, |
| 118 | + private val toPath: String, |
| 119 | + private val fromQuery: String? = null, |
| 120 | + private val toQuery: String? = null |
| 121 | + ) : ClientTrackableEvent { |
| 122 | + override val name: String get() = "RoutingEvent" |
| 123 | + override val customParameters: Map<String, Any> get() = mapOf( |
| 124 | + "fromPath" to (fromPath ?: "nil"), |
| 125 | + "toPath" to toPath, |
| 126 | + "fromQuery" to (fromQuery ?: "nil"), |
| 127 | + "toQuery" to (toQuery ?: "nil"), |
| 128 | + ) |
| 129 | + } |
| 130 | + |
| 131 | + class AppModeSurveyEvent( |
| 132 | + private val option1: Boolean, |
| 133 | + private val option2: Boolean, |
| 134 | + private val option3: Boolean, |
| 135 | + private val feedback: String? = null, |
| 136 | + private val isSubmit: Boolean, |
| 137 | + private val isDoNotShowAgain: Boolean |
| 138 | + ) : ClientTrackableEvent { |
| 139 | + override val name: String get() = "AppModeSurveyEvent" |
| 140 | + override val customParameters: Map<String, Any> get() = mapOf( |
| 141 | + "option1" to option1, |
| 142 | + "option2" to option2, |
| 143 | + "option3" to option3, |
| 144 | + "feedback" to (feedback ?: "nil"), |
| 145 | + "isSubmit" to isSubmit, |
| 146 | + "isDoNotShowAgain" to isDoNotShowAgain, |
| 147 | + ) |
| 148 | + } |
| 149 | + |
| 150 | + class DepositInitiatedEvent( |
| 151 | + private val transferInput: TransferInput, |
| 152 | + private val summary: TransferInputSummary? |
| 153 | + ) : ClientTrackableEvent { |
| 154 | + override val name: String get() = "DepositInitiated" |
| 155 | + override val customParameters: Map<String, Any> get() = mapOf( |
| 156 | + "sourceAssetDenom" to transferInput.token, |
| 157 | + "sourceAssetChainID" to transferInput.chain, |
| 158 | + "amountIn" to transferInput.size?.size, |
| 159 | + "amountOut" to summary?.toAmount, |
| 160 | + "usdAmountOut" to summary?.toAmountUSDC, |
| 161 | + "estimatedAmountOut" to summary?.toAmountMin, |
| 162 | + "swapPriceImpactPercent" to summary?.aggregatePriceImpact, |
| 163 | + "estimatedRouteDurationSeconds" to summary?.estimatedRouteDurationSeconds, |
| 164 | + ).filterValues { it != null } as Map<String, Any> |
| 165 | + } |
| 166 | + |
| 167 | + class DepositSubmittedEvent( |
| 168 | + private val transferInput: TransferInput, |
| 169 | + private val summary: TransferInputSummary?, |
| 170 | + private val txHash: String, |
| 171 | + private val isInstantDeposit: Boolean |
| 172 | + ) : ClientTrackableEvent { |
| 173 | + override val name: String get() = "DepositSubmitted" |
| 174 | + override val customParameters: Map<String, Any> get() = mapOf( |
| 175 | + "tokenInDenom" to transferInput.token, |
| 176 | + "tokenInChainId" to transferInput.chain, |
| 177 | + "tokenAmount" to transferInput.size?.size, |
| 178 | + "estimatedAmountUsd" to summary?.toAmountUSDC, |
| 179 | + "isInstantDeposit" to isInstantDeposit, |
| 180 | + "txHash" to txHash, |
| 181 | + ).filterValues { it != null } as Map<String, Any> |
| 182 | + } |
| 183 | + |
| 184 | + class DepositErrorEvent( |
| 185 | + private val transferInput: TransferInput, |
| 186 | + private val errorMessage: String |
| 187 | + ) : ClientTrackableEvent { |
| 188 | + override val name: String get() = "DepositError" |
| 189 | + override val customParameters: Map<String, Any> get() = mapOf( |
| 190 | + "tokenInDenom" to transferInput.token, |
| 191 | + "tokenInChainId" to transferInput.chain, |
| 192 | + "error" to errorMessage, |
| 193 | + ).filterValues { it != null } as Map<String, Any> |
| 194 | + } |
| 195 | + |
| 196 | + class DepositFinalizedEvent( |
| 197 | + private val status: TransferStatus |
| 198 | + ) : ClientTrackableEvent { |
| 199 | + override val name: String get() = "DepositFinalized" |
| 200 | + override val customParameters: Map<String, Any> get() = mapOf( |
| 201 | + "tokenInChainId" to status.routeStatuses?.firstOrNull()?.chainId, |
| 202 | + ).filterValues { it != null } as Map<String, Any> |
| 203 | + |
| 204 | + override fun toString(): String = name |
| 205 | + } |
| 206 | + |
| 207 | + class WithdrawInitiatedEvent( |
| 208 | + private val transferInput: TransferInput, |
| 209 | + private val summary: TransferInputSummary? |
| 210 | + ) : ClientTrackableEvent { |
| 211 | + override val name: String get() = "WithdrawInitiated" |
| 212 | + override val customParameters: Map<String, Any> get() = mapOf( |
| 213 | + "sourceAssetDenom" to transferInput.token, |
| 214 | + "sourceAssetChainID" to transferInput.chain, |
| 215 | + "amountIn" to transferInput.size?.size, |
| 216 | + "amountOut" to summary?.toAmount, |
| 217 | + "usdAmountOut" to summary?.toAmountUSDC, |
| 218 | + "estimatedAmountOut" to summary?.toAmountMin, |
| 219 | + "swapPriceImpactPercent" to summary?.aggregatePriceImpact, |
| 220 | + "estimatedRouteDurationSeconds" to summary?.estimatedRouteDurationSeconds, |
| 221 | + ).filterValues { it != null } as Map<String, Any> |
| 222 | + } |
| 223 | + |
| 224 | + class WithdrawSubmittedEvent( |
| 225 | + private val transferInput: TransferInput, |
| 226 | + private val summary: TransferInputSummary?, |
| 227 | + private val txHash: String, |
| 228 | + private val isInstantWithdraw: Boolean |
| 229 | + ) : ClientTrackableEvent { |
| 230 | + override val name: String get() = "WithdrawSubmitted" |
| 231 | + override val customParameters: Map<String, Any> get() = mapOf( |
| 232 | + "destinationChainId" to transferInput.chain, |
| 233 | + "estimatedAmountUsd" to summary?.toAmountUSDC, |
| 234 | + "isInstantWithdraw" to isInstantWithdraw, |
| 235 | + "txHash" to txHash, |
| 236 | + ).filterValues { it != null } as Map<String, Any> |
| 237 | + } |
| 238 | + |
| 239 | + class WithdrawErrorEvent( |
| 240 | + private val transferInput: TransferInput, |
| 241 | + private val errorMessage: String |
| 242 | + ) : ClientTrackableEvent { |
| 243 | + override val name: String get() = "WithdrawError" |
| 244 | + override val customParameters: Map<String, Any> get() = mapOf( |
| 245 | + "tokenInDenom" to transferInput.token, |
| 246 | + "tokenInChainId" to transferInput.chain, |
| 247 | + "error" to errorMessage, |
| 248 | + ).filterValues { it != null } as Map<String, Any> |
| 249 | + } |
| 250 | + |
| 251 | + class WithdrawFinalizedEvent( |
| 252 | + private val status: TransferStatus |
| 253 | + ) : ClientTrackableEvent { |
| 254 | + override val name: String get() = "WithdrawFinalized" |
| 255 | + |
| 256 | + override val customParameters: Map<String, Any> get() = mapOf( |
| 257 | + "tokenInChainId" to status.routeStatuses?.lastOrNull()?.chainId, |
| 258 | + ).filterValues { it != null } as Map<String, Any> |
| 259 | + } |
| 260 | +} |
0 commit comments