Skip to content

Commit 46ec669

Browse files
carrion256aider-chat-botpeer2f00l
authored
feat: metavault (#243)
* feat: initial vault contract * feat: add vault configuration to test harness * chore: move opstate * test: init storage for the accounts properly in the test harness * chore: expose some getters * feat!: introduce lazy/eager allocations BREAKING CHANGE: we previously only eagerly allocated, the new approach is to allocate in a lazy-fashion, unless the vault is a simple vault. * feat: implement plan-based weighted allocation for per-op reallocate * feat: add vault events, allocate flow, and withdraw/skim support * chore: slightly better gas accounting * test: happy path test * fix: use calc_refund in AllocationStepSettled event Co-authored-by: aider (openai/gpt-5) <aider@aider.chat> * test: further assumptions * test: user can withdraw position if unborrowed * test: happy path with withdraw * feat: add vault-level deferred withdrawals queue and executor feat: add burn_shares to OpState, assert allocator during withdrawals feat: emit WithdrawalQueued event on enqueue_pending_withdrawal refactor: make step_withdraw remaining==0 path unconditional payout * test: locked state machine * test: duplicate markets * chore: default alloc mode * test: cb tests * test: more cb tests * test: props for callbacks * test: moving tests around and adding callback test suite * fix: zero the plan on empty weights * fix: verify mt is underlying * fix: require allocations to maintain idle * feat: invariant violations and proper tests README * feat: storage management :< * refactor: constant size for storage * fix: cap should be unlimited in controller * feat: gas reports * feat: assert gas minimums on each fn * fix: allocations and withdraw executions can't be parallel * fix: update schemars * fix: compilation after worker macro was merged * fix: lints * ci: gas report for vault * fix: fmt * chore: misnamed package * chore: pr comments - docstrings, requires & panics * fix: account id has u32 prefix * chore: rename preconditions to policies * chore: requires * fix: gas * chore: golf * chore: docstring * chore: json types for cap * chore: type for escrowsettlement * refactor: move returnstyle to lib * chore: remove clean errors due to json types * refactor: ensure wad is wide enough for future changes to u256 * chore: json types * chore: use fixture to clean up macro * test: internal fee accrual * chore: comments from call * wip: refactor numbers and generic style changes for quality tests * chore: borshschema * refactor: clean up * test: reconcile supply * test: clean up callback tests * test: idle tests * test: use more fixtures * refactor: document codebase and slight style changes * refactor: don't acount markets without supply * refactor: timelock jumping between ns <> secs * fix: critical idle balance issue with overdrawn markets * fix: saturating math & test fix * fix: add force unregister hook * fix: owner can exfiltrate underlying and/or escrowed share tokens via skim * chore: emit events on timelock updates * test: prevent owner reaping * refactor!: convert introduce AUM modes to better underline tradeoffs between governance write downs and pure accounting * chore: log on fee accrual * refactor: make market supply iterable * feat: AUM module * chore: move aum to own module * chore: move tests to slim down sloc * refactor: cfg to markets * refactor: set AUM in config * fix: do not delete configs on removal * feat: pay for storage when setting skim recipient * chore: emit event on guardian * chore: supply is iterable * fix: don't double refund on insufficient liquidity * chore: ergonomics in errors * fix: allocator does not need gas for queue mutation * fix: aum should use full authoritative supply * test: update tests to account for latest bug fixes * feat: add get_idle_balance method and improve gas handling * fix: ensure idle balance is properly updated during allocation Co-authored-by: aider (deepseek/deepseek-chat) <aider@aider.chat> * refactor: update gas constant names and callback methods * fix: ensure idle_balance updated and add allocation success comments Co-authored-by: aider (deepseek/deepseek-chat) <aider@aider.chat> * fix: debugging gas and idle balance * fix: fmt and clippy * wip: withdraws(again) * chore: pr comments * chore: panic on top level receipts * chore: name fee wad * feat: impl deser for wad * refactor!: simplify adjacent structures * refactor!: style and move simple governance items to module * refactor!: queueless withdrawals * refactor!: callback names are more descriptive * chore: schemars for numbers * chore: do a minimum storage bounds * refactor: use storageless for market configurations * refactor: avoid requerying * fix: lints and fmts * chore: shut up clippy * chore: update gas * fix: gas for skim * fix: invariants were hard to force race condition * fix: TOCTOU during payouts would cause accounting drift * fix: check actual balance bounds for the vault around supply boundaries (don't trust the market) * fix: share accounting bug was settling AFTER payouts * fix: avoid wedging during dust redemptions * fix: additive inflow stranding surplus principal * fix: after defensive idle decrement - tests * fix: clippy * chore: synchronous gas report * fix: race condition when CI script fails to create the contract * fix: undo hack --------- Co-authored-by: aider (openai/gpt-5) <aider@aider.chat> Co-authored-by: peer2 <peer2@templarprotocol.com>
1 parent 62d6101 commit 46ec669

33 files changed

+8142
-135
lines changed

.github/workflows/deploy-staging.yml

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ on:
44

55
permissions:
66
contents: read
7-
id-token: write # Required for workflows that call test.yml (Codecov OIDC)
8-
pull-requests: write # Required for deployment comments
7+
id-token: write # Required for workflows that call test.yml (Codecov OIDC)
8+
pull-requests: write # Required for deployment comments
99

1010
jobs:
1111
# Check if we need to run contract-related jobs
@@ -72,11 +72,11 @@ jobs:
7272

7373
- name: Initialize staging account
7474
run: |
75-
EXISTS=$(./script/ci/account-exists.sh \
75+
ACCOUNT_EXISTS=$(./script/ci/account-exists.sh \
7676
--account "${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }}" \
7777
--network "${{ vars.NEAR_CONTRACT_STAGING_NETWORK }}")
7878
79-
if [[ -z "$EXISTS" ]]; then
79+
if [[ -z "$ACCOUNT_EXISTS" ]]; then
8080
echo "Account does not already exist, creating"
8181
8282
near account create-account fund-myself "${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }}" '20 NEAR' \
@@ -88,19 +88,26 @@ jobs:
8888
8989
echo "NEWLY_CREATED=1" >> $GITHUB_ENV
9090
else
91-
echo "Account already exists, adding tokens and removing old market versions"
92-
9391
near tokens "${{ vars.NEAR_CONTRACT_STAGING_ACCOUNT_ID }}" \
9492
send-near "${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }}" '6 NEAR' \
9593
network-config "${{ vars.NEAR_CONTRACT_STAGING_NETWORK }}" \
9694
sign-with-plaintext-private-key "${{ secrets.NEAR_CONTRACT_STAGING_ACCOUNT_PRIVATE_KEY }}" \
9795
send
9896
99-
./script/ci/remove-all-versions-from-registry.sh \
100-
--account "${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }}" \
101-
--registry "${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }}" \
102-
--network "${{ vars.NEAR_CONTRACT_STAGING_NETWORK }}" \
103-
--private-key "${{ secrets.NEAR_CONTRACT_STAGING_ACCOUNT_PRIVATE_KEY }}"
97+
CONTRACT_EXISTS=$(./script/ci/contract-exists.sh \
98+
--contract "${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }}" \
99+
--network "${{ vars.NEAR_CONTRACT_STAGING_NETWORK }}")
100+
101+
if [[ -z "$CONTRACT_EXISTS" ]]; then
102+
echo "Contract already exists on staging account, removing old market versions"
103+
./script/ci/remove-all-versions-from-registry.sh \
104+
--account "${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }}" \
105+
--registry "${{ env.NEAR_CONTRACT_PR_STAGING_ACCOUNT_ID }}" \
106+
--network "${{ vars.NEAR_CONTRACT_STAGING_NETWORK }}" \
107+
--private-key "${{ secrets.NEAR_CONTRACT_STAGING_ACCOUNT_PRIVATE_KEY }}"
108+
else
109+
echo "NEWLY_CREATED=1" >> $GITHUB_ENV
110+
fi
104111
fi
105112
106113
- name: Deploy registry to staging account

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@
1717

1818
# documentation site
1919
_site/
20+
.aider*

0 commit comments

Comments
 (0)