Smart Contract
DCAHandlerEVM
A.ca7ee55e4fc3251a.DCAHandlerEVM
1import FlowTransactionScheduler from 0xe467b9dd11fa00df
2import DCAServiceEVM from 0xca7ee55e4fc3251a
3
4/// DCAHandlerEVM: Scheduled Transaction Handler for EVM-Native DCA
5///
6/// Executes DCA plans via DCAServiceEVM. Rescheduling handled by backend.
7///
8access(all) contract DCAHandlerEVM {
9
10 access(all) event HandlerCreated(uuid: UInt64)
11 access(all) event ExecutionTriggered(planId: UInt64, success: Bool)
12 access(all) event ExecutionSkipped(planId: UInt64, reason: String)
13
14 access(all) let HandlerStoragePath: StoragePath
15
16 access(all) struct TransactionData {
17 access(all) let planId: UInt64
18 init(planId: UInt64) { self.planId = planId }
19 }
20
21 access(all) resource Handler: FlowTransactionScheduler.TransactionHandler {
22
23 access(FlowTransactionScheduler.Execute)
24 fun executeTransaction(id: UInt64, data: AnyStruct?) {
25 let txData = data as? TransactionData
26 if txData == nil {
27 log("DCAHandlerEVM: Invalid transaction data")
28 return
29 }
30 let planId = txData!.planId
31
32 let planOpt = DCAServiceEVM.getPlan(planId: planId)
33 if planOpt == nil {
34 emit ExecutionSkipped(planId: planId, reason: "Plan not found")
35 return
36 }
37 let plan = planOpt!
38
39 if plan.getStatus() != DCAServiceEVM.PlanStatus.Active {
40 emit ExecutionSkipped(planId: planId, reason: "Plan not active")
41 return
42 }
43
44 let success = DCAServiceEVM.executePlan(planId: planId)
45 emit ExecutionTriggered(planId: planId, success: success)
46 }
47
48 init() { emit HandlerCreated(uuid: self.uuid) }
49 }
50
51 access(all) fun createHandler(): @Handler { return <- create Handler() }
52 access(all) fun createTransactionData(planId: UInt64): TransactionData { return TransactionData(planId: planId) }
53
54 init() { self.HandlerStoragePath = /storage/DCAHandlerEVM }
55}
56