@hyperbridge/sdk 1.3.25 → 1.3.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.
- package/dist/browser/index.d.ts +8 -0
- package/dist/browser/index.js +153 -11
- package/dist/browser/index.js.map +1 -1
- package/dist/node/index.d.ts +8 -0
- package/dist/node/index.js +153 -11
- package/dist/node/index.js.map +1 -1
- package/package.json +2 -2
package/dist/browser/index.d.ts
CHANGED
|
@@ -1607,6 +1607,7 @@ declare class ChainConfigService {
|
|
|
1607
1607
|
getPermit2Address(chain: string): HexString;
|
|
1608
1608
|
getCoingeckoId(chain: string): string | undefined;
|
|
1609
1609
|
getEtherscanApiKey(): string | undefined;
|
|
1610
|
+
getCalldispatcherAddress(chain: string): HexString;
|
|
1610
1611
|
}
|
|
1611
1612
|
|
|
1612
1613
|
/**
|
|
@@ -2798,6 +2799,13 @@ declare class IntentGateway {
|
|
|
2798
2799
|
fee?: number;
|
|
2799
2800
|
transactions?: Transaction[];
|
|
2800
2801
|
}>;
|
|
2802
|
+
createMultiHopSwapThroughPair(dexPairAddress: HexString, tokenIn: HexString, tokenOut: HexString, amountIn: bigint, evmChainID: string, getQuoteIn: "source" | "dest", recipient: HexString, protocol?: "v2" | "v3"): Promise<{
|
|
2803
|
+
finalAmountOut: bigint;
|
|
2804
|
+
calldata: Transaction[];
|
|
2805
|
+
}>;
|
|
2806
|
+
private buildSwapPath;
|
|
2807
|
+
private executeSwapPath;
|
|
2808
|
+
private createSwapCalldata;
|
|
2801
2809
|
/**
|
|
2802
2810
|
* Checks if an order has been filled by verifying the commitment status on-chain.
|
|
2803
2811
|
* Reads the storage slot corresponding to the order's commitment hash.
|
package/dist/browser/index.js
CHANGED
|
@@ -3528,7 +3528,13 @@ var addresses = {
|
|
|
3528
3528
|
["EVM-130" /* UNICHAIN_MAINNET */]: "0x52f0e24d1c21c8a0cb1e5a5dd6198556bd9e1203"
|
|
3529
3529
|
},
|
|
3530
3530
|
Calldispatcher: {
|
|
3531
|
-
["EVM-11155111" /* SEPOLIA */]: "0xC7f13b6D03A0A7F3239d38897503E90553ABe155"
|
|
3531
|
+
["EVM-11155111" /* SEPOLIA */]: "0xC7f13b6D03A0A7F3239d38897503E90553ABe155",
|
|
3532
|
+
["EVM-1" /* MAINNET */]: "0xc71251c8b3e7b02697a84363eef6dce8dfbdf333",
|
|
3533
|
+
["EVM-56" /* BSC_MAINNET */]: "0xc71251c8b3e7b02697a84363eef6dce8dfbdf333",
|
|
3534
|
+
["EVM-42161" /* ARBITRUM_MAINNET */]: "0xc71251c8b3e7b02697a84363eef6dce8dfbdf333",
|
|
3535
|
+
["EVM-8453" /* BASE_MAINNET */]: "0xc71251c8b3e7b02697a84363eef6dce8dfbdf333",
|
|
3536
|
+
["EVM-137" /* POLYGON_MAINNET */]: "0xc71251c8b3e7b02697a84363eef6dce8dfbdf333",
|
|
3537
|
+
["EVM-130" /* UNICHAIN_MAINNET */]: "0xc71251c8b3e7b02697a84363eef6dce8dfbdf333"
|
|
3532
3538
|
},
|
|
3533
3539
|
Permit2: {
|
|
3534
3540
|
["EVM-1" /* MAINNET */]: "0x000000000022D473030F116dDEE9F6B43aC78BA3",
|
|
@@ -3646,6 +3652,9 @@ var ChainConfigService = class {
|
|
|
3646
3652
|
getEtherscanApiKey() {
|
|
3647
3653
|
return typeof process !== "undefined" ? process?.env?.ETHERSCAN_API_KEY : void 0;
|
|
3648
3654
|
}
|
|
3655
|
+
getCalldispatcherAddress(chain) {
|
|
3656
|
+
return addresses.Calldispatcher[chain];
|
|
3657
|
+
}
|
|
3649
3658
|
};
|
|
3650
3659
|
function getPeakPosByHeight(height) {
|
|
3651
3660
|
return (1n << BigInt(height + 1)) - 2n;
|
|
@@ -10404,6 +10413,37 @@ var UNISWAP_V4_QUOTER_ABI = [
|
|
|
10404
10413
|
}
|
|
10405
10414
|
];
|
|
10406
10415
|
|
|
10416
|
+
// src/abis/uniswapV2Pair.ts
|
|
10417
|
+
var ABI6 = [
|
|
10418
|
+
{
|
|
10419
|
+
inputs: [],
|
|
10420
|
+
name: "token0",
|
|
10421
|
+
outputs: [
|
|
10422
|
+
{
|
|
10423
|
+
internalType: "address",
|
|
10424
|
+
name: "",
|
|
10425
|
+
type: "address"
|
|
10426
|
+
}
|
|
10427
|
+
],
|
|
10428
|
+
stateMutability: "view",
|
|
10429
|
+
type: "function"
|
|
10430
|
+
},
|
|
10431
|
+
{
|
|
10432
|
+
inputs: [],
|
|
10433
|
+
name: "token1",
|
|
10434
|
+
outputs: [
|
|
10435
|
+
{
|
|
10436
|
+
internalType: "address",
|
|
10437
|
+
name: "",
|
|
10438
|
+
type: "address"
|
|
10439
|
+
}
|
|
10440
|
+
],
|
|
10441
|
+
stateMutability: "view",
|
|
10442
|
+
type: "function"
|
|
10443
|
+
}
|
|
10444
|
+
];
|
|
10445
|
+
var uniswapV2Pair_default = { ABI: ABI6 };
|
|
10446
|
+
|
|
10407
10447
|
// src/abis/permit2.ts
|
|
10408
10448
|
var PERMIT2_ABI = [
|
|
10409
10449
|
{
|
|
@@ -10436,7 +10476,7 @@ var PERMIT2_ABI = [
|
|
|
10436
10476
|
];
|
|
10437
10477
|
|
|
10438
10478
|
// src/abis/universalRouter.ts
|
|
10439
|
-
var
|
|
10479
|
+
var ABI7 = [
|
|
10440
10480
|
{
|
|
10441
10481
|
inputs: [
|
|
10442
10482
|
{
|
|
@@ -10879,7 +10919,7 @@ var ABI6 = [
|
|
|
10879
10919
|
type: "receive"
|
|
10880
10920
|
}
|
|
10881
10921
|
];
|
|
10882
|
-
var universalRouter_default = { ABI:
|
|
10922
|
+
var universalRouter_default = { ABI: ABI7 };
|
|
10883
10923
|
|
|
10884
10924
|
// src/protocols/intents.ts
|
|
10885
10925
|
var IntentGateway = class {
|
|
@@ -11179,8 +11219,8 @@ var IntentGateway = class {
|
|
|
11179
11219
|
args: [amountOut, [tokenInForQuote, tokenOutForQuote]]
|
|
11180
11220
|
});
|
|
11181
11221
|
return v2AmountIn.result[0];
|
|
11182
|
-
} catch
|
|
11183
|
-
console.warn("V2 quote failed:"
|
|
11222
|
+
} catch {
|
|
11223
|
+
console.warn("V2 quote failed:");
|
|
11184
11224
|
return maxUint256;
|
|
11185
11225
|
}
|
|
11186
11226
|
}
|
|
@@ -11203,8 +11243,8 @@ var IntentGateway = class {
|
|
|
11203
11243
|
args: [amountIn, [tokenInForQuote, tokenOutForQuote]]
|
|
11204
11244
|
});
|
|
11205
11245
|
return v2AmountOut.result[1];
|
|
11206
|
-
} catch
|
|
11207
|
-
console.warn("V2 quote failed:"
|
|
11246
|
+
} catch {
|
|
11247
|
+
console.warn("V2 quote failed:");
|
|
11208
11248
|
return BigInt(0);
|
|
11209
11249
|
}
|
|
11210
11250
|
}
|
|
@@ -11241,7 +11281,7 @@ var IntentGateway = class {
|
|
|
11241
11281
|
bestAmountIn = amountIn;
|
|
11242
11282
|
bestFee = fee;
|
|
11243
11283
|
}
|
|
11244
|
-
} catch
|
|
11284
|
+
} catch {
|
|
11245
11285
|
console.warn(`V3 quote failed for fee ${fee}, continuing to next fee tier`);
|
|
11246
11286
|
}
|
|
11247
11287
|
}
|
|
@@ -11280,7 +11320,7 @@ var IntentGateway = class {
|
|
|
11280
11320
|
bestAmountOut = amountOut;
|
|
11281
11321
|
bestFee = fee;
|
|
11282
11322
|
}
|
|
11283
|
-
} catch
|
|
11323
|
+
} catch {
|
|
11284
11324
|
console.warn(`V3 quote failed for fee ${fee}, continuing to next fee tier`);
|
|
11285
11325
|
}
|
|
11286
11326
|
}
|
|
@@ -11325,7 +11365,7 @@ var IntentGateway = class {
|
|
|
11325
11365
|
bestAmountIn = amountIn;
|
|
11326
11366
|
bestFee = fee;
|
|
11327
11367
|
}
|
|
11328
|
-
} catch
|
|
11368
|
+
} catch {
|
|
11329
11369
|
console.warn(`V4 quote failed for fee ${fee}, continuing to next fee tier`);
|
|
11330
11370
|
}
|
|
11331
11371
|
}
|
|
@@ -11370,7 +11410,7 @@ var IntentGateway = class {
|
|
|
11370
11410
|
bestAmountOut = amountOut;
|
|
11371
11411
|
bestFee = fee;
|
|
11372
11412
|
}
|
|
11373
|
-
} catch
|
|
11413
|
+
} catch {
|
|
11374
11414
|
console.warn(`V4 quote failed for fee ${fee}, continuing to next fee tier`);
|
|
11375
11415
|
}
|
|
11376
11416
|
}
|
|
@@ -12262,6 +12302,108 @@ var IntentGateway = class {
|
|
|
12262
12302
|
};
|
|
12263
12303
|
}
|
|
12264
12304
|
}
|
|
12305
|
+
async createMultiHopSwapThroughPair(dexPairAddress, tokenIn, tokenOut, amountIn, evmChainID, getQuoteIn, recipient, protocol = "v2") {
|
|
12306
|
+
const client = this[getQuoteIn].client;
|
|
12307
|
+
const wethAsset = this[getQuoteIn].config.getWrappedNativeAssetWithDecimals(evmChainID).asset;
|
|
12308
|
+
const calldispatcher = this[getQuoteIn].config.getCalldispatcherAddress(evmChainID);
|
|
12309
|
+
const [token0, token1] = await Promise.all([
|
|
12310
|
+
client.readContract({
|
|
12311
|
+
address: dexPairAddress,
|
|
12312
|
+
abi: uniswapV2Pair_default.ABI,
|
|
12313
|
+
functionName: "token0"
|
|
12314
|
+
}),
|
|
12315
|
+
client.readContract({
|
|
12316
|
+
address: dexPairAddress,
|
|
12317
|
+
abi: uniswapV2Pair_default.ABI,
|
|
12318
|
+
functionName: "token1"
|
|
12319
|
+
})
|
|
12320
|
+
]);
|
|
12321
|
+
const intermediateToken = tokenOut.toLowerCase() === token0.toLowerCase() ? token1 : token0;
|
|
12322
|
+
const swapPath = this.buildSwapPath(tokenIn, tokenOut, intermediateToken, wethAsset, calldispatcher, recipient);
|
|
12323
|
+
return this.executeSwapPath(swapPath, amountIn, evmChainID, getQuoteIn, protocol);
|
|
12324
|
+
}
|
|
12325
|
+
buildSwapPath(tokenIn, tokenOut, intermediateToken, wethAsset, calldispatcher, recipient) {
|
|
12326
|
+
const normalize = (token) => token.toLowerCase();
|
|
12327
|
+
if (normalize(intermediateToken) === normalize(tokenIn)) {
|
|
12328
|
+
return [{ from: tokenIn, to: tokenOut, recipient }];
|
|
12329
|
+
}
|
|
12330
|
+
if (normalize(intermediateToken) === normalize(wethAsset)) {
|
|
12331
|
+
return [
|
|
12332
|
+
{ from: tokenIn, to: wethAsset, recipient: calldispatcher },
|
|
12333
|
+
{ from: wethAsset, to: tokenOut, recipient }
|
|
12334
|
+
];
|
|
12335
|
+
}
|
|
12336
|
+
return [
|
|
12337
|
+
{ from: tokenIn, to: wethAsset, recipient: calldispatcher },
|
|
12338
|
+
{ from: wethAsset, to: intermediateToken, recipient: calldispatcher },
|
|
12339
|
+
{ from: intermediateToken, to: tokenOut, recipient }
|
|
12340
|
+
];
|
|
12341
|
+
}
|
|
12342
|
+
async executeSwapPath(path, initialAmount, evmChainID, getQuoteIn, protocol) {
|
|
12343
|
+
let currentAmount = initialAmount;
|
|
12344
|
+
const calldata = [];
|
|
12345
|
+
for (let i = 0; i < path.length; i++) {
|
|
12346
|
+
const segment = path[i];
|
|
12347
|
+
const isLastSwap = i === path.length - 1;
|
|
12348
|
+
const slippage = isLastSwap && path.length > 1 ? 990n : 995n;
|
|
12349
|
+
const swapResult = await this.createSwapCalldata(
|
|
12350
|
+
protocol,
|
|
12351
|
+
segment.from,
|
|
12352
|
+
segment.to,
|
|
12353
|
+
currentAmount,
|
|
12354
|
+
segment.recipient,
|
|
12355
|
+
evmChainID,
|
|
12356
|
+
getQuoteIn,
|
|
12357
|
+
slippage
|
|
12358
|
+
);
|
|
12359
|
+
currentAmount = swapResult.amountOut;
|
|
12360
|
+
calldata.push(...swapResult.calldata);
|
|
12361
|
+
}
|
|
12362
|
+
return {
|
|
12363
|
+
finalAmountOut: currentAmount,
|
|
12364
|
+
calldata
|
|
12365
|
+
};
|
|
12366
|
+
}
|
|
12367
|
+
async createSwapCalldata(protocol, tokenIn, tokenOut, amountIn, recipient, evmChainID, getQuoteIn, slippageFactor) {
|
|
12368
|
+
if (protocol === "v2") {
|
|
12369
|
+
let amountOut = await this.getV2QuoteWithAmountIn(getQuoteIn, tokenIn, tokenOut, amountIn, evmChainID);
|
|
12370
|
+
amountOut = amountOut * slippageFactor / 1000n;
|
|
12371
|
+
return {
|
|
12372
|
+
amountOut,
|
|
12373
|
+
calldata: this.createV2SwapCalldataExactIn(
|
|
12374
|
+
tokenIn,
|
|
12375
|
+
tokenOut,
|
|
12376
|
+
amountIn,
|
|
12377
|
+
amountOut,
|
|
12378
|
+
recipient,
|
|
12379
|
+
evmChainID,
|
|
12380
|
+
getQuoteIn
|
|
12381
|
+
)
|
|
12382
|
+
};
|
|
12383
|
+
} else {
|
|
12384
|
+
const { amountOut, fee } = await this.getV3QuoteWithAmountIn(
|
|
12385
|
+
getQuoteIn,
|
|
12386
|
+
tokenIn,
|
|
12387
|
+
tokenOut,
|
|
12388
|
+
amountIn,
|
|
12389
|
+
evmChainID
|
|
12390
|
+
);
|
|
12391
|
+
const adjustedAmountOut = amountOut * slippageFactor / 1000n;
|
|
12392
|
+
return {
|
|
12393
|
+
amountOut: adjustedAmountOut,
|
|
12394
|
+
calldata: this.createV3SwapCalldataExactIn(
|
|
12395
|
+
tokenIn,
|
|
12396
|
+
tokenOut,
|
|
12397
|
+
amountIn,
|
|
12398
|
+
adjustedAmountOut,
|
|
12399
|
+
fee,
|
|
12400
|
+
recipient,
|
|
12401
|
+
evmChainID,
|
|
12402
|
+
getQuoteIn
|
|
12403
|
+
)
|
|
12404
|
+
};
|
|
12405
|
+
}
|
|
12406
|
+
}
|
|
12265
12407
|
/**
|
|
12266
12408
|
* Checks if an order has been filled by verifying the commitment status on-chain.
|
|
12267
12409
|
* Reads the storage slot corresponding to the order's commitment hash.
|