Skip to content

Commit

Permalink
feat: sepolia support for deployment script
Browse files Browse the repository at this point in the history
  • Loading branch information
ugur-eren committed Sep 9, 2024
1 parent e1eda38 commit a52e3a4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
8 changes: 4 additions & 4 deletions packages/contracts/scripts/deploy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import colors from "colors";
import { deployFactory, deployTokenLocker } from "./libs/contract.js";
import { deployFactory, deployLockManager } from "./libs/contract.js";

const MIN_LOCK_TIME = 15_721_200; // 6 months

Expand All @@ -11,12 +11,12 @@ const main = async () => {
console.log(` |_| |___|`.red);

// Token Locker
console.log(`\n${"Deploying TokenLocker contract".blue}`);
await deployTokenLocker(MIN_LOCK_TIME);
console.log(`\n${"Deploying LockManager contract".blue}`);
const { lockManager } = await deployLockManager(MIN_LOCK_TIME);

// Factory
console.log(`\n${"Deploying Factory contract".blue}`);
await deployFactory();
await deployFactory(lockManager);
};

main();
41 changes: 28 additions & 13 deletions packages/contracts/scripts/libs/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,26 @@ const getContracts = () => {
return contracts;
};

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

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

const getUnruggableMemecoinPath = () => {
Expand Down Expand Up @@ -88,19 +99,20 @@ const declare = async (filepath, contract_name) => {
return contract;
};

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

// Declare contract
const locker = await declare(getTokenLockerPath(), "TokenLocker");
const lockManager = await declare(getLockManagerPath(), "LockManager");
const lockPosition = await declare(getLockPositionPath(), "LockPosition");

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

// Wait for transaction
Expand All @@ -110,9 +122,11 @@ export const deployTokenLocker = async (min_lock_time) => {
`${network.explorer_url}/tx/${contract.transaction_hash})`,
);
await account.waitForTransaction(contract.transaction_hash);

return { lockManager: contract.address }
};

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

Expand All @@ -133,9 +147,10 @@ export const deployFactory = async () => {
const contract = await account.deployContract({
classHash: factory.class_hash,
constructorCalldata: [
process.env.STARKNET_ACCOUNT_ADDRESS,
memecoin.class_hash,
lockManagerAddress,
exchanges,
[]
],
});

Expand Down

0 comments on commit a52e3a4

Please sign in to comment.