Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Contributing to Yield Aggregator

We welcome contributions to the Yield Aggregator smart contract! This document provides guidelines and instructions for contributing.

## Development Process

1. **Fork the Repository**
- Create your own fork of the project
- Set up your local development environment

2. **Create a Feature Branch**
- Branch naming convention: `feature/description` or `fix/description`
- Keep changes focused and atomic

3. **Development Guidelines**

- Follow Clarity best practices
- Maintain consistent code style
- Add comments for complex logic
- Update documentation as needed

4. **Testing Requirements**

- Add tests for new features
- Ensure all existing tests pass
- Test edge cases thoroughly
- Document test scenarios

5. **Code Review Process**

- Submit detailed pull requests
- Respond to review comments
- Make requested changes promptly
- Ensure CI checks pass

## Code Style Guidelines

### Clarity Conventions

```clarity
;; Use clear, descriptive names
(define-constant MAX-STRATEGIES u10)

;; Group related functions
;; Strategy management functions
(define-public (add-strategy ...) ...)
(define-public (update-strategy ...) ...)

;; Add meaningful comments
;; Calculate user's share of the pool based on deposit amount
(define-private (calculate-shares (amount uint)) ...)
```

### Documentation Standards

- Use clear, concise comments
- Document function parameters and return values
- Explain complex calculations
- Update README for significant changes

## Testing Guidelines

1. **Unit Tests**
- Test individual functions
- Cover edge cases
- Verify error conditions

2. **Integration Tests**
- Test interaction between components
- Verify end-to-end workflows
- Test with realistic data

3. **Security Tests**
- Test access controls
- Verify fund safety
- Check error handling

## Submitting Changes

1. **Pull Request Process**
- Create detailed PR description
- Reference related issues
- Include test results
- Update documentation

2. **Review Process**
- Address review comments
- Make requested changes
- Maintain PR discussion

3. **Merge Requirements**
- All tests passing
- Documentation updated
- Code review approved
- CI checks successful

## Getting Help

- Join our developer community
- Ask questions in issues
- Review existing documentation
- Contact maintainers
26 changes: 16 additions & 10 deletions Clarinet.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@

[project]
name = "yield-aggregator-protocol"
authors = []
description = ""
telemetry = true
requirements = []
[contracts.sip-010-trait]
path = "contracts/sip-010-trait.clar"
depends_on = []

[contracts.yield-aggregator]
path = "contracts/yield-aggregator.clar"
depends_on = ["sip-010-trait"]

[repl]
costs_version = 2
parser_version = 2

[repl.analysis]
passes = ["check_checker"]

[repl.analysis.check_checker]
# If true, inputs are trusted after tx_sender has been checked.
strict = false
trusted_sender = false
# If true, inputs are trusted after contract-caller has been checked.
trusted_caller = false
# If true, untrusted data may be passed into a private function without a
# warning, if it gets checked inside. This check will also propagate up to the
# caller.
callee_filter = false

# [contracts.counter]
# path = "contracts/counter.clar"
# depends_on = []
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Yield Aggregator

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
131 changes: 131 additions & 0 deletions READMEmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Yield Aggregator Smart Contract

A sophisticated yield optimization protocol built on Stacks blockchain that automatically allocates deposited tokens across multiple DeFi strategies to maximize returns while managing risk.

## Features

- **Automated Yield Optimization**: Dynamically allocates funds to the highest-yielding strategies
- **Multi-Strategy Support**: Supports up to 10 concurrent yield-generating strategies
- **SIP-010 Compliant**: Fully implements the SIP-010 fungible token standard
- **Risk Management**: Built-in risk scoring system and emergency shutdown mechanism
- **Fee Structure**: Configurable performance and management fees
- **User Shares**: Proportional share token system for tracking user deposits

## Architecture

### Core Components

1. **Strategy Management**

- Dynamic strategy registration
- APY tracking and updates
- Risk scoring system
- TVL monitoring
- Strategy allocation limits

2. **User Management**

- Deposit tracking
- Share token calculation
- Withdrawal processing
- Balance management

3. **Security Features**
- Emergency shutdown
- Access controls
- Reentrancy protection
- Slippage checks

### Key Data Structures

- `Strategies`: Stores strategy information and performance metrics
- `UserDeposits`: Tracks user deposits and share tokens
- `StrategyAllocations`: Manages strategy allocation parameters

## Usage

### For Users

```clarity
;; Deposit tokens
(contract-call? .yield-aggregator deposit token-trait amount)

;; Withdraw tokens
(contract-call? .yield-aggregator withdraw token-trait share-amount)

;; Query user info
(contract-call? .yield-aggregator get-user-info user-principal)
```

### For Administrators

```clarity
;; Add new strategy
(contract-call? .yield-aggregator add-strategy name protocol min-deposit max-deposit)

;; Update strategy APY
(contract-call? .yield-aggregator update-strategy-apy strategy-id new-apy)

;; Toggle emergency shutdown
(contract-call? .yield-aggregator toggle-emergency-shutdown)
```

## Error Codes

| Code | Description |
| ---- | -------------------------- |
| u100 | Not authorized |
| u101 | Invalid amount |
| u102 | Insufficient balance |
| u103 | Strategy already exists |
| u104 | Strategy not found |
| u105 | Strategy disabled |
| u106 | Maximum strategies reached |
| u107 | Slippage too high |
| u108 | Emergency shutdown active |

## Security Considerations

1. **Access Control**

- Contract owner privileges
- Strategy management restrictions
- Emergency shutdown capability

2. **Fund Safety**

- Deposit/withdrawal validations
- Balance checks
- Share token calculations

3. **Risk Management**
- Strategy risk scoring
- Allocation limits
- Emergency procedures

## Testing

Comprehensive test coverage is essential. Test cases should include:

1. Basic functionality

- Deposits
- Withdrawals
- Share calculations

2. Strategy management

- Adding strategies
- Updating APY
- Allocation logic

3. Security features

- Access controls
- Emergency shutdown
- Error conditions

4. Edge cases
- Zero amounts
- Maximum values
- Invalid inputs
25 changes: 25 additions & 0 deletions contracts/sip-010-trait.clar
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
;; SIP-010 Fungible Token Standard
(define-trait sip-010-token
(
;; Transfer from the caller to a new principal
(transfer (uint principal principal (optional (buff 34))) (response bool uint))

;; Returns the total number of tokens
(get-total-supply () (response uint uint))

;; Returns the token balance of the specified principal
(get-balance (principal) (response uint uint))

;; Returns the token name
(get-name () (response (string-ascii 32) uint))

;; Returns the token symbol
(get-symbol () (response (string-ascii 32) uint))

;; Returns the number of decimals used
(get-decimals () (response uint uint))

;; Returns the URI containing token metadata
(get-token-uri () (response (optional (string-utf8 256)) uint))
)
)
Loading