@coinbase/agentkit 0.9.0 → 0.10.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 +137 -55
- package/dist/action-providers/cdp/cdpApiActionProvider.js +2 -0
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.d.ts +43 -0
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.js +151 -0
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.test.d.ts +1 -0
- package/dist/action-providers/cdp/cdpEvmWalletActionProvider.test.js +242 -0
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.d.ts +42 -0
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.js +132 -0
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.test.d.ts +1 -0
- package/dist/action-providers/cdp/cdpSmartWalletActionProvider.test.js +199 -0
- package/dist/action-providers/cdp/index.d.ts +3 -0
- package/dist/action-providers/cdp/index.js +3 -0
- package/dist/action-providers/cdp/schemas.d.ts +29 -0
- package/dist/action-providers/cdp/schemas.js +32 -1
- package/dist/action-providers/cdp/spendPermissionUtils.d.ts +24 -0
- package/dist/action-providers/cdp/spendPermissionUtils.js +66 -0
- package/dist/action-providers/farcaster/farcasterActionProvider.js +2 -0
- package/dist/action-providers/farcaster/farcasterActionProvider.test.js +55 -0
- package/dist/action-providers/farcaster/schemas.d.ts +13 -0
- package/dist/action-providers/farcaster/schemas.js +6 -0
- package/dist/action-providers/index.d.ts +3 -0
- package/dist/action-providers/index.js +3 -0
- package/dist/action-providers/truemarkets/constants.d.ts +179 -0
- package/dist/action-providers/truemarkets/constants.js +46 -0
- package/dist/action-providers/truemarkets/index.d.ts +1 -0
- package/dist/action-providers/truemarkets/index.js +17 -0
- package/dist/action-providers/truemarkets/schemas.d.ts +21 -0
- package/dist/action-providers/truemarkets/schemas.js +29 -0
- package/dist/action-providers/truemarkets/truemarketsActionProvider.d.ts +51 -0
- package/dist/action-providers/truemarkets/truemarketsActionProvider.js +469 -0
- package/dist/action-providers/truemarkets/truemarketsActionProvider.test.d.ts +1 -0
- package/dist/action-providers/truemarkets/truemarketsActionProvider.test.js +217 -0
- package/dist/action-providers/truemarkets/utils.d.ts +10 -0
- package/dist/action-providers/truemarkets/utils.js +9 -0
- package/dist/action-providers/twitter/schemas.d.ts +16 -0
- package/dist/action-providers/twitter/schemas.js +23 -1
- package/dist/action-providers/twitter/twitterActionProvider.d.ts +8 -1
- package/dist/action-providers/twitter/twitterActionProvider.js +56 -5
- package/dist/action-providers/twitter/twitterActionProvider.test.js +52 -2
- package/dist/action-providers/weth/constants.d.ts +9 -0
- package/dist/action-providers/weth/constants.js +12 -0
- package/dist/action-providers/weth/schemas.d.ts +7 -0
- package/dist/action-providers/weth/schemas.js +7 -1
- package/dist/action-providers/weth/wethActionProvider.d.ts +9 -1
- package/dist/action-providers/weth/wethActionProvider.js +50 -1
- package/dist/action-providers/weth/wethActionProvider.test.js +60 -0
- package/dist/action-providers/zerion/constants.d.ts +1 -0
- package/dist/action-providers/zerion/constants.js +4 -0
- package/dist/action-providers/zerion/index.d.ts +2 -0
- package/dist/action-providers/zerion/index.js +18 -0
- package/dist/action-providers/zerion/schemas.d.ts +11 -0
- package/dist/action-providers/zerion/schemas.js +15 -0
- package/dist/action-providers/zerion/types.d.ts +125 -0
- package/dist/action-providers/zerion/types.js +16 -0
- package/dist/action-providers/zerion/utils.d.ts +3 -0
- package/dist/action-providers/zerion/utils.js +45 -0
- package/dist/action-providers/zerion/zerionActionProvider.d.ts +57 -0
- package/dist/action-providers/zerion/zerionActionProvider.js +159 -0
- package/dist/action-providers/zerion/zerionActionProvider.test.d.ts +1 -0
- package/dist/action-providers/zerion/zerionActionProvider.test.js +213 -0
- package/dist/action-providers/zora/index.d.ts +3 -0
- package/dist/action-providers/zora/index.js +19 -0
- package/dist/action-providers/zora/schemas.d.ts +29 -0
- package/dist/action-providers/zora/schemas.js +31 -0
- package/dist/action-providers/zora/utils.d.ts +28 -0
- package/dist/action-providers/zora/utils.js +200 -0
- package/dist/action-providers/zora/zoraActionProvider.d.ts +36 -0
- package/dist/action-providers/zora/zoraActionProvider.js +151 -0
- package/dist/action-providers/zora/zoraActionProvider.test.d.ts +1 -0
- package/dist/action-providers/zora/zoraActionProvider.test.js +205 -0
- package/dist/wallet-providers/cdpShared.d.ts +4 -0
- package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +8 -1
- package/dist/wallet-providers/cdpSmartWalletProvider.js +23 -11
- package/package.json +3 -2
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const zerionActionProvider_1 = require("./zerionActionProvider");
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
// Mocks for fetch and utils
|
|
6
|
+
global.fetch = jest.fn();
|
|
7
|
+
jest.mock("./utils", () => ({
|
|
8
|
+
formatPortfolioData: jest.fn(() => "formatted portfolio"),
|
|
9
|
+
formatPositionsData: jest.fn(() => "formatted positions"),
|
|
10
|
+
}));
|
|
11
|
+
describe("ZerionActionProvider", () => {
|
|
12
|
+
const mockApiKey = "test-api-key";
|
|
13
|
+
const originalEnv = process.env.ZERION_API_KEY;
|
|
14
|
+
const mockFungiblePositionResponse = {
|
|
15
|
+
links: {
|
|
16
|
+
self: "https://api.zerion.io/v1/wallets/0x42b9df65b219b3dd36ff330a4dd8f327a6ada990/positions/",
|
|
17
|
+
},
|
|
18
|
+
data: [
|
|
19
|
+
{
|
|
20
|
+
type: "positions",
|
|
21
|
+
id: "0x111c47865ade3b172a928df8f990bc7f2a3b9aaa-polygon-asset-none-",
|
|
22
|
+
attributes: {
|
|
23
|
+
parent: "0x111c47865ade3b172a928df8f990bc7f2a3b9aaa-polygon-asset-none-",
|
|
24
|
+
protocol: null,
|
|
25
|
+
pool_address: "0x109830a1aaad605bbf02a9dfa7b0b92ec2fb7daa",
|
|
26
|
+
name: "Asset",
|
|
27
|
+
group_id: "0a771a0064dad468045899032c7fb01a971f973f7dff0a5cdc3ce199f45e94d7",
|
|
28
|
+
position_type: "deposit",
|
|
29
|
+
quantity: {
|
|
30
|
+
int: "12345678",
|
|
31
|
+
decimals: 5,
|
|
32
|
+
float: 123.45678,
|
|
33
|
+
numeric: "123.45678",
|
|
34
|
+
},
|
|
35
|
+
value: 5.384656557642683,
|
|
36
|
+
price: 0.043615722,
|
|
37
|
+
changes: {
|
|
38
|
+
absolute_1d: 0.272309794,
|
|
39
|
+
percent_1d: 5.326512552079021,
|
|
40
|
+
},
|
|
41
|
+
fungible_info: {
|
|
42
|
+
name: "Bankless BED Index",
|
|
43
|
+
symbol: "BED",
|
|
44
|
+
description: "The BED index is meant to track crypto’s top 3 investab...",
|
|
45
|
+
icon: {
|
|
46
|
+
url: "https://token-icons.s3.amazonaws.com/0x0391d2021f89dc339f60fff84546ea23e337750f.png",
|
|
47
|
+
},
|
|
48
|
+
flags: {
|
|
49
|
+
verified: true,
|
|
50
|
+
},
|
|
51
|
+
implementations: [
|
|
52
|
+
{
|
|
53
|
+
chain_id: "ethereum",
|
|
54
|
+
address: "0x2af1df3ab0ab157e1e2ad8f88a7d04fbea0c7dc6",
|
|
55
|
+
decimals: 18,
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
flags: {
|
|
60
|
+
displayable: true,
|
|
61
|
+
is_trash: true,
|
|
62
|
+
},
|
|
63
|
+
updated_at: "2023-11-10T23:00:00Z",
|
|
64
|
+
updated_at_block: 0,
|
|
65
|
+
application_metadata: {
|
|
66
|
+
name: "AAVE",
|
|
67
|
+
icon: {
|
|
68
|
+
url: "https://token-icons.s3.amazonaws.com/0x0391d2021f89dc339f60fff84546ea23e337750f.png",
|
|
69
|
+
},
|
|
70
|
+
url: "https://app.aave.com/",
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
relationships: {
|
|
74
|
+
chain: {
|
|
75
|
+
links: {
|
|
76
|
+
related: "https://api.zerion.io/v1/chains/polygon",
|
|
77
|
+
},
|
|
78
|
+
data: {
|
|
79
|
+
type: "chains",
|
|
80
|
+
id: "polygon",
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
fungible: {
|
|
84
|
+
links: {
|
|
85
|
+
related: "https://api.zerion.io/v1/fungibles/0x111c47865ade3b172a928df8f990bc7f2a3b9aaa",
|
|
86
|
+
},
|
|
87
|
+
data: {
|
|
88
|
+
type: "fungibles",
|
|
89
|
+
id: "0x111c47865ade3b172a928df8f990bc7f2a3b9aaa",
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
dapp: {
|
|
93
|
+
data: {
|
|
94
|
+
type: "dapps",
|
|
95
|
+
id: "aave-v3",
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
};
|
|
102
|
+
const mockPortfolioResponse = {
|
|
103
|
+
links: {
|
|
104
|
+
self: "https://api.zerion.io/v1/wallets/0x42b9df65b219b3dd36ff330a4dd8f327a6ada990/portfolio",
|
|
105
|
+
},
|
|
106
|
+
data: {
|
|
107
|
+
type: "portfolio",
|
|
108
|
+
id: "0x42b9df65b219b3dd36ff330a4dd8f327a6ada990",
|
|
109
|
+
attributes: {
|
|
110
|
+
positions_distribution_by_type: {
|
|
111
|
+
wallet: 1864.774102420957,
|
|
112
|
+
deposited: 78.04192492782934,
|
|
113
|
+
borrowed: 0.9751475798305564,
|
|
114
|
+
locked: 5.780032725068765,
|
|
115
|
+
staked: 66.13183205505294,
|
|
116
|
+
},
|
|
117
|
+
positions_distribution_by_chain: {
|
|
118
|
+
arbitrum: 458.3555051522226,
|
|
119
|
+
aurora: 72.01031337463428,
|
|
120
|
+
avalanche: 17.128850607339444,
|
|
121
|
+
base: 55.01550749900544,
|
|
122
|
+
"binance-smart-chain": 5.561075880033699,
|
|
123
|
+
celo: 31.293849330045006,
|
|
124
|
+
ethereum: 1214.009900354964,
|
|
125
|
+
fantom: 84.58514074264951,
|
|
126
|
+
linea: 8.258227109505139,
|
|
127
|
+
optimism: 573.032664994399,
|
|
128
|
+
polygon: 64.31407562634853,
|
|
129
|
+
xdai: 113.1679493137936,
|
|
130
|
+
"zksync-era": 9.451002156306377,
|
|
131
|
+
},
|
|
132
|
+
total: {
|
|
133
|
+
positions: 2017.4858230069574,
|
|
134
|
+
},
|
|
135
|
+
changes: {
|
|
136
|
+
absolute_1d: 102.0271468171374,
|
|
137
|
+
percent_1d: 5.326512552079021,
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
beforeEach(() => {
|
|
143
|
+
jest.clearAllMocks();
|
|
144
|
+
process.env.ZERION_API_KEY = mockApiKey;
|
|
145
|
+
});
|
|
146
|
+
afterAll(() => {
|
|
147
|
+
process.env.ZERION_API_KEY = originalEnv;
|
|
148
|
+
});
|
|
149
|
+
it("should throw if no API key is provided", () => {
|
|
150
|
+
delete process.env.ZERION_API_KEY;
|
|
151
|
+
expect(() => new zerionActionProvider_1.ZerionActionProvider()).toThrow("ZERION_API_KEY is not configured.");
|
|
152
|
+
});
|
|
153
|
+
it("should use provided API key from config", () => {
|
|
154
|
+
const provider = new zerionActionProvider_1.ZerionActionProvider({ apiKey: "foo" });
|
|
155
|
+
expect(provider).toBeDefined();
|
|
156
|
+
});
|
|
157
|
+
// supportsNetwork tests
|
|
158
|
+
const provider = new zerionActionProvider_1.ZerionActionProvider({ apiKey: mockApiKey });
|
|
159
|
+
it("should support the protocol family", () => {
|
|
160
|
+
expect(provider.supportsNetwork({ protocolFamily: "evm" })).toBe(true);
|
|
161
|
+
});
|
|
162
|
+
it("should not support other protocol families", () => {
|
|
163
|
+
expect(provider.supportsNetwork({ protocolFamily: "other-protocol-family" })).toBe(false);
|
|
164
|
+
});
|
|
165
|
+
it("should handle invalid network objects", () => {
|
|
166
|
+
expect(provider.supportsNetwork({ protocolFamily: "invalid-protocol" })).toBe(false);
|
|
167
|
+
expect(provider.supportsNetwork({})).toBe(false);
|
|
168
|
+
});
|
|
169
|
+
describe("getPortfolioOverview", () => {
|
|
170
|
+
const validAddress = "0x42b9df65b219b3dd36ff330a4dd8f327a6ada990";
|
|
171
|
+
const invalidAddress = "invalid-address";
|
|
172
|
+
const provider = new zerionActionProvider_1.ZerionActionProvider({ apiKey: mockApiKey });
|
|
173
|
+
it("returns error for invalid address", async () => {
|
|
174
|
+
const result = await provider.getPortfolioOverview({ walletAddress: invalidAddress });
|
|
175
|
+
expect(result).toMatch(/Invalid wallet address/);
|
|
176
|
+
});
|
|
177
|
+
it("returns formatted data for valid address", async () => {
|
|
178
|
+
global.fetch.mockResolvedValueOnce({
|
|
179
|
+
json: jest.fn().mockResolvedValue(mockPortfolioResponse),
|
|
180
|
+
});
|
|
181
|
+
const result = await provider.getPortfolioOverview({ walletAddress: validAddress });
|
|
182
|
+
expect(utils_1.formatPortfolioData).toHaveBeenCalledWith(mockPortfolioResponse.data);
|
|
183
|
+
expect(result).toBe("formatted portfolio");
|
|
184
|
+
});
|
|
185
|
+
it("returns error on fetch failure", async () => {
|
|
186
|
+
global.fetch.mockRejectedValueOnce(new Error("fail"));
|
|
187
|
+
const result = await provider.getPortfolioOverview({ walletAddress: validAddress });
|
|
188
|
+
expect(result).toMatch(/Error fetching portfolio overview/);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
describe("getFungiblePositions", () => {
|
|
192
|
+
const validAddress = "0x42b9df65b219b3dd36ff330a4dd8f327a6ada990";
|
|
193
|
+
const invalidAddress = "invalid-address";
|
|
194
|
+
const provider = new zerionActionProvider_1.ZerionActionProvider({ apiKey: mockApiKey });
|
|
195
|
+
it("returns error for invalid address", async () => {
|
|
196
|
+
const result = await provider.getFungiblePositions({ walletAddress: invalidAddress });
|
|
197
|
+
expect(result).toMatch(/Invalid wallet address/);
|
|
198
|
+
});
|
|
199
|
+
it("returns formatted data for valid address", async () => {
|
|
200
|
+
global.fetch.mockResolvedValueOnce({
|
|
201
|
+
json: jest.fn().mockResolvedValue(mockFungiblePositionResponse),
|
|
202
|
+
});
|
|
203
|
+
const result = await provider.getFungiblePositions({ walletAddress: validAddress });
|
|
204
|
+
expect(utils_1.formatPositionsData).toHaveBeenCalledWith(mockFungiblePositionResponse.data);
|
|
205
|
+
expect(result).toBe("formatted positions");
|
|
206
|
+
});
|
|
207
|
+
it("returns error on fetch failure", async () => {
|
|
208
|
+
global.fetch.mockRejectedValueOnce(new Error("fail"));
|
|
209
|
+
const result = await provider.getFungiblePositions({ walletAddress: validAddress });
|
|
210
|
+
expect(result).toMatch(/Error fetching fungible positions/);
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./zoraActionProvider"), exports);
|
|
18
|
+
__exportStar(require("./schemas"), exports);
|
|
19
|
+
__exportStar(require("./utils"), exports);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const CreateCoinSchema: z.ZodObject<{
|
|
3
|
+
name: z.ZodString;
|
|
4
|
+
symbol: z.ZodString;
|
|
5
|
+
description: z.ZodString;
|
|
6
|
+
image: z.ZodString;
|
|
7
|
+
category: z.ZodDefault<z.ZodString>;
|
|
8
|
+
payoutRecipient: z.ZodOptional<z.ZodString>;
|
|
9
|
+
platformReferrer: z.ZodOptional<z.ZodString>;
|
|
10
|
+
currency: z.ZodDefault<z.ZodEnum<["ZORA", "ETH"]>>;
|
|
11
|
+
}, "strip", z.ZodTypeAny, {
|
|
12
|
+
symbol: string;
|
|
13
|
+
name: string;
|
|
14
|
+
description: string;
|
|
15
|
+
currency: "ETH" | "ZORA";
|
|
16
|
+
image: string;
|
|
17
|
+
category: string;
|
|
18
|
+
platformReferrer?: string | undefined;
|
|
19
|
+
payoutRecipient?: string | undefined;
|
|
20
|
+
}, {
|
|
21
|
+
symbol: string;
|
|
22
|
+
name: string;
|
|
23
|
+
description: string;
|
|
24
|
+
image: string;
|
|
25
|
+
currency?: "ETH" | "ZORA" | undefined;
|
|
26
|
+
platformReferrer?: string | undefined;
|
|
27
|
+
category?: string | undefined;
|
|
28
|
+
payoutRecipient?: string | undefined;
|
|
29
|
+
}>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CreateCoinSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
exports.CreateCoinSchema = zod_1.z
|
|
6
|
+
.object({
|
|
7
|
+
name: zod_1.z.string().describe("The name of the coin to create"),
|
|
8
|
+
symbol: zod_1.z.string().describe("The symbol of the coin to create"),
|
|
9
|
+
description: zod_1.z.string().describe("The description of the coin"),
|
|
10
|
+
image: zod_1.z.string().describe("Local image file path or URI (ipfs:// or https://)"),
|
|
11
|
+
category: zod_1.z
|
|
12
|
+
.string()
|
|
13
|
+
.default("social")
|
|
14
|
+
.describe("The category of the coin, optional, defaults to 'social'"),
|
|
15
|
+
payoutRecipient: zod_1.z
|
|
16
|
+
.string()
|
|
17
|
+
.regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
|
|
18
|
+
.optional()
|
|
19
|
+
.describe("The address that will receive creator earnings, defaults to wallet address"),
|
|
20
|
+
platformReferrer: zod_1.z
|
|
21
|
+
.string()
|
|
22
|
+
.regex(/^0x[a-fA-F0-9]{40}$/, "Invalid Ethereum address format")
|
|
23
|
+
.optional()
|
|
24
|
+
.describe("The address that will receive platform referrer fees, optional"),
|
|
25
|
+
currency: zod_1.z
|
|
26
|
+
.enum(["ZORA", "ETH"])
|
|
27
|
+
.default("ZORA")
|
|
28
|
+
.describe("Currency to be used for the trading pair, optional, defaults to 'ZORA'."),
|
|
29
|
+
})
|
|
30
|
+
.strip()
|
|
31
|
+
.describe("Instructions for creating a new coin on Zora");
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration for Pinata
|
|
3
|
+
*/
|
|
4
|
+
interface PinataConfig {
|
|
5
|
+
jwt: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Parameters for generating token URI
|
|
9
|
+
*/
|
|
10
|
+
interface TokenUriParams {
|
|
11
|
+
name: string;
|
|
12
|
+
symbol: string;
|
|
13
|
+
description: string;
|
|
14
|
+
image: string;
|
|
15
|
+
category?: string;
|
|
16
|
+
pinataConfig: PinataConfig;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Generates a Zora token URI by handling local file or URI
|
|
20
|
+
*
|
|
21
|
+
* @param params - Parameters for generating the token URI
|
|
22
|
+
* @returns A promise that resolves to object containing the IPFS URI
|
|
23
|
+
*/
|
|
24
|
+
export declare function generateZoraTokenUri(params: TokenUriParams): Promise<{
|
|
25
|
+
uri: string;
|
|
26
|
+
imageUri: string;
|
|
27
|
+
}>;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateZoraTokenUri = generateZoraTokenUri;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
/**
|
|
10
|
+
* Reads a local file and converts it to base64
|
|
11
|
+
*
|
|
12
|
+
* @param imageFileName - Path to the local file
|
|
13
|
+
* @returns Base64 encoded file and mime type
|
|
14
|
+
*/
|
|
15
|
+
async function readFileAsBase64(imageFileName) {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
fs_1.default.readFile(imageFileName, (err, data) => {
|
|
18
|
+
if (err) {
|
|
19
|
+
reject(new Error(`Failed to read file: ${err.message}`));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
// Determine mime type based on file extension
|
|
23
|
+
const extension = path_1.default.extname(imageFileName).toLowerCase();
|
|
24
|
+
let mimeType = "application/octet-stream"; // default
|
|
25
|
+
if (extension === ".png")
|
|
26
|
+
mimeType = "image/png";
|
|
27
|
+
else if (extension === ".jpg" || extension === ".jpeg")
|
|
28
|
+
mimeType = "image/jpeg";
|
|
29
|
+
else if (extension === ".gif")
|
|
30
|
+
mimeType = "image/gif";
|
|
31
|
+
else if (extension === ".svg")
|
|
32
|
+
mimeType = "image/svg+xml";
|
|
33
|
+
const base64 = data.toString("base64");
|
|
34
|
+
resolve({ base64, mimeType });
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Uploads a file to IPFS using Pinata
|
|
40
|
+
*
|
|
41
|
+
* @param params - Configuration and file data
|
|
42
|
+
* @param params.pinataConfig - Pinata configuration including JWT
|
|
43
|
+
* @param params.fileData - Base64 encoded file data
|
|
44
|
+
* @param params.fileName - Name for the uploaded file
|
|
45
|
+
* @param params.mimeType - MIME type of the file
|
|
46
|
+
* @returns Upload response with CID and other details
|
|
47
|
+
*/
|
|
48
|
+
async function uploadFileToIPFS(params) {
|
|
49
|
+
try {
|
|
50
|
+
const formData = new FormData();
|
|
51
|
+
// Convert base64 to Blob and then to File
|
|
52
|
+
const byteCharacters = atob(params.fileData);
|
|
53
|
+
const byteArrays = [];
|
|
54
|
+
for (let offset = 0; offset < byteCharacters.length; offset += 1024) {
|
|
55
|
+
const slice = byteCharacters.slice(offset, offset + 1024);
|
|
56
|
+
const byteNumbers = new Array(slice.length);
|
|
57
|
+
for (let i = 0; i < slice.length; i++) {
|
|
58
|
+
byteNumbers[i] = slice.charCodeAt(i);
|
|
59
|
+
}
|
|
60
|
+
const byteArray = new Uint8Array(byteNumbers);
|
|
61
|
+
byteArrays.push(byteArray);
|
|
62
|
+
}
|
|
63
|
+
const blob = new Blob(byteArrays, { type: params.mimeType });
|
|
64
|
+
const file = new File([blob], params.fileName, { type: params.mimeType });
|
|
65
|
+
formData.append("file", file);
|
|
66
|
+
const pinataMetadata = {
|
|
67
|
+
name: params.fileName,
|
|
68
|
+
};
|
|
69
|
+
formData.append("pinataMetadata", JSON.stringify(pinataMetadata));
|
|
70
|
+
const pinataOptions = {
|
|
71
|
+
cidVersion: 1,
|
|
72
|
+
};
|
|
73
|
+
formData.append("pinataOptions", JSON.stringify(pinataOptions));
|
|
74
|
+
const response = await fetch("https://api.pinata.cloud/pinning/pinFileToIPFS", {
|
|
75
|
+
method: "POST",
|
|
76
|
+
headers: {
|
|
77
|
+
Authorization: `Bearer ${params.pinataConfig.jwt}`,
|
|
78
|
+
},
|
|
79
|
+
body: formData,
|
|
80
|
+
});
|
|
81
|
+
if (!response.ok) {
|
|
82
|
+
const error = await response.json();
|
|
83
|
+
throw new Error(`Failed to upload file to IPFS: ${error.message || response.statusText}`);
|
|
84
|
+
}
|
|
85
|
+
const data = await response.json();
|
|
86
|
+
return {
|
|
87
|
+
IpfsHash: data.IpfsHash,
|
|
88
|
+
PinSize: data.PinSize,
|
|
89
|
+
Timestamp: data.Timestamp,
|
|
90
|
+
isDuplicate: data.isDuplicate || false,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
if (error instanceof Error) {
|
|
95
|
+
throw new Error(`Failed to upload file to IPFS: ${error.message}`);
|
|
96
|
+
}
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Uploads JSON data to IPFS using Pinata
|
|
102
|
+
*
|
|
103
|
+
* @param params - Configuration and JSON data
|
|
104
|
+
* @param params.pinataConfig - Pinata configuration including JWT
|
|
105
|
+
* @param params.json - JSON data to upload
|
|
106
|
+
* @returns Upload response with CID and other details
|
|
107
|
+
*/
|
|
108
|
+
async function uploadJsonToIPFS(params) {
|
|
109
|
+
try {
|
|
110
|
+
const requestBody = {
|
|
111
|
+
pinataOptions: {
|
|
112
|
+
cidVersion: 1,
|
|
113
|
+
},
|
|
114
|
+
pinataMetadata: {
|
|
115
|
+
name: `${params.json.name}-metadata.json`,
|
|
116
|
+
},
|
|
117
|
+
pinataContent: params.json,
|
|
118
|
+
};
|
|
119
|
+
const response = await fetch("https://api.pinata.cloud/pinning/pinJSONToIPFS", {
|
|
120
|
+
method: "POST",
|
|
121
|
+
headers: {
|
|
122
|
+
Authorization: `Bearer ${params.pinataConfig.jwt}`,
|
|
123
|
+
"Content-Type": "application/json",
|
|
124
|
+
},
|
|
125
|
+
body: JSON.stringify(requestBody),
|
|
126
|
+
});
|
|
127
|
+
if (!response.ok) {
|
|
128
|
+
const error = await response.json();
|
|
129
|
+
throw new Error(`Failed to upload JSON to IPFS: ${error.message || response.statusText}`);
|
|
130
|
+
}
|
|
131
|
+
const data = await response.json();
|
|
132
|
+
return {
|
|
133
|
+
IpfsHash: data.IpfsHash,
|
|
134
|
+
PinSize: data.PinSize,
|
|
135
|
+
Timestamp: data.Timestamp,
|
|
136
|
+
isDuplicate: data.isDuplicate || false,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
if (error instanceof Error) {
|
|
141
|
+
throw new Error(`Failed to upload JSON to IPFS: ${error.message}`);
|
|
142
|
+
}
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Generates a Zora token URI by handling local file or URI
|
|
148
|
+
*
|
|
149
|
+
* @param params - Parameters for generating the token URI
|
|
150
|
+
* @returns A promise that resolves to object containing the IPFS URI
|
|
151
|
+
*/
|
|
152
|
+
async function generateZoraTokenUri(params) {
|
|
153
|
+
try {
|
|
154
|
+
let imageUri;
|
|
155
|
+
// Check if image is already a URI (ipfs:// or https://)
|
|
156
|
+
if (params.image.startsWith("ipfs://") || params.image.startsWith("https://")) {
|
|
157
|
+
imageUri = params.image;
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
// Handle local file
|
|
161
|
+
const { base64, mimeType } = await readFileAsBase64(params.image);
|
|
162
|
+
const fileName = path_1.default.basename(params.image);
|
|
163
|
+
const imageRes = await uploadFileToIPFS({
|
|
164
|
+
pinataConfig: params.pinataConfig,
|
|
165
|
+
fileData: base64,
|
|
166
|
+
fileName,
|
|
167
|
+
mimeType,
|
|
168
|
+
});
|
|
169
|
+
imageUri = `ipfs://${imageRes.IpfsHash}`;
|
|
170
|
+
}
|
|
171
|
+
// Create and upload the metadata
|
|
172
|
+
const metadata = {
|
|
173
|
+
name: params.name,
|
|
174
|
+
description: params.description,
|
|
175
|
+
symbol: params.symbol,
|
|
176
|
+
image: imageUri,
|
|
177
|
+
content: {
|
|
178
|
+
uri: imageUri,
|
|
179
|
+
mime: imageUri.startsWith("ipfs://") || imageUri.startsWith("https://")
|
|
180
|
+
? "image/*"
|
|
181
|
+
: "image/png",
|
|
182
|
+
},
|
|
183
|
+
properties: {
|
|
184
|
+
category: params.category || "social",
|
|
185
|
+
},
|
|
186
|
+
};
|
|
187
|
+
const metadataRes = await uploadJsonToIPFS({
|
|
188
|
+
pinataConfig: params.pinataConfig,
|
|
189
|
+
json: metadata,
|
|
190
|
+
});
|
|
191
|
+
const uri = `ipfs://${metadataRes.IpfsHash}`;
|
|
192
|
+
return { uri, imageUri };
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
if (error instanceof Error) {
|
|
196
|
+
throw new Error(`Failed to generate Zora token URI: ${error.message}`);
|
|
197
|
+
}
|
|
198
|
+
throw error;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ActionProvider } from "../actionProvider";
|
|
3
|
+
import { EvmWalletProvider } from "../../wallet-providers/evmWalletProvider";
|
|
4
|
+
import { CreateCoinSchema } from "./schemas";
|
|
5
|
+
import { Network } from "../../network";
|
|
6
|
+
/**
|
|
7
|
+
* ZoraActionProvider provides actions for interacting with the Zora protocol.
|
|
8
|
+
*/
|
|
9
|
+
export declare class ZoraActionProvider extends ActionProvider<EvmWalletProvider> {
|
|
10
|
+
#private;
|
|
11
|
+
/**
|
|
12
|
+
* Constructor for the ZoraActionProvider.
|
|
13
|
+
*/
|
|
14
|
+
constructor();
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new Zora coin.
|
|
17
|
+
*
|
|
18
|
+
* @param walletProvider - The wallet provider to use for the transaction.
|
|
19
|
+
* @param args - The input arguments for the action.
|
|
20
|
+
* @returns A message containing the coin creation details.
|
|
21
|
+
*/
|
|
22
|
+
createCoin(walletProvider: EvmWalletProvider, args: z.infer<typeof CreateCoinSchema>): Promise<string>;
|
|
23
|
+
/**
|
|
24
|
+
* Checks if the Zora action provider supports the given network.
|
|
25
|
+
*
|
|
26
|
+
* @param network - The network to check.
|
|
27
|
+
* @returns True if the Zora action provider supports the network, false otherwise.
|
|
28
|
+
*/
|
|
29
|
+
supportsNetwork: (network: Network) => boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Factory function to create a new ZoraActionProvider instance.
|
|
33
|
+
*
|
|
34
|
+
* @returns A new ZoraActionProvider instance
|
|
35
|
+
*/
|
|
36
|
+
export declare const zoraActionProvider: () => ZoraActionProvider;
|