@avail-project/ca-common 2.0.0 → 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.
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FibrousRouterABI = void 0;
4
+ exports.FibrousRouterABI = [
5
+ {
6
+ inputs: [
7
+ {
8
+ components: [
9
+ { internalType: "address", name: "token_in", type: "address" },
10
+ { internalType: "address", name: "token_out", type: "address" },
11
+ { internalType: "uint256", name: "amount_in", type: "uint256" },
12
+ { internalType: "uint256", name: "amount_out", type: "uint256" },
13
+ { internalType: "uint256", name: "min_received", type: "uint256" },
14
+ { internalType: "address", name: "destination", type: "address" },
15
+ { internalType: "uint8", name: "swap_type", type: "uint8" },
16
+ ],
17
+ internalType: "struct IFibrousRouter.RouteParam",
18
+ name: "route",
19
+ type: "tuple",
20
+ },
21
+ {
22
+ components: [
23
+ { internalType: "address", name: "token_in", type: "address" },
24
+ { internalType: "address", name: "token_out", type: "address" },
25
+ { internalType: "uint32", name: "rate", type: "uint32" },
26
+ { internalType: "int24", name: "protocol_id", type: "int24" },
27
+ { internalType: "address", name: "pool_address", type: "address" },
28
+ { internalType: "uint8", name: "swap_type", type: "uint8" },
29
+ { internalType: "bytes", name: "extra_data", type: "bytes" },
30
+ ],
31
+ internalType: "struct IFibrousRouter.SwapParams[]",
32
+ name: "swap_parameters",
33
+ type: "tuple[]",
34
+ },
35
+ ],
36
+ name: "swap",
37
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
38
+ stateMutability: "payable",
39
+ type: "function",
40
+ },
41
+ ];
@@ -4,3 +4,4 @@ const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./erc20.abi"), exports);
5
5
  tslib_1.__exportStar(require("./vault.abi"), exports);
6
6
  tslib_1.__exportStar(require("./yakaggregator.abi"), exports);
7
+ tslib_1.__exportStar(require("./fibrousrouter.abi"), exports);
@@ -5,7 +5,8 @@
5
5
  // protoc v6.32.1
6
6
  // source: definition.proto
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.MsgDoubleCheckTx = exports.FillVEPacket = exports.DepositVEPacket = exports.MsgRefundReqResponse = exports.MsgRefundReq = exports.QueryGetPriceOracleDataResponse = exports.QueryGetPriceOracleDataRequest = exports.PriceOracleData = exports.PriceOracleDatum = exports.MsgUpdateProtocolFeesResponse = exports.MsgUpdateProtocolFees = exports.MsgCreateProtocolFeesResponse = exports.MsgCreateProtocolFees = exports.QueryGetProtocolFeesResponse = exports.QueryGetProtocolFeesRequest = exports.ProtocolFees = exports.AdminFeeRecipient = exports.FixedFeeTuple = exports.QueryRequestForFundsByAddressRequest = exports.QueryAllSettlementResponse = exports.QueryAllSettlementRequest = exports.QueryGetSettlementResponse = exports.QueryGetSettlementRequest = exports.Settlement = exports.MsgUpdateSolverDataResponse = exports.MsgUpdateSolverData = exports.MsgCreateSolverDataResponse = exports.MsgCreateSolverData = exports.QueryAllSolverDataResponse = exports.QueryAllSolverDataRequest = exports.QueryGetSolverDataResponse = exports.QueryGetSolverDataRequest = exports.SolverData = exports.SolverAddress = exports.RouteFee = exports.QueryAllRequestForFundsResponse = exports.QueryAllRequestForFundsRequest = exports.QueryGetRequestForFundsResponse = exports.QueryGetRequestForFundsRequest = exports.MsgCreateRequestForFundsResponse = exports.MsgCreateRequestForFunds = exports.RequestForFunds = exports.RFFDestinationPair = exports.SignatureDatum = exports.RFFSourcePair = exports.PageResponse = exports.PageRequest = exports.Universe = exports.RFFSourceState = exports.protobufPackage = void 0;
8
+ exports.FillVEPacket = exports.DepositVEPacket = exports.MsgRefundReqResponse = exports.MsgRefundReq = exports.QueryGetPriceOracleDataResponse = exports.QueryGetPriceOracleDataRequest = exports.PriceOracleData = exports.PriceOracleDatum = exports.MsgUpdateProtocolFeesResponse = exports.MsgUpdateProtocolFees = exports.MsgCreateProtocolFeesResponse = exports.MsgCreateProtocolFees = exports.QueryGetProtocolFeesResponse = exports.QueryGetProtocolFeesRequest = exports.ProtocolFees = exports.PerChainFeeBP = exports.AdminFeeRecipient = exports.FixedFeeTuple = exports.QueryRequestForFundsByAddressRequest = exports.QueryAllSettlementResponse = exports.QueryAllSettlementRequest = exports.QueryGetSettlementResponse = exports.QueryGetSettlementRequest = exports.Settlement = exports.MsgUpdateSolverDataResponse = exports.MsgUpdateSolverData = exports.MsgCreateSolverDataResponse = exports.MsgCreateSolverData = exports.QueryAllSolverDataResponse = exports.QueryAllSolverDataRequest = exports.QueryGetSolverDataResponse = exports.QueryGetSolverDataRequest = exports.SolverData = exports.SolverAddress = exports.RouteFee = exports.QueryAllRequestForFundsResponse = exports.QueryAllRequestForFundsRequest = exports.QueryGetRequestForFundsResponse = exports.QueryGetRequestForFundsRequest = exports.MsgCreateRequestForFundsResponse = exports.MsgCreateRequestForFunds = exports.RequestForFunds = exports.RFFDestinationPair = exports.SignatureDatum = exports.RFFSourcePair = exports.PageResponse = exports.PageRequest = exports.Universe = exports.RFFSourceState = exports.protobufPackage = void 0;
9
+ exports.MsgDoubleCheckTx = void 0;
9
10
  exports.rFFSourceStateFromJSON = rFFSourceStateFromJSON;
10
11
  exports.rFFSourceStateToJSON = rFFSourceStateToJSON;
11
12
  exports.universeFromJSON = universeFromJSON;
@@ -2779,8 +2780,91 @@ exports.AdminFeeRecipient = {
2779
2780
  return message;
2780
2781
  },
2781
2782
  };
2783
+ function createBasePerChainFeeBP() {
2784
+ return { universe: 0, chainID: new Uint8Array(0), feeBP: long_1.default.UZERO };
2785
+ }
2786
+ exports.PerChainFeeBP = {
2787
+ encode(message, writer = new wire_1.BinaryWriter()) {
2788
+ if (message.universe !== 0) {
2789
+ writer.uint32(8).int32(message.universe);
2790
+ }
2791
+ if (message.chainID.length !== 0) {
2792
+ writer.uint32(18).bytes(message.chainID);
2793
+ }
2794
+ if (!message.feeBP.equals(long_1.default.UZERO)) {
2795
+ writer.uint32(24).uint64(message.feeBP.toString());
2796
+ }
2797
+ return writer;
2798
+ },
2799
+ decode(input, length) {
2800
+ const reader = input instanceof wire_1.BinaryReader ? input : new wire_1.BinaryReader(input);
2801
+ const end = length === undefined ? reader.len : reader.pos + length;
2802
+ const message = createBasePerChainFeeBP();
2803
+ while (reader.pos < end) {
2804
+ const tag = reader.uint32();
2805
+ switch (tag >>> 3) {
2806
+ case 1: {
2807
+ if (tag !== 8) {
2808
+ break;
2809
+ }
2810
+ message.universe = reader.int32();
2811
+ continue;
2812
+ }
2813
+ case 2: {
2814
+ if (tag !== 18) {
2815
+ break;
2816
+ }
2817
+ message.chainID = reader.bytes();
2818
+ continue;
2819
+ }
2820
+ case 3: {
2821
+ if (tag !== 24) {
2822
+ break;
2823
+ }
2824
+ message.feeBP = long_1.default.fromString(reader.uint64().toString(), true);
2825
+ continue;
2826
+ }
2827
+ }
2828
+ if ((tag & 7) === 4 || tag === 0) {
2829
+ break;
2830
+ }
2831
+ reader.skip(tag & 7);
2832
+ }
2833
+ return message;
2834
+ },
2835
+ fromJSON(object) {
2836
+ return {
2837
+ universe: isSet(object.universe) ? universeFromJSON(object.universe) : 0,
2838
+ chainID: isSet(object.chainID) ? bytesFromBase64(object.chainID) : new Uint8Array(0),
2839
+ feeBP: isSet(object.feeBP) ? long_1.default.fromValue(object.feeBP) : long_1.default.UZERO,
2840
+ };
2841
+ },
2842
+ toJSON(message) {
2843
+ const obj = {};
2844
+ if (message.universe !== 0) {
2845
+ obj.universe = universeToJSON(message.universe);
2846
+ }
2847
+ if (message.chainID.length !== 0) {
2848
+ obj.chainID = base64FromBytes(message.chainID);
2849
+ }
2850
+ if (!message.feeBP.equals(long_1.default.UZERO)) {
2851
+ obj.feeBP = (message.feeBP || long_1.default.UZERO).toString();
2852
+ }
2853
+ return obj;
2854
+ },
2855
+ create(base) {
2856
+ return exports.PerChainFeeBP.fromPartial(base ?? {});
2857
+ },
2858
+ fromPartial(object) {
2859
+ const message = createBasePerChainFeeBP();
2860
+ message.universe = object.universe ?? 0;
2861
+ message.chainID = object.chainID ?? new Uint8Array(0);
2862
+ message.feeBP = (object.feeBP !== undefined && object.feeBP !== null) ? long_1.default.fromValue(object.feeBP) : long_1.default.UZERO;
2863
+ return message;
2864
+ },
2865
+ };
2782
2866
  function createBaseProtocolFees() {
2783
- return { feeBP: long_1.default.UZERO, collectionFees: [], fulfilmentFees: [], admin: "", feeRecipients: [] };
2867
+ return { feeBP: long_1.default.UZERO, collectionFees: [], fulfilmentFees: [], admin: "", feeRecipients: [], perChainFeeBP: [] };
2784
2868
  }
2785
2869
  exports.ProtocolFees = {
2786
2870
  encode(message, writer = new wire_1.BinaryWriter()) {
@@ -2799,6 +2883,9 @@ exports.ProtocolFees = {
2799
2883
  for (const v of message.feeRecipients) {
2800
2884
  exports.AdminFeeRecipient.encode(v, writer.uint32(42).fork()).join();
2801
2885
  }
2886
+ for (const v of message.perChainFeeBP) {
2887
+ exports.PerChainFeeBP.encode(v, writer.uint32(50).fork()).join();
2888
+ }
2802
2889
  return writer;
2803
2890
  },
2804
2891
  decode(input, length) {
@@ -2843,6 +2930,13 @@ exports.ProtocolFees = {
2843
2930
  message.feeRecipients.push(exports.AdminFeeRecipient.decode(reader, reader.uint32()));
2844
2931
  continue;
2845
2932
  }
2933
+ case 6: {
2934
+ if (tag !== 50) {
2935
+ break;
2936
+ }
2937
+ message.perChainFeeBP.push(exports.PerChainFeeBP.decode(reader, reader.uint32()));
2938
+ continue;
2939
+ }
2846
2940
  }
2847
2941
  if ((tag & 7) === 4 || tag === 0) {
2848
2942
  break;
@@ -2864,6 +2958,9 @@ exports.ProtocolFees = {
2864
2958
  feeRecipients: globalThis.Array.isArray(object?.feeRecipients)
2865
2959
  ? object.feeRecipients.map((e) => exports.AdminFeeRecipient.fromJSON(e))
2866
2960
  : [],
2961
+ perChainFeeBP: globalThis.Array.isArray(object?.perChainFeeBP)
2962
+ ? object.perChainFeeBP.map((e) => exports.PerChainFeeBP.fromJSON(e))
2963
+ : [],
2867
2964
  };
2868
2965
  },
2869
2966
  toJSON(message) {
@@ -2883,6 +2980,9 @@ exports.ProtocolFees = {
2883
2980
  if (message.feeRecipients?.length) {
2884
2981
  obj.feeRecipients = message.feeRecipients.map((e) => exports.AdminFeeRecipient.toJSON(e));
2885
2982
  }
2983
+ if (message.perChainFeeBP?.length) {
2984
+ obj.perChainFeeBP = message.perChainFeeBP.map((e) => exports.PerChainFeeBP.toJSON(e));
2985
+ }
2886
2986
  return obj;
2887
2987
  },
2888
2988
  create(base) {
@@ -2895,6 +2995,7 @@ exports.ProtocolFees = {
2895
2995
  message.fulfilmentFees = object.fulfilmentFees?.map((e) => exports.FixedFeeTuple.fromPartial(e)) || [];
2896
2996
  message.admin = object.admin ?? "";
2897
2997
  message.feeRecipients = object.feeRecipients?.map((e) => exports.AdminFeeRecipient.fromPartial(e)) || [];
2998
+ message.perChainFeeBP = object.perChainFeeBP?.map((e) => exports.PerChainFeeBP.fromPartial(e)) || [];
2898
2999
  return message;
2899
3000
  },
2900
3001
  };
@@ -2989,7 +3090,14 @@ exports.QueryGetProtocolFeesResponse = {
2989
3090
  },
2990
3091
  };
2991
3092
  function createBaseMsgCreateProtocolFees() {
2992
- return { creator: "", feeBP: long_1.default.UZERO, collectionFees: [], fulfilmentFees: [], feeRecipients: [] };
3093
+ return {
3094
+ creator: "",
3095
+ feeBP: long_1.default.UZERO,
3096
+ collectionFees: [],
3097
+ fulfilmentFees: [],
3098
+ feeRecipients: [],
3099
+ perChainFeeBP: [],
3100
+ };
2993
3101
  }
2994
3102
  exports.MsgCreateProtocolFees = {
2995
3103
  encode(message, writer = new wire_1.BinaryWriter()) {
@@ -3008,6 +3116,9 @@ exports.MsgCreateProtocolFees = {
3008
3116
  for (const v of message.feeRecipients) {
3009
3117
  exports.AdminFeeRecipient.encode(v, writer.uint32(42).fork()).join();
3010
3118
  }
3119
+ for (const v of message.perChainFeeBP) {
3120
+ exports.PerChainFeeBP.encode(v, writer.uint32(50).fork()).join();
3121
+ }
3011
3122
  return writer;
3012
3123
  },
3013
3124
  decode(input, length) {
@@ -3052,6 +3163,13 @@ exports.MsgCreateProtocolFees = {
3052
3163
  message.feeRecipients.push(exports.AdminFeeRecipient.decode(reader, reader.uint32()));
3053
3164
  continue;
3054
3165
  }
3166
+ case 6: {
3167
+ if (tag !== 50) {
3168
+ break;
3169
+ }
3170
+ message.perChainFeeBP.push(exports.PerChainFeeBP.decode(reader, reader.uint32()));
3171
+ continue;
3172
+ }
3055
3173
  }
3056
3174
  if ((tag & 7) === 4 || tag === 0) {
3057
3175
  break;
@@ -3073,6 +3191,9 @@ exports.MsgCreateProtocolFees = {
3073
3191
  feeRecipients: globalThis.Array.isArray(object?.feeRecipients)
3074
3192
  ? object.feeRecipients.map((e) => exports.AdminFeeRecipient.fromJSON(e))
3075
3193
  : [],
3194
+ perChainFeeBP: globalThis.Array.isArray(object?.perChainFeeBP)
3195
+ ? object.perChainFeeBP.map((e) => exports.PerChainFeeBP.fromJSON(e))
3196
+ : [],
3076
3197
  };
3077
3198
  },
3078
3199
  toJSON(message) {
@@ -3092,6 +3213,9 @@ exports.MsgCreateProtocolFees = {
3092
3213
  if (message.feeRecipients?.length) {
3093
3214
  obj.feeRecipients = message.feeRecipients.map((e) => exports.AdminFeeRecipient.toJSON(e));
3094
3215
  }
3216
+ if (message.perChainFeeBP?.length) {
3217
+ obj.perChainFeeBP = message.perChainFeeBP.map((e) => exports.PerChainFeeBP.toJSON(e));
3218
+ }
3095
3219
  return obj;
3096
3220
  },
3097
3221
  create(base) {
@@ -3104,6 +3228,7 @@ exports.MsgCreateProtocolFees = {
3104
3228
  message.collectionFees = object.collectionFees?.map((e) => exports.FixedFeeTuple.fromPartial(e)) || [];
3105
3229
  message.fulfilmentFees = object.fulfilmentFees?.map((e) => exports.FixedFeeTuple.fromPartial(e)) || [];
3106
3230
  message.feeRecipients = object.feeRecipients?.map((e) => exports.AdminFeeRecipient.fromPartial(e)) || [];
3231
+ message.perChainFeeBP = object.perChainFeeBP?.map((e) => exports.PerChainFeeBP.fromPartial(e)) || [];
3107
3232
  return message;
3108
3233
  },
3109
3234
  };
@@ -3145,7 +3270,14 @@ exports.MsgCreateProtocolFeesResponse = {
3145
3270
  },
3146
3271
  };
3147
3272
  function createBaseMsgUpdateProtocolFees() {
3148
- return { creator: "", feeBP: long_1.default.UZERO, collectionFees: [], fulfilmentFees: [], feeRecipients: [] };
3273
+ return {
3274
+ creator: "",
3275
+ feeBP: long_1.default.UZERO,
3276
+ collectionFees: [],
3277
+ fulfilmentFees: [],
3278
+ feeRecipients: [],
3279
+ perChainFeeBP: [],
3280
+ };
3149
3281
  }
3150
3282
  exports.MsgUpdateProtocolFees = {
3151
3283
  encode(message, writer = new wire_1.BinaryWriter()) {
@@ -3164,6 +3296,9 @@ exports.MsgUpdateProtocolFees = {
3164
3296
  for (const v of message.feeRecipients) {
3165
3297
  exports.AdminFeeRecipient.encode(v, writer.uint32(42).fork()).join();
3166
3298
  }
3299
+ for (const v of message.perChainFeeBP) {
3300
+ exports.PerChainFeeBP.encode(v, writer.uint32(50).fork()).join();
3301
+ }
3167
3302
  return writer;
3168
3303
  },
3169
3304
  decode(input, length) {
@@ -3208,6 +3343,13 @@ exports.MsgUpdateProtocolFees = {
3208
3343
  message.feeRecipients.push(exports.AdminFeeRecipient.decode(reader, reader.uint32()));
3209
3344
  continue;
3210
3345
  }
3346
+ case 6: {
3347
+ if (tag !== 50) {
3348
+ break;
3349
+ }
3350
+ message.perChainFeeBP.push(exports.PerChainFeeBP.decode(reader, reader.uint32()));
3351
+ continue;
3352
+ }
3211
3353
  }
3212
3354
  if ((tag & 7) === 4 || tag === 0) {
3213
3355
  break;
@@ -3229,6 +3371,9 @@ exports.MsgUpdateProtocolFees = {
3229
3371
  feeRecipients: globalThis.Array.isArray(object?.feeRecipients)
3230
3372
  ? object.feeRecipients.map((e) => exports.AdminFeeRecipient.fromJSON(e))
3231
3373
  : [],
3374
+ perChainFeeBP: globalThis.Array.isArray(object?.perChainFeeBP)
3375
+ ? object.perChainFeeBP.map((e) => exports.PerChainFeeBP.fromJSON(e))
3376
+ : [],
3232
3377
  };
3233
3378
  },
3234
3379
  toJSON(message) {
@@ -3248,6 +3393,9 @@ exports.MsgUpdateProtocolFees = {
3248
3393
  if (message.feeRecipients?.length) {
3249
3394
  obj.feeRecipients = message.feeRecipients.map((e) => exports.AdminFeeRecipient.toJSON(e));
3250
3395
  }
3396
+ if (message.perChainFeeBP?.length) {
3397
+ obj.perChainFeeBP = message.perChainFeeBP.map((e) => exports.PerChainFeeBP.toJSON(e));
3398
+ }
3251
3399
  return obj;
3252
3400
  },
3253
3401
  create(base) {
@@ -3260,6 +3408,7 @@ exports.MsgUpdateProtocolFees = {
3260
3408
  message.collectionFees = object.collectionFees?.map((e) => exports.FixedFeeTuple.fromPartial(e)) || [];
3261
3409
  message.fulfilmentFees = object.fulfilmentFees?.map((e) => exports.FixedFeeTuple.fromPartial(e)) || [];
3262
3410
  message.feeRecipients = object.feeRecipients?.map((e) => exports.AdminFeeRecipient.fromPartial(e)) || [];
3411
+ message.perChainFeeBP = object.perChainFeeBP?.map((e) => exports.PerChainFeeBP.fromPartial(e)) || [];
3263
3412
  return message;
3264
3413
  },
3265
3414
  };
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FibrousAggregator = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const axios_1 = tslib_1.__importStar(require("axios"));
6
+ const decimal_js_1 = tslib_1.__importDefault(require("decimal.js"));
7
+ const viem_1 = require("viem");
8
+ const data_1 = require("../data");
9
+ const evmabi_1 = require("../evmabi");
10
+ const definition_1 = require("../proto/definition");
11
+ const iface_1 = require("./iface");
12
+ const ChainNameMapping = new data_1.ChainIDKeyedMap([
13
+ [new data_1.OmniversalChainID(definition_1.Universe.ETHEREUM, 8453), "base"],
14
+ [new data_1.OmniversalChainID(definition_1.Universe.ETHEREUM, 999), "hyperevm"],
15
+ [new data_1.OmniversalChainID(definition_1.Universe.ETHEREUM, 143), "monad"],
16
+ [new data_1.OmniversalChainID(definition_1.Universe.ETHEREUM, 4114), "citrea"],
17
+ ]);
18
+ class FibrousAggregator {
19
+ static BASE_URL = "https://api.fibrous.finance";
20
+ axios;
21
+ slippage;
22
+ constructor(options = {}) {
23
+ const { apiKey, slippage = 0.5 } = options;
24
+ this.slippage = slippage;
25
+ this.axios = axios_1.default.create({
26
+ baseURL: FibrousAggregator.BASE_URL,
27
+ headers: apiKey != null ? { "X-API-Key": apiKey } : undefined,
28
+ timeout: 10_000,
29
+ });
30
+ }
31
+ async getQuotes(requests) {
32
+ const list = await Promise.allSettled(requests.map(async (r) => {
33
+ if (r.type === iface_1.QuoteType.EXACT_OUT) {
34
+ return null;
35
+ }
36
+ if (r.chain.universe !== definition_1.Universe.ETHEREUM) {
37
+ return null;
38
+ }
39
+ const chainName = ChainNameMapping.get(r.chain);
40
+ if (chainName == null) {
41
+ return null;
42
+ }
43
+ const inputTokenAddr = (0, viem_1.getAddress)((0, viem_1.bytesToHex)(r.inputToken.subarray(12)));
44
+ const outputTokenAddr = (0, viem_1.getAddress)((0, viem_1.bytesToHex)(r.outputToken.subarray(12)));
45
+ const userAddrHex = (0, viem_1.getAddress)((0, viem_1.bytesToHex)(r.userAddress.subarray(12)));
46
+ let resp;
47
+ try {
48
+ resp = await this.axios({
49
+ method: "GET",
50
+ url: `/${chainName}/v2/routeAndCallData`,
51
+ params: {
52
+ amount: r.inputAmount.toString(),
53
+ tokenInAddress: inputTokenAddr,
54
+ tokenOutAddress: outputTokenAddr,
55
+ slippage: this.slippage,
56
+ destination: userAddrHex,
57
+ },
58
+ });
59
+ }
60
+ catch (e) {
61
+ if (e instanceof axios_1.AxiosError && e.isAxiosError) {
62
+ return null;
63
+ }
64
+ throw e;
65
+ }
66
+ if (!resp.data.route.success) {
67
+ return null;
68
+ }
69
+ if (resp.data.calldata.swap_parameters.length === 0) {
70
+ return null;
71
+ }
72
+ const inputAmountInDecimal = new decimal_js_1.default(resp.data.route.inputAmount)
73
+ .div(decimal_js_1.default.pow(10, resp.data.route.inputToken.decimals))
74
+ .toFixed(resp.data.route.inputToken.decimals);
75
+ const outputAmountInDecimal = new decimal_js_1.default(resp.data.calldata.route.min_received)
76
+ .div(decimal_js_1.default.pow(10, resp.data.route.outputToken.decimals))
77
+ .toFixed(resp.data.route.outputToken.decimals);
78
+ const routerAddress = (0, viem_1.getAddress)(resp.data.router_address);
79
+ const isNativeInput = resp.data.calldata.route.swap_type === 0;
80
+ const quote = {
81
+ originalResponse: resp.data,
82
+ input: {
83
+ amount: inputAmountInDecimal,
84
+ amountRaw: BigInt(resp.data.route.inputAmount),
85
+ contractAddress: inputTokenAddr,
86
+ decimals: resp.data.route.inputToken.decimals,
87
+ value: decimal_js_1.default.mul(inputAmountInDecimal, resp.data.route.inputToken.price ?? 0).toNumber(),
88
+ symbol: resp.data.route.inputToken.symbol ??
89
+ resp.data.route.inputToken.name,
90
+ },
91
+ output: {
92
+ amount: outputAmountInDecimal,
93
+ amountRaw: BigInt(resp.data.calldata.route.min_received),
94
+ contractAddress: outputTokenAddr,
95
+ decimals: resp.data.route.outputToken.decimals,
96
+ value: decimal_js_1.default.mul(outputAmountInDecimal, resp.data.route.outputToken.price ?? 0).toNumber(),
97
+ symbol: resp.data.route.outputToken.symbol ??
98
+ resp.data.route.outputToken.name,
99
+ },
100
+ txData: {
101
+ approvalAddress: isNativeInput ? viem_1.zeroAddress : routerAddress,
102
+ tx: {
103
+ to: routerAddress,
104
+ value: isNativeInput
105
+ ? (0, viem_1.toHex)(BigInt(resp.data.calldata.route.amount_in))
106
+ : (0, viem_1.toHex)(0),
107
+ data: (0, viem_1.encodeFunctionData)({
108
+ abi: evmabi_1.FibrousRouterABI,
109
+ functionName: "swap",
110
+ args: [
111
+ {
112
+ token_in: (0, viem_1.getAddress)(resp.data.calldata.route.token_in),
113
+ token_out: (0, viem_1.getAddress)(resp.data.calldata.route.token_out),
114
+ amount_in: BigInt(resp.data.calldata.route.amount_in),
115
+ amount_out: BigInt(resp.data.calldata.route.amount_out),
116
+ min_received: BigInt(resp.data.calldata.route.min_received),
117
+ destination: (0, viem_1.getAddress)(resp.data.calldata.route.destination),
118
+ swap_type: resp.data.calldata.route.swap_type,
119
+ },
120
+ resp.data.calldata.swap_parameters.map((swapParameter) => ({
121
+ token_in: (0, viem_1.getAddress)(swapParameter.token_in),
122
+ token_out: (0, viem_1.getAddress)(swapParameter.token_out),
123
+ rate: Number.parseInt(swapParameter.rate, 10),
124
+ protocol_id: Number.parseInt(swapParameter.protocol_id, 10),
125
+ pool_address: (0, viem_1.getAddress)(swapParameter.pool_address),
126
+ swap_type: swapParameter.swap_type,
127
+ extra_data: swapParameter.extra_data,
128
+ })),
129
+ ],
130
+ }),
131
+ },
132
+ },
133
+ };
134
+ return quote;
135
+ }));
136
+ return list.map((item) => {
137
+ switch (item.status) {
138
+ case "fulfilled": {
139
+ return item.value;
140
+ }
141
+ case "rejected": {
142
+ console.error("Caught error in fetching Fibrous quotes:", item.reason);
143
+ return null;
144
+ }
145
+ }
146
+ });
147
+ }
148
+ }
149
+ exports.FibrousAggregator = FibrousAggregator;
@@ -4,4 +4,5 @@ const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./iface"), exports);
5
5
  tslib_1.__exportStar(require("./lifi-agg"), exports);
6
6
  tslib_1.__exportStar(require("./bebop-agg"), exports);
7
+ tslib_1.__exportStar(require("./fibrous-agg"), exports);
7
8
  tslib_1.__exportStar(require("./autochoice"), exports);
@@ -0,0 +1,38 @@
1
+ export const FibrousRouterABI = [
2
+ {
3
+ inputs: [
4
+ {
5
+ components: [
6
+ { internalType: "address", name: "token_in", type: "address" },
7
+ { internalType: "address", name: "token_out", type: "address" },
8
+ { internalType: "uint256", name: "amount_in", type: "uint256" },
9
+ { internalType: "uint256", name: "amount_out", type: "uint256" },
10
+ { internalType: "uint256", name: "min_received", type: "uint256" },
11
+ { internalType: "address", name: "destination", type: "address" },
12
+ { internalType: "uint8", name: "swap_type", type: "uint8" },
13
+ ],
14
+ internalType: "struct IFibrousRouter.RouteParam",
15
+ name: "route",
16
+ type: "tuple",
17
+ },
18
+ {
19
+ components: [
20
+ { internalType: "address", name: "token_in", type: "address" },
21
+ { internalType: "address", name: "token_out", type: "address" },
22
+ { internalType: "uint32", name: "rate", type: "uint32" },
23
+ { internalType: "int24", name: "protocol_id", type: "int24" },
24
+ { internalType: "address", name: "pool_address", type: "address" },
25
+ { internalType: "uint8", name: "swap_type", type: "uint8" },
26
+ { internalType: "bytes", name: "extra_data", type: "bytes" },
27
+ ],
28
+ internalType: "struct IFibrousRouter.SwapParams[]",
29
+ name: "swap_parameters",
30
+ type: "tuple[]",
31
+ },
32
+ ],
33
+ name: "swap",
34
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
35
+ stateMutability: "payable",
36
+ type: "function",
37
+ },
38
+ ];
@@ -1,3 +1,4 @@
1
1
  export * from './erc20.abi';
2
2
  export * from './vault.abi';
3
3
  export * from './yakaggregator.abi';
4
+ export * from './fibrousrouter.abi';
@@ -2771,8 +2771,91 @@ export const AdminFeeRecipient = {
2771
2771
  return message;
2772
2772
  },
2773
2773
  };
2774
+ function createBasePerChainFeeBP() {
2775
+ return { universe: 0, chainID: new Uint8Array(0), feeBP: Long.UZERO };
2776
+ }
2777
+ export const PerChainFeeBP = {
2778
+ encode(message, writer = new BinaryWriter()) {
2779
+ if (message.universe !== 0) {
2780
+ writer.uint32(8).int32(message.universe);
2781
+ }
2782
+ if (message.chainID.length !== 0) {
2783
+ writer.uint32(18).bytes(message.chainID);
2784
+ }
2785
+ if (!message.feeBP.equals(Long.UZERO)) {
2786
+ writer.uint32(24).uint64(message.feeBP.toString());
2787
+ }
2788
+ return writer;
2789
+ },
2790
+ decode(input, length) {
2791
+ const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
2792
+ const end = length === undefined ? reader.len : reader.pos + length;
2793
+ const message = createBasePerChainFeeBP();
2794
+ while (reader.pos < end) {
2795
+ const tag = reader.uint32();
2796
+ switch (tag >>> 3) {
2797
+ case 1: {
2798
+ if (tag !== 8) {
2799
+ break;
2800
+ }
2801
+ message.universe = reader.int32();
2802
+ continue;
2803
+ }
2804
+ case 2: {
2805
+ if (tag !== 18) {
2806
+ break;
2807
+ }
2808
+ message.chainID = reader.bytes();
2809
+ continue;
2810
+ }
2811
+ case 3: {
2812
+ if (tag !== 24) {
2813
+ break;
2814
+ }
2815
+ message.feeBP = Long.fromString(reader.uint64().toString(), true);
2816
+ continue;
2817
+ }
2818
+ }
2819
+ if ((tag & 7) === 4 || tag === 0) {
2820
+ break;
2821
+ }
2822
+ reader.skip(tag & 7);
2823
+ }
2824
+ return message;
2825
+ },
2826
+ fromJSON(object) {
2827
+ return {
2828
+ universe: isSet(object.universe) ? universeFromJSON(object.universe) : 0,
2829
+ chainID: isSet(object.chainID) ? bytesFromBase64(object.chainID) : new Uint8Array(0),
2830
+ feeBP: isSet(object.feeBP) ? Long.fromValue(object.feeBP) : Long.UZERO,
2831
+ };
2832
+ },
2833
+ toJSON(message) {
2834
+ const obj = {};
2835
+ if (message.universe !== 0) {
2836
+ obj.universe = universeToJSON(message.universe);
2837
+ }
2838
+ if (message.chainID.length !== 0) {
2839
+ obj.chainID = base64FromBytes(message.chainID);
2840
+ }
2841
+ if (!message.feeBP.equals(Long.UZERO)) {
2842
+ obj.feeBP = (message.feeBP || Long.UZERO).toString();
2843
+ }
2844
+ return obj;
2845
+ },
2846
+ create(base) {
2847
+ return PerChainFeeBP.fromPartial(base ?? {});
2848
+ },
2849
+ fromPartial(object) {
2850
+ const message = createBasePerChainFeeBP();
2851
+ message.universe = object.universe ?? 0;
2852
+ message.chainID = object.chainID ?? new Uint8Array(0);
2853
+ message.feeBP = (object.feeBP !== undefined && object.feeBP !== null) ? Long.fromValue(object.feeBP) : Long.UZERO;
2854
+ return message;
2855
+ },
2856
+ };
2774
2857
  function createBaseProtocolFees() {
2775
- return { feeBP: Long.UZERO, collectionFees: [], fulfilmentFees: [], admin: "", feeRecipients: [] };
2858
+ return { feeBP: Long.UZERO, collectionFees: [], fulfilmentFees: [], admin: "", feeRecipients: [], perChainFeeBP: [] };
2776
2859
  }
2777
2860
  export const ProtocolFees = {
2778
2861
  encode(message, writer = new BinaryWriter()) {
@@ -2791,6 +2874,9 @@ export const ProtocolFees = {
2791
2874
  for (const v of message.feeRecipients) {
2792
2875
  AdminFeeRecipient.encode(v, writer.uint32(42).fork()).join();
2793
2876
  }
2877
+ for (const v of message.perChainFeeBP) {
2878
+ PerChainFeeBP.encode(v, writer.uint32(50).fork()).join();
2879
+ }
2794
2880
  return writer;
2795
2881
  },
2796
2882
  decode(input, length) {
@@ -2835,6 +2921,13 @@ export const ProtocolFees = {
2835
2921
  message.feeRecipients.push(AdminFeeRecipient.decode(reader, reader.uint32()));
2836
2922
  continue;
2837
2923
  }
2924
+ case 6: {
2925
+ if (tag !== 50) {
2926
+ break;
2927
+ }
2928
+ message.perChainFeeBP.push(PerChainFeeBP.decode(reader, reader.uint32()));
2929
+ continue;
2930
+ }
2838
2931
  }
2839
2932
  if ((tag & 7) === 4 || tag === 0) {
2840
2933
  break;
@@ -2856,6 +2949,9 @@ export const ProtocolFees = {
2856
2949
  feeRecipients: globalThis.Array.isArray(object?.feeRecipients)
2857
2950
  ? object.feeRecipients.map((e) => AdminFeeRecipient.fromJSON(e))
2858
2951
  : [],
2952
+ perChainFeeBP: globalThis.Array.isArray(object?.perChainFeeBP)
2953
+ ? object.perChainFeeBP.map((e) => PerChainFeeBP.fromJSON(e))
2954
+ : [],
2859
2955
  };
2860
2956
  },
2861
2957
  toJSON(message) {
@@ -2875,6 +2971,9 @@ export const ProtocolFees = {
2875
2971
  if (message.feeRecipients?.length) {
2876
2972
  obj.feeRecipients = message.feeRecipients.map((e) => AdminFeeRecipient.toJSON(e));
2877
2973
  }
2974
+ if (message.perChainFeeBP?.length) {
2975
+ obj.perChainFeeBP = message.perChainFeeBP.map((e) => PerChainFeeBP.toJSON(e));
2976
+ }
2878
2977
  return obj;
2879
2978
  },
2880
2979
  create(base) {
@@ -2887,6 +2986,7 @@ export const ProtocolFees = {
2887
2986
  message.fulfilmentFees = object.fulfilmentFees?.map((e) => FixedFeeTuple.fromPartial(e)) || [];
2888
2987
  message.admin = object.admin ?? "";
2889
2988
  message.feeRecipients = object.feeRecipients?.map((e) => AdminFeeRecipient.fromPartial(e)) || [];
2989
+ message.perChainFeeBP = object.perChainFeeBP?.map((e) => PerChainFeeBP.fromPartial(e)) || [];
2890
2990
  return message;
2891
2991
  },
2892
2992
  };
@@ -2981,7 +3081,14 @@ export const QueryGetProtocolFeesResponse = {
2981
3081
  },
2982
3082
  };
2983
3083
  function createBaseMsgCreateProtocolFees() {
2984
- return { creator: "", feeBP: Long.UZERO, collectionFees: [], fulfilmentFees: [], feeRecipients: [] };
3084
+ return {
3085
+ creator: "",
3086
+ feeBP: Long.UZERO,
3087
+ collectionFees: [],
3088
+ fulfilmentFees: [],
3089
+ feeRecipients: [],
3090
+ perChainFeeBP: [],
3091
+ };
2985
3092
  }
2986
3093
  export const MsgCreateProtocolFees = {
2987
3094
  encode(message, writer = new BinaryWriter()) {
@@ -3000,6 +3107,9 @@ export const MsgCreateProtocolFees = {
3000
3107
  for (const v of message.feeRecipients) {
3001
3108
  AdminFeeRecipient.encode(v, writer.uint32(42).fork()).join();
3002
3109
  }
3110
+ for (const v of message.perChainFeeBP) {
3111
+ PerChainFeeBP.encode(v, writer.uint32(50).fork()).join();
3112
+ }
3003
3113
  return writer;
3004
3114
  },
3005
3115
  decode(input, length) {
@@ -3044,6 +3154,13 @@ export const MsgCreateProtocolFees = {
3044
3154
  message.feeRecipients.push(AdminFeeRecipient.decode(reader, reader.uint32()));
3045
3155
  continue;
3046
3156
  }
3157
+ case 6: {
3158
+ if (tag !== 50) {
3159
+ break;
3160
+ }
3161
+ message.perChainFeeBP.push(PerChainFeeBP.decode(reader, reader.uint32()));
3162
+ continue;
3163
+ }
3047
3164
  }
3048
3165
  if ((tag & 7) === 4 || tag === 0) {
3049
3166
  break;
@@ -3065,6 +3182,9 @@ export const MsgCreateProtocolFees = {
3065
3182
  feeRecipients: globalThis.Array.isArray(object?.feeRecipients)
3066
3183
  ? object.feeRecipients.map((e) => AdminFeeRecipient.fromJSON(e))
3067
3184
  : [],
3185
+ perChainFeeBP: globalThis.Array.isArray(object?.perChainFeeBP)
3186
+ ? object.perChainFeeBP.map((e) => PerChainFeeBP.fromJSON(e))
3187
+ : [],
3068
3188
  };
3069
3189
  },
3070
3190
  toJSON(message) {
@@ -3084,6 +3204,9 @@ export const MsgCreateProtocolFees = {
3084
3204
  if (message.feeRecipients?.length) {
3085
3205
  obj.feeRecipients = message.feeRecipients.map((e) => AdminFeeRecipient.toJSON(e));
3086
3206
  }
3207
+ if (message.perChainFeeBP?.length) {
3208
+ obj.perChainFeeBP = message.perChainFeeBP.map((e) => PerChainFeeBP.toJSON(e));
3209
+ }
3087
3210
  return obj;
3088
3211
  },
3089
3212
  create(base) {
@@ -3096,6 +3219,7 @@ export const MsgCreateProtocolFees = {
3096
3219
  message.collectionFees = object.collectionFees?.map((e) => FixedFeeTuple.fromPartial(e)) || [];
3097
3220
  message.fulfilmentFees = object.fulfilmentFees?.map((e) => FixedFeeTuple.fromPartial(e)) || [];
3098
3221
  message.feeRecipients = object.feeRecipients?.map((e) => AdminFeeRecipient.fromPartial(e)) || [];
3222
+ message.perChainFeeBP = object.perChainFeeBP?.map((e) => PerChainFeeBP.fromPartial(e)) || [];
3099
3223
  return message;
3100
3224
  },
3101
3225
  };
@@ -3137,7 +3261,14 @@ export const MsgCreateProtocolFeesResponse = {
3137
3261
  },
3138
3262
  };
3139
3263
  function createBaseMsgUpdateProtocolFees() {
3140
- return { creator: "", feeBP: Long.UZERO, collectionFees: [], fulfilmentFees: [], feeRecipients: [] };
3264
+ return {
3265
+ creator: "",
3266
+ feeBP: Long.UZERO,
3267
+ collectionFees: [],
3268
+ fulfilmentFees: [],
3269
+ feeRecipients: [],
3270
+ perChainFeeBP: [],
3271
+ };
3141
3272
  }
3142
3273
  export const MsgUpdateProtocolFees = {
3143
3274
  encode(message, writer = new BinaryWriter()) {
@@ -3156,6 +3287,9 @@ export const MsgUpdateProtocolFees = {
3156
3287
  for (const v of message.feeRecipients) {
3157
3288
  AdminFeeRecipient.encode(v, writer.uint32(42).fork()).join();
3158
3289
  }
3290
+ for (const v of message.perChainFeeBP) {
3291
+ PerChainFeeBP.encode(v, writer.uint32(50).fork()).join();
3292
+ }
3159
3293
  return writer;
3160
3294
  },
3161
3295
  decode(input, length) {
@@ -3200,6 +3334,13 @@ export const MsgUpdateProtocolFees = {
3200
3334
  message.feeRecipients.push(AdminFeeRecipient.decode(reader, reader.uint32()));
3201
3335
  continue;
3202
3336
  }
3337
+ case 6: {
3338
+ if (tag !== 50) {
3339
+ break;
3340
+ }
3341
+ message.perChainFeeBP.push(PerChainFeeBP.decode(reader, reader.uint32()));
3342
+ continue;
3343
+ }
3203
3344
  }
3204
3345
  if ((tag & 7) === 4 || tag === 0) {
3205
3346
  break;
@@ -3221,6 +3362,9 @@ export const MsgUpdateProtocolFees = {
3221
3362
  feeRecipients: globalThis.Array.isArray(object?.feeRecipients)
3222
3363
  ? object.feeRecipients.map((e) => AdminFeeRecipient.fromJSON(e))
3223
3364
  : [],
3365
+ perChainFeeBP: globalThis.Array.isArray(object?.perChainFeeBP)
3366
+ ? object.perChainFeeBP.map((e) => PerChainFeeBP.fromJSON(e))
3367
+ : [],
3224
3368
  };
3225
3369
  },
3226
3370
  toJSON(message) {
@@ -3240,6 +3384,9 @@ export const MsgUpdateProtocolFees = {
3240
3384
  if (message.feeRecipients?.length) {
3241
3385
  obj.feeRecipients = message.feeRecipients.map((e) => AdminFeeRecipient.toJSON(e));
3242
3386
  }
3387
+ if (message.perChainFeeBP?.length) {
3388
+ obj.perChainFeeBP = message.perChainFeeBP.map((e) => PerChainFeeBP.toJSON(e));
3389
+ }
3243
3390
  return obj;
3244
3391
  },
3245
3392
  create(base) {
@@ -3252,6 +3399,7 @@ export const MsgUpdateProtocolFees = {
3252
3399
  message.collectionFees = object.collectionFees?.map((e) => FixedFeeTuple.fromPartial(e)) || [];
3253
3400
  message.fulfilmentFees = object.fulfilmentFees?.map((e) => FixedFeeTuple.fromPartial(e)) || [];
3254
3401
  message.feeRecipients = object.feeRecipients?.map((e) => AdminFeeRecipient.fromPartial(e)) || [];
3402
+ message.perChainFeeBP = object.perChainFeeBP?.map((e) => PerChainFeeBP.fromPartial(e)) || [];
3255
3403
  return message;
3256
3404
  },
3257
3405
  };
@@ -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
+ }
@@ -1,4 +1,5 @@
1
1
  export * from './iface';
2
2
  export * from './lifi-agg';
3
3
  export * from './bebop-agg';
4
+ export * from './fibrous-agg';
4
5
  export * from './autochoice';
@@ -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
+ }];
@@ -1,3 +1,4 @@
1
1
  export * from './erc20.abi';
2
2
  export * from './vault.abi';
3
3
  export * from './yakaggregator.abi';
4
+ export * from './fibrousrouter.abi';
@@ -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>;
@@ -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,4 +1,5 @@
1
1
  export * from './iface';
2
2
  export * from './lifi-agg';
3
3
  export * from './bebop-agg';
4
+ export * from './fibrous-agg';
4
5
  export * from './autochoice';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avail-project/ca-common",
3
- "version": "2.0.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
  }