Skip to content

Commit

Permalink
Add Mainnet Address; Add GetAccountFromProvider for Superfluid
Browse files Browse the repository at this point in the history
  • Loading branch information
MHHukiewitz committed Jan 23, 2024
1 parent 8ada66e commit aa0dc52
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/accounts/superfluid.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Framework, SuperToken } from "@superfluid-finance/sdk-core";
import { AvalancheAccount } from "./avalanche";
import { ChainData, decToHex, JsonRPCWallet, RpcId } from "./providers/JsonRPCWallet";
import { BigNumber, ethers } from "ethers";
import { ALEPH_SUPERFLUID_FUJI_TESTNET } from "../global";
import { ChainData, ChangeRpcParam, decToHex, JsonRPCWallet, RpcId } from "./providers/JsonRPCWallet";
import { BigNumber, ethers, providers } from "ethers";
import { ALEPH_SUPERFLUID_FUJI_TESTNET, ALEPH_SUPERFLUID_MAINNET } from "../global";
import { Decimal } from "decimal.js";

/**
Expand All @@ -23,10 +23,6 @@ export class SuperfluidAccount extends AvalancheAccount {

public async init(): Promise<void> {
if (!this.wallet) throw Error("PublicKey Error: No providers are set up");
if (!(this.wallet instanceof JsonRPCWallet)) {
throw new Error("SuperfluidAccount must be initialized with a JsonRpcProvider");
}
await this.changeNetwork(RpcId.AVAX_TESTNET);
await this.wallet.connect();
if (!this.framework) {
this.framework = await Framework.create({
Expand All @@ -37,9 +33,11 @@ export class SuperfluidAccount extends AvalancheAccount {
if (!this.alephx) {
if (ChainData[RpcId.AVAX_TESTNET].chainId === decToHex(await this.getChainId())) {
this.alephx = await this.framework.loadSuperToken(ALEPH_SUPERFLUID_FUJI_TESTNET);
} else {
throw new Error("Only Fuji Testnet is supported for now");
}
if (ChainData[RpcId.AVAX].chainId === decToHex(await this.getChainId())) {
this.alephx = await this.framework.loadSuperToken(ALEPH_SUPERFLUID_MAINNET);
}
throw new Error(`ChainID ${await this.getChainId()} not supported`);
}
}

Expand Down Expand Up @@ -97,6 +95,10 @@ export class SuperfluidAccount extends AvalancheAccount {
return this.flowRateToAlephPerHour(flow.flowRate);
}
}

/**
* Get the net ALEPHx flow rate of the account in ALEPHx per hour.
*/
public async getNetALEPHxFlow(): Promise<Decimal> {
if (!this.wallet) throw Error("PublicKey Error: No providers are set up");
if (!this.alephx) throw new Error("SuperfluidAccount not initialized");
Expand Down Expand Up @@ -199,3 +201,16 @@ export function createFromAvalancheAccount(account: AvalancheAccount, rpc?: stri
const provider = new JsonRPCWallet(rpcProvider);
return new SuperfluidAccount(provider, account.address, account.publicKey);
}

export async function GetAccountFromProvider(
provider: providers.ExternalProvider,
requestedRpc: ChangeRpcParam = RpcId.AVAX,
): Promise<SuperfluidAccount> {
const web3Provider = new providers.Web3Provider(provider);
const wallet = new JsonRPCWallet(web3Provider);
if (!wallet.address) throw Error("PublicKey Error: No providers are set up");
const account = new SuperfluidAccount(wallet, wallet.address);
await account.changeNetwork(requestedRpc);
await account.init();
return account;
}
1 change: 1 addition & 0 deletions src/global.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const DEFAULT_API_V2 = "https://api2.aleph.im";
export const DEFAULT_API_WS_V2 = "ws://api2.aleph.im";
export const ALEPH_SUPERFLUID_FUJI_TESTNET = "0x1290248E01ED2F9f863A9752A8aAD396ef3a1B00";
export const ALEPH_SUPERFLUID_MAINNET = "0xc0Fbc4967259786C743361a5885ef49380473dCF";

0 comments on commit aa0dc52

Please sign in to comment.