Skip to content

Commit

Permalink
feat: add ticket fields to xrpl functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Polybius93 committed Nov 29, 2024
1 parent 6dbe960 commit 430b530
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 37 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,3 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

# Local Netlify folder
.netlify
69 changes: 39 additions & 30 deletions src/network-handlers/ripple-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,12 @@ export class RippleHandler {
});
}

async submitCreateTicketTransaction(signedTransactionBlobs: string[]): Promise<string[]> {
async submitCreateTicketTransaction(xrplSignatures: XRPLSignatures[]): Promise<string[]> {
return await this.withConnectionMgmt(async () => {
try {
const signedTransactionBlobs = xrplSignatures.find(
sig => sig.signatureType === 'createTicket'
)!.signatures;
const multisignedTransaction = multiSignTransaction(signedTransactionBlobs);

const submitCreateTicketTransactionResponse =
Expand Down Expand Up @@ -189,7 +192,7 @@ export class RippleHandler {
async createTicket(
ticketCount: number,
autoFillValues?: AutoFillValues
): Promise<MultisignatureTransactionResponse> {
): Promise<MultisignatureTransactionResponse[]> {
return await this.withConnectionMgmt(async () => {
try {
const createTicketRequest: TicketCreate = {
Expand Down Expand Up @@ -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}`);
}
Expand All @@ -245,6 +250,7 @@ export class RippleHandler {
timeStamp: number,
btcMintFeeBasisPoints: number,
btcRedeemFeeBasisPoints: number,
ticket: string,
autoFillValues?: AutoFillValues[]
): Promise<MultisignatureTransactionResponse[]> {
return await this.withConnectionMgmt(async () => {
Expand All @@ -259,7 +265,7 @@ export class RippleHandler {
return [
await this.mintNFT(
newVault,
undefined,
ticket,
autoFillValues?.find(sig => sig.signatureType === 'mintNFT')
),
];
Expand All @@ -272,6 +278,7 @@ export class RippleHandler {
async withdraw(
uuid: string,
withdrawAmount: bigint,
tickets: string[],
autoFillValues: AutoFillValues[]
): Promise<MultisignatureTransactionResponse[]> {
return await this.withConnectionMgmt(async () => {
Expand All @@ -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];
Expand Down Expand Up @@ -482,7 +489,7 @@ export class RippleHandler {

async burnNFT(
nftUUID: string,
incrementBy: number = 0,
ticket: string,
autoFillValues?: AutoFillValues
): Promise<MultisignatureTransactionResponse> {
return await this.withConnectionMgmt(async () => {
Expand All @@ -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,
};
Expand All @@ -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);
Expand All @@ -537,7 +542,7 @@ export class RippleHandler {

async mintNFT(
vault: RawVault,
incrementBy: number = 0,
ticket: string,
autoFillValues?: AutoFillValues
): Promise<MultisignatureTransactionResponse> {
return await this.withConnectionMgmt(async () => {
Expand All @@ -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,
Expand All @@ -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);
Expand All @@ -594,6 +598,7 @@ export class RippleHandler {
async getSigUpdateVaultForSSP(
uuid: string,
updates: SSPVaultUpdate,
ticket: string,
autoFillValues?: AutoFillValues
): Promise<MultisignatureTransactionResponse> {
return await this.withConnectionMgmt(async () => {
Expand All @@ -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}`);
}
Expand All @@ -619,7 +624,7 @@ export class RippleHandler {
async getSigUpdateVaultForSSF(
uuid: string,
updates: SSFVaultUpdate,
updateSequenceBy: number,
ticket: string,
autoFillValues?: AutoFillValues
): Promise<MultisignatureTransactionResponse> {
return await this.withConnectionMgmt(async () => {
Expand All @@ -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}`);
}
Expand Down Expand Up @@ -664,6 +669,7 @@ export class RippleHandler {

async getCashCheckAndWithdrawSignatures(
txHash: string,
tickets: string[],
autoFillValues?: AutoFillValues[]
): Promise<MultisignatureTransactionResponse[]> {
return await this.withConnectionMgmt(async () => {
Expand All @@ -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];
Expand All @@ -706,6 +714,7 @@ export class RippleHandler {
async cashCheck(
checkID: string,
dlcBTCAmount: string,
ticket: string,
autoFillValues?: AutoFillValues
): Promise<MultisignatureTransactionResponse> {
return await this.withConnectionMgmt(async () => {
Expand All @@ -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,
Expand Down Expand Up @@ -768,7 +779,7 @@ export class RippleHandler {
updatedValueMinted: number,
destinationAddress: string,
valueMinted: number,
incrementBy: number = 0,
ticket: string,
autoFillValues?: AutoFillValues
): Promise<MultisignatureTransactionResponse | undefined> {
return await this.withConnectionMgmt(async () => {
Expand All @@ -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: {
Expand All @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
=======
[email protected], 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==
Expand Down

0 comments on commit 430b530

Please sign in to comment.