liquid-sdk 1.5.2 → 1.5.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/index.d.mts +23 -8
- package/dist/index.d.ts +23 -8
- package/dist/index.js +56 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/skills/bid-in-auction.md +129 -90
package/dist/index.mjs
CHANGED
|
@@ -1574,22 +1574,30 @@ var LiquidSDK = class {
|
|
|
1574
1574
|
* The auction lets bidders compete via gas price — the bid amount is
|
|
1575
1575
|
* determined by how much your tx.gasprice exceeds the pool's gasPeg.
|
|
1576
1576
|
*
|
|
1577
|
+
* **Important:** The `amountIn` (swap input) is pulled from the caller's
|
|
1578
|
+
* WETH balance via `transferFrom`. The SDK automatically wraps ETH → WETH
|
|
1579
|
+
* and approves the SniperUtilV2 if needed. The `bidAmount` is sent as
|
|
1580
|
+
* `msg.value` (separate from the swap).
|
|
1581
|
+
*
|
|
1582
|
+
* Gas price must exceed the pool's `gasPeg` — the delta encodes the bid.
|
|
1583
|
+
* Both `maxFeePerGas` and `maxPriorityFeePerGas` are set to ensure the
|
|
1584
|
+
* effective gas price matches on Base (EIP-1559). Gas estimation is skipped
|
|
1585
|
+
* because `eth_estimateGas` simulates at `baseFee` which is below `gasPeg`.
|
|
1586
|
+
*
|
|
1577
1587
|
* @example
|
|
1578
1588
|
* ```typescript
|
|
1579
|
-
* // 1. Get auction state
|
|
1589
|
+
* // 1. Get auction state & pool key
|
|
1580
1590
|
* const state = await sdk.getAuctionState(poolId);
|
|
1591
|
+
* const rewards = await sdk.getTokenRewards(tokenAddress);
|
|
1581
1592
|
*
|
|
1582
1593
|
* // 2. Calculate gas price for desired bid
|
|
1583
1594
|
* const gasPrice = await sdk.getAuctionGasPriceForBid(state.gasPeg, bidAmount);
|
|
1584
1595
|
*
|
|
1585
|
-
* // 3.
|
|
1586
|
-
* const rewards = await sdk.getTokenRewards(tokenAddress);
|
|
1587
|
-
*
|
|
1588
|
-
* // 4. Bid
|
|
1596
|
+
* // 3. Bid (SDK auto-wraps WETH + approves if needed)
|
|
1589
1597
|
* const result = await sdk.bidInAuction({
|
|
1590
1598
|
* poolKey: rewards.poolKey,
|
|
1591
1599
|
* zeroForOne: true, // ETH → token
|
|
1592
|
-
* amountIn: parseEther("0.1"), // swap 0.1 ETH
|
|
1600
|
+
* amountIn: parseEther("0.1"), // swap 0.1 ETH (pulled from WETH balance)
|
|
1593
1601
|
* amountOutMinimum: 0n, // set slippage
|
|
1594
1602
|
* round: state.round,
|
|
1595
1603
|
* bidAmount: parseEther("0.01"),
|
|
@@ -1600,6 +1608,44 @@ var LiquidSDK = class {
|
|
|
1600
1608
|
if (!this.walletClient?.account) {
|
|
1601
1609
|
throw new Error("walletClient with account required for bidInAuction");
|
|
1602
1610
|
}
|
|
1611
|
+
const account = this.walletClient.account;
|
|
1612
|
+
const weth = EXTERNAL.WETH;
|
|
1613
|
+
const wethBalance = await this.publicClient.readContract({
|
|
1614
|
+
address: weth,
|
|
1615
|
+
abi: ERC20Abi,
|
|
1616
|
+
functionName: "balanceOf",
|
|
1617
|
+
args: [account.address]
|
|
1618
|
+
});
|
|
1619
|
+
if (wethBalance < params.amountIn) {
|
|
1620
|
+
const wrapAmount = params.amountIn - wethBalance;
|
|
1621
|
+
const wrapTx = await this.walletClient.writeContract({
|
|
1622
|
+
address: weth,
|
|
1623
|
+
abi: [{ type: "function", name: "deposit", inputs: [], outputs: [], stateMutability: "payable" }],
|
|
1624
|
+
functionName: "deposit",
|
|
1625
|
+
args: [],
|
|
1626
|
+
value: wrapAmount,
|
|
1627
|
+
chain: base2,
|
|
1628
|
+
account
|
|
1629
|
+
});
|
|
1630
|
+
await this.publicClient.waitForTransactionReceipt({ hash: wrapTx });
|
|
1631
|
+
}
|
|
1632
|
+
const allowance = await this.publicClient.readContract({
|
|
1633
|
+
address: weth,
|
|
1634
|
+
abi: ERC20Abi,
|
|
1635
|
+
functionName: "allowance",
|
|
1636
|
+
args: [account.address, ADDRESSES.SNIPER_UTIL_V2]
|
|
1637
|
+
});
|
|
1638
|
+
if (allowance < params.amountIn) {
|
|
1639
|
+
const approveTx = await this.walletClient.writeContract({
|
|
1640
|
+
address: weth,
|
|
1641
|
+
abi: ERC20Abi,
|
|
1642
|
+
functionName: "approve",
|
|
1643
|
+
args: [ADDRESSES.SNIPER_UTIL_V2, params.amountIn * 10n],
|
|
1644
|
+
chain: base2,
|
|
1645
|
+
account
|
|
1646
|
+
});
|
|
1647
|
+
await this.publicClient.waitForTransactionReceipt({ hash: approveTx });
|
|
1648
|
+
}
|
|
1603
1649
|
const hookData = encodeAbiParameters2(
|
|
1604
1650
|
[
|
|
1605
1651
|
{
|
|
@@ -1636,8 +1682,10 @@ var LiquidSDK = class {
|
|
|
1636
1682
|
],
|
|
1637
1683
|
value: params.bidAmount,
|
|
1638
1684
|
chain: base2,
|
|
1639
|
-
account
|
|
1640
|
-
|
|
1685
|
+
account,
|
|
1686
|
+
gas: 500000n,
|
|
1687
|
+
maxFeePerGas,
|
|
1688
|
+
maxPriorityFeePerGas: maxFeePerGas
|
|
1641
1689
|
});
|
|
1642
1690
|
return { txHash };
|
|
1643
1691
|
}
|