Skip to content

Commit

Permalink
Plugin: Crossmint Minting API (#23)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
bryan-eastwood3 and 0xaguspunk authored Dec 10, 2024
1 parent a1bfd55 commit bf161b7
Show file tree
Hide file tree
Showing 14 changed files with 452 additions and 103 deletions.
135 changes: 72 additions & 63 deletions goat.code-workspace
Original file line number Diff line number Diff line change
@@ -1,67 +1,76 @@
{
"folders": [
{
"name": "🐐 GOAT",
"path": "."
},
{
"name": "📘 Typescript",
"path": "./typescript"
},
{
"name": "🌋 Core",
"path": "./typescript/packages/core"
},
{
"name": "[Adapter] 🎧 eleven-labs",
"path": "./typescript/packages/adapters/eleven-labs"
},
{
"name": "[Adapter] 🟠 eliza",
"path": "./typescript/packages/adapters/eliza"
},
{
"name": "[Adapter] 🦜 langchain",
"path": "./typescript/packages/adapters/langchain"
},
{
"name": "[Adapter] 🤖 vercel-ai",
"path": "./typescript/packages/adapters/vercel-ai"
},
{
"name": "[Plugin] 💰 erc20",
"path": "./typescript/packages/plugins/erc20"
},
{
"name": "[Plugin] 🎰 polymarket",
"path": "./typescript/packages/plugins/polymarket"
},
{
"name": "[Plugin] 💰 coingecko",
"path": "./typescript/packages/plugins/coingecko"
},
{
"name": "[Wallet] 🍀 crossmint",
"path": "./typescript/packages/wallets/crossmint"
},
{
"name": "[Wallet] 🌞 solana",
"path": "./typescript/packages/wallets/solana"
},
{
"name": "[Wallet] 💳 viem",
"path": "./typescript/packages/wallets/viem"
},
{
"name": "📚 Docs",
"path": "./docs"
},
{
"name": "🚀 Examples",
"path": "./typescript/examples"
}
],
"settings": {
"folders": [
{
"name": "🐐 GOAT",
"path": "."
},
{
"name": "📘 Typescript",
"path": "./typescript"
},
{
"name": "🌋 Core",
"path": "./typescript/packages/core"
},
// Adapters
{
"name": "[Adapter] 🎧 eleven-labs",
"path": "./typescript/packages/adapters/eleven-labs"
},
{
"name": "[Adapter] 🟠 eliza",
"path": "./typescript/packages/adapters/eliza"
},
{
"name": "[Adapter] 🦜 langchain",
"path": "./typescript/packages/adapters/langchain"
},
{
"name": "[Adapter] 🤖 vercel-ai",
"path": "./typescript/packages/adapters/vercel-ai"
},
// Plugins
{
"name": "[Plugin] 💰 erc20",
"path": "./typescript/packages/plugins/erc20"
},
{
"name": "[Plugin] 🎰 polymarket",
"path": "./typescript/packages/plugins/polymarket"
},
{
"name": "[Plugin] 💰 coingecko",
"path": "./typescript/packages/plugins/coingecko"
},
{
"name": "[Plugin] 🌐 Solana NFTs",
"path": "./typescript/packages/plugins/solana-nfts"
},
// Wallets
{
"name": "[Wallet] 🍀 crossmint",
"path": "./typescript/packages/wallets/crossmint"
},
{
"name": "[Wallet] 🌞 solana",
"path": "./typescript/packages/wallets/solana"
},
{
"name": "[Wallet] 💳 viem",
"path": "./typescript/packages/wallets/viem"
},
// Docs
{
"name": "📚 Docs",
"path": "./docs"
},
// Examples
{
"name": "🚀 Examples",
"path": "./typescript/examples"
}
],
"settings": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "biomejs.biome"
}
Expand Down
8 changes: 8 additions & 0 deletions typescript/.changeset/plenty-radios-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@goat-sdk/crossmint": minor
"goat-examples-vercel-ai-crossmint-solana-custodial-wallets": patch
"goat-examples-vercel-ai-viem": patch
"@goat-sdk/core": patch
---

Add mint plugin to Crossmint
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const { custodial } = crossmint(apiKey);
wallet: await custodial({
chain: "solana",
email: email,
env: "staging",
connection: new Connection("https://api.devnet.solana.com", "confirmed"),
}),
});
Expand Down
2 changes: 1 addition & 1 deletion typescript/examples/vercel-ai/viem/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const walletClient = createWalletClient({
model: openai("gpt-4o-mini"),
tools: tools,
maxSteps: 5,
prompt: "Get my balance in USDC",
prompt: "Get the balance of the USDC token",
});

console.log(result.text);
Expand Down
6 changes: 5 additions & 1 deletion typescript/packages/core/src/wallets/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type Balance = {
* @param id - Chain ID, optional for EVM
*/
export type Chain = {
type: "evm" | "solana";
type: "evm" | "solana" | "aptos";
id?: number; // optional for EVM
};

Expand All @@ -26,6 +26,10 @@ export type SolanaChain = Chain & {
type: "solana";
};

export type AptosChain = Chain & {
type: "aptos";
};

export interface WalletClient {
getAddress: () => string;
getChain: () => Chain;
Expand Down
1 change: 1 addition & 0 deletions typescript/packages/wallets/crossmint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"dependencies": {
"@crossmint/common-sdk-base": "0.3.1",
"@goat-sdk/core": "workspace:*",
"@solana/web3.js": "catalog:",
"abitype": "^1.0.6",
Expand Down
10 changes: 4 additions & 6 deletions typescript/packages/wallets/crossmint/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { CrossmintApiClient } from "@crossmint/common-sdk-base";
import type { EVMTypedData } from "@goat-sdk/core";
import type { SupportedSmartWalletChains } from "./chains";

Expand Down Expand Up @@ -191,10 +192,8 @@ type APIResponse =
| SignTypedDataResponse
| ApproveSignatureResponse;

export function createCrossmintAPI(apiKey: string, env: "staging" | "production") {
const baseUrl =
env === "staging" ? "https://staging.crossmint.com/api/v1-alpha2" : "https://wwww.crossmint.com/api/v1-alpha2";

export function createCrossmintAPI(crossmintClient: CrossmintApiClient) {
const baseUrl = `${crossmintClient.baseUrl}/api/v1-alpha2`;
/**
* Makes an HTTP request to the Crossmint API.
*
Expand All @@ -208,8 +207,7 @@ export function createCrossmintAPI(apiKey: string, env: "staging" | "production"

// Set default headers and merge with any additional headers
const headers = new Headers({
"X-API-KEY": apiKey,
"Content-Type": "application/json",
...crossmintClient.authHeaders,
...(options.headers || {}),
});

Expand Down
106 changes: 97 additions & 9 deletions typescript/packages/wallets/crossmint/src/chains.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
import type { Chain as GoatChain } from "@goat-sdk/core";
import {
type Chain,
arbitrum,
arbitrumSepolia,
astarZkEVM,
astarZkyoto,
avalanche,
avalancheFuji,
base,
baseSepolia,
bsc,
chiliz,
mainnet,
optimism,
optimismSepolia,
polygon,
polygonAmoy,
sepolia,
shape,
shapeSepolia,
skaleNebula,
skaleNebulaTestnet,
victionTestnet,
xai,
xaiTestnet,
zora,
zoraSepolia,
} from "viem/chains";

const faucetChains = [
Expand Down Expand Up @@ -40,19 +54,69 @@ const smartWalletChains = [

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

const chainMap: Record<SupportedFaucetChains | SupportedSmartWalletChains, Chain> = {
arbitrum: arbitrum,
export const mintingChains = [
"arbitrum",
"arbitrum-sepolia",
"astar-zkevm",
"avalanche",
"avalanche-fuji",
"base",
"base-sepolia",
"bsc",
"chiliz",
"chiliz-spicy-testnet",
"ethereum",
"ethereum-sepolia",
"optimism",
"optimism-sepolia",
"polygon",
"polygon-amoy",
"shape",
"shape-sepolia",
"skale-nebula",
"skale-nebula-testnet",
"soneium-minato-testnet",
"xai",
"xai-sepolia-testnet",
"zkyoto",
"zora",
"zora-sepolia",
] as const;

export type SupportedMintingChains = (typeof mintingChains)[number];

const chainMap: Record<SupportedFaucetChains | SupportedSmartWalletChains | SupportedMintingChains, Chain> = {
arbitrum,
"arbitrum-sepolia": arbitrumSepolia,
base: base,
"astar-zkevm": astarZkEVM,
avalanche,
"avalanche-fuji": avalancheFuji,
base,
"base-sepolia": baseSepolia,
optimism: optimism,
bsc,
chiliz,
ethereum: mainnet,
optimism,
"optimism-sepolia": optimismSepolia,
polygon: polygon,
polygon,
"polygon-amoy": polygonAmoy,
"avalanche-fuji": avalancheFuji,
"ethereum-sepolia": sepolia,
shape,
"shape-sepolia": shapeSepolia,
"skale-nebula": skaleNebula,
"skale-nebula-testnet": skaleNebulaTestnet,
"viction-testnet": victionTestnet,
xai,
"xai-sepolia-testnet": xaiTestnet,
zkyoto: astarZkyoto,
zora,
"zora-sepolia": zoraSepolia,
"chiliz-spicy-testnet": {
id: 88882,
} as Chain,
"soneium-minato-testnet": {
id: 88882,
} as Chain,
};

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

const testnetChains = ["arbitrum-sepolia", "base-sepolia", "optimism-sepolia", "polygon-amoy"] as const;
export function getCrossmintChainString(chain: GoatChain): string {
if (chain.type === "solana") {
return "solana";
}
if (chain.type === "aptos") {
return "aptos";
}

export function getEnv(chain: SupportedSmartWalletChains): "staging" | "production" {
return (testnetChains as readonly string[]).includes(chain) ? "staging" : "production";
if (chain.type === "evm") {
// from chain.id figure out the chain name
const chainName = Object.keys(chainMap).find(
(key): key is keyof typeof chainMap => chainMap[key as keyof typeof chainMap].id === chain.id,
);
if (!chainName) {
throw new Error(`Unsupported chain: ${chain.id}`);
}
return chainName;
}

throw new Error(`Unsupported chain: ${chain.type}`);
}

const testnetChains = ["arbitrum-sepolia", "base-sepolia", "optimism-sepolia", "polygon-amoy"] as const;

const faucetChainIds = new Set(faucetChains.map((chainName) => chainMap[chainName].id));

export function isChainSupportedByFaucet(chainId: number): boolean {
return faucetChainIds.has(chainId);
}

const mintingChainIds = new Set(mintingChains.map((chainName) => chainMap[chainName].id));

export function isChainSupportedByMinting(chainId: number): boolean {
return mintingChainIds.has(chainId);
}
Loading

0 comments on commit bf161b7

Please sign in to comment.