Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: statusUpdateAt field created [SF-948] #68

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Order @entity {
inputAmount: BigInt!
filledAmount: BigInt!
status: OrderStatus!
statusUpdatedAt: BigInt!
lendingMarket: LendingMarket!
isPreOrder: Boolean!
type: OrderType!
Expand Down
2 changes: 1 addition & 1 deletion scripts/copy-abis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down
1 change: 1 addition & 0 deletions src/fund-management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
7 changes: 4 additions & 3 deletions src/helper/initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions src/lending-market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -260,6 +261,7 @@ export function handleOrdersCleaned(event: OrdersCleaned): void {
);
order.filledAmount = order.inputAmount;
order.status = 'Filled';
order.statusUpdatedAt = event.block.timestamp;
order.save();
}
}
Expand Down
2 changes: 1 addition & 1 deletion subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions test/lending-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -55,6 +56,7 @@ describe('With no lending markets existing', () => {
ethBytes,
orderBookId,
openingDate,
preOpeningDate,
maturity
);
handleOrderBookCreated(event);
Expand All @@ -80,6 +82,7 @@ describe('With no lending markets existing', () => {
ethBytes,
orderBookId,
openingDate,
preOpeningDate,
maturity
);
handleOrderBookCreated(event);
Expand All @@ -106,6 +109,7 @@ describe('With lending markets already existing', () => {
filBytes,
BigInt.fromI32(i + 1),
openingDate,
preOpeningDate,
maturity
)
);
Expand All @@ -114,6 +118,7 @@ describe('With lending markets already existing', () => {
ethBytes,
BigInt.fromI32(i + 1),
openingDate,
preOpeningDate,
maturity
)
);
Expand Down
7 changes: 7 additions & 0 deletions test/mocks/lending-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export function createOrderBookCreatedEvent(
ccy: Bytes,
orderBookId: BigInt,
openingDate: BigInt,
preOpeningDate: BigInt,
maturity: BigInt
): OrderBookCreated {
const mockEvent = changetype<OrderBookCreated>(newMockEvent());
Expand Down Expand Up @@ -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',
Expand Down