Skip to content

Commit

Permalink
Merge pull request #40 from argentlabs/feat/admin-scripts
Browse files Browse the repository at this point in the history
Scripts for admin functionality
  • Loading branch information
sgc-code authored Jul 1, 2024
2 parents d25f799 + 570b9b9 commit eca7529
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 0 deletions.
18 changes: 18 additions & 0 deletions scripts/cancel_upgrade.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { logTransactionJson } from "./json_tx_builder";

/// To use this script, fill in the following value:
/// - factoryAddress: the address of the factory contract

const factoryAddress = "";

if (!factoryAddress) {
throw new Error("Factory contract address is not set. Please set it in the script file.");
}

const tx = {
contractAddress: factoryAddress,
entrypoint: "cancel_upgrade",
calldata: [],
};

logTransactionJson([tx]);
43 changes: 43 additions & 0 deletions scripts/claim_dust.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { CallData } from "starknet";
import { calculateEscrowAddress } from "../lib";
import { Gift, buildGiftCallData, executeActionOnAccount } from "../lib/claim";
import { logTransactionJson } from "./json_tx_builder";

/// To use this script, fill in the following value:
/// - factoryAddress: the address of the factory contract
/// - dustReceiver: the address of the dust receiver
/// - claim: the claim object

const factoryAddress = "";
const dustReceiver = "";
const claim: Gift = {
factory: factoryAddress,
escrow_class_hash: "",
sender: "",
gift_token: "",
gift_amount: 0n,
fee_token: "",
fee_amount: 0n,
gift_pubkey: 0n,
};

if (!factoryAddress) {
throw new Error("Factory contract address is not set. Please set it in the script file.");
}

if (!dustReceiver) {
throw new Error("Dust receiver address is not set. Please set it in the script file.");
}

for (const key in claim) {
if (key in claim && !claim[key as keyof typeof claim] && key !== "fee_amount" && key !== "gift_amount") {
throw new Error(`The property ${key} is empty in the claim object.`);
}
}

const tx = executeActionOnAccount(
"claim_dust",
calculateEscrowAddress(claim),
CallData.compile([(buildGiftCallData(claim), dustReceiver)]),
);
logTransactionJson([tx]);
5 changes: 5 additions & 0 deletions scripts/json_tx_builder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Call } from "starknet";

export function logTransactionJson(transaction: Call[]) {
console.log(JSON.stringify(transaction, null, 2));
}
18 changes: 18 additions & 0 deletions scripts/pause.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { logTransactionJson } from "./json_tx_builder";

/// To use this script, fill in the following value:
/// - factoryAddress: the address of the factory contract

const factoryAddress = "";

if (!factoryAddress) {
throw new Error("Factory contract address is not set. Please set it in the script file.");
}

const tx = {
contractAddress: factoryAddress,
entrypoint: "pause",
calldata: [],
};

logTransactionJson([tx]);
33 changes: 33 additions & 0 deletions scripts/propose_upgrade.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { CallData } from "starknet";
import { logTransactionJson } from "./json_tx_builder";

/// To use this script, fill in the following value:
/// - factoryAddress: the address of the factory contract
/// - newImplementation: the class ahs of the new implementation contract
/// - callData: the call data for the propose_upgrade function

const factoryAddress = "";
const newImplementation = "";
const callData: any[] = [];

if (!factoryAddress) {
throw new Error("Factory contract address is not set. Please set it in the script file.");
}

if (!newImplementation) {
throw new Error("New implementation class hash is not set. Please set it in the script file.");
}

const tx = {
contractAddress: factoryAddress,
entrypoint: "propose_upgrade",
calldata: CallData.compile([newImplementation, callData]),
};

// date 7 days from now
const date = new Date();
date.setDate(date.getDate() + 7);

logTransactionJson([tx]);

console.log("Proposed upgrade will be ready at: ", date);
18 changes: 18 additions & 0 deletions scripts/unpause.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { logTransactionJson } from "./json_tx_builder";

/// To use this script, fill in the following value:
/// - factoryAddress: the address of the factory contract

const factoryAddress = "";

if (!factoryAddress) {
throw new Error("Factory contract address is not set. Please set it in the script file.");
}

const tx = {
contractAddress: factoryAddress,
entrypoint: "unpause",
calldata: [],
};

logTransactionJson([tx]);
22 changes: 22 additions & 0 deletions scripts/upgrade.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { CallData } from "starknet";
import { logTransactionJson } from "./json_tx_builder";

/// To use this script, fill in the following value:
/// - factoryAddress: the address of the factory contract
/// - callData: upgrade call data

const factoryAddress = "";

const callData: any[] = [];

if (!factoryAddress) {
throw new Error("Factory contract address is not set. Please set it in the script file.");
}

const tx = {
contractAddress: factoryAddress,
entrypoint: "upgrade",
calldata: CallData.compile(callData),
};

logTransactionJson([tx]);

0 comments on commit eca7529

Please sign in to comment.