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
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: 4 additions & 4 deletions packages/http-server/src/fakes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MessageKindClass, Offering, Rfq, Quote, Order, OrderStatus, Close } from '@tbdex/protocol'
import { OfferingsApi, ExchangesApi } from './main.js'

const offering = Offering.create({
const offering = await Offering.create({
metadata : { from: 'did:ex:pfi' },
data : {
description : 'Selling BTC for USD',
Expand All @@ -10,10 +10,10 @@ const offering = Offering.create({
},
payoutCurrency: {
currencyCode : 'BTC',
maxSubunits : '99952611'
maxAmount : '999526.11'
},
payoutUnitsPerPayinUnit : '0.000038',
payinMethods : [{
payoutUnitsPerPayinUnit : '0.000038',
payinMethods : [{
kind : 'DEBIT_CARD',
requiredPaymentDetails : {
$schema : 'http://json-schema.org/draft-07/schema',
Expand Down
4 changes: 2 additions & 2 deletions packages/protocol/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ const rfq = Rfq.create({
btcAddress: '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa'
}
},
quoteAmountSubunits : '20000',
vcs : ''
amount : '200.00',
vcs : ''
}
})

Expand Down
8 changes: 4 additions & 4 deletions packages/protocol/src/dev-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ export class DevTools {
/**
* creates and returns an example offering. Useful for testing purposes
*/
static createOffering() {
static createOffering(): Offering {
const offeringData: OfferingData = {
description : 'Selling BTC for USD',
payinCurrency : {
currencyCode: 'USD'
},
payoutCurrency: {
currencyCode : 'BTC',
maxSubunits : '99952611'
maxAmount : '999526.11'
},
payoutUnitsPerPayinUnit : '0.00003826',
payinMethods : [{
Expand Down Expand Up @@ -202,8 +202,8 @@ export class DevTools {
btcAddress: '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa'
}
},
payinSubunits : '20000',
claims : [signedCredential]
payinAmount : '200.00',
claims : [signedCredential]
}

return Rfq.create({
Expand Down
4 changes: 3 additions & 1 deletion packages/protocol/src/message-kinds/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export class Order extends Message<'order'> {
}

const message = { metadata, data: {} }
return new Order(message)
const order = new Order(message)
Message.validate(order)
return order
}
}
6 changes: 3 additions & 3 deletions packages/protocol/src/message-kinds/rfq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class Rfq extends Message<'rfq'> {
throw new Error(`offering id mismatch. (rfq) ${this.offeringId} !== ${offering.metadata.id} (offering)`)
}

// TODO: validate rfq's quoteAmountSubunits against offering's quoteCurrency min/max
// TODO: validate rfq's payinAmount against offering's quoteCurrency min/max

// TODO: validate rfq's payinMethod.kind against offering's payinMethods
// TODO: validate rfq's payinMethod.paymentDetails against offering's respective requiredPaymentDetails json schema
Expand Down Expand Up @@ -91,8 +91,8 @@ export class Rfq extends Message<'rfq'> {
}

/** Amount of payin currency you want to spend in order to receive payout currency */
get payinSubunits() {
return this.data.payinSubunits
get payinAmount() {
return this.data.payinAmount
}

/** Array of claims that satisfy the respective offering's requiredClaims */
Expand Down
10 changes: 5 additions & 5 deletions packages/protocol/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ export type CurrencyDetails = {
/** ISO 3166 currency code string */
currencyCode: string
/** Minimum amount of currency that can be requested */
minSubunits?: string
minAmount?: string
/** Maximum amount of currency that can be requested */
maxSubunits?: string
maxAmount?: string
}

/**
Expand Down Expand Up @@ -182,7 +182,7 @@ export type RfqData = {
/** Offering which Alice would like to get a quote for */
offeringId: string
/** Amount of _payin_ currency alice wants to spend in order to receive payout currency */
payinSubunits: string
payinAmount: string
/** Selected payment method that Alice will use to send the listed payin currency to the PFI. */
payinMethod: SelectedPaymentMethod
/** Selected payment method that the PFI will use to send the listed base currency to Alice */
Expand Down Expand Up @@ -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')*/

amountSubunits: string
amount: string
/** the amount paid in fees */
feeSubunits?: string
fee?: string
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/tests/offering.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const offeringData: OfferingData = {
},
payoutCurrency: {
currencyCode : 'BTC',
maxSubunits : '99952611'
maxAmount : '999526.11'
},
payoutUnitsPerPayinUnit : '0.00003826',
payinMethods : [{
Expand Down
14 changes: 7 additions & 7 deletions packages/protocol/tests/rfq.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const rfqData: RfqData = {
btcAddress: '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa'
}
},
payinSubunits : '20000',
claims : ['']
payinAmount : '200.00',
claims : ['']
}

describe('Rfq', () => {
Expand Down Expand Up @@ -161,7 +161,7 @@ describe('Rfq', () => {
describe('verifyClaims', () => {
it(`does not throw an exception if an rfq's claims fulfill the provided offering's requirements`, async () => {
const did = await DevTools.createDid()
const offering = DevTools.createOffering()
const offering = await DevTools.createOffering()
const { signedCredential } = await DevTools.createCredential({ // this credential fulfills the offering's required claims
type : 'SanctionsCredential',
issuer : did,
Expand Down Expand Up @@ -190,8 +190,8 @@ describe('Rfq', () => {
btcAddress: '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa'
}
},
payinSubunits : '20000',
claims : [signedCredential]
payinAmount : '200.00',
claims : [signedCredential]
}
})

Expand Down Expand Up @@ -229,8 +229,8 @@ describe('Rfq', () => {
btcAddress: '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa'
}
},
payinSubunits : '20000',
claims : [signedCredential]
payinAmount : '200.00',
claims : [signedCredential]
}
})

Expand Down