@oydual31/more-vaults-sdk 0.4.2 → 0.6.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.
- package/README.md +94 -0
- package/dist/{spokeRoutes-B8Lnk-t4.d.cts → curatorBridge-CNs59kT9.d.cts} +222 -1
- package/dist/{spokeRoutes-B8Lnk-t4.d.ts → curatorBridge-CNs59kT9.d.ts} +222 -1
- package/dist/ethers/index.cjs +328 -3
- package/dist/ethers/index.cjs.map +1 -1
- package/dist/ethers/index.d.cts +279 -1
- package/dist/ethers/index.d.ts +279 -1
- package/dist/ethers/index.js +318 -5
- package/dist/ethers/index.js.map +1 -1
- package/dist/react/index.cjs +375 -0
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +266 -2
- package/dist/react/index.d.ts +266 -2
- package/dist/react/index.js +372 -2
- package/dist/react/index.js.map +1 -1
- package/dist/viem/index.cjs +377 -0
- package/dist/viem/index.cjs.map +1 -1
- package/dist/viem/index.d.cts +261 -3
- package/dist/viem/index.d.ts +261 -3
- package/dist/viem/index.js +367 -2
- package/dist/viem/index.js.map +1 -1
- package/package.json +1 -1
- package/src/ethers/abis.ts +24 -0
- package/src/ethers/curatorBridge.ts +235 -0
- package/src/ethers/curatorSubVaults.ts +443 -0
- package/src/ethers/index.ts +26 -0
- package/src/ethers/types.ts +99 -0
- package/src/react/index.ts +14 -0
- package/src/react/useCuratorBridgeQuote.ts +43 -0
- package/src/react/useERC7540RequestStatus.ts +43 -0
- package/src/react/useExecuteBridge.ts +50 -0
- package/src/react/useSubVaultPositions.ts +35 -0
- package/src/react/useVaultPortfolio.ts +35 -0
- package/src/viem/abis.ts +24 -0
- package/src/viem/curatorBridge.ts +288 -0
- package/src/viem/curatorSubVaults.ts +514 -0
- package/src/viem/index.ts +23 -0
- package/src/viem/types.ts +100 -0
package/dist/viem/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getAddress, zeroAddress, pad, encodeAbiParameters, encodeFunctionData, createPublicClient, http, fallback } from 'viem';
|
|
1
|
+
import { keccak256, toHex, getAddress, zeroAddress, pad, encodeAbiParameters, encodeFunctionData, createPublicClient, http, fallback } from 'viem';
|
|
2
2
|
|
|
3
3
|
// src/viem/chains.ts
|
|
4
4
|
var CHAIN_IDS = {
|
|
@@ -1126,6 +1126,23 @@ var REGISTRY_ABI = [
|
|
|
1126
1126
|
{ type: "function", name: "isBridgeAllowed", inputs: [{ name: "bridge", type: "address" }], outputs: [{ type: "bool" }], stateMutability: "view" },
|
|
1127
1127
|
{ type: "function", name: "getAllowedFacets", inputs: [], outputs: [{ type: "address[]" }], stateMutability: "view" }
|
|
1128
1128
|
];
|
|
1129
|
+
var SUB_VAULT_ABI = [
|
|
1130
|
+
// ConfigurationFacet reads — called on the MoreVaults diamond proxy
|
|
1131
|
+
{ type: "function", name: "tokensHeld", inputs: [{ name: "id", type: "bytes32" }], outputs: [{ name: "", type: "address[]" }], stateMutability: "view" },
|
|
1132
|
+
{ type: "function", name: "lockedTokensAmountOfAsset", inputs: [{ name: "asset", type: "address" }], outputs: [{ name: "", type: "uint256" }], stateMutability: "view" },
|
|
1133
|
+
// ERC4626 standard reads — called on the sub-vault contract
|
|
1134
|
+
{ type: "function", name: "convertToAssets", inputs: [{ name: "shares", type: "uint256" }], outputs: [{ name: "", type: "uint256" }], stateMutability: "view" },
|
|
1135
|
+
{ type: "function", name: "convertToShares", inputs: [{ name: "assets", type: "uint256" }], outputs: [{ name: "", type: "uint256" }], stateMutability: "view" },
|
|
1136
|
+
{ type: "function", name: "previewDeposit", inputs: [{ name: "assets", type: "uint256" }], outputs: [{ name: "", type: "uint256" }], stateMutability: "view" },
|
|
1137
|
+
{ type: "function", name: "previewRedeem", inputs: [{ name: "shares", type: "uint256" }], outputs: [{ name: "", type: "uint256" }], stateMutability: "view" },
|
|
1138
|
+
{ type: "function", name: "maxDeposit", inputs: [{ name: "receiver", type: "address" }], outputs: [{ name: "", type: "uint256" }], stateMutability: "view" },
|
|
1139
|
+
{ type: "function", name: "maxRedeem", inputs: [{ name: "owner", type: "address" }], outputs: [{ name: "", type: "uint256" }], stateMutability: "view" },
|
|
1140
|
+
// ERC7540 async reads — called on the sub-vault contract
|
|
1141
|
+
{ type: "function", name: "pendingDepositRequest", inputs: [{ name: "requestId", type: "uint256" }, { name: "controller", type: "address" }], outputs: [{ name: "", type: "uint256" }], stateMutability: "view" },
|
|
1142
|
+
{ type: "function", name: "claimableDepositRequest", inputs: [{ name: "requestId", type: "uint256" }, { name: "controller", type: "address" }], outputs: [{ name: "", type: "uint256" }], stateMutability: "view" },
|
|
1143
|
+
{ type: "function", name: "pendingRedeemRequest", inputs: [{ name: "requestId", type: "uint256" }, { name: "controller", type: "address" }], outputs: [{ name: "", type: "uint256" }], stateMutability: "view" },
|
|
1144
|
+
{ type: "function", name: "claimableRedeemRequest", inputs: [{ name: "requestId", type: "uint256" }, { name: "controller", type: "address" }], outputs: [{ name: "", type: "uint256" }], stateMutability: "view" }
|
|
1145
|
+
];
|
|
1129
1146
|
var LZ_ENDPOINT_ABI = [
|
|
1130
1147
|
{
|
|
1131
1148
|
type: "function",
|
|
@@ -3945,6 +3962,354 @@ function buildUniswapV3Swap(params) {
|
|
|
3945
3962
|
}
|
|
3946
3963
|
};
|
|
3947
3964
|
}
|
|
3965
|
+
function encodeBridgeParams(params) {
|
|
3966
|
+
return encodeAbiParameters(
|
|
3967
|
+
[
|
|
3968
|
+
{ type: "address" },
|
|
3969
|
+
{ type: "uint32" },
|
|
3970
|
+
{ type: "uint256" },
|
|
3971
|
+
{ type: "address" },
|
|
3972
|
+
{ type: "address" }
|
|
3973
|
+
],
|
|
3974
|
+
[
|
|
3975
|
+
getAddress(params.oftToken),
|
|
3976
|
+
params.dstEid,
|
|
3977
|
+
params.amount,
|
|
3978
|
+
getAddress(params.dstVault),
|
|
3979
|
+
getAddress(params.refundAddress)
|
|
3980
|
+
]
|
|
3981
|
+
);
|
|
3982
|
+
}
|
|
3983
|
+
function encodeBridgeParamsForQuote(params) {
|
|
3984
|
+
return encodeAbiParameters(
|
|
3985
|
+
[
|
|
3986
|
+
{ type: "address" },
|
|
3987
|
+
{ type: "uint32" },
|
|
3988
|
+
{ type: "uint256" },
|
|
3989
|
+
{ type: "address" }
|
|
3990
|
+
],
|
|
3991
|
+
[
|
|
3992
|
+
getAddress(params.oftToken),
|
|
3993
|
+
params.dstEid,
|
|
3994
|
+
params.amount,
|
|
3995
|
+
getAddress(params.dstVault)
|
|
3996
|
+
]
|
|
3997
|
+
);
|
|
3998
|
+
}
|
|
3999
|
+
function findBridgeRoute(srcChainId, dstChainId, tokenAddress) {
|
|
4000
|
+
const normalizedToken = getAddress(tokenAddress);
|
|
4001
|
+
for (const [symbol, chains] of Object.entries(OFT_ROUTES)) {
|
|
4002
|
+
const srcEntry = chains[srcChainId];
|
|
4003
|
+
const dstEntry = chains[dstChainId];
|
|
4004
|
+
if (!srcEntry || !dstEntry) continue;
|
|
4005
|
+
const srcToken = getAddress(srcEntry.token);
|
|
4006
|
+
const srcOft = getAddress(srcEntry.oft);
|
|
4007
|
+
if (srcToken === normalizedToken || srcOft === normalizedToken) {
|
|
4008
|
+
return {
|
|
4009
|
+
oftSrc: srcOft,
|
|
4010
|
+
oftDst: getAddress(dstEntry.oft),
|
|
4011
|
+
symbol
|
|
4012
|
+
};
|
|
4013
|
+
}
|
|
4014
|
+
}
|
|
4015
|
+
return null;
|
|
4016
|
+
}
|
|
4017
|
+
async function quoteCuratorBridgeFee(publicClient, vault, params) {
|
|
4018
|
+
const status = await getCuratorVaultStatus(publicClient, vault);
|
|
4019
|
+
const lzAdapter = status.lzAdapter;
|
|
4020
|
+
const bridgeSpecificParams = encodeBridgeParamsForQuote(params);
|
|
4021
|
+
const nativeFee = await publicClient.readContract({
|
|
4022
|
+
address: lzAdapter,
|
|
4023
|
+
abi: LZ_ADAPTER_ABI,
|
|
4024
|
+
functionName: "quoteBridgeFee",
|
|
4025
|
+
args: [bridgeSpecificParams]
|
|
4026
|
+
});
|
|
4027
|
+
return nativeFee;
|
|
4028
|
+
}
|
|
4029
|
+
async function executeCuratorBridge(walletClient, publicClient, vault, token, params) {
|
|
4030
|
+
const account = walletClient.account;
|
|
4031
|
+
const v = getAddress(vault);
|
|
4032
|
+
const status = await getCuratorVaultStatus(publicClient, vault);
|
|
4033
|
+
const lzAdapter = status.lzAdapter;
|
|
4034
|
+
const fee = await quoteCuratorBridgeFee(publicClient, vault, params);
|
|
4035
|
+
const bridgeSpecificParams = encodeBridgeParams(params);
|
|
4036
|
+
const txHash = await walletClient.writeContract({
|
|
4037
|
+
address: v,
|
|
4038
|
+
abi: BRIDGE_FACET_ABI,
|
|
4039
|
+
functionName: "executeBridging",
|
|
4040
|
+
args: [
|
|
4041
|
+
lzAdapter,
|
|
4042
|
+
getAddress(token),
|
|
4043
|
+
params.amount,
|
|
4044
|
+
bridgeSpecificParams
|
|
4045
|
+
],
|
|
4046
|
+
value: fee,
|
|
4047
|
+
account,
|
|
4048
|
+
chain: walletClient.chain
|
|
4049
|
+
});
|
|
4050
|
+
return txHash;
|
|
4051
|
+
}
|
|
4052
|
+
var ERC4626_ID = keccak256(toHex("ERC4626_ID"));
|
|
4053
|
+
var ERC7540_ID = keccak256(toHex("ERC7540_ID"));
|
|
4054
|
+
async function getSubVaultPositions(publicClient, vault) {
|
|
4055
|
+
const v = getAddress(vault);
|
|
4056
|
+
const [erc4626Raw, erc7540Raw] = await Promise.all([
|
|
4057
|
+
publicClient.readContract({
|
|
4058
|
+
address: v,
|
|
4059
|
+
abi: SUB_VAULT_ABI,
|
|
4060
|
+
functionName: "tokensHeld",
|
|
4061
|
+
args: [ERC4626_ID]
|
|
4062
|
+
}).catch(() => []),
|
|
4063
|
+
publicClient.readContract({
|
|
4064
|
+
address: v,
|
|
4065
|
+
abi: SUB_VAULT_ABI,
|
|
4066
|
+
functionName: "tokensHeld",
|
|
4067
|
+
args: [ERC7540_ID]
|
|
4068
|
+
}).catch(() => [])
|
|
4069
|
+
]);
|
|
4070
|
+
const erc4626Vaults = erc4626Raw.map(getAddress);
|
|
4071
|
+
const erc7540Vaults = erc7540Raw.map(getAddress);
|
|
4072
|
+
const allSubVaults = [
|
|
4073
|
+
...erc4626Vaults.map((a) => ({ address: a, type: "erc4626" })),
|
|
4074
|
+
...erc7540Vaults.map((a) => ({ address: a, type: "erc7540" }))
|
|
4075
|
+
];
|
|
4076
|
+
if (allSubVaults.length === 0) return [];
|
|
4077
|
+
const PER_SV = 5;
|
|
4078
|
+
const subVaultCalls = allSubVaults.flatMap(({ address: sv }) => [
|
|
4079
|
+
{ address: sv, abi: ERC20_ABI, functionName: "balanceOf", args: [v] },
|
|
4080
|
+
{ address: sv, abi: VAULT_ABI, functionName: "asset" },
|
|
4081
|
+
{ address: sv, abi: METADATA_ABI, functionName: "name" },
|
|
4082
|
+
{ address: sv, abi: METADATA_ABI, functionName: "symbol" },
|
|
4083
|
+
{ address: sv, abi: METADATA_ABI, functionName: "decimals" }
|
|
4084
|
+
]);
|
|
4085
|
+
const subVaultResults = await publicClient.multicall({
|
|
4086
|
+
contracts: subVaultCalls,
|
|
4087
|
+
allowFailure: true
|
|
4088
|
+
});
|
|
4089
|
+
const partials = allSubVaults.map(({ address: sv, type }, i) => {
|
|
4090
|
+
const base = i * PER_SV;
|
|
4091
|
+
const sharesBalance = subVaultResults[base]?.status === "success" ? subVaultResults[base].result : 0n;
|
|
4092
|
+
const underlyingAsset = subVaultResults[base + 1]?.status === "success" ? getAddress(subVaultResults[base + 1].result) : zeroAddress;
|
|
4093
|
+
const name = subVaultResults[base + 2]?.status === "success" ? subVaultResults[base + 2].result : "";
|
|
4094
|
+
const symbol = subVaultResults[base + 3]?.status === "success" ? subVaultResults[base + 3].result : "";
|
|
4095
|
+
const decimals = subVaultResults[base + 4]?.status === "success" ? subVaultResults[base + 4].result : 18;
|
|
4096
|
+
return { address: sv, type, sharesBalance, underlyingAsset, name, symbol, decimals };
|
|
4097
|
+
});
|
|
4098
|
+
const active = partials.filter((p) => p.sharesBalance > 0n);
|
|
4099
|
+
if (active.length === 0) return [];
|
|
4100
|
+
const PER_ACTIVE = 4;
|
|
4101
|
+
const activeCalls = active.flatMap(({ address: sv, sharesBalance, underlyingAsset }) => [
|
|
4102
|
+
{ address: sv, abi: SUB_VAULT_ABI, functionName: "convertToAssets", args: [sharesBalance] },
|
|
4103
|
+
{ address: underlyingAsset, abi: METADATA_ABI, functionName: "name" },
|
|
4104
|
+
{ address: underlyingAsset, abi: METADATA_ABI, functionName: "symbol" },
|
|
4105
|
+
{ address: underlyingAsset, abi: METADATA_ABI, functionName: "decimals" }
|
|
4106
|
+
]);
|
|
4107
|
+
const activeResults = await publicClient.multicall({
|
|
4108
|
+
contracts: activeCalls,
|
|
4109
|
+
allowFailure: true
|
|
4110
|
+
});
|
|
4111
|
+
return active.map((p, i) => {
|
|
4112
|
+
const base = i * PER_ACTIVE;
|
|
4113
|
+
const underlyingValue = activeResults[base]?.status === "success" ? activeResults[base].result : 0n;
|
|
4114
|
+
const underlyingSymbol = activeResults[base + 2]?.status === "success" ? activeResults[base + 2].result : "";
|
|
4115
|
+
const underlyingDecimals = activeResults[base + 3]?.status === "success" ? activeResults[base + 3].result : 18;
|
|
4116
|
+
return {
|
|
4117
|
+
address: p.address,
|
|
4118
|
+
type: p.type,
|
|
4119
|
+
name: p.name,
|
|
4120
|
+
symbol: p.symbol,
|
|
4121
|
+
decimals: p.decimals,
|
|
4122
|
+
sharesBalance: p.sharesBalance,
|
|
4123
|
+
underlyingValue,
|
|
4124
|
+
underlyingAsset: p.underlyingAsset,
|
|
4125
|
+
underlyingSymbol,
|
|
4126
|
+
underlyingDecimals
|
|
4127
|
+
};
|
|
4128
|
+
});
|
|
4129
|
+
}
|
|
4130
|
+
async function detectSubVaultType(publicClient, subVault) {
|
|
4131
|
+
const sv = getAddress(subVault);
|
|
4132
|
+
const [erc7540Result, erc4626Result] = await publicClient.multicall({
|
|
4133
|
+
contracts: [
|
|
4134
|
+
{
|
|
4135
|
+
address: sv,
|
|
4136
|
+
abi: SUB_VAULT_ABI,
|
|
4137
|
+
functionName: "pendingDepositRequest",
|
|
4138
|
+
args: [0n, zeroAddress]
|
|
4139
|
+
},
|
|
4140
|
+
{
|
|
4141
|
+
address: sv,
|
|
4142
|
+
abi: SUB_VAULT_ABI,
|
|
4143
|
+
functionName: "convertToAssets",
|
|
4144
|
+
args: [0n]
|
|
4145
|
+
}
|
|
4146
|
+
],
|
|
4147
|
+
allowFailure: true
|
|
4148
|
+
});
|
|
4149
|
+
if (erc7540Result?.status === "success") return "erc7540";
|
|
4150
|
+
if (erc4626Result?.status === "success") return "erc4626";
|
|
4151
|
+
return null;
|
|
4152
|
+
}
|
|
4153
|
+
async function getSubVaultInfo(publicClient, vault, subVault) {
|
|
4154
|
+
const v = getAddress(vault);
|
|
4155
|
+
const sv = getAddress(subVault);
|
|
4156
|
+
const [type, basicResults] = await Promise.all([
|
|
4157
|
+
detectSubVaultType(publicClient, sv),
|
|
4158
|
+
publicClient.multicall({
|
|
4159
|
+
contracts: [
|
|
4160
|
+
{ address: sv, abi: METADATA_ABI, functionName: "name" },
|
|
4161
|
+
{ address: sv, abi: METADATA_ABI, functionName: "symbol" },
|
|
4162
|
+
{ address: sv, abi: METADATA_ABI, functionName: "decimals" },
|
|
4163
|
+
{ address: sv, abi: VAULT_ABI, functionName: "asset" },
|
|
4164
|
+
{ address: sv, abi: SUB_VAULT_ABI, functionName: "maxDeposit", args: [v] }
|
|
4165
|
+
],
|
|
4166
|
+
allowFailure: true
|
|
4167
|
+
})
|
|
4168
|
+
]);
|
|
4169
|
+
const name = basicResults[0]?.status === "success" ? basicResults[0].result : "";
|
|
4170
|
+
const symbol = basicResults[1]?.status === "success" ? basicResults[1].result : "";
|
|
4171
|
+
const decimals = basicResults[2]?.status === "success" ? basicResults[2].result : 18;
|
|
4172
|
+
const underlying = basicResults[3]?.status === "success" ? getAddress(basicResults[3].result) : zeroAddress;
|
|
4173
|
+
const maxDeposit = basicResults[4]?.status === "success" ? basicResults[4].result : 0n;
|
|
4174
|
+
const [underlyingResults, registryRaw] = await Promise.all([
|
|
4175
|
+
publicClient.multicall({
|
|
4176
|
+
contracts: [
|
|
4177
|
+
{ address: underlying, abi: METADATA_ABI, functionName: "name" },
|
|
4178
|
+
{ address: underlying, abi: METADATA_ABI, functionName: "symbol" },
|
|
4179
|
+
{ address: underlying, abi: METADATA_ABI, functionName: "decimals" }
|
|
4180
|
+
],
|
|
4181
|
+
allowFailure: true
|
|
4182
|
+
}),
|
|
4183
|
+
publicClient.readContract({ address: v, abi: VAULT_ANALYSIS_ABI, functionName: "moreVaultsRegistry" }).catch(() => null)
|
|
4184
|
+
]);
|
|
4185
|
+
const underlyingSymbol = underlyingResults[1]?.status === "success" ? underlyingResults[1].result : "";
|
|
4186
|
+
const underlyingDecimals = underlyingResults[2]?.status === "success" ? underlyingResults[2].result : 18;
|
|
4187
|
+
let isWhitelisted = false;
|
|
4188
|
+
if (registryRaw) {
|
|
4189
|
+
const registry = getAddress(registryRaw);
|
|
4190
|
+
const whitelistResult = await publicClient.readContract({
|
|
4191
|
+
address: registry,
|
|
4192
|
+
abi: REGISTRY_ABI,
|
|
4193
|
+
functionName: "isWhitelisted",
|
|
4194
|
+
args: [sv]
|
|
4195
|
+
}).catch(() => false);
|
|
4196
|
+
isWhitelisted = whitelistResult;
|
|
4197
|
+
}
|
|
4198
|
+
return {
|
|
4199
|
+
address: sv,
|
|
4200
|
+
type: type ?? "erc4626",
|
|
4201
|
+
name,
|
|
4202
|
+
symbol,
|
|
4203
|
+
decimals,
|
|
4204
|
+
underlyingAsset: underlying,
|
|
4205
|
+
underlyingSymbol,
|
|
4206
|
+
underlyingDecimals,
|
|
4207
|
+
maxDeposit,
|
|
4208
|
+
isWhitelisted
|
|
4209
|
+
};
|
|
4210
|
+
}
|
|
4211
|
+
async function getERC7540RequestStatus(publicClient, vault, subVault) {
|
|
4212
|
+
const v = getAddress(vault);
|
|
4213
|
+
const sv = getAddress(subVault);
|
|
4214
|
+
const results = await publicClient.multicall({
|
|
4215
|
+
contracts: [
|
|
4216
|
+
{ address: sv, abi: SUB_VAULT_ABI, functionName: "pendingDepositRequest", args: [0n, v] },
|
|
4217
|
+
{ address: sv, abi: SUB_VAULT_ABI, functionName: "claimableDepositRequest", args: [0n, v] },
|
|
4218
|
+
{ address: sv, abi: SUB_VAULT_ABI, functionName: "pendingRedeemRequest", args: [0n, v] },
|
|
4219
|
+
{ address: sv, abi: SUB_VAULT_ABI, functionName: "claimableRedeemRequest", args: [0n, v] }
|
|
4220
|
+
],
|
|
4221
|
+
allowFailure: true
|
|
4222
|
+
});
|
|
4223
|
+
const pendingDeposit = results[0]?.status === "success" ? results[0].result : 0n;
|
|
4224
|
+
const claimableDeposit = results[1]?.status === "success" ? results[1].result : 0n;
|
|
4225
|
+
const pendingRedeem = results[2]?.status === "success" ? results[2].result : 0n;
|
|
4226
|
+
const claimableRedeem = results[3]?.status === "success" ? results[3].result : 0n;
|
|
4227
|
+
return {
|
|
4228
|
+
subVault: sv,
|
|
4229
|
+
pendingDeposit,
|
|
4230
|
+
claimableDeposit,
|
|
4231
|
+
pendingRedeem,
|
|
4232
|
+
claimableRedeem,
|
|
4233
|
+
canFinalizeDeposit: claimableDeposit > 0n,
|
|
4234
|
+
canFinalizeRedeem: claimableRedeem > 0n
|
|
4235
|
+
};
|
|
4236
|
+
}
|
|
4237
|
+
async function previewSubVaultDeposit(publicClient, subVault, assets) {
|
|
4238
|
+
const result = await publicClient.readContract({
|
|
4239
|
+
address: getAddress(subVault),
|
|
4240
|
+
abi: SUB_VAULT_ABI,
|
|
4241
|
+
functionName: "previewDeposit",
|
|
4242
|
+
args: [assets]
|
|
4243
|
+
});
|
|
4244
|
+
return result;
|
|
4245
|
+
}
|
|
4246
|
+
async function previewSubVaultRedeem(publicClient, subVault, shares) {
|
|
4247
|
+
const result = await publicClient.readContract({
|
|
4248
|
+
address: getAddress(subVault),
|
|
4249
|
+
abi: SUB_VAULT_ABI,
|
|
4250
|
+
functionName: "previewRedeem",
|
|
4251
|
+
args: [shares]
|
|
4252
|
+
});
|
|
4253
|
+
return result;
|
|
4254
|
+
}
|
|
4255
|
+
async function getVaultPortfolio(publicClient, vault) {
|
|
4256
|
+
const v = getAddress(vault);
|
|
4257
|
+
const [availableRaw, subVaultPositions, vaultTotals] = await Promise.all([
|
|
4258
|
+
publicClient.readContract({ address: v, abi: VAULT_ANALYSIS_ABI, functionName: "getAvailableAssets" }).catch(() => []),
|
|
4259
|
+
getSubVaultPositions(publicClient, v),
|
|
4260
|
+
publicClient.multicall({
|
|
4261
|
+
contracts: [
|
|
4262
|
+
{ address: v, abi: VAULT_ABI, functionName: "totalAssets" },
|
|
4263
|
+
{ address: v, abi: VAULT_ABI, functionName: "totalSupply" },
|
|
4264
|
+
{ address: v, abi: VAULT_ABI, functionName: "asset" }
|
|
4265
|
+
],
|
|
4266
|
+
allowFailure: true
|
|
4267
|
+
})
|
|
4268
|
+
]);
|
|
4269
|
+
const totalAssets = vaultTotals[0]?.status === "success" ? vaultTotals[0].result : 0n;
|
|
4270
|
+
const totalSupply = vaultTotals[1]?.status === "success" ? vaultTotals[1].result : 0n;
|
|
4271
|
+
const underlyingAsset = vaultTotals[2]?.status === "success" ? getAddress(vaultTotals[2].result) : zeroAddress;
|
|
4272
|
+
const availableAddresses = availableRaw.map(getAddress);
|
|
4273
|
+
const subVaultAddressSet = new Set(subVaultPositions.map((p) => p.address.toLowerCase()));
|
|
4274
|
+
const liquidAddresses = availableAddresses.filter(
|
|
4275
|
+
(addr) => !subVaultAddressSet.has(addr.toLowerCase())
|
|
4276
|
+
);
|
|
4277
|
+
const PER_ASSET = 4;
|
|
4278
|
+
const liquidCalls = liquidAddresses.flatMap((addr) => [
|
|
4279
|
+
{ address: addr, abi: ERC20_ABI, functionName: "balanceOf", args: [v] },
|
|
4280
|
+
{ address: addr, abi: METADATA_ABI, functionName: "name" },
|
|
4281
|
+
{ address: addr, abi: METADATA_ABI, functionName: "symbol" },
|
|
4282
|
+
{ address: addr, abi: METADATA_ABI, functionName: "decimals" }
|
|
4283
|
+
]);
|
|
4284
|
+
const liquidResults = liquidAddresses.length > 0 ? await publicClient.multicall({ contracts: liquidCalls, allowFailure: true }) : [];
|
|
4285
|
+
const liquidAssets = liquidAddresses.map((addr, i) => {
|
|
4286
|
+
const base = i * PER_ASSET;
|
|
4287
|
+
const balance = liquidResults[base]?.status === "success" ? liquidResults[base].result : 0n;
|
|
4288
|
+
const name = liquidResults[base + 1]?.status === "success" ? liquidResults[base + 1].result : "";
|
|
4289
|
+
const symbol = liquidResults[base + 2]?.status === "success" ? liquidResults[base + 2].result : "";
|
|
4290
|
+
const decimals = liquidResults[base + 3]?.status === "success" ? liquidResults[base + 3].result : 18;
|
|
4291
|
+
return { address: addr, name, symbol, decimals, balance };
|
|
4292
|
+
});
|
|
4293
|
+
const lockedAssets = await publicClient.readContract({
|
|
4294
|
+
address: v,
|
|
4295
|
+
abi: SUB_VAULT_ABI,
|
|
4296
|
+
functionName: "lockedTokensAmountOfAsset",
|
|
4297
|
+
args: [underlyingAsset]
|
|
4298
|
+
}).catch(() => 0n);
|
|
4299
|
+
const subVaultTotal = subVaultPositions.reduce((sum, p) => sum + p.underlyingValue, 0n);
|
|
4300
|
+
const underlyingBalance = liquidAssets.find(
|
|
4301
|
+
(a) => a.address.toLowerCase() === underlyingAsset.toLowerCase()
|
|
4302
|
+
)?.balance ?? 0n;
|
|
4303
|
+
const totalValue = underlyingBalance + subVaultTotal;
|
|
4304
|
+
return {
|
|
4305
|
+
liquidAssets,
|
|
4306
|
+
subVaultPositions,
|
|
4307
|
+
totalValue,
|
|
4308
|
+
totalAssets,
|
|
4309
|
+
totalSupply,
|
|
4310
|
+
lockedAssets
|
|
4311
|
+
};
|
|
4312
|
+
}
|
|
3948
4313
|
|
|
3949
4314
|
// src/viem/wagmiCompat.ts
|
|
3950
4315
|
function asSdkClient(client) {
|
|
@@ -3952,6 +4317,6 @@ function asSdkClient(client) {
|
|
|
3952
4317
|
return client;
|
|
3953
4318
|
}
|
|
3954
4319
|
|
|
3955
|
-
export { ActionType, BRIDGE_ABI, BRIDGE_FACET_ABI, CCManagerNotConfiguredError, CHAIN_IDS, CHAIN_ID_TO_EID, CONFIG_ABI, CURATOR_CONFIG_ABI, CapacityFullError, DEX_ABI, EID_TO_CHAIN_ID, ERC20_ABI, ERC4626_FACET_ABI, ERC7540_FACET_ABI, EscrowNotConfiguredError, InsufficientLiquidityError, LZ_ADAPTER_ABI, LZ_EIDS, LZ_ENDPOINT_ABI, LZ_TIMEOUTS, METADATA_ABI, MULTICALL_ABI, MissingEscrowAddressError, MoreVaultsError, NATIVE_SYMBOL, NotHubVaultError, NotWhitelistedError, OFT_ABI, OFT_ROUTES, OMNI_FACTORY_ADDRESS, REGISTRY_ABI, STARGATE_TAXI_CMD, UNISWAP_V3_ROUTERS, USDC_STARGATE_OFT, USDC_TOKEN, VAULT_ABI, VAULT_ANALYSIS_ABI, VaultPausedError, WrongChainError, asSdkClient, bridgeAssetsToSpoke, bridgeSharesToHub, buildCuratorBatch, buildUniswapV3Swap, canDeposit, checkProtocolWhitelist, depositAsync, depositSimple as depositCrossChainOracleOn, depositFromSpoke, depositFromSpoke as depositFromSpokeAsync, depositMultiAsset, depositSimple, detectStargateOft, discoverVaultTopology, encodeCuratorAction, encodeUniswapV3SwapCalldata, ensureAllowance, executeActions, executeCompose, getAllVaultChainIds, getAsyncRequestStatus, getAsyncRequestStatusLabel, getCuratorVaultStatus, getFullVaultTopology, getInboundRoutes, getMaxWithdrawable, getOutboundRoutes, getPendingActions, getUserBalances, getUserBalancesForRoutes, getUserPosition, getUserPositionMultiChain, getVaultAnalysis, getVaultAssetBreakdown, getVaultDistribution, getVaultDistributionWithTopology, getVaultMetadata, getVaultStatus, getVaultSummary, getVaultTopology, getWithdrawalRequest, isAsyncMode, isCurator, isOnHubChain, mintAsync, preflightAsync, preflightRedeemLiquidity, preflightSpokeDeposit, preflightSpokeRedeem, preflightSync, previewDeposit, previewRedeem, quoteComposeFee, quoteDepositFromSpokeFee, quoteLzFee, quoteRouteDepositFee, quoteShareBridgeFee, redeemAsync, redeemShares, requestRedeem, resolveRedeemAddresses, smartDeposit, smartRedeem, submitActions, vetoActions, waitForAsyncRequest, waitForCompose, waitForTx, withdrawAssets };
|
|
4320
|
+
export { ActionType, BRIDGE_ABI, BRIDGE_FACET_ABI, CCManagerNotConfiguredError, CHAIN_IDS, CHAIN_ID_TO_EID, CONFIG_ABI, CURATOR_CONFIG_ABI, CapacityFullError, DEX_ABI, EID_TO_CHAIN_ID, ERC20_ABI, ERC4626_FACET_ABI, ERC7540_FACET_ABI, EscrowNotConfiguredError, InsufficientLiquidityError, LZ_ADAPTER_ABI, LZ_EIDS, LZ_ENDPOINT_ABI, LZ_TIMEOUTS, METADATA_ABI, MULTICALL_ABI, MissingEscrowAddressError, MoreVaultsError, NATIVE_SYMBOL, NotHubVaultError, NotWhitelistedError, OFT_ABI, OFT_ROUTES, OMNI_FACTORY_ADDRESS, REGISTRY_ABI, STARGATE_TAXI_CMD, SUB_VAULT_ABI, UNISWAP_V3_ROUTERS, USDC_STARGATE_OFT, USDC_TOKEN, VAULT_ABI, VAULT_ANALYSIS_ABI, VaultPausedError, WrongChainError, asSdkClient, bridgeAssetsToSpoke, bridgeSharesToHub, buildCuratorBatch, buildUniswapV3Swap, canDeposit, checkProtocolWhitelist, depositAsync, depositSimple as depositCrossChainOracleOn, depositFromSpoke, depositFromSpoke as depositFromSpokeAsync, depositMultiAsset, depositSimple, detectStargateOft, detectSubVaultType, discoverVaultTopology, encodeBridgeParams, encodeCuratorAction, encodeUniswapV3SwapCalldata, ensureAllowance, executeActions, executeCompose, executeCuratorBridge, findBridgeRoute, getAllVaultChainIds, getAsyncRequestStatus, getAsyncRequestStatusLabel, getCuratorVaultStatus, getERC7540RequestStatus, getFullVaultTopology, getInboundRoutes, getMaxWithdrawable, getOutboundRoutes, getPendingActions, getSubVaultInfo, getSubVaultPositions, getUserBalances, getUserBalancesForRoutes, getUserPosition, getUserPositionMultiChain, getVaultAnalysis, getVaultAssetBreakdown, getVaultDistribution, getVaultDistributionWithTopology, getVaultMetadata, getVaultPortfolio, getVaultStatus, getVaultSummary, getVaultTopology, getWithdrawalRequest, isAsyncMode, isCurator, isOnHubChain, mintAsync, preflightAsync, preflightRedeemLiquidity, preflightSpokeDeposit, preflightSpokeRedeem, preflightSync, previewDeposit, previewRedeem, previewSubVaultDeposit, previewSubVaultRedeem, quoteComposeFee, quoteCuratorBridgeFee, quoteDepositFromSpokeFee, quoteLzFee, quoteRouteDepositFee, quoteShareBridgeFee, redeemAsync, redeemShares, requestRedeem, resolveRedeemAddresses, smartDeposit, smartRedeem, submitActions, vetoActions, waitForAsyncRequest, waitForCompose, waitForTx, withdrawAssets };
|
|
3956
4321
|
//# sourceMappingURL=index.js.map
|
|
3957
4322
|
//# sourceMappingURL=index.js.map
|