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: velocore adapter #213

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

velocore
Copy link

@velocore velocore commented Apr 9, 2024

Description

Velocore is a veDEX with real-time voting.

Website: https://velocore.xyz
App: https://linea.velocore.xyz
Docs: https://docs.velocore.xyz
Contracts: https://docs.velocore.xyz/security-and-contract-address/linea-contracts

We have a different architecture to the Uniswap forks.
For example, we have a singleton vault structure for all kinds of interactions, erc-1155 LPs for stable pools, and a gauge contract for each LP.
So we implemented VelocorePoolAdapter based on the IProtocolAdapter class rather than SimplePoolAdapter.

Please note that we used gauge address instead of pool address as the key of the metadata object.
Because of our structure, a stable pool can have multiple LPs in a pool, each LP is an erc-1155 token, distinguished by tokenId, and each LP has one gauge associated with it.
Therefore, we used the gauge address as the key of the metadata object for a one-to-one mapping of protocolToken and key.

The rest of the VelocorePoolAdapter is nothing special. We used the Lens contract to get the data for the gauges and pools.

Pre-merge author checklist

  • A brief description of the protocol and adapters is added to the PR
  • Files outside the protocol folder are not being edited and, if they are, it's clearly explained why in the PR
  • update me comments are removed
  • Contracts used are verified for that chain block explorer
  • Test cases with a block number have been added to the testCases.ts file for every relevant method that has been implemented
    • positions
    • prices
    • deposits
    • withdrawals
    • profits
    • tvl
    • apr
    • apy
  • getAddress from ethers
    • Is used to parse hardcoded addresses
    • Is used to parse addresses that come from contract calls when it is not clear they'll be in checksum format
    • It is NOT used to parse addresses from input methods
    • It is NOT used to parse addresses from metadata
  • For every adapter that extends SimplePoolAdapter
    • getPositions is not overwritten and, if it is, it's clearly explained why in the PR
    • unwrap is not overwritten and, if it is, it's clearly explained why in the PR
  • If the adapters requires to fetch static data on-chain (e.g. pool ids, token metadata, etc)
    • The adapter implements IMetadataBuilder
    • The buildMetadata method is implemented with the @CacheToFile decorator
    • All the static data is stored within the metadata JSON file

@velocore velocore marked this pull request as draft April 9, 2024 04:34
Comment on lines 212 to +252
filterProtocolIds,
filterChainIds,
filterProtocolToken,
filterTokenId,
blockNumbers,
}: {
filterProtocolIds?: Protocol[]
filterChainIds?: Chain[]
filterProtocolToken?: string
filterTokenId?: string
blockNumbers?: Partial<Record<Chain, number>>
}): Promise<PricePerShareResponse[]> {
const runner = async (adapter: IProtocolAdapter) => {
const blockNumber = blockNumbers?.[adapter.chainId]

const protocolTokens = filterProtocolToken
const protocolTokens:
| (Erc20Metadata & {
tokenId?: string
})[]
| {
address: string
tokenId?: string
}[] = filterProtocolToken
? [
{
address: filterProtocolToken,
...(filterTokenId !== undefined
? { tokenId: filterTokenId }
: {}),
},
]
: await adapter.getProtocolTokens()

const tokens = await Promise.all(
protocolTokens.map(async ({ address }) => {
protocolTokens.map(async ({ address, tokenId }) => {
const startTime = Date.now()

const unwrap = await adapter.unwrap({
protocolTokenAddress: getAddress(address),
blockNumber,
tokenId,
Copy link
Author

Choose a reason for hiding this comment

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

We found that the defiProvider.unwrap function doesn't accept filterTokenId, even though the TestCase type has the filterTokenId property.

| {
method: 'prices'
blockNumber?: number
filterProtocolToken?: string
filterTokenId?: string
}

Also, the adapter.unwrap function has tokenId as a parameter.

export type UnwrapInput = {
/**
* Optional override param
*/
blockNumber?: number
/**
* Protocol token address (LP token address).
*/
protocolTokenAddress: string
/**
* Optional filter for pools that will be queried by an ID
*/
tokenId?: string
}

We need tokenId to handle our stable pool LPs (erc-1155) correctly, so we decided to add tokenId as params.

It is outside of our adapter implementation, so please let me know if it is not acceptable.

@velocore velocore marked this pull request as ready for review April 9, 2024 05:00
@jpsains jpsains self-assigned this Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants