@chainflip/rpc 2.1.4 → 2.1.5

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/Client.cjs CHANGED
@@ -1,5 +1,6 @@
1
1
  const require_common = require('./common.cjs');
2
2
  let _chainflip_utils_async = require("@chainflip/utils/async");
3
+ let timers_promises = require("timers/promises");
3
4
 
4
5
  //#region src/Client.ts
5
6
  var Client = class {
@@ -7,10 +8,12 @@ var Client = class {
7
8
  timer = null;
8
9
  requestMap = /* @__PURE__ */ new Map();
9
10
  archiveNodeUrl;
11
+ retryOnHeaderNotFound;
10
12
  eventTarget = new EventTarget();
11
13
  constructor(url, opts = {}) {
12
14
  this.url = url;
13
15
  this.archiveNodeUrl = opts.archiveNodeUrl;
16
+ this.retryOnHeaderNotFound = opts.retryOnHeaderNotFound ?? false;
14
17
  }
15
18
  getRequestId() {
16
19
  try {
@@ -54,7 +57,7 @@ var Client = class {
54
57
  item.deferred.reject(/* @__PURE__ */ new Error("Could not find the result for the request"));
55
58
  });
56
59
  }
57
- sendRequest(method, ...params) {
60
+ enqueueRequest(method, params) {
58
61
  if (!require_common.rpcResult[method]) return Promise.reject(/* @__PURE__ */ new Error(`Unknown method: ${method}`));
59
62
  const deferred = (0, _chainflip_utils_async.deferredPromise)();
60
63
  const body = this.formatRequest(method, params);
@@ -67,19 +70,36 @@ var Client = class {
67
70
  this.timer = null;
68
71
  this.handleBatch();
69
72
  }, 0);
70
- return deferred.promise.catch((error) => {
71
- if (error instanceof Error) {
72
- if (this.archiveNodeUrl && error.message.includes("Unknown block: State already discarded")) {
73
- this.eventTarget.dispatchEvent(new CustomEvent("archiveNodeFallback", { detail: {
74
- method,
75
- params
76
- } }));
77
- return new this.constructor(this.archiveNodeUrl).sendRequest(method, ...params);
78
- }
79
- Error.captureStackTrace(error);
73
+ return deferred.promise;
74
+ }
75
+ async sendRequest(method, ...params) {
76
+ const retries = this.retryOnHeaderNotFound ? 5 : 0;
77
+ let lastError;
78
+ for (let i = 0; i <= retries; i += 1) {
79
+ const result = await this.enqueueRequest(method, params).then((value) => ({
80
+ ok: true,
81
+ value
82
+ }), (error) => ({
83
+ ok: false,
84
+ error
85
+ }));
86
+ if (result.ok) return result.value;
87
+ lastError = result.error;
88
+ if (i < retries && lastError.message.includes("Unknown block: Header was not found in the database")) {
89
+ await (0, timers_promises.setTimeout)(6e3);
90
+ continue;
80
91
  }
81
- throw error;
82
- });
92
+ break;
93
+ }
94
+ if (this.archiveNodeUrl && lastError.message.includes("Unknown block: State already discarded")) {
95
+ this.eventTarget.dispatchEvent(new CustomEvent("archiveNodeFallback", { detail: {
96
+ method,
97
+ params
98
+ } }));
99
+ return new this.constructor(this.archiveNodeUrl).sendRequest(method, ...params);
100
+ }
101
+ if (lastError instanceof Error) Error.captureStackTrace(lastError);
102
+ throw lastError;
83
103
  }
84
104
  methods() {
85
105
  return Object.keys(require_common.rpcResult).sort();
package/dist/Client.d.cts CHANGED
@@ -18,6 +18,7 @@ type RequestMap = Map<string, {
18
18
  }>;
19
19
  type ClientOpts = {
20
20
  archiveNodeUrl?: string;
21
+ retryOnHeaderNotFound?: boolean;
21
22
  };
22
23
  declare abstract class Client {
23
24
  protected readonly url: string;
@@ -25,6 +26,7 @@ declare abstract class Client {
25
26
  private timer;
26
27
  private requestMap;
27
28
  private readonly archiveNodeUrl?;
29
+ private readonly retryOnHeaderNotFound;
28
30
  readonly eventTarget: EventTarget;
29
31
  constructor(url: string, opts?: ClientOpts);
30
32
  protected abstract send<const T extends RpcMethod>(data: JsonRpcRequest<T>[], clonedMap: RequestMap): Promise<void>;
@@ -33,6 +35,7 @@ declare abstract class Client {
33
35
  protected handleResponse(response: Response, clonedMap: RequestMap): void;
34
36
  protected handleErrorResponse(error: Error, clonedMap: RequestMap): void;
35
37
  private handleBatch;
38
+ private enqueueRequest;
36
39
  sendRequest<const T extends RpcMethod>(method: T, ...params: RpcRequest[T]): Promise<RpcResult<T>>;
37
40
  methods(): RpcMethod[];
38
41
  }
package/dist/Client.d.mts CHANGED
@@ -18,6 +18,7 @@ type RequestMap = Map<string, {
18
18
  }>;
19
19
  type ClientOpts = {
20
20
  archiveNodeUrl?: string;
21
+ retryOnHeaderNotFound?: boolean;
21
22
  };
22
23
  declare abstract class Client {
23
24
  protected readonly url: string;
@@ -25,6 +26,7 @@ declare abstract class Client {
25
26
  private timer;
26
27
  private requestMap;
27
28
  private readonly archiveNodeUrl?;
29
+ private readonly retryOnHeaderNotFound;
28
30
  readonly eventTarget: EventTarget;
29
31
  constructor(url: string, opts?: ClientOpts);
30
32
  protected abstract send<const T extends RpcMethod>(data: JsonRpcRequest<T>[], clonedMap: RequestMap): Promise<void>;
@@ -33,6 +35,7 @@ declare abstract class Client {
33
35
  protected handleResponse(response: Response, clonedMap: RequestMap): void;
34
36
  protected handleErrorResponse(error: Error, clonedMap: RequestMap): void;
35
37
  private handleBatch;
38
+ private enqueueRequest;
36
39
  sendRequest<const T extends RpcMethod>(method: T, ...params: RpcRequest[T]): Promise<RpcResult<T>>;
37
40
  methods(): RpcMethod[];
38
41
  }
package/dist/Client.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import { rpcResult } from "./common.mjs";
2
2
  import { deferredPromise } from "@chainflip/utils/async";
3
+ import { setTimeout as setTimeout$1 } from "timers/promises";
3
4
 
4
5
  //#region src/Client.ts
5
6
  var Client = class {
@@ -7,10 +8,12 @@ var Client = class {
7
8
  timer = null;
8
9
  requestMap = /* @__PURE__ */ new Map();
9
10
  archiveNodeUrl;
11
+ retryOnHeaderNotFound;
10
12
  eventTarget = new EventTarget();
11
13
  constructor(url, opts = {}) {
12
14
  this.url = url;
13
15
  this.archiveNodeUrl = opts.archiveNodeUrl;
16
+ this.retryOnHeaderNotFound = opts.retryOnHeaderNotFound ?? false;
14
17
  }
15
18
  getRequestId() {
16
19
  try {
@@ -54,7 +57,7 @@ var Client = class {
54
57
  item.deferred.reject(/* @__PURE__ */ new Error("Could not find the result for the request"));
55
58
  });
56
59
  }
57
- sendRequest(method, ...params) {
60
+ enqueueRequest(method, params) {
58
61
  if (!rpcResult[method]) return Promise.reject(/* @__PURE__ */ new Error(`Unknown method: ${method}`));
59
62
  const deferred = deferredPromise();
60
63
  const body = this.formatRequest(method, params);
@@ -67,19 +70,36 @@ var Client = class {
67
70
  this.timer = null;
68
71
  this.handleBatch();
69
72
  }, 0);
70
- return deferred.promise.catch((error) => {
71
- if (error instanceof Error) {
72
- if (this.archiveNodeUrl && error.message.includes("Unknown block: State already discarded")) {
73
- this.eventTarget.dispatchEvent(new CustomEvent("archiveNodeFallback", { detail: {
74
- method,
75
- params
76
- } }));
77
- return new this.constructor(this.archiveNodeUrl).sendRequest(method, ...params);
78
- }
79
- Error.captureStackTrace(error);
73
+ return deferred.promise;
74
+ }
75
+ async sendRequest(method, ...params) {
76
+ const retries = this.retryOnHeaderNotFound ? 5 : 0;
77
+ let lastError;
78
+ for (let i = 0; i <= retries; i += 1) {
79
+ const result = await this.enqueueRequest(method, params).then((value) => ({
80
+ ok: true,
81
+ value
82
+ }), (error) => ({
83
+ ok: false,
84
+ error
85
+ }));
86
+ if (result.ok) return result.value;
87
+ lastError = result.error;
88
+ if (i < retries && lastError.message.includes("Unknown block: Header was not found in the database")) {
89
+ await setTimeout$1(6e3);
90
+ continue;
80
91
  }
81
- throw error;
82
- });
92
+ break;
93
+ }
94
+ if (this.archiveNodeUrl && lastError.message.includes("Unknown block: State already discarded")) {
95
+ this.eventTarget.dispatchEvent(new CustomEvent("archiveNodeFallback", { detail: {
96
+ method,
97
+ params
98
+ } }));
99
+ return new this.constructor(this.archiveNodeUrl).sendRequest(method, ...params);
100
+ }
101
+ if (lastError instanceof Error) Error.captureStackTrace(lastError);
102
+ throw lastError;
83
103
  }
84
104
  methods() {
85
105
  return Object.keys(rpcResult).sort();
package/dist/common.cjs CHANGED
@@ -50,7 +50,8 @@ const rpcResult = {
50
50
  cf_lending_config: require_parsers.cfLendingConfig,
51
51
  cf_loan_accounts: require_parsers.cfLoanAccounts,
52
52
  cf_lending_pool_supply_balances: require_parsers.cfLendingPoolSupplyBalances,
53
- cf_get_vault_addresses: require_parsers.cfVaultAddresses
53
+ cf_get_vault_addresses: require_parsers.cfVaultAddresses,
54
+ cf_ingress_egress_events: require_parsers.cfIngressEgressEvents
54
55
  };
55
56
 
56
57
  //#endregion
package/dist/common.d.cts CHANGED
@@ -117,6 +117,7 @@ type RpcRequest = WithHash<{
117
117
  cf_loan_accounts: [accountId?: string];
118
118
  cf_lending_pool_supply_balances: [asset?: UncheckedAssetAndChain];
119
119
  cf_get_vault_addresses: [];
120
+ cf_ingress_egress_events: [chain: Chain];
120
121
  }> & {
121
122
  chain_getBlockHash: [blockHeight?: number];
122
123
  broker_request_swap_deposit_address: [sourceAsset: UncheckedAssetAndChain, destinationAsset: UncheckedAssetAndChain, destinationAddress: string, brokerCommission: number, ccmMetadata: Nullish<CcmParams>, boostFee: Nullish<number>, affiliateFees: Nullish<{
@@ -30759,6 +30760,347 @@ declare const rpcResult: {
30759
30760
  Btc: number[];
30760
30761
  }][];
30761
30762
  }>;
30763
+ readonly cf_ingress_egress_events: z.ZodObject<{
30764
+ deposits: z.ZodArray<z.ZodObject<{
30765
+ deposit_chain_block_height: z.ZodNumber;
30766
+ deposit_address: z.ZodString;
30767
+ amount: z.ZodString;
30768
+ asset: z.ZodObject<{
30769
+ chain: z.ZodString;
30770
+ asset: z.ZodString;
30771
+ }, "strip", z.ZodTypeAny, {
30772
+ chain: string;
30773
+ asset: string;
30774
+ }, {
30775
+ chain: string;
30776
+ asset: string;
30777
+ }>;
30778
+ deposit_details: z.ZodNullable<z.ZodUnion<[z.ZodObject<{
30779
+ tx_hashes: z.ZodArray<z.ZodString, "many">;
30780
+ }, "strip", z.ZodTypeAny, {
30781
+ tx_hashes: string[];
30782
+ }, {
30783
+ tx_hashes: string[];
30784
+ }>, z.ZodObject<{
30785
+ tx_id: z.ZodString;
30786
+ vout: z.ZodNumber;
30787
+ }, "strip", z.ZodTypeAny, {
30788
+ tx_id: string;
30789
+ vout: number;
30790
+ }, {
30791
+ tx_id: string;
30792
+ vout: number;
30793
+ }>]>>;
30794
+ }, "strip", z.ZodTypeAny, {
30795
+ deposit_address: string;
30796
+ asset: {
30797
+ chain: string;
30798
+ asset: string;
30799
+ };
30800
+ amount: string;
30801
+ deposit_chain_block_height: number;
30802
+ deposit_details: {
30803
+ tx_hashes: string[];
30804
+ } | {
30805
+ tx_id: string;
30806
+ vout: number;
30807
+ } | null;
30808
+ }, {
30809
+ deposit_address: string;
30810
+ asset: {
30811
+ chain: string;
30812
+ asset: string;
30813
+ };
30814
+ amount: string;
30815
+ deposit_chain_block_height: number;
30816
+ deposit_details: {
30817
+ tx_hashes: string[];
30818
+ } | {
30819
+ tx_id: string;
30820
+ vout: number;
30821
+ } | null;
30822
+ }>, "many">;
30823
+ broadcasts: z.ZodArray<z.ZodObject<{
30824
+ broadcast_id: z.ZodNumber;
30825
+ broadcast_chain_block_height: z.ZodNumber;
30826
+ tx_out_id: z.ZodUnknown;
30827
+ tx_ref: z.ZodUnknown;
30828
+ }, "strip", z.ZodTypeAny, {
30829
+ broadcast_id: number;
30830
+ broadcast_chain_block_height: number;
30831
+ tx_out_id?: unknown;
30832
+ tx_ref?: unknown;
30833
+ }, {
30834
+ broadcast_id: number;
30835
+ broadcast_chain_block_height: number;
30836
+ tx_out_id?: unknown;
30837
+ tx_ref?: unknown;
30838
+ }>, "many">;
30839
+ vault_deposits: z.ZodArray<z.ZodObject<{
30840
+ tx_id: z.ZodString;
30841
+ deposit_chain_block_height: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
30842
+ input_asset: z.ZodObject<{
30843
+ chain: z.ZodString;
30844
+ asset: z.ZodString;
30845
+ }, "strip", z.ZodTypeAny, {
30846
+ chain: string;
30847
+ asset: string;
30848
+ }, {
30849
+ chain: string;
30850
+ asset: string;
30851
+ }>;
30852
+ output_asset: z.ZodObject<{
30853
+ chain: z.ZodString;
30854
+ asset: z.ZodString;
30855
+ }, "strip", z.ZodTypeAny, {
30856
+ chain: string;
30857
+ asset: string;
30858
+ }, {
30859
+ chain: string;
30860
+ asset: string;
30861
+ }>;
30862
+ amount: z.ZodString;
30863
+ destination_address: z.ZodString;
30864
+ ccm_deposit_metadata: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
30865
+ deposit_details: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
30866
+ broker_fee: z.ZodOptional<z.ZodNullable<z.ZodObject<{
30867
+ account: z.ZodString;
30868
+ bps: z.ZodNumber;
30869
+ }, "strip", z.ZodTypeAny, {
30870
+ account: string;
30871
+ bps: number;
30872
+ }, {
30873
+ account: string;
30874
+ bps: number;
30875
+ }>>>;
30876
+ affiliate_fees: z.ZodArray<z.ZodObject<{
30877
+ account: z.ZodString;
30878
+ bps: z.ZodNumber;
30879
+ }, "strip", z.ZodTypeAny, {
30880
+ account: string;
30881
+ bps: number;
30882
+ }, {
30883
+ account: string;
30884
+ bps: number;
30885
+ }>, "many">;
30886
+ refund_params: z.ZodOptional<z.ZodNullable<z.ZodObject<{
30887
+ retry_duration: z.ZodNumber;
30888
+ refund_address: z.ZodString;
30889
+ min_price: z.ZodString;
30890
+ refund_ccm_metadata: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
30891
+ max_oracle_price_slippage: z.ZodOptional<z.ZodNullable<z.ZodUnknown>>;
30892
+ }, "strip", z.ZodTypeAny, {
30893
+ refund_address: string;
30894
+ retry_duration: number;
30895
+ min_price: string;
30896
+ refund_ccm_metadata?: unknown;
30897
+ max_oracle_price_slippage?: unknown;
30898
+ }, {
30899
+ refund_address: string;
30900
+ retry_duration: number;
30901
+ min_price: string;
30902
+ refund_ccm_metadata?: unknown;
30903
+ max_oracle_price_slippage?: unknown;
30904
+ }>>>;
30905
+ dca_params: z.ZodOptional<z.ZodNullable<z.ZodObject<{
30906
+ number_of_chunks: z.ZodNumber;
30907
+ chunk_interval: z.ZodNumber;
30908
+ }, "strip", z.ZodTypeAny, {
30909
+ number_of_chunks: number;
30910
+ chunk_interval: number;
30911
+ }, {
30912
+ number_of_chunks: number;
30913
+ chunk_interval: number;
30914
+ }>>>;
30915
+ max_boost_fee: z.ZodOptional<z.ZodNumber>;
30916
+ }, "strip", z.ZodTypeAny, {
30917
+ amount: string;
30918
+ tx_id: string;
30919
+ input_asset: {
30920
+ chain: string;
30921
+ asset: string;
30922
+ };
30923
+ output_asset: {
30924
+ chain: string;
30925
+ asset: string;
30926
+ };
30927
+ destination_address: string;
30928
+ affiliate_fees: {
30929
+ account: string;
30930
+ bps: number;
30931
+ }[];
30932
+ deposit_chain_block_height?: number | null | undefined;
30933
+ deposit_details?: unknown;
30934
+ ccm_deposit_metadata?: unknown;
30935
+ broker_fee?: {
30936
+ account: string;
30937
+ bps: number;
30938
+ } | null | undefined;
30939
+ refund_params?: {
30940
+ refund_address: string;
30941
+ retry_duration: number;
30942
+ min_price: string;
30943
+ refund_ccm_metadata?: unknown;
30944
+ max_oracle_price_slippage?: unknown;
30945
+ } | null | undefined;
30946
+ dca_params?: {
30947
+ number_of_chunks: number;
30948
+ chunk_interval: number;
30949
+ } | null | undefined;
30950
+ max_boost_fee?: number | undefined;
30951
+ }, {
30952
+ amount: string;
30953
+ tx_id: string;
30954
+ input_asset: {
30955
+ chain: string;
30956
+ asset: string;
30957
+ };
30958
+ output_asset: {
30959
+ chain: string;
30960
+ asset: string;
30961
+ };
30962
+ destination_address: string;
30963
+ affiliate_fees: {
30964
+ account: string;
30965
+ bps: number;
30966
+ }[];
30967
+ deposit_chain_block_height?: number | null | undefined;
30968
+ deposit_details?: unknown;
30969
+ ccm_deposit_metadata?: unknown;
30970
+ broker_fee?: {
30971
+ account: string;
30972
+ bps: number;
30973
+ } | null | undefined;
30974
+ refund_params?: {
30975
+ refund_address: string;
30976
+ retry_duration: number;
30977
+ min_price: string;
30978
+ refund_ccm_metadata?: unknown;
30979
+ max_oracle_price_slippage?: unknown;
30980
+ } | null | undefined;
30981
+ dca_params?: {
30982
+ number_of_chunks: number;
30983
+ chunk_interval: number;
30984
+ } | null | undefined;
30985
+ max_boost_fee?: number | undefined;
30986
+ }>, "many">;
30987
+ }, "strip", z.ZodTypeAny, {
30988
+ deposits: {
30989
+ deposit_address: string;
30990
+ asset: {
30991
+ chain: string;
30992
+ asset: string;
30993
+ };
30994
+ amount: string;
30995
+ deposit_chain_block_height: number;
30996
+ deposit_details: {
30997
+ tx_hashes: string[];
30998
+ } | {
30999
+ tx_id: string;
31000
+ vout: number;
31001
+ } | null;
31002
+ }[];
31003
+ broadcasts: {
31004
+ broadcast_id: number;
31005
+ broadcast_chain_block_height: number;
31006
+ tx_out_id?: unknown;
31007
+ tx_ref?: unknown;
31008
+ }[];
31009
+ vault_deposits: {
31010
+ amount: string;
31011
+ tx_id: string;
31012
+ input_asset: {
31013
+ chain: string;
31014
+ asset: string;
31015
+ };
31016
+ output_asset: {
31017
+ chain: string;
31018
+ asset: string;
31019
+ };
31020
+ destination_address: string;
31021
+ affiliate_fees: {
31022
+ account: string;
31023
+ bps: number;
31024
+ }[];
31025
+ deposit_chain_block_height?: number | null | undefined;
31026
+ deposit_details?: unknown;
31027
+ ccm_deposit_metadata?: unknown;
31028
+ broker_fee?: {
31029
+ account: string;
31030
+ bps: number;
31031
+ } | null | undefined;
31032
+ refund_params?: {
31033
+ refund_address: string;
31034
+ retry_duration: number;
31035
+ min_price: string;
31036
+ refund_ccm_metadata?: unknown;
31037
+ max_oracle_price_slippage?: unknown;
31038
+ } | null | undefined;
31039
+ dca_params?: {
31040
+ number_of_chunks: number;
31041
+ chunk_interval: number;
31042
+ } | null | undefined;
31043
+ max_boost_fee?: number | undefined;
31044
+ }[];
31045
+ }, {
31046
+ deposits: {
31047
+ deposit_address: string;
31048
+ asset: {
31049
+ chain: string;
31050
+ asset: string;
31051
+ };
31052
+ amount: string;
31053
+ deposit_chain_block_height: number;
31054
+ deposit_details: {
31055
+ tx_hashes: string[];
31056
+ } | {
31057
+ tx_id: string;
31058
+ vout: number;
31059
+ } | null;
31060
+ }[];
31061
+ broadcasts: {
31062
+ broadcast_id: number;
31063
+ broadcast_chain_block_height: number;
31064
+ tx_out_id?: unknown;
31065
+ tx_ref?: unknown;
31066
+ }[];
31067
+ vault_deposits: {
31068
+ amount: string;
31069
+ tx_id: string;
31070
+ input_asset: {
31071
+ chain: string;
31072
+ asset: string;
31073
+ };
31074
+ output_asset: {
31075
+ chain: string;
31076
+ asset: string;
31077
+ };
31078
+ destination_address: string;
31079
+ affiliate_fees: {
31080
+ account: string;
31081
+ bps: number;
31082
+ }[];
31083
+ deposit_chain_block_height?: number | null | undefined;
31084
+ deposit_details?: unknown;
31085
+ ccm_deposit_metadata?: unknown;
31086
+ broker_fee?: {
31087
+ account: string;
31088
+ bps: number;
31089
+ } | null | undefined;
31090
+ refund_params?: {
31091
+ refund_address: string;
31092
+ retry_duration: number;
31093
+ min_price: string;
31094
+ refund_ccm_metadata?: unknown;
31095
+ max_oracle_price_slippage?: unknown;
31096
+ } | null | undefined;
31097
+ dca_params?: {
31098
+ number_of_chunks: number;
31099
+ chunk_interval: number;
31100
+ } | null | undefined;
31101
+ max_boost_fee?: number | undefined;
31102
+ }[];
31103
+ }>;
30762
31104
  };
30763
31105
  type RpcMethod = keyof RpcRequest;
30764
31106
  type RpcResponse<T extends RpcMethod> = z.input<(typeof rpcResult)[T]>;