Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: stake-dao adapters and tests for DeFi-SDK integration #150

Open
wants to merge 4 commits into
base: interactive
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
75 changes: 75 additions & 0 deletions contracts/adapters/stake-dao/StakeDAOTokenAdapter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// SPDX-License-Identifier: None

pragma solidity 0.6.5;
pragma experimental ABIEncoderV2;

import {ERC20} from "../../ERC20.sol";
import {TokenMetadata, Component} from "../../Structs.sol";
import {TokenAdapter} from "../TokenAdapter.sol";

interface Vault {
function token() external view returns (address);

function getPricePerFullShare() external view returns (uint256);
}

/**
* @title Token adapter for Stake DAO Vaults.
* @dev Implementation of TokenAdapter abstract contract.
* @author Elephant memory/strength
sobolevigor986 marked this conversation as resolved.
Show resolved Hide resolved
*/
contract StakeDaoTokenAdapter is TokenAdapter {
address public sdveCrv = 0x478bBC744811eE8310B461514BDc29D03739084D;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we usually save such addresses as address internal constant

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might have a new address in the future, hence not a constant


function setSdveCrv(address newSdveCrv) external {
sdveCrv = newSdveCrv;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason it may be useful?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, so that you can update the sdveCrv address when it's changed in the future, without redeploying StakeDaoTokenAdapter.sol

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, but I will break the integration anyway
so I think there are 2 things you should do

  • inherit from Ownable contract from this repo and use onlyOwner here
  • notify us about change of sdveCrv address, so we change it here and in our backend


/**
* @return TokenMetadata struct with ERC20-style token info.
* @dev Implementation of TokenAdapter interface function.
*/
function getMetadata(address token)
external
view
override
returns (TokenMetadata memory)
{
return
TokenMetadata({
token: token,
name: ERC20(token).name(),
symbol: ERC20(token).symbol(),
decimals: ERC20(token).decimals()
});
}

/**
* @return Array of Component structs with underlying tokens rates for the given token.
* @dev Implementation of TokenAdapter abstract contract function.
*/
function getComponents(address token)
external
view
override
returns (Component[] memory)
{
Component[] memory components = new Component[](1);

if (token == sdveCrv) {
components[0] = Component({
token: sdveCrv,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
token: sdveCrv,
token: CRV,

it should be CRV address as it's component's address

tokenType: "ERC20",
rate: 1e18
});
} else {
components[0] = Component({
token: Vault(token).token(),
tokenType: "ERC20",
rate: Vault(token).getPricePerFullShare()
});
}

return components;
}
}
32 changes: 32 additions & 0 deletions contracts/adapters/stake-dao/StakeDAOVaultAdapter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: None

pragma solidity 0.6.5;
pragma experimental ABIEncoderV2;

import {ERC20} from "../../ERC20.sol";
import {ProtocolAdapter} from "../ProtocolAdapter.sol";

/**
* @title Adapter for Yearn Token Vaults.
* @dev Implementation of ProtocolAdapter interface.
* @author Igor Sobolev <[email protected]>
*/
contract StakeDAOVaultAdapter is ProtocolAdapter {
string public constant override adapterType = "Asset";

string public constant override tokenType = "Stake DAO Vault";

/**
* @return Amount of Stake DAO Vault Tokens owned by the given account.
* @param token Address of the vault token.
* @dev Implementation of ProtocolAdapter interface function.
*/
function getBalance(address token, address account)
external
view
override
returns (uint256)
{
return ERC20(token).balanceOf(account);
}
}
62 changes: 62 additions & 0 deletions test/adapters/StakeDaoTokenAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const TokenAdapter = artifacts.require("StakeDaoTokenAdapter");

contract("StakeDaoTokenAdapter", () => {
const sbtcVaultAddress = "0x24129B935AfF071c4f0554882C0D9573F4975fEd";
const sbtcCrv = "0x075b1bb99792c9E1041bA13afEf80C91a1e70fB3";

const sdveCrvAddress = "0x478bBC744811eE8310B461514BDc29D03739084D";

let accounts;
let tokenAdapter;
const sbtcVault = [
sbtcVaultAddress,
"stake dao Curve.fi renBTC/wBTC/sBTC",
"sdcrvRenWSBTC",
"18",
];

const sdveCrvVault = [sdveCrvAddress, "veCRV Stake DAO", "sdveCRV-DAO", "18"];

beforeEach(async () => {
accounts = await web3.eth.getAccounts();

await TokenAdapter.new({ from: accounts[0] }).then((result) => {
tokenAdapter = result.contract;
});
});

it("should return correct components for sBTC, 3Pool, Eurs vaults", async () => {
await tokenAdapter.methods["getComponents(address)"](sbtcVaultAddress)
.call()
.then((result) => {
assert.equal(result[0][0], sbtcCrv);
assert.equal(result[0][1], "ERC20");
});
});

it("should return correct metadata for sBTC, 3Pool, Eurs vaults", async () => {
await tokenAdapter.methods["getMetadata(address)"](sbtcVaultAddress)
.call()
.then((result) => {
assert.deepEqual(result, sbtcVault);
});
});

it("should return correct components for perpetual passive strategy vault", async () => {
await tokenAdapter.methods["getComponents(address)"](sdveCrvAddress)
.call()
.then((result) => {
assert.equal(result[0][0], sdveCrvAddress);
assert.equal(result[0][1], "ERC20");
assert.equal(result[0][2], "1000000000000000000");
});
});

it("should return correct metadata for perpetual passive strategy vaults", async () => {
await tokenAdapter.methods["getMetadata(address)"](sdveCrvAddress)
.call()
.then((result) => {
assert.deepEqual(result, sdveCrvVault);
});
});
});