Arnaud dee3d7b654
feat: move to hardhat ignition for deployments (#231)
* Move to ethers 6 and use hardhat ignition for deployments

* Update prettier to the last version

* Remove comment

* Remove npx call in package.json

* Remove useless comment

* Add localhost configuration for hardhat ignition

* Use contract initial balance instead of const value

* Update dependencies and use extract mining to a script in order to use hardhat ignition deploy command

* Fix deployment modules for local env

* Remove unused function

* Export contract deployment custom error assert into a function

* Refactoring

* Remove old deployments folder

* Add process names when running concurrently

* Remove conditional allowBlocksWithSameTimestamp, set true everytime

* Update dependencies

* Update Vault tests for ignition

* Update token description

* Add vault ignition module

* Remove old .tool-versions

* Fix formatting

* Remove deployments folder and add README for previous files references

* Put back the comment related to hardhat automine

* Set hardhat gas limit to auto and restore manual mining for Vault tests

* Apply prettier formatting and bug test with ignition syntax

* Add deployments artifacts

* Fix build-info ignore

* Use HARDHAT_NETWORK env variable to deploy marketplace contract

* Add guard to check that configs has tags

* Add testnet deployment addresses

* Add TOKEN_ADDRESS to reuse the token contract deployed

* Fix token deployment with contractAt

* Remove localhost deployment artifacts

* Add section in README for deployments

* Ignore localhost deployments in git

* Set mine script for localhost deployment only and add deploy reset command

* Remove previous deployment scripts

* Fix typo in documentation

* Add log when reusing token address

* Update testnet artifact reference

* Remove HARDHAT_NETWORK and update documentation

* fix md format

* Npm audit fix

* Update dependencies

* Remove default deployer

* Update commit for last testnet artifacts

* Remove deployments files from linea and testnet and update the last commit hashes to those artifacts
2025-06-20 16:05:57 +02:00

114 lines
3.4 KiB
JavaScript

const { advanceTimeTo, currentTime } = require("./evm")
const { slotId, requestId } = require("./ids")
const { payoutForDuration } = require("./price")
const { collateralPerSlot } = require("./collateral")
async function waitUntilCancelled(contract, request) {
const expiry = await contract.requestExpiry(requestId(request))
// We do +1, because the expiry check in contract is done as `>` and not `>=`.
return advanceTimeTo(expiry + 1n)
}
async function waitUntilSlotsFilled(contract, request, proof, token, slots) {
let collateral = collateralPerSlot(request)
await token.approve(await contract.getAddress(), collateral * slots.length)
let requestEnd = await contract.requestEnd(requestId(request))
const payouts = []
for (let slotIndex of slots) {
await contract.reserveSlot(requestId(request), slotIndex)
await contract.fillSlot(requestId(request), slotIndex, proof)
payouts[slotIndex] = payoutForDuration(
request,
await currentTime(),
requestEnd,
)
}
return payouts
}
async function waitUntilStarted(contract, request, proof, token) {
return waitUntilSlotsFilled(
contract,
request,
proof,
token,
Array.from({ length: request.ask.slots }, (_, i) => i),
)
}
async function waitUntilFinished(contract, requestId) {
const end = await contract.requestEnd(requestId)
// We do +1, because the end check in contract is done as `>` and not `>=`.
await advanceTimeTo(end + 1n)
}
async function waitUntilFailed(contract, request) {
slot = { request: requestId(request), slot: 0 }
for (let i = 0; i <= request.ask.maxSlotLoss; i++) {
slot.index = i
let id = slotId(slot)
await contract.forciblyFreeSlot(id)
}
}
async function waitUntilSlotFailed(contract, request, slot) {
let index = 0
let freed = 0
while (freed <= request.ask.maxSlotLoss) {
if (index !== slot.index) {
await contract.forciblyFreeSlot(slotId({ ...slot, index }))
freed++
}
index++
}
}
function patchOverloads(contract) {
contract.freeSlot = async (slotId, rewardRecipient, collateralRecipient) => {
const logicalXor = (a, b) => (a || b) && !(a && b)
if (logicalXor(rewardRecipient, collateralRecipient)) {
// XOR, if exactly one is truthy
throw new Error(
"Invalid freeSlot overload, you must specify both `rewardRecipient` and `collateralRecipient` or neither.",
)
}
if (!rewardRecipient && !collateralRecipient) {
// calls `freeSlot` overload without `rewardRecipient` and `collateralRecipient`
const fn = contract["freeSlot(bytes32)"]
return await fn(slotId)
}
const fn = contract["freeSlot(bytes32,address,address)"]
return await fn(slotId, rewardRecipient, collateralRecipient)
}
contract.withdrawFunds = async (requestId, withdrawRecipient) => {
if (!withdrawRecipient) {
// calls `withdrawFunds` overload without `withdrawRecipient`
const fn = contract["withdrawFunds(bytes32)"]
return await fn(requestId)
}
const fn = contract["withdrawFunds(bytes32,address)"]
return await fn(requestId, withdrawRecipient)
}
}
function littleEndianToBigInt(littleEndian) {
const buffer = Buffer.from(littleEndian)
return BigInt(`0x${buffer.toString("hex")}`)
}
module.exports = {
waitUntilCancelled,
waitUntilStarted,
waitUntilSlotsFilled,
waitUntilFinished,
waitUntilFailed,
waitUntilSlotFailed,
patchOverloads,
littleEndianToBigInt,
}