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 196 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: 2 additions & 0 deletions .github/workflows/protocol-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
working-directory: protocol
env:
TESTS_MAINNET_RPC_URL: ${{ secrets.TESTS_MAINNET_RPC_URL }}
ARBITRUM_ONE_RPC_URL: ${{ secrets.TESTS_ARBITRUM_ONE_RPC_URL }}

foundryTests:
name: Foundry Tests
Expand Down Expand Up @@ -106,6 +107,7 @@ jobs:
env:
FOUNDRY_PROFILE: ci
MAINNET_RPC_URL: ${{ secrets.TESTS_MAINNET_RPC_URL }}
ARBITRUM_ONE_RPC_URL: ${{ secrets.TESTS_ARBITRUM_ONE_RPC_URL }}

slither:
name: Slither
Expand Down
5 changes: 4 additions & 1 deletion protocol/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ lcov.info
report

# autogenerated fork args
scripts/deploys/localhost/deploymentArgs
scripts/deploys/localhost/deploymentArgs

# templegold scripts
test/forge/templegold/scripts/
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;
}
}
}
86 changes: 86 additions & 0 deletions protocol/contracts/common/access/ElevatedAccess.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
pragma solidity ^0.8.20;
// SPDX-License-Identifier: AGPL-3.0-or-later
// Temple (common/access/ElevatedAccess.sol)

import { CommonEventsAndErrors } from "contracts/common/CommonEventsAndErrors.sol";
import { IElevatedAccess } from "contracts/interfaces/common/access/IElevatedAccess.sol";

/**
* @notice Inherit to add Owner roles for DAO elevated access.
*/
abstract contract ElevatedAccess is IElevatedAccess {
/**
* @notice The address of the current owner.
*/
address public override owner;

/**
* @notice Explicit approval for an address to execute a function.
* allowedCaller => function selector => true/false
*/
mapping(address => mapping(bytes4 => bool)) public override explicitFunctionAccess;

/// @dev Track proposed owner
address private _proposedNewOwner;

function _init(address initialOwner) internal {
if (owner != address(0)) revert CommonEventsAndErrors.InvalidAccess();
if (initialOwner == address(0)) revert CommonEventsAndErrors.InvalidAddress();
owner = initialOwner;
}

/**
* @notice Proposes a new Owner.
* Can only be called by the current owner
*/
function proposeNewOwner(address account) external override onlyElevatedAccess {
if (account == address(0)) revert CommonEventsAndErrors.InvalidAddress();
emit NewOwnerProposed(owner, _proposedNewOwner, account);
_proposedNewOwner = account;
}

/**
* @notice Caller accepts the role as new Owner.
* Can only be called by the proposed owner
*/
function acceptOwner() external override {
if (msg.sender != _proposedNewOwner) revert CommonEventsAndErrors.InvalidAccess();

emit NewOwnerAccepted(owner, msg.sender);
owner = msg.sender;
delete _proposedNewOwner;
}

/**
* @notice Grant `allowedCaller` the rights to call the function selectors in the access list.
* @dev fnSelector == bytes4(keccak256("fn(argType1,argType2,...)"))
*/
function setExplicitAccess(address allowedCaller, ExplicitAccess[] calldata access) external override onlyElevatedAccess {
if (allowedCaller == address(0)) revert CommonEventsAndErrors.InvalidAddress();
uint256 _length = access.length;
ExplicitAccess memory _access;
for (uint256 i; i < _length; ++i) {
_access = access[i];
emit ExplicitAccessSet(allowedCaller, _access.fnSelector, _access.allowed);
explicitFunctionAccess[allowedCaller][_access.fnSelector] = _access.allowed;
}
}

function isElevatedAccess(address caller, bytes4 fnSelector) internal view returns (bool) {
return (
caller == owner ||
explicitFunctionAccess[caller][fnSelector]
);
}

/**
* @notice The owner is allowed to call, or if explicit access has been given to the caller.
* @dev Important: Only for use when called from an *external* contract.
* If a function with this modifier is called internally then the `msg.sig`
* will still refer to the top level externally called function.
*/
modifier onlyElevatedAccess() {
if (!isElevatedAccess(msg.sender, msg.sig)) revert CommonEventsAndErrors.InvalidAccess();
_;
}
}
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
125 changes: 125 additions & 0 deletions protocol/contracts/fakes/templegold/SpiceAuctionMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
pragma solidity ^0.8.18;
// SPDX-License-Identifier: AGPL-3.0-or-later
// Temple (templegold/SpiceAuctionMock.sol)


import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { CommonEventsAndErrors } from "contracts/common/CommonEventsAndErrors.sol";
import { ITempleGold } from "contracts/interfaces/templegold/ITempleGold.sol";
import { SendParam } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oft/interfaces/IOFT.sol";
import { MessagingFee } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oft/OFTCore.sol";
import { OptionsBuilder } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/libs/OptionsBuilder.sol";

/**
* @title SpiceAuction
* @notice Temple Gold is deposited into this contract to bid on a share of distributed Spice token,
* or vice versa, for an epoch. Temple Gold can be the bid or auction token at any auction epoch.
* Reward tokens acquired in past epochs can always be claimed. Once bid, users cannot
* claim their bid token and can only claim their share of reward token for epoch after epoch finishes.
* Bid and auction tokens could change per auction. These are set in `AuctionConfig`.
* Config is set before the next auction starts using `setAuctionConfig` by DAO execution.
*/
contract SpiceAuctionMock {
using SafeERC20 for IERC20;
using OptionsBuilder for bytes;

/// @notice Temple GOLD
address public immutable templeGold;

/// @notice Auctions run for minimum 1 week
uint32 public constant MINIMUM_AUCTION_PERIOD = 1 weeks;
/// @notice Maximum wait period between last and next auctions
uint32 public constant MAXIMUM_AUCTION_WAIT_PERIOD = 90 days;
/// @notice Maximum auction duration
uint32 public constant MAXIMUM_AUCTION_DURATION = 30 days;
uint32 private immutable _arbitrumOneLzEid;
uint32 private immutable _mintChainId;
uint32 public lzReceiveExecutorGas;

/// @notice If true, let first claim for an auction notify total TGLD redeemed
bool public claimShouldNotifyTotalRedeemed;

/// @notice Name of this Spice Bazaar auction
string public name;

/// @notice Last time auction was started. For zero auctions, it is the contract deploy timestamp
uint256 private immutable _deployTimestamp;

event RedeemedTempleGoldBurned(uint256 amount);
error ExpectedNonZero();
error WithdrawFailed(uint256 amount);

constructor(
address _templeGold,
uint32 _arbEid,
uint32 mintChainId_,
string memory _name
) {
templeGold = _templeGold;
_arbitrumOneLzEid = _arbEid;
_mintChainId = mintChainId_;
name = _name;
_deployTimestamp = block.timestamp;
lzReceiveExecutorGas = 85_412;
}

/// @notice withdraw ETH used for layer zero sends
function withdrawEth(address payable _to, uint256 _amount) external {
(bool success,) = _to.call{ value: _amount }("");
if (!success) { revert WithdrawFailed(_amount); }
}

/**
* @notice Burn redeemd TGLD and notify circulating supply
* @param amount Amount
* @param useContractEth If to use contract eth for layerzero send
*/
function burnAndNotify(uint256 amount, bool useContractEth) external payable {
if (amount == 0) { revert ExpectedNonZero(); }

emit RedeemedTempleGoldBurned(amount);
_burnAndNotify(amount, useContractEth);
}

function _burnAndNotify(uint256 amount, bool useContractEth) private {
// burn directly and call TempleGold to update circulating supply
if (block.chainid == _mintChainId) {
ITempleGold(templeGold).burn(amount);
return;
}
bytes memory options = OptionsBuilder.newOptions().addExecutorLzReceiveOption(lzReceiveExecutorGas, 0);
SendParam memory sendParam = SendParam(
_arbitrumOneLzEid, //<ARB_EID>,
bytes32(uint256(uint160(address(0)))), // bytes32(address(0)) to burn
amount,
0,
options,
bytes(""), // compose message
""
);
MessagingFee memory fee = ITempleGold(templeGold).quoteSend(sendParam, false);
if (useContractEth && address(this).balance < fee.nativeFee) {
revert CommonEventsAndErrors.InsufficientBalance(address(0), fee.nativeFee, address(this).balance);
} else if (!useContractEth && msg.value < fee.nativeFee) {
revert CommonEventsAndErrors.InsufficientBalance(address(0), fee.nativeFee, msg.value);
}

if (useContractEth) {
ITempleGold(templeGold).send{ value: fee.nativeFee }(sendParam, fee, payable(address(this)));
} else {
ITempleGold(templeGold).send{ value: fee.nativeFee }(sendParam, fee, payable(msg.sender));
uint256 leftover;
unchecked {
leftover = msg.value - fee.nativeFee;
}
if (leftover > 0) {
(bool success,) = payable(msg.sender).call{ value: leftover }("");
if (!success) { revert WithdrawFailed(leftover); }
}
}
}

// allow this contract to receive ether
receive() external payable {}
}
Loading