Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Yash <kumaryashcse@gmail.com>
- Loading branch information
1 parent
557429b
commit 9eaa21d
Showing
18 changed files
with
358 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@thirdweb-dev/contracts-js": patch | ||
--- | ||
|
||
Update to v3.3.0 of contracts package |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@thirdweb-dev/sdk": patch | ||
--- | ||
|
||
Add support for multi chain registry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@thirdweb-dev/contracts-js": patch | ||
--- | ||
|
||
Update to 3.1.10 of contracts package |
4 changes: 4 additions & 0 deletions
4
packages/contracts-js/factories/TWRegistryLegacy__factory/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"main": "dist/thirdweb-dev-contracts-js-factories-TWRegistryLegacy__factory.cjs.js", | ||
"module": "dist/thirdweb-dev-contracts-js-factories-TWRegistryLegacy__factory.esm.js" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
packages/sdk/src/evm/core/classes/multichain-registry.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
import { NetworkOrSignerOrProvider, TransactionResult } from ".."; | ||
import { getMultichainRegistryAddress } from "../../constants/addresses"; | ||
import { PublishedMetadata } from "../../schema/contracts/custom"; | ||
import { SDKOptions } from "../../schema/sdk-options"; | ||
import { AddContractInput, ContractInput, DeployedContract } from "../../types"; | ||
import { ContractWrapper } from "./contract-wrapper"; | ||
import type { | ||
TWMultichainRegistryRouter, | ||
TWMultichainRegistryLogic, | ||
} from "@thirdweb-dev/contracts-js"; | ||
import TWRegistryABI from "@thirdweb-dev/contracts-js/dist/abis/TWMultichainRegistryLogic.json"; | ||
import TWRegistryRouterABI from "@thirdweb-dev/contracts-js/dist/abis/TWMultichainRegistryRouter.json"; | ||
import { ThirdwebStorage } from "@thirdweb-dev/storage"; | ||
import { constants, utils } from "ethers"; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export class MultichainRegistry { | ||
private registryLogic: ContractWrapper<TWMultichainRegistryLogic>; | ||
private registryRouter: ContractWrapper<TWMultichainRegistryRouter>; | ||
private storage: ThirdwebStorage; | ||
|
||
constructor( | ||
network: NetworkOrSignerOrProvider, | ||
storage: ThirdwebStorage, | ||
options: SDKOptions = {}, | ||
) { | ||
this.storage = storage; | ||
this.registryLogic = new ContractWrapper<TWMultichainRegistryLogic>( | ||
network, | ||
getMultichainRegistryAddress(), | ||
TWRegistryABI, | ||
options, | ||
); | ||
|
||
this.registryRouter = new ContractWrapper<TWMultichainRegistryRouter>( | ||
network, | ||
getMultichainRegistryAddress(), | ||
TWRegistryRouterABI, | ||
options, | ||
); | ||
} | ||
|
||
public async updateSigner(signer: NetworkOrSignerOrProvider) { | ||
this.registryLogic.updateSignerOrProvider(signer); | ||
this.registryRouter.updateSignerOrProvider(signer); | ||
} | ||
|
||
public async getContractMetadataURI( | ||
chainId: number, | ||
address: string, | ||
): Promise<string> { | ||
return await this.registryLogic.readContract.getMetadataUri( | ||
chainId, | ||
address, | ||
); | ||
} | ||
|
||
public async getContractMetadata( | ||
chainId: number, | ||
address: string, | ||
): Promise<PublishedMetadata> { | ||
const uri = await this.getContractMetadataURI(chainId, address); | ||
if (!uri) { | ||
throw new Error( | ||
`No metadata URI found for contract ${address} on chain ${chainId}`, | ||
); | ||
} | ||
// TODO define the metadata JSON schema | ||
return await this.storage.downloadJSON<PublishedMetadata>(uri); | ||
} | ||
|
||
public async getContractAddresses( | ||
walletAddress: string, | ||
): Promise<DeployedContract[]> { | ||
return (await this.registryLogic.readContract.getAll(walletAddress)) | ||
.filter( | ||
(result) => | ||
utils.isAddress(result.deploymentAddress) && | ||
result.deploymentAddress.toLowerCase() !== constants.AddressZero, | ||
) | ||
.map((result) => ({ | ||
address: result.deploymentAddress, | ||
chainId: result.chainId.toNumber(), | ||
})); | ||
} | ||
|
||
public async addContract( | ||
contract: AddContractInput, | ||
): Promise<TransactionResult> { | ||
return await this.addContracts([contract]); | ||
} | ||
|
||
public async addContracts( | ||
contracts: AddContractInput[], | ||
): Promise<TransactionResult> { | ||
const deployerAddress = await this.registryRouter.getSignerAddress(); | ||
const encoded: string[] = []; | ||
contracts.forEach((contact) => { | ||
encoded.push( | ||
this.registryLogic.readContract.interface.encodeFunctionData("add", [ | ||
deployerAddress, | ||
contact.address, | ||
contact.chainId, | ||
contact.metadataURI || "", | ||
]), | ||
); | ||
}); | ||
|
||
return { | ||
receipt: await this.registryRouter.multiCall(encoded), | ||
}; | ||
} | ||
|
||
public async removeContract( | ||
contract: ContractInput, | ||
): Promise<TransactionResult> { | ||
return await this.removeContracts([contract]); | ||
} | ||
|
||
public async removeContracts( | ||
contracts: ContractInput[], | ||
): Promise<TransactionResult> { | ||
const deployerAddress = await this.registryRouter.getSignerAddress(); | ||
const encoded: string[] = []; | ||
contracts.forEach((contract) => { | ||
encoded.push( | ||
this.registryLogic.readContract.interface.encodeFunctionData("remove", [ | ||
deployerAddress, | ||
contract.address, | ||
contract.chainId, | ||
]), | ||
); | ||
}); | ||
|
||
return { | ||
receipt: await this.registryRouter.multiCall(encoded), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { BytesLikeSchema } from "../../../../core/schema/shared"; | ||
import { AddressSchema } from "../../shared"; | ||
import { z } from "zod"; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const PluginMapInput = z.object({ | ||
functionSelector: BytesLikeSchema, | ||
functionSignature: z.string(), | ||
pluginAddress: AddressSchema, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { PluginMapInput } from "../schema/contracts/common/plugins"; | ||
import { z } from "zod"; | ||
|
||
/** | ||
* Input model to pass a list of extension-addresses + function-selectors | ||
* @public | ||
*/ | ||
export type Plugin = z.input<typeof PluginMapInput>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export type ContractInput = { | ||
address: string; | ||
chainId: number; | ||
}; | ||
|
||
export type AddContractInput = ContractInput & { | ||
metadataURI?: string; | ||
}; | ||
|
||
export type DeployedContract = { | ||
address: string; | ||
chainId: number; | ||
}; |
Oops, something went wrong.