Skip to content

Instantly share code, notes, and snippets.

View buendiadas's full-sized avatar
🌅

Carlos Buendía buendiadas

🌅
View GitHub Profile
@buendiadas
buendiadas / lockModifyPosition.sol
Created November 7, 2023 23:45
Pool Operator: LockModifyPosition
function lockModifyPosition(PoolKey memory key, IPoolManager.ModifyPositionParams memory params) public {
poolManager.lock(abi.encodeCall(this.__performModifyPosition, (key, params, msg.sender)));
}
@buendiadas
buendiadas / fCash_pricing.md
Last active May 6, 2022 22:05
On fCash pricing
  • fCash is Notional's zero-coupon bond like instrument and derives its value from time to maturity and current interest rate levels:
    • Time to maturity is the time in seconds to a fixed date, where the fCash can be settled into cash

    • There's a notional native market for interest rates that mostly depends on lending vs borrowing volume. This market works as an AMM using the pair (fToken / cToken). A priori, the pair is not expected to have a high volatility, so they provide a curve that works very flat and doesn't trade at pre defined conditions that are considered as limits. Those values are set by governance and currently is ~20% for stablecoin and ~15% for crypto asset pools: image.

    • The value of fCash is calculated as PV(fCash) = fCash * e^ - (oracleRate * timeToMaturity)

  • Oracle rate is defined by the previous AMM, they provide a TWAP to protect from flash loan attacks. **T
@buendiadas
buendiadas / borrowing solution examples.md
Last active March 11, 2021 19:11
borrowing solution examples

Given the integrations above, the following example shows how we could manag

Solution 1: Collateral and debt positions registered as a single asset

  • Collateralized assets and debt could be modeled as a single asset (CDP)
  • The CDP value would be calculated as: CDP_VALUE = Σ COLLATERAL_ASSET_VALUE - DEBT
  • With this new implementation, GAV would be calculated as: GAV_NEXT = GAV_CURRENT + Σ CDP, where current and next represent the current and next release.

Solution 2: Collateral and debt positions registered as different assets

@buendiadas
buendiadas / lendingAutomation.sol
Last active March 11, 2021 10:49
LendingAutomation.sol
pragma solidity 0.6.12;
interface IComptroller {
function callOnExtension(
address,
uint256,
bytes calldata
) external;
@buendiadas
buendiadas / enzyme_borrowing.md
Last active March 30, 2021 09:45
Notes on Enzyme Borrowing

Notes on enzyme borrowing

Overview

This gist has some thoughts on a general solution to enable borrowing.

The exercise is divided in the following sections.

  • Problem: where the core problem to be solved is formally defined
  • Solution: where some solutions will be studied to the previously mentioned problem
@buendiadas
buendiadas / opcodelist.csv
Created December 18, 2020 10:53
List of opcode cost
Value Mnemonic Gas Used Subset Removed from stack Added to stack Notes Formula Notes
0x00 STOP 0 zero 0 0 Halts execution.
0x01 ADD 3 verylow 2 1 Addition operation
0x02 MUL 5 low 2 1 Multiplication operation.
0x03 SUB 3 verylow 2 1 Subtraction operation.
0x04 DIV 5 low 2 1 Integer division operation.
0x05 SDIV 5 low 2 1 Signed integer division operation (truncated).
0x06 MOD 5 low 2 1 Modulo remainder operation
0x07 SMOD 5 low 2 1 Signed modulo remainder operation.
0x08 ADDMOD 8 mid 3 1 Modulo addition operation.
https://www.reddit.com/r/ethereum/comments/6c1jui/delegatecall_forwarders_how_to_save_5098_on/
https://ethereum.stackexchange.com/questions/47174/does-it-cost-more-gas-to-call-another-contracts-functions-in-solidity
@buendiadas
buendiadas / constantGasChecker.sol
Last active December 7, 2020 16:11
Gas cost research on retrieving constants
pragma solidity ^0.6.8;
/// Trying to answer the question: Is it more expensive to check variable from a constant or from a memory variable?
/// The answer is that they both have near 0 gas costs (191 vs 213 gas) but checking from constant gives a lower value
contract externalContract {
uint256 storedConstant;

Keybase proof

I hereby claim:

  • I am carlos-buendia on github.
  • I am buendiadas (https://keybase.io/buendiadas) on keybase.
  • I have a public key ASARaaiZS6QVsGHGOYvOevUWa40GZ45_e7toYnro6WSvUAo

To claim this, I am signing this object: