Skip to content

Commit

Permalink
Fix agw tx sending
Browse files Browse the repository at this point in the history
  • Loading branch information
cygaar committed Jan 13, 2025
1 parent 35806c7 commit 445fece
Showing 1 changed file with 61 additions and 36 deletions.
97 changes: 61 additions & 36 deletions packages/plugin-abstract/src/actions/transferAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,49 +162,74 @@ export const transferAction: Action = {

try {
const account = useGetAccount(runtime);
let walletClient: AbstractClient | WalletClient;

let hash;
if (content.useAGW) {
walletClient = await createAbstractClient({
const abstractClient = await createAbstractClient({
chain: abstractTestnet,
signer: account,
});
} else {
walletClient = useGetWalletClient();
}

let hash;

// Check if the token is native
if (
content.tokenAddress.toLowerCase() !== ETH_ADDRESS.toLowerCase()
) {
// Convert amount to proper token decimals
const tokenInfo =
ERC20_OVERRIDE_INFO[content.tokenAddress.toLowerCase()];
const decimals = tokenInfo?.decimals ?? 18; // Default to 18 decimals if not specified
const tokenAmount = parseUnits(
content.amount.toString(),
decimals
);
// Handle AGW transfer based on token type
if (
content.tokenAddress.toLowerCase() !==
ETH_ADDRESS.toLowerCase()
) {
const tokenInfo =
ERC20_OVERRIDE_INFO[content.tokenAddress.toLowerCase()];
const decimals = tokenInfo?.decimals ?? 18;
const tokenAmount = parseUnits(
content.amount.toString(),
decimals
);

// Execute ERC20 transfer
hash = await walletClient.writeContract({
account,
chain: abstractTestnet,
address: content.tokenAddress as Address,
abi: erc20Abi,
functionName: "transfer",
args: [content.recipient as Address, tokenAmount],
});
hash = await abstractClient.writeContract({
chain: abstractTestnet,
address: content.tokenAddress as Address,
abi: erc20Abi,
functionName: "transfer",
args: [content.recipient as Address, tokenAmount],
});
} else {
hash = await abstractClient.sendTransaction({
chain: abstractTestnet,
to: content.recipient as Address,
value: parseEther(content.amount.toString()),
kzg: undefined,
});
}
} else {
hash = await walletClient.sendTransaction({
account: account,
chain: abstractTestnet,
to: content.recipient as Address,
value: parseEther(content.amount.toString()),
kzg: undefined,
});
const walletClient = useGetWalletClient();

// Handle regular wallet transfer based on token type
if (
content.tokenAddress.toLowerCase() !==
ETH_ADDRESS.toLowerCase()
) {
const tokenInfo =
ERC20_OVERRIDE_INFO[content.tokenAddress.toLowerCase()];
const decimals = tokenInfo?.decimals ?? 18;
const tokenAmount = parseUnits(
content.amount.toString(),
decimals
);

hash = await walletClient.writeContract({
account,
chain: abstractTestnet,
address: content.tokenAddress as Address,
abi: erc20Abi,
functionName: "transfer",
args: [content.recipient as Address, tokenAmount],
});
} else {
hash = await walletClient.sendTransaction({
account,
chain: abstractTestnet,
to: content.recipient as Address,
value: parseEther(content.amount.toString()),
kzg: undefined,
});
}
}

elizaLogger.success(
Expand Down

0 comments on commit 445fece

Please sign in to comment.