Skip to content

Commit 380564d

Browse files
Merge pull request #52 from DimensionDev/support_kardia
add support for kardia chain
2 parents 0e66cc8 + 3715f64 commit 380564d

10 files changed

+300
-288
lines changed

README.md

Lines changed: 138 additions & 135 deletions
Large diffs are not rendered by default.

contracts/redpacket.sol

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
**/
1010

1111
pragma solidity >= 0.8.0;
12-
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
13-
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
12+
import "@openzeppelin/contracts-upgradeable/token/ERC20/utils/SafeERC20Upgradeable.sol";
1413
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
1514
import "@openzeppelin/contracts/proxy/utils/Initializable.sol";
1615
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
@@ -56,7 +55,7 @@ contract HappyRedPacket is Initializable {
5655
uint remaining_balance
5756
);
5857

59-
using SafeERC20 for IERC20;
58+
using SafeERC20Upgradeable for IERC20Upgradeable;
6059
uint32 nonce;
6160
mapping(bytes32 => RedPacket) redpacket_by_id;
6261
bytes32 private seed;
@@ -84,9 +83,9 @@ contract HappyRedPacket is Initializable {
8483
else if (_token_type == 1) {
8584
// https://github.com/DimensionDev/Maskbook/issues/4168
8685
// `received_amount` is not necessarily equal to `_total_tokens`
87-
uint256 balance_before_transfer = IERC20(_token_addr).balanceOf(address(this));
88-
IERC20(_token_addr).safeTransferFrom(msg.sender, address(this), _total_tokens);
89-
uint256 balance_after_transfer = IERC20(_token_addr).balanceOf(address(this));
86+
uint256 balance_before_transfer = IERC20Upgradeable(_token_addr).balanceOf(address(this));
87+
IERC20Upgradeable(_token_addr).safeTransferFrom(msg.sender, address(this), _total_tokens);
88+
uint256 balance_after_transfer = IERC20Upgradeable(_token_addr).balanceOf(address(this));
9089
received_amount = balance_after_transfer.sub(balance_before_transfer);
9190
require(received_amount >= _number, "#received > #packets");
9291
}
@@ -271,7 +270,7 @@ contract HappyRedPacket is Initializable {
271270
}
272271

273272
function transfer_token(address token_address, address recipient_address, uint amount) internal{
274-
IERC20(token_address).safeTransfer(recipient_address, amount);
273+
IERC20Upgradeable(token_address).safeTransfer(recipient_address, amount);
275274
}
276275

277276
// A boring wrapper

deploy/erc721_support.ts

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,21 @@
1-
import { HardhatRuntimeEnvironment } from 'hardhat/types'
2-
import { DeployFunction } from 'hardhat-deploy/types'
3-
import { ethers, upgrades } from 'hardhat'
1+
import { HardhatRuntimeEnvironment } from 'hardhat/types';
2+
import { DeployFunction } from 'hardhat-deploy/types';
3+
import { ethers, upgrades } from 'hardhat';
4+
import fs from "fs/promises";
5+
import path from "path";
6+
import { parse } from "csv-parse/sync";
47

5-
type MyMapLikeType = Record<string, string>
6-
const deployedContracts: MyMapLikeType = {
7-
mainnet: '0x8d285739523FC2Ac8eC9c9C229ee863C8C9bF8C8',
8-
ropsten: '0x8fF42e93C19E44763FD1cD07b9E04d13bA07AD3f',
9-
bsc_mainnet: '0xf8968e1Fcf1440Be5Cec7Bb495bcee79753d5E06',
10-
matic_mainnet: '0xf6Dc042717EF4C097348bE00f4BaE688dcaDD4eA',
11-
arbitrum: '0x561c5f3a19871ecb1273D6D8eCc276BeEDa5c8b4',
12-
xdai: '0x561c5f3a19871ecb1273D6D8eCc276BeEDa5c8b4',
13-
goerli: '0x0a04e23f95E9DB2Fe4C31252548F663fFe3AAe4d',
14-
fantom: '0xF9F7C1496c21bC0180f4B64daBE0754ebFc8A8c0',
15-
avalanche: '0x96c7D011cdFD467f551605f0f5Fce279F86F4186',
16-
celo: '0x96c7D011cdFD467f551605f0f5Fce279F86F4186',
17-
optimism: '0x02Ea0720254F7fa4eca7d09A1b9C783F1020EbEF',
18-
optimism_kovan: '0x556F63d7467c729034585C3e50e54e582222b491',
19-
aurora: '0x05ee315E407C21a594f807D61d6CC11306D1F149',
20-
fuse: '0x066804d9123bF2609Ed4A4a40b1177a9c5a9Ed51',
21-
boba: '0xF9F7C1496c21bC0180f4B64daBE0754ebFc8A8c0',
22-
moonriver: '0xF9F7C1496c21bC0180f4B64daBE0754ebFc8A8c0',
23-
conflux_eSpace: '0x5b966f3a32db9c180843bcb40267a66b73e4f022',
24-
conflux_eSpace_test: '0x71834a3fdea3e70f14a93ed85c6be70925d0cad9',
25-
harmony: '0x83d6b366f21e413f214eb077d5378478e71a5ed2',
26-
metis: '0x812463356F58fc8194645A1838ee6C52D8ca2D26',
27-
}
8+
const ADDRESS_TABLE_PATH = path.resolve(__dirname, "..", "helper_scripts", "contract-addresses.csv");
289

2910
const func: DeployFunction = async function(hre: HardhatRuntimeEnvironment) {
3011
const { deployments, getNamedAccounts } = hre
3112
const { deploy } = deployments
3213
const { deployer } = await getNamedAccounts()
3314
const network: string = hre.hardhatArguments.network ? hre.hardhatArguments.network : 'ropsten'
15+
const deployedContracts = await loadDeployedAddress();
3416
const proxyAddress = deployedContracts[network]
3517

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

47+
async function loadDeployedAddress(): Promise<Record<string, string>> {
48+
const data = await fs.readFile(ADDRESS_TABLE_PATH, "utf-8");
49+
const columns = ['Chain', 'HappyRedPacket', 'HappyRedPacket_ERC721'];
50+
const records = parse(data, { delimiter: ',', columns, from: 2 });
51+
let deployedContract: Record<string, string> = {};
52+
for (const { Chain, HappyRedPacket_ERC721 } of records) {
53+
deployedContract[Chain.toLowerCase()] = HappyRedPacket_ERC721;
54+
}
55+
return deployedContract;
56+
}
57+
6558
func.tags = ['HappyRedPacket_ERC721']
6659

6760
module.exports = func

deploy/redpacket.ts

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,21 @@
1-
import { HardhatRuntimeEnvironment } from 'hardhat/types'
2-
import { DeployFunction } from 'hardhat-deploy/types'
3-
import { ethers, upgrades } from 'hardhat'
1+
import { HardhatRuntimeEnvironment } from 'hardhat/types';
2+
import { DeployFunction } from 'hardhat-deploy/types';
3+
import { ethers, upgrades } from 'hardhat';
4+
import fs from "fs/promises";
5+
import path from "path";
6+
import { parse } from "csv-parse/sync";
47

5-
type MyMapLikeType = Record<string, string>
6-
const deployedContracts: MyMapLikeType = {
7-
mainnet: '0xaBBe1101FD8fa5847c452A6D70C8655532B03C33',
8-
ropsten: '0x0722507c3b776A6B205946592016e358B0D34c3F',
9-
bsc_mainnet: '0x0ca42C178e14c618c81B8438043F27d9D38145f6',
10-
matic_mainnet: '0x93e0b87A0aD0C991dc1B5176ddCD850c9a78aabb',
11-
arbitrum: '0x83D6b366f21e413f214EB077D5378478e71a5eD2',
12-
arbitrum_rinkeby: '0x4A77E797031257db72F7D2C3Ec08a4FAc5c8CfE9',
13-
xdai: '0x54a0A221C25Fc0a347EC929cFC5db0be17fA2a2B',
14-
goerli: '0x8bF6b979286970860Adc75dc621cf1969b0bE66C',
15-
fantom: '0x578a7Fee5f0D8CEc7d00578Bf37374C5b95C4b98',
16-
avalanche: '0xF9F7C1496c21bC0180f4B64daBE0754ebFc8A8c0',
17-
celo: '0x871F2635EeB0bA3D9f90C4524E3f148C31393F9d',
18-
optimism: '0x981be454a930479d92C91a0092D204b64845A5D6',
19-
optimism_kovan: '0x68EDbfA3E564C987FaaAB54f4FD1E7567D4151Dd',
20-
aurora: '0x19f179D7e0D7d9F9d5386afFF64271D98A91615B',
21-
fuse: '0x561c5f3a19871ecb1273D6D8eCc276BeEDa5c8b4',
22-
boba: '0x578a7Fee5f0D8CEc7d00578Bf37374C5b95C4b98',
23-
moonriver: '0x578a7Fee5f0D8CEc7d00578Bf37374C5b95C4b98',
24-
conflux_eSpace: '0x96c7d011cdfd467f551605f0f5fce279f86f4186',
25-
conflux_eSpace_test: '0x913975af2bb8a6be4100d7dc5e9765b77f6a5d6c',
26-
harmony: '0xab7b1be4233a04e5c43a810e75657eced8e5463b',
27-
metis: '0x2cf91AD8C175305EBe6970Bd8f81231585EFbd77',
28-
}
8+
const ADDRESS_TABLE_PATH = path.resolve(__dirname, "..", "helper_scripts", "contract-addresses.csv");
299

3010
const func: DeployFunction = async function(hre: HardhatRuntimeEnvironment) {
3111
const { deployments, getNamedAccounts } = hre
3212
const { deploy } = deployments
3313
const { deployer } = await getNamedAccounts()
3414
const network: string = hre.hardhatArguments.network ? hre.hardhatArguments.network : 'ropsten'
15+
const deployedContracts = await loadDeployedAddress();
3516
const proxyAddress = deployedContracts[network]
36-
37-
if (false) {
17+
18+
if (true) {
3819
// deploy, we normally do this only once
3920
const HappyRedPacketImpl = await ethers.getContractFactory('HappyRedPacket')
4021
const HappyRedPacketProxy = await upgrades.deployProxy(HappyRedPacketImpl, [])
@@ -63,6 +44,17 @@ const func: DeployFunction = async function(hre: HardhatRuntimeEnvironment) {
6344
}
6445
}
6546

47+
async function loadDeployedAddress(): Promise<Record<string, string>> {
48+
const data = await fs.readFile(ADDRESS_TABLE_PATH, "utf-8");
49+
const columns = ['Chain', 'HappyRedPacket', 'HappyRedPacket_ERC721'];
50+
const records = parse(data, { delimiter: ',', columns, from: 2 });
51+
let deployedContract: Record<string, string> = {};
52+
for (const { Chain, HappyRedPacket } of records) {
53+
deployedContract[Chain.toLowerCase()] = HappyRedPacket;
54+
}
55+
return deployedContract;
56+
}
57+
6658
func.tags = ['HappyRedPacket']
6759

6860
module.exports = func

helper_scripts/contract-addresses.csv

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@ Mainnet,0xaBBe1101FD8fa5847c452A6D70C8655532B03C33,0x8d285739523FC2Ac8eC9c9C229e
33
Ropsten,0x0722507c3b776A6B205946592016e358B0D34c3F,0x8fF42e93C19E44763FD1cD07b9E04d13bA07AD3f
44
BSC,0x0ca42C178e14c618c81B8438043F27d9D38145f6,0xf8968e1Fcf1440Be5Cec7Bb495bcee79753d5E06
55
Matic,0x93e0b87A0aD0C991dc1B5176ddCD850c9a78aabb,0xf6Dc042717EF4C097348bE00f4BaE688dcaDD4eA
6-
Rinkeby_arbitrum,0x4A77E797031257db72F7D2C3Ec08a4FAc5c8CfE9,
6+
Arbitrum_rinkeby,0x4A77E797031257db72F7D2C3Ec08a4FAc5c8CfE9,
77
Arbitrum,0x83D6b366f21e413f214EB077D5378478e71a5eD2,0x561c5f3a19871ecb1273D6D8eCc276BeEDa5c8b4
88
xDai,0x54a0A221C25Fc0a347EC929cFC5db0be17fA2a2B,0x561c5f3a19871ecb1273D6D8eCc276BeEDa5c8b4
99
Goerli,0x8bF6b979286970860Adc75dc621cf1969b0bE66C,0x0a04e23f95E9DB2Fe4C31252548F663fFe3AAe4d
1010
Fantom,0x578a7Fee5f0D8CEc7d00578Bf37374C5b95C4b98,0xF9F7C1496c21bC0180f4B64daBE0754ebFc8A8c0
1111
Avalanche,0xF9F7C1496c21bC0180f4B64daBE0754ebFc8A8c0,0x96c7D011cdFD467f551605f0f5Fce279F86F4186
1212
Celo,0xab7b1be4233a04e5c43a810e75657eced8e5463b,0x96c7D011cdFD467f551605f0f5Fce279F86F4186
13-
Kovan_optimistic,0x68EDbfA3E564C987FaaAB54f4FD1E7567D4151Dd,0x556F63d7467c729034585C3e50e54e582222b491
14-
Optimistic,0x981be454a930479d92C91a0092D204b64845A5D6,0x02Ea0720254F7fa4eca7d09A1b9C783F1020EbEF
13+
Optimism_kovan,0x68EDbfA3E564C987FaaAB54f4FD1E7567D4151Dd,0x556F63d7467c729034585C3e50e54e582222b491
14+
Optimism,0x981be454a930479d92C91a0092D204b64845A5D6,0x02Ea0720254F7fa4eca7d09A1b9C783F1020EbEF
1515
Aurora,0x19f179D7e0D7d9F9d5386afFF64271D98A91615B,0x05ee315E407C21a594f807D61d6CC11306D1F149
1616
Fuse,0x561c5f3a19871ecb1273D6D8eCc276BeEDa5c8b4,0x066804d9123bF2609Ed4A4a40b1177a9c5a9Ed51
1717
Boba,0x578a7Fee5f0D8CEc7d00578Bf37374C5b95C4b98,0xF9F7C1496c21bC0180f4B64daBE0754ebFc8A8c0
1818
Moonriver,0x578a7Fee5f0D8CEc7d00578Bf37374C5b95C4b98,0xF9F7C1496c21bC0180f4B64daBE0754ebFc8A8c0
19-
Conflux,0x96c7d011cdfd467f551605f0f5fce279f86f4186,0x5b966f3a32db9c180843bcb40267a66b73e4f022
20-
Conflux_test,0x913975af2bb8a6be4100d7dc5e9765b77f6a5d6c,0x71834a3fdea3e70f14a93ed85c6be70925d0cad9
19+
Conflux_espace,0x96c7d011cdfd467f551605f0f5fce279f86f4186,0x5b966f3a32db9c180843bcb40267a66b73e4f022
20+
Conflux_espace_test,0x913975af2bb8a6be4100d7dc5e9765b77f6a5d6c,0x71834a3fdea3e70f14a93ed85c6be70925d0cad9
2121
Harmony,0xab7b1be4233a04e5c43a810e75657eced8e5463b,0x83d6b366f21e413f214eb077d5378478e71a5ed2
2222
Harmony_test,0x96c7d011cdfd467f551605f0f5fce279f86f4186,0x981be454a930479d92c91a0092d204b64845a5d6
2323
Metis,0x2cf91AD8C175305EBe6970Bd8f81231585EFbd77,0x812463356F58fc8194645A1838ee6C52D8ca2D26
24-
Metis_test,0xAb7B1bE4233A04e5C43a810E75657ECED8E5463B,0x2cf91AD8C175305EBe6970Bd8f81231585EFbd77
24+
Metis_test,0xAb7B1bE4233A04e5C43a810E75657ECED8E5463B,0x2cf91AD8C175305EBe6970Bd8f81231585EFbd77
25+
Kardia,0x081ea6437E73F3b4504b131443309404a9bC2054,0xc3e62b2CC70439C32a381Bfc056aCEd1d7162cef

helper_scripts/generate-readme.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ main();
2626

2727
function* makeTable(rows: DeployedAddressRow[]) {
2828
yield "| Chain | HappyRedPacket | HappyRedPacket_ERC721 |";
29-
yield "| - | :-: | :-: |";
29+
yield "| - | - | - |";
3030
for (const { Chain, HappyRedPacket, HappyRedPacket_ERC721 } of rows) {
3131
const rpElement = formElement(HappyRedPacket, `rp-${Chain}`);
3232
const nftRpElement = formElement(HappyRedPacket_ERC721, `rp721-${Chain}`);

helper_scripts/types.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,26 @@ export enum ChainId {
44
Rinkeby = 4,
55
BSC = 56,
66
Matic = 137,
7-
Rinkeby_arbitrum = 421611,
7+
Arbitrum_rinkeby = 421611,
88
Arbitrum = 42161,
99
Goerli = 5,
1010
Fantom = 250,
1111
Celo = 42220,
1212
Avalanche = 43114,
13-
Kovan_optimistic = 69,
14-
Optimistic = 10,
13+
Optimism_kovan = 69,
14+
Optimism = 10,
1515
Aurora = 1313161554,
1616
Fuse = 122,
1717
Boba = 288,
1818
Moonriver = 1285,
19-
Conflux_test = 71,
20-
Conflux = 1030,
19+
Conflux_espace_test = 71,
20+
Conflux_espace = 1030,
2121
Harmony = 1666600000,
2222
Harmony_test = 1666700000,
2323
Metis = 1088,
2424
Metis_test = 28,
2525
xDai = 100,
26+
Kardia = 24,
2627
}
2728

2829
function makeAddressDetailURL(domain: string) {
@@ -39,21 +40,22 @@ export const BlockExplorer: Record<ChainId, (address: string) => string> = {
3940
[ChainId.Fantom]: makeAddressDetailURL("ftmscan.com"),
4041
[ChainId.Celo]: makeAddressDetailURL("explorer.celo.org"),
4142
[ChainId.Avalanche]: makeAddressDetailURL("snowtrace.io"),
42-
[ChainId.Kovan_optimistic]: makeAddressDetailURL("kovan-optimistic.etherscan.io"),
43-
[ChainId.Optimistic]: makeAddressDetailURL("optimistic.etherscan.io"),
43+
[ChainId.Optimism_kovan]: makeAddressDetailURL("kovan-optimistic.etherscan.io"),
44+
[ChainId.Optimism]: makeAddressDetailURL("optimistic.etherscan.io"),
4445
[ChainId.Aurora]: makeAddressDetailURL("explorer.mainnet.aurora.dev"),
4546
[ChainId.Fuse]: makeAddressDetailURL("explorer.fuse.io"),
4647
[ChainId.Boba]: makeAddressDetailURL("blockexplorer.boba.network"),
4748
[ChainId.Moonriver]: makeAddressDetailURL("moonriver.moonscan.io"),
48-
[ChainId.Conflux_test]: makeAddressDetailURL("evmtestnet.confluxscan.io"),
49-
[ChainId.Conflux]: makeAddressDetailURL("evm.confluxscan.io"),
49+
[ChainId.Conflux_espace_test]: makeAddressDetailURL("evmtestnet.confluxscan.io"),
50+
[ChainId.Conflux_espace]: makeAddressDetailURL("evm.confluxscan.io"),
5051
[ChainId.Harmony]: makeAddressDetailURL("explorer.harmony.one"),
5152
[ChainId.Harmony_test]: makeAddressDetailURL("explorer.pops.one"),
5253
[ChainId.Metis]: makeAddressDetailURL("andromeda-explorer.metis.io"),
5354
[ChainId.Metis_test]: makeAddressDetailURL("stardust-explorer.metis.io"),
5455
[ChainId.xDai]: (address) => `https://blockscout.com/xdai/mainnet/address/${address}`,
5556
[ChainId.Arbitrum]: makeAddressDetailURL("explorer.arbitrum.io"),
56-
[ChainId.Rinkeby_arbitrum]: makeAddressDetailURL("rinkeby-explorer.arbitrum.io"),
57+
[ChainId.Arbitrum_rinkeby]: makeAddressDetailURL("rinkeby-explorer.arbitrum.io"),
58+
[ChainId.Kardia]: makeAddressDetailURL("explorer.kardiachain.io")
5759
}
5860

5961
export type DeployedAddressRow = {

0 commit comments

Comments
 (0)