AZWorlds Github Actions Foundry License: MIT

Frontend

https://github.com/0x73696d616f/azworlds-frontend

Backend

https://github.com/0x73696d616f/AZWorlds-backend

Description

AZWorlds is a cross chain finance/skill play to earn game where players compete for the most power and get real rewards in return. It can be played from any chain using LayerZero's infrastructure, giving access to many assets and defi protocols.

Players buy their characters in a variable rate gradual dutch auction with a target price of 10 USDC per character. 80% of the USDC is sent into the military and 20% to the developing team. Players can join the military and receive shares (gold) of the USDC deposits over a 1 year interval based on their power.

The power of characters can be increased by fighting bosses on each chain once a day that makes them level up and drop truly random items cryptographically proven using chainlink's VRF2 oracle.

Players can swap items for gold at the marketplace by placing sell and buy orders. They can then equip the bought items for more power.

In the bank, a ERC4626 vault, players can deposit USDC and retrieve gold (shares).

USDC deposited in the bank by either character sales or investors is invested in a protocol decided by governance. This means that players not only receive rewards based on their power, but also by investing in defi protocols of their choice. Each character gives a player 1 voting power unit.

Players can also play the UpVsDownGame with gold, betting on the DAI/MATIC price given by a 1 inch protocol price oracle, bringing full decentralization to AZWorlds. The oracle is flash loan protected by only allowing EOA's to fetch the oracle price.

Character Sale

The characters in the game are omnichain ERC721's, currently on Sepolia and Mumbai testnets. When a character is transfered, its level, power, equipped items and gold and also sent. The variables are tightly packed in a struct such that it only takes 1 storage space to store all char info, making it very easy to transfer characters between chains.

The sale is a variable rate gradual dutch auction with a target price of 10 USDC. This enables the price discovery of the game characters, due to the fact that the price lowers or increases based on demand.

Boss

The boss spawns every day (currently 5 minutes for testing), once per chain. Players attack the boss, and then after the round duration they can claim their reward. The randomness is provided by chainlink VRF2.

Marketplace

Players can place sell and buy orders, specifying the item ids and gold price of the items.

Military

Players can join the army and received gold rewards based on their power.

Bank

Anyone can deposit USDC and get gold (shares) in return. Character holders can also vote to invest in different protocols.

UpVsDownGame

Players can use gold to bet on the DAI/MATIC price. Fully decentralized by using the 1Inch spot price aggregator.

Testing the game

Head over to 0xaC5ded3fc6858cf82dD631a68b3Aed1C83afc05C at sepolia testnet and mint up to 1000e18 mock USDC for free. Then, buy a character at https://azworlds-frontend.vercel.app/characterSale.

About Us

Three Sigma is a venture builder firm focused on blockchain engineering, research, and investment. Our mission is to advance the adoption of blockchain technology and contribute towards the healthy development of the Web3 space.

If you are interested in joining our team, please contact us here.


Contents

Contents

ECRecover

Git Source

SPDX-License-Identifier: MIT Copyright (c) 2016-2019 zOS Global Limited Copyright (c) 2020 CENTRE SECZ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

A library that provides a safe ECDSA recovery function

Functions

recover

Recover signer's address from a signed message

Adapted from: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/65e4ffde586ec89af3b7e9140bdc9235d1254853/contracts/cryptography/ECDSA.sol Modifications: Accept v, r, and s as separate arguments

function recover(bytes32 digest, uint8 v, bytes32 r, bytes32 s) internal pure returns (address);

Parameters

NameTypeDescription
digestbytes32Keccak-256 hash digest of the signed message
vuint8v of the signature
rbytes32r of the signature
sbytes32s of the signature

Returns

NameTypeDescription
<none>addressSigner address

EIP3009

Git Source

Inherits: ERC20, EIP712Domain

SPDX-License-Identifier: MIT Copyright (c) 2020 CENTRE SECZ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

State Variables

TRANSFER_WITH_AUTHORIZATION_TYPEHASH

bytes32 public constant TRANSFER_WITH_AUTHORIZATION_TYPEHASH =
    0x7c7c6cdb67a18743f49ec6fa9b35f50d52ed05cbed4cc592e13b44501c1a2267;

RECEIVE_WITH_AUTHORIZATION_TYPEHASH

bytes32 public constant RECEIVE_WITH_AUTHORIZATION_TYPEHASH =
    0xd099cc98ef71107a616c4f0f941f04c322d8e254fe26b3c6668db87aae413de8;

CANCEL_AUTHORIZATION_TYPEHASH

bytes32 public constant CANCEL_AUTHORIZATION_TYPEHASH =
    0x158b0a9edf7a828aad02f63cd515c68ef2f50ba807396f6d12842833a1597429;

_authorizationStates

authorizer address => nonce => state (true = used / false = unused)

mapping(address => mapping(bytes32 => bool)) internal _authorizationStates;

_INVALID_SIGNATURE_ERROR

string internal constant _INVALID_SIGNATURE_ERROR = "EIP3009: invalid signature";

_AUTHORIZATION_USED_ERROR

string internal constant _AUTHORIZATION_USED_ERROR = "EIP3009: authorization is used";

Functions

authorizationState

Returns the state of an authorization

Nonces are randomly generated 32-byte data unique to the authorizer's address

function authorizationState(address authorizer, bytes32 nonce) external view returns (bool);

Parameters

NameTypeDescription
authorizeraddressAuthorizer's address
noncebytes32Nonce of the authorization

Returns

NameTypeDescription
<none>boolTrue if the nonce is used

transferWithAuthorization

Execute a transfer with a signed authorization

function transferWithAuthorization(
    address from,
    address to,
    uint256 value,
    uint256 validAfter,
    uint256 validBefore,
    bytes32 nonce,
    uint8 v,
    bytes32 r,
    bytes32 s
) external;

Parameters

NameTypeDescription
fromaddressPayer's address (Authorizer)
toaddressPayee's address
valueuint256Amount to be transferred
validAfteruint256The time after which this is valid (unix time)
validBeforeuint256The time before which this is valid (unix time)
noncebytes32Unique nonce
vuint8v of the signature
rbytes32r of the signature
sbytes32s of the signature

receiveWithAuthorization

Receive a transfer with a signed authorization from the payer

This has an additional check to ensure that the payee's address matches the caller of this function to prevent front-running attacks. (See security considerations)

function receiveWithAuthorization(
    address from,
    address to,
    uint256 value,
    uint256 validAfter,
    uint256 validBefore,
    bytes32 nonce,
    uint8 v,
    bytes32 r,
    bytes32 s
) external;

Parameters

NameTypeDescription
fromaddressPayer's address (Authorizer)
toaddressPayee's address
valueuint256Amount to be transferred
validAfteruint256The time after which this is valid (unix time)
validBeforeuint256The time before which this is valid (unix time)
noncebytes32Unique nonce
vuint8v of the signature
rbytes32r of the signature
sbytes32s of the signature

cancelAuthorization

Attempt to cancel an authorization

function cancelAuthorization(address authorizer, bytes32 nonce, uint8 v, bytes32 r, bytes32 s) external;

Parameters

NameTypeDescription
authorizeraddressAuthorizer's address
noncebytes32Nonce of the authorization
vuint8v of the signature
rbytes32r of the signature
sbytes32s of the signature

_transferWithAuthorization

function _transferWithAuthorization(
    bytes32 typeHash,
    address from,
    address to,
    uint256 value,
    uint256 validAfter,
    uint256 validBefore,
    bytes32 nonce,
    uint8 v,
    bytes32 r,
    bytes32 s
) internal;

Events

AuthorizationUsed

event AuthorizationUsed(address indexed authorizer, bytes32 indexed nonce);

AuthorizationCanceled

event AuthorizationCanceled(address indexed authorizer, bytes32 indexed nonce);

EIP712

Git Source

SPDX-License-Identifier: MIT Copyright (c) 2020 CENTRE SECZ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

A library that provides EIP712 helper functions

State Variables

EIP712_DOMAIN_TYPEHASH

bytes32 public constant EIP712_DOMAIN_TYPEHASH = 0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f;

Functions

makeDomainSeparator

Make EIP712 domain separator

function makeDomainSeparator(string memory name, string memory version) internal view returns (bytes32);

Parameters

NameTypeDescription
namestringContract name
versionstringContract version

Returns

NameTypeDescription
<none>bytes32Domain separator

recover

Recover signer's address from a EIP712 signature

function recover(bytes32 domainSeparator, uint8 v, bytes32 r, bytes32 s, bytes memory typeHashAndData)
    internal
    pure
    returns (address);

Parameters

NameTypeDescription
domainSeparatorbytes32Domain separator
vuint8v of the signature
rbytes32r of the signature
sbytes32s of the signature
typeHashAndDatabytesType hash concatenated with data

Returns

NameTypeDescription
<none>addressSigner's address

EIP712Domain

Git Source

State Variables

DOMAIN_SEPARATOR

EIP712 Domain Separator

bytes32 public DOMAIN_SEPARATOR;

Contents

Contents

LinkTokenInterface

Git Source

Functions

allowance

function allowance(address owner, address spender) external view returns (uint256 remaining);

approve

function approve(address spender, uint256 value) external returns (bool success);

balanceOf

function balanceOf(address owner) external view returns (uint256 balance);

decimals

function decimals() external view returns (uint8 decimalPlaces);

decreaseApproval

function decreaseApproval(address spender, uint256 addedValue) external returns (bool success);

increaseApproval

function increaseApproval(address spender, uint256 subtractedValue) external;

name

function name() external view returns (string memory tokenName);

symbol

function symbol() external view returns (string memory tokenSymbol);

totalSupply

function totalSupply() external view returns (uint256 totalTokensIssued);

transfer

function transfer(address to, uint256 value) external returns (bool success);

transferAndCall

function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool success);

transferFrom

function transferFrom(address from, address to, uint256 value) external returns (bool success);

VRFV2WrapperConsumerBaseInterface

Git Source

Functions

rawFulfillRandomWords

function rawFulfillRandomWords(uint256 _requestId, uint256[] memory _randomWords) external;

VRFV2WrapperInterface

Git Source

Functions

lastRequestId

function lastRequestId() external view returns (uint256);

Returns

NameTypeDescription
<none>uint256the request ID of the most recent VRF V2 request made by this wrapper. This should only be relied option within the same transaction that the request was made.

calculateRequestPrice

Calculates the price of a VRF request with the given callbackGasLimit at the current

block.

This function relies on the transaction gas price which is not automatically set during

simulation. To estimate the price at a specific gas price, use the estimatePrice function.

function calculateRequestPrice(uint32 _callbackGasLimit) external view returns (uint256);

Parameters

NameTypeDescription
_callbackGasLimituint32is the gas limit used to estimate the price.

estimateRequestPrice

Estimates the price of a VRF request with a specific gas limit and gas price.

This is a convenience function that can be called in simulation to better understand

pricing.

function estimateRequestPrice(uint32 _callbackGasLimit, uint256 _requestGasPriceWei) external view returns (uint256);

Parameters

NameTypeDescription
_callbackGasLimituint32is the gas limit used to estimate the price.
_requestGasPriceWeiuint256is the gas price in wei used for the estimation.

VRFV2WrapperConsumerBase

Git Source

Inherits: VRFV2WrapperConsumerBaseInterface

Interface for contracts using VRF randomness through the VRF V2 wrapper

PURPOSE

Create VRF V2 requests without the need for subscription management. Rather than creating

and funding a VRF V2 subscription, a user can use this wrapper to create one off requests,

paying up front rather than at fulfillment.

Since the price is determined using the gas price of the request transaction rather than

the fulfillment transaction, the wrapper charges an additional premium on callback gas

usage, in addition to some extra overhead costs associated with the VRFV2Wrapper contract.

USAGE

Calling contracts must inherit from VRFV2WrapperConsumerBase. The consumer must be funded

with enough LINK to make the request, otherwise requests will revert. To request randomness,

call the 'requestRandomness' function with the desired VRF parameters. This function handles

paying for the request based on the current pricing.

Consumers must implement the fullfillRandomWords function, which will be called during

fulfillment with the randomness result.

State Variables

LinkTokenInterface internal immutable LINK;

VRF_V2_WRAPPER

VRFV2WrapperInterface internal immutable VRF_V2_WRAPPER;

Functions

constructor

constructor(address _link, address _vrfV2Wrapper);

Parameters

NameTypeDescription
_linkaddressis the address of LinkToken
_vrfV2Wrapperaddressis the address of the VRFV2Wrapper contract

requestRandomness

Requests randomness from the VRF V2 wrapper.

function requestRandomness(uint32 _callbackGasLimit, uint16 _requestConfirmations, uint32 _numWords)
    internal
    returns (uint256 requestId);

Parameters

NameTypeDescription
_callbackGasLimituint32is the gas limit that should be used when calling the consumer's fulfillRandomWords function.
_requestConfirmationsuint16is the number of confirmations to wait before fulfilling the request. A higher number of confirmations increases security by reducing the likelihood that a chain re-org changes a published randomness outcome.
_numWordsuint32is the number of random words to request.

Returns

NameTypeDescription
requestIduint256is the VRF V2 request ID of the newly created randomness request.

fulfillRandomWords

fulfillRandomWords handles the VRF V2 wrapper response. The consuming contract must

implement it.

function fulfillRandomWords(uint256 _requestId, uint256[] memory _randomWords) internal virtual;

Parameters

NameTypeDescription
_requestIduint256is the VRF V2 request ID.
_randomWordsuint256[]is the randomness result.

rawFulfillRandomWords

function rawFulfillRandomWords(uint256 _requestId, uint256[] memory _randomWords) external override;

Contents

Contents

Contents

ILayerZeroEndpoint

Git Source

Inherits: ILayerZeroUserApplicationConfig

Functions

send

function send(
    uint16 _dstChainId,
    bytes calldata _destination,
    bytes calldata _payload,
    address payable _refundAddress,
    address _zroPaymentAddress,
    bytes calldata _adapterParams
) external payable;

receivePayload

function receivePayload(
    uint16 _srcChainId,
    bytes calldata _srcAddress,
    address _dstAddress,
    uint64 _nonce,
    uint256 _gasLimit,
    bytes calldata _payload
) external;

getInboundNonce

function getInboundNonce(uint16 _srcChainId, bytes calldata _srcAddress) external view returns (uint64);

getOutboundNonce

function getOutboundNonce(uint16 _dstChainId, address _srcAddress) external view returns (uint64);

estimateFees

function estimateFees(
    uint16 _dstChainId,
    address _userApplication,
    bytes calldata _payload,
    bool _payInZRO,
    bytes calldata _adapterParam
) external view returns (uint256 nativeFee, uint256 zroFee);

getChainId

function getChainId() external view returns (uint16);

retryPayload

function retryPayload(uint16 _srcChainId, bytes calldata _srcAddress, bytes calldata _payload) external;

hasStoredPayload

function hasStoredPayload(uint16 _srcChainId, bytes calldata _srcAddress) external view returns (bool);

getSendLibraryAddress

function getSendLibraryAddress(address _userApplication) external view returns (address);

getReceiveLibraryAddress

function getReceiveLibraryAddress(address _userApplication) external view returns (address);

isSendingPayload

function isSendingPayload() external view returns (bool);

isReceivingPayload

function isReceivingPayload() external view returns (bool);

getConfig

function getConfig(uint16 _version, uint16 _chainId, address _userApplication, uint256 _configType)
    external
    view
    returns (bytes memory);

getSendVersion

function getSendVersion(address _userApplication) external view returns (uint16);

getReceiveVersion

function getReceiveVersion(address _userApplication) external view returns (uint16);

ILayerZeroReceiver

Git Source

Functions

lzReceive

function lzReceive(uint16 _srcChainId, bytes calldata _srcAddress, uint64 _nonce, bytes calldata _payload) external;

ILayerZeroUserApplicationConfig

Git Source

Functions

setConfig

function setConfig(uint16 _version, uint16 _chainId, uint256 _configType, bytes calldata _config) external;

setSendVersion

function setSendVersion(uint16 _version) external;

setReceiveVersion

function setReceiveVersion(uint16 _version) external;

forceResumeReceive

function forceResumeReceive(uint16 _srcChainId, bytes calldata _srcAddress) external;

Contents

IOFT

Git Source

Inherits: IOFTCore, IERC20

Interface of the OFT standard

IOFTCore

Git Source

Inherits: IERC165

Interface of the IOFT core standard

Functions

estimateSendFee

estimate send token _tokenId to (_dstChainId, _toAddress) _dstChainId - L0 defined chain id to send tokens too _toAddress - dynamic bytes array which contains the address to whom you are sending tokens to on the dstChain _amount - amount of the tokens to transfer _useZro - indicates to use zro to pay L0 fees _adapterParam - flexible bytes array to indicate messaging adapter services in L0

function estimateSendFee(
    uint16 _dstChainId,
    bytes calldata _toAddress,
    uint256 _amount,
    bool _useZro,
    bytes calldata _adapterParams
) external view returns (uint256 nativeFee, uint256 zroFee);

sendFrom

send _amount amount of token to (_dstChainId, _toAddress) from _from _from the owner of token _dstChainId the destination chain identifier _toAddress can be any size depending on the dstChainId. _amount the quantity of tokens in wei _refundAddress the address LayerZero refunds if too much message fee is sent _zroPaymentAddress set to address(0x0) if not paying in ZRO (LayerZero Token) _adapterParams is a flexible bytes array to indicate messaging adapter services

function sendFrom(
    address _from,
    uint16 _dstChainId,
    bytes calldata _toAddress,
    uint256 _amount,
    address payable _refundAddress,
    address _zroPaymentAddress,
    bytes calldata _adapterParams
) external payable;

circulatingSupply

returns the circulating amount of tokens on current chain

function circulatingSupply() external view returns (uint256);

token

returns the address of the ERC20 token

function token() external view returns (address);

Events

SendToChain

Emitted when _amount tokens are moved from the _sender to (_dstChainId, _toAddress) _nonce is the outbound nonce

event SendToChain(uint16 indexed _dstChainId, address indexed _from, bytes _toAddress, uint256 _amount);

ReceiveFromChain

Emitted when _amount tokens are received from _srcChainId into the _toAddress on the local chain. _nonce is the inbound nonce.

event ReceiveFromChain(uint16 indexed _srcChainId, address indexed _to, uint256 _amount);

SetUseCustomAdapterParams

event SetUseCustomAdapterParams(bool _useCustomAdapterParams);

Contents

IONFT1155

Git Source

Inherits: IONFT1155Core, IERC1155

Interface of the ONFT standard

IONFT1155Core

Git Source

Inherits: IERC165

Interface of the ONFT Core standard

Functions

sendFrom

function sendFrom(
    address _from,
    uint16 _dstChainId,
    bytes calldata _toAddress,
    uint256 _tokenId,
    uint256 _amount,
    address payable _refundAddress,
    address _zroPaymentAddress,
    bytes calldata _adapterParams
) external payable;

sendBatchFrom

function sendBatchFrom(
    address _from,
    uint16 _dstChainId,
    bytes calldata _toAddress,
    uint256[] calldata _tokenIds,
    uint256[] calldata _amounts,
    address payable _refundAddress,
    address _zroPaymentAddress,
    bytes calldata _adapterParams
) external payable;

estimateSendFee

function estimateSendFee(
    uint16 _dstChainId,
    bytes calldata _toAddress,
    uint256 _tokenId,
    uint256 _amount,
    bool _useZro,
    bytes calldata _adapterParams
) external view returns (uint256 nativeFee, uint256 zroFee);

estimateSendBatchFee

function estimateSendBatchFee(
    uint16 _dstChainId,
    bytes calldata _toAddress,
    uint256[] calldata _tokenIds,
    uint256[] calldata _amounts,
    bool _useZro,
    bytes calldata _adapterParams
) external view returns (uint256 nativeFee, uint256 zroFee);

Events

SendToChain

event SendToChain(
    uint16 indexed _dstChainId, address indexed _from, bytes indexed _toAddress, uint256 _tokenId, uint256 _amount
);

SendBatchToChain

event SendBatchToChain(
    uint16 indexed _dstChainId, address indexed _from, bytes indexed _toAddress, uint256[] _tokenIds, uint256[] _amounts
);

ReceiveFromChain

event ReceiveFromChain(
    uint16 indexed _srcChainId, bytes indexed _srcAddress, address indexed _toAddress, uint256 _tokenId, uint256 _amount
);

ReceiveBatchFromChain

event ReceiveBatchFromChain(
    uint16 indexed _srcChainId,
    bytes indexed _srcAddress,
    address indexed _toAddress,
    uint256[] _tokenIds,
    uint256[] _amounts
);

Contents

IONFT721

Git Source

Inherits: IONFT721Core, IERC721

Interface of the ONFT standard

IONFT721Core

Git Source

Inherits: IERC165

Interface of the ONFT Core standard

Functions

estimateSendFee

estimate send token _tokenId to (_dstChainId, _toAddress) _dstChainId - L0 defined chain id to send tokens too _toAddress - dynamic bytes array which contains the address to whom you are sending tokens to on the dstChain _tokenId - token Id to transfer _useZro - indicates to use zro to pay L0 fees _adapterParams - flexible bytes array to indicate messaging adapter services in L0

function estimateSendFee(
    uint16 _dstChainId,
    bytes calldata _toAddress,
    uint256 _tokenId,
    bool _useZro,
    bytes calldata _adapterParams,
    bytes memory _data
) external view returns (uint256 nativeFee, uint256 zroFee);

estimateSendBatchFee

estimate send token _tokenId to (_dstChainId, _toAddress) _dstChainId - L0 defined chain id to send tokens too _toAddress - dynamic bytes array which contains the address to whom you are sending tokens to on the dstChain _tokenIds[] - token Ids to transfer _useZro - indicates to use zro to pay L0 fees _adapterParams - flexible bytes array to indicate messaging adapter services in L0

function estimateSendBatchFee(
    uint16 _dstChainId,
    bytes calldata _toAddress,
    uint256[] calldata _tokenIds,
    bool _useZro,
    bytes calldata _adapterParams,
    bytes[] memory _data
) external view returns (uint256 nativeFee, uint256 zroFee);

Events

SendToChain

Emitted when _tokenIds[] are moved from the _sender to (_dstChainId, _toAddress) _nonce is the outbound nonce from

event SendToChain(uint16 indexed _dstChainId, address indexed _from, bytes indexed _toAddress, uint256[] _tokenIds);

ReceiveFromChain

event ReceiveFromChain(
    uint16 indexed _srcChainId, bytes indexed _srcAddress, address indexed _toAddress, uint256[] _tokenIds
);

CreditStored

Emitted when _payload was received from lz, but not enough gas to deliver all tokenIds

event CreditStored(bytes32 _hashedPayload, bytes _payload);

CreditCleared

Emitted when _hashedPayload has been completely delivered

event CreditCleared(bytes32 _hashedPayload);

Contents

LzApp

Git Source

Inherits: Ownable, ILayerZeroReceiver, ILayerZeroUserApplicationConfig

State Variables

DEFAULT_PAYLOAD_SIZE_LIMIT

uint256 public constant DEFAULT_PAYLOAD_SIZE_LIMIT = 10_000;

lzEndpoint

ILayerZeroEndpoint public immutable lzEndpoint;

trustedRemoteLookup

mapping(uint16 => bytes) public trustedRemoteLookup;

minDstGasLookup

mapping(uint16 => mapping(uint16 => uint256)) public minDstGasLookup;

payloadSizeLimitLookup

mapping(uint16 => uint256) public payloadSizeLimitLookup;

precrime

address public precrime;

Functions

constructor

constructor(address _endpoint);

lzReceive

function lzReceive(uint16 _srcChainId, bytes calldata _srcAddress, uint64 _nonce, bytes calldata _payload)
    public
    virtual
    override;

_blockingLzReceive

function _blockingLzReceive(uint16 _srcChainId, bytes memory _srcAddress, uint64 _nonce, bytes memory _payload)
    internal
    virtual;

_lzSend

function _lzSend(
    uint16 _dstChainId,
    bytes memory _payload,
    address payable _refundAddress,
    address _zroPaymentAddress,
    bytes memory _adapterParams,
    uint256 _nativeFee
) internal virtual;

_checkGasLimit

function _checkGasLimit(uint16 _dstChainId, uint16 _type, bytes memory _adapterParams, uint256 _extraGas)
    internal
    view
    virtual;

_getGasLimit

function _getGasLimit(bytes memory _adapterParams) internal pure virtual returns (uint256 gasLimit);

_checkPayloadSize

function _checkPayloadSize(uint16 _dstChainId, uint256 _payloadSize) internal view virtual;

getConfig

function getConfig(uint16 _version, uint16 _chainId, address, uint256 _configType)
    external
    view
    returns (bytes memory);

setConfig

function setConfig(uint16 _version, uint16 _chainId, uint256 _configType, bytes calldata _config)
    external
    override
    onlyOwner;

setSendVersion

function setSendVersion(uint16 _version) external override onlyOwner;

setReceiveVersion

function setReceiveVersion(uint16 _version) external override onlyOwner;

forceResumeReceive

function forceResumeReceive(uint16 _srcChainId, bytes calldata _srcAddress) external override onlyOwner;

setTrustedRemote

function setTrustedRemote(uint16 _srcChainId, bytes calldata _path) external onlyOwner;

setTrustedRemoteAddress

function setTrustedRemoteAddress(uint16 _remoteChainId, bytes calldata _remoteAddress) external onlyOwner;

getTrustedRemoteAddress

function getTrustedRemoteAddress(uint16 _remoteChainId) external view returns (bytes memory);

setPrecrime

function setPrecrime(address _precrime) external onlyOwner;

setMinDstGas

function setMinDstGas(uint16 _dstChainId, uint16 _packetType, uint256 _minGas) external onlyOwner;

setPayloadSizeLimit

function setPayloadSizeLimit(uint16 _dstChainId, uint256 _size) external onlyOwner;

isTrustedRemote

function isTrustedRemote(uint16 _srcChainId, bytes calldata _srcAddress) external view returns (bool);

Events

SetPrecrime

event SetPrecrime(address precrime);

SetTrustedRemote

event SetTrustedRemote(uint16 _remoteChainId, bytes _path);

SetTrustedRemoteAddress

event SetTrustedRemoteAddress(uint16 _remoteChainId, bytes _remoteAddress);

SetMinDstGas

event SetMinDstGas(uint16 _dstChainId, uint16 _type, uint256 _minDstGas);

NonblockingLzApp

Git Source

Inherits: LzApp

State Variables

failedMessages

mapping(uint16 => mapping(bytes => mapping(uint64 => bytes32))) public failedMessages;

Functions

constructor

constructor(address _endpoint) LzApp(_endpoint);

_blockingLzReceive

function _blockingLzReceive(uint16 _srcChainId, bytes memory _srcAddress, uint64 _nonce, bytes memory _payload)
    internal
    virtual
    override;

_storeFailedMessage

function _storeFailedMessage(
    uint16 _srcChainId,
    bytes memory _srcAddress,
    uint64 _nonce,
    bytes memory _payload,
    bytes memory _reason
) internal virtual;

nonblockingLzReceive

function nonblockingLzReceive(uint16 _srcChainId, bytes calldata _srcAddress, uint64 _nonce, bytes calldata _payload)
    public
    virtual;

_nonblockingLzReceive

function _nonblockingLzReceive(uint16 _srcChainId, bytes memory _srcAddress, uint64 _nonce, bytes memory _payload)
    internal
    virtual;

retryMessage

function retryMessage(uint16 _srcChainId, bytes calldata _srcAddress, uint64 _nonce, bytes calldata _payload)
    public
    payable
    virtual;

Events

MessageFailed

event MessageFailed(uint16 _srcChainId, bytes _srcAddress, uint64 _nonce, bytes _payload, bytes _reason);

RetryMessageSuccess

event RetryMessageSuccess(uint16 _srcChainId, bytes _srcAddress, uint64 _nonce, bytes32 _payloadHash);

Contents

OFT

Git Source

Inherits: OFTCore, ERC20, IOFT

Functions

constructor

constructor(string memory _name, string memory _symbol, address _lzEndpoint)
    ERC20(_name, _symbol)
    OFTCore(_lzEndpoint);

supportsInterface

function supportsInterface(bytes4 interfaceId) public view virtual override(OFTCore, IERC165) returns (bool);

token

function token() public view virtual override returns (address);

circulatingSupply

function circulatingSupply() public view virtual override returns (uint256);

_debitFrom

function _debitFrom(address _from, uint16, bytes memory, uint256 _amount) internal virtual override returns (uint256);

_creditTo

function _creditTo(uint16, address _toAddress, uint256 _amount) internal virtual override returns (uint256);

OFTCore

Git Source

Inherits: NonblockingLzApp, ERC165, IOFTCore

State Variables

NO_EXTRA_GAS

uint256 public constant NO_EXTRA_GAS = 0;

PT_SEND

uint16 public constant PT_SEND = 0;

useCustomAdapterParams

bool public useCustomAdapterParams;

Functions

constructor

constructor(address _lzEndpoint) NonblockingLzApp(_lzEndpoint);

supportsInterface

function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool);

estimateSendFee

function estimateSendFee(
    uint16 _dstChainId,
    bytes calldata _toAddress,
    uint256 _amount,
    bool _useZro,
    bytes calldata _adapterParams
) public view virtual override returns (uint256 nativeFee, uint256 zroFee);

sendFrom

function sendFrom(
    address _from,
    uint16 _dstChainId,
    bytes calldata _toAddress,
    uint256 _amount,
    address payable _refundAddress,
    address _zroPaymentAddress,
    bytes calldata _adapterParams
) public payable virtual override;

setUseCustomAdapterParams

function setUseCustomAdapterParams(bool _useCustomAdapterParams) public virtual onlyOwner;

_nonblockingLzReceive

function _nonblockingLzReceive(uint16 _srcChainId, bytes memory _srcAddress, uint64 _nonce, bytes memory _payload)
    internal
    virtual
    override;

_send

function _send(
    address _from,
    uint16 _dstChainId,
    bytes memory _toAddress,
    uint256 _amount,
    address payable _refundAddress,
    address _zroPaymentAddress,
    bytes memory _adapterParams
) internal virtual;

_sendAck

function _sendAck(uint16 _srcChainId, bytes memory, uint64, bytes memory _payload) internal virtual;

_checkAdapterParams

function _checkAdapterParams(uint16 _dstChainId, uint16 _pkType, bytes memory _adapterParams, uint256 _extraGas)
    internal
    virtual;

_debitFrom

function _debitFrom(address _from, uint16 _dstChainId, bytes memory _toAddress, uint256 _amount)
    internal
    virtual
    returns (uint256);

_creditTo

function _creditTo(uint16 _srcChainId, address _toAddress, uint256 _amount) internal virtual returns (uint256);

Contents

ONFT1155

Git Source

Inherits: ONFT1155Core, ERC1155, IONFT1155

Functions

constructor

constructor(string memory _uri, address _lzEndpoint) ERC1155(_uri) ONFT1155Core(_lzEndpoint);

supportsInterface

function supportsInterface(bytes4 interfaceId)
    public
    view
    virtual
    override(ONFT1155Core, ERC1155, IERC165)
    returns (bool);

_debitFrom

function _debitFrom(address _from, uint16, bytes memory, uint256[] memory _tokenIds, uint256[] memory _amounts)
    internal
    virtual
    override;

_creditTo

function _creditTo(uint16, address _toAddress, uint256[] memory _tokenIds, uint256[] memory _amounts)
    internal
    virtual
    override;

ONFT1155Core

Git Source

Inherits: NonblockingLzApp, ERC165, IONFT1155Core

State Variables

NO_EXTRA_GAS

uint256 public constant NO_EXTRA_GAS = 0;

FUNCTION_TYPE_SEND

uint16 public constant FUNCTION_TYPE_SEND = 1;

FUNCTION_TYPE_SEND_BATCH

uint16 public constant FUNCTION_TYPE_SEND_BATCH = 2;

useCustomAdapterParams

bool public useCustomAdapterParams;

Functions

constructor

constructor(address _lzEndpoint) NonblockingLzApp(_lzEndpoint);

supportsInterface

function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool);

estimateSendFee

function estimateSendFee(
    uint16 _dstChainId,
    bytes memory _toAddress,
    uint256 _tokenId,
    uint256 _amount,
    bool _useZro,
    bytes memory _adapterParams
) public view virtual override returns (uint256 nativeFee, uint256 zroFee);

estimateSendBatchFee

function estimateSendBatchFee(
    uint16 _dstChainId,
    bytes memory _toAddress,
    uint256[] memory _tokenIds,
    uint256[] memory _amounts,
    bool _useZro,
    bytes memory _adapterParams
) public view virtual override returns (uint256 nativeFee, uint256 zroFee);

sendFrom

function sendFrom(
    address _from,
    uint16 _dstChainId,
    bytes memory _toAddress,
    uint256 _tokenId,
    uint256 _amount,
    address payable _refundAddress,
    address _zroPaymentAddress,
    bytes memory _adapterParams
) public payable virtual override;

sendBatchFrom

function sendBatchFrom(
    address _from,
    uint16 _dstChainId,
    bytes memory _toAddress,
    uint256[] memory _tokenIds,
    uint256[] memory _amounts,
    address payable _refundAddress,
    address _zroPaymentAddress,
    bytes memory _adapterParams
) public payable virtual override;

_sendBatch

function _sendBatch(
    address _from,
    uint16 _dstChainId,
    bytes memory _toAddress,
    uint256[] memory _tokenIds,
    uint256[] memory _amounts,
    address payable _refundAddress,
    address _zroPaymentAddress,
    bytes memory _adapterParams
) internal virtual;

_nonblockingLzReceive

function _nonblockingLzReceive(uint16 _srcChainId, bytes memory _srcAddress, uint64, bytes memory _payload)
    internal
    virtual
    override;

setUseCustomAdapterParams

function setUseCustomAdapterParams(bool _useCustomAdapterParams) external onlyOwner;

_debitFrom

function _debitFrom(
    address _from,
    uint16 _dstChainId,
    bytes memory _toAddress,
    uint256[] memory _tokenIds,
    uint256[] memory _amounts
) internal virtual;

_creditTo

function _creditTo(uint16 _srcChainId, address _toAddress, uint256[] memory _tokenIds, uint256[] memory _amounts)
    internal
    virtual;

_toSingletonArray

function _toSingletonArray(uint256 element) internal pure returns (uint256[] memory);

Events

SetUseCustomAdapterParams

event SetUseCustomAdapterParams(bool _useCustomAdapterParams);

Contents

ONFT721

Git Source

Inherits: IONFT721, ONFT721Core, ERC721

Functions

constructor

constructor(string memory _name, string memory _symbol, uint256 _minGasToTransfer, address _lzEndpoint)
    ERC721(_name, _symbol)
    ONFT721Core(_minGasToTransfer, _lzEndpoint);

supportsInterface

function supportsInterface(bytes4 interfaceId)
    public
    view
    virtual
    override(ONFT721Core, ERC721, IERC165)
    returns (bool);

_debitFrom

function _debitFrom(address _from, uint16, bytes memory, uint256 _tokenId) internal virtual;

_creditTo

function _creditTo(uint16, address _toAddress, uint256 _tokenId, bytes memory) internal virtual override;

ONFT721Core

Git Source

Inherits: NonblockingLzApp, ERC165, IONFT721Core

State Variables

FUNCTION_TYPE_SEND

uint16 public constant FUNCTION_TYPE_SEND = 1;

minGasToTransferAndStore

uint256 public minGasToTransferAndStore;

dstChainIdToBatchLimit

mapping(uint16 => uint256) public dstChainIdToBatchLimit;

dstChainIdToTransferGas

mapping(uint16 => uint256) public dstChainIdToTransferGas;

storedCredits

mapping(bytes32 => StoredCredit) public storedCredits;

Functions

constructor

constructor(uint256 _minGasToTransferAndStore, address _lzEndpoint) NonblockingLzApp(_lzEndpoint);

supportsInterface

function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool);

estimateSendFee

function estimateSendFee(
    uint16 _dstChainId,
    bytes memory _toAddress,
    uint256 _tokenId,
    bool _useZro,
    bytes memory _adapterParams,
    bytes memory _data
) public view virtual override returns (uint256 nativeFee, uint256 zroFee);

estimateSendBatchFee

function estimateSendBatchFee(
    uint16 _dstChainId,
    bytes memory _toAddress,
    uint256[] memory _tokenIds,
    bool _useZro,
    bytes memory _adapterParams,
    bytes[] memory _data
) public view virtual override returns (uint256 nativeFee, uint256 zroFee);

_send

function _send(
    address _from,
    uint16 _dstChainId,
    bytes memory _toAddress,
    uint256[] memory _tokenIds,
    address payable _refundAddress,
    address _zroPaymentAddress,
    bytes memory _adapterParams,
    bytes[] memory _data
) internal virtual;

_nonblockingLzReceive

function _nonblockingLzReceive(uint16 _srcChainId, bytes memory _srcAddress, uint64, bytes memory _payload)
    internal
    virtual
    override;

clearCredits

function clearCredits(bytes memory _payload) external;

_creditTill

function _creditTill(
    uint16 _srcChainId,
    address _toAddress,
    uint256 _startIndex,
    uint256[] memory _tokenIds,
    bytes[] memory _data
) internal returns (uint256);

setMinGasToTransferAndStore

function setMinGasToTransferAndStore(uint256 _minGasToTransferAndStore) external onlyOwner;

setDstChainIdToTransferGas

function setDstChainIdToTransferGas(uint16 _dstChainId, uint256 _dstChainIdToTransferGas) external onlyOwner;

setDstChainIdToBatchLimit

function setDstChainIdToBatchLimit(uint16 _dstChainId, uint256 _dstChainIdToBatchLimit) external onlyOwner;

_creditTo

function _creditTo(uint16 _srcChainId, address _toAddress, uint256 _tokenId, bytes memory _data) internal virtual;

_toSingletonArray

function _toSingletonArray(uint256 element) internal pure returns (uint256[] memory);

_toSingletonArray

function _toSingletonArray(bytes memory data) internal pure returns (bytes[] memory);

Structs

StoredCredit

struct StoredCredit {
    uint16 srcChainId;
    address toAddress;
    uint256 index;
    bool creditsRemain;
}

Contents

BytesLib

Git Source

Functions

concat

function concat(bytes memory _preBytes, bytes memory _postBytes) internal pure returns (bytes memory);

concatStorage

function concatStorage(bytes storage _preBytes, bytes memory _postBytes) internal;

slice

function slice(bytes memory _bytes, uint256 _start, uint256 _length) internal pure returns (bytes memory);

toAddress

function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address);

toUint8

function toUint8(bytes memory _bytes, uint256 _start) internal pure returns (uint8);

toUint16

function toUint16(bytes memory _bytes, uint256 _start) internal pure returns (uint16);

toUint32

function toUint32(bytes memory _bytes, uint256 _start) internal pure returns (uint32);

toUint64

function toUint64(bytes memory _bytes, uint256 _start) internal pure returns (uint64);

toUint96

function toUint96(bytes memory _bytes, uint256 _start) internal pure returns (uint96);

toUint128

function toUint128(bytes memory _bytes, uint256 _start) internal pure returns (uint128);

toUint256

function toUint256(bytes memory _bytes, uint256 _start) internal pure returns (uint256);

toBytes32

function toBytes32(bytes memory _bytes, uint256 _start) internal pure returns (bytes32);

equal

function equal(bytes memory _preBytes, bytes memory _postBytes) internal pure returns (bool);

equalStorage

function equalStorage(bytes storage _preBytes, bytes memory _postBytes) internal view returns (bool);

ExcessivelySafeCall

Git Source

State Variables

LOW_28_MASK

uint256 constant LOW_28_MASK = 0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff;

Functions

excessivelySafeCall

Use when you really really really don't trust the called contract. This prevents the called contract from causing reversion of the caller in as many ways as we can.

The main difference between this and a solidity low-level call is that we limit the number of bytes that the callee can cause to be copied to caller memory. This prevents stupid things like malicious contracts returning 10,000,000 bytes causing a local OOG when copying to memory.

function excessivelySafeCall(address _target, uint256 _gas, uint16 _maxCopy, bytes memory _calldata)
    internal
    returns (bool, bytes memory);

Parameters

NameTypeDescription
_targetaddressThe address to call
_gasuint256The amount of gas to forward to the remote contract
_maxCopyuint16The maximum number of bytes of returndata to copy to memory.
_calldatabytesThe data to send to the remote contract

Returns

NameTypeDescription
<none>boolsuccess and returndata, as .call(). Returndata is capped to _maxCopy bytes.
<none>bytes

excessivelySafeStaticCall

Use when you really really really don't trust the called contract. This prevents the called contract from causing reversion of the caller in as many ways as we can.

The main difference between this and a solidity low-level call is that we limit the number of bytes that the callee can cause to be copied to caller memory. This prevents stupid things like malicious contracts returning 10,000,000 bytes causing a local OOG when copying to memory.

function excessivelySafeStaticCall(address _target, uint256 _gas, uint16 _maxCopy, bytes memory _calldata)
    internal
    view
    returns (bool, bytes memory);

Parameters

NameTypeDescription
_targetaddressThe address to call
_gasuint256The amount of gas to forward to the remote contract
_maxCopyuint16The maximum number of bytes of returndata to copy to memory.
_calldatabytesThe data to send to the remote contract

Returns

NameTypeDescription
<none>boolsuccess and returndata, as .call(). Returndata is capped to _maxCopy bytes.
<none>bytes

swapSelector

Swaps function selectors in encoded contract calls

Allows reuse of encoded calldata for functions with identical argument types but different names. It simply swaps out the first 4 bytes for the new selector. This function modifies memory in place, and should only be used with caution.

function swapSelector(bytes4 _newSelector, bytes memory _buf) internal pure;

Parameters

NameTypeDescription
_newSelectorbytes4The new 4-byte selector
_bufbytesThe encoded contract args

Contents

Contents

wadDiv

Git Source

function wadDiv(int256 x, int256 y) pure returns (int256 r);

wadLn

Git Source

function wadLn(int256 x) pure returns (int256 r);

wadMul

Git Source

function wadMul(int256 x, int256 y) pure returns (int256 r);

fromDaysWadUnsafe

Git Source

Takes a wad amount of days and converts it to an integer amount of seconds.

Will not revert on overflow, only use where overflow is not possible.

Not meant for negative day amounts, it assumes x is positive.

function fromDaysWadUnsafe(int256 x) pure returns (uint256 r);

unsafeDiv

Git Source

Will return 0 instead of reverting if y is zero.

function unsafeDiv(int256 x, int256 y) pure returns (int256 r);

toWadUnsafe

Git Source

Authors: Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SignedWadMath.sol), Modified from Remco Bloemen (https://xn--2-umb.com/22/exp-ln/index.html)

Signed 18 decimal fixed point (wad) arithmetic library.

Will not revert on overflow, only use where overflow is not possible.

function toWadUnsafe(uint256 x) pure returns (int256 r);

wadPow

Git Source

Will not work with negative bases, only use when x is positive.

function wadPow(int256 x, int256 y) pure returns (int256);

wadExp

Git Source

function wadExp(int256 x) pure returns (int256 r);

unsafeWadDiv

Git Source

Will return 0 instead of reverting if y is zero and will not revert on overflow, only use where overflow is not possible.

function unsafeWadDiv(int256 x, int256 y) pure returns (int256 r);

unsafeWadMul

Git Source

Will not revert on overflow, only use where overflow is not possible.

function unsafeWadMul(int256 x, int256 y) pure returns (int256 r);

toDaysWadUnsafe

Git Source

Takes an integer amount of seconds and converts it to a wad amount of days.

Will not revert on overflow, only use where overflow is not possible.

Not meant for negative second amounts, it assumes x is positive.

function toDaysWadUnsafe(uint256 x) pure returns (int256 r);

LinearVRGDA

Git Source

Inherits: VRGDA

Authors: transmissions11 t11s@paradigm.xyz, FrankieIsLost frankie@paradigm.xyz

VRGDA with a linear issuance curve.

State Variables

perTimeUnit

The total number of tokens to target selling every full unit of time.

Represented as an 18 decimal fixed point number.

int256 internal immutable perTimeUnit;

Functions

constructor

Sets pricing parameters for the VRGDA.

constructor(int256 _targetPrice, int256 _priceDecayPercent, int256 _perTimeUnit)
    VRGDA(_targetPrice, _priceDecayPercent);

Parameters

NameTypeDescription
_targetPriceint256The target price for a token if sold on pace, scaled by 1e18.
_priceDecayPercentint256The percent price decays per unit of time with no sales, scaled by 1e18.
_perTimeUnitint256The number of tokens to target selling in 1 full unit of time, scaled by 1e18.

getTargetSaleTime

Given a number of tokens sold, return the target time that number of tokens should be sold by.

function getTargetSaleTime(int256 sold) public view override returns (int256);

Parameters

NameTypeDescription
soldint256A number of tokens sold, scaled by 1e18, to get the corresponding target sale time for.

Returns

NameTypeDescription
<none>int256The target time the tokens should be sold by, scaled by 1e18, where the time is relative, such that 0 means the tokens should be sold immediately when the VRGDA begins.

VRGDA

Git Source

Authors: transmissions11 t11s@paradigm.xyz, FrankieIsLost frankie@paradigm.xyz

Sell tokens roughly according to an issuance schedule.

State Variables

targetPrice

Target price for a token, to be scaled according to sales pace.

Represented as an 18 decimal fixed point number.

int256 public immutable targetPrice;

decayConstant

Precomputed constant that allows us to rewrite a pow() as an exp().

Represented as an 18 decimal fixed point number.

int256 internal immutable decayConstant;

Functions

constructor

Sets target price and per time unit price decay for the VRGDA.

constructor(int256 _targetPrice, int256 _priceDecayPercent);

Parameters

NameTypeDescription
_targetPriceint256The target price for a token if sold on pace, scaled by 1e18.
_priceDecayPercentint256The percent price decays per unit of time with no sales, scaled by 1e18.

getVRGDAPrice

Calculate the price of a token according to the VRGDA formula.

function getVRGDAPrice(int256 timeSinceStart, uint256 sold) public view virtual returns (uint256);

Parameters

NameTypeDescription
timeSinceStartint256Time passed since the VRGDA began, scaled by 1e18.
solduint256The total number of tokens that have been sold so far.

Returns

NameTypeDescription
<none>uint256The price of a token according to VRGDA, scaled by 1e18.

getTargetSaleTime

Given a number of tokens sold, return the target time that number of tokens should be sold by.

function getTargetSaleTime(int256 sold) public view virtual returns (int256);

Parameters

NameTypeDescription
soldint256A number of tokens sold, scaled by 1e18, to get the corresponding target sale time for.

Returns

NameTypeDescription
<none>int256The target time the tokens should be sold by, scaled by 1e18, where the time is relative, such that 0 means the tokens should be sold immediately when the VRGDA begins.

Babylonian

Git Source

Functions

sqrt

function sqrt(uint256 x) internal pure returns (uint256);

Context

Git Source

Submitted for verification at polygonscan.com on 2023-01-24

Provides information about the current execution context, including the sender of the transaction and its data. While these are generally available via msg.sender and msg.data, they should not be accessed in such a direct manner, since when dealing with meta-transactions the account sending and paying for execution may not be the actual sender (as far as an application is concerned). This contract is only required for intermediate, library-like contracts.

Functions

_msgSender

function _msgSender() internal view virtual returns (address);

_msgData

function _msgData() internal view virtual returns (bytes calldata);

Ownable

Git Source

Inherits: Context

Contract module which provides a basic access control mechanism, where there is an account (an owner) that can be granted exclusive access to specific functions. By default, the owner account will be the one that deploys the contract. This can later be changed with {transferOwnership}. This module is used through inheritance. It will make available the modifier onlyOwner, which can be applied to your functions to restrict their use to the owner.

State Variables

_owner

address private _owner;

Functions

constructor

Initializes the contract setting the deployer as the initial owner.

constructor();

owner

Returns the address of the current owner.

function owner() public view virtual returns (address);

onlyOwner

Throws if called by any account other than the owner.

modifier onlyOwner();

renounceOwnership

Leaves the contract without owner. It will not be possible to call onlyOwner functions anymore. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.

function renounceOwnership() public virtual onlyOwner;

transferOwnership

Transfers ownership of the contract to a new account (newOwner). Can only be called by the current owner.

function transferOwnership(address newOwner) public virtual onlyOwner;

_setOwner

function _setOwner(address newOwner) private;

Events

OwnershipTransferred

event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

UpVsDownGameV1

Git Source

Inherits: Ownable

State Variables

gameController

address public gameController;

pools

mapping(bytes => Round) public pools;

feePercentage

uint8 public feePercentage = 5;

feeAddress

address public feeAddress = msg.sender;

isRunning

bool public isRunning;

notRunningReason

bytes public notRunningReason;

Functions

onlyGameController

modifier onlyGameController();

onlyOpenPool

modifier onlyOpenPool(bytes calldata poolId);

onlyGameRunning

modifier onlyGameRunning();

onlyPoolExists

modifier onlyPoolExists(bytes calldata poolId);

constructor

constructor(address newGameController);

changeGameControllerAddress

function changeGameControllerAddress(address newGameController) public onlyOwner;

changeGameFeePercentage

function changeGameFeePercentage(uint8 newFeePercentage) public onlyOwner;

changeGameFeeAddress

function changeGameFeeAddress(address newFeeAddress) public onlyOwner;

stopGame

function stopGame(bytes calldata reason) public onlyOwner;

startGame

function startGame() public onlyOwner;

createPool

function createPool(bytes calldata poolId, uint256 minBetAmount, uint256 maxBetAmount, uint256 poolBetsLimit)
    public
    onlyGameController;

trigger

function trigger(bytes calldata poolId, int64 timeMS, int32 price, uint32 batchSize)
    public
    onlyGameController
    onlyPoolExists(poolId);

returnBets

function returnBets(bytes calldata poolId, BetGroup storage group, uint32 batchSize) private;

distribute

function distribute(bytes calldata poolId, uint32 batchSize, int64 timeMS)
    public
    onlyGameController
    onlyPoolExists(poolId);

calculateDistribution

function calculateDistribution(BetGroup storage winners, BetGroup storage losers)
    private
    view
    returns (Distribution memory);

clearPool

function clearPool(bytes calldata poolId) private;

hasPendingDistributions

function hasPendingDistributions(bytes calldata poolId) public view returns (bool);

isPoolOpen

function isPoolOpen(bytes calldata poolId) public view returns (bool);

addBet

function addBet(BetGroup storage betGroup, uint256 amount, string calldata avatar, string calldata countryCode)
    private
    returns (uint256);

makeTrade

function makeTrade(makeTradeStruct calldata userTrade)
    public
    payable
    onlyOpenPool(userTrade.poolId)
    onlyGameRunning
    onlyPoolExists(userTrade.poolId);

sendEther

function sendEther(address to, uint256 amount) private;

Events

RoundStarted

event RoundStarted(
    bytes poolId,
    int64 timestamp,
    int32 price,
    uint256 minTradeAmount,
    uint256 maxTradeAmount,
    uint256 poolTradesLimit,
    bytes indexed indexedPoolId
);

RoundEnded

event RoundEnded(bytes poolId, int64 timestamp, int32 startPrice, int32 endPrice, bytes indexed indexedPoolId);

TradePlaced

event TradePlaced(
    bytes poolId,
    address sender,
    uint256 amount,
    string prediction,
    uint256 newTotal,
    bytes indexed indexedPoolId,
    address indexed indexedSender,
    string avatarUrl,
    string countryCode,
    int64 roundStartTime
);

TradeReturned

event TradeReturned(bytes poolId, address sender, uint256 amount);

GameStopped

event GameStopped(bytes reason);

GameStarted

event GameStarted();

RoundDistributed

event RoundDistributed(bytes poolId, uint256 totalWinners, uint256 from, uint256 to, int64 timestamp);

TradeWinningsSent

event TradeWinningsSent(
    bytes poolId, address sender, uint256 tradeAmount, uint256 winningsAmount, address indexed indexedSender
);

Errors

PendingDistributions

error PendingDistributions();

Structs

BetGroup

struct BetGroup {
    uint256[] bets;
    address[] addresses;
    string[] avatars;
    string[] countries;
    uint256 total;
    uint256 distributedCount;
    uint256 totalDistributed;
}

Round

struct Round {
    bool created;
    int32 startPrice;
    int32 endPrice;
    uint256 minBetAmount;
    uint256 maxBetAmount;
    uint256 poolBetsLimit;
    BetGroup upBetGroup;
    BetGroup downBetGroup;
    int64 roundStartTime;
}

Distribution

struct Distribution {
    uint256 fee;
    uint256 totalMinusFee;
    uint256 pending;
}

makeTradeStruct

struct makeTradeStruct {
    bytes poolId;
    string avatarUrl;
    string countryCode;
    bool upOrDown;
}

Contents

IBank

Git Source

Inherits: IERC4626, IGold

Functions

depositAndSendToMilitary

function depositAndSendToMilitary(uint256 assets_) external;

invest

function invest(uint256 amount_) external;

withdrawInvestment

function withdrawInvestment(uint256 amount_) external;

setInvestmentStrategy

function setInvestmentStrategy(IInvestmentStrategy strategy_) external;

previewRewards

function previewRewards() external view returns (uint256);

getInvestment

function getInvestment() external view returns (uint256);

Events

Invest

event Invest(uint256 amount_);

WithdrawInvestment

event WithdrawInvestment(uint256 amount_);

Errors

NotGovernanceError

error NotGovernanceError(address sender_);

IBoss

Git Source

Inherits: VRFV2WrapperConsumerBaseInterface

Functions

attackBoss

function attackBoss(uint256 charId_) external;

claimRewards

function claimRewards(uint256 charId_, uint256 roundId_) external returns (uint256 itemId_);

previewRewards

function previewRewards(uint256 charId_, uint256 roundId_) external view returns (uint256 itemId_);

nextRound

function nextRound() external;

Events

RoundStarted

event RoundStarted(uint256 indexed roundId, uint256 timestamp);

BossAttacked

event BossAttacked(uint256 indexed roundId, uint256 indexed charId);

RewardClaimed

event RewardClaimed(uint256 indexed roundId, uint256 indexed charId, uint256 itemId);

RandomWordsFulfilled

event RandomWordsFulfilled(uint256 indexed roundId, uint256 seed);

Errors

RoundNotOverError

error RoundNotOverError(uint256 roundId_);

AlreadyAttackedError

error AlreadyAttackedError(uint256 charId_, uint256 roundId_);

AlreadyClaimedError

error AlreadyClaimedError(uint256 charId_, uint256 roundId_);

NotCharOwnerError

error NotCharOwnerError(uint256 charId_, address sender_);

Structs

Round

struct Round {
    bool attacked;
    bool claimed;
}

ICharacter

Git Source

Inherits: IERC721, IVotes

Functions

equipItems

function equipItems(uint256 charId_, uint256[] calldata itemIds_) external;

carryGold

function carryGold(uint256 charId_, uint256 goldAmount_) external;

dropGold

function dropGold(uint256 charId_, uint256 goldAmount_) external;

sendFrom

send token _tokenId to (_dstChainId, _toAddress) from _from _toAddress can be any size depending on the dstChainId. _zroPaymentAddress set to address(0x0) if not paying in ZRO (LayerZero Token) _adapterParams is a flexible bytes array to indicate messaging adapter services

function sendFrom(address from_, uint16 dstChainId_, address toAddress_, uint256 charId_, bytes memory adapterParams_)
    external
    payable;

sendBatchFrom

send tokens _tokenIds[] to (_dstChainId, _toAddress) from _from _toAddress can be any size depending on the dstChainId. _zroPaymentAddress set to address(0x0) if not paying in ZRO (LayerZero Token) _adapterParams is a flexible bytes array to indicate messaging adapter services

function sendBatchFrom(
    address _from,
    uint16 _dstChainId,
    address _toAddress,
    uint256[] calldata charIds_,
    bytes memory adapterParams_
) external payable;

creditTo

function creditTo(address toAddress_, uint256 tokenId_, bytes memory data_) external;

levelUp

function levelUp(uint256 charId_) external;

getCharInfo

function getCharInfo(uint256 charId_) external view returns (CharInfo memory, address);

Events

ItemsEquipped

event ItemsEquipped(uint256 indexed charId, uint256[] itemIds);

GoldCarried

event GoldCarried(uint256 indexed charId, uint256 goldAmount);

GoldDropped

event GoldDropped(uint256 indexed charId, uint256 goldAmount);

CharacterSent

event CharacterSent(CharInfo indexed charInfo, uint16 dstChainId, address toAddress);

CharacterReceived

event CharacterReceived(CharInfo indexed charInfo, address fromAddress);

CharacterLevelUp

event CharacterLevelUp(uint256 indexed charId, uint32 level);

Errors

InvalidCharInfoError

error InvalidCharInfoError(CharInfo charInfo);

NotOwnerError

error NotOwnerError(address owner);

OnlyPortalError

error OnlyPortalError(address portal);

OnlyBossError

error OnlyBossError(address boss);

Structs

CharInfo

struct CharInfo {
    uint32 charId;
    uint32 level;
    uint32 power;
    uint160 equippedGold;
}

ICharacterPortal

Git Source

Inherits: IONFT721Core

Functions

send

function send(
    address from_,
    uint16 dstChainId_,
    address toAddress_,
    uint256[] memory tokenIds_,
    address payable refundAddress_,
    bytes[] memory data_,
    bytes memory adapterParams_
) external payable;

Errors

NotCharacterError

error NotCharacterError(address sender);

ICharacterSale

Git Source

Inherits: ICharacter

Functions

buy

function buy(
    address from_,
    uint256 usdcSent_,
    uint256 validAfter_,
    uint256 validBefore_,
    bytes32 nonce_,
    Signature calldata signature_,
    string memory tokenURI_
) external returns (uint256 mintedId);

sendUsdcToBankAndGameController

function sendUsdcToBankAndGameController() external;

changeGameController

function changeGameController(address gameController_) external;

changeGameControllerFeePercentage

function changeGameControllerFeePercentage(uint256 gameControllerFeePercentage_) external;

getPrice

function getPrice() external view returns (uint256 price_);

Events

CharacterBought

event CharacterBought(address indexed buyer, uint256 indexed charId, uint256 price, string tokenURI);

Structs

Signature

struct Signature {
    uint8 v;
    bytes32 r;
    bytes32 s;
}

IGold

Git Source

Inherits: IOFT

Functions

burn

function burn(address account_, uint256 amount_) external;

mint

function mint(address account_, uint256 amount_) external;

privilegedTransferFrom

function privilegedTransferFrom(address from_, address to_, uint256 amount_) external;

Events

GoldBurned

event GoldBurned(address indexed account, uint256 amount);

GoldMinted

event GoldMinted(address indexed account, uint256 amount);

GoldPrivilegedTransfer

event GoldPrivilegedTransfer(address indexed from, address indexed to, uint256 amount);

Errors

NotPrivilegedSender

error NotPrivilegedSender(address sender);

NotCharacterError

error NotCharacterError(address sender);

IInvestmentStrategy

Git Source

Functions

invest

function invest(uint256 amount_) external;

claimRewards

function claimRewards() external returns (uint256);

previewRewards

function previewRewards() external view returns (uint256);

withdraw

function withdraw(uint256 amount_) external;

getTotalStaked

function getTotalStaked() external view returns (uint256);

Events

Invested

event Invested(uint256 amount_);

RewardsClaimed

event RewardsClaimed(uint256 amount_);

Withdraw

event Withdraw(uint256 amount_);

Errors

NotBankError

error NotBankError(address sender_);

IItem

Git Source

Inherits: IONFT1155

Functions

burn

function burn(address from, uint256 id) external;

mint

function mint(address to, uint256 id) external;

burnBatch

function burnBatch(address from, uint256[] memory ids, uint256[] memory amounts) external;

mintBatch

function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts) external;

privilegedSafeTransferFrom

function privilegedSafeTransferFrom(address from_, address to_, uint256 id_) external;

Events

ItemBurned

event ItemBurned(address indexed from, uint256 id);

ItemMinted

event ItemMinted(address indexed to, uint256 id);

ItemBatchBurned

event ItemBatchBurned(address indexed from, uint256[] ids, uint256[] amounts);

ItemBatchMinted

event ItemBatchMinted(address indexed to, uint256[] ids, uint256[] amounts);

ItemPrivilegedTransfer

event ItemPrivilegedTransfer(address indexed from, address indexed to, uint256 id);

IMarketplace

Git Source

Functions

placeOrders

function placeOrders(
    uint256[] calldata sellOrdersIds_,
    uint80[] calldata sellOrderPrices_,
    uint16[] calldata buyOrdersIds_,
    uint80[] calldata buyOrderPrices
) external;

fulfilOrders

function fulfilOrders(uint256[] calldata sellOrderIds_, uint256[] calldata buyOrderIds_) external;

cancelOrders

function cancelOrders(uint256[] calldata sellOrderIds_, uint256[] calldata buyOrderIds_) external;

getBuyOrders

function getBuyOrders() external view returns (BuyOrder[] memory);

getSellOrders

function getSellOrders() external view returns (SellOrder[] memory);

Events

SellOrderPlaced

event SellOrderPlaced(address indexed seller, uint16 itemId, uint80 price);

BuyOrderPlaced

event BuyOrderPlaced(address indexed buyer, uint16 itemId, uint80 price);

SellOrderCancelled

event SellOrderCancelled(address indexed seller, uint16 itemId, uint80 price);

BuyOrderCancelled

event BuyOrderCancelled(address indexed buyer, uint16 itemId, uint80 price);

SellOrderFulfilled

event SellOrderFulfilled(address indexed seller, uint16 itemId, uint80 price);

BuyOrderFulfilled

event BuyOrderFulfilled(address indexed buyer, uint16 itemId, uint80 price);

Errors

NoOrdersError

error NoOrdersError();

NotBuyerError

error NotBuyerError(uint256 buyOrderId_);

NotSellerError

error NotSellerError(uint256 sellOrderId_);

SellOrderDoesNotExistError

error SellOrderDoesNotExistError(uint256 sellOrderId_);

BuyOrderDoesNotExistError

error BuyOrderDoesNotExistError(uint256 buyOrderId_);

Structs

SellOrder

struct SellOrder {
    address seller;
    uint16 itemId;
    uint80 price;
}

BuyOrder

struct BuyOrder {
    address buyer;
    uint16 itemId;
    uint80 price;
}

IMilitary

Git Source

Functions

deposit

function deposit(uint256 amount_) external;

join

function join(uint256 charId_) external;

leave

function leave(uint256 charId_) external returns (uint256 rewards_);

leave

function leave(uint256 charId_, address owner_, uint256 charPower_) external;

increasePower

function increasePower(uint256 charId_, address owner_, uint256 oldPower_, uint256 powerChange_) external;

getRewards

function getRewards(uint256 charId_) external returns (uint256 rewards_);

previewRewards

function previewRewards(uint256 charId_) external view returns (uint256);

isCharEnlisted

function isCharEnlisted(uint256 charId_) external view returns (bool);

Events

Deposited

event Deposited(uint256 amount_, uint256 expireTimestamp_);

Joined

event Joined(uint256 indexed charId_, uint256 power_);

Left

event Left(uint256 indexed charId_, uint256 rewards_);

PowerIncreased

event PowerIncreased(uint256 indexed charId_, uint256 powerChange_);

TotalPowerUpdated

event TotalPowerUpdated(uint256 totalPower_);

FirstExpiringDepositUpdated

event FirstExpiringDepositUpdated(uint256 index);

GoldPerPowerofCharUpdated

event GoldPerPowerofCharUpdated(uint256 indexed charId_, uint256 goldPerPower_);

GoldPerPowerUpdated

event GoldPerPowerUpdated(uint256 goldPerPower_);

GoldBurned

event GoldBurned(uint256 amount_);

TotalDepositedUpdated

event TotalDepositedUpdated(uint256 totalDeposited_);

RewardsClaimed

event RewardsClaimed(uint256 indexed charId_, uint256 rewards_);

Errors

NotBankError

error NotBankError(address msgSender_);

NotCharacterError

error NotCharacterError(address msgSender_);

NotCharOwnerError

error NotCharOwnerError(uint256 charId_, address msgSender_);

AlreadyEnlistedError

error AlreadyEnlistedError(uint256 charId_);

Structs

Deposit

struct Deposit {
    uint192 amount;
    uint64 expireTimestamp;
}

CharInfo

struct CharInfo {
    uint224 goldPerPower;
    uint32 power;
}

IPriceFeed

Git Source

Functions

getRate

function getRate(IERC20 srcToken_, IERC20 dstToken_, bool useWrappers_) external view returns (uint256 rate_);

IUSDC

Git Source

Functions

receiveWithAuthorization

function receiveWithAuthorization(
    address from_,
    address to_,
    uint256 value_,
    uint256 validAfter_,
    uint256 validBefore_,
    bytes32 nonce_,
    uint8 v_,
    bytes32 r_,
    bytes32 s_
) external;

transfer

function transfer(address to_, uint256 value_) external;

approve

function approve(address spender_, uint256 value_) external;

balanceOf

function balanceOf(address account_) external view returns (uint256);

AZWorldsGovernor

Git Source

Inherits: Governor, GovernorSettings, GovernorCountingSimple, GovernorVotes, GovernorTimelockControl

Functions

constructor

constructor(IVotes _token, TimelockController _timelock)
    Governor("AZWorldsGovernor")
    GovernorSettings(1, 63, 2)
    GovernorVotes(_token)
    GovernorTimelockControl(_timelock);

quorum

function quorum(uint256) public pure override returns (uint256);

votingDelay

function votingDelay() public view override(IGovernor, GovernorSettings) returns (uint256);

votingPeriod

function votingPeriod() public view override(IGovernor, GovernorSettings) returns (uint256);

state

function state(uint256 proposalId) public view override(Governor, GovernorTimelockControl) returns (ProposalState);

propose

function propose(address[] memory targets, uint256[] memory values, bytes[] memory calldatas, string memory description)
    public
    override(Governor, IGovernor)
    returns (uint256);

proposalThreshold

function proposalThreshold() public view override(Governor, GovernorSettings) returns (uint256);

_execute

function _execute(
    uint256 proposalId,
    address[] memory targets,
    uint256[] memory values,
    bytes[] memory calldatas,
    bytes32 descriptionHash
) internal override(Governor, GovernorTimelockControl);

_cancel

function _cancel(address[] memory targets, uint256[] memory values, bytes[] memory calldatas, bytes32 descriptionHash)
    internal
    override(Governor, GovernorTimelockControl)
    returns (uint256);

_executor

function _executor() internal view override(Governor, GovernorTimelockControl) returns (address);

supportsInterface

function supportsInterface(bytes4 interfaceId) public view override(Governor, GovernorTimelockControl) returns (bool);

Bank

Git Source

Inherits: IBank, ERC4626, Gold

State Variables

totalUsdc

uint256 public totalUsdc;

military

address public military;

investmentStrategy

IInvestmentStrategy public investmentStrategy;

Functions

constructor

constructor(
    address character_,
    address marketplace_,
    address military_,
    address lzEndpoint_,
    IERC20 asset_,
    address game_
) Gold(character_, marketplace_, lzEndpoint_, game_) ERC4626(asset_);

depositAndSendToMilitary

function depositAndSendToMilitary(uint256 assets_) external override;

decimals

function decimals() public pure override(ERC20, ERC4626, IERC20Metadata) returns (uint8);

invest

function invest(uint256 amount_) public override onlyOwner;

withdrawInvestment

function withdrawInvestment(uint256 amount_) external override onlyOwner;

_claimRewards

function _claimRewards() internal returns (uint256 rewards_);

setInvestmentStrategy

function setInvestmentStrategy(IInvestmentStrategy strategy_) external override onlyOwner;

previewRewards

function previewRewards() external view override returns (uint256);

getInvestment

function getInvestment() external view override returns (uint256);

totalAssets

function totalAssets() public view virtual override(ERC4626, IERC4626) returns (uint256);

deposit

function deposit(uint256 assets, address receiver)
    public
    virtual
    override(ERC4626, IERC4626)
    returns (uint256 shares_);

mint

function mint(uint256 shares, address receiver) public virtual override(ERC4626, IERC4626) returns (uint256 assets_);

withdraw

function withdraw(uint256 assets, address receiver, address owner)
    public
    virtual
    override(ERC4626, IERC4626)
    returns (uint256 shares_);

redeem

function redeem(uint256 shares, address receiver, address owner)
    public
    virtual
    override(ERC4626, IERC4626)
    returns (uint256 assets_);

_withdrawInvestmentToAllowWithdrawal

function _withdrawInvestmentToAllowWithdrawal(uint256 assets_) internal;

Boss

Git Source

Inherits: IBoss, VRFV2WrapperConsumerBase

State Variables

ROUND_DURATION

uint256 public immutable ROUND_DURATION;

MAX_ITEM_ID

uint256 public constant MAX_ITEM_ID = 4999;

MAX_NUMBER_SQRT

uint256 public immutable MAX_NUMBER_SQRT;

charInfo

mapping(uint256 => mapping(uint256 => Round)) public charInfo;

roundSeed

mapping(uint256 => uint256) public roundSeed;

lastRoundTimestamp

uint256 public lastRoundTimestamp = block.timestamp;

roundId

uint256 public roundId;

_item

IItem public _item;

_char

IChar public _char;

Functions

constructor

constructor(IItem item_, IChar char_, address link_, address vrfV2Wrapper_, uint256 roundDuration_)
    VRFV2WrapperConsumerBase(link_, vrfV2Wrapper_);

attackBoss

function attackBoss(uint256 charId_) external override;

claimRewards

function claimRewards(uint256 charId_, uint256 roundId_) external override returns (uint256 itemId_);

previewRewards

function previewRewards(uint256 charId_, uint256 roundId_) external view override returns (uint256 itemId_);

nextRound

function nextRound() public override;

fulfillRandomWords

function fulfillRandomWords(uint256, uint256[] memory _randomWords) internal override;

Character

Git Source

Inherits: ICharacter, ERC721Votes, ERC721URIStorage

State Variables

portal

CharacterPortal public immutable portal;

item

IItem public immutable item;

bank

IBank public immutable bank;

military

address public immutable military;

boss

address public immutable boss;

_charInfos

mapping(uint256 => CharInfo) public _charInfos;

Functions

constructor

constructor(IBank bank_, IItem item_, address lzEndpoint_, address military_, address boss_)
    ERC721("Character", "CHAR")
    EIP712("Character", "1");

onlyCharOwner

modifier onlyCharOwner(uint256 charId_);

onlyPortal

modifier onlyPortal();

onlyBoss

modifier onlyBoss();

_mint

function _mint(address to_, uint256 charId_, string memory tokenURI_) internal;

equipItems

function equipItems(uint256 charId_, uint256[] calldata itemIds_) external override onlyCharOwner(charId_);

carryGold

function carryGold(uint256 charId_, uint256 goldAmount_) external override onlyCharOwner(charId_);

dropGold

function dropGold(uint256 charId_, uint256 goldAmount_) external override onlyCharOwner(charId_);

sendFrom

function sendFrom(address from_, uint16 dstChainId_, address toAddress_, uint256 charId_, bytes memory adapterParams_)
    external
    payable
    override;

sendBatchFrom

function sendBatchFrom(
    address from_,
    uint16 dstChainId_,
    address toAddress_,
    uint256[] calldata charIds_,
    bytes memory adapterParams_
) external payable override;

creditTo

function creditTo(address toAddress_, uint256 tokenId_, bytes memory data_) external override onlyPortal;

getCharInfo

function getCharInfo(uint256 charId_) external view override returns (CharInfo memory, address);

supportsInterface

function supportsInterface(bytes4 interfaceId)
    public
    view
    virtual
    override(ERC721, IERC165, ERC721URIStorage)
    returns (bool);

levelUp

function levelUp(uint256 charId_) external override onlyBoss;

_validateCharOwner

function _validateCharOwner(uint256 charId_) internal view;

_deleteCharInfo

function _deleteCharInfo(uint256 charId_) internal;

_afterTokenTransfer

function _afterTokenTransfer(address from, address to, uint256 tokenId, uint256 batchSize)
    internal
    override(ERC721Votes, ERC721);

_burn

function _burn(uint256 tokenId) internal override(ERC721URIStorage, ERC721);

tokenURI

function tokenURI(uint256 tokenId) public view virtual override(ERC721, ERC721URIStorage) returns (string memory);

CharacterPortal

Git Source

Inherits: ICharacterPortal, ONFT721Core

State Variables

_character

Character public immutable _character;

Functions

constructor

constructor(uint256 _minGasToTransferAndStore, address _lzEndpoint, address owner_)
    ONFT721Core(_minGasToTransferAndStore, _lzEndpoint);

send

function send(
    address from_,
    uint16 dstChainId_,
    address toAddress_,
    uint256[] memory tokenIds_,
    address payable refundAddress_,
    bytes[] memory data_,
    bytes memory adapterParams_
) external payable override;

_creditTo

function _creditTo(uint16, address _toAddress, uint256 _tokenId, bytes memory _data) internal virtual override;

CharacterSale

Git Source

Inherits: ICharacterSale, LinearVRGDA, Character, Ownable

State Variables

usdc

address public immutable usdc;

chainId

uint256 public immutable chainId;

nrChains

uint256 public immutable nrChains;

totalSold

uint256 public totalSold;

startTime

uint256 public immutable startTime = block.timestamp;

gameController

address public gameController;

gameControllerFeePercentage

uint256 public gameControllerFeePercentage;

Functions

constructor

constructor(
    IBank bank_,
    IItem item_,
    address military_,
    address boss_,
    address lzEndpoint_,
    address usdc_,
    uint8 chainId_,
    uint8 nrChains_,
    uint8 gameControllerFeePercentage_
) Character(bank_, item_, lzEndpoint_, military_, boss_) LinearVRGDA(10e18, 0.31e18, 10e18);

buy

function buy(
    address from_,
    uint256 usdcSent_,
    uint256 validAfter_,
    uint256 validBefore_,
    bytes32 nonce_,
    Signature calldata signature_,
    string memory tokenURI_
) external override returns (uint256 mintedId_);

changeGameController

function changeGameController(address gameController_) external override onlyOwner;

changeGameControllerFeePercentage

function changeGameControllerFeePercentage(uint256 gameControllerFeePercentage_) external override onlyOwner;

sendUsdcToBankAndGameController

function sendUsdcToBankAndGameController() public override;

getPrice

function getPrice() external view override returns (uint256 price_);

Gold

Git Source

Inherits: OFT, IGold

State Variables

character

address public immutable character;

marketplace

address public immutable marketplace;

game

address public immutable game;

Functions

constructor

constructor(address character_, address marketPlace_, address lzEndpoint_, address game_)
    OFT("Gold", "GOLD", lzEndpoint_);

privilegedTransferFrom

function privilegedTransferFrom(address from_, address to_, uint256 amount_) external override;

burn

function burn(address account_, uint256 amount_) external override;

mint

function mint(address account_, uint256 amount_) external override;

_validateSender

function _validateSender() internal view;

_onlyCharacter

function _onlyCharacter() internal view;

InvestmentStrategy

Git Source

Inherits: IInvestmentStrategy

State Variables

bank

Bank public bank;

Functions

onlyBank

modifier onlyBank();

constructor

constructor(Bank bank_);

invest

function invest(uint256 amount_) external virtual override onlyBank;

claimRewards

function claimRewards() external virtual override onlyBank returns (uint256);

previewRewards

function previewRewards() external view virtual override returns (uint256);

withdraw

function withdraw(uint256 amount_) external virtual override onlyBank;

getTotalStaked

function getTotalStaked() external view virtual override returns (uint256);

_onlyBank

function _onlyBank() internal view;

Item

Git Source

Inherits: IItem, ONFT1155

State Variables

_character

address public immutable _character;

_marketplace

address public immutable _marketplace;

_boss

address public immutable _boss;

Functions

constructor

constructor(address character_, address marketplace_, address boss_, address lzEndpoint_)
    ONFT1155("Item", lzEndpoint_);

burn

function burn(address from, uint256 id) external override;

mint

function mint(address to, uint256 id) external override;

burnBatch

function burnBatch(address from, uint256[] memory ids, uint256[] memory amounts) external override;

mintBatch

function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts) external override;

privilegedSafeTransferFrom

function privilegedSafeTransferFrom(address from_, address to_, uint256 id_) external override;

_validateSender

function _validateSender() internal view;

Errors

NotValidSender

error NotValidSender(address sender);

Marketplace

Git Source

Inherits: IMarketplace

State Variables

_buyOrders

BuyOrder[] private _buyOrders;

_sellOrders

SellOrder[] private _sellOrders;

_item

IItem private immutable _item;

_gold

IGold private immutable _gold;

Functions

constructor

constructor(IItem item_, IGold gold_);

placeOrders

function placeOrders(
    uint256[] calldata sellOrdersIds_,
    uint80[] calldata sellOrderPrices_,
    uint16[] calldata buyOrdersIds_,
    uint80[] calldata buyOrderPrices_
) external override;

fulfilOrders

function fulfilOrders(uint256[] calldata sellOrderIds_, uint256[] calldata buyOrderIds_) external override;

cancelOrders

function cancelOrders(uint256[] calldata sellOrderIds_, uint256[] calldata buyOrderIds_) external override;

getBuyOrders

function getBuyOrders() external view override returns (BuyOrder[] memory);

getSellOrders

function getSellOrders() external view override returns (SellOrder[] memory);

Military

Git Source

Inherits: IMilitary

State Variables

PRECISION

uint256 public constant PRECISION = 1e18;

_char

IChar public immutable _char;

_bank

address public immutable _bank;

_totalPower

uint256 public _totalPower;

_lastUpdate

uint256 public _lastUpdate;

_goldPerPower

uint256 public _goldPerPower = 1;

_firstExpiringDeposit

uint256 public _firstExpiringDeposit;

_totalDeposited

uint256 public _totalDeposited;

_goldPerPowerByCharId

mapping(uint256 => uint256) public _goldPerPowerByCharId;

_deposits

Deposit[] public _deposits;

Functions

onlyCharacter

modifier onlyCharacter();

constructor

constructor(IChar character_, address bank_);

deposit

function deposit(uint256 amount_) external override;

join

function join(uint256 charId_) external override;

leave

function leave(uint256 charId_) external override returns (uint256);

leave

function leave(uint256 charId_, address owner_, uint256 charPower_) external override onlyCharacter;

increasePower

function increasePower(uint256 charId_, address owner_, uint256 oldPower_, uint256 powerIncrease_)
    external
    override
    onlyCharacter;

getRewards

function getRewards(uint256 charId_) external override returns (uint256 rewards_);

previewRewards

function previewRewards(uint256 charId_) external view override returns (uint256);

isCharEnlisted

function isCharEnlisted(uint256 charId_) public view override returns (bool);

_leave

function _leave(uint256 charId_, address owner_, uint256 charPower_) internal returns (uint256 rewards_);

_validateCharOwner

function _validateCharOwner(uint256 charId_, address owner_) internal view;

_onlyCharacter

function _onlyCharacter() internal view;

_checkExpiredDeposits

function _checkExpiredDeposits()
    internal
    view
    returns (
        uint256 totalDeposited_,
        uint256 firstExpiringDeposit_,
        uint256 goldPerPower_,
        uint256 lastUpdate_,
        uint256 goldToburn_
    );

_updateExpiredDeposits

function _updateExpiredDeposits() internal returns (uint256 goldPerPower_);

UpVsDownGameV2

Git Source

Inherits: Ownable

State Variables

GAME_DURATION

int32 public GAME_DURATION = 30;

gameController

address public gameController;

pools

mapping(bytes => Round) public pools;

feePercentage

uint256 public feePercentage = 5;

isRunning

bool public isRunning;

notRunningReason

bytes public notRunningReason;

gold

IGold public immutable gold;

priceFeed

IPriceFeed public immutable priceFeed;

WBTC

IERC20 public immutable WBTC;

usdc

IERC20 public immutable usdc;

lostGold

mapping(address => uint256) public lostGold;

Functions

onlyGameController

modifier onlyGameController();

onlyOpenPool

modifier onlyOpenPool(bytes calldata poolId);

onlyGameRunning

modifier onlyGameRunning();

onlyPoolExists

modifier onlyPoolExists(bytes calldata poolId);

constructor

constructor(IGold gold_, IPriceFeed oneInchPriceFeed_, IERC20 WBTC_, IERC20 usdc_);

changeGameDuration

function changeGameDuration(int32 newGameDuration) public onlyOwner;

changeGameControllerAddress

function changeGameControllerAddress(address newGameController) public onlyOwner;

changeGameFeePercentage

function changeGameFeePercentage(uint256 newFeePercentage) public onlyOwner;

stopGame

function stopGame(bytes calldata reason) public onlyOwner;

startGame

function startGame() public onlyOwner;

createPool

function createPool(bytes calldata poolId, uint256 minBetAmount, uint256 maxBetAmount, uint256 poolBetsLimit)
    public
    onlyGameController;

trigger

function trigger(bytes calldata poolId, uint32 batchSize, uint256 price) public onlyPoolExists(poolId);

returnBets

function returnBets(bytes calldata poolId, BetGroup storage group, uint32 batchSize) private;

distribute

function distribute(bytes calldata poolId, uint32 batchSize) public onlyPoolExists(poolId);

calculateDistribution

function calculateDistribution(BetGroup storage winners, BetGroup storage losers)
    private
    view
    returns (Distribution memory);

clearPool

function clearPool(bytes calldata poolId) private;

hasPendingDistributions

function hasPendingDistributions(bytes calldata poolId) public view returns (bool);

isPoolOpen

function isPoolOpen(bytes calldata poolId) public view returns (bool);

addBet

function addBet(BetGroup storage betGroup, uint256 amount, string calldata avatar, string calldata countryCode)
    private
    returns (uint256);

makeTrade

function makeTrade(makeTradeStruct calldata userTrade)
    public
    payable
    onlyOpenPool(userTrade.poolId)
    onlyGameRunning
    onlyPoolExists(userTrade.poolId);

claimLostGold

function claimLostGold() external;

sendGold

function sendGold(address to, uint256 amount) private returns (bool success);

Events

RoundStarted

event RoundStarted(
    bytes poolId,
    int64 timestamp,
    int32 price,
    uint256 minTradeAmount,
    uint256 maxTradeAmount,
    uint256 poolTradesLimit,
    bytes indexed indexedPoolId
);

RoundEnded

event RoundEnded(bytes poolId, int64 timestamp, int32 startPrice, int32 endPrice, bytes indexed indexedPoolId);

TradePlaced

event TradePlaced(
    bytes poolId,
    address sender,
    uint256 amount,
    string prediction,
    uint256 newTotal,
    bytes indexed indexedPoolId,
    address indexed indexedSender,
    string avatarUrl,
    string countryCode,
    int64 roundStartTime
);

TradeReturned

event TradeReturned(bytes poolId, address sender, uint256 amount);

GameStopped

event GameStopped(bytes reason);

GameStarted

event GameStarted();

RoundDistributed

event RoundDistributed(bytes poolId, uint256 totalWinners, uint256 from, uint256 to, int64 timestamp);

TradeWinningsSent

event TradeWinningsSent(
    bytes poolId, address sender, uint256 tradeAmount, uint256 winningsAmount, address indexed indexedSender
);

Errors

PendingDistributions

error PendingDistributions();

Structs

BetGroup

struct BetGroup {
    uint256[] bets;
    address[] addresses;
    string[] avatars;
    string[] countries;
    uint256 total;
    uint256 distributedCount;
    uint256 totalDistributed;
}

Round

struct Round {
    bool created;
    int32 startPrice;
    int32 endPrice;
    uint256 minBetAmount;
    uint256 maxBetAmount;
    uint256 poolBetsLimit;
    BetGroup upBetGroup;
    BetGroup downBetGroup;
    int64 roundStartTime;
}

Distribution

struct Distribution {
    uint256 fee;
    uint256 totalMinusFee;
    uint256 pending;
}

makeTradeStruct

struct makeTradeStruct {
    bytes poolId;
    string avatarUrl;
    string countryCode;
    bool upOrDown;
    uint256 goldBet;
}