-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e6631f
commit 91003e5
Showing
19 changed files
with
302 additions
and
66 deletions.
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
protocol/contracts/fakes/templegold/TempleTeleporterTestnet.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
protocol/scripts/deploys/cartio/deploymentArgs/0x0090F9655a0B0A32cEE0Da5ae45E93EAB4C6d149.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = []; |
7 changes: 7 additions & 0 deletions
7
protocol/scripts/deploys/cartio/deploymentArgs/0x192aA9BfDcA5540406E211950C226C8E0cd5047F.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
]; |
12 changes: 12 additions & 0 deletions
12
protocol/scripts/deploys/cartio/deploymentArgs/0x2ae6318e34bb97ae3755AFcE75559452aA223A5D.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
]; |
12 changes: 12 additions & 0 deletions
12
protocol/scripts/deploys/cartio/deploymentArgs/0x98c5E61b1B3731A1f379E8770861164d23118cdc.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
]; |
7 changes: 7 additions & 0 deletions
7
protocol/scripts/deploys/cartio/deploymentArgs/0xBe9162230D9e637218D74C7f41f62ef2385fEe64.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
]; |
7 changes: 7 additions & 0 deletions
7
protocol/scripts/deploys/cartio/deploymentArgs/0xcbc7cf85dd0AB91Aa2671400E86ebf3AaC6dc658.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
43 changes: 0 additions & 43 deletions
43
protocol/scripts/deploys/cartio/templegold/999-transfer-ownership.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.