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

Backed token with auto accrual and multiplier #32

Merged
merged 17 commits into from
Jul 19, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Improve upgradeability
MiniRoman committed Jun 24, 2024
commit ed9b8d9c8eff33e7d0a783cb26f00c2b3dbda923
32 changes: 24 additions & 8 deletions contracts/BackedAutoFeeTokenImplementation.sol
Original file line number Diff line number Diff line change
@@ -114,38 +114,54 @@ contract BackedAutoFeeTokenImplementation is BackedTokenImplementation {
}

// Initializers:

function initialize(
string memory name_,
string memory symbol_
) public virtual override {
_initialize(name_, symbol_, 24 * 3600, block.timestamp);
super.initialize(name_, symbol_);
_initialize_auto_fee(24 * 3600, block.timestamp, 0);
}

function initialize(
string memory name_,
string memory symbol_,
uint256 _periodLength,
uint256 _lastTimeFeeApplied
uint256 _lastTimeFeeApplied,
uint256 _feePerPeriod
) public virtual {
_initialize(name_, symbol_, _periodLength, _lastTimeFeeApplied);
super.initialize(name_, symbol_);
_initialize_auto_fee(_periodLength, _lastTimeFeeApplied, _feePerPeriod);
}

function initialize_v2(
uint256 _periodLength,
uint256 _lastTimeFeeApplied,
uint256 _feePerPeriod
) public virtual {
_initialize_auto_fee(_periodLength, _lastTimeFeeApplied, _feePerPeriod);
}

function _initialize(
string memory name_,
string memory symbol_,
uint256 _periodLength,
uint256 _lastTimeFeeApplied
string memory symbol_
) public virtual initializer {
__ERC20_init(name_, symbol_);
__Ownable_init();
_buildDomainSeparator();
_setTerms("https://www.backedassets.fi/legal-documentation"); // Default Terms
}

multiplier = 1e18;
function _initialize_auto_fee(
uint256 _periodLength,
uint256 _lastTimeFeeApplied,
uint256 _feePerPeriod
) public virtual {
require(lastTimeFeeApplied == 0, "BackedAutoFeeTokenImplementation already initialized");

multiplier = 1e18;
periodLength = _periodLength;
lastTimeFeeApplied = _lastTimeFeeApplied;
feePerPeriod = _feePerPeriod;
}

/**
6 changes: 3 additions & 3 deletions test/BackedAutoFeeTokenImplementation.ts
Original file line number Diff line number Diff line change
@@ -71,12 +71,13 @@ describe("BackedAutoFeeTokenImplementation", function () {
const proxyAdminFactory = new ProxyAdmin__factory(owner.signer)
proxyAdmin = await proxyAdminFactory.deploy();
const tokenProxy = await new BackedTokenProxy__factory(owner.signer).deploy(tokenImplementation.address, proxyAdmin.address, tokenImplementation.interface.encodeFunctionData(
'initialize(string,string,uint256,uint256)',
'initialize(string,string,uint256,uint256,uint256)',
[
tokenName,
tokenSymbol,
24 * 3600,
baseTime
baseTime,
baseFeePerPeriod
]
));
token = BackedAutoFeeTokenImplementation__factory.connect(tokenProxy.address, owner.signer);
@@ -86,7 +87,6 @@ describe("BackedAutoFeeTokenImplementation", function () {
await token.setMultiplierUpdater(owner.address);
sanctionsList = await new SanctionsListMock__factory(blacklister.signer).deploy();
await token.setSanctionsList(sanctionsList.address);
await token.updateFeePerPeriod(baseFeePerPeriod);

// Chain Id
const network = await ethers.provider.getNetwork();
13 changes: 7 additions & 6 deletions test/Upgradability.ts
Original file line number Diff line number Diff line change
@@ -137,7 +137,7 @@ describe("Upgrade from v1.0.0 to v1.1.0", () => {
});
});

describe("Upgrade from v1.1.0 to v1.2.0", () => {
describe("Upgrade from v1.1.0 to auto fee", () => {
let implementationV2: BackedAutoFeeTokenImplementation;
let tokenV2: BackedAutoFeeTokenImplementation;
let tokenV1: BackedTokenImplementation;
@@ -165,16 +165,17 @@ describe("Upgrade from v1.1.0 to v1.2.0", () => {
await ethers.getContractFactory("BackedAutoFeeTokenImplementation")
).deploy();

await proxyAdmin.upgrade(tokenV1.address, implementationV2.address);
await proxyAdmin.upgradeAndCall(tokenV1.address, implementationV2.address, implementationV2.interface.encodeFunctionData(
'initialize_v2', [
24 * 3600,
Math.floor(Date.now() / 1000) - 3600,
0
]));

tokenV2 = await ethers.getContractAt(
"BackedAutoFeeTokenImplementation",
tokenV1.address
);
await tokenV2.setMultiplierUpdater(owner.address);
await tokenV2.setLastTimeFeeApplied(Math.floor(Date.now() / 1000) - 3600);
await tokenV2.setPeriodLength(24 * 3600);
await tokenV2.updateMultiplierValue(ethers.BigNumber.from(10).pow(18), 0)
};

beforeEach(async () => {