Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
xtools-at committed Feb 28, 2024
2 parents 2662944 + 3c6e22b commit 73c9cba
Show file tree
Hide file tree
Showing 15 changed files with 9,641 additions and 2 deletions.
10 changes: 10 additions & 0 deletions constants/tokenConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ module.exports = {
symbol: "DOMI",
withFee: true,
},
ForgottenPlaylandOFT: {
name: "Forgotten Playland",
symbol: "FP",
withFee: true,
},
},
"beam-testnet": {
BeamNativeOFT: {
Expand Down Expand Up @@ -115,6 +120,11 @@ module.exports = {
withFee: true,
minGas: 10000000,
},
ForgottenPlaylandProxyOFT: {
address: "0xEeee2A2E650697d2A8e8BC990C2f3d04203bE06f",
withFee: true,
minGas: 10000000,
},
},
goerli: {
BeamProxyOFT: {
Expand Down
10 changes: 10 additions & 0 deletions contracts/contracts-upgradable/examples/FP.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.18;

import "../token/oft/v2/fee/OFTWithFeePermitUpgradeable.sol";
import "../token/oft/v2/fee/ProxyOFTWithFeeUpgradeable.sol";

contract ForgottenPlaylandOFT is OFTWithFeePermitUpgradeable {}

contract ForgottenPlaylandProxyOFT is ProxyOFTWithFeeUpgradeable {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "hardhat-deploy/solc_0.8/proxy/Proxied.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/ERC20PermitUpgradeable.sol";
import "./BaseOFTWithFeeUpgradeable.sol";

contract OFTWithFeePermitUpgradeable is Initializable, BaseOFTWithFeeUpgradeable, ERC20Upgradeable, Proxied, ERC20PermitUpgradeable {
uint internal ld2sdRate;

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}

function initialize(
string memory _name,
string memory _symbol,
uint8 _sharedDecimals,
address _lzEndpoint
) public virtual initializer {
__OFTWithFeePermitUpgradeable_init(_name, _symbol, _sharedDecimals, _lzEndpoint);
}

function __OFTWithFeePermitUpgradeable_init(
string memory _name,
string memory _symbol,
uint8 _sharedDecimals,
address _lzEndpoint
) internal onlyInitializing {
__Ownable_init_unchained();
__LzAppUpgradeable_init_unchained(_lzEndpoint);
__OFTCoreV2Upgradeable_init_unchained(_sharedDecimals);

__ERC20_init_unchained(_name, _symbol);
__ERC20Permit_init_unchained(_name);

__OFTWithFeePermitUpgradeable_init_unchained(_sharedDecimals);
}

function __OFTWithFeePermitUpgradeable_init_unchained(uint8 _sharedDecimals) internal onlyInitializing {
uint8 decimals = decimals();
require(_sharedDecimals <= decimals, "OFTWithFee: sharedDecimals must be <= decimals");
ld2sdRate = 10**(decimals - _sharedDecimals);
}

/************************************************************************
* public functions
************************************************************************/
function circulatingSupply() public view virtual override returns (uint) {
return totalSupply();
}

function token() public view virtual override returns (address) {
return address(this);
}

/************************************************************************
* internal functions
************************************************************************/
function _debitFrom(
address _from,
uint16,
bytes32,
uint _amount
) internal virtual override returns (uint) {
address spender = _msgSender();
if (_from != spender) _spendAllowance(_from, spender, _amount);
_burn(_from, _amount);
return _amount;
}

function _creditTo(
uint16,
address _toAddress,
uint _amount
) internal virtual override returns (uint) {
_mint(_toAddress, _amount);
return _amount;
}

function _transferFrom(
address _from,
address _to,
uint _amount
) internal virtual override returns (uint) {
address spender = _msgSender();
// if transfer from this contract, no need to check allowance
if (_from != address(this) && _from != spender) _spendAllowance(_from, spender, _amount);
_transfer(_from, _to, _amount);
return _amount;
}

function _ld2sdRate() internal view virtual override returns (uint) {
return ld2sdRate;
}
}
47 changes: 47 additions & 0 deletions deploy/ForgottenPlaylandOFT.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const LZ_ENDPOINTS = require("../constants/layerzeroEndpoints.json")
const TOKEN_CONFIG = require("../constants/tokenConfig")

const CONTRACT_NAME = "ForgottenPlaylandOFT"

module.exports = async function ({ deployments, getNamedAccounts }) {
const { deploy } = deployments
const { deployer, proxyOwner } = await getNamedAccounts()

let lzEndpointAddress, lzEndpoint, LZEndpointMock
if (hre.network.name === "hardhat") {
LZEndpointMock = await ethers.getContractFactory("LZEndpointMock")
lzEndpoint = await LZEndpointMock.deploy(1)
lzEndpointAddress = lzEndpoint.address
} else {
lzEndpointAddress = LZ_ENDPOINTS[hre.network.name]
}

const tokenConfig = TOKEN_CONFIG[hre.network.name][CONTRACT_NAME]
if (!tokenConfig.name || !tokenConfig.symbol) {
console.error("No configuration found for target network.")
return
}

await deploy(CONTRACT_NAME, {
from: deployer,
log: true,
waitConfirmations: 1,
proxy: {
owner: proxyOwner,
proxyContract: "OptimizedTransparentProxy",
execute: {
init: {
methodName: "initialize",
args: [
tokenConfig.name,
tokenConfig.symbol,
tokenConfig.sharedDecimals != null ? tokenConfig.sharedDecimals : 6,
lzEndpointAddress,
],
},
},
},
})
}

module.exports.tags = [CONTRACT_NAME]
43 changes: 43 additions & 0 deletions deploy/ForgottenPlaylandProxyOFT.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const LZ_ENDPOINTS = require("../constants/layerzeroEndpoints.json")
const TOKEN_CONFIG = require("../constants/tokenConfig")

const CONTRACT_NAME = "ForgottenPlaylandProxyOFT"

module.exports = async function ({ deployments, getNamedAccounts }) {
const { deploy } = deployments
const { deployer, proxyOwner } = await getNamedAccounts()

let lzEndpointAddress, lzEndpoint, LZEndpointMock
if (hre.network.name === "hardhat") {
LZEndpointMock = await ethers.getContractFactory("LZEndpointMock")
lzEndpoint = await LZEndpointMock.deploy(1)
lzEndpointAddress = lzEndpoint.address
} else {
lzEndpointAddress = LZ_ENDPOINTS[hre.network.name]
}

const tokenConfig = TOKEN_CONFIG[hre.network.name][CONTRACT_NAME]

if (!tokenConfig.address) {
console.error("No configured token address found for target network.")
return
}

await deploy(CONTRACT_NAME, {
from: deployer,
log: true,
waitConfirmations: 1,
proxy: {
owner: proxyOwner,
proxyContract: "OptimizedTransparentProxy",
execute: {
init: {
methodName: "initialize",
args: [tokenConfig.address, tokenConfig.sharedDecimals != null ? tokenConfig.sharedDecimals : 6, lzEndpointAddress],
},
},
},
})
}

module.exports.tags = [CONTRACT_NAME]
Loading

0 comments on commit 73c9cba

Please sign in to comment.