0

Say I have a smart contract for exchanging 6 Token_A with 6 Token_B with an additional time condition when only 1 exchange can happen every 1 month (we don't care about msg.sender here. we can assume all actions can be done by one address):

In day 0, owner will trigger claim function that moves 1 Token_A to their address and 1 Token_B to someone else's address.

In day 6, if owner triggers claim function, the request will be rejected.

In day 30, owner can trigger claim for another token exchange and so on.

The simple solution I can think of is to create a list of timestamps and fill it with 6 timestamps (starting from creation of contract) and one pointer. Every time a claim request comes in, we can compare timestamp[pointer] with block.timestamp and increment pointer if this is a valid claim.

Though this might work for one user, this is going to become tricky if we have more than only one user (say we have a list of whitelisted users - timestamp list will be same for all but we will need multiple pointers for each user).

Any better solution for this problem?

1 Answer 1

1

These are the solutions i came up with

  • Off-Chain Managing and toggling useAvailableToClaim boolean mapping to address of the user, this solves the most risky part of managing users time and also allowing people to claim from the smart contract.
  • Using a Factory Method , each user gets their own smart contract and has the solution you have suggested. The token supply state is managed on the factory smart contract and it is distributed from the factory smart contract if needed
1
  • 1
    The first approach is interesting but the Owner will need to pay the gas fee every time they want to make the function available for a user. For the second approach, it will at too much complexity in case the number of users are significant. thanks for the suggestions!
    – Yar
    Mar 4 at 4:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.