Skip to content

Commit

Permalink
Merge pull request #199 from FindoraNetwork/feat_evm_token_asset_type…
Browse files Browse the repository at this point in the history
…_mainnet

feat: fix the method that caclulates the asset type to use the address from the contract
  • Loading branch information
GiambiHuang committed Jun 2, 2023
2 parents 9b3da22 + df4694a commit e579a61
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 27 deletions.
3 changes: 2 additions & 1 deletion dist/api/evm/evm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { WalletKeypar } from '../keypair';
import { SubmitEvmTxResult } from '../network/types';
import { IWebLinkedInfo } from './web3';
export declare const fraAddressToHashAddress: (address: string) => string;
export declare const hashAddressTofraAddress: (addresss: string) => Promise<string>;
export declare const hashAddressTofraAddressOld: (addresss: string) => Promise<string>;
export declare const hashAddressTofraAddress: (addresss: string, bridgeAddress: string, web3WalletInfo: IWebLinkedInfo) => Promise<string>;
export declare const hashAddressTofraAddressByNFT: (addresss: string, tokenId: string) => Promise<string>;
export declare const fraToBar: (bridgeAddress: string, recipientAddress: string, amount: string, web3WalletInfo: IWebLinkedInfo) => Promise<TransactionReceipt | any>;
export declare const approveToken: (tokenAddress: string, deckAddress: string, price: string, web3WalletInfo: IWebLinkedInfo) => Promise<import("web3-eth").TransactionReceipt>;
Expand Down
28 changes: 24 additions & 4 deletions dist/api/evm/evm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/api/evm/evm.js.map

Large diffs are not rendered by default.

11 changes: 2 additions & 9 deletions dist/run.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/run.js.map

Large diffs are not rendered by default.

28 changes: 24 additions & 4 deletions src/api/evm/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import { SubmitEvmTxResult } from '../network/types';
import * as AssetApi from '../sdkAsset';
import * as Transaction from '../transaction';
import {
IWebLinkedInfo,
calculationDecimalsAmount,
getErc20Contract,
getFNSRegistryContract,
getNameResolverContract,
getNFT1155Contract,
getNFT721Contract,
getNameResolverContract,
getSimBridgeContract,
getWeb3,
IWebLinkedInfo,
} from './web3';

export const fraAddressToHashAddress = (address: string) => {
Expand All @@ -35,7 +35,7 @@ export const fraAddressToHashAddress = (address: string) => {
return '0x' + Buffer.from(data).toString('hex');
};

export const hashAddressTofraAddress = async (addresss: string) => {
export const hashAddressTofraAddressOld = async (addresss: string) => {
const ledger = await getLedger();

const tokenAddress = ethereumjsAbi.rawEncode(
Expand All @@ -45,7 +45,27 @@ export const hashAddressTofraAddress = async (addresss: string) => {

const tokenAddressHex = Web3.utils.keccak256(`0x${tokenAddress.toString('hex')}`);

return ledger.asset_type_from_jsvalue(Web3.utils.hexToBytes(tokenAddressHex));
const assetType = ledger.asset_type_from_jsvalue(Web3.utils.hexToBytes(tokenAddressHex));

return assetType;
};

// uses contract to compute the proper asset type for the token
export const hashAddressTofraAddress = async (
addresss: string,
bridgeAddress: string,
web3WalletInfo: IWebLinkedInfo,
): Promise<string> => {
const ledger = await getLedger();

const web3 = getWeb3(web3WalletInfo.rpcUrl);
const contract = getSimBridgeContract(web3, bridgeAddress);

const tokenAddressHexA = await contract.methods.computeERC20AssetType(addresss).call();
// const tokenAddressHex = Web3.utils.keccak256(tokenAddressHexA);

const assetType = ledger.asset_type_from_jsvalue(Web3.utils.hexToBytes(tokenAddressHexA));
return assetType;
};

export const hashAddressTofraAddressByNFT = async (addresss: string, tokenId: string) => {
Expand Down
10 changes: 3 additions & 7 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
import S3 from 'aws-sdk/clients/s3';
import dotenv from 'dotenv';
import sleep from 'sleep-promise';
import Sdk from './Sdk';
import { Account, Asset, Evm, Keypair, Network, Staking, Transaction } from './api';
import * as NetworkTypes from './api/network/types';
import { waitForBlockChange } from './evm/testHelpers';
import Sdk from './Sdk';
import { toWei } from './services/bigNumber';
import { FileCacheProvider, MemoryCacheProvider } from './services/cacheStore/providers';
import * as Fee from './services/fee';
Expand Down Expand Up @@ -1300,15 +1300,13 @@ async function approveToken() {
// chainId: 1111, // 2154,
// account: '0x72488bAa718F52B76118C79168E55c209056A2E6',
// };

// const result = await Evm.approveToken(
// '0xfd66Bd7839Ed3AeC90f5F54ab2E11E7bF2FF4be5', // token
// '0xaBA48f89BDa0C2C57c0E68056E445D1984EA8664', // 授权 prism->ledger
// '100',
// webLinkedInfo,
// );
// console.log(result.transactionHash);

// const result1 = await Evm.frc20ToBar(
// '0x7Ed73c1D16590Bc2810F2C510Cd0923e34E3F592', // bridge
// 'fra1nqkz745gc6rcv2htrvv4yyey2482kw4awrjzsnw4nrkp99lxw64qjsrd6v',
Expand All @@ -1323,11 +1321,9 @@ async function approveToken() {
// true,
// webLinkedInfo.account,
// );

// console.log(result1);

const addr = await Evm.hashAddressTofraAddress('0xfd66Bd7839Ed3AeC90f5F54ab2E11E7bF2FF4be5');
console.log(addr);
// const addr = await Evm.hashAddressTofraAddress('0xfd66Bd7839Ed3AeC90f5F54ab2E11E7bF2FF4be5');
// console.log(addr);
}

async function testCommitment() {
Expand Down

0 comments on commit e579a61

Please sign in to comment.