-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from CamposBruno/feat/examples
add example scripts
- Loading branch information
Showing
5 changed files
with
162 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ethers } from 'hardhat'; | ||
import { AbiCoder } from 'ethers'; | ||
|
||
async function addKeyToIdentity() { | ||
const [deployer] = await ethers.getSigners(); | ||
|
||
const IDENTITY_ADDRESS = "IDENTITY_ADDRESS"; | ||
const PURPOSE = 2 //1 = MANAGEMENT, 2 = ACTION, 3 = CLAIM, 4 = ENCRYPTION | ||
const TYPE = 1 // 1 = ECDSA, 2 = RSA | ||
const KEY = ethers.keccak256(AbiCoder.defaultAbiCoder().encode(['address'], [deployer.address])) | ||
|
||
const identity = await ethers.getContractAt('Identity', IDENTITY_ADDRESS, deployer); | ||
|
||
await identity | ||
.connect(deployer) | ||
.addKey(KEY, PURPOSE, TYPE); | ||
} | ||
|
||
addKeyToIdentity() | ||
.catch((error) => { | ||
console.error(error); | ||
process.exitCode = 1; | ||
}); |
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,21 @@ | ||
import { ethers } from 'hardhat'; | ||
import Deployments from '../data/deployments/chain-296.json'; | ||
|
||
async function createIdentity(): Promise<void> { | ||
const [deployer] = await ethers.getSigners(); | ||
|
||
const IMPLEMENTATION_AUTHORITY_ADDRESS = Deployments.implementations.ImplementationAuthority; | ||
|
||
const identity = await ethers.deployContract('IdentityProxy', [IMPLEMENTATION_AUTHORITY_ADDRESS, deployer.address], deployer); | ||
await identity.waitForDeployment(); | ||
|
||
console.log({ | ||
identity: await identity.getAddress(), | ||
}) | ||
} | ||
|
||
createIdentity() | ||
.catch((error) => { | ||
console.error(error); | ||
process.exitCode = 1; | ||
}); |
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,74 @@ | ||
import { ethers } from "hardhat"; | ||
import Deployments from '../data/deployments/chain-296.json'; | ||
|
||
async function createToken() { | ||
const TREX_FACTORY_ADDRESS = Deployments.factories.TREXFactory; | ||
const TREX_GATEWAY_ADDRESS = Deployments.factories.TREXGateway; | ||
|
||
const TOKEN_NAME = "RWA_R_US"; // unique per deployer | ||
const TOKEN_SYMBOL = "RWARUS"; | ||
const TOKEN_DECIMALS = 8; | ||
|
||
const [deployer] = await ethers.getSigners(); | ||
const trexFactory = await ethers.getContractAt('TREXFactory', TREX_FACTORY_ADDRESS); | ||
const trexGateway = await ethers.getContractAt('TREXGateway', TREX_GATEWAY_ADDRESS); | ||
|
||
// admin should be able to select the desired compliance module to include in the token | ||
const compliance = { | ||
modules : [], | ||
settings : [] | ||
} | ||
|
||
// claims are not needed right now | ||
const claims = { | ||
topics: [], | ||
issuers: [], | ||
issuerClaims: [], | ||
} | ||
|
||
const tx = await trexGateway.connect(deployer).deployTREXSuite( | ||
{ | ||
owner: deployer.address, | ||
name: TOKEN_NAME, | ||
symbol: TOKEN_SYMBOL, | ||
decimals: TOKEN_DECIMALS, | ||
irs: ethers.ZeroAddress, // IdentityRegistryStorage | ||
ONCHAINID: ethers.ZeroAddress, // Identity for the token | ||
irAgents: [deployer], | ||
tokenAgents: [deployer], | ||
complianceModules: compliance.modules, | ||
complianceSettings: compliance.settings, | ||
}, | ||
{ | ||
claimTopics: claims.topics, | ||
issuers: claims.issuers, | ||
issuerClaims: claims.issuerClaims, | ||
}, | ||
); | ||
|
||
await tx.wait(); | ||
|
||
const event = (await trexFactory.queryFilter(trexFactory.filters.TREXSuiteDeployed, -1))[0]; | ||
|
||
const Token = event.args._token; | ||
const IdentityRegistry = event.args._ir; | ||
const IdentityRegistryStorage = event.args._irs; | ||
const TrustedIssuerRegistry = event.args._tir; | ||
const ClaimTopicsRegistry = event.args._ctr; | ||
const ModularCompliance = event.args._mc; | ||
|
||
console.log({ | ||
Token, // Newly Created Token | ||
IdentityRegistry, | ||
IdentityRegistryStorage, | ||
TrustedIssuerRegistry, | ||
ClaimTopicsRegistry, | ||
ModularCompliance, | ||
}); | ||
} | ||
|
||
createToken() | ||
.catch((error) => { | ||
console.error(error); | ||
process.exitCode = 1; | ||
}); |
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,21 @@ | ||
import { ethers } from 'hardhat'; | ||
|
||
async function registerIdentity() { | ||
const [deployer] = await ethers.getSigners(); | ||
|
||
const IDENTITY_ADDRESS = "IDENTITY_ADDRESS"; | ||
const IDENTITY_REGISTRY_ADDRESS = "IDENTITY_REGISTRY_ADDRESS"; | ||
const COUNTRY = 840; // ISO United States country code (see: https://www.iso.org/obp/ui/#search) | ||
|
||
const identityRegistry = await ethers.getContractAt('IdentityRegistry', IDENTITY_REGISTRY_ADDRESS, deployer); | ||
|
||
await identityRegistry | ||
.connect(deployer) | ||
.registerIdentity(deployer.address, IDENTITY_ADDRESS, COUNTRY); | ||
} | ||
|
||
registerIdentity() | ||
.catch((error) => { | ||
console.error(error); | ||
process.exitCode = 1; | ||
}); |
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,23 @@ | ||
import { ethers } from "hardhat"; | ||
|
||
async function unregisterIdentity() { | ||
const [deployer] = await ethers.getSigners(); | ||
const IDENTITY_REGISTRY_ADDRESS = "IDENTITY_REGISTRY_ADDRESS"; | ||
|
||
const identityRegistry = await ethers.getContractAt('IdentityRegistry', IDENTITY_REGISTRY_ADDRESS, deployer); | ||
|
||
const contains = await identityRegistry | ||
.connect(deployer) | ||
.contains(deployer.address); | ||
|
||
if (contains) | ||
await identityRegistry | ||
.connect(deployer) | ||
.deleteIdentity(deployer.address); | ||
} | ||
|
||
unregisterIdentity() | ||
.catch((error) => { | ||
console.error(error); | ||
process.exitCode = 1; | ||
}); |