@rhea-finance/cross-chain-sdk 0.1.9 → 0.1.11
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/README.md +45 -2
- package/dist/index.cjs +38 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +37 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -163,11 +163,13 @@ The following steps describe how to create a multi-chain account:
|
|
|
163
163
|
import type {
|
|
164
164
|
IChain,
|
|
165
165
|
IIntentsQuoteResult,
|
|
166
|
+
Asset,
|
|
166
167
|
} from "@rhea-finance/cross-chain-sdk";
|
|
167
168
|
import {
|
|
168
169
|
format_wallet,
|
|
169
170
|
serializationObj,
|
|
170
171
|
getCreateMcaCustomRecipientMsg,
|
|
172
|
+
getCreateMcaFeeData,
|
|
171
173
|
intentsQuotation,
|
|
172
174
|
prepare_sign_message_evm,
|
|
173
175
|
process_signature_evm,
|
|
@@ -200,7 +202,19 @@ const customRecipientMsg = getCreateMcaCustomRecipientMsg({
|
|
|
200
202
|
signedMessages: [signedMessage],
|
|
201
203
|
});
|
|
202
204
|
|
|
203
|
-
// Step 4: Get
|
|
205
|
+
// Step 4: Get create MCA fee data
|
|
206
|
+
// Get the on-chain fee for creating an MCA account
|
|
207
|
+
// Parameters:
|
|
208
|
+
// asset: The Asset object
|
|
209
|
+
// bufferMultiple: Optional buffer multiplier (default 1.05)
|
|
210
|
+
const mcaFee = await getCreateMcaFeeData({
|
|
211
|
+
asset: asset,
|
|
212
|
+
bufferMultiple: 1.05, // optional, default 1.05
|
|
213
|
+
});
|
|
214
|
+
// mcaFee.amountRaw - fee amount with token precision (for contract calls)
|
|
215
|
+
// mcaFee.amountReadable - human-readable fee amount
|
|
216
|
+
|
|
217
|
+
// Step 5: Get intents quote to obtain depositAddress
|
|
204
218
|
const res_quote: IIntentsQuoteResult = await intentsQuotation({
|
|
205
219
|
originAsset: "nep141:xxx",
|
|
206
220
|
destinationAsset: "nep141:xxx",
|
|
@@ -213,8 +227,18 @@ const res_quote: IIntentsQuoteResult = await intentsQuotation({
|
|
|
213
227
|
customRecipientMsg: customRecipientMsg,
|
|
214
228
|
});
|
|
215
229
|
|
|
216
|
-
// Step
|
|
230
|
+
// Step 6: Get depositAddress and transfer funds to complete MCA creation
|
|
217
231
|
const depositAddress = res_quote.quoteSuccessResult?.quote?.depositAddress;
|
|
232
|
+
|
|
233
|
+
// Step 7: Calculate total fee
|
|
234
|
+
// Total fee = MCA creation fee + intents quotation fee (cross-chain bridge/swap fee)
|
|
235
|
+
// quoteFeeData is returned by intentsQuotation when quoteStatus is "success"
|
|
236
|
+
// quoteFeeData.feeAmount - bridge/swap fee amount (readable)
|
|
237
|
+
// quoteFeeData.feeUsd - bridge/swap fee in USD
|
|
238
|
+
const quoteFee = res_quote.quoteFeeData;
|
|
239
|
+
// Total fee (readable) = mcaFee.amountReadable + quoteFee.feeAmount
|
|
240
|
+
// Total fee (USD) = mcaFee amount in USD + quoteFee.feeUsd
|
|
241
|
+
|
|
218
242
|
// Transfer funds to depositAddress using your wallet
|
|
219
243
|
```
|
|
220
244
|
|
|
@@ -307,6 +331,11 @@ const result = await getSupplyDepositData({
|
|
|
307
331
|
// Transfer to depositAddress to complete Supply
|
|
308
332
|
const depositAddress = result.depositAddress;
|
|
309
333
|
// result also contains quoteResult's full quote data
|
|
334
|
+
|
|
335
|
+
// quoteFeeData - cross-chain bridge/swap fee (present when quote succeeds)
|
|
336
|
+
const quoteFeeData = result.quoteResult?.quoteFeeData;
|
|
337
|
+
// quoteFeeData.feeAmount - bridge/swap fee amount (readable)
|
|
338
|
+
// quoteFeeData.feeUsd - bridge/swap fee in USD
|
|
310
339
|
```
|
|
311
340
|
|
|
312
341
|
### Cross-chain Repay
|
|
@@ -437,6 +466,11 @@ const { businessMap, quoteResult } = await prepareBusinessDataOnWithdraw({
|
|
|
437
466
|
decreaseCollateralAmoun,
|
|
438
467
|
});
|
|
439
468
|
|
|
469
|
+
// quoteFeeData - cross-chain bridge/swap fee (present when quote succeeds)
|
|
470
|
+
const quoteFeeData = quoteResult?.quoteFeeData;
|
|
471
|
+
// quoteFeeData.feeAmount - bridge/swap fee amount (readable)
|
|
472
|
+
// quoteFeeData.feeUsd - bridge/swap fee in USD
|
|
473
|
+
|
|
440
474
|
const wallet = format_wallet({ chain, identityKey });
|
|
441
475
|
const signedBusiness = await sign_message({
|
|
442
476
|
chain,
|
|
@@ -938,6 +972,7 @@ if (res.status === "success") {
|
|
|
938
972
|
|
|
939
973
|
**MCA Creation**
|
|
940
974
|
- `getCreateMcaCustomRecipientMsg` - Get custom recipient message for creating MCA
|
|
975
|
+
- `getCreateMcaFeeData` - Get the on-chain fee for creating an MCA account. Returns `{ amountRaw, amountReadable }`. Parameters: `asset` (Asset object), `bufferMultiple` (optional, default 1.5)
|
|
941
976
|
- `getZcashCreateMcaDepositAddress` - Get deposit address when creating MCA with Zcash (Old way)
|
|
942
977
|
- `getZcashResponseDataByAddress` - Get Zcash deposit/creation data by address (Old way)
|
|
943
978
|
|
|
@@ -953,6 +988,14 @@ if (res.status === "success") {
|
|
|
953
988
|
- `prepareBusinessDataOnWithdrawRewards` - Prepare cross-chain withdraw rewards business data
|
|
954
989
|
|
|
955
990
|
|
|
991
|
+
**Intents Quotation**
|
|
992
|
+
- `intentsQuotation` - Get cross-chain swap/bridge quote. Returns `IIntentsQuoteResult` which includes:
|
|
993
|
+
- `quoteStatus` - `"success"` or `"error"`
|
|
994
|
+
- `quoteSuccessResult` - Quote details (depositAddress, amounts, etc.)
|
|
995
|
+
- `quoteFeeData` - Fee data for the cross-chain bridge/swap (only present when `quoteStatus` is `"success"`):
|
|
996
|
+
- `feeAmount` - Bridge/swap fee amount (readable, = amountInFormatted - amountOutFormatted)
|
|
997
|
+
- `feeUsd` - Bridge/swap fee in USD (= amountInUsd - amountOutUsd)
|
|
998
|
+
|
|
956
999
|
**General Utilities**
|
|
957
1000
|
- `format_wallet` - Format wallet address
|
|
958
1001
|
- `serializationObj` - Serialize object
|
package/dist/index.cjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var Decimal13 = require('decimal.js');
|
|
4
|
-
var
|
|
4
|
+
var Big3 = require('big.js');
|
|
5
5
|
var ramda = require('ramda');
|
|
6
6
|
var _7 = require('lodash');
|
|
7
7
|
|
|
8
8
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
9
|
|
|
10
10
|
var Decimal13__default = /*#__PURE__*/_interopDefault(Decimal13);
|
|
11
|
-
var
|
|
11
|
+
var Big3__default = /*#__PURE__*/_interopDefault(Big3);
|
|
12
12
|
var _7__default = /*#__PURE__*/_interopDefault(_7);
|
|
13
13
|
|
|
14
14
|
var __create = Object.create;
|
|
@@ -18151,7 +18151,7 @@ async function fetchIntentsQuotation(params) {
|
|
|
18151
18151
|
refundType: "ORIGIN_CHAIN",
|
|
18152
18152
|
recipientType: "DESTINATION_CHAIN",
|
|
18153
18153
|
depositType: "ORIGIN_CHAIN",
|
|
18154
|
-
deadline: new Date(Date.now() +
|
|
18154
|
+
deadline: new Date(Date.now() + 1 * 60 * 60 * 1e3).toISOString(),
|
|
18155
18155
|
referral: "rhea",
|
|
18156
18156
|
quoteWaitingTimeMs: 3e3,
|
|
18157
18157
|
slippageTolerance: typeof params.slippageTolerance == "number" ? params.slippageTolerance : 50
|
|
@@ -18167,9 +18167,19 @@ async function fetchIntentsQuotation(params) {
|
|
|
18167
18167
|
});
|
|
18168
18168
|
const quote = response?.quote;
|
|
18169
18169
|
if (quote) {
|
|
18170
|
+
const feeAmountBig = new Big3__default.default(quote?.amountInFormatted || 0).minus(
|
|
18171
|
+
quote?.amountOutFormatted || 0
|
|
18172
|
+
);
|
|
18173
|
+
const feeUsdBig = new Big3__default.default(quote?.amountInUsd || 0).minus(
|
|
18174
|
+
quote?.amountOutUsd || 0
|
|
18175
|
+
);
|
|
18170
18176
|
return {
|
|
18171
18177
|
quoteStatus: "success",
|
|
18172
|
-
quoteSuccessResult: response
|
|
18178
|
+
quoteSuccessResult: response,
|
|
18179
|
+
quoteFeeData: {
|
|
18180
|
+
feeAmount: feeAmountBig.gt(0) ? feeAmountBig.toFixed() : "0",
|
|
18181
|
+
feeUsd: feeUsdBig.gt(0) ? feeUsdBig.toFixed() : "0"
|
|
18182
|
+
}
|
|
18173
18183
|
};
|
|
18174
18184
|
} else {
|
|
18175
18185
|
return {
|
|
@@ -18521,7 +18531,7 @@ async function getSwapActionsList({
|
|
|
18521
18531
|
});
|
|
18522
18532
|
return {
|
|
18523
18533
|
swapActionsList,
|
|
18524
|
-
amountOut: new
|
|
18534
|
+
amountOut: new Big3__default.default(amount_out || 0).mul(1 - slippage).toFixed(0, Big3__default.default.roundDown)
|
|
18525
18535
|
};
|
|
18526
18536
|
}
|
|
18527
18537
|
async function swap_tx_query({
|
|
@@ -18536,7 +18546,7 @@ async function swap_tx_query({
|
|
|
18536
18546
|
tokenInAmount: amountToken,
|
|
18537
18547
|
tokenOutId
|
|
18538
18548
|
});
|
|
18539
|
-
if (res_swap.length <= 0 || new
|
|
18549
|
+
if (res_swap.length <= 0 || new Big3__default.default(amountOut).lte(0)) {
|
|
18540
18550
|
return {
|
|
18541
18551
|
status: "error",
|
|
18542
18552
|
message: "No path available to make a swap"
|
|
@@ -19832,7 +19842,7 @@ function getUnclaimedRewards({
|
|
|
19832
19842
|
const sumByToken = {};
|
|
19833
19843
|
const add = (rewardTokenId, unclaimedAmount) => {
|
|
19834
19844
|
if (unclaimedAmount === "0") return;
|
|
19835
|
-
sumByToken[rewardTokenId] =
|
|
19845
|
+
sumByToken[rewardTokenId] = Big3__default.default(sumByToken[rewardTokenId] || "0").plus(unclaimedAmount).toFixed(0);
|
|
19836
19846
|
};
|
|
19837
19847
|
Object.values(tokennetbalance).forEach((farm) => {
|
|
19838
19848
|
Object.entries(farm).forEach(([rewardTokenId, data]) => {
|
|
@@ -19887,6 +19897,24 @@ async function getSimpleWithdrawData(params) {
|
|
|
19887
19897
|
}
|
|
19888
19898
|
return result;
|
|
19889
19899
|
}
|
|
19900
|
+
async function getCreateMcaFeeData({
|
|
19901
|
+
bufferMultiple = 1.05,
|
|
19902
|
+
asset
|
|
19903
|
+
}) {
|
|
19904
|
+
const feeList = await getCreateMcaFeePaged();
|
|
19905
|
+
const nearValueList = await getNearValuesPaged();
|
|
19906
|
+
const tokenId = asset.token_id;
|
|
19907
|
+
const mcaFee = feeList[tokenId] || "0";
|
|
19908
|
+
const nearValue = nearValueList[tokenId] || "0";
|
|
19909
|
+
const totalFee = Big3__default.default(mcaFee).plus(Big3__default.default(nearValue).mul(0.1)).toFixed(0, Big3__default.default.roundDown);
|
|
19910
|
+
const decimals = asset.metadata?.decimals ?? 0;
|
|
19911
|
+
const amountRaw = Big3__default.default(totalFee).mul(bufferMultiple).toFixed(0, Big3__default.default.roundDown);
|
|
19912
|
+
const amountReadable = toReadableNumber(decimals, amountRaw);
|
|
19913
|
+
return {
|
|
19914
|
+
amountRaw,
|
|
19915
|
+
amountReadable
|
|
19916
|
+
};
|
|
19917
|
+
}
|
|
19890
19918
|
|
|
19891
19919
|
// src/utils/transformers/account.ts
|
|
19892
19920
|
init_polyfills();
|
|
@@ -20822,7 +20850,7 @@ async function prepareBusinessDataOnWithdrawRewards({
|
|
|
20822
20850
|
}
|
|
20823
20851
|
});
|
|
20824
20852
|
}
|
|
20825
|
-
const bridgeTokenAmount = new
|
|
20853
|
+
const bridgeTokenAmount = new Big3__default.default(amountOut).toFixed(0, Decimal13__default.default.ROUND_DOWN);
|
|
20826
20854
|
const quoteResult = await intentsQuotation({
|
|
20827
20855
|
originAsset,
|
|
20828
20856
|
destinationAsset,
|
|
@@ -20858,7 +20886,7 @@ async function prepareBusinessDataOnWithdrawRewards({
|
|
|
20858
20886
|
]
|
|
20859
20887
|
};
|
|
20860
20888
|
const businessMapExtra = {
|
|
20861
|
-
nonce: new
|
|
20889
|
+
nonce: new Big3__default.default(nonce).plus(1).toFixed(0),
|
|
20862
20890
|
deadline,
|
|
20863
20891
|
tx_requests: [
|
|
20864
20892
|
...mca_register_receive_token_tx,
|
|
@@ -21131,6 +21159,7 @@ exports.getBorrowMaxAmount = getBorrowMaxAmount;
|
|
|
21131
21159
|
exports.getConfig = getConfig2;
|
|
21132
21160
|
exports.getCreateMcaCustomRecipientMsg = getCreateMcaCustomRecipientMsg;
|
|
21133
21161
|
exports.getCreateMcaFee = getCreateMcaFee;
|
|
21162
|
+
exports.getCreateMcaFeeData = getCreateMcaFeeData;
|
|
21134
21163
|
exports.getCreateMcaFeePaged = getCreateMcaFeePaged;
|
|
21135
21164
|
exports.getFarmDetailsOfAsset = getFarmDetailsOfAsset;
|
|
21136
21165
|
exports.getListWalletsByMca = getListWalletsByMca;
|