Skip to content

Commit 19ef4d6

Browse files
committed
feat: deployed DATAv2onPolygon
needed to add special hooks for the polygon-ethereum bridge: deposit for minting on polygon, withdraw for burning on polygon.
1 parent 5a89fde commit 19ef4d6

File tree

3 files changed

+66
-8
lines changed

3 files changed

+66
-8
lines changed

contracts/DATAv2.sol

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,12 @@ contract DATAv2 is ERC20Permit, ERC20Burnable, AccessControl, IERC677 {
7676
// ------------------------------------------------------------------------
7777
// allow admin to change the token name and symbol
7878

79-
function setTokenInformation(string calldata newName, string calldata newSymbol) public {
79+
modifier onlyAdmin {
8080
require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()), "Transaction signer is not an admin");
81+
_;
82+
}
83+
84+
function setTokenInformation(string calldata newName, string calldata newSymbol) public onlyAdmin {
8185
_name = newName;
8286
_symbol = newSymbol;
8387
emit UpdatedTokenInformation(_name, _symbol);

contracts/DATAv2onPolygon.sol

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.8.6;
3+
4+
import "./DATAv2.sol";
5+
6+
/**
7+
* Version of DATAv2 that fulfills the requirements in https://docs.polygon.technology/docs/develop/ethereum-polygon/pos/mapping-assets/
8+
*/
9+
contract DATAv2onPolygon is DATAv2 {
10+
address public bridgeAddress;
11+
12+
constructor(address initialBridgeAddress) DATAv2() {
13+
setBridgeAddress(initialBridgeAddress);
14+
}
15+
16+
///@dev docs say: being proxified smart contract, most probably bridge addreess is not going to change ever, but... just in case
17+
function setBridgeAddress(address newBridgeAddress) public onlyAdmin {
18+
bridgeAddress = newBridgeAddress;
19+
}
20+
21+
/**
22+
* When tokens are bridged from mainnet, perform a "mind-and-call" to activate
23+
* the receiving contract's ERC677 onTokenTransfer callback
24+
* Equal amount of tokens got locked in RootChainManager on the mainnet side
25+
*/
26+
function deposit(address user, bytes calldata depositData) external {
27+
require(msg.sender == bridgeAddress, "error_onlyBridge");
28+
uint256 amount = abi.decode(depositData, (uint256));
29+
_mint(address(this), amount);
30+
transferAndCall(user, amount, depositData);
31+
}
32+
33+
/**
34+
* When returning to mainnet, it's enough to simply burn the tokens on the Polygon side
35+
*/
36+
function withdraw(uint256 amount) external {
37+
_burn(msg.sender, amount);
38+
}
39+
}

scripts/deploy-without-migrator.js

100644100755
Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1-
const { ContractFactory, Wallet, providers: { JsonRpcProvider }, utils: { id } } = require("ethers")
1+
#!/usr/bin/env node
2+
3+
// Binance Smart Chain
4+
const providerUrl = "https://bsc-dataseed.binance.org/"
5+
const explorerUrl = "https://bscscan.com/tx"
26

7+
// Matic's Polygon
8+
// const providerUrl = "https://polygon-rpc.com"
9+
// const explorerUrl = "https://polygonscan.com/tx"
10+
11+
// Plain token, same as mainnet
312
const DATAv2Json = require("../artifacts/contracts/DATAv2.sol/DATAv2.json")
413

5-
const { KEY } = process.env
14+
// Matic's Polygon wants a special token for the bridge
15+
// const DATAv2Json = require("../artifacts/contracts/DATAv2onPolygon.sol/DATAv2onPolygon.json")
616

17+
18+
const { ContractFactory, Wallet, providers: { JsonRpcProvider }, utils: { id } } = require("ethers")
19+
20+
const { KEY } = process.env
721
if (!KEY) { throw new Error("Please provide env variable KEY") }
822

9-
const provider = new JsonRpcProvider("https://bsc-dataseed.binance.org/")
23+
const provider = new JsonRpcProvider(providerUrl)
1024
const deployer = new Wallet(KEY, provider)
1125
console.log("Deploying contracts from %s", deployer.address)
1226

@@ -15,19 +29,20 @@ const adminAddress = "0x42355e7dc0A872C465bE9DE4AcAAAcB5709Ce813"
1529
async function main() {
1630

1731
const DATAv2 = new ContractFactory(DATAv2Json.abi, DATAv2Json.bytecode, deployer)
18-
const token = await DATAv2.deploy()
19-
console.log("Follow deployment: https://bscscan.com/tx/%s", token.deployTransaction.hash)
32+
const token = await DATAv2.deploy() // plain token
33+
// const token = await DATAv2.deploy("0xA6FA4fB5f76172d178d61B04b0ecd319C5d1C0aa") // Matic's Polygon version of the token
34+
console.log("Follow deployment: %s/%s", explorerUrl, token.deployTransaction.hash)
2035

2136
await token.deployed()
2237
console.log("DATAv2 deployed to:", token.address)
2338

2439
const tx1 = await token.grantRole(id("MINTER_ROLE"), adminAddress)
25-
console.log("Follow grant minter tx: https://bscscan.com/tx/%s", tx1.hash)
40+
console.log("Follow grant minter tx: %s/%s", explorerUrl, tx1.hash)
2641
const tr1 = await tx1.wait()
2742
console.log("Transaction receipt: ", tr1)
2843

2944
const tx2 = await token.grantRole("0x0000000000000000000000000000000000000000000000000000000000000000", adminAddress)
30-
console.log("Follow grant admin tx: https://bscscan.com/tx/%s", tx2.hash)
45+
console.log("Follow grant admin tx: %s/%s", explorerUrl, tx2.hash)
3146
const tr2 = await tx2.wait()
3247
console.log("Transaction receipt: ", tr2)
3348
}

0 commit comments

Comments
 (0)