Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions contracts/bonding/BondingManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
// Constants
// Occurances are replaced at compile time
// and computed to a single value if possible by the optimizer
uint256 constant MAX_FUTURE_ROUND = 2**256 - 1;

Check warning on line 32 in contracts/bonding/BondingManager.sol

View workflow job for this annotation

GitHub Actions / Test with coverage

Explicitly mark visibility of state

// Time between unbonding and possible withdrawl in rounds
uint64 public unbondingPeriod;
Expand Down Expand Up @@ -106,6 +106,9 @@
// @dev Since the setter is callable by any address, a mapping key does not guarantee to be a registered or active transcoder.
mapping(address => address) public transcoderToRewardCaller;

// Tracks which addresses a delegator has authorized to perform third-party bonding actions on their behalf.
mapping(address => mapping(address => bool)) private authorizedThirdPartyBonders;

// Check if sender is TicketBroker
modifier onlyTicketBroker() {
_onlyTicketBroker();
Expand Down Expand Up @@ -548,6 +551,28 @@
emit TranscoderUpdate(msg.sender, _rewardCut, _feeShare);
}

/**
* @notice Authorize or deauthorize an address to perform third-party bonding actions (bondForWithHint, transferBond) on
* behalf of the delegator.
* @param _bonder Address to authorize or deauthorize for third-party bonding
* @param _authorized `true` to authorize `_bonder`, `false` to revoke a previously granted authorization
*/
function setThirdPartyBonderAuthorization(address _bonder, bool _authorized) external whenSystemNotPaused {
if (authorizedThirdPartyBonders[msg.sender][_bonder] != _authorized) {
authorizedThirdPartyBonders[msg.sender][_bonder] = _authorized;
emit ThirdPartyBonderAuthorization(msg.sender, _bonder, _authorized);
}
}

/**
* @notice Returns whether `_bonder` is authorized to perform third-party bonding actions on behalf of `_delegator`.
* @param _delegator The delegator whose authorization is being queried
* @param _bonder The third-party bonder being checked
*/
function isThirdPartyBonderAuthorized(address _delegator, address _bonder) external view returns (bool) {
return authorizedThirdPartyBonders[_delegator][_bonder];
}

/**
* @notice Delegates stake "on behalf of" another address towards a specific address
* and updates the transcoder pool using optional list hints if needed
Expand Down
5 changes: 5 additions & 0 deletions contracts/bonding/IBondingManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ interface IBondingManager {
uint256 endRound
);
event RewardCallerSet(address indexed transcoder, address indexed rewardCaller);
event ThirdPartyBonderAuthorization(address indexed delegator, address indexed bonder, bool authorized);

// Deprecated events
// These event signatures can be used to construct the appropriate topic hashes to filter for past logs corresponding
Expand Down Expand Up @@ -87,6 +88,10 @@ interface IBondingManager {
) external;

// Public functions
function setThirdPartyBonderAuthorization(address _bonder, bool _authorized) external;

function isThirdPartyBonderAuthorized(address _delegator, address _bonder) external view returns (bool);

function getTranscoderPoolSize() external view returns (uint256);

function transcoderTotalStake(address _transcoder) external view returns (uint256);
Expand Down
188 changes: 150 additions & 38 deletions deployments/arbitrumMainnet/BondingManagerTarget.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

131 changes: 131 additions & 0 deletions test/unit/BondingManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2267,6 +2267,137 @@ describe("BondingManager", () => {
})
})

describe("setThirdPartyBonderAuthorization", () => {
let delegator
let thirdParty
let otherThirdParty

beforeEach(async () => {
delegator = signers[0]
thirdParty = signers[1]
otherThirdParty = signers[2]
})

it("should fail if system is paused", async () => {
await fixture.controller.pause()

await expect(
bondingManager
.connect(delegator)
.setThirdPartyBonderAuthorization(thirdParty.address, true)
).to.be.revertedWith("system is paused")
})

it("should return false for an address that was never authorized", async () => {
assert.isFalse(
await bondingManager.isThirdPartyBonderAuthorized(
delegator.address,
thirdParty.address
)
)
})

it("should authorize a third party bonder", async () => {
const tx = bondingManager
.connect(delegator)
.setThirdPartyBonderAuthorization(thirdParty.address, true)

await expect(tx)
.to.emit(bondingManager, "ThirdPartyBonderAuthorization")
.withArgs(delegator.address, thirdParty.address, true)

assert.isTrue(
await bondingManager.isThirdPartyBonderAuthorized(
delegator.address,
thirdParty.address
)
)
})

it("should revoke a previously granted authorization", async () => {
await bondingManager
.connect(delegator)
.setThirdPartyBonderAuthorization(thirdParty.address, true)

const tx = bondingManager
.connect(delegator)
.setThirdPartyBonderAuthorization(thirdParty.address, false)

await expect(tx)
.to.emit(bondingManager, "ThirdPartyBonderAuthorization")
.withArgs(delegator.address, thirdParty.address, false)

assert.isFalse(
await bondingManager.isThirdPartyBonderAuthorized(
delegator.address,
thirdParty.address
)
)
})

it("should not emit an event when authorizing an already authorized bonder", async () => {
await bondingManager
.connect(delegator)
.setThirdPartyBonderAuthorization(thirdParty.address, true)

const tx = bondingManager
.connect(delegator)
.setThirdPartyBonderAuthorization(thirdParty.address, true)

await expect(tx).to.not.emit(
bondingManager,
"ThirdPartyBonderAuthorization"
)

assert.isTrue(
await bondingManager.isThirdPartyBonderAuthorized(
delegator.address,
thirdParty.address
)
)
})

it("should allow a delegator to authorize multiple bonders", async () => {
await bondingManager
.connect(delegator)
.setThirdPartyBonderAuthorization(thirdParty.address, true)
await bondingManager
.connect(delegator)
.setThirdPartyBonderAuthorization(otherThirdParty.address, true)

assert.isTrue(
await bondingManager.isThirdPartyBonderAuthorized(
delegator.address,
thirdParty.address
)
)
assert.isTrue(
await bondingManager.isThirdPartyBonderAuthorized(
delegator.address,
otherThirdParty.address
)
)

// Revoking one authorization leaves the other intact
await bondingManager
.connect(delegator)
.setThirdPartyBonderAuthorization(thirdParty.address, false)

assert.isFalse(
await bondingManager.isThirdPartyBonderAuthorized(
delegator.address,
thirdParty.address
)
)
assert.isTrue(
await bondingManager.isThirdPartyBonderAuthorized(
delegator.address,
otherThirdParty.address
)
)
})
})

describe("bondForWithHint", () => {
let transcoder0
let transcoder1
Expand Down
Loading