Memetroplis ProductionGuideReference

5.1 Buy Flow (Same Chain)

Single Chain Execution

Scenario: A user buys a new meme token on the same chain where it was created (no cross-chain interaction needed).

  1. User Action – Buy: The user calls the

    buy

    function on the TokenFactory contract, specifying which token to buy and how many tokens or how much currency they wish to spend. The user includes the payment in the transaction. For example, on Ethereum the user might call

    buy(tokenAddress, 100)

    with 100 being the desired tokens, and send the required ETH value.

  2. Cost Calculation: The TokenFactory reads the current sold supply of the token (let’s call it $S$). Using the TokenFactoryHelper (bonding curve math), it calculates the cost for the desired number of tokens $\Delta S$. It also retrieves the current price for reference or to emit an event.

    • If the user specified a token amount, the contract computes the cost and checks

      msg.value

      (or transferred amount) is sufficient.

    • If the user specified an ETH amount instead, the contract would compute how many tokens that buys (solving the inverse of the cost integral).

    • It also ensures this purchase won’t exceed the cap (if $\Delta S$ would take $S$ beyond the threshold supply, it may either restrict or allow only up to the threshold).

  3. Mint Tokens: The TokenFactory then mints the new tokens. It calls the meme token’s

    mint

    function to create $\Delta S$ tokens and assigns them to the buyer’s address. Now the token’s total supply (in the ERC-20 contract) has increased by $\Delta S$.

  4. Update State: The TokenFactory updates its record of the total sold supply: $S := S + \Delta S$. This new value will be used for subsequent price calculations. If this update hits the pre-set cap (e.g. the market cap threshold), the contract will mark the sale as completed and (in a subsequent transaction or step) trigger the liquidity provisioning process.

  5. Emit Event: The TokenFactory emits a

    BoughtMemeToken(buyer, token, amount, cost)

    event. This event can be picked up by off-chain services or a subgraph for UI updates. It includes who bought, which token, how many tokens, and how much base currency was spent.

  6. Completion: The user receives the tokens in their wallet. The remaining ETH (if they sent too much) could be refunded or the function might be structured to accept an exact payment. Now the user can hold or even sell back via the bonding curve.

(Throughout this process, the user’s transaction interacts only with the local blockchain. Gas fees are paid for the transaction, but no cross-chain fees are involved in same-chain buys.)

5.2 Sell Flow (Same Chain)