Skip to content

Commit

Permalink
fix: remove unused account and moved types
Browse files Browse the repository at this point in the history
  • Loading branch information
wellitongervickas committed Nov 1, 2023
1 parent b15ed3e commit 0ecf742
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 35 deletions.
20 changes: 10 additions & 10 deletions contracts/Hub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,18 @@ contract Hub is IHub {
registryAddress = registryAddress_;
}

modifier isAdapter(bytes32 adapterId_) {
modifier checkRegistryAdapter(bytes32 adapterId_) {
if (!registryAddress.isAdapter(adapterId_)) {
revert IHub.Hub_AdapterNotFound(adapterId_);
}
_;
}

function createApp(bytes32 adapterId_, address appAddress_) external isAdapter(adapterId_) returns (bytes32) {
Adapter memory adapter = registryAddress.getAdapter(adapterId_);

App memory app = App({
adapter: adapter,
appAddress: appAddress_,
owner: msg.sender,
createdAt: block.timestamp
});
function createApp(
bytes32 adapterId_,
address appAddress_
) external checkRegistryAdapter(adapterId_) returns (bytes32) {
App memory app = App({adapter: _getRegistryAdapter(adapterId_), appAddress: appAddress_});

bytes32 appId = keccak256(abi.encodePacked(appAddress_, msg.sender));

Expand All @@ -41,6 +37,10 @@ contract Hub is IHub {
return appId;
}

function _getRegistryAdapter(bytes32 adapterId_) internal view returns (Adapter memory) {
return registryAddress.getAdapter(adapterId_);
}

function getApp(bytes32 appId_) external view returns (App memory) {
return _apps[appId_];
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/Registry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ contract Registry is IRegistry, Roles {
mapping(bytes32 => Adapter) private _adapters;

function createAdapter(bytes32 adapterType_, address adapterAddress_) external OnlyManager returns (bytes32) {
Adapter memory adapter = Adapter({adapterType: adapterType_, adapterAddress: adapterAddress_, enabled: false});
Adapter memory adapter = Adapter({adapterType: adapterType_, adapterAddress: adapterAddress_});

bytes32 adapterId = keccak256(abi.encodePacked(adapterType_, adapterAddress_));

Expand Down
1 change: 0 additions & 1 deletion contracts/interfaces/IAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ pragma solidity 0.8.21;
struct Adapter {
bytes32 adapterType;
address adapterAddress;
bool enabled;
}
2 changes: 0 additions & 2 deletions contracts/interfaces/IApp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ pragma solidity 0.8.21;
import {Adapter} from "./IAdapter.sol";

struct App {
address owner;
uint256 createdAt;
address appAddress;
Adapter adapter;
}
12 changes: 2 additions & 10 deletions test/hub/Hub.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
time,
loadFixture
} from '@nomicfoundation/hardhat-toolbox/network-helpers'
import { loadFixture } from '@nomicfoundation/hardhat-toolbox/network-helpers'

import { expect } from 'chai'
import { ethers } from 'hardhat'
Expand All @@ -16,7 +13,7 @@ describe('Hub', function () {
deployRegistryFixture
)

const { owner, hub } = await loadFixture(
const { hub } = await loadFixture(
deployHubFixture.bind(this, registryAddress)
)

Expand All @@ -38,16 +35,11 @@ describe('Hub', function () {
const logs2 = await hub.queryFilter(filter2, receipt2?.blockHash)
const [appId] = logs2[0].args
const app = await hub.getApp(appId)
const createdAt = await time.latest()

expect({
owner: app.owner,
createdAt: app.createdAt,
appAddress: app.appAddress,
adapter: app.adapter
}).to.deep.equal({
owner: owner.address,
createdAt,
appAddress,
adapter
})
Expand Down
2 changes: 1 addition & 1 deletion test/hub/fixture.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { address } from './../utils/types'
import { address } from './../../types/account'
import { ethers } from 'hardhat'

export async function deployHubFixture(address: address) {
Expand Down
12 changes: 3 additions & 9 deletions test/registry/Registry.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
time,
loadFixture
} from '@nomicfoundation/hardhat-toolbox/network-helpers'
import { loadFixture } from '@nomicfoundation/hardhat-toolbox/network-helpers'

import { expect } from 'chai'
import { ethers } from 'hardhat'
Expand All @@ -17,7 +14,6 @@ describe('Registry', function () {

const tx = await registry.createAdapter(adapterType, adapterAddress)
const receipt = await tx.wait()

const filter = registry.filters.Registry_AdapterCreated
const logs = await registry.queryFilter(filter, receipt?.blockHash)
const [adapterId] = logs[0].args
Expand All @@ -26,12 +22,10 @@ describe('Registry', function () {

expect({
adapterType: adapter.adapterType,
adapterAddress: adapter.adapterAddress,
enabled: adapter.enabled
adapterAddress: adapter.adapterAddress
}).to.deep.equal({
adapterType,
adapterAddress,
enabled: false
adapterAddress
})
})

Expand Down
2 changes: 1 addition & 1 deletion test/registry/fixture.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from 'hardhat'
import { address } from '../utils/types'
import { address } from './../../types/account'

export const VAULT_V1 = ethers.keccak256(ethers.toUtf8Bytes('VAULT.V1'))

Expand Down
File renamed without changes.

0 comments on commit 0ecf742

Please sign in to comment.