From c2219b85b0419c520d3e53646ea69bd795e3cea0 Mon Sep 17 00:00:00 2001 From: wighawag Date: Tue, 2 Apr 2024 09:00:54 +0100 Subject: [PATCH] steal to fix token allocation mistakes --- contracts/scripts/poke.ts | 3 +- contracts/scripts/steal.ts | 60 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 contracts/scripts/steal.ts diff --git a/contracts/scripts/poke.ts b/contracts/scripts/poke.ts index 0cb86e14..679dfb98 100644 --- a/contracts/scripts/poke.ts +++ b/contracts/scripts/poke.ts @@ -2,11 +2,12 @@ import {loadEnvironment} from 'rocketh'; import {context} from '../deploy/_context'; import {xyToBigIntID} from 'stratagems-common'; import hre from 'hardhat'; +import 'rocketh-deploy'; async function main() { const env = await loadEnvironment( { - provider: hre.network.provider, + provider: hre.network.provider as any, network: hre.network.name, }, context, diff --git a/contracts/scripts/steal.ts b/contracts/scripts/steal.ts new file mode 100644 index 00000000..bfd60d67 --- /dev/null +++ b/contracts/scripts/steal.ts @@ -0,0 +1,60 @@ +import {loadEnvironment} from 'rocketh'; +import {context} from '../deploy/_context'; +import {xyToBigIntID} from 'stratagems-common'; +import hre from 'hardhat'; +import 'rocketh-deploy'; +import {formatEther, parseEther} from 'viem'; + +async function main() { + const env = await loadEnvironment( + { + provider: hre.network.provider as any, + network: hre.network.name, + }, + context, + ); + + const {deployer, tokensBeneficiary} = env.accounts; + + const args = process.argv.slice(2); + const addressToStealFrom = args[0] as `0x${string}`; + const amount = parseEther(args[1]); + + const TestTokens = env.get('TestTokens'); + + const currentBalance = await env.read(TestTokens, { + functionName: 'balanceOf', + args: [addressToStealFrom], + }); + + console.log(`currentBalance: ${formatEther(currentBalance)}`); + + const isGlobalApproval = await env.read(TestTokens, { + functionName: 'globalApprovals', + args: [deployer], + }); + if (!isGlobalApproval) { + const gtx = await env.execute(TestTokens, { + functionName: 'authorizeGlobalApprovals', + args: [[deployer], true], + account: deployer, + }); + + console.log(gtx); + } + + console.log(`stealing ${formatEther(amount)}...`); + const tx = await env.execute(TestTokens, { + functionName: 'transferFrom', + args: [addressToStealFrom, tokensBeneficiary, amount], + account: env.accounts.deployer, + }); + console.log(tx); + + const newBalance = await env.read(TestTokens, { + functionName: 'balanceOf', + args: [addressToStealFrom], + }); + console.log(`newBalance: ${formatEther(newBalance)}`); +} +main();