diff --git a/package.json b/package.json index 66cb0a3b..805973fa 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "@taquito/taquito": "^19.0.0", "@taquito/tzip16": "^19.0.0", "@taquito/utils": "^19.0.0", + "@thalalabs/surf": "^1.7.3", "@ton/core": "=0.56.3", "@ton/crypto": "=3.2.0", "@ton/ton": "=13.11.1", diff --git a/src/factory/config.ts b/src/factory/config.ts index 848cf4b2..f82b811b 100644 --- a/src/factory/config.ts +++ b/src/factory/config.ts @@ -138,7 +138,7 @@ export namespace ChainFactoryConfigs { }, aptosParams: { bridge: - "eea0db4fdc3d8915808c67268a668f3ee0810e864a40b4bde6c371b09337250a", + "13f8d626e383e8621a89caeb05c56a95fda38aa2dddfa8c2b1ed063f0edb23c9", identifier: "APTOS", network: Network.TESTNET, storage, diff --git a/src/factory/types/utils.ts b/src/factory/types/utils.ts index c605506f..83d6c73a 100644 --- a/src/factory/types/utils.ts +++ b/src/factory/types/utils.ts @@ -32,7 +32,7 @@ export type TChainFactory = { sourceNftContractAddress: string, destinationChain: TSupportedChain, to: string, - tokenId: bigint, + tokenId: string, metadataUri: string, extraArgs?: ExtraArgs, ) => Promise<{ ret: Ret; hash: () => string }>; @@ -42,7 +42,7 @@ export type TChainFactory = { sourceNftContractAddress: string, destinationChain: TSupportedSftChain, to: string, - tokenId: bigint, + tokenId: string, amt: bigint, metadataUri: string, extraArgs?: ExtraArgs, diff --git a/src/handlers/aptos/abi.ts b/src/handlers/aptos/abi.ts new file mode 100644 index 00000000..3fd5d2e0 --- /dev/null +++ b/src/handlers/aptos/abi.ts @@ -0,0 +1,419 @@ +export const ABI = (address: string) => { + return { + address: address, + name: "aptos_nft_bridge", + friends: [], + exposed_functions: [ + { + name: "add_validator", + visibility: "public", + is_entry: true, + is_view: false, + generic_type_params: [], + params: ["vector", "vector>", "vector>"], + return: [], + }, + { + name: "blacklist_validator", + visibility: "public", + is_entry: true, + is_view: false, + generic_type_params: [], + params: ["vector", "vector>", "vector>"], + return: [], + }, + { + name: "claim_1155", + visibility: "public", + is_entry: true, + is_view: false, + generic_type_params: [], + params: [ + "&signer", + "address", + "0x1::string::String", + "0x1::string::String", + "u64", + "address", + "u64", + "vector>", + "vector>", + "vector", + "vector", + "vector", + "u256", + "vector", + "vector", + "0x1::string::String", + "0x1::string::String", + "u64", + ], + return: [], + }, + { + name: "claim_721", + visibility: "public", + is_entry: true, + is_view: false, + generic_type_params: [], + params: [ + "&signer", + "address", + "0x1::string::String", + "0x1::string::String", + "u64", + "address", + "u64", + "vector>", + "vector>", + "vector", + "vector", + "vector", + "u256", + "vector", + "vector", + "0x1::string::String", + "0x1::string::String", + ], + return: [], + }, + { + name: "claim_validator_rewards", + visibility: "public", + is_entry: true, + is_view: false, + generic_type_params: [], + params: ["signer", "address", "vector"], + return: [], + }, + { + name: "has_validator", + visibility: "public", + is_entry: false, + is_view: true, + generic_type_params: [], + params: ["vector"], + return: ["bool"], + }, + { + name: "initialize", + visibility: "public", + is_entry: true, + is_view: false, + generic_type_params: [], + params: ["&signer", "vector>", "vector", "vector"], + return: [], + }, + { + name: "lock_1155", + visibility: "public", + is_entry: true, + is_view: false, + generic_type_params: [], + params: [ + "&signer", + "address", + "vector", + "0x1::string::String", + "address", + "u64", + "0x1::string::String", + ], + return: [], + }, + { + name: "lock_721", + visibility: "public", + is_entry: true, + is_view: false, + generic_type_params: [], + params: [ + "&signer", + "address", + "vector", + "0x1::string::String", + "address", + "0x1::string::String", + ], + return: [], + }, + { + name: "owns_nft", + visibility: "public", + is_entry: false, + is_view: true, + generic_type_params: [], + params: ["address", "0x1::string::String", "0x1::string::String"], + return: ["bool"], + }, + { + name: "token_id_from_nonce_and_collection", + visibility: "public", + is_entry: false, + is_view: true, + generic_type_params: [], + params: ["u256", "vector"], + return: ["address"], + }, + { + name: "validator_count", + visibility: "public", + is_entry: false, + is_view: true, + generic_type_params: [], + params: [], + return: ["u64"], + }, + ], + structs: [ + { + name: "AddNewValidatorEvent", + is_native: false, + is_event: true, + abilities: ["drop", "store"], + generic_type_params: [], + fields: [{ name: "validator", type: "vector" }], + }, + { + name: "BlacklistValidatorEvent", + is_native: false, + is_event: true, + abilities: ["drop", "store"], + generic_type_params: [], + fields: [{ name: "validator", type: "vector" }], + }, + { + name: "Bridge", + is_native: false, + is_event: false, + abilities: ["key"], + generic_type_params: [], + fields: [ + { + name: "validators", + type: "0x1::simple_map::SimpleMap, 0x13f8d626e383e8621a89caeb05c56a95fda38aa2dddfa8c2b1ed063f0edb23c9::aptos_nft_bridge::Validator>", + }, + { name: "signer_cap", type: "0x1::account::SignerCapability" }, + { + name: "collection_objects", + type: "0x1::table::Table<0x13f8d626e383e8621a89caeb05c56a95fda38aa2dddfa8c2b1ed063f0edb23c9::aptos_nft_bridge::CollectionObject, u256>", + }, + { name: "nfts_counter", type: "u64" }, + { + name: "original_to_duplicate_mapping", + type: "0x1::table::Table<0x13f8d626e383e8621a89caeb05c56a95fda38aa2dddfa8c2b1ed063f0edb23c9::aptos_nft_bridge::OriginalToDuplicateKey, 0x13f8d626e383e8621a89caeb05c56a95fda38aa2dddfa8c2b1ed063f0edb23c9::aptos_nft_bridge::OriginalToDuplicateInfo>", + }, + { + name: "duplicate_to_original_mapping", + type: "0x1::table::Table<0x13f8d626e383e8621a89caeb05c56a95fda38aa2dddfa8c2b1ed063f0edb23c9::aptos_nft_bridge::DuplicateToOriginalKey, 0x13f8d626e383e8621a89caeb05c56a95fda38aa2dddfa8c2b1ed063f0edb23c9::aptos_nft_bridge::DuplicateToOriginalInfo>", + }, + { + name: "nft_collection_tokens", + type: "0x1::simple_map::SimpleMap<0x13f8d626e383e8621a89caeb05c56a95fda38aa2dddfa8c2b1ed063f0edb23c9::aptos_nft_bridge::CollectionNftObject, address>", + }, + { + name: "nft_collections_counter", + type: "0x1::simple_map::SimpleMap", + }, + { name: "self_chain", type: "vector" }, + { + name: "blacklisted_validators", + type: "0x1::simple_map::SimpleMap, bool>", + }, + ], + }, + { + name: "Claim1155Event", + is_native: false, + is_event: true, + abilities: ["drop", "store"], + generic_type_params: [], + fields: [ + { name: "source_chain", type: "vector" }, + { name: "token_id", type: "u256" }, + { name: "amount", type: "u64" }, + { name: "transaction_hash", type: "vector" }, + { name: "nft_contract", type: "vector" }, + ], + }, + { + name: "Claim721Event", + is_native: false, + is_event: true, + abilities: ["drop", "store"], + generic_type_params: [], + fields: [ + { name: "source_chain", type: "vector" }, + { name: "token_id", type: "u256" }, + { name: "transaction_hash", type: "vector" }, + { name: "nft_contract", type: "vector" }, + ], + }, + { + name: "ClaimData", + is_native: false, + is_event: false, + abilities: ["copy", "drop"], + generic_type_params: [], + fields: [ + { name: "token_id", type: "u256" }, + { name: "source_chain", type: "vector" }, + { name: "destination_chain", type: "vector" }, + { name: "user", type: "address" }, + { name: "source_nft_contract_address", type: "vector" }, + { name: "name", type: "0x1::string::String" }, + { name: "royalty_percentage", type: "u64" }, + { name: "royalty_payee_address", type: "address" }, + { name: "metadata", type: "0x1::string::String" }, + { name: "transaction_hash", type: "vector" }, + { name: "token_amount", type: "u256" }, + { name: "nft_type", type: "vector" }, + { name: "fee", type: "u64" }, + { name: "symbol", type: "0x1::string::String" }, + ], + }, + { + name: "CollectionNftObject", + is_native: false, + is_event: false, + abilities: ["copy", "drop", "store"], + generic_type_params: [], + fields: [ + { name: "collection_address", type: "vector" }, + { name: "token_id", type: "u256" }, + ], + }, + { + name: "CollectionObject", + is_native: false, + is_event: false, + abilities: ["copy", "drop", "store"], + generic_type_params: [], + fields: [ + { name: "collection", type: "address" }, + { name: "object", type: "address" }, + ], + }, + { + name: "DuplicateToOriginalInfo", + is_native: false, + is_event: false, + abilities: ["copy", "drop", "store"], + generic_type_params: [], + fields: [ + { name: "source_chain", type: "vector" }, + { name: "source_contract", type: "vector" }, + ], + }, + { + name: "DuplicateToOriginalKey", + is_native: false, + is_event: false, + abilities: ["copy", "drop", "store"], + generic_type_params: [], + fields: [ + { name: "self_chain", type: "vector" }, + { name: "collection_address", type: "vector" }, + ], + }, + { + name: "LockedEvent", + is_native: false, + is_event: true, + abilities: ["drop", "store"], + generic_type_params: [], + fields: [ + { name: "token_id", type: "u256" }, + { name: "destination_user_address", type: "0x1::string::String" }, + { name: "token_amount", type: "u64" }, + { name: "nft_type", type: "vector" }, + { name: "destination_chain", type: "vector" }, + { name: "source_chain", type: "vector" }, + { name: "collection_address", type: "vector" }, + { name: "token_address", type: "address" }, + { name: "metadata_uri", type: "0x1::string::String" }, + ], + }, + { + name: "OriginalToDuplicateInfo", + is_native: false, + is_event: false, + abilities: ["copy", "drop", "store"], + generic_type_params: [], + fields: [ + { name: "self_chain", type: "vector" }, + { name: "collection_address", type: "vector" }, + ], + }, + { + name: "OriginalToDuplicateKey", + is_native: false, + is_event: false, + abilities: ["copy", "drop", "store"], + generic_type_params: [], + fields: [ + { name: "source_chain", type: "vector" }, + { name: "source_contract", type: "vector" }, + ], + }, + { + name: "ProcessedClaims", + is_native: false, + is_event: false, + abilities: ["key"], + generic_type_params: [], + fields: [{ name: "claims", type: "vector>" }], + }, + { + name: "RewardValidatorEvent", + is_native: false, + is_event: true, + abilities: ["drop", "store"], + generic_type_params: [], + fields: [{ name: "validator", type: "vector" }], + }, + { + name: "SignatureInfo", + is_native: false, + is_event: false, + abilities: ["drop"], + generic_type_params: [], + fields: [ + { name: "public_key", type: "vector" }, + { name: "signature", type: "vector" }, + ], + }, + { + name: "UnLock1155Event", + is_native: false, + is_event: true, + abilities: ["drop", "store"], + generic_type_params: [], + fields: [ + { name: "to", type: "address" }, + { name: "token_id", type: "u256" }, + { name: "amount", type: "u64" }, + ], + }, + { + name: "UnLock721Event", + is_native: false, + is_event: true, + abilities: ["drop", "store"], + generic_type_params: [], + fields: [ + { name: "to", type: "address" }, + { name: "token_id", type: "u256" }, + ], + }, + { + name: "Validator", + is_native: false, + is_event: false, + abilities: ["copy", "drop", "store"], + generic_type_params: [], + fields: [{ name: "pending_reward", type: "u64" }], + }, + ], + } as const; +}; diff --git a/src/handlers/aptos/bridge-client.ts b/src/handlers/aptos/bridge-client.ts deleted file mode 100644 index ac99e106..00000000 --- a/src/handlers/aptos/bridge-client.ts +++ /dev/null @@ -1,465 +0,0 @@ -import { createHash } from "crypto"; -import { - Account, - Aptos, - Ed25519Account, - InputViewFunctionData, - PendingTransactionResponse, -} from "@aptos-labs/ts-sdk"; -import { BCS, HexString } from "aptos"; -import { - BRIDGE_FUNCTIONS, - BRIDGE_MODULE, - MINT_FUNCTIONS, - MINT_MODULE, -} from "./constants"; - -type TCollectionCounterObj = { - key: string; - value: string; -}; - -type TValidatorsObj = { - key: string; - value: { - pending_reward: string; - }; -}; - -export type TClaimData = { - collection: string; - description: string; - symbol: string; - amount: number; - uri: string; - iconUri: string; - projectUri: string; - royaltyPointsNumerator: number; - royaltyPointsDenominator: number; - royaltyPayeeAddress: HexString; - fee: number; - sourceChain: Uint8Array; - sourceNftContractAddress: Uint8Array; - destinationChain: Uint8Array; - transactionHash: Uint8Array; - tokenId: string; - nftType: Uint8Array; - metadata: string; -}; - -type TBridgeData = { - collection_objects: { - handle: string; - }; - duplicate_to_original_mapping: { - handle: string; - }; - nft_collection_tokens: { - handle: string; - }; - nft_collections_counter: { - data: TCollectionCounterObj[]; - }; - nfts_counter: string; - original_to_duplicate_mapping: { - handle: string; - }; - self_chain: string; - validators: { - data: TValidatorsObj[]; - }; - signer_cap: { - account: string; - }; -}; - -export class BridgeClient { - private aptosClient: Aptos; - private address: string; - - constructor(client: Aptos, address: string) { - this.aptosClient = client; - this.address = address; - } - - async fundAccounts(accounts: Ed25519Account[]): Promise { - await Promise.all( - accounts.map((account) => - this.aptosClient.fundAccount({ - accountAddress: account.accountAddress, - amount: 100, - options: { checkSuccess: true }, - }), - ), - ); - } - - async initialize( - adminAccount: Ed25519Account, - validators: Uint8Array[], - seed: Uint8Array, - selfChain: Uint8Array, - ): Promise { - const transaction = await this.aptosClient.transaction.build.simple({ - sender: adminAccount.accountAddress, - data: { - function: `${this.address}::${BRIDGE_MODULE}::${BRIDGE_FUNCTIONS.Initialize}`, - functionArguments: [validators, seed, selfChain], - }, - }); - - return this.aptosClient.signAndSubmitTransaction({ - signer: adminAccount, - transaction, - }); - } - - async addValidator( - adminAccount: Ed25519Account, - validator: Uint8Array, - signatures: Uint8Array[], - public_keys: Uint8Array[], - ) { - const transaction = await this.aptosClient.transaction.build.simple({ - sender: adminAccount.accountAddress, - data: { - function: `${this.address}::${BRIDGE_MODULE}::${BRIDGE_FUNCTIONS.AddValidator}`, - functionArguments: [validator, signatures, public_keys], - }, - }); - - return this.aptosClient.signAndSubmitTransaction({ - signer: adminAccount, - transaction, - }); - } - - async lock721( - owner: Account, - collection: string, - name: string, - destination_chain: Uint8Array, - token_id: number, - source_nft_contract_address: Uint8Array, - ) { - const transaction = await this.aptosClient.transaction.build.simple({ - sender: owner.accountAddress, - data: { - function: `${this.address}::${BRIDGE_MODULE}::${BRIDGE_FUNCTIONS.Lock721}`, - functionArguments: [ - collection, - name, - destination_chain, - token_id, - source_nft_contract_address, - ], - }, - }); - - return this.aptosClient.signAndSubmitTransaction({ - signer: owner, - transaction, - }); - } - - async lock1155( - owner: Account, - collection: string, - name: string, - amount: number, - destination_chain: Uint8Array, - token_id: number, - source_nft_contract_address: Uint8Array, - ) { - const transaction = await this.aptosClient.transaction.build.simple({ - sender: owner.accountAddress, - data: { - function: `${this.address}::${BRIDGE_MODULE}::${BRIDGE_FUNCTIONS.Lock1155}`, - functionArguments: [ - collection, - name, - amount, - destination_chain, - token_id, - source_nft_contract_address, - ], - }, - }); - - return this.aptosClient.signAndSubmitTransaction({ - signer: owner, - transaction, - }); - } - - async claim721( - sender: Account, - { - collection, - description, - symbol, - uri, - royaltyPointsNumerator, - royaltyPointsDenominator, - royaltyPayeeAddress, - fee, - - sourceChain, - sourceNftContractAddress, - destinationChain, - transactionHash, - tokenId, - nftType, - metadata, - }: TClaimData, - signatures: Uint8Array[], - publicKeys: Uint8Array[], - ) { - const transaction = await this.aptosClient.transaction.build.simple({ - sender: sender.accountAddress, - data: { - function: `${this.address}::${BRIDGE_MODULE}::${BRIDGE_FUNCTIONS.Claim721}`, - functionArguments: [ - collection, - description, - uri, - royaltyPointsNumerator, - royaltyPointsDenominator, - royaltyPayeeAddress.toString(), - fee, - signatures, - publicKeys, - destinationChain, - sourceChain, - sourceNftContractAddress, - tokenId, - transactionHash, - nftType, - metadata, - symbol, - // amount, - // iconUri, - // projectUri, - ], - }, - }); - - return this.aptosClient.signAndSubmitTransaction({ - signer: sender, - transaction, - }); - } - - async claim1155( - sender: Account, - { - collection, - description, - symbol, - amount, - uri, - iconUri, - projectUri, - royaltyPointsNumerator, - royaltyPointsDenominator, - royaltyPayeeAddress, - fee, - sourceChain, - sourceNftContractAddress, - destinationChain, - transactionHash, - tokenId, - nftType, - metadata, - }: TClaimData, - signatures: Uint8Array[], - publicKeys: Uint8Array[], - ) { - const transaction = await this.aptosClient.transaction.build.simple({ - sender: sender.accountAddress, - data: { - function: `${this.address}::${BRIDGE_MODULE}::${BRIDGE_FUNCTIONS.Claim1155}`, - functionArguments: [ - collection, - description, - uri, - royaltyPointsNumerator, - royaltyPointsDenominator, - royaltyPayeeAddress.toString(), - fee, - signatures, - publicKeys, - destinationChain, - sourceChain, - sourceNftContractAddress, - tokenId, - transactionHash, - nftType, - metadata, - symbol, - amount, - iconUri, - projectUri, - ], - }, - }); - - return this.aptosClient.signAndSubmitTransaction({ - signer: sender, - transaction, - }); - } - - async claimValidatorRewards( - adminAccount: Ed25519Account, - to: HexString, - validator: Uint8Array, - signatures: Uint8Array[], - public_keys: Uint8Array[], - ) { - const transaction = await this.aptosClient.transaction.build.simple({ - sender: adminAccount.accountAddress, - data: { - function: `${this.address}::${BRIDGE_MODULE}::${BRIDGE_FUNCTIONS.ClaimValidatorRewards}`, - functionArguments: [to.toString(), validator, signatures, public_keys], - }, - }); - - return this.aptosClient.signAndSubmitTransaction({ - signer: adminAccount, - transaction, - }); - } - - async mintNft721( - owner: Ed25519Account, - collection_name: string, - collection_description: string, - collection_uri: string, - nft_name: string, - nft_description: string, - nft_uri: string, - ) { - const transaction = await this.aptosClient.transaction.build.simple({ - sender: owner.accountAddress, - data: { - function: `${this.address}::${MINT_MODULE}::${MINT_FUNCTIONS.MINT_TO}`, - functionArguments: [ - collection_name, - collection_description, - collection_uri, - nft_name, - nft_description, - nft_uri, - ], - }, - }); - - return this.aptosClient.signAndSubmitTransaction({ - signer: owner, - transaction, - }); - } - - async mintNft1155( - owner: Ed25519Account, - collection_name: string, - collection_description: string, - collection_uri: string, - nft_name: string, - nft_description: string, - nft_uri: string, - token_symbol: string, - amount: number, - icon_uri: string, - project_uri: string, - ) { - const transaction = await this.aptosClient.transaction.build.simple({ - sender: owner.accountAddress, - data: { - function: `${this.address}::${MINT_MODULE}::${MINT_FUNCTIONS.MINT_1155_TO}`, - functionArguments: [ - collection_name, - collection_description, - collection_uri, - nft_name, - nft_description, - nft_uri, - token_symbol, - amount, - icon_uri, - project_uri, - ], - }, - }); - - return this.aptosClient.signAndSubmitTransaction({ - signer: owner, - transaction, - }); - } - - async userOwnsNft( - owner: HexString, - collection: string, - name: string, - ): Promise<[boolean]> { - const payload: InputViewFunctionData = { - function: `${this.address}::${BRIDGE_MODULE}::${BRIDGE_FUNCTIONS.OwnsNFT}`, - // type_arguments: ["0x1::aptos_coin::AptosCoin"], - functionArguments: [owner.toString(), collection, name], - }; - return this.aptosClient.view({ payload }); - } - - async getBridgeData(): Promise { - const resources = await this.aptosClient.getAccountResources({ - accountAddress: this.address, - }); - const bridgeResource = resources.find( - (r) => r.type === `0x${this.address}::aptos_nft_bridge::Bridge`, - ); - return bridgeResource?.data as TBridgeData; - } - - generateRandomSeed(length: number): string { - let result = ""; - const characters = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - const charactersLength = characters.length; - let counter = 0; - while (counter < length) { - result += characters.charAt(Math.floor(Math.random() * charactersLength)); - counter += 1; - } - return result; - } - - convertToHexString(str: Uint8Array | string): string { - return `0x${Buffer.from(str).toString("hex")}`; - } - - generateClaimDataHash(claimData: TClaimData, user: Ed25519Account): Buffer { - const serializer = new BCS.Serializer(); - serializer.serializeStr(claimData.tokenId); - serializer.serializeBytes(claimData.sourceChain); - serializer.serializeBytes(claimData.destinationChain); - serializer.serializeFixedBytes( - new HexString(user.accountAddress.toString()).toUint8Array(), - ); - serializer.serializeBytes(claimData.sourceNftContractAddress); - serializer.serializeStr(claimData.collection); - serializer.serializeU64(claimData.royaltyPointsNumerator); - serializer.serializeU64(claimData.royaltyPointsDenominator); - serializer.serializeFixedBytes( - new HexString(user.accountAddress.toString()).toUint8Array(), - ); - serializer.serializeStr(claimData.metadata); - serializer.serializeBytes(claimData.transactionHash); - serializer.serializeU256(claimData.amount); - serializer.serializeBytes(claimData.nftType); - serializer.serializeU64(claimData.fee); - serializer.serializeStr(claimData.symbol); - return createHash("SHA256").update(serializer.getBytes()).digest(); - } -} diff --git a/src/handlers/aptos/index.ts b/src/handlers/aptos/index.ts index a6b6c80a..a8ee937d 100644 --- a/src/handlers/aptos/index.ts +++ b/src/handlers/aptos/index.ts @@ -1,7 +1,8 @@ import { Aptos, AptosConfig, isBcsAddress } from "@aptos-labs/ts-sdk"; +import { createSurfClient } from "@thalalabs/surf"; import { HexString } from "aptos"; import { raise } from "../ton"; -import { BridgeClient } from "./bridge-client"; +import { ABI } from "./abi"; import { TAptosHandler, TAptosParams } from "./types"; export function aptosHandler({ @@ -12,7 +13,7 @@ export function aptosHandler({ }: TAptosParams): TAptosHandler { const config = new AptosConfig({ network }); const aptos = new Aptos(config); - const bc = new BridgeClient(aptos, bridge); + const bc = createSurfClient(aptos).useABI(ABI(bridge)); return { validateAddress(address) { @@ -20,9 +21,12 @@ export function aptosHandler({ }, identifier, async getValidatorCount() { - const bd = await bc.getBridgeData(); + const [bd] = await bc.view.validator_count({ + functionArguments: [], + typeArguments: [], + }); if (!bd) throw new Error("Failed to fetch bridge data"); - return bd.validators.data.length; + return Number.parseInt(bd); }, async deployNftCollection(signer, da) { const transaction = await aptos.createCollectionTransaction({ @@ -35,18 +39,13 @@ export function aptosHandler({ signer, transaction, }); - const tx = await aptos.waitForTransaction({ + await aptos.waitForTransaction({ transactionHash: response.hash, options: { checkSuccess: true, }, }); - const alicesCollection = await aptos.getCollectionData({ - creatorAddress: signer.accountAddress, - collectionName: da.name, - minimumLedgerVersion: BigInt(tx.version), - }); - return alicesCollection.collection_id; + return da.name; }, async mintNft(signer, ma) { const transaction = await aptos.mintDigitalAssetTransaction({ @@ -73,18 +72,18 @@ export function aptosHandler({ return ( assets.find( (e) => - e.current_token_data?.collection_id === ma.contract && - e.current_token_data.token_name === ma.name, + e.current_token_data?.current_collection?.collection_name === + ma.contract && e.current_token_data?.token_name === ma.name, )?.token_data_id ?? raise("Failed to send tx") ); }, transform(input) { return { - amount: Number(input.tokenAmount), + amount: BigInt(input.tokenAmount), collection: input.sourceNftContractAddress, description: input.sourceNftContractAddress, destinationChain: Buffer.from(input.destinationChain), - fee: Number(input.fee), + fee: BigInt(input.fee), metadata: input.metadata, uri: input.metadata, royaltyPayeeAddress: HexString.ensure(input.royaltyReceiver), @@ -98,10 +97,20 @@ export function aptosHandler({ tokenId: input.tokenId, transactionHash: Buffer.from(input.transactionHash), sourceNftContractAddress: Buffer.from(input.sourceNftContractAddress), + destination_chain: input.destinationChain, + destinationUserAddress: input.destinationUserAddress as `0x${string}`, + name: input.name, + nft_type: input.nftType, + royaltyPercentage: BigInt(input.royalty), + royaltyReceiver: input.royaltyReceiver as `0x${string}`, + source_chain: input.sourceChain, + source_nft_contract_address: input.sourceNftContractAddress, + token_id: BigInt(input.tokenId), + transaction_hash: input.transactionHash, }; }, approveNft() { - throw new Error("Approval not required in aptos "); + throw new Error("Approval not required in aptos"); }, async getBalance(signer) { const balance = await aptos.getAccountAPTAmount({ @@ -161,12 +170,29 @@ export function aptosHandler({ Buffer.from(e.signature.replace("0x", ""), "hex"), ); const signers = sigs.map((e) => Buffer.from(e.signerAddress)); - const response = await bc.claim1155( - signer, - claimData, - signatures, - signers, - ); + const response = await bc.entry.claim_1155({ + account: signer, + functionArguments: [ + claimData.destinationUserAddress, + claimData.name, + claimData.uri, + claimData.royaltyPercentage, + claimData.royaltyReceiver, + claimData.fee, + signatures, + signers, + claimData.destination_chain, + claimData.source_chain, + claimData.source_nft_contract_address, + claimData.token_id, + claimData.transaction_hash, + claimData.nft_type, + claimData.metadata, + claimData.symbol, + claimData.amount, + ], + typeArguments: [], + }); return { hash() { return response.hash; @@ -179,12 +205,28 @@ export function aptosHandler({ Buffer.from(e.signature.replace("0x", ""), "hex"), ); const signers = sigs.map((e) => Buffer.from(e.signerAddress)); - const response = await bc.claim721( - signer, - claimData, - signatures, - signers, - ); + const response = await bc.entry.claim_721({ + account: signer, + functionArguments: [ + claimData.destinationUserAddress, + claimData.name, + claimData.uri, + claimData.royaltyPercentage, + claimData.royaltyReceiver, + claimData.fee, + signatures, + signers, + claimData.destination_chain, + claimData.source_chain, + claimData.source_nft_contract_address, + claimData.token_id, + claimData.transaction_hash, + claimData.nft_type, + claimData.metadata, + claimData.symbol, + ], + typeArguments: [], + }); return { hash() { return response.hash; @@ -192,15 +234,25 @@ export function aptosHandler({ ret: response, }; }, - async lockNft(signer, sourceNft, destinationChain, _, tokenId) { - const lock = await bc.lock721( - signer, - sourceNft, - tokenId.toString(), - Buffer.from(destinationChain), - 0, - Buffer.from(sourceNft), - ); + async lockNft( + signer, + sourceNft, + destinationChain, + destinationUserAddress, + tokenId, + metadataUri, + ) { + const lock = await bc.entry.lock_721({ + account: signer, + functionArguments: [ + tokenId as `0x${string}`, + destinationChain, + destinationUserAddress, + sourceNft as `0x${string}`, + metadataUri, + ], + typeArguments: [], + }); return { hash() { return lock.hash; @@ -208,16 +260,27 @@ export function aptosHandler({ ret: lock, }; }, - async lockSft(signer, sourceNft, destinationChain, _, tokenId, amount) { - const lock = await bc.lock1155( - signer, - sourceNft, - tokenId.toString(), - Number(amount), - Buffer.from(destinationChain), - 0, - Buffer.from(sourceNft), - ); + async lockSft( + signer, + sourceNft, + destinationChain, + destinationUserAddress, + tokenId, + amount, + metadataUri, + ) { + const lock = await bc.entry.lock_1155({ + account: signer, + functionArguments: [ + tokenId as `0x${string}`, + destinationChain, + destinationUserAddress, + sourceNft as `0x${string}`, + amount, + metadataUri, + ], + typeArguments: [], + }); return { hash() { return lock.hash; diff --git a/src/handlers/aptos/types.ts b/src/handlers/aptos/types.ts index 443fe469..d308bc45 100644 --- a/src/handlers/aptos/types.ts +++ b/src/handlers/aptos/types.ts @@ -1,12 +1,11 @@ import { Account, Aptos, + CommittedTransactionResponse, Network, - PendingTransactionResponse, } from "@aptos-labs/ts-sdk"; import { BridgeStorage } from "../../contractsTypes/evm"; import { DeployNFTCollection, MintNft, TNftChain } from "../types"; -import { TClaimData } from "./bridge-client"; export type TAptosMintArgs = { contract: string; @@ -14,11 +13,29 @@ export type TAptosMintArgs = { uri: string; }; +export type TClaimData = { + destinationUserAddress: `0x${string}`; + name: string; + uri: string; + royaltyPercentage: bigint; + royaltyReceiver: `0x${string}`; + fee: bigint; + destination_chain: string; + source_chain: string; + source_nft_contract_address: string; + token_id: bigint; + transaction_hash: string; + nft_type: string; + metadata: string; + symbol: string; + amount: bigint; +}; + export type TAptosHandler = TNftChain< Account, TClaimData, never, - PendingTransactionResponse, + CommittedTransactionResponse, Aptos > & MintNft & diff --git a/src/handlers/icp/index.ts b/src/handlers/icp/index.ts index 93feb5e6..9c1cd961 100644 --- a/src/handlers/icp/index.ts +++ b/src/handlers/icp/index.ts @@ -291,7 +291,7 @@ export async function icpHandler({ }); const hash = await bcWithSigner.lock_nft( Principal.fromText(sourceNft), - tokenId, + BigInt(tokenId), destinationChain, to, metaDataUri, diff --git a/src/handlers/ton/index.ts b/src/handlers/ton/index.ts index 46b9df20..97ad1a58 100644 --- a/src/handlers/ton/index.ts +++ b/src/handlers/ton/index.ts @@ -317,7 +317,9 @@ export function tonHandler({ const collection = client.open( NftCollection.fromAddress(Address.parse(sourceNft)), ); - const nftItemAddress = await collection.getGetNftAddressByIndex(tokenId); + const nftItemAddress = await collection.getGetNftAddressByIndex( + BigInt(tokenId), + ); if (!nftItemAddress) raise("NFT Does not exist."); const nftItem = client.open(NftItem.fromAddress(nftItemAddress)); const nftItemData = await nftItem.getGetNftData(); @@ -333,7 +335,7 @@ export function tonHandler({ .endCell(), destinationUserAddress: beginCell().storeStringRefTail(to).endCell(), sourceNftContractAddress: Address.parse(sourceNft), - tokenId: tokenId, + tokenId: BigInt(tokenId), metaDataUri: beginCell().storeStringRefTail(metaDataUri).endCell(), })(locked); @@ -346,7 +348,7 @@ export function tonHandler({ { $$type: "Transfer", forward_payload: beginCell() - .storeInt(tokenId, 256) + .storeInt(BigInt(tokenId), 256) .storeAddress(Address.parse(sourceNft)) .storeRef(beginCell().storeStringRefTail(destinationChain)) .storeRef(beginCell().storeStringRefTail(to)) diff --git a/src/handlers/types/chain.ts b/src/handlers/types/chain.ts index a4808ad0..eefc87d3 100644 --- a/src/handlers/types/chain.ts +++ b/src/handlers/types/chain.ts @@ -68,7 +68,7 @@ export type TLockNFT = { sourceNft: string, destinationChain: TSupportedChain, to: string, - tokenId: bigint, + tokenId: string, metaDataUri: string, extraArgs?: ExtraArgs, ) => Promise<{ ret: RetTx; hash: () => string }>; @@ -270,7 +270,7 @@ export type TLockSFT = { sourceNft: string, destinationChain: TSupportedSftChain, to: string, - tokenId: bigint, + tokenId: string, amt: bigint, metaDataUri: string, extraArgs?: ExtraArgs, diff --git a/yarn.lock b/yarn.lock index 38134f6e..619e0058 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1256,6 +1256,11 @@ elliptic "^6.5.4" typedarray-to-buffer "^4.0.0" +"@thalalabs/surf@^1.7.3": + version "1.7.3" + resolved "https://registry.yarnpkg.com/@thalalabs/surf/-/surf-1.7.3.tgz#461ad6b658bb8341c8570ac467108f3e5602d70c" + integrity sha512-bhZzQgVCVGiYaUwuIclseO0UXZJh6YkjfFi8iuKcpclbIfxELOJPPvDKCdsIKYN+BVTw8UeOXQvfuLJYwRszhA== + "@ton/core@=0.56.3": version "0.56.3" resolved "https://registry.yarnpkg.com/@ton/core/-/core-0.56.3.tgz#1162764573abb76032eba70f8497e5cb2ea532ee"