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

temple gold contracts #990

Merged
merged 212 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
212 commits
Select commit Hold shift + click to select a range
ae1aa9e
first draft temple gold contracts
princetonbishop Mar 20, 2024
0395e60
templegold update
princetonbishop Mar 28, 2024
31ea89b
Merge branch 'stage' into templegold
princetonbishop Mar 28, 2024
44904b7
reorganize templegold files
princetonbishop Mar 29, 2024
38a967d
reorganize files
princetonbishop Mar 29, 2024
a81c900
Merge branch 'stage' into templegold
princetonbishop Mar 29, 2024
39c3c72
integrating OZ gov after merge
princetonbishop Mar 30, 2024
24429bf
restructure, distribution update, spice auction contract
princetonbishop Apr 4, 2024
c886a66
override lz functions, add lz config, peers
princetonbishop Apr 10, 2024
f0bb9d4
add vote weight implementation
princetonbishop Apr 11, 2024
88e9ec0
use templeGold proxy with elevated access
princetonbishop Apr 12, 2024
f8f6342
remove external manual lz imports
princetonbishop Apr 12, 2024
e614c68
remove unused contract
princetonbishop Apr 12, 2024
f20b3e8
temple teleporter
princetonbishop Apr 12, 2024
7fb3052
modify vote token, chief approvals
princetonbishop Apr 13, 2024
f30820c
remove governance contracts, cleanup
princetonbishop Apr 14, 2024
b517991
cleanup
princetonbishop Apr 15, 2024
13c0b16
change whitelist func name
princetonbishop Apr 15, 2024
a068cfc
interface update
princetonbishop Apr 17, 2024
8033d0b
first README
princetonbishop Apr 19, 2024
eb2be48
updates from review
princetonbishop Apr 21, 2024
3c462ad
yarn lock
princetonbishop Apr 21, 2024
ff3bb87
Merge branch 'stage' into templegold
princetonbishop Apr 21, 2024
e2b9513
slither run
princetonbishop Apr 21, 2024
0da74e4
daigoldauction tests
princetonbishop Apr 23, 2024
86f5344
dai gold auctio tests update
princetonbishop Apr 24, 2024
b9dda2b
spice auction factory test
princetonbishop Apr 24, 2024
f88b73f
update spice auctions contract
princetonbishop Apr 25, 2024
9edef77
spice and spice factory tests update
princetonbishop Apr 26, 2024
aa0b800
spice auctions tests
princetonbishop Apr 26, 2024
2eae21f
vote token tests
princetonbishop Apr 28, 2024
9745d77
tests update
princetonbishop Apr 30, 2024
735ab39
tests update
princetonbishop May 1, 2024
65079ce
vote weight tests, staking tests
princetonbishop May 1, 2024
8db9412
test update and proxy tests
princetonbishop May 4, 2024
aa896db
tgold proxy tests, temple gold tests
princetonbishop May 4, 2024
2078776
tests update, before lzdevtools install
princetonbishop May 5, 2024
224258d
forge install: devtools
princetonbishop May 5, 2024
6783f3b
lz send test crosschain
princetonbishop May 6, 2024
e6948eb
add comments, minor changes
princetonbishop May 6, 2024
87ba793
update slither
princetonbishop May 6, 2024
f63fa69
test coverage
princetonbishop May 7, 2024
0941844
coverage tests, fix remove auction config bug
princetonbishop May 7, 2024
22d863f
cross chain tests, update sol version in contracts
princetonbishop May 8, 2024
e69271c
use latest block for forks
princetonbishop May 8, 2024
5b4db3d
remove old fork method
princetonbishop May 8, 2024
f9d76bf
Merge branch 'stage' into templegold
princetonbishop May 8, 2024
a2f0652
review changes
princetonbishop May 10, 2024
17e5ac0
remove vote token, epoch lib
princetonbishop May 11, 2024
84629ba
recover token, remove auction config, review updates
princetonbishop May 13, 2024
d815e5f
review changes
princetonbishop May 14, 2024
712fb62
delegates functions and tests
princetonbishop May 14, 2024
df23f29
update readme
princetonbishop May 15, 2024
a5862b9
review updates
princetonbishop May 16, 2024
7b4d055
feat: fork lz devtools to get coverage working
frontier159 May 22, 2024
c7d8158
some tests, remove distribution params check in mint()
princetonbishop May 22, 2024
5571c10
Merge branch 'templegold' of github.com:TempleDAO/temple into templegold
princetonbishop May 22, 2024
7acb377
fix templegold mint math, some tests
princetonbishop May 22, 2024
0b6512b
tgld audit fix M01
princetonbishop May 23, 2024
b0a97d8
tgld audit fix m02
princetonbishop May 23, 2024
5939df1
tgld audit fix m03
princetonbishop May 23, 2024
8f19fbe
tgld audit fix m04
princetonbishop May 23, 2024
01129c4
tgld audit fix h01
princetonbishop May 24, 2024
a94ff93
tgld audit fix m05
princetonbishop May 24, 2024
753ce34
tgld audit fix m08
princetonbishop May 24, 2024
324dd2e
tgld audit fix m09
princetonbishop May 27, 2024
da965e1
tgld audit fix m10
princetonbishop May 27, 2024
9422510
tgld-audit-fix-m10 update
princetonbishop May 28, 2024
14dc335
tgld audit fix m12
princetonbishop May 28, 2024
2e890fc
tgld audit fix m13
princetonbishop May 28, 2024
9cfc8a5
tgld audit fix m11
princetonbishop May 29, 2024
015d85a
cleanup
princetonbishop May 29, 2024
efaa9be
cleanup
princetonbishop May 29, 2024
b97e565
tgld aucit fix h15
princetonbishop Jun 2, 2024
d04d3f5
tgld audit fix m01 update
princetonbishop Jun 3, 2024
276b374
slither run
princetonbishop Jun 3, 2024
49b9c48
Merge pull request #1026 from TempleDAO/tgld-audit-fix-m01
princetonbishop Jun 3, 2024
18fbd64
slither run
princetonbishop Jun 3, 2024
56c8cb8
slither update
princetonbishop Jun 3, 2024
4196ea2
Merge pull request #1029 from TempleDAO/tgld-audit-fix-m04
princetonbishop Jun 3, 2024
355a549
Merge pull request #1030 from TempleDAO/tgld-audit-fix-h01
princetonbishop Jun 3, 2024
429fffa
Merge pull request #1027 from TempleDAO/tgld-audit-fix-m02
princetonbishop Jun 3, 2024
59df72d
Merge pull request #1032 from TempleDAO/tgld-audit-fix-m08
princetonbishop Jun 3, 2024
1a0e838
merge conflict fix
princetonbishop Jun 3, 2024
cdb91ce
slither
princetonbishop Jun 3, 2024
cd4b342
slither file
princetonbishop Jun 3, 2024
1f20958
slither file
princetonbishop Jun 3, 2024
e5b256f
Merge pull request #1028 from TempleDAO/tgld-audit-fix-m03
princetonbishop Jun 3, 2024
bdc05a7
Merge pull request #1034 from TempleDAO/tgld-audit-fix-m10
princetonbishop Jun 3, 2024
b62032e
merge conflict
princetonbishop Jun 3, 2024
5055915
slither
princetonbishop Jun 3, 2024
9baef02
Merge pull request #1031 from TempleDAO/tgld-audit-fix-m05
princetonbishop Jun 3, 2024
a151fa0
tgld audit fix m06
princetonbishop Jun 3, 2024
9aef4b0
tgld audit refix m05
princetonbishop Jun 3, 2024
e7fb7bd
test update
princetonbishop Jun 3, 2024
c1bae81
Merge pull request #1043 from TempleDAO/audit-fix-m05
princetonbishop Jun 3, 2024
3d918ee
Merge pull request #1038 from TempleDAO/tgld-audit-fix-m13
princetonbishop Jun 3, 2024
0ac3ea6
slither file
princetonbishop Jun 3, 2024
8311816
merge
princetonbishop Jun 3, 2024
cdf2dcf
slither file
princetonbishop Jun 3, 2024
bf38a22
Merge pull request #1037 from TempleDAO/tgld-audit-fix-m12
princetonbishop Jun 3, 2024
cf39c5e
pre merge
princetonbishop Jun 4, 2024
0a96b41
merge conflict
princetonbishop Jun 4, 2024
efdfba7
remove duplicate
princetonbishop Jun 4, 2024
c9ee065
update test
princetonbishop Jun 4, 2024
63ba9be
merge conflict
princetonbishop Jun 4, 2024
6ed1100
slither
princetonbishop Jun 4, 2024
0cae8e2
Merge pull request #1040 from TempleDAO/tgld-audit-fix-m11
princetonbishop Jun 4, 2024
e8f5e14
slither
princetonbishop Jun 4, 2024
68e7d0f
slither, test update
princetonbishop Jun 4, 2024
c35eaca
slither file
princetonbishop Jun 4, 2024
6f9d13f
Merge pull request #1033 from TempleDAO/tgld-audit-fix-m09
princetonbishop Jun 4, 2024
8e779a5
Merge pull request #1041 from TempleDAO/tgld-audit-fix-h15
princetonbishop Jun 4, 2024
6499249
tgld-audit-fix-i03
princetonbishop Jun 14, 2024
74b08cf
slither run
princetonbishop Jun 14, 2024
e6037be
cleanup
princetonbishop Jun 14, 2024
c050056
test update
princetonbishop Jun 14, 2024
e50f564
last update time in reward notification
princetonbishop Jun 14, 2024
17a6747
update fork block number
princetonbishop Jun 14, 2024
a59d548
update block number
princetonbishop Jun 14, 2024
49ba5ea
fix: link arb one rpc to gh actions
frontier159 Jun 14, 2024
35d5940
Merge pull request #1046 from TempleDAO/tgld-audit-fix-i03
princetonbishop Jun 17, 2024
d33ebb3
yarnlock conflict
princetonbishop Jun 17, 2024
e6d954b
Merge pull request #1047 from TempleDAO/fix-yarnlock-conflict
princetonbishop Jun 17, 2024
db17b0c
gas savings
princetonbishop Jun 18, 2024
c6d8175
Merge branch 'stage' into templegold
princetonbishop Jun 18, 2024
9a684c4
cleanup
princetonbishop Jun 19, 2024
d6bb75b
update readme
princetonbishop Jun 19, 2024
990810f
test update, deploy scripts
princetonbishop Jun 24, 2024
527ec44
remove audit scope file
princetonbishop Jul 2, 2024
c94bffd
update readme
princetonbishop Jul 2, 2024
3768698
remove tgld compiler warnings
princetonbishop Jul 8, 2024
d4d527e
redemption in spice auction, test update
princetonbishop Aug 2, 2024
50114a3
slither
princetonbishop Aug 2, 2024
3189126
Merge pull request #1057 from TempleDAO/redemption
princetonbishop Aug 2, 2024
ec7d4df
hawks l01
princetonbishop Aug 2, 2024
7fc9298
hawks l02
princetonbishop Aug 2, 2024
7bb09fd
Merge pull request #1058 from TempleDAO/hawks-l01
princetonbishop Aug 2, 2024
58b7890
Merge pull request #1059 from TempleDAO/hawks-l02
princetonbishop Aug 2, 2024
850b939
hawks l03
princetonbishop Aug 3, 2024
b9fc74e
Merge pull request #1061 from TempleDAO/hawks-l03
princetonbishop Aug 3, 2024
3806ea7
hawks l04
princetonbishop Aug 3, 2024
e26084d
Merge pull request #1062 from TempleDAO/hawks-l04
princetonbishop Aug 3, 2024
ae445ea
hawks l05
princetonbishop Aug 4, 2024
9ae05ec
Merge pull request #1063 from TempleDAO/hawks-l05
princetonbishop Aug 4, 2024
74f5af8
hawks m01
princetonbishop Aug 4, 2024
c50ca6d
Merge pull request #1064 from TempleDAO/hawks-m01
princetonbishop Aug 4, 2024
9fc581a
hawks m02
princetonbishop Aug 4, 2024
f15e86b
Merge pull request #1065 from TempleDAO/hawks-m02
princetonbishop Aug 4, 2024
832f113
new staking
princetonbishop Aug 8, 2024
86acc74
Merge pull request #1066 from TempleDAO/new-staking
princetonbishop Aug 8, 2024
0e0a92a
redemption test
princetonbishop Aug 8, 2024
57eb6ec
redemption tests
princetonbishop Aug 12, 2024
49217a1
cleanup
princetonbishop Aug 12, 2024
200bfc4
Merge pull request #1073 from TempleDAO/redemption-tests
princetonbishop Aug 12, 2024
d89d0e7
review update, new staking
princetonbishop Aug 14, 2024
364ed3d
review update
princetonbishop Aug 14, 2024
257811a
deploy scripts udpate
princetonbishop Aug 14, 2024
7de9bd0
remove redemption on claim
princetonbishop Aug 15, 2024
eb07b0c
spice operator, update tests
princetonbishop Aug 19, 2024
0943313
upgrade lz
princetonbishop Aug 20, 2024
b0ebf54
update readme, notify distribution
princetonbishop Aug 20, 2024
349fbcd
update test emission constant values
princetonbishop Aug 20, 2024
38f882d
Merge pull request #1075 from TempleDAO/new-staking
princetonbishop Aug 20, 2024
905e096
deploy script, anvil, cleanup
princetonbishop Aug 23, 2024
f37f09e
Merge pull request #1078 from TempleDAO/tgld-deploys
princetonbishop Aug 26, 2024
04f50fe
update deploy scripts
princetonbishop Sep 17, 2024
9bd6a12
Merge pull request #1084 from TempleDAO/tgld-deploys
princetonbishop Sep 17, 2024
afc0226
audit h01
princetonbishop Sep 17, 2024
99dbe28
audit h02
princetonbishop Sep 17, 2024
33e6458
audit m01
princetonbishop Sep 17, 2024
fa2d0e3
audit l01
princetonbishop Sep 17, 2024
7c1a2d4
audit l02
princetonbishop Sep 18, 2024
303d0bb
Merge pull request #1086 from TempleDAO/audit-h02
princetonbishop Sep 23, 2024
7f63113
merge
princetonbishop Sep 23, 2024
44b0baf
slither
princetonbishop Sep 23, 2024
c81fa04
Merge pull request #1088 from TempleDAO/audit-l01
princetonbishop Sep 23, 2024
07317b4
audit m01 test
princetonbishop Sep 23, 2024
3e93aa3
ignore elder test
princetonbishop Sep 23, 2024
9fb0daf
merge conflict
princetonbishop Sep 23, 2024
b0270a5
skip elder election test
princetonbishop Sep 23, 2024
a6b789b
Merge pull request #1087 from TempleDAO/audit-m01
princetonbishop Sep 23, 2024
70f1721
slither
princetonbishop Sep 23, 2024
1befc56
Merge pull request #1089 from TempleDAO/audit-l02
princetonbishop Sep 23, 2024
1f683a9
pre merge
princetonbishop Sep 24, 2024
01381db
Merge branch 'templegold' into audit-h01
princetonbishop Sep 24, 2024
ec0b6f4
test cross chain truncation
princetonbishop Sep 24, 2024
14a5693
Merge pull request #1091 from TempleDAO/audit-h01
princetonbishop Sep 24, 2024
d1d520b
Merge branch 'stage' into templegold
princetonbishop Sep 24, 2024
8e0cb2d
sepolia deploy script and addresses
princetonbishop Sep 27, 2024
e20676d
Merge pull request #1094 from TempleDAO/testnet-deploy
princetonbishop Sep 30, 2024
13658e7
review update
princetonbishop Oct 21, 2024
c342cb6
review update, slither
princetonbishop Oct 28, 2024
f15a142
remove new block numbers
princetonbishop Oct 28, 2024
93af130
fix: feedback update
princetonbishop Oct 31, 2024
fb42e66
add mainnet config and addresses
princetonbishop Nov 1, 2024
d376d72
review feedback
princetonbishop Nov 4, 2024
a33688f
sepolia deploy scripts and addresses
princetonbishop Nov 4, 2024
7d642d6
update testnet deploy addresses, use encode in teleporter
princetonbishop Nov 5, 2024
73c5e8b
review feedback
princetonbishop Nov 7, 2024
bcd4716
add helper function
princetonbishop Nov 8, 2024
efbd37b
deploy on sepolia, staking invariant test
princetonbishop Nov 14, 2024
f7edad1
update invariant test
princetonbishop Nov 18, 2024
38d5fc2
invariant auction, rename gold auction
princetonbishop Nov 18, 2024
cf5d822
fix merge conflict
princetonbishop Nov 19, 2024
eeec8e3
slither run
princetonbishop Nov 19, 2024
7cb50a1
fix forge test compiler error
princetonbishop Nov 20, 2024
09d4aef
Merge branch 'stage' into templegold
princetonbishop Nov 25, 2024
3d18667
chore: slither
frontier159 Nov 26, 2024
f5fcbdf
uni and invariant test folder, git workflow update
princetonbishop Nov 26, 2024
0ecc2fa
Merge branch 'templegold' of github.com:TempleDAO/temple into templegold
princetonbishop Nov 26, 2024
32dc552
deep invariant workflow
princetonbishop Nov 26, 2024
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
2 changes: 1 addition & 1 deletion protocol/contracts/amo/AuraStaking.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.8.20;
pragma solidity ^0.8.20;
// SPDX-License-Identifier: AGPL-3.0-or-later
// Temple (amo/AuraStaking.sol)

Expand Down
2 changes: 1 addition & 1 deletion protocol/contracts/amo/Ramos.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.8.20;
pragma solidity ^0.8.20;
// SPDX-License-Identifier: AGPL-3.0-or-later
// Temple (amo/Ramos.sol)

Expand Down
3 changes: 1 addition & 2 deletions protocol/contracts/common/CommonEventsAndErrors.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.8.20;
pragma solidity ^0.8.20;
// SPDX-License-Identifier: AGPL-3.0-or-later
// Temple (common/CommonEventsAndErrors.sol)

Expand All @@ -12,5 +12,4 @@ library CommonEventsAndErrors {
error ExpectedNonZero();
error Unimplemented();
event TokenRecovered(address indexed to, address indexed token, uint256 amount);
error AccountBlacklisted(address account);
}
2 changes: 1 addition & 1 deletion protocol/contracts/common/SafeCast.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.8.20;
pragma solidity ^0.8.20;
// SPDX-License-Identifier: AGPL-3.0-or-later
// Temple (common/SafeCast.sol)

Expand Down
16 changes: 16 additions & 0 deletions protocol/contracts/common/TempleMath.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
pragma solidity ^0.8.20;
// SPDX-License-Identifier: AGPL-3.0-or-later
// Temple (common/TempleMath.sol)

import { mulDiv } from "@prb/math/src/Common.sol";

library TempleMath {
/// @notice mulDiv with an option to round the result up or down to the nearest wei
function mulDivRound(uint256 x, uint256 y, uint256 denominator, bool roundUp) internal pure returns (uint256 result) {
result = mulDiv(x, y, denominator);
// See OZ Math.sol for the equivalent mulDiv() with rounding.
if (roundUp && mulmod(x, y, denominator) > 0) {
result += 1;
}
}
}
2 changes: 1 addition & 1 deletion protocol/contracts/core/MultiOtcOffer.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.8.20;
pragma solidity ^0.8.20;
// SPDX-License-Identifier: AGPL-3.0-or-later
// Temple (core/MultiOtcOffer.sol)

Expand Down
2 changes: 1 addition & 1 deletion protocol/contracts/core/OtcOffer.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.8.20;
pragma solidity ^0.8.20;
// SPDX-License-Identifier: AGPL-3.0-or-later
// Temple (core/OtcOffer.sol)

Expand Down
2 changes: 1 addition & 1 deletion protocol/contracts/fakes/FakeERC20.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.8.20;
pragma solidity ^0.8.20;
// SPDX-License-Identifier: AGPL-3.0-or-later

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
Expand Down
2 changes: 1 addition & 1 deletion protocol/contracts/fakes/FakeERC20CustomDecimals.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.8.20;
pragma solidity ^0.8.20;
// SPDX-License-Identifier: AGPL-3.0-or-later

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
Expand Down
173 changes: 173 additions & 0 deletions protocol/contracts/fakes/templegold/TempleGoldMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
pragma solidity ^0.8.20;
// SPDX-License-Identifier: AGPL-3.0-or-later
// Temple (templegold/TempleGoldMock.sol)


princetonbishop marked this conversation as resolved.
Show resolved Hide resolved
import { Origin } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/interfaces/IOAppReceiver.sol";
import { CommonEventsAndErrors } from "contracts/common/CommonEventsAndErrors.sol";
import { IOFT, OFTCore } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oft/OFTCore.sol";
import { ITempleGold } from "contracts/interfaces/templegold/ITempleGold.sol";
import { IDaiGoldAuction } from "contracts/interfaces/templegold/IDaiGoldAuction.sol";
import { OFT } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oft/OFT.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { ITempleGoldStaking} from "contracts/interfaces/templegold/ITempleGoldStaking.sol";
import { MessagingReceipt, MessagingFee } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/OAppSender.sol";
import { OFTMsgCodec } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oft/libs/OFTMsgCodec.sol";
import { SendParam, OFTReceipt } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oft/interfaces/IOFT.sol";
import { TempleMath } from "contracts/common/TempleMath.sol";

/**
* @title Temple Gold
* @notice Temple Gold is a non-transferrable ERC20 token with LayerZero integration for cross-chain transfer.
* Temple Gold can be only transferred to or from whitelisted addresses. On mint, Temple Gold is distributed between Staking, Auction and Gnosis Safe
* addresses using distribution share percentages set at `DistributionParams`. LayerZero's OFT token standard is modified to allow changing delegates
* with the same elevated access from v2.
* @notice
*/
contract TempleGoldMock is OFT {
using OFTMsgCodec for bytes;
using OFTMsgCodec for bytes32;

//// @notice Distribution as a percentage of 100
uint256 public constant DISTRIBUTION_MULTIPLIER = 100 ether;
/// @notice Minimum percentage of minted Temple Gold to distribute. 1 ether means 1%
uint256 public constant MINIMUM_DISTRIBUTION_SHARE = 1 ether;
/// @notice 1B max supply
uint256 public constant MAX_SUPPLY = 1_000_000_000 ether; // 1B
/// @notice Minimum Temple Gold minted per call to mint
uint256 public constant MINIMUM_MINT = 1_000;

/// @notice Whitelisted addresses for transferrability
mapping(address => bool) public authorized;

event ContractAuthorizationSet(address _contract, bool _whitelist);

constructor(
address _layerZeroEndpoint,
address _executor,
string memory _name,
string memory _symbol
) OFT(_name, _symbol, _layerZeroEndpoint, _executor) Ownable(_executor){}

/**
* @notice Whitelist an address to allow transfer of Temple Gold to or from
* @param _contract Contract address to whitelist
* @param _whitelist Boolean whitelist state
*/
function authorizeContract(address _contract, bool _whitelist) external onlyOwner {
if (_contract == address(0)) { revert CommonEventsAndErrors.InvalidAddress(); }
authorized[_contract] = _whitelist;
emit ContractAuthorizationSet(_contract, _whitelist);
}

/**
* @notice Mint new tokens to be distributed. Open to call from any address
* Enforces minimum mint amount and uses vesting factor to calculate mint token amount.
* Minting is only possible on source chain Arbitrum
*/
function mint(address to, uint256 amount) external {
_mint(to, amount);
}

/**
* @notice Get circulating supply across chains
* @return Circulating supply
*/
function circulatingSupply() public view returns (uint256) {
return totalSupply();
}

/**
* @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
* (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
* this function.
*
* Emits a {Transfer} event.
*/
function _update(address from, address to, uint256 value) internal override {
/// can only transfer to or from whitelisted addreess
/// @dev skip check on mint and burn. function `send` checks from == to
if (from != address(0) && to != address(0)) {
if (!authorized[from] && !authorized[to]) { revert ITempleGold.NonTransferrable(from, to); }
}
super._update(from, to, value);
}

/// @notice Overriden OFT functions

/**
* @dev Executes the send operation.
* @param _sendParam The parameters for the send operation.
* @param _fee The calculated fee for the send() operation.
* - nativeFee: The native fee.
* - lzTokenFee: The lzToken fee.
* @param _refundAddress The address to receive any excess funds.
* @return msgReceipt The receipt for the send operation.
* @return oftReceipt The OFT receipt information.
*
* @dev MessagingReceipt: LayerZero msg receipt
* - guid: The unique identifier for the sent message.
* - nonce: The nonce of the sent message.
* - fee: The LayerZero fee incurred for the message.
*/
function send(
SendParam calldata _sendParam,
MessagingFee calldata _fee,
address _refundAddress
) external payable virtual override returns (MessagingReceipt memory msgReceipt, OFTReceipt memory oftReceipt) {
/// cast bytes32 to address
// address _to = address(uint160(uint256(_sendParam.to)));
address _to = _sendParam.to.bytes32ToAddress();
/// @dev user can cross-chain transfer to either whitelisted or self
if (msg.sender != _to) { revert ITempleGold.NonTransferrable(msg.sender, _to); }

// @dev Applies the token transfers regarding this send() operation.
// - amountSentLD is the amount in local decimals that was ACTUALLY sent/debited from the sender.
// - amountReceivedLD is the amount in local decimals that will be received/credited to the recipient on the remote OFT instance.
(uint256 amountSentLD, uint256 amountReceivedLD) = _debit(
msg.sender,
_sendParam.amountLD,
_sendParam.minAmountLD,
_sendParam.dstEid
);

// @dev Builds the options and OFT message to quote in the endpoint.
(bytes memory message, bytes memory options) = _buildMsgAndOptions(_sendParam, amountReceivedLD);

// @dev Sends the message to the LayerZero endpoint and returns the LayerZero msg receipt.
msgReceipt = _lzSend(_sendParam.dstEid, message, options, _fee, _refundAddress);
// @dev Formulate the OFT receipt.
oftReceipt = OFTReceipt(amountSentLD, amountReceivedLD);

emit OFTSent(msgReceipt.guid, _sendParam.dstEid, msg.sender, amountSentLD, amountReceivedLD);
}

/**
* @dev Internal function to handle the receive on the LayerZero endpoint.
* @param _origin The origin information.
* - srcEid: The source chain endpoint ID.
* - sender: The sender address from the src chain.
* - nonce: The nonce of the LayerZero message.
* @param _guid The unique identifier for the received LayerZero message.
* @param _message The encoded message.
* @dev _executor The address of the executor.
* @dev _extraData Additional data.
*/
function _lzReceive(
Origin calldata _origin,
bytes32 _guid,
bytes calldata _message,
address /*_executor*/, // @dev unused in the default implementation.
bytes calldata /*_extraData*/ // @dev unused in the default implementation.
) internal virtual override {
// @dev The src sending chain doesnt know the address length on this chain (potentially non-evm)
// Thus everything is bytes32() encoded in flight.
address toAddress = _message.sendTo().bytes32ToAddress();
// @dev Credit the amountLD to the recipient and return the ACTUAL amount the recipient received in local decimals
uint256 amountReceivedLD = _credit(toAddress, _toLD(_message.amountSD()), _origin.srcEid);

/// @dev Disallow further execution on destination by ignoring composed message

emit OFTReceived(_guid, _origin.srcEid, toAddress, amountReceivedLD);
}
}
28 changes: 28 additions & 0 deletions protocol/contracts/fakes/templegold/TempleTokenMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
pragma solidity ^0.8.20;
// SPDX-License-Identifier: AGPL-3.0-or-later

import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import { ERC20Burnable} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { AccessControl } from "@openzeppelin/contracts/access/AccessControl.sol";

contract TempleTokenMock is ERC20, ERC20Burnable, Ownable, AccessControl {
bytes32 public constant CAN_MINT = keccak256("CAN_MINT");

constructor() ERC20("Temple", "TEMPLE") Ownable(msg.sender) {
_grantRole(DEFAULT_ADMIN_ROLE, owner());
}

function mint(address to, uint256 amount) external {
require(hasRole(CAN_MINT, msg.sender), "Caller cannot mint");
_mint(to, amount);
}

function addMinter(address account) external onlyOwner {
grantRole(CAN_MINT, account);
}

function removeMinter(address account) external onlyOwner {
revokeRole(CAN_MINT, account);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.8.20;
pragma solidity ^0.8.20;
// SPDX-License-Identifier: AGPL-3.0-or-later

import { ITempleDebtToken } from "contracts/interfaces/v2/ITempleDebtToken.sol";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.8.20;
pragma solidity ^0.8.20;
// SPDX-License-Identifier: AGPL-3.0-or-later
// Temple (v2/strategies/DSRStrategy.sol)

Expand Down
2 changes: 1 addition & 1 deletion protocol/contracts/interfaces/core/IMultiOtcOffer.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma solidity 0.8.20;
princetonbishop marked this conversation as resolved.
Show resolved Hide resolved
// SPDX-License-Identifier: AGPL-3.0-or-later
// Temple (interfaces/IMultiOtcOffer.sol)
// Temple (interfaces/core/IMultiOtcOffer.sol)

import { IERC20Metadata } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
interface IMultiOtcOffer {
Expand Down
2 changes: 1 addition & 1 deletion protocol/contracts/interfaces/core/ITempleERC20Token.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.8.20;
pragma solidity ^0.8.20;
// SPDX-License-Identifier: AGPL-3.0-or-later
// Temple (interfaces/core/ITempleERC20Token.sol)

Expand Down
66 changes: 66 additions & 0 deletions protocol/contracts/interfaces/templegold/IAuctionBase.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
pragma solidity ^0.8.20;
// SPDX-License-Identifier: AGPL-3.0-or-later
// Temple (interfaces/templegold/IAuctionBase.sol)


interface IAuctionBase {
event Deposit(address indexed depositor, uint256 epochId, uint256 amount);
event Claim(address indexed user, uint256 epochId, uint256 bidTokenAmount, uint256 auctionTokenAmount);
event AuctionStarted(uint256 epochId, address indexed starter, uint128 startTime, uint128 endTime, uint256 auctionTokenAmount);

error CannotDeposit();
error CannotClaim(uint256 epochId);
error CannotStartAuction();
error InvalidEpoch();
error AuctionActive();
error InvalidOperation();

struct EpochInfo {
/// @notice Start time for epoch
uint128 startTime;
/// @notice End time for epoch
uint128 endTime;
/// @notice Total amount of bid token deposited
uint256 totalBidTokenAmount;
/// @notice Total amount of auction tokens to distribute. Constant value
uint256 totalAuctionTokenAmount;
}

/// @notice Keep track of epochs details
function getEpochInfo(uint256 epochId) external returns (EpochInfo memory);
/// @notice Keep track of depositors for each epoch
function depositors(address depositor, uint256 epochId) external returns (uint256);

/**
* @notice Deposit bid token for current running epoch auction
* @param amount Amount of bid token to deposit
*/
function bid(uint256 amount) external;

/**
* @notice Claim share of Temple Gold for epoch
* Can only claim for past epochs, not current auction epoch.
* @param epochId Id of epoch
*/
function claim(uint256 epochId) external;

/**
* @notice Start auction. Auction start can be triggered by anyone if `auctionStarter` not set
* Uses up to date distributed Temple Gold tokens since last auction as total Temple Gold for distribution
*/
function startAuction() external;

/**
* @notice Get current epoch
* @return Epoch Id
*/
function currentEpoch() external view returns (uint256);

/**
* @notice Recover auction tokens for last but not started auction
* @param token Token to recover
* @param to Recipient
* @param amount Amount to auction tokens
*/
function recoverToken(address token, address to, uint256 amount) external;
}
Loading
Loading