@oydual31/more-vaults-sdk 1.1.25 → 1.1.26

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.
@@ -344,6 +344,13 @@ var UNISWAP_V3_ROUTERS = {
344
344
  [747]: "0xeEDC6Ff75e1b10B903D9013c358e446a73d35341"
345
345
  // Flow EVM — FlowSwap V3 SwapRouter
346
346
  };
347
+ var DEFAULT_LZ_ENDPOINT = "0x1a44076050125825900e736c501f859c50fe728c";
348
+ var LZ_ENDPOINT_BY_CHAIN = {
349
+ [CHAIN_IDS.flowEVMMainnet]: "0xcb566e3b6934fa77258d68ea18e931fa75e1aaaa"
350
+ };
351
+ function getLzEndpoint(chainId) {
352
+ return LZ_ENDPOINT_BY_CHAIN[chainId] ?? DEFAULT_LZ_ENDPOINT;
353
+ }
347
354
  var PUBLIC_RPCS = {
348
355
  1: ["https://ethereum-rpc.publicnode.com", "https://eth.drpc.org", "https://eth.llamarpc.com"],
349
356
  10: ["https://mainnet.optimism.io", "https://optimism-rpc.publicnode.com"],
@@ -1017,9 +1024,13 @@ async function detectStargateOft(provider, oft) {
1017
1024
  return false;
1018
1025
  }
1019
1026
  }
1020
- var LZ_ENDPOINT = "0x1a44076050125825900e736c501f859c50fe728c";
1027
+ var LZ_ENDPOINT = DEFAULT_LZ_ENDPOINT;
1021
1028
  var EMPTY_HASH = "0x0000000000000000000000000000000000000000000000000000000000000000";
1022
1029
  var RECEIVED_HASH = "0x0000000000000000000000000000000000000000000000000000000000000001";
1030
+ var COMPOSE_SENT_TOPIC = "0x0c68e6a0b0fb0f33c52455a8da89b21fc640a3dd4a1b21d9bfcc8aeee4a43e84";
1031
+ var COMPOSE_SCAN_WINDOW_BLOCKS = 200000n;
1032
+ var COMPOSE_SCAN_CHUNK_SIZE = 2000n;
1033
+ var EXECUTE_COMPOSE_GAS_LIMIT = 5000000n;
1023
1034
  async function ensureAllowance2(signer, token, spender, amount) {
1024
1035
  const owner = await signer.getAddress();
1025
1036
  const erc20 = new ethers.Contract(token, ERC20_ABI, signer);
@@ -1147,8 +1158,13 @@ async function quoteComposeFee(provider, vault, spokeEid, receiver) {
1147
1158
  return 500000000000000n;
1148
1159
  }
1149
1160
  }
1150
- async function executeCompose(signer, from, to, guid, message, fee, index = 0) {
1151
- const endpoint = new ethers.Contract(LZ_ENDPOINT, LZ_ENDPOINT_ABI, signer);
1161
+ async function executeCompose(signer, from, to, guid, message, fee, index = 0, hubChainId) {
1162
+ let resolvedChainId = hubChainId;
1163
+ if (resolvedChainId === void 0 && signer.provider) {
1164
+ resolvedChainId = Number((await signer.provider.getNetwork()).chainId);
1165
+ }
1166
+ const endpointAddr = resolvedChainId ? getLzEndpoint(resolvedChainId) : LZ_ENDPOINT;
1167
+ const endpoint = new ethers.Contract(endpointAddr, LZ_ENDPOINT_ABI, signer);
1152
1168
  const hash = await endpoint.composeQueue(from, to, guid, index);
1153
1169
  if (hash === EMPTY_HASH) {
1154
1170
  throw new Error("Compose not found in queue (hash = 0). Never sent or wrong parameters.");
@@ -1158,7 +1174,7 @@ async function executeCompose(signer, from, to, guid, message, fee, index = 0) {
1158
1174
  }
1159
1175
  const tx = await endpoint.lzCompose(from, to, guid, index, message, "0x", {
1160
1176
  value: fee,
1161
- gasLimit: 5000000n
1177
+ gasLimit: EXECUTE_COMPOSE_GAS_LIMIT
1162
1178
  });
1163
1179
  const receipt = await tx.wait();
1164
1180
  return { receipt };
@@ -1183,7 +1199,6 @@ async function waitForCompose(hubProvider, composeData, receiver, pollIntervalMs
1183
1199
  );
1184
1200
  const knownFromAddresses = stargateChecks.filter((c) => c.isSg).map((c) => c.addr);
1185
1201
  const endpointContract = new ethers.Contract(endpoint, LZ_ENDPOINT_ABI, hubProvider);
1186
- const COMPOSE_SENT_TOPIC = "0x0c68e6a0b0fb0f33c52455a8da89b21fc640a3dd4a1b21d9bfcc8aeee4a43e84";
1187
1202
  let attempt = 0;
1188
1203
  let scannedUpTo = startBlock - 1n;
1189
1204
  while (Date.now() < deadline) {
@@ -1277,6 +1292,132 @@ async function waitForCompose(hubProvider, composeData, receiver, pollIntervalMs
1277
1292
  `Timeout waiting for compose after ${timeoutMs / 6e4} min. Check LayerZero scan for composer ${composeData.to}.`
1278
1293
  );
1279
1294
  }
1295
+ function decodeComposeMessage(message) {
1296
+ const hex = message.startsWith("0x") ? message.slice(2) : message;
1297
+ const srcEid = parseInt(hex.slice(16, 24), 16);
1298
+ const amountLD = BigInt("0x" + hex.slice(24, 88));
1299
+ const depositor = ethers.getAddress("0x" + hex.slice(112, 152));
1300
+ let dstEid;
1301
+ let receiver;
1302
+ try {
1303
+ const payload = "0x" + hex.slice(152);
1304
+ const coder = ethers.AbiCoder.defaultAbiCoder();
1305
+ const [sendParam] = coder.decode(
1306
+ [
1307
+ "tuple(uint32 dstEid, bytes32 to, uint256 amountLD, uint256 minAmountLD, bytes extraOptions, bytes composeMsg, bytes oftCmd)",
1308
+ "uint256"
1309
+ ],
1310
+ payload
1311
+ );
1312
+ dstEid = Number(sendParam.dstEid);
1313
+ receiver = ethers.getAddress("0x" + sendParam.to.slice(26));
1314
+ } catch {
1315
+ }
1316
+ return { srcEid, amountLD, depositor, dstEid, receiver };
1317
+ }
1318
+ async function findComposeByGuid(hubProvider, endpoint, composer, guid, fromBlock, hubChainId, chunkSize = COMPOSE_SCAN_CHUNK_SIZE) {
1319
+ const currentBlock = BigInt(await hubProvider.getBlockNumber());
1320
+ const scanFrom = fromBlock ?? (currentBlock > COMPOSE_SCAN_WINDOW_BLOCKS ? currentBlock - COMPOSE_SCAN_WINDOW_BLOCKS : 0n);
1321
+ const endpointContract = new ethers.Contract(endpoint, LZ_ENDPOINT_ABI, hubProvider);
1322
+ const coder = ethers.AbiCoder.defaultAbiCoder();
1323
+ const composerLc = composer.toLowerCase();
1324
+ let from = scanFrom;
1325
+ while (from <= currentBlock) {
1326
+ const chunkEnd = from + chunkSize > currentBlock ? currentBlock : from + chunkSize;
1327
+ const logs = await hubProvider.getLogs({
1328
+ address: endpoint,
1329
+ topics: [COMPOSE_SENT_TOPIC],
1330
+ fromBlock: `0x${from.toString(16)}`,
1331
+ toBlock: `0x${chunkEnd.toString(16)}`
1332
+ });
1333
+ for (const log of logs) {
1334
+ let decoded;
1335
+ try {
1336
+ decoded = coder.decode(["address", "address", "bytes32", "uint16", "bytes"], log.data);
1337
+ } catch {
1338
+ continue;
1339
+ }
1340
+ const logFrom = decoded[0];
1341
+ const logTo = decoded[1].toLowerCase();
1342
+ const logGuid = decoded[2];
1343
+ const logIndex = Number(decoded[3]);
1344
+ const logMessage = decoded[4];
1345
+ if (logGuid.toLowerCase() === guid.toLowerCase() && logTo === composerLc) {
1346
+ const hash = await endpointContract.composeQueue(logFrom, composer, guid, logIndex);
1347
+ if (hash === RECEIVED_HASH) throw new ComposeAlreadyExecutedError();
1348
+ if (hash === EMPTY_HASH) {
1349
+ throw new Error(`Compose ${guid} found in events but composeQueue hash is empty \u2014 may have been cleared externally.`);
1350
+ }
1351
+ const chainId = hubChainId ?? Number((await hubProvider.getNetwork()).chainId);
1352
+ return {
1353
+ endpoint,
1354
+ from: logFrom,
1355
+ to: composer,
1356
+ guid,
1357
+ index: logIndex,
1358
+ message: logMessage,
1359
+ isStargate: false,
1360
+ hubChainId: chainId,
1361
+ hubBlockStart: scanFrom
1362
+ };
1363
+ }
1364
+ }
1365
+ from = chunkEnd + 1n;
1366
+ }
1367
+ throw new Error(
1368
+ `Compose GUID ${guid} not found in ComposeSent events on blocks ${scanFrom}\u2192${currentBlock}. Pass a lower fromBlock to scan further back.`
1369
+ );
1370
+ }
1371
+ async function listPendingComposes(hubProvider, endpoint, composer, fromBlock, chunkSize = COMPOSE_SCAN_CHUNK_SIZE) {
1372
+ const currentBlock = BigInt(await hubProvider.getBlockNumber());
1373
+ const scanFrom = fromBlock ?? (currentBlock > COMPOSE_SCAN_WINDOW_BLOCKS ? currentBlock - COMPOSE_SCAN_WINDOW_BLOCKS : 0n);
1374
+ const endpointContract = new ethers.Contract(endpoint, LZ_ENDPOINT_ABI, hubProvider);
1375
+ const coder = ethers.AbiCoder.defaultAbiCoder();
1376
+ const composerLc = composer.toLowerCase();
1377
+ const pending = [];
1378
+ for (let from = scanFrom; from <= currentBlock; from += chunkSize + 1n) {
1379
+ const chunkEnd = from + chunkSize > currentBlock ? currentBlock : from + chunkSize;
1380
+ try {
1381
+ const logs = await hubProvider.getLogs({
1382
+ address: endpoint,
1383
+ topics: [COMPOSE_SENT_TOPIC],
1384
+ fromBlock: `0x${from.toString(16)}`,
1385
+ toBlock: `0x${chunkEnd.toString(16)}`
1386
+ });
1387
+ for (const log of logs) {
1388
+ let decoded;
1389
+ try {
1390
+ decoded = coder.decode(["address", "address", "bytes32", "uint16", "bytes"], log.data);
1391
+ } catch {
1392
+ continue;
1393
+ }
1394
+ const logFrom = decoded[0];
1395
+ const logTo = decoded[1].toLowerCase();
1396
+ const logGuid = decoded[2];
1397
+ const logIndex = Number(decoded[3]);
1398
+ const logMessage = decoded[4];
1399
+ if (logTo !== composerLc) continue;
1400
+ try {
1401
+ const hash = await endpointContract.composeQueue(logFrom, composer, logGuid, logIndex);
1402
+ if (hash !== EMPTY_HASH && hash !== RECEIVED_HASH) {
1403
+ pending.push({
1404
+ guid: logGuid,
1405
+ blockNumber: BigInt(log.blockNumber),
1406
+ from: logFrom,
1407
+ index: logIndex,
1408
+ message: logMessage,
1409
+ decoded: decodeComposeMessage(logMessage)
1410
+ });
1411
+ }
1412
+ } catch {
1413
+ }
1414
+ }
1415
+ } catch {
1416
+ continue;
1417
+ }
1418
+ }
1419
+ return pending;
1420
+ }
1280
1421
 
1281
1422
  // src/ethers/preflight.ts
1282
1423
  async function preflightAsync(provider, vault, escrow) {
@@ -1777,6 +1918,23 @@ function getAllVaultChainIds(topology) {
1777
1918
  return [topology.hubChainId, ...topology.spokeChainIds];
1778
1919
  }
1779
1920
 
1921
+ // src/common/gasBuffer.ts
1922
+ var DEFAULT_GAS_BUFFER_BPS = 4000n;
1923
+ var BPS_DENOMINATOR = 10000n;
1924
+ var currentDefaultBps = DEFAULT_GAS_BUFFER_BPS;
1925
+ function setDefaultGasBufferBps(bps) {
1926
+ if (bps < 0n) throw new RangeError(`gas buffer bps must be >= 0, got ${bps}`);
1927
+ currentDefaultBps = bps;
1928
+ }
1929
+ function getDefaultGasBufferBps() {
1930
+ return currentDefaultBps;
1931
+ }
1932
+ function applyGasBuffer(estimate, bufferBps) {
1933
+ const bps = bufferBps ?? currentDefaultBps;
1934
+ if (bps < 0n) throw new RangeError(`gas buffer bps must be >= 0, got ${bps}`);
1935
+ return estimate * (BPS_DENOMINATOR + bps) / BPS_DENOMINATOR;
1936
+ }
1937
+
1780
1938
  // src/ethers/redeemFlows.ts
1781
1939
  async function ensureAllowance4(signer, token, spender, amount) {
1782
1940
  const owner = await signer.getAddress();
@@ -1957,7 +2115,7 @@ async function estimateRedeemCost(provider, addresses, shares, receiver, owner,
1957
2115
  extraOptions,
1958
2116
  { value: lzFee, from: owner }
1959
2117
  );
1960
- requestGas = BigInt(raw.toString()) * 130n / 100n;
2118
+ requestGas = applyGasBuffer(BigInt(raw.toString()));
1961
2119
  } catch {
1962
2120
  }
1963
2121
  const approveGas = 60000n;
@@ -3771,6 +3929,8 @@ exports.BRIDGE_FACET_ABI = BRIDGE_FACET_ABI;
3771
3929
  exports.CCManagerNotConfiguredError = CCManagerNotConfiguredError;
3772
3930
  exports.CHAIN_IDS = CHAIN_IDS;
3773
3931
  exports.CHAIN_ID_TO_EID = CHAIN_ID_TO_EID;
3932
+ exports.COMPOSE_SCAN_CHUNK_SIZE = COMPOSE_SCAN_CHUNK_SIZE;
3933
+ exports.COMPOSE_SCAN_WINDOW_BLOCKS = COMPOSE_SCAN_WINDOW_BLOCKS;
3774
3934
  exports.CONFIG_ABI = CONFIG_ABI;
3775
3935
  exports.CURATOR_CONFIG_ABI = CURATOR_CONFIG_ABI;
3776
3936
  exports.CantProcessWithdrawRequestError = CantProcessWithdrawRequestError;
@@ -3778,11 +3938,14 @@ exports.CapacityFullError = CapacityFullError;
3778
3938
  exports.ComposeAlreadyExecutedError = ComposeAlreadyExecutedError;
3779
3939
  exports.ComposeTimeoutError = ComposeTimeoutError;
3780
3940
  exports.ComposerNotConfiguredError = ComposerNotConfiguredError;
3941
+ exports.DEFAULT_GAS_BUFFER_BPS = DEFAULT_GAS_BUFFER_BPS;
3942
+ exports.DEFAULT_LZ_ENDPOINT = DEFAULT_LZ_ENDPOINT;
3781
3943
  exports.DEX_ABI = DEX_ABI;
3782
3944
  exports.EID_TO_CHAIN_ID = EID_TO_CHAIN_ID;
3783
3945
  exports.ERC20_ABI = ERC20_ABI;
3784
3946
  exports.ERC4626_FACET_ABI = ERC4626_FACET_ABI;
3785
3947
  exports.ERC7540_FACET_ABI = ERC7540_FACET_ABI;
3948
+ exports.EXECUTE_COMPOSE_GAS_LIMIT = EXECUTE_COMPOSE_GAS_LIMIT;
3786
3949
  exports.EscrowNotConfiguredError = EscrowNotConfiguredError;
3787
3950
  exports.InsufficientBalanceError = InsufficientBalanceError;
3788
3951
  exports.InsufficientLiquidityError = InsufficientLiquidityError;
@@ -3790,6 +3953,7 @@ exports.InvalidInputError = InvalidInputError;
3790
3953
  exports.LZ_ADAPTER_ABI = LZ_ADAPTER_ABI;
3791
3954
  exports.LZ_EIDS = LZ_EIDS;
3792
3955
  exports.LZ_ENDPOINT_ABI = LZ_ENDPOINT_ABI;
3956
+ exports.LZ_ENDPOINT_BY_CHAIN = LZ_ENDPOINT_BY_CHAIN;
3793
3957
  exports.LZ_TIMEOUTS = LZ_TIMEOUTS;
3794
3958
  exports.METADATA_ABI = METADATA_ABI;
3795
3959
  exports.MULTICALL_ABI = MULTICALL_ABI;
@@ -3822,6 +3986,7 @@ exports.WrongChainError = WrongChainError;
3822
3986
  exports.acceptOwnership = acceptOwnership;
3823
3987
  exports.addAvailableAsset = addAvailableAsset;
3824
3988
  exports.addAvailableAssets = addAvailableAssets;
3989
+ exports.applyGasBuffer = applyGasBuffer;
3825
3990
  exports.asSdkSigner = asSdkSigner;
3826
3991
  exports.bridgeAssetsToSpoke = bridgeAssetsToSpoke;
3827
3992
  exports.bridgeSharesToHub = bridgeSharesToHub;
@@ -3829,6 +3994,7 @@ exports.buildCuratorBatch = buildCuratorBatch;
3829
3994
  exports.buildUniswapV3Swap = buildUniswapV3Swap;
3830
3995
  exports.canDeposit = canDeposit;
3831
3996
  exports.checkProtocolWhitelist = checkProtocolWhitelist;
3997
+ exports.decodeComposeMessage = decodeComposeMessage;
3832
3998
  exports.depositAsync = depositAsync;
3833
3999
  exports.depositCrossChainOracleOn = depositCrossChainOracleOn;
3834
4000
  exports.depositFromSpoke = depositFromSpoke;
@@ -3849,13 +4015,16 @@ exports.executeActions = executeActions;
3849
4015
  exports.executeCompose = executeCompose;
3850
4016
  exports.executeCuratorBridge = executeCuratorBridge;
3851
4017
  exports.findBridgeRoute = findBridgeRoute;
4018
+ exports.findComposeByGuid = findComposeByGuid;
3852
4019
  exports.getAllVaultChainIds = getAllVaultChainIds;
3853
4020
  exports.getAsyncRequestStatus = getAsyncRequestStatus;
3854
4021
  exports.getAsyncRequestStatusLabel = getAsyncRequestStatusLabel;
3855
4022
  exports.getCuratorVaultStatus = getCuratorVaultStatus;
4023
+ exports.getDefaultGasBufferBps = getDefaultGasBufferBps;
3856
4024
  exports.getERC7540RequestStatus = getERC7540RequestStatus;
3857
4025
  exports.getFullVaultTopology = getFullVaultTopology;
3858
4026
  exports.getInboundRoutes = getInboundRoutes;
4027
+ exports.getLzEndpoint = getLzEndpoint;
3859
4028
  exports.getMaxWithdrawable = getMaxWithdrawable;
3860
4029
  exports.getOutboundRoutes = getOutboundRoutes;
3861
4030
  exports.getPendingActions = getPendingActions;
@@ -3880,6 +4049,7 @@ exports.getWithdrawalRequest = getWithdrawalRequest;
3880
4049
  exports.isAsyncMode = isAsyncMode;
3881
4050
  exports.isCurator = isCurator;
3882
4051
  exports.isOnHubChain = isOnHubChain;
4052
+ exports.listPendingComposes = listPendingComposes;
3883
4053
  exports.mintAsync = mintAsync;
3884
4054
  exports.pauseVault = pauseVault;
3885
4055
  exports.preflightAsync = preflightAsync;
@@ -3902,6 +4072,7 @@ exports.redeemAsync = redeemAsync;
3902
4072
  exports.redeemShares = redeemShares;
3903
4073
  exports.requestRedeem = requestRedeem;
3904
4074
  exports.resolveRedeemAddresses = resolveRedeemAddresses;
4075
+ exports.setDefaultGasBufferBps = setDefaultGasBufferBps;
3905
4076
  exports.setDepositCapacity = setDepositCapacity;
3906
4077
  exports.setDepositWhitelist = setDepositWhitelist;
3907
4078
  exports.setFeeRecipient = setFeeRecipient;