From 430b5306ca2712608e9c0b5768e3823d8f5b3a18 Mon Sep 17 00:00:00 2001 From: Polybius93 Date: Fri, 29 Nov 2024 18:22:39 +0100 Subject: [PATCH] feat: add ticket fields to xrpl functions --- .gitignore | 3 -- src/network-handlers/ripple-handler.ts | 69 +++++++++++++++----------- yarn.lock | 4 -- 3 files changed, 39 insertions(+), 37 deletions(-) diff --git a/.gitignore b/.gitignore index a138e33..2b3f55c 100644 --- a/.gitignore +++ b/.gitignore @@ -132,6 +132,3 @@ dist .yarn/build-state.yml .yarn/install-state.gz .pnp.* - -# Local Netlify folder -.netlify diff --git a/src/network-handlers/ripple-handler.ts b/src/network-handlers/ripple-handler.ts index 43e74bc..d6751d7 100644 --- a/src/network-handlers/ripple-handler.ts +++ b/src/network-handlers/ripple-handler.ts @@ -155,9 +155,12 @@ export class RippleHandler { }); } - async submitCreateTicketTransaction(signedTransactionBlobs: string[]): Promise { + async submitCreateTicketTransaction(xrplSignatures: XRPLSignatures[]): Promise { return await this.withConnectionMgmt(async () => { try { + const signedTransactionBlobs = xrplSignatures.find( + sig => sig.signatureType === 'createTicket' + )!.signatures; const multisignedTransaction = multiSignTransaction(signedTransactionBlobs); const submitCreateTicketTransactionResponse = @@ -189,7 +192,7 @@ export class RippleHandler { async createTicket( ticketCount: number, autoFillValues?: AutoFillValues - ): Promise { + ): Promise { return await this.withConnectionMgmt(async () => { try { const createTicketRequest: TicketCreate = { @@ -224,15 +227,17 @@ export class RippleHandler { ).tx_blob; console.log('createTicketTransactionSignature: ', createTicketTransactionSignature); - return { - tx_blob: createTicketTransactionSignature, - autoFillValues: { - signatureType: 'createTicket', - LastLedgerSequence: preparedCreateTicketTransaction.LastLedgerSequence!, - Sequence: preparedCreateTicketTransaction.Sequence!, - Fee: preparedCreateTicketTransaction.Fee!, + return [ + { + tx_blob: createTicketTransactionSignature, + autoFillValues: { + signatureType: 'createTicket', + LastLedgerSequence: preparedCreateTicketTransaction.LastLedgerSequence!, + Sequence: preparedCreateTicketTransaction.Sequence!, + Fee: preparedCreateTicketTransaction.Fee!, + }, }, - }; + ]; } catch (error) { throw new RippleError(`Could not create Ticket: ${error}`); } @@ -245,6 +250,7 @@ export class RippleHandler { timeStamp: number, btcMintFeeBasisPoints: number, btcRedeemFeeBasisPoints: number, + ticket: string, autoFillValues?: AutoFillValues[] ): Promise { return await this.withConnectionMgmt(async () => { @@ -259,7 +265,7 @@ export class RippleHandler { return [ await this.mintNFT( newVault, - undefined, + ticket, autoFillValues?.find(sig => sig.signatureType === 'mintNFT') ), ]; @@ -272,6 +278,7 @@ export class RippleHandler { async withdraw( uuid: string, withdrawAmount: bigint, + tickets: string[], autoFillValues: AutoFillValues[] ): Promise { return await this.withConnectionMgmt(async () => { @@ -283,14 +290,14 @@ export class RippleHandler { const thisVault = await this.getRawVault(nftUUID); const burnSig = await this.burnNFT( nftUUID, - 1, + tickets[0], autoFillValues.find(sig => sig.signatureType === 'burnNFT') ); thisVault.valueMinted = thisVault.valueMinted.sub(BigNumber.from(withdrawAmount)); const mintSig = await this.mintNFT( thisVault, - 2, + tickets[1], autoFillValues.find(sig => sig.signatureType === 'mintNFT') ); return [burnSig, mintSig]; @@ -482,7 +489,7 @@ export class RippleHandler { async burnNFT( nftUUID: string, - incrementBy: number = 0, + ticket: string, autoFillValues?: AutoFillValues ): Promise { return await this.withConnectionMgmt(async () => { @@ -491,6 +498,8 @@ export class RippleHandler { const nftTokenId = await this.getNFTokenIdForVault(nftUUID); const burnTransactionJson: SubmittableTransaction = { TransactionType: 'NFTokenBurn', + TicketSequence: new Decimal(ticket).toNumber(), + Sequence: 0, Account: this.issuerAddress, NFTokenID: nftTokenId, }; @@ -509,10 +518,6 @@ export class RippleHandler { // https://xrpl.org/docs/concepts/accounts/tickets preparedBurnTx.LastLedgerSequence = Math.ceil(preparedBurnTx.LastLedgerSequence! / 10000 + 1) * 10000; - - if (incrementBy > 0) { - preparedBurnTx.Sequence = preparedBurnTx.Sequence! + incrementBy; - } } console.log('preparedBurnTx ', preparedBurnTx); @@ -537,7 +542,7 @@ export class RippleHandler { async mintNFT( vault: RawVault, - incrementBy: number = 0, + ticket: string, autoFillValues?: AutoFillValues ): Promise { return await this.withConnectionMgmt(async () => { @@ -549,6 +554,8 @@ export class RippleHandler { console.log('newURI: ', newURI); const mintTransactionJson: SubmittableTransaction = { TransactionType: 'NFTokenMint', + TicketSequence: new Decimal(ticket).toNumber(), + Sequence: 0, Account: this.issuerAddress, URI: newURI, NFTokenTaxon: 0, @@ -568,9 +575,6 @@ export class RippleHandler { // https://xrpl.org/docs/concepts/accounts/tickets preparedMintTx.LastLedgerSequence = Math.ceil(preparedMintTx.LastLedgerSequence! / 10000 + 1) * 10000; - if (incrementBy > 0) { - preparedMintTx.Sequence = preparedMintTx.Sequence! + incrementBy; - } } console.log('preparedMintTx ', preparedMintTx); @@ -594,6 +598,7 @@ export class RippleHandler { async getSigUpdateVaultForSSP( uuid: string, updates: SSPVaultUpdate, + ticket: string, autoFillValues?: AutoFillValues ): Promise { return await this.withConnectionMgmt(async () => { @@ -609,7 +614,7 @@ export class RippleHandler { taprootPubKey: updates.taprootPubKey, }; console.log(`the updated vault: `, updatedVault); - return await this.mintNFT(updatedVault, 1, autoFillValues); + return await this.mintNFT(updatedVault, ticket, autoFillValues); } catch (error) { throw new RippleError(`Could not update Vault: ${error}`); } @@ -619,7 +624,7 @@ export class RippleHandler { async getSigUpdateVaultForSSF( uuid: string, updates: SSFVaultUpdate, - updateSequenceBy: number, + ticket: string, autoFillValues?: AutoFillValues ): Promise { return await this.withConnectionMgmt(async () => { @@ -634,7 +639,7 @@ export class RippleHandler { valueMinted: BigNumber.from(updates.valueMinted), valueLocked: BigNumber.from(updates.valueLocked), }; - return await this.mintNFT(updatedVault, updateSequenceBy, autoFillValues); + return await this.mintNFT(updatedVault, ticket, autoFillValues); } catch (error) { throw new RippleError(`Could not update Vault: ${error}`); } @@ -664,6 +669,7 @@ export class RippleHandler { async getCashCheckAndWithdrawSignatures( txHash: string, + tickets: string[], autoFillValues?: AutoFillValues[] ): Promise { return await this.withConnectionMgmt(async () => { @@ -688,12 +694,14 @@ export class RippleHandler { const checkCashSignatures = await this.cashCheck( check.index, checkSendMax.value, + tickets[0], autoFillValues?.find(sig => sig.signatureType === 'cashCheck') ); const mintAndBurnSignatures = await this.withdraw( vault.uuid, BigInt(shiftValue(Number(checkSendMax.value))), + tickets.slice(1), autoFillValues ?? [] ); return [checkCashSignatures, ...mintAndBurnSignatures]; @@ -706,6 +714,7 @@ export class RippleHandler { async cashCheck( checkID: string, dlcBTCAmount: string, + ticket: string, autoFillValues?: AutoFillValues ): Promise { return await this.withConnectionMgmt(async () => { @@ -716,6 +725,8 @@ export class RippleHandler { TransactionType: 'CheckCash', Account: this.issuerAddress, CheckID: checkID, + TicketSequence: new Decimal(ticket).toNumber(), + Sequence: 0, Amount: { currency: XRPL_DLCBTC_CURRENCY_HEX, value: dlcBTCAmount, @@ -768,7 +779,7 @@ export class RippleHandler { updatedValueMinted: number, destinationAddress: string, valueMinted: number, - incrementBy: number = 0, + ticket: string, autoFillValues?: AutoFillValues ): Promise { return await this.withConnectionMgmt(async () => { @@ -786,6 +797,8 @@ export class RippleHandler { const sendTokenTransactionJSON: Payment = { TransactionType: 'Payment', Account: this.issuerAddress, + TicketSequence: new Decimal(ticket).toNumber(), + Sequence: 0, Destination: destinationAddress, DestinationTag: 1, Amount: { @@ -812,10 +825,6 @@ export class RippleHandler { // https://xrpl.org/docs/concepts/accounts/tickets preparedSendTokenTx.LastLedgerSequence = Math.ceil(preparedSendTokenTx.LastLedgerSequence! / 10000 + 1) * 10000; - - if (incrementBy > 0) { - preparedSendTokenTx.Sequence = preparedSendTokenTx.Sequence! + incrementBy; - } } console.log('Issuer is about to sign the following mintTokens tx: ', preparedSendTokenTx); diff --git a/yarn.lock b/yarn.lock index effad5f..69fc3e6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4478,11 +4478,7 @@ ripple-address-codec@^5.0.0: "@scure/base" "^1.1.3" "@xrplf/isomorphic" "^1.0.0" -<<<<<<< HEAD -ripple-binary-codec@^2.1.0: -======= ripple-binary-codec@2.1.0, ripple-binary-codec@^2.1.0: ->>>>>>> main version "2.1.0" resolved "https://registry.yarnpkg.com/ripple-binary-codec/-/ripple-binary-codec-2.1.0.tgz#f1ef81f8d1f05a6cecc06fc6d9b13456569cafda" integrity sha512-q0GAx+hj3UVcDbhXVjk7qeNfgUMehlElYJwiCuIBwqs/51GVTOwLr39Ht3eNsX5ow2xPRaC5mqHwcFDvLRm6cA==