Skip to content

Commit 62084f4

Browse files
authored
Merge pull request #1579 from onflow/token_tutorial_docs_cws
Token tutorial docs cws
2 parents 4a76c09 + 66c7ff7 commit 62084f4

File tree

10 files changed

+394
-506
lines changed

10 files changed

+394
-506
lines changed

docs/blockchain-development-tutorials/forte/flow-actions/basic-combinations.md

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ We will update these tutorials, but you may need to refactor your code if the im
1919

2020
:::
2121

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:
2323

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.
2525

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.
2727

2828
- **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.
2929

3030
- **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.
3131

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.
3333

3434
## Learning objectives
3535

3636
After you complete this tutorial, you will be able to:
3737

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.
3939
- Create and use Sources to provide tokens from various protocols and locations.
4040
- Create and use Sinks to accept tokens up to defined capacity limits.
4141
- Create and use Swappers to exchange tokens between different types with price estimation.
@@ -78,7 +78,7 @@ Source B ↗
7878
Source C ↗
7979
```
8080

81-
**Example**: Multiple DEX aggregators finding the best swap route.
81+
**Example**: Multiple DEX aggregators find the best swap route.
8282

8383
## Common DeFi workflow combinations
8484

@@ -111,7 +111,7 @@ let zapper = IncrementFiPoolLiquidityConnectors.Zapper(
111111
let flowTokens <- flowVault.withdraw(amount: 100.0)
112112
let lpTokens <- zapper.swap(nil, inVault: <-flowTokens)
113113
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.
115115
```
116116

117117
**Benefits:**
@@ -128,7 +128,7 @@ This workflow automatically claims accumulated staking rewards and converts them
128128

129129
**How it works:**
130130

131-
1. Claims pending rewards from a staking pool using user certificate.
131+
1. Claims pending rewards from a staking pool with user certificate.
132132
2. Swaps the reward tokens (for example, FLOW) to stable tokens (for example, USDC).
133133
3. Deposits the stable tokens to a vault with capacity limits.
134134
4. Returns any unconverted tokens back to the user.
@@ -166,9 +166,9 @@ vaultSink.depositCapacity(from: &stableTokens)
166166

167167
**Benefits:**
168168

169-
- **Risk Reduction**: Converts volatile reward tokens to stable assets.
170-
- **Automation**: Single transaction handles claim, swap, and storage.
171-
- **Capital Efficiency**: No manual intervention needed for reward management.
169+
- **Risk Reduction**: converts volatile reward tokens to stable assets.
170+
- **Automation**: single transaction handles claim, swap, and storage.
171+
- **Capital Efficiency**: no manual intervention needed for reward management.
172172

173173
### Liquidity provision & yield farming
174174

@@ -181,7 +181,7 @@ This workflow takes a single token from your vault, converts it into liquidity p
181181
1. Withdraws single token (for example, FLOW) from vault with minimum balance protection.
182182
2. Uses Zapper to split token and create LP position (FLOW/USDC pair).
183183
3. Stakes the resulting LP tokens in a yield farming pool.
184-
4. Begins earning rewards on the staked LP position.
184+
4. Begins to earn rewards on the staked LP position.
185185

186186
```cadence
187187
// 1. Source: Provide single token (e.g., FLOW)
@@ -214,21 +214,21 @@ stakingSink.depositCapacity(from: &lpTokens)
214214

215215
**Benefits:**
216216

217-
- **Yield Optimization**: Converts idle tokens to yield-generating LP positions.
218-
- **Single Transaction**: No need for multiple manual steps or approvals.
217+
- **Yield Optimization**: converts idle tokens to yield-generating LP positions.
218+
- **Single Transaction**: no need for multiple manual steps or approvals.
219219
- **Automatic Staking**: LP tokens immediately start earning rewards.
220220

221221
### Cross-VM bridge and swap
222222

223223
**Goal**: Bridge tokens from Cadence to EVM, swap them, then bridge back.
224224

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.
226226

227227
**How it works:**
228228

229229
1. Withdraws tokens from Cadence vault with minimum balance protection.
230230
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.
232232
4. Bridges the swapped tokens back to Cadence environment.
233233
5. Deposits final tokens to target Cadence vault.
234234

@@ -265,23 +265,23 @@ cadenceSink.depositCapacity(from: &evmTokens)
265265

266266
**Benefits:**
267267

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 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.
271271

272272
### Flash loan arbitrage
273273

274274
**Goal**: Borrow tokens, execute arbitrage, repay loan with profit.
275275

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.
277277

278278
**How it works:**
279279

280280
1. Borrows tokens via flash loan without collateral requirements.
281281
2. Uses multi-swapper to find optimal arbitrage routes across DEXs.
282282
3. Executes trades to exploit price differences.
283283
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.
285285

286286
```cadence
287287
// 1. Flasher: Borrow tokens for arbitrage
@@ -309,7 +309,7 @@ flasher.flashLoan(1000.0, callback: arbitrageCallback)
309309
- **Risk-Free Profit**: Transaction reverts if arbitrage isn't profitable.
310310
- **Market Efficiency**: Helps eliminate price discrepancies across DEXs.
311311

312-
## Advanced Wwrkflow combinations
312+
## Advanced Workflow combinations
313313

314314
### VaultSource + Zapper integration
315315

@@ -353,9 +353,9 @@ log("LP tokens created: ".concat(lpTokens.balance.toString()))
353353

354354
**Benefits:**
355355

356-
- **Capital Efficiency**: Converts idle vault tokens to yield-generating LP positions.
356+
- **Capital Efficiency**: converts idle vault tokens to yield-generating LP positions.
357357
- **Automated Balancing**: Zapper handles optimal token split calculations automatically
358-
- **Single Transaction**: Complex multi-step process executed atomically.
358+
- **Single Transaction**: complex multi-step process executed atomically.
359359
- **Minimum Protection**: VaultSource ensures vault never goes below safety threshold.
360360

361361
### Price-informed rebalancing
@@ -396,16 +396,16 @@ autoBalancer.rebalance(force: false) // Autonomous rebalancing
396396

397397
**Benefits:**
398398

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.
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.
403403

404404
### Restake and compound strategy
405405

406406
**Goal**: Automatically compound staking rewards back into the pool.
407407

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.
409409

410410
**How it works:**
411411

@@ -451,9 +451,9 @@ poolSink.depositCapacity(from: lpTokens)
451451

452452
**Benefits:**
453453

454-
- **Compound Growth**: Exponential yield increase through automatic reinvestment.
455-
- **Gas Efficiency**: Single transaction handles claim, convert, and re-stake operations.
456-
- **Set-and-Forget**: Automated compounding without manual intervention required.
454+
- **Compound Growth**: exponential yield increase through automatic reinvestment.
455+
- **Gas Efficiency**: single transaction handles claim, convert, and re-stake operations.
456+
- **Set-and-Forget**: automated compounding without manual intervention required.
457457
- **Optimal Conversion**: Zapper ensures efficient reward token to LP token conversion.
458458

459459
## Safety best practices
@@ -486,7 +486,7 @@ assert(afterBalance >= beforeBalance, message: "Balance should not decrease")
486486

487487
### Use graceful degradation
488488

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.
490490

491491
```cadence
492492
// Handle failures gracefully
@@ -514,9 +514,9 @@ defer {
514514
}
515515
```
516516

517-
## Testing your combinations
517+
## Test your combinations
518518

519-
### Unit testing
519+
### Unit tests
520520

521521
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.
522522

@@ -531,7 +531,7 @@ test("VaultSource should maintain minimum balance") {
531531
}
532532
```
533533

534-
### Integration testing
534+
### Integration tests
535535

536536
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.
537537

@@ -549,7 +549,7 @@ test("Reward harvesting workflow should complete successfully") {
549549
}
550550
```
551551

552-
### Simulation testing
552+
### Simulation tests
553553

554554
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.
555555

@@ -576,9 +576,9 @@ test("Strategy should handle price volatility") {
576576

577577
Now that you understand basic combinations, explore:
578578

579-
1. **Advanced Strategies**: Complex multi-step workflows.
580-
2. **Risk Management**: Advanced safety and monitoring techniques.
581-
3. **Custom Connectors**: Building your own protocol adapters.
579+
1. **Advanced Strategies**: complex multi-step workflows.
580+
2. **Risk Management**: advanced safety and monitoring techniques.
581+
3. **Custom Connectors**: build your own protocol adapters.
582582

583583
## Conclusion
584584

0 commit comments

Comments
 (0)