-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update abigenerated files * Schwartz protocol v2 (#98) * Refactor basic methods for V2 * Add AgentDebt call * Add initial framework for margin helpers * Add _fi helper methods * Refactor liquidation queries and consolidate packages * Add back tests * Small fixes * Small tweaks * Add fee debt test Fix tests * Add econ tests, bug fixes and improvements * Get rid of pool registry * Small tweaks * Add agent data helpers and tests Fix collateral value not changing on computeagentdata * Add push funds helper with protect against push to fee debt miner * Improve tests * Add test helper * More cleanup * Nix the mock ado * Delete unused constants * Add claims decoder * More cleanup * Change method name * Fix issue with agentfi using only principal when computing debt (#100) * Add back edr calc * Update abigen * Update deployments * Add poolsapi calls to econ package (#101) Still need to do interest in agentfi call * add margin and leverage ratio * handle edge cases in margin and dtl * Schwartz improvements (#102) * Update deployments * Add more api helpers and tests * More helper methods * Revert bad merge * Update abigen * Update afi with spendable balance (#106) * Fix/borrow (#107) * fix max borrow on agent fi * Create minerfi type --------- Co-authored-by: Jonathan <jpschwartz2@uwalumni.com> * fix index out of range when miner sectors are less than desired sample size (#108) * add miner that gave error on staging to test cases (#109) * add miner that gave error on staging to test cases * fix step size rounding error * change BaseFi test to MinerFi test * Add Events API endpoint to extern struct (#105) * Add Events API endpoint to extern struct Also change functions that use it to take a SDK argument so they can look up the endpoint. * Polish --------- Co-authored-by: Jonathan <jpschwartz2@uwalumni.com> * Add test github action * Fix/glifapi (#110) * Add the AgentMarginJSON struct type * Update type name * Add LiveSectors and FaultySectors to AgentMarginJSON * Update type * Potential fix for eventsapi once pools-events is redeployed Consolidate function calls to the api * Update types * Fix glifapi queries * Refactor principal and interest sdk funcs to work for v0 historically Fix tests --------- Co-authored-by: ganzai-san <ganzai@protonmail.com> Co-authored-by: ganzai <79986704+ganzai-san@users.noreply.github.com> Co-authored-by: Jim Pick <jim@jimpick.com>
- Loading branch information
1 parent
8b1bbc0
commit 028a585
Showing
66 changed files
with
9,002 additions
and
13,642 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Go Test | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
jobs: | ||
test: | ||
name: Run Go Tests | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: 1.22.0 | ||
|
||
- name: Install dependencies | ||
run: go mod download | ||
|
||
- name: Run tests | ||
run: go test -v ./... | ||
env: | ||
LOTUS_DIAL_ADDR: ${{ secrets.LOTUS_DIAL_ADDR }} | ||
LOTUS_TOKEN: ${{ secrets.LOTUS_TOKEN }} |
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
package econ | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/filecoin-project/go-address" | ||
"github.com/filecoin-project/lotus/chain/types" | ||
pooltypes "github.com/glifio/go-pools/types" | ||
"github.com/glifio/go-pools/util" | ||
"github.com/glifio/go-pools/vc" | ||
) | ||
|
||
func GetAgentEcon(ctx context.Context, agentAddr common.Address, psdk pooltypes.PoolsSDK, ts *types.TipSet) (*big.Int, *big.Int, error) { | ||
query := psdk.Query() | ||
blockNumber := big.NewInt(int64(ts.Height())) | ||
|
||
agentAvailableBal, err := query.AgentLiquidAssets(ctx, agentAddr, blockNumber) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
principal, err := getAgentPrincipal(ctx, agentAddr, psdk, ts) | ||
if err != nil { | ||
return nil, nil, err | ||
} | ||
|
||
return agentAvailableBal, principal, nil | ||
} | ||
|
||
func getAgentPrincipal(ctx context.Context, agentAddr common.Address, psdk pooltypes.PoolsSDK, ts *types.TipSet) (*big.Int, error) { | ||
blockNumber := big.NewInt(int64(ts.Height())) | ||
principal, err := psdk.Query().AgentPrincipal(ctx, agentAddr, blockNumber) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return principal, nil | ||
} | ||
|
||
func ComputeBorrowAgentData(ctx context.Context, agentAddr common.Address, amount *big.Int, psdk pooltypes.PoolsSDK, ts *types.TipSet) (*vc.AgentData, error) { | ||
principal, err := getAgentPrincipal(ctx, agentAddr, psdk, ts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
newPrincipal := big.NewInt(0).Add(principal, amount) | ||
|
||
data, err := ComputeAgentData(ctx, agentAddr, amount, newPrincipal, address.Undef, psdk, ts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return data, err | ||
} | ||
|
||
func ComputePayAgentData(ctx context.Context, agentAddr common.Address, value *big.Int, psdk pooltypes.PoolsSDK, ts *types.TipSet) (*vc.AgentData, error) { | ||
agentAvailableBal, principal, err := GetAgentEcon(ctx, agentAddr, psdk, ts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if condition := value.Cmp(agentAvailableBal); condition == 1 { | ||
return nil, errors.New("pay amount is greater than agent's available balance") | ||
} | ||
|
||
removingBal := big.NewInt(0).Sub(big.NewInt(0), value) | ||
|
||
return ComputeAgentData(ctx, agentAddr, removingBal, principal, address.Undef, psdk, ts) | ||
} | ||
|
||
func ComputeWithdrawAgentData(ctx context.Context, agentAddr common.Address, withdrawAmount *big.Int, psdk pooltypes.PoolsSDK, ts *types.TipSet) (*vc.AgentData, error) { | ||
agentAvailableBal, principal, err := GetAgentEcon(ctx, agentAddr, psdk, ts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// check if amount is greater than agentAvailableBal | ||
if condition := withdrawAmount.Cmp(agentAvailableBal); condition == 1 { | ||
return nil, errors.New("withdraw amount is greater than agent's available balance") | ||
} | ||
|
||
// here we want to pass a negative value to ComputeAgentData to indicate that the agent's balance is being withdrawn | ||
removingVal := big.NewInt(0).Sub(big.NewInt(0), withdrawAmount) | ||
|
||
data, err := ComputeAgentData(ctx, agentAddr, removingVal, principal, address.Undef, psdk, ts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return data, err | ||
} | ||
|
||
func ComputePushFundsAgentData(ctx context.Context, agentAddr common.Address, minerAddr address.Address, psdk pooltypes.PoolsSDK, ts *types.TipSet) (*vc.AgentData, error) { | ||
principal, err := getAgentPrincipal(ctx, agentAddr, psdk, ts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
lapi, closer, err := psdk.Extern().ConnectLotusClient() | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer closer() | ||
|
||
// make sure we aren't pushing a miner with fee debt | ||
_, mstate, err := util.LoadMinerActor(ctx, lapi, minerAddr, ts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
feeDebt, err := mstate.FeeDebt() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if feeDebt.Sign() == 1 { | ||
return nil, errors.New("cannot push funds to miner with fee debt") | ||
} | ||
|
||
return ComputeAgentData(ctx, agentAddr, big.NewInt(0), principal, address.Undef, psdk, ts) | ||
} | ||
|
||
func ComputeRmMinerAgentData(ctx context.Context, agentAddr common.Address, miner address.Address, psdk pooltypes.PoolsSDK, ts *types.TipSet) (*vc.AgentData, error) { | ||
principal, err := getAgentPrincipal(ctx, agentAddr, psdk, ts) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return ComputeAgentData(ctx, agentAddr, big.NewInt(0), principal, miner, psdk, ts) | ||
} |
Oops, something went wrong.