Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
cwsnt committed Jan 19, 2024
1 parent f26eafe commit a63b93b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
14 changes: 7 additions & 7 deletions contracts/integration/MoC/MocIntegration.sol
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ contract MocIntegration is OwnableUpgradeable, ERC1967UpgradeUpgradeable {
*
* @return SignatureTransferDetails struct object
*/
function _generateTransferDetails(address _to, uint256 _amount) private view returns (ISignatureTransfer.SignatureTransferDetails memory) {
function _generateTransferDetails(address _to, uint256 _amount) private pure returns (ISignatureTransfer.SignatureTransferDetails memory) {
ISignatureTransfer.SignatureTransferDetails memory transferDetails = ISignatureTransfer.SignatureTransferDetails({
to: _to,
requestedAmount: _amount
Expand All @@ -187,23 +187,23 @@ contract MocIntegration is OwnableUpgradeable, ERC1967UpgradeUpgradeable {
/**
* @dev "Consume a nonce": return the current value and increment.
*
* @param owner address of owner
* @param _address address of owner
*
* @return current nonce of the owner's address
*/
function _useNonce(address owner) internal virtual returns (uint256 current) {
Counters.Counter storage nonce = _permit2Nonces[owner];
function _useNonce(address _address) internal virtual returns (uint256 current) {
Counters.Counter storage nonce = _permit2Nonces[_address];
current = nonce.current();
nonce.increment();
}

/**
* @dev getter for currernt nonce
*
* @param owner address of owner
* @param _address address of owner
* @return current nonce of the owner's address
*/
function nonces(address owner) public view returns (uint256) {
return _permit2Nonces[owner].current();
function getPermit2Nonce(address _address) public view returns (uint256) {
return _permit2Nonces[_address].current();
}
}
2 changes: 1 addition & 1 deletion docs/main.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions tasks/sips/args/SIPArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ const SIPSOV3564 = async (hre): Promise<ISipArgument> => {
const newMocIntegrationImpl = await ethers.getContract("MocIntegration_Implementation");
const myntAdminProxy = await ethers.getContract("MyntAdminProxy");

if (
(await myntAdminProxy.getProxyImplementation(mocIntegrationProxy.address)) === newMocIntegrationImpl.address
) {
logger.error("New mocIntegration implementation is the same with the current implementation");
throw Error("^");
}

const args: ISipArgument = {
args: {
targets: [myntAdminProxy.address],
Expand Down
26 changes: 13 additions & 13 deletions tests/integrations/MoC/MocIntegration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ describe("MoC Integration", async () => {

await dllr.connect(alice).approve(permit2.address, ethers.constants.MaxUint256);

const nonce = await mocIntegration.nonces(alice.address);
const nonce = await mocIntegration.getPermit2Nonce(alice.address);
const deadline = toDeadline(1000 * 60 * 60 * 30 /** 30 minutes */);

const permitTransferFrom: PermitTransferFrom = {
Expand Down Expand Up @@ -236,7 +236,7 @@ describe("MoC Integration", async () => {

expect((await dllr.balanceOf(alice.address)).toString()).eq("0");
expect(await ethers.provider.getBalance(moc.address)).eq(expectedRbtcValue);
expect(await mocIntegration.nonces(alice.address)).eq(nonce.add(1));
expect(await mocIntegration.getPermit2Nonce(alice.address)).eq(nonce.add(1));
});

it("should be able to redeem from DLLR Money on Chain DoC and then redeem RBTC from DoC through Permit2, with two transactions", async () => {
Expand All @@ -257,7 +257,7 @@ describe("MoC Integration", async () => {

await dllr.connect(alice).approve(permit2.address, ethers.constants.MaxUint256);

const nonce = await mocIntegration.nonces(alice.address);
const nonce = await mocIntegration.getPermit2Nonce(alice.address);
const deadline = toDeadline(1000 * 60 * 60 * 30 /** 30 minutes */);
let dllrAmountToRedeem = new BN(dllrAmount).div(new BN(2)).toString();

Expand Down Expand Up @@ -304,9 +304,9 @@ describe("MoC Integration", async () => {
)
.to.changeTokenBalance(dllr, alice.address, `-${dllrAmountToRedeem}`);

expect(await mocIntegration.nonces(alice.address)).eq(nonce.add(1));
expect(await mocIntegration.getPermit2Nonce(alice.address)).eq(nonce.add(1));

const nonce2 = await mocIntegration.nonces(alice.address);
const nonce2 = await mocIntegration.getPermit2Nonce(alice.address);
const deadline2 = toDeadline(1000 * 60 * 60 * 30 /** 30 minutes */);

const permitTransferFrom2: PermitTransferFrom = {
Expand Down Expand Up @@ -336,7 +336,7 @@ describe("MoC Integration", async () => {

expect((await dllr.balanceOf(alice.address)).toString()).eq("0");
expect(await ethers.provider.getBalance(moc.address)).eq(initialExpectedRbtcValue);
expect(await mocIntegration.nonces(alice.address)).eq(nonce2.add(1));
expect(await mocIntegration.getPermit2Nonce(alice.address)).eq(nonce2.add(1));
});

it("should revert to redeem from DLLR Money on Chain DoC and then redeem RBTC from DoC if yet approved the permit2", async () => {
Expand All @@ -354,7 +354,7 @@ describe("MoC Integration", async () => {
.to.changeTokenBalance(dllr, alice.address, dllrAmount)
.to.changeTokenBalance(bAssetDoc, alice.address, `-${dllrAmount}`);

const nonce = await mocIntegration.nonces(alice.address);
const nonce = await mocIntegration.getPermit2Nonce(alice.address);
const deadline = toDeadline(1000 * 60 * 60 * 30 /** 30 minutes */);

const permitTransferFrom: PermitTransferFrom = {
Expand Down Expand Up @@ -391,7 +391,7 @@ describe("MoC Integration", async () => {
mocIntegration.connect(alice).getDocFromDllrAndRedeemRBTCWithPermit2(permitTransferFrom, signature)
).to.be.revertedWith("TRANSFER_FROM_FAILED");

expect(await mocIntegration.nonces(alice.address)).eq(nonce);
expect(await mocIntegration.getPermit2Nonce(alice.address)).eq(nonce);
});

it("should revert to redeem from DLLR Money on Chain DoC and then redeem RBTC from DoC if signature is assigned to wrong spender", async () => {
Expand All @@ -411,7 +411,7 @@ describe("MoC Integration", async () => {

await dllr.connect(alice).approve(permit2.address, ethers.constants.MaxUint256);

const nonce = await mocIntegration.nonces(alice.address);
const nonce = await mocIntegration.getPermit2Nonce(alice.address);
const deadline = toDeadline(1000 * 60 * 60 * 30 /** 30 minutes */);

const permitTransferFrom: PermitTransferFrom = {
Expand Down Expand Up @@ -448,7 +448,7 @@ describe("MoC Integration", async () => {
mocIntegration.connect(alice).getDocFromDllrAndRedeemRBTCWithPermit2(permitTransferFrom, signature)
).to.revertedWithCustomError(permit2, "InvalidSigner");

expect(await mocIntegration.nonces(alice.address)).eq(nonce);
expect(await mocIntegration.getPermit2Nonce(alice.address)).eq(nonce);
});

it("should revert to redeem from DLLR Money on Chain DoC and then redeem RBTC from DoC through Permit2, with two transactions with invalid nonce", async () => {
Expand All @@ -469,7 +469,7 @@ describe("MoC Integration", async () => {

await dllr.connect(alice).approve(permit2.address, ethers.constants.MaxUint256);

const nonce = await mocIntegration.nonces(alice.address);
const nonce = await mocIntegration.getPermit2Nonce(alice.address);
const deadline = toDeadline(1000 * 60 * 60 * 30 /** 30 minutes */);
let dllrAmountToRedeem = new BN(dllrAmount).div(new BN(2)).toString();

Expand Down Expand Up @@ -516,7 +516,7 @@ describe("MoC Integration", async () => {
)
.to.changeTokenBalance(dllr, alice.address, `-${dllrAmountToRedeem}`);

expect(await mocIntegration.nonces(alice.address)).eq(nonce.add(1));
expect(await mocIntegration.getPermit2Nonce(alice.address)).eq(nonce.add(1));

const deadline2 = toDeadline(1000 * 60 * 60 * 30 /** 30 minutes */);

Expand Down Expand Up @@ -558,7 +558,7 @@ describe("MoC Integration", async () => {

await dllr.connect(alice).approve(permit2.address, ethers.constants.MaxUint256);

const nonce = await mocIntegration.nonces(alice.address);
const nonce = await mocIntegration.getPermit2Nonce(alice.address);
const deadline = toDeadline(1000 * 60 * 60 * 30 /** 30 minutes */);

const permitTransferFrom: PermitTransferFrom = {
Expand Down

0 comments on commit a63b93b

Please sign in to comment.