clanker-sdk 1.0.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 ADDED
@@ -0,0 +1,151 @@
1
+ # Clanker SDK
2
+
3
+ A lightweight TypeScript SDK for interacting with the Clanker API. This SDK provides a simple interface for token deployment, fee estimation, and reward tracking.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install clanker-sdk
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { ClankerSDK } from 'clanker-sdk';
15
+
16
+ // Initialize the SDK with your API key
17
+ const clanker = new ClankerSDK('your_api_key_here');
18
+
19
+ // Deploy a new token
20
+ const newToken = await clanker.deployToken({
21
+ name: "My Token",
22
+ symbol: "MTK",
23
+ image: "https://example.com/token-image.png",
24
+ requestorAddress: "0x1234567890abcdef1234567890abcdef12345678",
25
+ });
26
+ ```
27
+
28
+ ## Features
29
+
30
+ - 🚀 Deploy tokens with ease
31
+ - 💰 Track uncollected fees and rewards
32
+ - 🔄 Manage token splits
33
+ - 📊 Query deployed tokens and pool information
34
+
35
+ ## Examples
36
+
37
+ The SDK comes with several example scripts demonstrating common use cases:
38
+
39
+ ### Token Deployment
40
+ ```bash
41
+ # Run the token deployment example
42
+ npm run example:deploy
43
+ ```
44
+
45
+ ### Rewards and Fees
46
+ ```bash
47
+ # Run the rewards and fees example
48
+ npm run example:rewards
49
+ ```
50
+
51
+ Check out the `examples` directory for the complete source code of these examples.
52
+
53
+ ## API Reference
54
+
55
+ ### `deployToken(options)`
56
+ Deploy a new token with basic configuration.
57
+
58
+ ```typescript
59
+ const token = await clanker.deployToken({
60
+ name: "Community Token",
61
+ symbol: "CMTY",
62
+ image: "https://example.com/token.png",
63
+ requestorAddress: "0x...",
64
+ });
65
+ ```
66
+
67
+ ### `deployTokenWithSplits(options)`
68
+ Deploy a token with custom split configuration.
69
+
70
+ ```typescript
71
+ const token = await clanker.deployTokenWithSplits({
72
+ name: "Creator Token",
73
+ symbol: "CRTR",
74
+ image: "https://example.com/token.png",
75
+ requestorAddress: "0x...",
76
+ splitAddress: "0x...",
77
+ });
78
+ ```
79
+
80
+ ### `getEstimatedUncollectedFees(contractAddress)`
81
+ Get estimated uncollected fees for a contract.
82
+
83
+ ```typescript
84
+ const fees = await clanker.getEstimatedUncollectedFees("0x...");
85
+ ```
86
+
87
+ ### `fetchDeployedByAddress(address, page?)`
88
+ Fetch all tokens deployed by a specific address.
89
+
90
+ ```typescript
91
+ const tokens = await clanker.fetchDeployedByAddress("0x...");
92
+ ```
93
+
94
+ ### `getEstimatedRewardsByPoolAddress(poolAddress)`
95
+ Get estimated rewards for a specific pool.
96
+
97
+ ```typescript
98
+ const rewards = await clanker.getEstimatedRewardsByPoolAddress("0x...");
99
+ ```
100
+
101
+ ### `getClankerByAddress(address)`
102
+ Fetch details about a specific Clanker by contract address.
103
+
104
+ ```typescript
105
+ const clanker = await clanker.getClankerByAddress("0x...");
106
+ ```
107
+
108
+ ## Development
109
+
110
+ 1. Clone the repository
111
+ 2. Install dependencies:
112
+ ```bash
113
+ npm install
114
+ ```
115
+ 3. Build the SDK:
116
+ ```bash
117
+ npm run build
118
+ ```
119
+ 4. Run tests:
120
+ ```bash
121
+ npm test
122
+ ```
123
+ 5. Run examples:
124
+ ```bash
125
+ # Set your API key
126
+ export CLANKER_API_KEY=your_api_key_here
127
+
128
+ # Run examples
129
+ npm run example:deploy
130
+ npm run example:rewards
131
+ ```
132
+
133
+ ## Error Handling
134
+
135
+ The SDK includes built-in error handling and validation:
136
+
137
+ ```typescript
138
+ try {
139
+ await clanker.deployToken({...});
140
+ } catch (error) {
141
+ if (error instanceof ClankerError) {
142
+ console.error('API Error:', error.message);
143
+ console.error('Status:', error.status);
144
+ console.error('Code:', error.code);
145
+ }
146
+ }
147
+ ```
148
+
149
+ ## License
150
+
151
+ ISC
@@ -0,0 +1,70 @@
1
+ interface Token {
2
+ chainId: number;
3
+ address: string;
4
+ symbol: string;
5
+ decimals: number;
6
+ name: string;
7
+ }
8
+ interface DeployTokenOptions {
9
+ name: string;
10
+ symbol: string;
11
+ image: string;
12
+ requestorAddress: string;
13
+ requestKey?: string;
14
+ }
15
+ interface DeployTokenWithSplitsOptions extends DeployTokenOptions {
16
+ splitAddress: string;
17
+ }
18
+ interface UncollectedFeesResponse {
19
+ lockerAddress: string;
20
+ lpNftId: number;
21
+ token0UncollectedRewards: string;
22
+ token1UncollectedRewards: string;
23
+ token0: Token;
24
+ token1: Token;
25
+ }
26
+ interface DeployedToken {
27
+ id: number;
28
+ created_at: string;
29
+ tx_hash: string;
30
+ requestor_fid: number;
31
+ contract_address: string;
32
+ name: string;
33
+ symbol: string;
34
+ img_url: string | null;
35
+ pool_address: string;
36
+ cast_hash: string;
37
+ type: string;
38
+ pair: string;
39
+ }
40
+ interface DeployedTokensResponse {
41
+ data: DeployedToken[];
42
+ hasMore: boolean;
43
+ total: number;
44
+ }
45
+ interface EstimatedRewardsResponse {
46
+ userRewards: number;
47
+ }
48
+ declare class ClankerError extends Error {
49
+ readonly code?: string | undefined;
50
+ readonly status?: number | undefined;
51
+ readonly details?: any | undefined;
52
+ constructor(message: string, code?: string | undefined, status?: number | undefined, details?: any | undefined);
53
+ }
54
+
55
+ declare class ClankerSDK {
56
+ private readonly api;
57
+ private readonly baseURL;
58
+ constructor(apiKey: string);
59
+ getEstimatedUncollectedFees(contractAddress: string): Promise<UncollectedFeesResponse>;
60
+ deployToken(options: DeployTokenOptions): Promise<DeployedToken>;
61
+ deployTokenWithSplits(options: DeployTokenWithSplitsOptions): Promise<DeployedToken>;
62
+ fetchDeployedByAddress(address: string, page?: number): Promise<DeployedTokensResponse>;
63
+ getEstimatedRewardsByPoolAddress(poolAddress: string): Promise<EstimatedRewardsResponse>;
64
+ getClankerByAddress(address: string): Promise<DeployedToken>;
65
+ private generateRequestKey;
66
+ private isValidAddress;
67
+ private validateDeployOptions;
68
+ }
69
+
70
+ export { ClankerError, ClankerSDK, type DeployTokenOptions, type DeployTokenWithSplitsOptions, type DeployedToken, type DeployedTokensResponse, type EstimatedRewardsResponse, type Token, type UncollectedFeesResponse, ClankerSDK as default };
@@ -0,0 +1,70 @@
1
+ interface Token {
2
+ chainId: number;
3
+ address: string;
4
+ symbol: string;
5
+ decimals: number;
6
+ name: string;
7
+ }
8
+ interface DeployTokenOptions {
9
+ name: string;
10
+ symbol: string;
11
+ image: string;
12
+ requestorAddress: string;
13
+ requestKey?: string;
14
+ }
15
+ interface DeployTokenWithSplitsOptions extends DeployTokenOptions {
16
+ splitAddress: string;
17
+ }
18
+ interface UncollectedFeesResponse {
19
+ lockerAddress: string;
20
+ lpNftId: number;
21
+ token0UncollectedRewards: string;
22
+ token1UncollectedRewards: string;
23
+ token0: Token;
24
+ token1: Token;
25
+ }
26
+ interface DeployedToken {
27
+ id: number;
28
+ created_at: string;
29
+ tx_hash: string;
30
+ requestor_fid: number;
31
+ contract_address: string;
32
+ name: string;
33
+ symbol: string;
34
+ img_url: string | null;
35
+ pool_address: string;
36
+ cast_hash: string;
37
+ type: string;
38
+ pair: string;
39
+ }
40
+ interface DeployedTokensResponse {
41
+ data: DeployedToken[];
42
+ hasMore: boolean;
43
+ total: number;
44
+ }
45
+ interface EstimatedRewardsResponse {
46
+ userRewards: number;
47
+ }
48
+ declare class ClankerError extends Error {
49
+ readonly code?: string | undefined;
50
+ readonly status?: number | undefined;
51
+ readonly details?: any | undefined;
52
+ constructor(message: string, code?: string | undefined, status?: number | undefined, details?: any | undefined);
53
+ }
54
+
55
+ declare class ClankerSDK {
56
+ private readonly api;
57
+ private readonly baseURL;
58
+ constructor(apiKey: string);
59
+ getEstimatedUncollectedFees(contractAddress: string): Promise<UncollectedFeesResponse>;
60
+ deployToken(options: DeployTokenOptions): Promise<DeployedToken>;
61
+ deployTokenWithSplits(options: DeployTokenWithSplitsOptions): Promise<DeployedToken>;
62
+ fetchDeployedByAddress(address: string, page?: number): Promise<DeployedTokensResponse>;
63
+ getEstimatedRewardsByPoolAddress(poolAddress: string): Promise<EstimatedRewardsResponse>;
64
+ getClankerByAddress(address: string): Promise<DeployedToken>;
65
+ private generateRequestKey;
66
+ private isValidAddress;
67
+ private validateDeployOptions;
68
+ }
69
+
70
+ export { ClankerError, ClankerSDK, type DeployTokenOptions, type DeployTokenWithSplitsOptions, type DeployedToken, type DeployedTokensResponse, type EstimatedRewardsResponse, type Token, type UncollectedFeesResponse, ClankerSDK as default };
package/dist/index.js ADDED
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ ClankerError: () => ClankerError,
34
+ ClankerSDK: () => ClankerSDK,
35
+ default: () => ClankerSDK
36
+ });
37
+ module.exports = __toCommonJS(index_exports);
38
+
39
+ // src/ClankerSDK.ts
40
+ var import_axios = __toESM(require("axios"));
41
+
42
+ // src/types.ts
43
+ var ClankerError = class extends Error {
44
+ constructor(message, code, status, details) {
45
+ super(message);
46
+ this.code = code;
47
+ this.status = status;
48
+ this.details = details;
49
+ this.name = "ClankerError";
50
+ }
51
+ };
52
+
53
+ // src/ClankerSDK.ts
54
+ var ClankerSDK = class {
55
+ constructor(apiKey) {
56
+ this.baseURL = "https://www.clanker.world/api";
57
+ if (!apiKey) {
58
+ throw new ClankerError("API key is required");
59
+ }
60
+ this.api = import_axios.default.create({
61
+ baseURL: this.baseURL,
62
+ headers: {
63
+ "x-api-key": apiKey,
64
+ "Content-Type": "application/json"
65
+ }
66
+ });
67
+ this.api.interceptors.response.use(
68
+ (response) => response,
69
+ (error) => {
70
+ if (error.response) {
71
+ throw new ClankerError(
72
+ error.response.data?.message || "API request failed",
73
+ error.response.data?.code,
74
+ error.response.status,
75
+ error.response.data
76
+ );
77
+ }
78
+ throw new ClankerError("Network error occurred");
79
+ }
80
+ );
81
+ }
82
+ // Get estimated uncollected fees
83
+ async getEstimatedUncollectedFees(contractAddress) {
84
+ if (!this.isValidAddress(contractAddress)) {
85
+ throw new ClankerError("Invalid contract address format");
86
+ }
87
+ const response = await this.api.get(`/get-estimated-uncollected-fees/${contractAddress}`);
88
+ return response.data;
89
+ }
90
+ // Deploy a new token
91
+ async deployToken(options) {
92
+ this.validateDeployOptions(options);
93
+ const requestKey = options.requestKey || this.generateRequestKey();
94
+ const response = await this.api.post("/tokens/deploy", {
95
+ ...options,
96
+ requestKey
97
+ });
98
+ return response.data;
99
+ }
100
+ // Deploy token with splits
101
+ async deployTokenWithSplits(options) {
102
+ this.validateDeployOptions(options);
103
+ if (!this.isValidAddress(options.splitAddress)) {
104
+ throw new ClankerError("Invalid split address format");
105
+ }
106
+ const requestKey = options.requestKey || this.generateRequestKey();
107
+ const response = await this.api.post("/tokens/deploy/with-splits", {
108
+ ...options,
109
+ requestKey
110
+ });
111
+ return response.data;
112
+ }
113
+ // Fetch clankers deployed by address
114
+ async fetchDeployedByAddress(address, page = 1) {
115
+ if (!this.isValidAddress(address)) {
116
+ throw new ClankerError("Invalid address format");
117
+ }
118
+ if (page < 1) {
119
+ throw new ClankerError("Page number must be greater than 0");
120
+ }
121
+ const response = await this.api.get(`/tokens/fetch-deployed-by-address`, {
122
+ params: { address, page }
123
+ });
124
+ return response.data;
125
+ }
126
+ // Get estimated rewards by pool address
127
+ async getEstimatedRewardsByPoolAddress(poolAddress) {
128
+ if (!this.isValidAddress(poolAddress)) {
129
+ throw new ClankerError("Invalid pool address format");
130
+ }
131
+ const response = await this.api.get(`/tokens/estimate-rewards-by-pool-address`, {
132
+ params: { poolAddress }
133
+ });
134
+ return response.data;
135
+ }
136
+ // Fetch clanker by contract address
137
+ async getClankerByAddress(address) {
138
+ if (!this.isValidAddress(address)) {
139
+ throw new ClankerError("Invalid address format");
140
+ }
141
+ const response = await this.api.get(`/get-clanker-by-address`, {
142
+ params: { address }
143
+ });
144
+ return response.data;
145
+ }
146
+ // Utility function to generate request key
147
+ generateRequestKey() {
148
+ return Array.from(crypto.getRandomValues(new Uint8Array(16))).map((b) => b.toString(16).padStart(2, "0")).join("");
149
+ }
150
+ // Validation utilities
151
+ isValidAddress(address) {
152
+ return /^0x[a-fA-F0-9]{40}$/.test(address);
153
+ }
154
+ validateDeployOptions(options) {
155
+ if (!options.name || options.name.length < 1) {
156
+ throw new ClankerError("Token name is required");
157
+ }
158
+ if (!options.symbol || options.symbol.length < 1) {
159
+ throw new ClankerError("Token symbol is required");
160
+ }
161
+ if (!this.isValidAddress(options.requestorAddress)) {
162
+ throw new ClankerError("Invalid requestor address format");
163
+ }
164
+ if (options.requestKey && options.requestKey.length !== 32) {
165
+ throw new ClankerError("Request key must be 32 characters long");
166
+ }
167
+ }
168
+ };
169
+ // Annotate the CommonJS export names for ESM import in node:
170
+ 0 && (module.exports = {
171
+ ClankerError,
172
+ ClankerSDK
173
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,135 @@
1
+ // src/ClankerSDK.ts
2
+ import axios from "axios";
3
+
4
+ // src/types.ts
5
+ var ClankerError = class extends Error {
6
+ constructor(message, code, status, details) {
7
+ super(message);
8
+ this.code = code;
9
+ this.status = status;
10
+ this.details = details;
11
+ this.name = "ClankerError";
12
+ }
13
+ };
14
+
15
+ // src/ClankerSDK.ts
16
+ var ClankerSDK = class {
17
+ constructor(apiKey) {
18
+ this.baseURL = "https://www.clanker.world/api";
19
+ if (!apiKey) {
20
+ throw new ClankerError("API key is required");
21
+ }
22
+ this.api = axios.create({
23
+ baseURL: this.baseURL,
24
+ headers: {
25
+ "x-api-key": apiKey,
26
+ "Content-Type": "application/json"
27
+ }
28
+ });
29
+ this.api.interceptors.response.use(
30
+ (response) => response,
31
+ (error) => {
32
+ if (error.response) {
33
+ throw new ClankerError(
34
+ error.response.data?.message || "API request failed",
35
+ error.response.data?.code,
36
+ error.response.status,
37
+ error.response.data
38
+ );
39
+ }
40
+ throw new ClankerError("Network error occurred");
41
+ }
42
+ );
43
+ }
44
+ // Get estimated uncollected fees
45
+ async getEstimatedUncollectedFees(contractAddress) {
46
+ if (!this.isValidAddress(contractAddress)) {
47
+ throw new ClankerError("Invalid contract address format");
48
+ }
49
+ const response = await this.api.get(`/get-estimated-uncollected-fees/${contractAddress}`);
50
+ return response.data;
51
+ }
52
+ // Deploy a new token
53
+ async deployToken(options) {
54
+ this.validateDeployOptions(options);
55
+ const requestKey = options.requestKey || this.generateRequestKey();
56
+ const response = await this.api.post("/tokens/deploy", {
57
+ ...options,
58
+ requestKey
59
+ });
60
+ return response.data;
61
+ }
62
+ // Deploy token with splits
63
+ async deployTokenWithSplits(options) {
64
+ this.validateDeployOptions(options);
65
+ if (!this.isValidAddress(options.splitAddress)) {
66
+ throw new ClankerError("Invalid split address format");
67
+ }
68
+ const requestKey = options.requestKey || this.generateRequestKey();
69
+ const response = await this.api.post("/tokens/deploy/with-splits", {
70
+ ...options,
71
+ requestKey
72
+ });
73
+ return response.data;
74
+ }
75
+ // Fetch clankers deployed by address
76
+ async fetchDeployedByAddress(address, page = 1) {
77
+ if (!this.isValidAddress(address)) {
78
+ throw new ClankerError("Invalid address format");
79
+ }
80
+ if (page < 1) {
81
+ throw new ClankerError("Page number must be greater than 0");
82
+ }
83
+ const response = await this.api.get(`/tokens/fetch-deployed-by-address`, {
84
+ params: { address, page }
85
+ });
86
+ return response.data;
87
+ }
88
+ // Get estimated rewards by pool address
89
+ async getEstimatedRewardsByPoolAddress(poolAddress) {
90
+ if (!this.isValidAddress(poolAddress)) {
91
+ throw new ClankerError("Invalid pool address format");
92
+ }
93
+ const response = await this.api.get(`/tokens/estimate-rewards-by-pool-address`, {
94
+ params: { poolAddress }
95
+ });
96
+ return response.data;
97
+ }
98
+ // Fetch clanker by contract address
99
+ async getClankerByAddress(address) {
100
+ if (!this.isValidAddress(address)) {
101
+ throw new ClankerError("Invalid address format");
102
+ }
103
+ const response = await this.api.get(`/get-clanker-by-address`, {
104
+ params: { address }
105
+ });
106
+ return response.data;
107
+ }
108
+ // Utility function to generate request key
109
+ generateRequestKey() {
110
+ return Array.from(crypto.getRandomValues(new Uint8Array(16))).map((b) => b.toString(16).padStart(2, "0")).join("");
111
+ }
112
+ // Validation utilities
113
+ isValidAddress(address) {
114
+ return /^0x[a-fA-F0-9]{40}$/.test(address);
115
+ }
116
+ validateDeployOptions(options) {
117
+ if (!options.name || options.name.length < 1) {
118
+ throw new ClankerError("Token name is required");
119
+ }
120
+ if (!options.symbol || options.symbol.length < 1) {
121
+ throw new ClankerError("Token symbol is required");
122
+ }
123
+ if (!this.isValidAddress(options.requestorAddress)) {
124
+ throw new ClankerError("Invalid requestor address format");
125
+ }
126
+ if (options.requestKey && options.requestKey.length !== 32) {
127
+ throw new ClankerError("Request key must be 32 characters long");
128
+ }
129
+ }
130
+ };
131
+ export {
132
+ ClankerError,
133
+ ClankerSDK,
134
+ ClankerSDK as default
135
+ };
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "clanker-sdk",
3
+ "version": "1.0.0",
4
+ "description": "A lightweight TypeScript SDK for interacting with the Clanker API",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist",
10
+ "README.md"
11
+ ],
12
+ "scripts": {
13
+ "build": "tsup src/index.ts --format cjs,esm --dts",
14
+ "test": "jest",
15
+ "lint": "eslint src --ext .ts",
16
+ "format": "prettier --write \"src/**/*.ts\"",
17
+ "prepare": "npm run build",
18
+ "example:deploy": "ts-node examples/token-deployment.ts",
19
+ "example:rewards": "ts-node examples/rewards-and-fees.ts",
20
+ "example": "npm run example:deploy && npm run example:rewards"
21
+ },
22
+ "publishConfig": {
23
+ "access": "public",
24
+ "registry": "https://registry.npmjs.org/"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/clanker-devco/sdk"
29
+ },
30
+ "keywords": [
31
+ "clanker",
32
+ "api",
33
+ "sdk",
34
+ "typescript",
35
+ "blockchain",
36
+ "tokens",
37
+ "web3"
38
+ ],
39
+ "author": "Clanker Team",
40
+ "license": "ISC",
41
+ "dependencies": {
42
+ "axios": "^1.6.7"
43
+ },
44
+ "devDependencies": {
45
+ "@types/jest": "^29.5.12",
46
+ "@types/node": "^20.11.19",
47
+ "@typescript-eslint/eslint-plugin": "^7.0.1",
48
+ "@typescript-eslint/parser": "^7.0.1",
49
+ "eslint": "^8.56.0",
50
+ "jest": "^29.7.0",
51
+ "prettier": "^3.2.5",
52
+ "ts-jest": "^29.1.2",
53
+ "ts-node": "^10.9.2",
54
+ "tsup": "^8.0.2",
55
+ "typescript": "^5.3.3"
56
+ },
57
+ "engines": {
58
+ "node": ">=14.0.0"
59
+ }
60
+ }