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
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
Copyright 2020 Set Labs Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

SPDX-License-Identifier: Apache License, Version 2.0

*/

pragma solidity ^0.6.10;
pragma experimental "ABIEncoderV2";


contract SnapshotGovernanceAdapter {

address public immutable router;



/* ============= Constructor ============= */
/**
* Set state variable
* @param _router Address of DelegateRegistry Contract
**/

constructor(address _router) public {
router = _router;
}


/* ============ External Getter Functions ============ */

/**
* Calculate setDelegate encoded calldata. To be invoked on the SetToken.
*
* @param _delegate Address to delegate votes
*
* @return address Target address
* @return uint256 Call value
* @return bytes delegate calldata
*/


function getDelegateCalldata(address _delegate) external view returns (address, uint256, bytes memory) {

bytes memory callData = abi.encodeWithSignature(
"setDelegate(bytes32,address)",
bytes32(0),
_delegate
);

return (router, 0, callData);

}


/**
* Calculate clearDelegate encoded calldata. To be invoked on the SetToken.
*
* @return address Target address
* @return uint256 Call value
* @return bytes revoke calldata
*/

function getRevokeCalldata() external view returns (address, uint256, bytes memory) {

bytes memory callData = abi.encodeWithSignature(
"clearDelegate(bytes32)",
bytes32(0)
);

return (router, 0, callData);

}

}

9 changes: 9 additions & 0 deletions external/abi/snapshot/DelegateRegistry.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"contractName": "DelegateRegistry",
"abi": [{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"delegator","type":"address"},{"indexed":true,"internalType":"bytes32","name":"id","type":"bytes32"},{"indexed":true,"internalType":"address","name":"delegate","type":"address"}],"name":"ClearDelegate","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"delegator","type":"address"},{"indexed":true,"internalType":"bytes32","name":"id","type":"bytes32"},{"indexed":true,"internalType":"address","name":"delegate","type":"address"}],"name":"SetDelegate","type":"event"},{"inputs":[{"internalType":"bytes32","name":"id","type":"bytes32"}],"name":"clearDelegate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"delegation","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"id","type":"bytes32"},{"internalType":"address","name":"delegate","type":"address"}],"name":"setDelegate","outputs":[],"stateMutability":"nonpayable","type":"function"}],
"bytecode": "0x608060405234801561001057600080fd5b50610794806100206000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c806374c6c45414610046578063bd86e508146100be578063f0bedbe21461010c575b600080fd5b6100926004803603604081101561005c57600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291908035906020019092919050505061013a565b604051808273ffffffffffffffffffffffffffffffffffffffff16815260200191505060405180910390f35b61010a600480360360408110156100d457600080fd5b8101908080359060200190929190803573ffffffffffffffffffffffffffffffffffffffff16906020019092919050505061017c565b005b6101386004803603602081101561012257600080fd5b8101908080359060200190929190505050610538565b005b60006020528160005260406000206020528060005260406000206000915091509054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b3373ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141561021e576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260168152602001807f43616e27742064656c656761746520746f2073656c660000000000000000000081525060200191505060405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156102c1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260158152602001807f43616e27742064656c656761746520746f20307830000000000000000000000081525060200191505060405180910390fd5b60008060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690508073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1614156103ba576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602181526020018061073e6021913960400191505060405180910390fd5b816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600085815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16146104d8578073ffffffffffffffffffffffffffffffffffffffff16833373ffffffffffffffffffffffffffffffffffffffff167f9c4f00c4291262731946e308dc2979a56bd22cce8f95906b975065e96cd5a06460405160405180910390a45b8173ffffffffffffffffffffffffffffffffffffffff16833373ffffffffffffffffffffffffffffffffffffffff167fa9a7fd460f56bddb880a465a9c3e9730389c70bc53108148f16d55a87a6c468e60405160405180910390a4505050565b60008060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600083815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16141561064f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252600f8152602001807f4e6f2064656c656761746520736574000000000000000000000000000000000081525060200191505060405180910390fd5b60008060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600084815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508073ffffffffffffffffffffffffffffffffffffffff16823373ffffffffffffffffffffffffffffffffffffffff167f9c4f00c4291262731946e308dc2979a56bd22cce8f95906b975065e96cd5a06460405160405180910390a4505056fe416c72656164792064656c65676174656420746f20746869732061646472657373a2646970667358221220b6cd5a8d04426e1189563fbec7dfec4ba70090dc70fe05097a137991fe1b396964736f6c63430007020033",
"deployedBytecode": "",
"linkReferences": {},
"deployedLinkReferences": {}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import "module-alias/register";
import { Address } from "@utils/types";
import { Account } from "@utils/test/types";
import { ZERO, ZERO_BYTES } from "@utils/constants";
import { SnapshotGovernanceAdapter } from "@utils/contracts";
import DeployHelper from "@utils/deploys";
import {
addSnapshotBeforeRestoreAfterEach,
getAccounts,
getWaffleExpect,
getRandomAddress
} from "@utils/test/index";

import { DelegateRegistry } from "@typechain/DelegateRegistry";


const expect = getWaffleExpect();

describe("SnapshotGovernanceAdapter", () => {
let owner: Account;
let deployer: DeployHelper;
let snapshotGovernanceAdapter: SnapshotGovernanceAdapter;
let delegateRegistry: DelegateRegistry;

before(async () => {
[
owner,
] = await getAccounts();

deployer = new DeployHelper(owner.wallet);

delegateRegistry = await deployer.external.deployDelegateRegistry();
snapshotGovernanceAdapter = await deployer.adapters.deploySnapshotGovernanceAdapter(
delegateRegistry.address,
);
});

addSnapshotBeforeRestoreAfterEach();

describe("#constructor", async () => {
let subjectDelegateRegistryRouter: Address;

before(async () => {
subjectDelegateRegistryRouter = delegateRegistry.address;
});

async function subject(): Promise<any> {
return deployer.adapters.deploySnapshotGovernanceAdapter(subjectDelegateRegistryRouter);
}

it("should have the correct router address", async () => {
const deployedSnapshotGovernanceAdapter = await subject();

const actualRouterAddress = await deployedSnapshotGovernanceAdapter.router();
expect(actualRouterAddress).to.eq(subjectDelegateRegistryRouter);
});
});

describe("#getDelegateCalldata", async () => {
let subjectDelegate: Address;

before(async () => {
subjectDelegate = await getRandomAddress();
});

async function subject(): Promise<any> {
return snapshotGovernanceAdapter.getDelegateCalldata(subjectDelegate);
}

it("should return correct data for delegating", async () => {
const [targetAddress, ethValue, callData] = await subject();
const expectedCallData = delegateRegistry.interface.encodeFunctionData("setDelegate", [ZERO_BYTES, subjectDelegate]);

expect(targetAddress).to.eq(delegateRegistry.address);
expect(ethValue).to.eq(ZERO);
expect(callData).to.eq(expectedCallData);
});
});

describe("#getRevokeCalldata", async () => {
async function subject(): Promise<any> {
return snapshotGovernanceAdapter.getRevokeCalldata();
}

it("should return correct data for revoking", async () => {
const [targetAddress, ethValue, callData] = await subject();
const expectedCallData = delegateRegistry.interface.encodeFunctionData("clearDelegate", [ZERO_BYTES]);

expect(targetAddress).to.eq(delegateRegistry.address);
expect(ethValue).to.eq(ZERO);
expect(callData).to.eq(expectedCallData);
});
});
});
1 change: 1 addition & 0 deletions utils/contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export { SetToken } from "../../typechain/SetToken";
export { SetTokenCreator } from "../../typechain/SetTokenCreator";
export { SetValuer } from "../../typechain/SetValuer";
export { SingleIndexModule } from "../../typechain/SingleIndexModule";
export { SnapshotGovernanceAdapter } from "../../typechain/SnapshotGovernanceAdapter";
export { StakingAdapterMock } from "../../typechain/StakingAdapterMock";
export { StakingModule } from "../../typechain/StakingModule";
export { StakingRewards } from "../../typechain/StakingRewards";
Expand Down
2 changes: 2 additions & 0 deletions utils/contracts/snapshot.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// External Snapshot contracts
export { DelegateRegistry } from "../../typechain/DelegateRegistry";
8 changes: 8 additions & 0 deletions utils/deploys/deployAdapters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
SynthetixExchangeAdapter,
CompoundBravoGovernanceAdapter,
CompClaimAdapter,
SnapshotGovernanceAdapter
} from "../contracts";
import { convertLibraryNameToLinkId } from "../common";
import { Address, Bytes } from "./../types";
Expand All @@ -42,6 +43,7 @@ import { YearnWrapAdapter__factory } from "../../typechain/factories/YearnWrapAd
import { UniswapPairPriceAdapter__factory } from "../../typechain/factories/UniswapPairPriceAdapter__factory";
import { UniswapV2TransferFeeExchangeAdapter__factory } from "../../typechain/factories/UniswapV2TransferFeeExchangeAdapter__factory";
import { UniswapV2IndexExchangeAdapter__factory } from "../../typechain/factories/UniswapV2IndexExchangeAdapter__factory";
import { SnapshotGovernanceAdapter__factory } from "../../typechain/factories/SnapshotGovernanceAdapter__factory";
import { SynthetixExchangeAdapter__factory } from "../../typechain/factories/SynthetixExchangeAdapter__factory";
import { CompoundBravoGovernanceAdapter__factory } from "../../typechain/factories/CompoundBravoGovernanceAdapter__factory";
import { CompClaimAdapter__factory } from "../../typechain";
Expand Down Expand Up @@ -170,4 +172,10 @@ export default class DeployAdapters {
synthetixExchangerAddress
);
}

public async deploySnapshotGovernanceAdapter(router: Address): Promise<SnapshotGovernanceAdapter> {
return await new SnapshotGovernanceAdapter__factory(this._deployerSigner).deploy(
router
);
}
}
9 changes: 9 additions & 0 deletions utils/deploys/deployExternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,15 @@ import {
Stableswap,
} from "../contracts/curve";

import {
DelegateRegistry
} from "../contracts/snapshot";

import { CurvePoolERC20__factory } from "../../typechain/factories/CurvePoolERC20__factory";
import { Stableswap__factory } from "../../typechain/factories/Stableswap__factory";
import { CurveDeposit__factory } from "../../typechain/factories/CurveDeposit__factory";
import { CRVToken__factory } from "../../typechain/factories/CRVToken__factory";
import { DelegateRegistry__factory } from "../../typechain/factories/DelegateRegistry__factory";
import { GaugeController__factory } from "../../typechain/factories/GaugeController__factory";
import { LiquidityGaugeReward__factory } from "../../typechain/factories/LiquidityGaugeReward__factory";
import { Minter__factory } from "../../typechain/factories/Minter__factory";
Expand Down Expand Up @@ -465,6 +470,10 @@ export default class DeployExternalContracts {
);
}

public async deployDelegateRegistry(): Promise<DelegateRegistry> {
return await new DelegateRegistry__factory(this._deployerSigner).deploy();
}

public async deployCrvToken(_name: string, _symbol: string, _decimals: BigNumberish = 18): Promise<CRVToken> {
return await new CRVToken__factory(this._deployerSigner).deploy(_name, _symbol, _decimals);
}
Expand Down