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

4 governed contracts for whitelisting cw721 contracts and ICS721 channels. #1

Closed
wants to merge 53 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
21a20db
initial setup: sender whitelist contract
Mar 22, 2023
c2fdafa
whitelist proxy, only contract address in wl are eligible `send_nft`s…
Mar 22, 2023
2b10d36
update readme
Mar 22, 2023
b93eaea
typo
Mar 22, 2023
13032ee
use String instead of Addr for generic usage
Mar 22, 2023
6769303
rename package for general usage
Mar 22, 2023
b80a9cf
A proxy with a channel whitelist being eligible to `send_nft`s to ori…
Mar 22, 2023
0f6bbcb
update readme
Mar 22, 2023
d41612e
use generics for better re-usability
Mar 30, 2023
8c646b8
cleanup and renamings
Mar 30, 2023
c2f589d
cleanup
Mar 30, 2023
5e10d43
fix test
Mar 30, 2023
890816e
rename function
Mar 30, 2023
b646983
cargo fmt
Mar 30, 2023
7cc7ba4
mino renamings for better consistency
Mar 30, 2023
0478aa8
rename test for better consistency
Mar 30, 2023
e064faf
minor fix and changes
Mar 30, 2023
da24d54
new proxy for code ids
Mar 30, 2023
9a46be6
dedicated UnauthorizedChannel, cleanup
Mar 30, 2023
45a4f6f
add schema files
Mar 30, 2023
f0e3463
new proxy for cw721 and channels
Mar 30, 2023
1c27a83
document
Mar 30, 2023
accffc8
rename
Mar 30, 2023
fc49e75
document and rename
Mar 30, 2023
53c8df7
fix
Mar 30, 2023
f21afc2
fix lib entry point
Apr 24, 2023
34ad12a
update schema
Apr 24, 2023
1987e8e
transfer NFT to ICS721
May 2, 2023
4e74493
add migrate msg
May 5, 2023
e14f609
migrate origin as well if provided
May 5, 2023
9599f41
add migrate msg
May 9, 2023
9c00222
transfer nft
May 10, 2023
c076521
allow owner to change rate limit and origin
May 10, 2023
8845e68
new execute messages for origin and whitelist
May 10, 2023
dd62c76
query owner, cleanup
May 10, 2023
47f5156
execute owner
May 10, 2023
7a4edfc
minor fix
May 10, 2023
26e559b
typo
May 11, 2023
b275993
move IbcOutgoingMsg to packages
May 11, 2023
9bcc461
move to root's Cargo.toml
May 12, 2023
5433656
move to governance package
May 12, 2023
f80922f
new governed proxy contracts
May 19, 2023
b157066
keep original rate limit proxy
May 19, 2023
386abc1
update schema, cleanup
May 19, 2023
a2f9445
add owner for instantiation, if not provided transfer fees and origin…
May 21, 2023
f93a233
update README
May 21, 2023
4f2d5d5
allow owner to be migrated
May 21, 2023
0f57af5
rename
May 22, 2023
16cd627
cleanup
May 22, 2023
85d5819
add migrate msg
May 9, 2023
daa7979
new clear_whitelist, simplify types using tuples, and remove wrapper …
May 24, 2023
2396082
move governance to package
May 26, 2023
7d925e6
Kudos to Jake and Larry
May 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
353 changes: 268 additions & 85 deletions Cargo.lock

Large diffs are not rendered by default.

40 changes: 39 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,43 @@
[workspace]
members = ["contracts/*", "packages/*", "debug/*"]
members = ["contracts/*", "packages/*", "debug/*"]

[workspace.package]
authors = ["Mr T <mr-t@arkprotocol.io>"]
edition = "2021"
homepage = "https://arkprotocol.io"
repository = "https://github.com/arkprotocol/cw721-proxy/"
license = "Apache-2.0"
keywords = ["cosmos", "cosmwasm"]

[workspace.dependencies]
cosmwasm-std = "1.1"
cosmwasm-schema = "1.1"
cw-storage-plus = "0.16"
cw2 = "0.16"
cw721 = "0.16"
cw721-proxy = { path = "./packages/cw721-proxy", version = "*" }
cw721-proxy-derive = { path = "./packages/cw721-proxy-derive", version = "*" }
cw721-whitelist = { path = "./packages/cw721-whitelist", version = "*" }
cw721-whitelist-map = { path = "./packages/cw721-whitelist-map", version = "*" }
cw721-governed-proxy = { path = "./contracts/cw721-governed-proxy", version = "*" }
cw-ics721-governance = { path = "./packages/cw-ics721-governance", version = "*" }
cw-ics721-governance-derive = { path = "./packages/cw-ics721-governance/derive", version = "*" }
cw-rate-limiter = { path = "./packages/cw-rate-limiter", version = "*" }
cw-utils = "0.16.0"
ibc-outgoing-msg = { path = "./packages/ibc-outgoing-msg", version = "*" }
cw721-proxy-multi-test = { path = "./packages/cw721-proxy-multi-test", version = "*" }
schemars = "0.8.11"
proc-macro2 = "1.0"
quote = "1.0"
serde = "1.0"
syn = { version = "1.0", features = ["derive"] }
thiserror = "1"
# dev dependencies
cw-multi-test = "0.16.4"
cw721-base = "0.16"
cw721-proxy-tester = { path = "./debug/cw721-proxy-tester", version = "*" }
rand = "0.8"
anyhow = "1.0"

[profile.release]
codegen-units = 1
Expand Down
97 changes: 93 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,98 @@
# CW 721 Proxy

1. `packages/cw721-proxy` An interface for proxying cw721 send messages.
3. `contracts/cw721-rate-limited-proxy` An implementation of this
1. `contracts/cw721-rate-limited-proxy` An implementation of this
proxy interface to rate limit incoming cw721 send messages.
2. `packages/cw-rate-limiter` package for rate limiting in CosmWasm
2. `contracts/cw721-governed-proxy` A a governed proxy with an optional transfer fee
being eligible to `bridge_nft`s to origin contract.
3. `contracts/cw721-governed-rate-limited-proxy` A `cw721-governed-proxy` extension of above rate limited proxy.
4. `contracts/cw721-governed-channel-proxy` A `cw721-governed-proxy` extension with a channel whitelist
being eligible to `send_nft`s to origin contract.
5. `contracts/cw721-governed-code-id-proxy` A `cw721-governed-proxy` extension with a code id whitelist
being eligible to `send_nft`s to origin contract.
6. `contracts/cw721-governed-collection-proxy` A `cw721-governed-proxy` extension with a collection (cw721/sender) whitelist
being eligible to `send_nft`s to origin contract.
7. `contracts/cw721-governed-collection-channels-proxy` A `cw721-governed-proxy` extension with a sender and channels whitelist
being eligible to `send_nft`s to origin contract.
8. `packages/cw721-proxy` An interface for proxying cw721 send messages.
9. `packages/cw-rate-limiter` package for rate limiting in CosmWasm
contracts.
4. `packages/cw721-proxy-derive` Procedural macros for deriving the
10. `packages/cw721-proxy-derive` Procedural macros for deriving the
proxy receiver message types on an existing enum.
11. `packages/cw-governed-proxy-multitest` Test app with helper functions for testing governed proxies.
12. `packages/cw721-whitelist` An `Item<'a, Vec<T>>` store for whitelisting in CosmWasm contracts.
13. `packages/cw721-whitelist-map` A `Map<'a, K, T>` store for whitelisting in CosmWasm contracts.
contracts.
14. `packages/ibc-outgoing-msg` An `IbcOutgoingMsg` struct, required by [ICS721](https://github.com/public-awesome/ics721/blob/main/contracts/cw-ics721-bridge/src/msg.rs#L84-L95).

# Proxies

## Rate Limited Proxy

A simple proxy to rate limit incoming cw721 send messages. A rate limit can be set based on `Blocks` or `PerBlocks` as defined in [Rate](.packages/cw-rate-limiter/src/lib.rs#L15).

An incoming `receive_nft` message is forwarded to a given `origin` (ics721 contract).

## Governed Proxy

A simple governed proxy. There are 2 possibilities NFTs can be transferred to another chain:

1. `receive_nft`: NFT is send from collection to proxy. Proxy gets a `receive_nft` from collection, transfer ownership to ics721 (escrowed) and __forwards receive msg__ to ics721, which then handles inter-chain transfer.
2. `bridge_nft`: NFT is send by calling `bridge_nft` directly on proxy. Proxy is allowed and have approval to transfer nft to ics721 and __sends a receive msg__ to ics721, which then handles inter-chain transfer.

A governed proxy stores this:

- `origin`: required ics721 contract for handling inter-chain transfers.
- `owner`: optional, if given only owner is authorized changing `origin`, `owner`, `transfer_fee` and execute `send_funds`.
- `transfer_fee`: optional, if provided it will be checked whether funds have been send on `receive_nft` and `bridge_nft` is called. This means pratically only `bridge_nft` is eligible to call ics721, since `send_nft` is called by collection - and in case of base cw721 it doesn't send funds!

IMPORTANT: in case `owner` is not set, above stores (`origin`, `owner` and `transfer_fee`) are immutable. Also `send_funds` is disabled then. The only way of changing these is via migration!

## Governed Rate Limited Proxy

A `cw721-governed-proxy` extension of above rate limited proxy.

## Governed Channel Proxy

A `cw721-governed-proxy` extension with a channel whitelist being eligible to `send_nft`s to origin contract.

## Governed Code Id Proxy

A `cw721-governed-proxy` extension with a code id whitelist being eligible to `send_nft`s to origin contract.

## Governed Collection Proxy

A `cw721-governed-proxy` extension with a collection (cw721/sender) whitelist being eligible to `send_nft`s to origin contract.

## Governed Collection Channels Proxy

A `cw721-governed-proxy` extension with a sender and channels whitelist being eligible to `send_nft`s to origin contract.

# Packages

## cw721-proxy

An interface for proxying cw721 send messages.

## cw-rate-limiter

Package for rate limiting in CosmWasm contracts.

## cw721-proxy-derive

Procedural macros for deriving the proxy receiver message types on an existing enum.

## cw-governed-proxy-multitest

Test app with helper functions for testing governed proxies.

## cw721-whitelist

An `Item<'a, Vec<T>>` store for whitelisting in CosmWasm contracts.

## cw721-whitelist-map

A `Map<'a, K, T>` store for whitelisting in CosmWasm contracts.

## ibc-outgoing-msg

An `IbcOutgoingMsg` struct, required by [ICS721](https://github.com/public-awesome/ics721/blob/main/contracts/cw-ics721-bridge/src/msg.rs#L84-L95).
15 changes: 15 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

## Compiles and optimizes contracts

set -o errexit -o nounset -o pipefail
command -v shellcheck >/dev/null && shellcheck "$0"

cd "$(git rev-parse --show-toplevel)"

docker run --rm -v "$(pwd)":/code --platform linux/amd64 \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/workspace-optimizer:0.12.9

ls -al ./artifacts/*wasm
4 changes: 4 additions & 0 deletions contracts/cw721-governed-channel-proxy/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[alias]
wasm = "build --release --lib --target wasm32-unknown-unknown"
unit-test = "test --lib"
schema = "run --bin schema"
15 changes: 15 additions & 0 deletions contracts/cw721-governed-channel-proxy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Build results
/target

# 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
41 changes: 41 additions & 0 deletions contracts/cw721-governed-channel-proxy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[package]
name = "cw721-governed-channel-proxy"
version = "0.0.1"
description = "TODO"
license = { workspace = true }
authors = { workspace = true }
edition = { workspace = true }
homepage = { workspace = true }
repository = { workspace = true }
keywords = { workspace = true }

[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 = []

[dependencies]
cosmwasm-std = { workspace = true }
cosmwasm-schema = { workspace = true }
cw-storage-plus = { workspace = true }
cw2 = { workspace = true }
cw721 = { workspace = true }
cw721-proxy = { workspace = true }
cw721-proxy-derive = { workspace = true }
cw721-whitelist = { workspace = true }
cw721-governed-proxy = { workspace = true, features = ["library"] }
cw-ics721-governance = { workspace = true}
ibc-outgoing-msg = { workspace = true }
thiserror = { workspace = true }

[dev-dependencies]
cw-multi-test = { workspace = true }
cw721-base = { workspace = true }
cw721-proxy-tester = { workspace = true }
cw721-proxy-multi-test = { workspace = true }
rand = { workspace = true }
anyhow = { workspace = true }
Loading