Skip to content

Commit 0ef9509

Browse files
committed
format contract
1 parent 4f8db69 commit 0ef9509

File tree

6 files changed

+2874
-44
lines changed

6 files changed

+2874
-44
lines changed

contracts/proxies/VerifyingProxy.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import "../interfaces/IioIDStore.sol";
1414
import "../interfaces/IioIDRegistry.sol";
1515

1616
interface IDeviceNFT {
17-
function weight(uint256 tokenId) external view returns (uint256);
1817
function owner() external view returns (address);
1918

2019
function initialize(string memory _name, string memory _symbol) external;

hardhat.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as dotenv from 'dotenv';
22
import { HardhatUserConfig } from 'hardhat/config';
33
import '@nomicfoundation/hardhat-toolbox';
44
import '@openzeppelin/hardhat-upgrades';
5+
import '@nomiclabs/hardhat-truffle5';
56

67
dotenv.config();
78

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
2121
"@nomicfoundation/hardhat-toolbox": "^4.0.0",
2222
"@nomicfoundation/hardhat-verify": "^2.0.0",
23+
"@nomiclabs/hardhat-truffle5": "^2.0.7",
24+
"@nomiclabs/hardhat-web3": "^2.0.0",
2325
"@openzeppelin/hardhat-upgrades": "^3.0.3",
2426
"@tokenbound/sdk": "^0.5.1",
2527
"@typechain/ethers-v6": "^0.5.0",

scripts/manual-staking.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { artifacts, ethers } from 'hardhat';
2+
import { TokenboundClient } from '@tokenbound/sdk';
3+
import { IoID, IoIDRegistry } from '../typechain-types';
4+
5+
const SortedTroves = artifacts.require('SortedTroves');
6+
7+
async function main() {
8+
const network = await ethers.provider.getNetwork();
9+
const chainId = Number(network.chainId.toString());
10+
const owner = new ethers.Wallet(process.env.PRIVATE_KEY!, ethers.provider);
11+
console.log(`owner: ${owner.address}`);
12+
13+
const deviceNFTFactory = await ethers.getContractFactory('DeviceNFT');
14+
const deviceGaugeFactory = await ethers.getContractFactory('DummyDeviceGauge');
15+
const deviceGauge = deviceGaugeFactory.attach('0x6af1F299aa518423F469D5e89b4FBb2B81d89a5B');
16+
const ioIDRegistryFactory = await ethers.getContractFactory('ioIDRegistry');
17+
const ioIDRegistry = ioIDRegistryFactory.attach('0x04e4655Cf258EC802D17c23ec6112Ef7d97Fa2aF') as IoIDRegistry;
18+
const ioIDFactory = await ethers.getContractFactory('ioID');
19+
const ioID = ioIDFactory.attach('0x1FCB980eD0287777ab05ADc93012332e11300e54') as IoID;
20+
21+
// @ts-ignore
22+
const tokenboundClient = new TokenboundClient({
23+
chain: {
24+
id: chainId,
25+
name: 'IoTeX Testnet',
26+
network: 'mainnet',
27+
rpcUrls: {
28+
default: {
29+
http: ['https://babel-api.mainnet.iotex.io'],
30+
},
31+
public: {
32+
http: ['https://babel-api.mainnet.iotex.io'],
33+
},
34+
},
35+
nativeCurrency: {
36+
name: 'IoTeX',
37+
symbol: 'IOTX',
38+
decimals: 18,
39+
},
40+
},
41+
// registryAddress: '0x000000006551c19487814612e58FE06813775758',
42+
// implementationAddress: '0x1d1C779932271e9Dc683d5373E84Fa4239F2b3fb',
43+
signer: owner,
44+
});
45+
46+
const did = await ioIDRegistry.documentID('0xdCD0a79a5A2bdC1392B31573dA3B960985E98dcb');
47+
const wallet = await ioID['wallet(string)'](did);
48+
const approveCall = await tokenboundClient.execute({
49+
account: wallet,
50+
to: '0xB31d7d8950C490F316A0A553b141994249Be4012',
51+
value: BigInt(0),
52+
data: deviceNFTFactory.interface.encodeFunctionData('approve', [deviceGauge.target, 1]),
53+
});
54+
console.log(`${wallet} approve txHash: ${approveCall}`);
55+
}
56+
57+
main().catch(err => {
58+
console.error(err);
59+
process.exitCode = 1;
60+
});

scripts/proxy-register.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { ethers } from 'hardhat';
2+
3+
import { IoIDRegistry, VerifyingProxy } from '../typechain-types';
4+
import { getBytes, keccak256, solidityPacked } from 'ethers';
5+
6+
async function main() {
7+
const [verifier] = await ethers.getSigners();
8+
const owner = ethers.Wallet.createRandom();
9+
10+
const network = await ethers.provider.getNetwork();
11+
const chainId = Number(network.chainId.toString());
12+
const ioIDRegistryFactory = await ethers.getContractFactory('ioIDRegistry');
13+
const ioIDRegistry = ioIDRegistryFactory.attach('0x04e4655Cf258EC802D17c23ec6112Ef7d97Fa2aF') as IoIDRegistry;
14+
const verifyingProxyFactory = await ethers.getContractFactory('VerifyingProxy');
15+
const verifyingProxy = verifyingProxyFactory.attach('0xa5c293471ef44625d9ef079296ff4f223405714d') as VerifyingProxy;
16+
17+
const device = ethers.Wallet.createRandom();
18+
const domain = {
19+
name: 'ioIDRegistry',
20+
version: '1',
21+
chainId: chainId,
22+
verifyingContract: ioIDRegistry.target,
23+
};
24+
const types = {
25+
Permit: [
26+
{ name: 'owner', type: 'address' },
27+
{ name: 'nonce', type: 'uint256' },
28+
],
29+
};
30+
31+
const nonce = await ioIDRegistry.nonces(device.address);
32+
33+
// @ts-ignore
34+
const signature = await device.signTypedData(domain, types, { owner: verifyingProxy.target, nonce: nonce });
35+
const r = signature.substring(0, 66);
36+
const s = '0x' + signature.substring(66, 130);
37+
const v = '0x' + signature.substring(130);
38+
39+
const projectId = await verifyingProxy.projectId();
40+
const deviceNFT = await verifyingProxy.deviceNFT();
41+
42+
const verifyMessage = solidityPacked(['uint256', 'address', 'address'], [chainId, owner.address, device.address]);
43+
const verifySignature = await verifier.signMessage(getBytes(verifyMessage));
44+
45+
const tx = await verifyingProxy.register(
46+
verifySignature,
47+
keccak256('0x'), // did hash
48+
'http://resolver.did', // did document uri
49+
owner.address, // owner
50+
device.address, // device
51+
v,
52+
r,
53+
s,
54+
);
55+
56+
console.log(`divice nft: ${projectId}`);
57+
console.log(`divice nft: ${deviceNFT}`);
58+
console.log(`divice address: ${device.address}`);
59+
console.log(`owner private key: ${owner.privateKey}`);
60+
console.log(`register device txHash: ${tx.hash}`);
61+
}
62+
63+
main().catch(err => {
64+
console.error(err);
65+
process.exitCode = 1;
66+
});

0 commit comments

Comments
 (0)