@gainsnetwork/sdk 1.0.6-rc1 → 1.0.6-rc3
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.
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
import { SignedPricesResponse } from "./types";
|
|
1
|
+
import { Oracle, SignedPricesResponse } from "./types";
|
|
2
2
|
import { PendingOrderType } from "../../trade";
|
|
3
3
|
export interface FetchSignedPricesInput {
|
|
4
|
-
oracles:
|
|
4
|
+
oracles: Oracle[];
|
|
5
5
|
pairs: number[];
|
|
6
6
|
chain: number;
|
|
7
|
-
authKey?: string;
|
|
8
7
|
minAnswer?: number;
|
|
9
8
|
timeoutMs?: number;
|
|
10
9
|
}
|
|
11
10
|
export declare const fetchSignedPrices: (input: FetchSignedPricesInput) => Promise<SignedPricesResponse[] | null>;
|
|
12
11
|
export interface FetchSignedLookbackPricesInput {
|
|
13
|
-
oracles:
|
|
12
|
+
oracles: Oracle[];
|
|
14
13
|
trader: string;
|
|
15
14
|
tradeIndex: number;
|
|
16
15
|
pair: number;
|
|
@@ -18,7 +17,6 @@ export interface FetchSignedLookbackPricesInput {
|
|
|
18
17
|
currentBlock: number;
|
|
19
18
|
fromBlock: number;
|
|
20
19
|
chain: number;
|
|
21
|
-
authKey?: string;
|
|
22
20
|
minAnswer?: number;
|
|
23
21
|
timeoutMs?: number;
|
|
24
22
|
}
|
|
@@ -5,7 +5,7 @@ exports.isValidSignedPricesOrderType = exports.isValidSignedPricesChain = export
|
|
|
5
5
|
const types_1 = require("../../contracts/types");
|
|
6
6
|
const trade_1 = require("../../trade");
|
|
7
7
|
const fetchSignedPrices = async (input) => {
|
|
8
|
-
const { minAnswers, timeoutMs, oracles, chain
|
|
8
|
+
const { minAnswers, timeoutMs, oracles, chain } = {
|
|
9
9
|
minAnswers: input.chain === types_1.ChainId.ARBITRUM_SEPOLIA ? 2 : 3,
|
|
10
10
|
timeoutMs: 1000,
|
|
11
11
|
...input,
|
|
@@ -15,11 +15,11 @@ const fetchSignedPrices = async (input) => {
|
|
|
15
15
|
const { valid, pairs } = (0, exports.validateSignedPricesPairs)(input.pairs);
|
|
16
16
|
if (!valid)
|
|
17
17
|
throw new Error(`Invalid pairs array`);
|
|
18
|
-
return await initiateSignedPricesRequest(oracles, "signPrices", JSON.stringify({ pairs, chain }), minAnswers,
|
|
18
|
+
return await initiateSignedPricesRequest(oracles, "signPrices", JSON.stringify({ pairs, chain }), minAnswers, timeoutMs);
|
|
19
19
|
};
|
|
20
20
|
exports.fetchSignedPrices = fetchSignedPrices;
|
|
21
21
|
const fetchSignedLookbackPrices = async (input) => {
|
|
22
|
-
const { minAnswers, timeoutMs, oracles, trader, tradeIndex, pair, orderType, currentBlock, fromBlock, chain,
|
|
22
|
+
const { minAnswers, timeoutMs, oracles, trader, tradeIndex, pair, orderType, currentBlock, fromBlock, chain, } = {
|
|
23
23
|
minAnswers: input.chain === types_1.ChainId.ARBITRUM_SEPOLIA ? 2 : 3,
|
|
24
24
|
timeoutMs: 6000,
|
|
25
25
|
...input,
|
|
@@ -34,6 +34,7 @@ const fetchSignedLookbackPrices = async (input) => {
|
|
|
34
34
|
throw new Error(`Invalid tradeIndex ${tradeIndex}`);
|
|
35
35
|
if (!currentBlock || !fromBlock)
|
|
36
36
|
throw new Error(`Invalid block numbers`);
|
|
37
|
+
// @todo handle filtering to minAnswers
|
|
37
38
|
return await initiateSignedPricesRequest(oracles, "signLookbackPrices", JSON.stringify({
|
|
38
39
|
trader,
|
|
39
40
|
tradeIndex,
|
|
@@ -42,13 +43,14 @@ const fetchSignedLookbackPrices = async (input) => {
|
|
|
42
43
|
currentBlock,
|
|
43
44
|
fromBlock,
|
|
44
45
|
chain,
|
|
45
|
-
}), minAnswers,
|
|
46
|
+
}), minAnswers, timeoutMs);
|
|
46
47
|
};
|
|
47
48
|
exports.fetchSignedLookbackPrices = fetchSignedLookbackPrices;
|
|
48
|
-
|
|
49
|
+
// @todo optional filtering to minAnswers best responses
|
|
50
|
+
const initiateSignedPricesRequest = async (oracles, request, requestBody, minAnswers, timeoutMs) => {
|
|
49
51
|
try {
|
|
50
52
|
// Fetch signed prices from all oracles in parallel
|
|
51
|
-
const signedPrices = await Promise.allSettled(oracles.map(
|
|
53
|
+
const signedPrices = await Promise.allSettled(oracles.map(oracle => _getSignedPricesFromSigner(`${oracle.url}/${request}`, requestBody, oracle?.key, timeoutMs)));
|
|
52
54
|
// Filter out failed requests and null responses, then sort by signerId
|
|
53
55
|
const successfulResponses = signedPrices.filter(res => res.status === "fulfilled" && res.value !== null // Filter out failed or null responses
|
|
54
56
|
)
|