-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7d991fe
commit 1b7d2b1
Showing
10 changed files
with
430 additions
and
14 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
import { VaultDetails } from '@models/one-click-yield.models'; | ||
import { RawVault } from 'dlc-btc-lib/models'; | ||
import { ethers } from 'ethers'; | ||
|
||
export interface IntegrationInfo { | ||
address: string; // Integration Address | ||
strategy: string; | ||
isActive: boolean; | ||
totalShares: number; | ||
supportedRewardTokens: string[]; | ||
vaults: string[]; | ||
rewardRatePerSecond: number; | ||
lastRewardTime: number; | ||
pendingRewards: number; | ||
vaultAddress: string; | ||
rewardTokenAddress: string; | ||
} | ||
|
||
export const fetchAllICYVaultsForUser = async (taprootPubKey: string): Promise<VaultDetails[]> => { | ||
try { | ||
const provider = new ethers.providers.StaticJsonRpcProvider('http://127.0.0.1:8545', undefined); | ||
|
||
const poolMerchantContract = new ethers.Contract( | ||
ethereumNetworkConfiguration.poolMerchant.address, | ||
poolMerchantABI, | ||
provider | ||
); | ||
|
||
const dlcManagerContract = new ethers.Contract( | ||
ethereumNetworkConfiguration.dlcManager.address, | ||
dlcManagerABI, | ||
provider | ||
); | ||
|
||
const allVaultUUIDs = await poolMerchantContract.getVaultsByTaprootPubKey(taprootPubKey); | ||
|
||
const vaultDetailsPromises = allVaultUUIDs.map(async (vaultUUID: string) => { | ||
const details = await poolMerchantContract.getVaultDetails(vaultUUID); | ||
const dlcVault: RawVault = await dlcManagerContract.getVault(vaultUUID); | ||
return { | ||
uuid: vaultUUID, | ||
integration: details.integration.toString(), | ||
shares: Number(details.shares), | ||
valueMinted: Number(details.valueMinted), | ||
allocated: Number(details.allocated), | ||
unallocated: Number(details.unallocated), | ||
rewardTokens: details.rewardTokens.map((token: string) => token.toString()), | ||
lastClaimedAt: details.lastClaimedAt.map((time: bigint) => Number(time)), | ||
harvestedRewards: details.harvestedRewards.map((reward: bigint) => Number(reward)), | ||
pendingRewards: details.pendingRewards.map((reward: bigint) => Number(reward)), | ||
dlcVault: { | ||
uuid: dlcVault.uuid, | ||
protocolContract: dlcVault.protocolContract, | ||
timestamp: Number(dlcVault.timestamp), | ||
valueLocked: Number(dlcVault.valueLocked), | ||
valueMinted: Number(dlcVault.valueMinted), | ||
creator: dlcVault.creator, | ||
status: Number(dlcVault.status), | ||
fundingTxId: dlcVault.fundingTxId, | ||
closingTxId: dlcVault.closingTxId, | ||
wdTxId: dlcVault.wdTxId, | ||
btcFeeRecipient: dlcVault.btcFeeRecipient, | ||
btcMintFeeBasisPoints: Number(dlcVault.btcMintFeeBasisPoints), | ||
btcRedeemFeeBasisPoints: Number(dlcVault.btcRedeemFeeBasisPoints), | ||
taprootPubKey: dlcVault.taprootPubKey, | ||
}, | ||
}; | ||
}); | ||
|
||
return Promise.all(vaultDetailsPromises); | ||
} catch (error) { | ||
throw new Error( | ||
`Error fetching Attestor Group Public Key from Ethereum Network [${ethereumNetwork}]: ${error}` | ||
); | ||
} | ||
}; | ||
|
||
export const fetchIntegrationInfos = async (): Promise<IntegrationInfo[]> => { | ||
try { | ||
const provider = new ethers.providers.StaticJsonRpcProvider('http://127.0.0.1:8545', undefined); | ||
|
||
const poolMerchantContract = new ethers.Contract( | ||
ethereumNetworkConfiguration.poolMerchant.address, | ||
poolMerchantABI, | ||
provider | ||
); | ||
|
||
const activeIntegrations: string[] = await poolMerchantContract.getAllActiveIntegrations(); | ||
console.log('Active Integrations:', activeIntegrations); | ||
|
||
const integrationDetailsPromises = activeIntegrations.map( | ||
async (integrationAddress: string) => { | ||
const integration = await poolMerchantContract.integrations(integrationAddress); | ||
const vaults: string[] = | ||
await poolMerchantContract.getIntegrationVaults(integrationAddress); | ||
const integrationContract = new ethers.Contract( | ||
integrationAddress, | ||
integrationSampleABI, | ||
provider | ||
); | ||
|
||
const rewardRatePerSecond = await integrationContract.rewardRatePerSecond(); | ||
const lastRewardTime = await integrationContract.lastRewardTime(); | ||
const pendingRewardsArray: number[] = await integrationContract.getPendingRewards(); | ||
const pendingRewards = pendingRewardsArray[0]; // assuming only 1 reward token | ||
const vaultAddress = await integrationContract.vault(); | ||
const rewardTokenAddress = await integrationContract.rewardToken(); | ||
|
||
return { | ||
address: integrationAddress, | ||
strategy: integration.strategy.toString(), | ||
isActive: integration.isActive, | ||
totalShares: Number(integration.totalShares), | ||
supportedRewardTokens: integration.supportedRewardTokens?.map((token: string) => | ||
token.toString() | ||
), | ||
vaults: vaults.map((vault: string) => vault.toString()), | ||
rewardRatePerSecond: Number(rewardRatePerSecond), | ||
lastRewardTime: Number(lastRewardTime), | ||
pendingRewards: Number(pendingRewards), | ||
vaultAddress: vaultAddress.toString(), | ||
rewardTokenAddress: rewardTokenAddress.toString(), | ||
}; | ||
} | ||
); | ||
|
||
return Promise.all(integrationDetailsPromises); | ||
} catch (error) { | ||
throw new Error( | ||
`Error fetching integration information from Ethereum Network [${ethereumNetwork}]: ${error}` | ||
); | ||
} | ||
}; |
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
Oops, something went wrong.