@avail-project/ca-common 1.0.1 → 2.1.0
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/evmabi/fibrousrouter.abi.js +41 -0
- package/dist/cjs/evmabi/index.js +1 -0
- package/dist/cjs/proto/definition.js +153 -4
- package/dist/cjs/xcs/autochoice.js +96 -237
- package/dist/cjs/xcs/bebop-agg.js +34 -5
- package/dist/cjs/xcs/fibrous-agg.js +149 -0
- package/dist/cjs/xcs/index.js +1 -1
- package/dist/cjs/xcs/lifi-agg.js +34 -5
- package/dist/esm/evmabi/fibrousrouter.abi.js +38 -0
- package/dist/esm/evmabi/index.js +1 -0
- package/dist/esm/proto/definition.js +151 -3
- package/dist/esm/xcs/autochoice.js +98 -238
- package/dist/esm/xcs/bebop-agg.js +34 -5
- package/dist/esm/xcs/fibrous-agg.js +144 -0
- package/dist/esm/xcs/index.js +1 -1
- package/dist/esm/xcs/lifi-agg.js +34 -5
- package/dist/types/evmabi/fibrousrouter.abi.d.ts +77 -0
- package/dist/types/evmabi/index.d.ts +1 -0
- package/dist/types/proto/definition.d.ts +9 -0
- package/dist/types/xcs/autochoice.d.ts +6 -52
- package/dist/types/xcs/bebop-agg.d.ts +2 -2
- package/dist/types/xcs/fibrous-agg.d.ts +54 -0
- package/dist/types/xcs/iface.d.ts +37 -5
- package/dist/types/xcs/index.d.ts +1 -1
- package/dist/types/xcs/lifi-agg.d.ts +18 -14
- package/package.json +5 -2
- package/dist/cjs/xcs/yieldyak-agg.js +0 -113
- package/dist/esm/xcs/yieldyak-agg.js +0 -109
- package/dist/types/xcs/yieldyak-agg.d.ts +0 -21
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import axios, { AxiosError } from "axios";
|
|
2
|
+
import Decimal from "decimal.js";
|
|
3
|
+
import { bytesToHex, encodeFunctionData, getAddress, toHex, zeroAddress, } from "viem";
|
|
4
|
+
import { ChainIDKeyedMap, OmniversalChainID } from "../data";
|
|
5
|
+
import { FibrousRouterABI } from "../evmabi";
|
|
6
|
+
import { Universe } from "../proto/definition";
|
|
7
|
+
import { QuoteType, } from "./iface";
|
|
8
|
+
const ChainNameMapping = new ChainIDKeyedMap([
|
|
9
|
+
[new OmniversalChainID(Universe.ETHEREUM, 8453), "base"],
|
|
10
|
+
[new OmniversalChainID(Universe.ETHEREUM, 999), "hyperevm"],
|
|
11
|
+
[new OmniversalChainID(Universe.ETHEREUM, 143), "monad"],
|
|
12
|
+
[new OmniversalChainID(Universe.ETHEREUM, 4114), "citrea"],
|
|
13
|
+
]);
|
|
14
|
+
export class FibrousAggregator {
|
|
15
|
+
static BASE_URL = "https://api.fibrous.finance";
|
|
16
|
+
axios;
|
|
17
|
+
slippage;
|
|
18
|
+
constructor(options = {}) {
|
|
19
|
+
const { apiKey, slippage = 0.5 } = options;
|
|
20
|
+
this.slippage = slippage;
|
|
21
|
+
this.axios = axios.create({
|
|
22
|
+
baseURL: FibrousAggregator.BASE_URL,
|
|
23
|
+
headers: apiKey != null ? { "X-API-Key": apiKey } : undefined,
|
|
24
|
+
timeout: 10_000,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
async getQuotes(requests) {
|
|
28
|
+
const list = await Promise.allSettled(requests.map(async (r) => {
|
|
29
|
+
if (r.type === QuoteType.EXACT_OUT) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
if (r.chain.universe !== Universe.ETHEREUM) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
const chainName = ChainNameMapping.get(r.chain);
|
|
36
|
+
if (chainName == null) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
const inputTokenAddr = getAddress(bytesToHex(r.inputToken.subarray(12)));
|
|
40
|
+
const outputTokenAddr = getAddress(bytesToHex(r.outputToken.subarray(12)));
|
|
41
|
+
const userAddrHex = getAddress(bytesToHex(r.userAddress.subarray(12)));
|
|
42
|
+
let resp;
|
|
43
|
+
try {
|
|
44
|
+
resp = await this.axios({
|
|
45
|
+
method: "GET",
|
|
46
|
+
url: `/${chainName}/v2/routeAndCallData`,
|
|
47
|
+
params: {
|
|
48
|
+
amount: r.inputAmount.toString(),
|
|
49
|
+
tokenInAddress: inputTokenAddr,
|
|
50
|
+
tokenOutAddress: outputTokenAddr,
|
|
51
|
+
slippage: this.slippage,
|
|
52
|
+
destination: userAddrHex,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
if (e instanceof AxiosError && e.isAxiosError) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
throw e;
|
|
61
|
+
}
|
|
62
|
+
if (!resp.data.route.success) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
if (resp.data.calldata.swap_parameters.length === 0) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
const inputAmountInDecimal = new Decimal(resp.data.route.inputAmount)
|
|
69
|
+
.div(Decimal.pow(10, resp.data.route.inputToken.decimals))
|
|
70
|
+
.toFixed(resp.data.route.inputToken.decimals);
|
|
71
|
+
const outputAmountInDecimal = new Decimal(resp.data.calldata.route.min_received)
|
|
72
|
+
.div(Decimal.pow(10, resp.data.route.outputToken.decimals))
|
|
73
|
+
.toFixed(resp.data.route.outputToken.decimals);
|
|
74
|
+
const routerAddress = getAddress(resp.data.router_address);
|
|
75
|
+
const isNativeInput = resp.data.calldata.route.swap_type === 0;
|
|
76
|
+
const quote = {
|
|
77
|
+
originalResponse: resp.data,
|
|
78
|
+
input: {
|
|
79
|
+
amount: inputAmountInDecimal,
|
|
80
|
+
amountRaw: BigInt(resp.data.route.inputAmount),
|
|
81
|
+
contractAddress: inputTokenAddr,
|
|
82
|
+
decimals: resp.data.route.inputToken.decimals,
|
|
83
|
+
value: Decimal.mul(inputAmountInDecimal, resp.data.route.inputToken.price ?? 0).toNumber(),
|
|
84
|
+
symbol: resp.data.route.inputToken.symbol ??
|
|
85
|
+
resp.data.route.inputToken.name,
|
|
86
|
+
},
|
|
87
|
+
output: {
|
|
88
|
+
amount: outputAmountInDecimal,
|
|
89
|
+
amountRaw: BigInt(resp.data.calldata.route.min_received),
|
|
90
|
+
contractAddress: outputTokenAddr,
|
|
91
|
+
decimals: resp.data.route.outputToken.decimals,
|
|
92
|
+
value: Decimal.mul(outputAmountInDecimal, resp.data.route.outputToken.price ?? 0).toNumber(),
|
|
93
|
+
symbol: resp.data.route.outputToken.symbol ??
|
|
94
|
+
resp.data.route.outputToken.name,
|
|
95
|
+
},
|
|
96
|
+
txData: {
|
|
97
|
+
approvalAddress: isNativeInput ? zeroAddress : routerAddress,
|
|
98
|
+
tx: {
|
|
99
|
+
to: routerAddress,
|
|
100
|
+
value: isNativeInput
|
|
101
|
+
? toHex(BigInt(resp.data.calldata.route.amount_in))
|
|
102
|
+
: toHex(0),
|
|
103
|
+
data: encodeFunctionData({
|
|
104
|
+
abi: FibrousRouterABI,
|
|
105
|
+
functionName: "swap",
|
|
106
|
+
args: [
|
|
107
|
+
{
|
|
108
|
+
token_in: getAddress(resp.data.calldata.route.token_in),
|
|
109
|
+
token_out: getAddress(resp.data.calldata.route.token_out),
|
|
110
|
+
amount_in: BigInt(resp.data.calldata.route.amount_in),
|
|
111
|
+
amount_out: BigInt(resp.data.calldata.route.amount_out),
|
|
112
|
+
min_received: BigInt(resp.data.calldata.route.min_received),
|
|
113
|
+
destination: getAddress(resp.data.calldata.route.destination),
|
|
114
|
+
swap_type: resp.data.calldata.route.swap_type,
|
|
115
|
+
},
|
|
116
|
+
resp.data.calldata.swap_parameters.map((swapParameter) => ({
|
|
117
|
+
token_in: getAddress(swapParameter.token_in),
|
|
118
|
+
token_out: getAddress(swapParameter.token_out),
|
|
119
|
+
rate: Number.parseInt(swapParameter.rate, 10),
|
|
120
|
+
protocol_id: Number.parseInt(swapParameter.protocol_id, 10),
|
|
121
|
+
pool_address: getAddress(swapParameter.pool_address),
|
|
122
|
+
swap_type: swapParameter.swap_type,
|
|
123
|
+
extra_data: swapParameter.extra_data,
|
|
124
|
+
})),
|
|
125
|
+
],
|
|
126
|
+
}),
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
return quote;
|
|
131
|
+
}));
|
|
132
|
+
return list.map((item) => {
|
|
133
|
+
switch (item.status) {
|
|
134
|
+
case "fulfilled": {
|
|
135
|
+
return item.value;
|
|
136
|
+
}
|
|
137
|
+
case "rejected": {
|
|
138
|
+
console.error("Caught error in fetching Fibrous quotes:", item.reason);
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
package/dist/esm/xcs/index.js
CHANGED
package/dist/esm/xcs/lifi-agg.js
CHANGED
|
@@ -2,11 +2,13 @@ import axios, { AxiosError } from "axios";
|
|
|
2
2
|
import { bytesToHex, getAddress } from "viem";
|
|
3
3
|
import { QuoteType, } from "./iface";
|
|
4
4
|
import { Universe } from "../proto/definition";
|
|
5
|
+
import Decimal from "decimal.js";
|
|
5
6
|
export class LiFiAggregator {
|
|
6
7
|
static BASE_URL_V1 = "https://li.quest/v1";
|
|
7
8
|
static COMMON_OPTIONS = {
|
|
8
9
|
denyExchanges: "openocean",
|
|
9
10
|
slippage: "0.01",
|
|
11
|
+
skipSimulation: true,
|
|
10
12
|
};
|
|
11
13
|
axios;
|
|
12
14
|
constructor(apiKey) {
|
|
@@ -15,6 +17,7 @@ export class LiFiAggregator {
|
|
|
15
17
|
headers: {
|
|
16
18
|
"x-lifi-api-key": apiKey,
|
|
17
19
|
},
|
|
20
|
+
timeout: 10_000,
|
|
18
21
|
});
|
|
19
22
|
}
|
|
20
23
|
async getQuotes(requests) {
|
|
@@ -76,12 +79,38 @@ export class LiFiAggregator {
|
|
|
76
79
|
}
|
|
77
80
|
throw e;
|
|
78
81
|
}
|
|
82
|
+
const { estimate, transactionRequest: { to, value, data }, action: { fromToken, toToken }, } = resp.data;
|
|
83
|
+
const inputAmountInDecimal = new Decimal(estimate.fromAmount)
|
|
84
|
+
.div(Decimal.pow(10, fromToken.decimals))
|
|
85
|
+
.toFixed(fromToken.decimals);
|
|
86
|
+
const outputAmountInDecimal = new Decimal(estimate.toAmountMin)
|
|
87
|
+
.div(Decimal.pow(10, toToken.decimals))
|
|
88
|
+
.toFixed(toToken.decimals);
|
|
79
89
|
return {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
90
|
+
input: {
|
|
91
|
+
amount: inputAmountInDecimal,
|
|
92
|
+
amountRaw: BigInt(estimate.fromAmount),
|
|
93
|
+
contractAddress: inputTokenAddr,
|
|
94
|
+
decimals: fromToken.decimals,
|
|
95
|
+
value: Decimal.mul(inputAmountInDecimal, fromToken.priceUSD).toNumber(),
|
|
96
|
+
symbol: fromToken.symbol,
|
|
97
|
+
},
|
|
98
|
+
output: {
|
|
99
|
+
amount: outputAmountInDecimal,
|
|
100
|
+
amountRaw: BigInt(estimate.toAmountMin),
|
|
101
|
+
contractAddress: outputTokenAddr,
|
|
102
|
+
decimals: toToken.decimals,
|
|
103
|
+
value: Decimal.mul(outputAmountInDecimal, toToken.priceUSD).toNumber(),
|
|
104
|
+
symbol: toToken.symbol,
|
|
105
|
+
},
|
|
106
|
+
txData: {
|
|
107
|
+
approvalAddress: estimate.approvalAddress,
|
|
108
|
+
tx: {
|
|
109
|
+
to,
|
|
110
|
+
value,
|
|
111
|
+
data,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
85
114
|
};
|
|
86
115
|
}));
|
|
87
116
|
return list.map((item) => {
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
export declare const FibrousRouterABI: readonly [{
|
|
2
|
+
readonly inputs: readonly [{
|
|
3
|
+
readonly components: readonly [{
|
|
4
|
+
readonly internalType: "address";
|
|
5
|
+
readonly name: "token_in";
|
|
6
|
+
readonly type: "address";
|
|
7
|
+
}, {
|
|
8
|
+
readonly internalType: "address";
|
|
9
|
+
readonly name: "token_out";
|
|
10
|
+
readonly type: "address";
|
|
11
|
+
}, {
|
|
12
|
+
readonly internalType: "uint256";
|
|
13
|
+
readonly name: "amount_in";
|
|
14
|
+
readonly type: "uint256";
|
|
15
|
+
}, {
|
|
16
|
+
readonly internalType: "uint256";
|
|
17
|
+
readonly name: "amount_out";
|
|
18
|
+
readonly type: "uint256";
|
|
19
|
+
}, {
|
|
20
|
+
readonly internalType: "uint256";
|
|
21
|
+
readonly name: "min_received";
|
|
22
|
+
readonly type: "uint256";
|
|
23
|
+
}, {
|
|
24
|
+
readonly internalType: "address";
|
|
25
|
+
readonly name: "destination";
|
|
26
|
+
readonly type: "address";
|
|
27
|
+
}, {
|
|
28
|
+
readonly internalType: "uint8";
|
|
29
|
+
readonly name: "swap_type";
|
|
30
|
+
readonly type: "uint8";
|
|
31
|
+
}];
|
|
32
|
+
readonly internalType: "struct IFibrousRouter.RouteParam";
|
|
33
|
+
readonly name: "route";
|
|
34
|
+
readonly type: "tuple";
|
|
35
|
+
}, {
|
|
36
|
+
readonly components: readonly [{
|
|
37
|
+
readonly internalType: "address";
|
|
38
|
+
readonly name: "token_in";
|
|
39
|
+
readonly type: "address";
|
|
40
|
+
}, {
|
|
41
|
+
readonly internalType: "address";
|
|
42
|
+
readonly name: "token_out";
|
|
43
|
+
readonly type: "address";
|
|
44
|
+
}, {
|
|
45
|
+
readonly internalType: "uint32";
|
|
46
|
+
readonly name: "rate";
|
|
47
|
+
readonly type: "uint32";
|
|
48
|
+
}, {
|
|
49
|
+
readonly internalType: "int24";
|
|
50
|
+
readonly name: "protocol_id";
|
|
51
|
+
readonly type: "int24";
|
|
52
|
+
}, {
|
|
53
|
+
readonly internalType: "address";
|
|
54
|
+
readonly name: "pool_address";
|
|
55
|
+
readonly type: "address";
|
|
56
|
+
}, {
|
|
57
|
+
readonly internalType: "uint8";
|
|
58
|
+
readonly name: "swap_type";
|
|
59
|
+
readonly type: "uint8";
|
|
60
|
+
}, {
|
|
61
|
+
readonly internalType: "bytes";
|
|
62
|
+
readonly name: "extra_data";
|
|
63
|
+
readonly type: "bytes";
|
|
64
|
+
}];
|
|
65
|
+
readonly internalType: "struct IFibrousRouter.SwapParams[]";
|
|
66
|
+
readonly name: "swap_parameters";
|
|
67
|
+
readonly type: "tuple[]";
|
|
68
|
+
}];
|
|
69
|
+
readonly name: "swap";
|
|
70
|
+
readonly outputs: readonly [{
|
|
71
|
+
readonly internalType: "uint256";
|
|
72
|
+
readonly name: "";
|
|
73
|
+
readonly type: "uint256";
|
|
74
|
+
}];
|
|
75
|
+
readonly stateMutability: "payable";
|
|
76
|
+
readonly type: "function";
|
|
77
|
+
}];
|
|
@@ -227,12 +227,18 @@ export interface AdminFeeRecipient {
|
|
|
227
227
|
universe: Universe;
|
|
228
228
|
address: Uint8Array;
|
|
229
229
|
}
|
|
230
|
+
export interface PerChainFeeBP {
|
|
231
|
+
universe: Universe;
|
|
232
|
+
chainID: Uint8Array;
|
|
233
|
+
feeBP: Long;
|
|
234
|
+
}
|
|
230
235
|
export interface ProtocolFees {
|
|
231
236
|
feeBP: Long;
|
|
232
237
|
collectionFees: FixedFeeTuple[];
|
|
233
238
|
fulfilmentFees: FixedFeeTuple[];
|
|
234
239
|
admin: string;
|
|
235
240
|
feeRecipients: AdminFeeRecipient[];
|
|
241
|
+
perChainFeeBP: PerChainFeeBP[];
|
|
236
242
|
}
|
|
237
243
|
export interface QueryGetProtocolFeesRequest {
|
|
238
244
|
}
|
|
@@ -245,6 +251,7 @@ export interface MsgCreateProtocolFees {
|
|
|
245
251
|
collectionFees: FixedFeeTuple[];
|
|
246
252
|
fulfilmentFees: FixedFeeTuple[];
|
|
247
253
|
feeRecipients: AdminFeeRecipient[];
|
|
254
|
+
perChainFeeBP: PerChainFeeBP[];
|
|
248
255
|
}
|
|
249
256
|
export interface MsgCreateProtocolFeesResponse {
|
|
250
257
|
}
|
|
@@ -254,6 +261,7 @@ export interface MsgUpdateProtocolFees {
|
|
|
254
261
|
collectionFees: FixedFeeTuple[];
|
|
255
262
|
fulfilmentFees: FixedFeeTuple[];
|
|
256
263
|
feeRecipients: AdminFeeRecipient[];
|
|
264
|
+
perChainFeeBP: PerChainFeeBP[];
|
|
257
265
|
}
|
|
258
266
|
export interface MsgUpdateProtocolFeesResponse {
|
|
259
267
|
}
|
|
@@ -330,6 +338,7 @@ export declare const QueryAllSettlementResponse: MessageFns<QueryAllSettlementRe
|
|
|
330
338
|
export declare const QueryRequestForFundsByAddressRequest: MessageFns<QueryRequestForFundsByAddressRequest>;
|
|
331
339
|
export declare const FixedFeeTuple: MessageFns<FixedFeeTuple>;
|
|
332
340
|
export declare const AdminFeeRecipient: MessageFns<AdminFeeRecipient>;
|
|
341
|
+
export declare const PerChainFeeBP: MessageFns<PerChainFeeBP>;
|
|
333
342
|
export declare const ProtocolFees: MessageFns<ProtocolFees>;
|
|
334
343
|
export declare const QueryGetProtocolFeesRequest: MessageFns<QueryGetProtocolFeesRequest>;
|
|
335
344
|
export declare const QueryGetProtocolFeesResponse: MessageFns<QueryGetProtocolFeesResponse>;
|
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
import Decimal from "decimal.js";
|
|
2
|
-
import { Aggregator, Quote, QuoteRequestExactInput, QuoteRequestExactOutput } from "./iface";
|
|
2
|
+
import { Aggregator, Quote, QuoteRequestExactInput, QuoteRequestExactOutput, QuoteResponse } from "./iface";
|
|
3
3
|
import { Currency, CurrencyID, OmniversalChainID } from "../data";
|
|
4
4
|
import { Bytes } from "../types";
|
|
5
|
-
import {
|
|
6
|
-
type Asset = {
|
|
7
|
-
tokenAddress: Bytes;
|
|
8
|
-
amount: bigint;
|
|
9
|
-
};
|
|
10
|
-
export type Holding = {
|
|
11
|
-
chainID: OmniversalChainID;
|
|
12
|
-
value: number;
|
|
13
|
-
} & Asset;
|
|
5
|
+
import { Holding } from "./iface";
|
|
14
6
|
export declare class AutoSelectionError extends Error {
|
|
15
7
|
}
|
|
16
8
|
declare const enum AggregateAggregatorsMode {
|
|
@@ -22,15 +14,7 @@ export declare function aggregateAggregators(requests: (QuoteRequestExactInput |
|
|
|
22
14
|
aggregator: Aggregator;
|
|
23
15
|
}[]>;
|
|
24
16
|
export declare function autoSelectSourcesV2(userAddress: Bytes, holdings: Holding[], outputRequired: Decimal, aggregators: Aggregator[], commonCurrencyID?: CurrencyID): Promise<{
|
|
25
|
-
|
|
26
|
-
req: QuoteRequestExactInput;
|
|
27
|
-
originalHolding: Holding;
|
|
28
|
-
cur: Currency;
|
|
29
|
-
idx: number;
|
|
30
|
-
} & {
|
|
31
|
-
quote: Quote;
|
|
32
|
-
agg: Aggregator;
|
|
33
|
-
})[];
|
|
17
|
+
quoteResponses: QuoteResponse[];
|
|
34
18
|
usedCOTs: {
|
|
35
19
|
originalHolding: Holding;
|
|
36
20
|
amountUsed: Decimal;
|
|
@@ -38,37 +22,7 @@ export declare function autoSelectSourcesV2(userAddress: Bytes, holdings: Holdin
|
|
|
38
22
|
cur: Currency;
|
|
39
23
|
}[];
|
|
40
24
|
}>;
|
|
41
|
-
export declare function
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
originalHolding: Holding;
|
|
45
|
-
cur: Currency;
|
|
46
|
-
} & {
|
|
47
|
-
quote: Quote;
|
|
48
|
-
agg: Aggregator;
|
|
49
|
-
})[]>;
|
|
50
|
-
export declare function determineDestinationSwaps(userAddress: Bytes, chainID: OmniversalChainID, requirement: Asset, aggregators: Aggregator[], commonCurrencyID?: CurrencyID): Promise<{
|
|
51
|
-
quote: Quote | null;
|
|
52
|
-
aggregator: Aggregator;
|
|
53
|
-
inputAmount: Decimal;
|
|
54
|
-
outputAmount: bigint;
|
|
55
|
-
}>;
|
|
56
|
-
export declare function liquidateInputHoldings(userAddress: Bytes, holdings: Holding[], aggregators: Aggregator[], collectionFees: FixedFeeTuple[], commonCurrencyID?: CurrencyID): Promise<{
|
|
57
|
-
quotes: {
|
|
58
|
-
agg: Aggregator;
|
|
59
|
-
quote: Quote;
|
|
60
|
-
req: QuoteRequestExactInput;
|
|
61
|
-
cfee: bigint;
|
|
62
|
-
originalHolding: Holding;
|
|
63
|
-
cur: Currency;
|
|
64
|
-
aggregator: Aggregator;
|
|
65
|
-
}[];
|
|
66
|
-
total: Decimal;
|
|
67
|
-
}>;
|
|
68
|
-
export declare function destinationSwapWithExactIn(userAddress: Bytes, chainID: OmniversalChainID, inputAmount: bigint, outputToken: Bytes, aggregators: Aggregator[], commonCurrencyID?: CurrencyID): Promise<{
|
|
69
|
-
inputAmount: Decimal;
|
|
70
|
-
outputAmount: bigint;
|
|
71
|
-
quote: Quote | null;
|
|
72
|
-
aggregator: Aggregator;
|
|
73
|
-
}>;
|
|
25
|
+
export declare function determineDestinationSwaps(userAddress: Bytes, requirement: Holding, aggregators: Aggregator[], commonCurrencyID?: CurrencyID): Promise<QuoteResponse>;
|
|
26
|
+
export declare function liquidateInputHoldings(userAddress: Bytes, holdings: Holding[], aggregators: Aggregator[], commonCurrencyID?: CurrencyID): Promise<QuoteResponse[]>;
|
|
27
|
+
export declare function destinationSwapWithExactIn(userAddress: Bytes, omniChainID: OmniversalChainID, inputAmount: bigint, outputToken: Bytes, aggregators: Aggregator[], inputCurrency?: CurrencyID): Promise<QuoteResponse>;
|
|
74
28
|
export {};
|
|
@@ -35,7 +35,7 @@ export type BebopCommonQuote = {
|
|
|
35
35
|
priceBeforeFee: number;
|
|
36
36
|
}>;
|
|
37
37
|
settlementAddress: string;
|
|
38
|
-
approvalTarget:
|
|
38
|
+
approvalTarget: Hex;
|
|
39
39
|
requiredSignatures: Array<never>;
|
|
40
40
|
priceImpact: number;
|
|
41
41
|
warnings: Array<never>;
|
|
@@ -100,5 +100,5 @@ export declare class BebopAggregator implements Aggregator {
|
|
|
100
100
|
private static readonly COMMON_OPTIONS;
|
|
101
101
|
private readonly axios;
|
|
102
102
|
constructor(apiKey: string);
|
|
103
|
-
getQuotes(requests: (QuoteRequestExactInput | QuoteRequestExactOutput)[]): Promise<(
|
|
103
|
+
getQuotes(requests: (QuoteRequestExactInput | QuoteRequestExactOutput)[]): Promise<(Quote | null)[]>;
|
|
104
104
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Hex } from "viem";
|
|
2
|
+
import { Aggregator, Quote, QuoteRequestExactInput, QuoteRequestExactOutput } from "./iface";
|
|
3
|
+
export type FibrousToken = {
|
|
4
|
+
name: string;
|
|
5
|
+
symbol?: string;
|
|
6
|
+
address: Hex;
|
|
7
|
+
decimals: number;
|
|
8
|
+
price: number | string | null;
|
|
9
|
+
};
|
|
10
|
+
export type FibrousResponse = {
|
|
11
|
+
route: {
|
|
12
|
+
success: boolean;
|
|
13
|
+
routeSwapType: number;
|
|
14
|
+
inputToken: FibrousToken;
|
|
15
|
+
inputAmount: string;
|
|
16
|
+
outputToken: FibrousToken;
|
|
17
|
+
outputAmount: string;
|
|
18
|
+
};
|
|
19
|
+
calldata: {
|
|
20
|
+
route: {
|
|
21
|
+
token_in: Hex;
|
|
22
|
+
token_out: Hex;
|
|
23
|
+
amount_in: string;
|
|
24
|
+
amount_out: string;
|
|
25
|
+
min_received: string;
|
|
26
|
+
destination: Hex;
|
|
27
|
+
swap_type: number;
|
|
28
|
+
};
|
|
29
|
+
swap_parameters: Array<{
|
|
30
|
+
token_in: Hex;
|
|
31
|
+
token_out: Hex;
|
|
32
|
+
rate: string;
|
|
33
|
+
protocol_id: string;
|
|
34
|
+
pool_address: Hex;
|
|
35
|
+
swap_type: number;
|
|
36
|
+
extra_data: Hex;
|
|
37
|
+
}>;
|
|
38
|
+
};
|
|
39
|
+
router_address: Hex;
|
|
40
|
+
};
|
|
41
|
+
export type FibrousQuote = Quote & {
|
|
42
|
+
originalResponse: FibrousResponse;
|
|
43
|
+
};
|
|
44
|
+
export type FibrousAggregatorOptions = {
|
|
45
|
+
apiKey?: string;
|
|
46
|
+
slippage?: number;
|
|
47
|
+
};
|
|
48
|
+
export declare class FibrousAggregator implements Aggregator {
|
|
49
|
+
private static readonly BASE_URL;
|
|
50
|
+
private readonly axios;
|
|
51
|
+
private readonly slippage;
|
|
52
|
+
constructor(options?: FibrousAggregatorOptions);
|
|
53
|
+
getQuotes(requests: (QuoteRequestExactInput | QuoteRequestExactOutput)[]): Promise<(Quote | null)[]>;
|
|
54
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Bytes } from "../types";
|
|
2
2
|
import { OmniversalChainID } from "../data";
|
|
3
|
+
import { Hex } from "viem";
|
|
3
4
|
export declare enum QuoteType {
|
|
4
5
|
EXACT_IN = 0,
|
|
5
6
|
EXACT_OUT = 1
|
|
@@ -8,12 +9,43 @@ export declare enum QuoteSeriousness {
|
|
|
8
9
|
PRICE_SURVEY = 0,
|
|
9
10
|
SERIOUS = 1
|
|
10
11
|
}
|
|
12
|
+
export type QuoteResponse = {
|
|
13
|
+
chainID: number;
|
|
14
|
+
quote: Quote;
|
|
15
|
+
holding: Holding;
|
|
16
|
+
aggregator: Aggregator;
|
|
17
|
+
};
|
|
18
|
+
export type Holding = {
|
|
19
|
+
chainID: OmniversalChainID;
|
|
20
|
+
tokenAddress: Bytes;
|
|
21
|
+
amountRaw: bigint;
|
|
22
|
+
};
|
|
11
23
|
export interface Quote {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
24
|
+
expiry?: number;
|
|
25
|
+
input: {
|
|
26
|
+
contractAddress: Hex;
|
|
27
|
+
amount: string;
|
|
28
|
+
amountRaw: bigint;
|
|
29
|
+
decimals: number;
|
|
30
|
+
value: number;
|
|
31
|
+
symbol: string;
|
|
32
|
+
};
|
|
33
|
+
output: {
|
|
34
|
+
contractAddress: Hex;
|
|
35
|
+
amount: string;
|
|
36
|
+
amountRaw: bigint;
|
|
37
|
+
decimals: number;
|
|
38
|
+
value: number;
|
|
39
|
+
symbol: string;
|
|
40
|
+
};
|
|
41
|
+
txData: {
|
|
42
|
+
approvalAddress: Hex;
|
|
43
|
+
tx: {
|
|
44
|
+
to: Hex;
|
|
45
|
+
data: Hex;
|
|
46
|
+
value: Hex;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
17
49
|
}
|
|
18
50
|
type CommonQuoteParameters = {
|
|
19
51
|
userAddress: Bytes;
|
|
@@ -1,35 +1,39 @@
|
|
|
1
|
+
import { Hex } from "viem";
|
|
1
2
|
import { Aggregator, Quote, QuoteRequestExactInput, QuoteRequestExactOutput } from "./iface";
|
|
2
3
|
export type LiFiResponse = {
|
|
3
4
|
type: string;
|
|
4
5
|
id: string;
|
|
5
6
|
estimate: {
|
|
6
7
|
tool: string;
|
|
7
|
-
approvalAddress:
|
|
8
|
+
approvalAddress: Hex;
|
|
8
9
|
toAmountMin: string;
|
|
9
10
|
toAmount: string;
|
|
10
11
|
fromAmount: string;
|
|
11
12
|
executionDuration: number;
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
};
|
|
14
|
+
action: {
|
|
15
|
+
fromToken: {
|
|
16
|
+
symbol: string;
|
|
17
|
+
decimals: number;
|
|
18
|
+
priceUSD: string;
|
|
19
|
+
};
|
|
20
|
+
toToken: {
|
|
21
|
+
symbol: string;
|
|
22
|
+
decimals: number;
|
|
23
|
+
priceUSD: string;
|
|
24
|
+
};
|
|
14
25
|
};
|
|
15
26
|
integrator: string;
|
|
16
27
|
transactionRequest: {
|
|
17
|
-
value:
|
|
18
|
-
to:
|
|
19
|
-
data:
|
|
20
|
-
chainId: number;
|
|
21
|
-
gasPrice: string;
|
|
22
|
-
gasLimit: string;
|
|
23
|
-
from: string;
|
|
28
|
+
value: Hex;
|
|
29
|
+
to: Hex;
|
|
30
|
+
data: Hex;
|
|
24
31
|
};
|
|
25
32
|
};
|
|
26
|
-
export type LiFiQuote = Quote & {
|
|
27
|
-
originalResponse: LiFiResponse;
|
|
28
|
-
};
|
|
29
33
|
export declare class LiFiAggregator implements Aggregator {
|
|
30
34
|
private static readonly BASE_URL_V1;
|
|
31
35
|
private static readonly COMMON_OPTIONS;
|
|
32
36
|
private readonly axios;
|
|
33
37
|
constructor(apiKey: string);
|
|
34
|
-
getQuotes(requests: (QuoteRequestExactInput | QuoteRequestExactOutput)[]): Promise<(
|
|
38
|
+
getQuotes(requests: (QuoteRequestExactInput | QuoteRequestExactOutput)[]): Promise<(Quote | null)[]>;
|
|
35
39
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avail-project/ca-common",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "common utilities for CA",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -63,7 +63,10 @@
|
|
|
63
63
|
"es-toolkit": "^1.39.7",
|
|
64
64
|
"tslib": "^2.8.1"
|
|
65
65
|
},
|
|
66
|
+
"publishConfig": {
|
|
67
|
+
"provenance": true
|
|
68
|
+
},
|
|
66
69
|
"repository": {
|
|
67
|
-
"url": "https://github.com/availproject/ca-common"
|
|
70
|
+
"url": "git+https://github.com/availproject/ca-common.git"
|
|
68
71
|
}
|
|
69
72
|
}
|