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

CCIP-4474 manual exec lbtc #8

Merged
merged 11 commits into from
Dec 10, 2024
Merged

CCIP-4474 manual exec lbtc #8

merged 11 commits into from
Dec 10, 2024

Conversation

bukata-sa
Copy link
Contributor

Add lbtc manual exec feature.
If destTokenData is more than 32 bytes - attestation is disabled onchain
else - call lombard attestation api for a proof and include it as offchain token data

@bukata-sa bukata-sa requested a review from a team as a code owner December 8, 2024 14:00
@bukata-sa bukata-sa requested a review from andrevmatos December 9, 2024 11:09
Copy link

github-actions bot commented Dec 9, 2024

Coverage Report

------------------------------|---------|----------|---------|---------|----------------------------------------
File                          | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s                      
------------------------------|---------|----------|---------|---------|----------------------------------------
All files                     |   93.83 |    78.59 |   94.95 |   95.46 |                                        
 abi                          |     100 |      100 |     100 |     100 |                                        
  BurnMintERC677Token.ts      |     100 |      100 |     100 |     100 |                                        
  BurnMintTokenPool_1_5.ts    |     100 |      100 |     100 |     100 |                                        
  CommitStore_1_2.ts          |     100 |      100 |     100 |     100 |                                        
  CommitStore_1_5.ts          |     100 |      100 |     100 |     100 |                                        
  LockReleaseTokenPool_1_5.ts |     100 |      100 |     100 |     100 |                                        
  OffRamp_1_2.ts              |     100 |      100 |     100 |     100 |                                        
  OffRamp_1_5.ts              |     100 |      100 |     100 |     100 |                                        
  OnRamp_1_2.ts               |     100 |      100 |     100 |     100 |                                        
  OnRamp_1_5.ts               |     100 |      100 |     100 |     100 |                                        
  Router.ts                   |     100 |      100 |     100 |     100 |                                        
 lib                          |   93.92 |    81.19 |   97.93 |   96.05 |                                        
  commits.ts                  |    90.9 |    56.25 |     100 |   93.54 | 70,91                                  
  errors.ts                   |   93.97 |    87.23 |     100 |   96.05 | 162,181,189                            
  execution.ts                |   91.04 |    76.59 |      95 |   94.11 | 163-164,185-186,226,240,314            
  gas.ts                      |   94.33 |    66.66 |     100 |   96.15 | 86,126                                 
  offchain.ts                 |   98.66 |    91.89 |     100 |   98.59 | 128                                    
  requests.ts                 |   92.98 |    78.57 |   93.33 |   96.19 | 32,163,213,247                         
  selectors.ts                |     100 |      100 |     100 |     100 |                                        
  types.ts                    |     100 |      100 |     100 |     100 |                                        
  utils.ts                    |    93.1 |    81.57 |     100 |   95.32 | 53,66,73-74,125                        
 lib/hasher                   |      93 |    62.16 |   81.81 |   92.36 |                                        
  hasher.ts                   |     100 |    66.66 |     100 |     100 | 50                                     
  index.ts                    |     100 |      100 |   42.85 |     100 |                                        
  merklemulti.ts              |   91.15 |    61.76 |     100 |   90.74 | 52,147,210,229,233,239,243,248,295,304 
------------------------------|---------|----------|---------|---------|----------------------------------------

Copy link
Collaborator

@andrevmatos andrevmatos left a comment

Choose a reason for hiding this comment

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

Getting there!

src/lib/types.ts Outdated Show resolved Hide resolved
src/lib/offchain.test.ts Outdated Show resolved Hide resolved
src/lib/types.ts Outdated Show resolved Hide resolved
src/lib/offchain.ts Show resolved Hide resolved
src/lib/offchain.ts Show resolved Hide resolved
src/lib/offchain.ts Outdated Show resolved Hide resolved
Comment on lines 168 to 182
const attestations: (string | undefined)[] = []
for (const [i, _] of msg.tokenAmounts.entries()) {
const destTokenData = parseSourceTokenData(msg.sourceTokenData[i]).extraData
// If attestation is required, SourceTokenData.extraData will be 32 bytes ('0x' + 64 hex chars)
// otherwise attestation is not required
if (destTokenData.length !== 66) {
attestations.push(undefined)
continue
}
// check that this is LBTC indeed
if (lbtcDepositHashes.includes(destTokenData)) {
attestations.push(await getLbtcAttestation(destTokenData, isTestnet))
}
}
return attestations
Copy link
Collaborator

Choose a reason for hiding this comment

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

This function return usage requires exactly 1 entry per tokenAmount, otherwise the align by index inside fetchOffchainTokenData is not gonna work properly; But your loop here doesn't guarantee it'll return exactly tokenAmounts.length entries (e.g. when destTokenData.length == 66 but lbtcDepositHashes doesn't include it).

I'd suggest a Promise.all(tokenAmounts.map) (which guarantees/expresses better 1-to-1 result), and inside, you do your checks/requests, return the result if you have it, and let it fall through to return undefined in the end if some condition isn't met.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

src/lib/offchain.ts Show resolved Hide resolved

type AttestationResponse =
| { error: 'string' }
| { status: 'pending_confirmations' }
| { status: 'complete'; attestation: string }

type LombardAttestation = { status: string; message_hash: string; attestation: string }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: I see you compare status here with some constant. You don't need to extract that const in a global var, but if you can get a small list of possible status, it'd be nice to hardcode them as a union of string literals here, as it'll aid the constant comparison down there.

Suggested change
type LombardAttestation = { status: string; message_hash: string; attestation: string }
type LombardAttestation = { status: string; message_hash: string; attestation: string }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@bukata-sa bukata-sa requested a review from andrevmatos December 9, 2024 16:05
andrevmatos
andrevmatos previously approved these changes Dec 9, 2024
Copy link
Collaborator

@andrevmatos andrevmatos left a comment

Choose a reason for hiding this comment

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

Good job on this implementation!

src/lib/offchain.ts Show resolved Hide resolved
@andrevmatos
Copy link
Collaborator

Can you add a CHANGELOG entry, please?

@bukata-sa bukata-sa merged commit 9249c1d into main Dec 10, 2024
1 check passed
@bukata-sa bukata-sa deleted the feature/lbtc-manual-exec branch December 10, 2024 13:08
andrevmatos pushed a commit that referenced this pull request Dec 10, 2024
Add lbtc manual exec feature.
If destTokenData is more than 32 bytes - attestation is disabled onchain
else - call lombard attestation api for a proof and include it as
offchain token data
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