1c203eba8a
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
44 lines
2.4 KiB
JavaScript
44 lines
2.4 KiB
JavaScript
// Banner Line contract ABI: the ONE place the app learns the contract's shape.
|
|
// Primary: contract-abi.json = the compiled abi copied from ../contracts/out/BannerLine.sol/BannerLine.json
|
|
// (refresh it with `node qa/sync-abi.js` after a contract rebuild). Fallback: the SPEC.md shape below.
|
|
// Nothing else in the app hard-codes a selector or a topic.
|
|
// Reads are tried and skipped if missing (price falls back to the Chainlink feed math, same formula as InstantAdPay).
|
|
const { Interface } = require('ethers');
|
|
|
|
const SPEC_ABI = [
|
|
// writes
|
|
'function buy(address sponsor) payable',
|
|
'function buyFor(address owner, address sponsor) payable',
|
|
'function fundBuy(address giftee)',
|
|
// reads (OPTIONAL, any missing one is skipped)
|
|
'function quoteWei() view returns (uint256)',
|
|
'function requiredWei() view returns (uint256)',
|
|
'function priceFeed() view returns (address)',
|
|
'function fundBalance() view returns (uint256)',
|
|
'function lastGiftAt(address) view returns (uint256)',
|
|
'function paidSpots(address) view returns (uint256)',
|
|
'function spotCount() view returns (uint256)',
|
|
'function keeper() view returns (address)',
|
|
'function paused() view returns (bool)',
|
|
// events (names and argument order exactly as SPEC.md)
|
|
'event SpotBought(uint256 id, address owner, address payer, address sponsor, uint8 kind, uint256 valueWei, uint256 usdPrice)',
|
|
'event Paid(uint256 indexed spotId, address indexed to, uint256 amount, uint8 role)',
|
|
'event FundBuy(uint256 spotId, address giftee)',
|
|
'event MemberJoined(address member, address sponsor)',
|
|
'event PaymentFailed(uint256 indexed spotId, address indexed to, uint256 amount, uint8 role)'
|
|
];
|
|
let ABI = SPEC_ABI, ABI_SOURCE = 'spec';
|
|
try { const j = require('./contract-abi.json'); if (Array.isArray(j) && j.length) { ABI = j; ABI_SOURCE = 'compiled'; } } catch (e) {}
|
|
|
|
// Chainlink AggregatorV3 (POL/USD, 8 decimals), used only when the contract has no quote view
|
|
const FEED_ABI = ['function latestRoundData() view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound)'];
|
|
|
|
const PRICE_CENTS = 500; // $5 a spot (SPEC.md Money)
|
|
const KINDS = { 0: 'paid', 1: 'bought for', 2: 'fund gift', 3: 'fund kept' };
|
|
const ROLES = { 0: 'sponsor', 1: 'line', 2: 'company A', 3: 'company B', 4: 'fund' };
|
|
|
|
const iface = new Interface(ABI);
|
|
const feedIface = new Interface(FEED_ABI);
|
|
|
|
module.exports = { ABI, ABI_SOURCE, FEED_ABI, iface, feedIface, PRICE_CENTS, KINDS, ROLES };
|