|
| 1 | +# DeFi Actions Starter |
| 2 | + |
| 3 | +This project demonstrates how to build with Flow Actions - a standard for composable DeFi connectors on the Flow blockchain. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This starter project includes a minimal example connector (`TokenSink`) that implements the `DeFiActions.Sink` interface. It shows how to: |
| 8 | + |
| 9 | +- Create a connector that accepts fungible tokens via a receiver capability |
| 10 | +- Compose transactions using Flow Actions patterns |
| 11 | +- Test connectors using the Flow Testing Framework |
| 12 | + |
| 13 | +## Quick Start |
| 14 | + |
| 15 | +Get started in seconds: |
| 16 | + |
| 17 | +```bash |
| 18 | +flow test # Run tests to verify everything works |
| 19 | +``` |
| 20 | + |
| 21 | +That's it! The test deploys all contracts and executes an example transaction. |
| 22 | + |
| 23 | +## Prerequisites |
| 24 | + |
| 25 | +Before running this project, you need to install the Flow CLI: |
| 26 | + |
| 27 | +- **Installation Guide**: https://developers.flow.com/tools/flow-cli/install |
| 28 | + |
| 29 | +**Note**: All dependencies (FungibleToken, FlowToken, DeFiActions, etc.) are already installed in your project during initialization. |
| 30 | + |
| 31 | +## Getting Started |
| 32 | + |
| 33 | +### 1. Run Tests (Recommended First Step) |
| 34 | + |
| 35 | +```bash |
| 36 | +flow test |
| 37 | +``` |
| 38 | + |
| 39 | +This runs the test suite to verify everything works. The tests automatically deploy all contracts and execute the example transaction in an isolated test environment. |
| 40 | + |
| 41 | +### 2. Start the Flow Emulator |
| 42 | + |
| 43 | +```bash |
| 44 | +flow emulator |
| 45 | +``` |
| 46 | + |
| 47 | +This starts a local Flow blockchain for development. |
| 48 | + |
| 49 | +### 3. Deploy the Contracts |
| 50 | + |
| 51 | +In a new terminal: |
| 52 | + |
| 53 | +```bash |
| 54 | +flow project deploy --network emulator |
| 55 | +``` |
| 56 | + |
| 57 | +This deploys all required contracts to the emulator: |
| 58 | +- `DeFiActionsMathUtils` - Math utilities for DeFi Actions |
| 59 | +- `DeFiActionsUtils` - Helper utilities for DeFi Actions |
| 60 | +- `DeFiActions` - Core DeFi Actions framework |
| 61 | +- `ExampleConnectors` - Your TokenSink connector |
| 62 | + |
| 63 | +### 4. Run the Example Transaction |
| 64 | + |
| 65 | +Send tokens to yourself using the TokenSink: |
| 66 | + |
| 67 | +```bash |
| 68 | +flow transactions send cadence/transactions/DepositViaSink.cdc \ |
| 69 | + --signer emulator-account \ |
| 70 | + --network emulator \ |
| 71 | + --args-json '[{"type":"Address","value":"0xf8d6e0586b0a20c7"},{"type":"UFix64","value":"1.0"}]' |
| 72 | +``` |
| 73 | + |
| 74 | +This sends `1.0` FLOW from the emulator account to itself (`0xf8d6e0586b0a20c7`) using the `TokenSink` connector. |
| 75 | + |
| 76 | +## Testing |
| 77 | + |
| 78 | +Run the test suite to verify the connector works correctly: |
| 79 | + |
| 80 | +```bash |
| 81 | +flow test |
| 82 | +``` |
| 83 | + |
| 84 | +The tests run in an isolated environment and automatically: |
| 85 | +1. Deploy all DeFi Actions dependencies (`DeFiActionsMathUtils`, `DeFiActionsUtils`, `DeFiActions`) |
| 86 | +2. Deploy the `ExampleConnectors` contract |
| 87 | +3. Execute the `DepositViaSink` transaction |
| 88 | +4. Verify tokens are deposited successfully |
| 89 | + |
| 90 | +**Note**: Tests don't require the emulator to be running - they use their own test environment. |
| 91 | + |
| 92 | +## Project Structure |
| 93 | + |
| 94 | +- `cadence/contracts/` - Smart contracts |
| 95 | + - `ExampleConnectors.cdc` - TokenSink connector implementation |
| 96 | +- `cadence/transactions/` - Transaction files |
| 97 | + - `DepositViaSink.cdc` - Example transaction using TokenSink |
| 98 | +- `cadence/tests/` - Test files |
| 99 | + - `ExampleConnectors_test.cdc` - Integration test for TokenSink |
| 100 | +- `flow.json` - Flow project configuration with DeFiActions dependencies |
| 101 | + |
| 102 | +## Dependencies |
| 103 | + |
| 104 | +This project includes the following dependencies (already installed): |
| 105 | + |
| 106 | +**Core Dependencies:** |
| 107 | +- `FungibleToken` - Standard fungible token interface |
| 108 | +- `FlowToken` - Native FLOW token implementation |
| 109 | + |
| 110 | +**DeFi Actions Framework:** |
| 111 | +- `DeFiActions` - Core framework for composable DeFi connectors |
| 112 | +- `DeFiActionsUtils` - Helper utilities |
| 113 | +- `DeFiActionsMathUtils` - Math utilities for DeFi operations |
| 114 | + |
| 115 | +**Network Configuration:** |
| 116 | +- **Testnet**: All DeFi Actions contracts available at `0x4c2ff9dd03ab442f` |
| 117 | +- **Mainnet**: All DeFi Actions contracts available at `0x92195d814edf9cb0` |
| 118 | +- **Emulator**: Contracts are deployed from source to your emulator account |
| 119 | + |
| 120 | +## Understanding the TokenSink Connector |
| 121 | + |
| 122 | +The `TokenSink` connector demonstrates a minimal implementation of the `DeFiActions.Sink` interface: |
| 123 | + |
| 124 | +- Accepts a `FungibleToken.Receiver` capability (publicly available) |
| 125 | +- Deposits tokens into the recipient's vault via `depositCapacity()` |
| 126 | +- Includes type checks to ensure safe deposits |
| 127 | + |
| 128 | +## Next Steps |
| 129 | + |
| 130 | +- Explore the [Flow Actions FLIP](https://github.com/onflow/flips/pull/339) for more details on the standard |
| 131 | +- Build your own connectors implementing `Source`, `Sink`, or `Swapper` interfaces |
| 132 | +- Compose complex DeFi operations by chaining multiple connectors |
| 133 | + |
| 134 | +## Resources |
| 135 | + |
| 136 | +- **Flow Actions Repository**: https://github.com/onflow/FlowActions |
| 137 | +- **Flow Documentation**: https://developers.flow.com/ |
| 138 | +- **Cadence Language**: https://cadence-lang.org/docs/language |
| 139 | + |
| 140 | +## Community |
| 141 | + |
| 142 | +- [Flow Community Forum](https://forum.flow.com/) |
| 143 | +- [Flow Discord](https://discord.gg/flow) |
| 144 | +- [Flow Twitter](https://x.com/flow_blockchain) |
| 145 | + |
0 commit comments