Skip to content

Commit

Permalink
Switch to native USDC HTLC for swaps
Browse files Browse the repository at this point in the history
  • Loading branch information
sisou committed Feb 26, 2024
1 parent 5b425ca commit 9092ac4
Show file tree
Hide file tree
Showing 14 changed files with 213 additions and 196 deletions.
12 changes: 6 additions & 6 deletions client/src/PublicRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ export type SignSwapRequestCommon = SimpleRequest & {
refundKeyPath: string, // To validate that we own the HTLC script's refund address
}>
) | (
{type: 'USDC'}
& Omit<PolygonTransactionInfo, 'amount'>
{type: 'USDC_MATIC'}
& Omit<PolygonTransactionInfo, 'approval' | 'amount'>
) | (
{type: 'EUR'}
& {
Expand Down Expand Up @@ -320,8 +320,8 @@ export type SignSwapRequestCommon = SimpleRequest & {
output: BitcoinTransactionChangeOutput,
}
) | (
{type: 'USDC'}
& Omit<PolygonTransactionInfo, 'approval' | 'amount'>
{type: 'USDC_MATIC'}
& Omit<PolygonTransactionInfo, 'approval' | 'permit' | 'amount'>
& {
amount: number,
}
Expand Down Expand Up @@ -401,7 +401,7 @@ export type SignSwapTransactionsRequest = {
type: 'BTC',
htlcScript: Uint8Array,
} | {
type: 'USDC',
type: 'USDC_MATIC',
htlcData: string,
} | {
type: 'EUR',
Expand All @@ -419,7 +419,7 @@ export type SignSwapTransactionsRequest = {
transactionHash: string,
outputIndex: number;
} | {
type: 'USDC',
type: 'USDC_MATIC',
hash: string,
timeout: number,
htlcId: string,
Expand Down
6 changes: 3 additions & 3 deletions src/components/BalanceDistributionBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* global CryptoUtils */

/** @typedef {{address: string, balance: number, active: boolean, newBalance: number}} Segment */
/** @typedef {'NIM' | 'BTC' | 'USDC' | 'EUR'} Asset */
/** @typedef {'NIM' | 'BTC' | 'USDC_MATIC' | 'EUR'} Asset */

class BalanceDistributionBar { // eslint-disable-line no-unused-vars
/**
Expand Down Expand Up @@ -34,7 +34,7 @@ class BalanceDistributionBar { // eslint-disable-line no-unused-vars
newBalance: CryptoUtils.unitsToCoins(leftAsset, segment.newBalance) * leftFiatRate,
backgroundClass: leftAsset === 'NIM'
? LoginFileConfig[IqonHash.getBackgroundColorIndex(segment.address)].className
: leftAsset.toLowerCase(),
: CryptoUtils.assetToCurrency(leftAsset),
active: segment.active,
}));

Expand All @@ -43,7 +43,7 @@ class BalanceDistributionBar { // eslint-disable-line no-unused-vars
newBalance: CryptoUtils.unitsToCoins(rightAsset, segment.newBalance) * rightFiatRate,
backgroundClass: rightAsset === 'NIM'
? LoginFileConfig[IqonHash.getBackgroundColorIndex(segment.address)].className
: rightAsset.toLowerCase(),
: CryptoUtils.assetToCurrency(rightAsset),
active: segment.active,
}));

Expand Down
12 changes: 6 additions & 6 deletions src/components/SwapFeesTooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ class SwapFeesTooltip { // eslint-disable-line no-unused-vars
}

// Show USDC fees next
if (fundTx.type === 'USDC' || redeemTx.type === 'USDC') {
const myFee = fundTx.type === 'USDC'
if (fundTx.type === 'USDC_MATIC' || redeemTx.type === 'USDC_MATIC') {
const myFee = fundTx.type === 'USDC_MATIC'
? fundTx.description.args.fee.toNumber()
: redeemTx.type === 'USDC'
: redeemTx.type === 'USDC_MATIC'
? redeemTx.description.args.fee.toNumber()
: 0;

const theirFee = fundTx.type === 'USDC' ? fundFees.redeeming : redeemFees.funding;
const theirFee = fundTx.type === 'USDC_MATIC' ? fundFees.redeeming : redeemFees.funding;

const fiatRate = fundTx.type === 'USDC' ? fundingFiatRate : redeemingFiatRate;
const fiatFee = CryptoUtils.unitsToCoins('USDC', myFee + theirFee) * fiatRate;
const fiatRate = fundTx.type === 'USDC_MATIC' ? fundingFiatRate : redeemingFiatRate;
const fiatFee = CryptoUtils.unitsToCoins('USDC_MATIC', myFee + theirFee) * fiatRate;

const rows = this._createUsdcLine(fiatFee, fiatCurrency);
this.$tooltip.appendChild(rows[0]);
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.local.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ const CONFIG = { // eslint-disable-line no-unused-vars

POLYGON_CHAIN_ID: 80001,
BRIDGED_USDC_CONTRACT_ADDRESS: '0x0FA8781a83E46826621b3BC094Ea2A0212e71B23',
BRIDGED_USDC_HTLC_CONTRACT_ADDRESS: '0x2EB7cd7791b947A25d629219ead941fCd8f364BF',

NATIVE_USDC_CONTRACT_ADDRESS: '0x9999f7Fea5938fD3b1E26A12c3f2fb024e194f97',
NATIVE_USDC_TRANSFER_CONTRACT_ADDRESS: '0x5D101A320547f8D640c44fDfe5d1f35224f00B8B', // v1
NATIVE_USDC_HTLC_CONTRACT_ADDRESS: '0xA9fAbABE97375565e4A9Ac69A57Df33c91FCB897',

USDC_SWAP_CONTRACT_ADDRESS: '0x72e64Cff5cfFD4BFbC5b8d4fB081B33B9EE3e30e',
};
2 changes: 1 addition & 1 deletion src/config/config.mainnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ const CONFIG = { // eslint-disable-line no-unused-vars

POLYGON_CHAIN_ID: 137,
BRIDGED_USDC_CONTRACT_ADDRESS: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174',
BRIDGED_USDC_HTLC_CONTRACT_ADDRESS: '0xF615bD7EA00C4Cc7F39Faad0895dB5f40891359f',

NATIVE_USDC_CONTRACT_ADDRESS: '0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359',
NATIVE_USDC_TRANSFER_CONTRACT_ADDRESS: '0x3157d422cd1be13AC4a7cb00957ed717e648DFf2', // v1
NATIVE_USDC_HTLC_CONTRACT_ADDRESS: '',

USDC_SWAP_CONTRACT_ADDRESS: '',
};
2 changes: 1 addition & 1 deletion src/config/config.testnet.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ const CONFIG = { // eslint-disable-line no-unused-vars

POLYGON_CHAIN_ID: 80001,
BRIDGED_USDC_CONTRACT_ADDRESS: '0x0FA8781a83E46826621b3BC094Ea2A0212e71B23',
BRIDGED_USDC_HTLC_CONTRACT_ADDRESS: '0x2EB7cd7791b947A25d629219ead941fCd8f364BF',

NATIVE_USDC_CONTRACT_ADDRESS: '0x9999f7Fea5938fD3b1E26A12c3f2fb024e194f97',
NATIVE_USDC_TRANSFER_CONTRACT_ADDRESS: '0x5D101A320547f8D640c44fDfe5d1f35224f00B8B', // v1
NATIVE_USDC_HTLC_CONTRACT_ADDRESS: '0xA9fAbABE97375565e4A9Ac69A57Df33c91FCB897',

USDC_SWAP_CONTRACT_ADDRESS: '0x72e64Cff5cfFD4BFbC5b8d4fB081B33B9EE3e30e',
};
112 changes: 56 additions & 56 deletions src/lib/polygon/PolygonContractABIs.full.js.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,62 +74,6 @@ 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)',
],

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)',
'event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)',
'event Redeem(bytes32 indexed id, bytes32 secret)',
'event Refund(bytes32 indexed id)',
'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 htlcs(bytes32) view returns (address token, uint256 amount, address refund, address recipient, bytes32 hash, uint256 timeout)',
'function isTrustedForwarder(address forwarder) view returns (bool)',
'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 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 redeem(bytes32 id, address target, bytes32 secret, uint256 fee)',
'function redeemWithSecretInData(bytes32 id, address target, uint256 fee)',
'function refund(bytes32 id, address target, uint256 fee)',
'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 relayWithoutGsn(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, address relay)',
'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 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)',
],

NATIVE_USDC_CONTRACT_ABI: [
'event Approval(address indexed owner, address indexed spender, uint256 value)',
'event AuthorizationCanceled(address indexed authorizer, bytes32 indexed nonce)',
Expand Down Expand Up @@ -248,6 +192,62 @@ const PolygonContractABIsFull = { // eslint-disable-line no-unused-vars
'function wrappedChainToken() view returns (address)',
],

NATIVE_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)',
'event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)',
'event Redeem(bytes32 indexed id, bytes32 secret)',
'event Refund(bytes32 indexed id)',
'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 htlcs(bytes32) view returns (address token, uint256 amount, address refund, address recipient, bytes32 hash, uint256 timeout)',
'function isTrustedForwarder(address forwarder) view returns (bool)',
'function open(bytes32 id, address token, uint256 amount, address refundAddress, address recipientAddress, bytes32 hash, uint256 timeout, uint256 fee)',
'function openWithPermit(bytes32 id, address token, uint256 amount, address refundAddress, address recipientAddress, bytes32 hash, uint256 timeout, uint256 fee, uint256 value, bytes32 sigR, bytes32 sigS, uint8 sigV)',
'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 redeem(bytes32 id, address target, bytes32 secret, uint256 fee)',
'function redeemWithSecretInData(bytes32 id, address target, uint256 fee)',
'function refund(bytes32 id, address target, uint256 fee)',
'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 relayWithoutGsn(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, address relay)',
'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 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)',
],

SWAP_CONTRACT_ABI: [
"constructor()",
"event DomainRegistered(bytes32 indexed domainSeparator, bytes domainValue)",
Expand Down
Loading

0 comments on commit 9092ac4

Please sign in to comment.