@oydual31/more-vaults-sdk 0.3.2 → 0.3.3
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/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/{spokeRoutes-DK7cIW4z.d.cts → spokeRoutes-BIafSbQ3.d.cts} +13 -2
- package/dist/{spokeRoutes-DK7cIW4z.d.ts → spokeRoutes-BIafSbQ3.d.ts} +13 -2
- package/dist/viem/index.cjs +34 -28
- package/dist/viem/index.cjs.map +1 -1
- package/dist/viem/index.d.cts +1 -1
- package/dist/viem/index.d.ts +1 -1
- package/dist/viem/index.js +34 -29
- package/dist/viem/index.js.map +1 -1
- package/package.json +1 -1
- package/src/viem/crossChainFlows.ts +12 -22
- package/src/viem/index.ts +1 -0
- package/src/viem/preflight.ts +3 -9
- package/src/viem/redeemFlows.ts +4 -5
- package/src/viem/utils.ts +40 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Address,
|
|
1
|
+
import { Address, PublicClient, WalletClient, Hash } from 'viem';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Wait for a transaction receipt with generous timeout and retry logic.
|
|
@@ -193,6 +193,17 @@ declare function waitForAsyncRequest(publicClient: PublicClient, vault: Address,
|
|
|
193
193
|
refunded: boolean;
|
|
194
194
|
result: bigint;
|
|
195
195
|
}) => void): Promise<AsyncRequestFinalResult>;
|
|
196
|
+
/**
|
|
197
|
+
* Detect whether an OFT address is a Stargate V2 pool by calling `stargateType()`.
|
|
198
|
+
*
|
|
199
|
+
* Stargate pools implement this function (returns 0=Pool, 1=OFT).
|
|
200
|
+
* Standard OFTs revert because they don't have it.
|
|
201
|
+
*
|
|
202
|
+
* @param publicClient Viem public client on the OFT's chain
|
|
203
|
+
* @param oft OFT contract address
|
|
204
|
+
* @returns true if the contract is a Stargate V2 pool/OFT
|
|
205
|
+
*/
|
|
206
|
+
declare function detectStargateOft(publicClient: PublicClient, oft: Address): Promise<boolean>;
|
|
196
207
|
|
|
197
208
|
interface UserPosition {
|
|
198
209
|
/** Vault share balance */
|
|
@@ -618,4 +629,4 @@ declare function getOutboundRoutes(hubChainId: number, vault: Address): Promise<
|
|
|
618
629
|
*/
|
|
619
630
|
declare function quoteRouteDepositFee(route: InboundRoute, hubChainId: number, amount: bigint, userAddress: Address): Promise<bigint>;
|
|
620
631
|
|
|
621
|
-
export { type AsyncRequestFinalResult as A,
|
|
632
|
+
export { type AsyncRequestFinalResult as A, getUserPositionMultiChain as B, getVaultDistribution as C, type DepositBlockReason as D, getVaultDistributionWithTopology as E, getVaultMetadata as F, getVaultStatus as G, getVaultSummary as H, type InboundRoute as I, getVaultTopology as J, isAsyncMode as K, isOnHubChain as L, type MaxWithdrawable as M, NATIVE_SYMBOL as N, OMNI_FACTORY_ADDRESS as O, previewDeposit as P, previewRedeem as Q, quoteLzFee as R, type SpokeBalance as S, quoteRouteDepositFee as T, type UserBalances as U, type VaultDistribution as V, waitForAsyncRequest as W, waitForTx as X, type AsyncRequestStatus as a, type AsyncRequestStatusInfo as b, type DepositEligibility as c, type InboundRouteWithBalance as d, type MultiChainUserPosition as e, type OutboundRoute as f, type UserPosition as g, type VaultMetadata as h, type VaultMode as i, type VaultStatus as j, type VaultSummary as k, type VaultTopology as l, canDeposit as m, detectStargateOft as n, discoverVaultTopology as o, ensureAllowance as p, getAllVaultChainIds as q, getAsyncRequestStatus as r, getAsyncRequestStatusLabel as s, getFullVaultTopology as t, getInboundRoutes as u, getMaxWithdrawable as v, getOutboundRoutes as w, getUserBalances as x, getUserBalancesForRoutes as y, getUserPosition as z };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Address,
|
|
1
|
+
import { Address, PublicClient, WalletClient, Hash } from 'viem';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Wait for a transaction receipt with generous timeout and retry logic.
|
|
@@ -193,6 +193,17 @@ declare function waitForAsyncRequest(publicClient: PublicClient, vault: Address,
|
|
|
193
193
|
refunded: boolean;
|
|
194
194
|
result: bigint;
|
|
195
195
|
}) => void): Promise<AsyncRequestFinalResult>;
|
|
196
|
+
/**
|
|
197
|
+
* Detect whether an OFT address is a Stargate V2 pool by calling `stargateType()`.
|
|
198
|
+
*
|
|
199
|
+
* Stargate pools implement this function (returns 0=Pool, 1=OFT).
|
|
200
|
+
* Standard OFTs revert because they don't have it.
|
|
201
|
+
*
|
|
202
|
+
* @param publicClient Viem public client on the OFT's chain
|
|
203
|
+
* @param oft OFT contract address
|
|
204
|
+
* @returns true if the contract is a Stargate V2 pool/OFT
|
|
205
|
+
*/
|
|
206
|
+
declare function detectStargateOft(publicClient: PublicClient, oft: Address): Promise<boolean>;
|
|
196
207
|
|
|
197
208
|
interface UserPosition {
|
|
198
209
|
/** Vault share balance */
|
|
@@ -618,4 +629,4 @@ declare function getOutboundRoutes(hubChainId: number, vault: Address): Promise<
|
|
|
618
629
|
*/
|
|
619
630
|
declare function quoteRouteDepositFee(route: InboundRoute, hubChainId: number, amount: bigint, userAddress: Address): Promise<bigint>;
|
|
620
631
|
|
|
621
|
-
export { type AsyncRequestFinalResult as A,
|
|
632
|
+
export { type AsyncRequestFinalResult as A, getUserPositionMultiChain as B, getVaultDistribution as C, type DepositBlockReason as D, getVaultDistributionWithTopology as E, getVaultMetadata as F, getVaultStatus as G, getVaultSummary as H, type InboundRoute as I, getVaultTopology as J, isAsyncMode as K, isOnHubChain as L, type MaxWithdrawable as M, NATIVE_SYMBOL as N, OMNI_FACTORY_ADDRESS as O, previewDeposit as P, previewRedeem as Q, quoteLzFee as R, type SpokeBalance as S, quoteRouteDepositFee as T, type UserBalances as U, type VaultDistribution as V, waitForAsyncRequest as W, waitForTx as X, type AsyncRequestStatus as a, type AsyncRequestStatusInfo as b, type DepositEligibility as c, type InboundRouteWithBalance as d, type MultiChainUserPosition as e, type OutboundRoute as f, type UserPosition as g, type VaultMetadata as h, type VaultMode as i, type VaultStatus as j, type VaultSummary as k, type VaultTopology as l, canDeposit as m, detectStargateOft as n, discoverVaultTopology as o, ensureAllowance as p, getAllVaultChainIds as q, getAsyncRequestStatus as r, getAsyncRequestStatusLabel as s, getFullVaultTopology as t, getInboundRoutes as u, getMaxWithdrawable as v, getOutboundRoutes as w, getUserBalances as x, getUserBalancesForRoutes as y, getUserPosition as z };
|
package/dist/viem/index.cjs
CHANGED
|
@@ -1470,6 +1470,27 @@ async function waitForAsyncRequest(publicClient, vault, guid, pollInterval = 3e4
|
|
|
1470
1470
|
`[MoreVaults] Async request ${guid} did not finalize within ${timeout / 1e3}s. The request may still complete \u2014 check https://layerzeroscan.com/tx/${guid}`
|
|
1471
1471
|
);
|
|
1472
1472
|
}
|
|
1473
|
+
var STARGATE_TYPE_ABI = [
|
|
1474
|
+
{
|
|
1475
|
+
type: "function",
|
|
1476
|
+
name: "stargateType",
|
|
1477
|
+
inputs: [],
|
|
1478
|
+
outputs: [{ type: "uint8" }],
|
|
1479
|
+
stateMutability: "view"
|
|
1480
|
+
}
|
|
1481
|
+
];
|
|
1482
|
+
async function detectStargateOft(publicClient, oft) {
|
|
1483
|
+
try {
|
|
1484
|
+
await publicClient.readContract({
|
|
1485
|
+
address: viem.getAddress(oft),
|
|
1486
|
+
abi: STARGATE_TYPE_ABI,
|
|
1487
|
+
functionName: "stargateType"
|
|
1488
|
+
});
|
|
1489
|
+
return true;
|
|
1490
|
+
} catch {
|
|
1491
|
+
return false;
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1473
1494
|
var PUBLIC_RPCS = {
|
|
1474
1495
|
1: [
|
|
1475
1496
|
"https://ethereum-rpc.publicnode.com",
|
|
@@ -1868,21 +1889,11 @@ var COMPOSER_ABI = [
|
|
|
1868
1889
|
stateMutability: "view"
|
|
1869
1890
|
}
|
|
1870
1891
|
];
|
|
1871
|
-
var STARGATE_ASSETS = /* @__PURE__ */ new Set(["stgUSDC", "USDT", "WETH"]);
|
|
1872
1892
|
function buildLzComposeOption(gas, nativeValue) {
|
|
1873
1893
|
const gasHex = gas.toString(16).padStart(32, "0");
|
|
1874
1894
|
const valueHex = nativeValue.toString(16).padStart(32, "0");
|
|
1875
1895
|
return `0x00030300220000${gasHex}${valueHex}`;
|
|
1876
1896
|
}
|
|
1877
|
-
function isStargateOft(oft) {
|
|
1878
|
-
for (const [symbol, chainMap] of Object.entries(OFT_ROUTES)) {
|
|
1879
|
-
if (!STARGATE_ASSETS.has(symbol)) continue;
|
|
1880
|
-
for (const entry of Object.values(chainMap)) {
|
|
1881
|
-
if (viem.getAddress(entry.oft) === oft) return true;
|
|
1882
|
-
}
|
|
1883
|
-
}
|
|
1884
|
-
return false;
|
|
1885
|
-
}
|
|
1886
1897
|
async function resolveComposeNativeValue(hubClient, vault, composerAddress, spokeEid, receiverBytes32) {
|
|
1887
1898
|
const [readFeeResult, shareOftResult] = await Promise.allSettled([
|
|
1888
1899
|
hubClient.readContract({
|
|
@@ -1946,7 +1957,7 @@ async function depositFromSpoke(walletClient, publicClient, vault, spokeOFT, hub
|
|
|
1946
1957
|
if (composerAddress === viem.zeroAddress) throw new Error(`No composer registered for vault ${vault} on hub chainId ${hubChainId}`);
|
|
1947
1958
|
const composerBytes32 = viem.pad(composerAddress, { size: 32 });
|
|
1948
1959
|
const receiverBytes32 = viem.pad(viem.getAddress(receiver), { size: 32 });
|
|
1949
|
-
const isStargate =
|
|
1960
|
+
const isStargate = await detectStargateOft(publicClient, oft);
|
|
1950
1961
|
let resolvedExtraOptions;
|
|
1951
1962
|
if (extraOptions !== "0x") {
|
|
1952
1963
|
resolvedExtraOptions = extraOptions;
|
|
@@ -2043,7 +2054,7 @@ async function depositFromSpoke(walletClient, publicClient, vault, spokeOFT, hub
|
|
|
2043
2054
|
account,
|
|
2044
2055
|
chain: walletClient.chain
|
|
2045
2056
|
});
|
|
2046
|
-
const stargate =
|
|
2057
|
+
const stargate = isStargate;
|
|
2047
2058
|
let composeData;
|
|
2048
2059
|
if (stargate) {
|
|
2049
2060
|
const hubBlockStart = await hubClient.getBlockNumber();
|
|
@@ -2077,7 +2088,7 @@ async function quoteDepositFromSpokeFee(publicClient, vault, spokeOFT, hubEid, s
|
|
|
2077
2088
|
args: [viem.getAddress(vault)]
|
|
2078
2089
|
});
|
|
2079
2090
|
const composerBytes32 = viem.pad(composerAddress, { size: 32 });
|
|
2080
|
-
const isStargate =
|
|
2091
|
+
const isStargate = await detectStargateOft(publicClient, oft);
|
|
2081
2092
|
let resolvedExtraOptions;
|
|
2082
2093
|
if (extraOptions !== "0x") {
|
|
2083
2094
|
resolvedExtraOptions = extraOptions;
|
|
@@ -2146,13 +2157,16 @@ async function waitForCompose(hubPublicClient, composeData, receiver, pollInterv
|
|
|
2146
2157
|
const endpoint = viem.getAddress(composeData.endpoint);
|
|
2147
2158
|
const receiverNeedle = viem.getAddress(receiver).slice(2).toLowerCase();
|
|
2148
2159
|
const startBlock = composeData.hubBlockStart;
|
|
2149
|
-
const knownFromAddresses = [];
|
|
2150
2160
|
const hubChainId = composeData.hubChainId;
|
|
2151
|
-
|
|
2152
|
-
|
|
2161
|
+
const candidateAddresses = [];
|
|
2162
|
+
for (const chainMap of Object.values(OFT_ROUTES)) {
|
|
2153
2163
|
const entry = chainMap[hubChainId];
|
|
2154
|
-
if (entry)
|
|
2164
|
+
if (entry) candidateAddresses.push(viem.getAddress(entry.oft));
|
|
2155
2165
|
}
|
|
2166
|
+
const stargateChecks = await Promise.all(
|
|
2167
|
+
candidateAddresses.map(async (addr) => ({ addr, isSg: await detectStargateOft(hubPublicClient, addr) }))
|
|
2168
|
+
);
|
|
2169
|
+
const knownFromAddresses = stargateChecks.filter((c) => c.isSg).map((c) => c.addr);
|
|
2156
2170
|
let attempt = 0;
|
|
2157
2171
|
let scannedUpTo = startBlock - 1n;
|
|
2158
2172
|
while (Date.now() < deadline) {
|
|
@@ -2485,14 +2499,7 @@ async function preflightSpokeDeposit(spokePublicClient, vault, spokeOFT, hubEid,
|
|
|
2485
2499
|
Have: ${spokeNativeBalance} wei`
|
|
2486
2500
|
);
|
|
2487
2501
|
}
|
|
2488
|
-
const
|
|
2489
|
-
let isStargate = false;
|
|
2490
|
-
for (const [symbol, chainMap] of Object.entries(OFT_ROUTES)) {
|
|
2491
|
-
if (!STARGATE_ASSETS3.has(symbol)) continue;
|
|
2492
|
-
for (const entry of Object.values(chainMap)) {
|
|
2493
|
-
if (viem.getAddress(entry.oft) === oft) isStargate = true;
|
|
2494
|
-
}
|
|
2495
|
-
}
|
|
2502
|
+
const isStargate = await detectStargateOft(spokePublicClient, oft);
|
|
2496
2503
|
let hubNativeBalance = 0n;
|
|
2497
2504
|
let estimatedComposeFee = 0n;
|
|
2498
2505
|
if (isStargate) {
|
|
@@ -2994,7 +3001,6 @@ async function bridgeAssetsToSpoke(walletClient, publicClient, assetOFT, spokeCh
|
|
|
2994
3001
|
});
|
|
2995
3002
|
return { txHash };
|
|
2996
3003
|
}
|
|
2997
|
-
var STARGATE_ASSETS2 = /* @__PURE__ */ new Set(["stgUSDC", "USDT", "WETH"]);
|
|
2998
3004
|
var FACTORY_COMPOSER_ABI2 = [
|
|
2999
3005
|
{
|
|
3000
3006
|
type: "function",
|
|
@@ -3044,7 +3050,6 @@ async function resolveRedeemAddresses(hubPublicClient, vault, hubChainId, spokeC
|
|
|
3044
3050
|
const spokeShareOft = viem.getAddress(`0x${spokeShareOftBytes32.slice(-40)}`);
|
|
3045
3051
|
let hubAssetOft = null;
|
|
3046
3052
|
let spokeAsset = null;
|
|
3047
|
-
let isStargate = false;
|
|
3048
3053
|
let symbol = "";
|
|
3049
3054
|
for (const [sym, chainMap] of Object.entries(OFT_ROUTES)) {
|
|
3050
3055
|
const hubEntry = chainMap[hubChainId];
|
|
@@ -3053,7 +3058,6 @@ async function resolveRedeemAddresses(hubPublicClient, vault, hubChainId, spokeC
|
|
|
3053
3058
|
if (viem.getAddress(hubEntry.token) === viem.getAddress(hubAsset)) {
|
|
3054
3059
|
hubAssetOft = viem.getAddress(hubEntry.oft);
|
|
3055
3060
|
spokeAsset = viem.getAddress(spokeEntry.token);
|
|
3056
|
-
isStargate = STARGATE_ASSETS2.has(sym);
|
|
3057
3061
|
symbol = sym;
|
|
3058
3062
|
break;
|
|
3059
3063
|
}
|
|
@@ -3063,6 +3067,7 @@ async function resolveRedeemAddresses(hubPublicClient, vault, hubChainId, spokeC
|
|
|
3063
3067
|
`[MoreVaults] No OFT route found for vault asset ${hubAsset} between hub chain ${hubChainId} and spoke chain ${spokeChainId}`
|
|
3064
3068
|
);
|
|
3065
3069
|
}
|
|
3070
|
+
const isStargate = await detectStargateOft(hubPublicClient, hubAssetOft);
|
|
3066
3071
|
return {
|
|
3067
3072
|
hubChainId,
|
|
3068
3073
|
spokeChainId,
|
|
@@ -4001,6 +4006,7 @@ exports.depositFromSpoke = depositFromSpoke;
|
|
|
4001
4006
|
exports.depositFromSpokeAsync = depositFromSpoke;
|
|
4002
4007
|
exports.depositMultiAsset = depositMultiAsset;
|
|
4003
4008
|
exports.depositSimple = depositSimple;
|
|
4009
|
+
exports.detectStargateOft = detectStargateOft;
|
|
4004
4010
|
exports.discoverVaultTopology = discoverVaultTopology;
|
|
4005
4011
|
exports.encodeCuratorAction = encodeCuratorAction;
|
|
4006
4012
|
exports.encodeUniswapV3SwapCalldata = encodeUniswapV3SwapCalldata;
|