Skip to content

About

On-chain list of contract addresses on XDC, so a front end can read them instead of hard-coding them. Foundry tests included. Not audited.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

16 Commits

Folders and files

Repository files navigation

Contract Ledger: Keep an on-chain list of the contracts behind an app

build network: any EVM language: Solidity status: proof of concept license: MIT

How it works · Try it · What is tested · Known issues

Contract Ledger lets a person or a contract keep an on-chain list of contract addresses. An app with many contracts can keep them in one place, and a front end can read that list instead of hard-coding the addresses. The same pattern also stores lists of token IDs or strings.

Warning

This is a proof of concept. It has not been audited and has not run on a real network. Everything in a ledger is public.

How it works

flowchart LR
    K[Key holder] -->|addContract| U[LedgerUser]
    U -->|numbered entry| E[Addresses, time, ID]
    R[Anyone] -->|viewLedgerID| U
Loading
Contract Use Add function Read function
LedgerUser Ready to deploy. Holding a key token allows adding addContract(addresses) viewLedgerID(id)
LedgerContract Inherit it for lists of addresses Internal addContract viewLedgerID(id)
LedgerContractToken Inherit it for lists of token IDs Internal addTokenInt viewIntLedgerID(id)
LedgerContractData Inherit it for lists of strings Internal addData viewDataLedgerID(id)

Every read returns the list, the time it was added, its ID and whether it exists. Each add emits an event carrying the ID, because a wallet cannot read a function's return value.

The base contracts have no access control of their own. Whoever inherits them decides who may add.

Try it

git clone https://github.com/CoinClubQuincy/ContractLedger.git
cd ContractLedger
git clone --depth 1 -b v4.9.6 https://github.com/OpenZeppelin/openzeppelin-contracts lib/openzeppelin-contracts
git clone --depth 1 -b v1.9.7 https://github.com/foundry-rs/forge-std lib/forge-std
forge test

You need Foundry.

What is tested

test/foundry/Ledger.t.sol has 12 tests, including one fuzz test, and runs in CI on every push.

Tested Not tested
Adding and reading in all four contracts A real network, testnet or mainnet
Key access, and access moving with the key An independent security audit
Refusing empty entries and zero keys
Entries that do not exist, and events
Fuzz: IDs count up and entries stay separate

Changes from earlier versions

Contracts already deployed are unaffected and keep the old behaviour.

  • The three base ledgers are now abstract. They could be deployed before, but nothing could ever be added to them.
  • Each add emits an event with its ID, and empty lists are refused.
  • LedgerUser refuses zero keys, which would have left nobody able to add.
  • The Hardhat template (Lock.sol, its test and its script), the broken test/LedgerContract.js, the Hardhat config and package files, and tracked node_modules were removed. Foundry is the supported test path.

Known issues

Issue Effect
Entries cannot be edited or removed A mistake stays in the ledger. Add a corrected entry and have readers use the latest
Anyone holding a key can add Keys are all equal, and there is no way to take one back
Addresses are not checked An entry can name an address that is not a contract
More XDC and EVM projects
Group Project What it is
Standards XRC-SHARES Dividend-paying NFT shares and SPLITS for a DApp
Standards XRCDividendPlus Dividend-paying XRC-20 token
Treasury and finance Multi-Sig-Treasury Treasury controlled by tokenized keys
Treasury and finance XRC-Airdrop Self-run token airdrop
Treasury and finance XRC-Credit Single-loan credit contract
Treasury and finance XDC-Defi-Instruments Assets, agreements, forwards, futures and a marketplace
Treasury and finance XRC1155-Equities-Market Shares, portfolios and a marketplace on ERC-1155
Treasury and finance NFTOTC Over-the-counter sale of a token collection
Treasury and finance DAppProxySwap Currency swaps for a DApp through a fixed router
Identity and access LoginMFAContract Login with an NFT and a signed second factor
Identity and access PrivateAccessToken Token access to encrypted off-chain data
Identity and access Delegated_Authority KYC notary proof of concept
Identity and access EncryptedNFT-Documents NFTs tied to encrypted off-chain documents
Learning and libraries XDC-LemonadeStand Workshop DApp built on XRC-SHARES
Learning and libraries Non-Financial-SmartContracts Games, inventory, keys and on-chain repositories
Learning and libraries TimestampConverter Timestamps to calendar dates in Solidity
Tools XDC_Python_SDK_V1 Python client for the XDC JSON-RPC API
Tools PrivateXDCNode_SetupScript Private XDC network setup scripts
Tools WebApp_to_XDCPay Working web app connected to XDCPay
Multi-chain CoinClub_Framework Python library with an XDC adapter
Interfaces Contract_Interface_Model_Language Interface documents for smart contracts and APIs

License

MIT.

About

On-chain list of contract addresses on XDC, so a front end can read them instead of hard-coding them. Foundry tests included. Not audited.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages