Skip to content
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
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"access": "public"
},
"dependencies": {
"starknet": "^7.6.4",
"starknet": "8.6.0",
"winston": "^3.17.0",
"zod": "^3.24.2"
},
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ export const getOnchainWrite = (): onchainWrite => {
}

const provider = new RpcProvider({ nodeUrl: rpcUrl });
const account = new Account(provider, accountAddress, privateKey);
const account = new Account({
provider: provider,
address: accountAddress,
signer: privateKey,
});

return {
provider,
Expand Down
2 changes: 1 addition & 1 deletion packages/mcps/argent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@langchain/core": "^0.3.75",
"@modelcontextprotocol/sdk": "^1.11.2",
"dotenv": "^16.4.7",
"starknet": "^7.6.4",
"starknet": "8.6.0",
"winston": "^3.17.0",
"zod": "^3.24.2"
},
Expand Down
21 changes: 10 additions & 11 deletions packages/mcps/argent/src/lib/utils/AccountManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ export class AccountManager implements BaseUtilityClass {
accountDetails: AccountDetails
): Promise<TransactionResult> {
try {
const account = new Account(
this.provider,
accountDetails.contractAddress,
accountDetails.privateKey
);
const account = new Account({
provider: this.provider,
address: accountDetails.contractAddress,
signer: accountDetails.privateKey,
});

const axSigner = new CairoCustomEnum({
Starknet: { pubkey: accountDetails.publicKey },
Expand Down Expand Up @@ -124,12 +124,11 @@ export class AccountManager implements BaseUtilityClass {
accountDetails: AccountDetails
) {
try {
const account = new Account(
this.provider,
accountDetails.contractAddress,
accountDetails.privateKey
);

const account = new Account({
provider: this.provider,
address: accountDetails.contractAddress,
signer: accountDetails.privateKey,
});
const axSigner = new CairoCustomEnum({
Starknet: { pubkey: accountDetails.publicKey },
});
Expand Down
2 changes: 1 addition & 1 deletion packages/mcps/artpeace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@modelcontextprotocol/sdk": "^1.11.2",
"@nestjs/common": "^11.1.6",
"dotenv": "^16.4.7",
"starknet": "^7.1.0",
"starknet": "8.6.0",
"winston": "^3.17.0",
"zod": "^3.24.2"
},
Expand Down
7 changes: 5 additions & 2 deletions packages/mcps/artpeace/src/tools/placePixel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ export const placePixel = async (
const account = env.account;
const provider = env.provider;

const artpeaceContract = new Contract(artpeaceAbi, artpeaceAddr, provider);
const artpeaceContract = new Contract({
abi: artpeaceAbi,
address: artpeaceAddr,
providerOrAccount: account,
});
const checker = new Checker(params[0].canvasId ?? 0);
const id = await checker.checkWorld();
await checker.getColors();
Expand All @@ -34,7 +38,6 @@ export const placePixel = async (
);
const timestamp = Math.floor(Date.now() / 1000);

artpeaceContract.connect(account);
const call = artpeaceContract.populate('place_pixel', {
canvas_id: id,
pos: position,
Expand Down
2 changes: 1 addition & 1 deletion packages/mcps/avnu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@langchain/core": "^0.3.75",
"@modelcontextprotocol/sdk": "^1.11.2",
"dotenv": "^16.4.7",
"starknet": "^7.6.4",
"starknet": "8.6.0",
"winston": "^3.17.0",
"zod": "^3.24.2"
},
Expand Down
21 changes: 16 additions & 5 deletions packages/mcps/avnu/src/lib/utils/contractInteractor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { Account, Contract, Call, CallData, hash, EstimateFee } from 'starknet';
import {
Account,
Contract,
Call,
CallData,
hash,
EstimateFeeResponseOverhead,
} from 'starknet';
import {
BaseUtilityClass,
ContractDeployResult,
Expand Down Expand Up @@ -39,7 +46,7 @@ export class ContractInteractor implements BaseUtilityClass {
classHash: string,
constructorCalldata: any[] = [],
salt?: string
): Promise<EstimateFee> {
): Promise<EstimateFeeResponseOverhead> {
try {
const deployPayload = {
classHash,
Expand Down Expand Up @@ -73,7 +80,7 @@ export class ContractInteractor implements BaseUtilityClass {
async estimateMulticall(
account: Account,
calls: Call[]
): Promise<EstimateFee> {
): Promise<EstimateFeeResponseOverhead> {
try {
return account.estimateInvokeFee(calls);
} catch (error) {
Expand All @@ -82,7 +89,11 @@ export class ContractInteractor implements BaseUtilityClass {
}

createContract(abi: any[], address: string, account?: Account): Contract {
return new Contract(abi, address, account || this.provider);
return new Contract({
abi,
address,
providerOrAccount: account || this.provider,
});
}

async readContract(
Expand Down Expand Up @@ -122,7 +133,7 @@ export class ContractInteractor implements BaseUtilityClass {
contract: Contract,
method: string,
args: any[] = []
): Promise<EstimateFee> {
): Promise<EstimateFeeResponseOverhead> {
if (!contract.account) {
throw new Error(
'Contract must be connected to an account to estimate fees'
Expand Down
1 change: 0 additions & 1 deletion packages/mcps/avnu/src/tools/approval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export class ApprovalService {
const requiredAmount = BigInt(amount);

if (currentAllowance < requiredAmount) {
contract.connect(account);
const approveCall = await contract.approve(
spenderAddress,
uint256.bnToUint256(amount)
Expand Down
2 changes: 1 addition & 1 deletion packages/mcps/braavos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@langchain/core": "^0.3.75",
"@modelcontextprotocol/sdk": "^1.11.2",
"dotenv": "^16.4.7",
"starknet": "^7.6.4",
"starknet": "8.6.0",
"winston": "^3.17.0",
"zod": "^3.24.2"
},
Expand Down
52 changes: 28 additions & 24 deletions packages/mcps/braavos/src/lib/utils/AccountManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import {
BigNumberish,
Calldata,
num,
EDAMode,
ETransactionVersion,
ResourceBoundsBN,
} from 'starknet';

import {
Expand Down Expand Up @@ -68,43 +71,35 @@ export class AccountManager implements BaseUtilityClass {
* @async
* @method estimateAccountDeployFee
* @param {AccountDetails} accountDetails - The account details for deployment
* @returns {Promise<bigint>} The estimated maximum fee
* @returns {Promise<{resourceBounds: ResourceBoundsBN, maxFee: bigint}>} The estimated resource bounds and max fee
* @throws {Error} If fee estimation fails
*/
async estimateAccountDeployFee(
accountDetails: AccountDetails
): Promise<bigint> {
): Promise<{ resourceBounds: ResourceBoundsBN; maxFee: bigint }> {
try {
const version = constants.TRANSACTION_VERSION.V1;
const version = ETransactionVersion.V3;
const nonce = constants.ZERO;
const chainId = await this.provider.getChainId();

const initializer = this.calcInit(accountDetails.publicKey);
const constructorCalldata = this.getProxyConstructor(initializer);

const signature = this.getBraavosSignature(
accountDetails.contractAddress,
constructorCalldata,
accountDetails.publicKey,
constants.ZERO,
chainId,
BigInt(nonce),
accountDetails.privateKey
);

const deployAccountPayload = {
classHash: this.proxyClassHash,
constructorCalldata,
addressSalt: accountDetails.publicKey,
signature,
};

const response = await this.provider.getDeployAccountEstimateFee(
deployAccountPayload,
{ version, nonce }
);

return stark.estimatedFeeToMaxFee(response.overall_fee);
return {
resourceBounds: response.resourceBounds,
maxFee: response.overall_fee,
};
} catch (error) {
throw new Error(`Failed to estimate deploy fee: ${error.message}`);
}
Expand All @@ -115,29 +110,34 @@ export class AccountManager implements BaseUtilityClass {
* @async
* @method deployAccount
* @param {AccountDetails} accountDetails - The account details for deployment
* @param {ResourceBoundsBN} [resourceBounds] - Optional resource bounds for deployment
* @param {BigNumberish} [maxFee] - Optional maximum fee for deployment
* @returns {Promise<TransactionResult>} The deployment transaction result
* @throws {Error} If deployment fails
*/
async deployAccount(
accountDetails: AccountDetails,
resourceBounds?: ResourceBoundsBN,
maxFee?: BigNumberish
): Promise<TransactionResult> {
try {
const version = constants.TRANSACTION_VERSION.V1;
const version = ETransactionVersion.V3;
const nonce = constants.ZERO;
const chainId = await this.provider.getChainId();

const initializer = this.calcInit(accountDetails.publicKey);
const constructorCalldata = this.getProxyConstructor(initializer);

maxFee = maxFee ?? (await this.estimateAccountDeployFee(accountDetails));

if (!resourceBounds || !maxFee) {
const estimated = await this.estimateAccountDeployFee(accountDetails);
resourceBounds = resourceBounds ?? estimated.resourceBounds;
maxFee = maxFee ?? estimated.maxFee;
}
const signature = this.getBraavosSignature(
accountDetails.contractAddress,
constructorCalldata,
accountDetails.publicKey,
maxFee,
resourceBounds,
chainId,
BigInt(nonce),
accountDetails.privateKey
Expand Down Expand Up @@ -184,22 +184,26 @@ export class AccountManager implements BaseUtilityClass {

private getBraavosSignature(
contractAddress: BigNumberish,
constructorCalldata: Calldata,
compiledConstructorCalldata: Calldata,
publicKey: BigNumberish,
maxFee: BigNumberish,
resourceBounds: ResourceBoundsBN,
chainId: constants.StarknetChainId,
nonce: bigint,
privateKey: BigNumberish
): string[] {
const txHash = hash.calculateDeployAccountTransactionHash({
contractAddress,
classHash: this.proxyClassHash,
constructorCalldata,
compiledConstructorCalldata,
salt: publicKey,
version: constants.TRANSACTION_VERSION.V1,
maxFee,
version: ETransactionVersion.V3,
chainId,
nonce,
nonceDataAvailabilityMode: EDAMode.L2,
feeDataAvailabilityMode: EDAMode.L2,
resourceBounds,
paymasterData: [],
tip: 0,
});

const parsedOtherSigner = [0, 0, 0, 0, 0, 0, 0];
Expand Down
2 changes: 1 addition & 1 deletion packages/mcps/braavos/src/tools/createAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const CreateBraavosAccountSignature = async () => {

const suggestedMaxFee =
await accountManager.estimateAccountDeployFee(accountDetails);
const maxFee = suggestedMaxFee * 2n;
const maxFee = suggestedMaxFee.maxFee;

return {
status: 'success',
Expand Down
2 changes: 1 addition & 1 deletion packages/mcps/contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@kasarlabs/ask-starknet-core": "workspace:*",
"@modelcontextprotocol/sdk": "^1.11.2",
"dotenv": "^16.4.7",
"starknet": "^7.6.4",
"starknet": "8.6.0",
"winston": "^3.17.0",
"zod": "^3.24.2"
},
Expand Down
6 changes: 5 additions & 1 deletion packages/mcps/contract/src/tools/getConstructorParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ export const getConstructorParams = async (
const provider = new RpcProvider({
nodeUrl: 'https://starknet-mainnet.public.blastapi.io',
});
const dummyAccount = new Account(provider, '0x1', '0x1');
const dummyAccount = new Account({
provider,
address: '0x1',
signer: '0x1',
});

const contractManager = new ContractManager(dummyAccount);
await contractManager.loadContractCompilationFiles(
Expand Down
2 changes: 1 addition & 1 deletion packages/mcps/ekubo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@kasarlabs/ask-starknet-core": "workspace:*",
"@modelcontextprotocol/sdk": "^1.11.2",
"dotenv": "^16.4.7",
"starknet": "^7.6.4",
"starknet": "8.6.0",
"zod": "^3.24.2"
},
"devDependencies": {
Expand Down
20 changes: 13 additions & 7 deletions packages/mcps/ekubo/src/lib/utils/contracts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RpcProvider, shortString, Contract } from 'starknet';
import { RpcProvider, shortString, Contract, Account } from 'starknet';
import { ekuboAddress } from '../constants/addresses.js';
import {
CORE_ABI,
Expand Down Expand Up @@ -42,30 +42,36 @@ export function getEkuboAddress(

/**
* Get a contract instance for a specific Ekubo contract type
* @param account - Account instance for signing transactions
* @param provider - RPC provider
* @param contractType - Type of contract to instantiate
* @returns Contract instance
*/
export async function getContract(
provider: RpcProvider,
contractType: EkuboContract
contractType: EkuboContract,
account?: Account
): Promise<Contract> {
const chain = await getChain(provider);
const address = getEkuboAddress(contractType, chain);
const abi = CONTRACT_ABIS[contractType];

return new Contract(abi, address, provider);
return new Contract({ abi, address, providerOrAccount: account ?? provider });
}

/**
* Get an ERC20 contract instance
* @param account - Account instance for signing transactions
* @param tokenAddress - Token contract address
* @param provider - RPC provider
* @returns ERC20 Contract instance
*/
export function getERC20Contract(
tokenAddress: string,
provider: RpcProvider
account: Account,
tokenAddress: string
): Contract {
return new Contract(NEW_ERC20_ABI, tokenAddress, provider);
return new Contract({
abi: NEW_ERC20_ABI,
address: tokenAddress,
providerOrAccount: account,
});
}
Loading