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

Changed minting of reward tokens in L2MessageReceiver #17

Merged
merged 1 commit into from
Jan 23, 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
16 changes: 1 addition & 15 deletions contracts/L2MessageReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,10 @@ contract L2MessageReceiver is ILayerZeroReceiver, IL2MessageReceiver, OwnableUpg

(address user_, uint256 amount_) = abi.decode(payload_, (address, uint256));

_mintRewardTokens(user_, amount_);
IMOR(rewardToken).mint(user_, amount_);

isNonceUsed[senderChainId_][nonce_] = true;
}

function _mintRewardTokens(address user_, uint256 amount_) private {
uint256 maxAmount_ = IMOR(rewardToken).cap() - IMOR(rewardToken).totalSupply();

if (amount_ == 0 || maxAmount_ == 0) {
return;
}

if (amount_ > maxAmount_) {
amount_ = maxAmount_;
}

IMOR(rewardToken).mint(user_, amount_);
}

function _authorizeUpgrade(address) internal view override onlyOwner {}
}
30 changes: 20 additions & 10 deletions test/L2MessageReceiver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,6 @@ describe('L2MessageReceiver', () => {
expect(await l2MessageReceiver.isNonceUsed(2, 5)).to.be.equal(true);
payload = ethers.AbiCoder.defaultAbiCoder().encode(['address', 'uint256'], [await SECOND.getAddress(), wei(2)]);
tx = await l2MessageReceiver.connect(THIRD).lzReceive(2, address, 6, payload);
await expect(tx).to.changeTokenBalance(mor, SECOND, wei(1));
expect(await l2MessageReceiver.isNonceUsed(2, 6)).to.be.equal(true);
payload = ethers.AbiCoder.defaultAbiCoder().encode(['address', 'uint256'], [await SECOND.getAddress(), wei(2)]);
tx = await l2MessageReceiver.connect(THIRD).lzReceive(2, address, 7, payload);
await expect(tx).to.changeTokenBalance(mor, SECOND, wei(0));
expect(await l2MessageReceiver.isNonceUsed(2, 7)).to.be.equal(true);
payload = ethers.AbiCoder.defaultAbiCoder().encode(['address', 'uint256'], [await SECOND.getAddress(), wei(0)]);
tx = await l2MessageReceiver.connect(THIRD).lzReceive(2, address, 8, payload);
await expect(tx).to.changeTokenBalance(mor, SECOND, wei(0));
expect(await l2MessageReceiver.isNonceUsed(2, 8)).to.be.equal(true);
});
it('should revert if provided wrong lzEndpoint', async () => {
await expect(l2MessageReceiver.lzReceive(0, '0x', 1, '0x')).to.be.revertedWith('L2MR: invalid gateway');
Expand All @@ -155,6 +145,26 @@ describe('L2MessageReceiver', () => {
await l2MessageReceiver.connect(THIRD).lzReceive(2, address, 5, payload);
expect(await l2MessageReceiver.failedMessages(2, address, 5)).to.eq(ethers.keccak256(payload));
});
it('should fail if provided wrong mint amount', async () => {
const address = ethers.solidityPacked(
['address', 'address'],
[await OWNER.getAddress(), await l2MessageReceiver.getAddress()],
);
const payload = ethers.AbiCoder.defaultAbiCoder().encode(
['address', 'uint256'],
[await SECOND.getAddress(), wei(100)],
);

await l2MessageReceiver.connect(THIRD).lzReceive(2, address, 5, payload);

expect(await l2MessageReceiver.failedMessages(2, address, 5)).to.eq(ZERO_BYTES32);
await l2MessageReceiver.connect(THIRD).lzReceive(2, address, 5, payload);
expect(await l2MessageReceiver.failedMessages(2, address, 5)).to.eq(ethers.keccak256(payload));

await mor.connect(SECOND).burn(wei(100));

await l2MessageReceiver.connect(THIRD).lzReceive(2, address, 5, payload);
});
});

describe('#nonblockingLzReceive', () => {
Expand Down
Loading