Skip to content

Commit

Permalink
deploy script, anvil, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
princetonbishop committed Aug 23, 2024
1 parent 349fbcd commit 905e096
Show file tree
Hide file tree
Showing 9 changed files with 7,642 additions and 19 deletions.
8 changes: 4 additions & 4 deletions protocol/contracts/interfaces/templegold/IAuctionBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ interface IAuctionBase {
}

/// @notice Keep track of epochs details
function getEpochInfo(uint256 epochId) external returns (EpochInfo memory);
function getEpochInfo(uint256 epochId) external view returns (EpochInfo memory);
/// @notice Keep track of depositors for each epoch
function depositors(address depositor, uint256 epochId) external returns (uint256);
function depositors(address depositor, uint256 epochId) external view returns (uint256);
/// @notice Keep track of claimed accounts per epoch
function claimed(address depositor, uint256 epochId) external returns (bool);
function claimed(address depositor, uint256 epochId) external view returns (bool);
/// @notice claimed amounts
function claimedAmount(address depositor, uint256 epochId) external returns (uint256);
function claimedAmount(address depositor, uint256 epochId) external view returns (uint256);

/**
* @notice Deposit bid token for current running epoch auction
Expand Down
1 change: 0 additions & 1 deletion protocol/contracts/interfaces/templegold/ITempleGold.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ interface ITempleGold is IOFT, IOAppCore, IOAppOptionsType3, IERC20 {
event DaiGoldAuctionSet(address daiGoldAuction);
event TeamGnosisSet(address gnosis);
event CirculatingSupplyUpdated(address indexed sender, uint256 amount, uint256 circulatingSuppply, uint256 totalBurned);
event NotifierSet(address indexed notifier);

error InvalidTotalShare();
error MissingParameter();
Expand Down
13 changes: 0 additions & 13 deletions protocol/contracts/templegold/TempleGold.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ import { TempleMath } from "contracts/common/TempleMath.sol";
/// @notice Multisig gnosis address
address public override teamGnosis;

address public notifier;

/// @notice Last block timestamp Temple Gold was minted
uint32 public override lastMintTimestamp;

Expand Down Expand Up @@ -138,12 +136,6 @@ import { TempleMath } from "contracts/common/TempleMath.sol";
else { mint(); }
emit VestingFactorSet(_factor.value, _factor.weekMultiplier);
}

function setNotifier(address _notifier) external onlyOwner {
if (_notifier == address(0)) { revert CommonEventsAndErrors.InvalidAddress(); }
notifier = _notifier;
emit NotifierSet(_notifier);
}

/**
* @notice Mint new tokens to be distributed. Open to call from any address
Expand Down Expand Up @@ -394,9 +386,4 @@ import { TempleMath } from "contracts/common/TempleMath.sol";
if (block.chainid != _mintChainId) { revert WrongChain(); }
_;
}

modifier onlyNotifier() {
if (msg.sender != notifier) { revert CommonEventsAndErrors.InvalidAccess(); }
_;
}
}
27 changes: 27 additions & 0 deletions protocol/scripts/deploys/arbitrumOne/contract-addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,33 @@ const TEMPLEGOLD_DEPLOYED_CONTRACTS: {[key: string]: ContractAddresses} = {
}
},
},
localhost: {
TEMPLE_GOLD: {
AUCTION_AUTOMATION_EOA: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
STAKING_AUTOMATION_EOA: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
SPICE_AUCTION_OPERATOR: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
TEMPLE_GOLD: "0xf3800C1f5374d9104ab20A48F1F83485BD9a37da",
TEMPLE_GOLD_ADMIN: "0x0222F49C69567eB50f425AF01E2F9FCc451e807B",
TEMPLE_GOLD_STAKING: "0xa7390dA200fcB4ce8C1032Cc024779F488B0D03a",
TEMPLE_TELEPORTER: "0x876d471068e723279Fe52Eb10A6A587cA1a26CA4",
SPICE_AUCTION: "string",
SPICE_AUCTION_FACTORY: "string",
DAI_GOLD_AUCTION: "0xA3174691290D9F0D8Fe3E98D8222441e117d1c46",
EXECUTOR_MSIG: "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
RESCUER_MSIG: "0x70997970C51812dc3A010C7d01b50e0d17dc79C8",
},
CORE: {
TEMPLE_TOKEN: "0x7816d99063dfEc136d2139681D3fbD92375Ec14c",
},
EXTERNAL: {
LAYER_ZERO: {
ENDPOINT: '0x1a44076050125825900e736c501f859c50fE728c',
},
MAKER_DAO: {
DAI_TOKEN: "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1",
}
},
}
}

export function getDeployedTempleGoldContracts(): ContractAddresses {
Expand Down
134 changes: 134 additions & 0 deletions protocol/scripts/deploys/localhost/templegold/01-localhost.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import '@nomiclabs/hardhat-ethers';
import { ethers } from 'hardhat';
import { TempleGold__factory, TempleGoldAdmin__factory,
TempleGoldStaking__factory, TempleTeleporter__factory,
DaiGoldAuction__factory, FakeERC20__factory } from '../../../../typechain';
import {
deployAndMine,
ensureExpectedEnvvars,
toAtto,
} from '../../helpers';
import { getDeployedContracts } from '../../mainnet/v2/contract-addresses';
import { getDeployedTempleGoldContracts } from '../../arbitrumOne/contract-addresses';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { ContractAddresses } from '@balancer-labs/sdk';

async function main() {
ensureExpectedEnvvars();
const [owner, rescuer] = await ethers.getSigners();

await _deployTempleToken(owner);
await _deployTempleGold(owner);
await _deployTempleGoldAdmin(owner, rescuer);

await _deployTempleGoldStaking(owner, rescuer);
await _deployTempleTeleporter(owner);

await _deployDaiGoldAuction(owner, rescuer);
}

async function _deployTempleToken(owner: SignerWithAddress) {
const factory = new FakeERC20__factory(owner);
await deployAndMine(
'TEMPLE_TOKEN',
factory,
factory.deploy,
"Temple",
"TEMPLE",
await owner.getAddress(),
toAtto(1000)
);
}

async function _deployTempleGold(owner: SignerWithAddress) {
const TEMPLEGOLD_ADDRESSES = getDeployedTempleGoldContracts();
const ARBITRUM_ONE_CHAIN_ID = 42161;
const ARBITRUM_ONE_LZ_EID = 30110;
const _initArgs = {
// Changed in transfer ownership to TempleAdmin
executor: await owner.getAddress(), // executor is also used as delegate in LayerZero Endpoint.
layerZeroEndpoint: TEMPLEGOLD_ADDRESSES.EXTERNAL.LAYER_ZERO.ENDPOINT, // local endpoint address
mintChainId: ARBITRUM_ONE_CHAIN_ID,
mintChainLzEid: ARBITRUM_ONE_LZ_EID,
name: "TEMPLE GOLD",
symbol: "TGLD"
};
const factory = new TempleGold__factory(owner);
await deployAndMine(
'TEMPLE_GOLD',
factory,
factory.deploy,
_initArgs
);
}

async function _deployTempleGoldAdmin(owner: SignerWithAddress, rescuer: SignerWithAddress) {
const factory = new TempleGoldAdmin__factory(owner);
const TEMPLEGOLD_ADDRESSES = getDeployedTempleGoldContracts();
await deployAndMine(
'TEMPLE_GOLD_ADMIN',
factory,
factory.deploy,
await rescuer.getAddress(),
await owner.getAddress(),
TEMPLEGOLD_ADDRESSES.TEMPLE_GOLD.TEMPLE_GOLD
);
}

async function _deployTempleGoldStaking(owner: SignerWithAddress, rescuer: SignerWithAddress) {
const TEMPLEGOLD_ADDRESSES = getDeployedTempleGoldContracts();
const CORE_ADDRESSES = getDeployedContracts();


const factory = new TempleGoldStaking__factory(owner);
await deployAndMine(
'TEMPLE_GOLD_STAKING',
factory,
factory.deploy,
await rescuer.getAddress(),
await owner.getAddress(),
CORE_ADDRESSES.CORE.TEMPLE_TOKEN,
TEMPLEGOLD_ADDRESSES.TEMPLE_GOLD.TEMPLE_GOLD
);
}

async function _deployTempleTeleporter(owner: SignerWithAddress) {
const TEMPLEGOLD_ADDRESSES = getDeployedTempleGoldContracts();
const CORE_ADDRESSES = getDeployedContracts();

const factory = new TempleTeleporter__factory(owner);
await deployAndMine(
'TEMPLE_TELEPORTER',
factory,
factory.deploy,
await owner.getAddress(),
CORE_ADDRESSES.CORE.TEMPLE_TOKEN,
TEMPLEGOLD_ADDRESSES.EXTERNAL.LAYER_ZERO.ENDPOINT
);
}

async function _deployDaiGoldAuction(owner: SignerWithAddress, rescuer: SignerWithAddress): Promise<void> {
const TEMPLEGOLD_ADDRESSES = getDeployedTempleGoldContracts();
const arbDaiToken = "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1";
const factory = new DaiGoldAuction__factory(owner);
await deployAndMine(
'DAI_GOLD_AUCTION',
factory,
factory.deploy,
TEMPLEGOLD_ADDRESSES.TEMPLE_GOLD.TEMPLE_GOLD,
arbDaiToken,
await owner.getAddress(), // treasury
await rescuer.getAddress(),
await owner.getAddress(),
TEMPLEGOLD_ADDRESSES.TEMPLE_GOLD.AUCTION_AUTOMATION_EOA
);
}

// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});
81 changes: 81 additions & 0 deletions protocol/scripts/deploys/localhost/templegold/999-localhost.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { ethers, network } from 'hardhat';
import {
ensureExpectedEnvvars,
mine,
} from '../../helpers';
import { connectToContracts, getDeployedTempleGoldContracts } from '../../arbitrumOne/contract-addresses';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { TempleGold__factory, TempleGoldStaking__factory, DaiGoldAuction__factory } from '../../../../typechain';


async function main() {
ensureExpectedEnvvars();
const [owner] = await ethers.getSigners();
const TEMPLE_GOLD_ADDRESSES = getDeployedTempleGoldContracts();
const TEMPLE_GOLD_INSTANCES = connectToContracts(owner);
// signer 0
const teamGnosis = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266';
console.log(`OWNER ${await TEMPLE_GOLD_INSTANCES.TEMPLE_GOLD.TEMPLE_GOLD.owner()}`);
console.log(`OWNER ${await TEMPLE_GOLD_INSTANCES.TEMPLE_GOLD.TEMPLE_GOLD_STAKING.executor()}`);
const distributionParams = {
staking: ethers.utils.parseEther("20"),
daiGoldAuction: ethers.utils.parseEther("70"),
gnosis: ethers.utils.parseEther("10")
}
const vestingFactor = {
value: 35,
weekMultiplier: 3600 * 24 * 7 // 1 week
}
///// TEMPLE GOLD
const templeGold = TempleGold__factory.connect(TEMPLE_GOLD_ADDRESSES.TEMPLE_GOLD.TEMPLE_GOLD, owner);
const staking = TempleGoldStaking__factory.connect(TEMPLE_GOLD_ADDRESSES.TEMPLE_GOLD.TEMPLE_GOLD_STAKING, owner);
const daiGoldAuction = DaiGoldAuction__factory.connect(TEMPLE_GOLD_ADDRESSES.TEMPLE_GOLD.DAI_GOLD_AUCTION, owner);
console.log(`TempleGOld: ${await daiGoldAuction.templeGold()}`);
// // Set and whitelist contracts
await mine(templeGold.setTeamGnosis(teamGnosis));
await mine(templeGold.setDaiGoldAuction(TEMPLE_GOLD_ADDRESSES.TEMPLE_GOLD.DAI_GOLD_AUCTION));
await mine(templeGold.setStaking(TEMPLE_GOLD_ADDRESSES.TEMPLE_GOLD.TEMPLE_GOLD_STAKING));
await mine(templeGold.setVestingFactor(vestingFactor));
await mine(templeGold.setDistributionParams(distributionParams));
// // authorize contracts
await mine(templeGold.authorizeContract(TEMPLE_GOLD_ADDRESSES.TEMPLE_GOLD.DAI_GOLD_AUCTION, true));
await mine(templeGold.authorizeContract(TEMPLE_GOLD_ADDRESSES.TEMPLE_GOLD.TEMPLE_GOLD_STAKING, true));
await mine(templeGold.authorizeContract(teamGnosis, true));

// ///// Staking
const duration = 24 * 3600 * 7;
const unstakeCooldown = duration * 2; // 2 weeks
const rewardsDistributionCooldown = 3600; // 1 hour
// reward duration
await mine(staking.setRewardDuration(duration));
// distribution starter
await mine(staking.setDistributionStarter(teamGnosis));
// rewards distribution cool down
await mine(staking.setRewardDistributionCoolDown(rewardsDistributionCooldown));
// unstake cool down
await mine(staking.setUnstakeCooldown(unstakeCooldown));

////// DAI GOLD AUCTION
const auctionsTimeDiff = 60;
const auctionConfig = {
/// Time diff between two auctions. Usually 2 weeks
auctionsTimeDiff: auctionsTimeDiff,
/// Cooldown after auction start is triggered, to allow deposits
auctionStartCooldown: 60,
/// Minimum Gold distributed to enable auction start
auctionMinimumDistributedGold: ethers.utils.parseEther("0.01"),
};
// auction starter
await mine(daiGoldAuction.setAuctionStarter(teamGnosis));
// auction config
await mine(daiGoldAuction.setAuctionConfig(auctionConfig));
}

// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});
5 changes: 5 additions & 0 deletions protocol/scripts/deploys/localhost/templegold/deploy-anvil.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

anvil --fork-url $ARBITRUM_ONE_RPC_URL

npx hardhat --network localhost run scripts/deploys/localhost/templegold/01-localhost.ts
Loading

0 comments on commit 905e096

Please sign in to comment.