Smart Contract
DeFiActions
A.17ae3b1b0b0d50db.DeFiActions
1import FungibleToken from 0xf233dcee88fe0abe
2
3/// DeFiActions: Core interfaces for composable DeFi operations
4///
5/// Based on FlowActions framework: https://github.com/onflow/FlowActions
6/// Provides standardized interfaces for Sources, Sinks, Swappers, and more
7///
8access(all) contract DeFiActions {
9
10 /// Quote: Swap execution parameters
11 access(all) struct Quote {
12 access(all) let expectedAmount: UFix64
13 access(all) let minAmount: UFix64
14 access(all) let slippageTolerance: UFix64
15 access(all) let deadline: UFix64?
16 access(all) let data: {String: AnyStruct}
17
18 init(
19 expectedAmount: UFix64,
20 minAmount: UFix64,
21 slippageTolerance: UFix64,
22 deadline: UFix64?,
23 data: {String: AnyStruct}
24 ) {
25 self.expectedAmount = expectedAmount
26 self.minAmount = minAmount
27 self.slippageTolerance = slippageTolerance
28 self.deadline = deadline
29 self.data = data
30 }
31 }
32
33 /// ComponentInfo: Metadata for traceability
34 access(all) struct ComponentInfo {
35 access(all) let type: String
36 access(all) let identifier: String
37 access(all) let version: String
38
39 init(type: String, identifier: String, version: String) {
40 self.type = type
41 self.identifier = identifier
42 self.version = version
43 }
44 }
45
46 /// Swapper: Token exchange interface
47 ///
48 /// Implements atomic token swaps with quote validation
49 access(all) resource interface Swapper {
50 /// Swap tokens according to quote
51 access(all) fun swap(
52 inVault: @{FungibleToken.Vault},
53 quote: Quote
54 ): @{FungibleToken.Vault}
55
56 /// Get estimated quote for swap
57 access(all) fun getQuote(
58 fromTokenType: Type,
59 toTokenType: Type,
60 amount: UFix64
61 ): Quote
62
63 /// Get swapper info
64 access(all) fun getInfo(): ComponentInfo
65 }
66
67 /// Source: Token provision interface
68 ///
69 /// Provides tokens on demand (withdrawals, claims, etc.)
70 access(all) resource interface Source {
71 /// Withdraw tokens up to specified amount
72 access(all) fun withdraw(amount: UFix64): @{FungibleToken.Vault}
73
74 /// Get available balance
75 access(all) fun getAvailableBalance(): UFix64
76
77 /// Get source info
78 access(all) fun getInfo(): ComponentInfo
79 }
80
81 /// Sink: Token acceptance interface
82 ///
83 /// Accepts tokens within capacity limits (deposits, repayments, etc.)
84 access(all) resource interface Sink {
85 /// Deposit tokens
86 access(all) fun deposit(vault: @{FungibleToken.Vault})
87
88 /// Get current capacity
89 access(all) fun getCapacity(): UFix64
90
91 /// Get sink info
92 access(all) fun getInfo(): ComponentInfo
93 }
94
95 /// PriceOracle: Price data interface
96 ///
97 /// Provides asset price information
98 access(all) resource interface PriceOracle {
99 /// Get price for token pair
100 access(all) fun getPrice(
101 baseToken: Type,
102 quoteToken: Type
103 ): UFix64
104
105 /// Get oracle info
106 access(all) fun getInfo(): ComponentInfo
107 }
108
109 /// Flasher: Flash loan interface
110 ///
111 /// Issues flash loans with callback execution
112 access(all) resource interface Flasher {
113 /// Execute flash loan with callback
114 access(all) fun flashLoan(
115 amount: UFix64,
116 callback: fun(@{FungibleToken.Vault}): @{FungibleToken.Vault}
117 )
118
119 /// Get available flash loan capacity
120 access(all) fun getFlashLoanCapacity(): UFix64
121
122 /// Get flasher info
123 access(all) fun getInfo(): ComponentInfo
124 }
125
126 /// Events for traceability
127 access(all) event SwapExecuted(
128 swapperType: String,
129 fromToken: String,
130 toToken: String,
131 amountIn: UFix64,
132 amountOut: UFix64
133 )
134
135 access(all) event SourceWithdrawal(
136 sourceType: String,
137 tokenType: String,
138 amount: UFix64
139 )
140
141 access(all) event SinkDeposit(
142 sinkType: String,
143 tokenType: String,
144 amount: UFix64
145 )
146}
147