Skip to content

Commit

Permalink
feat: UsernameSimpleCharsetNamespaceRule made default for Namespaces …
Browse files Browse the repository at this point in the history
…deployed with LensFactory
  • Loading branch information
vicnaum committed Jan 20, 2025
1 parent 2b3b8e2 commit 5a76ef2
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 14 deletions.
34 changes: 30 additions & 4 deletions contracts/extensions/factories/LensFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ import {IAccount, AccountManagerPermissions} from "contracts/extensions/account/
import {INamespace} from "contracts/core/interfaces/INamespace.sol";
import {ITokenURIProvider} from "contracts/core/interfaces/ITokenURIProvider.sol";
import {LensUsernameTokenURIProvider} from "contracts/core/primitives/namespace/LensUsernameTokenURIProvider.sol";

import {IFeedRule} from "contracts/core/interfaces/IFeedRule.sol";
import {IGraphRule} from "contracts/core/interfaces/IGraphRule.sol";
import {INamespaceRule} from "contracts/core/interfaces/INamespaceRule.sol";

import {PARAM__GROUP} from "contracts/rules/feed/GroupGatedFeedRule.sol";
import {AccessControlled} from "contracts/core/access/AccessControlled.sol";
import {IGroup} from "contracts/core/interfaces/IGroup.sol";
Expand Down Expand Up @@ -82,6 +85,7 @@ contract LensFactory {
IAccessControl internal immutable TEMPORARY_ACCESS_CONTROL;
address internal immutable ACCOUNT_BLOCKING_RULE;
address internal immutable GROUP_GATED_FEED_RULE;
address internal immutable USERNAME_SIMPLE_CHARSET_RULE;

constructor(
AccessControlFactory accessControlFactory,
Expand All @@ -92,7 +96,8 @@ contract LensFactory {
GraphFactory graphFactory,
NamespaceFactory namespaceFactory,
address accountBlockingRule,
address groupGatedFeedRule
address groupGatedFeedRule,
address usernameSimpleCharsetRule
) {
ACCESS_CONTROL_FACTORY = accessControlFactory;
ACCOUNT_FACTORY = accountFactory;
Expand All @@ -104,6 +109,7 @@ contract LensFactory {
TEMPORARY_ACCESS_CONTROL = new PermissionlessAccessControl();
ACCOUNT_BLOCKING_RULE = accountBlockingRule;
GROUP_GATED_FEED_RULE = groupGatedFeedRule;
USERNAME_SIMPLE_CHARSET_RULE = usernameSimpleCharsetRule;
}

// TODO: This function belongs to an App probably.
Expand Down Expand Up @@ -314,18 +320,38 @@ contract LensFactory {
string memory nftName,
string memory nftSymbol
) external returns (address) {
ITokenURIProvider tokenURIProvider = new LensUsernameTokenURIProvider();
IRoleBasedAccessControl accessControl = _deployAccessControl(owner, admins);
RuleChange[] memory modifiedRules = new RuleChange[](rules.length + 1);

{
RuleSelectorChange[] memory selectorChanges = new RuleSelectorChange[](1);
selectorChanges[0] = RuleSelectorChange({
ruleSelector: INamespaceRule.processCreation.selector,
isRequired: true,
enabled: true
});
modifiedRules[0] = RuleChange({
ruleAddress: USERNAME_SIMPLE_CHARSET_RULE,
configSalt: bytes32(0),
configurationChanges: RuleConfigurationChange({configure: true, ruleParams: new KeyValue[](0)}),
selectorChanges: selectorChanges
});
for (uint256 i = 0; i < rules.length; i++) {
require(rules[i].ruleAddress != USERNAME_SIMPLE_CHARSET_RULE, Errors.DuplicatedValue());
modifiedRules[i + 1] = _injectRuleAccessControl(rules[i], address(accessControl));
}
}

return NAMESPACE_FACTORY.deployNamespace(
namespace,
metadataURI,
accessControl,
owner,
_injectRuleAccessControl(rules, address(accessControl)),
modifiedRules,
extraData,
nftName,
nftSymbol,
tokenURIProvider
new LensUsernameTokenURIProvider()
);
}

Expand Down
6 changes: 6 additions & 0 deletions deploy/deployFactories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ export default async function deployFactories(factoriesProxyOwner: string): Prom
contractType: ContractType.Rule,
constructorArguments: [metadataURI],
},
{
contractName: 'UsernameSimpleCharsetNamespaceRule',
contractType: ContractType.Rule,
constructorArguments: [metadataURI],
},
];

const deployedContracts: Record<string, ContractInfo> = {};
Expand All @@ -97,6 +102,7 @@ export default async function deployFactories(factoriesProxyOwner: string): Prom
deployedContracts['NamespaceFactory'].address,
deployedContracts['AccountBlockingRule'].address,
deployedContracts['GroupGatedFeedRule'].address,
deployedContracts['UsernameSimpleCharsetNamespaceRule'].address,
];

await deployLensContract({
Expand Down
12 changes: 6 additions & 6 deletions deploy/deployRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ export async function deployRules(): Promise<void> {
constructorArguments: [metadataURI],
},
// Namespace Rules
{
contractName: 'UsernameCharsetNamespaceRule',
contractType: ContractType.Rule,
constructorArguments: [metadataURI],
},
// {
// contractName: 'UsernameCharsetNamespaceRule',
// contractType: ContractType.Rule,
// constructorArguments: [metadataURI],
// },
{
contractName: 'UsernameLengthNamespaceRule',
contractType: ContractType.Rule,
Expand All @@ -93,7 +93,7 @@ export async function deployRules(): Promise<void> {
contractName: 'TokenGatedNamespaceRule',
contractType: ContractType.Rule,
constructorArguments: [metadataURI],
},
}
];

for (const contract of contracts) {
Expand Down
6 changes: 5 additions & 1 deletion script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {Beacon} from "contracts/core/upgradeability/Beacon.sol";

import {AccountBlockingRule} from "contracts/rules/base/AccountBlockingRule.sol";
import {GroupGatedFeedRule} from "contracts/rules/feed/GroupGatedFeedRule.sol";
import {UsernameSimpleCharsetNamespaceRule} from "contracts/rules/namespace/UsernameSimpleCharsetNamespaceRule.sol";

contract MyScript is Script {
function testMyScript() public {
Expand Down Expand Up @@ -69,6 +70,7 @@ contract MyScript is Script {

address accountBlockingRule;
address groupGatedFeedRule;
address usernameSimpleCharsetRule;

function run() external {
proxyAdminLock = address(new Lock(lockOwner, true));
Expand All @@ -78,6 +80,7 @@ contract MyScript is Script {

accountBlockingRule = address(new AccountBlockingRule({metadataURI: "uri://any"}));
groupGatedFeedRule = address(new GroupGatedFeedRule({metadataURI: "uri://any"}));
usernameSimpleCharsetRule = address(new UsernameSimpleCharsetNamespaceRule({metadataURI: "uri://any"}));

lensFactory = new LensFactory({
accessControlFactory: new AccessControlFactory(),
Expand All @@ -88,7 +91,8 @@ contract MyScript is Script {
graphFactory: graphFactory,
namespaceFactory: namespaceFactory,
accountBlockingRule: accountBlockingRule,
groupGatedFeedRule: groupGatedFeedRule
groupGatedFeedRule: groupGatedFeedRule,
usernameSimpleCharsetRule: usernameSimpleCharsetRule
});
}

Expand Down
2 changes: 1 addition & 1 deletion test/factories/LensFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ contract LensFactoryTest is Test, BaseDeployments {
accountExtraData: _emptyKeyValueArray()
});
CreateUsernameParams memory usernameParams = CreateUsernameParams({
username: "myTestUsername",
username: "satoshi",
createUsernameCustomParams: _emptyKeyValueArray(),
createUsernameRuleProcessingParams: _emptyRuleProcessingParamsArray(),
assignUsernameCustomParams: _emptyKeyValueArray(),
Expand Down
7 changes: 5 additions & 2 deletions test/helpers/BaseDeployments.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {Beacon} from "contracts/core/upgradeability/Beacon.sol";

import {AccountBlockingRule} from "contracts/rules/base/AccountBlockingRule.sol";
import {GroupGatedFeedRule} from "contracts/rules/feed/GroupGatedFeedRule.sol";

import {UsernameSimpleCharsetNamespaceRule} from "contracts/rules/namespace/UsernameSimpleCharsetNamespaceRule.sol";
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";

contract BaseDeployments is Test {
Expand Down Expand Up @@ -66,6 +66,7 @@ contract BaseDeployments is Test {

address accountBlockingRule;
address groupGatedFeedRule;
address usernameSimpleCharsetRule;

function setUp() public virtual {
proxyAdminLock = address(new Lock(lockOwner, true));
Expand All @@ -75,6 +76,7 @@ contract BaseDeployments is Test {

accountBlockingRule = address(new AccountBlockingRule({metadataURI: "uri://any"}));
groupGatedFeedRule = address(new GroupGatedFeedRule({metadataURI: "uri://any"}));
usernameSimpleCharsetRule = address(new UsernameSimpleCharsetNamespaceRule({metadataURI: "uri://any"}));

lensFactory = new LensFactory({
accessControlFactory: new AccessControlFactory(),
Expand All @@ -85,7 +87,8 @@ contract BaseDeployments is Test {
graphFactory: graphFactory,
namespaceFactory: namespaceFactory,
accountBlockingRule: accountBlockingRule,
groupGatedFeedRule: groupGatedFeedRule
groupGatedFeedRule: groupGatedFeedRule,
usernameSimpleCharsetRule: usernameSimpleCharsetRule
});
}

Expand Down

0 comments on commit 5a76ef2

Please sign in to comment.