USN - the first NEAR-native stablecoin

Related tags

Cryptography usn
Overview

USN

USN

USN is a NEAR-native USD stable coin.

The contract implements fungible token API according to the following standards:

  1. NEP-141 (ERC-20 fashioned)
  2. NEP-148
  3. Fungible Token Event

The specific part of the USN contract is buy/sell methods of NEAR/USD exchange with rates taken from the oracle (priceoracle).

Contract Address

Mainnet Testnet
usn usdn.testnet

How It Works

Buy USN for NEAR

Method: buy

Buy USN

Sell USN for NEAR with sell API

Method: sell

Sell USN

Slippage

Methods buy and sell requires the expected exchange rate to avoid slippage. If the price suddenly changes (slips) out of the expected deviation the USN contract aborts the transaction.

Build

First, install prerequisites:

npm install

Then, build.

For local sandbox:

npm run build

For testnet:

npm run build:testnet

For mainnet:

npm run build:mainnet

WARNING: There is a difference in each target. The crucial difference is that they communicate with different oracle addresses:

  • Mainnet: priceoracle.near
  • Testnet: priceoracle.testnet
  • Sandbox: priceoracle.test.near

And all these oracle contracts report prices with different asset names.

Test

Run unit tests

cargo test

Run integration tests

npm run build
npm run deploy
npm run test

Manual testing on the Testnet

Build

npm run build:testnet

Deploy

near deploy --force --wasmFile target/wasm32-unknown-unknown/testnet/usn.wasm --accountId=usdn.testnet --masterAccount=usdn.testnet

Init once

near call usdn.testnet new --args '{"owner_id": "usdn.testnet"}' --accountId=usdn.testnet

Add a guardian

near call usdn.testnet extend_guardians --accountId usdn.testnet --args '{"guardians": ["alice.testnet"]}'

Buy and sell

# Send NEAR, buy USN.
near call usdn.testnet buy --accountId alice.testnet --amount 1 --gas 50000000000000

# Check USN balance.
near call usdn.testnet ft_balance_of --accountId alice.testnet --args '{"account_id": "alice.testnet"}'

# Sell USN, receive NEAR.
near call usdn.testnet sell --accountId alice.testnet --args '{"amount": "118800"}' --amount 0.000000000000000000000001 --gas 50000000000000

# Buy USN with slippage control
 near call usdn.testnet buy  --args '{"expected": {"multiplier": "111439", "slippage": "10", "decimals": "28" }}' --accountId alice.testnet --amount 1 --gas 50000000000000

# Buy USN and transfer to someone.
near call usdn.testnet buy --args '{"to": "bob.testnet"}' --accountId alice.testnet --amount 1 --gas 50000000000000

DAO

Upgrade the contract via Upgrade Proposal

  1. Download usn.mainnet.wasm from https://github.com/binary-star-near/usn/releases
  2. Create an upgrade proposal:
    sputnikdao proposal upgrade usn.mainnet.wasm usn --daoAcc usn --accountId alice.near --network mainnet

API

Buy/sell USN

Send NEAR, receive USN.

pub fn buy(&mut self, expected: Option<ExpectedRate>, to: Option<AccountId>);

Send USN, receive NEAR.

pub fn sell(&mut self, amount: U128, expected: Option<ExpectedRate>) -> Promise;

View methods

pub fn contract_status(&self) -> ContractStatus;
pub fn name(&self) -> String;
pub fn symbol(&self) -> String;
pub fn decimals(&self) -> u8;
pub fn spread(&self, amount: Option<U128>) -> U128;
pub fn version(&self) -> String;
pub fn blacklist_status(&self, account_id: &AccountId) -> BlackListStatus;
pub fn owner(&self);

NEP-141 (ERC-20)

pub fn ft_transfer(&mut self, receiver_id: AccountId, amount: U128, memo: Option<String>);
pub fn ft_transfer_call(
        &mut self,
        receiver_id: AccountId,
        amount: U128,
        memo: Option<String>,
        msg: String,
    ) -> PromiseOrValue<U128>;
pub fn ft_total_supply(&self) -> U128;
pub fn ft_balance_of(&self, account_id: AccountId) -> U128;
pub fn ft_metadata(&self) -> FungibleTokenMetadata;

NEP-145: partial storage API

Always returns 125 milliNEAR indicating that user doesn't need to be registered with storage_deposit.

pub fn storage_balance_of(&self, account_id: AccountId) -> Option<StorageBalance>;

Constructor

pub fn new(owner_id: AccountId) -> Self;

Private setters

For owner only.

pub fn upgrade_name_symbol(&mut self, name: String, symbol: String);
pub fn upgrade_icon(&mut self, data: String);
pub fn add_to_blacklist(&mut self, account_id: &AccountId);
pub fn remove_from_blacklist(&mut self, account_id: &AccountId);
pub fn destroy_black_funds(&mut self, account_id: &AccountId);
pub fn pause(&mut self);
pub fn resume(&mut self);
pub fn set_fixed_spread(&mut self, spread: U128) {
pub fn set_adaptive_spread(&mut self, params: Option<ExponentialSpreadParams>);
pub fn set_owner(&mut self, owner_id: AccountId);
pub fn extend_guardians(&mut self, guardians: Vec<AccountId>);
pub fn remove_guardians(&mut self, guardians: Vec<AccountId>);

Upgradability

pub fn upgrade();
pub fn migrate() -> Self;
You might also like...
Helpful functions and macros for developing smart contracts on NEAR Protocol.

near-contract-tools Helpful functions and macros for developing smart contracts on NEAR Protocol. This package is a collection of common tools and pat

Confidential credit scores and loan disbursal, powered by zkSNARKs and NEAR Protocol
Confidential credit scores and loan disbursal, powered by zkSNARKs and NEAR Protocol

zkLoans zkLoans brings confidential Credit Scores. It proves to a counterparty if you meet threshold requirements for a credit score without revealing

evm2near compiles Solidity contracts into NEAR WebAssembly contracts.

EVM β†’ NEAR evm2near is a project for compiling EVM bytecode into wasm bytecode, with the particular goal of having that wasm artifact be executable on

Lesson 1 - Fundamental structure of smartcontract of near protocol

NEAR CONTRACT dev-1672293046853-49717456344735 pnpm run deploy [email protected] deploy /Users/vudangquang/Courses/VBI-Courses/rs-contract cd co

Marinde Anchor-Based, first on mainnet, liquid-staking-program and mSOL-SOL swap pool

marinade-anchor Marinade-finance liquid staking program for the Solana blockchain Audits & Code Review Kudelski Security: https://marinade.finance/Kud

Privacy-first delay tolerant network protocol

🌟 Liminality 🌟 Liminality is a unique protocol for wireless communication in fluid and dynamic environments. The protocol takes its name from the li

Rust-native building blocks for the Cardano blockchain ecosystem

Pallas Rust-native building blocks for the Cardano blockchain ecosystem. Introduction Pallas is an expanding collection of modules that re-implements

egui: an easy-to-use immediate mode GUI in Rust that runs on both web and native
egui: an easy-to-use immediate mode GUI in Rust that runs on both web and native

πŸ–Œ egui: an easy-to-use GUI in pure Rust πŸ‘‰ Click to run the web demo πŸ‘ˆ egui is a simple, fast, and highly portable immediate mode GUI library for Ru

Utilities for working with native solc and compiling projects.

foundry-compilers Utilities for working with native solc and compiling projects. To also compile contracts during cargo build (so that ethers abigen!

Comments
  • fix: remove rlib from crate

    fix: remove rlib from crate

    rlib is only needed when you need to import types exported from the library external to the crate and will not do any LTO.

    With docker build, Contract size with rlib: 432740 Contract size without: 366547

    opened by austinabell 1
Releases(v2.3.4)
Owner
DecentralBank
Decentralized organisation developing and supporting NEAR-native stablecoins.
DecentralBank
Decentralized stablecoin on Juno Network.

⚑️ C O S M W A S M S T A B L E C O I N ⚑️ coming soon to junø network ?? Overview Ultra is a CosmWasm stablecoin protocol developed on JunoNetwork by

notional-labs 12 Dec 15, 2022
rust-native-tls β€” Bindings for native TLS libraries

rust-native-tls Documentation An abstraction over platform-specific TLS implementations. Specifically, this crate uses SChannel on Windows (via the sc

Steven Fackler 371 Jan 8, 2023
Reference client for NEAR Protocol

Reference implementation of NEAR Protocol About NEAR NEAR's purpose is to enable community-driven innovation to benefit people around the world. To ac

NEAR 2k Jan 3, 2023
A PoC backbone for NFT Marketplaces on NEAR Protocol

NFT Market Reference Implementation A PoC backbone for NFT Marketplaces on NEAR Protocol. Reference Changelog Changelog Progress: basic purchase of NF

null 9 May 26, 2022
Reference client for NEAR Protocol

Reference implementation of NEAR Protocol About NEAR NEAR's purpose is to enable community-driven innovation to benefit people around the world. To ac

NEAR 2k Jan 4, 2023
Near contract collection for story-arc.io

arc-near-contracts TBD Development Setup Make sure to format code using defaults before every commit or set up the environment to handle this for you.

null 2 Mar 14, 2022
A tutorial for an NFT Market Place Built with Near Protocol and React.js

nft-marketplace-part-1 A tutorial for an NFT Market Place built using Near Protocol and React.js. Preview To run this app locally, follow below steps:

Kohwo Orien 5 Jun 29, 2022
A tool to help with estimating NEAR gas spent by transactions on Aurora.

Aurora Gas Estimator A tool to help with estimating NEAR gas spent by transactions on Aurora. Building from source Prerequisites Rust GNU Make (3.81+)

Michael Birch 4 Aug 23, 2022
Durudex Near Protocol Token.

Durudex Near Token ?? Prerequisites Rust Near CLI βš™οΈ Build To build a token you will need to use this: cargo build --all --target wasm32-unknown-unkno

Durudex 2 May 31, 2022
Helpful functions and macros for developing smart contracts on NEAR Protocol.

near-contract-tools Helpful functions and macros for developing smart contracts on NEAR Protocol. This package is a collection of common tools and pat

Jacob 27 Dec 17, 2022