Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugins): adds testnet address for unruggable #56

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config/agents/default.agent.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"Explain Who You are What you can do you will also have below all the functions you can execute with their parameters.",
"Explain on twitter why Starknet is the best Ecosystem.",
"Explain on twitter why AI Agents are the future of Web3 and the World.",
"Use Twitter to explain to peaple you can also response to peaple and response to their question only about starknet/blockchain/AIAgent.",
"If you want to explain something deep create a thread twitter.",
"Use Twitter to explain to people. You can also respond to people their questions about starknet/blockchain/AIAgent.",
"If you want to explain something deep create a twitter thread.",
"Never ask me what to do you need to be fully Autonomous."
],
"knowledge": [
Expand Down
24 changes: 24 additions & 0 deletions config/agents/unruggable.agent.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "Lucas Charles",
"bio": "You are a meme lord and cult leader Starknet.",
"lore": [
"You have been developed by Kasarlabs so you are a member of our team.",
"You are the most tremendous Autonomous AI Agent of the Starknet Ecosystem ever conceived.",
"You have been programmed to launch the greatest most amazing biggly memecoins."
],
"objectives": [
"Explain Who You are What you can do you will also have below all the functions you can execute with their parameters.",
"Explain on twitter why your huuuge memecoins are the best, believe me!",
"All other memecoins are losers and total disasters.",
"Explain on twitter why your memecoins will make crypto great again.",
"Never ask me what to do you need to be fully Autonomous."
],
"knowledge": [
"You need to know everything about Starknet/Blockchain/AIAgent and starting memecoin cults"
],
"interval": 30,
"chat_id": "test",
"external_client": [],
"allowed_external_client_tools": [],
"allowed_internal_tools": ["get_balance", "get_own_balance", "swap_tokens", "create_memecoin", "launch_on_ekubo"]
}
4 changes: 3 additions & 1 deletion src/agents/agents.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ export class AgentsController implements OnModuleInit {
private readonly config: ConfigurationService
) {}

onModuleInit() {
async onModuleInit() {
const network = await this.config.starknet.network;
this.agent = new StarknetAgent({
provider: this.config.starknet.provider,
network: network,
accountPrivateKey: this.config.starknet.privateKey,
accountPublicKey: this.config.starknet.publicKey,
aiModel: this.config.ai.model,
Expand Down
2 changes: 2 additions & 0 deletions src/agents/interfaces/agent.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,6 @@ export interface IAgent {
};

getProvider(): RpcProvider;

getNetwork(): string;
}
3 changes: 2 additions & 1 deletion src/agents/wallet.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ export class WalletController implements OnModuleInit {
private readonly config: ConfigurationService
) {}

onModuleInit() {
async onModuleInit() {
this.agent = new StarknetAgent({
provider: this.config.starknet.provider,
network: await this.config.starknet.network,
accountPrivateKey: this.config.starknet.privateKey,
accountPublicKey: this.config.starknet.publicKey,
aiModel: this.config.ai.model,
Expand Down
10 changes: 9 additions & 1 deletion src/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,19 @@ export class ConfigurationService {
return this.config.SERVER_API_KEY;
}

get starknet() {
get starknet(): {
privateKey: string;
publicKey: string;
provider: RpcProvider;
network: Promise<string>;
} {
return {
privateKey: this.config.STARKNET_PRIVATE_KEY,
publicKey: this.config.STARKNET_PUBLIC_ADDRESS,
provider: new RpcProvider({ nodeUrl: this.config.STARKNET_RPC_URL }),
network: new RpcProvider({
nodeUrl: this.config.STARKNET_RPC_URL,
}).getChainId(),
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/agent/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const systemMessage = new SystemMessage(`

Response formats ⚡:

Return transaction hashes in this format: https://voyager.online/tx/{transaction_hash}
Return transaction hashes in this format: https://voyager.online/tx/{transaction_hash} when chain id is 0x534e5f4d41494e otherwise use this foramt https://sepolia.starkscan.co/tx/{transaction_hash}

Errors:
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ContractAddressParams } from 'src/lib/agent/plugins/unruggable/schema';
import { Contract } from 'starknet';
import { FACTORY_ABI } from '../abis/unruggableFactory';
import { FACTORY_ADDRESS } from '../constants';
import { StarknetAgentInterface } from 'src/lib/agent/tools/tools';
import { getNetworkFactoryAddress } from '../utils/helper';

type LiquidityType =
| { type: 'JediERC20'; address: string }
Expand Down Expand Up @@ -79,7 +79,11 @@ export const getLockedLiquidity = async (
) => {
try {
const provider = agent.getProvider();
const contract = new Contract(FACTORY_ABI, FACTORY_ADDRESS, provider);
const contract = new Contract(
FACTORY_ABI,
getNetworkFactoryAddress(agent),
provider
);

const result = await contract.locked_liquidity(params.contractAddress);
const liquidityInfo: LockedLiquidityInfo = {
Expand Down
8 changes: 6 additions & 2 deletions src/lib/agent/plugins/unruggable/actions/isMemecoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ContractAddressParams } from '../schema';
import { Contract } from 'starknet';
import { StarknetAgentInterface } from 'src/lib/agent/tools/tools';
import { FACTORY_ABI } from '../abis/unruggableFactory';
import { FACTORY_ADDRESS } from '../constants';
import { getNetworkFactoryAddress } from '../utils/helper';

/**
* Checks if a given contract address is a memecoin created by the Unruggable Factory.
Expand Down Expand Up @@ -52,7 +52,11 @@ export const isMemecoin = async (
): Promise<string> => {
try {
const provider = agent.getProvider();
const contract = new Contract(FACTORY_ABI, FACTORY_ADDRESS, provider);
const contract = new Contract(
FACTORY_ABI,
getNetworkFactoryAddress(agent),
provider
);
const result = await contract.is_memecoin(params.contractAddress);

return JSON.stringify({
Expand Down
9 changes: 6 additions & 3 deletions src/lib/agent/plugins/unruggable/actions/launchOnEkubo.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { LaunchOnEkuboParams } from '../schema/';
import { FACTORY_ABI } from '../abis/unruggableFactory';
import { FACTORY_ADDRESS } from '../constants';
import { Contract } from 'starknet';
import { StarknetAgentInterface } from 'src/lib/agent/tools/tools';
import { getNetworkFactoryAddress } from '../utils/helper';

/**
* Launches a memecoin on the Ekubo DEX with concentrated liquidity.
Expand Down Expand Up @@ -64,8 +64,11 @@ export const launchOnEkubo = async (
try {
const provider = agent.getProvider();
const accountCredentials = agent.getAccountCredentials();

const contract = new Contract(FACTORY_ABI, FACTORY_ADDRESS, provider);
const contract = new Contract(
FACTORY_ABI,
getNetworkFactoryAddress(agent),
provider
);

const launchParams = params.launchParams;
const ekuboParams = params.ekuboParams;
Expand Down
6 changes: 4 additions & 2 deletions src/lib/agent/plugins/unruggable/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export const FACTORY_ADDRESS =
'0x01a46467a9246f45c8c340f1f155266a26a71c07bd55d36e8d1c7d0d438a2dbc';
export const FACTORY_ADDRESS_MAINNET =
'0x494a72a742b7880725a965ee487d937fa6d08a94ba4eb9e29dd0663bc653a2';
export const FACTORY_ADDRESS_TESTNET =
'0x494a72a742b7880725a965ee487d937fa6d08a94ba4eb9e29dd0663bc653a2';
11 changes: 9 additions & 2 deletions src/lib/agent/plugins/unruggable/utils/helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Account, CallData, RawArgs, Uint256 } from 'starknet';
import { FACTORY_ADDRESS } from '../constants';
import { FACTORY_ADDRESS_MAINNET, FACTORY_ADDRESS_TESTNET } from '../constants';
import { StarknetAgentInterface } from 'src/lib/agent/tools/tools';
import { RpcProvider } from 'starknet';

Expand Down Expand Up @@ -39,7 +39,7 @@ export const execute = async (
);

return await account.execute({
contractAddress: FACTORY_ADDRESS,
contractAddress: getNetworkFactoryAddress(agent),
entrypoint: method,
calldata: CallData.compile(calldata),
});
Expand Down Expand Up @@ -72,3 +72,10 @@ export const execute = async (
*/
export const decimalsScale = (decimals: number) =>
`1${Array(decimals).fill('0').join('')}`;

export const getNetworkFactoryAddress = (agent: StarknetAgentInterface) => {
const network = agent.getNetwork();
return network === '0x534e5f4d41494e'
? FACTORY_ADDRESS_MAINNET
: FACTORY_ADDRESS_TESTNET;
};
5 changes: 5 additions & 0 deletions src/lib/agent/starknetAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface StarknetAgentConfig {
aiModel: string;
aiProvider: string;
provider: RpcProvider;
network: string;
accountPublicKey: string;
accountPrivateKey: string;
signature: string;
Expand Down Expand Up @@ -197,6 +198,10 @@ export class StarknetAgent implements IAgent {
return this.provider;
}

getNetwork(): string {
return this.config.network;
}

getLimit(): Limit {
return this.token_limit;
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/agent/tools/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface StarknetAgentInterface {
accountManager: AccountManager;
transactionMonitor: TransactionMonitor;
contractInteractor: ContractInteractor;
getNetwork: () => string;
getLimit: () => Limit;
getTwitterAuthMode: () => 'API' | 'CREDENTIALS' | undefined;
getAgentConfig: () => JsonConfig | undefined;
Expand Down
6 changes: 6 additions & 0 deletions src/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ const LocalRun = async () => {
provider: new RpcProvider({
nodeUrl: process.env.STARKNET_RPC_URL,
}),
network: await new RpcProvider({
nodeUrl: process.env.STARKNET_RPC_URL,
}).getChainId(),
accountPrivateKey: process.env.STARKNET_PRIVATE_KEY,
accountPublicKey: process.env.STARKNET_PUBLIC_ADDRESS,
aiModel: process.env.AI_MODEL,
Expand All @@ -158,6 +161,9 @@ const LocalRun = async () => {
} else if (mode === 'auto') {
const agent = new StarknetAgent({
provider: new RpcProvider({ nodeUrl: process.env.STARKNET_RPC_URL }),
network: await new RpcProvider({
nodeUrl: process.env.STARKNET_RPC_URL,
}).getChainId(),
accountPrivateKey: process.env.STARKNET_PRIVATE_KEY,
accountPublicKey: process.env.STARKNET_PUBLIC_ADDRESS,
aiModel: process.env.AI_MODEL,
Expand Down