forked from goat-sdk/goat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plugin: Solana cNFT Transfers (goat-sdk#13)
* changes * changes * changes * changes * changes * fix formatter * more diff fixing * changes * changes * temp example * changes * fix build * changes * fix * changes
- Loading branch information
1 parent
7703f48
commit 1547668
Showing
11 changed files
with
5,835 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
typescript/biome.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"name": "@goat-sdk/plugin-solana-nfts", | ||
"version": "0.1.0", | ||
"files": ["dist/**/*", "README.md", "package.json"], | ||
"scripts": { | ||
"build": "tsup", | ||
"clean": "rm -rf dist", | ||
"test": "vitest run --passWithNoTests" | ||
}, | ||
"sideEffects": false, | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"dependencies": { | ||
"@goat-sdk/core": "workspace:*", | ||
"@metaplex-foundation/digital-asset-standard-api": "1.0.0", | ||
"@metaplex-foundation/mpl-bubblegum": "3.1.0", | ||
"@metaplex-foundation/umi": "^0.9.2", | ||
"@metaplex-foundation/umi-bundle-defaults": "0.9.2", | ||
"@metaplex-foundation/umi-web3js-adapters": "0.8.10", | ||
"@solana/web3.js": "1.95.8", | ||
"viem": "^2.21.49", | ||
"zod": "^3.23.8" | ||
}, | ||
"peerDependencies": { | ||
"@goat-sdk/core": "workspace:*", | ||
"viem": "^2.21.49" | ||
}, | ||
"homepage": "https://ohmygoat.dev", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/goat-sdk/goat.git" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/goat-sdk/goat/issues" | ||
}, | ||
"keywords": ["ai", "agents", "web3"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./nfts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { type Connection, PublicKey } from "@solana/web3.js"; | ||
import { z } from "zod"; | ||
import type { Plugin, SolanaWalletClient } from "@goat-sdk/core"; | ||
import { getAssetWithProof, mplBubblegum, transfer } from "@metaplex-foundation/mpl-bubblegum"; | ||
import { createUmi } from "@metaplex-foundation/umi-bundle-defaults"; | ||
import { fromWeb3JsPublicKey, toWeb3JsInstruction } from "@metaplex-foundation/umi-web3js-adapters"; | ||
|
||
export function nfts(connection: Connection): Plugin<SolanaWalletClient> { | ||
return { | ||
name: "nfts", | ||
supportsSmartWallets: () => false, | ||
supportsChain: (chain) => chain.type === "solana", | ||
getTools: async () => { | ||
return [ | ||
{ | ||
name: "transfer_nft", | ||
description: "This {{tool}} sends an NFT from your wallet to an address on a Solana chain.", | ||
parameters: transferNFTParametersSchema, | ||
method: transferNFTMethod(connection), | ||
}, | ||
]; | ||
}, | ||
}; | ||
} | ||
|
||
const transferNFTParametersSchema = z.object({ | ||
recipientAddress: z.string().describe("The address to send the NFT to"), | ||
assetId: z.string().describe("The asset ID of the NFT to send"), | ||
}); | ||
|
||
const transferNFTMethod = | ||
(connection: Connection) => | ||
async ( | ||
walletClient: SolanaWalletClient, | ||
parameters: z.infer<typeof transferNFTParametersSchema>, | ||
): Promise<string> => { | ||
const { recipientAddress, assetId } = parameters; | ||
const umi = createUmi(connection); | ||
umi.use(mplBubblegum()); | ||
const assetWithProof = await getAssetWithProof(umi, fromWeb3JsPublicKey(new PublicKey(assetId))); | ||
const instructions = transfer(umi, { | ||
...assetWithProof, | ||
leafOwner: fromWeb3JsPublicKey(new PublicKey(walletClient.getAddress())), | ||
newLeafOwner: fromWeb3JsPublicKey(new PublicKey(recipientAddress)), | ||
}).getInstructions(); | ||
|
||
const result = await walletClient.sendTransaction({ | ||
instructions: instructions.map(toWeb3JsInstruction), | ||
}); | ||
|
||
return result.hash; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/tsconfig", | ||
"extends": "../../../tsconfig.base.json", | ||
"include": ["src/**/*"], | ||
"exclude": ["node_modules", "dist"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { defineConfig } from "tsup"; | ||
import { treeShakableConfig } from "../../../tsup.config.base"; | ||
|
||
export default defineConfig({ | ||
...treeShakableConfig, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.