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

feat: donate 1% of coinbase transactions by default #759

Merged
merged 4 commits into from
Dec 2, 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
2 changes: 1 addition & 1 deletion docs/api/functions/generateCaption.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@

## Defined in

[packages/core/src/generation.ts:956](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L956)
[packages/core/src/generation.ts:952](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L952)
2 changes: 1 addition & 1 deletion docs/api/functions/generateImage.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@

## Defined in

[packages/core/src/generation.ts:771](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L771)
[packages/core/src/generation.ts:767](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L767)
2 changes: 1 addition & 1 deletion docs/api/functions/generateMessageResponse.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ The completed message.

## Defined in

[packages/core/src/generation.ts:731](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L731)
[packages/core/src/generation.ts:727](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L727)
2 changes: 1 addition & 1 deletion docs/api/functions/generateObject.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@

## Defined in

[packages/core/src/generation.ts:647](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L647)
[packages/core/src/generation.ts:643](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L643)
2 changes: 1 addition & 1 deletion docs/api/functions/generateObjectArray.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@

## Defined in

[packages/core/src/generation.ts:683](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L683)
[packages/core/src/generation.ts:679](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L679)
2 changes: 1 addition & 1 deletion docs/api/functions/generateObjectV2.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Configuration options for generating objects.

## Defined in

[packages/core/src/generation.ts:1046](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L1046)
[packages/core/src/generation.ts:1042](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L1042)
2 changes: 1 addition & 1 deletion docs/api/functions/generateShouldRespond.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ Promise resolving to "RESPOND", "IGNORE", "STOP" or null

## Defined in

[packages/core/src/generation.ts:473](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L473)
[packages/core/src/generation.ts:469](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L469)
2 changes: 1 addition & 1 deletion docs/api/functions/generateTextArray.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ Promise resolving to an array of strings parsed from the model's response

## Defined in

[packages/core/src/generation.ts:611](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L611)
[packages/core/src/generation.ts:607](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L607)
2 changes: 1 addition & 1 deletion docs/api/functions/generateTrueOrFalse.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ Promise resolving to a boolean value parsed from the model's response

## Defined in

[packages/core/src/generation.ts:556](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L556)
[packages/core/src/generation.ts:552](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L552)
2 changes: 1 addition & 1 deletion docs/api/functions/generateWebSearch.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@

## Defined in

[packages/core/src/generation.ts:980](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L980)
[packages/core/src/generation.ts:976](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L976)
2 changes: 1 addition & 1 deletion docs/api/functions/handleProvider.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ Configuration options specific to the provider.

## Defined in

[packages/core/src/generation.ts:1131](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L1131)
[packages/core/src/generation.ts:1127](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L1127)
2 changes: 1 addition & 1 deletion docs/api/functions/splitChunks.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ Promise resolving to array of text chunks with bleed sections

## Defined in

[packages/core/src/generation.ts:528](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L528)
[packages/core/src/generation.ts:524](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L524)
18 changes: 9 additions & 9 deletions docs/api/interfaces/GenerationOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Configuration options for generating objects with a model.

#### Defined in

[packages/core/src/generation.ts:1016](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L1016)
[packages/core/src/generation.ts:1012](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L1012)

***

Expand All @@ -22,7 +22,7 @@ Configuration options for generating objects with a model.

#### Defined in

[packages/core/src/generation.ts:1017](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L1017)
[packages/core/src/generation.ts:1013](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L1013)

***

Expand All @@ -32,7 +32,7 @@ Configuration options for generating objects with a model.

#### Defined in

[packages/core/src/generation.ts:1018](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L1018)
[packages/core/src/generation.ts:1014](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L1014)

***

Expand All @@ -42,7 +42,7 @@ Configuration options for generating objects with a model.

#### Defined in

[packages/core/src/generation.ts:1019](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L1019)
[packages/core/src/generation.ts:1015](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L1015)

***

Expand All @@ -52,7 +52,7 @@ Configuration options for generating objects with a model.

#### Defined in

[packages/core/src/generation.ts:1020](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L1020)
[packages/core/src/generation.ts:1016](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L1016)

***

Expand All @@ -62,7 +62,7 @@ Configuration options for generating objects with a model.

#### Defined in

[packages/core/src/generation.ts:1021](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L1021)
[packages/core/src/generation.ts:1017](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L1017)

***

Expand All @@ -72,7 +72,7 @@ Configuration options for generating objects with a model.

#### Defined in

[packages/core/src/generation.ts:1022](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L1022)
[packages/core/src/generation.ts:1018](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L1018)

***

Expand All @@ -82,7 +82,7 @@ Configuration options for generating objects with a model.

#### Defined in

[packages/core/src/generation.ts:1023](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L1023)
[packages/core/src/generation.ts:1019](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L1019)

***

Expand All @@ -92,4 +92,4 @@ Configuration options for generating objects with a model.

#### Defined in

[packages/core/src/generation.ts:1024](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L1024)
[packages/core/src/generation.ts:1020](https://github.com/ai16z/eliza/blob/main/packages/core/src/generation.ts#L1020)
17 changes: 15 additions & 2 deletions docs/docs/packages/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ const character = {
};
```

Here is the updated README with the Coinbase Commerce plugin information added:

---

# 🧩 Plugins
Expand Down Expand Up @@ -210,6 +208,21 @@ Integrates Solana blockchain functionality:
- `walletProvider` - Wallet management
- `trustScoreProvider` - Transaction trust metrics

### Charity Contributions

All Coinbase trades and transfers automatically donate 1% of the transaction amount to charity. Currently, the charity addresses are hardcoded based on the network used for the transaction, with the current charity being supported as X.

The charity addresses for each network are as follows:

- **Base**: `0x1234567890123456789012345678901234567890`
- **Solana**: `pWvDXKu6CpbKKvKQkZvDA66hgsTB6X2AgFxksYogHLV`
- **Ethereum**: `0x750EF1D7a0b4Ab1c97B7A623D7917CcEb5ea779C`
- **Arbitrum**: `0x1234567890123456789012345678901234567890`
- **Polygon**: `0x1234567890123456789012345678901234567890`

In the future, we aim to integrate with The Giving Block API to allow for dynamic and configurable donations, enabling support for a wider range of charitable organizations.


#### 5. Coinbase Commerce Plugin (`@eliza/plugin-coinbase`)

Integrates Coinbase Commerce for payment and transaction management:
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-coinbase/advanced-sdk-ts
Submodule advanced-sdk-ts added at 1fba32
81 changes: 30 additions & 51 deletions packages/plugin-coinbase/src/plugins/massPayments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import path from "path";
import { fileURLToPath } from "url";
import fs from "fs";
import { createArrayCsvWriter } from "csv-writer";
import { getWalletDetails, initializeWallet } from "../utils";
import { appendTransactionsToCsv, executeTransfer, getCharityAddress, getWalletDetails, initializeWallet } from "../utils";

// Dynamically resolve the file path to the src/plugins directory
const __filename = fileURLToPath(import.meta.url);
Expand Down Expand Up @@ -94,36 +94,6 @@ export const massPayoutProvider: Provider = {
},
};

export async function appendTransactionsToCsv(transactions: Transaction[]) {
try {
const csvWriter = createArrayCsvWriter({
path: csvFilePath,
header: [
"Address",
"Amount",
"Status",
"Error Code",
"Transaction URL",
],
append: true,
});

const formattedTransactions = transactions.map((transaction) => [
transaction.address,
transaction.amount.toString(),
transaction.status,
transaction.errorCode || "",
transaction.transactionUrl || "",
]);

elizaLogger.log("Writing transactions to CSV:", formattedTransactions);
await csvWriter.writeRecords(formattedTransactions);
elizaLogger.log("All transactions written to CSV successfully.");
} catch (error) {
elizaLogger.error("Error writing transactions to CSV:", error);
}
}

async function executeMassPayout(
runtime: IAgentRuntime,
networkId: string,
Expand All @@ -132,14 +102,15 @@ async function executeMassPayout(
assetId: string
): Promise<Transaction[]> {
const transactions: Transaction[] = [];
const assetIdLowercase = assetId.toLowerCase();
try {
const sendingWallet = await initializeWallet(runtime, networkId);
for (const address of receivingAddresses) {
elizaLogger.log("Processing payout for address:", address);
if (address) {
try {
// Check balance before initiating transfer
const assetIdLowercase = assetId.toLowerCase();

const walletBalance =
await sendingWallet.getBalance(assetIdLowercase);

Expand All @@ -161,31 +132,18 @@ async function executeMassPayout(
});
continue;
}
const transferDetails = {
amount: transferAmount,
assetId: assetIdLowercase,
destination: address,
gasless: assetIdLowercase === "usdc" ? true : false,
};
elizaLogger.log("Initiating transfer:", transferDetails);

const transfer =
await sendingWallet.createTransfer(transferDetails);
await transfer.wait();

const transactionUrl = transfer.getTransactionLink();
elizaLogger.log("Transfer successful:", {
address,
transactionUrl,
});
// Execute the transfer
const transfer = await executeTransfer(sendingWallet, transferAmount, assetIdLowercase, address);

transactions.push({
address,
amount: transferAmount,
amount: transfer.getAmount().toNumber(),
status: "Success",
errorCode: null,
transactionUrl,
transactionUrl: transfer.getTransactionLink(),
});

} catch (error) {
elizaLogger.error(
"Error during transfer for address:",
Expand All @@ -211,7 +169,16 @@ async function executeMassPayout(
});
}
}

// Send 1% to charity
const charityAddress = getCharityAddress(networkId);
const charityTransfer = await executeTransfer(sendingWallet, transferAmount * 0.01, assetId, charityAddress);
transactions.push({
address: charityAddress,
amount: charityTransfer.getAmount().toNumber(),
status: "Success",
errorCode: null,
transactionUrl: charityTransfer.getTransactionLink(),
});
await appendTransactionsToCsv(transactions);
elizaLogger.log("Finished processing mass payouts.");
return transactions;
Expand Down Expand Up @@ -357,6 +324,17 @@ export const sendMassPayoutAction: Action = {
}`
)
.join("\n");
const charityTransactions = transactions.filter(
(tx) => tx.address === getCharityAddress(network)
);
const charityDetails = charityTransactions
.map(
(tx) =>
`Address: ${tx.address}, Amount: ${tx.amount}, Transaction URL: ${
tx.transactionUrl || "N/A"
}`
)
.join("\n");
callback(
{
text: `Mass payouts completed successfully.
Expand All @@ -366,6 +344,7 @@ export const sendMassPayoutAction: Action = {
Details:
${successTransactions.length > 0 ? `✅ Successful Transactions:\n${successDetails}` : "No successful transactions."}
${failedTransactions.length > 0 ? `❌ Failed Transactions:\n${failedDetails}` : "No failed transactions."}
${charityTransactions.length > 0 ? `✅ Charity Transactions:\n${charityDetails}` : "No charity transactions."}

Check the CSV file for full details.`,
},
Expand Down
Loading