punkkit-sdk 1.0.26 → 1.0.29
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 +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +115 -75
- package/dist/index.mjs +115 -75
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -131,6 +131,16 @@ interface ModifyPositionParams {
|
|
|
131
131
|
|
|
132
132
|
declare function addLiq(wallet: Wallet, priceLower: number, priceUpper: number, amount0: bigint | number, amount1: bigint | number, poolKey: PoolKey): Promise<ethers.providers.TransactionReceipt>;
|
|
133
133
|
|
|
134
|
+
/**
|
|
135
|
+
* Removes liquidity by directly specifying exact tick ranges and the liquidity delta to remove.
|
|
136
|
+
* This is primarily used when matching with the frontend's position data.
|
|
137
|
+
*/
|
|
138
|
+
declare function removeLiqByPosition(wallet: Wallet, tickLower: number, tickUpper: number, liquidityToRemove: bigint | string): Promise<providers.TransactionReceipt>;
|
|
139
|
+
/**
|
|
140
|
+
* Legacy support: calculate liquidity to remove via token amount projections.
|
|
141
|
+
*/
|
|
142
|
+
declare function removeLiq(wallet: Wallet, priceLower: number, priceUpper: number, amount0: bigint, amount1: bigint, poolKey: PoolKey): Promise<providers.TransactionReceipt>;
|
|
143
|
+
|
|
134
144
|
interface UserPosition {
|
|
135
145
|
tokenId: number;
|
|
136
146
|
tickLower: number;
|
|
@@ -204,4 +214,4 @@ declare function balanceOf(contractAddress: string, provider: SignerOrProvider,
|
|
|
204
214
|
declare function getAllVouchers(contractAddress: string, provider: SignerOrProvider): Promise<string[]>;
|
|
205
215
|
declare function BuildUseVoucherTx(tx: providers.TransactionRequest, voucherName: string): providers.TransactionRequest;
|
|
206
216
|
|
|
207
|
-
export { BuildUseVoucherTx, type ChallengeMatchResultParams, type CreateAuctionConfigParams, type CreateAuctionParams, type ModifyPositionParams, type PlaceBidParams, type PoolKey, type RevealBidParams, type RevealLockParams, type SetUnlockStrategyParams, type SignerOrProvider, type SubmitMatchResultsParams, type SwapParams, type UnlockTokensParams, type UserPosition, type WithdrawMatchResultParams, addLiq, amount0, amount1, balanceOf, buyVoucher, buyVoucherWithEth, calculateLiqDelta, calculatePriceFromTick, calculateTickFromPrice, calculateTickFromPriceWithSpacing, createAuction$1 as createAuction, createAuctionConfig, createAuction as createAuctionOnVault, createVoucher, getActiveAuctionsCount, getAllVouchers, getAuctionContract, getAuctionInfo, getAuctionLockInfo, getContract, getCurrentTick, getLiquidity, getLockInfo, getMatchResult, getPoolId, getPoolPrice, getPoolSqrtPrice, getProvider, getSqrtPriceAtTick, getUserPositions, getVoucherContract, getVoucherInfo, liquidity0, liquidity1, main, modifyPosition, mutiVoucherABI, placeBid, priceToSqrtPrice, revealBid, revealLock, submitMatchResults, swap, toWei, unlockTokens, useVoucher, withdrawMatchResult };
|
|
217
|
+
export { BuildUseVoucherTx, type ChallengeMatchResultParams, type CreateAuctionConfigParams, type CreateAuctionParams, type ModifyPositionParams, type PlaceBidParams, type PoolKey, type RevealBidParams, type RevealLockParams, type SetUnlockStrategyParams, type SignerOrProvider, type SubmitMatchResultsParams, type SwapParams, type UnlockTokensParams, type UserPosition, type WithdrawMatchResultParams, addLiq, amount0, amount1, balanceOf, buyVoucher, buyVoucherWithEth, calculateLiqDelta, calculatePriceFromTick, calculateTickFromPrice, calculateTickFromPriceWithSpacing, createAuction$1 as createAuction, createAuctionConfig, createAuction as createAuctionOnVault, createVoucher, getActiveAuctionsCount, getAllVouchers, getAuctionContract, getAuctionInfo, getAuctionLockInfo, getContract, getCurrentTick, getLiquidity, getLockInfo, getMatchResult, getPoolId, getPoolPrice, getPoolSqrtPrice, getProvider, getSqrtPriceAtTick, getUserPositions, getVoucherContract, getVoucherInfo, liquidity0, liquidity1, main, modifyPosition, mutiVoucherABI, placeBid, priceToSqrtPrice, removeLiq, removeLiqByPosition, revealBid, revealLock, submitMatchResults, swap, toWei, unlockTokens, useVoucher, withdrawMatchResult };
|
package/dist/index.d.ts
CHANGED
|
@@ -131,6 +131,16 @@ interface ModifyPositionParams {
|
|
|
131
131
|
|
|
132
132
|
declare function addLiq(wallet: Wallet, priceLower: number, priceUpper: number, amount0: bigint | number, amount1: bigint | number, poolKey: PoolKey): Promise<ethers.providers.TransactionReceipt>;
|
|
133
133
|
|
|
134
|
+
/**
|
|
135
|
+
* Removes liquidity by directly specifying exact tick ranges and the liquidity delta to remove.
|
|
136
|
+
* This is primarily used when matching with the frontend's position data.
|
|
137
|
+
*/
|
|
138
|
+
declare function removeLiqByPosition(wallet: Wallet, tickLower: number, tickUpper: number, liquidityToRemove: bigint | string): Promise<providers.TransactionReceipt>;
|
|
139
|
+
/**
|
|
140
|
+
* Legacy support: calculate liquidity to remove via token amount projections.
|
|
141
|
+
*/
|
|
142
|
+
declare function removeLiq(wallet: Wallet, priceLower: number, priceUpper: number, amount0: bigint, amount1: bigint, poolKey: PoolKey): Promise<providers.TransactionReceipt>;
|
|
143
|
+
|
|
134
144
|
interface UserPosition {
|
|
135
145
|
tokenId: number;
|
|
136
146
|
tickLower: number;
|
|
@@ -204,4 +214,4 @@ declare function balanceOf(contractAddress: string, provider: SignerOrProvider,
|
|
|
204
214
|
declare function getAllVouchers(contractAddress: string, provider: SignerOrProvider): Promise<string[]>;
|
|
205
215
|
declare function BuildUseVoucherTx(tx: providers.TransactionRequest, voucherName: string): providers.TransactionRequest;
|
|
206
216
|
|
|
207
|
-
export { BuildUseVoucherTx, type ChallengeMatchResultParams, type CreateAuctionConfigParams, type CreateAuctionParams, type ModifyPositionParams, type PlaceBidParams, type PoolKey, type RevealBidParams, type RevealLockParams, type SetUnlockStrategyParams, type SignerOrProvider, type SubmitMatchResultsParams, type SwapParams, type UnlockTokensParams, type UserPosition, type WithdrawMatchResultParams, addLiq, amount0, amount1, balanceOf, buyVoucher, buyVoucherWithEth, calculateLiqDelta, calculatePriceFromTick, calculateTickFromPrice, calculateTickFromPriceWithSpacing, createAuction$1 as createAuction, createAuctionConfig, createAuction as createAuctionOnVault, createVoucher, getActiveAuctionsCount, getAllVouchers, getAuctionContract, getAuctionInfo, getAuctionLockInfo, getContract, getCurrentTick, getLiquidity, getLockInfo, getMatchResult, getPoolId, getPoolPrice, getPoolSqrtPrice, getProvider, getSqrtPriceAtTick, getUserPositions, getVoucherContract, getVoucherInfo, liquidity0, liquidity1, main, modifyPosition, mutiVoucherABI, placeBid, priceToSqrtPrice, revealBid, revealLock, submitMatchResults, swap, toWei, unlockTokens, useVoucher, withdrawMatchResult };
|
|
217
|
+
export { BuildUseVoucherTx, type ChallengeMatchResultParams, type CreateAuctionConfigParams, type CreateAuctionParams, type ModifyPositionParams, type PlaceBidParams, type PoolKey, type RevealBidParams, type RevealLockParams, type SetUnlockStrategyParams, type SignerOrProvider, type SubmitMatchResultsParams, type SwapParams, type UnlockTokensParams, type UserPosition, type WithdrawMatchResultParams, addLiq, amount0, amount1, balanceOf, buyVoucher, buyVoucherWithEth, calculateLiqDelta, calculatePriceFromTick, calculateTickFromPrice, calculateTickFromPriceWithSpacing, createAuction$1 as createAuction, createAuctionConfig, createAuction as createAuctionOnVault, createVoucher, getActiveAuctionsCount, getAllVouchers, getAuctionContract, getAuctionInfo, getAuctionLockInfo, getContract, getCurrentTick, getLiquidity, getLockInfo, getMatchResult, getPoolId, getPoolPrice, getPoolSqrtPrice, getProvider, getSqrtPriceAtTick, getUserPositions, getVoucherContract, getVoucherInfo, liquidity0, liquidity1, main, modifyPosition, mutiVoucherABI, placeBid, priceToSqrtPrice, removeLiq, removeLiqByPosition, revealBid, revealLock, submitMatchResults, swap, toWei, unlockTokens, useVoucher, withdrawMatchResult };
|
package/dist/index.js
CHANGED
|
@@ -31487,6 +31487,30 @@ var init_lib49 = __esm({
|
|
|
31487
31487
|
}
|
|
31488
31488
|
});
|
|
31489
31489
|
|
|
31490
|
+
// config/addresses.json
|
|
31491
|
+
var addresses_default;
|
|
31492
|
+
var init_addresses3 = __esm({
|
|
31493
|
+
"config/addresses.json"() {
|
|
31494
|
+
addresses_default = {
|
|
31495
|
+
mutiVoucher: "0x0000000000000000000000000000000000000044",
|
|
31496
|
+
auction: {
|
|
31497
|
+
chainYVaultV2: "0xAa9e62EB6d74d66Ff6720D1A8143c8237067Ff58",
|
|
31498
|
+
chainXAuctionV2: "0x88566F811b751Fa527A0816d99d6968E00f2eBef",
|
|
31499
|
+
coinbase: "0xAa9e62EB6d74d66Ff6720D1A8143c8237067Ff58"
|
|
31500
|
+
},
|
|
31501
|
+
uniswap: {
|
|
31502
|
+
create2: "0xc5a5C42992dECbae36851359345FE25997F5C42d",
|
|
31503
|
+
token0: "0x18c714d6cc9A38DBb369a8c47A8744016F8D7055",
|
|
31504
|
+
token1: "0x8B4eEeBE05048C084AB739deB29d94E8E0d07A6E",
|
|
31505
|
+
poolManager: "0x4cb143D21145BcAf06D2c5557927E2939Aa0FAfe",
|
|
31506
|
+
liquidPool: "0xB3AEA00D39f4dEE364D767Cd0fb7B437d415Fb9C",
|
|
31507
|
+
limitOrder: "0xE8feDC742EDE9852c7F3E2c3793a2A98C1c7D040",
|
|
31508
|
+
dynamicFee: "0xA0C0C10e144D34EB501A42Df0EdB5C45D40Ad040"
|
|
31509
|
+
}
|
|
31510
|
+
};
|
|
31511
|
+
}
|
|
31512
|
+
});
|
|
31513
|
+
|
|
31490
31514
|
// config/env.config.ts
|
|
31491
31515
|
function getEnvValue(key3, defaultValue) {
|
|
31492
31516
|
const value = process.env[key3];
|
|
@@ -31534,20 +31558,20 @@ function loadConfig() {
|
|
|
31534
31558
|
)
|
|
31535
31559
|
},
|
|
31536
31560
|
contracts: {
|
|
31537
|
-
mutiVoucher:
|
|
31561
|
+
mutiVoucher: addresses_default.mutiVoucher,
|
|
31538
31562
|
auction: {
|
|
31539
|
-
chainYVaultV2:
|
|
31540
|
-
chainXAuctionV2:
|
|
31541
|
-
coinbase:
|
|
31563
|
+
chainYVaultV2: addresses_default.auction.chainYVaultV2,
|
|
31564
|
+
chainXAuctionV2: addresses_default.auction.chainXAuctionV2,
|
|
31565
|
+
coinbase: addresses_default.auction.coinbase
|
|
31542
31566
|
},
|
|
31543
31567
|
uniswap: {
|
|
31544
|
-
create2:
|
|
31545
|
-
token0:
|
|
31546
|
-
token1:
|
|
31547
|
-
poolManager:
|
|
31548
|
-
liquidPool:
|
|
31549
|
-
limitOrder:
|
|
31550
|
-
dynamicFee:
|
|
31568
|
+
create2: addresses_default.uniswap.create2,
|
|
31569
|
+
token0: addresses_default.uniswap.token0,
|
|
31570
|
+
token1: addresses_default.uniswap.token1,
|
|
31571
|
+
poolManager: addresses_default.uniswap.poolManager,
|
|
31572
|
+
liquidPool: addresses_default.uniswap.liquidPool,
|
|
31573
|
+
limitOrder: addresses_default.uniswap.limitOrder,
|
|
31574
|
+
dynamicFee: addresses_default.uniswap.dynamicFee
|
|
31551
31575
|
}
|
|
31552
31576
|
},
|
|
31553
31577
|
abiPaths: {
|
|
@@ -31586,6 +31610,7 @@ var init_env_config = __esm({
|
|
|
31586
31610
|
"config/env.config.ts"() {
|
|
31587
31611
|
"use strict";
|
|
31588
31612
|
init_lib49();
|
|
31613
|
+
init_addresses3();
|
|
31589
31614
|
config = loadConfig();
|
|
31590
31615
|
RPC_URL = config.rpc.url;
|
|
31591
31616
|
PRIVATE_KEY = config.wallet.privateKey;
|
|
@@ -36119,64 +36144,6 @@ var init_contract = __esm({
|
|
|
36119
36144
|
}
|
|
36120
36145
|
});
|
|
36121
36146
|
|
|
36122
|
-
// src/uniswap/1-marketprice/removeLiquidity.ts
|
|
36123
|
-
var require_removeLiquidity = __commonJS({
|
|
36124
|
-
"src/uniswap/1-marketprice/removeLiquidity.ts"(exports2, module2) {
|
|
36125
|
-
"use strict";
|
|
36126
|
-
init_lib49();
|
|
36127
|
-
init_uniswap_config();
|
|
36128
|
-
init_pool();
|
|
36129
|
-
init_ERC20();
|
|
36130
|
-
init_liqCalculation();
|
|
36131
|
-
init_contract();
|
|
36132
|
-
async function removeLiq(wallet2, priceLower, priceUpper, amount02, amount12, poolKey) {
|
|
36133
|
-
const ticklow = calculateTickFromPriceWithSpacing(priceLower, poolKey.tickSpacing);
|
|
36134
|
-
const tickhigh = calculateTickFromPriceWithSpacing(priceUpper, poolKey.tickSpacing);
|
|
36135
|
-
const liqPool = await getContract(wallet2, "LiquidPool");
|
|
36136
|
-
const sqrtCurrent = await getPoolSqrtPrice(liqPool);
|
|
36137
|
-
const [liqDelta, amount0Rmv, amount1Rmv] = calculateLiqDelta(ticklow, sqrtCurrent, tickhigh, amount02, amount12);
|
|
36138
|
-
console.log(`Attempting to remove liquidity ${liqDelta} to price range [${priceLower}, ${priceUpper}] with amount0[${amount0Rmv.toString()}], amount1[${amount1Rmv.toString()}]`);
|
|
36139
|
-
const modifyPositionParams = {
|
|
36140
|
-
tickLower: ticklow,
|
|
36141
|
-
tickUpper: tickhigh,
|
|
36142
|
-
liquidityDelta: liqDelta * BigInt(-1)
|
|
36143
|
-
};
|
|
36144
|
-
await modifyPosition(liqPool, modifyPositionParams, "0x00");
|
|
36145
|
-
}
|
|
36146
|
-
async function main3() {
|
|
36147
|
-
const provider2 = new lib_exports3.JsonRpcProvider(RPC_URL);
|
|
36148
|
-
const wallet2 = new Wallet(PRIVATE_KEY, provider2);
|
|
36149
|
-
const liqPoolAddress = CONTRACT_ADDRESSES.LiquidPool;
|
|
36150
|
-
const token0 = await getContract(wallet2, "Token0");
|
|
36151
|
-
const token1 = await getContract(wallet2, "Token1");
|
|
36152
|
-
const liqPool = await getContract(wallet2, "LiquidPool");
|
|
36153
|
-
let poolPrice = await getPoolPrice(liqPool);
|
|
36154
|
-
console.log(`Current price of pool ${liqPool.address} before removing liquidity is ${poolPrice}`);
|
|
36155
|
-
const token0Before = await getERC20Balance(token0, wallet2.address);
|
|
36156
|
-
const token1Before = await getERC20Balance(token1, wallet2.address);
|
|
36157
|
-
console.log("Token0 balance before removing liquidity:", token0Before.toString());
|
|
36158
|
-
console.log("Token1 balance before removing liquidity:", token1Before.toString());
|
|
36159
|
-
const priceLower = 0.5;
|
|
36160
|
-
const priceUpper = 1.5;
|
|
36161
|
-
const amount02 = 100n;
|
|
36162
|
-
const amount12 = 100n;
|
|
36163
|
-
await removeLiq(wallet2, priceLower, priceUpper, amount02, amount12, POOL_KEYS.limitOrderPoolKey);
|
|
36164
|
-
poolPrice = await getPoolPrice(liqPool);
|
|
36165
|
-
console.log(`Current price of pool ${liqPool.address} after removing liquidity is ${poolPrice}`);
|
|
36166
|
-
const token0After = await getERC20Balance(token0, wallet2.address);
|
|
36167
|
-
const token1After = await getERC20Balance(token1, wallet2.address);
|
|
36168
|
-
console.log("Token0 change:", token0After - token0Before);
|
|
36169
|
-
console.log("Token1 change:", token1After - token1Before);
|
|
36170
|
-
}
|
|
36171
|
-
if (typeof require !== "undefined" && typeof module2 !== "undefined" && require.main === module2) {
|
|
36172
|
-
main3().catch((error) => {
|
|
36173
|
-
console.error(error);
|
|
36174
|
-
process.exit(1);
|
|
36175
|
-
});
|
|
36176
|
-
}
|
|
36177
|
-
}
|
|
36178
|
-
});
|
|
36179
|
-
|
|
36180
36147
|
// src/uniswap/2-limitorder/place.ts
|
|
36181
36148
|
var require_place = __commonJS({
|
|
36182
36149
|
"src/uniswap/2-limitorder/place.ts"(exports2, module2) {
|
|
@@ -36237,7 +36204,7 @@ var require_place = __commonJS({
|
|
|
36237
36204
|
const epoch = await placeLimitOrder(hook, poolKey, ticklow, zeroForOne, liquidity);
|
|
36238
36205
|
return epoch;
|
|
36239
36206
|
}
|
|
36240
|
-
async function
|
|
36207
|
+
async function main4() {
|
|
36241
36208
|
const provider2 = new ethers_exports.providers.JsonRpcProvider(RPC_URL);
|
|
36242
36209
|
const wallet2 = new ethers_exports.Wallet(PRIVATE_KEY, provider2);
|
|
36243
36210
|
const token0 = await getContract(wallet2, "Token0");
|
|
@@ -36254,7 +36221,7 @@ var require_place = __commonJS({
|
|
|
36254
36221
|
console.log("Token1 change:", token1After - token1Before);
|
|
36255
36222
|
}
|
|
36256
36223
|
if (typeof require !== "undefined" && typeof module2 !== "undefined" && require.main === module2) {
|
|
36257
|
-
|
|
36224
|
+
main4().catch((error) => {
|
|
36258
36225
|
console.error(error);
|
|
36259
36226
|
process.exit(1);
|
|
36260
36227
|
});
|
|
@@ -36305,6 +36272,8 @@ __export(index_exports, {
|
|
|
36305
36272
|
mutiVoucherABI: () => mutiVoucherABI,
|
|
36306
36273
|
placeBid: () => placeBid,
|
|
36307
36274
|
priceToSqrtPrice: () => priceToSqrtPrice,
|
|
36275
|
+
removeLiq: () => removeLiq,
|
|
36276
|
+
removeLiqByPosition: () => removeLiqByPosition,
|
|
36308
36277
|
revealBid: () => revealBid,
|
|
36309
36278
|
revealLock: () => revealLock,
|
|
36310
36279
|
submitMatchResults: () => submitMatchResults,
|
|
@@ -38699,8 +38668,77 @@ if (typeof require !== "undefined" && typeof module !== "undefined" && require.m
|
|
|
38699
38668
|
});
|
|
38700
38669
|
}
|
|
38701
38670
|
|
|
38702
|
-
// src/
|
|
38703
|
-
|
|
38671
|
+
// src/uniswap/1-marketprice/removeLiquidity.ts
|
|
38672
|
+
init_lib49();
|
|
38673
|
+
init_uniswap_config();
|
|
38674
|
+
init_pool();
|
|
38675
|
+
init_ERC20();
|
|
38676
|
+
init_liqCalculation();
|
|
38677
|
+
init_contract();
|
|
38678
|
+
async function removeLiqByPosition(wallet2, tickLower, tickUpper, liquidityToRemove) {
|
|
38679
|
+
const liqPool = await getContract(wallet2, "LiquidPool");
|
|
38680
|
+
let liqDelta = BigInt(liquidityToRemove.toString());
|
|
38681
|
+
if (liqDelta === 0n) {
|
|
38682
|
+
throw new Error("[SDK] Error: Cannot remove 0 liquidity. Action aborted.");
|
|
38683
|
+
}
|
|
38684
|
+
if (liqDelta > 0n) {
|
|
38685
|
+
liqDelta = liqDelta * -1n;
|
|
38686
|
+
}
|
|
38687
|
+
console.log(`[SDK] Attempting to remove liquidity ${liqDelta} from ticks [${tickLower}, ${tickUpper}]`);
|
|
38688
|
+
const modifyPositionParams = {
|
|
38689
|
+
tickLower,
|
|
38690
|
+
tickUpper,
|
|
38691
|
+
liquidityDelta: liqDelta
|
|
38692
|
+
};
|
|
38693
|
+
const receipt = await modifyPosition(liqPool, modifyPositionParams, "0x00");
|
|
38694
|
+
return receipt;
|
|
38695
|
+
}
|
|
38696
|
+
async function removeLiq(wallet2, priceLower, priceUpper, amount02, amount12, poolKey) {
|
|
38697
|
+
const ticklow = calculateTickFromPriceWithSpacing(priceLower, poolKey.tickSpacing);
|
|
38698
|
+
const tickhigh = calculateTickFromPriceWithSpacing(priceUpper, poolKey.tickSpacing);
|
|
38699
|
+
const liqPool = await getContract(wallet2, "LiquidPool");
|
|
38700
|
+
const sqrtCurrent = await getPoolSqrtPrice(liqPool);
|
|
38701
|
+
const [liqDelta, amount0Rmv, amount1Rmv] = calculateLiqDelta(ticklow, sqrtCurrent, tickhigh, amount02, amount12);
|
|
38702
|
+
console.log(`Attempting to remove liquidity ${liqDelta} to price range [${priceLower}, ${priceUpper}] with amount0[${amount0Rmv.toString()}], amount1[${amount1Rmv.toString()}]`);
|
|
38703
|
+
const modifyPositionParams = {
|
|
38704
|
+
tickLower: ticklow,
|
|
38705
|
+
tickUpper: tickhigh,
|
|
38706
|
+
liquidityDelta: liqDelta * -1n
|
|
38707
|
+
};
|
|
38708
|
+
const receipt = await modifyPosition(liqPool, modifyPositionParams, "0x00");
|
|
38709
|
+
return receipt;
|
|
38710
|
+
}
|
|
38711
|
+
async function main3() {
|
|
38712
|
+
const provider2 = new lib_exports3.JsonRpcProvider(RPC_URL);
|
|
38713
|
+
const wallet2 = new Wallet(PRIVATE_KEY, provider2);
|
|
38714
|
+
const liqPoolAddress = CONTRACT_ADDRESSES.LiquidPool;
|
|
38715
|
+
const token0 = await getContract(wallet2, "Token0");
|
|
38716
|
+
const token1 = await getContract(wallet2, "Token1");
|
|
38717
|
+
const liqPool = await getContract(wallet2, "LiquidPool");
|
|
38718
|
+
let poolPrice = await getPoolPrice(liqPool);
|
|
38719
|
+
console.log(`Current price of pool ${liqPool.address} before removing liquidity is ${poolPrice}`);
|
|
38720
|
+
const token0Before = await getERC20Balance(token0, wallet2.address);
|
|
38721
|
+
const token1Before = await getERC20Balance(token1, wallet2.address);
|
|
38722
|
+
console.log("Token0 balance before removing liquidity:", token0Before.toString());
|
|
38723
|
+
console.log("Token1 balance before removing liquidity:", token1Before.toString());
|
|
38724
|
+
const priceLower = 0.5;
|
|
38725
|
+
const priceUpper = 1.5;
|
|
38726
|
+
const amount02 = 100n;
|
|
38727
|
+
const amount12 = 100n;
|
|
38728
|
+
await removeLiq(wallet2, priceLower, priceUpper, amount02, amount12, POOL_KEYS.limitOrderPoolKey);
|
|
38729
|
+
poolPrice = await getPoolPrice(liqPool);
|
|
38730
|
+
console.log(`Current price of pool ${liqPool.address} after removing liquidity is ${poolPrice}`);
|
|
38731
|
+
const token0After = await getERC20Balance(token0, wallet2.address);
|
|
38732
|
+
const token1After = await getERC20Balance(token1, wallet2.address);
|
|
38733
|
+
console.log("Token0 change:", token0After - token0Before);
|
|
38734
|
+
console.log("Token1 change:", token1After - token1Before);
|
|
38735
|
+
}
|
|
38736
|
+
if (typeof require !== "undefined" && typeof module !== "undefined" && require.main === module) {
|
|
38737
|
+
main3().catch((error) => {
|
|
38738
|
+
console.error(error);
|
|
38739
|
+
process.exit(1);
|
|
38740
|
+
});
|
|
38741
|
+
}
|
|
38704
38742
|
|
|
38705
38743
|
// src/uniswap/1-marketprice/getPositions.ts
|
|
38706
38744
|
init_contract();
|
|
@@ -38719,8 +38757,8 @@ async function getUserPositions(wallet2, userAddress) {
|
|
|
38719
38757
|
// liquidity is int256, keep as string to prevent JS precision loss
|
|
38720
38758
|
liquidity: pos.liquidity.toString()
|
|
38721
38759
|
};
|
|
38722
|
-
});
|
|
38723
|
-
console.log(`[SDK] Found ${formattedPositions.length} position(s).`);
|
|
38760
|
+
}).filter((pos) => pos.liquidity !== "0");
|
|
38761
|
+
console.log(`[SDK] Found ${formattedPositions.length} active position(s).`);
|
|
38724
38762
|
return formattedPositions;
|
|
38725
38763
|
} catch (error) {
|
|
38726
38764
|
console.error(`[SDK] Failed to fetch user positions: `, error);
|
|
@@ -39033,6 +39071,8 @@ function BuildUseVoucherTx(tx, voucherName) {
|
|
|
39033
39071
|
mutiVoucherABI,
|
|
39034
39072
|
placeBid,
|
|
39035
39073
|
priceToSqrtPrice,
|
|
39074
|
+
removeLiq,
|
|
39075
|
+
removeLiqByPosition,
|
|
39036
39076
|
revealBid,
|
|
39037
39077
|
revealLock,
|
|
39038
39078
|
submitMatchResults,
|
package/dist/index.mjs
CHANGED
|
@@ -31491,6 +31491,30 @@ var init_lib49 = __esm({
|
|
|
31491
31491
|
}
|
|
31492
31492
|
});
|
|
31493
31493
|
|
|
31494
|
+
// config/addresses.json
|
|
31495
|
+
var addresses_default;
|
|
31496
|
+
var init_addresses3 = __esm({
|
|
31497
|
+
"config/addresses.json"() {
|
|
31498
|
+
addresses_default = {
|
|
31499
|
+
mutiVoucher: "0x0000000000000000000000000000000000000044",
|
|
31500
|
+
auction: {
|
|
31501
|
+
chainYVaultV2: "0xAa9e62EB6d74d66Ff6720D1A8143c8237067Ff58",
|
|
31502
|
+
chainXAuctionV2: "0x88566F811b751Fa527A0816d99d6968E00f2eBef",
|
|
31503
|
+
coinbase: "0xAa9e62EB6d74d66Ff6720D1A8143c8237067Ff58"
|
|
31504
|
+
},
|
|
31505
|
+
uniswap: {
|
|
31506
|
+
create2: "0xc5a5C42992dECbae36851359345FE25997F5C42d",
|
|
31507
|
+
token0: "0x18c714d6cc9A38DBb369a8c47A8744016F8D7055",
|
|
31508
|
+
token1: "0x8B4eEeBE05048C084AB739deB29d94E8E0d07A6E",
|
|
31509
|
+
poolManager: "0x4cb143D21145BcAf06D2c5557927E2939Aa0FAfe",
|
|
31510
|
+
liquidPool: "0xB3AEA00D39f4dEE364D767Cd0fb7B437d415Fb9C",
|
|
31511
|
+
limitOrder: "0xE8feDC742EDE9852c7F3E2c3793a2A98C1c7D040",
|
|
31512
|
+
dynamicFee: "0xA0C0C10e144D34EB501A42Df0EdB5C45D40Ad040"
|
|
31513
|
+
}
|
|
31514
|
+
};
|
|
31515
|
+
}
|
|
31516
|
+
});
|
|
31517
|
+
|
|
31494
31518
|
// config/env.config.ts
|
|
31495
31519
|
function getEnvValue(key3, defaultValue) {
|
|
31496
31520
|
const value = process.env[key3];
|
|
@@ -31538,20 +31562,20 @@ function loadConfig() {
|
|
|
31538
31562
|
)
|
|
31539
31563
|
},
|
|
31540
31564
|
contracts: {
|
|
31541
|
-
mutiVoucher:
|
|
31565
|
+
mutiVoucher: addresses_default.mutiVoucher,
|
|
31542
31566
|
auction: {
|
|
31543
|
-
chainYVaultV2:
|
|
31544
|
-
chainXAuctionV2:
|
|
31545
|
-
coinbase:
|
|
31567
|
+
chainYVaultV2: addresses_default.auction.chainYVaultV2,
|
|
31568
|
+
chainXAuctionV2: addresses_default.auction.chainXAuctionV2,
|
|
31569
|
+
coinbase: addresses_default.auction.coinbase
|
|
31546
31570
|
},
|
|
31547
31571
|
uniswap: {
|
|
31548
|
-
create2:
|
|
31549
|
-
token0:
|
|
31550
|
-
token1:
|
|
31551
|
-
poolManager:
|
|
31552
|
-
liquidPool:
|
|
31553
|
-
limitOrder:
|
|
31554
|
-
dynamicFee:
|
|
31572
|
+
create2: addresses_default.uniswap.create2,
|
|
31573
|
+
token0: addresses_default.uniswap.token0,
|
|
31574
|
+
token1: addresses_default.uniswap.token1,
|
|
31575
|
+
poolManager: addresses_default.uniswap.poolManager,
|
|
31576
|
+
liquidPool: addresses_default.uniswap.liquidPool,
|
|
31577
|
+
limitOrder: addresses_default.uniswap.limitOrder,
|
|
31578
|
+
dynamicFee: addresses_default.uniswap.dynamicFee
|
|
31555
31579
|
}
|
|
31556
31580
|
},
|
|
31557
31581
|
abiPaths: {
|
|
@@ -31590,6 +31614,7 @@ var init_env_config = __esm({
|
|
|
31590
31614
|
"config/env.config.ts"() {
|
|
31591
31615
|
"use strict";
|
|
31592
31616
|
init_lib49();
|
|
31617
|
+
init_addresses3();
|
|
31593
31618
|
config = loadConfig();
|
|
31594
31619
|
RPC_URL = config.rpc.url;
|
|
31595
31620
|
PRIVATE_KEY = config.wallet.privateKey;
|
|
@@ -36123,64 +36148,6 @@ var init_contract = __esm({
|
|
|
36123
36148
|
}
|
|
36124
36149
|
});
|
|
36125
36150
|
|
|
36126
|
-
// src/uniswap/1-marketprice/removeLiquidity.ts
|
|
36127
|
-
var require_removeLiquidity = __commonJS({
|
|
36128
|
-
"src/uniswap/1-marketprice/removeLiquidity.ts"(exports, module2) {
|
|
36129
|
-
"use strict";
|
|
36130
|
-
init_lib49();
|
|
36131
|
-
init_uniswap_config();
|
|
36132
|
-
init_pool();
|
|
36133
|
-
init_ERC20();
|
|
36134
|
-
init_liqCalculation();
|
|
36135
|
-
init_contract();
|
|
36136
|
-
async function removeLiq(wallet2, priceLower, priceUpper, amount02, amount12, poolKey) {
|
|
36137
|
-
const ticklow = calculateTickFromPriceWithSpacing(priceLower, poolKey.tickSpacing);
|
|
36138
|
-
const tickhigh = calculateTickFromPriceWithSpacing(priceUpper, poolKey.tickSpacing);
|
|
36139
|
-
const liqPool = await getContract(wallet2, "LiquidPool");
|
|
36140
|
-
const sqrtCurrent = await getPoolSqrtPrice(liqPool);
|
|
36141
|
-
const [liqDelta, amount0Rmv, amount1Rmv] = calculateLiqDelta(ticklow, sqrtCurrent, tickhigh, amount02, amount12);
|
|
36142
|
-
console.log(`Attempting to remove liquidity ${liqDelta} to price range [${priceLower}, ${priceUpper}] with amount0[${amount0Rmv.toString()}], amount1[${amount1Rmv.toString()}]`);
|
|
36143
|
-
const modifyPositionParams = {
|
|
36144
|
-
tickLower: ticklow,
|
|
36145
|
-
tickUpper: tickhigh,
|
|
36146
|
-
liquidityDelta: liqDelta * BigInt(-1)
|
|
36147
|
-
};
|
|
36148
|
-
await modifyPosition(liqPool, modifyPositionParams, "0x00");
|
|
36149
|
-
}
|
|
36150
|
-
async function main3() {
|
|
36151
|
-
const provider2 = new lib_exports3.JsonRpcProvider(RPC_URL);
|
|
36152
|
-
const wallet2 = new Wallet(PRIVATE_KEY, provider2);
|
|
36153
|
-
const liqPoolAddress = CONTRACT_ADDRESSES.LiquidPool;
|
|
36154
|
-
const token0 = await getContract(wallet2, "Token0");
|
|
36155
|
-
const token1 = await getContract(wallet2, "Token1");
|
|
36156
|
-
const liqPool = await getContract(wallet2, "LiquidPool");
|
|
36157
|
-
let poolPrice = await getPoolPrice(liqPool);
|
|
36158
|
-
console.log(`Current price of pool ${liqPool.address} before removing liquidity is ${poolPrice}`);
|
|
36159
|
-
const token0Before = await getERC20Balance(token0, wallet2.address);
|
|
36160
|
-
const token1Before = await getERC20Balance(token1, wallet2.address);
|
|
36161
|
-
console.log("Token0 balance before removing liquidity:", token0Before.toString());
|
|
36162
|
-
console.log("Token1 balance before removing liquidity:", token1Before.toString());
|
|
36163
|
-
const priceLower = 0.5;
|
|
36164
|
-
const priceUpper = 1.5;
|
|
36165
|
-
const amount02 = 100n;
|
|
36166
|
-
const amount12 = 100n;
|
|
36167
|
-
await removeLiq(wallet2, priceLower, priceUpper, amount02, amount12, POOL_KEYS.limitOrderPoolKey);
|
|
36168
|
-
poolPrice = await getPoolPrice(liqPool);
|
|
36169
|
-
console.log(`Current price of pool ${liqPool.address} after removing liquidity is ${poolPrice}`);
|
|
36170
|
-
const token0After = await getERC20Balance(token0, wallet2.address);
|
|
36171
|
-
const token1After = await getERC20Balance(token1, wallet2.address);
|
|
36172
|
-
console.log("Token0 change:", token0After - token0Before);
|
|
36173
|
-
console.log("Token1 change:", token1After - token1Before);
|
|
36174
|
-
}
|
|
36175
|
-
if (typeof __require !== "undefined" && typeof module2 !== "undefined" && __require.main === module2) {
|
|
36176
|
-
main3().catch((error) => {
|
|
36177
|
-
console.error(error);
|
|
36178
|
-
process.exit(1);
|
|
36179
|
-
});
|
|
36180
|
-
}
|
|
36181
|
-
}
|
|
36182
|
-
});
|
|
36183
|
-
|
|
36184
36151
|
// src/uniswap/2-limitorder/place.ts
|
|
36185
36152
|
var require_place = __commonJS({
|
|
36186
36153
|
"src/uniswap/2-limitorder/place.ts"(exports, module2) {
|
|
@@ -36241,7 +36208,7 @@ var require_place = __commonJS({
|
|
|
36241
36208
|
const epoch = await placeLimitOrder(hook, poolKey, ticklow, zeroForOne, liquidity);
|
|
36242
36209
|
return epoch;
|
|
36243
36210
|
}
|
|
36244
|
-
async function
|
|
36211
|
+
async function main4() {
|
|
36245
36212
|
const provider2 = new ethers_exports.providers.JsonRpcProvider(RPC_URL);
|
|
36246
36213
|
const wallet2 = new ethers_exports.Wallet(PRIVATE_KEY, provider2);
|
|
36247
36214
|
const token0 = await getContract(wallet2, "Token0");
|
|
@@ -36258,7 +36225,7 @@ var require_place = __commonJS({
|
|
|
36258
36225
|
console.log("Token1 change:", token1After - token1Before);
|
|
36259
36226
|
}
|
|
36260
36227
|
if (typeof __require !== "undefined" && typeof module2 !== "undefined" && __require.main === module2) {
|
|
36261
|
-
|
|
36228
|
+
main4().catch((error) => {
|
|
36262
36229
|
console.error(error);
|
|
36263
36230
|
process.exit(1);
|
|
36264
36231
|
});
|
|
@@ -36309,6 +36276,8 @@ __export(index_exports, {
|
|
|
36309
36276
|
mutiVoucherABI: () => mutiVoucherABI,
|
|
36310
36277
|
placeBid: () => placeBid,
|
|
36311
36278
|
priceToSqrtPrice: () => priceToSqrtPrice,
|
|
36279
|
+
removeLiq: () => removeLiq,
|
|
36280
|
+
removeLiqByPosition: () => removeLiqByPosition,
|
|
36312
36281
|
revealBid: () => revealBid,
|
|
36313
36282
|
revealLock: () => revealLock,
|
|
36314
36283
|
submitMatchResults: () => submitMatchResults,
|
|
@@ -38702,8 +38671,77 @@ if (typeof __require !== "undefined" && typeof module !== "undefined" && __requi
|
|
|
38702
38671
|
});
|
|
38703
38672
|
}
|
|
38704
38673
|
|
|
38705
|
-
// src/
|
|
38706
|
-
|
|
38674
|
+
// src/uniswap/1-marketprice/removeLiquidity.ts
|
|
38675
|
+
init_lib49();
|
|
38676
|
+
init_uniswap_config();
|
|
38677
|
+
init_pool();
|
|
38678
|
+
init_ERC20();
|
|
38679
|
+
init_liqCalculation();
|
|
38680
|
+
init_contract();
|
|
38681
|
+
async function removeLiqByPosition(wallet2, tickLower, tickUpper, liquidityToRemove) {
|
|
38682
|
+
const liqPool = await getContract(wallet2, "LiquidPool");
|
|
38683
|
+
let liqDelta = BigInt(liquidityToRemove.toString());
|
|
38684
|
+
if (liqDelta === 0n) {
|
|
38685
|
+
throw new Error("[SDK] Error: Cannot remove 0 liquidity. Action aborted.");
|
|
38686
|
+
}
|
|
38687
|
+
if (liqDelta > 0n) {
|
|
38688
|
+
liqDelta = liqDelta * -1n;
|
|
38689
|
+
}
|
|
38690
|
+
console.log(`[SDK] Attempting to remove liquidity ${liqDelta} from ticks [${tickLower}, ${tickUpper}]`);
|
|
38691
|
+
const modifyPositionParams = {
|
|
38692
|
+
tickLower,
|
|
38693
|
+
tickUpper,
|
|
38694
|
+
liquidityDelta: liqDelta
|
|
38695
|
+
};
|
|
38696
|
+
const receipt = await modifyPosition(liqPool, modifyPositionParams, "0x00");
|
|
38697
|
+
return receipt;
|
|
38698
|
+
}
|
|
38699
|
+
async function removeLiq(wallet2, priceLower, priceUpper, amount02, amount12, poolKey) {
|
|
38700
|
+
const ticklow = calculateTickFromPriceWithSpacing(priceLower, poolKey.tickSpacing);
|
|
38701
|
+
const tickhigh = calculateTickFromPriceWithSpacing(priceUpper, poolKey.tickSpacing);
|
|
38702
|
+
const liqPool = await getContract(wallet2, "LiquidPool");
|
|
38703
|
+
const sqrtCurrent = await getPoolSqrtPrice(liqPool);
|
|
38704
|
+
const [liqDelta, amount0Rmv, amount1Rmv] = calculateLiqDelta(ticklow, sqrtCurrent, tickhigh, amount02, amount12);
|
|
38705
|
+
console.log(`Attempting to remove liquidity ${liqDelta} to price range [${priceLower}, ${priceUpper}] with amount0[${amount0Rmv.toString()}], amount1[${amount1Rmv.toString()}]`);
|
|
38706
|
+
const modifyPositionParams = {
|
|
38707
|
+
tickLower: ticklow,
|
|
38708
|
+
tickUpper: tickhigh,
|
|
38709
|
+
liquidityDelta: liqDelta * -1n
|
|
38710
|
+
};
|
|
38711
|
+
const receipt = await modifyPosition(liqPool, modifyPositionParams, "0x00");
|
|
38712
|
+
return receipt;
|
|
38713
|
+
}
|
|
38714
|
+
async function main3() {
|
|
38715
|
+
const provider2 = new lib_exports3.JsonRpcProvider(RPC_URL);
|
|
38716
|
+
const wallet2 = new Wallet(PRIVATE_KEY, provider2);
|
|
38717
|
+
const liqPoolAddress = CONTRACT_ADDRESSES.LiquidPool;
|
|
38718
|
+
const token0 = await getContract(wallet2, "Token0");
|
|
38719
|
+
const token1 = await getContract(wallet2, "Token1");
|
|
38720
|
+
const liqPool = await getContract(wallet2, "LiquidPool");
|
|
38721
|
+
let poolPrice = await getPoolPrice(liqPool);
|
|
38722
|
+
console.log(`Current price of pool ${liqPool.address} before removing liquidity is ${poolPrice}`);
|
|
38723
|
+
const token0Before = await getERC20Balance(token0, wallet2.address);
|
|
38724
|
+
const token1Before = await getERC20Balance(token1, wallet2.address);
|
|
38725
|
+
console.log("Token0 balance before removing liquidity:", token0Before.toString());
|
|
38726
|
+
console.log("Token1 balance before removing liquidity:", token1Before.toString());
|
|
38727
|
+
const priceLower = 0.5;
|
|
38728
|
+
const priceUpper = 1.5;
|
|
38729
|
+
const amount02 = 100n;
|
|
38730
|
+
const amount12 = 100n;
|
|
38731
|
+
await removeLiq(wallet2, priceLower, priceUpper, amount02, amount12, POOL_KEYS.limitOrderPoolKey);
|
|
38732
|
+
poolPrice = await getPoolPrice(liqPool);
|
|
38733
|
+
console.log(`Current price of pool ${liqPool.address} after removing liquidity is ${poolPrice}`);
|
|
38734
|
+
const token0After = await getERC20Balance(token0, wallet2.address);
|
|
38735
|
+
const token1After = await getERC20Balance(token1, wallet2.address);
|
|
38736
|
+
console.log("Token0 change:", token0After - token0Before);
|
|
38737
|
+
console.log("Token1 change:", token1After - token1Before);
|
|
38738
|
+
}
|
|
38739
|
+
if (typeof __require !== "undefined" && typeof module !== "undefined" && __require.main === module) {
|
|
38740
|
+
main3().catch((error) => {
|
|
38741
|
+
console.error(error);
|
|
38742
|
+
process.exit(1);
|
|
38743
|
+
});
|
|
38744
|
+
}
|
|
38707
38745
|
|
|
38708
38746
|
// src/uniswap/1-marketprice/getPositions.ts
|
|
38709
38747
|
init_contract();
|
|
@@ -38722,8 +38760,8 @@ async function getUserPositions(wallet2, userAddress) {
|
|
|
38722
38760
|
// liquidity is int256, keep as string to prevent JS precision loss
|
|
38723
38761
|
liquidity: pos.liquidity.toString()
|
|
38724
38762
|
};
|
|
38725
|
-
});
|
|
38726
|
-
console.log(`[SDK] Found ${formattedPositions.length} position(s).`);
|
|
38763
|
+
}).filter((pos) => pos.liquidity !== "0");
|
|
38764
|
+
console.log(`[SDK] Found ${formattedPositions.length} active position(s).`);
|
|
38727
38765
|
return formattedPositions;
|
|
38728
38766
|
} catch (error) {
|
|
38729
38767
|
console.error(`[SDK] Failed to fetch user positions: `, error);
|
|
@@ -39035,6 +39073,8 @@ export {
|
|
|
39035
39073
|
mutiVoucherABI,
|
|
39036
39074
|
placeBid,
|
|
39037
39075
|
priceToSqrtPrice,
|
|
39076
|
+
removeLiq,
|
|
39077
|
+
removeLiqByPosition,
|
|
39038
39078
|
revealBid,
|
|
39039
39079
|
revealLock,
|
|
39040
39080
|
submitMatchResults,
|