Skip to content

Commit

Permalink
fix market data node bug and system program transfer filter for helius (
Browse files Browse the repository at this point in the history
  • Loading branch information
callensm authored Jun 30, 2023
1 parent e31753a commit b190fb8
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ export type CoinGeckoPriceData = {
market_cap_rank: number;
fully_filuted_valuation: number;
total_volume: number;
high_24h: number;
low_24h: number;
price_change_24h: number;
price_change_percentage_24h: number;
market_cap_change_24h: number;
market_cap_change_percentage_24h: number;
high_24h: number | null;
low_24h: number | null;
price_change_24h: number | null;
price_change_percentage_24h: number | null;
market_cap_change_24h: number | null;
market_cap_change_percentage_24h: number | null;
circulating_supply: number;
total_supply: number;
max_supply: number | null;
Expand Down
24 changes: 18 additions & 6 deletions backend/native/backpack-api/src/routes/graphql/clients/helius.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { RESTDataSource } from "@apollo/datasource-rest";
import { getATAAddressSync } from "@saberhq/token-utils";
import type { AccountInfo } from "@solana/web3.js";
import { PublicKey } from "@solana/web3.js";
import type { EnrichedTransaction } from "helius-sdk";
import { PublicKey, SystemProgram } from "@solana/web3.js";
import { type EnrichedTransaction, Source, TransactionType } from "helius-sdk";
import { LRUCache } from "lru-cache";

export const IN_MEM_SOL_COLLECTION_DATA_CACHE = new LRUCache<
Expand Down Expand Up @@ -104,12 +104,18 @@ export class Helius extends RESTDataSource {
until?: string,
mint?: string
): Promise<EnrichedTransaction[]> {
let isNativeTransferFilter = false;
let target = address;

if (mint) {
target = getATAAddressSync({
mint: new PublicKey(mint),
owner: new PublicKey(address),
}).toBase58();
if (mint !== SystemProgram.programId.toBase58()) {
target = getATAAddressSync({
mint: new PublicKey(mint),
owner: new PublicKey(address),
}).toBase58();
} else {
isNativeTransferFilter = true;
}
}

return this.get(`/v0/addresses/${target}/transactions`, {
Expand All @@ -118,6 +124,12 @@ export class Helius extends RESTDataSource {
commitment: "confirmed",
before,
until,
...(isNativeTransferFilter
? {
source: Source.SYSTEM_PROGRAM,
type: TransactionType.TRANSFER,
}
: undefined),
},
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { ProviderId } from "../types";
import { calculateBalanceAggregate, createConnection } from "../utils";

import type { BlockchainDataProvider } from ".";
import { createMarketDataNode } from "./util";

export type BitcoinProviderSettings = {
context?: ApiContext;
Expand Down Expand Up @@ -123,18 +124,11 @@ export class Bitcoin implements BlockchainDataProvider {
amount: balance.final_balance.toString(),
decimals: this.decimals(),
displayAmount,
marketData: prices?.bitcoin
? NodeBuilder.marketData("bitcoin", {
lastUpdatedAt: prices.bitcoin.last_updated,
percentChange: prices.bitcoin.price_change_percentage_24h,
price: prices.bitcoin.current_price,
sparkline: prices.bitcoin.sparkline_in_7d.price,
usdChange: prices.bitcoin.price_change_24h,
value: parseFloat(displayAmount) * prices.bitcoin.current_price,
valueChange:
parseFloat(displayAmount) * prices.bitcoin.price_change_24h,
})
: undefined,
marketData: createMarketDataNode(
displayAmount,
"bitcoin",
prices.bitcoin
),
token: this.defaultAddress(),
tokenListEntry: NodeBuilder.tokenListEntry({
address: BitcoinToken.address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { ProviderId } from "../types";
import { calculateBalanceAggregate, createConnection } from "../utils";

import type { BlockchainDataProvider } from ".";
import { createMarketDataNode } from "./util";

export type EthereumProviderSettings = {
context?: ApiContext;
Expand Down Expand Up @@ -163,17 +164,11 @@ export class Ethereum implements BlockchainDataProvider {
amount: native.toString(),
decimals: this.decimals(),
displayAmount: nativeDisplayAmount,
marketData: NodeBuilder.marketData("ethereum", {
lastUpdatedAt: prices.ethereum.last_updated,
percentChange: prices.ethereum.price_change_percentage_24h,
price: prices.ethereum.current_price,
sparkline: prices.ethereum.sparkline_in_7d.price,
usdChange: prices.ethereum.price_change_24h,
value:
parseFloat(nativeDisplayAmount) * prices.ethereum.current_price,
valueChange:
parseFloat(nativeDisplayAmount) * prices.ethereum.price_change_24h,
}),
marketData: createMarketDataNode(
nativeDisplayAmount,
"ethereum",
prices.ethereum
),
token: this.defaultAddress(),
tokenListEntry: NodeBuilder.tokenListEntry(this.tokenList["native"]),
},
Expand All @@ -187,19 +182,7 @@ export class Ethereum implements BlockchainDataProvider {

const amount = curr.rawBalance ?? "0";
const displayAmount = curr.balance ?? "0";

const marketData =
p && id
? NodeBuilder.marketData(id, {
lastUpdatedAt: p.last_updated,
percentChange: p.price_change_percentage_24h,
price: p.current_price,
sparkline: p.sparkline_in_7d.price,
usdChange: p.price_change_24h,
value: parseFloat(displayAmount) * p.current_price,
valueChange: parseFloat(displayAmount) * p.price_change_24h,
})
: undefined;
const marketData = createMarketDataNode(displayAmount, id, p);

const tokenListEntry = this.tokenList[curr.contractAddress]
? NodeBuilder.tokenListEntry(this.tokenList[curr.contractAddress])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ export function createMarketDataNode(
}
return NodeBuilder.marketData(id, {
lastUpdatedAt: price.last_updated,
percentChange: price.price_change_percentage_24h,
percentChange: price.price_change_percentage_24h ?? 0,
price: price.current_price,
sparkline: price.sparkline_in_7d.price,
usdChange: price.price_change_24h,
usdChange: price.price_change_24h ?? 0,
value: parseFloat(displayAmount) * price.current_price,
valueChange: parseFloat(displayAmount) * price.price_change_24h,
valueChange: parseFloat(displayAmount) * (price.price_change_24h ?? 0),
});
}

Expand Down
12 changes: 6 additions & 6 deletions backend/workers/price-indexer/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export type CoinGeckoPriceData = {
market_cap_rank: number;
fully_filuted_valuation: number;
total_volume: number;
high_24h: number;
low_24h: number;
price_change_24h: number;
price_change_percentage_24h: number;
market_cap_change_24h: number;
market_cap_change_percentage_24h: number;
high_24h: number | null;
low_24h: number | null;
price_change_24h: number | null;
price_change_percentage_24h: number | null;
market_cap_change_24h: number | null;
market_cap_change_percentage_24h: number | null;
circulating_supply: number;
total_supply: number;
max_supply: number | null;
Expand Down

1 comment on commit b190fb8

@vercel
Copy link

@vercel vercel bot commented on b190fb8 Jun 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.