Skip to content

Commit

Permalink
Transfer action update
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthera Node committed Jan 1, 2025
1 parent 05bcd6f commit 96eb3e6
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 225 deletions.
204 changes: 56 additions & 148 deletions packages/plugin-arthera/README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
# @elizaos/plugin-evm
Here’s the updated `README.md` tailored for the **Arthera plugin** while keeping relevant sections focused on its functionality:

This plugin provides actions and providers for interacting with EVM-compatible chains.
---

# @elizaos/plugin-arthera

This plugin provides actions and providers for interacting with the **Arthera blockchain**.

## Description

The EVM plugin provides comprehensive functionality for interacting with EVM-compatible chains, including token transfers, cross-chain bridging, and token swaps using LiFi integration.
The Arthera plugin enables seamless interaction with the Arthera blockchain, focusing on native token transfers. It provides dynamic configuration for Arthera-specific RPCs and facilitates token operations with ease.

## Features

- Multi-chain support with dynamic chain configuration
- Native token transfers
- Cross-chain token bridging via LiFi
- Token swapping on supported DEXs
- Wallet balance tracking
- Custom RPC endpoint configuration
- Automatic retry mechanisms
- Comprehensive transaction management
- **Arthera-specific support**:
- Native token transfers using **AA**.
- Wallet balance tracking.
- **Dynamic RPC configuration** for the Arthera chain.
- Comprehensive transaction management.

## Installation

```bash
pnpm install @elizaos/plugin-evm
pnpm install @elizaos/plugin-arthera
```

## Configuration
Expand All @@ -31,89 +32,54 @@ pnpm install @elizaos/plugin-evm
# Required
EVM_PRIVATE_KEY=your-private-key-here
# Optional - Custom RPC URLs
EVM_PROVIDER_URL=https://your-custom-mainnet-rpc-url
ETHEREUM_PROVIDER_<CHAIN_NAME>=https://your-custom-rpc-url
# Optional - Custom RPC URL for Arthera
ARTHERA_PROVIDER_URL=https://rpc.arthera.net
```

### Chain Configuration

By default, **Ethereum mainnet** is enabled. To enable additional chains, add them to your character config:
The plugin is pre-configured for the Arthera chain. To add additional configurations, modify your character settings as needed.

Example configuration for Arthera:

```json
"settings": {
"chains": {
"evm": [
"base", "arbitrum", "iotex"
"arthera"
]
}
}
```

Note: The chain names must match those in the viem/chains.

### Custom RPC URLs

By default, the RPC URL is inferred from the `viem/chains` config. To use a custom RPC URL for a specific chain, add the following to your `.env` file:

```env
ETHEREUM_PROVIDER_<CHAIN_NAME>=https://your-custom-rpc-url
```

**Example usage:**
### Custom RPC URL

```env
ETHEREUM_PROVIDER_IOTEX=https://iotex-network.rpc.thirdweb.com
```

#### Custom RPC for Ethereum Mainnet

To set a custom RPC URL for Ethereum mainnet, use:
By default, the plugin uses the public RPC URL for Arthera. To set a custom RPC URL, add the following to your `.env` file:

```env
EVM_PROVIDER_URL=https://your-custom-mainnet-rpc-url
ARTHERA_PROVIDER_URL=https://your-custom-rpc-url
```

## Provider

The **Wallet Provider** initializes with the **first chain in the list** as the default (or Ethereum mainnet if none are added). It:

- Provides the **context** of the currently connected address and its balance.
- Creates **Public** and **Wallet clients** to interact with the supported chains.
- Allows adding chains dynamically at runtime.
---

## Actions

### 1. Transfer

Transfer native tokens on the same chain:
Transfer native tokens (AA) on the Arthera chain:

```typescript
// Example: Transfer 1 AA
Transfer 1 AA to 0x742d35Cc6634C0532925a3b844Bc454e4438f44e
```

### 2. Bridge

Bridge tokens between different chains using LiFi:

```typescript
// Example: Bridge AA from Ethereum to Base
Bridge 1 AA from Ethereum to Base
```

### 3. Swap

Swap tokens on the same chain using LiFi:

```typescript
// Example: Swap AA for USDC
Swap 1 AA for USDC on Base
```
---

## Development

1. Clone the repository
1. Clone the repository.
2. Install dependencies:

```bash
Expand All @@ -132,118 +98,60 @@ pnpm run build
pnpm test
```

---

## API Reference

### Core Components

1. **WalletProvider**
- Manages wallet connections
- Handles chain switching
- Manages RPC endpoints
- Tracks balances
- Manages wallet connections.
- Handles RPC endpoints for Arthera.
- Tracks wallet balances.

2. **Actions**
- TransferAction: Native token transfers
- BridgeAction: Cross-chain transfers
- SwapAction: Same-chain token swaps
- **TransferAction**: Native token transfers on the Arthera chain.

---

## Future Enhancements

1. **Cross-Chain Operations**
- Enhanced bridge aggregation
- Multi-chain transaction batching
- Cross-chain liquidity management
- Bridge fee optimization
- Chain-specific gas strategies
- Cross-chain messaging

2. **DeFi Integration**
- Advanced swap routing
- Yield farming automation
- Liquidity pool management
- Position management tools
- MEV protection features
- Flash loan integration

3. **Smart Contract Management**
- Contract deployment templates
- Verification automation
- Upgrade management
- Security analysis tools
- Gas optimization
- ABI management system

4. **Token Operations**
- Batch transfer tools
- Token approval management
- Token metadata handling
- Custom token standards
- Token bridging optimization
- NFT support enhancement

5. **Wallet Features**
- Multi-signature support
- Account abstraction
- Hardware wallet integration
- Social recovery options
- Transaction simulation
- Batch transaction processing

6. **Network Management**
- Dynamic RPC management
- Network health monitoring
- Fallback provider system
- Custom network addition
- Gas price optimization
- Network analytics

7. **Security Enhancements**
- Transaction validation
- Risk assessment tools
- Fraud detection
- Rate limiting
- Emergency shutdown
- Audit integration

8. **Developer Tools**
- Enhanced debugging
- Testing framework
- Documentation generator
- CLI improvements
- Performance profiling
- Integration templates

We welcome community feedback and contributions to help prioritize these enhancements.
1. **Cross-Chain Operations** (when bridging support is added):
- Bridge AA across chains.
- Multi-chain transaction batching.

2. **Smart Contract Management**:
- Contract deployment support for Arthera.
- Automated gas optimization.

3. **Developer Tools**:
- Enhanced debugging and logging for Arthera interactions.

---

## Contributing

The plugin contains tests. Whether you're using **TDD** or not, please make sure to run the tests before submitting a PR:
The plugin contains tests. Before submitting a PR, make sure to run the tests:

```bash
pnpm test
```

Contributions are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) file for more information.

## Credits
---

This plugin integrates with and builds upon several key technologies:
## Credits

- [Ethereum](https://ethereum.org/): Decentralized blockchain
- [LiFi](https://lifi.io/): Cross-chain bridge and swap service
- [viem](https://viem.sh/): Ethereum client library
- [wagmi](https://wagmi.sh/): Ethereum client library
This plugin is designed specifically for the Arthera chain, leveraging:

Special thanks to:
- [Ethereum Developer community](https://ethereum.org/developers/)
- The Eliza community for their contributions and feedback
- [Arthera](https://arthera.net): A blockchain ecosystem.
- [viem](https://viem.sh/): Ethereum client library.

For more information about EVM capabilities:
- [Ethereum Documentation](https://ethereum.org/developers/)
- [LiFi Documentation](https://lifi.io)
- [viem Documentation](https://viem.sh)
- [wagmi Documentation](https://wagmi.sh)
---

## License

This plugin is part of the Eliza project. See the main project repository for license information.
This plugin is part of the ElizaOS project. See the main project repository for license information.

---
49 changes: 22 additions & 27 deletions packages/plugin-arthera/src/actions/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class TransferAction {
params.data = "0x";
}

// Switch to the correct chain
this.walletProvider.switchChain(params.fromChain);

const walletClient = this.walletProvider.getWalletClient(
Expand All @@ -36,32 +37,25 @@ export class TransferAction {

try {
const hash = await walletClient.sendTransaction({
account: walletClient.account,
account: walletClient.account!,
to: params.toAddress,
value: parseEther(params.amount),
data: params.data as Hex,
kzg: {
blobToKzgCommitment: function (_: ByteArray): ByteArray {
throw new Error("Function not implemented.");
},
computeBlobKzgProof: function (
_blob: ByteArray,
_commitment: ByteArray
): ByteArray {
throw new Error("Function not implemented.");
},
},
chain: undefined,
});

return {
hash,
from: walletClient.account.address,
to: params.toAddress,
value: parseEther(params.amount),
data: params.data as Hex,
};
} catch (error) {
if (walletClient.account) {
return {
hash,
from: walletClient.account.address,
to: params.toAddress,
value: parseEther(params.amount),
data: params.data as Hex,
};
} else {
throw new Error("Wallet client account is undefined");
}
} catch (error: any) {
throw new Error(`Transfer failed: ${error.message}`);
}
}
Expand Down Expand Up @@ -94,10 +88,7 @@ const buildTransferDetails = async (

if (!existingChain) {
throw new Error(
"The chain " +
transferDetails.fromChain +
" not configured yet. Add the chain or choose one from configured: " +
chains.toString()
`The chain "${transferDetails.fromChain}" is not configured. Add the chain or choose one from: ${chains.join(", ")}`
);
}

Expand All @@ -110,10 +101,14 @@ export const transferAction = {
handler: async (
runtime: IAgentRuntime,
_message: Memory,
state: State,
state: State | undefined, // Allow undefined state
_options: any,
callback?: HandlerCallback
) => {
if (!state) {
throw new Error("State is required for this action.");
}

console.log("Transfer action handler called");
const walletProvider = await initWalletProvider(runtime);
const action = new TransferAction(walletProvider);
Expand All @@ -140,8 +135,8 @@ export const transferAction = {
});
}
return true;
} catch (error) {
console.error("Error during token transfer:", error);
} catch (error: any) {
console.error("Error during token transfer:", error.message);
if (callback) {
callback({
text: `Error transferring tokens: ${error.message}`,
Expand Down
Loading

0 comments on commit 96eb3e6

Please sign in to comment.