[SDK, REACT] port over support for BSC to monorepo (#12)

This commit is contained in:
Jonas Daniels
2022-08-29 10:00:30 +00:00
committed by GitHub
parent 39f91c7525
commit d4abb09de7
9 changed files with 143 additions and 23 deletions
+6
View File
@@ -0,0 +1,6 @@
---
"@thirdweb-dev/react": patch
"@thirdweb-dev/sdk": patch
---
Add support for Binance chains (BSC)
@@ -96,6 +96,9 @@ const chainIdToCurrencyMap: Record<
[ChainId.Polygon]: "polygon",
[ChainId.Mumbai]: "polygon",
[ChainId.BinanceSmartChainMainnet]: "binance",
[ChainId.BinanceSmartChainTestnet]: "binance",
};
/**
@@ -228,4 +228,42 @@ export const chainLogos = {
</>
),
},
binance: {
svgProps: {
viewBox: "0 0 32 32",
xmlns: "http://www.w3.org/2000/svg",
},
paths: (
<>
<polygon
fill="#F3BA2F"
points="38.171,53.203 62.759,28.616 87.36,53.216 101.667,38.909 62.759,0 23.864,38.896 "
/>
<rect
x="3.644"
y="53.188"
transform="matrix(0.7071 0.7071 -0.7071 0.7071 48.7933 8.8106)"
fill="#F3BA2F"
width="20.233"
height="20.234"
/>
<polygon
fill="#F3BA2F"
points="38.171,73.408 62.759,97.995 87.359,73.396 101.674,87.695 101.667,87.703 62.759,126.61123.863,87.716 23.843,87.696 "
/>
<rect
x="101.64"
y="53.189"
transform="matrix(-0.7071 0.7071 -0.7071 -0.7071 235.5457 29.0503)"
fill="#F3BA2F"
width="20.234"
height="20.233"
/>
<polygon
fill="#F3BA2F"
points="77.271,63.298 77.277,63.298 62.759,48.78 52.03,59.509 52.029,59.509 50.797,60.742 48.254,63.28548.254,63.285 48.234,63.305 48.254,63.326 62.759,77.831 77.277,63.313 77.284,63.305 "
/>
</>
),
},
} as const;
+26
View File
@@ -185,6 +185,32 @@ const chain: Record<string, Chain> = {
],
testnet: true,
},
binanceSmartChainMainnet: {
id: ChainId.BinanceSmartChainMainnet,
name: "Binance Smart Chain Mainnet",
nativeCurrency: NATIVE_TOKENS[ChainId.BinanceSmartChainMainnet],
rpcUrls: ["https://bsc-dataseed1.binance.org"],
blockExplorers: [
{
name: "BscScan",
url: "https://bscscan.com/",
},
],
testnet: false,
},
binanceSmartChainTestnet: {
id: ChainId.BinanceSmartChainTestnet,
name: "Binance Smart Chain Testnet",
nativeCurrency: NATIVE_TOKENS[ChainId.BinanceSmartChainTestnet],
rpcUrls: ["https://data-seed-prebsc-1-s1.binance.org:8545"],
blockExplorers: [
{
name: "BscScan",
url: "https://testnet.bscscan.com/",
},
],
testnet: true,
},
};
export const defaultSupportedChains = Object.values(chain) as Chain[];
+13 -1
View File
@@ -1,5 +1,5 @@
import { constants } from "ethers";
import { ChainId, SUPPORTED_CHAIN_ID } from "./chains";
import { constants } from "ethers";
/**
* @internal
@@ -101,6 +101,18 @@ export const CONTRACT_ADDRESSES: Record<
twRegistry: "0x7c487845f98938Bb955B1D5AD069d9a30e4131fd",
twBYOCRegistry: constants.AddressZero,
},
[ChainId.BinanceSmartChainMainnet]: {
biconomyForwarder: constants.AddressZero,
twBYOCRegistry: constants.AddressZero,
twFactory: "0xd24b3de085CFd8c54b94feAD08a7962D343E6DE0",
twRegistry: "0x7c487845f98938Bb955B1D5AD069d9a30e4131fd",
},
[ChainId.BinanceSmartChainTestnet]: {
biconomyForwarder: constants.AddressZero,
twBYOCRegistry: constants.AddressZero,
twFactory: "0xd24b3de085CFd8c54b94feAD08a7962D343E6DE0",
twRegistry: "0x7c487845f98938Bb955B1D5AD069d9a30e4131fd",
},
};
/**
+7 -1
View File
@@ -18,6 +18,8 @@ export enum ChainId {
OptimismTestnet = 69,
Arbitrum = 42161,
ArbitrumTestnet = 421611,
BinanceSmartChainMainnet = 56,
BinanceSmartChainTestnet = 97,
}
/**
@@ -36,7 +38,9 @@ export type SUPPORTED_CHAIN_ID =
| ChainId.Optimism
| ChainId.OptimismTestnet
| ChainId.Arbitrum
| ChainId.ArbitrumTestnet;
| ChainId.ArbitrumTestnet
| ChainId.BinanceSmartChainMainnet
| ChainId.BinanceSmartChainTestnet;
/**
* @public
@@ -55,4 +59,6 @@ export const SUPPORTED_CHAIN_IDS: SUPPORTED_CHAIN_ID[] = [
ChainId.OptimismTestnet,
ChainId.Arbitrum,
ChainId.ArbitrumTestnet,
ChainId.BinanceSmartChainMainnet,
ChainId.BinanceSmartChainTestnet,
];
+21 -1
View File
@@ -1,5 +1,5 @@
import { ChainId, SUPPORTED_CHAIN_ID } from "./chains";
import { NativeToken } from "../types/currency";
import { ChainId, SUPPORTED_CHAIN_ID } from "./chains";
/**
* @public
@@ -154,6 +154,26 @@ export const NATIVE_TOKENS: Record<
symbol: "WETH",
},
},
[ChainId.BinanceSmartChainMainnet]: {
name: "Binance Chain Native Token",
symbol: "BNB",
decimals: 18,
wrapped: {
address: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
name: "Wrapped Binance Chain Token",
symbol: "WBNB",
},
},
[ChainId.BinanceSmartChainTestnet]: {
name: "Binance Chain Native Token",
symbol: "TBNB",
decimals: 18,
wrapped: {
address: "0x094616F0BdFB0b526bD735Bf66Eca0Ad254ca81F",
name: "Wrapped Binance Chain Testnet Token",
symbol: "WBNB",
},
},
};
/**
+8 -1
View File
@@ -1,5 +1,6 @@
import { ethers, providers } from "ethers";
import { SignerOrProvider } from "../core/types";
import { ethers, providers } from "ethers";
/**
* @internal
*/
@@ -45,6 +46,8 @@ export type ChainOrRpc =
| "optimism-testnet"
| "arbitrum"
| "arbitrum-testnet"
| "binance"
| "binance-testnet"
// ideally we could use `https://${string}` notation here, but doing that causes anything that is a generic string to throw a type error => not worth the hassle for now
| (string & {});
@@ -97,6 +100,10 @@ export function getProviderForNetwork(network: ChainOrRpc | SignerOrProvider) {
case "avalanche-testnet":
case "avalanche-fuji":
return "https://api.avax-test.network/ext/bc/C/rpc";
case "binance":
return "https://bsc-dataseed1.binance.org";
case "binance-testnet":
return "https://data-seed-prebsc-1-s1.binance.org:8545";
default:
if (network.startsWith("http") || network.startsWith("ws")) {
return network;
+21 -19
View File
@@ -1,4 +1,10 @@
import { ContractInterface, ethers, Signer } from "ethers";
import { fetchCurrencyValue } from "../common/currency";
import {
ChainOrRpc,
getProviderForNetwork,
getReadOnlyProvider,
NATIVE_TOKEN_ADDRESS,
} from "../constants";
import {
Edition,
EditionDrop,
@@ -13,8 +19,15 @@ import {
Token,
Vote,
} from "../contracts";
import { Multiwrap } from "../contracts/multiwrap";
import { SmartContract } from "../contracts/smart-contract";
import { TokenDrop } from "../contracts/token-drop";
import { SDKOptions } from "../schema/sdk-options";
import { IpfsStorage, RemoteStorage, IStorage } from "@thirdweb-dev/storage";
import { CurrencyValue } from "../types/index";
import { WalletAuthenticator } from "./auth/wallet-authenticator";
import { ContractMetadata } from "./classes";
import { ContractDeployer } from "./classes/contract-deployer";
import { ContractPublisher } from "./classes/contract-publisher";
import { RPCConnectionHandler } from "./classes/rpc-connection-handler";
import type {
ContractForContractType,
@@ -23,24 +36,11 @@ import type {
SignerOrProvider,
ValidContractInstance,
} from "./types";
import { IThirdwebContract__factory } from "@thirdweb-dev/contracts-js";
import { ContractDeployer } from "./classes/contract-deployer";
import { SmartContract } from "../contracts/smart-contract";
import invariant from "tiny-invariant";
import { TokenDrop } from "../contracts/token-drop";
import { ContractPublisher } from "./classes/contract-publisher";
import { ContractMetadata } from "./classes";
import {
ChainOrRpc,
getProviderForNetwork,
getReadOnlyProvider,
NATIVE_TOKEN_ADDRESS,
} from "../constants";
import { UserWallet } from "./wallet/UserWallet";
import { Multiwrap } from "../contracts/multiwrap";
import { WalletAuthenticator } from "./auth/wallet-authenticator";
import { CurrencyValue } from "../types/index";
import { fetchCurrencyValue } from "../common/currency";
import { IThirdwebContract__factory } from "@thirdweb-dev/contracts-js";
import { IpfsStorage, RemoteStorage, IStorage } from "@thirdweb-dev/storage";
import { ContractInterface, ethers, Signer } from "ethers";
import invariant from "tiny-invariant";
/**
* The main entry point for the thirdweb SDK
@@ -63,6 +63,7 @@ export class ThirdwebSDK extends RPCConnectionHandler {
* @param network - the network (chain) to connect to (e.g. "mainnet", "rinkeby", "polygon", "mumbai"...) or a fully formed RPC url
* @param options - the SDK options to use
* @returns an instance of the SDK
* @param storage - optional storage implementation to use
*
* @beta
*/
@@ -92,6 +93,7 @@ export class ThirdwebSDK extends RPCConnectionHandler {
* @param privateKey - the private key - **DO NOT EXPOSE THIS TO THE PUBLIC**
* @param network - the network (chain) to connect to (e.g. "mainnet", "rinkeby", "polygon", "mumbai"...) or a fully formed RPC url
* @param options - the SDK options to use
* @param storage - optional storage implementation to use
* @returns an instance of the SDK
*
* @beta