diff --git a/src/handlers/chain.ts b/src/handlers/chain.ts index dad61d62..d3416ecf 100644 --- a/src/handlers/chain.ts +++ b/src/handlers/chain.ts @@ -222,6 +222,10 @@ export type TGetProvider = { getProvider: () => T; }; +export type TMapTransferDetailsToChainClaimData = { + transform: (input: TNftTransferDetailsObject) => To; +}; + /** * Represents a type that has all the methods required to implement on a chain that can be used in the bridge to transfer Non Fungible Tokens. It is a combination of some of the types defined above. * @template Signer The type of the signer. ie {Signer} on EVM from ethers @@ -236,7 +240,8 @@ export type TSingularNftChain = TClaimNFT & TGetBalance & TGetClaimData & - TGetProvider; + TGetProvider & + TMapTransferDetailsToChainClaimData; /** * Represents a type that has all the methods required to implement on a chain that can be used in the bridge to transfer Semi Fungible Tokens. It is a combination of some of the types defined above. diff --git a/src/handlers/evm.ts b/src/handlers/evm.ts index f591df89..c36f3453 100644 --- a/src/handlers/evm.ts +++ b/src/handlers/evm.ts @@ -96,6 +96,9 @@ export function evmHandler({ getBalance(signer) { return provider.getBalance(signer); }, + transform(input) { + return { ...input }; + }, async nftData(tokenId, contract, overrides) { const nft = ERC721Royalty__factory.connect(contract, provider); return { diff --git a/src/handlers/multiversx.ts b/src/handlers/multiversx.ts index 55280919..1bff6583 100644 --- a/src/handlers/multiversx.ts +++ b/src/handlers/multiversx.ts @@ -123,6 +123,25 @@ export function multiversxHandler({ getProvider() { return provider; }, + transform(input) { + return { + attrs: input.metadata, + destinationChain: input.destinationChain, + destinationUserAddress: input.destinationUserAddress, + fee: input.fee, + metadata: input.metadata, + name: input.name, + nftType: input.nftType, + royalty: input.royalty, + royaltyReceiver: input.royaltyReceiver, + sourceChain: input.sourceChain, + sourceNftContractAddress: input.sourceNftContractAddress, + symbol: input.symbol, + tokenAmount: input.tokenAmount, + tokenId: input.tokenId, + transactionHash: input.transactionHash, + }; + }, async approveNft(_signer, _tokenId, _contract) { return Promise.resolve("Not Required for MultiversX"); }, diff --git a/src/handlers/secret.ts b/src/handlers/secret.ts index 2cdd6f74..4169de4c 100644 --- a/src/handlers/secret.ts +++ b/src/handlers/secret.ts @@ -85,7 +85,24 @@ export function secretHandler({ ); return tx; }, - + transform(input) { + return { + destination_chain: input.destinationChain, + destination_user_address: input.destinationUserAddress, + fee: input.fee, + name: input.name, + symbol: input.symbol, + metadata: input.metadata, + royalty: parseInt(input.royalty), + nft_type: input.nftType, + royalty_receiver: input.royaltyReceiver, + source_chain: input.sourceChain, + source_nft_contract_address: input.sourceNftContractAddress, + token_amount: input.tokenAmount, + token_id: input.tokenId, + transaction_hash: input.transactionHash, + }; + }, async getClaimData(txHash) { const eventId = "LockedEventInfo"; const tx = await provider.query.getTx(txHash); diff --git a/src/handlers/tezos.ts b/src/handlers/tezos.ts index aa6c29c0..10edc651 100644 --- a/src/handlers/tezos.ts +++ b/src/handlers/tezos.ts @@ -74,6 +74,24 @@ export function tezosHandler({ getProvider() { return Tezos; }, + transform(input) { + return { + dest_address: tas.address(input.destinationUserAddress), + dest_chain: input.destinationChain, + fee: tas.mutez(input.fee), + metadata: input.metadata, + name: input.name, + nft_type: input.nftType, + royalty: tas.nat(input.royalty), + royalty_receiver: tas.address(input.royaltyReceiver), + source_chain: input.sourceChain, + source_nft_contract_address: input.sourceNftContractAddress, + symbol: input.symbol, + token_amount: tas.nat(input.tokenAmount), + token_id: tas.nat(input.tokenId), + transaction_hash: input.transactionHash, + }; + }, async getBalance(signer, _) { return BigInt( (await Tezos.tz.getBalance(await signer.publicKeyHash())).toString(), diff --git a/src/handlers/ton.ts b/src/handlers/ton.ts index ed676ba2..b1e766f4 100644 --- a/src/handlers/ton.ts +++ b/src/handlers/ton.ts @@ -132,6 +132,78 @@ export function tonHandler({ } throw new Error("No locked event found"); }, + transform(input) { + let destinationAddress: Address; + try { + destinationAddress = Address.parseFriendly( + input.destinationUserAddress, + ).address; + } catch (e) { + destinationAddress = Address.parseFriendly( + input.royaltyReceiver, + ).address; + } + let sourceNftContractAddress_ = beginCell() + .storeSlice( + beginCell() + .storeStringTail(input.sourceNftContractAddress) + .endCell() + .asSlice(), + ) + .endCell(); + try { + sourceNftContractAddress_ = beginCell() + .storeSlice( + beginCell() + .storeAddress( + Address.parseFriendly(input.sourceNftContractAddress).address, + ) + .endCell() + .asSlice(), + ) + .endCell(); + } catch (e) { + console.log("Not Native TON Address"); + } + return { + $$type: "ClaimData", + data1: { + $$type: "ClaimData1", + destinationChain: input.destinationChain, + destinationUserAddress: destinationAddress, + sourceChain: input.sourceChain, + tokenAmount: BigInt(input.tokenAmount), + tokenId: BigInt(input.tokenId), + }, + data2: { + $$type: "ClaimData2", + name: input.name, + nftType: input.nftType, + symbol: input.symbol, + }, + data3: { + $$type: "ClaimData3", + fee: BigInt(input.fee), + metadata: input.metadata, + royaltyReceiver: Address.parseFriendly(input.royaltyReceiver).address, + sourceNftContractAddress: sourceNftContractAddress_, + }, + data4: { + $$type: "ClaimData4", + newContent: beginCell() + .storeInt(0x01, 8) + .storeStringRefTail(input.metadata) + .endCell(), + royalty: { + $$type: "RoyaltyParams", + denominator: 10000n, + destination: Address.parseFriendly(input.royaltyReceiver).address, + numerator: BigInt(input.royalty), + }, + transactionHash: input.transactionHash, + }, + }; + }, async lockNft(signer, sourceNft, destinationChain, to, tokenId, _) { if (!signer.address) { throw new Error("No Address present in signer");