Skip to content

Commit

Permalink
update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
princetonbishop committed Jan 2, 2025
1 parent 8e6631f commit 91003e5
Show file tree
Hide file tree
Showing 19 changed files with 302 additions and 66 deletions.
114 changes: 114 additions & 0 deletions protocol/contracts/fakes/templegold/TempleTeleporterTestnet.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
pragma solidity ^0.8.20;
// SPDX-License-Identifier: AGPL-3.0-or-later
// Temple (fakes/templegold/TempleTeleporterTestnet.sol)


import { CommonEventsAndErrors } from "contracts/common/CommonEventsAndErrors.sol";
import { FakeERC20 } from "contracts/fakes/FakeERC20.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { OApp } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/OApp.sol";
import { MessagingReceipt, MessagingFee } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/OAppSender.sol";
import { Origin } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/interfaces/IOAppReceiver.sol";
import { OFTMsgCodec } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oft/libs/OFTMsgCodec.sol";

/**
* @title Temple Teleporter for testnet
* @notice Temple Teleporter transfers Temple token cross-chain with layer zero integration.
* The only change in contract is moving from templeToken.burnFrom() to templeToken.burn() to go with testnet temple token
* which is not burnable. Interface has changed too from ITempleERC20Token to FakeERC20.
* ITempleTeleporter interface is removed.
*/
contract TempleTeleporterTestnet is OApp {
using OFTMsgCodec for address;

/// @notice Temple token
FakeERC20 public immutable temple;

event TempleTeleported(uint32 dstEid, address indexed sender, address indexed recipient, uint256 amount);

constructor(
address _executor,
address _temple,
address _endpoint
) Ownable(_executor) OApp(_endpoint, _executor){
temple = FakeERC20(_temple);
}

/**
* @notice Teleport temple tokens cross chain
* Enough msg.value needs to be sent through to cover completing execution and the transfer by endpoint and on the destination chain.
* This value can be estimated via the `quote()` function.
* @dev Temple tokens are burned from source chain and minted on destination chain
* @param dstEid Destination chain id
* @param to Recipient
* @param amount Amount of tokens
* @param options LZ extra options
*/
function teleport(
uint32 dstEid,
address to,
uint256 amount,
bytes calldata options
) external payable returns(MessagingReceipt memory receipt) {
if (amount == 0) { revert CommonEventsAndErrors.ExpectedNonZero(); }
if (to == address(0)) { revert CommonEventsAndErrors.InvalidAddress(); }
// Encodes the message before invoking _lzSend.
bytes memory _payload = abi.encode(to.addressToBytes32(), amount);
// debit
temple.burn(msg.sender, amount);
emit TempleTeleported(dstEid, msg.sender, to, amount);

receipt = _lzSend(dstEid, _payload, options, MessagingFee(msg.value, 0), payable(msg.sender));
}

/**
* @dev External function to interact with the LayerZero EndpointV2.quote() for fee calculation.
* @param _dstEid The destination endpoint ID.
* @param _message The message payload.
* @param _options Additional options for the message.
* @return fee The calculated MessagingFee for the message.
* - nativeFee: The native fee for the message.
* - lzTokenFee: The LZ token fee for the message.
*/
function quote(
uint32 _dstEid,
bytes memory _message,
bytes memory _options
) external view returns (MessagingFee memory fee) {
return _quote(_dstEid, _message, _options, false);
}

/**
* @dev External function to interact with the LayerZero EndpointV2.quote() for fee calculation.
* @param _dstEid The destination endpoint ID.
* @param _to Recipient
* @param _amount Amount to send
* @param _options Additional options for the message.
* @return fee The calculated MessagingFee for the message.
* - nativeFee: The native fee for the message.
* - lzTokenFee: The LZ token fee for the message.
*/
function quote(
uint32 _dstEid,
address _to,
uint256 _amount,
bytes memory _options
) external view returns (MessagingFee memory fee) {
return _quote(_dstEid, abi.encodePacked(_to.addressToBytes32(), _amount), _options, false);
}

/// @dev Called when data is received from the protocol. It overrides the equivalent function in the parent contract.
/// Protocol messages are defined as packets, comprised of the following parameters.
/// @param _payload Encoded message.
function _lzReceive(
Origin calldata /*_origin*/,
bytes32 /*_guid*/,
bytes calldata _payload,
address /*_executor,*/, // Executor address as specified by the OApp.
bytes calldata /*_extraData */ // Any extra data or options to trigger on receipt.
) internal override {
// Decode the payload to get the message
(address _recipient, uint256 _amount) = abi.decode(_payload, (address, uint256));
temple.mint(_recipient, _amount);
}
}
1 change: 1 addition & 0 deletions protocol/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ module.exports = {
goerli: process.env.ETHERSCAN_API_KEY,
sepolia: process.env.ETHERSCAN_API_KEY,
arbitrumSepolia: process.env.ARBISCAN_API_KEY,
cartio: process.env.CARTIO_API_KEY,
},
customChains: [
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// cartio: TEMPLE=0x0090F9655a0B0A32cEE0Da5ae45E93EAB4C6d149
// yarn hardhat verify --network cartio 0x0090F9655a0B0A32cEE0Da5ae45E93EAB4C6d149 --constructor-args scripts/deploys/cartio/deploymentArgs/0x0090F9655a0B0A32cEE0Da5ae45E93EAB4C6d149.js
module.exports = [];
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// cartio: TEMPLE_GOLD_ADMIN=0x192aA9BfDcA5540406E211950C226C8E0cd5047F
// yarn hardhat verify --network cartio 0x192aA9BfDcA5540406E211950C226C8E0cd5047F --constructor-args scripts/deploys/cartio/deploymentArgs/0x192aA9BfDcA5540406E211950C226C8E0cd5047F.js
module.exports = [
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"0xC785695710292c042a2de8A0Ba16F3a054cC2eAD",
"0x98c5E61b1B3731A1f379E8770861164d23118cdc"
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// cartio: TEMPLE_GOLD=0x2ae6318e34bb97ae3755AFcE75559452aA223A5D
// yarn hardhat verify --network cartio 0x2ae6318e34bb97ae3755AFcE75559452aA223A5D --constructor-args scripts/deploys/cartio/deploymentArgs/0x2ae6318e34bb97ae3755AFcE75559452aA223A5D.js
module.exports = [
{
"executor": "0xC785695710292c042a2de8A0Ba16F3a054cC2eAD",
"layerZeroEndpoint": "0x6C7Ab2202C98C4227C5c46f1417D81144DA716Ff",
"mintChainId": 11155111,
"mintChainLzEid": 40161,
"name": "TEMPLE GOLD",
"symbol": "TGLD"
}
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// cartio: TEMPLE_GOLD=0x98c5E61b1B3731A1f379E8770861164d23118cdc
// yarn hardhat verify --network cartio 0x98c5E61b1B3731A1f379E8770861164d23118cdc --constructor-args scripts/deploys/cartio/deploymentArgs/0x98c5E61b1B3731A1f379E8770861164d23118cdc.js
module.exports = [
{
"executor": "0xC785695710292c042a2de8A0Ba16F3a054cC2eAD",
"layerZeroEndpoint": "0x6C7Ab2202C98C4227C5c46f1417D81144DA716Ff",
"mintChainId": 80000,
"mintChainLzEid": 40346,
"name": "TEMPLE GOLD",
"symbol": "TGLD"
}
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// cartio: TEMPLE_GOLD_ADMIN=0xBe9162230D9e637218D74C7f41f62ef2385fEe64
// yarn hardhat verify --network cartio 0xBe9162230D9e637218D74C7f41f62ef2385fEe64 --constructor-args scripts/deploys/cartio/deploymentArgs/0xBe9162230D9e637218D74C7f41f62ef2385fEe64.js
module.exports = [
"0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"0xC785695710292c042a2de8A0Ba16F3a054cC2eAD",
"0x2ae6318e34bb97ae3755AFcE75559452aA223A5D"
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// cartio: TEMPLE_TELEPORTER=0xcbc7cf85dd0AB91Aa2671400E86ebf3AaC6dc658
// yarn hardhat verify --network cartio 0xcbc7cf85dd0AB91Aa2671400E86ebf3AaC6dc658 --constructor-args scripts/deploys/cartio/deploymentArgs/0xcbc7cf85dd0AB91Aa2671400E86ebf3AaC6dc658.js
module.exports = [
"0xC785695710292c042a2de8A0Ba16F3a054cC2eAD",
"0x0090F9655a0B0A32cEE0Da5ae45E93EAB4C6d149",
"0x6C7Ab2202C98C4227C5c46f1417D81144DA716Ff"
];
8 changes: 4 additions & 4 deletions protocol/scripts/deploys/cartio/templegold/02-temple-gold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ async function main() {
const [owner] = await ethers.getSigners();
const ownerAddress = await owner.getAddress();
const TEMPLEGOLD_ADDRESSES = getDeployedTempleGoldContracts();
const CARTIO_TESTNET_CHAIN_ID = 80000;
const CARTIO_TESTNET_LZ_EID = 40346;
const MINT_CHAIN_ID = 11155111; // sepolia
const MINT_CHAIN_LZ_EID = 40161; // sepolia lz
const _initArgs = {
// Changed in transfer ownership to TempleAdmin
executor: ownerAddress, // executor is also used as delegate in LayerZero Endpoint.
layerZeroEndpoint: TEMPLEGOLD_ADDRESSES.EXTERNAL.LAYER_ZERO.ENDPOINT, // local endpoint address
mintChainId: CARTIO_TESTNET_CHAIN_ID,
mintChainLzEid: CARTIO_TESTNET_LZ_EID,
mintChainId: MINT_CHAIN_ID,
mintChainLzEid: MINT_CHAIN_LZ_EID,
name: "TEMPLE GOLD",
symbol: "TGLD"
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@ import {
ensureExpectedEnvvars,
} from '../../helpers';
import { getDeployedTempleGoldContracts } from '../../mainnet/templegold/contract-addresses';
import { getDeployedContracts } from '../../mainnet/v2/contract-addresses';

async function main() {
ensureExpectedEnvvars();
const [owner] = await ethers.getSigners();
const TEMPLEGOLD_ADDRESSES = getDeployedTempleGoldContracts();
const CORE_ADDRESSES = getDeployedContracts();

const factory = new TempleTeleporter__factory(owner);
await deployAndMine(
'TEMPLE_TELEPORTER',
factory,
factory.deploy,
CORE_ADDRESSES.CORE.EXECUTOR_MSIG,
CORE_ADDRESSES.CORE.TEMPLE_TOKEN,
await owner.getAddress(), // executor
TEMPLEGOLD_ADDRESSES.CORE.TEMPLE_TOKEN,
TEMPLEGOLD_ADDRESSES.EXTERNAL.LAYER_ZERO.ENDPOINT
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@ import {
ensureExpectedEnvvars,
} from '../../helpers';
import { getDeployedTempleGoldContracts } from '../../mainnet/templegold/contract-addresses';
import { getDeployedContracts } from '../../mainnet/v2/contract-addresses';

async function main() {
ensureExpectedEnvvars();
const [owner] = await ethers.getSigners();
const TEMPLEGOLD_ADDRESSES = getDeployedTempleGoldContracts();
const CORE_ADDRESSES = getDeployedContracts();
const rescuer = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266";

const factory = new TempleGoldAdmin__factory(owner);
await deployAndMine(
'TEMPLE_GOLD_ADMIN',
factory,
factory.deploy,
CORE_ADDRESSES.CORE.RESCUER_MSIG,
CORE_ADDRESSES.CORE.EXECUTOR_MSIG,
rescuer, // rescuer
await owner.getAddress(), // executor
TEMPLEGOLD_ADDRESSES.TEMPLE_GOLD.TEMPLE_GOLD
);
}
Expand Down
35 changes: 35 additions & 0 deletions protocol/scripts/deploys/cartio/templegold/999-ops.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { ethers } from 'hardhat';
import {
ensureExpectedEnvvars,
mine,
} from '../../helpers';
import { connectToContracts, ContractInstances, ContractAddresses, getDeployedTempleGoldContracts } from '../../mainnet/templegold/contract-addresses';

async function main() {
ensureExpectedEnvvars();
const [owner] = await ethers.getSigners();
const TEMPLE_GOLD_ADDRESSES = getDeployedTempleGoldContracts();
const TEMPLE_GOLD_INSTANCES = connectToContracts(owner);

// Transfer ownership to the temple gold admin
await transferOwnerships(TEMPLE_GOLD_INSTANCES, TEMPLE_GOLD_ADDRESSES);

await addMinter(TEMPLE_GOLD_INSTANCES, TEMPLE_GOLD_ADDRESSES.TEMPLE_GOLD.TEMPLE_TELEPORTER);
}

async function transferOwnerships(instances: ContractInstances, addresses: ContractAddresses) {
await mine(instances.TEMPLE_GOLD.TEMPLE_GOLD.transferOwnership(addresses.TEMPLE_GOLD.TEMPLE_GOLD_ADMIN));
}

async function addMinter(instances: ContractInstances, minter: string) {
await mine(instances.CORE.TEMPLE_TOKEN.addMinter(minter));
}

// 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);
});

This file was deleted.

1 change: 1 addition & 0 deletions protocol/scripts/deploys/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ const expectedEnvvars: { [key: string]: string[] } = {
polygonMumbai: ['MUMBAI_ADDRESS_PRIVATE_KEY', 'MUMBAI_RPC_URL'],
sepolia: ['SEPOLIA_ADDRESS_PRIVATE_KEY', 'SEPOLIA_RPC_URL'],
arbitrumSepolia: ['ARBITRUM_SEPOLIA_ADDRESS_PRIVATE_KEY', 'ARBITRUM_SEPOLIA_RPC_URL'],
cartio: ['CARTIO_ADDRESS_PRIVATE_KEY', 'CARTIO_RPC_URL'],
anvil: [],
localhost: [],
};
Expand Down
Loading

0 comments on commit 91003e5

Please sign in to comment.