@oydual31/more-vaults-sdk 0.4.2 → 0.5.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.
@@ -910,6 +910,41 @@ var DEX_ABI = [
910
910
  stateMutability: "nonpayable"
911
911
  }
912
912
  ];
913
+ var BRIDGE_FACET_ABI = [
914
+ {
915
+ type: "function",
916
+ name: "executeBridging",
917
+ inputs: [
918
+ { name: "adapter", type: "address" },
919
+ { name: "token", type: "address" },
920
+ { name: "amount", type: "uint256" },
921
+ { name: "bridgeSpecificParams", type: "bytes" }
922
+ ],
923
+ outputs: [],
924
+ stateMutability: "payable"
925
+ },
926
+ {
927
+ type: "function",
928
+ name: "initVaultActionRequest",
929
+ inputs: [
930
+ { name: "actionType", type: "uint8" },
931
+ { name: "actionCallData", type: "bytes" },
932
+ { name: "amountLimit", type: "uint256" },
933
+ { name: "extraOptions", type: "bytes" }
934
+ ],
935
+ outputs: [{ name: "guid", type: "bytes32" }],
936
+ stateMutability: "payable"
937
+ },
938
+ {
939
+ type: "function",
940
+ name: "executeRequest",
941
+ inputs: [
942
+ { name: "guid", type: "bytes32" }
943
+ ],
944
+ outputs: [],
945
+ stateMutability: "nonpayable"
946
+ }
947
+ ];
913
948
  var ERC7540_FACET_ABI = [
914
949
  {
915
950
  type: "function",
@@ -996,6 +1031,37 @@ var CURATOR_CONFIG_ABI = [
996
1031
  stateMutability: "view"
997
1032
  }
998
1033
  ];
1034
+ var LZ_ADAPTER_ABI = [
1035
+ {
1036
+ type: "function",
1037
+ name: "quoteBridgeFee",
1038
+ inputs: [
1039
+ { name: "bridgeSpecificParams", type: "bytes" }
1040
+ ],
1041
+ outputs: [{ name: "nativeFee", type: "uint256" }],
1042
+ stateMutability: "view"
1043
+ },
1044
+ {
1045
+ type: "function",
1046
+ name: "quoteReadFee",
1047
+ inputs: [
1048
+ { name: "vaults", type: "address[]" },
1049
+ { name: "eids", type: "uint32[]" },
1050
+ { name: "_extraOptions", type: "bytes" }
1051
+ ],
1052
+ outputs: [
1053
+ {
1054
+ name: "fee",
1055
+ type: "tuple",
1056
+ components: [
1057
+ { name: "nativeFee", type: "uint256" },
1058
+ { name: "lzTokenFee", type: "uint256" }
1059
+ ]
1060
+ }
1061
+ ],
1062
+ stateMutability: "view"
1063
+ }
1064
+ ];
999
1065
  var ERC4626_FACET_ABI = [
1000
1066
  {
1001
1067
  type: "function",
@@ -2460,6 +2526,75 @@ async function vetoActions(walletClient, publicClient, vault, nonces) {
2460
2526
  });
2461
2527
  return { txHash };
2462
2528
  }
2529
+ function encodeBridgeParams(params) {
2530
+ return viem.encodeAbiParameters(
2531
+ [
2532
+ { type: "address" },
2533
+ { type: "uint32" },
2534
+ { type: "uint256" },
2535
+ { type: "address" },
2536
+ { type: "address" }
2537
+ ],
2538
+ [
2539
+ viem.getAddress(params.oftToken),
2540
+ params.dstEid,
2541
+ params.amount,
2542
+ viem.getAddress(params.dstVault),
2543
+ viem.getAddress(params.refundAddress)
2544
+ ]
2545
+ );
2546
+ }
2547
+ function encodeBridgeParamsForQuote(params) {
2548
+ return viem.encodeAbiParameters(
2549
+ [
2550
+ { type: "address" },
2551
+ { type: "uint32" },
2552
+ { type: "uint256" },
2553
+ { type: "address" }
2554
+ ],
2555
+ [
2556
+ viem.getAddress(params.oftToken),
2557
+ params.dstEid,
2558
+ params.amount,
2559
+ viem.getAddress(params.dstVault)
2560
+ ]
2561
+ );
2562
+ }
2563
+ async function quoteCuratorBridgeFee(publicClient, vault, params) {
2564
+ const status = await getCuratorVaultStatus(publicClient, vault);
2565
+ const lzAdapter = status.lzAdapter;
2566
+ const bridgeSpecificParams = encodeBridgeParamsForQuote(params);
2567
+ const nativeFee = await publicClient.readContract({
2568
+ address: lzAdapter,
2569
+ abi: LZ_ADAPTER_ABI,
2570
+ functionName: "quoteBridgeFee",
2571
+ args: [bridgeSpecificParams]
2572
+ });
2573
+ return nativeFee;
2574
+ }
2575
+ async function executeCuratorBridge(walletClient, publicClient, vault, token, params) {
2576
+ const account = walletClient.account;
2577
+ const v = viem.getAddress(vault);
2578
+ const status = await getCuratorVaultStatus(publicClient, vault);
2579
+ const lzAdapter = status.lzAdapter;
2580
+ const fee = await quoteCuratorBridgeFee(publicClient, vault, params);
2581
+ const bridgeSpecificParams = encodeBridgeParams(params);
2582
+ const txHash = await walletClient.writeContract({
2583
+ address: v,
2584
+ abi: BRIDGE_FACET_ABI,
2585
+ functionName: "executeBridging",
2586
+ args: [
2587
+ lzAdapter,
2588
+ viem.getAddress(token),
2589
+ params.amount,
2590
+ bridgeSpecificParams
2591
+ ],
2592
+ value: fee,
2593
+ account,
2594
+ chain: walletClient.chain
2595
+ });
2596
+ return txHash;
2597
+ }
2463
2598
 
2464
2599
  // src/viem/wagmiCompat.ts
2465
2600
  function asSdkClient(client) {
@@ -2920,12 +3055,40 @@ function useVetoActions(vault, chainId) {
2920
3055
  }
2921
3056
  });
2922
3057
  }
3058
+ function useCuratorBridgeQuote(vault, chainId, params) {
3059
+ const publicClient = wagmi.usePublicClient({ chainId });
3060
+ const query = reactQuery.useQuery({
3061
+ queryKey: ["curatorBridgeQuote", vault, chainId, params],
3062
+ queryFn: () => quoteCuratorBridgeFee(asSdkClient(publicClient), vault, params),
3063
+ enabled: !!vault && !!publicClient && !!params,
3064
+ refetchInterval: 6e4,
3065
+ staleTime: 3e4
3066
+ });
3067
+ return {
3068
+ ...query,
3069
+ fee: query.data
3070
+ };
3071
+ }
3072
+ function useExecuteBridge(vault, token, chainId) {
3073
+ const publicClient = wagmi.usePublicClient({ chainId });
3074
+ const { data: walletClient } = wagmi.useWalletClient({ chainId });
3075
+ return reactQuery.useMutation({
3076
+ mutationFn: async (params) => {
3077
+ if (!walletClient || !publicClient) {
3078
+ throw new Error("Wallet or public client not available");
3079
+ }
3080
+ return executeCuratorBridge(walletClient, asSdkClient(publicClient), vault, token, params);
3081
+ }
3082
+ });
3083
+ }
2923
3084
 
2924
3085
  exports.getRouteTokenDecimals = getRouteTokenDecimals;
2925
3086
  exports.useAsyncRequestStatus = useAsyncRequestStatus;
3087
+ exports.useCuratorBridgeQuote = useCuratorBridgeQuote;
2926
3088
  exports.useCuratorVaultStatus = useCuratorVaultStatus;
2927
3089
  exports.useDepositSimple = useDepositSimple;
2928
3090
  exports.useExecuteActions = useExecuteActions;
3091
+ exports.useExecuteBridge = useExecuteBridge;
2929
3092
  exports.useInboundRoutes = useInboundRoutes;
2930
3093
  exports.useIsCurator = useIsCurator;
2931
3094
  exports.useLzFee = useLzFee;