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

Feature/refactor lib #84

Merged
merged 7 commits into from
Feb 7, 2024
Merged

Feature/refactor lib #84

merged 7 commits into from
Feb 7, 2024

Conversation

Ptroger
Copy link
Contributor

@Ptroger Ptroger commented Feb 5, 2024

No description provided.

@Ptroger Ptroger marked this pull request as ready for review February 5, 2024 02:11
@@ -249,7 +249,7 @@ const ERC20_TRANSFER_INTENT: TransferErc20 = {
type: Intents.TRANSFER_ERC20,
to: `eip155:137/0x031d8c0ca142921c459bcb28104c0ff37928f9ed` as AccountId,
from: `eip155:137/${ERC20_TRANSFER_TX_REQUEST.from.toLowerCase()}` as AccountId,
contract: `eip155:137/${ERC20_TRANSFER_TX_REQUEST.to?.toLowerCase()}` as AccountId,
token: `eip155:137/${ERC20_TRANSFER_TX_REQUEST.to?.toLowerCase()}` as AccountId,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
token: `eip155:137/${ERC20_TRANSFER_TX_REQUEST.to?.toLowerCase()}` as AccountId,
token: getAccountId(`eip155:137/${ERC20_TRANSFER_TX_REQUEST.to?.toLowerCase()}`),

Use the utility function to get an account ID to ensure the format is right on your tests.

@@ -267,7 +267,7 @@ const ERC721_SAFE_TRANSFER_FROM_INTENT: TransferErc721 = {
to: `eip155:137/0xb253f6156e64b12ba0dec3974062dbbaee139f0c` as AccountId,
from: `eip155:137/${ERC721_SAFE_TRANSFER_FROM_TX_REQUEST.from.toLowerCase()}` as AccountId,
contract: `eip155:137/${ERC721_SAFE_TRANSFER_FROM_TX_REQUEST.to?.toLowerCase()}` as AccountId,
nftId: `eip155:137/erc721:${ERC721_SAFE_TRANSFER_FROM_TX_REQUEST.to}/41173` as AssetId
token: `eip155:137/erc721:${ERC721_SAFE_TRANSFER_FROM_TX_REQUEST.to}/41173` as AssetId
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
token: `eip155:137/erc721:${ERC721_SAFE_TRANSFER_FROM_TX_REQUEST.to}/41173` as AssetId
token: getAssetId(`eip155:137/erc721:${ERC721_SAFE_TRANSFER_FROM_TX_REQUEST.to}/41173`)

@@ -315,7 +315,7 @@ const ERC1155_SAFE_TRANSFER_FROM_INTENT: TransferErc1155 = {
to: `eip155:137/0x00ca04c45da318d5b7e7b14d5381ca59f09c73f0` as AccountId,
from: `eip155:137/${ERC1155_SAFE_TRANSFER_FROM_TX_REQUEST.from.toLowerCase()}` as AccountId,
contract: `eip155:137/${ERC1155_SAFE_TRANSFER_FROM_TX_REQUEST.to?.toLowerCase()}` as AccountId,
transfers: [{ tokenId: `eip155:137/erc1155:${ERC1155_SAFE_TRANSFER_FROM_TX_REQUEST.to}/175` as AssetId, amount: '1' }]
transfers: [{ token: `eip155:137/erc1155:${ERC1155_SAFE_TRANSFER_FROM_TX_REQUEST.to}/175` as AssetId, amount: '1' }]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Out of curiosity, why the amount is a 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.

Amount is a bigint encoded in Hex. So I decode it back to bigint and send it as a string, so that consumer decides how/if it needs to be encoded back into a number.

Comment on lines +67 to 72
const result = safeDecode({
input: {
type: InputType.TRANSACTION_REQUEST,
txRequest: authzRequest.request.transactionRequest
}
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you think something like this would be possible?

Suggested change
const result = safeDecode({
input: {
type: InputType.TRANSACTION_REQUEST,
txRequest: authzRequest.request.transactionRequest
}
})
const result = safeDecode(authzRequest.request.transactionRequest)
// or
const result = safeDecode(authzRequest.request.message)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess it wouldn't be.

If you look at the shape of the safeDecode input, it's like so:
{ input, config = defaultConfig }: { input: DecodeInput; config?: Config }

config include all the user trustworthy data that will be used to decode the input.

  • transaction registry
  • contract registry
  • set of supported methods and their decoder (default to my current set)

What is doable is determining the InputType, and then do something like this:

safeDecode({ input })

Or

safeDecode({ input, config })

}
return intent
return {
to: toAccountIdLowerCase({
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe you can use the toAccountId again? I changed it last week to respect the given format. In other words, if you send checksummed address you should get checksummed ID, or if you send lower case address you'll get lower case ID

Suggested change
to: toAccountIdLowerCase({
to: toAccountId({

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha

payload: input.raw.rawData
}
default:
throw new Error('Invalid input type')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
throw new Error('Invalid input type')
throw new DecodeError('Invalid input type')

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 changing those

super(input)
this.#input = input
if (!isSupportedMethodId(methodId)) {
throw new Error('Unsupported methodId')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
throw new Error('Unsupported methodId')
throw new DecodeError('Unsupported methodId')

}
const params = extract(supportedMethods, data, methodId) as ApproveAllowanceParams
if (!params) {
throw new Error('Params do not match ERC20 transfer methodId')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
throw new Error('Params do not match ERC20 transfer methodId')
throw new DecodeError('Params do not match ERC20 transfer methodId')

Copy link
Collaborator

@wcalderipe wcalderipe left a comment

Choose a reason for hiding this comment

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

I left some comments. Nothing critical or blocking your PR.

If you CMD/CTRL + F "throw new Error" you'll notice a bunch of pending domain errors yet 😉

message: string
}

export type SignRawMessage = {
type: Intents.SIGN_RAW_MESSAGE
from: AccountId
message: string
Copy link
Contributor

Choose a reason for hiding this comment

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

@Ptroger as discussed, you removed the wrong data

@Ptroger Ptroger merged commit bbf8d61 into main Feb 7, 2024
2 checks passed
@Ptroger Ptroger deleted the feature/refactor-lib branch February 7, 2024 14:24
mattschoch pushed a commit that referenced this pull request Jun 19, 2024
* changed interface

* changed intent naming, changed usage of lib in apps

* format and lint

* Update rego criteria

* changed interface

* used decoderErros

* fix

---------

Co-authored-by: samuel <samuel@narval.xyz>
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