Skip to content

Commit

Permalink
fix DepegDistribution and tests for usage /w USDT
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiaszimmermann committed Aug 4, 2024
1 parent 76bf0ba commit b7be31b
Show file tree
Hide file tree
Showing 11 changed files with 558 additions and 4 deletions.
9 changes: 5 additions & 4 deletions contracts/DepegDistribution.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity 0.8.2;

import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@etherisc/gif-interface/contracts/modules/IRegistry.sol";
import "@etherisc/gif-interface/contracts/services/IInstanceService.sol";

Expand Down Expand Up @@ -124,7 +125,7 @@ contract DepegDistribution is
bundleId);

// create allowance for net premium
_token.approve(_treasury, premiumNetAmount);
SafeERC20.safeIncreaseAllowance(_token, _treasury, premiumNetAmount);

// create policy
// this will transfer premium amount from this contract to depeg (and keep the commission in this contract)
Expand Down Expand Up @@ -167,7 +168,7 @@ contract DepegDistribution is
info.updatedAt = block.timestamp;

// collect total premium amount
_token.transferFrom(buyer, address(this), premiumTotalAmount);
SafeERC20.safeTransferFrom(_token, buyer, address (this), premiumTotalAmount);

emit LogDistributionInfoUpdated(distributor, commissionAmount, info.commissionBalance, info.policiesSold);
}
Expand Down Expand Up @@ -220,7 +221,7 @@ contract DepegDistribution is
onlyOwner()
{
require(_token.balanceOf(address(this)) >= amount, "ERROR:DST-040:BALANCE_INSUFFICIENT");
require(_token.transfer(owner(), amount), "ERROR:DST-041:WITHDRAWAL_FAILED");
SafeERC20.safeTransfer(_token, owner(), amount);
}

function withdrawCommission(uint256 amount)
Expand All @@ -236,7 +237,7 @@ contract DepegDistribution is
info.commissionBalance -= amount;
info.updatedAt = block.timestamp;

require(_token.transfer(distributor, amount), "ERROR:DST-052:WITHDRAWAL_FAILED");
SafeERC20.safeTransfer(_token, distributor, amount);
}

function getToken() external view returns (address token) {
Expand Down
14 changes: 14 additions & 0 deletions contracts/experiment/IUniswapV2Router.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;

// Interface for Uniswap V2 Router
interface IUniswapV2Router {
function swapExactETHForTokens(
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external payable returns (uint256[] memory amounts);

function WETH() external pure returns (address);

Check warning on line 13 in contracts/experiment/IUniswapV2Router.sol

View workflow job for this annotation

GitHub Actions / Compile and run tests

Function name must be in mixedCase
}
Loading

0 comments on commit b7be31b

Please sign in to comment.