Skip to content

Commit

Permalink
Rename wnom -> bnom
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitryhil committed Jun 2, 2022
1 parent cad7c47 commit ad4720f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 36 deletions.
14 changes: 7 additions & 7 deletions solidity/contract-deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const args = commandLineArgs([
{ name: "test-mode", type: String },
// remote mode, if enabled this script does not deploy the Gravity contract
{ name: "remote-mode", type: String },
// the wnom ERC20 address which will be used for burning in the send to cosmos Gravity contracts function
{ name: "wnom-address", type: String },
// the bnom ERC20 address which will be used for burning in the send to cosmos Gravity contracts function
{ name: "bnom-address", type: String },
]);

// 4. Now, the deployer script hits a full node api, gets the Eth signatures of the valset from the latest block, and deploys the Ethereum contract.
Expand Down Expand Up @@ -219,20 +219,20 @@ async function deploy() {
}
}

let wnomAddressArg = args["wnom-address"]
if (wnomAddressArg == null) {
wnomAddressArg = "0x0000000000000000000000000000000000000000"
let bnomAddressArg = args["bnom-address"]
if (bnomAddressArg == null) {
bnomAddressArg = "0x0000000000000000000000000000000000000000"
}

let wnomAddress = ethers.utils.getAddress(wnomAddressArg)
let bnomAddress = ethers.utils.getAddress(bnomAddressArg)

const gravity = (await factory.deploy(
// todo generate this randomly at deployment time that way we can avoid
// anything but intentional conflicts
gravityId,
eth_addresses,
powers,
wnomAddress,
bnomAddress,
overrides
)) as Gravity;

Expand Down
18 changes: 9 additions & 9 deletions solidity/contracts/Gravity.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ contract Gravity is ReentrancyGuard {
// update or batch execution, set to 2/3 of 2^32
uint256 constant constant_powerThreshold = 2863311530;

// Address for wNOM
address public wNomAddress;
IERC20Burnable private wNomBurner;
// Address for bNOM
address public bNomAddress;
IERC20Burnable private bNomBurner;

// These are updated often
bytes32 public state_lastValsetCheckpoint;
Expand Down Expand Up @@ -596,9 +596,9 @@ contract Gravity is ReentrancyGuard {

state_lastEventNonce = state_lastEventNonce + 1;

// If Token is wNOM then Burn it
if (_tokenContract == wNomAddress) {
wNomBurner.burn(_amount);
// If Token is bNOM then Burn it
if (_tokenContract == bNomAddress) {
bNomBurner.burn(_amount);
}

// emit to Cosmos the actual amount our balance has changed, rather than the user
Expand Down Expand Up @@ -641,11 +641,11 @@ contract Gravity is ReentrancyGuard {
// arguments would never be used in this case
address[] memory _validators,
uint256[] memory _powers,
address _wNomAddress
address _bNomAddress
) {
// Initialize NOM burner
wNomAddress = _wNomAddress;
wNomBurner = IERC20Burnable(_wNomAddress);
bNomAddress = _bNomAddress;
bNomBurner = IERC20Burnable(_bNomAddress);

// CHECKS

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ pragma solidity 0.8.10;
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";

// One of three testing coins
contract TestERC20WNOM is ERC20Burnable {
constructor() ERC20("Wnom", "WNOM") {
contract TestERC20BNOM is ERC20Burnable {
constructor() ERC20("Bnom", "BNOM") {
_mint(0xc783df8a850f42e7F7e57013759C285caa701eB6, 10000);
_mint(0xeAD9C93b79Ae7C1591b1FB5323BD777E86e150d4, 10000);
_mint(0xE5904695748fe4A84b40b3fc79De2277660BD1D3, 10000);
Expand Down
2 changes: 1 addition & 1 deletion solidity/scripts/contract-deployer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ contract-deployer.ts \
--eth-privkey="0xb1bab011e03a9862664706fc3bbaa1b16651528e5f0e7fbfcbfdd8be302a13e7" \
--contract=Gravity.json \
--test-mode=true \
--wnom-address="0x0F23c3f0C77582a5dB7fB3D61097B619982fb32f"
--bnom-address="0x0F23c3f0C77582a5dB7fB3D61097B619982fb32f"
10 changes: 5 additions & 5 deletions solidity/test-utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Gravity } from "../typechain/Gravity";
import { TestERC20A } from "../typechain/TestERC20A";
import { TestERC20WNOM } from "../typechain/TestERC20WNOM";
import { TestERC20BNOM } from "../typechain/TestERC20BNOM";
import { ethers } from "hardhat";
import { makeCheckpoint, getSignerAddresses, ZeroAddress } from "./pure";
import { Signer } from "ethers";
Expand All @@ -22,8 +22,8 @@ export async function deployContracts(
const TestERC20 = await ethers.getContractFactory("TestERC20A");
const testERC20 = (await TestERC20.deploy()) as TestERC20A;

const testERC20WNOMFactory = await ethers.getContractFactory("TestERC20WNOM");
const testERC20WNOM = (await testERC20WNOMFactory.deploy()) as TestERC20WNOM;
const testERC20BNOMFactory = await ethers.getContractFactory("TestERC20BNOM");
const testERC20BNOM = (await testERC20BNOMFactory.deploy()) as TestERC20BNOM;

const Gravity = await ethers.getContractFactory("Gravity");

Expand All @@ -35,12 +35,12 @@ export async function deployContracts(
gravityId,
await getSignerAddresses(validators),
powers,
testERC20WNOM.address
testERC20BNOM.address
)) as Gravity;

await gravity.deployed();

return { gravity, testERC20, checkpoint, testERC20WNOM };
return { gravity, testERC20, checkpoint, testERC20BNOM };
}

// Insertion Sort for sorting validators
Expand Down
24 changes: 12 additions & 12 deletions solidity/test/sendToCosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async function runNormalTest(opts: {}) {
expect((await gravity.functions.state_lastEventNonce())[0]).to.equal(3);
}

async function runSendAndBurnWnomTest(opts: {}) {
async function runSendAndBurnBnomTest(opts: {}) {

// Prep and deploy contract
// ========================
Expand All @@ -82,51 +82,51 @@ async function runSendAndBurnWnomTest(opts: {}) {
let validators = sortValidators(signers.slice(0, powers.length));
const {
gravity,
testERC20WNOM,
testERC20BNOM,
} = await deployContracts(gravityId, validators, powers);

// Transfer out to Cosmos, locking coins
// =====================================
await testERC20WNOM.functions.approve(gravity.address, 1000);
await testERC20BNOM.functions.approve(gravity.address, 1000);
await expect(gravity.functions.sendToCosmos(
testERC20WNOM.address,
testERC20BNOM.address,
ethers.utils.formatBytes32String("myCosmosAddress"),
1000
)).to.emit(gravity, 'SendToCosmosEvent').withArgs(
testERC20WNOM.address,
testERC20BNOM.address,
await signers[0].getAddress(),
ethers.utils.formatBytes32String("myCosmosAddress"),
1000,
2
);

expect((await testERC20WNOM.functions.balanceOf(gravity.address))[0]).to.equal(0);
expect((await testERC20BNOM.functions.balanceOf(gravity.address))[0]).to.equal(0);
expect((await gravity.functions.state_lastEventNonce())[0]).to.equal(2);

// Do it again
// =====================================
await testERC20WNOM.functions.approve(gravity.address, 1000);
await testERC20BNOM.functions.approve(gravity.address, 1000);
await expect(gravity.functions.sendToCosmos(
testERC20WNOM.address,
testERC20BNOM.address,
ethers.utils.formatBytes32String("myCosmosAddress"),
1000
)).to.emit(gravity, 'SendToCosmosEvent').withArgs(
testERC20WNOM.address,
testERC20BNOM.address,
await signers[0].getAddress(),
ethers.utils.formatBytes32String("myCosmosAddress"),
1000,
3
);

expect((await testERC20WNOM.functions.balanceOf(gravity.address))[0]).to.equal(0);
expect((await testERC20BNOM.functions.balanceOf(gravity.address))[0]).to.equal(0);
expect((await gravity.functions.state_lastEventNonce())[0]).to.equal(3);
}

describe("sendToCosmos tests", function () {
it("normal sendToCosmos", async function () {
await runNormalTest({})
});
it("sendToCosmos and burn wnom", async function () {
await runSendAndBurnWnomTest({})
it("sendToCosmos and burn bnom", async function () {
await runSendAndBurnBnomTest({})
});
});

0 comments on commit ad4720f

Please sign in to comment.