Skip to content

Commit

Permalink
Update schema
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKim20 committed Sep 22, 2023
1 parent 9f7aa19 commit 1a60f0c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/subgraph/generated/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1651,6 +1651,19 @@ export class UserTradeHistory extends Entity {
this.set("action", Value.fromString(value));
}

get assetFlow(): string {
let value = this.get("assetFlow");
if (!value || value.kind == ValueKind.NULL) {
throw new Error("Cannot return null for a required field.");
} else {
return value.toString();
}
}

set assetFlow(value: string) {
this.set("assetFlow", Value.fromString(value));
}

get amountMileage(): BigInt {
let value = this.get("amountMileage");
if (!value || value.kind == ValueKind.NULL) {
Expand Down
9 changes: 9 additions & 0 deletions packages/subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,19 @@ enum UserAction {
ClearedMileage
}

enum AssetFlow {
MileageInput,
MileageOutput,
TokenInput,
TokenOutput,
None
}

type UserTradeHistory @entity(immutable: true) {
id: Bytes!
email: Bytes!
action: UserAction!
assetFlow: AssetFlow!
amountMileage: BigInt!
amountToken: BigInt!
value: BigInt!
Expand Down
9 changes: 9 additions & 0 deletions packages/subgraph/src/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ export function handleProvidedMileageForHistory(event: ProvidedMileageEvent): vo
let entity = new UserTradeHistory(event.transaction.hash.concatI32(event.logIndex.toI32()));
entity.email = event.params.email;
entity.action = "ProvidedMileage";
entity.assetFlow = "MileageInput";
entity.amountMileage = event.params.providedAmountMileage;
entity.amountToken = BigInt.fromI32(0);
entity.value = event.params.value.div(AmountUnit);
Expand All @@ -290,6 +291,7 @@ export function handleProvidedMileageToFranchiseeForHistory(event: ProvidedMilea
let entity = new UserTradeHistory(event.transaction.hash.concatI32(event.logIndex.toI32()));
entity.email = event.params.email;
entity.action = "ClearedMileage";
entity.assetFlow = "MileageInput";
entity.amountMileage = event.params.providedAmountMileage.div(AmountUnit);
entity.amountToken = BigInt.fromI32(0);
entity.value = event.params.value.div(AmountUnit);
Expand All @@ -315,6 +317,7 @@ export function handleProvidedTokenForHistory(event: ProvidedTokenEvent): void {
let entity = new UserTradeHistory(event.transaction.hash.concatI32(event.logIndex.toI32()));
entity.email = event.params.email;
entity.action = "ProvidedToken";
entity.assetFlow = "TokenInput";
entity.amountMileage = BigInt.fromI32(0);
entity.amountToken = event.params.providedAmountToken.div(AmountUnit);
entity.value = event.params.value.div(AmountUnit);
Expand All @@ -341,6 +344,7 @@ export function handlePaidMileageForHistory(event: PaidMileageEvent): void {
let entity = new UserTradeHistory(event.transaction.hash.concatI32(event.logIndex.toI32()));
entity.email = event.params.email;
entity.action = "PaidMileage";
entity.assetFlow = "MileageOutput";
entity.amountMileage = event.params.paidAmountMileage.div(AmountUnit);
entity.amountToken = BigInt.fromI32(0);
entity.value = event.params.value.div(AmountUnit);
Expand All @@ -367,6 +371,7 @@ export function handlePaidTokenForHistory(event: PaidTokenEvent): void {
let entity = new UserTradeHistory(event.transaction.hash.concatI32(event.logIndex.toI32()));
entity.email = event.params.email;
entity.action = "PaidToken";
entity.assetFlow = "TokenOutput";
entity.amountMileage = BigInt.fromI32(0);
entity.amountToken = event.params.paidAmountToken.div(AmountUnit);
entity.value = event.params.value.div(AmountUnit);
Expand All @@ -393,6 +398,7 @@ export function handleDepositedForHistory(event: DepositedEvent): void {
let entity = new UserTradeHistory(event.transaction.hash.concatI32(event.logIndex.toI32()));
entity.email = event.params.email;
entity.action = "DepositedToken";
entity.assetFlow = "TokenInput";
entity.amountMileage = BigInt.fromI32(0);
entity.amountToken = event.params.depositAmount.div(AmountUnit);
entity.value = event.params.value.div(AmountUnit);
Expand All @@ -419,6 +425,7 @@ export function handleWithdrawnForHistory(event: WithdrawnEvent): void {
let entity = new UserTradeHistory(event.transaction.hash.concatI32(event.logIndex.toI32()));
entity.email = event.params.email;
entity.action = "WithdrawnToken";
entity.assetFlow = "TokenOutput";
entity.amountMileage = BigInt.fromI32(0);
entity.amountToken = event.params.withdrawAmount.div(AmountUnit);
entity.value = event.params.value.div(AmountUnit);
Expand All @@ -438,6 +445,7 @@ export function handleExchangedMileageToTokenForHistory(event: ExchangedMileageT
let entity = new UserTradeHistory(event.transaction.hash.concatI32(event.logIndex.toI32()));
entity.email = event.params.email;
entity.action = "ExchangedMileageToToken";
entity.assetFlow = "None";
entity.amountMileage = event.params.amountMileage.div(AmountUnit);
entity.amountToken = event.params.amountToken.div(AmountUnit);
entity.value = event.params.amountMileage.div(AmountUnit);
Expand Down Expand Up @@ -473,6 +481,7 @@ export function handleExchangedTokenToMileageForHistory(event: ExchangedTokenToM
let entity = new UserTradeHistory(event.transaction.hash.concatI32(event.logIndex.toI32()));
entity.email = event.params.email;
entity.action = "ExchangedTokenToMileage";
entity.assetFlow = "None";
entity.amountMileage = event.params.amountMileage.div(AmountUnit);
entity.amountToken = event.params.amountToken.div(AmountUnit);
entity.value = event.params.amountMileage.div(AmountUnit);
Expand Down

0 comments on commit 1a60f0c

Please sign in to comment.