diff --git a/src/mappings/utils/orderUtils.ts b/src/mappings/utils/orderUtils.ts new file mode 100644 index 0000000..497833d --- /dev/null +++ b/src/mappings/utils/orderUtils.ts @@ -0,0 +1,27 @@ +import { Order } from '../../@types/schema' + +export function getOrderId( + tx: string, + tokenAddress: string, + fromAddress: string +): string { + return `${tx}-${tokenAddress}-${fromAddress}` +} + +export function createOrder(orderId: string): Order { + const order = new Order(orderId) + return order +} + +export function getOrder( + transactionHash: string, + address: string, + transactionFrom: string +): Order { + const orderId = getOrderId(transactionHash, address, transactionFrom) + let newOrder = Order.load(orderId) + if (newOrder === null) { + newOrder = createOrder(orderId) + } + return newOrder +}