mirror of
https://github.com/luxfhe/example-blind-auction-v2.git
synced 2026-10-30 18:13:35 +00:00
- Update to unified FHE decryption API - Update dependencies to @luxfi/contracts
64 lines
1.9 KiB
TypeScript
64 lines
1.9 KiB
TypeScript
import { task } from "hardhat/config";
|
|
import type { TaskArguments } from "hardhat/types";
|
|
import { FHERC20 } from "../../typechain-types";
|
|
|
|
task("task:bid")
|
|
.addParam("amount", "Amount to transfer (plaintext number)", "1")
|
|
.setAction(async function (taskArguments: TaskArguments, hre) {
|
|
const { luxfhe, ethers, deployments } = hre;
|
|
const [signer] = await ethers.getSigners();
|
|
let signerAddress = await signer.getAddress();
|
|
const amountToBid = Number(taskArguments.amount);
|
|
|
|
const fherc20 = await deployments.get("ExampleToken");
|
|
const tokenContract = await ethers.getContractAt(
|
|
"ExampleToken",
|
|
fherc20.address,
|
|
);
|
|
|
|
const auction = await deployments.get("Auction");
|
|
const auctionContract = await ethers.getContractAt(
|
|
"Auction",
|
|
auction.address,
|
|
);
|
|
|
|
const encryptedAmount = await luxfhe.encrypt_uint32(amountToBid);
|
|
|
|
let contractWithSigner = tokenContract.connect(
|
|
signer,
|
|
) as unknown as FHERC20;
|
|
|
|
console.log(
|
|
`setting allowance on token contract: ${fherc20.address} for auction contract at: ${fherc20.address}`,
|
|
);
|
|
|
|
console.time("allowanceDuration");
|
|
try {
|
|
await contractWithSigner.approveEncrypted(
|
|
auction.address,
|
|
encryptedAmount,
|
|
);
|
|
} catch (e) {
|
|
console.log(`failed to set allowance: ${e}`);
|
|
console.timeEnd("allowanceDuration");
|
|
return;
|
|
}
|
|
console.timeEnd("allowanceDuration");
|
|
|
|
console.log(`minting ${amountToBid}`);
|
|
await hre.run("task:mint", { amount: String(amountToBid) });
|
|
|
|
console.log(
|
|
`bidding @ auction contract at: ${fherc20.address}, amount: ${amountToBid}`,
|
|
);
|
|
console.time("bidDuration");
|
|
try {
|
|
await auctionContract.bid(encryptedAmount);
|
|
} catch (e) {
|
|
console.log(`failed to bid: ${e}`);
|
|
console.timeEnd("bidDuration");
|
|
return;
|
|
}
|
|
console.timeEnd("bidDuration");
|
|
});
|