Exemple #1
0
# Number of decimal places
TOKEN_DECIMALS = 8

# Total Supply of tokens in the system
TOKEN_TOTAL_SUPPLY = 10_000_000 * 100_000_000  # 10m total supply * 10^8 (decimals)

# Allowance
ALLOWANCE_PREFIX = b'allowance'

# -------------------------------------------
# Events
# -------------------------------------------

on_transfer = Nep17TransferEvent
on_approval = CreateNewEvent([('owner', UInt160), ('spender', UInt160),
                              ('amount', int)], 'Approval')

# -------------------------------------------
# Methods
# -------------------------------------------


@public
def symbol() -> str:
    """
    Gets the symbols of the token.

    This string must be valid ASCII, must not contain whitespace or control characters, should be limited to uppercase
    Latin alphabet (i.e. the 26 letters used in English) and should be short (3-8 characters is recommended).
    This method must always return the same value every time it is invoked.
from boa3.builtin import CreateNewEvent, public

Event = CreateNewEvent([('a', int)], 'example')


@public
def Main():
    Event(10)
    meta.author = "Mirella Medeiros, Ricardo Prado and Lucas Uezu. COZ in partnership with Simpli"
    meta.description = "Update Contract Example. This contract represents the first smart contract deployed on the" \
                       "blockchain, with a buggy method."
    meta.email = "*****@*****.**"
    return meta


# -------------------------------------------
# Events
# -------------------------------------------


on_transfer = CreateNewEvent(
    [
        ('from_addr', Union[UInt160, None]),
        ('to_addr', Union[UInt160, None]),
        ('amount', int)
    ],
    'Transfer'
)


# -------------------------------------------
# Methods
# -------------------------------------------


@public(safe=True)
def update_sc(nef_file: bytes, manifest: bytes, data: Any = None):
    """
    Updates the smart contract. In this example there is a bugged method, so, the smart contract will be updated to fix
    the bug.
Exemple #4
0
from boa3.builtin import CreateNewEvent

Nep5TransferEvent = CreateNewEvent(
    [
        ('from_addr', bytes),
        ('to_addr', bytes),
        ('amount', int)
    ],
    'transfer'
)
Exemple #5
0
from typing import Union

from boa3.builtin import CreateNewEvent, Event
from boa3.builtin.type import ByteString, ECPoint, UInt160

Nep5TransferEvent: Event = CreateNewEvent([('from', bytes), ('to', bytes),
                                           ('amount', int)], 'transfer')
"""
The NEP-5 transfer event that will be triggered whenever a token is transferred, minted or burned. It needs the 
addresses of the sender, receiver and the amount transferred.

:meta hide-value:
"""

Nep11TransferEvent: Event = CreateNewEvent([('from', Union[UInt160, None]),
                                            ('to', Union[UInt160, None]),
                                            ('amount', int),
                                            ('tokenId', ByteString)],
                                           'Transfer')
"""
The NEP-11 Transfer event that will be triggered whenever a token is transferred, minted or burned. It needs the 
addresses of the sender, receiver, amount transferred and the id of the token.

:meta hide-value:
"""

Nep17TransferEvent: Event = CreateNewEvent([('from', Union[UInt160, None]),
                                            ('to', Union[UInt160, None]),
                                            ('amount', int)], 'Transfer')
"""
The NEP-17 Transfer event that will be triggered whenever a token is transferred, minted or burned. It needs the 
from boa3.builtin import CreateNewEvent


Event = CreateNewEvent(
    [
        ('a', int)
    ]
)


def Main():
    Event('10')
from typing import Any, Dict, List, cast

from boa3.builtin import CreateNewEvent, public
from boa3.builtin.contract import abort
from boa3.builtin.interop.binary import deserialize, serialize
from boa3.builtin.interop.blockchain import Transaction
from boa3.builtin.interop.contract import GAS, call_contract, destroy_contract, update_contract
from boa3.builtin.interop.runtime import calling_script_hash, check_witness, executing_script_hash, script_container
from boa3.builtin.interop.storage import delete, find, get, put
from boa3.builtin.type import UInt160, UInt256

# -------------------------------------------
# EVENTS
# -------------------------------------------

on_change_image = CreateNewEvent([('sender', UInt160)], 'ChangeImage')

# -------------------------------------------
# STORAGE KEYS
# -------------------------------------------

OWNER_KEY = b'OWNER'
POOL_OWNER_KEY = b'pool_owner_'
POOL_TOTAL_STAKE_KEY = b'pool_total_stake_'
POOL_OPTIONS_KEY = b'pool_options_'
POOL_DESCRIPTION_KEY = b'pool_description_'
POOL_RESULT_KEY = b'pool_result_'
POOL_BET_KEY = b'pool_bet_'

# -------------------------------------------
# CONTRACT LOGIC
Exemple #8
0
# -------------------------------------------
# Keys
# -------------------------------------------

TOKEN_COUNT = b'TC'
MINT_FEE = b'F'
AUTH_ADDRESSES = b'AU'
WL_ADDRESSES = b'W'

# -------------------------------------------
# Events
# -------------------------------------------

on_transfer = CreateNewEvent(
    # trigger when tokens are transferred, including zero value transfers.
    [('from_addr', Union[UInt160, None]), ('to_addr', Union[UInt160, None]),
     ('amount', int), ('tokenId', bytes)],
    'Transfer')

on_auth = CreateNewEvent(
    # trigger when an address has been authorized/whitelisted.
    [
        ('authorized', UInt160),
        ('type', int),
        ('add', bool),
    ],
    'Authorized')

on_withdraw_mint_fee = CreateNewEvent(
    # trigger when mint fees are withdrawn.
    [('from_addr', UInt160), ('value', int)],
Exemple #9
0
# structure of stream object
"""
stream = {
    id: int,
    deposit: int,
    remaining: int,
    sender: str,
    recipient: str,
    start: int,
    stop: int
}
"""

# Events
on_create = CreateNewEvent([('stream', str)], 'StreamCreated')

on_complete = CreateNewEvent([('stream_id', int)], 'StreamCompleted')

on_cancel = CreateNewEvent([('stream_id', int), ('requester', str)],
                           'StreamCanceled')
on_withdraw = CreateNewEvent([('stream_id', int), ('requester', str),
                              ('amount', int)], 'Withdraw')

# private functions


def newStream() -> Dict[str, Any]:
    """
    Create an empty stream object with the next ID in the sequence
Exemple #10
0
# ---------------------------------
# CONTRACT GLOBALS
# ---------------------------------

ACCOUNT_PREFIX = b'a'
ADMIN = UInt160(b'')
TOKEN_PREFIX = b't'
TOTAL_SUPPLY = b's'

# ---------------------------------
# EVENTS
# ---------------------------------

Nep11TransferEvent = CreateNewEvent([('from', Union[UInt160, None]),
                                     ('to', Union[UInt160, None]),
                                     ('amount', int), ('tokenId', bytes)],
                                    'Transfer')

# ---------------------------------
# Methods
# ---------------------------------


@public
def symbol() -> str:
    return "DESP"


@public
def decimals() -> int:
    return 0
Exemple #11
0
TOKEN_A = b'token_a_address'
TOKEN_B = b'token_b_address'

# Whether the smart contract was deployed or not
DEPLOYED = b'deployed'

# The fee for doing a swap. 1000 is 100%, 3 is 0.3% and so on
FEE = 3

# -------------------------------------------
# Events
# -------------------------------------------

on_transfer = Nep17TransferEvent

on_sync = CreateNewEvent([('reserve_token_a', int), ('reserve_token_b', int)],
                         'Sync')

on_mint = CreateNewEvent([('sender', UInt160), ('amount_token_a', int),
                          ('amount_token_b', int)], 'Mint')

on_burn = CreateNewEvent([('sender', UInt160), ('amount_token_a', int),
                          ('amount_token_b', int)], 'Burn')

on_swap = CreateNewEvent([('sender', UInt160), ('amount_token_a_in', int),
                          ('amount_token_b_in', int),
                          ('amount_token_a_out', int),
                          ('amount_token_b_out', int)], 'Swap')

# -------------------------------------------
# NEP-17 Methods
# -------------------------------------------
from boa3.builtin import CreateNewEvent, public

Event = CreateNewEvent()


@public
def Main():
    Event()
from boa3.builtin import CreateNewEvent


Event = CreateNewEvent([('a',)])


def Main():
    Event()
Exemple #14
0
# tested
from boa3.builtin import public

from boa3.builtin import CreateNewEvent

Transfer = CreateNewEvent([('from', int), ('to', int), ('amount', int)],
                          'transfer_test')

Refund = CreateNewEvent([('to', str), ('amount', int)], 'refund')


@public
def main() -> int:

    a = 2

    b = 5

    c = a + b

    Transfer(a, b, c)

    to = 'me'
    amount = 52

    Refund(to, amount)

    return c
Exemple #15
0
from typing import Union

from boa3.builtin import CreateNewEvent
from boa3.builtin.type import UInt160

Nep5TransferEvent = CreateNewEvent(
    [
        ('from_addr', bytes),
        ('to_addr', bytes),
        ('amount', int)
    ],
    'transfer'
)

Nep17TransferEvent = CreateNewEvent(
    [
        ('from_addr', Union[UInt160, None]),
        ('to_addr', Union[UInt160, None]),
        ('amount', int)
    ],
    'Transfer'
)


def abort():
    """
    Abort the execution of a smart contract
    """
    pass