Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add core compounder contract #126

Merged
merged 11 commits into from
Mar 22, 2024
19 changes: 19 additions & 0 deletions Cargo.lock

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

268 changes: 232 additions & 36 deletions Cookbook.md
matthiasmatt marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some duplicate code here

Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,35 @@
This file describes the different messages that can be sent as queries or transactions
to the contracts of this repository with a description of the expected behavior.

- [Core shifter](#core-shifter)
- [Instantiate](#instantiate)
- [Execute](#execute)
- [Query](#query)
- [Core token vesting](#core-token-vesting)
- [Instantiate](#instantiate-1)
- [Execute](#execute-1)
- [Query](#query-1)
- [4. Nibi Stargate](#4-nibi-stargate)
- [4.1 Instantiate](#41-instantiate)
- [4.2 Execute](#42-execute)
- [5. Nibi Stargate Perp](#5-nibi-stargate-perp)
- [5.1 Instantiate](#51-instantiate)
- [5.2 Execute](#52-execute)
- [6. Nusd Valuator](#6-nusd-valuator)
- [6.1 Instantiate](#61-instantiate)
- [6.2 Execute](#62-execute)
- [6.3 Query](#63-query)
- [Contracts Cookbook](#contracts-cookbook)
- [Core shifter](#core-shifter)
- [Instantiate](#instantiate)
- [Execute](#execute)
- [Query](#query)
- [Core token vesting](#core-token-vesting)
- [Instantiate](#instantiate-1)
- [Execute](#execute-1)
- [Query](#query-1)
- [4. Nibi Stargate](#4-nibi-stargate)
- [4.1 Instantiate](#41-instantiate)
- [4.2 Execute](#42-execute)
- [5. Nibi Stargate Perp](#5-nibi-stargate-perp)
- [5.1 Instantiate](#51-instantiate)
- [5.2 Execute](#52-execute)
- [6. Nusd Valuator](#6-nusd-valuator)
- [6.1 Instantiate](#61-instantiate)
- [6.2 Execute](#62-execute)
- [6.3 Query](#63-query)
- [7. Airdrop token vesting](#7-airdrop-token-vesting)
- [7.1 Instantiate](#71-instantiate)
- [7.2 Execute](#72-execute)
- [7.3 Query](#73-query)
- [8. Auto compounder](#8-auto-compounder)
- [8.1 Instantiate](#81-instantiate)
- [8.2 Execute](#82-execute)
- [Admin functions](#admin-functions)
- [Manager functions](#manager-functions)
- [8.3 Query](#83-query)

## Core shifter

Expand Down Expand Up @@ -101,7 +112,8 @@ This contract implements vesting accounts for the CW20 and native tokens.
There's no instantiation message.

```js
{}
{
}
```

### Execute
Expand Down Expand Up @@ -181,7 +193,8 @@ This smart contract showcases usage examples for certain Nibiru-specific and Cos
There's no instantiation message.

```js
{}
{
}
```

### 4.2 Execute
Expand All @@ -197,33 +210,33 @@ There's no instantiation message.
- **Mint** mints tokens

```js
{
"mint": {
"coin": { "amount": "[amount]", "denom": "tf/[contract-addr]/[subdenom]" },
"mint_to": "[mint-to-addr]"
}
{
"mint": {
"coin": { "amount": "[amount]", "denom": "tf/[contract-addr]/[subdenom]" },
"mint_to": "[mint-to-addr]"
}
}
```

- **Burn** burns tokens

```js
{
"burn": {
"coin": { "amount": "[amount]", "denom": "tf/[contract-addr]/[subdenom]" },
"burn_from": "[burn-from-addr]"
}
{
"burn": {
"coin": { "amount": "[amount]", "denom": "tf/[contract-addr]/[subdenom]" },
"burn_from": "[burn-from-addr]"
}
}
```

- **ChangeAdmin** changes the admin of a denom

```js
{
"change_admin": {
"denom": "tf/[contract-addr]/[subdenom]",
"new_admin": "[ADDR]"
}
{
"change_admin": {
"denom": "tf/[contract-addr]/[subdenom]",
"new_admin": "[ADDR]"
}
}
```

Expand Down Expand Up @@ -419,4 +432,187 @@ The owner is the only one who can execute messages in the contract
"redeem_amount": "1000000"
}
}
```
```

## 7. Airdrop token vesting

This contract implements vesting accounts for the native tokens.

### 7.1 Instantiate

We need to specify admin and managers

```javascript
{
"admin": "cosmos1...",
"managers": ["cosmos1...", "cosmos1..."]
}
```

### 7.2 Execute

- **RewardUsers** registers several vesting contracts

```javascript
{
"reward_users": {
"rewards": [
{
"user_address": "cosmos1...",
"vesting_amount": "1000000",
"cliff_amount": "100000", // Only needed if vesting schedule is linear with cliff
}
],
"vesting_schedule": {
"linear_vesting": {
"start_time": "1703772805",
"end_time": "1703872805",
"vesting_amount": "0" // This amount does not matter
}
}
}
}
```

- **DeregisterVestingAccount** deregisters a vesting account

```javascript
{
"deregister_vesting_account": {
"address": "cosmos1...",
"vested_token_recipient": "cosmos1...", // address that will receive the vested tokens after deregistration. If None, tokens are received by the owner address.
"left_vested_token_recipient": "cosmos1...", // address that will receive the left vesting tokens after deregistration.
}
}
```

- **Claim** allows to claim vested tokens

```javascript
{
"claim": {
"recipient": "cosmos1...",
}
}
```

### 7.3 Query

- **VestingAccount** returns the vesting account details for a given address.

```javascript
{
"vesting_account": {
"address": "cosmos1...",
}
}
```

## 8. Auto compounder

Unique-Divine marked this conversation as resolved.
Show resolved Hide resolved
This contract implements vesting accounts for the native tokens.

### 8.1 Instantiate

We need to specify admin and managers

```javascript
{
"admin": "cosmos1...",
"managers": ["cosmos1...", "cosmos1..."]
}
```

### 8.2 Execute

#### Admin functions

- **SetAutoCompounderMode** sets the auto compounder mode

```javascript
{
"set_auto_compounder_mode": {
"mode": "true" // true or false
}
}
```

- **Withdraw** allows to withdraw the funds from the contract

```javascript
{
"withdraw": {
"amount": "1000000"
Comment on lines +540 to +546
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JSON snippet for the Withdraw function is missing a comma at the end of line 545. This syntax error could lead to confusion or errors if someone tries to use this snippet as is. It should be corrected to ensure syntactical accuracy.

     "withdraw": {
       "amount": "1000000",
       "recipient": "cosmos1..."

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
- **Withdraw** allows to withdraw the funds from the contract
```javascript
{
"withdraw": {
"amount": "1000000"
"recipient": "cosmos1..."
- **Withdraw** allows to withdraw the funds from the contract
```javascript
{
"withdraw": {
"amount": "1000000",
"recipient": "cosmos1..."

"recipient": "cosmos1..."
}
}
Comment on lines +540 to +549
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a missing comma at the end of line 546 in the JSON snippet for the Withdraw function. This syntax error could lead to confusion or errors if someone tries to use this snippet as is. It should be corrected to ensure syntactical accuracy.

  {
    "withdraw": {
      "amount": "1000000",
+     "recipient": "cosmos1..."
    }
  }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
- **Withdraw** allows to withdraw the funds from the contract
```javascript
{
"withdraw": {
"amount": "1000000"
"recipient": "cosmos1..."
}
}
```
- **Withdraw** allows to withdraw the funds from the contract
```javascript
{
"withdraw": {
"amount": "1000000",
"recipient": "cosmos1..."
}
}

</details>
<!-- suggestion_end -->

<!-- This is an auto-generated comment by CodeRabbit -->

```

- **unstakes** allows to unstake the funds from the contract

```javascript
{
"unstake": {
"unstake_msgs": [
{
"validator": "cosmosvaloper1...",
"amount": "1000000"
},
{
"validator": "cosmosvaloper1...",
"amount": "1000000"
}
]
}
}
```

- **update managers** allows to update the managers of the contract

```javascript
{
"update_managers": {
"managers": ["cosmos1...", "cosmos1..."]
}
}
```

#### Manager functions

- **stake** allows to stake the funds from the contract. The shares are normalized

```javascript
{
"stake": {
"stake_msgs": [
{
"validator": "cosmosvaloper1...",
"share": "1000000"
},
{
"validator": "cosmosvaloper1...",
"share": "1000000"
}
]
},
Comment on lines +582 to +598
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The stake function documentation mentions that "The shares are normalized," but it lacks clarity on what "normalized" means in this context. Adding a brief explanation would help users understand how the function operates and what to expect when using it.

"amount": "1000000"
}
```

### 8.3 Query

- **auto compounder mode** returns wether the auto compounder mode is enabled or not

```javascript
{
"auto_compounder_mode": {}
}
```

- **AdminAndManagers** returns the admin and managers of the contract

```javascript
{
"admin_and_managers": {}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation for the "Auto compounder" contract is well-structured and aligns with the PR objectives of enhancing security and efficiency in staking re-delegation processes. However, there are a few areas that could be improved for clarity and consistency:

  1. Instantiate Section (Lines 665-671): The description "This contract implements vesting accounts for the native tokens." seems to be a copy-paste error from the previous section. It would be more appropriate to describe the specific purpose of the auto compounder contract here, focusing on its role in managing staking re-delegation securely.

  2. Execute Section - Withdraw Function (Lines 688-697): There's a missing comma at the end of line 693. This could lead to confusion or errors if someone tries to use this JSON snippet as is. It should be corrected to ensure syntactical accuracy.

  3. General Consistency: Ensure that the documentation style, such as the use of backticks for code snippets and the indentation of JSON objects, is consistent throughout this section and matches the style used in the rest of the Cookbook.md file. This includes consistent use of comments within the JSON snippets to explain parameters or expected values.

  4. Clarity on Manager Functions (Lines 728-747): It would be beneficial to add a brief explanation about what it means for shares to be "normalized" in the context of staking. This could help users understand how the stake function operates and what they should expect when using it.

Improving these areas will enhance the readability and usability of the documentation for developers and users interacting with the auto compounder contract.

```
1 change: 1 addition & 0 deletions artifacts/checksums.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
382c05baf544f2886de849933ecf59e8bc3bcdcdd552d5a63537bd6d63f2ecf1 controller.wasm
05948cad982935aa30a9c2011649ab40a38172ab50df5781a3e24f72b76dcc56 core_compounder.wasm
6cf70cdf7ca010cbeff5fff2ca992ccb6d48fa669baf2b9ee26c8289a926413c core_token_vesting_v2.wasm
b56a880d4c67d9f353f549b502256f73159f89b50aa6dae683948e117efa4792 cw3_flex_multisig.wasm
1ecff403bbf3b5fcedccb5de76a0ef5f1fdbcc5f60890e3388f5425584899f0b incentives.wasm
Expand Down
Binary file added artifacts/core_compounder.wasm
Unique-Divine marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
4 changes: 3 additions & 1 deletion contracts/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Contracts <!-- omit in toc -->
# Contracts <!-- omit in toc -->

- [Core Contracts](#core-contracts)
- [Example Contracts](#example-contracts)
Expand All @@ -14,6 +14,8 @@
to run a bot.
- [**core-controller**](./core-controller): Admin calls for things like creating
perp markets or changing oracle parameters.
- [**core-compounder**](./core-compounder): Simple contract to allow third parties
to stake funds without being able to withdraw/unstake them.

## Example Contracts

Expand Down
Loading
Loading