@layerzerolabs/layerzero-v2-ton 3.0.19-ton.0 → 3.0.19-ton.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 (206) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/AllStorages.compiled.json +1 -1
  3. package/build/AllStorages.test.compiled.json +1 -1
  4. package/build/BaseContract.test.compiled.json +1 -1
  5. package/build/Channel.compiled.json +1 -1
  6. package/build/Channel.permissions.test.compiled.json +1 -1
  7. package/build/ChannelBurn.test.compiled.json +1 -1
  8. package/build/ChannelCommitPacket.test.compiled.json +1 -1
  9. package/build/ChannelConfig.test.compiled.json +1 -1
  10. package/build/ChannelInitialize.test.compiled.json +1 -1
  11. package/build/ChannelMsglibIntegration.test.compiled.json +1 -1
  12. package/build/ChannelMsglibSendCallback.test.compiled.json +1 -1
  13. package/build/ChannelNilify.test.compiled.json +1 -1
  14. package/build/ChannelReceive.test.compiled.json +1 -1
  15. package/build/ChannelReceiveCallback.test.compiled.json +1 -1
  16. package/build/ChannelReceiveView.test.compiled.json +1 -1
  17. package/build/ChannelSend.test.compiled.json +1 -1
  18. package/build/Classlib.test.compiled.json +1 -1
  19. package/build/ComputeDataSizeGas.test.compiled.json +1 -1
  20. package/build/Connection.compiled.json +1 -1
  21. package/build/Controller.assertions.test.compiled.json +1 -1
  22. package/build/Controller.compiled.json +1 -1
  23. package/build/Controller.permissions.test.compiled.json +1 -1
  24. package/build/Controller.test.compiled.json +1 -1
  25. package/build/Counter.compiled.json +1 -1
  26. package/build/Counter.permissions.test.compiled.json +1 -1
  27. package/build/Counter.setters.test.compiled.json +1 -1
  28. package/build/Counter.test.compiled.json +1 -1
  29. package/build/Dvn.compiled.json +1 -1
  30. package/build/Dvn.test.compiled.json +1 -1
  31. package/build/DvnFeeLib.compiled.json +1 -1
  32. package/build/DvnPermissions.test.compiled.json +1 -1
  33. package/build/Endpoint.compiled.json +1 -1
  34. package/build/Endpoint.permissions.test.compiled.json +1 -1
  35. package/build/Endpoint.test.compiled.json +1 -1
  36. package/build/EndpointSetEpConfigDefaults.test.compiled.json +1 -1
  37. package/build/Executor.compiled.json +1 -1
  38. package/build/Executor.test.compiled.json +1 -1
  39. package/build/ExecutorFeeLib.compiled.json +1 -1
  40. package/build/ExecutorPermissions.test.compiled.json +1 -1
  41. package/build/LzClasses.test.compiled.json +1 -1
  42. package/build/LzUtil.test.compiled.json +1 -1
  43. package/build/MsgData.test.compiled.json +1 -1
  44. package/build/MsglibPacketCodec.test.compiled.json +1 -1
  45. package/build/PipelinedOutOfOrder.test.compiled.json +1 -1
  46. package/build/PriceFeedCache.compiled.json +1 -1
  47. package/build/PriceFeedCache.permissions.test.compiled.json +1 -1
  48. package/build/PriceFeedCache.test.compiled.json +1 -1
  49. package/build/Proxy.compiled.json +1 -1
  50. package/build/Proxy.permissions.test.compiled.json +1 -1
  51. package/build/Proxy.test.compiled.json +1 -1
  52. package/build/SmlConnection.compiled.json +1 -1
  53. package/build/SmlConnection.permissions.test.compiled.json +1 -1
  54. package/build/SmlConnection.test.compiled.json +1 -1
  55. package/build/SmlManager.compiled.json +1 -1
  56. package/build/SmlManager.permissions.test.compiled.json +1 -1
  57. package/build/SmlManager.test.compiled.json +1 -1
  58. package/build/Uln.compiled.json +1 -1
  59. package/build/Uln.test.compiled.json +1 -1
  60. package/build/UlnConnection.compiled.json +1 -1
  61. package/build/UlnConnection.test.compiled.json +1 -1
  62. package/build/UlnConnectionPermissions.test.compiled.json +1 -1
  63. package/build/UlnManagement.test.compiled.json +1 -1
  64. package/build/UlnManager.compiled.json +1 -1
  65. package/build/UlnManager.test.compiled.json +1 -1
  66. package/build/UlnManagerPermissions.test.compiled.json +1 -1
  67. package/build/UlnManagerUtil.test.compiled.json +1 -1
  68. package/build/UlnPermissions.test.compiled.json +1 -1
  69. package/build/UlnReceiveConfig.test.compiled.json +1 -1
  70. package/build/UlnSend.test.compiled.json +1 -1
  71. package/build/UlnSendConfig.test.compiled.json +1 -1
  72. package/build/UlnSendWithDvnFeeLib.test.compiled.json +1 -1
  73. package/build/UlnSendWithExecFeeLib.test.compiled.json +1 -1
  74. package/build/UlnSendWorkerFactory.test.compiled.json +1 -1
  75. package/build/UlnUtil.test.compiled.json +1 -1
  76. package/build/WorkerCore.test.compiled.json +1 -1
  77. package/build/badFeeLib1.test.compiled.json +1 -1
  78. package/build/badFeeLib10.test.compiled.json +1 -1
  79. package/build/badFeeLib11.test.compiled.json +1 -1
  80. package/build/badFeeLib12.test.compiled.json +1 -1
  81. package/build/badFeeLib2.test.compiled.json +1 -1
  82. package/build/badFeeLib3.test.compiled.json +1 -1
  83. package/build/badFeeLib4.test.compiled.json +1 -1
  84. package/build/badFeeLib5.test.compiled.json +1 -1
  85. package/build/badFeeLib6.test.compiled.json +1 -1
  86. package/build/badFeeLib7.test.compiled.json +1 -1
  87. package/build/badFeeLib8.test.compiled.json +1 -1
  88. package/build/badFeeLib9.test.compiled.json +1 -1
  89. package/package.json +5 -5
  90. package/src/classes/msgdata/LzReceiveStatus.fc +0 -1
  91. package/src/funC++/actions/call.fc +1 -0
  92. package/src/funC++/actions/deploy.fc +0 -1
  93. package/src/funC++/actions/destroy.fc +0 -1
  94. package/src/funC++/actions/dispatch.fc +0 -1
  95. package/src/funC++/actions/event.fc +0 -1
  96. package/src/funC++/actions/payment.fc +0 -1
  97. package/src/funC++/actions/sendJettons.fc +0 -1
  98. package/src/funC++/actions/utils.fc +0 -2
  99. package/src/funC++/baseInterface.fc +0 -2
  100. package/src/funC++/classlib.fc +0 -36
  101. package/src/funC++/contractMain.fc +2 -8
  102. package/src/funC++/dataStructures/DeterministicInsertionCircularQueue.fc +0 -1
  103. package/src/funC++/dataStructures/PipelinedOutOfOrder.fc +0 -1
  104. package/src/funC++/handlerCore.fc +2 -6
  105. package/src/funC++/stringlib.fc +0 -2
  106. package/src/funC++/testutils.fc +0 -1
  107. package/src/funC++/txnContext.fc +1 -1
  108. package/src/funC++/utils.fc +35 -0
  109. package/src/protocol/channel/callbackOpcodes.fc +10 -0
  110. package/src/protocol/channel/handler.fc +1032 -0
  111. package/src/protocol/channel/interface.fc +60 -0
  112. package/src/protocol/channel/main.fc +39 -0
  113. package/src/protocol/channel/storage.fc +55 -0
  114. package/src/protocol/controller/handler.fc +347 -0
  115. package/src/protocol/controller/interface.fc +25 -0
  116. package/src/protocol/controller/main.fc +29 -0
  117. package/src/protocol/controller/storage.fc +31 -0
  118. package/src/protocol/core/abstract/protocolHandler.fc +110 -0
  119. package/src/protocol/core/abstract/protocolMain.fc +30 -0
  120. package/src/protocol/core/baseStorage.fc +1 -2
  121. package/src/protocol/endpoint/handler.fc +426 -0
  122. package/src/protocol/endpoint/interface.fc +20 -0
  123. package/src/protocol/endpoint/main.fc +23 -0
  124. package/src/protocol/interfaces.fc +4 -0
  125. package/src/protocol/msglibs/BytesDecoder.fc +135 -0
  126. package/src/protocol/msglibs/BytesEncoder.fc +150 -0
  127. package/src/protocol/msglibs/interface.fc +16 -0
  128. package/src/protocol/msglibs/simpleMsglib/smlConnection/handler.fc +125 -0
  129. package/src/protocol/msglibs/simpleMsglib/smlConnection/interface.fc +3 -0
  130. package/src/protocol/msglibs/simpleMsglib/smlConnection/main.fc +19 -0
  131. package/src/protocol/msglibs/simpleMsglib/smlConnection/storage.fc +20 -0
  132. package/src/protocol/msglibs/simpleMsglib/smlManager/handler.fc +281 -0
  133. package/src/protocol/msglibs/simpleMsglib/smlManager/interface.fc +14 -0
  134. package/src/protocol/msglibs/simpleMsglib/smlManager/main.fc +24 -0
  135. package/src/protocol/msglibs/simpleMsglib/smlManager/storage.fc +38 -0
  136. package/src/protocol/msglibs/ultralightnode/callbackOpcodes.fc +1 -0
  137. package/src/protocol/msglibs/ultralightnode/feeLibInterface.fc +10 -0
  138. package/src/protocol/msglibs/ultralightnode/feeLibUtils.fc +51 -0
  139. package/src/protocol/msglibs/ultralightnode/msgdata/Attestation.fc +49 -0
  140. package/src/protocol/msglibs/ultralightnode/msgdata/DvnFeesPaidEvent.fc +26 -0
  141. package/src/protocol/msglibs/ultralightnode/msgdata/ExecutorFeePaidEvent.fc +23 -0
  142. package/src/protocol/msglibs/ultralightnode/msgdata/InitUln.fc +18 -0
  143. package/src/protocol/msglibs/ultralightnode/msgdata/InitUlnConnection.fc +62 -0
  144. package/src/protocol/msglibs/ultralightnode/msgdata/InitUlnManager.fc +18 -0
  145. package/src/protocol/msglibs/ultralightnode/msgdata/RentRefill.fc +18 -0
  146. package/src/protocol/msglibs/ultralightnode/msgdata/SetAdminWorkerAddresses.fc +18 -0
  147. package/src/protocol/msglibs/ultralightnode/msgdata/TreasuryFeeBps.fc +16 -0
  148. package/src/protocol/msglibs/ultralightnode/msgdata/UlnEvents.fc +26 -0
  149. package/src/protocol/msglibs/ultralightnode/msgdata/UlnReceiveConfig.fc +249 -0
  150. package/src/protocol/msglibs/ultralightnode/msgdata/UlnSend.fc +27 -0
  151. package/src/protocol/msglibs/ultralightnode/msgdata/UlnSendConfig.fc +170 -0
  152. package/src/protocol/msglibs/ultralightnode/msgdata/UlnVerification.fc +21 -0
  153. package/src/protocol/msglibs/ultralightnode/msgdata/UlnWorkerFeelibBytecode.fc +16 -0
  154. package/src/protocol/msglibs/ultralightnode/msgdata/UlnWorkerFeelibEvents.fc +58 -0
  155. package/src/protocol/msglibs/ultralightnode/msgdata/UlnWorkerFeelibInfo.fc +56 -0
  156. package/src/protocol/msglibs/ultralightnode/msgdata/VerificationStatus.fc +18 -0
  157. package/src/protocol/msglibs/ultralightnode/uln/handler.fc +803 -0
  158. package/src/protocol/msglibs/ultralightnode/uln/interface.fc +63 -0
  159. package/src/protocol/msglibs/ultralightnode/uln/main.fc +37 -0
  160. package/src/protocol/msglibs/ultralightnode/uln/storage.fc +43 -0
  161. package/src/protocol/msglibs/ultralightnode/ulnConnection/handler.fc +600 -0
  162. package/src/protocol/msglibs/ultralightnode/ulnConnection/interface.fc +36 -0
  163. package/src/protocol/msglibs/ultralightnode/ulnConnection/main.fc +32 -0
  164. package/src/protocol/msglibs/ultralightnode/ulnConnection/storage.fc +49 -0
  165. package/src/protocol/msglibs/ultralightnode/ulnConnection/utils.fc +141 -0
  166. package/src/protocol/msglibs/ultralightnode/ulnManager/handler.fc +495 -0
  167. package/src/protocol/msglibs/ultralightnode/ulnManager/interface.fc +59 -0
  168. package/src/protocol/msglibs/ultralightnode/ulnManager/main.fc +40 -0
  169. package/src/protocol/msglibs/ultralightnode/ulnManager/storage.fc +44 -0
  170. package/src/protocol/msglibs/ultralightnode/workerFeeLibs/common.fc +27 -0
  171. package/src/protocol/msglibs/ultralightnode/workerFeeLibs/dvnFeeLib/handler.fc +80 -0
  172. package/src/protocol/msglibs/ultralightnode/workerFeeLibs/dvnFeeLib/main.fc +4 -0
  173. package/src/protocol/msglibs/ultralightnode/workerFeeLibs/dvnFeeLib/storage.fc +26 -0
  174. package/src/protocol/msglibs/ultralightnode/workerFeeLibs/executorFeeLib/handler.fc +123 -0
  175. package/src/protocol/msglibs/ultralightnode/workerFeeLibs/executorFeeLib/main.fc +4 -0
  176. package/src/protocol/msglibs/ultralightnode/workerFeeLibs/executorFeeLib/storage.fc +29 -0
  177. package/src/protocol/msglibs/ultralightnode/workerFeeLibs/main.fc +3 -0
  178. package/src/protocol/msglibs/ultralightnode/workerFeeLibs/priceFeedFeeLib/main.fc +1 -0
  179. package/src/protocol/msglibs/ultralightnode/workerFeeLibs/priceFeedFeeLib/storage.fc +39 -0
  180. package/src/protocol/msglibs/ultralightnode/workerFeeLibs/ulnSendWorkerV1.fc +363 -0
  181. package/src/workers/core/abstract/workerHandler.fc +150 -0
  182. package/src/workers/core/interface.fc +25 -0
  183. package/src/workers/core/workerCoreStorage.fc +44 -0
  184. package/src/workers/dvn/handler.fc +332 -0
  185. package/src/workers/dvn/interface.fc +25 -0
  186. package/src/workers/dvn/main.fc +36 -0
  187. package/src/workers/dvn/storage.fc +27 -0
  188. package/src/workers/executor/handler.fc +110 -0
  189. package/src/workers/executor/interface.fc +19 -0
  190. package/src/workers/executor/main.fc +26 -0
  191. package/src/workers/executor/storage.fc +19 -0
  192. package/src/workers/msgdata/ExecuteParams.fc +29 -0
  193. package/src/workers/msgdata/NativeDrop.fc +16 -0
  194. package/src/workers/msgdata/ProxyMessage.fc +20 -0
  195. package/src/workers/msgdata/SetDict.fc +20 -0
  196. package/src/workers/msgdata/SetQuorum.fc +20 -0
  197. package/src/workers/msgdata/SignedRequest.fc +18 -0
  198. package/src/workers/priceFeedCache/handler.fc +114 -0
  199. package/src/workers/priceFeedCache/interface.fc +4 -0
  200. package/src/workers/priceFeedCache/main.fc +25 -0
  201. package/src/workers/priceFeedCache/storage.fc +21 -0
  202. package/src/workers/proxy/handler.fc +81 -0
  203. package/src/workers/proxy/interface.fc +11 -0
  204. package/src/workers/proxy/main.fc +17 -0
  205. package/src/workers/proxy/storage.fc +21 -0
  206. package/tests/testMain.fc +0 -1
@@ -0,0 +1,110 @@
1
+ #include "../../../funC++/handlerCore.fc";
2
+ #include "../../../funC++/actions/call.fc";
3
+ #include "../../../funC++/actions/deploy.fc";
4
+ #include "../../../funC++/actions/event.fc";
5
+ #include "../../../funC++/actions/payment.fc";
6
+
7
+ #include "../baseStorage.fc";
8
+
9
+ int getOwner() impure inline {
10
+ return getContractStorage()
11
+ .cl::get<objRef>(BASE_STORAGE_INDEX)
12
+ .cl::get<address>(BaseStorage::owner);
13
+ }
14
+
15
+ cell getInitialStorage() impure inline {
16
+ return getContractStorage()
17
+ .cl::get<objRef>(BASE_STORAGE_INDEX)
18
+ .cl::get<objRef>(BaseStorage::initialStorage);
19
+ }
20
+
21
+ ;;; ==========================================
22
+ ;; Modifiers
23
+ () assertAuthenticated() impure inline {
24
+ cell $baseStorage = getContractStorage().cl::get<objRef>(BASE_STORAGE_INDEX);
25
+ throw_unless(
26
+ BaseInterface::ERROR::notAuthenticated,
27
+ $baseStorage.cl::get<bool>(BaseStorage::authenticated)
28
+ );
29
+ }
30
+
31
+ () assertInitialized() impure inline {
32
+ cell $baseStorage = getContractStorage().cl::get<objRef>(BASE_STORAGE_INDEX);
33
+ throw_unless(
34
+ BaseInterface::ERROR::notInitialized,
35
+ $baseStorage.cl::get<bool>(BaseStorage::initialized)
36
+ );
37
+ }
38
+
39
+ ;; assert the ctx sender is the owner of this contract
40
+ ;; expects the ctx to be populated. Does not require storage to be loaded
41
+ () assertOwner() impure inline {
42
+ cell $baseStorage = getContractStorage().cl::get<objRef>(BASE_STORAGE_INDEX);
43
+ throw_unless(
44
+ BaseInterface::ERROR::onlyOwner,
45
+ getCaller() == $baseStorage.cl::get<address>(BaseStorage::owner)
46
+ );
47
+ }
48
+
49
+ ;; Step 1: authenticate
50
+ () authenticate() impure {
51
+ assertOwner();
52
+ cell $storage = getContractStorage();
53
+
54
+ setContractStorage(
55
+ $storage
56
+ .cl::set(
57
+ BASE_STORAGE_INDEX,
58
+ $storage
59
+ .cl::get<objRef>(BASE_STORAGE_INDEX)
60
+ .cl::set(
61
+ BaseStorage::initialStorage,
62
+ getContractStorage()
63
+ )
64
+ .cl::set(BaseStorage::authenticated, true)
65
+ )
66
+ );
67
+ }
68
+
69
+ () authenticateIfNecessary() impure inline {
70
+ if (getContractStorage()
71
+ .cl::get<objRef>(BASE_STORAGE_INDEX)
72
+ .cl::get<bool>(BaseStorage::authenticated) == false
73
+ ) {
74
+ authenticate();
75
+ }
76
+ }
77
+
78
+ (cell, tuple) _initialize(cell $md) impure inline;
79
+
80
+ ;; Step 2: initialize
81
+ tuple initialize(cell $md) impure inline {
82
+ assertAuthenticated();
83
+ if (
84
+ getContractStorage()
85
+ .cl::get<objRef>(BASE_STORAGE_INDEX)
86
+ .cl::get<bool>(BaseStorage::initialized)
87
+ ) {
88
+ return emptyActions();
89
+ }
90
+
91
+ (cell $storage, tuple actions) = _initialize($md);
92
+
93
+ setContractStorage(
94
+ $storage
95
+ .cl::set(
96
+ BASE_STORAGE_INDEX,
97
+ $storage
98
+ .cl::get<objRef>(BASE_STORAGE_INDEX)
99
+ .cl::set(BaseStorage::initialized, true)
100
+ )
101
+ );
102
+
103
+ return actions;
104
+ }
105
+
106
+ ;; declared inside of the actions/event.fc
107
+ ;; We declare it here because it saves the need for declaring initialStorage everytime we call event
108
+ tuple _newAction<event>(int topic, cell $body) impure inline {
109
+ return action::event::New(topic, $body, getInitialStorage());
110
+ }
@@ -0,0 +1,30 @@
1
+ ;;; ================================================================
2
+ ;; The base main function for LayerZero Endpoint, UltraLightNode, and OApp
3
+ ;;; ================================================================
4
+ #include "../../../funC++/actions/call.fc";
5
+ #include "../../../funC++/actions/deploy.fc";
6
+ #include "../../../funC++/actions/dispatch.fc";
7
+ #include "../../../funC++/actions/event.fc";
8
+ #include "../../../funC++/actions/payment.fc";
9
+
10
+ #include "../../../funC++/contractMain.fc";
11
+ #include "../../../funC++/handlerCore.fc";
12
+
13
+ int _executeAction(int actionType, tuple action) impure inline {
14
+ if (actionType == action::event::NAME) {
15
+ return executeEvent(action);
16
+ } elseif (actionType == action::call::NAME) {
17
+ return executeCall(action);
18
+ } elseif (actionType == action::payment::NAME) {
19
+ return executePayment(action);
20
+ } elseif (actionType == action::dispatch::NAME) {
21
+ return executeDispatch(action);
22
+ } elseif (actionType == action::deploy::NAME) {
23
+ return executeDeploy(action);
24
+ } else {
25
+ throw(BaseInterface::ERROR::invalidActionType);
26
+ }
27
+
28
+ ;; compiler freaks out if you dont have something here returning an int, but this should never be reached
29
+ return false;
30
+ }
@@ -1,6 +1,5 @@
1
- #include "../../funC++/baseInterface.fc";
2
1
  #include "../../funC++/classlib.fc";
3
- #include "../../funC++/actions/utils.fc";
2
+ #include "../../funC++/baseInterface.fc";
4
3
 
5
4
  ;; !!! If you put this storage anywhere other than index 0 of your custom contract storage,
6
5
  ;; you are gunna have a bad time
@@ -0,0 +1,426 @@
1
+ #include "../core/abstract/protocolHandler.fc";
2
+
3
+ #include "../../classes/lz/SendEpConfig.fc";
4
+ #include "../../classes/lz/MsglibInfo.fc";
5
+ #include "../../classes/lz/ReceiveEpConfig.fc";
6
+ #include "../../classes/lz/Packet.fc";
7
+ #include "../../classes/lz/Path.fc";
8
+ #include "../../classes/lz/EpConfig.fc";
9
+
10
+ #include "../../classes/msgdata/ExtendedMd.fc";
11
+ #include "../../classes/msgdata/MdAddress.fc";
12
+ #include "../../classes/msgdata/MdObj.fc";
13
+ #include "../../classes/msgdata/AddMsglib.fc";
14
+ #include "../../classes/msgdata/InitEndpoint.fc";
15
+ #include "../../classes/msgdata/LzSend.fc";
16
+ #include "../../classes/msgdata/SetEpConfig.fc";
17
+
18
+ #include "../../funC++/txnContext.fc";
19
+
20
+ #include "../channel/storage.fc";
21
+ #include "../interfaces.fc";
22
+ #include "interface.fc";
23
+ #include "storage.fc";
24
+
25
+ ;;; ==========================HELPER FUNCTIONS=====================================
26
+
27
+ ;; In LayerZero-TON, the msglib manager address is the outward facing alias for the messagelib
28
+ ;; that all users and admins specify in configurations etc.
29
+ ;; Within the protocol scope, the channel directly communicates `to` the Messagelib Connection
30
+ ;; shard and receives communication `from` some other arbitrary messagelib shard (for efficiency).
31
+ ;; shard addresses, this is where the validity of the messagelib is checked (i.e., that no
32
+ ;; unauthorized messagelib can be chosen in a configuration).
33
+ ;; @return (msglibAddress: address, msglibConnectionAddress: address)
34
+ (int, int) _msglibManagerToShards(int msglibManagerAddress, cell $path) impure inline method_id {
35
+ if (msglibManagerAddress == NULLADDRESS) {
36
+ return (NULLADDRESS, NULLADDRESS);
37
+ }
38
+
39
+ (cell $msglibInfo, int exists) = getContractStorage()
40
+ .cl::nestedDict256::get<cellRef>(Endpoint::msglibs, msglibManagerAddress);
41
+
42
+ throw_unless(
43
+ Endpoint::ERROR::unauthorizedMsglib,
44
+ exists
45
+ );
46
+
47
+ throw_unless(
48
+ Endpoint::ERROR::unresolvedMsglib,
49
+ $msglibInfo.cl::hash() != cl::nullObject().cl::hash()
50
+ );
51
+
52
+ return (
53
+ $msglibInfo.cl::get<address>(lz::MsglibInfo::msglibAddress),
54
+ lz::MsglibInfo::getMsglibConnectionAddress($msglibInfo, $path)
55
+ );
56
+ }
57
+
58
+ ;; Derive the channel address for a given path
59
+ int _getChannelAddress(cell $path) inline method_id {
60
+ cell $storage = getContractStorage();
61
+ return computeContractAddress(
62
+ $storage
63
+ .cl::get<objRef>(Endpoint::channelStorageInit)
64
+ .cl::set(Channel::path, $path),
65
+ $storage.cl::get<cellRef>(Endpoint::channelCode)
66
+ );
67
+ }
68
+
69
+ ;; resolve manager addresses into msglib addresses
70
+ ;; throws if the msglib manager is not registered or resolved
71
+ cell _getEpConfigFromManagerAddresses(cell $setEpConfigMd, cell $path) inline method_id {
72
+ int sendMsglibManager = $setEpConfigMd.cl::get<address>(md::SetEpConfig::sendMsglibManager);
73
+ (int sendMsglib, int sendMsglibConnection) = _msglibManagerToShards(
74
+ sendMsglibManager,
75
+ $path
76
+ );
77
+
78
+ int receiveMsglibManager = $setEpConfigMd.cl::get<address>(md::SetEpConfig::receiveMsglibManager);
79
+ (int receiveMsglib, int receiveMsglibConnection) = _msglibManagerToShards(
80
+ receiveMsglibManager,
81
+ $path
82
+ );
83
+
84
+ int timeoutReceiveMsglibManager = $setEpConfigMd.cl::get<address>(md::SetEpConfig::timeoutReceiveMsglibManager);
85
+ (int timeoutReceiveMsglib, int timeoutReceiveMsglibConnection) = _msglibManagerToShards(
86
+ timeoutReceiveMsglibManager,
87
+ $path
88
+ );
89
+
90
+ throw_if(
91
+ Endpoint::ERROR::sameTimeoutAndReceive,
92
+ (receiveMsglibManager == timeoutReceiveMsglibManager) & (receiveMsglibManager != NULLADDRESS)
93
+ );
94
+
95
+ return lz::EpConfig::NewWithConnection(
96
+ $setEpConfigMd.cl::get<bool>(md::SetEpConfig::useDefaults),
97
+ sendMsglib,
98
+ sendMsglibConnection,
99
+ receiveMsglib,
100
+ receiveMsglibConnection,
101
+ timeoutReceiveMsglib,
102
+ timeoutReceiveMsglibConnection,
103
+ $setEpConfigMd.cl::get<uint64>(md::SetEpConfig::timeoutReceiveMsglibExpiry)
104
+ );
105
+ }
106
+
107
+ (int, int) _getMsglibAndConnectionDefaults(int key, cell $path) inline method_id {
108
+ cell $msglibInfo = getContractStorage().cl::get<objRef>(key);
109
+ if (cl::isNull($msglibInfo)) {
110
+ return (NULLADDRESS, NULLADDRESS);
111
+ }
112
+ return (
113
+ $msglibInfo.cl::get<address>(lz::MsglibInfo::msglibAddress),
114
+ lz::MsglibInfo::getMsglibConnectionAddress($msglibInfo, $path)
115
+ );
116
+ }
117
+
118
+ (int, int) _getSendMsglibAndConnectionDefaults(cell $path) inline method_id {
119
+ return _getMsglibAndConnectionDefaults(Endpoint::defaultSendLibInfo, $path);
120
+ }
121
+
122
+ (int, int) getReceiveMsglibAndConnectionDefaults(cell $path) inline method_id {
123
+ return _getMsglibAndConnectionDefaults(Endpoint::defaultReceiveLibInfo, $path);
124
+ }
125
+
126
+ (int, int) getTimeoutReceiveMsglibAndConnectionDefaults(cell $path) inline method_id {
127
+ return _getMsglibAndConnectionDefaults(Endpoint::defaultTimeoutReceiveLibInfo, $path);
128
+ }
129
+
130
+ () _assertAuthorizedMsglib() impure inline method_id {
131
+ (_, int exists) = getContractStorage()
132
+ .cl::nestedDict256::get<cellRef>(Endpoint::msglibs, getCaller());
133
+
134
+ throw_unless(Endpoint::ERROR::unauthorizedMsglib, exists);
135
+ }
136
+
137
+ ;;; ================INTERFACE FUNCTIONS=====================
138
+
139
+ (cell, tuple) _initialize(cell $initEndpoint) impure inline {
140
+ (cell $storage, tuple actions) = preamble();
141
+ return (
142
+ $storage
143
+ .cl::set(
144
+ Endpoint::channelCode,
145
+ $initEndpoint.cl::get<cellRef>(md::InitEndpoint::channelCode)
146
+ )
147
+ .cl::set(
148
+ Endpoint::channelStorageInit,
149
+ Channel::New(
150
+ getOwner(),
151
+ lz::Path::endpointPath(
152
+ $storage.cl::get<uint32>(Endpoint::eid),
153
+ $storage.cl::get<uint32>(Endpoint::dstEid)
154
+ ),
155
+ getContractAddress()
156
+ )
157
+ ),
158
+ actions
159
+ );
160
+ }
161
+
162
+ int _getEventSink() impure inline {
163
+ return getContractStorage()
164
+ .cl::get<objRef>(Endpoint::baseStorage)
165
+ .cl::get<address>(BaseStorage::owner);
166
+ }
167
+
168
+
169
+ ;;; ================PERMISSION FUNCTIONS=====================
170
+
171
+ () _checkPermissions(int op, cell $md) impure inline {
172
+ if (op == Endpoint::OP::ENDPOINT_SEND) {
173
+ throw_unless(Endpoint::ERROR::notOApp,
174
+ getCaller() == $md
175
+ .cl::get<objRef>(md::LzSend::packet)
176
+ .cl::get<objRef>(lz::Packet::path)
177
+ .cl::get<address>(lz::Path::srcOApp)
178
+ );
179
+ } elseif (op == Endpoint::OP::ENDPOINT_COMMIT_PACKET) {
180
+ ;; open and public calls
181
+ return ();
182
+ } elseif (
183
+ (op == Endpoint::OP::SET_EP_CONFIG_OAPP)
184
+ | (op == Endpoint::OP::SET_EP_CONFIG_DEFAULTS)
185
+ | (op == Endpoint::OP::ADD_MSGLIB)
186
+ ) {
187
+ return assertOwner(); ;; controller
188
+ } elseif (op == Endpoint::OP::GET_MSGLIB_INFO_CALLBACK) {
189
+ return _assertAuthorizedMsglib();
190
+ } else {
191
+ ;; we must put a check for all opcodes to make sure we don't
192
+ ;; mistakenly miss an opp code's permissions
193
+ throw(BaseInterface::ERROR::invalidOpcode);
194
+ }
195
+ }
196
+
197
+ ;;; ==========================HANDLERS=====================================
198
+ ;; @in controller/handler.fc/setEpConfigDefaults
199
+ ;; @in_md setEpConfig
200
+ ;; @out controller/handler.fc/emit_event
201
+ ;; @permissions owner
202
+ ;; We MIGHT not support defaults for certain connections/dstEids
203
+ tuple setEpConfigDefaults(cell $setEpConfigMd) impure inline method_id {
204
+ (cell $storage, tuple actions) = preamble();
205
+
206
+ cell $path = lz::Path::endpointPath(
207
+ $storage.cl::get<uint32>(Endpoint::eid),
208
+ $storage.cl::get<uint32>(Endpoint::dstEid)
209
+ );
210
+
211
+ int sendLibManager = $setEpConfigMd
212
+ .cl::get<address>(md::SetEpConfig::sendMsglibManager);
213
+
214
+ int receiveLibManager = $setEpConfigMd
215
+ .cl::get<address>(md::SetEpConfig::receiveMsglibManager);
216
+
217
+ int timeoutReceiveLibManager = $setEpConfigMd
218
+ .cl::get<address>(md::SetEpConfig::timeoutReceiveMsglibManager);
219
+
220
+ (cell $sendLibInfo, int sendLibExists) = getContractStorage()
221
+ .cl::nestedDict256::get<cellRef>(Endpoint::msglibs, sendLibManager);
222
+
223
+ (cell $receiveLibInfo, int receiveLibExists) = getContractStorage()
224
+ .cl::nestedDict256::get<cellRef>(Endpoint::msglibs, receiveLibManager);
225
+
226
+ (cell $timeoutReceiveLibInfo, int timeoutReceiveLibExists) = getContractStorage()
227
+ .cl::nestedDict256::get<cellRef>(Endpoint::msglibs, timeoutReceiveLibManager);
228
+
229
+ int expiry = $setEpConfigMd.cl::get<uint64>(md::SetEpConfig::timeoutReceiveMsglibExpiry);
230
+ throw_unless(
231
+ Endpoint::ERROR::unauthorizedMsglib,
232
+ (sendLibExists | (sendLibManager == NULLADDRESS))
233
+ & (receiveLibExists | (receiveLibManager == NULLADDRESS))
234
+ & (timeoutReceiveLibExists | (timeoutReceiveLibManager == NULLADDRESS))
235
+ );
236
+ throw_if(
237
+ Endpoint::ERROR::sameTimeoutAndReceive,
238
+ (timeoutReceiveLibManager != NULLADDRESS) & (timeoutReceiveLibManager == receiveLibManager)
239
+ );
240
+ throw_unless(
241
+ Endpoint::ERROR::invalidExpiry,
242
+ ((timeoutReceiveLibManager == NULLADDRESS) & (expiry == 0))
243
+ | ((timeoutReceiveLibManager != NULLADDRESS) & (expiry > now()))
244
+ );
245
+
246
+ ;; make sure the manager addresses can be resolved
247
+ int validity = _getEpConfigFromManagerAddresses($setEpConfigMd, $path).lz::EpConfig::isValid();
248
+ ;; The above block validates *all* the inputs, meaning this throw_if will actually never
249
+ ;; throw. We leave it in because it doesn't hurt, might as well keep it.
250
+ ;; The extra gas cost is inconsequential because this is a configuration flow.
251
+ throw_if(validity, validity != lz::EpConfig::VALID);
252
+
253
+ setContractStorage(
254
+ $storage
255
+ .cl::set(Endpoint::defaultSendLibInfo, $sendLibInfo)
256
+ .cl::set(Endpoint::defaultReceiveLibInfo, $receiveLibInfo)
257
+ .cl::set(Endpoint::defaultTimeoutReceiveLibInfo, $timeoutReceiveLibInfo)
258
+ .cl::set(Endpoint::defaultExpiry, expiry)
259
+ );
260
+
261
+ ;; push the event
262
+ actions~pushAction<event>(Endpoint::event::EP_CONFIG_DEFAULTS_SET, $setEpConfigMd);
263
+
264
+ return actions;
265
+ }
266
+
267
+ ;; @in controller/handler.fc/setEpConfig
268
+ ;; @in_md ExtendedMd(channelAddress, setEpConfig)
269
+ ;; @out channel/handler.fc/setEpConfig
270
+ ;; @out_md ExtendedMd(defaultEpConfig, setEpConfig)
271
+ ;; @permissions owner
272
+ tuple setEpConfigOApp(cell $mdObj) impure inline method_id {
273
+ (_, tuple actions) = preamble();
274
+
275
+ ;; extract the md params
276
+ cell $setEpConfigOApp = $mdObj.cl::get<objRef>(md::MdObj::md);
277
+ cell $path = $mdObj.cl::get<objRef>(md::MdObj::obj);
278
+ cell $resolvedEpConfigOApp = _getEpConfigFromManagerAddresses($setEpConfigOApp, $path);
279
+
280
+ ;; send message to channel and forward the ep config defaults
281
+ actions~pushAction<call>(
282
+ _getChannelAddress($path),
283
+ Channel::OP::SET_EP_CONFIG_OAPP,
284
+ $resolvedEpConfigOApp
285
+ );
286
+
287
+ return actions;
288
+ }
289
+
290
+ ;; @in oApp/handler.fc/send
291
+ ;; @in_md lzSend
292
+ ;; @out channel/handler.fc/send
293
+ ;; @out_md MdObj(lzSend, defaultSendConfig)
294
+ ;; @permissions OApp
295
+ tuple endpointSend(cell $lzSend) impure inline method_id {
296
+ (_, tuple actions) = preamble();
297
+ ;; already asserted caller identity matches the request contents in checkPermissions()
298
+ cell $packet = $lzSend.cl::get<objRef>(md::LzSend::packet);
299
+ cell $path = $packet.cl::get<objRef>(lz::Packet::path);
300
+
301
+ ;; Invariant: if a msglib is set as a default msglib, it must be resolved
302
+ ;; thus, _getSendMsglibAndConnectionDefaults should never revert
303
+ (int sendMsglib, int sendMsglibConnection) = _getSendMsglibAndConnectionDefaults($path);
304
+
305
+ actions~pushAction<call>(
306
+ _getChannelAddress($path),
307
+ Channel::OP::CHANNEL_SEND,
308
+ md::MdObj::New($lzSend, lz::SendEpConfig::New(sendMsglib, sendMsglibConnection))
309
+ );
310
+ return actions;
311
+ }
312
+
313
+ ;; @in msglib/handler.fc/commitVerification
314
+ ;; @in_md ExtendedMd(msglib_addr, _, endpointCommitPacket)
315
+ ;; @out channel/handler.fc/endpointCommitPacket
316
+ ;; @out_md ExtendedMd(msglib_addr, defaultEpConfig, endpointCommitPacket)
317
+ tuple endpointCommitPacket(cell $packet) impure inline method_id {
318
+ (cell $storage, tuple actions) = preamble();
319
+
320
+ cell $receivePath = $packet.cl::get<objRef>(lz::Packet::path);
321
+
322
+ ;; Assert we are the correct endpoint for this commit request
323
+ ;; the srcEid of the packet should match the dstEid of the endpoint contract
324
+ throw_if(
325
+ Endpoint::ERROR::wrongPath,
326
+ ($receivePath.cl::get<uint32>(lz::Path::srcEid) != $storage.cl::get<uint32>(Endpoint::dstEid))
327
+ | ($receivePath.cl::get<uint32>(lz::Path::dstEid) != $storage.cl::get<uint32>(Endpoint::eid))
328
+ );
329
+
330
+ cell $sendPath = $receivePath.lz::Path::optimizedReverse();
331
+ int channelAddress = computeContractAddress(
332
+ $storage
333
+ .cl::get<objRef>(Endpoint::channelStorageInit)
334
+ .cl::set(Channel::path, $sendPath),
335
+ $storage.cl::get<cellRef>(Endpoint::channelCode)
336
+ );
337
+
338
+ (_, int receiveMsglibConnection) = getReceiveMsglibAndConnectionDefaults($sendPath);
339
+ (_, int timeoutReceiveMsglibConnection) = getTimeoutReceiveMsglibAndConnectionDefaults(
340
+ $sendPath
341
+ );
342
+
343
+ actions~pushAction<call>(
344
+ channelAddress,
345
+ Channel::OP::CHANNEL_COMMIT_PACKET,
346
+ md::ExtendedMd::New(
347
+ $packet,
348
+ lz::ReceiveEpConfig::New(
349
+ receiveMsglibConnection,
350
+ timeoutReceiveMsglibConnection,
351
+ $storage.cl::get<uint64>(Endpoint::defaultExpiry)
352
+ ),
353
+ getCaller()
354
+ )
355
+ );
356
+
357
+ return actions;
358
+ }
359
+
360
+ ;; @permissions controller
361
+ ;; @in controller/handler.fc/addMsglib
362
+ ;; @in_md resolve_msglib (msglib manager address)
363
+ ;; @out msglib controller/handler.fc/resolve_msglib
364
+ ;; @out_md resolve_msglib (msglib manager address, eid)
365
+ tuple addMsglib(cell $addMsglib) impure inline method_id {
366
+ (cell $storage, tuple actions) = preamble();
367
+
368
+ ;; Not necessary to check dstEid in $addMsglib is correct, because
369
+ ;; the controller derives our address based on dstEid, so it cannot be wrong.
370
+
371
+ int msglibManagerAddress = $addMsglib.cl::get<address>(md::AddMsglib::msglibManagerAddress);
372
+ (cell $msglibInfo, int exists) = $storage.cl::nestedDict256::get<cellRef>(
373
+ Endpoint::msglibs,
374
+ msglibManagerAddress
375
+ );
376
+
377
+ ifnot (exists) {
378
+ ;; Check that we havent exceeded the max number of msglibs
379
+ int currentNumMsglibs = $storage.cl::get<uint8>(Endpoint::numMsglibs);
380
+ throw_unless(Endpoint::ERROR::numMsglibsExceeded, currentNumMsglibs < MAX_MSGLIBS);
381
+
382
+ setContractStorage(
383
+ $storage
384
+ .cl::nestedDict256::setRef(
385
+ Endpoint::msglibs,
386
+ msglibManagerAddress,
387
+ cl::nullObject()
388
+ )
389
+ .cl::set(Endpoint::numMsglibs, currentNumMsglibs + 1)
390
+ );
391
+ }
392
+
393
+ ;; if the previous addMsglib ran out of gas, it can be retried
394
+ if ((~ exists) | $msglibInfo.cl::isNull()) {
395
+ ;; Call the msglib manager to resolve the correct msglib contract
396
+ ;; address for this endpoint's remote eid
397
+ actions~pushAction<call>(
398
+ msglibManagerAddress,
399
+ MsglibManager::OP::GET_MSGLIB_INFO,
400
+ $addMsglib
401
+ );
402
+ }
403
+
404
+ return actions;
405
+ }
406
+
407
+ ;; @in Any MsglibManager that was added in addMsglib
408
+ ;; @in_md MsglibInfo
409
+ ;; @out refund
410
+ tuple getMsglibInfoCallback(cell $msglibInfo) impure inline method_id {
411
+ (cell $storage, tuple actions) = preamble();
412
+
413
+ ;; the storedMsglibInfo is asserted to exist in checkPermissions
414
+ (cell $storedMsglibInfo, _) = $storage.cl::nestedDict256::get<cellRef>(
415
+ Endpoint::msglibs,
416
+ getCaller()
417
+ );
418
+
419
+ throw_unless(Endpoint::ERROR::msglibInfoExists, $storedMsglibInfo.cl::isNull());
420
+
421
+ setContractStorage(
422
+ $storage.cl::nestedDict256::setRef(Endpoint::msglibs, getCaller(), $msglibInfo)
423
+ );
424
+
425
+ return actions;
426
+ }
@@ -0,0 +1,20 @@
1
+ ;; OPCODES
2
+ const int Endpoint::OP::ENDPOINT_SEND = "Endpoint::OP::ENDPOINT_SEND"c;
3
+ const int Endpoint::OP::ENDPOINT_COMMIT_PACKET = "Endpoint::OP::ENDPOINT_COMMIT_PACKET"c;
4
+ const int Endpoint::OP::SET_EP_CONFIG_DEFAULTS = "Endpoint::OP::SET_EP_CONFIG_DEFAULTS"c;
5
+ const int Endpoint::OP::SET_EP_CONFIG_OAPP = "Endpoint::OP::SET_EP_CONFIG_OAPP"c;
6
+ const int Endpoint::OP::ADD_MSGLIB = "Endpoint::OP::ADD_MSGLIB"c;
7
+ const int Endpoint::OP::GET_MSGLIB_INFO_CALLBACK = "Endpoint::OP::GET_MSGLIB_INFO_CALLBACK"c;
8
+
9
+ ;; EVENTS
10
+ const int Endpoint::event::EP_CONFIG_DEFAULTS_SET = "EP_CONFIG_DEFAULTS_SET"u;
11
+
12
+ ;; ERRORS
13
+ const int Endpoint::ERROR::notOApp = 97;
14
+ const int Endpoint::ERROR::wrongPath = 98;
15
+ const int Endpoint::ERROR::unauthorizedMsglib = 99;
16
+ const int Endpoint::ERROR::invalidExpiry = 100;
17
+ const int Endpoint::ERROR::unresolvedMsglib = 101;
18
+ const int Endpoint::ERROR::msglibInfoExists = 102;
19
+ const int Endpoint::ERROR::numMsglibsExceeded = 103;
20
+ const int Endpoint::ERROR::sameTimeoutAndReceive = 104;
@@ -0,0 +1,23 @@
1
+ #include "../core/abstract/protocolMain.fc";
2
+
3
+ #include "handler.fc";
4
+ #include "interface.fc";
5
+
6
+ tuple _executeOpcode(int op, cell $md) impure inline {
7
+ if (op == Endpoint::OP::ENDPOINT_SEND) {
8
+ return endpointSend($md);
9
+ } elseif (op == Endpoint::OP::ENDPOINT_COMMIT_PACKET) {
10
+ return endpointCommitPacket($md);
11
+ } elseif (op == Endpoint::OP::SET_EP_CONFIG_DEFAULTS) {
12
+ return setEpConfigDefaults($md);
13
+ } elseif (op == Endpoint::OP::SET_EP_CONFIG_OAPP) {
14
+ return setEpConfigOApp($md);
15
+ } elseif (op == Endpoint::OP::ADD_MSGLIB) {
16
+ return addMsglib($md);
17
+ } elseif (op == Endpoint::OP::GET_MSGLIB_INFO_CALLBACK) {
18
+ return getMsglibInfoCallback($md);
19
+ }
20
+ throw(BaseInterface::ERROR::invalidOpcode);
21
+ return empty_tuple();
22
+ }
23
+
@@ -0,0 +1,4 @@
1
+ #include "channel/interface.fc";
2
+ #include "controller/interface.fc";
3
+ #include "endpoint/interface.fc";
4
+ #include "msglibs/interface.fc";