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

USTB GSM Implementation #431

Closed
wants to merge 72 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
ab52741
feat: skeleton for GsmConverter buyAsset
yan-man Aug 30, 2024
b102136
fix: resolve compilation issues
yan-man Sep 4, 2024
dd74cc2
feat: initialize interface
yan-man Sep 4, 2024
023a6b4
refactor: move files to separate directory
yan-man Sep 4, 2024
750eb61
fix: resolve interface function visibility
yan-man Sep 4, 2024
038e3be
test: initialize constructor unit test
yan-man Sep 4, 2024
c574b35
test: testRevertConstructorZeroAddressParams;
yan-man Sep 4, 2024
56ab408
test: initialize BUIDL-specific test GSM
yan-man Sep 5, 2024
5760379
test: add check on buyAsset for minAmount
yan-man Sep 5, 2024
bb08c59
test: happy path for converter buyAsset
yan-man Sep 5, 2024
eb4a888
test: events testing + happy path buyAsset
yan-man Sep 5, 2024
8ca6481
test: test revert cases
yan-man Sep 5, 2024
2942b36
fix: resolve tests involving facilitator due to new one added
yan-man Sep 5, 2024
ebca6d7
fix: resolve fuzz test input with zero address
yan-man Sep 5, 2024
cff5b1f
feat: rescueTokens implementation + tests
yan-man Sep 5, 2024
4d2abe2
fix: convert to Ownable
yan-man Sep 6, 2024
2faf8a6
fix: validate calculated ghoAmount matches ghoSold, reset approvals, …
yan-man Sep 6, 2024
bc05a7d
test: create mockGSM to test unmatching gho amount case
yan-man Sep 6, 2024
0c1beb2
refactor: methods re-order
yan-man Sep 6, 2024
117eda8
refactor: rename mock
yan-man Sep 6, 2024
4f4603c
test: test coverage for remaining token balances
yan-man Sep 6, 2024
1dbff49
feat: init buyAssetWithSig
yan-man Sep 6, 2024
bce34e7
test: happy path test for buyAssetWithSig
yan-man Sep 7, 2024
62657ee
test: simplify testBuyAssetWithSig, add testBuyAssetWithSigExactDeadline
yan-man Sep 9, 2024
522ada9
test: add testRevertBuyAssetWithSigExpiredSignature
yan-man Sep 9, 2024
b60751d
test: add testRevertBuyAssetWithSigInvalidSignature
yan-man Sep 9, 2024
6d90a66
test: add testRevertBuyAssetWithSigInvalidAmount
yan-man Sep 9, 2024
ea90912
test: refer to proper value for BUIDL gsm exposure
yan-man Sep 9, 2024
c9140c5
test: resolve test assertion on remaining gsm gho balance
yan-man Sep 9, 2024
14fc942
test: clean up assertion failure messages, reference different test v…
yan-man Sep 9, 2024
0ba7d24
refactor: code segmentation
yan-man Sep 9, 2024
1d0e326
test: fuzz test on minAssetAmount values
yan-man Sep 9, 2024
fdd0046
feat: init sellAsset functionality with mock
yan-man Sep 10, 2024
4e40559
refactor: rename vars, update docs
yan-man Sep 10, 2024
aa30e1b
test: add docs for mock redemption
yan-man Sep 10, 2024
3b96732
feat: skeleton for sellAsset implementation
yan-man Sep 10, 2024
d79ebde
feat: add remappings for mocks
yan-man Sep 10, 2024
80a2c72
test: resolve test compilations with additional constructor param
yan-man Sep 10, 2024
2f94eaa
test: happy path sellAsset emitting events
yan-man Sep 10, 2024
206160e
test: add happy path sellAsset assertions
yan-man Sep 10, 2024
acc78ca
test: invalid redemption
yan-man Sep 10, 2024
59d7291
test: fail cases for sellAsset with invalid asset amounts, add mocks
yan-man Sep 10, 2024
71b8641
refactor: rename redeemable asset to issued asset to be more correct
yan-man Sep 10, 2024
43187e6
test: declare new typehash specific for converter, init happy path se…
yan-man Sep 10, 2024
cd76351
refactor: reference mock contract directly
yan-man Sep 10, 2024
cb7b33b
refactor: re-order assertions
yan-man Sep 10, 2024
15e862a
test: fail cases for sellAssetWithSig
yan-man Sep 11, 2024
409944b
refactor: capitalize variable name
yan-man Sep 11, 2024
7b96c4c
refactor: use more precise variable reference
yan-man Sep 11, 2024
74da86e
test: add testRevertSellAssetWithSigInvalidAmount
yan-man Sep 11, 2024
f0c35fd
test: add testBuyAssetWithDonatedTokens
yan-man Sep 11, 2024
57df1d7
test: add testSellAssetDonatedTokens
yan-man Sep 11, 2024
4b1ed4e
test: fuzz for donated token amounts
yan-man Sep 11, 2024
fdc083e
test: clean up var references and add testFuzzSellAssetMaxAmount
yan-man Sep 11, 2024
df84a21
test: clean up var reference
yan-man Sep 11, 2024
91fb7b9
test: add fuzz tests, testRevertSellAssetWithSigInvalidNonce
yan-man Sep 11, 2024
655b0b0
test: add testRevertBuyAssetWithSigInvalidNonce
yan-man Sep 11, 2024
d0f89f2
test: remove mock test files from coverage
yan-man Sep 11, 2024
8a47c39
fix: remove need to upgrade gsm to trigger error
yan-man Sep 18, 2024
6e208a2
Merge branch 'main' into feat/gsm-buidl
yan-man Sep 18, 2024
3d7cbb0
feat: init GsmConverter overview doc
yan-man Sep 24, 2024
feeda78
test: reduce unneeded mock code for MockGsmFailedSellAssetRemainingGh…
yan-man Sep 25, 2024
53dc395
refactor: rename subscription event
yan-man Oct 14, 2024
b48a0be
test: resolve tests from event change, rename mock files to be BUIDL-…
yan-man Oct 14, 2024
ae2dec4
Merge branch 'main' into feat/gsm-buidl
yan-man Oct 14, 2024
72ee91d
refactor: rename issuance to subscription
yan-man Oct 14, 2024
9a686d3
test: add mock USTB subscription/redemption contract
yan-man Oct 14, 2024
16a5d59
feat: add todo notes on subscription fees
yan-man Oct 14, 2024
c943e73
fix: account for subscription fee, resolve tests, param names
yan-man Oct 14, 2024
0201eea
test: end prank
yan-man Oct 15, 2024
a32f7ee
Merge branch 'feat/gsm-buidl' into feat/gsm-ustb
yan-man Oct 15, 2024
a7a828f
test: update mock comments
yan-man Oct 15, 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
Prev Previous commit
Next Next commit
test: resolve tests from event change, rename mock files to be BUIDL-…
…specific
yan-man committed Oct 14, 2024
commit b48a0be3d955533215d34bf72f6da394f3ee639c
4 changes: 2 additions & 2 deletions src/contracts/facilitators/gsm/converter/GsmConverter.sol
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ import {IGsm} from '../interfaces/IGsm.sol';
import {IGsmConverter} from './interfaces/IGsmConverter.sol';
import {IRedemption} from '../dependencies/circle/IRedemption.sol';
// TODO: replace with proper issuance implementation later
import {MockIssuanceReceiver} from '../../../../test/mocks/MockIssuanceReceiver.sol';
import {MockBUIDLIssuanceReceiver} from '../../../../test/mocks/MockBUIDLIssuanceReceiver.sol';

import 'forge-std/console2.sol';

@@ -234,7 +234,7 @@ contract GsmConverter is Ownable, EIP712, IGsmConverter {
IERC20(REDEEMED_ASSET).transferFrom(originator, address(this), redeemedAssetAmount);
IERC20(REDEEMED_ASSET).approve(ISSUANCE_RECEIVER_CONTRACT, redeemedAssetAmount);
//TODO: replace with proper issuance implementation later
MockIssuanceReceiver(ISSUANCE_RECEIVER_CONTRACT).issuance(redeemedAssetAmount);
MockBUIDLIssuanceReceiver(ISSUANCE_RECEIVER_CONTRACT).issuance(redeemedAssetAmount);
require(
IERC20(ISSUED_ASSET).balanceOf(address(this)) ==
initialissuedAssetBalance + redeemedAssetAmount,
18 changes: 9 additions & 9 deletions src/test/TestGhoBase.t.sol
Original file line number Diff line number Diff line change
@@ -34,9 +34,9 @@ import {WETH9Mock} from '@aave/periphery-v3/contracts/mocks/WETH9Mock.sol';
import {MockRedemption} from './mocks/MockRedemption.sol';
import {MockRedemptionFailedIssuedAssetAmount} from './mocks/MockRedemptionFailedIssuedAssetAmount.sol';
import {MockRedemptionFailed} from './mocks/MockRedemptionFailed.sol';
import {MockIssuanceReceiver} from './mocks/MockIssuanceReceiver.sol';
import {MockIssuanceReceiverFailed} from './mocks/MockIssuanceReceiverFailed.sol';
import {MockIssuanceReceiverFailedInvalidUSDCAccepted} from './mocks/MockIssuanceReceiverFailedInvalidUSDCAccepted.sol';
import {MockBUIDLIssuanceReceiver} from './mocks/MockBUIDLIssuanceReceiver.sol';
import {MockBUIDLIssuanceReceiverFailed} from './mocks/MockBUIDLIssuanceReceiverFailed.sol';
import {MockBUIDLIssuanceReceiverFailedInvalidUSDCAccepted} from './mocks/MockBUIDLIssuanceReceiverFailedInvalidUSDCAccepted.sol';
import {MockPoolDataProvider} from './mocks/MockPoolDataProvider.sol';

// interfaces
@@ -128,9 +128,9 @@ contract TestGhoBase is Test, Constants, Events {
MockRedemption BUIDL_USDC_REDEMPTION;
MockRedemptionFailedIssuedAssetAmount BUIDL_USDC_REDEMPTION_FAILED_ISSUED_ASSET_AMOUNT;
MockRedemptionFailed BUIDL_USDC_REDEMPTION_FAILED;
MockIssuanceReceiver BUIDL_USDC_ISSUANCE;
MockIssuanceReceiverFailed BUIDL_USDC_ISSUANCE_FAILED;
MockIssuanceReceiverFailedInvalidUSDCAccepted BUIDL_USDC_ISSUANCE_FAILED_INVALID_USDC;
MockBUIDLIssuanceReceiver BUIDL_USDC_ISSUANCE;
MockBUIDLIssuanceReceiverFailed BUIDL_USDC_ISSUANCE_FAILED;
MockBUIDLIssuanceReceiverFailedInvalidUSDCAccepted BUIDL_USDC_ISSUANCE_FAILED_INVALID_USDC;
PriceOracle PRICE_ORACLE;
WETH9Mock WETH;
GhoVariableDebtToken GHO_DEBT_TOKEN;
@@ -408,12 +408,12 @@ contract TestGhoBase is Test, Constants, Events {
address(BUIDL_TOKEN),
address(USDC_TOKEN)
);
BUIDL_USDC_ISSUANCE = new MockIssuanceReceiver(address(BUIDL_TOKEN), address(USDC_TOKEN));
BUIDL_USDC_ISSUANCE_FAILED = new MockIssuanceReceiverFailed(
BUIDL_USDC_ISSUANCE = new MockBUIDLIssuanceReceiver(address(BUIDL_TOKEN), address(USDC_TOKEN));
BUIDL_USDC_ISSUANCE_FAILED = new MockBUIDLIssuanceReceiverFailed(
address(BUIDL_TOKEN),
address(USDC_TOKEN)
);
BUIDL_USDC_ISSUANCE_FAILED_INVALID_USDC = new MockIssuanceReceiverFailedInvalidUSDCAccepted(
BUIDL_USDC_ISSUANCE_FAILED_INVALID_USDC = new MockBUIDLIssuanceReceiverFailedInvalidUSDCAccepted(
address(BUIDL_TOKEN),
address(USDC_TOKEN)
);
16 changes: 8 additions & 8 deletions src/test/TestGsmConverter.t.sol
Original file line number Diff line number Diff line change
@@ -122,7 +122,7 @@ contract TestGsmConverter is TestGhoBase {
USDC_TOKEN.approve(address(GSM_CONVERTER), expectedIssuedAssetAmount);

vm.expectEmit(true, true, true, true, address(GSM_CONVERTER));
emit SellAssetThroughIssuance(ALICE, ALICE, expectedIssuedAssetAmount, expectedGhoBought);
emit SellAssetThroughSubscription(ALICE, ALICE, expectedIssuedAssetAmount, expectedGhoBought);
(uint256 assetAmount, uint256 ghoBought) = GSM_CONVERTER.sellAsset(
DEFAULT_GSM_BUIDL_AMOUNT,
ALICE
@@ -200,7 +200,7 @@ contract TestGsmConverter is TestGhoBase {
USDC_TOKEN.approve(address(GSM_CONVERTER), expectedIssuedAssetAmount);

vm.expectEmit(true, true, true, true, address(GSM_CONVERTER));
emit SellAssetThroughIssuance(ALICE, BOB, expectedIssuedAssetAmount, expectedGhoBought);
emit SellAssetThroughSubscription(ALICE, BOB, expectedIssuedAssetAmount, expectedGhoBought);
(uint256 assetAmount, uint256 ghoBought) = GSM_CONVERTER.sellAsset(
DEFAULT_GSM_BUIDL_AMOUNT,
BOB
@@ -288,7 +288,7 @@ contract TestGsmConverter is TestGhoBase {
USDC_TOKEN.approve(address(GSM_CONVERTER), expectedIssuedAssetAmount);

vm.expectEmit(true, true, true, true, address(GSM_CONVERTER));
emit SellAssetThroughIssuance(ALICE, ALICE, expectedIssuedAssetAmount, expectedGhoBought);
emit SellAssetThroughSubscription(ALICE, ALICE, expectedIssuedAssetAmount, expectedGhoBought);
(uint256 assetAmount, uint256 ghoBought) = GSM_CONVERTER.sellAsset(
DEFAULT_GSM_BUIDL_AMOUNT,
ALICE
@@ -367,7 +367,7 @@ contract TestGsmConverter is TestGhoBase {
USDC_TOKEN.approve(address(GSM_CONVERTER), expectedIssuedAssetAmount);

vm.expectEmit(true, true, true, true, address(GSM_CONVERTER));
emit SellAssetThroughIssuance(ALICE, ALICE, expectedIssuedAssetAmount, expectedGhoBought);
emit SellAssetThroughSubscription(ALICE, ALICE, expectedIssuedAssetAmount, expectedGhoBought);
(uint256 assetAmount, uint256 ghoBought) = GSM_CONVERTER.sellAsset(maxAmount, ALICE);
vm.stopPrank();

@@ -452,7 +452,7 @@ contract TestGsmConverter is TestGhoBase {
USDC_TOKEN.approve(address(GSM_CONVERTER), expectedIssuedAssetAmount);

vm.expectEmit(true, true, true, true, address(GSM_CONVERTER));
emit SellAssetThroughIssuance(ALICE, ALICE, expectedIssuedAssetAmount, expectedGhoBought);
emit SellAssetThroughSubscription(ALICE, ALICE, expectedIssuedAssetAmount, expectedGhoBought);
(uint256 assetAmount, uint256 ghoBought) = GSM_CONVERTER.sellAsset(
DEFAULT_GSM_BUIDL_AMOUNT,
ALICE
@@ -633,7 +633,7 @@ contract TestGsmConverter is TestGhoBase {

vm.prank(ALICE);
vm.expectEmit(true, true, true, true, address(GSM_CONVERTER));
emit SellAssetThroughIssuance(
emit SellAssetThroughSubscription(
gsmConverterSignerAddr,
gsmConverterSignerAddr,
expectedIssuedAssetAmount,
@@ -760,7 +760,7 @@ contract TestGsmConverter is TestGhoBase {

vm.prank(ALICE);
vm.expectEmit(true, true, true, true, address(GSM_CONVERTER));
emit SellAssetThroughIssuance(
emit SellAssetThroughSubscription(
gsmConverterSignerAddr,
gsmConverterSignerAddr,
expectedIssuedAssetAmount,
@@ -892,7 +892,7 @@ contract TestGsmConverter is TestGhoBase {

vm.prank(ALICE);
vm.expectEmit(true, true, true, true, address(GSM_CONVERTER));
emit SellAssetThroughIssuance(
emit SellAssetThroughSubscription(
gsmConverterSignerAddr,
gsmConverterSignerAddr,
expectedIssuedAssetAmount,
2 changes: 1 addition & 1 deletion src/test/helpers/Events.sol
Original file line number Diff line number Diff line change
@@ -118,7 +118,7 @@ interface Events {
uint256 issuedAssetAmount,
uint256 ghoAmount
);
event SellAssetThroughIssuance(
event SellAssetThroughSubscription(
address indexed originator,
address indexed receiver,
uint256 redeemedAssetAmount,
Original file line number Diff line number Diff line change
@@ -4,9 +4,9 @@ import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';

/**
* @title MockIssuanceReceiver
* @title MockBUIDLIssuanceReceiver
*/
contract MockIssuanceReceiver {
contract MockBUIDLIssuanceReceiver {
using SafeERC20 for IERC20;

address public immutable asset;
Original file line number Diff line number Diff line change
@@ -4,9 +4,9 @@ import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';

/**
* @title MockIssuanceReceiverFailed
* @title MockBUIDLIssuanceReceiverFailed
*/
contract MockIssuanceReceiverFailed {
contract MockBUIDLIssuanceReceiverFailed {
using SafeERC20 for IERC20;

address public immutable asset;
Original file line number Diff line number Diff line change
@@ -4,10 +4,10 @@ import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import {SafeERC20} from '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';

/**
* @title MockIssuanceReceiverFailedInvalidUSDCAccepted
* @title MockBUIDLIssuanceReceiverFailedInvalidUSDCAccepted
* @dev During issuance, the contract does not accept the proper amount of USDC but issues asset properly
*/
contract MockIssuanceReceiverFailedInvalidUSDCAccepted {
contract MockBUIDLIssuanceReceiverFailedInvalidUSDCAccepted {
using SafeERC20 for IERC20;

address public immutable asset;