Skip to content

Commit bf161b7

Browse files
Plugin: Crossmint Minting API (#23)
* changes * changes * changes * changeset * fix lockfile * fix import ordering * Fix bugs, add get collections and common base * update changeset * Fix format * update lockfile --------- Co-authored-by: Agustin Armellini Fischer <[email protected]>
1 parent a1bfd55 commit bf161b7

File tree

14 files changed

+452
-103
lines changed

14 files changed

+452
-103
lines changed

goat.code-workspace

Lines changed: 72 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,76 @@
11
{
2-
"folders": [
3-
{
4-
"name": "🐐 GOAT",
5-
"path": "."
6-
},
7-
{
8-
"name": "📘 Typescript",
9-
"path": "./typescript"
10-
},
11-
{
12-
"name": "🌋 Core",
13-
"path": "./typescript/packages/core"
14-
},
15-
{
16-
"name": "[Adapter] 🎧 eleven-labs",
17-
"path": "./typescript/packages/adapters/eleven-labs"
18-
},
19-
{
20-
"name": "[Adapter] 🟠 eliza",
21-
"path": "./typescript/packages/adapters/eliza"
22-
},
23-
{
24-
"name": "[Adapter] 🦜 langchain",
25-
"path": "./typescript/packages/adapters/langchain"
26-
},
27-
{
28-
"name": "[Adapter] 🤖 vercel-ai",
29-
"path": "./typescript/packages/adapters/vercel-ai"
30-
},
31-
{
32-
"name": "[Plugin] 💰 erc20",
33-
"path": "./typescript/packages/plugins/erc20"
34-
},
35-
{
36-
"name": "[Plugin] 🎰 polymarket",
37-
"path": "./typescript/packages/plugins/polymarket"
38-
},
39-
{
40-
"name": "[Plugin] 💰 coingecko",
41-
"path": "./typescript/packages/plugins/coingecko"
42-
},
43-
{
44-
"name": "[Wallet] 🍀 crossmint",
45-
"path": "./typescript/packages/wallets/crossmint"
46-
},
47-
{
48-
"name": "[Wallet] 🌞 solana",
49-
"path": "./typescript/packages/wallets/solana"
50-
},
51-
{
52-
"name": "[Wallet] 💳 viem",
53-
"path": "./typescript/packages/wallets/viem"
54-
},
55-
{
56-
"name": "📚 Docs",
57-
"path": "./docs"
58-
},
59-
{
60-
"name": "🚀 Examples",
61-
"path": "./typescript/examples"
62-
}
63-
],
64-
"settings": {
2+
"folders": [
3+
{
4+
"name": "🐐 GOAT",
5+
"path": "."
6+
},
7+
{
8+
"name": "📘 Typescript",
9+
"path": "./typescript"
10+
},
11+
{
12+
"name": "🌋 Core",
13+
"path": "./typescript/packages/core"
14+
},
15+
// Adapters
16+
{
17+
"name": "[Adapter] 🎧 eleven-labs",
18+
"path": "./typescript/packages/adapters/eleven-labs"
19+
},
20+
{
21+
"name": "[Adapter] 🟠 eliza",
22+
"path": "./typescript/packages/adapters/eliza"
23+
},
24+
{
25+
"name": "[Adapter] 🦜 langchain",
26+
"path": "./typescript/packages/adapters/langchain"
27+
},
28+
{
29+
"name": "[Adapter] 🤖 vercel-ai",
30+
"path": "./typescript/packages/adapters/vercel-ai"
31+
},
32+
// Plugins
33+
{
34+
"name": "[Plugin] 💰 erc20",
35+
"path": "./typescript/packages/plugins/erc20"
36+
},
37+
{
38+
"name": "[Plugin] 🎰 polymarket",
39+
"path": "./typescript/packages/plugins/polymarket"
40+
},
41+
{
42+
"name": "[Plugin] 💰 coingecko",
43+
"path": "./typescript/packages/plugins/coingecko"
44+
},
45+
{
46+
"name": "[Plugin] 🌐 Solana NFTs",
47+
"path": "./typescript/packages/plugins/solana-nfts"
48+
},
49+
// Wallets
50+
{
51+
"name": "[Wallet] 🍀 crossmint",
52+
"path": "./typescript/packages/wallets/crossmint"
53+
},
54+
{
55+
"name": "[Wallet] 🌞 solana",
56+
"path": "./typescript/packages/wallets/solana"
57+
},
58+
{
59+
"name": "[Wallet] 💳 viem",
60+
"path": "./typescript/packages/wallets/viem"
61+
},
62+
// Docs
63+
{
64+
"name": "📚 Docs",
65+
"path": "./docs"
66+
},
67+
// Examples
68+
{
69+
"name": "🚀 Examples",
70+
"path": "./typescript/examples"
71+
}
72+
],
73+
"settings": {
6574
"editor.formatOnSave": true,
6675
"editor.defaultFormatter": "biomejs.biome"
6776
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@goat-sdk/crossmint": minor
3+
"goat-examples-vercel-ai-crossmint-solana-custodial-wallets": patch
4+
"goat-examples-vercel-ai-viem": patch
5+
"@goat-sdk/core": patch
6+
---
7+
8+
Add mint plugin to Crossmint

typescript/examples/vercel-ai/crossmint-solana-custodial-wallets/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const { custodial } = crossmint(apiKey);
2121
wallet: await custodial({
2222
chain: "solana",
2323
email: email,
24-
env: "staging",
2524
connection: new Connection("https://api.devnet.solana.com", "confirmed"),
2625
}),
2726
});

typescript/examples/vercel-ai/viem/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const walletClient = createWalletClient({
3232
model: openai("gpt-4o-mini"),
3333
tools: tools,
3434
maxSteps: 5,
35-
prompt: "Get my balance in USDC",
35+
prompt: "Get the balance of the USDC token",
3636
});
3737

3838
console.log(result.text);

typescript/packages/core/src/wallets/core.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export type Balance = {
1414
* @param id - Chain ID, optional for EVM
1515
*/
1616
export type Chain = {
17-
type: "evm" | "solana";
17+
type: "evm" | "solana" | "aptos";
1818
id?: number; // optional for EVM
1919
};
2020

@@ -26,6 +26,10 @@ export type SolanaChain = Chain & {
2626
type: "solana";
2727
};
2828

29+
export type AptosChain = Chain & {
30+
type: "aptos";
31+
};
32+
2933
export interface WalletClient {
3034
getAddress: () => string;
3135
getChain: () => Chain;

typescript/packages/wallets/crossmint/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"module": "./dist/index.mjs",
1313
"types": "./dist/index.d.ts",
1414
"dependencies": {
15+
"@crossmint/common-sdk-base": "0.3.1",
1516
"@goat-sdk/core": "workspace:*",
1617
"@solana/web3.js": "catalog:",
1718
"abitype": "^1.0.6",

typescript/packages/wallets/crossmint/src/api.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { CrossmintApiClient } from "@crossmint/common-sdk-base";
12
import type { EVMTypedData } from "@goat-sdk/core";
23
import type { SupportedSmartWalletChains } from "./chains";
34

@@ -191,10 +192,8 @@ type APIResponse =
191192
| SignTypedDataResponse
192193
| ApproveSignatureResponse;
193194

194-
export function createCrossmintAPI(apiKey: string, env: "staging" | "production") {
195-
const baseUrl =
196-
env === "staging" ? "https://staging.crossmint.com/api/v1-alpha2" : "https://wwww.crossmint.com/api/v1-alpha2";
197-
195+
export function createCrossmintAPI(crossmintClient: CrossmintApiClient) {
196+
const baseUrl = `${crossmintClient.baseUrl}/api/v1-alpha2`;
198197
/**
199198
* Makes an HTTP request to the Crossmint API.
200199
*
@@ -208,8 +207,7 @@ export function createCrossmintAPI(apiKey: string, env: "staging" | "production"
208207

209208
// Set default headers and merge with any additional headers
210209
const headers = new Headers({
211-
"X-API-KEY": apiKey,
212-
"Content-Type": "application/json",
210+
...crossmintClient.authHeaders,
213211
...(options.headers || {}),
214212
});
215213

typescript/packages/wallets/crossmint/src/chains.ts

Lines changed: 97 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
1+
import type { Chain as GoatChain } from "@goat-sdk/core";
12
import {
23
type Chain,
34
arbitrum,
45
arbitrumSepolia,
6+
astarZkEVM,
7+
astarZkyoto,
8+
avalanche,
59
avalancheFuji,
610
base,
711
baseSepolia,
12+
bsc,
13+
chiliz,
14+
mainnet,
815
optimism,
916
optimismSepolia,
1017
polygon,
1118
polygonAmoy,
1219
sepolia,
20+
shape,
21+
shapeSepolia,
22+
skaleNebula,
1323
skaleNebulaTestnet,
1424
victionTestnet,
25+
xai,
26+
xaiTestnet,
27+
zora,
28+
zoraSepolia,
1529
} from "viem/chains";
1630

1731
const faucetChains = [
@@ -40,19 +54,69 @@ const smartWalletChains = [
4054

4155
export type SupportedSmartWalletChains = (typeof smartWalletChains)[number];
4256

43-
const chainMap: Record<SupportedFaucetChains | SupportedSmartWalletChains, Chain> = {
44-
arbitrum: arbitrum,
57+
export const mintingChains = [
58+
"arbitrum",
59+
"arbitrum-sepolia",
60+
"astar-zkevm",
61+
"avalanche",
62+
"avalanche-fuji",
63+
"base",
64+
"base-sepolia",
65+
"bsc",
66+
"chiliz",
67+
"chiliz-spicy-testnet",
68+
"ethereum",
69+
"ethereum-sepolia",
70+
"optimism",
71+
"optimism-sepolia",
72+
"polygon",
73+
"polygon-amoy",
74+
"shape",
75+
"shape-sepolia",
76+
"skale-nebula",
77+
"skale-nebula-testnet",
78+
"soneium-minato-testnet",
79+
"xai",
80+
"xai-sepolia-testnet",
81+
"zkyoto",
82+
"zora",
83+
"zora-sepolia",
84+
] as const;
85+
86+
export type SupportedMintingChains = (typeof mintingChains)[number];
87+
88+
const chainMap: Record<SupportedFaucetChains | SupportedSmartWalletChains | SupportedMintingChains, Chain> = {
89+
arbitrum,
4590
"arbitrum-sepolia": arbitrumSepolia,
46-
base: base,
91+
"astar-zkevm": astarZkEVM,
92+
avalanche,
93+
"avalanche-fuji": avalancheFuji,
94+
base,
4795
"base-sepolia": baseSepolia,
48-
optimism: optimism,
96+
bsc,
97+
chiliz,
98+
ethereum: mainnet,
99+
optimism,
49100
"optimism-sepolia": optimismSepolia,
50-
polygon: polygon,
101+
polygon,
51102
"polygon-amoy": polygonAmoy,
52-
"avalanche-fuji": avalancheFuji,
53103
"ethereum-sepolia": sepolia,
104+
shape,
105+
"shape-sepolia": shapeSepolia,
106+
"skale-nebula": skaleNebula,
54107
"skale-nebula-testnet": skaleNebulaTestnet,
55108
"viction-testnet": victionTestnet,
109+
xai,
110+
"xai-sepolia-testnet": xaiTestnet,
111+
zkyoto: astarZkyoto,
112+
zora,
113+
"zora-sepolia": zoraSepolia,
114+
"chiliz-spicy-testnet": {
115+
id: 88882,
116+
} as Chain,
117+
"soneium-minato-testnet": {
118+
id: 88882,
119+
} as Chain,
56120
};
57121

58122
export function getViemChain(chain: SupportedSmartWalletChains | SupportedFaucetChains): Chain {
@@ -63,14 +127,38 @@ export function getViemChain(chain: SupportedSmartWalletChains | SupportedFaucet
63127
return viemChain;
64128
}
65129

66-
const testnetChains = ["arbitrum-sepolia", "base-sepolia", "optimism-sepolia", "polygon-amoy"] as const;
130+
export function getCrossmintChainString(chain: GoatChain): string {
131+
if (chain.type === "solana") {
132+
return "solana";
133+
}
134+
if (chain.type === "aptos") {
135+
return "aptos";
136+
}
67137

68-
export function getEnv(chain: SupportedSmartWalletChains): "staging" | "production" {
69-
return (testnetChains as readonly string[]).includes(chain) ? "staging" : "production";
138+
if (chain.type === "evm") {
139+
// from chain.id figure out the chain name
140+
const chainName = Object.keys(chainMap).find(
141+
(key): key is keyof typeof chainMap => chainMap[key as keyof typeof chainMap].id === chain.id,
142+
);
143+
if (!chainName) {
144+
throw new Error(`Unsupported chain: ${chain.id}`);
145+
}
146+
return chainName;
147+
}
148+
149+
throw new Error(`Unsupported chain: ${chain.type}`);
70150
}
71151

152+
const testnetChains = ["arbitrum-sepolia", "base-sepolia", "optimism-sepolia", "polygon-amoy"] as const;
153+
72154
const faucetChainIds = new Set(faucetChains.map((chainName) => chainMap[chainName].id));
73155

74156
export function isChainSupportedByFaucet(chainId: number): boolean {
75157
return faucetChainIds.has(chainId);
76158
}
159+
160+
const mintingChainIds = new Set(mintingChains.map((chainName) => chainMap[chainName].id));
161+
162+
export function isChainSupportedByMinting(chainId: number): boolean {
163+
return mintingChainIds.has(chainId);
164+
}

0 commit comments

Comments
 (0)