@holoscript/plugin-economic-primitives 2.0.1 → 2.0.2

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/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@holoscript/plugin-economic-primitives",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "main": "src/index.ts",
5
5
  "peerDependencies": {
6
- "@holoscript/core": "8.0.6"
6
+ "@holoscript/core": ">=8.0.0"
7
7
  },
8
8
  "license": "MIT",
9
9
  "scripts": {
10
10
  "test": "vitest run --passWithNoTests",
11
11
  "test:coverage": "vitest run --coverage --passWithNoTests"
12
12
  }
13
- }
13
+ }
package/src/index.ts CHANGED
@@ -1,7 +1,24 @@
1
- export { createMarketplaceListingHandler, type MarketplaceListingConfig, type ListingStatus, type PricingModel } from './traits/MarketplaceListingTrait';
2
- export { createRoyaltyStreamHandler, type RoyaltyStreamConfig, type RoyaltySplit } from './traits/RoyaltyStreamTrait';
3
- export { createAgentOwnedEntityHandler, type AgentOwnedEntityConfig } from './traits/AgentOwnedEntityTrait';
4
- export { createFoundationDAOHandler, type FoundationDAOConfig, type FoundationDAOState, type Proposal } from './traits/FoundationDAOTrait';
1
+ export {
2
+ createMarketplaceListingHandler,
3
+ type MarketplaceListingConfig,
4
+ type ListingStatus,
5
+ type PricingModel,
6
+ } from './traits/MarketplaceListingTrait';
7
+ export {
8
+ createRoyaltyStreamHandler,
9
+ type RoyaltyStreamConfig,
10
+ type RoyaltySplit,
11
+ } from './traits/RoyaltyStreamTrait';
12
+ export {
13
+ createAgentOwnedEntityHandler,
14
+ type AgentOwnedEntityConfig,
15
+ } from './traits/AgentOwnedEntityTrait';
16
+ export {
17
+ createFoundationDAOHandler,
18
+ type FoundationDAOConfig,
19
+ type FoundationDAOState,
20
+ type Proposal,
21
+ } from './traits/FoundationDAOTrait';
5
22
  export * from './traits/types';
6
23
 
7
24
  import { createMarketplaceListingHandler } from './traits/MarketplaceListingTrait';
@@ -9,5 +26,14 @@ import { createRoyaltyStreamHandler } from './traits/RoyaltyStreamTrait';
9
26
  import { createAgentOwnedEntityHandler } from './traits/AgentOwnedEntityTrait';
10
27
  import { createFoundationDAOHandler } from './traits/FoundationDAOTrait';
11
28
 
12
- export const pluginMeta = { name: '@holoscript/plugin-economic-primitives', version: '1.0.0', traits: ['marketplace_listing', 'royalty_stream', 'agent_owned_entity', 'foundation_dao'] };
13
- export const traitHandlers = [createMarketplaceListingHandler(), createRoyaltyStreamHandler(), createAgentOwnedEntityHandler(), createFoundationDAOHandler()];
29
+ export const pluginMeta = {
30
+ name: '@holoscript/plugin-economic-primitives',
31
+ version: '1.0.0',
32
+ traits: ['marketplace_listing', 'royalty_stream', 'agent_owned_entity', 'foundation_dao'],
33
+ };
34
+ export const traitHandlers = [
35
+ createMarketplaceListingHandler(),
36
+ createRoyaltyStreamHandler(),
37
+ createAgentOwnedEntityHandler(),
38
+ createFoundationDAOHandler(),
39
+ ];
@@ -20,25 +20,74 @@ export interface AgentOwnedEntityState {
20
20
  isActive: boolean;
21
21
  }
22
22
 
23
- const defaultConfig: AgentOwnedEntityConfig = { entityId: '', ownerAgentId: '', entityType: 'trait', walletAddress: '', revenueShare: 100, autonomyLevel: 'limited', spendingLimitPerDay: 10, allowedActions: ['list', 'price', 'respond'] };
23
+ const defaultConfig: AgentOwnedEntityConfig = {
24
+ entityId: '',
25
+ ownerAgentId: '',
26
+ entityType: 'trait',
27
+ walletAddress: '',
28
+ revenueShare: 100,
29
+ autonomyLevel: 'limited',
30
+ spendingLimitPerDay: 10,
31
+ allowedActions: ['list', 'price', 'respond'],
32
+ };
24
33
 
25
34
  export function createAgentOwnedEntityHandler(): TraitHandler<AgentOwnedEntityConfig> {
26
- return { name: 'agent_owned_entity', defaultConfig,
27
- onAttach(n: HSPlusNode, c: AgentOwnedEntityConfig, ctx: TraitContext) { n.__aoeState = { balance: 0, totalEarned: 0, totalSpent: 0, transactionCount: 0, isActive: true }; ctx.emit?.('aoe:registered', { entity: c.entityId, owner: c.ownerAgentId, autonomy: c.autonomyLevel }); },
28
- onDetach(n: HSPlusNode, _c: AgentOwnedEntityConfig, ctx: TraitContext) { delete n.__aoeState; ctx.emit?.('aoe:deregistered'); },
35
+ return {
36
+ name: 'agent_owned_entity',
37
+ defaultConfig,
38
+ onAttach(n: HSPlusNode, c: AgentOwnedEntityConfig, ctx: TraitContext) {
39
+ n.__aoeState = {
40
+ balance: 0,
41
+ totalEarned: 0,
42
+ totalSpent: 0,
43
+ transactionCount: 0,
44
+ isActive: true,
45
+ };
46
+ ctx.emit?.('aoe:registered', {
47
+ entity: c.entityId,
48
+ owner: c.ownerAgentId,
49
+ autonomy: c.autonomyLevel,
50
+ });
51
+ },
52
+ onDetach(n: HSPlusNode, _c: AgentOwnedEntityConfig, ctx: TraitContext) {
53
+ delete n.__aoeState;
54
+ ctx.emit?.('aoe:deregistered');
55
+ },
29
56
  onUpdate() {},
30
57
  onEvent(n: HSPlusNode, c: AgentOwnedEntityConfig, ctx: TraitContext, e: TraitEvent) {
31
- const s = n.__aoeState as AgentOwnedEntityState | undefined; if (!s || !s.isActive) return;
32
- if (e.type === 'aoe:earn') { const amt = (e.payload?.amount as number) ?? 0; s.balance += amt; s.totalEarned += amt; s.transactionCount++; ctx.emit?.('aoe:earned', { amount: amt, balance: s.balance }); }
58
+ const s = n.__aoeState as AgentOwnedEntityState | undefined;
59
+ if (!s || !s.isActive) return;
60
+ if (e.type === 'aoe:earn') {
61
+ const amt = (e.payload?.amount as number) ?? 0;
62
+ s.balance += amt;
63
+ s.totalEarned += amt;
64
+ s.transactionCount++;
65
+ ctx.emit?.('aoe:earned', { amount: amt, balance: s.balance });
66
+ }
33
67
  if (e.type === 'aoe:spend') {
34
68
  const amt = (e.payload?.amount as number) ?? 0;
35
69
  const action = (e.payload?.action as string) ?? '';
36
- if (amt > c.spendingLimitPerDay) { ctx.emit?.('aoe:spend_rejected', { amount: amt, limit: c.spendingLimitPerDay }); return; }
37
- if (!c.allowedActions.includes(action) && c.autonomyLevel !== 'full') { ctx.emit?.('aoe:action_denied', { action }); return; }
38
- if (s.balance >= amt) { s.balance -= amt; s.totalSpent += amt; s.transactionCount++; ctx.emit?.('aoe:spent', { amount: amt, action, balance: s.balance }); }
39
- else { ctx.emit?.('aoe:insufficient_balance', { requested: amt, available: s.balance }); }
70
+ if (amt > c.spendingLimitPerDay) {
71
+ ctx.emit?.('aoe:spend_rejected', { amount: amt, limit: c.spendingLimitPerDay });
72
+ return;
73
+ }
74
+ if (!c.allowedActions.includes(action) && c.autonomyLevel !== 'full') {
75
+ ctx.emit?.('aoe:action_denied', { action });
76
+ return;
77
+ }
78
+ if (s.balance >= amt) {
79
+ s.balance -= amt;
80
+ s.totalSpent += amt;
81
+ s.transactionCount++;
82
+ ctx.emit?.('aoe:spent', { amount: amt, action, balance: s.balance });
83
+ } else {
84
+ ctx.emit?.('aoe:insufficient_balance', { requested: amt, available: s.balance });
85
+ }
86
+ }
87
+ if (e.type === 'aoe:deactivate') {
88
+ s.isActive = false;
89
+ ctx.emit?.('aoe:deactivated');
40
90
  }
41
- if (e.type === 'aoe:deactivate') { s.isActive = false; ctx.emit?.('aoe:deactivated'); }
42
91
  },
43
92
  };
44
93
  }
@@ -39,7 +39,7 @@ const defaultConfig: FoundationDAOConfig = {
39
39
  governanceToken: 'HOLO_GOV',
40
40
  quorumPercent: 33,
41
41
  executionDelayHours: 48,
42
- multisigOwnersCount: 9
42
+ multisigOwnersCount: 9,
43
43
  };
44
44
 
45
45
  export function createFoundationDAOHandler(): TraitHandler<FoundationDAOConfig> {
@@ -148,70 +148,73 @@ export function createFoundationDAOHandler(): TraitHandler<FoundationDAOConfig>
148
148
  const s = n.__daoState as FoundationDAOState;
149
149
  if (!s) return;
150
150
  if (e.type === 'dao:propose') {
151
- const nowMs = Date.now();
152
- const proposal: Proposal = {
153
- id: `prop_${nowMs}`,
154
- title: (e.payload?.title as string) || 'General Update',
155
- votesFor: 0,
156
- votesAgainst: 0,
157
- status: 'active',
158
- zoneId: typeof e.payload?.zoneId === 'string' ? (e.payload.zoneId as string) : undefined,
159
- requestedAmountX402:
160
- typeof e.payload?.requestedAmountX402 === 'number'
161
- ? (e.payload.requestedAmountX402 as number)
162
- : undefined,
163
- createdAtMs: nowMs,
164
- voterWeights: {},
165
- };
166
- s.activeProposals.push(proposal);
167
- ctx.emit?.('dao:proposal_created', { proposal });
151
+ const nowMs = Date.now();
152
+ const proposal: Proposal = {
153
+ id: `prop_${nowMs}`,
154
+ title: (e.payload?.title as string) || 'General Update',
155
+ votesFor: 0,
156
+ votesAgainst: 0,
157
+ status: 'active',
158
+ zoneId: typeof e.payload?.zoneId === 'string' ? (e.payload.zoneId as string) : undefined,
159
+ requestedAmountX402:
160
+ typeof e.payload?.requestedAmountX402 === 'number'
161
+ ? (e.payload.requestedAmountX402 as number)
162
+ : undefined,
163
+ createdAtMs: nowMs,
164
+ voterWeights: {},
165
+ };
166
+ s.activeProposals.push(proposal);
167
+ ctx.emit?.('dao:proposal_created', { proposal });
168
168
  } else if (e.type === 'dao:vote') {
169
- const pid = e.payload?.proposalId as string;
170
- const prop = s.activeProposals.find(p => p.id === pid);
171
- if (prop && prop.status !== 'executed') {
172
- const voterId = typeof e.payload?.voterId === 'string' ? (e.payload.voterId as string) : 'anonymous_voter';
173
- const support = Boolean(e.payload?.support);
174
- const weight = typeof e.payload?.weight === 'number' ? (e.payload.weight as number) : 1;
175
- prop.status = 'active';
176
- delete prop.executableAtMs;
177
- applyVote(prop, voterId, support, weight);
178
- maybeConcludeProposal(prop, c, s, ctx, Date.now());
179
- executeProposal(prop, s, ctx, Date.now());
180
- }
169
+ const pid = e.payload?.proposalId as string;
170
+ const prop = s.activeProposals.find((p) => p.id === pid);
171
+ if (prop && prop.status !== 'executed') {
172
+ const voterId =
173
+ typeof e.payload?.voterId === 'string'
174
+ ? (e.payload.voterId as string)
175
+ : 'anonymous_voter';
176
+ const support = Boolean(e.payload?.support);
177
+ const weight = typeof e.payload?.weight === 'number' ? (e.payload.weight as number) : 1;
178
+ prop.status = 'active';
179
+ delete prop.executableAtMs;
180
+ applyVote(prop, voterId, support, weight);
181
+ maybeConcludeProposal(prop, c, s, ctx, Date.now());
182
+ executeProposal(prop, s, ctx, Date.now());
183
+ }
181
184
  } else if (e.type === 'dao:autonomous_vote') {
182
- const pid = e.payload?.proposalId as string;
183
- const prop = s.activeProposals.find(p => p.id === pid);
184
- if (!prop || prop.status !== 'active') return;
185
-
186
- const agents = Array.isArray(e.payload?.agents)
187
- ? (e.payload?.agents as Array<Record<string, unknown>>)
188
- : [];
189
-
190
- for (const agent of agents) {
191
- const voterId = typeof agent.agentId === 'string' ? (agent.agentId as string) : 'agent';
192
- const support =
193
- typeof agent.support === 'boolean'
194
- ? (agent.support as boolean)
195
- : prop.requestedAmountX402
196
- ? prop.requestedAmountX402 <= s.treasuryBalanceX402
197
- : true;
198
- const weight = typeof agent.weight === 'number' ? (agent.weight as number) : 1;
199
- applyVote(prop, voterId, support, weight);
200
- }
201
-
202
- maybeConcludeProposal(prop, c, s, ctx, Date.now());
185
+ const pid = e.payload?.proposalId as string;
186
+ const prop = s.activeProposals.find((p) => p.id === pid);
187
+ if (!prop || prop.status !== 'active') return;
188
+
189
+ const agents = Array.isArray(e.payload?.agents)
190
+ ? (e.payload?.agents as Array<Record<string, unknown>>)
191
+ : [];
192
+
193
+ for (const agent of agents) {
194
+ const voterId = typeof agent.agentId === 'string' ? (agent.agentId as string) : 'agent';
195
+ const support =
196
+ typeof agent.support === 'boolean'
197
+ ? (agent.support as boolean)
198
+ : prop.requestedAmountX402
199
+ ? prop.requestedAmountX402 <= s.treasuryBalanceX402
200
+ : true;
201
+ const weight = typeof agent.weight === 'number' ? (agent.weight as number) : 1;
202
+ applyVote(prop, voterId, support, weight);
203
+ }
204
+
205
+ maybeConcludeProposal(prop, c, s, ctx, Date.now());
203
206
  executeProposal(prop, s, ctx, Date.now());
204
207
  } else if (e.type === 'dao:execute') {
205
- const nowMs =
206
- typeof e.payload?.nowMs === 'number' ? (e.payload.nowMs as number) : Date.now();
207
-
208
- if (typeof e.payload?.proposalId === 'string') {
209
- const prop = s.activeProposals.find(p => p.id === e.payload!.proposalId);
210
- if (prop) executeProposal(prop, s, ctx, nowMs);
211
- } else {
212
- s.activeProposals.forEach((p) => executeProposal(p, s, ctx, nowMs));
213
- }
208
+ const nowMs =
209
+ typeof e.payload?.nowMs === 'number' ? (e.payload.nowMs as number) : Date.now();
210
+
211
+ if (typeof e.payload?.proposalId === 'string') {
212
+ const prop = s.activeProposals.find((p) => p.id === e.payload!.proposalId);
213
+ if (prop) executeProposal(prop, s, ctx, nowMs);
214
+ } else {
215
+ s.activeProposals.forEach((p) => executeProposal(p, s, ctx, nowMs));
216
+ }
214
217
  }
215
- }
218
+ },
216
219
  };
217
220
  }
@@ -27,19 +27,65 @@ export interface MarketplaceListingState {
27
27
  reviewCount: number;
28
28
  }
29
29
 
30
- const defaultConfig: MarketplaceListingConfig = { listingId: '', title: '', description: '', sellerAgentId: '', assetType: 'trait', price: 0, currency: 'USDC', pricingModel: 'fixed', royaltyPercent: 10, tags: [], licenseType: 'MIT' };
30
+ const defaultConfig: MarketplaceListingConfig = {
31
+ listingId: '',
32
+ title: '',
33
+ description: '',
34
+ sellerAgentId: '',
35
+ assetType: 'trait',
36
+ price: 0,
37
+ currency: 'USDC',
38
+ pricingModel: 'fixed',
39
+ royaltyPercent: 10,
40
+ tags: [],
41
+ licenseType: 'MIT',
42
+ };
31
43
 
32
44
  export function createMarketplaceListingHandler(): TraitHandler<MarketplaceListingConfig> {
33
- return { name: 'marketplace_listing', defaultConfig,
34
- onAttach(n: HSPlusNode, c: MarketplaceListingConfig, ctx: TraitContext) { n.__listingState = { status: 'draft' as ListingStatus, views: 0, purchases: 0, revenue: 0, rating: 0, reviewCount: 0 }; ctx.emit?.('listing:created', { title: c.title, price: c.price }); },
35
- onDetach(n: HSPlusNode, _c: MarketplaceListingConfig, ctx: TraitContext) { delete n.__listingState; ctx.emit?.('listing:removed'); },
45
+ return {
46
+ name: 'marketplace_listing',
47
+ defaultConfig,
48
+ onAttach(n: HSPlusNode, c: MarketplaceListingConfig, ctx: TraitContext) {
49
+ n.__listingState = {
50
+ status: 'draft' as ListingStatus,
51
+ views: 0,
52
+ purchases: 0,
53
+ revenue: 0,
54
+ rating: 0,
55
+ reviewCount: 0,
56
+ };
57
+ ctx.emit?.('listing:created', { title: c.title, price: c.price });
58
+ },
59
+ onDetach(n: HSPlusNode, _c: MarketplaceListingConfig, ctx: TraitContext) {
60
+ delete n.__listingState;
61
+ ctx.emit?.('listing:removed');
62
+ },
36
63
  onUpdate() {},
37
64
  onEvent(n: HSPlusNode, c: MarketplaceListingConfig, ctx: TraitContext, e: TraitEvent) {
38
- const s = n.__listingState as MarketplaceListingState | undefined; if (!s) return;
39
- if (e.type === 'listing:publish') { s.status = 'active'; ctx.emit?.('listing:published', { listingId: c.listingId }); }
40
- if (e.type === 'listing:purchase') { s.purchases++; s.revenue += c.price; ctx.emit?.('listing:sold', { buyer: e.payload?.buyerAgentId, revenue: s.revenue, royalty: c.price * c.royaltyPercent / 100 }); }
41
- if (e.type === 'listing:view') { s.views++; }
42
- if (e.type === 'listing:review') { const rating = (e.payload?.rating as number) ?? 5; s.rating = (s.rating * s.reviewCount + rating) / (s.reviewCount + 1); s.reviewCount++; ctx.emit?.('listing:reviewed', { avgRating: s.rating }); }
65
+ const s = n.__listingState as MarketplaceListingState | undefined;
66
+ if (!s) return;
67
+ if (e.type === 'listing:publish') {
68
+ s.status = 'active';
69
+ ctx.emit?.('listing:published', { listingId: c.listingId });
70
+ }
71
+ if (e.type === 'listing:purchase') {
72
+ s.purchases++;
73
+ s.revenue += c.price;
74
+ ctx.emit?.('listing:sold', {
75
+ buyer: e.payload?.buyerAgentId,
76
+ revenue: s.revenue,
77
+ royalty: (c.price * c.royaltyPercent) / 100,
78
+ });
79
+ }
80
+ if (e.type === 'listing:view') {
81
+ s.views++;
82
+ }
83
+ if (e.type === 'listing:review') {
84
+ const rating = (e.payload?.rating as number) ?? 5;
85
+ s.rating = (s.rating * s.reviewCount + rating) / (s.reviewCount + 1);
86
+ s.reviewCount++;
87
+ ctx.emit?.('listing:reviewed', { avgRating: s.rating });
88
+ }
43
89
  },
44
90
  };
45
91
  }
@@ -1,31 +1,76 @@
1
1
  /** @royalty_stream Trait — Revenue sharing and royalty distribution. @trait royalty_stream */
2
2
  import type { TraitHandler, HSPlusNode, TraitContext, TraitEvent } from './types';
3
3
 
4
- export interface RoyaltySplit { recipientId: string; percent: number; walletAddress?: string; }
5
- export interface RoyaltyStreamConfig { assetId: string; splits: RoyaltySplit[]; currency: string; minimumPayout: number; payoutFrequency: 'instant' | 'daily' | 'weekly' | 'monthly'; }
6
- export interface RoyaltyStreamState { totalCollected: number; totalDistributed: number; pendingPayout: number; distributionCount: number; }
4
+ export interface RoyaltySplit {
5
+ recipientId: string;
6
+ percent: number;
7
+ walletAddress?: string;
8
+ }
9
+ export interface RoyaltyStreamConfig {
10
+ assetId: string;
11
+ splits: RoyaltySplit[];
12
+ currency: string;
13
+ minimumPayout: number;
14
+ payoutFrequency: 'instant' | 'daily' | 'weekly' | 'monthly';
15
+ }
16
+ export interface RoyaltyStreamState {
17
+ totalCollected: number;
18
+ totalDistributed: number;
19
+ pendingPayout: number;
20
+ distributionCount: number;
21
+ }
7
22
 
8
- const defaultConfig: RoyaltyStreamConfig = { assetId: '', splits: [], currency: 'USDC', minimumPayout: 1, payoutFrequency: 'instant' };
23
+ const defaultConfig: RoyaltyStreamConfig = {
24
+ assetId: '',
25
+ splits: [],
26
+ currency: 'USDC',
27
+ minimumPayout: 1,
28
+ payoutFrequency: 'instant',
29
+ };
9
30
 
10
31
  export function createRoyaltyStreamHandler(): TraitHandler<RoyaltyStreamConfig> {
11
- return { name: 'royalty_stream', defaultConfig,
12
- onAttach(n: HSPlusNode, _c: RoyaltyStreamConfig, ctx: TraitContext) { n.__royaltyState = { totalCollected: 0, totalDistributed: 0, pendingPayout: 0, distributionCount: 0 }; ctx.emit?.('royalty:stream_created'); },
13
- onDetach(n: HSPlusNode, _c: RoyaltyStreamConfig, ctx: TraitContext) { delete n.__royaltyState; ctx.emit?.('royalty:stream_closed'); },
32
+ return {
33
+ name: 'royalty_stream',
34
+ defaultConfig,
35
+ onAttach(n: HSPlusNode, _c: RoyaltyStreamConfig, ctx: TraitContext) {
36
+ n.__royaltyState = {
37
+ totalCollected: 0,
38
+ totalDistributed: 0,
39
+ pendingPayout: 0,
40
+ distributionCount: 0,
41
+ };
42
+ ctx.emit?.('royalty:stream_created');
43
+ },
44
+ onDetach(n: HSPlusNode, _c: RoyaltyStreamConfig, ctx: TraitContext) {
45
+ delete n.__royaltyState;
46
+ ctx.emit?.('royalty:stream_closed');
47
+ },
14
48
  onUpdate() {},
15
49
  onEvent(n: HSPlusNode, c: RoyaltyStreamConfig, ctx: TraitContext, e: TraitEvent) {
16
- const s = n.__royaltyState as RoyaltyStreamState | undefined; if (!s) return;
50
+ const s = n.__royaltyState as RoyaltyStreamState | undefined;
51
+ if (!s) return;
17
52
  if (e.type === 'royalty:collect') {
18
53
  const amount = (e.payload?.amount as number) ?? 0;
19
- s.totalCollected += amount; s.pendingPayout += amount;
54
+ s.totalCollected += amount;
55
+ s.pendingPayout += amount;
20
56
  if (c.payoutFrequency === 'instant' && s.pendingPayout >= c.minimumPayout) {
21
- const distributions = c.splits.map(split => ({ recipient: split.recipientId, amount: s.pendingPayout * split.percent / 100 }));
22
- s.totalDistributed += s.pendingPayout; s.pendingPayout = 0; s.distributionCount++;
57
+ const distributions = c.splits.map((split) => ({
58
+ recipient: split.recipientId,
59
+ amount: (s.pendingPayout * split.percent) / 100,
60
+ }));
61
+ s.totalDistributed += s.pendingPayout;
62
+ s.pendingPayout = 0;
63
+ s.distributionCount++;
23
64
  ctx.emit?.('royalty:distributed', { distributions, total: s.totalDistributed });
24
- } else { ctx.emit?.('royalty:collected', { pending: s.pendingPayout }); }
65
+ } else {
66
+ ctx.emit?.('royalty:collected', { pending: s.pendingPayout });
67
+ }
25
68
  }
26
69
  if (e.type === 'royalty:flush') {
27
70
  if (s.pendingPayout > 0) {
28
- s.totalDistributed += s.pendingPayout; s.pendingPayout = 0; s.distributionCount++;
71
+ s.totalDistributed += s.pendingPayout;
72
+ s.pendingPayout = 0;
73
+ s.distributionCount++;
29
74
  ctx.emit?.('royalty:flushed', { totalDistributed: s.totalDistributed });
30
75
  }
31
76
  }
@@ -32,23 +32,38 @@ describe('FoundationDAOTrait', () => {
32
32
 
33
33
  handler.onAttach(node, config, { emit: (type) => emitted.push(type) });
34
34
 
35
- handler.onEvent(node, config, { emit: (type) => emitted.push(type) }, {
36
- type: 'dao:propose',
37
- payload: { title: 'Fund autonomous zone indexing' },
38
- });
35
+ handler.onEvent(
36
+ node,
37
+ config,
38
+ { emit: (type) => emitted.push(type) },
39
+ {
40
+ type: 'dao:propose',
41
+ payload: { title: 'Fund autonomous zone indexing' },
42
+ }
43
+ );
39
44
 
40
45
  const state = node.__daoState as any;
41
46
  const proposal = state.activeProposals[0];
42
47
 
43
- handler.onEvent(node, config, { emit: (type) => emitted.push(type) }, {
44
- type: 'dao:vote',
45
- payload: { proposalId: proposal.id, voterId: 'agent_a', support: true, weight: 2 },
46
- });
47
-
48
- handler.onEvent(node, config, { emit: (type) => emitted.push(type) }, {
49
- type: 'dao:vote',
50
- payload: { proposalId: proposal.id, voterId: 'agent_a', support: false, weight: 1 },
51
- });
48
+ handler.onEvent(
49
+ node,
50
+ config,
51
+ { emit: (type) => emitted.push(type) },
52
+ {
53
+ type: 'dao:vote',
54
+ payload: { proposalId: proposal.id, voterId: 'agent_a', support: true, weight: 2 },
55
+ }
56
+ );
57
+
58
+ handler.onEvent(
59
+ node,
60
+ config,
61
+ { emit: (type) => emitted.push(type) },
62
+ {
63
+ type: 'dao:vote',
64
+ payload: { proposalId: proposal.id, voterId: 'agent_a', support: false, weight: 1 },
65
+ }
66
+ );
52
67
 
53
68
  expect(proposal.votesFor).toBe(0);
54
69
  expect(proposal.votesAgainst).toBe(1);
@@ -71,28 +86,38 @@ describe('FoundationDAOTrait', () => {
71
86
  emit: (type, payload) => emitted.push({ type, payload }),
72
87
  });
73
88
 
74
- handler.onEvent(node, config, { emit: (type, payload) => emitted.push({ type, payload }) }, {
75
- type: 'dao:propose',
76
- payload: {
77
- title: 'Fund sovereign spatial zone Z1',
78
- zoneId: 'zone-z1',
79
- requestedAmountX402: 250000,
80
- },
81
- });
89
+ handler.onEvent(
90
+ node,
91
+ config,
92
+ { emit: (type, payload) => emitted.push({ type, payload }) },
93
+ {
94
+ type: 'dao:propose',
95
+ payload: {
96
+ title: 'Fund sovereign spatial zone Z1',
97
+ zoneId: 'zone-z1',
98
+ requestedAmountX402: 250000,
99
+ },
100
+ }
101
+ );
82
102
 
83
103
  const state = node.__daoState as any;
84
104
  const proposal = state.activeProposals[0];
85
105
 
86
- handler.onEvent(node, config, { emit: (type, payload) => emitted.push({ type, payload }) }, {
87
- type: 'dao:autonomous_vote',
88
- payload: {
89
- proposalId: proposal.id,
90
- agents: [
91
- { agentId: 'agent_a', support: true, weight: 2 },
92
- { agentId: 'agent_b', support: true, weight: 2 },
93
- ],
94
- },
95
- });
106
+ handler.onEvent(
107
+ node,
108
+ config,
109
+ { emit: (type, payload) => emitted.push({ type, payload }) },
110
+ {
111
+ type: 'dao:autonomous_vote',
112
+ payload: {
113
+ proposalId: proposal.id,
114
+ agents: [
115
+ { agentId: 'agent_a', support: true, weight: 2 },
116
+ { agentId: 'agent_b', support: true, weight: 2 },
117
+ ],
118
+ },
119
+ }
120
+ );
96
121
 
97
122
  expect(proposal.status).toBe('executed');
98
123
  expect(state.allocations).toHaveLength(1);
@@ -123,24 +148,34 @@ describe('FoundationDAOTrait', () => {
123
148
  const state = node.__daoState as any;
124
149
  state.treasuryBalanceX402 = 100;
125
150
 
126
- handler.onEvent(node, config, { emit: (type, payload) => emitted.push({ type, payload }) }, {
127
- type: 'dao:propose',
128
- payload: {
129
- title: 'Huge funding ask',
130
- zoneId: 'zone-z2',
131
- requestedAmountX402: 5000,
132
- },
133
- });
151
+ handler.onEvent(
152
+ node,
153
+ config,
154
+ { emit: (type, payload) => emitted.push({ type, payload }) },
155
+ {
156
+ type: 'dao:propose',
157
+ payload: {
158
+ title: 'Huge funding ask',
159
+ zoneId: 'zone-z2',
160
+ requestedAmountX402: 5000,
161
+ },
162
+ }
163
+ );
134
164
 
135
165
  const proposal = state.activeProposals[0];
136
166
 
137
- handler.onEvent(node, config, { emit: (type, payload) => emitted.push({ type, payload }) }, {
138
- type: 'dao:autonomous_vote',
139
- payload: {
140
- proposalId: proposal.id,
141
- agents: [{ agentId: 'agent_a', support: true, weight: 5 }],
142
- },
143
- });
167
+ handler.onEvent(
168
+ node,
169
+ config,
170
+ { emit: (type, payload) => emitted.push({ type, payload }) },
171
+ {
172
+ type: 'dao:autonomous_vote',
173
+ payload: {
174
+ proposalId: proposal.id,
175
+ agents: [{ agentId: 'agent_a', support: true, weight: 5 }],
176
+ },
177
+ }
178
+ );
144
179
 
145
180
  expect(proposal.status).toBe('passed');
146
181
  expect(state.allocations).toHaveLength(0);
@@ -1,4 +1,22 @@
1
- export interface HSPlusNode { id?: string; properties?: Record<string, unknown>; [key: string]: unknown; }
2
- export interface TraitContext { emit?: (event: string, payload?: unknown) => void; [key: string]: unknown; }
3
- export interface TraitEvent { type: string; payload?: Record<string, unknown>; [key: string]: unknown; }
4
- export interface TraitHandler<T = unknown> { name: string; defaultConfig: T; onAttach(n: HSPlusNode, c: T, ctx: TraitContext): void; onDetach(n: HSPlusNode, c: T, ctx: TraitContext): void; onUpdate(n: HSPlusNode, c: T, ctx: TraitContext, d: number): void; onEvent(n: HSPlusNode, c: T, ctx: TraitContext, e: TraitEvent): void; }
1
+ export interface HSPlusNode {
2
+ id?: string;
3
+ properties?: Record<string, unknown>;
4
+ [key: string]: unknown;
5
+ }
6
+ export interface TraitContext {
7
+ emit?: (event: string, payload?: unknown) => void;
8
+ [key: string]: unknown;
9
+ }
10
+ export interface TraitEvent {
11
+ type: string;
12
+ payload?: Record<string, unknown>;
13
+ [key: string]: unknown;
14
+ }
15
+ export interface TraitHandler<T = unknown> {
16
+ name: string;
17
+ defaultConfig: T;
18
+ onAttach(n: HSPlusNode, c: T, ctx: TraitContext): void;
19
+ onDetach(n: HSPlusNode, c: T, ctx: TraitContext): void;
20
+ onUpdate(n: HSPlusNode, c: T, ctx: TraitContext, d: number): void;
21
+ onEvent(n: HSPlusNode, c: T, ctx: TraitContext, e: TraitEvent): void;
22
+ }
package/tsconfig.json CHANGED
@@ -1 +1,5 @@
1
- { "extends": "../../../tsconfig.json", "compilerOptions": { "outDir": "dist", "rootDir": "src", "declaration": true }, "include": ["src"] }
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "compilerOptions": { "outDir": "dist", "rootDir": "src", "declaration": true },
4
+ "include": ["src"]
5
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025-2026 HoloScript Contributors
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.