@leofcoin/contracts 0.1.5 → 0.1.6
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/.changeset/README.md +8 -0
- package/.changeset/config.json +11 -0
- package/exports/factory.d.ts +12 -11
- package/exports/factory.js +1 -1
- package/exports/name-service.d.ts +8 -16
- package/exports/name-service.js +1 -1
- package/exports/native-token.js +1 -1
- package/exports/power-token.js +1 -1
- package/exports/validators.d.ts +8 -7
- package/exports/validators.js +1 -1
- package/package.json +3 -2
- package/src/factory.ts +27 -10
- package/src/name-service.ts +30 -58
- package/src/validators.ts +16 -54
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Changesets
|
|
2
|
+
|
|
3
|
+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
|
|
4
|
+
with multi-package repos, or single-package repos to help you version and publish your code. You can
|
|
5
|
+
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
|
|
6
|
+
|
|
7
|
+
We have a quick list of common questions to get you started engaging with this project in
|
|
8
|
+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json",
|
|
3
|
+
"changelog": "@changesets/cli/changelog",
|
|
4
|
+
"commit": true,
|
|
5
|
+
"fixed": [],
|
|
6
|
+
"linked": [],
|
|
7
|
+
"access": "public",
|
|
8
|
+
"baseBranch": "main",
|
|
9
|
+
"updateInternalDependencies": "patch",
|
|
10
|
+
"ignore": []
|
|
11
|
+
}
|
package/exports/factory.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import { TokenReceiver } from '@leofcoin/standards';
|
|
2
|
+
import type { PublicVotingState } from '@leofcoin/standards/public-voting';
|
|
3
|
+
import { TokenReceiverState } from '@leofcoin/standards/token-receiver';
|
|
4
|
+
export interface FactoryState extends TokenReceiverState {
|
|
5
|
+
contracts: any[];
|
|
6
|
+
totalContracts: typeof BigNumber;
|
|
7
|
+
}
|
|
8
|
+
export default class Factory extends TokenReceiver {
|
|
2
9
|
#private;
|
|
3
|
-
constructor(state:
|
|
4
|
-
|
|
5
|
-
totalContracts: number;
|
|
6
|
-
});
|
|
7
|
-
get state(): {
|
|
8
|
-
totalContracts: number;
|
|
9
|
-
contracts: any[];
|
|
10
|
-
};
|
|
10
|
+
constructor(tokenToReceive: address, tokenAmountToReceive: typeof BigNumber, state: FactoryState);
|
|
11
|
+
get state(): PublicVotingState;
|
|
11
12
|
get name(): string;
|
|
12
|
-
get contracts():
|
|
13
|
-
get totalContracts():
|
|
13
|
+
get contracts(): string[];
|
|
14
|
+
get totalContracts(): import("@ethersproject/bignumber").BigNumber;
|
|
14
15
|
isRegistered(address: any): boolean;
|
|
15
16
|
/**
|
|
16
17
|
*
|
package/exports/factory.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class Factory{#name="
|
|
1
|
+
class PublicVoting{#votes;#votingDisabled;#votingDuration=1728e5;constructor(state){state&&(this.#votes=state.votes,this.#votingDisabled=state.votingDisabled)}get votes(){return{...this.#votes}}get votingDuration(){return this.#votingDuration}get votingDisabled(){return this.#votingDisabled}get state(){return{votes:this.#votes,votingDisabled:this.#votingDisabled,votingDuration:this.#votingDuration}}get inProgress(){return Object.entries(this.#votes).filter((([id,vote])=>!vote.finished)).map((([id,vote])=>({...vote,id:id})))}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}}#canVote(){return this._canVote?.()}#beforeVote(){return this._beforeVote?.()}#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}#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.inProgress)vote.endTime<(new Date).getTime()&&this.#endVoting(vote.id)}}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};
|
|
@@ -1,28 +1,20 @@
|
|
|
1
|
+
import { TokenReceiver } from '@leofcoin/standards';
|
|
2
|
+
import { TokenReceiverState } from '@leofcoin/standards/token-receiver';
|
|
1
3
|
type registry = {
|
|
2
4
|
name?: {
|
|
3
5
|
address: address;
|
|
4
6
|
owner: address;
|
|
5
7
|
};
|
|
6
8
|
};
|
|
7
|
-
export
|
|
9
|
+
export interface NameServiceState extends TokenReceiverState {
|
|
10
|
+
registry: registry;
|
|
11
|
+
}
|
|
12
|
+
export default class NameService extends TokenReceiver {
|
|
8
13
|
#private;
|
|
9
14
|
get name(): string;
|
|
10
15
|
get registry(): {};
|
|
11
|
-
get state():
|
|
12
|
-
|
|
13
|
-
registry: registry;
|
|
14
|
-
currency: string;
|
|
15
|
-
price: BigNumberish;
|
|
16
|
-
};
|
|
17
|
-
constructor(factoryAddress: address, currency: address, validatorAddress: address, price: BigNumberish, state: {
|
|
18
|
-
owner: address;
|
|
19
|
-
registry: registry;
|
|
20
|
-
currency: address;
|
|
21
|
-
price: BigNumberish;
|
|
22
|
-
});
|
|
23
|
-
changeOwner(owner: any): void;
|
|
24
|
-
changePrice(price: number): void;
|
|
25
|
-
changeCurrency(currency: any): void;
|
|
16
|
+
get state(): NameServiceState;
|
|
17
|
+
constructor(factoryAddress: address, tokenToReceive: address, validatorAddress: address, tokenAmountToReceive: typeof BigNumber, state: NameServiceState);
|
|
26
18
|
purchaseName(name: string | number, address: any): Promise<void>;
|
|
27
19
|
lookup(name: string | number): any;
|
|
28
20
|
transferOwnership(name: string | number, to: any): void;
|
package/exports/name-service.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class
|
|
1
|
+
class PublicVoting{#votes;#votingDisabled;#votingDuration=1728e5;constructor(state){state&&(this.#votes=state.votes,this.#votingDisabled=state.votingDisabled)}get votes(){return{...this.#votes}}get votingDuration(){return this.#votingDuration}get votingDisabled(){return this.#votingDisabled}get state(){return{votes:this.#votes,votingDisabled:this.#votingDisabled,votingDuration:this.#votingDuration}}get inProgress(){return Object.entries(this.#votes).filter((([id,vote])=>!vote.finished)).map((([id,vote])=>({...vote,id:id})))}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}}#canVote(){return this._canVote?.()}#beforeVote(){return this._beforeVote?.()}#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}#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.inProgress)vote.endTime<(new Date).getTime()&&this.#endVoting(vote.id)}}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 Roles{#roles={OWNER:[],MINT:[],BURN:[]};constructor(
|
|
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?.roles),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 Roles{#roles={OWNER:[],MINT:[],BURN:[]};constructor(
|
|
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?.roles),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.d.ts
CHANGED
|
@@ -2,21 +2,22 @@ import Roles from '@leofcoin/standards/roles.js';
|
|
|
2
2
|
export default class Validators extends Roles {
|
|
3
3
|
#private;
|
|
4
4
|
get state(): {
|
|
5
|
-
minimumBalance:
|
|
5
|
+
minimumBalance: import("@ethersproject/bignumber").BigNumber;
|
|
6
6
|
currency: string;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
validators: string[];
|
|
8
|
+
roles: {
|
|
9
|
+
[index: string]: string[];
|
|
10
|
+
};
|
|
11
|
+
contractCreator: string;
|
|
10
12
|
};
|
|
11
13
|
constructor(tokenAddress: address, state: any);
|
|
12
14
|
get name(): string;
|
|
13
15
|
get currency(): string;
|
|
14
|
-
get validators():
|
|
16
|
+
get validators(): string[];
|
|
15
17
|
get totalValidators(): number;
|
|
16
|
-
get minimumBalance():
|
|
18
|
+
get minimumBalance(): import("@ethersproject/bignumber").BigNumber;
|
|
17
19
|
changeCurrency(currency: any): void;
|
|
18
20
|
has(validator: any): boolean;
|
|
19
21
|
addValidator(validator: address): Promise<void>;
|
|
20
22
|
removeValidator(validator: any): void;
|
|
21
|
-
updateValidator(validator: any, active: any): Promise<void>;
|
|
22
23
|
}
|
package/exports/validators.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
class Roles{#roles={OWNER:[],MINT:[],BURN:[]};constructor(
|
|
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};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/contracts",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -26,8 +26,9 @@
|
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://github.com/leofcoin/contracts#readme",
|
|
28
28
|
"dependencies": {
|
|
29
|
+
"@changesets/cli": "^2.27.1",
|
|
29
30
|
"@leofcoin/global-types": "^1.0.0",
|
|
30
|
-
"@leofcoin/standards": "^0.
|
|
31
|
+
"@leofcoin/standards": "^0.2.2"
|
|
31
32
|
},
|
|
32
33
|
"devDependencies": {
|
|
33
34
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
package/src/factory.ts
CHANGED
|
@@ -1,26 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
import { PublicVoting, TokenReceiver } from '@leofcoin/standards'
|
|
2
|
+
import type { PublicVotingState } from '@leofcoin/standards/public-voting'
|
|
3
|
+
import { TokenReceiverState } from '@leofcoin/standards/token-receiver'
|
|
4
|
+
|
|
5
|
+
export interface FactoryState extends TokenReceiverState {
|
|
6
|
+
contracts: any[]
|
|
7
|
+
totalContracts: typeof BigNumber
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default class Factory extends TokenReceiver {
|
|
2
11
|
/**
|
|
3
12
|
* string
|
|
4
13
|
*/
|
|
5
|
-
#name = '
|
|
14
|
+
#name = 'LeofcoinContractFactory'
|
|
6
15
|
/**
|
|
7
16
|
* uint
|
|
8
17
|
*/
|
|
9
|
-
#totalContracts = 0
|
|
18
|
+
#totalContracts: typeof BigNumber = BigNumber['from'](0)
|
|
10
19
|
/**
|
|
11
20
|
* Array => string
|
|
12
21
|
*/
|
|
13
|
-
#contracts = []
|
|
22
|
+
#contracts: address[] = []
|
|
14
23
|
|
|
15
|
-
constructor(
|
|
24
|
+
constructor(tokenToReceive: address, tokenAmountToReceive: typeof BigNumber, state: FactoryState) {
|
|
25
|
+
super(tokenToReceive, tokenAmountToReceive, true, state as TokenReceiverState)
|
|
16
26
|
if (state) {
|
|
17
27
|
this.#contracts = state.contracts
|
|
18
28
|
this.#totalContracts = state.totalContracts
|
|
19
29
|
}
|
|
20
30
|
}
|
|
21
31
|
|
|
22
|
-
get state() {
|
|
32
|
+
get state(): PublicVotingState {
|
|
23
33
|
return {
|
|
34
|
+
...super.state,
|
|
24
35
|
totalContracts: this.#totalContracts,
|
|
25
36
|
contracts: this.#contracts
|
|
26
37
|
}
|
|
@@ -42,15 +53,21 @@ export default class Factory {
|
|
|
42
53
|
return this.#contracts.includes(address)
|
|
43
54
|
}
|
|
44
55
|
|
|
56
|
+
#isCreator(address: address) {
|
|
57
|
+
return msg.staticCall(address, '_isContractCreator')
|
|
58
|
+
}
|
|
59
|
+
|
|
45
60
|
/**
|
|
46
|
-
*
|
|
61
|
+
*
|
|
47
62
|
* @param {Address} address contract address to register
|
|
48
63
|
*/
|
|
49
64
|
async registerContract(address: string) {
|
|
50
|
-
|
|
51
|
-
if (this.#contracts.includes(address)) throw new Error('already registered')
|
|
65
|
+
if (!this._canPay()) throw new Error(`can't register, balance to low`)
|
|
52
66
|
|
|
53
|
-
this.#
|
|
67
|
+
if (!(await this.#isCreator(address))) throw new Error(`You don't own that contract`)
|
|
68
|
+
if (this.#contracts.includes(address)) throw new Error('already registered')
|
|
69
|
+
await this._payTokenToReceive()
|
|
70
|
+
this.#totalContracts.add(1)
|
|
54
71
|
this.#contracts.push(address)
|
|
55
72
|
}
|
|
56
73
|
}
|
package/src/name-service.ts
CHANGED
|
@@ -1,102 +1,74 @@
|
|
|
1
|
+
import { Roles, TokenReceiver } from '@leofcoin/standards'
|
|
2
|
+
import { TokenReceiverState } from '@leofcoin/standards/token-receiver'
|
|
3
|
+
|
|
1
4
|
type registry = {
|
|
2
5
|
name?: {
|
|
3
|
-
address: address
|
|
6
|
+
address: address
|
|
4
7
|
owner: address
|
|
5
8
|
}
|
|
6
9
|
}
|
|
7
10
|
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
export interface NameServiceState extends TokenReceiverState {
|
|
12
|
+
registry: registry
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default class NameService extends TokenReceiver {
|
|
13
16
|
/**
|
|
14
17
|
* string
|
|
15
18
|
*/
|
|
16
|
-
#
|
|
17
|
-
/**
|
|
18
|
-
* number
|
|
19
|
-
*/
|
|
20
|
-
#price: BigNumberish = 0
|
|
19
|
+
#name: string = 'LeofcoinNameService'
|
|
21
20
|
/**
|
|
22
21
|
* Object => string
|
|
23
22
|
*/
|
|
24
23
|
#registry: registry = {}
|
|
25
24
|
|
|
26
|
-
/**
|
|
27
|
-
* => string
|
|
28
|
-
*/
|
|
29
|
-
#currency: address
|
|
30
|
-
|
|
31
25
|
get name(): string {
|
|
32
26
|
return this.#name
|
|
33
27
|
}
|
|
34
28
|
|
|
35
29
|
get registry(): {} {
|
|
36
|
-
return {...this.#registry}
|
|
30
|
+
return { ...this.#registry }
|
|
37
31
|
}
|
|
38
32
|
|
|
39
|
-
get state() {
|
|
33
|
+
get state(): NameServiceState {
|
|
40
34
|
return {
|
|
41
|
-
|
|
42
|
-
registry: this.#registry
|
|
43
|
-
currency: this.#currency,
|
|
44
|
-
price: this.#price
|
|
35
|
+
...super.state,
|
|
36
|
+
registry: this.#registry
|
|
45
37
|
}
|
|
46
38
|
}
|
|
47
39
|
|
|
48
40
|
// TODO: control with contract
|
|
49
|
-
constructor(
|
|
41
|
+
constructor(
|
|
42
|
+
factoryAddress: address,
|
|
43
|
+
tokenToReceive: address,
|
|
44
|
+
validatorAddress: address,
|
|
45
|
+
tokenAmountToReceive: typeof BigNumber,
|
|
46
|
+
state: NameServiceState
|
|
47
|
+
) {
|
|
48
|
+
super(tokenToReceive, tokenAmountToReceive, true, state as TokenReceiverState)
|
|
50
49
|
if (state) {
|
|
51
|
-
this.#owner = state.owner
|
|
52
50
|
this.#registry = state.registry
|
|
53
|
-
this.#currency = state.currency
|
|
54
|
-
this.#price = state.price
|
|
55
51
|
} else {
|
|
56
|
-
this.#
|
|
57
|
-
this.#price = price
|
|
58
|
-
this.#registry['ArtOnlineContractFactory'] = {
|
|
52
|
+
this.#registry['LeofcoinContractFactory'] = {
|
|
59
53
|
owner: msg.sender,
|
|
60
54
|
address: factoryAddress
|
|
61
55
|
}
|
|
62
56
|
|
|
63
|
-
this.#registry['
|
|
57
|
+
this.#registry['LeofcoinToken'] = {
|
|
64
58
|
owner: msg.sender,
|
|
65
|
-
address:
|
|
59
|
+
address: tokenToReceive
|
|
66
60
|
}
|
|
67
61
|
|
|
68
|
-
this.#registry['
|
|
62
|
+
this.#registry['LeofcoinValidators'] = {
|
|
69
63
|
owner: msg.sender,
|
|
70
64
|
address: validatorAddress
|
|
71
65
|
}
|
|
72
|
-
|
|
73
|
-
this.#currency = currency
|
|
74
66
|
}
|
|
75
67
|
}
|
|
76
68
|
|
|
77
|
-
changeOwner(owner: any) {
|
|
78
|
-
if (msg.sender !== this.#owner) throw new Error('no owner')
|
|
79
|
-
this.#owner = owner
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
changePrice(price: number) {
|
|
83
|
-
if (msg.sender !== this.#owner) throw new Error('no owner')
|
|
84
|
-
this.#price = price
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
changeCurrency(currency: any) {
|
|
88
|
-
if (msg.sender !== this.#owner) throw new Error('no owner')
|
|
89
|
-
this.#currency = currency
|
|
90
|
-
}
|
|
91
|
-
|
|
92
69
|
async purchaseName(name: string | number, address: any) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
try {
|
|
96
|
-
await msg.call(this.#currency, 'transfer', [msg.sender, this.#owner, this.#price])
|
|
97
|
-
} catch (error) {
|
|
98
|
-
throw error
|
|
99
|
-
}
|
|
70
|
+
await this._canPay()
|
|
71
|
+
await this._payTokenToReceive()
|
|
100
72
|
|
|
101
73
|
this.#registry[name] = {
|
|
102
74
|
owner: msg.sender,
|
|
@@ -109,12 +81,12 @@ export default class NameService {
|
|
|
109
81
|
}
|
|
110
82
|
|
|
111
83
|
transferOwnership(name: string | number, to: any) {
|
|
112
|
-
if (msg.sender !== this.#registry[name].owner) throw new Error('not
|
|
84
|
+
if (msg.sender !== this.#registry[name].owner) throw new Error('not allowed')
|
|
113
85
|
this.#registry[name].owner = to
|
|
114
86
|
}
|
|
115
87
|
|
|
116
88
|
changeAddress(name: string | number, address: any) {
|
|
117
|
-
if (msg.sender !== this.#registry[name].owner) throw new Error('not
|
|
89
|
+
if (msg.sender !== this.#registry[name].owner) throw new Error('not allowed')
|
|
118
90
|
this.#registry[name].address = address
|
|
119
91
|
}
|
|
120
92
|
}
|
package/src/validators.ts
CHANGED
|
@@ -4,29 +4,21 @@ export default class Validators extends Roles {
|
|
|
4
4
|
/**
|
|
5
5
|
* string
|
|
6
6
|
*/
|
|
7
|
-
#name = '
|
|
8
|
-
/**
|
|
9
|
-
* uint
|
|
10
|
-
*/
|
|
11
|
-
#totalValidators = 0
|
|
12
|
-
|
|
13
|
-
#activeValidators = 0
|
|
7
|
+
#name = 'LeofcoinValidators'
|
|
14
8
|
/**
|
|
15
9
|
* Object => string(address) => Object
|
|
16
10
|
*/
|
|
17
|
-
#validators =
|
|
11
|
+
#validators: address[] = []
|
|
18
12
|
|
|
19
13
|
#currency: address
|
|
20
14
|
|
|
21
|
-
#minimumBalance:
|
|
15
|
+
#minimumBalance: typeof BigNumber
|
|
22
16
|
|
|
23
17
|
get state() {
|
|
24
18
|
return {
|
|
25
19
|
...super.state,
|
|
26
20
|
minimumBalance: this.#minimumBalance,
|
|
27
21
|
currency: this.#currency,
|
|
28
|
-
totalValidators: this.#totalValidators,
|
|
29
|
-
activeValidators: this.#activeValidators,
|
|
30
22
|
validators: this.#validators
|
|
31
23
|
}
|
|
32
24
|
}
|
|
@@ -34,25 +26,14 @@ export default class Validators extends Roles {
|
|
|
34
26
|
constructor(tokenAddress: address, state) {
|
|
35
27
|
super(state?.roles)
|
|
36
28
|
if (state) {
|
|
37
|
-
this.#minimumBalance = state.minimumBalance
|
|
29
|
+
this.#minimumBalance = BigNumber['from'](state.minimumBalance)
|
|
38
30
|
this.#currency = state.currency
|
|
39
|
-
|
|
40
|
-
this.#totalValidators = state.totalValidators
|
|
41
|
-
this.#activeValidators = state.activeValidators
|
|
42
31
|
this.#validators = state.validators
|
|
43
32
|
} else {
|
|
44
|
-
this.#minimumBalance = 50_000
|
|
33
|
+
this.#minimumBalance = new BigNumber['from'](50_000)
|
|
45
34
|
this.#currency = tokenAddress
|
|
46
|
-
|
|
47
|
-
this.#totalValidators += 1
|
|
48
|
-
this.#activeValidators += 1
|
|
49
|
-
this.#validators[msg.sender] = {
|
|
50
|
-
firstSeen: Date.now(),
|
|
51
|
-
lastSeen: Date.now(),
|
|
52
|
-
active: true
|
|
53
|
-
}
|
|
35
|
+
this.#validators.push(msg.sender)
|
|
54
36
|
}
|
|
55
|
-
|
|
56
37
|
}
|
|
57
38
|
|
|
58
39
|
get name() {
|
|
@@ -64,11 +45,11 @@ export default class Validators extends Roles {
|
|
|
64
45
|
}
|
|
65
46
|
|
|
66
47
|
get validators() {
|
|
67
|
-
return
|
|
48
|
+
return [...this.#validators]
|
|
68
49
|
}
|
|
69
50
|
|
|
70
51
|
get totalValidators() {
|
|
71
|
-
return this.#
|
|
52
|
+
return this.#validators.length
|
|
72
53
|
}
|
|
73
54
|
|
|
74
55
|
get minimumBalance() {
|
|
@@ -81,49 +62,30 @@ export default class Validators extends Roles {
|
|
|
81
62
|
}
|
|
82
63
|
|
|
83
64
|
has(validator) {
|
|
84
|
-
return
|
|
65
|
+
return this.#validators.includes(validator)
|
|
85
66
|
}
|
|
86
67
|
|
|
87
68
|
#isAllowed(address) {
|
|
88
|
-
if (msg.sender !== address && !this.hasRole(msg.sender, 'OWNER'))
|
|
69
|
+
if (msg.sender !== address && !this.hasRole(msg.sender, 'OWNER'))
|
|
70
|
+
throw new Error('sender is not the validator or owner')
|
|
89
71
|
return true
|
|
90
72
|
}
|
|
91
73
|
|
|
92
74
|
async addValidator(validator: address) {
|
|
93
75
|
this.#isAllowed(validator)
|
|
94
76
|
if (this.has(validator)) throw new Error('already a validator')
|
|
95
|
-
|
|
77
|
+
|
|
96
78
|
const balance = await msg.staticCall(this.currency, 'balanceOf', [validator])
|
|
97
79
|
|
|
98
|
-
if (
|
|
80
|
+
if (this.minimumBalance.gt(balance))
|
|
81
|
+
throw new Error(`balance to low! got: ${balance} need: ${this.#minimumBalance}`)
|
|
99
82
|
|
|
100
|
-
this.#
|
|
101
|
-
this.#activeValidators += 1
|
|
102
|
-
this.#validators[validator] = {
|
|
103
|
-
firstSeen: Date.now(),
|
|
104
|
-
lastSeen: Date.now(),
|
|
105
|
-
active: true
|
|
106
|
-
}
|
|
83
|
+
this.#validators.push(validator)
|
|
107
84
|
}
|
|
108
85
|
|
|
109
86
|
removeValidator(validator) {
|
|
110
87
|
this.#isAllowed(validator)
|
|
111
88
|
if (!this.has(validator)) throw new Error('validator not found')
|
|
112
|
-
|
|
113
|
-
this.#totalValidators -= 1
|
|
114
|
-
if (this.#validators[validator].active) this.#activeValidators -= 1
|
|
115
|
-
delete this.#validators[validator]
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
async updateValidator(validator, active) {
|
|
119
|
-
this.#isAllowed(validator)
|
|
120
|
-
if (!this.has(validator)) throw new Error('validator not found')
|
|
121
|
-
const balance = await msg.staticCall(this.currency, 'balanceOf', [validator])
|
|
122
|
-
if (balance < this.minimumBalance && active) throw new Error(`balance to low! got: ${balance} need: ${this.#minimumBalance}`)
|
|
123
|
-
if (this.#validators[validator].active === active) throw new Error(`already ${active ? 'activated' : 'deactivated'}`)
|
|
124
|
-
if (active) this.#activeValidators += 1
|
|
125
|
-
else this.#activeValidators -= 1
|
|
126
|
-
/** minimum balance always needs to be met */
|
|
127
|
-
this.#validators[validator].active = active
|
|
89
|
+
this.#validators.splice(this.#validators.indexOf(validator))
|
|
128
90
|
}
|
|
129
91
|
}
|