Skip to content

Commit a5f82e6

Browse files
authored
Testnet deployment v5.0 (#256)
* upgraded bill broker testnet * updated spot and stampl on testnet
1 parent 5b29e35 commit a5f82e6

File tree

18 files changed

+2082
-111
lines changed

18 files changed

+2082
-111
lines changed

spot-contracts/.openzeppelin/sepolia.json

Lines changed: 1238 additions & 0 deletions
Large diffs are not rendered by default.

spot-contracts/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ There is a testnet deployment on Sepolia.
3232
- Bond issuer: [0x3838C8d4D092d40Cb27DD22Dafc6E1A81ea2DB60](https://sepolia.etherscan.io//address/0x3838C8d4D092d40Cb27DD22Dafc6E1A81ea2DB60)
3333
- Router: [0xE5b53ee8182086790C1ab79cbf801F0c5EE241BF](https://sepolia.etherscan.io//address/0xE5b53ee8182086790C1ab79cbf801F0c5EE241BF)
3434
- RolloverVault: [0x107614c6602A8e602952Da107B8fE62b5Ab13b04](https://sepolia.etherscan.io//address/0x107614c6602A8e602952Da107B8fE62b5Ab13b04)
35-
- FeePolicy: [0x2DdF288F26490D1147296cC0FA2B3c4da5E15f10](https://sepolia.etherscan.io//address/0x2DdF288F26490D1147296cC0FA2B3c4da5E15f10)
35+
- FeePolicy: [0xd90FcB328D90B778D1f6719d781045bbbac8F251](https://sepolia.etherscan.io//address/0xd90FcB328D90B778D1f6719d781045bbbac8F251)
3636

3737
## Contribute
3838

spot-contracts/tasks/helpers.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ export async function getContractFactoryFromExternalArtifacts(ethers: any, name:
99
return ethers.getContractFactoryFromArtifact(artifact);
1010
}
1111

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

1614
interface ContractInput {
1715
internalType: string;

spot-contracts/tasks/ops/perp.ts

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ task("ops:perp:info")
2828
console.log("BondIssuer:", bondIssuer.target);
2929
console.log("bondFactory:", await bondIssuer.bondFactory());
3030
console.log("collateral:", await bondIssuer.collateral());
31-
console.log("issuedCount:", hre.ethers.formatUnits(await bondIssuer.issuedCount()), 0);
31+
console.log("issuedCount:", hre.ethers.formatUnits(await bondIssuer.issuedCount(), 0));
3232
console.log("maxMaturityDuration:", hre.ethers.formatUnits(await bondIssuer.maxMaturityDuration(), 0));
3333
console.log("minIssueTimeIntervalSec:", hre.ethers.formatUnits(await bondIssuer.minIssueTimeIntervalSec(), 0));
3434
console.log("issueWindowOffsetSec:", hre.ethers.formatUnits(await bondIssuer.issueWindowOffsetSec(), 0));
@@ -47,13 +47,6 @@ task("ops:perp:info")
4747
console.log("---------------------------------------------------------------");
4848
console.log("feePolicy:", feePolicy.target);
4949
console.log("owner", await feePolicy.owner());
50-
console.log("perpMintFeePerc:", hre.ethers.formatUnits(await feePolicy.perpMintFeePerc(), percDecimals));
51-
console.log("perpBurnFeePerc:", hre.ethers.formatUnits(await feePolicy.perpBurnFeePerc(), percDecimals));
52-
const r = await feePolicy.perpRolloverFee();
53-
console.log("minRolloverFeePerc:", hre.ethers.formatUnits(r.minRolloverFeePerc, percDecimals));
54-
console.log("perpDebasementSlope:", hre.ethers.formatUnits(r.perpDebasementSlope, percDecimals));
55-
console.log("perpEnrichmentSlope:", hre.ethers.formatUnits(r.perpEnrichmentSlope, percDecimals));
56-
5750
console.log("---------------------------------------------------------------");
5851
console.log("PerpetualTranche:", perp.target);
5952
console.log("proxyAdmin:", proxyAdminAddress);
@@ -84,7 +77,7 @@ task("ops:perp:info")
8477
const tokenAddress = await perp.getReserveAt.staticCall(i);
8578
const balance = await perp.getReserveTokenBalance.staticCall(tokenAddress);
8679
const value = await perp.getReserveTokenValue.staticCall(tokenAddress);
87-
const price = balance > 0n ? (value * balance * 1000) / 10n ** perpDecimals / 10n ** percDecimals : 0n;
80+
const price = balance > 0n ? (value * 1000n) / balance : 0n;
8881
data.push({
8982
token: tokenAddress,
9083
balance: hre.ethers.formatUnits(balance, await perp.decimals()),
@@ -213,7 +206,7 @@ task("ops:perp:trancheAndDeposit")
213206
console.log("Preview mint:", collateralAmount);
214207
const totalMintAmt = await perp.computeMintAmt.staticCall(depositTranches[0].token, depositTranches[0].amount);
215208
console.log("mintAmt", hre.ethers.formatUnits(totalMintAmt, await perp.decimals()));
216-
if (totalMintAmt.eq("0")) {
209+
if (totalMintAmt <= 0n) {
217210
throw Error("No perp minted");
218211
}
219212

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

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

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

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

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

275-
console.log("Approving router to spend tokens:");
276-
if ((await perp.allowance(signerAddress, router.target)).lt(fixedPtAmount)) {
277-
const tx1 = await perp.connect(signer).approve(router.target, fixedPtAmount);
278-
await tx1.wait();
279-
console.log("Tx", tx1.hash);
280-
}
281-
282266
console.log("Redeem:");
283-
const tx2 = await perp.connect(signer).redeem(fixedPtAmount);
284-
await tx2.wait();
285-
console.log("Tx", tx2.hash);
267+
const tx = await perp.connect(signer).redeem(fixedPtAmount);
268+
await tx.wait();
269+
console.log("Tx", tx.hash);
286270

287271
console.log("Signer balance", hre.ethers.formatUnits(await perp.balanceOf(signerAddress), await perp.decimals()));
288272
});

spot-contracts/tasks/ops/tranche.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from "fs";
22
import { task, types } from "hardhat/config";
33
import { TaskArguments, HardhatRuntimeEnvironment } from "hardhat/types";
4-
import { constants, Contract, BigNumber, Signer } from "ethers";
4+
import { Contract, BigNumber, Signer, MaxUint256 } from "ethers";
55
import { generateGnosisSafeBatchFile, ProposedTransaction } from "../helpers";
66

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

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

5050
for (let i = 0; i < balances.length; i++) {
51-
redeemableAmts[i] = ratios[i].mul(min).div("1000");
51+
redeemableAmts[i] = (ratios[i] * min) / 1000n;
5252
}
5353
return redeemableAmts;
5454
}
@@ -102,7 +102,7 @@ task("ops:redeemTranches")
102102
if (isMature) {
103103
for (let j = 0; j < bt.length; j++) {
104104
const b = await bt[j][0].balanceOf(signerAddress);
105-
if (b.gt(0)) {
105+
if (b > 0n) {
106106
console.log("Redeeming mature tranche", bt[j][0].target);
107107
const tx = await bond.connect(signer).redeemMature(bt[j][0].target, b);
108108
await tx.wait();
@@ -111,7 +111,7 @@ task("ops:redeemTranches")
111111
}
112112
} else {
113113
const redemptionAmounts = await computeRedeemableTrancheAmounts(bt, signerAddress);
114-
if (redemptionAmounts[0].gt("0")) {
114+
if (redemptionAmounts[0] > 0n) {
115115
console.log(
116116
"Redeeming immature bond",
117117
redemptionAmounts.map(a => a.toString()),
@@ -144,7 +144,7 @@ task("ops:preview_tx:redeemTranches")
144144
if (isMature) {
145145
for (let j = 0; j < bt.length; j++) {
146146
const b = await bt[j][0].balanceOf(walletAddress);
147-
if (b.gt(0)) {
147+
if (b > 0n) {
148148
txs.push({
149149
contract: bond,
150150
method: "redeemMature",
@@ -154,7 +154,7 @@ task("ops:preview_tx:redeemTranches")
154154
}
155155
} else {
156156
const redemptionAmounts = await computeRedeemableTrancheAmounts(bt, walletAddress);
157-
if (redemptionAmounts[0].gt("0")) {
157+
if (redemptionAmounts[0] > 0n) {
158158
txs.push({
159159
contract: bond,
160160
method: "redeem",

0 commit comments

Comments
 (0)