Skip to content

Commit

Permalink
Changes to support leaderboard pipelines (#18)
Browse files Browse the repository at this point in the history
* Add args parsers

* v1.0.2

* v1.0.3

* v1.0.4

* v1.0.5

* v1.0.6

* v1.0.1

* Add Torus support

* Changes for leaderboard data pipelines

* Comments
  • Loading branch information
ChewingGlass committed Aug 17, 2021
1 parent c58b441 commit db93582
Show file tree
Hide file tree
Showing 36 changed files with 367 additions and 93 deletions.
2 changes: 1 addition & 1 deletion js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
```bash
cp -r /path/to/metaplex/common packages/oyster-common
npx lerna bootstrap
npx lerna exec --parallel yarn run watch --scope wumbo-common --scope spl-token-bonding --scope @oyster/common --scope spl-wumbo --scope wumbo-extension
npx lerna exec --parallel yarn run watch --scope wumbo-common --scope @wum.bo/spl-token-bonding --scope @oyster/common --scope @wum.bo/spl-wumbo --scope wumbo-extension
```

### Starting the site
Expand Down
2 changes: 1 addition & 1 deletion js/packages/common/src/Avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { Spinner, useTokenMetadata } from ".";
import { TokenBondingV0 } from "../../spl-token-bonding/dist/lib";
import { TokenBondingV0 } from "@wum.bo/spl-token-bonding/dist/lib";
import { classNames } from "./utils/utils";

/*
Expand Down
2 changes: 1 addition & 1 deletion js/packages/common/src/Leaderboard/TokenLeaderboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async function getAllTokenAccounts(
],
})
)
.map(({ account, pubkey }) => TokenAccountParser(pubkey, account).info)
.map(({ account, pubkey }) => TokenAccountParser(pubkey, account)!.info)
.sort((a, b) => b.amount.toNumber() - a.amount.toNumber())
.map((account, index) => ({
rank: index + 1,
Expand Down
4 changes: 2 additions & 2 deletions js/packages/common/src/Pages/Claim.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from "react";
import { useHistory } from "react-router-dom";
import { CreateSocialTokenResult, TokenRef } from "spl-wumbo";
import { TokenBondingV0 } from "spl-token-bonding";
import { CreateSocialTokenResult, TokenRef } from "@wum.bo/spl-wumbo";
import { TokenBondingV0 } from "@wum.bo/spl-token-bonding";
import { useWallet } from "../utils/wallet";
import { useClaim, useCreateCoin } from "../utils/claim";
import { useSolOwnedAmount, useRentExemptAmount } from "../utils/pricing";
Expand Down
2 changes: 1 addition & 1 deletion js/packages/common/src/Pages/EditProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useEffect, useState } from "react";
import { PublicKey } from "@solana/web3.js";
import { useParams } from "react-router-dom";
import { SubmitHandler, useForm } from "react-hook-form";
import { TokenBondingV0 } from "spl-token-bonding";
import { TokenBondingV0 } from "@wum.bo/spl-token-bonding";
import { useReverseTwitter } from "../utils/twitter";
import { useClaimedTokenRef } from "../utils/tokenRef";
import { SetMetadataArgs, useSetMetadata, useTokenMetadata } from "../utils/metaplex";
Expand Down
2 changes: 1 addition & 1 deletion js/packages/common/src/Pages/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { useTokenRefFromBonding } from '../utils/tokenRef';
import { Spinner } from '../Spinner';
import { useAccount } from '../utils/account';
import { TokenBondingV0 } from "spl-token-bonding";
import { TokenBondingV0 } from "@wum.bo/spl-token-bonding";
import { PublicKey } from '@solana/web3.js';
import { supplyAsNum, useAssociatedAccount, useBondingPricing, useFiatPrice, useMint, useOwnedAmount, useQuery, useReverseTwitter, useTokenMetadata } from '../utils';
import { StatCard } from "../StatCard";
Expand Down
2 changes: 1 addition & 1 deletion js/packages/common/src/TokenPill.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Fragment, useState } from "react";
import { ChevronRightIcon } from "@heroicons/react/solid";
import { TokenBondingV0 } from "spl-token-bonding";
import { TokenBondingV0 } from "@wum.bo/spl-token-bonding";
import { useBondingPricing, useFiatPrice, useOwnedAmount } from "./utils/pricing";
import { useTokenMetadata } from "./utils/metaplex/hooks";
import { MetadataAvatar } from "./Avatar";
Expand Down
6 changes: 3 additions & 3 deletions js/packages/common/src/constants/globals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export const TWITTER_REGISTRAR_SERVER_URL =
// export const SOLANA_API_URL = "https://api.mainnet-beta.solana.com"
export const WUM_REWARDS_PERCENTAGE = 1000;
export const WUM_BONDING = new PublicKey(
"T8d8nTqeybQBcJgmFVEZHJebNuNEG2BvkZEQS2RuAhQ"
"BZN5FKwDAJ354iwfa89ecxxFFkufs8UtEpiNMmz9kE8g"
);
export const WUM_TOKEN = new PublicKey(
"3y8K5ZAqJYgHbHeQr9uownFTtSLSG6MraVq38cobKRgb"
"EN75YBRFCoSezbkvRfbEqvsRU4mgXaDQjG7fkAtYjN9z"
);
export const WUMBO_INSTANCE_KEY: PublicKey = new PublicKey(
"VyCsQR6LmmW4TMazay9CS2FEJpRk92yDavqp3Saw9Pc"
"JCQksCaGsRuQiog2sYddYb2xwogsnk64eDbZHCNFKsxP"
);
export const WUMBO_PROGRAM_ID: PublicKey = new PublicKey(
"AiYPQudWgXerJ1BdKfH5HkEamnPXSHAfPK2ThhKFkkDw"
Expand Down
11 changes: 9 additions & 2 deletions js/packages/common/src/constants/walletProviders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ import {
getLedgerWallet,
getPhantomWallet,
getSolflareWallet,
getTorusWallet
} from "@solana/wallet-adapter-wallets";

export const INJECTED_PROVIDERS: Wallet[] = [
getPhantomWallet(),
getLedgerWallet(),
getSolletWallet(),
getSolflareWallet(),
getSolflareWallet()
];

export const WALLET_PROVIDERS: Wallet[] = [...INJECTED_PROVIDERS];
export const WALLET_PROVIDERS: Wallet[] = [...INJECTED_PROVIDERS, getTorusWallet({
options: {
clientId: "BHgxWcEBp7kICzfoIUlL9kCmope2NRhrDz7d8ugBucqQqBel1Q7yDvkPfLrgZh140oLxyN0MgpmziL7UG7jZuWk",
network: "testnet",
uxMode: "popup"
}
})];
2 changes: 1 addition & 1 deletion js/packages/common/src/constants/wumbo.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Wumbo } from "spl-wumbo";
import { Wumbo } from "@wum.bo/spl-wumbo";
import { getTld } from "../utils";
import { WUMBO_PROGRAM_ID, WUMBO_INSTANCE_KEY } from "./globals"

Expand Down
4 changes: 2 additions & 2 deletions js/packages/common/src/utils/claim.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from "react";
import { CreateSocialTokenResult, TokenRef, Wumbo, WumboInstance } from "spl-wumbo";
import { TokenBondingV0 } from "spl-token-bonding";
import { CreateSocialTokenResult, TokenRef, Wumbo, WumboInstance } from "@wum.bo/spl-wumbo";
import { TokenBondingV0 } from "@wum.bo/spl-token-bonding";
import { useAsyncCallback } from "react-async-hook";
import {
SPL_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID,
Expand Down
4 changes: 2 additions & 2 deletions js/packages/common/src/utils/metaplex/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import {
} from "@solana/web3.js";
import { getFilesWithMetadata, getImage, getMetadataKey } from "./utils";
import { useWallet } from "../wallet";
import { TokenRef } from "spl-wumbo";
import { TokenRef } from "@wum.bo/spl-wumbo";
import { useMint } from "../mintState";
import { TokenBondingV0 } from "spl-token-bonding";
import { TokenBondingV0 } from "@wum.bo/spl-token-bonding";
import { useState } from "react";
import {
createMetadataWithArweave,
Expand Down
2 changes: 1 addition & 1 deletion js/packages/common/src/utils/mintState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AccountInfo, PublicKey } from "@solana/web3.js";
import { useEffect, useState } from "react";
import { MintInfo } from "@solana/spl-token";
import { useConnection } from "@oyster/common";
import { Mint } from "spl-wumbo";
import { Mint } from "@wum.bo/spl-wumbo";
import { SOL_TOKEN } from "../constants/globals";
import { Numberu64 } from "@bonfida/spl-name-service";

Expand Down
2 changes: 1 addition & 1 deletion js/packages/common/src/utils/pricing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
WUM_TOKEN,
} from "../constants/globals";
import { Order } from "@project-serum/serum/lib/market";
import { LogCurveV0, TokenBondingV0 } from "spl-token-bonding";
import { LogCurveV0, TokenBondingV0 } from "@wum.bo/spl-token-bonding";
import { MintInfo, u64 } from "@solana/spl-token";
// @ts-ignore
import { gsl_sf_lambert_W0 } from "./lambertw";
Expand Down
4 changes: 2 additions & 2 deletions js/packages/common/src/utils/tokenRef.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { useEffect, useMemo, useState } from "react";
import { Connection, PublicKey } from "@solana/web3.js";
import { useConnection } from "@oyster/common";
import { useAccount, UseAccountState } from "./account";
import { TokenRef, Wumbo } from "spl-wumbo";
import { TokenRef, Wumbo } from "@wum.bo/spl-wumbo";
import { useAsync, useAsyncCallback } from "react-async-hook";
import { TokenBondingV0 } from "spl-token-bonding";
import { TokenBondingV0 } from "@wum.bo/spl-token-bonding";
import { TokenMetadata, useTokenMetadata } from "./metaplex/hooks";
import { getWumbo } from "../constants/wumbo";

Expand Down
2 changes: 1 addition & 1 deletion js/packages/common/src/utils/walletState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function useAssociatedAccount(
const { info: associatedAccount, loading } = useAccount(
associatedTokenAddress,
(pubkey: PublicKey, acct: AccountInfo<Buffer>) => {
return TokenAccountParser(pubkey, acct).info;
return TokenAccountParser(pubkey, acct)!.info;
}
);

Expand Down
4 changes: 2 additions & 2 deletions js/packages/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"react-resize-aware": "^3.1.0",
"react-router-dom": "^5.2.0",
"serialize-error": "8.1.0",
"spl-token-bonding": "^1.0.0",
"spl-wumbo": "^1.0.0",
"@wum.bo/spl-token-bonding": "^1.0.0",
"@wum.bo/spl-wumbo": "^1.0.0",
"superstruct": "^0.15.2",
"url-template": "^2.0.8",
"wumbo-common": "^1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion js/packages/extension/src/components/MainButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { FC } from "react";
import { Link } from "react-router-dom";
import { WumboInstance } from "spl-wumbo";
import { WumboInstance } from "@wum.bo/spl-wumbo";
import { useUserInfo } from "@/utils/userState";
import { useAccount } from "wumbo-common";
import { WUMBO_INSTANCE_KEY, Button, IButtonProps, Spinner, ISpinnerProps } from "wumbo-common";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from "react";
import { useHistory } from "react-router-dom";
import { useConnection } from "@oyster/common";
import { WumboInstance, Wumbo } from "spl-wumbo";
import { WumboInstance, Wumbo } from "@wum.bo/spl-wumbo";
import { claimPath, routes } from "@/constants/routes";
import {
WUMBO_INSTANCE_KEY,
Expand Down
2 changes: 1 addition & 1 deletion js/packages/extension/src/components/trade/Trade.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { TokenForm, FormValues } from "./TokenForm";
import { CashIcon } from "@heroicons/react/solid";
import Logo from "../../../public/assets/img/logo.svg";
import { PublicKey } from "@solana/web3.js";
import { TokenBondingV0 } from "spl-token-bonding";
import { TokenBondingV0 } from "@wum.bo/spl-token-bonding";
import SolLogo from "../../../public/assets/img/sol.svg";
import { WumboDrawer } from "../WumboDrawer";

Expand Down
2 changes: 1 addition & 1 deletion js/packages/extension/src/utils/action.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useCallback } from "react";
import { useConnection } from "@oyster/common";
import { buyBondingInstructions, sellBondingInstructions } from "spl-token-bonding";
import { buyBondingInstructions, sellBondingInstructions } from "@wum.bo/spl-token-bonding";
import { PublicKey, Transaction, sendAndConfirmRawTransaction } from "@solana/web3.js";
import { WalletNotConnectedError } from "@solana/wallet-adapter-base";
import {
Expand Down
2 changes: 1 addition & 1 deletion js/packages/extension/src/utils/auth.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Connection, PublicKey } from "@solana/web3.js";
import { AccountInfo as TokenAccountInfo, Token } from "@solana/spl-token";
import { WumboInstance } from "spl-wumbo";
import { WumboInstance } from "@wum.bo/spl-wumbo";
import {
WUMBO_INSTANCE_KEY,
SPL_ASSOCIATED_TOKEN_ACCOUNT_PROGRAM_ID,
Expand Down
4 changes: 2 additions & 2 deletions js/packages/extension/src/utils/userState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import {
useTwitterTokenRef,
} from "wumbo-common";
import { AccountInfo, PublicKey } from "@solana/web3.js";
import { TokenRef } from "spl-wumbo";
import { TokenRef } from "@wum.bo/spl-wumbo";
import { MintInfo } from "@solana/spl-token";
import { LogCurveV0, TokenBondingV0 } from "spl-token-bonding";
import { LogCurveV0, TokenBondingV0 } from "@wum.bo/spl-token-bonding";

interface UserState {
tokenRef?: TokenRef;
Expand Down
28 changes: 20 additions & 8 deletions js/packages/extension/src/utils/wallet.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, { FC, ReactNode, useCallback, useEffect, useMemo, useState } from "react";
import {
WalletAdapter,
WalletError,
WalletNotConnectedError,
WalletNotReadyError,
} from "@solana/wallet-adapter-base";
import { WalletContext, WALLET_PROVIDERS, useLocalStorage, Notification } from "wumbo-common";
import { WalletContext, WALLET_PROVIDERS, useLocalStorage, Notification, INJECTED_PROVIDERS } from "wumbo-common";
import { PublicKey, Transaction } from "@solana/web3.js";
import { InjectedWalletAdapter } from "./wallets/injectedAdapter";
import { Wallet, WalletName } from "@solana/wallet-adapter-wallets";
Expand All @@ -20,7 +21,7 @@ export const WalletProvider: FC<IWalletProviderProps> = ({ children }) => {
const [selectCount, setSelectCount] = useState<number>(0);
const [name, setName] = useState<WalletName | null>(null);
const [wallet, setWallet] = useState<Wallet>();
const [adapter, setAdapter] = useState<InjectedWalletAdapter>();
const [adapter, setAdapter] = useState<WalletAdapter>();
const [ready, setReady] = useState(false);
const [connecting, setConnecting] = useState(false);
const [disconnecting, setDisconnecting] = useState(false);
Expand All @@ -47,6 +48,14 @@ export const WalletProvider: FC<IWalletProviderProps> = ({ children }) => {
[toast]
);

const injectedWalletsByName = useMemo(
() =>
INJECTED_PROVIDERS.reduce((walletsByName, wallet) => {
walletsByName[wallet.name] = wallet;
return walletsByName;
}, {} as { [name in WalletName]: Wallet }),
[INJECTED_PROVIDERS]
);
const walletsByName = useMemo(
() =>
WALLET_PROVIDERS.reduce((walletsByName, wallet) => {
Expand Down Expand Up @@ -81,7 +90,9 @@ export const WalletProvider: FC<IWalletProviderProps> = ({ children }) => {

setConnected(true);
setAutoApprove(adapter.autoApprove);
setPublicKey(adapter.publicKey?.toBase58() || null);
const newPublicKey = adapter.publicKey?.toBase58()
console.log(`Connected to wallet ${newPublicKey}`);
setPublicKey(newPublicKey || null);
}, [adapter, setConnected, setAutoApprove, setPublicKey]);

const onDisconnect = useCallback(() => reset(), [reset]);
Expand Down Expand Up @@ -173,14 +184,15 @@ export const WalletProvider: FC<IWalletProviderProps> = ({ children }) => {
// Reset state and set the wallet, adapter, and ready state when the name changes
useEffect(() => {
reset();
const wallet = name ? walletsByName[name] : undefined;
const adapter = wallet ? new InjectedWalletAdapter({ name }) : undefined;
const injectedWallet = name ? injectedWalletsByName[name] : undefined;
const normalWallet = name ? walletsByName[name] : undefined;
const adapter = injectedWallet ? new InjectedWalletAdapter({ name }) : normalWallet?.adapter();
const asyncReady = async () => {
const ready = adapter ? await adapter.readyAsync : false;
const ready = adapter && adapter instanceof InjectedWalletAdapter ? await adapter.readyAsync : !!adapter?.ready;
setReady(ready);
};

setWallet(wallet);
setWallet(injectedWallet || normalWallet);
setAdapter(adapter);
asyncReady();
}, [reset, name, walletsByName, setWallet, setAdapter, setReady]);
Expand All @@ -205,7 +217,7 @@ export const WalletProvider: FC<IWalletProviderProps> = ({ children }) => {
useEffect(() => {
(async function () {
if (adapter) {
const ready = await adapter?.readyAsync;
const ready = adapter instanceof InjectedWalletAdapter ? await adapter?.readyAsync : !!adapter?.ready;

if (!ready && wallet?.name === name) {
window.open(wallet!.url, "_blank");
Expand Down
2 changes: 1 addition & 1 deletion js/packages/extension/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"include": [
"src",
"../common/src/utils/wallet.tsx",
"../spl-wumbo/src/bindings.ts"
"../@wum.bo/spl-wumbo/src/bindings.ts"
],
"exclude": ["dist", "node_modules"]
}
11 changes: 7 additions & 4 deletions js/packages/spl-token-bonding/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
{
"name": "spl-token-bonding",
"version": "1.0.0",
"description": "Interface to the spl-token-bonding smart contract",
"name": "@wum.bo/spl-token-bonding",
"version": "1.0.1",
"description": "Interface to the @wum.bo/spl-token-bonding smart contract",
"repository": {
"type": "git",
"url": "https://github.com/ChewingGlassFund/wumbo"
},
"main": "dist/lib/index.js",
"types": "dist/lib/index.d.ts",
"exports": {
".": "./dist/lib"
".": "./dist/lib/index.js"
},
"files": [
"dist/lib/**/*"
],
"scripts": {
"build": "tsc --project tsconfig.json",
"watch": "tsc --watch --project tsconfig.json",
Expand Down
Loading

0 comments on commit db93582

Please sign in to comment.