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 5 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
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Starknet configuration (mandatory)
STARKNET_NETWORK=testnet
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you keep an exemple value here like YOUR_STARKNET_NETWORK

STARKNET_PUBLIC_ADDRESS="YOUR_STARKNET_PUBLIC_ADDRESS"
STARKNET_PRIVATE_KEY="YOUR_STARKNET_PRIVATE_KEY"
STARKNET_RPC_URL="YOUR_STARKNET_RPC_URL"
Expand All @@ -20,7 +21,7 @@ DISCORD_BOT_TOKEN?="YOUR_DISCORD_BOT_TOKEN"
DISCORD_CHANNEL_ID?="YOUR_DISCORD_CHANNEL_ID"

#Twitter Configuration Mode "API" || "CREDIDENTIALS"
TWITTER_AUTH_MODE?="YOUR_TWITTEr_CONFIGURATION_MODE"
TWITTER_AUTH_MODE?="YOUR_TWITTER_CONFIGURATION_MODE"

# OAuth 2.0 API Credentials
TWITTER_API?="YOUR_TWITTER_API"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Create a `.env` file:

```env
# Starknet configuration (mandatory)
STARKNET_NETWORK=testnet
STARKNET_PUBLIC_ADDRESS="YOUR_STARKNET_PUBLIC_ADDRESS"
STARKNET_PRIVATE_KEY="YOUR_STARKNET_PRIVATE_KEY"
STARKNET_RPC_URL="YOUR_STARKNET_RPC_URL"
Expand Down
8 changes: 4 additions & 4 deletions config/agents/default.agent.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
"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": [
"You need to know everything about Starknet/Blockchain/AIAgent."
],
"interval": 30,
"chat_id": "test",
"external_client": ["discord"],
"allowed_external_client_tools": ["discord-send-messages"]
"external_client": [],
"allowed_external_client_tools": [],
"allowed_internal_tools": ["get_balance", "get_own_balance", "swap_tokens"]
}
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", "launch_memecoin", "launch_on_ekubo"]
}
1 change: 1 addition & 0 deletions module.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
declare namespace NodeJS {
export interface ProcessEnv {
STARKNET_NETWORK: string;
STARKNET_PRIVATE_KEY: string;
STARKNET_PUBLIC_ADDRESS: string;
STARKNET_RPC_URL: string;
Expand Down
49 changes: 44 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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;
}
2 changes: 2 additions & 0 deletions src/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class ConfigurationService {
NODE_ENV: this.configService.get<string>('NODE_ENV'),
SERVER_PORT: this.configService.get<string>('SERVER_PORT'),
SERVER_API_KEY: this.configService.get<string>('SERVER_API_KEY'),
STARKNET_NETWORK: this.configService.get<string>('STARKNET_NETWORK'),
STARKNET_PRIVATE_KEY: this.configService.get<string>(
'STARKNET_PRIVATE_KEY'
),
Expand Down Expand Up @@ -57,6 +58,7 @@ export class ConfigurationService {
privateKey: this.config.STARKNET_PRIVATE_KEY,
publicKey: this.config.STARKNET_PUBLIC_ADDRESS,
provider: new RpcProvider({ nodeUrl: this.config.STARKNET_RPC_URL }),
network: this.config.STARKNET_NETWORK,
};
}

Expand Down
2 changes: 2 additions & 0 deletions src/config/env.validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export const envSchema = z
.min(1, 'API key is required for server authentication'),

// Starknet configuration
/** Starknet network to interact with */
STARKNET_NETWORK: z.string().default('testnet'),
/** Private key for Starknet blockchain interactions */
STARKNET_PRIVATE_KEY: z
.string()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ContractAddressParams } from 'src/lib/agent/schemas/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 'src/lib/agent/schemas/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 'src/lib/agent/schemas/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 === 'mainnet'
? 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 @@ -116,6 +116,7 @@ export interface StarknetAgentInterface {
accountManager: AccountManager;
transactionMonitor: TransactionMonitor;
contractInteractor: ContractInteractor;
getNetwork: () => string;
getLimit: () => Limit;
getTwitterAuthMode: () => 'API' | 'CREDIDENTIALS' | undefined;
getAgentConfig: () => JsonConfig | undefined;
Expand Down
3 changes: 3 additions & 0 deletions src/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const createBox = (

const validateEnvVars = () => {
const required = [
'STARKNET_NETWORK',
'STARKNET_RPC_URL',
'STARKNET_PRIVATE_KEY',
'STARKNET_PUBLIC_ADDRESS',
Expand Down Expand Up @@ -136,6 +137,7 @@ const LocalRun = async () => {
provider: new RpcProvider({
nodeUrl: process.env.STARKNET_RPC_URL,
}),
network: process.env.STARKNET_NETWORK,
accountPrivateKey: process.env.STARKNET_PRIVATE_KEY,
accountPublicKey: process.env.STARKNET_PUBLIC_ADDRESS,
aiModel: process.env.AI_MODEL,
Expand All @@ -158,6 +160,7 @@ const LocalRun = async () => {
} else if (mode === 'auto') {
const agent = new StarknetAgent({
provider: new RpcProvider({ nodeUrl: process.env.STARKNET_RPC_URL }),
network: process.env.STARKNET_NETWORK,
accountPrivateKey: process.env.STARKNET_PRIVATE_KEY,
accountPublicKey: process.env.STARKNET_PUBLIC_ADDRESS,
aiModel: process.env.AI_MODEL,
Expand Down
Loading