kuegi/ain

Implement dToken Restart DFIP

kuegi opened this issue · 2 comments

summary

In this issue I will try to document my implementation process of the needed changes for the DFIP to restart the dToken system

tasks to be done

  • create pull request
  • setup IDE (VS Code and prepare compiler locally)
  • write test
  • implement functionality

pseudo code from DFIP definition

  • On activationblock:
for all vaults:
  payback DUSD loans with collateral
  payback remaining loans with funds from address
  payback remaining loans by swapping collateral (first DUSD, then other collateral)

convert all loanTokens to new version (like stocksplit, but with no change in price or amount, must also affect the DUSD in collateral), new DUSD is called USDD

create native SC to lock funds in tranches, SC knows funds per address
SC keeps track of release-ratio, starting with 10%
initially 100 tranches (with 10% initial ratio, thats 0.9% per tranche)

for all LM positions in dToken-USDD pools:
  remove 90% of position and lock resulting funds directly into the SC

for all LM positions in USDD-DFI, USDC-USDD, USDT-USDD, EUROC-USDD, XCHF-USDD:
  remove 90% of position, lock resulting USDD directly into the SC, credit other resulting asset to owner

for all vaults:
  withdraw 90% of USDD collateral into SC (for vault owner address)

for all loantoken balances (=dTokens and USDD):
  lock 90% of balances into SC
  • extend Transferdomain:
any transfer EVM->DVM of old dToken or DUSD results in:
  SC.releaseRatio in new dToken/USDD is credited to targetaddress
  1-SC.releaseRatio in new dToken/USDD is locked in SC for targetaddress
  • extend stocksplit logic to update SC too (so future dToken splits are reflected in the SC)

  • implement SC-releaseTranche-tx (only allowed by foundation members):

on releaseTrancheTx:
  for all entries in SC:
     credit according tranche part of funds to address
     update SC.releaseratio accordingly
  • parameters to update after activation:
//deactivate DUSD loops:
"v0/vaults/dusd-vault/enabled": "false",

//remove old stab fee:
"v0/poolpairs/17/token_a_fee_pct": "0",
"v0/poolpairs/101/token_b_fee_pct": "0",
"v0/poolpairs/102/token_b_fee_pct": "0",
"v0/poolpairs/218/token_b_fee_pct": "0",
"v0/poolpairs/236/token_b_fee_pct": "0",

//activate new system-wide USDD fee

"v0/token/<usdd_id>/dex_in_fee_pct": "<updated according to algo ratio>",
"v0/token/<usdd_id>/dex_out_fee_pct": "<updated according to algo ratio>",

on my machine, cloning the repo and then calling ./make.sh build installed all necessary things and build succeeded on the first run.

./make.sh test runs all tests

to run only python testfiles that match a filter:
./make.sh test-py --filter feature_evm*

closing. now tracking it in the PR