Refactoring
We need a better library. The goal is for js developers to have a good experience.
Topics:
- do all those classes make sense?
- we need to restructure the files. We copied the structure from the contracts, we don't want that
- we need better flows/processes in place for building the packages so we can have an small optimized library
First proposals for the refactoring:
- Refactor folder names and file position in folders.
\poolsfolder must be renamed - Move
ConfigHelperfrom to\utilsto\config - Move
interfacetypes to\@types - Simplify imports in
\srcfiles - Are the ABI parameters necessary in Class constructors? Or can we use the default ABI?
- Move
getErcCreationParams()function toNFTFactory. It’s only used in this class - Move
getFreOrderParams()function toDatatoken. It’s only used in this class - Move
getFreCreationParams()function toDatatoken. It’s only used in this class - Move
getPoolCreationParams()function toDatatoken. It’s only used in this class - Move
getData()function toProvider. It’s only used in this class - Move all
\utils\ConversionTypeHelperfunctions toProvider. They are only used in this class - Move all
\utils\PoolHelperfunctions toPool. They are only used in this class ~13. RemovegenerateDid()functions. It’s not used~ - Remove
fetchData()functions. It’s not used ~15. RemovedownloadFileBrowser()functions. It’s not used~ - Remove
postWithHeaders()functions. It’s not used - Remove
postData()functions. It’s not used - Move
downloadFile()function to/utils/General~19. Adddecimals()function to/utils/TokenUtils.ts~ ~20. Addmint()function to/utils/TokenUtils.ts~
Perhaps 19 and 20 can be done in a different Pull Request.
- Not sure what the use of that was. If one changes the contracts they would need a changed library. @alexcos20 do you remember what's the point of ABI ?
- It is used in the market
- Used in the market
@mihaisc Do you refer to 6, 7 or 13, 14, 15?
I have reviewed it and yes, generateDid(), fetchData() and downloadFileBrowser() are used in the Market
Yes, sry, i am refering to 13 to 17, don't need to remove them
More proposals:
21. Put all smart contract related classes in a \contracts folder
22. Create two parent smart contract classes, SmartContract and SmartContractWithAddress from which all smart contract classes will derive from them. These classes will have the address, abi, web3, config, network and Contract properties
More proposals:
23. Unify naming ERC20 --> Datatoken. For example, in Erc20CreateParams --> DatatokenCreateParams, createNftErc20WithPool() --> createNftAndDatatokenWithPool()...
- Public functions:
-
NFTFactory.createNftWithErc20()-->NFTFactory.createNftWithDatatoken() -
NFTFactory.createNftErc20WithPool()-->NFTFactory.createNftWithDatatokenWithPool() -
NFTFactory.createNftErc20WithFixedRate()-->NFTFactory.createNftWithDatatokenWithFixedRate() -
NFTFactory.createNftErc20WithDispenser()-->NFTFactory.createNftWithDatatokenWithDispenser() -
Datatoken.isERC20Deployer()-->Datatoken.isDatatokenDeployer() -
NFT.createErc20()-->NFT.createDatatoken() -
NFT.addErc20Deployer()-->NFT.addDatatokenDeployer() -
NFT.removeErc20Deployer()-->NFT.removeDatatokenDeployer() -
NFT.isErc20Deployer()-->NFT.isDatatokenDeployer()
-
- Unify naming
ERC721-->Nft. For example, inERC721Factory-->NftFactory...
@kremalicious @alexcos20 should we use dataNft in code as well , instead of just Nft ?
More proposals:
25. Change the estimategas() specific functions. Instead of using a specific function for every task, use a parameter in the functions that let calculate the estimated gas instead of executing the transaction.
For example, with this function signature:
public async addNFTTemplate<G extends boolean = false>(
address: string,
templateAddress: string,
estimateGas?: G
): Promise<G extends false ? TransactionReceipt : number> {
By default, it executes the transaction and returns a TransactionReceipt value. But if we set the estimateGas parameter to true, it returns a number representing the gas cost, without executing the transaction.
More proposals:
26. Review the use of try... catch blocks in the class methods. Not all smart contract related classes follow the same pattern.
More proposals: 27. General renaming to unify naming conventions.
- Public functions:
-
FixedRateExchange.buyDT()-->FixedRateExchange.buyDatatokens() -
FixedRateExchange.sellDT()-->FixedRateExchange.sellDatatokens() -
FixedRateExchange.getDTSupply()-->FixedRateExchange.getDatatokenSupply() -
FixedRateExchange.getBTSupply()-->FixedRateExchange.getBasetokenSupply() -
FixedRateExchange.calcBaseInGivenOutDT()-->FixedRateExchange.calcBaseInGivenDatatokensOut() -
FixedRateExchange.getAmountBTOut()-->FixedRateExchange.getAmountBasetokensOut() -
FixedRateExchange.collectBT()-->FixedRateExchange.collectBasetokens() -
FixedRateExchange.collectDT()-->FixedRateExchange.collectDatatokens() -
SideStaking.getBaseToken()-->SideStaking.getBasetoken() -
SideStaking.getBaseTokenBalance()-->SideStaking.getBasetokenBalance() -
SideStaking.getvestingEndBlock()-->SideStaking.getVestingEndBlock() -
SideStaking.getvestingAmount()-->SideStaking.getVestingAmount() -
SideStaking.getvestingLastBlock()-->SideStaking.getVestingLastBlock() -
SideStaking.getvestingAmountSoFar()-->SideStaking.getVestingAmountSoFar() -
Router.buyDTBatch()-->Router.buyDatatokenBatch()
-
More proposals:
28. Review try...catch clauses. There are a lot of try...catch clauses that hide the error, and this doesn't give us the ability to ever fix or react to said error. We can see an example of this in #1468.
- Add functions for complex processes. For example, for Compute to Data. Sometimes these processes call the same functions, and they can be simplified with a unique function