Skip to content

Oak Contracts SDK#71

Open
mahabubAlahi wants to merge 12 commits intodevelopfrom
feat/contract-sdk
Open

Oak Contracts SDK#71
mahabubAlahi wants to merge 12 commits intodevelopfrom
feat/contract-sdk

Conversation

@mahabubAlahi
Copy link

@mahabubAlahi mahabubAlahi commented Mar 6, 2026

Introduces the Oak Contracts SDK (@oaknetwork/contracts): a client for interacting with Oak Network smart contracts (treasuries, campaign info, global params, etc.) with typed APIs, chain support, and structured error handling.

What's included

Package & build

  • Build: Switched to tsup for bundling; added tsup.config.ts.
  • TypeScript: Module resolution set to bundler, target ES2022, and proper module exports in package.json.
  • Structure: Package layout reorganized for clearer public API and exports.

Client & configuration

  • createOakContractsClient in index.ts with:
    • Simple config: chain ID (or chain name) and RPC URL.
    • Full config: extended options for advanced use.
  • Helpers for client setup, chain resolution, and type guards.
  • Chain support: CHAIN_IDS for Celo networks (e.g. CELO_SEPOLIA, ALFAJORES); Celo Sepolia added to chain registry; viem imports updated for current structure.

Contract entities

  • AllOrNothing – all-or-nothing treasury contract.
  • CampaignInfoFactory & CampaignInfo – campaign metadata and factory.
  • GlobalParams – protocol global parameters.
  • ItemRegistry – item registry contract.
  • KeepWhatsRaised – keep-what’s-raised treasury contract.
  • PaymentTreasury – payment treasury with initialize.
  • TreasuryFactory – treasury factory contract.

Types

  • Client types: SimpleOakContractsClientConfig, FullOakContractsClientConfig.
  • Domain types: campaign data, payment structures, treasury configs; protocol types centralized in index.ts to avoid circular deps.

ABIs

  • AllOrNothing / KeepWhatsRaised: cancelTreasury, cancelled, and event name/input updates.
  • CampaignInfo: _cancelCampaign; removed obsolete ownership transfer events.
  • PaymentTreasury: initialize.
  • GlobalParams: ABI cleanup (redundant error-handling params removed).

Error handling

  • Dedicated error classes for AllOrNothing, CampaignInfo, KeepWhatsRaised, ItemRegistry, PaymentTreasury, Shared, and TreasuryFactory.
  • Clearer messages and recovery hints; new error types exported from the package.

Documentation

  • README for @oaknetwork/contracts: installation, quick start, client config, supported chain IDs, and contract usage.

imon-ccp and others added 12 commits March 5, 2026 14:25
- Updated `package.json` to use `tsup` for building and added module exports.
- Changed TypeScript module resolution to `bundler` and updated module target to `ES2022`.
- Introduced `tsup.config.ts` for build configuration.
- Introduced a new constant `CHAIN_IDS` to define common chain IDs for various Celo networks, including CELO_SEPOLIA and ALFAJORES, to facilitate contract client creation.
- Added a new `index.ts` file to define the `createOakContractsClient` function, which supports both simple and full configuration for creating a client instance.
- Included utility functions for client configuration and chain resolution, along with type guards for better type safety.
- The client allows interaction with various contract entities such as global parameters, campaign info, and treasury factories.
- Expanded `client.ts` with new interfaces for campaign data, payment structures, and treasury configurations to improve type safety and clarity.
- Consolidated protocol types in `index.ts` to streamline exports and reduce circular dependencies.
- Introduced `SimpleOakContractsClientConfig` and `FullOakContractsClientConfig` for flexible client configuration options.
- Introduced Celo Sepolia testnet to the chain registry, enhancing support for Celo networks.
- Updated import paths for `defineChain`, `mainnet`, `sepolia`, and `goerli` to use the new structure from the `viem` package.
- Re-exported `CHAIN_IDS` from constants for simplified client configuration.
- Removed the `client.ts` file as part of the restructuring.
- Added multiple new contract entities including `AllOrNothing`, `CampaignInfoFactory`, `CampaignInfo`, `GlobalParams`, `ItemRegistry`, `KeepWhatsRaised`, `PaymentTreasury`, and `TreasuryFactory` to enhance functionality and modularity.
- Updated `index.ts` to export the new contract entities for easier access.
- Improved type safety and clarity in contract interactions by defining specific entity functions for read/write operations.
- Introduced a comprehensive README.md file for the @oaknetwork/contracts package.
- Documented installation instructions, quick start guide, client configuration options, supported chain IDs, and detailed contract functionalities.
- Enhanced clarity and usability for developers interacting with Oak Network smart contracts.
- Enhanced `AllOrNothing` ABI by adding new functions `cancelTreasury` and `cancelled`, and modified event names and input types for better clarity.
- Updated `CampaignInfo` ABI to include the `_cancelCampaign` function and removed outdated ownership transfer events.
- Refined `KeepWhatsRaised` ABI by adding `cancelTreasury` and `cancelled` functions, and corrected event names for consistency.
- Adjusted `PaymentTreasury` ABI to include an `initialize` function for contract setup.
- Cleaned up `GlobalParams` ABI by removing redundant input parameters for error handling functions.
- Updated `getplatformFeePercent` to `getPlatformFeePercent` in both `AllOrNothing` and `KeepWhatsRaised` contracts for consistency and adherence to naming conventions.
- Added multiple error classes for `AllOrNothing`, `CampaignInfo`, `KeepWhatsRaised`, `ItemRegistry`, `PaymentTreasury`, `Shared`, and `TreasuryFactory` to enhance error handling and provide clearer recovery hints.
- Updated `index.ts` to export the new error types for better accessibility across the contracts.
- Improved type safety and clarity in error management for contract interactions.
- Updated `getplatformFeePercent` to `getPlatformFeePercent` in `AllOrNothingTreasuryEntity` and `KeepWhatsRaisedTreasuryEntity` interfaces for consistency and adherence to naming conventions.
@mahabubAlahi mahabubAlahi self-assigned this Mar 6, 2026
@mahabubAlahi mahabubAlahi added the enhancement New feature or request label Mar 6, 2026
@mahabubAlahi mahabubAlahi requested review from adnanhq and imon-ccp March 6, 2026 11:14
@rayedsikder
Copy link
Member

@codex review

@rayedsikder rayedsikder requested a review from devmahmud March 6, 2026 16:33
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b705617608

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +128 to +129
account: privateKey as `0x${string}`,
chain: provider.chain,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Derive wallet account from private key before client creation

The createWallet helper passes the raw private key string as account to createWalletClient, but viem expects an account object (e.g. from privateKeyToAccount) or an address for JSON-RPC signing. With a private key string here, calls that rely on this helper can’t reliably sign transactions locally and may attempt to use the 32-byte key as a sender address, so write operations fail at runtime for the advertised private-key flow.

Useful? React with 👍 / 👎.

"publishConfig": {
"access": "public"
},
"type": "module",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep Jest config loadable after switching package to ESM

Setting "type": "module" makes jest.config.js execute as an ES module, but that config file still uses module.exports; this throws ReferenceError: module is not defined before tests even start (reproducible by running node packages/contracts/jest.config.js). As a result, the package test script is broken in this commit unless the config is migrated to ESM syntax or renamed to .cjs.

Useful? React with 👍 / 👎.

* ALFAJORES is the legacy Celo testnet (44787); use CELO_SEPOLIA for new development.
*/
export const CHAIN_IDS = {
MAINNET: 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should explicitly define the chain name and its type. For example:
CELO_MAINNET, ETHEREUM_MAINNET, CELO_SEPOLIA_TESTNET, ETHEREUM_SEPOLIA_TESTNET.

The type of the chain should be either in prefix or suffix.

Also, CELO_MAINNET: 42220 is not added here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The functions associated with Protocol Admins -- keeping some functions won't harm but critical ones enlistPlatform delistPlatform updateProtocolFeePercent and other functions might be confusing for the general platform devs, as they would never use these. Better to remove them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should have some of the extended functions of Ownable module too. For example minter_role - because its the only way to check (in contract call) the valid treasury address

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should have the general NFT view functions ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants