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

feat: quickswap d-quick #385

Merged
merged 6 commits into from
Dec 6, 2024
Merged
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
Binary file modified matic.db
Binary file not shown.
7 changes: 7 additions & 0 deletions packages/adapters-library/src/adapters/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ import { testCases as pendlePrincipleTokenTestCases } from './pendle/products/pr
import { testCases as pendleStandardisedYieldTokenTestCases } from './pendle/products/standardised-yield-token/tests/testCases'
import { testCases as pendleYieldTokenTestCases } from './pendle/products/yield-token/tests/testCases'
import { Protocol } from './protocols'
import { testCases as quickswapV2DQuickTestCases } from './quickswap-v2/products/d-quick/tests/testCases'
import { testCases as quickswapV2PoolTestCases } from './quickswap-v2/products/pool/tests/testCases'
import { testCases as quickswapV3PoolTestCases } from './quickswap-v3/products/pool/tests/testCases'
import { testCases as renzoEzEthTestCases } from './renzo/products/ez-eth/tests/testCases'
import { testCases as rocketPoolRethTestCases } from './rocket-pool/products/reth/tests/testCases'
import { testCases as solvSolvBtcTestCases } from './solv/products/solv-btc/tests/testCases'
Expand Down Expand Up @@ -306,9 +308,14 @@ const allTestCases: Record<Protocol, Record<string, TestCase[]>> = {
},

[Protocol.QuickswapV2]: {
['d-quick']: quickswapV2DQuickTestCases,
['pool']: quickswapV2PoolTestCases,
},

[Protocol.QuickswapV3]: {
['pool']: quickswapV3PoolTestCases,
},

[Protocol.Renzo]: {
['ez-eth']: renzoEzEthTestCases,
},
Expand Down
1 change: 1 addition & 0 deletions packages/adapters-library/src/adapters/protocols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const Protocol = {
PancakeswapV2: 'pancakeswap-v2',
Pendle: 'pendle',
QuickswapV2: 'quickswap-v2',
QuickswapV3: 'quickswap-v3',
Renzo: 'renzo',
RocketPool: 'rocket-pool',
Solv: 'solv',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
import { AdaptersController } from '../../../../core/adaptersController'
import { Chain } from '../../../../core/constants/chains'
import { CacheToDb } from '../../../../core/decorators/cacheToDb'
import { CustomJsonRpcProvider } from '../../../../core/provider/CustomJsonRpcProvider'
import { Helpers } from '../../../../scripts/helpers'
import {
IProtocolAdapter,
ProtocolToken,
} from '../../../../types/IProtocolAdapter'
import {
GetEventsInput,
GetPositionsInput,
GetTotalValueLockedInput,
MovementsByBlock,
PositionType,
ProtocolAdapterParams,
ProtocolDetails,
ProtocolPosition,
ProtocolTokenTvl,
UnwrapExchangeRate,
UnwrapInput,
} from '../../../../types/adapter'
import { Protocol } from '../../../protocols'

export class QuickswapV2DQuickAdapter implements IProtocolAdapter {
productId = 'd-quick'
protocolId: Protocol
chainId: Chain
helpers: Helpers

adapterSettings = {
enablePositionDetectionByProtocolTokenTransfer: true,
includeInUnwrap: true,
}

private provider: CustomJsonRpcProvider

adaptersController: AdaptersController

constructor({
provider,
chainId,
protocolId,
adaptersController,
helpers,
}: ProtocolAdapterParams) {
this.provider = provider
this.chainId = chainId
this.protocolId = protocolId
this.adaptersController = adaptersController
this.helpers = helpers
}

/**
* Update me.
* Add your protocol details
*/
getProtocolDetails(): ProtocolDetails {
return {
protocolId: this.protocolId,
name: 'QuickswapV2',
description: 'QuickswapV2 defi adapter',
siteUrl: 'https:',
iconUrl: 'https://',
positionType: PositionType.Supply,
chainId: this.chainId,
productId: this.productId,
}
}

@CacheToDb
async getProtocolTokens(): Promise<ProtocolToken[]> {
const protocolToken = await this.helpers.getTokenMetadata(
'0x958d208Cdf087843e9AD98d23823d32E17d723A1',
)

const underlyingToken = await this.helpers.getTokenMetadata(
'0xB5C064F955D8e7F38fE0460C556a72987494eE17',
)

return [
{
...protocolToken,
underlyingTokens: [underlyingToken],
},
]
}

private async getProtocolTokenByAddress(protocolTokenAddress: string) {
return this.helpers.getProtocolTokenByAddress({
protocolTokens: await this.getProtocolTokens(),
protocolTokenAddress,
})
}

async getPositions(input: GetPositionsInput): Promise<ProtocolPosition[]> {
return this.helpers.getBalanceOfTokens({
...input,
protocolTokens: await this.getProtocolTokens(),
})
}

async getWithdrawals({
protocolTokenAddress,
fromBlock,
toBlock,
userAddress,
}: GetEventsInput): Promise<MovementsByBlock[]> {
return this.helpers.withdrawals({
protocolToken: await this.getProtocolTokenByAddress(protocolTokenAddress),
filter: { fromBlock, toBlock, userAddress },
})
}

async getDeposits({
protocolTokenAddress,
fromBlock,
toBlock,
userAddress,
}: GetEventsInput): Promise<MovementsByBlock[]> {
return this.helpers.deposits({
protocolToken: await this.getProtocolTokenByAddress(protocolTokenAddress),
filter: { fromBlock, toBlock, userAddress },
})
}

async getTotalValueLocked({
protocolTokenAddresses,
blockNumber,
}: GetTotalValueLockedInput): Promise<ProtocolTokenTvl[]> {
const protocolTokens = await this.getProtocolTokens()

return await this.helpers.tvl({
protocolTokens,
filterProtocolTokenAddresses: protocolTokenAddresses,
blockNumber,
})
}

async unwrap({
protocolTokenAddress,
tokenId,
blockNumber,
}: UnwrapInput): Promise<UnwrapExchangeRate> {
return this.helpers.unwrapTokenAsRatio({
protocolToken: await this.getProtocolTokenByAddress(protocolTokenAddress),
underlyingTokens: (
await this.getProtocolTokenByAddress(protocolTokenAddress)
).underlyingTokens,
blockNumber,
})
}
}
Loading
Loading