Skip to content

Commit

Permalink
tasks: remove depositor token source
Browse files Browse the repository at this point in the history
  • Loading branch information
facuspagnuolo committed Nov 21, 2023
1 parent 109522f commit 16fcd4e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 90 deletions.
16 changes: 0 additions & 16 deletions packages/tasks/contracts/interfaces/primitives/IDepositor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,6 @@ interface IDepositor is ITask {
*/
error TaskPreviousConnectorNotZero(bytes32 id);

/**
* @dev The tokens source to be set is not the contract itself
*/
error TaskDepositorBadTokensSource(address tokensSource);

/**
* @dev Emitted every time the tokens source is set
*/
event TokensSourceSet(address indexed tokensSource);

/**
* @dev Sets the tokens source address
* @param tokensSource Address of the tokens source to be set
*/
function setTokensSource(address tokensSource) external;

/**
* @dev Executes the withdrawer task
*/
Expand Down
28 changes: 3 additions & 25 deletions packages/tasks/contracts/primitives/Depositor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,10 @@ contract Depositor is IDepositor, Task {
// Execution type for relayers
bytes32 public constant override EXECUTION_TYPE = keccak256('DEPOSITOR');

// Address from where the tokens will be pulled
address internal _tokensSource;

/**
* @dev Deposit config. Only used in the initializer.
*/
struct DepositConfig {
address tokensSource;
TaskConfig taskConfig;
}

Expand All @@ -63,14 +59,14 @@ contract Depositor is IDepositor, Task {
* @param config Deposit config
*/
function __Depositor_init_unchained(DepositConfig memory config) internal onlyInitializing {
_setTokensSource(config.tokensSource);
// solhint-disable-previous-line no-empty-blocks
}

/**
* @dev Tells the address from where the token amounts to execute this task are fetched
*/
function getTokensSource() public view virtual override(IBaseTask, BaseTask) returns (address) {
return _tokensSource;
return address(this);
}

/**
Expand All @@ -81,14 +77,6 @@ contract Depositor is IDepositor, Task {
return ERC20Helpers.balanceOf(token, getTokensSource());
}

/**
* @dev Sets the tokens source address. Sender must be authorized.
* @param tokensSource Address of the tokens source to be set
*/
function setTokensSource(address tokensSource) external override authP(authParams(tokensSource)) {
_setTokensSource(tokensSource);
}

/**
* @dev It allows receiving native token transfers
*/
Expand All @@ -107,7 +95,7 @@ contract Depositor is IDepositor, Task {
Address.sendValue(payable(smartVault), amount);
} else {
ERC20Helpers.approve(token, smartVault, amount);
ISmartVault(smartVault).collect(token, _tokensSource, amount);
ISmartVault(smartVault).collect(token, getTokensSource(), amount);
}

_afterDepositor(token, amount);
Expand Down Expand Up @@ -139,14 +127,4 @@ contract Depositor is IDepositor, Task {
if (previous != bytes32(0)) revert TaskPreviousConnectorNotZero(previous);
super._setBalanceConnectors(previous, next);
}

/**
* @dev Sets the source address
* @param tokensSource Address of the tokens source to be set
*/
function _setTokensSource(address tokensSource) internal virtual {
if (tokensSource != address(this)) revert TaskDepositorBadTokensSource(tokensSource);
_tokensSource = tokensSource;
emit TokensSourceSet(tokensSource);
}
}
50 changes: 1 addition & 49 deletions packages/tasks/test/primitives/Depositor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
deployProxy,
deployTokenMock,
fp,
getSigner,
getSigners,
NATIVE_TOKEN_ADDRESS,
ZERO_ADDRESS,
Expand All @@ -16,7 +15,6 @@ import {
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/dist/src/signer-with-address'
import { expect } from 'chai'
import { Contract } from 'ethers'
import { getContractAddress } from 'ethers/lib/utils'
import { ethers } from 'hardhat'

import { buildEmptyTaskConfig, deployEnvironment } from '../../src/setup'
Expand All @@ -32,13 +30,7 @@ describe('Depositor', () => {
})

beforeEach('deploy task', async () => {
const deployer = await getSigner()
const tokensSource = getContractAddress({
from: deployer.address,
nonce: (await deployer.getTransactionCount()) + 1,
})

task = await deployProxy('Depositor', [], [{ tokensSource, taskConfig: buildEmptyTaskConfig(owner, smartVault) }])
task = await deployProxy('Depositor', [], [{ taskConfig: buildEmptyTaskConfig(owner, smartVault) }])
})

describe('execution type', () => {
Expand Down Expand Up @@ -68,46 +60,6 @@ describe('Depositor', () => {
})
})

describe('setTokensSource', () => {
context('when the sender is authorized', async () => {
beforeEach('set sender', async () => {
const setTokensSourceRole = task.interface.getSighash('setTokensSource')
await authorizer.connect(owner).authorize(owner.address, task.address, setTokensSourceRole, [])
task = task.connect(owner)
})

context('when the new address is the task itself', async () => {
let newTokensSource: string

beforeEach('set new tokens source', async () => {
newTokensSource = task.address
})

it('sets the tokens source', async () => {
await task.setTokensSource(newTokensSource)
expect(await task.getTokensSource()).to.be.equal(newTokensSource)
})

it('emits an event', async () => {
const tx = await task.setTokensSource(newTokensSource)
await assertEvent(tx, 'TokensSourceSet', { tokensSource: newTokensSource })
})
})

context('when the new address is another', async () => {
it('reverts', async () => {
await expect(task.setTokensSource(ZERO_ADDRESS)).to.be.revertedWith('TaskDepositorBadTokensSource')
})
})
})

context('when the sender is not authorized', () => {
it('reverts', async () => {
await expect(task.setTokensSource(ZERO_ADDRESS)).to.be.revertedWith('AuthSenderNotAllowed')
})
})
})

describe('call', () => {
beforeEach('authorize task', async () => {
const collectRole = smartVault.interface.getSighash('collect')
Expand Down

0 comments on commit 16fcd4e

Please sign in to comment.