Skip to content

Commit

Permalink
feat(chains): allow deploying sft collections
Browse files Browse the repository at this point in the history
  • Loading branch information
imsk17 committed Sep 11, 2024
1 parent 7890571 commit d20d678
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/handlers/aptos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function aptosHandler({
if (!bd) throw new Error("Failed to fetch bridge data");
return bd.validators.data.length;
},
async deployCollection(signer, da) {
async deployNftCollection(signer, da) {
const transaction = await aptos.createCollectionTransaction({
creator: signer,
description: `Testnet Collection: ${da.name}(${da.symbol}) by XP Network.`,
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/aptos/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Account, Aptos, PendingTransactionResponse } from "@aptos-labs/ts-sdk";
import { Network } from "aptos";
import { BridgeStorage } from "../../contractsTypes/evm";
import { DeployCollection, MintNft, TNftChain } from "../types";
import { DeployNFTCollection, MintNft, TNftChain } from "../types";
import { TClaimData } from "./bridge-client";

export type TAptosMintArgs = {
Expand All @@ -18,7 +18,7 @@ export type TAptosHandler = TNftChain<
Aptos
> &
MintNft<Account, TAptosMintArgs, never, string> &
DeployCollection<Account, { name: string; symbol: string }, never, string>;
DeployNFTCollection<Account, { name: string; symbol: string }, never, string>;

export type TAptosParams = {
bridge: string;
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/cosmwasm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ export async function cosmWasmHandler({
);
return mint;
},
async deployCollection(signer, data, gasArgs) {
async deployNftCollection(signer, data, gasArgs) {
const sender = (await signer.getAccounts())[0];
const client = await SigningCosmWasmClient.connectWithSigner(rpc, signer);
const msg = {
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/cosmwasm/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { OfflineDirectSigner } from "@cosmjs/proto-signing";
import { ClaimData } from "@xp/cosmos-client/dist/bridge/Bridge.types";
import { BridgeStorage } from "../../contractsTypes/evm";
import {
DeployCollection,
DeployNFTCollection,
MintNft,
ReadClaimed721Event,
TSingularNftChain,
Expand Down Expand Up @@ -47,7 +47,7 @@ export type TCosmWasmHandler = TSingularNftChain<
CosmWasmExtraArgs,
ExecuteResult
> &
DeployCollection<
DeployNFTCollection<
OfflineDirectSigner,
{ name: string; symbol: string; codeId?: number },
CosmWasmExtraArgs,
Expand Down
13 changes: 12 additions & 1 deletion src/handlers/evm/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
Bridge__factory,
ERC721Royalty__factory,
ERC1155Royalty__factory,
} from "../../contractsTypes/evm";
import { retryFn } from "../utils";

Expand Down Expand Up @@ -86,7 +87,7 @@ export function evmHandler({
lock_tx_chain: claimed.args.lockTxChain,
};
},
async deployCollection(signer, da, ga) {
async deployNftCollection(signer, da, ga) {
const contract = await new ERC721Royalty__factory(signer).deploy(
da.name,
da.symbol,
Expand All @@ -98,6 +99,16 @@ export function evmHandler({
);
return await contract.getAddress();
},
async deploySFTCollection(signer, da, ga) {
const contract = await new ERC1155Royalty__factory(signer).deploy(
da.owner ?? signer,
{
...ga,
from: await signer.getAddress(),
},
);
return await contract.getAddress();
},
async mintNft(signer, ma, gas) {
const minter = ERC721Royalty__factory.connect(ma.contract, signer);
const response = await minter.mint(
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/hedera/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ export function hederaHandler({
},
);
},
async deployCollection(signer, da, ga) {
async deployNftCollection(signer, da, ga) {
const rif = proxy.connect(signer);
const deploy = await rif.deployNft(da.name, da.symbol, {
...ga,
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/hedera/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Bridge } from "../../contractsTypes/evm";
import { PayableOverrides } from "../../contractsTypes/evm/common";
import { TEvmParams } from "../evm/types";
import {
DeployCollection,
DeployNFTCollection,
MintNft,
ReadClaimed721Event,
TApproveNFT,
Expand Down Expand Up @@ -43,7 +43,7 @@ export type THederaHandler = TSingularNftChain<
PayableOverrides,
ContractTransactionResponse | TransactionResponseJSON
> &
DeployCollection<
DeployNFTCollection<
Signer,
{
name: string;
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/icp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export async function icpHandler({
throw new Error(`Failed to approve, ${approval?.Err}`);
return approval.Ok.toString();
},
async deployCollection(signer, _da) {
async deployNftCollection(signer, _da) {
const encoded = init({ IDL })[0].encodeValue({
icrc3_args: [
{
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/icp/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { BridgeStorage } from "../../contractsTypes/evm";
import { ClaimData } from "../../contractsTypes/icp/bridge/bridge.types";
import { Value } from "../../contractsTypes/icp/nft/nft.types";
import {
DeployCollection,
DeployNFTCollection,
MintNft,
ReadClaimed721Event,
TNFTList,
Expand Down Expand Up @@ -45,7 +45,7 @@ export type TICPHandler = TSingularNftChain<
HttpAgent
> &
MintNft<HttpAgent, TICPMintArgs, undefined, string> &
DeployCollection<
DeployNFTCollection<
HttpAgent,
{ name: string; symbol: string },
undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/multiversx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function multiversxHandler({
royalty: BigInt(royalties),
};
},
async deployCollection(signer, da, ga) {
async deployNftCollection(signer, da, ga) {
const builtInSC =
"erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u";
const args: TypedValue[] = [
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/multiversx/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Transaction } from "@multiversx/sdk-core/out";
import { INetworkProvider } from "@multiversx/sdk-network-providers/out/interface";
import { BridgeStorage } from "../../contractsTypes/evm";
import {
DeployCollection,
DeployNFTCollection,
MintNft,
ReadClaimed721Event,
ReadClaimed1155Event,
Expand Down Expand Up @@ -61,7 +61,7 @@ export type TMultiversXHandler = TSingularNftChain<
{ gasLimit: number; value: number },
string
> &
DeployCollection<
DeployNFTCollection<
TMultiversXSigner,
{ name: string; ticker: string },
{ gasLimit: number },
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/secret/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function secretHandler({
ret: tx,
};
},
async deployCollection(signer, da, ga) {
async deployNftCollection(signer, da, ga) {
const code = da.codeId ?? nftCodeId;
if (!code) {
throw new Error("Code not found");
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/secret/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SecretNetworkClient, TxOptions, TxResponse } from "secretjs";
import { BridgeStorage } from "../../contractsTypes/evm";
import {
DeployCollection,
DeployNFTCollection,
MintNft,
ReadClaimed721Event,
ReadClaimed1155Event,
Expand Down Expand Up @@ -41,7 +41,7 @@ export type TSecretHandler = TNftChain<
MintNft<SecretNetworkClient, SecretMintArgs, TxOptions, TxResponse> &
ReadClaimed721Event &
ReadClaimed1155Event &
DeployCollection<
DeployNFTCollection<
SecretNetworkClient,
{ name: string; symbol: string; codeId?: number },
TxOptions,
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/tezos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export function tezosHandler({
gasArgs,
);
},
async deployCollection(signer, da, ga) {
async deployNftCollection(signer, da, ga) {
const metadata = new MichelsonMap<string, bytes>();
metadata.set("", tas.bytes(char2Bytes("tezos-storage:data")));
metadata.set(
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/tezos/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import BigNumber from "bignumber.js";
import { BridgeStorage } from "../../contractsTypes/evm";
import { address, mutez, nat } from "../../contractsTypes/tezos/type-aliases";
import {
DeployCollection,
DeployNFTCollection,
MintNft,
ReadClaimed721Event,
TSingularNftChain,
Expand Down Expand Up @@ -57,7 +57,7 @@ export type TTezosHandler = TSingularNftChain<
TezosToolkit
> &
MintNft<TezosSigner, TezosMintArgs, Partial<SendParams>, string> &
DeployCollection<
DeployNFTCollection<
TezosSigner,
{
name: string;
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/ton/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export function tonHandler({

throw new Error("Claimed event not found");
},
async deployCollection(signer, da) {
async deployNftCollection(signer, da) {
const nft = client.open(
await TestnetNftCollection.fromInit(
da.owner_address,
Expand Down
4 changes: 2 additions & 2 deletions src/handlers/ton/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TonClient } from "@ton/ton";
import { BridgeStorage } from "../../contractsTypes/evm";
import { ClaimData } from "../../contractsTypes/ton/tonBridge";
import {
DeployCollection,
DeployNFTCollection,
MintNft,
ReadClaimed721Event,
TSingularNftChain,
Expand Down Expand Up @@ -35,7 +35,7 @@ export type TTonHandler = TSingularNftChain<
TonClient
> &
MintNft<Sender, TonMintArgs, never, undefined> &
DeployCollection<Sender, TonDeployArgs, never, string> &
DeployNFTCollection<Sender, TonDeployArgs, never, string> &
ReadClaimed721Event;

export type TTonParams = {
Expand Down
33 changes: 31 additions & 2 deletions src/handlers/types/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,43 @@ export type MintNft<Signer, MintArgs, GasArgs, RetTx> = {
mintNft: (signer: Signer, ma: MintArgs, gasArgs?: GasArgs) => Promise<RetTx>;
};

export type DeployCollection<Signer, DeployArgs, GasArgs, RetTx> = {
deployCollection: (
export type MintSft<Signer, MintArgs, GasArgs, RetTx> = {
mintSft: (
signer: Signer,
ma: MintArgs,
amount: bigint,
gasArgs?: GasArgs,
) => Promise<RetTx>;
};

export type Mint<Signer, MintArgs, GasArgs, RetTx> = MintNft<
Signer,
MintArgs,
GasArgs,
RetTx
> &
MintSft<Signer, MintArgs, GasArgs, RetTx>;

export type DeployNFTCollection<Signer, DeployArgs, GasArgs, RetTx> = {
deployNftCollection: (
signer: Signer,
da: DeployArgs,
ga?: GasArgs,
) => Promise<RetTx>;
};

export type DeploySFTCollection<Signer, DeployArgs, GasArgs, RetTx> = {
deploySFTCollection: (
signer: Signer,
da: DeployArgs,
ga?: GasArgs,
) => Promise<RetTx>;
};

export type DeployCollection<Signer, DeployArgs, GasArgs, RetTx> =
DeployNFTCollection<Signer, DeployArgs, GasArgs, RetTx> &
DeploySFTCollection<Signer, DeployArgs, GasArgs, RetTx>;

/**
* Represents a function that locks an NFT on the chain inside the bridge smart contract.
* @template Signer The type of the signer. ie {Signer} on EVM from ethers
Expand Down

0 comments on commit d20d678

Please sign in to comment.