-
Notifications
You must be signed in to change notification settings - Fork 244
Plugin: Solana cNFT Transfers #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ad7fe96
changes
bryan-eastwood3 b13268b
changes
bryan-eastwood3 d058113
changes
bryan-eastwood3 aafdc37
fix merge
bryan-eastwood3 f5ceaf9
changes
bryan-eastwood3 614b5f6
changes
bryan-eastwood3 e1b3f94
fix formatter
bryan-eastwood3 10f27db
more diff fixing
bryan-eastwood3 093d23c
merge
bryan-eastwood3 6424cf7
changes
bryan-eastwood3 d509536
changes
bryan-eastwood3 2f98acb
temp example
bryan-eastwood3 328bcd6
changes
bryan-eastwood3 7d0914a
fix build
bryan-eastwood3 7a7e88f
changes
bryan-eastwood3 f11af6f
fix
bryan-eastwood3 ff8b9ea
changes
bryan-eastwood3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -2,7 +2,11 @@ | |
"name": "@goat-sdk/core", | ||
"version": "0.3.10", | ||
"sideEffects": false, | ||
"files": ["dist/**/*", "README.md", "package.json"], | ||
"files": [ | ||
"dist/**/*", | ||
"README.md", | ||
"package.json" | ||
], | ||
"scripts": { | ||
"build": "tsup", | ||
"clean": "rm -rf dist", | ||
|
@@ -20,6 +24,9 @@ | |
"vitest": "^2.1.5" | ||
}, | ||
"dependencies": { | ||
"@metaplex-foundation/mpl-bubblegum": "^4.2.1", | ||
"@metaplex-foundation/umi-bundle-defaults": "^0.9.2", | ||
"@metaplex-foundation/umi-web3js-adapters": "^0.9.2", | ||
"@solana/web3.js": "1.95.8", | ||
"abitype": "^1.0.6", | ||
"viem": "^2.21.49", | ||
|
@@ -40,6 +47,10 @@ | |
"bugs": { | ||
"url": "https://github.com/goat-sdk/goat/issues" | ||
}, | ||
"keywords": ["ai", "agents", "web3"], | ||
"keywords": [ | ||
"ai", | ||
"agents", | ||
"web3" | ||
], | ||
"packageManager": "[email protected]" | ||
} |
This file contains hidden or 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,64 @@ | ||
import { Connection, PublicKey } from "@solana/web3.js"; | ||
import { parseUnits } from "viem"; | ||
import type { SolanaWalletClient } from "../wallets"; | ||
import type { Plugin } from "./plugins"; | ||
import { z } from "zod"; | ||
import { SystemProgram } from "@solana/web3.js"; | ||
import { | ||
mplBubblegum, | ||
getAssetWithProof, | ||
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 transferNFT(): Plugin<SolanaWalletClient> { | ||
return { | ||
name: "transfer_nft", | ||
supportsSmartWallets: () => true, | ||
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, | ||
}, | ||
]; | ||
}, | ||
}; | ||
} | ||
|
||
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"), | ||
}); | ||
|
||
async function transferNFTMethod( | ||
walletClient: SolanaWalletClient, | ||
parameters: z.infer<typeof transferNFTParametersSchema>, | ||
): Promise<string> { | ||
const { recipientAddress, assetId } = parameters; | ||
const umi = createUmi(walletClient.connection); | ||
bryan-eastwood3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -2,7 +2,11 @@ | |
"name": "@goat-sdk/crossmint", | ||
"version": "0.1.5", | ||
"sideEffects": false, | ||
"files": ["dist/**/*", "README.md", "package.json"], | ||
"files": [ | ||
"dist/**/*", | ||
"README.md", | ||
"package.json" | ||
], | ||
"scripts": { | ||
"build": "tsup", | ||
"clean": "rm -rf dist", | ||
|
@@ -21,6 +25,9 @@ | |
}, | ||
"dependencies": { | ||
"@goat-sdk/core": "workspace:*", | ||
"@metaplex-foundation/mpl-bubblegum": "^4.2.1", | ||
"@metaplex-foundation/umi": "^0.9.2", | ||
"@metaplex-foundation/umi-bundle-defaults": "^0.9.2", | ||
"@solana/web3.js": "1.95.8", | ||
"abitype": "^1.0.6", | ||
"bs58": "^6.0.0", | ||
|
@@ -45,6 +52,10 @@ | |
"bugs": { | ||
"url": "https://github.com/goat-sdk/goat/issues" | ||
}, | ||
"keywords": ["ai", "agents", "web3"], | ||
"keywords": [ | ||
"ai", | ||
"agents", | ||
"web3" | ||
], | ||
"packageManager": "[email protected]" | ||
} |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.