powerdlz23 1.1.5 → 1.1.7

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 (46) hide show
  1. package/Zefoy-Automation/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  2. package/Zefoy-Automation/README.md +134 -0
  3. package/Zefoy-Automation/captcha.png +0 -0
  4. package/Zefoy-Automation/donation-userlist.md +7 -0
  5. package/Zefoy-Automation/main.py +257 -0
  6. package/Zefoy-Automation/output/Zefoy Automation for Windows.exe +0 -0
  7. package/Zefoy-Automation/requirements.txt +5 -0
  8. package/Zefoy-Automation/src/captcha.png +0 -0
  9. package/Zefoy-Automation/src/process.py +269 -0
  10. package/package.json +1 -1
  11. package/polymer/polymer-template/.env.example +27 -0
  12. package/polymer/polymer-template/.gitmodules +6 -0
  13. package/polymer/polymer-template/.gitpod.yml +10 -0
  14. package/polymer/polymer-template/Justfile +97 -0
  15. package/polymer/polymer-template/README.md +312 -0
  16. package/polymer/polymer-template/config/alt-config.json +42 -0
  17. package/polymer/polymer-template/config.json +42 -0
  18. package/polymer/polymer-template/contracts/XCounter.sol +89 -0
  19. package/polymer/polymer-template/contracts/XCounterUC.sol +100 -0
  20. package/polymer/polymer-template/contracts/arguments.js +7 -0
  21. package/polymer/polymer-template/contracts/base/CustomChanIbcApp.sol +205 -0
  22. package/polymer/polymer-template/contracts/base/GeneralMiddleware.sol +200 -0
  23. package/polymer/polymer-template/contracts/base/UniversalChanIbcApp.sol +93 -0
  24. package/polymer/polymer-template/foundry.toml +6 -0
  25. package/polymer/polymer-template/hardhat.config.js +66 -0
  26. package/polymer/polymer-template/ibc.json +26 -0
  27. package/polymer/polymer-template/img/gh_template.png +0 -0
  28. package/polymer/polymer-template/package-lock.json +7672 -0
  29. package/polymer/polymer-template/package.json +34 -0
  30. package/polymer/polymer-template/remappings.txt +5 -0
  31. package/polymer/polymer-template/scripts/deploy.js +51 -0
  32. package/polymer/polymer-template/scripts/private/_create-channel-config.js +62 -0
  33. package/polymer/polymer-template/scripts/private/_create-channel.js +96 -0
  34. package/polymer/polymer-template/scripts/private/_deploy-config.js +62 -0
  35. package/polymer/polymer-template/scripts/private/_events.js +241 -0
  36. package/polymer/polymer-template/scripts/private/_helpers.js +113 -0
  37. package/polymer/polymer-template/scripts/private/_sanity-check-custom.js +69 -0
  38. package/polymer/polymer-template/scripts/private/_sanity-check-universal.js +120 -0
  39. package/polymer/polymer-template/scripts/private/_sanity-check.js +21 -0
  40. package/polymer/polymer-template/scripts/private/_send-packet-config.js +53 -0
  41. package/polymer/polymer-template/scripts/private/_set-contracts-config.js +50 -0
  42. package/polymer/polymer-template/scripts/private/_switch-clients.js +90 -0
  43. package/polymer/polymer-template/scripts/private/_update-vibc-address.js +52 -0
  44. package/polymer/polymer-template/scripts/private/_vibc-helpers.js +118 -0
  45. package/polymer/polymer-template/scripts/send-packet.js +38 -0
  46. package/polymer/polymer-template/scripts/send-universal-packet.js +44 -0
@@ -0,0 +1,312 @@
1
+ # ⛓️🔗⛓️ Template for IBC enabled Solidity contracts
2
+
3
+ This repo provides a starter project to build [IBC](https://github.com/cosmos/ibc) enabled Solidity contracts that connect rollups to one another Polymer Hub, through the [vIBC core contracts](https://github.com/open-ibc/vibc-core-smart-contracts).
4
+
5
+ The repository is a _GitHub template_ repository so you can click "Use this template" to create your own project repository without having the entire commit history of the template.
6
+
7
+ ![GitHub template](./img/gh_template.png)
8
+
9
+ ## 📚 Documentation
10
+
11
+ There's some basic information here in the README but a more comprehensive documentation can be found in [the official Polymer documentation](https://docs.polymerlabs.org/docs/category/build-ibc-dapps-1).
12
+
13
+ ## 📋 Prerequisites
14
+
15
+ The repo is **compatible with both Hardhat and Foundry** development environments.
16
+
17
+ - Have [git](https://git-scm.com/downloads) installed
18
+ - Have [node](https://nodejs.org) installed (v18+)
19
+ - Have [Foundry](https://book.getfoundry.sh/getting-started/installation) installed (Hardhat will be installed when running `npm install`)
20
+ - Have [just](https://just.systems/man/en/chapter_1.html) installed (recommended but not strictly necessary)
21
+
22
+ You'll need some API keys from third party's:
23
+ - [Optimism Sepolia](https://optimism-sepolia.blockscout.com/account/api-key) and [Base Sepolia](https://base-sepolia.blockscout.com/account/api-key) Blockscout Explorer API keys
24
+ - Have an [Alchemy API key](https://docs.alchemy.com/docs/alchemy-quickstart-guide) for OP and Base Sepolia
25
+
26
+ Some basic knowledge of all of these tools is also required, although the details are abstracted away for basic usage.
27
+
28
+ ## 🧰 Install dependencies
29
+
30
+ To compile your contracts and start testing, make sure that you have all dependencies installed.
31
+
32
+ From the root directory run:
33
+
34
+ ```bash
35
+ just install
36
+ ```
37
+
38
+ to install the [vIBC core smart contracts](https://github.com/open-ibc/vibc-core-smart-contracts) as a dependency.
39
+
40
+ Additionally Hardhat will be installed as a dev dependency with some useful plugins. Check `package.json` for an exhaustive list.
41
+
42
+ > Note: In case you're experiencing issues with dependencies using the `just install` recipe, check that all prerequisites are correctly installed. If issues persist with forge, try to do the individual dependency installations...
43
+
44
+ ## ⚙️ Set up your environment variables
45
+
46
+ Convert the `.env.example` file into an `.env` file. This will ignore the file for future git commits as well as expose the environment variables. Add your private keys and update the other values if you want to customize (advanced usage feature).
47
+
48
+ ```bash
49
+ cp .env.example .env
50
+ ```
51
+
52
+ This will enable you to sign transactions with your private key(s). If not added, the scripts from the justfile will fail.
53
+
54
+ ### Configuration file
55
+
56
+ The configuration file is where all important data is stored for the just commands and automation. We strive to make direct interaction with the config file as little as possible.
57
+
58
+ By default the configuration file is stored at root as `config.json`.
59
+
60
+ However, it is recommended to split up different contracts/projects in the same repo into different config file in case you want to switch between them.
61
+
62
+ Store alternate config files in the /config directory and set
63
+ ```sh
64
+ # .env file
65
+ CONFIG_PATH='config/alt-config.json'
66
+ ```
67
+ to use a different config file.
68
+
69
+ ### Obtaining testnet ETH
70
+
71
+ The account associated with your private key must have both Base Sepolia and Optimism Sepolia ETH. To obtain the testnet ETH visit:
72
+
73
+ - [Optimism Sepolia Faucet](https://www.alchemy.com/faucets/optimism-sepolia)
74
+ - [Base Sepolia Faucet](https://www.alchemy.com/faucets/base-sepolia)
75
+
76
+ ## 🏃🏽🏃🏻‍♀️ Quickstart
77
+
78
+ The project comes with a built-in dummy application called x-counter (which syncrhonizes a counter across two contracts on remote chains). You can find the contracts in the `/contracts` directory as XCounterUC.sol and XCounter.sol (the former when using the universal channel, the latter when creating a custom IBC channel).
79
+
80
+ ### Universal channels
81
+
82
+ The easiest way to get onboarded is to use Universal channels. A universal channel is an IBC channel where the port is owned by Polymer's Universal channel middleware contracts on each chain.
83
+
84
+ When a user deploys a Universal channel compatible contract (this means inheriting the [UniversalChanIbcApp](./contracts/base/UniversalChanIbcApp.sol) base contract), it will be able to connect to the Universal Channel middleware, define Universal packets which will then be wrapped into an IBC packet by the Universal Channel Handler and unwrapped by its counterpart on the destination chain (rollup). The Universal channel middleware on the destination will then unwrap the IBC packet and send the data through to you application on the destination.
85
+
86
+ Find out more about uinversal channels in the [documenation](https://docs.polymerlabs.org/docs/build/ibc-solidity/universal-channel).
87
+
88
+ The configuration file that comes as default in the template repository, allows to quickly send a packet by running:
89
+
90
+ ```sh
91
+ just send-packet base
92
+ ```
93
+
94
+ To send a packet between the XCounterUC contract on Base Sepolia to OP Sepolia and vice versa.
95
+
96
+ You can find the universal channel middleware details [in the documentation](https://docs.polymerlabs.org/docs/build/supp-networks).
97
+
98
+ Check if the packet got through on the [Polymer IBC explorer](https://sepolia.polymer.zone/packets).
99
+
100
+ ### Custom IBC channel
101
+
102
+ There's also a just recipe that quickly enables to try to send packets over a custom IBC channel. Custom IBC channel require a channel hanshake to open a private IBC channel (which can take a while depending on the client latency) but then give complete control over a private IBC channel that enables fault isolation from other applications, compared to unviersal channels.
103
+
104
+ To have your application be compatible with custom IBC channels, have it inherit the [CustomChanIbcApp](./contracts/base/CustomChanIbcApp.sol) base contract.
105
+
106
+ Run the following command to go through a full E2E sweep of the project, using the default XCounter.sol contract:
107
+
108
+ ```bash
109
+ # Usage: just do-it
110
+ just do-it
111
+ ```
112
+
113
+ It does the following under the hood:
114
+ ```bash
115
+ # Run the full E2E flow by setting the contracts, deploying them, creating a channel, and sending a packet
116
+ # Usage: just do-it
117
+ do-it:
118
+ echo "Running the full E2E flow..."
119
+ just set-contracts optimism XCounter false && just set-contracts base XCounter false
120
+ just deploy optimism base
121
+ just create-channel
122
+ just send-packet optimism
123
+ echo "You've done it!"
124
+ ```
125
+
126
+ It makes sure you've got the correct contracts set, deploys new instances, creates a channel and sends a packet over the channel once created.
127
+
128
+ > Note: by default the sim-client is used to improve latency. This is useful for iterative development and testing BUT also insecure as it involves no proofs. Make sure to move to the client **with proofs** by running another just command...
129
+
130
+ ```bash
131
+ # Usage: just switch-client
132
+ just switch-client
133
+ ```
134
+
135
+ Check if the packet got through on the [Polymer IBC explorer](https://sepolia.polymer.zone/packets).
136
+
137
+
138
+ ## 💻 Develop your custom application
139
+
140
+ The main work for you as a developer is to develop the contracts that make up your cross-chain logic.
141
+
142
+ You can use the contracts in the "/contracts/base" directory as base contracts for creating IBC enabled contracts that can either send packets over the universal channel or create their own channel to send packets over.
143
+
144
+ A complete walkthrough on how to develop these contracts is provided in the [official Polymer documentation](https://docs.polymerlabs.org/docs/build/ibc-solidity/).
145
+
146
+ ## 🕹️ Interaction with the contracts
147
+
148
+ When the contracts are ready, you can go ahead and interact with the contracts through scripts. There is a Justfile to for the most common commands, with the underlying scripts in the /scripts folder.
149
+
150
+ The `/private` folder within the scripts folder has scripts that you're unlikely to need to touch. The only scripts you'll (potentially) be interacting with are:
151
+
152
+ There's three types of default scripts in the project:
153
+
154
+ - The `deploy.js` allows you to deploy your application contract. You may want to add additional deployment logic to the Hardhat script.
155
+ - In the `/contracts` folder you'll find `arguments.js` to add your custom constructor arguments for automated deployment with the `deploy.js` script.
156
+ - The `send-packet.js` script sends packets over an existing custom channel, and `send-universal-packet.js` is specifically for sending packets over a universal channel. You might want to add additional logic before or after sending the packet to cusotmize your application.
157
+
158
+ For most of the actions above and more, there are just recipes that combine related logic and update the configuation file in an automated way.
159
+
160
+ > **Note**: These are the default scripts provided. They provide the most generic interactions with the contracts to deploy, create channels and send packets. For more complicated use cases you will want to customize the scripts to your use case. See [advanced usage](#🦾-advanced-usage) for more info.
161
+
162
+ ### Deploy
163
+
164
+ Before deploying, make sure to update the config.json with your contract type to deploy for each of the chain you wish to deploy to.
165
+
166
+ #### Set contracts to config
167
+
168
+ Do this by running:
169
+
170
+ ```bash
171
+ # Usage: just set-contracts [chain] [contract_type] [universal]
172
+ just set-contracts optimism MyContract true
173
+ ```
174
+
175
+ to deploy _MyContract_ artefact to the Optimism (Sepolia) chain.
176
+
177
+ > **IMPORTANT**: This is where you set if your contract uses universal or custom channels. Make sure this corresponds to the base contract you've inherited from when developing your application (UniversalChanIbcApp or CustomChanIbcApp).
178
+
179
+ #### Constructor arguments
180
+
181
+ By default any application inheriting a base IBC application contract will need a dispatcher or universal channel handler address passed into the constructor. Obviously you might have other constructor arguments you may want to add. To still make use of the `just deploy source destination` recipe, add your arguments to the arguments.js file
182
+
183
+ ```javascript title="/contracts/arguments.js"
184
+ module.exports = {
185
+ "XCounter": [],
186
+ "XCounterUC": [],
187
+ // Add your contract types here, along with the list of custom constructor arguments
188
+ // DO NOT ADD THE DISPATCHER OR UNIVERSAL CHANNEL HANDLER ADDRESSES HERE!!!
189
+ // These will be added in the deploy script at $ROOT/scripts/deploy.js
190
+ };
191
+ ```
192
+
193
+ #### Finally: deploy
194
+
195
+ Then run:
196
+
197
+ ```bash
198
+ # Usage: just deploy [source] [destination]
199
+ just deploy optimism base
200
+ ```
201
+
202
+ where the script will automatically detect whether you are using custom or universal IBC channels.
203
+
204
+ The script will take the output of the deployment and update the config file with all the relevant information.
205
+
206
+ Before moving on, you'll want to check if the variables in your .env and config files line up with what is stored in the actual deployed contracts... especially when you're actively playing around with different configuration files and contracts.
207
+
208
+ To do a sanity check, run:
209
+ ```bash
210
+ # Usage: just sanity-check
211
+ just sanity-check
212
+ ```
213
+
214
+ ### Create a channel
215
+
216
+ If you're **using universal channels, channel creation is not required**. Your contract will send and receive packet data from the Universal channel handler contract which already has a universal channel to send packets over. You can directly proceed to sending (universal) packets in that case.
217
+
218
+ To create a custom channel, run:
219
+
220
+ ```bash
221
+ just create-channel
222
+ ```
223
+
224
+ This creates a channel between base and optimism. Note that the **ORDER MATTERS**; if you picked optimism as the source chain (first argument) above, by default it will create the channel from optimism and vice versa.
225
+
226
+ The script will take the output of the channel creation and update the config file with all the relevant information.
227
+
228
+ Check out the [channel tab in the explorer](https://sepolia.polymer.zone/channels) to find out if the correct channel-id's related to your contracts were updated in the config.
229
+
230
+ ### Send packets
231
+
232
+ Finally Run:
233
+
234
+ ```bash
235
+ # Usage: just send-packet
236
+ just send-packet optimism
237
+ ```
238
+
239
+ to send a packet over a channel (script looks at the config's isUniversal flag to know if it should use the custom or universal packet). You can pick either optimism or base to send the packet from.
240
+
241
+ ## Verify, don't trust
242
+
243
+ As a starter value, the sim-client is used to improve latency. **The sim-client is useful for iterative development and testing BUT also insecure as it involves no proofs**. Make sure to move to the client **with proofs** by running another just command...
244
+
245
+ ```bash
246
+ # Usage: just switch-client
247
+ just switch-client
248
+ ```
249
+
250
+ This will use the op-stack client with proofs, making sure that the relayer is proving what is being submitted every step along the way, ensuring there's no trust assumption on the relayer.
251
+
252
+ An overview of the different clients can be found in `ibc.json`:
253
+ ```json
254
+ {
255
+ "optimism": {
256
+ "sim-client": {
257
+ "canonConnFrom": "connection-0",
258
+ "canonConnTo": "connection-1",
259
+ "universalChannel": "channel-10"
260
+ },
261
+ "op-client": {
262
+ "canonConnFrom": "connection-8",
263
+ "canonConnTo": "connection-9",
264
+ "universalChannel": "channel-16"
265
+ }
266
+ },
267
+ "base": {
268
+ "sim-client" : {
269
+ "canonConnFrom": "connection-4",
270
+ "canonConnTo": "connection-5",
271
+ "universalChannel": "channel-11"
272
+ },
273
+ "op-client": {
274
+ "canonConnFrom": "connection-10",
275
+ "canonConnTo": "connection-11",
276
+ "universalChannel": "channel-17"
277
+ }
278
+ }
279
+ }
280
+ ```
281
+
282
+ ## 🦾 Advanced usage
283
+
284
+ For advanced users, there's multiple custimizations to follow. These includes configuring the config.json manually and/or running the scripts without using just.
285
+
286
+ For example, the last action to send a packet on a universal channel could be executed with this command:
287
+
288
+ ```bash
289
+ npx hardhat run scripts/send-universal-packet.js --network base
290
+ ```
291
+
292
+ To send a universal packet from the contract specified in the config.sendUniversalPacket field in the config.
293
+
294
+ ## 🤝 Contributing
295
+
296
+ We welcome and encourage contributions from our community! Here’s how you can contribute.
297
+
298
+ Take a look at the open issues. If there's an issue that has the _help wanted_ label or _good first issue_, those are up for grabs. Assign yourself to the issue so people know you're working on it.
299
+
300
+ Alternatively you can open an issue for a new idea or piece of feedback.
301
+
302
+ When you want to contribute code, please follow these steps:
303
+
304
+ 1. **Fork the Repository:** Start by forking this repository.
305
+ 2. **Apply the improvements:** Want to optimize something or add support for additional developer tooling? Add your changes!
306
+ 3. **Create a Pull Request:** Once you're ready and have tested your added code, submit a PR to the repo and we'll review as soon as possible.
307
+
308
+ ## 💡 Questions or Suggestions?
309
+
310
+ Feel free to open an issue for questions, suggestions, or discussions related to this repository. For further discussion as well as a showcase of some community projects, check out the [Polymer developer forum](https://forum.polymerlabs.org).
311
+
312
+ Thank you for being a part of our community!
@@ -0,0 +1,42 @@
1
+ {
2
+ "proofsEnabled": false,
3
+ "deploy": {
4
+ "optimism": "XCounterUC",
5
+ "base": "XCounterUC"
6
+ },
7
+ "isUniversal": true,
8
+ "createChannel": {
9
+ "srcChain": "optimism",
10
+ "srcAddr": "0x1234567890AbCdEf1234567890aBcDeF12345678",
11
+ "dstChain": "base",
12
+ "dstAddr": "0x1234567890AbCdEf1234567890aBcDeF12345678",
13
+ "version": "1.0",
14
+ "ordering": 0,
15
+ "fees": false
16
+ },
17
+ "sendPacket": {
18
+ "optimism": {
19
+ "portAddr": "0x1234567890abcdef1234567890abcdef12345678",
20
+ "channelId": "channel-n",
21
+ "timeout": 36000
22
+ },
23
+ "base": {
24
+ "portAddr": "0x1234567890abcdef1234567890abcdef12345678",
25
+ "channelId": "channel-n",
26
+ "timeout": 36000
27
+ }
28
+ },
29
+ "sendUniversalPacket": {
30
+ "optimism": {
31
+ "portAddr": "0x1234567890abcdef1234567890abcdef12345678",
32
+ "channelId": "channel-x",
33
+ "timeout": 36000
34
+ },
35
+ "base": {
36
+ "portAddr": "0x1234567890abcdef1234567890abcdef12345678",
37
+ "channelId": "channel-y",
38
+ "timeout": 36000
39
+ }
40
+ },
41
+ "backup": {}
42
+ }
@@ -0,0 +1,42 @@
1
+ {
2
+ "proofsEnabled": false,
3
+ "deploy": {
4
+ "optimism": "XCounter",
5
+ "base": "XCounter"
6
+ },
7
+ "isUniversal": false,
8
+ "createChannel": {
9
+ "srcChain": "optimism",
10
+ "srcAddr": "0x9a5fDA8E49bcd1Ada645c06273A496D9A2397C9e",
11
+ "dstChain": "base",
12
+ "dstAddr": "0x9a5fDA8E49bcd1Ada645c06273A496D9A2397C9e",
13
+ "version": "1.0",
14
+ "ordering": 0,
15
+ "fees": false
16
+ },
17
+ "sendPacket": {
18
+ "optimism": {
19
+ "portAddr": "0x9a5fDA8E49bcd1Ada645c06273A496D9A2397C9e",
20
+ "channelId": "channel-19292",
21
+ "timeout": 36000
22
+ },
23
+ "base": {
24
+ "portAddr": "0x9a5fDA8E49bcd1Ada645c06273A496D9A2397C9e",
25
+ "channelId": "channel-19293",
26
+ "timeout": 36000
27
+ }
28
+ },
29
+ "sendUniversalPacket": {
30
+ "optimism": {
31
+ "portAddr": "0x1234567890abcdef1234567890abcdef12345678",
32
+ "channelId": "channel-x",
33
+ "timeout": 36000
34
+ },
35
+ "base": {
36
+ "portAddr": "0x1234567890abcdef1234567890abcdef12345678",
37
+ "channelId": "channel-y",
38
+ "timeout": 36000
39
+ }
40
+ },
41
+ "backup": {}
42
+ }
@@ -0,0 +1,89 @@
1
+ //SPDX-License-Identifier: UNLICENSED
2
+
3
+ pragma solidity ^0.8.9;
4
+
5
+ import './base/CustomChanIbcApp.sol';
6
+
7
+ contract XCounter is CustomChanIbcApp {
8
+ // app specific state
9
+ uint64 public counter;
10
+ mapping (uint64 => address) public counterMap;
11
+
12
+
13
+ constructor(IbcDispatcher _dispatcher) CustomChanIbcApp(_dispatcher) {}
14
+
15
+ // app specific logic
16
+ function resetCounter() internal {
17
+ counter = 0;
18
+ }
19
+
20
+ function increment() internal {
21
+ counter++;
22
+ }
23
+
24
+ // IBC logic
25
+
26
+ /**
27
+ * @dev Sends a packet with the caller address over a specified channel.
28
+ * @param channelId The ID of the channel (locally) to send the packet to.
29
+ * @param timeoutSeconds The timeout in seconds (relative).
30
+ */
31
+
32
+ function sendPacket( bytes32 channelId, uint64 timeoutSeconds) external {
33
+ // incrementing counter on source chain
34
+ increment();
35
+
36
+ // encoding the caller address to update counterMap on destination chain
37
+ bytes memory payload = abi.encode(msg.sender);
38
+
39
+ // setting the timeout timestamp at 10h from now
40
+ uint64 timeoutTimestamp = uint64((block.timestamp + timeoutSeconds) * 1000000000);
41
+
42
+ // calling the Dispatcher to send the packet
43
+ dispatcher.sendPacket(channelId, payload, timeoutTimestamp);
44
+ }
45
+
46
+ /**
47
+ * @dev Packet lifecycle callback that implements packet receipt logic and returns and acknowledgement packet.
48
+ * MUST be overriden by the inheriting contract.
49
+ *
50
+ * @param packet the IBC packet encoded by the source and relayed by the relayer.
51
+ */
52
+ function onRecvPacket(IbcPacket memory packet) external override onlyIbcDispatcher returns (AckPacket memory ackPacket) {
53
+ recvedPackets.push(packet);
54
+ address _caller = abi.decode(packet.data, (address));
55
+ counterMap[packet.sequence] = _caller;
56
+
57
+ increment();
58
+
59
+ return AckPacket(true, abi.encode(counter));
60
+ }
61
+
62
+ /**
63
+ * @dev Packet lifecycle callback that implements packet acknowledgment logic.
64
+ * MUST be overriden by the inheriting contract.
65
+ *
66
+ * @param ack the acknowledgment packet encoded by the destination and relayed by the relayer.
67
+ */
68
+ function onAcknowledgementPacket(IbcPacket calldata, AckPacket calldata ack) external override onlyIbcDispatcher {
69
+ ackPackets.push(ack);
70
+
71
+ (uint64 _counter) = abi.decode(ack.data, (uint64));
72
+
73
+ if (_counter != counter) {
74
+ resetCounter();
75
+ }
76
+ }
77
+
78
+ /**
79
+ * @dev Packet lifecycle callback that implements packet receipt logic and return and acknowledgement packet.
80
+ * MUST be overriden by the inheriting contract.
81
+ * NOT SUPPORTED YET
82
+ *
83
+ * @param packet the IBC packet encoded by the counterparty and relayed by the relayer
84
+ */
85
+ function onTimeoutPacket(IbcPacket calldata packet) external override onlyIbcDispatcher {
86
+ timeoutPackets.push(packet);
87
+ // do logic
88
+ }
89
+ }
@@ -0,0 +1,100 @@
1
+ //SPDX-License-Identifier: UNLICENSED
2
+
3
+ pragma solidity ^0.8.9;
4
+
5
+ import "./base/UniversalChanIbcApp.sol";
6
+
7
+ contract XCounterUC is UniversalChanIbcApp {
8
+ // application specific state
9
+ uint64 public counter;
10
+ mapping(uint64 => address) public counterMap;
11
+
12
+ constructor(address _middleware) UniversalChanIbcApp(_middleware) {}
13
+
14
+ // application specific logic
15
+ function resetCounter() internal {
16
+ counter = 0;
17
+ }
18
+
19
+ function increment() internal {
20
+ counter++;
21
+ }
22
+
23
+ // IBC logic
24
+
25
+ /**
26
+ * @dev Sends a packet with the caller's address over the universal channel.
27
+ * @param destPortAddr The address of the destination application.
28
+ * @param channelId The ID of the channel to send the packet to.
29
+ * @param timeoutSeconds The timeout in seconds (relative).
30
+ */
31
+ function sendUniversalPacket(address destPortAddr, bytes32 channelId, uint64 timeoutSeconds) external {
32
+ increment();
33
+ bytes memory payload = abi.encode(msg.sender, counter);
34
+
35
+ uint64 timeoutTimestamp = uint64((block.timestamp + timeoutSeconds) * 1000000000);
36
+
37
+ IbcUniversalPacketSender(mw).sendUniversalPacket(
38
+ channelId, IbcUtils.toBytes32(destPortAddr), payload, timeoutTimestamp
39
+ );
40
+ }
41
+
42
+ /**
43
+ * @dev Packet lifecycle callback that implements packet receipt logic and returns and acknowledgement packet.
44
+ * MUST be overriden by the inheriting contract.
45
+ *
46
+ * @param channelId the ID of the channel (locally) the packet was received on.
47
+ * @param packet the Universal packet encoded by the source and relayed by the relayer.
48
+ */
49
+ function onRecvUniversalPacket(bytes32 channelId, UniversalPacket calldata packet)
50
+ external
51
+ override
52
+ onlyIbcMw
53
+ returns (AckPacket memory ackPacket)
54
+ {
55
+ recvedPackets.push(UcPacketWithChannel(channelId, packet));
56
+
57
+ (address payload, uint64 c) = abi.decode(packet.appData, (address, uint64));
58
+ counterMap[c] = payload;
59
+
60
+ increment();
61
+
62
+ return AckPacket(true, abi.encode(counter));
63
+ }
64
+
65
+ /**
66
+ * @dev Packet lifecycle callback that implements packet acknowledgment logic.
67
+ * MUST be overriden by the inheriting contract.
68
+ *
69
+ * @param channelId the ID of the channel (locally) the ack was received on.
70
+ * @param packet the Universal packet encoded by the source and relayed by the relayer.
71
+ * @param ack the acknowledgment packet encoded by the destination and relayed by the relayer.
72
+ */
73
+ function onUniversalAcknowledgement(bytes32 channelId, UniversalPacket memory packet, AckPacket calldata ack)
74
+ external
75
+ override
76
+ onlyIbcMw
77
+ {
78
+ ackPackets.push(UcAckWithChannel(channelId, packet, ack));
79
+
80
+ // decode the counter from the ack packet
81
+ (uint64 _counter) = abi.decode(ack.data, (uint64));
82
+
83
+ if (_counter != counter) {
84
+ resetCounter();
85
+ }
86
+ }
87
+
88
+ /**
89
+ * @dev Packet lifecycle callback that implements packet receipt logic and return and acknowledgement packet.
90
+ * MUST be overriden by the inheriting contract.
91
+ * NOT SUPPORTED YET
92
+ *
93
+ * @param channelId the ID of the channel (locally) the timeout was submitted on.
94
+ * @param packet the Universal packet encoded by the counterparty and relayed by the relayer
95
+ */
96
+ function onTimeoutUniversalPacket(bytes32 channelId, UniversalPacket calldata packet) external override onlyIbcMw {
97
+ timeoutPackets.push(UcPacketWithChannel(channelId, packet));
98
+ // do logic
99
+ }
100
+ }
@@ -0,0 +1,7 @@
1
+ module.exports = {
2
+ "XCounter": [],
3
+ "XCounterUC": [],
4
+ // Add your contract types here, along with the list of custom constructor arguments
5
+ // DO NOT ADD THE DISPATCHER OR UNIVERSAL CHANNEL HANDLER ADDRESSES HERE!!!
6
+ // These will be added in the deploy script at $ROOT/scripts/deploy.js
7
+ };