Skip to content

Commit

Permalink
merged + deleted package-lock as we use yarn
Browse files Browse the repository at this point in the history
  • Loading branch information
ccorcoveanu committed Aug 22, 2024
2 parents fd9d1f0 + bfb0a19 commit e48fc36
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 72 deletions.
12 changes: 6 additions & 6 deletions abi/contracts/ERC20Safe/ERC20Safe.abi.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@
{
"indexed": false,
"internalType": "uint112",
"name": "depositNonce",
"name": "batchId",
"type": "uint112"
},
{
"indexed": false,
"internalType": "uint112",
"name": "batchId",
"name": "depositNonce",
"type": "uint112"
}
],
Expand All @@ -111,9 +111,9 @@
},
{
"indexed": false,
"internalType": "string",
"internalType": "bytes",
"name": "callData",
"type": "string"
"type": "bytes"
}
],
"name": "ERC20SCDeposit",
Expand Down Expand Up @@ -353,9 +353,9 @@
"type": "bytes32"
},
{
"internalType": "string",
"internalType": "bytes",
"name": "callData",
"type": "string"
"type": "bytes"
}
],
"name": "depositWithSCExecution",
Expand Down
42 changes: 21 additions & 21 deletions abi/contracts/ERC20Safe/ERC20Safe.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion abi/contracts/ERC20Safe/ERC20Safe.hex

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions abi/contracts/ERC20Safe/ERC20Safe.json

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions contracts/ERC20Safe.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ contract ERC20Safe is Initializable, BridgeRole, Pausable {
mapping(address => uint256) public burnBalances;
mapping(uint256 => Deposit[]) public batchDeposits;

event ERC20Deposit(uint112 depositNonce, uint112 batchId);
event ERC20SCDeposit(uint112 indexed batchId, uint112 depositNonce, string callData);
event ERC20Deposit(uint112 batchId, uint112 depositNonce);
event ERC20SCDeposit(uint112 indexed batchId, uint112 depositNonce, bytes callData);

function initialize() public initializer {
__BridgeRole_init();
Expand Down Expand Up @@ -184,11 +184,14 @@ contract ERC20Safe is Initializable, BridgeRole, Pausable {
* @param amount The amount of tokens to deposit.
* @param recipientAddress The address on the target chain to receive the tokens.
* @param callData The encoded data specifying the cross-chain call details. The expected format is:
* 0x01 + endpoint_name_length (4 bytes) + endpoint_name + gas_limit (8 bytes) +
* num_arguments_length (4 bytes) + [argument_length (4 bytes) + argument]...
* 0x + endpoint_name_length (4 bytes) + endpoint_name + gas_limit (8 bytes) +
* 01 (ArgumentsPresentProtocolMarker) + num_arguments_length (4 bytes) + [argument_length (4 bytes) + argument]...
* This payload includes the endpoint name, gas limit for the execution, and the arguments for the call.
* In case of no arguments, only the ArgumentsMissingProtocolMarker should be included. The expected format is:
* 0x + endpoint_name_length (4 bytes) + endpoint_name + gas_limit (8 bytes) +
* 00 (ArgumentsPresentProtocolMarker)
*/
function depositWithSCExecution(address tokenAddress, uint256 amount, bytes32 recipientAddress, string calldata callData) public whenNotPaused {
function depositWithSCExecution(address tokenAddress, uint256 amount, bytes32 recipientAddress, bytes calldata callData) public whenNotPaused {
uint112 batchNonce;
uint112 depositNonce;
(batchNonce, depositNonce) = _deposit_common(tokenAddress, amount, recipientAddress);
Expand Down
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import "./tasks/deploy/mint-burn-tokens";
import "./tasks/quorum";
import "./tasks/get-statuses-after-execution";
import "./tasks/depositSC";

import "./tasks/set-batch-settle-limit-on-safe"
import "./tasks/deploy";

import { resolve } from "path";
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"size": "cross-env TS_NODE_TRANSPILE_ONLY=true hardhat compile; hardhat size-contracts"
},
"dependencies": {
"@multiversx/sdk-js-bridge": "^0.2.0",
"@multiversx/sdk-js-bridge": "^0.2.3",
"yarn": "^1.22.18"
},
"packageManager": "[email protected]"
Expand Down
7 changes: 0 additions & 7 deletions tasks/approve.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ethers } from "ethers";
import { task } from "hardhat/config";
import { getDeployOptions } from "./args/deployOptions";

Expand All @@ -11,7 +10,6 @@ task("approve", "Approve token")
const filename = "setup.config.json";
let config = JSON.parse(fs.readFileSync(filename, "utf8"));
const safeAddress = config["erc20Safe"];
const scExecAddress = config["execProxy"];
const address = taskArgs.address;
const signersCount = taskArgs.signers ?? 1;
const signers = await hre.ethers.getSigners();
Expand All @@ -23,10 +21,5 @@ task("approve", "Approve token")
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
getDeployOptions(taskArgs),
);
await tokenContract.approve(
scExecAddress,
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
getDeployOptions(taskArgs),
);
}
});
4 changes: 3 additions & 1 deletion tasks/deploy/mint-burn-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { task } from "hardhat/config";
task("deploy-mint-burn-tokens", "Deploys MintBurnERC20 contracts to use to the bridge")
.addParam("name", "Name of the token to deploy")
.addParam("symbol", "Symbol of the token to deploy")
.addParam("decimals", "Num of decimals of the token to deploy")
.setAction(async (taskArgs, hre) => {
const fs = require("fs");
const filename = "setup.config.json";
Expand All @@ -17,8 +18,9 @@ task("deploy-mint-burn-tokens", "Deploys MintBurnERC20 contracts to use to the b

const tokenName = taskArgs.name;
const tokenSymbol = taskArgs.symbol;
const decimals = taskArgs.decimals;

const usdcContract = await mintBurnERC20Factory.deploy(tokenName, tokenSymbol);
const usdcContract = await mintBurnERC20Factory.deploy(tokenName, tokenSymbol, decimals);
await usdcContract.deployed();
console.log("MintBurn token deployed to:", usdcContract.address);

Expand Down
4 changes: 3 additions & 1 deletion tasks/deploy/test-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { task } from "hardhat/config";
task("deploy-test-tokens", "Deploys ERC20 contracts to use to test the bridge")
.addParam("name", "Name of the token to deploy")
.addParam("symbol", "Symbol of the token to deploy")
.addParam("decimals", "Num of decimals of the token to deploy")
.setAction(async (taskArgs, hre) => {
const fs = require("fs");
const filename = "setup.config.json";
Expand All @@ -17,8 +18,9 @@ task("deploy-test-tokens", "Deploys ERC20 contracts to use to test the bridge")

const tokenName = taskArgs.name;
const tokenSymbol = taskArgs.symbol;
const decimals = taskArgs.decimals;

const usdcContract = await genericERC20Factory.deploy(tokenName, tokenSymbol);
const usdcContract = await genericERC20Factory.deploy(tokenName, tokenSymbol, decimals);
await usdcContract.deployed();
console.log("Token deployed to:", usdcContract.address);
});
24 changes: 14 additions & 10 deletions tasks/depositSC.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
import { task } from "hardhat/config";
import { getDeployOptions } from "./args/deployOptions";

import { encodeCallData } from "@multiversx/sdk-js-bridge";
task("deposit-sc", "Deposits token and sends to safe")
.addParam("address", "Address of the token to be sent")
.addParam("amount", "Amount we want to deposit (full value, with decimals)")
.addParam("receiversc", "MultiversX address hex encoded of the receiver")
.addParam("callData", "data field for MVX SC execution")
.addParam("mvxGasLimit", "data field for MVX SC execution")
.addParam("sc", "MultiversX address hex encoded of the receiver")
.addParam("endpoint", "data field for MVX SC execution")
.addParam("gaslimit", "data field for MVX SC execution")
.addParam("args", "data field for MVX SC execution")
.addOptionalParam("price", "Gas price in gwei for this transaction", undefined)
.setAction(async (taskArgs, hre) => {
const fs = require("fs");
const filename = "setup.config.json";
let config = JSON.parse(fs.readFileSync(filename, "utf8"));
const [adminWallet] = await hre.ethers.getSigners();
const scExecProxy = config["execProxy"];
const scExecContactFactory = await hre.ethers.getContractFactory("SCExecProxy");
const scExecContract = scExecContactFactory.attach(scExecProxy).connect(adminWallet);
const safeAddress = config["erc20Safe"];
const safeContractFactory = await hre.ethers.getContractFactory("ERC20Safe");
const safe = safeContractFactory.attach(safeAddress).connect(adminWallet);

const address = taskArgs.address;
const amount = taskArgs.amount;
const receiver = taskArgs.receiversc;
const callData = taskArgs.callData;
const receiver = taskArgs.sc;
const endpoint = taskArgs.endpoint;
const gaslimit = taskArgs.gaslimit;
const args = JSON.parse(taskArgs.args);

await scExecContract.deposit(
const callData = encodeCallData(endpoint, gaslimit, args);
await safe.depositWithSCExecution(
address,
amount,
Buffer.from(receiver, "hex"),
Expand Down
2 changes: 1 addition & 1 deletion tasks/mint-test-tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ task("mint-test-tokens", "Mints tests tokens and sends them to the recipientAddr
for (let token of config["tokens"]) {
console.log("minting tokens for contract: ", token);
const tokenContract = (await hre.ethers.getContractFactory("GenericERC20")).attach(token);
await tokenContract.mint(address, 100000000000000);
await tokenContract.mint(address, "1000000000000000000000000000");
console.log("minted tokens for contract: ", token, address);
}
});
8 changes: 3 additions & 5 deletions tasks/set-batch-settle-limit-on-safe.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { task } from "hardhat/config";
import { getDeployOptions } from "./args/deployOptions";

task("set-batch-settle-limit-on-safe", "Sets a new batch settle limit")
.addParam("blocks", "new batch settle limit")
Expand All @@ -12,11 +13,8 @@ task("set-batch-settle-limit-on-safe", "Sets a new batch settle limit")
const safeContractFactory = await hre.ethers.getContractFactory("ERC20Safe");
const safe = safeContractFactory.attach(safeAddress).connect(adminWallet);

if (taskArgs.price) {
await safe.setBatchBlockLimit(taskArgs.blocks, { gasPrice: taskArgs.price * 1000000000 });
} else {
await safe.setBatchBlockLimit(taskArgs.blocks);
}
await safe.setBatchSettleLimit(taskArgs.blocks, getDeployOptions(taskArgs));

config.batchBlockLimit = taskArgs.blocks;
fs.writeFileSync(filename, JSON.stringify(config));
});
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -766,10 +766,10 @@
json-bigint "1.0.0"
keccak "3.0.2"

"@multiversx/sdk-js-bridge@^0.2.0":
version "0.2.0"
resolved "https://registry.npmjs.org/@multiversx/sdk-js-bridge/-/sdk-js-bridge-0.2.0.tgz"
integrity sha512-RtYHD78ZChWkLGeB3NsvckJrL6kvtwUV5+e1NxGAJZGQsvQ7Dn5xH81TA+mKAuGaRPy+KpHy/hFvE8PYqwGx7w==
"@multiversx/sdk-js-bridge@^0.2.3":
version "0.2.3"
resolved "https://registry.npmjs.org/@multiversx/sdk-js-bridge/-/sdk-js-bridge-0.2.3.tgz"
integrity sha512-iiJsTPZk97IYawLGvSs6X7ukaawIEhkL4cZHqHUkdNz/ioNlYsbYpsvTmk+khSLM2neN4WgUD8E7TDPPTV0InA==
dependencies:
bignumber.js "^9.1.2"

Expand Down

0 comments on commit e48fc36

Please sign in to comment.