@zoralabs/protocol-sdk 0.10.0 → 0.11.0

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.
Files changed (55) hide show
  1. package/.turbo/turbo-build.log +7 -7
  2. package/CHANGELOG.md +11 -0
  3. package/dist/apis/multicall3.d.ts +1 -1
  4. package/dist/apis/multicall3.d.ts.map +1 -1
  5. package/dist/create/1155-create-helper.test.d.ts +3 -0
  6. package/dist/create/1155-create-helper.test.d.ts.map +1 -0
  7. package/dist/fixtures/contract-setup.d.ts +16 -0
  8. package/dist/fixtures/contract-setup.d.ts.map +1 -0
  9. package/dist/index.cjs +538 -28
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.js +556 -28
  12. package/dist/index.js.map +1 -1
  13. package/dist/sdk.d.ts +4 -0
  14. package/dist/sdk.d.ts.map +1 -1
  15. package/dist/secondary/conversions.d.ts +7 -0
  16. package/dist/secondary/conversions.d.ts.map +1 -0
  17. package/dist/secondary/secondary-client.d.ts +67 -0
  18. package/dist/secondary/secondary-client.d.ts.map +1 -0
  19. package/dist/secondary/slippage.d.ts +25 -0
  20. package/dist/secondary/slippage.d.ts.map +1 -0
  21. package/dist/secondary/types.d.ts +37 -0
  22. package/dist/secondary/types.d.ts.map +1 -0
  23. package/dist/secondary/uniswap/abis.d.ts +152 -0
  24. package/dist/secondary/uniswap/abis.d.ts.map +1 -0
  25. package/dist/secondary/uniswap/uniswapQuote.d.ts +13 -0
  26. package/dist/secondary/uniswap/uniswapQuote.d.ts.map +1 -0
  27. package/dist/secondary/uniswap/uniswapQuoteExact.d.ts +37 -0
  28. package/dist/secondary/uniswap/uniswapQuoteExact.d.ts.map +1 -0
  29. package/dist/secondary/uniswap/uniswapReserves.d.ts +3 -0
  30. package/dist/secondary/uniswap/uniswapReserves.d.ts.map +1 -0
  31. package/dist/secondary/utils.d.ts +10 -0
  32. package/dist/secondary/utils.d.ts.map +1 -0
  33. package/dist/sparks/sparks-contracts.d.ts.map +1 -1
  34. package/dist/types.d.ts +3 -2
  35. package/dist/types.d.ts.map +1 -1
  36. package/dist/utils.d.ts +2 -1
  37. package/dist/utils.d.ts.map +1 -1
  38. package/package.json +1 -1
  39. package/src/apis/multicall3.ts +1 -1
  40. package/src/fixtures/contract-setup.ts +57 -0
  41. package/src/rewards/rewards-client.test.ts +15 -111
  42. package/src/sdk.ts +11 -0
  43. package/src/secondary/conversions.ts +20 -0
  44. package/src/secondary/secondary-client.test.ts +276 -0
  45. package/src/secondary/secondary-client.ts +374 -0
  46. package/src/secondary/slippage.ts +42 -0
  47. package/src/secondary/types.ts +64 -0
  48. package/src/secondary/uniswap/abis.ts +20 -0
  49. package/src/secondary/uniswap/uniswapQuote.ts +134 -0
  50. package/src/secondary/uniswap/uniswapQuoteExact.ts +114 -0
  51. package/src/secondary/uniswap/uniswapReserves.ts +34 -0
  52. package/src/secondary/utils.ts +40 -0
  53. package/src/sparks/sparks-contracts.ts +1 -3
  54. package/src/types.ts +6 -7
  55. package/src/utils.ts +7 -1
@@ -0,0 +1,114 @@
1
+ import { Address } from "viem";
2
+ import {
3
+ mainnet,
4
+ sepolia,
5
+ zora,
6
+ zoraSepolia,
7
+ base,
8
+ baseSepolia,
9
+ optimism,
10
+ arbitrum,
11
+ blast,
12
+ } from "viem/chains";
13
+ import { uniswapQuoterABI } from "./abis";
14
+ import { PublicClient } from "../../utils";
15
+
16
+ const UniswapQuoterAddress: Record<number, Address> = {
17
+ [mainnet.id]: "0x61fFE014bA17989E743c5F6cB21bF9697530B21e",
18
+ [sepolia.id]: "0xEd1f6473345F45b75F8179591dd5bA1888cf2FB3",
19
+ [zora.id]: "0x11867e1b3348F3ce4FcC170BC5af3d23E07E64Df",
20
+ [zoraSepolia.id]: "0xC195976fEF0985886E37036E2DF62bF371E12Df0",
21
+ [base.id]: "0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a",
22
+ [baseSepolia.id]: "0xC5290058841028F1614F3A6F0F5816cAd0df5E27",
23
+ [optimism.id]: "0x61fFE014bA17989E743c5F6cB21bF9697530B21e",
24
+ [arbitrum.id]: "0x61fFE014bA17989E743c5F6cB21bF9697530B21e",
25
+ [blast.id]: "0x6Cdcd65e03c1CEc3730AeeCd45bc140D57A25C77",
26
+ };
27
+
28
+ /**
29
+ * Fetches a quote for buying an exact amount of erc20z from the uniswap pool
30
+ *
31
+ * @param tokenIn - the token to sell (will be weth)
32
+ * @param tokenOut - the token to purchase (will be an erc20z)
33
+ * @param amount - the exact amount of erc20z to purchase
34
+ * @param fee - the fee of the pool
35
+ * @param chainId - the chain id
36
+ */
37
+ export async function quoteExactOutputSingle({
38
+ tokenIn,
39
+ tokenOut,
40
+ amountOut,
41
+ fee,
42
+ chainId,
43
+ client,
44
+ }: {
45
+ tokenIn: Address;
46
+ tokenOut: Address;
47
+ amountOut: bigint;
48
+ fee: number;
49
+ chainId: number;
50
+ client: PublicClient;
51
+ }): Promise<bigint> {
52
+ const quote = await client.simulateContract({
53
+ abi: uniswapQuoterABI,
54
+ address: UniswapQuoterAddress[
55
+ chainId as keyof typeof UniswapQuoterAddress
56
+ ] as Address,
57
+ functionName: "quoteExactOutputSingle",
58
+ args: [
59
+ {
60
+ tokenIn,
61
+ tokenOut,
62
+ amount: amountOut,
63
+ fee,
64
+ sqrtPriceLimitX96: 0n,
65
+ },
66
+ ],
67
+ });
68
+
69
+ return quote.result[0];
70
+ }
71
+
72
+ /**
73
+ * Fetches a quote for selling an exact amount of erc20z to the uniswap pool
74
+ *
75
+ * @param tokenIn - the token to sell (will be erc20z)
76
+ * @param tokenOut - the token to purchase (will be weth)
77
+ * @param amount - the exact amount of erc20z to sell
78
+ * @param fee - the fee of the pool
79
+ * @param chainId - the chain id
80
+ */
81
+ export async function quoteExactInputSingle({
82
+ tokenIn,
83
+ tokenOut,
84
+ amountIn,
85
+ fee,
86
+ chainId,
87
+ client,
88
+ }: {
89
+ tokenIn: Address;
90
+ tokenOut: Address;
91
+ amountIn: bigint;
92
+ fee: number;
93
+ chainId: number;
94
+ client: PublicClient;
95
+ }): Promise<bigint> {
96
+ const quote = await client.simulateContract({
97
+ abi: uniswapQuoterABI,
98
+ address: UniswapQuoterAddress[
99
+ chainId as keyof typeof UniswapQuoterAddress
100
+ ] as Address,
101
+ functionName: "quoteExactInputSingle",
102
+ args: [
103
+ {
104
+ tokenIn,
105
+ tokenOut,
106
+ amountIn,
107
+ fee,
108
+ sqrtPriceLimitX96: 0n,
109
+ },
110
+ ],
111
+ });
112
+
113
+ return quote.result[0];
114
+ }
@@ -0,0 +1,34 @@
1
+ import { createPublicClient, http } from "viem";
2
+ import { mainnet } from "viem/chains";
3
+ import { uniswapV2USDCAbi } from "./abis";
4
+
5
+ const uniswapV2USDCMainnetAddress =
6
+ "0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc";
7
+
8
+ export function getUniswapV2USDCReserves() {
9
+ const mainnetClient = createPublicClient({
10
+ chain: mainnet,
11
+ transport: http(),
12
+ });
13
+ return mainnetClient.readContract({
14
+ address: uniswapV2USDCMainnetAddress,
15
+ abi: uniswapV2USDCAbi,
16
+ functionName: "getReserves",
17
+ });
18
+ }
19
+
20
+ function toEthPriceInUSDC({
21
+ reserve0,
22
+ reserve1,
23
+ }: {
24
+ reserve0: bigint;
25
+ reserve1: bigint;
26
+ }) {
27
+ return Number((reserve0 * BigInt(1e14)) / reserve1) / 1e2;
28
+ }
29
+
30
+ // returns the ETH price in USDC
31
+ export async function getEthPriceInUSDC() {
32
+ const reserves = await getUniswapV2USDCReserves();
33
+ return toEthPriceInUSDC({ reserve0: reserves[0], reserve1: reserves[1] });
34
+ }
@@ -0,0 +1,40 @@
1
+ import { Address } from "viem";
2
+ import { PublicClient } from "src/utils";
3
+ import {
4
+ zoraTimedSaleStrategyABI,
5
+ zoraTimedSaleStrategyAddress,
6
+ } from "@zoralabs/protocol-deployments";
7
+ import { SecondaryInfo } from "./types";
8
+ export async function getSecondaryInfo({
9
+ contract,
10
+ tokenId,
11
+ publicClient,
12
+ chainId,
13
+ }: {
14
+ contract: Address;
15
+ tokenId: bigint;
16
+ publicClient: PublicClient;
17
+ chainId: number;
18
+ }): Promise<SecondaryInfo | undefined> {
19
+ const result = await publicClient.readContract({
20
+ abi: zoraTimedSaleStrategyABI,
21
+ address:
22
+ zoraTimedSaleStrategyAddress[
23
+ chainId as keyof typeof zoraTimedSaleStrategyAddress
24
+ ],
25
+ functionName: "sale",
26
+ args: [contract, tokenId],
27
+ });
28
+
29
+ // if there is no erc20zAddress, we can assume that secondary market has not been configured for this contract and token.
30
+ if (!result.erc20zAddress) {
31
+ return undefined;
32
+ }
33
+
34
+ return {
35
+ erc20z: result.erc20zAddress,
36
+ pool: result.poolAddress,
37
+ secondaryActivated: result.secondaryActivated,
38
+ saleEnd: result.saleEnd === 0n ? undefined : result.saleEnd,
39
+ };
40
+ }
@@ -27,9 +27,7 @@ import {
27
27
  encodeFunctionData,
28
28
  zeroAddress,
29
29
  } from "viem";
30
-
31
- const addressOrAccountAddress = (address: Address | Account) =>
32
- typeof address === "string" ? address : address.address;
30
+ import { addressOrAccountAddress } from "src/utils";
33
31
 
34
32
  /**
35
33
  * Constructs the parameters to mint a MINT with ETH on the ZoraMintsManager based on the price of the currently mintable ETH token.
package/src/types.ts CHANGED
@@ -1,13 +1,12 @@
1
- import {
2
- Account,
3
- Address,
4
- PublicClient,
5
- SimulateContractParameters,
6
- } from "viem";
1
+ import { Account, Address, SimulateContractParameters } from "viem";
2
+ import { PublicClient } from "src/utils";
7
3
 
8
4
  export type GenericTokenIdTypes = number | bigint | string;
9
5
 
10
- export type IPublicClient = Pick<PublicClient, "readContract" | "getBlock">;
6
+ export type IPublicClient = Pick<
7
+ PublicClient,
8
+ "readContract" | "getBlock" | "simulateContract" | "getBalance"
9
+ >;
11
10
 
12
11
  export type SimulateContractParametersWithAccount = SimulateContractParameters<
13
12
  any,
package/src/utils.ts CHANGED
@@ -5,7 +5,10 @@ export const makeContractParameters = (
5
5
  args: SimulateContractParametersWithAccount,
6
6
  ) => args;
7
7
 
8
- export type PublicClient = Pick<BasePublicClient, "readContract" | "getBlock">;
8
+ export type PublicClient = Pick<
9
+ BasePublicClient,
10
+ "readContract" | "getBlock" | "simulateContract" | "getBalance"
11
+ >;
9
12
 
10
13
  export type ClientConfig = {
11
14
  /** The chain that the client is to run on. */
@@ -37,3 +40,6 @@ export function mintRecipientOrAccount({
37
40
  export type Concrete<Type> = {
38
41
  [Property in keyof Type]-?: Type[Property];
39
42
  };
43
+
44
+ export const addressOrAccountAddress = (address: Address | Account) =>
45
+ typeof address === "string" ? address : address.address;