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

add holesky #174

Open
wants to merge 24 commits into
base: ultra-lrt
Choose a base branch
from
Open
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
768 changes: 0 additions & 768 deletions .yarn/releases/yarn-3.1.1.cjs

This file was deleted.

2 changes: 0 additions & 2 deletions .yarnrc.yml

This file was deleted.

1 change: 1 addition & 0 deletions dist/core/AlpineDeFiSDK.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ simulate = false, value) {
// regular (non-meta) tx
let overrides = { value };
args.push(overrides);
console.log("Blockchain call: ", { method }, args);
const gasLimit = (yield contract.estimateGas[method].apply(null, args)).mul(12).div(10);
overrides = { value, gasLimit };
args[args.length - 1] = overrides;
Expand Down
8 changes: 5 additions & 3 deletions dist/core/UltraLRT.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
export declare function canWithdraw(amount: string): Promise<boolean>;
export declare function canWithdraw(amount: number): Promise<boolean>;
export declare function withdraw(amount: string, address: string): Promise<import("./types").GasInfo | import("./types").SmallTxReceipt>;
export declare function redeem(address: string, epoch: string): Promise<import("./types").GasInfo | import("./types").SmallTxReceipt>;
export declare function canWithdrawEscrow(epoch: string): Promise<boolean>;
export declare function withdrawableAssets(address: string): Promise<{
totalAmount: number;
epochData: {
epoch: number;
value: number;
assets: string;
shares: string;
canWithdraw: boolean;
}[];
}>;
export declare function migratableAssets(address: string): Promise<number>;
export declare function queueMigrationWithdrawal(address: string, shares: string): Promise<import("./types").GasInfo | import("./types").SmallTxReceipt>;
export declare function queueMigrationWithdrawal(address: string, assets: string): Promise<import("./types").GasInfo | import("./types").SmallTxReceipt>;
export declare function completeMigrationWithdrawal(address: string, delegator: string, nonce: string, blockNumber: string, shares: string): Promise<import("./types").GasInfo | import("./types").SmallTxReceipt>;
43 changes: 30 additions & 13 deletions dist/core/UltraLRT.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { _removeDecimals, blockchainCall } from "./AlpineDeFiSDK";
import { _addDecimals, _removeDecimals, blockchainCall } from "./AlpineDeFiSDK";
import { getContracts } from "./cache";
import { _getVaultAndAsset } from "./product";
import { ethers } from "ethers";
function getUltraEthContract() {
return __awaiter(this, void 0, void 0, function* () {
Expand Down Expand Up @@ -40,7 +41,7 @@ function getEigenStETHContract() {
return eigenStETH;
});
}
const eigenStETHStrategy = "0x93c4b944D05dfe6df7645A86cd2206016c51564D";
const eigenStETHStrategy = "0x7D704507b76571a51d9caE8AdDAbBFd0ba0e63d3";
const stETHAddress = "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84";
function getEigenDelegatorContract() {
return __awaiter(this, void 0, void 0, function* () {
Expand All @@ -55,8 +56,9 @@ function getEigenDelegatorContract() {
// Vault
export function canWithdraw(amount) {
return __awaiter(this, void 0, void 0, function* () {
const ultraEth = yield getUltraEthContract();
const value = yield ultraEth.canWithdraw(amount);
const { vault, asset } = yield _getVaultAndAsset("ultraLRT");
const lrtVault = vault;
const value = yield lrtVault.canWithdraw(_addDecimals(amount.toString(), yield asset.decimals()));
return value;
});
}
Expand All @@ -83,15 +85,23 @@ export function canWithdrawEscrow(epoch) {
export function withdrawableAssets(address) {
return __awaiter(this, void 0, void 0, function* () {
const withdrawalEscrowV2 = yield getEscrowContract();
const lastEpoch = yield withdrawalEscrowV2.resolvingEpoch();
const { vault, asset } = yield _getVaultAndAsset("ultraLRT");
const vaultDecimals = yield vault.decimals();
const assetDecimals = yield asset.decimals();
const resolvingEpoch = (yield withdrawalEscrowV2.resolvingEpoch()).toNumber();
const currentEpoch = (yield withdrawalEscrowV2.currentEpoch()).toNumber();
let totalAmount = 0;
const epochData = [];
for (let i = 0; i <= lastEpoch.toNumber(); i++) {
const value = parseFloat(_removeDecimals(yield withdrawalEscrowV2.withdrawableAssets(address, i), 18));
if (value > 0) {
epochData.push({ epoch: i, value: value });
totalAmount += value;
}
for (let i = 0; i <= currentEpoch; i++) {
const shares = yield withdrawalEscrowV2.userDebtShare(ethers.BigNumber.from(i), address);
const assets = yield withdrawalEscrowV2.withdrawableAssets(address, i);
epochData.push({
epoch: i,
assets: _removeDecimals(assets, assetDecimals),
shares: _removeDecimals(shares, vaultDecimals),
canWithdraw: i < resolvingEpoch && shares.gt(0),
});
totalAmount += parseFloat(_removeDecimals(assets, assetDecimals));
}
return { totalAmount, epochData };
});
Expand All @@ -103,17 +113,24 @@ export function migratableAssets(address) {
return parseFloat(_removeDecimals(value, 18));
});
}
export function queueMigrationWithdrawal(address, shares) {
export function queueMigrationWithdrawal(address, assets) {
return __awaiter(this, void 0, void 0, function* () {
console.log("queueMigrationWithdrawal");
const eigenDelegator = yield getEigenDelegatorContract();
const eigenStETH = yield getEigenStETHContract();
const assetUnits = ethers.utils.parseUnits(assets, 18);
const shares = yield eigenStETH.underlyingToShares(assetUnits);
console.log("shares", shares.toString());
const queuedWithdrawalParams = [
{
strategies: [eigenStETHStrategy],
shares: [ethers.BigNumber.from(shares)],
recipient: address,
},
];
return blockchainCall(eigenDelegator, "queueWithdrawals", [queuedWithdrawalParams]);
const queuedWithdrawalParams2 = [[[[eigenStETHStrategy], [ethers.BigNumber.from(shares)], address]]];
console.log("queuedWithdrawalParams2", queuedWithdrawalParams2);
return blockchainCall(eigenDelegator, "queueWithdrawals", queuedWithdrawalParams2);
});
}
export function completeMigrationWithdrawal(address, delegator, nonce, blockNumber, shares) {
Expand Down
7 changes: 4 additions & 3 deletions dist/core/cache.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ethers } from "ethers";
import { BaseContracts, EthContracts, PolygonContracts } from "./types";
import { BaseContracts, EthContracts, HoleskyContracts, PolygonContracts } from "./types";
import { AllowedChainId } from "../types/account";
export declare let SIGNER: ethers.Signer;
export declare let userAddress: string;
Expand All @@ -15,11 +15,12 @@ export declare function getProviderByChainId(chainId: AllowedChainId): ethers.pr
* @param version The addressbook version
* @returns A map of contract names to ethers.Contract objects
*/
export declare function getAllContracts(provider: ethers.providers.JsonRpcProvider): Promise<PolygonContracts | EthContracts | BaseContracts>;
export declare function getContracts(): PolygonContracts | EthContracts | BaseContracts;
export declare function getAllContracts(provider: ethers.providers.JsonRpcProvider): Promise<PolygonContracts | EthContracts | BaseContracts | HoleskyContracts>;
export declare function getContracts(): PolygonContracts | EthContracts | BaseContracts | HoleskyContracts;
export declare function getEthContracts(): EthContracts;
export declare function getPolygonContracts(): PolygonContracts;
export declare function getBaseContracts(): BaseContracts;
export declare function getHoleskyContract(): HoleskyContracts;
export declare function init(signerOrAddress: ethers.Signer | string, biconomy: ethers.providers.Web3Provider | undefined, chainId?: AllowedChainId): Promise<void>;
export declare function getChainId(): number;
export declare function setProvider(provider: ethers.providers.JsonRpcProvider): void;
Expand Down
26 changes: 23 additions & 3 deletions dist/core/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const RPC_URLS = {
? FORKED_NODE_URL_FOR_ETH
: `https://eth-mainnet.alchemyapi.io/v2/${process.env.ALCHEMY_API_KEY}`,
5: `https://eth-goerli.alchemyapi.io/v2/${process.env.ALCHEMY_API_KEY}`,
17000: `https://ethereum-holesky-rpc.publicnode.com`,
137: IS_USING_FORKED_MAINNET && FORKED_NODE_URL_FOR_MATIC
? FORKED_NODE_URL_FOR_MATIC
: `https://polygon-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`,
Expand Down Expand Up @@ -75,9 +76,14 @@ export function getAllContracts(provider) {
"function queueWithdrawals((address[],uint256[],address)[])",
"function completeQueuedWithdrawals((address,address,address,uint256,uint32,address[],uint256[])[],address[][],uint256[],bool[])",
];
const eigenStEthAbi = ["function userUnderlyingView(address) view returns (uint256)"];
const eigenStEthAbi = [
"function userUnderlyingView(address) view returns (uint256)",
"function underlyingToShares(uint256) view returns (uint256)",
];
const { PolygonAlpSave: alpSaveData, PolygonBtcEthVault: alpLargeData, Forwarder: forwarder, ERC4626Router: router, EthUsdcEarn: ethEarnData, EthWethEarn: ethWethEarnData, EthRouter: ethRouter, EthSushiLpUsdcWeth: ssvEthSushiUSDEarn, Degen: degenData, PolygonDegen: polygonDegenData, EthStEthLev: ethLeverageData, PolygonStEthLev: polygonLeverageData, AffineGenesis: affineGenesisData, AffinePass: affinePassData, AffinePassBridgePolygon: affinePassBridgePolygonData, AffinePassBridgeEthereum: affinePassBridgeEthereumData, BaseUsdEarn: baseUsdEarnData, BaseStEthLev: baseStEthLevData, BaseRouter: baseRouterData, PolygonLevMaticX: polygonLevMaticXData, AffineReStaking: affineReStakingData, Polygon6xLevMaticX: Polygon6xLevMaticXData, UltraLRT: UltraLRTData, WithdrawalEscrowV2: withdrawalEscrowV2Data, } = allData;
const chainId = getChainId();
const eigenStETHStrategy = "0x7D704507b76571a51d9caE8AdDAbBFd0ba0e63d3";
const eigenDelegatorAddress = "0xA44151489861Fe9e3055d95adC98FbD462B948e7";
if (chainId === 80001 || chainId === 137) {
const alpSave = L2Vault__factory.connect(alpSaveData.address, provider);
const alpLarge = TwoAssetBasket__factory.connect(alpLargeData.address, provider);
Expand Down Expand Up @@ -115,8 +121,6 @@ export function getAllContracts(provider) {
const withdrawalEscrow = WithdrawalEscrow__factory.connect(yield ssvEthUSDEarn.debtEscrow(), provider);
const degen = Vault__factory.connect(degenData.address, provider);
const ethLeverage = chainId === 1 ? Vault__factory.connect(ethLeverageData.address, provider) : undefined;
const eigenStETHStrategy = "0x93c4b944D05dfe6df7645A86cd2206016c51564D";
const eigenDelegatorAddress = "0x39053D51B77DC0d36036Fc1fCc8Cb819df8Ef37A";
// reStaking
const affineReStaking = chainId == 1 ? AffineReStaking__factory.connect(affineReStakingData.address, provider) : undefined;
const ultraLRT = chainId == 1 ? UltraLRT__factory.connect(UltraLRTData.address, provider) : undefined;
Expand All @@ -141,6 +145,19 @@ export function getAllContracts(provider) {
eigenDelegator: new ethers.Contract(eigenDelegatorAddress, eigenDelegatorAbi, provider),
};
}
else if (chainId == 17000) {
const ultraLRT = UltraLRT__factory.connect("0x3b07A1A5de80f9b22DE0EC6C44C6E59DDc1C5f41", provider);
const withdrawalEscrowV2 = WithdrawalEscrowV2__factory.connect("0x84eF1F1A7f14A237c4b1DA8d13548123879FC3A9", provider);
return {
usdc: new ethers.Contract("0x74A4A85C611679B73F402B36c0F84A7D2CcdFDa3", erc20Abi, provider),
weth: new ethers.Contract("0x6B5817E7091BC0C747741E96820b0199388245EA", erc20Abi, provider),
router: Router__factory.connect(ethRouter.address, provider),
ultraLRT,
withdrawalEscrowV2,
eigenStETH: new ethers.Contract(eigenStETHStrategy, eigenStEthAbi, provider),
eigenDelegator: new ethers.Contract(eigenDelegatorAddress, eigenDelegatorAbi, provider),
};
}
else if (chainId == 8453 || chainId == 84531) {
const baseUsdEarn = chainId == 8453 ? VaultV2__factory.connect(baseUsdEarnData.address, provider) : undefined;
const baseLeverage = VaultV2__factory.connect(baseStEthLevData.address, provider);
Expand Down Expand Up @@ -170,6 +187,9 @@ export function getPolygonContracts() {
export function getBaseContracts() {
return CONTRACTS;
}
export function getHoleskyContract() {
return CONTRACTS;
}
export function init(signerOrAddress, biconomy, chainId = DEFAULT_RAW_CHAIN_ID) {
return __awaiter(this, void 0, void 0, function* () {
CHAIN_ID = chainId;
Expand Down
12 changes: 11 additions & 1 deletion dist/core/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function getChainIdFromRaw(chainId = DEFAULT_RAW_CHAIN_ID) {
return `0x${Number(chainId).toString(16)}`;
}
export const NETWORK_TYPE = process.env.NEXT_PUBLIC_NETWORK_TYPE === "mainnet" ? "mainnet" : "testnet";
export const ALLOWED_CHAIN_IDS = NETWORK_TYPE === "mainnet" ? [1, 137] : [5, 80001];
export const ALLOWED_CHAIN_IDS = NETWORK_TYPE === "mainnet" ? [1, 137] : [5, 80001, 17000];
export const MAX_UINT = ethers.BigNumber.from(2).pow(256).sub(1);
export const MAX_APPROVAL_AMOUNT = ethers.constants.MaxUint256;
export const WALLETCONNECT_PROJECT_ID = process.env.WALLETCONNECT_PROJECT_ID || "demo-project-id";
Expand Down Expand Up @@ -74,6 +74,16 @@ export const NETWORK_PARAMS = {
rpcUrls: ["https://rpc.ankr.com/eth_goerli"],
blockExplorerUrls: ["https://goerli.etherscan.io"],
},
17000: {
chainName: "Holesky Testnet",
nativeCurrency: {
name: "Ether",
symbol: "ETH",
decimals: 18,
},
rpcUrls: ["https://ethereum-holesky-rpc.publicnode.com"],
blockExplorerUrls: ["https://holesky.etherscan.io"],
},
137: {
chainName: `Polygon Mainnet${IS_USING_FORKED_MAINNET ? " (Forked)" : ""}`,
nativeCurrency: {
Expand Down
5 changes: 5 additions & 0 deletions dist/core/product.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { BigNumber, ethers } from "ethers";
import { GasInfo, SmallTxReceipt } from "..";
import { ERC4626Upgradeable, MockERC20, Router } from "../typechain";
import { AlpineProduct, DryRunReceipt, FullTxReceipt, TokenInfo } from "./types";
export declare function _getVaultAndAsset(product: AlpineProduct): Promise<{
vault: ERC4626Upgradeable;
asset: MockERC20;
router: Router;
}>;
export declare function buyProduct(product: AlpineProduct, amount: number, slippageBps?: number): Promise<DryRunReceipt>;
export declare function sellProduct(product: AlpineProduct, amount: number): Promise<DryRunReceipt>;
export declare function buyVault(vault: ERC4626Upgradeable, rawAssets: number, asset: MockERC20): Promise<DryRunReceipt & (SmallTxReceipt | GasInfo)>;
Expand Down
15 changes: 14 additions & 1 deletion dist/core/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { MockERC20__factory } from "../typechain";
import { _addDecimals, _removeDecimals, blockchainCall } from "./AlpineDeFiSDK";
import { getBaseContracts, getContracts, getEthContracts, getPolygonContracts, PROVIDER, SIMULATE, userAddress, } from "./cache";
import { MAX_UINT } from "./constants";
function _getVaultAndAsset(product) {
export function _getVaultAndAsset(product) {
return __awaiter(this, void 0, void 0, function* () {
const { alpSave, alpLarge, polygonDegen, polygonLeverage, polygonLevMaticX, polygon6xLevMaticX } = getPolygonContracts();
const { ethEarn, ethWethEarn, ssvEthUSDEarn, degen, ethLeverage, ultraLRT } = getEthContracts();
Expand All @@ -39,7 +39,9 @@ function _getVaultAndAsset(product) {
const vault = productToVault[product];
if (!vault)
throw new Error("Invalid product");
console.log("init");
const asset = MockERC20__factory.connect(yield vault.asset(), vault.provider);
console.log("done");
return { vault, asset, router };
});
}
Expand Down Expand Up @@ -239,6 +241,17 @@ export function getTokenInfo(product, token) {
equity: assetAmount,
};
}
else if (product === "ultraLRT") {
const { vault, asset } = yield _getVaultAndAsset(product);
const assets = yield vault.convertToAssets(yield vault.balanceOf(user));
const vaultDecimals = yield vault.decimals();
const price = yield vault.convertToAssets(ethers.BigNumber.from(10).pow(vaultDecimals));
return {
amount: _removeDecimals(assets, yield asset.decimals()),
price: _removeDecimals(price, vaultDecimals),
equity: "0",
};
}
const { alpSave, alpLarge, ethEarn, ethWethEarn, ssvEthUSDEarn, degen, polygonDegen, ethLeverage, polygonLeverage, baseUsdEarn, baseLeverage, polygonLevMaticX, polygon6xLevMaticX, affineReStaking, ultraLRT, } = getContracts();
const productToContract = {
alpSave,
Expand Down
9 changes: 9 additions & 0 deletions dist/core/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ export interface EthContracts extends BothContracts {
eigenStETH?: ethers.Contract;
eigenDelegator?: ethers.Contract;
}
export interface HoleskyContracts {
usdc: ethers.Contract;
weth: ethers.Contract;
router: Router;
ultraLRT?: UltraLRT;
withdrawalEscrowV2?: WithdrawalEscrowV2;
eigenStETH?: ethers.Contract;
eigenDelegator?: ethers.Contract;
}
export interface BaseContracts extends BothContracts {
baseUsdEarn?: VaultV2;
baseLeverage: VaultV2;
Expand Down
Loading