Skip to content
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

Allow swapping bridged USDC.e to native USDC via new OpenGSN-enabled swap contract #488

Merged
merged 6 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/src/PublicRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export type PolygonTransactionInfo = {

/**
* The sender's nonce in the token contract, required when calling the
* contract function `transferWithApproval` for bridged USDC.e.
* contract function `swapWithApproval` for bridged USDC.e.
*/
approval?: {
tokenNonce: number,
Expand Down
5 changes: 5 additions & 0 deletions src/assets/icons/usdc_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/components/PolygonAddressInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class PolygonAddressInfo { // eslint-disable-line no-unused-vars
/**
* @param {string} address
* @param {string} [label]
* @param {'none' | 'usdc' | 'unknown'} [logo = 'none']
* @param {'none' | 'usdc' | 'usdc_dark' | 'unknown'} [logo = 'none']
*/
constructor(address, label, logo = 'none') {
this._address = address;
Expand Down Expand Up @@ -37,7 +37,7 @@ class PolygonAddressInfo { // eslint-disable-line no-unused-vars
$avatar.classList.add('unlabelled');
}
$el.appendChild($avatar);
} else if (this._logo === 'usdc' || this._logo === 'unknown') {
} else if (this._logo === 'usdc' || this._logo === 'usdc_dark' || this._logo === 'unknown') {
const $img = document.createElement('img');
$img.classList.add('logo');
$img.src = `../../assets/icons/${this._logo}.svg`;
Expand Down
7 changes: 4 additions & 3 deletions src/config/config.local.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ const CONFIG = { // eslint-disable-line no-unused-vars
ROOT_REDIRECT: 'https://wallet.nimiq-testnet.com',

POLYGON_CHAIN_ID: 80001,
USDC_CONTRACT_ADDRESS: '0x0FA8781a83E46826621b3BC094Ea2A0212e71B23',
USDC_TRANSFER_CONTRACT_ADDRESS: '0x2805f3187dcDfa424EFA8c55Db6012Cf08Fa6eEc', // v3
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

USDC_SWAP_CONTRACT_ADDRESS: '0x72e64Cff5cfFD4BFbC5b8d4fB081B33B9EE3e30e',
};
7 changes: 4 additions & 3 deletions src/config/config.mainnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ const CONFIG = { // eslint-disable-line no-unused-vars
ROOT_REDIRECT: 'https://wallet.nimiq.com',

POLYGON_CHAIN_ID: 137,
USDC_CONTRACT_ADDRESS: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174',
USDC_TRANSFER_CONTRACT_ADDRESS: '0x98E69a6927747339d5E543586FC0262112eBe4BD',
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

USDC_SWAP_CONTRACT_ADDRESS: '',
};
7 changes: 4 additions & 3 deletions src/config/config.testnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ const CONFIG = { // eslint-disable-line no-unused-vars
ROOT_REDIRECT: 'https://wallet.nimiq-testnet.com',

POLYGON_CHAIN_ID: 80001,
USDC_CONTRACT_ADDRESS: '0x0FA8781a83E46826621b3BC094Ea2A0212e71B23',
USDC_TRANSFER_CONTRACT_ADDRESS: '0x2805f3187dcDfa424EFA8c55Db6012Cf08Fa6eEc',
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

USDC_SWAP_CONTRACT_ADDRESS: '0x72e64Cff5cfFD4BFbC5b8d4fB081B33B9EE3e30e',
};
102 changes: 52 additions & 50 deletions src/lib/polygon/PolygonContractABIs.full.js.txt
Original file line number Diff line number Diff line change
@@ -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)',
Expand Down Expand Up @@ -74,55 +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_TRANSFER_CONTRACT_ABI: [
'constructor()',
'event DomainRegistered(bytes32 indexed domainSeparator, bytes domainValue)',
'event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)',
'event RequestTypeRegistered(bytes32 indexed typeHash, string typeStr)',
'function EIP712_DOMAIN_TYPE() view returns (string)',
'function deposits(address) view returns (uint256)',
'function domains(bytes32) view returns (bool)',
'function execute(tuple(address from, address to, uint256 value, uint256 gas, uint256 nonce, bytes data, uint256 validUntil) request, bytes32 domainSeparator, bytes32 requestTypeHash, bytes suffixData, bytes signature) payable returns (bool success, bytes ret)',
'function getGasAndDataLimits() view returns (tuple(uint256 acceptanceBudget, uint256 preRelayedCallGasLimit, uint256 postRelayedCallGasLimit, uint256 calldataSizeLimit) limits)',
'function getHubAddr() view returns (address)',
'function getMinimumRelayFee(tuple(uint256 gasPrice, uint256 pctRelayFee, uint256 baseRelayFee, address relayWorker, address paymaster, address forwarder, bytes paymasterData, uint256 clientId) relayData) view returns (uint256 amount)',
'function getNonce(address from) view returns (uint256)',
'function getRelayHubDeposit() view returns (uint256)',
'function getRequiredRelayFee(tuple(uint256 gasPrice, uint256 pctRelayFee, uint256 baseRelayFee, address relayWorker, address paymaster, address forwarder, bytes paymasterData, uint256 clientId) relayData, bytes4 methodId) view returns (uint256 amount)',
'function getRequiredRelayGas(bytes4 methodId) view returns (uint256 gas)',
'function isTrustedForwarder(address forwarder) view returns (bool)',
'function owner() view returns (address)',
'function postRelayedCall(bytes context, bool success, uint256 gasUseWithoutPost, tuple(uint256 gasPrice, uint256 pctRelayFee, uint256 baseRelayFee, address relayWorker, address paymaster, address forwarder, bytes paymasterData, uint256 clientId) relayData)',
'function preRelayedCall(tuple(tuple(address from, address to, uint256 value, uint256 gas, uint256 nonce, bytes data, uint256 validUntil) request, tuple(uint256 gasPrice, uint256 pctRelayFee, uint256 baseRelayFee, address relayWorker, address paymaster, address forwarder, bytes paymasterData, uint256 clientId) relayData) relayRequest, bytes signature, bytes approvalData, uint256 maxPossibleGas) returns (bytes context, bool revertOnRecipientRevert)',
'function registerDomainSeparator(string name, string version)',
'function registerRequestType(string typeName, string typeSuffix)',
'function registerToken(address token, address pool)',
'function registeredTokenPool(address) view returns (address)',
'function registeredTokenPoolFee(address token) view returns (uint24 fee)',
'function renounceOwnership()',
'function requiredRelayGas() view returns (uint256)',
'function setGasAndDataLimits(tuple(uint256 acceptanceBudget, uint256 preRelayedCallGasLimit, uint256 postRelayedCallGasLimit, uint256 calldataSizeLimit) limits)',
'function setMaxRequiredRelayGas(uint256 gas)',
'function setRelayHub(address hub)',
'function setRequiredRelayGas(bytes4 methodId, uint256 gas)',
'function setWrappedChainToken(address _wrappedChainToken)',
'function transfer(address token, uint256 amount, address target, uint256 fee)',
'function transferOwnership(address newOwner)',
'function transferWithApproval(address token, uint256 amount, address target, uint256 fee, uint256 approval, bytes32 sigR, bytes32 sigS, uint8 sigV)',
'function trustedForwarder() view returns (address forwarder)',
'function typeHashes(bytes32) view returns (bool)',
'function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes _data)',
'function unregisterToken(address token)',
'function verify(tuple(address from, address to, uint256 value, uint256 gas, uint256 nonce, bytes data, uint256 validUntil) forwardRequest, bytes32 domainSeparator, bytes32 requestTypeHash, bytes suffixData, bytes signature) view',
'function versionPaymaster() view returns (string)',
'function versionRecipient() view returns (string)',
'function withdraw(uint256 amount, address target)',
'function withdrawRelayHubDeposit(uint256 amount, address target)',
'function withdrawToken(address token, uint256 amount, address target)',
'function wrappedChainToken() view returns (address)',
],

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)',
Expand Down Expand Up @@ -295,5 +247,55 @@ const PolygonContractABIsFull = { // eslint-disable-line no-unused-vars
'function withdrawToken(address token, uint256 amount, address target)',
'function wrappedChainToken() view returns (address)',
],

SWAP_CONTRACT_ABI: [
"constructor()",
"event DomainRegistered(bytes32 indexed domainSeparator, bytes domainValue)",
"event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)",
"event RequestTypeRegistered(bytes32 indexed typeHash, string typeStr)",
"function EIP712_DOMAIN_TYPE() view returns (string)",
"function deposits(address) view returns (uint256)",
"function domains(bytes32) view returns (bool)",
"function execute(tuple(address from, address to, uint256 value, uint256 gas, uint256 nonce, bytes data, uint256 validUntil) request, bytes32 domainSeparator, bytes32 requestTypeHash, bytes suffixData, bytes signature) payable returns (bool success, bytes ret)",
"function getGasAndDataLimits() view returns (tuple(uint256 acceptanceBudget, uint256 preRelayedCallGasLimit, uint256 postRelayedCallGasLimit, uint256 calldataSizeLimit) limits)",
"function getHubAddr() view returns (address)",
"function getMinimumRelayFee(tuple(uint256 gasPrice, uint256 pctRelayFee, uint256 baseRelayFee, address relayWorker, address paymaster, address forwarder, bytes paymasterData, uint256 clientId) relayData) view returns (uint256 amount)",
"function getNonce(address from) view returns (uint256)",
"function getRelayHubDeposit() view returns (uint256)",
"function getRequiredRelayFee(tuple(uint256 gasPrice, uint256 pctRelayFee, uint256 baseRelayFee, address relayWorker, address paymaster, address forwarder, bytes paymasterData, uint256 clientId) relayData, bytes4 methodId) view returns (uint256 amount)",
"function getRequiredRelayGas(bytes4 methodId) view returns (uint256 gas)",
"function isTrustedForwarder(address forwarder) view returns (bool)",
"function owner() view returns (address)",
"function postRelayedCall(bytes context, bool success, uint256 gasUseWithoutPost, tuple(uint256 gasPrice, uint256 pctRelayFee, uint256 baseRelayFee, address relayWorker, address paymaster, address forwarder, bytes paymasterData, uint256 clientId) relayData)",
"function preRelayedCall(tuple(tuple(address from, address to, uint256 value, uint256 gas, uint256 nonce, bytes data, uint256 validUntil) request, tuple(uint256 gasPrice, uint256 pctRelayFee, uint256 baseRelayFee, address relayWorker, address paymaster, address forwarder, bytes paymasterData, uint256 clientId) relayData) relayRequest, bytes signature, bytes approvalData, uint256 maxPossibleGas) returns (bytes context, bool revertOnRecipientRevert)",
"function registerDomainSeparator(string name, string version)",
"function registerRequestType(string typeName, string typeSuffix)",
"function registerSwapPool(address pool)",
"function registerToken(address token, address pool)",
"function registeredSwapPool(address) view returns (bool)",
"function registeredTokenPool(address) view returns (address)",
"function registeredTokenPoolFee(address token) view returns (uint24 fee)",
"function renounceOwnership()",
"function requiredRelayGas() view returns (uint256)",
"function setGasAndDataLimits(tuple(uint256 acceptanceBudget, uint256 preRelayedCallGasLimit, uint256 postRelayedCallGasLimit, uint256 calldataSizeLimit) limits)",
"function setMaxRequiredRelayGas(uint256 gas)",
"function setRelayHub(address hub)",
"function setRequiredRelayGas(bytes4 methodId, uint256 gas)",
"function setWrappedChainToken(address _wrappedChainToken)",
"function swap(address token, uint256 amount, address pool, uint256 targetAmount, uint256 fee)",
"function swapWithApproval(address token, uint256 amount, address pool, uint256 targetAmount, uint256 fee, uint256 approval, bytes32 sigR, bytes32 sigS, uint8 sigV)",
"function transferOwnership(address newOwner)",
"function trustedForwarder() view returns (address forwarder)",
"function typeHashes(bytes32) view returns (bool)",
"function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes _data)",
"function unregisterToken(address token)",
"function verify(tuple(address from, address to, uint256 value, uint256 gas, uint256 nonce, bytes data, uint256 validUntil) forwardRequest, bytes32 domainSeparator, bytes32 requestTypeHash, bytes suffixData, bytes signature) view",
"function versionPaymaster() view returns (string)",
"function versionRecipient() view returns (string)",
"function withdraw(uint256 amount, address target)",
"function withdrawRelayHubDeposit(uint256 amount, address target)",
"function withdrawToken(address token, uint256 amount, address target)",
"function wrappedChainToken() view returns (address)",
],
};
/* eslint-enable max-len */
14 changes: 7 additions & 7 deletions src/lib/polygon/PolygonContractABIs.js
Original file line number Diff line number Diff line change
@@ -1,15 +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_TRANSFER_CONTRACT_ABI: [
'function transfer(address token, uint256 amount, address target, uint256 fee)',
'function transferWithApproval(address token, uint256 amount, address target, uint256 fee, uint256 approval, bytes32 sigR, bytes32 sigS, uint8 sigV)',
],

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)',
Expand All @@ -23,5 +18,10 @@ const PolygonContractABIs = { // eslint-disable-line no-unused-vars
'function transfer(address token, uint256 amount, address target, uint256 fee)',
'function transferWithPermit(address token, uint256 amount, address target, uint256 fee, uint256 value, bytes32 sigR, bytes32 sigS, uint8 sigV)',
],

SWAP_CONTRACT_ABI: [
'function swap(address token, uint256 amount, address pool, uint256 targetAmount, uint256 fee)',
'function swapWithApproval(address token, uint256 amount, address pool, uint256 targetAmount, uint256 fee, uint256 approval, bytes32 sigR, bytes32 sigS, uint8 sigV)',
],
};
/* eslint-enable max-len */
2 changes: 1 addition & 1 deletion src/lib/polygon/PolygonKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};

Expand Down
Loading
Loading