From 7cc05d920c373ae06c7175e42b47a1515adb7caf Mon Sep 17 00:00:00 2001 From: bitbeckers Date: Thu, 26 Oct 2023 12:58:28 +0200 Subject: [PATCH] fix(build): build and lint errors --- contracts/.solhint.json | 7 +- contracts/hardhat.config.ts | 2 +- contracts/package.json | 2 +- .../CreatorFeeManagerWithRoyalties.sol | 12 +- .../interfaces/ILooksRareProtocol.sol | 12 +- .../marketplace/ProtocolFeeRecipient.t.sol | 2 +- .../marketplace/utils/MerkleWithPosition.sol | 12 +- .../foundry/protocol/HypercertMinter.t.sol | 4 +- graph/abis/HypercertTrader.json | 656 ------------ .../HypercertTrader/HypercertTrader.ts | 954 ------------------ graph/networks.json | 4 - graph/src/hypercert-trader.ts | 73 -- graph/src/utils.ts | 1 - graph/subgraph.yaml | 24 - graph/tests/hypercert-trader-utils.ts | 261 ----- graph/tests/hypercert-trader.test.ts | 80 -- 16 files changed, 31 insertions(+), 2075 deletions(-) delete mode 100644 graph/abis/HypercertTrader.json delete mode 100644 graph/generated/HypercertTrader/HypercertTrader.ts delete mode 100644 graph/src/hypercert-trader.ts delete mode 100644 graph/tests/hypercert-trader-utils.ts delete mode 100644 graph/tests/hypercert-trader.test.ts diff --git a/contracts/.solhint.json b/contracts/.solhint.json index d60b535e..fad41466 100644 --- a/contracts/.solhint.json +++ b/contracts/.solhint.json @@ -1,11 +1,10 @@ { - "plugins": ["prettier"], "extends": "solhint:recommended", "rules": { - "code-complexity": ["error", 8], - "compiler-version": ["error", "0.8.16"], + "code-complexity": ["error", 12], + "compiler-version": ["error", ">=0.8.16"], "func-visibility": ["error", { "ignoreConstructors": true }], - "max-line-length": ["warn", 120], + "max-line-length": ["warn", 200], "no-console": "off", "not-rely-on-time": "off", "reason-string": ["warn", { "maxLength": 64 }], diff --git a/contracts/hardhat.config.ts b/contracts/hardhat.config.ts index 36d33635..87cd1dc7 100644 --- a/contracts/hardhat.config.ts +++ b/contracts/hardhat.config.ts @@ -152,7 +152,7 @@ const config = { }, paths: { cache: "./cache_hardhat", // Use a different cache for Hardhat than Foundry - sources: "./src", + sources: "./src/protocol", tests: "./test", }, preprocess: { diff --git a/contracts/package.json b/contracts/package.json index 21473b24..5d06aefd 100644 --- a/contracts/package.json +++ b/contracts/package.json @@ -107,7 +107,7 @@ "copy:contracts": "copyfiles -u 1 ./src/**/*.sol ./src/*.sol ./contracts", "docs": "hardhat dodoc", "lint": "pnpm lint:sol && pnpm prettier:check", - "lint:sol": "solhint -w 5 \"./{src,test}/**/*.sol\"", + "lint:sol": "solhint -w 60 \"./{src,test/protocol,test/marketplace}/**/*.sol\"", "prebuild": "pnpm clean", "prepublish": "pnpm build", "prettier": "prettier --config \"./.prettierrc.yml\" --write \"**/*.{json,md,sol,yml}\"", diff --git a/contracts/src/marketplace/CreatorFeeManagerWithRoyalties.sol b/contracts/src/marketplace/CreatorFeeManagerWithRoyalties.sol index a1185163..ac72682d 100644 --- a/contracts/src/marketplace/CreatorFeeManagerWithRoyalties.sol +++ b/contracts/src/marketplace/CreatorFeeManagerWithRoyalties.sol @@ -30,16 +30,16 @@ contract CreatorFeeManagerWithRoyalties is ICreatorFeeManager { /** * @inheritdoc ICreatorFeeManager * @dev There are two on-chain sources for the royalty fee to distribute. - * 1. RoyaltyFeeRegistry: It is an on-chain registry where creator fee is defined - for all items of a collection. + * 1. RoyaltyFeeRegistry: It is an on-chain registry where creator fee is defined + * for all items of a collection. * 2. ERC2981: The NFT Royalty Standard where royalty fee is defined at a itemId level in a collection. - * The on-chain logic looks up the registry first. If it does not find anything, + * The on-chain logic looks up the registry first. If it does not find anything, * it checks if a collection is ERC2981. If so, it fetches the proper royalty information for the itemId. - * For a bundle that contains multiple itemIds (for a collection using ERC2981), if the royalty fee/recipient + * For a bundle that contains multiple itemIds (for a collection using ERC2981), if the royalty fee/recipient * differ among the itemIds part of the bundle, the trade reverts. - * This contract DOES NOT enforce any restriction for extremely high creator fee, + * This contract DOES NOT enforce any restriction for extremely high creator fee, * nor verifies the creator fee fetched is inferior to the total price. - * If any contract relies on it to build an on-chain royalty logic, + * If any contract relies on it to build an on-chain royalty logic, * it should implement protection against: * (1) high royalties * (2) potential unexpected royalty changes that can occur after the creation of the order. diff --git a/contracts/src/marketplace/interfaces/ILooksRareProtocol.sol b/contracts/src/marketplace/interfaces/ILooksRareProtocol.sol index b9305d03..09722537 100644 --- a/contracts/src/marketplace/interfaces/ILooksRareProtocol.sol +++ b/contracts/src/marketplace/interfaces/ILooksRareProtocol.sol @@ -59,10 +59,12 @@ interface ILooksRareProtocol { * feeAmounts[1] Creator fee amount * feeAmounts[2] Protocol fee amount prior to adjustment for a potential affiliate payment */ + // maker (receives the NFT) event TakerAsk( + // taker (initiates the transaction) NonceInvalidationParameters nonceInvalidationParameters, - address askUser, // taker (initiates the transaction) - address bidUser, // maker (receives the NFT) + address askUser, + address bidUser, uint256 strategyId, address currency, address collection, @@ -90,10 +92,12 @@ interface ILooksRareProtocol { * feeAmounts[1] Creator fee amount * feeAmounts[2] Protocol fee amount prior to adjustment for a potential affiliate payment */ + // taker (receives the NFT) event TakerBid( + // taker (initiates the transaction) NonceInvalidationParameters nonceInvalidationParameters, - address bidUser, // taker (initiates the transaction) - address bidRecipient, // taker (receives the NFT) + address bidUser, + address bidRecipient, uint256 strategyId, address currency, address collection, diff --git a/contracts/test/foundry/marketplace/ProtocolFeeRecipient.t.sol b/contracts/test/foundry/marketplace/ProtocolFeeRecipient.t.sol index 5074a83d..36f370df 100644 --- a/contracts/test/foundry/marketplace/ProtocolFeeRecipient.t.sol +++ b/contracts/test/foundry/marketplace/ProtocolFeeRecipient.t.sol @@ -17,7 +17,7 @@ contract ProtocolFeeRecipientTest is TestParameters { uint256 private feeSharingSetterInitialWETHBalance; address private constant FEE_SHARING_SETTER = 0x5924A28caAF1cc016617874a2f0C3710d881f3c1; - uint256 private constant DUST = 0.69420 ether; + uint256 private constant DUST = 0.6942 ether; function setUp() public { vm.createSelectFork(vm.rpcUrl("mainnet")); diff --git a/contracts/test/foundry/marketplace/utils/MerkleWithPosition.sol b/contracts/test/foundry/marketplace/utils/MerkleWithPosition.sol index 38628707..3b7cf871 100644 --- a/contracts/test/foundry/marketplace/utils/MerkleWithPosition.sol +++ b/contracts/test/foundry/marketplace/utils/MerkleWithPosition.sol @@ -8,9 +8,11 @@ import { OrderStructs } from "@hypercerts/marketplace/libraries/OrderStructs.sol * hashLeafPair does not sort the nodes to match EIP-712. */ contract MerkleWithPosition { - /******************** + /** + * * PROOF GENERATION * - ********************/ + * + */ function getRoot(OrderStructs.MerkleTreeNode[] memory data) public pure returns (bytes32) { require(data.length > 1, "won't generate root for single leaf"); @@ -90,9 +92,11 @@ contract MerkleWithPosition { return result; } - /****************** + /** + * * MATH "LIBRARY" * - ******************/ + * + */ /// Original bitmagic adapted from https://github.com/paulrberg/prb-math/blob/main/contracts/PRBMath.sol /// @dev Note that x assumed > 1 diff --git a/contracts/test/foundry/protocol/HypercertMinter.t.sol b/contracts/test/foundry/protocol/HypercertMinter.t.sol index 6647ffc0..86364b56 100644 --- a/contracts/test/foundry/protocol/HypercertMinter.t.sol +++ b/contracts/test/foundry/protocol/HypercertMinter.t.sol @@ -38,7 +38,9 @@ contract MinterTestHelper { return 0; } sum = 0; - for (uint256 i = 0; i < array.length; i++) sum += array[i]; + for (uint256 i = 0; i < array.length; i++) { + sum += array[i]; + } } function buildFractions(uint256 size) public pure returns (uint256[] memory) { diff --git a/graph/abis/HypercertTrader.json b/graph/abis/HypercertTrader.json deleted file mode 100644 index 1f114e5e..00000000 --- a/graph/abis/HypercertTrader.json +++ /dev/null @@ -1,656 +0,0 @@ -[ - { - "inputs": [], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "inputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "name": "InvalidBuy", - "type": "error" - }, - { - "inputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "name": "InvalidOffer", - "type": "error" - }, - { - "inputs": [], - "name": "NotAllowed", - "type": "error" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "previousAdmin", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "newAdmin", - "type": "address" - } - ], - "name": "AdminChanged", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "beacon", - "type": "address" - } - ], - "name": "BeaconUpgraded", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint8", - "name": "version", - "type": "uint8" - } - ], - "name": "Initialized", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "creator", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "hypercertContract", - "type": "address" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "fractionID", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "offerID", - "type": "uint256" - } - ], - "name": "OfferCancelled", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "offerer", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "hypercertContract", - "type": "address" - }, - { - "indexed": true, - "internalType": "uint256", - "name": "fractionID", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "offerID", - "type": "uint256" - } - ], - "name": "OfferCreated", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "previousOwner", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "newOwner", - "type": "address" - } - ], - "name": "OwnershipTransferred", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "Paused", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "seller", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "buyer", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "hypercertContract", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "fractionID", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "unitsBought", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "address", - "name": "buyToken", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "tokenAmountPerUnit", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "offerID", - "type": "uint256" - } - ], - "name": "Trade", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "account", - "type": "address" - } - ], - "name": "Unpaused", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "implementation", - "type": "address" - } - ], - "name": "Upgraded", - "type": "event" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "recipient", - "type": "address" - }, - { - "internalType": "uint256[]", - "name": "offerIDs", - "type": "uint256[]" - }, - { - "internalType": "uint256[]", - "name": "unitAmounts", - "type": "uint256[]" - }, - { - "internalType": "address[]", - "name": "buyTokens", - "type": "address[]" - }, - { - "internalType": "uint256[]", - "name": "tokenAmountsPerUnit", - "type": "uint256[]" - } - ], - "name": "batchBuyUnits", - "outputs": [], - "stateMutability": "payable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "recipient", - "type": "address" - }, - { - "internalType": "uint256", - "name": "offerID", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "unitAmount", - "type": "uint256" - }, - { - "internalType": "address", - "name": "buyToken", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenAmountPerUnit", - "type": "uint256" - } - ], - "name": "buyUnits", - "outputs": [], - "stateMutability": "payable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "offerID", - "type": "uint256" - } - ], - "name": "cancelOffer", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "hypercertContract", - "type": "address" - }, - { - "internalType": "uint256", - "name": "fractionID", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "unitsForSale", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "minUnitsPerTrade", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxUnitsPerTrade", - "type": "uint256" - }, - { - "components": [ - { - "internalType": "address", - "name": "token", - "type": "address" - }, - { - "internalType": "uint256", - "name": "minimumAmountPerUnit", - "type": "uint256" - } - ], - "internalType": "struct IHypercertTrader.AcceptedToken[]", - "name": "acceptedTokens", - "type": "tuple[]" - } - ], - "name": "createOffer", - "outputs": [ - { - "internalType": "uint256", - "name": "offerID", - "type": "uint256" - } - ], - "stateMutability": "payable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "offerID", - "type": "uint256" - } - ], - "name": "getOffer", - "outputs": [ - { - "components": [ - { - "internalType": "address", - "name": "offerer", - "type": "address" - }, - { - "internalType": "address", - "name": "hypercertContract", - "type": "address" - }, - { - "internalType": "uint256", - "name": "fractionID", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "unitsAvailable", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "minUnitsPerTrade", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxUnitsPerTrade", - "type": "uint256" - }, - { - "internalType": "enum IHypercertTrader.OfferType", - "name": "offerType", - "type": "uint8" - }, - { - "internalType": "enum IHypercertTrader.OfferStatus", - "name": "status", - "type": "uint8" - }, - { - "components": [ - { - "internalType": "address", - "name": "token", - "type": "address" - }, - { - "internalType": "uint256", - "name": "minimumAmountPerUnit", - "type": "uint256" - } - ], - "internalType": "struct IHypercertTrader.AcceptedToken[]", - "name": "acceptedTokens", - "type": "tuple[]" - } - ], - "internalType": "struct IHypercertTrader.Offer", - "name": "", - "type": "tuple" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "initialize", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "offers", - "outputs": [ - { - "internalType": "address", - "name": "offerer", - "type": "address" - }, - { - "internalType": "address", - "name": "hypercertContract", - "type": "address" - }, - { - "internalType": "uint256", - "name": "fractionID", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "unitsAvailable", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "minUnitsPerTrade", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "maxUnitsPerTrade", - "type": "uint256" - }, - { - "internalType": "enum IHypercertTrader.OfferType", - "name": "offerType", - "type": "uint8" - }, - { - "internalType": "enum IHypercertTrader.OfferStatus", - "name": "status", - "type": "uint8" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "owner", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "pause", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "paused", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "proxiableUUID", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "renounceOwnership", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - }, - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "totalUnitsForSale", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "newOwner", - "type": "address" - } - ], - "name": "transferOwnership", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "unpause", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "newImplementation", - "type": "address" - } - ], - "name": "upgradeTo", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "newImplementation", - "type": "address" - }, - { - "internalType": "bytes", - "name": "data", - "type": "bytes" - } - ], - "name": "upgradeToAndCall", - "outputs": [], - "stateMutability": "payable", - "type": "function" - } -] diff --git a/graph/generated/HypercertTrader/HypercertTrader.ts b/graph/generated/HypercertTrader/HypercertTrader.ts deleted file mode 100644 index 36aef88f..00000000 --- a/graph/generated/HypercertTrader/HypercertTrader.ts +++ /dev/null @@ -1,954 +0,0 @@ -// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. - -import { - ethereum, - JSONValue, - TypedMap, - Entity, - Bytes, - Address, - BigInt, -} from "@graphprotocol/graph-ts"; - -export class AdminChanged extends ethereum.Event { - get params(): AdminChanged__Params { - return new AdminChanged__Params(this); - } -} - -export class AdminChanged__Params { - _event: AdminChanged; - - constructor(event: AdminChanged) { - this._event = event; - } - - get previousAdmin(): Address { - return this._event.parameters[0].value.toAddress(); - } - - get newAdmin(): Address { - return this._event.parameters[1].value.toAddress(); - } -} - -export class BeaconUpgraded extends ethereum.Event { - get params(): BeaconUpgraded__Params { - return new BeaconUpgraded__Params(this); - } -} - -export class BeaconUpgraded__Params { - _event: BeaconUpgraded; - - constructor(event: BeaconUpgraded) { - this._event = event; - } - - get beacon(): Address { - return this._event.parameters[0].value.toAddress(); - } -} - -export class Initialized extends ethereum.Event { - get params(): Initialized__Params { - return new Initialized__Params(this); - } -} - -export class Initialized__Params { - _event: Initialized; - - constructor(event: Initialized) { - this._event = event; - } - - get version(): i32 { - return this._event.parameters[0].value.toI32(); - } -} - -export class OfferCancelled extends ethereum.Event { - get params(): OfferCancelled__Params { - return new OfferCancelled__Params(this); - } -} - -export class OfferCancelled__Params { - _event: OfferCancelled; - - constructor(event: OfferCancelled) { - this._event = event; - } - - get creator(): Address { - return this._event.parameters[0].value.toAddress(); - } - - get hypercertContract(): Address { - return this._event.parameters[1].value.toAddress(); - } - - get fractionID(): BigInt { - return this._event.parameters[2].value.toBigInt(); - } - - get offerID(): BigInt { - return this._event.parameters[3].value.toBigInt(); - } -} - -export class OfferCreated extends ethereum.Event { - get params(): OfferCreated__Params { - return new OfferCreated__Params(this); - } -} - -export class OfferCreated__Params { - _event: OfferCreated; - - constructor(event: OfferCreated) { - this._event = event; - } - - get offerer(): Address { - return this._event.parameters[0].value.toAddress(); - } - - get hypercertContract(): Address { - return this._event.parameters[1].value.toAddress(); - } - - get fractionID(): BigInt { - return this._event.parameters[2].value.toBigInt(); - } - - get offerID(): BigInt { - return this._event.parameters[3].value.toBigInt(); - } -} - -export class OwnershipTransferred extends ethereum.Event { - get params(): OwnershipTransferred__Params { - return new OwnershipTransferred__Params(this); - } -} - -export class OwnershipTransferred__Params { - _event: OwnershipTransferred; - - constructor(event: OwnershipTransferred) { - this._event = event; - } - - get previousOwner(): Address { - return this._event.parameters[0].value.toAddress(); - } - - get newOwner(): Address { - return this._event.parameters[1].value.toAddress(); - } -} - -export class Paused extends ethereum.Event { - get params(): Paused__Params { - return new Paused__Params(this); - } -} - -export class Paused__Params { - _event: Paused; - - constructor(event: Paused) { - this._event = event; - } - - get account(): Address { - return this._event.parameters[0].value.toAddress(); - } -} - -export class Trade extends ethereum.Event { - get params(): Trade__Params { - return new Trade__Params(this); - } -} - -export class Trade__Params { - _event: Trade; - - constructor(event: Trade) { - this._event = event; - } - - get seller(): Address { - return this._event.parameters[0].value.toAddress(); - } - - get buyer(): Address { - return this._event.parameters[1].value.toAddress(); - } - - get hypercertContract(): Address { - return this._event.parameters[2].value.toAddress(); - } - - get fractionID(): BigInt { - return this._event.parameters[3].value.toBigInt(); - } - - get unitsBought(): BigInt { - return this._event.parameters[4].value.toBigInt(); - } - - get buyToken(): Address { - return this._event.parameters[5].value.toAddress(); - } - - get tokenAmountPerUnit(): BigInt { - return this._event.parameters[6].value.toBigInt(); - } - - get offerID(): BigInt { - return this._event.parameters[7].value.toBigInt(); - } -} - -export class Unpaused extends ethereum.Event { - get params(): Unpaused__Params { - return new Unpaused__Params(this); - } -} - -export class Unpaused__Params { - _event: Unpaused; - - constructor(event: Unpaused) { - this._event = event; - } - - get account(): Address { - return this._event.parameters[0].value.toAddress(); - } -} - -export class Upgraded extends ethereum.Event { - get params(): Upgraded__Params { - return new Upgraded__Params(this); - } -} - -export class Upgraded__Params { - _event: Upgraded; - - constructor(event: Upgraded) { - this._event = event; - } - - get implementation(): Address { - return this._event.parameters[0].value.toAddress(); - } -} - -export class HypercertTrader__getOfferResultValue0Struct extends ethereum.Tuple { - get offerer(): Address { - return this[0].toAddress(); - } - - get hypercertContract(): Address { - return this[1].toAddress(); - } - - get fractionID(): BigInt { - return this[2].toBigInt(); - } - - get unitsAvailable(): BigInt { - return this[3].toBigInt(); - } - - get minUnitsPerTrade(): BigInt { - return this[4].toBigInt(); - } - - get maxUnitsPerTrade(): BigInt { - return this[5].toBigInt(); - } - - get offerType(): i32 { - return this[6].toI32(); - } - - get status(): i32 { - return this[7].toI32(); - } - - get acceptedTokens(): Array { - return this[8].toTupleArray(); - } -} - -export class HypercertTrader__getOfferResultValue0AcceptedTokensStruct extends ethereum.Tuple { - get token(): Address { - return this[0].toAddress(); - } - - get minimumAmountPerUnit(): BigInt { - return this[1].toBigInt(); - } -} - -export class HypercertTrader__offersResult { - value0: Address; - value1: Address; - value2: BigInt; - value3: BigInt; - value4: BigInt; - value5: BigInt; - value6: i32; - value7: i32; - - constructor( - value0: Address, - value1: Address, - value2: BigInt, - value3: BigInt, - value4: BigInt, - value5: BigInt, - value6: i32, - value7: i32, - ) { - this.value0 = value0; - this.value1 = value1; - this.value2 = value2; - this.value3 = value3; - this.value4 = value4; - this.value5 = value5; - this.value6 = value6; - this.value7 = value7; - } - - toMap(): TypedMap { - let map = new TypedMap(); - map.set("value0", ethereum.Value.fromAddress(this.value0)); - map.set("value1", ethereum.Value.fromAddress(this.value1)); - map.set("value2", ethereum.Value.fromUnsignedBigInt(this.value2)); - map.set("value3", ethereum.Value.fromUnsignedBigInt(this.value3)); - map.set("value4", ethereum.Value.fromUnsignedBigInt(this.value4)); - map.set("value5", ethereum.Value.fromUnsignedBigInt(this.value5)); - map.set( - "value6", - ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(this.value6)), - ); - map.set( - "value7", - ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(this.value7)), - ); - return map; - } - - getOfferer(): Address { - return this.value0; - } - - getHypercertContract(): Address { - return this.value1; - } - - getFractionID(): BigInt { - return this.value2; - } - - getUnitsAvailable(): BigInt { - return this.value3; - } - - getMinUnitsPerTrade(): BigInt { - return this.value4; - } - - getMaxUnitsPerTrade(): BigInt { - return this.value5; - } - - getOfferType(): i32 { - return this.value6; - } - - getStatus(): i32 { - return this.value7; - } -} - -export class HypercertTrader extends ethereum.SmartContract { - static bind(address: Address): HypercertTrader { - return new HypercertTrader("HypercertTrader", address); - } - - getOffer(offerID: BigInt): HypercertTrader__getOfferResultValue0Struct { - let result = super.call( - "getOffer", - "getOffer(uint256):((address,address,uint256,uint256,uint256,uint256,uint8,uint8,(address,uint256)[]))", - [ethereum.Value.fromUnsignedBigInt(offerID)], - ); - - return changetype( - result[0].toTuple(), - ); - } - - try_getOffer( - offerID: BigInt, - ): ethereum.CallResult { - let result = super.tryCall( - "getOffer", - "getOffer(uint256):((address,address,uint256,uint256,uint256,uint256,uint8,uint8,(address,uint256)[]))", - [ethereum.Value.fromUnsignedBigInt(offerID)], - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue( - changetype( - value[0].toTuple(), - ), - ); - } - - offers(param0: BigInt): HypercertTrader__offersResult { - let result = super.call( - "offers", - "offers(uint256):(address,address,uint256,uint256,uint256,uint256,uint8,uint8)", - [ethereum.Value.fromUnsignedBigInt(param0)], - ); - - return new HypercertTrader__offersResult( - result[0].toAddress(), - result[1].toAddress(), - result[2].toBigInt(), - result[3].toBigInt(), - result[4].toBigInt(), - result[5].toBigInt(), - result[6].toI32(), - result[7].toI32(), - ); - } - - try_offers( - param0: BigInt, - ): ethereum.CallResult { - let result = super.tryCall( - "offers", - "offers(uint256):(address,address,uint256,uint256,uint256,uint256,uint8,uint8)", - [ethereum.Value.fromUnsignedBigInt(param0)], - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue( - new HypercertTrader__offersResult( - value[0].toAddress(), - value[1].toAddress(), - value[2].toBigInt(), - value[3].toBigInt(), - value[4].toBigInt(), - value[5].toBigInt(), - value[6].toI32(), - value[7].toI32(), - ), - ); - } - - owner(): Address { - let result = super.call("owner", "owner():(address)", []); - - return result[0].toAddress(); - } - - try_owner(): ethereum.CallResult
{ - let result = super.tryCall("owner", "owner():(address)", []); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toAddress()); - } - - paused(): boolean { - let result = super.call("paused", "paused():(bool)", []); - - return result[0].toBoolean(); - } - - try_paused(): ethereum.CallResult { - let result = super.tryCall("paused", "paused():(bool)", []); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBoolean()); - } - - proxiableUUID(): Bytes { - let result = super.call("proxiableUUID", "proxiableUUID():(bytes32)", []); - - return result[0].toBytes(); - } - - try_proxiableUUID(): ethereum.CallResult { - let result = super.tryCall( - "proxiableUUID", - "proxiableUUID():(bytes32)", - [], - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBytes()); - } - - totalUnitsForSale(param0: Address, param1: BigInt): BigInt { - let result = super.call( - "totalUnitsForSale", - "totalUnitsForSale(address,uint256):(uint256)", - [ - ethereum.Value.fromAddress(param0), - ethereum.Value.fromUnsignedBigInt(param1), - ], - ); - - return result[0].toBigInt(); - } - - try_totalUnitsForSale( - param0: Address, - param1: BigInt, - ): ethereum.CallResult { - let result = super.tryCall( - "totalUnitsForSale", - "totalUnitsForSale(address,uint256):(uint256)", - [ - ethereum.Value.fromAddress(param0), - ethereum.Value.fromUnsignedBigInt(param1), - ], - ); - if (result.reverted) { - return new ethereum.CallResult(); - } - let value = result.value; - return ethereum.CallResult.fromValue(value[0].toBigInt()); - } -} - -export class ConstructorCall extends ethereum.Call { - get inputs(): ConstructorCall__Inputs { - return new ConstructorCall__Inputs(this); - } - - get outputs(): ConstructorCall__Outputs { - return new ConstructorCall__Outputs(this); - } -} - -export class ConstructorCall__Inputs { - _call: ConstructorCall; - - constructor(call: ConstructorCall) { - this._call = call; - } -} - -export class ConstructorCall__Outputs { - _call: ConstructorCall; - - constructor(call: ConstructorCall) { - this._call = call; - } -} - -export class BatchBuyUnitsCall extends ethereum.Call { - get inputs(): BatchBuyUnitsCall__Inputs { - return new BatchBuyUnitsCall__Inputs(this); - } - - get outputs(): BatchBuyUnitsCall__Outputs { - return new BatchBuyUnitsCall__Outputs(this); - } -} - -export class BatchBuyUnitsCall__Inputs { - _call: BatchBuyUnitsCall; - - constructor(call: BatchBuyUnitsCall) { - this._call = call; - } - - get recipient(): Address { - return this._call.inputValues[0].value.toAddress(); - } - - get offerIDs(): Array { - return this._call.inputValues[1].value.toBigIntArray(); - } - - get unitAmounts(): Array { - return this._call.inputValues[2].value.toBigIntArray(); - } - - get buyTokens(): Array
{ - return this._call.inputValues[3].value.toAddressArray(); - } - - get tokenAmountsPerUnit(): Array { - return this._call.inputValues[4].value.toBigIntArray(); - } -} - -export class BatchBuyUnitsCall__Outputs { - _call: BatchBuyUnitsCall; - - constructor(call: BatchBuyUnitsCall) { - this._call = call; - } -} - -export class BuyUnitsCall extends ethereum.Call { - get inputs(): BuyUnitsCall__Inputs { - return new BuyUnitsCall__Inputs(this); - } - - get outputs(): BuyUnitsCall__Outputs { - return new BuyUnitsCall__Outputs(this); - } -} - -export class BuyUnitsCall__Inputs { - _call: BuyUnitsCall; - - constructor(call: BuyUnitsCall) { - this._call = call; - } - - get recipient(): Address { - return this._call.inputValues[0].value.toAddress(); - } - - get offerID(): BigInt { - return this._call.inputValues[1].value.toBigInt(); - } - - get unitAmount(): BigInt { - return this._call.inputValues[2].value.toBigInt(); - } - - get buyToken(): Address { - return this._call.inputValues[3].value.toAddress(); - } - - get tokenAmountPerUnit(): BigInt { - return this._call.inputValues[4].value.toBigInt(); - } -} - -export class BuyUnitsCall__Outputs { - _call: BuyUnitsCall; - - constructor(call: BuyUnitsCall) { - this._call = call; - } -} - -export class CancelOfferCall extends ethereum.Call { - get inputs(): CancelOfferCall__Inputs { - return new CancelOfferCall__Inputs(this); - } - - get outputs(): CancelOfferCall__Outputs { - return new CancelOfferCall__Outputs(this); - } -} - -export class CancelOfferCall__Inputs { - _call: CancelOfferCall; - - constructor(call: CancelOfferCall) { - this._call = call; - } - - get offerID(): BigInt { - return this._call.inputValues[0].value.toBigInt(); - } -} - -export class CancelOfferCall__Outputs { - _call: CancelOfferCall; - - constructor(call: CancelOfferCall) { - this._call = call; - } -} - -export class CreateOfferCall extends ethereum.Call { - get inputs(): CreateOfferCall__Inputs { - return new CreateOfferCall__Inputs(this); - } - - get outputs(): CreateOfferCall__Outputs { - return new CreateOfferCall__Outputs(this); - } -} - -export class CreateOfferCall__Inputs { - _call: CreateOfferCall; - - constructor(call: CreateOfferCall) { - this._call = call; - } - - get hypercertContract(): Address { - return this._call.inputValues[0].value.toAddress(); - } - - get fractionID(): BigInt { - return this._call.inputValues[1].value.toBigInt(); - } - - get unitsForSale(): BigInt { - return this._call.inputValues[2].value.toBigInt(); - } - - get minUnitsPerTrade(): BigInt { - return this._call.inputValues[3].value.toBigInt(); - } - - get maxUnitsPerTrade(): BigInt { - return this._call.inputValues[4].value.toBigInt(); - } - - get acceptedTokens(): Array { - return this._call.inputValues[5].value.toTupleArray(); - } -} - -export class CreateOfferCall__Outputs { - _call: CreateOfferCall; - - constructor(call: CreateOfferCall) { - this._call = call; - } - - get offerID(): BigInt { - return this._call.outputValues[0].value.toBigInt(); - } -} - -export class CreateOfferCallAcceptedTokensStruct extends ethereum.Tuple { - get token(): Address { - return this[0].toAddress(); - } - - get minimumAmountPerUnit(): BigInt { - return this[1].toBigInt(); - } -} - -export class InitializeCall extends ethereum.Call { - get inputs(): InitializeCall__Inputs { - return new InitializeCall__Inputs(this); - } - - get outputs(): InitializeCall__Outputs { - return new InitializeCall__Outputs(this); - } -} - -export class InitializeCall__Inputs { - _call: InitializeCall; - - constructor(call: InitializeCall) { - this._call = call; - } -} - -export class InitializeCall__Outputs { - _call: InitializeCall; - - constructor(call: InitializeCall) { - this._call = call; - } -} - -export class PauseCall extends ethereum.Call { - get inputs(): PauseCall__Inputs { - return new PauseCall__Inputs(this); - } - - get outputs(): PauseCall__Outputs { - return new PauseCall__Outputs(this); - } -} - -export class PauseCall__Inputs { - _call: PauseCall; - - constructor(call: PauseCall) { - this._call = call; - } -} - -export class PauseCall__Outputs { - _call: PauseCall; - - constructor(call: PauseCall) { - this._call = call; - } -} - -export class RenounceOwnershipCall extends ethereum.Call { - get inputs(): RenounceOwnershipCall__Inputs { - return new RenounceOwnershipCall__Inputs(this); - } - - get outputs(): RenounceOwnershipCall__Outputs { - return new RenounceOwnershipCall__Outputs(this); - } -} - -export class RenounceOwnershipCall__Inputs { - _call: RenounceOwnershipCall; - - constructor(call: RenounceOwnershipCall) { - this._call = call; - } -} - -export class RenounceOwnershipCall__Outputs { - _call: RenounceOwnershipCall; - - constructor(call: RenounceOwnershipCall) { - this._call = call; - } -} - -export class TransferOwnershipCall extends ethereum.Call { - get inputs(): TransferOwnershipCall__Inputs { - return new TransferOwnershipCall__Inputs(this); - } - - get outputs(): TransferOwnershipCall__Outputs { - return new TransferOwnershipCall__Outputs(this); - } -} - -export class TransferOwnershipCall__Inputs { - _call: TransferOwnershipCall; - - constructor(call: TransferOwnershipCall) { - this._call = call; - } - - get newOwner(): Address { - return this._call.inputValues[0].value.toAddress(); - } -} - -export class TransferOwnershipCall__Outputs { - _call: TransferOwnershipCall; - - constructor(call: TransferOwnershipCall) { - this._call = call; - } -} - -export class UnpauseCall extends ethereum.Call { - get inputs(): UnpauseCall__Inputs { - return new UnpauseCall__Inputs(this); - } - - get outputs(): UnpauseCall__Outputs { - return new UnpauseCall__Outputs(this); - } -} - -export class UnpauseCall__Inputs { - _call: UnpauseCall; - - constructor(call: UnpauseCall) { - this._call = call; - } -} - -export class UnpauseCall__Outputs { - _call: UnpauseCall; - - constructor(call: UnpauseCall) { - this._call = call; - } -} - -export class UpgradeToCall extends ethereum.Call { - get inputs(): UpgradeToCall__Inputs { - return new UpgradeToCall__Inputs(this); - } - - get outputs(): UpgradeToCall__Outputs { - return new UpgradeToCall__Outputs(this); - } -} - -export class UpgradeToCall__Inputs { - _call: UpgradeToCall; - - constructor(call: UpgradeToCall) { - this._call = call; - } - - get newImplementation(): Address { - return this._call.inputValues[0].value.toAddress(); - } -} - -export class UpgradeToCall__Outputs { - _call: UpgradeToCall; - - constructor(call: UpgradeToCall) { - this._call = call; - } -} - -export class UpgradeToAndCallCall extends ethereum.Call { - get inputs(): UpgradeToAndCallCall__Inputs { - return new UpgradeToAndCallCall__Inputs(this); - } - - get outputs(): UpgradeToAndCallCall__Outputs { - return new UpgradeToAndCallCall__Outputs(this); - } -} - -export class UpgradeToAndCallCall__Inputs { - _call: UpgradeToAndCallCall; - - constructor(call: UpgradeToAndCallCall) { - this._call = call; - } - - get newImplementation(): Address { - return this._call.inputValues[0].value.toAddress(); - } - - get data(): Bytes { - return this._call.inputValues[1].value.toBytes(); - } -} - -export class UpgradeToAndCallCall__Outputs { - _call: UpgradeToAndCallCall; - - constructor(call: UpgradeToAndCallCall) { - this._call = call; - } -} diff --git a/graph/networks.json b/graph/networks.json index 477c6127..28925338 100644 --- a/graph/networks.json +++ b/graph/networks.json @@ -9,10 +9,6 @@ "HypercertMinter": { "address": "0x822F17A9A5EeCFd66dBAFf7946a8071C265D1d07", "startBlock": 8537999 - }, - "HypercertTrader": { - "address": "0x689587461AA3103D3D7975c5e4B352Ab711C14C2", - "startBlock": 9638007 } }, "optimism": { diff --git a/graph/src/hypercert-trader.ts b/graph/src/hypercert-trader.ts deleted file mode 100644 index 5c06f969..00000000 --- a/graph/src/hypercert-trader.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { - OfferCancelled as OfferCancelledEvent, - OfferCreated as OfferCreatedEvent, - Trade as TradeEvent, -} from "../generated/HypercertTrader/HypercertTrader"; -import { Trade } from "../generated/schema"; -import { getOrCreateOffer, getOrCreateOfferByID } from "./utils"; -import { log, BigInt } from "@graphprotocol/graph-ts"; - -export function handleOfferCancelled(event: OfferCancelledEvent): void { - const offer = getOrCreateOfferByID( - event.params.hypercertContract, - event.params.fractionID, - event.params.offerID, - ); - - if (!offer) { - return; - } - - offer.status = "Cancelled"; - - offer.save(); -} - -export function handleOfferCreated(event: OfferCreatedEvent): void { - const offer = getOrCreateOffer( - event.params.hypercertContract, - event.address, - event.params.fractionID, - event.params.offerID, - ); - - offer.save(); -} - -export function handleTrade(event: TradeEvent): void { - const offer = getOrCreateOfferByID( - event.params.hypercertContract, - event.params.fractionID, - event.params.offerID, - ); - - if (!offer) { - log.error("Offer with ID {} not found", [ - event.params.offerID.toHexString(), - ]); - return; - } - - const tradeID = offer.id.concat(event.transaction.hash.toHexString()); - - let trade = Trade.load(tradeID); - - if (trade == null) { - trade = new Trade(tradeID); - - trade.buyer = event.params.buyer; - trade.offerID = offer.id; - trade.unitsSold = event.params.unitsBought; - trade.token = event.params.buyToken.toHexString(); - trade.amountPerUnit = event.params.tokenAmountPerUnit; - - trade.offerID = offer.id; - } - - offer.unitsAvailable = offer.unitsAvailable.minus(event.params.unitsBought); - if (offer.unitsAvailable.equals(BigInt.fromI32(0))) { - offer.status = "Fulfilled"; - } - - trade.save(); -} diff --git a/graph/src/utils.ts b/graph/src/utils.ts index 42b51fc5..2828cc15 100644 --- a/graph/src/utils.ts +++ b/graph/src/utils.ts @@ -1,5 +1,4 @@ import { HypercertMinter } from "../generated/HypercertMinter/HypercertMinter"; -import { HypercertTrader } from "../generated/HypercertTrader/HypercertTrader"; import { AcceptedToken, Allowlist, diff --git a/graph/subgraph.yaml b/graph/subgraph.yaml index 3c469f83..6b664dde 100644 --- a/graph/subgraph.yaml +++ b/graph/subgraph.yaml @@ -44,27 +44,3 @@ dataSources: - event: BatchValueTransfer(uint256[],uint256[],uint256[],uint256[]) handler: handleBatchValueTransfer file: ./src/hypercert-minter.ts - - kind: ethereum - name: HypercertTrader - network: goerli - source: - address: "0x689587461AA3103D3D7975c5e4B352Ab711C14C2" - abi: HypercertTrader - mapping: - kind: ethereum/events - apiVersion: 0.0.7 - language: wasm/assemblyscript - entities: - - Offer - abis: - - name: HypercertTrader - file: ./abis/HypercertTrader.json - eventHandlers: - - event: OfferCancelled(indexed address,indexed address,indexed uint256,uint256) - handler: handleOfferCancelled - - event: OfferCreated(indexed address,indexed address,indexed uint256,uint256) - handler: handleOfferCreated - - event: Trade(indexed address,indexed address,indexed - address,uint256,uint256,address,uint256,uint256) - handler: handleTrade - file: ./src/hypercert-trader.ts diff --git a/graph/tests/hypercert-trader-utils.ts b/graph/tests/hypercert-trader-utils.ts deleted file mode 100644 index 74ee37c1..00000000 --- a/graph/tests/hypercert-trader-utils.ts +++ /dev/null @@ -1,261 +0,0 @@ -import { - AdminChanged, - BeaconUpgraded, - Initialized, - OfferCancelled, - OfferCreated, - OwnershipTransferred, - Paused, - Trade, - Unpaused, - Upgraded, -} from "../generated/HypercertTrader/HypercertTrader"; -import { ethereum, Address, BigInt } from "@graphprotocol/graph-ts"; -import { newMockEvent } from "matchstick-as"; - -export const DEFAULT_TRADER_ADDRESS = Address.fromString( - "0x0000000000000000000000000000000000001337", -); - -export function createAdminChangedEvent( - previousAdmin: Address, - newAdmin: Address, -): AdminChanged { - let adminChangedEvent = changetype(newMockEvent()); - - adminChangedEvent.parameters = new Array(); - - adminChangedEvent.parameters.push( - new ethereum.EventParam( - "previousAdmin", - ethereum.Value.fromAddress(previousAdmin), - ), - ); - adminChangedEvent.parameters.push( - new ethereum.EventParam("newAdmin", ethereum.Value.fromAddress(newAdmin)), - ); - - return adminChangedEvent; -} - -export function createBeaconUpgradedEvent(beacon: Address): BeaconUpgraded { - let beaconUpgradedEvent = changetype(newMockEvent()); - - beaconUpgradedEvent.parameters = new Array(); - - beaconUpgradedEvent.parameters.push( - new ethereum.EventParam("beacon", ethereum.Value.fromAddress(beacon)), - ); - - return beaconUpgradedEvent; -} - -export function createInitializedEvent(version: i32): Initialized { - let initializedEvent = changetype(newMockEvent()); - - initializedEvent.parameters = new Array(); - - initializedEvent.parameters.push( - new ethereum.EventParam( - "version", - ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(version)), - ), - ); - - return initializedEvent; -} - -export function createOfferCancelledEvent( - creator: Address, - hypercertContract: Address, - fractionID: BigInt, - offerID: BigInt, -): OfferCancelled { - let offerCancelledEvent = changetype(newMockEvent()); - - offerCancelledEvent.parameters = new Array(); - - offerCancelledEvent.parameters.push( - new ethereum.EventParam("creator", ethereum.Value.fromAddress(creator)), - ); - offerCancelledEvent.parameters.push( - new ethereum.EventParam( - "hypercertContract", - ethereum.Value.fromAddress(hypercertContract), - ), - ); - offerCancelledEvent.parameters.push( - new ethereum.EventParam( - "fractionID", - ethereum.Value.fromUnsignedBigInt(fractionID), - ), - ); - offerCancelledEvent.parameters.push( - new ethereum.EventParam( - "offerID", - ethereum.Value.fromUnsignedBigInt(offerID), - ), - ); - - offerCancelledEvent.address = DEFAULT_TRADER_ADDRESS; - - return offerCancelledEvent; -} - -export function createOfferCreatedEvent( - offerer: Address, - hypercertContract: Address, - fractionID: BigInt, - offerID: BigInt, -): OfferCreated { - let offerCreatedEvent = changetype(newMockEvent()); - - offerCreatedEvent.parameters = new Array(); - - offerCreatedEvent.parameters.push( - new ethereum.EventParam("offerer", ethereum.Value.fromAddress(offerer)), - ); - offerCreatedEvent.parameters.push( - new ethereum.EventParam( - "hypercertContract", - ethereum.Value.fromAddress(hypercertContract), - ), - ); - offerCreatedEvent.parameters.push( - new ethereum.EventParam( - "fractionID", - ethereum.Value.fromUnsignedBigInt(fractionID), - ), - ); - offerCreatedEvent.parameters.push( - new ethereum.EventParam( - "offerID", - ethereum.Value.fromUnsignedBigInt(offerID), - ), - ); - - offerCreatedEvent.address = DEFAULT_TRADER_ADDRESS; - - return offerCreatedEvent; -} - -export function createOwnershipTransferredEvent( - previousOwner: Address, - newOwner: Address, -): OwnershipTransferred { - let ownershipTransferredEvent = changetype( - newMockEvent(), - ); - - ownershipTransferredEvent.parameters = new Array(); - - ownershipTransferredEvent.parameters.push( - new ethereum.EventParam( - "previousOwner", - ethereum.Value.fromAddress(previousOwner), - ), - ); - ownershipTransferredEvent.parameters.push( - new ethereum.EventParam("newOwner", ethereum.Value.fromAddress(newOwner)), - ); - - return ownershipTransferredEvent; -} - -export function createPausedEvent(account: Address): Paused { - let pausedEvent = changetype(newMockEvent()); - - pausedEvent.parameters = new Array(); - - pausedEvent.parameters.push( - new ethereum.EventParam("account", ethereum.Value.fromAddress(account)), - ); - - return pausedEvent; -} - -export function createTradeEvent( - seller: Address, - buyer: Address, - hypercertContract: Address, - fractionID: BigInt, - unitsBought: BigInt, - buyToken: Address, - tokenAmountPerUnit: BigInt, - offerID: BigInt, -): Trade { - let tradeEvent = changetype(newMockEvent()); - - tradeEvent.parameters = new Array(); - - tradeEvent.parameters.push( - new ethereum.EventParam("seller", ethereum.Value.fromAddress(seller)), - ); - tradeEvent.parameters.push( - new ethereum.EventParam("buyer", ethereum.Value.fromAddress(buyer)), - ); - tradeEvent.parameters.push( - new ethereum.EventParam( - "hypercertContract", - ethereum.Value.fromAddress(hypercertContract), - ), - ); - tradeEvent.parameters.push( - new ethereum.EventParam( - "fractionID", - ethereum.Value.fromUnsignedBigInt(fractionID), - ), - ); - tradeEvent.parameters.push( - new ethereum.EventParam( - "unitsBought", - ethereum.Value.fromUnsignedBigInt(unitsBought), - ), - ); - tradeEvent.parameters.push( - new ethereum.EventParam("buyToken", ethereum.Value.fromAddress(buyToken)), - ); - tradeEvent.parameters.push( - new ethereum.EventParam( - "tokenAmountPerUnit", - ethereum.Value.fromUnsignedBigInt(tokenAmountPerUnit), - ), - ); - tradeEvent.parameters.push( - new ethereum.EventParam( - "offerID", - ethereum.Value.fromUnsignedBigInt(offerID), - ), - ); - - tradeEvent.address = DEFAULT_TRADER_ADDRESS; - - return tradeEvent; -} - -export function createUnpausedEvent(account: Address): Unpaused { - let unpausedEvent = changetype(newMockEvent()); - - unpausedEvent.parameters = new Array(); - - unpausedEvent.parameters.push( - new ethereum.EventParam("account", ethereum.Value.fromAddress(account)), - ); - - return unpausedEvent; -} - -export function createUpgradedEvent(implementation: Address): Upgraded { - let upgradedEvent = changetype(newMockEvent()); - - upgradedEvent.parameters = new Array(); - - upgradedEvent.parameters.push( - new ethereum.EventParam( - "implementation", - ethereum.Value.fromAddress(implementation), - ), - ); - - return upgradedEvent; -} diff --git a/graph/tests/hypercert-trader.test.ts b/graph/tests/hypercert-trader.test.ts deleted file mode 100644 index 51230b74..00000000 --- a/graph/tests/hypercert-trader.test.ts +++ /dev/null @@ -1,80 +0,0 @@ -import { handleOfferCreated } from "../src/hypercert-trader"; -import { ZERO_ADDRESS } from "../src/utils"; -import { - DEFAULT_TRADER_ADDRESS, - createOfferCreatedEvent, -} from "./hypercert-trader-utils"; -import { Address, BigInt, Bytes, ethereum } from "@graphprotocol/graph-ts"; -import { - assert, - describe, - test, - clearStore, - beforeAll, - afterAll, - createMockedFunction, -} from "matchstick-as/assembly/index"; - -// Tests structure (matchstick-as >=0.5.0) -// https://thegraph.com/docs/en/developer/matchstick/#tests-structure-0-5-0 - -describe("Describe entity assertions", () => { - beforeAll(() => { - let acceptedToken: Array = [ - ethereum.Value.fromAddress( - Address.fromString("0x89205A3A3b2A69De6Dbf7f01ED13B2108B2c43e7"), - ), - ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(1)), - ]; - - let tuple = changetype(acceptedToken); - let tupleValue = ethereum.Value.fromTupleArray([tuple]); - - const returnValues = [ - ethereum.Value.fromAddress( - Address.fromString("0x0000000000000000000000000000000000000003"), - ), - ethereum.Value.fromAddress( - Address.fromString("0x0000000000000000000000000000000000000004"), - ), - ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(1)), - ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(1)), - ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(1)), - ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(1)), - ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(1)), - ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(1)), - ethereum.Value.fromTupleArray([tuple]), - ]; - - let returnValueTuple = changetype(returnValues); - let returnValue = ethereum.Value.fromTuple(returnValueTuple); - - createMockedFunction( - DEFAULT_TRADER_ADDRESS, - "getOffer", - "getOffer(uint256):((address,address,uint256,uint256,uint256,uint256,uint8,uint8,(address,uint256)[]))", - ) - .withArgs([ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(1))]) - .returns([returnValue]); - }); - - afterAll(() => { - clearStore(); - }); - - test("Offer created and stored", () => { - assert.entityCount("Offer", 0); - - // Create an OfferCreated event - let offerCreatedEvent = createOfferCreatedEvent( - Address.fromString("0x0000000000000000000000000000000000000001"), - Address.fromString("0x0000000000000000000000000000000000000002"), - BigInt.fromI32(1), - BigInt.fromI32(1), - ); - - handleOfferCreated(offerCreatedEvent); - - assert.entityCount("Offer", 1); - }); -});