From 6b69520e132dc2eacd0340ce47972029790134e5 Mon Sep 17 00:00:00 2001 From: AIFlow_ML Date: Tue, 28 Jan 2025 17:00:34 +0700 Subject: [PATCH] Fixed all the typing and also the reassign. Leaved 4 reassign because i could not understand the logic --- .../src/actions/bank/send_tokens.ts | 19 +++++++++++++------ .../src/actions/staking/cancel_unbonding.ts | 18 ++++++++++++------ .../src/actions/staking/delegate_token.ts | 19 +++++++++++++------ .../src/actions/staking/redelegate.ts | 17 +++++++++++------ .../src/actions/staking/undelegate_token.ts | 18 ++++++++++++------ packages/plugin-omniflix/src/index.ts | 2 +- .../plugin-omniflix/src/providers/bank.ts | 2 +- packages/plugin-omniflix/src/providers/gov.ts | 2 +- .../plugin-omniflix/src/providers/staking.ts | 8 ++++---- .../plugin-omniflix/src/providers/wallet.ts | 6 ++++-- 10 files changed, 72 insertions(+), 39 deletions(-) diff --git a/packages/plugin-omniflix/src/actions/bank/send_tokens.ts b/packages/plugin-omniflix/src/actions/bank/send_tokens.ts index 82d961ab49..9f162f590e 100644 --- a/packages/plugin-omniflix/src/actions/bank/send_tokens.ts +++ b/packages/plugin-omniflix/src/actions/bank/send_tokens.ts @@ -107,7 +107,7 @@ export class SendTokensAction { if (typeof params.amount === "number") { params.amount = params.amount * 1000000; } else if (typeof params.amount === "string") { - params.amount = parseInt(params.amount) * 1000000; + params.amount = Number.parseInt(params.amount) * 1000000; } } @@ -128,14 +128,21 @@ const buildTransferDetails = async ( message: Memory, state: State ): Promise => { - if (!state) { - state = (await runtime.composeState(message)) as State; - } else { - state = await runtime.updateRecentMessageState(state); + + // if (!state) { + // state = (await runtime.composeState(message)) as State; + // } else { + // state = await runtime.updateRecentMessageState(state); + // } + + let currentState: State = state; + if (!currentState) { + currentState = (await runtime.composeState(message)) as State; } + currentState = await runtime.updateRecentMessageState(currentState); const transferContext = composeContext({ - state, + state: currentState, template: sendTokensTemplate, }); diff --git a/packages/plugin-omniflix/src/actions/staking/cancel_unbonding.ts b/packages/plugin-omniflix/src/actions/staking/cancel_unbonding.ts index 0ae36aa5e1..3d45403b40 100644 --- a/packages/plugin-omniflix/src/actions/staking/cancel_unbonding.ts +++ b/packages/plugin-omniflix/src/actions/staking/cancel_unbonding.ts @@ -108,7 +108,7 @@ export class CancelUnbondingAction { if (typeof params.amount === "number") { params.amount = params.amount * 1000000; } else if (typeof params.amount === "string") { - params.amount = parseInt(params.amount) * 1000000; + params.amount = Number.parseInt(params.amount) * 1000000; } } @@ -135,14 +135,20 @@ const buildCancelUnbondingContent = async ( message: Memory, state: State ): Promise => { - if (!state) { - state = (await runtime.composeState(message)) as State; - } else { - state = await runtime.updateRecentMessageState(state); + // if (!state) { + // state = (await runtime.composeState(message)) as State; + // } else { + // state = await runtime.updateRecentMessageState(state); + // } + + let currentState: State = state; + if (!currentState) { + currentState = (await runtime.composeState(message)) as State; } + currentState = await runtime.updateRecentMessageState(currentState); const cancelUnbondingContext = composeContext({ - state, + state: currentState, template: cancelUnbondingTemplate, }); diff --git a/packages/plugin-omniflix/src/actions/staking/delegate_token.ts b/packages/plugin-omniflix/src/actions/staking/delegate_token.ts index 570f4626a4..ff00f98f54 100644 --- a/packages/plugin-omniflix/src/actions/staking/delegate_token.ts +++ b/packages/plugin-omniflix/src/actions/staking/delegate_token.ts @@ -104,7 +104,7 @@ export class DelegateTokensAction { if (typeof params.amount === "number") { params.amount = params.amount * 1000000; } else if (typeof params.amount === "string") { - params.amount = parseInt(params.amount) * 1000000; + params.amount = Number.parseInt(params.amount) * 1000000; } } @@ -128,14 +128,21 @@ const buildDelegateTokensContent = async ( message: Memory, state: State ): Promise => { - if (!state) { - state = (await runtime.composeState(message)) as State; - } else { - state = await runtime.updateRecentMessageState(state); + + // if (!state) { + // state = (await runtime.composeState(message)) as State; + // } else { + // state = await runtime.updateRecentMessageState(state); + // } + + let currentState: State = state; + if (!currentState) { + currentState = (await runtime.composeState(message)) as State; } + currentState = await runtime.updateRecentMessageState(currentState); const delegateContext = composeContext({ - state, + state: currentState, template: delegateTokensTemplate, }); diff --git a/packages/plugin-omniflix/src/actions/staking/redelegate.ts b/packages/plugin-omniflix/src/actions/staking/redelegate.ts index b220777c77..7ef7dc96c4 100644 --- a/packages/plugin-omniflix/src/actions/staking/redelegate.ts +++ b/packages/plugin-omniflix/src/actions/staking/redelegate.ts @@ -125,7 +125,7 @@ export class RedelegateTokensAction { if (typeof params.amount === "number") { params.amount = params.amount * 1000000; } else if (typeof params.amount === "string") { - params.amount = parseInt(params.amount) * 1000000; + params.amount = Number.parseInt(params.amount) * 1000000; } } @@ -150,14 +150,19 @@ const buildRedelegateDetails = async ( message: Memory, state: State ): Promise => { - if (!state) { - state = (await runtime.composeState(message)) as State; - } else { - state = await runtime.updateRecentMessageState(state); + // if (!state) { + // state = (await runtime.composeState(message)) as State; + // } else { + // state = await runtime.updateRecentMessageState(state); + // } + let currentState: State = state; + if (!currentState) { + currentState = (await runtime.composeState(message)) as State; } + currentState = await runtime.updateRecentMessageState(currentState); const redelegateContext = composeContext({ - state, + state: currentState, template: redelegateTokensTemplate, }); diff --git a/packages/plugin-omniflix/src/actions/staking/undelegate_token.ts b/packages/plugin-omniflix/src/actions/staking/undelegate_token.ts index 6253cb35a0..6642317e07 100644 --- a/packages/plugin-omniflix/src/actions/staking/undelegate_token.ts +++ b/packages/plugin-omniflix/src/actions/staking/undelegate_token.ts @@ -104,7 +104,7 @@ export class UndelegateTokensAction { if (typeof params.amount === "number") { params.amount = params.amount * 1000000; } else if (typeof params.amount === "string") { - params.amount = parseInt(params.amount) * 1000000; + params.amount = Number.parseInt(params.amount) * 1000000; } } @@ -128,14 +128,20 @@ const buildUndelegateTokensContent = async ( message: Memory, state: State ): Promise => { - if (!state) { - state = (await runtime.composeState(message)) as State; - } else { - state = await runtime.updateRecentMessageState(state); + // if (!state) { + // state = (await runtime.composeState(message)) as State; + // } else { + // state = await runtime.updateRecentMessageState(state); + // } + + let currentState: State = state; + if (!currentState) { + currentState = (await runtime.composeState(message)) as State; } + currentState = await runtime.updateRecentMessageState(currentState); const undelegateContext = composeContext({ - state, + state: currentState, template: undelegateTokensTemplate, }); diff --git a/packages/plugin-omniflix/src/index.ts b/packages/plugin-omniflix/src/index.ts index ff08abdff2..5960321ae5 100644 --- a/packages/plugin-omniflix/src/index.ts +++ b/packages/plugin-omniflix/src/index.ts @@ -1,4 +1,4 @@ -import { type Plugin } from "@elizaos/core"; +import type { Plugin } from "@elizaos/core"; import providers from "./providers/index.ts"; import actions from "./actions/index.ts"; diff --git a/packages/plugin-omniflix/src/providers/bank.ts b/packages/plugin-omniflix/src/providers/bank.ts index 68d8c5f6da..79891bf3f6 100644 --- a/packages/plugin-omniflix/src/providers/bank.ts +++ b/packages/plugin-omniflix/src/providers/bank.ts @@ -29,7 +29,7 @@ export class BankProvider { ); return tx; } catch (e) { - elizaLogger.error("Error in sendTokens: " + e); + elizaLogger.error(`Error in sendTokens: ${e}`); throw e; } } diff --git a/packages/plugin-omniflix/src/providers/gov.ts b/packages/plugin-omniflix/src/providers/gov.ts index 64948e4896..52e934dea0 100644 --- a/packages/plugin-omniflix/src/providers/gov.ts +++ b/packages/plugin-omniflix/src/providers/gov.ts @@ -41,7 +41,7 @@ export class GovProvider { ); return tx; } catch (e) { - elizaLogger.error("Error in voteOnProposal: " + e); + elizaLogger.error(`Error in voteOnProposal: ${e}`); throw e; } } diff --git a/packages/plugin-omniflix/src/providers/staking.ts b/packages/plugin-omniflix/src/providers/staking.ts index 2459119593..ee07ebf399 100644 --- a/packages/plugin-omniflix/src/providers/staking.ts +++ b/packages/plugin-omniflix/src/providers/staking.ts @@ -29,7 +29,7 @@ export class StakingProvider { ); return tx; } catch (e) { - elizaLogger.error("Error in delegate: " + e); + elizaLogger.error(`Error in delegate: ${e}`); throw e; } } @@ -53,7 +53,7 @@ export class StakingProvider { ); return tx; } catch (e) { - elizaLogger.error("Error in undelegate: " + e); + elizaLogger.error(`Error in undelegate: ${e}`); throw e; } } @@ -87,7 +87,7 @@ export class StakingProvider { ); return tx; } catch (e) { - elizaLogger.error("Error in redelegate: " + e); + elizaLogger.error(`Error in redelegate: ${e}`); throw e; } } @@ -122,7 +122,7 @@ export class StakingProvider { ); return tx; } catch (e) { - elizaLogger.error("Error in cancelUnbondingDelegation: " + e); + elizaLogger.error(`Error in cancelUnbondingDelegation: ${e}`); throw e; } } diff --git a/packages/plugin-omniflix/src/providers/wallet.ts b/packages/plugin-omniflix/src/providers/wallet.ts index 6168e717c7..62e999437e 100644 --- a/packages/plugin-omniflix/src/providers/wallet.ts +++ b/packages/plugin-omniflix/src/providers/wallet.ts @@ -82,12 +82,14 @@ export const walletProvider: Provider = { "omniflix" ); elizaLogger.info("Wallet initialized with private key"); - } else { + } else if (mnemonic) { // Use mnemonic - wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic!, { + wallet = await DirectSecp256k1HdWallet.fromMnemonic(mnemonic, { prefix: "omniflix", }); elizaLogger.info("Wallet initialized with mnemonic"); + } else { + throw new Error("Neither private key nor mnemonic available"); } const client = await SigningStargateClient.connectWithSigner(