Smart Contract

FlowActionsInterfaces

A.a9c238d801df5106.FlowActionsInterfaces

Valid From

129,871,774

Deployed

1w ago
Feb 21, 2026, 01:22:26 PM UTC

Dependents

1 imports
1import FungibleToken from 0xf233dcee88fe0abe
2
3/// Flow Actions Interfaces
4/// Standardized interfaces for composable DeFi workflows
5/// Based on FLIP 339
6access(all) contract FlowActionsInterfaces {
7
8    /// Source - Provides tokens on demand
9    /// Withdraws from vaults or claims rewards
10    access(all) resource interface Source {
11        /// Get available balance for a token
12        access(all) fun getAvailableBalance(tokenType: Type): UFix64
13
14        /// Withdraw tokens up to amount
15        /// Respects minimum balance constraints
16        access(all) fun withdraw(tokenType: Type, amount: UFix64): @{FungibleToken.Vault}
17
18        /// Get minimum balance that must remain
19        access(all) fun getMinimumBalance(tokenType: Type): UFix64
20    }
21
22    /// Sink - Accepts token deposits
23    /// Deposits to vaults with capacity limits
24    access(all) resource interface Sink {
25        /// Get current capacity for a token
26        access(all) fun getCapacity(tokenType: Type): UFix64
27
28        /// Deposit tokens up to capacity
29        /// No-op when capacity exceeded (doesn't revert)
30        access(all) fun deposit(vault: @{FungibleToken.Vault})
31
32        /// Check if can accept deposit
33        access(all) fun canAccept(tokenType: Type, amount: UFix64): Bool
34    }
35
36    /// Swapper - Exchanges one token for another
37    /// Supports DEX trades, bridges, bidirectional swaps
38    access(all) resource interface Swapper {
39        /// Get quote for a swap (for slippage protection)
40        access(all) fun getQuote(
41            tokenInType: Type,
42            tokenOutType: Type,
43            amountIn: UFix64
44        ): UFix64
45
46        /// Execute swap
47        access(all) fun swap(
48            vaultIn: @{FungibleToken.Vault},
49            tokenOutType: Type,
50            amountOutMin: UFix64
51        ): @{FungibleToken.Vault}
52
53        /// Check if swap path exists
54        access(all) fun canSwap(tokenInType: Type, tokenOutType: Type): Bool
55
56        /// Get supported token pairs
57        access(all) fun getSupportedPairs(): [{String: Type}]
58    }
59
60    /// PriceOracle - Provides real-time price data
61    access(all) resource interface PriceOracle {
62        /// Get price in USD (or reference token)
63        access(all) fun getPrice(tokenType: Type): UFix64
64
65        /// Get price ratio between two tokens
66        access(all) fun getPriceRatio(
67            tokenA: Type,
68            tokenB: Type
69        ): UFix64
70
71        /// Check if price is available
72        access(all) fun hasPriceFor(tokenType: Type): Bool
73    }
74
75    /// Flasher - Issues flash loans
76    access(all) resource interface Flasher {
77        /// Get available flash loan amount
78        access(all) fun getFlashLoanCapacity(tokenType: Type): UFix64
79
80        /// Execute flash loan
81        /// Must be repaid within same transaction
82        access(all) fun flashLoan(
83            tokenType: Type,
84            amount: UFix64,
85            callback: &{FlashLoanCallback}
86        )
87
88        /// Get flash loan fee
89        access(all) fun getFlashLoanFee(tokenType: Type, amount: UFix64): UFix64
90    }
91
92    /// Callback for flash loans
93    access(all) resource interface FlashLoanCallback {
94        access(all) fun executeCallback(
95            loan: @{FungibleToken.Vault}
96        ): @{FungibleToken.Vault}
97    }
98
99    /// Swap configuration
100    access(all) struct SwapConfig {
101        access(all) let tokenInType: Type
102        access(all) let tokenOutType: Type
103        access(all) let amountIn: UFix64
104        access(all) let amountOutMin: UFix64
105        access(all) let deadline: UFix64?
106        access(all) let metadata: {String: String}
107
108        init(
109            tokenInType: Type,
110            tokenOutType: Type,
111            amountIn: UFix64,
112            amountOutMin: UFix64,
113            deadline: UFix64?,
114            metadata: {String: String}
115        ) {
116            self.tokenInType = tokenInType
117            self.tokenOutType = tokenOutType
118            self.amountIn = amountIn
119            self.amountOutMin = amountOutMin
120            self.deadline = deadline
121            self.metadata = metadata
122        }
123    }
124
125    /// Swap result
126    access(all) struct SwapResult {
127        access(all) let amountIn: UFix64
128        access(all) let amountOut: UFix64
129        access(all) let tokenInType: Type
130        access(all) let tokenOutType: Type
131        access(all) let priceImpact: UFix64?
132        access(all) let executedAt: UFix64
133
134        init(
135            amountIn: UFix64,
136            amountOut: UFix64,
137            tokenInType: Type,
138            tokenOutType: Type,
139            priceImpact: UFix64?,
140            executedAt: UFix64
141        ) {
142            self.amountIn = amountIn
143            self.amountOut = amountOut
144            self.tokenInType = tokenInType
145            self.tokenOutType = tokenOutType
146            self.priceImpact = priceImpact
147            self.executedAt = executedAt
148        }
149    }
150
151    /// Events
152    access(all) event SwapExecuted(
153        swapper: Address,
154        tokenIn: String,
155        tokenOut: String,
156        amountIn: UFix64,
157        amountOut: UFix64,
158        priceImpact: UFix64?
159    )
160
161    access(all) event SourceWithdrawn(
162        source: Address,
163        tokenType: String,
164        amount: UFix64
165    )
166
167    access(all) event SinkDeposited(
168        sink: Address,
169        tokenType: String,
170        amount: UFix64
171    )
172}
173