diff --git a/package-lock.json b/package-lock.json index 1d65396..c791ca2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "devDependencies": { "@graphprotocol/graph-cli": "0.62.0", "@graphprotocol/graph-ts": "0.31.0", - "@secured-finance/smart-contracts": "0.1.11-beta.0", + "@secured-finance/contracts": "0.2.0-beta.2", "@types/js-yaml": "4.0.5", "@types/node": "16.18.67", "js-yaml": "4.1.0", @@ -1606,12 +1606,12 @@ "integrity": "sha512-zGzFsgtZ44mgL4Xef2gOy1hrRVdrs9mcxCOOKZrIPsmbZW14yTkaF591GXxpQvjXiHtgZ/iA9qLyWH6oSReIxQ==", "dev": true }, - "node_modules/@secured-finance/smart-contracts": { - "version": "0.1.11-beta.0", - "resolved": "https://npm.pkg.github.com/download/@Secured-Finance/smart-contracts/0.1.11-beta.0/9726d26539419fe5b3be9a88c383facd57e9240c", - "integrity": "sha512-XQkk+Xn98vcqjPt1J/VLs5hTc2BbNCWaeftUxGNBe9jjVdYAUemONROU/X7U7Pv9rZ0tNYfbQwCchlno/PpMrg==", + "node_modules/@secured-finance/contracts": { + "version": "0.2.0-beta.2", + "resolved": "https://npm.pkg.github.com/download/@secured-finance/contracts/0.2.0-beta.2/411870d86a7809947334043c2fb0f938c48d84ee", + "integrity": "sha512-Laj+3fFNHH/ellUy6UN482R3XGZb5wAdwLallfbZp31Qvd3RLGlee0n56kPax6hAkdYRwL1RccP4fjcRDF6cxA==", "dev": true, - "license": "ISC", + "license": "BUSL-1.1", "dependencies": { "@chainlink/contracts": "^0.4.0", "@openzeppelin/contracts": "^4.7.3", diff --git a/package.json b/package.json index e91f182..a8a7849 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "devDependencies": { "@graphprotocol/graph-cli": "0.62.0", "@graphprotocol/graph-ts": "0.31.0", - "@secured-finance/smart-contracts": "0.1.11-beta.0", + "@secured-finance/contracts": "0.2.0-beta.2", "@types/js-yaml": "4.0.5", "@types/node": "16.18.67", "js-yaml": "4.1.0", diff --git a/schema.graphql b/schema.graphql index f577a08..122e604 100644 --- a/schema.graphql +++ b/schema.graphql @@ -30,6 +30,7 @@ type Order @entity { inputAmount: BigInt! filledAmount: BigInt! status: OrderStatus! + statusUpdatedAt: BigInt! lendingMarket: LendingMarket! isPreOrder: Boolean! type: OrderType! diff --git a/scripts/copy-abis.ts b/scripts/copy-abis.ts index f5cac4c..20a7b11 100644 --- a/scripts/copy-abis.ts +++ b/scripts/copy-abis.ts @@ -4,7 +4,7 @@ class Main { run() { const rootDir = process.cwd(); const modulePath = require - .resolve('@secured-finance/smart-contracts/package.json') + .resolve('@secured-finance/contracts/package.json') .replace('/package.json', ''); const abiDir = `${rootDir}/abis`; diff --git a/src/fund-management.ts b/src/fund-management.ts index 9ef47e7..823305e 100644 --- a/src/fund-management.ts +++ b/src/fund-management.ts @@ -14,6 +14,7 @@ export function handleOrderPartiallyFilled(event: OrderPartiallyFilled): void { if (order) { order.filledAmount = order.filledAmount.plus(event.params.amount); order.status = 'PartiallyFilled'; + order.statusUpdatedAt = event.block.timestamp; order.save(); const txId = diff --git a/src/helper/initializer.ts b/src/helper/initializer.ts index 69ea77d..b5f4d83 100644 --- a/src/helper/initializer.ts +++ b/src/helper/initializer.ts @@ -112,12 +112,12 @@ export const initOrder = ( status: string, isPreOrder: boolean, type: string, - createdAt: BigInt, + timestamp: BigInt, blockNumber: BigInt, txHash: Bytes ): void => { const order = new Order(id); - const user = getOrInitUser(maker, createdAt); + const user = getOrInitUser(maker, timestamp); order.orderId = orderId; order.maker = user.id; @@ -128,10 +128,11 @@ export const initOrder = ( order.filledAmount = filledAmount; order.inputAmount = inputAmount; order.status = status; + order.statusUpdatedAt = timestamp; order.lendingMarket = getOrInitLendingMarket(currency, maturity).id; order.isPreOrder = isPreOrder; order.type = type; - order.createdAt = createdAt; + order.createdAt = timestamp; order.blockNumber = blockNumber; order.txHash = txHash; order.save(); diff --git a/src/lending-market.ts b/src/lending-market.ts index 25f9373..17ade61 100644 --- a/src/lending-market.ts +++ b/src/lending-market.ts @@ -205,6 +205,7 @@ export function handleOrderCanceled(event: OrderCanceled): void { const order = Order.load(id); if (order) { order.status = 'Cancelled'; + order.statusUpdatedAt = event.block.timestamp; order.save(); } } @@ -260,6 +261,7 @@ export function handleOrdersCleaned(event: OrdersCleaned): void { ); order.filledAmount = order.inputAmount; order.status = 'Filled'; + order.statusUpdatedAt = event.block.timestamp; order.save(); } } diff --git a/subgraph.yaml b/subgraph.yaml index ba83e27..bd331be 100644 --- a/subgraph.yaml +++ b/subgraph.yaml @@ -20,7 +20,7 @@ dataSources: eventHandlers: - event: LendingMarketInitialized(indexed bytes32,uint256,uint256,uint256,uint256,address,address) handler: handleLendingMarketInitialized - - event: OrderBookCreated(indexed bytes32,indexed uint8,uint256,uint256) + - event: OrderBookCreated(indexed bytes32,indexed uint8,uint256,uint256,uint256) handler: handleOrderBookCreated - event: OrderBooksRotated(bytes32,uint256,uint256) handler: handleOrderBooksRotated diff --git a/test/lending-controller.test.ts b/test/lending-controller.test.ts index 1d287b8..52b5a00 100644 --- a/test/lending-controller.test.ts +++ b/test/lending-controller.test.ts @@ -21,6 +21,7 @@ import { const orderBookId = BigInt.fromI32(1); const openingDate = BigInt.fromI32(12345); +const preOpeningDate = BigInt.fromI32(1234); const maturity = BigInt.fromI32(365); afterEach(() => { @@ -55,6 +56,7 @@ describe('With no lending markets existing', () => { ethBytes, orderBookId, openingDate, + preOpeningDate, maturity ); handleOrderBookCreated(event); @@ -80,6 +82,7 @@ describe('With no lending markets existing', () => { ethBytes, orderBookId, openingDate, + preOpeningDate, maturity ); handleOrderBookCreated(event); @@ -106,6 +109,7 @@ describe('With lending markets already existing', () => { filBytes, BigInt.fromI32(i + 1), openingDate, + preOpeningDate, maturity ) ); @@ -114,6 +118,7 @@ describe('With lending markets already existing', () => { ethBytes, BigInt.fromI32(i + 1), openingDate, + preOpeningDate, maturity ) ); diff --git a/test/mocks/lending-controller.ts b/test/mocks/lending-controller.ts index dc4e4a6..6d8f455 100644 --- a/test/mocks/lending-controller.ts +++ b/test/mocks/lending-controller.ts @@ -9,6 +9,7 @@ export function createOrderBookCreatedEvent( ccy: Bytes, orderBookId: BigInt, openingDate: BigInt, + preOpeningDate: BigInt, maturity: BigInt ): OrderBookCreated { const mockEvent = changetype(newMockEvent()); @@ -39,6 +40,12 @@ export function createOrderBookCreatedEvent( ethereum.Value.fromUnsignedBigInt(openingDate) ) ); + event.parameters.push( + new ethereum.EventParam( + 'preOpeningDate', + ethereum.Value.fromUnsignedBigInt(preOpeningDate) + ) + ); event.parameters.push( new ethereum.EventParam( 'maturity',