punkkit-sdk 1.0.24 → 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.js +0 -134
- package/dist/index.mjs +0 -134
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -38678,140 +38678,6 @@ async function getUserPositions(wallet2, userAddress) {
|
|
|
38678
38678
|
init_lib49();
|
|
38679
38679
|
var provider = new ethers_exports.providers.JsonRpcProvider("http://localhost:8545");
|
|
38680
38680
|
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
38681
|
|
|
38816
38682
|
// src/index.ts
|
|
38817
38683
|
__reExport(index_exports, __toESM(require_place()), module.exports);
|
package/dist/index.mjs
CHANGED
|
@@ -38681,140 +38681,6 @@ async function getUserPositions(wallet2, userAddress) {
|
|
|
38681
38681
|
init_lib49();
|
|
38682
38682
|
var provider = new ethers_exports.providers.JsonRpcProvider("http://localhost:8545");
|
|
38683
38683
|
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
38684
|
|
|
38819
38685
|
// src/index.ts
|
|
38820
38686
|
__reExport(index_exports, __toESM(require_place()));
|