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

refactored client contract for zondax 4 #7

Closed
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 5 additions & 2 deletions client-contract/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"dependencies": {
"@zondax/filecoin-solidity": "4.0.2"
"@zondax/filecoin-solidity": "4.0.2",
"solidity-cborutils": "^2.0.0"
},
"devDependencies": {
"husky": "^8.0.3",
Expand All @@ -17,6 +18,8 @@
}
},
"lint-staged": {
"*.sol": ["npx prettier --write"]
"*.sol": [
"npx prettier --write"
]
}
}
19 changes: 10 additions & 9 deletions client-contract/src/DealClient.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {CommonTypes} from "@zondax/filecoin-solidity/contracts/v0.8/types/Common
import {AccountCBOR} from "@zondax/filecoin-solidity/contracts/v0.8/cbor/AccountCbor.sol";
import {MarketCBOR} from "@zondax/filecoin-solidity/contracts/v0.8/cbor/MarketCbor.sol";
import {BytesCBOR} from "@zondax/filecoin-solidity/contracts/v0.8/cbor/BytesCbor.sol";
import {BigNumbers} from "@zondax/filecoin-solidity/contracts/v0.8/external/BigNumbers.sol";
import {CBOR} from "@zondax/filecoin-solidity/contracts/v0.8/external/CBOR.sol";
import {BigNumbers, BigNumber} from "@zondax/solidity-bignumber/src/BigNumbers.sol";
import {CBOR} from "solidity-cborutils/contracts/CBOR.sol";
import {Misc} from "@zondax/filecoin-solidity/contracts/v0.8/utils/Misc.sol";
import {FilAddresses} from "@zondax/filecoin-solidity/contracts/v0.8/utils/FilAddresses.sol";
import {MarketDealNotifyParams, deserializeMarketDealNotifyParams, serializeDealProposal, deserializeDealProposal} from "./Types.sol";
Expand Down Expand Up @@ -190,9 +190,10 @@ contract DealClient {
ret.client = getDelegatedAddress(address(this));
polus-arcticus marked this conversation as resolved.
Show resolved Hide resolved
// Set a dummy provider. The provider that picks up this deal will need to set its own address.
ret.provider = FilAddresses.fromActorID(0);
ret.label = deal.label;
ret.start_epoch = deal.start_epoch;
ret.end_epoch = deal.end_epoch;
// not sure if isString bool should be true here cause of bytes type conversion
ret.label = CommonTypes.DealLabel(bytes(deal.label), true);
polus-arcticus marked this conversation as resolved.
Show resolved Hide resolved
ret.start_epoch = CommonTypes.ChainEpoch.wrap(deal.start_epoch);
ret.end_epoch = CommonTypes.ChainEpoch.wrap(deal.end_epoch);
ret.storage_price_per_epoch = uintToBigInt(
deal.storage_price_per_epoch
);
Expand Down Expand Up @@ -293,9 +294,9 @@ contract DealClient {
require(pieceDeals[pieceCid] > 0, "no deal published for this piece cid");

MarketTypes.GetDealActivationReturn memory ret = MarketAPI.getDealActivation(pieceDeals[pieceCid]);
if (ret.terminated > 0) {
if (CommonTypes.ChainEpoch.unwrap(ret.terminated) > 0) {
pieceStatus[pieceCid] = Status.DealTerminated;
} else if (ret.activated > 0) {
} else if (CommonTypes.ChainEpoch.unwrap(ret.activated) > 0) {
pieceStatus[pieceCid] = Status.DealActivated;
}
}
Expand All @@ -312,7 +313,7 @@ contract DealClient {
function uintToBigInt(
polus-arcticus marked this conversation as resolved.
Show resolved Hide resolved
uint256 value
) internal view returns (CommonTypes.BigInt memory) {
BigNumbers.BigNumber memory bigNumVal = BigNumbers.init(value, false);
BigNumber memory bigNumVal = BigNumbers.init(value, false);
CommonTypes.BigInt memory bigIntVal = CommonTypes.BigInt(
bigNumVal.val,
bigNumVal.neg
Expand All @@ -323,7 +324,7 @@ contract DealClient {
function bigIntToUint(
CommonTypes.BigInt memory bigInt
) internal view returns (uint256) {
BigNumbers.BigNumber memory bigNumUint = BigNumbers.init(
BigNumber memory bigNumUint = BigNumbers.init(
bigInt.val,
bigInt.neg
);
Expand Down
17 changes: 10 additions & 7 deletions client-contract/src/Types.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.17;

import {MarketTypes} from "@zondax/filecoin-solidity/contracts/v0.8/types/MarketTypes.sol";
import {CBOR} from "@zondax/filecoin-solidity/contracts/v0.8/external/CBOR.sol";
import {CBOR} from "solidity-cborutils/contracts/CBOR.sol";
import {FilecoinCBOR} from "@zondax/filecoin-solidity/contracts/v0.8/cbor/FilecoinCbor.sol";
import {CBORDecoder} from "@zondax/filecoin-solidity/contracts/v0.8/utils/CborDecode.sol";
import {CommonTypes} from "@zondax/filecoin-solidity/contracts/v0.8/types/CommonTypes.sol";
Expand All @@ -13,6 +13,7 @@ using CBORDecoder for bytes;
using BigIntCBOR for CommonTypes.BigInt;
using BigIntCBOR for bytes;
using FilecoinCBOR for CBOR.CBORBuffer;
using FilecoinCBOR for bytes;
polus-arcticus marked this conversation as resolved.
Show resolved Hide resolved

struct MarketDealNotifyParams {
bytes dealProposal;
Expand Down Expand Up @@ -48,9 +49,11 @@ function serializeDealProposal(
buf.writeBool(dealProposal.verified_deal);
buf.writeBytes(dealProposal.client.data);
buf.writeBytes(dealProposal.provider.data);
buf.writeString(dealProposal.label);
buf.writeInt64(dealProposal.start_epoch);
buf.writeInt64(dealProposal.end_epoch);
dealProposal.label.isString ?
buf.writeString(string(dealProposal.label.data)) :
buf.writeBytes(dealProposal.label.data);
buf.writeInt64(CommonTypes.ChainEpoch.unwrap(dealProposal.start_epoch));
buf.writeInt64(CommonTypes.ChainEpoch.unwrap(dealProposal.end_epoch));
buf.writeBytes(dealProposal.storage_price_per_epoch.serializeBigInt());
buf.writeBytes(dealProposal.provider_collateral.serializeBigInt());
buf.writeBytes(dealProposal.client_collateral.serializeBigInt());
Expand Down Expand Up @@ -83,9 +86,9 @@ function deserializeDealProposal(
(ret.client.data, byteIdx) = rawResp.readBytes(byteIdx);
(ret.provider.data, byteIdx) = rawResp.readBytes(byteIdx);

(ret.label, byteIdx) = rawResp.readString(byteIdx);
(ret.start_epoch, byteIdx) = rawResp.readInt64(byteIdx);
(ret.end_epoch, byteIdx) = rawResp.readInt64(byteIdx);
(ret.label, byteIdx) = rawResp.readDealLabel(byteIdx);
(ret.start_epoch, byteIdx) = rawResp.readChainEpoch(byteIdx);
(ret.end_epoch, byteIdx) = rawResp.readChainEpoch(byteIdx);

bytes memory storage_price_per_epoch_bytes;
(storage_price_per_epoch_bytes, byteIdx) = rawResp.readBytes(byteIdx);
Expand Down