Complete Integration Example
// Initialize SOVEREIGN protocol integration
class SovereignProtocol {
constructor(web3Provider) {
this.web3 = new Web3(web3Provider);
this.contracts = {};
this.initialized = false;
}
async initialize() {
// Load contract addresses
const deployment = await fetch('/deployments/localhost-deployment.json');
const addresses = await deployment.json();
// Initialize contracts
this.contracts = {
sovToken: new this.web3.eth.Contract(SOV_ABI, addresses.contracts.SOVToken),
treasury: new this.web3.eth.Contract(TREASURY_ABI, addresses.contracts.SovereignTreasury),
staking: new this.web3.eth.Contract(STAKING_ABI, addresses.contracts.SovereignStaking),
agentController: new this.web3.eth.Contract(CONTROLLER_ABI, addresses.contracts.AgentController)
};
this.initialized = true;
}
async getProtocolOverview() {
if (!this.initialized) await this.initialize();
const [totalSupply, treasuryBalance, totalStaked, successRate, agentCount] = await Promise.all([
this.contracts.sovToken.methods.totalSupply().call(),
this.contracts.treasury.methods.getTreasuryBalance().call(),
this.contracts.staking.methods.getTotalStaked().call(),
this.contracts.treasury.methods.getSuccessRate().call(),
this.contracts.agentController.methods.getAgentCount().call()
]);
return {
totalSupply: this.web3.utils.fromWei(totalSupply, 'ether'),
treasuryBalance: this.web3.utils.fromWei(treasuryBalance, 'ether'),
totalStaked: this.web3.utils.fromWei(totalStaked, 'ether'),
treasurySuccessRate: successRate + '%',
activeAgents: parseInt(agentCount)
};
}
}
// Usage
const sovereign = new SovereignProtocol(window.ethereum);
const overview = await sovereign.getProtocolOverview();
console.log('SOVEREIGN Protocol Overview:', overview);