Skip to content

Commit

Permalink
#104: Requested changes done mentioned in #165
Browse files Browse the repository at this point in the history
  • Loading branch information
blackbeard002 committed Jan 16, 2024
1 parent 3ebfdd8 commit f85d0f0
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
6 changes: 6 additions & 0 deletions contracts/SwapFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,19 @@ abstract contract SwapFactory is ISwapFactory, ISwap, IErrors {
return Swap(owner,config, biding, asking);
}

/**
* @dev See {ISwapFactory-packData}.
*/
function packData(
address allowed,
uint256 expiry
) public pure returns(uint256) {
return (uint256(uint160(allowed)) << 96) | uint256(expiry);
}

/**
* @dev See {ISwapFactory-parseData}.
*/
function parseData(
uint256 config
) public pure returns(address,uint256) {
Expand Down
4 changes: 1 addition & 3 deletions contracts/Swaplace.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ contract Swaplace is SwapFactory, ISwaplace, IERC165 {

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

expiry = 0;

_swaps[swapId].config = packData(allowed,expiry);
_swaps[swapId].config = packData(allowed,0);

Asset[] memory assets = swap.asking;

Expand Down
5 changes: 2 additions & 3 deletions contracts/interfaces/ISwap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ interface ISwap {
*
* It is composed of:
* - `owner` of the Swap.
* - `config` holds two values 'allowed' and 'expiry',packed using bitwise.
* 'allowed' address to accept the Swap.
* 'expiry' date of the Swap.
* - `config` represents two packed values: 'allowed' for the allowed address
* to accept the swap and 'expiry' for the expiration date of the swap.
* - `biding` assets that are being bided by the owner.
* - `asking` assets that are being asked by the owner.
*
Expand Down
8 changes: 8 additions & 0 deletions contracts/interfaces/ISwapFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,19 @@ interface ISwapFactory {
ISwap.Asset[] memory asking
) external view returns (ISwap.Swap memory);

/**
* @dev Packs `allowed` and the `expiry`.
* This function returns the bitwise packing of `allowed` and `expiry` as a uint256.
*/
function packData(
address allowed,
uint256 expiry
) external pure returns(uint256);

/**
* @dev Parsing the `config`.
* This function returns the extracted values of `allowed` and `expiry`.
*/
function parseData(
uint256 config
) external pure returns (address,uint256);
Expand Down
14 changes: 7 additions & 7 deletions test/TestSwapFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ describe("Swaplace Factory", async function () {
});

it("Should be able to {makeSwap} with ERC20 and ERC721", async function () {
const _expiry = (await blocktimestamp()) * 2;
const currentTimestamp = (await blocktimestamp()) * 2;

const ERC20Asset: Asset = await makeAsset(MockERC20.address, 1000);
const ERC721Asset: Asset = await makeAsset(MockERC721.address, 1);

const config = await Swaplace.packData(zeroAddress, _expiry);
const config = await Swaplace.packData(zeroAddress, currentTimestamp);

const swap = await makeSwap(
owner.address,
Expand All @@ -61,7 +61,7 @@ describe("Swaplace Factory", async function () {
const [allowed, expiry] = await Swaplace.parseData(swap.config);

expect(swap.owner).to.be.equals(owner.address);
expect(expiry).to.be.equals(_expiry);
expect(expiry).to.be.equals(currentTimestamp);
expect(allowed).to.be.equals(zeroAddress);
expect(swap.biding[0]).to.be.equals(ERC20Asset);
expect(swap.asking[0]).to.be.equals(ERC721Asset);
Expand Down Expand Up @@ -111,12 +111,12 @@ describe("Swaplace Factory", async function () {
});

it("Should be able to {makeSwap} with multiple assets", async function () {
const _expiry = (await blocktimestamp()) * 2;
const currentTimestamp = (await blocktimestamp()) * 2;

const ERC20Asset = await makeAsset(MockERC20.address, 1000);
const ERC721Asset = await makeAsset(MockERC721.address, 1);

const config = await Swaplace.packData(zeroAddress, _expiry);
const config = await Swaplace.packData(zeroAddress, currentTimestamp);

const swap = await makeSwap(
owner.address,
Expand All @@ -136,15 +136,15 @@ describe("Swaplace Factory", async function () {
});

it("Should be able to {composeSwap} using both ERC20, ERC721", async function () {
const _expiry = (await blocktimestamp()) * 2;
const currentTimestamp = (await blocktimestamp()) * 2;

const bidingAddr = [MockERC20.address, MockERC721.address];
const bidingAmountOrId = [1000, 1];

const askingAddr = [MockERC721.address];
const askingAmountOrId = [2];

const config = await Swaplace.packData(zeroAddress, _expiry);
const config = await Swaplace.packData(zeroAddress, currentTimestamp);

const swap = await composeSwap(
owner.address,
Expand Down

0 comments on commit f85d0f0

Please sign in to comment.