// SPDX-License-Identifier: LicenseRef-Blockwell-Smart-License/*
__ _
/ / ___ ____ _____(_)________ ____
/ / / _ \/ __ \/ ___/ / ___/ __ \/ __ \
/ /___/ __/ /_/ / / / / /__/ /_/ / / / /
/_____/\___/ .___/_/ /_/\___/\____/_/ /_/
/_/
L3P was born on 17th March, 2021. You can relive its first day by using this link:
https://youtu.be/uvC-dGaUD_I
Lepricon is a player-owned and governed hyper-casual gaming platform with
elements of DeFi powered by its utility token, L3P, itself controlled by this
very contract.
We created L3P because we believe in the inevitable merging of the gaming and
blockchain industries, where game economies and currencies are owned and run
by the players who play them. Check back in 2030, and you will see we were
right.
Josh Galloway - Stephen Browne - Phil Ingram
*/pragmasolidity ^0.6.10;import"./_PrimeToken.sol";
/**
* @dev Extended constructor for added user groups and deployment fees.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/contractPrimeDeployableisPrimeToken{
constructor(stringmemory _name,
stringmemory _symbol,
uint8 _decimals,
uint256 _totalSupply,
address owner,
address bwAdmin,
address feeAccount,
uint256 feePercentageTenths,
address attorney,
stringmemory _attorneyEmail
) publicPrimeToken(_name, _symbol, _decimals, _totalSupply) {
_addBwAdmin(bwAdmin);
_addAdmin(owner);
if (attorney !=address(0x0)) {
_addAttorney(attorney);
}
attorneyEmail = _attorneyEmail;
// Percentage should be in tenths, so 1% would be 10if (feePercentageTenths >0) {
uint256 fee = totalTokenSupply.mul(feePercentageTenths).div(1000);
balances[owner] = totalTokenSupply.sub(fee);
emit Transfer(address(0), owner, balances[owner]);
balances[feeAccount] = fee;
emit Transfer(address(0), feeAccount, fee);
} else {
balances[owner] = totalTokenSupply;
emit Transfer(address(0), owner, totalTokenSupply);
}
}
functioninit(address) internaloverride{
// Skip the original init function
}
}
Contract Source Code
File 2 of 10: _BlockwellQuill.sol
// SPDX-License-Identifier: LicenseRef-Blockwell-Smart-Licensepragmasolidity ^0.6.10;/**
* @dev Blockwell Quill, storing arbitrary data associated with accounts.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/libraryBlockwellQuill{
structData {
mapping(address=>bytes) data;
}
/**
* @dev Set data on the account.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functionset(
Data storage data,
address account,
bytesmemory value
) internal{
require(account !=address(0));
data.data[account] = value;
}
/**
* @dev Get data on the account.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functionget(Data storage data, address account) internalviewreturns (bytesmemory) {
require(account !=address(0));
return data.data[account];
}
/**
* @dev Convert and set string data on the account.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functionsetString(
Data storage data,
address account,
stringmemory value
) internal{
data.data[address(account)] =bytes(value);
}
/**
* @dev Get and convert string data on the account.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functiongetString(Data storage data, address account) internalviewreturns (stringmemory) {
returnstring(data.data[address(account)]);
}
/**
* @dev Convert and set uint256 data on the account.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functionsetUint256(
Data storage data,
address account,
uint256 value
) internal{
data.data[address(account)] =abi.encodePacked(value);
}
/**
* @dev Get and convert uint256 data on the account.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functiongetUint256(Data storage data, address account) internalviewreturns (uint256) {
uint256 ret;
bytesmemory source = data.data[address(account)];
assembly {
ret :=mload(add(source, 32))
}
return ret;
}
/**
* @dev Convert and set address data on the account.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functionsetAddress(
Data storage data,
address account,
address value
) internal{
data.data[address(account)] =abi.encodePacked(value);
}
/**
* @dev Get and convert address data on the account.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functiongetAddress(Data storage data, address account) internalviewreturns (address) {
address ret;
bytesmemory source = data.data[address(account)];
assembly {
ret :=mload(add(source, 20))
}
return ret;
}
}
Contract Source Code
File 3 of 10: _Groups.sol
// SPDX-License-Identifier: LicenseRef-Blockwell-Smart-Licensepragmasolidity ^0.6.10;/**
* @dev Unified system for arbitrary user groups.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/libraryGroups{
structMemberMap {
mapping(address=>bool) members;
}
structGroupMap {
mapping(uint8=> MemberMap) groups;
}
/**
* @dev Add an account to a group
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functionadd(
GroupMap storage map,
uint8 groupId,
address account
) internal{
MemberMap storage group = map.groups[groupId];
require(account !=address(0));
require(!groupContains(group, account));
group.members[account] =true;
}
/**
* @dev Remove an account from a group
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functionremove(
GroupMap storage map,
uint8 groupId,
address account
) internal{
MemberMap storage group = map.groups[groupId];
require(account !=address(0));
require(groupContains(group, account));
group.members[account] =false;
}
/**
* @dev Returns true if the account is in the group
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
* @return bool
*/functioncontains(
GroupMap storage map,
uint8 groupId,
address account
) internalviewreturns (bool) {
MemberMap storage group = map.groups[groupId];
return groupContains(group, account);
}
functiongroupContains(MemberMap storage group, address account) internalviewreturns (bool) {
require(account !=address(0));
return group.members[account];
}
}
Contract Source Code
File 4 of 10: _Pausable.sol
// SPDX-License-Identifier: LicenseRef-Blockwell-Smart-Licensepragmasolidity ^0.6.10;/**
* @dev Pausing logic that includes whether the pause was initiated by an attorney.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/contractPausable{
structPauseState {
bool paused;
bool pausedByAttorney;
}
PauseState private pauseState;
eventPaused(address account, bool attorney);
eventUnpaused(address account);
constructor() internal{
pauseState = PauseState(false, false);
}
modifierwhenNotPaused() {
require(!pauseState.paused);
_;
}
modifierwhenPaused() {
require(pauseState.paused);
_;
}
functionpaused() publicviewreturns (bool) {
return pauseState.paused;
}
/**
* @dev Check if the pause was initiated by an attorney.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functionpausedByAttorney() publicviewreturns (bool) {
return pauseState.paused && pauseState.pausedByAttorney;
}
/**
* @dev Internal logic for pausing the contract.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/function_pause(bool attorney) internal{
pauseState.paused =true;
pauseState.pausedByAttorney = attorney;
emit Paused(msg.sender, attorney);
}
/**
* @dev Internal logic for unpausing the contract.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/function_unpause() internal{
pauseState.paused =false;
pauseState.pausedByAttorney =false;
emit Unpaused(msg.sender);
}
}
Contract Source Code
File 5 of 10: _PrimeToken.sol
// SPDX-License-Identifier: LicenseRef-Blockwell-Smart-Licensepragmasolidity ^0.6.10;import"./_TokenGroups.sol";
import"./__SafeMath.sol";
import"./_Voting.sol";
import"./__Erc20.sol";
import"./_BlockwellQuill.sol";
import"./_Type.sol";
/**
* Blockwell Prime Token
*/contractPrimeTokenisErc20, TokenGroups, Type, Voting{
usingSafeMathforuint256;
usingBlockwellQuillforBlockwellQuill.Data;
/**
* @dev Stores data for individual token locks used by transferAndLock.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/structLock {
uint256 value;
uint64 expiration;
uint32 periodLength;
uint16 periods;
}
mapping(address=>uint256) internal balances;
mapping(address=>mapping(address=>uint256)) private allowed;
mapping(address=> Lock[]) locks;
stringpublic name;
stringpublic symbol;
uint8public decimals;
uint256public unlockTime;
uint256public transferLockTime;
stringpublic attorneyEmail;
uint256internal totalTokenSupply;
uint256public swapNonce;
boolpublic suggestionsRestricted =false;
boolpublic requireBalanceForVote =false;
boolpublic requireBalanceForCreateSuggestion =false;
uint256public voteCost;
BlockwellQuill.Data bwQuill1;
BlockwellQuill.Data bwAddress1;
eventSetNewUnlockTime(uint256 unlockTime);
eventMultiTransferPrevented(addressindexedfrom, addressindexed to, uint256 value);
eventLocked(addressindexed owner,
uint256 value,
uint64 expiration,
uint32 periodLength,
uint16 periodCount
);
eventUnlocked(addressindexed owner, uint256 value, uint16 periodsLeft);
eventSwapToChain(string toChain,
addressindexedfrom,
addressindexed to,
bytes32indexed swapId,
uint256 value
);
eventSwapFromChain(string fromChain,
addressindexedfrom,
addressindexed to,
bytes32indexed swapId,
uint256 value
);
eventBwQuillSet(uint8indexed index, addressindexed account, string value);
eventBwAddressSet(uint8indexed index, addressindexed account, address value);
eventPayment(addressindexedfrom, addressindexed to, uint256 value, uint256 order);
constructor(stringmemory _name,
stringmemory _symbol,
uint8 _decimals,
uint256 _totalSupply
) public{
require(_totalSupply >0);
name = _name;
symbol = _symbol;
decimals = _decimals;
totalTokenSupply = _totalSupply;
init(msg.sender);
bwtype = PRIME;
bwver =45;
}
functioninit(address sender) internalvirtual{
_addBwAdmin(sender);
_addAdmin(sender);
balances[sender] = totalTokenSupply;
emit Transfer(address(0), sender, totalTokenSupply);
}
/**
* @dev Allow only when the contract is unlocked, or if the sender is an admin, an attorney, or whitelisted.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/modifierwhenUnlocked() {
require(
now> unlockTime || isAdmin(msg.sender) || isAttorney(msg.sender) || isWhitelisted(msg.sender)
);
_;
}
/**
* @dev Set a quill 1 value for an account.
*
* dapp https://app.blockwell.ai/125sz0
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functionsetBwQuill1(address account, stringmemory value) publiconlyAdminOrAttorney{
bwQuill1.setString(account, value);
emit BwQuillSet(1, account, value);
}
/**
* @dev Get a quill 1 value for any account.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functiongetBwQuill1(address account) publicviewreturns (stringmemory) {
return bwQuill1.getString(account);
}
/**
* @dev Set quill address 1 value for an account.
*
* dapp https://app.blockwell.ai/7rvk5o
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functionsetBwAddress1(address account, address value) publiconlyAdminOrAttorney{
bwAddress1.setAddress(account, value);
emit BwAddressSet(1, account, value);
}
/**
* @dev Get quill address 1 value for any account.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functiongetBwAddress1(address account) publicviewreturns (address) {
return bwAddress1.getAddress(account);
}
/**
* @dev Configure how users can vote.
*
* dapp https://app.blockwell.ai/48ruoc
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functionconfigureVoting(bool restrictSuggestions,
bool balanceForVote,
bool balanceForCreateSuggestion,
uint256 cost,
bool oneVote
) publiconlyAdminOrAttorney{
suggestionsRestricted = restrictSuggestions;
requireBalanceForVote = balanceForVote;
requireBalanceForCreateSuggestion = balanceForCreateSuggestion;
voteCost = cost;
oneVotePerAccount = oneVote;
}
/**
* @dev Update the email address for this token's assigned attorney.
*
* dapp https://app.blockwell.ai/zsrmai
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functionsetAttorneyEmail(stringmemory email) publiconlyAdminOrAttorney{
attorneyEmail = email;
}
/**
* @dev Pause the contract, preventing transfers.
*
* dapp https://app.blockwell.ai/5zdyx7
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functionpause() publicwhenNotPaused{
bool attorney = isAttorney(msg.sender);
require(attorney || isAdmin(msg.sender));
_pause(attorney);
}
/**
* @dev Resume the contract.
*
* If the contract was originally paused by an attorney, only an attorney can resume.
*
* dapp https://app.blockwell.ai/5nwjwj
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functionunpause() publicwhenPaused{
if (!isAttorney(msg.sender)) {
require(isAdmin(msg.sender));
require(!pausedByAttorney());
}
_unpause();
}
/**
* @dev Lock the contract if not already locked until the given time.
*
* dapp https://app.blockwell.ai/d4uchl
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functionsetUnlockTime(uint256 timestamp) publiconlyAdminOrAttorney{
unlockTime = timestamp;
emit SetNewUnlockTime(unlockTime);
}
/**
* @dev Total number of tokens.
*/functiontotalSupply() publicviewoverridereturns (uint256) {
return totalTokenSupply;
}
/**
* @dev Get account balance.
*/functionbalanceOf(address account) publicviewoverridereturns (uint256) {
return balances[account];
}
/**
* @dev Get allowance for an owner-spender pair.
*/functionallowance(address owner, address spender) publicviewoverridereturns (uint256) {
return allowed[owner][spender];
}
/**
* @dev Transfer tokens.
*
* dapp https://app.blockwell.ai/u5v1lq
*/functiontransfer(address to, uint256 value) publicoverridewhenNotPausedwhenUnlockedreturns (bool) {
_transfer(msg.sender, to, value);
returntrue;
}
/**
* @dev Make multiple token transfers with one transaction.
* @param to Array of addresses to transfer to.
* @param value Array of amounts to be transferred.
*
* dapp https://app.blockwell.ai/jzjy5x
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functionmultiTransfer(address[] calldata to, uint256[] calldata value)
publicwhenNotPausedonlyBundlerreturns (bool)
{
require(to.length>0);
require(value.length== to.length);
for (uint256 i =0; i < to.length; i++) {
if (!isFrozen(to[i])) {
_transfer(msg.sender, to[i], value[i]);
} else {
emit MultiTransferPrevented(msg.sender, to[i], value[i]);
}
}
returntrue;
}
/**
* @dev Approve a spender to transfer the given amount of the sender's tokens.
*
* dapp https://app.blockwell.ai/rftj01
*/functionapprove(address spender, uint256 value)
publicoverrideisNotFrozenwhenNotPausedwhenUnlockedreturns (bool)
{
require(spender !=address(0));
allowed[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
returntrue;
}
/**
* @dev Transfer tokens from an account the sender has been approved to send from.
*
* dapp https://app.blockwell.ai/p03b2c
*/functiontransferFrom(addressfrom,
address to,
uint256 value
) publicoverridewhenNotPausedwhenUnlockedreturns (bool) {
allowed[from][msg.sender] = allowed[from][msg.sender].sub(value);
_transfer(from, to, value);
returntrue;
}
/**
* @dev Transfer tokens from one address to multiple others.
* @param from Address to send from.
* @param to Array of addresses to transfer to.
* @param value Array of amounts to be transferred.
*
* dapp https://app.blockwell.ai/mnxpe4
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functionmultiTransferFrom(addressfrom,
address[] calldata to,
uint256[] calldata value
) publicwhenNotPausedonlyBundlerreturns (bool) {
require(to.length>0);
require(value.length== to.length);
for (uint256 i =0; i < to.length; i++) {
if (!isFrozen(to[i])) {
allowed[from][msg.sender] = allowed[from][msg.sender].sub(value[i]);
_transfer(from, to[i], value[i]);
} else {
emit MultiTransferPrevented(from, to[i], value[i]);
}
}
returntrue;
}
/**
* @dev Increase the amount of tokens a spender can transfer from the sender's account.
*
* dapp https://app.blockwell.ai/xr9xi3
*/functionincreaseAllowance(address spender, uint256 addedValue)
publicisNotFrozenwhenNotPausedwhenUnlockedreturns (bool)
{
require(spender !=address(0));
allowed[msg.sender][spender] = allowed[msg.sender][spender].add(addedValue);
emit Approval(msg.sender, spender, allowed[msg.sender][spender]);
returntrue;
}
/**
* @dev Decrease the amount of tokens a spender can transfer from the sender's account.
*
* dapp https://app.blockwell.ai/hnogar
*/functiondecreaseAllowance(address spender, uint256 subtractedValue)
publicisNotFrozenwhenNotPausedwhenUnlockedreturns (bool)
{
require(spender !=address(0));
allowed[msg.sender][spender] = allowed[msg.sender][spender].sub(subtractedValue);
emit Approval(msg.sender, spender, allowed[msg.sender][spender]);
returntrue;
}
/**
* @dev Lists all the locks for the given account as an array, with [value1, expiration1, value2, expiration2, ...]
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functionlocksOf(address account) publicviewreturns (uint256[] memory) {
Lock[] storage userLocks = locks[account];
uint256[] memory lockArray =newuint256[](userLocks.length*4);
for (uint256 i =0; i < userLocks.length; i++) {
uint256 pos =4* i;
lockArray[pos] = userLocks[i].value;
lockArray[pos +1] = userLocks[i].expiration;
lockArray[pos +2] = userLocks[i].periodLength;
lockArray[pos +3] = userLocks[i].periods;
}
return lockArray;
}
/**
* @dev Unlocks all expired locks.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functionunlock() publicreturns (bool) {
Lock[] storage list = locks[msg.sender];
if (list.length==0) {
returntrue;
}
for (uint256 i =0; i < list.length; ) {
Lock storage lock = list[i];
if (lock.expiration <block.timestamp) {
// Less than 2 means it's the last period (1), or periods are not used (0)if (lock.periods <2) {
emit Unlocked(msg.sender, lock.value, 0);
if (i < list.length-1) {
list[i] = list[list.length-1];
}
list.pop();
} else {
uint256 value;
uint256 diff =block.timestamp.sub(lock.expiration);
uint16 periodsPassed =1+uint16(diff.div(lock.periodLength));
if (periodsPassed >= lock.periods) {
periodsPassed = lock.periods;
value = lock.value;
emit Unlocked(msg.sender, value, 0);
if (i < list.length-1) {
list[i] = list[list.length-1];
}
list.pop();
} else {
value = lock.value.div(lock.periods) * periodsPassed;
lock.periods -= periodsPassed;
lock.value= lock.value.sub(value);
lock.expiration =
lock.expiration +uint32(uint256(lock.periodLength).mul(periodsPassed));
emit Unlocked(msg.sender, value, lock.periods);
i++;
}
}
} else {
i++;
}
}
returntrue;
}
/**
* @dev Gets the unlocked balance of the specified address.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functionunlockedBalanceOf(address account) publicviewreturns (uint256) {
return balances[account].sub(totalLocked(account));
}
/**
* @dev Gets the total usable tokens for an account, including tokens that could be unlocked.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functionavailableBalanceOf(address account) externalviewreturns (uint256) {
return balances[account].sub(totalLocked(account)).add(totalUnlockable(account));
}
/**
* @dev Transfers tokens and locks them for lockTime.
*
* dapp https://app.blockwell.ai/x2aiar
* dapp https://app.blockwell.ai/x2tnj5
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functiontransferAndLock(address to,
uint256 value,
uint32 lockTime,
uint32 periodLength,
uint16 periods
) publicreturns (bool) {
uint64 expires =uint64(block.timestamp.add(lockTime));
Lock memory newLock = Lock(value, expires, periodLength, periods);
locks[to].push(newLock);
transfer(to, value);
emit Locked(to, value, expires, periodLength, periods);
returntrue;
}
/**
* @dev Transfer and lock to multiple accounts with a single transaction.
*
* dapp https://app.blockwell.ai/57s696
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functionmultiTransferAndLock(address[] calldata to,
uint256[] calldata value,
uint32 lockTime,
uint32 periodLength,
uint16 periods
) publicwhenNotPausedonlyBundlerreturns (bool) {
require(to.length>0);
require(value.length== to.length);
for (uint256 i =0; i < to.length; i++) {
if (!isFrozen(to[i])) {
transferAndLock(to[i], value[i], lockTime, periodLength, periods);
} else {
emit MultiTransferPrevented(msg.sender, to[i], value[i]);
}
}
returntrue;
}
/**
* @dev Gets the total amount of locked tokens in the given account.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functiontotalLocked(address account) publicviewreturns (uint256) {
uint256 total =0;
for (uint256 i =0; i < locks[account].length; i++) {
total = total.add(locks[account][i].value);
}
return total;
}
/**
* @dev Gets the amount of tokens that can currently be unlocked.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functiontotalUnlockable(address account) publicviewreturns (uint256) {
Lock[] storage userLocks = locks[account];
uint256 total =0;
for (uint256 i =0; i < userLocks.length; i++) {
Lock storage lock = userLocks[i];
if (lock.expiration <block.timestamp) {
if (lock.periods <2) {
total = total.add(lock.value);
} else {
uint256 value;
uint256 diff =block.timestamp.sub(lock.expiration);
uint16 periodsPassed =1+uint16(diff.div(lock.periodLength));
if (periodsPassed > lock.periods) {
periodsPassed = lock.periods;
value = lock.value;
} else {
value = lock.value.div(lock.periods) * periodsPassed;
}
total = total.add(value);
}
}
}
return total;
}
/**
* @dev Withdraw any tokens the contract itself is holding.
*
* dapp https://app.blockwell.ai/0id2my
*/functionwithdrawTokens() publicwhenNotPaused{
require(isAdmin(msg.sender));
_transfer(address(this), msg.sender, balanceOf(address(this)));
}
/**
* @dev Gets an incrementing nonce for generating swap IDs.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functiongetSwapNonce() internalreturns (uint256) {
return++swapNonce;
}
/**
* @dev Initiates a swap to another chain. Transfers the tokens to this contract and emits an event
* indicating the request to swap.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functionswapToChain(stringmemory chain,
address to,
uint256 value
) publicwhenNotPausedwhenUnlocked{
bytes32 swapId =keccak256(abi.encodePacked(getSwapNonce(), msg.sender, to, address(this), chain, value));
_transfer(msg.sender, address(this), value);
emit SwapToChain(chain, msg.sender, to, swapId, value);
}
/**
* @dev Completes a swap from another chain, called by a swapper account.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functionswapFromChain(stringmemory fromChain,
addressfrom,
address to,
bytes32 swapId,
uint256 value
) publicwhenNotPausedonlySwapper{
_transfer(address(this), to, value);
emit SwapFromChain(fromChain, from, to, swapId, value);
}
/**
* @dev Create a new suggestion for voting.
*
* dapp https://app.blockwell.ai/q9mxct
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functioncreateSuggestion(stringmemory text) public{
if (suggestionsRestricted) {
require(isAdmin(msg.sender) || isDelegate(msg.sender));
} elseif (requireBalanceForCreateSuggestion) {
require(balanceOf(msg.sender) >0);
}
_createSuggestion(text);
}
/**
* @dev Vote on a suggestion.
*
* dapp https://app.blockwell.ai/0l98rj
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functionvote(uint256 suggestionId, stringmemory comment) public{
if (requireBalanceForVote) {
require(balanceOf(msg.sender) >0);
}
if (voteCost >0) {
_transfer(msg.sender, address(this), voteCost);
}
_vote(msg.sender, suggestionId, 1, comment);
}
/**
* @dev Cast multiple votes on a suggestion.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functionmultiVote(uint256 suggestionId,
uint256 votes,
stringmemory comment
) public{
require(!oneVotePerAccount);
if (requireBalanceForVote) {
require(balanceOf(msg.sender) >0);
}
if (voteCost >0) {
_transfer(msg.sender, address(this), voteCost.mul(votes));
}
_vote(msg.sender, suggestionId, votes, comment);
}
/**
* @dev Transfer tokens and include an order number for external reference.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functionpayment(address to,
uint256 value,
uint256 order
) publicwhenNotPausedwhenUnlockedreturns (bool) {
_transfer(msg.sender, to, value);
emit Payment(msg.sender, to, value, order);
returntrue;
}
/**
* @dev Base method for transferring tokens.
*/function_transfer(addressfrom,
address to,
uint256 value
) internal{
require(to !=address(0));
require(!isFrozen(from));
require(!isFrozen(to));
unlock();
require(value <= unlockedBalanceOf(from));
balances[from] = balances[from].sub(value);
balances[to] = balances[to].add(value);
emit Transfer(from, to, value);
}
}
// SPDX-License-Identifier: LicenseRef-Blockwell-Smart-Licensepragmasolidity >=0.4.25;/**
* @dev Contract type mapping.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/contractType{
uint256constant PRIME =1;
uint256public bwtype;
uint256public bwver;
}
Contract Source Code
File 8 of 10: _Voting.sol
// SPDX-License-Identifier: LicenseRef-Blockwell-Smart-Licensepragmasolidity ^0.6.10;import"./__SafeMath.sol";
/**
* @dev Suggestions and Voting for token-holders.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/contractVoting{
usingSafeMathforuint256;
structSuggestion {
uint256 votes;
bool created;
address creator;
string text;
}
// This stores how many votes a user has cast on a suggestionmapping(uint256=>mapping(address=>uint256)) private voted;
// This map stores the suggestions, and they're retrieved using their ID numbermapping(uint256=> Suggestion) internal suggestions;
// This keeps track of the number of suggestions in the systemuint256public suggestionCount;
// If true, a wallet can only vote on a suggestion onceboolpublic oneVotePerAccount =true;
eventSuggestionCreated(uint256 suggestionId, string text);
eventVotes(address voter,
uint256indexed suggestionId,
uint256 votes,
uint256 totalVotes,
string comment
);
/**
* @dev Gets the number of votes a suggestion has received.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functiongetVotes(uint256 suggestionId) publicviewreturns (uint256) {
return suggestions[suggestionId].votes;
}
/**
* @dev Gets the number of votes for every suggestion in the contract.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functiongetAllVotes() publicviewreturns (uint256[] memory) {
uint256[] memory votes =newuint256[](suggestionCount);
for (uint256 i =0; i < suggestionCount; i++) {
votes[i] = suggestions[i].votes;
}
return votes;
}
/**
* @dev Gets the text of a suggestion.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functiongetSuggestionText(uint256 suggestionId) publicviewreturns (stringmemory) {
return suggestions[suggestionId].text;
}
/**
* @dev Gets whether or not an account has voted for a suggestion.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functionhasVoted(address account, uint256 suggestionId) publicviewreturns (bool) {
return voted[suggestionId][account] >0;
}
/**
* @dev Gets the number of votes an account has cast towards a suggestion.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functiongetAccountVotes(address account, uint256 suggestionId) publicviewreturns (uint256) {
return voted[suggestionId][account];
}
/**
* @dev Gets the creator of a suggestion.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functiongetSuggestionCreator(uint256 suggestionId) publicviewreturns (address) {
return suggestions[suggestionId].creator;
}
/**
* @dev Gets the creator for every suggestion in the contract.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/functiongetAllSuggestionCreators() publicviewreturns (address[] memory) {
address[] memory creators =newaddress[](suggestionCount);
for (uint256 i =0; i < suggestionCount; i++) {
creators[i] = suggestions[i].creator;
}
return creators;
}
/**
* @dev Internal logic for creating a suggestion.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/function_createSuggestion(stringmemory text) internal{
// The ID is just based on the suggestion count, so the IDs go 0, 1, 2, etc.uint256 suggestionId = suggestionCount++;
// Starts at 0 votes
suggestions[suggestionId] = Suggestion(0, true, msg.sender, text);
emit SuggestionCreated(suggestionId, text);
}
/**
* @dev Internal logic for voting.
*
* Blockwell Exclusive (Intellectual Property that lives on-chain via Smart License)
*/function_vote(address account,
uint256 suggestionId,
uint256 votes,
stringmemory comment
) internalreturns (uint256) {
if (oneVotePerAccount) {
require(!hasVoted(account, suggestionId));
require(votes ==1);
}
Suggestion storage sugg = suggestions[suggestionId];
require(sugg.created);
voted[suggestionId][account] = voted[suggestionId][account].add(votes);
sugg.votes = sugg.votes.add(votes);
emit Votes(account, suggestionId, votes, sugg.votes, comment);
return sugg.votes;
}
}
// SPDX-License-Identifier: MITpragmasolidity ^0.6.10;/**
* @title SafeMath
* @dev Math operations with safety checks that revert on error
*
* Originally from https://github.com/OpenZeppelin/openzeppelin-contracts
* Copyright (c) 2016-2020 zOS Global Limited
*/librarySafeMath{
/**
* @dev Multiplies two numbers, reverts on overflow.
*/functionmul(uint256 a, uint256 b) internalpurereturns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the// benefit is lost if 'b' is also tested.// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522if (a ==0) {
return0;
}
uint256 c = a * b;
require(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers truncating the quotient, reverts on division by zero.
*/functiondiv(uint256 a, uint256 b) internalpurereturns (uint256) {
// Solidity only automatically asserts when dividing by 0require(b >0);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't holdreturn c;
}
/**
* @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/functionsub(uint256 a, uint256 b) internalpurereturns (uint256) {
require(b <= a);
uint256 c = a - b;
return c;
}
/**
* @dev Adds two numbers, reverts on overflow.
*/functionadd(uint256 a, uint256 b) internalpurereturns (uint256) {
uint256 c = a + b;
require(c >= a);
return c;
}
/**
* @dev Divides two numbers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/functionmod(uint256 a, uint256 b) internalpurereturns (uint256) {
require(b !=0);
return a % b;
}
}