Skip to content

Commit

Permalink
add stableCoinVault and its test files
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraLantean committed Jan 30, 2023
1 parent d81c21d commit b9173ac
Show file tree
Hide file tree
Showing 7 changed files with 1,055 additions and 0 deletions.
32 changes: 32 additions & 0 deletions basic/stable-coin/.gitignore
@@ -0,0 +1,32 @@
archive
build
coverage
coverage.json
cache
removed
.env
.vscode
yarn-error.log
z*.sh

# Visual studio code
core/*/.vscode
defi/*/.vscode
nft/*/.vscode

# macOS folder attributes
.DS_Store

# Rust auto-generated
target/
Cargo.lock
**/*.rs.bk

# Flamegraph profiles
flamegraph.svg

# IntelliJ
.idea/

# Emacs
*~
28 changes: 28 additions & 0 deletions basic/stable-coin/Cargo.toml
@@ -0,0 +1,28 @@
[package]
name = "stable-coin-vault"
version = "0.1.0"
edition = "2021"

[dependencies]
sbor = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v0.7.0" }
scrypto = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v0.7.0" }

[dev-dependencies]
transaction = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v0.7.0" }
radix-engine = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v0.7.0" }
scrypto-unit = { git = "https://github.com/radixdlt/radixdlt-scrypto", tag = "v0.7.0" }

[profile.release]
opt-level = 's' # Optimize for size.
lto = true # Enable Link Time Optimization.
codegen-units = 1 # Reduce number of codegen units to increase optimizations.
panic = 'abort' # Abort on panic.
strip = "debuginfo" # Strip debug info.
overflow-checks = true # Panic in the case of an overflow.

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

[workspace]
# Set the package crate as its own empty workspace, to hide it from any potential ancestor workspace
# Remove this [workspace] section if you intend the package to be part of a Cargo workspace
21 changes: 21 additions & 0 deletions basic/stable-coin/LICENSE
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 AuroraLantean

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
130 changes: 130 additions & 0 deletions basic/stable-coin/README.md
@@ -0,0 +1,130 @@
# Radix Stablecoin Vault

## Description

A Stablecoin vault blueprint that can

- mint tokens to the vault or to the admin badge holder
- withdraw tokens from the vault to admin bucket
- deposit tokens from admin bucket into the vault
- burn tokens inside the vault or from admin bucket
- get the vault status data: version, token amount, total supply
- set version to mark future upgrades

## Installation

The following steps assume working in a Linux environment.

See official installation guide for other operation systems:
https://docs-babylon.radixdlt.com/main/getting-started-developers/first-component/install-scrypto.html

Install build dependencies

```bash
sudo apt install clang build-essential llvm
```

### Install Rust

https://www.rust-lang.org/tools/install

If you already have Rust:

```bash
rustup update stable
```

OR install it the first time

```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

Add WebAssembly target

```bash
rustup target add wasm32-unknown-unknown
```

Add Rust in your PATH:

```
export PATH="~/.cargo/bin:$PATH"
```

To configure your current shell and confirm Rust installation:

```bash
source $HOME/.cargo/env
rustc --version
```

### Install Scrypto

```bash
git clone https://github.com/radixdlt/radixdlt-scrypto.git
cd radixdlt-scrypto
cargo install --path ./simulator
resim -V
```

### Install VS Code Extensions

- Rust-Analyzer
- Radix Transaction Manifest Support

```bash
code --install-extension rust-lang.rust-analyzer
code --install-extension RadixPublishing.radix-transaction-manifest-support
```

### Install Repository Dependencies

```bash
git clone https://github.com/AuroraLantean/radix_stablecoin_vault
cd radix_stablecoin_vault
scrypto build
```

This is only needed for the first time to install all Rust dependencies. For subsequent building, the above command can be omitted as running tests will automatically build everything again.

### Run Automatic Tests

Adding `-- --nocapture` will force logs to show even there is no error.

```bash
scrypto test
scrypto test -- --nocapture
```

### Run Manual Tests

1. Create a new account, and save the account address

```
resim new-account
```

2. Publish the package, and save the package address:

```
resim publish .
```

3. Call the `new` function to instantiate a component, and save the component address:

```
resim call-function <PACKAGE_ADDRESS> StableCoinVault new
```

4. Call the `mint_to_bucket` method of the component:

```
resim call-method <COMPONENT_ADDRESS> mint_to_bucket 100
```

5. Check out our balance

```
resim show <ACCOUNT_ADDRESS>
```

0 comments on commit b9173ac

Please sign in to comment.