@allbridge/bridge-core-sdk 0.3.0 → 0.4.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.
@@ -50378,29 +50378,15 @@ P.valueOf = function() {
50378
50378
  var Big = _Big_();
50379
50379
 
50380
50380
  // src/chains/index.ts
50381
- var ChainSymbol = /* @__PURE__ */ ((ChainSymbol2) => {
50382
- ChainSymbol2["KVN"] = "KVN";
50383
- ChainSymbol2["RPS"] = "RPS";
50384
- ChainSymbol2["GRL"] = "GRL";
50385
- ChainSymbol2["BSC"] = "BSC";
50386
- ChainSymbol2["ETH"] = "ETH";
50387
- ChainSymbol2["SOL"] = "SOL";
50388
- ChainSymbol2["TRX"] = "TRX";
50389
- return ChainSymbol2;
50381
+ var ChainSymbol = /* @__PURE__ */ ((ChainSymbol3) => {
50382
+ ChainSymbol3["GRL"] = "GRL";
50383
+ ChainSymbol3["BSC"] = "BSC";
50384
+ ChainSymbol3["ETH"] = "ETH";
50385
+ ChainSymbol3["SOL"] = "SOL";
50386
+ ChainSymbol3["TRX"] = "TRX";
50387
+ return ChainSymbol3;
50390
50388
  })(ChainSymbol || {});
50391
50389
  var chainProperties = {
50392
- ["KVN" /* KVN */]: {
50393
- chainSymbol: "KVN" /* KVN */,
50394
- chainId: "0x2a",
50395
- name: "Kovan",
50396
- chainType: "EVM" /* EVM */
50397
- },
50398
- ["RPS" /* RPS */]: {
50399
- chainSymbol: "RPS" /* RPS */,
50400
- chainId: "0x3",
50401
- name: "Ropsten",
50402
- chainType: "EVM" /* EVM */
50403
- },
50404
50390
  ["GRL" /* GRL */]: {
50405
50391
  chainSymbol: "GRL" /* GRL */,
50406
50392
  chainId: "0x5",
@@ -50663,6 +50649,94 @@ var abi_default = [
50663
50649
  // src/bridge/evm/index.ts
50664
50650
  var import_randombytes = __toESM(require_browser());
50665
50651
 
50652
+ // src/utils/calculation/constants.ts
50653
+ var SYSTEM_PRECISION = 3;
50654
+
50655
+ // src/utils/calculation/index.ts
50656
+ function getFeePercent(input, output) {
50657
+ return Big(100).minus(Big(100).times(output).div(input)).toNumber();
50658
+ }
50659
+ function toSystemPrecision(amount, decimals) {
50660
+ return convertAmountPrecision(amount, decimals, SYSTEM_PRECISION);
50661
+ }
50662
+ function fromSystemPrecision(amount, decimals) {
50663
+ return convertAmountPrecision(amount, SYSTEM_PRECISION, decimals);
50664
+ }
50665
+ function swapToVUsd(amount, tokenInfo) {
50666
+ const fee = Big(amount).times(tokenInfo.feeShare);
50667
+ const amountWithoutFee = Big(amount).minus(fee);
50668
+ const inSystemPrecision = toSystemPrecision(
50669
+ amountWithoutFee,
50670
+ tokenInfo.decimals
50671
+ );
50672
+ const poolInfo = tokenInfo.poolInfo;
50673
+ const tokenBalance = Big(poolInfo.tokenBalance).plus(inSystemPrecision);
50674
+ const vUsdNewAmount = getY(tokenBalance, poolInfo.aValue, poolInfo.dValue);
50675
+ return Big(poolInfo.vUsdBalance).minus(vUsdNewAmount).round(0, 0);
50676
+ }
50677
+ function swapFromVUsd(amount, tokenInfo) {
50678
+ const poolInfo = tokenInfo.poolInfo;
50679
+ const vUsdBalance = Big(amount).plus(poolInfo.vUsdBalance);
50680
+ const newAmount = getY(vUsdBalance, poolInfo.aValue, poolInfo.dValue);
50681
+ const result = fromSystemPrecision(
50682
+ Big(poolInfo.tokenBalance).minus(newAmount),
50683
+ tokenInfo.decimals
50684
+ );
50685
+ const fee = Big(result).times(tokenInfo.feeShare);
50686
+ return Big(result).minus(fee).round(0, 0);
50687
+ }
50688
+ function swapToVUsdReverse(amount, tokenInfo) {
50689
+ const poolInfo = tokenInfo.poolInfo;
50690
+ const vUsdNewAmount = Big(poolInfo.vUsdBalance).minus(amount);
50691
+ const tokenBalance = getY(vUsdNewAmount, poolInfo.aValue, poolInfo.dValue);
50692
+ const inSystemPrecision = Big(tokenBalance).minus(poolInfo.tokenBalance);
50693
+ const amountWithoutFee = fromSystemPrecision(
50694
+ inSystemPrecision,
50695
+ tokenInfo.decimals
50696
+ );
50697
+ const reversedFeeShare = Big(tokenInfo.feeShare).div(
50698
+ Big(1).minus(tokenInfo.feeShare)
50699
+ );
50700
+ const fee = Big(amountWithoutFee).times(reversedFeeShare);
50701
+ return Big(amountWithoutFee).plus(fee).round(0, 0);
50702
+ }
50703
+ function swapFromVUsdReverse(amount, tokenInfo) {
50704
+ const reversedFeeShare = Big(tokenInfo.feeShare).div(
50705
+ Big(1).minus(tokenInfo.feeShare)
50706
+ );
50707
+ const fee = Big(amount).times(reversedFeeShare);
50708
+ const amountWithFee = Big(amount).plus(fee);
50709
+ const inSystemPrecision = toSystemPrecision(
50710
+ amountWithFee,
50711
+ tokenInfo.decimals
50712
+ );
50713
+ const poolInfo = tokenInfo.poolInfo;
50714
+ const tokenBalance = Big(poolInfo.tokenBalance).minus(inSystemPrecision);
50715
+ const vUsdNewAmount = getY(tokenBalance, poolInfo.aValue, poolInfo.dValue);
50716
+ return Big(vUsdNewAmount).minus(poolInfo.vUsdBalance).round(0, 0);
50717
+ }
50718
+ function convertAmountPrecision(amount, decimalsFrom, decimalsTo) {
50719
+ const dif = Big(decimalsTo).minus(decimalsFrom).toNumber();
50720
+ return Big(amount).times(toPowBase10(dif)).round(0, 0);
50721
+ }
50722
+ function toPowBase10(decimals) {
50723
+ return Big(10).pow(decimals);
50724
+ }
50725
+ function convertFloatAmountToInt(amountFloat, decimals) {
50726
+ return Big(amountFloat).times(toPowBase10(decimals));
50727
+ }
50728
+ function convertIntAmountToFloat(amountInt, decimals) {
50729
+ return Big(amountInt).div(toPowBase10(decimals));
50730
+ }
50731
+ function getY(x, a, d) {
50732
+ const commonPartBig = Big(4).times(a).times(Big(d).minus(x)).minus(d);
50733
+ const dCubed = Big(d).pow(3);
50734
+ const commonPartSquared = commonPartBig.pow(2);
50735
+ const sqrtBig = Big(x).times(Big(x).times(commonPartSquared).plus(Big(4).times(a).times(dCubed))).sqrt();
50736
+ const dividerBig = Big(8).times(a).times(x);
50737
+ return commonPartBig.times(x).plus(sqrtBig).div(dividerBig);
50738
+ }
50739
+
50666
50740
  // src/bridge/models/bridge.model.ts
50667
50741
  var Bridge = class {
50668
50742
  };
@@ -51449,50 +51523,64 @@ var EvmBridge = class extends ApprovalBridge {
51449
51523
  return this.getContract(abi_default, data.tokenAddress).methods.balanceOf(data.account).call();
51450
51524
  }
51451
51525
  async send(params) {
51452
- let contractAddress;
51526
+ const txSendParams = {};
51453
51527
  let fromChainId;
51454
- let fromTokenAddress;
51455
51528
  let toChainType;
51456
- let toChainId;
51457
- let toTokenAddress;
51458
51529
  if (BridgeService.isSendParamsWithChainSymbol(params)) {
51459
- const tokensInfo = await this.api.getTokensInfo();
51460
- const chainDetailsMap = tokensInfo.chainDetailsMap();
51461
- contractAddress = chainDetailsMap[params.fromChainSymbol].bridgeAddress;
51530
+ const chainDetailsMap = (await this.api.getTokensInfo()).chainDetailsMap();
51462
51531
  fromChainId = chainDetailsMap[params.fromChainSymbol].allbridgeChainId;
51463
- fromTokenAddress = params.fromTokenAddress;
51464
51532
  toChainType = chainProperties[params.toChainSymbol].chainType;
51465
- toChainId = chainDetailsMap[params.toChainSymbol].allbridgeChainId;
51466
- toTokenAddress = params.toTokenAddress;
51533
+ txSendParams.contractAddress = chainDetailsMap[params.fromChainSymbol].bridgeAddress;
51534
+ txSendParams.fromTokenAddress = params.fromTokenAddress;
51535
+ txSendParams.toChainId = chainDetailsMap[params.toChainSymbol].allbridgeChainId;
51536
+ txSendParams.toTokenAddress = params.toTokenAddress;
51537
+ txSendParams.amount = convertFloatAmountToInt(
51538
+ params.amount,
51539
+ this.getDecimalsByContractAddress(
51540
+ chainDetailsMap,
51541
+ params.fromChainSymbol,
51542
+ txSendParams.fromTokenAddress
51543
+ )
51544
+ ).toFixed();
51467
51545
  } else {
51468
- contractAddress = params.sourceChainToken.bridgeAddress;
51469
51546
  fromChainId = params.sourceChainToken.allbridgeChainId;
51470
- fromTokenAddress = params.sourceChainToken.tokenAddress;
51471
51547
  toChainType = chainProperties[params.destinationChainToken.chainSymbol].chainType;
51472
- toChainId = params.destinationChainToken.allbridgeChainId;
51473
- toTokenAddress = params.destinationChainToken.tokenAddress;
51474
- }
51475
- const { amount, fromAccountAddress, toAccountAddress, messenger } = params;
51548
+ txSendParams.contractAddress = params.sourceChainToken.bridgeAddress;
51549
+ txSendParams.fromTokenAddress = params.sourceChainToken.tokenAddress;
51550
+ txSendParams.toChainId = params.destinationChainToken.allbridgeChainId;
51551
+ txSendParams.toTokenAddress = params.destinationChainToken.tokenAddress;
51552
+ txSendParams.amount = convertFloatAmountToInt(
51553
+ params.amount,
51554
+ params.sourceChainToken.decimals
51555
+ ).toFixed();
51556
+ }
51557
+ txSendParams.messenger = params.messenger;
51558
+ txSendParams.fromAccountAddress = params.fromAccountAddress;
51476
51559
  let { fee } = params;
51477
51560
  if (fee == null) {
51478
51561
  fee = await this.api.getReceiveTransactionCost({
51479
51562
  sourceChainId: fromChainId,
51480
- destinationChainId: toChainId,
51481
- messenger
51563
+ destinationChainId: txSendParams.toChainId,
51564
+ messenger: txSendParams.messenger
51482
51565
  });
51483
51566
  }
51484
- return this.sendTx({
51485
- amount,
51486
- contractAddress,
51487
- fromAccountAddress,
51488
- fromTokenAddress,
51567
+ txSendParams.fee = fee;
51568
+ txSendParams.fromTokenAddress = formatAddress(
51569
+ txSendParams.fromTokenAddress,
51570
+ "EVM" /* EVM */,
51571
+ "EVM" /* EVM */
51572
+ );
51573
+ txSendParams.toAccountAddress = formatAddress(
51574
+ params.toAccountAddress,
51489
51575
  toChainType,
51490
- toChainId,
51491
- toAccountAddress,
51492
- toTokenAddress,
51493
- messenger,
51494
- fee
51495
- });
51576
+ "EVM" /* EVM */
51577
+ );
51578
+ txSendParams.toTokenAddress = formatAddress(
51579
+ txSendParams.toTokenAddress,
51580
+ toChainType,
51581
+ "EVM" /* EVM */
51582
+ );
51583
+ return this.sendTx(txSendParams);
51496
51584
  }
51497
51585
  async sendTx(params) {
51498
51586
  const {
@@ -51500,36 +51588,20 @@ var EvmBridge = class extends ApprovalBridge {
51500
51588
  contractAddress,
51501
51589
  fromAccountAddress,
51502
51590
  fromTokenAddress,
51503
- toChainType,
51504
51591
  toChainId,
51505
51592
  toAccountAddress,
51506
51593
  toTokenAddress,
51507
51594
  messenger,
51508
51595
  fee
51509
51596
  } = params;
51510
- const formattedFromTokenAddress = formatAddress(
51511
- fromTokenAddress,
51512
- "EVM" /* EVM */,
51513
- "EVM" /* EVM */
51514
- );
51515
- const formattedToAccountAddress = formatAddress(
51516
- toAccountAddress,
51517
- toChainType,
51518
- "EVM" /* EVM */
51519
- );
51520
- const formattedToTokenAddress = formatAddress(
51521
- toTokenAddress,
51522
- toChainType,
51523
- "EVM" /* EVM */
51524
- );
51525
51597
  const bridgeContract = this.getBridgeContract(contractAddress);
51526
51598
  const nonce = new import_bn.default(EvmBridge.getNonce());
51527
51599
  const swapAndBridgeMethod = bridgeContract.methods.swapAndBridge(
51528
- formattedFromTokenAddress,
51600
+ fromTokenAddress,
51529
51601
  amount,
51530
- formattedToAccountAddress,
51602
+ toAccountAddress,
51531
51603
  toChainId,
51532
- formattedToTokenAddress,
51604
+ toTokenAddress,
51533
51605
  nonce,
51534
51606
  messenger
51535
51607
  );
@@ -51572,6 +51644,15 @@ var EvmBridge = class extends ApprovalBridge {
51572
51644
  static getNonce() {
51573
51645
  return (0, import_randombytes.default)(32);
51574
51646
  }
51647
+ getDecimalsByContractAddress(chainDetailsMap, chainSymbol, contractAddress) {
51648
+ const sourceTokenInfoWithChainDetails = chainDetailsMap[chainSymbol].tokens.find(
51649
+ (value) => value.tokenAddress.toUpperCase() === contractAddress.toUpperCase()
51650
+ );
51651
+ if (!sourceTokenInfoWithChainDetails) {
51652
+ throw new Error("Cannot find source token info");
51653
+ }
51654
+ return sourceTokenInfoWithChainDetails.decimals;
51655
+ }
51575
51656
  };
51576
51657
 
51577
51658
  // src/bridge/index.ts
@@ -51615,14 +51696,14 @@ var BridgeService = class {
51615
51696
  }
51616
51697
  };
51617
51698
 
51618
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/helpers/bind.js
51699
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/helpers/bind.js
51619
51700
  function bind(fn, thisArg) {
51620
51701
  return function wrap() {
51621
51702
  return fn.apply(thisArg, arguments);
51622
51703
  };
51623
51704
  }
51624
51705
 
51625
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/utils.js
51706
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/utils.js
51626
51707
  var { toString: toString2 } = Object.prototype;
51627
51708
  var { getPrototypeOf } = Object;
51628
51709
  var kindOf = ((cache) => (thing) => {
@@ -51659,7 +51740,7 @@ var isPlainObject = (val) => {
51659
51740
  return false;
51660
51741
  }
51661
51742
  const prototype3 = getPrototypeOf(val);
51662
- return prototype3 === null || prototype3 === Object.prototype;
51743
+ return (prototype3 === null || prototype3 === Object.prototype || Object.getPrototypeOf(prototype3) === null) && !(Symbol.toStringTag in val) && !(Symbol.iterator in val);
51663
51744
  };
51664
51745
  var isDate = kindOfTest("Date");
51665
51746
  var isFile = kindOfTest("File");
@@ -51903,7 +51984,7 @@ var utils_default = {
51903
51984
  toFiniteNumber
51904
51985
  };
51905
51986
 
51906
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/core/AxiosError.js
51987
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/core/AxiosError.js
51907
51988
  function AxiosError(message, code, config, request, response) {
51908
51989
  Error.call(this);
51909
51990
  if (Error.captureStackTrace) {
@@ -51970,11 +52051,11 @@ AxiosError.from = (error, code, config, request, response, customProps) => {
51970
52051
  };
51971
52052
  var AxiosError_default = AxiosError;
51972
52053
 
51973
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/env/classes/FormData.js
52054
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/env/classes/FormData.js
51974
52055
  var import_form_data = __toESM(require_browser2(), 1);
51975
52056
  var FormData_default = import_form_data.default;
51976
52057
 
51977
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/helpers/toFormData.js
52058
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/helpers/toFormData.js
51978
52059
  function isVisitable(thing) {
51979
52060
  return utils_default.isPlainObject(thing) || utils_default.isArray(thing);
51980
52061
  }
@@ -52091,7 +52172,7 @@ function toFormData(obj, formData, options) {
52091
52172
  }
52092
52173
  var toFormData_default = toFormData;
52093
52174
 
52094
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/helpers/AxiosURLSearchParams.js
52175
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/helpers/AxiosURLSearchParams.js
52095
52176
  function encode(str) {
52096
52177
  const charMap = {
52097
52178
  "!": "%21",
@@ -52124,7 +52205,7 @@ prototype2.toString = function toString3(encoder) {
52124
52205
  };
52125
52206
  var AxiosURLSearchParams_default = AxiosURLSearchParams;
52126
52207
 
52127
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/helpers/buildURL.js
52208
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/helpers/buildURL.js
52128
52209
  function encode2(val) {
52129
52210
  return encodeURIComponent(val).replace(/%3A/gi, ":").replace(/%24/g, "$").replace(/%2C/gi, ",").replace(/%20/g, "+").replace(/%5B/gi, "[").replace(/%5D/gi, "]");
52130
52211
  }
@@ -52144,7 +52225,7 @@ function buildURL(url, params, options) {
52144
52225
  return url;
52145
52226
  }
52146
52227
 
52147
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/core/InterceptorManager.js
52228
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/core/InterceptorManager.js
52148
52229
  var InterceptorManager = class {
52149
52230
  constructor() {
52150
52231
  this.handlers = [];
@@ -52178,20 +52259,20 @@ var InterceptorManager = class {
52178
52259
  };
52179
52260
  var InterceptorManager_default = InterceptorManager;
52180
52261
 
52181
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/defaults/transitional.js
52262
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/defaults/transitional.js
52182
52263
  var transitional_default = {
52183
52264
  silentJSONParsing: true,
52184
52265
  forcedJSONParsing: true,
52185
52266
  clarifyTimeoutError: false
52186
52267
  };
52187
52268
 
52188
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/platform/browser/classes/URLSearchParams.js
52269
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/platform/browser/classes/URLSearchParams.js
52189
52270
  var URLSearchParams_default = typeof URLSearchParams !== "undefined" ? URLSearchParams : AxiosURLSearchParams_default;
52190
52271
 
52191
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/platform/browser/classes/FormData.js
52272
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/platform/browser/classes/FormData.js
52192
52273
  var FormData_default2 = FormData;
52193
52274
 
52194
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/platform/browser/index.js
52275
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/platform/browser/index.js
52195
52276
  var isStandardBrowserEnv = (() => {
52196
52277
  let product;
52197
52278
  if (typeof navigator !== "undefined" && ((product = navigator.product) === "ReactNative" || product === "NativeScript" || product === "NS")) {
@@ -52210,7 +52291,7 @@ var browser_default = {
52210
52291
  protocols: ["http", "https", "file", "blob", "url", "data"]
52211
52292
  };
52212
52293
 
52213
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/helpers/toURLEncodedForm.js
52294
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/helpers/toURLEncodedForm.js
52214
52295
  function toURLEncodedForm(data, options) {
52215
52296
  return toFormData_default(data, new browser_default.classes.URLSearchParams(), Object.assign({
52216
52297
  visitor: function(value, key, path, helpers) {
@@ -52223,7 +52304,7 @@ function toURLEncodedForm(data, options) {
52223
52304
  }, options));
52224
52305
  }
52225
52306
 
52226
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/helpers/formDataToJSON.js
52307
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/helpers/formDataToJSON.js
52227
52308
  function parsePropPath(name) {
52228
52309
  return utils_default.matchAll(/\w+|\[(\w*)]/g, name).map((match) => {
52229
52310
  return match[0] === "[]" ? "" : match[1] || match[0];
@@ -52275,7 +52356,7 @@ function formDataToJSON(formData) {
52275
52356
  }
52276
52357
  var formDataToJSON_default = formDataToJSON;
52277
52358
 
52278
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/core/settle.js
52359
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/core/settle.js
52279
52360
  function settle(resolve, reject, response) {
52280
52361
  const validateStatus2 = response.config.validateStatus;
52281
52362
  if (!response.status || !validateStatus2 || validateStatus2(response.status)) {
@@ -52291,7 +52372,7 @@ function settle(resolve, reject, response) {
52291
52372
  }
52292
52373
  }
52293
52374
 
52294
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/helpers/cookies.js
52375
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/helpers/cookies.js
52295
52376
  var cookies_default = browser_default.isStandardBrowserEnv ? function standardBrowserEnv() {
52296
52377
  return {
52297
52378
  write: function write(name, value, expires, path, domain, secure) {
@@ -52331,17 +52412,17 @@ var cookies_default = browser_default.isStandardBrowserEnv ? function standardBr
52331
52412
  };
52332
52413
  }();
52333
52414
 
52334
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/helpers/isAbsoluteURL.js
52415
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/helpers/isAbsoluteURL.js
52335
52416
  function isAbsoluteURL(url) {
52336
52417
  return /^([a-z][a-z\d+\-.]*:)?\/\//i.test(url);
52337
52418
  }
52338
52419
 
52339
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/helpers/combineURLs.js
52420
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/helpers/combineURLs.js
52340
52421
  function combineURLs(baseURL, relativeURL) {
52341
52422
  return relativeURL ? baseURL.replace(/\/+$/, "") + "/" + relativeURL.replace(/^\/+/, "") : baseURL;
52342
52423
  }
52343
52424
 
52344
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/core/buildFullPath.js
52425
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/core/buildFullPath.js
52345
52426
  function buildFullPath(baseURL, requestedURL) {
52346
52427
  if (baseURL && !isAbsoluteURL(requestedURL)) {
52347
52428
  return combineURLs(baseURL, requestedURL);
@@ -52349,7 +52430,7 @@ function buildFullPath(baseURL, requestedURL) {
52349
52430
  return requestedURL;
52350
52431
  }
52351
52432
 
52352
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/helpers/isURLSameOrigin.js
52433
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/helpers/isURLSameOrigin.js
52353
52434
  var isURLSameOrigin_default = browser_default.isStandardBrowserEnv ? function standardBrowserEnv2() {
52354
52435
  const msie = /(msie|trident)/i.test(navigator.userAgent);
52355
52436
  const urlParsingNode = document.createElement("a");
@@ -52383,7 +52464,7 @@ var isURLSameOrigin_default = browser_default.isStandardBrowserEnv ? function st
52383
52464
  };
52384
52465
  }();
52385
52466
 
52386
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/cancel/CanceledError.js
52467
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/cancel/CanceledError.js
52387
52468
  function CanceledError(message, config, request) {
52388
52469
  AxiosError_default.call(this, message == null ? "canceled" : message, AxiosError_default.ERR_CANCELED, config, request);
52389
52470
  this.name = "CanceledError";
@@ -52393,13 +52474,13 @@ utils_default.inherits(CanceledError, AxiosError_default, {
52393
52474
  });
52394
52475
  var CanceledError_default = CanceledError;
52395
52476
 
52396
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/helpers/parseProtocol.js
52477
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/helpers/parseProtocol.js
52397
52478
  function parseProtocol(url) {
52398
52479
  const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url);
52399
52480
  return match && match[1] || "";
52400
52481
  }
52401
52482
 
52402
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/helpers/parseHeaders.js
52483
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/helpers/parseHeaders.js
52403
52484
  var ignoreDuplicateOf = utils_default.toObjectSet([
52404
52485
  "age",
52405
52486
  "authorization",
@@ -52444,7 +52525,7 @@ var parseHeaders_default = (rawHeaders) => {
52444
52525
  return parsed;
52445
52526
  };
52446
52527
 
52447
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/core/AxiosHeaders.js
52528
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/core/AxiosHeaders.js
52448
52529
  var $internals = Symbol("internals");
52449
52530
  var $defaults = Symbol("defaults");
52450
52531
  function normalizeHeader(header) {
@@ -52653,7 +52734,7 @@ utils_default.freezeMethods(AxiosHeaders.prototype);
52653
52734
  utils_default.freezeMethods(AxiosHeaders);
52654
52735
  var AxiosHeaders_default = AxiosHeaders;
52655
52736
 
52656
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/helpers/speedometer.js
52737
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/helpers/speedometer.js
52657
52738
  function speedometer(samplesCount, min) {
52658
52739
  samplesCount = samplesCount || 10;
52659
52740
  const bytes = new Array(samplesCount);
@@ -52689,7 +52770,7 @@ function speedometer(samplesCount, min) {
52689
52770
  }
52690
52771
  var speedometer_default = speedometer;
52691
52772
 
52692
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/adapters/xhr.js
52773
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/adapters/xhr.js
52693
52774
  function progressEventReducer(listener, isDownloadStream) {
52694
52775
  let bytesNotified = 0;
52695
52776
  const _speedometer = speedometer_default(50, 250);
@@ -52848,7 +52929,7 @@ function xhrAdapter(config) {
52848
52929
  });
52849
52930
  }
52850
52931
 
52851
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/adapters/index.js
52932
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/adapters/index.js
52852
52933
  var adapters = {
52853
52934
  http: xhrAdapter,
52854
52935
  xhr: xhrAdapter
@@ -52872,7 +52953,7 @@ var adapters_default = {
52872
52953
  adapters
52873
52954
  };
52874
52955
 
52875
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/defaults/index.js
52956
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/defaults/index.js
52876
52957
  var DEFAULT_CONTENT_TYPE = {
52877
52958
  "Content-Type": "application/x-www-form-urlencoded"
52878
52959
  };
@@ -52991,7 +53072,7 @@ utils_default.forEach(["post", "put", "patch"], function forEachMethodWithData(m
52991
53072
  });
52992
53073
  var defaults_default = defaults;
52993
53074
 
52994
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/core/transformData.js
53075
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/core/transformData.js
52995
53076
  function transformData(fns, response) {
52996
53077
  const config = this || defaults_default;
52997
53078
  const context = response || config;
@@ -53004,12 +53085,12 @@ function transformData(fns, response) {
53004
53085
  return data;
53005
53086
  }
53006
53087
 
53007
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/cancel/isCancel.js
53088
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/cancel/isCancel.js
53008
53089
  function isCancel(value) {
53009
53090
  return !!(value && value.__CANCEL__);
53010
53091
  }
53011
53092
 
53012
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/core/dispatchRequest.js
53093
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/core/dispatchRequest.js
53013
53094
  function throwIfCancellationRequested(config) {
53014
53095
  if (config.cancelToken) {
53015
53096
  config.cancelToken.throwIfRequested();
@@ -53051,7 +53132,7 @@ function dispatchRequest(config) {
53051
53132
  });
53052
53133
  }
53053
53134
 
53054
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/core/mergeConfig.js
53135
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/core/mergeConfig.js
53055
53136
  function mergeConfig(config1, config2) {
53056
53137
  config2 = config2 || {};
53057
53138
  const config = {};
@@ -53128,10 +53209,10 @@ function mergeConfig(config1, config2) {
53128
53209
  return config;
53129
53210
  }
53130
53211
 
53131
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/env/data.js
53132
- var VERSION = "1.0.0";
53212
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/env/data.js
53213
+ var VERSION = "1.1.2";
53133
53214
 
53134
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/helpers/validator.js
53215
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/helpers/validator.js
53135
53216
  var validators = {};
53136
53217
  ["object", "boolean", "number", "function", "string", "symbol"].forEach((type, i) => {
53137
53218
  validators[type] = function validator(thing) {
@@ -53189,7 +53270,7 @@ var validator_default = {
53189
53270
  validators
53190
53271
  };
53191
53272
 
53192
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/core/Axios.js
53273
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/core/Axios.js
53193
53274
  var validators2 = validator_default.validators;
53194
53275
  var Axios = class {
53195
53276
  constructor(instanceConfig) {
@@ -53312,7 +53393,7 @@ utils_default.forEach(["post", "put", "patch"], function forEachMethodWithData2(
53312
53393
  });
53313
53394
  var Axios_default = Axios;
53314
53395
 
53315
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/cancel/CancelToken.js
53396
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/cancel/CancelToken.js
53316
53397
  var CancelToken = class {
53317
53398
  constructor(executor) {
53318
53399
  if (typeof executor !== "function") {
@@ -53389,19 +53470,19 @@ var CancelToken = class {
53389
53470
  };
53390
53471
  var CancelToken_default = CancelToken;
53391
53472
 
53392
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/helpers/spread.js
53473
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/helpers/spread.js
53393
53474
  function spread(callback) {
53394
53475
  return function wrap(arr) {
53395
53476
  return callback.apply(null, arr);
53396
53477
  };
53397
53478
  }
53398
53479
 
53399
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/helpers/isAxiosError.js
53480
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/helpers/isAxiosError.js
53400
53481
  function isAxiosError(payload) {
53401
53482
  return utils_default.isObject(payload) && payload.isAxiosError === true;
53402
53483
  }
53403
53484
 
53404
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/lib/axios.js
53485
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/lib/axios.js
53405
53486
  function createInstance(defaultConfig) {
53406
53487
  const context = new Axios_default(defaultConfig);
53407
53488
  const instance = bind(Axios_default.prototype.request, context);
@@ -53431,7 +53512,7 @@ axios.formToJSON = (thing) => {
53431
53512
  };
53432
53513
  var axios_default = axios;
53433
53514
 
53434
- // node_modules/.pnpm/axios@1.0.0/node_modules/axios/index.js
53515
+ // node_modules/.pnpm/axios@1.1.2/node_modules/axios/index.js
53435
53516
  var axios_default2 = axios_default;
53436
53517
 
53437
53518
  // src/tokens-info/index.ts
@@ -53544,6 +53625,11 @@ var AllbridgeCoreClient = class {
53544
53625
  }
53545
53626
  };
53546
53627
 
53628
+ // src/configs/production.ts
53629
+ var production = {
53630
+ apiUrl: "https://core.api.allbridgecoreapi.net"
53631
+ };
53632
+
53547
53633
  // src/exceptions/insufficient-pool-liquidity.ts
53548
53634
  var InsufficientPoolLiquidity = class extends Error {
53549
53635
  constructor() {
@@ -53552,107 +53638,9 @@ var InsufficientPoolLiquidity = class extends Error {
53552
53638
  }
53553
53639
  };
53554
53640
 
53555
- // src/utils/calculation/constants.ts
53556
- var SYSTEM_PRECISION = 3;
53557
-
53558
- // src/utils/calculation/index.ts
53559
- function getFeePercent(input, output) {
53560
- return Big(100).minus(Big(100).times(output).div(input)).toNumber();
53561
- }
53562
- function toSystemPrecision(amount, decimals) {
53563
- return convertAmountPrecision(amount, decimals, SYSTEM_PRECISION);
53564
- }
53565
- function fromSystemPrecision(amount, decimals) {
53566
- return convertAmountPrecision(amount, SYSTEM_PRECISION, decimals);
53567
- }
53568
- function swapToVUsd(amount, tokenInfo) {
53569
- const fee = Big(amount).times(tokenInfo.feeShare);
53570
- const amountWithoutFee = Big(amount).minus(fee);
53571
- const inSystemPrecision = toSystemPrecision(
53572
- amountWithoutFee,
53573
- tokenInfo.decimals
53574
- );
53575
- const poolInfo = tokenInfo.poolInfo;
53576
- const tokenBalance = Big(poolInfo.tokenBalance).plus(inSystemPrecision);
53577
- const vUsdNewAmount = getY(tokenBalance, poolInfo.aValue, poolInfo.dValue);
53578
- return Big(poolInfo.vUsdBalance).minus(vUsdNewAmount).round(0, 0);
53579
- }
53580
- function swapFromVUsd(amount, tokenInfo) {
53581
- const poolInfo = tokenInfo.poolInfo;
53582
- const vUsdBalance = Big(amount).plus(poolInfo.vUsdBalance);
53583
- const newAmount = getY(vUsdBalance, poolInfo.aValue, poolInfo.dValue);
53584
- const result = fromSystemPrecision(
53585
- Big(poolInfo.tokenBalance).minus(newAmount),
53586
- tokenInfo.decimals
53587
- );
53588
- const fee = Big(result).times(tokenInfo.feeShare);
53589
- return Big(result).minus(fee).round(0, 0);
53590
- }
53591
- function swapToVUsdReverse(amount, tokenInfo) {
53592
- const poolInfo = tokenInfo.poolInfo;
53593
- const vUsdNewAmount = Big(poolInfo.vUsdBalance).minus(amount);
53594
- const tokenBalance = getY(vUsdNewAmount, poolInfo.aValue, poolInfo.dValue);
53595
- const inSystemPrecision = Big(tokenBalance).minus(poolInfo.tokenBalance);
53596
- const amountWithoutFee = fromSystemPrecision(
53597
- inSystemPrecision,
53598
- tokenInfo.decimals
53599
- );
53600
- const reversedFeeShare = Big(tokenInfo.feeShare).div(
53601
- Big(1).minus(tokenInfo.feeShare)
53602
- );
53603
- const fee = Big(amountWithoutFee).times(reversedFeeShare);
53604
- return Big(amountWithoutFee).plus(fee).round(0, 0);
53605
- }
53606
- function swapFromVUsdReverse(amount, tokenInfo) {
53607
- const reversedFeeShare = Big(tokenInfo.feeShare).div(
53608
- Big(1).minus(tokenInfo.feeShare)
53609
- );
53610
- const fee = Big(amount).times(reversedFeeShare);
53611
- const amountWithFee = Big(amount).plus(fee);
53612
- const inSystemPrecision = toSystemPrecision(
53613
- amountWithFee,
53614
- tokenInfo.decimals
53615
- );
53616
- const poolInfo = tokenInfo.poolInfo;
53617
- const tokenBalance = Big(poolInfo.tokenBalance).minus(inSystemPrecision);
53618
- const vUsdNewAmount = getY(tokenBalance, poolInfo.aValue, poolInfo.dValue);
53619
- return Big(vUsdNewAmount).minus(poolInfo.vUsdBalance).round(0, 0);
53620
- }
53621
- function convertAmountPrecision(amount, decimalsFrom, decimalsTo) {
53622
- const dif = Big(decimalsTo).minus(decimalsFrom).toNumber();
53623
- return Big(amount).times(toPowBase10(dif)).round(0, 0);
53624
- }
53625
- function toPowBase10(decimals) {
53626
- return Big(10).pow(decimals);
53627
- }
53628
- function convertFloatAmountToInt(amountFloat, decimals) {
53629
- return Big(amountFloat).times(toPowBase10(decimals));
53630
- }
53631
- function convertIntAmountToFloat(amountInt, decimals) {
53632
- return Big(amountInt).div(toPowBase10(decimals));
53633
- }
53634
- function getY(x, a, d) {
53635
- const commonPartBig = Big(4).times(a).times(Big(d).minus(x)).minus(d);
53636
- const dCubed = Big(d).pow(3);
53637
- const commonPartSquared = commonPartBig.pow(2);
53638
- const sqrtBig = Big(x).times(Big(x).times(commonPartSquared).plus(Big(4).times(a).times(dCubed))).sqrt();
53639
- const dividerBig = Big(8).times(a).times(x);
53640
- return commonPartBig.times(x).plus(sqrtBig).div(dividerBig);
53641
- }
53642
-
53643
- // src/configs/production.ts
53644
- var production = {
53645
- apiUrl: "https://core.api.allbridgecoreapi.net"
53646
- };
53647
-
53648
- // src/configs/development.ts
53649
- var development = {
53650
- apiUrl: "https://core-dev.a11bd.net"
53651
- };
53652
-
53653
53641
  // src/index.ts
53654
53642
  var AllbridgeCoreSdk = class {
53655
- constructor(params) {
53643
+ constructor(params = production) {
53656
53644
  this.api = new AllbridgeCoreClient({ apiUrl: params.apiUrl });
53657
53645
  this.bridgeService = new BridgeService(this.api);
53658
53646
  }
@@ -53698,8 +53686,8 @@ var AllbridgeCoreSdk = class {
53698
53686
  }
53699
53687
  async getAmountToBeReceivedAndTxCost(amountToSendFloat, sourceChainToken, destinationChainToken, messenger) {
53700
53688
  return {
53701
- fromAmount: Big(amountToSendFloat).toFixed(),
53702
- toAmount: this.getAmountToBeReceived(
53689
+ amountToSendFloat: Big(amountToSendFloat).toFixed(),
53690
+ amountToBeReceivedFloat: this.getAmountToBeReceived(
53703
53691
  amountToSendFloat,
53704
53692
  sourceChainToken,
53705
53693
  destinationChainToken
@@ -53713,12 +53701,12 @@ var AllbridgeCoreSdk = class {
53713
53701
  }
53714
53702
  async getAmountToSendAndTxCost(amountToBeReceivedFloat, sourceChainToken, destinationChainToken, messenger) {
53715
53703
  return {
53716
- fromAmount: this.getAmountToSend(
53704
+ amountToSendFloat: this.getAmountToSend(
53717
53705
  amountToBeReceivedFloat,
53718
53706
  sourceChainToken,
53719
53707
  destinationChainToken
53720
53708
  ),
53721
- toAmount: Big(amountToBeReceivedFloat).toFixed(),
53709
+ amountToBeReceivedFloat: Big(amountToBeReceivedFloat).toFixed(),
53722
53710
  txCost: await this.getTxCost(
53723
53711
  sourceChainToken,
53724
53712
  destinationChainToken,
@@ -53738,7 +53726,7 @@ var AllbridgeCoreSdk = class {
53738
53726
  }
53739
53727
  return convertIntAmountToFloat(
53740
53728
  resultInt,
53741
- sourceChainToken.decimals
53729
+ destinationChainToken.decimals
53742
53730
  ).toFixed();
53743
53731
  }
53744
53732
  getAmountToSend(amountToBeReceivedFloat, sourceChainToken, destinationChainToken) {
@@ -53777,7 +53765,6 @@ export {
53777
53765
  ChainSymbol,
53778
53766
  Messenger,
53779
53767
  TokensInfo,
53780
- development,
53781
53768
  production
53782
53769
  };
53783
53770
  /*!