Skip to content

Commit e3b5615

Browse files
committed
fix: add some useful utils
1 parent 02089e5 commit e3b5615

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-0
lines changed

src/market/pricefeeds/RedstoneUpdater.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ interface UpdatePFTask {
2424

2525
/**
2626
* Class to update multiple redstone price feeds at once
27+
* TODO: historical updates....
28+
* TODO: warp time on testnets
2729
*/
2830
export class RedstoneUpdater extends SDKConstruct {
2931
#logger?: ILogger;

src/utils/etherscan.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import type { TransactionReceipt } from "viem";
2+
3+
import type { CreditAccountData } from "../base";
4+
import type { NetworkType } from "../chain";
5+
6+
export type EtherscanURLParam =
7+
| { block: number }
8+
| { tx: string }
9+
| { address: string };
10+
11+
export function etherscanUrl(
12+
entity: EtherscanURLParam | TransactionReceipt | CreditAccountData,
13+
network: NetworkType,
14+
): string {
15+
let [prefix, domain] = ["", "etherscan.io"];
16+
17+
let param: EtherscanURLParam;
18+
if ("transactionHash" in entity && "blockHash" in entity) {
19+
param = { tx: entity.transactionHash };
20+
} else if ("creditAccount" in entity && "creditManager" in entity) {
21+
param = { address: entity.creditAccount };
22+
} else {
23+
param = entity;
24+
}
25+
26+
switch (network) {
27+
case "Optimism":
28+
prefix = "optimistic.";
29+
break;
30+
case "Arbitrum":
31+
domain = "arbiscan.io";
32+
break;
33+
case "Base":
34+
domain = "basescan.org";
35+
break;
36+
}
37+
const [key, value] = Object.entries(param)[0];
38+
return `https://${prefix}${domain}/${key}/${value}`;
39+
}

src/utils/filterDust.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { Address } from "viem";
2+
3+
import type { CreditAccountData } from "../base";
4+
5+
/**
6+
* Helper function to filter out low-balance assets
7+
* @param account
8+
* @returns
9+
*/
10+
export function filterDust(
11+
account: CreditAccountData,
12+
): Record<Address, bigint> {
13+
const result: Record<Address, bigint> = {};
14+
for (const { token, balance } of account.tokens) {
15+
if (balance > 10n) {
16+
result[token] = balance;
17+
}
18+
}
19+
return result;
20+
}

src/utils/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@ export * from "./AddressMap";
22
export * from "./bytes32ToString";
33
export * from "./childLogger";
44
export * from "./createRawTx";
5+
export * from "./etherscan";
6+
export * from "./filterDust";
57
export * from "./formatter";
68
export * from "./json";

0 commit comments

Comments
 (0)