Skip to content

Commit

Permalink
steal to fix token allocation mistakes
Browse files Browse the repository at this point in the history
  • Loading branch information
wighawag committed Apr 2, 2024
1 parent af51850 commit c2219b8
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
3 changes: 2 additions & 1 deletion contracts/scripts/poke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
60 changes: 60 additions & 0 deletions contracts/scripts/steal.ts
Original file line number Diff line number Diff line change
@@ -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<typeof context.artifacts.TestTokens.abi>('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();

0 comments on commit c2219b8

Please sign in to comment.