diff --git a/contracts/topos-core/SubnetRegistrator.sol b/contracts/topos-core/SubnetRegistrator.sol index 20874e6..7034cf7 100644 --- a/contracts/topos-core/SubnetRegistrator.sol +++ b/contracts/topos-core/SubnetRegistrator.sol @@ -11,11 +11,12 @@ contract SubnetRegistrator is Initializable, Ownable { using Bytes32SetsLib for Bytes32SetsLib.Set; struct Subnet { - string endpoint; + uint256 chainId; + string currencySymbol; + string endpointHttp; + string endpointWs; string logoURL; string name; - string currencySymbol; - uint256 chainId; } /// @notice Set of subnet IDs @@ -56,27 +57,30 @@ contract SubnetRegistrator is Initializable, Ownable { } /// @notice Register a new subnet - /// @param endpoint JSON RPC endpoint of a subnet + /// @param chainId subnet network ID + /// @param currencySymbol currencySymbol for a subnet currency + /// @param endpointHttp JSON RPC http endpoint of a subnet + /// @param endpointWs JSON RPC ws endpoint of a subnet /// @param logoURL URL for the logo of a subnet /// @param name name of a subnet /// @param subnetId FROST public key of a subnet - /// @param currencySymbol currencySymbol for a subnet currency - /// @param chainId subnet network ID function registerSubnet( - string calldata endpoint, + uint256 chainId, + string calldata currencySymbol, + string calldata endpointHttp, + string calldata endpointWs, string calldata logoURL, string calldata name, - SubnetId subnetId, - string calldata currencySymbol, - uint256 chainId + SubnetId subnetId ) public onlyOwner { subnetSet.insert(SubnetId.unwrap(subnetId)); Subnet storage subnet = subnets[subnetId]; - subnet.endpoint = endpoint; + subnet.chainId = chainId; + subnet.currencySymbol = currencySymbol; + subnet.endpointHttp = endpointHttp; + subnet.endpointWs = endpointWs; subnet.logoURL = logoURL; subnet.name = name; - subnet.currencySymbol = currencySymbol; - subnet.chainId = chainId; emit NewSubnetRegistered(subnetId); } diff --git a/package.json b/package.json index c639db8..33610f8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@topos-protocol/topos-smart-contracts", - "version": "1.2.3", + "version": "2.0.0", "description": "Topos Smart Contracts", "repository": { "type": "git", diff --git a/scripts/register-subnet.ts b/scripts/register-subnet.ts index 429fbe8..c512054 100644 --- a/scripts/register-subnet.ts +++ b/scripts/register-subnet.ts @@ -8,7 +8,8 @@ const main = async function (...args: string[]) { subnetRegistratorAddress, subnetName, subnetChainId, - subnetRPCEndpoint, + subnetEndpointHttp, + subnetEndpointWs, subnetCurrencySymbol, subnetLogoUrl, _adminPrivateKey, @@ -28,8 +29,13 @@ const main = async function (...args: string[]) { process.exit(1) } - if (!subnetRPCEndpoint) { - console.error('ERROR: Please provide the subnet endpoint private key!') + if (!subnetEndpointHttp) { + console.error('ERROR: Please provide the subnet HTTP endpoint!') + process.exit(1) + } + + if (!subnetEndpointWs) { + console.error('ERROR: Please provide the subnet WS endpoint!') process.exit(1) } @@ -102,12 +108,13 @@ const main = async function (...args: string[]) { } const tx: ContractTransaction = await contract.registerSubnet( - subnetRPCEndpoint, + subnetChainId, + subnetCurrencySymbol, + subnetEndpointHttp, + subnetEndpointWs, subnetLogoUrl, subnetName, subnetId, - subnetCurrencySymbol, - subnetChainId, { gasLimit: 4_000_000 } ) diff --git a/test/topos-core/SubnetRegistrator.test.ts b/test/topos-core/SubnetRegistrator.test.ts index 486b69b..cf49f5e 100644 --- a/test/topos-core/SubnetRegistrator.test.ts +++ b/test/topos-core/SubnetRegistrator.test.ts @@ -5,12 +5,13 @@ import { expect } from 'chai' describe('SubnetRegistrator', () => { let subnetRegistrator: Contract - const endpoint = 'http://127.0.0.1' + const chainId = 1 + const currencySymbol = 'SUB' + const endpointHttp = 'http://127.0.0.1' + const endpointWs = 'ws://127.0.0.1' const logoURL = 'http://image-url.com' - const subnetName = 'Test Subnet' + const name = 'Test Subnet' const subnetId = ethers.utils.formatBytes32String('subnetId') - const subnetCurrencySymbol = 'SUB' - const chainId = 1 async function deploySubnetRegistratorFixture() { const [admin, nonAdmin, toposDeployer] = await ethers.getSigners() @@ -36,12 +37,13 @@ describe('SubnetRegistrator', () => { subnetRegistrator .connect(nonAdmin) .registerSubnet( - endpoint, + chainId, + currencySymbol, + endpointHttp, + endpointWs, logoURL, - subnetName, - subnetId, - subnetCurrencySymbol, - chainId + name, + subnetId ) ).to.be.revertedWith('Ownable: caller is not the owner') }) @@ -50,25 +52,27 @@ describe('SubnetRegistrator', () => { const { admin, subnetRegistrator } = await deploySubnetRegistratorFixture() await registerSubnet( - endpoint, + admin, + chainId, + currencySymbol, + endpointHttp, + endpointWs, logoURL, - subnetName, + name, subnetId, - subnetCurrencySymbol, - chainId, - subnetRegistrator, - admin + subnetRegistrator ) await expect( registerSubnet( - endpoint, + admin, + chainId, + currencySymbol, + endpointHttp, + endpointWs, logoURL, - subnetName, + name, subnetId, - subnetCurrencySymbol, - chainId, - subnetRegistrator, - admin + subnetRegistrator ) ).to.be.revertedWith('Bytes32Set: key already exists in the set.') }) @@ -77,19 +81,21 @@ describe('SubnetRegistrator', () => { const { admin, subnetRegistrator } = await deploySubnetRegistratorFixture() await registerSubnet( - endpoint, + admin, + chainId, + currencySymbol, + endpointHttp, + endpointWs, logoURL, - subnetName, + name, subnetId, - subnetCurrencySymbol, - chainId, - subnetRegistrator, - admin + subnetRegistrator ) const subnet = await subnetRegistrator.subnets(subnetId) - expect(subnet.name).to.equal(subnetName) - expect(subnet.currencySymbol).to.equal(subnetCurrencySymbol) - expect(subnet.endpoint).to.equal(endpoint) + expect(subnet.name).to.equal(name) + expect(subnet.currencySymbol).to.equal(currencySymbol) + expect(subnet.endpointHttp).to.equal(endpointHttp) + expect(subnet.endpointWs).to.equal(endpointWs) expect(subnet.logoURL).to.equal(logoURL) expect(subnet.chainId).to.equal(chainId) }) @@ -98,14 +104,15 @@ describe('SubnetRegistrator', () => { const { admin, subnetRegistrator } = await deploySubnetRegistratorFixture() await registerSubnet( - endpoint, + admin, + chainId, + currencySymbol, + endpointHttp, + endpointWs, logoURL, - subnetName, + name, subnetId, - subnetCurrencySymbol, - chainId, - subnetRegistrator, - admin + subnetRegistrator ) const count = await subnetRegistrator.getSubnetCount() expect(count).to.equal(1) @@ -115,14 +122,15 @@ describe('SubnetRegistrator', () => { const { admin, subnetRegistrator } = await deploySubnetRegistratorFixture() await registerSubnet( - endpoint, + admin, + chainId, + currencySymbol, + endpointHttp, + endpointWs, logoURL, - subnetName, + name, subnetId, - subnetCurrencySymbol, - chainId, - subnetRegistrator, - admin + subnetRegistrator ) const id = await subnetRegistrator.getSubnetIdAtIndex(0) expect(id).to.equal(subnetId) @@ -132,14 +140,15 @@ describe('SubnetRegistrator', () => { const { admin, subnetRegistrator } = await deploySubnetRegistratorFixture() await registerSubnet( - endpoint, + admin, + chainId, + currencySymbol, + endpointHttp, + endpointWs, logoURL, - subnetName, + name, subnetId, - subnetCurrencySymbol, - chainId, - subnetRegistrator, - admin + subnetRegistrator ) const exists = await subnetRegistrator.subnetExists(subnetId) expect(exists).to.be.true @@ -150,14 +159,15 @@ describe('SubnetRegistrator', () => { await deploySubnetRegistratorFixture() await expect( registerSubnet( - endpoint, + admin, + chainId, + currencySymbol, + endpointHttp, + endpointWs, logoURL, - subnetName, + name, subnetId, - subnetCurrencySymbol, - chainId, - subnetRegistrator, - admin + subnetRegistrator ) ) .to.emit(subnetRegistrator, 'NewSubnetRegistered') @@ -185,14 +195,15 @@ describe('SubnetRegistrator', () => { const { admin, subnetRegistrator } = await deploySubnetRegistratorFixture() await registerSubnet( - endpoint, + admin, + chainId, + currencySymbol, + endpointHttp, + endpointWs, logoURL, - subnetName, + name, subnetId, - subnetCurrencySymbol, - chainId, - subnetRegistrator, - admin + subnetRegistrator ) await expect(removeSubnet(subnetId, subnetRegistrator, admin)) .to.emit(subnetRegistrator, 'SubnetRemoved') @@ -201,24 +212,26 @@ describe('SubnetRegistrator', () => { }) async function registerSubnet( - endpoint: string, + admin: Wallet, + chainId: number, + currencySymbol: string, + endpointHttp: string, + endpointWs: string, logoURL: string, - subnetName: string, + name: string, subnetId: string, - subnetCurrencySymbol: string, - chainId: number, - subnetRegistrator: Contract, - admin: Wallet + subnetRegistrator: Contract ) { return await subnetRegistrator .connect(admin) .registerSubnet( - endpoint, + chainId, + currencySymbol, + endpointHttp, + endpointWs, logoURL, - subnetName, - subnetId, - subnetCurrencySymbol, - chainId + name, + subnetId ) }