zeta-chain / toolkit

A library of ZetaChain helper utilities, contracts, and Hardhat tasks for smart-contract development
MIT License
42 stars 21 forks source link

Refactor the CCTX tracking functionality #167

Open fadeev opened 2 months ago

fadeev commented 2 months ago

Background

Currently, the trackCCTX function queries the /zeta-chain/crosschain/inTxHashToCctx/${hash} to convert an inbound (connected chain) hash into a cross-chain tx hash.

https://github.com/zeta-chain/toolkit/blob/f0bf8b19b2b1f7686fbc44982f821640e416f7a1/packages/client/src/trackCCTX.ts#L35

Then, the function queries the API by CCTX hash to get CCTX data:

https://github.com/zeta-chain/toolkit/blob/f0bf8b19b2b1f7686fbc44982f821640e416f7a1/packages/client/src/trackCCTX.ts#L115

This is no longer needed, as there is an API endpoint that converts an inbound hash directly to CCTX data:

https://zetachain-athens.blockpi.network/lcd/v1/public/zeta-chain/crosschain/inboundHashToCctxData/0xce8832232639d29d40078e14d0a5b20c055123d6df1e1d39f90cfd130c33466d

Task

### Tasks
- [ ] Refactor `trackCCTX` so that it no longer uses `/inTxHashToCctx` and uses `/cctx`, instead
- [ ] Add tests to the function
- [ ] Make sure that this refactor doesn't break the event emitting API. If it does, document the changes
- [ ] Make any additional changes you think are necessary to simplify the logic

Feel free to use these hashes for testing purposes:

npx hardhat cctx 0xce8832232639d29d40078e14d0a5b20c055123d6df1e1d39f90cfd130c33466d

✓ CCTXs on ZetaChain found.
✓ 0x1ae1436358ef755c1c782d0a249ae99e857b0aecb91dcd8da4a4e7171f5d9459: 11155111 → 7001: OutboundMined (Remote omnichain contract call completed)
✓ 0xbefe99d3e17d16fc88762f85b1becd1396b01956c04b5ec037abc2c63d821caa: 7001 → 97: OutboundMined (ZRC20 withdrawal event setting to pending outbound directly : Outbound succeeded, mined)
npx hardhat cctx 0xf6895678629b99d756c8d4378d4d3e57e495c95edd39b2ab51cbd707bff75d59

✓ CCTXs on ZetaChain found.
✓ 0x83dc34b68d36fbafb7a9c7eef51f3a19a5b842a39f1364f53091a236266d4ff1: 97 → 7001: OutboundMined (Remote omnichain contract call completed)
✓ 0x25494fd66075c98a1ef1d13723fb0ca9029377580cf1c2847d0b786896d850cb: 7001 → 11155111: PendingOutbound  → OutboundMined
✓ 0xacc9d061b051c48b79b1dfec9e2ed3b7679af7ac225e8c995fab77b96d437bcc: 7001 → 18332: PendingOutbound  → OutboundMined
mikelord007 commented 1 month ago

I can take this