Skip to content
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

emit events from InstanceService (#672) #689

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion contracts/instance/IInstanceService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ interface IInstanceService is IService {
error ErrorInstanceServiceInstanceComponentMismatch(NftId instanceNftId, NftId componentNftId);
error ErrorInstanceServiceInvalidComponentType(address componentAddress, ObjectType expectedType, ObjectType componentType);

event LogInstanceCloned(NftId instanceNftId, address instance);
event LogInstanceServiceInstanceLocked(NftId instanceNftId, bool locked);
event LogInstanceServiceInstanceCreated(NftId instanceNftId, address instance);
event LogInstanceServiceMasterInstanceReaderUpgraded(NftId instanceNfId, address newInstanceReader);
event LogInstanceServiceInstanceReaderUpgraded(NftId instanceNfId, address newInstanceReader);

/// @dev Creates a new custom role for the calling instance.
function createRole(string memory roleName, RoleId adminRoleId, uint32 maxMemberCount) external returns (RoleId roleId);
Expand Down
14 changes: 13 additions & 1 deletion contracts/instance/InstanceService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,10 @@ contract InstanceService is
{
address instanceAddress = msg.sender;
IInstance(instanceAddress).getInstanceAdmin().setInstanceLocked(locked);

emit LogInstanceServiceInstanceLocked(
getRegistry().getNftIdForAddress(instanceAddress),
locked);
}


Expand Down Expand Up @@ -213,7 +217,7 @@ contract InstanceService is
TargetManagerLib.getDefaultLockingPeriod(),
TargetManagerLib.getDefaultRewardRate());

emit LogInstanceCloned(
emit LogInstanceServiceInstanceCreated(
instanceNftId,
address(instance));
}
Expand Down Expand Up @@ -299,6 +303,10 @@ contract InstanceService is

upgradedInstanceReaderClone.initializeWithInstance(instanceAddress);
instance.setInstanceReader(upgradedInstanceReaderClone);

emit LogInstanceServiceInstanceReaderUpgraded(
getRegistry().getNftIdForAddress(instanceAddress),
address(upgradedInstanceReaderClone));
}


Expand Down Expand Up @@ -369,6 +377,10 @@ contract InstanceService is
if(instanceReader.getInstance() != IInstance(_masterInstance)) { revert ErrorInstanceServiceInstanceReaderInstanceMismatch(); }

_masterInstanceReader = instanceReaderAddress;

emit LogInstanceServiceMasterInstanceReaderUpgraded(
getRegistry().getNftIdForAddress(_masterInstance),
instanceReaderAddress);
}

function getMasterInstanceReader() external virtual view returns (address) {
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/example-fire.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The payout is 25% for small fires, 50% for medium fires and 100% for large fires
4. Switch to the `Deploy & Run Transactions` tab and connect to the network of choice (must have a GIF deployment).
5. Connect to the existing `InstanceService` contract.
6. Decide if you want to use a registered token or use an unregistered one (the latter allows for more flexibility during testing but will create an unsupported instance).
7. Call the `createInstance` function (set the `allowAnyToken` parameter according to above decision) and find the log `LogInstanceCloned` that shows the address of the new instance in field `instance` and the instance nft id in field `instanceNftId`.
7. Call the `createInstance` function (set the `allowAnyToken` parameter according to above decision) and find the log `LogInstanceServiceInstanceCreated` that shows the address of the new instance in field `instance` and the instance nft id in field `instanceNftId`.
8. Now compile the contracts `FireUSD.sol`, `FirePoolAuthorization`, `FirePool`, `FireProductAuthorization` and `FireProduct` in the directory `contracts/examples/fire`.
9. Deploy the FireUSD contract and save the address. You can also use any pre-existing ERC20 Token. If you deploy a new token and have not enabled the `allowAnyToken` flag on the instance, then please ensure that the new token is registered with the token registry as well.
10. Deploy the FirePoolAuthorization contract with an arbitrary unique name and save the address.
Expand Down
4 changes: 2 additions & 2 deletions scripts/deploy_fire_components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export async function deployFireComponentContracts(libraries: LibraryAddresses,
[IInstanceService__factory.createInterface()]
);

const instanceAddress = getFieldFromLogs(instanceCreateTx.logs, instanceService.interface, "LogInstanceCloned", "instance") as string;
const instanceNftId = getFieldFromLogs(instanceCreateTx.logs, instanceService.interface, "LogInstanceCloned", "instanceNftId") as string;
const instanceAddress = getFieldFromLogs(instanceCreateTx.logs, instanceService.interface, "LogInstanceServiceInstanceCreated", "instance") as string;
const instanceNftId = getFieldFromLogs(instanceCreateTx.logs, instanceService.interface, "LogInstanceServiceInstanceCreated", "instanceNftId") as string;
logger.debug(`Instance created at ${instanceAddress} with NFT ID ${instanceNftId}`);
const instance = IInstance__factory.connect(instanceAddress, fireOwner);

Expand Down
4 changes: 2 additions & 2 deletions scripts/libs/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ export async function cloneInstance(masterInstance: InstanceAddresses, libraries
[InstanceService__factory.createInterface()]
);

const clonedInstanceAddress = getFieldFromLogs(cloneTx.logs, instanceServiceAsClonedInstanceOwner.interface, "LogInstanceCloned", "instance");
const clonedInstanceNftId = getFieldFromLogs(cloneTx.logs, instanceServiceAsClonedInstanceOwner.interface, "LogInstanceCloned", "instanceNftId");
const clonedInstanceAddress = getFieldFromLogs(cloneTx.logs, instanceServiceAsClonedInstanceOwner.interface, "LogInstanceServiceInstanceCreated", "instance");
const clonedInstanceNftId = getFieldFromLogs(cloneTx.logs, instanceServiceAsClonedInstanceOwner.interface, "LogInstanceServiceInstanceCreated", "instanceNftId");
const clonedInstance = IInstance__factory.connect(clonedInstanceAddress as string, instanceOwner);
const clonedInstanceAdminAddress = await clonedInstance.getInstanceAdmin();
const clonedInstanceStoreAddress = await clonedInstance.getInstanceStore();
Expand Down
4 changes: 2 additions & 2 deletions scripts/new_instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export async function cloneInstanceFromRegistry(registryAddress: AddressLike, in
const cloneTx = await executeTx(
async () => await instanceServiceAsClonedInstanceOwner.createInstance(getTxOpts())
);
const clonedInstanceAddress = getFieldFromLogs(cloneTx.logs, instanceServiceAsClonedInstanceOwner.interface, "LogInstanceCloned", "instance");
const clonedInstanceNftId = getFieldFromLogs(cloneTx.logs, instanceServiceAsClonedInstanceOwner.interface, "LogInstanceCloned", "instanceNftId");
const clonedInstanceAddress = getFieldFromLogs(cloneTx.logs, instanceServiceAsClonedInstanceOwner.interface, "LogInstanceServiceInstanceCreated", "instance");
const clonedInstanceNftId = getFieldFromLogs(cloneTx.logs, instanceServiceAsClonedInstanceOwner.interface, "LogInstanceServiceInstanceCreated", "instanceNftId");

logger.info(`instanceNftId: ${clonedInstanceNftId} instanceAddress: ${clonedInstanceAddress}`);

Expand Down
8 changes: 8 additions & 0 deletions test/instance/InstanceReader.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ contract InstanceReaderTest is GifTest {
// GIVEN
vm.startPrank(registryOwner);
InstanceReader newMasterInstanceReader = _createNewMasterInstanceReader();
// address newMasterInstanceReaderAddress = address(newMasterInstanceReader);

vm.expectEmit();
emit IInstanceService.LogInstanceServiceMasterInstanceReaderUpgraded(masterInstanceNftId, address(newMasterInstanceReader));

// WHEN
instanceService.upgradeMasterInstanceReader(address(newMasterInstanceReader));

Expand Down Expand Up @@ -72,6 +76,10 @@ contract InstanceReaderTest is GifTest {

// WHEN
vm.startPrank(instanceOwner);

vm.expectEmit(true, false, false, false);
emit IInstanceService.LogInstanceServiceInstanceReaderUpgraded(instanceNftId, address(newMasterInstanceReader));

instance.upgradeInstanceReader();
vm.stopPrank();

Expand Down
Loading