@hyperbridge/sdk 2.3.1 → 2.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/browser/index.d.ts +2 -2
- package/dist/browser/index.js +101 -56
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.cjs +101 -56
- package/dist/node/index.cjs.map +1 -1
- package/dist/node/index.d.cts +2 -2
- package/dist/node/index.d.ts +2 -2
- package/dist/node/index.js +101 -56
- package/dist/node/index.js.map +1 -1
- package/package.json +1 -1
package/dist/node/index.cjs
CHANGED
|
@@ -6786,15 +6786,20 @@ var EvmChain = class _EvmChain {
|
|
|
6786
6786
|
async quoteNative(request, fee) {
|
|
6787
6787
|
const totalFee = await this.quote(request) + fee;
|
|
6788
6788
|
const feeToken = await this.getFeeTokenWithDecimals();
|
|
6789
|
-
|
|
6789
|
+
const hostRouter = await this.publicClient.readContract({
|
|
6790
|
+
address: this.params.host,
|
|
6791
|
+
abi: evmHost_default.ABI,
|
|
6792
|
+
functionName: "uniswapV2Router"
|
|
6793
|
+
});
|
|
6794
|
+
return this.getAmountsIn(totalFee, feeToken.address, request.source, hostRouter);
|
|
6790
6795
|
}
|
|
6791
6796
|
/**
|
|
6792
6797
|
* Given a desired output amount of a token, returns how much native is needed as input.
|
|
6793
|
-
* Uses the chain's Uniswap V2 router: WETH → tokenOut path.
|
|
6798
|
+
* Uses the chain's Uniswap V2 router (or `router` when provided): WETH → tokenOut path.
|
|
6794
6799
|
*/
|
|
6795
|
-
async getAmountsIn(amountOut, tokenOutForQuote, chain) {
|
|
6800
|
+
async getAmountsIn(amountOut, tokenOutForQuote, chain, router) {
|
|
6796
6801
|
const chainId = chain ?? `EVM-${this.params.chainId}`;
|
|
6797
|
-
const v2Router = this.configService.getUniswapRouterV2Address(chainId);
|
|
6802
|
+
const v2Router = router ?? this.configService.getUniswapRouterV2Address(chainId);
|
|
6798
6803
|
const WETH = this.configService.getWrappedNativeAssetWithDecimals(chainId).asset;
|
|
6799
6804
|
const v2AmountIn = await this.publicClient.simulateContract({
|
|
6800
6805
|
address: v2Router,
|
|
@@ -7039,6 +7044,11 @@ var ExpectedError = class _ExpectedError extends Error {
|
|
|
7039
7044
|
return error instanceof _ExpectedError;
|
|
7040
7045
|
}
|
|
7041
7046
|
};
|
|
7047
|
+
|
|
7048
|
+
// src/configs/constants.ts
|
|
7049
|
+
var ISMP_PREFIX = ":child_storage:default:ISMPv2";
|
|
7050
|
+
|
|
7051
|
+
// src/chains/substrate.ts
|
|
7042
7052
|
var HttpRpcClient = class {
|
|
7043
7053
|
constructor(url) {
|
|
7044
7054
|
this.url = url;
|
|
@@ -7162,7 +7172,7 @@ var SubstrateChain = class _SubstrateChain {
|
|
|
7162
7172
|
* @returns {Promise<HexString | undefined>} The commitment data if found, undefined otherwise.
|
|
7163
7173
|
*/
|
|
7164
7174
|
async queryRequestCommitment(commitment) {
|
|
7165
|
-
const prefix = viem.toHex(
|
|
7175
|
+
const prefix = viem.toHex(ISMP_PREFIX);
|
|
7166
7176
|
const key = this.requestCommitmentKey(commitment);
|
|
7167
7177
|
const item = await this.rpcClient.call("childstate_getStorage", [prefix, key]);
|
|
7168
7178
|
return item;
|
|
@@ -7173,7 +7183,7 @@ var SubstrateChain = class _SubstrateChain {
|
|
|
7173
7183
|
* @returns {Promise<HexString | undefined>} The relayer address responsible for delivering the request.
|
|
7174
7184
|
*/
|
|
7175
7185
|
async queryRequestReceipt(commitment) {
|
|
7176
|
-
const prefix = viem.toHex(
|
|
7186
|
+
const prefix = viem.toHex(ISMP_PREFIX);
|
|
7177
7187
|
const key = this.requestReceiptKey(commitment);
|
|
7178
7188
|
const item = await this.rpcClient.call("childstate_getStorage", [prefix, key]);
|
|
7179
7189
|
return item;
|
|
@@ -7197,7 +7207,7 @@ var SubstrateChain = class _SubstrateChain {
|
|
|
7197
7207
|
* @returns {Promise<HexString | undefined>} The receipt data if present, otherwise undefined.
|
|
7198
7208
|
*/
|
|
7199
7209
|
async queryResponseReceipt(commitment) {
|
|
7200
|
-
const prefix = viem.toHex(
|
|
7210
|
+
const prefix = viem.toHex(ISMP_PREFIX);
|
|
7201
7211
|
const key = this.responseReceiptKey(commitment);
|
|
7202
7212
|
const item = await this.rpcClient.call("childstate_getStorage", [prefix, key]);
|
|
7203
7213
|
return item;
|
|
@@ -15305,7 +15315,11 @@ var OrderExecutor = class {
|
|
|
15305
15315
|
*/
|
|
15306
15316
|
async fetchBids(params) {
|
|
15307
15317
|
const { commitment, solver, solverLockStartTime } = params;
|
|
15308
|
-
const
|
|
15318
|
+
const intentsCoprocessor = this.ctx.intentsCoprocessor;
|
|
15319
|
+
if (!intentsCoprocessor) {
|
|
15320
|
+
throw new Error("IntentsCoprocessor required for order execution");
|
|
15321
|
+
}
|
|
15322
|
+
const fetchedBids = await intentsCoprocessor.getBidsForOrder(commitment);
|
|
15309
15323
|
if (solver) {
|
|
15310
15324
|
const { address, timeoutMs } = solver;
|
|
15311
15325
|
const solverLockActive = Date.now() - solverLockStartTime < timeoutMs;
|
|
@@ -15394,7 +15408,7 @@ var OrderExecutor = class {
|
|
|
15394
15408
|
* → (`FILLED` | `PARTIAL_FILL`)* → (`FILLED` | `EXPIRED`)
|
|
15395
15409
|
*
|
|
15396
15410
|
* **Cross-chain:** `AWAITING_BIDS` → `BIDS_RECEIVED` → `BID_SELECTED`
|
|
15397
|
-
*
|
|
15411
|
+
* → `FILLED`
|
|
15398
15412
|
*/
|
|
15399
15413
|
async *executeOrder(options) {
|
|
15400
15414
|
const { order, sessionPrivateKey, auctionTimeMs, pollIntervalMs = DEFAULT_POLL_INTERVAL, solver } = options;
|
|
@@ -15533,7 +15547,13 @@ var OrderExecutor = class {
|
|
|
15533
15547
|
userOp: result.userOp,
|
|
15534
15548
|
transactionHash: result.txnHash
|
|
15535
15549
|
};
|
|
15536
|
-
const fill = this.processFillResult(
|
|
15550
|
+
const fill = this.processFillResult(
|
|
15551
|
+
result,
|
|
15552
|
+
commitment,
|
|
15553
|
+
targetAssets,
|
|
15554
|
+
totalFilledAssets,
|
|
15555
|
+
remainingAssets
|
|
15556
|
+
);
|
|
15537
15557
|
totalFilledAssets = fill.totalFilledAssets;
|
|
15538
15558
|
remainingAssets = fill.remainingAssets;
|
|
15539
15559
|
if (fill.update) {
|
|
@@ -15559,6 +15579,10 @@ var OrderCanceller = class {
|
|
|
15559
15579
|
this.ctx = ctx;
|
|
15560
15580
|
}
|
|
15561
15581
|
ctx;
|
|
15582
|
+
logger = consola.createConsola({
|
|
15583
|
+
level: consola.LogLevels.info,
|
|
15584
|
+
formatOptions: { columns: 80, colors: true, compact: true, date: false }
|
|
15585
|
+
}).withTag("[OrderCanceller]");
|
|
15562
15586
|
/**
|
|
15563
15587
|
* Returns both the native token cost and the relayer fee for cancelling an
|
|
15564
15588
|
* order. Frontends can use `relayerFee` to approve the ERC-20 spend before
|
|
@@ -15974,32 +15998,55 @@ var OrderCanceller = class {
|
|
|
15974
15998
|
}
|
|
15975
15999
|
/**
|
|
15976
16000
|
* Submits an unsigned GET request message to Hyperbridge and waits until
|
|
15977
|
-
* the
|
|
16001
|
+
* the GET response receipt is confirmed on-chain.
|
|
15978
16002
|
*
|
|
15979
|
-
*
|
|
15980
|
-
*
|
|
16003
|
+
* GET handling on Hyperbridge creates a response receipt keyed by the
|
|
16004
|
+
* request commitment. That receipt is the durable delivery signal, so a
|
|
16005
|
+
* duplicate unsigned submission is considered successful only if the
|
|
16006
|
+
* response receipt can be observed.
|
|
15981
16007
|
*
|
|
15982
16008
|
* @param hyperbridge - Hyperbridge Substrate chain client.
|
|
15983
16009
|
* @param commitment - The GET request commitment hash used to poll for the receipt.
|
|
15984
16010
|
* @param message - The fully constructed GET request message to submit.
|
|
15985
16011
|
*/
|
|
15986
16012
|
async submitAndConfirmReceipt(hyperbridge, commitment, message) {
|
|
15987
|
-
|
|
15988
|
-
if (
|
|
15989
|
-
|
|
15990
|
-
|
|
15991
|
-
|
|
15992
|
-
|
|
16013
|
+
this.logger.info(`Checking GET response receipt before Hyperbridge delivery (${commitment})`);
|
|
16014
|
+
if (await this.queryDeliveredReceipt(hyperbridge, commitment)) {
|
|
16015
|
+
this.logger.info(`GET ${commitment} already delivered to Hyperbridge; skipping unsigned submission`);
|
|
16016
|
+
return;
|
|
16017
|
+
}
|
|
16018
|
+
try {
|
|
16019
|
+
this.logger.info(`Submitting unsigned GET ${commitment} to Hyperbridge`);
|
|
16020
|
+
await hyperbridge.submitUnsigned(message);
|
|
16021
|
+
this.logger.info(`Unsigned GET ${commitment} submitted; waiting for Hyperbridge response receipt`);
|
|
15993
16022
|
await sleep(3e4);
|
|
15994
|
-
|
|
15995
|
-
|
|
15996
|
-
|
|
15997
|
-
if (!value) throw new Error("Receipt not found");
|
|
15998
|
-
return value;
|
|
15999
|
-
},
|
|
16000
|
-
{ maxRetries: 10, backoffMs: 5e3, logMessage: "Checking for receipt" }
|
|
16023
|
+
} catch (error) {
|
|
16024
|
+
this.logger.warn(
|
|
16025
|
+
`Unsigned GET submit failed for ${commitment}; polling response receipt before failing: ${String(error)}`
|
|
16001
16026
|
);
|
|
16002
16027
|
}
|
|
16028
|
+
try {
|
|
16029
|
+
await this.pollDeliveredReceipt(hyperbridge, commitment);
|
|
16030
|
+
this.logger.info(`Confirmed Hyperbridge GET delivery for ${commitment}`);
|
|
16031
|
+
} catch (error) {
|
|
16032
|
+
const message2 = `Failed to deliver GET request to Hyperbridge; no response receipt found for ${commitment}: ${String(error)}`;
|
|
16033
|
+
this.logger.error(message2);
|
|
16034
|
+
throw new Error(message2);
|
|
16035
|
+
}
|
|
16036
|
+
}
|
|
16037
|
+
async queryDeliveredReceipt(hyperbridge, commitment) {
|
|
16038
|
+
return hyperbridge.queryResponseReceipt(commitment);
|
|
16039
|
+
}
|
|
16040
|
+
async pollDeliveredReceipt(hyperbridge, commitment) {
|
|
16041
|
+
this.logger.info(`Polling Hyperbridge GET response receipt for ${commitment}`);
|
|
16042
|
+
return retryPromise(
|
|
16043
|
+
async () => {
|
|
16044
|
+
const value = await this.queryDeliveredReceipt(hyperbridge, commitment);
|
|
16045
|
+
if (!value) throw new Error(`GET response receipt not found for ${commitment}`);
|
|
16046
|
+
return value;
|
|
16047
|
+
},
|
|
16048
|
+
{ maxRetries: 10, backoffMs: 5e3, logMessage: `Checking GET response receipt ${commitment}` }
|
|
16049
|
+
);
|
|
16003
16050
|
}
|
|
16004
16051
|
/**
|
|
16005
16052
|
* Estimates the relayer fee for delivering a POST from dest to source.
|
|
@@ -16070,7 +16117,7 @@ var BidImpl = class {
|
|
|
16070
16117
|
const sessionKeyAddress = this.order.session;
|
|
16071
16118
|
const sessionKeyData = this.sessionPrivateKey ? { privateKey: this.sessionPrivateKey } : await this.ctx.sessionKeyStorage.getSessionKeyByAddress(sessionKeyAddress);
|
|
16072
16119
|
if (!sessionKeyData) {
|
|
16073
|
-
throw new Error(
|
|
16120
|
+
throw new Error(`SessionKey not found for commitment: ${commitment}`);
|
|
16074
16121
|
}
|
|
16075
16122
|
const signature = await CryptoUtils.signSolverSelection(
|
|
16076
16123
|
commitment,
|
|
@@ -16130,8 +16177,8 @@ var BidImpl = class {
|
|
|
16130
16177
|
/**
|
|
16131
16178
|
* Signs the `SelectSolver` message with the session key, appends it to the
|
|
16132
16179
|
* solver's existing UserOp signature, and submits the UserOperation to the
|
|
16133
|
-
* bundler.
|
|
16134
|
-
*
|
|
16180
|
+
* bundler. Waits for the receipt and reads `OrderFilled` / `PartialFill`
|
|
16181
|
+
* logs to determine fill status.
|
|
16135
16182
|
*
|
|
16136
16183
|
* @returns A {@link SelectBidResult} with the submitted UserOperation, its hash,
|
|
16137
16184
|
* the solver address, transaction hash, and fill status.
|
|
@@ -16171,33 +16218,31 @@ var BidImpl = class {
|
|
|
16171
16218
|
{ maxRetries: 5, backoffMs: 2e3, logMessage: "Fetching user operation receipt" }
|
|
16172
16219
|
);
|
|
16173
16220
|
txnHash = receipt.receipt.transactionHash;
|
|
16174
|
-
|
|
16175
|
-
|
|
16176
|
-
|
|
16177
|
-
|
|
16178
|
-
|
|
16179
|
-
|
|
16180
|
-
|
|
16181
|
-
|
|
16182
|
-
|
|
16183
|
-
|
|
16184
|
-
|
|
16185
|
-
|
|
16186
|
-
|
|
16187
|
-
|
|
16188
|
-
|
|
16189
|
-
|
|
16190
|
-
|
|
16191
|
-
|
|
16192
|
-
|
|
16193
|
-
|
|
16194
|
-
|
|
16195
|
-
|
|
16196
|
-
filledAssets = matched.args.outputs ?? [];
|
|
16197
|
-
}
|
|
16198
|
-
} catch {
|
|
16199
|
-
throw new Error("Failed to determine fill status from logs");
|
|
16221
|
+
try {
|
|
16222
|
+
const chainReceipt = await this.ctx.dest.client.waitForTransactionReceipt({
|
|
16223
|
+
hash: txnHash,
|
|
16224
|
+
confirmations: 1
|
|
16225
|
+
});
|
|
16226
|
+
const events = viem.parseEventLogs({
|
|
16227
|
+
abi: ABI3,
|
|
16228
|
+
logs: chainReceipt.logs,
|
|
16229
|
+
eventName: ["OrderFilled", "PartialFill"]
|
|
16230
|
+
});
|
|
16231
|
+
const matched = events.find((e) => {
|
|
16232
|
+
if (e.eventName === "OrderFilled")
|
|
16233
|
+
return e.args.commitment.toLowerCase() === commitment.toLowerCase();
|
|
16234
|
+
if (e.eventName === "PartialFill")
|
|
16235
|
+
return e.args.commitment.toLowerCase() === commitment.toLowerCase();
|
|
16236
|
+
return false;
|
|
16237
|
+
});
|
|
16238
|
+
if (matched?.eventName === "OrderFilled") {
|
|
16239
|
+
fillStatus = "full";
|
|
16240
|
+
} else if (matched?.eventName === "PartialFill") {
|
|
16241
|
+
fillStatus = "partial";
|
|
16242
|
+
filledAssets = matched.args.outputs ?? [];
|
|
16200
16243
|
}
|
|
16244
|
+
} catch {
|
|
16245
|
+
throw new Error("Failed to determine fill status from logs");
|
|
16201
16246
|
}
|
|
16202
16247
|
} catch (err) {
|
|
16203
16248
|
throw new Error(`Failed to execute bid: ${err instanceof Error ? err.message : String(err)}`);
|
|
@@ -16999,9 +17044,9 @@ var GasEstimator = class {
|
|
|
16999
17044
|
from: this.ctx.source.configService.getIntentGatewayAddress(destChainId),
|
|
17000
17045
|
to: this.ctx.source.configService.getIntentGatewayAddress(sourceChainId)
|
|
17001
17046
|
};
|
|
17047
|
+
postRequestFeeInDestFeeToken = postRequestFeeInDestFeeToken * 1005n / 1000n;
|
|
17002
17048
|
let protocolFeeInNativeToken = await this.ctx.dest.quoteNative(postRequest, postRequestFeeInDestFeeToken).catch(() => 0n);
|
|
17003
17049
|
protocolFeeInNativeToken = protocolFeeInNativeToken * 1005n / 1000n;
|
|
17004
|
-
postRequestFeeInDestFeeToken = postRequestFeeInDestFeeToken * 1005n / 1000n;
|
|
17005
17050
|
return { postRequestFee: postRequestFeeInDestFeeToken, protocolFee: protocolFeeInNativeToken };
|
|
17006
17051
|
}
|
|
17007
17052
|
/**
|