@tradelayerprotocol/tradelayer 1.9.1

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.
Files changed (249) hide show
  1. package/.claude/settings.local.json +13 -0
  2. package/.claude/skills/tl-algo/SKILL.md +255 -0
  3. package/.gitattributes +2 -0
  4. package/.github/workflows/publish.yaml +26 -0
  5. package/4mm.js +163 -0
  6. package/LICENSE +21 -0
  7. package/NPMSwapRefactor.zip +0 -0
  8. package/README.md +217 -0
  9. package/address.sh +26 -0
  10. package/algoAPI.js +581 -0
  11. package/analyzepsbt.js +92 -0
  12. package/apiEx.js +99 -0
  13. package/bb_hyperscalper.js +290 -0
  14. package/bbo_demo.js +111 -0
  15. package/buyer.js +622 -0
  16. package/client.js +50 -0
  17. package/createTxTest.js +26 -0
  18. package/createWallet.js +75 -0
  19. package/daytrader.js +531 -0
  20. package/decodeTest.js +69 -0
  21. package/fundingManager.js +144 -0
  22. package/index.js +4 -0
  23. package/listener.js +27 -0
  24. package/litecoreTxBuilder.js +1128 -0
  25. package/mmEx.js +356 -0
  26. package/networks.js +51 -0
  27. package/orderbook.js +200 -0
  28. package/package.json +34 -0
  29. package/perTradeQueue.js +36 -0
  30. package/projectsTLNPMTLNPM/package-lock.json +162 -0
  31. package/projectsTLNPMTLNPM/package.json +5 -0
  32. package/quick.js +32 -0
  33. package/quickFut.js +37 -0
  34. package/quickSell.js +37 -0
  35. package/relayerClient.js +117 -0
  36. package/run4mm.js +80 -0
  37. package/run_bbo_tracker.js +241 -0
  38. package/seller.js +443 -0
  39. package/session.js +45 -0
  40. package/setup-lin-ltc.sh +139 -0
  41. package/setup-lin.sh +203 -0
  42. package/setup-win-ltc.bat +108 -0
  43. package/setup-win.bat +167 -0
  44. package/spam_screamer_futures.js +222 -0
  45. package/tradelayer.js/.gitattributes +2 -0
  46. package/tradelayer.js/README.md +2 -0
  47. package/tradelayer.js/oldTests/activationTest.js +6 -0
  48. package/tradelayer.js/oldTests/base58.test.js +23 -0
  49. package/tradelayer.js/oldTests/base64Decode.test.js +16 -0
  50. package/tradelayer.js/oldTests/blocksRefactor.js +140 -0
  51. package/tradelayer.js/oldTests/checkVestBalance.js +25 -0
  52. package/tradelayer.js/oldTests/consensusHashProto.js +151 -0
  53. package/tradelayer.js/oldTests/contractOrderbook.js +243 -0
  54. package/tradelayer.js/oldTests/createPayload.js +0 -0
  55. package/tradelayer.js/oldTests/createTestnetAddr.js +43 -0
  56. package/tradelayer.js/oldTests/decode.js +205 -0
  57. package/tradelayer.js/oldTests/decodeTest.js +50 -0
  58. package/tradelayer.js/oldTests/displayTallyMap.js +19 -0
  59. package/tradelayer.js/oldTests/encodeDecode.js +340 -0
  60. package/tradelayer.js/oldTests/expressTest.js +29 -0
  61. package/tradelayer.js/oldTests/extractBlocksVanilla.js +214 -0
  62. package/tradelayer.js/oldTests/extractBlocksVanillaa.js +179 -0
  63. package/tradelayer.js/oldTests/extractPubkeyTest.js +60 -0
  64. package/tradelayer.js/oldTests/fillInputCacheProto.js +111 -0
  65. package/tradelayer.js/oldTests/getRawTxTest.js +22 -0
  66. package/tradelayer.js/oldTests/indexTest.js +26 -0
  67. package/tradelayer.js/oldTests/initTokensTest.js +32 -0
  68. package/tradelayer.js/oldTests/interfaceChild.js +129 -0
  69. package/tradelayer.js/oldTests/listenerChild.js +112 -0
  70. package/tradelayer.js/oldTests/opdecode.js +26 -0
  71. package/tradelayer.js/oldTests/options.js +79 -0
  72. package/tradelayer.js/oldTests/optxtest.js +116 -0
  73. package/tradelayer.js/oldTests/optxtest1.js +64 -0
  74. package/tradelayer.js/oldTests/oracle.test.js +32 -0
  75. package/tradelayer.js/oldTests/orderbook.test.js +36 -0
  76. package/tradelayer.js/oldTests/parsing.js +93 -0
  77. package/tradelayer.js/oldTests/payload.js +13 -0
  78. package/tradelayer.js/oldTests/persistenceUnitTest.js +23 -0
  79. package/tradelayer.js/oldTests/property.test.js +53 -0
  80. package/tradelayer.js/oldTests/propertyLevel.js +75 -0
  81. package/tradelayer.js/oldTests/propertyTest.js +32 -0
  82. package/tradelayer.js/oldTests/queryAddressTest.js +17 -0
  83. package/tradelayer.js/oldTests/salter.js +14 -0
  84. package/tradelayer.js/oldTests/tally.js +81 -0
  85. package/tradelayer.js/oldTests/tally.test.js +48 -0
  86. package/tradelayer.js/oldTests/tally2.js +124 -0
  87. package/tradelayer.js/oldTests/tally3.js +142 -0
  88. package/tradelayer.js/oldTests/tallyDiag.js +38 -0
  89. package/tradelayer.js/oldTests/testGetRaw.js +40 -0
  90. package/tradelayer.js/oldTests/testHexConvert.js +47 -0
  91. package/tradelayer.js/oldTests/testNewEncoding.js +96 -0
  92. package/tradelayer.js/oldTests/testNewEncoding2.js +113 -0
  93. package/tradelayer.js/oldTests/testNewEncoding3 +112 -0
  94. package/tradelayer.js/oldTests/testNewEncoding3.js +168 -0
  95. package/tradelayer.js/oldTests/testOPReturn.js +102 -0
  96. package/tradelayer.js/oldTests/testPayload.js +23 -0
  97. package/tradelayer.js/oldTests/testRaw.js +50 -0
  98. package/tradelayer.js/oldTests/testSendTooMuch.js +20 -0
  99. package/tradelayer.js/oldTests/testTxBuild +28 -0
  100. package/tradelayer.js/oldTests/testTxBuild.js +42 -0
  101. package/tradelayer.js/oldTests/tokenOrderbook.js +243 -0
  102. package/tradelayer.js/oldTests/txUtilsA.js +515 -0
  103. package/tradelayer.js/oldTests/validityUnitTest.js +53 -0
  104. package/tradelayer.js/oldTests/vaults.js +72 -0
  105. package/tradelayer.js/oldTests/volumeIndex.js +117 -0
  106. package/tradelayer.js/oldTests/volumeIndex2.js +88 -0
  107. package/tradelayer.js/output_base64.txt +1 -0
  108. package/tradelayer.js/package-lock.json +9967 -0
  109. package/tradelayer.js/package.json +61 -0
  110. package/tradelayer.js/server/index.js +88 -0
  111. package/tradelayer.js/server/litecoind.exe +0 -0
  112. package/tradelayer.js/src/activation.js +303 -0
  113. package/tradelayer.js/src/adjuster.js +77 -0
  114. package/tradelayer.js/src/amm.js +400 -0
  115. package/tradelayer.js/src/base256.js +55 -0
  116. package/tradelayer.js/src/base94.js +79 -0
  117. package/tradelayer.js/src/channels.js +1163 -0
  118. package/tradelayer.js/src/clearing.js +3109 -0
  119. package/tradelayer.js/src/clearlist.js +364 -0
  120. package/tradelayer.js/src/client.js +295 -0
  121. package/tradelayer.js/src/consensus.js +613 -0
  122. package/tradelayer.js/src/contractRegistry.js +964 -0
  123. package/tradelayer.js/src/db.js +89 -0
  124. package/tradelayer.js/src/init.js +24 -0
  125. package/tradelayer.js/src/insurance.js +347 -0
  126. package/tradelayer.js/src/interface.js +218 -0
  127. package/tradelayer.js/src/interfaceExpress.js +178 -0
  128. package/tradelayer.js/src/iou.js +509 -0
  129. package/tradelayer.js/src/listener.js +226 -0
  130. package/tradelayer.js/src/logic.js +1702 -0
  131. package/tradelayer.js/src/main.js +927 -0
  132. package/tradelayer.js/src/marginMap.js +2165 -0
  133. package/tradelayer.js/src/options.js +126 -0
  134. package/tradelayer.js/src/oracle.js +394 -0
  135. package/tradelayer.js/src/orderbook.js +4123 -0
  136. package/tradelayer.js/src/persistence.js +554 -0
  137. package/tradelayer.js/src/property.js +411 -0
  138. package/tradelayer.js/src/reOrg.js +41 -0
  139. package/tradelayer.js/src/scaling.js +145 -0
  140. package/tradelayer.js/src/tally.js +1275 -0
  141. package/tradelayer.js/src/tradeHistoryManager.js +552 -0
  142. package/tradelayer.js/src/txDecoder.js +584 -0
  143. package/tradelayer.js/src/txEncoder.js +610 -0
  144. package/tradelayer.js/src/txIndex.js +502 -0
  145. package/tradelayer.js/src/txUtils.js +1392 -0
  146. package/tradelayer.js/src/types.js +429 -0
  147. package/tradelayer.js/src/validity.js +3077 -0
  148. package/tradelayer.js/src/vaults.js +430 -0
  149. package/tradelayer.js/src/vesting.js +491 -0
  150. package/tradelayer.js/src/volumeIndex.js +618 -0
  151. package/tradelayer.js/src/walletInterface.js +220 -0
  152. package/tradelayer.js/src/walletListener.js +665 -0
  153. package/tradelayer.js/tests/256decode.js +82 -0
  154. package/tradelayer.js/tests/UTXOracle.js +205 -0
  155. package/tradelayer.js/tests/base94test.js +23 -0
  156. package/tradelayer.js/tests/cancelTxTest.js +62 -0
  157. package/tradelayer.js/tests/contractInterfaceTest.js +48 -0
  158. package/tradelayer.js/tests/decimalTest.js +65 -0
  159. package/tradelayer.js/tests/decoderTest.js +100 -0
  160. package/tradelayer.js/tests/deltaCount.js +47 -0
  161. package/tradelayer.js/tests/deltaCount2.js +60 -0
  162. package/tradelayer.js/tests/interfaceTest.js +37 -0
  163. package/tradelayer.js/tests/mainTest.js +53 -0
  164. package/tradelayer.js/tests/makeActivationTest.js +24 -0
  165. package/tradelayer.js/tests/maxHeightTest.js +49 -0
  166. package/tradelayer.js/tests/reverseHash.js +72 -0
  167. package/tradelayer.js/tests/sensitiveConsoleOutput.txt +267 -0
  168. package/tradelayer.js/tests/tallyTest.js +40 -0
  169. package/tradelayer.js/tests/testBuybacks.js +46 -0
  170. package/tradelayer.js/tests/testCodeHash.js +49 -0
  171. package/tradelayer.js/tests/testConsensusHash.js +91 -0
  172. package/tradelayer.js/tests/testDecode.js +30 -0
  173. package/tradelayer.js/tests/testEncodingLengths.js +129 -0
  174. package/tradelayer.js/tests/testGetTx +32 -0
  175. package/tradelayer.js/tests/testGetTx.js +32 -0
  176. package/tradelayer.js/tests/testHexHash.js +32 -0
  177. package/tradelayer.js/tests/testIndexHash.js +35 -0
  178. package/tradelayer.js/tests/testInitContracts.js +38 -0
  179. package/tradelayer.js/tests/testMaxConsensus.js +12 -0
  180. package/tradelayer.js/tests/testMaxSynth.js +44 -0
  181. package/tradelayer.js/tests/testMint.js +21 -0
  182. package/tradelayer.js/tests/testNetwork.js +33 -0
  183. package/tradelayer.js/tests/testOrderbookLoad.js +62 -0
  184. package/tradelayer.js/tests/testRebates.js +32 -0
  185. package/tradelayer.js/tests/testRedeem.js +22 -0
  186. package/tradelayer.js/tests/testTokenTrade.js +39 -0
  187. package/tradelayer.js/tests/testTxBuild.js +42 -0
  188. package/tradelayer.js/tests/testUTXOTrade.js +27 -0
  189. package/tradelayer.js/tests/tokenTradeHistory.js +27 -0
  190. package/tradelayer.js/tests/tradeFutures.js +40 -0
  191. package/tradelayer.js/tests/tradeHistoryExample.js +35 -0
  192. package/tradelayer.js/tests/tradeHistoryLoad.js +15 -0
  193. package/tradelayer.js/tests/txScanTest.js +134 -0
  194. package/tradelayer.js/tests/validateTest.js +136 -0
  195. package/tradelayer.js/tests/vestingTest.js +37 -0
  196. package/tradelayer.js/utils/activateMainnet.js +59 -0
  197. package/tradelayer.js/utils/activateMainnetDoge.js +63 -0
  198. package/tradelayer.js/utils/autocompactdb.js +23 -0
  199. package/tradelayer.js/utils/base64toHex.js +32 -0
  200. package/tradelayer.js/utils/broadcastDoge.js +38 -0
  201. package/tradelayer.js/utils/calcRedeem.js +19 -0
  202. package/tradelayer.js/utils/checkNetwork.js +27 -0
  203. package/tradelayer.js/utils/createAddress.js +48 -0
  204. package/tradelayer.js/utils/createAttestation.js +133 -0
  205. package/tradelayer.js/utils/createContract.js +118 -0
  206. package/tradelayer.js/utils/createOracle.js +94 -0
  207. package/tradelayer.js/utils/createwallet.js +20 -0
  208. package/tradelayer.js/utils/crossFuturesTrades.js +57 -0
  209. package/tradelayer.js/utils/crossTokenTrades.js +62 -0
  210. package/tradelayer.js/utils/dumpPriv.js +29 -0
  211. package/tradelayer.js/utils/generateChannel.js +34 -0
  212. package/tradelayer.js/utils/getInfo.js +21 -0
  213. package/tradelayer.js/utils/hardWipe.js +20 -0
  214. package/tradelayer.js/utils/hexTo64.js +16 -0
  215. package/tradelayer.js/utils/importAddress.js +28 -0
  216. package/tradelayer.js/utils/importpriv.js +20 -0
  217. package/tradelayer.js/utils/issueOracleContract.js +67 -0
  218. package/tradelayer.js/utils/issueTokens.js +41 -0
  219. package/tradelayer.js/utils/listunspent.js +66 -0
  220. package/tradelayer.js/utils/litecoinClient.js +30 -0
  221. package/tradelayer.js/utils/loadwallet.js +20 -0
  222. package/tradelayer.js/utils/publishOracle.js +113 -0
  223. package/tradelayer.js/utils/sendActivation.js +21 -0
  224. package/tradelayer.js/utils/sendChannelContractTrade.js +34 -0
  225. package/tradelayer.js/utils/sendChannelTokenTrade.js +34 -0
  226. package/tradelayer.js/utils/sendCommit.js +24 -0
  227. package/tradelayer.js/utils/sendDoge.js +62 -0
  228. package/tradelayer.js/utils/sendDogeMain.js +67 -0
  229. package/tradelayer.js/utils/sendDogeTx.js +46 -0
  230. package/tradelayer.js/utils/sendLTC.js +63 -0
  231. package/tradelayer.js/utils/sendMainnet.js +62 -0
  232. package/tradelayer.js/utils/sendTransfer.js +19 -0
  233. package/tradelayer.js/utils/sendVestTest.js +88 -0
  234. package/tradelayer.js/utils/sendWithdrawal.js +26 -0
  235. package/tradelayer.js/utils/simpleStart.js +8 -0
  236. package/tradelayer.js/utils/startStop.js +27 -0
  237. package/tradelayer.js/utils/structuredTrades.js +136 -0
  238. package/tradelayer.js/utils/verifySignature.js +90 -0
  239. package/tradelayer.js/utils/verifyWitnessAndScriptPubkey.js +41 -0
  240. package/tradelayer.js/utils/walletCache.js +172 -0
  241. package/tradelayer.js/utils/walletContractInterface.js +48 -0
  242. package/tradelayer.js/utils/walletFetchTxs.js +66 -0
  243. package/tradelayer.js/utils/walletUtils.js +97 -0
  244. package/tradelayer.js/utils/wipeDB.js +55 -0
  245. package/tradelayer.js/utils/wipeDBNotTx.js +50 -0
  246. package/txEncoder.js +529 -0
  247. package/utility.js +28 -0
  248. package/verifymessage.js +38 -0
  249. package/ws-transport.js +311 -0
@@ -0,0 +1,303 @@
1
+ const db = require('./db.js')
2
+ //const Logic = require('./logic.js');
3
+ const TradeLayerManager = require('./vesting.js')
4
+ const Consensus = require('./consensus'); // Import consensus.js functions
5
+ const ClientWrapper = require('./client.js')
6
+
7
+ const testAdmin = "tltc1qa0kd2d39nmeph3hvcx8ytv65ztcywg5sazhtw8"
8
+
9
+ class Activation {
10
+ static instance = null; // Static instance holder
11
+
12
+ constructor(chain) {
13
+ if (Activation.instance) {
14
+ return Activation.instance;
15
+ }
16
+
17
+ this.consensusVector = {};
18
+ this.txRegistry = this.initializeTxRegistry()
19
+ //this.init(chain)
20
+ Activation.instance = this; // Set the instance
21
+ }
22
+
23
+ async init(chain) {
24
+ const client = await ClientWrapper.getInstance()
25
+ if(!chain){
26
+ console.log('assigning chain '+client.chain)
27
+ this.chain = await client.getChain()
28
+ }else{
29
+ this.chain = await client.getChain(chain);
30
+ }
31
+ this.test = await client.getTest();
32
+ this.updateAdminAddress()
33
+ }
34
+
35
+ updateAdminAddress() {
36
+ if (this.chain === 'BTC') {
37
+ this.adminAddress = this.test ? 'tb1q8f84erfegxhaylmvpfll9m5rgwymqy4akjnnvq' : 'bc1qktknrnx2jcchjht9anz0uy8ae02xryxq2vxeem';
38
+ } else if (this.chain === 'DOGE') {
39
+ this.adminAddress = this.test ? 'nop27JQWbGr95ySHXZMzCg8XXxYzbCBZAW' : 'DLSfu9qvEggkeXAgCAwBBw5BVLvMCtkewz';
40
+ } else if (this.chain === 'LTC') {
41
+ this.adminAddress = this.test ? 'tltc1qa0kd2d39nmeph3hvcx8ytv65ztcywg5sazhtw8' : 'MTmoypkhRQoJ172ZqxcsVumPZfJ8KCrQCB';
42
+ }
43
+ }
44
+
45
+
46
+ async delay(ms) {
47
+ return new Promise(resolve => setTimeout(resolve, ms));
48
+ }
49
+
50
+ // Static method to get the singleton instance
51
+ static getInstance(chain) {
52
+ if (!Activation.instance) {
53
+ console.log('generate activation instance')
54
+ Activation.instance = new Activation(chain);
55
+ }
56
+ return Activation.instance;
57
+ }
58
+
59
+ getAdmin(){
60
+ return this.adminAddress
61
+ }
62
+
63
+ async saveActivationsList() {
64
+ try {
65
+ const activationsDB = await db.getDatabase('activations');
66
+ const query = { _id: 'activationsList' };
67
+ const update = { $set: { value: JSON.stringify(this.txRegistry) } };
68
+ const options = { upsert: true }; // This option will insert if not found
69
+
70
+ //console.log('Saving activations list:', JSON.stringify(this.txRegistry));
71
+ await activationsDB.updateAsync(query, update, options);
72
+ console.log('Activations list saved successfully.');
73
+ } catch (error) {
74
+ console.error('Error saving activations list:', error);
75
+ }
76
+ }
77
+
78
+
79
+ // New Method to load activations list
80
+ async loadActivationsList() {
81
+ try {
82
+ const activationsDB = await db.getDatabase('activations');
83
+ const entries = await activationsDB.findAsync({});
84
+
85
+ if (entries.length === 0) {
86
+ console.log('No activations list found, initializing with default values.');
87
+ this.txRegistry = this.initializeTxRegistry();
88
+ await this.saveActivationsList(); // Save the newly created default activations list
89
+ } else {
90
+ let data = {};
91
+ entries.forEach(entry => {
92
+ data[entry._id] = entry.value;
93
+ });
94
+
95
+ if (data['activationsList']) {
96
+ this.txRegistry = JSON.parse(data['activationsList']);
97
+ console.log('Activations list loaded successfully.');
98
+ } else {
99
+ console.error('Activations list not found in the database, initializing with default values.');
100
+ this.txRegistry = this.initializeTxRegistry();
101
+ await this.saveActivationsList(); // Save the newly created default activations list
102
+ }
103
+ }
104
+
105
+ // Return the latest activations list (txRegistry)
106
+ return this.txRegistry;
107
+ } catch (error) {
108
+ console.error('Error loading activations list:', error);
109
+ this.txRegistry = this.initializeTxRegistry(); // Initialize with default values in case of any error
110
+ await this.saveActivationsList(); // Save the newly created default activations list
111
+ return this.txRegistry;
112
+ }
113
+ }
114
+
115
+
116
+ // Example helper functions (implementations depend on your specific logic and data structures)
117
+ async activate(txType, block, codeHash) {
118
+ txType = parseInt(txType)
119
+ //console.log('Activating transaction type:' +txType +(txType === 0) + ' block '+ block );
120
+ await this.loadActivationsList(); // Make sure to load the activations list first
121
+ if (txType === undefined) {
122
+ console.error("Transaction type is undefined.");
123
+ return; // Exit the function if txType is undefined
124
+ }
125
+ if (txType === 0) {
126
+ //console.log('in the activate 0 block')
127
+ // Handle the special case for the initial transaction
128
+ //const TL = .getInstance(testAdmin);
129
+ const tradeLayerManager = await TradeLayerManager.getInstance(this.adminAddress, this.chain,this.test);
130
+ const balances = await tradeLayerManager.initializeTokens(block); //await TradeLayerManager.initializeContractSeries(); going to save this for the activation of native contracts
131
+ console.log('balances '+ balances + "if undefined this is a repeat that successfully prevented inflation")
132
+ this.txRegistry[txType].active = true;
133
+ this.txRegistry[txType].activationBlock = block
134
+ if(codeHash){
135
+ this.txRegistry[txType].codeHash = codeHash
136
+ }
137
+ //console.log(JSON.stringify(this.txRegistry))
138
+ await this.saveActivationsList()
139
+ await Consensus.pushLatestActivationToConsensusVector();
140
+ }else{
141
+ // Check if the transaction type exists in the registry
142
+ //console.log('in the general activations block')
143
+ if (this.txRegistry[txType]) {
144
+ this.txRegistry[txType].active = true;
145
+ this.txRegistry[txType].activationBlock = block
146
+ if(codeHash){
147
+ this.txRegistry[txType].codeHash = codeHash
148
+ }
149
+ //console.log('activating '+txType+ ' '+JSON.stringify(this.txRegistry))
150
+
151
+ await this.saveActivationsList();
152
+ await Consensus.pushLatestActivationToConsensusVector(); // Save the updated activations list
153
+ return this.txRegistry[txType] ; // Save the updated activations list
154
+ } else {
155
+ console.error(`Transaction type ${txType} not found in registry.`);
156
+ }
157
+ }
158
+ }
159
+
160
+ /**
161
+ * Checks if more than 90% of the activations in the transaction registry are true.
162
+ * @returns {boolean} - Returns true if >90% of activations are true, otherwise false.
163
+ */
164
+ async areActivationsAboveThreshold() {
165
+ await this.loadActivationsList(); // Ensure the registry is up-to-date
166
+
167
+ const totalTxTypes = Object.keys(this.txRegistry).length;
168
+ if (totalTxTypes === 0) {
169
+ console.error('Transaction registry is empty.');
170
+ return false;
171
+ }
172
+
173
+ // Count active transactions
174
+ const activeCount = Object.values(this.txRegistry).reduce((count, tx) => {
175
+ return tx.active ? count + 1 : count;
176
+ }, 0);
177
+
178
+ const activationPercentage = (activeCount / totalTxTypes) * 100;
179
+
180
+ console.log(`Active transactions: ${activeCount}/${totalTxTypes} (${activationPercentage.toFixed(2)}%)`);
181
+ console.log('above threshold? '+Boolean(activationPercentage > 90))
182
+ // Check if >90% of activations are true
183
+ return Boolean(activationPercentage > 90);
184
+ }
185
+
186
+
187
+ initializeTxRegistry() {
188
+ // Initialize the transaction registry
189
+ return {
190
+ 0: { name: "Activate TradeLayer", active: false },
191
+ 1: { name: "Token Issue", active: false },
192
+ 2: { name: "Send", active: false },
193
+ 3: { name: "Trade Token for UTXO", active: false },
194
+ 4: { name: "Commit Token", active: false },
195
+ 5: { name: "On-chain Token for Token", active: false },
196
+ 6: { name: "cancelOrder", active: false },
197
+ 7: { name: "Create Whitelist", active: false },
198
+ 8: { name: "Update Admin", active: false },
199
+ 9: { name: "Issue or Revoke Attestation", active: false },
200
+ 10: { name: "AMM", active: false },
201
+ 11: { name: "Grant Managed Token", active: false },
202
+ 12: { name: "Redeem Managed Token", active: false },
203
+ 13: { name: "Create Oracle", active: false },
204
+ 14: { name: "Publish Oracle Data", active: false },
205
+ 15: { name: "Close Oracle", active: false },
206
+ 16: { name: "Create Future Contract Series", active: false },
207
+ 17: { name: "Exercise Derivative", active: false },
208
+ 18: { name: "Trade Contract On-chain", active: false },
209
+ 19: { name: "Trade Contract Channel", active: false },
210
+ 20: { name: "Trade Tokens Channel", active: false },
211
+ 21: { name: "Withdrawal", active: false },
212
+ 22: { name: "Transfer", active: false },
213
+ 23: { name: "Settle Channel PNL", active: false },
214
+ 24: { name: "Mint Synthetic", active: false },
215
+ 25: { name: "Redeem Synthetic", active: false },
216
+ 26: { name: "Pay to Tokens", active: false },
217
+ 27: { name: "Create Option Chain", active: false },
218
+ 28: { name: "Trade Bai Urbun", active: false },
219
+ 29: { name: "Trade Murabaha", active: false },
220
+ 30: { name: "Issue Invoice", active: false },
221
+ 31: { name: "Batch Move Zk Rollup", active: false },
222
+ 32: { name: "Publish New Tx", active: false },
223
+ 33: { name: "Colored Coin", active: false },
224
+ 34: { name: "Cross Layer Bridge", active: false },
225
+ 35: { name: "Smart Contract Bind", active: false },
226
+ }
227
+
228
+ }
229
+
230
+ // Function to get the activation block of a transaction type
231
+ getActivationBlock(txType) {
232
+ if (this.txRegistry.hasOwnProperty(txType)) {
233
+ return this.txRegistry[txType].activationBlock || null; // Returns the activation block if available, otherwise null
234
+ } else {
235
+ console.error(`Transaction type ${txType} not found in registry.`);
236
+ return null; // Return null if the transaction type is not found
237
+ }
238
+ }
239
+
240
+ /**
241
+ * Checks if a transaction type is active in the transaction registry.
242
+ * @param {number} txTypeNumber - The transaction type number to check.
243
+ * @returns {boolean} - Returns true if the transaction type is active, false otherwise.
244
+ */
245
+ async isTxTypeActive(txTypeNumber) {
246
+ // Assuming txRegistry is accessible within this context
247
+ await this.loadActivationsList()
248
+ const txType = this.txRegistry[txTypeNumber];
249
+ //console.log('checking ' + JSON.stringify(txType)+' registry '+JSON.stringify(this.txRegistry))
250
+ if(txType==undefined){return false}
251
+ if (txType.active==true) {
252
+ return true;
253
+ }
254
+ return false;
255
+ }
256
+
257
+ async checkActivationBlock(txTypeNumber){
258
+ await this.loadActivationsList()
259
+ //console.log('checking for activation block ' +this.txRegistry[txTypeNumber])
260
+ const txType = this.txRegistry[txTypeNumber];
261
+ //console.log('checking type activation' + JSON.stringify(txType))
262
+ if(txType.activationBlock==undefined){return null}else{return txType.activationBlock};
263
+ }
264
+
265
+ async isSenderGenesisAdmin(address) {
266
+ // Check if the given address is the genesis admin
267
+ return (address === 'tltc1qa0kd2d39nmeph3hvcx8ytv65ztcywg5sazhtw8')
268
+ }
269
+
270
+ isValidJSON(json) {
271
+ try {
272
+ JSON.parse(json);
273
+ return true;
274
+ } catch (e) {
275
+ return false;
276
+ }
277
+ }
278
+
279
+ isValidJavaScript(jsCode) {
280
+ // Implement JavaScript validation logic
281
+ // This could include syntax checking and potentially safety checks
282
+ return true; // Placeholder
283
+ }
284
+
285
+ minifyJavaScript(jsCode) {
286
+ // Implement JavaScript code minification
287
+ // You might use existing libraries for minification
288
+ return jsCode; // Placeholder
289
+ }
290
+
291
+ getNextTxTypeId() {
292
+ // Logic to get the next transaction type ID
293
+ // This might involve querying a database or keeping track in memory
294
+ return /* next transaction type ID */;
295
+ }
296
+
297
+ saveNewTransaction(newTx) {
298
+ // Logic to save the new transaction
299
+ // This will likely involve database operations
300
+ }
301
+ }
302
+
303
+ module.exports = Activation;
@@ -0,0 +1,77 @@
1
+ class TickSizeAdjuster {
2
+ constructor() {
3
+ this.tickSize = 0.1; // Initial tick size
4
+ this.minContractSize = 1; // Minimum contract size
5
+ this.notionalThreshold = 2; // Threshold for increasing tick size
6
+ this.notionalMultiplier = 10; // Multiplier for notional value increase
7
+ this.doublingInterval = 3; // Doubling interval for tick size adjustment
8
+ this.consecutiveDoublings = 0; // Counter for consecutive doublings
9
+ }
10
+
11
+ adjustTickSize(notionalValue) {
12
+ if (notionalValue >= this.notionalThreshold * this.minContractSize) {
13
+ this.consecutiveDoublings++;
14
+
15
+ if (this.consecutiveDoublings >= this.doublingInterval) {
16
+ // Double tick size every 'doublingInterval' consecutive doublings
17
+ this.tickSize *= 2;
18
+ this.consecutiveDoublings = 0;
19
+
20
+ // Save adjustment event to the database
21
+ this.saveAdjustmentEvent("DoubleTickSize", this.tickSize);
22
+ }
23
+
24
+ // Increase tick size based on notional value
25
+ this.tickSize *= this.notionalMultiplier;
26
+
27
+ // Save adjustment event to the database
28
+ this.saveAdjustmentEvent("IncreaseTickSize", this.tickSize);
29
+ } else {
30
+ this.consecutiveDoublings = 0; // Reset consecutive doublings if notional value is below threshold
31
+ }
32
+
33
+ return this.tickSize;
34
+ }
35
+
36
+ increaseNotionalSize() {
37
+ this.minContractSize *= 10;
38
+
39
+ // Save adjustment event to the database
40
+ this.saveAdjustmentEvent("IncreaseNotionalSize", this.minContractSize);
41
+ }
42
+
43
+ saveAdjustmentEvent(type, value) {
44
+ return new Promise(async (resolve, reject) => {
45
+ try {
46
+ const db = require('./db.js');
47
+
48
+ // Save adjustment event to the "contractAdjustments" category in the database
49
+ const result = await db.getDatabase("contractAdjustments").updateAsync(
50
+ { category: "contractAdjustments" },
51
+ { $push: { events: { type, value, timestamp: new Date() } } },
52
+ { upsert: true }
53
+ );
54
+
55
+ resolve(result);
56
+ } catch (error) {
57
+ reject(error);
58
+ }
59
+ });
60
+ }
61
+
62
+ }
63
+
64
+ // Example usage
65
+ const tickSizeAdjuster = new TickSizeAdjuster();
66
+
67
+ // Simulate trading with varying notional values
68
+ const notionalValues = [1, 5, 10, 20, 50, 100, 500, 1000];
69
+
70
+ notionalValues.forEach((notionalValue) => {
71
+ const adjustedTickSize = tickSizeAdjuster.adjustTickSize(notionalValue);
72
+ console.log(`Notional Value: ${notionalValue}, Adjusted Tick Size: ${adjustedTickSize}`);
73
+ });
74
+
75
+ // Simulate increasing notional size
76
+ tickSizeAdjuster.increaseNotionalSize();
77
+ console.log(`New Min Contract Size: ${tickSizeAdjuster.minContractSize}`);