Code Monkey home page Code Monkey logo

usn's Introduction

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

Contract Address

Mainnet usn
Testnet usdn.testnet
Sandbox usn.test.near

How It Works

Obtain USN for USDT

Method: ft_transfer_call (USDT) -> ft_on_transfer (USN)

Deposit USDT

Withdraw USDT with withdraw API

Method: withdraw (USN)

Withdraw USDT

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 about the addresses for cross-contract communication.

USDT address

Mainnet dac17f958d2ee523a2206206994597c13d831ec7.factory.bridge.near
Testnet usdt.fakes.testnet
Sandbox usdt.test.near

Test

Run unit tests

cargo test

Run integration tests

npm 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"]}'

Deposit and withdraw

# Send USDT, mint USN.
near call usdt.fakes.testnet ft_transfer_call --args '{"receiver_id": "usdn.testnet", "amount": "1000000", "msg": ""}' --accountId alice.testnet --depositYocto 1 --gas 100000000000000

# Burn USN, withdraw USDT.
near call usdn.testnet withdraw --args '{"amount": "999500000000000000"}' --accountId alice.testnet --depositYocto 1 --gas 100000000000000

DAO

Upgrade the contract via Upgrade Proposal

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

API

Deposit/withdraw

// Deposit
pub fn ft_on_transfer(&mut self, sender_id: AccountId, amount: U128, msg: String) -> PromiseOrValue<U128>;
// Withdraw
pub fn withdraw(&mut self, asset_id: Option<AccountId>, amount: U128) -> 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 version(&self) -> String;
pub fn blacklist_status(&self, account_id: &AccountId) -> BlackListStatus;
pub fn owner(&self);
pub fn treasury(&self) -> Vec<(AccountId, StableInfo)>;
pub fn commission(&self) -> CommissionOutput;
pub fn commission_rate(&self, asset_id: &AccountId) -> CommissionRate;

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;
pub fn ft_on_transfer(&mut self, sender_id: AccountId, amount: U128, msg: String) -> PromiseOrValue<U128>;

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 extend_guardians(&mut self, guardians: Vec<AccountId>);
pub fn remove_guardians(&mut self, guardians: Vec<AccountId>);
pub fn add_stable_asset(&mut self, asset_id: &AccountId, decimals: u8);
pub fn enable_stable_asset(&mut self, asset_id: &AccountId);
pub fn disable_stable_asset(&mut self, asset_id: &AccountId);
pub fn transfer_commission(&mut self, account_id: AccountId, amount: U128); 
pub fn set_commission_rate(&mut self, asset_id: &AccountId, rate: CommissionRate)
pub fn stake(&self, amount: U128, pool_id: AccountId) -> Promise;
pub fn unstake(&self, amount: U128, pool_id: AccountId) -> Promise;
pub fn unstake_all(&self, pool_id: AccountId) -> Promise;
pub fn withdraw_all(&self, pool_id: AccountId) -> Promise;

Ownership change

pub fn propose_new_owner(&mut self, proposed_owner_id: AccountId);
pub fn accept_ownership(&mut self);

Upgradability

pub fn upgrade();
pub fn migrate() -> Self;

usn's People

Contributors

austinabell avatar usnzorro avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.