Skip to content

Commit f063864

Browse files
authored
fix: NEAR Conversion version and processor (#935)
1 parent cd4f55d commit f063864

File tree

6 files changed

+22
-16
lines changed

6 files changed

+22
-16
lines changed

packages/advanced-logic/src/extensions/payment-network/any-to-near.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ExtensionTypes, IdentityTypes, RequestLogicTypes } from '@requestnetwor
33
import { UnsupportedNetworkError } from './address-based';
44
import AnyToNativeTokenPaymentNetwork from './any-to-native';
55

6-
const CURRENT_VERSION = '0.2.0';
6+
const CURRENT_VERSION = '0.1.0';
77
const supportedNetworks = ['aurora', 'aurora-testnet'];
88

99
export default class AnyToNearPaymentNetwork extends AnyToNativeTokenPaymentNetwork {

packages/advanced-logic/test/utils/payment-network/any/generator-data-create.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export const actionCreationWithNativeTokenPayment: ExtensionTypes.IAction<Extens
9393
refundAddress: 'refund.near',
9494
salt: arbitrarySalt,
9595
},
96-
version: '0.2.0',
96+
version: '0.1.0',
9797
};
9898
export const actionCreationWithAnyToNativeTokenPayment: ExtensionTypes.IAction<ExtensionTypes.PnAnyToAnyConversion.ICreationParameters> =
9999
{
@@ -108,7 +108,7 @@ export const actionCreationWithAnyToNativeTokenPayment: ExtensionTypes.IAction<E
108108
network: 'aurora',
109109
maxRateTimespan: 1000000,
110110
},
111-
version: '0.2.0',
111+
version: '0.1.0',
112112
};
113113

114114
export const actionAddDelegate = {
@@ -239,7 +239,7 @@ export const extensionStateWithNativeTokenPaymentAndRefund: RequestLogicTypes.IE
239239
sentPaymentAmount: '0',
240240
sentRefundAmount: '0',
241241
},
242-
version: '0.2.0',
242+
version: '0.1.0',
243243
},
244244
};
245245
export const extensionStateWithAnyToNativeTokenPaymentAndRefund: RequestLogicTypes.IExtensionStates =
@@ -279,7 +279,7 @@ export const extensionStateWithAnyToNativeTokenPaymentAndRefund: RequestLogicTyp
279279
maxRateTimespan: 1000000,
280280
feeAmount: '100',
281281
},
282-
version: '0.2.0',
282+
version: '0.1.0',
283283
},
284284
};
285285
export const extensionStateAnyToNativeWithPaymentAddressAdded: RequestLogicTypes.IExtensionStates =
@@ -325,7 +325,7 @@ export const extensionStateAnyToNativeWithPaymentAddressAdded: RequestLogicTypes
325325
maxRateTimespan: 1000000,
326326
feeAmount: '100',
327327
},
328-
version: '0.2.0',
328+
version: '0.1.0',
329329
},
330330
};
331331

@@ -371,7 +371,7 @@ export const extensionStateAnyToNativeWithFeeAdded: RequestLogicTypes.IExtension
371371
maxRateTimespan: 1000000,
372372
feeAmount: '100',
373373
},
374-
version: '0.2.0',
374+
version: '0.1.0',
375375
},
376376
};
377377

packages/payment-processor/src/payment/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { encodeRequestPayment } from './encoder-payment';
2222
import { IPreparedTransaction } from './prepared-transaction';
2323
import { IRequestPaymentOptions } from './settings';
2424

25-
export const supportedNetworks = [
25+
export const noConversionNetworks = [
2626
ExtensionTypes.ID.PAYMENT_NETWORK_ERC777_STREAM,
2727
ExtensionTypes.ID.PAYMENT_NETWORK_ERC20_PROXY_CONTRACT,
2828
ExtensionTypes.ID.PAYMENT_NETWORK_ERC20_FEE_PROXY_CONTRACT,
@@ -177,7 +177,7 @@ export async function swapToPayRequest(
177177

178178
/**
179179
* Verifies the address has enough funds to pay the request in its currency.
180-
* Supported networks: ERC20_PROXY_CONTRACT, ETH_INPUT_DATA
180+
* Only supports networks with no (on-chain) conversion.
181181
*
182182
* @throws UnsupportedNetworkError if network isn't supported
183183
* @param request the request to verify.
@@ -194,7 +194,7 @@ export async function hasSufficientFunds(
194194
},
195195
): Promise<boolean> {
196196
const paymentNetwork = getPaymentNetwork(request);
197-
if (!paymentNetwork || !supportedNetworks.includes(paymentNetwork)) {
197+
if (!paymentNetwork || !noConversionNetworks.includes(paymentNetwork)) {
198198
throw new UnsupportedNetworkError(paymentNetwork);
199199
}
200200

@@ -216,6 +216,7 @@ export async function hasSufficientFunds(
216216

217217
/**
218218
* Verifies the address has enough funds to pay an amount in a given currency.
219+
* Supported chains: EVMs and Near.
219220
*
220221
* @param fromAddress the address willing to pay
221222
* @param amount

packages/payment-processor/src/payment/near-conversion.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export async function payNearConversionRequest(
4141
}
4242

4343
if (!network || !isNearNetwork(network)) {
44-
throw new Error('Should be a near network');
44+
throw new Error('Should be a Near network');
4545
}
4646

4747
const amountToPay = getAmountToPay(request, amount).toString();
@@ -56,6 +56,7 @@ export async function payNearConversionRequest(
5656
getTicker(request.currencyInfo),
5757
feeAddress || '0x',
5858
feeAmount || 0,
59+
paymentSettings.maxToSpend,
5960
maxRateTimespan || '0',
6061
version,
6162
);

packages/payment-processor/src/payment/utils-near.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export const isNearAccountSolvent = (
3434

3535
const GAS_LIMIT_IN_TGAS = 50;
3636
const GAS_LIMIT = ethers.utils.parseUnits(GAS_LIMIT_IN_TGAS.toString(), 12);
37+
const GAS_LIMIT_NATIVE = GAS_LIMIT.toString();
38+
const GAS_LIMIT_CONVERSION_TO_NATIVE = GAS_LIMIT.mul(2).toString();
3739

3840
export const processNearPayment = async (
3941
walletConnection: WalletConnection,
@@ -69,7 +71,7 @@ export const processNearPayment = async (
6971
to,
7072
payment_reference: paymentReference,
7173
},
72-
GAS_LIMIT.toString(),
74+
GAS_LIMIT_NATIVE,
7375
amount.toString(),
7476
);
7577
return;
@@ -94,6 +96,7 @@ export const processNearPaymentWithConversion = async (
9496
currency: string,
9597
feeAddress: string,
9698
feeAmount: BigNumberish,
99+
maxToSpend: BigNumberish,
97100
maxRateTimespan = '0',
98101
version = '0.1.0',
99102
): Promise<void> => {
@@ -127,8 +130,8 @@ export const processNearPaymentWithConversion = async (
127130
fee_amount: feeAmount,
128131
max_rate_timespan: maxRateTimespan,
129132
},
130-
GAS_LIMIT.toString(),
131-
amount.toString(),
133+
GAS_LIMIT_CONVERSION_TO_NATIVE,
134+
maxToSpend.toString(),
132135
);
133136
return;
134137
} catch (e) {

packages/payment-processor/test/payment/any-to-near.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ const request: any = {
4141
};
4242

4343
// Use the default currency manager
44-
const conversionSettings = {} as unknown as IConversionPaymentSettings;
44+
const conversionSettings: IConversionPaymentSettings = { maxToSpend: '30' };
4545

4646
describe('payNearWithConversionRequest', () => {
4747
afterEach(() => {
@@ -75,6 +75,7 @@ describe('payNearWithConversionRequest', () => {
7575
'USD',
7676
feeAddress,
7777
feeAmount,
78+
conversionSettings.maxToSpend,
7879
'0',
7980
'0.1.0',
8081
);
@@ -159,7 +160,7 @@ describe('payNearWithConversionRequest', () => {
159160

160161
await expect(
161162
payNearConversionRequest(invalidRequest, mockedNearWalletConnection, conversionSettings),
162-
).rejects.toThrowError('Should be a near network');
163+
).rejects.toThrowError('Should be a Near network');
163164
expect(paymentSpy).toHaveBeenCalledTimes(0);
164165
});
165166
});

0 commit comments

Comments
 (0)