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>
74 lines
2.8 KiB
JavaScript
74 lines
2.8 KiB
JavaScript
import { network } from 'hardhat';
|
|
import { expect } from 'chai';
|
|
import { product } from '../helpers/iterate';
|
|
import * as random from '../helpers/random';
|
|
import { PACKING_SIZES as SIZES } from '../../scripts/generate/data.js';
|
|
|
|
const {
|
|
ethers,
|
|
networkHelpers: { loadFixture },
|
|
} = await network.create();
|
|
|
|
async function fixture() {
|
|
return { mock: await ethers.deployContract('$Packing') };
|
|
}
|
|
|
|
describe('Packing', function () {
|
|
beforeEach(async function () {
|
|
Object.assign(this, await loadFixture(fixture));
|
|
});
|
|
|
|
describe('pack', function () {
|
|
for (const [size1, size2] of product(SIZES, SIZES).filter(([size1, size2]) => SIZES.includes(size1 + size2))) {
|
|
const value1 = random.bytes(size1);
|
|
const value2 = random.bytes(size2);
|
|
const packed = ethers.concat([value1, value2]);
|
|
|
|
it(`pack bytes${size1} + bytes${size2} => bytes${size1 + size2}`, async function () {
|
|
expect(await this.mock[`$pack_${size1}_${size2}`](value1, value2)).to.equal(packed);
|
|
expect(await this.mock[`$extract_${size1 + size2}_${size1}`](packed, 0)).to.equal(ethers.hexlify(value1));
|
|
expect(await this.mock[`$extract_${size1 + size2}_${size2}`](packed, size1)).to.equal(ethers.hexlify(value2));
|
|
});
|
|
}
|
|
});
|
|
|
|
describe('extract / replace', function () {
|
|
for (const [size1, size2] of product(SIZES, SIZES).filter(([size1, size2]) => size1 > size2)) {
|
|
const MAX_OFFSET = size1 - size2;
|
|
const offset = ethers.toNumber(random.bytes(1)) % (MAX_OFFSET + 1);
|
|
const outer = random.bytes(size1);
|
|
const value = random.bytes(size2);
|
|
|
|
it(`extract bytes${size2} from bytes${size1}`, async function () {
|
|
expect(await this.mock[`$extract_${size1}_${size2}`](outer, offset)).to.equal(
|
|
ethers.hexlify(outer.slice(offset, offset + size2)),
|
|
);
|
|
|
|
await expect(this.mock[`$extract_${size1}_${size2}`](outer, MAX_OFFSET)).to.not.be.revertedWithCustomError(
|
|
this.mock,
|
|
'OutOfRangeAccess',
|
|
);
|
|
|
|
await expect(this.mock[`$extract_${size1}_${size2}`](outer, MAX_OFFSET + 1)).to.be.revertedWithCustomError(
|
|
this.mock,
|
|
'OutOfRangeAccess',
|
|
);
|
|
});
|
|
|
|
it(`replace bytes${size2} from bytes${size1}`, async function () {
|
|
expect(await this.mock[`$replace_${size1}_${size2}`](outer, value, offset)).to.equal(
|
|
ethers.concat([outer.slice(0, offset), value, outer.slice(offset + size2)]),
|
|
);
|
|
|
|
await expect(
|
|
this.mock[`$replace_${size1}_${size2}`](outer, value, MAX_OFFSET),
|
|
).to.not.be.revertedWithCustomError(this.mock, 'OutOfRangeAccess');
|
|
|
|
await expect(
|
|
this.mock[`$replace_${size1}_${size2}`](outer, value, MAX_OFFSET + 1),
|
|
).to.be.revertedWithCustomError(this.mock, 'OutOfRangeAccess');
|
|
});
|
|
}
|
|
});
|
|
});
|