Compare commits

..
Author SHA1 Message Date
github-actions[bot]andgithub-actions[bot] 836484ba98 Version Packages (#504)
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-01-23 13:59:28 -08:00
Nacho Iacovino 5047686f2a Fix ConnectWallet network selector (#507) 2023-01-23 20:53:44 +00:00
YashandJoaquim Verges 7cab8d1679 [SDK] Plugin pattern: get composite ABI (#475)
Co-authored-by: Joaquim Verges <[email protected]>
2023-01-20 17:52:30 -08:00
18 changed files with 186 additions and 34 deletions
+2
View File
@@ -1,5 +1,7 @@
# @thirdweb-dev/auth
## 2.0.41
## 2.0.40
## 2.0.39
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/auth",
"version": "2.0.40",
"version": "2.0.41",
"exports": {
"./next": {
"module": "./next/dist/thirdweb-dev-auth-next.esm.js",
+7
View File
@@ -1,5 +1,12 @@
# thirdweb
## 0.9.10
### Patch Changes
- Updated dependencies [[`7cab8d1`](https://github.com/thirdweb-dev/js/commit/7cab8d1679f8d007091aa03adb83add3822a504a)]:
- @thirdweb-dev/sdk@3.6.11
## 0.9.9
### Patch Changes
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "thirdweb",
"main": "dist/cli/index.js",
"version": "0.9.9",
"version": "0.9.10",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/cli",
"author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0",
+6
View File
@@ -1,5 +1,11 @@
# @thirdweb-dev/react
## 3.6.11
### Patch Changes
- [#507](https://github.com/thirdweb-dev/js/pull/507) [`5047686`](https://github.com/thirdweb-dev/js/commit/5047686f2afbca4fa32b1bbb6bcf4419bd17cf8d) Thanks [@nachoiacovino](https://github.com/nachoiacovino)! - Fix ConnectWallet network selector showing all options three times
## 3.6.10
## 3.6.9
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/react",
"version": "3.6.10",
"version": "3.6.11",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/react",
"author": "thirdweb eng <[email protected]>",
"license": "Apache-2.0",
@@ -11,23 +11,17 @@ export const SupportedNetworkSelect: React.FC<SupportedNetworkSelectProps> = ({
disabledChainIds,
...selectProps
}) => {
const deprecatedNetworks = useMemo(() => {
return SUPPORTED_CHAIN_IDS.map((supportedChain) => {
const { mainnets, testnets } = useMemo(() => {
const networks = SUPPORTED_CHAIN_IDS.map((supportedChain) => {
return getChainFromChainId(supportedChain);
});
return {
mainnets: networks.filter((n) => !n.testnet),
testnets: networks.filter((n) => n.testnet),
};
}, []);
const testnets = useMemo(() => {
return SUPPORTED_CHAIN_IDS.map((supportedChain) => {
return getChainFromChainId(supportedChain);
});
}, []);
const mainnets = useMemo(() => {
return SUPPORTED_CHAIN_IDS.map((supportedChain) => {
return getChainFromChainId(supportedChain);
});
}, []);
return (
<Select {...selectProps}>
<option disabled value={-1}>
@@ -55,17 +49,6 @@ export const SupportedNetworkSelect: React.FC<SupportedNetworkSelectProps> = ({
</option>
))}
</optgroup>
<optgroup label="Deprecated">
{deprecatedNetworks.map((tn) => (
<option
key={tn.id}
value={tn.id}
disabled={disabledChainIds?.includes(tn.id)}
>
{tn.name} ({tn.nativeCurrency?.symbol})
</option>
))}
</optgroup>
</Select>
);
};
+6
View File
@@ -1,5 +1,11 @@
# @thirdweb-dev/sdk
## 3.6.11
### Patch Changes
- [#475](https://github.com/thirdweb-dev/js/pull/475) [`7cab8d1`](https://github.com/thirdweb-dev/js/commit/7cab8d1679f8d007091aa03adb83add3822a504a) Thanks [@kumaryash90](https://github.com/kumaryash90)! - Support for Plugin Pattern based contracts
## 3.6.10
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/sdk",
"version": "3.6.10",
"version": "3.6.11",
"description": "The main thirdweb SDK.",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/sdk",
"license": "Apache-2.0",
+89
View File
@@ -0,0 +1,89 @@
import { ContractWrapper } from "../core/classes/contract-wrapper";
import { Abi, AbiSchema, SDKOptions } from "../schema";
import { isFeatureEnabled } from "./feature-detection";
import { fetchContractMetadataFromAddress } from "./metadata-resolver";
import { unique } from "./utils";
import type { IRouter } from "@thirdweb-dev/contracts-js";
import RouterABI from "@thirdweb-dev/contracts-js/dist/abis/Router.json";
import { ThirdwebStorage } from "@thirdweb-dev/storage";
import { ethers } from "ethers";
/**
* @internal
*/
export async function getCompositePluginABI(
address: string,
abi: Abi,
provider: ethers.providers.Provider,
options: SDKOptions,
storage: ThirdwebStorage,
): Promise<Abi> {
let pluginABIs: Abi[] = [];
try {
// check if contract is plugin-pattern
const isPluginRouter: boolean = isFeatureEnabled(
AbiSchema.parse(abi),
"PluginRouter",
);
if (isPluginRouter) {
const contract = new ContractWrapper<IRouter>(
provider,
address,
RouterABI,
options,
);
const pluginMap = await contract.readContract.getAllPlugins();
// get extension addresses
const allPlugins = pluginMap.map((item) => item.pluginAddress);
const plugins = Array.from(new Set(allPlugins));
// get ABIs of extension contracts
pluginABIs = await getPluginABI(plugins, provider, storage);
}
} catch (err) {}
return pluginABIs.length > 0 ? joinABIs([abi, ...pluginABIs]) : abi;
}
/**
* @internal
*/
async function getPluginABI(
addresses: string[],
provider: ethers.providers.Provider,
storage: ThirdwebStorage,
): Promise<Abi[]> {
return (
await Promise.all(
addresses.map((address) =>
fetchContractMetadataFromAddress(address, provider, storage).catch(
(err) => {
console.error(`Failed to fetch plug-in for ${address}`, err);
return { abi: [] };
},
),
),
)
).map((metadata) => metadata.abi);
}
/**
* @internal
*/
export function joinABIs(abis: Abi[]): Abi {
const parsedABIs = abis.map((abi) => AbiSchema.parse(abi)).flat();
const filteredABIs = unique(parsedABIs, (a, b): boolean => {
return (
a.name === b.name &&
a.type === b.type &&
a.inputs.length === b.inputs.length
);
});
return AbiSchema.parse(filteredABIs);
}
+21
View File
@@ -8,3 +8,24 @@ export const isBrowser = () => typeof window !== "undefined";
* @internal
*/
export const isNode = () => !isBrowser();
/**
* @internal
*/
export function unique<T>(a: T[], fn: (a: T, b: T) => boolean): T[] {
if (a.length === 0 || a.length === 1) {
return a;
}
if (!fn) {
return a;
}
for (let i = 0; i < a.length; i++) {
for (let j = i + 1; j < a.length; j++) {
if (fn(a[i], a[j])) {
a.splice(j, 1);
}
}
}
return a;
}
@@ -54,6 +54,7 @@ import {
FEATURE_APPURI,
FEATURE_GASLESS,
FEATURE_PACK_VRF,
FEATURE_PLUGIN_ROUTER,
} from "./thirdweb-features";
/**
@@ -108,7 +109,8 @@ export type Feature =
| typeof FEATURE_APPURI
| typeof FEATURE_OWNER
| typeof FEATURE_GASLESS
| typeof FEATURE_PACK_VRF;
| typeof FEATURE_PACK_VRF
| typeof FEATURE_PLUGIN_ROUTER;
/**
* @internal
@@ -138,4 +140,5 @@ export const SUPPORTED_FEATURES: Record<string, Feature> = {
[FEATURE_OWNER.name]: FEATURE_OWNER,
[FEATURE_GASLESS.name]: FEATURE_GASLESS,
[FEATURE_PACK_VRF.name]: FEATURE_PACK_VRF,
[FEATURE_PLUGIN_ROUTER.name]: FEATURE_PLUGIN_ROUTER,
};
@@ -6,6 +6,7 @@ import IPermissionsAbi from "@thirdweb-dev/contracts-js/dist/abis/IPermissions.j
import IPermissionsEnumerableAbi from "@thirdweb-dev/contracts-js/dist/abis/IPermissionsEnumerable.json";
import IThirdwebPlatformFeeAbi from "@thirdweb-dev/contracts-js/dist/abis/IPlatformFee.json";
import IThirdwebPrimarySaleAbi from "@thirdweb-dev/contracts-js/dist/abis/IPrimarySale.json";
import IRouterAbi from "@thirdweb-dev/contracts-js/dist/abis/IRouter.json";
import IThirdwebRoyaltyAbi from "@thirdweb-dev/contracts-js/dist/abis/IRoyalty.json";
import IOwnableAbi from "@thirdweb-dev/contracts-js/dist/abis/Ownable.json";
@@ -121,3 +122,14 @@ export const FEATURE_PACK_VRF = {
abis: [IPackVRFAbi],
features: {},
} as const;
export const FEATURE_PLUGIN_ROUTER = {
name: "PluginRouter",
namespace: "plugin.router",
docLinks: {
sdk: "sdk.pluginrouter",
contracts: "IRouter",
},
abis: [IRouterAbi],
features: {},
} as const;
+11 -1
View File
@@ -1,4 +1,5 @@
import { fetchCurrencyValue } from "../common/currency";
import { getCompositePluginABI } from "../common/plugin";
import {
ChainOrRpc,
getProviderForNetwork,
@@ -10,6 +11,7 @@ import {
PREBUILT_CONTRACTS_MAP,
} from "../contracts";
import { SmartContract } from "../contracts/smart-contract";
import { AbiSchema } from "../schema";
import { SDKOptions } from "../schema/sdk-options";
import { CurrencyValue } from "../types/index";
import type { AbstractWallet } from "../wallets";
@@ -617,11 +619,19 @@ export class ThirdwebSDK extends RPCConnectionHandler {
this.getSignerOrProvider(),
this.options,
);
const parsedABI = typeof abi === "string" ? JSON.parse(abi) : abi;
// TODO we still might want to lazy-fy this
const contract = new SmartContract(
this.getSignerOrProvider(),
address,
abi,
await getCompositePluginABI(
address,
AbiSchema.parse(parsedABI),
provider,
this.options,
this.storage,
),
this.storageHandler,
this.options,
(await provider.getNetwork()).chainId,
-2
View File
@@ -53,8 +53,6 @@ import {
PluginMap,
PluginMap__factory,
VoteERC20__factory,
TWProxy__factory,
TWProxy,
} from "@thirdweb-dev/contracts-js";
import { ThirdwebStorage } from "@thirdweb-dev/storage";
import { ethers } from "ethers";
+9 -1
View File
@@ -1,8 +1,10 @@
import { getMultichainRegistryAddress } from "../../src/evm";
import { getMultichainRegistryAddress, ThirdwebSDK } from "../../src/evm";
import { joinABIs } from "../../src/evm/common/plugin";
import { MultichainRegistry } from "../../src/evm/core/classes/multichain-registry";
import { ContractRegistry } from "../../src/evm/core/classes/registry";
import { sdk, signers } from "./before-setup";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import RouterABI from "@thirdweb-dev/contracts-js/dist/abis/Router.json";
import { expect } from "chai";
describe("Contract Registry", () => {
@@ -50,6 +52,12 @@ describe("Contract Registry", () => {
expect(contracts[0].address).to.equal(address);
});
it("check abi merge", async () => {
const abi = joinABIs([RouterABI, RouterABI]);
expect(abi.length).to.equal(RouterABI.length);
});
it("should allow adding and removing contracts", async () => {
sdk.updateSignerOrProvider(adminWallet);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+7
View File
@@ -1,5 +1,12 @@
# @thirdweb-dev/unity-js-bridge
## 0.1.7
### Patch Changes
- Updated dependencies [[`7cab8d1`](https://github.com/thirdweb-dev/js/commit/7cab8d1679f8d007091aa03adb83add3822a504a)]:
- @thirdweb-dev/sdk@3.6.11
## 0.1.6
### Patch Changes
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@thirdweb-dev/unity-js-bridge",
"version": "0.1.6",
"version": "0.1.7",
"main": "dist/thirdweb-unity-bridge.js",
"repository": "https://github.com/thirdweb-dev/js/tree/main/packages/unity-js-bridge",
"license": "Apache-2.0",