Skip to content

Commit

Permalink
progress before rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
0xNoushad committed Jan 2, 2025
1 parent e39ff94 commit b1b6cbb
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 47 deletions.
88 changes: 48 additions & 40 deletions src/agent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import {
create_TipLink,
listNFTForSale,
cancelListing,

} from "../tools";

import {
Expand All @@ -59,7 +58,7 @@ import {
PumpFunTokenOptions,
} from "../types";
import { BN } from "@coral-xyz/anchor";
import { WalletAdapter , walletManager } from "../tools/walletManager";
import { WalletAdapter , walletManager } from "../wallet/walletmanager";


/**
Expand All @@ -72,45 +71,54 @@ import { WalletAdapter , walletManager } from "../tools/walletManager";
* @property {PublicKey} wallet_address - Public key of the wallet
* @property {Config} config - Configuration object
*/
export class SolanaAgentKit {
public connection: Connection;
public wallet: WalletAdapter;
public wallet_address: PublicKey;
private config: Config;

/**
* @deprecated Using openai_api_key directly in constructor is deprecated.
* Please use the new constructor with Config object instead:
* @example
* const agent = new SolanaAgentKit(privateKey, rpcUrl, {
* OPENAI_API_KEY: 'your-key'
* });
*/
constructor(
walletOrPrivateKey: WalletAdapter | string | Keypair,
rpc_url: string = "https://api.mainnet-beta.solana.com",
config: Config = {}
) {
this.connection = new Connection(rpc_url);
this.wallet = this.initializeWallet(walletOrPrivateKey);
this.wallet_address = this.wallet.publicKey;
this.config = config;
}

private initializeWallet(walletOrPrivateKey: WalletAdapter | string | Keypair): WalletAdapter {
if (typeof walletOrPrivateKey === 'string') {
const keypair = Keypair.fromSecretKey(bs58.decode(walletOrPrivateKey));
walletManager.connectWallet(keypair);
} else if (walletOrPrivateKey instanceof Keypair) {
walletManager.connectWallet(walletOrPrivateKey);
} else {
walletManager.connectWallet(walletOrPrivateKey);
}
return walletManager.getWallet();
}




export class SolanaAgentKit {
public connection: Connection;
public wallet: WalletAdapter;
public wallet_address: PublicKey;
public config: Config;

/**
* @deprecated Using openai_api_key directly in constructor is deprecated.
* Please use the new constructor with Config object instead:
* @example
* const agent = new SolanaAgentKit(privateKey, rpcUrl, {
* OPENAI_API_KEY: 'your-key'
* });
*/
constructor(private_key: string, rpc_url: string, openai_api_key: string | null);
constructor(private_key: string, rpc_url: string, config: Config);
constructor(
walletOrPrivateKey: WalletAdapter | string | Keypair,
rpc_url: string = "https://api.mainnet-beta.solana.com",
configOrOpenAIKey: Config | string | null = {}
) {
this.connection = new Connection(rpc_url);
this.wallet = this.initializeWallet(walletOrPrivateKey);
this.wallet_address = this.wallet.publicKey;

if (typeof configOrOpenAIKey === 'string' || configOrOpenAIKey === null) {
console.warn('Deprecated: Using openai_api_key directly in constructor is deprecated. Please use the new constructor with Config object instead.');
this.config = { OPENAI_API_KEY: configOrOpenAIKey || undefined };
} else {
this.config = configOrOpenAIKey;
}
}
private initializeWallet(walletOrPrivateKey: WalletAdapter | string | Keypair): WalletAdapter {
if (typeof walletOrPrivateKey === 'string') {

const keypair = Keypair.fromSecretKey(bs58.decode(walletOrPrivateKey));
walletManager.connectWallet(keypair, keypair);
} else if (walletOrPrivateKey instanceof Keypair) {
walletManager.connectWallet(walletOrPrivateKey, walletOrPrivateKey);
} else {
const keypair = Keypair.generate();
walletManager.connectWallet(walletOrPrivateKey, keypair);
}
return walletManager.getWallet();
}

// Tool methods
async requestFaucetFunds() {
return request_faucet_funds(this);
Expand Down
6 changes: 3 additions & 3 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { PublicKey } from "@solana/web3.js";

export interface Config {
OPENAI_API_KEY?: string;
JUPITER_REFERRAL_ACCOUNT?: string;
JUPITER_FEE_BPS?: number;
OPENAI_API_KEY?: string | undefined;
JUPITER_REFERRAL_ACCOUNT?: string | undefined;
JUPITER_FEE_BPS?: number | undefined;
}

export interface Creator {
Expand Down
9 changes: 5 additions & 4 deletions src/utils/keypair.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// keypair.ts
import { Keypair } from "@solana/web3.js";
import bs58 from "bs58";
import { walletManager } from "../tools/walletManager";
import { walletManager } from "../wallet/walletmanager";

export const keypair = Keypair.generate();
const wallet = walletManager.connectWallet(keypair);
const walletId = keypair.publicKey.toString();
const wallet = walletManager.connectWallet(walletId, keypair);

console.log(keypair.publicKey.toString());
console.log(bs58.encode(keypair.secretKey));

export { wallet };

export { wallet };
File renamed without changes.

0 comments on commit b1b6cbb

Please sign in to comment.