Skip to content

Commit

Permalink
US-2050 Updated rifwallet to include an extra pendingTxsCount. Update…
Browse files Browse the repository at this point in the history
…d rif-relay-sdk to use pendingTxsCount to increase the nonce of the smartwallet. (#123)
  • Loading branch information
Freshenext authored Dec 15, 2023
1 parent 39fedc5 commit 48d4f9b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsksmart/rif-wallet-core",
"version": "1.0.4",
"version": "1.0.5",
"description": "RIF Wallet Core",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/RIFWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ export class RIFWallet extends Signer implements TypedDataSigner {
...transactionRequest,
gasPrice: overriddenOptions.gasPrice,
gasLimit: overriddenOptions.gasLimit,
}, overriddenOptions.tokenPayment)
}, overriddenOptions.tokenPayment,
overriddenOptions.pendingTxsCount
)
}

// direct execute transaction paying gas with EOA wallet:
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type OverriddableTransactionOptions = {
gasLimit: BigNumberish,
gasPrice: BigNumberish,
tokenPayment?: RelayPayment
pendingTxsCount?: number
}

export type SendTransactionRequest = IncomingRequest<
Expand Down
2 changes: 1 addition & 1 deletion packages/rif-relay-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@rsksmart/rif-relay-light-sdk",
"version": "1.0.16",
"version": "1.0.17",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
16 changes: 10 additions & 6 deletions packages/rif-relay-sdk/src/RifRelaySDK/RifRelaySDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ export class RIFRelaySDK {

private createRelayRequest = async (
tx: TransactionRequest,
payment: RelayPayment
payment: RelayPayment,
pendingTxsCount = 0
): Promise<RelayRequest> => {
const gasPrice = this.checkTransactionGasPrice(tx.gasPrice)
const nonce = await this.smartWallet.nonce()
Expand All @@ -127,6 +128,7 @@ export class RIFRelaySDK {
? estimated.sub(INTERNAL_TRANSACTION_ESTIMATE_CORRECTION)
: estimated
const internalCallCost = Math.round(correction.toNumber() * 1.01)
const updatedNonceWithPendingTxs = nonce.add(pendingTxsCount)

const relayRequest: RelayRequest = {
request: {
Expand All @@ -136,7 +138,7 @@ export class RIFRelaySDK {
data: tx.data?.toString() || '0x',
value: tx.value?.toString() || '0',
gas: internalCallCost.toString(),
nonce: nonce.toString(),
nonce: updatedNonceWithPendingTxs.toString(),
tokenContract: tokenContract.toLowerCase(),
tokenAmount: tokenAmount.toString(),
tokenGas: tokenGas.toString(),
Expand Down Expand Up @@ -180,13 +182,14 @@ export class RIFRelaySDK {

sendRelayTransaction = async (
tx: TransactionRequest,
payment: RelayPayment
payment: RelayPayment,
pendingTxsCount = 0
): Promise<TransactionResponse> => {
if (Object.is(this.serverConfig, null)) {
await this.getServerConfig()
}

const request = await this.createRelayRequest(tx, payment)
const request = await this.createRelayRequest(tx, payment, pendingTxsCount)
const signature = await this.signRelayRequest(request, false)

return this.sendRequestToRelay(request, signature).then((hash: string) =>
Expand Down Expand Up @@ -291,7 +294,8 @@ export class RIFRelaySDK {

estimateTransactionCost = async (
tx: TransactionRequest,
tokenContract: Address
tokenContract: Address,
pendingTxsCount = 0
): Promise<BigNumber> => {
if (Object.is(this.serverConfig, null)) {
await this.getServerConfig()
Expand All @@ -304,7 +308,7 @@ export class RIFRelaySDK {

let request
try {
const relayRequest = await this.createRelayRequest(tx, payment)
const relayRequest = await this.createRelayRequest(tx, payment, pendingTxsCount)
const signature = await this.signRelayRequest(relayRequest, false)
request = await this.prepareDataForServer(relayRequest, signature)
} catch (err) {
Expand Down

0 comments on commit 48d4f9b

Please sign in to comment.