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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ typechain
#Hardhat files
cache
artifacts

#Generated files
RolloverBatch.json
4 changes: 0 additions & 4 deletions spot-contracts/tasks/ganache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ yarn hardhat --network ganache ops:trancheAndRollover \
--perp-address 0x89967625335C35c5FE1F3C1c03D37fdEb6f415Ed \
--collateral-amount 200

yarn hardhat --network ganache ops:trancheAndRolloverMax \
--router-address 0x4a57d51af3a8a90905a5F756E0B28cC2888A1bD5 \
--perp-address 0x89967625335C35c5FE1F3C1c03D37fdEb6f415Ed

yarn hardhat --network ganache ops:increaseTimeBy 300
yarn hardhat --network ganache ops:updateState 0x89967625335C35c5FE1F3C1c03D37fdEb6f415Ed

Expand Down
9 changes: 8 additions & 1 deletion spot-contracts/tasks/goeril.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ yarn hardhat --network goerli deploy:Router
## OPS
yarn hardhat --network goerli ops:info 0x95014Bc18F82a98CFAA3253fbD3184125A01f848

yarn hardhat --network goerli ops:updateState 0x95014Bc18F82a98CFAA3253fbD3184125A01f848

yarn hardhat --network goerli ops:trancheAndDeposit \
--router-address 0x5e902bdCC408550b4BD612678bE2d57677664Dc9 \
--perp-address 0x95014Bc18F82a98CFAA3253fbD3184125A01f848 \
Expand All @@ -47,6 +49,11 @@ yarn hardhat --network goerli ops:redeemTranches \
yarn hardhat --network goerli ops:redeemTranches \
--bond-issuer-address 0xAb7d17864463dEdA6c19060Ad6556e1B218c5Ba0

yarn hardhat --network goerli ops:preview_tx:trancheAndRollover \
--wallet-address [INSERT_WALLET_ADDRESS] \
--router-address 0x5e902bdCC408550b4BD612678bE2d57677664Dc9 \
--perp-address 0x95014Bc18F82a98CFAA3253fbD3184125A01f848

yarn hardhat --network goerli ops:trancheAndRollover \
--router-address 0x5e902bdCC408550b4BD612678bE2d57677664Dc9 \
--perp-address 0x95014Bc18F82a98CFAA3253fbD3184125A01f848 \
Expand All @@ -60,4 +67,4 @@ yarn hardhat --network goerli ops:rebase:MockAMPL \
########################################################################
## upgrade

yarn hardhat --network goerli upgrade:perp:testnet 0x95014Bc18F82a98CFAA3253fbD3184125A01f848
yarn hardhat --network goerli upgrade:perp:testnet 0x95014Bc18F82a98CFAA3253fbD3184125A01f848
78 changes: 77 additions & 1 deletion spot-contracts/tasks/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as fs from "fs";
import * as path from "path";
import { ContractFactory } from "ethers";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { ContractFactory, Contract, utils } from "ethers";

const EXTERNAL_ARTIFACTS_PATH = path.join(__dirname, "/../external-artifacts");
export async function getContractFactoryFromExternalArtifacts(ethers: any, name: string): Promise<ContractFactory> {
Expand All @@ -11,3 +12,78 @@ export async function getContractFactoryFromExternalArtifacts(ethers: any, name:
export async function sleep(sleepSec: number) {
await new Promise(resolve => setTimeout(resolve, sleepSec));
}

interface ContractInput {
internalType: string;
name: string;
type: string;
components?: ContractInput[];
}

interface ContractMethod {
inputs: ContractInput[];
name: string;
payable: boolean;
}

interface BatchFileMeta {
txBuilderVersion?: string;
name: string;
description?: string;
}

interface BatchTransaction {
to: string;
value: string;
data?: string;
contractMethod?: ContractMethod;
contractInputsValues?: { [key: string]: string };
}

interface BatchFile {
version: string;
chainId: string;
createdAt: number;
meta: BatchFileMeta;
transactions: BatchTransaction[];
}

export interface ProposedTransaction {
contract: Contract;
method: string;
args: any[];
}

function encodeContractTx(p: ProposedTransaction): BatchTransaction {
const methodFragment = JSON.parse(p.contract.interface.getFunction(p.method).format(utils.FormatTypes.json));
return {
to: p.contract.address,
value: "0",
data: "",
contractMethod: methodFragment,
contractInputsValues: methodFragment.inputs
.map((m: ContractInput) => m.name)
.reduce((m: { [key: string]: string }, e: string, i: number) => {
m[e] = p.args[i];
return m;
}, {}),
};
}

export async function generateGnosisSafeBatchFile(
hre: HardhatRuntimeEnvironment,
transactions: ProposedTransaction[],
): Promise<BatchFile> {
const chainId = (await hre.ethers.provider.getNetwork()).chainId;
return {
version: "1.0",
chainId: `${chainId}`,
createdAt: Date.now(),
meta: {
name: "Transaction Batch",
description: "Script generated transaction batch. Verify manually before execution!",
txBuilderVersion: "1.11.1",
},
transactions: transactions.map(encodeContractTx),
};
}
5 changes: 5 additions & 0 deletions spot-contracts/tasks/mainnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ yarn hardhat --network mainnet ops:redeemTranches \
yarn hardhat --network mainnet ops:redeemTranches \
--bond-issuer-address 0x2E2E49eDCd5ce08677Bab6d791C863f1361B52F2

yarn hardhat --network mainnet ops:preview_tx:trancheAndRollover \
--wallet-address [INSERT_WALLET_ADDRESS] \
--router-address 0x38f600e08540178719BF656e6B43FC15A529c393 \
--perp-address 0xC1f33e0cf7e40a67375007104B929E49a581bafE

yarn hardhat --network mainnet ops:trancheAndRollover \
--router-address 0x38f600e08540178719BF656e6B43FC15A529c393 \
--perp-address 0xC1f33e0cf7e40a67375007104B929E49a581bafE \
Expand Down
1 change: 1 addition & 0 deletions spot-contracts/tasks/ops/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "./ampl";
import "./perp";
import "./perp_rollover";
import "./testnet";
Loading