Skip to content

Commit

Permalink
fix bid & bid-random tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincharm committed Apr 16, 2024
1 parent 3a5c534 commit af6318e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 15 deletions.
13 changes: 6 additions & 7 deletions packages/contracts/scripts/node/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
VrfCoordinatorV2MockWithErc677__factory,
} from 'build/types'
import { minStateDuration, reservePrice, minBidIncrement, initialRequiredScore } from './config'
import { attestScore } from 'utils/attestScore'

const SECOND = 1000

Expand Down Expand Up @@ -68,14 +67,14 @@ async function bid(auctionRaffle: AuctionRaffle, signers: SignerWithAddress[], a
const scoreAttestationVerifier = ScoreAttestationVerifier__factory.connect(scoreVerifier, attestor)
const score = 21 * 10 ** 8 // 21.0
for (let i = 0; i < signers.length; i++) {
const subject = signers[i].address
const { signature } = await attestScore(
subject,
await bidAsSigner(
auctionRaffle,
signers[i],
initialBidAmount.add(minBidIncrement.mul(i)),
score,
attestor as unknown as Wallet,
scoreAttestationVerifier.address
attestor,
scoreAttestationVerifier
)
await bidAsSigner(auctionRaffle, signers[i], initialBidAmount.add(minBidIncrement.mul(i)), score, signature)
}
}

Expand Down
21 changes: 17 additions & 4 deletions packages/contracts/scripts/tasks/auctionRaffle/hardhatTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import { randomBigNumbers } from 'scripts/utils/random'
import { generateRandomAccounts } from 'scripts/utils/generateRandomAccounts'
import { fundAccounts } from 'scripts/utils/fundAccounts'
import { bidAsSigner } from 'scripts/utils/bid'
import { minBidIncrement, reservePrice } from 'scripts/node/config'
import { initialRequiredScore, minBidIncrement, reservePrice } from 'scripts/node/config'
import { connectToScoreAttestationVerifier } from 'scripts/utils/scoreAttestationVerifier'

const auctionRaffleAddress = '0x5FbDB2315678afecb367f032d93F642f64180aa3'
const scoreAttestationVerifierAddress = '0x0165878a594ca255338adfa4d48449f69242eb8f'
const auctionRaffleAddress = '0xa513e6e4b8f2a923d98304ec87f64353c4d5c853'

task('bid', 'Places bid for given account with provided amount')
.addParam('account', 'Hardhat account to use')
Expand All @@ -19,9 +21,11 @@ task('bid', 'Places bid for given account with provided amount')
const signer = await hre.ethers.getSigner(account)
const auctionRaffle = await connectToAuctionRaffle(hre, auctionRaffleAddress)
const auctionRaffleAsSigner = auctionRaffle.connect(signer)
const [attestor] = await hre.ethers.getSigners()
const scoreAttestationVerifier = await connectToScoreAttestationVerifier(hre, scoreAttestationVerifierAddress)

const ethAmount = parseEther(amount)
await auctionRaffleAsSigner.bid({ value: ethAmount })
await bidAsSigner(auctionRaffle, signer, ethAmount, initialRequiredScore, attestor, scoreAttestationVerifier)
logBid(account, ethAmount)
})

Expand All @@ -31,6 +35,8 @@ task('bid-random', 'Bids X times using randomly generated accounts')
.setAction(async ({ amount, account }: { amount: number; account: number }, hre) => {
const signers = await hre.ethers.getSigners()
const auctionRaffle = await connectToAuctionRaffle(hre, auctionRaffleAddress)
const attestor = signers[0]
const scoreAttestationVerifier = await connectToScoreAttestationVerifier(hre, scoreAttestationVerifierAddress)

console.log('Generating accounts...')
const randomAccounts = generateRandomAccounts(amount, hre.ethers.provider)
Expand All @@ -41,7 +47,14 @@ task('bid-random', 'Bids X times using randomly generated accounts')
console.log('Starting bidding...')
for (let i = 0; i < randomAccounts.length; i++) {
console.log(`Bidding with random account #${i + 1} out of ${randomAccounts.length}`)
await bidAsSigner(auctionRaffle, randomAccounts[i], reservePrice.add(minBidIncrement.mul(i)))
await bidAsSigner(
auctionRaffle,
randomAccounts[i],
reservePrice.add(minBidIncrement.mul(i)),
initialRequiredScore,
attestor,
scoreAttestationVerifier
)
}
})

Expand Down
15 changes: 11 additions & 4 deletions packages/contracts/scripts/utils/bid.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import { AuctionRaffle } from 'build/types'
import { BigNumberish, BytesLike, Signer } from 'ethers'
import { BigNumberish, Contract, Signer, Wallet } from 'ethers'
import { attestScore } from 'utils/attestScore'

export async function bidAsSigner(
auctionRaffle: AuctionRaffle,
auctionRaffle: Contract,
signer: Signer,
value: BigNumberish,
score: BigNumberish,
proof: BytesLike
attestor: Signer,
scoreAttestationVerifier: Contract
) {
const { signature: proof } = await attestScore(
await signer.getAddress(),
score,
attestor as unknown as Wallet,
scoreAttestationVerifier.address
)
await auctionRaffle.connect(signer).bid(score, proof, { value, gasLimit: 1_000_000 })
}
12 changes: 12 additions & 0 deletions packages/contracts/scripts/utils/scoreAttestationVerifier.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { HardhatRuntimeEnvironment } from 'hardhat/types'

export const scoreAttestationVerifierArtifactName =
'contracts/verifier/ScoreAttestationVerifier.sol:ScoreAttestationVerifier'

export async function connectToScoreAttestationVerifier(
hre: HardhatRuntimeEnvironment,
scoreAttestationVerifierAddress: string
) {
const scoreAttestationVerifierFactory = await hre.ethers.getContractFactory(scoreAttestationVerifierArtifactName)
return scoreAttestationVerifierFactory.attach(scoreAttestationVerifierAddress)
}

0 comments on commit af6318e

Please sign in to comment.