Skip to content

Commit

Permalink
Include fee setters
Browse files Browse the repository at this point in the history
  • Loading branch information
michwill committed Oct 4, 2023
1 parent bcbd8cb commit 5272fd2
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions contracts/implementations/plain-2/Plain2Price.vy
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,21 @@ event StopRampA:
A: uint256
t: uint256

event CommitNewFee:
new_fee: uint256

event ApplyNewFee:
fee: uint256


N_COINS: constant(int128) = 2
N_COINS_256: constant(uint256) = 2
PRECISION: constant(uint256) = 10 ** 18

FEE_DENOMINATOR: constant(uint256) = 10 ** 10
ADMIN_FEE: constant(uint256) = 5000000000
MAX_FEE: constant(uint256) = 5 * 10 ** 9
ADMIN_ACTIONS_DEADLINE_DT: constant(uint256) = 86400 * 3

A_PRECISION: constant(uint256) = 100
MAX_A: constant(uint256) = 10 ** 6
Expand All @@ -100,6 +108,8 @@ originator: address
coins: public(address[N_COINS])
balances: public(uint256[N_COINS])
fee: public(uint256) # fee * 1e10
future_fee: public(uint256)
admin_action_deadline: public(uint256)

initial_A: public(uint256)
future_A: public(uint256)
Expand Down Expand Up @@ -127,7 +137,7 @@ nonces: public(HashMap[address, uint256])
@external
def __init__():
# we do this to prevent the implementation contract from being used as a pool
self.fee = 31337
self.factory = 0x0000000000000000000000000000000000000001


@external
Expand All @@ -148,8 +158,8 @@ def initialize(
@param _A Amplification coefficient multiplied by n ** (n - 1)
@param _fee Fee to charge for exchanges
"""
# check if fee was already set to prevent initializing contract twice
assert self.fee == 0
# check if factory was already set to prevent initializing contract twice
assert self.factory == empty(address)

# tx.origin will have the ability to set oracles for coins
self.originator = tx.origin
Expand Down Expand Up @@ -1126,6 +1136,29 @@ def admin_balances(i: uint256) -> uint256:
return ERC20(self.coins[i]).balanceOf(self) - self.balances[i]


@external
def commit_new_fee(_new_fee: uint256):
assert msg.sender == Factory(self.factory).admin()
assert _new_fee <= MAX_FEE
assert self.admin_action_deadline == 0

self.future_fee = _new_fee
self.admin_action_deadline = block.timestamp + ADMIN_ACTIONS_DEADLINE_DT
log CommitNewFee(_new_fee)


@external
def apply_new_fee():
assert msg.sender == Factory(self.factory).admin()
deadline: uint256 = self.admin_action_deadline
assert deadline != 0 and block.timestamp >= deadline

fee: uint256 = self.future_fee
self.fee = fee
self.admin_action_deadline = 0
log ApplyNewFee(fee)


@external
def withdraw_admin_fees():
receiver: address = Factory(self.factory).get_fee_receiver(self)
Expand Down

0 comments on commit 5272fd2

Please sign in to comment.