Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: icon bridge migration #872

Merged
merged 6 commits into from
Apr 25, 2024
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
7 changes: 6 additions & 1 deletion devnet/docker/icon-bsc/scripts/bts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const BTSCore = artifacts.require("BTSCore");
const BTSCore = artifacts.require("BTSCoreV5");
const BTSOwnerManager = artifacts.require("BTSOwnerManager");
module.exports = async function (callback) {
try {
Expand Down Expand Up @@ -27,6 +27,11 @@ module.exports = async function (callback) {
tx = await btsCore.updateCoinDb()
console.log(tx)
break;
case "moveLockedEth":
console.log("Move Locked Eth ", argv.addr)
tx = await btsCore.moveLockedEth(argv.addr)
console.log(tx)
break;
case "addOwner":
console.log("Add bts owner ", argv.addr)
tx = await btsOwnerManager.addOwner(argv.addr)
Expand Down
21 changes: 21 additions & 0 deletions devnet/docker/icon-bsc/scripts/migrate_locked_eth.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

set -e

source config.sh
source rpc.sh

export PRIVATE_KEY="[\""$(cat $BSC_KEY_STORE.priv)"\"]"

# Address to transfer the funds to
ADDR=0x69e81Cea7889608A63947814893ad1B86DcC03Aa

moveLockedEth() {
echo "transferring all locked ETH to ${ADDR}"
cd $CONTRACTS_DIR/solidity/bmc
tx=$(truffle exec --network bsc "$SCRIPTS_DIR"/bts.js \
--method moveLockedEth --addr "${ADDR}")
echo "$tx" >$CONFIG_DIR/tx/moveLockedEth.bts.bsc
}

moveLockedEth
28 changes: 28 additions & 0 deletions devnet/docker/icon-bsc/scripts/transfer_icon_eth_ownership.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

set -e

source config.sh
source rpc.sh

# Address of new owner of ETH token on ICON
ADDR=hx80e312d8e68ee2db8fb95e6e7daae2e770d0e368

transferEthOwnership() {
cd $CONFIG_DIR

if [ ! -f icon.addr.bts ]; then
echo "BTS address file icon.addr.bts does not exist"
exit
fi

goloop rpc sendtx call --to $(cat icon.addr.bts) \
--method transferOwnership \
--param _name=btp-0x38.bsc-ETH \
--param to=${ADDR} | jq -r . >tx/transferTokenOwnership.icon
sleep 3
ensure_txresult tx/transferTokenOwnership.icon
echo "Ownership of ETH transferred to ${ADDR} "
}

transferEthOwnership
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,20 @@ public BigInteger getSn() {
return sn.get();
}

/**
* Transfer ownership of token contract to somewhere else
*
* @param _name Reegistered name of the token
* @param to New owner
*/
@External
public void transferOwnership(String _name, Address to) {
requireOwnerAccess();
Address tokenAddr = coinAddresses.get(_name);
Context.require(tokenAddr != null, "Token not registered");
Context.call(ZERO_SCORE_ADDRESS, "setScoreOwner", tokenAddr, to);
}

/**
* Add users to blacklist on certain networks
* Maintains information of all addresses blacklisted on all chains
Expand Down Expand Up @@ -484,6 +498,12 @@ public void tokenFallback(Address _from, BigInteger _value, byte[] _data) {
checkUintLimit(_value);
String _coinName = coinAddressName.get(Context.getCaller());
if (_coinName != null && !Context.getAddress().equals(_from)) {

// icon bridge migration checks
requireNotEth(_coinName);
Coin coin = coinDb.get(_coinName);
require(coin.getCoinType() == NATIVE_WRAPPED_COIN_TYPE, "Cannnot transfer icon tokens anymore.");

Context.require(coinAddresses.get(_coinName) != null, "CoinNotExists");
Balance _userBalance = getBalance(_coinName, _from);
_userBalance.setUsable(_userBalance.getUsable().add(_value));
Expand Down Expand Up @@ -547,6 +567,10 @@ public void reclaim(String _coinName, BigInteger _value) {
@Payable
@External
public void transferNativeCoin(String _to) {

// icon bridge migration checks
Context.revert("Cannot transfer ICX.");

Context.require(_to.length() < 100, "Length Check");

BigInteger value = Context.getValue();
Expand Down Expand Up @@ -580,6 +604,11 @@ public void transfer(String _coinName, BigInteger _value, String _to) {
require(isRegistered(_coinName), "Not supported Token");
Context.require(_to.length() < 100, "Length Check");

// icon bridge migration checks
requireNotEth(_coinName);
Coin coin = coinDb.get(_coinName);
require(coin.getCoinType() == NATIVE_WRAPPED_COIN_TYPE, "Cannnot transfer icon tokens anymore.");

Address owner = Context.getCaller();
BTPAddress to = BTPAddress.valueOf(_to);
checkRestrictions(_coinName, Context.getCaller().toString(), to, _value);
Expand Down Expand Up @@ -613,6 +642,7 @@ public void transferBatch(String[] _coinNames, BigInteger[] _values, String _to)

int tempLen = len;
if (icxValue != null && icxValue.compareTo(BigInteger.ZERO) > 0) {
Context.revert("Cannot transfer ICX.");
tempLen = tempLen + 1;
checkTokenLimit(name, icxValue);
coinNameList.add(name);
Expand All @@ -629,6 +659,12 @@ public void transferBatch(String[] _coinNames, BigInteger[] _values, String _to)
for (int i = 0; i < len; i++) {
String coinName = _coinNames[i];
BigInteger value = _values[i];

// icon bridge migration checks
requireNotEth(coinName);
Coin coin = coinDb.get(coinName);
require(coin.getCoinType() == NATIVE_WRAPPED_COIN_TYPE, "Cannnot transfer icon tokens anymore.");

require(!name.equals(coinName) && this.coinNames.contains(coinName), "Not supported Token");
require(value != null && value.compareTo(BigInteger.ZERO) > 0, "Invalid amount");
checkUintLimit(value);
Expand Down Expand Up @@ -1501,4 +1537,8 @@ private void checkUintLimit(BigInteger value) {
require(UINT_CAP.compareTo(value) >= 0, "Value cannot exceed uint(256)-1");
}

private void requireNotEth(String name) {
String ethName = "btp-0x38.bsc-ETH";
require(!name.equals(ethName), "NotETH");
}
}
Loading
Loading