Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into pr/zhourunlai/1603
Browse files Browse the repository at this point in the history
  • Loading branch information
shakkernerd committed Dec 31, 2024
2 parents 0d044b3 + 66c66fd commit 2e49b21
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 99 deletions.
41 changes: 27 additions & 14 deletions packages/plugin-conflux/src/actions/confiPump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Memory,
State,
HandlerCallback,
elizaLogger,
} from "@elizaos/core";
import { generateObject, composeContext, ModelClass } from "@elizaos/core";
import {
Expand Down Expand Up @@ -38,7 +39,7 @@ async function ensureAllowance(
memeAddress: `0x${string}`,
amount: bigint
) {
console.log(
elizaLogger.log(
`Checking allowance: token: ${tokenAddress} meme: ${memeAddress} amount: ${amount}`
);

Expand All @@ -54,10 +55,10 @@ async function ensureAllowance(
args: [account.address, memeAddress],
});

console.log("allowance:", allowance);
elizaLogger.log("allowance:", allowance);

if (allowance < amount) {
console.log(
elizaLogger.log(
`allowance(${allowance}) is less than amount(${amount}), approving...`
);

Expand All @@ -73,11 +74,11 @@ async function ensureAllowance(
kzg: null,
});

console.log(`Approving hash: ${hash}`);
elizaLogger.log(`Approving hash: ${hash}`);
await publicClient.waitForTransactionReceipt({ hash });
console.log(`Approving success: ${hash}`);
elizaLogger.log(`Approving success: ${hash}`);
} else {
console.log(`No need to approve`);
elizaLogger.log(`No need to approve`);
}
}

Expand Down Expand Up @@ -213,9 +214,13 @@ export const confiPump: Action = {
switch (contentObject.action) {
case "CREATE_TOKEN":
if (!isPumpCreateContent(contentObject)) {
throw new Error("Invalid content");
elizaLogger.error(
"Invalid PumpCreateContent: ",
contentObject
);
throw new Error("Invalid PumpCreateContent");
}
console.log(
elizaLogger.log(
"creating: ",
contentObject.params.name,
contentObject.params.symbol,
Expand All @@ -235,13 +240,17 @@ export const confiPump: Action = {

case "BUY_TOKEN":
if (!isPumpBuyContent(contentObject)) {
throw new Error("Invalid content");
elizaLogger.error(
"Invalid PumpBuyContent: ",
contentObject
);
throw new Error("Invalid PumpBuyContent");
}
value = parseUnits(
contentObject.params.value.toString(),
18
);
console.log(
elizaLogger.log(
"buying: ",
contentObject.params.tokenAddress,
value
Expand All @@ -260,12 +269,16 @@ export const confiPump: Action = {

case "SELL_TOKEN":
if (!isPumpSellContent(contentObject)) {
throw new Error("Invalid content");
elizaLogger.error(
"Invalid PumpSellContent: ",
contentObject
);
throw new Error("Invalid PumpSellContent");
}
const tokenAddress = getAddress(
contentObject.params.tokenAddress as `0x${string}`
);
console.log(
elizaLogger.log(
"selling: ",
tokenAddress,
account.address,
Expand Down Expand Up @@ -312,7 +325,7 @@ export const confiPump: Action = {
value,
account,
});
console.log("simulate: ", simulate);
elizaLogger.log("simulate: ", simulate);

const hash = await walletClient.sendTransaction({
account,
Expand All @@ -332,7 +345,7 @@ export const confiPump: Action = {
});
}
} catch (error) {
console.error(`Error performing the action: ${error}`);
elizaLogger.error(`Error performing the action: ${error}`);
if (callback) {
callback({
text: `Failed to perform the action: ${content.object.action}: ${error}`,
Expand Down
18 changes: 3 additions & 15 deletions packages/plugin-conflux/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,13 @@ export function isPumpContent(object: any): object is PumpContent {
}

export function isPumpCreateContent(object: any): object is PumpCreateContent {
if (PumpCreateSchema.safeParse(object).success) {
return true;
}
console.error("Invalid content: ", object);
return false;
return PumpCreateSchema.safeParse(object).success;
}

export function isPumpBuyContent(object: any): object is PumpBuyContent {
if (PumpBuySchema.safeParse(object).success) {
return true;
}
console.error("Invalid content: ", object);
return false;
return PumpBuySchema.safeParse(object).success;
}

export function isPumpSellContent(object: any): object is PumpSellContent {
if (PumpSellSchema.safeParse(object).success) {
return true;
}
console.error("Invalid content: ", object);
return false;
return PumpSellSchema.safeParse(object).success;
}
2 changes: 1 addition & 1 deletion packages/plugin-evm/src/templates/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const transferTemplate = `Given the recent messages and wallet informatio
{{walletInfo}}
Extract the following information about the requested transfer:
- Chain to execute on: Must be one of ["ethereum", "base", ...] (like in viem/chains)
- Chain to execute on (like in viem/chains)
- Amount to transfer: Must be a string representing the amount in ETH (only number without coin symbol, e.g., "0.1")
- Recipient address: Must be a valid Ethereum address starting with "0x"
- Token symbol or address (if not native token): Optional, leave as null for ETH transfers
Expand Down
73 changes: 4 additions & 69 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2e49b21

Please sign in to comment.