-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPackageManager.sol
42 lines (34 loc) · 1.63 KB
/
PackageManager.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import { Library } from './libraries/Library.sol';
import { IPackageManager } from './IPackageManager.sol';
import { IGit } from './IGit.sol';
import { Installer } from '../external/Installer.sol';
import { OwnableInternal } from '@solidstate/contracts/access/ownable/OwnableInternal.sol';
import 'hardhat/console.sol';
contract PackageManager is IPackageManager, OwnableInternal {
address public immutable xpm;
constructor(address diamond) {
xpm = diamond;
}
function install(address account, string memory repo) external onlyOwner {
require(!IGit(xpm).isSubscriber(account, repo, address(this)), '0xpm: Already installed!');
address pkg = IGit(xpm).latest(account, repo);
Library._upgrade(pkg);
IGit(xpm).subscribe(account, repo, address(this));
emit Upgraded(account, repo, pkg, address(0), address(this));
}
function uninstall(address account, string memory repo, address pkg) external onlyOwner {
address uninstaller = Installer(pkg).uninstaller();
Library._upgrade(uninstaller);
IGit(xpm).unsubscribe(account, repo, address(this));
emit Upgraded(account, repo, address(0), pkg, address(this));
}
function update(address account, string memory repo, address toPkg, address fromPkg) external onlyOwner {
require(IGit(xpm).isSubscriber(account, repo, address(this)), '0xpm: Not installed!');
address latestPkg = IGit(xpm).latest(account, repo);
require(latestPkg == toPkg, "PackageManager: new pkg does not match latest.");
Library._update(toPkg, fromPkg);
emit Upgraded(account, repo, toPkg, fromPkg, address(this));
}
}