{"id":28380731,"url":"https://github.com/0xsequence/erc5189-libs","last_synced_at":"2025-06-24T21:31:39.164Z","repository":{"id":226324672,"uuid":"764876211","full_name":"0xsequence/erc5189-libs","owner":"0xsequence","description":null,"archived":false,"fork":false,"pushed_at":"2024-05-01T22:06:42.000Z","size":40,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-06-06T03:40:54.574Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Solidity","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/0xsequence.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-02-28T21:42:50.000Z","updated_at":"2024-03-07T00:32:43.000Z","dependencies_parsed_at":"2024-03-08T17:25:54.422Z","dependency_job_id":"b519f8dc-5b21-438e-98e8-2a570940dc95","html_url":"https://github.com/0xsequence/erc5189-libs","commit_stats":null,"previous_names":["0xsequence/erc5189-libs"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/0xsequence/erc5189-libs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xsequence%2Ferc5189-libs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xsequence%2Ferc5189-libs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xsequence%2Ferc5189-libs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xsequence%2Ferc5189-libs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/0xsequence","download_url":"https://codeload.github.com/0xsequence/erc5189-libs/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/0xsequence%2Ferc5189-libs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261759141,"owners_count":23205503,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-30T03:09:12.130Z","updated_at":"2025-06-24T21:31:39.138Z","avatar_url":"https://github.com/0xsequence.png","language":"Solidity","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ERC5189 Libs\n\nThis repository contains libraries for interacting with [ERC-5189](https://eips.ethereum.org/EIPS/eip-5189) contracts.\n\n## IEndorser\n\nThe `IEndorser` interface is an interface for ERC-5189 Endorsers.\nFor more information, see the [ERC-5189 specification](https://eips.ethereum.org/EIPS/eip-5189).\n\n## IReceiptProvider\n\nThe IReceiptProvider is an additional interface for ERC-5189 endorsers to provide operation receipts.\nFor more information, see the [ERC-7655 specification](https://eips.ethereum.org/EIPS/eip-7655).\n\n## LibDc\n\nThe `LibDc` library contains functions for constructing dependency lists for ERC-5189 Endorsers, it uses a builder pattern that simplifies the process of creating dependencies.\n\nCreate a `Dc` (DependencyCarrier) with the `create()`, an optional `IEndorser.Operation` can be passed to it, this will allow the library to also perform assertions on the operation.\n\n```solidity\nimport { Dc, LibDc } from \"contracts/LibDc.sol\";\n\ncontract Endorser {\n  using LibDc for Dc;\n\n  function _myFunction() internal {\n    Dc memory dc = LibDc.create();\n\n    //...\n  }\n}\n```\n\nYou can define global dependencies using the available functions.\n\n```solidity\n// These can only be set once\ndc.addBaseFee();\ndc.addBlobBaseFee();\ndc.addChainId();\ndc.addCoinBase();\ndc.addDifficulty();\ndc.addGasLimit();\ndc.addNumber();\ndc.addTimestamp();\ndc.addTxOrigin();\ndc.addTxGasPrice();\n\n// These functions set the maximum value unless it is already set to a lower value\ndc.addMaxBlockNumber(block.number + 1000);\ndc.addMaxBlockTimestamp(block.timestamp + 1000);\n```\n\nFor address specific dependencies, use the available functions to ensure no duplicate dependencies are created.\n\n```solidity\ndc.addBalanceDependency(0x1234);\ndc.addCodeDependency(0x1234);\n```\n\nSimilarly, for slot dependencies, use the available functions to ensure no duplicate dependencies are created. Setting slots is ignored if `allSlots` is set for the given address.\n\n```solidity\ndc.addSlotDependency(0x1234, 0x5678);\n```\n\nSome values cannot be determined on chain due to visibility restrictions. Use `contraints` to notify the ERC-5189 Bundler of the required values.\n\n```solidity\ndc.addConstraint(0x1234, 0x5678, 0x9abc); // Require specific value\ndc.addConstraint(0x1234, 0xdefg, 0x0, 0x1); // Require value in range\n```\n\nThe `build()` method will return the return arguments for `isOperationReady()`.\n\n```solidity\nfunction isOperationReady(\n  //...\n) public view returns (bool readiness, GlobalDependency memory, Dependency[] memory) {\n  //...\n  return dc.build();\n}\n```\n\n### Chaining changes\n\nThe library supports the builder pattern, allowing for chaining changes. This pattern is entirely optional, as the `Dc` is modified in place.\n\n```solidity\nDc memory dc = LibDc.create()\n  .addBaseFee()\n  .addBlobBaseFee()\n  .addChainId()\n  .addCoinBase()\n  .addDifficulty()\n  .addGasLimit()\n  .addNumber()\n  .addTimestamp()\n  .addTxOrigin()\n  .addTxGasPrice()\n  .addMaxBlockNumber(block.number + 1000)\n  .addMaxBlockTimestamp(block.timestamp + 1000)\n  .addBalanceDependency(0x1234)\n  .addCodeDependency(0x1234)\n  .addSlotDependency(0x1234, 0x5678)\n  .addConstraint(0x1234, 0x5678, 0x9abc)\n  .addConstraint(0x1234, 0xdefg, 0x0, 0x1);\n```\n\n## LibSlot\n\nThe `LibSlot` library contains functions for determining with storage mappings slots.\n\nYou can read about the storage layout of contracts in the [Solidity documentation](https://docs.soliditylang.org/en/latest/internals/layout_in_storage.html).\n\nFor a mapping, the slot is determined by the `keccak256` hash of the key and the storage slot. Find the mapping slot by interogating the storage layout of the contract.\n\nFor two dimensional mappings, the slot can be determined recursively.\n\n```solidity\nmapping(bytes32 =\u003e bytes32) public map;\nmapping(bytes32 =\u003e mapping(bytes32 =\u003e bytes32)) public map2d;\n\nmap[0x5678] = 0xffff; // map at 0x0\nLibSlot.getMappingStorageSlot(0x0, 0x5678);\n\nmap2d[0x5678][0x9abc] = 0xffff; // map2d at 0x1\nLibSlot.getMappingStorageSlot(LibSlot.getMappingStorageSlot(0x1, 0x5678), 0x9abc);\n```\n\n## LibString\n\nThe `LibString` allows for creating verbose string errors, for debugging purposes. These verbose strings can be used to generate detailed revert messages, which can be helpful when building complex endorser contracts.\n\n```solidity\nimport { LibString } from \"contracts/LibString.sol\";\n\ncontract Example {\n  using LibString for *;\n\n  function example() public {\n    // Concatenate strings\n    // \"Hola mundo!\"\n    string memory s1 = \"Hola \".c(\"mundo!\".s());\n\n    // Concatenate uints and strings\n    // \"Hola 123!\"\n    string memory s2 = \"Hola \".c(123).c(\"!\");\n\n    // Concatenate bytes32 and strings\n    // Hex formatted: df5f697d36135c1a2b807e8cdd39a4c3a6e9aa5295c6f750a0d674daf840617d\n    string memory s3 = \"Hex formatted: \".c(bytes32(0xdf5f697d36135c1a2b807e8cdd39a4c3a6e9aa5295c6f750a0d674daf840617d));\n\n    // Concatenate address and strings\n    // \"Address: 0x0xe28c4384F57e38775B288C5becDb3B28f2b0AEdb\"\n    string memory s4 = \"Address: \".c(address(0xe28c4384F57e38775B288C5becDb3B28f2b0AEdb));\n\n    // Concatenate byte arrays and strings\n    // \"Bytes: 0x1234\"\n    string memory s5 = \"Bytes: \".c(hex\"1234\");\n  }\n}\n```\n\n\u003e Notice that concatenating two strings requires calling `.s()` on the argument, this is to avoid ambiguity when concatenating strings and other types. The `solc` compiler will not allow concatenating two strings without an explicit conversion.\n\n## Usage\n\n### Build\n\n```shell\nforge build\n```\n\n### Test\n\n```shell\nforge test -vvv\n```\n\n### Format\n\nPlease run formatting before creating a pull request.\n\n```shell\nforge fmt\n```\n\n## License\n\nAll contracts in this repository are [UNLICENSED](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0xsequence%2Ferc5189-libs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F0xsequence%2Ferc5189-libs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F0xsequence%2Ferc5189-libs/lists"}