diff --git a/contracts/CrocSwapDex.sol b/contracts/CrocSwapDex.sol index 7ca8a85b..9107aecc 100644 --- a/contracts/CrocSwapDex.sol +++ b/contracts/CrocSwapDex.sol @@ -37,8 +37,8 @@ contract CrocSwapDex is HotPath, ICrocMinion { constructor() { // Register to CSR turnstile - // Turnstile turnstile = Turnstile(0xEcf044C5B4b867CFda001101c617eCd347095B44); - // turnstile.register(tx.origin); + Turnstile turnstile = Turnstile(0xEcf044C5B4b867CFda001101c617eCd347095B44); + turnstile.register(tx.origin); // Authority is originally set to deployer address, which can then transfer to // proper governance contract (if deployer already isn't) authority_ = msg.sender; diff --git a/foundry.toml b/foundry.toml index 9283177a..76d58a42 100644 --- a/foundry.toml +++ b/foundry.toml @@ -5,5 +5,8 @@ libs = ['node_modules', 'lib'] test = 'test_other/test_foundry' cache_path = 'forge-cache' via_ir = true +solc-version = "0.8.19" +optimizer = true +optimizer-runs = 14900 # See more config options https://book.getfoundry.sh/reference/config.html diff --git a/hardhat.config.ts b/hardhat.config.ts index e7bd8d9c..b65f4414 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -41,10 +41,10 @@ module.exports = { url: 'http://127.0.0.1:8545', chainId: 31337 }, - canto_testnet: { - url: 'https://testnet-archive.plexnode.wtf', - chainId: 7701, - accounts: ["0x7c5e2cfbba7b00ba95e5ed7cd80566021da709442e147ad3e08f23f5044a3d5a"] + canto_mainnet: { + url: 'https://mainnode.plexnode.org:8545', + chainId: 7700, + accounts: [""] }, ropsten: { url: 'https://ropsten.infura.io/v3/cf3bc905d88d4f248c6be347adc8a1d8', diff --git a/misc/scripts/deploy_canto/deploy1.js b/misc/scripts/deploy_canto/deploy1.js index 1d1bfac7..f9cc1ded 100644 --- a/misc/scripts/deploy_canto/deploy1.js +++ b/misc/scripts/deploy_canto/deploy1.js @@ -5,38 +5,56 @@ async function main() { console.log("Deploying contracts with the account:", deployer.address); - // deploy CrocSwapDex contract - const dex = await ethers.deployContract("CrocSwapDex"); - // deploy ColdPath - const ColdPath = await ethers.deployContract("ColdPath"); - // deploy HotPath - const HotProxy = await ethers.deployContract("HotProxy"); - // deploy KnockoutPath - const KnockoutLiqPath = await ethers.deployContract("KnockoutLiqPath"); - // deploy CrossKnockoutPath - const KnockoutFlagPath = await ethers.deployContract("KnockoutFlagPath"); - // deploy LongPath - const LongPath = await ethers.deployContract("LongPath"); - // deploy MicroPath - const MicroPaths = await ethers.deployContract("MicroPaths"); - // deploy SafeModePath - const SafeModePath = await ethers.deployContract("SafeModePath"); + // // deploy CrocSwapDex contract + // const dex = await ethers.deployContract("CrocSwapDex"); + // await dex.deployed(); + // console.log("CrocSwapDex:", await dex.address); + + // // deploy ColdPath + // const ColdPath = await ethers.deployContract("ColdPath"); + // await ColdPath.deployed(); + // console.log("ColdPath:", await ColdPath.address); + + // // deploy HotPath + // const HotProxy = await ethers.deployContract("HotProxy"); + // await HotProxy.deployed(); + // console.log("HotProxy:", await HotProxy.address); + + // // deploy KnockoutPath + // const KnockoutLiqPath = await ethers.deployContract("KnockoutLiqPath"); + // await KnockoutLiqPath.deployed(); + // console.log("KnockoutLiqPath:", await KnockoutLiqPath.address); + + // // deploy CrossKnockoutPath + // const KnockoutFlagPath = await ethers.deployContract("KnockoutFlagPath"); + // await KnockoutFlagPath.deployed(); + // console.log("KnockoutFlagPath:", await KnockoutFlagPath.address); + + // // deploy LongPath + // const LongPath = await ethers.deployContract("LongPath"); + // await LongPath.deployed(); + // console.log("LongPath:", await LongPath.address); + + // // deploy MicroPath + // const MicroPaths = await ethers.deployContract("MicroPaths"); + // await MicroPaths.deployed(); + // console.log("MicroPaths:", await MicroPaths.address); + + // // deploy SafeModePath + // const SafeModePath = await ethers.deployContract("SafeModePath"); + // await SafeModePath.deployed(); + // console.log("SafeModePath:", await SafeModePath.address); + // deploy WarmPath const WarmPath = await ethers.deployContract("WarmPath"); + await WarmPath.deployed(); + console.log("WarmPath:", await WarmPath.address); + // deploy LiquidityMiningPath const LiquidityMiningPath = await ethers.deployContract( "LiquidityMiningPath" ); - - console.log("CrocSwapDex:", await dex.address); - console.log("HotProxy:", await HotProxy.address); - console.log("WarmPath:", await WarmPath.address); - console.log("ColdPath:", await ColdPath.address); - console.log("LongPath:", await LongPath.address); - console.log("MicroPaths:", await MicroPaths.address); - console.log("KnockoutLiqPath:", await KnockoutLiqPath.address); - console.log("KnockoutFlagPath:", await KnockoutFlagPath.address); - console.log("SafeModePath:", await SafeModePath.address); + await LiquidityMiningPath.deployed(); console.log("LiquidityMiningPath:", await LiquidityMiningPath.address); } diff --git a/misc/scripts/deploy_canto/deploy2.js b/misc/scripts/deploy_canto/deploy2.js index 4f806d1b..65a6c6ad 100644 --- a/misc/scripts/deploy_canto/deploy2.js +++ b/misc/scripts/deploy_canto/deploy2.js @@ -4,18 +4,18 @@ var AbiCoder = require("@ethersproject/abi").AbiCoder; const abi = new AbiCoder(); -// testnet addresses 1 +// mainnet addresses 1 const addresses = { - CrocSwapDex: "0xA4C0F8febA559083Fe47E396f7C4f047E8820253", - HotProxy: "0xcf883bB0B1903b96B10242696D62d54BE94Aa2f5", - WarmPath: "0xafC5554c7710F760E79f748eb900A28B7b1E4FA7", - ColdPath: "0x3b62C6B3430832B970551eab21268e7C87A48912", - LongPath: "0x4d9E727A61b8BEc65300A1b05b31E01C82d4B982", - MicroPaths: "0x663f021531BDE01C2373dA41c3144115e06f9211", - KnockoutLiqPath: "0xcA54dcD6B08687e61D0E44010af35C65C4EDefF4", - KnockoutFlagPath: "0x575298cbc88faB5433928D1cF27C57d779677844", - SafeModePath: "0xC428162feD5E33cBf604dfCBa8Eb9247DE9722a4", - LiquidityMiningPath: "0x5e27C6FD3967275E566F55A4F2f2e56A0d29A461", + CrocSwapDex: "0x9290C893ce949FE13EF3355660d07dE0FB793618", + ColdPath: "0x9B2a63F27661A468E2da22226b64A4914144f195", + HotProxy: "0x35FF0Ae8D893aC4c1Cefd4B5ac80eAb96684D9B7", + KnockoutLiqPath: "0x29BfE042158b5a213c224AFE44C749eC4429527A", + KnockoutFlagPath: "0x35E66506D8d1f456Ac0eD8fF0C50a847d43ec02C", + LongPath: "0x54861bdc3Ce98b0d11a4fEaA965dA97d239762d5", + MicroPaths: "0xB183D02122F55f928d711Ef10C3758A512aCaBd3", + SafeModePath: "0xf6153C52EEdA76728A2139F3ec5a6cE055266F40", + WarmPath: "0x74ff14e7E80DC76C355B156A06882e18C1938A19", + LiquidityMiningPath: "0x2D826ae54b06839042Da0c9B81EAB34bfeA05646", }; const BOOT_PROXY_IDX = 0; @@ -39,61 +39,68 @@ async function main() { const dex = await CrocSwapDex.attach(addresses.CrocSwapDex); // use protocolCmd to install paths - // install coldpath - cmd = abi.encode( - ["uint8", "address", "uint16"], - [21, addresses.ColdPath, COLD_PROXY_IDX] - ); - await dex.protocolCmd(BOOT_PROXY_IDX, cmd, true); - - // install longpath - cmd = abi.encode( - ["uint8", "address", "uint16"], - [21, addresses.LongPath, LONG_PROXY_IDX] - ); - await dex.protocolCmd(BOOT_PROXY_IDX, cmd, true); - - // install warm path - cmd = abi.encode( - ["uint8", "address", "uint16"], - [21, addresses.WarmPath, LP_PROXY_IDX] - ); - await dex.protocolCmd(BOOT_PROXY_IDX, cmd, true); - - // install hot proxy path - cmd = abi.encode( - ["uint8", "address", "uint16"], - [21, addresses.HotProxy, SWAP_PROXY_IDX] - ); - await dex.protocolCmd(BOOT_PROXY_IDX, cmd, true); - - // install micro paths - cmd = abi.encode( - ["uint8", "address", "uint16"], - [21, addresses.MicroPaths, MICRO_PROXY_IDX] - ); - await dex.protocolCmd(BOOT_PROXY_IDX, cmd, true); - - // install knockout lp proxy path - cmd = abi.encode( - ["uint8", "address", "uint16"], - [21, addresses.KnockoutLiqPath, KNOCKOUT_LP_PROXY_IDX] - ); - await dex.protocolCmd(BOOT_PROXY_IDX, cmd, true); - - // install cross knockout cross proxy path - cmd = abi.encode( - ["uint8", "address", "uint16"], - [21, addresses.KnockoutFlagPath, FLAG_CROSS_PROXY_IDX] - ); - await dex.protocolCmd(BOOT_PROXY_IDX, cmd, true); - - // install liquidity mining path - cmd = abi.encode( - ["uint8", "address", "uint16"], - [21, addresses.LiquidityMiningPath, LIQUIDITY_MINING_PROXY_IDX] - ); - await dex.protocolCmd(BOOT_PROXY_IDX, cmd, true); + // // install coldpath + // cmd = abi.encode( + // ["uint8", "address", "uint16"], + // [21, addresses.ColdPath, COLD_PROXY_IDX] + // ); + // await dex.protocolCmd(BOOT_PROXY_IDX, cmd, true); + + // // install longpath + // cmd = abi.encode( + // ["uint8", "address", "uint16"], + // [21, addresses.LongPath, LONG_PROXY_IDX] + // ); + // await dex.protocolCmd(BOOT_PROXY_IDX, cmd, true); + + // // install warm path + // cmd = abi.encode( + // ["uint8", "address", "uint16"], + // [21, addresses.WarmPath, LP_PROXY_IDX] + // ); + // await dex.protocolCmd(BOOT_PROXY_IDX, cmd, true); + + // // install hot proxy path + // cmd = abi.encode( + // ["uint8", "address", "uint16"], + // [21, addresses.HotProxy, SWAP_PROXY_IDX] + // ); + // await dex.protocolCmd(BOOT_PROXY_IDX, cmd, true); + + // // install micro paths + // cmd = abi.encode( + // ["uint8", "address", "uint16"], + // [21, addresses.MicroPaths, MICRO_PROXY_IDX] + // ); + // await dex.protocolCmd(BOOT_PROXY_IDX, cmd, true); + + // // install knockout lp proxy path + // cmd = abi.encode( + // ["uint8", "address", "uint16"], + // [21, addresses.KnockoutLiqPath, KNOCKOUT_LP_PROXY_IDX] + // ); + // await dex.protocolCmd(BOOT_PROXY_IDX, cmd, true); + + // // install cross knockout cross proxy path + // cmd = abi.encode( + // ["uint8", "address", "uint16"], + // [21, addresses.KnockoutFlagPath, FLAG_CROSS_PROXY_IDX] + // ); + // await dex.protocolCmd(BOOT_PROXY_IDX, cmd, true); + + // // install safe mode path + // cmd = abi.encode( + // ["uint8", "address", "uint16"], + // [21, addresses.SafeModePath, SAFE_MODE_PROXY_PATH] + // ); + // await dex.protocolCmd(BOOT_PROXY_IDX, cmd, true); + + // // install liquidity mining path + // cmd = abi.encode( + // ["uint8", "address", "uint16"], + // [21, addresses.LiquidityMiningPath, LIQUIDITY_MINING_PROXY_IDX] + // ); + // await dex.protocolCmd(BOOT_PROXY_IDX, cmd, true); } main() diff --git a/misc/scripts/deploy_canto/deploy3.js b/misc/scripts/deploy_canto/deploy3.js index b88cd724..05e278e4 100644 --- a/misc/scripts/deploy_canto/deploy3.js +++ b/misc/scripts/deploy_canto/deploy3.js @@ -1,7 +1,7 @@ // Deploy Croc Lens Contracts // testnet dex address -const dexAddress = "0xA4C0F8febA559083Fe47E396f7C4f047E8820253"; +const dexAddress = "0x9290C893ce949FE13EF3355660d07dE0FB793618"; async function main() { const [deployer] = await ethers.getSigners(); diff --git a/misc/scripts/deploy_canto/deploy4Pool.js b/misc/scripts/deploy_canto/deploy4Pool.js index 5af65d7d..b32ee496 100644 --- a/misc/scripts/deploy_canto/deploy4Pool.js +++ b/misc/scripts/deploy_canto/deploy4Pool.js @@ -8,10 +8,10 @@ const abi = new AbiCoder(); const PRECISION = 100000000; const Q_64 = BigNumber.from(2).pow(64); -// testnet dex address -const dexAddress = "0xA4C0F8febA559083Fe47E396f7C4f047E8820253"; -const usdcAddress = "0xc51534568489f47949A828C8e3BF68463bdF3566"; -const cNoteAddress = "0x04E52476d318CdF739C38BD41A922787D441900c"; +// mainnet dex address +const dexAddress = "0x9290C893ce949FE13EF3355660d07dE0FB793618"; +const usdcAddress = "0x80b5a32E4F032B2a058b4F29EC95EEfEEB87aDcd"; +const cNoteAddress = "0xEe602429Ef7eCe0a13e4FfE8dBC16e101049504C"; async function main() { const [deployer] = await ethers.getSigners(); @@ -31,7 +31,7 @@ async function main() { approveCNOTE = await cNOTE.approve(dexAddress, BigNumber.from(10).pow(36)); await approveCNOTE.wait(); - /* + /* / 2. set new pool liquidity (amount to lock up for new pool) / params = [code, liq] */ @@ -46,7 +46,7 @@ async function main() { */ let templateCmd = abi.encode( ["uint8", "uint256", "uint16", "uint16", "uint8", "uint8", "uint8"], - [110, 36000, 500, 1, 2, 64, 0] + [110, 36000, 100, 1, 8, 64, 0] ); tx = await dex.protocolCmd(3, templateCmd, false); await tx.wait(); @@ -58,11 +58,11 @@ async function main() { */ let initPoolCmd = abi.encode( ["uint8", "address", "address", "uint256", "uint128"], - [71, cNoteAddress, usdcAddress, 36000, toSqrtPrice(Math.pow(10, 12))] + [71, usdcAddress, cNoteAddress, 36000, toSqrtPrice(Math.pow(10, -12))] ); tx = await dex.userCmd(3, initPoolCmd, { gasLimit: 6000000 }); await tx.wait(); - console.log(tx); + console.log("Initialized new pool"); // // ----------------------------- // // EXTRA FUNCTIONS diff --git a/misc/scripts/deploy_canto/deploy5AddLiquidity.js b/misc/scripts/deploy_canto/deploy5AddLiquidity.js index 2648e7bd..dc1061f3 100644 --- a/misc/scripts/deploy_canto/deploy5AddLiquidity.js +++ b/misc/scripts/deploy_canto/deploy5AddLiquidity.js @@ -9,9 +9,9 @@ const PRECISION = 100000000; const Q_64 = BigNumber.from(2).pow(64); // testnet dex address -const dexAddress = "0xA4C0F8febA559083Fe47E396f7C4f047E8820253"; -const usdcAddress = "0xc51534568489f47949A828C8e3BF68463bdF3566"; -const cNoteAddress = "0x04E52476d318CdF739C38BD41A922787D441900c"; +const dexAddress = "0x9290C893ce949FE13EF3355660d07dE0FB793618"; +const usdcAddress = "0x80b5a32E4F032B2a058b4F29EC95EEfEEB87aDcd"; +const cNoteAddress = "0xEe602429Ef7eCe0a13e4FfE8dBC16e101049504C"; async function main() { const [deployer] = await ethers.getSigners(); @@ -21,7 +21,7 @@ async function main() { const CrocSwapDex = await hre.ethers.getContractFactory("CrocSwapDex"); const dex = await CrocSwapDex.attach(dexAddress); - const currentTick = 276324; + const currentTick = -276325; const ZERO_ADDR = "0x0000000000000000000000000000000000000000"; // Mint concentrated liquidity @@ -41,21 +41,20 @@ async function main() { ], [ 11, // code (mint concentrated liquidity in base token liq) - cNoteAddress, // base token - usdcAddress, // quote token + usdcAddress, // base token + cNoteAddress, // quote token 36000, // poolIDX - currentTick - 10, // tickLower - currentTick + 10, // tickUpper - BigNumber.from("100000000000000000000"), // amount of base token to send - BigNumber.from("16602069666338596454400000"), // min price - BigNumber.from("20291418481080506777600000"), // max price + currentTick - 75, // tickLower + currentTick + 75, // tickUpper + BigNumber.from("10000000"), // amount of base token to send + BigNumber.from("18446744073"), // min price + BigNumber.from("18446744073709000"), // max price 0, // reserve flag ZERO_ADDR, // lp conduit address (0 if not using) ] ); tx = await dex.userCmd(2, mintConcentratedLiqCmd, { gasLimit: 6000000, - value: ethers.utils.parseUnits("1", "ether"), }); await tx.wait(); console.log(tx); diff --git a/misc/scripts/deploy_canto/swapTest.js b/misc/scripts/deploy_canto/swapTest.js index dc7483d5..5651aaf5 100644 --- a/misc/scripts/deploy_canto/swapTest.js +++ b/misc/scripts/deploy_canto/swapTest.js @@ -9,9 +9,9 @@ const PRECISION = 100000000; const Q_64 = BigNumber.from(2).pow(64); // testnet dex address -const dexAddress = "0xd9bac85f6ac9fBFd2559A4Ac2883c635C29Feb4b"; -const usdcAddress = "0xc51534568489f47949A828C8e3BF68463bdF3566"; -const cNoteAddress = "0x04E52476d318CdF739C38BD41A922787D441900c"; +const dexAddress = "0x9290C893ce949FE13EF3355660d07dE0FB793618"; +const usdcAddress = "0x80b5a32E4F032B2a058b4F29EC95EEfEEB87aDcd"; +const cNoteAddress = "0xEe602429Ef7eCe0a13e4FfE8dBC16e101049504C"; async function main() { const [deployer] = await ethers.getSigners(); @@ -46,15 +46,15 @@ async function main() { // ); swapTx = await dex.swap( - cNoteAddress, usdcAddress, + cNoteAddress, 36000, false, - false, - BigNumber.from("20000000"), + true, + BigNumber.from("1000000"), 0, - BigNumber.from("16602069666338596454400000"), - BigNumber.from("19000000000000000000"), + BigNumber.from("16446744073709"), + BigNumber.from("1080000000000000000"), 0 );