Skip to content

Commit

Permalink
refactor: add lsp1 data in ownership function hooks (#789)
Browse files Browse the repository at this point in the history
* refactor: add lsp1 data in ownership function hooks

* test: resolve failing tests to latest behavior

* refactor: add the hooks in LSP14 and LSP9

* test: resolve lsp1 failing tests

* chore: delete renounceOwnershipStartedAt in acceptOwnership

---------

Co-authored-by: Jean Cvllr <31145285+CJ42@users.noreply.github.com>
  • Loading branch information
YamenMerhi and CJ42 authored Nov 6, 2023
1 parent e7ef125 commit 0b27572
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 22 deletions.
13 changes: 7 additions & 6 deletions contracts/LSP0ERC725Account/LSP0ERC725AccountCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ abstract contract LSP0ERC725AccountCore is
// notify the pending owner through LSP1
pendingNewOwner.notifyUniversalReceiver(
_TYPEID_LSP0_OwnershipTransferStarted,
""
abi.encode(currentOwner, pendingNewOwner)
);

// reset the transfer ownership lock
Expand All @@ -563,7 +563,7 @@ abstract contract LSP0ERC725AccountCore is
// notify the pending owner through LSP1
pendingNewOwner.notifyUniversalReceiver(
_TYPEID_LSP0_OwnershipTransferStarted,
""
abi.encode(currentOwner, pendingNewOwner)
);

// reset the transfer ownership lock
Expand Down Expand Up @@ -598,20 +598,21 @@ abstract contract LSP0ERC725AccountCore is

_setOwner(pendingOwnerAddress);
delete _pendingOwner;
delete _renounceOwnershipStartedAt;
} else {
_acceptOwnership();
}

// notify the previous owner if supports LSP1
previousOwner.notifyUniversalReceiver(
_TYPEID_LSP0_OwnershipTransferred_SenderNotification,
""
abi.encode(previousOwner, pendingOwnerAddress)
);

// notify the pending owner if supports LSP1
pendingOwnerAddress.notifyUniversalReceiver(
_TYPEID_LSP0_OwnershipTransferred_RecipientNotification,
""
abi.encode(previousOwner, pendingOwnerAddress)
);

// If msg.sender != pendingOwnerAddress & verifyAfter is true, Call {lsp20VerifyCallResult} on the new owner
Expand Down Expand Up @@ -644,7 +645,7 @@ abstract contract LSP0ERC725AccountCore is
if (owner() == address(0)) {
previousOwner.notifyUniversalReceiver(
_TYPEID_LSP0_OwnershipTransferred_SenderNotification,
""
abi.encode(accountOwner, address(0))
);
}
} else {
Expand All @@ -658,7 +659,7 @@ abstract contract LSP0ERC725AccountCore is
if (owner() == address(0)) {
previousOwner.notifyUniversalReceiver(
_TYPEID_LSP0_OwnershipTransferred_SenderNotification,
""
abi.encode(accountOwner, address(0))
);
}

Expand Down
8 changes: 4 additions & 4 deletions contracts/LSP14Ownable2Step/LSP14Ownable2Step.sol
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ abstract contract LSP14Ownable2Step is ILSP14Ownable2Step, OwnableUnset {

newOwner.notifyUniversalReceiver(
_TYPEID_LSP14_OwnershipTransferStarted,
""
abi.encode(currentOwner, newOwner)
);

// reset the transfer ownership lock
Expand All @@ -118,12 +118,12 @@ abstract contract LSP14Ownable2Step is ILSP14Ownable2Step, OwnableUnset {

previousOwner.notifyUniversalReceiver(
_TYPEID_LSP14_OwnershipTransferred_SenderNotification,
""
abi.encode(previousOwner, msg.sender)
);

msg.sender.notifyUniversalReceiver(
_TYPEID_LSP14_OwnershipTransferred_RecipientNotification,
""
abi.encode(previousOwner, msg.sender)
);
}

Expand All @@ -144,7 +144,7 @@ abstract contract LSP14Ownable2Step is ILSP14Ownable2Step, OwnableUnset {
if (owner() == address(0)) {
previousOwner.notifyUniversalReceiver(
_TYPEID_LSP14_OwnershipTransferred_SenderNotification,
""
abi.encode(previousOwner, address(0))
);
}
}
Expand Down
8 changes: 4 additions & 4 deletions contracts/LSP9Vault/LSP9VaultCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ contract LSP9VaultCore is

newOwner.notifyUniversalReceiver(
_TYPEID_LSP9_OwnershipTransferStarted,
""
abi.encode(currentOwner, newOwner)
);

// reset the transfer ownership lock
Expand All @@ -462,12 +462,12 @@ contract LSP9VaultCore is

previousOwner.notifyUniversalReceiver(
_TYPEID_LSP9_OwnershipTransferred_SenderNotification,
""
abi.encode(previousOwner, msg.sender)
);

msg.sender.notifyUniversalReceiver(
_TYPEID_LSP9_OwnershipTransferred_RecipientNotification,
""
abi.encode(previousOwner, msg.sender)
);
}

Expand All @@ -490,7 +490,7 @@ contract LSP9VaultCore is
if (owner() == address(0)) {
previousOwner.notifyUniversalReceiver(
_TYPEID_LSP9_OwnershipTransferred_SenderNotification,
""
abi.encode(previousOwner, address(0))
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1573,7 +1573,10 @@ export const shouldBehaveLikeLSP1Delegate = (
vault.address,
0,
LSP1_TYPE_IDS.LSP9OwnershipTransferred_SenderNotification,
'0x',
abiCoder.encode(
['address', 'address'],
[context.universalProfile1.address, context.accounts.owner1.address],
),
lsp1ReturnedData,
);
});
Expand Down Expand Up @@ -1649,7 +1652,10 @@ export const shouldBehaveLikeLSP1Delegate = (
vault.address,
0,
LSP1_TYPE_IDS.LSP9OwnershipTransferred_SenderNotification,
'0x',
abiCoder.encode(
['address', 'address'],
[context.universalProfile1.address, context.accounts.owner1.address],
),
lsp1ReturnedData,
);
});
Expand Down Expand Up @@ -1732,7 +1738,10 @@ export const shouldBehaveLikeLSP1Delegate = (
vault.address,
0,
LSP1_TYPE_IDS.LSP9OwnershipTransferred_SenderNotification,
'0x',
abiCoder.encode(
['address', 'address'],
[context.universalProfile1.address, context.accounts.owner1.address],
),
lsp1ReturnedData,
);
});
Expand Down Expand Up @@ -2882,7 +2891,10 @@ export const shouldBehaveLikeLSP1Delegate = (
vault.address,
0,
LSP1_TYPE_IDS.LSP9OwnershipTransferred_SenderNotification,
'0x',
abiCoder.encode(
['address', 'address'],
[testContext.universalProfile.address, newVaultOwner.address],
),
expectedReturnedValues,
);

Expand Down Expand Up @@ -3004,7 +3016,10 @@ export const shouldBehaveLikeLSP1Delegate = (
vault.address,
0,
LSP1_TYPE_IDS.LSP9OwnershipTransferred_RecipientNotification,
'0x',
abiCoder.encode(
['address', 'address'],
[vaultOwner.address, context.universalProfile1.address],
),
expectedReturnedValues,
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {

// constants
import { LSP1_TYPE_IDS, LSP20_SUCCESS_VALUES, OPERATION_TYPES } from '../../constants';
import { abiCoder } from './..//utils/helpers';

export type LSP20TestContext = {
accounts: SignerWithAddress[];
Expand Down Expand Up @@ -237,7 +238,10 @@ export const shouldBehaveLikeLSP20 = (buildContext: () => Promise<LSP20TestConte
context.universalProfile.address,
0,
LSP1_TYPE_IDS.LSP0OwnershipTransferred_SenderNotification,
'0x',
abiCoder.encode(
['address', 'address'],
[newContractOwner.address, ethers.constants.AddressZero],
),
'0x',
);
});
Expand Down
5 changes: 4 additions & 1 deletion tests/LSP9Vault/LSP9Vault.behaviour.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,10 @@ export const shouldBehaveLikeLSP9 = (
context.lsp9Vault.address,
0,
LSP1_TYPE_IDS.LSP9OwnershipTransferStarted,
'0x',
abiCoder.encode(
['address', 'address'],
[context.accounts.owner.address, context.universalProfile.address],
),
abiCoder.encode(
['bytes', 'bytes'],
[ethers.utils.hexlify(ethers.utils.toUtf8Bytes('LSP1: typeId out of scope')), '0x'],
Expand Down
5 changes: 4 additions & 1 deletion tests/UniversalProfile.behaviour.ts
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,10 @@ export const shouldBehaveLikeLSP3 = (
context.universalProfile.address,
0,
LSP1_TYPE_IDS.LSP0OwnershipTransferred_SenderNotification,
'0x',
abiCoder.encode(
['address', 'address'],
[newContractOwner.address, ethers.constants.AddressZero],
),
'0x',
);
});
Expand Down

0 comments on commit 0b27572

Please sign in to comment.