punkkit-sdk 1.0.23 → 1.0.25
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 +15 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.js +28 -134
- package/dist/index.mjs +28 -134
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -131,6 +131,20 @@ 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
|
+
interface UserPosition {
|
|
135
|
+
tokenId: number;
|
|
136
|
+
tickLower: number;
|
|
137
|
+
tickUpper: number;
|
|
138
|
+
liquidity: string;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Fetch all liquidity positions for a specific user from the LiquidPool contract.
|
|
142
|
+
* @param wallet The user's wallet or signer instance.
|
|
143
|
+
* @param userAddress Addres of the user to fetch positions for. If not provided, it uses the wallet's address.
|
|
144
|
+
* @returns An array of UserPosition objects containing the position details.
|
|
145
|
+
*/
|
|
146
|
+
declare function getUserPositions(wallet: Wallet, userAddress?: string): Promise<UserPosition[]>;
|
|
147
|
+
|
|
134
148
|
declare function getContract(wallet: Wallet, name: string): Promise<Contract>;
|
|
135
149
|
|
|
136
150
|
declare function modifyPosition(contract: Contract, modifyPositionParams: ModifyPositionParams, hookData: string): Promise<any>;
|
|
@@ -190,4 +204,4 @@ declare function balanceOf(contractAddress: string, provider: SignerOrProvider,
|
|
|
190
204
|
declare function getAllVouchers(contractAddress: string, provider: SignerOrProvider): Promise<string[]>;
|
|
191
205
|
declare function BuildUseVoucherTx(tx: providers.TransactionRequest, voucherName: string): providers.TransactionRequest;
|
|
192
206
|
|
|
193
|
-
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 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, getVoucherContract, getVoucherInfo, liquidity0, liquidity1, main, modifyPosition, mutiVoucherABI, placeBid, priceToSqrtPrice, revealBid, revealLock, submitMatchResults, swap, toWei, unlockTokens, useVoucher, withdrawMatchResult };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -131,6 +131,20 @@ 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
|
+
interface UserPosition {
|
|
135
|
+
tokenId: number;
|
|
136
|
+
tickLower: number;
|
|
137
|
+
tickUpper: number;
|
|
138
|
+
liquidity: string;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Fetch all liquidity positions for a specific user from the LiquidPool contract.
|
|
142
|
+
* @param wallet The user's wallet or signer instance.
|
|
143
|
+
* @param userAddress Addres of the user to fetch positions for. If not provided, it uses the wallet's address.
|
|
144
|
+
* @returns An array of UserPosition objects containing the position details.
|
|
145
|
+
*/
|
|
146
|
+
declare function getUserPositions(wallet: Wallet, userAddress?: string): Promise<UserPosition[]>;
|
|
147
|
+
|
|
134
148
|
declare function getContract(wallet: Wallet, name: string): Promise<Contract>;
|
|
135
149
|
|
|
136
150
|
declare function modifyPosition(contract: Contract, modifyPositionParams: ModifyPositionParams, hookData: string): Promise<any>;
|
|
@@ -190,4 +204,4 @@ declare function balanceOf(contractAddress: string, provider: SignerOrProvider,
|
|
|
190
204
|
declare function getAllVouchers(contractAddress: string, provider: SignerOrProvider): Promise<string[]>;
|
|
191
205
|
declare function BuildUseVoucherTx(tx: providers.TransactionRequest, voucherName: string): providers.TransactionRequest;
|
|
192
206
|
|
|
193
|
-
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 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, getVoucherContract, getVoucherInfo, liquidity0, liquidity1, main, modifyPosition, mutiVoucherABI, placeBid, priceToSqrtPrice, revealBid, revealLock, submitMatchResults, swap, toWei, unlockTokens, useVoucher, withdrawMatchResult };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -36237,6 +36237,7 @@ __export(index_exports, {
|
|
|
36237
36237
|
getPoolSqrtPrice: () => getPoolSqrtPrice,
|
|
36238
36238
|
getProvider: () => getProvider,
|
|
36239
36239
|
getSqrtPriceAtTick: () => getSqrtPriceAtTick,
|
|
36240
|
+
getUserPositions: () => getUserPositions,
|
|
36240
36241
|
getVoucherContract: () => getVoucherContract,
|
|
36241
36242
|
getVoucherInfo: () => getVoucherInfo,
|
|
36242
36243
|
liquidity0: () => liquidity0,
|
|
@@ -38647,144 +38648,36 @@ if (typeof require !== "undefined" && typeof module !== "undefined" && require.m
|
|
|
38647
38648
|
});
|
|
38648
38649
|
}
|
|
38649
38650
|
|
|
38651
|
+
// src/uniswap/1-marketprice/getPositions.ts
|
|
38652
|
+
init_contract();
|
|
38653
|
+
async function getUserPositions(wallet2, userAddress) {
|
|
38654
|
+
const liqPool = await getContract(wallet2, "LiquidPool");
|
|
38655
|
+
const targetAddress = userAddress || await wallet2.getAddress();
|
|
38656
|
+
console.log(`[SDK] Fetching liquidity NFT positions for address: ${targetAddress}`);
|
|
38657
|
+
try {
|
|
38658
|
+
const positions = await liqPool.getPosition(targetAddress);
|
|
38659
|
+
const formattedPositions = positions.map((pos) => {
|
|
38660
|
+
return {
|
|
38661
|
+
tokenId: pos.tokenId.toNumber(),
|
|
38662
|
+
// tick is int24, so it should fit standard JS number
|
|
38663
|
+
tickLower: pos.tickLower,
|
|
38664
|
+
tickUpper: pos.tickUpper,
|
|
38665
|
+
// liquidity is int256, keep as string to prevent JS precision loss
|
|
38666
|
+
liquidity: pos.liquidity.toString()
|
|
38667
|
+
};
|
|
38668
|
+
});
|
|
38669
|
+
console.log(`[SDK] Found ${formattedPositions.length} position(s).`);
|
|
38670
|
+
return formattedPositions;
|
|
38671
|
+
} catch (error) {
|
|
38672
|
+
console.error(`[SDK] Failed to fetch user positions: `, error);
|
|
38673
|
+
throw error;
|
|
38674
|
+
}
|
|
38675
|
+
}
|
|
38676
|
+
|
|
38650
38677
|
// src/uniswap/3-dynamicfee/dynamicfee.ts
|
|
38651
38678
|
init_lib49();
|
|
38652
38679
|
var provider = new ethers_exports.providers.JsonRpcProvider("http://localhost:8545");
|
|
38653
38680
|
var wallet = new ethers_exports.Wallet("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", provider);
|
|
38654
|
-
async function isdepolyed(address) {
|
|
38655
|
-
let code = await provider.getCode(address);
|
|
38656
|
-
if (code !== "0x") {
|
|
38657
|
-
console.log(`The contract ${address} has been deployed.`);
|
|
38658
|
-
} else {
|
|
38659
|
-
console.log(`The contract ${address} has not been deployed. `);
|
|
38660
|
-
}
|
|
38661
|
-
}
|
|
38662
|
-
async function modifyPosition2(contract, poolKey, modifyPositionParams) {
|
|
38663
|
-
let tx = await contract.setPositionParameters(poolKey, modifyPositionParams);
|
|
38664
|
-
await tx.wait();
|
|
38665
|
-
console.log("Position parameters set successfully");
|
|
38666
|
-
tx = await contract.addLiquidity();
|
|
38667
|
-
await tx.wait();
|
|
38668
|
-
}
|
|
38669
|
-
async function initialize(contract, key3, sqrtPriceX96) {
|
|
38670
|
-
let tick = await contract.initialize(key3, sqrtPriceX96);
|
|
38671
|
-
console.log(`Returned tick: ${JSON.stringify(tick)}`);
|
|
38672
|
-
}
|
|
38673
|
-
async function approveERC202(contract, toAddress, amount) {
|
|
38674
|
-
let tx = await contract.approve(toAddress, amount);
|
|
38675
|
-
let receipt = await tx.wait();
|
|
38676
|
-
console.log(`Transaction hash: ${receipt.transactionHash}`);
|
|
38677
|
-
}
|
|
38678
|
-
async function getERC20Balance2(contract, address) {
|
|
38679
|
-
let balance = await contract.balanceOf(address);
|
|
38680
|
-
console.log(`ERC20 Balance: ${balance.toString()}`);
|
|
38681
|
-
return balance;
|
|
38682
|
-
}
|
|
38683
|
-
async function executeSwap2(contract, poolKey, swapParams) {
|
|
38684
|
-
console.log("begin swap");
|
|
38685
|
-
let to0params = {
|
|
38686
|
-
tickLower: 84e4,
|
|
38687
|
-
// lower price 0.5
|
|
38688
|
-
tickUpper: 876600,
|
|
38689
|
-
// upper price 1.5
|
|
38690
|
-
liquidityDelta: 0
|
|
38691
|
-
};
|
|
38692
|
-
let tx1 = await contract.setPositionParameters(poolKey, to0params);
|
|
38693
|
-
await tx1.wait();
|
|
38694
|
-
let tx2 = await contract.setSwapParameters(poolKey, swapParams);
|
|
38695
|
-
console.log("begin swap1");
|
|
38696
|
-
await tx2.wait();
|
|
38697
|
-
console.log("Position parameters set successfully");
|
|
38698
|
-
let tx3 = await contract.executeSwap();
|
|
38699
|
-
await tx3.wait();
|
|
38700
|
-
}
|
|
38701
|
-
async function depolyContract(contractName, params) {
|
|
38702
|
-
const Factory = await ethers_exports.getContractFactory(contractName);
|
|
38703
|
-
let contract;
|
|
38704
|
-
if (params === void 0) {
|
|
38705
|
-
contract = await Factory.deploy();
|
|
38706
|
-
} else {
|
|
38707
|
-
console.log(`params: ${JSON.stringify(params)}`);
|
|
38708
|
-
contract = await Factory.deploy(params);
|
|
38709
|
-
}
|
|
38710
|
-
await contract.deployed();
|
|
38711
|
-
console.log(`${contractName} deployed to ${contract.address}`);
|
|
38712
|
-
return contract;
|
|
38713
|
-
}
|
|
38714
|
-
describe("PoolManager", function() {
|
|
38715
|
-
it("Should return the new greeting once it's changed", async function() {
|
|
38716
|
-
const token0 = await depolyContract("Token0");
|
|
38717
|
-
const token1 = await depolyContract("Token1");
|
|
38718
|
-
const totalSupply0 = await token0.totalSupply();
|
|
38719
|
-
console.log(`Token0 deployed to ${token0.address} with an initial supply ${totalSupply0}`);
|
|
38720
|
-
const totalSupply1 = await token1.totalSupply();
|
|
38721
|
-
console.log(`Token1 deployed to ${token1.address} with an initial supply ${totalSupply1}`);
|
|
38722
|
-
getERC20Balance2(token0, wallet.address);
|
|
38723
|
-
getERC20Balance2(token1, wallet.address);
|
|
38724
|
-
const token0Address = token0.address < token1.address ? token0.address : token1.address;
|
|
38725
|
-
const token1Address = token0.address > token1.address ? token0.address : token1.address;
|
|
38726
|
-
const poolManager = await depolyContract("PoolManager", 88888888888);
|
|
38727
|
-
const poolManagerAddress = poolManager.address;
|
|
38728
|
-
await isdepolyed(poolManagerAddress);
|
|
38729
|
-
const dynamicFee = await depolyContract("DynamicFee", poolManagerAddress);
|
|
38730
|
-
console.log("LimitOrder Contract deployed to:", dynamicFee.address);
|
|
38731
|
-
let sqrtPriceX96 = BigInt("792281625142643375935439503360");
|
|
38732
|
-
const DYNAMIC_FEE_FLAG2 = 8388608;
|
|
38733
|
-
let poolKey = {
|
|
38734
|
-
currency0: token0Address,
|
|
38735
|
-
currency1: token1Address,
|
|
38736
|
-
fee: DYNAMIC_FEE_FLAG2,
|
|
38737
|
-
tickSpacing: 60,
|
|
38738
|
-
hooks: dynamicFee.address
|
|
38739
|
-
};
|
|
38740
|
-
await initialize(poolManager, poolKey, sqrtPriceX96);
|
|
38741
|
-
const MyLiquidityProvider = await depolyContract("MyLiquidityProvider", poolManagerAddress);
|
|
38742
|
-
const wei = ethers_exports.utils.parseUnits("21000000", 18).toBigInt();
|
|
38743
|
-
await approveERC202(token0, MyLiquidityProvider.address, wei);
|
|
38744
|
-
await approveERC202(token1, MyLiquidityProvider.address, wei);
|
|
38745
|
-
let modifyPositionParams = {
|
|
38746
|
-
tickLower: 45e3,
|
|
38747
|
-
// lower price 90
|
|
38748
|
-
tickUpper: 46980,
|
|
38749
|
-
// upper price 110
|
|
38750
|
-
//liquidityDelta: 194868329805051412324060
|
|
38751
|
-
liquidityDelta: BigInt("10000000000000000000000")
|
|
38752
|
-
// 10000token0 10000token1
|
|
38753
|
-
};
|
|
38754
|
-
await getERC20Balance2(token0, wallet.address);
|
|
38755
|
-
await getERC20Balance2(token1, wallet.address);
|
|
38756
|
-
await modifyPosition2(MyLiquidityProvider, poolKey, modifyPositionParams);
|
|
38757
|
-
console.log("Liquidity added successfully");
|
|
38758
|
-
await getERC20Balance2(token0, wallet.address);
|
|
38759
|
-
await getERC20Balance2(token1, wallet.address);
|
|
38760
|
-
let sqrtpricelimit = ethers_exports.BigNumber.from("7922816251426433759354395033600").toBigInt();
|
|
38761
|
-
let amountswap = ethers_exports.BigNumber.from("1083456789101112134000").toBigInt();
|
|
38762
|
-
console.log("amountswap:", amountswap.toString());
|
|
38763
|
-
let swapParams = {
|
|
38764
|
-
zeroForOne: false,
|
|
38765
|
-
amountSpecified: amountswap,
|
|
38766
|
-
sqrtPriceLimitX96: sqrtpricelimit
|
|
38767
|
-
};
|
|
38768
|
-
let token0beforswap = await getERC20Balance2(token0, wallet.address);
|
|
38769
|
-
let token1beforswap = await getERC20Balance2(token1, wallet.address);
|
|
38770
|
-
await executeSwap2(MyLiquidityProvider, poolKey, swapParams);
|
|
38771
|
-
console.log("swap successfully");
|
|
38772
|
-
let token0afterswap = await getERC20Balance2(token0, wallet.address);
|
|
38773
|
-
let token1afterswap = await getERC20Balance2(token1, wallet.address);
|
|
38774
|
-
console.log("token0 change:", token0afterswap.sub(token0beforswap).toString());
|
|
38775
|
-
console.log("token1 change:", token1afterswap.sub(token1beforswap).toString());
|
|
38776
|
-
console.log("price:", token1afterswap.sub(token1beforswap).toString() / token0afterswap.sub(token0beforswap).toString());
|
|
38777
|
-
token0beforswap = await getERC20Balance2(token0, wallet.address);
|
|
38778
|
-
token1beforswap = await getERC20Balance2(token1, wallet.address);
|
|
38779
|
-
await executeSwap2(MyLiquidityProvider, poolKey, swapParams);
|
|
38780
|
-
console.log("swap successfully");
|
|
38781
|
-
token0afterswap = await getERC20Balance2(token0, wallet.address);
|
|
38782
|
-
token1afterswap = await getERC20Balance2(token1, wallet.address);
|
|
38783
|
-
console.log("token0 change:", token0afterswap.sub(token0beforswap).toString());
|
|
38784
|
-
console.log("token1 change:", token1afterswap.sub(token1beforswap).toString());
|
|
38785
|
-
console.log("price:", token1afterswap.sub(token1beforswap).toString() / token0afterswap.sub(token0beforswap).toString());
|
|
38786
|
-
});
|
|
38787
|
-
});
|
|
38788
38681
|
|
|
38789
38682
|
// src/index.ts
|
|
38790
38683
|
__reExport(index_exports, __toESM(require_place()), module.exports);
|
|
@@ -39076,6 +38969,7 @@ function BuildUseVoucherTx(tx, voucherName) {
|
|
|
39076
38969
|
getPoolSqrtPrice,
|
|
39077
38970
|
getProvider,
|
|
39078
38971
|
getSqrtPriceAtTick,
|
|
38972
|
+
getUserPositions,
|
|
39079
38973
|
getVoucherContract,
|
|
39080
38974
|
getVoucherInfo,
|
|
39081
38975
|
liquidity0,
|
package/dist/index.mjs
CHANGED
|
@@ -36241,6 +36241,7 @@ __export(index_exports, {
|
|
|
36241
36241
|
getPoolSqrtPrice: () => getPoolSqrtPrice,
|
|
36242
36242
|
getProvider: () => getProvider,
|
|
36243
36243
|
getSqrtPriceAtTick: () => getSqrtPriceAtTick,
|
|
36244
|
+
getUserPositions: () => getUserPositions,
|
|
36244
36245
|
getVoucherContract: () => getVoucherContract,
|
|
36245
36246
|
getVoucherInfo: () => getVoucherInfo,
|
|
36246
36247
|
liquidity0: () => liquidity0,
|
|
@@ -38650,144 +38651,36 @@ if (typeof __require !== "undefined" && typeof module !== "undefined" && __requi
|
|
|
38650
38651
|
});
|
|
38651
38652
|
}
|
|
38652
38653
|
|
|
38654
|
+
// src/uniswap/1-marketprice/getPositions.ts
|
|
38655
|
+
init_contract();
|
|
38656
|
+
async function getUserPositions(wallet2, userAddress) {
|
|
38657
|
+
const liqPool = await getContract(wallet2, "LiquidPool");
|
|
38658
|
+
const targetAddress = userAddress || await wallet2.getAddress();
|
|
38659
|
+
console.log(`[SDK] Fetching liquidity NFT positions for address: ${targetAddress}`);
|
|
38660
|
+
try {
|
|
38661
|
+
const positions = await liqPool.getPosition(targetAddress);
|
|
38662
|
+
const formattedPositions = positions.map((pos) => {
|
|
38663
|
+
return {
|
|
38664
|
+
tokenId: pos.tokenId.toNumber(),
|
|
38665
|
+
// tick is int24, so it should fit standard JS number
|
|
38666
|
+
tickLower: pos.tickLower,
|
|
38667
|
+
tickUpper: pos.tickUpper,
|
|
38668
|
+
// liquidity is int256, keep as string to prevent JS precision loss
|
|
38669
|
+
liquidity: pos.liquidity.toString()
|
|
38670
|
+
};
|
|
38671
|
+
});
|
|
38672
|
+
console.log(`[SDK] Found ${formattedPositions.length} position(s).`);
|
|
38673
|
+
return formattedPositions;
|
|
38674
|
+
} catch (error) {
|
|
38675
|
+
console.error(`[SDK] Failed to fetch user positions: `, error);
|
|
38676
|
+
throw error;
|
|
38677
|
+
}
|
|
38678
|
+
}
|
|
38679
|
+
|
|
38653
38680
|
// src/uniswap/3-dynamicfee/dynamicfee.ts
|
|
38654
38681
|
init_lib49();
|
|
38655
38682
|
var provider = new ethers_exports.providers.JsonRpcProvider("http://localhost:8545");
|
|
38656
38683
|
var wallet = new ethers_exports.Wallet("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", provider);
|
|
38657
|
-
async function isdepolyed(address) {
|
|
38658
|
-
let code = await provider.getCode(address);
|
|
38659
|
-
if (code !== "0x") {
|
|
38660
|
-
console.log(`The contract ${address} has been deployed.`);
|
|
38661
|
-
} else {
|
|
38662
|
-
console.log(`The contract ${address} has not been deployed. `);
|
|
38663
|
-
}
|
|
38664
|
-
}
|
|
38665
|
-
async function modifyPosition2(contract, poolKey, modifyPositionParams) {
|
|
38666
|
-
let tx = await contract.setPositionParameters(poolKey, modifyPositionParams);
|
|
38667
|
-
await tx.wait();
|
|
38668
|
-
console.log("Position parameters set successfully");
|
|
38669
|
-
tx = await contract.addLiquidity();
|
|
38670
|
-
await tx.wait();
|
|
38671
|
-
}
|
|
38672
|
-
async function initialize(contract, key3, sqrtPriceX96) {
|
|
38673
|
-
let tick = await contract.initialize(key3, sqrtPriceX96);
|
|
38674
|
-
console.log(`Returned tick: ${JSON.stringify(tick)}`);
|
|
38675
|
-
}
|
|
38676
|
-
async function approveERC202(contract, toAddress, amount) {
|
|
38677
|
-
let tx = await contract.approve(toAddress, amount);
|
|
38678
|
-
let receipt = await tx.wait();
|
|
38679
|
-
console.log(`Transaction hash: ${receipt.transactionHash}`);
|
|
38680
|
-
}
|
|
38681
|
-
async function getERC20Balance2(contract, address) {
|
|
38682
|
-
let balance = await contract.balanceOf(address);
|
|
38683
|
-
console.log(`ERC20 Balance: ${balance.toString()}`);
|
|
38684
|
-
return balance;
|
|
38685
|
-
}
|
|
38686
|
-
async function executeSwap2(contract, poolKey, swapParams) {
|
|
38687
|
-
console.log("begin swap");
|
|
38688
|
-
let to0params = {
|
|
38689
|
-
tickLower: 84e4,
|
|
38690
|
-
// lower price 0.5
|
|
38691
|
-
tickUpper: 876600,
|
|
38692
|
-
// upper price 1.5
|
|
38693
|
-
liquidityDelta: 0
|
|
38694
|
-
};
|
|
38695
|
-
let tx1 = await contract.setPositionParameters(poolKey, to0params);
|
|
38696
|
-
await tx1.wait();
|
|
38697
|
-
let tx2 = await contract.setSwapParameters(poolKey, swapParams);
|
|
38698
|
-
console.log("begin swap1");
|
|
38699
|
-
await tx2.wait();
|
|
38700
|
-
console.log("Position parameters set successfully");
|
|
38701
|
-
let tx3 = await contract.executeSwap();
|
|
38702
|
-
await tx3.wait();
|
|
38703
|
-
}
|
|
38704
|
-
async function depolyContract(contractName, params) {
|
|
38705
|
-
const Factory = await ethers_exports.getContractFactory(contractName);
|
|
38706
|
-
let contract;
|
|
38707
|
-
if (params === void 0) {
|
|
38708
|
-
contract = await Factory.deploy();
|
|
38709
|
-
} else {
|
|
38710
|
-
console.log(`params: ${JSON.stringify(params)}`);
|
|
38711
|
-
contract = await Factory.deploy(params);
|
|
38712
|
-
}
|
|
38713
|
-
await contract.deployed();
|
|
38714
|
-
console.log(`${contractName} deployed to ${contract.address}`);
|
|
38715
|
-
return contract;
|
|
38716
|
-
}
|
|
38717
|
-
describe("PoolManager", function() {
|
|
38718
|
-
it("Should return the new greeting once it's changed", async function() {
|
|
38719
|
-
const token0 = await depolyContract("Token0");
|
|
38720
|
-
const token1 = await depolyContract("Token1");
|
|
38721
|
-
const totalSupply0 = await token0.totalSupply();
|
|
38722
|
-
console.log(`Token0 deployed to ${token0.address} with an initial supply ${totalSupply0}`);
|
|
38723
|
-
const totalSupply1 = await token1.totalSupply();
|
|
38724
|
-
console.log(`Token1 deployed to ${token1.address} with an initial supply ${totalSupply1}`);
|
|
38725
|
-
getERC20Balance2(token0, wallet.address);
|
|
38726
|
-
getERC20Balance2(token1, wallet.address);
|
|
38727
|
-
const token0Address = token0.address < token1.address ? token0.address : token1.address;
|
|
38728
|
-
const token1Address = token0.address > token1.address ? token0.address : token1.address;
|
|
38729
|
-
const poolManager = await depolyContract("PoolManager", 88888888888);
|
|
38730
|
-
const poolManagerAddress = poolManager.address;
|
|
38731
|
-
await isdepolyed(poolManagerAddress);
|
|
38732
|
-
const dynamicFee = await depolyContract("DynamicFee", poolManagerAddress);
|
|
38733
|
-
console.log("LimitOrder Contract deployed to:", dynamicFee.address);
|
|
38734
|
-
let sqrtPriceX96 = BigInt("792281625142643375935439503360");
|
|
38735
|
-
const DYNAMIC_FEE_FLAG2 = 8388608;
|
|
38736
|
-
let poolKey = {
|
|
38737
|
-
currency0: token0Address,
|
|
38738
|
-
currency1: token1Address,
|
|
38739
|
-
fee: DYNAMIC_FEE_FLAG2,
|
|
38740
|
-
tickSpacing: 60,
|
|
38741
|
-
hooks: dynamicFee.address
|
|
38742
|
-
};
|
|
38743
|
-
await initialize(poolManager, poolKey, sqrtPriceX96);
|
|
38744
|
-
const MyLiquidityProvider = await depolyContract("MyLiquidityProvider", poolManagerAddress);
|
|
38745
|
-
const wei = ethers_exports.utils.parseUnits("21000000", 18).toBigInt();
|
|
38746
|
-
await approveERC202(token0, MyLiquidityProvider.address, wei);
|
|
38747
|
-
await approveERC202(token1, MyLiquidityProvider.address, wei);
|
|
38748
|
-
let modifyPositionParams = {
|
|
38749
|
-
tickLower: 45e3,
|
|
38750
|
-
// lower price 90
|
|
38751
|
-
tickUpper: 46980,
|
|
38752
|
-
// upper price 110
|
|
38753
|
-
//liquidityDelta: 194868329805051412324060
|
|
38754
|
-
liquidityDelta: BigInt("10000000000000000000000")
|
|
38755
|
-
// 10000token0 10000token1
|
|
38756
|
-
};
|
|
38757
|
-
await getERC20Balance2(token0, wallet.address);
|
|
38758
|
-
await getERC20Balance2(token1, wallet.address);
|
|
38759
|
-
await modifyPosition2(MyLiquidityProvider, poolKey, modifyPositionParams);
|
|
38760
|
-
console.log("Liquidity added successfully");
|
|
38761
|
-
await getERC20Balance2(token0, wallet.address);
|
|
38762
|
-
await getERC20Balance2(token1, wallet.address);
|
|
38763
|
-
let sqrtpricelimit = ethers_exports.BigNumber.from("7922816251426433759354395033600").toBigInt();
|
|
38764
|
-
let amountswap = ethers_exports.BigNumber.from("1083456789101112134000").toBigInt();
|
|
38765
|
-
console.log("amountswap:", amountswap.toString());
|
|
38766
|
-
let swapParams = {
|
|
38767
|
-
zeroForOne: false,
|
|
38768
|
-
amountSpecified: amountswap,
|
|
38769
|
-
sqrtPriceLimitX96: sqrtpricelimit
|
|
38770
|
-
};
|
|
38771
|
-
let token0beforswap = await getERC20Balance2(token0, wallet.address);
|
|
38772
|
-
let token1beforswap = await getERC20Balance2(token1, wallet.address);
|
|
38773
|
-
await executeSwap2(MyLiquidityProvider, poolKey, swapParams);
|
|
38774
|
-
console.log("swap successfully");
|
|
38775
|
-
let token0afterswap = await getERC20Balance2(token0, wallet.address);
|
|
38776
|
-
let token1afterswap = await getERC20Balance2(token1, wallet.address);
|
|
38777
|
-
console.log("token0 change:", token0afterswap.sub(token0beforswap).toString());
|
|
38778
|
-
console.log("token1 change:", token1afterswap.sub(token1beforswap).toString());
|
|
38779
|
-
console.log("price:", token1afterswap.sub(token1beforswap).toString() / token0afterswap.sub(token0beforswap).toString());
|
|
38780
|
-
token0beforswap = await getERC20Balance2(token0, wallet.address);
|
|
38781
|
-
token1beforswap = await getERC20Balance2(token1, wallet.address);
|
|
38782
|
-
await executeSwap2(MyLiquidityProvider, poolKey, swapParams);
|
|
38783
|
-
console.log("swap successfully");
|
|
38784
|
-
token0afterswap = await getERC20Balance2(token0, wallet.address);
|
|
38785
|
-
token1afterswap = await getERC20Balance2(token1, wallet.address);
|
|
38786
|
-
console.log("token0 change:", token0afterswap.sub(token0beforswap).toString());
|
|
38787
|
-
console.log("token1 change:", token1afterswap.sub(token1beforswap).toString());
|
|
38788
|
-
console.log("price:", token1afterswap.sub(token1beforswap).toString() / token0afterswap.sub(token0beforswap).toString());
|
|
38789
|
-
});
|
|
38790
|
-
});
|
|
38791
38684
|
|
|
38792
38685
|
// src/index.ts
|
|
38793
38686
|
__reExport(index_exports, __toESM(require_place()));
|
|
@@ -39078,6 +38971,7 @@ export {
|
|
|
39078
38971
|
getPoolSqrtPrice,
|
|
39079
38972
|
getProvider,
|
|
39080
38973
|
getSqrtPriceAtTick,
|
|
38974
|
+
getUserPositions,
|
|
39081
38975
|
getVoucherContract,
|
|
39082
38976
|
getVoucherInfo,
|
|
39083
38977
|
liquidity0,
|