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>
108 lines
4.0 KiB
JavaScript
108 lines
4.0 KiB
JavaScript
import { network } from 'hardhat';
|
|
import { expect } from 'chai';
|
|
import { shouldBehaveLikeERC6909 } from './ERC6909.behavior';
|
|
|
|
const {
|
|
ethers,
|
|
networkHelpers: { loadFixture },
|
|
} = await network.create();
|
|
|
|
async function fixture() {
|
|
const [holder, operator, recipient, other] = await ethers.getSigners();
|
|
const token = await ethers.deployContract('$ERC6909');
|
|
return { token, holder, operator, recipient, other };
|
|
}
|
|
|
|
describe('ERC6909', function () {
|
|
beforeEach(async function () {
|
|
Object.assign(this, await loadFixture(fixture));
|
|
});
|
|
|
|
shouldBehaveLikeERC6909();
|
|
|
|
describe('internal functions', function () {
|
|
const tokenId = 1990n;
|
|
const mintValue = 9001n;
|
|
const burnValue = 3000n;
|
|
|
|
describe('_mint', function () {
|
|
it('reverts with a zero destination address', async function () {
|
|
await expect(this.token.$_mint(ethers.ZeroAddress, tokenId, mintValue))
|
|
.to.be.revertedWithCustomError(this.token, 'ERC6909InvalidReceiver')
|
|
.withArgs(ethers.ZeroAddress);
|
|
});
|
|
|
|
describe('with minted tokens', function () {
|
|
beforeEach(async function () {
|
|
this.tx = await this.token.connect(this.operator).$_mint(this.holder, tokenId, mintValue);
|
|
});
|
|
|
|
it('emits a Transfer event from 0 address', async function () {
|
|
await expect(this.tx)
|
|
.to.emit(this.token, 'Transfer')
|
|
.withArgs(this.operator, ethers.ZeroAddress, this.holder, tokenId, mintValue);
|
|
});
|
|
|
|
it('credits the minted token value', async function () {
|
|
await expect(this.token.balanceOf(this.holder, tokenId)).to.eventually.be.equal(mintValue);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('_transfer', function () {
|
|
it('reverts when transferring from the zero address', async function () {
|
|
await expect(this.token.$_transfer(ethers.ZeroAddress, this.holder, 1n, 1n))
|
|
.to.be.revertedWithCustomError(this.token, 'ERC6909InvalidSender')
|
|
.withArgs(ethers.ZeroAddress);
|
|
});
|
|
|
|
it('reverts when transferring to the zero address', async function () {
|
|
await expect(this.token.$_transfer(this.holder, ethers.ZeroAddress, 1n, 1n))
|
|
.to.be.revertedWithCustomError(this.token, 'ERC6909InvalidReceiver')
|
|
.withArgs(ethers.ZeroAddress);
|
|
});
|
|
});
|
|
|
|
describe('_burn', function () {
|
|
it('reverts with a zero from address', async function () {
|
|
await expect(this.token.$_burn(ethers.ZeroAddress, tokenId, burnValue))
|
|
.to.be.revertedWithCustomError(this.token, 'ERC6909InvalidSender')
|
|
.withArgs(ethers.ZeroAddress);
|
|
});
|
|
|
|
describe('with burned tokens', function () {
|
|
beforeEach(async function () {
|
|
await this.token.connect(this.operator).$_mint(this.holder, tokenId, mintValue);
|
|
this.tx = await this.token.connect(this.operator).$_burn(this.holder, tokenId, burnValue);
|
|
});
|
|
|
|
it('emits a Transfer event to 0 address', async function () {
|
|
await expect(this.tx)
|
|
.to.emit(this.token, 'Transfer')
|
|
.withArgs(this.operator, this.holder, ethers.ZeroAddress, tokenId, burnValue);
|
|
});
|
|
|
|
it('debits the burned token value', async function () {
|
|
await expect(this.token.balanceOf(this.holder, tokenId)).to.eventually.be.equal(mintValue - burnValue);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('_approve', function () {
|
|
it('reverts when the owner is the zero address', async function () {
|
|
await expect(this.token.$_approve(ethers.ZeroAddress, this.recipient, 1n, 1n))
|
|
.to.be.revertedWithCustomError(this.token, 'ERC6909InvalidApprover')
|
|
.withArgs(ethers.ZeroAddress);
|
|
});
|
|
});
|
|
|
|
describe('_setOperator', function () {
|
|
it('reverts when the owner is the zero address', async function () {
|
|
await expect(this.token.$_setOperator(ethers.ZeroAddress, this.operator, true))
|
|
.to.be.revertedWithCustomError(this.token, 'ERC6909InvalidApprover')
|
|
.withArgs(ethers.ZeroAddress);
|
|
});
|
|
});
|
|
});
|
|
});
|