Skip to content

Commit

Permalink
add protocol sdk and minting features
Browse files Browse the repository at this point in the history
  • Loading branch information
oveddan committed Nov 10, 2023
1 parent 0830e06 commit fe8b4e4
Show file tree
Hide file tree
Showing 30 changed files with 3,991 additions and 289 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ jobs:
- 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.

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.
202 changes: 117 additions & 85 deletions packages/protocol-sdk/README.md
Original file line number Diff line number Diff line change
@@ -1,115 +1,147 @@
# Premint SDK

Premint SDK allows users to manage zora premints
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:

```js
import {PremintAPI} from '@zoralabs/premint-sdk';
import type {Address, WalletClient} from 'viem';
```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;
// 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:

```js
import {PremintAPI} from '@zoralabs/premint-sdk';
import type {Address, WalletClient} from 'viem';
```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;
// 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:

```js
import {PremintAPI} from '@zoralabs/premint-sdk';
import type {Address, WalletClient} from 'viem';
```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;
// 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:

```js
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,
}
});
```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:
Expand Down
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
84 changes: 84 additions & 0 deletions packages/protocol-sdk/src/anvil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { spawn } from "node:child_process";
import { join } from "path";
import { test } from "vitest";
import {
PublicClient,
TestClient,
WalletClient,
createPublicClient,
createTestClient,
createWalletClient,
http,
} from "viem";
import { foundry } from "viem/chains";

export interface AnvilViemClientsTest {
viemClients: {
walletClient: WalletClient;
publicClient: PublicClient;
testClient: TestClient;
};
}

async function waitForAnvilInit(anvil: any) {
return new Promise((resolve) => {
anvil.stdout.once("data", () => {
resolve(true);
});
});
}

export const anvilTest = test.extend<AnvilViemClientsTest>({
viemClients: async ({task}, use) => {
console.log('setting up clients for ', task.name);
const port = Math.floor(Math.random() * 2000) + 4000;
const anvil = spawn(
"anvil",
[
"--port",
`${port}`,
"--fork-url",
"https://rpc.zora.co/",
"--fork-block-number",
"6133407",
"--chain-id",
"31337",
],
{
cwd: join(__dirname, ".."),
killSignal: "SIGINT",
},
);
const anvilHost = `http://0.0.0.0:${port}`;
await waitForAnvilInit(anvil);

const chain = {
...foundry,
};

const walletClient = createWalletClient({
chain,
transport: http(anvilHost),
});

const testClient = createTestClient({
chain,
mode: "anvil",
transport: http(anvilHost),
});

const publicClient = createPublicClient({
chain,
transport: http(anvilHost),
});

await use({
publicClient,
walletClient,
testClient,
});

// clean up function, called once after all tests run
anvil.kill("SIGINT");
},
});
Loading

0 comments on commit fe8b4e4

Please sign in to comment.