Skip to content

Commit b190fb8

Browse files
authored
fix market data node bug and system program transfer filter for helius (#4255)
1 parent e31753a commit b190fb8

File tree

6 files changed

+46
-57
lines changed

6 files changed

+46
-57
lines changed

backend/native/backpack-api/src/routes/graphql/clients/coingecko.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ export type CoinGeckoPriceData = {
8282
market_cap_rank: number;
8383
fully_filuted_valuation: number;
8484
total_volume: number;
85-
high_24h: number;
86-
low_24h: number;
87-
price_change_24h: number;
88-
price_change_percentage_24h: number;
89-
market_cap_change_24h: number;
90-
market_cap_change_percentage_24h: number;
85+
high_24h: number | null;
86+
low_24h: number | null;
87+
price_change_24h: number | null;
88+
price_change_percentage_24h: number | null;
89+
market_cap_change_24h: number | null;
90+
market_cap_change_percentage_24h: number | null;
9191
circulating_supply: number;
9292
total_supply: number;
9393
max_supply: number | null;

backend/native/backpack-api/src/routes/graphql/clients/helius.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { RESTDataSource } from "@apollo/datasource-rest";
22
import { getATAAddressSync } from "@saberhq/token-utils";
33
import type { AccountInfo } from "@solana/web3.js";
4-
import { PublicKey } from "@solana/web3.js";
5-
import type { EnrichedTransaction } from "helius-sdk";
4+
import { PublicKey, SystemProgram } from "@solana/web3.js";
5+
import { type EnrichedTransaction, Source, TransactionType } from "helius-sdk";
66
import { LRUCache } from "lru-cache";
77

88
export const IN_MEM_SOL_COLLECTION_DATA_CACHE = new LRUCache<
@@ -104,12 +104,18 @@ export class Helius extends RESTDataSource {
104104
until?: string,
105105
mint?: string
106106
): Promise<EnrichedTransaction[]> {
107+
let isNativeTransferFilter = false;
107108
let target = address;
109+
108110
if (mint) {
109-
target = getATAAddressSync({
110-
mint: new PublicKey(mint),
111-
owner: new PublicKey(address),
112-
}).toBase58();
111+
if (mint !== SystemProgram.programId.toBase58()) {
112+
target = getATAAddressSync({
113+
mint: new PublicKey(mint),
114+
owner: new PublicKey(address),
115+
}).toBase58();
116+
} else {
117+
isNativeTransferFilter = true;
118+
}
113119
}
114120

115121
return this.get(`/v0/addresses/${target}/transactions`, {
@@ -118,6 +124,12 @@ export class Helius extends RESTDataSource {
118124
commitment: "confirmed",
119125
before,
120126
until,
127+
...(isNativeTransferFilter
128+
? {
129+
source: Source.SYSTEM_PROGRAM,
130+
type: TransactionType.TRANSFER,
131+
}
132+
: undefined),
121133
},
122134
});
123135
}

backend/native/backpack-api/src/routes/graphql/providers/bitcoin.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { ProviderId } from "../types";
2525
import { calculateBalanceAggregate, createConnection } from "../utils";
2626

2727
import type { BlockchainDataProvider } from ".";
28+
import { createMarketDataNode } from "./util";
2829

2930
export type BitcoinProviderSettings = {
3031
context?: ApiContext;
@@ -123,18 +124,11 @@ export class Bitcoin implements BlockchainDataProvider {
123124
amount: balance.final_balance.toString(),
124125
decimals: this.decimals(),
125126
displayAmount,
126-
marketData: prices?.bitcoin
127-
? NodeBuilder.marketData("bitcoin", {
128-
lastUpdatedAt: prices.bitcoin.last_updated,
129-
percentChange: prices.bitcoin.price_change_percentage_24h,
130-
price: prices.bitcoin.current_price,
131-
sparkline: prices.bitcoin.sparkline_in_7d.price,
132-
usdChange: prices.bitcoin.price_change_24h,
133-
value: parseFloat(displayAmount) * prices.bitcoin.current_price,
134-
valueChange:
135-
parseFloat(displayAmount) * prices.bitcoin.price_change_24h,
136-
})
137-
: undefined,
127+
marketData: createMarketDataNode(
128+
displayAmount,
129+
"bitcoin",
130+
prices.bitcoin
131+
),
138132
token: this.defaultAddress(),
139133
tokenListEntry: NodeBuilder.tokenListEntry({
140134
address: BitcoinToken.address,

backend/native/backpack-api/src/routes/graphql/providers/ethereum.ts

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { ProviderId } from "../types";
2929
import { calculateBalanceAggregate, createConnection } from "../utils";
3030

3131
import type { BlockchainDataProvider } from ".";
32+
import { createMarketDataNode } from "./util";
3233

3334
export type EthereumProviderSettings = {
3435
context?: ApiContext;
@@ -163,17 +164,11 @@ export class Ethereum implements BlockchainDataProvider {
163164
amount: native.toString(),
164165
decimals: this.decimals(),
165166
displayAmount: nativeDisplayAmount,
166-
marketData: NodeBuilder.marketData("ethereum", {
167-
lastUpdatedAt: prices.ethereum.last_updated,
168-
percentChange: prices.ethereum.price_change_percentage_24h,
169-
price: prices.ethereum.current_price,
170-
sparkline: prices.ethereum.sparkline_in_7d.price,
171-
usdChange: prices.ethereum.price_change_24h,
172-
value:
173-
parseFloat(nativeDisplayAmount) * prices.ethereum.current_price,
174-
valueChange:
175-
parseFloat(nativeDisplayAmount) * prices.ethereum.price_change_24h,
176-
}),
167+
marketData: createMarketDataNode(
168+
nativeDisplayAmount,
169+
"ethereum",
170+
prices.ethereum
171+
),
177172
token: this.defaultAddress(),
178173
tokenListEntry: NodeBuilder.tokenListEntry(this.tokenList["native"]),
179174
},
@@ -187,19 +182,7 @@ export class Ethereum implements BlockchainDataProvider {
187182

188183
const amount = curr.rawBalance ?? "0";
189184
const displayAmount = curr.balance ?? "0";
190-
191-
const marketData =
192-
p && id
193-
? NodeBuilder.marketData(id, {
194-
lastUpdatedAt: p.last_updated,
195-
percentChange: p.price_change_percentage_24h,
196-
price: p.current_price,
197-
sparkline: p.sparkline_in_7d.price,
198-
usdChange: p.price_change_24h,
199-
value: parseFloat(displayAmount) * p.current_price,
200-
valueChange: parseFloat(displayAmount) * p.price_change_24h,
201-
})
202-
: undefined;
185+
const marketData = createMarketDataNode(displayAmount, id, p);
203186

204187
const tokenListEntry = this.tokenList[curr.contractAddress]
205188
? NodeBuilder.tokenListEntry(this.tokenList[curr.contractAddress])

backend/native/backpack-api/src/routes/graphql/providers/util.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ export function createMarketDataNode(
2020
}
2121
return NodeBuilder.marketData(id, {
2222
lastUpdatedAt: price.last_updated,
23-
percentChange: price.price_change_percentage_24h,
23+
percentChange: price.price_change_percentage_24h ?? 0,
2424
price: price.current_price,
2525
sparkline: price.sparkline_in_7d.price,
26-
usdChange: price.price_change_24h,
26+
usdChange: price.price_change_24h ?? 0,
2727
value: parseFloat(displayAmount) * price.current_price,
28-
valueChange: parseFloat(displayAmount) * price.price_change_24h,
28+
valueChange: parseFloat(displayAmount) * (price.price_change_24h ?? 0),
2929
});
3030
}
3131

backend/workers/price-indexer/src/types.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ export type CoinGeckoPriceData = {
1515
market_cap_rank: number;
1616
fully_filuted_valuation: number;
1717
total_volume: number;
18-
high_24h: number;
19-
low_24h: number;
20-
price_change_24h: number;
21-
price_change_percentage_24h: number;
22-
market_cap_change_24h: number;
23-
market_cap_change_percentage_24h: number;
18+
high_24h: number | null;
19+
low_24h: number | null;
20+
price_change_24h: number | null;
21+
price_change_percentage_24h: number | null;
22+
market_cap_change_24h: number | null;
23+
market_cap_change_percentage_24h: number | null;
2424
circulating_supply: number;
2525
total_supply: number;
2626
max_supply: number | null;

0 commit comments

Comments
 (0)