Skip to content

DebtEngine to use with CMTAT to implement Debt and Credit events

License

Notifications You must be signed in to change notification settings

CMTA/DebtEngine

Repository files navigation

Debt Engine

This project has not been audited yet, please use at your own risk. For any questions, please contact [email protected].

This repository includes the DebtEngine contract for the CMTAT token.

The debtEngine allows to define debt and credit events for several different contracts.

A debt is defined with the following attributes

struct DebtBase {
        uint256 interestRate;
        uint256 parValue;
        string guarantor;
        string bondHolder;
        string maturityDate;
        string interestScheduleFormat;
        string interestPaymentDate;
        string dayCountConvention;
        string businessDayConvention;
        string publicHolidaysCalendar;
        string issuanceDate;
        string couponFrequency;
}

A creditEventsis defined with the following attributes

struct CreditEvents {
      bool flagDefault;
      bool flagRedeemed;
      string rating;
}

How to include it

While it has been designed for the CMTAT, the debtEngine can be used with others contracts to define debt and credit events.

For that, the only thing to do is to import in your contract the interface IDebtEngine which declares the two functions debt and creditEvents.

This interface can be found in CMTAT/contracts/interfaces/engine/IDebtEngine.sol

interface IDebtEngine is IDebtGlobal {
    function debt() external view returns(IDebtGlobal.DebtBase memory);
    function creditEvents() external view returns(IDebtGlobal.CreditEvents memory);
}

Schema

Inheritance

surya_inheritance_DebtEngine.sol

Graph

surya_graph_DebtEngine.sol

Surya Description Report

Contracts Description Table

Contract Type Bases
Function Name Visibility Mutability Modifiers
DebtEngine Implementation IDebtEngine, AccessControl, DebtEngineInvariantStorage
Public ❗️ 🛑 NO❗️
debt External ❗️ NO❗️
debt Public ❗️ NO❗️
creditEvents External ❗️ NO❗️
creditEvents Public ❗️ NO❗️
setDebt External ❗️ 🛑 onlyRole
setCreditEvents External ❗️ 🛑 onlyRole
setCreditEventsBatch External ❗️ 🛑 onlyRole
setDebtsBatch External ❗️ 🛑 onlyRole
hasRole Public ❗️ NO❗️

Legend

Symbol Meaning
🛑 Function can modify state
💵 Function is payable

Gasless support (ERC-2771)

The DebtEngine supports client-side gasless transactions using the Gas Station Network (GSN) pattern, the main open standard for transfering fee payment to another account than that of the transaction issuer. The contract uses the OpenZeppelin contract ERC2771ContextUpgradeable, which allows a contract to get the original client with _msgSender() instead of the fee payer given by msg.sender while allowing upgrades on the main contract (see Deployment via a proxy above).

At deployment, the parameter forwarder inside the constructor has to be set with the defined address of the forwarder. Please note that the forwarder can not be changed after deployment.

Please see the OpenGSN documentation for more details on what is done to support GSN in the contract.

Dependencies

The toolchain includes the following components, where the versions are the latest ones that we tested:

  • Foundry
  • Solidity 0.8.26 (via solc-js)
  • OpenZeppelin Contracts (submodule) v5.0.2
  • Tests

The CMTAT contracts and the OpenZeppelin library are included as a submodule of the present repository.

Tools

Prettier

npx prettier --write --plugin=prettier-plugin-solidity 'src/**/*.sol'

Slither

slither .  --checklist --filter-paths "openzeppelin-contracts|test|CMTAT|forge-std" > slither-report.md

Surya

See ./doc/script

Foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.

Foundry consists of:

  • Forge: Ethereum testing framework (like Truffle, Hardhat and DappTools).
  • Cast: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
  • Anvil: Local Ethereum node, akin to Ganache, Hardhat Network.
  • Chisel: Fast, utilitarian, and verbose solidity REPL.

Documentation

https://book.getfoundry.sh/

Usage

Coverage
$ forge coverage --report lcov && genhtml lcov.info --branch-coverage --output-dir coverage
Gas report
$ forge test --gas-report
Build
$ forge build
Test
$ forge test
Format
$ forge fmt
Gas Snapshots
$ forge snapshot
Anvil
$ anvil
Deploy
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
Cast
$ cast <subcommand>
Help
$ forge --help
$ anvil --help
$ cast --help

Intellectual property

The code is copyright (c) Capital Market and Technology Association, 2018-2024, and is released under Mozilla Public License 2.0.

About

DebtEngine to use with CMTAT to implement Debt and Credit events

Resources

License

Stars

Watchers

Forks