Skip to content
Open
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
24 changes: 19 additions & 5 deletions packages/subgraph/src/sale/v2.1/saleMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function handleSetPaymentTokenInfo(event: SetPaymentTokenInfo): void {
}

const paymentMethod = getOrCreateTokenPaymentMethod(
event.params.token,
event.params.token,
event.params.paymentTokenInfo.decimals,
event.params.paymentTokenInfo.oracle,
event.block
Expand Down Expand Up @@ -109,7 +109,7 @@ export function handleBuy(event: Buy): void {

// The buy event uses token == address(0) to signify a native purchase
let paymentMethod: PaymentMethod;
const isNative = event.params.token.toHexString() == '0x0000000000000000000000000000000000000000'
const isNative = event.params.token.toHexString() == '0x0000000000000000000000000000000000000000'
if (isNative) {
// native payment
const nativeOracle = saleContract.nativeTokenPriceOracle();
Expand Down Expand Up @@ -139,7 +139,7 @@ export function handleBuy(event: Buy): void {
// fallback for 0 value transactions
price = BigInt.fromI32(0);
}

// Create a new purchase
const id = event.transaction.hash.toHexString() + "-" + event.logIndex.toString();
let purchase = new Purchase(id);
Expand All @@ -159,6 +159,9 @@ export function handleBuy(event: Buy): void {
// update the sale metrics
sale.purchaseTotal = sale.purchaseTotal.plus(purchase.baseCurrencyValue);
sale.purchaseCount = sale.purchaseCount.plus(BigInt.fromI32(1));
if (isNative) {
sale.escrowNativeBalance = sale.escrowNativeBalance.plus(purchase.spent);
}
sale.save();

// update the payment method metrics
Expand All @@ -179,11 +182,22 @@ export function handleBuy(event: Buy): void {
}

export function handleSweepToken(event: SweepToken): void {
// TODO: handle sweeps
// TODO: handle sweeps
}

export function handleSweepNative(event: SweepNative): void {
// TODO: handle sweeps
// TODO: handle sweeps
const saleId = event.address.toHexString();
const sale = Sale.load(saleId);
if (!sale) {
log.error('missing sale {}', [saleId]);

return;
// throw new Error('no sale to update: ' + saleId);
}

sale.escrowNativeBalance = sale.escrowNativeBalance.minus(event.params.amount);
sale.save();
}

export function handleRegisterDistributor(event: RegisterDistributor): void {
Expand Down
3 changes: 3 additions & 0 deletions packages/subgraph/src/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ type Sale @entity {
purchases: [Purchase!] @derivedFrom(field: "sale")
maxQueueTime: BigInt!
uris: [String!]!
escrowNativeBalance: BigInt!



# payment info
baseCurrency: String!
Expand Down