Initial build for QIE Mainnet Hackathon 3.0 (DeFi & Financial Infrastructure track). Includes: - packages/contracts: constant-product AMM (factory/pair/router), over-collateralized lending vault, and an oracle adapter wrapping QIE's real deployed price-feed contracts. 25/25 Foundry tests pass locally. Clean-room: no existing DEX/lending protocol source was read or copied. - packages/core: TypeScript SDK (viem-based) for QIE's chain, the real (corrected) oracle ABI, a fail-closed QUSDC helper, a Blockscout explorer client, and QIE Wallet connection constants. Live-verified against real testnet (chain 1983) and mainnet (chain 1990) RPCs and the real oracle contracts. - packages/cli: a small CLI built on @qie-forge/core. Real findings from building this, documented in README.md and docs/STATUS.md: the previously-documented testnet RPC URL is dead (replacement found and verified live); QIE's own oracle docs describe a getPrice(string) function that reverts on the real deployed contracts, which actually implement a Chainlink AggregatorV3-style interface (verified live via raw eth_call); the oracle is deployed on Mainnet only, not Testnet. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
106 lines
4.1 KiB
JavaScript
106 lines
4.1 KiB
JavaScript
import { network } from 'hardhat';
|
|
import { expect } from 'chai';
|
|
import { zip } from '../../helpers/iterate';
|
|
import { sum } from '../../helpers/math';
|
|
import { shouldBehaveLikeVotes } from './Votes.behavior';
|
|
|
|
const connection = await network.create();
|
|
const {
|
|
ethers,
|
|
helpers: { time },
|
|
networkHelpers: { loadFixture },
|
|
} = connection;
|
|
|
|
const MODES = {
|
|
blockNumber: '$VotesMock',
|
|
timestamp: '$VotesTimestampMock',
|
|
};
|
|
|
|
const AMOUNTS = [ethers.parseEther('10000000'), 10n, 20n];
|
|
|
|
describe('Votes', function () {
|
|
for (const [mode, artifact] of Object.entries(MODES)) {
|
|
const fixture = async () => {
|
|
const accounts = await ethers.getSigners();
|
|
|
|
const amounts = Object.fromEntries(
|
|
zip(
|
|
accounts.slice(0, AMOUNTS.length).map(({ address }) => address),
|
|
AMOUNTS,
|
|
),
|
|
);
|
|
|
|
const name = 'My Vote';
|
|
const version = '1';
|
|
const votes = await ethers.deployContract(artifact, [name, version]);
|
|
|
|
return { accounts, amounts, votes, name, version };
|
|
};
|
|
|
|
describe(`vote with ${mode}`, function () {
|
|
beforeEach(async function () {
|
|
Object.assign(this, connection, await loadFixture(fixture));
|
|
});
|
|
|
|
shouldBehaveLikeVotes(AMOUNTS, { mode, fungible: true });
|
|
|
|
it('starts with zero votes', async function () {
|
|
expect(await this.votes.getTotalSupply()).to.equal(0n);
|
|
});
|
|
|
|
describe('performs voting operations', function () {
|
|
beforeEach(async function () {
|
|
this.txs = [];
|
|
for (const [account, amount] of Object.entries(this.amounts)) {
|
|
this.txs.push(await this.votes.$_mint(account, amount));
|
|
}
|
|
});
|
|
|
|
it('reverts if block number >= current block', async function () {
|
|
const lastTxTimepoint = await time.clockFromReceipt[mode](this.txs.at(-1));
|
|
const clock = await this.votes.clock();
|
|
await expect(this.votes.getPastTotalSupply(lastTxTimepoint))
|
|
.to.be.revertedWithCustomError(this.votes, 'ERC5805FutureLookup')
|
|
.withArgs(lastTxTimepoint, clock);
|
|
});
|
|
|
|
it('delegates', async function () {
|
|
expect(await this.votes.getVotes(this.accounts[0])).to.equal(0n);
|
|
expect(await this.votes.getVotes(this.accounts[1])).to.equal(0n);
|
|
expect(await this.votes.delegates(this.accounts[0])).to.equal(ethers.ZeroAddress);
|
|
expect(await this.votes.delegates(this.accounts[1])).to.equal(ethers.ZeroAddress);
|
|
|
|
await this.votes.delegate(this.accounts[0], ethers.Typed.address(this.accounts[0]));
|
|
|
|
expect(await this.votes.getVotes(this.accounts[0])).to.equal(this.amounts[this.accounts[0].address]);
|
|
expect(await this.votes.getVotes(this.accounts[1])).to.equal(0n);
|
|
expect(await this.votes.delegates(this.accounts[0])).to.equal(this.accounts[0]);
|
|
expect(await this.votes.delegates(this.accounts[1])).to.equal(ethers.ZeroAddress);
|
|
|
|
await this.votes.delegate(this.accounts[1], ethers.Typed.address(this.accounts[0]));
|
|
|
|
expect(await this.votes.getVotes(this.accounts[0])).to.equal(
|
|
this.amounts[this.accounts[0].address] + this.amounts[this.accounts[1].address],
|
|
);
|
|
expect(await this.votes.getVotes(this.accounts[1])).to.equal(0n);
|
|
expect(await this.votes.delegates(this.accounts[0])).to.equal(this.accounts[0]);
|
|
expect(await this.votes.delegates(this.accounts[1])).to.equal(this.accounts[0]);
|
|
});
|
|
|
|
it('cross delegates', async function () {
|
|
await this.votes.delegate(this.accounts[0], ethers.Typed.address(this.accounts[1]));
|
|
await this.votes.delegate(this.accounts[1], ethers.Typed.address(this.accounts[0]));
|
|
|
|
expect(await this.votes.getVotes(this.accounts[0])).to.equal(this.amounts[this.accounts[1].address]);
|
|
expect(await this.votes.getVotes(this.accounts[1])).to.equal(this.amounts[this.accounts[0].address]);
|
|
});
|
|
|
|
it('returns total amount of votes', async function () {
|
|
const totalSupply = sum(...Object.values(this.amounts));
|
|
expect(await this.votes.getTotalSupply()).to.equal(totalSupply);
|
|
});
|
|
});
|
|
});
|
|
}
|
|
});
|