Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Commit

Permalink
fix(solace): Adjust Solace implementation (#472)
Browse files Browse the repository at this point in the history
  • Loading branch information
immasandwich authored May 20, 2022
1 parent 860de45 commit cdd243d
Show file tree
Hide file tree
Showing 28 changed files with 637 additions and 708 deletions.
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- [ ] I have followed the [Contributing Guidelines](../CONTRIBUTING.md)
- [ ] (optional) As a contributor, my Ethereum address/ENS is:
- [ ] (optional) As a contributor, my Twitter handle is:

## How to test?

Expand Down
Binary file added src/apps/solace/assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 0 additions & 30 deletions src/apps/solace/assets/logo.svg

This file was deleted.

79 changes: 39 additions & 40 deletions src/apps/solace/ethereum/helpers/getBondBalance.ts
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())];
},
});
}
42 changes: 22 additions & 20 deletions src/apps/solace/ethereum/helpers/getPolicyBalance.ts
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())];
},
});
}
3 changes: 2 additions & 1 deletion src/apps/solace/ethereum/helpers/getScpBalance.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IAppToolkit } from '~app-toolkit/app-toolkit.interface';
import { Network } from '~types/network.interface';

import { SOLACE_DEFINITION } from '../../solace.definition';
import { IAppToolkit } from '~app-toolkit/app-toolkit.interface';

export default async function getScpBalance(address: string, appToolkit: IAppToolkit) {
return appToolkit.helpers.tokenBalanceHelper.getTokenBalances({
Expand Down
90 changes: 46 additions & 44 deletions src/apps/solace/ethereum/helpers/getXSLockerBalance.ts
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())];
},
});
}
3 changes: 2 additions & 1 deletion src/apps/solace/ethereum/helpers/getXSolaceV1Balance.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IAppToolkit } from '~app-toolkit/app-toolkit.interface';
import { Network } from '~types/network.interface';

import { SOLACE_DEFINITION } from '../../solace.definition';
import { IAppToolkit } from '~app-toolkit/app-toolkit.interface';

export default async function getXSolaceV1Balance(address: string, appToolkit: IAppToolkit) {
return appToolkit.helpers.tokenBalanceHelper.getTokenBalances({
Expand Down
9 changes: 5 additions & 4 deletions src/apps/solace/ethereum/solace.balance-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ import { Network } from '~types/network.interface';

import { SolaceContractFactory } from '../contracts';
import { SOLACE_DEFINITION } from '../solace.definition';
import getScpBalance from './helpers/getScpBalance';
import getXSolaceV1Balance from './helpers/getXSolaceV1Balance';
import getXSLockerBalance from './helpers/getXSLockerBalance';

import getBondBalance from './helpers/getBondBalance';
import getPolicyBalance from './helpers/getPolicyBalance';
import getScpBalance from './helpers/getScpBalance';
import getXSLockerBalance from './helpers/getXSLockerBalance';
import getXSolaceV1Balance from './helpers/getXSolaceV1Balance';

const network = Network.ETHEREUM_MAINNET;

@Register.BalanceFetcher(SOLACE_DEFINITION.id, network)
export class EthereumSolaceBalanceFetcher implements BalanceFetcher {
constructor(
@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit,
@Inject(SolaceContractFactory) private readonly solaceContractFactory: SolaceContractFactory
@Inject(SolaceContractFactory) private readonly solaceContractFactory: SolaceContractFactory,
) {}

async getBalances(address: string) {
Expand Down
Loading

0 comments on commit cdd243d

Please sign in to comment.