@across-protocol/sdk 4.3.145-alpha.1 → 4.3.145-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/src/caching/Arweave/ArweaveClient.d.ts +2 -0
- package/dist/cjs/src/caching/Arweave/ArweaveClient.js +116 -40
- package/dist/cjs/src/caching/Arweave/ArweaveClient.js.map +1 -1
- package/dist/cjs/src/clients/BundleDataClient/BundleDataClient.d.ts +5 -2
- package/dist/cjs/src/clients/BundleDataClient/BundleDataClient.js +74 -10
- package/dist/cjs/src/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/cjs/src/coingecko/Coingecko.js +2 -9
- package/dist/cjs/src/coingecko/Coingecko.js.map +1 -1
- package/dist/cjs/src/utils/CachingUtils.d.ts +1 -0
- package/dist/cjs/src/utils/CachingUtils.js +4 -0
- package/dist/cjs/src/utils/CachingUtils.js.map +1 -1
- package/dist/cjs/src/utils/common.d.ts +1 -13
- package/dist/cjs/src/utils/common.js +8 -19
- package/dist/cjs/src/utils/common.js.map +1 -1
- package/dist/esm/src/caching/Arweave/ArweaveClient.d.ts +2 -0
- package/dist/esm/src/caching/Arweave/ArweaveClient.js +117 -47
- package/dist/esm/src/caching/Arweave/ArweaveClient.js.map +1 -1
- package/dist/esm/src/clients/BundleDataClient/BundleDataClient.d.ts +5 -2
- package/dist/esm/src/clients/BundleDataClient/BundleDataClient.js +77 -13
- package/dist/esm/src/clients/BundleDataClient/BundleDataClient.js.map +1 -1
- package/dist/esm/src/coingecko/Coingecko.js +2 -9
- package/dist/esm/src/coingecko/Coingecko.js.map +1 -1
- package/dist/esm/src/utils/CachingUtils.d.ts +1 -0
- package/dist/esm/src/utils/CachingUtils.js +3 -0
- package/dist/esm/src/utils/CachingUtils.js.map +1 -1
- package/dist/esm/src/utils/common.d.ts +6 -33
- package/dist/esm/src/utils/common.js +13 -26
- package/dist/esm/src/utils/common.js.map +1 -1
- package/dist/types/src/caching/Arweave/ArweaveClient.d.ts +2 -0
- package/dist/types/src/caching/Arweave/ArweaveClient.d.ts.map +1 -1
- package/dist/types/src/clients/BundleDataClient/BundleDataClient.d.ts +5 -2
- package/dist/types/src/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
- package/dist/types/src/coingecko/Coingecko.d.ts.map +1 -1
- package/dist/types/src/utils/CachingUtils.d.ts +1 -0
- package/dist/types/src/utils/CachingUtils.d.ts.map +1 -1
- package/dist/types/src/utils/common.d.ts +6 -33
- package/dist/types/src/utils/common.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/caching/Arweave/ArweaveClient.ts +142 -54
- package/src/clients/BundleDataClient/BundleDataClient.ts +86 -17
- package/src/coingecko/Coingecko.ts +2 -9
- package/src/utils/CachingUtils.ts +4 -0
- package/src/utils/common.ts +14 -49
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SpokePoolClientsByChain, LoadDataReturnValue, Clients, FillWithBlock, DepositWithBlock } from "../../interfaces";
|
|
1
|
+
import { SpokePoolClientsByChain, LoadDataReturnValue, Clients, FillWithBlock, DepositWithBlock, CachingMechanismInterface } from "../../interfaces";
|
|
2
2
|
import { SpokePoolClient } from "..";
|
|
3
3
|
import winston from "winston";
|
|
4
4
|
import { SpokePoolManager } from "../SpokePoolClient/SpokePoolClientManager";
|
|
@@ -9,6 +9,7 @@ export declare class BundleDataClient {
|
|
|
9
9
|
readonly blockRangeEndBlockBuffer: {
|
|
10
10
|
[chainId: number]: number;
|
|
11
11
|
};
|
|
12
|
+
readonly arweaveTopicCache?: CachingMechanismInterface | undefined;
|
|
12
13
|
private loadDataCache;
|
|
13
14
|
private arweaveDataCache;
|
|
14
15
|
private bundleTimestampCache;
|
|
@@ -17,7 +18,7 @@ export declare class BundleDataClient {
|
|
|
17
18
|
[chainId: number]: SpokePoolClient;
|
|
18
19
|
}, chainIdListForBundleEvaluationBlockNumbers: number[], blockRangeEndBlockBuffer?: {
|
|
19
20
|
[chainId: number]: number;
|
|
20
|
-
});
|
|
21
|
+
}, arweaveTopicCache?: CachingMechanismInterface | undefined);
|
|
21
22
|
clearCache(): void;
|
|
22
23
|
private loadDataFromCache;
|
|
23
24
|
getBundleTimestampsFromCache(key: string): undefined | {
|
|
@@ -28,6 +29,8 @@ export declare class BundleDataClient {
|
|
|
28
29
|
}): void;
|
|
29
30
|
static getArweaveClientKey(blockRangesForChains: number[][]): string;
|
|
30
31
|
private getArweaveBundleDataClientKey;
|
|
32
|
+
private getPersistedArweaveTopicFromCache;
|
|
33
|
+
private backfillPersistedArweaveTopicCache;
|
|
31
34
|
private loadPersistedDataFromArweave;
|
|
32
35
|
private loadArweaveData;
|
|
33
36
|
loadData(blockRangesForChains: number[][], spokePoolClients: SpokePoolClientsByChain, attemptArweaveLoad?: boolean): Promise<LoadDataReturnValue>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BundleDataClient.d.ts","sourceRoot":"","sources":["../../../../../src/clients/BundleDataClient/BundleDataClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BundleDataClient.d.ts","sourceRoot":"","sources":["../../../../../src/clients/BundleDataClient/BundleDataClient.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,uBAAuB,EAGvB,mBAAmB,EAOnB,OAAO,EACP,aAAa,EAEb,gBAAgB,EAChB,yBAAyB,EAC1B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,IAAI,CAAC;AA4BrC,OAAO,OAAO,MAAM,SAAS,CAAC;AAa9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAgG7E,qBAAa,gBAAgB;IASzB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM;IAC/B,QAAQ,CAAC,OAAO,EAAE,OAAO;IAEzB,QAAQ,CAAC,0CAA0C,EAAE,MAAM,EAAE;IAC7D,QAAQ,CAAC,wBAAwB,EAAE;QAAE,CAAC,OAAO,EAAE,MAAM,GAA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AAG,SAAS;IAwB7B,SAAS,CAAC,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC,GAAG,SAAS;IAU7G,SAAS,CAAC,gBAAgB,CAAC,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;IAwBhH,SAAS,CAAC,wBAAwB,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;YAuB5E,UAAU;YAOV,QAAQ;CAIvB"}
|
|
@@ -15,4 +15,5 @@ export declare function setDepositInCache(deposit: Deposit, currentChainTime: nu
|
|
|
15
15
|
* @returns The key for caching the event.
|
|
16
16
|
*/
|
|
17
17
|
export declare function getDepositKey(bridgeEvent: Deposit | Fill | SlowFillRequest): string;
|
|
18
|
+
export declare function getArweaveTopicCacheKey(tag: string): string;
|
|
18
19
|
//# sourceMappingURL=CachingUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CachingUtils.d.ts","sourceRoot":"","sources":["../../../../src/utils/CachingUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAO1F,wBAAgB,WAAW,CAAC,cAAc,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAItG;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAGnH;AAED,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,OAAO,EAChB,gBAAgB,EAAE,MAAM,EACxB,KAAK,EAAE,yBAAyB,EAChC,aAAa,SAAsB,EACnC,WAAW,SAA2B,GACrC,OAAO,CAAC,IAAI,CAAC,CAaf;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,WAAW,EAAE,OAAO,GAAG,IAAI,GAAG,eAAe,GAAG,MAAM,CAGnF"}
|
|
1
|
+
{"version":3,"file":"CachingUtils.d.ts","sourceRoot":"","sources":["../../../../src/utils/CachingUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAO1F,wBAAgB,WAAW,CAAC,cAAc,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAItG;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,GAAG,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAGnH;AAED,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,OAAO,EAChB,gBAAgB,EAAE,MAAM,EACxB,KAAK,EAAE,yBAAyB,EAChC,aAAa,SAAsB,EACnC,WAAW,SAA2B,GACrC,OAAO,CAAC,IAAI,CAAC,CAaf;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,WAAW,EAAE,OAAO,GAAG,IAAI,GAAG,eAAe,GAAG,MAAM,CAGnF;AAED,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE3D"}
|
|
@@ -120,40 +120,13 @@ export declare const getSamplesBetween: (min: number, max: number, size: number)
|
|
|
120
120
|
*/
|
|
121
121
|
export declare function delay(seconds: number): Promise<unknown>;
|
|
122
122
|
/**
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
123
|
+
* Attempt to retry a function call a number of times with a delay between each attempt
|
|
124
|
+
* @param call The function to call
|
|
125
|
+
* @param times The number of times to retry
|
|
126
|
+
* @param delayS The number of seconds to delay between each attempt
|
|
127
|
+
* @returns The result of the function call.
|
|
126
128
|
*/
|
|
127
|
-
export
|
|
128
|
-
ok: true;
|
|
129
|
-
value: T;
|
|
130
|
-
} | {
|
|
131
|
-
ok: false;
|
|
132
|
-
error: E;
|
|
133
|
-
};
|
|
134
|
-
/**
|
|
135
|
-
* Configures {@link retry}. Retries always use exponential backoff
|
|
136
|
-
* (`delaySeconds * 2 ** attempt + random()` seconds) to play nicely with upstream
|
|
137
|
-
* rate-limits; callers that want tighter spacing should lower {@link delaySeconds}.
|
|
138
|
-
*/
|
|
139
|
-
export type RetryOptions = {
|
|
140
|
-
/** Maximum number of retry attempts after the initial call (total attempts = retries + 1). Defaults to 2 (3 total tries). */
|
|
141
|
-
retries?: number;
|
|
142
|
-
/** Base delay in seconds for the exponential backoff. Defaults to 1. */
|
|
143
|
-
delaySeconds?: number;
|
|
144
|
-
/** Predicate evaluated against the thrown error to decide whether to retry. Defaults to retrying every error. */
|
|
145
|
-
isRetryable?: (err: unknown) => boolean;
|
|
146
|
-
};
|
|
147
|
-
/**
|
|
148
|
-
* Attempt a function call with exponential backoff and a retryability predicate, returning a
|
|
149
|
-
* {@link Result} that encodes success or the terminal failure. Exhausted retries and errors
|
|
150
|
-
* rejected by `isRetryable` both surface as `{ ok: false, error }` — the caller decides how
|
|
151
|
-
* to react instead of catching a throw.
|
|
152
|
-
* @param call The function to call.
|
|
153
|
-
* @param options Retry configuration — see {@link RetryOptions}. All fields are optional.
|
|
154
|
-
* @returns A `Result<T>` wrapping the terminal outcome.
|
|
155
|
-
*/
|
|
156
|
-
export declare function retry<T>(call: () => Promise<T>, options?: RetryOptions): Promise<Result<T>>;
|
|
129
|
+
export declare function retry<T>(call: () => Promise<T>, times: number, delayS: number): Promise<T>;
|
|
157
130
|
export type TransactionCostEstimate = {
|
|
158
131
|
nativeGasCost: BigNumber;
|
|
159
132
|
tokenGasCost: BigNumber;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":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AU,EACrB,gBAAgB,UAAU,EAC1B,gBAAgB,UAAU,KACzB,MAaF,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,OAAO,GAClB,aAAa,UAAU,EACvB,WAAW,UAAU,EACrB,gBAAgB,UAAU,EAC1B,gBAAgB,UAAU,KACzB,MAEF,CAAC;AACF;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,GAAI,KAAK,MAAM,EAAE,KAAK,MAAM,EAAE,MAAM,MAAM,eAYvE,CAAC;AAEF;;;GAGG;AACH,wBAAgB,KAAK,CAAC,OAAO,EAAE,MAAM,oBAEpC;AAED;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAQ1F;AAED,MAAM,MAAM,uBAAuB,GAAG;IACpC,aAAa,EAAE,SAAS,CAAC;IACzB,YAAY,EAAE,SAAS,CAAC;IACxB,QAAQ,EAAE,SAAS,CAAC;IACpB,gBAAgB,CAAC,EAAE,SAAS,CAAC;CAC9B,CAAC;AAEF,wBAAgB,aAAa,WAE5B"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import Arweave from "arweave";
|
|
2
|
+
import Transaction from "arweave/node/lib/transaction";
|
|
2
3
|
import { JWKInterface } from "arweave/node/lib/wallet";
|
|
3
4
|
|
|
4
5
|
import { Struct, create } from "superstruct";
|
|
5
6
|
import winston from "winston";
|
|
6
7
|
import { ARWEAVE_TAG_APP_NAME, ARWEAVE_TAG_APP_VERSION, DEFAULT_ARWEAVE_STORAGE_ADDRESS } from "../../constants";
|
|
7
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
BigNumber,
|
|
10
|
+
delay,
|
|
11
|
+
fetchWithTimeout,
|
|
12
|
+
isDefined,
|
|
13
|
+
isHttpError,
|
|
14
|
+
jsonReplacerWithBigNumbers,
|
|
15
|
+
postWithTimeout,
|
|
16
|
+
toBN,
|
|
17
|
+
} from "../../utils";
|
|
8
18
|
|
|
9
19
|
export interface ArweaveGatewayConfig {
|
|
10
20
|
host: string;
|
|
@@ -19,6 +29,28 @@ interface Gateway {
|
|
|
19
29
|
url: string;
|
|
20
30
|
}
|
|
21
31
|
|
|
32
|
+
interface GraphQLTransactionsResponse {
|
|
33
|
+
data?: {
|
|
34
|
+
transactions?: {
|
|
35
|
+
edges?: { node: { id: string } }[];
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
type WritePhase = "createTransaction" | "sign" | "post";
|
|
41
|
+
|
|
42
|
+
class ArweaveWriteError extends Error {
|
|
43
|
+
constructor(
|
|
44
|
+
message: string,
|
|
45
|
+
readonly phase: WritePhase,
|
|
46
|
+
readonly gateway: string,
|
|
47
|
+
readonly status?: number
|
|
48
|
+
) {
|
|
49
|
+
super(message);
|
|
50
|
+
this.name = "ArweaveWriteError";
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
22
54
|
export class ArweaveClient {
|
|
23
55
|
private gateways: Gateway[];
|
|
24
56
|
|
|
@@ -69,16 +101,20 @@ export class ArweaveClient {
|
|
|
69
101
|
* Tries gateways sequentially, returning the first successful response.
|
|
70
102
|
* Used for write operations where we want exactly one successful submission.
|
|
71
103
|
*/
|
|
72
|
-
private async _failoverGateways<T>(label: string, fn: (gw: Gateway) => Promise<T>): Promise<T> {
|
|
104
|
+
private async _failoverGateways<T>(label: string, fn: (gw: Gateway, attempt: number) => Promise<T>): Promise<T> {
|
|
73
105
|
const errors: Error[] = [];
|
|
74
|
-
for (const gw of this.gateways) {
|
|
106
|
+
for (const [index, gw] of this.gateways.entries()) {
|
|
75
107
|
try {
|
|
76
|
-
return await this._retryRequest(() => fn(gw), 0);
|
|
108
|
+
return await this._retryRequest(() => fn(gw, index + 1), 0);
|
|
77
109
|
} catch (e) {
|
|
78
|
-
|
|
110
|
+
const error = e instanceof Error ? e : new Error(String(e));
|
|
111
|
+
errors.push(error);
|
|
79
112
|
this.logger.debug({
|
|
80
113
|
at: "ArweaveClient:failoverGateways",
|
|
81
|
-
message: `Gateway ${gw.url} failed for ${label}, trying next
|
|
114
|
+
message: `Gateway ${gw.url} failed for ${label}, trying next gateway`,
|
|
115
|
+
gateway: gw.url,
|
|
116
|
+
attempt: index + 1,
|
|
117
|
+
error: String(error),
|
|
82
118
|
});
|
|
83
119
|
}
|
|
84
120
|
}
|
|
@@ -107,6 +143,25 @@ export class ArweaveClient {
|
|
|
107
143
|
}
|
|
108
144
|
}
|
|
109
145
|
|
|
146
|
+
private _isNotFoundError(error: unknown): boolean {
|
|
147
|
+
if (isHttpError(error)) {
|
|
148
|
+
return error.status === 404;
|
|
149
|
+
}
|
|
150
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
151
|
+
return /404/i.test(message);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
private _wrapWriteError(error: unknown, phase: WritePhase, gateway: string): ArweaveWriteError {
|
|
155
|
+
if (error instanceof ArweaveWriteError) {
|
|
156
|
+
return error;
|
|
157
|
+
}
|
|
158
|
+
if (isHttpError(error)) {
|
|
159
|
+
return new ArweaveWriteError(error.message, phase, gateway, error.status);
|
|
160
|
+
}
|
|
161
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
162
|
+
return new ArweaveWriteError(message, phase, gateway);
|
|
163
|
+
}
|
|
164
|
+
|
|
110
165
|
/**
|
|
111
166
|
* Stores an arbitrary record in the Arweave network. The record is stored as a JSON string and uses
|
|
112
167
|
* JSON.stringify to convert the record to a string. The record has all of its big numbers converted
|
|
@@ -116,49 +171,66 @@ export class ArweaveClient {
|
|
|
116
171
|
* @returns The transaction ID of the stored value
|
|
117
172
|
*/
|
|
118
173
|
async set(value: Record<string, unknown>, topicTag?: string | undefined): Promise<string | undefined> {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const templateClient = this.gateways[0].client;
|
|
122
|
-
const transaction = await templateClient.createTransaction(
|
|
123
|
-
{ data: JSON.stringify(value, jsonReplacerWithBigNumbers) },
|
|
124
|
-
this.arweaveJWT
|
|
125
|
-
);
|
|
174
|
+
const payload = JSON.stringify(value, jsonReplacerWithBigNumbers);
|
|
175
|
+
let signedTransaction: Transaction | undefined;
|
|
126
176
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
177
|
+
try {
|
|
178
|
+
return await this._failoverGateways("set", async ({ client, url }, attempt) => {
|
|
179
|
+
if (!signedTransaction) {
|
|
180
|
+
let createdTransaction: Transaction;
|
|
181
|
+
try {
|
|
182
|
+
createdTransaction = await client.createTransaction({ data: payload }, this.arweaveJWT);
|
|
183
|
+
} catch (error) {
|
|
184
|
+
throw this._wrapWriteError(error, "createTransaction", url);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
createdTransaction.addTag("Content-Type", "application/json");
|
|
188
|
+
createdTransaction.addTag("App-Name", ARWEAVE_TAG_APP_NAME);
|
|
189
|
+
createdTransaction.addTag("App-Version", ARWEAVE_TAG_APP_VERSION.toString());
|
|
190
|
+
if (isDefined(topicTag)) {
|
|
191
|
+
createdTransaction.addTag("Topic", topicTag);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
try {
|
|
195
|
+
await client.transactions.sign(createdTransaction, this.arweaveJWT);
|
|
196
|
+
} catch (error) {
|
|
197
|
+
throw this._wrapWriteError(error, "sign", url);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
signedTransaction = createdTransaction;
|
|
201
|
+
}
|
|
134
202
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
203
|
+
let result: Awaited<ReturnType<Arweave["transactions"]["post"]>>;
|
|
204
|
+
try {
|
|
205
|
+
result = await client.transactions.post(signedTransaction);
|
|
206
|
+
} catch (error) {
|
|
207
|
+
throw this._wrapWriteError(error, "post", url);
|
|
208
|
+
}
|
|
138
209
|
|
|
139
|
-
|
|
140
|
-
|
|
210
|
+
if (result.status !== 200) {
|
|
211
|
+
const message = result?.data?.error?.msg ?? result.statusText ?? `HTTP ${result.status}`;
|
|
212
|
+
throw new ArweaveWriteError(message, "post", url, result.status);
|
|
213
|
+
}
|
|
141
214
|
|
|
142
|
-
|
|
143
|
-
if (result.status !== 200) {
|
|
144
|
-
const message = result?.data?.error?.msg ?? "Unknown error";
|
|
145
|
-
this.logger.error({
|
|
215
|
+
this.logger.debug({
|
|
146
216
|
at: "ArweaveClient:set",
|
|
147
|
-
message
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
217
|
+
message: `Arweave transaction posted with ${signedTransaction.id}`,
|
|
218
|
+
gateway: url,
|
|
219
|
+
attempt,
|
|
220
|
+
phase: "post",
|
|
221
|
+
txn: signedTransaction.id,
|
|
152
222
|
});
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
this.logger.
|
|
223
|
+
return signedTransaction.id;
|
|
224
|
+
});
|
|
225
|
+
} catch (error) {
|
|
226
|
+
this.logger.error({
|
|
157
227
|
at: "ArweaveClient:set",
|
|
158
|
-
message:
|
|
228
|
+
message: "Failed to persist data to Arweave after exhausting all gateways",
|
|
229
|
+
topicTag,
|
|
230
|
+
error: String(error),
|
|
159
231
|
});
|
|
160
|
-
|
|
161
|
-
}
|
|
232
|
+
throw error;
|
|
233
|
+
}
|
|
162
234
|
}
|
|
163
235
|
|
|
164
236
|
/**
|
|
@@ -218,17 +290,11 @@ export class ArweaveClient {
|
|
|
218
290
|
) { edges { node { id } } }
|
|
219
291
|
}`;
|
|
220
292
|
|
|
221
|
-
const response = await this._raceGateways("getByTopic", async ({
|
|
222
|
-
|
|
223
|
-
data: { transactions: { edges: { node: { id: string } }[] } };
|
|
224
|
-
}>("/graphql", { query });
|
|
225
|
-
if (!response.ok) {
|
|
226
|
-
throw new Error(`Arweave GraphQL request failed with status ${response.status}`);
|
|
227
|
-
}
|
|
228
|
-
return response;
|
|
293
|
+
const response = await this._raceGateways("getByTopic", async ({ url }) => {
|
|
294
|
+
return await postWithTimeout<GraphQLTransactionsResponse>(`${url}/graphql`, { query }, {}, {}, 20_000);
|
|
229
295
|
});
|
|
230
296
|
|
|
231
|
-
const entries = response?.data?.
|
|
297
|
+
const entries = response?.data?.transactions?.edges ?? [];
|
|
232
298
|
this.logger.debug({
|
|
233
299
|
at: "ArweaveClient:getByTopic",
|
|
234
300
|
message: `Retrieved ${entries.length} matching transactions from Arweave`,
|
|
@@ -239,6 +305,7 @@ export class ArweaveClient {
|
|
|
239
305
|
appVersion: ARWEAVE_TAG_APP_VERSION,
|
|
240
306
|
},
|
|
241
307
|
});
|
|
308
|
+
const failures: { hash: string; error: unknown }[] = [];
|
|
242
309
|
const results = await Promise.all(
|
|
243
310
|
entries.map(async (edge) => {
|
|
244
311
|
try {
|
|
@@ -250,14 +317,35 @@ export class ArweaveClient {
|
|
|
250
317
|
}
|
|
251
318
|
: null;
|
|
252
319
|
} catch (e) {
|
|
253
|
-
|
|
254
|
-
at: "ArweaveClient:getByTopic",
|
|
255
|
-
message: `Bad request for Arweave topic ${edge.node.id}: ${e}`,
|
|
256
|
-
});
|
|
320
|
+
failures.push({ hash: edge.node.id, error: e });
|
|
257
321
|
return null;
|
|
258
322
|
}
|
|
259
323
|
})
|
|
260
324
|
);
|
|
325
|
+
const notFoundFailures = failures.filter(({ error }) => this._isNotFoundError(error));
|
|
326
|
+
const unexpectedFailures = failures.filter(({ error }) => !this._isNotFoundError(error));
|
|
327
|
+
|
|
328
|
+
if (notFoundFailures.length > 0) {
|
|
329
|
+
this.logger.debug({
|
|
330
|
+
at: "ArweaveClient:getByTopic",
|
|
331
|
+
message: `Skipped ${notFoundFailures.length} Arweave topic entries that were not yet available`,
|
|
332
|
+
tag,
|
|
333
|
+
transactions: notFoundFailures.map(({ hash }) => hash),
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
if (unexpectedFailures.length > 0) {
|
|
338
|
+
this.logger.warn({
|
|
339
|
+
at: "ArweaveClient:getByTopic",
|
|
340
|
+
message: `Failed to fetch ${unexpectedFailures.length} Arweave topic entries`,
|
|
341
|
+
tag,
|
|
342
|
+
failures: unexpectedFailures.map(({ hash, error }) => ({
|
|
343
|
+
hash,
|
|
344
|
+
error: String(error),
|
|
345
|
+
})),
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
|
|
261
349
|
return results.filter(isDefined);
|
|
262
350
|
}
|
|
263
351
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import assert from "assert";
|
|
2
2
|
import _ from "lodash";
|
|
3
|
+
import { create } from "superstruct";
|
|
3
4
|
import {
|
|
4
5
|
SlowFillRequestWithBlock,
|
|
5
6
|
SpokePoolClientsByChain,
|
|
@@ -16,6 +17,7 @@ import {
|
|
|
16
17
|
FillWithBlock,
|
|
17
18
|
Deposit,
|
|
18
19
|
DepositWithBlock,
|
|
20
|
+
CachingMechanismInterface,
|
|
19
21
|
} from "../../interfaces";
|
|
20
22
|
import { SpokePoolClient } from "..";
|
|
21
23
|
import { findFillEvent as findEvmFillEvent } from "../../arch/evm";
|
|
@@ -42,10 +44,13 @@ import {
|
|
|
42
44
|
convertRelayDataParamsToBytes32,
|
|
43
45
|
convertFillParamsToBytes32,
|
|
44
46
|
chainIsTvm,
|
|
47
|
+
getArweaveTopicCacheKey,
|
|
48
|
+
jsonReplacerWithBigNumbers,
|
|
45
49
|
} from "../../utils";
|
|
46
50
|
import winston from "winston";
|
|
47
51
|
import {
|
|
48
52
|
BundleDataSS,
|
|
53
|
+
BundleData as PersistedArweaveBundleData,
|
|
49
54
|
getRefundInformationFromFill,
|
|
50
55
|
isChainDisabledAtBlock,
|
|
51
56
|
isChainPaused,
|
|
@@ -56,7 +61,7 @@ import {
|
|
|
56
61
|
} from "./utils";
|
|
57
62
|
import { isEVMSpokePoolClient, isSVMSpokePoolClient } from "../SpokePoolClient";
|
|
58
63
|
import { SpokePoolManager } from "../SpokePoolClient/SpokePoolClientManager";
|
|
59
|
-
|
|
64
|
+
import { DEFAULT_CACHING_TTL } from "../../constants";
|
|
60
65
|
type DataCache = Record<string, Promise<LoadDataReturnValue>>;
|
|
61
66
|
|
|
62
67
|
// V3 dictionary helper functions
|
|
@@ -164,7 +169,8 @@ export class BundleDataClient {
|
|
|
164
169
|
readonly clients: Clients,
|
|
165
170
|
spokePoolClients: { [chainId: number]: SpokePoolClient },
|
|
166
171
|
readonly chainIdListForBundleEvaluationBlockNumbers: number[],
|
|
167
|
-
readonly blockRangeEndBlockBuffer: { [chainId: number]: number } = {}
|
|
172
|
+
readonly blockRangeEndBlockBuffer: { [chainId: number]: number } = {},
|
|
173
|
+
readonly arweaveTopicCache?: CachingMechanismInterface
|
|
168
174
|
) {
|
|
169
175
|
this.spokePoolClientManager = new SpokePoolManager(logger, spokePoolClients);
|
|
170
176
|
}
|
|
@@ -204,6 +210,50 @@ export class BundleDataClient {
|
|
|
204
210
|
return `bundles-${BundleDataClient.getArweaveClientKey(blockRangesForChains)}`;
|
|
205
211
|
}
|
|
206
212
|
|
|
213
|
+
private async getPersistedArweaveTopicFromCache(tag: string): Promise<PersistedArweaveBundleData | undefined> {
|
|
214
|
+
if (!isDefined(this.arweaveTopicCache)) {
|
|
215
|
+
return undefined;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
try {
|
|
219
|
+
const cachedPayload = await this.arweaveTopicCache.get<string>(getArweaveTopicCacheKey(tag));
|
|
220
|
+
if (!isDefined(cachedPayload)) {
|
|
221
|
+
return undefined;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return create(JSON.parse(cachedPayload), BundleDataSS);
|
|
225
|
+
} catch (error) {
|
|
226
|
+
this.logger.debug({
|
|
227
|
+
at: "BundleDataClient#getPersistedArweaveTopicFromCache",
|
|
228
|
+
message: "Failed to restore persisted bundle data from topic cache, falling back to Arweave",
|
|
229
|
+
tag,
|
|
230
|
+
error: String(error),
|
|
231
|
+
});
|
|
232
|
+
return undefined;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
private async backfillPersistedArweaveTopicCache(tag: string, data: PersistedArweaveBundleData): Promise<void> {
|
|
237
|
+
if (!isDefined(this.arweaveTopicCache)) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
try {
|
|
242
|
+
await this.arweaveTopicCache.set(
|
|
243
|
+
getArweaveTopicCacheKey(tag),
|
|
244
|
+
JSON.stringify(data, jsonReplacerWithBigNumbers),
|
|
245
|
+
DEFAULT_CACHING_TTL
|
|
246
|
+
);
|
|
247
|
+
} catch (error) {
|
|
248
|
+
this.logger.debug({
|
|
249
|
+
at: "BundleDataClient#backfillPersistedArweaveTopicCache",
|
|
250
|
+
message: "Failed to backfill persisted bundle data into topic cache",
|
|
251
|
+
tag,
|
|
252
|
+
error: String(error),
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
207
257
|
private async loadPersistedDataFromArweave(
|
|
208
258
|
blockRangesForChains: number[][]
|
|
209
259
|
): Promise<LoadDataReturnValue | undefined> {
|
|
@@ -211,14 +261,25 @@ export class BundleDataClient {
|
|
|
211
261
|
return undefined;
|
|
212
262
|
}
|
|
213
263
|
const start = performance.now();
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
)
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
264
|
+
const tag = this.getArweaveBundleDataClientKey(blockRangesForChains);
|
|
265
|
+
let data = await this.getPersistedArweaveTopicFromCache(tag);
|
|
266
|
+
|
|
267
|
+
if (!isDefined(data)) {
|
|
268
|
+
const persistedData = await this.clients.arweaveClient.getByTopic(tag, BundleDataSS);
|
|
269
|
+
// If there is no data or the data is empty, return undefined because we couldn't
|
|
270
|
+
// pull info from the Arweave persistence layer.
|
|
271
|
+
if (!isDefined(persistedData) || persistedData.length < 1) {
|
|
272
|
+
return undefined;
|
|
273
|
+
}
|
|
274
|
+
data = persistedData[0].data;
|
|
275
|
+
await this.backfillPersistedArweaveTopicCache(tag, data);
|
|
276
|
+
} else {
|
|
277
|
+
this.logger.debug({
|
|
278
|
+
at: "BundleDataClient#loadPersistedDataFromArweave",
|
|
279
|
+
message: "Loaded persisted bundle data from topic cache",
|
|
280
|
+
blockRanges: JSON.stringify(blockRangesForChains),
|
|
281
|
+
tag,
|
|
282
|
+
});
|
|
222
283
|
}
|
|
223
284
|
|
|
224
285
|
// A converter function to account for the fact that our SuperStruct schema does not support numeric
|
|
@@ -302,8 +363,6 @@ export class BundleDataClient {
|
|
|
302
363
|
);
|
|
303
364
|
};
|
|
304
365
|
|
|
305
|
-
const data = persistedData[0].data;
|
|
306
|
-
|
|
307
366
|
// This section processes and transforms bundle data loaded from Arweave storage into the correct format:
|
|
308
367
|
// 1. Each field (bundleFillsV3, expiredDepositsToRefundV3, etc.) contains nested records keyed by chainId and token
|
|
309
368
|
// 2. The chainId keys are converted from strings to numbers using convertTypedStringRecordIntoNumericRecord
|
|
@@ -365,7 +424,10 @@ export class BundleDataClient {
|
|
|
365
424
|
const arweaveKey = this.getArweaveBundleDataClientKey(blockRangesForChains);
|
|
366
425
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
367
426
|
if (!this.arweaveDataCache[arweaveKey]) {
|
|
368
|
-
this.arweaveDataCache[arweaveKey] = this.loadPersistedDataFromArweave(blockRangesForChains)
|
|
427
|
+
this.arweaveDataCache[arweaveKey] = this.loadPersistedDataFromArweave(blockRangesForChains).catch((error) => {
|
|
428
|
+
delete this.arweaveDataCache[arweaveKey];
|
|
429
|
+
throw error;
|
|
430
|
+
});
|
|
369
431
|
}
|
|
370
432
|
const arweaveData = _.cloneDeep(await this.arweaveDataCache[arweaveKey]);
|
|
371
433
|
return arweaveData!;
|
|
@@ -382,11 +444,18 @@ export class BundleDataClient {
|
|
|
382
444
|
const key = JSON.stringify(blockRangesForChains);
|
|
383
445
|
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
384
446
|
if (!this.loadDataCache[key]) {
|
|
385
|
-
let arweaveData;
|
|
447
|
+
let arweaveData: LoadDataReturnValue | undefined;
|
|
386
448
|
if (attemptArweaveLoad) {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
449
|
+
try {
|
|
450
|
+
arweaveData = await this.loadArweaveData(blockRangesForChains);
|
|
451
|
+
} catch (error) {
|
|
452
|
+
this.logger.warn({
|
|
453
|
+
at: "BundleDataClient#loadData",
|
|
454
|
+
message: "Failed to load bundle data from Arweave, falling back to on-chain reconstruction",
|
|
455
|
+
blockRanges: JSON.stringify(blockRangesForChains),
|
|
456
|
+
error: String(error),
|
|
457
|
+
});
|
|
458
|
+
}
|
|
390
459
|
}
|
|
391
460
|
const data = isDefined(arweaveData)
|
|
392
461
|
? // We can return the data to a Promise to keep the return type consistent.
|
|
@@ -378,7 +378,7 @@ export class Coingecko {
|
|
|
378
378
|
return this.call("asset_platforms");
|
|
379
379
|
}
|
|
380
380
|
|
|
381
|
-
|
|
381
|
+
call<T>(path: string): Promise<T> {
|
|
382
382
|
const sendRequest = async () => {
|
|
383
383
|
const { proHost } = this;
|
|
384
384
|
|
|
@@ -401,14 +401,7 @@ export class Coingecko {
|
|
|
401
401
|
};
|
|
402
402
|
|
|
403
403
|
// Note: If a pro API key is configured, there is no need to retry as the Pro API will act as the basic's fall back.
|
|
404
|
-
|
|
405
|
-
retries: this.apiKey === undefined ? this.numRetries : 0,
|
|
406
|
-
delaySeconds: this.retryDelay,
|
|
407
|
-
});
|
|
408
|
-
if (!result.ok) {
|
|
409
|
-
throw result.error;
|
|
410
|
-
}
|
|
411
|
-
return result.value;
|
|
404
|
+
return retry(sendRequest, this.apiKey === undefined ? this.numRetries : 0, this.retryDelay);
|
|
412
405
|
}
|
|
413
406
|
|
|
414
407
|
protected getPriceCache(currency: string, platform_id: string): { [addr: string]: CoinGeckoPrice } {
|
|
@@ -54,3 +54,7 @@ export function getDepositKey(bridgeEvent: Deposit | Fill | SlowFillRequest): st
|
|
|
54
54
|
const relayHash = getRelayEventKey(bridgeEvent);
|
|
55
55
|
return `deposit_${bridgeEvent.originChainId}_${bridgeEvent.depositId.toString()}_${relayHash}`;
|
|
56
56
|
}
|
|
57
|
+
|
|
58
|
+
export function getArweaveTopicCacheKey(tag: string): string {
|
|
59
|
+
return `arweave-topic:${tag}`;
|
|
60
|
+
}
|