Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip]: bs3-ui-misc #1102

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"ui:test": "yarn workspace ui test",
"test:browser": "yarn workspace tests test:browser",
"ex": "yarn workspace @beanstalk/examples x",
"anvil-arbitrum": "yarn cli:anvil-arbitrum --code-size-limit 50000 --fork-block-number 250704543",
"anvil-arbitrum": "yarn cli:anvil-arbitrum --code-size-limit 50000 --fork-block-number 254247030",
"anvil-eth-mainnet": "yarn cli:anvil-eth-mainnet",
"anvil": "anvil --fork-url https://eth-mainnet.g.alchemy.com/v2/5ubn94zT7v7DnB5bNW1VOnoIbX5-AG2N --chain-id 1337",
"anvil4tests": "anvil --fork-url https://eth-mainnet.g.alchemy.com/v2/Kk7ktCQL5wz4v4AG8bR2Gun8TAASQ-qi --chain-id 1337 --fork-block-number 18629000"
Expand Down
2 changes: 1 addition & 1 deletion projects/examples/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const RPC_URL = "http://127.0.0.1:8545";
const network = {
name: "local",
chainId: ChainId.LOCALHOST,
_defaultProvider: () => new ethers.providers.JsonRpcProvider(RPC_URL, network)
_defaultProvider: () => new ethers.providers.JsonRpcProvider(RPC_URL)
};

export const provider = new ethers.providers.StaticJsonRpcProvider(RPC_URL, network);
Expand Down
44 changes: 19 additions & 25 deletions projects/sdk/src/classes/Pool/BasinWell.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,11 @@
import { BasinWell__factory, BasinWell as BasinWellContract } from "src/constants/generated";
import { BasinWell__factory } from "src/constants/generated";
import { TokenValue } from "src/TokenValue";
import Pool, { Reserves } from "./Pool";
import { ERC20Token } from "../Token";
import { BeanstalkSDK } from "src/lib/BeanstalkSDK";

export class BasinWell extends Pool {
public readonly contract: BasinWellContract;

constructor(
sdk: BeanstalkSDK,
address: string,
lpToken: ERC20Token,
tokens: ERC20Token[],
metadata: {
name: string;
symbol: string;
logo: string;
color: string;
}
) {
super(sdk, address, lpToken, tokens, metadata);
this.contract = BasinWell__factory.connect(address, sdk.providerOrSigner);
}

public getContract() {
return this.contract;
return BasinWell__factory.connect(this.address, Pool.sdk.providerOrSigner);
}

public getReserves() {
Expand All @@ -44,21 +25,34 @@ export class BasinWell extends Pool {
}

async getAddLiquidityOut(amounts: TokenValue[]) {
return this.contract
return this.getContract()
.getAddLiquidityOut(amounts.map((a) => a.toBigNumber()))
.then((result) => this.lpToken.fromBlockchain(result));
}

async getRemoveLiquidityOutEqual(amount: TokenValue) {
return this.contract
return this.getContract()
.getRemoveLiquidityOut(amount.toBigNumber())
.then((result) => this.tokens.map((token, i) => token.fromBlockchain(result[i])));
}

async getRemoveLiquidityOutOneToken(lpAmountIn: TokenValue, tokenOut: ERC20Token) {
return this.contract
const tokenIndex = this.tokens.findIndex((token) => token.equals(tokenOut));
if (tokenIndex < 0) {
throw new Error(`Unable to determine token index of ${tokenOut.symbol} in ${this.tokens}`);
}

return this.getContract()
.getRemoveLiquidityOneTokenOut(lpAmountIn.toBigNumber(), tokenOut.address)
.then((result) => tokenOut.fromBlockchain(result));
.then((result) => {
const underlying = [
tokenOut.fromBlockchain(result),
this.tokens[tokenIndex === 0 ? 1 : 0].fromHuman(0)
];
// If the specified token out index === 1, reverse the result
if (tokenIndex === 1) return underlying.reverse();
return underlying;
});
}

/**
Expand Down
28 changes: 12 additions & 16 deletions projects/sdk/src/constants/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ export const addresses = {
[ChainId.ARBITRUM_MAINNET]: "0x6985884C4392D348587B19cb9eAAf157F13271cd"
}),

// ----------------------------------------
// Uniswap V3
UNISWAP_V3_ROUTER: Address.make({
[ChainId.ETH_MAINNET]: "0xE592427A0AEce92De3Edee1F18E0157C05861564",
[ChainId.ARBITRUM_MAINNET]: "0xE592427A0AEce92De3Edee1F18E0157C05861564"
}),

UNISWAP_V3_QUOTER_V2: Address.make({
[ChainId.ETH_MAINNET]: "0x61fFE014bA17989E743c5F6cB21bF9697530B21e",
[ChainId.ARBITRUM_MAINNET]: "0x61fFE014bA17989E743c5F6cB21bF9697530B21e"
}),

// ----------------------------------------
// Curve Pools: Other
// ----------------------------------------
Expand Down Expand Up @@ -255,22 +267,6 @@ export const addresses = {
[ChainId.ETH_MAINNET]: "0xA79828DF1850E8a3A3064576f380D90aECDD3359"
}),

/**
* @deprecated
* Uniswap V3 Router
*/
UNISWAP_V3_ROUTER: Address.make({
[ChainId.ETH_MAINNET]: "0xE592427A0AEce92De3Edee1F18E0157C05861564"
}),

/**
* @deprecated
* Uniswap V3 Quoter V2
*/
UNISWAP_V3_QUOTER_V2: Address.make({
[ChainId.ETH_MAINNET]: "0x61fFE014bA17989E743c5F6cB21bF9697530B21e"
}),

/**
* @deprecated
*/
Expand Down
71 changes: 26 additions & 45 deletions projects/sdk/src/lib/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,7 @@ import {
UnwrapAndSendEthJunction,
UnwrapAndSendEthJunction__factory,
Junction,
Junction__factory,
Curve3Pool,
CurveCryptoFactory,
CurveMetaFactory,
CurveMetaPool,
CurveRegistry,
CurveTriCrypto2Pool,
CurveZap,
Curve3Pool__factory,
CurveCryptoFactory__factory,
CurveMetaFactory__factory,
CurveMetaPool__factory,
CurveRegistry__factory,
CurveTriCrypto2Pool__factory,
CurveZap__factory
Junction__factory
} from "src/constants/generated";

type LidoContracts = {
Expand All @@ -60,30 +46,27 @@ export class Contracts {
public readonly pipeline: Pipeline;
public readonly depot: Depot;
public readonly junction: Junction;
public readonly usdOracle: UsdOracle;
public readonly pipelineJunctions: PipelineJunctions;

public readonly lido: LidoContracts;

// Deprecated contracts
public readonly uniswapV3Router: UniswapV3Router;
public readonly uniswapV3QuoterV2: UniswapV3QuoterV2;

/**
* @deprecated
* @description External contract not part of Beanstalk3 L2 migration.
* @description Not included in Beanstalk3 deployment on Arbitrum.
* @note mainnet Beanstalk only
*/
public readonly root: Root | null = null;

/**
* @deprecated as of Beanstalk 3.0 L2 migration
* @description mainnet only
*/
public readonly uniswapV3Router: UniswapV3Router;
public readonly usdOracle: UsdOracle;

// Deprecated contracts
/**
* @deprecated as of Beanstalk 3.0 L2 migration
* @description mainnet only
* @deprecated
* @description Not included in Beanstalk3 deployment on Arbitrum.
* @note mainnet Beanstalk only
*/
public readonly uniswapV3QuoterV2: UniswapV3QuoterV2;
public readonly root: Root | null = null;

constructor(sdk: BeanstalkSDK) {
Contracts.sdk = sdk;
Expand Down Expand Up @@ -137,31 +120,29 @@ export class Contracts {
)
};
}
if (rootAddress) {
this.root = Root__factory.connect(rootAddress, sdk.providerOrSigner);
}
if (usdOracleAddress) {
this.usdOracle = UsdOracle__factory.connect(usdOracleAddress, sdk.providerOrSigner);
}

// Lido
this.lido = {
wsteth: Wsteth__factory.connect(wstEthAddress, sdk.providerOrSigner)
};

// Uniswap
if (uniswapV3RouterAddress) {
this.uniswapV3Router = UniswapV3Router__factory.connect(
uniswapV3RouterAddress,
sdk.providerOrSigner
);
}

if (uniswapV3QuoterV2Address) {
this.uniswapV3QuoterV2 = UniswapV3QuoterV2__factory.connect(
uniswapV3QuoterV2Address,
sdk.providerOrSigner
);
this.uniswapV3Router = UniswapV3Router__factory.connect(
uniswapV3RouterAddress,
sdk.providerOrSigner
);

this.uniswapV3QuoterV2 = UniswapV3QuoterV2__factory.connect(
uniswapV3QuoterV2Address,
sdk.providerOrSigner
);

if (rootAddress) {
this.root = Root__factory.connect(rootAddress, sdk.providerOrSigner);
}
if (usdOracleAddress) {
this.usdOracle = UsdOracle__factory.connect(usdOracleAddress, sdk.providerOrSigner);
}
}
}
8 changes: 8 additions & 0 deletions projects/sdk/src/lib/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,21 @@ export class Pools {
return this.whitelistedPools.has(_pool.address);
}

// Do we need this? Maybe we can just have wells only??
getPoolByLPToken(token: Token | string): Pool | undefined {
if (typeof token === "string") {
return this.lpAddressMap.get(token.toLowerCase());
}
return this.lpAddressMap.get(token.address);
}

getWellByLPToken(token: Token | string): BasinWell | undefined {
if (typeof token === "string") {
return this.wellAddressMap.get(token.toLowerCase());
}
return this.wellAddressMap.get(token.address);
}

getWells(): readonly BasinWell[] {
return Array.from(this.wellAddressMap.values()) as ReadonlyArray<BasinWell>;
}
Expand Down
17 changes: 14 additions & 3 deletions projects/sdk/src/lib/silo/Convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ export class Convert {
this.paths.set(Convert.sdk.tokens.BEAN, [
// Convert.sdk.tokens.BEAN_CRV3_LP, // Deprecated.
Convert.sdk.tokens.BEAN_WSTETH_WELL_LP,
Convert.sdk.tokens.BEAN_ETH_WELL_LP
Convert.sdk.tokens.BEAN_ETH_WELL_LP,
Convert.sdk.tokens.BEAN_WBTC_WELL_LP,
Convert.sdk.tokens.BEAN_WEETH_WELL_LP,
Convert.sdk.tokens.BEAN_USDC_WELL_LP,
Convert.sdk.tokens.BEAN_USDT_WELL_LP
]);
this.paths.set(Convert.sdk.tokens.BEAN_CRV3_LP, [Convert.sdk.tokens.BEAN]);
this.paths.set(Convert.sdk.tokens.BEAN_ETH_WELL_LP, [Convert.sdk.tokens.BEAN]);
Expand All @@ -57,6 +61,10 @@ export class Convert {
Convert.sdk.tokens.UNRIPE_BEAN,
Convert.sdk.tokens.BEAN_WSTETH_WELL_LP
]);
this.paths.set(Convert.sdk.tokens.BEAN_WBTC_WELL_LP, [Convert.sdk.tokens.BEAN]);
this.paths.set(Convert.sdk.tokens.BEAN_USDC_WELL_LP, [Convert.sdk.tokens.BEAN]);
this.paths.set(Convert.sdk.tokens.BEAN_USDT_WELL_LP, [Convert.sdk.tokens.BEAN]);
this.paths.set(Convert.sdk.tokens.BEAN_WEETH_WELL_LP, [Convert.sdk.tokens.BEAN]);
}

async convert(
Expand Down Expand Up @@ -168,7 +176,11 @@ export class Convert {

const whitelistedWellLPs = new Set([
Convert.sdk.tokens.BEAN_ETH_WELL_LP.address.toLowerCase(),
Convert.sdk.tokens.BEAN_WSTETH_WELL_LP.address.toLowerCase()
Convert.sdk.tokens.BEAN_WSTETH_WELL_LP.address.toLowerCase(),
Convert.sdk.tokens.BEAN_USDC_WELL_LP.address.toLowerCase(),
Convert.sdk.tokens.BEAN_USDT_WELL_LP.address.toLowerCase(),
Convert.sdk.tokens.BEAN_WEETH_WELL_LP.address.toLowerCase(),
Convert.sdk.tokens.BEAN_WBTC_WELL_LP.address.toLowerCase()
]);
const isFromWlLP = Boolean(whitelistedWellLPs.has(fromToken.address.toLowerCase()));
const isToWlLP = Boolean(whitelistedWellLPs.has(toToken.address.toLowerCase()));
Expand Down Expand Up @@ -267,5 +279,4 @@ export class Convert {
const token = Convert.sdk.tokens.findByAddress(fromToken.address);
return token ? this.paths.get(token) || [] : [];
}

}
18 changes: 12 additions & 6 deletions projects/sdk/src/utils/TestUtils/BlockchainUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,18 @@ export class BlockchainUtils {
private getBalanceConfig(tokenAddress: string) {
const slotConfig = new Map();
slotConfig.set(this.sdk.tokens.BEAN.address, [0, false]);
slotConfig.set(this.sdk.tokens.WETH.address, [0, false]);
slotConfig.set(this.sdk.tokens.WSTETH.address, [0, false]);
slotConfig.set(this.sdk.tokens.WEETH.address, [0, false]);
slotConfig.set(this.sdk.tokens.WBTC.address, [0, false]);
slotConfig.set(this.sdk.tokens.USDC.address, [0, false]);
slotConfig.set(this.sdk.tokens.USDT.address, [0, false]);
slotConfig.set(this.sdk.tokens.WETH.address, [51, false]); // OnChain
// slotConfig.set(this.sdk.tokens.WETH.address, [0, false]); // MockToken
slotConfig.set(this.sdk.tokens.WSTETH.address, [1, false]); // OnChain
// slotConfig.set(this.sdk.tokens.WSTETH.address, [0, false]); // MockToken
slotConfig.set(this.sdk.tokens.WEETH.address, [51, false]); // OnChain
// slotConfig.set(this.sdk.tokens.WEETH.address, [0, false]); // MockToken
slotConfig.set(this.sdk.tokens.WBTC.address, [51, false]); // OnChain
// slotConfig.set(this.sdk.tokens.WBTC.address, [0, false]); // MockToken
slotConfig.set(this.sdk.tokens.USDC.address, [9, false]); // OnChain
// slotConfig.set(this.sdk.tokens.USDC.address, [0, false]); // MockToken
slotConfig.set(this.sdk.tokens.USDT.address, [51, false]); // OnChain
// slotConfig.set(this.sdk.tokens.USDT.address, [0, false]); // MockToken
slotConfig.set(this.sdk.tokens.DAI.address, [2, false]);
slotConfig.set(this.sdk.tokens.UNRIPE_BEAN.address, [0, false]);
slotConfig.set(this.sdk.tokens.UNRIPE_BEAN_WSTETH.address, [0, false]);
Expand Down
13 changes: 10 additions & 3 deletions projects/sdk/src/utils/TestUtils/provider.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import { ethers } from "ethers";
import { BeanstalkSDK, DataSource } from "src/lib/BeanstalkSDK";
import { BlockchainUtils } from "./BlockchainUtils";
import { ChainId } from "@beanstalk/sdk-core";

// private key + account mapping
// these keys are provided by hardhat/anvil
export const ACCOUNTS = [
["0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"],
["0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d", "0x70997970c51812dc3a010c7d01b50e0d17dc79c8"]
[
"0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
"0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"
],
[
"0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d",
"0x70997970c51812dc3a010c7d01b50e0d17dc79c8"
]
] as const;

export const getProvider = () =>
new ethers.providers.StaticJsonRpcProvider(`http://127.0.0.1:8545`, {
name: "foundry",
chainId: 41337 // default to arbitrum-local
chainId: ChainId.LOCALHOST // default to arbitrum-local
});

export const setupConnection = (provider: ethers.providers.JsonRpcProvider = getProvider()) => {
Expand Down
12 changes: 12 additions & 0 deletions projects/ui/src/graph/graphql.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -128859,6 +128859,18 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "proposalsCount1d",
"description": null,
"args": [],
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "proposalsCount7d",
"description": null,
Expand Down
1 change: 1 addition & 0 deletions projects/ui/src/graph/schema-snapshot1.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ type Space {
plugins: Any
private: Boolean
proposalsCount: Int
proposalsCount1d: Int
proposalsCount7d: Int
rank: Float
skin: String
Expand Down
Loading