Skip to content

Commit

Permalink
Fixed all the issues (#3092)
Browse files Browse the repository at this point in the history
Co-authored-by: Odilitime <janesmith@airmail.cc>
  • Loading branch information
AIFlowML and odilitime authored Jan 31, 2025
1 parent 0fccffb commit 3aa73fc
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 51 deletions.
41 changes: 41 additions & 0 deletions packages/plugin-avalanche/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/**/*"
]
}
}
9 changes: 7 additions & 2 deletions packages/plugin-avalanche/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@
},
"devDependencies": {
"tsup": "8.3.5",
"vitest": "^2.1.5"
"vitest": "^2.1.5",
"@biomejs/biome": "1.9.4"
},
"scripts": {
"build": "tsup src/index.ts --format esm --no-dts",
"test": "vitest run"
"test": "vitest run",
"lint": "biome lint .",
"lint:fix": "biome check --apply .",
"format": "biome format .",
"format:fix": "biome format --write ."
},
"peerDependencies": {
"whatwg-url": "7.1.0"
Expand Down
11 changes: 6 additions & 5 deletions packages/plugin-avalanche/src/actions/tokenMillCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface TokenMillCreateContent extends Content {
}

function isTokenMillCreateContent(
runtime: IAgentRuntime,
_runtime: IAgentRuntime,
content: any

Check warning on line 24 in packages/plugin-avalanche/src/actions/tokenMillCreate.ts

View check run for this annotation

codefactor.io / CodeFactor

packages/plugin-avalanche/src/actions/tokenMillCreate.ts#L24

Unexpected any. Specify a different type. (@typescript-eslint/no-explicit-any)
): content is TokenMillCreateContent {
elizaLogger.debug("Content for create", content);
Expand Down Expand Up @@ -75,15 +75,16 @@ export default {
elizaLogger.log("Starting CREATE_TOKEN handler...");

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

// Compose transfer context
const transferContext = composeContext({
state,
state: currentState,
template: transferTemplate,
});

Expand Down
40 changes: 24 additions & 16 deletions packages/plugin-avalanche/src/actions/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,28 @@ import { validateAvalancheConfig } from "../environment";
import { TOKEN_ADDRESSES } from "../utils/constants";

export interface TransferContent extends Content {
tokenAddress: string;
recipient: string;
tokenAddress: Address;
recipient: Address;
amount: string | number;
}

function isTransferContent(
runtime: IAgentRuntime,
content: any
_runtime: IAgentRuntime,
content: unknown
): content is TransferContent {
elizaLogger.debug("Content for transfer", content);
return (
typeof content.tokenAddress === "string" &&
typeof content.recipient === "string" &&
(typeof content.amount === "string" ||
typeof content.amount === "number")
typeof content === "object" &&
content !== null &&
"tokenAddress" in content &&
"recipient" in content &&
"amount" in content &&
typeof (content as TransferContent).tokenAddress === "string" &&
(content as TransferContent).tokenAddress.startsWith("0x") &&
typeof (content as TransferContent).recipient === "string" &&
(content as TransferContent).recipient.startsWith("0x") &&
(typeof (content as TransferContent).amount === "string" ||
typeof (content as TransferContent).amount === "number")
);
}

Expand Down Expand Up @@ -110,15 +117,16 @@ export default {
}

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

// Compose transfer context
const transferContext = composeContext({
state,
state: currentState,
template: transferTemplate,
});

Expand All @@ -141,21 +149,21 @@ export default {
return false;
}

let tx;
let tx: `0x${string}` | undefined;
if (
content.tokenAddress ===
"0x0000000000000000000000000000000000000000"
) {
tx = await sendNativeAsset(
runtime,
content.recipient as Address,
content.recipient,
content.amount as number
);
} else {
tx = await sendToken(
runtime,
content.tokenAddress as Address,
content.recipient as Address,
content.tokenAddress,
content.recipient,
content.amount as number
);
}
Expand Down
27 changes: 17 additions & 10 deletions packages/plugin-avalanche/src/actions/yakStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,22 @@ export interface StrategyContent extends Content {
amount: string | number;
}

// refactoring zone
function isStrategyContent(
runtime: IAgentRuntime,
content: any
_runtime: IAgentRuntime,
content: unknown
): content is StrategyContent {
elizaLogger.debug("Content for strategy", content);
return (
typeof content.depositTokenAddress === "string" &&
typeof content.strategyAddress === "string" &&
(typeof content.amount === "string" ||
typeof content.amount === "number")
typeof content === "object" &&
content !== null &&
"depositTokenAddress" in content &&
"strategyAddress" in content &&
"amount" in content &&
typeof (content as StrategyContent).depositTokenAddress === "string" &&
typeof (content as StrategyContent).strategyAddress === "string" &&
(typeof (content as StrategyContent).amount === "string" ||
typeof (content as StrategyContent).amount === "number")
);
}

Expand Down Expand Up @@ -99,15 +105,16 @@ export default {
elizaLogger.log("Starting DEPOSIT_TO_STRATEGY handler...");

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

// Compose context
const strategyContext = composeContext({
state,
state: currentState,
template: strategyTemplate,
});

Expand Down
28 changes: 17 additions & 11 deletions packages/plugin-avalanche/src/actions/yakSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,22 @@ export interface SwapContent extends Content {
amount: string | number;
}

// refactoring zone
function isSwapContent(
runtime: IAgentRuntime,
content: any
_runtime: IAgentRuntime,
content: unknown
): content is SwapContent {
elizaLogger.debug("Content for swap", content);
return (
typeof content.fromTokenAddress === "string" &&
typeof content.toTokenAddress === "string" &&
(typeof content.recipient === "string" || !content.recipient) &&
(typeof content.amount === "string" ||
typeof content.amount === "number")
typeof content === "object" &&
content !== null &&
"fromTokenAddress" in content &&
"toTokenAddress" in content &&
typeof (content as SwapContent).fromTokenAddress === "string" &&
typeof (content as SwapContent).toTokenAddress === "string" &&
(typeof (content as SwapContent).recipient === "string" || !(content as SwapContent).recipient) &&
(typeof (content as SwapContent).amount === "string" ||
typeof (content as SwapContent).amount === "number")
);
}

Expand Down Expand Up @@ -119,15 +124,16 @@ export default {
elizaLogger.log("Starting SWAP_TOKEN handler...");

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

// Compose swap context
const swapContext = composeContext({
state,
state: currentState,
template: transferTemplate,
});

Expand Down
10 changes: 5 additions & 5 deletions packages/plugin-avalanche/src/providers/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ const walletProvider: Provider = {

const account = getAccount(runtime);

let output = `# Wallet Balances\n\n`;
let output = "# Wallet Balances\n\n";
output += `## Wallet Address\n\n\`${account.address}\`\n\n`;

output += `## Latest Token Balances\n\n`;
output += "## Latest Token Balances\n\n";
for (const [token, address] of Object.entries(TOKEN_ADDRESSES)) {
const decimals = await getDecimals(runtime, address);
const balance = await getTokenBalance(
Expand All @@ -34,9 +34,9 @@ const walletProvider: Provider = {
);
output += `${token}: ${formatUnits(balance, decimals)}\n`;
}
output += `Note: These balances can be used at any time.\n\n`;
output += "Note: These balances can be used at any time.\n\n";

output += `## Balances in Yield Strategies\n\n`;
output += "## Balances in Yield Strategies\n\n";
for (const [strategy, address] of Object.entries(STRATEGY_ADDRESSES)) {
const balance = await getTokenBalance(
runtime,
Expand All @@ -46,7 +46,7 @@ const walletProvider: Provider = {
const decimals = await getDecimals(runtime, address);
output += `${strategy}: ${formatUnits(balance, decimals)}\n`;
}
output += `Note: These balances must be withdrawn from the strategy before they can be used.\n\n`;
output += "Note: These balances must be withdrawn from the strategy before they can be used.\n\n";

elizaLogger.debug("walletProvider::get output:", output);
return output;
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-avalanche/src/utils/tokenMill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ export const createMarketAndToken = async (
},
];

if (name.length == 0) {
if (name.length === 0) {
throw new Error("Name must be provided");
}

if (name.length > 32) {
throw new Error("Name must be less than 12 characters");
}

if (symbol.length == 0) {
if (symbol.length === 0) {
throw new Error("Symbol must be provided");
}

Expand Down

0 comments on commit 3aa73fc

Please sign in to comment.