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: remove dead code #2945

Merged
merged 1 commit into from
Jan 29, 2025
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
70 changes: 46 additions & 24 deletions packages/plugin-movement/src/actions/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import {
PrivateKeyVariants,
} from "@aptos-labs/ts-sdk";
import { walletProvider } from "../providers/wallet";
import { MOVEMENT_NETWORK_CONFIG, MOVE_DECIMALS, MOVEMENT_EXPLORER_URL } from "../constants";
import {
MOVEMENT_NETWORK_CONFIG,
MOVE_DECIMALS,
MOVEMENT_EXPLORER_URL,
} from "../constants";

export interface TransferContent extends Content {
recipient: string;
Expand Down Expand Up @@ -80,19 +84,27 @@ export default {
"transfer token",
"can you send",
"please send",
"send"
"send",
],
shouldHandle: (message: Memory) => {
const text = message.content?.text?.toLowerCase() || "";
return text.includes("send") && text.includes("move") && text.includes("0x");
return (
text.includes("send") &&
text.includes("move") &&
text.includes("0x")
);
},
validate: async (_runtime: IAgentRuntime, message: Memory) => {
elizaLogger.debug("Starting transfer validation for user:", message.userId);
elizaLogger.debug(
"Starting transfer validation for user:",
message.userId
);
elizaLogger.debug("Message text:", message.content?.text);
return true; // Let the handler do the validation
},
priority: 1000, // High priority for transfer actions
description: "Transfer Move tokens from the agent's wallet to another address",
description:
"Transfer Move tokens from the agent's wallet to another address",
handler: async (
runtime: IAgentRuntime,
message: Memory,
Expand All @@ -104,16 +116,22 @@ export default {
elizaLogger.debug("Message:", {
text: message.content?.text,
userId: message.userId,
action: message.content?.action
action: message.content?.action,
});

try {
const privateKey = runtime.getSetting("MOVEMENT_PRIVATE_KEY");
elizaLogger.debug("Got private key:", privateKey ? "Present" : "Missing");
elizaLogger.debug(
"Got private key:",
privateKey ? "Present" : "Missing"
);

const network = runtime.getSetting("MOVEMENT_NETWORK");
elizaLogger.debug("Network config:", network);
elizaLogger.debug("Available networks:", Object.keys(MOVEMENT_NETWORK_CONFIG));
elizaLogger.debug(
"Available networks:",
Object.keys(MOVEMENT_NETWORK_CONFIG)
);

const movementAccount = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey(
Expand All @@ -123,33 +141,37 @@ export default {
)
),
});
elizaLogger.debug("Created Movement account:", movementAccount.accountAddress.toStringLong());
elizaLogger.debug(
"Created Movement account:",
movementAccount.accountAddress.toStringLong()
);

const aptosClient = new Aptos(
new AptosConfig({
network: Network.CUSTOM,
fullnode: MOVEMENT_NETWORK_CONFIG[network].fullnode
fullnode: MOVEMENT_NETWORK_CONFIG[network].fullnode,
})
);
elizaLogger.debug("Created Aptos client with network:", MOVEMENT_NETWORK_CONFIG[network].fullnode);
elizaLogger.debug(
"Created Aptos client with network:",
MOVEMENT_NETWORK_CONFIG[network].fullnode
);

const walletInfo = await walletProvider.get(runtime, message, state);
const walletInfo = await walletProvider.get(
runtime,
message,
state
);
state.walletInfo = walletInfo;

// // Initialize or update state
// if (!state) {
// state = (await runtime.composeState(message)) as State;
// } else {
// state = await runtime.updateRecentMessageState(state);
// }

// Initialize or update state
let currentState: State;
if (!state) {
currentState = (await runtime.composeState(message)) as State;
} else {
currentState = await runtime.updateRecentMessageState(state);
}

// Compose transfer context
const transferContext = composeContext({
state: currentState,
Expand All @@ -176,7 +198,7 @@ export default {
}

const adjustedAmount = BigInt(
Number(content.amount) * (10 ** MOVE_DECIMALS)
Number(content.amount) * 10 ** MOVE_DECIMALS
);
console.log(
`Transferring: ${content.amount} tokens (${adjustedAmount} base units)`
Expand Down Expand Up @@ -204,7 +226,7 @@ export default {
hash: executedTransaction.hash,
amount: content.amount,
recipient: content.recipient,
explorerUrl
explorerUrl,
});

if (callback) {
Expand All @@ -215,7 +237,7 @@ export default {
hash: executedTransaction.hash,
amount: content.amount,
recipient: content.recipient,
explorerUrl
explorerUrl,
},
});
}
Expand Down Expand Up @@ -263,6 +285,6 @@ export default {
action: "TRANSFER_MOVE",
},
},
]
],
] as ActionExample[][],
} as Action;
16 changes: 3 additions & 13 deletions packages/plugin-near/src/actions/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,8 @@ async function transferNEAR(
if (!parsedAmount) {
throw new Error("Failed to parse NEAR amount");
}

const result = await account.sendMoney(
recipient,
BigInt(parsedAmount)
);

const result = await account.sendMoney(recipient, BigInt(parsedAmount));

return result.transaction.hash;
}
Expand All @@ -117,15 +114,8 @@ export const executeTransfer: Action = {
callback?: HandlerCallback
): Promise<boolean> => {
// Initialize or update state

// if (!state) {
// state = (await runtime.composeState(message)) as State;
// } else {
// state = await runtime.updateRecentMessageState(state);
// }

let currentState: State;

if (!state) {
currentState = (await runtime.composeState(message)) as State;
} else {
Expand Down
Loading