Skip to content

Commit

Permalink
chore: deploy splitter
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlagonia committed Mar 8, 2024
1 parent a8c1a97 commit 2bf290d
Show file tree
Hide file tree
Showing 4 changed files with 281 additions and 11 deletions.
4 changes: 3 additions & 1 deletion contracts/splitter/Splitter.vy
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,6 @@ def setMaxLoss(new_max_loss: uint256):
def setAuction(new_auction: address):
assert msg.sender == self.manager, "!manager"

self.auction = new_auction
self.auction = new_auction

log UpdateAuction(new_auction)
52 changes: 52 additions & 0 deletions scripts/deploy_splitter_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from ape import project, accounts, Contract, chain, networks
from hexbytes import HexBytes
from scripts.deployments import getSalt, deploy_contract


def deploy_splitter_factory():
print("Deploying Splitter Factory on ChainID", chain.chain_id)

if input("Do you want to continue? ") == "n":
return

splitter = project.Splitter
splitter_factory = project.SplitterFactory

deployer = input("Name of account to use? ")
deployer = accounts.load(deployer)

salt = getSalt("Splitter Factory")

print(f"Salt we are using {salt}")
print("Init balance:", deployer.balance / 1e18)

print(f"Deploying Original.")

original_deploy_bytecode = HexBytes(
HexBytes(splitter.contract_type.deployment_bytecode.bytecode)
)

original_address = deploy_contract(original_deploy_bytecode, salt, deployer)

print(f"Original deployed to {original_address}")

allocator_constructor = splitter_factory.constructor.encode_input(original_address)

# generate and deploy
deploy_bytecode = HexBytes(
HexBytes(splitter_factory.contract_type.deployment_bytecode.bytecode)
+ allocator_constructor
)

print(f"Deploying the Factory...")

deploy_contract(deploy_bytecode, salt, deployer)

print("------------------")
print(
f"Encoded Constructor to use for verifaction {allocator_constructor.hex()[2:]}"
)


def main():
deploy_splitter_factory()
2 changes: 2 additions & 0 deletions scripts/deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ def deploy_contract(init_code, salt, deployer):

print("------------------")
print(f"Deployed the contract to {address}")

return address
234 changes: 224 additions & 10 deletions tests/splitter/test_splitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,37 @@ def test_split_setup(splitter_factory, splitter, daddy, brain, management):
assert splitter.maxLoss() == 1
assert splitter.auction() == ZERO_ADDRESS

def test_unwrap(splitter, daddy, vault, mock_tokenized, strategy, asset, user, amount):

def test_unwrap(
splitter, daddy, vault, mock_tokenized, deploy_mock_tokenized, asset, user, amount
):
assert splitter.manager() == daddy

second_strategy = deploy_mock_tokenized()

amount = amount // 3

asset.approve(vault, amount, sender=user)
asset.approve(mock_tokenized, amount, sender=user)
asset.approv(strategy, amount, sender=user)
asset.approve(second_strategy, amount, sender=user)

vault.deposit(amount, splitter, sender=user)
mock_tokenized.deposit(amount, splitter, sender=user)
strategy.deposit(amount, splitter, sender=user)
second_strategy.deposit(amount, splitter, sender=user)

assert vault.balanceOf(splitter) == amount
assert mock_tokenized.balanceOf(splitter) == amount
assert strategy.balanceOf(splitter) == amount
assert second_strategy.balanceOf(splitter) == amount
assert asset.balanceOf(splitter) == 0

with ape.reverts("!allowed"):
splitter.unwrapVault(strategy, sender=user)
splitter.unwrapVault(second_strategy, sender=user)

splitter.unwrapVault(strategy, sender=daddy)
splitter.unwrapVault(second_strategy, sender=daddy)

assert vault.balanceOf(splitter) == 0
assert vault.balanceOf(splitter) == amount
assert mock_tokenized.balanceOf(splitter) == amount
assert strategy.balanceOf(splitter) == amount
assert second_strategy.balanceOf(splitter) == 0
assert asset.balanceOf(splitter) == amount

vaults = [vault, mock_tokenized]
Expand All @@ -50,5 +55,214 @@ def test_unwrap(splitter, daddy, vault, mock_tokenized, strategy, asset, user, a

assert vault.balanceOf(splitter) == 0
assert mock_tokenized.balanceOf(splitter) == 0
assert strategy.balanceOf(splitter) == 0
assert asset.balanceOf(splitter) == amount * 3
assert second_strategy.balanceOf(splitter) == 0
assert asset.balanceOf(splitter) == amount * 3


def test_distribute(
splitter,
daddy,
vault,
mock_tokenized,
deploy_mock_tokenized,
asset,
user,
management,
brain,
amount,
):
assert splitter.manager() == daddy
recipeint = management
splitee = brain
split = 5_000

second_strategy = deploy_mock_tokenized()

amount = amount // 4

asset.approve(vault, amount, sender=user)
asset.approve(mock_tokenized, amount, sender=user)
asset.approve(second_strategy, amount, sender=user)

vault.deposit(amount, splitter, sender=user)
mock_tokenized.deposit(amount, splitter, sender=user)
second_strategy.deposit(amount, splitter, sender=user)

assert vault.balanceOf(splitter) == amount
assert vault.balanceOf(recipeint) == 0
assert vault.balanceOf(splitee) == 0

assert mock_tokenized.balanceOf(splitter) == amount
assert mock_tokenized.balanceOf(recipeint) == 0
assert mock_tokenized.balanceOf(splitee) == 0

assert second_strategy.balanceOf(splitter) == amount
assert second_strategy.balanceOf(recipeint) == 0
assert second_strategy.balanceOf(splitee) == 0

with ape.reverts("!allowed"):
splitter.distributeToken(second_strategy, sender=user)

splitter.distributeToken(second_strategy, sender=daddy)

assert second_strategy.balanceOf(splitter) == 0
assert second_strategy.balanceOf(recipeint) == amount / 2
assert second_strategy.balanceOf(splitee) == amount / 2

vaults = [vault, mock_tokenized]

with ape.reverts("!allowed"):
splitter.distributeTokens(vaults, sender=user)

splitter.distributeTokens(vaults, sender=daddy)

assert vault.balanceOf(splitter) == 0
assert vault.balanceOf(recipeint) == amount / 2
assert vault.balanceOf(splitee) == amount / 2

assert mock_tokenized.balanceOf(splitter) == 0
assert mock_tokenized.balanceOf(recipeint) == amount / 2
assert mock_tokenized.balanceOf(splitee) == amount / 2


def test_auction(
splitter,
daddy,
vault,
mock_tokenized,
deploy_mock_tokenized,
asset,
user,
management,
brain,
amount,
):
assert splitter.manager() == daddy
auction = user

second_strategy = deploy_mock_tokenized()

amount = amount // 4

asset.approve(vault, amount, sender=user)
asset.approve(mock_tokenized, amount, sender=user)
asset.approve(second_strategy, amount, sender=user)

vault.deposit(amount, splitter, sender=user)
mock_tokenized.deposit(amount, splitter, sender=user)
second_strategy.deposit(amount, splitter, sender=user)

assert vault.balanceOf(splitter) == amount
assert vault.balanceOf(auction) == 0

assert mock_tokenized.balanceOf(splitter) == amount
assert mock_tokenized.balanceOf(auction) == 0

assert second_strategy.balanceOf(splitter) == amount
assert second_strategy.balanceOf(auction) == 0

with ape.reverts("!allowed"):
splitter.fundAuction(second_strategy, sender=user)

with ape.reverts():
splitter.fundAuction(second_strategy, sender=daddy)

splitter.setAuction(auction, sender=daddy)

splitter.fundAuction(second_strategy, sender=daddy)

assert second_strategy.balanceOf(splitter) == 0
assert second_strategy.balanceOf(auction) == amount

vaults = [vault, mock_tokenized]

with ape.reverts("!allowed"):
splitter.fundAuctions(vaults, sender=user)

splitter.fundAuctions(vaults, sender=daddy)

assert vault.balanceOf(splitter) == 0
assert vault.balanceOf(auction) == amount

assert mock_tokenized.balanceOf(splitter) == 0
assert mock_tokenized.balanceOf(auction) == amount


def test_setters(splitter, daddy, user, brain, management):
recipeint = management
splitee = brain
split = 5_000
max_loss = 1

new_recipient = user

assert splitter.managerRecipient() == recipeint

with ape.reverts("!manager"):
splitter.setMangerRecipient(new_recipient, sender=brain)

assert splitter.managerRecipient() == recipeint

tx = splitter.setMangerRecipient(new_recipient, sender=daddy)

assert splitter.managerRecipient() == new_recipient
assert (
list(tx.decode_logs(splitter.UpdateManagerRecipient))[0].newManagerRecipient
== new_recipient
)

new_splitee = user

assert splitter.splitee() == splitee

with ape.reverts("!splitee"):
splitter.setSplitee(new_splitee, sender=daddy)

assert splitter.splitee() == splitee

tx = splitter.setSplitee(new_splitee, sender=brain)

assert splitter.splitee() == new_splitee
assert list(tx.decode_logs(splitter.UpdateSplitee))[0].newSplitee == new_splitee

new_split = 123

assert splitter.split() == split

with ape.reverts("!manager"):
splitter.setSplit(new_split, sender=brain)

assert splitter.split() == split

tx = splitter.setSplit(new_split, sender=daddy)

assert splitter.split() == new_split
assert list(tx.decode_logs(splitter.UpdateSplit))[0].newSplit == new_split

new_max_loss = 123

assert splitter.maxLoss() == max_loss

with ape.reverts("!manager"):
splitter.setMaxLoss(new_max_loss, sender=brain)

assert splitter.maxLoss() == max_loss

tx = splitter.setMaxLoss(new_split, sender=daddy)

assert splitter.maxLoss() == new_max_loss
assert list(tx.decode_logs(splitter.UpdateMaxLoss))[0].newMaxLoss == new_max_loss

new_auction = user

assert splitter.auction() == ZERO_ADDRESS

with ape.reverts("!manager"):
splitter.setAuction(new_auction, sender=brain)

assert splitter.auction() == ZERO_ADDRESS

tx = splitter.setAuction(new_auction, sender=daddy)

assert splitter.auction() == new_auction
assert list(tx.decode_logs(splitter.UpdateAuction))[0].newAuction == new_auction

0 comments on commit 2bf290d

Please sign in to comment.