Skip to content

Commit

Permalink
Factory: Chains: Approval: Add Approval To all chains
Browse files Browse the repository at this point in the history
  • Loading branch information
imsk17 committed Feb 8, 2024
1 parent 14a23a2 commit 9d4df94
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/handlers/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@ export type TLockNFT<Signer, ExtraArgs, RetTx> = {
) => Promise<RetTx>;
};

/**
* 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<Signer, ExtraArgs, RetTx> = {
/**
* 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<RetTx>;
};

/**
* Represents a signer and its corresponding signature.
* @field signer The signer's address as a string (should be HEX Encoded)
Expand Down Expand Up @@ -176,7 +199,8 @@ export type TSingularNftChain<
GetNFTArgs extends unknown[],
ExtraArgs,
RetTx,
> = TLockNFT<Signer, ExtraArgs, RetTx> &
> = TApproveNFT<Signer, ExtraArgs, RetTx> &
TLockNFT<Signer, ExtraArgs, RetTx> &
TGetNFTData<Signer, ExtraArgs, GetNFTArgs> &
TClaimNFT<Signer, ClaimData, ExtraArgs, RetTx> &
TGetBalance<Signer, ExtraArgs>;
Expand Down
9 changes: 9 additions & 0 deletions src/handlers/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions src/handlers/multiversx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
18 changes: 18 additions & 0 deletions src/handlers/secret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions src/handlers/tezos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<NFTContractType>(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;
Expand Down
1 change: 1 addition & 0 deletions src/handlers/ton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 9d4df94

Please sign in to comment.