@cowprotocol/sdk-contracts-ts 2.2.0-beta.0 → 2.2.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/index.d.mts CHANGED
@@ -1130,9 +1130,10 @@ declare enum Environment {
1130
1130
  Prod = 1
1131
1131
  }
1132
1132
  declare const LIMIT_CONCURRENT_REQUESTS = 5;
1133
- declare function apiUrl(environment: Environment, network: string): string;
1133
+ declare function apiUrl(environment: Environment, network: string, apiKey?: string): string;
1134
1134
  interface ApiCall {
1135
1135
  baseUrl: string;
1136
+ apiKey?: string;
1136
1137
  }
1137
1138
  interface EstimateTradeAmountQuery {
1138
1139
  sellToken: string;
@@ -1200,7 +1201,8 @@ declare enum GetQuoteErrorType {
1200
1201
  declare class Api {
1201
1202
  network: string;
1202
1203
  baseUrl: string;
1203
- constructor(network: string, baseUrlOrEnv: string | Environment);
1204
+ apiKey?: string;
1205
+ constructor(network: string, baseUrlOrEnv: string | Environment, apiKey?: string);
1204
1206
  private apiCallParams;
1205
1207
  estimateTradeAmount(query: EstimateTradeAmountQuery): Promise<BigIntish>;
1206
1208
  placeOrder(query: PlaceOrderQuery): Promise<string>;
@@ -1312,6 +1314,6 @@ declare function getTypedDataV3Signer(signer: Signer): AbstractSigner<unknown>;
1312
1314
  */
1313
1315
  declare function getIntChainIdTypedDataV4Signer(signer: Signer): AbstractSigner<unknown>;
1314
1316
 
1315
- declare const CONTRACTS_PKG_VERSION = "2.2.0-beta.0";
1317
+ declare const CONTRACTS_PKG_VERSION = "2.2.0";
1316
1318
 
1317
1319
  export { AllowListReader, Api, type ApiCall, type ApiError, type ArtifactDeployment, BUY_ETH_ADDRESS, type BatchSwapStep, type BuyAmountAfterFee, CANCELLATIONS_TYPE_FIELDS, CONTRACTS_PKG_VERSION, CONTRACT_NAMES, type CallError, type CommonQuoteQuery, type ContractName, type EcdsaSignature as ContractsEcdsaSignature, type EcdsaSigningScheme as ContractsEcdsaSigningScheme, type Order as ContractsOrder, type OrderCancellations as ContractsOrderCancellations, OrderKind as ContractsOrderKind, type Signature as ContractsSignature, SigningScheme as ContractsSigningScheme, type Trade as ContractsTrade, ContractsTs, DEPLOYER_CONTRACT, type DeploymentArguments, EIP1271_MAGICVALUE, EIP173_PROXY_ABI, type Eip1271Signature, type Eip1271SignatureData, type EncodedSettlement, type EncodedSwap, Environment, type EstimateTradeAmountQuery, FLAG_MASKS, type FlagKey, type FlagOptions, type FlagValue, type GetExecutedSellAmountQuery, GetQuoteErrorType, type GetQuoteResponse, type HashLike, type Interaction, type InteractionLike, InteractionStage, LIMIT_CONCURRENT_REQUESTS, type MaybeNamedArtifactArtifactDeployment, type NamedArtifactDeployment, type NormalizedOrder, ORDER_TYPE_FIELDS, ORDER_TYPE_HASH, ORDER_UID_LENGTH, OrderBalance, type OrderDetailResponse, type OrderFlags, type OrderRefunds, type OrderUidParams, PRE_SIGNED, type PlaceOrderQuery, type PreSignSignature, type Prices, QuotePriceQuality, type QuoteQuery, SALT, type SellAmountAfterFee, type SellAmountBeforeFee, SettlementEncoder, SettlementReader, type Swap, SwapEncoder, type SwapExecution, type Timestamp, TokenRegistry, type TradeExecution, type TradeFlags, type TradeSimulation, type TradeSimulationBalanceDelta, type TradeSimulationResult, TradeSimulator, apiUrl, computeOrderUid, decodeEip1271SignatureData, decodeOrder, decodeOrderFlags, decodeSignatureOwner, decodeSigningScheme, decodeTradeFlags, deterministicDeploymentAddress, ecdsaSignTypedData, encodeEip1271SignatureData, encodeOrderFlags, encodeSignatureData, encodeSigningScheme, encodeSwapStep, encodeTrade, encodeTradeFlags, extractOrderUidParams, getIntChainIdTypedDataV4Signer, getTypedDataV3Signer, getTypedDataVersionedSigner, grantRequiredRoles, hashOrder, hashOrderCancellation, hashOrderCancellations, hashTypedData, hashify, implementationAddress, normalizeBuyTokenBalance, normalizeInteraction, normalizeInteractions, normalizeOrder, ownerAddress, packOrderUidParams, signOrder, signOrderCancellation, signOrderCancellations, timestamp };
package/dist/index.d.ts CHANGED
@@ -1130,9 +1130,10 @@ declare enum Environment {
1130
1130
  Prod = 1
1131
1131
  }
1132
1132
  declare const LIMIT_CONCURRENT_REQUESTS = 5;
1133
- declare function apiUrl(environment: Environment, network: string): string;
1133
+ declare function apiUrl(environment: Environment, network: string, apiKey?: string): string;
1134
1134
  interface ApiCall {
1135
1135
  baseUrl: string;
1136
+ apiKey?: string;
1136
1137
  }
1137
1138
  interface EstimateTradeAmountQuery {
1138
1139
  sellToken: string;
@@ -1200,7 +1201,8 @@ declare enum GetQuoteErrorType {
1200
1201
  declare class Api {
1201
1202
  network: string;
1202
1203
  baseUrl: string;
1203
- constructor(network: string, baseUrlOrEnv: string | Environment);
1204
+ apiKey?: string;
1205
+ constructor(network: string, baseUrlOrEnv: string | Environment, apiKey?: string);
1204
1206
  private apiCallParams;
1205
1207
  estimateTradeAmount(query: EstimateTradeAmountQuery): Promise<BigIntish>;
1206
1208
  placeOrder(query: PlaceOrderQuery): Promise<string>;
@@ -1312,6 +1314,6 @@ declare function getTypedDataV3Signer(signer: Signer): AbstractSigner<unknown>;
1312
1314
  */
1313
1315
  declare function getIntChainIdTypedDataV4Signer(signer: Signer): AbstractSigner<unknown>;
1314
1316
 
1315
- declare const CONTRACTS_PKG_VERSION = "2.2.0-beta.0";
1317
+ declare const CONTRACTS_PKG_VERSION = "2.2.0";
1316
1318
 
1317
1319
  export { AllowListReader, Api, type ApiCall, type ApiError, type ArtifactDeployment, BUY_ETH_ADDRESS, type BatchSwapStep, type BuyAmountAfterFee, CANCELLATIONS_TYPE_FIELDS, CONTRACTS_PKG_VERSION, CONTRACT_NAMES, type CallError, type CommonQuoteQuery, type ContractName, type EcdsaSignature as ContractsEcdsaSignature, type EcdsaSigningScheme as ContractsEcdsaSigningScheme, type Order as ContractsOrder, type OrderCancellations as ContractsOrderCancellations, OrderKind as ContractsOrderKind, type Signature as ContractsSignature, SigningScheme as ContractsSigningScheme, type Trade as ContractsTrade, ContractsTs, DEPLOYER_CONTRACT, type DeploymentArguments, EIP1271_MAGICVALUE, EIP173_PROXY_ABI, type Eip1271Signature, type Eip1271SignatureData, type EncodedSettlement, type EncodedSwap, Environment, type EstimateTradeAmountQuery, FLAG_MASKS, type FlagKey, type FlagOptions, type FlagValue, type GetExecutedSellAmountQuery, GetQuoteErrorType, type GetQuoteResponse, type HashLike, type Interaction, type InteractionLike, InteractionStage, LIMIT_CONCURRENT_REQUESTS, type MaybeNamedArtifactArtifactDeployment, type NamedArtifactDeployment, type NormalizedOrder, ORDER_TYPE_FIELDS, ORDER_TYPE_HASH, ORDER_UID_LENGTH, OrderBalance, type OrderDetailResponse, type OrderFlags, type OrderRefunds, type OrderUidParams, PRE_SIGNED, type PlaceOrderQuery, type PreSignSignature, type Prices, QuotePriceQuality, type QuoteQuery, SALT, type SellAmountAfterFee, type SellAmountBeforeFee, SettlementEncoder, SettlementReader, type Swap, SwapEncoder, type SwapExecution, type Timestamp, TokenRegistry, type TradeExecution, type TradeFlags, type TradeSimulation, type TradeSimulationBalanceDelta, type TradeSimulationResult, TradeSimulator, apiUrl, computeOrderUid, decodeEip1271SignatureData, decodeOrder, decodeOrderFlags, decodeSignatureOwner, decodeSigningScheme, decodeTradeFlags, deterministicDeploymentAddress, ecdsaSignTypedData, encodeEip1271SignatureData, encodeOrderFlags, encodeSignatureData, encodeSigningScheme, encodeSwapStep, encodeTrade, encodeTradeFlags, extractOrderUidParams, getIntChainIdTypedDataV4Signer, getTypedDataV3Signer, getTypedDataVersionedSigner, grantRequiredRoles, hashOrder, hashOrderCancellation, hashOrderCancellations, hashTypedData, hashify, implementationAddress, normalizeBuyTokenBalance, normalizeInteraction, normalizeInteractions, normalizeOrder, ownerAddress, packOrderUidParams, signOrder, signOrderCancellation, signOrderCancellations, timestamp };
package/dist/index.js CHANGED
@@ -137,14 +137,13 @@ function normalizeBuyTokenBalance(balance) {
137
137
  }
138
138
  }
139
139
  function normalizeOrder(order) {
140
- const adapter = (0, import_sdk_common.getGlobalAdapter)();
141
- if (order.receiver === adapter.ZERO_ADDRESS) {
140
+ if (order.receiver === import_sdk_common.ZERO_ADDRESS) {
142
141
  throw new Error("receiver cannot be address(0)");
143
142
  }
144
143
  const normalizedOrder = {
145
144
  ...order,
146
145
  sellTokenBalance: order.sellTokenBalance ?? "erc20" /* ERC20 */,
147
- receiver: order.receiver ?? adapter.ZERO_ADDRESS,
146
+ receiver: order.receiver ?? import_sdk_common.ZERO_ADDRESS,
148
147
  validTo: timestamp(order.validTo),
149
148
  appData: hashify(order.appData),
150
149
  buyTokenBalance: normalizeBuyTokenBalance(order.buyTokenBalance)
@@ -895,15 +894,21 @@ var Environment = /* @__PURE__ */ ((Environment2) => {
895
894
  return Environment2;
896
895
  })(Environment || {});
897
896
  var LIMIT_CONCURRENT_REQUESTS = 5;
898
- function apiUrl(environment, network) {
897
+ var PARTNER_PROD_BASE_URL = "https://partners.cow.fi";
898
+ var PARTNER_DEV_BASE_URL = "https://partners.barn.cow.fi";
899
+ function apiUrl(environment, network, apiKey) {
900
+ let baseUrl;
899
901
  switch (environment) {
900
902
  case 0 /* Dev */:
901
- return `https://barn.api.cow.fi/${network}`;
903
+ baseUrl = apiKey ? PARTNER_DEV_BASE_URL : "https://barn.api.cow.fi";
904
+ break;
902
905
  case 1 /* Prod */:
903
- return `https://api.cow.fi/${network}`;
906
+ baseUrl = apiKey ? PARTNER_PROD_BASE_URL : "https://api.cow.fi";
907
+ break;
904
908
  default:
905
909
  throw new Error("Invalid environment");
906
910
  }
911
+ return `${baseUrl}/${network}`;
907
912
  }
908
913
  var QuotePriceQuality = /* @__PURE__ */ ((QuotePriceQuality2) => {
909
914
  QuotePriceQuality2["FAST"] = "fast";
@@ -939,9 +944,13 @@ function apiSigningScheme(scheme) {
939
944
  throw new Error(`Unsupported signing scheme ${scheme}`);
940
945
  }
941
946
  }
942
- async function call(route, baseUrl, init) {
947
+ async function call(route, baseUrl, init, apiKey) {
943
948
  const url = `${baseUrl}/api/v1/${route}`;
944
- const response = await fetch(url, init);
949
+ const headers = {
950
+ ...init?.headers ?? {},
951
+ ...apiKey ? { "X-API-Key": apiKey } : {}
952
+ };
953
+ const response = await fetch(url, { ...init, headers });
945
954
  const body = await response.text();
946
955
  if (!response.ok) {
947
956
  const error = new Error(
@@ -960,7 +969,8 @@ async function estimateTradeAmount({
960
969
  buyToken,
961
970
  kind,
962
971
  amount,
963
- baseUrl
972
+ baseUrl,
973
+ apiKey
964
974
  }) {
965
975
  const side = kind == "sell" /* SELL */ ? {
966
976
  kind: "sell" /* SELL */,
@@ -970,7 +980,7 @@ async function estimateTradeAmount({
970
980
  buyAmountAfterFee: amount
971
981
  };
972
982
  const { quote } = await getQuote(
973
- { baseUrl },
983
+ { baseUrl, apiKey },
974
984
  {
975
985
  from: "0x0000000000000000000000000000000000000000",
976
986
  sellToken,
@@ -979,42 +989,57 @@ async function estimateTradeAmount({
979
989
  ...side
980
990
  }
981
991
  );
982
- if (quote.buyToken.toLowerCase() !== buyToken.toLowerCase()) {
992
+ if (!(0, import_sdk_common9.areAddressesEqual)(quote.buyToken, buyToken)) {
983
993
  throw new Error(
984
- `Price returned for sell token ${sellToken} uses an incorrect quote token (${quote.buyToken.toLowerCase()} instead of ${buyToken.toLowerCase()})`
994
+ `Price returned for sell token ${sellToken} uses an incorrect quote token (${quote.buyToken} instead of ${buyToken})`
985
995
  );
986
996
  }
987
997
  const estimatedAmount = kind == "sell" /* SELL */ ? quote.buyAmount : quote.sellAmount;
988
998
  return (0, import_sdk_common9.getGlobalAdapter)().utils.toBigIntish(estimatedAmount);
989
999
  }
990
- async function placeOrder({ order, signature, baseUrl, from }) {
1000
+ async function placeOrder({
1001
+ order,
1002
+ signature,
1003
+ baseUrl,
1004
+ from,
1005
+ apiKey
1006
+ }) {
991
1007
  const normalizedOrder = normalizeOrder(order);
992
1008
  const adapter = (0, import_sdk_common9.getGlobalAdapter)();
993
- return await call("orders", baseUrl, {
994
- method: "post",
995
- body: JSON.stringify({
996
- sellToken: normalizedOrder.sellToken,
997
- buyToken: normalizedOrder.buyToken,
998
- sellAmount: String(adapter.utils.toBigIntish(normalizedOrder.sellAmount)),
999
- buyAmount: String(adapter.utils.toBigIntish(normalizedOrder.buyAmount)),
1000
- validTo: normalizedOrder.validTo,
1001
- appData: normalizedOrder.appData,
1002
- feeAmount: String(adapter.utils.toBigIntish(normalizedOrder.feeAmount)),
1003
- kind: apiKind(order.kind),
1004
- partiallyFillable: normalizedOrder.partiallyFillable,
1005
- signature: encodeSignatureData(signature),
1006
- signingScheme: apiSigningScheme(signature.scheme),
1007
- receiver: normalizedOrder.receiver,
1008
- from
1009
- }),
1010
- headers: { "Content-Type": "application/json" }
1011
- });
1009
+ return await call(
1010
+ "orders",
1011
+ baseUrl,
1012
+ {
1013
+ method: "post",
1014
+ body: JSON.stringify({
1015
+ sellToken: normalizedOrder.sellToken,
1016
+ buyToken: normalizedOrder.buyToken,
1017
+ sellAmount: String(adapter.utils.toBigIntish(normalizedOrder.sellAmount)),
1018
+ buyAmount: String(adapter.utils.toBigIntish(normalizedOrder.buyAmount)),
1019
+ validTo: normalizedOrder.validTo,
1020
+ appData: normalizedOrder.appData,
1021
+ feeAmount: String(adapter.utils.toBigIntish(normalizedOrder.feeAmount)),
1022
+ kind: apiKind(order.kind),
1023
+ partiallyFillable: normalizedOrder.partiallyFillable,
1024
+ signature: encodeSignatureData(signature),
1025
+ signingScheme: apiSigningScheme(signature.scheme),
1026
+ receiver: normalizedOrder.receiver,
1027
+ from
1028
+ }),
1029
+ headers: { "Content-Type": "application/json" }
1030
+ },
1031
+ apiKey
1032
+ );
1012
1033
  }
1013
- async function getExecutedSellAmount({ uid, baseUrl }) {
1014
- const response = await call(`orders/${uid}`, baseUrl);
1034
+ async function getExecutedSellAmount({
1035
+ uid,
1036
+ baseUrl,
1037
+ apiKey
1038
+ }) {
1039
+ const response = await call(`orders/${uid}`, baseUrl, void 0, apiKey);
1015
1040
  return (0, import_sdk_common9.getGlobalAdapter)().utils.toBigIntish(response.executedSellAmount);
1016
1041
  }
1017
- async function getQuote({ baseUrl }, quote) {
1042
+ async function getQuote({ baseUrl, apiKey }, quote) {
1018
1043
  if (quote.sellAmountBeforeFee) {
1019
1044
  ;
1020
1045
  quote.sellAmountBeforeFee = String(quote.sellAmountBeforeFee);
@@ -1027,27 +1052,32 @@ async function getQuote({ baseUrl }, quote) {
1027
1052
  ;
1028
1053
  quote.buyAmountAfterFee = String(quote.buyAmountAfterFee);
1029
1054
  }
1030
- return call("quote", baseUrl, {
1031
- method: "post",
1032
- headers: { "Content-Type": "application/json" },
1033
- body: JSON.stringify(quote)
1034
- });
1055
+ return call(
1056
+ "quote",
1057
+ baseUrl,
1058
+ {
1059
+ method: "post",
1060
+ headers: { "Content-Type": "application/json" },
1061
+ body: JSON.stringify(quote)
1062
+ },
1063
+ apiKey
1064
+ );
1035
1065
  }
1036
1066
  var Api = class {
1037
1067
  network;
1038
1068
  baseUrl;
1039
- constructor(network, baseUrlOrEnv) {
1069
+ apiKey;
1070
+ constructor(network, baseUrlOrEnv, apiKey) {
1040
1071
  this.network = network;
1041
- let baseUrl;
1072
+ this.apiKey = apiKey;
1042
1073
  if (typeof baseUrlOrEnv === "string") {
1043
- baseUrl = baseUrlOrEnv;
1074
+ this.baseUrl = baseUrlOrEnv;
1044
1075
  } else {
1045
- baseUrl = apiUrl(baseUrlOrEnv, network);
1076
+ this.baseUrl = apiUrl(baseUrlOrEnv, network, apiKey);
1046
1077
  }
1047
- this.baseUrl = baseUrl;
1048
1078
  }
1049
1079
  apiCallParams() {
1050
- return { network: this.network, baseUrl: this.baseUrl };
1080
+ return { network: this.network, baseUrl: this.baseUrl, apiKey: this.apiKey };
1051
1081
  }
1052
1082
  async estimateTradeAmount(query) {
1053
1083
  return estimateTradeAmount({ ...this.apiCallParams(), ...query });
@@ -1177,7 +1207,7 @@ function getIntChainIdTypedDataV4Signer(signer) {
1177
1207
  }
1178
1208
 
1179
1209
  // src/generated/packageVersion.ts
1180
- var CONTRACTS_PKG_VERSION = "2.2.0-beta.0";
1210
+ var CONTRACTS_PKG_VERSION = "2.2.0";
1181
1211
  // Annotate the CommonJS export names for ESM import in node:
1182
1212
  0 && (module.exports = {
1183
1213
  AllowListReader,
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  import { setGlobalAdapter as setGlobalAdapter3 } from "@cowprotocol/sdk-common";
3
3
 
4
4
  // src/order.ts
5
- import { getGlobalAdapter } from "@cowprotocol/sdk-common";
5
+ import { getGlobalAdapter, ZERO_ADDRESS } from "@cowprotocol/sdk-common";
6
6
  var BUY_ETH_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
7
7
  var OrderBalance = /* @__PURE__ */ ((OrderBalance3) => {
8
8
  OrderBalance3["ERC20"] = "erc20";
@@ -45,14 +45,13 @@ function normalizeBuyTokenBalance(balance) {
45
45
  }
46
46
  }
47
47
  function normalizeOrder(order) {
48
- const adapter = getGlobalAdapter();
49
- if (order.receiver === adapter.ZERO_ADDRESS) {
48
+ if (order.receiver === ZERO_ADDRESS) {
50
49
  throw new Error("receiver cannot be address(0)");
51
50
  }
52
51
  const normalizedOrder = {
53
52
  ...order,
54
53
  sellTokenBalance: order.sellTokenBalance ?? "erc20" /* ERC20 */,
55
- receiver: order.receiver ?? adapter.ZERO_ADDRESS,
54
+ receiver: order.receiver ?? ZERO_ADDRESS,
56
55
  validTo: timestamp(order.validTo),
57
56
  appData: hashify(order.appData),
58
57
  buyTokenBalance: normalizeBuyTokenBalance(order.buyTokenBalance)
@@ -801,22 +800,28 @@ var ContractsTs = class {
801
800
  };
802
801
 
803
802
  // src/api.ts
804
- import { getGlobalAdapter as getGlobalAdapter7 } from "@cowprotocol/sdk-common";
803
+ import { areAddressesEqual, getGlobalAdapter as getGlobalAdapter7 } from "@cowprotocol/sdk-common";
805
804
  var Environment = /* @__PURE__ */ ((Environment2) => {
806
805
  Environment2[Environment2["Dev"] = 0] = "Dev";
807
806
  Environment2[Environment2["Prod"] = 1] = "Prod";
808
807
  return Environment2;
809
808
  })(Environment || {});
810
809
  var LIMIT_CONCURRENT_REQUESTS = 5;
811
- function apiUrl(environment, network) {
810
+ var PARTNER_PROD_BASE_URL = "https://partners.cow.fi";
811
+ var PARTNER_DEV_BASE_URL = "https://partners.barn.cow.fi";
812
+ function apiUrl(environment, network, apiKey) {
813
+ let baseUrl;
812
814
  switch (environment) {
813
815
  case 0 /* Dev */:
814
- return `https://barn.api.cow.fi/${network}`;
816
+ baseUrl = apiKey ? PARTNER_DEV_BASE_URL : "https://barn.api.cow.fi";
817
+ break;
815
818
  case 1 /* Prod */:
816
- return `https://api.cow.fi/${network}`;
819
+ baseUrl = apiKey ? PARTNER_PROD_BASE_URL : "https://api.cow.fi";
820
+ break;
817
821
  default:
818
822
  throw new Error("Invalid environment");
819
823
  }
824
+ return `${baseUrl}/${network}`;
820
825
  }
821
826
  var QuotePriceQuality = /* @__PURE__ */ ((QuotePriceQuality2) => {
822
827
  QuotePriceQuality2["FAST"] = "fast";
@@ -852,9 +857,13 @@ function apiSigningScheme(scheme) {
852
857
  throw new Error(`Unsupported signing scheme ${scheme}`);
853
858
  }
854
859
  }
855
- async function call(route, baseUrl, init) {
860
+ async function call(route, baseUrl, init, apiKey) {
856
861
  const url = `${baseUrl}/api/v1/${route}`;
857
- const response = await fetch(url, init);
862
+ const headers = {
863
+ ...init?.headers ?? {},
864
+ ...apiKey ? { "X-API-Key": apiKey } : {}
865
+ };
866
+ const response = await fetch(url, { ...init, headers });
858
867
  const body = await response.text();
859
868
  if (!response.ok) {
860
869
  const error = new Error(
@@ -873,7 +882,8 @@ async function estimateTradeAmount({
873
882
  buyToken,
874
883
  kind,
875
884
  amount,
876
- baseUrl
885
+ baseUrl,
886
+ apiKey
877
887
  }) {
878
888
  const side = kind == "sell" /* SELL */ ? {
879
889
  kind: "sell" /* SELL */,
@@ -883,7 +893,7 @@ async function estimateTradeAmount({
883
893
  buyAmountAfterFee: amount
884
894
  };
885
895
  const { quote } = await getQuote(
886
- { baseUrl },
896
+ { baseUrl, apiKey },
887
897
  {
888
898
  from: "0x0000000000000000000000000000000000000000",
889
899
  sellToken,
@@ -892,42 +902,57 @@ async function estimateTradeAmount({
892
902
  ...side
893
903
  }
894
904
  );
895
- if (quote.buyToken.toLowerCase() !== buyToken.toLowerCase()) {
905
+ if (!areAddressesEqual(quote.buyToken, buyToken)) {
896
906
  throw new Error(
897
- `Price returned for sell token ${sellToken} uses an incorrect quote token (${quote.buyToken.toLowerCase()} instead of ${buyToken.toLowerCase()})`
907
+ `Price returned for sell token ${sellToken} uses an incorrect quote token (${quote.buyToken} instead of ${buyToken})`
898
908
  );
899
909
  }
900
910
  const estimatedAmount = kind == "sell" /* SELL */ ? quote.buyAmount : quote.sellAmount;
901
911
  return getGlobalAdapter7().utils.toBigIntish(estimatedAmount);
902
912
  }
903
- async function placeOrder({ order, signature, baseUrl, from }) {
913
+ async function placeOrder({
914
+ order,
915
+ signature,
916
+ baseUrl,
917
+ from,
918
+ apiKey
919
+ }) {
904
920
  const normalizedOrder = normalizeOrder(order);
905
921
  const adapter = getGlobalAdapter7();
906
- return await call("orders", baseUrl, {
907
- method: "post",
908
- body: JSON.stringify({
909
- sellToken: normalizedOrder.sellToken,
910
- buyToken: normalizedOrder.buyToken,
911
- sellAmount: String(adapter.utils.toBigIntish(normalizedOrder.sellAmount)),
912
- buyAmount: String(adapter.utils.toBigIntish(normalizedOrder.buyAmount)),
913
- validTo: normalizedOrder.validTo,
914
- appData: normalizedOrder.appData,
915
- feeAmount: String(adapter.utils.toBigIntish(normalizedOrder.feeAmount)),
916
- kind: apiKind(order.kind),
917
- partiallyFillable: normalizedOrder.partiallyFillable,
918
- signature: encodeSignatureData(signature),
919
- signingScheme: apiSigningScheme(signature.scheme),
920
- receiver: normalizedOrder.receiver,
921
- from
922
- }),
923
- headers: { "Content-Type": "application/json" }
924
- });
922
+ return await call(
923
+ "orders",
924
+ baseUrl,
925
+ {
926
+ method: "post",
927
+ body: JSON.stringify({
928
+ sellToken: normalizedOrder.sellToken,
929
+ buyToken: normalizedOrder.buyToken,
930
+ sellAmount: String(adapter.utils.toBigIntish(normalizedOrder.sellAmount)),
931
+ buyAmount: String(adapter.utils.toBigIntish(normalizedOrder.buyAmount)),
932
+ validTo: normalizedOrder.validTo,
933
+ appData: normalizedOrder.appData,
934
+ feeAmount: String(adapter.utils.toBigIntish(normalizedOrder.feeAmount)),
935
+ kind: apiKind(order.kind),
936
+ partiallyFillable: normalizedOrder.partiallyFillable,
937
+ signature: encodeSignatureData(signature),
938
+ signingScheme: apiSigningScheme(signature.scheme),
939
+ receiver: normalizedOrder.receiver,
940
+ from
941
+ }),
942
+ headers: { "Content-Type": "application/json" }
943
+ },
944
+ apiKey
945
+ );
925
946
  }
926
- async function getExecutedSellAmount({ uid, baseUrl }) {
927
- const response = await call(`orders/${uid}`, baseUrl);
947
+ async function getExecutedSellAmount({
948
+ uid,
949
+ baseUrl,
950
+ apiKey
951
+ }) {
952
+ const response = await call(`orders/${uid}`, baseUrl, void 0, apiKey);
928
953
  return getGlobalAdapter7().utils.toBigIntish(response.executedSellAmount);
929
954
  }
930
- async function getQuote({ baseUrl }, quote) {
955
+ async function getQuote({ baseUrl, apiKey }, quote) {
931
956
  if (quote.sellAmountBeforeFee) {
932
957
  ;
933
958
  quote.sellAmountBeforeFee = String(quote.sellAmountBeforeFee);
@@ -940,27 +965,32 @@ async function getQuote({ baseUrl }, quote) {
940
965
  ;
941
966
  quote.buyAmountAfterFee = String(quote.buyAmountAfterFee);
942
967
  }
943
- return call("quote", baseUrl, {
944
- method: "post",
945
- headers: { "Content-Type": "application/json" },
946
- body: JSON.stringify(quote)
947
- });
968
+ return call(
969
+ "quote",
970
+ baseUrl,
971
+ {
972
+ method: "post",
973
+ headers: { "Content-Type": "application/json" },
974
+ body: JSON.stringify(quote)
975
+ },
976
+ apiKey
977
+ );
948
978
  }
949
979
  var Api = class {
950
980
  network;
951
981
  baseUrl;
952
- constructor(network, baseUrlOrEnv) {
982
+ apiKey;
983
+ constructor(network, baseUrlOrEnv, apiKey) {
953
984
  this.network = network;
954
- let baseUrl;
985
+ this.apiKey = apiKey;
955
986
  if (typeof baseUrlOrEnv === "string") {
956
- baseUrl = baseUrlOrEnv;
987
+ this.baseUrl = baseUrlOrEnv;
957
988
  } else {
958
- baseUrl = apiUrl(baseUrlOrEnv, network);
989
+ this.baseUrl = apiUrl(baseUrlOrEnv, network, apiKey);
959
990
  }
960
- this.baseUrl = baseUrl;
961
991
  }
962
992
  apiCallParams() {
963
- return { network: this.network, baseUrl: this.baseUrl };
993
+ return { network: this.network, baseUrl: this.baseUrl, apiKey: this.apiKey };
964
994
  }
965
995
  async estimateTradeAmount(query) {
966
996
  return estimateTradeAmount({ ...this.apiCallParams(), ...query });
@@ -1090,7 +1120,7 @@ function getIntChainIdTypedDataV4Signer(signer) {
1090
1120
  }
1091
1121
 
1092
1122
  // src/generated/packageVersion.ts
1093
- var CONTRACTS_PKG_VERSION = "2.2.0-beta.0";
1123
+ var CONTRACTS_PKG_VERSION = "2.2.0";
1094
1124
  export {
1095
1125
  AllowListReader,
1096
1126
  Api,
package/package.json CHANGED
@@ -1,7 +1,12 @@
1
1
  {
2
2
  "name": "@cowprotocol/sdk-contracts-ts",
3
- "version": "2.2.0-beta.0",
3
+ "version": "2.2.0",
4
4
  "description": "TypeScript contract bindings for CoW Protocol SDK",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/cowprotocol/cow-sdk.git",
8
+ "directory": "packages/contracts-ts"
9
+ },
5
10
  "main": "./dist/index.js",
6
11
  "module": "./dist/index.mjs",
7
12
  "types": "./dist/index.d.ts",
@@ -14,8 +19,8 @@
14
19
  "access": "public"
15
20
  },
16
21
  "dependencies": {
17
- "@cowprotocol/sdk-config": "0.3.3-beta.0",
18
- "@cowprotocol/sdk-common": "0.4.0-beta.0"
22
+ "@cowprotocol/sdk-common": "0.8.2",
23
+ "@cowprotocol/sdk-config": "1.1.2"
19
24
  },
20
25
  "devDependencies": {
21
26
  "@types/jest": "^29.5.5",
@@ -29,9 +34,9 @@
29
34
  "typescript": "^5.2.2",
30
35
  "viem": "^2.28.4",
31
36
  "@cow-sdk/typescript-config": "0.0.0-beta.0",
32
- "@cowprotocol/sdk-ethers-v5-adapter": "0.2.3-beta.0",
33
- "@cowprotocol/sdk-ethers-v6-adapter": "0.2.3-beta.0",
34
- "@cowprotocol/sdk-viem-adapter": "0.3.0-beta.0"
37
+ "@cowprotocol/sdk-ethers-v6-adapter": "0.4.0",
38
+ "@cowprotocol/sdk-ethers-v5-adapter": "0.4.0",
39
+ "@cowprotocol/sdk-viem-adapter": "0.3.14"
35
40
  },
36
41
  "scripts": {
37
42
  "build": "tsup src/index.ts --format esm,cjs --dts",