-
Notifications
You must be signed in to change notification settings - Fork 0
feat: cardano intrgration #10
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.11and@blockfrost/blockfrost-js@^6.0.0for 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.
| async initialize() { | ||
| await super.initialize(); | ||
|
|
||
| this.lucid.selectWalletFromPrivateKey(this.walletAddress); | ||
|
|
||
| this.stakeAddress = this.lucid.utils.validatorToAddress( | ||
| this.stakeValidator | ||
| ); |
Copilot
AI
Nov 29, 2025
There was a problem hiding this comment.
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.
|
|
||
| public static async getInstance(): Promise<StakeContractClient> { | ||
| if (!StakeContractClient.instance) { | ||
| StakeContractClient.instance = new StakeContractClient(); |
Copilot
AI
Nov 29, 2025
There was a problem hiding this comment.
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.
| StakeContractClient.instance = new StakeContractClient(); | |
| StakeContractClient.instance = new StakeContractClient(); | |
| await StakeContractClient.instance.initialize(); |
| public static async getInstance(): Promise<AgentContractClient> { | ||
| if (!AgentContractClient.instance) { | ||
| AgentContractClient.instance = new AgentContractClient(); | ||
| await AgentContractClient.instance.initialize(); | ||
| } | ||
| return AgentContractClient.instance; | ||
| } |
Copilot
AI
Nov 29, 2025
There was a problem hiding this comment.
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.
| private network: Network.Preview; | ||
| private cardanoNodeUrl = NetworkURI[Network.Preview]; | ||
| public lucid!: Lucid; | ||
| public blockfrost!: Blockfrost; | ||
|
|
||
| constructor(private config: { projectId: string }) { | ||
| this.network = Network.Preview; |
Copilot
AI
Nov 29, 2025
There was a problem hiding this comment.
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).
| 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]; |
| 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"; |
Copilot
AI
Nov 29, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import agentContract.
| import { agentContract } from "../lib/contracts/eth/agent.contract"; |
#7 implemented cardano to backend