@flaunch/sdk 0.6.0 → 0.7.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.
package/README.md CHANGED
@@ -38,19 +38,19 @@ _Note: Add this `llms-full.txt` file into Cursor IDE / LLMs to provide context a
38
38
  Using pnpm (recommended):
39
39
 
40
40
  ```bash
41
- pnpm add @flaunch/sdk @delvtech/drift
41
+ pnpm add @flaunch/sdk
42
42
  ```
43
43
 
44
44
  Using npm:
45
45
 
46
46
  ```bash
47
- npm install @flaunch/sdk @delvtech/drift
47
+ npm install @flaunch/sdk
48
48
  ```
49
49
 
50
50
  Using yarn:
51
51
 
52
52
  ```bash
53
- yarn add @flaunch/sdk @delvtech/drift
53
+ yarn add @flaunch/sdk
54
54
  ```
55
55
 
56
56
  ## Quick Start
@@ -58,9 +58,8 @@ yarn add @flaunch/sdk @delvtech/drift
58
58
  Here's a simple example to get started with reading token metadata:
59
59
 
60
60
  ```ts
61
- import { ReadFlaunchSDK } from "@flaunch/sdk";
62
- import { createDrift } from "@delvtech/drift";
63
- import { viemAdapter } from "@delvtech/drift-viem";
61
+ import { createFlaunch } from "@flaunch/sdk";
62
+ import { createPublicClient, http } from "viem";
64
63
  import { base } from "viem/chains";
65
64
 
66
65
  const publicClient = createPublicClient({
@@ -68,48 +67,31 @@ const publicClient = createPublicClient({
68
67
  transport: http(),
69
68
  });
70
69
 
71
- const drift = createDrift({
72
- adapter: viemAdapter({ publicClient }),
73
- });
74
-
75
- const flaunchRead = new ReadFlaunchSDK(base.id, drift);
70
+ const flaunchRead = createFlaunch({ publicClient });
76
71
  const { symbol, name, image } = await flaunchRead.getCoinMetadata(coinAddress);
77
72
  // returns: {symbol: "TEST", name: "Test", image: "https://<IMAGE_URL>"}
78
73
  ```
79
74
 
80
75
  ## Usage
81
76
 
82
- The SDK has 2 exports:
77
+ The SDK provides two types of operations:
83
78
 
84
- 1. `ReadFlaunchSDK`: public read only operations
85
- 2. `ReadWriteFlaunchSDK`: read and write operations (extends `ReadFlaunchSDK`)
79
+ 1. Read operations: Only require a `publicClient`
80
+ 2. Write operations: Require both `publicClient` and `walletClient`
86
81
 
87
82
  ### Read Operations (with Viem)
88
83
 
89
- 1. First, install the Viem adapter:
90
-
91
- ```bash
92
- pnpm add @delvtech/drift-viem
93
- ```
94
-
95
- 2. Initialize the SDK for read operations:
96
-
97
84
  ```ts
98
- import { ReadFlaunchSDK } from "@flaunch/sdk";
99
- import { createDrift } from "@delvtech/drift";
100
- import { viemAdapter } from "@delvtech/drift-viem";
101
- import { base, baseSepolia } from "viem/chains";
85
+ import { createFlaunch } from "@flaunch/sdk";
86
+ import { createPublicClient, http } from "viem";
87
+ import { base } from "viem/chains";
102
88
 
103
89
  const publicClient = createPublicClient({
104
90
  chain: base,
105
91
  transport: http("<RPC_URL>"), // "<RPC_URL>" is optional, defaults to public RPC
106
92
  });
107
93
 
108
- const drift = createDrift({
109
- adapter: viemAdapter({ publicClient }),
110
- });
111
-
112
- const flaunchRead = new ReadFlaunchSDK(base.id, drift);
94
+ const flaunchRead = createFlaunch({ publicClient });
113
95
 
114
96
  // Read token metadata
115
97
  const { symbol, name, image } = await flaunchRead.getCoinMetadata(coinAddress);
@@ -121,25 +103,27 @@ const { symbol, name, image } = await flaunchRead.getCoinMetadata(coinAddress);
121
103
  For write operations, you'll need both Viem and Wagmi. Here's how to set it up in a React component:
122
104
 
123
105
  ```ts
124
- import { ReadWriteFlaunchSDK } from "@flaunch/sdk";
125
- import { createDrift } from "@delvtech/drift";
126
- import { viemAdapter } from "@delvtech/drift-viem";
106
+ import { createFlaunch } from "@flaunch/sdk";
127
107
  import { base } from "viem/chains";
128
108
  import { useWalletClient } from "wagmi";
129
109
  import { useMemo } from "react";
130
110
 
131
111
  // ... your React component ...
132
112
 
113
+ const publicClient = createPublicClient({
114
+ chain: base,
115
+ transport: http("<RPC_URL>"), // "<RPC_URL>" is optional, defaults to public RPC
116
+ });
133
117
  const { data: walletClient } = useWalletClient();
134
118
 
135
119
  const flaunchWrite = useMemo(() => {
136
- if (walletClient) {
137
- const drift = createDrift({
138
- adapter: viemAdapter({ publicClient, walletClient }),
139
- });
140
- return new ReadWriteFlaunchSDK(base.id, drift);
141
- }
142
- }, [walletClient]);
120
+ if (!publicClient && !walletClient) return null;
121
+
122
+ return createFlaunch({
123
+ publicClient,
124
+ walletClient,
125
+ }) as ReadWriteFlaunchSDK;
126
+ }, [publicClient, walletClient]);
143
127
 
144
128
  // Execute a buy transaction
145
129
  const buyTokens = async () => {
package/dist/index.cjs.js CHANGED
@@ -6,6 +6,7 @@ var drift = require('@delvtech/drift');
6
6
  var viem = require('viem');
7
7
  var axios = require('axios');
8
8
  var v3Sdk = require('@uniswap/v3-sdk');
9
+ var driftViem = require('@delvtech/drift-viem');
9
10
 
10
11
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
12
 
@@ -18958,6 +18959,28 @@ class ReadWriteFlaunchSDK extends ReadFlaunchSDK {
18958
18959
  }
18959
18960
  }
18960
18961
 
18962
+ /**
18963
+ * Creates a Flaunch SDK instance with the provided clients
18964
+ * @param params - Parameters for creating the SDK
18965
+ * @returns ReadFlaunchSDK if only publicClient is provided, ReadWriteFlaunchSDK if walletClient is also provided
18966
+ * @throws Error if publicClient.chain is not configured
18967
+ */
18968
+ function createFlaunch(params) {
18969
+ const { publicClient, walletClient } = params;
18970
+ if (!publicClient.chain) {
18971
+ throw new Error("publicClient must be configured with a chain");
18972
+ }
18973
+ const chainId = publicClient.chain.id;
18974
+ // Return appropriate SDK type based on whether walletClient is provided
18975
+ return walletClient
18976
+ ? new ReadWriteFlaunchSDK(chainId, drift.createDrift({
18977
+ adapter: driftViem.viemAdapter({ publicClient, walletClient }),
18978
+ }))
18979
+ : new ReadFlaunchSDK(chainId, drift.createDrift({
18980
+ adapter: driftViem.viemAdapter({ publicClient }),
18981
+ }));
18982
+ }
18983
+
18961
18984
  const FlaunchSDK = {
18962
18985
  ReadFlaunchSDK,
18963
18986
  ReadWriteFlaunchSDK,
@@ -18996,6 +19019,7 @@ exports.UniversalRouterAddress = UniversalRouterAddress;
18996
19019
  exports.bytes32ToUint256 = bytes32ToUint256;
18997
19020
  exports.calculateUnderlyingTokenBalances = calculateUnderlyingTokenBalances;
18998
19021
  exports.chainIdToChain = chainIdToChain;
19022
+ exports.createFlaunch = createFlaunch;
18999
19023
  exports.generateTokenUri = generateTokenUri;
19000
19024
  exports.getPoolId = getPoolId;
19001
19025
  exports.getSqrtPriceX96FromTick = getSqrtPriceX96FromTick;