Skip to content

Commit

Permalink
Merge pull request #2866 from AIFlowML/fix-plugin-starknet
Browse files Browse the repository at this point in the history
fix: plugin-starknet
  • Loading branch information
shakkernerd authored Jan 28, 2025
2 parents 2dab937 + c2b5bbd commit 045161f
Show file tree
Hide file tree
Showing 11 changed files with 182 additions and 90 deletions.
17 changes: 8 additions & 9 deletions packages/plugin-starknet/src/actions/subdomain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,17 @@ export default {
): Promise<boolean> => {
elizaLogger.log("Starting CREATE_SUBDOMAIN handler...");

// Initialize or update state
if (!state) {
state = (await runtime.composeState(message)) as State;
// Fix: Create new variable instead of reassigning parameter
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 Expand Up @@ -146,13 +147,11 @@ export default {
const tx = await account.execute(transferCall);

elizaLogger.success(
"Transfer completed successfully! tx: " + tx.transaction_hash
`Transfer completed successfully! tx: ${tx.transaction_hash}`
);
if (callback) {
callback({
text:
"Transfer completed successfully! tx: " +
tx.transaction_hash,
text: `Transfer completed successfully! tx: ${tx.transaction_hash}`,
content: {},
});
}
Expand Down
18 changes: 10 additions & 8 deletions packages/plugin-starknet/src/actions/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,17 @@ export const executeSwap: Action = {
callback?: HandlerCallback
): Promise<boolean> => {
elizaLogger.log("Starting EXECUTE_STARKNET_SWAP handler...");
if (!state) {
state = (await runtime.composeState(message)) as State;

// Fix: Create new variable instead of reassigning parameter
let currentState = state;
if (!currentState) {
currentState = (await runtime.composeState(message)) as State;
} else {
state = await runtime.updateRecentMessageState(state);
currentState = await runtime.updateRecentMessageState(currentState);
}

const swapContext = composeContext({
state,
state: currentState,
template: swapTemplate,
});

Expand Down Expand Up @@ -139,18 +142,17 @@ export const executeSwap: Action = {
);

elizaLogger.log(
"Swap completed successfully! tx: " + swapResult.transactionHash
`Swap completed successfully! tx: ${swapResult.transactionHash}`
);
callback?.({
text:
"Swap completed successfully! tx: " +
swapResult.transactionHash,
`Swap completed successfully! tx: ${swapResult.transactionHash}`,
});

return true;
} catch (error) {
elizaLogger.error("Error during token swap:", error);
callback?.({ text: `Error during swap:` });
callback?.({ text: `Error during swap: ${error.message}` });
return false;
}
},
Expand Down
6 changes: 4 additions & 2 deletions packages/plugin-starknet/src/actions/takeOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ModelClass,
settings,
} from "@elizaos/core";
import * as fs from "fs";
import * as fs from "node:fs"; // Added node: protocol
import { validateStarknetConfig } from "../environment";

interface Order {
Expand Down Expand Up @@ -54,7 +54,9 @@ const take_order: Action = {
const _text = (message.content as Content).text;
const userId = message.userId;

let ticker, contractAddress;
// Fix: Declare variables separately with explicit types
let ticker: string | undefined;
let contractAddress: string | undefined;

// TODO:

Expand Down
19 changes: 9 additions & 10 deletions packages/plugin-starknet/src/actions/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,17 @@ export default {
): Promise<boolean> => {
elizaLogger.log("Starting SEND_TOKEN handler...");

// Initialize or update state
if (!state) {
state = (await runtime.composeState(message)) as State;
// Fix: Create new variable instead of reassigning parameter
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 Expand Up @@ -162,7 +163,7 @@ export default {
const decimals = await erc20Token.decimals();
// Convert decimal amount to integer before converting to BigInt
const amountInteger = Math.floor(
Number(content.amount) * Math.pow(10, Number(decimals))
Number(content.amount) * (10 ** Number(decimals)) // Fix: Use exponentiation operator instead of Math.pow
);
const amountWei = BigInt(amountInteger.toString());
const recipient =
Expand All @@ -182,13 +183,11 @@ export default {
const tx = await account.execute(transferCall);

elizaLogger.success(
"Transfer completed successfully! tx: " + tx.transaction_hash
`Transfer completed successfully! tx: ${tx.transaction_hash}` // Fix: Use template literal
);
if (callback) {
callback({
text:
"Transfer completed successfully! tx: " +
tx.transaction_hash,
text: `Transfer completed successfully! tx: ${tx.transaction_hash}`, // Fix: Use template literal
content: {},
});
}
Expand Down
23 changes: 9 additions & 14 deletions packages/plugin-starknet/src/actions/unruggable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,16 @@ export const deployToken: Action = {
elizaLogger.log(
"Starting DEPLOY_STARKNET_UNRUGGABLE_MEME_TOKEN handler..."
);
if (!state) {
state = (await runtime.composeState(message)) as State;
// Fix: Create new variable instead of reassigning parameter
let currentState = state;
if (!currentState) {
currentState = (await runtime.composeState(message)) as State;
} else {
state = await runtime.updateRecentMessageState(state);
currentState = await runtime.updateRecentMessageState(currentState);
}

const deployContext = composeContext({
state,
state: currentState,
template: deployTemplate,
});

Expand All @@ -116,7 +118,7 @@ export const deployToken: Action = {
modelClass: ModelClass.MEDIUM,
});

elizaLogger.log("init supply." + response.initialSupply);
elizaLogger.log(`init supply. ${response.initialSupply}`);
elizaLogger.log(response);

if (!isDeployTokenContent(response)) {
Expand Down Expand Up @@ -148,10 +150,7 @@ export const deployToken: Action = {
);

elizaLogger.log(
"Token deployment initiated for: " +
response.name +
" at address: " +
tokenAddress
`Token deployment initiated for: ${response.name} at address: ${tokenAddress}`
);

await launchOnEkubo(config, {
Expand Down Expand Up @@ -181,11 +180,7 @@ export const deployToken: Action = {
});

callback?.({
text:
"Token Deployment completed successfully!" +
response.symbol +
" deployed in tx: " +
transactionHash,
text: `Token Deployment completed successfully! ${response.symbol} deployed in tx: ${transactionHash}`,
});

return true;
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-starknet/src/providers/portfolioProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,11 @@ const walletProvider: Provider = {
if (rawBalance === undefined) return null;

const decimalBalance =
Number(rawBalance) / Math.pow(10, token.decimals);
Number(rawBalance) / (10 ** token.decimals); // Fix: Use exponentiation operator instead of Math.pow
const price = tokenUsdValues[token.coingeckoId]?.usd ?? 0;
const usdValue = decimalBalance * price;


if (decimalBalance === 0 && usdValue === 0) return null;

return `${symbol.padEnd(9)}| ${decimalBalance
Expand Down
26 changes: 15 additions & 11 deletions packages/plugin-starknet/src/providers/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class TokenProvider {
lastError = error as Error;

if (i < PROVIDER_CONFIG.MAX_RETRIES - 1) {
const delay = PROVIDER_CONFIG.RETRY_DELAY * Math.pow(2, i);
const delay = PROVIDER_CONFIG.RETRY_DELAY * (2 ** i); // Fix: Use exponentiation operator instead of Math.pow
await new Promise((resolve) => setTimeout(resolve, delay));
}
}
Expand Down Expand Up @@ -156,10 +156,10 @@ export class TokenProvider {
// Check if the tokenAddress exists in the TokenBalances
if (items[tokenAddress]) {
return tokenAddress;
} else {
console.warn(`Token with address ${tokenAddress} not found in wallet`);
return null;
}

console.warn(`Token with address ${tokenAddress} not found in wallet`);
return null;
} catch (error) {
console.error("Error checking token in wallet:", error);
return null;
Expand Down Expand Up @@ -401,7 +401,7 @@ export class TokenProvider {

return dexData;
} catch (error) {
console.error(`Error fetching DexScreener data:`, error);
console.error("Error fetching DexScreener data:", error);
return {
schemaVersion: "1.0.0",
pairs: [],
Expand Down Expand Up @@ -444,7 +444,7 @@ export class TokenProvider {
// Return the pair with the highest liquidity and market cap
return this.getHighestLiquidityPair(dexData);
} catch (error) {
console.error(`Error fetching DexScreener data:`, error);
console.error("Error fetching DexScreener data:", error);
return null;
}
}
Expand Down Expand Up @@ -504,11 +504,11 @@ export class TokenProvider {

if (averageChange > increaseThreshold) {
return "increasing";
} else if (averageChange < decreaseThreshold) {
}
if (averageChange < decreaseThreshold) {
return "decreasing";
} else {
return "stable";
}
return "stable";
}

// TODO: Update to Starknet

Check notice on line 514 in packages/plugin-starknet/src/providers/token.ts

View check run for this annotation

codefactor.io / CodeFactor

packages/plugin-starknet/src/providers/token.ts#L514

Unexpected 'todo' comment: 'TODO: Update to Starknet'. (no-warning-comments)
Expand All @@ -523,7 +523,10 @@ export class TokenProvider {
const allHoldersMap = new Map<string, number>();
let page = 1;
const limit = 1000;
let cursor;
// let cursor;
// Fix: Add type annotation to prevent implicit any
let cursor: string | undefined;

//HELIOUS_API_KEY needs to be added
const url = `https://mainnet.helius-rpc.com/?api-key=${
settings.HELIUS_API_KEY || ""
Expand All @@ -538,7 +541,8 @@ export class TokenProvider {
mint: this.tokenAddress,
cursor: cursor,
};
if (cursor != undefined) {
// Fix: Replace != with !==
if (cursor !== undefined) {
params.cursor = cursor;
}
console.log(`Fetching holders - Page ${page}`);
Expand Down
Loading

0 comments on commit 045161f

Please sign in to comment.