Skip to content

Commit

Permalink
[Contract] Apply dms-bridge-contracts 1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKim20 committed May 2, 2024
1 parent 0664fb3 commit 180a2c8
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/contracts-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dms-osx-lib",
"version": "2.12.0",
"version": "2.14.0",
"description": "",
"main": "dist/bundle-cjs.js",
"module": "dist/bundle-esm.js",
Expand Down
30 changes: 27 additions & 3 deletions packages/contracts/contracts/controllers/LoyaltyBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ contract LoyaltyBridge is LoyaltyBridgeStorage, Initializable, OwnableUpgradeabl
__Ownable_init_unchained();

fee = 5e18;
feePolicy = IBridge.FeePolicy.FixedFee;
validatorContract = IBridgeValidator(_validatorAddress);

isSetLedger = false;
Expand Down Expand Up @@ -75,6 +76,16 @@ contract LoyaltyBridge is LoyaltyBridgeStorage, Initializable, OwnableUpgradeabl
else return false;
}

function calculateFee(bytes32 _tokenId, uint256 _amount) internal returns (uint256) {
uint256 value = 0;
if (feePolicy == IBridge.FeePolicy.FixedFee) {
value = fee;
} else {
value = (((_amount * fee) / 10000) / 1 gwei) * 1 gwei;
}
return value;
}

/// @notice 브리지에 자금을 에치합니다.
function depositToBridge(
bytes32 _tokenId,
Expand All @@ -91,8 +102,9 @@ contract LoyaltyBridge is LoyaltyBridgeStorage, Initializable, OwnableUpgradeabl
require(ECDSA.recover(ECDSA.toEthSignedMessageHash(dataHash), _signature) == _account, "1501");
require(ledgerContract.loyaltyTypeOf(_account) == ILedger.LoyaltyType.TOKEN, "1520");
require(ledgerContract.tokenBalanceOf(_account) >= _amount, "1511");
uint256 feeValue = calculateFee(_tokenId, _amount);
require(_amount % 1 gwei == 0, "1030");
require(_amount > fee * 2, "1031");
require(_amount > feeValue, "1031");

ledgerContract.transferToken(_account, address(this), _amount);
ledgerContract.increaseNonce(_account);
Expand Down Expand Up @@ -128,7 +140,8 @@ contract LoyaltyBridge is LoyaltyBridgeStorage, Initializable, OwnableUpgradeabl
confirmations[_withdrawId][_msgSender()] = true;

if (!withdraws[_withdrawId].executed && _isConfirmed(_withdrawId)) {
uint256 withdrawalAmount = _amount - fee;
uint256 feeValue = calculateFee(_tokenId, withdraws[_withdrawId].amount);
uint256 withdrawalAmount = _amount - feeValue;
if (ledgerContract.tokenBalanceOf(address(this)) >= withdraws[_withdrawId].amount) {
ledgerContract.transferToken(address(this), _account, withdrawalAmount);
ledgerContract.transferToken(address(this), txFeeAccount, fee);
Expand All @@ -149,7 +162,8 @@ contract LoyaltyBridge is LoyaltyBridgeStorage, Initializable, OwnableUpgradeabl
bytes32 _withdrawId
) external override onlyValidator(_msgSender()) existWithdraw(_withdrawId) {
if (!withdraws[_withdrawId].executed && _isConfirmed(_withdrawId)) {
uint256 withdrawalAmount = withdraws[_withdrawId].amount - fee;
uint256 feeValue = calculateFee(tokenId, withdraws[_withdrawId].amount);
uint256 withdrawalAmount = withdraws[_withdrawId].amount - feeValue;
if (ledgerContract.tokenBalanceOf(address(this)) >= withdraws[_withdrawId].amount) {
ledgerContract.transferToken(address(this), withdraws[_withdrawId].account, withdrawalAmount);
ledgerContract.transferToken(address(this), txFeeAccount, fee);
Expand Down Expand Up @@ -206,6 +220,16 @@ contract LoyaltyBridge is LoyaltyBridgeStorage, Initializable, OwnableUpgradeabl
fee = _fee;
}

function getFeePolicy(bytes32 _tokenId) external view override returns (IBridge.FeePolicy) {
return feePolicy;
}

function changeFeePolicy(bytes32 _tokenId, IBridge.FeePolicy _feePolicy) external override {
require(_tokenId == tokenId, "1713");
require(_msgSender() == owner(), "1050");
feePolicy = _feePolicy;
}

/// @notice 전체 유동성 자금을 조회합니다.
function getTotalLiquidity(bytes32 _tokenId) external view override returns (uint256) {
require(_tokenId == tokenId, "1713");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ contract LoyaltyBridgeStorage {
address internal txFeeAccount;

uint256 internal fee;
IBridge.FeePolicy internal feePolicy;

bool internal isSetLedger;
ILedger internal ledgerContract;
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-osx-artifacts",
"version": "2.12.0",
"version": "2.13.0",
"description": "Smart contracts that decentralized point systems",
"files": [
"**/*.sol"
Expand Down Expand Up @@ -67,7 +67,7 @@
},
"dependencies": {
"del-osx-artifacts": "^2.3.0",
"dms-bridge-contracts": "^1.3.0",
"dms-bridge-contracts": "^1.4.0",
"multisig-wallet-contracts": "^1.1.0",
"loyalty-tokens": "^1.1.0"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/faker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
"axios": "^1.6.7",
"chai": "^4.3.7",
"del-osx-artifacts": "^2.3.0",
"dms-bridge-contracts": "^1.3.0",
"dms-osx-artifacts": "^2.12.0",
"dms-bridge-contracts": "^1.4.0",
"dms-osx-artifacts": "^2.13.0",
"dotenv": "^10.0.0",
"ethereum-waffle": "^4.0.10",
"ethers": "5.7.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/relay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
"chai-http": "^4.3.7",
"cors": "^2.8.5",
"del-osx-artifacts": "^2.3.0",
"dms-bridge-contracts": "^1.3.0",
"dms-osx-artifacts": "^2.12.0",
"dms-bridge-contracts": "^1.4.0",
"dms-osx-artifacts": "^2.13.0",
"dotenv": "^10.0.0",
"ethereum-waffle": "^4.0.10",
"ethereumjs-util": "^7.1.5",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3350,10 +3350,10 @@ [email protected]:
resolved "https://registry.yarnpkg.com/discontinuous-range/-/discontinuous-range-1.0.0.tgz#e38331f0844bba49b9a9cb71c771585aab1bc65a"
integrity sha512-c68LpLbO+7kP/b1Hr1qs8/BJ09F5khZGTxqxZuhzxpmwJKOgRFHJWIb9/KmqnqHhLdO55aOxFH/EGBvUQbL/RQ==

dms-bridge-contracts@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/dms-bridge-contracts/-/dms-bridge-contracts-1.3.0.tgz#ba37c2171c49571aef9184cc917e5f1570162d96"
integrity sha512-o/s8iJwRJl+tNGYN0BddojF3LbAXZG6aKnsl+qUmpo/QO3QWwx4N4LJsxgiSwDLCrcbdEBHS5kP7GwqfwO2mOA==
dms-bridge-contracts@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/dms-bridge-contracts/-/dms-bridge-contracts-1.4.0.tgz#d1d09dbd389e83a2077f022146b53c2ade23340f"
integrity sha512-2xb7W8R1xiFDNoPadkA6tW/tS01So/imZ+nwtoD3wGAq/NUhYwhAGAx2JauOCvJvMXnQGVph84YkVt/oAjVQGg==

dns-over-http-resolver@^1.2.3:
version "1.2.3"
Expand Down

0 comments on commit 180a2c8

Please sign in to comment.