Main Functions
factory
This feature makes diamond contract deployment easier. Each time this function is executed, a new integrated abi is created.
async factory(
-
artifacts: The name of diamond that is trying to deploy artifact.
-
cut data: Diamond cut data for diamond.
( {key: string, data: [ facet artifacts ]} )
-
init args: Values for diamond args for initializing.
);
import { diamond } from '@coinmeca/ethers';
function deploy() {
const contract = await diamond.factory(
'contracts/myapp/MyDiamond.sol:MyDiamond',
[
// If your diamond contract's constructor has other args.
MyDiamondArg1, // parameter's order has to match with
MyDiamondArg2, // your diamond contract's args order of a constructor.
// Diamond cut, args data.
[
key: 'myDiamond.app',
data: [
'contracts/myapp/facets/Mint.sol:Mint',
'contracts/myapp/facets/Burn.sol:Mint',
'contracts/myapp/facets/Apporval.sol:Apporval',
'contracts/myapp/facets/Transfer.sol:Transfer'
]
],
{
owner: addressOf.owner,
init: addressOf.initContract,
initCalldata: addressOf.initData
}
]
);
}
abi
( artifactName: string ) => void
If you pass the diamond's artifact name, it finds the facets that need to be integrated into the specific diamond in a path and creates an integrated artifact.
import { diamond } from "@coinmeca/ethers";
await diamond.abi("contracts/myapp/MyDiamond.sol:MyDiamond");
cut
lightweight-diamond If you pass in diamond cut information that matches the configuration, the diamond cut data needed when factory the diamond is generated and returned.
import { diamond } from "@coinmeca/ethers";
await diamond.cut([
{
key: "myDiamond.app",
data: [
"contracts/myapp/facets/Mint.sol:Mint",
"contracts/myapp/facets/Burn.sol:Mint",
"contracts/myapp/facets/Apporval.sol:Apporval",
"contracts/myapp/facets/Transfer.sol:Transfer",
],
},
]);
Or it can be used like this with existing ethers library.
import { diamond } from "@coinmeca/ethers";
const deploy = () =>{
await ethers.getContractAt(
"myDiamond",
[
{
key: "myDiamond.app",
data: [
"contracts/myapp/facets/Mint.sol:Mint",
"contracts/myapp/facets/Burn.sol:Mint",
"contracts/myapp/facets/Apporval.sol:Apporval",
"contracts/myapp/facets/Transfer.sol:Transfer",
],
},
],
{
owner: addressOf.owner,
init: addressOf.initContract,
initCalldata: addressOf.initData
}
);
}
If the situation needs diamond abi when using the existing ethers library, it also can be used like this.
import { diamond } from "@coinmeca/ethers";
const deploy = () =>{
await ethers.getContractAt(
"myDiamond",
[
{
key: "myDiamond.app",
data: [
"contracts/myapp/facets/Mint.sol:Mint",
"contracts/myapp/facets/Burn.sol:Mint",
"contracts/myapp/facets/Apporval.sol:Apporval",
"contracts/myapp/facets/Transfer.sol:Transfer",
],
},
],
{
owner: addressOf.owner,
init: addressOf.initContract,
initCalldata: addressOf.initData
}
);
}
getAllFunctionNames
( BaseContract || {contract: BaseContract} )
Returns the function name held in the currently deployed contract in the form of a string array.
import { getAllFunctionNames } from "@coinmeca/ethers/diamond";
getAllFunctionNames(baseContract);
[
"function owner() returns (address)",
"function setOwner(address)",
"function setAccess(address,bool)",
"function checkAccess(address) view returns (bool)",
"function setInterface(bytes4,bool)",
"function facet(bytes4) returns (address)",
"function facetAddress(bytes4) view returns (address)",
"function facetAddresses() view returns (address[])",
];
getAllFunctionSelectors
( BaseContract || {contract: BaseContract} )
Returns the selector (signature) of the function contained in the currently deployed contract in the form of a string array.
import { getAllFunctionSelectors } from "@coinmeca/ethers/diamond";
getAllFunctionSelectors(baseContract);
["0x466a0146", "0x851642bf", "0xb1530104", "0x82431dab", "0xcdffacc6", "0x52ef6b2c", "0xf69f473c", "0xadfca15e"];
getSelectors
( BaseContract || {contract: BaseContract} )
Returns an object to which the selector property and get and remove functions for handling it are added in the form of a string array with selectors (signatures) of all functions actually owned by the contract within the BaseContract itself or an object in which BaseContract exists as a contract property.
import { getSelectors, type ContractWithSelectors } from "@coinmeca/ethers/diamond";
const contract = await (await ethers.getContractFactory("MyContract")).deploy();
const address = await facet.getAddress();
const selectors = getSelectors(contract);
<ContractWithSelectors> {
contract: <BaseContract>,
selectors ['0x466a0146', ...],
get() => Selector[],
set() => Selector[]
}
getSelector
( funtionName: string )
Returns selector (signature) of the given function name passed via parameter.
import { getSelector } from "@coinmeca/ethers/diamond";
getSelector("setAccess(address,bool)");
"0x466a0146";
removeSelectors
( selectors: Selector[] | functionNames: (Selector | string)[] )
Removes the selector corresponding to the additionally given filter list from the some selector array passed in the parameter. The filter list for removal provided in the parameter can be passed as an input value in the desired form, either as a function name or as a string array of a selector (signature).
import { removeSelectors, type Selector } from "@coinmeca/ethers/diamond";
const mySelectors: Selector[] = ["0x466a0146", "0x851642bf", "0xb1530104", "0x82431dab", "0xcdffacc6", "0x52ef6b2c", "0xf69f473c", "0xadfca15e"];
getSelector(["0xf69f473c", "0xadfca15e"]);
// or
getSelector(["function facetAddress(bytes4) view returns (address)", "function facetAddresses() view returns (address[])"]);
[
'0x466a0146', '0x851642bf',
'0xb1530104', '0x82431dab',
'0xcdffacc6', '0x52ef6b2c',
- '0xf69f473c', '0xadfca15e'
]