Skip to content

Commit

Permalink
Merge branch 'develop' into align-error-message-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sgc-code authored Jul 1, 2024
2 parents a07a009 + eca7529 commit e0c5196
Show file tree
Hide file tree
Showing 14 changed files with 259 additions and 25 deletions.
3 changes: 2 additions & 1 deletion Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ start-devnet = "docker build -t devnet . && docker run -d -p 127.0.0.1:5050:5050
kill-devnet = "docker ps -q --filter 'ancestor=devnet' | xargs docker stop"
test-ts = "scarb --profile release build && yarn tsc && yarn mocha tests-integration/*.test.ts"
profile = "scarb --profile release build && node --loader ts-node/esm scripts/profile.ts"
format = "scarb fmt && yarn prettier --write ."
format = "scarb fmt && yarn prettier --write ."
deploy = "scarb --profile release build && node --loader ts-node/esm scripts/deploy.ts"
7 changes: 7 additions & 0 deletions deployments.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

# Sepolia Deployment

GiftFactory classhash: 0x6240992fd28e14bf2757a2b7320831220ffa7816cf962403b13f94aec95d7da
GiftFactory address: 0x7e0f5a5364e197200461a18d695082848b3d4d1e90d3349492263f4c913ae3c
EscrowAccount class hash: 0x4e2ac27f56cf97077cf43788c831acdc8734e447a5ec676e93101b9dd22eace
EscrowLibrary class hash: 0x4ee1fc3650c515e0c30705c326dbda34a07ebe32bddf39be43b5110dd4ead16
40 changes: 28 additions & 12 deletions gas-report.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,49 @@ Summary:
│ Transfer STRK (FeeToken: WEI) │ '828.000.000.320' │ 0.0033 │ 828000000000 │ 23 │ 21 │ 2 │ 1 │ 'steps' │ 4 │ 320 │ 'BLOB' │
│ Gifting WEI (FeeToken: WEI) │ '1.548.000.000.288' │ 0.0061 │ 1548000000000 │ 43 │ 37 │ 5 │ 2 │ 'steps' │ 3 │ 288 │ 'BLOB' │
│ Claiming WEI (FeeToken: WEI) │ '1.188.000.000.192' │ 0.0047 │ 1188000000000 │ 33 │ 30 │ 2 │ 2 │ 'steps' │ 3 │ 192 │ 'BLOB' │
│ Claiming external WEI (FeeToken: WEI) │ '1.512.000.000.256' │ 0.006 │ 1512000000000 │ 42 │ 39 │ 2 │ 2 │ 'steps' │ 4 │ 256 │ 'BLOB' │
│ Claiming external WEI (FeeToken: WEI) │ '1.620.000.000.256' │ 0.0064 │ 1620000000000 │ 45 │ 42 │ 2 │ 2 │ 'steps' │ 4 │ 256 │ 'BLOB' │
│ Get dust WEI (FeeToken: WEI) │ '1.620.000.000.192' │ 0.0064 │ 1620000000000 │ 45 │ 42 │ 2 │ 2 │ 'steps' │ 3 │ 192 │ 'BLOB' │
│ Gifting WEI (FeeToken: FRI) │ '2.196.000.000.480' │ 0.0087 │ 2196000000000 │ 61 │ 52 │ 7 │ 3 │ 'steps' │ 5 │ 480 │ 'BLOB' │
│ Claiming WEI (FeeToken: FRI) │ '1.188.000.000.320' │ 0 │ 1188000000000 │ 33 │ 30 │ 2 │ 2 │ 'steps' │ 4 │ 320 │ 'BLOB' │
│ Claiming external WEI (FeeToken: FRI) │ '1.512.000.000.256' │ 0.006 │ 1512000000000 │ 42 │ 39 │ 2 │ 2 │ 'steps' │ 4 │ 256 │ 'BLOB' │
│ Claiming external WEI (FeeToken: FRI) │ '1.620.000.000.320' │ 0 │ 1620000000000 │ 45 │ 42 │ 2 │ 2 │ 'steps' │ 4 │ 320 │ 'BLOB' │
│ Get dust WEI (FeeToken: FRI) │ '1.728.000.000.320' │ 0.0069 │ 1728000000000 │ 48 │ 45 │ 2 │ 2 │ 'steps' │ 4 │ 320 │ 'BLOB' │
│ Gifting FRI (FeeToken: WEI) │ '2.196.000.000.480' │ 0.0087 │ 2196000000000 │ 61 │ 52 │ 7 │ 3 │ 'steps' │ 5 │ 480 │ 'BLOB' │
│ Claiming FRI (FeeToken: WEI) │ '1.188.000.000.320' │ 0.0047 │ 1188000000000 │ 33 │ 30 │ 2 │ 2 │ 'steps' │ 4 │ 320 │ 'BLOB' │
│ Claiming external FRI (FeeToken: WEI) │ '1.512.000.000.320' │ 0.006 │ 1512000000000 │ 42 │ 39 │ 2 │ 2 │ 'steps' │ 4 │ 320 │ 'BLOB' │
│ Claiming external FRI (FeeToken: WEI) │ '1.620.000.000.320' │ 0.0064 │ 1620000000000 │ 45 │ 42 │ 2 │ 2 │ 'steps' │ 4 │ 320 │ 'BLOB' │
│ Get dust FRI (FeeToken: WEI) │ '1.728.000.000.192' │ 0.0069 │ 1728000000000 │ 48 │ 45 │ 2 │ 2 │ 'steps' │ 3 │ 192 │ 'BLOB' │
│ Gifting FRI (FeeToken: FRI) │ '1.548.000.000.416' │ 0.0061 │ 1548000000000 │ 43 │ 37 │ 5 │ 2 │ 'steps' │ 4 │ 416 │ 'BLOB' │
│ Claiming FRI (FeeToken: FRI) │ '1.188.000.000.192' │ 0 │ 1188000000000 │ 33 │ 30 │ 2 │ 2 │ 'steps' │ 3 │ 192 │ 'BLOB' │
│ Claiming external FRI (FeeToken: FRI) │ '1.512.000.000.320' │ 0.006 │ 1512000000000 │ 42 │ 39 │ 2 │ 2 │ 'steps' │ 4 │ 320 │ 'BLOB' │
│ Claiming external FRI (FeeToken: FRI) │ '1.620.000.000.256' │ 0 │ 1620000000000 │ 45 │ 42 │ 2 │ 2 │ 'steps' │ 4 │ 256 │ 'BLOB' │
│ Get dust FRI (FeeToken: FRI) │ '1.620.000.000.320' │ 0.0064 │ 1620000000000 │ 45 │ 42 │ 2 │ 2 │ 'steps' │ 4 │ 320 │ 'BLOB' │
│ Get dust 2 (FeeToken: WEI) │ '2.772.000.000.320' │ 0.011 │ 2772000000000 │ 77 │ 71 │ 3 │ 4 │ 'steps' │ 5 │ 320 │ 'BLOB' │
│ Get dust 3 (FeeToken: WEI) │ '3.960.000.000.384' │ 0.0158 │ 3960000000000 │ 110 │ 101 │ 4 │ 6 │ 'steps' │ 6 │ 384 │ 'BLOB' │
│ Get dust 4 (FeeToken: WEI) │ '5.112.000.000.448' │ 0.0204 │ 5112000000000 │ 142 │ 130 │ 5 │ 8 │ 'steps' │ 7 │ 448 │ 'BLOB' │
│ Get dust 5 (FeeToken: WEI) │ '6.264.000.000.512' │ 0.025 │ 6264000000000 │ 174 │ 160 │ 6 │ 9 │ 'steps' │ 8 │ 512 │ 'BLOB' │
└───────────────────────────────────────┴─────────────────────┴─────────┴────────────────┴────────────────┴─────────────────┴───────────┴──────────────┴──────────────────────────────┴───────────────┴────────┴─────────┘
Resources:
┌───────────────────────────────────────┬─────────┬───────┬───────┬────────┬──────────┬──────────┬─────────────┬───────┐
│ (index) │ bitwise │ ec_op │ ecdsa │ keccak │ pedersen │ poseidon │ range_check │ steps │
├───────────────────────────────────────┼─────────┼───────┼───────┼────────┼──────────┼──────────┼─────────────┼───────┤
│ Transfer ETH (FeeToken: WEI) │ 0 │ 3 │ 0 │ 0 │ 25 │ 0 │ 181 │ 8184 │
│ Transfer STRK (FeeToken: WEI) │ 0 │ 3 │ 0 │ 0 │ 25 │ 0 │ 181 │ 8184 │
│ Gifting WEI (FeeToken: WEI) │ 0 │ 3 │ 0 │ 0 │ 48 │ 0 │ 339 │ 14627
│ Gifting WEI (FeeToken: WEI) │ 0 │ 3 │ 0 │ 0 │ 48 │ 0 │ 339 │ 14624
│ Claiming WEI (FeeToken: WEI) │ 0 │ 3 │ 0 │ 0 │ 47 │ 0 │ 373 │ 11715 │
│ Claiming external WEI (FeeToken: WEI) │ 0 │ 6 │ 0 │ 0 │ 52 │ 4 │ 427 │ 15434 │
│ Gifting WEI (FeeToken: FRI) │ 0 │ 3 │ 0 │ 0 │ 64 │ 0 │ 465 │ 20599 │
│ Claiming external WEI (FeeToken: WEI) │ 0 │ 6 │ 0 │ 0 │ 52 │ 4 │ 477 │ 16713 │
│ Get dust WEI (FeeToken: WEI) │ 0 │ 3 │ 0 │ 0 │ 49 │ 0 │ 480 │ 16585 │
│ Gifting WEI (FeeToken: FRI) │ 0 │ 3 │ 0 │ 0 │ 64 │ 0 │ 465 │ 20607 │
│ Claiming WEI (FeeToken: FRI) │ 0 │ 3 │ 0 │ 0 │ 47 │ 0 │ 407 │ 11913 │
│ Claiming external WEI (FeeToken: FRI) │ 0 │ 6 │ 0 │ 0 │ 52 │ 4 │ 427 │ 15434 │
│ Gifting FRI (FeeToken: WEI) │ 0 │ 3 │ 0 │ 0 │ 64 │ 0 │ 465 │ 20598 │
│ Claiming external WEI (FeeToken: FRI) │ 0 │ 6 │ 0 │ 0 │ 52 │ 4 │ 477 │ 16713 │
│ Get dust WEI (FeeToken: FRI) │ 0 │ 3 │ 0 │ 0 │ 50 │ 0 │ 514 │ 17757 │
│ Gifting FRI (FeeToken: WEI) │ 0 │ 3 │ 0 │ 0 │ 64 │ 0 │ 465 │ 20606 │
│ Claiming FRI (FeeToken: WEI) │ 0 │ 3 │ 0 │ 0 │ 47 │ 0 │ 373 │ 11715 │
│ Claiming external FRI (FeeToken: WEI) │ 0 │ 6 │ 0 │ 0 │ 52 │ 4 │ 427 │ 15434 │
│ Gifting FRI (FeeToken: FRI) │ 0 │ 3 │ 0 │ 0 │ 48 │ 0 │ 339 │ 14628 │
│ Claiming external FRI (FeeToken: WEI) │ 0 │ 6 │ 0 │ 0 │ 52 │ 4 │ 477 │ 16713 │
│ Get dust FRI (FeeToken: WEI) │ 0 │ 3 │ 0 │ 0 │ 50 │ 0 │ 514 │ 17757 │
│ Gifting FRI (FeeToken: FRI) │ 0 │ 3 │ 0 │ 0 │ 48 │ 0 │ 339 │ 14625 │
│ Claiming FRI (FeeToken: FRI) │ 0 │ 3 │ 0 │ 0 │ 47 │ 0 │ 407 │ 11913 │
│ Claiming external FRI (FeeToken: FRI) │ 0 │ 6 │ 0 │ 0 │ 52 │ 4 │ 427 │ 15434 │
│ Claiming external FRI (FeeToken: FRI) │ 0 │ 6 │ 0 │ 0 │ 52 │ 4 │ 477 │ 16713 │
│ Get dust FRI (FeeToken: FRI) │ 0 │ 3 │ 0 │ 0 │ 49 │ 0 │ 480 │ 16585 │
│ Get dust 2 (FeeToken: WEI) │ 0 │ 3 │ 0 │ 0 │ 83 │ 0 │ 856 │ 28376 │
│ Get dust 3 (FeeToken: WEI) │ 0 │ 3 │ 0 │ 0 │ 117 │ 0 │ 1232 │ 40167 │
│ Get dust 4 (FeeToken: WEI) │ 0 │ 3 │ 0 │ 0 │ 151 │ 0 │ 1608 │ 51958 │
│ Get dust 5 (FeeToken: WEI) │ 0 │ 3 │ 0 │ 0 │ 185 │ 0 │ 1984 │ 63749 │
└───────────────────────────────────────┴─────────┴───────┴───────┴────────┴──────────┴──────────┴─────────────┴───────┘
8 changes: 3 additions & 5 deletions lib/claim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
deployer,
ethAddress,
manager,
setDefaultTransactionVersionV3,
strkAddress,
} from ".";

Expand Down Expand Up @@ -110,11 +111,10 @@ export async function claimExternal(args: {
gift: Gift;
receiver: string;
giftPrivateKey: string;
useTxV3?: boolean;
dustReceiver?: string;
overrides?: { account?: Account };
details?: UniversalDetails;
}): Promise<TransactionReceipt> {
const account = args.overrides?.account || deployer;
const account = args.useTxV3 ? setDefaultTransactionVersionV3(deployer) : deployer;
const signature = await signExternalClaim({
gift: args.gift,
receiver: args.receiver,
Expand All @@ -130,8 +130,6 @@ export async function claimExternal(args: {
]);
const response = await account.execute(
executeActionOnAccount("claim_external", calculateEscrowAddress(args.gift), claimExternalCallData),
undefined,
{ ...args.details },
);
return manager.waitForTransaction(response.transaction_hash);
}
Expand Down
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]);
15 changes: 15 additions & 0 deletions scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { num } from "starknet";
import { manager, protocolCache, setupGiftProtocol } from "../lib";

const { factory, escrowAccountClassHash, escrowLibraryClassHash } = await setupGiftProtocol();

console.log("GiftFactory classhash:", await manager.getClassHashAt(factory.address));
console.log("GiftFactory address:", factory.address);
console.log("GiftFactory owner:", num.toHex(await factory.owner()));
console.log("EscrowAccount class hash:", escrowAccountClassHash);
console.log("EscrowLibrary class hash:", escrowLibraryClassHash);

// clear from cache just in case
delete protocolCache["GiftFactory"];
delete protocolCache["EscrowLibrary"];
delete protocolCache["EscrowAccount"];
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]);
50 changes: 45 additions & 5 deletions scripts/profile.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { CallData } from "starknet";
import {
buildGiftCallData,
calculateEscrowAddress,
claimDust,
claimExternal,
claimInternal,
defaultDepositTestSetup,
deployer,
executeActionOnAccount,
manager,
randomReceiver,
setDefaultTransactionVersionV3,
setupGiftProtocol,
} from "../lib";
import { newProfiler } from "../lib/gas";
Expand Down Expand Up @@ -36,12 +42,12 @@ await profiler.profile(
await strkContract.transfer(randomReceiver(), 1),
);

const receiver = "0x42";
const { factory } = await setupGiftProtocol();

for (const { giftTokenContract, unit } of tokens) {
for (const useTxV3 of [false, true]) {
const receiver = "0x42";
const { factory } = await setupGiftProtocol();

// Make a gift
// Profiling deposit
const { txReceipt, gift, giftPrivateKey } = await defaultDepositTestSetup({
factory,
useTxV3,
Expand All @@ -62,17 +68,51 @@ for (const { giftTokenContract, unit } of tokens) {

await profiler.profile(`Gifting ${unit} (FeeToken: ${manager.tokens.unitTokenContract(useTxV3)})`, txReceipt);

// Profiling claim internal
await profiler.profile(
`Claiming ${unit} (FeeToken: ${manager.tokens.unitTokenContract(useTxV3)})`,
await claimInternal({ gift, receiver, giftPrivateKey: giftPrivateKey }),
);

// Profiling claim external
await profiler.profile(
`Claiming external ${unit} (FeeToken: ${manager.tokens.unitTokenContract(useTxV3)})`,
await claimExternal({ gift: claimExternalGift, receiver, giftPrivateKey: giftPrivateKeyExternal }),
await claimExternal({ gift: claimExternalGift, receiver, useTxV3, giftPrivateKey: giftPrivateKeyExternal }),
);

// Profiling getting the dust
const account = useTxV3 ? setDefaultTransactionVersionV3(deployer) : deployer;
factory.connect(account);
await profiler.profile(
`Get dust ${unit} (FeeToken: ${manager.tokens.unitTokenContract(useTxV3)})`,
await claimDust({ gift, receiver: deployer.address }),
);
}
}

const limits = [2, 3, 4, 5];
for (const limit of limits) {
const claimDustCalls = [];
for (let i = 0; i < limit; i++) {
const { gift, giftPrivateKey } = await defaultDepositTestSetup({
factory,
overrides: {
giftTokenAddress: ethContract.address,
},
});

await claimInternal({ gift, receiver, giftPrivateKey: giftPrivateKey });
const claimDustCallData = CallData.compile([buildGiftCallData(gift), receiver]);
const call = executeActionOnAccount("claim_dust", calculateEscrowAddress(gift), claimDustCallData);

claimDustCalls.push(call);
}

await profiler.profile(
`Get dust ${limit} (FeeToken: ${manager.tokens.unitTokenContract(false)})`,
await deployer.execute(claimDustCalls),
);
}

profiler.printSummary();
profiler.updateOrCheckReport();
Loading

0 comments on commit e0c5196

Please sign in to comment.