-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #227 from prevostc/add-beefy-clm
beefy - yield : add CLM
- Loading branch information
Showing
14 changed files
with
155 additions
and
44 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -9,3 +9,5 @@ number,timestamp | |
4740000,1716263772 | ||
4730000,1716233771 | ||
4784763,1716398064 | ||
5684890,1718771519 | ||
5784890,1718972096 |
This file contains 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,19 @@ | ||
export const BeefyClmStrategyAbi = [ | ||
{ | ||
type: "function", | ||
name: "price", | ||
inputs: [], | ||
outputs: [{ name: "_price", type: "uint256", internalType: "uint256" }], | ||
stateMutability: "view", | ||
}, | ||
{ | ||
type: "function", | ||
name: "range", | ||
inputs: [], | ||
outputs: [ | ||
{ name: "lowerPrice", type: "uint256", internalType: "uint256" }, | ||
{ name: "upperPrice", type: "uint256", internalType: "uint256" }, | ||
], | ||
stateMutability: "view", | ||
}, | ||
] as const; |
This file contains 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,29 @@ | ||
export const BeefyVaultConcLiqAbi = [ | ||
{ | ||
inputs: [], | ||
name: "balances", | ||
outputs: [ | ||
{ internalType: "uint256", name: "amount0", type: "uint256" }, | ||
{ internalType: "uint256", name: "amount1", type: "uint256" }, | ||
], | ||
stateMutability: "view", | ||
type: "function", | ||
}, | ||
{ | ||
inputs: [], | ||
name: "totalSupply", | ||
outputs: [{ internalType: "uint256", name: "", type: "uint256" }], | ||
stateMutability: "view", | ||
type: "function", | ||
}, | ||
{ | ||
inputs: [], | ||
name: "wants", | ||
outputs: [ | ||
{ internalType: "address", name: "token0", type: "address" }, | ||
{ internalType: "address", name: "token1", type: "address" }, | ||
], | ||
stateMutability: "view", | ||
type: "function", | ||
}, | ||
] as const; |
This file contains 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
This file contains 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
This file contains 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
52 changes: 52 additions & 0 deletions
52
adapters/beefy/src/sdk/breakdown/protocol_type/beefy_clm.ts
This file contains 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,52 @@ | ||
import { Hex, getContract } from "viem"; | ||
import { BeefyVault } from "../../vault/getBeefyVaultConfig"; | ||
import { BeefyViemClient } from "../../viemClient"; | ||
import { BeefyVaultBreakdown } from "../types"; | ||
import { BeefyVaultConcLiqAbi } from "../../../abi/BeefyVaultConcLiq"; | ||
import { BeefyClmStrategyAbi } from "../../../abi/BeefyClmStrategy"; | ||
|
||
export const getBeefyClmVaultBreakdown = async ( | ||
client: BeefyViemClient, | ||
blockNumber: bigint, | ||
vault: BeefyVault | ||
): Promise<BeefyVaultBreakdown> => { | ||
const managerContract = getContract({ | ||
client, | ||
address: vault.vault_address, | ||
abi: BeefyVaultConcLiqAbi, | ||
}); | ||
|
||
const strategyContract = getContract({ | ||
client, | ||
address: vault.strategy_address, | ||
abi: BeefyClmStrategyAbi, | ||
}); | ||
|
||
const [balances, vaultTotalSupply, wants, range, price] = await Promise.all([ | ||
managerContract.read.balances({ blockNumber }), | ||
managerContract.read.totalSupply({ blockNumber }), | ||
managerContract.read.wants({ blockNumber }), | ||
strategyContract.read.range({ blockNumber }), | ||
strategyContract.read.price({ blockNumber }), | ||
]); | ||
|
||
// special rule to exclude out of range liquidity for concentrated liquidity vaults | ||
const isLiquidityEligible = price >= range[0] && price <= range[1]; | ||
|
||
return { | ||
vault, | ||
blockNumber, | ||
vaultTotalSupply, | ||
isLiquidityEligible, | ||
balances: [ | ||
{ | ||
tokenAddress: wants[0].toLocaleLowerCase() as Hex, | ||
vaultBalance: balances[0], | ||
}, | ||
{ | ||
tokenAddress: wants[1].toLocaleLowerCase() as Hex, | ||
vaultBalance: balances[1], | ||
}, | ||
], | ||
}; | ||
}; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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