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