Skip to content

Commit

Permalink
ABC Improvements (DA0-DA0#818)
Browse files Browse the repository at this point in the history
* Make hatcher_allowlist a map

Also cleans up state when going from Hatch -> Open
Various spell-checking fixes

* Allow existing tokens to be used with ABC's

I think it's important for an existing token to be supported by an ABC.
Token DAO's will be able to set up liquidity more easily by simply allowing mint & burn functionality after instantiating the ABC while holding ownership of it.

*Also adds a query for hatcher allowlist
*fixes spell checks I ran into
*moves TokenInfo from dao-voting-token-staked to dao-interface for use in cw-abc

* Complete funding pool logic

Renamed fees_recipient to funding_pool_forwarding for better naming
Made funding_pool_forwarding optional
Allow updating the funding_pool_forwarding by owner
Allow withdrawing from the funding pool by owner

* Implement a circuit breaker

Adds IS_PAUSED state that is checked in execute entry
Also fixes naming in commands

* Add query for initial supply at ABC creation

* Allow donation into the reserve pool

Also fixes donation state being lost after multiple donations

* Move cw-abc curves to its own package cw-curves

* Improve validation for max_supply

* Support DAO membership in hatcher allowlist

Could use a test here
Also fixes some warnings and flag for cw-std

* Clippy fix

* Only clone decimals from curve_state

also reorg buy command to be closer to sell command for readability

* QoL improvements

Derive copy on DecimalPlaces
Catch OverflowError directly in ContractError
Do not set initial supply as supply - will further remove allowing initial supplies

* Revert support for initial supply

* Fix clippy unnecessary clones

* Donate only into the funding pool

* Add a test for donate and withdraw from funding pool

* Add test for dao hatchers + update schemas

Also removes unused deps from cw-abc which now live in cw-curves

* Update Cargo.toml

* Buy & Sell Quotes

Let users know the curve state and returned amount after x payment

* Complete DAO hatchers w/ priority queue

Disallow selling in the hatch phase
Do not validate max_contribution against max_raise

* Fix priority queue ordering on ties

also clippy fixes

* Couple more clippy fixes
  • Loading branch information
ismellike authored May 14, 2024
1 parent 6d4b430 commit f656e8a
Show file tree
Hide file tree
Showing 50 changed files with 2,643 additions and 894 deletions.
20 changes: 16 additions & 4 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 @@ -88,6 +88,7 @@ cw-ownable = "0.5"

cw-abc = { path = "./contracts/external/cw-abc", version = "*" }
cw-admin-factory = { path = "./contracts/external/cw-admin-factory", version = "2.4.1" }
cw-curves = { path = "./packages/cw-curves", version = "2.4.1" }
cw-denom = { path = "./packages/cw-denom", version = "2.4.1" }
cw-hooks = { path = "./packages/cw-hooks", version = "2.4.1" }
cw-paginate-storage = { path = "./packages/cw-paginate-storage", version = "2.4.1" }
Expand Down
3 changes: 2 additions & 1 deletion ci/bootstrap-env/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ fn main() -> Result<()> {
);

// Persist contract code_ids in local.yaml so we can use SKIP_CONTRACT_STORE locally to avoid having to re-store them again
cfg.contract_deploy_info = orc.contract_map.deploy_info().clone();
cfg.contract_deploy_info
.clone_from(orc.contract_map.deploy_info());
fs::write(
"ci/configs/cosm-orc/local.yaml",
serde_yaml::to_string(&cfg)?,
Expand Down
3 changes: 2 additions & 1 deletion ci/integration-tests/src/helpers/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ fn global_setup() -> Cfg {
.unwrap();
save_gas_report(&orc, &gas_report_dir);
// persist stored code_ids in CONFIG, so we can reuse for all tests
cfg.contract_deploy_info = orc.contract_map.deploy_info().clone();
cfg.contract_deploy_info
.clone_from(orc.contract_map.deploy_info());
}

Cfg {
Expand Down
2 changes: 1 addition & 1 deletion contracts/dao-dao-core/schema/dao-dao-core.json
Original file line number Diff line number Diff line change
Expand Up @@ -1723,7 +1723,7 @@
"additionalProperties": false
},
{
"description": "Lists all of the items associted with the contract. For example, given the items `{ \"group\": \"foo\", \"subdao\": \"bar\"}` this query would return `[(\"group\", \"foo\"), (\"subdao\", \"bar\")]`.",
"description": "Lists all of the items associated with the contract. For example, given the items `{ \"group\": \"foo\", \"subdao\": \"bar\"}` this query would return `[(\"group\", \"foo\"), (\"subdao\", \"bar\")]`.",
"type": "object",
"required": [
"list_items"
Expand Down
11 changes: 7 additions & 4 deletions contracts/external/cw-abc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ authors = [
"Ethan Frey <ethanfrey@users.noreply.github.com>",
"Jake Hartnell",
"Adair <adairrr@users.noreply.github.com>",
"Gabe Lopez <ismellike@users.noreply.github.com>",
]
description = "Implements an Augmented Bonding Curve"
# Inherits license from previous work
license = "Apache-2.0"
edition = { workspace = true }
repository = { workspace = true }
version = "0.0.1"
version = { workspace = true }

[lib]
crate-type = ["cdylib", "rlib"]
Expand All @@ -36,11 +37,9 @@ cw-ownable = { workspace = true }
cw-paginate-storage = { workspace = true }
cw-tokenfactory-issuer = { workspace = true, features = ["library"] }
dao-interface = { workspace = true }
rust_decimal = { workspace = true }
integer-sqrt = { workspace = true }
integer-cbrt = { workspace = true }
getrandom = { workspace = true, features = ["js"] }
thiserror = { workspace = true }
cw-curves = { workspace = true }

[dev-dependencies]
speculoos = { workspace = true }
Expand All @@ -51,3 +50,7 @@ osmosis-std = { workspace = true }
osmosis-test-tube = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
cw-tokenfactory-issuer = { workspace = true }
dao-voting-token-staked = { workspace = true }
dao-proposal-single = { workspace = true }
dao-voting = { workspace = true }
42 changes: 29 additions & 13 deletions contracts/external/cw-abc/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# cw-abc

Implments an [Augmented Bonding Curve](https://medium.com/commonsstack/deep-dive-augmented-bonding-curves-b5ca4fad4436).
Implements an [Augmented Bonding Curve](https://medium.com/commonsstack/deep-dive-augmented-bonding-curves-b5ca4fad4436).

Forked from and heavily inspired by the work on [cw20-bonding](https://github.com/cosmwasm/cw-tokens/tree/main/contracts/cw20-bonding). This contract uses native and token factory tokens instead.

Expand All @@ -18,8 +18,8 @@ Each bonding curve has a pricing function, also known as the price curve (or `cu
With bonding curves, we will always know what the price of an asset will be based on supply! More on benefits later.

This contract implements two methods:
- `Buy {}` is called with sending along some reserve curency (such as $USDC, or whatever the bonding curve is backed by). The reserve currency is stored by the bonding curve contract, and new tokens are minted and sent to the user.
- `Sell {}` is called along with sending some supply currency (the token minted by the bonding curve). The supply tokens are burned, and reserve curency is returned.
- `Buy {}` is called with sending along some reserve currency (such as $USDC, or whatever the bonding curve is backed by). The reserve currency is stored by the bonding curve contract, and new tokens are minted and sent to the user.
- `Sell {}` is called along with sending some supply currency (the token minted by the bonding curve). The supply tokens are burned, and reserve currency is returned.

It is possible to use this contact as a basic bonding curve, without any of the augmented features.

Expand Down Expand Up @@ -64,7 +64,7 @@ Augmented Bonding Curves are nothing new, some articles that inspired this imple
- https://medium.com/commonsstack/deep-dive-augmented-bonding-curves-b5ca4fad4436
- https://tokeneconomy.co/token-bonding-curves-in-practice-3eb904720cb8

At a high level, augmented bonding curves extend bonding curves with new funcationality:
At a high level, augmented bonding curves extend bonding curves with new functionality:
- Entry and exit fees
- Different phases representing the life cycles of projects

Expand All @@ -74,7 +74,7 @@ Example Instantiation message:

``` json
{
"fees_recipient": "address that recieves fees",
"fees_recipient": "address that receives fees",
"token_issuer_code_id": 0,
"supply": {
"subdenom": "utokenname",
Expand All @@ -87,17 +87,17 @@ Example Instantiation message:
"decimals": 6,
"max_supply": "100000000000000"
},
reserve: {
"reserve": {
"denom": "ujuno",
"decimals": 6,
},
curve_type: {
"curve_type": {
"linear": {
"slope": "2",
"scale": 1
}
},
phase_config: {
"phase_config": {
"hatch": {
"contribution_limits": {
"min": "10000000",
Expand All @@ -107,22 +107,38 @@ Example Instantiation message:
"min": "10000000",
"max": "100000000000"
},
"entry_fee": "0.25",
"exit_fee": "0.10"
"entry_fee": "0.25"
},
"open": {
"exit_fee": "0.01",
"entry_fee": "0.01"
},
"closed": {}
},
hatcher_allowlist: ["allowlist addresses, leave blank for no allowlist"],
"hatcher_allowlist": [
{
"addr": "dao_address",
"config": {
"config_type": { "dao": { "priority": 1 } },
"contribution_limits_override": {
"min": "100000000",
"max": "99999999999999"
}
}
},
{
"addr": "address",
"config": {
"config_type": { "address": {} }
}
}
],
}
```

- `fees_recipient`: the address that will recieve fees (usually a DAO).
- `fees_recipient`: the address that will receive fees (usually a DAO).
- `token_issuer_code_id`: the CosmWasm code ID for a `cw-tokenfactory_issuer` contract.
- `supply`: infor about the token that will be minted by the curve. This is the token that is created by the bonding curve.
- `supply`: info about the token that will be minted by the curve. This is the token that is created by the bonding curve.
- `reserve`: this is the token that is used to mint the supply token.
- `curve_type`: information about the pricing curve.
- `phase_config`: configuration for the different phase of the augmented bonding curve.
Expand Down
Loading

0 comments on commit f656e8a

Please sign in to comment.