@rhea-finance/cross-chain-sdk 0.1.8 → 0.1.10
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 +73 -2
- package/dist/index.cjs +91 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -1
- package/dist/index.d.ts +30 -1
- package/dist/index.js +89 -8
- 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,
|
|
@@ -759,6 +793,33 @@ if (relayer_result?.code == 0) {
|
|
|
759
793
|
}
|
|
760
794
|
```
|
|
761
795
|
|
|
796
|
+
### Get farm details for an asset
|
|
797
|
+
|
|
798
|
+
```typescript
|
|
799
|
+
import {
|
|
800
|
+
getFarmDetailsOfAsset,
|
|
801
|
+
getAssetDetailsView,
|
|
802
|
+
} from "@rhea-finance/cross-chain-sdk";
|
|
803
|
+
|
|
804
|
+
// Get assets view (IAssetsView)
|
|
805
|
+
const assets = await getAssetDetailsView();
|
|
806
|
+
|
|
807
|
+
// Get farm details for a specific asset
|
|
808
|
+
const farmDetails = getFarmDetailsOfAsset({
|
|
809
|
+
assets,
|
|
810
|
+
assetId: "zec.omft.near",
|
|
811
|
+
booster: 1.5, // optional, default 1.5
|
|
812
|
+
});
|
|
813
|
+
|
|
814
|
+
// farmDetails: IFarmDetailsOfAsset
|
|
815
|
+
console.log(farmDetails.minFarmApy); // market farm APY (min)
|
|
816
|
+
console.log(farmDetails.maxFarmApy); // max farm APY (with booster)
|
|
817
|
+
console.log(farmDetails.tokenNetRewards); // reward token metadata
|
|
818
|
+
console.log(farmDetails.canBeBooster); // whether asset can be boosted
|
|
819
|
+
console.log(farmDetails.supplyApy); // supply APR (%)
|
|
820
|
+
console.log(farmDetails.borrowApy); // borrow APR (%)
|
|
821
|
+
```
|
|
822
|
+
|
|
762
823
|
### Cross-chain Withdraw Rewards
|
|
763
824
|
|
|
764
825
|
```typescript
|
|
@@ -882,6 +943,7 @@ if (res.status === "success") {
|
|
|
882
943
|
- `getPrices` - Get price information
|
|
883
944
|
- `getBalance` - Get balance
|
|
884
945
|
- `getFarms` - Get liquidity mining information
|
|
946
|
+
- `getFarmDetailsOfAsset` - Get farm details (APY, rewards, canBeBooster) for an asset
|
|
885
947
|
- `getConfig` - Get configuration
|
|
886
948
|
- `getBoosterTokens` - Get booster token information
|
|
887
949
|
- `getTokenDetail` - Get token details
|
|
@@ -910,6 +972,7 @@ if (res.status === "success") {
|
|
|
910
972
|
|
|
911
973
|
**MCA Creation**
|
|
912
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)
|
|
913
976
|
- `getZcashCreateMcaDepositAddress` - Get deposit address when creating MCA with Zcash (Old way)
|
|
914
977
|
- `getZcashResponseDataByAddress` - Get Zcash deposit/creation data by address (Old way)
|
|
915
978
|
|
|
@@ -925,6 +988,14 @@ if (res.status === "success") {
|
|
|
925
988
|
- `prepareBusinessDataOnWithdrawRewards` - Prepare cross-chain withdraw rewards business data
|
|
926
989
|
|
|
927
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
|
+
|
|
928
999
|
**General Utilities**
|
|
929
1000
|
- `format_wallet` - Format wallet address
|
|
930
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;
|
|
@@ -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();
|
|
@@ -20071,6 +20099,59 @@ var getAllFarms = async () => {
|
|
|
20071
20099
|
throw new Error("getAllFarms");
|
|
20072
20100
|
}
|
|
20073
20101
|
};
|
|
20102
|
+
function getFarmDetailsOfAsset({
|
|
20103
|
+
assets,
|
|
20104
|
+
assetId,
|
|
20105
|
+
booster = 1.5
|
|
20106
|
+
}) {
|
|
20107
|
+
const asset = assets[assetId];
|
|
20108
|
+
if (!asset) {
|
|
20109
|
+
return {
|
|
20110
|
+
minFarmApy: 0,
|
|
20111
|
+
maxFarmApy: 0,
|
|
20112
|
+
tokenNetRewards: [],
|
|
20113
|
+
canBeBooster: false,
|
|
20114
|
+
supplyApy: 0,
|
|
20115
|
+
borrowApy: 0
|
|
20116
|
+
};
|
|
20117
|
+
}
|
|
20118
|
+
const tokenNetFarms = asset.farms.tokennetbalance || {};
|
|
20119
|
+
const assetDecimals = (asset.metadata?.decimals ?? 0) + (asset.config?.extra_decimals ?? 0);
|
|
20120
|
+
const rewardMetas = [];
|
|
20121
|
+
for (const rewardTokenId of Object.keys(tokenNetFarms)) {
|
|
20122
|
+
const rewardAsset = assets[rewardTokenId];
|
|
20123
|
+
if (rewardAsset?.metadata) rewardMetas.push(rewardAsset.metadata);
|
|
20124
|
+
}
|
|
20125
|
+
const firstFarm = Object.values(tokenNetFarms)[0];
|
|
20126
|
+
const canBeBooster = !!(firstFarm?.booster_log_bases && Object.keys(firstFarm.booster_log_bases).length > 0);
|
|
20127
|
+
const marketFarmApy = Object.entries(tokenNetFarms).reduce(
|
|
20128
|
+
(acc, [rewardTokenId, farmData]) => {
|
|
20129
|
+
const rewardAsset = assets[rewardTokenId];
|
|
20130
|
+
if (!rewardAsset) return acc;
|
|
20131
|
+
const rewardAPY = new Decimal13__default.default(farmData.reward_per_day).div(
|
|
20132
|
+
new Decimal13__default.default(10).pow(
|
|
20133
|
+
(rewardAsset.metadata?.decimals ?? 0) + (rewardAsset.config?.extra_decimals ?? 0)
|
|
20134
|
+
)
|
|
20135
|
+
).mul(365).mul(rewardAsset.price?.usd || "0").div(
|
|
20136
|
+
new Decimal13__default.default(shrinkToken(farmData.boosted_shares, assetDecimals)).mul(
|
|
20137
|
+
asset.price?.usd || "0"
|
|
20138
|
+
)
|
|
20139
|
+
).mul(100);
|
|
20140
|
+
return acc.plus(rewardAPY);
|
|
20141
|
+
},
|
|
20142
|
+
new Decimal13__default.default(0)
|
|
20143
|
+
);
|
|
20144
|
+
const supplyApr = new Decimal13__default.default(asset.supply_apr || 0).mul(100).toNumber();
|
|
20145
|
+
const borrowApr = new Decimal13__default.default(asset.borrow_apr || 0).mul(100).toNumber();
|
|
20146
|
+
return {
|
|
20147
|
+
minFarmApy: marketFarmApy.toNumber(),
|
|
20148
|
+
maxFarmApy: marketFarmApy.mul(booster).toNumber(),
|
|
20149
|
+
supplyApy: supplyApr,
|
|
20150
|
+
borrowApy: borrowApr,
|
|
20151
|
+
tokenNetRewards: rewardMetas,
|
|
20152
|
+
canBeBooster
|
|
20153
|
+
};
|
|
20154
|
+
}
|
|
20074
20155
|
|
|
20075
20156
|
// src/view/zcash.ts
|
|
20076
20157
|
init_polyfills();
|
|
@@ -20769,7 +20850,7 @@ async function prepareBusinessDataOnWithdrawRewards({
|
|
|
20769
20850
|
}
|
|
20770
20851
|
});
|
|
20771
20852
|
}
|
|
20772
|
-
const bridgeTokenAmount = new
|
|
20853
|
+
const bridgeTokenAmount = new Big3__default.default(amountOut).toFixed(0, Decimal13__default.default.ROUND_DOWN);
|
|
20773
20854
|
const quoteResult = await intentsQuotation({
|
|
20774
20855
|
originAsset,
|
|
20775
20856
|
destinationAsset,
|
|
@@ -20805,7 +20886,7 @@ async function prepareBusinessDataOnWithdrawRewards({
|
|
|
20805
20886
|
]
|
|
20806
20887
|
};
|
|
20807
20888
|
const businessMapExtra = {
|
|
20808
|
-
nonce: new
|
|
20889
|
+
nonce: new Big3__default.default(nonce).plus(1).toFixed(0),
|
|
20809
20890
|
deadline,
|
|
20810
20891
|
tx_requests: [
|
|
20811
20892
|
...mca_register_receive_token_tx,
|
|
@@ -21078,7 +21159,9 @@ exports.getBorrowMaxAmount = getBorrowMaxAmount;
|
|
|
21078
21159
|
exports.getConfig = getConfig2;
|
|
21079
21160
|
exports.getCreateMcaCustomRecipientMsg = getCreateMcaCustomRecipientMsg;
|
|
21080
21161
|
exports.getCreateMcaFee = getCreateMcaFee;
|
|
21162
|
+
exports.getCreateMcaFeeData = getCreateMcaFeeData;
|
|
21081
21163
|
exports.getCreateMcaFeePaged = getCreateMcaFeePaged;
|
|
21164
|
+
exports.getFarmDetailsOfAsset = getFarmDetailsOfAsset;
|
|
21082
21165
|
exports.getListWalletsByMca = getListWalletsByMca;
|
|
21083
21166
|
exports.getMcaByWallet = getMcaByWallet;
|
|
21084
21167
|
exports.getMultichainLendingConfig = getMultichainLendingConfig;
|