Install Dependencies:
npm install
Start Local ETH Blockchain:
npm run dev
Reset contracts (compile, deploy, mint USDC, set data in DB if available)
TODO: The first run of the script fails. The second succeed. Fix that
# From the <project_root>/Contracts dir, run:
# In full dapp mode via multisig contract owner
npm run reset:contracts
# In contracts-only mode, with direct owner of the contracts
npm run reset:contracts <ownerAddress>
# In development, due to the static mnemonic you can
# npm run reset:contracts 0x9e74E6Be10B63A7442184dFFD633fbed80175B34
Compile Contracts
npm run compile
Deploy Contract
npm run deploy
Upgrade Contract
npm run upgrade
Run the mintUSDC.js script in the scripts folder (it will mint 10K local mirror of USDC to the first account on ganache on every run)
TODO: add mintInverseToken script instructions
- This will create flatten files in flats folder. These can be used in remix to connect to deployed contracts.
npm run flatten
- new solidity file <contractName>.sol
- copy paste the <contractName> flat file in remix
- compile using 0.5 compiler
- Find the local <contractName> address in local /tmp/contractAddresses.json
- Environment: inject web3
- contract deployed at: [previously found address]
- function are now available for interactions
- These are best structured by mirroring the contracts directory: for each
.sol
file there, create a corresponding.test.js
file.
npm test
For more information on testing smart contracts go to https://docs.openzeppelin.com/learn/writing-automated-tests and https://docs.openzeppelin.com/test-environment/0.1/api
- Amun Frontend (UI for KYC, Creation/Redemption, and Token Management)
- Amun Backend (User Database and API Wrapper for Smart Contract Functions)
- Token Swap Smart Contract System (Responsible for Token Swap Management + Portfolio Composition Calcuation)
- Jasper (driven from Onyx system) off-chain Trading Engine (Processes creation, redemption, and rebalance)
The steps involved in CREATE and REDEEM processes are illustrated below
- KYC’d Authorised User (AU) sends USDC (stablecoin) to the Token collateral pool
- Backend listener is capturing confirmations of that transaction
Once N confirmations reached:
- The backend executes on the trading engine a short-sell
- Once confirmed, a call is made to the CREATE function of the Token Swap Manager (TSM) which mints inverse tokens to the AU's address
- KYC’d Authorised User (AU) sends inverse tokens to the Token collateral pool
- Backend listener is capturing confirmations of that transaction
Once N confirmations reached:
- The backend executes on the trading engine a long-repay
- Once confirmed, a call is made to the REDEEM function of the Token Swap Manager (TSM) which transfers USDC from the Collateral Pool to the AU and burns the previously sent inverse tokens
A rebalance will be ordered by the Onyx Trading Engine during two events:
- 5pm CET during a Daily Rebalance
- A price increase of 33% since the last rebalance, AKA Threshold Rebalance
During a rebalance, Jasper Trading Engine engages in one of two actions depending on crypto price:
- Increase short exposure
- Decrease short exposure
The rebalance workflow is detailed below:
- Jasper Backend listens for the Time or a Threshold Price to be reached.
- It then reads the Crypto Price from the trading desk and decides to either increase or decrease short exposure.
- The trading engine then executing the short-sell / long-repay action
- Once confirmed, a call to the TSM is made to initiates a calculation of the NAV/Cash Position of the Inverse Tokens.