-
Notifications
You must be signed in to change notification settings - Fork 303
feat(sdk-coin-eth): add zama token withdrawal support #8919
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
Draft
MohammedRyaan786
wants to merge
1
commit into
master
Choose a base branch
from
CHALO-529
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,113
−18
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| export * from './baseNFTTransferBuilder'; | ||
| export * from './transferBuilderERC1155'; | ||
| export * from './transferBuilderERC721'; | ||
| export * from './transferBuilderERC7984'; |
133 changes: 133 additions & 0 deletions
133
modules/abstract-eth/src/lib/transferBuilders/transferBuilderERC7984.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| import { BuildTransactionError, InvalidParameterValueError } from '@bitgo/sdk-core'; | ||
| import { coins, EthereumNetwork as EthLikeNetwork } from '@bitgo/statics'; | ||
|
|
||
| import { ContractCall } from '../contractCall'; | ||
| import { decodeConfidentialTransferData, isValidEthAddress, sendMultiSigData } from '../utils'; | ||
| import { BaseNFTTransferBuilder } from './baseNFTTransferBuilder'; | ||
| import { confidentialTransferWithProofMethodId, confidentialTransferWithProofTypes } from '../walletUtil'; | ||
|
|
||
| export class TransferBuilderERC7984 extends BaseNFTTransferBuilder { | ||
| private _encryptedHandle: string; | ||
| private _inputProof: string; | ||
| /** Plaintext token amount in base units, stored as metadata only (NOT included in calldata). */ | ||
| private _amount: string; | ||
|
|
||
| constructor(serializedData?: string) { | ||
| super(serializedData); | ||
| if (serializedData) { | ||
| this.decodeTransferData(serializedData); | ||
| } | ||
| } | ||
|
|
||
| coin(coin: string): this { | ||
| this._coin = coins.get(coin); | ||
| this._nativeCoinOperationHashPrefix = (this._coin.network as EthLikeNetwork).nativeCoinOperationHashPrefix; | ||
| return this; | ||
| } | ||
|
|
||
| tokenContractAddress(address: string): this { | ||
| if (isValidEthAddress(address)) { | ||
| this._tokenContractAddress = address; | ||
| return this; | ||
| } | ||
| throw new InvalidParameterValueError('Invalid address'); | ||
| } | ||
|
|
||
| /** | ||
| * Set the plaintext transfer amount in base units. | ||
| * | ||
| * This value is stored as metadata only — it is NOT included in the on-chain | ||
| * calldata, which carries only the encrypted form (encryptedHandle + inputProof). | ||
| * Storing it here lets verifyTransaction confirm the signer's intent against | ||
| * the original amount the client submitted. | ||
| */ | ||
| amount(amount: string): this { | ||
| if (!/^\d+$/.test(amount) || BigInt(amount) <= 0n) { | ||
| throw new InvalidParameterValueError('amount must be a positive integer string in base units'); | ||
| } | ||
| this._amount = amount; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Set the encrypted handle (bytes32 hex from WP) | ||
| * Must be a 0x-prefixed 32-byte hex string (66 chars total) | ||
| */ | ||
| encryptedHandle(handle: string): this { | ||
| if (!/^0x[0-9a-fA-F]{64}$/.test(handle)) { | ||
| throw new InvalidParameterValueError('encryptedHandle must be a 0x-prefixed 32-byte hex string (66 characters)'); | ||
| } | ||
| this._encryptedHandle = handle; | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Set the input proof (bytes hex from WP) | ||
| * Must be a 0x-prefixed non-empty hex bytes string | ||
| */ | ||
| inputProof(proof: string): this { | ||
| if (!/^0x[0-9a-fA-F]{2,}$/.test(proof)) { | ||
| throw new InvalidParameterValueError('inputProof must be a 0x-prefixed non-empty hex bytes string'); | ||
| } | ||
| this._inputProof = proof; | ||
|
MohammedRyaan786 marked this conversation as resolved.
|
||
| return this; | ||
| } | ||
|
|
||
| getIsFirstSigner(): boolean { | ||
| return false; | ||
| } | ||
|
|
||
| build(): string { | ||
| this.validateMandatoryFields(); | ||
| const contractCall = new ContractCall(confidentialTransferWithProofMethodId, confidentialTransferWithProofTypes, [ | ||
| this._toAddress, | ||
| this._encryptedHandle, | ||
| this._inputProof, | ||
| ]); | ||
| return contractCall.serialize(); | ||
| } | ||
|
|
||
| signAndBuild(chainId: string): string { | ||
| if (!Number.isInteger(this._sequenceId)) { | ||
| throw new BuildTransactionError('Missing mandatory field: contract sequence id'); | ||
| } | ||
| this._chainId = chainId; | ||
| this.validateMandatoryFields(); | ||
| this._data = this.build(); | ||
|
|
||
| return sendMultiSigData( | ||
| this._tokenContractAddress, | ||
| '0', | ||
| this._data, | ||
| this._expirationTime, | ||
| this._sequenceId, | ||
| this.getSignature() | ||
| ); | ||
| } | ||
|
|
||
| private validateMandatoryFields(): void { | ||
| if (!this._toAddress) { | ||
| throw new BuildTransactionError('Missing mandatory field: destination (to) address'); | ||
| } | ||
| if (!this._tokenContractAddress) { | ||
| throw new BuildTransactionError('Missing mandatory field: token contract address'); | ||
| } | ||
| if (!this._encryptedHandle) { | ||
| throw new BuildTransactionError('Missing mandatory field: encryptedHandle'); | ||
| } | ||
| if (!this._inputProof || this._inputProof === '0x' || !/^0x[0-9a-fA-F]{2,}$/.test(this._inputProof)) { | ||
| throw new BuildTransactionError('Missing mandatory field: inputProof'); | ||
| } | ||
|
MohammedRyaan786 marked this conversation as resolved.
|
||
| } | ||
|
MohammedRyaan786 marked this conversation as resolved.
|
||
|
|
||
| private decodeTransferData(data: string): void { | ||
| const transferData = decodeConfidentialTransferData(data); | ||
| this._toAddress = transferData.toAddress; | ||
| this._tokenContractAddress = transferData.tokenContractAddress; | ||
| this._encryptedHandle = transferData.encryptedHandle; | ||
| this._inputProof = transferData.inputProof; | ||
| this._expirationTime = parseInt(transferData.expireTime, 10); | ||
| this._sequenceId = parseInt(transferData.sequenceId, 10); | ||
| this._signature = transferData.signature; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.