Skip to content

Commit

Permalink
Protocol SDK (#348)
Browse files Browse the repository at this point in the history
* added back build-js task

* Add protocol sdk and minting features (#322)

* Moved premint sdk to protocol sdk

* add protocol sdk and minting features

---------

Co-authored-by: Dan Oved <[email protected]>

---------

Co-authored-by: Iain Nash <[email protected]>
  • Loading branch information
oveddan and iainnash authored Nov 13, 2023
1 parent 06c2fff commit e72e8f5
Show file tree
Hide file tree
Showing 33 changed files with 4,064 additions and 337 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: JS

on:
push:
branches:
- main

concurrency: ${{ github.workflow }}-${{ github.ref }}

jobs:
build_js:
strategy:
fail-fast: true

name: Build js package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install node deps and founry
uses: ./.github/actions/setup_deps

- name: Build js package
run: |
npx turbo run build
- name: Test js package
run: |
npx turbo run test:js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This file is automatically generated by code; do not manually update
// Last updated on 2023-11-09T00:33:12.481Z
// Last updated on 2023-11-02T19:45:49.899Z
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

Expand Down
2 changes: 0 additions & 2 deletions packages/premint-sdk/.env.anvil

This file was deleted.

131 changes: 0 additions & 131 deletions packages/premint-sdk/README.md

This file was deleted.

5 changes: 0 additions & 5 deletions packages/premint-sdk/src/index.ts

This file was deleted.

5 changes: 5 additions & 0 deletions packages/protocol-deployments/package/chainConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ export const chainConfigs = {
MINT_FEE_RECIPIENT: "0xE84DBB2B25F761751231a9D0DAfbdD4dC3aa8252",
PROTOCOL_REWARDS: "0x7777777F279eba3d3Ad8F4E708545291A6fDBA8B",
},
[999999999]: {
FACTORY_OWNER: "0xdae22ce69Afcb7f4bc37D32E267645722949DE0E",
MINT_FEE_RECIPIENT: "0xdae22ce69Afcb7f4bc37D32E267645722949DE0E",
PROTOCOL_REWARDS: "0x7777777F279eba3d3Ad8F4E708545291A6fDBA8B",
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ async function signAndSaveUpgradeGate({
proxyName,
}: {
turnkeyAccount: LocalAccount;
chainConfigs: {
chainId: number; owner: Address
}[];
chainConfigs: {
chainId: number;
owner: Address;
}[];
proxyName: "upgradeGate";
}) {
const configFolder = path.resolve(
Expand Down
File renamed without changes.
163 changes: 163 additions & 0 deletions packages/protocol-sdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
# Premint SDK

Protocol SDK allows users to manage zora mints and collects.

## Installing

[viem](https://viem.sh/) is a peerDependency of protocol-sdk. If not already installed, it needs to be installed alongside the protocol sdk.

- `npm install viem`
- `npm install `

### Creating a mint from an on-chain contract:

```ts
import { MintAPI } from "@zoralabs/protocol-sdk";
import type { Address, WalletClient } from "viem";

async function mintNFT(
walletClient: WalletClient,
address: Address,
tokenId: bigint,
) {
const mintAPI = new MintAPI(walletClient.chain);
await mintAPI.mintNFT({
walletClient,
address,
tokenId,
mintArguments: {
quantityToMint: 23,
mintComment: "Helo",
},
});
}
```

### Creating a premint:

```ts
import { PremintAPI } from "@zoralabs/protocol-sdk";
import type { Address, WalletClient } from "viem";

async function makePremint(walletClient: WalletClient) {
// Create premint API object passing in the current wallet chain (only zora and zora testnet are supported currently).
const premintAPI = new PremintAPI(walletClient.chain);

// Create premint
const premint = await premintAPI.createPremint({
// Extra step to check the signature on-chain before attempting to sign
checkSignature: true,
// Collection information that this premint NFT will exist in once minted.
collection: {
contractAdmin: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
contractName: "Testing Contract",
contractURI:
"ipfs://bafkreiainxen4b4wz4ubylvbhons6rembxdet4a262nf2lziclqvv7au3e",
},
// WalletClient doing the signature
walletClient,
// Token information, falls back to defaults set in DefaultMintArguments.
token: {
tokenURI:
"ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u",
},
});

console.log(`created ZORA premint, link: ${premint.url}`);
return premint;
}
```

### Updating a premint:

```ts
import { PremintAPI } from "@zoralabs/premint-sdk";
import type { Address, WalletClient } from "viem";

async function updatePremint(walletClient: WalletClient) {
// Create premint API object passing in the current wallet chain (only zora and zora testnet are supported currently).
const premintAPI = new PremintAPI(walletClient.chain);

// Create premint
const premint = await premintAPI.updatePremint({
// Extra step to check the signature on-chain before attempting to sign
collection: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
uid: 23,
// WalletClient doing the signature
walletClient,
// Token information, falls back to defaults set in DefaultMintArguments.
token: {
tokenURI:
"ipfs://bafkreice23maski3x52tsfqgxstx3kbiifnt5jotg3a5ynvve53c4soi2u",
},
});

console.log(`updated ZORA premint, link: ${premint.url}`);
return premint;
}
```

### Deleting a premint:

```ts
import { PremintAPI } from "@zoralabs/premint-sdk";
import type { Address, WalletClient } from "viem";

async function deletePremint(walletClient: WalletClient) {
// Create premint API object passing in the current wallet chain (only zora and zora testnet are supported currently).
const premintAPI = new PremintAPI(walletClient.chain);

// Create premint
const premint = await premintAPI.deletePremint({
// Extra step to check the signature on-chain before attempting to sign
collection: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
uid: 23,
// WalletClient doing the signature
walletClient,
});

console.log(`updated ZORA premint, link: ${premint.url}`);
return premint;
}
```

### Executing a premint:

```ts
import { PremintAPI } from "@zoralabs/premint-sdk";
import type { Address, WalletClient } from "viem";

async function executePremint(
walletClient: WalletClient,
premintAddress: Address,
premintUID: number,
) {
const premintAPI = new PremintAPI(walletClient.chain);

return await premintAPI.executePremintWithWallet({
data: premintAPI.getPremintData(premintAddress, premintUID),
walletClient,
mintArguments: {
quantityToMint: 1,
},
});
}
```

### Deleting a premint:

```js
import {PremintAPI} from '@zoralabs/premint-sdk';
import type {Address, WalletClient} from 'viem';

async function deletePremint(walletClient: WalletClient, collection: Address, uid: number) {
const premintAPI = new PremintAPI(walletClient.chain);

return await premintAPI.deletePremint({
walletClient,
uid,
collection
});
}

```
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zoralabs/premint-sdk",
"version": "0.1.1",
"name": "@zoralabs/protocol-sdk",
"version": "0.2.0",
"repository": "https://github.com/ourzora/zora-protocol",
"license": "MIT",
"main": "./dist/index.js",
Expand All @@ -10,8 +10,7 @@
"build": "tsup",
"prepack": "yarn build",
"test:js": "vitest src",
"generate-types": "npx openapi-typescript https://api.zora.co/premint/openapi.json -o src/generated/premint-api-types.ts && npx openapi-typescript https://api.zora.co/discover/openapi.json -o src/generated/discover-api-types.ts",
"anvil": "source .env.anvil && anvil --fork-url $FORK_RPC_URL --fork-block-number $FORK_BLOCK_NUMBER --chain-id 31337"
"generate-types": "npx openapi-typescript https://api.zora.co/premint/openapi.json -o src/generated/premint-api-types.ts && npx openapi-typescript https://api.zora.co/discover/openapi.json -o src/generated/discover-api-types.ts"
},
"dependencies": {
"@zoralabs/protocol-deployments": "*",
Expand Down
Loading

0 comments on commit e72e8f5

Please sign in to comment.