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 5 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 addOwner --addr "${ADDR}")
izyak marked this conversation as resolved.
Show resolved Hide resolved
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 @@
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);

Check warning on line 282 in javascore/bts/src/main/java/foundation/icon/btp/bts/BTPTokenService.java

View check run for this annotation

Codecov / codecov/patch

javascore/bts/src/main/java/foundation/icon/btp/bts/BTPTokenService.java#L281-L282

Added lines #L281 - L282 were not covered by tests
Context.require(tokenAddr != null, "Token not registered");
Context.call(ZERO_SCORE_ADDRESS, "setScoreOwner", tokenAddr, to);
}

Check warning on line 285 in javascore/bts/src/main/java/foundation/icon/btp/bts/BTPTokenService.java

View check run for this annotation

Codecov / codecov/patch

javascore/bts/src/main/java/foundation/icon/btp/bts/BTPTokenService.java#L284-L285

Added lines #L284 - L285 were not covered by tests

/**
* Add users to blacklist on certain networks
* Maintains information of all addresses blacklisted on all chains
Expand Down Expand Up @@ -484,6 +498,12 @@
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);

Check warning on line 504 in javascore/bts/src/main/java/foundation/icon/btp/bts/BTPTokenService.java

View check run for this annotation

Codecov / codecov/patch

javascore/bts/src/main/java/foundation/icon/btp/bts/BTPTokenService.java#L503-L504

Added lines #L503 - L504 were not covered by tests
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 @@
@Payable
@External
public void transferNativeCoin(String _to) {

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

Check warning on line 572 in javascore/bts/src/main/java/foundation/icon/btp/bts/BTPTokenService.java

View check run for this annotation

Codecov / codecov/patch

javascore/bts/src/main/java/foundation/icon/btp/bts/BTPTokenService.java#L572

Added line #L572 was not covered by tests

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

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

// icon bridge migration checks
requireNotEth(_coinName);
Coin coin = coinDb.get(_coinName);

Check warning on line 609 in javascore/bts/src/main/java/foundation/icon/btp/bts/BTPTokenService.java

View check run for this annotation

Codecov / codecov/patch

javascore/bts/src/main/java/foundation/icon/btp/bts/BTPTokenService.java#L608-L609

Added lines #L608 - L609 were not covered by tests
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 @@

int tempLen = len;
if (icxValue != null && icxValue.compareTo(BigInteger.ZERO) > 0) {
Context.revert("Cannot transfer ICX.");

Check warning on line 645 in javascore/bts/src/main/java/foundation/icon/btp/bts/BTPTokenService.java

View check run for this annotation

Codecov / codecov/patch

javascore/bts/src/main/java/foundation/icon/btp/bts/BTPTokenService.java#L645

Added line #L645 was not covered by tests
tempLen = tempLen + 1;
checkTokenLimit(name, icxValue);
coinNameList.add(name);
Expand All @@ -629,6 +659,12 @@
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 @@
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