SDC Solidity implementation
Description
The reference SDC implementation can be unit tested with Hardhat to understand the trade process logic.
The trade interface takes explicit participants. Inception returns a generated trade ID that is never reused; confirmation and cancellation repeat it with the original parties, signed amounts and text fields. Termination methods also identify the requester and retain that requester's payment perspective.
The SDC and FX spot trade examples require direct calls from the participant responsible for each action. This authorization policy is specific to the examples, not part of ERC-6123. The build uses Solidity 0.8.24.
FxSpotTrade represents an FX spot trade with atomic payment-versus-payment (PvP)
settlement. Confirmation exchanges the two currency-token amounts once through a
shared ERC20PvPSettlementRouter. Parties approve the router before confirmation.
These implementations illustrate the protocol. ERC20Settlement allows unrestricted
mint and setSDCAddress calls, and SDCSingleTradePledgedBalance.performSettlement
does not authenticate the valuation provider. Applications must define and enforce
those permissions before using these examples with real assets.
Compile and run tests with Hardhat
We provide the essential steps to compile the contracts and run the provided unit tests.
Provided Contracts and Tests
Interfaces
contracts/ISDC.sol- Interface contract (aggregation ofISDCTrade,ISDCSettlement,IAsyncTransferCallback)contracts/ISDCTrade.sol- Interface related to trade incept/confirm/terminatecontracts/ISDCSettlement.sol- Interface related to settlement initiate/perform/aftercontracts/IAsyncTransferCallback.sol- Interface related to transfer.contracts/IAsyncTransfer.sol- Interface (extending the ERC-20) for settlement tokens used inSDCPledgedBalance.
Implementations
contracts/TradeIdGenerator.sol- Generates decimal trade identifiers that are never reusedcontracts/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 testscontracts/examples/FxSpotTrade/FxSpotTrade.sol- FX spot trade with atomic PvP settlementcontracts/examples/FxSpotTrade/FxSpotTradeFactory.sol- Creates trades and registers them with the shared routercontracts/examples/FxSpotTrade/ERC20PvPSettlementRouter.sol- Settles both token legs atomically using shared token allowances
Tests
test/SDCTests.js- Unit tests for the life-cycle of the sdc implementationtest/TradeContextTest.js- Explicit participants, exact matching and trade ID replay checkstest/FxSpotTradeTest.js- FX settlement, exact matching and single-use lifecycle checks
Compile and run tests with Hardhat
Install dependencies:
npm i
Compile:
npx hardhat compile
Run all tests:
npx hardhat test
Configuration files
package.json- JavaScript package definition.hardhat.config.js- Hardhat config.
Used javascript-based testing libraries for solidity
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.
Packaging
The npm package is built from assets/erc-6123 in the ERCs repository.
Run npm pack --dry-run from this directory to inspect its contents. Contracts,
documentation, tests and configuration are included; generated build and coverage
files are excluded.