-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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 #2296 from 0xCardinalError/feat/gitcoin_passport_p…
…lugin feat: Gitcoin passport
- Loading branch information
Showing
11 changed files
with
273 additions
and
2 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
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,38 @@ | ||
# `@elizaos/plugin-passport` | ||
|
||
This plugin provides actions for interacting with Gitcoin passport | ||
https://docs.passport.xyz/building-with-passport/passport-api/overview | ||
|
||
--- | ||
|
||
## Installation | ||
|
||
Just add it under your character profile in plugins as | ||
|
||
``` | ||
"plugins": [ | ||
"@elizaos/plugin-gitcoin-passport" | ||
], | ||
``` | ||
|
||
## Configuration | ||
|
||
Getting Your API Key | ||
|
||
1. Log in to the developer portal: Go to developer.passport.xyz and log in to your account by connecting your wallet. | ||
2. Navigate to the API Keys section: After logging in, go to the "API Keys" section. | ||
3. Generate an API key: Click on the "+ Create a Key" button to generate a unique API key for your account. | ||
4. Store your API key securely: Store your API key in a secure place, as it will be used to access the Passport API. | ||
|
||
Getting your Scorer ID | ||
|
||
1. Log in to the Developer Portal: Go to developer.passport.xyz and log in to your account by connecting your wallet. | ||
2. Navigate to the Scorer section: After logging in, go to the "Scorer" section | ||
3. Create a Scorer: Click on the "+ Create a Scorer" button and input a Scorer name and description. Make sure you use the Unique Humanity scorer, and not the Binary scorer. | ||
4. Find your Scorer ID: Click on the newly created Scorer and you will see the Scorer ID in the page URL. | ||
Example: https://developer.passport.xyz/dashboard/scorer/{scorer_id} | ||
|
||
## Usage | ||
|
||
Results are saved as message and agents can retrive it from there for different use cases. | ||
Default passport treshold of 20 is used, but you can pick your own value and match it agains that |
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,20 @@ | ||
{ | ||
"name": "@elizaos/plugin-gitcoin-passport", | ||
"version": "0.1.7-alpha.2", | ||
"main": "dist/index.js", | ||
"type": "module", | ||
"types": "dist/index.d.ts", | ||
"dependencies": { | ||
"@elizaos/core": "workspace:*", | ||
"tsup": "8.3.5" | ||
}, | ||
"scripts": { | ||
"build": "tsup --format esm --dts", | ||
"dev": "tsup --format esm --dts --watch", | ||
"test": "vitest run", | ||
"lint": "eslint --fix --cache ." | ||
}, | ||
"peerDependencies": { | ||
"whatwg-url": "7.1.0" | ||
} | ||
} |
137 changes: 137 additions & 0 deletions
137
packages/plugin-gitcoin-passport/src/actions/getScore.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,137 @@ | ||
import { | ||
Action, | ||
elizaLogger, | ||
IAgentRuntime, | ||
Memory, | ||
HandlerCallback, | ||
State, | ||
getEmbeddingZeroVector, | ||
Content, | ||
composeContext, | ||
generateMessageResponse, | ||
ModelClass, | ||
} from "@elizaos/core"; | ||
|
||
interface PassportScore { | ||
address: string; | ||
score: string; | ||
threshold: string; | ||
passing_score: string; | ||
} | ||
|
||
const createTokenMemory = async ( | ||
runtime: IAgentRuntime, | ||
_message: Memory, | ||
formattedOutput: string | ||
) => { | ||
const memory: Memory = { | ||
userId: _message.userId, | ||
agentId: _message.agentId, | ||
roomId: _message.roomId, | ||
content: { text: formattedOutput }, | ||
createdAt: Date.now(), | ||
embedding: getEmbeddingZeroVector(), | ||
}; | ||
await runtime.messageManager.createMemory(memory); | ||
}; | ||
|
||
export const addressTemplate = `From previous sentence extract only the Ethereum address being asked about. | ||
Respond with a JSON markdown block containing only the extracted value: | ||
\`\`\`json | ||
{ | ||
"address": string | null | ||
} | ||
\`\`\` | ||
`; | ||
|
||
export const getPassportScoreAction: Action = { | ||
name: "GET_PASSPORT_SCORE", | ||
description: "Get score from Passport API for an address", | ||
validate: async (runtime: IAgentRuntime, _message: Memory) => { | ||
elizaLogger.log("Validating runtime for GET_PASSPORT_SCORE..."); | ||
const apiKey = runtime.getSetting("PASSPORT_API_KEY"); | ||
const scorerId = runtime.getSetting("PASSPORT_SCORER"); | ||
if (!apiKey || !scorerId) { | ||
elizaLogger.error( | ||
"Missing PASSPORT_API_KEY or PASSPORT_SCORER settings" | ||
); | ||
return false; | ||
} | ||
return true; | ||
}, | ||
handler: async ( | ||
runtime: IAgentRuntime, | ||
_message: Memory, | ||
state: State, | ||
_options: any, | ||
callback: HandlerCallback | ||
) => { | ||
elizaLogger.log("Starting GET_PASSPORT_SCORE handler..."); | ||
const apiKey = runtime.getSetting("PASSPORT_API_KEY"); | ||
const scorerId = runtime.getSetting("PASSPORT_SCORER"); | ||
|
||
if (!state) { | ||
state = (await runtime.composeState(_message)) as State; | ||
} else { | ||
state = await runtime.updateRecentMessageState(state); | ||
} | ||
|
||
const context = composeContext({ | ||
state, | ||
template: `${_message.content.text}\n${addressTemplate}`, | ||
}); | ||
|
||
const addressRequest = await generateMessageResponse({ | ||
runtime, | ||
context, | ||
modelClass: ModelClass.SMALL, | ||
}); | ||
|
||
const address = addressRequest.address as string; | ||
|
||
if (!address) { | ||
callback({ text: "Address is required." }, []); | ||
return; | ||
} | ||
|
||
try { | ||
const response = await fetch( | ||
`https://api.passport.xyz/v2/stamps/${scorerId}/score/${address}`, | ||
{ | ||
method: "GET", | ||
headers: { | ||
"X-API-KEY": apiKey, | ||
accept: "application/json", | ||
}, | ||
} | ||
); | ||
|
||
if (!response.ok) { | ||
throw new Error(`HTTP error! status: ${response.status}`); | ||
} | ||
|
||
const data: PassportScore = await response.json(); | ||
const formattedOutput = `Address: ${data.address}\nScore: ${data.score}${data.passing_score ? "\nScore is above threshold" : `\nScore is below threshold (${data.threshold})`}`; | ||
|
||
await createTokenMemory(runtime, _message, formattedOutput); | ||
|
||
callback({ text: formattedOutput }, []); | ||
} catch (error) { | ||
elizaLogger.error("Error fetching Passport score:", error); | ||
callback( | ||
{ | ||
text: "Failed to fetch Passport score. Please check the logs for more details.", | ||
}, | ||
[] | ||
); | ||
} | ||
}, | ||
examples: [], | ||
similes: [ | ||
"GET_PASSPORT_SCORE", | ||
"FETCH_PASSPORT_SCORE", | ||
"CHECK_PASSPORT_SCORE", | ||
"VIEW_PASSPORT_SCORE", | ||
], | ||
}; |
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,15 @@ | ||
export * from "./actions/getScore"; | ||
|
||
import type { Plugin } from "@elizaos/core"; | ||
import { getPassportScoreAction } from "./actions/getScore"; | ||
|
||
export const gitcoinPassportPlugin: Plugin = { | ||
name: "passport", | ||
description: "Gitcoin passport integration plugin", | ||
providers: [], | ||
evaluators: [], | ||
services: [], | ||
actions: [getPassportScoreAction], | ||
}; | ||
|
||
export default gitcoinPassportPlugin; |
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,15 @@ | ||
{ | ||
"extends": "../core/tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "dist", | ||
"rootDir": "./src", | ||
"typeRoots": [ | ||
"./node_modules/@types", | ||
"./src/types" | ||
], | ||
"declaration": true | ||
}, | ||
"include": [ | ||
"src" | ||
] | ||
} |
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,21 @@ | ||
import { defineConfig } from "tsup"; | ||
|
||
export default defineConfig({ | ||
entry: ["src/index.ts"], | ||
outDir: "dist", | ||
sourcemap: true, | ||
clean: true, | ||
format: ["esm"], // Ensure you're targeting CommonJS | ||
external: [ | ||
"dotenv", // Externalize dotenv to prevent bundling | ||
"fs", // Externalize fs to use Node.js built-in module | ||
"path", // Externalize other built-ins if necessary | ||
"@reflink/reflink", | ||
"@node-llama-cpp", | ||
"https", | ||
"http", | ||
"agentkeepalive", | ||
"viem", | ||
"@lifi/sdk", | ||
], | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.