Skip to content

Commit

Permalink
feat(core): add evmtx signer on convert
Browse files Browse the repository at this point in the history
  • Loading branch information
lykalabrada committed Sep 27, 2023
1 parent e187749 commit a2e2275
Show file tree
Hide file tree
Showing 6 changed files with 744 additions and 361 deletions.
3 changes: 3 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ module.exports = function (api) {
},
],
"@babel/plugin-proposal-export-namespace-from",
"@babel/plugin-transform-private-methods",
"@babel/plugin-transform-class-properties",
"@babel/plugin-transform-private-property-in-object",
"react-native-reanimated/plugin",
];

Expand Down
59 changes: 59 additions & 0 deletions mobile-app/app/api/transaction/transfer_domain.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { translate } from "@translations";
import BigNumber from "bignumber.js";
import { ethers, utils, BigNumber as BN } from "ethers";
// import { providers } from "ethers"; // TODO: Uncomment
import { DfTxSigner } from "@waveshq/walletkit-ui/dist/store";
import { WhaleWalletAccount } from "@defichain/whale-api-wallet";
import {
CTransactionSegWit,
TransactionSegWit,
} from "@defichain/jellyfish-transaction";
import { ConvertDirection } from "@screens/enum";
import TransferDomain from "../../contracts/TransferDomain.json";

const TRANSFER_DOMAIN_TYPE = {
DVM: 2,
Expand Down Expand Up @@ -41,6 +44,54 @@ export async function transferDomainSigner(
? [TRANSFER_DOMAIN_TYPE.EVM, TRANSFER_DOMAIN_TYPE.DVM]
: [TRANSFER_DOMAIN_TYPE.DVM, TRANSFER_DOMAIN_TYPE.EVM];

/**
* TODO: Start of EvmTx signer here
* */
const TD_CONTRACT_ADDR = "0x0000000000000000000000000000000000000302";
const tdIFace = new utils.Interface(TransferDomain.abi);

const from =
convertDirection === ConvertDirection.evmToDvm
? await account.getEvmAddress()
: await account.getAddress();
const to = TD_CONTRACT_ADDR;
const evmAmount = BN.from(amount.toString()).toHexString(); // "0x29a2241af62c0000"; // 3_000_000_000_000_000_000
const native = await account.getAddress();
const data = tdIFace.encodeFunctionData("transfer", [
from,
to,
evmAmount,
native,
]);
// const ethRpc = new providers.JsonRpcProvider("http://localhost:19551"); // TODO: Uncomment
const privateKey = await account.privateKey();
const wallet = new ethers.Wallet(privateKey);

/* TODO: Figure out CORS issue when using the ethRpc
const tx: any = {
to: TD_CONTRACT_ADDR,
nonce: await ethRpc.getTransactionCount(from),
value: 0,
chainId: (await ethRpc.getNetwork()).chainId,
data: data,
gasLimit: 100_000,
gasPrice: (await ethRpc.getFeeData()).gasPrice, // base fee
}; */

const tx: any = {
to: TD_CONTRACT_ADDR,
nonce: 0,
value: 0,
chainId: 1133,
data: data,
gasLimit: 100_000,
gasPrice: 1000, // base fee
};

const evmtxSigned = (await wallet.signTransaction(tx)).substring(2); // rm prefix `0x`
const evmTx =
new Uint8Array(Buffer.from(evmtxSigned, "hex")) || new Uint8Array([]);

const signed: TransactionSegWit = await builder.account.transferDomain(
{
items: [
Expand All @@ -52,6 +103,10 @@ export async function transferDomainSigner(
amount,
},
domain: srcDomain,
data:
convertDirection === ConvertDirection.evmToDvm
? evmTx
: new Uint8Array([]),
},
dst: {
address: dstScript,
Expand All @@ -60,6 +115,10 @@ export async function transferDomainSigner(
amount,
},
domain: dstDomain,
data:
convertDirection === ConvertDirection.dvmToEvm
? evmTx
: new Uint8Array([]),
},
},
],
Expand Down
150 changes: 150 additions & 0 deletions mobile-app/app/contracts/TransferDomain.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "TransferDomain",
"sourceName": "contracts/TransferDomain.sol",
"abi": [
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "string",
"name": "nativeAddress",
"type": "string"
}
],
"name": "NativeAddress",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "from",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "to",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "Transfer",
"type": "event"
},
{
"inputs": [
{
"internalType": "address",
"name": "contractAddress",
"type": "address"
},
{
"internalType": "address",
"name": "from",
"type": "address"
},
{
"internalType": "address payable",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"internalType": "string",
"name": "nativeAddress",
"type": "string"
}
],
"name": "bridgeDST20",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "decimals",
"outputs": [
{
"internalType": "uint8",
"name": "",
"type": "uint8"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "name",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "symbol",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "from",
"type": "address"
},
{
"internalType": "address payable",
"name": "to",
"type": "address"
},
{
"internalType": "uint256",
"name": "amount",
"type": "uint256"
},
{
"internalType": "string",
"name": "nativeAddress",
"type": "string"
}
],
"name": "transfer",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
],
"bytecode": "0x608060405234801561001057600080fd5b506109b8806100206000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c806306fdde031461005c578063313ce5671461007a5780635a4623b61461009857806395d89b41146100b4578063d57b2826146100d2575b600080fd5b6100646100ee565b6040516100719190610454565b60405180910390f35b61008261012b565b60405161008f9190610492565b60405180910390f35b6100b260048036038101906100ad91906106c8565b610134565b005b6100bc610227565b6040516100c99190610454565b60405180910390f35b6100ec60048036038101906100e7919061075f565b610264565b005b60606040518060400160405280600381526020017f4446490000000000000000000000000000000000000000000000000000000000815250905090565b60006012905090565b3073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16146101e9578473ffffffffffffffffffffffffffffffffffffffff166323b872dd8585856040518463ffffffff1660e01b81526004016101a49392919061085f565b6020604051808303816000875af11580156101c3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101e791906108ce565b505b7f12c780c9fb4c8747cd81626cec0e8958e858fb859cc93ddb04a45d42765596f2816040516102189190610454565b60405180910390a15050505050565b60606040518060400160405280600381526020017f4446490000000000000000000000000000000000000000000000000000000000815250905090565b3073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161461032257814710156102da576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102d190610947565b60405180910390fd5b8273ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f19350505050158015610320573d6000803e3d6000fd5b505b8273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161037f9190610967565b60405180910390a37f12c780c9fb4c8747cd81626cec0e8958e858fb859cc93ddb04a45d42765596f2816040516103b69190610454565b60405180910390a150505050565b600081519050919050565b600082825260208201905092915050565b60005b838110156103fe5780820151818401526020810190506103e3565b60008484015250505050565b6000601f19601f8301169050919050565b6000610426826103c4565b61043081856103cf565b93506104408185602086016103e0565b6104498161040a565b840191505092915050565b6000602082019050818103600083015261046e818461041b565b905092915050565b600060ff82169050919050565b61048c81610476565b82525050565b60006020820190506104a76000830184610483565b92915050565b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006104ec826104c1565b9050919050565b6104fc816104e1565b811461050757600080fd5b50565b600081359050610519816104f3565b92915050565b600061052a826104c1565b9050919050565b61053a8161051f565b811461054557600080fd5b50565b60008135905061055781610531565b92915050565b6000819050919050565b6105708161055d565b811461057b57600080fd5b50565b60008135905061058d81610567565b92915050565b600080fd5b600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6105d58261040a565b810181811067ffffffffffffffff821117156105f4576105f361059d565b5b80604052505050565b60006106076104ad565b905061061382826105cc565b919050565b600067ffffffffffffffff8211156106335761063261059d565b5b61063c8261040a565b9050602081019050919050565b82818337600083830152505050565b600061066b61066684610618565b6105fd565b90508281526020810184848401111561068757610686610598565b5b610692848285610649565b509392505050565b600082601f8301126106af576106ae610593565b5b81356106bf848260208601610658565b91505092915050565b600080600080600060a086880312156106e4576106e36104b7565b5b60006106f28882890161050a565b95505060206107038882890161050a565b945050604061071488828901610548565b93505060606107258882890161057e565b925050608086013567ffffffffffffffff811115610746576107456104bc565b5b6107528882890161069a565b9150509295509295909350565b60008060008060808587031215610779576107786104b7565b5b60006107878782880161050a565b945050602061079887828801610548565b93505060406107a98782880161057e565b925050606085013567ffffffffffffffff8111156107ca576107c96104bc565b5b6107d68782880161069a565b91505092959194509250565b6107eb816104e1565b82525050565b6000819050919050565b600061081661081161080c846104c1565b6107f1565b6104c1565b9050919050565b6000610828826107fb565b9050919050565b600061083a8261081d565b9050919050565b61084a8161082f565b82525050565b6108598161055d565b82525050565b600060608201905061087460008301866107e2565b6108816020830185610841565b61088e6040830184610850565b949350505050565b60008115159050919050565b6108ab81610896565b81146108b657600080fd5b50565b6000815190506108c8816108a2565b92915050565b6000602082840312156108e4576108e36104b7565b5b60006108f2848285016108b9565b91505092915050565b7f496e73756666696369656e7420636f6e74726163742062616c616e6365000000600082015250565b6000610931601d836103cf565b915061093c826108fb565b602082019050919050565b6000602082019050818103600083015261096081610924565b9050919050565b600060208201905061097c6000830184610850565b9291505056fea26469706673582212200b351e22b19ac8482db5acafcaedfb8b91e766506933222072f36e5417e7bbf864736f6c63430008130033",
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100575760003560e01c806306fdde031461005c578063313ce5671461007a5780635a4623b61461009857806395d89b41146100b4578063d57b2826146100d2575b600080fd5b6100646100ee565b6040516100719190610454565b60405180910390f35b61008261012b565b60405161008f9190610492565b60405180910390f35b6100b260048036038101906100ad91906106c8565b610134565b005b6100bc610227565b6040516100c99190610454565b60405180910390f35b6100ec60048036038101906100e7919061075f565b610264565b005b60606040518060400160405280600381526020017f4446490000000000000000000000000000000000000000000000000000000000815250905090565b60006012905090565b3073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16146101e9578473ffffffffffffffffffffffffffffffffffffffff166323b872dd8585856040518463ffffffff1660e01b81526004016101a49392919061085f565b6020604051808303816000875af11580156101c3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101e791906108ce565b505b7f12c780c9fb4c8747cd81626cec0e8958e858fb859cc93ddb04a45d42765596f2816040516102189190610454565b60405180910390a15050505050565b60606040518060400160405280600381526020017f4446490000000000000000000000000000000000000000000000000000000000815250905090565b3073ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff161461032257814710156102da576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102d190610947565b60405180910390fd5b8273ffffffffffffffffffffffffffffffffffffffff166108fc839081150290604051600060405180830381858888f19350505050158015610320573d6000803e3d6000fd5b505b8273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8460405161037f9190610967565b60405180910390a37f12c780c9fb4c8747cd81626cec0e8958e858fb859cc93ddb04a45d42765596f2816040516103b69190610454565b60405180910390a150505050565b600081519050919050565b600082825260208201905092915050565b60005b838110156103fe5780820151818401526020810190506103e3565b60008484015250505050565b6000601f19601f8301169050919050565b6000610426826103c4565b61043081856103cf565b93506104408185602086016103e0565b6104498161040a565b840191505092915050565b6000602082019050818103600083015261046e818461041b565b905092915050565b600060ff82169050919050565b61048c81610476565b82525050565b60006020820190506104a76000830184610483565b92915050565b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006104ec826104c1565b9050919050565b6104fc816104e1565b811461050757600080fd5b50565b600081359050610519816104f3565b92915050565b600061052a826104c1565b9050919050565b61053a8161051f565b811461054557600080fd5b50565b60008135905061055781610531565b92915050565b6000819050919050565b6105708161055d565b811461057b57600080fd5b50565b60008135905061058d81610567565b92915050565b600080fd5b600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6105d58261040a565b810181811067ffffffffffffffff821117156105f4576105f361059d565b5b80604052505050565b60006106076104ad565b905061061382826105cc565b919050565b600067ffffffffffffffff8211156106335761063261059d565b5b61063c8261040a565b9050602081019050919050565b82818337600083830152505050565b600061066b61066684610618565b6105fd565b90508281526020810184848401111561068757610686610598565b5b610692848285610649565b509392505050565b600082601f8301126106af576106ae610593565b5b81356106bf848260208601610658565b91505092915050565b600080600080600060a086880312156106e4576106e36104b7565b5b60006106f28882890161050a565b95505060206107038882890161050a565b945050604061071488828901610548565b93505060606107258882890161057e565b925050608086013567ffffffffffffffff811115610746576107456104bc565b5b6107528882890161069a565b9150509295509295909350565b60008060008060808587031215610779576107786104b7565b5b60006107878782880161050a565b945050602061079887828801610548565b93505060406107a98782880161057e565b925050606085013567ffffffffffffffff8111156107ca576107c96104bc565b5b6107d68782880161069a565b91505092959194509250565b6107eb816104e1565b82525050565b6000819050919050565b600061081661081161080c846104c1565b6107f1565b6104c1565b9050919050565b6000610828826107fb565b9050919050565b600061083a8261081d565b9050919050565b61084a8161082f565b82525050565b6108598161055d565b82525050565b600060608201905061087460008301866107e2565b6108816020830185610841565b61088e6040830184610850565b949350505050565b60008115159050919050565b6108ab81610896565b81146108b657600080fd5b50565b6000815190506108c8816108a2565b92915050565b6000602082840312156108e4576108e36104b7565b5b60006108f2848285016108b9565b91505092915050565b7f496e73756666696369656e7420636f6e74726163742062616c616e6365000000600082015250565b6000610931601d836103cf565b915061093c826108fb565b602082019050919050565b6000602082019050818103600083015261096081610924565b9050919050565b600060208201905061097c6000830184610850565b9291505056fea26469706673582212200b351e22b19ac8482db5acafcaedfb8b91e766506933222072f36e5417e7bbf864736f6c63430008130033",
"linkReferences": {},
"deployedLinkReferences": {}
}

2 changes: 1 addition & 1 deletion mobile-app/app/hooks/useWalletAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function useWalletAddress(): {
const account = wallet.get(i);
const dvm = await account.getAddress();
// TODO (Harsh) replace it with getEvmAddress
const evm = "evmaddress"; // await account.getEvmAddress();
const evm = await account.getEvmAddress();
addresses.push({ dvm, evm });
}
return addresses;
Expand Down
Loading

0 comments on commit a2e2275

Please sign in to comment.