@t2000/sdk 0.8.5 → 0.8.7

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.
@@ -229,9 +229,13 @@ var ProtocolRegistry = class {
229
229
  function stableToRaw(amount, decimals) {
230
230
  return BigInt(Math.round(amount * 10 ** decimals));
231
231
  }
232
- var ASSET_LOOKUP = new Map(
233
- Object.keys(SUPPORTED_ASSETS).map((k) => [k.toUpperCase(), k])
234
- );
232
+ var ASSET_LOOKUP = /* @__PURE__ */ new Map();
233
+ for (const [key, info] of Object.entries(SUPPORTED_ASSETS)) {
234
+ ASSET_LOOKUP.set(key.toUpperCase(), key);
235
+ if (info.displayName && info.displayName.toUpperCase() !== key.toUpperCase()) {
236
+ ASSET_LOOKUP.set(info.displayName.toUpperCase(), key);
237
+ }
238
+ }
235
239
  function normalizeAsset(input) {
236
240
  return ASSET_LOOKUP.get(input.toUpperCase()) ?? input;
237
241
  }
@@ -819,6 +823,9 @@ async function buildSwapTx(params) {
819
823
  const { client, address, fromAsset, toAsset, amount, maxSlippageBps = DEFAULT_SLIPPAGE_BPS } = params;
820
824
  const fromInfo = SUPPORTED_ASSETS[fromAsset];
821
825
  const toInfo = SUPPORTED_ASSETS[toAsset];
826
+ if (!fromInfo || !toInfo) {
827
+ throw new T2000Error("ASSET_NOT_SUPPORTED", `Swap pair ${fromAsset}/${toAsset} is not supported`);
828
+ }
822
829
  const rawAmount = BigInt(Math.floor(amount * 10 ** fromInfo.decimals));
823
830
  const aggClient = createAggregatorClient(client, address);
824
831
  const result = await aggClient.findRouters({
@@ -871,6 +878,9 @@ async function getPoolPrice(client) {
871
878
  async function getSwapQuote(client, fromAsset, toAsset, amount) {
872
879
  const fromInfo = SUPPORTED_ASSETS[fromAsset];
873
880
  const toInfo = SUPPORTED_ASSETS[toAsset];
881
+ if (!fromInfo || !toInfo) {
882
+ throw new T2000Error("ASSET_NOT_SUPPORTED", `Swap pair ${fromAsset}/${toAsset} is not supported`);
883
+ }
874
884
  const rawAmount = BigInt(Math.floor(amount * 10 ** fromInfo.decimals));
875
885
  const poolPrice = await getPoolPrice(client);
876
886
  try {
@@ -922,19 +932,14 @@ var CetusAdapter = class {
922
932
  this.client = client;
923
933
  }
924
934
  async getQuote(from, to, amount) {
925
- return getSwapQuote(
926
- this.client,
927
- from.toUpperCase(),
928
- to.toUpperCase(),
929
- amount
930
- );
935
+ return getSwapQuote(this.client, from, to, amount);
931
936
  }
932
937
  async buildSwapTx(address, from, to, amount, maxSlippageBps) {
933
938
  const result = await buildSwapTx({
934
939
  client: this.client,
935
940
  address,
936
- fromAsset: from.toUpperCase(),
937
- toAsset: to.toUpperCase(),
941
+ fromAsset: from,
942
+ toAsset: to,
938
943
  amount,
939
944
  maxSlippageBps
940
945
  });