@leofcoin/contracts 0.1.15 → 0.1.17

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/.size-log.json CHANGED
@@ -110,6 +110,193 @@
110
110
  "development": 6,
111
111
  "total": 8
112
112
  }
113
+ },
114
+ {
115
+ "version": "0.1.15",
116
+ "timestamp": "2025-12-25T16:48:50.705Z",
117
+ "size": {
118
+ "bytes": 33746,
119
+ "formatted": "32.96 KB"
120
+ },
121
+ "nodeModules": {
122
+ "bytes": 40109779,
123
+ "formatted": "38.25 MB"
124
+ },
125
+ "dependencies": {
126
+ "production": 2,
127
+ "development": 6,
128
+ "total": 8
129
+ }
130
+ },
131
+ {
132
+ "version": "0.1.16",
133
+ "timestamp": "2026-04-15T20:03:31.692Z",
134
+ "size": {
135
+ "bytes": 30022,
136
+ "formatted": "29.32 KB"
137
+ },
138
+ "nodeModules": {
139
+ "bytes": 0,
140
+ "formatted": "0 Bytes"
141
+ },
142
+ "dependencies": {
143
+ "production": 2,
144
+ "development": 6,
145
+ "total": 8
146
+ }
147
+ },
148
+ {
149
+ "version": "0.1.16",
150
+ "timestamp": "2026-04-15T20:04:08.558Z",
151
+ "size": {
152
+ "bytes": 30022,
153
+ "formatted": "29.32 KB"
154
+ },
155
+ "nodeModules": {
156
+ "bytes": 0,
157
+ "formatted": "0 Bytes"
158
+ },
159
+ "dependencies": {
160
+ "production": 2,
161
+ "development": 6,
162
+ "total": 8
163
+ }
164
+ },
165
+ {
166
+ "version": "0.1.16",
167
+ "timestamp": "2026-04-15T20:11:04.490Z",
168
+ "size": {
169
+ "bytes": 30783,
170
+ "formatted": "30.06 KB"
171
+ },
172
+ "nodeModules": {
173
+ "bytes": 0,
174
+ "formatted": "0 Bytes"
175
+ },
176
+ "dependencies": {
177
+ "production": 2,
178
+ "development": 6,
179
+ "total": 8
180
+ }
181
+ },
182
+ {
183
+ "version": "0.1.16",
184
+ "timestamp": "2026-04-15T20:14:27.141Z",
185
+ "size": {
186
+ "bytes": 30783,
187
+ "formatted": "30.06 KB"
188
+ },
189
+ "nodeModules": {
190
+ "bytes": 0,
191
+ "formatted": "0 Bytes"
192
+ },
193
+ "dependencies": {
194
+ "production": 2,
195
+ "development": 6,
196
+ "total": 8
197
+ }
198
+ },
199
+ {
200
+ "version": "0.1.16",
201
+ "timestamp": "2026-04-15T20:17:15.946Z",
202
+ "size": {
203
+ "bytes": 30783,
204
+ "formatted": "30.06 KB"
205
+ },
206
+ "nodeModules": {
207
+ "bytes": 0,
208
+ "formatted": "0 Bytes"
209
+ },
210
+ "dependencies": {
211
+ "production": 2,
212
+ "development": 6,
213
+ "total": 8
214
+ }
215
+ },
216
+ {
217
+ "version": "0.1.16",
218
+ "timestamp": "2026-04-15T20:25:06.245Z",
219
+ "size": {
220
+ "bytes": 30783,
221
+ "formatted": "30.06 KB"
222
+ },
223
+ "nodeModules": {
224
+ "bytes": 0,
225
+ "formatted": "0 Bytes"
226
+ },
227
+ "dependencies": {
228
+ "production": 2,
229
+ "development": 6,
230
+ "total": 8
231
+ }
232
+ },
233
+ {
234
+ "version": "0.1.16",
235
+ "timestamp": "2026-04-15T20:25:34.516Z",
236
+ "size": {
237
+ "bytes": 30783,
238
+ "formatted": "30.06 KB"
239
+ },
240
+ "nodeModules": {
241
+ "bytes": 0,
242
+ "formatted": "0 Bytes"
243
+ },
244
+ "dependencies": {
245
+ "production": 2,
246
+ "development": 6,
247
+ "total": 8
248
+ }
249
+ },
250
+ {
251
+ "version": "0.1.17",
252
+ "timestamp": "2026-04-15T20:29:45.714Z",
253
+ "size": {
254
+ "bytes": 30783,
255
+ "formatted": "30.06 KB"
256
+ },
257
+ "nodeModules": {
258
+ "bytes": 0,
259
+ "formatted": "0 Bytes"
260
+ },
261
+ "dependencies": {
262
+ "production": 2,
263
+ "development": 6,
264
+ "total": 8
265
+ }
266
+ },
267
+ {
268
+ "version": "0.1.17",
269
+ "timestamp": "2026-04-15T20:29:52.324Z",
270
+ "size": {
271
+ "bytes": 30783,
272
+ "formatted": "30.06 KB"
273
+ },
274
+ "nodeModules": {
275
+ "bytes": 0,
276
+ "formatted": "0 Bytes"
277
+ },
278
+ "dependencies": {
279
+ "production": 2,
280
+ "development": 6,
281
+ "total": 8
282
+ }
283
+ },
284
+ {
285
+ "version": "0.1.17",
286
+ "timestamp": "2026-04-15T20:41:38.067Z",
287
+ "size": {
288
+ "bytes": 30783,
289
+ "formatted": "30.06 KB"
290
+ },
291
+ "nodeModules": {
292
+ "bytes": 0,
293
+ "formatted": "0 Bytes"
294
+ },
295
+ "dependencies": {
296
+ "production": 2,
297
+ "development": 6,
298
+ "total": 8
299
+ }
113
300
  }
114
301
  ]
115
302
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/contracts",
3
- "version": "0.1.15",
3
+ "version": "0.1.17",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "exports": {
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "homepage": "https://github.com/leofcoin/contracts#readme",
30
30
  "dependencies": {
31
- "@leofcoin/standards": "^0.3.4",
31
+ "@leofcoin/standards": "^0.3.6",
32
32
  "lucky-numbers": "^1.2.1"
33
33
  },
34
34
  "devDependencies": {
package/src/validators.ts CHANGED
@@ -8,6 +8,7 @@ export declare interface ValidatorsState extends RolesState {
8
8
  currency: address
9
9
  validators: address[]
10
10
  currentValidator: address
11
+ validatorHistory: { [height: number]: address[] }
11
12
  }
12
13
 
13
14
  export default class Validators extends Roles {
@@ -28,6 +29,9 @@ export default class Validators extends Roles {
28
29
 
29
30
  #balances: { [address: address]: bigint } = {}
30
31
 
32
+ /** Track validator set changes at each block height (for protocol safety) */
33
+ #validatorHistory: { [height: number]: address[] } = {}
34
+
31
35
  get state() {
32
36
  return {
33
37
  ...super.state,
@@ -35,7 +39,8 @@ export default class Validators extends Roles {
35
39
  minimumBalance: this.#minimumBalance,
36
40
  currency: this.#currency,
37
41
  validators: this.#validators,
38
- currentValidator: this.#currentValidator
42
+ currentValidator: this.#currentValidator,
43
+ validatorHistory: this.#validatorHistory
39
44
  }
40
45
  }
41
46
 
@@ -47,10 +52,12 @@ export default class Validators extends Roles {
47
52
  this.#validators = state.validators
48
53
  this.#balances = state.balances
49
54
  this.#currentValidator = state.currentValidator
55
+ this.#validatorHistory = state.validatorHistory || {}
50
56
  } else {
51
57
  this.#currency = tokenAddress
52
58
  this.#validators.push(msg.sender)
53
59
  this.#currentValidator = msg.sender
60
+ this.#validatorHistory[0] = [msg.sender]
54
61
  }
55
62
  }
56
63
 
@@ -93,6 +100,24 @@ export default class Validators extends Roles {
93
100
  return true
94
101
  }
95
102
 
103
+ /** Query validators at a specific block height (enables height-scoped validator snapshots) */
104
+ validatorsByHeight(height: number) {
105
+ // If we have history for this height, return it
106
+ if (this.#validatorHistory[height]) {
107
+ return this.#validatorHistory[height]
108
+ }
109
+
110
+ // Otherwise return current validators
111
+ // (In future, could query historical state from block headers)
112
+ return this.#validators
113
+ }
114
+
115
+ /** Record validator set change at a specific block height */
116
+ recordValidatorSnapshot(height: number) {
117
+ // Create a snapshot of current validators at this height
118
+ this.#validatorHistory[height] = [...this.#validators]
119
+ }
120
+
96
121
  async addValidator(validator: address) {
97
122
  this.#isAllowed(validator)
98
123
  if (this.has(validator)) throw new Error('validator already exists')
@@ -1,33 +0,0 @@
1
- name: Tests
2
-
3
- on:
4
- push:
5
- branches: [main]
6
- pull_request:
7
- branches: [main]
8
-
9
- jobs:
10
- test:
11
- runs-on: ubuntu-latest
12
-
13
- strategy:
14
- matrix:
15
- node-version: [22.x, latest]
16
-
17
- steps:
18
- - uses: actions/checkout@v4
19
-
20
- - name: Use Node.js ${{ matrix.node-version }}
21
- uses: actions/setup-node@v4
22
- with:
23
- node-version: ${{ matrix.node-version }}
24
- cache: 'npm'
25
-
26
- - name: Install dependencies
27
- run: npm ci
28
-
29
- - name: Build project
30
- run: npm run build
31
-
32
- - name: Run tests
33
- run: npm test
package/exports/chat.d.ts DELETED
@@ -1,12 +0,0 @@
1
- import { TokenReceiver } from '@leofcoin/standards';
2
- import { TokenReceiverState } from '@leofcoin/standards/token-receiver';
3
- export interface chatState extends TokenReceiverState {
4
- nicknames: {
5
- [address: string]: string;
6
- };
7
- }
8
- export default class Chat extends TokenReceiver {
9
- #private;
10
- constructor(tokenToReceive: any, tokenAmountToReceive: any, state: any);
11
- changeNickName(newName: string): Promise<void>;
12
- }
@@ -1,24 +0,0 @@
1
- import { TokenReceiver } from '@leofcoin/standards';
2
- import { TokenReceiverState } from '@leofcoin/standards/token-receiver.js';
3
- export interface FactoryState extends TokenReceiverState {
4
- contracts: any[];
5
- totalContracts: bigint;
6
- }
7
- export default class Factory extends TokenReceiver {
8
- #private;
9
- constructor(tokenToReceive: address, tokenAmountToReceive: bigint, state: FactoryState);
10
- get state(): FactoryState;
11
- get name(): string;
12
- get contracts(): string[];
13
- get totalContracts(): bigint;
14
- isRegistered(address: any): boolean;
15
- /**
16
- * Public hook for creator check to ease testing/stubbing.
17
- */
18
- isCreator(address: address): boolean;
19
- /**
20
- *
21
- * @param {Address} address contract address to register
22
- */
23
- registerContract(address: string): Promise<void>;
24
- }
@@ -1 +0,0 @@
1
- class Meta{#creator;#createdAt=BigInt(Date.now());constructor(state){state?(this.#creator=state.creator,this.#createdAt=state.createdAt):(this.#creator=msg.sender,this.#createdAt=BigInt(Date.now()))}get state(){return{creator:this.#creator,createdAt:this.#createdAt}}get creator(){return this.#creator}get createdAt(){return this.#createdAt}}class PublicVoting extends Meta{#votes;#votingDisabled;#votingDuration=1728e5;constructor(state){super(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{...super.state,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=BigInt(state.tokenAmountToReceive),this.#voteType=state.voteType):(this.#tokenReceiver=msg.contract,this.#tokenToReceive=tokenToReceive,this.#tokenAmountToReceive=BigInt(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])>=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])}#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()>0n)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(0n!==await this.#balance()&&"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=BigInt(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,"creator",[msg.sender])}isCreator(address){return this.#isCreator(address)}async registerContract(address){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+=1n,this.#contracts.push(address)}}export{Factory as default};
@@ -1,23 +0,0 @@
1
- import { TokenReceiver } from '@leofcoin/standards';
2
- import { TokenReceiverState } from '@leofcoin/standards/token-receiver';
3
- type registry = {
4
- name?: {
5
- address: address;
6
- owner: address;
7
- };
8
- };
9
- export interface NameServiceState extends TokenReceiverState {
10
- registry: registry;
11
- }
12
- export default class NameService extends TokenReceiver {
13
- #private;
14
- get name(): string;
15
- get registry(): {};
16
- get state(): NameServiceState;
17
- constructor(factoryAddress: address, tokenToReceive: address, validatorAddress: address, tokenAmountToReceive: bigint, state: NameServiceState);
18
- purchaseName(name: string | number, address: any): Promise<void>;
19
- lookup(name: string | number): any;
20
- transferOwnership(name: string | number, to: any): void;
21
- changeAddress(name: string | number, address: any): void;
22
- }
23
- export {};
@@ -1 +0,0 @@
1
- class Meta{#creator;#createdAt=BigInt(Date.now());constructor(state){state?(this.#creator=state.creator,this.#createdAt=state.createdAt):(this.#creator=msg.sender,this.#createdAt=BigInt(Date.now()))}get state(){return{creator:this.#creator,createdAt:this.#createdAt}}get creator(){return this.#creator}get createdAt(){return this.#createdAt}}class PublicVoting extends Meta{#votes;#votingDisabled;#votingDuration=1728e5;constructor(state){super(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{...super.state,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=BigInt(state.tokenAmountToReceive),this.#voteType=state.voteType):(this.#tokenReceiver=msg.contract,this.#tokenToReceive=tokenToReceive,this.#tokenAmountToReceive=BigInt(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])>=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])}#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()>0n)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(0n!==await this.#balance()&&"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:msg.contract},this.#registry.LeofcoinToken={owner:msg.sender,address:tokenToReceive},this.#registry.LeofcoinValidators={owner:msg.sender,address:validatorAddress})}async purchaseName(name,address){if(this.#registry[name])throw new Error("name already registered");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};
@@ -1,5 +0,0 @@
1
- import Token, { TokenState } from '@leofcoin/standards/token.js';
2
- export default class Leofcoin extends Token {
3
- constructor(state: TokenState);
4
- burn(from: address, amount: bigint): void;
5
- }
@@ -1 +0,0 @@
1
- class Meta{#creator;#createdAt=BigInt(Date.now());constructor(state){state?(this.#creator=state.creator,this.#createdAt=state.createdAt):(this.#creator=msg.sender,this.#createdAt=BigInt(Date.now()))}get state(){return{creator:this.#creator,createdAt:this.#createdAt}}get creator(){return this.#creator}get createdAt(){return this.#createdAt}}class Roles extends Meta{#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}}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=0n;#balances={};#approvals={};#decimals=18;#totalSupply=0n;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]=BigInt(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]=BigInt(approvals[owner][operator])}return _approvals})(state.approvals),this.#holders=BigInt(state.holders),this.#totalSupply=BigInt(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+amount,this.#increaseBalance(to,amount)}burn(from,amount){if(!this.hasRole(msg.sender,"BURN"))throw new Error("not allowed");this.#totalSupply=this.#totalSupply-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){0n===this.#balances[address]?this.#holders-=1n:0n!==this.#balances[address]&&0n===previousBalance&&(this.#holders+=1n)}#increaseBalance(address,amount){this.#balances[address]||(this.#balances[address]=0n);const previousBalance=this.#balances[address];this.#balances[address]=this.#balances[address]+amount,this.#updateHolders(address,previousBalance)}#decreaseBalance(address,amount){const previousBalance=this.#balances[address];this.#balances[address]=this.#balances[address]-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]=BigInt(amount)}approved(owner,operator,amount){return this.#approvals[owner][operator]===amount}transfer(from,to,amount){amount=BigInt(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)}burn(from,amount){if(this.balanceOf(from)<amount)throw new Error("amount exceeds balance");return super.burn(from,amount)}}export{Leofcoin as default};
@@ -1,4 +0,0 @@
1
- import Token, { TokenState } from '@leofcoin/standards/token.js';
2
- export default class Power extends Token {
3
- constructor(state: TokenState);
4
- }
@@ -1 +0,0 @@
1
- class Meta{#creator;#createdAt=BigInt(Date.now());constructor(state){state?(this.#creator=state.creator,this.#createdAt=state.createdAt):(this.#creator=msg.sender,this.#createdAt=BigInt(Date.now()))}get state(){return{creator:this.#creator,createdAt:this.#createdAt}}get creator(){return this.#creator}get createdAt(){return this.#createdAt}}class Roles extends Meta{#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}}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=0n;#balances={};#approvals={};#decimals=18;#totalSupply=0n;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]=BigInt(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]=BigInt(approvals[owner][operator])}return _approvals})(state.approvals),this.#holders=BigInt(state.holders),this.#totalSupply=BigInt(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+amount,this.#increaseBalance(to,amount)}burn(from,amount){if(!this.hasRole(msg.sender,"BURN"))throw new Error("not allowed");this.#totalSupply=this.#totalSupply-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){0n===this.#balances[address]?this.#holders-=1n:0n!==this.#balances[address]&&0n===previousBalance&&(this.#holders+=1n)}#increaseBalance(address,amount){this.#balances[address]||(this.#balances[address]=0n);const previousBalance=this.#balances[address];this.#balances[address]=this.#balances[address]+amount,this.#updateHolders(address,previousBalance)}#decreaseBalance(address,amount){const previousBalance=this.#balances[address];this.#balances[address]=this.#balances[address]-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]=BigInt(amount)}approved(owner,operator,amount){return this.#approvals[owner][operator]===amount}transfer(from,to,amount){amount=BigInt(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};
@@ -1,12 +0,0 @@
1
- import { TokenReceiver } from '@leofcoin/standards';
2
- import { TokenReceiverState } from '@leofcoin/standards/token-receiver';
3
- export interface chatState extends TokenReceiverState {
4
- nicknames: {
5
- [address: string]: string;
6
- };
7
- }
8
- export default class Chat extends TokenReceiver {
9
- #private;
10
- constructor(tokenToReceive: any, tokenAmountToReceive: any, state: any);
11
- changeNickName(newName: string): Promise<void>;
12
- }
@@ -1,22 +0,0 @@
1
- /// <reference types="@leofcoin/types/global" />
2
- import { TokenReceiver } from '@leofcoin/standards';
3
- import type { PublicVotingState } from '@leofcoin/standards/public-voting';
4
- import { TokenReceiverState } from '@leofcoin/standards/token-receiver';
5
- export interface FactoryState extends TokenReceiverState {
6
- contracts: any[];
7
- totalContracts: bigint;
8
- }
9
- export default class Factory extends TokenReceiver {
10
- #private;
11
- constructor(tokenToReceive: address, tokenAmountToReceive: bigint, state: FactoryState);
12
- get state(): PublicVotingState;
13
- get name(): string;
14
- get contracts(): string[];
15
- get totalContracts(): bigint;
16
- isRegistered(address: any): boolean;
17
- /**
18
- *
19
- * @param {Address} address contract address to register
20
- */
21
- registerContract(address: string): Promise<void>;
22
- }
@@ -1,24 +0,0 @@
1
- /// <reference types="@leofcoin/types/global" />
2
- import { TokenReceiver } from '@leofcoin/standards';
3
- import { TokenReceiverState } from '@leofcoin/standards/token-receiver';
4
- type registry = {
5
- name?: {
6
- address: address;
7
- owner: address;
8
- };
9
- };
10
- export interface NameServiceState extends TokenReceiverState {
11
- registry: registry;
12
- }
13
- export default class NameService extends TokenReceiver {
14
- #private;
15
- get name(): string;
16
- get registry(): {};
17
- get state(): NameServiceState;
18
- constructor(factoryAddress: address, tokenToReceive: address, validatorAddress: address, tokenAmountToReceive: bigint, state: NameServiceState);
19
- purchaseName(name: string | number, address: any): Promise<void>;
20
- lookup(name: string | number): any;
21
- transferOwnership(name: string | number, to: any): void;
22
- changeAddress(name: string | number, address: any): void;
23
- }
24
- export {};
@@ -1,4 +0,0 @@
1
- import Token, { TokenState } from '@leofcoin/standards/token.js';
2
- export default class Leofcoin extends Token {
3
- constructor(state: TokenState);
4
- }
@@ -1,4 +0,0 @@
1
- import Token, { TokenState } from '@leofcoin/standards/token.js';
2
- export default class Power extends Token {
3
- constructor(state: TokenState);
4
- }
@@ -1 +0,0 @@
1
- import '@leofcoin/global-types';
@@ -1,39 +0,0 @@
1
- /// <reference types="@leofcoin/types/global" />
2
- import Roles, { RolesState } from '@leofcoin/standards/roles.js';
3
- export declare interface ValidatorsState extends RolesState {
4
- balances: {
5
- [address: string]: bigint;
6
- };
7
- minimumBalance: bigint;
8
- currency: address;
9
- validators: address[];
10
- currentValidator: address;
11
- }
12
- export default class Validators extends Roles {
13
- #private;
14
- get state(): {
15
- balances: {
16
- [address: string]: bigint;
17
- };
18
- minimumBalance: bigint;
19
- currency: string;
20
- validators: string[];
21
- currentValidator: string;
22
- roles: {
23
- [index: string]: string[];
24
- };
25
- contractCreator: string;
26
- };
27
- constructor(tokenAddress: address, state: ValidatorsState);
28
- get currentValidator(): string;
29
- get name(): string;
30
- get currency(): string;
31
- get validators(): string[];
32
- get totalValidators(): number;
33
- get minimumBalance(): bigint;
34
- changeCurrency(currency: any): void;
35
- has(validator: any): boolean;
36
- addValidator(validator: address): Promise<void>;
37
- removeValidator(validator: any): Promise<void>;
38
- shuffleValidator(): void;
39
- }
@@ -1 +0,0 @@
1
- import '@leofcoin/global-types';
@@ -1,35 +0,0 @@
1
- import Roles from '@leofcoin/standards/roles.js';
2
- import type { RolesState } from '@leofcoin/standards/interfaces.js';
3
- export declare interface ValidatorsState extends RolesState {
4
- balances: {
5
- [address: string]: bigint;
6
- };
7
- minimumBalance: bigint;
8
- currency: address;
9
- validators: address[];
10
- currentValidator: address;
11
- }
12
- export default class Validators extends Roles {
13
- #private;
14
- get state(): {
15
- balances: {
16
- [address: string]: bigint;
17
- };
18
- minimumBalance: bigint;
19
- currency: string;
20
- validators: string[];
21
- currentValidator: string;
22
- };
23
- constructor(tokenAddress: address, state: ValidatorsState);
24
- get currentValidator(): string;
25
- get name(): string;
26
- get currency(): string;
27
- get validators(): string[];
28
- get totalValidators(): number;
29
- get minimumBalance(): bigint;
30
- changeCurrency(currency: any): void;
31
- has(validator: any): boolean;
32
- addValidator(validator: address): Promise<void>;
33
- removeValidator(validator: any): Promise<void>;
34
- shuffleValidator(): void;
35
- }
@@ -1 +0,0 @@
1
- const between=(min,max,length=1)=>{let arr=[];for(let i=0;i<length;++i)arr=[...arr,Math.floor(Math.random()*(max+1-min)+min)];return arr},lottery=(numbers=7,max=100,min=0,length=100)=>{let arr=[],ran=between(min,max,length);ran=(arr=>arr.filter((el,pos,arr)=>arr.indexOf(el)==pos))(ran);for(let i=0;i<numbers;++i){const _ran=between(min,ran.length-1,ran.length)[0];arr=[...arr,ran[_ran]]}return arr};class Meta{#creator;#createdAt=BigInt(Date.now());constructor(state){state?(this.#creator=state.creator,this.#createdAt=state.createdAt):(this.#creator=msg.sender,this.#createdAt=BigInt(Date.now()))}get state(){return{creator:this.#creator,createdAt:this.#createdAt}}get creator(){return this.#creator}get createdAt(){return this.#createdAt}}class Roles extends Meta{#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}}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=[];#currentValidator;#currency;#minimumBalance=BigInt(5e4);#balances={};get state(){return{...super.state,balances:this.#balances,minimumBalance:this.#minimumBalance,currency:this.#currency,validators:this.#validators,currentValidator:this.#currentValidator}}constructor(tokenAddress,state){super(state),state?(this.#minimumBalance=BigInt(state.minimumBalance),this.#currency=state.currency,this.#validators=state.validators,this.#balances=state.balances,this.#currentValidator=state.currentValidator):(this.#currency=tokenAddress,this.#validators.push(msg.sender),this.#currentValidator=msg.sender)}get currentValidator(){return this.#currentValidator}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("validator already exists");const balance=await msg.staticCall(this.currency,"balanceOf",[validator]);if(this.minimumBalance>balance)throw new Error(`balance to low! got: ${balance} need: ${this.#minimumBalance}`);await msg.call(this.currency,"transfer",[validator,msg.contract,this.#minimumBalance]),this.#balances[validator]=this.#minimumBalance,this.#validators.push(validator)}async removeValidator(validator){if(this.#isAllowed(validator),!this.has(validator))throw new Error("validator not found");await msg.call(this.currency,"transfer",[msg.contract,validator,this.#minimumBalance]),delete this.#balances[validator],this.#validators.splice(this.#validators.indexOf(validator),1)}shuffleValidator(){const _peers=state.peers,peers=_peers.filter(peer=>this.#validators.includes(peer[0])).map(peer=>(peer[1].totalBytes=peer[1].bw.up+peer[1].bw.down,peer)).sort((a,b)=>b[1].totalBytes-a[1].totalBytes).splice(0,_peers.length>128?128:_peers.length);let nextValidator=peers[lottery(1,peers.length-1)[0]][0];if(this.#currentValidator===nextValidator&&1!==peers.length){nextValidator=peers[lottery(1,peers.length-1)[0]][0]}this.#currentValidator=nextValidator}}export{Validators as default};