From e47ae9e4e975ae84879469247a396dddf39bd477 Mon Sep 17 00:00:00 2001 From: Leonard Paturel Date: Mon, 24 Jun 2024 11:26:04 +0100 Subject: [PATCH 1/8] basic scripts --- scripts/claim-dust.ts | 43 ++++++++++++++++++++++++++++++++++++++ scripts/jsonTxBuilder.ts | 9 ++++++++ scripts/pause.ts | 18 ++++++++++++++++ scripts/propose-upgrade.ts | 33 +++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 scripts/claim-dust.ts create mode 100644 scripts/jsonTxBuilder.ts create mode 100644 scripts/pause.ts create mode 100644 scripts/propose-upgrade.ts diff --git a/scripts/claim-dust.ts b/scripts/claim-dust.ts new file mode 100644 index 0000000..8e02aa4 --- /dev/null +++ b/scripts/claim-dust.ts @@ -0,0 +1,43 @@ +import { CallData } from "starknet"; +import { Claim, buildCallDataClaim } from "../lib/claim"; +import { logTransactionJson } from "./jsonTxBuilder"; + +/// 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 = "0"; +const claim: Claim = { + factory: factoryAddress, + class_hash: "", + sender: "", + gift_token: "", + gift_amount: 0n, + fee_token: "", + fee_amount: 0n, + claim_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 (let key in claim) { + if (!claim[key] && key !== "fee_amount" && key !== "gift_amount") { + throw new Error(`The property ${key} is empty in the claim object.`); + } +} + +const tx = { + contractAddress: factoryAddress, + entrypoint: "get_dust", + calldata: CallData.compile([buildCallDataClaim(claim), dustReceiver]), +}; + +logTransactionJson([tx]); diff --git a/scripts/jsonTxBuilder.ts b/scripts/jsonTxBuilder.ts new file mode 100644 index 0000000..f2616c9 --- /dev/null +++ b/scripts/jsonTxBuilder.ts @@ -0,0 +1,9 @@ +interface Transaction { + contractAddress: string; + entrypoint: string; + calldata: (string | number | undefined)[]; +} + +export function logTransactionJson(transaction: Transaction[]) { + console.log(JSON.stringify(transaction, null, 2)); +} diff --git a/scripts/pause.ts b/scripts/pause.ts new file mode 100644 index 0000000..371a7e4 --- /dev/null +++ b/scripts/pause.ts @@ -0,0 +1,18 @@ +import { logTransactionJson } from "./jsonTxBuilder"; + +/// 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]); diff --git a/scripts/propose-upgrade.ts b/scripts/propose-upgrade.ts new file mode 100644 index 0000000..6eed047 --- /dev/null +++ b/scripts/propose-upgrade.ts @@ -0,0 +1,33 @@ +import { CallData } from "starknet"; +import { logTransactionJson } from "./jsonTxBuilder"; + +/// 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 = []; + +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); From 1c892ea187de2f6ea9b37c12f3a3a9ae216344fe Mon Sep 17 00:00:00 2001 From: Leonard Paturel Date: Mon, 24 Jun 2024 11:29:39 +0100 Subject: [PATCH 2/8] scripts --- scripts/upgrade.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 scripts/upgrade.ts diff --git a/scripts/upgrade.ts b/scripts/upgrade.ts new file mode 100644 index 0000000..e7c7e09 --- /dev/null +++ b/scripts/upgrade.ts @@ -0,0 +1,22 @@ +import { CallData } from "starknet"; +import { logTransactionJson } from "./jsonTxBuilder"; + +/// To use this script, fill in the following value: +/// - factoryAddress: the address of the factory contract +/// - callData: upgrade call data + +const factoryAddress = ""; + +const callData = []; + +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]); From 87944cf302fbda317a625a3edb6761ba8fb6a66a Mon Sep 17 00:00:00 2001 From: Leonard-Pat <106159231+Leonard-Pat@users.noreply.github.com> Date: Mon, 24 Jun 2024 11:53:27 +0100 Subject: [PATCH 3/8] Update scripts/claim-dust.ts Co-authored-by: gaetbout --- scripts/claim-dust.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/claim-dust.ts b/scripts/claim-dust.ts index 8e02aa4..eb81134 100644 --- a/scripts/claim-dust.ts +++ b/scripts/claim-dust.ts @@ -28,7 +28,7 @@ if (!dustReceiver) { throw new Error("Dust receiver address is not set. Please set it in the script file."); } -for (let key in claim) { +for (const key in claim) { if (!claim[key] && key !== "fee_amount" && key !== "gift_amount") { throw new Error(`The property ${key} is empty in the claim object.`); } From e8559d13f13165178ab5b52f82fac5c07c61aa95 Mon Sep 17 00:00:00 2001 From: Leonard Paturel Date: Mon, 24 Jun 2024 11:59:17 +0100 Subject: [PATCH 4/8] fix linting errors --- scripts/claim-dust.ts | 4 ++-- scripts/propose-upgrade.ts | 2 +- scripts/upgrade.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/claim-dust.ts b/scripts/claim-dust.ts index eb81134..e4932be 100644 --- a/scripts/claim-dust.ts +++ b/scripts/claim-dust.ts @@ -8,7 +8,7 @@ import { logTransactionJson } from "./jsonTxBuilder"; /// - claim: the claim object const factoryAddress = ""; -const dustReceiver = "0"; +const dustReceiver = ""; const claim: Claim = { factory: factoryAddress, class_hash: "", @@ -29,7 +29,7 @@ if (!dustReceiver) { } for (const key in claim) { - if (!claim[key] && key !== "fee_amount" && key !== "gift_amount") { + 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.`); } } diff --git a/scripts/propose-upgrade.ts b/scripts/propose-upgrade.ts index 6eed047..bc24f7e 100644 --- a/scripts/propose-upgrade.ts +++ b/scripts/propose-upgrade.ts @@ -8,7 +8,7 @@ import { logTransactionJson } from "./jsonTxBuilder"; const factoryAddress = ""; const newImplementation = ""; -const callData = []; +const callData: any[] = []; if (!factoryAddress) { throw new Error("Factory contract address is not set. Please set it in the script file."); diff --git a/scripts/upgrade.ts b/scripts/upgrade.ts index e7c7e09..cdbd03b 100644 --- a/scripts/upgrade.ts +++ b/scripts/upgrade.ts @@ -7,7 +7,7 @@ import { logTransactionJson } from "./jsonTxBuilder"; const factoryAddress = ""; -const callData = []; +const callData: any[] = []; if (!factoryAddress) { throw new Error("Factory contract address is not set. Please set it in the script file."); From e42c4085d8a8e0c3085b1a0b479306b72bbf27c6 Mon Sep 17 00:00:00 2001 From: Leonard Paturel Date: Fri, 28 Jun 2024 15:22:05 +0100 Subject: [PATCH 5/8] update scripts --- scripts/cancel-upgrade.ts | 18 ++++++++++++++++++ scripts/claim-dust.ts | 25 +++++++++++++++---------- scripts/jsonTxBuilder.ts | 8 ++------ scripts/unpause.ts | 18 ++++++++++++++++++ 4 files changed, 53 insertions(+), 16 deletions(-) create mode 100644 scripts/cancel-upgrade.ts create mode 100644 scripts/unpause.ts diff --git a/scripts/cancel-upgrade.ts b/scripts/cancel-upgrade.ts new file mode 100644 index 0000000..0989d5c --- /dev/null +++ b/scripts/cancel-upgrade.ts @@ -0,0 +1,18 @@ +import { logTransactionJson } from "./jsonTxBuilder"; + +/// 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]); diff --git a/scripts/claim-dust.ts b/scripts/claim-dust.ts index e4932be..a36302f 100644 --- a/scripts/claim-dust.ts +++ b/scripts/claim-dust.ts @@ -1,23 +1,25 @@ import { CallData } from "starknet"; -import { Claim, buildCallDataClaim } from "../lib/claim"; +import { Gift, buildGiftCallData, executeActionOnAccount } from "../lib/claim"; import { logTransactionJson } from "./jsonTxBuilder"; /// To use this script, fill in the following value: /// - factoryAddress: the address of the factory contract +/// - escrowAddress: the address of the escrow account /// - dustReceiver: the address of the dust receiver /// - claim: the claim object const factoryAddress = ""; +const escrowAddress = ""; const dustReceiver = ""; -const claim: Claim = { +const claim: Gift = { factory: factoryAddress, - class_hash: "", + escrow_class_hash: "", sender: "", gift_token: "", gift_amount: 0n, fee_token: "", fee_amount: 0n, - claim_pubkey: 0n, + gift_pubkey: 0n, }; if (!factoryAddress) { @@ -28,16 +30,19 @@ if (!dustReceiver) { throw new Error("Dust receiver address is not set. Please set it in the script file."); } +if (!escrowAddress) { + throw new Error("Escrow 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 = { - contractAddress: factoryAddress, - entrypoint: "get_dust", - calldata: CallData.compile([buildCallDataClaim(claim), dustReceiver]), -}; - +const tx = executeActionOnAccount( + "get_dust", + escrowAddress, + CallData.compile([(buildGiftCallData(claim), dustReceiver)]), +); logTransactionJson([tx]); diff --git a/scripts/jsonTxBuilder.ts b/scripts/jsonTxBuilder.ts index f2616c9..31f2b8d 100644 --- a/scripts/jsonTxBuilder.ts +++ b/scripts/jsonTxBuilder.ts @@ -1,9 +1,5 @@ -interface Transaction { - contractAddress: string; - entrypoint: string; - calldata: (string | number | undefined)[]; -} +import { Call } from "starknet"; -export function logTransactionJson(transaction: Transaction[]) { +export function logTransactionJson(transaction: Call[]) { console.log(JSON.stringify(transaction, null, 2)); } diff --git a/scripts/unpause.ts b/scripts/unpause.ts new file mode 100644 index 0000000..5fb1fc7 --- /dev/null +++ b/scripts/unpause.ts @@ -0,0 +1,18 @@ +import { logTransactionJson } from "./jsonTxBuilder"; + +/// 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]); From 10eeca5347f2f2e59306732cc916885236e391cf Mon Sep 17 00:00:00 2001 From: Leonard Paturel Date: Mon, 1 Jul 2024 10:39:26 +0100 Subject: [PATCH 6/8] update claim dust --- scripts/claim-dust.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/scripts/claim-dust.ts b/scripts/claim-dust.ts index a36302f..c5f179d 100644 --- a/scripts/claim-dust.ts +++ b/scripts/claim-dust.ts @@ -1,15 +1,14 @@ import { CallData } from "starknet"; +import { calculateEscrowAddress } from "../lib"; import { Gift, buildGiftCallData, executeActionOnAccount } from "../lib/claim"; import { logTransactionJson } from "./jsonTxBuilder"; /// To use this script, fill in the following value: /// - factoryAddress: the address of the factory contract -/// - escrowAddress: the address of the escrow account /// - dustReceiver: the address of the dust receiver /// - claim: the claim object const factoryAddress = ""; -const escrowAddress = ""; const dustReceiver = ""; const claim: Gift = { factory: factoryAddress, @@ -30,10 +29,6 @@ if (!dustReceiver) { throw new Error("Dust receiver address is not set. Please set it in the script file."); } -if (!escrowAddress) { - throw new Error("Escrow 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.`); @@ -41,8 +36,8 @@ for (const key in claim) { } const tx = executeActionOnAccount( - "get_dust", - escrowAddress, + "claim_dust", + calculateEscrowAddress(claim), CallData.compile([(buildGiftCallData(claim), dustReceiver)]), ); logTransactionJson([tx]); From 936ef2800bf23c75aa9129ad392f24944c737619 Mon Sep 17 00:00:00 2001 From: Leonard Paturel Date: Mon, 1 Jul 2024 10:46:57 +0100 Subject: [PATCH 7/8] rename file to snake --- scripts/{cancel-upgrade.ts => cancel_upgrade.ts} | 2 +- scripts/{claim-dust.ts => claim_dust.ts} | 2 +- scripts/{jsonTxBuilder.ts => json_tx_builder.ts} | 0 scripts/pause.ts | 2 +- scripts/{propose-upgrade.ts => propose_upgrade.ts} | 0 scripts/unpause.ts | 2 +- scripts/upgrade.ts | 2 +- 7 files changed, 5 insertions(+), 5 deletions(-) rename scripts/{cancel-upgrade.ts => cancel_upgrade.ts} (87%) rename scripts/{claim-dust.ts => claim_dust.ts} (95%) rename scripts/{jsonTxBuilder.ts => json_tx_builder.ts} (100%) rename scripts/{propose-upgrade.ts => propose_upgrade.ts} (100%) diff --git a/scripts/cancel-upgrade.ts b/scripts/cancel_upgrade.ts similarity index 87% rename from scripts/cancel-upgrade.ts rename to scripts/cancel_upgrade.ts index 0989d5c..034eda8 100644 --- a/scripts/cancel-upgrade.ts +++ b/scripts/cancel_upgrade.ts @@ -1,4 +1,4 @@ -import { logTransactionJson } from "./jsonTxBuilder"; +import { logTransactionJson } from "./json_tx_builder"; /// To use this script, fill in the following value: /// - factoryAddress: the address of the factory contract diff --git a/scripts/claim-dust.ts b/scripts/claim_dust.ts similarity index 95% rename from scripts/claim-dust.ts rename to scripts/claim_dust.ts index c5f179d..6b2fb73 100644 --- a/scripts/claim-dust.ts +++ b/scripts/claim_dust.ts @@ -1,7 +1,7 @@ import { CallData } from "starknet"; import { calculateEscrowAddress } from "../lib"; import { Gift, buildGiftCallData, executeActionOnAccount } from "../lib/claim"; -import { logTransactionJson } from "./jsonTxBuilder"; +import { logTransactionJson } from "./json_tx_builder"; /// To use this script, fill in the following value: /// - factoryAddress: the address of the factory contract diff --git a/scripts/jsonTxBuilder.ts b/scripts/json_tx_builder.ts similarity index 100% rename from scripts/jsonTxBuilder.ts rename to scripts/json_tx_builder.ts diff --git a/scripts/pause.ts b/scripts/pause.ts index 371a7e4..c7c1889 100644 --- a/scripts/pause.ts +++ b/scripts/pause.ts @@ -1,4 +1,4 @@ -import { logTransactionJson } from "./jsonTxBuilder"; +import { logTransactionJson } from "./json_tx_builder"; /// To use this script, fill in the following value: /// - factoryAddress: the address of the factory contract diff --git a/scripts/propose-upgrade.ts b/scripts/propose_upgrade.ts similarity index 100% rename from scripts/propose-upgrade.ts rename to scripts/propose_upgrade.ts diff --git a/scripts/unpause.ts b/scripts/unpause.ts index 5fb1fc7..3c64e00 100644 --- a/scripts/unpause.ts +++ b/scripts/unpause.ts @@ -1,4 +1,4 @@ -import { logTransactionJson } from "./jsonTxBuilder"; +import { logTransactionJson } from "./json_tx_builder"; /// To use this script, fill in the following value: /// - factoryAddress: the address of the factory contract diff --git a/scripts/upgrade.ts b/scripts/upgrade.ts index cdbd03b..9168a60 100644 --- a/scripts/upgrade.ts +++ b/scripts/upgrade.ts @@ -1,5 +1,5 @@ import { CallData } from "starknet"; -import { logTransactionJson } from "./jsonTxBuilder"; +import { logTransactionJson } from "./json_tx_builder"; /// To use this script, fill in the following value: /// - factoryAddress: the address of the factory contract From 570b9b9ac226224bb7322f6404d196e2a3eb052a Mon Sep 17 00:00:00 2001 From: Leonard Paturel Date: Mon, 1 Jul 2024 10:51:56 +0100 Subject: [PATCH 8/8] import --- scripts/propose_upgrade.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/propose_upgrade.ts b/scripts/propose_upgrade.ts index bc24f7e..49e64bf 100644 --- a/scripts/propose_upgrade.ts +++ b/scripts/propose_upgrade.ts @@ -1,5 +1,5 @@ import { CallData } from "starknet"; -import { logTransactionJson } from "./jsonTxBuilder"; +import { logTransactionJson } from "./json_tx_builder"; /// To use this script, fill in the following value: /// - factoryAddress: the address of the factory contract