2022-02-22 08:25:42 +00:00
|
|
|
const { ethers } = require("hardhat")
|
|
|
|
const { keccak256, defaultAbiCoder } = ethers.utils
|
|
|
|
|
|
|
|
function requestId(request) {
|
2023-03-08 11:02:34 +00:00
|
|
|
const Ask = "tuple(int64, uint256, uint256, uint256, uint256, uint256, int64)"
|
2023-10-18 14:27:42 +00:00
|
|
|
const Content = "tuple(string, bytes)"
|
2022-04-06 12:26:56 +00:00
|
|
|
const Request =
|
|
|
|
"tuple(address, " + Ask + ", " + Content + ", uint256, bytes32)"
|
|
|
|
return keccak256(defaultAbiCoder.encode([Request], requestToArray(request)))
|
2022-02-22 08:25:42 +00:00
|
|
|
}
|
|
|
|
|
2022-04-06 12:26:56 +00:00
|
|
|
function askToArray(ask) {
|
2022-08-02 09:41:49 +00:00
|
|
|
return [
|
|
|
|
ask.slots,
|
|
|
|
ask.slotSize,
|
|
|
|
ask.duration,
|
|
|
|
ask.proofProbability,
|
|
|
|
ask.reward,
|
2023-03-08 11:02:34 +00:00
|
|
|
ask.collateral,
|
2022-08-24 05:30:55 +00:00
|
|
|
ask.maxSlotLoss,
|
2022-08-02 09:41:49 +00:00
|
|
|
]
|
2022-04-06 12:26:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function contentToArray(content) {
|
2023-10-18 14:27:42 +00:00
|
|
|
return [content.cid, content.merkleRoot]
|
2022-04-06 12:26:56 +00:00
|
|
|
}
|
|
|
|
|
2022-02-22 08:25:42 +00:00
|
|
|
function requestToArray(request) {
|
|
|
|
return [
|
2022-04-06 12:26:56 +00:00
|
|
|
[
|
|
|
|
request.client,
|
|
|
|
askToArray(request.ask),
|
|
|
|
contentToArray(request.content),
|
|
|
|
request.expiry,
|
|
|
|
request.nonce,
|
|
|
|
],
|
2022-02-22 08:25:42 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2022-07-19 09:33:54 +00:00
|
|
|
function slotId(slot) {
|
|
|
|
const types = "tuple(bytes32, uint256)"
|
|
|
|
const values = [slot.request, slot.index]
|
|
|
|
const encoding = defaultAbiCoder.encode([types], [values])
|
|
|
|
return keccak256(encoding)
|
|
|
|
}
|
|
|
|
|
2022-04-06 12:26:56 +00:00
|
|
|
module.exports = {
|
|
|
|
requestId,
|
2022-07-19 09:33:54 +00:00
|
|
|
slotId,
|
2022-04-06 12:26:56 +00:00
|
|
|
requestToArray,
|
|
|
|
askToArray,
|
|
|
|
}
|