This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(solace): Adjust Solace implementation (#472)
- Loading branch information
1 parent
860de45
commit cdd243d
Showing
28 changed files
with
637 additions
and
708 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,48 +1,47 @@ | ||
import { SolaceContractFactory } from '../../contracts'; | ||
import { Network } from '~types/network.interface'; | ||
import { SOLACE_DEFINITION } from '../../solace.definition'; | ||
import { ethers } from 'ethers'; | ||
import { range } from 'lodash'; | ||
|
||
import { drillBalance } from '~app-toolkit'; | ||
import { IAppToolkit } from '~app-toolkit/app-toolkit.interface'; | ||
import { Token } from '~position/position.interface'; | ||
import { WithMetaType } from '~position/display.interface'; | ||
import { MetaType } from '~position/position.interface'; | ||
import { Network } from '~types/network.interface'; | ||
|
||
import { SolaceContractFactory } from '../../contracts'; | ||
import { SOLACE_DEFINITION } from '../../solace.definition'; | ||
|
||
import { ethers } from 'ethers'; | ||
const BN = ethers.BigNumber; | ||
import { range } from '~apps/solace/utils'; | ||
|
||
export default async function getBondBalance(address: string, appToolkit: IAppToolkit, solaceContractFactory: SolaceContractFactory) { | ||
export default async function getBondBalance( | ||
address: string, | ||
appToolkit: IAppToolkit, | ||
solaceContractFactory: SolaceContractFactory, | ||
) { | ||
const network = Network.ETHEREUM_MAINNET; | ||
return appToolkit.helpers.contractPositionBalanceHelper.getContractPositionBalances({ | ||
address, | ||
appId: SOLACE_DEFINITION.id, | ||
groupId: SOLACE_DEFINITION.groups.bonds.id, | ||
network, | ||
resolveBalances: async ({ address, contractPosition, multicall }) => { | ||
|
||
// Resolve the staked token and reward token from the contract position object | ||
const stakedToken = contractPosition.tokens.find((t:WithMetaType<Token>) => t.metaType === 'supplied')!; | ||
const rewardToken = contractPosition.tokens.find((t:WithMetaType<Token>) => t.metaType === 'claimable')!; | ||
|
||
const teller = solaceContractFactory.bondTellerErc20({ address: contractPosition.address, network }); | ||
|
||
const mct = multicall.wrap(teller); | ||
|
||
const balance = await mct.balanceOf(address); | ||
const indices = range(0, balance.toNumber()); | ||
const tokenIDs = await Promise.all(indices.map((i:number) => mct.tokenOfOwnerByIndex(address, i))); | ||
const bonds = await Promise.all(tokenIDs.map(id => mct.bonds(id))); | ||
|
||
let supplySum = BN.from(0); | ||
let rewardSum = BN.from(0); | ||
indices.forEach((i:number) => { | ||
supplySum = supplySum.add(bonds[i].principalPaid); | ||
rewardSum = rewardSum.add(bonds[i].payoutAmount.sub(bonds[i].payoutAlreadyClaimed)); | ||
}); | ||
|
||
return [ | ||
drillBalance(stakedToken, supplySum.toString()), | ||
drillBalance(rewardToken, rewardSum.toString()), | ||
]; | ||
}, | ||
}); | ||
address, | ||
appId: SOLACE_DEFINITION.id, | ||
groupId: SOLACE_DEFINITION.groups.bonds.id, | ||
network, | ||
resolveBalances: async ({ address, contractPosition, multicall }) => { | ||
// Resolve the staked token and reward token from the contract position object | ||
const stakedToken = contractPosition.tokens.find(t => t.metaType === MetaType.SUPPLIED)!; | ||
const rewardToken = contractPosition.tokens.find(t => t.metaType === MetaType.CLAIMABLE)!; | ||
const teller = solaceContractFactory.bondTellerErc20({ address: contractPosition.address, network }); | ||
|
||
const mct = multicall.wrap(teller); | ||
const balance = await mct.balanceOf(address); | ||
const indices = range(0, balance.toNumber()); | ||
const tokenIDs = await Promise.all(indices.map((i: number) => mct.tokenOfOwnerByIndex(address, i))); | ||
const bonds = await Promise.all(tokenIDs.map(id => mct.bonds(id))); | ||
|
||
let supplySum = BN.from(0); | ||
let rewardSum = BN.from(0); | ||
indices.forEach((i: number) => { | ||
supplySum = supplySum.add(bonds[i].principalPaid); | ||
rewardSum = rewardSum.add(bonds[i].payoutAmount.sub(bonds[i].payoutAlreadyClaimed)); | ||
}); | ||
|
||
return [drillBalance(stakedToken, supplySum.toString()), drillBalance(rewardToken, rewardSum.toString())]; | ||
}, | ||
}); | ||
} |
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 |
---|---|---|
@@ -1,28 +1,30 @@ | ||
import { SolaceContractFactory } from '../../contracts'; | ||
import { Network } from '~types/network.interface'; | ||
import { SOLACE_DEFINITION } from '../../solace.definition'; | ||
import { drillBalance } from '~app-toolkit'; | ||
import { IAppToolkit } from '~app-toolkit/app-toolkit.interface'; | ||
import { Token } from '~position/position.interface'; | ||
import { WithMetaType } from '~position/display.interface'; | ||
import { MetaType } from '~position/position.interface'; | ||
import { Network } from '~types/network.interface'; | ||
|
||
import { SolaceContractFactory } from '../../contracts'; | ||
import { SOLACE_DEFINITION } from '../../solace.definition'; | ||
|
||
export default async function getPolicyBalance(address: string, appToolkit: IAppToolkit, solaceContractFactory: SolaceContractFactory) { | ||
export default async function getPolicyBalance( | ||
address: string, | ||
appToolkit: IAppToolkit, | ||
solaceContractFactory: SolaceContractFactory, | ||
) { | ||
const network = Network.ETHEREUM_MAINNET; | ||
return appToolkit.helpers.contractPositionBalanceHelper.getContractPositionBalances({ | ||
address, | ||
appId: SOLACE_DEFINITION.id, | ||
groupId: SOLACE_DEFINITION.groups.policies.id, | ||
network, | ||
resolveBalances: async ({ address, contractPosition, multicall }) => { | ||
// Resolve the staked token and reward token from the contract position object | ||
const stakedToken = contractPosition.tokens.find((t:WithMetaType<Token>) => t.metaType === 'supplied')!; | ||
address, | ||
appId: SOLACE_DEFINITION.id, | ||
groupId: SOLACE_DEFINITION.groups.policies.id, | ||
network, | ||
resolveBalances: async ({ address, contractPosition }) => { | ||
// Resolve the staked token and reward token from the contract position object | ||
const stakedToken = contractPosition.tokens.find(t => t.metaType === MetaType.SUPPLIED)!; | ||
|
||
const product = solaceContractFactory.solaceCoverProduct({ address: contractPosition.address, network }); | ||
const bal = await product.accountBalanceOf(address); | ||
const product = solaceContractFactory.solaceCoverProduct({ address: contractPosition.address, network }); | ||
const bal = await product.accountBalanceOf(address); | ||
|
||
return [ | ||
drillBalance(stakedToken, bal.toString()), | ||
]; | ||
}, | ||
}); | ||
return [drillBalance(stakedToken, bal.toString())]; | ||
}, | ||
}); | ||
} |
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 |
---|---|---|
@@ -1,53 +1,55 @@ | ||
import { SolaceContractFactory } from '../../contracts'; | ||
import { Network } from '~types/network.interface'; | ||
import { SOLACE_DEFINITION } from '../../solace.definition'; | ||
import { ethers } from 'ethers'; | ||
import { range } from 'lodash'; | ||
|
||
import { drillBalance } from '~app-toolkit'; | ||
import { IAppToolkit } from '~app-toolkit/app-toolkit.interface'; | ||
import { Token } from '~position/position.interface'; | ||
import { WithMetaType } from '~position/display.interface'; | ||
import { MetaType } from '~position/position.interface'; | ||
import { Network } from '~types/network.interface'; | ||
|
||
import { SolaceContractFactory } from '../../contracts'; | ||
import { SOLACE_DEFINITION } from '../../solace.definition'; | ||
|
||
import { ethers } from 'ethers'; | ||
const BN = ethers.BigNumber; | ||
import { range } from '~apps/solace/utils'; | ||
|
||
const XSLOCKER_ADDRESS = "0x501ace47c5b0c2099c4464f681c3fa2ecd3146c1"; | ||
const STAKING_REWARDS_ADDRESS = "0x501ace3d42f9c8723b108d4fbe29989060a91411"; | ||
const XSLOCKER_ADDRESS = '0x501ace47c5b0c2099c4464f681c3fa2ecd3146c1'; | ||
const STAKING_REWARDS_ADDRESS = '0x501ace3d42f9c8723b108d4fbe29989060a91411'; | ||
|
||
export default async function getXSLockerBalance(address: string, appToolkit: IAppToolkit, solaceContractFactory: SolaceContractFactory) { | ||
export default async function getXSLockerBalance( | ||
address: string, | ||
appToolkit: IAppToolkit, | ||
solaceContractFactory: SolaceContractFactory, | ||
) { | ||
const network = Network.ETHEREUM_MAINNET; | ||
return appToolkit.helpers.contractPositionBalanceHelper.getContractPositionBalances({ | ||
address, | ||
appId: SOLACE_DEFINITION.id, | ||
groupId: SOLACE_DEFINITION.groups.xslocker.id, | ||
network, | ||
resolveBalances: async ({ address, contractPosition, multicall }) => { | ||
// Resolve the staked token and reward token from the contract position object | ||
const stakedToken = contractPosition.tokens.find((t:WithMetaType<Token>) => t.metaType === 'supplied')!; | ||
const rewardToken = contractPosition.tokens.find((t:WithMetaType<Token>) => t.metaType === 'claimable')!; | ||
|
||
const xslocker = solaceContractFactory.xsLocker({ address: XSLOCKER_ADDRESS, network }); | ||
const stakingRewards = solaceContractFactory.stakingRewards({ address: STAKING_REWARDS_ADDRESS, network }); | ||
|
||
const mcxsl = multicall.wrap(xslocker); | ||
const mcsr = multicall.wrap(stakingRewards); | ||
|
||
const balance = await xslocker.balanceOf(address); | ||
const indices = range(0, balance.toNumber()); | ||
const tokenIDs = await Promise.all(indices.map((i:number) => mcxsl.tokenOfOwnerByIndex(address, i))); | ||
const locks = await Promise.all(tokenIDs.map(id => mcxsl.locks(id))); | ||
const rewards = await Promise.all(tokenIDs.map(id => mcsr.pendingRewardsOfLock(id))); | ||
|
||
let supplySum = BN.from(0); | ||
let rewardSum = BN.from(0); | ||
indices.forEach((i:number) => { | ||
supplySum = supplySum.add(locks[i].amount); | ||
rewardSum = rewardSum.add(rewards[i]); | ||
}); | ||
|
||
return [ | ||
drillBalance(stakedToken, supplySum.toString()), | ||
drillBalance(rewardToken, rewardSum.toString()), | ||
]; | ||
}, | ||
}); | ||
address, | ||
appId: SOLACE_DEFINITION.id, | ||
groupId: SOLACE_DEFINITION.groups.xslocker.id, | ||
network, | ||
resolveBalances: async ({ address, contractPosition, multicall }) => { | ||
// Resolve the staked token and reward token from the contract position object | ||
const stakedToken = contractPosition.tokens.find(t => t.metaType === MetaType.SUPPLIED)!; | ||
const rewardToken = contractPosition.tokens.find(t => t.metaType === MetaType.CLAIMABLE)!; | ||
|
||
const xslocker = solaceContractFactory.xsLocker({ address: XSLOCKER_ADDRESS, network }); | ||
const stakingRewards = solaceContractFactory.stakingRewards({ address: STAKING_REWARDS_ADDRESS, network }); | ||
|
||
const mcxsl = multicall.wrap(xslocker); | ||
const mcsr = multicall.wrap(stakingRewards); | ||
|
||
const balance = await xslocker.balanceOf(address); | ||
const indices = range(0, balance.toNumber()); | ||
const tokenIDs = await Promise.all(indices.map((i: number) => mcxsl.tokenOfOwnerByIndex(address, i))); | ||
const locks = await Promise.all(tokenIDs.map(id => mcxsl.locks(id))); | ||
const rewards = await Promise.all(tokenIDs.map(id => mcsr.pendingRewardsOfLock(id))); | ||
|
||
let supplySum = BN.from(0); | ||
let rewardSum = BN.from(0); | ||
indices.forEach((i: number) => { | ||
supplySum = supplySum.add(locks[i].amount); | ||
rewardSum = rewardSum.add(rewards[i]); | ||
}); | ||
|
||
return [drillBalance(stakedToken, supplySum.toString()), drillBalance(rewardToken, rewardSum.toString())]; | ||
}, | ||
}); | ||
} |
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.