@rhea-finance/cross-chain-aggregation-dex 0.1.4 → 0.1.5
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.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +57 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +57 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -90,6 +90,8 @@ interface BaseExecuteParams {
|
|
|
90
90
|
recipient: string;
|
|
91
91
|
depositAddress?: string;
|
|
92
92
|
deadline?: number;
|
|
93
|
+
/** Optional sender address (for native NEAR wrap operations) */
|
|
94
|
+
sender?: string;
|
|
93
95
|
}
|
|
94
96
|
/**
|
|
95
97
|
* Recipient execute parameters (V2 NEAR, EVM, etc.)
|
|
@@ -429,6 +431,10 @@ interface CompleteQuoteParams {
|
|
|
429
431
|
recipient: string;
|
|
430
432
|
refundTo?: string;
|
|
431
433
|
customRecipientMsg?: string;
|
|
434
|
+
appFees?: Array<{
|
|
435
|
+
recipient: string;
|
|
436
|
+
fee: number;
|
|
437
|
+
}>;
|
|
432
438
|
}
|
|
433
439
|
interface CompleteQuoteResult {
|
|
434
440
|
intents: {
|
package/dist/index.d.ts
CHANGED
|
@@ -90,6 +90,8 @@ interface BaseExecuteParams {
|
|
|
90
90
|
recipient: string;
|
|
91
91
|
depositAddress?: string;
|
|
92
92
|
deadline?: number;
|
|
93
|
+
/** Optional sender address (for native NEAR wrap operations) */
|
|
94
|
+
sender?: string;
|
|
93
95
|
}
|
|
94
96
|
/**
|
|
95
97
|
* Recipient execute parameters (V2 NEAR, EVM, etc.)
|
|
@@ -429,6 +431,10 @@ interface CompleteQuoteParams {
|
|
|
429
431
|
recipient: string;
|
|
430
432
|
refundTo?: string;
|
|
431
433
|
customRecipientMsg?: string;
|
|
434
|
+
appFees?: Array<{
|
|
435
|
+
recipient: string;
|
|
436
|
+
fee: number;
|
|
437
|
+
}>;
|
|
432
438
|
}
|
|
433
439
|
interface CompleteQuoteResult {
|
|
434
440
|
intents: {
|
package/dist/index.js
CHANGED
|
@@ -147,6 +147,13 @@ function convertSlippageToBasisPoints(slippage) {
|
|
|
147
147
|
}
|
|
148
148
|
function normalizeDestinationAsset(assetId, wrapNearContractId = "wrap.near") {
|
|
149
149
|
if (!assetId) return assetId;
|
|
150
|
+
if (assetId.startsWith("1cs_v1:")) {
|
|
151
|
+
const parts = assetId.split(":");
|
|
152
|
+
const nep141Index = parts.findIndex((p) => p === "nep141");
|
|
153
|
+
if (nep141Index >= 0 && nep141Index < parts.length - 1) {
|
|
154
|
+
return `nep141:${parts.slice(nep141Index + 1).join(":")}`;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
150
157
|
if (assetId.startsWith("nep141:") || assetId.startsWith("nep245:")) {
|
|
151
158
|
return assetId;
|
|
152
159
|
}
|
|
@@ -383,7 +390,43 @@ var NearSmartRouter = class {
|
|
|
383
390
|
};
|
|
384
391
|
}
|
|
385
392
|
const finalRecipient = depositAddress || recipient;
|
|
393
|
+
const sender = params.sender || finalRecipient;
|
|
386
394
|
const transactions = [];
|
|
395
|
+
const isNativeNear = quote.tokenIn.address === "near" || quote.tokenIn.address === this.wrapNearContractId && quote.tokenIn.symbol === "NEAR" || !quote.tokenIn.address && quote.tokenIn.symbol === "NEAR";
|
|
396
|
+
if (isNativeNear) {
|
|
397
|
+
let wrapNearStorageBalance = null;
|
|
398
|
+
try {
|
|
399
|
+
wrapNearStorageBalance = await this.nearChainAdapter.view({
|
|
400
|
+
contractId: this.wrapNearContractId,
|
|
401
|
+
methodName: "storage_balance_of",
|
|
402
|
+
args: {
|
|
403
|
+
account_id: sender
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
} catch (err) {
|
|
407
|
+
wrapNearStorageBalance = null;
|
|
408
|
+
}
|
|
409
|
+
if (!wrapNearStorageBalance) {
|
|
410
|
+
transactions.push({
|
|
411
|
+
contractId: this.wrapNearContractId,
|
|
412
|
+
methodName: "storage_deposit",
|
|
413
|
+
args: {
|
|
414
|
+
account_id: sender,
|
|
415
|
+
registration_only: true
|
|
416
|
+
},
|
|
417
|
+
gas: "50000000000000",
|
|
418
|
+
expandDeposit: "1250000000000000000000"
|
|
419
|
+
// 0.00125 NEAR
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
transactions.push({
|
|
423
|
+
contractId: this.wrapNearContractId,
|
|
424
|
+
methodName: "near_deposit",
|
|
425
|
+
args: {},
|
|
426
|
+
gas: "50000000000000",
|
|
427
|
+
expandDeposit: quote.amountIn
|
|
428
|
+
});
|
|
429
|
+
}
|
|
387
430
|
if (finalRecipient && quote.tokenOut?.address) {
|
|
388
431
|
let isRegistered = false;
|
|
389
432
|
try {
|
|
@@ -419,8 +462,9 @@ var NearSmartRouter = class {
|
|
|
419
462
|
if (finalRecipient) {
|
|
420
463
|
swapMsg.swap_out_recipient = finalRecipient;
|
|
421
464
|
}
|
|
465
|
+
const tokenInAddress = isNativeNear ? this.wrapNearContractId : quote.tokenIn.address;
|
|
422
466
|
transactions.push({
|
|
423
|
-
contractId:
|
|
467
|
+
contractId: tokenInAddress,
|
|
424
468
|
methodName: "ft_transfer_call",
|
|
425
469
|
args: {
|
|
426
470
|
receiver_id: this.refExchangeId,
|
|
@@ -980,7 +1024,8 @@ async function completeQuote(params, config) {
|
|
|
980
1024
|
slippage,
|
|
981
1025
|
recipient,
|
|
982
1026
|
refundTo,
|
|
983
|
-
customRecipientMsg
|
|
1027
|
+
customRecipientMsg,
|
|
1028
|
+
appFees
|
|
984
1029
|
} = params;
|
|
985
1030
|
const {
|
|
986
1031
|
intentsQuotationAdapter,
|
|
@@ -1045,13 +1090,15 @@ async function completeQuote(params, config) {
|
|
|
1045
1090
|
const bluechipTokenConfig = bluechipKey && bluechipTokens[bluechipKey] || void 0;
|
|
1046
1091
|
const normalizedSourceAsset = bluechipTokenConfig?.assetId ? bluechipTokenConfig.assetId : `nep141:${bluechipToken.address}`;
|
|
1047
1092
|
let normalizedTargetAsset = targetToken.address;
|
|
1048
|
-
if (normalizedTargetAsset && !normalizedTargetAsset.startsWith("nep141:") && !normalizedTargetAsset.startsWith("nep245:") && normalizedTargetAsset.includes(".")) {
|
|
1093
|
+
if (normalizedTargetAsset?.startsWith("1cs_v1:")) ; else if (normalizedTargetAsset && !normalizedTargetAsset.startsWith("nep141:") && !normalizedTargetAsset.startsWith("nep245:") && normalizedTargetAsset.includes(".")) {
|
|
1049
1094
|
normalizedTargetAsset = `nep141:${normalizeTokenId(
|
|
1050
1095
|
normalizedTargetAsset,
|
|
1051
1096
|
wrapNearContractId
|
|
1052
1097
|
)}`;
|
|
1053
1098
|
}
|
|
1054
|
-
|
|
1099
|
+
if (!normalizedTargetAsset?.startsWith("1cs_v1:")) {
|
|
1100
|
+
normalizedTargetAsset = normalizeDestinationAsset(normalizedTargetAsset, wrapNearContractId) || normalizedTargetAsset;
|
|
1101
|
+
}
|
|
1055
1102
|
const slippageBps = convertSlippageToBasisPoints(slippage);
|
|
1056
1103
|
const intentsQuote = await intentsQuotationAdapter.quote({
|
|
1057
1104
|
originAsset: normalizedSourceAsset,
|
|
@@ -1061,7 +1108,8 @@ async function completeQuote(params, config) {
|
|
|
1061
1108
|
recipient,
|
|
1062
1109
|
slippageTolerance: slippageBps,
|
|
1063
1110
|
swapType: "FLEX_INPUT",
|
|
1064
|
-
...customRecipientMsg ? { customRecipientMsg } : {}
|
|
1111
|
+
...customRecipientMsg ? { customRecipientMsg } : {},
|
|
1112
|
+
...appFees ? { appFees } : {}
|
|
1065
1113
|
});
|
|
1066
1114
|
if (intentsQuote.quoteStatus !== "success") {
|
|
1067
1115
|
throw new Error("Failed to get quote");
|
|
@@ -1104,13 +1152,15 @@ async function completeQuote(params, config) {
|
|
|
1104
1152
|
}
|
|
1105
1153
|
}
|
|
1106
1154
|
let normalizedTargetAsset = targetToken.address;
|
|
1107
|
-
if (normalizedTargetAsset && !normalizedTargetAsset.startsWith("nep141:") && !normalizedTargetAsset.startsWith("nep245:") && normalizedTargetAsset.includes(".")) {
|
|
1155
|
+
if (normalizedTargetAsset?.startsWith("1cs_v1:")) ; else if (normalizedTargetAsset && !normalizedTargetAsset.startsWith("nep141:") && !normalizedTargetAsset.startsWith("nep245:") && normalizedTargetAsset.includes(".")) {
|
|
1108
1156
|
normalizedTargetAsset = `nep141:${normalizeTokenId(
|
|
1109
1157
|
normalizedTargetAsset,
|
|
1110
1158
|
wrapNearContractId
|
|
1111
1159
|
)}`;
|
|
1112
1160
|
}
|
|
1113
|
-
|
|
1161
|
+
if (!normalizedTargetAsset?.startsWith("1cs_v1:")) {
|
|
1162
|
+
normalizedTargetAsset = normalizeDestinationAsset(normalizedTargetAsset, wrapNearContractId) || normalizedTargetAsset;
|
|
1163
|
+
}
|
|
1114
1164
|
const slippageBps = convertSlippageToBasisPoints(slippage);
|
|
1115
1165
|
const intentsQuote = await intentsQuotationAdapter.quote({
|
|
1116
1166
|
originAsset: normalizedSourceAsset,
|