In this new project, Blockful is a P2P Ownerless and Feeles MarketPlace:
Summarized:
A) Users propose a trade of any asset.
B) Users accept available trades.
Detailed:
A) User call public pure function composeTrade
.
B) User provides allowances for the biding assets.
C) Returned Trade struct is used to call createTrade
.
D) Trade acceptee provides allowances for asked assets.
D) tradeId
is used to accept the trade.
E) Assets are swapped and the trade becomes unavailable.
- The contracts cannot be upgraded.
- The contracts have no ownership.
- The contracts don't charge fees.
- Complex mechanics should be built by the community using the interface of Swaplace.
- There are no external contract dependencies.
- The protocol operates using allowances.
Both EOA and Contracts can access all functions in the contract.
- Create Trade
- Accept Trade
- Cancel Trade
- Make Asset
- Make Trade
- Compose Trade
- GetTrade
- GetTradesBy
The caller can store a trade request in the contract. One must give the contract allowance when transferring assets. Nevertheless, trades require a minimum expiration of 1 day.
The caller can accept any trade if the asked assets match the sender's ownership. The tradeId
must be provided and the allowances of the sender must be in place.
Provide the tradeId
and be the trade owner to cancel a trade at will. It sets the trade as expired. Notice that the allowances won't dismiss, but new ones can take their place.
Easily create and return the Asset type to use in your trade by calling this function. An Asset is a struct holding an address, an amount or id and an asset type, which can be ERC20 or ERC721.
struct Asset {
address addr;
uint256 amountOrIdOrCall;
AssetType assetType;
}
A trade carries two arrays of Asset types, an owner and the expiry period in seconds. One can call makeAsset
method to return the Asset types and use them as input when calling makeTrade
, which will return the Trade struct used when proposing a trade.
The usage is on-chain focused, but when working with off-chain, the Trade struct should be built using methods not involving calling the blockchain multiple times.
Similar to makeTrade
, compose trade will build the entire trade in a single function and return the Trade struct. Different from the make trade function, which requires pre-built assets, composeTrade
will receive as parameters all the data from the assets involved in the trade in three arrays of data, corresponding to the Asset struct requirement.
To avoid having six arrays as parameters for both assets bided or asked, both of them should be placed in the same array and then specify the uint256
integer representing the place at the index where the assets bided will turn assets asked. The variable indexFlipToAsking
is the length of bided assets and also the beginning index of the assets being asked to fulfill the trade.
function composeTrade(
address owner,
uint256 expiry,
address[] memory addrs,
uint256[] memory amountsOrIdsOrCalls,
AssetType[] memory assetTypes,
uint256 indexFlipToAsking
) public pure returns (Trade memory)
Return the trade struct info by providing the tradeId
.
Return the trades created by providing an address
.
Install dependencies.
yarn
npm i
The project is being tested in localhost.
npx hardhat test
Dex Swaplace Audit SoulPrime, DeTask Designer, Layout Cassino