-
Notifications
You must be signed in to change notification settings - Fork 23
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
feat: WM on Test wallet #1427
feat: WM on Test wallet #1427
Conversation
fix conflicts
…58-be-asset-scale-2-to-asset-scale-9
…ub.com/interledger/testnet into 1358-be-asset-scale-2-to-asset-scale-9
@@ -54,7 +54,7 @@ services: | |||
RATE_API_KEY: ${RATE_API_KEY} | |||
BASE_ASSET_SCALE: 2 | |||
MAX_ASSET_SCALE: 9 | |||
WM_THRESHOLD: 100000000 | |||
RAPYD_THRESHOLD: 10000000 # 0.01 |
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.
I modified this to 0.01
(which is the lowest non-zero amount representable in asset scale 2) instead of 0.1
. Any reason to change it back?
@@ -289,7 +289,7 @@ export class RapydClient implements IRapydClient { | |||
: ',' | |||
const [street, city, postCode] = args.user.address?.split(', ') ?? [] | |||
let address = [street, postCode].join(addressDelimiter) | |||
if (args.assetCode === 'EUR') address = address.replace(/[,\s]+/g, '') | |||
if (args.assetCode === 'USD') address = address.replace(/[,\s]+/g, '') |
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 sure why this hardcoded transformation happens here tbh, but why was the asset code change needed?
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.
Also interested in the answer here, we are creating default USD account for every new user in Rapyd, but don't know if that ihas anything to do with this. But why change EUR?
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.
When I first started working on this issue I couldn't create an EUR account in the onboarding and thought that it should be USD by default. This was a change that I introduced in one of the first commits. Since then, I realised that I was wrong about the onboarding but forgot to revert the changes. Now I switched back to EUR 👍
@@ -387,6 +345,7 @@ export class WalletAddressService implements IWalletAddressService { | |||
|
|||
if (transfer.status?.status !== 'SUCCESS') { | |||
if (type === 'OUTGOING') { | |||
//TODO this might not be needed |
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.
as in: debt being part of the walletAddress model might not be needed?
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.
Yes, but I'm not 100% sure we should delete it. It makes sense to have it in case transferring liquidity to Rapyd fails, but also there's no mechanism to handle debt so I assume we don't care if transferring fails since the amounts are very small?
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.
The point you are raising is valid. I think there should be a retry mechanism in place.
But I think the retry mechanism can be part of the current flow:
Transfer to rapyd fails -> the imbalance state remains the same, and the transfer should be picked up by the next iteration of the worker job and retried, since it should again be detected as imbalance.
This way, no additional mechanism requiring debt would be needed.
if ( | ||
!accountsResponse.success || | ||
!userResponse.success || | ||
!accountsResponse.result |
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.
At a quick glance, accountResponse.result
might end up being an empty list.
Taking the following js truthy behaviour into account:
This might not be the desired outcome of the condition^^
Double check if this can be the case, and if such, check for accountsResponse.result.length
to reach desired condition
account.id, | ||
ctx.req.headers.cookie | ||
) | ||
if (walletAddressesResponse.success && walletAddressesResponse.result) { |
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.
ditto above
…ub.com/interledger/testnet into 1358-be-asset-scale-2-to-asset-scale-9
if (!accountsResponse.result) { | ||
return { | ||
notFound: true | ||
const incomingOutgoingBalances: Record<string, number> = {} |
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.
How could we share incoming/outgoing balance state so that we don't calculate it in each page as we do here (also in send, index)? @Tymmmy @raducristianpopa
@@ -20,6 +20,20 @@ module.exports = { | |||
} | |||
}, | |||
|
|||
rafiki_backend: { |
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.
why is this added?
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.
I added this so that I can migrate assets to scale 9 in the assets
table which is in rafiki_backend
db. That requires a separate connection.
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.
add an env variable instead with the connection string
if (account) { | ||
await knex('walletAddresses') | ||
.where('id', walletAddress.id) | ||
.update({ assetCode: account.assetCode }) |
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.
why would asset code change?
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.
This happens because assetCode
was null
for every WA for some reason and that was causing keepBalancesSynced
to fail when checking that asset code exists for every WA. Until now, we only populated assetCode
column on WAs table for WM payment pointers. Therefore, I changed the asset code from null
to whatever asset code the account has when migrating to prevent issues.
We will cherry pick the useful code we need from this. |
Context
This PR introduces changes that will allow creation of asset scale 9 wallet addresses by default and all WM accounting logic is removed as there will be no difference between payment pointers.
Rapyd will only take into account asset scale 2 (this is unchanged) while we also keep track of an asset scale 9 "virtual" balance in our wallet's db. This virtual balance is separated into
incomingBalance
andoutgoingBalance
for each PP. Whenever scale 9 incoming or outgoing transfers add up to the lowest amount representable in scale 2 (i.e.0.01
), then Rapyd balance is updated. This is similar to the previous WM accounting logic, but it now applies to all transactions.Changes TLDR;
Important questions
incomingBalance
andoutgoingBalance
columns fromwalletAddresses
table and move them toaccounts
table?debt
column in theaccounts
table?