Skip to content

Commit

Permalink
Allow existing tokens to be used with ABC's
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ismellike committed Apr 7, 2024
1 parent e8874ca commit 11eaf88
Show file tree
Hide file tree
Showing 25 changed files with 706 additions and 159 deletions.
1 change: 1 addition & 0 deletions contracts/external/cw-abc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ osmosis-std = { workspace = true }
osmosis-test-tube = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
cw-tokenfactory-issuer = { workspace = true }
8 changes: 4 additions & 4 deletions contracts/external/cw-abc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -116,7 +116,7 @@ Example Instantiation message:
},
"closed": {}
},
hatcher_allowlist: ["allowlist addresses, leave blank for no allowlist"],
"hatcher_allowlist": ["allowlist addresses, leave blank for no allowlist"],
}
```

Expand Down
227 changes: 202 additions & 25 deletions contracts/external/cw-abc/schema/cw-abc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"fees_recipient",
"phase_config",
"reserve",
"supply",
"token_issuer_code_id"
"supply"
],
"properties": {
"curve_type": {
Expand Down Expand Up @@ -60,16 +59,14 @@
"$ref": "#/definitions/SupplyToken"
}
]
},
"token_issuer_code_id": {
"description": "The code id of the cw-tokenfactory-issuer contract",
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
},
"additionalProperties": false,
"definitions": {
"Binary": {
"description": "Binary is a wrapper around Vec<u8> to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec<u8>. See also <https://github.com/CosmWasm/cosmwasm/blob/main/docs/MESSAGE_TYPES.md>.",
"type": "string"
},
"ClosedConfig": {
"type": "object",
"additionalProperties": false
Expand Down Expand Up @@ -273,8 +270,24 @@
},
"additionalProperties": false
},
"InitialBalance": {
"type": "object",
"required": [
"address",
"amount"
],
"properties": {
"address": {
"type": "string"
},
"amount": {
"$ref": "#/definitions/Uint128"
}
},
"additionalProperties": false
},
"MinMax": {
"description": "Struct for minimium and maximum values",
"description": "Struct for minimum and maximum values",
"type": "object",
"required": [
"max",
Expand Down Expand Up @@ -328,6 +341,56 @@
},
"additionalProperties": false
},
"NewTokenInfo": {
"type": "object",
"required": [
"initial_balances",
"subdenom",
"token_issuer_code_id"
],
"properties": {
"initial_balances": {
"description": "The initial balances to set for the token, cannot be empty.",
"type": "array",
"items": {
"$ref": "#/definitions/InitialBalance"
}
},
"initial_dao_balance": {
"description": "Optional balance to mint for the DAO.",
"anyOf": [
{
"$ref": "#/definitions/Uint128"
},
{
"type": "null"
}
]
},
"metadata": {
"description": "Optional metadata for the token, this can additionally be set later.",
"anyOf": [
{
"$ref": "#/definitions/NewDenomMetadata"
},
{
"type": "null"
}
]
},
"subdenom": {
"description": "The subdenom of the token to create, will also be used as an alias for the denom. The Token Factory denom will have the format of factory/{contract_address}/{subdenom}",
"type": "string"
},
"token_issuer_code_id": {
"description": "The code id of the cw-tokenfactory-issuer contract",
"type": "integer",
"format": "uint64",
"minimum": 0.0
}
},
"additionalProperties": false
},
"OpenConfig": {
"type": "object",
"required": [
Expand Down Expand Up @@ -378,7 +441,7 @@
"type": "object",
"required": [
"decimals",
"subdenom"
"token_info"
],
"properties": {
"decimals": {
Expand All @@ -397,24 +460,70 @@
}
]
},
"metadata": {
"description": "Metadata for the supply token to create",
"anyOf": [
{
"$ref": "#/definitions/NewDenomMetadata"
},
"token_info": {
"description": "New or existing native token NOTE: If using an existing token, then the ABC must be given mint and burn permissions after creation",
"allOf": [
{
"type": "null"
"$ref": "#/definitions/TokenInfo"
}
]
},
"subdenom": {
"description": "The denom to create for the supply token",
"type": "string"
}
},
"additionalProperties": false
},
"TokenInfo": {
"oneOf": [
{
"description": "Uses an existing Token Factory token and creates a new issuer contract. Full setup, such as transferring ownership or setting up MsgSetBeforeSendHook, must be done manually.",
"type": "object",
"required": [
"existing"
],
"properties": {
"existing": {
"type": "object",
"required": [
"denom"
],
"properties": {
"denom": {
"description": "Token factory denom",
"type": "string"
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"description": "Creates a new Token Factory token via the issue contract with the DAO automatically setup as admin and owner.",
"type": "object",
"required": [
"new"
],
"properties": {
"new": {
"$ref": "#/definitions/NewTokenInfo"
}
},
"additionalProperties": false
},
{
"description": "Uses a factory contract that must return the denom, optionally a Token Contract address. The binary must serialize to a `WasmMsg::Execute` message. Validation happens in the factory contract itself, so be sure to use a trusted factory contract.",
"type": "object",
"required": [
"factory"
],
"properties": {
"factory": {
"$ref": "#/definitions/Binary"
}
},
"additionalProperties": false
}
]
},
"Uint128": {
"description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```",
"type": "string"
Expand Down Expand Up @@ -783,7 +892,7 @@
]
},
"MinMax": {
"description": "Struct for minimium and maximum values",
"description": "Struct for minimum and maximum values",
"type": "object",
"required": [
"max",
Expand Down Expand Up @@ -1005,7 +1114,7 @@
"additionalProperties": false
},
{
"description": "Returns the Fee Recipient for the contract. This is the address that recieves any fees collected from bonding curve operation",
"description": "Returns the Fee Recipient for the contract. This is the address that receives any fees collected from bonding curve operation",
"type": "object",
"required": [
"fees_recipient"
Expand Down Expand Up @@ -1049,7 +1158,37 @@
"additionalProperties": false
},
{
"description": "Returns the Maxiumum Supply of the supply token",
"description": "Lists the hatcher allowlist Returns [`HatcherAllowlistResponse`]",
"type": "object",
"required": [
"hatcher_allowlist"
],
"properties": {
"hatcher_allowlist": {
"type": "object",
"properties": {
"limit": {
"type": [
"integer",
"null"
],
"format": "uint32",
"minimum": 0.0
},
"start_after": {
"type": [
"string",
"null"
]
}
},
"additionalProperties": false
}
},
"additionalProperties": false
},
{
"description": "Returns the Maximum Supply of the supply token",
"type": "object",
"required": [
"max_supply"
Expand Down Expand Up @@ -1338,6 +1477,44 @@
"description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.",
"type": "string"
},
"hatcher_allowlist": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "HatcherAllowlistResponse",
"type": "object",
"properties": {
"allowlist": {
"description": "Hatcher allowlist",
"type": [
"array",
"null"
],
"items": {
"type": "array",
"items": [
{
"$ref": "#/definitions/Addr"
},
{
"$ref": "#/definitions/Empty"
}
],
"maxItems": 2,
"minItems": 2
}
}
},
"additionalProperties": false,
"definitions": {
"Addr": {
"description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.",
"type": "string"
},
"Empty": {
"description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)",
"type": "object"
}
}
},
"hatchers": {
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "HatchersResponse",
Expand Down Expand Up @@ -1611,7 +1788,7 @@
"additionalProperties": false
},
"MinMax": {
"description": "Struct for minimium and maximum values",
"description": "Struct for minimum and maximum values",
"type": "object",
"required": [
"max",
Expand Down
11 changes: 5 additions & 6 deletions contracts/external/cw-abc/src/abc.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{ensure, Decimal as StdDecimal, Uint128};
use dao_interface::token::NewDenomMetadata;
use dao_interface::token::TokenInfo;

use crate::curves::{decimal, Constant, Curve, DecimalPlaces, Linear, SquareRoot};
use crate::ContractError;

#[cw_serde]
pub struct SupplyToken {
/// The denom to create for the supply token
pub subdenom: String,
/// Metadata for the supply token to create
pub metadata: Option<NewDenomMetadata>,
/// New or existing native token
/// NOTE: If using an existing token, then the ABC must be given mint and burn permissions after creation
pub token_info: TokenInfo,
/// Number of decimal places for the supply token, needed for proper curve math.
/// Default for token factory is 6
pub decimals: u8,
Expand All @@ -27,7 +26,7 @@ pub struct ReserveToken {
pub decimals: u8,
}

/// Struct for minimium and maximum values
/// Struct for minimum and maximum values
#[cw_serde]
pub struct MinMax {
pub min: Uint128,
Expand Down
Loading

0 comments on commit 11eaf88

Please sign in to comment.