Skip to content

Commit

Permalink
Merge branch 'develop' into sif-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Jan 11, 2025
2 parents 01cf6e9 + bf5b72d commit 9cd60f9
Show file tree
Hide file tree
Showing 17 changed files with 106 additions and 64 deletions.
8 changes: 4 additions & 4 deletions packages/plugin-akash/src/actions/closeDeployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import { MsgCloseDeployment } from "@akashnetwork/akash-api/akash/deployment/v1b
import { validateAkashConfig } from "../environment";
import { fetchDeployments } from "./getDeploymentApi";
import { AkashError, AkashErrorCode } from "../error/error";
import { getCertificatePath } from "../utils/paths";
import { inspectRuntime, isPluginLoaded } from "../runtime_inspect";
// import { getCertificatePath } from "../utils/paths";
import { isPluginLoaded } from "../runtime_inspect";

interface CloseDeploymentContent extends Content {
dseq?: string;
closeAll?: boolean;
}

// Certificate file path
const CERTIFICATE_PATH = getCertificatePath(import.meta.url);
// const CERTIFICATE_PATH = getCertificatePath(import.meta.url);

// Initialize wallet and client
async function initializeClient(runtime: IAgentRuntime) {
Expand Down Expand Up @@ -312,7 +312,7 @@ export const closeDeploymentAction: Action = {
runtime: IAgentRuntime,
message: Memory,
state: State | undefined,
options: { [key: string]: unknown } = {},
_options: { [key: string]: unknown } = {},
callback?: HandlerCallback
): Promise<boolean> => {
const actionId = Date.now().toString();
Expand Down
11 changes: 6 additions & 5 deletions packages/plugin-akash/src/actions/createDeployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { AkashError, AkashErrorCode, withRetry } from "../error/error";
import * as fs from 'fs';
import * as path from 'path';
import { getCertificatePath, getDefaultSDLPath } from "../utils/paths";
import { fileURLToPath } from 'url';
// import { fileURLToPath } from 'url';
import { inspectRuntime, isPluginLoaded } from "../runtime_inspect";
import https from 'node:https';
import axios from 'axios';
Expand Down Expand Up @@ -162,7 +162,8 @@ const loadSDLFromFile = (filePath: string): string => {
}
};

const formatErrorMessage = (error: unknown): string => {
// Preserved for future use
/* const formatErrorMessage = (error: unknown): string => {
if (error instanceof AkashError) {
if (error.code === AkashErrorCode.WALLET_NOT_INITIALIZED) {
return "Akash wallet not initialized";
Expand Down Expand Up @@ -196,7 +197,7 @@ const formatErrorMessage = (error: unknown): string => {
return "Failed to parse SDL: Invalid format";
}
return message;
};
}; */

async function initializeWallet(mnemonic: string) {
elizaLogger.debug("=== Initializing Wallet ===", {
Expand Down Expand Up @@ -619,7 +620,7 @@ async function queryLeaseStatus(lease: any, providerUri: string, certificate: Ce
'Content-Type': 'application/json',
'Accept': 'application/json'
},
// @ts-ignore - Node's fetch has agent support
// @ts-expect-error - TypeScript's fetch types don't include Node's agent support, but it exists at runtime
agent,
signal: AbortSignal.timeout(10000)
});
Expand Down Expand Up @@ -1138,7 +1139,7 @@ export const createDeploymentAction: Action = {
runtime: IAgentRuntime,
message: Memory,
state: State | undefined,
options: { [key: string]: unknown; } = {},
_options: { [key: string]: unknown; } = {},
callback?: HandlerCallback
): Promise<boolean> => {
const actionId = Date.now().toString();
Expand Down
7 changes: 3 additions & 4 deletions packages/plugin-akash/src/actions/getDeploymentApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { validateAkashConfig } from "../environment";
import { AkashError, AkashErrorCode } from "../error/error";
import * as fs from 'fs';
import * as path from 'path';
import { getCertificatePath, getDeploymentsPath } from "../utils/paths";
import { getDeploymentsPath } from "../utils/paths";

export interface DeploymentInfo {
owner: string;
Expand Down Expand Up @@ -278,7 +278,6 @@ export async function loadDeploymentInfo(filePath: string): Promise<DeploymentIn
elizaLogger.info("Loading deployment info", { filePath });

try {
const fs = require('fs');
if (!fs.existsSync(filePath)) {
throw new AkashError(
`Deployment info file not found: ${filePath}`,
Expand Down Expand Up @@ -383,14 +382,14 @@ export const getDeploymentApiAction: Action = {
runtime: IAgentRuntime,
message: Memory,
state: State | undefined,
options: { [key: string]: unknown } = {},
_options: { [key: string]: unknown } = {},
callback?: HandlerCallback
): Promise<boolean> => {
const actionId = Date.now().toString();
elizaLogger.info("Starting deployment API request", { actionId });

try {
const config = await validateAkashConfig(runtime);
// const config = await validateAkashConfig(runtime);
const params = message.content as Partial<GetDeploymentsContent>;

// Fetch deployments
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-akash/src/actions/getDeploymentStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export const getDeploymentStatusAction: Action = {
runtime: IAgentRuntime,
message: Memory,
state: State | undefined,
options: { [key: string]: unknown } = {},
_options: { [key: string]: unknown } = {},
callback?: HandlerCallback
): Promise<boolean> => {
const actionId = Date.now().toString();
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-akash/src/actions/getGPUPricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const getGPUPricingAction: Action = {
runtime: IAgentRuntime,
message: Memory,
state: State | undefined,
options: { [key: string]: unknown; } = {},
_options: { [key: string]: unknown; } = {},
callback?: HandlerCallback
): Promise<boolean> => {
const actionId = Date.now().toString();
Expand Down
14 changes: 7 additions & 7 deletions packages/plugin-akash/src/actions/getManifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { AkashError, AkashErrorCode } from "../error/error";
import * as fs from 'fs';
import * as path from 'path';
import yaml from 'js-yaml';
import { getAkashTypeRegistry } from "@akashnetwork/akashjs/build/stargate";
import { getCertificatePath, getDefaultSDLPath } from "../utils/paths";
// import { getAkashTypeRegistry } from "@akashnetwork/akashjs/build/stargate";
import { getDefaultSDLPath } from "../utils/paths";

interface GetManifestContent extends Content {
sdl?: string;
Expand Down Expand Up @@ -121,10 +121,10 @@ const validateSDL = (sdlContent: string, validationLevel: string = "strict"): bo
// });
return true;
} catch (error) {
// elizaLogger.error("SDL validation failed", {
// error: error instanceof Error ? error.message : String(error),
// validationLevel
// });
elizaLogger.error("SDL validation failed", {
error: error instanceof Error ? error.message : String(error),
validationLevel
});
return false;
}
};
Expand Down Expand Up @@ -186,7 +186,7 @@ export const getManifestAction: Action = {
runtime: IAgentRuntime,
message: Memory,
state: State | undefined,
options: { [key: string]: unknown; } = {},
_options: { [key: string]: unknown; } = {},
callback?: HandlerCallback
): Promise<boolean> => {
const actionId = Date.now().toString();
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-akash/src/actions/getProvidersList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export const getProvidersListAction: Action = {
runtime: IAgentRuntime,
message: Memory,
state: State | undefined,
options: { [key: string]: unknown; } = {},
_options: { [key: string]: unknown; } = {},
callback?: HandlerCallback
): Promise<boolean> => {
const actionId = Date.now().toString();
Expand Down
1 change: 0 additions & 1 deletion packages/plugin-akash/src/error/error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { elizaLogger } from "@elizaos/core";

export enum AkashErrorCategory {
WALLET = 'WALLET',
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-akash/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Plugin, elizaLogger } from "@elizaos/core";
import { Plugin} from "@elizaos/core";
import { createDeploymentAction } from "./actions/createDeployment";
import { closeDeploymentAction } from "./actions/closeDeployment";
import { getProviderInfoAction } from "./actions/getProviderInfo";
Expand Down
5 changes: 2 additions & 3 deletions packages/plugin-akash/src/providers/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import { SigningStargateClient } from "@cosmjs/stargate";
import { elizaLogger } from "@elizaos/core";
import { IAgentRuntime, Memory } from "@elizaos/core/src/types";
import { elizaLogger, IAgentRuntime, Memory } from "@elizaos/core";
// import { IAgentRuntime, Memory } from "@elizaos/core/src/types";
import { validateAkashConfig } from "../environment";
import { getAkashTypeRegistry } from "@akashnetwork/akashjs/build/stargate";
import {
AkashProvider,
AkashWalletState,
AkashError,
AKASH_ERROR_CODES,
AkashRegistryTypes
} from "../types";

// Use a proper UUID for the wallet room
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-akash/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { DirectSecp256k1HdWallet, Registry } from "@cosmjs/proto-signing";
import { DirectSecp256k1HdWallet} from "@cosmjs/proto-signing";
import { SigningStargateClient } from "@cosmjs/stargate";
import { Provider } from "@elizaos/core";
// import { Provider } from "@elizaos/core";
import { IAgentRuntime, Memory } from "@elizaos/core";
import { SDL } from "@akashnetwork/akashjs/build/sdl";
import { MsgCreateDeployment } from "@akashnetwork/akash-api/akash/deployment/v1beta3";
import { QueryBidsRequest, MsgCreateLease, BidID } from "@akashnetwork/akash-api/akash/market/v1beta4";
import { MsgCreateLease} from "@akashnetwork/akash-api/akash/market/v1beta4";

// Core wallet state type
export interface AkashWalletState {
Expand Down
3 changes: 1 addition & 2 deletions packages/plugin-akash/src/utils/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import * as path from 'path';
import { fileURLToPath } from 'url';
import { elizaLogger } from "@elizaos/core";
import { existsSync } from 'fs';
import fs from 'fs';
import { getConfig } from '../environment';

export const getPluginRoot = (importMetaUrl: string) => {
Expand Down Expand Up @@ -81,7 +80,7 @@ export const getDefaultSDLPath = (importMetaUrl: string) => {
const config = getConfig(process.env.AKASH_ENV);
const sdlFileName = config.AKASH_SDL;
const sdlPath = path.join(srcPath, 'sdl', sdlFileName);
const sdlDir = path.dirname(sdlPath);
// const sdlDir = path.dirname(sdlPath);

// Only log if file doesn't exist as a warning
if (!existsSync(sdlPath)) {
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-starknet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
],
"dependencies": {
"@elizaos/core": "workspace:*",
"@elizaos/plugin-trustdb": "workspace:*",
"@avnu/avnu-sdk": "2.1.1",
"@uniswap/sdk-core": "6.0.0",
"unruggable-sdk": "1.4.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,4 @@ const walletProvider: Provider = {
},
};

export { walletProvider };
export { walletProvider, TokenBalances };
35 changes: 24 additions & 11 deletions packages/plugin-starknet/src/providers/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
CalculatedBuyAmounts,
Prices,
} from "../types/trustDB.ts";
import { WalletProvider, Item } from "./walletProvider.ts";
import { WalletProvider, TokenBalances } from "./portfolioProvider.ts";
import { num } from "starknet";
import {
analyzeHighSupplyHolders,
Expand Down Expand Up @@ -129,22 +129,35 @@ export class TokenProvider {
}

// TODO: Update to Starknet
async getTokensInWallet(runtime: IAgentRuntime): Promise<Item[]> {
const walletInfo =
await this.walletProvider.fetchPortfolioValue(runtime);
const items = walletInfo.items;
return items;
async getTokensInWallet(): Promise<TokenBalances> {
const tokenBalances =
await this.walletProvider.getWalletPortfolio();
return tokenBalances;
}

// check if the token symbol is in the wallet
async getTokenFromWallet(runtime: IAgentRuntime, tokenSymbol: string) {
async getTokenFromWallet(tokenSymbol: string) {
try {
const items = await this.getTokensInWallet(runtime);
const token = items.find((item) => item.symbol === tokenSymbol);
// Find the token in the PORTFOLIO_TOKENS using the provided tokenSymbol
const portfolioToken = Object.values(PORTFOLIO_TOKENS).find(
(token) => token.coingeckoId === tokenSymbol
);

if (!portfolioToken) {
console.warn(`Token with symbol ${tokenSymbol} not found in PORTFOLIO_TOKENS`);
return null;
}

const tokenAddress = portfolioToken.address;

// Get the list of tokens in the wallet
const items = await this.getTokensInWallet();

if (token) {
return token.address;
// 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;
}
} catch (error) {
Expand Down
Loading

0 comments on commit 9cd60f9

Please sign in to comment.