@leofcoin/contracts 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/exports/factory.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class
|
|
1
|
+
class ContractCreator{#creator;constructor(state){this.#creator=state?state.contractCreator:msg.sender}get _contractCreator(){return this.#creator}get state(){return{contractCreator:this.#creator}}get _isContractCreator(){return msg.sender===this.#creator}}class Voting extends ContractCreator{#votes={};#votingDisabled=!1;#votingDuration=1728e5;constructor(state){super(state),state&&(this.#votes=state.votes,this.#votingDisabled=state.votingDisabled,this.#votingDuration=state.votingDuration)}get votes(){return{...this.#votes}}get votingDuration(){return this.#votingDuration}get votingDisabled(){return this.#votingDisabled}get state(){return{...super.state,votes:this.#votes,votingDisabled:this.#votingDisabled,votingDuration:this.#votingDuration}}#canVote(){return this._canVote?.()}#beforeVote(){return this._beforeVote?.()}#afterVote(){return this._afterVote?.()}createVote(title,description,endTime,method,args=[]){if(!this.#canVote())throw new Error("Not allowed to create a vote");const id=crypto.randomUUID();this.#votes[id]={title:title,description:description,method:method,endTime:endTime,args:args}}#endVoting(voteId){let agree=Object.values(this.#votes[voteId].results).filter((result=>1===result)),disagree=Object.values(this.#votes[voteId].results).filter((result=>0===result));agree.length>disagree.length&&this.#votes[voteId].enoughVotes&&this[this.#votes[voteId].method](...this.#votes[voteId].args),this.#votes[voteId].finished=!0}async vote(voteId,vote){if(0!==(vote=Number(vote))&&.5!==vote&&1!==vote)throw new Error(`invalid vote value ${vote}`);if(!this.#votes[voteId])throw new Error(`Nothing found for ${voteId}`);const ended=(new Date).getTime()>this.#votes[voteId].endTime;if(ended&&!this.#votes[voteId].finished&&this.#endVoting(voteId),ended)throw new Error("voting already ended");if(!this.#canVote())throw new Error("Not allowed to vote");await this.#beforeVote(),this.#votes[voteId][msg.sender]=vote,await this.#afterVote()}get votesInProgress(){return Object.entries(this.#votes).filter((([id,vote])=>!vote.finished)).map((([id,vote])=>({...vote,id:id})))}#disableVoting(){this.#votingDisabled=!0}disableVoting(){if(!this.#canVote())throw new Error("not a allowed");this.createVote("disable voting","Warning this disables all voting features forever",(new Date).getTime()+this.#votingDuration,"#disableVoting",[])}_sync(){for(const vote of this.votesInProgress)vote.endTime<(new Date).getTime()&&this.#endVoting(vote.id)}}class PublicVoting extends Voting{constructor(state){super(state)}}class TokenReceiver extends PublicVoting{#tokenToReceive;#tokenAmountToReceive;#tokenReceiver;#voteType="transfer";constructor(tokenToReceive,tokenAmountToReceive,burns,state){super(state),state?(this.#tokenReceiver=state.tokenReceiver,this.#tokenToReceive=state.tokenToReceive,this.#tokenAmountToReceive=BigNumber.from(state.tokenAmountToReceive),this.#voteType=state.voteType):(this.#tokenReceiver=msg.contract,this.#tokenToReceive=tokenToReceive,this.#tokenAmountToReceive=BigNumber.from(tokenAmountToReceive),burns&&(this.#voteType="burn"))}get tokenToReceive(){return this.#tokenToReceive}get tokenAmountToReceive(){return this.#tokenAmountToReceive}get tokenReceiver(){return this.#tokenReceiver}get state(){return{...super.state,tokenReceiver:this.#tokenReceiver,tokenToReceive:this.#tokenToReceive,tokenAmountToReceive:this.#tokenAmountToReceive,voteType:this.#voteType}}async#canVote(){return(await msg.staticCall(this.#tokenToReceive,"balanceOf",[msg.sender])).gte(this.#tokenAmountToReceive)}async _canVote(){return this.#canVote()}async#beforeVote(){return"burn"===this.#voteType?msg.staticCall(this.tokenToReceive,"burn",[this.tokenAmountToReceive]):msg.staticCall(this.tokenToReceive,"transfer",[msg.sender,this.tokenReceiver,this.tokenAmountToReceive])}async _beforeVote(){await this.#beforeVote()}async _payTokenToReceive(){return msg.staticCall(this.#tokenToReceive,"transfer",[msg.sender,this.#tokenReceiver,this.#tokenAmountToReceive])}async _burnTokenToReceive(){return msg.staticCall(this.#tokenToReceive,"burn",[this.#tokenAmountToReceive])}async _canPay(){return(await msg.call(this.#tokenToReceive,"balance",[])).gte(this.tokenAmountToReceive)}#changeTokenToReceive(address){this.#tokenToReceive=address}#changeTokenAmountToReceive(amount){this.#tokenAmountToReceive=amount}#changeVoteType(type){this.#voteType=type}#getTokensOut(amount,receiver){return msg.call(this.#tokenReceiver,"transfer",[this.#tokenReceiver,receiver,amount])}async changeVoteType(type){if(!this.#canVote())throw new Error("not a allowed");if("transfer"===this.#voteType&&(await this.#balance()).gt(0))throw new Error("get tokens out first or they be lost forever");this.createVote("change the token amount to receive","set tokenAmountToReceive",(new Date).getTime()+this.votingDuration,"#changeVoteType",[type])}getTokensOut(amount,receiver){if(!this.#canVote())throw new Error("not a allowed");this.createVote("withdraw all tokens",`withdraw all tokens to ${receiver}`,(new Date).getTime()+this.votingDuration,"#getTokensOut",[amount,receiver])}changeTokenAmountToReceive(){if(!this.#canVote())throw new Error("not a allowed");this.createVote("change the token amount to receive","set tokenAmountToReceive",(new Date).getTime()+this.votingDuration,"#changeTokenAmountToReceive",[])}#balance(){return msg.staticCall(this.#tokenToReceive,"balanceOf",[this.#tokenReceiver])}async changeTokenToReceive(){if(!this.#canVote())throw new Error("not a allowed");if(!(await this.#balance()).eq(0)&&"transfer"===this.#voteType)throw new Error("get tokens out first or they be lost forever");this.createVote("change the token to receive","set tokenToReceive to a new address",(new Date).getTime()+this.votingDuration,"#changeTokenToReceive",[])}}class Factory extends TokenReceiver{#name="LeofcoinContractFactory";#totalContracts=BigNumber.from(0);#contracts=[];constructor(tokenToReceive,tokenAmountToReceive,state){super(tokenToReceive,tokenAmountToReceive,!0,state),state&&(this.#contracts=state.contracts,this.#totalContracts=state.totalContracts)}get state(){return{...super.state,totalContracts:this.#totalContracts,contracts:this.#contracts}}get name(){return this.#name}get contracts(){return[...this.#contracts]}get totalContracts(){return this.#totalContracts}isRegistered(address){return this.#contracts.includes(address)}#isCreator(address){return msg.staticCall(address,"_isContractCreator")}async registerContract(address){if(!this._canPay())throw new Error("can't register, balance to low");if(!await this.#isCreator(address))throw new Error("You don't own that contract");if(this.#contracts.includes(address))throw new Error("already registered");await this._payTokenToReceive(),this.#totalContracts.add(1),this.#contracts.push(address)}}export{Factory as default};
|
package/exports/name-service.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class
|
|
1
|
+
class ContractCreator{#creator;constructor(state){this.#creator=state?state.contractCreator:msg.sender}get _contractCreator(){return this.#creator}get state(){return{contractCreator:this.#creator}}get _isContractCreator(){return msg.sender===this.#creator}}class Voting extends ContractCreator{#votes={};#votingDisabled=!1;#votingDuration=1728e5;constructor(state){super(state),state&&(this.#votes=state.votes,this.#votingDisabled=state.votingDisabled,this.#votingDuration=state.votingDuration)}get votes(){return{...this.#votes}}get votingDuration(){return this.#votingDuration}get votingDisabled(){return this.#votingDisabled}get state(){return{...super.state,votes:this.#votes,votingDisabled:this.#votingDisabled,votingDuration:this.#votingDuration}}#canVote(){return this._canVote?.()}#beforeVote(){return this._beforeVote?.()}#afterVote(){return this._afterVote?.()}createVote(title,description,endTime,method,args=[]){if(!this.#canVote())throw new Error("Not allowed to create a vote");const id=crypto.randomUUID();this.#votes[id]={title:title,description:description,method:method,endTime:endTime,args:args}}#endVoting(voteId){let agree=Object.values(this.#votes[voteId].results).filter((result=>1===result)),disagree=Object.values(this.#votes[voteId].results).filter((result=>0===result));agree.length>disagree.length&&this.#votes[voteId].enoughVotes&&this[this.#votes[voteId].method](...this.#votes[voteId].args),this.#votes[voteId].finished=!0}async vote(voteId,vote){if(0!==(vote=Number(vote))&&.5!==vote&&1!==vote)throw new Error(`invalid vote value ${vote}`);if(!this.#votes[voteId])throw new Error(`Nothing found for ${voteId}`);const ended=(new Date).getTime()>this.#votes[voteId].endTime;if(ended&&!this.#votes[voteId].finished&&this.#endVoting(voteId),ended)throw new Error("voting already ended");if(!this.#canVote())throw new Error("Not allowed to vote");await this.#beforeVote(),this.#votes[voteId][msg.sender]=vote,await this.#afterVote()}get votesInProgress(){return Object.entries(this.#votes).filter((([id,vote])=>!vote.finished)).map((([id,vote])=>({...vote,id:id})))}#disableVoting(){this.#votingDisabled=!0}disableVoting(){if(!this.#canVote())throw new Error("not a allowed");this.createVote("disable voting","Warning this disables all voting features forever",(new Date).getTime()+this.#votingDuration,"#disableVoting",[])}_sync(){for(const vote of this.votesInProgress)vote.endTime<(new Date).getTime()&&this.#endVoting(vote.id)}}class PublicVoting extends Voting{constructor(state){super(state)}}class TokenReceiver extends PublicVoting{#tokenToReceive;#tokenAmountToReceive;#tokenReceiver;#voteType="transfer";constructor(tokenToReceive,tokenAmountToReceive,burns,state){super(state),state?(this.#tokenReceiver=state.tokenReceiver,this.#tokenToReceive=state.tokenToReceive,this.#tokenAmountToReceive=BigNumber.from(state.tokenAmountToReceive),this.#voteType=state.voteType):(this.#tokenReceiver=msg.contract,this.#tokenToReceive=tokenToReceive,this.#tokenAmountToReceive=BigNumber.from(tokenAmountToReceive),burns&&(this.#voteType="burn"))}get tokenToReceive(){return this.#tokenToReceive}get tokenAmountToReceive(){return this.#tokenAmountToReceive}get tokenReceiver(){return this.#tokenReceiver}get state(){return{...super.state,tokenReceiver:this.#tokenReceiver,tokenToReceive:this.#tokenToReceive,tokenAmountToReceive:this.#tokenAmountToReceive,voteType:this.#voteType}}async#canVote(){return(await msg.staticCall(this.#tokenToReceive,"balanceOf",[msg.sender])).gte(this.#tokenAmountToReceive)}async _canVote(){return this.#canVote()}async#beforeVote(){return"burn"===this.#voteType?msg.staticCall(this.tokenToReceive,"burn",[this.tokenAmountToReceive]):msg.staticCall(this.tokenToReceive,"transfer",[msg.sender,this.tokenReceiver,this.tokenAmountToReceive])}async _beforeVote(){await this.#beforeVote()}async _payTokenToReceive(){return msg.staticCall(this.#tokenToReceive,"transfer",[msg.sender,this.#tokenReceiver,this.#tokenAmountToReceive])}async _burnTokenToReceive(){return msg.staticCall(this.#tokenToReceive,"burn",[this.#tokenAmountToReceive])}async _canPay(){return(await msg.call(this.#tokenToReceive,"balance",[])).gte(this.tokenAmountToReceive)}#changeTokenToReceive(address){this.#tokenToReceive=address}#changeTokenAmountToReceive(amount){this.#tokenAmountToReceive=amount}#changeVoteType(type){this.#voteType=type}#getTokensOut(amount,receiver){return msg.call(this.#tokenReceiver,"transfer",[this.#tokenReceiver,receiver,amount])}async changeVoteType(type){if(!this.#canVote())throw new Error("not a allowed");if("transfer"===this.#voteType&&(await this.#balance()).gt(0))throw new Error("get tokens out first or they be lost forever");this.createVote("change the token amount to receive","set tokenAmountToReceive",(new Date).getTime()+this.votingDuration,"#changeVoteType",[type])}getTokensOut(amount,receiver){if(!this.#canVote())throw new Error("not a allowed");this.createVote("withdraw all tokens",`withdraw all tokens to ${receiver}`,(new Date).getTime()+this.votingDuration,"#getTokensOut",[amount,receiver])}changeTokenAmountToReceive(){if(!this.#canVote())throw new Error("not a allowed");this.createVote("change the token amount to receive","set tokenAmountToReceive",(new Date).getTime()+this.votingDuration,"#changeTokenAmountToReceive",[])}#balance(){return msg.staticCall(this.#tokenToReceive,"balanceOf",[this.#tokenReceiver])}async changeTokenToReceive(){if(!this.#canVote())throw new Error("not a allowed");if(!(await this.#balance()).eq(0)&&"transfer"===this.#voteType)throw new Error("get tokens out first or they be lost forever");this.createVote("change the token to receive","set tokenToReceive to a new address",(new Date).getTime()+this.votingDuration,"#changeTokenToReceive",[])}}class NameService extends TokenReceiver{#name="LeofcoinNameService";#registry={};get name(){return this.#name}get registry(){return{...this.#registry}}get state(){return{...super.state,registry:this.#registry}}constructor(factoryAddress,tokenToReceive,validatorAddress,tokenAmountToReceive,state){super(tokenToReceive,tokenAmountToReceive,!0,state),state?this.#registry=state.registry:(this.#registry.LeofcoinContractFactory={owner:msg.sender,address:factoryAddress},this.#registry.LeofcoinToken={owner:msg.sender,address:tokenToReceive},this.#registry.LeofcoinValidators={owner:msg.sender,address:validatorAddress})}async purchaseName(name,address){await this._canPay(),await this._payTokenToReceive(),this.#registry[name]={owner:msg.sender,address:address}}lookup(name){return this.#registry[name]}transferOwnership(name,to){if(msg.sender!==this.#registry[name].owner)throw new Error("not allowed");this.#registry[name].owner=to}changeAddress(name,address){if(msg.sender!==this.#registry[name].owner)throw new Error("not allowed");this.#registry[name].address=address}}export{NameService as default};
|
package/exports/native-token.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class ContractCreator{#creator;constructor(state){this.#creator=state?state.contractCreator:msg.sender}get _contractCreator(){return this.#creator}get state(){return{contractCreator:this.#creator}}get _isContractCreator(){return msg.sender===this.#creator}}class Roles extends ContractCreator{#roles={OWNER:[],MINT:[],BURN:[]};constructor(state){if(super(state),state
|
|
1
|
+
class ContractCreator{#creator;constructor(state){this.#creator=state?state.contractCreator:msg.sender}get _contractCreator(){return this.#creator}get state(){return{contractCreator:this.#creator}}get _isContractCreator(){return msg.sender===this.#creator}}class Roles extends ContractCreator{#roles={OWNER:[],MINT:[],BURN:[]};constructor(state){if(super(state),state?.roles){if(!(state.roles instanceof Object))throw new TypeError("expected roles to be an object");this.#roles={...state.roles,...this.#roles}}else this.#grantRole(msg.sender,"OWNER")}get state(){return{...super.state,roles:this.roles}}get roles(){return{...this.#roles}}hasRole(address,role){return!!this.#roles[role]&&this.#roles[role].includes(address)}#grantRole(address,role){if(this.hasRole(address,role))throw new Error(`${role} role already granted for ${address}`);this.#roles[role].push(address)}#revokeRole(address,role){if(!this.hasRole(address,role))throw new Error(`${role} role already revoked for ${address}`);if("OWNER"===role&&1===this.#roles[role].length)throw new Error("atleast one owner is needed!");this.#roles[role].splice(this.#roles[role].indexOf(address))}grantRole(address,role){if(!this.hasRole(address,"OWNER"))throw new Error("Not allowed");this.#grantRole(address,role)}revokeRole(address,role){if(!this.hasRole(address,"OWNER"))throw new Error("Not allowed");this.#revokeRole(address,role)}}class Token extends Roles{#name;#symbol;#holders=BigNumber.from(0);#balances={};#approvals={};#decimals=18;#totalSupply=BigNumber.from(0);constructor(name,symbol,decimals=18,state){if(!name)throw new Error("name undefined");if(!symbol)throw new Error("symbol undefined");super(state),state?(this.#balances=(balances=>{const _balances={};for(const address in balances)_balances[address]=BigNumber.from(balances[address]);return _balances})(state.balances),this.#approvals=(approvals=>{const _approvals={};for(const owner in approvals){_approvals[owner]={};for(const operator in approvals[owner])_approvals[owner][operator]=BigNumber.from(approvals[owner][operator])}return _approvals})(state.approvals),this.#holders=BigNumber.from(state.holders),this.#totalSupply=BigNumber.from(state.totalSupply)):(this.#name=name,this.#symbol=symbol,this.#decimals=decimals)}get state(){return{...super.state,holders:this.holders,balances:this.balances,approvals:{...this.#approvals},totalSupply:this.totalSupply}}get totalSupply(){return this.#totalSupply}get name(){return this.#name}get symbol(){return this.#symbol}get holders(){return this.#holders}get balances(){return{...this.#balances}}get approvals(){return this.#approvals}get decimals(){return this.#decimals}mint(to,amount){if(!this.hasRole(msg.sender,"MINT"))throw new Error("not allowed");this.#totalSupply=this.#totalSupply.add(amount),this.#increaseBalance(to,amount)}burn(from,amount){if(!this.hasRole(msg.sender,"BURN"))throw new Error("not allowed");this.#totalSupply=this.#totalSupply.sub(amount),this.#decreaseBalance(from,amount)}#beforeTransfer(from,to,amount){if(!this.#balances[from]||this.#balances[from]<amount)throw new Error("amount exceeds balance")}#updateHolders(address,previousBalance){"0x00"===this.#balances[address].toHexString()?this.#holders.sub(1):"0x00"!==this.#balances[address].toHexString()&&"0x00"===previousBalance.toHexString()&&this.#holders.add(1)}#increaseBalance(address,amount){this.#balances[address]||(this.#balances[address]=BigNumber.from(0));const previousBalance=this.#balances[address];this.#balances[address]=this.#balances[address].add(amount),this.#updateHolders(address,previousBalance)}#decreaseBalance(address,amount){const previousBalance=this.#balances[address];this.#balances[address]=this.#balances[address].sub(amount),this.#updateHolders(address,previousBalance)}balance(){return this.#balances[msg.sender]}balanceOf(address){return this.#balances[address]}setApproval(operator,amount){const owner=msg.sender;this.#approvals[owner]||(this.#approvals[owner]={}),this.#approvals[owner][operator]=BigNumber.from(amount)}approved(owner,operator,amount){return this.#approvals[owner][operator]===amount}transfer(from,to,amount){amount=BigNumber.from(amount),this.#beforeTransfer(from,to,amount),this.#decreaseBalance(from,amount),this.#increaseBalance(to,amount)}}class Leofcoin extends Token{constructor(state){super("Leofcoin","LFC",18,state)}}export{Leofcoin as default};
|
package/exports/power-token.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class ContractCreator{#creator;constructor(state){this.#creator=state?state.contractCreator:msg.sender}get _contractCreator(){return this.#creator}get state(){return{contractCreator:this.#creator}}get _isContractCreator(){return msg.sender===this.#creator}}class Roles extends ContractCreator{#roles={OWNER:[],MINT:[],BURN:[]};constructor(state){if(super(state),state
|
|
1
|
+
class ContractCreator{#creator;constructor(state){this.#creator=state?state.contractCreator:msg.sender}get _contractCreator(){return this.#creator}get state(){return{contractCreator:this.#creator}}get _isContractCreator(){return msg.sender===this.#creator}}class Roles extends ContractCreator{#roles={OWNER:[],MINT:[],BURN:[]};constructor(state){if(super(state),state?.roles){if(!(state.roles instanceof Object))throw new TypeError("expected roles to be an object");this.#roles={...state.roles,...this.#roles}}else this.#grantRole(msg.sender,"OWNER")}get state(){return{...super.state,roles:this.roles}}get roles(){return{...this.#roles}}hasRole(address,role){return!!this.#roles[role]&&this.#roles[role].includes(address)}#grantRole(address,role){if(this.hasRole(address,role))throw new Error(`${role} role already granted for ${address}`);this.#roles[role].push(address)}#revokeRole(address,role){if(!this.hasRole(address,role))throw new Error(`${role} role already revoked for ${address}`);if("OWNER"===role&&1===this.#roles[role].length)throw new Error("atleast one owner is needed!");this.#roles[role].splice(this.#roles[role].indexOf(address))}grantRole(address,role){if(!this.hasRole(address,"OWNER"))throw new Error("Not allowed");this.#grantRole(address,role)}revokeRole(address,role){if(!this.hasRole(address,"OWNER"))throw new Error("Not allowed");this.#revokeRole(address,role)}}class Token extends Roles{#name;#symbol;#holders=BigNumber.from(0);#balances={};#approvals={};#decimals=18;#totalSupply=BigNumber.from(0);constructor(name,symbol,decimals=18,state){if(!name)throw new Error("name undefined");if(!symbol)throw new Error("symbol undefined");super(state),state?(this.#balances=(balances=>{const _balances={};for(const address in balances)_balances[address]=BigNumber.from(balances[address]);return _balances})(state.balances),this.#approvals=(approvals=>{const _approvals={};for(const owner in approvals){_approvals[owner]={};for(const operator in approvals[owner])_approvals[owner][operator]=BigNumber.from(approvals[owner][operator])}return _approvals})(state.approvals),this.#holders=BigNumber.from(state.holders),this.#totalSupply=BigNumber.from(state.totalSupply)):(this.#name=name,this.#symbol=symbol,this.#decimals=decimals)}get state(){return{...super.state,holders:this.holders,balances:this.balances,approvals:{...this.#approvals},totalSupply:this.totalSupply}}get totalSupply(){return this.#totalSupply}get name(){return this.#name}get symbol(){return this.#symbol}get holders(){return this.#holders}get balances(){return{...this.#balances}}get approvals(){return this.#approvals}get decimals(){return this.#decimals}mint(to,amount){if(!this.hasRole(msg.sender,"MINT"))throw new Error("not allowed");this.#totalSupply=this.#totalSupply.add(amount),this.#increaseBalance(to,amount)}burn(from,amount){if(!this.hasRole(msg.sender,"BURN"))throw new Error("not allowed");this.#totalSupply=this.#totalSupply.sub(amount),this.#decreaseBalance(from,amount)}#beforeTransfer(from,to,amount){if(!this.#balances[from]||this.#balances[from]<amount)throw new Error("amount exceeds balance")}#updateHolders(address,previousBalance){"0x00"===this.#balances[address].toHexString()?this.#holders.sub(1):"0x00"!==this.#balances[address].toHexString()&&"0x00"===previousBalance.toHexString()&&this.#holders.add(1)}#increaseBalance(address,amount){this.#balances[address]||(this.#balances[address]=BigNumber.from(0));const previousBalance=this.#balances[address];this.#balances[address]=this.#balances[address].add(amount),this.#updateHolders(address,previousBalance)}#decreaseBalance(address,amount){const previousBalance=this.#balances[address];this.#balances[address]=this.#balances[address].sub(amount),this.#updateHolders(address,previousBalance)}balance(){return this.#balances[msg.sender]}balanceOf(address){return this.#balances[address]}setApproval(operator,amount){const owner=msg.sender;this.#approvals[owner]||(this.#approvals[owner]={}),this.#approvals[owner][operator]=BigNumber.from(amount)}approved(owner,operator,amount){return this.#approvals[owner][operator]===amount}transfer(from,to,amount){amount=BigNumber.from(amount),this.#beforeTransfer(from,to,amount),this.#decreaseBalance(from,amount),this.#increaseBalance(to,amount)}}class Power extends Token{constructor(state){super("Power","PWR",18,state)}}export{Power as default};
|
package/exports/validators.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class ContractCreator{#creator;constructor(state){this.#creator=state?state.contractCreator:msg.sender}get _contractCreator(){return this.#creator}get state(){return{contractCreator:this.#creator}}get _isContractCreator(){return msg.sender===this.#creator}}class Roles extends ContractCreator{#roles={OWNER:[],MINT:[],BURN:[]};constructor(state){if(super(state),state
|
|
1
|
+
class ContractCreator{#creator;constructor(state){this.#creator=state?state.contractCreator:msg.sender}get _contractCreator(){return this.#creator}get state(){return{contractCreator:this.#creator}}get _isContractCreator(){return msg.sender===this.#creator}}class Roles extends ContractCreator{#roles={OWNER:[],MINT:[],BURN:[]};constructor(state){if(super(state),state?.roles){if(!(state.roles instanceof Object))throw new TypeError("expected roles to be an object");this.#roles={...state.roles,...this.#roles}}else this.#grantRole(msg.sender,"OWNER")}get state(){return{...super.state,roles:this.roles}}get roles(){return{...this.#roles}}hasRole(address,role){return!!this.#roles[role]&&this.#roles[role].includes(address)}#grantRole(address,role){if(this.hasRole(address,role))throw new Error(`${role} role already granted for ${address}`);this.#roles[role].push(address)}#revokeRole(address,role){if(!this.hasRole(address,role))throw new Error(`${role} role already revoked for ${address}`);if("OWNER"===role&&1===this.#roles[role].length)throw new Error("atleast one owner is needed!");this.#roles[role].splice(this.#roles[role].indexOf(address))}grantRole(address,role){if(!this.hasRole(address,"OWNER"))throw new Error("Not allowed");this.#grantRole(address,role)}revokeRole(address,role){if(!this.hasRole(address,"OWNER"))throw new Error("Not allowed");this.#revokeRole(address,role)}}class Validators extends Roles{#name="LeofcoinValidators";#validators=[];#currency;#minimumBalance;get state(){return{...super.state,minimumBalance:this.#minimumBalance,currency:this.#currency,validators:this.#validators}}constructor(tokenAddress,state){super(state?.roles),state?(this.#minimumBalance=BigNumber.from(state.minimumBalance),this.#currency=state.currency,this.#validators=state.validators):(this.#minimumBalance=new BigNumber.from(5e4),this.#currency=tokenAddress,this.#validators.push(msg.sender))}get name(){return this.#name}get currency(){return this.#currency}get validators(){return[...this.#validators]}get totalValidators(){return this.#validators.length}get minimumBalance(){return this.#minimumBalance}changeCurrency(currency){if(!this.hasRole(msg.sender,"OWNER"))throw new Error("not an owner");this.#currency=currency}has(validator){return this.#validators.includes(validator)}#isAllowed(address){if(msg.sender!==address&&!this.hasRole(msg.sender,"OWNER"))throw new Error("sender is not the validator or owner");return!0}async addValidator(validator){if(this.#isAllowed(validator),this.has(validator))throw new Error("already a validator");const balance=await msg.staticCall(this.currency,"balanceOf",[validator]);if(this.minimumBalance.gt(balance))throw new Error(`balance to low! got: ${balance} need: ${this.#minimumBalance}`);this.#validators.push(validator)}removeValidator(validator){if(this.#isAllowed(validator),!this.has(validator))throw new Error("validator not found");this.#validators.splice(this.#validators.indexOf(validator))}}export{Validators as default};
|