-
Notifications
You must be signed in to change notification settings - Fork 269
feature: stake-dao adapters and tests for DeFi-SDK integration #150
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
Open
smitrajput
wants to merge
4
commits into
zeriontech:interactive
Choose a base branch
from
smitrajput:stakedao
base: interactive
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// 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 | ||
*/ | ||
contract StakeDaoTokenAdapter is TokenAdapter { | ||
address internal constant SD_VECRV = 0x478bBC744811eE8310B461514BDc29D03739084D; | ||
address internal constant CRV = 0xD533a949740bb3306d119CC777fa900bA034cd52; | ||
|
||
/** | ||
* @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 == SD_VECRV) { | ||
components[0] = Component({ | ||
token: CRV, | ||
tokenType: "ERC20", | ||
rate: 1e18 | ||
}); | ||
} else { | ||
components[0] = Component({ | ||
token: Vault(token).token(), | ||
tokenType: "ERC20", | ||
rate: Vault(token).getPricePerFullShare() | ||
}); | ||
} | ||
|
||
return components; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const TokenAdapter = artifacts.require("StakeDaoTokenAdapter"); | ||
|
||
contract("StakeDaoTokenAdapter", () => { | ||
const sbtcVaultAddress = "0x24129B935AfF071c4f0554882C0D9573F4975fEd"; | ||
const sbtcCrv = "0x075b1bb99792c9E1041bA13afEf80C91a1e70fB3"; | ||
|
||
const sdveCrvAddress = "0x478bBC744811eE8310B461514BDc29D03739084D"; | ||
const CRV = '0xD533a949740bb3306d119CC777fa900bA034cd52'; | ||
|
||
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], CRV); | ||
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); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.