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

Update currency string representation #115

Closed
wants to merge 6 commits into from
Closed

Conversation

diehuxx
Copy link
Contributor

@diehuxx diehuxx commented Dec 14, 2023

Update currency amount representation and validation based on this spec change: TBD54566975/tbdex#206

Changes based on the spec

Update the protocol spec, test-vectors, and examples to represent currencies as decided in issue #199 in this comment here.

  1. Strings
  2. Containing major unit amounts
  3. Decimals using period . as the decimal separator regardless of currency.
    Currency representation tbdex#199 (comment)

The updated fields taken from this comment here.

Old New
offering.payinCurrency.minSubunits minAmount
offering.payinCurrency.maxSubunits maxAmount
offering.payoutCurrency.minSubunits minAmount
offering.payoutCurrency.maxSubunits maxAmount
offering.paymentMethods[*].feeSubunits fee
rfq.payinSubunits payinAmount
quote.payin.amountSubunits amount
quote.payin.feeSubunits fee
quote.payout.amountSubunits amount
quote.payout.feeSubunits fee

Notes

I added an await Message.validate(<message-object> to each #create method. Since the updated test-vectors in the spec change PR include regex for decimal strings, we can use Message.validate() to check that currency strings are in fact valid.

Copy link

changeset-bot bot commented Dec 14, 2023

⚠️ No Changeset found

Latest commit: 6bfbd09

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

@kirahsapong kirahsapong left a comment

Choose a reason for hiding this comment

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

nice!

@@ -202,8 +202,8 @@ export class DevTools {
btcAddress: '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa'
}
},
payinSubunits : '20000',
claims : [signedCredential]
payinAmount : '20000',
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
payinAmount : '20000',
payinAmount : '200.00',

@@ -226,9 +226,9 @@ export type QuoteDetails = {
/** ISO 3166 currency code string */
currencyCode: string
/** The amount of currency expressed in the smallest respective unit */
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/** The amount of currency expressed in the smallest respective unit */
/** The amount of currency to two decimal places expressed as a string (ie. '1000.00')*/

@@ -21,8 +21,8 @@ const rfqData: RfqData = {
btcAddress: '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa'
}
},
payinSubunits : '20000',
claims : ['']
payinAmount : '20000',
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
payinAmount : '20000',
payinAmount : '200.00',

@@ -190,8 +190,8 @@ describe('Rfq', () => {
btcAddress: '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa'
}
},
payinSubunits : '20000',
claims : [signedCredential]
payinAmount : '20000',
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
payinAmount : '20000',
payinAmount : '200.00',

@@ -229,8 +229,8 @@ describe('Rfq', () => {
btcAddress: '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa'
}
},
payinSubunits : '20000',
claims : [signedCredential]
payinAmount : '20000',
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
payinAmount : '20000',
payinAmount : '200.00',

},
payoutUnitsPerPayinUnit : '0.000038',
payinMethods : [{
rate : '0.000038',
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the rename to rate? We have had issues knowing which direction the rate is hence the explicitness

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was suggested in the issue and I liked it. But I'll revert if it's controversial.

@@ -31,7 +31,9 @@ export class Close extends Message<'close'> {
}

const message = { metadata, data: opts.data }
return new Close(message)
const close = new Close(message)
await Message.validate(close)
Copy link
Contributor

Choose a reason for hiding this comment

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

Message.validate is not async so I don't think we need to await this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Decided to remove Message.validate entirely since it's requires signature to be present even though the message is not signed at this point.

@@ -31,7 +31,9 @@ export class Offering extends Resource<'offering'> {
}

const message = { metadata, data: opts.data }
return new Offering(message)
const offering = new Offering(message)
await Resource.validate(offering)
Copy link
Contributor

Choose a reason for hiding this comment

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

Resource.validate is not async

@@ -32,7 +33,9 @@ export class OrderStatus extends Message<'orderstatus'> {
}

const message = { metadata, data: opts.data }
return new OrderStatus(message)
const orderStatus = new OrderStatus(message)
await Message.validate(order)
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto not async

@@ -31,6 +31,8 @@ export class Order extends Message<'order'> {
}

const message = { metadata, data: {} }
return new Order(message)
const order = new Order(message)
await Message.validate(order)
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto not async

@@ -32,7 +32,9 @@ export class Quote extends Message<'quote'> {
}

const message = { metadata, data: opts.data }
return new Quote(message)
const quote = new Quote(message)
await Message.validate(quote)
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto not async

@@ -44,7 +44,9 @@ export class Rfq extends Message<'rfq'> {
// TODO: hash `data.payoutMethod.paymentDetails` and set `private`

const message = { metadata, data: opts.data }
return new Rfq(message)
const rfq = new Rfq(message)
await Message.validate(rfq)
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto not async

@diehuxx
Copy link
Contributor Author

diehuxx commented Jan 14, 2024

Closing this PR because I forgot about (woops) and then reimplemented this change but more thoroughly in #134.

@diehuxx diehuxx closed this Jan 14, 2024
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