Skip to content

Commit

Permalink
add doc comment for DMCBridge.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
waterflier committed Jul 16, 2024
1 parent 5f2a0db commit 320022d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
28 changes: 24 additions & 4 deletions contracts/dmc_bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,53 @@ import "@openzeppelin/contracts/access/Ownable.sol";
contract DMCBridge is Ownable {
DMC public dmc2;

// DMC1到2的兑换
mapping(bytes32 => uint256) public dmc1_to_dmc2;

constructor(address _dmc2) Ownable(msg.sender) {
dmc2 = DMC(_dmc2);
}

/**
* @dev Retrieves the amount of claimable DMC2 tokens for a given cookie.
* @param cookie The cookie associated with the claimable DMC2 tokens.
* @return The amount of claimable DMC2 tokens.
*/
function getClaimableDMC2(string calldata cookie) public view returns (uint256) {
return dmc1_to_dmc2[keccak256(abi.encodePacked(msg.sender, cookie))];
}

/**
* @dev Registers DMC1 transfor request for claimDMC2
* @param recvAddress The array of recipient addresses.
* @param cookie The array of cookie values associated with each recipient.
* @param dmc1Amount The array of DMC1 token amounts to be registered for each recipient.
* @notice recvAddress, cookie and dmc1Amount must have the same length
*/
function registerDMC1(address[] calldata recvAddress, string[] calldata cookie, uint256[] calldata dmc1Amount) onlyOwner public {
for (uint i = 0; i < recvAddress.length; i++) {
dmc1_to_dmc2[keccak256(abi.encodePacked(recvAddress[i], cookie[i]))] = dmc1Amount[i];
}

}
}

/**
* @dev Allows a user to claim DMC2 tokens.
* @param cookie The cookie string for authentication.
* @notice cookie must same as the one used in registerDMC1
*/
function claimDMC2(string calldata cookie) public {
// function implementation goes here
}
bytes32 key = keccak256(abi.encodePacked(msg.sender, cookie));
require(dmc1_to_dmc2[key] > 0, "no dmc1 amount");
uint256 dmc2Amount = dmc1_to_dmc2[key];
dmc1_to_dmc2[key] = 0;

dmc2.transfer(msg.sender, dmc2Amount);
}


/**
* @dev Allows the owner to claim remaining DMC2 tokens.
*/
function claimRemainDMC2() public onlyOwner {
dmc2.transfer(msg.sender, dmc2.balanceOf(address(this)));
}
Expand Down
11 changes: 11 additions & 0 deletions doc/gwt_mine.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# 算力奖励的核心思路,是资本回报逻辑
# 矿工出售空间,质押了7500个 GWT,按质押率 3倍来算,在结束时可以得到2500个GWT的收入,那么通过算力奖励,要得到多少附加的GWT》
# 用户花了2500个GWT购买空间,那么通过算力奖励,其实际开销相当于打了几折呢?

# 因为我们不使用自动匹配机制,所以存在矿工左手倒右手的问题,一共是锁定了10000个GWT,那么其算力奖励的收入在2000GWT到 250GWT之间。
# 因为不使用自动匹配机制,无存储空间的矿工会Cancel不是自己左手的订单。系统通过增加Cancel时间提高了矿工的资金成本
# 用户一般不承担Cancel的手续费(因为锁定的资金比矿工少)
# Fake用户攻击,准备一些GWT,然后不断的去买空间,单不传数据等取消。这样的行为会导致整个DMC网络的实际GWT利用率低下。这样的用户行为是损人不直接利己的,比较适合GWT的大户来提高挖矿难度。

# 算力奖励与price无关,只和质押率有关。也就是说,站在提高算力的角度,系统鼓励高质押率,低价格的存储空间。

# x的含义是当前的增长率
def mine_gwt(x):
return 0.2 + (1.8*x) / (x + 1)
Expand Down

0 comments on commit 320022d

Please sign in to comment.