Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,238 changes: 1,238 additions & 0 deletions spot-contracts/.openzeppelin/sepolia.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion spot-contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ There is a testnet deployment on Sepolia.
- Bond issuer: [0x3838C8d4D092d40Cb27DD22Dafc6E1A81ea2DB60](https://sepolia.etherscan.io//address/0x3838C8d4D092d40Cb27DD22Dafc6E1A81ea2DB60)
- Router: [0xE5b53ee8182086790C1ab79cbf801F0c5EE241BF](https://sepolia.etherscan.io//address/0xE5b53ee8182086790C1ab79cbf801F0c5EE241BF)
- RolloverVault: [0x107614c6602A8e602952Da107B8fE62b5Ab13b04](https://sepolia.etherscan.io//address/0x107614c6602A8e602952Da107B8fE62b5Ab13b04)
- FeePolicy: [0x2DdF288F26490D1147296cC0FA2B3c4da5E15f10](https://sepolia.etherscan.io//address/0x2DdF288F26490D1147296cC0FA2B3c4da5E15f10)
- FeePolicy: [0xd90FcB328D90B778D1f6719d781045bbbac8F251](https://sepolia.etherscan.io//address/0xd90FcB328D90B778D1f6719d781045bbbac8F251)

## Contribute

Expand Down
4 changes: 1 addition & 3 deletions spot-contracts/tasks/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ export async function getContractFactoryFromExternalArtifacts(ethers: any, name:
return ethers.getContractFactoryFromArtifact(artifact);
}

export async function sleep(sleepSec: number) {
await new Promise(resolve => setTimeout(resolve, sleepSec));
}
export const sleep = seconds => new Promise(resolve => setTimeout(resolve, seconds * 1000));

interface ContractInput {
internalType: string;
Expand Down
32 changes: 8 additions & 24 deletions spot-contracts/tasks/ops/perp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ task("ops:perp:info")
console.log("BondIssuer:", bondIssuer.target);
console.log("bondFactory:", await bondIssuer.bondFactory());
console.log("collateral:", await bondIssuer.collateral());
console.log("issuedCount:", hre.ethers.formatUnits(await bondIssuer.issuedCount()), 0);
console.log("issuedCount:", hre.ethers.formatUnits(await bondIssuer.issuedCount(), 0));
console.log("maxMaturityDuration:", hre.ethers.formatUnits(await bondIssuer.maxMaturityDuration(), 0));
console.log("minIssueTimeIntervalSec:", hre.ethers.formatUnits(await bondIssuer.minIssueTimeIntervalSec(), 0));
console.log("issueWindowOffsetSec:", hre.ethers.formatUnits(await bondIssuer.issueWindowOffsetSec(), 0));
Expand All @@ -47,13 +47,6 @@ task("ops:perp:info")
console.log("---------------------------------------------------------------");
console.log("feePolicy:", feePolicy.target);
console.log("owner", await feePolicy.owner());
console.log("perpMintFeePerc:", hre.ethers.formatUnits(await feePolicy.perpMintFeePerc(), percDecimals));
console.log("perpBurnFeePerc:", hre.ethers.formatUnits(await feePolicy.perpBurnFeePerc(), percDecimals));
const r = await feePolicy.perpRolloverFee();
console.log("minRolloverFeePerc:", hre.ethers.formatUnits(r.minRolloverFeePerc, percDecimals));
console.log("perpDebasementSlope:", hre.ethers.formatUnits(r.perpDebasementSlope, percDecimals));
console.log("perpEnrichmentSlope:", hre.ethers.formatUnits(r.perpEnrichmentSlope, percDecimals));

console.log("---------------------------------------------------------------");
console.log("PerpetualTranche:", perp.target);
console.log("proxyAdmin:", proxyAdminAddress);
Expand Down Expand Up @@ -84,7 +77,7 @@ task("ops:perp:info")
const tokenAddress = await perp.getReserveAt.staticCall(i);
const balance = await perp.getReserveTokenBalance.staticCall(tokenAddress);
const value = await perp.getReserveTokenValue.staticCall(tokenAddress);
const price = balance > 0n ? (value * balance * 1000) / 10n ** perpDecimals / 10n ** percDecimals : 0n;
const price = balance > 0n ? (value * 1000n) / balance : 0n;
data.push({
token: tokenAddress,
balance: hre.ethers.formatUnits(balance, await perp.decimals()),
Expand Down Expand Up @@ -213,7 +206,7 @@ task("ops:perp:trancheAndDeposit")
console.log("Preview mint:", collateralAmount);
const totalMintAmt = await perp.computeMintAmt.staticCall(depositTranches[0].token, depositTranches[0].amount);
console.log("mintAmt", hre.ethers.formatUnits(totalMintAmt, await perp.decimals()));
if (totalMintAmt.eq("0")) {
if (totalMintAmt <= 0n) {
throw Error("No perp minted");
}

Expand All @@ -225,7 +218,7 @@ task("ops:perp:trancheAndDeposit")

console.log("Approving router to spend tokens:");
const allowance = await collateralToken.allowance(signerAddress, router.target);
if (allowance.lt(fixedPtCollateralAmount)) {
if (allowance < fixedPtCollateralAmount) {
const tx1 = await collateralToken.connect(signer).approve(router.target, fixedPtCollateralAmount);
await tx1.wait();
console.log("Tx", tx1.hash);
Expand All @@ -243,13 +236,11 @@ task("ops:perp:trancheAndDeposit")

task("ops:perp:redeem")
.addParam("perpAddress", "the address of the perp contract", undefined, types.string, false)
.addParam("routerAddress", "the address of the router contract", undefined, types.string, false)
.addParam("amount", "the total amount of perp tokens (in float) to redeem", undefined, types.string, false)
.addParam("fromIdx", "the index of sender", 0, types.int)
.setAction(async function (args: TaskArguments, hre) {
const { perpAddress, routerAddress, amount } = args;
const { perpAddress, amount } = args;

const router = await hre.ethers.getContractAt("RouterV2", routerAddress);
const perp = await hre.ethers.getContractAt("PerpetualTranche", perpAddress);
const fixedPtAmount = hre.ethers.parseUnits(amount, await perp.decimals());

Expand All @@ -272,17 +263,10 @@ task("ops:perp:redeem")
const signerAddress = await signer.getAddress();
console.log("Signer", signerAddress);

console.log("Approving router to spend tokens:");
if ((await perp.allowance(signerAddress, router.target)).lt(fixedPtAmount)) {
const tx1 = await perp.connect(signer).approve(router.target, fixedPtAmount);
await tx1.wait();
console.log("Tx", tx1.hash);
}

console.log("Redeem:");
const tx2 = await perp.connect(signer).redeem(fixedPtAmount);
await tx2.wait();
console.log("Tx", tx2.hash);
const tx = await perp.connect(signer).redeem(fixedPtAmount);
await tx.wait();
console.log("Tx", tx.hash);

console.log("Signer balance", hre.ethers.formatUnits(await perp.balanceOf(signerAddress), await perp.decimals()));
});
22 changes: 11 additions & 11 deletions spot-contracts/tasks/ops/tranche.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from "fs";
import { task, types } from "hardhat/config";
import { TaskArguments, HardhatRuntimeEnvironment } from "hardhat/types";
import { constants, Contract, BigNumber, Signer } from "ethers";
import { Contract, BigNumber, Signer, MaxUint256 } from "ethers";
import { generateGnosisSafeBatchFile, ProposedTransaction } from "../helpers";

async function matureBond(bond: Contract, signer: Signer) {
Expand Down Expand Up @@ -38,17 +38,17 @@ function computeProportionalBalances(balances: BigNumber[], ratios: BigNumber[])
}

const redeemableAmts: BigNumber[] = [];
let min = BigNumber.from(constants.MaxUint256);
for (let i = 0; i < balances.length && min.gt("0"); i++) {
const b = balances[i].sub(balances[i].mod(ratios[i]));
const d = b.mul("1000").div(ratios[i]);
if (d.lt(min)) {
let min = MaxUint256;
for (let i = 0; i < balances.length && min > 0n; i++) {
const b = balances[i] - (balances[i] % ratios[i]);
const d = (b * 1000n) / ratios[i];
if (d < min) {
min = d;
}
}

for (let i = 0; i < balances.length; i++) {
redeemableAmts[i] = ratios[i].mul(min).div("1000");
redeemableAmts[i] = (ratios[i] * min) / 1000n;
}
return redeemableAmts;
}
Expand Down Expand Up @@ -102,7 +102,7 @@ task("ops:redeemTranches")
if (isMature) {
for (let j = 0; j < bt.length; j++) {
const b = await bt[j][0].balanceOf(signerAddress);
if (b.gt(0)) {
if (b > 0n) {
console.log("Redeeming mature tranche", bt[j][0].target);
const tx = await bond.connect(signer).redeemMature(bt[j][0].target, b);
await tx.wait();
Expand All @@ -111,7 +111,7 @@ task("ops:redeemTranches")
}
} else {
const redemptionAmounts = await computeRedeemableTrancheAmounts(bt, signerAddress);
if (redemptionAmounts[0].gt("0")) {
if (redemptionAmounts[0] > 0n) {
console.log(
"Redeeming immature bond",
redemptionAmounts.map(a => a.toString()),
Expand Down Expand Up @@ -144,7 +144,7 @@ task("ops:preview_tx:redeemTranches")
if (isMature) {
for (let j = 0; j < bt.length; j++) {
const b = await bt[j][0].balanceOf(walletAddress);
if (b.gt(0)) {
if (b > 0n) {
txs.push({
contract: bond,
method: "redeemMature",
Expand All @@ -154,7 +154,7 @@ task("ops:preview_tx:redeemTranches")
}
} else {
const redemptionAmounts = await computeRedeemableTrancheAmounts(bt, walletAddress);
if (redemptionAmounts[0].gt("0")) {
if (redemptionAmounts[0] > 0n) {
txs.push({
contract: bond,
method: "redeem",
Expand Down
Loading