Skip to content

Commit

Permalink
feat: auction option
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlagonia committed Feb 15, 2024
1 parent ad57e52 commit 13f569e
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions contracts/splitter/Splitter.vy
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ interface IVault:
def redeem(shares: uint256, receiver: address, owner: address, max_loss: uint256) -> uint256: nonpayable
def transfer(receiver: address, amount: uint256) -> bool: nonpayable

interface IAuction:
def getAuctionId(from_token: address) -> bytes32: view
def auctionInfo(auction_id: bytes32) -> (address, address, uint256, uint256): view

event UpdateManagerRecipient:
newManagerRecipient: indexed(address)

Expand All @@ -18,6 +22,9 @@ event UpdateSplit:
event UpdateMaxLoss:
newMaxLoss: uint256

event UpdateAuction:
newAuction: address

MAX_BPS: constant(uint256) = 10_000
MAX_ARRAY_SIZE: public(constant(uint256)) = 20

Expand All @@ -35,6 +42,9 @@ split: public(uint256)
# Max loss to use on vault redeems
maxLoss: public(uint256)

# Address of the contract to conduct dutch auctions for token sales
auction: public(address)

@external
def initialize(
name: String[64],
Expand Down Expand Up @@ -108,6 +118,37 @@ def _distribute(token: address, split: uint256, manager_recipient: address, spli
assert IVault(token).transfer(manager_recipient, manager_split, default_return_value=True), "transfer failed"
assert IVault(token).transfer(splitee, unsafe_sub(current_balance, manager_split), default_return_value=True), "transfer failed"


###### AUCTION INITIATORS ######

@external
def fundAuctions(tokens: DynArray[address, MAX_ARRAY_SIZE]):
assert msg.sender == self.splitee or msg.sender == self.manager, "!allowed"
auction: address = self.auction

for token in tokens:
amount: uint256 = IVault(token).balanceOf(self)
self._fundAuction(token, auction, amount)

@external
def fundAuction(token: address, amount: uint256 = max_value(uint256)):
assert msg.sender == self.splitee or msg.sender == self.manager, "!allowed"

to_send: uint256 = amount
if(amount == max_value(uint256)):
to_send = IVault(token).balanceOf(self)

self._fundAuction(token, self.auction, to_send)

@internal
def _fundAuction(token: address, auction: address, amount: uint256):
# Make sure the auction is set is enabled for this token
from_token: address = IAuction(auction).auctionInfo(IAuction(auction).getAuctionId(token))[0]
assert from_token == token, "not enabled"

# Send tokens to the auction contract.
assert IVault(token).transfer(auction, amount, default_return_value=True), "transfer failed"

###### SETTERS ######

# update recipients
Expand Down Expand Up @@ -149,3 +190,9 @@ def setMaxLoss(new_max_loss: uint256):
self.maxLoss = new_max_loss

log UpdateMaxLoss(new_max_loss)

@external
def setAuction(new_auction: address):
assert msg.sender == self.manager, "!manager"

self.auction = new_auction

0 comments on commit 13f569e

Please sign in to comment.