blockful-io / swaplace-contracts

Swaplace is an open-source, ownerless and feeless token swap protocol
https://app.swaplace.xyz/
MIT License
33 stars 33 forks source link

refactor: lower gas cost of createSwap by delegating security checks to the implementer #172

Closed 0xneves closed 8 months ago

0xneves commented 8 months ago

Refactor Request

Describe the Refactor Request

A couple of validations in the createSwap function can be removed to prioritize gas optimization.

Describe Preferred Solution

By removing the parseData from createSwap and leaving only the swapId in the event emission we can slightly reduce gas consumption for the final user. Both if checks can be done on the front-end while the event should only rely on the swapId which should be used by a front-end or back-end to fetch the other information about the swap, which is needed anyways.

Related Code

...
    (address allowed, uint256 expiry) = parseData(swap.config);

    if (expiry < block.timestamp) revert InvalidExpiry(expiry);

    if (swap.biding.length == 0 || swap.asking.length == 0)
      revert InvalidAssetsLength();
...
    emit SwapCreated(swapId, msg.sender, allowed, expiry);
}

Additional Context

This is an optimization vs legibility/usability issue. We decided to prioritize the optimization after checking the issue #104 .

blackbeard002 commented 8 months ago

Hey @0xneves can I take this? Once you merge #165 I'll get onto this.

0xneves commented 8 months ago

This is probably the last smart-contract-related Swaplace task before a release. I marked the iteration as past week to follow schedule, you must rush this asap @blackbeard002

blackbeard002 commented 8 months ago

Roger that. I'm on it