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

Commit

Permalink
Enable better interface for single vault token helper (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
immasandwich authored Apr 13, 2022
1 parent 177fd29 commit 06aad39
Show file tree
Hide file tree
Showing 8 changed files with 784 additions and 9 deletions.
14 changes: 8 additions & 6 deletions src/app-toolkit/helpers/position/single-vault.token-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import { Network } from '~types/network.interface';
import { buildDollarDisplayItem } from '../presentation/display-item.present';
import { getTokenImg } from '../presentation/image.present';

type SingleVaultTokenHelperParams = {
type SingleVaultTokenHelperParams<T> = {
address: string;
network: Network;
appId: string;
groupId: string;
dependencies?: AppGroupsDefinition[];
resolveUnderlyingTokenAddress: (opts: { address: string; network: Network }) => string | Promise<string>;
resolveContract: (opts: { address: string; network: Network }) => T;
resolveUnderlyingTokenAddress: (opts: { contract: T }) => string | Promise<string>;
resolveReserve?: (opts: { underlyingToken: Token; address: string; network: Network }) => Promise<number>;
resolvePricePerShare?: (opts: {
reserve: number;
Expand All @@ -34,12 +35,13 @@ export type SingleVaultTokenDataProps = {
export class SingleVaultTokenHelper {
constructor(@Inject(APP_TOOLKIT) private readonly appToolkit: IAppToolkit) {}

async getTokens({
async getTokens<T>({
address,
network,
appId,
groupId,
dependencies = [],
resolveContract,
resolveUnderlyingTokenAddress,
resolveReserve = async ({ underlyingToken, address, network }) => {
const contract = this.appToolkit.globalContracts.erc20({ address: underlyingToken.address, network });
Expand All @@ -48,15 +50,16 @@ export class SingleVaultTokenHelper {
},
resolvePricePerShare = ({ reserve, supply }) => reserve / supply,
resolveImages = ({ address }) => [getTokenImg(address, network)],
}: SingleVaultTokenHelperParams) {
}: SingleVaultTokenHelperParams<T>) {
// Supports implementations forked (or similar) to xSUSHI
const type = ContractType.APP_TOKEN;
const multicall = this.appToolkit.getMulticall(network);
const baseTokens = await this.appToolkit.getBaseTokenPrices(network);
const appTokens = await this.appToolkit.getAppTokenPositions(...dependencies);
const allTokens = [...appTokens, ...baseTokens];

const underlyingTokenAddressRaw = await resolveUnderlyingTokenAddress({ address, network });
const contract = resolveContract({ address, network });
const underlyingTokenAddressRaw = await resolveUnderlyingTokenAddress({ contract });
const underlyingTokenAddress = underlyingTokenAddressRaw.toLowerCase();
const underlyingToken = allTokens.find(p => p.address === underlyingTokenAddress);
if (!underlyingToken) return [];
Expand All @@ -74,7 +77,6 @@ export class SingleVaultTokenHelper {
const pricePerShare = await resolvePricePerShare({ reserve, supply, address, network });
const price = Number(pricePerShare) * underlyingToken.price;
const liquidity = supply * price;

const tokens = [underlyingToken];

// Display properties
Expand Down
123 changes: 123 additions & 0 deletions src/apps/aelin/contracts/abis/aelin-v-aelin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
[
{
"inputs": [{ "internalType": "address", "name": "preDistributionAddress", "type": "address" }],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "owner", "type": "address" },
{ "indexed": true, "internalType": "address", "name": "spender", "type": "address" },
{ "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" }
],
"name": "Approval",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "from", "type": "address" },
{ "indexed": true, "internalType": "address", "name": "to", "type": "address" },
{ "indexed": false, "internalType": "uint256", "name": "value", "type": "uint256" }
],
"name": "Transfer",
"type": "event"
},
{
"inputs": [
{ "internalType": "address", "name": "owner", "type": "address" },
{ "internalType": "address", "name": "spender", "type": "address" }
],
"name": "allowance",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "spender", "type": "address" },
{ "internalType": "uint256", "name": "amount", "type": "uint256" }
],
"name": "approve",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "account", "type": "address" }],
"name": "balanceOf",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "decimals",
"outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "spender", "type": "address" },
{ "internalType": "uint256", "name": "subtractedValue", "type": "uint256" }
],
"name": "decreaseAllowance",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "spender", "type": "address" },
{ "internalType": "uint256", "name": "addedValue", "type": "uint256" }
],
"name": "increaseAllowance",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "name",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "symbol",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "totalSupply",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "recipient", "type": "address" },
{ "internalType": "uint256", "name": "amount", "type": "uint256" }
],
"name": "transfer",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "sender", "type": "address" },
{ "internalType": "address", "name": "recipient", "type": "address" },
{ "internalType": "uint256", "name": "amount", "type": "uint256" }
],
"name": "transferFrom",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "nonpayable",
"type": "function"
}
]
Loading

0 comments on commit 06aad39

Please sign in to comment.