Standalone

Clone Factories

close button

Part I

Factory Pattern

Download quests in Questplay

A SpiritCat is a contract that holds onto ERC20 tokens for an owner.

  • The contract is designated to a recipient who can withdraw the tokens after a set amount of time.

  • if the recipient decides to withdraw the tokens early, they can only withdraw a partial amount. The rest of the tokens will then be permanently locked until the set amount of time has passed.

  • The amount of token the recipient can withdraw early is linearly correlated to time passed.

unlockedBalance=totalBalance*(timePassed/lockTime)

We would like to design an Elaine contract that can deploy new SpiritCat contracts.

ABI of Elaine:

Events

EscrowSummoned(address escrow)

View Functions

Description

owner() -> address

Returns the creator of the contract.

Functions

Description

summon(address recipient, IERC20 token, uint256 balance, uint256 lockTime)

Creates a SpiritCat contract with the specified parameters and emits an EscrowSummoned event. Can only be called by a contract's creator.

dispel(SpiritCat cat)

Collects all remaining tokens from cat and deactivates the contract. Can only be called by a contract's creator.

ABI of SpiritCat:

View Functions

Description

isActive() -> bool

Returns whether contract is active.

recipient() -> address

Recipient of tokens.

isFullyLocked() -> bool

Returns true if the recipient has withdrawn tokens early. false otherwise.

token() -> IERC20

Address of ERC20 token.

balance() -> uint256

Amount of ERC20 token not yet withdrawn.

endTime() -> uint256

Time when the recipient can fully withdraw tokens afterwards.

unlockedBalance() -> uint256

Amount of tokens the recipient can withdraw early. Should be 0 if the contract is deactivated.

Functions

Description

withdraw()

If endTime() has not passed, transfers unlockedBalance() amount of tokens to the recipient, and locks the remainder up. Otherwise, transfers all remaining tokens to the recipient. Can only be called by the recipient and when the contract is still active.

dispel()

Can only be called by the contract's creator (i.e. Summoner). Transfers all remaining tokens to creator and deactivates itself.

Your Task

Complete the implementations in Elaine.sol and SpiritCat.sol.

You can assume that when summon() is called, Summoner has ownership of sufficient amount of the corresponding ERC20 token.

Run tests in Questplay

Spirit Cats are escrow spirits that hold onto coins for a recipient. They safekeep these coins, only returning them to their designated recipient slowly over time.