punkkit-sdk 1.0.24 → 1.0.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/index.js +61 -141
- package/dist/index.mjs +61 -141
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -36119,6 +36119,64 @@ var init_contract = __esm({
|
|
|
36119
36119
|
}
|
|
36120
36120
|
});
|
|
36121
36121
|
|
|
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
|
+
|
|
36122
36180
|
// src/uniswap/2-limitorder/place.ts
|
|
36123
36181
|
var require_place = __commonJS({
|
|
36124
36182
|
"src/uniswap/2-limitorder/place.ts"(exports2, module2) {
|
|
@@ -38582,13 +38640,6 @@ async function addLiq(wallet2, priceLower, priceUpper, amount02, amount12, poolK
|
|
|
38582
38640
|
const liqPool = await getContract(wallet2, "LiquidPool");
|
|
38583
38641
|
const amount0Big = BigInt(amount02);
|
|
38584
38642
|
const amount1Big = BigInt(amount12);
|
|
38585
|
-
console.log(`[SDK] Validating network and wallet...`);
|
|
38586
|
-
if (wallet2.provider) {
|
|
38587
|
-
const net = await wallet2.provider.getNetwork();
|
|
38588
|
-
console.log(`[SDK] Wallet connected to chainId: ${net.chainId}`);
|
|
38589
|
-
} else {
|
|
38590
|
-
console.warn(`[SDK] Wallet has no provider attached!`);
|
|
38591
|
-
}
|
|
38592
38643
|
const ticklow = calculateTickFromPriceWithSpacing(priceLower, poolKey.tickSpacing);
|
|
38593
38644
|
const tickhigh = calculateTickFromPriceWithSpacing(priceUpper, poolKey.tickSpacing);
|
|
38594
38645
|
let sqrtCurrent;
|
|
@@ -38648,6 +38699,9 @@ if (typeof require !== "undefined" && typeof module !== "undefined" && require.m
|
|
|
38648
38699
|
});
|
|
38649
38700
|
}
|
|
38650
38701
|
|
|
38702
|
+
// src/index.ts
|
|
38703
|
+
__reExport(index_exports, __toESM(require_removeLiquidity()), module.exports);
|
|
38704
|
+
|
|
38651
38705
|
// src/uniswap/1-marketprice/getPositions.ts
|
|
38652
38706
|
init_contract();
|
|
38653
38707
|
async function getUserPositions(wallet2, userAddress) {
|
|
@@ -38678,140 +38732,6 @@ async function getUserPositions(wallet2, userAddress) {
|
|
|
38678
38732
|
init_lib49();
|
|
38679
38733
|
var provider = new ethers_exports.providers.JsonRpcProvider("http://localhost:8545");
|
|
38680
38734
|
var wallet = new ethers_exports.Wallet("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", provider);
|
|
38681
|
-
async function isdepolyed(address) {
|
|
38682
|
-
let code = await provider.getCode(address);
|
|
38683
|
-
if (code !== "0x") {
|
|
38684
|
-
console.log(`The contract ${address} has been deployed.`);
|
|
38685
|
-
} else {
|
|
38686
|
-
console.log(`The contract ${address} has not been deployed. `);
|
|
38687
|
-
}
|
|
38688
|
-
}
|
|
38689
|
-
async function modifyPosition2(contract, poolKey, modifyPositionParams) {
|
|
38690
|
-
let tx = await contract.setPositionParameters(poolKey, modifyPositionParams);
|
|
38691
|
-
await tx.wait();
|
|
38692
|
-
console.log("Position parameters set successfully");
|
|
38693
|
-
tx = await contract.addLiquidity();
|
|
38694
|
-
await tx.wait();
|
|
38695
|
-
}
|
|
38696
|
-
async function initialize(contract, key3, sqrtPriceX96) {
|
|
38697
|
-
let tick = await contract.initialize(key3, sqrtPriceX96);
|
|
38698
|
-
console.log(`Returned tick: ${JSON.stringify(tick)}`);
|
|
38699
|
-
}
|
|
38700
|
-
async function approveERC202(contract, toAddress, amount) {
|
|
38701
|
-
let tx = await contract.approve(toAddress, amount);
|
|
38702
|
-
let receipt = await tx.wait();
|
|
38703
|
-
console.log(`Transaction hash: ${receipt.transactionHash}`);
|
|
38704
|
-
}
|
|
38705
|
-
async function getERC20Balance2(contract, address) {
|
|
38706
|
-
let balance = await contract.balanceOf(address);
|
|
38707
|
-
console.log(`ERC20 Balance: ${balance.toString()}`);
|
|
38708
|
-
return balance;
|
|
38709
|
-
}
|
|
38710
|
-
async function executeSwap2(contract, poolKey, swapParams) {
|
|
38711
|
-
console.log("begin swap");
|
|
38712
|
-
let to0params = {
|
|
38713
|
-
tickLower: 84e4,
|
|
38714
|
-
// lower price 0.5
|
|
38715
|
-
tickUpper: 876600,
|
|
38716
|
-
// upper price 1.5
|
|
38717
|
-
liquidityDelta: 0
|
|
38718
|
-
};
|
|
38719
|
-
let tx1 = await contract.setPositionParameters(poolKey, to0params);
|
|
38720
|
-
await tx1.wait();
|
|
38721
|
-
let tx2 = await contract.setSwapParameters(poolKey, swapParams);
|
|
38722
|
-
console.log("begin swap1");
|
|
38723
|
-
await tx2.wait();
|
|
38724
|
-
console.log("Position parameters set successfully");
|
|
38725
|
-
let tx3 = await contract.executeSwap();
|
|
38726
|
-
await tx3.wait();
|
|
38727
|
-
}
|
|
38728
|
-
async function depolyContract(contractName, params) {
|
|
38729
|
-
const Factory = await ethers_exports.getContractFactory(contractName);
|
|
38730
|
-
let contract;
|
|
38731
|
-
if (params === void 0) {
|
|
38732
|
-
contract = await Factory.deploy();
|
|
38733
|
-
} else {
|
|
38734
|
-
console.log(`params: ${JSON.stringify(params)}`);
|
|
38735
|
-
contract = await Factory.deploy(params);
|
|
38736
|
-
}
|
|
38737
|
-
await contract.deployed();
|
|
38738
|
-
console.log(`${contractName} deployed to ${contract.address}`);
|
|
38739
|
-
return contract;
|
|
38740
|
-
}
|
|
38741
|
-
describe("PoolManager", function() {
|
|
38742
|
-
it("Should return the new greeting once it's changed", async function() {
|
|
38743
|
-
const token0 = await depolyContract("Token0");
|
|
38744
|
-
const token1 = await depolyContract("Token1");
|
|
38745
|
-
const totalSupply0 = await token0.totalSupply();
|
|
38746
|
-
console.log(`Token0 deployed to ${token0.address} with an initial supply ${totalSupply0}`);
|
|
38747
|
-
const totalSupply1 = await token1.totalSupply();
|
|
38748
|
-
console.log(`Token1 deployed to ${token1.address} with an initial supply ${totalSupply1}`);
|
|
38749
|
-
getERC20Balance2(token0, wallet.address);
|
|
38750
|
-
getERC20Balance2(token1, wallet.address);
|
|
38751
|
-
const token0Address = token0.address < token1.address ? token0.address : token1.address;
|
|
38752
|
-
const token1Address = token0.address > token1.address ? token0.address : token1.address;
|
|
38753
|
-
const poolManager = await depolyContract("PoolManager", 88888888888);
|
|
38754
|
-
const poolManagerAddress = poolManager.address;
|
|
38755
|
-
await isdepolyed(poolManagerAddress);
|
|
38756
|
-
const dynamicFee = await depolyContract("DynamicFee", poolManagerAddress);
|
|
38757
|
-
console.log("LimitOrder Contract deployed to:", dynamicFee.address);
|
|
38758
|
-
let sqrtPriceX96 = BigInt("792281625142643375935439503360");
|
|
38759
|
-
const DYNAMIC_FEE_FLAG2 = 8388608;
|
|
38760
|
-
let poolKey = {
|
|
38761
|
-
currency0: token0Address,
|
|
38762
|
-
currency1: token1Address,
|
|
38763
|
-
fee: DYNAMIC_FEE_FLAG2,
|
|
38764
|
-
tickSpacing: 60,
|
|
38765
|
-
hooks: dynamicFee.address
|
|
38766
|
-
};
|
|
38767
|
-
await initialize(poolManager, poolKey, sqrtPriceX96);
|
|
38768
|
-
const MyLiquidityProvider = await depolyContract("MyLiquidityProvider", poolManagerAddress);
|
|
38769
|
-
const wei = ethers_exports.utils.parseUnits("21000000", 18).toBigInt();
|
|
38770
|
-
await approveERC202(token0, MyLiquidityProvider.address, wei);
|
|
38771
|
-
await approveERC202(token1, MyLiquidityProvider.address, wei);
|
|
38772
|
-
let modifyPositionParams = {
|
|
38773
|
-
tickLower: 45e3,
|
|
38774
|
-
// lower price 90
|
|
38775
|
-
tickUpper: 46980,
|
|
38776
|
-
// upper price 110
|
|
38777
|
-
//liquidityDelta: 194868329805051412324060
|
|
38778
|
-
liquidityDelta: BigInt("10000000000000000000000")
|
|
38779
|
-
// 10000token0 10000token1
|
|
38780
|
-
};
|
|
38781
|
-
await getERC20Balance2(token0, wallet.address);
|
|
38782
|
-
await getERC20Balance2(token1, wallet.address);
|
|
38783
|
-
await modifyPosition2(MyLiquidityProvider, poolKey, modifyPositionParams);
|
|
38784
|
-
console.log("Liquidity added successfully");
|
|
38785
|
-
await getERC20Balance2(token0, wallet.address);
|
|
38786
|
-
await getERC20Balance2(token1, wallet.address);
|
|
38787
|
-
let sqrtpricelimit = ethers_exports.BigNumber.from("7922816251426433759354395033600").toBigInt();
|
|
38788
|
-
let amountswap = ethers_exports.BigNumber.from("1083456789101112134000").toBigInt();
|
|
38789
|
-
console.log("amountswap:", amountswap.toString());
|
|
38790
|
-
let swapParams = {
|
|
38791
|
-
zeroForOne: false,
|
|
38792
|
-
amountSpecified: amountswap,
|
|
38793
|
-
sqrtPriceLimitX96: sqrtpricelimit
|
|
38794
|
-
};
|
|
38795
|
-
let token0beforswap = await getERC20Balance2(token0, wallet.address);
|
|
38796
|
-
let token1beforswap = await getERC20Balance2(token1, wallet.address);
|
|
38797
|
-
await executeSwap2(MyLiquidityProvider, poolKey, swapParams);
|
|
38798
|
-
console.log("swap successfully");
|
|
38799
|
-
let token0afterswap = await getERC20Balance2(token0, wallet.address);
|
|
38800
|
-
let token1afterswap = await getERC20Balance2(token1, wallet.address);
|
|
38801
|
-
console.log("token0 change:", token0afterswap.sub(token0beforswap).toString());
|
|
38802
|
-
console.log("token1 change:", token1afterswap.sub(token1beforswap).toString());
|
|
38803
|
-
console.log("price:", token1afterswap.sub(token1beforswap).toString() / token0afterswap.sub(token0beforswap).toString());
|
|
38804
|
-
token0beforswap = await getERC20Balance2(token0, wallet.address);
|
|
38805
|
-
token1beforswap = await getERC20Balance2(token1, wallet.address);
|
|
38806
|
-
await executeSwap2(MyLiquidityProvider, poolKey, swapParams);
|
|
38807
|
-
console.log("swap successfully");
|
|
38808
|
-
token0afterswap = await getERC20Balance2(token0, wallet.address);
|
|
38809
|
-
token1afterswap = await getERC20Balance2(token1, wallet.address);
|
|
38810
|
-
console.log("token0 change:", token0afterswap.sub(token0beforswap).toString());
|
|
38811
|
-
console.log("token1 change:", token1afterswap.sub(token1beforswap).toString());
|
|
38812
|
-
console.log("price:", token1afterswap.sub(token1beforswap).toString() / token0afterswap.sub(token0beforswap).toString());
|
|
38813
|
-
});
|
|
38814
|
-
});
|
|
38815
38735
|
|
|
38816
38736
|
// src/index.ts
|
|
38817
38737
|
__reExport(index_exports, __toESM(require_place()), module.exports);
|
package/dist/index.mjs
CHANGED
|
@@ -36123,6 +36123,64 @@ var init_contract = __esm({
|
|
|
36123
36123
|
}
|
|
36124
36124
|
});
|
|
36125
36125
|
|
|
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
|
+
|
|
36126
36184
|
// src/uniswap/2-limitorder/place.ts
|
|
36127
36185
|
var require_place = __commonJS({
|
|
36128
36186
|
"src/uniswap/2-limitorder/place.ts"(exports, module2) {
|
|
@@ -38585,13 +38643,6 @@ async function addLiq(wallet2, priceLower, priceUpper, amount02, amount12, poolK
|
|
|
38585
38643
|
const liqPool = await getContract(wallet2, "LiquidPool");
|
|
38586
38644
|
const amount0Big = BigInt(amount02);
|
|
38587
38645
|
const amount1Big = BigInt(amount12);
|
|
38588
|
-
console.log(`[SDK] Validating network and wallet...`);
|
|
38589
|
-
if (wallet2.provider) {
|
|
38590
|
-
const net = await wallet2.provider.getNetwork();
|
|
38591
|
-
console.log(`[SDK] Wallet connected to chainId: ${net.chainId}`);
|
|
38592
|
-
} else {
|
|
38593
|
-
console.warn(`[SDK] Wallet has no provider attached!`);
|
|
38594
|
-
}
|
|
38595
38646
|
const ticklow = calculateTickFromPriceWithSpacing(priceLower, poolKey.tickSpacing);
|
|
38596
38647
|
const tickhigh = calculateTickFromPriceWithSpacing(priceUpper, poolKey.tickSpacing);
|
|
38597
38648
|
let sqrtCurrent;
|
|
@@ -38651,6 +38702,9 @@ if (typeof __require !== "undefined" && typeof module !== "undefined" && __requi
|
|
|
38651
38702
|
});
|
|
38652
38703
|
}
|
|
38653
38704
|
|
|
38705
|
+
// src/index.ts
|
|
38706
|
+
__reExport(index_exports, __toESM(require_removeLiquidity()));
|
|
38707
|
+
|
|
38654
38708
|
// src/uniswap/1-marketprice/getPositions.ts
|
|
38655
38709
|
init_contract();
|
|
38656
38710
|
async function getUserPositions(wallet2, userAddress) {
|
|
@@ -38681,140 +38735,6 @@ async function getUserPositions(wallet2, userAddress) {
|
|
|
38681
38735
|
init_lib49();
|
|
38682
38736
|
var provider = new ethers_exports.providers.JsonRpcProvider("http://localhost:8545");
|
|
38683
38737
|
var wallet = new ethers_exports.Wallet("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", provider);
|
|
38684
|
-
async function isdepolyed(address) {
|
|
38685
|
-
let code = await provider.getCode(address);
|
|
38686
|
-
if (code !== "0x") {
|
|
38687
|
-
console.log(`The contract ${address} has been deployed.`);
|
|
38688
|
-
} else {
|
|
38689
|
-
console.log(`The contract ${address} has not been deployed. `);
|
|
38690
|
-
}
|
|
38691
|
-
}
|
|
38692
|
-
async function modifyPosition2(contract, poolKey, modifyPositionParams) {
|
|
38693
|
-
let tx = await contract.setPositionParameters(poolKey, modifyPositionParams);
|
|
38694
|
-
await tx.wait();
|
|
38695
|
-
console.log("Position parameters set successfully");
|
|
38696
|
-
tx = await contract.addLiquidity();
|
|
38697
|
-
await tx.wait();
|
|
38698
|
-
}
|
|
38699
|
-
async function initialize(contract, key3, sqrtPriceX96) {
|
|
38700
|
-
let tick = await contract.initialize(key3, sqrtPriceX96);
|
|
38701
|
-
console.log(`Returned tick: ${JSON.stringify(tick)}`);
|
|
38702
|
-
}
|
|
38703
|
-
async function approveERC202(contract, toAddress, amount) {
|
|
38704
|
-
let tx = await contract.approve(toAddress, amount);
|
|
38705
|
-
let receipt = await tx.wait();
|
|
38706
|
-
console.log(`Transaction hash: ${receipt.transactionHash}`);
|
|
38707
|
-
}
|
|
38708
|
-
async function getERC20Balance2(contract, address) {
|
|
38709
|
-
let balance = await contract.balanceOf(address);
|
|
38710
|
-
console.log(`ERC20 Balance: ${balance.toString()}`);
|
|
38711
|
-
return balance;
|
|
38712
|
-
}
|
|
38713
|
-
async function executeSwap2(contract, poolKey, swapParams) {
|
|
38714
|
-
console.log("begin swap");
|
|
38715
|
-
let to0params = {
|
|
38716
|
-
tickLower: 84e4,
|
|
38717
|
-
// lower price 0.5
|
|
38718
|
-
tickUpper: 876600,
|
|
38719
|
-
// upper price 1.5
|
|
38720
|
-
liquidityDelta: 0
|
|
38721
|
-
};
|
|
38722
|
-
let tx1 = await contract.setPositionParameters(poolKey, to0params);
|
|
38723
|
-
await tx1.wait();
|
|
38724
|
-
let tx2 = await contract.setSwapParameters(poolKey, swapParams);
|
|
38725
|
-
console.log("begin swap1");
|
|
38726
|
-
await tx2.wait();
|
|
38727
|
-
console.log("Position parameters set successfully");
|
|
38728
|
-
let tx3 = await contract.executeSwap();
|
|
38729
|
-
await tx3.wait();
|
|
38730
|
-
}
|
|
38731
|
-
async function depolyContract(contractName, params) {
|
|
38732
|
-
const Factory = await ethers_exports.getContractFactory(contractName);
|
|
38733
|
-
let contract;
|
|
38734
|
-
if (params === void 0) {
|
|
38735
|
-
contract = await Factory.deploy();
|
|
38736
|
-
} else {
|
|
38737
|
-
console.log(`params: ${JSON.stringify(params)}`);
|
|
38738
|
-
contract = await Factory.deploy(params);
|
|
38739
|
-
}
|
|
38740
|
-
await contract.deployed();
|
|
38741
|
-
console.log(`${contractName} deployed to ${contract.address}`);
|
|
38742
|
-
return contract;
|
|
38743
|
-
}
|
|
38744
|
-
describe("PoolManager", function() {
|
|
38745
|
-
it("Should return the new greeting once it's changed", async function() {
|
|
38746
|
-
const token0 = await depolyContract("Token0");
|
|
38747
|
-
const token1 = await depolyContract("Token1");
|
|
38748
|
-
const totalSupply0 = await token0.totalSupply();
|
|
38749
|
-
console.log(`Token0 deployed to ${token0.address} with an initial supply ${totalSupply0}`);
|
|
38750
|
-
const totalSupply1 = await token1.totalSupply();
|
|
38751
|
-
console.log(`Token1 deployed to ${token1.address} with an initial supply ${totalSupply1}`);
|
|
38752
|
-
getERC20Balance2(token0, wallet.address);
|
|
38753
|
-
getERC20Balance2(token1, wallet.address);
|
|
38754
|
-
const token0Address = token0.address < token1.address ? token0.address : token1.address;
|
|
38755
|
-
const token1Address = token0.address > token1.address ? token0.address : token1.address;
|
|
38756
|
-
const poolManager = await depolyContract("PoolManager", 88888888888);
|
|
38757
|
-
const poolManagerAddress = poolManager.address;
|
|
38758
|
-
await isdepolyed(poolManagerAddress);
|
|
38759
|
-
const dynamicFee = await depolyContract("DynamicFee", poolManagerAddress);
|
|
38760
|
-
console.log("LimitOrder Contract deployed to:", dynamicFee.address);
|
|
38761
|
-
let sqrtPriceX96 = BigInt("792281625142643375935439503360");
|
|
38762
|
-
const DYNAMIC_FEE_FLAG2 = 8388608;
|
|
38763
|
-
let poolKey = {
|
|
38764
|
-
currency0: token0Address,
|
|
38765
|
-
currency1: token1Address,
|
|
38766
|
-
fee: DYNAMIC_FEE_FLAG2,
|
|
38767
|
-
tickSpacing: 60,
|
|
38768
|
-
hooks: dynamicFee.address
|
|
38769
|
-
};
|
|
38770
|
-
await initialize(poolManager, poolKey, sqrtPriceX96);
|
|
38771
|
-
const MyLiquidityProvider = await depolyContract("MyLiquidityProvider", poolManagerAddress);
|
|
38772
|
-
const wei = ethers_exports.utils.parseUnits("21000000", 18).toBigInt();
|
|
38773
|
-
await approveERC202(token0, MyLiquidityProvider.address, wei);
|
|
38774
|
-
await approveERC202(token1, MyLiquidityProvider.address, wei);
|
|
38775
|
-
let modifyPositionParams = {
|
|
38776
|
-
tickLower: 45e3,
|
|
38777
|
-
// lower price 90
|
|
38778
|
-
tickUpper: 46980,
|
|
38779
|
-
// upper price 110
|
|
38780
|
-
//liquidityDelta: 194868329805051412324060
|
|
38781
|
-
liquidityDelta: BigInt("10000000000000000000000")
|
|
38782
|
-
// 10000token0 10000token1
|
|
38783
|
-
};
|
|
38784
|
-
await getERC20Balance2(token0, wallet.address);
|
|
38785
|
-
await getERC20Balance2(token1, wallet.address);
|
|
38786
|
-
await modifyPosition2(MyLiquidityProvider, poolKey, modifyPositionParams);
|
|
38787
|
-
console.log("Liquidity added successfully");
|
|
38788
|
-
await getERC20Balance2(token0, wallet.address);
|
|
38789
|
-
await getERC20Balance2(token1, wallet.address);
|
|
38790
|
-
let sqrtpricelimit = ethers_exports.BigNumber.from("7922816251426433759354395033600").toBigInt();
|
|
38791
|
-
let amountswap = ethers_exports.BigNumber.from("1083456789101112134000").toBigInt();
|
|
38792
|
-
console.log("amountswap:", amountswap.toString());
|
|
38793
|
-
let swapParams = {
|
|
38794
|
-
zeroForOne: false,
|
|
38795
|
-
amountSpecified: amountswap,
|
|
38796
|
-
sqrtPriceLimitX96: sqrtpricelimit
|
|
38797
|
-
};
|
|
38798
|
-
let token0beforswap = await getERC20Balance2(token0, wallet.address);
|
|
38799
|
-
let token1beforswap = await getERC20Balance2(token1, wallet.address);
|
|
38800
|
-
await executeSwap2(MyLiquidityProvider, poolKey, swapParams);
|
|
38801
|
-
console.log("swap successfully");
|
|
38802
|
-
let token0afterswap = await getERC20Balance2(token0, wallet.address);
|
|
38803
|
-
let token1afterswap = await getERC20Balance2(token1, wallet.address);
|
|
38804
|
-
console.log("token0 change:", token0afterswap.sub(token0beforswap).toString());
|
|
38805
|
-
console.log("token1 change:", token1afterswap.sub(token1beforswap).toString());
|
|
38806
|
-
console.log("price:", token1afterswap.sub(token1beforswap).toString() / token0afterswap.sub(token0beforswap).toString());
|
|
38807
|
-
token0beforswap = await getERC20Balance2(token0, wallet.address);
|
|
38808
|
-
token1beforswap = await getERC20Balance2(token1, wallet.address);
|
|
38809
|
-
await executeSwap2(MyLiquidityProvider, poolKey, swapParams);
|
|
38810
|
-
console.log("swap successfully");
|
|
38811
|
-
token0afterswap = await getERC20Balance2(token0, wallet.address);
|
|
38812
|
-
token1afterswap = await getERC20Balance2(token1, wallet.address);
|
|
38813
|
-
console.log("token0 change:", token0afterswap.sub(token0beforswap).toString());
|
|
38814
|
-
console.log("token1 change:", token1afterswap.sub(token1beforswap).toString());
|
|
38815
|
-
console.log("price:", token1afterswap.sub(token1beforswap).toString() / token0afterswap.sub(token0beforswap).toString());
|
|
38816
|
-
});
|
|
38817
|
-
});
|
|
38818
38738
|
|
|
38819
38739
|
// src/index.ts
|
|
38820
38740
|
__reExport(index_exports, __toESM(require_place()));
|