diff --git a/src/config/config.local.js b/src/config/config.local.js index 7c12e7883..8371066c9 100644 --- a/src/config/config.local.js +++ b/src/config/config.local.js @@ -17,8 +17,8 @@ const CONFIG = { // eslint-disable-line no-unused-vars ROOT_REDIRECT: 'https://wallet.nimiq-testnet.com', POLYGON_CHAIN_ID: 80001, - USDC_CONTRACT_ADDRESS: '0x0FA8781a83E46826621b3BC094Ea2A0212e71B23', - USDC_HTLC_CONTRACT_ADDRESS: '0x2EB7cd7791b947A25d629219ead941fCd8f364BF', + BRIDGED_USDC_CONTRACT_ADDRESS: '0x0FA8781a83E46826621b3BC094Ea2A0212e71B23', + BRIDGED_USDC_HTLC_CONTRACT_ADDRESS: '0x2EB7cd7791b947A25d629219ead941fCd8f364BF', NATIVE_USDC_CONTRACT_ADDRESS: '0x9999f7Fea5938fD3b1E26A12c3f2fb024e194f97', NATIVE_USDC_TRANSFER_CONTRACT_ADDRESS: '0x5D101A320547f8D640c44fDfe5d1f35224f00B8B', // v1 diff --git a/src/config/config.mainnet.js b/src/config/config.mainnet.js index a73a750a8..0ea16cc40 100644 --- a/src/config/config.mainnet.js +++ b/src/config/config.mainnet.js @@ -8,8 +8,8 @@ const CONFIG = { // eslint-disable-line no-unused-vars ROOT_REDIRECT: 'https://wallet.nimiq.com', POLYGON_CHAIN_ID: 137, - USDC_CONTRACT_ADDRESS: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174', - USDC_HTLC_CONTRACT_ADDRESS: '0xF615bD7EA00C4Cc7F39Faad0895dB5f40891359f', + BRIDGED_USDC_CONTRACT_ADDRESS: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174', + BRIDGED_USDC_HTLC_CONTRACT_ADDRESS: '0xF615bD7EA00C4Cc7F39Faad0895dB5f40891359f', NATIVE_USDC_CONTRACT_ADDRESS: '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359', NATIVE_USDC_TRANSFER_CONTRACT_ADDRESS: '0x3157d422cd1be13AC4a7cb00957ed717e648DFf2', // v1 diff --git a/src/config/config.testnet.js b/src/config/config.testnet.js index f83fe8b68..306ae17a1 100644 --- a/src/config/config.testnet.js +++ b/src/config/config.testnet.js @@ -8,8 +8,8 @@ const CONFIG = { // eslint-disable-line no-unused-vars ROOT_REDIRECT: 'https://wallet.nimiq-testnet.com', POLYGON_CHAIN_ID: 80001, - USDC_CONTRACT_ADDRESS: '0x0FA8781a83E46826621b3BC094Ea2A0212e71B23', - USDC_HTLC_CONTRACT_ADDRESS: '0x2EB7cd7791b947A25d629219ead941fCd8f364BF', + BRIDGED_USDC_CONTRACT_ADDRESS: '0x0FA8781a83E46826621b3BC094Ea2A0212e71B23', + BRIDGED_USDC_HTLC_CONTRACT_ADDRESS: '0x2EB7cd7791b947A25d629219ead941fCd8f364BF', NATIVE_USDC_CONTRACT_ADDRESS: '0x9999f7Fea5938fD3b1E26A12c3f2fb024e194f97', NATIVE_USDC_TRANSFER_CONTRACT_ADDRESS: '0x5D101A320547f8D640c44fDfe5d1f35224f00B8B', // v1 diff --git a/src/lib/polygon/PolygonContractABIs.full.js.txt b/src/lib/polygon/PolygonContractABIs.full.js.txt index 73c2ef07b..275215d27 100644 --- a/src/lib/polygon/PolygonContractABIs.full.js.txt +++ b/src/lib/polygon/PolygonContractABIs.full.js.txt @@ -1,6 +1,6 @@ /* eslint-disable max-len */ const PolygonContractABIsFull = { // eslint-disable-line no-unused-vars - USDC_CONTRACT_ABI: [ + BRIDGED_USDC_CONTRACT_ABI: [ 'event Approval(address indexed owner, address indexed spender, uint256 value)', 'event AuthorizationCanceled(address indexed authorizer, bytes32 indexed nonce)', 'event AuthorizationUsed(address indexed authorizer, bytes32 indexed nonce)', @@ -74,7 +74,7 @@ const PolygonContractABIsFull = { // eslint-disable-line no-unused-vars 'function withdrawWithAuthorization(address owner, uint256 value, uint256 validAfter, uint256 validBefore, bytes32 nonce, uint8 v, bytes32 r, bytes32 s)', ], - USDC_HTLC_CONTRACT_ABI: [ + BRIDGED_USDC_HTLC_CONTRACT_ABI: [ 'constructor()', 'event DomainRegistered(bytes32 indexed domainSeparator, bytes domainValue)', 'event Open(bytes32 indexed id, address token, uint256 amount, address recipient, bytes32 hash, uint256 timeout)', diff --git a/src/lib/polygon/PolygonContractABIs.js b/src/lib/polygon/PolygonContractABIs.js index 3c5e869dd..767c59967 100644 --- a/src/lib/polygon/PolygonContractABIs.js +++ b/src/lib/polygon/PolygonContractABIs.js @@ -1,10 +1,10 @@ /* eslint-disable max-len */ const PolygonContractABIs = { // eslint-disable-line no-unused-vars - USDC_CONTRACT_ABI: [ + BRIDGED_USDC_CONTRACT_ABI: [ 'function approve(address spender, uint256 amount) returns (bool)', ], - USDC_HTLC_CONTRACT_ABI: [ + BRIDGED_USDC_HTLC_CONTRACT_ABI: [ 'function open(bytes32 id, address token, uint256 amount, address refundAddress, address recipientAddress, bytes32 hash, uint256 timeout, uint256 fee)', 'function openWithApproval(bytes32 id, address token, uint256 amount, address refundAddress, address recipientAddress, bytes32 hash, uint256 timeout, uint256 fee, uint256 approval, bytes32 sigR, bytes32 sigS, uint8 sigV)', 'function redeem(bytes32 id, address target, bytes32 secret, uint256 fee)', diff --git a/src/lib/polygon/PolygonKey.js b/src/lib/polygon/PolygonKey.js index 3ea2c81f7..9f0e6efed 100644 --- a/src/lib/polygon/PolygonKey.js +++ b/src/lib/polygon/PolygonKey.js @@ -65,7 +65,7 @@ class PolygonKey { // eslint-disable-line no-unused-vars const domain = { name: 'USD Coin (PoS)', // This is currently the same for testnet and mainnet version: '1', // This is currently the same for testnet and mainnet - verifyingContract: CONFIG.USDC_CONTRACT_ADDRESS, + verifyingContract: CONFIG.BRIDGED_USDC_CONTRACT_ADDRESS, salt: ethers.utils.hexZeroPad(ethers.utils.hexlify(CONFIG.POLYGON_CHAIN_ID), 32), }; diff --git a/src/request/sign-polygon-transaction/SignPolygonTransaction.js b/src/request/sign-polygon-transaction/SignPolygonTransaction.js index 44515c5f9..2e1aeb567 100644 --- a/src/request/sign-polygon-transaction/SignPolygonTransaction.js +++ b/src/request/sign-polygon-transaction/SignPolygonTransaction.js @@ -164,8 +164,8 @@ class SignPolygonTransaction { const { sigR, sigS, sigV } = await polygonKey.signUsdcApproval( request.keyPath, new ethers.Contract( - CONFIG.USDC_CONTRACT_ADDRESS, - PolygonContractABIs.USDC_CONTRACT_ABI, + CONFIG.BRIDGED_USDC_CONTRACT_ADDRESS, + PolygonContractABIs.BRIDGED_USDC_CONTRACT_ABI, ), transferContract, request.description.args.approval, diff --git a/src/request/sign-polygon-transaction/SignPolygonTransactionApi.js b/src/request/sign-polygon-transaction/SignPolygonTransactionApi.js index 22b8f0be2..ff6669726 100644 --- a/src/request/sign-polygon-transaction/SignPolygonTransactionApi.js +++ b/src/request/sign-polygon-transaction/SignPolygonTransactionApi.js @@ -95,10 +95,10 @@ class SignPolygonTransactionApi extends PolygonRequestParserMixin(TopLevelApi) { if (!['transfer', 'transferWithPermit'].includes(description.name)) { throw new Errors.InvalidRequestError('Requested Polygon contract method is invalid'); } - } else if (forwardRequest.to === CONFIG.USDC_HTLC_CONTRACT_ADDRESS) { + } else if (forwardRequest.to === CONFIG.BRIDGED_USDC_HTLC_CONTRACT_ADDRESS) { const usdcHtlcContract = new ethers.Contract( - CONFIG.USDC_HTLC_CONTRACT_ADDRESS, - PolygonContractABIs.USDC_HTLC_CONTRACT_ABI, + CONFIG.BRIDGED_USDC_HTLC_CONTRACT_ADDRESS, + PolygonContractABIs.BRIDGED_USDC_HTLC_CONTRACT_ABI, ); /** @type {PolygonRefundDescription} */ @@ -122,7 +122,7 @@ class SignPolygonTransactionApi extends PolygonRequestParserMixin(TopLevelApi) { value: forwardRequest.value, })); - if (description.args.token !== CONFIG.USDC_CONTRACT_ADDRESS) { + if (description.args.token !== CONFIG.BRIDGED_USDC_CONTRACT_ADDRESS) { throw new Errors.InvalidRequestError('Invalid USDC token contract in request data'); } diff --git a/src/request/sign-swap/SignSwap.js b/src/request/sign-swap/SignSwap.js index a180f7826..4047c7c3b 100644 --- a/src/request/sign-swap/SignSwap.js +++ b/src/request/sign-swap/SignSwap.js @@ -549,10 +549,10 @@ class SignSwap { const { sigR, sigS, sigV } = await polygonKey.signUsdcApproval( request.fund.keyPath, new ethers.Contract( - CONFIG.USDC_CONTRACT_ADDRESS, - PolygonContractABIs.USDC_CONTRACT_ABI, + CONFIG.BRIDGED_USDC_CONTRACT_ADDRESS, + PolygonContractABIs.BRIDGED_USDC_CONTRACT_ABI, ), - CONFIG.USDC_HTLC_CONTRACT_ADDRESS, + CONFIG.BRIDGED_USDC_HTLC_CONTRACT_ADDRESS, request.fund.description.args.approval, // Has been validated to be defined when function called is `openWithApproval` /** @type {{ tokenNonce: number }} */ (request.fund.approval).tokenNonce, @@ -560,8 +560,8 @@ class SignSwap { ); const htlcContract = new ethers.Contract( - CONFIG.USDC_HTLC_CONTRACT_ADDRESS, - PolygonContractABIs.USDC_HTLC_CONTRACT_ABI, + CONFIG.BRIDGED_USDC_HTLC_CONTRACT_ADDRESS, + PolygonContractABIs.BRIDGED_USDC_HTLC_CONTRACT_ABI, ); request.fund.request.data = htlcContract.interface.encodeFunctionData(request.fund.description.name, [ diff --git a/src/request/sign-swap/SignSwapApi.js b/src/request/sign-swap/SignSwapApi.js index 6b593ab40..3baa8329e 100644 --- a/src/request/sign-swap/SignSwapApi.js +++ b/src/request/sign-swap/SignSwapApi.js @@ -320,13 +320,13 @@ class SignSwapApi extends PolygonRequestParserMixin(BitcoinRequestParserMixin(To parseOpenGsnForwardRequest(request, allowedMethods) { const forwardRequest = this.parseOpenGsnForwardRequestRoot(request.request); - if (forwardRequest.to !== CONFIG.USDC_HTLC_CONTRACT_ADDRESS) { + if (forwardRequest.to !== CONFIG.BRIDGED_USDC_HTLC_CONTRACT_ADDRESS) { throw new Errors.InvalidRequestError('request.to address is not allowed'); } const usdcHtlcContract = new ethers.Contract( - CONFIG.USDC_HTLC_CONTRACT_ADDRESS, - PolygonContractABIs.USDC_HTLC_CONTRACT_ABI, + CONFIG.BRIDGED_USDC_HTLC_CONTRACT_ADDRESS, + PolygonContractABIs.BRIDGED_USDC_HTLC_CONTRACT_ABI, ); // eslint-disable-next-line operator-linebreak @@ -345,7 +345,7 @@ class SignSwapApi extends PolygonRequestParserMixin(BitcoinRequestParserMixin(To } if (description.name === 'open' || description.name === 'openWithApproval') { - if (description.args.token !== CONFIG.USDC_CONTRACT_ADDRESS) { + if (description.args.token !== CONFIG.BRIDGED_USDC_CONTRACT_ADDRESS) { throw new Errors.InvalidRequestError('Invalid USDC token contract in request data'); } diff --git a/src/request/swap-iframe/SwapIFrameApi.js b/src/request/swap-iframe/SwapIFrameApi.js index f55d48789..5f02cc55d 100644 --- a/src/request/swap-iframe/SwapIFrameApi.js +++ b/src/request/swap-iframe/SwapIFrameApi.js @@ -87,8 +87,8 @@ class SwapIFrameApi extends BitcoinRequestParserMixin(RequestParser) { // eslint } if (storedRawRequest.fund.type === 'USDC') { const usdcHtlcContract = new ethers.Contract( - CONFIG.USDC_HTLC_CONTRACT_ADDRESS, - PolygonContractABIs.USDC_HTLC_CONTRACT_ABI, + CONFIG.BRIDGED_USDC_HTLC_CONTRACT_ADDRESS, + PolygonContractABIs.BRIDGED_USDC_HTLC_CONTRACT_ABI, ); storedRawRequest.fund.description = usdcHtlcContract.interface.parseTransaction({ @@ -102,8 +102,8 @@ class SwapIFrameApi extends BitcoinRequestParserMixin(RequestParser) { // eslint } if (storedRawRequest.redeem.type === 'USDC') { const usdcHtlcContract = new ethers.Contract( - CONFIG.USDC_HTLC_CONTRACT_ADDRESS, - PolygonContractABIs.USDC_HTLC_CONTRACT_ABI, + CONFIG.BRIDGED_USDC_HTLC_CONTRACT_ADDRESS, + PolygonContractABIs.BRIDGED_USDC_HTLC_CONTRACT_ABI, ); storedRawRequest.redeem.description = usdcHtlcContract.interface.parseTransaction({ @@ -226,8 +226,8 @@ class SwapIFrameApi extends BitcoinRequestParserMixin(RequestParser) { // eslint if (request.fund.type === 'USDC' && storedRequest.fund.type === 'USDC') { const usdcHtlcContract = new ethers.Contract( - CONFIG.USDC_HTLC_CONTRACT_ADDRESS, - PolygonContractABIs.USDC_HTLC_CONTRACT_ABI, + CONFIG.BRIDGED_USDC_HTLC_CONTRACT_ADDRESS, + PolygonContractABIs.BRIDGED_USDC_HTLC_CONTRACT_ABI, ); const description = /** @type {PolygonOpenDescription} */ (usdcHtlcContract.interface.parseTransaction({ @@ -243,7 +243,7 @@ class SwapIFrameApi extends BitcoinRequestParserMixin(RequestParser) { // eslint } // Verify already known parts of the data - if (description.args.token !== CONFIG.USDC_CONTRACT_ADDRESS) { + if (description.args.token !== CONFIG.BRIDGED_USDC_CONTRACT_ADDRESS) { throw new Errors.InvalidRequestError('Invalid USDC token contract in HTLC data'); } @@ -546,8 +546,8 @@ class SwapIFrameApi extends BitcoinRequestParserMixin(RequestParser) { // eslint if (parsedRequest.fund.type === 'USDC' && storedRequest.fund.type === 'USDC') { const usdcHtlcContract = new ethers.Contract( - CONFIG.USDC_HTLC_CONTRACT_ADDRESS, - PolygonContractABIs.USDC_HTLC_CONTRACT_ABI, + CONFIG.BRIDGED_USDC_HTLC_CONTRACT_ADDRESS, + PolygonContractABIs.BRIDGED_USDC_HTLC_CONTRACT_ABI, ); // Place contract details into existing function call data @@ -572,10 +572,14 @@ class SwapIFrameApi extends BitcoinRequestParserMixin(RequestParser) { // eslint ], ); - const typedData = new OpenGSN.TypedRequestData(CONFIG.POLYGON_CHAIN_ID, CONFIG.USDC_HTLC_CONTRACT_ADDRESS, { - request: storedRequest.fund.request, - relayData: storedRequest.fund.relayData, - }); + const typedData = new OpenGSN.TypedRequestData( + CONFIG.POLYGON_CHAIN_ID, + CONFIG.BRIDGED_USDC_HTLC_CONTRACT_ADDRESS, + { + request: storedRequest.fund.request, + relayData: storedRequest.fund.relayData, + }, + ); const { EIP712Domain, ...cleanedTypes } = typedData.types; @@ -695,8 +699,8 @@ class SwapIFrameApi extends BitcoinRequestParserMixin(RequestParser) { // eslint if (parsedRequest.redeem.type === 'USDC' && storedRequest.redeem.type === 'USDC') { const usdcHtlcContract = new ethers.Contract( - CONFIG.USDC_HTLC_CONTRACT_ADDRESS, - PolygonContractABIs.USDC_HTLC_CONTRACT_ABI, + CONFIG.BRIDGED_USDC_HTLC_CONTRACT_ADDRESS, + PolygonContractABIs.BRIDGED_USDC_HTLC_CONTRACT_ABI, ); // Place contract details into existing function call data @@ -712,10 +716,14 @@ class SwapIFrameApi extends BitcoinRequestParserMixin(RequestParser) { // eslint ], ); - const typedData = new OpenGSN.TypedRequestData(CONFIG.POLYGON_CHAIN_ID, CONFIG.USDC_HTLC_CONTRACT_ADDRESS, { - request: storedRequest.redeem.request, - relayData: storedRequest.redeem.relayData, - }); + const typedData = new OpenGSN.TypedRequestData( + CONFIG.POLYGON_CHAIN_ID, + CONFIG.BRIDGED_USDC_HTLC_CONTRACT_ADDRESS, + { + request: storedRequest.redeem.request, + relayData: storedRequest.redeem.relayData, + }, + ); const { EIP712Domain, ...cleanedTypes } = typedData.types;