
Overview
DEL has collaborated with Kim Protocol to introduce a pioneering community-built plugin: an NFT Marketplace. The primary goal was to provide a dedicated space for creators of kpNFTs to sell their NFTs without managing liquidity directly. Additionally, we aimed to extend the marketplace’s capabilities to include all ERC721 and ERC1155 tokens, thus encouraging innovative uses within the Kim ecosystem.
As an external developer, DEL ensured that the smart contracts align with Kim’s requirement for users to allocate xKIM to access the marketplace functions. This allocation is key to engaging users with the Kim Protocol, with varying levels of xKIM needed based on whether transactions involve premium NFTs.
We’re thrilled about this collaboration and the opportunity it presents for both Kim Protocol’s community and future builders, inviting everyone to explore the potential of this new marketplace plugin.
Technical Requirements
The Solidity contracts were designed in collaboration with Kim as an escrow-based marketplace for NFTs and semi-fungible NFTs that are listed. For listings that support bids, funds are also escrowed until the sale is settled or listing is cancelled (seller cancellation restrictions apply).
The following listing types were required and implemented:
- Buy it now (with the option to enable bidding)
- English auction (ascending price)
- Dutch auction (descending price)
- Blind (commit / reveal with ascending price)
Buy it now auctions will instantly settle when the buyer pays the asking price and so will the Dutch auction when the first valid bid arrives at the smart contract after observing the price decrease. English and blind auctions all require settling after the auction ends but that can be facilitated by anyone since the smart contract will know the winner which will payout the seller and send the NFT onto the buyer. For bidding on Buy it now auctions, sellers have to accept or reject a bid and buyers have the ability to place expiration to reflect price sensitive markets and movements.
The following functionality requires xKIM allocations in order to use:
- Listing an NFT (Which is one entry point regardless of listing type or NFT type)
- Buying and Bidding (Which checks if the NFT is premium)
- Revealing a blind bid
The full list of functionality including the listing cancellation logic can be found in the technical docs.
Building the Plugin and Challenges
Foundry is some of the best tooling for Solidity development. Thanks to the Rust-based implementation, compilation is fast and it offers a much more powerful set of tools for testing such as the fuzzer which was used to develop the NFT marketplace.
In order to ensure maximum compatibility with the Kim Protocol, the existing Kim token repository was installed as a git submodule inside of the lib. The goal was to utilize an instance of the real xKIM token and logic deployed but within local tests. As a result it was eventually possible to ensure that the `IXKimTokenUsage` notification hook was working correctly when a user allocated xKIM to the plugin (required to know if the user has correctly allocated xKIM).
The challenge was building the NFT marketplace using one of the newer versions of Solidity (0.8.X) and OpenZeppelin whilst trying to utilize the xKIM token built for Solidity (=0.7.6) and an older version of OpenZeppelin with a different contract suite and a folder layout that is not 100% forward compatible. Foundry is able to compile multiple Solidity files using different Solidity versions but things get complicated when trying to import a =0.7.6 Solidity file into a 0.8.X test file and as mentioned before, there is an upstream dependency issue with OpenZeppelin.
The issues were sorted as follows:
- Install two versions of OpenZeppelin’s contracts as lib dependencies referencing specific commits saved as different lib folders
- Remap (foundry.toml) the NFT marketplace contracts to reference the newer version of OpenZeppelin whilst external Kim protocol smart contracts were set up under a remap pointing to the correct OpenZeppelin for the =0.7.6 files
- Create artifact generator files in the test directory that simply import the xKIM token (and associated dependencies) in order to generate a bytecode artifact in `out/`
- Finally, use a foundry cheatcode to deploy i.e: `deployCode(“./out/XKimToken.sol/XKimToken.json”, abi.encode(kimToken));`
From there, the development was smooth sailing and once internal testing was completed it was shipped to audit.
Closing thoughts
Developing this bespoke NFT marketplace in collaboration with Kim Protocol has been both a fun and exciting endeavour, unlocking a host of new possibilities within the DeFi space. The ability to list, buy, and bid on a variety of NFTs through different auction types not only enhances user interaction, but also offers flexibility tailored to different market dynamics. The integration of the plugin with xKIM token allocations ensures that users are actively engaged with the Kim Protocol ecosystem, promoting a secure and rewarding environment. This project underscores the commitment of both Kim Protocol and DEL to user security and community involvement, paving the way for future innovations and empowering builders to explore further integrations. As we continue to push the boundaries of what’s possible in the blockchain world, this marketplace stands as a testament to what can be achieved when community, technology, and shared values come together.
Leave a Reply