Skip to content

Commit

Permalink
improve(BundleDataClient): Simplify key used to store bundle data on …
Browse files Browse the repository at this point in the history
…Arweave (#778)
  • Loading branch information
nicholaspai authored Nov 20, 2024
1 parent c6f4ce0 commit be97c75
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@across-protocol/sdk",
"author": "UMA Team",
"version": "3.2.15",
"version": "3.2.16",
"license": "AGPL-3.0",
"homepage": "https://docs.across.to/reference/sdk",
"files": [
Expand Down
16 changes: 12 additions & 4 deletions src/clients/BundleDataClient/BundleDataClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,16 @@ export class BundleDataClient {
this.bundleTimestampCache[key] = timestamps;
}

private getArweaveClientKey(blockRangesForChains: number[][]): string {
return `bundles-${blockRangesForChains}`;
static getArweaveClientKey(blockRangesForChains: number[][]): string {
// As a unique key for this bundle, use the bundle mainnet end block, which should
// never be duplicated between bundles as long as thebundle block range
// always progresses forwards, which I think is a safe assumption. Other chains might pause
// but mainnet should never pause.
return blockRangesForChains[0][1].toString();
}

private getArweaveBundleDataClientKey(blockRangesForChains: number[][]): string {
return `bundles-${BundleDataClient.getArweaveClientKey(blockRangesForChains)}`;
}

private async loadPersistedDataFromArweave(
Expand All @@ -183,7 +191,7 @@ export class BundleDataClient {
}
const start = performance.now();
const persistedData = await this.clients.arweaveClient.getByTopic(
this.getArweaveClientKey(blockRangesForChains),
this.getArweaveBundleDataClientKey(blockRangesForChains),
BundleDataSS
);
// If there is no data or the data is empty, return undefined because we couldn't
Expand Down Expand Up @@ -579,7 +587,7 @@ export class BundleDataClient {
}

private async loadArweaveData(blockRangesForChains: number[][]): Promise<LoadDataReturnValue> {
const arweaveKey = this.getArweaveClientKey(blockRangesForChains);
const arweaveKey = this.getArweaveBundleDataClientKey(blockRangesForChains);
// eslint-disable-next-line @typescript-eslint/no-misused-promises
if (!this.arweaveDataCache[arweaveKey]) {
this.arweaveDataCache[arweaveKey] = this.loadPersistedDataFromArweave(blockRangesForChains);
Expand Down
4 changes: 2 additions & 2 deletions src/clients/BundleDataClient/utils/SuperstructUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
pattern,
boolean,
defaulted,
type,
} from "superstruct";
import { BigNumber } from "../../../utils";

Expand Down Expand Up @@ -122,8 +123,7 @@ const nestedV3BundleFillsSS = record(
)
);

export const BundleDataSS = object({
bundleBlockRanges: array(array(number())),
export const BundleDataSS = type({
bundleDepositsV3: nestedV3DepositRecordSS,
expiredDepositsToRefundV3: nestedV3DepositRecordSS,
unexecutableSlowFills: nestedV3DepositRecordWithLpFeePctSS,
Expand Down

0 comments on commit be97c75

Please sign in to comment.