-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1011 from xwxtwd/feat/add_plugin-nft-generator
feat: Add plugin-nft-generation: create Solana NFT collections.
- Loading branch information
Showing
18 changed files
with
1,047 additions
and
1 deletion.
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
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
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 @@ | ||
* | ||
|
||
!dist/** | ||
!package.json | ||
!readme.md | ||
!tsup.config.ts |
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,3 @@ | ||
import eslintGlobalConfig from "../../eslint.config.mjs"; | ||
|
||
export default [...eslintGlobalConfig]; |
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,30 @@ | ||
{ | ||
"name": "@ai16z/plugin-nft-generation", | ||
"version": "0.1.5-alpha.5", | ||
"main": "dist/index.js", | ||
"type": "module", | ||
"types": "dist/index.d.ts", | ||
"dependencies": { | ||
"@ai16z/eliza": "workspace:*", | ||
"@ai16z/plugin-image-generation": "workspace:*", | ||
"@ai16z/plugin-node": "workspace:*", | ||
"@metaplex-foundation/mpl-token-metadata": "^3.3.0", | ||
"@metaplex-foundation/mpl-toolbox": "^0.9.4", | ||
"@metaplex-foundation/umi": "^0.9.2", | ||
"@metaplex-foundation/umi-bundle-defaults": "^0.9.2", | ||
"@solana-developers/helpers": "^2.5.6", | ||
"@solana/web3.js": "1.95.5", | ||
"bs58": "6.0.0", | ||
"express": "4.21.1", | ||
"node-cache": "5.1.2", | ||
"tsup": "8.3.5" | ||
}, | ||
"scripts": { | ||
"build": "tsup --format esm --dts", | ||
"dev": "tsup --format esm --dts --watch", | ||
"lint": "eslint . --fix" | ||
}, | ||
"peerDependencies": { | ||
"whatwg-url": "7.1.0" | ||
} | ||
} |
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,165 @@ | ||
import express from "express"; | ||
|
||
import { AgentRuntime } from "@ai16z/eliza"; | ||
import { createCollection } from "./handlers/createCollection.ts"; | ||
import { createNFT, createNFTMetadata } from "./handlers/createNFT.ts"; | ||
import { verifyNFT } from "./handlers/verifyNFT.ts"; | ||
|
||
export function createNFTApiRouter(agents: Map<string, AgentRuntime>) { | ||
const router = express.Router(); | ||
|
||
router.post( | ||
"/api/nft-generation/create-collection", | ||
async (req: express.Request, res: express.Response) => { | ||
const agentId = req.body.agentId; | ||
const fee = req.body.fee || 0; | ||
const runtime = agents.get(agentId); | ||
if (!runtime) { | ||
res.status(404).send("Agent not found"); | ||
return; | ||
} | ||
try { | ||
const collectionAddressRes = await createCollection({ | ||
runtime, | ||
collectionName: runtime.character.name, | ||
fee | ||
}); | ||
|
||
res.json({ | ||
success: true, | ||
data: collectionAddressRes, | ||
}); | ||
} catch (e: any) { | ||
console.log(e); | ||
res.json({ | ||
success: false, | ||
data: JSON.stringify(e), | ||
}); | ||
} | ||
} | ||
); | ||
|
||
|
||
router.post( | ||
"/api/nft-generation/create-nft-metadata", | ||
async (req: express.Request, res: express.Response) => { | ||
const agentId = req.body.agentId; | ||
const collectionName = req.body.collectionName; | ||
const collectionAddress = req.body.collectionAddress; | ||
const collectionAdminPublicKey = req.body.collectionAdminPublicKey; | ||
const collectionFee = req.body.collectionFee; | ||
const tokenId = req.body.tokenId; | ||
const runtime = agents.get(agentId); | ||
if (!runtime) { | ||
res.status(404).send("Agent not found"); | ||
return; | ||
} | ||
|
||
try { | ||
const nftInfo = await createNFTMetadata({ | ||
runtime, | ||
collectionName, | ||
collectionAdminPublicKey, | ||
collectionFee, | ||
tokenId, | ||
}); | ||
|
||
res.json({ | ||
success: true, | ||
data: { | ||
...nftInfo, | ||
collectionAddress, | ||
}, | ||
}); | ||
} catch (e: any) { | ||
console.log(e); | ||
res.json({ | ||
success: false, | ||
data: JSON.stringify(e), | ||
}); | ||
} | ||
} | ||
); | ||
|
||
router.post( | ||
"/api/nft-generation/create-nft", | ||
async (req: express.Request, res: express.Response) => { | ||
const agentId = req.body.agentId; | ||
const collectionName = req.body.collectionName; | ||
const collectionAddress = req.body.collectionAddress; | ||
const collectionAdminPublicKey = req.body.collectionAdminPublicKey; | ||
const collectionFee = req.body.collectionFee; | ||
const tokenId = req.body.tokenId; | ||
const runtime = agents.get(agentId); | ||
if (!runtime) { | ||
res.status(404).send("Agent not found"); | ||
return; | ||
} | ||
|
||
try { | ||
const nftRes = await createNFT({ | ||
runtime, | ||
collectionName, | ||
collectionAddress, | ||
collectionAdminPublicKey, | ||
collectionFee, | ||
tokenId, | ||
}); | ||
|
||
res.json({ | ||
success: true, | ||
data: nftRes, | ||
}); | ||
} catch (e: any) { | ||
console.log(e); | ||
res.json({ | ||
success: false, | ||
data: JSON.stringify(e), | ||
}); | ||
} | ||
} | ||
); | ||
|
||
|
||
router.post( | ||
"/api/nft-generation/verify-nft", | ||
async (req: express.Request, res: express.Response) => { | ||
const agentId = req.body.agentId; | ||
const collectionAddress = req.body.collectionAddress; | ||
const NFTAddress = req.body.nftAddress; | ||
const token = req.body.token; | ||
|
||
const runtime = agents.get(agentId); | ||
if (!runtime) { | ||
res.status(404).send("Agent not found"); | ||
return; | ||
} | ||
const verifyToken = runtime.getSetting('SOLANA_VERIFY_TOKEN') | ||
if (token !== verifyToken) { | ||
res.status(401).send(" Access denied for translation"); | ||
return; | ||
} | ||
try { | ||
const {success} = await verifyNFT({ | ||
runtime, | ||
collectionAddress, | ||
NFTAddress, | ||
}); | ||
|
||
res.json({ | ||
success: true, | ||
data: success ? 'verified' : 'unverified', | ||
}); | ||
} catch (e: any) { | ||
console.log(e); | ||
res.json({ | ||
success: false, | ||
data: JSON.stringify(e), | ||
}); | ||
} | ||
} | ||
); | ||
|
||
|
||
return router; | ||
} |
Oops, something went wrong.