Skip to content

Dev/fresh start - #2

Merged
royalf00l merged 51 commits into
mainfrom
dev/fresh_start
Jan 1, 2025
Merged

Dev/fresh start#2
royalf00l merged 51 commits into
mainfrom
dev/fresh_start

Conversation

@royalf00l

@royalf00l royalf00l commented Sep 3, 2024

Copy link
Copy Markdown
Collaborator

Used cargo near new to create this project that comes with boilerplate dir structure, readme, and github workflows

  • creates contract
  • borrow
  • supply
  • withdraw (in progress)
  • fix serialization errors
  • fix github workflows
  • create markets
  • support for chain sigs

Will add more functionality in Future PR.

@royalf00l royalf00l self-assigned this Sep 3, 2024
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment on lines +166 to +175
Promise::new(vault.collateral_asset.clone()).function_call(
"ft_transfer_call".to_string(),
serde_json::to_vec(&serde_json::json!({
"receiver_id": env::current_account_id(),
"amount": collateral_amount,
"msg": format!("collateral:{}", vault_id)
})).unwrap(),
NearToken::from_yoctonear(1),
Gas::from_tgas(10),
).then(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same as above, this won't work. The token sender himself needs to send the collateral by calling ft_transfer_call on the collateral contract.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

in progress figuring out XCC work with borrow (and associated tests) too

Comment thread src/lib.rs Outdated

@peer2f00l peer2f00l left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A few more comments and changes from me... Is there a place where the individual workflows are sketched out quite specifically?

Like:

  • these are the steps to create a vault
  • these are the steps to add collateral to (or create) a loan
  • these are the steps to withdraw stablecoins
  • these are the steps to repay stablecoins
  • these are the steps to liquidation

Comment thread src/lib.rs Outdated
Comment on lines +130 to +144
#[payable]
pub fn deposit_stablecoin(&mut self, vault_id: String, amount: U128) {
let nft_collection = self.get_nft_collection_for_vault(&vault_id);
require!(
self.owns_nft(&env::predecessor_account_id(), &nft_collection.to_string()),
"Not authorized",
);

// Instead of calling ft_transfer_call, we just log the intent
// The actual transfer should be initiated by the user
env::log_str(&format!(
"Deposit intent: {} tokens to vault {}",
amount.0, vault_id
));
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does this method need to exist?

@royalf00l royalf00l Sep 16, 2024

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes. There needs to be some sort of method to call for lenders to deposit stablecoins. I updated it in the 371f3c2 commit. Think the loan test is failing because the ft_transfer_call initiates an XCC and I'm having trouble testing with that.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Normal Rust tests cannot be used to test xccs, since there's no runner to execute the created promise. We have to use near-workspaces for that.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Comment thread src/lib.rs Outdated
Comment thread src/lib.rs Outdated
Comment on lines +170 to +184
ext_ft_core::ext(vault.collateral_asset.clone())
.with_attached_deposit(NearToken::from_yoctonear(1))
.with_static_gas(Gas::from_tgas(10))
.ft_transfer_call(
env::current_account_id(),
collateral_amount,
None,
format!("collateral:{vault_id}"),
)
.then(
ext_ft_core::ext(vault.stablecoin.clone())
.with_attached_deposit(NearToken::from_yoctonear(1))
.with_static_gas(Gas::from_tgas(10))
.ft_transfer(env::predecessor_account_id(), borrow_amount, None),
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This probably only needs to transfer stablecoins to the caller.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

addressed in 36d3819, 00db003

@royalf00l

Copy link
Copy Markdown
Collaborator Author

A few more comments and changes from me... Is there a place where the individual workflows are sketched out quite specifically?

Like:

  • these are the steps to create a vault
  • these are the steps to add collateral to (or create) a loan
  • these are the steps to withdraw stablecoins
  • these are the steps to repay stablecoins
  • these are the steps to liquidation

The litepaper contains most of this currently. I'll create an architecture doc specifically for what happens at the contract level tomorrow.

@royalf00l
royalf00l merged commit dcb79da into main Jan 1, 2025
peer2f00l added a commit that referenced this pull request Aug 1, 2026
Plan completeness was measured in totals, which a coherent subset satisfies:

- `proposals >= 2` passed a plan with both borrow-feed steps deleted, since the
  collateral create/execute pair alone reaches two (#1). Each feed now needs its
  own create *and* execute, matched by the price id the operation names.
- Storage registrations were counted, not matched, so two registrations against
  the collateral token satisfied a two-NEP-141 market and left the borrow asset
  unreceivable (#2). They are matched against the token contracts the encoded
  configuration names.

`summary_digest` did not cover `step_digests` (#23), so deleting a step *and*
its digest entry reported "unmodified since generation" on the line `review`
prints above the confirmation prompt. Plan schema bumped to 3.

The journal never flushed (#20). `fs::write` returns at the page cache and
`rename` is atomic only against a process crash; the machine loss this module
exists for could still leave a truncated journal, which reads as a step that
never ran and re-sends a deploy whose deposit is already spent.

A direct plan derived `proxy-oracle-<name>` and `proxy-gov-<name>` it never
creates (#27), so a valid market name whose prefixed forms exceed NEAR's
account-id limit failed to plan. `Derived.governance_id` is optional now.

Also: a CoinGecko coin with no USD quote failed the whole response and skipped
every other id in the request (#14); a spec from a newer build reported the
first unknown field rather than its schema version (#19); one funding assertion
message stated the opposite of what `available` does (#11); markdown fences
carry languages (#4); the freeness test asserts the exact remaining set rather
than a smaller count (#24).

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants