npm.io
0.9.0 • Published 5h ago

@finmath.net/sdc

Licence
CC0-1.0
Version
0.9.0
Deps
1
Size
325 kB
Vulns
0
Weekly
0
Stars
15

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 of ISDCTrade, 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 in SDCPledgedBalance.

Implementations
  • contracts/TradeIdGenerator.sol - Generates decimal trade identifiers that are never reused

  • 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 implementing IERC20Settlement for unit tests

  • contracts/examples/FxSpotTrade/FxSpotTrade.sol - FX spot trade with atomic PvP settlement

  • contracts/examples/FxSpotTrade/FxSpotTradeFactory.sol - Creates trades and registers them with the shared router

  • contracts/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 implementation
  • test/TradeContextTest.js - Explicit participants, exact matching and trade ID replay checks
  • test/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.

Keywords