@oydual31/more-vaults-sdk 0.1.16 → 0.2.0

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.
@@ -111,6 +111,10 @@ var OFT_ABI = [
111
111
  "function send(tuple(uint32 dstEid, bytes32 to, uint256 amountLD, uint256 minAmountLD, bytes extraOptions, bytes composeMsg, bytes oftCmd) sendParam, tuple(uint256 nativeFee, uint256 lzTokenFee) fee, address refundAddress) payable returns (tuple(bytes32 guid, uint64 nonce, uint256 amountSentLD, uint256 amountReceivedLD) receipt, tuple(uint256 nativeFee, uint256 lzTokenFee) fee)",
112
112
  "function quoteSend(tuple(uint32 dstEid, bytes32 to, uint256 amountLD, uint256 minAmountLD, bytes extraOptions, bytes composeMsg, bytes oftCmd) sendParam, bool payInLzToken) view returns (tuple(uint256 nativeFee, uint256 lzTokenFee))"
113
113
  ];
114
+ var LZ_ENDPOINT_ABI = [
115
+ "function composeQueue(address from, address to, bytes32 guid, uint16 index) view returns (bytes32 messageHash)",
116
+ "function lzCompose(address _from, address _to, bytes32 _guid, uint16 _index, bytes _message, bytes _extraData) payable"
117
+ ];
114
118
 
115
119
  // src/ethers/errors.ts
116
120
  var MoreVaultsError = class extends Error {
@@ -588,6 +592,9 @@ async function smartDeposit(signer, provider, addresses, assets, receiver, extra
588
592
  }
589
593
  return depositSimple(signer, addresses, assets, receiver);
590
594
  }
595
+ var LZ_ENDPOINT = "0x1a44076050125825900e736c501f859c50fe728c";
596
+ var EMPTY_HASH = "0x0000000000000000000000000000000000000000000000000000000000000000";
597
+ var RECEIVED_HASH = "0x0000000000000000000000000000000000000000000000000000000000000001";
591
598
  async function ensureAllowance3(signer, token, spender, amount) {
592
599
  const owner = await signer.getAddress();
593
600
  const erc20 = new ethers.Contract(token, ERC20_ABI, signer);
@@ -597,11 +604,12 @@ async function ensureAllowance3(signer, token, spender, amount) {
597
604
  await tx.wait();
598
605
  }
599
606
  }
600
- async function depositFromSpoke(signer, spokeOFT, hubEid, spokeEid, amount, receiver, lzFee, minMsgValue = 0n, minSharesOut = 0n, minAmountLD, extraOptions = "0x") {
607
+ async function depositFromSpoke(signer, spokeOFT, composer, hubEid, spokeEid, amount, receiver, lzFee, minMsgValue = 0n, minSharesOut = 0n, minAmountLD, extraOptions = "0x") {
601
608
  await ensureAllowance3(signer, spokeOFT, spokeOFT, amount);
602
609
  const oft = new ethers.Contract(spokeOFT, OFT_ABI, signer);
603
610
  const refundAddress = await signer.getAddress();
604
611
  const receiverBytes32 = ethers.zeroPadValue(receiver, 32);
612
+ const composerBytes32 = ethers.zeroPadValue(composer, 32);
605
613
  const hopSendParam = {
606
614
  dstEid: spokeEid,
607
615
  to: receiverBytes32,
@@ -621,7 +629,7 @@ async function depositFromSpoke(signer, spokeOFT, hubEid, spokeEid, amount, rece
621
629
  );
622
630
  const sendParam = {
623
631
  dstEid: hubEid,
624
- to: receiverBytes32,
632
+ to: composerBytes32,
625
633
  amountLD: amount,
626
634
  minAmountLD: minAmountLD ?? amount,
627
635
  extraOptions,
@@ -636,8 +644,9 @@ async function depositFromSpoke(signer, spokeOFT, hubEid, spokeEid, amount, rece
636
644
  return { receipt };
637
645
  }
638
646
  var depositFromSpokeAsync = depositFromSpoke;
639
- async function quoteDepositFromSpokeFee(provider, spokeOFT, hubEid, spokeEid, amount, receiver, minMsgValue = 0n, minSharesOut = 0n, minAmountLD, extraOptions = "0x") {
647
+ async function quoteDepositFromSpokeFee(provider, spokeOFT, composer, hubEid, spokeEid, amount, receiver, minMsgValue = 0n, minSharesOut = 0n, minAmountLD, extraOptions = "0x") {
640
648
  const receiverBytes32 = ethers.zeroPadValue(receiver, 32);
649
+ const composerBytes32 = ethers.zeroPadValue(composer, 32);
641
650
  const hopSendParam = {
642
651
  dstEid: spokeEid,
643
652
  to: receiverBytes32,
@@ -665,7 +674,7 @@ async function quoteDepositFromSpokeFee(provider, spokeOFT, hubEid, spokeEid, am
665
674
  );
666
675
  const sendParam = {
667
676
  dstEid: hubEid,
668
- to: receiverBytes32,
677
+ to: composerBytes32,
669
678
  amountLD: amount,
670
679
  minAmountLD: minAmountLD ?? amount,
671
680
  extraOptions,
@@ -676,6 +685,55 @@ async function quoteDepositFromSpokeFee(provider, spokeOFT, hubEid, spokeEid, am
676
685
  const fee = await oft.quoteSend(sendParam, false);
677
686
  return fee.nativeFee;
678
687
  }
688
+ async function quoteComposeFee(provider, vault, spokeEid, receiver) {
689
+ try {
690
+ const vaultContract = new ethers.Contract(vault, BRIDGE_ABI, provider);
691
+ const readFee = await vaultContract.quoteAccountingFee("0x");
692
+ let shareSendFee = 0n;
693
+ if (spokeEid && receiver) {
694
+ try {
695
+ const COMPOSER_ABI = ["function SHARE_OFT() view returns (address)"];
696
+ const FACTORY_ABI = ["function vaultComposer(address _vault) view returns (address)"];
697
+ const factory = new ethers.Contract("0x7bDB8B17604b03125eFAED33cA0c55FBf856BB0C", FACTORY_ABI, provider);
698
+ const composerAddr = await factory.vaultComposer(vault);
699
+ const composer = new ethers.Contract(composerAddr, COMPOSER_ABI, provider);
700
+ const shareOftAddr = await composer.SHARE_OFT();
701
+ const shareOft = new ethers.Contract(shareOftAddr, OFT_ABI, provider);
702
+ const receiverBytes32 = ethers.zeroPadValue(receiver, 32);
703
+ const fee = await shareOft.quoteSend({
704
+ dstEid: spokeEid,
705
+ to: receiverBytes32,
706
+ amountLD: 1000000n,
707
+ minAmountLD: 0n,
708
+ extraOptions: "0x",
709
+ composeMsg: "0x",
710
+ oftCmd: "0x"
711
+ }, false);
712
+ shareSendFee = fee.nativeFee;
713
+ } catch {
714
+ }
715
+ }
716
+ return (readFee + shareSendFee) * 110n / 100n;
717
+ } catch {
718
+ return 500000000000000n;
719
+ }
720
+ }
721
+ async function executeCompose(signer, from, to, guid, message, fee, index = 0) {
722
+ const endpoint = new ethers.Contract(LZ_ENDPOINT, LZ_ENDPOINT_ABI, signer);
723
+ const hash = await endpoint.composeQueue(from, to, guid, index);
724
+ if (hash === EMPTY_HASH) {
725
+ throw new Error("Compose not found in queue (hash = 0). Never sent or wrong parameters.");
726
+ }
727
+ if (hash === RECEIVED_HASH) {
728
+ throw new Error("Compose already delivered \u2014 no action needed.");
729
+ }
730
+ const tx = await endpoint.lzCompose(from, to, guid, index, message, "0x", {
731
+ value: fee,
732
+ gasLimit: 5000000n
733
+ });
734
+ const receipt = await tx.wait();
735
+ return { receipt };
736
+ }
679
737
  async function ensureAllowance4(signer, token, spender, amount) {
680
738
  const owner = await signer.getAddress();
681
739
  const erc20 = new ethers.Contract(token, ERC20_ABI, signer);
@@ -998,6 +1056,7 @@ exports.ERC20_ABI = ERC20_ABI;
998
1056
  exports.EscrowNotConfiguredError = EscrowNotConfiguredError;
999
1057
  exports.InsufficientLiquidityError = InsufficientLiquidityError;
1000
1058
  exports.LZ_EIDS = LZ_EIDS;
1059
+ exports.LZ_ENDPOINT_ABI = LZ_ENDPOINT_ABI;
1001
1060
  exports.METADATA_ABI = METADATA_ABI;
1002
1061
  exports.MissingEscrowAddressError = MissingEscrowAddressError;
1003
1062
  exports.MoreVaultsError = MoreVaultsError;
@@ -1017,6 +1076,7 @@ exports.depositFromSpokeAsync = depositFromSpokeAsync;
1017
1076
  exports.depositMultiAsset = depositMultiAsset;
1018
1077
  exports.depositSimple = depositSimple;
1019
1078
  exports.ensureAllowance = ensureAllowance;
1079
+ exports.executeCompose = executeCompose;
1020
1080
  exports.getAsyncRequestStatus = getAsyncRequestStatus;
1021
1081
  exports.getAsyncRequestStatusLabel = getAsyncRequestStatusLabel;
1022
1082
  exports.getMaxWithdrawable = getMaxWithdrawable;
@@ -1033,6 +1093,7 @@ exports.preflightRedeemLiquidity = preflightRedeemLiquidity;
1033
1093
  exports.preflightSync = preflightSync;
1034
1094
  exports.previewDeposit = previewDeposit;
1035
1095
  exports.previewRedeem = previewRedeem;
1096
+ exports.quoteComposeFee = quoteComposeFee;
1036
1097
  exports.quoteDepositFromSpokeFee = quoteDepositFromSpokeFee;
1037
1098
  exports.quoteLzFee = quoteLzFee;
1038
1099
  exports.redeemAsync = redeemAsync;