Skip to content

Conversation

@AdityaTote
Copy link
Contributor

#7 implemented cardano to backend

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds Cardano blockchain integration to the backend system, expanding the platform's multi-chain capabilities beyond Ethereum. The PR reorganizes existing Ethereum contracts into a dedicated subdirectory and introduces comprehensive Cardano smart contract clients for agent and stake management using Lucid-Cardano and Blockfrost.

Key Changes

  • Cardano Integration: Added complete Cardano blockchain support with agent and stake contract clients using Lucid-Cardano
  • Code Organization: Restructured contract files by separating Ethereum contracts into eth/ subdirectory for better multi-chain organization
  • New Dependencies: Added lucid-cardano@^0.10.11 and @blockfrost/blockfrost-js@^6.0.0 for Cardano blockchain interaction

Reviewed changes

Copilot reviewed 14 out of 18 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/services/agent.service.ts Updated import path for Ethereum agent contract
src/lib/utils/helper.ts Updated import path for Ethereum stake contract
src/lib/env.ts Added new environment variables for Cardano integration (BLACKFROST_PROJECT_ID, WALLET_PRIVATE_KEY) with formatting changes
src/lib/contracts/eth/stake.contract.ts Moved and updated with corrected import paths, commented out unused helper function
src/lib/contracts/eth/contract.ts Moved to eth subdirectory with unused Contract import removed
src/lib/contracts/eth/agent.contract.ts Moved to eth subdirectory with updated import path
src/lib/contracts/eth/abis/stake-abis.json Moved Ethereum stake contract ABI to eth subdirectory
src/lib/contracts/eth/abis/agent-abis.json Moved Ethereum agent contract ABI to eth subdirectory
src/lib/contracts/cardano/stake.contract.ts New Cardano stake contract client with transfer functionality
src/lib/contracts/cardano/schema/stake-contract.types.ts Type definitions and schemas for Cardano stake contract
src/lib/contracts/cardano/schema/agent-contract.types.ts Type definitions and schemas for Cardano agent contract
src/lib/contracts/cardano/contract.ts Base Cardano contract client with Lucid and Blockfrost initialization
src/lib/contracts/cardano/agent.contract.ts Cardano agent contract client with register, update, and query functionality
src/lib/contracts/cardano/abis/plutus.json Plutus smart contract ABIs for Cardano validators
package.json Added Cardano dependencies and build script with formatting changes
bun.lock Updated lockfile with new Cardano-related dependencies
.gitignore Added /dist directory to ignore list
.env.example Updated with new required environment variables for Cardano integration

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Comment on lines +28 to +35
async initialize() {
await super.initialize();

this.lucid.selectWalletFromPrivateKey(this.walletAddress);

this.stakeAddress = this.lucid.utils.validatorToAddress(
this.stakeValidator
);
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

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

The initialize() method is called in the constructor but not awaited. This method is async and should be awaited to ensure proper initialization before the instance is used. Consider making getInstance() the only way to create instances and handle initialization there.

Copilot uses AI. Check for mistakes.

public static async getInstance(): Promise<StakeContractClient> {
if (!StakeContractClient.instance) {
StakeContractClient.instance = new StakeContractClient();
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

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

The getInstance() method doesn't await the initialize() call, which means the instance might not be fully initialized when returned. This could lead to runtime errors when methods try to use this.lucid or this.stakeAddress before they're properly set up.

Suggested change
StakeContractClient.instance = new StakeContractClient();
StakeContractClient.instance = new StakeContractClient();
await StakeContractClient.instance.initialize();

Copilot uses AI. Check for mistakes.
Comment on lines +37 to +43
public static async getInstance(): Promise<AgentContractClient> {
if (!AgentContractClient.instance) {
AgentContractClient.instance = new AgentContractClient();
await AgentContractClient.instance.initialize();
}
return AgentContractClient.instance;
}
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

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

The same initialization issue exists here. The initialize() method is async but not awaited when creating a new instance in getInstance(). This could cause this.agentAddress and this.agentUtxo to be undefined when methods are called immediately after getting the instance.

Copilot uses AI. Check for mistakes.
Comment on lines +16 to +22
private network: Network.Preview;
private cardanoNodeUrl = NetworkURI[Network.Preview];
public lucid!: Lucid;
public blockfrost!: Blockfrost;

constructor(private config: { projectId: string }) {
this.network = Network.Preview;
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

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

[nitpick] The hardcoded network type Network.Preview limits flexibility. Consider making the network configurable through environment variables to support different environments (Mainnet, Preprod, Preview).

Suggested change
private network: Network.Preview;
private cardanoNodeUrl = NetworkURI[Network.Preview];
public lucid!: Lucid;
public blockfrost!: Blockfrost;
constructor(private config: { projectId: string }) {
this.network = Network.Preview;
private network: Network;
private cardanoNodeUrl: string;
public lucid!: Lucid;
public blockfrost!: Blockfrost;
constructor(private config: { projectId: string }) {
const envNetwork = process.env.CARDANO_NETWORK;
if (
envNetwork === Network.Mainnet ||
envNetwork === Network.Preprod ||
envNetwork === Network.Preview
) {
this.network = envNetwork as Network;
} else {
this.network = Network.Preview;
}
this.cardanoNodeUrl = NetworkURI[this.network];

Copilot uses AI. Check for mistakes.
import { setCookie } from "hono/cookie";
import { prisma } from "../lib/db";
import { agentContract } from "../lib/contracts/agent.contract";
import { agentContract } from "../lib/contracts/eth/agent.contract";
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

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

Unused import agentContract.

Suggested change
import { agentContract } from "../lib/contracts/eth/agent.contract";

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants