@sodax/sdk 0.0.1-rc.21 → 0.0.1-rc.23

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
@@ -6158,6 +6158,17 @@ function calculateFeeAmount(inputAmount, fee) {
6158
6158
  }
6159
6159
  return feeAmount;
6160
6160
  }
6161
+ function adjustAmountByFee(amount, fee, quoteType) {
6162
+ invariant10(amount > 0n, "Amount must be greater than 0");
6163
+ invariant10(quoteType === "exact_input" || quoteType === "exact_output", "Invalid quote type");
6164
+ if (quoteType === "exact_input") {
6165
+ return amount - calculateFeeAmount(amount, fee);
6166
+ }
6167
+ if (quoteType === "exact_output") {
6168
+ return amount + calculateFeeAmount(amount, fee);
6169
+ }
6170
+ throw new Error("Invalid quote type");
6171
+ }
6161
6172
  function BigIntToHex(value) {
6162
6173
  return `0x${value.toString(16)}`;
6163
6174
  }
@@ -11173,7 +11184,7 @@ var SolverService = class {
11173
11184
  async getQuote(payload) {
11174
11185
  payload = {
11175
11186
  ...payload,
11176
- amount: payload.amount - this.getFee(payload.amount)
11187
+ amount: adjustAmountByFee(payload.amount, this.config.partnerFee, payload.quote_type)
11177
11188
  };
11178
11189
  return SolverApiService.getQuote(payload, this.config);
11179
11190
  }
@@ -11683,8 +11694,7 @@ var SolverService = class {
11683
11694
  params.srcAddress.toLowerCase() === walletAddress.toLowerCase(),
11684
11695
  "srcAddress must be the same as wallet address"
11685
11696
  );
11686
- const walletAddressBytes = encodeAddress(params.srcChain, walletAddress);
11687
- const creatorHubWalletAddress = spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id ? walletAddressBytes : await WalletAbstractionService.getUserHubWalletAddress(walletAddress, spokeProvider, this.hubProvider);
11697
+ const creatorHubWalletAddress = spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id ? walletAddress : await WalletAbstractionService.getUserHubWalletAddress(walletAddress, spokeProvider, this.hubProvider);
11688
11698
  const [data, intent, feeAmount] = EvmSolverService.constructCreateIntentData(
11689
11699
  {
11690
11700
  ...params,
@@ -11735,8 +11745,7 @@ var SolverService = class {
11735
11745
  invariant10(isValidIntentRelayChainId(intent.srcChain), `Invalid intent.srcChain: ${intent.srcChain}`);
11736
11746
  invariant10(isValidIntentRelayChainId(intent.dstChain), `Invalid intent.dstChain: ${intent.dstChain}`);
11737
11747
  const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
11738
- const walletAddressBytes = encodeAddress(spokeProvider.chainConfig.chain.id, walletAddress);
11739
- const creatorHubWalletAddress = spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id ? walletAddressBytes : await WalletAbstractionService.getUserHubWalletAddress(walletAddress, spokeProvider, this.hubProvider);
11748
+ const creatorHubWalletAddress = spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id ? walletAddress : await WalletAbstractionService.getUserHubWalletAddress(walletAddress, spokeProvider, this.hubProvider);
11740
11749
  const calls = [];
11741
11750
  const intentsContract = this.config.intentsContract;
11742
11751
  calls.push(EvmSolverService.encodeCancelIntent(intent, intentsContract));
@@ -14667,6 +14676,10 @@ var UiPoolDataProviderService = class {
14667
14676
  args: [this.poolAddressesProvider, userAddress]
14668
14677
  });
14669
14678
  }
14679
+ /**
14680
+ * Get the reserves data humanized
14681
+ * @returns {Promise<ReservesDataHumanized>} - The reserves data humanized
14682
+ */
14670
14683
  async getReservesHumanized() {
14671
14684
  const [reservesRaw, poolBaseCurrencyRaw] = await this.getReservesData();
14672
14685
  const reservesData = reservesRaw.map((reserveRaw, index) => {
@@ -14768,7 +14781,7 @@ var LendingPoolService = class {
14768
14781
  }
14769
14782
  /**
14770
14783
  * Get the normalized income for a reserve
14771
- * @param asset The address of the asset
14784
+ * @param asset - The address of the asset
14772
14785
  * @returns {Promise<bigint>} - Normalized income
14773
14786
  */
14774
14787
  async getReserveNormalizedIncome(asset) {
@@ -14785,48 +14798,94 @@ var LendingPoolService = class {
14785
14798
  var MoneyMarketDataService = class {
14786
14799
  uiPoolDataProviderService;
14787
14800
  lendingPoolService;
14801
+ hubProvider;
14788
14802
  constructor(hubProvider) {
14803
+ this.hubProvider = hubProvider;
14789
14804
  this.uiPoolDataProviderService = new UiPoolDataProviderService(hubProvider);
14790
14805
  this.lendingPoolService = new LendingPoolService(hubProvider);
14791
14806
  }
14792
14807
  /**
14793
14808
  * LendingPool
14794
14809
  */
14810
+ /**
14811
+ * Get the normalized income for a reserve
14812
+ * @param asset - The address of the asset
14813
+ * @returns {Promise<bigint>} - Normalized income
14814
+ */
14795
14815
  async getReserveNormalizedIncome(asset) {
14796
14816
  return this.lendingPoolService.getReserveNormalizedIncome(asset);
14797
14817
  }
14818
+ /**
14819
+ * Get the reserve data for an asset
14820
+ * @param asset - The address of the asset
14821
+ * @returns {Promise<ReserveDataLegacy>} - The reserve data
14822
+ */
14798
14823
  async getReserveData(asset) {
14799
14824
  return this.lendingPoolService.getReserveData(asset);
14800
14825
  }
14801
14826
  /**
14802
14827
  * UiPoolDataProvider
14803
14828
  */
14829
+ /**
14830
+ * Get the reserves list
14831
+ * @returns {Promise<readonly Address[]>} - List of reserve asset addresses
14832
+ */
14804
14833
  async getReservesList() {
14805
14834
  return this.uiPoolDataProviderService.getReservesList();
14806
14835
  }
14836
+ /**
14837
+ * Get the reserves data
14838
+ * @returns {Promise<readonly [readonly AggregatedReserveData[], BaseCurrencyInfo]>} - The reserves data
14839
+ */
14807
14840
  async getReservesData() {
14808
14841
  return this.uiPoolDataProviderService.getReservesData();
14809
14842
  }
14810
- async getUserReservesData(userAddress) {
14811
- return this.uiPoolDataProviderService.getUserReservesData(userAddress);
14843
+ /**
14844
+ * Get the user reserves data
14845
+ * @param spokeProvider - The spoke provider
14846
+ * @returns {Promise<readonly [readonly UserReserveData[], number]>} - The user reserves data
14847
+ */
14848
+ async getUserReservesData(spokeProvider) {
14849
+ const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
14850
+ const hubWalletAddress = spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id ? walletAddress : await WalletAbstractionService.getUserHubWalletAddress(walletAddress, spokeProvider, this.hubProvider);
14851
+ return this.uiPoolDataProviderService.getUserReservesData(hubWalletAddress);
14812
14852
  }
14853
+ /**
14854
+ * Get the list of all eModes in the pool
14855
+ * @returns {Promise<readonly EModeData[]>} - Array of eMode data
14856
+ */
14813
14857
  async getEModes() {
14814
14858
  return this.uiPoolDataProviderService.getEModes();
14815
14859
  }
14860
+ /**
14861
+ * Get the list of all eModes in the pool humanized
14862
+ * @returns {Promise<EmodeDataHumanized[]>} - Array of eMode data humanized
14863
+ */
14816
14864
  async getEModesHumanized() {
14817
14865
  return this.uiPoolDataProviderService.getEModesHumanized();
14818
14866
  }
14867
+ /**
14868
+ * Get the reserves data humanized
14869
+ * @returns {Promise<ReservesDataHumanized>} - The reserves data humanized
14870
+ */
14819
14871
  async getReservesHumanized() {
14820
14872
  return this.uiPoolDataProviderService.getReservesHumanized();
14821
14873
  }
14822
- async getUserReservesHumanized(userAddress) {
14823
- return this.uiPoolDataProviderService.getUserReservesHumanized(userAddress);
14874
+ /**
14875
+ * Get the user reserves humanized
14876
+ * @param spokeProvider - The spoke provider
14877
+ * @returns {Promise<{userReserves: UserReserveDataHumanized[], userEmodeCategoryId: number}>} - The user reserves humanized
14878
+ */
14879
+ async getUserReservesHumanized(spokeProvider) {
14880
+ const walletAddress = await spokeProvider.walletProvider.getWalletAddress();
14881
+ const hubWalletAddress = spokeProvider.chainConfig.chain.id === this.hubProvider.chainConfig.chain.id ? walletAddress : await WalletAbstractionService.getUserHubWalletAddress(walletAddress, spokeProvider, this.hubProvider);
14882
+ return this.uiPoolDataProviderService.getUserReservesHumanized(hubWalletAddress);
14824
14883
  }
14825
14884
  /**
14826
14885
  * Utils for building requests
14827
14886
  */
14828
14887
  /**
14829
- * @description builds the request for the formatReserves function
14888
+ * @description Util function to build the request for the formatReserves function
14830
14889
  */
14831
14890
  buildReserveDataWithPrice(reserves) {
14832
14891
  const currentUnixTimestamp = Math.floor(Date.now() / 1e3);
@@ -14839,7 +14898,7 @@ var MoneyMarketDataService = class {
14839
14898
  };
14840
14899
  }
14841
14900
  /**
14842
- * @description builds the request for the formatReserves function
14901
+ * @description Util function to build the request for the formatReserves function
14843
14902
  */
14844
14903
  buildUserSummaryRequest(reserves, formattedReserves, userReserves) {
14845
14904
  const currentUnixTimestamp = Math.floor(Date.now() / 1e3);
@@ -16072,6 +16131,6 @@ var SolverIntentErrorCode = /* @__PURE__ */ ((SolverIntentErrorCode2) => {
16072
16131
  return SolverIntentErrorCode2;
16073
16132
  })(SolverIntentErrorCode || {});
16074
16133
 
16075
- export { BalnSwapService, BigIntToHex, BigNumberZeroDecimal, BnUSDMigrationService, ChainIdToIntentRelayChainId, DEFAULT_MAX_RETRY, DEFAULT_RELAYER_API_ENDPOINT, DEFAULT_RELAY_TX_TIMEOUT, DEFAULT_RETRY_DELAY_MS, EVM_CHAIN_IDS, EVM_SPOKE_CHAIN_IDS, Erc20Service, EvmAssetManagerService, EvmHubProvider, EvmSolverService, EvmSpokeProvider, EvmSpokeService, EvmVaultTokenService, EvmWalletAbstraction, FEE_PERCENTAGE_SCALE, HALF_RAY, HALF_WAD, HubVaultSymbols, ICON_TX_RESULT_WAIT_MAX_RETRY, INTENT_RELAY_CHAIN_IDS, IconSpokeProvider, IcxMigrationService, InjectiveSpokeProvider, IntentCreatedEventAbi, IntentDataType, IntentsAbi, LTV_PRECISION, LendingPoolService, LockupMultiplier, LockupPeriod, MAX_UINT256, MigrationService, MoneyMarketDataService, MoneyMarketService, RAY, RAY_DECIMALS, SECONDS_PER_YEAR, STELLAR_DEFAULT_TX_TIMEOUT_SECONDS, STELLAR_PRIORITY_FEE, Sodax, SolanaSpokeProvider, SolverIntentErrorCode, SolverIntentStatusCode, SolverService, SonicSpokeProvider, SonicSpokeService, SpokeService, StellarSpokeProvider, SuiSpokeProvider, SupportedMigrationTokens, USD_DECIMALS, UiPoolDataProviderService, VAULT_TOKEN_DECIMALS, WAD, WAD_RAY_RATIO, WEI_DECIMALS, WalletAbstractionService, assetManagerAbi, balnSwapAbi, binomialApproximatedRayPow, bnUSDLegacySpokeChainIds, bnUSDLegacyTokens, bnUSDNewTokens, calculateAllReserveIncentives, calculateAllUserIncentives, calculateAvailableBorrowsMarketReferenceCurrency, calculateCompoundedInterest, calculateCompoundedRate, calculateFeeAmount, calculateHealthFactorFromBalances, calculateHealthFactorFromBalancesBigUnits, calculateLinearInterest, calculatePercentageFeeAmount, chainIdToHubAssetsMap, connectionAbi, encodeAddress, encodeContractCalls, erc20Abi, formatBasisPoints, formatEModeCategory, formatEModes, formatPercentage, formatReserve, formatReserveUSD, formatReserves, formatReservesAndIncentives, formatUserSummary, formatUserSummaryAndIncentives, getAllLegacybnUSDTokens, getAndFormatReserveEModes, getCompoundedBalance, getEvmViemChain, getHubAssetInfo, getHubChainConfig, getIconAddressBytes, getIntentRelayChainId, getLinearBalance, getMarketReferenceCurrencyAndUsdBalance, getMoneyMarketConfig, getOriginalAssetAddress, getPacket, getRandomBytes, getReserveNormalizedIncome, getReservesEModes, getSolanaAddressBytes, getSolverConfig, getSpokeChainIdFromIntentRelayChainId, getSupportedMoneyMarketTokens, getSupportedSolverTokens, getTransactionPackets, hexToBigInt, hubAssetToOriginalAssetMap, hubAssets, hubVaults, hubVaultsAddressSet, intentRelayChainIdToSpokeChainIdMap, isBalnMigrateParams, isConfiguredMoneyMarketConfig, isConfiguredSolverConfig, isEvmHubChainConfig, isEvmInitializedConfig, isEvmSpokeChainConfig, isEvmSpokeProvider, isEvmUninitializedBrowserConfig, isEvmUninitializedConfig, isEvmUninitializedPrivateKeyConfig, isIconAddress, isIconSpokeProvider, isIcxCreateRevertMigrationParams, isIcxMigrateParams, isInjectiveSpokeProvider, isIntentCreationFailedError, isIntentCreationUnknownError, isIntentPostExecutionFailedError, isIntentRelayChainId, isIntentSubmitTxFailedError, isJsonRpcPayloadResponse, isLegacybnUSDChainId, isLegacybnUSDToken, isMoneyMarketBorrowUnknownError, isMoneyMarketCreateBorrowIntentFailedError, isMoneyMarketCreateRepayIntentFailedError, isMoneyMarketCreateSupplyIntentFailedError, isMoneyMarketCreateWithdrawIntentFailedError, isMoneyMarketRelayTimeoutError, isMoneyMarketRepayUnknownError, isMoneyMarketReserveAsset, isMoneyMarketReserveHubAsset, isMoneyMarketSubmitTxFailedError, isMoneyMarketSupplyUnknownError, isMoneyMarketSupportedToken, isMoneyMarketWithdrawUnknownError, isNativeToken, isNewbnUSDChainId, isNewbnUSDToken, isPartnerFeeAmount, isPartnerFeePercentage, isResponseAddressType, isResponseSigningType, isSolanaSpokeProvider, isSolverSupportedToken, isSonicSpokeProvider, isStellarSpokeProvider, isSuiSpokeProvider, isUnifiedBnUSDMigrateParams, isValidChainHubAsset, isValidHubAsset, isValidIntentRelayChainId, isValidOriginalAssetAddress, isValidSpokeChainId, isWaitUntilIntentExecutedFailed, moneyMarketReserveAssets, moneyMarketReserveHubAssetsSet, moneyMarketSupportedTokens, nativeToUSD, newbnUSDSpokeChainIds, normalize, normalizeBN, normalizedToUsd, originalAssetTohubAssetMap, poolAbi, randomUint256, rayDiv, rayMul, rayPow, rayToWad, relayTxAndWaitPacket, requestAddress, requestJsonRpc, requestSigning, retry, sonicWalletFactoryAbi, spokeAssetManagerAbi, spokeChainConfig, spokeChainIdsSet, submitTransaction, supportedHubAssets, supportedHubChains, supportedSpokeChains, supportedTokensPerChain, uiPoolDataAbi, valueToBigNumber, valueToZDBigNumber, variableDebtTokenAbi, vaultTokenAbi, wadToRay, waitForTransactionReceipt, waitUntilIntentExecuted, walletFactoryAbi, wrappedSonicAbi };
16134
+ export { BalnSwapService, BigIntToHex, BigNumberZeroDecimal, BnUSDMigrationService, ChainIdToIntentRelayChainId, DEFAULT_MAX_RETRY, DEFAULT_RELAYER_API_ENDPOINT, DEFAULT_RELAY_TX_TIMEOUT, DEFAULT_RETRY_DELAY_MS, EVM_CHAIN_IDS, EVM_SPOKE_CHAIN_IDS, Erc20Service, EvmAssetManagerService, EvmHubProvider, EvmSolverService, EvmSpokeProvider, EvmSpokeService, EvmVaultTokenService, EvmWalletAbstraction, FEE_PERCENTAGE_SCALE, HALF_RAY, HALF_WAD, HubVaultSymbols, ICON_TX_RESULT_WAIT_MAX_RETRY, INTENT_RELAY_CHAIN_IDS, IconSpokeProvider, IcxMigrationService, InjectiveSpokeProvider, IntentCreatedEventAbi, IntentDataType, IntentsAbi, LTV_PRECISION, LendingPoolService, LockupMultiplier, LockupPeriod, MAX_UINT256, MigrationService, MoneyMarketDataService, MoneyMarketService, RAY, RAY_DECIMALS, SECONDS_PER_YEAR, STELLAR_DEFAULT_TX_TIMEOUT_SECONDS, STELLAR_PRIORITY_FEE, Sodax, SolanaSpokeProvider, SolverIntentErrorCode, SolverIntentStatusCode, SolverService, SonicSpokeProvider, SonicSpokeService, SpokeService, StellarSpokeProvider, SuiSpokeProvider, SupportedMigrationTokens, USD_DECIMALS, UiPoolDataProviderService, VAULT_TOKEN_DECIMALS, WAD, WAD_RAY_RATIO, WEI_DECIMALS, WalletAbstractionService, adjustAmountByFee, assetManagerAbi, balnSwapAbi, binomialApproximatedRayPow, bnUSDLegacySpokeChainIds, bnUSDLegacyTokens, bnUSDNewTokens, calculateAllReserveIncentives, calculateAllUserIncentives, calculateAvailableBorrowsMarketReferenceCurrency, calculateCompoundedInterest, calculateCompoundedRate, calculateFeeAmount, calculateHealthFactorFromBalances, calculateHealthFactorFromBalancesBigUnits, calculateLinearInterest, calculatePercentageFeeAmount, chainIdToHubAssetsMap, connectionAbi, encodeAddress, encodeContractCalls, erc20Abi, formatBasisPoints, formatEModeCategory, formatEModes, formatPercentage, formatReserve, formatReserveUSD, formatReserves, formatReservesAndIncentives, formatUserSummary, formatUserSummaryAndIncentives, getAllLegacybnUSDTokens, getAndFormatReserveEModes, getCompoundedBalance, getEvmViemChain, getHubAssetInfo, getHubChainConfig, getIconAddressBytes, getIntentRelayChainId, getLinearBalance, getMarketReferenceCurrencyAndUsdBalance, getMoneyMarketConfig, getOriginalAssetAddress, getPacket, getRandomBytes, getReserveNormalizedIncome, getReservesEModes, getSolanaAddressBytes, getSolverConfig, getSpokeChainIdFromIntentRelayChainId, getSupportedMoneyMarketTokens, getSupportedSolverTokens, getTransactionPackets, hexToBigInt, hubAssetToOriginalAssetMap, hubAssets, hubVaults, hubVaultsAddressSet, intentRelayChainIdToSpokeChainIdMap, isBalnMigrateParams, isConfiguredMoneyMarketConfig, isConfiguredSolverConfig, isEvmHubChainConfig, isEvmInitializedConfig, isEvmSpokeChainConfig, isEvmSpokeProvider, isEvmUninitializedBrowserConfig, isEvmUninitializedConfig, isEvmUninitializedPrivateKeyConfig, isIconAddress, isIconSpokeProvider, isIcxCreateRevertMigrationParams, isIcxMigrateParams, isInjectiveSpokeProvider, isIntentCreationFailedError, isIntentCreationUnknownError, isIntentPostExecutionFailedError, isIntentRelayChainId, isIntentSubmitTxFailedError, isJsonRpcPayloadResponse, isLegacybnUSDChainId, isLegacybnUSDToken, isMoneyMarketBorrowUnknownError, isMoneyMarketCreateBorrowIntentFailedError, isMoneyMarketCreateRepayIntentFailedError, isMoneyMarketCreateSupplyIntentFailedError, isMoneyMarketCreateWithdrawIntentFailedError, isMoneyMarketRelayTimeoutError, isMoneyMarketRepayUnknownError, isMoneyMarketReserveAsset, isMoneyMarketReserveHubAsset, isMoneyMarketSubmitTxFailedError, isMoneyMarketSupplyUnknownError, isMoneyMarketSupportedToken, isMoneyMarketWithdrawUnknownError, isNativeToken, isNewbnUSDChainId, isNewbnUSDToken, isPartnerFeeAmount, isPartnerFeePercentage, isResponseAddressType, isResponseSigningType, isSolanaSpokeProvider, isSolverSupportedToken, isSonicSpokeProvider, isStellarSpokeProvider, isSuiSpokeProvider, isUnifiedBnUSDMigrateParams, isValidChainHubAsset, isValidHubAsset, isValidIntentRelayChainId, isValidOriginalAssetAddress, isValidSpokeChainId, isWaitUntilIntentExecutedFailed, moneyMarketReserveAssets, moneyMarketReserveHubAssetsSet, moneyMarketSupportedTokens, nativeToUSD, newbnUSDSpokeChainIds, normalize, normalizeBN, normalizedToUsd, originalAssetTohubAssetMap, poolAbi, randomUint256, rayDiv, rayMul, rayPow, rayToWad, relayTxAndWaitPacket, requestAddress, requestJsonRpc, requestSigning, retry, sonicWalletFactoryAbi, spokeAssetManagerAbi, spokeChainConfig, spokeChainIdsSet, submitTransaction, supportedHubAssets, supportedHubChains, supportedSpokeChains, supportedTokensPerChain, uiPoolDataAbi, valueToBigNumber, valueToZDBigNumber, variableDebtTokenAbi, vaultTokenAbi, wadToRay, waitForTransactionReceipt, waitUntilIntentExecuted, walletFactoryAbi, wrappedSonicAbi };
16076
16135
  //# sourceMappingURL=index.mjs.map
16077
16136
  //# sourceMappingURL=index.mjs.map