Skip to content

Feat/rc naga 2025 04 07 #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions json.d.ts

This file was deleted.

150 changes: 101 additions & 49 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,80 +1,132 @@
# Fetch Lit contracts and have the same format as general-worker

To run locally, use the following command:

Ensure you have a fine-grain read-only personal access token for the `lit-assets` repository (`GH_LIT_ASSETS_READ_ONLY_API`). For the `LIT_ABI_SOURCE` environment variable, you can set it to either `prod` or `dev`.

- `prod`: Pulls content from the stable network contracts and ABIs found in the [LIT Protocol networks repository](https://github.com/LIT-Protocol/networks).
- `dev`: Pulls content from the [LIT Protocol lit-assets repository](https://github.com/LIT-Protocol/lit-assets), a private repository with frequently changing ABIs and addresses, likely used for internal development.
# Lit Protocol Contract Fetcher

A TypeScript utility for fetching and caching Lit Protocol contract ABIs and addresses. This tool maintains consistent contract data formats across the Lit Protocol ecosystem.

## Architecture

```mermaid
flowchart TB
subgraph Main Process
main["main()"] --> procProd["Process Production Networks"]
main --> procDev["Process Development Networks"]
main --> genIndex["Generate Index File"]
main --> summary["Print Network Summary"]
end

subgraph Production Flow
procProd --> |"For each network"| updateProdCache["updateProdCache()"]
updateProdCache --> getProdABIs["getProdContractABIs()"]
updateProdCache --> getLastMod["getLastModified()"]
updateProdCache --> writeCache["Write Cache File"]
end

subgraph Development Flow
procDev --> updateDevCache["updateDevCache()"]
updateDevCache --> getDevABIs["getDevContractABIs()"]
updateDevCache --> getLastMod
updateDevCache --> writeCache
end

subgraph File Generation
genIndex --> |"Generate"| indexTS["dist/index.ts"]
writeCache --> |"Generate"| prodTS["dist/prod/*.ts"]
writeCache --> |"Generate"| devTS["dist/dev/*.ts"]
end

subgraph Configuration
config["Constants & Config"]
networks["Network Definitions"]
contractMap["Contract Name Mappings"]
config --> main
networks --> main
contractMap --> updateProdCache
contractMap --> updateDevCache
end

subgraph GitHub API
getProdABIs --> |"Fetch"| ghAPI["GitHub API"]
getDevABIs --> |"Fetch"| ghAPI
getLastMod --> |"Fetch"| ghAPI
end

style main fill:#f9f,stroke:#333,stroke-width:4px
style ghAPI fill:#b8d4ff,stroke:#333
style config fill:#d4ffb8,stroke:#333
```

eg.
## Project Structure

```
LIT_ABI_SOURCE=prod GH_LIT_ASSETS_READ_ONLY_API=xxx bun run fetch-contracts.ts

// for specific branch
DEV_BRANCH=develop LIT_ABI_SOURCE=prod GH_LIT_ASSETS_READ_ONLY_API=xxx bun run fetch-contracts.ts
src/
├── config/ # Configuration constants and network definitions
├── services/ # Core business logic services
├── types/ # TypeScript type definitions
├── utils/ # Utility functions
└── index.ts # Main entry point
```

# To trigger build
## Prerequisites

```
curl -X POST -H "Accept: application/vnd.github.everest-preview+json" \
-H "Authorization: token github_pat_<____YOUR_GITHUB_PERSONAL_ACCESS_TOKEN____>" \
https://api.github.com/repos/LIT-Protocol/lit-contracts/dispatches \
-d '{"event_type":"sync_trigger"}'
```
- Node.js 16 or higher
- GitHub Personal Access Token with read permissions

# Installation
## Environment Variables

```
- `GH_API_KEY`: GitHub Personal Access Token (required)
- `DEV_BRANCH`: Development branch name (defaults to 'develop')

## Installation

```bash
yarn add @lit-protocol/contracts
```

# Usage
## Usage

## for "main" branch
### Production Networks (from 'networks' repo)

### Production (Getting data from `networks` repo )

```
```typescript
import { datilDev, datilTest, datil } from "@lit-protocol/contracts";

console.log("datilDev:", datilDev);
console.log("datilTest:", datilTest);
console.log("datil:", datil);
```

### Development (Getting data from `lit-assets` repo `develop` branch )
### Development Networks (from 'lit-assets' repo)

```
import { _datilDev, _datilTest, _datil } from "@lit-protocol/contracts";
```typescript
import { develop } from "@lit-protocol/contracts";

console.log("datilDev:", _datilDev);
console.log("datilTest:", _datilTest);
console.log("datil:", _datil);
console.log("Development contracts:", develop);
```

## for any other branches with `dev-` prefix
## Local Development

### Development (Getting data from `lit-assets` repo with whatever the branch name is)
1. Clone the repository
2. Install dependencies:
```bash
yarn install
```
3. Set up environment variables:
```bash
export GH_API_KEY=your_github_token
export LIT_ABI_SOURCE=prod # or 'dev'
```
4. Run the fetcher:

eg. if your branch here is called `dev-datil` then it will pull data from lit-assets `datil` branch
```bash
# For default branch
bun run fetch-contracts.ts

the `dev-` prefix is to allow GitHub action to publish to npm.
# For specific branch
DEV_BRANCH=develop bun run fetch-contracts.ts
```

```
import { _datilDev, _datilTest, _datil } from "@lit-protocol/contracts";
## CI/CD Workflow

console.log("datilDev:", _datilDev);
console.log("datilTest:", _datilTest);
console.log("datil:", _datil);
```

# Branching & dev strategy

![](https://i.ibb.co/Z136p20/image.png)
![](https://www.plantuml.com/plantuml/png/TP6nSl8m48HxFSMLvf-11p35Ju0KAI0COM1I2ljiYyWdpKaYuUqZ2Po9YtIQtTMdqzx2USa-z5haWoWFhDeM6Kw6FnfjFkT2DL0Cwk5cyVy4V8S4nIwuRY9GEuHYZzOuvGtVOAsSbRvA5jMg4UKRUdYcgs93FPA7esGbpnhTdRraILKtHc-aeea0o7SRmv04k2Vd-SbqiyRhzDyejiRhA0N5QmJoA9EL8VLhnc1XQsgSNHn8gc4PQ2xA5ugzQ1t1DYQHAfN6BlU1eC7uoMbboBEil9jv1vPD_RSRntsOBHAoz3Z5BsiuklqbKLUcxvNFhwTkOTL9QeUQTk6iLHIVTDmArZzLlQFBtrk6ti8HsIaJ1mSOQ0y9af_r0UGDR7UReQUjoPIqF2rlS99CYjgX7-UD5Oju3ht-1W00)

# CI Workflow
## License

![](https://www.plantuml.com/plantuml/png/TP6nSl8m48HxFSMLvf-11p35Ju0KAI0COM1I2ljiYyWdpKaYuUqZ2Po9YtIQtTMdqzx2USa-z5haWoWFhDeM6Kw6FnfjFkT2DL0Cwk5cyVy4V8S4nIwuRY9GEuHYZzOuvGtVOAsSbRvA5jMg4UKRUdYcgs93FPA7esGbpnhTdRraILKtHc-aeea0o7SRmv04k2Vd-SbqiyRhzDyejiRhA0N5QmJoA9EL8VLhnc1XQsgSNHn8gc4PQ2xA5ugzQ1t1DYQHAfN6BlU1eC7uoMbboBEil9jv1vPD_RSRntsOBHAoz3Z5BsiuklqbKLUcxvNFhwTkOTL9QeUQTk6iLHIVTDmArZzLlQFBtrk6ti8HsIaJ1mSOQ0y9af_r0UGDR7UReQUjoPIqF2rlS99CYjgX7-UD5Oju3ht-1W00)
MIT
Binary file modified bun.lockb
Binary file not shown.
Loading