Skip to content

Commit

Permalink
secondary orderbook for pretrades data
Browse files Browse the repository at this point in the history
  • Loading branch information
kallolborah committed Aug 19, 2024
1 parent 9226f62 commit 58ac3a6
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions manifest.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2483,8 +2483,8 @@ templates:
# file: ./abis/WeightedPool.json
- name: SecondaryIssuePool
file: ./abis/SecondaryIssuePool.json
#- name: Orderbook
# file: ./abis/Orderbook.json
- name: Orderbook
file: ./abis/Orderbook.json
eventHandlers:
- event: Transfer(indexed address,indexed address,uint256)
handler: handleTransfer
Expand Down
10 changes: 5 additions & 5 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,11 @@ type Pool @entity {

# SecondaryPool and OffchainSecondariesPool only
minOrderSize: BigInt
orderBook: Bytes
orderBook: Orderbook
#orderBook: Bytes
issueManager: Bytes
secondaryTrades: [SecondaryTrades!] @derivedFrom(field: "pool")
# secondaryPreTrades: [SecondaryPreTrades!] @derivedFrom(field: "pool")
#secondaryPreTrades: [SecondaryPreTrades!] @derivedFrom(field: "pool")
orders: [SecondaryOrders!]@derivedFrom(field: "pool")

# MarginTradingPool only
Expand Down Expand Up @@ -201,17 +202,16 @@ type SecondaryOrders @entity {
priceOffered: BigDecimal!
timestamp: BigInt
orderReference: Bytes!
orderbook: Orderbook!
}

type Orderbook @entity {
id: ID!
preTrades: [SecondaryPreTrades!]! @derivedFrom(field: "orderbook")
secondaryPreTrades: [SecondaryPreTrades!]! @derivedFrom(field: "orderbook")
}

type SecondaryPreTrades @entity {
id: ID!
pool: Pool!
pool: Pool
party: User
counterparty: User
executionDate: BigInt!
Expand Down
4 changes: 2 additions & 2 deletions src/mappings/helpers/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ export function loadSecondaryTrades(poolId: string, tokenAddress: Address): Seco
return SecondaryTrades.load(getPoolTokenId(poolId, tokenAddress));
}

export function loadSecondaryPreTrades(poolId: string, tokenAddress: Address): SecondaryPreTrades | null {
return SecondaryPreTrades.load(getPoolTokenId(poolId, tokenAddress));
export function loadSecondaryPreTrades(orderBook: string, tokenAddress: Address): SecondaryPreTrades | null {
return SecondaryPreTrades.load(getPoolTokenId(orderBook, tokenAddress));
}

export function loadSecondaryOrders(poolId: string, tokenAddress: Address): SecondaryOrders | null {
Expand Down
26 changes: 13 additions & 13 deletions src/mappings/poolController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ export function handleSubscription(event: Subscription): void {

pool.security = event.params.security;
pool.currency = event.params.currency;
pool.orderBook = event.params.orderBook;
pool.orderBook = event.params.orderBook.toHexString();
pool.minOrderSize = event.params.minOrderSize;
pool.issueManager = event.params.issueManager;

Expand Down Expand Up @@ -620,28 +620,28 @@ export function handleOrderBook(event: OrderBook): void {
}

export function handlePreTrades(event: tradeExecuted): void {
let poolAddress = event.params.pool;
let orderBook = event.address;

let poolContract = SecondaryIssuePool.bind(poolAddress);
let poolIdCall = poolContract.try_getPoolId();
let poolId = poolIdCall.value;
//let poolContract = SecondaryIssuePool.bind(poolAddress);
//let poolIdCall = poolContract.try_getPoolId();
//let poolId = poolIdCall.value;

let pretrades = loadSecondaryPreTrades(event.transaction.hash.toHexString(), event.params.pool);
let pretrades = loadSecondaryPreTrades(event.transaction.hash.toHexString(), orderBook);
if (pretrades == null) {
let providerId = getPoolTokenId(event.transaction.hash.toHexString(), event.params.pool);
let providerId = getPoolTokenId(event.transaction.hash.toHexString(), orderBook);
let pretrades = new SecondaryPreTrades(providerId);
pretrades.pool = poolId.toHexString();
pretrades.pool = event.params.pool.toHexString();
pretrades.executionDate = event.params.tradeToReportDate;
pretrades.party = event.params.party.toHexString();
pretrades.counterparty = event.params.counterparty.toHexString();
pretrades.save();
}
else{
/*else{
pretrades.executionDate = event.params.tradeToReportDate;
pretrades.party = event.params.party.toHexString();
pretrades.counterparty = event.params.counterparty.toHexString();
pretrades.save();
}
}*/
}

export function handleTradeReport(event: TradeReport): void {
Expand Down Expand Up @@ -683,7 +683,7 @@ export function handleTradeReport(event: TradeReport): void {
/************************************
*******OFFCHAIN SECONDARY***********
************************************/

/*
export function handleOffchainSecondaryOffer(event: Offer): void {
let poolAddress = event.address;
Expand Down Expand Up @@ -770,7 +770,7 @@ export function handleOffchainTradeReport(event: TradeReport): void {
}
}

*/
/************************************
*************MARGIN POOL************
************************************/
Expand All @@ -790,7 +790,7 @@ export function handleOffchainTradeReport(event: TradeReport): void {
pool.margin = event.params.margin;
pool.collateral = event.params.collateral;
pool.cficode = event.params.CfiCode;
pool.orderBook = event.params.orderBook;
pool.orderBook = event.params.orderBook.toHexString();
pool.minOrderSize = event.params.minOrderSize;
pool.issueManager = event.params.issueManager;

Expand Down
6 changes: 3 additions & 3 deletions src/mappings/poolFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ export function handleNewSecondaryPool(event: PoolCreated): void {
pool.owner = balancerManager;
pool.principalToken = security;
pool.baseToken = currency;
pool.orderBook = orderBook;
//pool.orderBook = orderBook;

let tokens = getPoolTokens(poolId);
if (tokens == null) return;
Expand Down Expand Up @@ -456,7 +456,7 @@ export function handleNewMarginPool(event: PoolCreated): void {
pool.margin = margin;
pool.collateral = collateral;
pool.baseToken = currency;
pool.orderBook = orderBook;
//pool.orderBook = orderBook;

let tokens = getPoolTokens(poolId);
if (tokens == null) return;
Expand Down Expand Up @@ -498,7 +498,7 @@ export function handleNewOffchainSecondaryPool(event: PoolCreated): void {
pool.owner = balancerManager;
pool.principalToken = security;
pool.baseToken = currency;
pool.orderBook = orderBook;
//pool.orderBook = orderBook;

let tokens = getPoolTokens(poolId);
if (tokens == null) return;
Expand Down
4 changes: 2 additions & 2 deletions subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1025,8 +1025,8 @@ templates:
# file: ./abis/WeightedPool.json
- name: SecondaryIssuePool
file: ./abis/SecondaryIssuePool.json
#- name: Orderbook
# file: ./abis/Orderbook.json
- name: Orderbook
file: ./abis/Orderbook.json
eventHandlers:
- event: Transfer(indexed address,indexed address,uint256)
handler: handleTransfer
Expand Down

0 comments on commit 58ac3a6

Please sign in to comment.