Starting a Melon Fund requires 9 Ethereum transactions. Together, these transactions instantiate the hub and spoke contracts that will serve as the foundation for your fund. In order to begin this sequence of transactions, you must first decide on the parameters that will govern your fund. The first transaction must be initiated by the fund's manager. All subsequent steps can be called by anyone.
Step | Contract | User |
|
| fund manager |
|
| anyone |
|
| anyone |
|
| anyone |
|
| anyone |
|
| anyone |
|
| anyone |
|
| anyone |
|
| anyone |
This example requires an environment instance as described here.
import { DeployedEnvironment, Version } from '@melonproject/melonjs';// instantiate the current version of the Melon Fund Factoryconst factory = new Version(environment, environment.deployment.melon.addr.Version);// declare the necessary variables:// the fund manager's addressconst managerAddress = '0x5b8677fb951517d55b224fbc07cd7e3ffb075203';// specify the gas price (refer to http://ethgasstation.info/)const gasPrice = 30000000000;// currently all funds are denominated in WETHconst denominationAddress = environment.getToken('WETH');// use the environment to generate an array of token addressesconst defaultAssets = environment.tokens.map(token => token.address);// declare the management feeconst managementFeeRate = new BigNumber(2).multipliedBy('1e18');// declare the performance feeconst performanceFeeRate = new BigNumber(20).multipliedBy('1e18');// declare the management fee period. In this case, the management fee is always redeemableconst managementFeePeriod = new BigNumber(0);// declare the performance fee period. In this case the performance fee is redeemable every 90 daysconst performanceFeePeriod = new BigNumber(90 * 24 * 60 * 60);// an array of decentralized exchange addressesconst exchanges = environment.exchanges.map(exchange => exchange.exchange);// an array of those exchanges' corresponding adapter contract addressesconst adapters = environment.exchanges.map(exchange => exchange.adapter);// pass your newly-defined variables to the `beginSetup` function to create the transaction and you're on your way.{const transaction = factory.beginSetup(managerAddress, {name: 'TestFund',fees: [environment.deployment.melon.addr.ManagementFee, environment.deployment.melon.addr.PerformanceFee],feeRates: [managementFeeRate, performanceFeeRate],feePeriods: [managementFeePeriod, performanceFeePeriod],exchanges: exchanges,adapters: adapters,denominationAsset: denominationAssetAddress,defaultAssets: defaultAssets,});const opts = await transaction.prepare({gasPrice});const receipt = await transaction.send(opts);}// Now, you'll create the spoke contracts individually:{const transaction = factory.createAccounting(managerAddress);const opts = await transaction.prepare({gasPrice});const receipt = await transaction.send(opts);}{const transaction = factory.createFeeManager(managerAddress);const opts = await transaction.prepare({gasPrice});const receipt = await transaction.send(opts);}{const transaction = factory.createParticipation(managerAddress);const opts = await transaction.prepare({gasPrice});const receipt = await transaction.send(opts);}{const transaction = factory.createPolicyManager(managerAddress);const opts = await transaction.prepare({gasPrice});const receipt = await transaction.send(opts);{const transaction = factory.createShares(managerAddress);const opts = await transaction.prepare({gasPrice});const receipt = await transaction.send(opts);}{const transaction = factory.createTrading(managerAddress);const opts = await transaction.prepare({gasPrice});const receipt = await transaction.send(opts);}{const transaction = factory.createVault(managerAddress);const opts = await transaction.prepare({gasPrice});const receipt = await transaction.send(opts);}// Finally, call completeSetup to finish up.{const transaction = factory.completeSetup(managerAddress);const opts = await transaction.prepare({gasPrice});const receipt = await transaction.send(opts);}
At this point, you have a fully capable Melon Fund.