nibiruchain / cw-nibiru Goto Github PK
View Code? Open in Web Editor NEWRust monorepo and CosmWasm smart contract sandbox for Nibiru Chain
Rust monorepo and CosmWasm smart contract sandbox for Nibiru Chain
The token agreements defined in the
tokenomics will be implemented
via a CosmWasm smart contract. The feature demands (1) a secure and
configurable way to vest tokens linearly over time and (2) an interface for
claiming vested tokens.
cw-nibiru
repo. | @jgimenocw-nibiru/nibiru-std/src/proto/mod.rs
Lines 107 to 135 in 8d93e73
ExecuteMsg::Claim
as admin-onlyExecuteMsg::EditSudoers
as admin-onlyWrite docs to answer the following questions:
package.json
Create a GitHub action appropriate for a Rust monorepo.
The setup used in the CosmWasm/cw-plus repo seems close to what we're looking for, but there are better-managed monorepos we can take cues from.
schema.json
files and other important generated assets.Contracts like "token-vesting", "nibi-stargate", "shifter", or ones for the Go bindings can be grouped together as "core contracts" and have grouped releases. This can help keep the versions more semnatic without coupling them too tightly to unrelated code.
Future smart contracts that become core or essential to the protocol can be kept here as well.
scripts
and the justfile
.The Cosmos-SDK repo has a clever convention for managing many dependencies in tandem by prefixing tags with a scope. For instance, tags for separate packages of cosmossdk.io are prefixed.
Reference implementation: https://lib.rs/crates/mars-owner
That's pretty much unreachable lol
Originally posted by @matthiasmatt in #48 (comment)
I ran some performance benchmarks to compare times when building for the Wasm target with and without release optimization. On average (on my local machine), it was about 23% faster to build with cargo wasm-debug
than to build with cargo wasm
.
cargo wasm-debug := cargo build --target wasm32-unknown-unknown
cargo wasm := cargo build --release --target wasm32-unknown-unknown
This test should use the non-release builds since they're faster and the resulting bytecode from these CI runs won't be published.
The current contract implementation allows potentially many accounts to operate a single position opened and controlled by the smart contract.
As of right now, there's no way to claim the funds, and there's no way to migrate to a new version of the contract.
To migrate, the contract should:
Eventually, we should extend migrate
to go iterate through each position and close it.
migrate
.Image source: https://app.codecov.io/github/NibiruChain/cw-nibiru/tree/main/packages/bindings/src
sudoers
permission checks to the execute handlersFor both the IBC and IBC transfer types,
NibiruChain/nibiru#1378 (comment)
OpenPosition
, ClosePosition
, etc.There's an issue with the shifter contract logic. The maximum number
representable by the CosmWasm Decimal type is
340282366920938463463.374607431768211455 (~3.4e20), which leads to base
reserves and quote reserves of 18446744073.709551615000000000, far too small
for our perps markets.
For example, when I do:
nibid tx wasm execute \
nibi14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9ssa9gcs \
'{"depth_shift":{"pair":"ubtc:unusd","depth_mult":"1600000000000000000000000000"}}' \
--from validator \
--yes
I get an error
failed to execute message; message index: 0: Error parsing into type shifter::msgs::ExecuteMsg: Error parsing decimal '1600000000000000000000000000': Generic error: Value too big: execute wasm contract failed
A possible fix here would be to have the shifter contract logic operate with
sqrt_k
instead of k
, which increases our order of magnitude of 1e10.
The way SetMarketEnabled is not the correct way to Disable a Market.
This should be runnable from the justfile and have simple docs:
just gen-schema
Useful reference: https://github.com/mars-protocol/contracts/blob/0a453c0626340233b2ff50e4e936b59370d5bc67/schema.Makefile.toml
Provide a simplified abstraction around CosmWasm/ts-codegen. This should be usable from the top-level justfile
.
ts-codegen
for everything to an output dir like dist
.Dev X and Reduced Complexity: Simplifying the interactions with ts-codegen
will help eliminate the need to remember or input intricate command specifics.
Unified Output Directory: Centralizing generated code into a directory like dist
fosters organization and ensures uniformity across the repo.
Better Publishing: A publishing workflow for the TypeScript code will simplify the process of sharing or distributing the generated code, reducing manual steps and potential errors.
Install
npm install -g @cosmwasm/ts-codegen
Generating a client
# Template: Using the "client" plugin
cosmwasm-ts-codegen generate \
--plugin client \
--schema [path-to-schema-dir] \
--out [path-to-ts-out-dir] \
--name [contract-crate-name] \
--no-bundle
# Example: Using the "client" plugin
cosmwasm-ts-codegen generate \
--plugin client \
--schema ./schema \
--out ./ts \
--name SG721 \
--no-bundle
Generally, everything we need is some variation on cosmwasm-ts-codegen generate
Suppose that my machine doesn't have the right architecture to generate Wasm bytecode intended for production. This could be Windows without WSL or a Darwin (MacOS) architecture that could result in nondeterminism.
As a workaround, there should be an easy way me to:
Then, I can download the artifacts and checksums to include in the pull request.
Here's an example error raised from the bindings-perp
contract when I queried
the reserves in Go using a pair that wasn't defined in the genesis.
Error calling the VM: Error executing Wasm: Wasmer runtime error: RuntimeError: Aborted: panicked at 'called `Result::unwrap()` on an `Err` value: GenericErr { msg: "Querier contract error: codespace: undefined, code: 1" }', contracts/bindings-perp/src/binding.rs:74:24: query wasm contract failed
The VM error tells me that an error was raised, but it doesn't say what went
wrong. Instead of simply using unwrap, the contract should be more descriptive.
Logs from TestSuite/TestQueryReserves
:
querier_test.go:59:
Error Trace: /home/realu/warpath/NibiruChain/nibiru/x/wasm/binding/querier_test.go:59
/home/realu/warpath/NibiruChain/nibiru/x/wasm/binding/querier_test.go:153
Error: Received unexpected error:
github.com/CosmWasm/wasmd/x/wasm/keeper.Keeper.QuerySmart
/home/realu/go/pkg/mod/github.com/!cosm!wasm/[email protected]/x/wasm/keeper/keeper.go:718
github.com/NibiruChain/nibiru/x/wasm/binding_test.DoCustomBindingQuery
/home/realu/warpath/NibiruChain/nibiru/x/wasm/binding/querier_test.go:56
github.com/NibiruChain/nibiru/x/wasm/binding_test.(*QuerierTestSuite).TestQueryReserves
/home/realu/warpath/NibiruChain/nibiru/x/wasm/binding/querier_test.go:153
reflect.Value.call
/usr/local/go/src/reflect/value.go:584
reflect.Value.Call
/usr/local/go/src/reflect/value.go:368
github.com/stretchr/testify/suite.Run.func1
/home/realu/go/pkg/mod/github.com/stretchr/[email protected]/suite/suite.go:197
Error calling the VM: Error executing Wasm: Wasmer runtime
error: RuntimeError: Aborted: panicked at 'called
`Result::unwrap()` on an `Err` value: GenericErr { msg:
"Querier contract error: codespace: undefined, code: 1" }',
contracts/bindings-perp/src/binding.rs:74:24: query wasm
contract failed
start_time
is useless then in this implementation. We could just use start_time
instead of cliff_time
right?
Originally posted by @matthiasmatt in #48 (comment)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.