Skip to content

Commit

Permalink
refactor: bonding manager
Browse files Browse the repository at this point in the history
Co-authored-by: 0xFable <[email protected]>
Co-authored-by: nahem <[email protected]>
  • Loading branch information
3 people authored May 20, 2024
2 parents e70bfcb + 61ed894 commit 17ae446
Show file tree
Hide file tree
Showing 94 changed files with 6,168 additions and 4,009 deletions.
15 changes: 9 additions & 6 deletions .github/ISSUE_TEMPLATE/1_bug.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
name: Bug on migaloo-core contracts
about: You are interacting with White Whale's contracts, and you are getting an unexpected behavior, an exception, or something looks wrong.
title: ''
labels: 'bug'
assignees: ''

title: ""
labels: "bug"
assignees: ""
---

<!-- Thank you for using White Whale Migaloo!
Expand All @@ -22,6 +21,7 @@ assignees: ''
If you want to report a security issue, please follow our security policy: `https://github.com/White-Whale-Defi-Platform/migaloo-core/blob/main/SECURITY.md`

---

## Steps to Reproduce

<!-- Please include full steps to reproduce so that we can reproduce the problem. -->
Expand All @@ -37,17 +37,19 @@ If you want to report a security issue, please follow our security policy: `http
---

### Additional context

Add any other context about the problem here, code snippets, json responses and so on.

<details>
<summary>Code sample</summary>

<!--
If case you are working on a smart contract, please attach a minimal reproducible
If case you are working on a smart contract, please attach a minimal reproducible
sample that shows the problem and attach it below between the lines with the backticks.
-->

```rust

```

</details>
Expand All @@ -56,14 +58,15 @@ Add any other context about the problem here, code snippets, json responses and
<summary>Logs</summary>

<!--
Paste the log output below between the lines with the backticks, whether it is
Paste the log output below between the lines with the backticks, whether it is
from compilation or executing a query on chain.
Please see if the error message includes enough information
to explain how to solve the issue.
-->

```
```

</details>
Expand Down
18 changes: 11 additions & 7 deletions .github/ISSUE_TEMPLATE/2_improvement.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
name: Improvement proposal
about: General improvements to the protocol. Anything that exists on Migaloo, is working well but could be enhanced or optimized.
title: ''
labels: 'enhancement'
assignees: ''

title: ""
labels: "enhancement"
assignees: ""
---

<!-- Thank you for using White Whale Migaloo!
Expand All @@ -22,6 +21,7 @@ assignees: ''
If you want to report a security issue, please follow our security policy: `https://github.com/White-Whale-Defi-Platform/migaloo-core/blob/main/SECURITY.md`

---

## Improvement description

<!--
Expand All @@ -32,17 +32,19 @@ If you want to report a security issue, please follow our security policy: `http
---

### Additional context

Add any other context here, code snippets, json responses, screenshots and so on.

<details>
<summary>Code sample</summary>

<!--
If case you are working on a smart contract, please attach a minimal reproducible
If case you are working on a smart contract, please attach a minimal reproducible
sample that shows the problem and attach it below between the lines with the backticks.
-->

```rust

```

</details>
Expand All @@ -51,14 +53,15 @@ Add any other context here, code snippets, json responses, screenshots and so on
<summary>Logs</summary>

<!--
Paste the log output below between the lines with the backticks, whether it is
Paste the log output below between the lines with the backticks, whether it is
from compilation or executing a query on chain.
Please see if the error message includes enough information
to explain how to solve the issue.
-->

```
```

</details>
Expand All @@ -75,10 +78,11 @@ Add any other context here, code snippets, json responses, screenshots and so on
-->

```
```

</details>

<!--
Include any additional resource that doesn't fit the categories previously listed.
-->
-->
9 changes: 4 additions & 5 deletions .github/ISSUE_TEMPLATE/3_feature_request.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
name: Feature request
about: Suggest a new idea for White Whale Migaloo. This is something that doesn't exist currently, and you want to see.
title: ''
labels: 'enhancement'
assignees: ''

title: ""
labels: "enhancement"
assignees: ""
---

<!-- Thank you for using White Whale Migaloo!
Expand Down Expand Up @@ -46,4 +45,4 @@ assignees: ''
Does this have to be provided by White Whale directly, or can it be provided
by a third-party contract? If so, maybe consider implementing and
share it with the community rather than filing a bug.
-->
-->
7 changes: 3 additions & 4 deletions .github/ISSUE_TEMPLATE/4_infrastructure.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
name: The CI infrastructure used by Migaloo has a problem
about: As a contributor, you want to file an issue about the build/test infra, e.g. Github actions etc.
title: ''
labels: 'infra'
assignees: ''

title: ""
labels: "infra"
assignees: ""
---

<!-- Thank you for using White Whale Migaloo!
Expand Down
9 changes: 4 additions & 5 deletions .github/ISSUE_TEMPLATE/5_protocol.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
name: Migaloo's architecture has an issue or can be improved
about: You found an issue with the protocol's architecture, or have ideas on how to make further improvements.
title: ''
labels: 'protocol architecture'
assignees: ''

title: ""
labels: "protocol architecture"
assignees: ""
---

<!-- Thank you for using White Whale Migaloo!
Expand All @@ -23,7 +22,7 @@ assignees: ''

<!--
Please tell us what issue you found, explain how is that a problem to the
Please tell us what issue you found, explain how is that a problem to the
protocol.
Alternatively, what do you think can be improved in the current architecture?
Expand Down
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ incentive-factory = { path = "./contracts/liquidity_hub/pool-network/incentive_f
terraswap-token = { path = "./contracts/liquidity_hub/pool-network/terraswap_token" }
terraswap-pair = { path = "./contracts/liquidity_hub/pool-network/terraswap_pair" }
incentive-manager = { path = "./contracts/liquidity_hub/incentive-manager" }
bonding-manager = { path = "./contracts/liquidity_hub/bonding-manager" }

[workspace.metadata.dylint]
libraries = [{ git = "https://github.com/0xFable/cw-lint" }]
Expand Down
69 changes: 38 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,37 @@

[![codecov](https://codecov.io/github/White-Whale-Defi-Platform/migaloo-core/branch/main/graph/badge.svg?token=Y8S6P1KBS2)](https://codecov.io/github/White-Whale-Defi-Platform/migaloo-core)
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/6401/badge)](https://bestpractices.coreinfrastructure.org/projects/6401)
[![Discord badge][]][Discord invite]
[![Twitter handle][]][Twitter badge]
[![Discord badge][]][discord invite]
[![Twitter handle][]][twitter badge]
[![first-timers-only](https://img.shields.io/badge/first--timers--only-friendly-blue.svg?style=flat-square)](https://www.firsttimersonly.com/)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)

[Discord invite]: https://discord.com/invite/tSxyyCWgYX
[Discord badge]: https://img.shields.io/discord/908044702794801233
[Twitter handle]: https://img.shields.io/twitter/follow/WhiteWhaleDefi.svg?style=social&label=Follow
[Twitter badge]: https://twitter.com/intent/follow?screen_name=WhiteWhaleDefi
[discord invite]: https://discord.com/invite/tSxyyCWgYX
[discord badge]: https://img.shields.io/discord/908044702794801233
[twitter handle]: https://img.shields.io/twitter/follow/WhiteWhaleDefi.svg?style=social&label=Follow
[twitter badge]: https://twitter.com/intent/follow?screen_name=WhiteWhaleDefi

## Getting started

To get started with `white-whale-core`, please go through the [contributing guide](./docs/CONTRIBUTING.md) to see the
To get started with `white-whale-core`, please go through the [contributing guide](./docs/CONTRIBUTING.md) to see the
different ways to contribute to the project.

## Resources

1. [Website](https://whitewhale.money/)
2. [LitePaper](https://whitewhale.money/LitepaperV2.pdf)
3. [Docs](https://docs.whitewhale.money/white-whale)
3. [Docs](https://docs.whitewhale.money/white-whale)
4. [Discord](https://discord.com/invite/tSxyyCWgYX)
5. [Twitter](https://twitter.com/WhiteWhaleDefi)
6. [Telegram](https://t.me/whitewhaleofficial)

## V2 Architecture

White Whale V2 is the next iteration of the White Whale protocol V1. Besides minor yet impactful tweaks, functionality wise V2
hasn't changed much from V1. The main difference is the architecture, which makes it easier to integrate with to other
White Whale V2 is the next iteration of the White Whale protocol V1. Besides minor yet impactful tweaks, functionality wise V2
hasn't changed much from V1. The main difference is the architecture, which makes it easier to integrate with to other
protocols. In V1, the protocol used multiple contracts which makes it complex, factories spawning other contracts and so on.
In V2, the protocol has been simplified significantly and built around singleton contracts. So to get an idea, V1 had 14+ contracts,
while V2 has only 5 contracts.
In V2, the protocol has been simplified significantly and built around singleton contracts. So to get an idea, V1 had 14+ contracts,
while V2 has only 5 contracts.

The following is the V2 architecture, and a general description of each contract:

Expand All @@ -61,67 +61,74 @@ I <-->|on_epoch_created| E
click B "https://github.com/White-Whale-Defi-Platform/white-whale-core/tree/release/v2_contracts/contracts/liquidity_hub/bonding-manager" "Bonding Manager"
click E "https://github.com/White-Whale-Defi-Platform/white-whale-core/tree/release/v2_contracts/contracts/liquidity_hub/epoch-manager" "Epoch Manager"
```

The direction of the arrows represents the dependencies between the contracts.

### Pool Manager
The Pool Manager is the contract that manages the pools in the protocol. It is responsible for creating pool and handling
swaps. Pool creation is permisionless, meaning anyone can create a pool if the fee is paid. The Pool Manager depends on

The Pool Manager is the contract that manages the pools in the protocol. It is responsible for creating pool and handling
swaps. Pool creation is permisionless, meaning anyone can create a pool if the fee is paid. The Pool Manager depends on
both the Incentive and Bonding Managers.

### Vault Manager
The Vault Manager is the contract that manages the vaults in the protocol. It is responsible for creating vaults and performing
flashloan operations. Vault creation is permissionless, meaning anyone can create a vault if the fee is paid. The Vault Manager

The Vault Manager is the contract that manages the vaults in the protocol. It is responsible for creating vaults and performing
flashloan operations. Vault creation is permissionless, meaning anyone can create a vault if the fee is paid. The Vault Manager
depends on the Bonding Manager, as that's where the flashloan fees are sent for distribution.

### Incentive Manager
The Incentive Manager is the contract that manages the incentives in the protocol. It is responsible for creating and
distributing incentives on pools. Incentive creation is permissionless, meaning anyone can create an incentive if the fee is paid.

The Incentive Manager is the contract that manages the incentives in the protocol. It is responsible for creating and
distributing incentives on pools. Incentive creation is permissionless, meaning anyone can create an incentive if the fee is paid.
The Incentive Manager depends on the Epoch Manager, as incentives are distributed based on epochs.

### Bonding Manager

The Bonding Manager is the contract that manages the bonding in the protocol. It is responsible for bonding eligible tokens
and distributing the fees generated by the pools and vaults among the users that bond tokens. The Bonding Manager depends
on the Epoch Manager, as the rewards distribution is done based on epochs.

### Epoch Manager
The Epoch Manager is the contract that manages the epochs in the protocol. Its single responsibility is to create the epochs,

The Epoch Manager is the contract that manages the epochs in the protocol. Its single responsibility is to create the epochs,
which are used by the Incentive and Bonding Managers for distributing incentives and fees.

---
---

## Deployed contracts

White Whale is a protocol that exists across multiple chains. You can find contract addresses for different chain deployments
White Whale is a protocol that exists across multiple chains. You can find contract addresses for different chain deployments
in the [documentation](https://docs.whitewhale.money/white-whale/smart-contracts/liquidity-hub-deployments).

## Building and Deploying White Whale

To build and deploy White Whale's smart contracts, there are a series of deployment scripts under `scripts/`. Alternatively,
there are a few `just` recipes you can take advantage of. You need at least Rust v1.65.0 to compile the contracts.
To build and deploy White Whale's smart contracts, there are a series of deployment scripts under `scripts/`. Alternatively,
there are a few `just` recipes you can take advantage of. You need at least Rust v1.65.0 to compile the contracts.

### Build scripts

- `build_release.sh`: builds the project artifacts, optimized for production.
- `build_schemas.sh`: generates schemas for the contracts.
- `check_artifacts_size.sh`: validates the size of the optimized artifacts. The default maximum size is 600 kB, though
it is customizable by passing the number of kB to the script. For example `check_artifacts_size.sh 400` verifies the
artifacts are under 400 kB.
- `check_artifacts_size.sh`: validates the size of the optimized artifacts. The default maximum size is 600 kB, though
it is customizable by passing the number of kB to the script. For example `check_artifacts_size.sh 400` verifies the
artifacts are under 400 kB.

### Just recipes

All recipes are found in the `justfile`. To see all available recipes, run `just` or `just --list`. Here are some of them:

- `build FEATURE=''` # Builds the whole project with the a feature flag if provided.
- `fmt` # Formats the rust, toml and sh files in the project.
- `get-pools CHAIN` # Extracts the pools from the given chain.
- `schemas` # Generates the schemas for the contracts.
- `build FEATURE=''` # Builds the whole project with the a feature flag if provided.
- `fmt` # Formats the rust, toml and sh files in the project.
- `get-pools CHAIN` # Extracts the pools from the given chain.
- `schemas` # Generates the schemas for the contracts.

### Deployment scripts

TODO update deployment scripts for V2.

## Testing White Whale

To run the tests, run `cargo test`. You can also run `cargo tarpaulin -v` to get test code coverage. Note that the White Whale
To run the tests, run `cargo test`. You can also run `cargo tarpaulin -v` to get test code coverage. Note that the White Whale
project contains a few feature flags that can be used to run the tests. If you want to run the tests for a particular feature,
run `cargo test --features "feature_name"`.

Expand Down
Loading

0 comments on commit 17ae446

Please sign in to comment.