Skip to content

Commit

Permalink
fix: mint working
Browse files Browse the repository at this point in the history
  • Loading branch information
jahabeebs committed Dec 15, 2024
1 parent d89bf31 commit 38eeb0f
Showing 1 changed file with 65 additions and 38 deletions.
103 changes: 65 additions & 38 deletions apps/agent/test/e2e/utils/prophet-e2e-scaffold/eboCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,22 @@ async function fundAccount(
console.log("funded minter with eth");

console.log(`Sending GRT tokens from ${grt.holderAddress} to ${account.address}...`);
console.log(grt.holderAddress, "grt.holderAddress");
console.log(minter, "minter address");

// Add before minting
const isMinter = await anvilClient.readContract({
address: grt.contractAddress,
abi: parseAbi(["function isMinter(address) returns (bool)"]),
functionName: "isMinter",
args: [minter],
});

console.log(`Is minter authorized? ${isMinter}`);

// const balance = await anvilClient.readContract({
// address: grt.contractAddress,
// abi: parseAbi(["function balanceOf(address) returns (uint256)"]),
// functionName: "balanceOf",
// args: [grt.holderAddress],
// });
// console.log(balance, 'grt balance with new contract')
if (!isMinter) {
throw new Error(`Address ${minter} does not have minting permissions`);
}

// simulate minting grt

Expand All @@ -117,7 +125,7 @@ async function fundAccount(

console.log(request, "mint request logged");

//call mint function for minting grt
// After minting
const mintHash = await anvilClient.sendTransaction({
account: minter,
to: grt.contractAddress,
Expand All @@ -127,21 +135,23 @@ async function fundAccount(
}),
});

await anvilClient.waitForTransactionReceipt({ hash: mintHash });

console.log(mintHash, "mintHash");
// Wait for transaction receipt
const mintReceipt = await anvilClient.waitForTransactionReceipt({ hash: mintHash });
console.log("Mint transaction receipt:", mintReceipt);

const balanceHolder = await anvilClient.readContract({
// Check if mint was successful by verifying the holder's balance
const balanceAfterMint = await anvilClient.readContract({
address: grt.contractAddress,
abi: parseAbi(["function balanceOf(address) returns (uint256)"]),
functionName: "balanceOf",
args: [grt.holderAddress],
});
console.log(balanceHolder, "grt balance of holder");
console.log(grt.fundAmount, "grt.fundAmount");

console.log(mintHash, "mintHash");
console.log("mint success");
console.log(`GRT balance after minting: ${balanceAfterMint}`);

if (balanceAfterMint === 0n) {
throw new Error(`Minting failed - no balance for holder ${grt.holderAddress}`);
}

await anvilClient.stopImpersonatingAccount({ address: minter });

Expand Down Expand Up @@ -430,7 +440,17 @@ async function stakeGrtWithProvision(
confirmations: 1,
});

// 2. Stake GRT tokens
// 2. Verify GRT allowance
const allowance = await anvilClient.readContract({
address: grt,
abi: parseAbi(["function allowance(address,address) view returns (uint256)"]),
functionName: "allowance",
args: [account.address, horizonStaking],
});

console.log(`GRT allowance for staking: ${allowance}`);

// 3. Stake GRT tokens
console.log("Staking GRT...");
console.log(grtProvisionAmount, "grtProvisionAmount");
const stakeHash = await anvilClient.sendTransaction({
Expand All @@ -442,13 +462,33 @@ async function stakeGrtWithProvision(
}),
});

await anvilClient.waitForTransactionReceipt({
const stakeReceipt = await anvilClient.waitForTransactionReceipt({
hash: stakeHash,
confirmations: 1,
});

// 3. Provision the stake
console.log("Provisioning stake...");
console.log("Stake transaction receipt:", stakeReceipt);

// 4. Mine a block to update state
await anvilClient.mine({ blocks: 1 });

// 5. Now check staked amount
console.log("Checking staked amount...");
const stakedAmount = await anvilClient.readContract({
address: horizonStaking,
abi: parseAbi(["function stakes(address) view returns (uint256)"]),
functionName: "stakes",
args: [account.address],
});

console.log(`Staked amount: ${stakedAmount}`);

if (stakedAmount < grtProvisionAmount) {
throw new Error(`Failed to stake required amount for ${account.address}`);
}

// 6. Then proceed with provision setup
console.log("Setting up provision...");
const provisionHash = await anvilClient.sendTransaction({
account: account,
to: horizonStaking,
Expand All @@ -460,32 +500,19 @@ async function stakeGrtWithProvision(
account.address,
horizonAccountingExtension,
grtProvisionAmount,
// TODO: use contract call to get this value
// https://github.com/defi-wonderland/EBO-core/blob/175bcd57c3254a90dd6fcbf53b3db3359085551f/src/contracts/HorizonAccountingExtension.sol#L38C26-L38C42
1_000_000,
// https://github.com/defi-wonderland/EBO-core/blob/175bcd57c3254a90dd6fcbf53b3db3359085551f/script/Constants.sol#L21
BigInt(60 * 60 * 24 * 3), // 3 days in seconds
],
}),
});

await anvilClient.waitForTransactionReceipt({
const provisionReceipt = await anvilClient.waitForTransactionReceipt({
hash: provisionHash,
confirmations: 1,
});

// 4. Verify the stake was successful
const stakedBalance = await anvilClient.readContract({
address: horizonStaking,
abi: parseAbi(["function stakes(address) view returns (uint256)"]),
functionName: "stakes",
args: [account.address],
});

console.log(`Staked balance for ${account.address}: ${stakedBalance}`);

if (stakedBalance < grtProvisionAmount) {
throw new Error(`Failed to stake required amount for ${account.address}`);
}

console.log(`Stake and provision completed for ${account.address}`);
console.log("Provision transaction receipt:", provisionReceipt);
}
}

Expand Down

0 comments on commit 38eeb0f

Please sign in to comment.