-
Notifications
You must be signed in to change notification settings - Fork 88
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
chore(backend): allow asset scale 2 to asset scale 9 payments #2748
Conversation
…inator fields in the quotes table
✅ Deploy Preview for brilliant-pasca-3e80ec canceled.
|
if (receipt.error) { | ||
throw receipt.error | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this check before the debug logger, so we don't continue to log "'ILP payment completed'" when there is an error
client: options.client, | ||
feeId: sendingFee?.id, | ||
estimatedExchangeRate: quote.estimatedExchangeRate, | ||
additionalFields: quote.additionalFields |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't store additionalFields
anymore
@@ -245,20 +246,6 @@ async function pay( | |||
} | |||
} | |||
|
|||
function fromJSONtoRatio(ratio: unknown): Pay.Ratio { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed anymore, we don't use additionalFields
quote field to get these ratio amounts
if (receiveAmountValue <= exchangeAdjustedFees) { | ||
throw QuoteError.NegativeReceiveAmount | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Behaviour change:
We used to throw if the receiveAmount was less than the fees: e.g. if receiveAmountValue = 100, and exchangeAdjustedFees were 60, we would throw, even though receiveAmountValue of 40 seems like it should be possible to do. (In other words, more than 50% of the transfer in this situation goes to fees, which wouldn't be nice for the user, but not necessarily a problem/bug)
We discussed this in a slack thread.
table.string('highEstimatedExchangeRateNumerator').alter() | ||
table.string('highEstimatedExchangeRateDenominator').alter() | ||
|
||
table.dropColumn('additionalFields') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Originally, additionalFields
was a temp solution when building out support for multiple payment methods. Now I decided to get rid of this extra field, since we will not be building that out.
table.decimal('minExchangeRateNumerator', 64, 0).alter() | ||
table.decimal('minExchangeRateDenominator', 64, 0).alter() | ||
table.decimal('lowEstimatedExchangeRateNumerator', 64, 0).alter() | ||
table.decimal('lowEstimatedExchangeRateDenominator', 64, 0).alter() | ||
table.decimal('highEstimatedExchangeRateNumerator', 64, 0).alter() | ||
table.decimal('highEstimatedExchangeRateDenominator', 64, 0).alter() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needed something bigger than 20, (I don't think we will ever need more than 20 ever), but just being generous so we don't run into this issue again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable. Inspecting the db shows these are stored as numeric
types (same as decimal) in postgres. Found this in the docs about how much storage this would take:
Numeric values are physically stored without any extra leading or trailing zeroes. Thus, the declared precision and scale of a column are maximums, not fixed allocations. (In this sense the numeric type is more akin to varchar(n) than to char(n).) The actual storage requirement is two bytes for each group of four decimal digits, plus three to eight bytes overhead.
https://www.postgresql.org/docs/current/datatype-numeric.html
So it varies on actual size of the data, not just this declaration. So I don't really see a downside of leaving lots of extra headroom.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were you able to test this migration against any existing data? Since we're going from lower to higher precision I imagine it probably works fine but figure it's worth testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BlairCurrey I just made some transactions on main
then rebuilt the backend and continued making transactions without issue
if (!maxReceiveAmountValue) { | ||
// FixedDelivery | ||
const fees = quote.fee?.calculate(debitAmountValue) ?? 0n | ||
debitAmountValue = BigInt(debitAmountValue) + fees | ||
if ( | ||
debitAmountValue < quote.debitAmount.value || | ||
debitAmountValue <= BigInt(0) | ||
) { | ||
throw QuoteError.InvalidAmount | ||
} | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
split these up into functions, logic remains the same other than the comment below
@@ -681,41 +697,5 @@ describe('IlpPaymentService', (): void => { | |||
expect((error as PaymentMethodHandlerError).retryable).toBe(false) | |||
} | |||
}) | |||
|
|||
test('throws if invalid quote data', async (): Promise<void> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't use additionalFields
so parsing JSON is not required, so this test is not necessary
@@ -272,6 +284,7 @@ describe('IlpPaymentService', (): void => { | |||
minDeliveryAmount: -1n | |||
} as Pay.Quote) | |||
|
|||
expect.assertions(4) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to make sure exceptions in catch are tracked
Changes proposed in this pull request
Context
Fixes #2747
Checklist
fixes #number