Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nmlinaric committed Jan 16, 2025
1 parent c4be936 commit d251b53
Show file tree
Hide file tree
Showing 58 changed files with 388 additions and 524 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ data/
.vscode/
.env
artifacts/
cache
1 change: 1 addition & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as dotenv from "dotenv";
import type { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-viem";
import "@nomiclabs/hardhat-solhint";
import "hardhat-chai-matchers-viem";
import "hardhat-gas-reporter"
Expand Down
14 changes: 6 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@
"author": "Sygma",
"license": "BUSL-1.1",
"devDependencies": {
"@nomicfoundation/hardhat-chai-matchers": "^2.0.8",
"@nomicfoundation/hardhat-ignition": "^0.15.0",
"@metamask/eth-sig-util": "^8.1.2",
"@nomicfoundation/hardhat-ignition-viem": "^0.15.0",
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
"@nomicfoundation/hardhat-verify": "^2.0.0",
"@nomicfoundation/hardhat-viem": "^2.0.5",
"@nomicfoundation/hardhat-viem": "^2.0.6",
"@nomiclabs/hardhat-solhint": "^4.0.1",
"@types/chai": "^5.0.1",
"@types/chai-as-promised": "^7.1.6",
Expand All @@ -54,21 +53,20 @@
"eslint-plugin-import": "^2.25.2",
"eslint-plugin-n": "^15.0.0",
"eslint-plugin-promise": "^6.0.0",
"hardhat": "^2.22.15",
"ethers": "^6.13.5",
"hardhat": "^2.22.18",
"hardhat-chai-matchers-viem": "^2.0.8",
"hardhat-gas-reporter": "^2.2.2",
"prettier": "2.8.1",
"solhint": "^3.3.7",
"solidity-coverage": "^0.8.0",
"solmate": "^6.8.0",
"ts-node": ">=8.0.0",
"typescript": "5.0.3",
"viem": "^2.13.7"
},
"dependencies": {
"@metamask/eth-sig-util": "^8.1.1",
"@openzeppelin/contracts": "4.5.0",
"@uniswap/v3-periphery": "^1.4.4",
"ethers": "^6.13.4",
"solmate": "^6.2.0"
"@uniswap/v3-periphery": "^1.4.4"
}
}
1 change: 1 addition & 0 deletions test/adapters/native/collectFee.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ describe("Bridge - [collect fee - native token]", () => {
// check that correct ETH amount is successfully transferred to the adapter
const adapterBalanceAfter = await getBalance(NativeTokenTransferGatewayInstance);
const handlerBalanceAfter = await getBalance(NativeTokenHandlerInstance);
console.log("123-0", depositAmount)
console.log("123-1", transferredAmount)
console.log("123-2", handlerBalanceBefore)
console.log("123-3", handlerBalanceAfter)
Expand Down
9 changes: 4 additions & 5 deletions test/adapters/native/decimalConversion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import hre from "hardhat";
import {assert, expect} from "chai";
import {encodeAbiParameters, Hex, keccak256, parseAbiParameters, parseEther, parseUnits, WalletClient, concat, toHex} from "viem";
import {encodeAbiParameters, Hex, keccak256, parseAbiParameters, parseEther, parseUnits, WalletClient, concat, toHex, toBytes} from "viem";
import {createBtcDepositData, createERCDepositData, deploySourceChainContracts, getBalance, mpcAddress, signTypedProposal, trimPrefix} from "../../helpers";
import {ContractTypesMap} from "hardhat/types";
import {loadFixture} from "@nomicfoundation/hardhat-network-helpers";
Expand All @@ -18,7 +18,7 @@ describe("Bridge - [decimal conversion - native token]", () => {
const resourceID = toHex(650, {size:32});
const btcrecipient = "bc1qs0fcdq73vgurej48yhtupzcv83un2p5qhsje7n";
const originDecimalPlaces = 8;
const originHexDecimalPlaces = toHex(originDecimalPlaces);
const originHexDecimalPlaces = toHex(originDecimalPlaces, {size: 1});
const depositAmount = parseUnits("1", originDecimalPlaces);
const fee = parseUnits("0.1", originDecimalPlaces);
const transferredAmount = depositAmount - fee;
Expand Down Expand Up @@ -91,9 +91,8 @@ describe("Bridge - [decimal conversion - native token]", () => {
await BridgeInstance.write.endKeygen([mpcAddress]);

// send ETH to destination adapter for transfers

await depositor.sendTransaction({
account: depositor!.account,
account: depositor.account!.address,
to: NativeTokenHandlerInstance.address,
value: BigInt(1000000000000000000),
chain: null
Expand Down Expand Up @@ -150,7 +149,7 @@ describe("Bridge - [decimal conversion - native token]", () => {
data: proposalData,
};

const proposalSignedData = await signTypedProposal(
const proposalSignedData = signTypedProposal(
BridgeInstance.address,
[proposal]
);
Expand Down
13 changes: 7 additions & 6 deletions test/adapters/native/executeProposal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ describe("Bridge - [execute proposal - native token]", () => {
await BridgeInstance.write.endKeygen([mpcAddress]);

// send ETH to destination adapter for transfers
await web3.eth.sendTransaction({
account: depositor.account,
await depositor.sendTransaction({
account: depositor.account!.address,
to: NativeTokenHandlerInstance.address,
value: "1000000000000000000"
value: BigInt(1000000000000000000),
chain: null
})
});

Expand All @@ -107,7 +108,7 @@ describe("Bridge - [execute proposal - native token]", () => {
});

it("should create and execute executeProposal successfully", async () => {
const proposalSignedData = await signTypedProposal(
const proposalSignedData = signTypedProposal(
BridgeInstance.address,
[proposal]
);
Expand Down Expand Up @@ -145,7 +146,7 @@ describe("Bridge - [execute proposal - native token]", () => {
});

it("should skip executing proposal if deposit nonce is already used", async () => {
const proposalSignedData = await signTypedProposal(
const proposalSignedData = signTypedProposal(
BridgeInstance.address,
[proposal]
);
Expand Down Expand Up @@ -181,7 +182,7 @@ describe("Bridge - [execute proposal - native token]", () => {
});

it("executeProposal event should be emitted with expected values", async () => {
const proposalSignedData = await signTypedProposal(
const proposalSignedData = signTypedProposal(
BridgeInstance.address,
[proposal]
);
Expand Down
2 changes: 2 additions & 0 deletions test/adapters/native/optionalContractCall/collectFee.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ describe("Bridge - [collect fee - native token]", () => {
DefaultMessageReceiverInstance,
BridgeInstance,
BasicFeeHandlerInstance,
NativeTokenHandlerInstance,
ERC20MintableInstance,
FeeHandlerRouterInstance
} = await loadFixture(deploySourceChainContracts));
[
,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,11 @@ describe("Bridge - [decimal conversion - native token]", () => {
};

// send ETH to destination adapter for transfers
await web3.eth.sendTransaction({
account: depositor.account,
await depositor.sendTransaction({
account: depositor.account!.address,
to: NativeTokenHandlerInstance.address,
value: "1000000000000000000"
value: BigInt(1000000000000000000),
chain: null
})

// set MPC address to unpause the Bridge
Expand Down Expand Up @@ -192,7 +193,7 @@ describe("Bridge - [decimal conversion - native token]", () => {
data: proposalData,
};

const proposalSignedData = await signTypedProposal(
const proposalSignedData = signTypedProposal(
BridgeInstance.address,
[proposal]
);
Expand Down
3 changes: 3 additions & 0 deletions test/adapters/native/optionalContractCall/deposit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ describe("Bridge - [deposit - native token]", () => {
BridgeInstance,
ERC20MintableInstance,
BasicFeeHandlerInstance,
NativeTokenTransferGatewayInstance,
NativeTokenHandlerInstance,
FeeHandlerRouterInstance
} = await loadFixture(deploySourceChainContracts));
[
,
Expand Down
66 changes: 22 additions & 44 deletions test/adapters/native/optionalContractCall/distributeFee.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// SPDX-License-Identifier: LGPL-3.0-only

import hre from 'hardhat';
import {concat, encodeAbiParameters, encodeFunctionData, Hex, keccak256, parseAbiParameters, parseEther, parseUnits, toFunctionSelector, toHex, WalletClient, zeroAddress} from "viem";
import {createBtcDepositData, createGmpDepositData, createMessageCallData, createOptionalContractCallDepositData, createResourceID, deploySourceChainContracts, mpcAddress, trimPrefix} from "../../../helpers";
import {concat, encodeAbiParameters, encodeFunctionData, formatEther, formatUnits, Hex, keccak256, parseAbiParameters, parseEther, parseUnits, toFunctionSelector, toHex, WalletClient, zeroAddress} from "viem";
import {createBtcDepositData, createGmpDepositData, createMessageCallData, createOptionalContractCallDepositData, createResourceID, deploySourceChainContracts, getBalance, mpcAddress, trimPrefix} from "../../../helpers";
import {ContractTypesMap} from 'hardhat/types';
import {loadFixture} from '@nomicfoundation/hardhat-network-helpers';
import {assert, expect} from 'chai';
Expand Down Expand Up @@ -43,6 +43,8 @@ describe("Native token adapter - [distributeFee]", () => {
BridgeInstance,
ERC20MintableInstance,
BasicFeeHandlerInstance,
NativeTokenHandlerInstance,
NativeTokenTransferGatewayInstance,
} = await loadFixture(deploySourceChainContracts));
[
,
Expand Down Expand Up @@ -111,11 +113,8 @@ describe("Native token adapter - [distributeFee]", () => {

// check the balance is 0
assert.equal(
web3.utils.fromWei(
await getBalance(BridgeInstance.address),
"ether"
),
"0"
await getBalance(BridgeInstance),
parseEther("0")
);
await NativeTokenTransferGatewayInstance.write.depositToEVMWithMessage([
destinationDomainID,
Expand All @@ -128,25 +127,16 @@ describe("Native token adapter - [distributeFee]", () => {
}
);
assert.equal(
web3.utils.fromWei(
await getBalance(BridgeInstance.address),
"ether"
),
"0"
await getBalance(BridgeInstance),
parseEther("0")
);
assert.equal(
web3.utils.fromWei(
await getBalance(NativeTokenTransferGatewayInstance.address),
"ether"
),
"0"
await getBalance(NativeTokenTransferGatewayInstance),
parseEther("0")
);
assert.equal(
web3.utils.fromWei(
await getBalance(NativeTokenHandlerInstance.address),
"ether"
),
Ethers.utils.formatUnits(transferredAmount)
await getBalance(NativeTokenHandlerInstance),
parseEther(transferredAmount.toString())
);

const depositorBalanceBefore = await getBalance(depositor);
Expand All @@ -171,8 +161,8 @@ describe("Native token adapter - [distributeFee]", () => {
payout
);

const depositorBalanceAfter = await getBalance(depositor.account!.address);
const recipientBalanceAfter = await getBalance(recipient.account!.address);
const depositorBalanceAfter = await getBalance(depositor);
const recipientBalanceAfter = await getBalance(recipient);
assert.equal(depositorBalanceAfter, depositorBalanceBefore + payout);
assert.equal(recipientBalanceAfter, recipientBalanceBefore + payout);
});
Expand All @@ -193,18 +183,12 @@ describe("Native token adapter - [distributeFee]", () => {
);

assert.equal(
web3.utils.fromWei(
await getBalance(NativeTokenTransferGatewayInstance.address),
"ether"
),
"0"
await getBalance(NativeTokenTransferGatewayInstance),
parseEther("0")
);
assert.equal(
web3.utils.fromWei(
await getBalance(NativeTokenHandlerInstance.address),
"ether"
),
Ethers.utils.formatUnits(transferredAmount)
await getBalance(NativeTokenHandlerInstance),
parseEther(transferredAmount.toString())
);

const payout = parseEther("0.01");
Expand All @@ -231,18 +215,12 @@ describe("Native token adapter - [distributeFee]", () => {
);

assert.equal(
web3.utils.fromWei(
await getBalance(NativeTokenTransferGatewayInstance.address),
"ether"
),
"0"
await getBalance(NativeTokenTransferGatewayInstance),
parseEther("0")
);
assert.equal(
web3.utils.fromWei(
await getBalance(NativeTokenHandlerInstance.address),
"ether"
),
Ethers.utils.formatUnits(transferredAmount)
await getBalance(NativeTokenHandlerInstance),
parseEther(transferredAmount.toString())
);

const payout = parseEther("0.01");
Expand Down
20 changes: 12 additions & 8 deletions test/adapters/native/optionalContractCall/executeProposal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ describe("Bridge - [execute proposal - native token]", () => {
BridgeInstance,
ERC20MintableInstance,
BasicFeeHandlerInstance,
DefaultMessageReceiverInstance,
NativeTokenTransferGatewayInstance,
NativeTokenHandlerInstance,
FeeHandlerRouterInstance
} = await loadFixture(deploySourceChainContracts));
[
,
Expand Down Expand Up @@ -139,7 +143,7 @@ describe("Bridge - [execute proposal - native token]", () => {
});

it("should create and execute executeProposal with contract call successfully", async () => {
const proposalSignedData = await signTypedProposal(
const proposalSignedData = signTypedProposal(
BridgeInstance.address,
[proposal]
);
Expand All @@ -159,8 +163,8 @@ describe("Bridge - [execute proposal - native token]", () => {
).not.to.be.reverted;

const recipientNativeBalanceBefore = await getBalance(recipient);
const recipientERC20BalanceBefore = await ERC20MintableInstance.read.balanceOf([recipient]);
const defaultReceiverBalanceBefore = await getBalance(DefaultMessageReceiverInstance.address);
const recipientERC20BalanceBefore = await ERC20MintableInstance.read.balanceOf([recipient.account!.address]);
const defaultReceiverBalanceBefore = await getBalance(DefaultMessageReceiverInstance);

await expect(
BridgeInstance.write.executeProposal([proposal, proposalSignedData], {
Expand All @@ -180,7 +184,7 @@ describe("Bridge - [execute proposal - native token]", () => {
// check that tokens are transferred to recipient address
const recipientNativeBalanceAfter = await getBalance(recipient);
const recipientERC20BalanceAfter = await ERC20MintableInstance.read.balanceOf([recipient.account!.address]);
const defaultReceiverBalanceAfter = await getBalance(DefaultMessageReceiverInstance.address);
const defaultReceiverBalanceAfter = await getBalance(DefaultMessageReceiverInstance);

assert.strictEqual(
recipientNativeBalanceBefore + transferredAmount,
Expand All @@ -194,7 +198,7 @@ describe("Bridge - [execute proposal - native token]", () => {
});

it("should skip executing proposal if deposit nonce is already used", async () => {
const proposalSignedData = await signTypedProposal(
const proposalSignedData = signTypedProposal(
BridgeInstance.address,
[proposal]
);
Expand Down Expand Up @@ -234,7 +238,7 @@ describe("Bridge - [execute proposal - native token]", () => {
});

it("executeProposal event should be emitted with expected values", async () => {
const proposalSignedData = await signTypedProposal(
const proposalSignedData = signTypedProposal(
BridgeInstance.address,
[proposal]
);
Expand Down Expand Up @@ -321,7 +325,7 @@ describe("Bridge - [execute proposal - native token]", () => {
await DefaultMessageReceiverInstance.read.SYGMA_HANDLER_ROLE(),
NativeTokenHandlerInstance.address
]);
const proposalSignedData = await signTypedProposal(
const proposalSignedData = signTypedProposal(
BridgeInstance.address,
[proposal]
);
Expand Down Expand Up @@ -358,7 +362,7 @@ describe("Bridge - [execute proposal - native token]", () => {

it("should revert if insufficient gas limit left for executing action", async () => {
const insufficientExecutionGasAmount = BigInt(100000);
const proposalSignedData = await signTypedProposal(
const proposalSignedData = signTypedProposal(
BridgeInstance.address,
[proposal]
);
Expand Down
Loading

0 comments on commit d251b53

Please sign in to comment.