Skip to content

Commit

Permalink
Fixed all the issues (#3076)
Browse files Browse the repository at this point in the history
  • Loading branch information
AIFlowML authored Jan 31, 2025
1 parent 0a00b32 commit 82c2383
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 21 deletions.
41 changes: 41 additions & 0 deletions packages/plugin-cronos/biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
"organizeImports": {
"enabled": false
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"correctness": {
"noUnusedVariables": "error"
},
"suspicious": {
"noExplicitAny": "error"
},
"style": {
"useConst": "error",
"useImportType": "off"
}
}
},
"formatter": {
"enabled": true,
"indentStyle": "space",
"indentWidth": 4,
"lineWidth": 100
},
"javascript": {
"formatter": {
"quoteStyle": "single",
"trailingCommas": "es5"
}
},
"files": {
"ignore": [
"dist/**/*",
"extra/**/*",
"node_modules/**/*"
]
}
}
8 changes: 7 additions & 1 deletion packages/plugin-cronos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@
"@elizaos/core": "workspace:*"
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"tsup": "8.3.5"
},
"scripts": {
"build": "tsup --format esm --no-dts",
"dev": "tsup --format esm --no-dts --watch"
"dev": "tsup --format esm --no-dts --watch",
"clean": "rm -rf dist",
"lint": "biome lint .",
"lint:fix": "biome check --apply .",
"format": "biome format .",
"format:fix": "biome format --write ."
},
"peerDependencies": {
"whatwg-url": "7.1.0"
Expand Down
20 changes: 11 additions & 9 deletions packages/plugin-cronos/src/actions/balance.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
Action,
type Action,
composeContext,
generateObject,
HandlerCallback,
type HandlerCallback,
ModelClass,
type IAgentRuntime,
type Memory,
Expand All @@ -11,7 +11,7 @@ import {
import { z } from "zod";
import { isAddress } from "viem";

import { CronosWalletProvider, initCronosWalletProvider } from "../providers/wallet";
import { type CronosWalletProvider, initCronosWalletProvider } from "../providers/wallet";
import type { BalanceParams } from "../types";
import { balanceTemplate } from "../templates";

Expand Down Expand Up @@ -43,7 +43,7 @@ export class BalanceAction {
const buildBalanceDetails = async (
state: State,
runtime: IAgentRuntime,
wp: CronosWalletProvider
_wp: CronosWalletProvider
): Promise<BalanceParams> => {
state.supportedChains = '"cronos"|"cronosTestnet"';

Expand All @@ -69,20 +69,22 @@ export const balanceAction: Action = {
runtime: IAgentRuntime,
message: Memory,
state: State | undefined,
_options: any,
_options: Record<string, unknown>,
callback?: HandlerCallback
) => {
if (!state) {
state = (await runtime.composeState(message)) as State;
// Initialize or update state
let currentState = state;
if (!currentState) {
currentState = (await runtime.composeState(message)) as State;
} else {
state = await runtime.updateRecentMessageState(state);
currentState = await runtime.updateRecentMessageState(currentState);
}

const walletProvider = await initCronosWalletProvider(runtime);
const action = new BalanceAction(walletProvider);

const paramOptions = await buildBalanceDetails(
state,
currentState,
runtime,
walletProvider
);
Expand Down
20 changes: 11 additions & 9 deletions packages/plugin-cronos/src/actions/transfer.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { ByteArray, formatEther, parseEther, type Hex, isAddress } from "viem";
import {
Action,
type Action,
composeContext,
generateObject,
HandlerCallback,
type HandlerCallback,
ModelClass,
type IAgentRuntime,
type Memory,
type State,
} from "@elizaos/core";
import { z } from "zod";

import { CronosWalletProvider, initCronosWalletProvider } from "../providers/wallet";
import { type CronosWalletProvider, initCronosWalletProvider } from "../providers/wallet";
import type { Transaction, TransferParams } from "../types";
import { transferTemplate } from "../templates";
import { cronos, cronosTestnet } from "../constants/chains";
Expand Down Expand Up @@ -78,7 +78,7 @@ export class TransferAction {
const buildTransferDetails = async (
state: State,
runtime: IAgentRuntime,
wp: CronosWalletProvider
_wp: CronosWalletProvider
): Promise<TransferParams> => {
state.supportedChains = '"cronos"|"cronosTestnet"';

Expand All @@ -104,20 +104,22 @@ export const transferAction: Action = {
runtime: IAgentRuntime,
message: Memory,
state: State | undefined,
_options: any,
_options: Record<string, unknown>,
callback?: HandlerCallback
) => {
if (!state) {
state = (await runtime.composeState(message)) as State;
// Initialize or update state
let currentState = state;
if (!currentState) {
currentState = (await runtime.composeState(message)) as State;
} else {
state = await runtime.updateRecentMessageState(state);
currentState = await runtime.updateRecentMessageState(currentState);
}

const walletProvider = await initCronosWalletProvider(runtime);
const action = new TransferAction(walletProvider);

const paramOptions = await buildTransferDetails(
state,
currentState,
runtime,
walletProvider
);
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-cronos/src/providers/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import {
elizaLogger,
} from "@elizaos/core";
import NodeCache from "node-cache";
import * as path from "path";
import * as path from "node:path";

import { cronos, cronosTestnet } from "../constants/chains";
import type { CronosChain, CronosProvider } from "../types";

export class CronosWalletProvider {
private cache: NodeCache;
private cacheKey: string = "cronos/wallet";
private cacheKey = "cronos/wallet";
private currentChain: CronosChain = "cronos";
private CACHE_EXPIRY_SEC = 5;
chains: Record<CronosChain, Chain> = {
Expand Down

0 comments on commit 82c2383

Please sign in to comment.