Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: deploy registry contract to arbitrum goerli #91

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Contract Deployment

### Subscriptions contract
To deploy the contract run:

```bash
Expand All @@ -10,6 +11,16 @@ PRIVATE_KEY=<> hh deploy --token <STABLE_COIN_ADDRESS> --network <arbitrum-goerl

Alternatively you can use the env var `MNEMONIC` to deploy the contract and it will pick the first derived address.

### Registry contract
To deploy the contract run:

```bash
PRIVATE_KEY=<> hh deploy:registry --owner <OWNER_ADDRESS> --network <arbitrum-goerli|arbitrum-one>
```

Note that the `--owner` flag is optional, if not passed the deployer address will be set as the contract owner.
Alternatively you can use the env var `MNEMONIC` to deploy the contract and it will pick the first derived address.

## Tests

To test the contract run:
Expand Down
3 changes: 2 additions & 1 deletion contracts/addresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"Subscriptions": "0x482f58d3513E386036670404b35cB3F2DF67a750"
},
"421613": {
"Subscriptions": "0x29f49a438c747e7Dd1bfe7926b03783E47f9447B"
"Subscriptions": "0x29f49a438c747e7Dd1bfe7926b03783E47f9447B",
"Registry": "0xb9c4faA67f80e3fB4C4b7b7b2AcA6E0D1d7C711B"
}
}
16 changes: 8 additions & 8 deletions contracts/build/Registry.abi
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"type": "address[]"
},
{
"internalType": "uint256",
"internalType": "bytes32",
"name": "metadataHash",
"type": "uint256"
"type": "bytes32"
}
],
"indexed": false,
Expand Down Expand Up @@ -73,9 +73,9 @@
"name": "entries",
"outputs": [
{
"internalType": "uint256",
"internalType": "bytes32",
"name": "metadataHash",
"type": "uint256"
"type": "bytes32"
}
],
"stateMutability": "view",
Expand All @@ -97,9 +97,9 @@
"type": "address[]"
},
{
"internalType": "uint256",
"internalType": "bytes32",
"name": "",
"type": "uint256"
"type": "bytes32"
}
],
"stateMutability": "view",
Expand All @@ -120,9 +120,9 @@
"type": "address[]"
},
{
"internalType": "uint256",
"internalType": "bytes32",
"name": "metadataHash",
"type": "uint256"
"type": "bytes32"
}
],
"internalType": "struct Entry",
Expand Down
4 changes: 2 additions & 2 deletions contracts/contracts/Registry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "@openzeppelin/contracts/access/Ownable.sol";
/// @notice Data for an entry, a set of subscriptions contracts and a metadata hash.
struct Entry {
address[] subscriptions;
uint256 metadataHash;
bytes32 metadataHash;
}

/// @notice This contract is designed to store an allowlist of entries, where each entry is associated with a set of
Expand All @@ -33,7 +33,7 @@ contract Registry is Ownable {
}

/// @notice Return the entry data, (subscriptions, metadataHash), associated with the given `_id`.
function getEntry(uint256 _id) external view returns (address[] memory, uint256) {
function getEntry(uint256 _id) external view returns (address[] memory, bytes32) {
Entry memory _entry = entries[_id];
return (_entry.subscriptions, _entry.metadataHash);
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {HardhatUserConfig, task} from 'hardhat/config';
import '@nomiclabs/hardhat-ethers';
import '@typechain/hardhat';
import "@nomiclabs/hardhat-etherscan";
import '@nomiclabs/hardhat-etherscan';
import './tasks/deploy';

task('accounts', 'Print a list of accounts', async (_, hre) => {
Expand Down
50 changes: 39 additions & 11 deletions contracts/tasks/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,50 @@
import { Wallet } from 'ethers'
import { task, types } from 'hardhat/config'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import {Wallet, ethers} from 'ethers';
import {task, types} from 'hardhat/config';
import {HardhatRuntimeEnvironment} from 'hardhat/types';

import { deploySubscriptions } from '../utils/deploy'
import {deploySubscriptions, deployRegistry} from '../utils/deploy';

task('deploy', 'Deploy the subscription contract (use L2 network!)')
.addParam('token', 'Address of the ERC20 token')
.addOptionalParam('epochSeconds', 'Epoch length in seconds.', 3, types.int)
.setAction(async (taskArgs, hre: HardhatRuntimeEnvironment) => {
const accounts = await hre.ethers.getSigners()
const accounts = await hre.ethers.getSigners();

if (accounts.length === 0) {
throw new Error('No accounts available, set PRIVATE_KEY or MNEMONIC env variables')
throw new Error(
'No accounts available, set PRIVATE_KEY or MNEMONIC env variables'
);
}
console.log('Deploying subscriptions contract with the account:', accounts[0].address);

console.log(
'Deploying subscriptions contract with the account:',
accounts[0].address
);

await deploySubscriptions(
[taskArgs.token, taskArgs.epochSeconds],
accounts[0] as unknown as Wallet,
)
})
accounts[0] as unknown as Wallet
);
});

task('deploy:registry', 'Deploy the registry contract (use L2 network!)')
.addOptionalParam('owner', 'Address of the contract owner')
.setAction(async (taskArgs, hre: HardhatRuntimeEnvironment) => {
const accounts = await hre.ethers.getSigners();

if (accounts.length === 0) {
throw new Error(
'No accounts available, set PRIVATE_KEY or MNEMONIC env variables'
);
}
console.log(
'Deploying registry contract with the account:',
accounts[0].address
);

const registry = await deployRegistry(accounts[0] as unknown as Wallet);

if (ethers.utils.isAddress(taskArgs.owner)) {
console.log(`Transferring ownership to ${taskArgs.owner}`);
await registry.connect(accounts[0]).transferOwnership(taskArgs.owner);
}
});
16 changes: 5 additions & 11 deletions contracts/test/registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as deployment from '../utils/deploy';
import {getAccounts, Account} from '../utils/helpers';

import {Registry} from '../types/contracts/Registry';
import {BigNumber} from 'ethers';
import {BigNumber, ethers} from 'ethers';
import {setAutoMine} from './helpers';

describe('Registry contract', () => {
Expand Down Expand Up @@ -47,9 +47,7 @@ describe('Registry contract', () => {
'0x0000000000000000000000000000000000000001',
'0x0000000000000000000000000000000000000002',
],
metadataHash: BigNumber.from(
'0x0000000000000000000000000000000000000000000000000000000000000001'
),
metadataHash: '0x0000000000000000000000000000000000000000000000000000000000000001',
};
await registry.insertEntry(entryID, entry);
const result = await registry.getEntry(entryID);
Expand All @@ -61,15 +59,11 @@ describe('Registry contract', () => {
const entryID = BigNumber.from(1);
const entry1 = {
subscriptions: ['0x0000000000000000000000000000000000000001'],
metadataHash: BigNumber.from(
'0x0000000000000000000000000000000000000000000000000000000000000001'
),
metadataHash: '0x0000000000000000000000000000000000000000000000000000000000000001',
};
const entry2 = {
subscriptions: ['0x0000000000000000000000000000000000000002'],
metadataHash: BigNumber.from(
'0x0000000000000000000000000000000000000000000000000000000000000002'
),
metadataHash: '0x0000000000000000000000000000000000000000000000000000000000000002',
};
await registry.insertEntry(entryID, entry1);
await registry.insertEntry(entryID, entry2);
Expand All @@ -89,7 +83,7 @@ describe('Registry contract', () => {
await registry.removeEntry(entryID);
const result = await registry.getEntry(entryID);
expect(result[0]).to.eql([]);
expect(result[1]).to.eql(BigNumber.from(0));
expect(result[1]).to.eql(ethers.constants.HashZero);
});
});
});