Skip to content
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

Fix/charity #852

Merged
merged 3 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,11 @@ INTERNET_COMPUTER_ADDRESS=
# Aptos
APTOS_PRIVATE_KEY= # Aptos private key
APTOS_NETWORK= # must be one of mainnet, testnet

# Charity Configuration
IS_CHARITABLE=false # Set to true to enable charity donations
CHARITY_ADDRESS_BASE=0x1234567890123456789012345678901234567890
CHARITY_ADDRESS_SOL=pWvDXKu6CpbKKvKQkZvDA66hgsTB6X2AgFxksYogHLV
CHARITY_ADDRESS_ETH=0x750EF1D7a0b4Ab1c97B7A623D7917CcEb5ea779C
CHARITY_ADDRESS_ARB=0x1234567890123456789012345678901234567890
CHARITY_ADDRESS_POL=0x1234567890123456789012345678901234567890
Comment on lines +194 to +199
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please update the BASE address to the ETH address they should be the same.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And arb and poly should be empty for now as they are dummy addresses atm :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're removing hardcoded wallets its weird to force projects to give charity

23 changes: 23 additions & 0 deletions packages/client-whatsapp/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "@ai16z/client-whatsapp",
"version": "0.0.1",
"description": "WhatsApp client for Eliza",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"clean": "rimraf dist",
"test": "jest",
"lint": "eslint src --ext .ts"
},
"dependencies": {
"@ai16z/eliza": "workspace:*"
},
"devDependencies": {
"@types/node": "^20.0.0",
"typescript": "^5.0.0",
"rimraf": "^5.0.0",
"jest": "^29.0.0",
"@types/jest": "^29.0.0"
}
}
Empty file.
21 changes: 21 additions & 0 deletions packages/client-whatsapp/src/environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { IAgentRuntime } from "@ai16z/eliza";

export async function validateWhatsAppConfig(
runtime: IAgentRuntime
): Promise<void> {
const requiredSettings = [
"WHATSAPP_API_TOKEN",
"WHATSAPP_PHONE_NUMBER_ID",
"WHATSAPP_APP_ID",
"WHATSAPP_APP_SECRET",
"WHATSAPP_WEBHOOK_VERIFY_TOKEN"
];

for (const setting of requiredSettings) {
if (!runtime.getSetting(setting)) {
throw new Error(
`Missing required WhatsApp configuration: ${setting}`
);
}
}
}
28 changes: 28 additions & 0 deletions packages/client-whatsapp/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { elizaLogger } from "@ai16z/eliza";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why these whatsapp changes are included

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like upstream changes from before idk

import { Client, IAgentRuntime } from "@ai16z/eliza";
import { WhatsAppClient } from "./whatsappClient";
import { validateWhatsAppConfig } from "../../../eliza/packages/client-whatsapp/src/environment";

export const WhatsAppClientInterface: Client = {
start: async (runtime: IAgentRuntime) => {
await validateWhatsAppConfig(runtime);

const client = new WhatsAppClient(
runtime,
runtime.getSetting("WHATSAPP_API_TOKEN"),
runtime.getSetting("WHATSAPP_PHONE_NUMBER_ID")
);

await client.start();

elizaLogger.success(
`✅ WhatsApp client successfully started for character ${runtime.character.name}`
);
return client;
},
stop: async (runtime: IAgentRuntime) => {
elizaLogger.warn("WhatsApp client stopping...");
},
};

export default WhatsAppClientInterface;
30 changes: 16 additions & 14 deletions packages/plugin-coinbase/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,22 +380,24 @@ export async function executeTransfer(wallet: Wallet, amount: number, sourceAsse

/**
* Gets the charity address based on the network.
* For now we are giving to the following charity, but will make this configurable in the future
* https://www.givedirectly.org/crypto/?_gl=1*va5e6k*_gcl_au*MTM1NDUzNTk5Mi4xNzMzMDczNjA3*_ga*OTIwMDMwNTMwLjE3MzMwNzM2MDg.*_ga_GV8XF9FJ16*MTczMzA3MzYwNy4xLjEuMTczMzA3MzYyMi40NS4wLjA.
* @param {string} network - The network to use.
* @param {boolean} isCharitable - Whether charity donations are enabled
* @throws {Error} If charity address for the network is not configured when charity is enabled
*/
export function getCharityAddress(network: string): string {
let charityAddress;
if (network === "base") {
charityAddress = "0x1234567890123456789012345678901234567890";
} else if (network === "sol") {
charityAddress = "pWvDXKu6CpbKKvKQkZvDA66hgsTB6X2AgFxksYogHLV";
} else if (network === "eth") {
charityAddress = "0x750EF1D7a0b4Ab1c97B7A623D7917CcEb5ea779C";
} else if (network === "arb") {
charityAddress = "0x1234567890123456789012345678901234567890";
} else if (network === "pol") {
charityAddress = "0x1234567890123456789012345678901234567890";
export function getCharityAddress(network: string, isCharitable: boolean = false): string | null {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will also want to handle what happens when getCharityAddress returns null. I had some changes here for that feel free to take a look and integrate: f7ace73

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its a consensus of the group to have charitble as a boolean set to false

// Check both environment variable and passed parameter
const isCharityEnabled = process.env.IS_CHARITABLE === 'true' && isCharitable;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's funny because I was about to make this nullable :) Great minds!


Comment on lines +389 to +390
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use runtime.getSetting instead of this check thanks :)

if (!isCharityEnabled) {
return null;
}

const networkKey = `CHARITY_ADDRESS_${network.toUpperCase()}`;
const charityAddress = process.env[networkKey];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here :)


if (!charityAddress) {
throw new Error(`Charity address not configured for network ${network}. Please set ${networkKey} in your environment variables.`);
}

return charityAddress;
}
Loading
Loading