@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/node/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/node/index.js
CHANGED
|
@@ -3479,7 +3479,13 @@ var addresses = {
|
|
|
3479
3479
|
["EVM-130" /* UNICHAIN_MAINNET */]: "0x52f0e24d1c21c8a0cb1e5a5dd6198556bd9e1203"
|
|
3480
3480
|
},
|
|
3481
3481
|
Calldispatcher: {
|
|
3482
|
-
["EVM-11155111" /* SEPOLIA */]: "0xC7f13b6D03A0A7F3239d38897503E90553ABe155"
|
|
3482
|
+
["EVM-11155111" /* SEPOLIA */]: "0xC7f13b6D03A0A7F3239d38897503E90553ABe155",
|
|
3483
|
+
["EVM-1" /* MAINNET */]: "0xc71251c8b3e7b02697a84363eef6dce8dfbdf333",
|
|
3484
|
+
["EVM-56" /* BSC_MAINNET */]: "0xc71251c8b3e7b02697a84363eef6dce8dfbdf333",
|
|
3485
|
+
["EVM-42161" /* ARBITRUM_MAINNET */]: "0xc71251c8b3e7b02697a84363eef6dce8dfbdf333",
|
|
3486
|
+
["EVM-8453" /* BASE_MAINNET */]: "0xc71251c8b3e7b02697a84363eef6dce8dfbdf333",
|
|
3487
|
+
["EVM-137" /* POLYGON_MAINNET */]: "0xc71251c8b3e7b02697a84363eef6dce8dfbdf333",
|
|
3488
|
+
["EVM-130" /* UNICHAIN_MAINNET */]: "0xc71251c8b3e7b02697a84363eef6dce8dfbdf333"
|
|
3483
3489
|
},
|
|
3484
3490
|
Permit2: {
|
|
3485
3491
|
["EVM-1" /* MAINNET */]: "0x000000000022D473030F116dDEE9F6B43aC78BA3",
|
|
@@ -3597,6 +3603,9 @@ var ChainConfigService = class {
|
|
|
3597
3603
|
getEtherscanApiKey() {
|
|
3598
3604
|
return typeof process !== "undefined" ? process?.env?.ETHERSCAN_API_KEY : void 0;
|
|
3599
3605
|
}
|
|
3606
|
+
getCalldispatcherAddress(chain) {
|
|
3607
|
+
return addresses.Calldispatcher[chain];
|
|
3608
|
+
}
|
|
3600
3609
|
};
|
|
3601
3610
|
function getPeakPosByHeight(height) {
|
|
3602
3611
|
return (1n << BigInt(height + 1)) - 2n;
|
|
@@ -10355,6 +10364,37 @@ var UNISWAP_V4_QUOTER_ABI = [
|
|
|
10355
10364
|
}
|
|
10356
10365
|
];
|
|
10357
10366
|
|
|
10367
|
+
// src/abis/uniswapV2Pair.ts
|
|
10368
|
+
var ABI6 = [
|
|
10369
|
+
{
|
|
10370
|
+
inputs: [],
|
|
10371
|
+
name: "token0",
|
|
10372
|
+
outputs: [
|
|
10373
|
+
{
|
|
10374
|
+
internalType: "address",
|
|
10375
|
+
name: "",
|
|
10376
|
+
type: "address"
|
|
10377
|
+
}
|
|
10378
|
+
],
|
|
10379
|
+
stateMutability: "view",
|
|
10380
|
+
type: "function"
|
|
10381
|
+
},
|
|
10382
|
+
{
|
|
10383
|
+
inputs: [],
|
|
10384
|
+
name: "token1",
|
|
10385
|
+
outputs: [
|
|
10386
|
+
{
|
|
10387
|
+
internalType: "address",
|
|
10388
|
+
name: "",
|
|
10389
|
+
type: "address"
|
|
10390
|
+
}
|
|
10391
|
+
],
|
|
10392
|
+
stateMutability: "view",
|
|
10393
|
+
type: "function"
|
|
10394
|
+
}
|
|
10395
|
+
];
|
|
10396
|
+
var uniswapV2Pair_default = { ABI: ABI6 };
|
|
10397
|
+
|
|
10358
10398
|
// src/abis/permit2.ts
|
|
10359
10399
|
var PERMIT2_ABI = [
|
|
10360
10400
|
{
|
|
@@ -10387,7 +10427,7 @@ var PERMIT2_ABI = [
|
|
|
10387
10427
|
];
|
|
10388
10428
|
|
|
10389
10429
|
// src/abis/universalRouter.ts
|
|
10390
|
-
var
|
|
10430
|
+
var ABI7 = [
|
|
10391
10431
|
{
|
|
10392
10432
|
inputs: [
|
|
10393
10433
|
{
|
|
@@ -10830,7 +10870,7 @@ var ABI6 = [
|
|
|
10830
10870
|
type: "receive"
|
|
10831
10871
|
}
|
|
10832
10872
|
];
|
|
10833
|
-
var universalRouter_default = { ABI:
|
|
10873
|
+
var universalRouter_default = { ABI: ABI7 };
|
|
10834
10874
|
|
|
10835
10875
|
// src/protocols/intents.ts
|
|
10836
10876
|
var IntentGateway = class {
|
|
@@ -11130,8 +11170,8 @@ var IntentGateway = class {
|
|
|
11130
11170
|
args: [amountOut, [tokenInForQuote, tokenOutForQuote]]
|
|
11131
11171
|
});
|
|
11132
11172
|
return v2AmountIn.result[0];
|
|
11133
|
-
} catch
|
|
11134
|
-
console.warn("V2 quote failed:"
|
|
11173
|
+
} catch {
|
|
11174
|
+
console.warn("V2 quote failed:");
|
|
11135
11175
|
return maxUint256;
|
|
11136
11176
|
}
|
|
11137
11177
|
}
|
|
@@ -11154,8 +11194,8 @@ var IntentGateway = class {
|
|
|
11154
11194
|
args: [amountIn, [tokenInForQuote, tokenOutForQuote]]
|
|
11155
11195
|
});
|
|
11156
11196
|
return v2AmountOut.result[1];
|
|
11157
|
-
} catch
|
|
11158
|
-
console.warn("V2 quote failed:"
|
|
11197
|
+
} catch {
|
|
11198
|
+
console.warn("V2 quote failed:");
|
|
11159
11199
|
return BigInt(0);
|
|
11160
11200
|
}
|
|
11161
11201
|
}
|
|
@@ -11192,7 +11232,7 @@ var IntentGateway = class {
|
|
|
11192
11232
|
bestAmountIn = amountIn;
|
|
11193
11233
|
bestFee = fee;
|
|
11194
11234
|
}
|
|
11195
|
-
} catch
|
|
11235
|
+
} catch {
|
|
11196
11236
|
console.warn(`V3 quote failed for fee ${fee}, continuing to next fee tier`);
|
|
11197
11237
|
}
|
|
11198
11238
|
}
|
|
@@ -11231,7 +11271,7 @@ var IntentGateway = class {
|
|
|
11231
11271
|
bestAmountOut = amountOut;
|
|
11232
11272
|
bestFee = fee;
|
|
11233
11273
|
}
|
|
11234
|
-
} catch
|
|
11274
|
+
} catch {
|
|
11235
11275
|
console.warn(`V3 quote failed for fee ${fee}, continuing to next fee tier`);
|
|
11236
11276
|
}
|
|
11237
11277
|
}
|
|
@@ -11276,7 +11316,7 @@ var IntentGateway = class {
|
|
|
11276
11316
|
bestAmountIn = amountIn;
|
|
11277
11317
|
bestFee = fee;
|
|
11278
11318
|
}
|
|
11279
|
-
} catch
|
|
11319
|
+
} catch {
|
|
11280
11320
|
console.warn(`V4 quote failed for fee ${fee}, continuing to next fee tier`);
|
|
11281
11321
|
}
|
|
11282
11322
|
}
|
|
@@ -11321,7 +11361,7 @@ var IntentGateway = class {
|
|
|
11321
11361
|
bestAmountOut = amountOut;
|
|
11322
11362
|
bestFee = fee;
|
|
11323
11363
|
}
|
|
11324
|
-
} catch
|
|
11364
|
+
} catch {
|
|
11325
11365
|
console.warn(`V4 quote failed for fee ${fee}, continuing to next fee tier`);
|
|
11326
11366
|
}
|
|
11327
11367
|
}
|
|
@@ -12213,6 +12253,108 @@ var IntentGateway = class {
|
|
|
12213
12253
|
};
|
|
12214
12254
|
}
|
|
12215
12255
|
}
|
|
12256
|
+
async createMultiHopSwapThroughPair(dexPairAddress, tokenIn, tokenOut, amountIn, evmChainID, getQuoteIn, recipient, protocol = "v2") {
|
|
12257
|
+
const client = this[getQuoteIn].client;
|
|
12258
|
+
const wethAsset = this[getQuoteIn].config.getWrappedNativeAssetWithDecimals(evmChainID).asset;
|
|
12259
|
+
const calldispatcher = this[getQuoteIn].config.getCalldispatcherAddress(evmChainID);
|
|
12260
|
+
const [token0, token1] = await Promise.all([
|
|
12261
|
+
client.readContract({
|
|
12262
|
+
address: dexPairAddress,
|
|
12263
|
+
abi: uniswapV2Pair_default.ABI,
|
|
12264
|
+
functionName: "token0"
|
|
12265
|
+
}),
|
|
12266
|
+
client.readContract({
|
|
12267
|
+
address: dexPairAddress,
|
|
12268
|
+
abi: uniswapV2Pair_default.ABI,
|
|
12269
|
+
functionName: "token1"
|
|
12270
|
+
})
|
|
12271
|
+
]);
|
|
12272
|
+
const intermediateToken = tokenOut.toLowerCase() === token0.toLowerCase() ? token1 : token0;
|
|
12273
|
+
const swapPath = this.buildSwapPath(tokenIn, tokenOut, intermediateToken, wethAsset, calldispatcher, recipient);
|
|
12274
|
+
return this.executeSwapPath(swapPath, amountIn, evmChainID, getQuoteIn, protocol);
|
|
12275
|
+
}
|
|
12276
|
+
buildSwapPath(tokenIn, tokenOut, intermediateToken, wethAsset, calldispatcher, recipient) {
|
|
12277
|
+
const normalize = (token) => token.toLowerCase();
|
|
12278
|
+
if (normalize(intermediateToken) === normalize(tokenIn)) {
|
|
12279
|
+
return [{ from: tokenIn, to: tokenOut, recipient }];
|
|
12280
|
+
}
|
|
12281
|
+
if (normalize(intermediateToken) === normalize(wethAsset)) {
|
|
12282
|
+
return [
|
|
12283
|
+
{ from: tokenIn, to: wethAsset, recipient: calldispatcher },
|
|
12284
|
+
{ from: wethAsset, to: tokenOut, recipient }
|
|
12285
|
+
];
|
|
12286
|
+
}
|
|
12287
|
+
return [
|
|
12288
|
+
{ from: tokenIn, to: wethAsset, recipient: calldispatcher },
|
|
12289
|
+
{ from: wethAsset, to: intermediateToken, recipient: calldispatcher },
|
|
12290
|
+
{ from: intermediateToken, to: tokenOut, recipient }
|
|
12291
|
+
];
|
|
12292
|
+
}
|
|
12293
|
+
async executeSwapPath(path, initialAmount, evmChainID, getQuoteIn, protocol) {
|
|
12294
|
+
let currentAmount = initialAmount;
|
|
12295
|
+
const calldata = [];
|
|
12296
|
+
for (let i = 0; i < path.length; i++) {
|
|
12297
|
+
const segment = path[i];
|
|
12298
|
+
const isLastSwap = i === path.length - 1;
|
|
12299
|
+
const slippage = isLastSwap && path.length > 1 ? 990n : 995n;
|
|
12300
|
+
const swapResult = await this.createSwapCalldata(
|
|
12301
|
+
protocol,
|
|
12302
|
+
segment.from,
|
|
12303
|
+
segment.to,
|
|
12304
|
+
currentAmount,
|
|
12305
|
+
segment.recipient,
|
|
12306
|
+
evmChainID,
|
|
12307
|
+
getQuoteIn,
|
|
12308
|
+
slippage
|
|
12309
|
+
);
|
|
12310
|
+
currentAmount = swapResult.amountOut;
|
|
12311
|
+
calldata.push(...swapResult.calldata);
|
|
12312
|
+
}
|
|
12313
|
+
return {
|
|
12314
|
+
finalAmountOut: currentAmount,
|
|
12315
|
+
calldata
|
|
12316
|
+
};
|
|
12317
|
+
}
|
|
12318
|
+
async createSwapCalldata(protocol, tokenIn, tokenOut, amountIn, recipient, evmChainID, getQuoteIn, slippageFactor) {
|
|
12319
|
+
if (protocol === "v2") {
|
|
12320
|
+
let amountOut = await this.getV2QuoteWithAmountIn(getQuoteIn, tokenIn, tokenOut, amountIn, evmChainID);
|
|
12321
|
+
amountOut = amountOut * slippageFactor / 1000n;
|
|
12322
|
+
return {
|
|
12323
|
+
amountOut,
|
|
12324
|
+
calldata: this.createV2SwapCalldataExactIn(
|
|
12325
|
+
tokenIn,
|
|
12326
|
+
tokenOut,
|
|
12327
|
+
amountIn,
|
|
12328
|
+
amountOut,
|
|
12329
|
+
recipient,
|
|
12330
|
+
evmChainID,
|
|
12331
|
+
getQuoteIn
|
|
12332
|
+
)
|
|
12333
|
+
};
|
|
12334
|
+
} else {
|
|
12335
|
+
const { amountOut, fee } = await this.getV3QuoteWithAmountIn(
|
|
12336
|
+
getQuoteIn,
|
|
12337
|
+
tokenIn,
|
|
12338
|
+
tokenOut,
|
|
12339
|
+
amountIn,
|
|
12340
|
+
evmChainID
|
|
12341
|
+
);
|
|
12342
|
+
const adjustedAmountOut = amountOut * slippageFactor / 1000n;
|
|
12343
|
+
return {
|
|
12344
|
+
amountOut: adjustedAmountOut,
|
|
12345
|
+
calldata: this.createV3SwapCalldataExactIn(
|
|
12346
|
+
tokenIn,
|
|
12347
|
+
tokenOut,
|
|
12348
|
+
amountIn,
|
|
12349
|
+
adjustedAmountOut,
|
|
12350
|
+
fee,
|
|
12351
|
+
recipient,
|
|
12352
|
+
evmChainID,
|
|
12353
|
+
getQuoteIn
|
|
12354
|
+
)
|
|
12355
|
+
};
|
|
12356
|
+
}
|
|
12357
|
+
}
|
|
12216
12358
|
/**
|
|
12217
12359
|
* Checks if an order has been filled by verifying the commitment status on-chain.
|
|
12218
12360
|
* Reads the storage slot corresponding to the order's commitment hash.
|