diff --git a/.gitignore b/.gitignore index 182de8ca..8261c8d3 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ artifacts #Generated files RolloverBatch.json +RedeemBatch.json \ No newline at end of file diff --git a/spot-contracts/tasks/mainnet.sh b/spot-contracts/tasks/mainnet.sh index 3f513df2..48ba6ad3 100644 --- a/spot-contracts/tasks/mainnet.sh +++ b/spot-contracts/tasks/mainnet.sh @@ -69,6 +69,10 @@ yarn hardhat --network mainnet ops:redeemTranches \ yarn hardhat --network mainnet ops:redeemTranches \ --bond-issuer-address 0x2E2E49eDCd5ce08677Bab6d791C863f1361B52F2 +yarn hardhat --network mainnet ops:preview_tx:redeemTranches \ + --wallet-address [INSERT_WALLET_ADDRESS] \ + --bond-issuer-address 0x2E2E49eDCd5ce08677Bab6d791C863f1361B52F2 + yarn hardhat --network mainnet ops:preview_tx:trancheAndRollover \ --wallet-address [INSERT_WALLET_ADDRESS] \ --router-address 0x38f600e08540178719BF656e6B43FC15A529c393 \ diff --git a/spot-contracts/tasks/ops/perp_rollover.ts b/spot-contracts/tasks/ops/perp_rollover.ts index ba68f85c..d799caf1 100644 --- a/spot-contracts/tasks/ops/perp_rollover.ts +++ b/spot-contracts/tasks/ops/perp_rollover.ts @@ -396,3 +396,54 @@ task("ops:preview_tx:trancheAndRollover") console.log("Wrote tx batch to file:", "RolloverBatch.json"); fs.writeFileSync("RolloverBatch.json", JSON.stringify(await generateGnosisSafeBatchFile(hre, [tx1, tx2]), null, 2)); }); + +task("ops:preview_tx:redeemTranches") + .addParam("walletAddress", "the address of the wallet with the collateral token", undefined, types.string, false) + .addParam("bondIssuerAddress", "the address of the bond issuer", undefined, types.string, false) + .addParam("depth", "the number of bonds to check", 5, types.int) + .setAction(async function (args: TaskArguments, hre) { + const { walletAddress, bondIssuerAddress, depth } = args; + const txs: ProposedTransaction[] = []; + const bondIssuer = await hre.ethers.getContractAt("BondIssuer", bondIssuerAddress); + + const issuedCount = await bondIssuer.callStatic.issuedCount(); + for (let i = issuedCount - 1; i > 0 && issuedCount - 1 - i < depth; i--) { + const bondAddress = await bondIssuer.callStatic.issuedBondAt(i); + const bond = await hre.ethers.getContractAt("IBondController", bondAddress); + + const td = await getTrancheData(hre, bond); + const isMature = await bond.isMature(); + + if (isMature) { + for (let j = 0; j < td.length; j++) { + const b = await td[j][0].balanceOf(walletAddress); + if (b.gt(0)) { + txs.push({ + contract: bond, + method: "redeemMature", + args: [td[j][0].address, b.toString()], + }); + } + } + } else { + const redemptionAmounts = await computeRedeemableTrancheAmounts(td, walletAddress); + if (redemptionAmounts[0].gt("0")) { + txs.push({ + contract: bond, + method: "redeem", + args: [JSON.stringify(redemptionAmounts.map(a => a.toString()))], + }); + } + } + } + + console.log("---------------------------------------------------------------"); + console.log("Execute the following transactions"); + + for (let i = 0; i < txs.length; i++) { + console.log({ to: txs[i].contract.address, method: txs[i].method, args: txs[i].args }); + } + + console.log("Wrote tx batch to file:", "RedeemBatch.json"); + fs.writeFileSync("RedeemBatch.json", JSON.stringify(await generateGnosisSafeBatchFile(hre, txs), null, 2)); + });