Skip to content

Commit

Permalink
format contract
Browse files Browse the repository at this point in the history
  • Loading branch information
ququzone committed Oct 22, 2024
1 parent 4f8db69 commit 0ef9509
Show file tree
Hide file tree
Showing 6 changed files with 2,874 additions and 44 deletions.
1 change: 0 additions & 1 deletion contracts/proxies/VerifyingProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import "../interfaces/IioIDStore.sol";
import "../interfaces/IioIDRegistry.sol";

interface IDeviceNFT {
function weight(uint256 tokenId) external view returns (uint256);
function owner() external view returns (address);

function initialize(string memory _name, string memory _symbol) external;
Expand Down
1 change: 1 addition & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as dotenv from 'dotenv';
import { HardhatUserConfig } from 'hardhat/config';
import '@nomicfoundation/hardhat-toolbox';
import '@openzeppelin/hardhat-upgrades';
import '@nomiclabs/hardhat-truffle5';

dotenv.config();

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
"@nomicfoundation/hardhat-toolbox": "^4.0.0",
"@nomicfoundation/hardhat-verify": "^2.0.0",
"@nomiclabs/hardhat-truffle5": "^2.0.7",
"@nomiclabs/hardhat-web3": "^2.0.0",
"@openzeppelin/hardhat-upgrades": "^3.0.3",
"@tokenbound/sdk": "^0.5.1",
"@typechain/ethers-v6": "^0.5.0",
Expand Down
60 changes: 60 additions & 0 deletions scripts/manual-staking.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { artifacts, ethers } from 'hardhat';
import { TokenboundClient } from '@tokenbound/sdk';
import { IoID, IoIDRegistry } from '../typechain-types';

const SortedTroves = artifacts.require('SortedTroves');

async function main() {
const network = await ethers.provider.getNetwork();
const chainId = Number(network.chainId.toString());
const owner = new ethers.Wallet(process.env.PRIVATE_KEY!, ethers.provider);
console.log(`owner: ${owner.address}`);

const deviceNFTFactory = await ethers.getContractFactory('DeviceNFT');
const deviceGaugeFactory = await ethers.getContractFactory('DummyDeviceGauge');
const deviceGauge = deviceGaugeFactory.attach('0x6af1F299aa518423F469D5e89b4FBb2B81d89a5B');
const ioIDRegistryFactory = await ethers.getContractFactory('ioIDRegistry');
const ioIDRegistry = ioIDRegistryFactory.attach('0x04e4655Cf258EC802D17c23ec6112Ef7d97Fa2aF') as IoIDRegistry;
const ioIDFactory = await ethers.getContractFactory('ioID');
const ioID = ioIDFactory.attach('0x1FCB980eD0287777ab05ADc93012332e11300e54') as IoID;

// @ts-ignore
const tokenboundClient = new TokenboundClient({
chain: {
id: chainId,
name: 'IoTeX Testnet',
network: 'mainnet',
rpcUrls: {
default: {
http: ['https://babel-api.mainnet.iotex.io'],
},
public: {
http: ['https://babel-api.mainnet.iotex.io'],
},
},
nativeCurrency: {
name: 'IoTeX',
symbol: 'IOTX',
decimals: 18,
},
},
// registryAddress: '0x000000006551c19487814612e58FE06813775758',
// implementationAddress: '0x1d1C779932271e9Dc683d5373E84Fa4239F2b3fb',
signer: owner,
});

const did = await ioIDRegistry.documentID('0xdCD0a79a5A2bdC1392B31573dA3B960985E98dcb');
const wallet = await ioID['wallet(string)'](did);
const approveCall = await tokenboundClient.execute({
account: wallet,
to: '0xB31d7d8950C490F316A0A553b141994249Be4012',
value: BigInt(0),
data: deviceNFTFactory.interface.encodeFunctionData('approve', [deviceGauge.target, 1]),
});
console.log(`${wallet} approve txHash: ${approveCall}`);
}

main().catch(err => {
console.error(err);
process.exitCode = 1;
});
66 changes: 66 additions & 0 deletions scripts/proxy-register.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { ethers } from 'hardhat';

import { IoIDRegistry, VerifyingProxy } from '../typechain-types';
import { getBytes, keccak256, solidityPacked } from 'ethers';

async function main() {
const [verifier] = await ethers.getSigners();
const owner = ethers.Wallet.createRandom();

const network = await ethers.provider.getNetwork();
const chainId = Number(network.chainId.toString());
const ioIDRegistryFactory = await ethers.getContractFactory('ioIDRegistry');
const ioIDRegistry = ioIDRegistryFactory.attach('0x04e4655Cf258EC802D17c23ec6112Ef7d97Fa2aF') as IoIDRegistry;
const verifyingProxyFactory = await ethers.getContractFactory('VerifyingProxy');
const verifyingProxy = verifyingProxyFactory.attach('0xa5c293471ef44625d9ef079296ff4f223405714d') as VerifyingProxy;

const device = ethers.Wallet.createRandom();
const domain = {
name: 'ioIDRegistry',
version: '1',
chainId: chainId,
verifyingContract: ioIDRegistry.target,
};
const types = {
Permit: [
{ name: 'owner', type: 'address' },
{ name: 'nonce', type: 'uint256' },
],
};

const nonce = await ioIDRegistry.nonces(device.address);

// @ts-ignore
const signature = await device.signTypedData(domain, types, { owner: verifyingProxy.target, nonce: nonce });
const r = signature.substring(0, 66);
const s = '0x' + signature.substring(66, 130);
const v = '0x' + signature.substring(130);

const projectId = await verifyingProxy.projectId();
const deviceNFT = await verifyingProxy.deviceNFT();

const verifyMessage = solidityPacked(['uint256', 'address', 'address'], [chainId, owner.address, device.address]);
const verifySignature = await verifier.signMessage(getBytes(verifyMessage));

const tx = await verifyingProxy.register(
verifySignature,
keccak256('0x'), // did hash
'http://resolver.did', // did document uri
owner.address, // owner
device.address, // device
v,
r,
s,
);

console.log(`divice nft: ${projectId}`);
console.log(`divice nft: ${deviceNFT}`);
console.log(`divice address: ${device.address}`);
console.log(`owner private key: ${owner.privateKey}`);
console.log(`register device txHash: ${tx.hash}`);
}

main().catch(err => {
console.error(err);
process.exitCode = 1;
});
Loading

0 comments on commit 0ef9509

Please sign in to comment.