@leofcoin/contracts 0.1.1 → 0.1.3
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.d.ts +20 -0
- package/exports/factory.js +1 -56
- package/exports/name-service.d.ts +31 -0
- package/exports/name-service.js +1 -106
- package/exports/native-token.d.ts +4 -0
- package/exports/native-token.js +1 -7
- package/exports/power-token.d.ts +4 -0
- package/exports/power-token.js +1 -7
- package/exports/types.d.ts +2 -0
- package/exports/validators.d.ts +16 -0
- package/exports/validators.js +1 -129
- package/package.json +12 -2
- package/rollup.config.js +82 -0
- package/src/factory.ts +56 -0
- package/src/name-service.ts +120 -0
- package/src/native-token.ts +7 -0
- package/src/power-token.ts +7 -0
- package/src/types.ts +3 -0
- package/src/validators.ts +129 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export default class Factory {
|
|
2
|
+
#private;
|
|
3
|
+
constructor(state: {
|
|
4
|
+
contracts: any[];
|
|
5
|
+
totalContracts: number;
|
|
6
|
+
});
|
|
7
|
+
get state(): {
|
|
8
|
+
totalContracts: number;
|
|
9
|
+
contracts: any[];
|
|
10
|
+
};
|
|
11
|
+
get name(): string;
|
|
12
|
+
get contracts(): any[];
|
|
13
|
+
get totalContracts(): number;
|
|
14
|
+
isRegistered(address: any): boolean;
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
* @param {Address} address contract address to register
|
|
18
|
+
*/
|
|
19
|
+
registerContract(address: string): Promise<void>;
|
|
20
|
+
}
|
package/exports/factory.js
CHANGED
|
@@ -1,56 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* string
|
|
4
|
-
*/
|
|
5
|
-
#name = 'ArtOnlineContractFactory'
|
|
6
|
-
/**
|
|
7
|
-
* uint
|
|
8
|
-
*/
|
|
9
|
-
#totalContracts = 0
|
|
10
|
-
/**
|
|
11
|
-
* Array => string
|
|
12
|
-
*/
|
|
13
|
-
#contracts = []
|
|
14
|
-
|
|
15
|
-
constructor(state) {
|
|
16
|
-
if (state) {
|
|
17
|
-
this.#contracts = state.contracts
|
|
18
|
-
this.#totalContracts = state.totalContracts
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
get state() {
|
|
23
|
-
return {
|
|
24
|
-
totalContracts: this.#totalContracts,
|
|
25
|
-
contracts: this.#contracts
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
get name() {
|
|
30
|
-
return this.#name
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
get contracts() {
|
|
34
|
-
return [...this.#contracts]
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
get totalContracts() {
|
|
38
|
-
return this.#totalContracts
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
isRegistered(address) {
|
|
42
|
-
return this.#contracts.includes(address)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
*
|
|
47
|
-
* @param {Address} address contract address to register
|
|
48
|
-
*/
|
|
49
|
-
async registerContract(address) {
|
|
50
|
-
await msg.staticCall(address, 'hasRole', [msg.sender, 'OWNER'])
|
|
51
|
-
if (this.#contracts.includes(address)) throw new Error('already registered')
|
|
52
|
-
|
|
53
|
-
this.#totalContracts += 1
|
|
54
|
-
this.#contracts.push(address)
|
|
55
|
-
}
|
|
56
|
-
}
|
|
1
|
+
class Factory{#name="ArtOnlineContractFactory";#totalContracts=0;#contracts=[];constructor(state){state&&(this.#contracts=state.contracts,this.#totalContracts=state.totalContracts)}get state(){return{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)}async registerContract(address){if(await msg.staticCall(address,"hasRole",[msg.sender,"OWNER"]),this.#contracts.includes(address))throw new Error("already registered");this.#totalContracts+=1,this.#contracts.push(address)}}export{Factory as default};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
type registry = {
|
|
2
|
+
name: {
|
|
3
|
+
address: address;
|
|
4
|
+
owner: address;
|
|
5
|
+
};
|
|
6
|
+
};
|
|
7
|
+
export default class NameService {
|
|
8
|
+
#private;
|
|
9
|
+
get name(): string;
|
|
10
|
+
get registry(): {};
|
|
11
|
+
get state(): {
|
|
12
|
+
owner: string;
|
|
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;
|
|
26
|
+
purchaseName(name: string | number, address: any): Promise<void>;
|
|
27
|
+
lookup(name: string | number): any;
|
|
28
|
+
transferOwnership(name: string | number, to: any): void;
|
|
29
|
+
changeAddress(name: string | number, address: any): void;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
package/exports/name-service.js
CHANGED
|
@@ -1,106 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* string
|
|
4
|
-
*/
|
|
5
|
-
#name = 'ArtOnlineNameService'
|
|
6
|
-
/**
|
|
7
|
-
* string
|
|
8
|
-
*/
|
|
9
|
-
#owner
|
|
10
|
-
/**
|
|
11
|
-
* number
|
|
12
|
-
*/
|
|
13
|
-
#price = 0
|
|
14
|
-
/**
|
|
15
|
-
* Object => string
|
|
16
|
-
*/
|
|
17
|
-
#registry = {}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* => string
|
|
21
|
-
*/
|
|
22
|
-
#currency
|
|
23
|
-
|
|
24
|
-
get name() {
|
|
25
|
-
return this.#name
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
get registry() {
|
|
29
|
-
return {...this.#registry}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
get state() {}
|
|
33
|
-
|
|
34
|
-
// TODO: control with contract
|
|
35
|
-
constructor(factoryAddress, currency, validatorAddress, price, state) {
|
|
36
|
-
if (state) {
|
|
37
|
-
this.#owner = state.owner
|
|
38
|
-
this.#registry = state.registry
|
|
39
|
-
this.#currency = state.currency
|
|
40
|
-
this.#price = state.price
|
|
41
|
-
} else {
|
|
42
|
-
this.#owner = msg.sender
|
|
43
|
-
this.#price = price
|
|
44
|
-
this.#registry['ArtOnlineContractFactory'] = {
|
|
45
|
-
owner: msg.sender,
|
|
46
|
-
address: factoryAddress
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
this.#registry['ArtOnlineToken'] = {
|
|
50
|
-
owner: msg.sender,
|
|
51
|
-
address: currency
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
this.#registry['ArtOnlineValidators'] = {
|
|
55
|
-
owner: msg.sender,
|
|
56
|
-
address: validatorAddress
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
this.#currency = currency
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
changeOwner(owner) {
|
|
64
|
-
if (msg.sender !== this.#owner) throw new Error('no owner')
|
|
65
|
-
this.#owner = owner
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
changePrice(price) {
|
|
69
|
-
if (msg.sender !== this.#owner) throw new Error('no owner')
|
|
70
|
-
this.#price = price
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
changeCurrency(currency) {
|
|
74
|
-
if (msg.sender !== this.#owner) throw new Error('no owner')
|
|
75
|
-
this.#currency = currency
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async purchaseName(name, address) {
|
|
79
|
-
const balance = await msg.call(this.#currency, 'balanceOf', [msg.sender])
|
|
80
|
-
if (balance < this.#price) throw new Error('price exceeds balance')
|
|
81
|
-
try {
|
|
82
|
-
await msg.call(this.#currency, 'transfer', [msg.sender, this.#owner, this.#price])
|
|
83
|
-
} catch (error) {
|
|
84
|
-
throw error
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
this.#registry[name] = {
|
|
88
|
-
owner: msg.sender,
|
|
89
|
-
address
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
lookup(name) {
|
|
94
|
-
return this.#registry[name]
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
transferOwnership(name, to) {
|
|
98
|
-
if (msg.sender !== this.#registry.owner) throw new Error('not a owner')
|
|
99
|
-
this.#registry[name].owner = to
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
changeAddress(name, address) {
|
|
103
|
-
if (msg.sender !== this.#registry.owner) throw new Error('not a owner')
|
|
104
|
-
this.#registry[name].address = address
|
|
105
|
-
}
|
|
106
|
-
}
|
|
1
|
+
class NameService{#name="ArtOnlineNameService";#owner;#price=0;#registry;#currency;get name(){return this.#name}get registry(){return{...this.#registry}}get state(){return{owner:this.#owner,registry:this.#registry,currency:this.#currency,price:this.#price}}constructor(factoryAddress,currency,validatorAddress,price,state){state?(this.#owner=state.owner,this.#registry=state.registry,this.#currency=state.currency,this.#price=state.price):(this.#owner=msg.sender,this.#price=price,this.#registry.ArtOnlineContractFactory={owner:msg.sender,address:factoryAddress},this.#registry.ArtOnlineToken={owner:msg.sender,address:currency},this.#registry.ArtOnlineValidators={owner:msg.sender,address:validatorAddress},this.#currency=currency)}changeOwner(owner){if(msg.sender!==this.#owner)throw new Error("no owner");this.#owner=owner}changePrice(price){if(msg.sender!==this.#owner)throw new Error("no owner");this.#price=price}changeCurrency(currency){if(msg.sender!==this.#owner)throw new Error("no owner");this.#currency=currency}async purchaseName(name,address){if(await msg.call(this.#currency,"balanceOf",[msg.sender])<this.#price)throw new Error("price exceeds balance");try{await msg.call(this.#currency,"transfer",[msg.sender,this.#owner,this.#price])}catch(error){throw error}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 a owner");this.#registry[name].owner=to}changeAddress(name,address){if(msg.sender!==this.#registry[name].owner)throw new Error("not a owner");this.#registry[name].address=address}}export{NameService as default};
|
package/exports/native-token.js
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export default class ArtOnline extends Token {
|
|
4
|
-
constructor(state) {
|
|
5
|
-
super('ArtOnline', 'ART', 18, state)
|
|
6
|
-
}
|
|
7
|
-
}
|
|
1
|
+
class Roles{#roles={OWNER:[],MINT:[],BURN:[]};constructor(roles){if(roles){if(!(roles instanceof Object))throw new TypeError("expected roles to be an object");this.#roles={...roles,...this.#roles}}else this.#grantRole(msg.sender,"OWNER")}get state(){return{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=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),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}}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-=1:"0x00"!==this.#balances[address].toHexString()&&"0x00"===previousBalance.toHexString()&&(this.#holders+=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)}balanceOf(address){return this.#balances[address]}setApproval(operator,amount){const owner=msg.sender;this.#approvals[owner]||(this.#approvals[owner]={}),this.#approvals[owner][operator]=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 ArtOnline extends Token{constructor(state){super("ArtOnline","ART",18,state)}}export{ArtOnline as default};
|
package/exports/power-token.js
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export default class Power extends Token {
|
|
4
|
-
constructor(state) {
|
|
5
|
-
super('Power', 'PWR', 18, state)
|
|
6
|
-
}
|
|
7
|
-
}
|
|
1
|
+
class Roles{#roles={OWNER:[],MINT:[],BURN:[]};constructor(roles){if(roles){if(!(roles instanceof Object))throw new TypeError("expected roles to be an object");this.#roles={...roles,...this.#roles}}else this.#grantRole(msg.sender,"OWNER")}get state(){return{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=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),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}}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-=1:"0x00"!==this.#balances[address].toHexString()&&"0x00"===previousBalance.toHexString()&&(this.#holders+=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)}balanceOf(address){return this.#balances[address]}setApproval(operator,amount){const owner=msg.sender;this.#approvals[owner]||(this.#approvals[owner]={}),this.#approvals[owner][operator]=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};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import Roles from '@leofcoin/standards/roles.js';
|
|
2
|
+
export default class Validators extends Roles {
|
|
3
|
+
#private;
|
|
4
|
+
get state(): any;
|
|
5
|
+
constructor(tokenAddress: any, state: any);
|
|
6
|
+
get name(): string;
|
|
7
|
+
get currency(): any;
|
|
8
|
+
get validators(): {};
|
|
9
|
+
get totalValidators(): number;
|
|
10
|
+
get minimumBalance(): any;
|
|
11
|
+
changeCurrency(currency: any): void;
|
|
12
|
+
has(validator: any): boolean;
|
|
13
|
+
addValidator(validator: address): Promise<void>;
|
|
14
|
+
removeValidator(validator: any): void;
|
|
15
|
+
updateValidator(validator: any, active: any): Promise<void>;
|
|
16
|
+
}
|
package/exports/validators.js
CHANGED
|
@@ -1,129 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export default class Validators extends Roles {
|
|
4
|
-
/**
|
|
5
|
-
* string
|
|
6
|
-
*/
|
|
7
|
-
#name = 'ArtOnlineValidators'
|
|
8
|
-
/**
|
|
9
|
-
* uint
|
|
10
|
-
*/
|
|
11
|
-
#totalValidators = 0
|
|
12
|
-
|
|
13
|
-
#activeValidators = 0
|
|
14
|
-
/**
|
|
15
|
-
* Object => string(address) => Object
|
|
16
|
-
*/
|
|
17
|
-
#validators = {}
|
|
18
|
-
|
|
19
|
-
#currency
|
|
20
|
-
|
|
21
|
-
#minimumBalance
|
|
22
|
-
|
|
23
|
-
get state() {
|
|
24
|
-
return {
|
|
25
|
-
...super.state,
|
|
26
|
-
minimumBalance: this.#minimumBalance,
|
|
27
|
-
currency: this.#currency,
|
|
28
|
-
totalValidators: this.#totalValidators,
|
|
29
|
-
activeValidators: this.#activeValidators,
|
|
30
|
-
validators: this.#validators
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
constructor(tokenAddress, state) {
|
|
35
|
-
super(state?.roles)
|
|
36
|
-
if (state) {
|
|
37
|
-
this.#minimumBalance = state.minimumBalance
|
|
38
|
-
this.#currency = state.currency
|
|
39
|
-
|
|
40
|
-
this.#totalValidators = state.totalValidators
|
|
41
|
-
this.#activeValidators = state.activeValidators
|
|
42
|
-
this.#validators = state.validators
|
|
43
|
-
} else {
|
|
44
|
-
this.#minimumBalance = 50_000
|
|
45
|
-
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
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
get name() {
|
|
59
|
-
return this.#name
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
get currency() {
|
|
63
|
-
return this.#currency
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
get validators() {
|
|
67
|
-
return {...this.#validators}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
get totalValidators() {
|
|
71
|
-
return this.#totalValidators
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
get minimumBalance() {
|
|
75
|
-
return this.#minimumBalance
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
changeCurrency(currency) {
|
|
79
|
-
if (!this.hasRole(msg.sender, 'OWNER')) throw new Error('not an owner')
|
|
80
|
-
this.#currency = currency
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
has(validator) {
|
|
84
|
-
return Boolean(this.#validators[validator] !== undefined)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
#isAllowed(address) {
|
|
88
|
-
if (msg.sender !== address && !this.hasRole(msg.sender, 'OWNER')) throw new Error('sender is not the validator or owner')
|
|
89
|
-
return true
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async addValidator(validator) {
|
|
93
|
-
this.#isAllowed(validator)
|
|
94
|
-
if (this.has(validator)) throw new Error('already a validator')
|
|
95
|
-
|
|
96
|
-
const balance = await msg.staticCall(this.currency, 'balanceOf', [validator])
|
|
97
|
-
|
|
98
|
-
if (balance < this.minimumBalance) throw new Error(`balance to low! got: ${balance} need: ${this.#minimumBalance}`)
|
|
99
|
-
|
|
100
|
-
this.#totalValidators += 1
|
|
101
|
-
this.#activeValidators += 1
|
|
102
|
-
this.#validators[validator] = {
|
|
103
|
-
firstSeen: Date.now(),
|
|
104
|
-
lastSeen: Date.now(),
|
|
105
|
-
active: true
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
removeValidator(validator) {
|
|
110
|
-
this.#isAllowed(validator)
|
|
111
|
-
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
|
|
128
|
-
}
|
|
129
|
-
}
|
|
1
|
+
class Roles{#roles={OWNER:[],MINT:[],BURN:[]};constructor(roles){if(roles){if(!(roles instanceof Object))throw new TypeError("expected roles to be an object");this.#roles={...roles,...this.#roles}}else this.#grantRole(msg.sender,"OWNER")}get state(){return{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="ArtOnlineValidators";#totalValidators=0;#activeValidators=0;#validators={};#currency;#minimumBalance;get state(){return{...super.state,minimumBalance:this.#minimumBalance,currency:this.#currency,totalValidators:this.#totalValidators,activeValidators:this.#activeValidators,validators:this.#validators}}constructor(tokenAddress,state){super(state?.roles),state?(this.#minimumBalance=state.minimumBalance,this.#currency=state.currency,this.#totalValidators=state.totalValidators,this.#activeValidators=state.activeValidators,this.#validators=state.validators):(this.#minimumBalance=5e4,this.#currency=tokenAddress,this.#totalValidators+=1,this.#activeValidators+=1,this.#validators[msg.sender]={firstSeen:Date.now(),lastSeen:Date.now(),active:!0})}get name(){return this.#name}get currency(){return this.#currency}get validators(){return{...this.#validators}}get totalValidators(){return this.#totalValidators}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 Boolean(void 0!==this.#validators[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(balance<this.minimumBalance)throw new Error(`balance to low! got: ${balance} need: ${this.#minimumBalance}`);this.#totalValidators+=1,this.#activeValidators+=1,this.#validators[validator]={firstSeen:Date.now(),lastSeen:Date.now(),active:!0}}removeValidator(validator){if(this.#isAllowed(validator),!this.has(validator))throw new Error("validator not found");this.#totalValidators-=1,this.#validators[validator].active&&(this.#activeValidators-=1),delete this.#validators[validator]}async updateValidator(validator,active){if(this.#isAllowed(validator),!this.has(validator))throw new Error("validator not found");const balance=await msg.staticCall(this.currency,"balanceOf",[validator]);if(balance<this.minimumBalance&&active)throw new Error(`balance to low! got: ${balance} need: ${this.#minimumBalance}`);if(this.#validators[validator].active===active)throw new Error("already "+(active?"activated":"deactivated"));active?this.#activeValidators+=1:this.#activeValidators-=1,this.#validators[validator].active=active}}export{Validators as default};
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/contracts",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"exports": {
|
|
6
7
|
"./factory": "./exports/factory.js",
|
|
7
8
|
"./name-token": "./exports/name-token.js",
|
|
@@ -10,6 +11,7 @@
|
|
|
10
11
|
"./validators": "./exports/validators.js"
|
|
11
12
|
},
|
|
12
13
|
"scripts": {
|
|
14
|
+
"build": "rollup -c",
|
|
13
15
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
14
16
|
},
|
|
15
17
|
"repository": {
|
|
@@ -24,6 +26,14 @@
|
|
|
24
26
|
},
|
|
25
27
|
"homepage": "https://github.com/leofcoin/contracts#readme",
|
|
26
28
|
"dependencies": {
|
|
27
|
-
"@leofcoin/
|
|
29
|
+
"@leofcoin/global-types": "^1.0.0",
|
|
30
|
+
"@leofcoin/standards": "^0.1.2"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
34
|
+
"@rollup/plugin-terser": "^0.4.0",
|
|
35
|
+
"@rollup/plugin-typescript": "^11.0.0",
|
|
36
|
+
"rollup": "^3.17.2",
|
|
37
|
+
"tslib": "^2.5.0"
|
|
28
38
|
}
|
|
29
39
|
}
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import typescript from '@rollup/plugin-typescript'
|
|
2
|
+
import tsConfig from './tsconfig.json' assert { type: 'json'}
|
|
3
|
+
import terser from '@rollup/plugin-terser'
|
|
4
|
+
import resolve from '@rollup/plugin-node-resolve'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export default [{
|
|
8
|
+
input: './src/factory.ts',
|
|
9
|
+
output: {
|
|
10
|
+
dir: './exports',
|
|
11
|
+
format: 'es'
|
|
12
|
+
},
|
|
13
|
+
plugins: [
|
|
14
|
+
resolve({
|
|
15
|
+
mainFields: ['exports']
|
|
16
|
+
}),
|
|
17
|
+
typescript(tsConfig),
|
|
18
|
+
terser({
|
|
19
|
+
mangle: false
|
|
20
|
+
})
|
|
21
|
+
]
|
|
22
|
+
}, {
|
|
23
|
+
input: './src/name-service.ts',
|
|
24
|
+
output: {
|
|
25
|
+
dir: './exports',
|
|
26
|
+
format: 'es'
|
|
27
|
+
},
|
|
28
|
+
plugins: [
|
|
29
|
+
resolve({
|
|
30
|
+
mainFields: ['exports']
|
|
31
|
+
}),
|
|
32
|
+
typescript(tsConfig),
|
|
33
|
+
terser({
|
|
34
|
+
mangle: false
|
|
35
|
+
})
|
|
36
|
+
]
|
|
37
|
+
}, {
|
|
38
|
+
input: './src/native-token.ts',
|
|
39
|
+
output: {
|
|
40
|
+
dir: './exports',
|
|
41
|
+
format: 'es'
|
|
42
|
+
},
|
|
43
|
+
plugins: [
|
|
44
|
+
resolve({
|
|
45
|
+
mainFields: ['exports']
|
|
46
|
+
}),
|
|
47
|
+
typescript(tsConfig),
|
|
48
|
+
terser({
|
|
49
|
+
mangle: false
|
|
50
|
+
})
|
|
51
|
+
]
|
|
52
|
+
}, {
|
|
53
|
+
input: './src/power-token.ts',
|
|
54
|
+
output: {
|
|
55
|
+
dir: './exports',
|
|
56
|
+
format: 'es'
|
|
57
|
+
},
|
|
58
|
+
plugins: [
|
|
59
|
+
resolve({
|
|
60
|
+
mainFields: ['exports']
|
|
61
|
+
}),
|
|
62
|
+
typescript(tsConfig),
|
|
63
|
+
terser({
|
|
64
|
+
mangle: false
|
|
65
|
+
})
|
|
66
|
+
]
|
|
67
|
+
}, {
|
|
68
|
+
input: './src/validators.ts',
|
|
69
|
+
output: {
|
|
70
|
+
dir: './exports',
|
|
71
|
+
format: 'es'
|
|
72
|
+
},
|
|
73
|
+
plugins: [
|
|
74
|
+
resolve({
|
|
75
|
+
mainFields: ['exports']
|
|
76
|
+
}),
|
|
77
|
+
typescript(tsConfig),
|
|
78
|
+
terser({
|
|
79
|
+
mangle: false
|
|
80
|
+
})
|
|
81
|
+
]
|
|
82
|
+
}]
|
package/src/factory.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export default class Factory {
|
|
2
|
+
/**
|
|
3
|
+
* string
|
|
4
|
+
*/
|
|
5
|
+
#name = 'ArtOnlineContractFactory'
|
|
6
|
+
/**
|
|
7
|
+
* uint
|
|
8
|
+
*/
|
|
9
|
+
#totalContracts = 0
|
|
10
|
+
/**
|
|
11
|
+
* Array => string
|
|
12
|
+
*/
|
|
13
|
+
#contracts = []
|
|
14
|
+
|
|
15
|
+
constructor(state: { contracts: any[]; totalContracts: number }) {
|
|
16
|
+
if (state) {
|
|
17
|
+
this.#contracts = state.contracts
|
|
18
|
+
this.#totalContracts = state.totalContracts
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get state() {
|
|
23
|
+
return {
|
|
24
|
+
totalContracts: this.#totalContracts,
|
|
25
|
+
contracts: this.#contracts
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get name() {
|
|
30
|
+
return this.#name
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
get contracts() {
|
|
34
|
+
return [...this.#contracts]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
get totalContracts() {
|
|
38
|
+
return this.#totalContracts
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
isRegistered(address: any) {
|
|
42
|
+
return this.#contracts.includes(address)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @param {Address} address contract address to register
|
|
48
|
+
*/
|
|
49
|
+
async registerContract(address: string) {
|
|
50
|
+
await msg.staticCall(address, 'hasRole', [msg.sender, 'OWNER'])
|
|
51
|
+
if (this.#contracts.includes(address)) throw new Error('already registered')
|
|
52
|
+
|
|
53
|
+
this.#totalContracts += 1
|
|
54
|
+
this.#contracts.push(address)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
type registry = {
|
|
2
|
+
name: {
|
|
3
|
+
address: address,
|
|
4
|
+
owner: address
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export default class NameService {
|
|
9
|
+
/**
|
|
10
|
+
* string
|
|
11
|
+
*/
|
|
12
|
+
#name: string = 'ArtOnlineNameService'
|
|
13
|
+
/**
|
|
14
|
+
* string
|
|
15
|
+
*/
|
|
16
|
+
#owner: address
|
|
17
|
+
/**
|
|
18
|
+
* number
|
|
19
|
+
*/
|
|
20
|
+
#price: BigNumberish = 0
|
|
21
|
+
/**
|
|
22
|
+
* Object => string
|
|
23
|
+
*/
|
|
24
|
+
#registry: registry
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* => string
|
|
28
|
+
*/
|
|
29
|
+
#currency: address
|
|
30
|
+
|
|
31
|
+
get name(): string {
|
|
32
|
+
return this.#name
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
get registry(): {} {
|
|
36
|
+
return {...this.#registry}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
get state() {
|
|
40
|
+
return {
|
|
41
|
+
owner: this.#owner,
|
|
42
|
+
registry: this.#registry,
|
|
43
|
+
currency: this.#currency,
|
|
44
|
+
price: this.#price
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// TODO: control with contract
|
|
49
|
+
constructor(factoryAddress: address, currency: address, validatorAddress: address, price: BigNumberish, state: { owner: address; registry: registry; currency: address; price: BigNumberish }) {
|
|
50
|
+
if (state) {
|
|
51
|
+
this.#owner = state.owner
|
|
52
|
+
this.#registry = state.registry
|
|
53
|
+
this.#currency = state.currency
|
|
54
|
+
this.#price = state.price
|
|
55
|
+
} else {
|
|
56
|
+
this.#owner = msg.sender
|
|
57
|
+
this.#price = price
|
|
58
|
+
this.#registry['ArtOnlineContractFactory'] = {
|
|
59
|
+
owner: msg.sender,
|
|
60
|
+
address: factoryAddress
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
this.#registry['ArtOnlineToken'] = {
|
|
64
|
+
owner: msg.sender,
|
|
65
|
+
address: currency
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
this.#registry['ArtOnlineValidators'] = {
|
|
69
|
+
owner: msg.sender,
|
|
70
|
+
address: validatorAddress
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
this.#currency = currency
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
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
|
+
async purchaseName(name: string | number, address: any) {
|
|
93
|
+
const balance = await msg.call(this.#currency, 'balanceOf', [msg.sender])
|
|
94
|
+
if (balance < this.#price) throw new Error('price exceeds balance')
|
|
95
|
+
try {
|
|
96
|
+
await msg.call(this.#currency, 'transfer', [msg.sender, this.#owner, this.#price])
|
|
97
|
+
} catch (error) {
|
|
98
|
+
throw error
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
this.#registry[name] = {
|
|
102
|
+
owner: msg.sender,
|
|
103
|
+
address
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
lookup(name: string | number) {
|
|
108
|
+
return this.#registry[name]
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
transferOwnership(name: string | number, to: any) {
|
|
112
|
+
if (msg.sender !== this.#registry[name].owner) throw new Error('not a owner')
|
|
113
|
+
this.#registry[name].owner = to
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
changeAddress(name: string | number, address: any) {
|
|
117
|
+
if (msg.sender !== this.#registry[name].owner) throw new Error('not a owner')
|
|
118
|
+
this.#registry[name].address = address
|
|
119
|
+
}
|
|
120
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import Roles from '@leofcoin/standards/roles.js'
|
|
2
|
+
|
|
3
|
+
export default class Validators extends Roles {
|
|
4
|
+
/**
|
|
5
|
+
* string
|
|
6
|
+
*/
|
|
7
|
+
#name = 'ArtOnlineValidators'
|
|
8
|
+
/**
|
|
9
|
+
* uint
|
|
10
|
+
*/
|
|
11
|
+
#totalValidators = 0
|
|
12
|
+
|
|
13
|
+
#activeValidators = 0
|
|
14
|
+
/**
|
|
15
|
+
* Object => string(address) => Object
|
|
16
|
+
*/
|
|
17
|
+
#validators = {}
|
|
18
|
+
|
|
19
|
+
#currency
|
|
20
|
+
|
|
21
|
+
#minimumBalance
|
|
22
|
+
|
|
23
|
+
get state() {
|
|
24
|
+
return {
|
|
25
|
+
...super.state,
|
|
26
|
+
minimumBalance: this.#minimumBalance,
|
|
27
|
+
currency: this.#currency,
|
|
28
|
+
totalValidators: this.#totalValidators,
|
|
29
|
+
activeValidators: this.#activeValidators,
|
|
30
|
+
validators: this.#validators
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
constructor(tokenAddress, state) {
|
|
35
|
+
super(state?.roles)
|
|
36
|
+
if (state) {
|
|
37
|
+
this.#minimumBalance = state.minimumBalance
|
|
38
|
+
this.#currency = state.currency
|
|
39
|
+
|
|
40
|
+
this.#totalValidators = state.totalValidators
|
|
41
|
+
this.#activeValidators = state.activeValidators
|
|
42
|
+
this.#validators = state.validators
|
|
43
|
+
} else {
|
|
44
|
+
this.#minimumBalance = 50_000
|
|
45
|
+
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
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get name() {
|
|
59
|
+
return this.#name
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
get currency() {
|
|
63
|
+
return this.#currency
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
get validators() {
|
|
67
|
+
return {...this.#validators}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get totalValidators() {
|
|
71
|
+
return this.#totalValidators
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
get minimumBalance() {
|
|
75
|
+
return this.#minimumBalance
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
changeCurrency(currency) {
|
|
79
|
+
if (!this.hasRole(msg.sender, 'OWNER')) throw new Error('not an owner')
|
|
80
|
+
this.#currency = currency
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
has(validator) {
|
|
84
|
+
return Boolean(this.#validators[validator] !== undefined)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
#isAllowed(address) {
|
|
88
|
+
if (msg.sender !== address && !this.hasRole(msg.sender, 'OWNER')) throw new Error('sender is not the validator or owner')
|
|
89
|
+
return true
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async addValidator(validator: address) {
|
|
93
|
+
this.#isAllowed(validator)
|
|
94
|
+
if (this.has(validator)) throw new Error('already a validator')
|
|
95
|
+
|
|
96
|
+
const balance = await msg.staticCall(this.currency, 'balanceOf', [validator])
|
|
97
|
+
|
|
98
|
+
if (balance < this.minimumBalance) throw new Error(`balance to low! got: ${balance} need: ${this.#minimumBalance}`)
|
|
99
|
+
|
|
100
|
+
this.#totalValidators += 1
|
|
101
|
+
this.#activeValidators += 1
|
|
102
|
+
this.#validators[validator] = {
|
|
103
|
+
firstSeen: Date.now(),
|
|
104
|
+
lastSeen: Date.now(),
|
|
105
|
+
active: true
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
removeValidator(validator) {
|
|
110
|
+
this.#isAllowed(validator)
|
|
111
|
+
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
|
|
128
|
+
}
|
|
129
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "es2022",
|
|
4
|
+
"target": "es2022",
|
|
5
|
+
"declarationDir": "./exports",
|
|
6
|
+
"moduleResolution": "nodenext",
|
|
7
|
+
"allowJs": true,
|
|
8
|
+
"allowSyntheticDefaultImports": true,
|
|
9
|
+
"resolveJsonModule": true,
|
|
10
|
+
"declaration": true
|
|
11
|
+
},
|
|
12
|
+
"include": [
|
|
13
|
+
"./src/**/*"
|
|
14
|
+
]
|
|
15
|
+
}
|