You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/blockchain-development-tutorials/forte/flow-actions/basic-combinations.md
+40-40Lines changed: 40 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,23 +19,23 @@ We will update these tutorials, but you may need to refactor your code if the im
19
19
20
20
:::
21
21
22
-
Flow Actions are designed to be **composable**, which means you can chain them together like LEGO blocks to build complex strategies. Each primitive has a standardized interface that works consistently across all protocols and eliminates the need to learn multiple APIs. This composability allows atomic execution of multi-step workflows within single transactions, ensuring either complete success or safe failure. When developers combine these primitives, they create sophisticated decentralized finance (DeFi) strategies like automated yield farming, cross-protocol arbitrage, and portfolio rebalancing. The [5 Flow Actions Primitives] are:
22
+
Flow Actions are designed to be **composable**, which means you can chain them together like LEGO blocks to build complex strategies. Each primitive has a standardized interface that works consistently across all protocols and eliminates the need to learn multiple APIs. This composability allows atomic execution of multi-step workflows within single transactions, which ensures either complete success or safe failure. When developers combine these primitives, they create sophisticated decentralized finance (DeFi) strategies like automated yield farming, cross-protocol arbitrage, and portfolio rebalancing. The [5 Flow Actions Primitives] are:
23
23
24
-
-**Source** → Provides tokens on demand by withdrawing from vaults or claiming rewards. Sources respect minimum balance constraints and return empty vaults gracefully when nothing is available.
24
+
-**Source** → Provides tokens on demand by withdrawl from vaults or reward claims. Sources respect minimum balance constraints and return empty vaults gracefully when nothing is available.
25
25
26
-
-**Sink** → Accepts token deposits up to a specified capacity limit. Sinks perform no-ops rather than reverting when deposits exceed capacity, which allows smooth workflow execution.
26
+
-**Sink** → Accepts token deposits up to a specified capacity limit. Sinks perform no-ops rather than revert when deposits exceed capacity, which allows smooth workflow execution.
27
27
28
28
-**Swapper** → Exchanges one token type for another through DEX trades or cross-chain bridges. Swappers support bidirectional operations and provide quote estimation for slippage protection.
29
29
30
30
-**PriceOracle** → Provides real-time price data for assets from external feeds or DEX prices. Oracles handle staleness validation and return nil for unavailable prices rather than failing.
31
31
32
-
-**Flasher** → Issues flash loans that must be repaid within the same transaction via callback execution. Flashers enable capital-efficient strategies like arbitrage and liquidations without requiring upfront capital.
32
+
-**Flasher** → Issues flash loans that must be repaid within the same transaction via callback execution. Flashers allow capital-efficient strategies like arbitrage and liquidations without the need for upfront capital.
33
33
34
34
## Learning objectives
35
35
36
36
After you complete this tutorial, you will be able to:
37
37
38
-
- Understand the key features of Flow Actions including atomic composition, weak guarantees, and event traceability.
38
+
- Understand the key features of Flow Actions, which includes atomic composition, weak guarantees, and event traceability.
39
39
- Create and use Sources to provide tokens from various protocols and locations.
40
40
- Create and use Sinks to accept tokens up to defined capacity limits.
41
41
- Create and use Swappers to exchange tokens between different types with price estimation.
@@ -78,7 +78,7 @@ Source B ↗
78
78
Source C ↗
79
79
```
80
80
81
-
**Example**: Multiple DEX aggregators finding the best swap route.
81
+
**Example**: Multiple DEX aggregators find the best swap route.
82
82
83
83
## Common DeFi workflow combinations
84
84
@@ -111,7 +111,7 @@ let zapper = IncrementFiPoolLiquidityConnectors.Zapper(
111
111
let flowTokens <- flowVault.withdraw(amount: 100.0)
112
112
let lpTokens <- zapper.swap(nil, inVault: <-flowTokens)
113
113
114
-
// Now you have LP tokens ready for staking or further use
114
+
// Now you have LP tokens ready to stake or for further use.
115
115
```
116
116
117
117
**Benefits:**
@@ -128,7 +128,7 @@ This workflow automatically claims accumulated staking rewards and converts them
128
128
129
129
**How it works:**
130
130
131
-
1. Claims pending rewards from a staking pool using user certificate.
131
+
1. Claims pending rewards from a staking pool with user certificate.
132
132
2. Swaps the reward tokens (for example, FLOW) to stable tokens (for example, USDC).
133
133
3. Deposits the stable tokens to a vault with capacity limits.
134
134
4. Returns any unconverted tokens back to the user.
**Goal**: Bridge tokens from Cadence to EVM, swap them, then bridge back.
224
224
225
-
This workflow demonstrates Flow's unique cross-VM capabilities by bridging tokens from Cadence to Flow EVM, executing a swap using UniswapV2-style routing, and bridging the results back to Cadence. This allows access to EVM-based DEX liquidity while maintaining Cadence token ownership.
225
+
This workflow demonstrates Flow's unique cross-VM capabilities by bridging tokens from Cadence to Flow EVM, executes a swap with UniswapV2-style routing, and bridges the results back to Cadence. This allows access to EVM-based DEX liquidity and maintain Cadence token ownership.
226
226
227
227
**How it works:**
228
228
229
229
1. Withdraws tokens from Cadence vault with minimum balance protection.
230
230
2. Bridges tokens from Cadence to Flow EVM environment.
231
-
3. Executes swap using UniswapV2 router on EVM side.
231
+
3. Executes swap with UniswapV2 router on EVM side.
232
232
4. Bridges the swapped tokens back to Cadence environment.
-**Extended Liquidity**: Access to both Cadence and EVM DEX liquidity.
269
-
-**Cross-VM Arbitrage**: Exploit price differences between VM environments.
270
-
-**Atomic Execution**: All bridging and swapping happens in single transaction.
268
+
-**Extended Liquidity**: access to both Cadence and EVM DEX liquidity.
269
+
-**Cross-VM Arbitrage**: exploit price differences between VM environments.
270
+
-**Atomic Execution**: all bridges and swaps happen in single transaction.
271
271
272
272
### Flash loan arbitrage
273
273
274
274
**Goal**: Borrow tokens, execute arbitrage, repay loan with profit.
275
275
276
-
This advanced strategy uses flash loans to execute risk-free arbitrage by borrowing tokens, exploiting price differences across multiple DEXs, and repaying the loan with interest while keeping the profit. The entire operation happens atomically within a single transaction.
276
+
This advanced strategy uses flash loans to execute risk-free arbitrage. To do this, it borrows tokens, exploits price differences across multiple DEXs, and repays the loan with interest while it keeps the profit. The entire operation happens atomically within a single transaction.
277
277
278
278
**How it works:**
279
279
280
280
1. Borrows tokens via flash loan without collateral requirements.
281
281
2. Uses multi-swapper to find optimal arbitrage routes across DEXs.
282
282
3. Executes trades to exploit price differences.
283
283
4. Repays flash loan with fees from arbitrage profits.
284
-
5. Keeps remaining profit after loan repayment.
284
+
5. Keeps profits that remain profit after loan repayment.
-**Autonomous Operation**: Maintains portfolio balance without manual intervention.
400
-
-**Risk Management**: Prevents excessive exposure through automated position sizing.
401
-
-**Market Responsive**: Adapts to price movements with real-time oracle data.
402
-
-**Threshold Flexibility**: Configurable upper/lower bounds for different risk profiles.
399
+
-**Autonomous Operation**: maintains portfolio balance without manual intervention.
400
+
-**Risk Management**: prevents excessive exposure through automated position sizing.
401
+
-**Market Responsive**: adapts to price movements with real-time oracle data.
402
+
-**Threshold Flexibility**: configurable upper/lower bounds for different risk profiles.
403
403
404
404
### Restake and compound strategy
405
405
406
406
**Goal**: Automatically compound staking rewards back into the pool.
407
407
408
-
This advanced compounding strategy maximizes yield by automatically claiming staking rewards and converting them back into LP tokens for re-staking. The workflow combines rewards claiming, zapping, and staking into a seamless compound operation that accelerates yield accumulation through reinvestment.
408
+
This advanced compounding strategy maximizes yield; it automatically claims staking rewards and converts them back into LP tokens for re-staking. The workflow combines rewards claims, zaps, and staking into a seamless compound operation that accelerates yield accumulation through reinvestment.
@@ -486,7 +486,7 @@ assert(afterBalance >= beforeBalance, message: "Balance should not decrease")
486
486
487
487
### Use graceful degradation
488
488
489
-
Prevents entire workflows from failing when individual components encounter issues. This approach allows robust strategies that can adapt to changing market conditions or temporary protocol unavailability.
489
+
Prevents entire workflows from failure when individual components encounter issues. This approach allows robust strategies that can adapt to volatile market conditions or temporary protocol unavailability.
490
490
491
491
```cadence
492
492
// Handle failures gracefully
@@ -514,9 +514,9 @@ defer {
514
514
}
515
515
```
516
516
517
-
## Testing your combinations
517
+
## Test your combinations
518
518
519
-
### Unit testing
519
+
### Unit tests
520
520
521
521
Tests individual connectors in isolation to verify they respect their constraints and behave correctly under various conditions. This catches bugs early and ensures each component works as designed.
522
522
@@ -531,7 +531,7 @@ test("VaultSource should maintain minimum balance") {
531
531
}
532
532
```
533
533
534
-
### Integration testing
534
+
### Integration tests
535
535
536
536
Validates that multiple connectors work together correctly in complete workflows. This ensures the composition logic is sound and identifies issues that only appear when components interact.
Tests strategies under various market conditions using mock data to verify they respond appropriately to price changes, liquidity variations, and other market dynamics. This is essential for strategies that rely on external market data.
555
555
@@ -576,9 +576,9 @@ test("Strategy should handle price volatility") {
576
576
577
577
Now that you understand basic combinations, explore:
0 commit comments