holosphere 2.0.0-alpha2 → 2.0.0-alpha5
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/dist/2019-D2OG2idw.js +6680 -0
- package/dist/2019-D2OG2idw.js.map +1 -0
- package/dist/2019-EION3wKo.cjs +8 -0
- package/dist/2019-EION3wKo.cjs.map +1 -0
- package/dist/_commonjsHelpers-C37NGDzP.cjs +2 -0
- package/dist/_commonjsHelpers-C37NGDzP.cjs.map +1 -0
- package/dist/_commonjsHelpers-CUmg6egw.js +7 -0
- package/dist/_commonjsHelpers-CUmg6egw.js.map +1 -0
- package/dist/browser-BSniCNqO.js +3058 -0
- package/dist/browser-BSniCNqO.js.map +1 -0
- package/dist/browser-Cq59Ij19.cjs +2 -0
- package/dist/browser-Cq59Ij19.cjs.map +1 -0
- package/dist/cjs/holosphere.cjs +1 -1
- package/dist/esm/holosphere.js +50 -53
- package/dist/index-BG8FStkt.cjs +12 -0
- package/dist/index-BG8FStkt.cjs.map +1 -0
- package/dist/index-Bbey4GkP.js +37869 -0
- package/dist/index-Bbey4GkP.js.map +1 -0
- package/dist/index-Cp3xctq8.js +15104 -0
- package/dist/index-Cp3xctq8.js.map +1 -0
- package/dist/index-hfVGRwSr.cjs +5 -0
- package/dist/index-hfVGRwSr.cjs.map +1 -0
- package/dist/indexeddb-storage-BD70pN7q.cjs +2 -0
- package/dist/indexeddb-storage-BD70pN7q.cjs.map +1 -0
- package/dist/{indexeddb-storage-CMW4qRQS.js → indexeddb-storage-Bjg84U5R.js} +49 -13
- package/dist/indexeddb-storage-Bjg84U5R.js.map +1 -0
- package/dist/{memory-storage-DQzcAZlf.js → memory-storage-CD0XFayE.js} +6 -2
- package/dist/memory-storage-CD0XFayE.js.map +1 -0
- package/dist/{memory-storage-DmePEP2q.cjs → memory-storage-DmMyJtOo.cjs} +2 -2
- package/dist/memory-storage-DmMyJtOo.cjs.map +1 -0
- package/dist/{secp256k1-vOXp40Fx.js → secp256k1-69sS9O-P.js} +2 -393
- package/dist/secp256k1-69sS9O-P.js.map +1 -0
- package/dist/secp256k1-TcN6vWGh.cjs +12 -0
- package/dist/secp256k1-TcN6vWGh.cjs.map +1 -0
- package/docs/CONTRACTS.md +797 -0
- package/examples/demo.html +47 -0
- package/package.json +10 -5
- package/src/contracts/abis/Appreciative.json +1280 -0
- package/src/contracts/abis/AppreciativeFactory.json +101 -0
- package/src/contracts/abis/Bundle.json +1435 -0
- package/src/contracts/abis/BundleFactory.json +106 -0
- package/src/contracts/abis/Holon.json +881 -0
- package/src/contracts/abis/Holons.json +330 -0
- package/src/contracts/abis/Managed.json +1262 -0
- package/src/contracts/abis/ManagedFactory.json +149 -0
- package/src/contracts/abis/Membrane.json +261 -0
- package/src/contracts/abis/Splitter.json +1624 -0
- package/src/contracts/abis/SplitterFactory.json +220 -0
- package/src/contracts/abis/TestToken.json +321 -0
- package/src/contracts/abis/Zoned.json +1461 -0
- package/src/contracts/abis/ZonedFactory.json +154 -0
- package/src/contracts/chain-manager.js +375 -0
- package/src/contracts/deployer.js +443 -0
- package/src/contracts/event-listener.js +507 -0
- package/src/contracts/holon-contracts.js +344 -0
- package/src/contracts/index.js +83 -0
- package/src/contracts/networks.js +224 -0
- package/src/contracts/operations.js +670 -0
- package/src/contracts/queries.js +589 -0
- package/src/core/holosphere.js +453 -1
- package/src/crypto/nostr-utils.js +263 -0
- package/src/federation/handshake.js +455 -0
- package/src/federation/hologram.js +1 -1
- package/src/hierarchical/upcast.js +6 -5
- package/src/index.js +463 -1939
- package/src/lib/ai-methods.js +308 -0
- package/src/lib/contract-methods.js +293 -0
- package/src/lib/errors.js +23 -0
- package/src/lib/federation-methods.js +238 -0
- package/src/lib/index.js +26 -0
- package/src/spatial/h3-operations.js +2 -2
- package/src/storage/backends/gundb-backend.js +377 -46
- package/src/storage/global-tables.js +28 -1
- package/src/storage/gun-auth.js +303 -0
- package/src/storage/gun-federation.js +776 -0
- package/src/storage/gun-references.js +198 -0
- package/src/storage/gun-schema.js +291 -0
- package/src/storage/gun-wrapper.js +347 -31
- package/src/storage/indexeddb-storage.js +49 -11
- package/src/storage/memory-storage.js +5 -0
- package/src/storage/nostr-async.js +194 -37
- package/src/storage/nostr-client.js +580 -51
- package/src/storage/persistent-storage.js +6 -1
- package/src/storage/unified-storage.js +119 -0
- package/src/subscriptions/manager.js +1 -1
- package/types/index.d.ts +133 -0
- package/dist/index-CDfIuXew.js +0 -15974
- package/dist/index-CDfIuXew.js.map +0 -1
- package/dist/index-ifOgtDvd.cjs +0 -3
- package/dist/index-ifOgtDvd.cjs.map +0 -1
- package/dist/indexeddb-storage-CMW4qRQS.js.map +0 -1
- package/dist/indexeddb-storage-DLZOgetM.cjs +0 -2
- package/dist/indexeddb-storage-DLZOgetM.cjs.map +0 -1
- package/dist/memory-storage-DQzcAZlf.js.map +0 -1
- package/dist/memory-storage-DmePEP2q.cjs.map +0 -1
- package/dist/secp256k1-CP0ZkpAx.cjs +0 -13
- package/dist/secp256k1-CP0ZkpAx.cjs.map +0 -1
- package/dist/secp256k1-vOXp40Fx.js.map +0 -1
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ContractDeployer - 1-Click deployment for Holosphere smart contracts
|
|
3
|
+
* Deploys all factories, registry, and individual holon contracts
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Import ABIs
|
|
7
|
+
import SplitterABI from './abis/Splitter.json' with { type: 'json' };
|
|
8
|
+
import ManagedABI from './abis/Managed.json' with { type: 'json' };
|
|
9
|
+
import ZonedABI from './abis/Zoned.json' with { type: 'json' };
|
|
10
|
+
import AppreciativeABI from './abis/Appreciative.json' with { type: 'json' };
|
|
11
|
+
import BundleABI from './abis/Bundle.json' with { type: 'json' };
|
|
12
|
+
import HolonsABI from './abis/Holons.json' with { type: 'json' };
|
|
13
|
+
import SplitterFactoryABI from './abis/SplitterFactory.json' with { type: 'json' };
|
|
14
|
+
import ManagedFactoryABI from './abis/ManagedFactory.json' with { type: 'json' };
|
|
15
|
+
import ZonedFactoryABI from './abis/ZonedFactory.json' with { type: 'json' };
|
|
16
|
+
import AppreciativeFactoryABI from './abis/AppreciativeFactory.json' with { type: 'json' };
|
|
17
|
+
import BundleFactoryABI from './abis/BundleFactory.json' with { type: 'json' };
|
|
18
|
+
import TestTokenABI from './abis/TestToken.json' with { type: 'json' };
|
|
19
|
+
|
|
20
|
+
import { getTxUrl, getAddressUrl } from './networks.js';
|
|
21
|
+
|
|
22
|
+
// Export ABIs for external use
|
|
23
|
+
export const ABIs = {
|
|
24
|
+
Splitter: SplitterABI,
|
|
25
|
+
Managed: ManagedABI,
|
|
26
|
+
Zoned: ZonedABI,
|
|
27
|
+
Appreciative: AppreciativeABI,
|
|
28
|
+
Bundle: BundleABI,
|
|
29
|
+
Holons: HolonsABI,
|
|
30
|
+
SplitterFactory: SplitterFactoryABI,
|
|
31
|
+
ManagedFactory: ManagedFactoryABI,
|
|
32
|
+
ZonedFactory: ZonedFactoryABI,
|
|
33
|
+
AppreciativeFactory: AppreciativeFactoryABI,
|
|
34
|
+
BundleFactory: BundleFactoryABI,
|
|
35
|
+
TestToken: TestTokenABI
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export class ContractDeployer {
|
|
39
|
+
constructor(chainManager) {
|
|
40
|
+
this.chainManager = chainManager;
|
|
41
|
+
this.deployedContracts = {};
|
|
42
|
+
this.ethers = null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Load ethers from chain manager
|
|
47
|
+
* @private
|
|
48
|
+
*/
|
|
49
|
+
async _loadEthers() {
|
|
50
|
+
if (!this.ethers) {
|
|
51
|
+
this.ethers = await import('ethers');
|
|
52
|
+
}
|
|
53
|
+
return this.ethers;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 1-CLICK DEPLOY: Deploy entire Holosphere contract infrastructure
|
|
58
|
+
* Deploys: All factories + Holons registry + optional TestToken
|
|
59
|
+
*
|
|
60
|
+
* @param {Object} options - Deployment options
|
|
61
|
+
* @param {string} [options.botAddress] - Bot address for managed operations (defaults to deployer)
|
|
62
|
+
* @param {string} [options.testTokenSupply='1000000'] - Initial supply for test token (in whole tokens)
|
|
63
|
+
* @param {boolean} [options.deployTestToken=true] - Whether to deploy test token
|
|
64
|
+
* @param {Function} [options.onProgress] - Callback for deployment progress
|
|
65
|
+
* @returns {Promise<Object>} Deployed contract addresses and instances
|
|
66
|
+
*/
|
|
67
|
+
async deployAll(options = {}) {
|
|
68
|
+
const ethers = await this._loadEthers();
|
|
69
|
+
const signer = this.chainManager.getSigner();
|
|
70
|
+
const deployerAddress = await signer.getAddress();
|
|
71
|
+
|
|
72
|
+
const botAddress = options.botAddress || deployerAddress;
|
|
73
|
+
const testTokenSupply = options.testTokenSupply || '1000000';
|
|
74
|
+
const deployTestToken = options.deployTestToken !== false;
|
|
75
|
+
const onProgress = options.onProgress || (() => {});
|
|
76
|
+
|
|
77
|
+
const deployment = {
|
|
78
|
+
network: this.chainManager.networkName,
|
|
79
|
+
chainId: this.chainManager.getChainId(),
|
|
80
|
+
deployer: deployerAddress,
|
|
81
|
+
botAddress,
|
|
82
|
+
timestamp: new Date().toISOString(),
|
|
83
|
+
contracts: {}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
// Step 1: Deploy ManagedFactory
|
|
88
|
+
onProgress({ step: 1, total: deployTestToken ? 8 : 7, message: 'Deploying ManagedFactory...' });
|
|
89
|
+
const managedFactory = await this._deployContract(
|
|
90
|
+
ManagedFactoryABI.abi,
|
|
91
|
+
ManagedFactoryABI.bytecode,
|
|
92
|
+
[botAddress]
|
|
93
|
+
);
|
|
94
|
+
deployment.contracts.managedFactory = managedFactory.address;
|
|
95
|
+
onProgress({ step: 1, done: true, address: managedFactory.address });
|
|
96
|
+
|
|
97
|
+
// Step 2: Deploy ZonedFactory
|
|
98
|
+
onProgress({ step: 2, total: deployTestToken ? 8 : 7, message: 'Deploying ZonedFactory...' });
|
|
99
|
+
const zonedFactory = await this._deployContract(
|
|
100
|
+
ZonedFactoryABI.abi,
|
|
101
|
+
ZonedFactoryABI.bytecode,
|
|
102
|
+
[botAddress]
|
|
103
|
+
);
|
|
104
|
+
deployment.contracts.zonedFactory = zonedFactory.address;
|
|
105
|
+
onProgress({ step: 2, done: true, address: zonedFactory.address });
|
|
106
|
+
|
|
107
|
+
// Step 3: Deploy SplitterFactory
|
|
108
|
+
onProgress({ step: 3, total: deployTestToken ? 8 : 7, message: 'Deploying SplitterFactory...' });
|
|
109
|
+
const splitterFactory = await this._deployContract(
|
|
110
|
+
SplitterFactoryABI.abi,
|
|
111
|
+
SplitterFactoryABI.bytecode,
|
|
112
|
+
[]
|
|
113
|
+
);
|
|
114
|
+
deployment.contracts.splitterFactory = splitterFactory.address;
|
|
115
|
+
onProgress({ step: 3, done: true, address: splitterFactory.address });
|
|
116
|
+
|
|
117
|
+
// Step 4: Deploy AppreciativeFactory
|
|
118
|
+
onProgress({ step: 4, total: deployTestToken ? 8 : 7, message: 'Deploying AppreciativeFactory...' });
|
|
119
|
+
const appreciativeFactory = await this._deployContract(
|
|
120
|
+
AppreciativeFactoryABI.abi,
|
|
121
|
+
AppreciativeFactoryABI.bytecode,
|
|
122
|
+
[]
|
|
123
|
+
);
|
|
124
|
+
deployment.contracts.appreciativeFactory = appreciativeFactory.address;
|
|
125
|
+
onProgress({ step: 4, done: true, address: appreciativeFactory.address });
|
|
126
|
+
|
|
127
|
+
// Step 5: Deploy BundleFactory
|
|
128
|
+
onProgress({ step: 5, total: deployTestToken ? 8 : 7, message: 'Deploying BundleFactory...' });
|
|
129
|
+
const bundleFactory = await this._deployContract(
|
|
130
|
+
BundleFactoryABI.abi,
|
|
131
|
+
BundleFactoryABI.bytecode,
|
|
132
|
+
[]
|
|
133
|
+
);
|
|
134
|
+
deployment.contracts.bundleFactory = bundleFactory.address;
|
|
135
|
+
onProgress({ step: 5, done: true, address: bundleFactory.address });
|
|
136
|
+
|
|
137
|
+
// Step 6: Deploy Holons (Central Registry)
|
|
138
|
+
onProgress({ step: 6, total: deployTestToken ? 8 : 7, message: 'Deploying Holons Registry...' });
|
|
139
|
+
const holons = await this._deployContract(
|
|
140
|
+
HolonsABI.abi,
|
|
141
|
+
HolonsABI.bytecode,
|
|
142
|
+
[]
|
|
143
|
+
);
|
|
144
|
+
deployment.contracts.holons = holons.address;
|
|
145
|
+
onProgress({ step: 6, done: true, address: holons.address });
|
|
146
|
+
|
|
147
|
+
// Step 7: Configure Holons Registry
|
|
148
|
+
onProgress({ step: 7, total: deployTestToken ? 8 : 7, message: 'Configuring Holons Registry...' });
|
|
149
|
+
|
|
150
|
+
// Set factories
|
|
151
|
+
await holons.contract.setFactories(managedFactory.address, zonedFactory.address);
|
|
152
|
+
|
|
153
|
+
// Register flavors
|
|
154
|
+
await holons.contract.newFlavor('Splitter', splitterFactory.address);
|
|
155
|
+
await holons.contract.newFlavor('Managed', managedFactory.address);
|
|
156
|
+
await holons.contract.newFlavor('Zoned', zonedFactory.address);
|
|
157
|
+
await holons.contract.newFlavor('Appreciative', appreciativeFactory.address);
|
|
158
|
+
await holons.contract.newFlavor('Bundle', bundleFactory.address);
|
|
159
|
+
|
|
160
|
+
onProgress({ step: 7, done: true, message: 'Registry configured' });
|
|
161
|
+
|
|
162
|
+
// Step 8: Deploy TestToken (optional)
|
|
163
|
+
if (deployTestToken) {
|
|
164
|
+
onProgress({ step: 8, total: 8, message: 'Deploying TestToken...' });
|
|
165
|
+
const supply = ethers.parseEther(testTokenSupply);
|
|
166
|
+
const testToken = await this._deployContract(
|
|
167
|
+
TestTokenABI.abi,
|
|
168
|
+
TestTokenABI.bytecode,
|
|
169
|
+
[supply]
|
|
170
|
+
);
|
|
171
|
+
deployment.contracts.testToken = testToken.address;
|
|
172
|
+
onProgress({ step: 8, done: true, address: testToken.address });
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Store deployed contracts
|
|
176
|
+
this.deployedContracts = deployment.contracts;
|
|
177
|
+
|
|
178
|
+
// Add explorer URLs
|
|
179
|
+
deployment.explorerUrls = {};
|
|
180
|
+
for (const [name, address] of Object.entries(deployment.contracts)) {
|
|
181
|
+
const url = getAddressUrl(deployment.network, address);
|
|
182
|
+
if (url) deployment.explorerUrls[name] = url;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return deployment;
|
|
186
|
+
|
|
187
|
+
} catch (error) {
|
|
188
|
+
throw new Error(`Deployment failed: ${error.message}`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Deploy a Splitter contract for a holon (fractal ownership)
|
|
194
|
+
* @param {string} holonId - Holon identifier
|
|
195
|
+
* @param {string} name - Contract display name
|
|
196
|
+
* @param {number} [splitPercentage=70] - Internal/External split (e.g., 70 = 70% internal, 30% external)
|
|
197
|
+
* @param {Object} [options] - Additional options
|
|
198
|
+
* @returns {Promise<{contract, address, txHash}>}
|
|
199
|
+
*/
|
|
200
|
+
async deploySplitter(holonId, name, splitPercentage = 70, options = {}) {
|
|
201
|
+
const signer = this.chainManager.getSigner();
|
|
202
|
+
const deployerAddress = await signer.getAddress();
|
|
203
|
+
|
|
204
|
+
const creatorUserId = options.creatorUserId || holonId;
|
|
205
|
+
const managedFactory = options.managedFactory || this.deployedContracts.managedFactory;
|
|
206
|
+
const zonedFactory = options.zonedFactory || this.deployedContracts.zonedFactory;
|
|
207
|
+
|
|
208
|
+
if (!managedFactory || !zonedFactory) {
|
|
209
|
+
throw new Error('Factories not deployed. Run deployAll() first or provide factory addresses.');
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const result = await this._deployContract(
|
|
213
|
+
SplitterABI.abi,
|
|
214
|
+
SplitterABI.bytecode,
|
|
215
|
+
[deployerAddress, creatorUserId, name, splitPercentage, managedFactory, zonedFactory]
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
// Configure the split
|
|
219
|
+
await result.contract.setContractSplit(splitPercentage, 100 - splitPercentage);
|
|
220
|
+
|
|
221
|
+
// Create child contracts
|
|
222
|
+
await result.contract.createManagedContract(creatorUserId, name, 0);
|
|
223
|
+
await result.contract.createZonedContract(creatorUserId, name, 6); // 6 zones default
|
|
224
|
+
|
|
225
|
+
return {
|
|
226
|
+
...result,
|
|
227
|
+
holonId,
|
|
228
|
+
type: 'Splitter',
|
|
229
|
+
splitPercentage
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Deploy a Managed contract (appreciation-based distribution)
|
|
235
|
+
* @param {string} name - Contract name
|
|
236
|
+
* @param {Object} [options] - Additional options
|
|
237
|
+
* @returns {Promise<{contract, address, txHash}>}
|
|
238
|
+
*/
|
|
239
|
+
async deployManaged(name, options = {}) {
|
|
240
|
+
const signer = this.chainManager.getSigner();
|
|
241
|
+
const deployerAddress = await signer.getAddress();
|
|
242
|
+
const botAddress = options.botAddress || deployerAddress;
|
|
243
|
+
|
|
244
|
+
const result = await this._deployContract(
|
|
245
|
+
ManagedABI.abi,
|
|
246
|
+
ManagedABI.bytecode,
|
|
247
|
+
[deployerAddress, name, botAddress]
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
return {
|
|
251
|
+
...result,
|
|
252
|
+
type: 'Managed'
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Deploy a Zoned contract (tier-based distribution)
|
|
258
|
+
* @param {string} name - Contract name
|
|
259
|
+
* @param {number} [nZones=6] - Number of zones
|
|
260
|
+
* @param {Object} [options] - Additional options
|
|
261
|
+
* @returns {Promise<{contract, address, txHash}>}
|
|
262
|
+
*/
|
|
263
|
+
async deployZoned(name, nZones = 6, options = {}) {
|
|
264
|
+
const signer = this.chainManager.getSigner();
|
|
265
|
+
const deployerAddress = await signer.getAddress();
|
|
266
|
+
const botAddress = options.botAddress || deployerAddress;
|
|
267
|
+
const creatorUserId = options.creatorUserId || 'creator';
|
|
268
|
+
|
|
269
|
+
const result = await this._deployContract(
|
|
270
|
+
ZonedABI.abi,
|
|
271
|
+
ZonedABI.bytecode,
|
|
272
|
+
[creatorUserId, deployerAddress, name, nZones, botAddress]
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
return {
|
|
276
|
+
...result,
|
|
277
|
+
type: 'Zoned',
|
|
278
|
+
nZones
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Deploy an Appreciative contract (peer-to-peer appreciation)
|
|
284
|
+
* @param {string} name - Contract name
|
|
285
|
+
* @param {string} creatorUserId - Creator's user ID
|
|
286
|
+
* @param {Object} [options] - Additional options
|
|
287
|
+
* @returns {Promise<{contract, address, txHash}>}
|
|
288
|
+
*/
|
|
289
|
+
async deployAppreciative(name, creatorUserId, options = {}) {
|
|
290
|
+
const signer = this.chainManager.getSigner();
|
|
291
|
+
const deployerAddress = await signer.getAddress();
|
|
292
|
+
|
|
293
|
+
const result = await this._deployContract(
|
|
294
|
+
AppreciativeABI.abi,
|
|
295
|
+
AppreciativeABI.bytecode,
|
|
296
|
+
[name, creatorUserId, deployerAddress]
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
return {
|
|
300
|
+
...result,
|
|
301
|
+
type: 'Appreciative'
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Deploy a Bundle contract (2-way split with steepness)
|
|
307
|
+
* @param {string} name - Contract name
|
|
308
|
+
* @param {number} [steepness=500000000000000000n] - Steepness factor (0.5e18 = 50% decay)
|
|
309
|
+
* @param {number} [nZones=6] - Number of zones
|
|
310
|
+
* @param {Object} [options] - Additional options
|
|
311
|
+
* @returns {Promise<{contract, address, txHash}>}
|
|
312
|
+
*/
|
|
313
|
+
async deployBundle(name, steepness, nZones = 6, options = {}) {
|
|
314
|
+
const ethers = await this._loadEthers();
|
|
315
|
+
const signer = this.chainManager.getSigner();
|
|
316
|
+
const deployerAddress = await signer.getAddress();
|
|
317
|
+
const creatorUserId = options.creatorUserId || 'creator';
|
|
318
|
+
|
|
319
|
+
// Default steepness: 0.5e18 (50% decay per zone)
|
|
320
|
+
const steepnessValue = steepness || ethers.parseEther('0.5');
|
|
321
|
+
|
|
322
|
+
const result = await this._deployContract(
|
|
323
|
+
BundleABI.abi,
|
|
324
|
+
BundleABI.bytecode,
|
|
325
|
+
[deployerAddress, creatorUserId, name, steepnessValue, nZones]
|
|
326
|
+
);
|
|
327
|
+
|
|
328
|
+
return {
|
|
329
|
+
...result,
|
|
330
|
+
type: 'Bundle',
|
|
331
|
+
steepness: steepnessValue,
|
|
332
|
+
nZones
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Deploy a TestToken (ERC20 for testing)
|
|
338
|
+
* @param {string} [initialSupply='1000000'] - Initial supply in whole tokens
|
|
339
|
+
* @returns {Promise<{contract, address, txHash}>}
|
|
340
|
+
*/
|
|
341
|
+
async deployTestToken(initialSupply = '1000000') {
|
|
342
|
+
const ethers = await this._loadEthers();
|
|
343
|
+
const supply = ethers.parseEther(initialSupply);
|
|
344
|
+
|
|
345
|
+
const result = await this._deployContract(
|
|
346
|
+
TestTokenABI.abi,
|
|
347
|
+
TestTokenABI.bytecode,
|
|
348
|
+
[supply]
|
|
349
|
+
);
|
|
350
|
+
|
|
351
|
+
return {
|
|
352
|
+
...result,
|
|
353
|
+
type: 'TestToken',
|
|
354
|
+
initialSupply
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Create a holon bundle through the Holons registry
|
|
360
|
+
* @param {string} creatorUserId - Creator's user ID
|
|
361
|
+
* @param {string} name - Bundle name
|
|
362
|
+
* @param {number} [parameter=70] - Split parameter
|
|
363
|
+
* @returns {Promise<{address, txHash}>}
|
|
364
|
+
*/
|
|
365
|
+
async createHolonBundle(creatorUserId, name, parameter = 70) {
|
|
366
|
+
if (!this.deployedContracts.holons) {
|
|
367
|
+
throw new Error('Holons registry not deployed. Run deployAll() first.');
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
const holons = await this.chainManager.getContract(
|
|
371
|
+
this.deployedContracts.holons,
|
|
372
|
+
HolonsABI.abi
|
|
373
|
+
);
|
|
374
|
+
|
|
375
|
+
const tx = await holons.newHolonBundle(creatorUserId, name, parameter);
|
|
376
|
+
const receipt = await tx.wait();
|
|
377
|
+
|
|
378
|
+
// Get the created address from events
|
|
379
|
+
const event = receipt.logs.find(log => {
|
|
380
|
+
try {
|
|
381
|
+
const parsed = holons.interface.parseLog(log);
|
|
382
|
+
return parsed?.name === 'NewHolon';
|
|
383
|
+
} catch {
|
|
384
|
+
return false;
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
const address = event ? holons.interface.parseLog(event).args.addr : await holons.toAddress(name);
|
|
389
|
+
|
|
390
|
+
return {
|
|
391
|
+
address,
|
|
392
|
+
txHash: receipt.hash,
|
|
393
|
+
name,
|
|
394
|
+
creatorUserId
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Get contract instance by address
|
|
400
|
+
* @param {string} address - Contract address
|
|
401
|
+
* @param {string} type - Contract type (Splitter, Managed, Zoned, etc.)
|
|
402
|
+
* @returns {Promise<Contract>}
|
|
403
|
+
*/
|
|
404
|
+
async getContract(address, type) {
|
|
405
|
+
const abi = ABIs[type];
|
|
406
|
+
if (!abi) {
|
|
407
|
+
throw new Error(`Unknown contract type: ${type}`);
|
|
408
|
+
}
|
|
409
|
+
return this.chainManager.getContract(address, abi.abi);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Get deployed contract addresses
|
|
414
|
+
* @returns {Object}
|
|
415
|
+
*/
|
|
416
|
+
getDeployedAddresses() {
|
|
417
|
+
return { ...this.deployedContracts };
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* Load previously deployed contracts
|
|
422
|
+
* @param {Object} addresses - Contract addresses
|
|
423
|
+
*/
|
|
424
|
+
loadDeployedAddresses(addresses) {
|
|
425
|
+
this.deployedContracts = { ...addresses };
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* Internal: Deploy a contract
|
|
430
|
+
* @private
|
|
431
|
+
*/
|
|
432
|
+
async _deployContract(abi, bytecode, constructorArgs) {
|
|
433
|
+
const result = await this.chainManager.deployContract(abi, bytecode, constructorArgs);
|
|
434
|
+
return {
|
|
435
|
+
contract: result.contract,
|
|
436
|
+
address: result.address,
|
|
437
|
+
txHash: result.txHash,
|
|
438
|
+
explorerUrl: getAddressUrl(this.chainManager.networkName, result.address)
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
export default ContractDeployer;
|