diff --git a/src/handlers/chain.ts b/src/handlers/chain.ts index 22f32bf1..043d515c 100644 --- a/src/handlers/chain.ts +++ b/src/handlers/chain.ts @@ -25,6 +25,29 @@ export type TLockNFT = { ) => Promise; }; +/** + * Represents a type definition for the `approveNft` function. + * @template Signer The type of the signer. + * @template ExtraArgs The type of the extra arguments. + * @template RetTx The type of the return transaction. + */ +export type TApproveNFT = { + /** + * Approves the NFT to be locked on the source chain using the bridge smart contract. + * @param signer The signer who is going to send the approve transaction. + * @param tokenId The id of the NFT to be approved. + * @param contract The address of the NFT contract on the source chain. + * @param ex The extra arguments required for a chain. + * @returns A promise that resolves to the transaction which is of type {RetTx}. + */ + approveNft( + signer: Signer, + tokenId: string, + contract: string, + ex: ExtraArgs, + ): Promise; +}; + /** * Represents a signer and its corresponding signature. * @field signer The signer's address as a string (should be HEX Encoded) @@ -176,7 +199,8 @@ export type TSingularNftChain< GetNFTArgs extends unknown[], ExtraArgs, RetTx, -> = TLockNFT & +> = TApproveNFT & + TLockNFT & TGetNFTData & TClaimNFT & TGetBalance; diff --git a/src/handlers/evm.ts b/src/handlers/evm.ts index eb6fdfb9..b1772b1c 100644 --- a/src/handlers/evm.ts +++ b/src/handlers/evm.ts @@ -65,6 +65,15 @@ export function evmHandler({ ex, ); }, + async approveNft(signer, tokenId, contract, ex) { + return ERC721Royalty__factory.connect(contract, signer).approve( + bridge, + tokenId, + { + ...ex, + }, + ); + }, claimSft(wallet, claimData, sigs, ex) { const contract = Bridge__factory.connect(bridge, wallet); return contract.claimNFT1155( diff --git a/src/handlers/multiversx.ts b/src/handlers/multiversx.ts index 286cf79d..7d5a4cfa 100644 --- a/src/handlers/multiversx.ts +++ b/src/handlers/multiversx.ts @@ -107,6 +107,9 @@ export function multiversxHandler({ royalty: BigInt(royalties), }; }, + async approveNft(_signer, _tokenId, _contract, _ex) { + return Promise.resolve("Not Required for MultiversX"); + }, async lockNft(signer, sourceNft, destinationChain, to, tokenId, _) { const ba = new Address(bridge); diff --git a/src/handlers/secret.ts b/src/handlers/secret.ts index 3b4ff65e..286d5804 100644 --- a/src/handlers/secret.ts +++ b/src/handlers/secret.ts @@ -162,6 +162,24 @@ export function secretHandler({ royalty: BigInt(royalty), }; }, + async approveNft(signer, tokenId, contract, ex) { + const res = await signer.tx.compute.executeContract( + { + sender: signer.address, + contract_address: contract, + msg: { + approve: { + spender: bridge, + token_id: tokenId, + }, + }, + }, + { + ...ex, + }, + ); + return res; + }, async getBalance(signer, _) { const result = await signer.query.bank.balance({ address: signer.address, diff --git a/src/handlers/tezos.ts b/src/handlers/tezos.ts index 297165d5..fdebe607 100644 --- a/src/handlers/tezos.ts +++ b/src/handlers/tezos.ts @@ -68,6 +68,17 @@ export function tezosHandler({ Tezos, bridge }: TezosParams): TezosHandler { (await Tezos.tz.getBalance(await signer.publicKeyHash())).toString(), ); }, + async approveNft(signer, tokenId, contract, ex) { + const nftContract = await Tezos.contract.at(contract); + const tx = await nftContract.methods + .add_operator( + (await signer.publicKeyHash()) as address, + bridge as address, + tas.nat(tokenId.toString()), + ) + .send({ ...ex }); + return tx; + }, async claimNft(signer, data, ex, sigs) { const isTezosAddr = validateAddress(data.source_nft_contract_address) === 3; diff --git a/src/handlers/ton.ts b/src/handlers/ton.ts index 6a9c495c..fcc1350f 100644 --- a/src/handlers/ton.ts +++ b/src/handlers/ton.ts @@ -77,6 +77,7 @@ export function tonHandler({ client, bridgeAddress }: TonParams): TonHandler { }, ); }, + async approveNft(_signer, _tokenId, _contract, _ex) {}, async nftData(_signer, _, _tokenId, contract) { const nftItem = client.open( NftItem.fromAddress(Address.parseFriendly(contract).address),