forked from dapplingnetwork/gogopool-observer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae20f79
commit 0a15099
Showing
5 changed files
with
262 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
177 changes: 177 additions & 0 deletions
177
src/actions-local/payload/payload-artifact-rented-batch.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
{ | ||
"network": "43113", | ||
"blockHash": "0x5abebf587496f64d5fc7ddf3f48d958e0faeb990670a392390c42a4330a09375", | ||
"blockNumber": 37128793, | ||
"hash": "0x0f8b6cbad6e26c3ae9d5ee0a8526719ca3a72096a8bd9665a7a5da0161e99753", | ||
"from": "0x8640577C7e9C906C6b1CdCeF532f030F21D2381A", | ||
"to": "0x9D2498375B7b1EB6262B421935B948C6adBe24e1", | ||
"logs": [ | ||
{ | ||
"address": "0xd00ae08403B9bbb9124bB305C09058E32C39A48c", | ||
"topics": [ | ||
"0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c", | ||
"0x000000000000000000000000b4315e873dbcf96ffd0acd8ea43f689d8c20fb30" | ||
], | ||
"data": "0x000000000000000000000000000000000000000000000000002386f26fc10000" | ||
}, | ||
{ | ||
"address": "0xd00ae08403B9bbb9124bB305C09058E32C39A48c", | ||
"topics": [ | ||
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", | ||
"0x000000000000000000000000b4315e873dbcf96ffd0acd8ea43f689d8c20fb30", | ||
"0x0000000000000000000000006fc0ae8f34b011d81fa3f89a3d877e5d7c7f9fb5" | ||
], | ||
"data": "0x000000000000000000000000000000000000000000000000002386f26fc10000" | ||
}, | ||
{ | ||
"address": "0xACdDAEfab64c8038ED294BAA45183Cf4d6454dF7", | ||
"topics": [ | ||
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", | ||
"0x0000000000000000000000006fc0ae8f34b011d81fa3f89a3d877e5d7c7f9fb5", | ||
"0x0000000000000000000000009d2498375b7b1eb6262b421935b948c6adbe24e1" | ||
], | ||
"data": "0x0000000000000000000000000000000000000000000000000000208630cdc4bd" | ||
}, | ||
{ | ||
"address": "0x6fc0aE8F34B011D81Fa3F89a3D877e5d7c7F9fb5", | ||
"topics": [ | ||
"0x1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1" | ||
], | ||
"data": "0x0000000000000000000000000000000000000000000000000ae3c30f5a6284fe00000000000000000000000000000000000000000000000bdc28b7df0296caa9" | ||
}, | ||
{ | ||
"address": "0x6fc0aE8F34B011D81Fa3F89a3D877e5d7c7F9fb5", | ||
"topics": [ | ||
"0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822", | ||
"0x000000000000000000000000b4315e873dbcf96ffd0acd8ea43f689d8c20fb30", | ||
"0x0000000000000000000000009d2498375b7b1eb6262b421935b948c6adbe24e1" | ||
], | ||
"data": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002386f26fc100000000000000000000000000000000000000000000000000000000208630cdc4bd0000000000000000000000000000000000000000000000000000000000000000" | ||
}, | ||
{ | ||
"address": "0xACdDAEfab64c8038ED294BAA45183Cf4d6454dF7", | ||
"topics": [ | ||
"0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925", | ||
"0x0000000000000000000000009d2498375b7b1eb6262b421935b948c6adbe24e1", | ||
"0x000000000000000000000000823de3b24c6461aa91234cfb42c571def8035b9b" | ||
], | ||
"data": "0x0000000000000000000000000000000000000000000000000000208630cdc4bd" | ||
}, | ||
{ | ||
"address": "0xACdDAEfab64c8038ED294BAA45183Cf4d6454dF7", | ||
"topics": [ | ||
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", | ||
"0x0000000000000000000000009d2498375b7b1eb6262b421935b948c6adbe24e1", | ||
"0x000000000000000000000000823de3b24c6461aa91234cfb42c571def8035b9b" | ||
], | ||
"data": "0x0000000000000000000000000000000000000000000000000000208630cdc4bd" | ||
}, | ||
{ | ||
"address": "0x823de3b24C6461aA91234cFb42C571dEf8035B9b", | ||
"topics": [ | ||
"0x3cd32fbc628a7c1c5a309e823125e5a4b8d98b9b31ad71d8338cc5f05829b199", | ||
"0x0000000000000000000000008640577c7e9c906c6b1cdcef532f030f21d2381a" | ||
], | ||
"data": "0x0000000000000000000000000000000000000000000000000000208630cdc4bd" | ||
}, | ||
{ | ||
"address": "0xACdDAEfab64c8038ED294BAA45183Cf4d6454dF7", | ||
"topics": [ | ||
"0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925", | ||
"0x000000000000000000000000823de3b24c6461aa91234cfb42c571def8035b9b", | ||
"0x000000000000000000000000aaa95d2e271a8293fc16e339080db83c9beb6fcf" | ||
], | ||
"data": "0x0000000000000000000000000000000000000000000000000000208630cdc4bd" | ||
}, | ||
{ | ||
"address": "0xaaA95D2E271a8293FC16E339080DB83C9bEB6Fcf", | ||
"topics": [ | ||
"0xc4c24354aa86aa3532ebd9da7ff92230de931c78c77fcdf84544f11bf8fae753", | ||
"0xb6e5041d5be52fb06762b7cdbdbe290c545b1c43853437eaa90e372a86bf8ecc", | ||
"0x000000000000000000000000acddaefab64c8038ed294baa45183cf4d6454df7" | ||
], | ||
"data": "0x0000000000000000000000000000000000000000000000000000208630cdc4bd" | ||
}, | ||
{ | ||
"address": "0xACdDAEfab64c8038ED294BAA45183Cf4d6454dF7", | ||
"topics": [ | ||
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", | ||
"0x000000000000000000000000823de3b24c6461aa91234cfb42c571def8035b9b", | ||
"0x000000000000000000000000aaa95d2e271a8293fc16e339080db83c9beb6fcf" | ||
], | ||
"data": "0x0000000000000000000000000000000000000000000000000000208630cdc4bd" | ||
}, | ||
{ | ||
"address": "0xd68922cB57Ff95F705405553A92aaD8746A55F88", | ||
"topics": [ | ||
"0x081f7fc11ad5b45c96f3e5bb7fababfc251f5fe0b0bda6490b198686a876e5c3" | ||
], | ||
"data": "0x0000000000000000000000008640577c7e9c906c6b1cdcef532f030f21d2381a00000000000000000000000001c87267d454d93311ed682a85d35175bcb62b5c9e8a01bb951fb38ff9aa0ddecfcda59c7d92b7e1569928f14e6d7bd3cce2f8600000000000000000000000000000000000000000000000000000000000015f90000000000000000000000000000000000000000000000000002386f26fc10000" | ||
}, | ||
{ | ||
"address": "0x9779eF3E309337A5F1043878886e5de1cdA4B6EB", | ||
"topics": [ | ||
"0xc9c043637725967252aedd2704cc65fee962e7b8a1e3cf8098587a66601e50c5", | ||
"0x00000000000000000000000001c87267d454d93311ed682a85d35175bcb62b5c", | ||
"0x0000000000000000000000000000000000000000000000000000000000000000" | ||
], | ||
"data": "0x" | ||
}, | ||
{ | ||
"address": "0xaaA95D2E271a8293FC16E339080DB83C9bEB6Fcf", | ||
"topics": [ | ||
"0xd4502e0d4f9dc8fb9302d686a2b2bff55a6ed89cc5549f55b64490dff5d3e559", | ||
"0xdc9f46fd71d4bf9bb05b835608e68c9394b627d9f45ac7ee85b2772e827e321e" | ||
], | ||
"data": "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000" | ||
}, | ||
{ | ||
"address": "0x9D2498375B7b1EB6262B421935B948C6adBe24e1", | ||
"topics": [ | ||
"0xaf1005964e27ad5f17fe27fe24bb7248ecff702f011c192a9493e34b29854fca" | ||
], | ||
"data": "0x00000000000000000000000001c87267d454d93311ed682a85d35175bcb62b5c0000000000000000000000008640577c7e9c906c6b1cdcef532f030f21d2381a9e8a01bb951fb38ff9aa0ddecfcda59c7d92b7e1569928f14e6d7bd3cce2f860000000000000000000000000000000000000000000000000002386f26fc100000000000000000000000000000000000000000000000000000000000000015f90" | ||
}, | ||
{ | ||
"address": "0xd68922cB57Ff95F705405553A92aaD8746A55F88", | ||
"topics": [ | ||
"0x081f7fc11ad5b45c96f3e5bb7fababfc251f5fe0b0bda6490b198686a876e5c3" | ||
], | ||
"data": "0x0000000000000000000000008640577c7e9c906c6b1cdcef532f030f21d2381a0000000000000000000000006c0d835bb8c4fba891c5d22258b7cc7c11d539f69e8a01bb951fb38ff9aa0ddecfcda59c7d92b7e1569928f14e6d7bd3cce2f8600000000000000000000000000000000000000000000000000000000000015f90000000000000000000000000000000000000000000000000002386f26fc10000" | ||
}, | ||
{ | ||
"address": "0x9779eF3E309337A5F1043878886e5de1cdA4B6EB", | ||
"topics": [ | ||
"0xc9c043637725967252aedd2704cc65fee962e7b8a1e3cf8098587a66601e50c5", | ||
"0x0000000000000000000000006c0d835bb8c4fba891c5d22258b7cc7c11d539f6", | ||
"0x0000000000000000000000000000000000000000000000000000000000000000" | ||
], | ||
"data": "0x" | ||
}, | ||
{ | ||
"address": "0xaaA95D2E271a8293FC16E339080DB83C9bEB6Fcf", | ||
"topics": [ | ||
"0xd4502e0d4f9dc8fb9302d686a2b2bff55a6ed89cc5549f55b64490dff5d3e559", | ||
"0xdc9f46fd71d4bf9bb05b835608e68c9394b627d9f45ac7ee85b2772e827e321e" | ||
], | ||
"data": "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000" | ||
}, | ||
{ | ||
"address": "0x9D2498375B7b1EB6262B421935B948C6adBe24e1", | ||
"topics": [ | ||
"0xaf1005964e27ad5f17fe27fe24bb7248ecff702f011c192a9493e34b29854fca" | ||
], | ||
"data": "0x0000000000000000000000006c0d835bb8c4fba891c5d22258b7cc7c11d539f60000000000000000000000008640577c7e9c906c6b1cdcef532f030f21d2381a9e8a01bb951fb38ff9aa0ddecfcda59c7d92b7e1569928f14e6d7bd3cce2f860000000000000000000000000000000000000000000000000002386f26fc100000000000000000000000000000000000000000000000000000000000000015f90" | ||
} | ||
], | ||
"input": "0x088ec131000000000000000000000000000000000000000000000000002386f26fc1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000024000000000000000000000000001c87267d454d93311ed682a85d35175bcb62b5c00000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000015f900000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000002386f26fc100009e8a01bb951fb38ff9aa0ddecfcda59c7d92b7e1569928f14e6d7bd3cce2f8600000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000308f7cb43a9802e917bd7bdc49f128f20d7c13365bf77465ac628990d55f1753857c790c5d5224d1afc68b2cda1fef43f2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060a0f185c56cca4b67deeb9d0ed46e60b3c5b75b425f8694bfb21dcd50bbdb01b117c105d7ae41b6b95694bb058fd2343c0d5e150406255e5fa523065a8c99c92136f10900626a8f585608033cccbefb156d945799a9289f5019fae9e5aa828c050000000000000000000000006c0d835bb8c4fba891c5d22258b7cc7c11d539f600000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000015f900000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000002386f26fc100009e8a01bb951fb38ff9aa0ddecfcda59c7d92b7e1569928f14e6d7bd3cce2f8600000000000000000000000000000000000000000000000000000000000000120000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000308d64c33d137c4ad6e841757b3d369fc9a0c760778d9e40d930ec259e046214d98399274e4dc407c678725727937f2a0c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006088e94f38fda64ba89c2b8ff927d0c6f20ee95893ac6c6b2ef271b2e61169b5eff9e8bdb5275ba477ba81a660ea7aa616077e9042bf7a0fed2a8e9f0dfd396e333b4bdda1577c66deaeac30b123e1df36b32fa231ec54724ff5b3d9733806a781", | ||
"value": "0x1c2c023e9e0b0000", | ||
"nonce": "0x215", | ||
"gas": "0x19dd13", | ||
"gasUsed": "0x193a1d", | ||
"cumulativeGasUsed": "0x193a1d", | ||
"gasPrice": "0x3b9aca01", | ||
"gasTipCap": "0x3b9aca01", | ||
"gasFeeCap": "0x3b9aca01", | ||
"alertId": null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,62 @@ | ||
import { Context, Event, Network, TransactionEvent } from "@tenderly/actions"; | ||
import { emitter } from "./emitter"; | ||
import { getHardwareRentedEvent } from "./logParsing"; | ||
import { getHardwareRentedEvents } from "./logParsing"; | ||
import { HardwareRented } from "./types"; | ||
import { initServices, nodeHexToID } from "./utils"; | ||
import { SLACK_HARDWARE_RENTED_TEMPLATE } from "./templates"; | ||
import { formatEther } from "ethers/lib/utils"; | ||
|
||
const handleHardwareRentedEvent = async ( | ||
const handleHardwareRentedEvents = async ( | ||
transactionEvent: TransactionEvent, | ||
hardwareRentedEvent: HardwareRented, | ||
hardwareRentedEvents: HardwareRented[], | ||
network?: Network | ||
) => { | ||
const { user, nodeID, hardwareProviderName, duration, payment } = | ||
hardwareRentedEvent; | ||
// Group events by user to consolidate messages | ||
const eventsByUser = hardwareRentedEvents.reduce((acc, event) => { | ||
const { user } = event; | ||
if (!acc[user]) acc[user] = []; | ||
acc[user].push(event); | ||
return acc; | ||
}, {} as Record<string, HardwareRented[]>); | ||
|
||
const slackMessage = await SLACK_HARDWARE_RENTED_TEMPLATE({ | ||
transactionHash: transactionEvent.hash, | ||
user, | ||
nodeID: nodeHexToID(nodeID), | ||
hardwareProviderName, | ||
duration: duration.toString(), | ||
payment: formatEther(payment), | ||
}); | ||
console.info("Slack message prepared for hardware rented"); | ||
const workflowData = { | ||
...slackMessage, | ||
user, | ||
nodeID: nodeHexToID(nodeID), | ||
nodeIDHex: nodeID.toString(), | ||
hardwareProviderName, | ||
duration: duration.toString(), | ||
payment: payment.toString(), | ||
}; | ||
await emitter.emit(undefined, workflowData, undefined, network); | ||
// Send one message per user with all their rented nodes | ||
for (const [user, events] of Object.entries(eventsByUser)) { | ||
const nodeIDs = events.map(event => nodeHexToID(event.nodeID)); | ||
const totalPayment = events.reduce((sum, event) => sum + BigInt(event.payment.toString()), BigInt(0)); | ||
const duration = events[0].duration; // Assuming same duration for batch rentals | ||
|
||
const slackMessage = await SLACK_HARDWARE_RENTED_TEMPLATE({ | ||
transactionHash: transactionEvent.hash, | ||
user, | ||
nodeIDs, | ||
hardwareProviderName: events[0].hardwareProviderName, | ||
duration: duration.toString(), | ||
payment: formatEther(totalPayment), | ||
}); | ||
|
||
console.info("Slack message prepared for hardware rented"); | ||
const workflowData = { | ||
...slackMessage, | ||
user, | ||
nodeIDs, | ||
nodeIDsHex: events.map(event => event.nodeID.toString()), | ||
hardwareProviderName: events[0].hardwareProviderName, | ||
duration: duration.toString(), | ||
payment: totalPayment.toString(), | ||
}; | ||
await emitter.emit(undefined, workflowData, undefined, network); | ||
} | ||
}; | ||
|
||
export const hardwareRented = async (context: Context, event: Event) => { | ||
await initServices(context); | ||
const transactionEvent = event as TransactionEvent; | ||
const network = context.metadata.getNetwork() | ||
const network = context.metadata.getNetwork(); | ||
|
||
const hardwareRentedEvent = await getHardwareRentedEvent(transactionEvent); | ||
if (hardwareRentedEvent) { | ||
await handleHardwareRentedEvent(transactionEvent, hardwareRentedEvent, network); | ||
const hardwareRentedEvents = await getHardwareRentedEvents(transactionEvent); | ||
if (hardwareRentedEvents.length > 0) { | ||
await handleHardwareRentedEvents(transactionEvent, hardwareRentedEvents, network); | ||
} else { | ||
throw new Error("No Withdraw or Deposit event found"); | ||
throw new Error("No HardwareRented events found"); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters