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

Fix spend logic for unlock deposit amount #86

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/apis/platformvm/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2586,7 +2586,7 @@ export class PlatformVMAPI extends JRPCAPI {
})

if (depositOfferOwnerAuth.length !== depositOfferOwnerSigs.length) {
throw new Error("OwnerAuth length must mathch OwnerSigs length")
throw new Error("OwnerAuth length must match OwnerSigs length")
}

const o_auth: [number, Buffer][] = []
Expand Down Expand Up @@ -2641,17 +2641,18 @@ export class PlatformVMAPI extends JRPCAPI {
* @param changeAddresses The addresses that can spend the change remaining from the spent UTXOs.
* @param memo Optional contains arbitrary bytes, up to 256 bytes
* @param asOf Optional. The timestamp to verify the transaction against as a {@link https://github.com/indutny/bn.js/|BN}
* @param amountToUnlock The amount of tokens to unlock from the deposit
* @param changeThreshold Optional. The number of signatures required to spend the funds in the resultant change UTXO
*
* @returns An unsigned transaction created from the passed in parameters.
*/
buildUnlockDepositTx = async (
utxoset: UTXOSet,
fromAddresses: string[],
fromAddresses: FromType,
Copy link

@VjeraTurk VjeraTurk Feb 11, 2025

Choose a reason for hiding this comment

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

Instead of fromAdresses we need depositTxIDs (better than depositOfferId)
We skip the amount for now

changeAddresses: string[] = undefined,
memo: PayloadBase | Buffer = undefined,
asOf: BN = ZeroBN,
amountToLock: BN,
amountToUnlock: BN,
changeThreshold: number = 1
): Promise<UnsignedTx> => {
const caller = "buildUnlockDepositTx"
Expand Down Expand Up @@ -2680,6 +2681,7 @@ export class PlatformVMAPI extends JRPCAPI {
avaxAssetID,
memo,
asOf,
amountToUnlock,
changeThreshold
)

Expand Down
4 changes: 3 additions & 1 deletion src/apis/platformvm/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1415,6 +1415,7 @@ export class Builder {
* @param feeAssetID Optional. The assetID of the fees being burned
* @param memo Optional contains arbitrary bytes, up to 256 bytes
* @param asOf Optional. The timestamp to verify the transaction against as a {@link https://github.com/indutny/bn.js/|BN}
* @param amountToUnlock The amount of tokens to unlock
* @param changeThreshold Optional. The number of signatures required to spend the funds in the resultant change UTXO
*
* @returns An unsigned UnlockDepositTx created from the passed in parameters.
Expand All @@ -1428,6 +1429,7 @@ export class Builder {
feeAssetID: Buffer = undefined,
memo: Buffer = undefined,
asOf: BN = zero,
amountToUnlock: BN,
changeThreshold: number = 1
): Promise<UnsignedTx> => {
let ins: TransferableInput[] = []
Expand All @@ -1443,7 +1445,7 @@ export class Builder {
changeThreshold
)

aad.addAssetAmount(feeAssetID, zero, fee)
aad.addAssetAmount(feeAssetID, amountToUnlock, fee)

const minSpendableErr: Error = await this.spender.getMinimumSpendable(
Copy link

@VjeraTurk VjeraTurk Feb 11, 2025

Choose a reason for hiding this comment

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

  1. call spend for burning the already unlocked UTXOs
  2. call a call to a different function (undeposit ) to unlock the locked UTXOs

aad,
Expand Down
Loading