Using with Solidity

Usage with Solidity

An ERC-20 token contract named BasedToken with BasedLang meta programming comments injected into its functions. The BasedLang comments are used to describe additional logic and context that could be interpreted or executed by a Large Language Model (LLM) when integrated with the BasedLang compiler.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
 
// Example ERC-20 Token Contract with BasedLang code injected into the functions
contract BasedToken {
    string public name = "BasedToken";
    string public symbol = "BASED";
    uint8 public decimals = 18;
    uint256 public totalSupply;
 
    mapping(address => uint256) public balanceOf;
    mapping(address => mapping(address => uint256)) public allowance;
 
    /* !based0.1:
    let initSupply = 1000000
    context initContext = "Setting initial supply and assigning to creator."
    */
 
    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
 
    constructor() {
        /* !based0.1:
        let creator = msg.sender
        model supplyModel = "text-davinci-003"
        context supplyContext = "Creator is minting initial supply."
        */
        totalSupply = 1000000 * (10 ** uint256(decimals));
        balanceOf[msg.sender] = totalSupply;
        emit Transfer(address(0), msg.sender, totalSupply);
    }
 
    function transfer(address _to, uint256 _value) public returns (bool success) {
        /* !based0.1:
        def checkBalance = ( >= balanceOf[msg.sender] _value )
        context transferContext = "Transferring tokens from sender to recipient."
        loop i = [1, _value]
            print "Transferring token number: " i
        */
        require(balanceOf[msg.sender] >= _value, "Insufficient balance");
        balanceOf[msg.sender] -= _value;
        balanceOf[_to] += _value;
        emit Transfer(msg.sender, _to, _value);
        return true;
    }
 
    function approve(address _spender, uint256 _value) public returns (bool success) {
        /* !based0.1:
        def setAllowance = ( let allowance[msg.sender][_spender] = _value )
        context approveContext = "Approving spender to withdraw tokens up to the specified amount."
        */
        allowance[msg.sender][_spender] = _value;
        emit Approval(msg.sender, _spender, _value);
        return true;
    }
 
    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
        /* !based0.1:
        def checkAllowance = ( >= allowance[_from][msg.sender] _value )
        context transferFromContext = "Transferring tokens from an approved account to recipient."
        model transferFromModel = "text-davinci-003"
        */
        require(_value <= balanceOf[_from], "Insufficient balance");
        require(_value <= allowance[_from][msg.sender], "Insufficient allowance");
        balanceOf[_from] -= _value;
        balanceOf[_to] += _value;
        allowance[_from][msg.sender] -= _value;
        emit Transfer(_from, _to, _value);
        return true;
    }
}