{"id":25451461,"url":"https://github.com/usagi-coffee/pg_chainutils","last_synced_at":"2026-03-07T22:07:58.251Z","repository":{"id":168061960,"uuid":"643680904","full_name":"usagi-coffee/pg_chainutils","owner":"usagi-coffee","description":"Blockchain utilities for PostgreSQL","archived":false,"fork":false,"pushed_at":"2025-05-18T18:17:33.000Z","size":99,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-18T19:27:06.561Z","etag":null,"topics":["blockchain","database","ethereum","pgrx","postgreql","postgres","postgres-extension","postgresql","postgresql-extension","rust","sql"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/usagi-coffee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-05-21T23:14:12.000Z","updated_at":"2025-05-18T18:17:37.000Z","dependencies_parsed_at":"2024-05-15T17:57:41.990Z","dependency_job_id":"da780bba-3ea7-4153-b261-2e3db9565585","html_url":"https://github.com/usagi-coffee/pg_chainutils","commit_stats":null,"previous_names":["usagi-coffee/pg_chainutils"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/usagi-coffee/pg_chainutils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usagi-coffee%2Fpg_chainutils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usagi-coffee%2Fpg_chainutils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usagi-coffee%2Fpg_chainutils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usagi-coffee%2Fpg_chainutils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/usagi-coffee","download_url":"https://codeload.github.com/usagi-coffee/pg_chainutils/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usagi-coffee%2Fpg_chainutils/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30233432,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T19:01:10.287Z","status":"ssl_error","status_checked_at":"2026-03-07T18:59:58.103Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["blockchain","database","ethereum","pgrx","postgreql","postgres","postgres-extension","postgresql","postgresql-extension","rust","sql"],"created_at":"2025-02-17T22:53:38.326Z","updated_at":"2026-03-07T22:07:58.232Z","avatar_url":"https://github.com/usagi-coffee.png","language":"Rust","readme":"# pg_chainutils: blockchain utilities for PostgreSQL\n\npg_chainutils adds some simple utilities that help parse/transform/interact with blockchain datatypes and standards directly inside PostgreSQL.\n\nContributions and suggestions welcome!\n\nThis extension is created using [pgrx](https://github.com/tcdi/pgrx)\nCheck out [pg_chainsync](https://github.com/usagi-coffee/pg_chainsync) extension to fetch blocks and events inside your database.\n\n## Usage\n\n```sql\nCREATE EXTENSION pg_chainutils;\n```\n\n### H256 / H160\n\n```sql\nSELECT H256.parse(\"0000000000000000000000001111111111111111111111111111111111111111\");\n-- 0x0000000000000000000000001111111111111111111111111111111111111111\n\nSELECT H256.parse_slice(\n    \"0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000a16e02e87b7454126e5e10d957a927a7f5b5d2be\",\n    64, 128\n);\n-- 0x000000000000000000000000a16e02e87b7454126e5e10d957a927a7f5b5d2be\n\nSELECT H160.from_H256(\"0x0000000000000000000000001111111111111111111111111111111111111111\")\n-- 0x1111111111111111111111111111111111111111\n\nSELECT H256.keccak256(\"Sync(uint112,uint112)\"); -- keccak256 of event signature\n-- 0x1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1\n```\n\n### ERC20 / ERC721\n\n```sql\n-- Takes abi hex encoded topics as argument\nSELECT ERC20.transfer_from('{0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef,0x0000000000000000000000001111111111111111111111111111111111111111,0x0000000000000000000000002222222222222222222222222222222222222222}');\n-- 0x1111111111111111111111111111111111111111\n-- Or you can just use H160.from_H256 and pass second element of topics array\n\n-- Takes abi hex encoded topics as argument\nSELECT ERC20.transfer_to('{0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef,0x0000000000000000000000001111111111111111111111111111111111111111,0x0000000000000000000000002222222222222222222222222222222222222222}');\n-- 0x2222222222222222222222222222222222222222\n-- Or you can just use H160.from_H256 and pass third element of topics array\n\n-- Takes non-hex encoded data and returns value\nSELECT ERC20.transfer_value('00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000001d688');\n-- 120456\n\nSELECT ERC721.transfer_token('00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000001d688');\n-- 120456\n```\n\n### Sushiswap / Uniswap\n\n```sql\n-- Takes non-hex encoded data and returns swap type\nSELECT Sushiswap.swap_type('00..');\nSELECT Uniswap.swap_type('00..');\n-- 1 (BUY) or -1 (SELL)\n\n-- Pair: BASE / QUOTE\n-- Takes non-hex encoded data and returns swap amount\nSELECT Sushiswap.swap_base_amount('00..');\nSELECT Sushiswap.swap_quote_amount('00..');\n\nSELECT Uniswap.swap_base_amount('00..');\nSELECT Uniswap.swap_quote_amount('00..');\n\n-- Takes non-hex encoded data and returns reserve\nSELECT Sushiswap.sync_base_reserve('00..');\nSELECT Sushiswap.sync_quote_reserve('00..');\n\nSELECT Uniswap.sync_base_reserve('00..');\nSELECT Uniswap.sync_quote_reserve('00..');\n\n-- Takes non-hex encoded data and base decimals / quote decimals, returns price\nSELECT Sushiswap.sync_price('00..', 18, 18);\n\n-- Takes non-hex encoded data of swap and base/quote decimals, returns price\n-- Uniswap does not have sync event but we can get the same result using swap event\nSELECT Uniswap.sync_price('00..', 18, 18);\n```\n\n## License\n\n```\nMIT License\n\nCopyright (c) 2023 Kamil Jakubus and contributors\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusagi-coffee%2Fpg_chainutils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fusagi-coffee%2Fpg_chainutils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusagi-coffee%2Fpg_chainutils/lists"}