@virtuals-protocol/acp-node 0.2.0-beta.7 → 0.2.0-beta.9

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.mjs CHANGED
@@ -47,7 +47,7 @@ var require_package = __commonJS({
47
47
  "package.json"(exports, module) {
48
48
  module.exports = {
49
49
  name: "@virtuals-protocol/acp-node",
50
- version: "0.2.0-beta.7",
50
+ version: "0.2.0-beta.9",
51
51
  main: "./dist/index.js",
52
52
  module: "./dist/index.mjs",
53
53
  types: "./dist/index.d.ts",
@@ -1859,43 +1859,242 @@ import { alchemy } from "@account-kit/infra";
1859
1859
  import {
1860
1860
  createModularAccountV2Client
1861
1861
  } from "@account-kit/smart-contracts";
1862
+ import { decodeEventLog, encodeFunctionData, erc20Abi, fromHex } from "viem";
1862
1863
 
1863
- // src/configs.ts
1864
+ // src/acpConfigs.ts
1864
1865
  import { baseSepolia, base } from "@account-kit/infra";
1865
- var baseSepoliaAcpConfig = {
1866
- chain: baseSepolia,
1867
- contractAddress: "0x8Db6B1c839Fc8f6bd35777E194677B67b4D51928",
1868
- paymentTokenAddress: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
1869
- paymentTokenDecimals: 6,
1870
- alchemyRpcUrl: "https://alchemy-proxy.virtuals.io/api/proxy/rpc",
1871
- acpUrl: "https://acpx.virtuals.gg",
1872
- priorityFeeMultiplier: 2,
1873
- maxFeePerGas: 2e7,
1874
- maxPriorityFeePerGas: 21e6
1866
+
1867
+ // src/acpFare.ts
1868
+ import { ethAddress, parseUnits } from "viem";
1869
+ var Fare = class {
1870
+ constructor(contractAddress, decimals) {
1871
+ this.contractAddress = contractAddress;
1872
+ this.decimals = decimals;
1873
+ }
1874
+ formatAmount(amount) {
1875
+ return parseUnits(amount.toString(), this.decimals);
1876
+ }
1877
+ };
1878
+ var FareAmount = class _FareAmount {
1879
+ constructor(fareAmount, fare) {
1880
+ this.amount = fare.formatAmount(
1881
+ this.truncateTo6Decimals(fareAmount.toString())
1882
+ );
1883
+ this.fare = fare;
1884
+ }
1885
+ truncateTo6Decimals(input) {
1886
+ const [intPart, decPart = ""] = input.split(".");
1887
+ if (decPart === "") {
1888
+ return parseFloat(intPart);
1889
+ }
1890
+ const truncated = decPart.slice(0, 6).padEnd(6, "0");
1891
+ return parseFloat(`${intPart}.${truncated}`);
1892
+ }
1893
+ add(other) {
1894
+ if (this.fare.contractAddress !== other.fare.contractAddress) {
1895
+ throw new Error("Token addresses do not match");
1896
+ }
1897
+ return new _FareAmount(Number(this.amount + other.amount), this.fare);
1898
+ }
1899
+ };
1900
+ var FareBigInt = class _FareBigInt {
1901
+ constructor(amount, fare) {
1902
+ this.amount = amount;
1903
+ this.fare = fare;
1904
+ }
1905
+ add(other) {
1906
+ if (this.fare.contractAddress !== other.fare.contractAddress) {
1907
+ throw new Error("Token addresses do not match");
1908
+ }
1909
+ return new _FareBigInt(this.amount + other.amount, this.fare);
1910
+ }
1875
1911
  };
1876
- var baseAcpConfig = {
1877
- chain: base,
1878
- contractAddress: "0x6a1FE26D54ab0d3E1e3168f2e0c0cDa5cC0A0A4A",
1879
- paymentTokenAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
1880
- paymentTokenDecimals: 6,
1881
- alchemyRpcUrl: "https://alchemy-proxy-prod.virtuals.io/api/proxy/rpc",
1882
- acpUrl: "https://acpx.virtuals.io",
1883
- priorityFeeMultiplier: 2,
1884
- maxFeePerGas: 2e7,
1885
- maxPriorityFeePerGas: 21e6
1912
+ var wethFare = new Fare("0x4200000000000000000000000000000000000006", 18);
1913
+ var ethFare = new Fare(ethAddress, 18);
1914
+
1915
+ // src/acpConfigs.ts
1916
+ var AcpContractConfig = class {
1917
+ constructor(chain, contractAddress, baseFare, alchemyRpcUrl, acpUrl, rpcEndpoint) {
1918
+ this.chain = chain;
1919
+ this.contractAddress = contractAddress;
1920
+ this.baseFare = baseFare;
1921
+ this.alchemyRpcUrl = alchemyRpcUrl;
1922
+ this.acpUrl = acpUrl;
1923
+ this.rpcEndpoint = rpcEndpoint;
1924
+ }
1886
1925
  };
1926
+ var baseSepoliaAcpConfig = new AcpContractConfig(
1927
+ baseSepolia,
1928
+ "0x8Db6B1c839Fc8f6bd35777E194677B67b4D51928",
1929
+ new Fare("0x036CbD53842c5426634e7929541eC2318f3dCF7e", 6),
1930
+ "https://alchemy-proxy.virtuals.io/api/proxy/rpc",
1931
+ "https://acpx.virtuals.gg"
1932
+ );
1933
+ var baseAcpConfig = new AcpContractConfig(
1934
+ base,
1935
+ "0x6a1FE26D54ab0d3E1e3168f2e0c0cDa5cC0A0A4A",
1936
+ new Fare("0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", 6),
1937
+ "https://alchemy-proxy-prod.virtuals.io/api/proxy/rpc",
1938
+ "https://acpx.virtuals.io"
1939
+ );
1940
+
1941
+ // src/wethAbi.ts
1942
+ var WETH_ABI = [
1943
+ {
1944
+ anonymous: false,
1945
+ inputs: [
1946
+ { indexed: true, internalType: "address", name: "src", type: "address" },
1947
+ { indexed: true, internalType: "address", name: "guy", type: "address" },
1948
+ { indexed: false, internalType: "uint256", name: "wad", type: "uint256" }
1949
+ ],
1950
+ name: "Approval",
1951
+ type: "event"
1952
+ },
1953
+ {
1954
+ anonymous: false,
1955
+ inputs: [
1956
+ { indexed: true, internalType: "address", name: "dst", type: "address" },
1957
+ { indexed: false, internalType: "uint256", name: "wad", type: "uint256" }
1958
+ ],
1959
+ name: "Deposit",
1960
+ type: "event"
1961
+ },
1962
+ {
1963
+ anonymous: false,
1964
+ inputs: [
1965
+ { indexed: true, internalType: "address", name: "src", type: "address" },
1966
+ { indexed: true, internalType: "address", name: "dst", type: "address" },
1967
+ { indexed: false, internalType: "uint256", name: "wad", type: "uint256" }
1968
+ ],
1969
+ name: "Transfer",
1970
+ type: "event"
1971
+ },
1972
+ {
1973
+ anonymous: false,
1974
+ inputs: [
1975
+ { indexed: true, internalType: "address", name: "src", type: "address" },
1976
+ { indexed: false, internalType: "uint256", name: "wad", type: "uint256" }
1977
+ ],
1978
+ name: "Withdrawal",
1979
+ type: "event"
1980
+ },
1981
+ { payable: true, stateMutability: "payable", type: "fallback" },
1982
+ {
1983
+ constant: true,
1984
+ inputs: [
1985
+ { internalType: "address", name: "", type: "address" },
1986
+ { internalType: "address", name: "", type: "address" }
1987
+ ],
1988
+ name: "allowance",
1989
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
1990
+ payable: false,
1991
+ stateMutability: "view",
1992
+ type: "function"
1993
+ },
1994
+ {
1995
+ constant: false,
1996
+ inputs: [
1997
+ { internalType: "address", name: "guy", type: "address" },
1998
+ { internalType: "uint256", name: "wad", type: "uint256" }
1999
+ ],
2000
+ name: "approve",
2001
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
2002
+ payable: false,
2003
+ stateMutability: "nonpayable",
2004
+ type: "function"
2005
+ },
2006
+ {
2007
+ constant: true,
2008
+ inputs: [{ internalType: "address", name: "", type: "address" }],
2009
+ name: "balanceOf",
2010
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
2011
+ payable: false,
2012
+ stateMutability: "view",
2013
+ type: "function"
2014
+ },
2015
+ {
2016
+ constant: true,
2017
+ inputs: [],
2018
+ name: "decimals",
2019
+ outputs: [{ internalType: "uint8", name: "", type: "uint8" }],
2020
+ payable: false,
2021
+ stateMutability: "view",
2022
+ type: "function"
2023
+ },
2024
+ {
2025
+ constant: false,
2026
+ inputs: [],
2027
+ name: "deposit",
2028
+ outputs: [],
2029
+ payable: true,
2030
+ stateMutability: "payable",
2031
+ type: "function"
2032
+ },
2033
+ {
2034
+ constant: true,
2035
+ inputs: [],
2036
+ name: "name",
2037
+ outputs: [{ internalType: "string", name: "", type: "string" }],
2038
+ payable: false,
2039
+ stateMutability: "view",
2040
+ type: "function"
2041
+ },
2042
+ {
2043
+ constant: true,
2044
+ inputs: [],
2045
+ name: "symbol",
2046
+ outputs: [{ internalType: "string", name: "", type: "string" }],
2047
+ payable: false,
2048
+ stateMutability: "view",
2049
+ type: "function"
2050
+ },
2051
+ {
2052
+ constant: true,
2053
+ inputs: [],
2054
+ name: "totalSupply",
2055
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
2056
+ payable: false,
2057
+ stateMutability: "view",
2058
+ type: "function"
2059
+ },
2060
+ {
2061
+ constant: false,
2062
+ inputs: [
2063
+ { internalType: "address", name: "dst", type: "address" },
2064
+ { internalType: "uint256", name: "wad", type: "uint256" }
2065
+ ],
2066
+ name: "transfer",
2067
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
2068
+ payable: false,
2069
+ stateMutability: "nonpayable",
2070
+ type: "function"
2071
+ },
2072
+ {
2073
+ constant: false,
2074
+ inputs: [
2075
+ { internalType: "address", name: "src", type: "address" },
2076
+ { internalType: "address", name: "dst", type: "address" },
2077
+ { internalType: "uint256", name: "wad", type: "uint256" }
2078
+ ],
2079
+ name: "transferFrom",
2080
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
2081
+ payable: false,
2082
+ stateMutability: "nonpayable",
2083
+ type: "function"
2084
+ },
2085
+ {
2086
+ constant: false,
2087
+ inputs: [{ internalType: "uint256", name: "wad", type: "uint256" }],
2088
+ name: "withdraw",
2089
+ outputs: [],
2090
+ payable: false,
2091
+ stateMutability: "nonpayable",
2092
+ type: "function"
2093
+ }
2094
+ ];
2095
+ var wethAbi_default = WETH_ABI;
1887
2096
 
1888
2097
  // src/acpContractClient.ts
1889
- import {
1890
- createPublicClient,
1891
- decodeEventLog,
1892
- encodeFunctionData,
1893
- erc20Abi,
1894
- fromHex,
1895
- http,
1896
- parseUnits
1897
- } from "viem";
1898
- import { publicActionsL2 } from "viem/op-stack";
1899
2098
  var MemoType = /* @__PURE__ */ ((MemoType2) => {
1900
2099
  MemoType2[MemoType2["MESSAGE"] = 0] = "MESSAGE";
1901
2100
  MemoType2[MemoType2["CONTEXT_URL"] = 1] = "CONTEXT_URL";
@@ -1919,30 +2118,26 @@ var AcpJobPhases = /* @__PURE__ */ ((AcpJobPhases2) => {
1919
2118
  return AcpJobPhases2;
1920
2119
  })(AcpJobPhases || {});
1921
2120
  var AcpContractClient = class _AcpContractClient {
1922
- constructor(walletPrivateKey, sessionEntityKeyId, agentWalletAddress, config = baseAcpConfig, customRpcUrl) {
2121
+ // private paymentTokenAddress: Address;
2122
+ constructor(walletPrivateKey, sessionEntityKeyId, agentWalletAddress, config = baseAcpConfig) {
1923
2123
  this.walletPrivateKey = walletPrivateKey;
1924
2124
  this.sessionEntityKeyId = sessionEntityKeyId;
1925
2125
  this.agentWalletAddress = agentWalletAddress;
1926
2126
  this.config = config;
1927
- this.customRpcUrl = customRpcUrl;
1928
2127
  this.MAX_RETRIES = 3;
2128
+ this.PRIORITY_FEE_MULTIPLIER = 2;
2129
+ this.MAX_FEE_PER_GAS = 2e7;
2130
+ this.MAX_PRIORITY_FEE_PER_GAS = 21e6;
1929
2131
  this.chain = config.chain;
1930
2132
  this.contractAddress = config.contractAddress;
1931
- this.paymentTokenAddress = config.paymentTokenAddress;
1932
- this.customRpcUrl = customRpcUrl;
1933
- this.customRpcClient = createPublicClient({
1934
- chain: this.chain,
1935
- transport: this.customRpcUrl ? http(this.customRpcUrl) : http()
1936
- }).extend(publicActionsL2());
1937
- }
1938
- static build(_0, _1, _2, _3) {
1939
- return __async(this, arguments, function* (walletPrivateKey, sessionEntityKeyId, agentWalletAddress, customRpcUrl, config = baseAcpConfig) {
2133
+ }
2134
+ static build(_0, _1, _2) {
2135
+ return __async(this, arguments, function* (walletPrivateKey, sessionEntityKeyId, agentWalletAddress, config = baseAcpConfig) {
1940
2136
  const acpContractClient = new _AcpContractClient(
1941
2137
  walletPrivateKey,
1942
2138
  sessionEntityKeyId,
1943
2139
  agentWalletAddress,
1944
- config,
1945
- customRpcUrl
2140
+ config
1946
2141
  );
1947
2142
  yield acpContractClient.init();
1948
2143
  return acpContractClient;
@@ -1977,21 +2172,17 @@ var AcpContractClient = class _AcpContractClient {
1977
2172
  }
1978
2173
  calculateGasFees() {
1979
2174
  return __async(this, null, function* () {
1980
- const { maxFeePerGas, maxPriorityFeePerGas } = yield this.customRpcClient.estimateFeesPerGas();
1981
- let finalMaxFeePerGas = maxFeePerGas;
1982
- let priorityFeeMultiplier = Number(this.config.priorityFeeMultiplier) || 2;
1983
- const overrideMaxFeePerGas = this.config.maxFeePerGas || maxFeePerGas;
1984
- const overrideMaxPriorityFeePerGas = this.config.maxPriorityFeePerGas || maxPriorityFeePerGas;
1985
- finalMaxFeePerGas = BigInt(overrideMaxFeePerGas) + BigInt(overrideMaxPriorityFeePerGas) * BigInt(Math.max(0, priorityFeeMultiplier - 1));
2175
+ const finalMaxFeePerGas = BigInt(this.MAX_FEE_PER_GAS) + BigInt(this.MAX_PRIORITY_FEE_PER_GAS) * BigInt(Math.max(0, this.PRIORITY_FEE_MULTIPLIER - 1));
1986
2176
  return finalMaxFeePerGas;
1987
2177
  });
1988
2178
  }
1989
2179
  handleSendUserOperation(_0) {
1990
- return __async(this, arguments, function* (data, contractAddress = this.contractAddress) {
2180
+ return __async(this, arguments, function* (data, contractAddress = this.contractAddress, value) {
1991
2181
  const payload = {
1992
2182
  uo: {
1993
2183
  target: contractAddress,
1994
- data
2184
+ data,
2185
+ value
1995
2186
  },
1996
2187
  overrides: {}
1997
2188
  };
@@ -2038,9 +2229,6 @@ var AcpContractClient = class _AcpContractClient {
2038
2229
  return fromHex(contractLogs.data, "number");
2039
2230
  });
2040
2231
  }
2041
- formatAmount(amount) {
2042
- return parseUnits(amount.toString(), this.config.paymentTokenDecimals);
2043
- }
2044
2232
  createJob(providerAddress, evaluatorAddress, expireAt) {
2045
2233
  return __async(this, null, function* () {
2046
2234
  try {
@@ -2063,12 +2251,12 @@ var AcpContractClient = class _AcpContractClient {
2063
2251
  });
2064
2252
  }
2065
2253
  approveAllowance(_0) {
2066
- return __async(this, arguments, function* (amount, paymentTokenAddress = this.paymentTokenAddress) {
2254
+ return __async(this, arguments, function* (amountBaseUnit, paymentTokenAddress = this.config.baseFare.contractAddress) {
2067
2255
  try {
2068
2256
  const data = encodeFunctionData({
2069
2257
  abi: erc20Abi,
2070
2258
  functionName: "approve",
2071
- args: [this.contractAddress, this.formatAmount(amount)]
2259
+ args: [this.contractAddress, amountBaseUnit]
2072
2260
  });
2073
2261
  return yield this.handleSendUserOperation(data, paymentTokenAddress);
2074
2262
  } catch (error) {
@@ -2078,7 +2266,7 @@ var AcpContractClient = class _AcpContractClient {
2078
2266
  });
2079
2267
  }
2080
2268
  createPayableMemo(_0, _1, _2, _3, _4, _5, _6, _7, _8) {
2081
- return __async(this, arguments, function* (jobId, content, amount, recipient, feeAmount, feeType, nextPhase, type, expiredAt, token = this.paymentTokenAddress) {
2269
+ return __async(this, arguments, function* (jobId, content, amountBaseUnit, recipient, feeAmountBaseUnit, feeType, nextPhase, type, expiredAt, token = this.config.baseFare.contractAddress) {
2082
2270
  let retries = 3;
2083
2271
  while (retries > 0) {
2084
2272
  try {
@@ -2089,9 +2277,9 @@ var AcpContractClient = class _AcpContractClient {
2089
2277
  jobId,
2090
2278
  content,
2091
2279
  token,
2092
- this.formatAmount(amount),
2280
+ amountBaseUnit,
2093
2281
  recipient,
2094
- this.formatAmount(feeAmount),
2282
+ feeAmountBaseUnit,
2095
2283
  feeType,
2096
2284
  type,
2097
2285
  nextPhase,
@@ -2172,13 +2360,13 @@ var AcpContractClient = class _AcpContractClient {
2172
2360
  }
2173
2361
  });
2174
2362
  }
2175
- setBudget(jobId, budget) {
2363
+ setBudget(jobId, budgetBaseUnit) {
2176
2364
  return __async(this, null, function* () {
2177
2365
  try {
2178
2366
  const data = encodeFunctionData({
2179
2367
  abi: acpAbi_default,
2180
2368
  functionName: "setBudget",
2181
- args: [jobId, this.formatAmount(budget)]
2369
+ args: [jobId, budgetBaseUnit]
2182
2370
  });
2183
2371
  return yield this.handleSendUserOperation(data);
2184
2372
  } catch (error) {
@@ -2188,12 +2376,12 @@ var AcpContractClient = class _AcpContractClient {
2188
2376
  });
2189
2377
  }
2190
2378
  setBudgetWithPaymentToken(_0, _1) {
2191
- return __async(this, arguments, function* (jobId, budget, paymentTokenAddress = this.paymentTokenAddress) {
2379
+ return __async(this, arguments, function* (jobId, budgetBaseUnit, paymentTokenAddress = this.config.baseFare.contractAddress) {
2192
2380
  try {
2193
2381
  const data = encodeFunctionData({
2194
2382
  abi: acpAbi_default,
2195
2383
  functionName: "setBudgetWithPaymentToken",
2196
- args: [jobId, this.formatAmount(budget), paymentTokenAddress]
2384
+ args: [jobId, budgetBaseUnit, paymentTokenAddress]
2197
2385
  });
2198
2386
  return yield this.handleSendUserOperation(data);
2199
2387
  } catch (error) {
@@ -2202,6 +2390,24 @@ var AcpContractClient = class _AcpContractClient {
2202
2390
  }
2203
2391
  });
2204
2392
  }
2393
+ wrapEth(amountBaseUnit) {
2394
+ return __async(this, null, function* () {
2395
+ try {
2396
+ const data = encodeFunctionData({
2397
+ abi: wethAbi_default,
2398
+ functionName: "deposit"
2399
+ });
2400
+ return yield this.handleSendUserOperation(
2401
+ data,
2402
+ wethFare.contractAddress,
2403
+ amountBaseUnit
2404
+ );
2405
+ } catch (error) {
2406
+ console.error(`Failed to wrap eth ${error}`);
2407
+ throw new Error("Failed to wrap eth");
2408
+ }
2409
+ });
2410
+ }
2205
2411
  };
2206
2412
  var acpContractClient_default = AcpContractClient;
2207
2413
 
@@ -2234,6 +2440,8 @@ var AcpOnlineStatus = /* @__PURE__ */ ((AcpOnlineStatus2) => {
2234
2440
  var PayloadType = /* @__PURE__ */ ((PayloadType2) => {
2235
2441
  PayloadType2["FUND_RESPONSE"] = "fund_response";
2236
2442
  PayloadType2["OPEN_POSITION"] = "open_position";
2443
+ PayloadType2["SWAP_TOKEN"] = "swap_token";
2444
+ PayloadType2["RESPONSE_SWAP_TOKEN"] = "response_swap_token";
2237
2445
  PayloadType2["CLOSE_PARTIAL_POSITION"] = "close_partial_position";
2238
2446
  PayloadType2["CLOSE_POSITION"] = "close_position";
2239
2447
  PayloadType2["POSITION_FULFILLED"] = "position_fulfilled";
@@ -2241,6 +2449,11 @@ var PayloadType = /* @__PURE__ */ ((PayloadType2) => {
2241
2449
  PayloadType2["UNFULFILLED_POSITION"] = "unfulfilled_position";
2242
2450
  return PayloadType2;
2243
2451
  })(PayloadType || {});
2452
+ var PositionDirection = /* @__PURE__ */ ((PositionDirection2) => {
2453
+ PositionDirection2["LONG"] = "long";
2454
+ PositionDirection2["SHORT"] = "short";
2455
+ return PositionDirection2;
2456
+ })(PositionDirection || {});
2244
2457
 
2245
2458
  // src/utils.ts
2246
2459
  function tryParseJson(content) {
@@ -2264,6 +2477,7 @@ var AcpJob = class {
2264
2477
  this.memos = memos;
2265
2478
  this.phase = phase;
2266
2479
  this.context = context;
2480
+ this.baseFare = acpClient.acpContractClient.config.baseFare;
2267
2481
  }
2268
2482
  get serviceRequirement() {
2269
2483
  var _a;
@@ -2317,7 +2531,12 @@ var AcpJob = class {
2317
2531
  if (!memo) {
2318
2532
  throw new Error("No transaction memo found");
2319
2533
  }
2320
- return yield this.acpClient.payJob(this.id, amount, memo.id, reason);
2534
+ return yield this.acpClient.payJob(
2535
+ this.id,
2536
+ this.baseFare.formatAmount(amount),
2537
+ memo.id,
2538
+ reason
2539
+ );
2321
2540
  });
2322
2541
  }
2323
2542
  respond(accept, payload, reason) {
@@ -2362,11 +2581,12 @@ var AcpJob = class {
2362
2581
  if (payload.length === 0) {
2363
2582
  throw new Error("No positions to open");
2364
2583
  }
2584
+ const sumAmount = payload.reduce((acc, curr) => acc + curr.amount, 0);
2365
2585
  return yield this.acpClient.transferFunds(
2366
2586
  this.id,
2367
- payload.reduce((acc, curr) => acc + curr.amount, 0),
2587
+ new FareAmount(sumAmount, this.baseFare),
2368
2588
  walletAddress || this.providerAddress,
2369
- feeAmount,
2589
+ new FareAmount(feeAmount, this.baseFare),
2370
2590
  1 /* IMMEDIATE_FEE */,
2371
2591
  {
2372
2592
  type: "open_position" /* OPEN_POSITION */,
@@ -2377,6 +2597,55 @@ var AcpJob = class {
2377
2597
  );
2378
2598
  });
2379
2599
  }
2600
+ swapToken(payload, decimals, feeAmount, walletAddress) {
2601
+ return __async(this, null, function* () {
2602
+ return yield this.acpClient.transferFunds(
2603
+ this.id,
2604
+ new FareAmount(
2605
+ payload.amount,
2606
+ new Fare(payload.fromContractAddress, decimals)
2607
+ ),
2608
+ walletAddress || this.providerAddress,
2609
+ new FareAmount(feeAmount, this.baseFare),
2610
+ 1 /* IMMEDIATE_FEE */,
2611
+ {
2612
+ type: "swap_token" /* SWAP_TOKEN */,
2613
+ data: payload
2614
+ },
2615
+ 2 /* TRANSACTION */,
2616
+ new Date(Date.now() + 1e3 * 60 * 30)
2617
+ );
2618
+ });
2619
+ }
2620
+ responseSwapToken(memoId, accept, reason) {
2621
+ return __async(this, null, function* () {
2622
+ const memo = this.memos.find((m) => m.id === memoId);
2623
+ if ((memo == null ? void 0 : memo.nextPhase) !== 2 /* TRANSACTION */ || (memo == null ? void 0 : memo.type) !== 8 /* PAYABLE_TRANSFER_ESCROW */) {
2624
+ throw new Error("No swap token memo found");
2625
+ }
2626
+ const payload = tryParseJson(
2627
+ memo.content
2628
+ );
2629
+ if ((payload == null ? void 0 : payload.type) !== "swap_token" /* SWAP_TOKEN */) {
2630
+ throw new Error("Invalid swap token memo");
2631
+ }
2632
+ return yield memo.sign(accept, reason);
2633
+ });
2634
+ }
2635
+ transferFunds(_0, _1, _2) {
2636
+ return __async(this, arguments, function* (payload, fareAmount, walletAddress, expiredAt = new Date(Date.now() + 1e3 * 60 * 30)) {
2637
+ return yield this.acpClient.transferFunds(
2638
+ this.id,
2639
+ fareAmount,
2640
+ walletAddress || this.clientAddress,
2641
+ new FareAmount(0, this.baseFare),
2642
+ 0 /* NO_FEE */,
2643
+ payload,
2644
+ 2 /* TRANSACTION */,
2645
+ expiredAt
2646
+ );
2647
+ });
2648
+ }
2380
2649
  responseOpenPosition(memoId, accept, reason) {
2381
2650
  return __async(this, null, function* () {
2382
2651
  const memo = this.memos.find((m) => m.id === memoId);
@@ -2396,9 +2665,9 @@ var AcpJob = class {
2396
2665
  return __async(this, arguments, function* (payload, expireAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
2397
2666
  return yield this.acpClient.requestFunds(
2398
2667
  this.id,
2399
- payload.amount,
2668
+ new FareAmount(payload.amount, this.baseFare),
2400
2669
  this.clientAddress,
2401
- 0,
2670
+ new FareAmount(0, this.baseFare),
2402
2671
  0 /* NO_FEE */,
2403
2672
  {
2404
2673
  type: "close_partial_position" /* CLOSE_PARTIAL_POSITION */,
@@ -2424,7 +2693,7 @@ var AcpJob = class {
2424
2693
  return yield this.acpClient.responseFundsRequest(
2425
2694
  memo.id,
2426
2695
  accept,
2427
- payload.data.amount,
2696
+ this.baseFare.formatAmount(payload.data.amount),
2428
2697
  reason
2429
2698
  );
2430
2699
  });
@@ -2455,9 +2724,9 @@ var AcpJob = class {
2455
2724
  if (accept) {
2456
2725
  return yield this.acpClient.transferFunds(
2457
2726
  this.id,
2458
- payload.amount,
2727
+ new FareAmount(payload.amount, this.baseFare),
2459
2728
  this.clientAddress,
2460
- 0,
2729
+ new FareAmount(0, this.baseFare),
2461
2730
  0 /* NO_FEE */,
2462
2731
  {
2463
2732
  type: "close_position" /* CLOSE_POSITION */,
@@ -2488,9 +2757,9 @@ var AcpJob = class {
2488
2757
  return __async(this, arguments, function* (payload, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
2489
2758
  return yield this.acpClient.transferFunds(
2490
2759
  this.id,
2491
- payload.amount,
2760
+ new FareAmount(payload.amount, this.baseFare),
2492
2761
  this.clientAddress,
2493
- 0,
2762
+ new FareAmount(0, this.baseFare),
2494
2763
  0 /* NO_FEE */,
2495
2764
  {
2496
2765
  type: "position_fulfilled" /* POSITION_FULFILLED */,
@@ -2505,9 +2774,9 @@ var AcpJob = class {
2505
2774
  return __async(this, arguments, function* (payload, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
2506
2775
  return yield this.acpClient.transferFunds(
2507
2776
  this.id,
2508
- payload.amount,
2777
+ new FareAmount(payload.amount, this.baseFare),
2509
2778
  this.clientAddress,
2510
- 0,
2779
+ new FareAmount(0, this.baseFare),
2511
2780
  0 /* NO_FEE */,
2512
2781
  {
2513
2782
  type: "unfulfilled_position" /* UNFULFILLED_POSITION */,
@@ -2594,9 +2863,9 @@ var AcpJob = class {
2594
2863
  }
2595
2864
  return yield this.acpClient.transferFunds(
2596
2865
  this.id,
2597
- fulfilledPositions.reduce((acc, curr) => acc + curr.amount, 0),
2866
+ new FareAmount(totalAmount, this.baseFare),
2598
2867
  this.clientAddress,
2599
- 0,
2868
+ new FareAmount(0, this.baseFare),
2600
2869
  0 /* NO_FEE */,
2601
2870
  {
2602
2871
  type: "close_job_and_withdraw" /* CLOSE_JOB_AND_WITHDRAW */,
@@ -2637,6 +2906,10 @@ var AcpMemo = class {
2637
2906
  this.signedReason = signedReason;
2638
2907
  this.expiry = expiry;
2639
2908
  this.payableDetails = payableDetails;
2909
+ if (this.payableDetails) {
2910
+ this.payableDetails.amount = BigInt(this.payableDetails.amount);
2911
+ this.payableDetails.feeAmount = BigInt(this.payableDetails.feeAmount);
2912
+ }
2640
2913
  this.structuredContent = tryParseJson(this.content) || void 0;
2641
2914
  }
2642
2915
  get payloadType() {
@@ -2704,7 +2977,10 @@ var AcpJobOffering = class {
2704
2977
  return yield this.acpClient.initiateJob(
2705
2978
  this.providerAddress,
2706
2979
  finalServiceRequirement,
2707
- this.price,
2980
+ new FareAmount(
2981
+ this.price,
2982
+ this.acpClient.acpContractClient.config.baseFare
2983
+ ),
2708
2984
  evaluatorAddress,
2709
2985
  expiredAt
2710
2986
  );
@@ -2872,13 +3148,22 @@ var AcpClient = class {
2872
3148
  });
2873
3149
  }
2874
3150
  initiateJob(_0, _1, _2, _3) {
2875
- return __async(this, arguments, function* (providerAddress, serviceRequirement, amount, evaluatorAddress, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
3151
+ return __async(this, arguments, function* (providerAddress, serviceRequirement, fareAmount, evaluatorAddress, expiredAt = new Date(Date.now() + 1e3 * 60 * 60 * 24)) {
3152
+ if (providerAddress === this.acpContractClient.walletAddress) {
3153
+ throw new Error(
3154
+ "Provider address cannot be the same as the client address"
3155
+ );
3156
+ }
2876
3157
  const { jobId } = yield this.acpContractClient.createJob(
2877
3158
  providerAddress,
2878
3159
  evaluatorAddress || this.acpContractClient.walletAddress,
2879
3160
  expiredAt
2880
3161
  );
2881
- yield this.acpContractClient.setBudgetWithPaymentToken(jobId, amount);
3162
+ yield this.acpContractClient.setBudgetWithPaymentToken(
3163
+ jobId,
3164
+ fareAmount.amount,
3165
+ fareAmount.fare.contractAddress
3166
+ );
2882
3167
  yield this.acpContractClient.createMemo(
2883
3168
  jobId,
2884
3169
  typeof serviceRequirement === "string" ? serviceRequirement : JSON.stringify(serviceRequirement),
@@ -2904,29 +3189,29 @@ var AcpClient = class {
2904
3189
  );
2905
3190
  });
2906
3191
  }
2907
- payJob(jobId, amount, memoId, reason) {
3192
+ payJob(jobId, amountBaseUnit, memoId, reason) {
2908
3193
  return __async(this, null, function* () {
2909
- if (amount > 0) {
2910
- yield this.acpContractClient.approveAllowance(amount);
3194
+ if (amountBaseUnit > BigInt(0)) {
3195
+ yield this.acpContractClient.approveAllowance(amountBaseUnit);
2911
3196
  }
2912
3197
  yield this.acpContractClient.signMemo(memoId, true, reason);
2913
3198
  return yield this.acpContractClient.createMemo(
2914
3199
  jobId,
2915
- `Payment of ${amount} made. ${reason != null ? reason : ""}`,
3200
+ `Payment made. ${reason != null ? reason : ""}`,
2916
3201
  0 /* MESSAGE */,
2917
3202
  false,
2918
3203
  3 /* EVALUATION */
2919
3204
  );
2920
3205
  });
2921
3206
  }
2922
- requestFunds(jobId, amount, recipient, feeAmount, feeType, reason, nextPhase, expiredAt) {
3207
+ requestFunds(jobId, transferFareAmount, recipient, feeFareAmount, feeType, reason, nextPhase, expiredAt) {
2923
3208
  return __async(this, null, function* () {
2924
3209
  return yield this.acpContractClient.createPayableMemo(
2925
3210
  jobId,
2926
3211
  JSON.stringify(reason),
2927
- amount,
3212
+ transferFareAmount.amount,
2928
3213
  recipient,
2929
- feeAmount,
3214
+ feeFareAmount.amount,
2930
3215
  feeType,
2931
3216
  nextPhase,
2932
3217
  6 /* PAYABLE_REQUEST */,
@@ -2934,33 +3219,49 @@ var AcpClient = class {
2934
3219
  );
2935
3220
  });
2936
3221
  }
2937
- responseFundsRequest(memoId, accept, amount, reason) {
3222
+ responseFundsRequest(memoId, accept, amountBaseUnit, reason) {
2938
3223
  return __async(this, null, function* () {
2939
3224
  if (!accept) {
2940
3225
  return yield this.acpContractClient.signMemo(memoId, accept, reason);
2941
3226
  }
2942
- if (amount > 0) {
2943
- yield this.acpContractClient.approveAllowance(amount);
3227
+ if (amountBaseUnit > BigInt(0)) {
3228
+ yield this.acpContractClient.approveAllowance(amountBaseUnit);
2944
3229
  }
2945
3230
  return yield this.acpContractClient.signMemo(memoId, true, reason);
2946
3231
  });
2947
3232
  }
2948
- transferFunds(jobId, amount, recipient, feeAmount, feeType, reason, nextPhase, expiredAt) {
3233
+ transferFunds(jobId, transferFareAmount, recipient, feeFareAmount, feeType, reason, nextPhase, expiredAt) {
2949
3234
  return __async(this, null, function* () {
2950
- const totalAmount = amount + feeAmount;
2951
- if (totalAmount > 0) {
2952
- yield this.acpContractClient.approveAllowance(totalAmount);
3235
+ if (transferFareAmount.fare.contractAddress === ethFare.contractAddress) {
3236
+ yield this.acpContractClient.wrapEth(transferFareAmount.amount);
3237
+ transferFareAmount = new FareBigInt(transferFareAmount.amount, wethFare);
3238
+ }
3239
+ if (feeFareAmount.amount > 0 && feeFareAmount.fare.contractAddress !== this.acpContractClient.config.baseFare.contractAddress) {
3240
+ throw new Error("Fee token address is not the same as the base fare");
3241
+ }
3242
+ const isFeeTokenDifferent = feeFareAmount.fare.contractAddress !== transferFareAmount.fare.contractAddress;
3243
+ if (isFeeTokenDifferent) {
3244
+ yield this.acpContractClient.approveAllowance(
3245
+ feeFareAmount.amount,
3246
+ feeFareAmount.fare.contractAddress
3247
+ );
2953
3248
  }
3249
+ const finalAmount = isFeeTokenDifferent ? transferFareAmount : transferFareAmount.add(feeFareAmount);
3250
+ yield this.acpContractClient.approveAllowance(
3251
+ finalAmount.amount,
3252
+ transferFareAmount.fare.contractAddress
3253
+ );
2954
3254
  return yield this.acpContractClient.createPayableMemo(
2955
3255
  jobId,
2956
3256
  JSON.stringify(reason),
2957
- amount,
3257
+ transferFareAmount.amount,
2958
3258
  recipient,
2959
- feeAmount,
3259
+ feeFareAmount.amount,
2960
3260
  feeType,
2961
3261
  nextPhase,
2962
3262
  8 /* PAYABLE_TRANSFER_ESCROW */,
2963
- expiredAt
3263
+ expiredAt,
3264
+ transferFareAmount.fare.contractAddress
2964
3265
  );
2965
3266
  });
2966
3267
  }
@@ -3223,15 +3524,22 @@ export {
3223
3524
  acpAbi_default as ACP_ABI,
3224
3525
  AcpAgentSort,
3225
3526
  acpContractClient_default as AcpContractClient,
3527
+ AcpContractConfig,
3226
3528
  AcpGraduationStatus,
3227
3529
  acpJob_default as AcpJob,
3228
3530
  AcpJobPhases,
3229
3531
  acpMemo_default as AcpMemo,
3230
3532
  AcpMemoStatus,
3231
3533
  AcpOnlineStatus,
3534
+ Fare,
3535
+ FareAmount,
3536
+ FareBigInt,
3232
3537
  MemoType,
3233
3538
  PayloadType,
3539
+ PositionDirection,
3234
3540
  baseAcpConfig,
3235
3541
  baseSepoliaAcpConfig,
3236
- index_default as default
3542
+ index_default as default,
3543
+ ethFare,
3544
+ wethFare
3237
3545
  };