-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat: evm-swap example #330
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for lit-dev-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
docs/additional-examples/evm-swap.md
Outdated
|
||
## 1) Understanding Lit PKPs as escrow | ||
|
||
A Private key is meant for signing transactions which are executed on the blockchain, a network verifies if the transaction is a legitimate one and then executes it. With Lit Network we can generate a special type of private keys which can be programmed to sign transactions only when certain conditions are met. With this, we can create several escrow mechanisms, and we will look into how we can execute a cross-chain swap. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we can abstract away some of these details here, they feel a bit excessive. I think we can just briefly introduce PKPs (like we do here https://developer.litprotocol.com/user-wallets/pkps/overview in the overview) and then say that for this use case we are going to use them as escrow accounts to support the cross chain swap flow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was meant to give an overview of how we can "generally" use pkps for escrow-like cases and not only limit to defining pkps. As for bridging, messaging and swapping, the only thing that'll change will be the lit action.
I tried to make it use friendly but if it feels overwhelming, I can reduce it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea imo i think we can simplify things a bit. I think we should start by briefly introducing PKPs generally before honing in the specific use case of escrow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs/additional-examples/evm-swap.md
Outdated
|
||
Lit Actions are programmable code written in Javascript which can run on the LIT Network. We can program a Lit Action so that if certain permissions are met for a pkp, it must sign specific transactions that can be sent to the blockchain. We need to grant a Lit Action as a permitted action to the PKP to allow the Lit Action to generate signatures with it. | ||
|
||
We can create an escrow pkp in the following way (Mint/ Grant/ Burn) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can create an escrow pkp in the following way (Mint/ Grant/ Burn)
Consider, "We can create a PKP "escrow" using the Mint/Grant/Burn [link to docs] method in the following way:"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with [link to docs] you mean the link to current page where the example resides or exactly what page of the docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i was referring to the docs on m/g/b, but i realize that we don't have dedicated docs for this rn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lmk, i can shoot another pr for that as well
docs/additional-examples/evm-swap.md
Outdated
|
||
If the swap conditions aren't met then the Lit Action execution shall revert the funds to their depositors. | ||
|
||
### Architecture for Mint/Grant/Burn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should title this "Complete Swap Architecture"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The diagram depicts how the general m/g/b function and lit actions built through it works. This should be the general flow of any such scenario as swap, messaging, bridging etc.
Swap definition is provided in the lit action
|
||
You can find a generator which takes the above params to generate a Lit Action for swap: [swapActionGenerator.js](https://github.com/anshss/lit-evm-swap/blob/main/lit/swapActionGenerator.js) | ||
|
||
Remember, once a Mint/Grant/Burn PKP is created, anyone can execute the Lit Action on the Lit Network. This execution needs to define the parameters needed by the Lit Action to run. While generating a sign or checking conditions on the action, we need information around the pkp for which we are doing it. Due to this, we need to construct our Lit Action in a way that works with any PKP. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember, once a Mint/Grant/Burn PKP is created, anyone can execute the Lit Action on the Lit Network. This execution needs to define the parameters needed by the Lit Action to run. While generating a sign or checking conditions on the action, we need information around the pkp for which we are doing it. Due to this, we need to construct our Lit Action in a way that works with any PKP.
Do we need to include this info here? Also, anyone could technically 'call' it, but wouldn't it depend on where the publisher stored it in the first place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for a m/g/b function on the contracts or while simulating its approach like this example, we need to pass the cid for action in both the ways which makes a lit action an immutable piece of code. This makes it independent of the storage provider as anyway on using ipfs or arweave, your lit action would be immutable and visible to all.
As a specific session signature is not needed to just run a lit action on lit network, we need to construct our lit action in a way that it doesn't hardcode or depend on a specific pkp (in order, need to first construct the lit action and will then mint a pkp). This works like a wallet being created, then you fund the wallet, run the only action that can make a wallet create a sign, and get transactions as per conditions.
The above info describes the nature of the action where an action is independent of the pkp data and made to run for a specific pkp. We can definitely short this information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could make it to where a valid Auth Sig from either Alice or Bob has to be provided in order for the LA to execute, but not sure if it's worth adding this complexity to this example
Either way, I find the paragraph a bit confusing
docs/additional-examples/evm-swap.md
Outdated
|
||
Our Lit Action primarily focuses on three factors: | ||
|
||
- Access Conditions for checking funds on both chains |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these access control conditions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, renaming them to "access control conditions"
let chainATransaction = { | ||
to: "0xad50f302a957C165d865eD398fC3ca5A5A2cDA85", | ||
gasLimit: "60000", | ||
from: "0x291B0E3aA139b2bC9Ebd92168575b5c6bAD5236C", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could just omit this property. We don't usually specify the from
property in an ETH transaction since it's derived from the signature
const chainACondition = {"conditionType":"evmBasic","contractAddress":"0xad50f302a957C165d865eD398fC3ca5A5A2cDA85","standardContractType":"ERC20","chain":"baseSepolia","method":"balanceOf","parameters":["address"],"returnValueTest":{"comparator":">=","value":"4000000000000000000"}} | ||
const chainBCondition = {"conditionType":"evmBasic","contractAddress":"0x2dcA1a80c89c81C37efa7b401e2d20c1ED99C72F","standardContractType":"ERC20","chain":"yellowstone","method":"balanceOf","parameters":["address"],"returnValueTest":{"comparator":">=","value":"8000000000000000000"}} | ||
let chainATransaction = {"to":"0xad50f302a957C165d865eD398fC3ca5A5A2cDA85","gasLimit":"60000","from":"0x48e6a467852Fa29710AaaCDB275F85db4Fa420eB","data":"0xa9059cbb000000000000000000000000291b0e3aa139b2bc9ebd92168575b5c6bad5236c0000000000000000000000000000000000000000000000003782dace9d900000","type":2} | ||
let chainBTransaction = {"to":"0x2dcA1a80c89c81C37efa7b401e2d20c1ED99C72F","gasLimit":"60000","from":"0x291B0E3aA139b2bC9Ebd92168575b5c6bAD5236C","data":"0xa9059cbb00000000000000000000000048e6a467852fa29710aaacdb275f85db4fa420eb0000000000000000000000000000000000000000000000006f05b59d3b200000","type":2} | ||
let chainAClawbackTransaction = {"to":"0xad50f302a957C165d865eD398fC3ca5A5A2cDA85","gasLimit":"60000","from":"0x48e6a467852Fa29710AaaCDB275F85db4Fa420eB","data":"0xa9059cbb00000000000000000000000048e6a467852fa29710aaacdb275f85db4fa420eb0000000000000000000000000000000000000000000000003782dace9d900000","type":2} | ||
let chainBClawbackTransaction = {"to":"0x2dcA1a80c89c81C37efa7b401e2d20c1ED99C72F","gasLimit":"60000","from":"0x291B0E3aA139b2bC9Ebd92168575b5c6bAD5236C","data":"0xa9059cbb000000000000000000000000291b0e3aa139b2bc9ebd92168575b5c6bad5236c0000000000000000000000000000000000000000000000006f05b59d3b200000","type":2} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't we want to pass these in as a parameter to the LA? This way the LA could be reused by anyone for swaps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing these as a parameter to the la would disrupt the meaning of "trustless swap" being offered by lit protocol as the action could then be ran with wrong values at runtime as well
I've made a separate la generator script where you pass a simple set of swap parameters and it will return you a swap la, have mentioned that in the docs
my flow is to pass simple set of swap parameter like
const chainAParams = {
from: "0x48e6a467852Fa29710AaaCDB275F85db4Fa420eB",
to: "0x291B0E3aA139b2bC9Ebd92168575b5c6bAD5236C",
tokenAddress: "0xad50f302a957C165d865eD398fC3ca5A5A2cDA85",
chain: "baseSepolia",
amount: "4",
decimals: 18,
chainId: 84532,
};
const chainBParams = {
from: "0x291B0E3aA139b2bC9Ebd92168575b5c6bAD5236C",
to: "0x48e6a467852Fa29710AaaCDB275F85db4Fa420eB",
tokenAddress: "0x2dcA1a80c89c81C37efa7b401e2d20c1ED99C72F",
chain: "yellowstone",
amount: "8",
decimals: 18,
chainId: 175188,
};
to swapGenerator, then that cook you a la
let chainAClawbackTransaction = {"to":"0xad50f302a957C165d865eD398fC3ca5A5A2cDA85","gasLimit":"60000","from":"0x48e6a467852Fa29710AaaCDB275F85db4Fa420eB","data":"0xa9059cbb00000000000000000000000048e6a467852fa29710aaacdb275f85db4fa420eb0000000000000000000000000000000000000000000000003782dace9d900000","type":2} | ||
let chainBClawbackTransaction = {"to":"0x2dcA1a80c89c81C37efa7b401e2d20c1ED99C72F","gasLimit":"60000","from":"0x291B0E3aA139b2bC9Ebd92168575b5c6bAD5236C","data":"0xa9059cbb000000000000000000000000291b0e3aa139b2bc9ebd92168575b5c6bad5236c0000000000000000000000000000000000000000000000006f05b59d3b200000","type":2} | ||
|
||
chainATransaction.from = chainBTransaction.from = pkpAddress; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think this is necessary either?
```js | ||
async function getWalletA() { | ||
const provider = new ethers.providers.JsonRpcProvider( | ||
`https://yellowstone-rpc.litprotocol.com/` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`https://yellowstone-rpc.litprotocol.com/` | |
LIT_RPC.CHRONICLE_YELLOWSTONE |
true, | ||
{ | ||
value: pkpMintCost, | ||
maxFeePerGas: ethers.BigNumber.from("1800000000"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this property is required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my transaction was failing so I had to configure the gases manually
Co-authored-by: Wyatt Barnes <[email protected]>
Co-authored-by: Wyatt Barnes <[email protected]>
Co-authored-by: Wyatt Barnes <[email protected]>
Co-authored-by: Wyatt Barnes <[email protected]>
Co-authored-by: Wyatt Barnes <[email protected]>
Co-authored-by: Wyatt Barnes <[email protected]>
Description
Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change.
Type of change
Link to the relevant updated sections in the Netlify preview
Checklist:
General
If I have added a new concept, I have