@oikos/core-addresses 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,17 +1,39 @@
1
1
  # @oikos/core-addresses
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/@oikos/core-addresses.svg)](https://www.npmjs.com/package/@oikos/core-addresses)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@oikos/core-addresses.svg)](https://www.npmjs.com/package/@oikos/core-addresses)
5
+ [![license](https://img.shields.io/npm/l/@oikos/core-addresses.svg)](#license)
6
+
3
7
  Programmatic access to Oikos Protocol contract addresses by chain id or network name.
4
8
 
5
9
  Deployment data is bundled from a pinned release tag of [`oikos-cash/core`](https://github.com/oikos-cash/core), so installing a fixed version of this package gives you a frozen, offline snapshot of the addresses for that protocol release.
6
10
 
11
+ Published on npm: <https://www.npmjs.com/package/@oikos/core-addresses>
12
+
7
13
  ## Install
8
14
 
15
+ Requires **Node.js 18+** (uses native `fetch` at build time; the runtime library itself has zero dependencies).
16
+
9
17
  ```sh
10
18
  npm install @oikos/core-addresses
11
19
  # or
12
20
  pnpm add @oikos/core-addresses
13
21
  # or
14
22
  yarn add @oikos/core-addresses
23
+ # or
24
+ bun add @oikos/core-addresses
25
+ ```
26
+
27
+ To pin to a specific protocol release:
28
+
29
+ ```sh
30
+ npm install @oikos/core-addresses@0.1.0
31
+ ```
32
+
33
+ No install needed for one-off CLI lookups:
34
+
35
+ ```sh
36
+ npx @oikos/core-addresses bsc Vault
15
37
  ```
16
38
 
17
39
  ## Programmatic usage
@@ -64,6 +86,12 @@ const { getAddress } = require("@oikos/core-addresses");
64
86
  | `NETWORKS` | All known network metadata (including networks without deployments yet). |
65
87
  | `getSourceMeta()` | `{ tag, source, fetchedAt, sha256 }` for the bundled snapshot. |
66
88
  | `SOURCE_TAG` / `SOURCE_URL` / `FETCHED_AT` / `SOURCE_SHA256` | Same values as above, as top-level constants. |
89
+ | `getContract(network, contract)` | Returns `{ address, abi }` for the network/contract pair. Throws if the ABI is not bundled (see [ABIs](#abis)). |
90
+ | `getAbi(contract)` | Returns the bundled ABI array for `contract`. Throws if not available. |
91
+ | `hasAbi(contract)` | `true` if an ABI is bundled for `contract`. |
92
+ | `listAbis()` | Sorted list of contracts with bundled ABIs. |
93
+ | `getAbiSourceMeta()` | `{ ref, fetchedAt, contracts }` describing the ABI pin and per-contract status. |
94
+ | `ABI_SOURCE_REF` / `ABI_FETCHED_AT` | Top-level constants for the ABI pin. |
67
95
 
68
96
  `network` can be a number (`56`), a numeric string (`"56"`), the canonical name (`"bsc"`), or any registered alias (`"bnb"`, `"binance"`, `"bnbchain"`, `"bsc-mainnet"`, `"bnb-mainnet"`). Names are case-insensitive.
69
97
 
@@ -85,8 +113,63 @@ type SourceMeta = {
85
113
  fetchedAt: string; // ISO-8601 timestamp
86
114
  sha256: string; // sha256 of the fetched bytes
87
115
  };
116
+
117
+ type AbiItem = Readonly<Record<string, unknown>>;
118
+ type Abi = ReadonlyArray<AbiItem>;
119
+
120
+ type AbiContractStatus = {
121
+ available: boolean;
122
+ source?: string; // raw.githubusercontent URL of the source artifact
123
+ artifact?: string; // out/<file>.sol/<name>.json
124
+ items?: number; // number of ABI entries
125
+ sha256?: string; // sha256 of the extracted, serialised ABI
126
+ reason?: string; // populated when available === false
127
+ };
128
+
129
+ type AbiSourceMeta = {
130
+ ref: string; // commit / tag the ABIs are pinned to
131
+ fetchedAt: string;
132
+ contracts: Record<string, AbiContractStatus>;
133
+ };
88
134
  ```
89
135
 
136
+ ## ABIs
137
+
138
+ ABIs for the deployed contracts are bundled alongside the addresses, fetched at build time from a **separate** pin on `oikos-cash/core` (see `oikosCoreAbiRef` in [`package.json`](package.json)). The ABI pin is decoupled from the deployment pin (`oikosCoreTag`) so that on-chain addresses and the ABIs used to call them can move on independent cadences.
139
+
140
+ ```ts
141
+ import { getContract, getAbi, hasAbi, listAbis } from "@oikos/core-addresses";
142
+
143
+ const { address, abi } = getContract("bsc", "Resolver");
144
+ // ^ 0xa78142B2A829AbA5D737af86a14d2BeEE82dDcF9
145
+ // ^ readonly array of ABI items
146
+
147
+ getAbi("ExchangeHelper"); // → readonly ABI array (copy)
148
+ hasAbi("Vault"); // → false at the current ABI pin (see below)
149
+ listAbis(); // → ["AdaptiveSupply", "ExchangeHelper", "Factory",
150
+ // "ModelHelper", "Resolver", "RewardsCalculator"]
151
+ ```
152
+
153
+ The returned `abi` is typed as `ReadonlyArray<Readonly<Record<string, unknown>>>` — pass it directly to ethers `new Contract(address, abi, …)`, viem `getContract({ address, abi, … })`, or wagmi. If you want the wagmi/viem `as const` inference you'll need to cast or codegen on your side; this package intentionally avoids pulling in `abitype`.
154
+
155
+ ### What's bundled at the current ABI pin
156
+
157
+ | Contract | ABI bundled? | Note |
158
+ | --- | --- | --- |
159
+ | `AdaptiveSupply` | ✅ | |
160
+ | `ExchangeHelper` | ✅ | |
161
+ | `Factory` | ✅ | Sourced from `OikosFactory.sol`. |
162
+ | `ModelHelper` | ✅ | Sourced from `Helper.sol`. |
163
+ | `Resolver` | ✅ | |
164
+ | `RewardsCalculator` | ✅ | |
165
+ | `Vault` | ❌ | Diamond proxy — composed ABI is a union of facets. Facet artifacts aren't checked in at the current ABI pin. |
166
+ | `Pool` | ❌ | External Uniswap V3 pool. Use [`@uniswap/v3-core`](https://www.npmjs.com/package/@uniswap/v3-core) `IUniswapV3Pool` for now. |
167
+ | `Proxy` | ❌ | External OpenZeppelin `ERC1967Proxy` wrapping OKS. Use [`@openzeppelin/contracts`](https://www.npmjs.com/package/@openzeppelin/contracts) for now. |
168
+
169
+ `getAbi()` / `getContract()` throw a clear, named error for the three unavailable contracts. Use `hasAbi(name)` to guard.
170
+
171
+ The current ABI pin is a temporary commit reference rather than a tagged release; it will be moved to a tag once the missing artifacts are available upstream.
172
+
90
173
  ## CLI (`npx`)
91
174
 
92
175
  ```sh
@@ -100,10 +183,16 @@ npx @oikos/core-addresses --json bsc
100
183
  | Flag | Effect |
101
184
  | --- | --- |
102
185
  | `-h, --help` | Show usage. |
103
- | `-l, --list` | List supported networks plus the bundled source tag and sha256. |
186
+ | `-l, --list` | List supported networks, the bundled source tag/sha256, and per-contract ABI availability. |
104
187
  | `-j, --json` | Print compact single-line JSON instead of pretty-printed. |
188
+ | `-a, --abi <name>` | Print the bundled ABI for `<name>` as JSON. |
105
189
 
106
- Exit code is `1` on unknown network or unknown contract.
190
+ ```sh
191
+ npx @oikos/core-addresses --abi Resolver
192
+ npx @oikos/core-addresses -a ExchangeHelper -j
193
+ ```
194
+
195
+ Exit code is `1` on unknown network, unknown contract, or when an ABI is requested for a contract that isn't bundled at the current ABI pin.
107
196
 
108
197
  ## Supported networks
109
198
 
@@ -113,38 +202,48 @@ Exit code is `1` on unknown network or unknown contract.
113
202
 
114
203
  Adding a new network: append an entry to [`src/networks.ts`](src/networks.ts) and make sure the chain id is present in the source `deployment.json`.
115
204
 
116
- ## How the deployment data is pinned
205
+ ## How the data is pinned
117
206
 
118
- This package does not check its address data into git. Instead, on every build it fetches the canonical `deployment.json` from a pinned ref of `oikos-cash/core`:
207
+ This package does not check its address or ABI data into git. Instead, on every build it fetches both from `oikos-cash/core` at independent pinned refs.
119
208
 
209
+ **Addresses** — single file at:
120
210
  ```
121
211
  https://raw.githubusercontent.com/oikos-cash/core/${oikosCoreTag}/deploy_helper/out/deployment.json
122
212
  ```
123
213
 
124
- The fetched bytes (plus tag, URL, timestamp, and sha256) are bundled into `dist/` and re-exported from the library, so consumers can verify which protocol release they are running against.
214
+ **ABIs** one file per available contract at:
215
+ ```
216
+ https://raw.githubusercontent.com/oikos-cash/core/${oikosCoreAbiRef}/out/<file>.sol/<artifact>.json
217
+ ```
218
+ The `abi` field is extracted from each Foundry artifact; bytecode and metadata are dropped.
219
+
220
+ Both feeds (plus per-file sha256 and fetch timestamp) are bundled into `dist/` and re-exported from the library, so consumers can verify which upstream bytes they are running against.
125
221
 
126
- - The pin lives in [`package.json`](package.json) under `"oikosCoreTag"` (default `v0.1`).
127
- - It can be overridden ad-hoc via the `OIKOS_CORE_TAG` env var or a positional arg to the fetch script.
222
+ - Address pin: [`package.json`](package.json) field `"oikosCoreTag"` (default `v0.1`). Override via `OIKOS_CORE_TAG`.
223
+ - ABI pin: [`package.json`](package.json) field `"oikosCoreAbiRef"` (default: a commit hash; currently temporary). Override via `OIKOS_CORE_ABI_REF`.
128
224
  - Network access is required at **build/publish time only**. End consumers installing from npm get a fully bundled, offline-capable package.
129
225
 
130
- ### Bumping the pinned protocol release
226
+ ### Bumping the pinned refs
131
227
 
132
- 1. Edit `oikosCoreTag` in `package.json` to the new tag (e.g. `v0.2`).
133
- 2. Bump the npm `version` in `package.json` to match.
134
- 3. `npm run build` — re-fetches from the new ref and re-bundles.
228
+ 1. Edit `oikosCoreTag` and/or `oikosCoreAbiRef` in `package.json`.
229
+ 2. Bump the npm `version` in `package.json` accordingly.
230
+ 3. `npm run build` — re-fetches from both refs and re-bundles.
135
231
  4. `npm publish --access public`.
136
232
 
137
- Or as a one-off without changing the default:
233
+ Or as a one-off without changing the defaults:
138
234
 
139
235
  ```sh
140
236
  OIKOS_CORE_TAG=v0.2 npm run build
237
+ OIKOS_CORE_ABI_REF=<commit-or-tag> npm run build
141
238
  ```
142
239
 
143
240
  ## Development
144
241
 
145
242
  ```sh
146
243
  npm install
147
- npm run fetch-deployment # writes data/deployment.json + data/meta.json
244
+ npm run fetch # both feeds: deployment.json + ABIs
245
+ npm run fetch-deployment # addresses only → data/deployment.json + data/meta.json
246
+ npm run fetch-abis # ABIs only → data/abi/*.json + data/abi-meta.json
148
247
  npm run build # tsup → dist/{index,cli}.{js,cjs,d.ts,d.cts}
149
248
  npm test # node:test against the built bundle
150
249
  npm run typecheck # tsc --noEmit