Skip to content
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

Proposal/return all contracts #451

Closed
wants to merge 2 commits into from
Closed

Conversation

Ansonhkg
Copy link
Collaborator

@Ansonhkg Ansonhkg commented May 2, 2024

Description

LitContracts package only supports ethers5 atm., and we are pretty much locked-in to this version and blockchain client. We should just return all the network contract addresses & abis; then, the developers can use whatever clients they want. However, we need to provide documentation on how to use common smart contract features, such as mintNext for PKP, addPermittedAction to add permitted action to a given PKP & IPFS ID, etc.

Usage

const contracts = await LitContracts.getContracts();

// for cayenne contracts
const cayennePkpNftContractAddress = contracts.cayenne.PKPNFT.address;
const cayennePkpNftContractAbi = contracts.cayenne.PKPNFT.abi;

// for manzano contracts
const manzanoRateLimitNftContractAddress = contracts.manzano.RateLimitNFT.address;
const manzanoRateLimitNftContractAbi = contracts.manzano.RateLimitNFT.abi;

// for habanero contracts
const manzanoPkpHelperContractAddress = contracts.manzano.PKPHelper.address;
const manzanoPkpHelperContractAbi = contracts.manzano.PKPHelper.abi;

Interface

export type LitContract = {
  address?: string;
  abi?: any;
  name?: string;
};

type LitContractContext = {
  [index: string]: string | any;

  Allowlist: LitContract;
  LITToken: LitContract;
  Multisender: LitContract;
  PKPHelper: LitContract;
  PKPNFT: LitContract;
  PKPNFTMetadata: LitContract;
  PKPPermissions: LitContract;
  PubkeyRouter: LitContract;
  RateLimitNFT: LitContract;
  Staking: LitContract;
  StakingBalances: LitContract;
};

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Jessy jesty jest

node 'node_modules/.bin/jest' './packages/contracts-sdk/src/lib/contracts-sdk.spec.ts' -c './packages/contracts-sdk/jest.config.ts' -t 'contractsSdk should get all contracts'

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Ansonhkg added 2 commits May 2, 2024 13:28
…whatever blockchain clients you want to interact with them. eg. ethers.js, web3.js, viem, etc. We don't care.
Copy link
Contributor

@MaximusHaximus MaximusHaximus left a comment

Choose a reason for hiding this comment

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

👍 It would be great to allow consumers to find contracts themselves I think 👍

I am curious about why we have a single method that always returns all 3 networks of contracts, though? I think most commonly consumers work within the context of a single network at a time, and everything else in the contracts-sdk is specific to a single network at a time.

Why not make _resolveContractContext a public, static method if we want to expose its behaviour? Then consumers could call it for one or for many networks however they want.


it('should get all contracts', async () => {
// polyfill
const crossFetch = require('cross-fetch');
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not import 'cross-fetch/polyfill'; at top of file?

Comment on lines +587 to +589
await LitContracts._resolveContractContext(LitNetwork.Manzano),
await LitContracts._resolveContractContext(LitNetwork.Habanero),
await LitContracts._resolveContractContext(LitNetwork.Cayenne),
Copy link
Contributor

Choose a reason for hiding this comment

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

This is the equivalent of:

    const val = await LitContracts._resolveContractContext(LitNetwork.Manzano);
    const val2 = await LitContracts._resolveContractContext(LitNetwork.Habanero);
    const val3 = await LitContracts._resolveContractContext(LitNetwork.Cayenne);
    
    const [manzano, habanero, cayenne] = await Promise.all([val, val2, val3]);

    return {
      manzano,
      habanero,
      cayenne
    };

🔪 awaiting each array element here -- promise.all() should receive an array of promises that are running in parallel, but this is awaiting each array element, putting the the un-wrapped values into an array, then passing the array of no-longer-promises into promise.all() instead of passing the promises themselves into `promise.all()...

Copy link
Collaborator Author

@Ansonhkg Ansonhkg May 9, 2024

Choose a reason for hiding this comment

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

Good catch! yea was copy/pasting the original code didn't pay attention to that, but we can discuss if we actually want this. It was a 3am idea that i quickly drafted, so it's not a hard requirement nor tracked in linear.

@Ansonhkg Ansonhkg closed this Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants