Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/aptos updates #2

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 71 additions & 68 deletions src/handlers/aptos/bridge-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import {
MINT_MODULE,
} from "./constants";

type TCollectionCounterObj = {
key: string;
value: string;
type TAptosMapObj<K, V> = {
key: K;
value: V;
};

type TValidatorsObj = {
Expand All @@ -27,24 +27,26 @@ type TValidatorsObj = {
};

export type TClaimData = {
collection: string;
description: string;
destinationUserAddress: HexString;
name: string;
symbol: string;
amount: number;
uri: string;
iconUri: string;
projectUri: string;
royaltyPointsNumerator: number;
royaltyPointsDenominator: number;
royaltyPercentage: number;
royaltyPayeeAddress: HexString;
fee: number;
sourceChain: Uint8Array;
sourceNftContractAddress: Uint8Array;
destinationChain: Uint8Array;
sourceNftContractAddress: Uint8Array;
transactionHash: Uint8Array;
tokenId: string;
tokenId: number;
nftType: Uint8Array;
metadata: string;
lockTxChain: Uint8Array;
};

type TCollectionNFTObj = {
collection_address: string;
token_id: string;
};

type TBridgeData = {
Expand All @@ -55,10 +57,10 @@ type TBridgeData = {
handle: string;
};
nft_collection_tokens: {
handle: string;
data: TAptosMapObj<TCollectionNFTObj, string>[];
};
nft_collections_counter: {
data: TCollectionCounterObj[];
data: TAptosMapObj<string, string>[];
};
nfts_counter: string;
original_to_duplicate_mapping: {
Expand Down Expand Up @@ -136,22 +138,20 @@ export class BridgeClient {

async lock721(
owner: Account,
collection: string,
name: string,
token_address: HexString,
destination_chain: Uint8Array,
token_id: number,
source_nft_contract_address: Uint8Array,
destination_user_address: string,
collection_address: HexString,
) {
const transaction = await this.aptosClient.transaction.build.simple({
sender: owner.accountAddress,
data: {
function: `${this.address}::${BRIDGE_MODULE}::${BRIDGE_FUNCTIONS.Lock721}`,
functionArguments: [
collection,
name,
token_address.toString(),
destination_chain,
token_id,
source_nft_contract_address,
destination_user_address,
collection_address.toString(),
],
},
});
Expand All @@ -164,24 +164,22 @@ export class BridgeClient {

async lock1155(
owner: Account,
collection: string,
name: string,
amount: number,
token_address: HexString,
destination_chain: Uint8Array,
token_id: number,
source_nft_contract_address: Uint8Array,
destination_user_address: string,
collection_address: HexString,
amount: number,
) {
const transaction = await this.aptosClient.transaction.build.simple({
sender: owner.accountAddress,
data: {
function: `${this.address}::${BRIDGE_MODULE}::${BRIDGE_FUNCTIONS.Lock1155}`,
functionArguments: [
collection,
name,
amount,
token_address.toString(),
destination_chain,
token_id,
source_nft_contract_address,
destination_user_address,
collection_address.toString(),
amount,
],
},
});
Expand All @@ -195,22 +193,20 @@ export class BridgeClient {
async claim721(
sender: Account,
{
collection,
description,
destinationUserAddress,
name,
symbol,
uri,
royaltyPointsNumerator,
royaltyPointsDenominator,
royaltyPercentage,
royaltyPayeeAddress,
fee,

sourceChain,
sourceNftContractAddress,
destinationChain,
transactionHash,
tokenId,
nftType,
metadata,
lockTxChain,
}: TClaimData,
signatures: Uint8Array[],
publicKeys: Uint8Array[],
Expand All @@ -220,11 +216,9 @@ export class BridgeClient {
data: {
function: `${this.address}::${BRIDGE_MODULE}::${BRIDGE_FUNCTIONS.Claim721}`,
functionArguments: [
collection,
description,
uri,
royaltyPointsNumerator,
royaltyPointsDenominator,
destinationUserAddress.toString(),
name,
royaltyPercentage,
royaltyPayeeAddress.toString(),
fee,
signatures,
Expand All @@ -237,9 +231,8 @@ export class BridgeClient {
nftType,
metadata,
symbol,
// amount,
// iconUri,
// projectUri,
0,
lockTxChain,
],
},
});
Expand All @@ -253,15 +246,10 @@ export class BridgeClient {
async claim1155(
sender: Account,
{
collection,
description,
destinationUserAddress,
name,
symbol,
amount,
uri,
iconUri,
projectUri,
royaltyPointsNumerator,
royaltyPointsDenominator,
royaltyPercentage,
royaltyPayeeAddress,
fee,
sourceChain,
Expand All @@ -271,6 +259,8 @@ export class BridgeClient {
tokenId,
nftType,
metadata,
amount,
lockTxChain,
}: TClaimData,
signatures: Uint8Array[],
publicKeys: Uint8Array[],
Expand All @@ -280,11 +270,9 @@ export class BridgeClient {
data: {
function: `${this.address}::${BRIDGE_MODULE}::${BRIDGE_FUNCTIONS.Claim1155}`,
functionArguments: [
collection,
description,
uri,
royaltyPointsNumerator,
royaltyPointsDenominator,
destinationUserAddress.toString(),
name,
royaltyPercentage,
royaltyPayeeAddress.toString(),
fee,
signatures,
Expand All @@ -298,8 +286,7 @@ export class BridgeClient {
metadata,
symbol,
amount,
iconUri,
projectUri,
lockTxChain,
],
},
});
Expand Down Expand Up @@ -439,27 +426,43 @@ export class BridgeClient {
return `0x${Buffer.from(str).toString("hex")}`;
}

generateClaimDataHash(claimData: TClaimData, user: Ed25519Account): Buffer {
base64ToUint8Array(base64String: string): Uint8Array {
const binaryString = atob(base64String);
const len = binaryString.length;
const bytes = new Uint8Array(len);
for (let i = 0; i < len; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
return bytes;
}

generateClaimDataHash(claimData: TClaimData): Buffer {
const serializer = new BCS.Serializer();
serializer.serializeStr(claimData.tokenId);
serializer.serializeU256(claimData.tokenId);
serializer.serializeBytes(claimData.sourceChain);
serializer.serializeBytes(claimData.destinationChain);
serializer.serializeFixedBytes(
new HexString(user.accountAddress.toString()).toUint8Array(),
claimData.destinationUserAddress.toUint8Array(),
);
serializer.serializeBytes(claimData.sourceNftContractAddress);
serializer.serializeStr(claimData.collection);
serializer.serializeU64(claimData.royaltyPointsNumerator);
serializer.serializeU64(claimData.royaltyPointsDenominator);
serializer.serializeStr(claimData.name);
serializer.serializeU64(claimData.royaltyPercentage);
serializer.serializeFixedBytes(
new HexString(user.accountAddress.toString()).toUint8Array(),
claimData.royaltyPayeeAddress.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);
serializer.serializeBytes(claimData.lockTxChain);
return createHash("SHA256").update(serializer.getBytes()).digest();
}

hexStringToUint8Array(hexString: string): Uint8Array {
return new Uint8Array(
hexString.match(/.{1,2}/g)?.map((byte) => parseInt(byte, 16)) ?? [],
);
}
}
4 changes: 2 additions & 2 deletions src/handlers/aptos/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ enum CONTRACT_ERROR_CODES {

const CHAIN_ID = "APTOS";

const CLAIM_FEE_5_APT = 5 * 10 ** 8;
const CLAIM_FEE_20_APT = 20 * 10 ** 8;
const CLAIM_FEE_POINT_1_APT = 0.1 * 10 ** 8;

export {
Expand All @@ -52,6 +52,6 @@ export {
CHAIN_ID,
MINT_MODULE,
MINT_FUNCTIONS,
CLAIM_FEE_5_APT,
CLAIM_FEE_20_APT,
CLAIM_FEE_POINT_1_APT,
};
Loading