SmartPy smart contract with Chat GPT - Experiment

Inspired by this Tweet - Using Chat GPT to create a SmartPy contract:

I was thinking myself lets try it out. I used Chat GPT-4 for this little experiment.
Obviously this should not be trusted, I would like to see the opinion of experiences SmartPy developers what they think about this code. Is it worthless? Or can you work with that and adapt some changes? I am no smart contract dev so it looks good for me but what do I know!

My Input to Chat GPT-4 was:

You are an AI smart contract programming assistant.
Follow the users requirements carefully and to the letter!

  • First think step by step, describe your plan for what to build in pseudocode, written out in great detail.
  • Then output the code in a single codeblock.
  • Minimize any other prose
  • Write in the Tezos Smart contract language SmartPy

Here I put an explanation what rebase tokens on ethereum are with some examples.

Based on this create a similar smart contract with functions of a rebase token but on Tezos in SmartPy.
The rebases shall take place every 24 hours and occur if the price of the token will differ from the USD price by 5%. You will probably need to call an oracle to check the USD price for that.

This was the response:

  1. Import necessary SmartPy libraries

  2. Initialize contract storage

    • target_price
    • rebase_period
    • last_rebase_timestamp
    • total_supply
    • balances (map of address to balance)
    • price_oracle (oracle contract address)
  3. Implement a rebase function

    • Check if 24 hours have passed since the last rebase
    • Call the price oracle to get the current token price in USD
    • Calculate the percentage difference between the target price and the current price
    • If the percentage difference is greater than or equal to 5%, perform the rebase
      • Calculate the new total supply
      • Update balances proportionally for all token holders
      • Update the last rebase timestamp
    1. Implement entry points for standard token functionality (transfer, approve, allowance, etc.)

And here is the SmartPy code:

import smartpy as sp

class ElasticSupplyToken(sp.Contract):
    def __init__(self, target_price, price_oracle):
            rebase_period=sp.timestamp(24 * 60 * 60),
            balances=sp.big_map(tkey=sp.TAddress, tvalue=sp.TNat),
            allowances=sp.big_map(tkey=(sp.TAddress, sp.TAddress), tvalue=sp.TNat),

    def rebase(self, params):
   - >=,
            message="Not enough time has passed since the last rebase",
        current_price = sp.contract(
            sp.TMutez,, "get_token_price"
        sp.transfer(sp.unit, sp.mutez(0), current_price)
        price = sp.local("price", sp.fst(sp.result()))
        sp.verify(price > 0, message="Invalid price")

        percentage_difference = (
            sp.abs( - price) * 100) /
            percentage_difference >= 5, message="Price difference is less than 5%"

        new_total_supply = ( * price) //
        factor = new_total_supply * sp.nat(10_000) //

        for addr in
  [addr] = ([addr] * factor) // sp.nat(10_000) = new_total_supply =

    def transfer(self, params):
  [sp.sender] >= params.value,
            message="Insufficient balance",
        )[sp.sender] -= params.value[] += params.value

    def approve(self, params):[(sp.sender, params.spender)] = params.value

    def transfer_from(self, params):
  [(params.from_, sp.sender)] >= params.value,
            message="Insufficient allowance",
  [params.from_] >= params.value,
            message="Insufficient balance",
        )[(params.from_, sp.sender)] -= params.value[params.from_] -= params.value[] += params.value

# Instantiate the contract and compile it to Michelson
target_price = 1_000_000  # 1 USD in micro-USD
price_oracle = sp.address("tz1...")  # Address of the price oracle contract
elastic_token = ElasticSupplyToken(target_price, price_oracle)
sp.add_compilation_target("elastic_token", elastic_token)