Skip to content

Commit

Permalink
Merge pull request #67 from terra-money/feature/latest_updates
Browse files Browse the repository at this point in the history
Feature/latest updates
  • Loading branch information
simke9445 authored Mar 13, 2024
2 parents c953c34 + 2ee6d3c commit 868c3f2
Show file tree
Hide file tree
Showing 82 changed files with 5,224 additions and 1,932 deletions.
80 changes: 42 additions & 38 deletions Cargo.lock

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

Binary file not shown.
119 changes: 119 additions & 0 deletions V2CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# V2 Changelog

## Major Updates

- **User’s Warp-Account Removed:**
- Replaced by job accounts.
- `create_job` now creates a job account on the fly in the same transaction.
- Users can provide funds in `info.funds` that are relayed to the job account.
- Job account is used as a job session throughout job execution.
- In case of recurring jobs, the same job account is kept through time.
- Required for stateful jobs like trading strategies.

- **Multiple Funding Accounts:**
- Users can create and manage multiple funding accounts.
- Funding account is used for distributing rewards to keepers and paying fees.
- Otherwise, fees are subtracted from `info.funds`.
- Useful for recurring jobs to provide fees and topups on the side.

- **New Fee Mechanism:**
- Introduces a more dynamic and flexible fee calculation system.
- Creation Fee: Calculated based on the queue size.
- Maintenance Fee: Determined based on the duration in days.
- Burn Fee: Computed from the job reward.
- `total_fees = creation_fee + maintenance_fee + burn_fee`
- `job cost = total_fees + reward`

- **New Contract Warp-Account-Tracker:**
- Used for management of job accounts and funding accounts.
- Holds state for taken and free accounts by job_id.

## API Changes

### Removed
- `create_job.msgs`
- `create_job.condition`
- `create_job.requeue_on_evict`

### Added
- `create_job.executions`
- Array of executions that operate like a switch.
- Single execution contains msgs (warp msgs) and condition.
- On job execution, the first execution condition that returns true top-down is taken.
- **Job Accounts with WarpMsg Struct:**
- Job accounts now operate with WarpMsg struct.
- Previously, warp accounts worked only with cosmos msgs.
- WarpMsg:Generic is equivalent to a cosmos msg.
- Added support for WarpMsg:WithdrawAssets and WarpMsg:IbcTransfer.
- Extensible messaging standard within warp in case custom message formats are needed in the future.
- `create_job.operational_amount`
- Without funding account: `operational_amount` needs to equal `total_fees + reward`.
- With funding account: Ignored, can be set to 0.
- `create_job.duration_days`
- Defines job length of stay in the warp queue.
- Maintenance fee paid upfront for it based on fee calculations.
- `create_job.cw_funds`
- Optionally passed list of cw20 and cw721 funds to be sent from user to job account.
- `create_job.funding_account`
- Optionally attached funding account from which job fees and rewards are deducted.
- Required for recurring jobs.
- Optionally provided for one-time jobs.
- `create_job.account_msgs`
- Messages that are executed via job-account on job creation.
- Useful for deploying funds to money markets to earn APR while the job waits for execution.
- **Controller.create_funding_account API:**
- Creates a new free funding account for the user.
- **FnValue StringValue Support:**
- Static variable can be initialized with an `init_fn`.
- FnValue now supports `StringValue`.

## Fee functions

### Creation Fee

The creation fee (`f(qs)`) is a piecewise function depending on the queue size (`qs`).

```
f(qs) =
y1, if qs < x1
slope * qs + y1 - slope * x1, if x1 <= qs < x2
y2, if qs >= x2
```

Where:
- `x1` = `config.queue_size_left`
- `x2` = `config.queue_size_right`
- `y1` = `config.creation_fee_min`
- `y2` = `config.creation_fee_max`
- `slope` = `(y2 - y1) / (x2 - x1)`

### Maintenance Fee

The maintenance fee (`g(dd)`) is structured similarly, based on the duration in days (`dd`).

```
g(dd) =
y1, if dd < x1
slope * dd + y1 - slope * x1, if x1 <= dd < x2
y2, if dd >= x2
```

Where:
- `x1` = `config.duration_days_min`
- `x2` = `config.duration_days_max`
- `slope` = `(y2 - y1) / (x2 - x1)`

### Burn Fee

The burn fee (`h(job_reward)`) is calculated as the maximum between the `calculated_fee` and `min_fee`.

```
h(job_reward) =
max(calculated_fee, min_fee)
```

Where:
- `calculated_fee` = `job_reward * config.burn_fee_rate / 100`
- `min_fee` = `config.burn_fee_min`


4 changes: 4 additions & 0 deletions contracts/warp-account-tracker/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[alias]
wasm = "build --release --target wasm32-unknown-unknown"
unit-test = "test --lib"
schema = "run --example warp-account-tracker-schema"
16 changes: 16 additions & 0 deletions contracts/warp-account-tracker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Build results
/target
/schema

# Cargo+Git helper file (https://github.com/rust-lang/cargo/blob/0.44.1/src/cargo/sources/git/utils.rs#L320-L327)
.cargo-ok

# Text file backups
**/*.rs.bk

# macOS
.DS_Store

# IDEs
*.iml
.idea
52 changes: 52 additions & 0 deletions contracts/warp-account-tracker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[package]
name = "warp-account-tracker"
version = "0.1.0"
authors = ["Terra Money <[email protected]>"]
edition = "2021"

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 more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
library = []

[package.metadata.scripts]
optimize = """docker run --rm -v "${process.cwd()}":/code \
-v "${path.join(process.cwd(), "../../", "packages")}":/packages \
--mount type=volume,source="${contract}_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/rust-optimizer${process.env.TERRARIUM_ARCH_ARM64 ? "-arm64" : ""}:0.12.6
"""

[dependencies]
cosmwasm-std = "1.1"
cosmwasm-storage = "1.1"
cosmwasm-schema = "1.1"
base64 = "0.13.0"
cw-asset = "2.2"
cw-storage-plus = "0.16"
cw2 = "0.16"
cw20 = "0.16"
cw721 = "0.16.0"
cw-utils = "0.16"
account-tracker = { path = "../../packages/account-tracker", default-features = false, version = "*" }
schemars = "0.8"
thiserror = "1"
serde-json-wasm = "0.4.1"
json-codec-wasm = "0.1.0"
prost = "0.11.9"

[dev-dependencies]
cw-multi-test = "0.16.0"
anyhow = "1.0.71"
Loading

0 comments on commit 868c3f2

Please sign in to comment.