Skip to content

Commit

Permalink
Merge pull request #19 from CamposBruno/feat/examples
Browse files Browse the repository at this point in the history
add example scripts
  • Loading branch information
CamposBruno authored Apr 8, 2024
2 parents 952cfc7 + f9b89c5 commit c85acd5
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 0 deletions.
23 changes: 23 additions & 0 deletions examples/add-key-to-identity.ts
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;
});
21 changes: 21 additions & 0 deletions examples/create-identity.ts
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;
});
74 changes: 74 additions & 0 deletions examples/deploy-token.ts
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;
});
21 changes: 21 additions & 0 deletions examples/register-identity.ts
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;
});
23 changes: 23 additions & 0 deletions examples/unregister-identity.ts
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;
});

0 comments on commit c85acd5

Please sign in to comment.