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

Commit

Permalink
feat(polynomial): Fix smart wallet balances (#3095)
Browse files Browse the repository at this point in the history
  • Loading branch information
immasandwich authored Dec 1, 2023
1 parent 5075240 commit 5d49ce6
Showing 1 changed file with 15 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Inject } from '@nestjs/common';
import Axios from 'axios';

import { APP_TOOLKIT, IAppToolkit } from '~app-toolkit/app-toolkit.interface';
import { PositionTemplate } from '~app-toolkit/decorators/position-template.decorator';
Expand All @@ -11,7 +10,6 @@ import {
DefaultContractPositionDefinition,
GetDisplayPropsParams,
GetTokenBalancesParams,
GetTokenDefinitionsParams,
} from '~position/template/contract-position.template.types';

import { PolynomialAccountResolver } from '../common/polynomial.account-resolver';
Expand All @@ -22,13 +20,6 @@ export type PolynomialSmartWalletDataProp = {

@PositionTemplate()
export class OptimismPolynomialSmartWalletContractPositionFetcher extends ContractPositionTemplatePositionFetcher<Erc20> {
supportedTokens = [
'0x8c6f28f2f1a3c87f0f938b96d27520d9751ec8d9', //sUSD
'0x7f5c764cbc14f9669b88837ca1490cca17c31607', //USDC
'0x94b008aa00579c1307b0ef2c499ad98a8ce58e58', //USDT
'0xda10009cbd5d07dd0cecc66161fc93d7c9000da1', //DAI
'0x4200000000000000000000000000000000000042', //OP
];
groupLabel = 'Smart Wallet';

constructor(
Expand All @@ -43,40 +34,33 @@ export class OptimismPolynomialSmartWalletContractPositionFetcher extends Contra
}

async getDefinitions(): Promise<DefaultContractPositionDefinition[]> {
return this.supportedTokens.map(token => {
return { address: token };
});
return [{ address: '0xb43c0899eccf98bc7a0f3e2c2a211d6fc4f9b3fe' }];
}

async getLabel({ contractPosition }: GetDisplayPropsParams<Erc20>): Promise<string> {
return getLabelFromToken(contractPosition.tokens[0]);
}

async getTokenDefinitions({ contract }: GetTokenDefinitionsParams<Erc20>) {
async getTokenDefinitions() {
return [
{
address: contract.address,
metaType: MetaType.SUPPLIED,
network: this.network,
},
];
'0x8c6f28f2f1a3c87f0f938b96d27520d9751ec8d9', //sUSD
'0x7f5c764cbc14f9669b88837ca1490cca17c31607', //USDC
'0x94b008aa00579c1307b0ef2c499ad98a8ce58e58', //USDT
'0xda10009cbd5d07dd0cecc66161fc93d7c9000da1', //DAI
'0x4200000000000000000000000000000000000042', //OP
].map(address => ({ metaType: MetaType.SUPPLIED, address, network: this.network }));
}

async getAccountAddress(address: string): Promise<string> {
return this.polynomialAccountResolver.getSmartWalletAddress(address);
}

async getTokenBalancesPerPosition({ address, contract }: GetTokenBalancesParams<Erc20>) {
return [await contract.read.balanceOf([address])];
}

async getDataProps({ contract }): Promise<PolynomialSmartWalletDataProp> {
if ((await contract.read.symbol()) != 'sUSD') {
return { liquidity: 0 };
}
const { data } = await Axios.get<{ tvl: number }>('https://perps-api-experimental.polynomial.fi/snx-perps/tvl');
return {
liquidity: data.tvl,
};
async getTokenBalancesPerPosition({ address, multicall, contractPosition }: GetTokenBalancesParams<Erc20>) {
return await Promise.all(
contractPosition.tokens.map(token => {
const contract = this.appToolkit.globalViemContracts.erc20({ address: token.address, network: this.network });
return multicall.wrap(contract).read.balanceOf([address]);
}),
);
}
}

0 comments on commit 5d49ce6

Please sign in to comment.