From 0f124d01dd0679636a4156ccc59a58215426884f Mon Sep 17 00:00:00 2001 From: Jamie Hewitt Date: Mon, 4 Jul 2022 11:49:24 +0100 Subject: [PATCH] Updating or Creating OrderResue provider fee --- schema.graphql | 1 + src/mappings/erc20Templates.ts | 26 ++++++++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/schema.graphql b/schema.graphql index 36fe1f2..f992a32 100644 --- a/schema.graphql +++ b/schema.graphql @@ -249,6 +249,7 @@ type OrderReuse @entity { createdTimestamp: BigInt! tx: String! block: BigInt! + providerFee: String } type Order @entity { "transaction hash - token address - from address" diff --git a/src/mappings/erc20Templates.ts b/src/mappings/erc20Templates.ts index c098229..3ba5e99 100644 --- a/src/mappings/erc20Templates.ts +++ b/src/mappings/erc20Templates.ts @@ -199,12 +199,6 @@ export function handleNewPaymentCollector(event: NewPaymentCollector): void { } export function handleProviderFee(event: ProviderFee): void { - const order = getOrder( - event.transaction.hash.toHex(), - event.address.toHex(), - event.transaction.from.toHex() - ) - const providerFee: string = `{providerFeeAddress: ${event.params.providerFeeAddress.toHex()}, providerFeeToken: ${event.params.providerFeeToken.toHex()}, providerFeeAmount: ${ event.params.providerFeeAmount }, providerData: ${event.params.providerData.toHexString()}, v: ${ @@ -214,8 +208,24 @@ export function handleProviderFee(event: ProviderFee): void { } }` - order.providerFee = providerFee - order.save() + const orderId = getOrderId( + event.transaction.hash.toHex(), + event.address.toHex(), + event.transaction.from.toHex() + ) + const order = Order.load(orderId) + let orderReuse = OrderReuse.load(event.transaction.hash.toHex()) + if (order) { + order.providerFee = providerFee + order.save() + } else if (orderReuse) { + orderReuse.providerFee = providerFee + orderReuse.save() + } else { + orderReuse = new OrderReuse(event.transaction.hash.toHex()) + orderReuse.providerFee = providerFee + orderReuse.save() + } } // export function handlePublishMarketFees(event: PublishMarketFees): void {