The reference SDC implementation can be unit tested with Hardhat to understand the trade process logic.
We provide the essential steps to compile the contracts and run the provided unit tests.
-
contracts/ISDC.sol- Interface contract (aggregation ofISDCTrade,ISDCSettlement,IAsyncTransferCallback) -
contracts/ISDCTrade.sol- Interface related to trade incept/confirm/terminate -
contracts/ISDCSettlement.sol- Interface related to settlement initiate/perform/after -
contracts/IAsyncTransferCallback.sol- Interface related to transfer. -
contracts/IAsyncTransfer.sol- Interface (extending the ERC-20) for settlement tokens used inSDCPledgedBalance.
contracts/SDCSingleTrade.sol- SDC abstract contract for an OTC Derivative (single trade case only)contracts/SDCSingleTradePledgedBalance.sol- SDC full implementation for an OTC Derivative (single trade case only)contracts/ERC20Settlement.sol- Mintable settlement token contract implementingIERC20Settlementfor unit tests
test/SDCTests.js- Unit tests for the life-cycle of the sdc implementation
Install dependencies:
npm iCompile:
npx hardhat compileRun all tests:
npx hardhat testpackage.js- Javascript package definition.hardhat.config.js- Hardhat config.
ethereum-waffle: Waffle is a Solidity testing library. It allows you to write tests for your contracts with JavaScript.chai: Chai is an assertion library and provides functions like expect.ethers: This is a popular Ethereum client library. It allows you to interface with blockchains that implement the Ethereum API.solidity-coverage: This library gives you coverage reports on unit tests with the help of Istanbul.
- Re-introduced the method
afterSettlementthat can be used to check pre-conditions of the next settlement cycle, e.g., triggered by a time-oracle. - Added the event
SettlementAwaitingInitiationwhich should be issued when the trade goes active and whenafterSettlementveryfied that the trade is ready for the next settlement.