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

[ETHEREUM-CONTRACTS] [GDA] Fixes for GDA #1729

Merged
merged 75 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
9bba415
[ETHEREUM-CONTRACTS] BatchLiquidator: don't revert for non-transferra…
d10r Oct 16, 2023
2da9bb9
patch getUnderlyingToken (#1718)
0xdavinchee Oct 16, 2023
7177a50
Bump undici from 5.21.0 to 5.26.3 (#1719)
dependabot[bot] Oct 17, 2023
de7df25
add error hashes, use currentContext.timestamp
0xdavinchee Oct 17, 2023
1616671
use getHost.getTimestamp()
0xdavinchee Oct 17, 2023
72f1611
Bump @babel/traverse from 7.21.3 to 7.23.2 (#1723)
dependabot[bot] Oct 18, 2023
ffe6790
[SDK-CORE/ METADATA] SDK-Core No Governance Fix + Metadata Types (#1728)
0xdavinchee Oct 20, 2023
1798815
remove tests flakiness
0xdavinchee Oct 20, 2023
99e2d6d
remove forge.sh
0xdavinchee Oct 20, 2023
8ab5829
[SDK-CORE] GoodDollar sdk core fix (#1734)
0xdavinchee Oct 24, 2023
e8990d8
[ETHEREUM-CONTRACTS] make deploy script compatible with ethers v6 (#1…
0xdavinchee Oct 24, 2023
da9f3e6
update deploy.sh (#1738)
0xdavinchee Oct 27, 2023
ddc8213
Bump browserify-sign in /packages/sdk-core/previous-versions-testing …
dependabot[bot] Oct 30, 2023
99f4a68
Bump browserify-sign from 4.2.1 to 4.2.2 (#1739)
dependabot[bot] Oct 30, 2023
7f68614
fix verification script
d10r Oct 31, 2023
b50c82f
change GDA forwarder address (needed to redeploy)
d10r Oct 31, 2023
081415f
change GDA forwarder address for polygon-mumbai
d10r Nov 3, 2023
50c3ccf
fix tests to fuzz with different pool configs and fix distributeFlow …
0xdavinchee Nov 6, 2023
5bb4aa2
fix TOB-SUPERFLUID-2: Incorrect event emission in connectPool
0xdavinchee Nov 6, 2023
42e0448
fix TOB-SUPERFLUID-5: Large encoded buffer amount could manipulate pr…
0xdavinchee Nov 6, 2023
66bae97
fix TOB-SUPERFLUID-6: Off-by-one gas left check
0xdavinchee Nov 6, 2023
500e787
fix broken test
0xdavinchee Nov 6, 2023
ae6b2f1
wrangle with reducing the code size of GDA...
0xdavinchee Nov 6, 2023
5e1024b
cleanup
0xdavinchee Nov 6, 2023
23acb2c
fix build + tests
0xdavinchee Nov 6, 2023
86d0e27
cleanup
0xdavinchee Nov 6, 2023
761ce76
add update beacon proxy update paths
0xdavinchee Nov 8, 2023
a56dc42
fix broken deploy script, add tests, add transfer ownership of beacon…
0xdavinchee Nov 8, 2023
697e497
fix broken deploy script attempt 2
0xdavinchee Nov 8, 2023
3297168
[WORKFLOWS] Use nix in `handler.run-ethereum-contracts-script.yml` (#…
0xdavinchee Nov 14, 2023
4227f0a
[ETHEREUM-CONTRACTS] App credit test (#1743)
0xdavinchee Nov 14, 2023
2295e0f
add cliName (#1748)
0xdavinchee Nov 15, 2023
5389948
doConnect != isConnected fixed
0xdavinchee Nov 15, 2023
ce89da0
remove extra whitespace
0xdavinchee Nov 15, 2023
e345e10
add assertEq in SFGovII test and import PoolConfig in ISuperfluid for…
0xdavinchee Nov 15, 2023
3516a61
merge conflict resolved
0xdavinchee Nov 15, 2023
fffedd0
fix build
0xdavinchee Nov 15, 2023
eba67b0
merge metadata changes in
0xdavinchee Nov 15, 2023
10e8f9d
fuzzing fix
0xdavinchee Nov 15, 2023
570812f
EXPECT BREAKAGE IN FUZZ
0xdavinchee Nov 15, 2023
7efa597
fix build but echidna should break
0xdavinchee Nov 15, 2023
27ead42
undo breakage
0xdavinchee Nov 15, 2023
fd83f01
fix the test
0xdavinchee Nov 15, 2023
c6322e0
bump sdk-core version, fix sdk-core operation functions, fix subgraph…
0xdavinchee Nov 16, 2023
e44ec01
fix unit tests
0xdavinchee Nov 16, 2023
ce55850
fix again
0xdavinchee Nov 16, 2023
9f51f3e
hot fuzz additions
0xdavinchee Nov 17, 2023
bfa428c
[ETHEREUM-CONTRACTS] Fix canary build (#1742)
d10r Nov 20, 2023
8d7d403
distributeFlow: fix order of args to be consistent
d10r Nov 21, 2023
651cbe6
fix build
0xdavinchee Nov 22, 2023
9f32e90
add fix back in
0xdavinchee Nov 22, 2023
a98c3c6
[ETHEREUM-CONTRACTS] new resolver and loader, updated and bumped meta…
d10r Nov 24, 2023
9122e24
fix build
d10r Nov 24, 2023
690b599
new resolver and loader, refs #1004
d10r Nov 24, 2023
566fce8
remove getIsListed workaround assuming resolver exists (#1751)
0xdavinchee Nov 24, 2023
37038b4
merge dev
0xdavinchee Nov 24, 2023
b892785
fix broken unit test
0xdavinchee Nov 27, 2023
3cb0782
fix gda logic
0xdavinchee Nov 27, 2023
a429e11
[ETHEREUM-CONTRACTS] new resolver & loader address for mainnets (#1752)
d10r Nov 27, 2023
4065973
remove unimplemented function from yaml (#1753)
0xdavinchee Nov 28, 2023
7f2e5cf
map the name from subgraph to unknown entity (#1754)
kasparkallas Dec 1, 2023
886c0f1
Merge branch 'dev' into gda-fixes
hellwolf Dec 6, 2023
8516ec6
fix mapping
0xdavinchee Dec 7, 2023
a3a5a61
add total units
0xdavinchee Dec 11, 2023
9577da2
missing import
0xdavinchee Dec 11, 2023
655cc5b
missing import pt 2
0xdavinchee Dec 12, 2023
e3dcef5
[WORKFLOW] Subgraph deloy all networks (#1760)
mmd-afegbua Dec 14, 2023
b182e1d
fix
0xdavinchee Dec 14, 2023
e5da4ec
fix mapping (#1758)
0xdavinchee Dec 14, 2023
5f66bbb
added new supported subgraphs (#1761)
mmd-afegbua Dec 18, 2023
941f460
remove duplicate verification
d10r Jan 3, 2024
5526913
subgraph mapping addition
0xdavinchee Jan 3, 2024
1bf8e7c
type fix (#1771)
0xdavinchee Jan 4, 2024
abaeb14
readme fix
0xdavinchee Jan 5, 2024
a7e370a
Merge branch 'dev' into gda-fixes
0xdavinchee Jan 5, 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
4 changes: 2 additions & 2 deletions .github/workflows/ci.canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ jobs:
cloudfront_distribution_id: E3JEO5R14CT8IH

upgrade-contracts:
name: Upgrade ethereum-contracts on canary testnet (protocol release version "test")
name: Upgrade ethereum-contracts on canary testnet (protocol release version "canary")

needs: [all-packages-tested]

Expand Down Expand Up @@ -306,6 +306,6 @@ jobs:
npx truffle exec --network ${{ matrix.network }} ops-scripts/info-print-contract-addresses.js : addresses.vars
tasks/etherscan-verify-framework.sh ${{ matrix.network }} addresses.vars
env:
RELEASE_VERSION: master
RELEASE_VERSION: canary
AVALANCHE_FUJI_MNEMONIC: ${{ secrets.BUILD_AGENT_MNEMONIC }}
AVALANCHE_FUJI_PROVIDER_URL: ${{ secrets.AVALANCHE_FUJI_PROVIDER_URL }}
10 changes: 6 additions & 4 deletions .github/workflows/handler.deploy-to-testnets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ jobs:
DEFAULT_MNEMONIC: ${{ secrets.BUILD_AGENT_MNEMONIC }}
PROVIDER_URL_TEMPLATE: ${{ secrets.PROVIDER_URL_TEMPLATE }}

defaults:
run:
shell: nix develop -c bash -xe {0}

strategy:
fail-fast: false
matrix:
Expand All @@ -39,12 +43,10 @@ jobs:
if: ${{ github.event.inputs.only_network != '' && github.event.inputs.only_network != matrix.network }}
run: echo "DO_SKIP=1" >> "$GITHUB_ENV"

- name: Use Node.js 18.x
- uses: cachix/install-nix-action@v19
if: env.DO_SKIP != 1
uses: actions/setup-node@v3
with:
node-version: 18.x
cache: "yarn"
github_access_token: ${{ secrets.GITHUB_TOKEN }}

- name: Build
if: env.DO_SKIP != 1
Expand Down
12 changes: 7 additions & 5 deletions .github/workflows/handler.run-ethereum-contracts-script.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,21 @@ jobs:
run-ethereum-contracts-script:
runs-on: ubuntu-latest

defaults:
run:
shell: nix develop -c bash -xe {0}

env:
RELEASE_VERSION: ${{ github.event.inputs.release_version }}
RESOLVER_ADMIN_TYPE: ${{ github.event.inputs.admin_type }}
GOVERNANCE_ADMIN_TYPE: ${{ github.event.inputs.admin_type }}

steps:
- uses: actions/checkout@v3

- name: Use Node.js 18.x
uses: actions/setup-node@v3

- uses: cachix/install-nix-action@v19
with:
node-version: 18.x
cache: "yarn"
github_access_token: ${{ secrets.GITHUB_TOKEN }}

- name: Build
run: |
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<h1 align="center">Welcome to superfluid protocol-monorepo 👋</h1>

<p>
<a href="#superfluid-financeethereum-contracts" target="_blank">
<a href="#superfluid-finance/ethereum-contracts" target="_blank">
<img alt="npm" src="https://img.shields.io/npm/v/@superfluid-finance/ethereum-contracts?label=ethereum-contracts">
</a>
<a href="#superfluid-financesubgraph" target="_blank">
<a href="#superfluid-finance/subgraph" target="_blank">
<img alt="GitHub package.json version (subfolder of monorepo)" src="https://img.shields.io/github/package-json/v/superfluid-finance/protocol-monorepo?filename=packages%2Fsubgraph%2Fpackage.json&label=subgraph">
</a>
<a href="#superfluid-financejs-sdk" target="_blank">
<a href="#superfluid-finance/js-sdk" target="_blank">
<img alt="npm" src="https://img.shields.io/npm/v/@superfluid-finance/js-sdk?label=js-sdk">
</a>
<a href="#superfluid-financesdk-core" target="_blank">
<a href="#superfluid-finance/sdk-core" target="_blank">
<img alt="npm" src="https://img.shields.io/npm/v/@superfluid-finance/sdk-core?label=sdk-core">
</a>
<a href="#superfluid-financesdk-redux" target="_blank">
<a href="#superfluid-finance/sdk-redux" target="_blank">
<img alt="npm" src="https://img.shields.io/npm/v/@superfluid-finance/sdk-redux?label=sdk-redux">
</a>
<a href="#superfluid-financehot-fuzz" target="_blank">
<a href="#superfluid-finance/hot-fuzz" target="_blank">
<img alt="GitHub package.json version (subfolder of monorepo)" src="https://img.shields.io/github/package-json/v/superfluid-finance/protocol-monorepo?filename=packages%2Fhot-fuzz%2Fpackage.json&label=hot-fuzz">
</a>
<br>
Expand Down
2 changes: 1 addition & 1 deletion packages/automation-contracts/autowrap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"dependencies": {
"@openzeppelin/contracts": "4.9.3",
"@superfluid-finance/ethereum-contracts": "1.8.1",
"@superfluid-finance/metadata": "1.1.17"
"@superfluid-finance/metadata": "1.1.21"
}
}
2 changes: 1 addition & 1 deletion packages/automation-contracts/scheduler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"dependencies": {
"@openzeppelin/contracts": "4.9.3",
"@superfluid-finance/ethereum-contracts": "1.8.1",
"@superfluid-finance/metadata": "1.1.17"
"@superfluid-finance/metadata": "1.1.21"
}
}
7 changes: 7 additions & 0 deletions packages/ethereum-contracts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
## Unreleased

### Breaking

- `TokenInfo` and `ERC20WithTokenInfo` interface/abstract contract are removed from the codebase, including the bundled ABI contracts
- Migration: Use `IERC20Metadata` instead, as this replaces the previous contracts
- `build/typechain-ethers-v5` is removed from the npm package
Expand All @@ -25,13 +26,19 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Note that the admin is stored in the EIP-1967 admin storage slot (`0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`)
- `SuperToken.getAdmin()` added to retrieve the admin address
- `SuperTokenFactory.createERC20Wrapper()` overloads added to create a SuperToken AND explicitly initialize a SuperToken with an admin
- New explicit functions: `deployTestFrameworkWithEthersV5` and `deployTestFrameworkWithEthersV6` in `deploy-test-framework.js`
- `deployTestFramework` is still there, but it is considered deprecated now

### Changed

- Reuse config keys from `SuperfluidGovernanceConfigs` instead of duplicating them in `ConstantFlowAgreementV1`.
- Deprecating `registerAppWithKey` and `registerAppByFactory`: DO NOT USE for new deployments
- Simplification of Super App registration: use `registerApp` in all cases going forward.
- Use `registerApp(uint256 configWord)` to be called by the super app in the constructor or `registerApp(ISuperApp app, uint256 configWord)` to be called by any address with a valid app registration config key

### Fixes
- [`dev-scripts/deploy-test-framework.js`](dev-scripts/deploy-test-framework.js) compatible with both ethers-v5 and ethers-v6 now

## [v1.8.1] - 2023-08-28

### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,7 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
uint256 private constant _POOL_SUBS_BITMAP_STATE_SLOT_ID = 1;
/// @dev Pool member state slot id starting point for pool connections
uint256 private constant _POOL_CONNECTIONS_DATA_STATE_SLOT_ID_START = 1 << 128;
/// @dev CFAv1 PPP Config Key
bytes32 private constant CFAV1_PPP_CONFIG_KEY =
keccak256("org.superfluid-finance.agreements.ConstantFlowAgreement.v1.PPPConfiguration");

/// @dev SuperToken minimum deposit key
bytes32 private constant SUPERTOKEN_MINIMUM_DEPOSIT_KEY =
keccak256("org.superfluid-finance.superfluid.superTokenMinimumDeposit");

Expand All @@ -105,19 +102,21 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
superfluidPoolBeacon = superfluidPoolBeacon_;
}

function realtimeBalanceVectorAt(ISuperfluidToken token, address account, uint256 time)
function realtimeBalanceOf(ISuperfluidToken token, address account, uint256 time)
public
view
returns (int256 available, int256 fromPools, int256 buffer)
override
returns (int256 rtb, uint256 buf, uint256 owedBuffer)
{
UniversalIndexData memory universalIndexData = _getUIndexData(abi.encode(token), account);

if (_isPool(token, account)) {
available = ISuperfluidPool(account).getDisconnectedBalance(uint32(time));
rtb = ISuperfluidPool(account).getDisconnectedBalance(uint32(time));
} else {
available = Value.unwrap(_getBasicParticleFromUIndex(universalIndexData).rtb(Time.wrap(uint32(time))));
rtb = Value.unwrap(_getBasicParticleFromUIndex(universalIndexData).rtb(Time.wrap(uint32(time))));
}

int256 fromPools;
{
(uint32[] memory slotIds, bytes32[] memory pidList) = _listPoolConnectionIds(token, account);
for (uint256 i = 0; i < slotIds.length; ++i) {
Expand All @@ -126,24 +125,12 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
_getPoolMemberData(token, account, ISuperfluidPool(pool));
assert(exist);
assert(poolMemberData.pool == pool);
fromPools = fromPools + ISuperfluidPool(pool).getClaimable(account, uint32(time));
fromPools += ISuperfluidPool(pool).getClaimable(account, uint32(time));
}
}
rtb += fromPools;

buffer = universalIndexData.totalBuffer.toInt256();
}

function realtimeBalanceOf(ISuperfluidToken token, address account, uint256 time)
public
view
override
returns (int256 rtb, uint256 buf, uint256 owedBuffer)
{
(int256 available, int256 fromPools, int256 buffer) = realtimeBalanceVectorAt(token, account, time);
rtb = available + fromPools;

buf = uint256(buffer); // upcasting to uint256 is safe
owedBuffer = 0;
buf = uint256(universalIndexData.totalBuffer.toInt256()); // upcasting to uint256 is safe
}

/// @dev ISuperAgreement.realtimeBalanceOf implementation
Expand Down Expand Up @@ -322,10 +309,15 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
ISuperfluid.Context memory currentContext = AgreementLibrary.authorizeTokenAccess(token, ctx);
address msgSender = currentContext.msgSender;
newCtx = ctx;
if (doConnect) {
if (!isMemberConnected(token, address(pool), msgSender)) {
assert(SuperfluidPool(address(pool)).operatorConnectMember(msgSender, true, uint32(block.timestamp)));
bool isConnected = _isMemberConnected(token, address(pool), msgSender);
if (doConnect != isConnected) {
assert(
SuperfluidPool(address(pool)).operatorConnectMember(
msgSender, doConnect, uint32(currentContext.timestamp)
)
);

if (doConnect) {
uint32 poolSlotID =
_findAndFillPoolConnectionsBitmap(token, msgSender, bytes32(uint256(uint160(address(pool)))));

Expand All @@ -336,33 +328,24 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
_getPoolMemberHash(msgSender, pool),
_encodePoolMemberData(PoolMemberData({ poolID: poolSlotID, pool: address(pool) }))
);
}
} else {
if (isMemberConnected(token, address(pool), msgSender)) {
assert(SuperfluidPool(address(pool)).operatorConnectMember(msgSender, false, uint32(block.timestamp)));
} else {
(, PoolMemberData memory poolMemberData) = _getPoolMemberData(token, msgSender, pool);
token.terminateAgreement(_getPoolMemberHash(msgSender, pool), 1);

_clearPoolConnectionsBitmap(token, msgSender, poolMemberData.poolID);
}

emit PoolConnectionUpdated(token, pool, msgSender, doConnect, currentContext.userData);
}

emit PoolConnectionUpdated(token, pool, msgSender, doConnect, currentContext.userData);
}

/// @inheritdoc IGeneralDistributionAgreementV1
function isMemberConnected(ISuperfluidToken token, address pool, address member)
public
view
override
returns (bool)
{
function _isMemberConnected(ISuperfluidToken token, address pool, address member) internal view returns (bool) {
(bool exist,) = _getPoolMemberData(token, member, ISuperfluidPool(pool));
return exist;
}

function isMemberConnected(ISuperfluidPool pool, address member) public view override returns (bool) {
return isMemberConnected(pool.superToken(), address(pool), member);
function isMemberConnected(ISuperfluidPool pool, address member) external view override returns (bool) {
return _isMemberConnected(pool.superToken(), address(pool), member);
}

function appendIndexUpdateByPool(ISuperfluidToken token, BasicParticle memory p, Time t) external returns (bool) {
Expand Down Expand Up @@ -404,12 +387,15 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
revert GDA_ONLY_SUPER_TOKEN_POOL();
}

// you cannot distribute if admin is not equal to the ctx.msgSender
if (!pool.distributionFromAnyAddress()) {
if (pool.admin() != currentContext.msgSender) {
revert GDA_DISTRIBUTE_FROM_ANY_ADDRESS_NOT_ALLOWED();
}
}

// the from address must be the same as the ctx.msgSender
// there is no ACL support
if (from != currentContext.msgSender) {
revert GDA_DISTRIBUTE_FOR_OTHERS_NOT_ALLOWED();
}
Expand Down Expand Up @@ -467,7 +453,10 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi

newCtx = ctx;

if (!pool.distributionFromAnyAddress()) {
// we must check if the requestedFlowRate is greater than 0 here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's improve our echidna fuzzing with better assertions on expected liquidations.

// otherwise we will block liquidators from closing streams in pools
// where the pool config has distributionFromAnyAddress set to false
if (requestedFlowRate > 0 && !pool.distributionFromAnyAddress()) {
if (pool.admin() != flowVars.currentContext.msgSender) {
revert GDA_DISTRIBUTE_FROM_ANY_ADDRESS_NOT_ALLOWED();
}
Expand All @@ -479,7 +468,7 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
address(pool),
flowVars.distributionFlowHash,
FlowRate.wrap(requestedFlowRate),
Time.wrap(uint32(block.timestamp))
Time.wrap(uint32(flowVars.currentContext.timestamp))
);

// handle distribute flow on behalf of someone else
Expand Down Expand Up @@ -515,14 +504,7 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
}

{
_adjustBuffer(
abi.encode(token),
address(pool),
from,
flowVars.distributionFlowHash,
flowVars.oldFlowRate,
actualFlowRate
);
_adjustBuffer(token, address(pool), from, flowVars.distributionFlowHash, actualFlowRate);
}

// ensure sender has enough balance to execute transaction
Expand Down Expand Up @@ -636,7 +618,6 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
_getFlowDistributionData(ISuperfluidToken(data.token), data.distributionFlowHash);
int256 signedSingleDeposit = flowDistributionData.buffer.toInt256();

bytes memory liquidationTypeData;
bool isCurrentlyPatricianPeriod;

{
Expand All @@ -652,10 +633,9 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
// critical case
if (totalRewardLeft >= 0) {
int256 rewardAmount = (signedSingleDeposit * totalRewardLeft) / data.signedTotalGDADeposit;
liquidationTypeData = abi.encode(2, isCurrentlyPatricianPeriod ? 0 : 1);
data.token.makeLiquidationPayoutsV2(
data.distributionFlowHash,
liquidationTypeData,
abi.encode(2, isCurrentlyPatricianPeriod ? 0 : 1),
data.liquidator,
isCurrentlyPatricianPeriod,
data.sender,
Expand All @@ -677,15 +657,9 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
}
}

function _adjustBuffer(
bytes memory eff,
address pool,
address from,
bytes32 flowHash,
FlowRate, // oldFlowRate,
FlowRate newFlowRate
) internal returns (bytes memory) {
address token = abi.decode(eff, (address));
function _adjustBuffer(ISuperfluidToken token, address pool, address from, bytes32 flowHash, FlowRate newFlowRate)
internal
{
// not using oldFlowRate in this model
// surprising effect: reducing flow rate may require more buffer when liquidation_period adjusted upward
ISuperfluidGovernance gov = ISuperfluidGovernance(ISuperfluid(_host).getGovernance());
Expand Down Expand Up @@ -718,7 +692,7 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
ISuperfluidToken(token).updateAgreementData(flowHash, data);
}

UniversalIndexData memory universalIndexData = _getUIndexData(eff, from);
UniversalIndexData memory universalIndexData = _getUIndexData(abi.encode(token), from);
universalIndexData.totalBuffer =
// new buffer
(universalIndexData.totalBuffer.toInt256() + Value.unwrap(bufferDelta)).toUint256();
Expand All @@ -736,8 +710,6 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
universalIndexData.totalBuffer
);
}

return eff;
}

// Solvency Related Getters
Expand Down Expand Up @@ -810,7 +782,7 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
data = new bytes32[](2);
data[0] = bytes32(
(uint256(int256(FlowRate.unwrap(p.flow_rate()))) << 160) | (uint256(Time.unwrap(p.settled_at())) << 128)
| (buffer << 32) | (isPool_ ? 1 : 0)
| (uint256(buffer.toUint96()) << 32) | (isPool_ ? 1 : 0)
);
data[1] = bytes32(uint256(Value.unwrap(p._settled_value)));
}
Expand All @@ -823,7 +795,7 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
data = new bytes32[](2);
data[0] = bytes32(
(uint256(int256(uIndexData.flowRate)) << 160) | (uint256(uIndexData.settledAt) << 128)
| (uint256(uIndexData.totalBuffer) << 32) | (uIndexData.isPool ? 1 : 0)
| (uint256(uIndexData.totalBuffer.toUint96()) << 32) | (uIndexData.isPool ? 1 : 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @hellwolf please take a closer look

);
data[1] = bytes32(uint256(uIndexData.settledValue));
}
Expand Down
Loading
Loading