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

Apply dms-contracts-lib-v2 version 2.1.3 #119

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"@ethersproject/providers": "^5.7.0",
"@ethersproject/random": "^5.7.0",
"@ethersproject/wallet": "^5.7.0",
"dms-contracts-lib-v2": "~2.1.1",
"dms-contracts-lib-v2": "~2.1.3",
"dms-sdk-common-v2": "~2.0.0",
"unfetch": "^5.0.0"
},
Expand Down
26 changes: 26 additions & 0 deletions packages/client/src/utils/ContractUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,32 @@ export class ContractUtils {
return arrayify(keccak256(encodedResult));
}

public static getCurrencyProposeMessage(
height: BigNumberish,
rates: { symbol: string; rate: BigNumberish }[],
signatures: BytesLike[],
chainId: BigNumberish
): Uint8Array {
const messages: BytesLike[] = [];
for (const elem of rates) {
const encodedData = defaultAbiCoder.encode(
["string", "uint256", "uint256"],
[elem.symbol, elem.rate, chainId]
);
messages.push(keccak256(encodedData));
}
const signaturesMessages: BytesLike[] = [];
for (const elem of signatures) {
const encodedData = defaultAbiCoder.encode(["bytes32", "uint256"], [keccak256(elem), chainId]);
signaturesMessages.push(keccak256(encodedData));
}
const encodedResult = defaultAbiCoder.encode(
["uint256", "uint256", "bytes32[]", "bytes32[]"],
[height, rates.length, messages, signaturesMessages]
);
return arrayify(keccak256(encodedResult));
}

public static getTransferMessage(
chainId: BigNumberish,
tokenAddress: string,
Expand Down
6 changes: 4 additions & 2 deletions packages/client/test/helper/NodeInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,10 @@ export class NodeInfo {
}
];
const message = ContractUtils.getCurrencyMessage(height, rates, NodeInfo.CHAIN_ID);
const signatures = validators.map((m) => ContractUtils.signMessage(m, message));
const tx1 = await currencyRateContract.connect(validators[0]).set(height, rates, signatures);
const signatures = await Promise.all(validators.map((m) => ContractUtils.signMessage(m, message)));
const proposeMessage = ContractUtils.getCurrencyProposeMessage(height, rates, signatures, NodeInfo.CHAIN_ID);
const proposerSignature = await ContractUtils.signMessage(validators[0], proposeMessage);
const tx1 = await currencyRateContract.connect(validators[0]).set(height, rates, signatures, proposerSignature);
await tx1.wait();
}

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2878,10 +2878,10 @@ dir-glob@^3.0.1:
dependencies:
path-type "^4.0.0"

dms-contracts-lib-v2@~2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/dms-contracts-lib-v2/-/dms-contracts-lib-v2-2.1.1.tgz#d1d5d1d94fcd6da143efe26ef43d26fd65e293a8"
integrity sha512-Aha8v4WoklrjFgjx/o3Go2CdL7YmJTNetmBAF9LSfpiTdFnc+UZJMTLFgmwCDLuSwdY6rEZuKZiKXOEMZEWcUg==
dms-contracts-lib-v2@~2.1.3:
version "2.1.3"
resolved "https://registry.yarnpkg.com/dms-contracts-lib-v2/-/dms-contracts-lib-v2-2.1.3.tgz#bff92af26a4d09c9c1d71ac60877b5b58a55c70f"
integrity sha512-8CyknpGYYLYMfRWbWKDvQ6bnQnCBCgKsGwpqgbOmd/CwA0/GYrc5L7EXO3nJhRW59gDlG0/HRFpca0iefdXX5g==
dependencies:
ethers "5.7.0"

Expand Down
Loading