Skip to content

Commit

Permalink
Upgrade npm modules loyalty-tokens, multisig-wallet-contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKim20 committed May 10, 2024
1 parent 960d906 commit 7aafee6
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 65 deletions.
12 changes: 9 additions & 3 deletions packages/contracts/contracts/bridge/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ contract Bridge is BridgeStorage, Initializable, OwnableUpgradeable, UUPSUpgrade
bytes32 _depositId,
address _account,
uint256 _amount,
uint256 _expiry,
bytes calldata _signature
) external payable override notExistDeposit(_depositId) {
require(tokenInfos[_tokenId].status == TokenStatus.Registered, "1713");
Expand All @@ -111,7 +112,7 @@ contract Bridge is BridgeStorage, Initializable, OwnableUpgradeable, UUPSUpgrade
require(_amount > tokenInfos[_tokenId].fee * 2, "1031");

BIP20DelegatedTransfer token = tokenInfos[_tokenId].token;
if (token.delegatedTransfer(_account, address(this), _amount, _signature)) {
if (token.delegatedTransfer(_account, address(this), _amount, _expiry, _signature)) {
DepositData memory data = DepositData({ tokenId: _tokenId, account: _account, amount: _amount });
deposits[_depositId] = data;
emit BridgeDeposited(_tokenId, _depositId, data.account, data.amount, 0);
Expand Down Expand Up @@ -264,7 +265,12 @@ contract Bridge is BridgeStorage, Initializable, OwnableUpgradeable, UUPSUpgrade
}

/// @notice 브리지를 위한 유동성 자금을 예치합니다.
function depositLiquidity(bytes32 _tokenId, uint256 _amount, bytes calldata _signature) external payable override {
function depositLiquidity(
bytes32 _tokenId,
uint256 _amount,
uint256 _expiry,
bytes calldata _signature
) external payable override {
require(tokenInfos[_tokenId].status == TokenStatus.Registered, "1713");

if (tokenInfos[_tokenId].native) {
Expand All @@ -277,7 +283,7 @@ contract Bridge is BridgeStorage, Initializable, OwnableUpgradeable, UUPSUpgrade
require(token.balanceOf(_msgSender()) >= _amount, "1511");
require(_amount % 1 gwei == 0, "1030");

if (token.delegatedTransfer(_msgSender(), address(this), _amount, _signature)) {
if (token.delegatedTransfer(_msgSender(), address(this), _amount, _expiry, _signature)) {
liquidity[_tokenId][_msgSender()] += _amount;
emit DepositedLiquidity(_tokenId, _msgSender(), _amount, liquidity[_tokenId][_msgSender()]);
}
Expand Down
1 change: 1 addition & 0 deletions packages/contracts/contracts/interfaces/IBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface IBridge {
bytes32 _depositId,
address _account,
uint256 _amount,
uint256 _expiry,
bytes calldata _signature
) external payable;

Expand Down
7 changes: 6 additions & 1 deletion packages/contracts/contracts/interfaces/IBridgeLiquidity.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ interface IBridgeLiquidity {
event DepositedLiquidity(bytes32 tokenId, address account, uint256 amount, uint256 liquidity);
event WithdrawnLiquidity(bytes32 tokenId, address account, uint256 amount, uint256 liquidity);

function depositLiquidity(bytes32 _tokenId, uint256 _amount, bytes calldata _signature) external payable;
function depositLiquidity(
bytes32 _tokenId,
uint256 _amount,
uint256 _expiry,
bytes calldata _signature
) external payable;

function withdrawLiquidity(bytes32 _tokenId, uint256 _amount) external;

Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dms-bridge-contracts",
"version": "1.5.0",
"version": "1.6.0",
"description": "Smart Contracts of DMS Bridge",
"files": [
"**/*.sol"
Expand Down Expand Up @@ -46,7 +46,7 @@
"ethers": "^5.7.0",
"hardhat": "^2.12.7",
"hardhat-gas-reporter": "^1.0.7",
"loyalty-tokens": "^1.1.0",
"loyalty-tokens": "^1.1.2",
"mocha": "10.1.0",
"prettier": "^2.5.1",
"prettier-plugin-solidity": "^1.1.1",
Expand Down
9 changes: 6 additions & 3 deletions packages/contracts/src/utils/ContractUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,21 @@ export class ContractUtils {
}

public static getTransferMessage(
chainId: BigNumberish,
tokenAddress: string,
from: string,
to: string,
amount: BigNumberish,
nonce: BigNumberish,
chainId?: BigNumberish
expiry: number
): Uint8Array {
const encodedResult = defaultAbiCoder.encode(
["address", "address", "uint256", "uint256", "uint256"],
[from, to, amount, chainId ? chainId : hre.ethers.provider.network.chainId, nonce]
["uint256", "address", "address", "address", "uint256", "uint256", "uint256"],
[chainId, tokenAddress, from, to, amount, nonce, expiry]
);
return arrayify(keccak256(encodedResult));
}

public static async signMessage(signer: Signer, message: Uint8Array): Promise<string> {
return signer.signMessage(message);
}
Expand Down
25 changes: 16 additions & 9 deletions packages/contracts/test/01-Bridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe("Test for Ledger", () => {
const signature = await ContractUtils.signMessage(deployments.accounts.deployer, arrayify(HashZero));
const tx1 = await bridgeContract
.connect(deployments.accounts.deployer)
.depositLiquidity(tokenId0, liquidityAmount, signature, { value: liquidityAmount });
.depositLiquidity(tokenId0, liquidityAmount, 0, signature, { value: liquidityAmount });
console.log(`Deposit liquidity native token (tx: ${tx1.hash})...`);
await tx1.wait();

Expand All @@ -71,19 +71,22 @@ describe("Test for Ledger", () => {

it("Deposit BIP20 Liquidity", async () => {
const liquidityAmount = Amount.make(1_000_000_000, 18).value;
const nonce = await (deployments.getContract("TestLYT") as BIP20DelegatedTransfer).nonceOf(
deployments.accounts.deployer.address
);
const token = deployments.getContract("TestLYT") as BIP20DelegatedTransfer;
const nonce = await token.nonceOf(deployments.accounts.deployer.address);
const expiry = ContractUtils.getTimeStamp() + 12 * 5;
const message = ContractUtils.getTransferMessage(
hre.ethers.provider.network.chainId,
token.address,
deployments.accounts.deployer.address,
bridgeContract.address,
liquidityAmount,
nonce
nonce,
expiry
);
const signature = await ContractUtils.signMessage(deployments.accounts.deployer, message);
const tx1 = await bridgeContract
.connect(deployments.accounts.deployer)
.depositLiquidity(tokenId1, liquidityAmount, signature);
.depositLiquidity(tokenId1, liquidityAmount, expiry, signature);
console.log(`Deposit liquidity token (tx: ${tx1.hash})...`);
await tx1.wait();

Expand All @@ -97,7 +100,7 @@ describe("Test for Ledger", () => {
await expect(
bridgeContract
.connect(deployments.accounts.users[0])
.depositToBridge(tokenId0, depositId, AddressZero, 0, signature, {
.depositToBridge(tokenId0, depositId, AddressZero, 0, 0, signature, {
value: amount,
})
)
Expand Down Expand Up @@ -145,18 +148,22 @@ describe("Test for Ledger", () => {
const oldLiquidity = await tokenContract.balanceOf(bridgeContract.address);
const oldTokenBalance = await tokenContract.balanceOf(deployments.accounts.users[0].address);
const nonce = await tokenContract.nonceOf(deployments.accounts.users[0].address);
const expiry = ContractUtils.getTimeStamp() + 12 * 5;
const message = ContractUtils.getTransferMessage(
hre.ethers.provider.network.chainId,
tokenContract.address,
deployments.accounts.users[0].address,
bridgeContract.address,
amount,
nonce
nonce,
expiry
);
depositId = ContractUtils.getRandomId(deployments.accounts.users[0].address);
const signature = await ContractUtils.signMessage(deployments.accounts.users[0], message);
await expect(
bridgeContract
.connect(deployments.accounts.deployer)
.depositToBridge(tokenId1, depositId, deployments.accounts.users[0].address, amount, signature)
.depositToBridge(tokenId1, depositId, deployments.accounts.users[0].address, amount, expiry, signature)
)
.to.emit(bridgeContract, "BridgeDeposited")
.withNamedArgs({
Expand Down
6 changes: 3 additions & 3 deletions packages/validator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"chai": "^4.3.7",
"chai-http": "^4.3.7",
"cors": "^2.8.5",
"dms-bridge-contracts": "^1.5.0",
"dms-bridge-contracts": "^1.6.0",
"dom-parser": "^1.1.5",
"dotenv": "^10.0.0",
"ethereum-waffle": "^4.0.10",
Expand All @@ -82,8 +82,8 @@
"hardhat": "^2.12.7",
"hardhat-gas-reporter": "^1.0.7",
"ip": "^1.1.5",
"loyalty-tokens": "^1.1.0",
"multisig-wallet-contracts": "^1.1.0",
"loyalty-tokens": "^1.1.2",
"multisig-wallet-contracts": "^1.1.3",
"mybatis-mapper": "^0.7.1",
"node-cron": "^3.0.0",
"pg": "^8.11.3",
Expand Down
8 changes: 5 additions & 3 deletions packages/validator/src/utils/ContractUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,15 +616,17 @@ export class ContractUtils {
}

public static getTransferMessage(
chainId: BigNumberish,
tokenAddress: string,
from: string,
to: string,
amount: BigNumberish,
nonce: BigNumberish,
chainId: BigNumberish
expiry: number
): Uint8Array {
const encodedResult = defaultAbiCoder.encode(
["address", "address", "uint256", "uint256", "uint256"],
[from, to, amount, chainId, nonce]
["uint256", "address", "address", "address", "uint256", "uint256", "uint256"],
[chainId, tokenAddress, from, to, amount, nonce, expiry]
);
return arrayify(keccak256(encodedResult));
}
Expand Down
27 changes: 18 additions & 9 deletions packages/validator/test-local/localtest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe("Test for Bridge", function () {
const signature = await ContractUtils.signMessage(deploymentsA.accounts.deployer, arrayify(HashZero));
const tx1 = await bridgeAContract
.connect(deploymentsA.accounts.deployer)
.depositLiquidity(tokenId0, liquidityAmount, signature, { value: liquidityAmount });
.depositLiquidity(tokenId0, liquidityAmount, 0, signature, { value: liquidityAmount });
await tx1.wait();
});

Expand All @@ -109,43 +109,49 @@ describe("Test for Bridge", function () {
const signature = await ContractUtils.signMessage(deploymentsB.accounts.deployer, arrayify(HashZero));
const tx1 = await bridgeBContract
.connect(deploymentsB.accounts.deployer)
.depositLiquidity(tokenId0, liquidityAmount, signature, { value: liquidityAmount });
.depositLiquidity(tokenId0, liquidityAmount, 0, signature, { value: liquidityAmount });
await tx1.wait();
});

it("Deposit BIP20 Liquidity at Bridge A", async () => {
await hre.changeNetwork(config.bridge.networkAName);
const liquidityAmount = Amount.make(1_000_000_000, 18).value;
const nonce = await tokenAContract.nonceOf(deploymentsA.accounts.deployer.address);
const expiry = ContractUtils.getTimeStamp() + 60;
const message = ContractUtils.getTransferMessage(
hre.getChainId(config.bridge.networkAName),
tokenAContract.address,
deploymentsA.accounts.deployer.address,
bridgeAContract.address,
liquidityAmount,
nonce,
hre.getChainId(config.bridge.networkAName)
expiry
);
const signature = await ContractUtils.signMessage(deploymentsA.accounts.deployer, message);
const tx1 = await bridgeAContract
.connect(deploymentsA.accounts.deployer)
.depositLiquidity(tokenId1, liquidityAmount, signature);
.depositLiquidity(tokenId1, liquidityAmount, expiry, signature);
await tx1.wait();
});

it("Deposit BIP20 Liquidity at Bridge B", async () => {
await hre.changeNetwork(config.bridge.networkBName);
const liquidityAmount = Amount.make(1_000_000_000, 18).value;
const nonce = await tokenBContract.nonceOf(deploymentsB.accounts.deployer.address);
const expiry = ContractUtils.getTimeStamp() + 60;
const message = ContractUtils.getTransferMessage(
hre.getChainId(config.bridge.networkBName),
tokenBContract.address,
deploymentsB.accounts.deployer.address,
bridgeBContract.address,
liquidityAmount,
nonce,
hre.getChainId(config.bridge.networkBName)
expiry
);
const signature = await ContractUtils.signMessage(deploymentsB.accounts.deployer, message);
const tx1 = await bridgeBContract
.connect(deploymentsB.accounts.deployer)
.depositLiquidity(tokenId1, liquidityAmount, signature);
.depositLiquidity(tokenId1, liquidityAmount, expiry, signature);
await tx1.wait();
});

Expand All @@ -160,7 +166,7 @@ describe("Test for Bridge", function () {
const signature = await ContractUtils.signMessage(deploymentsA.accounts.users[0], arrayify(HashZero));
const tx = await bridgeAContract
.connect(deploymentsA.accounts.users[0])
.depositToBridge(tokenId0, depositId, AddressZero, 0, signature, {
.depositToBridge(tokenId0, depositId, AddressZero, 0, 0, signature, {
value: amount,
});
await tx.wait();
Expand All @@ -183,18 +189,21 @@ describe("Test for Bridge", function () {
const oldLiquidity = await tokenBContract.balanceOf(bridgeBContract.address);
const oldTokenBalance = await tokenBContract.balanceOf(deploymentsB.accounts.users[0].address);
const nonce = await tokenBContract.nonceOf(deploymentsB.accounts.users[0].address);
const expiry = ContractUtils.getTimeStamp() + 60;
const message = ContractUtils.getTransferMessage(
hre.getChainId(config.bridge.networkBName),
tokenBContract.address,
deploymentsB.accounts.users[0].address,
bridgeBContract.address,
amount,
nonce,
hre.getChainId(config.bridge.networkBName)
expiry
);
depositId = ContractUtils.getRandomId(deploymentsB.accounts.users[0].address);
const signature = await ContractUtils.signMessage(deploymentsB.accounts.users[0], message);
const tx = await bridgeBContract
.connect(deploymentsB.accounts.deployer)
.depositToBridge(tokenId1, depositId, deploymentsB.accounts.users[0].address, amount, signature);
.depositToBridge(tokenId1, depositId, deploymentsB.accounts.users[0].address, amount, expiry, signature);
await tx.wait();

expect(await tokenBContract.balanceOf(deploymentsB.accounts.users[0].address)).to.deep.equal(
Expand Down
23 changes: 14 additions & 9 deletions packages/validator/test/01-Collector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,27 +113,29 @@ describe("Test for EventCollector", () => {
const signature = await ContractUtils.signMessage(deploymentsA.accounts.deployer, arrayify(HashZero));
const tx1 = await bridgeContract
.connect(deploymentsA.accounts.deployer)
.depositLiquidity(tokenId0, liquidityAmount, signature, { value: liquidityAmount });
.depositLiquidity(tokenId0, liquidityAmount, 0, signature, { value: liquidityAmount });
await tx1.wait();
});

it("Deposit BIP20 Liquidity", async () => {
await hre.changeNetwork(config.bridge.networkAName);
const liquidityAmount = Amount.make(1_000_000_000, 18).value;
const nonce = await (deploymentsA.getContract("TestLYT") as BIP20DelegatedTransfer).nonceOf(
deploymentsA.accounts.deployer.address
);
const token = deploymentsA.getContract("TestLYT") as BIP20DelegatedTransfer;
const nonce = await token.nonceOf(deploymentsA.accounts.deployer.address);
const expiry = ContractUtils.getTimeStamp() + 60;
const message = ContractUtils.getTransferMessage(
hre.getChainId(config.bridge.networkAName),
token.address,
deploymentsA.accounts.deployer.address,
bridgeContract.address,
liquidityAmount,
nonce,
hre.getChainId(config.bridge.networkAName)
expiry
);
const signature = await ContractUtils.signMessage(deploymentsA.accounts.deployer, message);
const tx1 = await bridgeContract
.connect(deploymentsA.accounts.deployer)
.depositLiquidity(tokenId1, liquidityAmount, signature);
.depositLiquidity(tokenId1, liquidityAmount, expiry, signature);
await tx1.wait();
});

Expand All @@ -145,7 +147,7 @@ describe("Test for EventCollector", () => {
await expect(
bridgeContract
.connect(deploymentsA.accounts.users[0])
.depositToBridge(tokenId0, depositId, AddressZero, 0, signature, {
.depositToBridge(tokenId0, depositId, AddressZero, 0, 0, signature, {
value: amount,
})
)
Expand Down Expand Up @@ -180,19 +182,22 @@ describe("Test for EventCollector", () => {
const oldLiquidity = await tokenContract.balanceOf(bridgeContract.address);
const oldTokenBalance = await tokenContract.balanceOf(deploymentsA.accounts.users[0].address);
const nonce = await tokenContract.nonceOf(deploymentsA.accounts.users[0].address);
const expiry = ContractUtils.getTimeStamp() + 60;
const message = ContractUtils.getTransferMessage(
hre.getChainId(config.bridge.networkAName),
tokenContract.address,
deploymentsA.accounts.users[0].address,
bridgeContract.address,
amount,
nonce,
hre.getChainId(config.bridge.networkAName)
expiry
);
depositId = ContractUtils.getRandomId(deploymentsA.accounts.users[0].address);
const signature = await ContractUtils.signMessage(deploymentsA.accounts.users[0], message);
await expect(
bridgeContract
.connect(deploymentsA.accounts.deployer)
.depositToBridge(tokenId1, depositId, deploymentsA.accounts.users[0].address, amount, signature)
.depositToBridge(tokenId1, depositId, deploymentsA.accounts.users[0].address, amount, expiry, signature)
)
.to.emit(bridgeContract, "BridgeDeposited")
.withNamedArgs({
Expand Down
Loading

0 comments on commit 7aafee6

Please sign in to comment.