Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create aip for Aptos Intent Framework #511

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

runtian-zhou
Copy link
Contributor

No description provided.

aips/aip-x.md Outdated
Logic here can then be translated into a Move struct that looks like the following:
```
struct TradeIntent<Source, phantom Target, Args> has key {
offered_resource: Source,

Choose a reason for hiding this comment

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

Does dispensable_resource sounds better here?

aips/aip-x.md Outdated
The `TradeIntent` is parameterized by three type parameters:
1. `Source`: Value that intent issuer is willing to give away
2. `Target`: the type of value that the intent issuer is expecting.
3. `Argument`: Intent user will use `Argument` as auxillary info to determine whether the unlock condition is met.
Copy link

@ch4r10t33r ch4r10t33r Oct 2, 2024

Choose a reason for hiding this comment

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

Are you intending for the argument to be a proof (either zk-proof or storage proof) that can be verified on-chain?

In theory, we could represent the argument as a function f(state, intent) -> bool, where solvers submit proofs for on-chain verification.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the current design, there's no proof involved: user specifies the post condition the transaction will need to meet, and aptos framework will assert this transaction can only be committed if post condition has been met. Argument is just some auxillary data to help the framework determine whether the transaction can be committed. It would be easier if you look at the move code directly.


With those types being generic, we can implement different trading intents easily:
- If `Target` is instantiated with `FungibleAsset`, it means we are trading a Move value for a specific fungible asset.
- If `Target` is instantiated with `LinearTransferRef`, it means we are trading a Move value for an Object.
Copy link

@ch4r10t33r ch4r10t33r Oct 2, 2024

Choose a reason for hiding this comment

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

Should we also include NonFungibleAsset as a type? Some DeFi protocols mint NFTs for specific staking or deposit operations, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here are just examples. You can put arbitrary type here.

Copy link
Contributor

@igor-aptos igor-aptos left a comment

Choose a reason for hiding this comment

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

You should add a note about this not being published at 0x1.

you can look at https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-72.md#risks-and-drawbacks for what they wrote there, but it could probably be explained a bit more (and the reasons for going that way)

aips/aip-x.md Outdated

## Summary

Designing a generic mechanism for declaring intents for trading between on chain resources on Aptos. This would allow users to declare which operations they would like to perform upfront and let 3rd party builders to fill in the details on how this transactions should be executed.
Copy link
Contributor

Choose a reason for hiding this comment

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

this is not necessarily for trading, but for creating offers. (i.e. offer can be more general than a trade)

For example, you could have an offer for a bet.

aips/aip-x.md Outdated

### Out of scope

We will only be covering the intent declaration and execution logic in the framework. We are not going to touch the solving logic on how intents should be fulfilled and we will leave it for builders on Aptos to figure out.
Copy link
Contributor

Choose a reason for hiding this comment

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

in the framework => in this AIP

aips/aip-x.md Outdated
- It can simplify and speed up cross-chain interactions by pushing risk to "relayers" or "fillers" in exchange for a small fee.
- Intents are inherently secure, since the outcome signed by the user must match the outcome of the solution. However, ensuring that this is possible typically requires an "intent settlement network".

Intent is a particular concept for Aptos because Move has a unique way of encoding on chain assets. With Move, you can represent
Copy link
Contributor

Choose a reason for hiding this comment

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

sentence not finished?

aips/aip-x.md Outdated

Aptos Labs will be responsible for implementing:
1. A set of intent contracts to ramp up the system.
2. Framework code for creating and validating intents.
Copy link
Contributor

Choose a reason for hiding this comment

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

Framework code for creating and validating intents.
=>
Library code for creating and validating intents.

- If `Target` is instantiated with `LinearTransferRef`, it means we are trading a Move value for an Object.
- If `Source` is instantiated with `TransferRef`, it means we are giving out ownership to an Object given certain condition.
- If `Source` is instantiated with `FungibleAsset`, it means we are giving out a certain fungible asset given certain condition.
- This doesn't quite work because `FungibleAsset` is not storable. The real implementation would look like giving out ownership of a `FungibleStore`
Copy link
Contributor

Choose a reason for hiding this comment

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

could this be hidden in the intent? i.e. it stores FungibleStore, but returns extracted FungibleAsset to the caller?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it is currently hidden for implementation.

aips/aip-x.md Outdated
```
User can use this api to register a trading intent to offer a value of `Source` type. The intent can only be executed if anyone can provide a value of `Witness` type. Intent always have an expiry time so that issuer can claim the resource back after the expiry time. Note that the return value of this function is wrapped in an `Object`. This is because we want anyone to be able to claim this intent by providing the address of this object.

Another note is that this procedure is an on-chain procedure. Ideally we should make this a signed message instead so that users don't need to publish this intent to everyone.
Copy link
Contributor

Choose a reason for hiding this comment

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

this sentence probably goes to future work

}
```
Here we are defining an example of intent where the unlock condition is receiving a certain amount of a given fungible asset type. `Argument` type is instantiated to `FungibleAssetLimitOrder` and `Witness` type is instantated to `FungibleAssetRecipientWitness` in this example. In the arugment, we specify the amount and the type of FA we would like to receive. The check will then be implemented by first checking if the passed in `FungibleAsset` meets the requirement set in the `FungibleAssetLimitOrder` and deposit the FA to the issuer's primary fungible storage if the conditions are met. Once the checks are completed, we will provide the witness `FungibleAssetRecipientWitness` to complete this intent session.

Copy link
Contributor

Choose a reason for hiding this comment

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

this needs an example of snippet of code of what the issuer and settler would need to do , for the above fungible_asset_intent_hooks.

aips/aip-x.md Outdated

### Example: Defining an intent to receive a certain fungible asset.
```
module aptos_framework::fungible_asset_intent_hooks {
Copy link
Contributor

Choose a reason for hiding this comment

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

it's not aptos_framework , but a different adress

aips/aip-x.md Outdated

### Frontrun Risk

The intent claiming transaction can be front-runned by malicious mempool operator. Since anyone is able to sign transaction to claim intent solution, a malicous mempool operator can take the intent solving transaction submitted by the solver and sign the same transaction with its own address to be able to claim the lucrative ones. However, since txns usually won't stay too long in the mempool right now, it should not be a major concern at this point. In the future we might need some authentication schema for intent claiming process.
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rephrase this:

As the system is first-come first-serve, the intent claiming transaction can be front-runned by whoever sees it - mempool operator, validator operator, etc. Since anyone is able to sign transaction to claim intent solution, anyone can take the intent solving transaction submitted by the solver and sign the same transaction with its own address to be able to claim the lucrative ones. If main value comes from finding the route, and not being willing to settle, privacy of submitted transactions will become imporatnt. Intent Solver might want to run a validator node or partner with validator operator. Additionally in the future, support for "secret transactions" , that are revealed only at the time of execution might be added.

aips/aip-x.md Outdated
- We need offchain declaration of the intents
- We can use this standard to incentivize for a credit score system for different DeFi lending protocol:
- Implement borrow/lending action as an NFT, and implement scoring system for the NFT as the consumption condition.

Copy link
Contributor

Choose a reason for hiding this comment

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

"secret transactions"

@runtian-zhou
Copy link
Contributor Author

Update the PR with @igor-aptos's comments

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.

3 participants