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

twap at height NTRN-357 #7

Merged
merged 13 commits into from
Mar 9, 2023
737 changes: 731 additions & 6 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["contracts/*"]
members = ["contracts/auction", "contracts/lockdrop", "contracts/credits","contracts/astroport/*"]

[profile.release]
rpath = false
Expand Down
4 changes: 4 additions & 0 deletions contracts/astroport/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Astroport

This is [Astroport Core contracts](https://github.com/astroport-fi/astroport-core/tree/bedca9e7736d76f7a57a25fa4d1d850696cd03c5) modified for Neutron purposes.
Original repo commit hash: bedca9e7736d76f7a57a25fa4d1d850696cd03c5
6 changes: 6 additions & 0 deletions contracts/astroport/factory/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[alias]
wasm = "build --release --target wasm32-unknown-unknown"
wasm-debug = "build --target wasm32-unknown-unknown"
unit-test = "test --lib"
integration-test = "test --test integration"
schema = "run --example factory_schema"
11 changes: 11 additions & 0 deletions contracts/astroport/factory/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.rs]
indent_size = 4
40 changes: 40 additions & 0 deletions contracts/astroport/factory/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[package]
name = "astroport-factory"
version = "1.3.0"
authors = ["Astroport"]
edition = "2021"
description = "Astroport factory contract - pair contract generator and directory"
license = "MIT"

exclude = [
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication.
"contract.wasm",
"hash.txt",
]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["cdylib", "rlib"]

[features]
# for quicker tests, cargo test --lib
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]

[dependencies]
cosmwasm-std = "1.1"
astroport = { path = "../../../packages/astroport", default-features = false }
cw-storage-plus = "0.15"
cw2 = "0.15"
thiserror = { version = "1.0" }
protobuf = { version = "2", features = ["with-bytes"] }
itertools = "0.10"
cosmwasm-schema = "1.1"

[dev-dependencies]
cw-multi-test = "0.15"
astroport-token = {path = "../token" }
astroport-pair = {path = "../pair" }
cw20 = { version = "0.15" }
anyhow = "1.0"
268 changes: 268 additions & 0 deletions contracts/astroport/factory/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,268 @@
# Astroport Factory

The factory contract can create new Astroport pair contracts (and associated LP token contracts) and it is used as a directory for all pairs. The default pair types are constant product and stableswap but governance may decide to add custom pools that can have any implementation.

---

## InstantiateMsg

The instantiation message takes in the token code ID for the token type supported on Astroport. It also takes in the `fee_address` that collects fees for governance, the contract `owner`, the Generator contract address and the initial pair types available to create.

```json
{
"token_code_id": 123,
"fee_address": "terra...",
"owner": "terra...",
"generator_address": "terra...",
"pair_configs": [{
"code_id": 123,
"pair_type": {
"xyk": {}
},
"total_fee_bps": 100,
"maker_fee_bps": 10,
"is_disabled": false
}
]
}
```

## ExecuteMsg

### `update_config`

Updates contract variables, namely the code ID of the token implementation used in Astroport, the address that receives governance fees and the Generator contract address.

```json
{
"update_config": {
"token_code_id": 123,
"fee_address": "terra...",
"generator_address": "terra..."
}
}
```

### `update_pair_config`

This function can be used to:

- Update the code ID used to instantiate new pairs of a specific type
- Change the fee structure for a pair
- Disable the pair type so no other pairs can be instantiated

Note that all fields are optional.

The fee structure for a pair is set up as follows:

- `total_fee_bps` is the total amount of fees (in bps) that are charged on each swap
- `maker_fee_bps` is the percentage of fees out of `total_fee_bps` that is sent to governance. 100% is 10,000

As an example, let's say a pool charged 30bps (`total_fee_bps` is 30) and we want 1/3r of the fees to go to governance. In this case, `maker_fee_bps` should be 3333 because 3333 / 10,000 * 30 / 100 = 0.1%

```json
{
"update_pair_config": {
"config": {
"code_id": 123,
"pair_type": {
"xyk": {}
},
"total_fee_bps": 100,
"maker_fee_bps": 10,
"is_disabled": false
}
}
}
```

### `create_pair`

Anyone can execute this function to create an Astroport pair. `CreatePair` creates both a `Pair` contract and a `LP(liquidity provider)` token contract. The account that instantiates the pair must specify the pair type they want as well as the assets for which the pool is created.

Custom pool types may also need extra parameters which can be packed in `init_params`.

```json
{
"create_pair": {
"pair_type": {
"xyk": {}
},
"asset_infos": [
{
"token": {
"contract_addr": "terra..."
}
},
{
"native_token": {
"denom": "uusd"
}
}
],
"init_params": "<base64_encoded_json_string: Optional binary serialised parameters for custom pool types>"
}
}
```

### `deregister`

Deregisters an already registered pair. This allows someone else to create a new pair (of any type) for the tokens that don't have a registered pair anymore. This is how pairs can be "upgraded".

```json
{
"deregister": {
"asset_infos": [
{
"token": {
"contract_address": "terra..."
}
},
{
"native_token": {
"denom": "uusd"
}
}
]
}
}
```

### `propose_new_owner`

Creates an offer to change the contract ownership. The validity period of the offer is set in the `expires_in` variable. After `expires_in` seconds pass, the proposal expires and cannot be accepted anymore.

```json
{
"propose_new_owner": {
"owner": "terra...",
"expires_in": 1234567
}
}
```

### `drop_ownership_proposal`

Removes an existing offer to change the contract owner.

```json
{
"drop_ownership_proposal": {}
}
```

### `claim_ownership`

Used to claim contract ownership.

```json
{
"claim_ownership": {}
}
```


### `mark_as_migrated`

Mark pairs as migrated.

```json
{
"mark_as_migrated": {
"pairs": ["terra...", "terra..."]
}
}
```

## QueryMsg

All query messages are described below. A custom struct is defined for each query response.

### `config`

Returns general factory parameters (owner, token code ID, pair type configurations).

```json
{
"config": {}
}
```

### `pair`

Returns information about a specific pair.

```json
{
"pair": {
"asset_infos": [
{
"token": {
"contract_address": "terra..."
}
},
{
"native_token": {
"denom": "uusd"
}
}
]
}
}
```

### `pairs`

Returns information about multiple pairs (the result is paginated). The function starts returning pair information starting after the pair `start_after`. The function returns maximum `limit` pairs.

```json
{
"pairs": {
"start_after": [
{
"token": {
"contract_address": "terra..."
}
},
{
"native_token": {
"denom": "uusd"
}
}
],
"limit": 10
}
}
```

### `fee_info`

Returns the fee information for a specific pair type (`total_fee_bps` and `maker_fee_bps`).

```json
{
"pair_type": {
"xyk": {}
}
}
```

### `blacklisted_pair_types`

Returns a vector that contains blacklisted pair types.

```json
{
"blacklisted_pair_types": {}
}
```

### `pairs_to_migrate`

Returns a vector that contains pair addresses that are not migrated.

```json
{
"pairs_to_migrate": {}
}
```
24 changes: 24 additions & 0 deletions contracts/astroport/factory/examples/factory_schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::env::current_dir;
use std::fs::create_dir_all;

use cosmwasm_schema::{export_schema_with_title, remove_schemas, schema_for};

use astroport::asset::PairInfo;
use astroport::factory::{
ConfigResponse, ExecuteMsg, InstantiateMsg, MigrateMsg, PairsResponse, QueryMsg,
};

fn main() {
let mut out_dir = current_dir().unwrap();
out_dir.push("schema");
create_dir_all(&out_dir).unwrap();
remove_schemas(&out_dir).unwrap();

export_schema_with_title(&schema_for!(InstantiateMsg), &out_dir, "InstantiateMsg");
export_schema_with_title(&schema_for!(ExecuteMsg), &out_dir, "ExecuteMsg");
export_schema_with_title(&schema_for!(QueryMsg), &out_dir, "QueryMsg");
export_schema_with_title(&schema_for!(PairInfo), &out_dir, "PairInfo");
export_schema_with_title(&schema_for!(PairsResponse), &out_dir, "PairsResponse");
export_schema_with_title(&schema_for!(ConfigResponse), &out_dir, "ConfigResponse");
export_schema_with_title(&schema_for!(MigrateMsg), &out_dir, "MigrateMsg");
}
Loading