Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(contracts): deploy on sepolia testnet #281

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,5 @@ build

# Misc
.DS_Store

target/
31 changes: 17 additions & 14 deletions packages/contracts/scripts/deploy.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import colors from "colors";
import { deployFactory, deployTokenLocker } from "./libs/contract.js";
/* import colors from 'colors' */
import { deployFactory, deployLockManager, deployEkuboLauncher } from './libs/contract.js'

const MIN_LOCK_TIME = 15_721_200; // 6 months
const MIN_LOCK_TIME = 15_721_200 // 6 months

const main = async () => {
console.log(` ____ _ `.red);
console.log(` | \\ ___ ___| |___ _ _ `.red);
console.log(` | | | -_| . | | . | | |`.red);
console.log(` |____/|___| _|_|___|_ |`.red);
console.log(` |_| |___|`.red);
console.log(` ____ _ `.red)
console.log(` | \\ ___ ___| |___ _ _ `.red)
console.log(` | | | -_| . | | . | | |`.red)
console.log(` |____/|___| _|_|___|_ |`.red)
console.log(` |_| |___|`.red)

// Token Locker
console.log(`\n${"Deploying TokenLocker contract".blue}`);
await deployTokenLocker(MIN_LOCK_TIME);
// console.log(`\n${'Deploying LockManager contract'.blue}`)
// await deployLockManager(MIN_LOCK_TIME, "0x013d8ed1df7eae07a2ea97fc23d6f2e99717a0d4f686dfb5c16e67aa1a806ced")

// console.log(`\n${'Deploying Ekubo launcher contract'.blue}`)
// const ekuboLauncherAddress = await deployEkuboLauncher();

// Factory
console.log(`\n${"Deploying Factory contract".blue}`);
await deployFactory();
};
console.log(`\n${'Deploying Factory contract'.blue}`)
await deployFactory("0x011d74272a1f83791cfAb19702AE28ba396f9A5cF8a5A689eb1C88C32419fe02", "0x01aE6B1EB0B2a1B0F1c3cC75Af16402AE98EE696B6A5633f8b03D31519300175")
}

main();
main()
216 changes: 113 additions & 103 deletions packages/contracts/scripts/libs/contract.js
Original file line number Diff line number Diff line change
@@ -1,149 +1,159 @@
import "dotenv/config";
import * as fs from "fs";
import * as path from "path";
import colors from "colors";
import { fileURLToPath } from "url";
import { json } from "starknet";
import { getNetwork, getAccount } from "./network.js";
import { getExchanges } from "./exchange.js";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const TARGET_PATH = path.join(__dirname, "..", "..", "target", "dev");
import 'dotenv/config'
import * as fs from 'fs'
import * as path from 'path'
import colors from 'colors'
import { fileURLToPath } from 'url'
import { json } from 'starknet'
import { getNetwork, getAccount } from './network.js'
import { getExchanges } from './exchange.js'

const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
const TARGET_PATH = path.join(__dirname, '..', '..', 'target', 'dev')

const getContracts = () => {
if (!fs.existsSync(TARGET_PATH)) {
throw new Error(`Target directory not found at path: ${TARGET_PATH}`);
throw new Error(`Target directory not found at path: ${TARGET_PATH}`)
}
const contracts = fs
.readdirSync(TARGET_PATH)
.filter((contract) => contract.includes(".contract_class.json"));
const contracts = fs.readdirSync(TARGET_PATH).filter((contract) => contract.includes('.contract_class.json'))
if (contracts.length === 0) {
throw new Error("No build files found. Run `scarb build` first");
throw new Error('No build files found. Run `scarb build` first')
}
return contracts;
};

const getTokenLockerPath = () => {
const contracts = getContracts();
const tokenLocker = contracts.find((contract) =>
contract.includes("TokenLocker"),
);
return contracts
}

const getLockManagerPath = () => {
const contracts = getContracts()

const tokenLocker = contracts.find((contract) => contract.includes('LockManager'))
if (!tokenLocker) {
throw new Error("TokenLocker contract not found. Run `scarb build` first");
throw new Error('TokenLocker contract not found. Run `scarb build` first')
}
return path.join(TARGET_PATH, tokenLocker)
}

const getEkuboLauncherPath = () => {
const contracts = getContracts()
const ekuboLauncher = contracts.find((contract) => contract.includes('EkuboLauncher'))
if (!ekuboLauncher) {
throw new Error('EkuboLauncher contract not found. Run `scarb build` first')
}
return path.join(TARGET_PATH, tokenLocker);
};
return path.join(TARGET_PATH, ekuboLauncher)
}

const getUnruggableMemecoinPath = () => {
const contracts = getContracts();
const unruggableMemecoin = contracts.find((contract) =>
contract.includes("UnruggableMemecoin"),
);
const contracts = getContracts()
const unruggableMemecoin = contracts.find((contract) => contract.includes('UnruggableMemecoin'))
if (!unruggableMemecoin) {
throw new Error(
"UnruggableMemecoin contract not found. Run `scarb build` first",
);
throw new Error('UnruggableMemecoin contract not found. Run `scarb build` first')
}
return path.join(TARGET_PATH, unruggableMemecoin);
};
return path.join(TARGET_PATH, unruggableMemecoin)
}

const getFactoryPath = () => {
const contracts = getContracts();
const factory = contracts.find((contract) => contract.includes("Factory"));
const contracts = getContracts()
const factory = contracts.find((contract) => contract.includes('Factory'))
if (!factory) {
throw new Error("Factory contract not found. Run `scarb build` first");
throw new Error('Factory contract not found. Run `scarb build` first')
}
return path.join(TARGET_PATH, factory);
};
return path.join(TARGET_PATH, factory)
}

const declare = async (filepath, contract_name) => {
console.log(`\nDeclaring ${contract_name}...`.magenta);
const compiledSierraCasm = filepath.replace(
".contract_class.json",
".compiled_contract_class.json",
);
const compiledFile = json.parse(fs.readFileSync(filepath).toString("ascii"));
const compiledSierraCasmFile = json.parse(
fs.readFileSync(compiledSierraCasm).toString("ascii"),
);
const account = getAccount();
console.log(`\nDeclaring ${contract_name}...`.magenta)
const compiledSierraCasm = filepath.replace('.contract_class.json', '.compiled_contract_class.json')
const compiledFile = json.parse(fs.readFileSync(filepath).toString('ascii'))
const compiledSierraCasmFile = json.parse(fs.readFileSync(compiledSierraCasm).toString('ascii'))
const account = getAccount()

const contract = await account.declareIfNot({
contract: compiledFile,
casm: compiledSierraCasmFile,
});
})

const network = getNetwork(process.env.STARKNET_NETWORK);
console.log(`- Class Hash: `.magenta, `${contract.class_hash}`);
const network = getNetwork(process.env.STARKNET_NETWORK)
console.log(`- Class Hash: `.magenta, `${contract.class_hash}`)
if (contract.transaction_hash) {
console.log(
"- Tx Hash: ".magenta,
`${network.explorer_url}/tx/${contract.transaction_hash})`,
);
await account.waitForTransaction(contract.transaction_hash);
console.log('- Tx Hash: '.magenta, `${network.explorer_url}/tx/${contract.transaction_hash})`)
await account.waitForTransaction(contract.transaction_hash)
} else {
console.log("- Tx Hash: ".magenta, "Already declared");
console.log('- Tx Hash: '.magenta, 'Already declared')
}

return contract;
};
return contract
}

export const deployTokenLocker = async (min_lock_time) => {
export const deployLockManager = async (minLockTime, lockPositionClassHash) => {
// Load account
const account = getAccount();
const account = getAccount()

// Declare contract
const locker = await declare(getTokenLockerPath(), "TokenLocker");

const path = getLockManagerPath()
console.log('=> path', path)
const locker = await declare(path, 'LockManager')

// Deploy contract
console.log(`\nDeploying TokenLocker...`.green);
console.log("Min lock time: ".green, min_lock_time);
console.log(`\nDeploying LockManager...`.green)
console.log('Min lock time: '.green, minLockTime)
const contract = await account.deployContract({
classHash: locker.class_hash,
constructorCalldata: [min_lock_time],
});
constructorCalldata: [minLockTime, lockPositionClassHash],
})

// Wait for transaction
const network = getNetwork(process.env.STARKNET_NETWORK)
console.log('Tx hash: '.green, `${network.explorer_url}/tx/${contract.transaction_hash})`)
await account.waitForTransaction(contract.transaction_hash)
}

export const deployEkuboLauncher = async () => {
// Load account
const account = getAccount()

const ekuboLauncher = await declare(getEkuboLauncherPath(), 'EkuboLauncher')
console.log('=> ekuboLauncher', ekuboLauncher)

const contract = await account.deployContract({
classHash: ekuboLauncher.class_hash,
constructorCalldata: [
'0x0444a09d96389aa7148f1aada508e30b71299ffe650d9c97fdaae38cb9a23384', // ekubo core
'0x04484f91f0d2482bad844471ca8dc8e846d3a0211792322e72f21f0f44be63e5', // ekubo registry
'0x06a2aee84bb0ed5dded4384ddd0e40e9c1372b818668375ab8e3ec08807417e5', // ekubo positions
'0x0045f933adf0607292468ad1c1dedaa74d5ad166392590e72676a34d01d7b763', // ekubo router
],
})

// Wait for transaction
const network = getNetwork(process.env.STARKNET_NETWORK);
console.log(
"Tx hash: ".green,
`${network.explorer_url}/tx/${contract.transaction_hash})`,
);
await account.waitForTransaction(contract.transaction_hash);
};

export const deployFactory = async () => {
const network = getNetwork(process.env.STARKNET_NETWORK)
console.log('Tx hash: '.green, `${network.explorer_url}/tx/${contract.transaction_hash})`)
await account.waitForTransaction(contract.transaction_hash)

return contract.address
}

export const deployFactory = async (lockManagerAddress, ekuboLauncherAddress) => {
// Load account
const account = getAccount();
const account = getAccount()

// Declare contracts
const memecoin = await declare(
getUnruggableMemecoinPath(),
"UnruggableMemecoin",
);
const factory = await declare(getFactoryPath(), "Factory");
const memecoin = await declare(getUnruggableMemecoinPath(), 'UnruggableMemecoin')
const factory = await declare(getFactoryPath(), 'Factory')

// Deploy factory
const exchanges = getExchanges(process.env.STARKNET_NETWORK);
console.log(`\nDeploying Factory...`.green);
console.log("Owner: ".green, process.env.STARKNET_ACCOUNT_ADDRESS);
console.log("Memecoin class hash: ".green, memecoin.class_hash);
console.log("Exchanges: ".green, exchanges);
const exchanges = getExchanges(process.env.STARKNET_NETWORK)
console.log(`\nDeploying Factory...`.green)
console.log('Owner: '.green, process.env.STARKNET_ACCOUNT_ADDRESS)
console.log('Memecoin class hash: '.green, memecoin.class_hash)
console.log('Exchanges: '.green, exchanges)

const contract = await account.deployContract({
classHash: factory.class_hash,
constructorCalldata: [
process.env.STARKNET_ACCOUNT_ADDRESS,
memecoin.class_hash,
exchanges,
],
});
constructorCalldata: [memecoin.class_hash, lockManagerAddress, 1, 1, ekuboLauncherAddress, []],
})

// Wait for transaction
const network = getNetwork(process.env.STARKNET_NETWORK);
console.log(
"Tx hash: ".green,
`${network.explorer_url}/tx/${contract.transaction_hash})`,
);
await account.waitForTransaction(contract.transaction_hash);
};
const network = getNetwork(process.env.STARKNET_NETWORK)
console.log('Tx hash: '.green, `${network.explorer_url}/tx/${contract.transaction_hash})`)
await account.waitForTransaction(contract.transaction_hash)
}
30 changes: 15 additions & 15 deletions packages/contracts/scripts/libs/exchange.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
const EXCHANGES = {
mainnet: [
{
name: "JediSwap",
contract_address:
"0x041fd22b238fa21cfcf5dd45a8548974d8263b3a531a60388411c5e230f97023",
name: 'JediSwap',
contract_address: '0x041fd22b238fa21cfcf5dd45a8548974d8263b3a531a60388411c5e230f97023',
},
],
goerli: [
{
name: "JediSwap",
contract_address:
"0x02bcc885342ebbcbcd170ae6cafa8a4bed22bb993479f49806e72d96af94c965",
},
"name": "Ekubo",
"contract_address": "0x00000005dd3D2F4429AF886cD1a3b08289DBcEa99A294197E9eB43b0e0325b4b"
}
],
sepolia: [
{
name: "JediSwap",
contract_address: "",
name: 'JediSwap',
contract_address: '0x0',
},
{
name: "Ekubo",
contract_address: '0x0444a09d96389aa7148f1aada508e30b71299ffe650d9c97fdaae38cb9a23384'
}
],
};
}

export const getExchanges = (network) => {
if (!EXCHANGES[network.toLowerCase()]) {
throw new Error(`Network ${network} not found`);
throw new Error(`Network ${network} not found`)
}
return EXCHANGES[network.toLowerCase()];
};
return EXCHANGES[network.toLowerCase()]
}
Loading