Skip to content

Commit

Permalink
FIX: aime factory nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
cctv2206 committed Apr 16, 2024
1 parent 0739d9d commit f0d0e13
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 3 additions & 3 deletions contracts/aime/AIMeFactoryV4.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ contract AIMeFactoryV4 is Ownable {
bytes memory signature
) public payable {
require(protocolSigner != address(0), "Invalid protocol signer");
uint256 nonce = addressNonce[creator_];
bytes32 _msgHash = ECDSA.toEthSignedMessageHash(
keccak256(
abi.encodePacked(
Expand All @@ -52,8 +53,7 @@ contract AIMeFactoryV4 is Ownable {
socialId_,
minPrice_,
priceIncrement_,
// aimePowerAddress,
addressNonce[msg.sender]
nonce
)
)
)
Expand All @@ -62,7 +62,7 @@ contract AIMeFactoryV4 is Ownable {
ECDSA.recover(_msgHash, signature) == protocolSigner,
"Invalid signature"
);
addressNonce[msg.sender] += 1;
addressNonce[creator_] += 1;

address aimeAddress = _createAIME(
creator_,
Expand Down
17 changes: 16 additions & 1 deletion test/AIMeCreator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,13 @@ describe("AIMe Creator", () => {
const symbol = "KK";
const sig =
"0x6a92ce898f169f9fb312ec62d7fc60e98256a0c5b7ba3453792152a9c2d0c8370591433dae99ab3ae6fa6cbe3d57d394f37ffe001b4a269637b721b53b57612f1b";
// const nonce = await aimeFactoryContract.addressNonce(signer3.address);

const callerNonce = await aimeFactoryContract.addressNonce(
aimeCreator.address
);
expect(callerNonce).to.eq(0);
const nonce = await aimeFactoryContract.addressNonce(signer3.address);
expect(nonce).to.eq(0);

const tx = await aimeCreator.connect(signer3).create(
name,
Expand Down Expand Up @@ -105,6 +111,15 @@ describe("AIMe Creator", () => {

const aimeAddress = await aimeFactoryContract.aimeAddresses(name);
expect(aimeAddress).to.not.eq(ethers.constants.AddressZero);

const callerNonceAfter = await aimeFactoryContract.addressNonce(
aimeCreator.address
);
expect(callerNonceAfter).to.eq(0);
const nonceAfter = await aimeFactoryContract.addressNonce(
signer3.address
);
expect(nonceAfter).to.eq(1);
});
});

Expand Down

0 comments on commit f0d0e13

Please sign in to comment.