Closed DOBEN closed 10 months ago
To me, it seems the bid
entry point is not really needed, since onCis2Received
is the entry point for making the bidding.
Users can use permit
or transfer
directly on the token contract instead.
@limemloh The bid
and onCis2Received
entry points were consolidated into one entry point.
Task description
Motivation: Some use cases came with the request to have an example of how to implement a sponsored transaction mechanism on a CIS2 token so that the CIS2 token can be used as a payment token (without acquiring any CCD from an exchange to cover transaction fees).
Some scenarios requested:
The task is to have a simple auction dApp that can hold several items. Everyone can create an item to be auctioned. Users can bid for an item by paying with a given cis2Token via the sponsored transaction mechanism.
Sub-tasks Smart contract state layout:
Smart contract ItemState(
state (e.g. sold, active), highest_bidder, highest_bid, item_name, endTime, startTime
):Functions in auction contract:
addItem
(can be called by anyone and theItemState
has to be provided as an input parameter. Some sanity checks will be done.)view
(returns the state content),viewItemState
(returns the state of a specific item).bid
(TheinputParameter
to thebid
function is equivalent to theOnReceivingCis2Params
. This function is not directly invoked by the user but rather theonCis2Received
hook function as specified in the cis2 standard. The flow is that the user invokes thepermit
entry point in thecis2_contract
first which transfers the new bid amount to thebid
function in this auction contract. TheAddtitionalData
in thepayload
part of thePermitParam
includes theitem_index
so that thebid
function can retrieve the user's intendeditem_index
as well. Thebid
function logic contains the following main tasks:cis2_contract
(hard coded in the state) can call into this hook.itemState
if the newest bid is higher than the stored bid for a given item.old_bidder
withold_bid
.auction_finalize
(can be called by anyone for a specific item after the auction has ended, the item will be marked as sold and the amount ofhighest_bid
cis2-tokens as specified in the ItemState will be transferred to the auction creator).Additional modification in the cis2-token contract:
mint(receiverAddress)
function (Unprotected, will airdrop a specific amount of cis2-tokens to thereceiverAddress
).Front end + Back end part of dApp: