Skip to content

Commit

Permalink
Merge pull request #817 from etherisc/feature/events-refactoring
Browse files Browse the repository at this point in the history
refactor events to improve parameter order and indexing (#787)
  • Loading branch information
doerfli authored Dec 17, 2024
2 parents 303db9f + 09cd353 commit 4a8758c
Show file tree
Hide file tree
Showing 55 changed files with 432 additions and 418 deletions.
4 changes: 2 additions & 2 deletions contracts/accounting/IAccountingService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ interface IAccountingService is
{
event LogAccountingServiceBalanceChanged(
NftId indexed nftId,
Amount indexed amount,
Amount indexed feeAmount,
Amount amount,
Amount feeAmount,
bool increase,
ObjectType objectType
);
Expand Down
18 changes: 10 additions & 8 deletions contracts/authorization/AccessAdmin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ contract AccessAdmin is
// add role to list of roles
_roleIds.push(roleId);

emit LogAccessAdminRoleCreated(_adminName, roleId, info.targetType, info.adminRoleId, info.name.toString());
emit LogAccessAdminRoleCreated(roleId, info.adminRoleId, info.targetType, info.name.toString(), _adminName);
}


Expand All @@ -387,7 +387,7 @@ contract AccessAdmin is
Blocknumber lastUpdateIn = _roleInfo[roleId].lastUpdateIn;
_roleInfo[roleId].lastUpdateIn = BlocknumberLib.current();

emit LogAccessAdminRoleActivatedSet(_adminName, roleId, active, lastUpdateIn);
emit LogAccessAdminRoleActivatedSet(roleId, active, _adminName, lastUpdateIn);
}


Expand Down Expand Up @@ -418,9 +418,9 @@ contract AccessAdmin is
0);

emit LogAccessAdminRoleGranted(
_adminName,
account,
AccessAdminLib.getRoleName(this, roleId));
AccessAdminLib.getRoleName(this, roleId),
_adminName);
}


Expand All @@ -441,7 +441,7 @@ contract AccessAdmin is
RoleId.unwrap(roleId),
account);

emit LogAccessAdminRoleRevoked(_adminName, account, _roleInfo[roleId].name.toString());
emit LogAccessAdminRoleRevoked(account, _roleInfo[roleId].name.toString(), _adminName);
}


Expand Down Expand Up @@ -557,7 +557,7 @@ contract AccessAdmin is
// grant contract role to target
_grantRoleToAccount(targetRoleId, target);

emit LogAccessAdminTargetCreated(_adminName, targetName, managed, target, targetRoleId);
emit LogAccessAdminTargetCreated(target, targetRoleId, managed, targetName, _adminName);
}


Expand All @@ -571,7 +571,7 @@ contract AccessAdmin is
Blocknumber lastUpdateIn = _targetInfo[target].lastUpdateIn;
_targetInfo[target].lastUpdateIn = BlocknumberLib.current();

emit LogAccessAdminTargetLockedSet(_adminName, target, locked, lastUpdateIn);
emit LogAccessAdminTargetLockedSet(target, locked, _adminName, lastUpdateIn);
}


Expand Down Expand Up @@ -652,9 +652,11 @@ contract AccessAdmin is

// logging
emit LogAccessAdminFunctionGranted(
_adminName,
target,
selector,
roleId,
AccessAdminLib.toFunctionGrantingString(this, func.name, roleId),
_adminName,
lastUpdateIn);
}
}
17 changes: 9 additions & 8 deletions contracts/authorization/IAccessAdmin.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {Blocknumber} from "../type/Blocknumber.sol";
import {NftId} from "../type/NftId.sol";
import {ObjectType} from "../type/ObjectType.sol";
import {RoleId} from "../type/RoleId.sol";
import {Selector} from "../type/Selector.sol";
import {Str} from "../type/String.sol";
import {VersionPart} from "../type/Version.sol";

Expand All @@ -24,14 +25,14 @@ interface IAccessAdmin is
{

// roles, targets and functions
event LogAccessAdminRoleCreated(string admin, RoleId roleId, TargetType targetType, RoleId roleAdminId, string name);
event LogAccessAdminTargetCreated(string admin, string name, bool managed, address target, RoleId roleId);

event LogAccessAdminRoleActivatedSet(string admin, RoleId roleId, bool active, Blocknumber lastUpdateIn);
event LogAccessAdminRoleGranted(string admin, address account, string roleName);
event LogAccessAdminRoleRevoked(string admin, address account, string roleName);
event LogAccessAdminTargetLockedSet(string admin, address target, bool locked, Blocknumber lastUpdateIn);
event LogAccessAdminFunctionGranted(string admin, address target, string func, Blocknumber lastUpdateIn);
event LogAccessAdminRoleCreated(RoleId indexed roleId, RoleId indexed roleAdminId, TargetType indexed targetType, string name, string admin);
event LogAccessAdminTargetCreated(address indexed target, RoleId indexed roleId, bool indexed managed, string name, string admin);

event LogAccessAdminRoleActivatedSet(RoleId indexed roleId, bool indexed active, string admin, Blocknumber indexed lastUpdateIn);
event LogAccessAdminRoleGranted(address indexed account, string roleName, string admin);
event LogAccessAdminRoleRevoked(address indexed account, string roleName, string admin);
event LogAccessAdminTargetLockedSet(address indexed target, bool indexed locked, string admin, Blocknumber indexed lastUpdateIn);
event LogAccessAdminFunctionGranted(address indexed target, Selector indexed selector, RoleId indexed roleId, string func, string admin, Blocknumber lastUpdateIn);

// only deployer modifier
error ErrorAccessAdminNotDeployer();
Expand Down
41 changes: 22 additions & 19 deletions contracts/distribution/DistributionService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,21 +98,24 @@ contract DistributionService is
}

distributorType = DistributorTypeLib.toDistributorType(distributionNftId, name);
IDistribution.DistributorTypeInfo memory info = IDistribution.DistributorTypeInfo({
name: name,
distributionNftId: distributionNftId,
minDiscountPercentage: minDiscountPercentage,
maxDiscountPercentage: maxDiscountPercentage,
commissionPercentage: commissionPercentage,
maxReferralCount: maxReferralCount,
maxReferralLifetime: maxReferralLifetime,
allowSelfReferrals: allowSelfReferrals,
allowRenewals: allowRenewals,
data: data});

instance.getInstanceStore().createDistributorType(distributorType, info);

{
IDistribution.DistributorTypeInfo memory info = IDistribution.DistributorTypeInfo({
name: name,
distributionNftId: distributionNftId,
minDiscountPercentage: minDiscountPercentage,
maxDiscountPercentage: maxDiscountPercentage,
commissionPercentage: commissionPercentage,
maxReferralCount: maxReferralCount,
maxReferralLifetime: maxReferralLifetime,
allowSelfReferrals: allowSelfReferrals,
allowRenewals: allowRenewals,
data: data});

instance.getInstanceStore().createDistributorType(distributorType, info);
}

emit LogDistributionServiceDistributorTypeCreated(distributionNftId, name, commissionPercentage);
emit LogDistributionServiceDistributorTypeCreated(distributionNftId, distributorType, name, commissionPercentage);
}


Expand Down Expand Up @@ -148,7 +151,7 @@ contract DistributionService is

instance.getInstanceStore().createDistributor(distributorNftId, info);

emit LogDistributionServiceDistributorCreated(distributionNftId, distributorNftId, distributorType, distributor);
emit LogDistributionServiceDistributorCreated(distributionNftId, distributorNftId, distributor, distributorType);
}

function changeDistributorType(
Expand Down Expand Up @@ -236,7 +239,7 @@ contract DistributionService is

instance.getInstanceStore().createReferral(referralId, info);

emit LogDistributionServiceReferralCreated(distributionNftId, distributorNftId, referralId, code, discountPercentage, maxReferrals, expiryAt);
emit LogDistributionServiceReferralCreated(distributorNftId, referralId, code, discountPercentage, maxReferrals, expiryAt);
}
}

Expand All @@ -258,7 +261,7 @@ contract DistributionService is
referralInfo.usedReferrals += 1;
instance.getInstanceStore().updateReferral(referralId, referralInfo, KEEP_STATE());

emit LogDistributionServiceReferralProcessed(distributionNftId, referralInfo.distributorNftId, referralId, referralInfo.usedReferrals);
emit LogDistributionServiceReferralProcessed(referralInfo.distributorNftId, referralId, referralInfo.usedReferrals);
}
}

Expand Down Expand Up @@ -299,7 +302,7 @@ contract DistributionService is
} else {
// increase distribution balance by distribution owner fee
_accountingService.increaseDistributionBalance(store, distributionNftId, AmountLib.zero(), distributionOwnerFee);
emit LogDistributionServiceSaleProcessed(distributionNftId, referralId, premium.premiumAmount, distributionOwnerFee);
emit LogDistributionServiceSaleProcessed(distributionNftId, premium.premiumAmount, distributionOwnerFee);
}


Expand Down Expand Up @@ -343,7 +346,7 @@ contract DistributionService is
// transfer amount to distributor
{
address distributor = getRegistry().ownerOf(distributorNftId);
emit LogDistributionServiceCommissionWithdrawn(distributorNftId, distributor, address(distributionInfo.tokenHandler.TOKEN()), withdrawnAmount);
emit LogDistributionServiceCommissionWithdrawn(distributorNftId, distributor, withdrawnAmount, address(distributionInfo.tokenHandler.TOKEN()));
distributionInfo.tokenHandler.pushToken(distributor, withdrawnAmount);
}
}
Expand Down
16 changes: 8 additions & 8 deletions contracts/distribution/IDistributionService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ interface IDistributionService is IService {
error ErrorDistributionServiceInvalidFeeTransferred(Amount transferredDistributionFeeAmount, Amount expectedDistributionFeeAmount);
error ErrorDistributionServiceReferralDistributionMismatch(ReferralId referralId, NftId referralDistributionNft, NftId distributionNftId);

event LogDistributionServiceCommissionWithdrawn(NftId distributorNftId, address recipient, address tokenAddress, Amount amount);
event LogDistributionServiceDistributorTypeCreated(NftId distributionNftId, string name, UFixed commissionPercentage);
event LogDistributionServiceDistributorCreated(NftId distributionNftId, NftId distributorNftId, DistributorType distributorType, address distributor);
event LogDistributionServiceDistributorTypeChanged(NftId distributorNftId, DistributorType oldDistributorType, DistributorType newDistributorType);
event LogDistributionServiceReferralCreated(NftId distributionNftId, NftId distributorNftId, ReferralId referralId, string code, UFixed discountPercentage, uint32 maxReferrals, Timestamp expiryAt);
event LogDistributionServiceReferralProcessed(NftId distributionNftId, NftId distributorNftId, ReferralId referralId, uint32 usedReferrals);
event LogDistributionServiceSaleProcessed(NftId distributionNftId, ReferralId referralId, Amount premium, Amount distributionOwnerFee);
event LogDistributionServiceSaleProcessedWithReferral(NftId distributionNftId, NftId distributorNftId, ReferralId referralId, uint32 numPoliciesSold, Amount premium, Amount distributionOwnerFee, Amount commissionAmount);
event LogDistributionServiceCommissionWithdrawn(NftId indexed distributorNftId, address indexed recipient, Amount amount, address indexed tokenAddress);
event LogDistributionServiceDistributorTypeCreated(NftId indexed distributionNftId, DistributorType indexed distributorType, string name, UFixed commissionPercentage);
event LogDistributionServiceDistributorCreated(NftId indexed distributionNftId, NftId indexed distributorNftId, address indexed distributor, DistributorType distributorType);
event LogDistributionServiceDistributorTypeChanged(NftId indexed distributorNftId, DistributorType indexed oldDistributorType, DistributorType indexed newDistributorType);
event LogDistributionServiceReferralCreated(NftId indexed distributorNftId, ReferralId indexed referralId, string code, UFixed discountPercentage, uint32 maxReferrals, Timestamp expiryAt);
event LogDistributionServiceReferralProcessed(NftId indexed distributorNftId, ReferralId indexed referralId, uint32 usedReferrals);
event LogDistributionServiceSaleProcessed(NftId indexed distributionNftId, Amount premium, Amount distributionOwnerFee);
event LogDistributionServiceSaleProcessedWithReferral(NftId indexed distributionNftId, NftId indexed distributorNftId, ReferralId indexed referralId, uint32 numPoliciesSold, Amount premium, Amount distributionOwnerFee, Amount commissionAmount);

function createDistributorType(
string memory name,
Expand Down
15 changes: 7 additions & 8 deletions contracts/instance/BundleSet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ contract BundleSet is
{
using LibNftIdSet for LibNftIdSet.Set;

event LogBundleSetPolicyLinked(NftId bundleNftId, NftId policyNftId);
event LogBundleSetPolicyUnlinked(NftId bundleNftId, NftId policyNftId);
event LogBundleSetPolicyLinked(NftId indexed bundleNftId, NftId indexed policyNftId);
event LogBundleSetPolicyUnlinked(NftId indexed bundleNftId, NftId indexed policyNftId);

event LogBundleSetBundleAdded(NftId poolNftId, NftId bundleNftId);
event LogBundleSetBundleUnlocked(NftId poolNftId, NftId bundleNftId);
event LogBundleSetBundleLocked(NftId poolNftId, NftId bundleNftId);
event LogBundleSetBundleClosed(NftId poolNftId, NftId bundleNftId);
event LogBundleSetBundleAdded(NftId indexed poolNftId, NftId indexed bundleNftId);
event LogBundleSetBundleLocked(NftId indexed poolNftId, NftId indexed bundleNftId, bool locked);
event LogBundleSetBundleClosed(NftId indexed poolNftId, NftId indexed bundleNftId);

error ErrorBundleSetPolicyAlreadyActivated(NftId policyNftId);
error ErrorBundleSetBundleLocked(NftId bundleNftId, NftId policyNftId);
Expand Down Expand Up @@ -76,14 +75,14 @@ contract BundleSet is
function unlock(NftId bundleNftId) external restricted() {
NftId poolNftId = ObjectSetHelperLib.getPoolNftId(_instanceAddress, bundleNftId);
_activate(poolNftId, _toBundleKey32(bundleNftId));
emit LogBundleSetBundleUnlocked(poolNftId, bundleNftId);
emit LogBundleSetBundleLocked(poolNftId, bundleNftId, false);
}

/// @dev locked (deactivated) bundles may not collateralize any new policies
function lock(NftId bundleNftId) external restricted() {
NftId poolNftId = ObjectSetHelperLib.getPoolNftId(_instanceAddress, bundleNftId);
_deactivate(poolNftId, _toBundleKey32(bundleNftId));
emit LogBundleSetBundleLocked(poolNftId, bundleNftId);
emit LogBundleSetBundleLocked(poolNftId, bundleNftId, true);
}


Expand Down
14 changes: 7 additions & 7 deletions contracts/instance/IInstance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ interface IInstance is
IRegisterable
{
// role handling
event LogInstanceCustomRoleCreated(RoleId roleId, string roleName, RoleId adminRoleId, uint32 maxMemberCount);
event LogInstanceCustomRoleActiveSet(RoleId roleId, bool active, address caller);
event LogInstanceCustomRoleGranted(RoleId roleId, address account, address caller);
event LogInstanceCustomRoleRevoked(RoleId roleId, address account, address caller);
event LogInstanceCustomRoleCreated(RoleId indexed roleId, string indexed roleName, RoleId indexed adminRoleId, uint32 maxMemberCount);
event LogInstanceCustomRoleActiveSet(RoleId indexed roleId, bool indexed active, address indexed caller);
event LogInstanceCustomRoleGranted(RoleId indexed roleId, address indexed account, address indexed caller);
event LogInstanceCustomRoleRevoked(RoleId indexed roleId, address indexed account, address indexed caller);

// target handling
event LogInstanceCustomTargetCreated(address target, RoleId targetRoleId, string name);
event LogInstanceTargetLocked(address target, bool locked);
event LogInstanceCustomTargetFunctionRoleSet(address target, bytes4[] selectors, RoleId roleId);
event LogInstanceCustomTargetCreated(address indexed target, RoleId indexed targetRoleId, string indexed name);
event LogInstanceTargetLocked(address indexed target, bool indexed locked);
event LogInstanceCustomTargetFunctionRoleSet(address indexed target, bytes4[] selectors, RoleId indexed roleId);

// modifier is onlyRoleAdmin
error ErrorInstanceNotCustomRole(RoleId roleId);
Expand Down
11 changes: 6 additions & 5 deletions contracts/instance/IInstanceService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ interface IInstanceService is IService {
error ErrorInstanceServiceInstanceComponentMismatch(NftId instanceNftId, NftId componentNftId);
error ErrorInstanceServiceInvalidComponentType(address componentAddress, ObjectType expectedType, ObjectType componentType);

event LogInstanceServiceInstanceLocked(NftId instanceNftId, bool locked);
event LogInstanceServiceInstanceCreated(NftId instanceNftId, address instance);
event LogInstanceServiceMasterInstanceRegistered(NftId masterInstanceNftId, address masterInstance, address masterInstanceAdmin, address masterAccessManager,

event LogInstanceServiceInstanceLocked(NftId indexed instanceNftId, bool indexed locked);
event LogInstanceServiceInstanceCreated(NftId indexed instanceNftId, address indexed instance);
event LogInstanceServiceMasterInstanceRegistered(NftId indexed masterInstanceNftId, address indexed masterInstance, address indexed masterInstanceAdmin, address masterAccessManager,
address masterInstanceReader, address masterInstanceBundleSet, address masterInstanceRiskSet, address masterInstanceRequestSet, address masterInstanceStore, address masterProductStore);
event LogInstanceServiceMasterInstanceReaderUpgraded(NftId instanceNfId, address newInstanceReader);
event LogInstanceServiceInstanceReaderUpgraded(NftId instanceNfId, address newInstanceReader);
event LogInstanceServiceMasterInstanceReaderUpgraded(NftId indexed instanceNfId, address indexed oldInstanceReader, address indexed newInstanceReader);
event LogInstanceServiceInstanceReaderUpgraded(NftId indexed instanceNfId, address indexed oldInstanceReader, address indexed 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
4 changes: 4 additions & 0 deletions contracts/instance/InstanceService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,13 @@ contract InstanceService is
InstanceReader upgradedInstanceReaderClone = InstanceReader(
Clones.clone(address(_masterInstanceReader)));

address oldInstanceReaderAddress = address(instance.getInstanceReader());
upgradedInstanceReaderClone.initializeWithInstance(instanceAddress);
instance.setInstanceReader(upgradedInstanceReaderClone);

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

Expand Down Expand Up @@ -415,10 +417,12 @@ contract InstanceService is
InstanceReader instanceReader = InstanceReader(instanceReaderAddress);
if(instanceReader.getInstance() != IInstance(_masterInstance)) { revert ErrorInstanceServiceInstanceReaderInstanceMismatch(); }

address oldMasterInstanceReaderAddress = _masterInstanceReader;
_masterInstanceReader = instanceReaderAddress;

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

Expand Down
Loading

0 comments on commit 4a8758c

Please sign in to comment.