-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add `@therootnetwork/evm` package * Refactor utils * Update `evm` examples * Prettier format * Singularize `precompile`
- Loading branch information
1 parent
95f709b
commit 8c36205
Showing
16 changed files
with
65 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,18 @@ | ||
import { getPublicProviderUrl } from "@therootnetwork/api"; | ||
import { Contract, getDefaultProvider, Wallet } from "ethers"; | ||
import { getAddress } from "ethers/lib/utils"; | ||
import { assetIdToERC20Address, ERC20_ABI } from "@therootnetwork/evm"; | ||
import { Contract } from "ethers"; | ||
|
||
export const assetIdToERC20ContractAddress = (assetId: string | number): string => { | ||
const asset_id_hex = (+assetId).toString(16).padStart(8, "0"); | ||
return getAddress(`0xCCCCCCCC${asset_id_hex.toUpperCase()}000000000000000000000000`); | ||
}; | ||
|
||
export const ERC20_ABI = [ | ||
"event Transfer(address indexed from, address indexed to, uint256 value)", | ||
"event Approval(address indexed owner, address indexed spender, uint256 value)", | ||
"function approve(address spender, uint256 amount) public returns (bool)", | ||
"function allowance(address owner, address spender) public view returns (uint256)", | ||
"function balanceOf(address who) public view returns (uint256)", | ||
"function name() public view returns (string memory)", | ||
"function symbol() public view returns (string memory)", | ||
"function decimals() public view returns (uint8)", | ||
"function totalSupply() external view returns (uint256)", | ||
"function transfer(address who, uint256 amount)", | ||
"function transferFrom(address from, address to, uint256 amount)", | ||
]; | ||
import { getSignerWallet } from "./getSignerWallet"; | ||
|
||
export const getERC20PrecompileForAssetId = (privateKey: string, assetId: string | number) => { | ||
const wallet = new Wallet(privateKey, getDefaultProvider(getPublicProviderUrl("porcini"))); | ||
const getERC20PrecompileForAssetId = (privateKey: string, assetId: string | number) => { | ||
const wallet = getSignerWallet(privateKey); | ||
|
||
const erc20PrecompileAddress = assetIdToERC20ContractAddress(assetId); | ||
const erc20PrecompileAddress = assetIdToERC20Address(assetId); | ||
|
||
// Create precompiles contract | ||
// Create precompile contract | ||
return { | ||
erc20Precompile: new Contract(erc20PrecompileAddress, ERC20_ABI, wallet), | ||
wallet, | ||
}; | ||
}; | ||
|
||
export { ERC20_ABI, getERC20PrecompileForAssetId }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,26 @@ | ||
import { Contract, Wallet } from "ethers"; | ||
import { getAddress } from "ethers/lib/utils"; | ||
import { collectionIdToERC721Address, ERC721_PRECOMPILE_ABI } from "@therootnetwork/evm"; | ||
import { Contract } from "ethers"; | ||
|
||
import { getEthersProvider } from "./getEthersProvider"; | ||
import { getSignerWallet } from "./getSignerWallet"; | ||
|
||
export const collectionIdToERC721Address = (collectionId: string | number): string => { | ||
const collection_id_hex = (+collectionId).toString(16).padStart(8, "0"); | ||
return getAddress(`0xAAAAAAAA${collection_id_hex.toUpperCase()}000000000000000000000000`); | ||
}; | ||
|
||
const OWNABLE_ABI = [ | ||
"event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)", | ||
|
||
"function owner() public view returns (address)", | ||
"function renounceOwnership()", | ||
"function transferOwnership(address owner)", | ||
]; | ||
|
||
export const ERC721_PRECOMPILE_ABI = [ | ||
// ERC721 | ||
"event Transfer(address indexed from, address indexed to, uint256 indexed tokenId)", | ||
"event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId)", | ||
"event ApprovalForAll(address indexed owner, address indexed operator, bool approved)", | ||
|
||
"function balanceOf(address who) public view returns (uint256)", | ||
"function ownerOf(uint256 tokenId) public view returns (address)", | ||
"function safeTransferFrom(address from, address to, uint256 tokenId)", | ||
"function transferFrom(address from, address to, uint256 tokenId)", | ||
"function approve(address to, uint256 tokenId)", | ||
"function getApproved(uint256 tokenId) public view returns (address)", | ||
"function setApprovalForAll(address operator, bool _approved)", | ||
"function isApprovedForAll(address owner, address operator) public view returns (bool)", | ||
|
||
// ERC721 Metadata | ||
"function name() public view returns (string memory)", | ||
"function symbol() public view returns (string memory)", | ||
"function tokenURI(uint256 tokenId) public view returns (string memory)", | ||
|
||
// Root specific precompiles | ||
"event MaxSupplyUpdated(uint32 maxSupply)", | ||
"event BaseURIUpdated(string baseURI)", | ||
|
||
"function totalSupply() external view returns (uint256)", | ||
"function mint(address owner, uint32 quantity)", | ||
"function setMaxSupply(uint32 maxSupply)", | ||
"function setBaseURI(bytes baseURI)", | ||
"function ownedTokens(address who, uint16 limit, uint32 cursor) public view returns (uint32, uint32, uint32[] memory)", | ||
|
||
// Ownable | ||
...OWNABLE_ABI, | ||
]; | ||
|
||
export const getERC721Precompile = ( | ||
const getERC721Precompile = ( | ||
privateKey: string, | ||
precompileAddress: string, | ||
collectionId: string | number | null | ||
) => { | ||
const wallet = new Wallet(privateKey, getEthersProvider("porcini")); | ||
const wallet = getSignerWallet(privateKey); | ||
|
||
const erc721PrecompileAddress = precompileAddress | ||
? precompileAddress | ||
: collectionIdToERC721Address(collectionId as string); | ||
|
||
const erc721Precompile = new Contract(erc721PrecompileAddress, ERC721_PRECOMPILE_ABI, wallet); | ||
|
||
// Create precompiles contract | ||
// Create precompile contract | ||
return { | ||
erc721Precompile, | ||
wallet, | ||
}; | ||
}; | ||
|
||
export function getSignerWallet(privateKey: string) { | ||
return new Wallet(privateKey, getEthersProvider("porcini")); | ||
} | ||
export { ERC721_PRECOMPILE_ABI, getERC721Precompile }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { getPublicProviderUrl } from "@therootnetwork/evm"; | ||
import { getDefaultProvider, Wallet } from "ethers"; | ||
|
||
export function getSignerWallet(privateKey: string) { | ||
return new Wallet(privateKey, getDefaultProvider(getPublicProviderUrl("porcini"))); | ||
} |
Oops, something went wrong.