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
273 changes: 138 additions & 135 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion SmartContractProjectConfig
13 changes: 6 additions & 7 deletions contracts/redpacket.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
**/

pragma solidity >= 0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
Expand Down Expand Up @@ -56,7 +55,7 @@ contract HappyRedPacket is Initializable {
uint remaining_balance
);

using SafeERC20 for IERC20;
using SafeERC20Upgradeable for IERC20Upgradeable;
uint32 nonce;
mapping(bytes32 => RedPacket) redpacket_by_id;
bytes32 private seed;
Expand Down Expand Up @@ -84,9 +83,9 @@ contract HappyRedPacket is Initializable {
else if (_token_type == 1) {
// https://github.com/DimensionDev/Maskbook/issues/4168
// `received_amount` is not necessarily equal to `_total_tokens`
uint256 balance_before_transfer = IERC20(_token_addr).balanceOf(address(this));
IERC20(_token_addr).safeTransferFrom(msg.sender, address(this), _total_tokens);
uint256 balance_after_transfer = IERC20(_token_addr).balanceOf(address(this));
uint256 balance_before_transfer = IERC20Upgradeable(_token_addr).balanceOf(address(this));
IERC20Upgradeable(_token_addr).safeTransferFrom(msg.sender, address(this), _total_tokens);
uint256 balance_after_transfer = IERC20Upgradeable(_token_addr).balanceOf(address(this));
received_amount = balance_after_transfer.sub(balance_before_transfer);
require(received_amount >= _number, "#received > #packets");
}
Expand Down Expand Up @@ -271,7 +270,7 @@ contract HappyRedPacket is Initializable {
}

function transfer_token(address token_address, address recipient_address, uint amount) internal{
IERC20(token_address).safeTransfer(recipient_address, amount);
IERC20Upgradeable(token_address).safeTransfer(recipient_address, amount);
}

// A boring wrapper
Expand Down
47 changes: 20 additions & 27 deletions deploy/erc721_support.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,21 @@
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import { DeployFunction } from 'hardhat-deploy/types'
import { ethers, upgrades } from 'hardhat'
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { DeployFunction } from 'hardhat-deploy/types';
import { ethers, upgrades } from 'hardhat';
import fs from "fs/promises";
import path from "path";
import { parse } from "csv-parse/sync";

type MyMapLikeType = Record<string, string>
const deployedContracts: MyMapLikeType = {
mainnet: '0x8d285739523FC2Ac8eC9c9C229ee863C8C9bF8C8',
ropsten: '0x8fF42e93C19E44763FD1cD07b9E04d13bA07AD3f',
bsc_mainnet: '0xf8968e1Fcf1440Be5Cec7Bb495bcee79753d5E06',
matic_mainnet: '0xf6Dc042717EF4C097348bE00f4BaE688dcaDD4eA',
arbitrum: '0x561c5f3a19871ecb1273D6D8eCc276BeEDa5c8b4',
xdai: '0x561c5f3a19871ecb1273D6D8eCc276BeEDa5c8b4',
goerli: '0x0a04e23f95E9DB2Fe4C31252548F663fFe3AAe4d',
fantom: '0xF9F7C1496c21bC0180f4B64daBE0754ebFc8A8c0',
avalanche: '0x96c7D011cdFD467f551605f0f5Fce279F86F4186',
celo: '0x96c7D011cdFD467f551605f0f5Fce279F86F4186',
optimism: '0x02Ea0720254F7fa4eca7d09A1b9C783F1020EbEF',
optimism_kovan: '0x556F63d7467c729034585C3e50e54e582222b491',
aurora: '0x05ee315E407C21a594f807D61d6CC11306D1F149',
fuse: '0x066804d9123bF2609Ed4A4a40b1177a9c5a9Ed51',
boba: '0xF9F7C1496c21bC0180f4B64daBE0754ebFc8A8c0',
moonriver: '0xF9F7C1496c21bC0180f4B64daBE0754ebFc8A8c0',
conflux_eSpace: '0x5b966f3a32db9c180843bcb40267a66b73e4f022',
conflux_eSpace_test: '0x71834a3fdea3e70f14a93ed85c6be70925d0cad9',
harmony: '0x83d6b366f21e413f214eb077d5378478e71a5ed2',
metis: '0x812463356F58fc8194645A1838ee6C52D8ca2D26',
}
const ADDRESS_TABLE_PATH = path.resolve(__dirname, "..", "helper_scripts", "contract-addresses.csv");

const func: DeployFunction = async function(hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts } = hre
const { deploy } = deployments
const { deployer } = await getNamedAccounts()
const network: string = hre.hardhatArguments.network ? hre.hardhatArguments.network : 'ropsten'
const deployedContracts = await loadDeployedAddress();
const proxyAddress = deployedContracts[network]

if (false) {
if (true) {
// deploy, we normally do this only once
const HappyRedPacketImpl_erc721 = await ethers.getContractFactory('HappyRedPacket_ERC721')
const HappyRedPacketProxy_erc721 = await upgrades.deployProxy(HappyRedPacketImpl_erc721, [])
Expand Down Expand Up @@ -62,6 +44,17 @@ const func: DeployFunction = async function(hre: HardhatRuntimeEnvironment) {
}
}

async function loadDeployedAddress(): Promise<Record<string, string>> {
const data = await fs.readFile(ADDRESS_TABLE_PATH, "utf-8");
const columns = ['Chain', 'HappyRedPacket', 'HappyRedPacket_ERC721'];
const records = parse(data, { delimiter: ',', columns, from: 2 });
let deployedContract: Record<string, string> = {};
for (const { Chain, HappyRedPacket_ERC721 } of records) {
deployedContract[Chain.toLowerCase()] = HappyRedPacket_ERC721;
}
return deployedContract;
}

func.tags = ['HappyRedPacket_ERC721']

module.exports = func
50 changes: 21 additions & 29 deletions deploy/redpacket.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,21 @@
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import { DeployFunction } from 'hardhat-deploy/types'
import { ethers, upgrades } from 'hardhat'
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { DeployFunction } from 'hardhat-deploy/types';
import { ethers, upgrades } from 'hardhat';
import fs from "fs/promises";
import path from "path";
import { parse } from "csv-parse/sync";

type MyMapLikeType = Record<string, string>
const deployedContracts: MyMapLikeType = {
mainnet: '0xaBBe1101FD8fa5847c452A6D70C8655532B03C33',
ropsten: '0x0722507c3b776A6B205946592016e358B0D34c3F',
bsc_mainnet: '0x0ca42C178e14c618c81B8438043F27d9D38145f6',
matic_mainnet: '0x93e0b87A0aD0C991dc1B5176ddCD850c9a78aabb',
arbitrum: '0x83D6b366f21e413f214EB077D5378478e71a5eD2',
arbitrum_rinkeby: '0x4A77E797031257db72F7D2C3Ec08a4FAc5c8CfE9',
xdai: '0x54a0A221C25Fc0a347EC929cFC5db0be17fA2a2B',
goerli: '0x8bF6b979286970860Adc75dc621cf1969b0bE66C',
fantom: '0x578a7Fee5f0D8CEc7d00578Bf37374C5b95C4b98',
avalanche: '0xF9F7C1496c21bC0180f4B64daBE0754ebFc8A8c0',
celo: '0x871F2635EeB0bA3D9f90C4524E3f148C31393F9d',
optimism: '0x981be454a930479d92C91a0092D204b64845A5D6',
optimism_kovan: '0x68EDbfA3E564C987FaaAB54f4FD1E7567D4151Dd',
aurora: '0x19f179D7e0D7d9F9d5386afFF64271D98A91615B',
fuse: '0x561c5f3a19871ecb1273D6D8eCc276BeEDa5c8b4',
boba: '0x578a7Fee5f0D8CEc7d00578Bf37374C5b95C4b98',
moonriver: '0x578a7Fee5f0D8CEc7d00578Bf37374C5b95C4b98',
conflux_eSpace: '0x96c7d011cdfd467f551605f0f5fce279f86f4186',
conflux_eSpace_test: '0x913975af2bb8a6be4100d7dc5e9765b77f6a5d6c',
harmony: '0xab7b1be4233a04e5c43a810e75657eced8e5463b',
metis: '0x2cf91AD8C175305EBe6970Bd8f81231585EFbd77',
}
const ADDRESS_TABLE_PATH = path.resolve(__dirname, "..", "helper_scripts", "contract-addresses.csv");

const func: DeployFunction = async function(hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts } = hre
const { deploy } = deployments
const { deployer } = await getNamedAccounts()
const network: string = hre.hardhatArguments.network ? hre.hardhatArguments.network : 'ropsten'
const deployedContracts = await loadDeployedAddress();
const proxyAddress = deployedContracts[network]

if (false) {
if (true) {
// deploy, we normally do this only once
const HappyRedPacketImpl = await ethers.getContractFactory('HappyRedPacket')
const HappyRedPacketProxy = await upgrades.deployProxy(HappyRedPacketImpl, [])
Expand Down Expand Up @@ -63,6 +44,17 @@ const func: DeployFunction = async function(hre: HardhatRuntimeEnvironment) {
}
}

async function loadDeployedAddress(): Promise<Record<string, string>> {
const data = await fs.readFile(ADDRESS_TABLE_PATH, "utf-8");
const columns = ['Chain', 'HappyRedPacket', 'HappyRedPacket_ERC721'];
const records = parse(data, { delimiter: ',', columns, from: 2 });
let deployedContract: Record<string, string> = {};
for (const { Chain, HappyRedPacket } of records) {
deployedContract[Chain.toLowerCase()] = HappyRedPacket;
}
return deployedContract;
}

func.tags = ['HappyRedPacket']

module.exports = func
13 changes: 7 additions & 6 deletions helper_scripts/contract-addresses.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@ Mainnet,0xaBBe1101FD8fa5847c452A6D70C8655532B03C33,0x8d285739523FC2Ac8eC9c9C229e
Ropsten,0x0722507c3b776A6B205946592016e358B0D34c3F,0x8fF42e93C19E44763FD1cD07b9E04d13bA07AD3f
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add chain id field into the table?

BSC,0x0ca42C178e14c618c81B8438043F27d9D38145f6,0xf8968e1Fcf1440Be5Cec7Bb495bcee79753d5E06
Matic,0x93e0b87A0aD0C991dc1B5176ddCD850c9a78aabb,0xf6Dc042717EF4C097348bE00f4BaE688dcaDD4eA
Rinkeby_arbitrum,0x4A77E797031257db72F7D2C3Ec08a4FAc5c8CfE9,
Arbitrum_rinkeby,0x4A77E797031257db72F7D2C3Ec08a4FAc5c8CfE9,
Arbitrum,0x83D6b366f21e413f214EB077D5378478e71a5eD2,0x561c5f3a19871ecb1273D6D8eCc276BeEDa5c8b4
xDai,0x54a0A221C25Fc0a347EC929cFC5db0be17fA2a2B,0x561c5f3a19871ecb1273D6D8eCc276BeEDa5c8b4
Goerli,0x8bF6b979286970860Adc75dc621cf1969b0bE66C,0x0a04e23f95E9DB2Fe4C31252548F663fFe3AAe4d
Fantom,0x578a7Fee5f0D8CEc7d00578Bf37374C5b95C4b98,0xF9F7C1496c21bC0180f4B64daBE0754ebFc8A8c0
Avalanche,0xF9F7C1496c21bC0180f4B64daBE0754ebFc8A8c0,0x96c7D011cdFD467f551605f0f5Fce279F86F4186
Celo,0xab7b1be4233a04e5c43a810e75657eced8e5463b,0x96c7D011cdFD467f551605f0f5Fce279F86F4186
Kovan_optimistic,0x68EDbfA3E564C987FaaAB54f4FD1E7567D4151Dd,0x556F63d7467c729034585C3e50e54e582222b491
Optimistic,0x981be454a930479d92C91a0092D204b64845A5D6,0x02Ea0720254F7fa4eca7d09A1b9C783F1020EbEF
Optimism_kovan,0x68EDbfA3E564C987FaaAB54f4FD1E7567D4151Dd,0x556F63d7467c729034585C3e50e54e582222b491
Optimism,0x981be454a930479d92C91a0092D204b64845A5D6,0x02Ea0720254F7fa4eca7d09A1b9C783F1020EbEF
Aurora,0x19f179D7e0D7d9F9d5386afFF64271D98A91615B,0x05ee315E407C21a594f807D61d6CC11306D1F149
Fuse,0x561c5f3a19871ecb1273D6D8eCc276BeEDa5c8b4,0x066804d9123bF2609Ed4A4a40b1177a9c5a9Ed51
Boba,0x578a7Fee5f0D8CEc7d00578Bf37374C5b95C4b98,0xF9F7C1496c21bC0180f4B64daBE0754ebFc8A8c0
Moonriver,0x578a7Fee5f0D8CEc7d00578Bf37374C5b95C4b98,0xF9F7C1496c21bC0180f4B64daBE0754ebFc8A8c0
Conflux,0x96c7d011cdfd467f551605f0f5fce279f86f4186,0x5b966f3a32db9c180843bcb40267a66b73e4f022
Conflux_test,0x913975af2bb8a6be4100d7dc5e9765b77f6a5d6c,0x71834a3fdea3e70f14a93ed85c6be70925d0cad9
Conflux_espace,0x96c7d011cdfd467f551605f0f5fce279f86f4186,0x5b966f3a32db9c180843bcb40267a66b73e4f022
Conflux_espace_test,0x913975af2bb8a6be4100d7dc5e9765b77f6a5d6c,0x71834a3fdea3e70f14a93ed85c6be70925d0cad9
Harmony,0xab7b1be4233a04e5c43a810e75657eced8e5463b,0x83d6b366f21e413f214eb077d5378478e71a5ed2
Harmony_test,0x96c7d011cdfd467f551605f0f5fce279f86f4186,0x981be454a930479d92c91a0092d204b64845a5d6
Metis,0x2cf91AD8C175305EBe6970Bd8f81231585EFbd77,0x812463356F58fc8194645A1838ee6C52D8ca2D26
Metis_test,0xAb7B1bE4233A04e5C43a810E75657ECED8E5463B,0x2cf91AD8C175305EBe6970Bd8f81231585EFbd77
Metis_test,0xAb7B1bE4233A04e5C43a810E75657ECED8E5463B,0x2cf91AD8C175305EBe6970Bd8f81231585EFbd77
Kardia,0x081ea6437E73F3b4504b131443309404a9bC2054,0xc3e62b2CC70439C32a381Bfc056aCEd1d7162cef
2 changes: 1 addition & 1 deletion helper_scripts/generate-readme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ main();

function* makeTable(rows: DeployedAddressRow[]) {
yield "| Chain | HappyRedPacket | HappyRedPacket_ERC721 |";
yield "| - | :-: | :-: |";
yield "| - | - | - |";
for (const { Chain, HappyRedPacket, HappyRedPacket_ERC721 } of rows) {
const rpElement = formElement(HappyRedPacket, `rp-${Chain}`);
const nftRpElement = formElement(HappyRedPacket_ERC721, `rp721-${Chain}`);
Expand Down
22 changes: 12 additions & 10 deletions helper_scripts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,26 @@ export enum ChainId {
Rinkeby = 4,
BSC = 56,
Matic = 137,
Rinkeby_arbitrum = 421611,
Arbitrum_rinkeby = 421611,
Arbitrum = 42161,
Goerli = 5,
Fantom = 250,
Celo = 42220,
Avalanche = 43114,
Kovan_optimistic = 69,
Optimistic = 10,
Optimism_kovan = 69,
Optimism = 10,
Aurora = 1313161554,
Fuse = 122,
Boba = 288,
Moonriver = 1285,
Conflux_test = 71,
Conflux = 1030,
Conflux_espace_test = 71,
Conflux_espace = 1030,
Harmony = 1666600000,
Harmony_test = 1666700000,
Metis = 1088,
Metis_test = 28,
xDai = 100,
Kardia = 24,
}

function makeAddressDetailURL(domain: string) {
Expand All @@ -39,21 +40,22 @@ export const BlockExplorer: Record<ChainId, (address: string) => string> = {
[ChainId.Fantom]: makeAddressDetailURL("ftmscan.com"),
[ChainId.Celo]: makeAddressDetailURL("explorer.celo.org"),
[ChainId.Avalanche]: makeAddressDetailURL("snowtrace.io"),
[ChainId.Kovan_optimistic]: makeAddressDetailURL("kovan-optimistic.etherscan.io"),
[ChainId.Optimistic]: makeAddressDetailURL("optimistic.etherscan.io"),
[ChainId.Optimism_kovan]: makeAddressDetailURL("kovan-optimistic.etherscan.io"),
[ChainId.Optimism]: makeAddressDetailURL("optimistic.etherscan.io"),
[ChainId.Aurora]: makeAddressDetailURL("explorer.mainnet.aurora.dev"),
[ChainId.Fuse]: makeAddressDetailURL("explorer.fuse.io"),
[ChainId.Boba]: makeAddressDetailURL("blockexplorer.boba.network"),
[ChainId.Moonriver]: makeAddressDetailURL("moonriver.moonscan.io"),
[ChainId.Conflux_test]: makeAddressDetailURL("evmtestnet.confluxscan.io"),
[ChainId.Conflux]: makeAddressDetailURL("evm.confluxscan.io"),
[ChainId.Conflux_espace_test]: makeAddressDetailURL("evmtestnet.confluxscan.io"),
[ChainId.Conflux_espace]: makeAddressDetailURL("evm.confluxscan.io"),
[ChainId.Harmony]: makeAddressDetailURL("explorer.harmony.one"),
[ChainId.Harmony_test]: makeAddressDetailURL("explorer.pops.one"),
[ChainId.Metis]: makeAddressDetailURL("andromeda-explorer.metis.io"),
[ChainId.Metis_test]: makeAddressDetailURL("stardust-explorer.metis.io"),
[ChainId.xDai]: (address) => `https://blockscout.com/xdai/mainnet/address/${address}`,
[ChainId.Arbitrum]: makeAddressDetailURL("explorer.arbitrum.io"),
[ChainId.Rinkeby_arbitrum]: makeAddressDetailURL("rinkeby-explorer.arbitrum.io"),
[ChainId.Arbitrum_rinkeby]: makeAddressDetailURL("rinkeby-explorer.arbitrum.io"),
[ChainId.Kardia]: makeAddressDetailURL("explorer.kardiachain.io")
}

export type DeployedAddressRow = {
Expand Down
Loading